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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright 2019-2021 Broadcom.
*/
#include <common.h>
#include <asm/io.h>
#include <dm.h>
#include <linux/delay.h>
#include <memalign.h>
#include <net.h>
#include "bnxt.h"
#include "bnxt_dbg.h"
#define bnxt_down_chip(bp) bnxt_hwrm_run(down_chip, bp, 0)
#define bnxt_bring_chip(bp) bnxt_hwrm_run(bring_chip, bp, 1)
/* Broadcom ethernet driver PCI APIs. */
static void bnxt_bring_pci(struct bnxt *bp)
{
u16 cmd_reg = 0;
dm_pci_read_config16(bp->pdev, PCI_VENDOR_ID, &bp->vendor_id);
dm_pci_read_config16(bp->pdev, PCI_DEVICE_ID, &bp->device_id);
dm_pci_read_config16(bp->pdev, PCI_SUBSYSTEM_VENDOR_ID, &bp->subsystem_vendor);
dm_pci_read_config16(bp->pdev, PCI_SUBSYSTEM_ID, &bp->subsystem_device);
dm_pci_read_config16(bp->pdev, PCI_COMMAND, &bp->cmd_reg);
dm_pci_read_config8(bp->pdev, PCI_INTERRUPT_LINE, &bp->irq);
bp->bar0 = dm_pci_map_bar(bp->pdev, PCI_BASE_ADDRESS_0, 0, 0,
PCI_REGION_TYPE, PCI_REGION_MEM);
bp->bar1 = dm_pci_map_bar(bp->pdev, PCI_BASE_ADDRESS_2, 0, 0,
PCI_REGION_TYPE, PCI_REGION_MEM);
bp->bar2 = dm_pci_map_bar(bp->pdev, PCI_BASE_ADDRESS_4, 0, 0,
PCI_REGION_TYPE, PCI_REGION_MEM);
cmd_reg = bp->cmd_reg | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
cmd_reg |= PCI_COMMAND_INTX_DISABLE; /* disable intr */
dm_pci_write_config16(bp->pdev, PCI_COMMAND, cmd_reg);
dm_pci_read_config16(bp->pdev, PCI_COMMAND, &cmd_reg);
dbg_pci(bp, __func__, cmd_reg);
}
int bnxt_free_rx_iob(struct bnxt *bp)
{
unsigned int i;
if (!(FLAG_TEST(bp->flag_hwrm, VALID_RX_IOB)))
return STATUS_SUCCESS;
for (i = 0; i < bp->rx.buf_cnt; i++) {
if (bp->rx.iob[i]) {
free(bp->rx.iob[i]);
bp->rx.iob[i] = NULL;
}
}
FLAG_RESET(bp->flag_hwrm, VALID_RX_IOB);
return STATUS_SUCCESS;
}
static void set_rx_desc(u8 *buf, void *iob, u16 cons_id, u32 iob_idx)
{
struct rx_prod_pkt_bd *desc;
u16 off = cons_id * sizeof(struct rx_prod_pkt_bd);
desc = (struct rx_prod_pkt_bd *)&buf[off];
desc->flags_type = RX_PROD_PKT_BD_TYPE_RX_PROD_PKT;
desc->len = MAX_ETHERNET_PACKET_BUFFER_SIZE;
desc->opaque = iob_idx;
desc->dma.addr = virt_to_bus(iob);
}
static int bnxt_alloc_rx_iob(struct bnxt *bp, u16 cons_id, u16 iob_idx)
{
void *iob;
iob = memalign(BNXT_DMA_ALIGNMENT, RX_STD_DMA_ALIGNED);
if (!iob)
return -ENOMEM;
dbg_rx_iob(iob, iob_idx, cons_id);
set_rx_desc((u8 *)bp->rx.bd_virt, iob, cons_id, (u32)iob_idx);
bp->rx.iob[iob_idx] = iob;
return 0;
}
void bnxt_mm_init(struct bnxt *bp, const char *func)
{
memset(bp->hwrm_addr_req, 0, REQ_BUFFER_SIZE);
memset(bp->hwrm_addr_resp, 0, RESP_BUFFER_SIZE);
memset(bp->cq.bd_virt, 0, CQ_RING_DMA_BUFFER_SIZE);
memset(bp->tx.bd_virt, 0, TX_RING_DMA_BUFFER_SIZE);
memset(bp->rx.bd_virt, 0, RX_RING_DMA_BUFFER_SIZE);
bp->data_addr_mapping = virt_to_bus(bp->hwrm_addr_data);
bp->req_addr_mapping = virt_to_bus(bp->hwrm_addr_req);
bp->resp_addr_mapping = virt_to_bus(bp->hwrm_addr_resp);
bp->wait_link_timeout = LINK_DEFAULT_TIMEOUT;
bp->link_status = STATUS_LINK_DOWN;
bp->media_change = 1;
bp->mtu = MAX_ETHERNET_PACKET_BUFFER_SIZE;
bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN;
bp->rx.buf_cnt = NUM_RX_BUFFERS;
bp->rx.ring_cnt = MAX_RX_DESC_CNT;
bp->tx.ring_cnt = MAX_TX_DESC_CNT;
bp->cq.ring_cnt = MAX_CQ_DESC_CNT;
bp->cq.completion_bit = 0x1;
bp->link_set = LINK_SPEED_DRV_100G;
dbg_mem(bp, func);
}
void bnxt_free_mem(struct bnxt *bp)
{
if (bp->cq.bd_virt) {
free(bp->cq.bd_virt);
bp->cq.bd_virt = NULL;
}
if (bp->rx.bd_virt) {
free(bp->rx.bd_virt);
bp->rx.bd_virt = NULL;
}
if (bp->tx.bd_virt) {
free(bp->tx.bd_virt);
bp->tx.bd_virt = NULL;
}
if (bp->hwrm_addr_resp) {
free(bp->hwrm_addr_resp);
bp->resp_addr_mapping = 0;
bp->hwrm_addr_resp = NULL;
}
if (bp->hwrm_addr_req) {
free(bp->hwrm_addr_req);
bp->req_addr_mapping = 0;
bp->hwrm_addr_req = NULL;
}
if (bp->hwrm_addr_data) {
free(bp->hwrm_addr_data);
bp->data_addr_mapping = 0;
bp->hwrm_addr_data = NULL;
}
dbg_mem_free_done(__func__);
}
int bnxt_alloc_mem(struct bnxt *bp)
{
bp->hwrm_addr_data = memalign(BNXT_DMA_ALIGNMENT, DMA_BUF_SIZE_ALIGNED);
bp->hwrm_addr_req = memalign(BNXT_DMA_ALIGNMENT, REQ_BUF_SIZE_ALIGNED);
bp->hwrm_addr_resp = MEM_HWRM_RESP;
memset(&bp->tx, 0, sizeof(struct lm_tx_info_t));
memset(&bp->rx, 0, sizeof(struct lm_rx_info_t));
memset(&bp->cq, 0, sizeof(struct lm_cmp_info_t));
bp->tx.bd_virt = memalign(BNXT_DMA_ALIGNMENT, TX_RING_DMA_BUFFER_SIZE);
bp->rx.bd_virt = memalign(BNXT_DMA_ALIGNMENT, RX_RING_DMA_BUFFER_SIZE);
bp->cq.bd_virt = memalign(BNXT_DMA_ALIGNMENT, CQ_RING_DMA_BUFFER_SIZE);
if (bp->hwrm_addr_req &&
bp->hwrm_addr_resp &&
bp->hwrm_addr_data &&
bp->tx.bd_virt &&
bp->rx.bd_virt &&
bp->cq.bd_virt) {
bnxt_mm_init(bp, __func__);
return STATUS_SUCCESS;
}
dbg_mem_alloc_fail(__func__);
bnxt_free_mem(bp);
return -ENOMEM;
}
static void hwrm_init(struct bnxt *bp, struct input *req, u16 cmd, u16 len)
{
memset(req, 0, len);
req->req_type = cmd;
req->cmpl_ring = (u16)HWRM_NA_SIGNATURE;
req->target_id = (u16)HWRM_NA_SIGNATURE;
req->resp_addr = bp->resp_addr_mapping;
req->seq_id = bp->seq_id++;
}
static void hwrm_write_req(struct bnxt *bp, void *req, u32 cnt)
{
u32 i = 0;
for (i = 0; i < cnt; i++)
writel(((u32 *)req)[i], bp->bar0 + GRC_COM_CHAN_BASE + (i * 4));
writel(0x1, (bp->bar0 + GRC_COM_CHAN_BASE + GRC_COM_CHAN_TRIG));
}
static void short_hwrm_cmd_req(struct bnxt *bp, u16 len)
{
struct hwrm_short_input sreq;
memset(&sreq, 0, sizeof(struct hwrm_short_input));
sreq.req_type = (u16)((struct input *)bp->hwrm_addr_req)->req_type;
sreq.signature = SHORT_REQ_SIGNATURE_SHORT_CMD;
sreq.size = len;
sreq.req_addr = bp->req_addr_mapping;
dbg_short_cmd((u8 *)&sreq, __func__, sizeof(struct hwrm_short_input));
hwrm_write_req(bp, &sreq, sizeof(struct hwrm_short_input) / 4);
}
static int wait_resp(struct bnxt *bp, u32 tmo, u16 len, const char *func)
{
struct input *req = (struct input *)bp->hwrm_addr_req;
struct output *resp = (struct output *)bp->hwrm_addr_resp;
u8 *ptr = (u8 *)resp;
u32 idx;
u32 wait_cnt = HWRM_CMD_DEFAULT_MULTIPLAYER((u32)tmo);
u16 resp_len = 0;
u16 ret = STATUS_TIMEOUT;
if (len > bp->hwrm_max_req_len)
short_hwrm_cmd_req(bp, len);
else
hwrm_write_req(bp, req, (u32)(len / 4));
for (idx = 0; idx < wait_cnt; idx++) {
resp_len = resp->resp_len;
if (resp->seq_id == req->seq_id && resp->req_type == req->req_type &&
ptr[resp_len - 1] == 1) {
bp->last_resp_code = resp->error_code;
ret = resp->error_code;
break;
}
udelay(HWRM_CMD_POLL_WAIT_TIME);
}
dbg_hw_cmd(bp, func, len, resp_len, tmo, ret);
return (int)ret;
}
static void bnxt_db_cq(struct bnxt *bp)
{
writel(CQ_DOORBELL_KEY_IDX(bp->cq.cons_idx), bp->bar1);
}
static void bnxt_db_rx(struct bnxt *bp, u32 idx)
{
writel(RX_DOORBELL_KEY_RX | idx, bp->bar1);
}
static void bnxt_db_tx(struct bnxt *bp, u32 idx)
{
writel((u32)(TX_DOORBELL_KEY_TX | idx), bp->bar1);
}
int iob_pad(void *packet, int length)
{
if (length >= ETH_ZLEN)
return length;
memset(((u8 *)packet + length), 0x00, (ETH_ZLEN - length));
return ETH_ZLEN;
}
static inline u32 bnxt_tx_avail(struct bnxt *bp)
{
barrier();
return TX_AVAIL(bp->tx.ring_cnt) -
((bp->tx.prod_id - bp->tx.cons_id) &
(bp->tx.ring_cnt - 1));
}
void set_txq(struct bnxt *bp, int entry, dma_addr_t mapping, int len)
{
struct tx_bd_short *prod_bd;
prod_bd = (struct tx_bd_short *)BD_NOW(bp->tx.bd_virt,
entry,
sizeof(struct tx_bd_short));
if (len < 512)
prod_bd->flags_type = TX_BD_SHORT_FLAGS_LHINT_LT512;
else if (len < 1024)
prod_bd->flags_type = TX_BD_SHORT_FLAGS_LHINT_LT1K;
else if (len < 2048)
prod_bd->flags_type = TX_BD_SHORT_FLAGS_LHINT_LT2K;
else
prod_bd->flags_type = TX_BD_SHORT_FLAGS_LHINT_GTE2K;
prod_bd->flags_type |= TX_BD_FLAGS;
prod_bd->dma.addr = mapping;
prod_bd->len = len;
prod_bd->opaque = (u32)entry;
dump_tx_bd(prod_bd, (u16)(sizeof(struct tx_bd_short)));
}
static void bnxt_tx_complete(struct bnxt *bp)
{
bp->tx.cons_id = NEXT_IDX(bp->tx.cons_id, bp->tx.ring_cnt);
bp->tx.cnt++;
dump_tx_stat(bp);
}
int post_rx_buffers(struct bnxt *bp)
{
u16 cons_id = (bp->rx.cons_idx % bp->rx.ring_cnt);
u16 iob_idx;
while (bp->rx.iob_cnt < bp->rx.buf_cnt) {
iob_idx = (cons_id % bp->rx.buf_cnt);
if (!bp->rx.iob[iob_idx]) {
if (bnxt_alloc_rx_iob(bp, cons_id, iob_idx) < 0) {
dbg_rx_alloc_iob_fail(iob_idx, cons_id);
break;
}
}
cons_id = NEXT_IDX(cons_id, bp->rx.ring_cnt);
bp->rx.iob_cnt++;
}
if (cons_id != bp->rx.cons_idx) {
dbg_rx_cid(bp->rx.cons_idx, cons_id);
bp->rx.cons_idx = cons_id;
bnxt_db_rx(bp, (u32)cons_id);
}
FLAG_SET(bp->flag_hwrm, VALID_RX_IOB);
return STATUS_SUCCESS;
}
u8 bnxt_rx_drop(struct bnxt *bp, u8 *rx_buf, struct rx_pkt_cmpl_hi *rx_cmp_hi)
{
u8 chksum_err = 0;
u8 i;
u16 error_flags;
error_flags = (rx_cmp_hi->errors_v2 >>
RX_PKT_CMPL_ERRORS_BUFFER_ERROR_SFT);
if (rx_cmp_hi->errors_v2 == 0x20 || rx_cmp_hi->errors_v2 == 0x21)
chksum_err = 1;
if (error_flags && !chksum_err) {
bp->rx.err++;
return 1;
}
for (i = 0; i < 6; i++) {
if (rx_buf[6 + i] != bp->mac_set[i])
break;
}
if (i == 6) {
bp->rx.dropped++;
return 2; /* Drop the loopback packets */
}
return 0;
}
static void bnxt_adv_cq_index(struct bnxt *bp, u16 count)
{
u16 cons_idx = bp->cq.cons_idx + count;
if (cons_idx >= MAX_CQ_DESC_CNT) {
/* Toggle completion bit when the ring wraps. */
bp->cq.completion_bit ^= 1;
cons_idx = cons_idx - MAX_CQ_DESC_CNT;
}
bp->cq.cons_idx = cons_idx;
}
void bnxt_adv_rx_index(struct bnxt *bp, u8 *iob, u32 iob_idx)
{
u16 cons_id = (bp->rx.cons_idx % bp->rx.ring_cnt);
set_rx_desc((u8 *)bp->rx.bd_virt, (void *)iob, cons_id, iob_idx);
cons_id = NEXT_IDX(cons_id, bp->rx.ring_cnt);
if (cons_id != bp->rx.cons_idx) {
dbg_rx_cid(bp->rx.cons_idx, cons_id);
bp->rx.cons_idx = cons_id;
bnxt_db_rx(bp, (u32)cons_id);
}
}
void rx_process(struct bnxt *bp, struct rx_pkt_cmpl *rx_cmp,
struct rx_pkt_cmpl_hi *rx_cmp_hi)
{
u32 desc_idx = rx_cmp->opaque;
u8 *iob = bp->rx.iob[desc_idx];
dump_rx_bd(rx_cmp, rx_cmp_hi, desc_idx);
bp->rx.iob_len = rx_cmp->len;
bp->rx.iob_rx = iob;
if (bnxt_rx_drop(bp, iob, rx_cmp_hi))
bp->rx.iob_recv = PKT_DROPPED;
else
bp->rx.iob_recv = PKT_RECEIVED;
bp->rx.rx_cnt++;
dbg_rxp(bp->rx.iob_rx, bp->rx.iob_len, bp->rx.iob_recv);
bnxt_adv_rx_index(bp, iob, desc_idx);
bnxt_adv_cq_index(bp, 2); /* Rx completion is 2 entries. */
}
static int bnxt_rx_complete(struct bnxt *bp, struct rx_pkt_cmpl *rx_cmp)
{
struct rx_pkt_cmpl_hi *rx_cmp_hi;
u8 completion_bit = bp->cq.completion_bit;
if (bp->cq.cons_idx == (bp->cq.ring_cnt - 1)) {
rx_cmp_hi = (struct rx_pkt_cmpl_hi *)bp->cq.bd_virt;
completion_bit ^= 0x1; /* Ring has wrapped. */
} else {
rx_cmp_hi = (struct rx_pkt_cmpl_hi *)(rx_cmp + 1);
}
if (!((rx_cmp_hi->errors_v2 & RX_PKT_CMPL_V2) ^ completion_bit))
rx_process(bp, rx_cmp, rx_cmp_hi);
return NO_MORE_CQ_BD_TO_SERVICE;
}
static int bnxt_hwrm_ver_get(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_ver_get_input);
struct hwrm_ver_get_input *req;
struct hwrm_ver_get_output *resp;
int rc;
req = (struct hwrm_ver_get_input *)bp->hwrm_addr_req;
resp = (struct hwrm_ver_get_output *)bp->hwrm_addr_resp;
hwrm_init(bp, (void *)req, (u16)HWRM_VER_GET, cmd_len);
req->hwrm_intf_maj = HWRM_VERSION_MAJOR;
req->hwrm_intf_min = HWRM_VERSION_MINOR;
req->hwrm_intf_upd = HWRM_VERSION_UPDATE;
rc = wait_resp(bp, HWRM_CMD_DEFAULT_TIMEOUT, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
bp->hwrm_spec_code =
resp->hwrm_intf_maj_8b << 16 |
resp->hwrm_intf_min_8b << 8 |
resp->hwrm_intf_upd_8b;
bp->hwrm_cmd_timeout = (u32)resp->def_req_timeout;
if (!bp->hwrm_cmd_timeout)
bp->hwrm_cmd_timeout = (u32)HWRM_CMD_DEFAULT_TIMEOUT;
if (resp->hwrm_intf_maj_8b >= 1)
bp->hwrm_max_req_len = resp->max_req_win_len;
bp->chip_id =
resp->chip_rev << 24 |
resp->chip_metal << 16 |
resp->chip_bond_id << 8 |
resp->chip_platform_type;
bp->chip_num = resp->chip_num;
if ((resp->dev_caps_cfg & SHORT_CMD_SUPPORTED) &&
(resp->dev_caps_cfg & SHORT_CMD_REQUIRED))
FLAG_SET(bp->flags, BNXT_FLAG_HWRM_SHORT_CMD_SUPP);
bp->hwrm_max_ext_req_len = resp->max_ext_req_len;
bp->fw_maj = resp->hwrm_fw_maj_8b;
bp->fw_min = resp->hwrm_fw_min_8b;
bp->fw_bld = resp->hwrm_fw_bld_8b;
bp->fw_rsvd = resp->hwrm_fw_rsvd_8b;
print_fw_ver(resp, bp->hwrm_cmd_timeout);
return STATUS_SUCCESS;
}
/* Broadcom ethernet driver Function HW cmds APIs. */
static int bnxt_hwrm_func_resource_qcaps(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_func_resource_qcaps_input);
struct hwrm_func_resource_qcaps_input *req;
struct hwrm_func_resource_qcaps_output *resp;
int rc;
req = (struct hwrm_func_resource_qcaps_input *)bp->hwrm_addr_req;
resp = (struct hwrm_func_resource_qcaps_output *)bp->hwrm_addr_resp;
hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_RESOURCE_QCAPS, cmd_len);
req->fid = (u16)HWRM_NA_SIGNATURE;
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc != STATUS_SUCCESS)
return STATUS_SUCCESS;
FLAG_SET(bp->flags, BNXT_FLAG_RESOURCE_QCAPS_SUPPORT);
/* VFs */
bp->max_vfs = resp->max_vfs;
bp->vf_res_strategy = resp->vf_reservation_strategy;
/* vNICs */
bp->min_vnics = resp->min_vnics;
bp->max_vnics = resp->max_vnics;
/* MSI-X */
bp->max_msix = resp->max_msix;
/* Ring Groups */
bp->min_hw_ring_grps = resp->min_hw_ring_grps;
bp->max_hw_ring_grps = resp->max_hw_ring_grps;
/* TX Rings */
bp->min_tx_rings = resp->min_tx_rings;
bp->max_tx_rings = resp->max_tx_rings;
/* RX Rings */
bp->min_rx_rings = resp->min_rx_rings;
bp->max_rx_rings = resp->max_rx_rings;
/* Completion Rings */
bp->min_cp_rings = resp->min_cmpl_rings;
bp->max_cp_rings = resp->max_cmpl_rings;
/* RSS Contexts */
bp->min_rsscos_ctxs = resp->min_rsscos_ctx;
bp->max_rsscos_ctxs = resp->max_rsscos_ctx;
/* L2 Contexts */
bp->min_l2_ctxs = resp->min_l2_ctxs;
bp->max_l2_ctxs = resp->max_l2_ctxs;
/* Statistic Contexts */
bp->min_stat_ctxs = resp->min_stat_ctx;
bp->max_stat_ctxs = resp->max_stat_ctx;
dbg_func_resource_qcaps(bp);
return STATUS_SUCCESS;
}
static u32 set_ring_info(struct bnxt *bp)
{
u32 enables = 0;
bp->num_cmpl_rings = DEFAULT_NUMBER_OF_CMPL_RINGS;
bp->num_tx_rings = DEFAULT_NUMBER_OF_TX_RINGS;
bp->num_rx_rings = DEFAULT_NUMBER_OF_RX_RINGS;
bp->num_hw_ring_grps = DEFAULT_NUMBER_OF_RING_GRPS;
bp->num_stat_ctxs = DEFAULT_NUMBER_OF_STAT_CTXS;
if (bp->min_cp_rings <= DEFAULT_NUMBER_OF_CMPL_RINGS)
bp->num_cmpl_rings = bp->min_cp_rings;
if (bp->min_tx_rings <= DEFAULT_NUMBER_OF_TX_RINGS)
bp->num_tx_rings = bp->min_tx_rings;
if (bp->min_rx_rings <= DEFAULT_NUMBER_OF_RX_RINGS)
bp->num_rx_rings = bp->min_rx_rings;
if (bp->min_hw_ring_grps <= DEFAULT_NUMBER_OF_RING_GRPS)
bp->num_hw_ring_grps = bp->min_hw_ring_grps;
if (bp->min_stat_ctxs <= DEFAULT_NUMBER_OF_STAT_CTXS)
bp->num_stat_ctxs = bp->min_stat_ctxs;
print_num_rings(bp);
enables = (FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS |
FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS |
FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS |
FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS);
return enables;
}
static void bnxt_hwrm_assign_resources(struct bnxt *bp)
{
struct hwrm_func_cfg_input *req;
u32 enables = 0;
if (FLAG_TEST(bp->flags, BNXT_FLAG_RESOURCE_QCAPS_SUPPORT))
enables = set_ring_info(bp);
req = (struct hwrm_func_cfg_input *)bp->hwrm_addr_req;
req->num_cmpl_rings = bp->num_cmpl_rings;
req->num_tx_rings = bp->num_tx_rings;
req->num_rx_rings = bp->num_rx_rings;
req->num_stat_ctxs = bp->num_stat_ctxs;
req->num_hw_ring_grps = bp->num_hw_ring_grps;
req->enables = enables;
}
int bnxt_hwrm_nvm_flush(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_nvm_flush_input);
struct hwrm_nvm_flush_input *req;
int rc;
req = (struct hwrm_nvm_flush_input *)bp->hwrm_addr_req;
hwrm_init(bp, (void *)req, (u16)HWRM_NVM_FLUSH, cmd_len);
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
return STATUS_SUCCESS;
}
static int bnxt_hwrm_func_qcaps_req(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_func_qcaps_input);
struct hwrm_func_qcaps_input *req;
struct hwrm_func_qcaps_output *resp;
int rc;
req = (struct hwrm_func_qcaps_input *)bp->hwrm_addr_req;
resp = (struct hwrm_func_qcaps_output *)bp->hwrm_addr_resp;
hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_QCAPS, cmd_len);
req->fid = (u16)HWRM_NA_SIGNATURE;
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
bp->fid = resp->fid;
bp->port_idx = (u8)resp->port_id;
/* Get MAC address for this PF */
memcpy(&bp->mac_addr[0], &resp->mac_address[0], ETH_ALEN);
memcpy(&bp->mac_set[0], &bp->mac_addr[0], ETH_ALEN);
print_func_qcaps(bp);
return STATUS_SUCCESS;
}
static int bnxt_hwrm_func_qcfg_req(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_func_qcfg_input);
struct hwrm_func_qcfg_input *req;
struct hwrm_func_qcfg_output *resp;
int rc;
req = (struct hwrm_func_qcfg_input *)bp->hwrm_addr_req;
resp = (struct hwrm_func_qcfg_output *)bp->hwrm_addr_resp;
hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_QCFG, cmd_len);
req->fid = (u16)HWRM_NA_SIGNATURE;
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
if (resp->flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST)
FLAG_SET(bp->flags, BNXT_FLAG_MULTI_HOST);
if (resp->port_partition_type &
FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0)
FLAG_SET(bp->flags, BNXT_FLAG_NPAR_MODE);
bp->ordinal_value = (u8)resp->pci_id & 0x0F;
bp->stat_ctx_id = resp->stat_ctx_id;
memcpy(&bp->mac_addr[0], &resp->mac_address[0], ETH_ALEN);
print_func_qcfg(bp);
dbg_flags(__func__, bp->flags);
return STATUS_SUCCESS;
}
static int bnxt_hwrm_func_reset_req(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_func_reset_input);
struct hwrm_func_reset_input *req;
req = (struct hwrm_func_reset_input *)bp->hwrm_addr_req;
hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_RESET, cmd_len);
req->func_reset_level = FUNC_RESET_REQ_FUNC_RESET_LEVEL_RESETME;
return wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
}
static int bnxt_hwrm_func_cfg_req(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_func_cfg_input);
struct hwrm_func_cfg_input *req;
req = (struct hwrm_func_cfg_input *)bp->hwrm_addr_req;
hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_CFG, cmd_len);
req->fid = (u16)HWRM_NA_SIGNATURE;
bnxt_hwrm_assign_resources(bp);
return wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
}
static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_func_drv_rgtr_input);
struct hwrm_func_drv_rgtr_input *req;
int rc;
req = (struct hwrm_func_drv_rgtr_input *)bp->hwrm_addr_req;
hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_DRV_RGTR, cmd_len);
/* Register with HWRM */
req->enables = FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE |
FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD |
FUNC_DRV_RGTR_REQ_ENABLES_VER;
req->async_event_fwd[0] |= 0x01;
req->os_type = FUNC_DRV_RGTR_REQ_OS_TYPE_OTHER;
req->ver_maj = DRIVER_VERSION_MAJOR;
req->ver_min = DRIVER_VERSION_MINOR;
req->ver_upd = DRIVER_VERSION_UPDATE;
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
FLAG_SET(bp->flag_hwrm, VALID_DRIVER_REG);
return STATUS_SUCCESS;
}
static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_func_drv_unrgtr_input);
struct hwrm_func_drv_unrgtr_input *req;
int rc;
if (!(FLAG_TEST(bp->flag_hwrm, VALID_DRIVER_REG)))
return STATUS_SUCCESS;
req = (struct hwrm_func_drv_unrgtr_input *)bp->hwrm_addr_req;
hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_DRV_UNRGTR, cmd_len);
req->flags = FUNC_DRV_UNRGTR_REQ_FLAGS_PREPARE_FOR_SHUTDOWN;
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
FLAG_RESET(bp->flag_hwrm, VALID_DRIVER_REG);
return STATUS_SUCCESS;
}
static int bnxt_hwrm_cfa_l2_filter_alloc(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_cfa_l2_filter_alloc_input);
struct hwrm_cfa_l2_filter_alloc_input *req;
struct hwrm_cfa_l2_filter_alloc_output *resp;
int rc;
u32 flags = CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX;
u32 enables;
req = (struct hwrm_cfa_l2_filter_alloc_input *)bp->hwrm_addr_req;
resp = (struct hwrm_cfa_l2_filter_alloc_output *)bp->hwrm_addr_resp;
enables = CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID |
CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK;
hwrm_init(bp, (void *)req, (u16)HWRM_CFA_L2_FILTER_ALLOC, cmd_len);
req->flags = flags;
req->enables = enables;
memcpy((char *)&req->l2_addr[0], (char *)&bp->mac_set[0], ETH_ALEN);
memset((char *)&req->l2_addr_mask[0], 0xff, ETH_ALEN);
memcpy((char *)&req->t_l2_addr[0], (char *)&bp->mac_set[0], ETH_ALEN);
memset((char *)&req->t_l2_addr_mask[0], 0xff, ETH_ALEN);
req->src_type = CFA_L2_FILTER_ALLOC_REQ_SRC_TYPE_NPORT;
req->src_id = (u32)bp->port_idx;
req->dst_id = bp->vnic_id;
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
FLAG_SET(bp->flag_hwrm, VALID_L2_FILTER);
bp->l2_filter_id = resp->l2_filter_id;
return STATUS_SUCCESS;
}
static int bnxt_hwrm_cfa_l2_filter_free(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_cfa_l2_filter_free_input);
struct hwrm_cfa_l2_filter_free_input *req;
int rc;
if (!(FLAG_TEST(bp->flag_hwrm, VALID_L2_FILTER)))
return STATUS_SUCCESS;
req = (struct hwrm_cfa_l2_filter_free_input *)bp->hwrm_addr_req;
hwrm_init(bp, (void *)req, (u16)HWRM_CFA_L2_FILTER_FREE, cmd_len);
req->l2_filter_id = bp->l2_filter_id;
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
FLAG_RESET(bp->flag_hwrm, VALID_L2_FILTER);
return STATUS_SUCCESS;
}
u32 bnxt_set_rx_mask(u32 rx_mask)
{
u32 mask = 0;
if (!rx_mask)
return mask;
mask = CFA_L2_SET_RX_MASK_REQ_MASK_BCAST;
if (rx_mask != RX_MASK_ACCEPT_NONE) {
if (rx_mask & RX_MASK_ACCEPT_MULTICAST)
mask |= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST;
if (rx_mask & RX_MASK_ACCEPT_ALL_MULTICAST)
mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
if (rx_mask & RX_MASK_PROMISCUOUS_MODE)
mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
}
return mask;
}
static int bnxt_hwrm_set_rx_mask(struct bnxt *bp, u32 rx_mask)
{
u16 cmd_len = (u16)sizeof(struct hwrm_cfa_l2_set_rx_mask_input);
struct hwrm_cfa_l2_set_rx_mask_input *req;
u32 mask = bnxt_set_rx_mask(rx_mask);
req = (struct hwrm_cfa_l2_set_rx_mask_input *)bp->hwrm_addr_req;
hwrm_init(bp, (void *)req, (u16)HWRM_CFA_L2_SET_RX_MASK, cmd_len);
req->vnic_id = bp->vnic_id;
req->mask = mask;
return wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
}
static int bnxt_hwrm_port_mac_cfg(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_port_mac_cfg_input);
struct hwrm_port_mac_cfg_input *req;
req = (struct hwrm_port_mac_cfg_input *)bp->hwrm_addr_req;
hwrm_init(bp, (void *)req, (u16)HWRM_PORT_MAC_CFG, cmd_len);
req->lpbk = PORT_MAC_CFG_REQ_LPBK_NONE;
return wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
}
static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp, u16 idx)
{
u16 cmd_len = (u16)sizeof(struct hwrm_port_phy_qcfg_input);
struct hwrm_port_phy_qcfg_input *req;
struct hwrm_port_phy_qcfg_output *resp;
int rc;
req = (struct hwrm_port_phy_qcfg_input *)bp->hwrm_addr_req;
resp = (struct hwrm_port_phy_qcfg_output *)bp->hwrm_addr_resp;
hwrm_init(bp, (void *)req, (u16)HWRM_PORT_PHY_QCFG, cmd_len);
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
if (idx & SUPPORT_SPEEDS)
bp->support_speeds = resp->support_speeds;
if (idx & DETECT_MEDIA)
bp->media_detect = resp->module_status;
if (idx & PHY_SPEED)
bp->current_link_speed = resp->link_speed;
if (idx & PHY_STATUS) {
if (resp->link == PORT_PHY_QCFG_RESP_LINK_LINK)
bp->link_status = STATUS_LINK_ACTIVE;
else
bp->link_status = STATUS_LINK_DOWN;
}
return STATUS_SUCCESS;
}
u16 set_link_speed_mask(u16 link_cap)
{
u16 speed_mask = 0;
if (link_cap & SPEED_CAPABILITY_DRV_100M)
speed_mask |= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_MASK_100MB;
if (link_cap & SPEED_CAPABILITY_DRV_1G)
speed_mask |= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_MASK_1GB;
if (link_cap & SPEED_CAPABILITY_DRV_10G)
speed_mask |= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_MASK_10GB;
if (link_cap & SPEED_CAPABILITY_DRV_25G)
speed_mask |= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_MASK_25GB;
if (link_cap & SPEED_CAPABILITY_DRV_40G)
speed_mask |= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_MASK_40GB;
if (link_cap & SPEED_CAPABILITY_DRV_50G)
speed_mask |= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_MASK_50GB;
if (link_cap & SPEED_CAPABILITY_DRV_100G)
speed_mask |= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_MASK_100GB;
return speed_mask;
}
static int bnxt_hwrm_port_phy_cfg(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_port_phy_cfg_input);
struct hwrm_port_phy_cfg_input *req;
u32 flags;
u32 enables = 0;
u16 force_link_speed = 0;
u16 auto_link_speed_mask = 0;
u8 auto_mode = 0;
u8 auto_pause = 0;
u8 auto_duplex = 0;
/*
* If multi_host or NPAR is set to TRUE,
* do not issue hwrm_port_phy_cfg
*/
if (FLAG_TEST(bp->flags, PORT_PHY_FLAGS)) {
dbg_flags(__func__, bp->flags);
return STATUS_SUCCESS;
}
req = (struct hwrm_port_phy_cfg_input *)bp->hwrm_addr_req;
flags = PORT_PHY_CFG_REQ_FLAGS_FORCE |
PORT_PHY_CFG_REQ_FLAGS_RESET_PHY;
switch (GET_MEDIUM_SPEED(bp->medium)) {
case MEDIUM_SPEED_1000MBPS:
force_link_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_1GB;
break;
case MEDIUM_SPEED_10GBPS:
force_link_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_10GB;
break;
case MEDIUM_SPEED_25GBPS:
force_link_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_25GB;
break;
case MEDIUM_SPEED_40GBPS:
force_link_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_40GB;
break;
case MEDIUM_SPEED_50GBPS:
force_link_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_50GB;
break;
case MEDIUM_SPEED_100GBPS:
force_link_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_100GB;
break;
default:
/* Enable AUTONEG by default */
auto_mode = PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK;
flags &= ~PORT_PHY_CFG_REQ_FLAGS_FORCE;
enables |= PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE |
PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK |
PORT_PHY_CFG_REQ_ENABLES_AUTO_DUPLEX |
PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE;
auto_pause = PORT_PHY_CFG_REQ_AUTO_PAUSE_TX |
PORT_PHY_CFG_REQ_AUTO_PAUSE_RX;
auto_duplex = PORT_PHY_CFG_REQ_AUTO_DUPLEX_BOTH;
auto_link_speed_mask = bp->support_speeds;
break;
}
hwrm_init(bp, (void *)req, (u16)HWRM_PORT_PHY_CFG, cmd_len);
req->flags = flags;
req->enables = enables;
req->port_id = bp->port_idx;
req->force_link_speed = force_link_speed;
req->auto_mode = auto_mode;
req->auto_duplex = auto_duplex;
req->auto_pause = auto_pause;
req->auto_link_speed_mask = auto_link_speed_mask;
return wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
}
static int bnxt_qphy_link(struct bnxt *bp)
{
u16 flag = QCFG_PHY_ALL;
/* Query Link Status */
if (bnxt_hwrm_port_phy_qcfg(bp, flag) != STATUS_SUCCESS)
return STATUS_FAILURE;
if (bp->link_status != STATUS_LINK_ACTIVE) {
/*
* Configure link if it is not up.
* try to bring link up, but don't return
* failure if port_phy_cfg() fails
*/
bnxt_hwrm_port_phy_cfg(bp);
/* refresh link speed values after bringing link up */
if (bnxt_hwrm_port_phy_qcfg(bp, flag) != STATUS_SUCCESS)
return STATUS_FAILURE;
}
return STATUS_SUCCESS;
}
static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_stat_ctx_alloc_input);
struct hwrm_stat_ctx_alloc_input *req;
struct hwrm_stat_ctx_alloc_output *resp;
int rc;
req = (struct hwrm_stat_ctx_alloc_input *)bp->hwrm_addr_req;
resp = (struct hwrm_stat_ctx_alloc_output *)bp->hwrm_addr_resp;
hwrm_init(bp, (void *)req, (u16)HWRM_STAT_CTX_ALLOC, cmd_len);
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
FLAG_SET(bp->flag_hwrm, VALID_STAT_CTX);
bp->stat_ctx_id = (u16)resp->stat_ctx_id;
return STATUS_SUCCESS;
}
static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_stat_ctx_free_input);
struct hwrm_stat_ctx_free_input *req;
int rc;
if (!(FLAG_TEST(bp->flag_hwrm, VALID_STAT_CTX)))
return STATUS_SUCCESS;
req = (struct hwrm_stat_ctx_free_input *)bp->hwrm_addr_req;
hwrm_init(bp, (void *)req, (u16)HWRM_STAT_CTX_FREE, cmd_len);
req->stat_ctx_id = (u32)bp->stat_ctx_id;
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
FLAG_RESET(bp->flag_hwrm, VALID_STAT_CTX);
return STATUS_SUCCESS;
}
static int bnxt_hwrm_ring_free_grp(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_ring_grp_free_input);
struct hwrm_ring_grp_free_input *req;
int rc;
if (!(FLAG_TEST(bp->flag_hwrm, VALID_RING_GRP)))
return STATUS_SUCCESS;
req = (struct hwrm_ring_grp_free_input *)bp->hwrm_addr_req;
hwrm_init(bp, (void *)req, (u16)HWRM_RING_GRP_FREE, cmd_len);
req->ring_group_id = (u32)bp->ring_grp_id;
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
FLAG_RESET(bp->flag_hwrm, VALID_RING_GRP);
return STATUS_SUCCESS;
}
static int bnxt_hwrm_ring_alloc_grp(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_ring_grp_alloc_input);
struct hwrm_ring_grp_alloc_input *req;
struct hwrm_ring_grp_alloc_output *resp;
int rc;
req = (struct hwrm_ring_grp_alloc_input *)bp->hwrm_addr_req;
resp = (struct hwrm_ring_grp_alloc_output *)bp->hwrm_addr_resp;
hwrm_init(bp, (void *)req, (u16)HWRM_RING_GRP_ALLOC, cmd_len);
req->cr = bp->cq_ring_id;
req->rr = bp->rx_ring_id;
req->ar = (u16)HWRM_NA_SIGNATURE;
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
FLAG_SET(bp->flag_hwrm, VALID_RING_GRP);
bp->ring_grp_id = (u16)resp->ring_group_id;
return STATUS_SUCCESS;
}
int bnxt_hwrm_ring_free(struct bnxt *bp, u16 ring_id, u8 ring_type)
{
u16 cmd_len = (u16)sizeof(struct hwrm_ring_free_input);
struct hwrm_ring_free_input *req;
req = (struct hwrm_ring_free_input *)bp->hwrm_addr_req;
hwrm_init(bp, (void *)req, (u16)HWRM_RING_FREE, cmd_len);
req->ring_type = ring_type;
req->ring_id = ring_id;
return wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
}
static int bnxt_hwrm_ring_alloc(struct bnxt *bp,
dma_addr_t ring_map,
u16 length,
u16 ring_id,
u8 ring_type,
u8 int_mode)
{
u16 cmd_len = (u16)sizeof(struct hwrm_ring_alloc_input);
struct hwrm_ring_alloc_input *req;
struct hwrm_ring_alloc_output *resp;
int rc;
req = (struct hwrm_ring_alloc_input *)bp->hwrm_addr_req;
resp = (struct hwrm_ring_alloc_output *)bp->hwrm_addr_resp;
hwrm_init(bp, (void *)req, (u16)HWRM_RING_ALLOC, cmd_len);
req->ring_type = ring_type;
req->page_tbl_addr = ring_map;
req->page_size = LM_PAGE_SIZE;
req->length = (u32)length;
req->cmpl_ring_id = ring_id;
req->int_mode = int_mode;
if (ring_type == RING_ALLOC_REQ_RING_TYPE_TX) {
req->queue_id = TX_RING_QID;
} else if (ring_type == RING_ALLOC_REQ_RING_TYPE_RX) {
req->queue_id = RX_RING_QID;
req->enables = RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID;
req->rx_buf_size = MAX_ETHERNET_PACKET_BUFFER_SIZE;
}
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
if (ring_type == RING_ALLOC_REQ_RING_TYPE_L2_CMPL) {
FLAG_SET(bp->flag_hwrm, VALID_RING_CQ);
bp->cq_ring_id = resp->ring_id;
} else if (ring_type == RING_ALLOC_REQ_RING_TYPE_TX) {
FLAG_SET(bp->flag_hwrm, VALID_RING_TX);
bp->tx_ring_id = resp->ring_id;
} else if (ring_type == RING_ALLOC_REQ_RING_TYPE_RX) {
FLAG_SET(bp->flag_hwrm, VALID_RING_RX);
bp->rx_ring_id = resp->ring_id;
}
return STATUS_SUCCESS;
}
static int bnxt_hwrm_ring_alloc_cq(struct bnxt *bp)
{
return bnxt_hwrm_ring_alloc(bp,
virt_to_bus(bp->cq.bd_virt),
bp->cq.ring_cnt,
0,
RING_ALLOC_REQ_RING_TYPE_L2_CMPL,
BNXT_CQ_INTR_MODE());
}
static int bnxt_hwrm_ring_alloc_tx(struct bnxt *bp)
{
return bnxt_hwrm_ring_alloc(bp,
virt_to_bus(bp->tx.bd_virt),
bp->tx.ring_cnt, bp->cq_ring_id,
RING_ALLOC_REQ_RING_TYPE_TX,
BNXT_INTR_MODE());
}
static int bnxt_hwrm_ring_alloc_rx(struct bnxt *bp)
{
return bnxt_hwrm_ring_alloc(bp,
virt_to_bus(bp->rx.bd_virt),
bp->rx.ring_cnt,
bp->cq_ring_id,
RING_ALLOC_REQ_RING_TYPE_RX,
BNXT_INTR_MODE());
}
static int bnxt_hwrm_ring_free_cq(struct bnxt *bp)
{
int ret = STATUS_SUCCESS;
if (!(FLAG_TEST(bp->flag_hwrm, VALID_RING_CQ)))
return ret;
ret = RING_FREE(bp, bp->cq_ring_id, RING_FREE_REQ_RING_TYPE_L2_CMPL);
if (ret == STATUS_SUCCESS)
FLAG_RESET(bp->flag_hwrm, VALID_RING_CQ);
return ret;
}
static int bnxt_hwrm_ring_free_tx(struct bnxt *bp)
{
int ret = STATUS_SUCCESS;
if (!(FLAG_TEST(bp->flag_hwrm, VALID_RING_TX)))
return ret;
ret = RING_FREE(bp, bp->tx_ring_id, RING_FREE_REQ_RING_TYPE_TX);
if (ret == STATUS_SUCCESS)
FLAG_RESET(bp->flag_hwrm, VALID_RING_TX);
return ret;
}
static int bnxt_hwrm_ring_free_rx(struct bnxt *bp)
{
int ret = STATUS_SUCCESS;
if (!(FLAG_TEST(bp->flag_hwrm, VALID_RING_RX)))
return ret;
ret = RING_FREE(bp, bp->rx_ring_id, RING_FREE_REQ_RING_TYPE_RX);
if (ret == STATUS_SUCCESS)
FLAG_RESET(bp->flag_hwrm, VALID_RING_RX);
return ret;
}
static int bnxt_hwrm_vnic_alloc(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_vnic_alloc_input);
struct hwrm_vnic_alloc_input *req;
struct hwrm_vnic_alloc_output *resp;
int rc;
req = (struct hwrm_vnic_alloc_input *)bp->hwrm_addr_req;
resp = (struct hwrm_vnic_alloc_output *)bp->hwrm_addr_resp;
hwrm_init(bp, (void *)req, (u16)HWRM_VNIC_ALLOC, cmd_len);
req->flags = VNIC_ALLOC_REQ_FLAGS_DEFAULT;
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
FLAG_SET(bp->flag_hwrm, VALID_VNIC_ID);
bp->vnic_id = resp->vnic_id;
return STATUS_SUCCESS;
}
static int bnxt_hwrm_vnic_free(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_vnic_free_input);
struct hwrm_vnic_free_input *req;
int rc;
if (!(FLAG_TEST(bp->flag_hwrm, VALID_VNIC_ID)))
return STATUS_SUCCESS;
req = (struct hwrm_vnic_free_input *)bp->hwrm_addr_req;
hwrm_init(bp, (void *)req, (u16)HWRM_VNIC_FREE, cmd_len);
req->vnic_id = bp->vnic_id;
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
if (rc)
return STATUS_FAILURE;
FLAG_RESET(bp->flag_hwrm, VALID_VNIC_ID);
return STATUS_SUCCESS;
}
static int bnxt_hwrm_vnic_cfg(struct bnxt *bp)
{
u16 cmd_len = (u16)sizeof(struct hwrm_vnic_cfg_input);
struct hwrm_vnic_cfg_input *req;
req = (struct hwrm_vnic_cfg_input *)bp->hwrm_addr_req;
hwrm_init(bp, (void *)req, (u16)HWRM_VNIC_CFG, cmd_len);
req->enables = VNIC_CFG_REQ_ENABLES_MRU;
req->mru = bp->mtu;
req->enables |= VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP;
req->dflt_ring_grp = bp->ring_grp_id;
req->vnic_id = bp->vnic_id;
return wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
}
static int set_phy_speed(struct bnxt *bp)
{
char name[20];
u16 flag = PHY_STATUS | PHY_SPEED | DETECT_MEDIA;
/* Query Link Status */
if (bnxt_hwrm_port_phy_qcfg(bp, flag) != STATUS_SUCCESS)
return STATUS_FAILURE;
switch (bp->current_link_speed) {
case PORT_PHY_QCFG_RESP_LINK_SPEED_100GB:
sprintf(name, "%s %s", str_100, str_gbps);
break;
case PORT_PHY_QCFG_RESP_LINK_SPEED_50GB:
sprintf(name, "%s %s", str_50, str_gbps);
break;
case PORT_PHY_QCFG_RESP_LINK_SPEED_40GB:
sprintf(name, "%s %s", str_40, str_gbps);
break;
case PORT_PHY_QCFG_RESP_LINK_SPEED_25GB:
sprintf(name, "%s %s", str_25, str_gbps);
break;
case PORT_PHY_QCFG_RESP_LINK_SPEED_20GB:
sprintf(name, "%s %s", str_20, str_gbps);
break;
case PORT_PHY_QCFG_RESP_LINK_SPEED_10GB:
sprintf(name, "%s %s", str_10, str_gbps);
break;
case PORT_PHY_QCFG_RESP_LINK_SPEED_2_5GB:
sprintf(name, "%s %s", str_2_5, str_gbps);
break;
case PORT_PHY_QCFG_RESP_LINK_SPEED_2GB:
sprintf(name, "%s %s", str_2, str_gbps);
break;
case PORT_PHY_QCFG_RESP_LINK_SPEED_1GB:
sprintf(name, "%s %s", str_1, str_gbps);
break;
case PORT_PHY_QCFG_RESP_LINK_SPEED_100MB:
sprintf(name, "%s %s", str_100, str_mbps);
break;
case PORT_PHY_QCFG_RESP_LINK_SPEED_10MB:
sprintf(name, "%s %s", str_10, str_mbps);
break;
default:
sprintf(name, "%s %x", str_unknown, bp->current_link_speed);
}
dbg_phy_speed(bp, name);
return STATUS_SUCCESS;
}
static int set_phy_link(struct bnxt *bp, u32 tmo)
{
int ret;
set_phy_speed(bp);
dbg_link_status(bp);
ret = STATUS_FAILURE;
if (bp->link_status == STATUS_LINK_ACTIVE) {
dbg_link_state(bp, tmo);
ret = STATUS_SUCCESS;
}
return ret;
}
static int get_phy_link(struct bnxt *bp)
{
u16 flag = PHY_STATUS | PHY_SPEED | DETECT_MEDIA;
dbg_chip_info(bp);
/* Query Link Status */
if (bnxt_hwrm_port_phy_qcfg(bp, flag) != STATUS_SUCCESS)
return STATUS_FAILURE;
set_phy_link(bp, 100);
return STATUS_SUCCESS;
}
static int bnxt_hwrm_set_async_event(struct bnxt *bp)
{
int rc;
u16 cmd_len = (u16)sizeof(struct hwrm_func_cfg_input);
struct hwrm_func_cfg_input *req;
req = (struct hwrm_func_cfg_input *)bp->hwrm_addr_req;
hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_CFG, cmd_len);
req->fid = (u16)HWRM_NA_SIGNATURE;
req->enables = FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR;
req->async_event_cr = bp->cq_ring_id;
rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__);
return rc;
}
int bnxt_hwrm_get_nvmem(struct bnxt *bp,
u16 data_len,
u16 option_num,
u16 dimensions,
u16 index_0)
{
u16 cmd_len = (u16)sizeof(struct hwrm_nvm_get_variable_input);
struct hwrm_nvm_get_variable_input *req;
req = (struct hwrm_nvm_get_variable_input *)bp->hwrm_addr_req;
hwrm_init(bp, (void *)req, (u16)HWRM_NVM_GET_VARIABLE, cmd_len);
req->dest_data_addr = bp->data_addr_mapping;
req->data_len = data_len;
req->option_num = option_num;
req->dimensions = dimensions;
req->index_0 = index_0;
return wait_resp(bp,
HWRM_CMD_FLASH_MULTIPLAYER(bp->hwrm_cmd_timeout),
cmd_len,
__func__);
}
static void set_medium(struct bnxt *bp)
{
switch (bp->link_set & LINK_SPEED_DRV_MASK) {
case LINK_SPEED_DRV_1G:
bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_1000MBPS);
break;
case LINK_SPEED_DRV_2_5G:
bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_2500MBPS);
break;
case LINK_SPEED_DRV_10G:
bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_10GBPS);
break;
case LINK_SPEED_DRV_25G:
bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_25GBPS);
break;
case LINK_SPEED_DRV_40G:
bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_40GBPS);
break;
case LINK_SPEED_DRV_50G:
bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_50GBPS);
break;
case LINK_SPEED_DRV_100G:
bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_100GBPS);
break;
case LINK_SPEED_DRV_200G:
bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_200GBPS);
break;
case LINK_SPEED_DRV_AUTONEG:
bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_AUTONEG);
break;
default:
bp->medium = SET_MEDIUM_DUPLEX(bp, MEDIUM_FULL_DUPLEX);
break;
}
}
static int bnxt_hwrm_get_link_speed(struct bnxt *bp)
{
u32 *ptr32 = (u32 *)bp->hwrm_addr_data;
if (bnxt_hwrm_get_nvmem(bp,
4,
(u16)LINK_SPEED_DRV_NUM,
1,
(u16)bp->port_idx) != STATUS_SUCCESS)
return STATUS_FAILURE;
bp->link_set = *ptr32;
bp->link_set &= SPEED_DRV_MASK;
set_medium(bp);
return STATUS_SUCCESS;
}
typedef int (*hwrm_func_t)(struct bnxt *bp);
hwrm_func_t down_chip[] = {
bnxt_hwrm_cfa_l2_filter_free, /* Free l2 filter */
bnxt_free_rx_iob, /* Free rx iob */
bnxt_hwrm_vnic_free, /* Free vnic */
bnxt_hwrm_ring_free_grp, /* Free ring group */
bnxt_hwrm_ring_free_rx, /* Free rx ring */
bnxt_hwrm_ring_free_tx, /* Free tx ring */
bnxt_hwrm_ring_free_cq, /* Free CQ ring */
bnxt_hwrm_stat_ctx_free, /* Free Stat ctx */
bnxt_hwrm_func_drv_unrgtr, /* unreg driver */
NULL,
};
hwrm_func_t bring_chip[] = {
bnxt_hwrm_ver_get, /* HWRM_VER_GET */
bnxt_hwrm_func_reset_req, /* HWRM_FUNC_RESET */
bnxt_hwrm_func_drv_rgtr, /* HWRM_FUNC_DRV_RGTR */
bnxt_hwrm_func_resource_qcaps, /* HWRM_FUNC_RESOURCE_QCAPS */
bnxt_hwrm_func_qcfg_req, /* HWRM_FUNC_QCFG */
bnxt_hwrm_func_qcaps_req, /* HWRM_FUNC_QCAPS */
bnxt_hwrm_get_link_speed, /* HWRM_NVM_GET_VARIABLE - 203 */
bnxt_hwrm_port_mac_cfg, /* HWRM_PORT_MAC_CFG */
bnxt_qphy_link, /* HWRM_PORT_PHY_QCFG */
bnxt_hwrm_func_cfg_req, /* HWRM_FUNC_CFG - ring resource*/
bnxt_hwrm_stat_ctx_alloc, /* Allocate Stat Ctx ID */
bnxt_hwrm_ring_alloc_cq, /* Allocate CQ Ring */
bnxt_hwrm_ring_alloc_tx, /* Allocate Tx ring */
bnxt_hwrm_ring_alloc_rx, /* Allocate Rx Ring */
bnxt_hwrm_ring_alloc_grp, /* Create Ring Group */
post_rx_buffers, /* Post RX buffers */
bnxt_hwrm_set_async_event, /* ENABLES_ASYNC_EVENT_CR */
bnxt_hwrm_vnic_alloc, /* Alloc VNIC */
bnxt_hwrm_vnic_cfg, /* Config VNIC */
bnxt_hwrm_cfa_l2_filter_alloc, /* Alloc L2 Filter */
get_phy_link, /* Get Physical Link */
NULL,
};
int bnxt_hwrm_run(hwrm_func_t cmds[], struct bnxt *bp, int flag)
{
hwrm_func_t *ptr;
int ret;
int status = STATUS_SUCCESS;
for (ptr = cmds; *ptr; ++ptr) {
ret = (*ptr)(bp);
if (ret) {
status = STATUS_FAILURE;
/* Continue till all cleanup routines are called */
if (flag)
return STATUS_FAILURE;
}
}
return status;
}
/* Broadcom ethernet driver Network interface APIs. */
static int bnxt_start(struct udevice *dev)
{
struct bnxt *bp = dev_get_priv(dev);
if (bnxt_hwrm_set_rx_mask(bp, RX_MASK) != STATUS_SUCCESS)
return STATUS_FAILURE;
bp->card_en = true;
return STATUS_SUCCESS;
}
static int bnxt_send(struct udevice *dev, void *packet, int length)
{
struct bnxt *bp = dev_get_priv(dev);
int len;
u16 entry;
dma_addr_t mapping;
if (bnxt_tx_avail(bp) < 1) {
dbg_no_tx_bd();
return -ENOBUFS;
}
entry = bp->tx.prod_id;
len = iob_pad(packet, length);
mapping = virt_to_bus(packet);
set_txq(bp, entry, mapping, len);
entry = NEXT_IDX(entry, bp->tx.ring_cnt);
dump_tx_pkt(packet, mapping, len);
bnxt_db_tx(bp, (u32)entry);
bp->tx.prod_id = entry;
bp->tx.cnt_req++;
bnxt_tx_complete(bp);
return 0;
}
static void bnxt_link_evt(struct bnxt *bp, struct cmpl_base *cmp)
{
struct hwrm_async_event_cmpl *evt;
evt = (struct hwrm_async_event_cmpl *)cmp;
switch (evt->event_id) {
case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
if (evt->event_data1 & 0x01)
bp->link_status = STATUS_LINK_ACTIVE;
else
bp->link_status = STATUS_LINK_DOWN;
set_phy_link(bp, 0);
break;
default:
break;
}
}
static int bnxt_recv(struct udevice *dev, int flags, uchar **packetp)
{
struct bnxt *bp = dev_get_priv(dev);
struct cmpl_base *cmp;
u16 old_cons_idx = bp->cq.cons_idx;
int done = SERVICE_NEXT_CQ_BD;
u32 cq_type;
while (done == SERVICE_NEXT_CQ_BD) {
cmp = (struct cmpl_base *)BD_NOW(bp->cq.bd_virt,
bp->cq.cons_idx,
sizeof(struct cmpl_base));
if ((cmp->info3_v & CMPL_BASE_V) ^ bp->cq.completion_bit)
break;
cq_type = cmp->type & CMPL_BASE_TYPE_MASK;
dump_evt((u8 *)cmp, cq_type, bp->cq.cons_idx);
dump_CQ(cmp, bp->cq.cons_idx);
switch (cq_type) {
case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
bnxt_link_evt(bp, cmp);
fallthrough;
case CMPL_BASE_TYPE_TX_L2:
case CMPL_BASE_TYPE_STAT_EJECT:
bnxt_adv_cq_index(bp, 1);
break;
case CMPL_BASE_TYPE_RX_L2:
done = bnxt_rx_complete(bp, (struct rx_pkt_cmpl *)cmp);
break;
default:
done = NO_MORE_CQ_BD_TO_SERVICE;
break;
}
}
if (bp->cq.cons_idx != old_cons_idx)
bnxt_db_cq(bp);
if (bp->rx.iob_recv == PKT_RECEIVED) {
*packetp = bp->rx.iob_rx;
return bp->rx.iob_len;
}
return -EAGAIN;
}
static void bnxt_stop(struct udevice *dev)
{
struct bnxt *bp = dev_get_priv(dev);
if (bp->card_en) {
bnxt_hwrm_set_rx_mask(bp, 0);
bp->card_en = false;
}
}
static int bnxt_free_pkt(struct udevice *dev, uchar *packet, int length)
{
struct bnxt *bp = dev_get_priv(dev);
dbg_rx_pkt(bp, __func__, packet, length);
bp->rx.iob_recv = PKT_DONE;
bp->rx.iob_len = 0;
bp->rx.iob_rx = NULL;
return 0;
}
static int bnxt_read_rom_hwaddr(struct udevice *dev)
{
struct eth_pdata *plat = dev_get_plat(dev);
struct bnxt *bp = dev_get_priv(dev);
memcpy(plat->enetaddr, bp->mac_set, ETH_ALEN);
return 0;
}
static const struct eth_ops bnxt_eth_ops = {
.start = bnxt_start,
.send = bnxt_send,
.recv = bnxt_recv,
.stop = bnxt_stop,
.free_pkt = bnxt_free_pkt,
.read_rom_hwaddr = bnxt_read_rom_hwaddr,
};
static const struct udevice_id bnxt_eth_ids[] = {
{ .compatible = "broadcom,nxe" },
{ }
};
static int bnxt_eth_bind(struct udevice *dev)
{
char name[20];
sprintf(name, "bnxt_eth%u", dev_seq(dev));
return device_set_name(dev, name);
}
static int bnxt_eth_probe(struct udevice *dev)
{
struct bnxt *bp = dev_get_priv(dev);
int ret;
ret = bnxt_alloc_mem(bp);
if (ret) {
printf("*** error: bnxt_alloc_mem failed! ***\n");
return ret;
}
bp->cardnum = dev_seq(dev);
bp->name = dev->name;
bp->pdev = (struct udevice *)dev;
bnxt_bring_pci(bp);
ret = bnxt_bring_chip(bp);
if (ret) {
printf("*** error: bnxt_bring_chip failed! ***\n");
return -ENODATA;
}
return 0;
}
static int bnxt_eth_remove(struct udevice *dev)
{
struct bnxt *bp = dev_get_priv(dev);
bnxt_down_chip(bp);
bnxt_free_mem(bp);
return 0;
}
static struct pci_device_id bnxt_nics[] = {
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NXT_57320)},
{}
};
U_BOOT_DRIVER(eth_bnxt) = {
.name = "eth_bnxt",
.id = UCLASS_ETH,
.of_match = bnxt_eth_ids,
.bind = bnxt_eth_bind,
.probe = bnxt_eth_probe,
.remove = bnxt_eth_remove,
.ops = &bnxt_eth_ops,
.priv_auto = sizeof(struct bnxt),
.plat_auto = sizeof(struct eth_pdata),
.flags = DM_FLAG_ACTIVE_DMA,
};
U_BOOT_PCI_DEVICE(eth_bnxt, bnxt_nics);
|