/* determine data length and mbmem tail index */
mask = mbx->mbmem_len - 1;
len = mbx->tail_len;
tail = fm10k_mbx_tail_sub(mbx, len); if (tail > mask)
tail++;
/* determine offset in the ring */
end = fm10k_fifo_head_offset(fifo, mbx->pulled);
head += end;
/* memory barrier to guarantee data is ready to be read */
rmb();
/* Copy message from Tx FIFO */ for (end = fifo->size - end; len; head = fifo->buffer) { do { /* adjust tail to match offset for FIFO */
tail &= mask; if (!tail)
tail++;
mbx->tx_mbmem_pulled++;
/* write message to hardware FIFO */
fm10k_write_reg(hw, mbmem + tail++, *(head++));
} while (--len && --end);
}
}
/* update number of bytes pulled and update bytes in transit */
mbx->pulled += mbx->tail_len - ack;
/* determine length of data to pull, reserve space for mbmem header */
mbmem_len = mbx->mbmem_len - 1;
len = fm10k_fifo_used(fifo) - mbx->pulled; if (len > mbmem_len)
len = mbmem_len;
/* update tail and record number of bytes in transit */
mbx->tail = fm10k_mbx_tail_add(mbx, len - ack);
mbx->tail_len = len;
/* drop pulled messages from the FIFO */ for (len = fm10k_fifo_head_len(fifo);
len && (mbx->pulled >= len);
len = fm10k_fifo_head_len(fifo)) {
mbx->pulled -= fm10k_fifo_head_drop(fifo);
mbx->tx_messages++;
mbx->tx_dwords += len;
}
/* Copy message out from the Tx FIFO */
fm10k_mbx_write_copy(hw, mbx);
}
/* determine data length and mbmem head index */
len = mbx->head_len;
head = fm10k_mbx_head_sub(mbx, len); if (head >= mbx->mbmem_len)
head++;
/* determine offset in the ring */
end = fm10k_fifo_tail_offset(fifo, mbx->pushed);
tail += end;
/* Copy message into Rx FIFO */ for (end = fifo->size - end; len; tail = fifo->buffer) { do { /* adjust head to match offset for FIFO */
head &= mbx->mbmem_len - 1; if (!head)
head++;
mbx->rx_mbmem_pushed++;
/* read message from hardware FIFO */
*(tail++) = fm10k_read_reg(hw, mbmem + head++);
} while (--len && --end);
}
/* memory barrier to guarantee FIFO is written before tail update */
wmb();
}
/* track when we should cross the end of the FIFO */
offset = fifo->size - offset;
/* if we are in 2 blocks process the end of the FIFO first */ if (offset < len) {
seed = fm10k_crc_16b(data, seed, offset * 2);
data = fifo->buffer;
len -= offset;
}
/* process any remaining bits */ return fm10k_crc_16b(data, seed, len * 2);
}
/* parse Rx messages out of the Rx FIFO to empty it */ for (cnt = 0; !fm10k_fifo_empty(fifo); cnt++) {
err = fm10k_tlv_msg_parse(hw, fifo->buffer + fifo->head,
mbx, mbx->msg_data); if (err < 0)
mbx->rx_parse_err++;
fm10k_fifo_head_drop(fifo);
}
/* shift remaining bytes back to start of FIFO */
memmove(fifo->buffer, fifo->buffer + fifo->tail, mbx->pushed << 2);
/* shift head and tail based on the memory we moved */
fifo->tail -= fifo->head;
fifo->head = 0;
switch (mbx->state) { case FM10K_STATE_CLOSED: case FM10K_STATE_DISCONNECT: return FM10K_MBX_ERR_NO_MBX; default: break;
}
/* enqueue the message on the Tx FIFO */
err = fm10k_fifo_enqueue(&mbx->tx, msg);
/* if it failed give the FIFO a chance to drain */ while (err && countdown) {
countdown--;
udelay(mbx->udelay);
mbx->ops.process(hw, mbx);
err = fm10k_fifo_enqueue(&mbx->tx, msg);
}
/* if we failed treat the error */ if (err) {
mbx->timeout = 0;
mbx->tx_busy++;
}
/* begin processing message, ignore errors as this is just meant *tostartthemailboxflowsowearenotconcernedifthere *isabaderror,orthemailboxisalreadybusywitharequest
*/ if (!mbx->tail_len)
mbx->ops.process(hw, mbx);
return0;
}
/** *fm10k_mbx_read-Copiesthembmemtolocalmessagebuffer *@hw:pointertohardwarestructure *@mbx:pointertomailbox * *Thisfunctioncopiesthemessagefromthembmemtothemessagearray
**/ static s32 fm10k_mbx_read(struct fm10k_hw *hw, struct fm10k_mbx_info *mbx)
{ /* only allow one reader in here at a time */ if (mbx->mbx_hdr) return FM10K_MBX_ERR_BUSY;
/* read to capture initial interrupt bits */ if (fm10k_read_reg(hw, mbx->mbx_reg) & FM10K_MBX_REQ_INTERRUPT)
mbx->mbx_lock = FM10K_MBX_ACK;
/* write back interrupt bits to clear */
fm10k_write_reg(hw, mbx->mbx_reg,
FM10K_MBX_REQ_INTERRUPT | FM10K_MBX_ACK_INTERRUPT);
/* load header to memory to be written */
mbx->mbx_hdr = hdr | FM10K_MSG_HDR_FIELD_SET(crc, CRC);
}
/** *fm10k_mbx_create_error_msg-Generateanerrormessage *@mbx:pointertomailbox *@err:localerrorencountered * *Thisfunctionwillinterprettheerrorprovidedbyerr,andbasedon *thatitmayshiftthemessageby1DWORDandthenplaceanerrorheader *atthestartofthemessage.
**/ staticvoid fm10k_mbx_create_error_msg(struct fm10k_mbx_info *mbx, s32 err)
{ /* only generate an error message for these types */ switch (err) { case FM10K_MBX_ERR_TAIL: case FM10K_MBX_ERR_HEAD: case FM10K_MBX_ERR_TYPE: case FM10K_MBX_ERR_SIZE: case FM10K_MBX_ERR_RSVD0: case FM10K_MBX_ERR_CRC: break; default: return;
}
type = FM10K_MSG_HDR_FIELD_GET(*hdr, TYPE);
rsvd0 = FM10K_MSG_HDR_FIELD_GET(*hdr, RSVD0);
tail = FM10K_MSG_HDR_FIELD_GET(*hdr, TAIL);
head = FM10K_MSG_HDR_FIELD_GET(*hdr, HEAD);
size = FM10K_MSG_HDR_FIELD_GET(*hdr, CONNECT_SIZE);
if (rsvd0) return FM10K_MBX_ERR_RSVD0;
switch (type) { case FM10K_MSG_DISCONNECT: /* validate that all data has been received */ if (tail != mbx->head) return FM10K_MBX_ERR_TAIL;
fallthrough; case FM10K_MSG_DATA: /* validate that head is moving correctly */ if (!head || (head == FM10K_MSG_HDR_MASK(HEAD))) return FM10K_MBX_ERR_HEAD; if (fm10k_mbx_index_len(mbx, head, mbx->tail) > mbx->tail_len) return FM10K_MBX_ERR_HEAD;
/* validate that tail is moving correctly */ if (!tail || (tail == FM10K_MSG_HDR_MASK(TAIL))) return FM10K_MBX_ERR_TAIL; if (fm10k_mbx_index_len(mbx, mbx->head, tail) < mbx->mbmem_len) break;
return FM10K_MBX_ERR_TAIL; case FM10K_MSG_CONNECT: /* validate size is in range and is power of 2 mask */ if ((size < FM10K_VFMBX_MSG_MTU) || (size & (size + 1))) return FM10K_MBX_ERR_SIZE;
fallthrough; case FM10K_MSG_ERROR: if (!head || (head == FM10K_MSG_HDR_MASK(HEAD))) return FM10K_MBX_ERR_HEAD; /* neither create nor error include a tail offset */ if (tail) return FM10K_MBX_ERR_TAIL;
break; default: return FM10K_MBX_ERR_TYPE;
}
return0;
}
/** *fm10k_mbx_create_reply-Generatereplybasedonstateandremotehead *@hw:pointertohardwarestructure *@mbx:pointertomailbox *@head:acknowledgementnumber * *Thisfunctionwillgenerateanoutgoingmessagebasedonthecurrent *mailboxstateandtheremoteFIFOhead.Itwillreturnthelength *oftheoutgoingmessageexcludingheaderonsuccess,andanegativevalue *onerror.
**/ static s32 fm10k_mbx_create_reply(struct fm10k_hw *hw, struct fm10k_mbx_info *mbx, u16 head)
{ switch (mbx->state) { case FM10K_STATE_OPEN: case FM10K_STATE_DISCONNECT: /* update our checksum for the outgoing data */
fm10k_mbx_update_local_crc(mbx, head);
/* as long as other end recognizes us keep sending data */
fm10k_mbx_pull_head(hw, mbx, head);
/* generate new header based on data */ if (mbx->tail_len || (mbx->state == FM10K_STATE_OPEN))
fm10k_mbx_create_data_hdr(mbx); else
fm10k_mbx_create_disconnect_hdr(mbx); break; case FM10K_STATE_CONNECT: /* send disconnect even if we aren't connected */
fm10k_mbx_create_connect_hdr(mbx); break; case FM10K_STATE_CLOSED: /* generate new header based on data */
fm10k_mbx_create_disconnect_hdr(mbx); break; default: break;
}
/* reset our outgoing max size back to Rx limits */
mbx->max_size = mbx->rx.size - 1;
/* update mbx->pulled to account for tail_len and ack */
head = FM10K_MSG_HDR_FIELD_GET(mbx->mbx_hdr, HEAD);
ack = fm10k_mbx_index_len(mbx, head, mbx->tail);
mbx->pulled += mbx->tail_len - ack;
/* now drop any messages which have started or finished transmitting */ while (fm10k_fifo_head_len(&mbx->tx) && mbx->pulled) {
len = fm10k_fifo_head_drop(&mbx->tx);
mbx->tx_dropped++; if (mbx->pulled >= len)
mbx->pulled -= len; else
mbx->pulled = 0;
}
/* just do a quick resysnc to start of message */
mbx->pushed = 0;
mbx->pulled = 0;
mbx->tail_len = 0;
mbx->head_len = 0;
mbx->rx.tail = 0;
mbx->rx.head = 0;
}
/* flush any oversized messages from the queue */ for (len = fm10k_fifo_head_len(&mbx->tx);
len > size;
len = fm10k_fifo_head_len(&mbx->tx)) {
fm10k_fifo_head_drop(&mbx->tx);
mbx->tx_dropped++;
}
}
/** *fm10k_mbx_connect_reset-Resetfollowingrequestforreset *@mbx:pointertomailbox * *Thisfunctionresetsthemailboxtoeitheradisconnectedstate *oraconnectstatedependingonthecurrentmailboxstate
**/ staticvoid fm10k_mbx_connect_reset(struct fm10k_mbx_info *mbx)
{ /* just do a quick resysnc to start of frame */
fm10k_mbx_reset_work(mbx);
/* we cannot exit connect until the size is good */ if (mbx->state == FM10K_STATE_OPEN)
mbx->state = FM10K_STATE_CONNECT; else
mbx->state = FM10K_STATE_CLOSED;
}
/* we will need to pull all of the fields for verification */
size = FM10K_MSG_HDR_FIELD_GET(*hdr, CONNECT_SIZE);
head = FM10K_MSG_HDR_FIELD_GET(*hdr, HEAD);
switch (state) { case FM10K_STATE_DISCONNECT: case FM10K_STATE_OPEN: /* reset any in-progress work */
fm10k_mbx_connect_reset(mbx); break; case FM10K_STATE_CONNECT: /* we cannot exit connect until the size is good */ if (size > mbx->rx.size) {
mbx->max_size = mbx->rx.size - 1;
} else { /* record the remote system requesting connection */
mbx->state = FM10K_STATE_OPEN;
/* we will need to pull the header field for verification */
head = FM10K_MSG_HDR_FIELD_GET(*hdr, HEAD);
/* We should not be receiving disconnect if Rx is incomplete */ if (mbx->pushed) return FM10K_MBX_ERR_TAIL;
/* we have already verified mbx->head == tail so we know this is 0 */
mbx->head_len = 0;
/* verify the checksum on the incoming header is correct */
err = fm10k_mbx_verify_remote_crc(mbx); if (err) return err;
switch (state) { case FM10K_STATE_DISCONNECT: case FM10K_STATE_OPEN: /* state doesn't change if we still have work to do */ if (!fm10k_mbx_tx_complete(mbx)) break;
/* verify the head indicates we completed all transmits */ if (head != mbx->tail) return FM10K_MBX_ERR_HEAD;
/* reset any in-progress work */
fm10k_mbx_connect_reset(mbx); break; default: break;
}
/* Place mbx in ready to disconnect state */
mbx->state = FM10K_STATE_DISCONNECT;
/* trigger interrupt to start shutdown process */
fm10k_write_reg(hw, mbx->mbx_reg, FM10K_MBX_REQ |
FM10K_MBX_INTERRUPT_DISABLE); do {
udelay(FM10K_MBX_POLL_DELAY);
mbx->ops.process(hw, mbx);
timeout -= FM10K_MBX_POLL_DELAY;
} while ((timeout > 0) && (mbx->state != FM10K_STATE_CLOSED));
/* in case we didn't close, just force the mailbox into shutdown and *dropallleftovermessagesintheFIFO.
*/
fm10k_mbx_connect_reset(mbx);
fm10k_fifo_drop_all(&mbx->tx);
/* enable interrupt and notify other party of new message */
mbx->mbx_lock = FM10K_MBX_REQ_INTERRUPT | FM10K_MBX_ACK_INTERRUPT |
FM10K_MBX_INTERRUPT_ENABLE;
/* generate and load connect header into mailbox */
fm10k_mbx_create_connect_hdr(mbx);
fm10k_mbx_write(hw, mbx);
/* Allow NULL mailboxes that transmit but don't receive */ if (!msg_data) return0;
while (msg_data->id != FM10K_TLV_ERROR) { /* all messages should have a function handler */ if (!msg_data->func) return FM10K_ERR_PARAM;
/* parser is optional */
attr = msg_data->attr; if (attr) { while (attr->id != FM10K_TLV_ERROR) {
id = attr->id;
attr++; /* ID should always be increasing */ if (id >= attr->id) return FM10K_ERR_PARAM; /* ID should fit in results array */ if (id >= FM10K_TLV_RESULTS_MAX) return FM10K_ERR_PARAM;
}
/* verify terminator is in the list */ if (attr->id != FM10K_TLV_ERROR) return FM10K_ERR_PARAM;
}
id = msg_data->id;
msg_data++; /* ID should always be increasing */ if (id >= msg_data->id) return FM10K_ERR_PARAM;
}
/* verify terminator is in the list */ if ((msg_data->id != FM10K_TLV_ERROR) || !msg_data->func) return FM10K_ERR_PARAM;
return0;
}
/** *fm10k_mbx_register_handlers-Registerasetofhandleropsformailbox *@mbx:pointertomailbox *@msg_data:handlersformailboxevents * *Thisfunctionassociatesasetofmessagehandlingopswithamailbox.
**/ static s32 fm10k_mbx_register_handlers(struct fm10k_mbx_info *mbx, conststruct fm10k_msg_data *msg_data)
{ /* validate layout of handlers before assigning them */ if (fm10k_mbx_validate_handlers(msg_data)) return FM10K_ERR_PARAM;
/* initialize the message handlers */
mbx->msg_data = msg_data;
/* start out in closed state */
mbx->state = FM10K_STATE_CLOSED;
/* validate layout of handlers before assigning them */ if (fm10k_mbx_validate_handlers(msg_data)) return FM10K_ERR_PARAM;
/* initialize the message handlers */
mbx->msg_data = msg_data;
/* start mailbox as timed out and let the reset_hw call *setthetimeoutvaluetobegincommunications
*/
mbx->timeout = 0;
mbx->udelay = FM10K_MBX_INIT_DELAY;
/* initialize tail and head */
mbx->tail = 1;
mbx->head = 1;
/* we cannot connect an already connected mailbox */ if (mbx->state != FM10K_STATE_CLOSED) return FM10K_MBX_ERR_BUSY;
/* mailbox timeout can now become active */
mbx->timeout = FM10K_MBX_INIT_TIMEOUT;
/* Place mbx in ready to connect state */
mbx->state = FM10K_STATE_CONNECT;
mbx->max_size = FM10K_MBX_MSG_MAX_SIZE;
/* reset interface back to connect */
fm10k_sm_mbx_connect_reset(mbx);
/* enable interrupt and notify other party of new message */
mbx->mbx_lock = FM10K_MBX_REQ_INTERRUPT | FM10K_MBX_ACK_INTERRUPT |
FM10K_MBX_INTERRUPT_ENABLE;
/* generate and load connect header into mailbox */
fm10k_sm_mbx_create_connect_hdr(mbx, 0);
fm10k_mbx_write(hw, mbx);
/* Place mbx in ready to disconnect state */
mbx->state = FM10K_STATE_DISCONNECT;
/* trigger interrupt to start shutdown process */
fm10k_write_reg(hw, mbx->mbx_reg, FM10K_MBX_REQ |
FM10K_MBX_INTERRUPT_DISABLE); do {
udelay(FM10K_MBX_POLL_DELAY);
mbx->ops.process(hw, mbx);
timeout -= FM10K_MBX_POLL_DELAY;
} while ((timeout > 0) && (mbx->state != FM10K_STATE_CLOSED));
/* in case we didn't close just force the mailbox into shutdown */
mbx->state = FM10K_STATE_CLOSED;
mbx->remote = 0;
fm10k_mbx_reset_work(mbx);
fm10k_fifo_drop_all(&mbx->tx);
switch (state) { case FM10K_STATE_DISCONNECT: /* if there is an error just disconnect */
mbx->remote = 0; break; case FM10K_STATE_OPEN: /* flush any uncompleted work */
fm10k_sm_mbx_connect_reset(mbx); break; case FM10K_STATE_CONNECT: /* try connecting at lower version */ if (mbx->remote) { while (mbx->local > 1)
mbx->local--;
mbx->remote = 0;
} break; default: break;
}
fm10k_sm_mbx_create_connect_hdr(mbx, 0);
}
/** *fm10k_sm_mbx_create_error_msg-ProcessanerrorinFIFOheader *@mbx:pointertomailbox *@err:localerrorencountered * *Thisfunctionwillinterprettheerrorprovidedbyerr,andbasedon *thatitmaysettheerrorbitinthelocalmessageheader
**/ staticvoid fm10k_sm_mbx_create_error_msg(struct fm10k_mbx_info *mbx, s32 err)
{ /* only generate an error message for these types */ switch (err) { case FM10K_MBX_ERR_TAIL: case FM10K_MBX_ERR_HEAD: case FM10K_MBX_ERR_SRC: case FM10K_MBX_ERR_SIZE: case FM10K_MBX_ERR_RSVD0: break; default: return;
}
/* process it as though we received an error, and send error reply */
fm10k_sm_mbx_process_error(mbx);
fm10k_sm_mbx_create_connect_hdr(mbx, 1);
}
/** *fm10k_sm_mbx_receive-TakemessagefromRxmailboxFIFOandputitinRx *@hw:pointertohardwarestructure *@mbx:pointertomailbox *@tail:tailindexofmessage * *ThisfunctionwilldequeueonemessagefromtheRxswitchmanagermailbox *FIFOandplaceitintheRxmailboxFIFOforprocessingbysoftware.
**/ static s32 fm10k_sm_mbx_receive(struct fm10k_hw *hw, struct fm10k_mbx_info *mbx,
u16 tail)
{ /* reduce length by 1 to convert to a mask */
u16 mbmem_len = mbx->mbmem_len - 1;
s32 err;
/* push tail in front of head */ if (tail < mbx->head)
tail += mbmem_len;
/* copy data to the Rx FIFO */
err = fm10k_mbx_push_tail(hw, mbx, tail); if (err < 0) return err;
/* process messages if we have received any */
fm10k_mbx_dequeue_rx(hw, mbx);
/* guarantee head aligns with the end of the last message */
mbx->head = fm10k_mbx_head_sub(mbx, mbx->pushed);
mbx->pushed = 0;
/* clear any extra bits left over since index adds 1 extra bit */ if (mbx->head > mbmem_len)
mbx->head -= mbmem_len;
return err;
}
/** *fm10k_sm_mbx_transmit-TakemessagefromTxandputitinTxmailboxFIFO *@hw:pointertohardwarestructure *@mbx:pointertomailbox *@head:headindexofmessage * *ThisfunctionwilldequeueonemessagefromtheTxmailboxFIFOandplace *itintheTxswitchmanagermailboxFIFOforprocessingbyhardware.
**/ staticvoid fm10k_sm_mbx_transmit(struct fm10k_hw *hw, struct fm10k_mbx_info *mbx, u16 head)
{ struct fm10k_mbx_fifo *fifo = &mbx->tx; /* reduce length by 1 to convert to a mask */
u16 mbmem_len = mbx->mbmem_len - 1;
u16 tail_len, len = 0;
/* push head behind tail */ if (mbx->tail < head)
head += mbmem_len;
fm10k_mbx_pull_head(hw, mbx, head);
/* determine msg aligned offset for end of buffer */ do {
u32 *msg;
switch (state) { case FM10K_STATE_DISCONNECT: /* drop remote connections and disconnect */
mbx->state = FM10K_STATE_CLOSED;
mbx->remote = 0;
mbx->local = 0; break; case FM10K_STATE_OPEN: /* flush any incomplete work */
fm10k_sm_mbx_connect_reset(mbx);
err = FM10K_ERR_RESET_REQUESTED; break; case FM10K_STATE_CONNECT: /* Update remote value to match local value */
mbx->remote = mbx->local; break; default: break;
}
/* pull all fields needed for verification */
tail = FM10K_MSG_HDR_FIELD_GET(*hdr, SM_TAIL);
head = FM10K_MSG_HDR_FIELD_GET(*hdr, SM_HEAD);
/* if we are in connect and wanting version 1 then start up and go */ if (mbx->state == FM10K_STATE_CONNECT) { if (!mbx->remote) goto send_reply; if (mbx->remote != 1) return FM10K_MBX_ERR_SRC;
mbx->state = FM10K_STATE_OPEN;
}
do { /* abort on message size errors */
len = fm10k_sm_mbx_receive(hw, mbx, tail); if (len < 0) return len;
/* continue until we have flushed the Rx FIFO */
} while (len);
/* start out in closed state */
mbx->state = FM10K_STATE_CLOSED;
/* validate layout of handlers before assigning them */ if (fm10k_mbx_validate_handlers(msg_data)) return FM10K_ERR_PARAM;
/* initialize the message handlers */
mbx->msg_data = msg_data;
/* start mailbox as timed out and let the reset_hw call *setthetimeoutvaluetobegincommunications
*/
mbx->timeout = 0;
mbx->udelay = FM10K_MBX_INIT_DELAY;
/* Split buffer for use by Tx/Rx FIFOs */
mbx->max_size = FM10K_MBX_MSG_MAX_SIZE;
mbx->mbmem_len = FM10K_MBMEM_PF_XOR;
/* initialize the FIFOs, sizes are in 4 byte increments */
fm10k_fifo_init(&mbx->tx, mbx->buffer, FM10K_MBX_TX_BUFFER_SIZE);
fm10k_fifo_init(&mbx->rx, &mbx->buffer[FM10K_MBX_TX_BUFFER_SIZE],
FM10K_MBX_RX_BUFFER_SIZE);
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.47Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-10-03)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.