-
Notifications
You must be signed in to change notification settings - Fork 102
/
vxge-main.c
4848 lines (4089 loc) · 128 KB
/
vxge-main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
* This software may be used and distributed according to the terms of
* the GNU General Public License (GPL), incorporated herein by reference.
* Drivers based on or derived from this code fall under the GPL and must
* retain the authorship, copyright and license notice. This file is not
* a complete program and may only be used when the entire operating
* system is licensed under the GPL.
* See the file COPYING in this distribution for more information.
*
* vxge-main.c: Driver for Exar Corp's X3100 Series 10GbE PCIe I/O
* Virtualized Server Adapter.
* Copyright(c) 2002-2010 Exar Corp.
*
* The module loadable parameters that are supported by the driver and a brief
* explanation of all the variables:
* vlan_tag_strip:
* Strip VLAN Tag enable/disable. Instructs the device to remove
* the VLAN tag from all received tagged frames that are not
* replicated at the internal L2 switch.
* 0 - Do not strip the VLAN tag.
* 1 - Strip the VLAN tag.
*
* addr_learn_en:
* Enable learning the mac address of the guest OS interface in
* a virtualization environment.
* 0 - DISABLE
* 1 - ENABLE
*
* max_config_port:
* Maximum number of port to be supported.
* MIN -1 and MAX - 2
*
* max_config_vpath:
* This configures the maximum no of VPATH configures for each
* device function.
* MIN - 1 and MAX - 17
*
* max_config_dev:
* This configures maximum no of Device function to be enabled.
* MIN - 1 and MAX - 17
*
******************************************************************************/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/bitops.h>
#include <linux/if_vlan.h>
#include <linux/interrupt.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/tcp.h>
#include <net/ip.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/firmware.h>
#include <linux/net_tstamp.h>
#include <linux/prefetch.h>
#include <linux/module.h>
#include "vxge-main.h"
#include "vxge-reg.h"
MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
"Virtualized Server Adapter");
static const struct pci_device_id vxge_id_table[] = {
{PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
PCI_ANY_ID},
{PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
PCI_ANY_ID},
{0}
};
MODULE_DEVICE_TABLE(pci, vxge_id_table);
VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
{0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
{[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
module_param_array(bw_percentage, uint, NULL, 0);
static struct vxge_drv_config *driver_config;
static enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev);
static inline int is_vxge_card_up(struct vxgedev *vdev)
{
return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
}
static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
{
struct sk_buff **skb_ptr = NULL;
struct sk_buff **temp;
#define NR_SKB_COMPLETED 16
struct sk_buff *completed[NR_SKB_COMPLETED];
int more;
do {
more = 0;
skb_ptr = completed;
if (__netif_tx_trylock(fifo->txq)) {
vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
NR_SKB_COMPLETED, &more);
__netif_tx_unlock(fifo->txq);
}
/* free SKBs */
for (temp = completed; temp != skb_ptr; temp++)
dev_consume_skb_irq(*temp);
} while (more);
}
static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
{
int i;
/* Complete all transmits */
for (i = 0; i < vdev->no_of_vpath; i++)
VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
}
static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
{
int i;
struct vxge_ring *ring;
/* Complete all receives*/
for (i = 0; i < vdev->no_of_vpath; i++) {
ring = &vdev->vpaths[i].ring;
vxge_hw_vpath_poll_rx(ring->handle);
}
}
/*
* vxge_callback_link_up
*
* This function is called during interrupt context to notify link up state
* change.
*/
static void vxge_callback_link_up(struct __vxge_hw_device *hldev)
{
struct net_device *dev = hldev->ndev;
struct vxgedev *vdev = netdev_priv(dev);
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
vdev->ndev->name, __func__, __LINE__);
netdev_notice(vdev->ndev, "Link Up\n");
vdev->stats.link_up++;
netif_carrier_on(vdev->ndev);
netif_tx_wake_all_queues(vdev->ndev);
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
}
/*
* vxge_callback_link_down
*
* This function is called during interrupt context to notify link down state
* change.
*/
static void vxge_callback_link_down(struct __vxge_hw_device *hldev)
{
struct net_device *dev = hldev->ndev;
struct vxgedev *vdev = netdev_priv(dev);
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
netdev_notice(vdev->ndev, "Link Down\n");
vdev->stats.link_down++;
netif_carrier_off(vdev->ndev);
netif_tx_stop_all_queues(vdev->ndev);
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
}
/*
* vxge_rx_alloc
*
* Allocate SKB.
*/
static struct sk_buff *
vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
{
struct net_device *dev;
struct sk_buff *skb;
struct vxge_rx_priv *rx_priv;
dev = ring->ndev;
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
ring->ndev->name, __func__, __LINE__);
rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
/* try to allocate skb first. this one may fail */
skb = netdev_alloc_skb(dev, skb_size +
VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
if (skb == NULL) {
vxge_debug_mem(VXGE_ERR,
"%s: out of memory to allocate SKB", dev->name);
ring->stats.skb_alloc_fail++;
return NULL;
}
vxge_debug_mem(VXGE_TRACE,
"%s: %s:%d Skb : 0x%p", ring->ndev->name,
__func__, __LINE__, skb);
skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
rx_priv->skb = skb;
rx_priv->skb_data = NULL;
rx_priv->data_size = skb_size;
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
return skb;
}
/*
* vxge_rx_map
*/
static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
{
struct vxge_rx_priv *rx_priv;
dma_addr_t dma_addr;
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
ring->ndev->name, __func__, __LINE__);
rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
rx_priv->skb_data = rx_priv->skb->data;
dma_addr = dma_map_single(&ring->pdev->dev, rx_priv->skb_data,
rx_priv->data_size, DMA_FROM_DEVICE);
if (unlikely(dma_mapping_error(&ring->pdev->dev, dma_addr))) {
ring->stats.pci_map_fail++;
return -EIO;
}
vxge_debug_mem(VXGE_TRACE,
"%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
ring->ndev->name, __func__, __LINE__,
(unsigned long long)dma_addr);
vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
rx_priv->data_dma = dma_addr;
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
return 0;
}
/*
* vxge_rx_initial_replenish
* Allocation of RxD as an initial replenish procedure.
*/
static enum vxge_hw_status
vxge_rx_initial_replenish(void *dtrh, void *userdata)
{
struct vxge_ring *ring = (struct vxge_ring *)userdata;
struct vxge_rx_priv *rx_priv;
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
ring->ndev->name, __func__, __LINE__);
if (vxge_rx_alloc(dtrh, ring,
VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
return VXGE_HW_FAIL;
if (vxge_rx_map(dtrh, ring)) {
rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
dev_kfree_skb(rx_priv->skb);
return VXGE_HW_FAIL;
}
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
return VXGE_HW_OK;
}
static inline void
vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
{
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
ring->ndev->name, __func__, __LINE__);
skb_record_rx_queue(skb, ring->driver_id);
skb->protocol = eth_type_trans(skb, ring->ndev);
u64_stats_update_begin(&ring->stats.syncp);
ring->stats.rx_frms++;
ring->stats.rx_bytes += pkt_length;
if (skb->pkt_type == PACKET_MULTICAST)
ring->stats.rx_mcast++;
u64_stats_update_end(&ring->stats.syncp);
vxge_debug_rx(VXGE_TRACE,
"%s: %s:%d skb protocol = %d",
ring->ndev->name, __func__, __LINE__, skb->protocol);
if (ext_info->vlan &&
ring->vlan_tag_strip == VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE)
__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), ext_info->vlan);
napi_gro_receive(ring->napi_p, skb);
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
}
static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
struct vxge_rx_priv *rx_priv)
{
dma_sync_single_for_device(&ring->pdev->dev, rx_priv->data_dma,
rx_priv->data_size, DMA_FROM_DEVICE);
vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
}
static inline void vxge_post(int *dtr_cnt, void **first_dtr,
void *post_dtr, struct __vxge_hw_ring *ringh)
{
int dtr_count = *dtr_cnt;
if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
if (*first_dtr)
vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
*first_dtr = post_dtr;
} else
vxge_hw_ring_rxd_post_post(ringh, post_dtr);
dtr_count++;
*dtr_cnt = dtr_count;
}
/*
* vxge_rx_1b_compl
*
* If the interrupt is because of a received frame or if the receive ring
* contains fresh as yet un-processed frames, this function is called.
*/
static enum vxge_hw_status
vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
u8 t_code, void *userdata)
{
struct vxge_ring *ring = (struct vxge_ring *)userdata;
struct net_device *dev = ring->ndev;
unsigned int dma_sizes;
void *first_dtr = NULL;
int dtr_cnt = 0;
int data_size;
dma_addr_t data_dma;
int pkt_length;
struct sk_buff *skb;
struct vxge_rx_priv *rx_priv;
struct vxge_hw_ring_rxd_info ext_info;
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
ring->ndev->name, __func__, __LINE__);
if (ring->budget <= 0)
goto out;
do {
prefetch((char *)dtr + L1_CACHE_BYTES);
rx_priv = vxge_hw_ring_rxd_private_get(dtr);
skb = rx_priv->skb;
data_size = rx_priv->data_size;
data_dma = rx_priv->data_dma;
prefetch(rx_priv->skb_data);
vxge_debug_rx(VXGE_TRACE,
"%s: %s:%d skb = 0x%p",
ring->ndev->name, __func__, __LINE__, skb);
vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
pkt_length = dma_sizes;
pkt_length -= ETH_FCS_LEN;
vxge_debug_rx(VXGE_TRACE,
"%s: %s:%d Packet Length = %d",
ring->ndev->name, __func__, __LINE__, pkt_length);
vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
/* check skb validity */
vxge_assert(skb);
prefetch((char *)skb + L1_CACHE_BYTES);
if (unlikely(t_code)) {
if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
VXGE_HW_OK) {
ring->stats.rx_errors++;
vxge_debug_rx(VXGE_TRACE,
"%s: %s :%d Rx T_code is %d",
ring->ndev->name, __func__,
__LINE__, t_code);
/* If the t_code is not supported and if the
* t_code is other than 0x5 (unparseable packet
* such as unknown UPV6 header), Drop it !!!
*/
vxge_re_pre_post(dtr, ring, rx_priv);
vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
ring->stats.rx_dropped++;
continue;
}
}
if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
if (!vxge_rx_map(dtr, ring)) {
skb_put(skb, pkt_length);
dma_unmap_single(&ring->pdev->dev,
data_dma, data_size,
DMA_FROM_DEVICE);
vxge_hw_ring_rxd_pre_post(ringh, dtr);
vxge_post(&dtr_cnt, &first_dtr, dtr,
ringh);
} else {
dev_kfree_skb(rx_priv->skb);
rx_priv->skb = skb;
rx_priv->data_size = data_size;
vxge_re_pre_post(dtr, ring, rx_priv);
vxge_post(&dtr_cnt, &first_dtr, dtr,
ringh);
ring->stats.rx_dropped++;
break;
}
} else {
vxge_re_pre_post(dtr, ring, rx_priv);
vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
ring->stats.rx_dropped++;
break;
}
} else {
struct sk_buff *skb_up;
skb_up = netdev_alloc_skb(dev, pkt_length +
VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
if (skb_up != NULL) {
skb_reserve(skb_up,
VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
dma_sync_single_for_cpu(&ring->pdev->dev,
data_dma, data_size,
DMA_FROM_DEVICE);
vxge_debug_mem(VXGE_TRACE,
"%s: %s:%d skb_up = %p",
ring->ndev->name, __func__,
__LINE__, skb);
memcpy(skb_up->data, skb->data, pkt_length);
vxge_re_pre_post(dtr, ring, rx_priv);
vxge_post(&dtr_cnt, &first_dtr, dtr,
ringh);
/* will netif_rx small SKB instead */
skb = skb_up;
skb_put(skb, pkt_length);
} else {
vxge_re_pre_post(dtr, ring, rx_priv);
vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
vxge_debug_rx(VXGE_ERR,
"%s: vxge_rx_1b_compl: out of "
"memory", dev->name);
ring->stats.skb_alloc_fail++;
break;
}
}
if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
!(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
(dev->features & NETIF_F_RXCSUM) && /* Offload Rx side CSUM */
ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
skb->ip_summed = CHECKSUM_UNNECESSARY;
else
skb_checksum_none_assert(skb);
if (ring->rx_hwts) {
struct skb_shared_hwtstamps *skb_hwts;
u32 ns = *(u32 *)(skb->head + pkt_length);
skb_hwts = skb_hwtstamps(skb);
skb_hwts->hwtstamp = ns_to_ktime(ns);
}
/* rth_hash_type and rth_it_hit are non-zero regardless of
* whether rss is enabled. Only the rth_value is zero/non-zero
* if rss is disabled/enabled, so key off of that.
*/
if (ext_info.rth_value)
skb_set_hash(skb, ext_info.rth_value,
PKT_HASH_TYPE_L3);
vxge_rx_complete(ring, skb, ext_info.vlan,
pkt_length, &ext_info);
ring->budget--;
ring->pkts_processed++;
if (!ring->budget)
break;
} while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
&t_code) == VXGE_HW_OK);
if (first_dtr)
vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
out:
vxge_debug_entryexit(VXGE_TRACE,
"%s:%d Exiting...",
__func__, __LINE__);
return VXGE_HW_OK;
}
/*
* vxge_xmit_compl
*
* If an interrupt was raised to indicate DMA complete of the Tx packet,
* this function is called. It identifies the last TxD whose buffer was
* freed and frees all skbs whose data have already DMA'ed into the NICs
* internal memory.
*/
static enum vxge_hw_status
vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
enum vxge_hw_fifo_tcode t_code, void *userdata,
struct sk_buff ***skb_ptr, int nr_skb, int *more)
{
struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
struct sk_buff *skb, **done_skb = *skb_ptr;
int pkt_cnt = 0;
vxge_debug_entryexit(VXGE_TRACE,
"%s:%d Entered....", __func__, __LINE__);
do {
int frg_cnt;
skb_frag_t *frag;
int i = 0, j;
struct vxge_tx_priv *txd_priv =
vxge_hw_fifo_txdl_private_get(dtr);
skb = txd_priv->skb;
frg_cnt = skb_shinfo(skb)->nr_frags;
frag = &skb_shinfo(skb)->frags[0];
vxge_debug_tx(VXGE_TRACE,
"%s: %s:%d fifo_hw = %p dtr = %p "
"tcode = 0x%x", fifo->ndev->name, __func__,
__LINE__, fifo_hw, dtr, t_code);
/* check skb validity */
vxge_assert(skb);
vxge_debug_tx(VXGE_TRACE,
"%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
fifo->ndev->name, __func__, __LINE__,
skb, txd_priv, frg_cnt);
if (unlikely(t_code)) {
fifo->stats.tx_errors++;
vxge_debug_tx(VXGE_ERR,
"%s: tx: dtr %p completed due to "
"error t_code %01x", fifo->ndev->name,
dtr, t_code);
vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
}
/* for unfragmented skb */
dma_unmap_single(&fifo->pdev->dev, txd_priv->dma_buffers[i++],
skb_headlen(skb), DMA_TO_DEVICE);
for (j = 0; j < frg_cnt; j++) {
dma_unmap_page(&fifo->pdev->dev,
txd_priv->dma_buffers[i++],
skb_frag_size(frag), DMA_TO_DEVICE);
frag += 1;
}
vxge_hw_fifo_txdl_free(fifo_hw, dtr);
/* Updating the statistics block */
u64_stats_update_begin(&fifo->stats.syncp);
fifo->stats.tx_frms++;
fifo->stats.tx_bytes += skb->len;
u64_stats_update_end(&fifo->stats.syncp);
*done_skb++ = skb;
if (--nr_skb <= 0) {
*more = 1;
break;
}
pkt_cnt++;
if (pkt_cnt > fifo->indicate_max_pkts)
break;
} while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
&dtr, &t_code) == VXGE_HW_OK);
*skb_ptr = done_skb;
if (netif_tx_queue_stopped(fifo->txq))
netif_tx_wake_queue(fifo->txq);
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d Exiting...",
fifo->ndev->name, __func__, __LINE__);
return VXGE_HW_OK;
}
/* select a vpath to transmit the packet */
static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
{
u16 queue_len, counter = 0;
if (skb->protocol == htons(ETH_P_IP)) {
struct iphdr *ip;
struct tcphdr *th;
ip = ip_hdr(skb);
if (!ip_is_fragment(ip)) {
th = (struct tcphdr *)(((unsigned char *)ip) +
ip->ihl*4);
queue_len = vdev->no_of_vpath;
counter = (ntohs(th->source) +
ntohs(th->dest)) &
vdev->vpath_selector[queue_len - 1];
if (counter >= queue_len)
counter = queue_len - 1;
}
}
return counter;
}
static enum vxge_hw_status vxge_search_mac_addr_in_list(
struct vxge_vpath *vpath, u64 del_mac)
{
struct list_head *entry, *next;
list_for_each_safe(entry, next, &vpath->mac_addr_list) {
if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
return TRUE;
}
return FALSE;
}
static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
{
struct vxge_mac_addrs *new_mac_entry;
u8 *mac_address = NULL;
if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
return TRUE;
new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
if (!new_mac_entry) {
vxge_debug_mem(VXGE_ERR,
"%s: memory allocation failed",
VXGE_DRIVER_NAME);
return FALSE;
}
list_add(&new_mac_entry->item, &vpath->mac_addr_list);
/* Copy the new mac address to the list */
mac_address = (u8 *)&new_mac_entry->macaddr;
memcpy(mac_address, mac->macaddr, ETH_ALEN);
new_mac_entry->state = mac->state;
vpath->mac_addr_cnt++;
if (is_multicast_ether_addr(mac->macaddr))
vpath->mcast_addr_cnt++;
return TRUE;
}
/* Add a mac address to DA table */
static enum vxge_hw_status
vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
{
enum vxge_hw_status status = VXGE_HW_OK;
struct vxge_vpath *vpath;
enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
if (is_multicast_ether_addr(mac->macaddr))
duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
else
duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
vpath = &vdev->vpaths[mac->vpath_no];
status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
mac->macmask, duplicate_mode);
if (status != VXGE_HW_OK) {
vxge_debug_init(VXGE_ERR,
"DA config add entry failed for vpath:%d",
vpath->device_id);
} else
if (FALSE == vxge_mac_list_add(vpath, mac))
status = -EPERM;
return status;
}
static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
{
struct macInfo mac_info;
u8 *mac_address = NULL;
u64 mac_addr = 0, vpath_vector = 0;
int vpath_idx = 0;
enum vxge_hw_status status = VXGE_HW_OK;
struct vxge_vpath *vpath = NULL;
mac_address = (u8 *)&mac_addr;
memcpy(mac_address, mac_header, ETH_ALEN);
/* Is this mac address already in the list? */
for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
vpath = &vdev->vpaths[vpath_idx];
if (vxge_search_mac_addr_in_list(vpath, mac_addr))
return vpath_idx;
}
memset(&mac_info, 0, sizeof(struct macInfo));
memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
/* Any vpath has room to add mac address to its da table? */
for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
vpath = &vdev->vpaths[vpath_idx];
if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
/* Add this mac address to this vpath */
mac_info.vpath_no = vpath_idx;
mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
status = vxge_add_mac_addr(vdev, &mac_info);
if (status != VXGE_HW_OK)
return -EPERM;
return vpath_idx;
}
}
mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
vpath_idx = 0;
mac_info.vpath_no = vpath_idx;
/* Is the first vpath already selected as catch-basin ? */
vpath = &vdev->vpaths[vpath_idx];
if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
/* Add this mac address to this vpath */
if (FALSE == vxge_mac_list_add(vpath, &mac_info))
return -EPERM;
return vpath_idx;
}
/* Select first vpath as catch-basin */
vpath_vector = vxge_mBIT(vpath->device_id);
status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
vxge_hw_mgmt_reg_type_mrpcim,
0,
(ulong)offsetof(
struct vxge_hw_mrpcim_reg,
rts_mgr_cbasin_cfg),
vpath_vector);
if (status != VXGE_HW_OK) {
vxge_debug_tx(VXGE_ERR,
"%s: Unable to set the vpath-%d in catch-basin mode",
VXGE_DRIVER_NAME, vpath->device_id);
return -EPERM;
}
if (FALSE == vxge_mac_list_add(vpath, &mac_info))
return -EPERM;
return vpath_idx;
}
/**
* vxge_xmit
* @skb : the socket buffer containing the Tx data.
* @dev : device pointer.
*
* This function is the Tx entry point of the driver. Neterion NIC supports
* certain protocol assist features on Tx side, namely CSO, S/G, LSO.
*/
static netdev_tx_t
vxge_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct vxge_fifo *fifo = NULL;
void *dtr_priv;
void *dtr = NULL;
struct vxgedev *vdev = NULL;
enum vxge_hw_status status;
int frg_cnt, first_frg_len;
skb_frag_t *frag;
int i = 0, j = 0, avail;
u64 dma_pointer;
struct vxge_tx_priv *txdl_priv = NULL;
struct __vxge_hw_fifo *fifo_hw;
int offload_type;
int vpath_no = 0;
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
dev->name, __func__, __LINE__);
/* A buffer with no data will be dropped */
if (unlikely(skb->len <= 0)) {
vxge_debug_tx(VXGE_ERR,
"%s: Buffer has no data..", dev->name);
dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
}
vdev = netdev_priv(dev);
if (unlikely(!is_vxge_card_up(vdev))) {
vxge_debug_tx(VXGE_ERR,
"%s: vdev not initialized", dev->name);
dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
}
if (vdev->config.addr_learn_en) {
vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
if (vpath_no == -EPERM) {
vxge_debug_tx(VXGE_ERR,
"%s: Failed to store the mac address",
dev->name);
dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
}
}
if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
vpath_no = skb_get_queue_mapping(skb);
else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
vpath_no = vxge_get_vpath_no(vdev, skb);
vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
if (vpath_no >= vdev->no_of_vpath)
vpath_no = 0;
fifo = &vdev->vpaths[vpath_no].fifo;
fifo_hw = fifo->handle;
if (netif_tx_queue_stopped(fifo->txq))
return NETDEV_TX_BUSY;
avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
if (avail == 0) {
vxge_debug_tx(VXGE_ERR,
"%s: No free TXDs available", dev->name);
fifo->stats.txd_not_free++;
goto _exit0;
}
/* Last TXD? Stop tx queue to avoid dropping packets. TX
* completion will resume the queue.
*/
if (avail == 1)
netif_tx_stop_queue(fifo->txq);
status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
if (unlikely(status != VXGE_HW_OK)) {
vxge_debug_tx(VXGE_ERR,
"%s: Out of descriptors .", dev->name);
fifo->stats.txd_out_of_desc++;
goto _exit0;
}
vxge_debug_tx(VXGE_TRACE,
"%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
dev->name, __func__, __LINE__,
fifo_hw, dtr, dtr_priv);
if (skb_vlan_tag_present(skb)) {
u16 vlan_tag = skb_vlan_tag_get(skb);
vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
}
first_frg_len = skb_headlen(skb);
dma_pointer = dma_map_single(&fifo->pdev->dev, skb->data,
first_frg_len, DMA_TO_DEVICE);
if (unlikely(dma_mapping_error(&fifo->pdev->dev, dma_pointer))) {
vxge_hw_fifo_txdl_free(fifo_hw, dtr);
fifo->stats.pci_map_fail++;
goto _exit0;
}
txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
txdl_priv->skb = skb;
txdl_priv->dma_buffers[j] = dma_pointer;
frg_cnt = skb_shinfo(skb)->nr_frags;
vxge_debug_tx(VXGE_TRACE,
"%s: %s:%d skb = %p txdl_priv = %p "
"frag_cnt = %d dma_pointer = 0x%llx", dev->name,
__func__, __LINE__, skb, txdl_priv,
frg_cnt, (unsigned long long)dma_pointer);
vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
first_frg_len);
frag = &skb_shinfo(skb)->frags[0];
for (i = 0; i < frg_cnt; i++) {
/* ignore 0 length fragment */
if (!skb_frag_size(frag))
continue;
dma_pointer = (u64)skb_frag_dma_map(&fifo->pdev->dev, frag,
0, skb_frag_size(frag),
DMA_TO_DEVICE);
if (unlikely(dma_mapping_error(&fifo->pdev->dev, dma_pointer)))
goto _exit2;
vxge_debug_tx(VXGE_TRACE,
"%s: %s:%d frag = %d dma_pointer = 0x%llx",
dev->name, __func__, __LINE__, i,
(unsigned long long)dma_pointer);
txdl_priv->dma_buffers[j] = dma_pointer;
vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
skb_frag_size(frag));
frag += 1;
}
offload_type = vxge_offload_type(skb);
if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
int mss = vxge_tcp_mss(skb);
if (mss) {
vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
dev->name, __func__, __LINE__, mss);
vxge_hw_fifo_txdl_mss_set(dtr, mss);
} else {
vxge_assert(skb->len <=
dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
vxge_assert(0);
goto _exit1;
}
}
if (skb->ip_summed == CHECKSUM_PARTIAL)
vxge_hw_fifo_txdl_cksum_set_bits(dtr,
VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
vxge_hw_fifo_txdl_post(fifo_hw, dtr);
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
dev->name, __func__, __LINE__);
return NETDEV_TX_OK;
_exit2:
vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
_exit1:
j = 0;
frag = &skb_shinfo(skb)->frags[0];
dma_unmap_single(&fifo->pdev->dev, txdl_priv->dma_buffers[j++],
skb_headlen(skb), DMA_TO_DEVICE);
for (; j < i; j++) {
dma_unmap_page(&fifo->pdev->dev, txdl_priv->dma_buffers[j],
skb_frag_size(frag), DMA_TO_DEVICE);
frag += 1;
}
vxge_hw_fifo_txdl_free(fifo_hw, dtr);
_exit0:
netif_tx_stop_queue(fifo->txq);
dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
}
/*
* vxge_rx_term
*