/** *i40e_alloc_arq_bufs-Allocatepre-postedbuffersforthereceivequeue *@hw:pointertothehardwarestructure
**/ staticint i40e_alloc_arq_bufs(struct i40e_hw *hw)
{ struct libie_aq_desc *desc; struct i40e_dma_mem *bi; int ret_code; int i;
/* We'll be allocating the buffer info memory first, then we can *allocatethemappedbuffersfortheeventprocessing
*/
/* buffer_info structures do not need alignment */
ret_code = i40e_allocate_virt_mem(hw, &hw->aq.arq.dma_head,
(hw->aq.num_arq_entries * sizeof(struct i40e_dma_mem))); if (ret_code) goto alloc_arq_bufs;
hw->aq.arq.r.arq_bi = (struct i40e_dma_mem *)hw->aq.arq.dma_head.va;
/* allocate the mapped buffers */ for (i = 0; i < hw->aq.num_arq_entries; i++) {
bi = &hw->aq.arq.r.arq_bi[i];
ret_code = i40e_allocate_dma_mem(hw, bi,
hw->aq.arq_buf_size,
I40E_ADMINQ_DESC_ALIGNMENT); if (ret_code) goto unwind_alloc_arq_bufs;
/* now configure the descriptors for use */
desc = I40E_ADMINQ_DESC(hw->aq.arq, i);
desc->flags = cpu_to_le16(LIBIE_AQ_FLAG_BUF); if (hw->aq.arq_buf_size > I40E_AQ_LARGE_BUF)
desc->flags |= cpu_to_le16(LIBIE_AQ_FLAG_LB);
desc->opcode = 0; /* This is in accordance with Admin queue design, there is no *registerforbuffersizeconfiguration
*/
desc->datalen = cpu_to_le16((u16)bi->size);
desc->retval = 0;
desc->cookie_high = 0;
desc->cookie_low = 0;
desc->params.generic.addr_high =
cpu_to_le32(upper_32_bits(bi->pa));
desc->params.generic.addr_low =
cpu_to_le32(lower_32_bits(bi->pa));
desc->params.generic.param0 = 0;
desc->params.generic.param1 = 0;
}
alloc_arq_bufs: return ret_code;
unwind_alloc_arq_bufs: /* don't try to free the one that failed... */
i--; for (; i >= 0; i--)
i40e_free_dma_mem(hw, &hw->aq.arq.r.arq_bi[i]);
i40e_free_virt_mem(hw, &hw->aq.arq.dma_head);
return ret_code;
}
/** *i40e_alloc_asq_bufs-Allocateemptybufferstructsforthesendqueue *@hw:pointertothehardwarestructure
**/ staticint i40e_alloc_asq_bufs(struct i40e_hw *hw)
{ struct i40e_dma_mem *bi; int ret_code; int i;
/* No mapped memory needed yet, just the buffer info structures */
ret_code = i40e_allocate_virt_mem(hw, &hw->aq.asq.dma_head,
(hw->aq.num_asq_entries * sizeof(struct i40e_dma_mem))); if (ret_code) goto alloc_asq_bufs;
hw->aq.asq.r.asq_bi = (struct i40e_dma_mem *)hw->aq.asq.dma_head.va;
/* allocate the mapped buffers */ for (i = 0; i < hw->aq.num_asq_entries; i++) {
bi = &hw->aq.asq.r.asq_bi[i];
ret_code = i40e_allocate_dma_mem(hw, bi,
hw->aq.asq_buf_size,
I40E_ADMINQ_DESC_ALIGNMENT); if (ret_code) goto unwind_alloc_asq_bufs;
}
alloc_asq_bufs: return ret_code;
unwind_alloc_asq_bufs: /* don't try to free the one that failed... */
i--; for (; i >= 0; i--)
i40e_free_dma_mem(hw, &hw->aq.asq.r.asq_bi[i]);
i40e_free_virt_mem(hw, &hw->aq.asq.dma_head);
/* only unmap if the address is non-NULL */ for (i = 0; i < hw->aq.num_asq_entries; i++) if (hw->aq.asq.r.asq_bi[i].pa)
i40e_free_dma_mem(hw, &hw->aq.asq.r.asq_bi[i]);
/* free the buffer info list */
i40e_free_virt_mem(hw, &hw->aq.asq.cmd_buf);
/* free the descriptor memory */
i40e_free_dma_mem(hw, &hw->aq.asq.desc_buf);
/* free the dma header */
i40e_free_virt_mem(hw, &hw->aq.asq.dma_head);
}
/* Clear Head and Tail */
wr32(hw, I40E_PF_ATQH, 0);
wr32(hw, I40E_PF_ATQT, 0);
/* set starting point */
wr32(hw, I40E_PF_ATQLEN, (hw->aq.num_asq_entries |
I40E_PF_ATQLEN_ATQENABLE_MASK));
wr32(hw, I40E_PF_ATQBAL, lower_32_bits(hw->aq.asq.desc_buf.pa));
wr32(hw, I40E_PF_ATQBAH, upper_32_bits(hw->aq.asq.desc_buf.pa));
/* Check one register to verify that config was applied */
reg = rd32(hw, I40E_PF_ATQBAL); if (reg != lower_32_bits(hw->aq.asq.desc_buf.pa))
ret_code = -EIO;
/* Clear Head and Tail */
wr32(hw, I40E_PF_ARQH, 0);
wr32(hw, I40E_PF_ARQT, 0);
/* set starting point */
wr32(hw, I40E_PF_ARQLEN, (hw->aq.num_arq_entries |
I40E_PF_ARQLEN_ARQENABLE_MASK));
wr32(hw, I40E_PF_ARQBAL, lower_32_bits(hw->aq.arq.desc_buf.pa));
wr32(hw, I40E_PF_ARQBAH, upper_32_bits(hw->aq.arq.desc_buf.pa));
/* Update tail in the HW to post pre-allocated buffers */
wr32(hw, I40E_PF_ARQT, hw->aq.num_arq_entries - 1);
/* Check one register to verify that config was applied */
reg = rd32(hw, I40E_PF_ARQBAL); if (reg != lower_32_bits(hw->aq.arq.desc_buf.pa))
ret_code = -EIO;
switch (hw->mac.type) { case I40E_MAC_XL710: if (i40e_is_aq_api_ver_ge(hw, 1,
I40E_MINOR_VER_GET_LINK_INFO_XL710)) {
set_bit(I40E_HW_CAP_AQ_PHY_ACCESS, hw->caps);
set_bit(I40E_HW_CAP_FW_LLDP_STOPPABLE, hw->caps); /* The ability to RX (not drop) 802.1ad frames */
set_bit(I40E_HW_CAP_802_1AD, hw->caps);
} if (i40e_is_aq_api_ver_ge(hw, 1, 5)) { /* Supported in FW API version higher than 1.4 */
set_bit(I40E_HW_CAP_GENEVE_OFFLOAD, hw->caps);
} if (i40e_is_fw_ver_lt(hw, 4, 33)) {
set_bit(I40E_HW_CAP_RESTART_AUTONEG, hw->caps); /* No DCB support for FW < v4.33 */
set_bit(I40E_HW_CAP_NO_DCB_SUPPORT, hw->caps);
} if (i40e_is_fw_ver_lt(hw, 4, 3)) { /* Disable FW LLDP if FW < v4.3 */
set_bit(I40E_HW_CAP_STOP_FW_LLDP, hw->caps);
} if (i40e_is_fw_ver_ge(hw, 4, 40)) { /* Use the FW Set LLDP MIB API if FW >= v4.40 */
set_bit(I40E_HW_CAP_USE_SET_LLDP_MIB, hw->caps);
} if (i40e_is_fw_ver_ge(hw, 6, 0)) { /* Enable PTP L4 if FW > v6.0 */
set_bit(I40E_HW_CAP_PTP_L4, hw->caps);
} break; case I40E_MAC_X722:
set_bit(I40E_HW_CAP_AQ_SRCTL_ACCESS_ENABLE, hw->caps);
set_bit(I40E_HW_CAP_NVM_READ_REQUIRES_LOCK, hw->caps);
set_bit(I40E_HW_CAP_RSS_AQ, hw->caps);
set_bit(I40E_HW_CAP_128_QP_RSS, hw->caps);
set_bit(I40E_HW_CAP_ATR_EVICT, hw->caps);
set_bit(I40E_HW_CAP_WB_ON_ITR, hw->caps);
set_bit(I40E_HW_CAP_MULTI_TCP_UDP_RSS_PCTYPE, hw->caps);
set_bit(I40E_HW_CAP_NO_PCI_LINK_CHECK, hw->caps);
set_bit(I40E_HW_CAP_USE_SET_LLDP_MIB, hw->caps);
set_bit(I40E_HW_CAP_GENEVE_OFFLOAD, hw->caps);
set_bit(I40E_HW_CAP_PTP_L4, hw->caps);
set_bit(I40E_HW_CAP_WOL_MC_MAGIC_PKT_WAKE, hw->caps);
set_bit(I40E_HW_CAP_OUTER_UDP_CSUM, hw->caps);
if (rd32(hw, I40E_GLQF_FDEVICTENA(1)) !=
I40E_FDEVICT_PCTYPE_DEFAULT) {
hw_warn(hw, "FD EVICT PCTYPES are not right, disable FD HW EVICT\n");
clear_bit(I40E_HW_CAP_ATR_EVICT, hw->caps);
}
if (i40e_is_aq_api_ver_ge(hw, 1,
I40E_MINOR_VER_FW_LLDP_STOPPABLE_X722))
set_bit(I40E_HW_CAP_FW_LLDP_STOPPABLE, hw->caps);
if (i40e_is_aq_api_ver_ge(hw, 1,
I40E_MINOR_VER_GET_LINK_INFO_X722))
set_bit(I40E_HW_CAP_AQ_PHY_ACCESS, hw->caps);
if (i40e_is_aq_api_ver_ge(hw, 1,
I40E_MINOR_VER_FW_REQUEST_FEC_X722))
set_bit(I40E_HW_CAP_X722_FEC_REQUEST, hw->caps);
fallthrough; default: break;
}
/* Newer versions of firmware require lock when reading the NVM */ if (i40e_is_aq_api_ver_ge(hw, 1, 5))
set_bit(I40E_HW_CAP_NVM_READ_REQUIRES_LOCK, hw->caps);
/* The ability to RX (not drop) 802.1ad frames was added in API 1.7 */ if (i40e_is_aq_api_ver_ge(hw, 1, 7))
set_bit(I40E_HW_CAP_802_1AD, hw->caps);
if (i40e_is_aq_api_ver_ge(hw, 1, 8))
set_bit(I40E_HW_CAP_FW_LLDP_PERSISTENT, hw->caps);
if (i40e_is_aq_api_ver_ge(hw, 1, 9))
set_bit(I40E_HW_CAP_AQ_PHY_ACCESS_EXTENDED, hw->caps);
}
/** *i40e_init_adminq-maininitializationroutineforAdminQueue *@hw:pointertothehardwarestructure * *Priortocallingthisfunction,drivers*MUST*setthefollowingfields *inthehw->aqstructure: *-hw->aq.num_asq_entries *-hw->aq.num_arq_entries *-hw->aq.arq_buf_size *-hw->aq.asq_buf_size
**/ int i40e_init_adminq(struct i40e_hw *hw)
{
u16 cfg_ptr, oem_hi, oem_lo;
u16 eetrack_lo, eetrack_hi; int retry = 0; int ret_code;
/* allocate the ASQ */
ret_code = i40e_init_asq(hw); if (ret_code) goto init_adminq_destroy_locks;
/* allocate the ARQ */
ret_code = i40e_init_arq(hw); if (ret_code) goto init_adminq_free_asq;
/* There are some cases where the firmware may not be quite ready *forAdminQoperations,soweretrytheAdminQsetupafewtimes *ifweseetimeoutsinthisfirstAQcall.
*/ do {
ret_code = i40e_aq_get_firmware_version(hw,
&hw->aq.fw_maj_ver,
&hw->aq.fw_min_ver,
&hw->aq.fw_build,
&hw->aq.api_maj_ver,
&hw->aq.api_min_ver,
NULL); if (ret_code != -EIO) break;
retry++;
msleep(100);
i40e_resume_aq(hw);
} while (retry < 10); if (ret_code != 0) goto init_adminq_free_arq;
/* Some features were introduced in different FW API version *fordifferentMACtype.
*/
i40e_set_hw_caps(hw);
if (hw->aq.asq.count == 0) {
i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, "AQTX: Admin queue not initialized.\n");
status = -EIO; goto asq_send_command_error;
}
hw->aq.asq_last_status = LIBIE_AQ_RC_OK;
val = rd32(hw, I40E_PF_ATQH); if (val >= hw->aq.num_asq_entries) {
i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, "AQTX: head overrun at %d\n", val);
status = -ENOSPC; goto asq_send_command_error;
}
details = I40E_ADMINQ_DETAILS(hw->aq.asq, hw->aq.asq.next_to_use); if (cmd_details) {
*details = *cmd_details;
/* If the cmd_details are defined copy the cookie. The *cpu_to_le32isnotneededherebecausethedataisignored *bytheFW,onlyusedbythedriver
*/ if (details->cookie) {
desc->cookie_high =
cpu_to_le32(upper_32_bits(details->cookie));
desc->cookie_low =
cpu_to_le32(lower_32_bits(details->cookie));
}
} else {
memset(details, 0, sizeof(struct i40e_asq_cmd_details));
}
/* clear requested flags and then set additional flags if defined */
desc->flags &= ~cpu_to_le16(details->flags_dis);
desc->flags |= cpu_to_le16(details->flags_ena);
if (buff_size > hw->aq.asq_buf_size) {
i40e_debug(hw,
I40E_DEBUG_AQ_MESSAGE, "AQTX: Invalid buffer size: %d.\n",
buff_size);
status = -EINVAL; goto asq_send_command_error;
}
if (details->postpone && !details->async) {
i40e_debug(hw,
I40E_DEBUG_AQ_MESSAGE, "AQTX: Async flag not set along with postpone flag");
status = -EINVAL; goto asq_send_command_error;
}
/* call clean and check queue available function to reclaim the *descriptorsthatwereprocessedbyFW,thefunctionreturnsthe *numberofdescavailable
*/ /* the clean function called here could be called in a separate thread *incaseofasynchronouscompletions
*/ if (i40e_clean_asq(hw) == 0) {
i40e_debug(hw,
I40E_DEBUG_AQ_MESSAGE, "AQTX: Error queue is full.\n");
status = -ENOSPC; goto asq_send_command_error;
}
/* initialize the temp desc pointer with the right desc */
desc_on_ring = I40E_ADMINQ_DESC(hw->aq.asq, hw->aq.asq.next_to_use);
/* if the desc is available copy the temp desc to the right place */
*desc_on_ring = *desc;
/* if buff is not NULL assume indirect command */ if (buff != NULL) {
dma_buff = &(hw->aq.asq.r.asq_bi[hw->aq.asq.next_to_use]); /* copy the user buff into the respective DMA buff */
memcpy(dma_buff->va, buff, buff_size);
desc_on_ring->datalen = cpu_to_le16(buff_size);
/* Update the address values in the desc with the pa value *forrespectivebuffer
*/
desc_on_ring->params.generic.addr_high =
cpu_to_le32(upper_32_bits(dma_buff->pa));
desc_on_ring->params.generic.addr_low =
cpu_to_le32(lower_32_bits(dma_buff->pa));
}
/* bump the tail */
i40e_debug(hw, I40E_DEBUG_AQ_COMMAND, "AQTX: desc and buffer:\n");
i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc_on_ring,
buff, buff_size);
(hw->aq.asq.next_to_use)++; if (hw->aq.asq.next_to_use == hw->aq.asq.count)
hw->aq.asq.next_to_use = 0; if (!details->postpone)
wr32(hw, I40E_PF_ATQT, hw->aq.asq.next_to_use);
/* if cmd_details are not defined or async flag is not set, *weneedtowaitfordescwriteback
*/ if (!details->async && !details->postpone) {
u32 total_delay = 0;
do { /* AQ designers suggest use of head for better *timingreliabilitythanDDbit
*/ if (i40e_asq_done(hw)) break;
if (is_atomic_context)
udelay(50); else
usleep_range(40, 60);
total_delay += 50;
} while (total_delay < hw->aq.asq_cmd_timeout);
}
/* if ready, copy the desc back to temp */ if (i40e_asq_done(hw)) {
*desc = *desc_on_ring; if (buff != NULL)
memcpy(buff, dma_buff->va, buff_size);
retval = le16_to_cpu(desc->retval); if (retval != 0) {
i40e_debug(hw,
I40E_DEBUG_AQ_MESSAGE, "AQTX: Command completed with error 0x%X.\n",
retval);
/* strip off FW internal code */
retval &= 0xff;
}
cmd_completed = true; if ((enum libie_aq_err)retval == LIBIE_AQ_RC_OK)
status = 0; elseif ((enum libie_aq_err)retval == LIBIE_AQ_RC_EBUSY)
status = -EBUSY; else
status = -EIO;
hw->aq.asq_last_status = (enum libie_aq_err)retval;
}
/* save writeback aq if requested */ if (details->wb_desc)
*details->wb_desc = *desc_on_ring;
/* update the error if time out occurred */ if ((!cmd_completed) &&
(!details->async && !details->postpone)) { if (rd32(hw, I40E_PF_ATQLEN) & I40E_GL_ATQLEN_ATQCRIT_MASK) {
i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, "AQTX: AQ Critical error.\n");
status = -EIO;
} else {
i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, "AQTX: Writeback timeout.\n");
status = -EIO;
}
}
asq_send_command_error: return status;
}
/** *i40e_asq_send_command_atomic-sendcommandtoAdminQueue *@hw:pointertothehwstruct *@desc:prefilleddescriptordescribingthecommand(nonDMAmem) *@buff:buffertouseforindirectcommands *@buff_size:sizeofbufferforindirectcommands *@cmd_details:pointertocommanddetailsstructure *@is_atomic_context:isthefunctioncalledinanatomiccontext? * *Acquiresthelockandcallsthemainsendcommandexecution *routine.
**/ int
i40e_asq_send_command_atomic(struct i40e_hw *hw, struct libie_aq_desc *desc, void *buff, /* can be NULL */
u16 buff_size, struct i40e_asq_cmd_details *cmd_details, bool is_atomic_context)
{ int status;
mutex_lock(&hw->aq.asq_mutex);
status = i40e_asq_send_command_atomic_exec(hw, desc, buff, buff_size,
cmd_details,
is_atomic_context);
mutex_unlock(&hw->aq.asq_mutex); return status;
}
int
i40e_asq_send_command(struct i40e_hw *hw, struct libie_aq_desc *desc, void *buff, /* can be NULL */ u16 buff_size, struct i40e_asq_cmd_details *cmd_details)
{ return i40e_asq_send_command_atomic(hw, desc, buff, buff_size,
cmd_details, false);
}
/* pre-clean the event info */
memset(&e->desc, 0, sizeof(e->desc));
/* take the lock before we start messing with the ring */
mutex_lock(&hw->aq.arq_mutex);
if (hw->aq.arq.count == 0) {
i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, "AQRX: Admin queue not initialized.\n");
ret_code = -EIO; goto clean_arq_element_err;
}
/* set next_to_use to head */
ntu = rd32(hw, I40E_PF_ARQH) & I40E_PF_ARQH_ARQH_MASK; if (ntu == ntc) { /* nothing to do - shouldn't need to update ring's values */
ret_code = -EALREADY; goto clean_arq_element_out;
}
/* now clean the next descriptor */
desc = I40E_ADMINQ_DESC(hw->aq.arq, ntc);
desc_idx = ntc;
hw->aq.arq_last_status =
(enum libie_aq_err)le16_to_cpu(desc->retval);
flags = le16_to_cpu(desc->flags); if (flags & LIBIE_AQ_FLAG_ERR) {
ret_code = -EIO;
i40e_debug(hw,
I40E_DEBUG_AQ_MESSAGE, "AQRX: Event received with error 0x%X.\n",
hw->aq.arq_last_status);
}
/* Restore the original datalen and buffer address in the desc, *FWupdatesdatalentoindicatetheeventmessage *size
*/
bi = &hw->aq.arq.r.arq_bi[ntc];
memset((void *)desc, 0, sizeof(struct libie_aq_desc));
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.