forked from freebsd/freebsd-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
if_ixv.c
1931 lines (1644 loc) · 60.5 KB
/
if_ixv.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
/******************************************************************************
Copyright (c) 2001-2017, Intel Corporation
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
/*$FreeBSD$*/
#include "opt_inet.h"
#include "opt_inet6.h"
#include "ixgbe.h"
#include "ifdi_if.h"
#include <net/netmap.h>
#include <dev/netmap/netmap_kern.h>
/************************************************************************
* Driver version
************************************************************************/
char ixv_driver_version[] = "2.0.1-k";
/************************************************************************
* PCI Device ID Table
*
* Used by probe to select devices to load on
* Last field stores an index into ixv_strings
* Last entry must be all 0s
*
* { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index }
************************************************************************/
static pci_vendor_info_t ixv_vendor_info_array[] =
{
PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_VF, "Intel(R) PRO/10GbE Virtual Function Network Driver"),
PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540_VF, "Intel(R) PRO/10GbE Virtual Function Network Driver"),
PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550_VF, "Intel(R) PRO/10GbE Virtual Function Network Driver"),
PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_VF, "Intel(R) PRO/10GbE Virtual Function Network Driver"),
PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_VF, "Intel(R) PRO/10GbE Virtual Function Network Driver"),
/* required last entry */
PVID_END
};
/************************************************************************
* Function prototypes
************************************************************************/
static void *ixv_register(device_t dev);
static int ixv_if_attach_pre(if_ctx_t ctx);
static int ixv_if_attach_post(if_ctx_t ctx);
static int ixv_if_detach(if_ctx_t ctx);
static int ixv_if_rx_queue_intr_enable(if_ctx_t ctx, uint16_t qid);
static int ixv_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int nqs, int nqsets);
static int ixv_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int nqs, int nqsets);
static void ixv_if_queues_free(if_ctx_t ctx);
static void ixv_identify_hardware(if_ctx_t ctx);
static void ixv_init_device_features(struct adapter *);
static int ixv_allocate_pci_resources(if_ctx_t ctx);
static void ixv_free_pci_resources(if_ctx_t ctx);
static int ixv_setup_interface(if_ctx_t ctx);
static void ixv_if_media_status(if_ctx_t , struct ifmediareq *);
static int ixv_if_media_change(if_ctx_t ctx);
static void ixv_if_update_admin_status(if_ctx_t ctx);
static int ixv_if_msix_intr_assign(if_ctx_t ctx, int msix);
static int ixv_if_mtu_set(if_ctx_t ctx, uint32_t mtu);
static void ixv_if_init(if_ctx_t ctx);
static void ixv_if_local_timer(if_ctx_t ctx, uint16_t qid);
static void ixv_if_stop(if_ctx_t ctx);
static int ixv_negotiate_api(struct adapter *);
static void ixv_initialize_transmit_units(if_ctx_t ctx);
static void ixv_initialize_receive_units(if_ctx_t ctx);
static void ixv_initialize_rss_mapping(struct adapter *);
static void ixv_setup_vlan_support(if_ctx_t ctx);
static void ixv_configure_ivars(struct adapter *);
static void ixv_if_enable_intr(if_ctx_t ctx);
static void ixv_if_disable_intr(if_ctx_t ctx);
static void ixv_if_multi_set(if_ctx_t ctx);
static void ixv_if_register_vlan(if_ctx_t, u16);
static void ixv_if_unregister_vlan(if_ctx_t, u16);
static uint64_t ixv_if_get_counter(if_ctx_t, ift_counter);
static void ixv_save_stats(struct adapter *);
static void ixv_init_stats(struct adapter *);
static void ixv_update_stats(struct adapter *);
static void ixv_add_stats_sysctls(struct adapter *adapter);
static int ixv_sysctl_debug(SYSCTL_HANDLER_ARGS);
static void ixv_set_ivar(struct adapter *, u8, u8, s8);
static u8 *ixv_mc_array_itr(struct ixgbe_hw *, u8 **, u32 *);
/* The MSI-X Interrupt handlers */
static int ixv_msix_que(void *);
static int ixv_msix_mbx(void *);
/************************************************************************
* FreeBSD Device Interface Entry Points
************************************************************************/
static device_method_t ixv_methods[] = {
/* Device interface */
DEVMETHOD(device_register, ixv_register),
DEVMETHOD(device_probe, iflib_device_probe),
DEVMETHOD(device_attach, iflib_device_attach),
DEVMETHOD(device_detach, iflib_device_detach),
DEVMETHOD(device_shutdown, iflib_device_shutdown),
DEVMETHOD_END
};
static driver_t ixv_driver = {
"ixv", ixv_methods, sizeof(struct adapter),
};
devclass_t ixv_devclass;
DRIVER_MODULE(ixv, pci, ixv_driver, ixv_devclass, 0, 0);
MODULE_PNP_INFO("U16:vendor;U16:device", pci, ixv, ixv_vendor_info_array,
nitems(ixv_vendor_info_array) - 1);
MODULE_DEPEND(ixv, pci, 1, 1, 1);
MODULE_DEPEND(ixv, ether, 1, 1, 1);
#ifdef DEV_NETMAP
MODULE_DEPEND(ixv, netmap, 1, 1, 1);
#endif /* DEV_NETMAP */
static device_method_t ixv_if_methods[] = {
DEVMETHOD(ifdi_attach_pre, ixv_if_attach_pre),
DEVMETHOD(ifdi_attach_post, ixv_if_attach_post),
DEVMETHOD(ifdi_detach, ixv_if_detach),
DEVMETHOD(ifdi_init, ixv_if_init),
DEVMETHOD(ifdi_stop, ixv_if_stop),
DEVMETHOD(ifdi_msix_intr_assign, ixv_if_msix_intr_assign),
DEVMETHOD(ifdi_intr_enable, ixv_if_enable_intr),
DEVMETHOD(ifdi_intr_disable, ixv_if_disable_intr),
DEVMETHOD(ifdi_tx_queue_intr_enable, ixv_if_rx_queue_intr_enable),
DEVMETHOD(ifdi_rx_queue_intr_enable, ixv_if_rx_queue_intr_enable),
DEVMETHOD(ifdi_tx_queues_alloc, ixv_if_tx_queues_alloc),
DEVMETHOD(ifdi_rx_queues_alloc, ixv_if_rx_queues_alloc),
DEVMETHOD(ifdi_queues_free, ixv_if_queues_free),
DEVMETHOD(ifdi_update_admin_status, ixv_if_update_admin_status),
DEVMETHOD(ifdi_multi_set, ixv_if_multi_set),
DEVMETHOD(ifdi_mtu_set, ixv_if_mtu_set),
DEVMETHOD(ifdi_media_status, ixv_if_media_status),
DEVMETHOD(ifdi_media_change, ixv_if_media_change),
DEVMETHOD(ifdi_timer, ixv_if_local_timer),
DEVMETHOD(ifdi_vlan_register, ixv_if_register_vlan),
DEVMETHOD(ifdi_vlan_unregister, ixv_if_unregister_vlan),
DEVMETHOD(ifdi_get_counter, ixv_if_get_counter),
DEVMETHOD_END
};
static driver_t ixv_if_driver = {
"ixv_if", ixv_if_methods, sizeof(struct adapter)
};
/*
* TUNEABLE PARAMETERS:
*/
/* Flow control setting, default to full */
static int ixv_flow_control = ixgbe_fc_full;
TUNABLE_INT("hw.ixv.flow_control", &ixv_flow_control);
/*
* Header split: this causes the hardware to DMA
* the header into a separate mbuf from the payload,
* it can be a performance win in some workloads, but
* in others it actually hurts, its off by default.
*/
static int ixv_header_split = FALSE;
TUNABLE_INT("hw.ixv.hdr_split", &ixv_header_split);
/*
* Shadow VFTA table, this is needed because
* the real filter table gets cleared during
* a soft reset and we need to repopulate it.
*/
static u32 ixv_shadow_vfta[IXGBE_VFTA_SIZE];
extern struct if_txrx ixgbe_txrx;
static struct if_shared_ctx ixv_sctx_init = {
.isc_magic = IFLIB_MAGIC,
.isc_q_align = PAGE_SIZE,/* max(DBA_ALIGN, PAGE_SIZE) */
.isc_tx_maxsize = IXGBE_TSO_SIZE + sizeof(struct ether_vlan_header),
.isc_tx_maxsegsize = PAGE_SIZE,
.isc_tso_maxsize = IXGBE_TSO_SIZE + sizeof(struct ether_vlan_header),
.isc_tso_maxsegsize = PAGE_SIZE,
.isc_rx_maxsize = MJUM16BYTES,
.isc_rx_nsegments = 1,
.isc_rx_maxsegsize = MJUM16BYTES,
.isc_nfl = 1,
.isc_ntxqs = 1,
.isc_nrxqs = 1,
.isc_admin_intrcnt = 1,
.isc_vendor_info = ixv_vendor_info_array,
.isc_driver_version = ixv_driver_version,
.isc_driver = &ixv_if_driver,
.isc_nrxd_min = {MIN_RXD},
.isc_ntxd_min = {MIN_TXD},
.isc_nrxd_max = {MAX_RXD},
.isc_ntxd_max = {MAX_TXD},
.isc_nrxd_default = {DEFAULT_RXD},
.isc_ntxd_default = {DEFAULT_TXD},
};
if_shared_ctx_t ixv_sctx = &ixv_sctx_init;
static void *
ixv_register(device_t dev)
{
return (ixv_sctx);
}
/************************************************************************
* ixv_if_tx_queues_alloc
************************************************************************/
static int
ixv_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs,
int ntxqs, int ntxqsets)
{
struct adapter *adapter = iflib_get_softc(ctx);
if_softc_ctx_t scctx = adapter->shared;
struct ix_tx_queue *que;
int i, j, error;
MPASS(adapter->num_tx_queues == ntxqsets);
MPASS(ntxqs == 1);
/* Allocate queue structure memory */
adapter->tx_queues =
(struct ix_tx_queue *)malloc(sizeof(struct ix_tx_queue) * ntxqsets,
M_DEVBUF, M_NOWAIT | M_ZERO);
if (!adapter->tx_queues) {
device_printf(iflib_get_dev(ctx),
"Unable to allocate TX ring memory\n");
return (ENOMEM);
}
for (i = 0, que = adapter->tx_queues; i < ntxqsets; i++, que++) {
struct tx_ring *txr = &que->txr;
txr->me = i;
txr->adapter = que->adapter = adapter;
adapter->active_queues |= (u64)1 << txr->me;
/* Allocate report status array */
if (!(txr->tx_rsq = (qidx_t *)malloc(sizeof(qidx_t) * scctx->isc_ntxd[0], M_DEVBUF, M_NOWAIT | M_ZERO))) {
error = ENOMEM;
goto fail;
}
for (j = 0; j < scctx->isc_ntxd[0]; j++)
txr->tx_rsq[j] = QIDX_INVALID;
/* get the virtual and physical address of the hardware queues */
txr->tail = IXGBE_VFTDT(txr->me);
txr->tx_base = (union ixgbe_adv_tx_desc *)vaddrs[i*ntxqs];
txr->tx_paddr = paddrs[i*ntxqs];
txr->bytes = 0;
txr->total_packets = 0;
}
device_printf(iflib_get_dev(ctx), "allocated for %d queues\n",
adapter->num_tx_queues);
return (0);
fail:
ixv_if_queues_free(ctx);
return (error);
} /* ixv_if_tx_queues_alloc */
/************************************************************************
* ixv_if_rx_queues_alloc
************************************************************************/
static int
ixv_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs,
int nrxqs, int nrxqsets)
{
struct adapter *adapter = iflib_get_softc(ctx);
struct ix_rx_queue *que;
int i, error;
MPASS(adapter->num_rx_queues == nrxqsets);
MPASS(nrxqs == 1);
/* Allocate queue structure memory */
adapter->rx_queues =
(struct ix_rx_queue *)malloc(sizeof(struct ix_rx_queue) * nrxqsets,
M_DEVBUF, M_NOWAIT | M_ZERO);
if (!adapter->rx_queues) {
device_printf(iflib_get_dev(ctx),
"Unable to allocate TX ring memory\n");
error = ENOMEM;
goto fail;
}
for (i = 0, que = adapter->rx_queues; i < nrxqsets; i++, que++) {
struct rx_ring *rxr = &que->rxr;
rxr->me = i;
rxr->adapter = que->adapter = adapter;
/* get the virtual and physical address of the hw queues */
rxr->tail = IXGBE_VFRDT(rxr->me);
rxr->rx_base = (union ixgbe_adv_rx_desc *)vaddrs[i];
rxr->rx_paddr = paddrs[i*nrxqs];
rxr->bytes = 0;
rxr->que = que;
}
device_printf(iflib_get_dev(ctx), "allocated for %d rx queues\n",
adapter->num_rx_queues);
return (0);
fail:
ixv_if_queues_free(ctx);
return (error);
} /* ixv_if_rx_queues_alloc */
/************************************************************************
* ixv_if_queues_free
************************************************************************/
static void
ixv_if_queues_free(if_ctx_t ctx)
{
struct adapter *adapter = iflib_get_softc(ctx);
struct ix_tx_queue *que = adapter->tx_queues;
int i;
if (que == NULL)
goto free;
for (i = 0; i < adapter->num_tx_queues; i++, que++) {
struct tx_ring *txr = &que->txr;
if (txr->tx_rsq == NULL)
break;
free(txr->tx_rsq, M_DEVBUF);
txr->tx_rsq = NULL;
}
if (adapter->tx_queues != NULL)
free(adapter->tx_queues, M_DEVBUF);
free:
if (adapter->rx_queues != NULL)
free(adapter->rx_queues, M_DEVBUF);
adapter->tx_queues = NULL;
adapter->rx_queues = NULL;
} /* ixv_if_queues_free */
/************************************************************************
* ixv_if_attach_pre - Device initialization routine
*
* Called when the driver is being loaded.
* Identifies the type of hardware, allocates all resources
* and initializes the hardware.
*
* return 0 on success, positive on failure
************************************************************************/
static int
ixv_if_attach_pre(if_ctx_t ctx)
{
struct adapter *adapter;
device_t dev;
if_softc_ctx_t scctx;
struct ixgbe_hw *hw;
int error = 0;
INIT_DEBUGOUT("ixv_attach: begin");
/* Allocate, clear, and link in our adapter structure */
dev = iflib_get_dev(ctx);
adapter = iflib_get_softc(ctx);
adapter->dev = dev;
adapter->ctx = ctx;
adapter->hw.back = adapter;
scctx = adapter->shared = iflib_get_softc_ctx(ctx);
adapter->media = iflib_get_media(ctx);
hw = &adapter->hw;
/* Do base PCI setup - map BAR0 */
if (ixv_allocate_pci_resources(ctx)) {
device_printf(dev, "ixv_allocate_pci_resources() failed!\n");
error = ENXIO;
goto err_out;
}
/* SYSCTL APIs */
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "debug",
CTLTYPE_INT | CTLFLAG_RW, adapter, 0, ixv_sysctl_debug, "I",
"Debug Info");
/* Determine hardware revision */
ixv_identify_hardware(ctx);
ixv_init_device_features(adapter);
/* Initialize the shared code */
error = ixgbe_init_ops_vf(hw);
if (error) {
device_printf(dev, "ixgbe_init_ops_vf() failed!\n");
error = EIO;
goto err_out;
}
/* Setup the mailbox */
ixgbe_init_mbx_params_vf(hw);
error = hw->mac.ops.reset_hw(hw);
if (error == IXGBE_ERR_RESET_FAILED)
device_printf(dev, "...reset_hw() failure: Reset Failed!\n");
else if (error)
device_printf(dev, "...reset_hw() failed with error %d\n",
error);
if (error) {
error = EIO;
goto err_out;
}
error = hw->mac.ops.init_hw(hw);
if (error) {
device_printf(dev, "...init_hw() failed with error %d\n",
error);
error = EIO;
goto err_out;
}
/* Negotiate mailbox API version */
error = ixv_negotiate_api(adapter);
if (error) {
device_printf(dev,
"Mailbox API negotiation failed during attach!\n");
goto err_out;
}
/* If no mac address was assigned, make a random one */
if (!ixv_check_ether_addr(hw->mac.addr)) {
u8 addr[ETHER_ADDR_LEN];
arc4rand(&addr, sizeof(addr), 0);
addr[0] &= 0xFE;
addr[0] |= 0x02;
bcopy(addr, hw->mac.addr, sizeof(addr));
bcopy(addr, hw->mac.perm_addr, sizeof(addr));
}
/* Most of the iflib initialization... */
iflib_set_mac(ctx, hw->mac.addr);
switch (adapter->hw.mac.type) {
case ixgbe_mac_X550_vf:
case ixgbe_mac_X550EM_x_vf:
case ixgbe_mac_X550EM_a_vf:
scctx->isc_ntxqsets_max = scctx->isc_nrxqsets_max = 2;
break;
default:
scctx->isc_ntxqsets_max = scctx->isc_nrxqsets_max = 1;
}
scctx->isc_txqsizes[0] =
roundup2(scctx->isc_ntxd[0] * sizeof(union ixgbe_adv_tx_desc) +
sizeof(u32), DBA_ALIGN);
scctx->isc_rxqsizes[0] =
roundup2(scctx->isc_nrxd[0] * sizeof(union ixgbe_adv_rx_desc),
DBA_ALIGN);
/* XXX */
scctx->isc_tx_csum_flags = CSUM_IP | CSUM_TCP | CSUM_UDP | CSUM_TSO |
CSUM_IP6_TCP | CSUM_IP6_UDP | CSUM_IP6_TSO;
scctx->isc_tx_nsegments = IXGBE_82599_SCATTER;
scctx->isc_msix_bar = PCIR_BAR(MSIX_82598_BAR);
scctx->isc_tx_tso_segments_max = scctx->isc_tx_nsegments;
scctx->isc_tx_tso_size_max = IXGBE_TSO_SIZE;
scctx->isc_tx_tso_segsize_max = PAGE_SIZE;
scctx->isc_txrx = &ixgbe_txrx;
/*
* Tell the upper layer(s) we support everything the PF
* driver does except...
* Wake-on-LAN
*/
scctx->isc_capabilities = IXGBE_CAPS;
scctx->isc_capabilities ^= IFCAP_WOL;
scctx->isc_capenable = scctx->isc_capabilities;
INIT_DEBUGOUT("ixv_if_attach_pre: end");
return (0);
err_out:
ixv_free_pci_resources(ctx);
return (error);
} /* ixv_if_attach_pre */
static int
ixv_if_attach_post(if_ctx_t ctx)
{
struct adapter *adapter = iflib_get_softc(ctx);
device_t dev = iflib_get_dev(ctx);
int error = 0;
/* Setup OS specific network interface */
error = ixv_setup_interface(ctx);
if (error) {
device_printf(dev, "Interface setup failed: %d\n", error);
goto end;
}
/* Do the stats setup */
ixv_save_stats(adapter);
ixv_init_stats(adapter);
ixv_add_stats_sysctls(adapter);
end:
return error;
} /* ixv_if_attach_post */
/************************************************************************
* ixv_detach - Device removal routine
*
* Called when the driver is being removed.
* Stops the adapter and deallocates all the resources
* that were allocated for driver operation.
*
* return 0 on success, positive on failure
************************************************************************/
static int
ixv_if_detach(if_ctx_t ctx)
{
INIT_DEBUGOUT("ixv_detach: begin");
ixv_free_pci_resources(ctx);
return (0);
} /* ixv_if_detach */
/************************************************************************
* ixv_if_mtu_set
************************************************************************/
static int
ixv_if_mtu_set(if_ctx_t ctx, uint32_t mtu)
{
struct adapter *adapter = iflib_get_softc(ctx);
struct ifnet *ifp = iflib_get_ifp(ctx);
int error = 0;
IOCTL_DEBUGOUT("ioctl: SIOCSIFMTU (Set Interface MTU)");
if (mtu > IXGBE_MAX_FRAME_SIZE - IXGBE_MTU_HDR) {
error = EINVAL;
} else {
ifp->if_mtu = mtu;
adapter->max_frame_size = ifp->if_mtu + IXGBE_MTU_HDR;
}
return error;
} /* ixv_if_mtu_set */
/************************************************************************
* ixv_if_init - Init entry point
*
* Used in two ways: It is used by the stack as an init entry
* point in network interface structure. It is also used
* by the driver as a hw/sw initialization routine to get
* to a consistent state.
*
* return 0 on success, positive on failure
************************************************************************/
static void
ixv_if_init(if_ctx_t ctx)
{
struct adapter *adapter = iflib_get_softc(ctx);
struct ifnet *ifp = iflib_get_ifp(ctx);
device_t dev = iflib_get_dev(ctx);
struct ixgbe_hw *hw = &adapter->hw;
int error = 0;
INIT_DEBUGOUT("ixv_if_init: begin");
hw->adapter_stopped = FALSE;
hw->mac.ops.stop_adapter(hw);
/* reprogram the RAR[0] in case user changed it. */
hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
/* Get the latest mac address, User can use a LAA */
bcopy(IF_LLADDR(ifp), hw->mac.addr, IXGBE_ETH_LENGTH_OF_ADDRESS);
hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, 1);
/* Reset VF and renegotiate mailbox API version */
hw->mac.ops.reset_hw(hw);
hw->mac.ops.start_hw(hw);
error = ixv_negotiate_api(adapter);
if (error) {
device_printf(dev,
"Mailbox API negotiation failed in if_init!\n");
return;
}
ixv_initialize_transmit_units(ctx);
/* Setup Multicast table */
ixv_if_multi_set(ctx);
/*
* Determine the correct mbuf pool
* for doing jumbo/headersplit
*/
if (ifp->if_mtu > ETHERMTU)
adapter->rx_mbuf_sz = MJUMPAGESIZE;
else
adapter->rx_mbuf_sz = MCLBYTES;
/* Configure RX settings */
ixv_initialize_receive_units(ctx);
/* Set up VLAN offload and filter */
ixv_setup_vlan_support(ctx);
/* Set up MSI-X routing */
ixv_configure_ivars(adapter);
/* Set up auto-mask */
IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, IXGBE_EICS_RTX_QUEUE);
/* Set moderation on the Link interrupt */
IXGBE_WRITE_REG(hw, IXGBE_VTEITR(adapter->vector), IXGBE_LINK_ITR);
/* Stats init */
ixv_init_stats(adapter);
/* Config/Enable Link */
hw->mac.ops.check_link(hw, &adapter->link_speed, &adapter->link_up,
FALSE);
/* And now turn on interrupts */
ixv_if_enable_intr(ctx);
return;
} /* ixv_if_init */
/************************************************************************
* ixv_enable_queue
************************************************************************/
static inline void
ixv_enable_queue(struct adapter *adapter, u32 vector)
{
struct ixgbe_hw *hw = &adapter->hw;
u32 queue = 1 << vector;
u32 mask;
mask = (IXGBE_EIMS_RTX_QUEUE & queue);
IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
} /* ixv_enable_queue */
/************************************************************************
* ixv_disable_queue
************************************************************************/
static inline void
ixv_disable_queue(struct adapter *adapter, u32 vector)
{
struct ixgbe_hw *hw = &adapter->hw;
u64 queue = (u64)(1 << vector);
u32 mask;
mask = (IXGBE_EIMS_RTX_QUEUE & queue);
IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, mask);
} /* ixv_disable_queue */
/************************************************************************
* ixv_msix_que - MSI-X Queue Interrupt Service routine
************************************************************************/
static int
ixv_msix_que(void *arg)
{
struct ix_rx_queue *que = arg;
struct adapter *adapter = que->adapter;
ixv_disable_queue(adapter, que->msix);
++que->irqs;
return (FILTER_SCHEDULE_THREAD);
} /* ixv_msix_que */
/************************************************************************
* ixv_msix_mbx
************************************************************************/
static int
ixv_msix_mbx(void *arg)
{
struct adapter *adapter = arg;
struct ixgbe_hw *hw = &adapter->hw;
u32 reg;
++adapter->link_irq;
/* First get the cause */
reg = IXGBE_READ_REG(hw, IXGBE_VTEICS);
/* Clear interrupt with write */
IXGBE_WRITE_REG(hw, IXGBE_VTEICR, reg);
/* Link status change */
if (reg & IXGBE_EICR_LSC)
iflib_admin_intr_deferred(adapter->ctx);
IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, IXGBE_EIMS_OTHER);
return (FILTER_HANDLED);
} /* ixv_msix_mbx */
/************************************************************************
* ixv_media_status - Media Ioctl callback
*
* Called whenever the user queries the status of
* the interface using ifconfig.
************************************************************************/
static void
ixv_if_media_status(if_ctx_t ctx, struct ifmediareq * ifmr)
{
struct adapter *adapter = iflib_get_softc(ctx);
INIT_DEBUGOUT("ixv_media_status: begin");
iflib_admin_intr_deferred(ctx);
ifmr->ifm_status = IFM_AVALID;
ifmr->ifm_active = IFM_ETHER;
if (!adapter->link_active)
return;
ifmr->ifm_status |= IFM_ACTIVE;
switch (adapter->link_speed) {
case IXGBE_LINK_SPEED_1GB_FULL:
ifmr->ifm_active |= IFM_1000_T | IFM_FDX;
break;
case IXGBE_LINK_SPEED_10GB_FULL:
ifmr->ifm_active |= IFM_10G_T | IFM_FDX;
break;
case IXGBE_LINK_SPEED_100_FULL:
ifmr->ifm_active |= IFM_100_TX | IFM_FDX;
break;
case IXGBE_LINK_SPEED_10_FULL:
ifmr->ifm_active |= IFM_10_T | IFM_FDX;
break;
}
} /* ixv_if_media_status */
/************************************************************************
* ixv_if_media_change - Media Ioctl callback
*
* Called when the user changes speed/duplex using
* media/mediopt option with ifconfig.
************************************************************************/
static int
ixv_if_media_change(if_ctx_t ctx)
{
struct adapter *adapter = iflib_get_softc(ctx);
struct ifmedia *ifm = iflib_get_media(ctx);
INIT_DEBUGOUT("ixv_media_change: begin");
if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
return (EINVAL);
switch (IFM_SUBTYPE(ifm->ifm_media)) {
case IFM_AUTO:
break;
default:
device_printf(adapter->dev, "Only auto media type\n");
return (EINVAL);
}
return (0);
} /* ixv_if_media_change */
/************************************************************************
* ixv_negotiate_api
*
* Negotiate the Mailbox API with the PF;
* start with the most featured API first.
************************************************************************/
static int
ixv_negotiate_api(struct adapter *adapter)
{
struct ixgbe_hw *hw = &adapter->hw;
int mbx_api[] = { ixgbe_mbox_api_11,
ixgbe_mbox_api_10,
ixgbe_mbox_api_unknown };
int i = 0;
while (mbx_api[i] != ixgbe_mbox_api_unknown) {
if (ixgbevf_negotiate_api_version(hw, mbx_api[i]) == 0)
return (0);
i++;
}
return (EINVAL);
} /* ixv_negotiate_api */
/************************************************************************
* ixv_if_multi_set - Multicast Update
*
* Called whenever multicast address list is updated.
************************************************************************/
static void
ixv_if_multi_set(if_ctx_t ctx)
{
u8 mta[MAX_NUM_MULTICAST_ADDRESSES * IXGBE_ETH_LENGTH_OF_ADDRESS];
struct adapter *adapter = iflib_get_softc(ctx);
u8 *update_ptr;
struct ifmultiaddr *ifma;
if_t ifp = iflib_get_ifp(ctx);
int mcnt = 0;
IOCTL_DEBUGOUT("ixv_if_multi_set: begin");
CK_STAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
&mta[mcnt * IXGBE_ETH_LENGTH_OF_ADDRESS],
IXGBE_ETH_LENGTH_OF_ADDRESS);
mcnt++;
}
update_ptr = mta;
adapter->hw.mac.ops.update_mc_addr_list(&adapter->hw, update_ptr, mcnt,
ixv_mc_array_itr, TRUE);
} /* ixv_if_multi_set */
/************************************************************************
* ixv_mc_array_itr
*
* An iterator function needed by the multicast shared code.
* It feeds the shared code routine the addresses in the
* array of ixv_set_multi() one by one.
************************************************************************/
static u8 *
ixv_mc_array_itr(struct ixgbe_hw *hw, u8 **update_ptr, u32 *vmdq)
{
u8 *addr = *update_ptr;
u8 *newptr;
*vmdq = 0;
newptr = addr + IXGBE_ETH_LENGTH_OF_ADDRESS;
*update_ptr = newptr;
return addr;
} /* ixv_mc_array_itr */
/************************************************************************
* ixv_if_local_timer - Timer routine
*
* Checks for link status, updates statistics,
* and runs the watchdog check.
************************************************************************/
static void
ixv_if_local_timer(if_ctx_t ctx, uint16_t qid)
{
if (qid != 0)
return;
/* Fire off the adminq task */
iflib_admin_intr_deferred(ctx);
} /* ixv_if_local_timer */
/************************************************************************
* ixv_if_update_admin_status - Update OS on link state
*
* Note: Only updates the OS on the cached link state.
* The real check of the hardware only happens with
* a link interrupt.
************************************************************************/
static void
ixv_if_update_admin_status(if_ctx_t ctx)
{
struct adapter *adapter = iflib_get_softc(ctx);
device_t dev = iflib_get_dev(ctx);
s32 status;
adapter->hw.mac.get_link_status = TRUE;
status = ixgbe_check_link(&adapter->hw, &adapter->link_speed,
&adapter->link_up, FALSE);
if (status != IXGBE_SUCCESS && adapter->hw.adapter_stopped == FALSE) {
/* Mailbox's Clear To Send status is lost or timeout occurred.
* We need reinitialization. */
iflib_get_ifp(ctx)->if_init(ctx);
}
if (adapter->link_up) {
if (adapter->link_active == FALSE) {
if (bootverbose)
device_printf(dev, "Link is up %d Gbps %s \n",
((adapter->link_speed == 128) ? 10 : 1),
"Full Duplex");
adapter->link_active = TRUE;
iflib_link_state_change(ctx, LINK_STATE_UP,
IF_Gbps(10));
}
} else { /* Link down */
if (adapter->link_active == TRUE) {
if (bootverbose)
device_printf(dev, "Link is Down\n");
iflib_link_state_change(ctx, LINK_STATE_DOWN, 0);
adapter->link_active = FALSE;
}
}
/* Stats Update */
ixv_update_stats(adapter);
} /* ixv_if_update_admin_status */
/************************************************************************
* ixv_if_stop - Stop the hardware
*
* Disables all traffic on the adapter by issuing a
* global reset on the MAC and deallocates TX/RX buffers.
************************************************************************/
static void
ixv_if_stop(if_ctx_t ctx)
{
struct adapter *adapter = iflib_get_softc(ctx);
struct ixgbe_hw *hw = &adapter->hw;
INIT_DEBUGOUT("ixv_stop: begin\n");
ixv_if_disable_intr(ctx);
hw->mac.ops.reset_hw(hw);
adapter->hw.adapter_stopped = FALSE;
hw->mac.ops.stop_adapter(hw);
/* Update the stack */
adapter->link_up = FALSE;
ixv_if_update_admin_status(ctx);
/* reprogram the RAR[0] in case user changed it. */
hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
} /* ixv_if_stop */
/************************************************************************
* ixv_identify_hardware - Determine hardware revision.
************************************************************************/
static void
ixv_identify_hardware(if_ctx_t ctx)
{
struct adapter *adapter = iflib_get_softc(ctx);
device_t dev = iflib_get_dev(ctx);
struct ixgbe_hw *hw = &adapter->hw;
/* Save off the information about this board */
hw->vendor_id = pci_get_vendor(dev);
hw->device_id = pci_get_device(dev);
hw->revision_id = pci_get_revid(dev);
hw->subsystem_vendor_id = pci_get_subvendor(dev);
hw->subsystem_device_id = pci_get_subdevice(dev);
/* A subset of set_mac_type */
switch (hw->device_id) {
case IXGBE_DEV_ID_82599_VF: