20
20
#define DRV_NAME "thunder-nic"
21
21
#define DRV_VERSION "1.0"
22
22
23
+ struct hw_info {
24
+ u8 bgx_cnt ;
25
+ u8 chans_per_lmac ;
26
+ u8 chans_per_bgx ; /* Rx/Tx chans */
27
+ u16 cpi_cnt ;
28
+ u16 rssi_cnt ;
29
+ u16 rss_ind_tbl_size ;
30
+ u16 tl4_cnt ;
31
+ u16 tl3_cnt ;
32
+ u8 tl2_cnt ;
33
+ u8 tl1_cnt ;
34
+ bool tl1_per_bgx ; /* TL1 per BGX or per LMAC */
35
+ };
36
+
23
37
struct nicpf {
24
38
struct pci_dev * pdev ;
39
+ struct hw_info * hw ;
25
40
u8 node ;
26
41
unsigned int flags ;
27
42
u8 num_vf_en ; /* No of VF enabled */
@@ -44,7 +59,6 @@ struct nicpf {
44
59
u32 speed [MAX_LMAC ];
45
60
u16 cpi_base [MAX_NUM_VFS_SUPPORTED ];
46
61
u16 rssi_base [MAX_NUM_VFS_SUPPORTED ];
47
- u16 rss_ind_tbl_size ;
48
62
bool mbx_lock [MAX_NUM_VFS_SUPPORTED ];
49
63
50
64
/* MSI-X */
@@ -275,7 +289,7 @@ static void nic_set_lmac_vf_mapping(struct nicpf *nic)
275
289
276
290
nic -> num_vf_en = 0 ;
277
291
278
- for (bgx = 0 ; bgx < NIC_MAX_BGX ; bgx ++ ) {
292
+ for (bgx = 0 ; bgx < nic -> hw -> bgx_cnt ; bgx ++ ) {
279
293
if (!(bgx_map & (1 << bgx )))
280
294
continue ;
281
295
lmac_cnt = bgx_get_lmac_count (nic -> node , bgx );
@@ -298,6 +312,30 @@ static void nic_set_lmac_vf_mapping(struct nicpf *nic)
298
312
}
299
313
}
300
314
315
+ static void nic_get_hw_info (struct nicpf * nic )
316
+ {
317
+ u16 sdevid ;
318
+ struct hw_info * hw = nic -> hw ;
319
+
320
+ pci_read_config_word (nic -> pdev , PCI_SUBSYSTEM_ID , & sdevid );
321
+
322
+ switch (sdevid ) {
323
+ case PCI_SUBSYS_DEVID_88XX_NIC_PF :
324
+ hw -> bgx_cnt = MAX_BGX_PER_CN88XX ;
325
+ hw -> chans_per_lmac = 16 ;
326
+ hw -> chans_per_bgx = 128 ;
327
+ hw -> cpi_cnt = 2048 ;
328
+ hw -> rssi_cnt = 4096 ;
329
+ hw -> rss_ind_tbl_size = NIC_MAX_RSS_IDR_TBL_SIZE ;
330
+ hw -> tl3_cnt = 256 ;
331
+ hw -> tl2_cnt = 64 ;
332
+ hw -> tl1_cnt = 2 ;
333
+ hw -> tl1_per_bgx = true;
334
+ break ;
335
+ }
336
+ hw -> tl4_cnt = MAX_QUEUES_PER_QSET * pci_sriov_get_totalvfs (nic -> pdev );
337
+ }
338
+
301
339
#define BGX0_BLOCK 8
302
340
#define BGX1_BLOCK 9
303
341
@@ -306,6 +344,9 @@ static void nic_init_hw(struct nicpf *nic)
306
344
int i ;
307
345
u64 cqm_cfg ;
308
346
347
+ /* Get HW capability info */
348
+ nic_get_hw_info (nic );
349
+
309
350
/* Enable NIC HW block */
310
351
nic_reg_write (nic , NIC_PF_CFG , 0x3 );
311
352
@@ -351,6 +392,7 @@ static void nic_init_hw(struct nicpf *nic)
351
392
/* Channel parse index configuration */
352
393
static void nic_config_cpi (struct nicpf * nic , struct cpi_cfg_msg * cfg )
353
394
{
395
+ struct hw_info * hw = nic -> hw ;
354
396
u32 vnic , bgx , lmac , chan ;
355
397
u32 padd , cpi_count = 0 ;
356
398
u64 cpi_base , cpi , rssi_base , rssi ;
@@ -360,9 +402,11 @@ static void nic_config_cpi(struct nicpf *nic, struct cpi_cfg_msg *cfg)
360
402
bgx = NIC_GET_BGX_FROM_VF_LMAC_MAP (nic -> vf_lmac_map [vnic ]);
361
403
lmac = NIC_GET_LMAC_FROM_VF_LMAC_MAP (nic -> vf_lmac_map [vnic ]);
362
404
363
- chan = (lmac * MAX_BGX_CHANS_PER_LMAC ) + (bgx * NIC_CHANS_PER_INF );
364
- cpi_base = (lmac * NIC_MAX_CPI_PER_LMAC ) + (bgx * NIC_CPI_PER_BGX );
365
- rssi_base = (lmac * nic -> rss_ind_tbl_size ) + (bgx * NIC_RSSI_PER_BGX );
405
+ chan = (lmac * hw -> chans_per_lmac ) + (bgx * hw -> chans_per_bgx );
406
+ cpi_base = (lmac * NIC_MAX_CPI_PER_LMAC ) +
407
+ (bgx * (hw -> cpi_cnt / hw -> bgx_cnt ));
408
+ rssi_base = (lmac * hw -> rss_ind_tbl_size ) +
409
+ (bgx * (hw -> rssi_cnt / hw -> bgx_cnt ));
366
410
367
411
/* Rx channel configuration */
368
412
nic_reg_write (nic , NIC_PF_CHAN_0_255_RX_BP_CFG | (chan << 3 ),
@@ -434,7 +478,7 @@ static void nic_send_rss_size(struct nicpf *nic, int vf)
434
478
msg = (u64 * )& mbx ;
435
479
436
480
mbx .rss_size .msg = NIC_MBOX_MSG_RSS_SIZE ;
437
- mbx .rss_size .ind_tbl_size = nic -> rss_ind_tbl_size ;
481
+ mbx .rss_size .ind_tbl_size = nic -> hw -> rss_ind_tbl_size ;
438
482
nic_send_msg_to_vf (nic , vf , & mbx );
439
483
}
440
484
@@ -494,6 +538,7 @@ static void nic_config_rss(struct nicpf *nic, struct rss_cfg_msg *cfg)
494
538
static void nic_tx_channel_cfg (struct nicpf * nic , u8 vnic ,
495
539
struct sq_cfg_msg * sq )
496
540
{
541
+ struct hw_info * hw = nic -> hw ;
497
542
u32 bgx , lmac , chan ;
498
543
u32 tl2 , tl3 , tl4 ;
499
544
u32 rr_quantum ;
@@ -512,30 +557,38 @@ static void nic_tx_channel_cfg(struct nicpf *nic, u8 vnic,
512
557
/* 24 bytes for FCS, IPG and preamble */
513
558
rr_quantum = ((NIC_HW_MAX_FRS + 24 ) / 4 );
514
559
560
+ /* For 88xx 0-511 TL4 transmits via BGX0 and
561
+ * 512-1023 TL4s transmit via BGX1.
562
+ */
563
+ tl4 = bgx * (hw -> tl4_cnt / hw -> bgx_cnt );
515
564
if (!sq -> sqs_mode ) {
516
- tl4 = (lmac * NIC_TL4_PER_LMAC ) + ( bgx * NIC_TL4_PER_BGX );
565
+ tl4 + = (lmac * MAX_QUEUES_PER_QSET );
517
566
} else {
518
567
for (svf = 0 ; svf < MAX_SQS_PER_VF ; svf ++ ) {
519
568
if (nic -> vf_sqs [pqs_vnic ][svf ] == vnic )
520
569
break ;
521
570
}
522
- tl4 = (MAX_LMAC_PER_BGX * NIC_TL4_PER_LMAC );
523
- tl4 += (lmac * NIC_TL4_PER_LMAC * MAX_SQS_PER_VF );
524
- tl4 += (svf * NIC_TL4_PER_LMAC );
525
- tl4 += (bgx * NIC_TL4_PER_BGX );
571
+ tl4 += (MAX_LMAC_PER_BGX * MAX_QUEUES_PER_QSET );
572
+ tl4 += (lmac * MAX_QUEUES_PER_QSET * MAX_SQS_PER_VF );
573
+ tl4 += (svf * MAX_QUEUES_PER_QSET );
526
574
}
527
575
tl4 += sq_idx ;
528
576
529
- tl3 = tl4 / (NIC_MAX_TL4 / NIC_MAX_TL3 );
577
+ tl3 = tl4 / (hw -> tl4_cnt / hw -> tl3_cnt );
530
578
nic_reg_write (nic , NIC_PF_QSET_0_127_SQ_0_7_CFG2 |
531
579
((u64 )vnic << NIC_QS_ID_SHIFT ) |
532
580
((u32 )sq_idx << NIC_Q_NUM_SHIFT ), tl4 );
533
581
nic_reg_write (nic , NIC_PF_TL4_0_1023_CFG | (tl4 << 3 ),
534
582
((u64 )vnic << 27 ) | ((u32 )sq_idx << 24 ) | rr_quantum );
535
583
536
584
nic_reg_write (nic , NIC_PF_TL3_0_255_CFG | (tl3 << 3 ), rr_quantum );
537
- chan = (lmac * MAX_BGX_CHANS_PER_LMAC ) + (bgx * NIC_CHANS_PER_INF );
585
+
586
+ /* On 88xx 0-127 channels are for BGX0 and
587
+ * 127-255 channels for BGX1.
588
+ */
589
+ chan = (lmac * hw -> chans_per_lmac ) + (bgx * hw -> chans_per_bgx );
538
590
nic_reg_write (nic , NIC_PF_TL3_0_255_CHAN | (tl3 << 3 ), chan );
591
+
539
592
/* Enable backpressure on the channel */
540
593
nic_reg_write (nic , NIC_PF_CHAN_0_255_TX_CFG | (chan << 3 ), 1 );
541
594
@@ -1008,6 +1061,12 @@ static int nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1008
1061
if (!nic )
1009
1062
return - ENOMEM ;
1010
1063
1064
+ nic -> hw = devm_kzalloc (dev , sizeof (struct hw_info ), GFP_KERNEL );
1065
+ if (!nic -> hw ) {
1066
+ devm_kfree (dev , nic );
1067
+ return - ENOMEM ;
1068
+ }
1069
+
1011
1070
pci_set_drvdata (pdev , nic );
1012
1071
1013
1072
nic -> pdev = pdev ;
@@ -1047,13 +1106,10 @@ static int nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1047
1106
1048
1107
nic -> node = nic_get_node_id (pdev );
1049
1108
1050
- nic_set_lmac_vf_mapping (nic );
1051
-
1052
1109
/* Initialize hardware */
1053
1110
nic_init_hw (nic );
1054
1111
1055
- /* Set RSS TBL size for each VF */
1056
- nic -> rss_ind_tbl_size = NIC_MAX_RSS_IDR_TBL_SIZE ;
1112
+ nic_set_lmac_vf_mapping (nic );
1057
1113
1058
1114
/* Register interrupts */
1059
1115
err = nic_register_interrupts (nic );
@@ -1086,6 +1142,8 @@ static int nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1086
1142
err_release_regions :
1087
1143
pci_release_regions (pdev );
1088
1144
err_disable_device :
1145
+ devm_kfree (dev , nic -> hw );
1146
+ devm_kfree (dev , nic );
1089
1147
pci_disable_device (pdev );
1090
1148
pci_set_drvdata (pdev , NULL );
1091
1149
return err ;
@@ -1106,6 +1164,10 @@ static void nic_remove(struct pci_dev *pdev)
1106
1164
1107
1165
nic_unregister_interrupts (nic );
1108
1166
pci_release_regions (pdev );
1167
+
1168
+ devm_kfree (& pdev -> dev , nic -> hw );
1169
+ devm_kfree (& pdev -> dev , nic );
1170
+
1109
1171
pci_disable_device (pdev );
1110
1172
pci_set_drvdata (pdev , NULL );
1111
1173
}
0 commit comments