blob: f914eef6573a841ea2befe1b9cb94ae437e1ee6d [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>
13#include <net/ip.h>
14#include <net/tso.h>
15
16#include "nic_reg.h"
17#include "nic.h"
18#include "q_struct.h"
19#include "nicvf_queues.h"
20
Sunil Goutham5c2e26f2016-03-14 16:36:14 +053021static void nicvf_get_page(struct nicvf *nic)
22{
23 if (!nic->rb_pageref || !nic->rb_page)
24 return;
25
Joonsoo Kim6d061f92016-05-19 17:10:46 -070026 page_ref_add(nic->rb_page, nic->rb_pageref);
Sunil Goutham5c2e26f2016-03-14 16:36:14 +053027 nic->rb_pageref = 0;
28}
29
Sunil Goutham4863dea2015-05-26 19:20:15 -070030/* Poll a register for a specific value */
31static int nicvf_poll_reg(struct nicvf *nic, int qidx,
32 u64 reg, int bit_pos, int bits, int val)
33{
34 u64 bit_mask;
35 u64 reg_val;
36 int timeout = 10;
37
38 bit_mask = (1ULL << bits) - 1;
39 bit_mask = (bit_mask << bit_pos);
40
41 while (timeout) {
42 reg_val = nicvf_queue_reg_read(nic, reg, qidx);
43 if (((reg_val & bit_mask) >> bit_pos) == val)
44 return 0;
45 usleep_range(1000, 2000);
46 timeout--;
47 }
48 netdev_err(nic->netdev, "Poll on reg 0x%llx failed\n", reg);
49 return 1;
50}
51
52/* Allocate memory for a queue's descriptors */
53static int nicvf_alloc_q_desc_mem(struct nicvf *nic, struct q_desc_mem *dmem,
54 int q_len, int desc_size, int align_bytes)
55{
56 dmem->q_len = q_len;
57 dmem->size = (desc_size * q_len) + align_bytes;
58 /* Save address, need it while freeing */
59 dmem->unalign_base = dma_zalloc_coherent(&nic->pdev->dev, dmem->size,
60 &dmem->dma, GFP_KERNEL);
61 if (!dmem->unalign_base)
62 return -ENOMEM;
63
64 /* Align memory address for 'align_bytes' */
65 dmem->phys_base = NICVF_ALIGNED_ADDR((u64)dmem->dma, align_bytes);
Aleksey Makarov39a0dd02015-06-02 11:00:25 -070066 dmem->base = dmem->unalign_base + (dmem->phys_base - dmem->dma);
Sunil Goutham4863dea2015-05-26 19:20:15 -070067 return 0;
68}
69
70/* Free queue's descriptor memory */
71static void nicvf_free_q_desc_mem(struct nicvf *nic, struct q_desc_mem *dmem)
72{
73 if (!dmem)
74 return;
75
76 dma_free_coherent(&nic->pdev->dev, dmem->size,
77 dmem->unalign_base, dmem->dma);
78 dmem->unalign_base = NULL;
79 dmem->base = NULL;
80}
81
82/* Allocate buffer for packet reception
83 * HW returns memory address where packet is DMA'ed but not a pointer
84 * into RBDR ring, so save buffer address at the start of fragment and
85 * align the start address to a cache aligned address
86 */
87static inline int nicvf_alloc_rcv_buffer(struct nicvf *nic, gfp_t gfp,
88 u32 buf_len, u64 **rbuf)
89{
Sunil Goutham6e4be8d2016-02-11 21:50:26 +053090 int order = (PAGE_SIZE <= 4096) ? PAGE_ALLOC_COSTLY_ORDER : 0;
Sunil Goutham4863dea2015-05-26 19:20:15 -070091
92 /* Check if request can be accomodated in previous allocated page */
Sunil Goutham5c2e26f2016-03-14 16:36:14 +053093 if (nic->rb_page &&
94 ((nic->rb_page_offset + buf_len) < (PAGE_SIZE << order))) {
95 nic->rb_pageref++;
96 goto ret;
Sunil Goutham4863dea2015-05-26 19:20:15 -070097 }
98
Sunil Goutham5c2e26f2016-03-14 16:36:14 +053099 nicvf_get_page(nic);
100 nic->rb_page = NULL;
101
Sunil Goutham4863dea2015-05-26 19:20:15 -0700102 /* Allocate a new page */
103 if (!nic->rb_page) {
Sunil Gouthamf8ce9662015-07-29 16:49:41 +0300104 nic->rb_page = alloc_pages(gfp | __GFP_COMP | __GFP_NOWARN,
105 order);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700106 if (!nic->rb_page) {
Thanneeru Srinivasulua05d4842016-02-11 21:50:21 +0530107 nic->drv_stats.rcv_buffer_alloc_failures++;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700108 return -ENOMEM;
109 }
110 nic->rb_page_offset = 0;
111 }
112
Sunil Goutham5c2e26f2016-03-14 16:36:14 +0530113ret:
Sunil Goutham668dda02015-12-07 10:30:33 +0530114 *rbuf = (u64 *)((u64)page_address(nic->rb_page) + nic->rb_page_offset);
Sunil Goutham5c2e26f2016-03-14 16:36:14 +0530115 nic->rb_page_offset += buf_len;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700116
Sunil Goutham4863dea2015-05-26 19:20:15 -0700117 return 0;
118}
119
Sunil Goutham668dda02015-12-07 10:30:33 +0530120/* Build skb around receive buffer */
Sunil Goutham4863dea2015-05-26 19:20:15 -0700121static struct sk_buff *nicvf_rb_ptr_to_skb(struct nicvf *nic,
122 u64 rb_ptr, int len)
123{
Sunil Goutham668dda02015-12-07 10:30:33 +0530124 void *data;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700125 struct sk_buff *skb;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700126
Sunil Goutham668dda02015-12-07 10:30:33 +0530127 data = phys_to_virt(rb_ptr);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700128
129 /* Now build an skb to give to stack */
Sunil Goutham668dda02015-12-07 10:30:33 +0530130 skb = build_skb(data, RCV_FRAG_LEN);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700131 if (!skb) {
Sunil Goutham668dda02015-12-07 10:30:33 +0530132 put_page(virt_to_page(data));
Sunil Goutham4863dea2015-05-26 19:20:15 -0700133 return NULL;
134 }
135
Sunil Goutham668dda02015-12-07 10:30:33 +0530136 prefetch(skb->data);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700137 return skb;
138}
139
140/* Allocate RBDR ring and populate receive buffers */
141static int nicvf_init_rbdr(struct nicvf *nic, struct rbdr *rbdr,
142 int ring_len, int buf_size)
143{
144 int idx;
145 u64 *rbuf;
146 struct rbdr_entry_t *desc;
147 int err;
148
149 err = nicvf_alloc_q_desc_mem(nic, &rbdr->dmem, ring_len,
150 sizeof(struct rbdr_entry_t),
151 NICVF_RCV_BUF_ALIGN_BYTES);
152 if (err)
153 return err;
154
155 rbdr->desc = rbdr->dmem.base;
156 /* Buffer size has to be in multiples of 128 bytes */
157 rbdr->dma_size = buf_size;
158 rbdr->enable = true;
159 rbdr->thresh = RBDR_THRESH;
160
161 nic->rb_page = NULL;
162 for (idx = 0; idx < ring_len; idx++) {
163 err = nicvf_alloc_rcv_buffer(nic, GFP_KERNEL, RCV_FRAG_LEN,
164 &rbuf);
165 if (err)
166 return err;
167
168 desc = GET_RBDR_DESC(rbdr, idx);
169 desc->buf_addr = virt_to_phys(rbuf) >> NICVF_RCV_BUF_ALIGN;
170 }
Sunil Goutham5c2e26f2016-03-14 16:36:14 +0530171
172 nicvf_get_page(nic);
173
Sunil Goutham4863dea2015-05-26 19:20:15 -0700174 return 0;
175}
176
177/* Free RBDR ring and its receive buffers */
178static void nicvf_free_rbdr(struct nicvf *nic, struct rbdr *rbdr)
179{
180 int head, tail;
181 u64 buf_addr;
182 struct rbdr_entry_t *desc;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700183
184 if (!rbdr)
185 return;
186
187 rbdr->enable = false;
188 if (!rbdr->dmem.base)
189 return;
190
191 head = rbdr->head;
192 tail = rbdr->tail;
193
194 /* Free SKBs */
195 while (head != tail) {
196 desc = GET_RBDR_DESC(rbdr, head);
197 buf_addr = desc->buf_addr << NICVF_RCV_BUF_ALIGN;
Sunil Goutham668dda02015-12-07 10:30:33 +0530198 put_page(virt_to_page(phys_to_virt(buf_addr)));
Sunil Goutham4863dea2015-05-26 19:20:15 -0700199 head++;
200 head &= (rbdr->dmem.q_len - 1);
201 }
202 /* Free SKB of tail desc */
203 desc = GET_RBDR_DESC(rbdr, tail);
204 buf_addr = desc->buf_addr << NICVF_RCV_BUF_ALIGN;
Sunil Goutham668dda02015-12-07 10:30:33 +0530205 put_page(virt_to_page(phys_to_virt(buf_addr)));
Sunil Goutham4863dea2015-05-26 19:20:15 -0700206
207 /* Free RBDR ring */
208 nicvf_free_q_desc_mem(nic, &rbdr->dmem);
209}
210
211/* Refill receive buffer descriptors with new buffers.
212 */
Aleksey Makarovfd7ec062015-06-02 11:00:23 -0700213static void nicvf_refill_rbdr(struct nicvf *nic, gfp_t gfp)
Sunil Goutham4863dea2015-05-26 19:20:15 -0700214{
215 struct queue_set *qs = nic->qs;
216 int rbdr_idx = qs->rbdr_cnt;
217 int tail, qcount;
218 int refill_rb_cnt;
219 struct rbdr *rbdr;
220 struct rbdr_entry_t *desc;
221 u64 *rbuf;
222 int new_rb = 0;
223
224refill:
225 if (!rbdr_idx)
226 return;
227 rbdr_idx--;
228 rbdr = &qs->rbdr[rbdr_idx];
229 /* Check if it's enabled */
230 if (!rbdr->enable)
231 goto next_rbdr;
232
233 /* Get no of desc's to be refilled */
234 qcount = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_STATUS0, rbdr_idx);
235 qcount &= 0x7FFFF;
236 /* Doorbell can be ringed with a max of ring size minus 1 */
237 if (qcount >= (qs->rbdr_len - 1))
238 goto next_rbdr;
239 else
240 refill_rb_cnt = qs->rbdr_len - qcount - 1;
241
242 /* Start filling descs from tail */
243 tail = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_TAIL, rbdr_idx) >> 3;
244 while (refill_rb_cnt) {
245 tail++;
246 tail &= (rbdr->dmem.q_len - 1);
247
248 if (nicvf_alloc_rcv_buffer(nic, gfp, RCV_FRAG_LEN, &rbuf))
249 break;
250
251 desc = GET_RBDR_DESC(rbdr, tail);
252 desc->buf_addr = virt_to_phys(rbuf) >> NICVF_RCV_BUF_ALIGN;
253 refill_rb_cnt--;
254 new_rb++;
255 }
256
Sunil Goutham5c2e26f2016-03-14 16:36:14 +0530257 nicvf_get_page(nic);
258
Sunil Goutham4863dea2015-05-26 19:20:15 -0700259 /* make sure all memory stores are done before ringing doorbell */
260 smp_wmb();
261
262 /* Check if buffer allocation failed */
263 if (refill_rb_cnt)
264 nic->rb_alloc_fail = true;
265 else
266 nic->rb_alloc_fail = false;
267
268 /* Notify HW */
269 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_DOOR,
270 rbdr_idx, new_rb);
271next_rbdr:
272 /* Re-enable RBDR interrupts only if buffer allocation is success */
273 if (!nic->rb_alloc_fail && rbdr->enable)
274 nicvf_enable_intr(nic, NICVF_INTR_RBDR, rbdr_idx);
275
276 if (rbdr_idx)
277 goto refill;
278}
279
280/* Alloc rcv buffers in non-atomic mode for better success */
281void nicvf_rbdr_work(struct work_struct *work)
282{
283 struct nicvf *nic = container_of(work, struct nicvf, rbdr_work.work);
284
285 nicvf_refill_rbdr(nic, GFP_KERNEL);
286 if (nic->rb_alloc_fail)
287 schedule_delayed_work(&nic->rbdr_work, msecs_to_jiffies(10));
288 else
289 nic->rb_work_scheduled = false;
290}
291
292/* In Softirq context, alloc rcv buffers in atomic mode */
293void nicvf_rbdr_task(unsigned long data)
294{
295 struct nicvf *nic = (struct nicvf *)data;
296
297 nicvf_refill_rbdr(nic, GFP_ATOMIC);
298 if (nic->rb_alloc_fail) {
299 nic->rb_work_scheduled = true;
300 schedule_delayed_work(&nic->rbdr_work, msecs_to_jiffies(10));
301 }
302}
303
304/* Initialize completion queue */
305static int nicvf_init_cmp_queue(struct nicvf *nic,
306 struct cmp_queue *cq, int q_len)
307{
308 int err;
309
310 err = nicvf_alloc_q_desc_mem(nic, &cq->dmem, q_len, CMP_QUEUE_DESC_SIZE,
311 NICVF_CQ_BASE_ALIGN_BYTES);
312 if (err)
313 return err;
314
315 cq->desc = cq->dmem.base;
Sunil Gouthamb9687b42015-12-10 13:25:20 +0530316 cq->thresh = pass1_silicon(nic->pdev) ? 0 : CMP_QUEUE_CQE_THRESH;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700317 nic->cq_coalesce_usecs = (CMP_QUEUE_TIMER_THRESH * 0.05) - 1;
318
319 return 0;
320}
321
322static void nicvf_free_cmp_queue(struct nicvf *nic, struct cmp_queue *cq)
323{
324 if (!cq)
325 return;
326 if (!cq->dmem.base)
327 return;
328
329 nicvf_free_q_desc_mem(nic, &cq->dmem);
330}
331
332/* Initialize transmit queue */
333static int nicvf_init_snd_queue(struct nicvf *nic,
334 struct snd_queue *sq, int q_len)
335{
336 int err;
337
338 err = nicvf_alloc_q_desc_mem(nic, &sq->dmem, q_len, SND_QUEUE_DESC_SIZE,
339 NICVF_SQ_BASE_ALIGN_BYTES);
340 if (err)
341 return err;
342
343 sq->desc = sq->dmem.base;
Aleksey Makarov86ace692015-06-02 11:00:27 -0700344 sq->skbuff = kcalloc(q_len, sizeof(u64), GFP_KERNEL);
Aleksey Makarovfa1a6c92015-06-02 11:00:26 -0700345 if (!sq->skbuff)
346 return -ENOMEM;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700347 sq->head = 0;
348 sq->tail = 0;
349 atomic_set(&sq->free_cnt, q_len - 1);
350 sq->thresh = SND_QUEUE_THRESH;
351
352 /* Preallocate memory for TSO segment's header */
353 sq->tso_hdrs = dma_alloc_coherent(&nic->pdev->dev,
354 q_len * TSO_HEADER_SIZE,
355 &sq->tso_hdrs_phys, GFP_KERNEL);
356 if (!sq->tso_hdrs)
357 return -ENOMEM;
358
359 return 0;
360}
361
362static void nicvf_free_snd_queue(struct nicvf *nic, struct snd_queue *sq)
363{
364 if (!sq)
365 return;
366 if (!sq->dmem.base)
367 return;
368
369 if (sq->tso_hdrs)
Sunil Goutham143ceb02015-07-29 16:49:37 +0300370 dma_free_coherent(&nic->pdev->dev,
371 sq->dmem.q_len * TSO_HEADER_SIZE,
Sunil Goutham4863dea2015-05-26 19:20:15 -0700372 sq->tso_hdrs, sq->tso_hdrs_phys);
373
374 kfree(sq->skbuff);
375 nicvf_free_q_desc_mem(nic, &sq->dmem);
376}
377
378static void nicvf_reclaim_snd_queue(struct nicvf *nic,
379 struct queue_set *qs, int qidx)
380{
381 /* Disable send queue */
382 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_CFG, qidx, 0);
383 /* Check if SQ is stopped */
384 if (nicvf_poll_reg(nic, qidx, NIC_QSET_SQ_0_7_STATUS, 21, 1, 0x01))
385 return;
386 /* Reset send queue */
387 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_CFG, qidx, NICVF_SQ_RESET);
388}
389
390static void nicvf_reclaim_rcv_queue(struct nicvf *nic,
391 struct queue_set *qs, int qidx)
392{
393 union nic_mbx mbx = {};
394
395 /* Make sure all packets in the pipeline are written back into mem */
396 mbx.msg.msg = NIC_MBOX_MSG_RQ_SW_SYNC;
397 nicvf_send_msg_to_pf(nic, &mbx);
398}
399
400static void nicvf_reclaim_cmp_queue(struct nicvf *nic,
401 struct queue_set *qs, int qidx)
402{
403 /* Disable timer threshold (doesn't get reset upon CQ reset */
404 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_CFG2, qidx, 0);
405 /* Disable completion queue */
406 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_CFG, qidx, 0);
407 /* Reset completion queue */
408 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_CFG, qidx, NICVF_CQ_RESET);
409}
410
411static void nicvf_reclaim_rbdr(struct nicvf *nic,
412 struct rbdr *rbdr, int qidx)
413{
414 u64 tmp, fifo_state;
415 int timeout = 10;
416
417 /* Save head and tail pointers for feeing up buffers */
418 rbdr->head = nicvf_queue_reg_read(nic,
419 NIC_QSET_RBDR_0_1_HEAD,
420 qidx) >> 3;
421 rbdr->tail = nicvf_queue_reg_read(nic,
422 NIC_QSET_RBDR_0_1_TAIL,
423 qidx) >> 3;
424
425 /* If RBDR FIFO is in 'FAIL' state then do a reset first
426 * before relaiming.
427 */
428 fifo_state = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_STATUS0, qidx);
429 if (((fifo_state >> 62) & 0x03) == 0x3)
430 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_CFG,
431 qidx, NICVF_RBDR_RESET);
432
433 /* Disable RBDR */
434 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_CFG, qidx, 0);
435 if (nicvf_poll_reg(nic, qidx, NIC_QSET_RBDR_0_1_STATUS0, 62, 2, 0x00))
436 return;
437 while (1) {
438 tmp = nicvf_queue_reg_read(nic,
439 NIC_QSET_RBDR_0_1_PREFETCH_STATUS,
440 qidx);
441 if ((tmp & 0xFFFFFFFF) == ((tmp >> 32) & 0xFFFFFFFF))
442 break;
443 usleep_range(1000, 2000);
444 timeout--;
445 if (!timeout) {
446 netdev_err(nic->netdev,
447 "Failed polling on prefetch status\n");
448 return;
449 }
450 }
451 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_CFG,
452 qidx, NICVF_RBDR_RESET);
453
454 if (nicvf_poll_reg(nic, qidx, NIC_QSET_RBDR_0_1_STATUS0, 62, 2, 0x02))
455 return;
456 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_CFG, qidx, 0x00);
457 if (nicvf_poll_reg(nic, qidx, NIC_QSET_RBDR_0_1_STATUS0, 62, 2, 0x00))
458 return;
459}
460
Sunil Gouthamaa2e2592015-08-30 12:29:13 +0300461void nicvf_config_vlan_stripping(struct nicvf *nic, netdev_features_t features)
462{
463 u64 rq_cfg;
464 int sqs;
465
466 rq_cfg = nicvf_queue_reg_read(nic, NIC_QSET_RQ_GEN_CFG, 0);
467
468 /* Enable first VLAN stripping */
469 if (features & NETIF_F_HW_VLAN_CTAG_RX)
470 rq_cfg |= (1ULL << 25);
471 else
472 rq_cfg &= ~(1ULL << 25);
473 nicvf_queue_reg_write(nic, NIC_QSET_RQ_GEN_CFG, 0, rq_cfg);
474
475 /* Configure Secondary Qsets, if any */
476 for (sqs = 0; sqs < nic->sqs_count; sqs++)
477 if (nic->snicvf[sqs])
478 nicvf_queue_reg_write(nic->snicvf[sqs],
479 NIC_QSET_RQ_GEN_CFG, 0, rq_cfg);
480}
481
Jerin Jacob3458c402016-08-12 16:51:39 +0530482static void nicvf_reset_rcv_queue_stats(struct nicvf *nic)
483{
484 union nic_mbx mbx = {};
485
486 /* Reset all RXQ's stats */
487 mbx.reset_stat.msg = NIC_MBOX_MSG_RESET_STAT_COUNTER;
488 mbx.reset_stat.rq_stat_mask = 0xFFFF;
489 nicvf_send_msg_to_pf(nic, &mbx);
490}
491
Sunil Goutham4863dea2015-05-26 19:20:15 -0700492/* Configures receive queue */
493static void nicvf_rcv_queue_config(struct nicvf *nic, struct queue_set *qs,
494 int qidx, bool enable)
495{
496 union nic_mbx mbx = {};
497 struct rcv_queue *rq;
498 struct rq_cfg rq_cfg;
499
500 rq = &qs->rq[qidx];
501 rq->enable = enable;
502
503 /* Disable receive queue */
504 nicvf_queue_reg_write(nic, NIC_QSET_RQ_0_7_CFG, qidx, 0);
505
506 if (!rq->enable) {
507 nicvf_reclaim_rcv_queue(nic, qs, qidx);
508 return;
509 }
510
511 rq->cq_qs = qs->vnic_id;
512 rq->cq_idx = qidx;
513 rq->start_rbdr_qs = qs->vnic_id;
514 rq->start_qs_rbdr_idx = qs->rbdr_cnt - 1;
515 rq->cont_rbdr_qs = qs->vnic_id;
516 rq->cont_qs_rbdr_idx = qs->rbdr_cnt - 1;
517 /* all writes of RBDR data to be loaded into L2 Cache as well*/
518 rq->caching = 1;
519
520 /* Send a mailbox msg to PF to config RQ */
521 mbx.rq.msg = NIC_MBOX_MSG_RQ_CFG;
522 mbx.rq.qs_num = qs->vnic_id;
523 mbx.rq.rq_num = qidx;
524 mbx.rq.cfg = (rq->caching << 26) | (rq->cq_qs << 19) |
525 (rq->cq_idx << 16) | (rq->cont_rbdr_qs << 9) |
526 (rq->cont_qs_rbdr_idx << 8) |
527 (rq->start_rbdr_qs << 1) | (rq->start_qs_rbdr_idx);
528 nicvf_send_msg_to_pf(nic, &mbx);
529
530 mbx.rq.msg = NIC_MBOX_MSG_RQ_BP_CFG;
531 mbx.rq.cfg = (1ULL << 63) | (1ULL << 62) | (qs->vnic_id << 0);
532 nicvf_send_msg_to_pf(nic, &mbx);
533
534 /* RQ drop config
535 * Enable CQ drop to reserve sufficient CQEs for all tx packets
536 */
537 mbx.rq.msg = NIC_MBOX_MSG_RQ_DROP_CFG;
538 mbx.rq.cfg = (1ULL << 62) | (RQ_CQ_DROP << 8);
539 nicvf_send_msg_to_pf(nic, &mbx);
540
Sunil Gouthamcadcf952016-11-15 17:37:54 +0530541 if (!nic->sqs_mode && (qidx == 0)) {
542 /* Enable checking L3/L4 length and TCP/UDP checksums */
543 nicvf_queue_reg_write(nic, NIC_QSET_RQ_GEN_CFG, 0,
544 (BIT(24) | BIT(23) | BIT(21)));
Sunil Gouthamaa2e2592015-08-30 12:29:13 +0300545 nicvf_config_vlan_stripping(nic, nic->netdev->features);
Sunil Gouthamcadcf952016-11-15 17:37:54 +0530546 }
Sunil Goutham4863dea2015-05-26 19:20:15 -0700547
548 /* Enable Receive queue */
xypron.glpk@gmx.de161de2c2016-05-09 00:46:18 +0200549 memset(&rq_cfg, 0, sizeof(struct rq_cfg));
Sunil Goutham4863dea2015-05-26 19:20:15 -0700550 rq_cfg.ena = 1;
551 rq_cfg.tcp_ena = 0;
552 nicvf_queue_reg_write(nic, NIC_QSET_RQ_0_7_CFG, qidx, *(u64 *)&rq_cfg);
553}
554
555/* Configures completion queue */
556void nicvf_cmp_queue_config(struct nicvf *nic, struct queue_set *qs,
557 int qidx, bool enable)
558{
559 struct cmp_queue *cq;
560 struct cq_cfg cq_cfg;
561
562 cq = &qs->cq[qidx];
563 cq->enable = enable;
564
565 if (!cq->enable) {
566 nicvf_reclaim_cmp_queue(nic, qs, qidx);
567 return;
568 }
569
570 /* Reset completion queue */
571 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_CFG, qidx, NICVF_CQ_RESET);
572
573 if (!cq->enable)
574 return;
575
576 spin_lock_init(&cq->lock);
577 /* Set completion queue base address */
578 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_BASE,
579 qidx, (u64)(cq->dmem.phys_base));
580
581 /* Enable Completion queue */
xypron.glpk@gmx.de161de2c2016-05-09 00:46:18 +0200582 memset(&cq_cfg, 0, sizeof(struct cq_cfg));
Sunil Goutham4863dea2015-05-26 19:20:15 -0700583 cq_cfg.ena = 1;
584 cq_cfg.reset = 0;
585 cq_cfg.caching = 0;
586 cq_cfg.qsize = CMP_QSIZE;
587 cq_cfg.avg_con = 0;
588 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_CFG, qidx, *(u64 *)&cq_cfg);
589
590 /* Set threshold value for interrupt generation */
591 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_THRESH, qidx, cq->thresh);
592 nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_CFG2,
Sunil Goutham006394a2015-12-02 15:36:15 +0530593 qidx, CMP_QUEUE_TIMER_THRESH);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700594}
595
596/* Configures transmit queue */
597static void nicvf_snd_queue_config(struct nicvf *nic, struct queue_set *qs,
598 int qidx, bool enable)
599{
600 union nic_mbx mbx = {};
601 struct snd_queue *sq;
602 struct sq_cfg sq_cfg;
603
604 sq = &qs->sq[qidx];
605 sq->enable = enable;
606
607 if (!sq->enable) {
608 nicvf_reclaim_snd_queue(nic, qs, qidx);
609 return;
610 }
611
612 /* Reset send queue */
613 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_CFG, qidx, NICVF_SQ_RESET);
614
615 sq->cq_qs = qs->vnic_id;
616 sq->cq_idx = qidx;
617
618 /* Send a mailbox msg to PF to config SQ */
619 mbx.sq.msg = NIC_MBOX_MSG_SQ_CFG;
620 mbx.sq.qs_num = qs->vnic_id;
621 mbx.sq.sq_num = qidx;
Sunil Goutham92dc8762015-08-30 12:29:15 +0300622 mbx.sq.sqs_mode = nic->sqs_mode;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700623 mbx.sq.cfg = (sq->cq_qs << 3) | sq->cq_idx;
624 nicvf_send_msg_to_pf(nic, &mbx);
625
626 /* Set queue base address */
627 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_BASE,
628 qidx, (u64)(sq->dmem.phys_base));
629
630 /* Enable send queue & set queue size */
xypron.glpk@gmx.de161de2c2016-05-09 00:46:18 +0200631 memset(&sq_cfg, 0, sizeof(struct sq_cfg));
Sunil Goutham4863dea2015-05-26 19:20:15 -0700632 sq_cfg.ena = 1;
633 sq_cfg.reset = 0;
634 sq_cfg.ldwb = 0;
635 sq_cfg.qsize = SND_QSIZE;
636 sq_cfg.tstmp_bgx_intf = 0;
637 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_CFG, qidx, *(u64 *)&sq_cfg);
638
639 /* Set threshold value for interrupt generation */
640 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_THRESH, qidx, sq->thresh);
641
642 /* Set queue:cpu affinity for better load distribution */
643 if (cpu_online(qidx)) {
644 cpumask_set_cpu(qidx, &sq->affinity_mask);
645 netif_set_xps_queue(nic->netdev,
646 &sq->affinity_mask, qidx);
647 }
648}
649
650/* Configures receive buffer descriptor ring */
651static void nicvf_rbdr_config(struct nicvf *nic, struct queue_set *qs,
652 int qidx, bool enable)
653{
654 struct rbdr *rbdr;
655 struct rbdr_cfg rbdr_cfg;
656
657 rbdr = &qs->rbdr[qidx];
658 nicvf_reclaim_rbdr(nic, rbdr, qidx);
659 if (!enable)
660 return;
661
662 /* Set descriptor base address */
663 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_BASE,
664 qidx, (u64)(rbdr->dmem.phys_base));
665
666 /* Enable RBDR & set queue size */
667 /* Buffer size should be in multiples of 128 bytes */
xypron.glpk@gmx.de161de2c2016-05-09 00:46:18 +0200668 memset(&rbdr_cfg, 0, sizeof(struct rbdr_cfg));
Sunil Goutham4863dea2015-05-26 19:20:15 -0700669 rbdr_cfg.ena = 1;
670 rbdr_cfg.reset = 0;
671 rbdr_cfg.ldwb = 0;
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);
677
678 /* Notify HW */
679 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_DOOR,
680 qidx, qs->rbdr_len - 1);
681
682 /* Set threshold value for interrupt generation */
683 nicvf_queue_reg_write(nic, NIC_QSET_RBDR_0_1_THRESH,
684 qidx, rbdr->thresh - 1);
685}
686
687/* Requests PF to assign and enable Qset */
688void nicvf_qset_config(struct nicvf *nic, bool enable)
689{
690 union nic_mbx mbx = {};
691 struct queue_set *qs = nic->qs;
692 struct qs_cfg *qs_cfg;
693
694 if (!qs) {
695 netdev_warn(nic->netdev,
696 "Qset is still not allocated, don't init queues\n");
697 return;
698 }
699
700 qs->enable = enable;
701 qs->vnic_id = nic->vf_id;
702
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;
Sunil Goutham92dc8762015-08-30 12:29:15 +0300706 mbx.qs.sqs_count = nic->sqs_count;
Sunil Goutham4863dea2015-05-26 19:20:15 -0700707
708 mbx.qs.cfg = 0;
709 qs_cfg = (struct qs_cfg *)&mbx.qs.cfg;
710 if (qs->enable) {
711 qs_cfg->ena = 1;
712#ifdef __BIG_ENDIAN
713 qs_cfg->be = 1;
714#endif
715 qs_cfg->vnic = qs->vnic_id;
716 }
717 nicvf_send_msg_to_pf(nic, &mbx);
718}
719
720static void nicvf_free_resources(struct nicvf *nic)
721{
722 int qidx;
723 struct queue_set *qs = nic->qs;
724
725 /* Free receive buffer descriptor ring */
726 for (qidx = 0; qidx < qs->rbdr_cnt; qidx++)
727 nicvf_free_rbdr(nic, &qs->rbdr[qidx]);
728
729 /* Free completion queue */
730 for (qidx = 0; qidx < qs->cq_cnt; qidx++)
731 nicvf_free_cmp_queue(nic, &qs->cq[qidx]);
732
733 /* Free send queue */
734 for (qidx = 0; qidx < qs->sq_cnt; qidx++)
735 nicvf_free_snd_queue(nic, &qs->sq[qidx]);
736}
737
738static int nicvf_alloc_resources(struct nicvf *nic)
739{
740 int qidx;
741 struct queue_set *qs = nic->qs;
742
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,
746 DMA_BUFFER_LEN))
747 goto alloc_fail;
748 }
749
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))
753 goto alloc_fail;
754 }
755
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))
759 goto alloc_fail;
760 }
761
762 return 0;
763alloc_fail:
764 nicvf_free_resources(nic);
765 return -ENOMEM;
766}
767
768int nicvf_set_qset_resources(struct nicvf *nic)
769{
770 struct queue_set *qs;
771
772 qs = devm_kzalloc(&nic->pdev->dev, sizeof(*qs), GFP_KERNEL);
773 if (!qs)
774 return -ENOMEM;
775 nic->qs = qs;
776
777 /* Set count of each queue */
Sunil Goutham3a397eb2016-08-12 16:51:27 +0530778 qs->rbdr_cnt = DEFAULT_RBDR_CNT;
779 qs->rq_cnt = min_t(u8, MAX_RCV_QUEUES_PER_QS, num_online_cpus());
780 qs->sq_cnt = min_t(u8, MAX_SND_QUEUES_PER_QS, num_online_cpus());
781 qs->cq_cnt = max_t(u8, qs->rq_cnt, qs->sq_cnt);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700782
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;
Sunil Goutham92dc8762015-08-30 12:29:15 +0300787
788 nic->rx_queues = qs->rq_cnt;
789 nic->tx_queues = qs->sq_cnt;
790
Sunil Goutham4863dea2015-05-26 19:20:15 -0700791 return 0;
792}
793
794int nicvf_config_data_transfer(struct nicvf *nic, bool enable)
795{
796 bool disable = false;
797 struct queue_set *qs = nic->qs;
798 int qidx;
799
800 if (!qs)
801 return 0;
802
803 if (enable) {
804 if (nicvf_alloc_resources(nic))
805 return -ENOMEM;
806
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);
815 } else {
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);
824
825 nicvf_free_resources(nic);
826 }
827
Jerin Jacob3458c402016-08-12 16:51:39 +0530828 /* Reset RXQ's stats.
829 * SQ's stats will get reset automatically once SQ is reset.
830 */
831 nicvf_reset_rcv_queue_stats(nic);
832
Sunil Goutham4863dea2015-05-26 19:20:15 -0700833 return 0;
834}
835
836/* Get a free desc from SQ
837 * returns descriptor ponter & descriptor number
838 */
839static inline int nicvf_get_sq_desc(struct snd_queue *sq, int desc_cnt)
840{
841 int qentry;
842
843 qentry = sq->tail;
844 atomic_sub(desc_cnt, &sq->free_cnt);
845 sq->tail += desc_cnt;
846 sq->tail &= (sq->dmem.q_len - 1);
847
848 return qentry;
849}
850
851/* Free descriptor back to SQ for future use */
852void nicvf_put_sq_desc(struct snd_queue *sq, int desc_cnt)
853{
854 atomic_add(desc_cnt, &sq->free_cnt);
855 sq->head += desc_cnt;
856 sq->head &= (sq->dmem.q_len - 1);
857}
858
859static inline int nicvf_get_nxt_sqentry(struct snd_queue *sq, int qentry)
860{
861 qentry++;
862 qentry &= (sq->dmem.q_len - 1);
863 return qentry;
864}
865
866void nicvf_sq_enable(struct nicvf *nic, struct snd_queue *sq, int qidx)
867{
868 u64 sq_cfg;
869
870 sq_cfg = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_CFG, qidx);
871 sq_cfg |= NICVF_SQ_EN;
872 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_CFG, qidx, sq_cfg);
873 /* Ring doorbell so that H/W restarts processing SQEs */
874 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_DOOR, qidx, 0);
875}
876
877void nicvf_sq_disable(struct nicvf *nic, int qidx)
878{
879 u64 sq_cfg;
880
881 sq_cfg = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_CFG, qidx);
882 sq_cfg &= ~NICVF_SQ_EN;
883 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_CFG, qidx, sq_cfg);
884}
885
886void nicvf_sq_free_used_descs(struct net_device *netdev, struct snd_queue *sq,
887 int qidx)
888{
889 u64 head, tail;
890 struct sk_buff *skb;
891 struct nicvf *nic = netdev_priv(netdev);
892 struct sq_hdr_subdesc *hdr;
893
894 head = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_HEAD, qidx) >> 4;
895 tail = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_TAIL, qidx) >> 4;
896 while (sq->head != head) {
897 hdr = (struct sq_hdr_subdesc *)GET_SQ_DESC(sq, sq->head);
898 if (hdr->subdesc_type != SQ_DESC_TYPE_HEADER) {
899 nicvf_put_sq_desc(sq, 1);
900 continue;
901 }
902 skb = (struct sk_buff *)sq->skbuff[sq->head];
Sunil Goutham143ceb02015-07-29 16:49:37 +0300903 if (skb)
904 dev_kfree_skb_any(skb);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700905 atomic64_add(1, (atomic64_t *)&netdev->stats.tx_packets);
906 atomic64_add(hdr->tot_len,
907 (atomic64_t *)&netdev->stats.tx_bytes);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700908 nicvf_put_sq_desc(sq, hdr->subdesc_cnt + 1);
909 }
910}
911
912/* Calculate no of SQ subdescriptors needed to transmit all
913 * segments of this TSO packet.
914 * Taken from 'Tilera network driver' with a minor modification.
915 */
916static int nicvf_tso_count_subdescs(struct sk_buff *skb)
917{
918 struct skb_shared_info *sh = skb_shinfo(skb);
919 unsigned int sh_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
920 unsigned int data_len = skb->len - sh_len;
921 unsigned int p_len = sh->gso_size;
922 long f_id = -1; /* id of the current fragment */
923 long f_size = skb_headlen(skb) - sh_len; /* current fragment size */
924 long f_used = 0; /* bytes used from the current fragment */
925 long n; /* size of the current piece of payload */
926 int num_edescs = 0;
927 int segment;
928
929 for (segment = 0; segment < sh->gso_segs; segment++) {
930 unsigned int p_used = 0;
931
932 /* One edesc for header and for each piece of the payload. */
933 for (num_edescs++; p_used < p_len; num_edescs++) {
934 /* Advance as needed. */
935 while (f_used >= f_size) {
936 f_id++;
937 f_size = skb_frag_size(&sh->frags[f_id]);
938 f_used = 0;
939 }
940
941 /* Use bytes from the current fragment. */
942 n = p_len - p_used;
943 if (n > f_size - f_used)
944 n = f_size - f_used;
945 f_used += n;
946 p_used += n;
947 }
948
949 /* The last segment may be less than gso_size. */
950 data_len -= p_len;
951 if (data_len < p_len)
952 p_len = data_len;
953 }
954
955 /* '+ gso_segs' for SQ_HDR_SUDESCs for each segment */
956 return num_edescs + sh->gso_segs;
957}
958
Sunil Goutham7ceb8a12016-08-30 11:36:27 +0530959#define POST_CQE_DESC_COUNT 2
960
Sunil Goutham4863dea2015-05-26 19:20:15 -0700961/* Get the number of SQ descriptors needed to xmit this skb */
962static int nicvf_sq_subdesc_required(struct nicvf *nic, struct sk_buff *skb)
963{
964 int subdesc_cnt = MIN_SQ_DESC_PER_PKT_XMIT;
965
Sunil Goutham40fb5f82015-12-10 13:25:19 +0530966 if (skb_shinfo(skb)->gso_size && !nic->hw_tso) {
Sunil Goutham4863dea2015-05-26 19:20:15 -0700967 subdesc_cnt = nicvf_tso_count_subdescs(skb);
968 return subdesc_cnt;
969 }
970
Sunil Goutham7ceb8a12016-08-30 11:36:27 +0530971 /* Dummy descriptors to get TSO pkt completion notification */
972 if (nic->t88 && nic->hw_tso && skb_shinfo(skb)->gso_size)
973 subdesc_cnt += POST_CQE_DESC_COUNT;
974
Sunil Goutham4863dea2015-05-26 19:20:15 -0700975 if (skb_shinfo(skb)->nr_frags)
976 subdesc_cnt += skb_shinfo(skb)->nr_frags;
977
978 return subdesc_cnt;
979}
980
981/* Add SQ HEADER subdescriptor.
982 * First subdescriptor for every send descriptor.
983 */
984static inline void
Sunil Goutham40fb5f82015-12-10 13:25:19 +0530985nicvf_sq_add_hdr_subdesc(struct nicvf *nic, struct snd_queue *sq, int qentry,
Sunil Goutham4863dea2015-05-26 19:20:15 -0700986 int subdesc_cnt, struct sk_buff *skb, int len)
987{
988 int proto;
989 struct sq_hdr_subdesc *hdr;
990
991 hdr = (struct sq_hdr_subdesc *)GET_SQ_DESC(sq, qentry);
Sunil Goutham4863dea2015-05-26 19:20:15 -0700992 memset(hdr, 0, SND_QUEUE_DESC_SIZE);
993 hdr->subdesc_type = SQ_DESC_TYPE_HEADER;
Sunil Goutham7ceb8a12016-08-30 11:36:27 +0530994
995 if (nic->t88 && nic->hw_tso && skb_shinfo(skb)->gso_size) {
996 /* post_cqe = 0, to avoid HW posting a CQE for every TSO
997 * segment transmitted on 88xx.
998 */
999 hdr->subdesc_cnt = subdesc_cnt - POST_CQE_DESC_COUNT;
1000 } else {
1001 sq->skbuff[qentry] = (u64)skb;
1002 /* Enable notification via CQE after processing SQE */
1003 hdr->post_cqe = 1;
1004 /* No of subdescriptors following this */
1005 hdr->subdesc_cnt = subdesc_cnt;
1006 }
Sunil Goutham4863dea2015-05-26 19:20:15 -07001007 hdr->tot_len = len;
1008
1009 /* Offload checksum calculation to HW */
1010 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Sunil Goutham4863dea2015-05-26 19:20:15 -07001011 hdr->csum_l3 = 1; /* Enable IP csum calculation */
1012 hdr->l3_offset = skb_network_offset(skb);
1013 hdr->l4_offset = skb_transport_offset(skb);
1014
1015 proto = ip_hdr(skb)->protocol;
1016 switch (proto) {
1017 case IPPROTO_TCP:
1018 hdr->csum_l4 = SEND_L4_CSUM_TCP;
1019 break;
1020 case IPPROTO_UDP:
1021 hdr->csum_l4 = SEND_L4_CSUM_UDP;
1022 break;
1023 case IPPROTO_SCTP:
1024 hdr->csum_l4 = SEND_L4_CSUM_SCTP;
1025 break;
1026 }
1027 }
Sunil Goutham40fb5f82015-12-10 13:25:19 +05301028
1029 if (nic->hw_tso && skb_shinfo(skb)->gso_size) {
1030 hdr->tso = 1;
1031 hdr->tso_start = skb_transport_offset(skb) + tcp_hdrlen(skb);
1032 hdr->tso_max_paysize = skb_shinfo(skb)->gso_size;
1033 /* For non-tunneled pkts, point this to L2 ethertype */
1034 hdr->inner_l3_offset = skb_network_offset(skb) - 2;
1035 nic->drv_stats.tx_tso++;
1036 }
Sunil Goutham4863dea2015-05-26 19:20:15 -07001037}
1038
1039/* SQ GATHER subdescriptor
1040 * Must follow HDR descriptor
1041 */
1042static inline void nicvf_sq_add_gather_subdesc(struct snd_queue *sq, int qentry,
1043 int size, u64 data)
1044{
1045 struct sq_gather_subdesc *gather;
1046
1047 qentry &= (sq->dmem.q_len - 1);
1048 gather = (struct sq_gather_subdesc *)GET_SQ_DESC(sq, qentry);
1049
1050 memset(gather, 0, SND_QUEUE_DESC_SIZE);
1051 gather->subdesc_type = SQ_DESC_TYPE_GATHER;
Sunil Goutham4b561c12015-07-29 16:49:36 +03001052 gather->ld_type = NIC_SEND_LD_TYPE_E_LDD;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001053 gather->size = size;
1054 gather->addr = data;
1055}
1056
Sunil Goutham7ceb8a12016-08-30 11:36:27 +05301057/* Add HDR + IMMEDIATE subdescriptors right after descriptors of a TSO
1058 * packet so that a CQE is posted as a notifation for transmission of
1059 * TSO packet.
1060 */
1061static inline void nicvf_sq_add_cqe_subdesc(struct snd_queue *sq, int qentry,
1062 int tso_sqe, struct sk_buff *skb)
1063{
1064 struct sq_imm_subdesc *imm;
1065 struct sq_hdr_subdesc *hdr;
1066
1067 sq->skbuff[qentry] = (u64)skb;
1068
1069 hdr = (struct sq_hdr_subdesc *)GET_SQ_DESC(sq, qentry);
1070 memset(hdr, 0, SND_QUEUE_DESC_SIZE);
1071 hdr->subdesc_type = SQ_DESC_TYPE_HEADER;
1072 /* Enable notification via CQE after processing SQE */
1073 hdr->post_cqe = 1;
1074 /* There is no packet to transmit here */
1075 hdr->dont_send = 1;
1076 hdr->subdesc_cnt = POST_CQE_DESC_COUNT - 1;
1077 hdr->tot_len = 1;
1078 /* Actual TSO header SQE index, needed for cleanup */
1079 hdr->rsvd2 = tso_sqe;
1080
1081 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1082 imm = (struct sq_imm_subdesc *)GET_SQ_DESC(sq, qentry);
1083 memset(imm, 0, SND_QUEUE_DESC_SIZE);
1084 imm->subdesc_type = SQ_DESC_TYPE_IMMEDIATE;
1085 imm->len = 1;
1086}
1087
Sunil Goutham2c204c22016-09-23 14:42:28 +05301088static inline void nicvf_sq_doorbell(struct nicvf *nic, struct sk_buff *skb,
1089 int sq_num, int desc_cnt)
1090{
1091 struct netdev_queue *txq;
1092
1093 txq = netdev_get_tx_queue(nic->pnicvf->netdev,
1094 skb_get_queue_mapping(skb));
1095
1096 netdev_tx_sent_queue(txq, skb->len);
1097
1098 /* make sure all memory stores are done before ringing doorbell */
1099 smp_wmb();
1100
1101 /* Inform HW to xmit all TSO segments */
1102 nicvf_queue_reg_write(nic, NIC_QSET_SQ_0_7_DOOR,
1103 sq_num, desc_cnt);
1104}
1105
Sunil Goutham4863dea2015-05-26 19:20:15 -07001106/* Segment a TSO packet into 'gso_size' segments and append
1107 * them to SQ for transfer
1108 */
1109static int nicvf_sq_append_tso(struct nicvf *nic, struct snd_queue *sq,
Sunil Goutham92dc8762015-08-30 12:29:15 +03001110 int sq_num, int qentry, struct sk_buff *skb)
Sunil Goutham4863dea2015-05-26 19:20:15 -07001111{
1112 struct tso_t tso;
1113 int seg_subdescs = 0, desc_cnt = 0;
1114 int seg_len, total_len, data_left;
1115 int hdr_qentry = qentry;
1116 int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1117
1118 tso_start(skb, &tso);
1119 total_len = skb->len - hdr_len;
1120 while (total_len > 0) {
1121 char *hdr;
1122
1123 /* Save Qentry for adding HDR_SUBDESC at the end */
1124 hdr_qentry = qentry;
1125
1126 data_left = min_t(int, skb_shinfo(skb)->gso_size, total_len);
1127 total_len -= data_left;
1128
1129 /* Add segment's header */
1130 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1131 hdr = sq->tso_hdrs + qentry * TSO_HEADER_SIZE;
1132 tso_build_hdr(skb, hdr, &tso, data_left, total_len == 0);
1133 nicvf_sq_add_gather_subdesc(sq, qentry, hdr_len,
1134 sq->tso_hdrs_phys +
1135 qentry * TSO_HEADER_SIZE);
1136 /* HDR_SUDESC + GATHER */
1137 seg_subdescs = 2;
1138 seg_len = hdr_len;
1139
1140 /* Add segment's payload fragments */
1141 while (data_left > 0) {
1142 int size;
1143
1144 size = min_t(int, tso.size, data_left);
1145
1146 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1147 nicvf_sq_add_gather_subdesc(sq, qentry, size,
1148 virt_to_phys(tso.data));
1149 seg_subdescs++;
1150 seg_len += size;
1151
1152 data_left -= size;
1153 tso_build_data(skb, &tso, size);
1154 }
Sunil Goutham40fb5f82015-12-10 13:25:19 +05301155 nicvf_sq_add_hdr_subdesc(nic, sq, hdr_qentry,
Sunil Goutham4863dea2015-05-26 19:20:15 -07001156 seg_subdescs - 1, skb, seg_len);
Sunil Goutham143ceb02015-07-29 16:49:37 +03001157 sq->skbuff[hdr_qentry] = (u64)NULL;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001158 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1159
1160 desc_cnt += seg_subdescs;
1161 }
1162 /* Save SKB in the last segment for freeing */
1163 sq->skbuff[hdr_qentry] = (u64)skb;
1164
Sunil Goutham2c204c22016-09-23 14:42:28 +05301165 nicvf_sq_doorbell(nic, skb, sq_num, desc_cnt);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001166
Sunil Goutham2cb468e2015-07-29 16:49:40 +03001167 nic->drv_stats.tx_tso++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001168 return 1;
1169}
1170
1171/* Append an skb to a SQ for packet transfer. */
1172int nicvf_sq_append_skb(struct nicvf *nic, struct sk_buff *skb)
1173{
1174 int i, size;
Sunil Goutham7ceb8a12016-08-30 11:36:27 +05301175 int subdesc_cnt, tso_sqe = 0;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001176 int sq_num, qentry;
Sunil Goutham92dc8762015-08-30 12:29:15 +03001177 struct queue_set *qs;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001178 struct snd_queue *sq;
1179
1180 sq_num = skb_get_queue_mapping(skb);
Sunil Goutham92dc8762015-08-30 12:29:15 +03001181 if (sq_num >= MAX_SND_QUEUES_PER_QS) {
1182 /* Get secondary Qset's SQ structure */
1183 i = sq_num / MAX_SND_QUEUES_PER_QS;
1184 if (!nic->snicvf[i - 1]) {
1185 netdev_warn(nic->netdev,
1186 "Secondary Qset#%d's ptr not initialized\n",
1187 i - 1);
1188 return 1;
1189 }
1190 nic = (struct nicvf *)nic->snicvf[i - 1];
1191 sq_num = sq_num % MAX_SND_QUEUES_PER_QS;
1192 }
1193
1194 qs = nic->qs;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001195 sq = &qs->sq[sq_num];
1196
1197 subdesc_cnt = nicvf_sq_subdesc_required(nic, skb);
1198 if (subdesc_cnt > atomic_read(&sq->free_cnt))
1199 goto append_fail;
1200
1201 qentry = nicvf_get_sq_desc(sq, subdesc_cnt);
1202
1203 /* Check if its a TSO packet */
Sunil Goutham40fb5f82015-12-10 13:25:19 +05301204 if (skb_shinfo(skb)->gso_size && !nic->hw_tso)
Sunil Goutham92dc8762015-08-30 12:29:15 +03001205 return nicvf_sq_append_tso(nic, sq, sq_num, qentry, skb);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001206
1207 /* Add SQ header subdesc */
Sunil Goutham40fb5f82015-12-10 13:25:19 +05301208 nicvf_sq_add_hdr_subdesc(nic, sq, qentry, subdesc_cnt - 1,
1209 skb, skb->len);
Sunil Goutham7ceb8a12016-08-30 11:36:27 +05301210 tso_sqe = qentry;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001211
1212 /* Add SQ gather subdescs */
1213 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1214 size = skb_is_nonlinear(skb) ? skb_headlen(skb) : skb->len;
1215 nicvf_sq_add_gather_subdesc(sq, qentry, size, virt_to_phys(skb->data));
1216
1217 /* Check for scattered buffer */
1218 if (!skb_is_nonlinear(skb))
1219 goto doorbell;
1220
1221 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1222 const struct skb_frag_struct *frag;
1223
1224 frag = &skb_shinfo(skb)->frags[i];
1225
1226 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1227 size = skb_frag_size(frag);
1228 nicvf_sq_add_gather_subdesc(sq, qentry, size,
1229 virt_to_phys(
1230 skb_frag_address(frag)));
1231 }
1232
1233doorbell:
Sunil Goutham7ceb8a12016-08-30 11:36:27 +05301234 if (nic->t88 && skb_shinfo(skb)->gso_size) {
1235 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1236 nicvf_sq_add_cqe_subdesc(sq, qentry, tso_sqe, skb);
1237 }
1238
Sunil Goutham2c204c22016-09-23 14:42:28 +05301239 nicvf_sq_doorbell(nic, skb, sq_num, subdesc_cnt);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001240
Sunil Goutham4863dea2015-05-26 19:20:15 -07001241 return 1;
1242
1243append_fail:
Sunil Goutham92dc8762015-08-30 12:29:15 +03001244 /* Use original PCI dev for debug log */
1245 nic = nic->pnicvf;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001246 netdev_dbg(nic->netdev, "Not enough SQ descriptors to xmit pkt\n");
1247 return 0;
1248}
1249
1250static inline unsigned frag_num(unsigned i)
1251{
1252#ifdef __BIG_ENDIAN
1253 return (i & ~3) + 3 - (i & 3);
1254#else
1255 return i;
1256#endif
1257}
1258
1259/* Returns SKB for a received packet */
1260struct sk_buff *nicvf_get_rcv_skb(struct nicvf *nic, struct cqe_rx_t *cqe_rx)
1261{
1262 int frag;
1263 int payload_len = 0;
1264 struct sk_buff *skb = NULL;
Sunil Gouthama8671ac2016-08-12 16:51:37 +05301265 struct page *page;
1266 int offset;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001267 u16 *rb_lens = NULL;
1268 u64 *rb_ptrs = NULL;
1269
1270 rb_lens = (void *)cqe_rx + (3 * sizeof(u64));
Sunil Goutham02a72bd2016-08-12 16:51:28 +05301271 /* Except 88xx pass1 on all other chips CQE_RX2_S is added to
1272 * CQE_RX at word6, hence buffer pointers move by word
1273 *
1274 * Use existing 'hw_tso' flag which will be set for all chips
1275 * except 88xx pass1 instead of a additional cache line
1276 * access (or miss) by using pci dev's revision.
1277 */
1278 if (!nic->hw_tso)
1279 rb_ptrs = (void *)cqe_rx + (6 * sizeof(u64));
1280 else
1281 rb_ptrs = (void *)cqe_rx + (7 * sizeof(u64));
Sunil Goutham4863dea2015-05-26 19:20:15 -07001282
1283 netdev_dbg(nic->netdev, "%s rb_cnt %d rb0_ptr %llx rb0_sz %d\n",
1284 __func__, cqe_rx->rb_cnt, cqe_rx->rb0_ptr, cqe_rx->rb0_sz);
1285
1286 for (frag = 0; frag < cqe_rx->rb_cnt; frag++) {
1287 payload_len = rb_lens[frag_num(frag)];
1288 if (!frag) {
1289 /* First fragment */
1290 skb = nicvf_rb_ptr_to_skb(nic,
1291 *rb_ptrs - cqe_rx->align_pad,
1292 payload_len);
1293 if (!skb)
1294 return NULL;
1295 skb_reserve(skb, cqe_rx->align_pad);
1296 skb_put(skb, payload_len);
1297 } else {
1298 /* Add fragments */
Sunil Gouthama8671ac2016-08-12 16:51:37 +05301299 page = virt_to_page(phys_to_virt(*rb_ptrs));
1300 offset = phys_to_virt(*rb_ptrs) - page_address(page);
1301 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1302 offset, payload_len, RCV_FRAG_LEN);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001303 }
1304 /* Next buffer pointer */
1305 rb_ptrs++;
1306 }
1307 return skb;
1308}
1309
Yury Norovb45ceb42015-12-07 10:30:32 +05301310static u64 nicvf_int_type_to_mask(int int_type, int q_idx)
Sunil Goutham4863dea2015-05-26 19:20:15 -07001311{
1312 u64 reg_val;
1313
Sunil Goutham4863dea2015-05-26 19:20:15 -07001314 switch (int_type) {
1315 case NICVF_INTR_CQ:
1316 reg_val = ((1ULL << q_idx) << NICVF_INTR_CQ_SHIFT);
1317 break;
1318 case NICVF_INTR_SQ:
1319 reg_val = ((1ULL << q_idx) << NICVF_INTR_SQ_SHIFT);
1320 break;
1321 case NICVF_INTR_RBDR:
1322 reg_val = ((1ULL << q_idx) << NICVF_INTR_RBDR_SHIFT);
1323 break;
1324 case NICVF_INTR_PKT_DROP:
1325 reg_val = (1ULL << NICVF_INTR_PKT_DROP_SHIFT);
1326 break;
1327 case NICVF_INTR_TCP_TIMER:
1328 reg_val = (1ULL << NICVF_INTR_TCP_TIMER_SHIFT);
1329 break;
1330 case NICVF_INTR_MBOX:
1331 reg_val = (1ULL << NICVF_INTR_MBOX_SHIFT);
1332 break;
1333 case NICVF_INTR_QS_ERR:
Yury Norovb45ceb42015-12-07 10:30:32 +05301334 reg_val = (1ULL << NICVF_INTR_QS_ERR_SHIFT);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001335 break;
1336 default:
Yury Norovb45ceb42015-12-07 10:30:32 +05301337 reg_val = 0;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001338 }
1339
Yury Norovb45ceb42015-12-07 10:30:32 +05301340 return reg_val;
1341}
1342
1343/* Enable interrupt */
1344void nicvf_enable_intr(struct nicvf *nic, int int_type, int q_idx)
1345{
1346 u64 mask = nicvf_int_type_to_mask(int_type, q_idx);
1347
1348 if (!mask) {
1349 netdev_dbg(nic->netdev,
1350 "Failed to enable interrupt: unknown type\n");
1351 return;
1352 }
1353 nicvf_reg_write(nic, NIC_VF_ENA_W1S,
1354 nicvf_reg_read(nic, NIC_VF_ENA_W1S) | mask);
1355}
1356
1357/* Disable interrupt */
1358void nicvf_disable_intr(struct nicvf *nic, int int_type, int q_idx)
1359{
1360 u64 mask = nicvf_int_type_to_mask(int_type, q_idx);
1361
1362 if (!mask) {
1363 netdev_dbg(nic->netdev,
1364 "Failed to disable interrupt: unknown type\n");
1365 return;
1366 }
1367
1368 nicvf_reg_write(nic, NIC_VF_ENA_W1C, mask);
1369}
1370
1371/* Clear interrupt */
1372void nicvf_clear_intr(struct nicvf *nic, int int_type, int q_idx)
1373{
1374 u64 mask = nicvf_int_type_to_mask(int_type, q_idx);
1375
1376 if (!mask) {
1377 netdev_dbg(nic->netdev,
1378 "Failed to clear interrupt: unknown type\n");
1379 return;
1380 }
1381
1382 nicvf_reg_write(nic, NIC_VF_INT, mask);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001383}
1384
1385/* Check if interrupt is enabled */
1386int nicvf_is_intr_enabled(struct nicvf *nic, int int_type, int q_idx)
1387{
Yury Norovb45ceb42015-12-07 10:30:32 +05301388 u64 mask = nicvf_int_type_to_mask(int_type, q_idx);
1389 /* If interrupt type is unknown, we treat it disabled. */
1390 if (!mask) {
1391 netdev_dbg(nic->netdev,
Sunil Goutham4863dea2015-05-26 19:20:15 -07001392 "Failed to check interrupt enable: unknown type\n");
Yury Norovb45ceb42015-12-07 10:30:32 +05301393 return 0;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001394 }
1395
Yury Norovb45ceb42015-12-07 10:30:32 +05301396 return mask & nicvf_reg_read(nic, NIC_VF_ENA_W1S);
Sunil Goutham4863dea2015-05-26 19:20:15 -07001397}
1398
1399void nicvf_update_rq_stats(struct nicvf *nic, int rq_idx)
1400{
1401 struct rcv_queue *rq;
1402
1403#define GET_RQ_STATS(reg) \
1404 nicvf_reg_read(nic, NIC_QSET_RQ_0_7_STAT_0_1 |\
1405 (rq_idx << NIC_Q_NUM_SHIFT) | (reg << 3))
1406
1407 rq = &nic->qs->rq[rq_idx];
1408 rq->stats.bytes = GET_RQ_STATS(RQ_SQ_STATS_OCTS);
1409 rq->stats.pkts = GET_RQ_STATS(RQ_SQ_STATS_PKTS);
1410}
1411
1412void nicvf_update_sq_stats(struct nicvf *nic, int sq_idx)
1413{
1414 struct snd_queue *sq;
1415
1416#define GET_SQ_STATS(reg) \
1417 nicvf_reg_read(nic, NIC_QSET_SQ_0_7_STAT_0_1 |\
1418 (sq_idx << NIC_Q_NUM_SHIFT) | (reg << 3))
1419
1420 sq = &nic->qs->sq[sq_idx];
1421 sq->stats.bytes = GET_SQ_STATS(RQ_SQ_STATS_OCTS);
1422 sq->stats.pkts = GET_SQ_STATS(RQ_SQ_STATS_PKTS);
1423}
1424
1425/* Check for errors in the receive cmp.queue entry */
Sunil Gouthamad2eceb2016-02-16 16:29:51 +05301426int nicvf_check_cqe_rx_errs(struct nicvf *nic, struct cqe_rx_t *cqe_rx)
Sunil Goutham4863dea2015-05-26 19:20:15 -07001427{
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001428 struct nicvf_hw_stats *stats = &nic->hw_stats;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001429
Sunil Gouthamad2eceb2016-02-16 16:29:51 +05301430 if (!cqe_rx->err_level && !cqe_rx->err_opcode)
Sunil Goutham4863dea2015-05-26 19:20:15 -07001431 return 0;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001432
1433 if (netif_msg_rx_err(nic))
1434 netdev_err(nic->netdev,
1435 "%s: RX error CQE err_level 0x%x err_opcode 0x%x\n",
1436 nic->netdev->name,
1437 cqe_rx->err_level, cqe_rx->err_opcode);
1438
Sunil Goutham4863dea2015-05-26 19:20:15 -07001439 switch (cqe_rx->err_opcode) {
1440 case CQ_RX_ERROP_RE_PARTIAL:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001441 stats->rx_bgx_truncated_pkts++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001442 break;
1443 case CQ_RX_ERROP_RE_JABBER:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001444 stats->rx_jabber_errs++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001445 break;
1446 case CQ_RX_ERROP_RE_FCS:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001447 stats->rx_fcs_errs++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001448 break;
1449 case CQ_RX_ERROP_RE_RX_CTL:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001450 stats->rx_bgx_errs++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001451 break;
1452 case CQ_RX_ERROP_PREL2_ERR:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001453 stats->rx_prel2_errs++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001454 break;
1455 case CQ_RX_ERROP_L2_MAL:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001456 stats->rx_l2_hdr_malformed++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001457 break;
1458 case CQ_RX_ERROP_L2_OVERSIZE:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001459 stats->rx_oversize++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001460 break;
1461 case CQ_RX_ERROP_L2_UNDERSIZE:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001462 stats->rx_undersize++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001463 break;
1464 case CQ_RX_ERROP_L2_LENMISM:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001465 stats->rx_l2_len_mismatch++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001466 break;
1467 case CQ_RX_ERROP_L2_PCLP:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001468 stats->rx_l2_pclp++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001469 break;
1470 case CQ_RX_ERROP_IP_NOT:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001471 stats->rx_ip_ver_errs++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001472 break;
1473 case CQ_RX_ERROP_IP_CSUM_ERR:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001474 stats->rx_ip_csum_errs++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001475 break;
1476 case CQ_RX_ERROP_IP_MAL:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001477 stats->rx_ip_hdr_malformed++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001478 break;
1479 case CQ_RX_ERROP_IP_MALD:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001480 stats->rx_ip_payload_malformed++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001481 break;
1482 case CQ_RX_ERROP_IP_HOP:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001483 stats->rx_ip_ttl_errs++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001484 break;
1485 case CQ_RX_ERROP_L3_PCLP:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001486 stats->rx_l3_pclp++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001487 break;
1488 case CQ_RX_ERROP_L4_MAL:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001489 stats->rx_l4_malformed++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001490 break;
1491 case CQ_RX_ERROP_L4_CHK:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001492 stats->rx_l4_csum_errs++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001493 break;
1494 case CQ_RX_ERROP_UDP_LEN:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001495 stats->rx_udp_len_errs++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001496 break;
1497 case CQ_RX_ERROP_L4_PORT:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001498 stats->rx_l4_port_errs++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001499 break;
1500 case CQ_RX_ERROP_TCP_FLAG:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001501 stats->rx_tcp_flag_errs++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001502 break;
1503 case CQ_RX_ERROP_TCP_OFFSET:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001504 stats->rx_tcp_offset_errs++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001505 break;
1506 case CQ_RX_ERROP_L4_PCLP:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001507 stats->rx_l4_pclp++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001508 break;
1509 case CQ_RX_ERROP_RBDR_TRUNC:
Sunil Gouthama2dc5de2015-08-30 12:29:10 +03001510 stats->rx_truncated_pkts++;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001511 break;
1512 }
1513
1514 return 1;
1515}
1516
1517/* Check for errors in the send cmp.queue entry */
1518int nicvf_check_cqe_tx_errs(struct nicvf *nic,
1519 struct cmp_queue *cq, struct cqe_send_t *cqe_tx)
1520{
1521 struct cmp_queue_stats *stats = &cq->stats;
1522
1523 switch (cqe_tx->send_status) {
1524 case CQ_TX_ERROP_GOOD:
1525 stats->tx.good++;
1526 return 0;
1527 case CQ_TX_ERROP_DESC_FAULT:
1528 stats->tx.desc_fault++;
1529 break;
1530 case CQ_TX_ERROP_HDR_CONS_ERR:
1531 stats->tx.hdr_cons_err++;
1532 break;
1533 case CQ_TX_ERROP_SUBDC_ERR:
1534 stats->tx.subdesc_err++;
1535 break;
Sunil Goutham712c3182016-11-15 17:37:36 +05301536 case CQ_TX_ERROP_MAX_SIZE_VIOL:
1537 stats->tx.max_size_exceeded++;
1538 break;
Sunil Goutham4863dea2015-05-26 19:20:15 -07001539 case CQ_TX_ERROP_IMM_SIZE_OFLOW:
1540 stats->tx.imm_size_oflow++;
1541 break;
1542 case CQ_TX_ERROP_DATA_SEQUENCE_ERR:
1543 stats->tx.data_seq_err++;
1544 break;
1545 case CQ_TX_ERROP_MEM_SEQUENCE_ERR:
1546 stats->tx.mem_seq_err++;
1547 break;
1548 case CQ_TX_ERROP_LOCK_VIOL:
1549 stats->tx.lock_viol++;
1550 break;
1551 case CQ_TX_ERROP_DATA_FAULT:
1552 stats->tx.data_fault++;
1553 break;
1554 case CQ_TX_ERROP_TSTMP_CONFLICT:
1555 stats->tx.tstmp_conflict++;
1556 break;
1557 case CQ_TX_ERROP_TSTMP_TIMEOUT:
1558 stats->tx.tstmp_timeout++;
1559 break;
1560 case CQ_TX_ERROP_MEM_FAULT:
1561 stats->tx.mem_fault++;
1562 break;
1563 case CQ_TX_ERROP_CK_OVERLAP:
1564 stats->tx.csum_overlap++;
1565 break;
1566 case CQ_TX_ERROP_CK_OFLOW:
1567 stats->tx.csum_overflow++;
1568 break;
1569 }
1570
1571 return 1;
1572}