1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING".
22 * Contact Information:
23 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 ******************************************************************************/
28 #include "i40e_status.h"
29 #include "i40e_type.h"
30 #include "i40e_register.h"
31 #include "i40e_adminq.h"
32 #include "i40e_prototype.h"
34 static void i40e_resume_aq(struct i40e_hw *hw);
37 * i40e_adminq_init_regs - Initialize AdminQ registers
38 * @hw: pointer to the hardware structure
40 * This assumes the alloc_asq and alloc_arq functions have already been called
42 static void i40e_adminq_init_regs(struct i40e_hw *hw)
44 /* set head and tail registers in our local struct */
45 if (hw->mac.type == I40E_MAC_VF) {
46 hw->aq.asq.tail = I40E_VF_ATQT1;
47 hw->aq.asq.head = I40E_VF_ATQH1;
48 hw->aq.asq.len = I40E_VF_ATQLEN1;
49 hw->aq.arq.tail = I40E_VF_ARQT1;
50 hw->aq.arq.head = I40E_VF_ARQH1;
51 hw->aq.arq.len = I40E_VF_ARQLEN1;
53 hw->aq.asq.tail = I40E_PF_ATQT;
54 hw->aq.asq.head = I40E_PF_ATQH;
55 hw->aq.asq.len = I40E_PF_ATQLEN;
56 hw->aq.arq.tail = I40E_PF_ARQT;
57 hw->aq.arq.head = I40E_PF_ARQH;
58 hw->aq.arq.len = I40E_PF_ARQLEN;
63 * i40e_alloc_adminq_asq_ring - Allocate Admin Queue send rings
64 * @hw: pointer to the hardware structure
66 static i40e_status i40e_alloc_adminq_asq_ring(struct i40e_hw *hw)
70 ret_code = i40e_allocate_dma_mem(hw, &hw->aq.asq.desc_buf,
72 (hw->aq.num_asq_entries *
73 sizeof(struct i40e_aq_desc)),
74 I40E_ADMINQ_DESC_ALIGNMENT);
78 ret_code = i40e_allocate_virt_mem(hw, &hw->aq.asq.cmd_buf,
79 (hw->aq.num_asq_entries *
80 sizeof(struct i40e_asq_cmd_details)));
82 i40e_free_dma_mem(hw, &hw->aq.asq.desc_buf);
90 * i40e_alloc_adminq_arq_ring - Allocate Admin Queue receive rings
91 * @hw: pointer to the hardware structure
93 static i40e_status i40e_alloc_adminq_arq_ring(struct i40e_hw *hw)
97 ret_code = i40e_allocate_dma_mem(hw, &hw->aq.arq.desc_buf,
99 (hw->aq.num_arq_entries *
100 sizeof(struct i40e_aq_desc)),
101 I40E_ADMINQ_DESC_ALIGNMENT);
107 * i40e_free_adminq_asq - Free Admin Queue send rings
108 * @hw: pointer to the hardware structure
110 * This assumes the posted send buffers have already been cleaned
113 static void i40e_free_adminq_asq(struct i40e_hw *hw)
115 i40e_free_dma_mem(hw, &hw->aq.asq.desc_buf);
119 * i40e_free_adminq_arq - Free Admin Queue receive rings
120 * @hw: pointer to the hardware structure
122 * This assumes the posted receive buffers have already been cleaned
125 static void i40e_free_adminq_arq(struct i40e_hw *hw)
127 i40e_free_dma_mem(hw, &hw->aq.arq.desc_buf);
131 * i40e_alloc_arq_bufs - Allocate pre-posted buffers for the receive queue
132 * @hw: pointer to the hardware structure
134 static i40e_status i40e_alloc_arq_bufs(struct i40e_hw *hw)
136 i40e_status ret_code;
137 struct i40e_aq_desc *desc;
138 struct i40e_dma_mem *bi;
141 /* We'll be allocating the buffer info memory first, then we can
142 * allocate the mapped buffers for the event processing
145 /* buffer_info structures do not need alignment */
146 ret_code = i40e_allocate_virt_mem(hw, &hw->aq.arq.dma_head,
147 (hw->aq.num_arq_entries * sizeof(struct i40e_dma_mem)));
150 hw->aq.arq.r.arq_bi = (struct i40e_dma_mem *)hw->aq.arq.dma_head.va;
152 /* allocate the mapped buffers */
153 for (i = 0; i < hw->aq.num_arq_entries; i++) {
154 bi = &hw->aq.arq.r.arq_bi[i];
155 ret_code = i40e_allocate_dma_mem(hw, bi,
158 I40E_ADMINQ_DESC_ALIGNMENT);
160 goto unwind_alloc_arq_bufs;
162 /* now configure the descriptors for use */
163 desc = I40E_ADMINQ_DESC(hw->aq.arq, i);
165 desc->flags = cpu_to_le16(I40E_AQ_FLAG_BUF);
166 if (hw->aq.arq_buf_size > I40E_AQ_LARGE_BUF)
167 desc->flags |= cpu_to_le16(I40E_AQ_FLAG_LB);
169 /* This is in accordance with Admin queue design, there is no
170 * register for buffer size configuration
172 desc->datalen = cpu_to_le16((u16)bi->size);
174 desc->cookie_high = 0;
175 desc->cookie_low = 0;
176 desc->params.external.addr_high =
177 cpu_to_le32(upper_32_bits(bi->pa));
178 desc->params.external.addr_low =
179 cpu_to_le32(lower_32_bits(bi->pa));
180 desc->params.external.param0 = 0;
181 desc->params.external.param1 = 0;
187 unwind_alloc_arq_bufs:
188 /* don't try to free the one that failed... */
191 i40e_free_dma_mem(hw, &hw->aq.arq.r.arq_bi[i]);
192 i40e_free_virt_mem(hw, &hw->aq.arq.dma_head);
198 * i40e_alloc_asq_bufs - Allocate empty buffer structs for the send queue
199 * @hw: pointer to the hardware structure
201 static i40e_status i40e_alloc_asq_bufs(struct i40e_hw *hw)
203 i40e_status ret_code;
204 struct i40e_dma_mem *bi;
207 /* No mapped memory needed yet, just the buffer info structures */
208 ret_code = i40e_allocate_virt_mem(hw, &hw->aq.asq.dma_head,
209 (hw->aq.num_asq_entries * sizeof(struct i40e_dma_mem)));
212 hw->aq.asq.r.asq_bi = (struct i40e_dma_mem *)hw->aq.asq.dma_head.va;
214 /* allocate the mapped buffers */
215 for (i = 0; i < hw->aq.num_asq_entries; i++) {
216 bi = &hw->aq.asq.r.asq_bi[i];
217 ret_code = i40e_allocate_dma_mem(hw, bi,
220 I40E_ADMINQ_DESC_ALIGNMENT);
222 goto unwind_alloc_asq_bufs;
227 unwind_alloc_asq_bufs:
228 /* don't try to free the one that failed... */
231 i40e_free_dma_mem(hw, &hw->aq.asq.r.asq_bi[i]);
232 i40e_free_virt_mem(hw, &hw->aq.asq.dma_head);
238 * i40e_free_arq_bufs - Free receive queue buffer info elements
239 * @hw: pointer to the hardware structure
241 static void i40e_free_arq_bufs(struct i40e_hw *hw)
245 /* free descriptors */
246 for (i = 0; i < hw->aq.num_arq_entries; i++)
247 i40e_free_dma_mem(hw, &hw->aq.arq.r.arq_bi[i]);
249 /* free the descriptor memory */
250 i40e_free_dma_mem(hw, &hw->aq.arq.desc_buf);
252 /* free the dma header */
253 i40e_free_virt_mem(hw, &hw->aq.arq.dma_head);
257 * i40e_free_asq_bufs - Free send queue buffer info elements
258 * @hw: pointer to the hardware structure
260 static void i40e_free_asq_bufs(struct i40e_hw *hw)
264 /* only unmap if the address is non-NULL */
265 for (i = 0; i < hw->aq.num_asq_entries; i++)
266 if (hw->aq.asq.r.asq_bi[i].pa)
267 i40e_free_dma_mem(hw, &hw->aq.asq.r.asq_bi[i]);
269 /* free the buffer info list */
270 i40e_free_virt_mem(hw, &hw->aq.asq.cmd_buf);
272 /* free the descriptor memory */
273 i40e_free_dma_mem(hw, &hw->aq.asq.desc_buf);
275 /* free the dma header */
276 i40e_free_virt_mem(hw, &hw->aq.asq.dma_head);
280 * i40e_config_asq_regs - configure ASQ registers
281 * @hw: pointer to the hardware structure
283 * Configure base address and length registers for the transmit queue
285 static void i40e_config_asq_regs(struct i40e_hw *hw)
287 if (hw->mac.type == I40E_MAC_VF) {
288 /* configure the transmit queue */
289 wr32(hw, I40E_VF_ATQBAH1,
290 upper_32_bits(hw->aq.asq.desc_buf.pa));
291 wr32(hw, I40E_VF_ATQBAL1,
292 lower_32_bits(hw->aq.asq.desc_buf.pa));
293 wr32(hw, I40E_VF_ATQLEN1, (hw->aq.num_asq_entries |
294 I40E_VF_ATQLEN1_ATQENABLE_MASK));
296 /* configure the transmit queue */
297 wr32(hw, I40E_PF_ATQBAH,
298 upper_32_bits(hw->aq.asq.desc_buf.pa));
299 wr32(hw, I40E_PF_ATQBAL,
300 lower_32_bits(hw->aq.asq.desc_buf.pa));
301 wr32(hw, I40E_PF_ATQLEN, (hw->aq.num_asq_entries |
302 I40E_PF_ATQLEN_ATQENABLE_MASK));
307 * i40e_config_arq_regs - ARQ register configuration
308 * @hw: pointer to the hardware structure
310 * Configure base address and length registers for the receive (event queue)
312 static void i40e_config_arq_regs(struct i40e_hw *hw)
314 if (hw->mac.type == I40E_MAC_VF) {
315 /* configure the receive queue */
316 wr32(hw, I40E_VF_ARQBAH1,
317 upper_32_bits(hw->aq.arq.desc_buf.pa));
318 wr32(hw, I40E_VF_ARQBAL1,
319 lower_32_bits(hw->aq.arq.desc_buf.pa));
320 wr32(hw, I40E_VF_ARQLEN1, (hw->aq.num_arq_entries |
321 I40E_VF_ARQLEN1_ARQENABLE_MASK));
323 /* configure the receive queue */
324 wr32(hw, I40E_PF_ARQBAH,
325 upper_32_bits(hw->aq.arq.desc_buf.pa));
326 wr32(hw, I40E_PF_ARQBAL,
327 lower_32_bits(hw->aq.arq.desc_buf.pa));
328 wr32(hw, I40E_PF_ARQLEN, (hw->aq.num_arq_entries |
329 I40E_PF_ARQLEN_ARQENABLE_MASK));
332 /* Update tail in the HW to post pre-allocated buffers */
333 wr32(hw, hw->aq.arq.tail, hw->aq.num_arq_entries - 1);
337 * i40e_init_asq - main initialization routine for ASQ
338 * @hw: pointer to the hardware structure
340 * This is the main initialization routine for the Admin Send Queue
341 * Prior to calling this function, drivers *MUST* set the following fields
342 * in the hw->aq structure:
343 * - hw->aq.num_asq_entries
344 * - hw->aq.arq_buf_size
346 * Do *NOT* hold the lock when calling this as the memory allocation routines
347 * called are not going to be atomic context safe
349 static i40e_status i40e_init_asq(struct i40e_hw *hw)
351 i40e_status ret_code = 0;
353 if (hw->aq.asq.count > 0) {
354 /* queue already initialized */
355 ret_code = I40E_ERR_NOT_READY;
356 goto init_adminq_exit;
359 /* verify input for valid configuration */
360 if ((hw->aq.num_asq_entries == 0) ||
361 (hw->aq.asq_buf_size == 0)) {
362 ret_code = I40E_ERR_CONFIG;
363 goto init_adminq_exit;
366 hw->aq.asq.next_to_use = 0;
367 hw->aq.asq.next_to_clean = 0;
368 hw->aq.asq.count = hw->aq.num_asq_entries;
370 /* allocate the ring memory */
371 ret_code = i40e_alloc_adminq_asq_ring(hw);
373 goto init_adminq_exit;
375 /* allocate buffers in the rings */
376 ret_code = i40e_alloc_asq_bufs(hw);
378 goto init_adminq_free_rings;
380 /* initialize base registers */
381 i40e_config_asq_regs(hw);
384 goto init_adminq_exit;
386 init_adminq_free_rings:
387 i40e_free_adminq_asq(hw);
394 * i40e_init_arq - initialize ARQ
395 * @hw: pointer to the hardware structure
397 * The main initialization routine for the Admin Receive (Event) Queue.
398 * Prior to calling this function, drivers *MUST* set the following fields
399 * in the hw->aq structure:
400 * - hw->aq.num_asq_entries
401 * - hw->aq.arq_buf_size
403 * Do *NOT* hold the lock when calling this as the memory allocation routines
404 * called are not going to be atomic context safe
406 static i40e_status i40e_init_arq(struct i40e_hw *hw)
408 i40e_status ret_code = 0;
410 if (hw->aq.arq.count > 0) {
411 /* queue already initialized */
412 ret_code = I40E_ERR_NOT_READY;
413 goto init_adminq_exit;
416 /* verify input for valid configuration */
417 if ((hw->aq.num_arq_entries == 0) ||
418 (hw->aq.arq_buf_size == 0)) {
419 ret_code = I40E_ERR_CONFIG;
420 goto init_adminq_exit;
423 hw->aq.arq.next_to_use = 0;
424 hw->aq.arq.next_to_clean = 0;
425 hw->aq.arq.count = hw->aq.num_arq_entries;
427 /* allocate the ring memory */
428 ret_code = i40e_alloc_adminq_arq_ring(hw);
430 goto init_adminq_exit;
432 /* allocate buffers in the rings */
433 ret_code = i40e_alloc_arq_bufs(hw);
435 goto init_adminq_free_rings;
437 /* initialize base registers */
438 i40e_config_arq_regs(hw);
441 goto init_adminq_exit;
443 init_adminq_free_rings:
444 i40e_free_adminq_arq(hw);
451 * i40e_shutdown_asq - shutdown the ASQ
452 * @hw: pointer to the hardware structure
454 * The main shutdown routine for the Admin Send Queue
456 static i40e_status i40e_shutdown_asq(struct i40e_hw *hw)
458 i40e_status ret_code = 0;
460 if (hw->aq.asq.count == 0)
461 return I40E_ERR_NOT_READY;
463 /* Stop firmware AdminQ processing */
464 wr32(hw, hw->aq.asq.head, 0);
465 wr32(hw, hw->aq.asq.tail, 0);
466 wr32(hw, hw->aq.asq.len, 0);
468 /* make sure lock is available */
469 mutex_lock(&hw->aq.asq_mutex);
471 hw->aq.asq.count = 0; /* to indicate uninitialized queue */
473 /* free ring buffers */
474 i40e_free_asq_bufs(hw);
476 mutex_unlock(&hw->aq.asq_mutex);
482 * i40e_shutdown_arq - shutdown ARQ
483 * @hw: pointer to the hardware structure
485 * The main shutdown routine for the Admin Receive Queue
487 static i40e_status i40e_shutdown_arq(struct i40e_hw *hw)
489 i40e_status ret_code = 0;
491 if (hw->aq.arq.count == 0)
492 return I40E_ERR_NOT_READY;
494 /* Stop firmware AdminQ processing */
495 wr32(hw, hw->aq.arq.head, 0);
496 wr32(hw, hw->aq.arq.tail, 0);
497 wr32(hw, hw->aq.arq.len, 0);
499 /* make sure lock is available */
500 mutex_lock(&hw->aq.arq_mutex);
502 hw->aq.arq.count = 0; /* to indicate uninitialized queue */
504 /* free ring buffers */
505 i40e_free_arq_bufs(hw);
507 mutex_unlock(&hw->aq.arq_mutex);
513 * i40e_init_adminq - main initialization routine for Admin Queue
514 * @hw: pointer to the hardware structure
516 * Prior to calling this function, drivers *MUST* set the following fields
517 * in the hw->aq structure:
518 * - hw->aq.num_asq_entries
519 * - hw->aq.num_arq_entries
520 * - hw->aq.arq_buf_size
521 * - hw->aq.asq_buf_size
523 i40e_status i40e_init_adminq(struct i40e_hw *hw)
525 i40e_status ret_code;
526 u16 eetrack_lo, eetrack_hi;
529 /* verify input for valid configuration */
530 if ((hw->aq.num_arq_entries == 0) ||
531 (hw->aq.num_asq_entries == 0) ||
532 (hw->aq.arq_buf_size == 0) ||
533 (hw->aq.asq_buf_size == 0)) {
534 ret_code = I40E_ERR_CONFIG;
535 goto init_adminq_exit;
538 /* initialize locks */
539 mutex_init(&hw->aq.asq_mutex);
540 mutex_init(&hw->aq.arq_mutex);
542 /* Set up register offsets */
543 i40e_adminq_init_regs(hw);
545 /* allocate the ASQ */
546 ret_code = i40e_init_asq(hw);
548 goto init_adminq_destroy_locks;
550 /* allocate the ARQ */
551 ret_code = i40e_init_arq(hw);
553 goto init_adminq_free_asq;
555 /* There are some cases where the firmware may not be quite ready
556 * for AdminQ operations, so we retry the AdminQ setup a few times
557 * if we see timeouts in this first AQ call.
560 ret_code = i40e_aq_get_firmware_version(hw,
566 if (ret_code != I40E_ERR_ADMIN_QUEUE_TIMEOUT)
571 } while (retry < 10);
572 if (ret_code != I40E_SUCCESS)
573 goto init_adminq_free_arq;
575 /* get the NVM version info */
576 i40e_read_nvm_word(hw, I40E_SR_NVM_IMAGE_VERSION, &hw->nvm.version);
577 i40e_read_nvm_word(hw, I40E_SR_NVM_EETRACK_LO, &eetrack_lo);
578 i40e_read_nvm_word(hw, I40E_SR_NVM_EETRACK_HI, &eetrack_hi);
579 hw->nvm.eetrack = (eetrack_hi << 16) | eetrack_lo;
581 if (hw->aq.api_maj_ver != I40E_FW_API_VERSION_MAJOR ||
582 hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) {
583 ret_code = I40E_ERR_FIRMWARE_API_VERSION;
584 goto init_adminq_free_arq;
587 ret_code = i40e_aq_set_hmc_resource_profile(hw,
588 I40E_HMC_PROFILE_DEFAULT,
594 goto init_adminq_exit;
596 init_adminq_free_arq:
597 i40e_shutdown_arq(hw);
598 init_adminq_free_asq:
599 i40e_shutdown_asq(hw);
600 init_adminq_destroy_locks:
607 * i40e_shutdown_adminq - shutdown routine for the Admin Queue
608 * @hw: pointer to the hardware structure
610 i40e_status i40e_shutdown_adminq(struct i40e_hw *hw)
612 i40e_status ret_code = 0;
614 if (i40e_check_asq_alive(hw))
615 i40e_aq_queue_shutdown(hw, true);
617 i40e_shutdown_asq(hw);
618 i40e_shutdown_arq(hw);
620 /* destroy the locks */
626 * i40e_clean_asq - cleans Admin send queue
627 * @asq: pointer to the adminq send ring
629 * returns the number of free desc
631 static u16 i40e_clean_asq(struct i40e_hw *hw)
633 struct i40e_adminq_ring *asq = &(hw->aq.asq);
634 struct i40e_asq_cmd_details *details;
635 u16 ntc = asq->next_to_clean;
636 struct i40e_aq_desc desc_cb;
637 struct i40e_aq_desc *desc;
639 desc = I40E_ADMINQ_DESC(*asq, ntc);
640 details = I40E_ADMINQ_DETAILS(*asq, ntc);
641 while (rd32(hw, hw->aq.asq.head) != ntc) {
642 if (details->callback) {
643 I40E_ADMINQ_CALLBACK cb_func =
644 (I40E_ADMINQ_CALLBACK)details->callback;
646 cb_func(hw, &desc_cb);
648 memset((void *)desc, 0, sizeof(struct i40e_aq_desc));
649 memset((void *)details, 0,
650 sizeof(struct i40e_asq_cmd_details));
652 if (ntc == asq->count)
654 desc = I40E_ADMINQ_DESC(*asq, ntc);
655 details = I40E_ADMINQ_DETAILS(*asq, ntc);
658 asq->next_to_clean = ntc;
660 return I40E_DESC_UNUSED(asq);
664 * i40e_asq_done - check if FW has processed the Admin Send Queue
665 * @hw: pointer to the hw struct
667 * Returns true if the firmware has processed all descriptors on the
668 * admin send queue. Returns false if there are still requests pending.
670 static bool i40e_asq_done(struct i40e_hw *hw)
672 /* AQ designers suggest use of head for better
673 * timing reliability than DD bit
675 return rd32(hw, hw->aq.asq.head) == hw->aq.asq.next_to_use;
680 * i40e_asq_send_command - send command to Admin Queue
681 * @hw: pointer to the hw struct
682 * @desc: prefilled descriptor describing the command (non DMA mem)
683 * @buff: buffer to use for indirect commands
684 * @buff_size: size of buffer for indirect commands
685 * @cmd_details: pointer to command details structure
687 * This is the main send command driver routine for the Admin Queue send
688 * queue. It runs the queue, cleans the queue, etc
690 i40e_status i40e_asq_send_command(struct i40e_hw *hw,
691 struct i40e_aq_desc *desc,
692 void *buff, /* can be NULL */
694 struct i40e_asq_cmd_details *cmd_details)
696 i40e_status status = 0;
697 struct i40e_dma_mem *dma_buff = NULL;
698 struct i40e_asq_cmd_details *details;
699 struct i40e_aq_desc *desc_on_ring;
700 bool cmd_completed = false;
703 if (hw->aq.asq.count == 0) {
704 i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
705 "AQTX: Admin queue not initialized.\n");
706 status = I40E_ERR_QUEUE_EMPTY;
707 goto asq_send_command_exit;
710 details = I40E_ADMINQ_DETAILS(hw->aq.asq, hw->aq.asq.next_to_use);
712 *details = *cmd_details;
714 /* If the cmd_details are defined copy the cookie. The
715 * cpu_to_le32 is not needed here because the data is ignored
716 * by the FW, only used by the driver
718 if (details->cookie) {
720 cpu_to_le32(upper_32_bits(details->cookie));
722 cpu_to_le32(lower_32_bits(details->cookie));
725 memset(details, 0, sizeof(struct i40e_asq_cmd_details));
728 /* clear requested flags and then set additional flags if defined */
729 desc->flags &= ~cpu_to_le16(details->flags_dis);
730 desc->flags |= cpu_to_le16(details->flags_ena);
732 mutex_lock(&hw->aq.asq_mutex);
734 if (buff_size > hw->aq.asq_buf_size) {
736 I40E_DEBUG_AQ_MESSAGE,
737 "AQTX: Invalid buffer size: %d.\n",
739 status = I40E_ERR_INVALID_SIZE;
740 goto asq_send_command_error;
743 if (details->postpone && !details->async) {
745 I40E_DEBUG_AQ_MESSAGE,
746 "AQTX: Async flag not set along with postpone flag");
747 status = I40E_ERR_PARAM;
748 goto asq_send_command_error;
751 /* call clean and check queue available function to reclaim the
752 * descriptors that were processed by FW, the function returns the
753 * number of desc available
755 /* the clean function called here could be called in a separate thread
756 * in case of asynchronous completions
758 if (i40e_clean_asq(hw) == 0) {
760 I40E_DEBUG_AQ_MESSAGE,
761 "AQTX: Error queue is full.\n");
762 status = I40E_ERR_ADMIN_QUEUE_FULL;
763 goto asq_send_command_error;
766 /* initialize the temp desc pointer with the right desc */
767 desc_on_ring = I40E_ADMINQ_DESC(hw->aq.asq, hw->aq.asq.next_to_use);
769 /* if the desc is available copy the temp desc to the right place */
770 *desc_on_ring = *desc;
772 /* if buff is not NULL assume indirect command */
774 dma_buff = &(hw->aq.asq.r.asq_bi[hw->aq.asq.next_to_use]);
775 /* copy the user buff into the respective DMA buff */
776 memcpy(dma_buff->va, buff, buff_size);
777 desc_on_ring->datalen = cpu_to_le16(buff_size);
779 /* Update the address values in the desc with the pa value
780 * for respective buffer
782 desc_on_ring->params.external.addr_high =
783 cpu_to_le32(upper_32_bits(dma_buff->pa));
784 desc_on_ring->params.external.addr_low =
785 cpu_to_le32(lower_32_bits(dma_buff->pa));
789 i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc_on_ring, buff);
790 (hw->aq.asq.next_to_use)++;
791 if (hw->aq.asq.next_to_use == hw->aq.asq.count)
792 hw->aq.asq.next_to_use = 0;
793 if (!details->postpone)
794 wr32(hw, hw->aq.asq.tail, hw->aq.asq.next_to_use);
796 /* if cmd_details are not defined or async flag is not set,
797 * we need to wait for desc write back
799 if (!details->async && !details->postpone) {
804 /* AQ designers suggest use of head for better
805 * timing reliability than DD bit
807 if (i40e_asq_done(hw))
809 /* ugh! delay while spin_lock */
811 total_delay += delay_len;
812 } while (total_delay < I40E_ASQ_CMD_TIMEOUT);
815 /* if ready, copy the desc back to temp */
816 if (i40e_asq_done(hw)) {
817 *desc = *desc_on_ring;
819 memcpy(buff, dma_buff->va, buff_size);
820 retval = le16_to_cpu(desc->retval);
823 I40E_DEBUG_AQ_MESSAGE,
824 "AQTX: Command completed with error 0x%X.\n",
826 /* strip off FW internal code */
829 cmd_completed = true;
830 if ((enum i40e_admin_queue_err)retval == I40E_AQ_RC_OK)
833 status = I40E_ERR_ADMIN_QUEUE_ERROR;
834 hw->aq.asq_last_status = (enum i40e_admin_queue_err)retval;
837 /* update the error if time out occurred */
838 if ((!cmd_completed) &&
839 (!details->async && !details->postpone)) {
841 I40E_DEBUG_AQ_MESSAGE,
842 "AQTX: Writeback timeout.\n");
843 status = I40E_ERR_ADMIN_QUEUE_TIMEOUT;
846 asq_send_command_error:
847 mutex_unlock(&hw->aq.asq_mutex);
848 asq_send_command_exit:
853 * i40e_fill_default_direct_cmd_desc - AQ descriptor helper function
854 * @desc: pointer to the temp descriptor (non DMA mem)
855 * @opcode: the opcode can be used to decide which flags to turn off or on
857 * Fill the desc with default values
859 void i40e_fill_default_direct_cmd_desc(struct i40e_aq_desc *desc,
862 /* zero out the desc */
863 memset((void *)desc, 0, sizeof(struct i40e_aq_desc));
864 desc->opcode = cpu_to_le16(opcode);
865 desc->flags = cpu_to_le16(I40E_AQ_FLAG_EI | I40E_AQ_FLAG_SI);
869 * i40e_clean_arq_element
870 * @hw: pointer to the hw struct
871 * @e: event info from the receive descriptor, includes any buffers
872 * @pending: number of events that could be left to process
874 * This function cleans one Admin Receive Queue element and returns
875 * the contents through e. It can also return how many events are
876 * left to process through 'pending'
878 i40e_status i40e_clean_arq_element(struct i40e_hw *hw,
879 struct i40e_arq_event_info *e,
882 i40e_status ret_code = 0;
883 u16 ntc = hw->aq.arq.next_to_clean;
884 struct i40e_aq_desc *desc;
885 struct i40e_dma_mem *bi;
891 /* take the lock before we start messing with the ring */
892 mutex_lock(&hw->aq.arq_mutex);
894 /* set next_to_use to head */
895 ntu = (rd32(hw, hw->aq.arq.head) & I40E_PF_ARQH_ARQH_MASK);
897 /* nothing to do - shouldn't need to update ring's values */
899 I40E_DEBUG_AQ_MESSAGE,
900 "AQRX: Queue is empty.\n");
901 ret_code = I40E_ERR_ADMIN_QUEUE_NO_WORK;
902 goto clean_arq_element_out;
905 /* now clean the next descriptor */
906 desc = I40E_ADMINQ_DESC(hw->aq.arq, ntc);
909 I40E_DEBUG_AQ_COMMAND,
911 hw->aq.arq.r.arq_bi[desc_idx].va);
913 flags = le16_to_cpu(desc->flags);
914 if (flags & I40E_AQ_FLAG_ERR) {
915 ret_code = I40E_ERR_ADMIN_QUEUE_ERROR;
916 hw->aq.arq_last_status =
917 (enum i40e_admin_queue_err)le16_to_cpu(desc->retval);
919 I40E_DEBUG_AQ_MESSAGE,
920 "AQRX: Event received with error 0x%X.\n",
921 hw->aq.arq_last_status);
923 memcpy(&e->desc, desc, sizeof(struct i40e_aq_desc));
924 datalen = le16_to_cpu(desc->datalen);
925 e->msg_size = min(datalen, e->msg_size);
926 if (e->msg_buf != NULL && (e->msg_size != 0))
927 memcpy(e->msg_buf, hw->aq.arq.r.arq_bi[desc_idx].va,
931 /* Restore the original datalen and buffer address in the desc,
932 * FW updates datalen to indicate the event message
935 bi = &hw->aq.arq.r.arq_bi[ntc];
936 desc->datalen = cpu_to_le16((u16)bi->size);
937 desc->params.external.addr_high = cpu_to_le32(upper_32_bits(bi->pa));
938 desc->params.external.addr_low = cpu_to_le32(lower_32_bits(bi->pa));
940 /* set tail = the last cleaned desc index. */
941 wr32(hw, hw->aq.arq.tail, ntc);
942 /* ntc is updated to tail + 1 */
944 if (ntc == hw->aq.num_arq_entries)
946 hw->aq.arq.next_to_clean = ntc;
947 hw->aq.arq.next_to_use = ntu;
949 clean_arq_element_out:
950 /* Set pending if needed, unlock and return */
952 *pending = (ntc > ntu ? hw->aq.arq.count : 0) + (ntu - ntc);
953 mutex_unlock(&hw->aq.arq_mutex);
958 static void i40e_resume_aq(struct i40e_hw *hw)
960 /* Registers are reset after PF reset */
961 hw->aq.asq.next_to_use = 0;
962 hw->aq.asq.next_to_clean = 0;
964 i40e_config_asq_regs(hw);
966 hw->aq.arq.next_to_use = 0;
967 hw->aq.arq.next_to_clean = 0;
969 i40e_config_arq_regs(hw);