2 * Copyright (C) 2015 Cavium, Inc.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License
6 * as published by the Free Software Foundation.
10 #include <linux/netdevice.h>
12 #include <linux/etherdevice.h>
19 #include "nicvf_queues.h"
27 #define GET_RBUF_INFO(x) ((struct rbuf_info *)(x - NICVF_RCV_BUF_ALIGN_BYTES))
29 /* Poll a register for a specific value */
30 static int nicvf_poll_reg(struct nicvf
*nic
, int qidx
,
31 u64 reg
, int bit_pos
, int bits
, int val
)
37 bit_mask
= (1ULL << bits
) - 1;
38 bit_mask
= (bit_mask
<< bit_pos
);
41 reg_val
= nicvf_queue_reg_read(nic
, reg
, qidx
);
42 if (((reg_val
& bit_mask
) >> bit_pos
) == val
)
44 usleep_range(1000, 2000);
47 netdev_err(nic
->netdev
, "Poll on reg 0x%llx failed\n", reg
);
51 /* Allocate memory for a queue's descriptors */
52 static int nicvf_alloc_q_desc_mem(struct nicvf
*nic
, struct q_desc_mem
*dmem
,
53 int q_len
, int desc_size
, int align_bytes
)
56 dmem
->size
= (desc_size
* q_len
) + align_bytes
;
57 /* Save address, need it while freeing */
58 dmem
->unalign_base
= dma_zalloc_coherent(&nic
->pdev
->dev
, dmem
->size
,
59 &dmem
->dma
, GFP_KERNEL
);
60 if (!dmem
->unalign_base
)
63 /* Align memory address for 'align_bytes' */
64 dmem
->phys_base
= NICVF_ALIGNED_ADDR((u64
)dmem
->dma
, align_bytes
);
65 dmem
->base
= dmem
->unalign_base
+ (dmem
->phys_base
- dmem
->dma
);
69 /* Free queue's descriptor memory */
70 static void nicvf_free_q_desc_mem(struct nicvf
*nic
, struct q_desc_mem
*dmem
)
75 dma_free_coherent(&nic
->pdev
->dev
, dmem
->size
,
76 dmem
->unalign_base
, dmem
->dma
);
77 dmem
->unalign_base
= NULL
;
81 /* Allocate buffer for packet reception
82 * HW returns memory address where packet is DMA'ed but not a pointer
83 * into RBDR ring, so save buffer address at the start of fragment and
84 * align the start address to a cache aligned address
86 static inline int nicvf_alloc_rcv_buffer(struct nicvf
*nic
, gfp_t gfp
,
87 u32 buf_len
, u64
**rbuf
)
90 struct rbuf_info
*rinfo
;
91 int order
= get_order(buf_len
);
93 /* Check if request can be accomodated in previous allocated page */
95 if ((nic
->rb_page_offset
+ buf_len
+ buf_len
) >
96 (PAGE_SIZE
<< order
)) {
99 nic
->rb_page_offset
+= buf_len
;
100 get_page(nic
->rb_page
);
104 /* Allocate a new page */
106 nic
->rb_page
= alloc_pages(gfp
| __GFP_COMP
| __GFP_NOWARN
,
109 netdev_err(nic
->netdev
,
110 "Failed to allocate new rcv buffer\n");
113 nic
->rb_page_offset
= 0;
116 data
= (u64
)page_address(nic
->rb_page
) + nic
->rb_page_offset
;
118 /* Align buffer addr to cache line i.e 128 bytes */
119 rinfo
= (struct rbuf_info
*)(data
+ NICVF_RCV_BUF_ALIGN_LEN(data
));
120 /* Save page address for reference updation */
121 rinfo
->page
= nic
->rb_page
;
122 /* Store start address for later retrieval */
123 rinfo
->data
= (void *)data
;
124 /* Store alignment offset */
125 rinfo
->offset
= NICVF_RCV_BUF_ALIGN_LEN(data
);
127 data
+= rinfo
->offset
;
129 /* Give next aligned address to hw for DMA */
130 *rbuf
= (u64
*)(data
+ NICVF_RCV_BUF_ALIGN_BYTES
);
134 /* Retrieve actual buffer start address and build skb for received packet */
135 static struct sk_buff
*nicvf_rb_ptr_to_skb(struct nicvf
*nic
,
139 struct rbuf_info
*rinfo
;
141 rb_ptr
= (u64
)phys_to_virt(rb_ptr
);
142 /* Get buffer start address and alignment offset */
143 rinfo
= GET_RBUF_INFO(rb_ptr
);
145 /* Now build an skb to give to stack */
146 skb
= build_skb(rinfo
->data
, RCV_FRAG_LEN
);
148 put_page(rinfo
->page
);
152 /* Set correct skb->data */
153 skb_reserve(skb
, rinfo
->offset
+ NICVF_RCV_BUF_ALIGN_BYTES
);
155 prefetch((void *)rb_ptr
);
159 /* Allocate RBDR ring and populate receive buffers */
160 static int nicvf_init_rbdr(struct nicvf
*nic
, struct rbdr
*rbdr
,
161 int ring_len
, int buf_size
)
165 struct rbdr_entry_t
*desc
;
168 err
= nicvf_alloc_q_desc_mem(nic
, &rbdr
->dmem
, ring_len
,
169 sizeof(struct rbdr_entry_t
),
170 NICVF_RCV_BUF_ALIGN_BYTES
);
174 rbdr
->desc
= rbdr
->dmem
.base
;
175 /* Buffer size has to be in multiples of 128 bytes */
176 rbdr
->dma_size
= buf_size
;
178 rbdr
->thresh
= RBDR_THRESH
;
181 for (idx
= 0; idx
< ring_len
; idx
++) {
182 err
= nicvf_alloc_rcv_buffer(nic
, GFP_KERNEL
, RCV_FRAG_LEN
,
187 desc
= GET_RBDR_DESC(rbdr
, idx
);
188 desc
->buf_addr
= virt_to_phys(rbuf
) >> NICVF_RCV_BUF_ALIGN
;
193 /* Free RBDR ring and its receive buffers */
194 static void nicvf_free_rbdr(struct nicvf
*nic
, struct rbdr
*rbdr
)
198 struct rbdr_entry_t
*desc
;
199 struct rbuf_info
*rinfo
;
204 rbdr
->enable
= false;
205 if (!rbdr
->dmem
.base
)
212 while (head
!= tail
) {
213 desc
= GET_RBDR_DESC(rbdr
, head
);
214 buf_addr
= desc
->buf_addr
<< NICVF_RCV_BUF_ALIGN
;
215 rinfo
= GET_RBUF_INFO((u64
)phys_to_virt(buf_addr
));
216 put_page(rinfo
->page
);
218 head
&= (rbdr
->dmem
.q_len
- 1);
220 /* Free SKB of tail desc */
221 desc
= GET_RBDR_DESC(rbdr
, tail
);
222 buf_addr
= desc
->buf_addr
<< NICVF_RCV_BUF_ALIGN
;
223 rinfo
= GET_RBUF_INFO((u64
)phys_to_virt(buf_addr
));
224 put_page(rinfo
->page
);
227 nicvf_free_q_desc_mem(nic
, &rbdr
->dmem
);
230 /* Refill receive buffer descriptors with new buffers.
232 static void nicvf_refill_rbdr(struct nicvf
*nic
, gfp_t gfp
)
234 struct queue_set
*qs
= nic
->qs
;
235 int rbdr_idx
= qs
->rbdr_cnt
;
239 struct rbdr_entry_t
*desc
;
247 rbdr
= &qs
->rbdr
[rbdr_idx
];
248 /* Check if it's enabled */
252 /* Get no of desc's to be refilled */
253 qcount
= nicvf_queue_reg_read(nic
, NIC_QSET_RBDR_0_1_STATUS0
, rbdr_idx
);
255 /* Doorbell can be ringed with a max of ring size minus 1 */
256 if (qcount
>= (qs
->rbdr_len
- 1))
259 refill_rb_cnt
= qs
->rbdr_len
- qcount
- 1;
261 /* Start filling descs from tail */
262 tail
= nicvf_queue_reg_read(nic
, NIC_QSET_RBDR_0_1_TAIL
, rbdr_idx
) >> 3;
263 while (refill_rb_cnt
) {
265 tail
&= (rbdr
->dmem
.q_len
- 1);
267 if (nicvf_alloc_rcv_buffer(nic
, gfp
, RCV_FRAG_LEN
, &rbuf
))
270 desc
= GET_RBDR_DESC(rbdr
, tail
);
271 desc
->buf_addr
= virt_to_phys(rbuf
) >> NICVF_RCV_BUF_ALIGN
;
276 /* make sure all memory stores are done before ringing doorbell */
279 /* Check if buffer allocation failed */
281 nic
->rb_alloc_fail
= true;
283 nic
->rb_alloc_fail
= false;
286 nicvf_queue_reg_write(nic
, NIC_QSET_RBDR_0_1_DOOR
,
289 /* Re-enable RBDR interrupts only if buffer allocation is success */
290 if (!nic
->rb_alloc_fail
&& rbdr
->enable
)
291 nicvf_enable_intr(nic
, NICVF_INTR_RBDR
, rbdr_idx
);
297 /* Alloc rcv buffers in non-atomic mode for better success */
298 void nicvf_rbdr_work(struct work_struct
*work
)
300 struct nicvf
*nic
= container_of(work
, struct nicvf
, rbdr_work
.work
);
302 nicvf_refill_rbdr(nic
, GFP_KERNEL
);
303 if (nic
->rb_alloc_fail
)
304 schedule_delayed_work(&nic
->rbdr_work
, msecs_to_jiffies(10));
306 nic
->rb_work_scheduled
= false;
309 /* In Softirq context, alloc rcv buffers in atomic mode */
310 void nicvf_rbdr_task(unsigned long data
)
312 struct nicvf
*nic
= (struct nicvf
*)data
;
314 nicvf_refill_rbdr(nic
, GFP_ATOMIC
);
315 if (nic
->rb_alloc_fail
) {
316 nic
->rb_work_scheduled
= true;
317 schedule_delayed_work(&nic
->rbdr_work
, msecs_to_jiffies(10));
321 /* Initialize completion queue */
322 static int nicvf_init_cmp_queue(struct nicvf
*nic
,
323 struct cmp_queue
*cq
, int q_len
)
327 err
= nicvf_alloc_q_desc_mem(nic
, &cq
->dmem
, q_len
, CMP_QUEUE_DESC_SIZE
,
328 NICVF_CQ_BASE_ALIGN_BYTES
);
332 cq
->desc
= cq
->dmem
.base
;
333 cq
->thresh
= CMP_QUEUE_CQE_THRESH
;
334 nic
->cq_coalesce_usecs
= (CMP_QUEUE_TIMER_THRESH
* 0.05) - 1;
339 static void nicvf_free_cmp_queue(struct nicvf
*nic
, struct cmp_queue
*cq
)
346 nicvf_free_q_desc_mem(nic
, &cq
->dmem
);
349 /* Initialize transmit queue */
350 static int nicvf_init_snd_queue(struct nicvf
*nic
,
351 struct snd_queue
*sq
, int q_len
)
355 err
= nicvf_alloc_q_desc_mem(nic
, &sq
->dmem
, q_len
, SND_QUEUE_DESC_SIZE
,
356 NICVF_SQ_BASE_ALIGN_BYTES
);
360 sq
->desc
= sq
->dmem
.base
;
361 sq
->skbuff
= kcalloc(q_len
, sizeof(u64
), GFP_KERNEL
);
366 atomic_set(&sq
->free_cnt
, q_len
- 1);
367 sq
->thresh
= SND_QUEUE_THRESH
;
369 /* Preallocate memory for TSO segment's header */
370 sq
->tso_hdrs
= dma_alloc_coherent(&nic
->pdev
->dev
,
371 q_len
* TSO_HEADER_SIZE
,
372 &sq
->tso_hdrs_phys
, GFP_KERNEL
);
379 static void nicvf_free_snd_queue(struct nicvf
*nic
, struct snd_queue
*sq
)
387 dma_free_coherent(&nic
->pdev
->dev
,
388 sq
->dmem
.q_len
* TSO_HEADER_SIZE
,
389 sq
->tso_hdrs
, sq
->tso_hdrs_phys
);
392 nicvf_free_q_desc_mem(nic
, &sq
->dmem
);
395 static void nicvf_reclaim_snd_queue(struct nicvf
*nic
,
396 struct queue_set
*qs
, int qidx
)
398 /* Disable send queue */
399 nicvf_queue_reg_write(nic
, NIC_QSET_SQ_0_7_CFG
, qidx
, 0);
400 /* Check if SQ is stopped */
401 if (nicvf_poll_reg(nic
, qidx
, NIC_QSET_SQ_0_7_STATUS
, 21, 1, 0x01))
403 /* Reset send queue */
404 nicvf_queue_reg_write(nic
, NIC_QSET_SQ_0_7_CFG
, qidx
, NICVF_SQ_RESET
);
407 static void nicvf_reclaim_rcv_queue(struct nicvf
*nic
,
408 struct queue_set
*qs
, int qidx
)
410 union nic_mbx mbx
= {};
412 /* Make sure all packets in the pipeline are written back into mem */
413 mbx
.msg
.msg
= NIC_MBOX_MSG_RQ_SW_SYNC
;
414 nicvf_send_msg_to_pf(nic
, &mbx
);
417 static void nicvf_reclaim_cmp_queue(struct nicvf
*nic
,
418 struct queue_set
*qs
, int qidx
)
420 /* Disable timer threshold (doesn't get reset upon CQ reset */
421 nicvf_queue_reg_write(nic
, NIC_QSET_CQ_0_7_CFG2
, qidx
, 0);
422 /* Disable completion queue */
423 nicvf_queue_reg_write(nic
, NIC_QSET_CQ_0_7_CFG
, qidx
, 0);
424 /* Reset completion queue */
425 nicvf_queue_reg_write(nic
, NIC_QSET_CQ_0_7_CFG
, qidx
, NICVF_CQ_RESET
);
428 static void nicvf_reclaim_rbdr(struct nicvf
*nic
,
429 struct rbdr
*rbdr
, int qidx
)
434 /* Save head and tail pointers for feeing up buffers */
435 rbdr
->head
= nicvf_queue_reg_read(nic
,
436 NIC_QSET_RBDR_0_1_HEAD
,
438 rbdr
->tail
= nicvf_queue_reg_read(nic
,
439 NIC_QSET_RBDR_0_1_TAIL
,
442 /* If RBDR FIFO is in 'FAIL' state then do a reset first
445 fifo_state
= nicvf_queue_reg_read(nic
, NIC_QSET_RBDR_0_1_STATUS0
, qidx
);
446 if (((fifo_state
>> 62) & 0x03) == 0x3)
447 nicvf_queue_reg_write(nic
, NIC_QSET_RBDR_0_1_CFG
,
448 qidx
, NICVF_RBDR_RESET
);
451 nicvf_queue_reg_write(nic
, NIC_QSET_RBDR_0_1_CFG
, qidx
, 0);
452 if (nicvf_poll_reg(nic
, qidx
, NIC_QSET_RBDR_0_1_STATUS0
, 62, 2, 0x00))
455 tmp
= nicvf_queue_reg_read(nic
,
456 NIC_QSET_RBDR_0_1_PREFETCH_STATUS
,
458 if ((tmp
& 0xFFFFFFFF) == ((tmp
>> 32) & 0xFFFFFFFF))
460 usleep_range(1000, 2000);
463 netdev_err(nic
->netdev
,
464 "Failed polling on prefetch status\n");
468 nicvf_queue_reg_write(nic
, NIC_QSET_RBDR_0_1_CFG
,
469 qidx
, NICVF_RBDR_RESET
);
471 if (nicvf_poll_reg(nic
, qidx
, NIC_QSET_RBDR_0_1_STATUS0
, 62, 2, 0x02))
473 nicvf_queue_reg_write(nic
, NIC_QSET_RBDR_0_1_CFG
, qidx
, 0x00);
474 if (nicvf_poll_reg(nic
, qidx
, NIC_QSET_RBDR_0_1_STATUS0
, 62, 2, 0x00))
478 void nicvf_config_vlan_stripping(struct nicvf
*nic
, netdev_features_t features
)
483 rq_cfg
= nicvf_queue_reg_read(nic
, NIC_QSET_RQ_GEN_CFG
, 0);
485 /* Enable first VLAN stripping */
486 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
487 rq_cfg
|= (1ULL << 25);
489 rq_cfg
&= ~(1ULL << 25);
490 nicvf_queue_reg_write(nic
, NIC_QSET_RQ_GEN_CFG
, 0, rq_cfg
);
492 /* Configure Secondary Qsets, if any */
493 for (sqs
= 0; sqs
< nic
->sqs_count
; sqs
++)
494 if (nic
->snicvf
[sqs
])
495 nicvf_queue_reg_write(nic
->snicvf
[sqs
],
496 NIC_QSET_RQ_GEN_CFG
, 0, rq_cfg
);
499 /* Configures receive queue */
500 static void nicvf_rcv_queue_config(struct nicvf
*nic
, struct queue_set
*qs
,
501 int qidx
, bool enable
)
503 union nic_mbx mbx
= {};
504 struct rcv_queue
*rq
;
505 struct rq_cfg rq_cfg
;
510 /* Disable receive queue */
511 nicvf_queue_reg_write(nic
, NIC_QSET_RQ_0_7_CFG
, qidx
, 0);
514 nicvf_reclaim_rcv_queue(nic
, qs
, qidx
);
518 rq
->cq_qs
= qs
->vnic_id
;
520 rq
->start_rbdr_qs
= qs
->vnic_id
;
521 rq
->start_qs_rbdr_idx
= qs
->rbdr_cnt
- 1;
522 rq
->cont_rbdr_qs
= qs
->vnic_id
;
523 rq
->cont_qs_rbdr_idx
= qs
->rbdr_cnt
- 1;
524 /* all writes of RBDR data to be loaded into L2 Cache as well*/
527 /* Send a mailbox msg to PF to config RQ */
528 mbx
.rq
.msg
= NIC_MBOX_MSG_RQ_CFG
;
529 mbx
.rq
.qs_num
= qs
->vnic_id
;
530 mbx
.rq
.rq_num
= qidx
;
531 mbx
.rq
.cfg
= (rq
->caching
<< 26) | (rq
->cq_qs
<< 19) |
532 (rq
->cq_idx
<< 16) | (rq
->cont_rbdr_qs
<< 9) |
533 (rq
->cont_qs_rbdr_idx
<< 8) |
534 (rq
->start_rbdr_qs
<< 1) | (rq
->start_qs_rbdr_idx
);
535 nicvf_send_msg_to_pf(nic
, &mbx
);
537 mbx
.rq
.msg
= NIC_MBOX_MSG_RQ_BP_CFG
;
538 mbx
.rq
.cfg
= (1ULL << 63) | (1ULL << 62) | (qs
->vnic_id
<< 0);
539 nicvf_send_msg_to_pf(nic
, &mbx
);
542 * Enable CQ drop to reserve sufficient CQEs for all tx packets
544 mbx
.rq
.msg
= NIC_MBOX_MSG_RQ_DROP_CFG
;
545 mbx
.rq
.cfg
= (1ULL << 62) | (RQ_CQ_DROP
<< 8);
546 nicvf_send_msg_to_pf(nic
, &mbx
);
548 nicvf_queue_reg_write(nic
, NIC_QSET_RQ_GEN_CFG
, 0, 0x00);
550 nicvf_config_vlan_stripping(nic
, nic
->netdev
->features
);
552 /* Enable Receive queue */
555 nicvf_queue_reg_write(nic
, NIC_QSET_RQ_0_7_CFG
, qidx
, *(u64
*)&rq_cfg
);
558 /* Configures completion queue */
559 void nicvf_cmp_queue_config(struct nicvf
*nic
, struct queue_set
*qs
,
560 int qidx
, bool enable
)
562 struct cmp_queue
*cq
;
563 struct cq_cfg cq_cfg
;
569 nicvf_reclaim_cmp_queue(nic
, qs
, qidx
);
573 /* Reset completion queue */
574 nicvf_queue_reg_write(nic
, NIC_QSET_CQ_0_7_CFG
, qidx
, NICVF_CQ_RESET
);
579 spin_lock_init(&cq
->lock
);
580 /* Set completion queue base address */
581 nicvf_queue_reg_write(nic
, NIC_QSET_CQ_0_7_BASE
,
582 qidx
, (u64
)(cq
->dmem
.phys_base
));
584 /* Enable Completion queue */
588 cq_cfg
.qsize
= CMP_QSIZE
;
590 nicvf_queue_reg_write(nic
, NIC_QSET_CQ_0_7_CFG
, qidx
, *(u64
*)&cq_cfg
);
592 /* Set threshold value for interrupt generation */
593 nicvf_queue_reg_write(nic
, NIC_QSET_CQ_0_7_THRESH
, qidx
, cq
->thresh
);
594 nicvf_queue_reg_write(nic
, NIC_QSET_CQ_0_7_CFG2
,
595 qidx
, CMP_QUEUE_TIMER_THRESH
);
598 /* Configures transmit queue */
599 static void nicvf_snd_queue_config(struct nicvf
*nic
, struct queue_set
*qs
,
600 int qidx
, bool enable
)
602 union nic_mbx mbx
= {};
603 struct snd_queue
*sq
;
604 struct sq_cfg sq_cfg
;
610 nicvf_reclaim_snd_queue(nic
, qs
, qidx
);
614 /* Reset send queue */
615 nicvf_queue_reg_write(nic
, NIC_QSET_SQ_0_7_CFG
, qidx
, NICVF_SQ_RESET
);
617 sq
->cq_qs
= qs
->vnic_id
;
620 /* Send a mailbox msg to PF to config SQ */
621 mbx
.sq
.msg
= NIC_MBOX_MSG_SQ_CFG
;
622 mbx
.sq
.qs_num
= qs
->vnic_id
;
623 mbx
.sq
.sq_num
= qidx
;
624 mbx
.sq
.sqs_mode
= nic
->sqs_mode
;
625 mbx
.sq
.cfg
= (sq
->cq_qs
<< 3) | sq
->cq_idx
;
626 nicvf_send_msg_to_pf(nic
, &mbx
);
628 /* Set queue base address */
629 nicvf_queue_reg_write(nic
, NIC_QSET_SQ_0_7_BASE
,
630 qidx
, (u64
)(sq
->dmem
.phys_base
));
632 /* Enable send queue & set queue size */
636 sq_cfg
.qsize
= SND_QSIZE
;
637 sq_cfg
.tstmp_bgx_intf
= 0;
638 nicvf_queue_reg_write(nic
, NIC_QSET_SQ_0_7_CFG
, qidx
, *(u64
*)&sq_cfg
);
640 /* Set threshold value for interrupt generation */
641 nicvf_queue_reg_write(nic
, NIC_QSET_SQ_0_7_THRESH
, qidx
, sq
->thresh
);
643 /* Set queue:cpu affinity for better load distribution */
644 if (cpu_online(qidx
)) {
645 cpumask_set_cpu(qidx
, &sq
->affinity_mask
);
646 netif_set_xps_queue(nic
->netdev
,
647 &sq
->affinity_mask
, qidx
);
651 /* Configures receive buffer descriptor ring */
652 static void nicvf_rbdr_config(struct nicvf
*nic
, struct queue_set
*qs
,
653 int qidx
, bool enable
)
656 struct rbdr_cfg rbdr_cfg
;
658 rbdr
= &qs
->rbdr
[qidx
];
659 nicvf_reclaim_rbdr(nic
, rbdr
, qidx
);
663 /* Set descriptor base address */
664 nicvf_queue_reg_write(nic
, NIC_QSET_RBDR_0_1_BASE
,
665 qidx
, (u64
)(rbdr
->dmem
.phys_base
));
667 /* Enable RBDR & set queue size */
668 /* Buffer size should be in multiples of 128 bytes */
672 rbdr_cfg
.qsize
= RBDR_SIZE
;
673 rbdr_cfg
.avg_con
= 0;
674 rbdr_cfg
.lines
= rbdr
->dma_size
/ 128;
675 nicvf_queue_reg_write(nic
, NIC_QSET_RBDR_0_1_CFG
,
676 qidx
, *(u64
*)&rbdr_cfg
);
679 nicvf_queue_reg_write(nic
, NIC_QSET_RBDR_0_1_DOOR
,
680 qidx
, qs
->rbdr_len
- 1);
682 /* Set threshold value for interrupt generation */
683 nicvf_queue_reg_write(nic
, NIC_QSET_RBDR_0_1_THRESH
,
684 qidx
, rbdr
->thresh
- 1);
687 /* Requests PF to assign and enable Qset */
688 void nicvf_qset_config(struct nicvf
*nic
, bool enable
)
690 union nic_mbx mbx
= {};
691 struct queue_set
*qs
= nic
->qs
;
692 struct qs_cfg
*qs_cfg
;
695 netdev_warn(nic
->netdev
,
696 "Qset is still not allocated, don't init queues\n");
701 qs
->vnic_id
= nic
->vf_id
;
703 /* Send a mailbox msg to PF to config Qset */
704 mbx
.qs
.msg
= NIC_MBOX_MSG_QS_CFG
;
705 mbx
.qs
.num
= qs
->vnic_id
;
706 mbx
.qs
.sqs_count
= nic
->sqs_count
;
709 qs_cfg
= (struct qs_cfg
*)&mbx
.qs
.cfg
;
715 qs_cfg
->vnic
= qs
->vnic_id
;
717 nicvf_send_msg_to_pf(nic
, &mbx
);
720 static void nicvf_free_resources(struct nicvf
*nic
)
723 struct queue_set
*qs
= nic
->qs
;
725 /* Free receive buffer descriptor ring */
726 for (qidx
= 0; qidx
< qs
->rbdr_cnt
; qidx
++)
727 nicvf_free_rbdr(nic
, &qs
->rbdr
[qidx
]);
729 /* Free completion queue */
730 for (qidx
= 0; qidx
< qs
->cq_cnt
; qidx
++)
731 nicvf_free_cmp_queue(nic
, &qs
->cq
[qidx
]);
733 /* Free send queue */
734 for (qidx
= 0; qidx
< qs
->sq_cnt
; qidx
++)
735 nicvf_free_snd_queue(nic
, &qs
->sq
[qidx
]);
738 static int nicvf_alloc_resources(struct nicvf
*nic
)
741 struct queue_set
*qs
= nic
->qs
;
743 /* Alloc receive buffer descriptor ring */
744 for (qidx
= 0; qidx
< qs
->rbdr_cnt
; qidx
++) {
745 if (nicvf_init_rbdr(nic
, &qs
->rbdr
[qidx
], qs
->rbdr_len
,
750 /* Alloc send queue */
751 for (qidx
= 0; qidx
< qs
->sq_cnt
; qidx
++) {
752 if (nicvf_init_snd_queue(nic
, &qs
->sq
[qidx
], qs
->sq_len
))
756 /* Alloc completion queue */
757 for (qidx
= 0; qidx
< qs
->cq_cnt
; qidx
++) {
758 if (nicvf_init_cmp_queue(nic
, &qs
->cq
[qidx
], qs
->cq_len
))
764 nicvf_free_resources(nic
);
768 int nicvf_set_qset_resources(struct nicvf
*nic
)
770 struct queue_set
*qs
;
772 qs
= devm_kzalloc(&nic
->pdev
->dev
, sizeof(*qs
), GFP_KERNEL
);
777 /* Set count of each queue */
778 qs
->rbdr_cnt
= RBDR_CNT
;
779 qs
->rq_cnt
= RCV_QUEUE_CNT
;
780 qs
->sq_cnt
= SND_QUEUE_CNT
;
781 qs
->cq_cnt
= CMP_QUEUE_CNT
;
783 /* Set queue lengths */
784 qs
->rbdr_len
= RCV_BUF_COUNT
;
785 qs
->sq_len
= SND_QUEUE_LEN
;
786 qs
->cq_len
= CMP_QUEUE_LEN
;
788 nic
->rx_queues
= qs
->rq_cnt
;
789 nic
->tx_queues
= qs
->sq_cnt
;
794 int nicvf_config_data_transfer(struct nicvf
*nic
, bool enable
)
796 bool disable
= false;
797 struct queue_set
*qs
= nic
->qs
;
804 if (nicvf_alloc_resources(nic
))
807 for (qidx
= 0; qidx
< qs
->sq_cnt
; qidx
++)
808 nicvf_snd_queue_config(nic
, qs
, qidx
, enable
);
809 for (qidx
= 0; qidx
< qs
->cq_cnt
; qidx
++)
810 nicvf_cmp_queue_config(nic
, qs
, qidx
, enable
);
811 for (qidx
= 0; qidx
< qs
->rbdr_cnt
; qidx
++)
812 nicvf_rbdr_config(nic
, qs
, qidx
, enable
);
813 for (qidx
= 0; qidx
< qs
->rq_cnt
; qidx
++)
814 nicvf_rcv_queue_config(nic
, qs
, qidx
, enable
);
816 for (qidx
= 0; qidx
< qs
->rq_cnt
; qidx
++)
817 nicvf_rcv_queue_config(nic
, qs
, qidx
, disable
);
818 for (qidx
= 0; qidx
< qs
->rbdr_cnt
; qidx
++)
819 nicvf_rbdr_config(nic
, qs
, qidx
, disable
);
820 for (qidx
= 0; qidx
< qs
->sq_cnt
; qidx
++)
821 nicvf_snd_queue_config(nic
, qs
, qidx
, disable
);
822 for (qidx
= 0; qidx
< qs
->cq_cnt
; qidx
++)
823 nicvf_cmp_queue_config(nic
, qs
, qidx
, disable
);
825 nicvf_free_resources(nic
);
831 /* Get a free desc from SQ
832 * returns descriptor ponter & descriptor number
834 static inline int nicvf_get_sq_desc(struct snd_queue
*sq
, int desc_cnt
)
839 atomic_sub(desc_cnt
, &sq
->free_cnt
);
840 sq
->tail
+= desc_cnt
;
841 sq
->tail
&= (sq
->dmem
.q_len
- 1);
846 /* Free descriptor back to SQ for future use */
847 void nicvf_put_sq_desc(struct snd_queue
*sq
, int desc_cnt
)
849 atomic_add(desc_cnt
, &sq
->free_cnt
);
850 sq
->head
+= desc_cnt
;
851 sq
->head
&= (sq
->dmem
.q_len
- 1);
854 static inline int nicvf_get_nxt_sqentry(struct snd_queue
*sq
, int qentry
)
857 qentry
&= (sq
->dmem
.q_len
- 1);
861 void nicvf_sq_enable(struct nicvf
*nic
, struct snd_queue
*sq
, int qidx
)
865 sq_cfg
= nicvf_queue_reg_read(nic
, NIC_QSET_SQ_0_7_CFG
, qidx
);
866 sq_cfg
|= NICVF_SQ_EN
;
867 nicvf_queue_reg_write(nic
, NIC_QSET_SQ_0_7_CFG
, qidx
, sq_cfg
);
868 /* Ring doorbell so that H/W restarts processing SQEs */
869 nicvf_queue_reg_write(nic
, NIC_QSET_SQ_0_7_DOOR
, qidx
, 0);
872 void nicvf_sq_disable(struct nicvf
*nic
, int qidx
)
876 sq_cfg
= nicvf_queue_reg_read(nic
, NIC_QSET_SQ_0_7_CFG
, qidx
);
877 sq_cfg
&= ~NICVF_SQ_EN
;
878 nicvf_queue_reg_write(nic
, NIC_QSET_SQ_0_7_CFG
, qidx
, sq_cfg
);
881 void nicvf_sq_free_used_descs(struct net_device
*netdev
, struct snd_queue
*sq
,
886 struct nicvf
*nic
= netdev_priv(netdev
);
887 struct sq_hdr_subdesc
*hdr
;
889 head
= nicvf_queue_reg_read(nic
, NIC_QSET_SQ_0_7_HEAD
, qidx
) >> 4;
890 tail
= nicvf_queue_reg_read(nic
, NIC_QSET_SQ_0_7_TAIL
, qidx
) >> 4;
891 while (sq
->head
!= head
) {
892 hdr
= (struct sq_hdr_subdesc
*)GET_SQ_DESC(sq
, sq
->head
);
893 if (hdr
->subdesc_type
!= SQ_DESC_TYPE_HEADER
) {
894 nicvf_put_sq_desc(sq
, 1);
897 skb
= (struct sk_buff
*)sq
->skbuff
[sq
->head
];
899 dev_kfree_skb_any(skb
);
900 atomic64_add(1, (atomic64_t
*)&netdev
->stats
.tx_packets
);
901 atomic64_add(hdr
->tot_len
,
902 (atomic64_t
*)&netdev
->stats
.tx_bytes
);
903 nicvf_put_sq_desc(sq
, hdr
->subdesc_cnt
+ 1);
907 /* Calculate no of SQ subdescriptors needed to transmit all
908 * segments of this TSO packet.
909 * Taken from 'Tilera network driver' with a minor modification.
911 static int nicvf_tso_count_subdescs(struct sk_buff
*skb
)
913 struct skb_shared_info
*sh
= skb_shinfo(skb
);
914 unsigned int sh_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
915 unsigned int data_len
= skb
->len
- sh_len
;
916 unsigned int p_len
= sh
->gso_size
;
917 long f_id
= -1; /* id of the current fragment */
918 long f_size
= skb_headlen(skb
) - sh_len
; /* current fragment size */
919 long f_used
= 0; /* bytes used from the current fragment */
920 long n
; /* size of the current piece of payload */
924 for (segment
= 0; segment
< sh
->gso_segs
; segment
++) {
925 unsigned int p_used
= 0;
927 /* One edesc for header and for each piece of the payload. */
928 for (num_edescs
++; p_used
< p_len
; num_edescs
++) {
929 /* Advance as needed. */
930 while (f_used
>= f_size
) {
932 f_size
= skb_frag_size(&sh
->frags
[f_id
]);
936 /* Use bytes from the current fragment. */
938 if (n
> f_size
- f_used
)
944 /* The last segment may be less than gso_size. */
946 if (data_len
< p_len
)
950 /* '+ gso_segs' for SQ_HDR_SUDESCs for each segment */
951 return num_edescs
+ sh
->gso_segs
;
954 /* Get the number of SQ descriptors needed to xmit this skb */
955 static int nicvf_sq_subdesc_required(struct nicvf
*nic
, struct sk_buff
*skb
)
957 int subdesc_cnt
= MIN_SQ_DESC_PER_PKT_XMIT
;
959 if (skb_shinfo(skb
)->gso_size
) {
960 subdesc_cnt
= nicvf_tso_count_subdescs(skb
);
964 if (skb_shinfo(skb
)->nr_frags
)
965 subdesc_cnt
+= skb_shinfo(skb
)->nr_frags
;
970 /* Add SQ HEADER subdescriptor.
971 * First subdescriptor for every send descriptor.
974 nicvf_sq_add_hdr_subdesc(struct snd_queue
*sq
, int qentry
,
975 int subdesc_cnt
, struct sk_buff
*skb
, int len
)
978 struct sq_hdr_subdesc
*hdr
;
980 hdr
= (struct sq_hdr_subdesc
*)GET_SQ_DESC(sq
, qentry
);
981 sq
->skbuff
[qentry
] = (u64
)skb
;
983 memset(hdr
, 0, SND_QUEUE_DESC_SIZE
);
984 hdr
->subdesc_type
= SQ_DESC_TYPE_HEADER
;
985 /* Enable notification via CQE after processing SQE */
987 /* No of subdescriptors following this */
988 hdr
->subdesc_cnt
= subdesc_cnt
;
991 /* Offload checksum calculation to HW */
992 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
993 hdr
->csum_l3
= 1; /* Enable IP csum calculation */
994 hdr
->l3_offset
= skb_network_offset(skb
);
995 hdr
->l4_offset
= skb_transport_offset(skb
);
997 proto
= ip_hdr(skb
)->protocol
;
1000 hdr
->csum_l4
= SEND_L4_CSUM_TCP
;
1003 hdr
->csum_l4
= SEND_L4_CSUM_UDP
;
1006 hdr
->csum_l4
= SEND_L4_CSUM_SCTP
;
1012 /* SQ GATHER subdescriptor
1013 * Must follow HDR descriptor
1015 static inline void nicvf_sq_add_gather_subdesc(struct snd_queue
*sq
, int qentry
,
1018 struct sq_gather_subdesc
*gather
;
1020 qentry
&= (sq
->dmem
.q_len
- 1);
1021 gather
= (struct sq_gather_subdesc
*)GET_SQ_DESC(sq
, qentry
);
1023 memset(gather
, 0, SND_QUEUE_DESC_SIZE
);
1024 gather
->subdesc_type
= SQ_DESC_TYPE_GATHER
;
1025 gather
->ld_type
= NIC_SEND_LD_TYPE_E_LDD
;
1026 gather
->size
= size
;
1027 gather
->addr
= data
;
1030 /* Segment a TSO packet into 'gso_size' segments and append
1031 * them to SQ for transfer
1033 static int nicvf_sq_append_tso(struct nicvf
*nic
, struct snd_queue
*sq
,
1034 int sq_num
, int qentry
, struct sk_buff
*skb
)
1037 int seg_subdescs
= 0, desc_cnt
= 0;
1038 int seg_len
, total_len
, data_left
;
1039 int hdr_qentry
= qentry
;
1040 int hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
1042 tso_start(skb
, &tso
);
1043 total_len
= skb
->len
- hdr_len
;
1044 while (total_len
> 0) {
1047 /* Save Qentry for adding HDR_SUBDESC at the end */
1048 hdr_qentry
= qentry
;
1050 data_left
= min_t(int, skb_shinfo(skb
)->gso_size
, total_len
);
1051 total_len
-= data_left
;
1053 /* Add segment's header */
1054 qentry
= nicvf_get_nxt_sqentry(sq
, qentry
);
1055 hdr
= sq
->tso_hdrs
+ qentry
* TSO_HEADER_SIZE
;
1056 tso_build_hdr(skb
, hdr
, &tso
, data_left
, total_len
== 0);
1057 nicvf_sq_add_gather_subdesc(sq
, qentry
, hdr_len
,
1059 qentry
* TSO_HEADER_SIZE
);
1060 /* HDR_SUDESC + GATHER */
1064 /* Add segment's payload fragments */
1065 while (data_left
> 0) {
1068 size
= min_t(int, tso
.size
, data_left
);
1070 qentry
= nicvf_get_nxt_sqentry(sq
, qentry
);
1071 nicvf_sq_add_gather_subdesc(sq
, qentry
, size
,
1072 virt_to_phys(tso
.data
));
1077 tso_build_data(skb
, &tso
, size
);
1079 nicvf_sq_add_hdr_subdesc(sq
, hdr_qentry
,
1080 seg_subdescs
- 1, skb
, seg_len
);
1081 sq
->skbuff
[hdr_qentry
] = (u64
)NULL
;
1082 qentry
= nicvf_get_nxt_sqentry(sq
, qentry
);
1084 desc_cnt
+= seg_subdescs
;
1086 /* Save SKB in the last segment for freeing */
1087 sq
->skbuff
[hdr_qentry
] = (u64
)skb
;
1089 /* make sure all memory stores are done before ringing doorbell */
1092 /* Inform HW to xmit all TSO segments */
1093 nicvf_queue_reg_write(nic
, NIC_QSET_SQ_0_7_DOOR
,
1095 nic
->drv_stats
.tx_tso
++;
1099 /* Append an skb to a SQ for packet transfer. */
1100 int nicvf_sq_append_skb(struct nicvf
*nic
, struct sk_buff
*skb
)
1105 struct queue_set
*qs
;
1106 struct snd_queue
*sq
;
1108 sq_num
= skb_get_queue_mapping(skb
);
1109 if (sq_num
>= MAX_SND_QUEUES_PER_QS
) {
1110 /* Get secondary Qset's SQ structure */
1111 i
= sq_num
/ MAX_SND_QUEUES_PER_QS
;
1112 if (!nic
->snicvf
[i
- 1]) {
1113 netdev_warn(nic
->netdev
,
1114 "Secondary Qset#%d's ptr not initialized\n",
1118 nic
= (struct nicvf
*)nic
->snicvf
[i
- 1];
1119 sq_num
= sq_num
% MAX_SND_QUEUES_PER_QS
;
1123 sq
= &qs
->sq
[sq_num
];
1125 subdesc_cnt
= nicvf_sq_subdesc_required(nic
, skb
);
1126 if (subdesc_cnt
> atomic_read(&sq
->free_cnt
))
1129 qentry
= nicvf_get_sq_desc(sq
, subdesc_cnt
);
1131 /* Check if its a TSO packet */
1132 if (skb_shinfo(skb
)->gso_size
)
1133 return nicvf_sq_append_tso(nic
, sq
, sq_num
, qentry
, skb
);
1135 /* Add SQ header subdesc */
1136 nicvf_sq_add_hdr_subdesc(sq
, qentry
, subdesc_cnt
- 1, skb
, skb
->len
);
1138 /* Add SQ gather subdescs */
1139 qentry
= nicvf_get_nxt_sqentry(sq
, qentry
);
1140 size
= skb_is_nonlinear(skb
) ? skb_headlen(skb
) : skb
->len
;
1141 nicvf_sq_add_gather_subdesc(sq
, qentry
, size
, virt_to_phys(skb
->data
));
1143 /* Check for scattered buffer */
1144 if (!skb_is_nonlinear(skb
))
1147 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
1148 const struct skb_frag_struct
*frag
;
1150 frag
= &skb_shinfo(skb
)->frags
[i
];
1152 qentry
= nicvf_get_nxt_sqentry(sq
, qentry
);
1153 size
= skb_frag_size(frag
);
1154 nicvf_sq_add_gather_subdesc(sq
, qentry
, size
,
1156 skb_frag_address(frag
)));
1160 /* make sure all memory stores are done before ringing doorbell */
1163 /* Inform HW to xmit new packet */
1164 nicvf_queue_reg_write(nic
, NIC_QSET_SQ_0_7_DOOR
,
1165 sq_num
, subdesc_cnt
);
1169 /* Use original PCI dev for debug log */
1171 netdev_dbg(nic
->netdev
, "Not enough SQ descriptors to xmit pkt\n");
1175 static inline unsigned frag_num(unsigned i
)
1178 return (i
& ~3) + 3 - (i
& 3);
1184 /* Returns SKB for a received packet */
1185 struct sk_buff
*nicvf_get_rcv_skb(struct nicvf
*nic
, struct cqe_rx_t
*cqe_rx
)
1188 int payload_len
= 0;
1189 struct sk_buff
*skb
= NULL
;
1190 struct sk_buff
*skb_frag
= NULL
;
1191 struct sk_buff
*prev_frag
= NULL
;
1192 u16
*rb_lens
= NULL
;
1193 u64
*rb_ptrs
= NULL
;
1195 rb_lens
= (void *)cqe_rx
+ (3 * sizeof(u64
));
1196 rb_ptrs
= (void *)cqe_rx
+ (6 * sizeof(u64
));
1198 netdev_dbg(nic
->netdev
, "%s rb_cnt %d rb0_ptr %llx rb0_sz %d\n",
1199 __func__
, cqe_rx
->rb_cnt
, cqe_rx
->rb0_ptr
, cqe_rx
->rb0_sz
);
1201 for (frag
= 0; frag
< cqe_rx
->rb_cnt
; frag
++) {
1202 payload_len
= rb_lens
[frag_num(frag
)];
1204 /* First fragment */
1205 skb
= nicvf_rb_ptr_to_skb(nic
,
1206 *rb_ptrs
- cqe_rx
->align_pad
,
1210 skb_reserve(skb
, cqe_rx
->align_pad
);
1211 skb_put(skb
, payload_len
);
1214 skb_frag
= nicvf_rb_ptr_to_skb(nic
, *rb_ptrs
,
1221 if (!skb_shinfo(skb
)->frag_list
)
1222 skb_shinfo(skb
)->frag_list
= skb_frag
;
1224 prev_frag
->next
= skb_frag
;
1226 prev_frag
= skb_frag
;
1227 skb
->len
+= payload_len
;
1228 skb
->data_len
+= payload_len
;
1229 skb_frag
->len
= payload_len
;
1231 /* Next buffer pointer */
1237 /* Enable interrupt */
1238 void nicvf_enable_intr(struct nicvf
*nic
, int int_type
, int q_idx
)
1242 reg_val
= nicvf_reg_read(nic
, NIC_VF_ENA_W1S
);
1246 reg_val
|= ((1ULL << q_idx
) << NICVF_INTR_CQ_SHIFT
);
1249 reg_val
|= ((1ULL << q_idx
) << NICVF_INTR_SQ_SHIFT
);
1251 case NICVF_INTR_RBDR
:
1252 reg_val
|= ((1ULL << q_idx
) << NICVF_INTR_RBDR_SHIFT
);
1254 case NICVF_INTR_PKT_DROP
:
1255 reg_val
|= (1ULL << NICVF_INTR_PKT_DROP_SHIFT
);
1257 case NICVF_INTR_TCP_TIMER
:
1258 reg_val
|= (1ULL << NICVF_INTR_TCP_TIMER_SHIFT
);
1260 case NICVF_INTR_MBOX
:
1261 reg_val
|= (1ULL << NICVF_INTR_MBOX_SHIFT
);
1263 case NICVF_INTR_QS_ERR
:
1264 reg_val
|= (1ULL << NICVF_INTR_QS_ERR_SHIFT
);
1267 netdev_err(nic
->netdev
,
1268 "Failed to enable interrupt: unknown type\n");
1272 nicvf_reg_write(nic
, NIC_VF_ENA_W1S
, reg_val
);
1275 /* Disable interrupt */
1276 void nicvf_disable_intr(struct nicvf
*nic
, int int_type
, int q_idx
)
1282 reg_val
|= ((1ULL << q_idx
) << NICVF_INTR_CQ_SHIFT
);
1285 reg_val
|= ((1ULL << q_idx
) << NICVF_INTR_SQ_SHIFT
);
1287 case NICVF_INTR_RBDR
:
1288 reg_val
|= ((1ULL << q_idx
) << NICVF_INTR_RBDR_SHIFT
);
1290 case NICVF_INTR_PKT_DROP
:
1291 reg_val
|= (1ULL << NICVF_INTR_PKT_DROP_SHIFT
);
1293 case NICVF_INTR_TCP_TIMER
:
1294 reg_val
|= (1ULL << NICVF_INTR_TCP_TIMER_SHIFT
);
1296 case NICVF_INTR_MBOX
:
1297 reg_val
|= (1ULL << NICVF_INTR_MBOX_SHIFT
);
1299 case NICVF_INTR_QS_ERR
:
1300 reg_val
|= (1ULL << NICVF_INTR_QS_ERR_SHIFT
);
1303 netdev_err(nic
->netdev
,
1304 "Failed to disable interrupt: unknown type\n");
1308 nicvf_reg_write(nic
, NIC_VF_ENA_W1C
, reg_val
);
1311 /* Clear interrupt */
1312 void nicvf_clear_intr(struct nicvf
*nic
, int int_type
, int q_idx
)
1318 reg_val
= ((1ULL << q_idx
) << NICVF_INTR_CQ_SHIFT
);
1321 reg_val
= ((1ULL << q_idx
) << NICVF_INTR_SQ_SHIFT
);
1323 case NICVF_INTR_RBDR
:
1324 reg_val
= ((1ULL << q_idx
) << NICVF_INTR_RBDR_SHIFT
);
1326 case NICVF_INTR_PKT_DROP
:
1327 reg_val
= (1ULL << NICVF_INTR_PKT_DROP_SHIFT
);
1329 case NICVF_INTR_TCP_TIMER
:
1330 reg_val
= (1ULL << NICVF_INTR_TCP_TIMER_SHIFT
);
1332 case NICVF_INTR_MBOX
:
1333 reg_val
= (1ULL << NICVF_INTR_MBOX_SHIFT
);
1335 case NICVF_INTR_QS_ERR
:
1336 reg_val
|= (1ULL << NICVF_INTR_QS_ERR_SHIFT
);
1339 netdev_err(nic
->netdev
,
1340 "Failed to clear interrupt: unknown type\n");
1344 nicvf_reg_write(nic
, NIC_VF_INT
, reg_val
);
1347 /* Check if interrupt is enabled */
1348 int nicvf_is_intr_enabled(struct nicvf
*nic
, int int_type
, int q_idx
)
1353 reg_val
= nicvf_reg_read(nic
, NIC_VF_ENA_W1S
);
1357 mask
= ((1ULL << q_idx
) << NICVF_INTR_CQ_SHIFT
);
1360 mask
= ((1ULL << q_idx
) << NICVF_INTR_SQ_SHIFT
);
1362 case NICVF_INTR_RBDR
:
1363 mask
= ((1ULL << q_idx
) << NICVF_INTR_RBDR_SHIFT
);
1365 case NICVF_INTR_PKT_DROP
:
1366 mask
= NICVF_INTR_PKT_DROP_MASK
;
1368 case NICVF_INTR_TCP_TIMER
:
1369 mask
= NICVF_INTR_TCP_TIMER_MASK
;
1371 case NICVF_INTR_MBOX
:
1372 mask
= NICVF_INTR_MBOX_MASK
;
1374 case NICVF_INTR_QS_ERR
:
1375 mask
= NICVF_INTR_QS_ERR_MASK
;
1378 netdev_err(nic
->netdev
,
1379 "Failed to check interrupt enable: unknown type\n");
1383 return (reg_val
& mask
);
1386 void nicvf_update_rq_stats(struct nicvf
*nic
, int rq_idx
)
1388 struct rcv_queue
*rq
;
1390 #define GET_RQ_STATS(reg) \
1391 nicvf_reg_read(nic, NIC_QSET_RQ_0_7_STAT_0_1 |\
1392 (rq_idx << NIC_Q_NUM_SHIFT) | (reg << 3))
1394 rq
= &nic
->qs
->rq
[rq_idx
];
1395 rq
->stats
.bytes
= GET_RQ_STATS(RQ_SQ_STATS_OCTS
);
1396 rq
->stats
.pkts
= GET_RQ_STATS(RQ_SQ_STATS_PKTS
);
1399 void nicvf_update_sq_stats(struct nicvf
*nic
, int sq_idx
)
1401 struct snd_queue
*sq
;
1403 #define GET_SQ_STATS(reg) \
1404 nicvf_reg_read(nic, NIC_QSET_SQ_0_7_STAT_0_1 |\
1405 (sq_idx << NIC_Q_NUM_SHIFT) | (reg << 3))
1407 sq
= &nic
->qs
->sq
[sq_idx
];
1408 sq
->stats
.bytes
= GET_SQ_STATS(RQ_SQ_STATS_OCTS
);
1409 sq
->stats
.pkts
= GET_SQ_STATS(RQ_SQ_STATS_PKTS
);
1412 /* Check for errors in the receive cmp.queue entry */
1413 int nicvf_check_cqe_rx_errs(struct nicvf
*nic
,
1414 struct cmp_queue
*cq
, struct cqe_rx_t
*cqe_rx
)
1416 struct nicvf_hw_stats
*stats
= &nic
->hw_stats
;
1417 struct nicvf_drv_stats
*drv_stats
= &nic
->drv_stats
;
1419 if (!cqe_rx
->err_level
&& !cqe_rx
->err_opcode
) {
1420 drv_stats
->rx_frames_ok
++;
1424 if (netif_msg_rx_err(nic
))
1425 netdev_err(nic
->netdev
,
1426 "%s: RX error CQE err_level 0x%x err_opcode 0x%x\n",
1428 cqe_rx
->err_level
, cqe_rx
->err_opcode
);
1430 switch (cqe_rx
->err_opcode
) {
1431 case CQ_RX_ERROP_RE_PARTIAL
:
1432 stats
->rx_bgx_truncated_pkts
++;
1434 case CQ_RX_ERROP_RE_JABBER
:
1435 stats
->rx_jabber_errs
++;
1437 case CQ_RX_ERROP_RE_FCS
:
1438 stats
->rx_fcs_errs
++;
1440 case CQ_RX_ERROP_RE_RX_CTL
:
1441 stats
->rx_bgx_errs
++;
1443 case CQ_RX_ERROP_PREL2_ERR
:
1444 stats
->rx_prel2_errs
++;
1446 case CQ_RX_ERROP_L2_MAL
:
1447 stats
->rx_l2_hdr_malformed
++;
1449 case CQ_RX_ERROP_L2_OVERSIZE
:
1450 stats
->rx_oversize
++;
1452 case CQ_RX_ERROP_L2_UNDERSIZE
:
1453 stats
->rx_undersize
++;
1455 case CQ_RX_ERROP_L2_LENMISM
:
1456 stats
->rx_l2_len_mismatch
++;
1458 case CQ_RX_ERROP_L2_PCLP
:
1459 stats
->rx_l2_pclp
++;
1461 case CQ_RX_ERROP_IP_NOT
:
1462 stats
->rx_ip_ver_errs
++;
1464 case CQ_RX_ERROP_IP_CSUM_ERR
:
1465 stats
->rx_ip_csum_errs
++;
1467 case CQ_RX_ERROP_IP_MAL
:
1468 stats
->rx_ip_hdr_malformed
++;
1470 case CQ_RX_ERROP_IP_MALD
:
1471 stats
->rx_ip_payload_malformed
++;
1473 case CQ_RX_ERROP_IP_HOP
:
1474 stats
->rx_ip_ttl_errs
++;
1476 case CQ_RX_ERROP_L3_PCLP
:
1477 stats
->rx_l3_pclp
++;
1479 case CQ_RX_ERROP_L4_MAL
:
1480 stats
->rx_l4_malformed
++;
1482 case CQ_RX_ERROP_L4_CHK
:
1483 stats
->rx_l4_csum_errs
++;
1485 case CQ_RX_ERROP_UDP_LEN
:
1486 stats
->rx_udp_len_errs
++;
1488 case CQ_RX_ERROP_L4_PORT
:
1489 stats
->rx_l4_port_errs
++;
1491 case CQ_RX_ERROP_TCP_FLAG
:
1492 stats
->rx_tcp_flag_errs
++;
1494 case CQ_RX_ERROP_TCP_OFFSET
:
1495 stats
->rx_tcp_offset_errs
++;
1497 case CQ_RX_ERROP_L4_PCLP
:
1498 stats
->rx_l4_pclp
++;
1500 case CQ_RX_ERROP_RBDR_TRUNC
:
1501 stats
->rx_truncated_pkts
++;
1508 /* Check for errors in the send cmp.queue entry */
1509 int nicvf_check_cqe_tx_errs(struct nicvf
*nic
,
1510 struct cmp_queue
*cq
, struct cqe_send_t
*cqe_tx
)
1512 struct cmp_queue_stats
*stats
= &cq
->stats
;
1514 switch (cqe_tx
->send_status
) {
1515 case CQ_TX_ERROP_GOOD
:
1518 case CQ_TX_ERROP_DESC_FAULT
:
1519 stats
->tx
.desc_fault
++;
1521 case CQ_TX_ERROP_HDR_CONS_ERR
:
1522 stats
->tx
.hdr_cons_err
++;
1524 case CQ_TX_ERROP_SUBDC_ERR
:
1525 stats
->tx
.subdesc_err
++;
1527 case CQ_TX_ERROP_IMM_SIZE_OFLOW
:
1528 stats
->tx
.imm_size_oflow
++;
1530 case CQ_TX_ERROP_DATA_SEQUENCE_ERR
:
1531 stats
->tx
.data_seq_err
++;
1533 case CQ_TX_ERROP_MEM_SEQUENCE_ERR
:
1534 stats
->tx
.mem_seq_err
++;
1536 case CQ_TX_ERROP_LOCK_VIOL
:
1537 stats
->tx
.lock_viol
++;
1539 case CQ_TX_ERROP_DATA_FAULT
:
1540 stats
->tx
.data_fault
++;
1542 case CQ_TX_ERROP_TSTMP_CONFLICT
:
1543 stats
->tx
.tstmp_conflict
++;
1545 case CQ_TX_ERROP_TSTMP_TIMEOUT
:
1546 stats
->tx
.tstmp_timeout
++;
1548 case CQ_TX_ERROP_MEM_FAULT
:
1549 stats
->tx
.mem_fault
++;
1551 case CQ_TX_ERROP_CK_OVERLAP
:
1552 stats
->tx
.csum_overlap
++;
1554 case CQ_TX_ERROP_CK_OFLOW
:
1555 stats
->tx
.csum_overflow
++;