161ae650dSJack F Vogel /******************************************************************************
261ae650dSJack F Vogel
3f4cc2d17SEric Joyner Copyright (c) 2013-2018, Intel Corporation
461ae650dSJack F Vogel All rights reserved.
561ae650dSJack F Vogel
661ae650dSJack F Vogel Redistribution and use in source and binary forms, with or without
761ae650dSJack F Vogel modification, are permitted provided that the following conditions are met:
861ae650dSJack F Vogel
961ae650dSJack F Vogel 1. Redistributions of source code must retain the above copyright notice,
1061ae650dSJack F Vogel this list of conditions and the following disclaimer.
1161ae650dSJack F Vogel
1261ae650dSJack F Vogel 2. Redistributions in binary form must reproduce the above copyright
1361ae650dSJack F Vogel notice, this list of conditions and the following disclaimer in the
1461ae650dSJack F Vogel documentation and/or other materials provided with the distribution.
1561ae650dSJack F Vogel
1661ae650dSJack F Vogel 3. Neither the name of the Intel Corporation nor the names of its
1761ae650dSJack F Vogel contributors may be used to endorse or promote products derived from
1861ae650dSJack F Vogel this software without specific prior written permission.
1961ae650dSJack F Vogel
2061ae650dSJack F Vogel THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2161ae650dSJack F Vogel AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2261ae650dSJack F Vogel IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2361ae650dSJack F Vogel ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2461ae650dSJack F Vogel LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2561ae650dSJack F Vogel CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2661ae650dSJack F Vogel SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2761ae650dSJack F Vogel INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2861ae650dSJack F Vogel CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2961ae650dSJack F Vogel ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3061ae650dSJack F Vogel POSSIBILITY OF SUCH DAMAGE.
3161ae650dSJack F Vogel
3261ae650dSJack F Vogel ******************************************************************************/
3361ae650dSJack F Vogel
3461ae650dSJack F Vogel #include "i40e_status.h"
3561ae650dSJack F Vogel #include "i40e_type.h"
3661ae650dSJack F Vogel #include "i40e_register.h"
3761ae650dSJack F Vogel #include "i40e_adminq.h"
3861ae650dSJack F Vogel #include "i40e_prototype.h"
3961ae650dSJack F Vogel
4061ae650dSJack F Vogel /**
4161ae650dSJack F Vogel * i40e_adminq_init_regs - Initialize AdminQ registers
4261ae650dSJack F Vogel * @hw: pointer to the hardware structure
4361ae650dSJack F Vogel *
4461ae650dSJack F Vogel * This assumes the alloc_asq and alloc_arq functions have already been called
4561ae650dSJack F Vogel **/
i40e_adminq_init_regs(struct i40e_hw * hw)4661ae650dSJack F Vogel static void i40e_adminq_init_regs(struct i40e_hw *hw)
4761ae650dSJack F Vogel {
4861ae650dSJack F Vogel /* set head and tail registers in our local struct */
4961ae650dSJack F Vogel if (i40e_is_vf(hw)) {
5061ae650dSJack F Vogel hw->aq.asq.tail = I40E_VF_ATQT1;
5161ae650dSJack F Vogel hw->aq.asq.head = I40E_VF_ATQH1;
5261ae650dSJack F Vogel hw->aq.asq.len = I40E_VF_ATQLEN1;
5361ae650dSJack F Vogel hw->aq.asq.bal = I40E_VF_ATQBAL1;
5461ae650dSJack F Vogel hw->aq.asq.bah = I40E_VF_ATQBAH1;
5561ae650dSJack F Vogel hw->aq.arq.tail = I40E_VF_ARQT1;
5661ae650dSJack F Vogel hw->aq.arq.head = I40E_VF_ARQH1;
5761ae650dSJack F Vogel hw->aq.arq.len = I40E_VF_ARQLEN1;
5861ae650dSJack F Vogel hw->aq.arq.bal = I40E_VF_ARQBAL1;
5961ae650dSJack F Vogel hw->aq.arq.bah = I40E_VF_ARQBAH1;
6061ae650dSJack F Vogel } else {
6161ae650dSJack F Vogel hw->aq.asq.tail = I40E_PF_ATQT;
6261ae650dSJack F Vogel hw->aq.asq.head = I40E_PF_ATQH;
6361ae650dSJack F Vogel hw->aq.asq.len = I40E_PF_ATQLEN;
6461ae650dSJack F Vogel hw->aq.asq.bal = I40E_PF_ATQBAL;
6561ae650dSJack F Vogel hw->aq.asq.bah = I40E_PF_ATQBAH;
6661ae650dSJack F Vogel hw->aq.arq.tail = I40E_PF_ARQT;
6761ae650dSJack F Vogel hw->aq.arq.head = I40E_PF_ARQH;
6861ae650dSJack F Vogel hw->aq.arq.len = I40E_PF_ARQLEN;
6961ae650dSJack F Vogel hw->aq.arq.bal = I40E_PF_ARQBAL;
7061ae650dSJack F Vogel hw->aq.arq.bah = I40E_PF_ARQBAH;
7161ae650dSJack F Vogel }
7261ae650dSJack F Vogel }
7361ae650dSJack F Vogel
7461ae650dSJack F Vogel /**
7561ae650dSJack F Vogel * i40e_alloc_adminq_asq_ring - Allocate Admin Queue send rings
7661ae650dSJack F Vogel * @hw: pointer to the hardware structure
7761ae650dSJack F Vogel **/
i40e_alloc_adminq_asq_ring(struct i40e_hw * hw)7861ae650dSJack F Vogel enum i40e_status_code i40e_alloc_adminq_asq_ring(struct i40e_hw *hw)
7961ae650dSJack F Vogel {
8061ae650dSJack F Vogel enum i40e_status_code ret_code;
8161ae650dSJack F Vogel
8261ae650dSJack F Vogel ret_code = i40e_allocate_dma_mem(hw, &hw->aq.asq.desc_buf,
8361ae650dSJack F Vogel i40e_mem_atq_ring,
8461ae650dSJack F Vogel (hw->aq.num_asq_entries *
8561ae650dSJack F Vogel sizeof(struct i40e_aq_desc)),
8661ae650dSJack F Vogel I40E_ADMINQ_DESC_ALIGNMENT);
8761ae650dSJack F Vogel if (ret_code)
8861ae650dSJack F Vogel return ret_code;
8961ae650dSJack F Vogel
9061ae650dSJack F Vogel ret_code = i40e_allocate_virt_mem(hw, &hw->aq.asq.cmd_buf,
9161ae650dSJack F Vogel (hw->aq.num_asq_entries *
9261ae650dSJack F Vogel sizeof(struct i40e_asq_cmd_details)));
9361ae650dSJack F Vogel if (ret_code) {
9461ae650dSJack F Vogel i40e_free_dma_mem(hw, &hw->aq.asq.desc_buf);
9561ae650dSJack F Vogel return ret_code;
9661ae650dSJack F Vogel }
9761ae650dSJack F Vogel
9861ae650dSJack F Vogel return ret_code;
9961ae650dSJack F Vogel }
10061ae650dSJack F Vogel
10161ae650dSJack F Vogel /**
10261ae650dSJack F Vogel * i40e_alloc_adminq_arq_ring - Allocate Admin Queue receive rings
10361ae650dSJack F Vogel * @hw: pointer to the hardware structure
10461ae650dSJack F Vogel **/
i40e_alloc_adminq_arq_ring(struct i40e_hw * hw)10561ae650dSJack F Vogel enum i40e_status_code i40e_alloc_adminq_arq_ring(struct i40e_hw *hw)
10661ae650dSJack F Vogel {
10761ae650dSJack F Vogel enum i40e_status_code ret_code;
10861ae650dSJack F Vogel
10961ae650dSJack F Vogel ret_code = i40e_allocate_dma_mem(hw, &hw->aq.arq.desc_buf,
11061ae650dSJack F Vogel i40e_mem_arq_ring,
11161ae650dSJack F Vogel (hw->aq.num_arq_entries *
11261ae650dSJack F Vogel sizeof(struct i40e_aq_desc)),
11361ae650dSJack F Vogel I40E_ADMINQ_DESC_ALIGNMENT);
11461ae650dSJack F Vogel
11561ae650dSJack F Vogel return ret_code;
11661ae650dSJack F Vogel }
11761ae650dSJack F Vogel
11861ae650dSJack F Vogel /**
11961ae650dSJack F Vogel * i40e_free_adminq_asq - Free Admin Queue send rings
12061ae650dSJack F Vogel * @hw: pointer to the hardware structure
12161ae650dSJack F Vogel *
12261ae650dSJack F Vogel * This assumes the posted send buffers have already been cleaned
12361ae650dSJack F Vogel * and de-allocated
12461ae650dSJack F Vogel **/
i40e_free_adminq_asq(struct i40e_hw * hw)12561ae650dSJack F Vogel void i40e_free_adminq_asq(struct i40e_hw *hw)
12661ae650dSJack F Vogel {
127b4a7ce06SEric Joyner i40e_free_virt_mem(hw, &hw->aq.asq.cmd_buf);
12861ae650dSJack F Vogel i40e_free_dma_mem(hw, &hw->aq.asq.desc_buf);
12961ae650dSJack F Vogel }
13061ae650dSJack F Vogel
13161ae650dSJack F Vogel /**
13261ae650dSJack F Vogel * i40e_free_adminq_arq - Free Admin Queue receive rings
13361ae650dSJack F Vogel * @hw: pointer to the hardware structure
13461ae650dSJack F Vogel *
13561ae650dSJack F Vogel * This assumes the posted receive buffers have already been cleaned
13661ae650dSJack F Vogel * and de-allocated
13761ae650dSJack F Vogel **/
i40e_free_adminq_arq(struct i40e_hw * hw)13861ae650dSJack F Vogel void i40e_free_adminq_arq(struct i40e_hw *hw)
13961ae650dSJack F Vogel {
14061ae650dSJack F Vogel i40e_free_dma_mem(hw, &hw->aq.arq.desc_buf);
14161ae650dSJack F Vogel }
14261ae650dSJack F Vogel
14361ae650dSJack F Vogel /**
14461ae650dSJack F Vogel * i40e_alloc_arq_bufs - Allocate pre-posted buffers for the receive queue
14561ae650dSJack F Vogel * @hw: pointer to the hardware structure
14661ae650dSJack F Vogel **/
i40e_alloc_arq_bufs(struct i40e_hw * hw)14761ae650dSJack F Vogel static enum i40e_status_code i40e_alloc_arq_bufs(struct i40e_hw *hw)
14861ae650dSJack F Vogel {
14961ae650dSJack F Vogel enum i40e_status_code ret_code;
15061ae650dSJack F Vogel struct i40e_aq_desc *desc;
15161ae650dSJack F Vogel struct i40e_dma_mem *bi;
15261ae650dSJack F Vogel int i;
15361ae650dSJack F Vogel
15461ae650dSJack F Vogel /* We'll be allocating the buffer info memory first, then we can
15561ae650dSJack F Vogel * allocate the mapped buffers for the event processing
15661ae650dSJack F Vogel */
15761ae650dSJack F Vogel
15861ae650dSJack F Vogel /* buffer_info structures do not need alignment */
15961ae650dSJack F Vogel ret_code = i40e_allocate_virt_mem(hw, &hw->aq.arq.dma_head,
16061ae650dSJack F Vogel (hw->aq.num_arq_entries * sizeof(struct i40e_dma_mem)));
16161ae650dSJack F Vogel if (ret_code)
16261ae650dSJack F Vogel goto alloc_arq_bufs;
16361ae650dSJack F Vogel hw->aq.arq.r.arq_bi = (struct i40e_dma_mem *)hw->aq.arq.dma_head.va;
16461ae650dSJack F Vogel
16561ae650dSJack F Vogel /* allocate the mapped buffers */
16661ae650dSJack F Vogel for (i = 0; i < hw->aq.num_arq_entries; i++) {
16761ae650dSJack F Vogel bi = &hw->aq.arq.r.arq_bi[i];
16861ae650dSJack F Vogel ret_code = i40e_allocate_dma_mem(hw, bi,
16961ae650dSJack F Vogel i40e_mem_arq_buf,
17061ae650dSJack F Vogel hw->aq.arq_buf_size,
17161ae650dSJack F Vogel I40E_ADMINQ_DESC_ALIGNMENT);
17261ae650dSJack F Vogel if (ret_code)
17361ae650dSJack F Vogel goto unwind_alloc_arq_bufs;
17461ae650dSJack F Vogel
17561ae650dSJack F Vogel /* now configure the descriptors for use */
17661ae650dSJack F Vogel desc = I40E_ADMINQ_DESC(hw->aq.arq, i);
17761ae650dSJack F Vogel
17861ae650dSJack F Vogel desc->flags = CPU_TO_LE16(I40E_AQ_FLAG_BUF);
17961ae650dSJack F Vogel if (hw->aq.arq_buf_size > I40E_AQ_LARGE_BUF)
18061ae650dSJack F Vogel desc->flags |= CPU_TO_LE16(I40E_AQ_FLAG_LB);
18161ae650dSJack F Vogel desc->opcode = 0;
18261ae650dSJack F Vogel /* This is in accordance with Admin queue design, there is no
18361ae650dSJack F Vogel * register for buffer size configuration
18461ae650dSJack F Vogel */
18561ae650dSJack F Vogel desc->datalen = CPU_TO_LE16((u16)bi->size);
18661ae650dSJack F Vogel desc->retval = 0;
18761ae650dSJack F Vogel desc->cookie_high = 0;
18861ae650dSJack F Vogel desc->cookie_low = 0;
18961ae650dSJack F Vogel desc->params.external.addr_high =
19061ae650dSJack F Vogel CPU_TO_LE32(I40E_HI_DWORD(bi->pa));
19161ae650dSJack F Vogel desc->params.external.addr_low =
19261ae650dSJack F Vogel CPU_TO_LE32(I40E_LO_DWORD(bi->pa));
19361ae650dSJack F Vogel desc->params.external.param0 = 0;
19461ae650dSJack F Vogel desc->params.external.param1 = 0;
19561ae650dSJack F Vogel }
19661ae650dSJack F Vogel
19761ae650dSJack F Vogel alloc_arq_bufs:
19861ae650dSJack F Vogel return ret_code;
19961ae650dSJack F Vogel
20061ae650dSJack F Vogel unwind_alloc_arq_bufs:
20161ae650dSJack F Vogel /* don't try to free the one that failed... */
20261ae650dSJack F Vogel i--;
20361ae650dSJack F Vogel for (; i >= 0; i--)
20461ae650dSJack F Vogel i40e_free_dma_mem(hw, &hw->aq.arq.r.arq_bi[i]);
20561ae650dSJack F Vogel i40e_free_virt_mem(hw, &hw->aq.arq.dma_head);
20661ae650dSJack F Vogel
20761ae650dSJack F Vogel return ret_code;
20861ae650dSJack F Vogel }
20961ae650dSJack F Vogel
21061ae650dSJack F Vogel /**
21161ae650dSJack F Vogel * i40e_alloc_asq_bufs - Allocate empty buffer structs for the send queue
21261ae650dSJack F Vogel * @hw: pointer to the hardware structure
21361ae650dSJack F Vogel **/
i40e_alloc_asq_bufs(struct i40e_hw * hw)21461ae650dSJack F Vogel static enum i40e_status_code i40e_alloc_asq_bufs(struct i40e_hw *hw)
21561ae650dSJack F Vogel {
21661ae650dSJack F Vogel enum i40e_status_code ret_code;
21761ae650dSJack F Vogel struct i40e_dma_mem *bi;
21861ae650dSJack F Vogel int i;
21961ae650dSJack F Vogel
22061ae650dSJack F Vogel /* No mapped memory needed yet, just the buffer info structures */
22161ae650dSJack F Vogel ret_code = i40e_allocate_virt_mem(hw, &hw->aq.asq.dma_head,
22261ae650dSJack F Vogel (hw->aq.num_asq_entries * sizeof(struct i40e_dma_mem)));
22361ae650dSJack F Vogel if (ret_code)
22461ae650dSJack F Vogel goto alloc_asq_bufs;
22561ae650dSJack F Vogel hw->aq.asq.r.asq_bi = (struct i40e_dma_mem *)hw->aq.asq.dma_head.va;
22661ae650dSJack F Vogel
22761ae650dSJack F Vogel /* allocate the mapped buffers */
22861ae650dSJack F Vogel for (i = 0; i < hw->aq.num_asq_entries; i++) {
22961ae650dSJack F Vogel bi = &hw->aq.asq.r.asq_bi[i];
23061ae650dSJack F Vogel ret_code = i40e_allocate_dma_mem(hw, bi,
23161ae650dSJack F Vogel i40e_mem_asq_buf,
23261ae650dSJack F Vogel hw->aq.asq_buf_size,
23361ae650dSJack F Vogel I40E_ADMINQ_DESC_ALIGNMENT);
23461ae650dSJack F Vogel if (ret_code)
23561ae650dSJack F Vogel goto unwind_alloc_asq_bufs;
23661ae650dSJack F Vogel }
23761ae650dSJack F Vogel alloc_asq_bufs:
23861ae650dSJack F Vogel return ret_code;
23961ae650dSJack F Vogel
24061ae650dSJack F Vogel unwind_alloc_asq_bufs:
24161ae650dSJack F Vogel /* don't try to free the one that failed... */
24261ae650dSJack F Vogel i--;
24361ae650dSJack F Vogel for (; i >= 0; i--)
24461ae650dSJack F Vogel i40e_free_dma_mem(hw, &hw->aq.asq.r.asq_bi[i]);
24561ae650dSJack F Vogel i40e_free_virt_mem(hw, &hw->aq.asq.dma_head);
24661ae650dSJack F Vogel
24761ae650dSJack F Vogel return ret_code;
24861ae650dSJack F Vogel }
24961ae650dSJack F Vogel
25061ae650dSJack F Vogel /**
25161ae650dSJack F Vogel * i40e_free_arq_bufs - Free receive queue buffer info elements
25261ae650dSJack F Vogel * @hw: pointer to the hardware structure
25361ae650dSJack F Vogel **/
i40e_free_arq_bufs(struct i40e_hw * hw)25461ae650dSJack F Vogel static void i40e_free_arq_bufs(struct i40e_hw *hw)
25561ae650dSJack F Vogel {
25661ae650dSJack F Vogel int i;
25761ae650dSJack F Vogel
25861ae650dSJack F Vogel /* free descriptors */
25961ae650dSJack F Vogel for (i = 0; i < hw->aq.num_arq_entries; i++)
26061ae650dSJack F Vogel i40e_free_dma_mem(hw, &hw->aq.arq.r.arq_bi[i]);
26161ae650dSJack F Vogel
26261ae650dSJack F Vogel /* free the descriptor memory */
26361ae650dSJack F Vogel i40e_free_dma_mem(hw, &hw->aq.arq.desc_buf);
26461ae650dSJack F Vogel
26561ae650dSJack F Vogel /* free the dma header */
26661ae650dSJack F Vogel i40e_free_virt_mem(hw, &hw->aq.arq.dma_head);
26761ae650dSJack F Vogel }
26861ae650dSJack F Vogel
26961ae650dSJack F Vogel /**
27061ae650dSJack F Vogel * i40e_free_asq_bufs - Free send queue buffer info elements
27161ae650dSJack F Vogel * @hw: pointer to the hardware structure
27261ae650dSJack F Vogel **/
i40e_free_asq_bufs(struct i40e_hw * hw)27361ae650dSJack F Vogel static void i40e_free_asq_bufs(struct i40e_hw *hw)
27461ae650dSJack F Vogel {
27561ae650dSJack F Vogel int i;
27661ae650dSJack F Vogel
27761ae650dSJack F Vogel /* only unmap if the address is non-NULL */
27861ae650dSJack F Vogel for (i = 0; i < hw->aq.num_asq_entries; i++)
27961ae650dSJack F Vogel if (hw->aq.asq.r.asq_bi[i].pa)
28061ae650dSJack F Vogel i40e_free_dma_mem(hw, &hw->aq.asq.r.asq_bi[i]);
28161ae650dSJack F Vogel
28261ae650dSJack F Vogel /* free the buffer info list */
28361ae650dSJack F Vogel i40e_free_virt_mem(hw, &hw->aq.asq.cmd_buf);
28461ae650dSJack F Vogel
28561ae650dSJack F Vogel /* free the descriptor memory */
28661ae650dSJack F Vogel i40e_free_dma_mem(hw, &hw->aq.asq.desc_buf);
28761ae650dSJack F Vogel
28861ae650dSJack F Vogel /* free the dma header */
28961ae650dSJack F Vogel i40e_free_virt_mem(hw, &hw->aq.asq.dma_head);
29061ae650dSJack F Vogel }
29161ae650dSJack F Vogel
29261ae650dSJack F Vogel /**
29361ae650dSJack F Vogel * i40e_config_asq_regs - configure ASQ registers
29461ae650dSJack F Vogel * @hw: pointer to the hardware structure
29561ae650dSJack F Vogel *
29661ae650dSJack F Vogel * Configure base address and length registers for the transmit queue
29761ae650dSJack F Vogel **/
i40e_config_asq_regs(struct i40e_hw * hw)29861ae650dSJack F Vogel static enum i40e_status_code i40e_config_asq_regs(struct i40e_hw *hw)
29961ae650dSJack F Vogel {
30061ae650dSJack F Vogel enum i40e_status_code ret_code = I40E_SUCCESS;
30161ae650dSJack F Vogel u32 reg = 0;
30261ae650dSJack F Vogel
30361ae650dSJack F Vogel /* Clear Head and Tail */
30461ae650dSJack F Vogel wr32(hw, hw->aq.asq.head, 0);
30561ae650dSJack F Vogel wr32(hw, hw->aq.asq.tail, 0);
30661ae650dSJack F Vogel
30761ae650dSJack F Vogel /* set starting point */
308be771cdaSJack F Vogel if (!i40e_is_vf(hw))
30961ae650dSJack F Vogel wr32(hw, hw->aq.asq.len, (hw->aq.num_asq_entries |
31061ae650dSJack F Vogel I40E_PF_ATQLEN_ATQENABLE_MASK));
311be771cdaSJack F Vogel if (i40e_is_vf(hw))
312be771cdaSJack F Vogel wr32(hw, hw->aq.asq.len, (hw->aq.num_asq_entries |
313be771cdaSJack F Vogel I40E_VF_ATQLEN1_ATQENABLE_MASK));
31461ae650dSJack F Vogel wr32(hw, hw->aq.asq.bal, I40E_LO_DWORD(hw->aq.asq.desc_buf.pa));
31561ae650dSJack F Vogel wr32(hw, hw->aq.asq.bah, I40E_HI_DWORD(hw->aq.asq.desc_buf.pa));
31661ae650dSJack F Vogel
31761ae650dSJack F Vogel /* Check one register to verify that config was applied */
31861ae650dSJack F Vogel reg = rd32(hw, hw->aq.asq.bal);
31961ae650dSJack F Vogel if (reg != I40E_LO_DWORD(hw->aq.asq.desc_buf.pa))
32061ae650dSJack F Vogel ret_code = I40E_ERR_ADMIN_QUEUE_ERROR;
32161ae650dSJack F Vogel
32261ae650dSJack F Vogel return ret_code;
32361ae650dSJack F Vogel }
32461ae650dSJack F Vogel
32561ae650dSJack F Vogel /**
32661ae650dSJack F Vogel * i40e_config_arq_regs - ARQ register configuration
32761ae650dSJack F Vogel * @hw: pointer to the hardware structure
32861ae650dSJack F Vogel *
32961ae650dSJack F Vogel * Configure base address and length registers for the receive (event queue)
33061ae650dSJack F Vogel **/
i40e_config_arq_regs(struct i40e_hw * hw)33161ae650dSJack F Vogel static enum i40e_status_code i40e_config_arq_regs(struct i40e_hw *hw)
33261ae650dSJack F Vogel {
33361ae650dSJack F Vogel enum i40e_status_code ret_code = I40E_SUCCESS;
33461ae650dSJack F Vogel u32 reg = 0;
33561ae650dSJack F Vogel
33661ae650dSJack F Vogel /* Clear Head and Tail */
33761ae650dSJack F Vogel wr32(hw, hw->aq.arq.head, 0);
33861ae650dSJack F Vogel wr32(hw, hw->aq.arq.tail, 0);
33961ae650dSJack F Vogel
34061ae650dSJack F Vogel /* set starting point */
341be771cdaSJack F Vogel if (!i40e_is_vf(hw))
34261ae650dSJack F Vogel wr32(hw, hw->aq.arq.len, (hw->aq.num_arq_entries |
34361ae650dSJack F Vogel I40E_PF_ARQLEN_ARQENABLE_MASK));
344be771cdaSJack F Vogel if (i40e_is_vf(hw))
345be771cdaSJack F Vogel wr32(hw, hw->aq.arq.len, (hw->aq.num_arq_entries |
346be771cdaSJack F Vogel I40E_VF_ARQLEN1_ARQENABLE_MASK));
34761ae650dSJack F Vogel wr32(hw, hw->aq.arq.bal, I40E_LO_DWORD(hw->aq.arq.desc_buf.pa));
34861ae650dSJack F Vogel wr32(hw, hw->aq.arq.bah, I40E_HI_DWORD(hw->aq.arq.desc_buf.pa));
34961ae650dSJack F Vogel
35061ae650dSJack F Vogel /* Update tail in the HW to post pre-allocated buffers */
35161ae650dSJack F Vogel wr32(hw, hw->aq.arq.tail, hw->aq.num_arq_entries - 1);
35261ae650dSJack F Vogel
35361ae650dSJack F Vogel /* Check one register to verify that config was applied */
35461ae650dSJack F Vogel reg = rd32(hw, hw->aq.arq.bal);
35561ae650dSJack F Vogel if (reg != I40E_LO_DWORD(hw->aq.arq.desc_buf.pa))
35661ae650dSJack F Vogel ret_code = I40E_ERR_ADMIN_QUEUE_ERROR;
35761ae650dSJack F Vogel
35861ae650dSJack F Vogel return ret_code;
35961ae650dSJack F Vogel }
36061ae650dSJack F Vogel
36161ae650dSJack F Vogel /**
36261ae650dSJack F Vogel * i40e_init_asq - main initialization routine for ASQ
36361ae650dSJack F Vogel * @hw: pointer to the hardware structure
36461ae650dSJack F Vogel *
36561ae650dSJack F Vogel * This is the main initialization routine for the Admin Send Queue
36661ae650dSJack F Vogel * Prior to calling this function, drivers *MUST* set the following fields
36761ae650dSJack F Vogel * in the hw->aq structure:
36861ae650dSJack F Vogel * - hw->aq.num_asq_entries
36961ae650dSJack F Vogel * - hw->aq.arq_buf_size
37061ae650dSJack F Vogel *
37161ae650dSJack F Vogel * Do *NOT* hold the lock when calling this as the memory allocation routines
37261ae650dSJack F Vogel * called are not going to be atomic context safe
37361ae650dSJack F Vogel **/
i40e_init_asq(struct i40e_hw * hw)37461ae650dSJack F Vogel enum i40e_status_code i40e_init_asq(struct i40e_hw *hw)
37561ae650dSJack F Vogel {
37661ae650dSJack F Vogel enum i40e_status_code ret_code = I40E_SUCCESS;
37761ae650dSJack F Vogel
37861ae650dSJack F Vogel if (hw->aq.asq.count > 0) {
37961ae650dSJack F Vogel /* queue already initialized */
38061ae650dSJack F Vogel ret_code = I40E_ERR_NOT_READY;
38161ae650dSJack F Vogel goto init_adminq_exit;
38261ae650dSJack F Vogel }
38361ae650dSJack F Vogel
38461ae650dSJack F Vogel /* verify input for valid configuration */
38561ae650dSJack F Vogel if ((hw->aq.num_asq_entries == 0) ||
38661ae650dSJack F Vogel (hw->aq.asq_buf_size == 0)) {
38761ae650dSJack F Vogel ret_code = I40E_ERR_CONFIG;
38861ae650dSJack F Vogel goto init_adminq_exit;
38961ae650dSJack F Vogel }
39061ae650dSJack F Vogel
39161ae650dSJack F Vogel hw->aq.asq.next_to_use = 0;
39261ae650dSJack F Vogel hw->aq.asq.next_to_clean = 0;
39361ae650dSJack F Vogel
39461ae650dSJack F Vogel /* allocate the ring memory */
39561ae650dSJack F Vogel ret_code = i40e_alloc_adminq_asq_ring(hw);
39661ae650dSJack F Vogel if (ret_code != I40E_SUCCESS)
39761ae650dSJack F Vogel goto init_adminq_exit;
39861ae650dSJack F Vogel
39961ae650dSJack F Vogel /* allocate buffers in the rings */
40061ae650dSJack F Vogel ret_code = i40e_alloc_asq_bufs(hw);
40161ae650dSJack F Vogel if (ret_code != I40E_SUCCESS)
40261ae650dSJack F Vogel goto init_adminq_free_rings;
40361ae650dSJack F Vogel
40461ae650dSJack F Vogel /* initialize base registers */
40561ae650dSJack F Vogel ret_code = i40e_config_asq_regs(hw);
40661ae650dSJack F Vogel if (ret_code != I40E_SUCCESS)
407b4a7ce06SEric Joyner goto init_config_regs;
40861ae650dSJack F Vogel
40961ae650dSJack F Vogel /* success! */
4107f70bec6SEric Joyner hw->aq.asq.count = hw->aq.num_asq_entries;
41161ae650dSJack F Vogel goto init_adminq_exit;
41261ae650dSJack F Vogel
41361ae650dSJack F Vogel init_adminq_free_rings:
41461ae650dSJack F Vogel i40e_free_adminq_asq(hw);
415b4a7ce06SEric Joyner return ret_code;
416b4a7ce06SEric Joyner
417b4a7ce06SEric Joyner init_config_regs:
418b4a7ce06SEric Joyner i40e_free_asq_bufs(hw);
41961ae650dSJack F Vogel
42061ae650dSJack F Vogel init_adminq_exit:
42161ae650dSJack F Vogel return ret_code;
42261ae650dSJack F Vogel }
42361ae650dSJack F Vogel
42461ae650dSJack F Vogel /**
42561ae650dSJack F Vogel * i40e_init_arq - initialize ARQ
42661ae650dSJack F Vogel * @hw: pointer to the hardware structure
42761ae650dSJack F Vogel *
42861ae650dSJack F Vogel * The main initialization routine for the Admin Receive (Event) Queue.
42961ae650dSJack F Vogel * Prior to calling this function, drivers *MUST* set the following fields
43061ae650dSJack F Vogel * in the hw->aq structure:
43161ae650dSJack F Vogel * - hw->aq.num_asq_entries
43261ae650dSJack F Vogel * - hw->aq.arq_buf_size
43361ae650dSJack F Vogel *
43461ae650dSJack F Vogel * Do *NOT* hold the lock when calling this as the memory allocation routines
43561ae650dSJack F Vogel * called are not going to be atomic context safe
43661ae650dSJack F Vogel **/
i40e_init_arq(struct i40e_hw * hw)43761ae650dSJack F Vogel enum i40e_status_code i40e_init_arq(struct i40e_hw *hw)
43861ae650dSJack F Vogel {
43961ae650dSJack F Vogel enum i40e_status_code ret_code = I40E_SUCCESS;
44061ae650dSJack F Vogel
44161ae650dSJack F Vogel if (hw->aq.arq.count > 0) {
44261ae650dSJack F Vogel /* queue already initialized */
44361ae650dSJack F Vogel ret_code = I40E_ERR_NOT_READY;
44461ae650dSJack F Vogel goto init_adminq_exit;
44561ae650dSJack F Vogel }
44661ae650dSJack F Vogel
44761ae650dSJack F Vogel /* verify input for valid configuration */
44861ae650dSJack F Vogel if ((hw->aq.num_arq_entries == 0) ||
44961ae650dSJack F Vogel (hw->aq.arq_buf_size == 0)) {
45061ae650dSJack F Vogel ret_code = I40E_ERR_CONFIG;
45161ae650dSJack F Vogel goto init_adminq_exit;
45261ae650dSJack F Vogel }
45361ae650dSJack F Vogel
45461ae650dSJack F Vogel hw->aq.arq.next_to_use = 0;
45561ae650dSJack F Vogel hw->aq.arq.next_to_clean = 0;
45661ae650dSJack F Vogel
45761ae650dSJack F Vogel /* allocate the ring memory */
45861ae650dSJack F Vogel ret_code = i40e_alloc_adminq_arq_ring(hw);
45961ae650dSJack F Vogel if (ret_code != I40E_SUCCESS)
46061ae650dSJack F Vogel goto init_adminq_exit;
46161ae650dSJack F Vogel
46261ae650dSJack F Vogel /* allocate buffers in the rings */
46361ae650dSJack F Vogel ret_code = i40e_alloc_arq_bufs(hw);
46461ae650dSJack F Vogel if (ret_code != I40E_SUCCESS)
46561ae650dSJack F Vogel goto init_adminq_free_rings;
46661ae650dSJack F Vogel
46761ae650dSJack F Vogel /* initialize base registers */
46861ae650dSJack F Vogel ret_code = i40e_config_arq_regs(hw);
46961ae650dSJack F Vogel if (ret_code != I40E_SUCCESS)
47061ae650dSJack F Vogel goto init_adminq_free_rings;
47161ae650dSJack F Vogel
47261ae650dSJack F Vogel /* success! */
4737f70bec6SEric Joyner hw->aq.arq.count = hw->aq.num_arq_entries;
47461ae650dSJack F Vogel goto init_adminq_exit;
47561ae650dSJack F Vogel
47661ae650dSJack F Vogel init_adminq_free_rings:
47761ae650dSJack F Vogel i40e_free_adminq_arq(hw);
47861ae650dSJack F Vogel
47961ae650dSJack F Vogel init_adminq_exit:
48061ae650dSJack F Vogel return ret_code;
48161ae650dSJack F Vogel }
48261ae650dSJack F Vogel
48361ae650dSJack F Vogel /**
48461ae650dSJack F Vogel * i40e_shutdown_asq - shutdown the ASQ
48561ae650dSJack F Vogel * @hw: pointer to the hardware structure
48661ae650dSJack F Vogel *
48761ae650dSJack F Vogel * The main shutdown routine for the Admin Send Queue
48861ae650dSJack F Vogel **/
i40e_shutdown_asq(struct i40e_hw * hw)48961ae650dSJack F Vogel enum i40e_status_code i40e_shutdown_asq(struct i40e_hw *hw)
49061ae650dSJack F Vogel {
49161ae650dSJack F Vogel enum i40e_status_code ret_code = I40E_SUCCESS;
49261ae650dSJack F Vogel
493ac83ea83SEric Joyner i40e_acquire_spinlock(&hw->aq.asq_spinlock);
494ac83ea83SEric Joyner
495ac83ea83SEric Joyner if (hw->aq.asq.count == 0) {
496ac83ea83SEric Joyner ret_code = I40E_ERR_NOT_READY;
497ac83ea83SEric Joyner goto shutdown_asq_out;
498ac83ea83SEric Joyner }
49961ae650dSJack F Vogel
50061ae650dSJack F Vogel /* Stop firmware AdminQ processing */
50161ae650dSJack F Vogel wr32(hw, hw->aq.asq.head, 0);
50261ae650dSJack F Vogel wr32(hw, hw->aq.asq.tail, 0);
50361ae650dSJack F Vogel wr32(hw, hw->aq.asq.len, 0);
50461ae650dSJack F Vogel wr32(hw, hw->aq.asq.bal, 0);
50561ae650dSJack F Vogel wr32(hw, hw->aq.asq.bah, 0);
50661ae650dSJack F Vogel
50761ae650dSJack F Vogel hw->aq.asq.count = 0; /* to indicate uninitialized queue */
50861ae650dSJack F Vogel
50961ae650dSJack F Vogel /* free ring buffers */
51061ae650dSJack F Vogel i40e_free_asq_bufs(hw);
51161ae650dSJack F Vogel
512ac83ea83SEric Joyner shutdown_asq_out:
51361ae650dSJack F Vogel i40e_release_spinlock(&hw->aq.asq_spinlock);
51461ae650dSJack F Vogel return ret_code;
51561ae650dSJack F Vogel }
51661ae650dSJack F Vogel
51761ae650dSJack F Vogel /**
51861ae650dSJack F Vogel * i40e_shutdown_arq - shutdown ARQ
51961ae650dSJack F Vogel * @hw: pointer to the hardware structure
52061ae650dSJack F Vogel *
52161ae650dSJack F Vogel * The main shutdown routine for the Admin Receive Queue
52261ae650dSJack F Vogel **/
i40e_shutdown_arq(struct i40e_hw * hw)52361ae650dSJack F Vogel enum i40e_status_code i40e_shutdown_arq(struct i40e_hw *hw)
52461ae650dSJack F Vogel {
52561ae650dSJack F Vogel enum i40e_status_code ret_code = I40E_SUCCESS;
52661ae650dSJack F Vogel
527ac83ea83SEric Joyner i40e_acquire_spinlock(&hw->aq.arq_spinlock);
528ac83ea83SEric Joyner
529ac83ea83SEric Joyner if (hw->aq.arq.count == 0) {
530ac83ea83SEric Joyner ret_code = I40E_ERR_NOT_READY;
531ac83ea83SEric Joyner goto shutdown_arq_out;
532ac83ea83SEric Joyner }
53361ae650dSJack F Vogel
53461ae650dSJack F Vogel /* Stop firmware AdminQ processing */
53561ae650dSJack F Vogel wr32(hw, hw->aq.arq.head, 0);
53661ae650dSJack F Vogel wr32(hw, hw->aq.arq.tail, 0);
53761ae650dSJack F Vogel wr32(hw, hw->aq.arq.len, 0);
53861ae650dSJack F Vogel wr32(hw, hw->aq.arq.bal, 0);
53961ae650dSJack F Vogel wr32(hw, hw->aq.arq.bah, 0);
54061ae650dSJack F Vogel
54161ae650dSJack F Vogel hw->aq.arq.count = 0; /* to indicate uninitialized queue */
54261ae650dSJack F Vogel
54361ae650dSJack F Vogel /* free ring buffers */
54461ae650dSJack F Vogel i40e_free_arq_bufs(hw);
54561ae650dSJack F Vogel
546ac83ea83SEric Joyner shutdown_arq_out:
54761ae650dSJack F Vogel i40e_release_spinlock(&hw->aq.arq_spinlock);
54861ae650dSJack F Vogel return ret_code;
54961ae650dSJack F Vogel }
55061ae650dSJack F Vogel
55161ae650dSJack F Vogel /**
552d4683565SEric Joyner * i40e_resume_aq - resume AQ processing from 0
553d4683565SEric Joyner * @hw: pointer to the hardware structure
554d4683565SEric Joyner **/
i40e_resume_aq(struct i40e_hw * hw)555d4683565SEric Joyner static void i40e_resume_aq(struct i40e_hw *hw)
556d4683565SEric Joyner {
557d4683565SEric Joyner /* Registers are reset after PF reset */
558d4683565SEric Joyner hw->aq.asq.next_to_use = 0;
559d4683565SEric Joyner hw->aq.asq.next_to_clean = 0;
560d4683565SEric Joyner
561d4683565SEric Joyner i40e_config_asq_regs(hw);
562d4683565SEric Joyner
563d4683565SEric Joyner hw->aq.arq.next_to_use = 0;
564d4683565SEric Joyner hw->aq.arq.next_to_clean = 0;
565d4683565SEric Joyner
566d4683565SEric Joyner i40e_config_arq_regs(hw);
567d4683565SEric Joyner }
568d4683565SEric Joyner
569d4683565SEric Joyner /**
570b4a7ce06SEric Joyner * i40e_set_hw_flags - set HW flags
571b4a7ce06SEric Joyner * @hw: pointer to the hardware structure
572b4a7ce06SEric Joyner **/
i40e_set_hw_flags(struct i40e_hw * hw)573b4a7ce06SEric Joyner static void i40e_set_hw_flags(struct i40e_hw *hw)
574b4a7ce06SEric Joyner {
575b4a7ce06SEric Joyner struct i40e_adminq_info *aq = &hw->aq;
576b4a7ce06SEric Joyner
577b4a7ce06SEric Joyner hw->flags = 0;
578b4a7ce06SEric Joyner
579b4a7ce06SEric Joyner switch (hw->mac.type) {
580b4a7ce06SEric Joyner case I40E_MAC_XL710:
581b4a7ce06SEric Joyner if (aq->api_maj_ver > 1 ||
582b4a7ce06SEric Joyner (aq->api_maj_ver == 1 &&
583b4a7ce06SEric Joyner aq->api_min_ver >= I40E_MINOR_VER_GET_LINK_INFO_XL710)) {
584b4a7ce06SEric Joyner hw->flags |= I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE;
585b4a7ce06SEric Joyner hw->flags |= I40E_HW_FLAG_FW_LLDP_STOPPABLE;
586b4a7ce06SEric Joyner /* The ability to RX (not drop) 802.1ad frames */
587b4a7ce06SEric Joyner hw->flags |= I40E_HW_FLAG_802_1AD_CAPABLE;
588b4a7ce06SEric Joyner }
589b4a7ce06SEric Joyner break;
590b4a7ce06SEric Joyner case I40E_MAC_X722:
591b4a7ce06SEric Joyner hw->flags |= I40E_HW_FLAG_AQ_SRCTL_ACCESS_ENABLE |
592b4a7ce06SEric Joyner I40E_HW_FLAG_NVM_READ_REQUIRES_LOCK;
593b4a7ce06SEric Joyner
594b4a7ce06SEric Joyner if (aq->api_maj_ver > 1 ||
595b4a7ce06SEric Joyner (aq->api_maj_ver == 1 &&
596b4a7ce06SEric Joyner aq->api_min_ver >= I40E_MINOR_VER_FW_LLDP_STOPPABLE_X722))
597b4a7ce06SEric Joyner hw->flags |= I40E_HW_FLAG_FW_LLDP_STOPPABLE;
598b4a7ce06SEric Joyner
599b4a7ce06SEric Joyner if (aq->api_maj_ver > 1 ||
600b4a7ce06SEric Joyner (aq->api_maj_ver == 1 &&
601b4a7ce06SEric Joyner aq->api_min_ver >= I40E_MINOR_VER_GET_LINK_INFO_X722))
602b4a7ce06SEric Joyner hw->flags |= I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE;
603b4a7ce06SEric Joyner
604b4a7ce06SEric Joyner if (aq->api_maj_ver > 1 ||
605b4a7ce06SEric Joyner (aq->api_maj_ver == 1 &&
606b4a7ce06SEric Joyner aq->api_min_ver >= I40E_MINOR_VER_FW_REQUEST_FEC_X722))
607b4a7ce06SEric Joyner hw->flags |= I40E_HW_FLAG_X722_FEC_REQUEST_CAPABLE;
608b4a7ce06SEric Joyner
609b4a7ce06SEric Joyner /* fall through */
610b4a7ce06SEric Joyner default:
611b4a7ce06SEric Joyner break;
612b4a7ce06SEric Joyner }
613b4a7ce06SEric Joyner
614b4a7ce06SEric Joyner /* Newer versions of firmware require lock when reading the NVM */
615b4a7ce06SEric Joyner if (aq->api_maj_ver > 1 ||
616b4a7ce06SEric Joyner (aq->api_maj_ver == 1 &&
617b4a7ce06SEric Joyner aq->api_min_ver >= 5))
618b4a7ce06SEric Joyner hw->flags |= I40E_HW_FLAG_NVM_READ_REQUIRES_LOCK;
619b4a7ce06SEric Joyner
620b4a7ce06SEric Joyner if (aq->api_maj_ver > 1 ||
621b4a7ce06SEric Joyner (aq->api_maj_ver == 1 &&
622b4a7ce06SEric Joyner aq->api_min_ver >= 8)) {
623b4a7ce06SEric Joyner hw->flags |= I40E_HW_FLAG_FW_LLDP_PERSISTENT;
624b4a7ce06SEric Joyner hw->flags |= I40E_HW_FLAG_DROP_MODE;
625b4a7ce06SEric Joyner }
626b4a7ce06SEric Joyner
627b4a7ce06SEric Joyner if (aq->api_maj_ver > 1 ||
628b4a7ce06SEric Joyner (aq->api_maj_ver == 1 &&
629b4a7ce06SEric Joyner aq->api_min_ver >= 9))
630b4a7ce06SEric Joyner hw->flags |= I40E_HW_FLAG_AQ_PHY_ACCESS_EXTENDED;
631b4a7ce06SEric Joyner }
632b4a7ce06SEric Joyner
633b4a7ce06SEric Joyner /**
63461ae650dSJack F Vogel * i40e_init_adminq - main initialization routine for Admin Queue
63561ae650dSJack F Vogel * @hw: pointer to the hardware structure
63661ae650dSJack F Vogel *
63761ae650dSJack F Vogel * Prior to calling this function, drivers *MUST* set the following fields
63861ae650dSJack F Vogel * in the hw->aq structure:
63961ae650dSJack F Vogel * - hw->aq.num_asq_entries
64061ae650dSJack F Vogel * - hw->aq.num_arq_entries
64161ae650dSJack F Vogel * - hw->aq.arq_buf_size
64261ae650dSJack F Vogel * - hw->aq.asq_buf_size
64361ae650dSJack F Vogel **/
i40e_init_adminq(struct i40e_hw * hw)64461ae650dSJack F Vogel enum i40e_status_code i40e_init_adminq(struct i40e_hw *hw)
64561ae650dSJack F Vogel {
646b4a7ce06SEric Joyner struct i40e_adminq_info *aq = &hw->aq;
647b4a7ce06SEric Joyner enum i40e_status_code ret_code;
648*abf77452SKrzysztof Galazka u16 oem_hi = 0, oem_lo = 0;
649*abf77452SKrzysztof Galazka u16 eetrack_hi = 0;
650*abf77452SKrzysztof Galazka u16 eetrack_lo = 0;
651*abf77452SKrzysztof Galazka u16 cfg_ptr = 0;
65261ae650dSJack F Vogel int retry = 0;
653d4683565SEric Joyner
65461ae650dSJack F Vogel /* verify input for valid configuration */
655b4a7ce06SEric Joyner if (aq->num_arq_entries == 0 ||
656b4a7ce06SEric Joyner aq->num_asq_entries == 0 ||
657b4a7ce06SEric Joyner aq->arq_buf_size == 0 ||
658b4a7ce06SEric Joyner aq->asq_buf_size == 0) {
65961ae650dSJack F Vogel ret_code = I40E_ERR_CONFIG;
66061ae650dSJack F Vogel goto init_adminq_exit;
66161ae650dSJack F Vogel }
662b4a7ce06SEric Joyner i40e_init_spinlock(&aq->asq_spinlock);
663b4a7ce06SEric Joyner i40e_init_spinlock(&aq->arq_spinlock);
66461ae650dSJack F Vogel
66561ae650dSJack F Vogel /* Set up register offsets */
66661ae650dSJack F Vogel i40e_adminq_init_regs(hw);
66761ae650dSJack F Vogel
66861ae650dSJack F Vogel /* setup ASQ command write back timeout */
66961ae650dSJack F Vogel hw->aq.asq_cmd_timeout = I40E_ASQ_CMD_TIMEOUT;
67061ae650dSJack F Vogel
67161ae650dSJack F Vogel /* allocate the ASQ */
67261ae650dSJack F Vogel ret_code = i40e_init_asq(hw);
67361ae650dSJack F Vogel if (ret_code != I40E_SUCCESS)
67461ae650dSJack F Vogel goto init_adminq_destroy_spinlocks;
67561ae650dSJack F Vogel
67661ae650dSJack F Vogel /* allocate the ARQ */
67761ae650dSJack F Vogel ret_code = i40e_init_arq(hw);
67861ae650dSJack F Vogel if (ret_code != I40E_SUCCESS)
67961ae650dSJack F Vogel goto init_adminq_free_asq;
68061ae650dSJack F Vogel
681f247dc25SJack F Vogel /* VF has no need of firmware */
682f247dc25SJack F Vogel if (i40e_is_vf(hw))
68361ae650dSJack F Vogel goto init_adminq_exit;
68461ae650dSJack F Vogel /* There are some cases where the firmware may not be quite ready
68561ae650dSJack F Vogel * for AdminQ operations, so we retry the AdminQ setup a few times
68661ae650dSJack F Vogel * if we see timeouts in this first AQ call.
68761ae650dSJack F Vogel */
68861ae650dSJack F Vogel do {
68961ae650dSJack F Vogel ret_code = i40e_aq_get_firmware_version(hw,
690b4a7ce06SEric Joyner &aq->fw_maj_ver,
691b4a7ce06SEric Joyner &aq->fw_min_ver,
692b4a7ce06SEric Joyner &aq->fw_build,
693b4a7ce06SEric Joyner &aq->api_maj_ver,
694b4a7ce06SEric Joyner &aq->api_min_ver,
69561ae650dSJack F Vogel NULL);
69661ae650dSJack F Vogel if (ret_code != I40E_ERR_ADMIN_QUEUE_TIMEOUT)
69761ae650dSJack F Vogel break;
69861ae650dSJack F Vogel retry++;
69961ae650dSJack F Vogel i40e_msec_delay(100);
70061ae650dSJack F Vogel i40e_resume_aq(hw);
70161ae650dSJack F Vogel } while (retry < 10);
70261ae650dSJack F Vogel if (ret_code != I40E_SUCCESS)
70361ae650dSJack F Vogel goto init_adminq_free_arq;
70461ae650dSJack F Vogel
705b4a7ce06SEric Joyner /*
706b4a7ce06SEric Joyner * Some features were introduced in different FW API version
707b4a7ce06SEric Joyner * for different MAC type.
708b4a7ce06SEric Joyner */
709b4a7ce06SEric Joyner i40e_set_hw_flags(hw);
710b4a7ce06SEric Joyner
71161ae650dSJack F Vogel /* get the NVM version info */
712b6c8f260SJack F Vogel i40e_read_nvm_word(hw, I40E_SR_NVM_DEV_STARTER_VERSION,
713b6c8f260SJack F Vogel &hw->nvm.version);
71461ae650dSJack F Vogel i40e_read_nvm_word(hw, I40E_SR_NVM_EETRACK_LO, &eetrack_lo);
71561ae650dSJack F Vogel i40e_read_nvm_word(hw, I40E_SR_NVM_EETRACK_HI, &eetrack_hi);
71661ae650dSJack F Vogel hw->nvm.eetrack = (eetrack_hi << 16) | eetrack_lo;
717be771cdaSJack F Vogel i40e_read_nvm_word(hw, I40E_SR_BOOT_CONFIG_PTR, &cfg_ptr);
718be771cdaSJack F Vogel i40e_read_nvm_word(hw, (cfg_ptr + I40E_NVM_OEM_VER_OFF),
719be771cdaSJack F Vogel &oem_hi);
720be771cdaSJack F Vogel i40e_read_nvm_word(hw, (cfg_ptr + (I40E_NVM_OEM_VER_OFF + 1)),
721be771cdaSJack F Vogel &oem_lo);
722be771cdaSJack F Vogel hw->nvm.oem_ver = ((u32)oem_hi << 16) | oem_lo;
72361ae650dSJack F Vogel
724b4a7ce06SEric Joyner if (aq->api_maj_ver > I40E_FW_API_VERSION_MAJOR) {
72561ae650dSJack F Vogel ret_code = I40E_ERR_FIRMWARE_API_VERSION;
72661ae650dSJack F Vogel goto init_adminq_free_arq;
72761ae650dSJack F Vogel }
72861ae650dSJack F Vogel
72961ae650dSJack F Vogel /* pre-emptive resource lock release */
73061ae650dSJack F Vogel i40e_aq_release_resource(hw, I40E_NVM_RESOURCE_ID, 0, NULL);
7314294f337SSean Bruno hw->nvm_release_on_done = FALSE;
732f247dc25SJack F Vogel hw->nvmupd_state = I40E_NVMUPD_STATE_INIT;
73361ae650dSJack F Vogel
73461ae650dSJack F Vogel ret_code = I40E_SUCCESS;
73561ae650dSJack F Vogel
73661ae650dSJack F Vogel /* success! */
73761ae650dSJack F Vogel goto init_adminq_exit;
73861ae650dSJack F Vogel
73961ae650dSJack F Vogel init_adminq_free_arq:
74061ae650dSJack F Vogel i40e_shutdown_arq(hw);
74161ae650dSJack F Vogel init_adminq_free_asq:
74261ae650dSJack F Vogel i40e_shutdown_asq(hw);
74361ae650dSJack F Vogel init_adminq_destroy_spinlocks:
744b4a7ce06SEric Joyner i40e_destroy_spinlock(&aq->asq_spinlock);
745b4a7ce06SEric Joyner i40e_destroy_spinlock(&aq->arq_spinlock);
74661ae650dSJack F Vogel
74761ae650dSJack F Vogel init_adminq_exit:
74861ae650dSJack F Vogel return ret_code;
74961ae650dSJack F Vogel }
75061ae650dSJack F Vogel
75161ae650dSJack F Vogel /**
75261ae650dSJack F Vogel * i40e_shutdown_adminq - shutdown routine for the Admin Queue
75361ae650dSJack F Vogel * @hw: pointer to the hardware structure
75461ae650dSJack F Vogel **/
i40e_shutdown_adminq(struct i40e_hw * hw)75561ae650dSJack F Vogel enum i40e_status_code i40e_shutdown_adminq(struct i40e_hw *hw)
75661ae650dSJack F Vogel {
75761ae650dSJack F Vogel enum i40e_status_code ret_code = I40E_SUCCESS;
75861ae650dSJack F Vogel
75961ae650dSJack F Vogel if (i40e_check_asq_alive(hw))
76061ae650dSJack F Vogel i40e_aq_queue_shutdown(hw, TRUE);
76161ae650dSJack F Vogel
76261ae650dSJack F Vogel i40e_shutdown_asq(hw);
76361ae650dSJack F Vogel i40e_shutdown_arq(hw);
76461ae650dSJack F Vogel i40e_destroy_spinlock(&hw->aq.asq_spinlock);
76561ae650dSJack F Vogel i40e_destroy_spinlock(&hw->aq.arq_spinlock);
76661ae650dSJack F Vogel
767be771cdaSJack F Vogel if (hw->nvm_buff.va)
768be771cdaSJack F Vogel i40e_free_virt_mem(hw, &hw->nvm_buff);
769be771cdaSJack F Vogel
77061ae650dSJack F Vogel return ret_code;
77161ae650dSJack F Vogel }
77261ae650dSJack F Vogel
77361ae650dSJack F Vogel /**
77461ae650dSJack F Vogel * i40e_clean_asq - cleans Admin send queue
77561ae650dSJack F Vogel * @hw: pointer to the hardware structure
77661ae650dSJack F Vogel *
77761ae650dSJack F Vogel * returns the number of free desc
77861ae650dSJack F Vogel **/
i40e_clean_asq(struct i40e_hw * hw)77961ae650dSJack F Vogel u16 i40e_clean_asq(struct i40e_hw *hw)
78061ae650dSJack F Vogel {
78161ae650dSJack F Vogel struct i40e_adminq_ring *asq = &(hw->aq.asq);
78261ae650dSJack F Vogel struct i40e_asq_cmd_details *details;
78361ae650dSJack F Vogel u16 ntc = asq->next_to_clean;
78461ae650dSJack F Vogel struct i40e_aq_desc desc_cb;
78561ae650dSJack F Vogel struct i40e_aq_desc *desc;
78661ae650dSJack F Vogel
78761ae650dSJack F Vogel desc = I40E_ADMINQ_DESC(*asq, ntc);
78861ae650dSJack F Vogel details = I40E_ADMINQ_DETAILS(*asq, ntc);
78961ae650dSJack F Vogel while (rd32(hw, hw->aq.asq.head) != ntc) {
790b4a7ce06SEric Joyner i40e_debug(hw, I40E_DEBUG_AQ_COMMAND,
791be771cdaSJack F Vogel "ntc %d head %d.\n", ntc, rd32(hw, hw->aq.asq.head));
79261ae650dSJack F Vogel
79361ae650dSJack F Vogel if (details->callback) {
79461ae650dSJack F Vogel I40E_ADMINQ_CALLBACK cb_func =
79561ae650dSJack F Vogel (I40E_ADMINQ_CALLBACK)details->callback;
796be771cdaSJack F Vogel i40e_memcpy(&desc_cb, desc, sizeof(struct i40e_aq_desc),
797be771cdaSJack F Vogel I40E_DMA_TO_DMA);
79861ae650dSJack F Vogel cb_func(hw, &desc_cb);
79961ae650dSJack F Vogel }
80061ae650dSJack F Vogel i40e_memset(desc, 0, sizeof(*desc), I40E_DMA_MEM);
80161ae650dSJack F Vogel i40e_memset(details, 0, sizeof(*details), I40E_NONDMA_MEM);
80261ae650dSJack F Vogel ntc++;
80361ae650dSJack F Vogel if (ntc == asq->count)
80461ae650dSJack F Vogel ntc = 0;
80561ae650dSJack F Vogel desc = I40E_ADMINQ_DESC(*asq, ntc);
80661ae650dSJack F Vogel details = I40E_ADMINQ_DETAILS(*asq, ntc);
80761ae650dSJack F Vogel }
80861ae650dSJack F Vogel
80961ae650dSJack F Vogel asq->next_to_clean = ntc;
81061ae650dSJack F Vogel
81161ae650dSJack F Vogel return I40E_DESC_UNUSED(asq);
81261ae650dSJack F Vogel }
81361ae650dSJack F Vogel
81461ae650dSJack F Vogel /**
81561ae650dSJack F Vogel * i40e_asq_done - check if FW has processed the Admin Send Queue
81661ae650dSJack F Vogel * @hw: pointer to the hw struct
81761ae650dSJack F Vogel *
81861ae650dSJack F Vogel * Returns TRUE if the firmware has processed all descriptors on the
81961ae650dSJack F Vogel * admin send queue. Returns FALSE if there are still requests pending.
82061ae650dSJack F Vogel **/
i40e_asq_done(struct i40e_hw * hw)82161ae650dSJack F Vogel bool i40e_asq_done(struct i40e_hw *hw)
82261ae650dSJack F Vogel {
82361ae650dSJack F Vogel /* AQ designers suggest use of head for better
82461ae650dSJack F Vogel * timing reliability than DD bit
82561ae650dSJack F Vogel */
82661ae650dSJack F Vogel return rd32(hw, hw->aq.asq.head) == hw->aq.asq.next_to_use;
82761ae650dSJack F Vogel
82861ae650dSJack F Vogel }
82961ae650dSJack F Vogel
83061ae650dSJack F Vogel /**
83161ae650dSJack F Vogel * i40e_asq_send_command - send command to Admin Queue
83261ae650dSJack F Vogel * @hw: pointer to the hw struct
83361ae650dSJack F Vogel * @desc: prefilled descriptor describing the command (non DMA mem)
83461ae650dSJack F Vogel * @buff: buffer to use for indirect commands
83561ae650dSJack F Vogel * @buff_size: size of buffer for indirect commands
83661ae650dSJack F Vogel * @cmd_details: pointer to command details structure
83761ae650dSJack F Vogel *
83861ae650dSJack F Vogel * This is the main send command driver routine for the Admin Queue send
83961ae650dSJack F Vogel * queue. It runs the queue, cleans the queue, etc
84061ae650dSJack F Vogel **/
i40e_asq_send_command(struct i40e_hw * hw,struct i40e_aq_desc * desc,void * buff,u16 buff_size,struct i40e_asq_cmd_details * cmd_details)84161ae650dSJack F Vogel enum i40e_status_code i40e_asq_send_command(struct i40e_hw *hw,
84261ae650dSJack F Vogel struct i40e_aq_desc *desc,
84361ae650dSJack F Vogel void *buff, /* can be NULL */
84461ae650dSJack F Vogel u16 buff_size,
84561ae650dSJack F Vogel struct i40e_asq_cmd_details *cmd_details)
84661ae650dSJack F Vogel {
84761ae650dSJack F Vogel enum i40e_status_code status = I40E_SUCCESS;
84861ae650dSJack F Vogel struct i40e_dma_mem *dma_buff = NULL;
84961ae650dSJack F Vogel struct i40e_asq_cmd_details *details;
85061ae650dSJack F Vogel struct i40e_aq_desc *desc_on_ring;
85161ae650dSJack F Vogel bool cmd_completed = FALSE;
85261ae650dSJack F Vogel u16 retval = 0;
85361ae650dSJack F Vogel u32 val = 0;
85461ae650dSJack F Vogel
855ac83ea83SEric Joyner i40e_acquire_spinlock(&hw->aq.asq_spinlock);
856ac83ea83SEric Joyner
857be771cdaSJack F Vogel hw->aq.asq_last_status = I40E_AQ_RC_OK;
858be771cdaSJack F Vogel
859ac83ea83SEric Joyner if (hw->aq.asq.count == 0) {
860ac83ea83SEric Joyner i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
861ac83ea83SEric Joyner "AQTX: Admin queue not initialized.\n");
862ac83ea83SEric Joyner status = I40E_ERR_QUEUE_EMPTY;
863ac83ea83SEric Joyner goto asq_send_command_error;
864ac83ea83SEric Joyner }
865ac83ea83SEric Joyner
86661ae650dSJack F Vogel val = rd32(hw, hw->aq.asq.head);
86761ae650dSJack F Vogel if (val >= hw->aq.num_asq_entries) {
86861ae650dSJack F Vogel i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
86961ae650dSJack F Vogel "AQTX: head overrun at %d\n", val);
870b4a7ce06SEric Joyner status = I40E_ERR_ADMIN_QUEUE_FULL;
871ac83ea83SEric Joyner goto asq_send_command_error;
87261ae650dSJack F Vogel }
87361ae650dSJack F Vogel
87461ae650dSJack F Vogel details = I40E_ADMINQ_DETAILS(hw->aq.asq, hw->aq.asq.next_to_use);
87561ae650dSJack F Vogel if (cmd_details) {
87661ae650dSJack F Vogel i40e_memcpy(details,
87761ae650dSJack F Vogel cmd_details,
87861ae650dSJack F Vogel sizeof(struct i40e_asq_cmd_details),
87961ae650dSJack F Vogel I40E_NONDMA_TO_NONDMA);
88061ae650dSJack F Vogel
88161ae650dSJack F Vogel /* If the cmd_details are defined copy the cookie. The
88261ae650dSJack F Vogel * CPU_TO_LE32 is not needed here because the data is ignored
88361ae650dSJack F Vogel * by the FW, only used by the driver
88461ae650dSJack F Vogel */
88561ae650dSJack F Vogel if (details->cookie) {
88661ae650dSJack F Vogel desc->cookie_high =
88761ae650dSJack F Vogel CPU_TO_LE32(I40E_HI_DWORD(details->cookie));
88861ae650dSJack F Vogel desc->cookie_low =
88961ae650dSJack F Vogel CPU_TO_LE32(I40E_LO_DWORD(details->cookie));
89061ae650dSJack F Vogel }
89161ae650dSJack F Vogel } else {
89261ae650dSJack F Vogel i40e_memset(details, 0,
89361ae650dSJack F Vogel sizeof(struct i40e_asq_cmd_details),
89461ae650dSJack F Vogel I40E_NONDMA_MEM);
89561ae650dSJack F Vogel }
89661ae650dSJack F Vogel
89761ae650dSJack F Vogel /* clear requested flags and then set additional flags if defined */
89861ae650dSJack F Vogel desc->flags &= ~CPU_TO_LE16(details->flags_dis);
89961ae650dSJack F Vogel desc->flags |= CPU_TO_LE16(details->flags_ena);
90061ae650dSJack F Vogel
90161ae650dSJack F Vogel if (buff_size > hw->aq.asq_buf_size) {
90261ae650dSJack F Vogel i40e_debug(hw,
90361ae650dSJack F Vogel I40E_DEBUG_AQ_MESSAGE,
90461ae650dSJack F Vogel "AQTX: Invalid buffer size: %d.\n",
90561ae650dSJack F Vogel buff_size);
90661ae650dSJack F Vogel status = I40E_ERR_INVALID_SIZE;
90761ae650dSJack F Vogel goto asq_send_command_error;
90861ae650dSJack F Vogel }
90961ae650dSJack F Vogel
91061ae650dSJack F Vogel if (details->postpone && !details->async) {
91161ae650dSJack F Vogel i40e_debug(hw,
91261ae650dSJack F Vogel I40E_DEBUG_AQ_MESSAGE,
91361ae650dSJack F Vogel "AQTX: Async flag not set along with postpone flag");
91461ae650dSJack F Vogel status = I40E_ERR_PARAM;
91561ae650dSJack F Vogel goto asq_send_command_error;
91661ae650dSJack F Vogel }
91761ae650dSJack F Vogel
91861ae650dSJack F Vogel /* call clean and check queue available function to reclaim the
91961ae650dSJack F Vogel * descriptors that were processed by FW, the function returns the
92061ae650dSJack F Vogel * number of desc available
92161ae650dSJack F Vogel */
92261ae650dSJack F Vogel /* the clean function called here could be called in a separate thread
92361ae650dSJack F Vogel * in case of asynchronous completions
92461ae650dSJack F Vogel */
92561ae650dSJack F Vogel if (i40e_clean_asq(hw) == 0) {
92661ae650dSJack F Vogel i40e_debug(hw,
92761ae650dSJack F Vogel I40E_DEBUG_AQ_MESSAGE,
92861ae650dSJack F Vogel "AQTX: Error queue is full.\n");
92961ae650dSJack F Vogel status = I40E_ERR_ADMIN_QUEUE_FULL;
93061ae650dSJack F Vogel goto asq_send_command_error;
93161ae650dSJack F Vogel }
93261ae650dSJack F Vogel
93361ae650dSJack F Vogel /* initialize the temp desc pointer with the right desc */
93461ae650dSJack F Vogel desc_on_ring = I40E_ADMINQ_DESC(hw->aq.asq, hw->aq.asq.next_to_use);
93561ae650dSJack F Vogel
93661ae650dSJack F Vogel /* if the desc is available copy the temp desc to the right place */
93761ae650dSJack F Vogel i40e_memcpy(desc_on_ring, desc, sizeof(struct i40e_aq_desc),
93861ae650dSJack F Vogel I40E_NONDMA_TO_DMA);
93961ae650dSJack F Vogel
94061ae650dSJack F Vogel /* if buff is not NULL assume indirect command */
94161ae650dSJack F Vogel if (buff != NULL) {
94261ae650dSJack F Vogel dma_buff = &(hw->aq.asq.r.asq_bi[hw->aq.asq.next_to_use]);
94361ae650dSJack F Vogel /* copy the user buff into the respective DMA buff */
94461ae650dSJack F Vogel i40e_memcpy(dma_buff->va, buff, buff_size,
94561ae650dSJack F Vogel I40E_NONDMA_TO_DMA);
94661ae650dSJack F Vogel desc_on_ring->datalen = CPU_TO_LE16(buff_size);
94761ae650dSJack F Vogel
94861ae650dSJack F Vogel /* Update the address values in the desc with the pa value
94961ae650dSJack F Vogel * for respective buffer
95061ae650dSJack F Vogel */
95161ae650dSJack F Vogel desc_on_ring->params.external.addr_high =
95261ae650dSJack F Vogel CPU_TO_LE32(I40E_HI_DWORD(dma_buff->pa));
95361ae650dSJack F Vogel desc_on_ring->params.external.addr_low =
95461ae650dSJack F Vogel CPU_TO_LE32(I40E_LO_DWORD(dma_buff->pa));
95561ae650dSJack F Vogel }
95661ae650dSJack F Vogel
95761ae650dSJack F Vogel /* bump the tail */
958b4a7ce06SEric Joyner i40e_debug(hw, I40E_DEBUG_AQ_COMMAND, "AQTX: desc and buffer:\n");
95961ae650dSJack F Vogel i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc_on_ring,
96061ae650dSJack F Vogel buff, buff_size);
96161ae650dSJack F Vogel (hw->aq.asq.next_to_use)++;
96261ae650dSJack F Vogel if (hw->aq.asq.next_to_use == hw->aq.asq.count)
96361ae650dSJack F Vogel hw->aq.asq.next_to_use = 0;
96461ae650dSJack F Vogel if (!details->postpone)
96561ae650dSJack F Vogel wr32(hw, hw->aq.asq.tail, hw->aq.asq.next_to_use);
96661ae650dSJack F Vogel
96761ae650dSJack F Vogel /* if cmd_details are not defined or async flag is not set,
96861ae650dSJack F Vogel * we need to wait for desc write back
96961ae650dSJack F Vogel */
97061ae650dSJack F Vogel if (!details->async && !details->postpone) {
97161ae650dSJack F Vogel u32 total_delay = 0;
97261ae650dSJack F Vogel
97361ae650dSJack F Vogel do {
97461ae650dSJack F Vogel /* AQ designers suggest use of head for better
97561ae650dSJack F Vogel * timing reliability than DD bit
97661ae650dSJack F Vogel */
97761ae650dSJack F Vogel if (i40e_asq_done(hw))
97861ae650dSJack F Vogel break;
979ceebc2f3SEric Joyner i40e_usec_delay(50);
980ceebc2f3SEric Joyner total_delay += 50;
98161ae650dSJack F Vogel } while (total_delay < hw->aq.asq_cmd_timeout);
98261ae650dSJack F Vogel }
98361ae650dSJack F Vogel
98461ae650dSJack F Vogel /* if ready, copy the desc back to temp */
98561ae650dSJack F Vogel if (i40e_asq_done(hw)) {
98661ae650dSJack F Vogel i40e_memcpy(desc, desc_on_ring, sizeof(struct i40e_aq_desc),
98761ae650dSJack F Vogel I40E_DMA_TO_NONDMA);
98861ae650dSJack F Vogel if (buff != NULL)
98961ae650dSJack F Vogel i40e_memcpy(buff, dma_buff->va, buff_size,
99061ae650dSJack F Vogel I40E_DMA_TO_NONDMA);
99161ae650dSJack F Vogel retval = LE16_TO_CPU(desc->retval);
99261ae650dSJack F Vogel if (retval != 0) {
99361ae650dSJack F Vogel i40e_debug(hw,
99461ae650dSJack F Vogel I40E_DEBUG_AQ_MESSAGE,
99561ae650dSJack F Vogel "AQTX: Command completed with error 0x%X.\n",
99661ae650dSJack F Vogel retval);
99761ae650dSJack F Vogel
99861ae650dSJack F Vogel /* strip off FW internal code */
99961ae650dSJack F Vogel retval &= 0xff;
100061ae650dSJack F Vogel }
100161ae650dSJack F Vogel cmd_completed = TRUE;
100261ae650dSJack F Vogel if ((enum i40e_admin_queue_err)retval == I40E_AQ_RC_OK)
100361ae650dSJack F Vogel status = I40E_SUCCESS;
1004b4a7ce06SEric Joyner else if ((enum i40e_admin_queue_err)retval == I40E_AQ_RC_EBUSY)
1005b4a7ce06SEric Joyner status = I40E_ERR_NOT_READY;
100661ae650dSJack F Vogel else
100761ae650dSJack F Vogel status = I40E_ERR_ADMIN_QUEUE_ERROR;
100861ae650dSJack F Vogel hw->aq.asq_last_status = (enum i40e_admin_queue_err)retval;
100961ae650dSJack F Vogel }
101061ae650dSJack F Vogel
1011b4a7ce06SEric Joyner i40e_debug(hw, I40E_DEBUG_AQ_COMMAND,
101261ae650dSJack F Vogel "AQTX: desc and buffer writeback:\n");
101361ae650dSJack F Vogel i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc, buff, buff_size);
101461ae650dSJack F Vogel
1015be771cdaSJack F Vogel /* save writeback aq if requested */
1016be771cdaSJack F Vogel if (details->wb_desc)
1017be771cdaSJack F Vogel i40e_memcpy(details->wb_desc, desc_on_ring,
1018be771cdaSJack F Vogel sizeof(struct i40e_aq_desc), I40E_DMA_TO_NONDMA);
1019be771cdaSJack F Vogel
102061ae650dSJack F Vogel /* update the error if time out occurred */
102161ae650dSJack F Vogel if ((!cmd_completed) &&
102261ae650dSJack F Vogel (!details->async && !details->postpone)) {
1023ceebc2f3SEric Joyner if (rd32(hw, hw->aq.asq.len) & I40E_GL_ATQLEN_ATQCRIT_MASK) {
1024ceebc2f3SEric Joyner i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
1025ceebc2f3SEric Joyner "AQTX: AQ Critical error.\n");
1026ceebc2f3SEric Joyner status = I40E_ERR_ADMIN_QUEUE_CRITICAL_ERROR;
1027ceebc2f3SEric Joyner } else {
1028ceebc2f3SEric Joyner i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
102961ae650dSJack F Vogel "AQTX: Writeback timeout.\n");
103061ae650dSJack F Vogel status = I40E_ERR_ADMIN_QUEUE_TIMEOUT;
103161ae650dSJack F Vogel }
1032ceebc2f3SEric Joyner }
103361ae650dSJack F Vogel
103461ae650dSJack F Vogel asq_send_command_error:
103561ae650dSJack F Vogel i40e_release_spinlock(&hw->aq.asq_spinlock);
103661ae650dSJack F Vogel return status;
103761ae650dSJack F Vogel }
103861ae650dSJack F Vogel
103961ae650dSJack F Vogel /**
104061ae650dSJack F Vogel * i40e_fill_default_direct_cmd_desc - AQ descriptor helper function
104161ae650dSJack F Vogel * @desc: pointer to the temp descriptor (non DMA mem)
104261ae650dSJack F Vogel * @opcode: the opcode can be used to decide which flags to turn off or on
104361ae650dSJack F Vogel *
104461ae650dSJack F Vogel * Fill the desc with default values
104561ae650dSJack F Vogel **/
i40e_fill_default_direct_cmd_desc(struct i40e_aq_desc * desc,u16 opcode)104661ae650dSJack F Vogel void i40e_fill_default_direct_cmd_desc(struct i40e_aq_desc *desc,
104761ae650dSJack F Vogel u16 opcode)
104861ae650dSJack F Vogel {
104961ae650dSJack F Vogel /* zero out the desc */
105061ae650dSJack F Vogel i40e_memset((void *)desc, 0, sizeof(struct i40e_aq_desc),
105161ae650dSJack F Vogel I40E_NONDMA_MEM);
105261ae650dSJack F Vogel desc->opcode = CPU_TO_LE16(opcode);
105361ae650dSJack F Vogel desc->flags = CPU_TO_LE16(I40E_AQ_FLAG_SI);
105461ae650dSJack F Vogel }
105561ae650dSJack F Vogel
105661ae650dSJack F Vogel /**
105761ae650dSJack F Vogel * i40e_clean_arq_element
105861ae650dSJack F Vogel * @hw: pointer to the hw struct
105961ae650dSJack F Vogel * @e: event info from the receive descriptor, includes any buffers
106061ae650dSJack F Vogel * @pending: number of events that could be left to process
106161ae650dSJack F Vogel *
106261ae650dSJack F Vogel * This function cleans one Admin Receive Queue element and returns
106361ae650dSJack F Vogel * the contents through e. It can also return how many events are
106461ae650dSJack F Vogel * left to process through 'pending'
106561ae650dSJack F Vogel **/
i40e_clean_arq_element(struct i40e_hw * hw,struct i40e_arq_event_info * e,u16 * pending)106661ae650dSJack F Vogel enum i40e_status_code i40e_clean_arq_element(struct i40e_hw *hw,
106761ae650dSJack F Vogel struct i40e_arq_event_info *e,
106861ae650dSJack F Vogel u16 *pending)
106961ae650dSJack F Vogel {
107061ae650dSJack F Vogel enum i40e_status_code ret_code = I40E_SUCCESS;
107161ae650dSJack F Vogel u16 ntc = hw->aq.arq.next_to_clean;
107261ae650dSJack F Vogel struct i40e_aq_desc *desc;
107361ae650dSJack F Vogel struct i40e_dma_mem *bi;
107461ae650dSJack F Vogel u16 desc_idx;
107561ae650dSJack F Vogel u16 datalen;
107661ae650dSJack F Vogel u16 flags;
107761ae650dSJack F Vogel u16 ntu;
107861ae650dSJack F Vogel
10796d011ad5SEric Joyner /* pre-clean the event info */
10806d011ad5SEric Joyner i40e_memset(&e->desc, 0, sizeof(e->desc), I40E_NONDMA_MEM);
10816d011ad5SEric Joyner
108261ae650dSJack F Vogel /* take the lock before we start messing with the ring */
108361ae650dSJack F Vogel i40e_acquire_spinlock(&hw->aq.arq_spinlock);
108461ae650dSJack F Vogel
10857f70bec6SEric Joyner if (hw->aq.arq.count == 0) {
10867f70bec6SEric Joyner i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
10877f70bec6SEric Joyner "AQRX: Admin queue not initialized.\n");
10887f70bec6SEric Joyner ret_code = I40E_ERR_QUEUE_EMPTY;
10897f70bec6SEric Joyner goto clean_arq_element_err;
10907f70bec6SEric Joyner }
10917f70bec6SEric Joyner
109261ae650dSJack F Vogel /* set next_to_use to head */
1093be771cdaSJack F Vogel if (!i40e_is_vf(hw))
1094ceebc2f3SEric Joyner ntu = rd32(hw, hw->aq.arq.head) & I40E_PF_ARQH_ARQH_MASK;
1095ceebc2f3SEric Joyner else
1096ceebc2f3SEric Joyner ntu = rd32(hw, hw->aq.arq.head) & I40E_VF_ARQH1_ARQH_MASK;
109761ae650dSJack F Vogel if (ntu == ntc) {
109861ae650dSJack F Vogel /* nothing to do - shouldn't need to update ring's values */
109961ae650dSJack F Vogel ret_code = I40E_ERR_ADMIN_QUEUE_NO_WORK;
110061ae650dSJack F Vogel goto clean_arq_element_out;
110161ae650dSJack F Vogel }
110261ae650dSJack F Vogel
110361ae650dSJack F Vogel /* now clean the next descriptor */
110461ae650dSJack F Vogel desc = I40E_ADMINQ_DESC(hw->aq.arq, ntc);
110561ae650dSJack F Vogel desc_idx = ntc;
110661ae650dSJack F Vogel
1107cb6b8299SEric Joyner hw->aq.arq_last_status =
1108cb6b8299SEric Joyner (enum i40e_admin_queue_err)LE16_TO_CPU(desc->retval);
110961ae650dSJack F Vogel flags = LE16_TO_CPU(desc->flags);
111061ae650dSJack F Vogel if (flags & I40E_AQ_FLAG_ERR) {
111161ae650dSJack F Vogel ret_code = I40E_ERR_ADMIN_QUEUE_ERROR;
111261ae650dSJack F Vogel i40e_debug(hw,
111361ae650dSJack F Vogel I40E_DEBUG_AQ_MESSAGE,
111461ae650dSJack F Vogel "AQRX: Event received with error 0x%X.\n",
111561ae650dSJack F Vogel hw->aq.arq_last_status);
111661ae650dSJack F Vogel }
111761ae650dSJack F Vogel
111861ae650dSJack F Vogel i40e_memcpy(&e->desc, desc, sizeof(struct i40e_aq_desc),
111961ae650dSJack F Vogel I40E_DMA_TO_NONDMA);
112061ae650dSJack F Vogel datalen = LE16_TO_CPU(desc->datalen);
112161ae650dSJack F Vogel e->msg_len = min(datalen, e->buf_len);
112261ae650dSJack F Vogel if (e->msg_buf != NULL && (e->msg_len != 0))
112361ae650dSJack F Vogel i40e_memcpy(e->msg_buf,
112461ae650dSJack F Vogel hw->aq.arq.r.arq_bi[desc_idx].va,
112561ae650dSJack F Vogel e->msg_len, I40E_DMA_TO_NONDMA);
112661ae650dSJack F Vogel
1127b4a7ce06SEric Joyner i40e_debug(hw, I40E_DEBUG_AQ_COMMAND, "AQRX: desc and buffer:\n");
112861ae650dSJack F Vogel i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc, e->msg_buf,
112961ae650dSJack F Vogel hw->aq.arq_buf_size);
113061ae650dSJack F Vogel
113161ae650dSJack F Vogel /* Restore the original datalen and buffer address in the desc,
113261ae650dSJack F Vogel * FW updates datalen to indicate the event message
113361ae650dSJack F Vogel * size
113461ae650dSJack F Vogel */
113561ae650dSJack F Vogel bi = &hw->aq.arq.r.arq_bi[ntc];
113661ae650dSJack F Vogel i40e_memset((void *)desc, 0, sizeof(struct i40e_aq_desc), I40E_DMA_MEM);
113761ae650dSJack F Vogel
113861ae650dSJack F Vogel desc->flags = CPU_TO_LE16(I40E_AQ_FLAG_BUF);
113961ae650dSJack F Vogel if (hw->aq.arq_buf_size > I40E_AQ_LARGE_BUF)
114061ae650dSJack F Vogel desc->flags |= CPU_TO_LE16(I40E_AQ_FLAG_LB);
114161ae650dSJack F Vogel desc->datalen = CPU_TO_LE16((u16)bi->size);
114261ae650dSJack F Vogel desc->params.external.addr_high = CPU_TO_LE32(I40E_HI_DWORD(bi->pa));
114361ae650dSJack F Vogel desc->params.external.addr_low = CPU_TO_LE32(I40E_LO_DWORD(bi->pa));
114461ae650dSJack F Vogel
114561ae650dSJack F Vogel /* set tail = the last cleaned desc index. */
114661ae650dSJack F Vogel wr32(hw, hw->aq.arq.tail, ntc);
114761ae650dSJack F Vogel /* ntc is updated to tail + 1 */
114861ae650dSJack F Vogel ntc++;
114961ae650dSJack F Vogel if (ntc == hw->aq.num_arq_entries)
115061ae650dSJack F Vogel ntc = 0;
115161ae650dSJack F Vogel hw->aq.arq.next_to_clean = ntc;
115261ae650dSJack F Vogel hw->aq.arq.next_to_use = ntu;
115361ae650dSJack F Vogel
1154ceebc2f3SEric Joyner i40e_nvmupd_check_wait_event(hw, LE16_TO_CPU(e->desc.opcode), &e->desc);
11556d011ad5SEric Joyner clean_arq_element_out:
11566d011ad5SEric Joyner /* Set pending if needed, unlock and return */
11576d011ad5SEric Joyner if (pending != NULL)
11586d011ad5SEric Joyner *pending = (ntc > ntu ? hw->aq.arq.count : 0) + (ntu - ntc);
11596d011ad5SEric Joyner clean_arq_element_err:
11606d011ad5SEric Joyner i40e_release_spinlock(&hw->aq.arq_spinlock);
11616d011ad5SEric Joyner
116261ae650dSJack F Vogel return ret_code;
116361ae650dSJack F Vogel }
116461ae650dSJack F Vogel
1165