1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
4 #include "iavf_status.h"
6 #include "iavf_register.h"
7 #include "iavf_adminq.h"
8 #include "iavf_prototype.h"
11 * iavf_alloc_adminq_asq_ring - Allocate Admin Queue send rings
12 * @hw: pointer to the hardware structure
14 static enum iavf_status
iavf_alloc_adminq_asq_ring(struct iavf_hw
*hw
)
16 enum iavf_status ret_code
;
18 ret_code
= iavf_allocate_dma_mem(hw
, &hw
->aq
.asq
.desc_buf
,
20 (hw
->aq
.num_asq_entries
*
21 sizeof(struct iavf_aq_desc
)),
22 IAVF_ADMINQ_DESC_ALIGNMENT
);
26 ret_code
= iavf_allocate_virt_mem(hw
, &hw
->aq
.asq
.cmd_buf
,
27 (hw
->aq
.num_asq_entries
*
28 sizeof(struct iavf_asq_cmd_details
)));
30 iavf_free_dma_mem(hw
, &hw
->aq
.asq
.desc_buf
);
38 * iavf_alloc_adminq_arq_ring - Allocate Admin Queue receive rings
39 * @hw: pointer to the hardware structure
41 static enum iavf_status
iavf_alloc_adminq_arq_ring(struct iavf_hw
*hw
)
43 enum iavf_status ret_code
;
45 ret_code
= iavf_allocate_dma_mem(hw
, &hw
->aq
.arq
.desc_buf
,
47 (hw
->aq
.num_arq_entries
*
48 sizeof(struct iavf_aq_desc
)),
49 IAVF_ADMINQ_DESC_ALIGNMENT
);
55 * iavf_free_adminq_asq - Free Admin Queue send rings
56 * @hw: pointer to the hardware structure
58 * This assumes the posted send buffers have already been cleaned
61 static void iavf_free_adminq_asq(struct iavf_hw
*hw
)
63 iavf_free_dma_mem(hw
, &hw
->aq
.asq
.desc_buf
);
67 * iavf_free_adminq_arq - Free Admin Queue receive rings
68 * @hw: pointer to the hardware structure
70 * This assumes the posted receive buffers have already been cleaned
73 static void iavf_free_adminq_arq(struct iavf_hw
*hw
)
75 iavf_free_dma_mem(hw
, &hw
->aq
.arq
.desc_buf
);
79 * iavf_alloc_arq_bufs - Allocate pre-posted buffers for the receive queue
80 * @hw: pointer to the hardware structure
82 static enum iavf_status
iavf_alloc_arq_bufs(struct iavf_hw
*hw
)
84 struct iavf_aq_desc
*desc
;
85 struct iavf_dma_mem
*bi
;
86 enum iavf_status ret_code
;
89 /* We'll be allocating the buffer info memory first, then we can
90 * allocate the mapped buffers for the event processing
93 /* buffer_info structures do not need alignment */
94 ret_code
= iavf_allocate_virt_mem(hw
, &hw
->aq
.arq
.dma_head
,
95 (hw
->aq
.num_arq_entries
*
96 sizeof(struct iavf_dma_mem
)));
99 hw
->aq
.arq
.r
.arq_bi
= (struct iavf_dma_mem
*)hw
->aq
.arq
.dma_head
.va
;
101 /* allocate the mapped buffers */
102 for (i
= 0; i
< hw
->aq
.num_arq_entries
; i
++) {
103 bi
= &hw
->aq
.arq
.r
.arq_bi
[i
];
104 ret_code
= iavf_allocate_dma_mem(hw
, bi
,
107 IAVF_ADMINQ_DESC_ALIGNMENT
);
109 goto unwind_alloc_arq_bufs
;
111 /* now configure the descriptors for use */
112 desc
= IAVF_ADMINQ_DESC(hw
->aq
.arq
, i
);
114 desc
->flags
= cpu_to_le16(IAVF_AQ_FLAG_BUF
);
115 if (hw
->aq
.arq_buf_size
> IAVF_AQ_LARGE_BUF
)
116 desc
->flags
|= cpu_to_le16(IAVF_AQ_FLAG_LB
);
118 /* This is in accordance with Admin queue design, there is no
119 * register for buffer size configuration
121 desc
->datalen
= cpu_to_le16((u16
)bi
->size
);
123 desc
->cookie_high
= 0;
124 desc
->cookie_low
= 0;
125 desc
->params
.external
.addr_high
=
126 cpu_to_le32(upper_32_bits(bi
->pa
));
127 desc
->params
.external
.addr_low
=
128 cpu_to_le32(lower_32_bits(bi
->pa
));
129 desc
->params
.external
.param0
= 0;
130 desc
->params
.external
.param1
= 0;
136 unwind_alloc_arq_bufs
:
137 /* don't try to free the one that failed... */
140 iavf_free_dma_mem(hw
, &hw
->aq
.arq
.r
.arq_bi
[i
]);
141 iavf_free_virt_mem(hw
, &hw
->aq
.arq
.dma_head
);
147 * iavf_alloc_asq_bufs - Allocate empty buffer structs for the send queue
148 * @hw: pointer to the hardware structure
150 static enum iavf_status
iavf_alloc_asq_bufs(struct iavf_hw
*hw
)
152 struct iavf_dma_mem
*bi
;
153 enum iavf_status ret_code
;
156 /* No mapped memory needed yet, just the buffer info structures */
157 ret_code
= iavf_allocate_virt_mem(hw
, &hw
->aq
.asq
.dma_head
,
158 (hw
->aq
.num_asq_entries
*
159 sizeof(struct iavf_dma_mem
)));
162 hw
->aq
.asq
.r
.asq_bi
= (struct iavf_dma_mem
*)hw
->aq
.asq
.dma_head
.va
;
164 /* allocate the mapped buffers */
165 for (i
= 0; i
< hw
->aq
.num_asq_entries
; i
++) {
166 bi
= &hw
->aq
.asq
.r
.asq_bi
[i
];
167 ret_code
= iavf_allocate_dma_mem(hw
, bi
,
170 IAVF_ADMINQ_DESC_ALIGNMENT
);
172 goto unwind_alloc_asq_bufs
;
177 unwind_alloc_asq_bufs
:
178 /* don't try to free the one that failed... */
181 iavf_free_dma_mem(hw
, &hw
->aq
.asq
.r
.asq_bi
[i
]);
182 iavf_free_virt_mem(hw
, &hw
->aq
.asq
.dma_head
);
188 * iavf_free_arq_bufs - Free receive queue buffer info elements
189 * @hw: pointer to the hardware structure
191 static void iavf_free_arq_bufs(struct iavf_hw
*hw
)
195 /* free descriptors */
196 for (i
= 0; i
< hw
->aq
.num_arq_entries
; i
++)
197 iavf_free_dma_mem(hw
, &hw
->aq
.arq
.r
.arq_bi
[i
]);
199 /* free the descriptor memory */
200 iavf_free_dma_mem(hw
, &hw
->aq
.arq
.desc_buf
);
202 /* free the dma header */
203 iavf_free_virt_mem(hw
, &hw
->aq
.arq
.dma_head
);
207 * iavf_free_asq_bufs - Free send queue buffer info elements
208 * @hw: pointer to the hardware structure
210 static void iavf_free_asq_bufs(struct iavf_hw
*hw
)
214 /* only unmap if the address is non-NULL */
215 for (i
= 0; i
< hw
->aq
.num_asq_entries
; i
++)
216 if (hw
->aq
.asq
.r
.asq_bi
[i
].pa
)
217 iavf_free_dma_mem(hw
, &hw
->aq
.asq
.r
.asq_bi
[i
]);
219 /* free the buffer info list */
220 iavf_free_virt_mem(hw
, &hw
->aq
.asq
.cmd_buf
);
222 /* free the descriptor memory */
223 iavf_free_dma_mem(hw
, &hw
->aq
.asq
.desc_buf
);
225 /* free the dma header */
226 iavf_free_virt_mem(hw
, &hw
->aq
.asq
.dma_head
);
230 * iavf_config_asq_regs - configure ASQ registers
231 * @hw: pointer to the hardware structure
233 * Configure base address and length registers for the transmit queue
235 static enum iavf_status
iavf_config_asq_regs(struct iavf_hw
*hw
)
237 enum iavf_status ret_code
= 0;
240 /* Clear Head and Tail */
241 wr32(hw
, IAVF_VF_ATQH1
, 0);
242 wr32(hw
, IAVF_VF_ATQT1
, 0);
244 /* set starting point */
245 wr32(hw
, IAVF_VF_ATQLEN1
, (hw
->aq
.num_asq_entries
|
246 IAVF_VF_ATQLEN1_ATQENABLE_MASK
));
247 wr32(hw
, IAVF_VF_ATQBAL1
, lower_32_bits(hw
->aq
.asq
.desc_buf
.pa
));
248 wr32(hw
, IAVF_VF_ATQBAH1
, upper_32_bits(hw
->aq
.asq
.desc_buf
.pa
));
250 /* Check one register to verify that config was applied */
251 reg
= rd32(hw
, IAVF_VF_ATQBAL1
);
252 if (reg
!= lower_32_bits(hw
->aq
.asq
.desc_buf
.pa
))
253 ret_code
= IAVF_ERR_ADMIN_QUEUE_ERROR
;
259 * iavf_config_arq_regs - ARQ register configuration
260 * @hw: pointer to the hardware structure
262 * Configure base address and length registers for the receive (event queue)
264 static enum iavf_status
iavf_config_arq_regs(struct iavf_hw
*hw
)
266 enum iavf_status ret_code
= 0;
269 /* Clear Head and Tail */
270 wr32(hw
, IAVF_VF_ARQH1
, 0);
271 wr32(hw
, IAVF_VF_ARQT1
, 0);
273 /* set starting point */
274 wr32(hw
, IAVF_VF_ARQLEN1
, (hw
->aq
.num_arq_entries
|
275 IAVF_VF_ARQLEN1_ARQENABLE_MASK
));
276 wr32(hw
, IAVF_VF_ARQBAL1
, lower_32_bits(hw
->aq
.arq
.desc_buf
.pa
));
277 wr32(hw
, IAVF_VF_ARQBAH1
, upper_32_bits(hw
->aq
.arq
.desc_buf
.pa
));
279 /* Update tail in the HW to post pre-allocated buffers */
280 wr32(hw
, IAVF_VF_ARQT1
, hw
->aq
.num_arq_entries
- 1);
282 /* Check one register to verify that config was applied */
283 reg
= rd32(hw
, IAVF_VF_ARQBAL1
);
284 if (reg
!= lower_32_bits(hw
->aq
.arq
.desc_buf
.pa
))
285 ret_code
= IAVF_ERR_ADMIN_QUEUE_ERROR
;
291 * iavf_init_asq - main initialization routine for ASQ
292 * @hw: pointer to the hardware structure
294 * This is the main initialization routine for the Admin Send Queue
295 * Prior to calling this function, drivers *MUST* set the following fields
296 * in the hw->aq structure:
297 * - hw->aq.num_asq_entries
298 * - hw->aq.arq_buf_size
300 * Do *NOT* hold the lock when calling this as the memory allocation routines
301 * called are not going to be atomic context safe
303 static enum iavf_status
iavf_init_asq(struct iavf_hw
*hw
)
305 enum iavf_status ret_code
= 0;
308 if (hw
->aq
.asq
.count
> 0) {
309 /* queue already initialized */
310 ret_code
= IAVF_ERR_NOT_READY
;
311 goto init_adminq_exit
;
314 /* verify input for valid configuration */
315 if ((hw
->aq
.num_asq_entries
== 0) ||
316 (hw
->aq
.asq_buf_size
== 0)) {
317 ret_code
= IAVF_ERR_CONFIG
;
318 goto init_adminq_exit
;
321 hw
->aq
.asq
.next_to_use
= 0;
322 hw
->aq
.asq
.next_to_clean
= 0;
324 /* allocate the ring memory */
325 ret_code
= iavf_alloc_adminq_asq_ring(hw
);
327 goto init_adminq_exit
;
329 /* allocate buffers in the rings */
330 ret_code
= iavf_alloc_asq_bufs(hw
);
332 goto init_adminq_free_rings
;
334 /* initialize base registers */
335 ret_code
= iavf_config_asq_regs(hw
);
337 goto init_free_asq_bufs
;
340 hw
->aq
.asq
.count
= hw
->aq
.num_asq_entries
;
341 goto init_adminq_exit
;
344 for (i
= 0; i
< hw
->aq
.num_asq_entries
; i
++)
345 iavf_free_dma_mem(hw
, &hw
->aq
.asq
.r
.asq_bi
[i
]);
346 iavf_free_virt_mem(hw
, &hw
->aq
.asq
.dma_head
);
348 init_adminq_free_rings
:
349 iavf_free_adminq_asq(hw
);
356 * iavf_init_arq - initialize ARQ
357 * @hw: pointer to the hardware structure
359 * The main initialization routine for the Admin Receive (Event) Queue.
360 * Prior to calling this function, drivers *MUST* set the following fields
361 * in the hw->aq structure:
362 * - hw->aq.num_asq_entries
363 * - hw->aq.arq_buf_size
365 * Do *NOT* hold the lock when calling this as the memory allocation routines
366 * called are not going to be atomic context safe
368 static enum iavf_status
iavf_init_arq(struct iavf_hw
*hw
)
370 enum iavf_status ret_code
= 0;
373 if (hw
->aq
.arq
.count
> 0) {
374 /* queue already initialized */
375 ret_code
= IAVF_ERR_NOT_READY
;
376 goto init_adminq_exit
;
379 /* verify input for valid configuration */
380 if ((hw
->aq
.num_arq_entries
== 0) ||
381 (hw
->aq
.arq_buf_size
== 0)) {
382 ret_code
= IAVF_ERR_CONFIG
;
383 goto init_adminq_exit
;
386 hw
->aq
.arq
.next_to_use
= 0;
387 hw
->aq
.arq
.next_to_clean
= 0;
389 /* allocate the ring memory */
390 ret_code
= iavf_alloc_adminq_arq_ring(hw
);
392 goto init_adminq_exit
;
394 /* allocate buffers in the rings */
395 ret_code
= iavf_alloc_arq_bufs(hw
);
397 goto init_adminq_free_rings
;
399 /* initialize base registers */
400 ret_code
= iavf_config_arq_regs(hw
);
402 goto init_free_arq_bufs
;
405 hw
->aq
.arq
.count
= hw
->aq
.num_arq_entries
;
406 goto init_adminq_exit
;
409 for (i
= 0; i
< hw
->aq
.num_arq_entries
; i
++)
410 iavf_free_dma_mem(hw
, &hw
->aq
.arq
.r
.arq_bi
[i
]);
411 iavf_free_virt_mem(hw
, &hw
->aq
.arq
.dma_head
);
412 init_adminq_free_rings
:
413 iavf_free_adminq_arq(hw
);
420 * iavf_shutdown_asq - shutdown the ASQ
421 * @hw: pointer to the hardware structure
423 * The main shutdown routine for the Admin Send Queue
425 static enum iavf_status
iavf_shutdown_asq(struct iavf_hw
*hw
)
427 enum iavf_status ret_code
= 0;
429 mutex_lock(&hw
->aq
.asq_mutex
);
431 if (hw
->aq
.asq
.count
== 0) {
432 ret_code
= IAVF_ERR_NOT_READY
;
433 goto shutdown_asq_out
;
436 /* Stop firmware AdminQ processing */
437 wr32(hw
, IAVF_VF_ATQH1
, 0);
438 wr32(hw
, IAVF_VF_ATQT1
, 0);
439 wr32(hw
, IAVF_VF_ATQLEN1
, 0);
440 wr32(hw
, IAVF_VF_ATQBAL1
, 0);
441 wr32(hw
, IAVF_VF_ATQBAH1
, 0);
443 hw
->aq
.asq
.count
= 0; /* to indicate uninitialized queue */
445 /* free ring buffers */
446 iavf_free_asq_bufs(hw
);
449 mutex_unlock(&hw
->aq
.asq_mutex
);
454 * iavf_shutdown_arq - shutdown ARQ
455 * @hw: pointer to the hardware structure
457 * The main shutdown routine for the Admin Receive Queue
459 static enum iavf_status
iavf_shutdown_arq(struct iavf_hw
*hw
)
461 enum iavf_status ret_code
= 0;
463 mutex_lock(&hw
->aq
.arq_mutex
);
465 if (hw
->aq
.arq
.count
== 0) {
466 ret_code
= IAVF_ERR_NOT_READY
;
467 goto shutdown_arq_out
;
470 /* Stop firmware AdminQ processing */
471 wr32(hw
, IAVF_VF_ARQH1
, 0);
472 wr32(hw
, IAVF_VF_ARQT1
, 0);
473 wr32(hw
, IAVF_VF_ARQLEN1
, 0);
474 wr32(hw
, IAVF_VF_ARQBAL1
, 0);
475 wr32(hw
, IAVF_VF_ARQBAH1
, 0);
477 hw
->aq
.arq
.count
= 0; /* to indicate uninitialized queue */
479 /* free ring buffers */
480 iavf_free_arq_bufs(hw
);
483 mutex_unlock(&hw
->aq
.arq_mutex
);
488 * iavf_init_adminq - main initialization routine for Admin Queue
489 * @hw: pointer to the hardware structure
491 * Prior to calling this function, drivers *MUST* set the following fields
492 * in the hw->aq structure:
493 * - hw->aq.num_asq_entries
494 * - hw->aq.num_arq_entries
495 * - hw->aq.arq_buf_size
496 * - hw->aq.asq_buf_size
498 enum iavf_status
iavf_init_adminq(struct iavf_hw
*hw
)
500 enum iavf_status ret_code
;
502 /* verify input for valid configuration */
503 if ((hw
->aq
.num_arq_entries
== 0) ||
504 (hw
->aq
.num_asq_entries
== 0) ||
505 (hw
->aq
.arq_buf_size
== 0) ||
506 (hw
->aq
.asq_buf_size
== 0)) {
507 ret_code
= IAVF_ERR_CONFIG
;
508 goto init_adminq_exit
;
511 /* setup ASQ command write back timeout */
512 hw
->aq
.asq_cmd_timeout
= IAVF_ASQ_CMD_TIMEOUT
;
514 /* allocate the ASQ */
515 ret_code
= iavf_init_asq(hw
);
517 goto init_adminq_destroy_locks
;
519 /* allocate the ARQ */
520 ret_code
= iavf_init_arq(hw
);
522 goto init_adminq_free_asq
;
525 goto init_adminq_exit
;
527 init_adminq_free_asq
:
528 iavf_shutdown_asq(hw
);
529 init_adminq_destroy_locks
:
536 * iavf_shutdown_adminq - shutdown routine for the Admin Queue
537 * @hw: pointer to the hardware structure
539 enum iavf_status
iavf_shutdown_adminq(struct iavf_hw
*hw
)
541 if (iavf_check_asq_alive(hw
))
542 iavf_aq_queue_shutdown(hw
, true);
544 iavf_shutdown_asq(hw
);
545 iavf_shutdown_arq(hw
);
551 * iavf_clean_asq - cleans Admin send queue
552 * @hw: pointer to the hardware structure
554 * returns the number of free desc
556 static u16
iavf_clean_asq(struct iavf_hw
*hw
)
558 struct iavf_adminq_ring
*asq
= &hw
->aq
.asq
;
559 struct iavf_asq_cmd_details
*details
;
560 u16 ntc
= asq
->next_to_clean
;
561 struct iavf_aq_desc desc_cb
;
562 struct iavf_aq_desc
*desc
;
564 desc
= IAVF_ADMINQ_DESC(*asq
, ntc
);
565 details
= IAVF_ADMINQ_DETAILS(*asq
, ntc
);
566 while (rd32(hw
, IAVF_VF_ATQH1
) != ntc
) {
567 iavf_debug(hw
, IAVF_DEBUG_AQ_MESSAGE
,
568 "ntc %d head %d.\n", ntc
, rd32(hw
, IAVF_VF_ATQH1
));
570 if (details
->callback
) {
571 IAVF_ADMINQ_CALLBACK cb_func
=
572 (IAVF_ADMINQ_CALLBACK
)details
->callback
;
574 cb_func(hw
, &desc_cb
);
576 memset((void *)desc
, 0, sizeof(struct iavf_aq_desc
));
577 memset((void *)details
, 0,
578 sizeof(struct iavf_asq_cmd_details
));
580 if (ntc
== asq
->count
)
582 desc
= IAVF_ADMINQ_DESC(*asq
, ntc
);
583 details
= IAVF_ADMINQ_DETAILS(*asq
, ntc
);
586 asq
->next_to_clean
= ntc
;
588 return IAVF_DESC_UNUSED(asq
);
592 * iavf_asq_done - check if FW has processed the Admin Send Queue
593 * @hw: pointer to the hw struct
595 * Returns true if the firmware has processed all descriptors on the
596 * admin send queue. Returns false if there are still requests pending.
598 bool iavf_asq_done(struct iavf_hw
*hw
)
600 /* AQ designers suggest use of head for better
601 * timing reliability than DD bit
603 return rd32(hw
, IAVF_VF_ATQH1
) == hw
->aq
.asq
.next_to_use
;
607 * iavf_asq_send_command - send command to Admin Queue
608 * @hw: pointer to the hw struct
609 * @desc: prefilled descriptor describing the command (non DMA mem)
610 * @buff: buffer to use for indirect commands
611 * @buff_size: size of buffer for indirect commands
612 * @cmd_details: pointer to command details structure
614 * This is the main send command driver routine for the Admin Queue send
615 * queue. It runs the queue, cleans the queue, etc
617 enum iavf_status
iavf_asq_send_command(struct iavf_hw
*hw
,
618 struct iavf_aq_desc
*desc
,
619 void *buff
, /* can be NULL */
621 struct iavf_asq_cmd_details
*cmd_details
)
623 struct iavf_dma_mem
*dma_buff
= NULL
;
624 struct iavf_asq_cmd_details
*details
;
625 struct iavf_aq_desc
*desc_on_ring
;
626 bool cmd_completed
= false;
627 enum iavf_status status
= 0;
631 mutex_lock(&hw
->aq
.asq_mutex
);
633 if (hw
->aq
.asq
.count
== 0) {
634 iavf_debug(hw
, IAVF_DEBUG_AQ_MESSAGE
,
635 "AQTX: Admin queue not initialized.\n");
636 status
= IAVF_ERR_QUEUE_EMPTY
;
637 goto asq_send_command_error
;
640 hw
->aq
.asq_last_status
= IAVF_AQ_RC_OK
;
642 val
= rd32(hw
, IAVF_VF_ATQH1
);
643 if (val
>= hw
->aq
.num_asq_entries
) {
644 iavf_debug(hw
, IAVF_DEBUG_AQ_MESSAGE
,
645 "AQTX: head overrun at %d\n", val
);
646 status
= IAVF_ERR_QUEUE_EMPTY
;
647 goto asq_send_command_error
;
650 details
= IAVF_ADMINQ_DETAILS(hw
->aq
.asq
, hw
->aq
.asq
.next_to_use
);
652 *details
= *cmd_details
;
654 /* If the cmd_details are defined copy the cookie. The
655 * cpu_to_le32 is not needed here because the data is ignored
656 * by the FW, only used by the driver
658 if (details
->cookie
) {
660 cpu_to_le32(upper_32_bits(details
->cookie
));
662 cpu_to_le32(lower_32_bits(details
->cookie
));
665 memset(details
, 0, sizeof(struct iavf_asq_cmd_details
));
668 /* clear requested flags and then set additional flags if defined */
669 desc
->flags
&= ~cpu_to_le16(details
->flags_dis
);
670 desc
->flags
|= cpu_to_le16(details
->flags_ena
);
672 if (buff_size
> hw
->aq
.asq_buf_size
) {
674 IAVF_DEBUG_AQ_MESSAGE
,
675 "AQTX: Invalid buffer size: %d.\n",
677 status
= IAVF_ERR_INVALID_SIZE
;
678 goto asq_send_command_error
;
681 if (details
->postpone
&& !details
->async
) {
683 IAVF_DEBUG_AQ_MESSAGE
,
684 "AQTX: Async flag not set along with postpone flag");
685 status
= IAVF_ERR_PARAM
;
686 goto asq_send_command_error
;
689 /* call clean and check queue available function to reclaim the
690 * descriptors that were processed by FW, the function returns the
691 * number of desc available
693 /* the clean function called here could be called in a separate thread
694 * in case of asynchronous completions
696 if (iavf_clean_asq(hw
) == 0) {
698 IAVF_DEBUG_AQ_MESSAGE
,
699 "AQTX: Error queue is full.\n");
700 status
= IAVF_ERR_ADMIN_QUEUE_FULL
;
701 goto asq_send_command_error
;
704 /* initialize the temp desc pointer with the right desc */
705 desc_on_ring
= IAVF_ADMINQ_DESC(hw
->aq
.asq
, hw
->aq
.asq
.next_to_use
);
707 /* if the desc is available copy the temp desc to the right place */
708 *desc_on_ring
= *desc
;
710 /* if buff is not NULL assume indirect command */
712 dma_buff
= &hw
->aq
.asq
.r
.asq_bi
[hw
->aq
.asq
.next_to_use
];
713 /* copy the user buff into the respective DMA buff */
714 memcpy(dma_buff
->va
, buff
, buff_size
);
715 desc_on_ring
->datalen
= cpu_to_le16(buff_size
);
717 /* Update the address values in the desc with the pa value
718 * for respective buffer
720 desc_on_ring
->params
.external
.addr_high
=
721 cpu_to_le32(upper_32_bits(dma_buff
->pa
));
722 desc_on_ring
->params
.external
.addr_low
=
723 cpu_to_le32(lower_32_bits(dma_buff
->pa
));
727 iavf_debug(hw
, IAVF_DEBUG_AQ_MESSAGE
, "AQTX: desc and buffer:\n");
728 iavf_debug_aq(hw
, IAVF_DEBUG_AQ_COMMAND
, (void *)desc_on_ring
,
730 (hw
->aq
.asq
.next_to_use
)++;
731 if (hw
->aq
.asq
.next_to_use
== hw
->aq
.asq
.count
)
732 hw
->aq
.asq
.next_to_use
= 0;
733 if (!details
->postpone
)
734 wr32(hw
, IAVF_VF_ATQT1
, hw
->aq
.asq
.next_to_use
);
736 /* if cmd_details are not defined or async flag is not set,
737 * we need to wait for desc write back
739 if (!details
->async
&& !details
->postpone
) {
743 /* AQ designers suggest use of head for better
744 * timing reliability than DD bit
746 if (iavf_asq_done(hw
))
750 } while (total_delay
< hw
->aq
.asq_cmd_timeout
);
753 /* if ready, copy the desc back to temp */
754 if (iavf_asq_done(hw
)) {
755 *desc
= *desc_on_ring
;
757 memcpy(buff
, dma_buff
->va
, buff_size
);
758 retval
= le16_to_cpu(desc
->retval
);
761 IAVF_DEBUG_AQ_MESSAGE
,
762 "AQTX: Command completed with error 0x%X.\n",
765 /* strip off FW internal code */
768 cmd_completed
= true;
769 if ((enum iavf_admin_queue_err
)retval
== IAVF_AQ_RC_OK
)
771 else if ((enum iavf_admin_queue_err
)retval
== IAVF_AQ_RC_EBUSY
)
772 status
= IAVF_ERR_NOT_READY
;
774 status
= IAVF_ERR_ADMIN_QUEUE_ERROR
;
775 hw
->aq
.asq_last_status
= (enum iavf_admin_queue_err
)retval
;
778 iavf_debug(hw
, IAVF_DEBUG_AQ_MESSAGE
,
779 "AQTX: desc and buffer writeback:\n");
780 iavf_debug_aq(hw
, IAVF_DEBUG_AQ_COMMAND
, (void *)desc
, buff
, buff_size
);
782 /* save writeback aq if requested */
783 if (details
->wb_desc
)
784 *details
->wb_desc
= *desc_on_ring
;
786 /* update the error if time out occurred */
787 if ((!cmd_completed
) &&
788 (!details
->async
&& !details
->postpone
)) {
789 if (rd32(hw
, IAVF_VF_ATQLEN1
) & IAVF_VF_ATQLEN1_ATQCRIT_MASK
) {
790 iavf_debug(hw
, IAVF_DEBUG_AQ_MESSAGE
,
791 "AQTX: AQ Critical error.\n");
792 status
= IAVF_ERR_ADMIN_QUEUE_CRITICAL_ERROR
;
794 iavf_debug(hw
, IAVF_DEBUG_AQ_MESSAGE
,
795 "AQTX: Writeback timeout.\n");
796 status
= IAVF_ERR_ADMIN_QUEUE_TIMEOUT
;
800 asq_send_command_error
:
801 mutex_unlock(&hw
->aq
.asq_mutex
);
806 * iavf_fill_default_direct_cmd_desc - AQ descriptor helper function
807 * @desc: pointer to the temp descriptor (non DMA mem)
808 * @opcode: the opcode can be used to decide which flags to turn off or on
810 * Fill the desc with default values
812 void iavf_fill_default_direct_cmd_desc(struct iavf_aq_desc
*desc
, u16 opcode
)
814 /* zero out the desc */
815 memset((void *)desc
, 0, sizeof(struct iavf_aq_desc
));
816 desc
->opcode
= cpu_to_le16(opcode
);
817 desc
->flags
= cpu_to_le16(IAVF_AQ_FLAG_SI
);
821 * iavf_clean_arq_element
822 * @hw: pointer to the hw struct
823 * @e: event info from the receive descriptor, includes any buffers
824 * @pending: number of events that could be left to process
826 * This function cleans one Admin Receive Queue element and returns
827 * the contents through e. It can also return how many events are
828 * left to process through 'pending'
830 enum iavf_status
iavf_clean_arq_element(struct iavf_hw
*hw
,
831 struct iavf_arq_event_info
*e
,
834 u16 ntc
= hw
->aq
.arq
.next_to_clean
;
835 struct iavf_aq_desc
*desc
;
836 enum iavf_status ret_code
= 0;
837 struct iavf_dma_mem
*bi
;
843 /* pre-clean the event info */
844 memset(&e
->desc
, 0, sizeof(e
->desc
));
846 /* take the lock before we start messing with the ring */
847 mutex_lock(&hw
->aq
.arq_mutex
);
849 if (hw
->aq
.arq
.count
== 0) {
850 iavf_debug(hw
, IAVF_DEBUG_AQ_MESSAGE
,
851 "AQRX: Admin queue not initialized.\n");
852 ret_code
= IAVF_ERR_QUEUE_EMPTY
;
853 goto clean_arq_element_err
;
856 /* set next_to_use to head */
857 ntu
= rd32(hw
, IAVF_VF_ARQH1
) & IAVF_VF_ARQH1_ARQH_MASK
;
859 /* nothing to do - shouldn't need to update ring's values */
860 ret_code
= IAVF_ERR_ADMIN_QUEUE_NO_WORK
;
861 goto clean_arq_element_out
;
864 /* now clean the next descriptor */
865 desc
= IAVF_ADMINQ_DESC(hw
->aq
.arq
, ntc
);
868 hw
->aq
.arq_last_status
=
869 (enum iavf_admin_queue_err
)le16_to_cpu(desc
->retval
);
870 flags
= le16_to_cpu(desc
->flags
);
871 if (flags
& IAVF_AQ_FLAG_ERR
) {
872 ret_code
= IAVF_ERR_ADMIN_QUEUE_ERROR
;
874 IAVF_DEBUG_AQ_MESSAGE
,
875 "AQRX: Event received with error 0x%X.\n",
876 hw
->aq
.arq_last_status
);
880 datalen
= le16_to_cpu(desc
->datalen
);
881 e
->msg_len
= min(datalen
, e
->buf_len
);
882 if (e
->msg_buf
&& (e
->msg_len
!= 0))
883 memcpy(e
->msg_buf
, hw
->aq
.arq
.r
.arq_bi
[desc_idx
].va
,
886 iavf_debug(hw
, IAVF_DEBUG_AQ_MESSAGE
, "AQRX: desc and buffer:\n");
887 iavf_debug_aq(hw
, IAVF_DEBUG_AQ_COMMAND
, (void *)desc
, e
->msg_buf
,
888 hw
->aq
.arq_buf_size
);
890 /* Restore the original datalen and buffer address in the desc,
891 * FW updates datalen to indicate the event message
894 bi
= &hw
->aq
.arq
.r
.arq_bi
[ntc
];
895 memset((void *)desc
, 0, sizeof(struct iavf_aq_desc
));
897 desc
->flags
= cpu_to_le16(IAVF_AQ_FLAG_BUF
);
898 if (hw
->aq
.arq_buf_size
> IAVF_AQ_LARGE_BUF
)
899 desc
->flags
|= cpu_to_le16(IAVF_AQ_FLAG_LB
);
900 desc
->datalen
= cpu_to_le16((u16
)bi
->size
);
901 desc
->params
.external
.addr_high
= cpu_to_le32(upper_32_bits(bi
->pa
));
902 desc
->params
.external
.addr_low
= cpu_to_le32(lower_32_bits(bi
->pa
));
904 /* set tail = the last cleaned desc index. */
905 wr32(hw
, IAVF_VF_ARQT1
, ntc
);
906 /* ntc is updated to tail + 1 */
908 if (ntc
== hw
->aq
.num_arq_entries
)
910 hw
->aq
.arq
.next_to_clean
= ntc
;
911 hw
->aq
.arq
.next_to_use
= ntu
;
913 clean_arq_element_out
:
914 /* Set pending if needed, unlock and return */
916 *pending
= (ntc
> ntu
? hw
->aq
.arq
.count
: 0) + (ntu
- ntc
);
918 clean_arq_element_err
:
919 mutex_unlock(&hw
->aq
.arq_mutex
);