forked from torvalds/linux
/
cxgb4vf_main.c
2954 lines (2603 loc) · 77.7 KB
/
cxgb4vf_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 file is part of the Chelsio T4 PCI-E SR-IOV Virtual Function Ethernet
* driver for Linux.
*
* Copyright (c) 2009-2010 Chelsio Communications, Inc. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenIB.org BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - 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.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/pci.h>
#include <linux/dma-mapping.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/debugfs.h>
#include <linux/ethtool.h>
#include "t4vf_common.h"
#include "t4vf_defs.h"
#include "../cxgb4/t4_regs.h"
#include "../cxgb4/t4_msg.h"
/*
* Generic information about the driver.
*/
#define DRV_VERSION "1.0.0"
#define DRV_DESC "Chelsio T4 Virtual Function (VF) Network Driver"
/*
* Module Parameters.
* ==================
*/
/*
* Default ethtool "message level" for adapters.
*/
#define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \
NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\
NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
static int dflt_msg_enable = DFLT_MSG_ENABLE;
module_param(dflt_msg_enable, int, 0644);
MODULE_PARM_DESC(dflt_msg_enable,
"default adapter ethtool message level bitmap");
/*
* The driver uses the best interrupt scheme available on a platform in the
* order MSI-X then MSI. This parameter determines which of these schemes the
* driver may consider as follows:
*
* msi = 2: choose from among MSI-X and MSI
* msi = 1: only consider MSI interrupts
*
* Note that unlike the Physical Function driver, this Virtual Function driver
* does _not_ support legacy INTx interrupts (this limitation is mandated by
* the PCI-E SR-IOV standard).
*/
#define MSI_MSIX 2
#define MSI_MSI 1
#define MSI_DEFAULT MSI_MSIX
static int msi = MSI_DEFAULT;
module_param(msi, int, 0644);
MODULE_PARM_DESC(msi, "whether to use MSI-X or MSI");
/*
* Fundamental constants.
* ======================
*/
enum {
MAX_TXQ_ENTRIES = 16384,
MAX_RSPQ_ENTRIES = 16384,
MAX_RX_BUFFERS = 16384,
MIN_TXQ_ENTRIES = 32,
MIN_RSPQ_ENTRIES = 128,
MIN_FL_ENTRIES = 16,
/*
* For purposes of manipulating the Free List size we need to
* recognize that Free Lists are actually Egress Queues (the host
* produces free buffers which the hardware consumes), Egress Queues
* indices are all in units of Egress Context Units bytes, and free
* list entries are 64-bit PCI DMA addresses. And since the state of
* the Producer Index == the Consumer Index implies an EMPTY list, we
* always have at least one Egress Unit's worth of Free List entries
* unused. See sge.c for more details ...
*/
EQ_UNIT = SGE_EQ_IDXSIZE,
FL_PER_EQ_UNIT = EQ_UNIT / sizeof(__be64),
MIN_FL_RESID = FL_PER_EQ_UNIT,
};
/*
* Global driver state.
* ====================
*/
static struct dentry *cxgb4vf_debugfs_root;
/*
* OS "Callback" functions.
* ========================
*/
/*
* The link status has changed on the indicated "port" (Virtual Interface).
*/
void t4vf_os_link_changed(struct adapter *adapter, int pidx, int link_ok)
{
struct net_device *dev = adapter->port[pidx];
/*
* If the port is disabled or the current recorded "link up"
* status matches the new status, just return.
*/
if (!netif_running(dev) || link_ok == netif_carrier_ok(dev))
return;
/*
* Tell the OS that the link status has changed and print a short
* informative message on the console about the event.
*/
if (link_ok) {
const char *s;
const char *fc;
const struct port_info *pi = netdev_priv(dev);
netif_carrier_on(dev);
switch (pi->link_cfg.speed) {
case SPEED_10000:
s = "10Gbps";
break;
case SPEED_1000:
s = "1000Mbps";
break;
case SPEED_100:
s = "100Mbps";
break;
default:
s = "unknown";
break;
}
switch (pi->link_cfg.fc) {
case PAUSE_RX:
fc = "RX";
break;
case PAUSE_TX:
fc = "TX";
break;
case PAUSE_RX|PAUSE_TX:
fc = "RX/TX";
break;
default:
fc = "no";
break;
}
printk(KERN_INFO "%s: link up, %s, full-duplex, %s PAUSE\n",
dev->name, s, fc);
} else {
netif_carrier_off(dev);
printk(KERN_INFO "%s: link down\n", dev->name);
}
}
/*
* Net device operations.
* ======================
*/
/*
* Perform the MAC and PHY actions needed to enable a "port" (Virtual
* Interface).
*/
static int link_start(struct net_device *dev)
{
int ret;
struct port_info *pi = netdev_priv(dev);
/*
* We do not set address filters and promiscuity here, the stack does
* that step explicitly. Enable vlan accel.
*/
ret = t4vf_set_rxmode(pi->adapter, pi->viid, dev->mtu, -1, -1, -1, 1,
true);
if (ret == 0) {
ret = t4vf_change_mac(pi->adapter, pi->viid,
pi->xact_addr_filt, dev->dev_addr, true);
if (ret >= 0) {
pi->xact_addr_filt = ret;
ret = 0;
}
}
/*
* We don't need to actually "start the link" itself since the
* firmware will do that for us when the first Virtual Interface
* is enabled on a port.
*/
if (ret == 0)
ret = t4vf_enable_vi(pi->adapter, pi->viid, true, true);
return ret;
}
/*
* Name the MSI-X interrupts.
*/
static void name_msix_vecs(struct adapter *adapter)
{
int namelen = sizeof(adapter->msix_info[0].desc) - 1;
int pidx;
/*
* Firmware events.
*/
snprintf(adapter->msix_info[MSIX_FW].desc, namelen,
"%s-FWeventq", adapter->name);
adapter->msix_info[MSIX_FW].desc[namelen] = 0;
/*
* Ethernet queues.
*/
for_each_port(adapter, pidx) {
struct net_device *dev = adapter->port[pidx];
const struct port_info *pi = netdev_priv(dev);
int qs, msi;
for (qs = 0, msi = MSIX_IQFLINT; qs < pi->nqsets; qs++, msi++) {
snprintf(adapter->msix_info[msi].desc, namelen,
"%s-%d", dev->name, qs);
adapter->msix_info[msi].desc[namelen] = 0;
}
}
}
/*
* Request all of our MSI-X resources.
*/
static int request_msix_queue_irqs(struct adapter *adapter)
{
struct sge *s = &adapter->sge;
int rxq, msi, err;
/*
* Firmware events.
*/
err = request_irq(adapter->msix_info[MSIX_FW].vec, t4vf_sge_intr_msix,
0, adapter->msix_info[MSIX_FW].desc, &s->fw_evtq);
if (err)
return err;
/*
* Ethernet queues.
*/
msi = MSIX_IQFLINT;
for_each_ethrxq(s, rxq) {
err = request_irq(adapter->msix_info[msi].vec,
t4vf_sge_intr_msix, 0,
adapter->msix_info[msi].desc,
&s->ethrxq[rxq].rspq);
if (err)
goto err_free_irqs;
msi++;
}
return 0;
err_free_irqs:
while (--rxq >= 0)
free_irq(adapter->msix_info[--msi].vec, &s->ethrxq[rxq].rspq);
free_irq(adapter->msix_info[MSIX_FW].vec, &s->fw_evtq);
return err;
}
/*
* Free our MSI-X resources.
*/
static void free_msix_queue_irqs(struct adapter *adapter)
{
struct sge *s = &adapter->sge;
int rxq, msi;
free_irq(adapter->msix_info[MSIX_FW].vec, &s->fw_evtq);
msi = MSIX_IQFLINT;
for_each_ethrxq(s, rxq)
free_irq(adapter->msix_info[msi++].vec,
&s->ethrxq[rxq].rspq);
}
/*
* Turn on NAPI and start up interrupts on a response queue.
*/
static void qenable(struct sge_rspq *rspq)
{
napi_enable(&rspq->napi);
/*
* 0-increment the Going To Sleep register to start the timer and
* enable interrupts.
*/
t4_write_reg(rspq->adapter, T4VF_SGE_BASE_ADDR + SGE_VF_GTS,
CIDXINC(0) |
SEINTARM(rspq->intr_params) |
INGRESSQID(rspq->cntxt_id));
}
/*
* Enable NAPI scheduling and interrupt generation for all Receive Queues.
*/
static void enable_rx(struct adapter *adapter)
{
int rxq;
struct sge *s = &adapter->sge;
for_each_ethrxq(s, rxq)
qenable(&s->ethrxq[rxq].rspq);
qenable(&s->fw_evtq);
/*
* The interrupt queue doesn't use NAPI so we do the 0-increment of
* its Going To Sleep register here to get it started.
*/
if (adapter->flags & USING_MSI)
t4_write_reg(adapter, T4VF_SGE_BASE_ADDR + SGE_VF_GTS,
CIDXINC(0) |
SEINTARM(s->intrq.intr_params) |
INGRESSQID(s->intrq.cntxt_id));
}
/*
* Wait until all NAPI handlers are descheduled.
*/
static void quiesce_rx(struct adapter *adapter)
{
struct sge *s = &adapter->sge;
int rxq;
for_each_ethrxq(s, rxq)
napi_disable(&s->ethrxq[rxq].rspq.napi);
napi_disable(&s->fw_evtq.napi);
}
/*
* Response queue handler for the firmware event queue.
*/
static int fwevtq_handler(struct sge_rspq *rspq, const __be64 *rsp,
const struct pkt_gl *gl)
{
/*
* Extract response opcode and get pointer to CPL message body.
*/
struct adapter *adapter = rspq->adapter;
u8 opcode = ((const struct rss_header *)rsp)->opcode;
void *cpl = (void *)(rsp + 1);
switch (opcode) {
case CPL_FW6_MSG: {
/*
* We've received an asynchronous message from the firmware.
*/
const struct cpl_fw6_msg *fw_msg = cpl;
if (fw_msg->type == FW6_TYPE_CMD_RPL)
t4vf_handle_fw_rpl(adapter, fw_msg->data);
break;
}
case CPL_SGE_EGR_UPDATE: {
/*
* We've received an Egress Queue Status Update message. We
* get these, if the SGE is configured to send these when the
* firmware passes certain points in processing our TX
* Ethernet Queue or if we make an explicit request for one.
* We use these updates to determine when we may need to
* restart a TX Ethernet Queue which was stopped for lack of
* free TX Queue Descriptors ...
*/
const struct cpl_sge_egr_update *p = (void *)cpl;
unsigned int qid = EGR_QID(be32_to_cpu(p->opcode_qid));
struct sge *s = &adapter->sge;
struct sge_txq *tq;
struct sge_eth_txq *txq;
unsigned int eq_idx;
/*
* Perform sanity checking on the Queue ID to make sure it
* really refers to one of our TX Ethernet Egress Queues which
* is active and matches the queue's ID. None of these error
* conditions should ever happen so we may want to either make
* them fatal and/or conditionalized under DEBUG.
*/
eq_idx = EQ_IDX(s, qid);
if (unlikely(eq_idx >= MAX_EGRQ)) {
dev_err(adapter->pdev_dev,
"Egress Update QID %d out of range\n", qid);
break;
}
tq = s->egr_map[eq_idx];
if (unlikely(tq == NULL)) {
dev_err(adapter->pdev_dev,
"Egress Update QID %d TXQ=NULL\n", qid);
break;
}
txq = container_of(tq, struct sge_eth_txq, q);
if (unlikely(tq->abs_id != qid)) {
dev_err(adapter->pdev_dev,
"Egress Update QID %d refers to TXQ %d\n",
qid, tq->abs_id);
break;
}
/*
* Restart a stopped TX Queue which has less than half of its
* TX ring in use ...
*/
txq->q.restarts++;
netif_tx_wake_queue(txq->txq);
break;
}
default:
dev_err(adapter->pdev_dev,
"unexpected CPL %#x on FW event queue\n", opcode);
}
return 0;
}
/*
* Allocate SGE TX/RX response queues. Determine how many sets of SGE queues
* to use and initializes them. We support multiple "Queue Sets" per port if
* we have MSI-X, otherwise just one queue set per port.
*/
static int setup_sge_queues(struct adapter *adapter)
{
struct sge *s = &adapter->sge;
int err, pidx, msix;
/*
* Clear "Queue Set" Free List Starving and TX Queue Mapping Error
* state.
*/
bitmap_zero(s->starving_fl, MAX_EGRQ);
/*
* If we're using MSI interrupt mode we need to set up a "forwarded
* interrupt" queue which we'll set up with our MSI vector. The rest
* of the ingress queues will be set up to forward their interrupts to
* this queue ... This must be first since t4vf_sge_alloc_rxq() uses
* the intrq's queue ID as the interrupt forwarding queue for the
* subsequent calls ...
*/
if (adapter->flags & USING_MSI) {
err = t4vf_sge_alloc_rxq(adapter, &s->intrq, false,
adapter->port[0], 0, NULL, NULL);
if (err)
goto err_free_queues;
}
/*
* Allocate our ingress queue for asynchronous firmware messages.
*/
err = t4vf_sge_alloc_rxq(adapter, &s->fw_evtq, true, adapter->port[0],
MSIX_FW, NULL, fwevtq_handler);
if (err)
goto err_free_queues;
/*
* Allocate each "port"'s initial Queue Sets. These can be changed
* later on ... up to the point where any interface on the adapter is
* brought up at which point lots of things get nailed down
* permanently ...
*/
msix = MSIX_IQFLINT;
for_each_port(adapter, pidx) {
struct net_device *dev = adapter->port[pidx];
struct port_info *pi = netdev_priv(dev);
struct sge_eth_rxq *rxq = &s->ethrxq[pi->first_qset];
struct sge_eth_txq *txq = &s->ethtxq[pi->first_qset];
int qs;
for (qs = 0; qs < pi->nqsets; qs++, rxq++, txq++) {
err = t4vf_sge_alloc_rxq(adapter, &rxq->rspq, false,
dev, msix++,
&rxq->fl, t4vf_ethrx_handler);
if (err)
goto err_free_queues;
err = t4vf_sge_alloc_eth_txq(adapter, txq, dev,
netdev_get_tx_queue(dev, qs),
s->fw_evtq.cntxt_id);
if (err)
goto err_free_queues;
rxq->rspq.idx = qs;
memset(&rxq->stats, 0, sizeof(rxq->stats));
}
}
/*
* Create the reverse mappings for the queues.
*/
s->egr_base = s->ethtxq[0].q.abs_id - s->ethtxq[0].q.cntxt_id;
s->ingr_base = s->ethrxq[0].rspq.abs_id - s->ethrxq[0].rspq.cntxt_id;
IQ_MAP(s, s->fw_evtq.abs_id) = &s->fw_evtq;
for_each_port(adapter, pidx) {
struct net_device *dev = adapter->port[pidx];
struct port_info *pi = netdev_priv(dev);
struct sge_eth_rxq *rxq = &s->ethrxq[pi->first_qset];
struct sge_eth_txq *txq = &s->ethtxq[pi->first_qset];
int qs;
for (qs = 0; qs < pi->nqsets; qs++, rxq++, txq++) {
IQ_MAP(s, rxq->rspq.abs_id) = &rxq->rspq;
EQ_MAP(s, txq->q.abs_id) = &txq->q;
/*
* The FW_IQ_CMD doesn't return the Absolute Queue IDs
* for Free Lists but since all of the Egress Queues
* (including Free Lists) have Relative Queue IDs
* which are computed as Absolute - Base Queue ID, we
* can synthesize the Absolute Queue IDs for the Free
* Lists. This is useful for debugging purposes when
* we want to dump Queue Contexts via the PF Driver.
*/
rxq->fl.abs_id = rxq->fl.cntxt_id + s->egr_base;
EQ_MAP(s, rxq->fl.abs_id) = &rxq->fl;
}
}
return 0;
err_free_queues:
t4vf_free_sge_resources(adapter);
return err;
}
/*
* Set up Receive Side Scaling (RSS) to distribute packets to multiple receive
* queues. We configure the RSS CPU lookup table to distribute to the number
* of HW receive queues, and the response queue lookup table to narrow that
* down to the response queues actually configured for each "port" (Virtual
* Interface). We always configure the RSS mapping for all ports since the
* mapping table has plenty of entries.
*/
static int setup_rss(struct adapter *adapter)
{
int pidx;
for_each_port(adapter, pidx) {
struct port_info *pi = adap2pinfo(adapter, pidx);
struct sge_eth_rxq *rxq = &adapter->sge.ethrxq[pi->first_qset];
u16 rss[MAX_PORT_QSETS];
int qs, err;
for (qs = 0; qs < pi->nqsets; qs++)
rss[qs] = rxq[qs].rspq.abs_id;
err = t4vf_config_rss_range(adapter, pi->viid,
0, pi->rss_size, rss, pi->nqsets);
if (err)
return err;
/*
* Perform Global RSS Mode-specific initialization.
*/
switch (adapter->params.rss.mode) {
case FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL:
/*
* If Tunnel All Lookup isn't specified in the global
* RSS Configuration, then we need to specify a
* default Ingress Queue for any ingress packets which
* aren't hashed. We'll use our first ingress queue
* ...
*/
if (!adapter->params.rss.u.basicvirtual.tnlalllookup) {
union rss_vi_config config;
err = t4vf_read_rss_vi_config(adapter,
pi->viid,
&config);
if (err)
return err;
config.basicvirtual.defaultq =
rxq[0].rspq.abs_id;
err = t4vf_write_rss_vi_config(adapter,
pi->viid,
&config);
if (err)
return err;
}
break;
}
}
return 0;
}
/*
* Bring the adapter up. Called whenever we go from no "ports" open to having
* one open. This function performs the actions necessary to make an adapter
* operational, such as completing the initialization of HW modules, and
* enabling interrupts. Must be called with the rtnl lock held. (Note that
* this is called "cxgb_up" in the PF Driver.)
*/
static int adapter_up(struct adapter *adapter)
{
int err;
/*
* If this is the first time we've been called, perform basic
* adapter setup. Once we've done this, many of our adapter
* parameters can no longer be changed ...
*/
if ((adapter->flags & FULL_INIT_DONE) == 0) {
err = setup_sge_queues(adapter);
if (err)
return err;
err = setup_rss(adapter);
if (err) {
t4vf_free_sge_resources(adapter);
return err;
}
if (adapter->flags & USING_MSIX)
name_msix_vecs(adapter);
adapter->flags |= FULL_INIT_DONE;
}
/*
* Acquire our interrupt resources. We only support MSI-X and MSI.
*/
BUG_ON((adapter->flags & (USING_MSIX|USING_MSI)) == 0);
if (adapter->flags & USING_MSIX)
err = request_msix_queue_irqs(adapter);
else
err = request_irq(adapter->pdev->irq,
t4vf_intr_handler(adapter), 0,
adapter->name, adapter);
if (err) {
dev_err(adapter->pdev_dev, "request_irq failed, err %d\n",
err);
return err;
}
/*
* Enable NAPI ingress processing and return success.
*/
enable_rx(adapter);
t4vf_sge_start(adapter);
return 0;
}
/*
* Bring the adapter down. Called whenever the last "port" (Virtual
* Interface) closed. (Note that this routine is called "cxgb_down" in the PF
* Driver.)
*/
static void adapter_down(struct adapter *adapter)
{
/*
* Free interrupt resources.
*/
if (adapter->flags & USING_MSIX)
free_msix_queue_irqs(adapter);
else
free_irq(adapter->pdev->irq, adapter);
/*
* Wait for NAPI handlers to finish.
*/
quiesce_rx(adapter);
}
/*
* Start up a net device.
*/
static int cxgb4vf_open(struct net_device *dev)
{
int err;
struct port_info *pi = netdev_priv(dev);
struct adapter *adapter = pi->adapter;
/*
* If this is the first interface that we're opening on the "adapter",
* bring the "adapter" up now.
*/
if (adapter->open_device_map == 0) {
err = adapter_up(adapter);
if (err)
return err;
}
/*
* Note that this interface is up and start everything up ...
*/
netif_set_real_num_tx_queues(dev, pi->nqsets);
err = netif_set_real_num_rx_queues(dev, pi->nqsets);
if (err)
goto err_unwind;
err = link_start(dev);
if (err)
goto err_unwind;
netif_tx_start_all_queues(dev);
set_bit(pi->port_id, &adapter->open_device_map);
return 0;
err_unwind:
if (adapter->open_device_map == 0)
adapter_down(adapter);
return err;
}
/*
* Shut down a net device. This routine is called "cxgb_close" in the PF
* Driver ...
*/
static int cxgb4vf_stop(struct net_device *dev)
{
struct port_info *pi = netdev_priv(dev);
struct adapter *adapter = pi->adapter;
netif_tx_stop_all_queues(dev);
netif_carrier_off(dev);
t4vf_enable_vi(adapter, pi->viid, false, false);
pi->link_cfg.link_ok = 0;
clear_bit(pi->port_id, &adapter->open_device_map);
if (adapter->open_device_map == 0)
adapter_down(adapter);
return 0;
}
/*
* Translate our basic statistics into the standard "ifconfig" statistics.
*/
static struct net_device_stats *cxgb4vf_get_stats(struct net_device *dev)
{
struct t4vf_port_stats stats;
struct port_info *pi = netdev2pinfo(dev);
struct adapter *adapter = pi->adapter;
struct net_device_stats *ns = &dev->stats;
int err;
spin_lock(&adapter->stats_lock);
err = t4vf_get_port_stats(adapter, pi->pidx, &stats);
spin_unlock(&adapter->stats_lock);
memset(ns, 0, sizeof(*ns));
if (err)
return ns;
ns->tx_bytes = (stats.tx_bcast_bytes + stats.tx_mcast_bytes +
stats.tx_ucast_bytes + stats.tx_offload_bytes);
ns->tx_packets = (stats.tx_bcast_frames + stats.tx_mcast_frames +
stats.tx_ucast_frames + stats.tx_offload_frames);
ns->rx_bytes = (stats.rx_bcast_bytes + stats.rx_mcast_bytes +
stats.rx_ucast_bytes);
ns->rx_packets = (stats.rx_bcast_frames + stats.rx_mcast_frames +
stats.rx_ucast_frames);
ns->multicast = stats.rx_mcast_frames;
ns->tx_errors = stats.tx_drop_frames;
ns->rx_errors = stats.rx_err_frames;
return ns;
}
/*
* Collect up to maxaddrs worth of a netdevice's unicast addresses, starting
* at a specified offset within the list, into an array of addrss pointers and
* return the number collected.
*/
static inline unsigned int collect_netdev_uc_list_addrs(const struct net_device *dev,
const u8 **addr,
unsigned int offset,
unsigned int maxaddrs)
{
unsigned int index = 0;
unsigned int naddr = 0;
const struct netdev_hw_addr *ha;
for_each_dev_addr(dev, ha)
if (index++ >= offset) {
addr[naddr++] = ha->addr;
if (naddr >= maxaddrs)
break;
}
return naddr;
}
/*
* Collect up to maxaddrs worth of a netdevice's multicast addresses, starting
* at a specified offset within the list, into an array of addrss pointers and
* return the number collected.
*/
static inline unsigned int collect_netdev_mc_list_addrs(const struct net_device *dev,
const u8 **addr,
unsigned int offset,
unsigned int maxaddrs)
{
unsigned int index = 0;
unsigned int naddr = 0;
const struct netdev_hw_addr *ha;
netdev_for_each_mc_addr(ha, dev)
if (index++ >= offset) {
addr[naddr++] = ha->addr;
if (naddr >= maxaddrs)
break;
}
return naddr;
}
/*
* Configure the exact and hash address filters to handle a port's multicast
* and secondary unicast MAC addresses.
*/
static int set_addr_filters(const struct net_device *dev, bool sleep)
{
u64 mhash = 0;
u64 uhash = 0;
bool free = true;
unsigned int offset, naddr;
const u8 *addr[7];
int ret;
const struct port_info *pi = netdev_priv(dev);
/* first do the secondary unicast addresses */
for (offset = 0; ; offset += naddr) {
naddr = collect_netdev_uc_list_addrs(dev, addr, offset,
ARRAY_SIZE(addr));
if (naddr == 0)
break;
ret = t4vf_alloc_mac_filt(pi->adapter, pi->viid, free,
naddr, addr, NULL, &uhash, sleep);
if (ret < 0)
return ret;
free = false;
}
/* next set up the multicast addresses */
for (offset = 0; ; offset += naddr) {
naddr = collect_netdev_mc_list_addrs(dev, addr, offset,
ARRAY_SIZE(addr));
if (naddr == 0)
break;
ret = t4vf_alloc_mac_filt(pi->adapter, pi->viid, free,
naddr, addr, NULL, &mhash, sleep);
if (ret < 0)
return ret;
free = false;
}
return t4vf_set_addr_hash(pi->adapter, pi->viid, uhash != 0,
uhash | mhash, sleep);
}
/*
* Set RX properties of a port, such as promiscruity, address filters, and MTU.
* If @mtu is -1 it is left unchanged.
*/
static int set_rxmode(struct net_device *dev, int mtu, bool sleep_ok)
{
int ret;
struct port_info *pi = netdev_priv(dev);
ret = set_addr_filters(dev, sleep_ok);
if (ret == 0)
ret = t4vf_set_rxmode(pi->adapter, pi->viid, -1,
(dev->flags & IFF_PROMISC) != 0,
(dev->flags & IFF_ALLMULTI) != 0,
1, -1, sleep_ok);
return ret;
}
/*
* Set the current receive modes on the device.
*/
static void cxgb4vf_set_rxmode(struct net_device *dev)
{
/* unfortunately we can't return errors to the stack */
set_rxmode(dev, -1, false);
}
/*
* Find the entry in the interrupt holdoff timer value array which comes
* closest to the specified interrupt holdoff value.
*/
static int closest_timer(const struct sge *s, int us)
{
int i, timer_idx = 0, min_delta = INT_MAX;
for (i = 0; i < ARRAY_SIZE(s->timer_val); i++) {
int delta = us - s->timer_val[i];
if (delta < 0)
delta = -delta;
if (delta < min_delta) {
min_delta = delta;
timer_idx = i;
}
}
return timer_idx;
}
static int closest_thres(const struct sge *s, int thres)
{
int i, delta, pktcnt_idx = 0, min_delta = INT_MAX;
for (i = 0; i < ARRAY_SIZE(s->counter_val); i++) {
delta = thres - s->counter_val[i];
if (delta < 0)
delta = -delta;
if (delta < min_delta) {
min_delta = delta;
pktcnt_idx = i;
}
}
return pktcnt_idx;
}
/*
* Return a queue's interrupt hold-off time in us. 0 means no timer.
*/
static unsigned int qtimer_val(const struct adapter *adapter,
const struct sge_rspq *rspq)
{
unsigned int timer_idx = QINTR_TIMER_IDX_GET(rspq->intr_params);
return timer_idx < SGE_NTIMERS
? adapter->sge.timer_val[timer_idx]
: 0;
}
/**
* set_rxq_intr_params - set a queue's interrupt holdoff parameters
* @adapter: the adapter
* @rspq: the RX response queue
* @us: the hold-off time in us, or 0 to disable timer
* @cnt: the hold-off packet count, or 0 to disable counter
*
* Sets an RX response queue's interrupt hold-off time and packet count.
* At least one of the two needs to be enabled for the queue to generate
* interrupts.
*/
static int set_rxq_intr_params(struct adapter *adapter, struct sge_rspq *rspq,
unsigned int us, unsigned int cnt)
{
unsigned int timer_idx;
/*
* If both the interrupt holdoff timer and count are specified as
* zero, default to a holdoff count of 1 ...
*/
if ((us | cnt) == 0)
cnt = 1;