blob: 5009f497e64f07f20a0ee527fc3ca4cc43837952 [file] [log] [blame]
Sunil Goutham4863dea2015-05-26 19:20:15 -07001/*
2 * Copyright (C) 2015 Cavium, Inc.
3 *
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.
7 */
8
9#include <linux/pci.h>
10#include <linux/netdevice.h>
11#include <linux/ip.h>
12#include <linux/etherdevice.h>
Sunil Goutham83abb7d2017-03-07 18:09:08 +053013#include <linux/iommu.h>
Sunil Goutham4863dea2015-05-26 19:20:15 -070014#include <net/ip.h>
15#include <net/tso.h>
16
17#include "nic_reg.h"
18#include "nic.h"
19#include "q_struct.h"
20#include "nicvf_queues.h"
21
Sunil Goutham5c2e26f2016-03-14 16:36:14 +053022static void nicvf_get_page(struct nicvf *nic)
23{
24 if (!nic->rb_pageref || !nic->rb_page)
25 return;
26
Joonsoo Kim6d061f92016-05-19 17:10:46 -070027 page_ref_add(nic->rb_page, nic->rb_pageref);
Sunil Goutham5c2e26f2016-03-14 16:36:14 +053028 nic->rb_pageref = 0;
29}
30
Sunil Goutham4863dea2015-05-26 19:20:15 -070031/* Poll a register for a specific value */
32static int nicvf_poll_reg(struct nicvf *nic, int qidx,
33 u64 reg, int bit_pos, int bits, int val)
34{
35 u64 bit_mask;
36 u64 reg_val;
37 int timeout = 10;
38
39 bit_mask = (1ULL << bits) - 1;
40 bit_mask = (bit_mask << bit_pos);
41
42 while (timeout) {
43 reg_val = nicvf_queue_reg_read(nic, reg, qidx);
44 if (((reg_val & bit_mask) >> bit_pos) == val)
45 return 0;
46 usleep_range(1000, 2000);
47 timeout--;
48 }
49 netdev_err(nic->netdev, "Poll on reg 0x%llx failed\n", reg);
50 return 1;
51}
52
53/* Allocate memory for a queue's descriptors */
54static int nicvf_alloc_q_desc_mem(struct nicvf *nic, struct q_desc_mem *dmem,
55 int q_len, int desc_size, int align_bytes)
56{
57 dmem->q_len = q_len;
58 dmem->size = (desc_size * q_len) + align_bytes;
59 /* Save address, need it while freeing */
60 dmem->unalign_base = dma_zalloc_coherent(&nic->pdev->dev, dmem->size,
61 &dmem->dma, GFP_KERNEL);
62 if (!dmem->unalign_base)
63 return -ENOMEM;
64
65 /* Align memory address for 'align_bytes' */
66 dmem->phys_base = NICVF_ALIGNED_ADDR((u64)dmem->dma, align_bytes);
Aleksey Makarov39a0dd02015-06-02 11:00:25 -070067 dmem->base = dmem->unalign_base + (dmem->phys_base - dmem->dma);
Sunil Goutham4863dea2015-05-26 19:20:15 -070068 return 0;
69}
70
71/* Free queue's descriptor memory */
72static void nicvf_free_q_desc_mem(struct nicvf *nic, struct q_desc_mem *dmem)
73{
74 if (!dmem)
75 return;
76
77 dma_free_coherent(&nic->pdev->dev, dmem->size,
78 dmem->unalign_base, dmem->dma);
79 dmem->unalign_base = NULL;
80 dmem->base = NULL;
81}
82
Sunil Goutham5836b442017-05-02 18:36:50 +053083/* Allocate a new page or recycle one if possible
84 *
85 * We cannot optimize dma mapping here, since
86 * 1. It's only one RBDR ring for 8 Rx queues.
87 * 2. CQE_RX gives address of the buffer where pkt has been DMA'ed
88 * and not idx into RBDR ring, so can't refer to saved info.
89 * 3. There are multiple receive buffers per page
Sunil Goutham4863dea2015-05-26 19:20:15 -070090 */
Sunil Goutham5836b442017-05-02 18:36:50 +053091static struct pgcache *nicvf_alloc_page(struct nicvf *nic,
92 struct rbdr *rbdr, gfp_t gfp)
Sunil Goutham4863dea2015-05-26 19:20:15 -070093{
Sunil Goutham5836b442017-05-02 18:36:50 +053094 struct page *page = NULL;
95 struct pgcache *pgcache, *next;
96
97 /* Check if page is already allocated */
98 pgcache = &rbdr->pgcache[rbdr->pgidx];
99 page = pgcache->page;
100 /* Check if page can be recycled */
101 if (page && (page_ref_count(page) != 1))
102 page = NULL;
103
104 if (!page) {
105 page = alloc_pages(gfp | __GFP_COMP | __GFP_NOWARN, 0);
106 if (!page)
107 return NULL;
108
109 this_cpu_inc(nic->pnicvf->drv_stats->page_alloc);
110
111 /* Check for space */
112 if (rbdr->pgalloc >= rbdr->pgcnt) {
113 /* Page can still be used */
114 nic->rb_page = page;
115 return NULL;
116 }
117
118 /* Save the page in page cache */
119 pgcache->page = page;
Sunil Gouthamc56d91c2017-05-02 18:36:55 +0530120 pgcache->dma_addr = 0;
Sunil Goutham5836b442017-05-02 18:36:50 +0530121 rbdr->pgalloc++;
122 }
123
124 /* Take extra page reference for recycling */
125 page_ref_add(page, 1);
126
127 rbdr->pgidx++;
128 rbdr->pgidx &= (rbdr->pgcnt - 1);
129
130 /* Prefetch refcount of next page in page cache */
131 next = &rbdr->pgcache[rbdr->pgidx];
132 page = next->page;
133 if (page)
134 prefetch(&page->_refcount);
135
136 return pgcache;
137}
138
139/* Allocate buffer for packet reception */
140static inline int nicvf_alloc_rcv_buffer(struct nicvf *nic, struct rbdr *rbdr,
Sunil Goutham927987f2017-05-02 18:36:53 +0530141 gfp_t gfp, u32 buf_len, u64 *rbuf)
Sunil Goutham5836b442017-05-02 18:36:50 +0530142{
143 struct pgcache *pgcache = NULL;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700144
Sunil Goutham05c773f2017-05-02 18:36:54 +0530145 /* Check if request can be accomodated in previous allocated page.
146 * But in XDP mode only one buffer per page is permitted.
147 */
Sunil Gouthamc56d91c2017-05-02 18:36:55 +0530148 if (!rbdr->is_xdp && nic->rb_page &&
Sunil Goutham5836b442017-05-02 18:36:50 +0530149 ((nic->rb_page_offset + buf_len) <= PAGE_SIZE)) {
Sunil Goutham5c2e26f2016-03-14 16:36:14 +0530150 nic->rb_pageref++;
151 goto ret;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700152 }
153
Sunil Goutham5c2e26f2016-03-14 16:36:14 +0530154 nicvf_get_page(nic);
Sunil Goutham5836b442017-05-02 18:36:50 +0530155 nic->rb_page = NULL;
Sunil Goutham5c2e26f2016-03-14 16:36:14 +0530156
Sunil Goutham5836b442017-05-02 18:36:50 +0530157 /* Get new page, either recycled or new one */
158 pgcache = nicvf_alloc_page(nic, rbdr, gfp);
159 if (!pgcache && !nic->rb_page) {
Sunil Goutham83abb7d2017-03-07 18:09:08 +0530160 this_cpu_inc(nic->pnicvf->drv_stats->rcv_buffer_alloc_failures);
161 return -ENOMEM;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700162 }
Sunil Goutham5836b442017-05-02 18:36:50 +0530163
Sunil Goutham83abb7d2017-03-07 18:09:08 +0530164 nic->rb_page_offset = 0;
Sunil Goutham5836b442017-05-02 18:36:50 +0530165 /* Check if it's recycled */
166 if (pgcache)
167 nic->rb_page = pgcache->page;
Sunil Goutham5c2e26f2016-03-14 16:36:14 +0530168ret:
Sunil Gouthamc56d91c2017-05-02 18:36:55 +0530169 if (rbdr->is_xdp && pgcache && pgcache->dma_addr) {
170 *rbuf = pgcache->dma_addr;
171 } else {
172 /* HW will ensure data coherency, CPU sync not required */
173 *rbuf = (u64)dma_map_page_attrs(&nic->pdev->dev, nic->rb_page,
174 nic->rb_page_offset, buf_len,
175 DMA_FROM_DEVICE,
176 DMA_ATTR_SKIP_CPU_SYNC);
177 if (dma_mapping_error(&nic->pdev->dev, (dma_addr_t)*rbuf)) {
178 if (!nic->rb_page_offset)
179 __free_pages(nic->rb_page, 0);
180 nic->rb_page = NULL;
181 return -ENOMEM;
182 }
183 if (pgcache)
184 pgcache->dma_addr = *rbuf;
185 nic->rb_page_offset += buf_len;
Sunil Goutham83abb7d2017-03-07 18:09:08 +0530186 }
Sunil Goutham4863dea2015-05-26 19:20:15 -0700187
Sunil Goutham4863dea2015-05-26 19:20:15 -0700188 return 0;
189}
190
Sunil Goutham668dda02015-12-07 10:30:33 +0530191/* Build skb around receive buffer */
Sunil Goutham4863dea2015-05-26 19:20:15 -0700192static struct sk_buff *nicvf_rb_ptr_to_skb(struct nicvf *nic,
193 u64 rb_ptr, int len)
194{
Sunil Goutham668dda02015-12-07 10:30:33 +0530195 void *data;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700196 struct sk_buff *skb;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700197
Sunil Goutham668dda02015-12-07 10:30:33 +0530198 data = phys_to_virt(rb_ptr);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700199
200 /* Now build an skb to give to stack */
Sunil Goutham668dda02015-12-07 10:30:33 +0530201 skb = build_skb(data, RCV_FRAG_LEN);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700202 if (!skb) {
Sunil Goutham668dda02015-12-07 10:30:33 +0530203 put_page(virt_to_page(data));
Sunil Goutham4863dea2015-05-26 19:20:15 -0700204 return NULL;
205 }
206
Sunil Goutham668dda02015-12-07 10:30:33 +0530207 prefetch(skb->data);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700208 return skb;
209}
210
211/* Allocate RBDR ring and populate receive buffers */
212static int nicvf_init_rbdr(struct nicvf *nic, struct rbdr *rbdr,
213 int ring_len, int buf_size)
214{
215 int idx;
Sunil Goutham927987f2017-05-02 18:36:53 +0530216 u64 rbuf;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700217 struct rbdr_entry_t *desc;
218 int err;
219
220 err = nicvf_alloc_q_desc_mem(nic, &rbdr->dmem, ring_len,
221 sizeof(struct rbdr_entry_t),
222 NICVF_RCV_BUF_ALIGN_BYTES);
223 if (err)
224 return err;
225
226 rbdr->desc = rbdr->dmem.base;
227 /* Buffer size has to be in multiples of 128 bytes */
228 rbdr->dma_size = buf_size;
229 rbdr->enable = true;
230 rbdr->thresh = RBDR_THRESH;
Sunil Goutham83abb7d2017-03-07 18:09:08 +0530231 rbdr->head = 0;
232 rbdr->tail = 0;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700233
Sunil Goutham5836b442017-05-02 18:36:50 +0530234 /* Initialize page recycling stuff.
235 *
236 * Can't use single buffer per page especially with 64K pages.
237 * On embedded platforms i.e 81xx/83xx available memory itself
238 * is low and minimum ring size of RBDR is 8K, that takes away
239 * lots of memory.
Sunil Gouthamc56d91c2017-05-02 18:36:55 +0530240 *
241 * But for XDP it has to be a single buffer per page.
Sunil Goutham5836b442017-05-02 18:36:50 +0530242 */
Sunil Gouthamc56d91c2017-05-02 18:36:55 +0530243 if (!nic->pnicvf->xdp_prog) {
244 rbdr->pgcnt = ring_len / (PAGE_SIZE / buf_size);
245 rbdr->is_xdp = false;
246 } else {
247 rbdr->pgcnt = ring_len;
248 rbdr->is_xdp = true;
249 }
Sunil Goutham5836b442017-05-02 18:36:50 +0530250 rbdr->pgcnt = roundup_pow_of_two(rbdr->pgcnt);
251 rbdr->pgcache = kzalloc(sizeof(*rbdr->pgcache) *
252 rbdr->pgcnt, GFP_KERNEL);
253 if (!rbdr->pgcache)
254 return -ENOMEM;
255 rbdr->pgidx = 0;
256 rbdr->pgalloc = 0;
257
Sunil Goutham4863dea2015-05-26 19:20:15 -0700258 nic->rb_page = NULL;
259 for (idx = 0; idx < ring_len; idx++) {
Sunil Goutham5836b442017-05-02 18:36:50 +0530260 err = nicvf_alloc_rcv_buffer(nic, rbdr, GFP_KERNEL,
261 RCV_FRAG_LEN, &rbuf);
Sunil Goutham83abb7d2017-03-07 18:09:08 +0530262 if (err) {
263 /* To free already allocated and mapped ones */
264 rbdr->tail = idx - 1;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700265 return err;
Sunil Goutham83abb7d2017-03-07 18:09:08 +0530266 }
Sunil Goutham4863dea2015-05-26 19:20:15 -0700267
268 desc = GET_RBDR_DESC(rbdr, idx);
Sunil Goutham927987f2017-05-02 18:36:53 +0530269 desc->buf_addr = rbuf & ~(NICVF_RCV_BUF_ALIGN_BYTES - 1);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700270 }
Sunil Goutham5c2e26f2016-03-14 16:36:14 +0530271
272 nicvf_get_page(nic);
273
Sunil Goutham4863dea2015-05-26 19:20:15 -0700274 return 0;
275}
276
277/* Free RBDR ring and its receive buffers */
278static void nicvf_free_rbdr(struct nicvf *nic, struct rbdr *rbdr)
279{
280 int head, tail;
Sunil Goutham83abb7d2017-03-07 18:09:08 +0530281 u64 buf_addr, phys_addr;
Sunil Goutham5836b442017-05-02 18:36:50 +0530282 struct pgcache *pgcache;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700283 struct rbdr_entry_t *desc;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700284
285 if (!rbdr)
286 return;
287
288 rbdr->enable = false;
289 if (!rbdr->dmem.base)
290 return;
291
292 head = rbdr->head;
293 tail = rbdr->tail;
294
Sunil Goutham83abb7d2017-03-07 18:09:08 +0530295 /* Release page references */
Sunil Goutham4863dea2015-05-26 19:20:15 -0700296 while (head != tail) {
297 desc = GET_RBDR_DESC(rbdr, head);
Sunil Goutham5e848e42017-05-02 18:36:51 +0530298 buf_addr = desc->buf_addr;
Sunil Goutham83abb7d2017-03-07 18:09:08 +0530299 phys_addr = nicvf_iova_to_phys(nic, buf_addr);
300 dma_unmap_page_attrs(&nic->pdev->dev, buf_addr, RCV_FRAG_LEN,
301 DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
302 if (phys_addr)
303 put_page(virt_to_page(phys_to_virt(phys_addr)));
Sunil Goutham4863dea2015-05-26 19:20:15 -0700304 head++;
305 head &= (rbdr->dmem.q_len - 1);
306 }
Sunil Goutham83abb7d2017-03-07 18:09:08 +0530307 /* Release buffer of tail desc */
Sunil Goutham4863dea2015-05-26 19:20:15 -0700308 desc = GET_RBDR_DESC(rbdr, tail);
Sunil Goutham5e848e42017-05-02 18:36:51 +0530309 buf_addr = desc->buf_addr;
Sunil Goutham83abb7d2017-03-07 18:09:08 +0530310 phys_addr = nicvf_iova_to_phys(nic, buf_addr);
311 dma_unmap_page_attrs(&nic->pdev->dev, buf_addr, RCV_FRAG_LEN,
312 DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
313 if (phys_addr)
314 put_page(virt_to_page(phys_to_virt(phys_addr)));
Sunil Goutham4863dea2015-05-26 19:20:15 -0700315
Sunil Goutham5836b442017-05-02 18:36:50 +0530316 /* Sync page cache info */
317 smp_rmb();
318
319 /* Release additional page references held for recycling */
320 head = 0;
321 while (head < rbdr->pgcnt) {
322 pgcache = &rbdr->pgcache[head];
323 if (pgcache->page && page_ref_count(pgcache->page) != 0)
324 put_page(pgcache->page);
325 head++;
326 }
327
Sunil Goutham4863dea2015-05-26 19:20:15 -0700328 /* Free RBDR ring */
329 nicvf_free_q_desc_mem(nic, &rbdr->dmem);
330}
331
332/* Refill receive buffer descriptors with new buffers.
333 */
Aleksey Makarovfd7ec062015-06-02 11:00:23 -0700334static void nicvf_refill_rbdr(struct nicvf *nic, gfp_t gfp)
Sunil Goutham4863dea2015-05-26 19:20:15 -0700335{
336 struct queue_set *qs = nic->qs;
337 int rbdr_idx = qs->rbdr_cnt;
338 int tail, qcount;
339 int refill_rb_cnt;
340 struct rbdr *rbdr;
341 struct rbdr_entry_t *desc;
Sunil Goutham927987f2017-05-02 18:36:53 +0530342 u64 rbuf;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700343 int new_rb = 0;
344
345refill:
346 if (!rbdr_idx)
347 return;
348 rbdr_idx--;
349 rbdr = &qs->rbdr[rbdr_idx];
350 /* Check if it's enabled */
351 if (!rbdr->enable)
352 goto next_rbdr;
353
354 /* Get no of desc's to be refilled */
355 qcount = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_STATUS0, rbdr_idx);
356 qcount &= 0x7FFFF;
357 /* Doorbell can be ringed with a max of ring size minus 1 */
358 if (qcount >= (qs->rbdr_len - 1))
359 goto next_rbdr;
360 else
361 refill_rb_cnt = qs->rbdr_len - qcount - 1;
362
Sunil Goutham5836b442017-05-02 18:36:50 +0530363 /* Sync page cache info */
364 smp_rmb();
365
Sunil Goutham4863dea2015-05-26 19:20:15 -0700366 /* Start filling descs from tail */
367 tail = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_TAIL, rbdr_idx) >> 3;
368 while (refill_rb_cnt) {
369 tail++;
370 tail &= (rbdr->dmem.q_len - 1);
371
Sunil Goutham5836b442017-05-02 18:36:50 +0530372 if (nicvf_alloc_rcv_buffer(nic, rbdr, gfp, RCV_FRAG_LEN, &rbuf))
Sunil Goutham4863dea2015-05-26 19:20:15 -0700373 break;
374
375 desc = GET_RBDR_DESC(rbdr, tail);
Sunil Goutham927987f2017-05-02 18:36:53 +0530376 desc->buf_addr = rbuf & ~(NICVF_RCV_BUF_ALIGN_BYTES - 1);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700377 refill_rb_cnt--;
378 new_rb++;
379 }
380
Sunil Goutham5c2e26f2016-03-14 16:36:14 +0530381 nicvf_get_page(nic);
382
Sunil Goutham4863dea2015-05-26 19:20:15 -0700383 /* make sure all memory stores are done before ringing doorbell */
384 smp_wmb();
385
386 /* Check if buffer allocation failed */
387 if (refill_rb_cnt)
388 nic->rb_alloc_fail = true;
389 else
390 nic->rb_alloc_fail = false;
391
392 /* Notify HW */
393 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_DOOR,
394 rbdr_idx, new_rb);
395next_rbdr:
396 /* Re-enable RBDR interrupts only if buffer allocation is success */
Sunil Gouthamc94acf82016-11-15 17:38:29 +0530397 if (!nic->rb_alloc_fail && rbdr->enable &&
398 netif_running(nic->pnicvf->netdev))
Sunil Goutham4863dea2015-05-26 19:20:15 -0700399 nicvf_enable_intr(nic, NICVF_INTR_RBDR, rbdr_idx);
400
401 if (rbdr_idx)
402 goto refill;
403}
404
405/* Alloc rcv buffers in non-atomic mode for better success */
406void nicvf_rbdr_work(struct work_struct *work)
407{
408 struct nicvf *nic = container_of(work, struct nicvf, rbdr_work.work);
409
410 nicvf_refill_rbdr(nic, GFP_KERNEL);
411 if (nic->rb_alloc_fail)
412 schedule_delayed_work(&nic->rbdr_work, msecs_to_jiffies(10));
413 else
414 nic->rb_work_scheduled = false;
415}
416
417/* In Softirq context, alloc rcv buffers in atomic mode */
418void nicvf_rbdr_task(unsigned long data)
419{
420 struct nicvf *nic = (struct nicvf *)data;
421
422 nicvf_refill_rbdr(nic, GFP_ATOMIC);
423 if (nic->rb_alloc_fail) {
424 nic->rb_work_scheduled = true;
425 schedule_delayed_work(&nic->rbdr_work, msecs_to_jiffies(10));
426 }
427}
428
429/* Initialize completion queue */
430static int nicvf_init_cmp_queue(struct nicvf *nic,
431 struct cmp_queue *cq, int q_len)
432{
433 int err;
434
435 err = nicvf_alloc_q_desc_mem(nic, &cq->dmem, q_len, CMP_QUEUE_DESC_SIZE,
436 NICVF_CQ_BASE_ALIGN_BYTES);
437 if (err)
438 return err;
439
440 cq->desc = cq->dmem.base;
Sunil Gouthamb9687b42015-12-10 13:25:20 +0530441 cq->thresh = pass1_silicon(nic->pdev) ? 0 : CMP_QUEUE_CQE_THRESH;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700442 nic->cq_coalesce_usecs = (CMP_QUEUE_TIMER_THRESH * 0.05) - 1;
443
444 return 0;
445}
446
447static void nicvf_free_cmp_queue(struct nicvf *nic, struct cmp_queue *cq)
448{
449 if (!cq)
450 return;
451 if (!cq->dmem.base)
452 return;
453
454 nicvf_free_q_desc_mem(nic, &cq->dmem);
455}
456
457/* Initialize transmit queue */
458static int nicvf_init_snd_queue(struct nicvf *nic,
459 struct snd_queue *sq, int q_len)
460{
461 int err;
462
463 err = nicvf_alloc_q_desc_mem(nic, &sq->dmem, q_len, SND_QUEUE_DESC_SIZE,
464 NICVF_SQ_BASE_ALIGN_BYTES);
465 if (err)
466 return err;
467
468 sq->desc = sq->dmem.base;
Aleksey Makarov86ace692015-06-02 11:00:27 -0700469 sq->skbuff = kcalloc(q_len, sizeof(u64), GFP_KERNEL);
Aleksey Makarovfa1a6c92015-06-02 11:00:26 -0700470 if (!sq->skbuff)
471 return -ENOMEM;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700472 sq->head = 0;
473 sq->tail = 0;
474 atomic_set(&sq->free_cnt, q_len - 1);
475 sq->thresh = SND_QUEUE_THRESH;
476
477 /* Preallocate memory for TSO segment's header */
478 sq->tso_hdrs = dma_alloc_coherent(&nic->pdev->dev,
479 q_len * TSO_HEADER_SIZE,
480 &sq->tso_hdrs_phys, GFP_KERNEL);
481 if (!sq->tso_hdrs)
482 return -ENOMEM;
483
484 return 0;
485}
486
Sunil Goutham83abb7d2017-03-07 18:09:08 +0530487void nicvf_unmap_sndq_buffers(struct nicvf *nic, struct snd_queue *sq,
488 int hdr_sqe, u8 subdesc_cnt)
489{
490 u8 idx;
491 struct sq_gather_subdesc *gather;
492
493 /* Unmap DMA mapped skb data buffers */
494 for (idx = 0; idx < subdesc_cnt; idx++) {
495 hdr_sqe++;
496 hdr_sqe &= (sq->dmem.q_len - 1);
497 gather = (struct sq_gather_subdesc *)GET_SQ_DESC(sq, hdr_sqe);
498 /* HW will ensure data coherency, CPU sync not required */
499 dma_unmap_page_attrs(&nic->pdev->dev, gather->addr,
500 gather->size, DMA_TO_DEVICE,
501 DMA_ATTR_SKIP_CPU_SYNC);
502 }
503}
504
Sunil Goutham4863dea2015-05-26 19:20:15 -0700505static void nicvf_free_snd_queue(struct nicvf *nic, struct snd_queue *sq)
506{
Sunil Gouthamc94acf82016-11-15 17:38:29 +0530507 struct sk_buff *skb;
Sunil Goutham83abb7d2017-03-07 18:09:08 +0530508 struct sq_hdr_subdesc *hdr;
509 struct sq_hdr_subdesc *tso_sqe;
Sunil Gouthamc94acf82016-11-15 17:38:29 +0530510
Sunil Goutham4863dea2015-05-26 19:20:15 -0700511 if (!sq)
512 return;
513 if (!sq->dmem.base)
514 return;
515
516 if (sq->tso_hdrs)
Sunil Goutham143ceb02015-07-29 16:49:37 +0300517 dma_free_coherent(&nic->pdev->dev,
518 sq->dmem.q_len * TSO_HEADER_SIZE,
Sunil Goutham4863dea2015-05-26 19:20:15 -0700519 sq->tso_hdrs, sq->tso_hdrs_phys);
520
Sunil Gouthamc94acf82016-11-15 17:38:29 +0530521 /* Free pending skbs in the queue */
522 smp_rmb();
523 while (sq->head != sq->tail) {
524 skb = (struct sk_buff *)sq->skbuff[sq->head];
Sunil Goutham83abb7d2017-03-07 18:09:08 +0530525 if (!skb)
526 goto next;
527 hdr = (struct sq_hdr_subdesc *)GET_SQ_DESC(sq, sq->head);
528 /* Check for dummy descriptor used for HW TSO offload on 88xx */
529 if (hdr->dont_send) {
530 /* Get actual TSO descriptors and unmap them */
531 tso_sqe =
532 (struct sq_hdr_subdesc *)GET_SQ_DESC(sq, hdr->rsvd2);
533 nicvf_unmap_sndq_buffers(nic, sq, hdr->rsvd2,
534 tso_sqe->subdesc_cnt);
535 } else {
536 nicvf_unmap_sndq_buffers(nic, sq, sq->head,
537 hdr->subdesc_cnt);
538 }
539 dev_kfree_skb_any(skb);
540next:
Sunil Gouthamc94acf82016-11-15 17:38:29 +0530541 sq->head++;
542 sq->head &= (sq->dmem.q_len - 1);
543 }
Sunil Goutham4863dea2015-05-26 19:20:15 -0700544 kfree(sq->skbuff);
545 nicvf_free_q_desc_mem(nic, &sq->dmem);
546}
547
548static void nicvf_reclaim_snd_queue(struct nicvf *nic,
549 struct queue_set *qs, int qidx)
550{
551 /* Disable send queue */
552 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_CFG, qidx, 0);
553 /* Check if SQ is stopped */
554 if (nicvf_poll_reg(nic, qidx, NIC_QSET_SQ_0_7_STATUS, 21, 1, 0x01))
555 return;
556 /* Reset send queue */
557 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_CFG, qidx, NICVF_SQ_RESET);
558}
559
560static void nicvf_reclaim_rcv_queue(struct nicvf *nic,
561 struct queue_set *qs, int qidx)
562{
563 union nic_mbx mbx = {};
564
565 /* Make sure all packets in the pipeline are written back into mem */
566 mbx.msg.msg = NIC_MBOX_MSG_RQ_SW_SYNC;
567 nicvf_send_msg_to_pf(nic, &mbx);
568}
569
570static void nicvf_reclaim_cmp_queue(struct nicvf *nic,
571 struct queue_set *qs, int qidx)
572{
573 /* Disable timer threshold (doesn't get reset upon CQ reset */
574 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_CFG2, qidx, 0);
575 /* Disable completion queue */
576 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_CFG, qidx, 0);
577 /* Reset completion queue */
578 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_CFG, qidx, NICVF_CQ_RESET);
579}
580
581static void nicvf_reclaim_rbdr(struct nicvf *nic,
582 struct rbdr *rbdr, int qidx)
583{
584 u64 tmp, fifo_state;
585 int timeout = 10;
586
587 /* Save head and tail pointers for feeing up buffers */
588 rbdr->head = nicvf_queue_reg_read(nic,
589 NIC_QSET_RBDR_0_1_HEAD,
590 qidx) >> 3;
591 rbdr->tail = nicvf_queue_reg_read(nic,
592 NIC_QSET_RBDR_0_1_TAIL,
593 qidx) >> 3;
594
595 /* If RBDR FIFO is in 'FAIL' state then do a reset first
596 * before relaiming.
597 */
598 fifo_state = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_STATUS0, qidx);
599 if (((fifo_state >> 62) & 0x03) == 0x3)
600 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_CFG,
601 qidx, NICVF_RBDR_RESET);
602
603 /* Disable RBDR */
604 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_CFG, qidx, 0);
605 if (nicvf_poll_reg(nic, qidx, NIC_QSET_RBDR_0_1_STATUS0, 62, 2, 0x00))
606 return;
607 while (1) {
608 tmp = nicvf_queue_reg_read(nic,
609 NIC_QSET_RBDR_0_1_PREFETCH_STATUS,
610 qidx);
611 if ((tmp & 0xFFFFFFFF) == ((tmp >> 32) & 0xFFFFFFFF))
612 break;
613 usleep_range(1000, 2000);
614 timeout--;
615 if (!timeout) {
616 netdev_err(nic->netdev,
617 "Failed polling on prefetch status\n");
618 return;
619 }
620 }
621 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_CFG,
622 qidx, NICVF_RBDR_RESET);
623
624 if (nicvf_poll_reg(nic, qidx, NIC_QSET_RBDR_0_1_STATUS0, 62, 2, 0x02))
625 return;
626 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_CFG, qidx, 0x00);
627 if (nicvf_poll_reg(nic, qidx, NIC_QSET_RBDR_0_1_STATUS0, 62, 2, 0x00))
628 return;
629}
630
Sunil Gouthamaa2e2592015-08-30 12:29:13 +0300631void nicvf_config_vlan_stripping(struct nicvf *nic, netdev_features_t features)
632{
633 u64 rq_cfg;
634 int sqs;
635
636 rq_cfg = nicvf_queue_reg_read(nic, NIC_QSET_RQ_GEN_CFG, 0);
637
638 /* Enable first VLAN stripping */
639 if (features & NETIF_F_HW_VLAN_CTAG_RX)
640 rq_cfg |= (1ULL << 25);
641 else
642 rq_cfg &= ~(1ULL << 25);
643 nicvf_queue_reg_write(nic, NIC_QSET_RQ_GEN_CFG, 0, rq_cfg);
644
645 /* Configure Secondary Qsets, if any */
646 for (sqs = 0; sqs < nic->sqs_count; sqs++)
647 if (nic->snicvf[sqs])
648 nicvf_queue_reg_write(nic->snicvf[sqs],
649 NIC_QSET_RQ_GEN_CFG, 0, rq_cfg);
650}
651
Jerin Jacob3458c402016-08-12 16:51:39 +0530652static void nicvf_reset_rcv_queue_stats(struct nicvf *nic)
653{
654 union nic_mbx mbx = {};
655
Sunil Goutham964cb692016-11-15 17:38:16 +0530656 /* Reset all RQ/SQ and VF stats */
Jerin Jacob3458c402016-08-12 16:51:39 +0530657 mbx.reset_stat.msg = NIC_MBOX_MSG_RESET_STAT_COUNTER;
Sunil Goutham964cb692016-11-15 17:38:16 +0530658 mbx.reset_stat.rx_stat_mask = 0x3FFF;
659 mbx.reset_stat.tx_stat_mask = 0x1F;
Jerin Jacob3458c402016-08-12 16:51:39 +0530660 mbx.reset_stat.rq_stat_mask = 0xFFFF;
Sunil Goutham964cb692016-11-15 17:38:16 +0530661 mbx.reset_stat.sq_stat_mask = 0xFFFF;
Jerin Jacob3458c402016-08-12 16:51:39 +0530662 nicvf_send_msg_to_pf(nic, &mbx);
663}
664
Sunil Goutham4863dea2015-05-26 19:20:15 -0700665/* Configures receive queue */
666static void nicvf_rcv_queue_config(struct nicvf *nic, struct queue_set *qs,
667 int qidx, bool enable)
668{
669 union nic_mbx mbx = {};
670 struct rcv_queue *rq;
671 struct rq_cfg rq_cfg;
672
673 rq = &qs->rq[qidx];
674 rq->enable = enable;
675
676 /* Disable receive queue */
677 nicvf_queue_reg_write(nic, NIC_QSET_RQ_0_7_CFG, qidx, 0);
678
679 if (!rq->enable) {
680 nicvf_reclaim_rcv_queue(nic, qs, qidx);
681 return;
682 }
683
684 rq->cq_qs = qs->vnic_id;
685 rq->cq_idx = qidx;
686 rq->start_rbdr_qs = qs->vnic_id;
687 rq->start_qs_rbdr_idx = qs->rbdr_cnt - 1;
688 rq->cont_rbdr_qs = qs->vnic_id;
689 rq->cont_qs_rbdr_idx = qs->rbdr_cnt - 1;
690 /* all writes of RBDR data to be loaded into L2 Cache as well*/
691 rq->caching = 1;
692
693 /* Send a mailbox msg to PF to config RQ */
694 mbx.rq.msg = NIC_MBOX_MSG_RQ_CFG;
695 mbx.rq.qs_num = qs->vnic_id;
696 mbx.rq.rq_num = qidx;
697 mbx.rq.cfg = (rq->caching << 26) | (rq->cq_qs << 19) |
698 (rq->cq_idx << 16) | (rq->cont_rbdr_qs << 9) |
699 (rq->cont_qs_rbdr_idx << 8) |
700 (rq->start_rbdr_qs << 1) | (rq->start_qs_rbdr_idx);
701 nicvf_send_msg_to_pf(nic, &mbx);
702
703 mbx.rq.msg = NIC_MBOX_MSG_RQ_BP_CFG;
Sunil Gouthamd5b2d7a2016-11-24 14:48:02 +0530704 mbx.rq.cfg = BIT_ULL(63) | BIT_ULL(62) |
705 (RQ_PASS_RBDR_LVL << 16) | (RQ_PASS_CQ_LVL << 8) |
706 (qs->vnic_id << 0);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700707 nicvf_send_msg_to_pf(nic, &mbx);
708
709 /* RQ drop config
710 * Enable CQ drop to reserve sufficient CQEs for all tx packets
711 */
712 mbx.rq.msg = NIC_MBOX_MSG_RQ_DROP_CFG;
Sunil Gouthamd5b2d7a2016-11-24 14:48:02 +0530713 mbx.rq.cfg = BIT_ULL(63) | BIT_ULL(62) |
714 (RQ_PASS_RBDR_LVL << 40) | (RQ_DROP_RBDR_LVL << 32) |
715 (RQ_PASS_CQ_LVL << 16) | (RQ_DROP_CQ_LVL << 8);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700716 nicvf_send_msg_to_pf(nic, &mbx);
717
Sunil Gouthamcadcf952016-11-15 17:37:54 +0530718 if (!nic->sqs_mode && (qidx == 0)) {
Thanneeru Srinivasulu36fa35d2017-03-07 18:09:11 +0530719 /* Enable checking L3/L4 length and TCP/UDP checksums
720 * Also allow IPv6 pkts with zero UDP checksum.
721 */
Sunil Gouthamcadcf952016-11-15 17:37:54 +0530722 nicvf_queue_reg_write(nic, NIC_QSET_RQ_GEN_CFG, 0,
Thanneeru Srinivasulu36fa35d2017-03-07 18:09:11 +0530723 (BIT(24) | BIT(23) | BIT(21) | BIT(20)));
Sunil Gouthamaa2e2592015-08-30 12:29:13 +0300724 nicvf_config_vlan_stripping(nic, nic->netdev->features);
Sunil Gouthamcadcf952016-11-15 17:37:54 +0530725 }
Sunil Goutham4863dea2015-05-26 19:20:15 -0700726
727 /* Enable Receive queue */
xypron.glpk@gmx.de161de2c2016-05-09 00:46:18 +0200728 memset(&rq_cfg, 0, sizeof(struct rq_cfg));
Sunil Goutham4863dea2015-05-26 19:20:15 -0700729 rq_cfg.ena = 1;
730 rq_cfg.tcp_ena = 0;
731 nicvf_queue_reg_write(nic, NIC_QSET_RQ_0_7_CFG, qidx, *(u64 *)&rq_cfg);
732}
733
734/* Configures completion queue */
735void nicvf_cmp_queue_config(struct nicvf *nic, struct queue_set *qs,
736 int qidx, bool enable)
737{
738 struct cmp_queue *cq;
739 struct cq_cfg cq_cfg;
740
741 cq = &qs->cq[qidx];
742 cq->enable = enable;
743
744 if (!cq->enable) {
745 nicvf_reclaim_cmp_queue(nic, qs, qidx);
746 return;
747 }
748
749 /* Reset completion queue */
750 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_CFG, qidx, NICVF_CQ_RESET);
751
752 if (!cq->enable)
753 return;
754
755 spin_lock_init(&cq->lock);
756 /* Set completion queue base address */
757 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_BASE,
758 qidx, (u64)(cq->dmem.phys_base));
759
760 /* Enable Completion queue */
xypron.glpk@gmx.de161de2c2016-05-09 00:46:18 +0200761 memset(&cq_cfg, 0, sizeof(struct cq_cfg));
Sunil Goutham4863dea2015-05-26 19:20:15 -0700762 cq_cfg.ena = 1;
763 cq_cfg.reset = 0;
764 cq_cfg.caching = 0;
Sunil Gouthamfff4ffd2017-01-25 17:36:23 +0530765 cq_cfg.qsize = ilog2(qs->cq_len >> 10);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700766 cq_cfg.avg_con = 0;
767 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_CFG, qidx, *(u64 *)&cq_cfg);
768
769 /* Set threshold value for interrupt generation */
770 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_THRESH, qidx, cq->thresh);
771 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_CFG2,
Sunil Goutham006394a2015-12-02 15:36:15 +0530772 qidx, CMP_QUEUE_TIMER_THRESH);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700773}
774
775/* Configures transmit queue */
776static void nicvf_snd_queue_config(struct nicvf *nic, struct queue_set *qs,
777 int qidx, bool enable)
778{
779 union nic_mbx mbx = {};
780 struct snd_queue *sq;
781 struct sq_cfg sq_cfg;
782
783 sq = &qs->sq[qidx];
784 sq->enable = enable;
785
786 if (!sq->enable) {
787 nicvf_reclaim_snd_queue(nic, qs, qidx);
788 return;
789 }
790
791 /* Reset send queue */
792 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_CFG, qidx, NICVF_SQ_RESET);
793
794 sq->cq_qs = qs->vnic_id;
795 sq->cq_idx = qidx;
796
797 /* Send a mailbox msg to PF to config SQ */
798 mbx.sq.msg = NIC_MBOX_MSG_SQ_CFG;
799 mbx.sq.qs_num = qs->vnic_id;
800 mbx.sq.sq_num = qidx;
Sunil Goutham92dc8762015-08-30 12:29:15 +0300801 mbx.sq.sqs_mode = nic->sqs_mode;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700802 mbx.sq.cfg = (sq->cq_qs << 3) | sq->cq_idx;
803 nicvf_send_msg_to_pf(nic, &mbx);
804
805 /* Set queue base address */
806 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_BASE,
807 qidx, (u64)(sq->dmem.phys_base));
808
809 /* Enable send queue & set queue size */
xypron.glpk@gmx.de161de2c2016-05-09 00:46:18 +0200810 memset(&sq_cfg, 0, sizeof(struct sq_cfg));
Sunil Goutham4863dea2015-05-26 19:20:15 -0700811 sq_cfg.ena = 1;
812 sq_cfg.reset = 0;
813 sq_cfg.ldwb = 0;
Sunil Gouthamfff4ffd2017-01-25 17:36:23 +0530814 sq_cfg.qsize = ilog2(qs->sq_len >> 10);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700815 sq_cfg.tstmp_bgx_intf = 0;
Sunil Gouthamfff4ffd2017-01-25 17:36:23 +0530816 /* CQ's level at which HW will stop processing SQEs to avoid
817 * transmitting a pkt with no space in CQ to post CQE_TX.
818 */
819 sq_cfg.cq_limit = (CMP_QUEUE_PIPELINE_RSVD * 256) / qs->cq_len;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700820 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_CFG, qidx, *(u64 *)&sq_cfg);
821
822 /* Set threshold value for interrupt generation */
823 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_THRESH, qidx, sq->thresh);
824
825 /* Set queue:cpu affinity for better load distribution */
826 if (cpu_online(qidx)) {
827 cpumask_set_cpu(qidx, &sq->affinity_mask);
828 netif_set_xps_queue(nic->netdev,
829 &sq->affinity_mask, qidx);
830 }
831}
832
833/* Configures receive buffer descriptor ring */
834static void nicvf_rbdr_config(struct nicvf *nic, struct queue_set *qs,
835 int qidx, bool enable)
836{
837 struct rbdr *rbdr;
838 struct rbdr_cfg rbdr_cfg;
839
840 rbdr = &qs->rbdr[qidx];
841 nicvf_reclaim_rbdr(nic, rbdr, qidx);
842 if (!enable)
843 return;
844
845 /* Set descriptor base address */
846 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_BASE,
847 qidx, (u64)(rbdr->dmem.phys_base));
848
849 /* Enable RBDR & set queue size */
850 /* Buffer size should be in multiples of 128 bytes */
xypron.glpk@gmx.de161de2c2016-05-09 00:46:18 +0200851 memset(&rbdr_cfg, 0, sizeof(struct rbdr_cfg));
Sunil Goutham4863dea2015-05-26 19:20:15 -0700852 rbdr_cfg.ena = 1;
853 rbdr_cfg.reset = 0;
854 rbdr_cfg.ldwb = 0;
855 rbdr_cfg.qsize = RBDR_SIZE;
856 rbdr_cfg.avg_con = 0;
857 rbdr_cfg.lines = rbdr->dma_size / 128;
858 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_CFG,
859 qidx, *(u64 *)&rbdr_cfg);
860
861 /* Notify HW */
862 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_DOOR,
863 qidx, qs->rbdr_len - 1);
864
865 /* Set threshold value for interrupt generation */
866 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_THRESH,
867 qidx, rbdr->thresh - 1);
868}
869
870/* Requests PF to assign and enable Qset */
871void nicvf_qset_config(struct nicvf *nic, bool enable)
872{
873 union nic_mbx mbx = {};
874 struct queue_set *qs = nic->qs;
875 struct qs_cfg *qs_cfg;
876
877 if (!qs) {
878 netdev_warn(nic->netdev,
879 "Qset is still not allocated, don't init queues\n");
880 return;
881 }
882
883 qs->enable = enable;
884 qs->vnic_id = nic->vf_id;
885
886 /* Send a mailbox msg to PF to config Qset */
887 mbx.qs.msg = NIC_MBOX_MSG_QS_CFG;
888 mbx.qs.num = qs->vnic_id;
Sunil Goutham92dc8762015-08-30 12:29:15 +0300889 mbx.qs.sqs_count = nic->sqs_count;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700890
891 mbx.qs.cfg = 0;
892 qs_cfg = (struct qs_cfg *)&mbx.qs.cfg;
893 if (qs->enable) {
894 qs_cfg->ena = 1;
895#ifdef __BIG_ENDIAN
896 qs_cfg->be = 1;
897#endif
898 qs_cfg->vnic = qs->vnic_id;
899 }
900 nicvf_send_msg_to_pf(nic, &mbx);
901}
902
903static void nicvf_free_resources(struct nicvf *nic)
904{
905 int qidx;
906 struct queue_set *qs = nic->qs;
907
908 /* Free receive buffer descriptor ring */
909 for (qidx = 0; qidx < qs->rbdr_cnt; qidx++)
910 nicvf_free_rbdr(nic, &qs->rbdr[qidx]);
911
912 /* Free completion queue */
913 for (qidx = 0; qidx < qs->cq_cnt; qidx++)
914 nicvf_free_cmp_queue(nic, &qs->cq[qidx]);
915
916 /* Free send queue */
917 for (qidx = 0; qidx < qs->sq_cnt; qidx++)
918 nicvf_free_snd_queue(nic, &qs->sq[qidx]);
919}
920
921static int nicvf_alloc_resources(struct nicvf *nic)
922{
923 int qidx;
924 struct queue_set *qs = nic->qs;
925
926 /* Alloc receive buffer descriptor ring */
927 for (qidx = 0; qidx < qs->rbdr_cnt; qidx++) {
928 if (nicvf_init_rbdr(nic, &qs->rbdr[qidx], qs->rbdr_len,
929 DMA_BUFFER_LEN))
930 goto alloc_fail;
931 }
932
933 /* Alloc send queue */
934 for (qidx = 0; qidx < qs->sq_cnt; qidx++) {
935 if (nicvf_init_snd_queue(nic, &qs->sq[qidx], qs->sq_len))
936 goto alloc_fail;
937 }
938
939 /* Alloc completion queue */
940 for (qidx = 0; qidx < qs->cq_cnt; qidx++) {
941 if (nicvf_init_cmp_queue(nic, &qs->cq[qidx], qs->cq_len))
942 goto alloc_fail;
943 }
944
945 return 0;
946alloc_fail:
947 nicvf_free_resources(nic);
948 return -ENOMEM;
949}
950
951int nicvf_set_qset_resources(struct nicvf *nic)
952{
953 struct queue_set *qs;
954
955 qs = devm_kzalloc(&nic->pdev->dev, sizeof(*qs), GFP_KERNEL);
956 if (!qs)
957 return -ENOMEM;
958 nic->qs = qs;
959
960 /* Set count of each queue */
Sunil Goutham3a397eb2016-08-12 16:51:27 +0530961 qs->rbdr_cnt = DEFAULT_RBDR_CNT;
962 qs->rq_cnt = min_t(u8, MAX_RCV_QUEUES_PER_QS, num_online_cpus());
963 qs->sq_cnt = min_t(u8, MAX_SND_QUEUES_PER_QS, num_online_cpus());
964 qs->cq_cnt = max_t(u8, qs->rq_cnt, qs->sq_cnt);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700965
966 /* Set queue lengths */
967 qs->rbdr_len = RCV_BUF_COUNT;
968 qs->sq_len = SND_QUEUE_LEN;
969 qs->cq_len = CMP_QUEUE_LEN;
Sunil Goutham92dc8762015-08-30 12:29:15 +0300970
971 nic->rx_queues = qs->rq_cnt;
972 nic->tx_queues = qs->sq_cnt;
Sunil Goutham05c773f2017-05-02 18:36:54 +0530973 nic->xdp_tx_queues = 0;
Sunil Goutham92dc8762015-08-30 12:29:15 +0300974
Sunil Goutham4863dea2015-05-26 19:20:15 -0700975 return 0;
976}
977
978int nicvf_config_data_transfer(struct nicvf *nic, bool enable)
979{
980 bool disable = false;
981 struct queue_set *qs = nic->qs;
Sunil Gouthamfff4ffd2017-01-25 17:36:23 +0530982 struct queue_set *pqs = nic->pnicvf->qs;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700983 int qidx;
984
985 if (!qs)
986 return 0;
987
Sunil Gouthamfff4ffd2017-01-25 17:36:23 +0530988 /* Take primary VF's queue lengths.
989 * This is needed to take queue lengths set from ethtool
990 * into consideration.
991 */
992 if (nic->sqs_mode && pqs) {
993 qs->cq_len = pqs->cq_len;
994 qs->sq_len = pqs->sq_len;
995 }
996
Sunil Goutham4863dea2015-05-26 19:20:15 -0700997 if (enable) {
998 if (nicvf_alloc_resources(nic))
999 return -ENOMEM;
1000
1001 for (qidx = 0; qidx < qs->sq_cnt; qidx++)
1002 nicvf_snd_queue_config(nic, qs, qidx, enable);
1003 for (qidx = 0; qidx < qs->cq_cnt; qidx++)
1004 nicvf_cmp_queue_config(nic, qs, qidx, enable);
1005 for (qidx = 0; qidx < qs->rbdr_cnt; qidx++)
1006 nicvf_rbdr_config(nic, qs, qidx, enable);
1007 for (qidx = 0; qidx < qs->rq_cnt; qidx++)
1008 nicvf_rcv_queue_config(nic, qs, qidx, enable);
1009 } else {
1010 for (qidx = 0; qidx < qs->rq_cnt; qidx++)
1011 nicvf_rcv_queue_config(nic, qs, qidx, disable);
1012 for (qidx = 0; qidx < qs->rbdr_cnt; qidx++)
1013 nicvf_rbdr_config(nic, qs, qidx, disable);
1014 for (qidx = 0; qidx < qs->sq_cnt; qidx++)
1015 nicvf_snd_queue_config(nic, qs, qidx, disable);
1016 for (qidx = 0; qidx < qs->cq_cnt; qidx++)
1017 nicvf_cmp_queue_config(nic, qs, qidx, disable);
1018
1019 nicvf_free_resources(nic);
1020 }
1021
Jerin Jacob3458c402016-08-12 16:51:39 +05301022 /* Reset RXQ's stats.
1023 * SQ's stats will get reset automatically once SQ is reset.
1024 */
1025 nicvf_reset_rcv_queue_stats(nic);
1026
Sunil Goutham4863dea2015-05-26 19:20:15 -07001027 return 0;
1028}
1029
1030/* Get a free desc from SQ
1031 * returns descriptor ponter & descriptor number
1032 */
1033static inline int nicvf_get_sq_desc(struct snd_queue *sq, int desc_cnt)
1034{
1035 int qentry;
1036
1037 qentry = sq->tail;
1038 atomic_sub(desc_cnt, &sq->free_cnt);
1039 sq->tail += desc_cnt;
1040 sq->tail &= (sq->dmem.q_len - 1);
1041
1042 return qentry;
1043}
1044
Sunil Goutham83abb7d2017-03-07 18:09:08 +05301045/* Rollback to previous tail pointer when descriptors not used */
1046static inline void nicvf_rollback_sq_desc(struct snd_queue *sq,
1047 int qentry, int desc_cnt)
1048{
1049 sq->tail = qentry;
1050 atomic_add(desc_cnt, &sq->free_cnt);
1051}
1052
Sunil Goutham4863dea2015-05-26 19:20:15 -07001053/* Free descriptor back to SQ for future use */
1054void nicvf_put_sq_desc(struct snd_queue *sq, int desc_cnt)
1055{
1056 atomic_add(desc_cnt, &sq->free_cnt);
1057 sq->head += desc_cnt;
1058 sq->head &= (sq->dmem.q_len - 1);
1059}
1060
1061static inline int nicvf_get_nxt_sqentry(struct snd_queue *sq, int qentry)
1062{
1063 qentry++;
1064 qentry &= (sq->dmem.q_len - 1);
1065 return qentry;
1066}
1067
1068void nicvf_sq_enable(struct nicvf *nic, struct snd_queue *sq, int qidx)
1069{
1070 u64 sq_cfg;
1071
1072 sq_cfg = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_CFG, qidx);
1073 sq_cfg |= NICVF_SQ_EN;
1074 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_CFG, qidx, sq_cfg);
1075 /* Ring doorbell so that H/W restarts processing SQEs */
1076 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_DOOR, qidx, 0);
1077}
1078
1079void nicvf_sq_disable(struct nicvf *nic, int qidx)
1080{
1081 u64 sq_cfg;
1082
1083 sq_cfg = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_CFG, qidx);
1084 sq_cfg &= ~NICVF_SQ_EN;
1085 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_CFG, qidx, sq_cfg);
1086}
1087
1088void nicvf_sq_free_used_descs(struct net_device *netdev, struct snd_queue *sq,
1089 int qidx)
1090{
1091 u64 head, tail;
1092 struct sk_buff *skb;
1093 struct nicvf *nic = netdev_priv(netdev);
1094 struct sq_hdr_subdesc *hdr;
1095
1096 head = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_HEAD, qidx) >> 4;
1097 tail = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_TAIL, qidx) >> 4;
1098 while (sq->head != head) {
1099 hdr = (struct sq_hdr_subdesc *)GET_SQ_DESC(sq, sq->head);
1100 if (hdr->subdesc_type != SQ_DESC_TYPE_HEADER) {
1101 nicvf_put_sq_desc(sq, 1);
1102 continue;
1103 }
1104 skb = (struct sk_buff *)sq->skbuff[sq->head];
Sunil Goutham143ceb02015-07-29 16:49:37 +03001105 if (skb)
1106 dev_kfree_skb_any(skb);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001107 atomic64_add(1, (atomic64_t *)&netdev->stats.tx_packets);
1108 atomic64_add(hdr->tot_len,
1109 (atomic64_t *)&netdev->stats.tx_bytes);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001110 nicvf_put_sq_desc(sq, hdr->subdesc_cnt + 1);
1111 }
1112}
1113
1114/* Calculate no of SQ subdescriptors needed to transmit all
1115 * segments of this TSO packet.
1116 * Taken from 'Tilera network driver' with a minor modification.
1117 */
1118static int nicvf_tso_count_subdescs(struct sk_buff *skb)
1119{
1120 struct skb_shared_info *sh = skb_shinfo(skb);
1121 unsigned int sh_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1122 unsigned int data_len = skb->len - sh_len;
1123 unsigned int p_len = sh->gso_size;
1124 long f_id = -1; /* id of the current fragment */
1125 long f_size = skb_headlen(skb) - sh_len; /* current fragment size */
1126 long f_used = 0; /* bytes used from the current fragment */
1127 long n; /* size of the current piece of payload */
1128 int num_edescs = 0;
1129 int segment;
1130
1131 for (segment = 0; segment < sh->gso_segs; segment++) {
1132 unsigned int p_used = 0;
1133
1134 /* One edesc for header and for each piece of the payload. */
1135 for (num_edescs++; p_used < p_len; num_edescs++) {
1136 /* Advance as needed. */
1137 while (f_used >= f_size) {
1138 f_id++;
1139 f_size = skb_frag_size(&sh->frags[f_id]);
1140 f_used = 0;
1141 }
1142
1143 /* Use bytes from the current fragment. */
1144 n = p_len - p_used;
1145 if (n > f_size - f_used)
1146 n = f_size - f_used;
1147 f_used += n;
1148 p_used += n;
1149 }
1150
1151 /* The last segment may be less than gso_size. */
1152 data_len -= p_len;
1153 if (data_len < p_len)
1154 p_len = data_len;
1155 }
1156
1157 /* '+ gso_segs' for SQ_HDR_SUDESCs for each segment */
1158 return num_edescs + sh->gso_segs;
1159}
1160
Sunil Goutham7ceb8a12016-08-30 11:36:27 +05301161#define POST_CQE_DESC_COUNT 2
1162
Sunil Goutham4863dea2015-05-26 19:20:15 -07001163/* Get the number of SQ descriptors needed to xmit this skb */
1164static int nicvf_sq_subdesc_required(struct nicvf *nic, struct sk_buff *skb)
1165{
1166 int subdesc_cnt = MIN_SQ_DESC_PER_PKT_XMIT;
1167
Sunil Goutham40fb5f82015-12-10 13:25:19 +05301168 if (skb_shinfo(skb)->gso_size && !nic->hw_tso) {
Sunil Goutham4863dea2015-05-26 19:20:15 -07001169 subdesc_cnt = nicvf_tso_count_subdescs(skb);
1170 return subdesc_cnt;
1171 }
1172
Sunil Goutham7ceb8a12016-08-30 11:36:27 +05301173 /* Dummy descriptors to get TSO pkt completion notification */
1174 if (nic->t88 && nic->hw_tso && skb_shinfo(skb)->gso_size)
1175 subdesc_cnt += POST_CQE_DESC_COUNT;
1176
Sunil Goutham4863dea2015-05-26 19:20:15 -07001177 if (skb_shinfo(skb)->nr_frags)
1178 subdesc_cnt += skb_shinfo(skb)->nr_frags;
1179
1180 return subdesc_cnt;
1181}
1182
1183/* Add SQ HEADER subdescriptor.
1184 * First subdescriptor for every send descriptor.
1185 */
1186static inline void
Sunil Goutham40fb5f82015-12-10 13:25:19 +05301187nicvf_sq_add_hdr_subdesc(struct nicvf *nic, struct snd_queue *sq, int qentry,
Sunil Goutham4863dea2015-05-26 19:20:15 -07001188 int subdesc_cnt, struct sk_buff *skb, int len)
1189{
1190 int proto;
1191 struct sq_hdr_subdesc *hdr;
Thanneeru Srinivasulu3a9024f2017-04-06 16:12:26 +05301192 union {
1193 struct iphdr *v4;
1194 struct ipv6hdr *v6;
1195 unsigned char *hdr;
1196 } ip;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001197
Thanneeru Srinivasulu3a9024f2017-04-06 16:12:26 +05301198 ip.hdr = skb_network_header(skb);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001199 hdr = (struct sq_hdr_subdesc *)GET_SQ_DESC(sq, qentry);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001200 memset(hdr, 0, SND_QUEUE_DESC_SIZE);
1201 hdr->subdesc_type = SQ_DESC_TYPE_HEADER;
Sunil Goutham7ceb8a12016-08-30 11:36:27 +05301202
1203 if (nic->t88 && nic->hw_tso && skb_shinfo(skb)->gso_size) {
1204 /* post_cqe = 0, to avoid HW posting a CQE for every TSO
1205 * segment transmitted on 88xx.
1206 */
1207 hdr->subdesc_cnt = subdesc_cnt - POST_CQE_DESC_COUNT;
1208 } else {
1209 sq->skbuff[qentry] = (u64)skb;
1210 /* Enable notification via CQE after processing SQE */
1211 hdr->post_cqe = 1;
1212 /* No of subdescriptors following this */
1213 hdr->subdesc_cnt = subdesc_cnt;
1214 }
Sunil Goutham4863dea2015-05-26 19:20:15 -07001215 hdr->tot_len = len;
1216
1217 /* Offload checksum calculation to HW */
1218 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Sunil Goutham4863dea2015-05-26 19:20:15 -07001219 hdr->csum_l3 = 1; /* Enable IP csum calculation */
1220 hdr->l3_offset = skb_network_offset(skb);
1221 hdr->l4_offset = skb_transport_offset(skb);
1222
Thanneeru Srinivasulu3a9024f2017-04-06 16:12:26 +05301223 proto = (ip.v4->version == 4) ? ip.v4->protocol :
1224 ip.v6->nexthdr;
1225
Sunil Goutham4863dea2015-05-26 19:20:15 -07001226 switch (proto) {
1227 case IPPROTO_TCP:
1228 hdr->csum_l4 = SEND_L4_CSUM_TCP;
1229 break;
1230 case IPPROTO_UDP:
1231 hdr->csum_l4 = SEND_L4_CSUM_UDP;
1232 break;
1233 case IPPROTO_SCTP:
1234 hdr->csum_l4 = SEND_L4_CSUM_SCTP;
1235 break;
1236 }
1237 }
Sunil Goutham40fb5f82015-12-10 13:25:19 +05301238
1239 if (nic->hw_tso && skb_shinfo(skb)->gso_size) {
1240 hdr->tso = 1;
1241 hdr->tso_start = skb_transport_offset(skb) + tcp_hdrlen(skb);
1242 hdr->tso_max_paysize = skb_shinfo(skb)->gso_size;
1243 /* For non-tunneled pkts, point this to L2 ethertype */
1244 hdr->inner_l3_offset = skb_network_offset(skb) - 2;
Sunil Goutham964cb692016-11-15 17:38:16 +05301245 this_cpu_inc(nic->pnicvf->drv_stats->tx_tso);
Sunil Goutham40fb5f82015-12-10 13:25:19 +05301246 }
Sunil Goutham4863dea2015-05-26 19:20:15 -07001247}
1248
1249/* SQ GATHER subdescriptor
1250 * Must follow HDR descriptor
1251 */
1252static inline void nicvf_sq_add_gather_subdesc(struct snd_queue *sq, int qentry,
1253 int size, u64 data)
1254{
1255 struct sq_gather_subdesc *gather;
1256
1257 qentry &= (sq->dmem.q_len - 1);
1258 gather = (struct sq_gather_subdesc *)GET_SQ_DESC(sq, qentry);
1259
1260 memset(gather, 0, SND_QUEUE_DESC_SIZE);
1261 gather->subdesc_type = SQ_DESC_TYPE_GATHER;
Sunil Goutham4b561c12015-07-29 16:49:36 +03001262 gather->ld_type = NIC_SEND_LD_TYPE_E_LDD;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001263 gather->size = size;
1264 gather->addr = data;
1265}
1266
Sunil Goutham7ceb8a12016-08-30 11:36:27 +05301267/* Add HDR + IMMEDIATE subdescriptors right after descriptors of a TSO
1268 * packet so that a CQE is posted as a notifation for transmission of
1269 * TSO packet.
1270 */
1271static inline void nicvf_sq_add_cqe_subdesc(struct snd_queue *sq, int qentry,
1272 int tso_sqe, struct sk_buff *skb)
1273{
1274 struct sq_imm_subdesc *imm;
1275 struct sq_hdr_subdesc *hdr;
1276
1277 sq->skbuff[qentry] = (u64)skb;
1278
1279 hdr = (struct sq_hdr_subdesc *)GET_SQ_DESC(sq, qentry);
1280 memset(hdr, 0, SND_QUEUE_DESC_SIZE);
1281 hdr->subdesc_type = SQ_DESC_TYPE_HEADER;
1282 /* Enable notification via CQE after processing SQE */
1283 hdr->post_cqe = 1;
1284 /* There is no packet to transmit here */
1285 hdr->dont_send = 1;
1286 hdr->subdesc_cnt = POST_CQE_DESC_COUNT - 1;
1287 hdr->tot_len = 1;
1288 /* Actual TSO header SQE index, needed for cleanup */
1289 hdr->rsvd2 = tso_sqe;
1290
1291 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1292 imm = (struct sq_imm_subdesc *)GET_SQ_DESC(sq, qentry);
1293 memset(imm, 0, SND_QUEUE_DESC_SIZE);
1294 imm->subdesc_type = SQ_DESC_TYPE_IMMEDIATE;
1295 imm->len = 1;
1296}
1297
Sunil Goutham2c204c22016-09-23 14:42:28 +05301298static inline void nicvf_sq_doorbell(struct nicvf *nic, struct sk_buff *skb,
1299 int sq_num, int desc_cnt)
1300{
1301 struct netdev_queue *txq;
1302
1303 txq = netdev_get_tx_queue(nic->pnicvf->netdev,
1304 skb_get_queue_mapping(skb));
1305
1306 netdev_tx_sent_queue(txq, skb->len);
1307
1308 /* make sure all memory stores are done before ringing doorbell */
1309 smp_wmb();
1310
1311 /* Inform HW to xmit all TSO segments */
1312 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_DOOR,
1313 sq_num, desc_cnt);
1314}
1315
Sunil Goutham4863dea2015-05-26 19:20:15 -07001316/* Segment a TSO packet into 'gso_size' segments and append
1317 * them to SQ for transfer
1318 */
1319static int nicvf_sq_append_tso(struct nicvf *nic, struct snd_queue *sq,
Sunil Goutham92dc8762015-08-30 12:29:15 +03001320 int sq_num, int qentry, struct sk_buff *skb)
Sunil Goutham4863dea2015-05-26 19:20:15 -07001321{
1322 struct tso_t tso;
1323 int seg_subdescs = 0, desc_cnt = 0;
1324 int seg_len, total_len, data_left;
1325 int hdr_qentry = qentry;
1326 int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1327
1328 tso_start(skb, &tso);
1329 total_len = skb->len - hdr_len;
1330 while (total_len > 0) {
1331 char *hdr;
1332
1333 /* Save Qentry for adding HDR_SUBDESC at the end */
1334 hdr_qentry = qentry;
1335
1336 data_left = min_t(int, skb_shinfo(skb)->gso_size, total_len);
1337 total_len -= data_left;
1338
1339 /* Add segment's header */
1340 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1341 hdr = sq->tso_hdrs + qentry * TSO_HEADER_SIZE;
1342 tso_build_hdr(skb, hdr, &tso, data_left, total_len == 0);
1343 nicvf_sq_add_gather_subdesc(sq, qentry, hdr_len,
1344 sq->tso_hdrs_phys +
1345 qentry * TSO_HEADER_SIZE);
1346 /* HDR_SUDESC + GATHER */
1347 seg_subdescs = 2;
1348 seg_len = hdr_len;
1349
1350 /* Add segment's payload fragments */
1351 while (data_left > 0) {
1352 int size;
1353
1354 size = min_t(int, tso.size, data_left);
1355
1356 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1357 nicvf_sq_add_gather_subdesc(sq, qentry, size,
1358 virt_to_phys(tso.data));
1359 seg_subdescs++;
1360 seg_len += size;
1361
1362 data_left -= size;
1363 tso_build_data(skb, &tso, size);
1364 }
Sunil Goutham40fb5f82015-12-10 13:25:19 +05301365 nicvf_sq_add_hdr_subdesc(nic, sq, hdr_qentry,
Sunil Goutham4863dea2015-05-26 19:20:15 -07001366 seg_subdescs - 1, skb, seg_len);
Sunil Goutham143ceb02015-07-29 16:49:37 +03001367 sq->skbuff[hdr_qentry] = (u64)NULL;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001368 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1369
1370 desc_cnt += seg_subdescs;
1371 }
1372 /* Save SKB in the last segment for freeing */
1373 sq->skbuff[hdr_qentry] = (u64)skb;
1374
Sunil Goutham2c204c22016-09-23 14:42:28 +05301375 nicvf_sq_doorbell(nic, skb, sq_num, desc_cnt);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001376
Sunil Goutham964cb692016-11-15 17:38:16 +05301377 this_cpu_inc(nic->pnicvf->drv_stats->tx_tso);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001378 return 1;
1379}
1380
1381/* Append an skb to a SQ for packet transfer. */
Sunil Gouthambd3ad7d2016-12-01 18:24:28 +05301382int nicvf_sq_append_skb(struct nicvf *nic, struct snd_queue *sq,
1383 struct sk_buff *skb, u8 sq_num)
Sunil Goutham4863dea2015-05-26 19:20:15 -07001384{
1385 int i, size;
Sunil Goutham83abb7d2017-03-07 18:09:08 +05301386 int subdesc_cnt, hdr_sqe = 0;
Sunil Gouthambd3ad7d2016-12-01 18:24:28 +05301387 int qentry;
Sunil Goutham83abb7d2017-03-07 18:09:08 +05301388 u64 dma_addr;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001389
1390 subdesc_cnt = nicvf_sq_subdesc_required(nic, skb);
1391 if (subdesc_cnt > atomic_read(&sq->free_cnt))
1392 goto append_fail;
1393
1394 qentry = nicvf_get_sq_desc(sq, subdesc_cnt);
1395
1396 /* Check if its a TSO packet */
Sunil Goutham40fb5f82015-12-10 13:25:19 +05301397 if (skb_shinfo(skb)->gso_size && !nic->hw_tso)
Sunil Goutham92dc8762015-08-30 12:29:15 +03001398 return nicvf_sq_append_tso(nic, sq, sq_num, qentry, skb);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001399
1400 /* Add SQ header subdesc */
Sunil Goutham40fb5f82015-12-10 13:25:19 +05301401 nicvf_sq_add_hdr_subdesc(nic, sq, qentry, subdesc_cnt - 1,
1402 skb, skb->len);
Sunil Goutham83abb7d2017-03-07 18:09:08 +05301403 hdr_sqe = qentry;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001404
1405 /* Add SQ gather subdescs */
1406 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1407 size = skb_is_nonlinear(skb) ? skb_headlen(skb) : skb->len;
Sunil Goutham83abb7d2017-03-07 18:09:08 +05301408 /* HW will ensure data coherency, CPU sync not required */
1409 dma_addr = dma_map_page_attrs(&nic->pdev->dev, virt_to_page(skb->data),
1410 offset_in_page(skb->data), size,
1411 DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
1412 if (dma_mapping_error(&nic->pdev->dev, dma_addr)) {
1413 nicvf_rollback_sq_desc(sq, qentry, subdesc_cnt);
1414 return 0;
1415 }
1416
1417 nicvf_sq_add_gather_subdesc(sq, qentry, size, dma_addr);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001418
1419 /* Check for scattered buffer */
1420 if (!skb_is_nonlinear(skb))
1421 goto doorbell;
1422
1423 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1424 const struct skb_frag_struct *frag;
1425
1426 frag = &skb_shinfo(skb)->frags[i];
1427
1428 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1429 size = skb_frag_size(frag);
Sunil Goutham83abb7d2017-03-07 18:09:08 +05301430 dma_addr = dma_map_page_attrs(&nic->pdev->dev,
1431 skb_frag_page(frag),
1432 frag->page_offset, size,
1433 DMA_TO_DEVICE,
1434 DMA_ATTR_SKIP_CPU_SYNC);
1435 if (dma_mapping_error(&nic->pdev->dev, dma_addr)) {
1436 /* Free entire chain of mapped buffers
1437 * here 'i' = frags mapped + above mapped skb->data
1438 */
1439 nicvf_unmap_sndq_buffers(nic, sq, hdr_sqe, i);
1440 nicvf_rollback_sq_desc(sq, qentry, subdesc_cnt);
1441 return 0;
1442 }
1443 nicvf_sq_add_gather_subdesc(sq, qentry, size, dma_addr);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001444 }
1445
1446doorbell:
Sunil Goutham7ceb8a12016-08-30 11:36:27 +05301447 if (nic->t88 && skb_shinfo(skb)->gso_size) {
1448 qentry = nicvf_get_nxt_sqentry(sq, qentry);
Sunil Goutham83abb7d2017-03-07 18:09:08 +05301449 nicvf_sq_add_cqe_subdesc(sq, qentry, hdr_sqe, skb);
Sunil Goutham7ceb8a12016-08-30 11:36:27 +05301450 }
1451
Sunil Goutham2c204c22016-09-23 14:42:28 +05301452 nicvf_sq_doorbell(nic, skb, sq_num, subdesc_cnt);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001453
Sunil Goutham4863dea2015-05-26 19:20:15 -07001454 return 1;
1455
1456append_fail:
Sunil Goutham92dc8762015-08-30 12:29:15 +03001457 /* Use original PCI dev for debug log */
1458 nic = nic->pnicvf;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001459 netdev_dbg(nic->netdev, "Not enough SQ descriptors to xmit pkt\n");
1460 return 0;
1461}
1462
1463static inline unsigned frag_num(unsigned i)
1464{
1465#ifdef __BIG_ENDIAN
1466 return (i & ~3) + 3 - (i & 3);
1467#else
1468 return i;
1469#endif
1470}
1471
Sunil Gouthamc56d91c2017-05-02 18:36:55 +05301472static void nicvf_unmap_rcv_buffer(struct nicvf *nic, u64 dma_addr,
1473 u64 buf_addr, bool xdp)
1474{
1475 struct page *page = NULL;
1476 int len = RCV_FRAG_LEN;
1477
1478 if (xdp) {
1479 page = virt_to_page(phys_to_virt(buf_addr));
1480 /* Check if it's a recycled page, if not
1481 * unmap the DMA mapping.
1482 *
1483 * Recycled page holds an extra reference.
1484 */
1485 if (page_ref_count(page) != 1)
1486 return;
1487 /* Receive buffers in XDP mode are mapped from page start */
1488 dma_addr &= PAGE_MASK;
1489 }
1490 dma_unmap_page_attrs(&nic->pdev->dev, dma_addr, len,
1491 DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
1492}
1493
Sunil Goutham4863dea2015-05-26 19:20:15 -07001494/* Returns SKB for a received packet */
Sunil Gouthamc56d91c2017-05-02 18:36:55 +05301495struct sk_buff *nicvf_get_rcv_skb(struct nicvf *nic,
1496 struct cqe_rx_t *cqe_rx, bool xdp)
Sunil Goutham4863dea2015-05-26 19:20:15 -07001497{
1498 int frag;
1499 int payload_len = 0;
1500 struct sk_buff *skb = NULL;
Sunil Gouthama8671ac2016-08-12 16:51:37 +05301501 struct page *page;
1502 int offset;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001503 u16 *rb_lens = NULL;
1504 u64 *rb_ptrs = NULL;
Sunil Goutham83abb7d2017-03-07 18:09:08 +05301505 u64 phys_addr;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001506
1507 rb_lens = (void *)cqe_rx + (3 * sizeof(u64));
Sunil Goutham02a72bd2016-08-12 16:51:28 +05301508 /* Except 88xx pass1 on all other chips CQE_RX2_S is added to
1509 * CQE_RX at word6, hence buffer pointers move by word
1510 *
1511 * Use existing 'hw_tso' flag which will be set for all chips
1512 * except 88xx pass1 instead of a additional cache line
1513 * access (or miss) by using pci dev's revision.
1514 */
1515 if (!nic->hw_tso)
1516 rb_ptrs = (void *)cqe_rx + (6 * sizeof(u64));
1517 else
1518 rb_ptrs = (void *)cqe_rx + (7 * sizeof(u64));
Sunil Goutham4863dea2015-05-26 19:20:15 -07001519
Sunil Goutham4863dea2015-05-26 19:20:15 -07001520 for (frag = 0; frag < cqe_rx->rb_cnt; frag++) {
1521 payload_len = rb_lens[frag_num(frag)];
Sunil Goutham83abb7d2017-03-07 18:09:08 +05301522 phys_addr = nicvf_iova_to_phys(nic, *rb_ptrs);
1523 if (!phys_addr) {
1524 if (skb)
1525 dev_kfree_skb_any(skb);
1526 return NULL;
1527 }
1528
Sunil Goutham4863dea2015-05-26 19:20:15 -07001529 if (!frag) {
1530 /* First fragment */
Sunil Gouthamc56d91c2017-05-02 18:36:55 +05301531 nicvf_unmap_rcv_buffer(nic,
1532 *rb_ptrs - cqe_rx->align_pad,
1533 phys_addr, xdp);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001534 skb = nicvf_rb_ptr_to_skb(nic,
Sunil Goutham83abb7d2017-03-07 18:09:08 +05301535 phys_addr - cqe_rx->align_pad,
Sunil Goutham4863dea2015-05-26 19:20:15 -07001536 payload_len);
1537 if (!skb)
1538 return NULL;
1539 skb_reserve(skb, cqe_rx->align_pad);
1540 skb_put(skb, payload_len);
1541 } else {
1542 /* Add fragments */
Sunil Gouthamc56d91c2017-05-02 18:36:55 +05301543 nicvf_unmap_rcv_buffer(nic, *rb_ptrs, phys_addr, xdp);
Sunil Goutham83abb7d2017-03-07 18:09:08 +05301544 page = virt_to_page(phys_to_virt(phys_addr));
1545 offset = phys_to_virt(phys_addr) - page_address(page);
Sunil Gouthama8671ac2016-08-12 16:51:37 +05301546 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1547 offset, payload_len, RCV_FRAG_LEN);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001548 }
1549 /* Next buffer pointer */
1550 rb_ptrs++;
1551 }
1552 return skb;
1553}
1554
Yury Norovb45ceb42015-12-07 10:30:32 +05301555static u64 nicvf_int_type_to_mask(int int_type, int q_idx)
Sunil Goutham4863dea2015-05-26 19:20:15 -07001556{
1557 u64 reg_val;
1558
Sunil Goutham4863dea2015-05-26 19:20:15 -07001559 switch (int_type) {
1560 case NICVF_INTR_CQ:
1561 reg_val = ((1ULL << q_idx) << NICVF_INTR_CQ_SHIFT);
1562 break;
1563 case NICVF_INTR_SQ:
1564 reg_val = ((1ULL << q_idx) << NICVF_INTR_SQ_SHIFT);
1565 break;
1566 case NICVF_INTR_RBDR:
1567 reg_val = ((1ULL << q_idx) << NICVF_INTR_RBDR_SHIFT);
1568 break;
1569 case NICVF_INTR_PKT_DROP:
1570 reg_val = (1ULL << NICVF_INTR_PKT_DROP_SHIFT);
1571 break;
1572 case NICVF_INTR_TCP_TIMER:
1573 reg_val = (1ULL << NICVF_INTR_TCP_TIMER_SHIFT);
1574 break;
1575 case NICVF_INTR_MBOX:
1576 reg_val = (1ULL << NICVF_INTR_MBOX_SHIFT);
1577 break;
1578 case NICVF_INTR_QS_ERR:
Yury Norovb45ceb42015-12-07 10:30:32 +05301579 reg_val = (1ULL << NICVF_INTR_QS_ERR_SHIFT);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001580 break;
1581 default:
Yury Norovb45ceb42015-12-07 10:30:32 +05301582 reg_val = 0;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001583 }
1584
Yury Norovb45ceb42015-12-07 10:30:32 +05301585 return reg_val;
1586}
1587
1588/* Enable interrupt */
1589void nicvf_enable_intr(struct nicvf *nic, int int_type, int q_idx)
1590{
1591 u64 mask = nicvf_int_type_to_mask(int_type, q_idx);
1592
1593 if (!mask) {
1594 netdev_dbg(nic->netdev,
1595 "Failed to enable interrupt: unknown type\n");
1596 return;
1597 }
1598 nicvf_reg_write(nic, NIC_VF_ENA_W1S,
1599 nicvf_reg_read(nic, NIC_VF_ENA_W1S) | mask);
1600}
1601
1602/* Disable interrupt */
1603void nicvf_disable_intr(struct nicvf *nic, int int_type, int q_idx)
1604{
1605 u64 mask = nicvf_int_type_to_mask(int_type, q_idx);
1606
1607 if (!mask) {
1608 netdev_dbg(nic->netdev,
1609 "Failed to disable interrupt: unknown type\n");
1610 return;
1611 }
1612
1613 nicvf_reg_write(nic, NIC_VF_ENA_W1C, mask);
1614}
1615
1616/* Clear interrupt */
1617void nicvf_clear_intr(struct nicvf *nic, int int_type, int q_idx)
1618{
1619 u64 mask = nicvf_int_type_to_mask(int_type, q_idx);
1620
1621 if (!mask) {
1622 netdev_dbg(nic->netdev,
1623 "Failed to clear interrupt: unknown type\n");
1624 return;
1625 }
1626
1627 nicvf_reg_write(nic, NIC_VF_INT, mask);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001628}
1629
1630/* Check if interrupt is enabled */
1631int nicvf_is_intr_enabled(struct nicvf *nic, int int_type, int q_idx)
1632{
Yury Norovb45ceb42015-12-07 10:30:32 +05301633 u64 mask = nicvf_int_type_to_mask(int_type, q_idx);
1634 /* If interrupt type is unknown, we treat it disabled. */
1635 if (!mask) {
1636 netdev_dbg(nic->netdev,
Sunil Goutham4863dea2015-05-26 19:20:15 -07001637 "Failed to check interrupt enable: unknown type\n");
Yury Norovb45ceb42015-12-07 10:30:32 +05301638 return 0;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001639 }
1640
Yury Norovb45ceb42015-12-07 10:30:32 +05301641 return mask & nicvf_reg_read(nic, NIC_VF_ENA_W1S);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001642}
1643
1644void nicvf_update_rq_stats(struct nicvf *nic, int rq_idx)
1645{
1646 struct rcv_queue *rq;
1647
1648#define GET_RQ_STATS(reg) \
1649 nicvf_reg_read(nic, NIC_QSET_RQ_0_7_STAT_0_1 |\
1650 (rq_idx << NIC_Q_NUM_SHIFT) | (reg << 3))
1651
1652 rq = &nic->qs->rq[rq_idx];
1653 rq->stats.bytes = GET_RQ_STATS(RQ_SQ_STATS_OCTS);
1654 rq->stats.pkts = GET_RQ_STATS(RQ_SQ_STATS_PKTS);
1655}
1656
1657void nicvf_update_sq_stats(struct nicvf *nic, int sq_idx)
1658{
1659 struct snd_queue *sq;
1660
1661#define GET_SQ_STATS(reg) \
1662 nicvf_reg_read(nic, NIC_QSET_SQ_0_7_STAT_0_1 |\
1663 (sq_idx << NIC_Q_NUM_SHIFT) | (reg << 3))
1664
1665 sq = &nic->qs->sq[sq_idx];
1666 sq->stats.bytes = GET_SQ_STATS(RQ_SQ_STATS_OCTS);
1667 sq->stats.pkts = GET_SQ_STATS(RQ_SQ_STATS_PKTS);
1668}
1669
1670/* Check for errors in the receive cmp.queue entry */
Sunil Gouthamad2eceb2016-02-16 16:29:51 +05301671int nicvf_check_cqe_rx_errs(struct nicvf *nic, struct cqe_rx_t *cqe_rx)
Sunil Goutham4863dea2015-05-26 19:20:15 -07001672{
Sunil Goutham4863dea2015-05-26 19:20:15 -07001673 if (netif_msg_rx_err(nic))
1674 netdev_err(nic->netdev,
1675 "%s: RX error CQE err_level 0x%x err_opcode 0x%x\n",
1676 nic->netdev->name,
1677 cqe_rx->err_level, cqe_rx->err_opcode);
1678
Sunil Goutham4863dea2015-05-26 19:20:15 -07001679 switch (cqe_rx->err_opcode) {
1680 case CQ_RX_ERROP_RE_PARTIAL:
Sunil Goutham964cb692016-11-15 17:38:16 +05301681 this_cpu_inc(nic->drv_stats->rx_bgx_truncated_pkts);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001682 break;
1683 case CQ_RX_ERROP_RE_JABBER:
Sunil Goutham964cb692016-11-15 17:38:16 +05301684 this_cpu_inc(nic->drv_stats->rx_jabber_errs);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001685 break;
1686 case CQ_RX_ERROP_RE_FCS:
Sunil Goutham964cb692016-11-15 17:38:16 +05301687 this_cpu_inc(nic->drv_stats->rx_fcs_errs);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001688 break;
1689 case CQ_RX_ERROP_RE_RX_CTL:
Sunil Goutham964cb692016-11-15 17:38:16 +05301690 this_cpu_inc(nic->drv_stats->rx_bgx_errs);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001691 break;
1692 case CQ_RX_ERROP_PREL2_ERR:
Sunil Goutham964cb692016-11-15 17:38:16 +05301693 this_cpu_inc(nic->drv_stats->rx_prel2_errs);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001694 break;
1695 case CQ_RX_ERROP_L2_MAL:
Sunil Goutham964cb692016-11-15 17:38:16 +05301696 this_cpu_inc(nic->drv_stats->rx_l2_hdr_malformed);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001697 break;
1698 case CQ_RX_ERROP_L2_OVERSIZE:
Sunil Goutham964cb692016-11-15 17:38:16 +05301699 this_cpu_inc(nic->drv_stats->rx_oversize);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001700 break;
1701 case CQ_RX_ERROP_L2_UNDERSIZE:
Sunil Goutham964cb692016-11-15 17:38:16 +05301702 this_cpu_inc(nic->drv_stats->rx_undersize);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001703 break;
1704 case CQ_RX_ERROP_L2_LENMISM:
Sunil Goutham964cb692016-11-15 17:38:16 +05301705 this_cpu_inc(nic->drv_stats->rx_l2_len_mismatch);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001706 break;
1707 case CQ_RX_ERROP_L2_PCLP:
Sunil Goutham964cb692016-11-15 17:38:16 +05301708 this_cpu_inc(nic->drv_stats->rx_l2_pclp);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001709 break;
1710 case CQ_RX_ERROP_IP_NOT:
Sunil Goutham964cb692016-11-15 17:38:16 +05301711 this_cpu_inc(nic->drv_stats->rx_ip_ver_errs);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001712 break;
1713 case CQ_RX_ERROP_IP_CSUM_ERR:
Sunil Goutham964cb692016-11-15 17:38:16 +05301714 this_cpu_inc(nic->drv_stats->rx_ip_csum_errs);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001715 break;
1716 case CQ_RX_ERROP_IP_MAL:
Sunil Goutham964cb692016-11-15 17:38:16 +05301717 this_cpu_inc(nic->drv_stats->rx_ip_hdr_malformed);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001718 break;
1719 case CQ_RX_ERROP_IP_MALD:
Sunil Goutham964cb692016-11-15 17:38:16 +05301720 this_cpu_inc(nic->drv_stats->rx_ip_payload_malformed);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001721 break;
1722 case CQ_RX_ERROP_IP_HOP:
Sunil Goutham964cb692016-11-15 17:38:16 +05301723 this_cpu_inc(nic->drv_stats->rx_ip_ttl_errs);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001724 break;
1725 case CQ_RX_ERROP_L3_PCLP:
Sunil Goutham964cb692016-11-15 17:38:16 +05301726 this_cpu_inc(nic->drv_stats->rx_l3_pclp);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001727 break;
1728 case CQ_RX_ERROP_L4_MAL:
Sunil Goutham964cb692016-11-15 17:38:16 +05301729 this_cpu_inc(nic->drv_stats->rx_l4_malformed);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001730 break;
1731 case CQ_RX_ERROP_L4_CHK:
Sunil Goutham964cb692016-11-15 17:38:16 +05301732 this_cpu_inc(nic->drv_stats->rx_l4_csum_errs);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001733 break;
1734 case CQ_RX_ERROP_UDP_LEN:
Sunil Goutham964cb692016-11-15 17:38:16 +05301735 this_cpu_inc(nic->drv_stats->rx_udp_len_errs);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001736 break;
1737 case CQ_RX_ERROP_L4_PORT:
Sunil Goutham964cb692016-11-15 17:38:16 +05301738 this_cpu_inc(nic->drv_stats->rx_l4_port_errs);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001739 break;
1740 case CQ_RX_ERROP_TCP_FLAG:
Sunil Goutham964cb692016-11-15 17:38:16 +05301741 this_cpu_inc(nic->drv_stats->rx_tcp_flag_errs);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001742 break;
1743 case CQ_RX_ERROP_TCP_OFFSET:
Sunil Goutham964cb692016-11-15 17:38:16 +05301744 this_cpu_inc(nic->drv_stats->rx_tcp_offset_errs);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001745 break;
1746 case CQ_RX_ERROP_L4_PCLP:
Sunil Goutham964cb692016-11-15 17:38:16 +05301747 this_cpu_inc(nic->drv_stats->rx_l4_pclp);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001748 break;
1749 case CQ_RX_ERROP_RBDR_TRUNC:
Sunil Goutham964cb692016-11-15 17:38:16 +05301750 this_cpu_inc(nic->drv_stats->rx_truncated_pkts);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001751 break;
1752 }
1753
1754 return 1;
1755}
1756
1757/* Check for errors in the send cmp.queue entry */
Sunil Goutham964cb692016-11-15 17:38:16 +05301758int nicvf_check_cqe_tx_errs(struct nicvf *nic, struct cqe_send_t *cqe_tx)
Sunil Goutham4863dea2015-05-26 19:20:15 -07001759{
Sunil Goutham4863dea2015-05-26 19:20:15 -07001760 switch (cqe_tx->send_status) {
Sunil Goutham4863dea2015-05-26 19:20:15 -07001761 case CQ_TX_ERROP_DESC_FAULT:
Sunil Goutham964cb692016-11-15 17:38:16 +05301762 this_cpu_inc(nic->drv_stats->tx_desc_fault);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001763 break;
1764 case CQ_TX_ERROP_HDR_CONS_ERR:
Sunil Goutham964cb692016-11-15 17:38:16 +05301765 this_cpu_inc(nic->drv_stats->tx_hdr_cons_err);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001766 break;
1767 case CQ_TX_ERROP_SUBDC_ERR:
Sunil Goutham964cb692016-11-15 17:38:16 +05301768 this_cpu_inc(nic->drv_stats->tx_subdesc_err);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001769 break;
Sunil Goutham712c3182016-11-15 17:37:36 +05301770 case CQ_TX_ERROP_MAX_SIZE_VIOL:
Sunil Goutham964cb692016-11-15 17:38:16 +05301771 this_cpu_inc(nic->drv_stats->tx_max_size_exceeded);
Sunil Goutham712c3182016-11-15 17:37:36 +05301772 break;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001773 case CQ_TX_ERROP_IMM_SIZE_OFLOW:
Sunil Goutham964cb692016-11-15 17:38:16 +05301774 this_cpu_inc(nic->drv_stats->tx_imm_size_oflow);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001775 break;
1776 case CQ_TX_ERROP_DATA_SEQUENCE_ERR:
Sunil Goutham964cb692016-11-15 17:38:16 +05301777 this_cpu_inc(nic->drv_stats->tx_data_seq_err);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001778 break;
1779 case CQ_TX_ERROP_MEM_SEQUENCE_ERR:
Sunil Goutham964cb692016-11-15 17:38:16 +05301780 this_cpu_inc(nic->drv_stats->tx_mem_seq_err);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001781 break;
1782 case CQ_TX_ERROP_LOCK_VIOL:
Sunil Goutham964cb692016-11-15 17:38:16 +05301783 this_cpu_inc(nic->drv_stats->tx_lock_viol);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001784 break;
1785 case CQ_TX_ERROP_DATA_FAULT:
Sunil Goutham964cb692016-11-15 17:38:16 +05301786 this_cpu_inc(nic->drv_stats->tx_data_fault);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001787 break;
1788 case CQ_TX_ERROP_TSTMP_CONFLICT:
Sunil Goutham964cb692016-11-15 17:38:16 +05301789 this_cpu_inc(nic->drv_stats->tx_tstmp_conflict);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001790 break;
1791 case CQ_TX_ERROP_TSTMP_TIMEOUT:
Sunil Goutham964cb692016-11-15 17:38:16 +05301792 this_cpu_inc(nic->drv_stats->tx_tstmp_timeout);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001793 break;
1794 case CQ_TX_ERROP_MEM_FAULT:
Sunil Goutham964cb692016-11-15 17:38:16 +05301795 this_cpu_inc(nic->drv_stats->tx_mem_fault);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001796 break;
1797 case CQ_TX_ERROP_CK_OVERLAP:
Sunil Goutham964cb692016-11-15 17:38:16 +05301798 this_cpu_inc(nic->drv_stats->tx_csum_overlap);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001799 break;
1800 case CQ_TX_ERROP_CK_OFLOW:
Sunil Goutham964cb692016-11-15 17:38:16 +05301801 this_cpu_inc(nic->drv_stats->tx_csum_overflow);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001802 break;
1803 }
1804
1805 return 1;
1806}