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
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <nxge_impl.h>
#include <npi_mac.h>
#include <npi_rxdma.h>
#include <nxge_hio.h>
#if defined(sun4v) && defined(NIU_LP_WORKAROUND)
static int nxge_herr2kerr(uint64_t);
static uint64_t nxge_init_hv_fzc_lp_op(p_nxge_t, uint64_t,
uint64_t, uint64_t, uint64_t, uint64_t);
#endif
static nxge_status_t nxge_init_fzc_rdc_pages(p_nxge_t,
uint16_t, dma_log_page_t *, dma_log_page_t *);
static nxge_status_t nxge_init_fzc_tdc_pages(p_nxge_t,
uint16_t, dma_log_page_t *, dma_log_page_t *);
/*
* The following interfaces are controlled by the
* function control registers. Some global registers
* are to be initialized by only byt one of the 2/4 functions.
* Use the test and set register.
*/
/*ARGSUSED*/
nxge_status_t
nxge_test_and_set(p_nxge_t nxgep, uint8_t tas)
{
npi_handle_t handle;
npi_status_t rs = NPI_SUCCESS;
handle = NXGE_DEV_NPI_HANDLE(nxgep);
if ((rs = npi_dev_func_sr_sr_get_set_clear(handle, tas))
!= NPI_SUCCESS) {
return (NXGE_ERROR | rs);
}
return (NXGE_OK);
}
nxge_status_t
nxge_set_fzc_multi_part_ctl(p_nxge_t nxgep, boolean_t mpc)
{
npi_handle_t handle;
npi_status_t rs = NPI_SUCCESS;
NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_set_fzc_multi_part_ctl"));
/*
* In multi-partitioning, the partition manager
* who owns function zero should set this multi-partition
* control bit.
*/
if (nxgep->use_partition && nxgep->function_num) {
return (NXGE_ERROR);
}
handle = NXGE_DEV_NPI_HANDLE(nxgep);
if ((rs = npi_fzc_mpc_set(handle, mpc)) != NPI_SUCCESS) {
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"<== nxge_set_fzc_multi_part_ctl"));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_set_fzc_multi_part_ctl"));
return (NXGE_OK);
}
nxge_status_t
nxge_get_fzc_multi_part_ctl(p_nxge_t nxgep, boolean_t *mpc_p)
{
npi_handle_t handle;
npi_status_t rs = NPI_SUCCESS;
NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_get_fzc_multi_part_ctl"));
handle = NXGE_DEV_NPI_HANDLE(nxgep);
if ((rs = npi_fzc_mpc_get(handle, mpc_p)) != NPI_SUCCESS) {
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"<== nxge_set_fzc_multi_part_ctl"));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_get_fzc_multi_part_ctl"));
return (NXGE_OK);
}
/*
* System interrupt registers that are under function zero
* management.
*/
nxge_status_t
nxge_fzc_intr_init(p_nxge_t nxgep)
{
nxge_status_t status = NXGE_OK;
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_fzc_intr_init"));
/* Configure the initial timer resolution */
if ((status = nxge_fzc_intr_tmres_set(nxgep)) != NXGE_OK) {
return (status);
}
if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
/*
* Set up the logical device group's logical devices that
* the group owns.
*/
if ((status = nxge_fzc_intr_ldg_num_set(nxgep)) != NXGE_OK)
goto fzc_intr_init_exit;
/* Configure the system interrupt data */
if ((status = nxge_fzc_intr_sid_set(nxgep)) != NXGE_OK)
goto fzc_intr_init_exit;
}
fzc_intr_init_exit:
NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_fzc_intr_init"));
return (status);
}
nxge_status_t
nxge_fzc_intr_ldg_num_set(p_nxge_t nxgep)
{
p_nxge_ldg_t ldgp;
p_nxge_ldv_t ldvp;
npi_handle_t handle;
int i, j;
npi_status_t rs = NPI_SUCCESS;
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_fzc_intr_ldg_num_set"));
if (nxgep->ldgvp == NULL) {
return (NXGE_ERROR);
}
ldgp = nxgep->ldgvp->ldgp;
ldvp = nxgep->ldgvp->ldvp;
if (ldgp == NULL || ldvp == NULL) {
return (NXGE_ERROR);
}
handle = NXGE_DEV_NPI_HANDLE(nxgep);
for (i = 0; i < nxgep->ldgvp->ldg_intrs; i++, ldgp++) {
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_fzc_intr_ldg_num_set "
"<== nxge_f(Neptune): # ldv %d "
"in group %d", ldgp->nldvs, ldgp->ldg));
for (j = 0; j < ldgp->nldvs; j++, ldvp++) {
rs = npi_fzc_ldg_num_set(handle, ldvp->ldv,
ldvp->ldg_assigned);
if (rs != NPI_SUCCESS) {
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"<== nxge_fzc_intr_ldg_num_set failed "
" rs 0x%x ldv %d ldg %d",
rs, ldvp->ldv, ldvp->ldg_assigned));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"<== nxge_fzc_intr_ldg_num_set OK "
" ldv %d ldg %d",
ldvp->ldv, ldvp->ldg_assigned));
}
}
NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_fzc_intr_ldg_num_set"));
return (NXGE_OK);
}
nxge_status_t
nxge_fzc_intr_tmres_set(p_nxge_t nxgep)
{
npi_handle_t handle;
npi_status_t rs = NPI_SUCCESS;
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_fzc_intr_tmrese_set"));
if (nxgep->ldgvp == NULL) {
return (NXGE_ERROR);
}
handle = NXGE_DEV_NPI_HANDLE(nxgep);
if ((rs = npi_fzc_ldg_timer_res_set(handle, nxgep->ldgvp->tmres))) {
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_fzc_intr_tmrese_set"));
return (NXGE_OK);
}
nxge_status_t
nxge_fzc_intr_sid_set(p_nxge_t nxgep)
{
npi_handle_t handle;
p_nxge_ldg_t ldgp;
fzc_sid_t sid;
int i;
npi_status_t rs = NPI_SUCCESS;
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_fzc_intr_sid_set"));
if (nxgep->ldgvp == NULL) {
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"<== nxge_fzc_intr_sid_set: no ldg"));
return (NXGE_ERROR);
}
handle = NXGE_DEV_NPI_HANDLE(nxgep);
ldgp = nxgep->ldgvp->ldgp;
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_fzc_intr_sid_set: #int %d", nxgep->ldgvp->ldg_intrs));
for (i = 0; i < nxgep->ldgvp->ldg_intrs; i++, ldgp++) {
sid.ldg = ldgp->ldg;
sid.niu = B_FALSE;
sid.func = ldgp->func;
sid.vector = ldgp->vector;
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_fzc_intr_sid_set(%d): func %d group %d "
"vector %d",
i, sid.func, sid.ldg, sid.vector));
rs = npi_fzc_sid_set(handle, sid);
if (rs != NPI_SUCCESS) {
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"<== nxge_fzc_intr_sid_set:failed 0x%x",
rs));
return (NXGE_ERROR | rs);
}
}
NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_fzc_intr_sid_set"));
return (NXGE_OK);
}
/*
* nxge_init_fzc_rdc
*
* Initialize all of a RDC's FZC_DMC registers.
* This is executed by the service domain, on behalf of a
* guest domain, who cannot access these registers.
*
* Arguments:
* nxgep
* channel The channel to initialize.
*
* NPI_NXGE function calls:
* nxge_init_fzc_rdc_pages()
*
* Context:
* Service Domain
*/
/*ARGSUSED*/
nxge_status_t
nxge_init_fzc_rdc(p_nxge_t nxgep, uint16_t channel)
{
nxge_status_t status = NXGE_OK;
dma_log_page_t page1, page2;
npi_handle_t handle;
rdc_red_para_t red;
/*
* Initialize the RxDMA channel-specific FZC control
* registers.
*/
NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_init_fzc_tdc"));
handle = NXGE_DEV_NPI_HANDLE(nxgep);
/* Reset RXDMA channel */
status = npi_rxdma_cfg_rdc_reset(handle, channel);
if (status != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"==> nxge_init_fzc_rdc: npi_rxdma_cfg_rdc_reset(%d) "
"returned 0x%08x", channel, status));
return (NXGE_ERROR | status);
}
/*
* These values have been copied from
* nxge_txdma.c:nxge_map_txdma_channel_cfg_ring().
*/
page1.page_num = 0;
page1.valid = 1;
page1.func_num = nxgep->function_num;
page1.mask = 0;
page1.value = 0;
page1.reloc = 0;
page2.page_num = 1;
page2.valid = 1;
page2.func_num = nxgep->function_num;
page2.mask = 0;
page2.value = 0;
page2.reloc = 0;
if (nxgep->niu_type == N2_NIU) {
#if !defined(NIU_HV_WORKAROUND)
status = NXGE_OK;
#else
NXGE_DEBUG_MSG((nxgep, RX_CTL,
"==> nxge_init_fzc_rxdma_channel: N2_NIU - NEED to "
"set up logical pages"));
/* Initialize the RXDMA logical pages */
status = nxge_init_fzc_rdc_pages(nxgep, channel,
&page1, &page2);
if (status != NXGE_OK) {
return (status);
}
#endif
} else if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
/* Initialize the RXDMA logical pages */
status = nxge_init_fzc_rdc_pages(nxgep, channel,
&page1, &page2);
if (status != NXGE_OK) {
return (status);
}
} else {
return (NXGE_ERROR);
}
/*
* Configure RED parameters
*/
red.value = 0;
red.bits.ldw.win = RXDMA_RED_WINDOW_DEFAULT;
red.bits.ldw.thre =
(nxgep->nxge_port_rcr_size - RXDMA_RED_LESS_ENTRIES);
red.bits.ldw.win_syn = RXDMA_RED_WINDOW_DEFAULT;
red.bits.ldw.thre_sync =
(nxgep->nxge_port_rcr_size - RXDMA_RED_LESS_ENTRIES);
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_fzc_rxdma_channel_red(thre_sync %d(%x))",
red.bits.ldw.thre_sync,
red.bits.ldw.thre_sync));
status |= npi_rxdma_cfg_wred_param(handle, channel, &red);
NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_init_fzc_rdc"));
return (status);
}
/*
* nxge_init_fzc_rxdma_channel
*
* Initialize all per-channel FZC_DMC registers.
*
* Arguments:
* nxgep
* channel The channel to start
*
* NPI_NXGE function calls:
* nxge_init_hv_fzc_rxdma_channel_pages()
* nxge_init_fzc_rxdma_channel_pages()
* nxge_init_fzc_rxdma_channel_red()
*
* Context:
* Service Domain
*/
/*ARGSUSED*/
nxge_status_t
nxge_init_fzc_rxdma_channel(p_nxge_t nxgep, uint16_t channel)
{
rx_rbr_ring_t *rbr_ring;
rx_rcr_ring_t *rcr_ring;
nxge_status_t status = NXGE_OK;
NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_init_fzc_rxdma_channel"));
rbr_ring = nxgep->rx_rbr_rings->rbr_rings[channel];
rcr_ring = nxgep->rx_rcr_rings->rcr_rings[channel];
if (nxgep->niu_type == N2_NIU) {
#ifndef NIU_HV_WORKAROUND
#if defined(sun4v) && defined(NIU_LP_WORKAROUND)
NXGE_DEBUG_MSG((nxgep, RX_CTL,
"==> nxge_init_fzc_rxdma_channel: N2_NIU - call HV "
"set up logical pages"));
/* Initialize the RXDMA logical pages */
status = nxge_init_hv_fzc_rxdma_channel_pages(nxgep, channel,
rbr_ring);
if (status != NXGE_OK) {
return (status);
}
#endif
status = NXGE_OK;
#else
NXGE_DEBUG_MSG((nxgep, RX_CTL,
"==> nxge_init_fzc_rxdma_channel: N2_NIU - NEED to "
"set up logical pages"));
/* Initialize the RXDMA logical pages */
status = nxge_init_fzc_rxdma_channel_pages(nxgep, channel,
rbr_ring);
if (status != NXGE_OK) {
return (status);
}
#endif
} else if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
/* Initialize the RXDMA logical pages */
status = nxge_init_fzc_rxdma_channel_pages(nxgep,
channel, rbr_ring);
if (status != NXGE_OK) {
return (status);
}
} else {
return (NXGE_ERROR);
}
/* Configure RED parameters */
status = nxge_init_fzc_rxdma_channel_red(nxgep, channel, rcr_ring);
NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_init_fzc_rxdma_channel"));
return (status);
}
/*
* nxge_init_fzc_rdc_pages
*
* Configure a TDC's logical pages.
*
* This function is executed by the service domain, on behalf of
* a guest domain, to whom this RDC has been loaned.
*
* Arguments:
* nxgep
* channel The channel to initialize.
* page0 Logical page 0 definition.
* page1 Logical page 1 definition.
*
* Notes:
* I think that this function can be called from any
* domain, but I need to check.
*
* NPI/NXGE function calls:
* hv_niu_tx_logical_page_conf()
* hv_niu_tx_logical_page_info()
*
* Context:
* Any domain
*/
nxge_status_t
nxge_init_fzc_rdc_pages(
p_nxge_t nxgep,
uint16_t channel,
dma_log_page_t *page0,
dma_log_page_t *page1)
{
npi_handle_t handle;
npi_status_t rs;
uint64_t page_handle;
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_fzc_txdma_channel_pages"));
#ifndef NIU_HV_WORKAROUND
if (nxgep->niu_type == N2_NIU) {
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"<== nxge_init_fzc_rdc_pages: "
"N2_NIU: no need to set rxdma logical pages"));
return (NXGE_OK);
}
#else
if (nxgep->niu_type == N2_NIU) {
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"<== nxge_init_fzc_rdc_pages: "
"N2_NIU: NEED to set rxdma logical pages"));
}
#endif
/*
* Initialize logical page 1.
*/
handle = NXGE_DEV_NPI_HANDLE(nxgep);
if ((rs = npi_rxdma_cfg_logical_page(handle, channel, page0))
!= NPI_SUCCESS)
return (NXGE_ERROR | rs);
/*
* Initialize logical page 2.
*/
if ((rs = npi_rxdma_cfg_logical_page(handle, channel, page1))
!= NPI_SUCCESS)
return (NXGE_ERROR | rs);
/*
* Initialize the page handle.
* (In the current driver, this is always set to 0.)
*/
page_handle = 0;
rs = npi_rxdma_cfg_logical_page_handle(handle, channel, page_handle);
if (rs == NPI_SUCCESS) {
return (NXGE_OK);
} else {
return (NXGE_ERROR | rs);
}
}
/*ARGSUSED*/
nxge_status_t
nxge_init_fzc_rxdma_channel_pages(p_nxge_t nxgep,
uint16_t channel, p_rx_rbr_ring_t rbrp)
{
npi_handle_t handle;
dma_log_page_t cfg;
npi_status_t rs = NPI_SUCCESS;
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_fzc_rxdma_channel_pages"));
handle = NXGE_DEV_NPI_HANDLE(nxgep);
/*
* Initialize logical page 1.
*/
cfg.func_num = nxgep->function_num;
cfg.page_num = 0;
cfg.valid = rbrp->page_valid.bits.ldw.page0;
cfg.value = rbrp->page_value_1.value;
cfg.mask = rbrp->page_mask_1.value;
cfg.reloc = rbrp->page_reloc_1.value;
rs = npi_rxdma_cfg_logical_page(handle, channel,
(p_dma_log_page_t)&cfg);
if (rs != NPI_SUCCESS) {
return (NXGE_ERROR | rs);
}
/*
* Initialize logical page 2.
*/
cfg.page_num = 1;
cfg.valid = rbrp->page_valid.bits.ldw.page1;
cfg.value = rbrp->page_value_2.value;
cfg.mask = rbrp->page_mask_2.value;
cfg.reloc = rbrp->page_reloc_2.value;
rs = npi_rxdma_cfg_logical_page(handle, channel, &cfg);
if (rs != NPI_SUCCESS) {
return (NXGE_ERROR | rs);
}
/* Initialize the page handle */
rs = npi_rxdma_cfg_logical_page_handle(handle, channel,
rbrp->page_hdl.bits.ldw.handle);
if (rs != NPI_SUCCESS) {
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"<== nxge_init_fzc_rxdma_channel_pages"));
return (NXGE_OK);
}
/*ARGSUSED*/
nxge_status_t
nxge_init_fzc_rxdma_channel_red(p_nxge_t nxgep,
uint16_t channel, p_rx_rcr_ring_t rcr_p)
{
npi_handle_t handle;
rdc_red_para_t red;
npi_status_t rs = NPI_SUCCESS;
NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_init_fzc_rxdma_channel_red"));
handle = NXGE_DEV_NPI_HANDLE(nxgep);
red.value = 0;
red.bits.ldw.win = RXDMA_RED_WINDOW_DEFAULT;
red.bits.ldw.thre = (rcr_p->comp_size - RXDMA_RED_LESS_ENTRIES);
red.bits.ldw.win_syn = RXDMA_RED_WINDOW_DEFAULT;
red.bits.ldw.thre_sync = (rcr_p->comp_size - RXDMA_RED_LESS_ENTRIES);
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_fzc_rxdma_channel_red(thre_sync %d(%x))",
red.bits.ldw.thre_sync,
red.bits.ldw.thre_sync));
rs = npi_rxdma_cfg_wred_param(handle, channel, &red);
if (rs != NPI_SUCCESS) {
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"<== nxge_init_fzc_rxdma_channel_red"));
return (NXGE_OK);
}
/*
* nxge_init_fzc_tdc
*
* Initialize all of a TDC's FZC_DMC registers.
* This is executed by the service domain, on behalf of a
* guest domain, who cannot access these registers.
*
* Arguments:
* nxgep
* channel The channel to initialize.
*
* NPI_NXGE function calls:
* nxge_init_fzc_tdc_pages()
* npi_txc_dma_max_burst_set()
*
* Registers accessed:
* TXC_DMA_MAX_BURST
*
* Context:
* Service Domain
*/
/*ARGSUSED*/
nxge_status_t
nxge_init_fzc_tdc(p_nxge_t nxgep, uint16_t channel)
{
nxge_status_t status = NXGE_OK;
dma_log_page_t page1, page2;
npi_handle_t handle;
NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_init_fzc_tdc"));
/*
* These values have been copied from
* nxge_txdma.c:nxge_map_txdma_channel_cfg_ring().
*/
page1.page_num = 0;
page1.valid = 1;
page1.func_num = nxgep->function_num;
page1.mask = 0;
page1.value = 0;
page1.reloc = 0;
page1.page_num = 1;
page1.valid = 1;
page1.func_num = nxgep->function_num;
page1.mask = 0;
page1.value = 0;
page1.reloc = 0;
#ifdef NIU_HV_WORKAROUND
if (nxgep->niu_type == N2_NIU) {
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_fzc_txdma_channel "
"N2_NIU: NEED to set up txdma logical pages"));
/* Initialize the TXDMA logical pages */
(void) nxge_init_fzc_tdc_pages(nxgep, channel,
&page1, &page2);
}
#endif
if (nxgep->niu_type != N2_NIU) {
if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
/* Initialize the TXDMA logical pages */
(void) nxge_init_fzc_tdc_pages(nxgep, channel,
&page1, &page2);
} else
return (NXGE_ERROR);
}
/*
* Configure the TXC DMA Max Burst value.
*
* PRM.13.5
*
* TXC DMA Max Burst. TXC_DMA_MAX (FZC_TXC + 0000016)
* 19:0 dma_max_burst RW
* Max burst value associated with DMA. Used by DRR engine
* for computing when DMA has gone into deficit.
*/
handle = NXGE_DEV_NPI_HANDLE(nxgep);
(void) npi_txc_dma_max_burst_set(
handle, channel, TXC_DMA_MAX_BURST_DEFAULT);
NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_init_fzc_tdc"));
return (status);
}
/*ARGSUSED*/
nxge_status_t
nxge_init_fzc_txdma_channel(p_nxge_t nxgep, uint16_t channel,
p_tx_ring_t tx_ring_p, p_tx_mbox_t mbox_p)
{
nxge_status_t status = NXGE_OK;
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_fzc_txdma_channel"));
if (nxgep->niu_type == N2_NIU) {
#ifndef NIU_HV_WORKAROUND
#if defined(sun4v) && defined(NIU_LP_WORKAROUND)
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_fzc_txdma_channel "
"N2_NIU: call HV to set up txdma logical pages"));
status = nxge_init_hv_fzc_txdma_channel_pages(nxgep, channel,
tx_ring_p);
if (status != NXGE_OK) {
return (status);
}
#endif
status = NXGE_OK;
#else
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_fzc_txdma_channel "
"N2_NIU: NEED to set up txdma logical pages"));
/* Initialize the TXDMA logical pages */
(void) nxge_init_fzc_txdma_channel_pages(nxgep, channel,
tx_ring_p);
#endif
} else if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
/* Initialize the TXDMA logical pages */
(void) nxge_init_fzc_txdma_channel_pages(nxgep,
channel, tx_ring_p);
} else {
return (NXGE_ERROR);
}
/*
* Configure Transmit DRR Weight parameters
* (It actually programs the TXC max burst register).
*/
(void) nxge_init_fzc_txdma_channel_drr(nxgep, channel, tx_ring_p);
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"<== nxge_init_fzc_txdma_channel"));
return (status);
}
nxge_status_t
nxge_init_fzc_rx_common(p_nxge_t nxgep)
{
npi_handle_t handle;
npi_status_t rs = NPI_SUCCESS;
nxge_status_t status = NXGE_OK;
nxge_rdc_grp_t *rdc_grp_p;
clock_t lbolt;
int table;
nxge_hw_pt_cfg_t *hardware;
NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_init_fzc_rx_common"));
handle = NXGE_DEV_NPI_HANDLE(nxgep);
if (!handle.regp) {
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_fzc_rx_common null ptr"));
return (NXGE_ERROR);
}
/*
* Configure the rxdma clock divider
* This is the granularity counter based on
* the hardware system clock (i.e. 300 Mhz) and
* it is running around 3 nanoseconds.
* So, set the clock divider counter to 1000 to get
* microsecond granularity.
* For example, for a 3 microsecond timeout, the timeout
* will be set to 1.
*/
rs = npi_rxdma_cfg_clock_div_set(handle, RXDMA_CK_DIV_DEFAULT);
if (rs != NPI_SUCCESS)
return (NXGE_ERROR | rs);
#if defined(__i386)
rs = npi_rxdma_cfg_32bitmode_enable(handle);
if (rs != NPI_SUCCESS)
return (NXGE_ERROR | rs);
rs = npi_txdma_mode32_set(handle, B_TRUE);
if (rs != NPI_SUCCESS)
return (NXGE_ERROR | rs);
#endif
/*
* Enable WRED and program an initial value.
* Use time to set the initial random number.
*/
(void) drv_getparm(LBOLT, &lbolt);
rs = npi_rxdma_cfg_red_rand_init(handle, (uint16_t)lbolt);
if (rs != NPI_SUCCESS)
return (NXGE_ERROR | rs);
hardware = &nxgep->pt_config.hw_config;
for (table = 0; table < NXGE_MAX_RDC_GRPS; table++) {
/* Does this table belong to <nxgep>? */
if (hardware->grpids[table] == (nxgep->function_num + 256)) {
rdc_grp_p = &nxgep->pt_config.rdc_grps[table];
status = nxge_init_fzc_rdc_tbl(nxgep, rdc_grp_p, table);
}
}
/* Ethernet Timeout Counter (?) */
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"<== nxge_init_fzc_rx_common:status 0x%08x", status));
return (status);
}
nxge_status_t
nxge_init_fzc_rdc_tbl(p_nxge_t nxge, nxge_rdc_grp_t *group, int rdc_tbl)
{
nxge_hio_data_t *nhd = (nxge_hio_data_t *)nxge->nxge_hw_p->hio;
nx_rdc_tbl_t *table;
npi_handle_t handle;
npi_status_t rs = NPI_SUCCESS;
nxge_status_t status = NXGE_OK;
NXGE_DEBUG_MSG((nxge, DMA_CTL, "==> nxge_init_fzc_rdc_tbl(%d)", table));
/* This RDC table must have been previously bound to <nxge>. */
MUTEX_ENTER(&nhd->lock);
table = &nhd->rdc_tbl[rdc_tbl];
if (table->nxge != (uintptr_t)nxge) {
MUTEX_EXIT(&nhd->lock);
NXGE_ERROR_MSG((nxge, DMA_CTL,
"nxge_init_fzc_rdc_tbl(%d): not owner", table));
return (NXGE_ERROR);
} else {
table->map = group->map;
}
MUTEX_EXIT(&nhd->lock);
handle = NXGE_DEV_NPI_HANDLE(nxge);
rs = npi_rxdma_rdc_table_config(handle, rdc_tbl,
group->map, group->max_rdcs);
if (rs != NPI_SUCCESS) {
status = NXGE_ERROR | rs;
}
NXGE_DEBUG_MSG((nxge, DMA_CTL, "<== nxge_init_fzc_rdc_tbl(%d)", table));
return (status);
}
static
int
rdc_tbl_bind(p_nxge_t nxge, int rdc_tbl)
{
nxge_hio_data_t *nhd = (nxge_hio_data_t *)nxge->nxge_hw_p->hio;
nx_rdc_tbl_t *table;
int i;
NXGE_DEBUG_MSG((nxge, DMA_CTL, "==> nxge_fzc_rdc_tbl_bind"));
MUTEX_ENTER(&nhd->lock);
/* is the caller asking for a particular table? */
if (rdc_tbl >= 0 && rdc_tbl < NXGE_MAX_RDC_GROUPS) {
table = &nhd->rdc_tbl[rdc_tbl];
if (table->nxge == 0) {
table->nxge = (uintptr_t)nxge; /* It is now bound. */
NXGE_DEBUG_MSG((nxge, DMA_CTL,
"<== nxge_fzc_rdc_tbl_bind(%d)", rdc_tbl));
MUTEX_EXIT(&nhd->lock);
return (rdc_tbl);
}
} else { /* The caller will take any old RDC table. */
for (i = 0; i < NXGE_MAX_RDC_GROUPS; i++) {
nx_rdc_tbl_t *table = &nhd->rdc_tbl[i];
if (table->nxge == 0) {
table->nxge = (uintptr_t)nxge;
/* It is now bound. */
MUTEX_EXIT(&nhd->lock);
NXGE_DEBUG_MSG((nxge, DMA_CTL,
"<== nxge_fzc_rdc_tbl_bind: %d", i));
return (i);
}
}
}
MUTEX_EXIT(&nhd->lock);
NXGE_DEBUG_MSG((nxge, HIO_CTL, "<== nxge_fzc_rdc_tbl_bind"));
return (-EBUSY); /* RDC tables are bound. */
}
int
nxge_fzc_rdc_tbl_bind(
nxge_t *nxge,
int grp_index,
int acceptNoSubstitutes)
{
nxge_hw_pt_cfg_t *hardware;
int index;
hardware = &nxge->pt_config.hw_config;
if ((index = rdc_tbl_bind(nxge, grp_index)) < 0) {
if (acceptNoSubstitutes)
return (index);
index = rdc_tbl_bind(nxge, grp_index);
if (index < 0) {
NXGE_ERROR_MSG((nxge, OBP_CTL,
"nxge_fzc_rdc_tbl_init: "
"there are no free RDC tables!"));
return (index);
}
}
hardware->grpids[index] = nxge->function_num + 256;
return (index);
}
int
nxge_fzc_rdc_tbl_unbind(p_nxge_t nxge, int rdc_tbl)
{
nxge_hio_data_t *nhd = (nxge_hio_data_t *)nxge->nxge_hw_p->hio;
nx_rdc_tbl_t *table;
if (nhd == NULL)
return (0);
NXGE_DEBUG_MSG((nxge, DMA_CTL, "==> nxge_fzc_rdc_tbl_unbind(%d)",
rdc_tbl));
MUTEX_ENTER(&nhd->lock);
table = &nhd->rdc_tbl[rdc_tbl];
if (table->nxge != (uintptr_t)nxge) {
NXGE_ERROR_MSG((nxge, DMA_CTL,
"nxge_fzc_rdc_tbl_unbind(%d): func%d not owner",
nxge->function_num, rdc_tbl));
MUTEX_EXIT(&nhd->lock);
return (EINVAL);
} else {
bzero(table, sizeof (*table));
}
MUTEX_EXIT(&nhd->lock);
NXGE_DEBUG_MSG((nxge, DMA_CTL, "<== nxge_fzc_rdc_tbl_unbind(%d)",
rdc_tbl));
return (0);
}
nxge_status_t
nxge_init_fzc_rxdma_port(p_nxge_t nxgep)
{
npi_handle_t handle;
p_nxge_dma_pt_cfg_t p_all_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
hostinfo_t hostinfo;
int i;
npi_status_t rs = NPI_SUCCESS;
p_nxge_class_pt_cfg_t p_class_cfgp;
NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_init_fzc_rxdma_port"));
p_all_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
p_cfgp = (p_nxge_hw_pt_cfg_t)&p_all_cfgp->hw_config;
handle = NXGE_DEV_NPI_HANDLE(nxgep);
/*
* Initialize the port scheduler DRR weight.
* npi_rxdma_cfg_port_ddr_weight();
*/
if ((nxgep->mac.portmode == PORT_1G_COPPER) ||
(nxgep->mac.portmode == PORT_1G_FIBER) ||
(nxgep->mac.portmode == PORT_1G_TN1010) ||
(nxgep->mac.portmode == PORT_1G_SERDES)) {
rs = npi_rxdma_cfg_port_ddr_weight(handle,
nxgep->function_num, NXGE_RX_DRR_WT_1G);
if (rs != NPI_SUCCESS) {
return (NXGE_ERROR | rs);
}
}
/* Program the default RDC of a port */
rs = npi_rxdma_cfg_default_port_rdc(handle, nxgep->function_num,
p_cfgp->def_rdc);
if (rs != NPI_SUCCESS) {
return (NXGE_ERROR | rs);
}
/*
* Configure the MAC host info table with RDC tables
*/
hostinfo.value = 0;
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
for (i = 0; i < p_cfgp->max_macs; i++) {
hostinfo.bits.w0.rdc_tbl_num = p_cfgp->def_mac_rxdma_grpid;
hostinfo.bits.w0.mac_pref = p_cfgp->mac_pref;
if (p_class_cfgp->mac_host_info[i].flag) {
hostinfo.bits.w0.rdc_tbl_num =
p_class_cfgp->mac_host_info[i].rdctbl;
hostinfo.bits.w0.mac_pref =
p_class_cfgp->mac_host_info[i].mpr_npr;
}
rs = npi_mac_hostinfo_entry(handle, OP_SET,
nxgep->function_num, i, &hostinfo);
if (rs != NPI_SUCCESS)
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"<== nxge_init_fzc_rxdma_port rs 0x%08x", rs));
return (NXGE_OK);
}
nxge_status_t
nxge_fzc_dmc_def_port_rdc(p_nxge_t nxgep, uint8_t port, uint16_t rdc)
{
npi_status_t rs = NPI_SUCCESS;
rs = npi_rxdma_cfg_default_port_rdc(nxgep->npi_reg_handle,
port, rdc);
if (rs & NPI_FAILURE)
return (NXGE_ERROR | rs);
return (NXGE_OK);
}
/*
* nxge_init_fzc_tdc_pages
*
* Configure a TDC's logical pages.
*
* This function is executed by the service domain, on behalf of
* a guest domain, to whom this TDC has been loaned.
*
* Arguments:
* nxgep
* channel The channel to initialize.
* page0 Logical page 0 definition.
* page1 Logical page 1 definition.
*
* Notes:
* I think that this function can be called from any
* domain, but I need to check.
*
* NPI/NXGE function calls:
* hv_niu_tx_logical_page_conf()
* hv_niu_tx_logical_page_info()
*
* Context:
* Any domain
*/
nxge_status_t
nxge_init_fzc_tdc_pages(
p_nxge_t nxgep,
uint16_t channel,
dma_log_page_t *page0,
dma_log_page_t *page1)
{
npi_handle_t handle;
npi_status_t rs;
log_page_hdl_t page_handle;
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_fzc_txdma_channel_pages"));
#ifndef NIU_HV_WORKAROUND
if (nxgep->niu_type == N2_NIU) {
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"<== nxge_init_fzc_tdc_pages: "
"N2_NIU: no need to set txdma logical pages"));
return (NXGE_OK);
}
#else
if (nxgep->niu_type == N2_NIU) {
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"<== nxge_init_fzc_tdc_pages: "
"N2_NIU: NEED to set txdma logical pages"));
}
#endif
/*
* Initialize logical page 1.
*/
handle = NXGE_DEV_NPI_HANDLE(nxgep);
if ((rs = npi_txdma_log_page_set(handle, channel, page0))
!= NPI_SUCCESS)
return (NXGE_ERROR | rs);
/*
* Initialize logical page 2.
*/
if ((rs = npi_txdma_log_page_set(handle, channel, page1))
!= NPI_SUCCESS)
return (NXGE_ERROR | rs);
/*
* Initialize the page handle.
* (In the current driver, this is always set to 0.)
*/
page_handle.value = 0;
rs = npi_txdma_log_page_handle_set(handle, channel, &page_handle);
if (rs == NPI_SUCCESS) {
return (NXGE_OK);
} else {
return (NXGE_ERROR | rs);
}
}
nxge_status_t
nxge_init_fzc_txdma_channel_pages(p_nxge_t nxgep, uint16_t channel,
p_tx_ring_t tx_ring_p)
{
npi_handle_t handle;
dma_log_page_t cfg;
npi_status_t rs = NPI_SUCCESS;
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_fzc_txdma_channel_pages"));
#ifndef NIU_HV_WORKAROUND
if (nxgep->niu_type == N2_NIU) {
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"<== nxge_init_fzc_txdma_channel_pages: "
"N2_NIU: no need to set txdma logical pages"));
return (NXGE_OK);
}
#else
if (nxgep->niu_type == N2_NIU) {
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"<== nxge_init_fzc_txdma_channel_pages: "
"N2_NIU: NEED to set txdma logical pages"));
}
#endif
/*
* Initialize logical page 1.
*/
handle = NXGE_DEV_NPI_HANDLE(nxgep);
cfg.func_num = nxgep->function_num;
cfg.page_num = 0;
cfg.valid = tx_ring_p->page_valid.bits.ldw.page0;
cfg.value = tx_ring_p->page_value_1.value;
cfg.mask = tx_ring_p->page_mask_1.value;
cfg.reloc = tx_ring_p->page_reloc_1.value;
rs = npi_txdma_log_page_set(handle, channel,
(p_dma_log_page_t)&cfg);
if (rs != NPI_SUCCESS) {
return (NXGE_ERROR | rs);
}
/*
* Initialize logical page 2.
*/
cfg.page_num = 1;
cfg.valid = tx_ring_p->page_valid.bits.ldw.page1;
cfg.value = tx_ring_p->page_value_2.value;
cfg.mask = tx_ring_p->page_mask_2.value;
cfg.reloc = tx_ring_p->page_reloc_2.value;
rs = npi_txdma_log_page_set(handle, channel, &cfg);
if (rs != NPI_SUCCESS) {
return (NXGE_ERROR | rs);
}
/* Initialize the page handle */
rs = npi_txdma_log_page_handle_set(handle, channel,
&tx_ring_p->page_hdl);
if (rs == NPI_SUCCESS) {
return (NXGE_OK);
} else {
return (NXGE_ERROR | rs);
}
}
nxge_status_t
nxge_init_fzc_txdma_channel_drr(p_nxge_t nxgep, uint16_t channel,
p_tx_ring_t tx_ring_p)
{
npi_status_t rs = NPI_SUCCESS;
npi_handle_t handle;
handle = NXGE_DEV_NPI_HANDLE(nxgep);
rs = npi_txc_dma_max_burst_set(handle, channel,
tx_ring_p->max_burst.value);
if (rs == NPI_SUCCESS) {
return (NXGE_OK);
} else {
return (NXGE_ERROR | rs);
}
}
nxge_status_t
nxge_fzc_sys_err_mask_set(p_nxge_t nxgep, uint64_t mask)
{
npi_status_t rs = NPI_SUCCESS;
npi_handle_t handle;
handle = NXGE_DEV_NPI_HANDLE(nxgep);
rs = npi_fzc_sys_err_mask_set(handle, mask);
if (rs == NPI_SUCCESS) {
return (NXGE_OK);
} else {
return (NXGE_ERROR | rs);
}
}
/*
* nxge_init_hv_fzc_txdma_channel_pages
*
* Configure a TDC's logical pages.
*
* Arguments:
* nxgep
* channel The channel to initialize.
* tx_ring_p The transmit ring.
*
* Notes:
* I think that this function can be called from any
* domain, but I need to check.
*
* NPI/NXGE function calls:
* hv_niu_tx_logical_page_conf()
* hv_niu_tx_logical_page_info()
*
* Context:
* Any domain
*/
#if defined(sun4v) && defined(NIU_LP_WORKAROUND)
nxge_status_t
nxge_init_hv_fzc_txdma_channel_pages(p_nxge_t nxgep, uint16_t channel,
p_tx_ring_t tx_ring_p)
{
int err;
uint64_t hverr;
#ifdef DEBUG
uint64_t ra, size;
#endif
NXGE_DEBUG_MSG((nxgep, TX_CTL,
"==> nxge_init_hv_fzc_txdma_channel_pages"));
if (tx_ring_p->hv_set) {
return (NXGE_OK);
}
/*
* Initialize logical page 1 for data buffers.
*/
hverr = nxge_init_hv_fzc_lp_op(nxgep, (uint64_t)channel,
(uint64_t)0, N2NIU_TX_LP_CONF,
tx_ring_p->hv_tx_buf_base_ioaddr_pp,
tx_ring_p->hv_tx_buf_ioaddr_size);
err = (nxge_status_t)nxge_herr2kerr(hverr);
if (err != 0) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"<== nxge_init_hv_fzc_txdma_channel_pages: channel %d "
"error status 0x%x "
"(page 0 data buf) hverr 0x%llx "
"ioaddr_pp $%p "
"size 0x%llx ",
channel,
err,
hverr,
tx_ring_p->hv_tx_buf_base_ioaddr_pp,
tx_ring_p->hv_tx_buf_ioaddr_size));
return (NXGE_ERROR | err);
}
#ifdef DEBUG
ra = size = 0;
hverr = nxge_init_hv_fzc_lp_op(nxgep, (uint64_t)channel,
(uint64_t)0, N2NIU_TX_LP_INFO,
(uint64_t)&ra, (uint64_t)&size);
NXGE_DEBUG_MSG((nxgep, TX_CTL,
"==> nxge_init_hv_fzc_txdma_channel_pages: channel %d "
"ok status 0x%x "
"(page 0 data buf) hverr 0x%llx "
"set ioaddr_pp $%p "
"set size 0x%llx "
"get ra ioaddr_pp $%p "
"get size 0x%llx ",
channel,
err,
hverr,
tx_ring_p->hv_tx_buf_base_ioaddr_pp,
tx_ring_p->hv_tx_buf_ioaddr_size,
ra,
size));
#endif
NXGE_DEBUG_MSG((nxgep, TX_CTL,
"==> nxge_init_hv_fzc_txdma_channel_pages: channel %d "
"(page 0 data buf) hverr 0x%llx "
"ioaddr_pp $%p "
"size 0x%llx ",
channel,
hverr,
tx_ring_p->hv_tx_buf_base_ioaddr_pp,
tx_ring_p->hv_tx_buf_ioaddr_size));
/*
* Initialize logical page 2 for control buffers.
*/
hverr = nxge_init_hv_fzc_lp_op(nxgep, (uint64_t)channel,
(uint64_t)1, N2NIU_TX_LP_CONF,
tx_ring_p->hv_tx_cntl_base_ioaddr_pp,
tx_ring_p->hv_tx_cntl_ioaddr_size);
err = (nxge_status_t)nxge_herr2kerr(hverr);
NXGE_DEBUG_MSG((nxgep, TX_CTL,
"==> nxge_init_hv_fzc_txdma_channel_pages: channel %d"
"ok status 0x%x "
"(page 1 cntl buf) hverr 0x%llx "
"ioaddr_pp $%p "
"size 0x%llx ",
channel,
err,
hverr,
tx_ring_p->hv_tx_cntl_base_ioaddr_pp,
tx_ring_p->hv_tx_cntl_ioaddr_size));
if (err != 0) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"<== nxge_init_hv_fzc_txdma_channel_pages: channel %d"
"error status 0x%x "
"(page 1 cntl buf) hverr 0x%llx "
"ioaddr_pp $%p "
"size 0x%llx ",
channel,
err,
hverr,
tx_ring_p->hv_tx_cntl_base_ioaddr_pp,
tx_ring_p->hv_tx_cntl_ioaddr_size));
return (NXGE_ERROR | err);
}
#ifdef DEBUG
ra = size = 0;
hverr = nxge_init_hv_fzc_lp_op(nxgep, (uint64_t)channel,
(uint64_t)1, N2NIU_TX_LP_INFO,
(uint64_t)&ra, (uint64_t)&size);
NXGE_DEBUG_MSG((nxgep, TX_CTL,
"==> nxge_init_hv_fzc_txdma_channel_pages: channel %d "
"(page 1 cntl buf) hverr 0x%llx "
"set ioaddr_pp $%p "
"set size 0x%llx "
"get ra ioaddr_pp $%p "
"get size 0x%llx ",
channel,
hverr,
tx_ring_p->hv_tx_cntl_base_ioaddr_pp,
tx_ring_p->hv_tx_cntl_ioaddr_size,
ra,
size));
#endif
tx_ring_p->hv_set = B_TRUE;
NXGE_DEBUG_MSG((nxgep, TX_CTL,
"<== nxge_init_hv_fzc_txdma_channel_pages"));
return (NXGE_OK);
}
/*ARGSUSED*/
nxge_status_t
nxge_init_hv_fzc_rxdma_channel_pages(p_nxge_t nxgep,
uint16_t channel, p_rx_rbr_ring_t rbrp)
{
int err;
uint64_t hverr;
#ifdef DEBUG
uint64_t ra, size;
#endif
NXGE_DEBUG_MSG((nxgep, RX_CTL,
"==> nxge_init_hv_fzc_rxdma_channel_pages"));
if (rbrp->hv_set) {
return (NXGE_OK);
}
/* Initialize data buffers for page 0 */
hverr = nxge_init_hv_fzc_lp_op(nxgep, (uint64_t)channel,
(uint64_t)0, N2NIU_RX_LP_CONF,
rbrp->hv_rx_buf_base_ioaddr_pp,
rbrp->hv_rx_buf_ioaddr_size);
err = (nxge_status_t)nxge_herr2kerr(hverr);
if (err != 0) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"<== nxge_init_hv_fzc_rxdma_channel_pages: channel %d"
"error status 0x%x "
"(page 0 data buf) hverr 0x%llx "
"ioaddr_pp $%p "
"size 0x%llx ",
channel,
err,
hverr,
rbrp->hv_rx_buf_base_ioaddr_pp,
rbrp->hv_rx_buf_ioaddr_size));
return (NXGE_ERROR | err);
}
#ifdef DEBUG
ra = size = 0;
hverr = nxge_init_hv_fzc_lp_op(nxgep, (uint64_t)channel,
(uint64_t)0, N2NIU_RX_LP_INFO,
(uint64_t)&ra, (uint64_t)&size);
NXGE_DEBUG_MSG((nxgep, RX_CTL,
"==> nxge_init_hv_fzc_rxdma_channel_pages: channel %d "
"ok status 0x%x "
"(page 0 data buf) hverr 0x%llx "
"set databuf ioaddr_pp $%p "
"set databuf size 0x%llx "
"get databuf ra ioaddr_pp %p "
"get databuf size 0x%llx",
channel,
err,
hverr,
rbrp->hv_rx_buf_base_ioaddr_pp,
rbrp->hv_rx_buf_ioaddr_size,
ra,
size));
#endif
/* Initialize control buffers for logical page 1. */
hverr = nxge_init_hv_fzc_lp_op(nxgep, (uint64_t)channel,
(uint64_t)1, N2NIU_RX_LP_CONF,
rbrp->hv_rx_cntl_base_ioaddr_pp,
rbrp->hv_rx_cntl_ioaddr_size);
err = (nxge_status_t)nxge_herr2kerr(hverr);
if (err != 0) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"<== nxge_init_hv_fzc_rxdma_channel_pages: channel %d"
"error status 0x%x "
"(page 1 cntl buf) hverr 0x%llx "
"ioaddr_pp $%p "
"size 0x%llx ",
channel,
err,
hverr,
rbrp->hv_rx_buf_base_ioaddr_pp,
rbrp->hv_rx_buf_ioaddr_size));
return (NXGE_ERROR | err);
}
#ifdef DEBUG
ra = size = 0;
hverr = nxge_init_hv_fzc_lp_op(nxgep, (uint64_t)channel,
(uint64_t)1, N2NIU_RX_LP_INFO,
(uint64_t)&ra, (uint64_t)&size);
NXGE_DEBUG_MSG((nxgep, RX_CTL,
"==> nxge_init_hv_fzc_rxdma_channel_pages: channel %d "
"error status 0x%x "
"(page 1 cntl buf) hverr 0x%llx "
"set cntl ioaddr_pp $%p "
"set cntl size 0x%llx "
"get cntl ioaddr_pp $%p "
"get cntl size 0x%llx ",
channel,
err,
hverr,
rbrp->hv_rx_cntl_base_ioaddr_pp,
rbrp->hv_rx_cntl_ioaddr_size,
ra,
size));
#endif
rbrp->hv_set = B_FALSE;
NXGE_DEBUG_MSG((nxgep, RX_CTL,
"<== nxge_init_hv_fzc_rxdma_channel_pages"));
return (NXGE_OK);
}
/*
* Map hypervisor error code to errno. Only
* H_ENORADDR, H_EBADALIGN and H_EINVAL are meaningful
* for niu driver. Any other error codes are mapped to EINVAL.
*/
static int
nxge_herr2kerr(uint64_t hv_errcode)
{
int s_errcode;
switch (hv_errcode) {
case H_ENORADDR:
case H_EBADALIGN:
s_errcode = EFAULT;
break;
case H_EOK:
s_errcode = 0;
break;
default:
s_errcode = EINVAL;
break;
}
return (s_errcode);
}
uint64_t
nxge_init_hv_fzc_lp_op(p_nxge_t nxgep, uint64_t channel,
uint64_t page_no, uint64_t op_type,
uint64_t ioaddr_pp, uint64_t ioaddr_size)
{
uint64_t hverr;
uint64_t major;
nxge_hio_data_t *nhd = (nxge_hio_data_t *)nxgep->nxge_hw_p->hio;
nxhv_dc_fp_t *io_fp;
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_hv_fzc_lp_op"));
major = nxgep->niu_hsvc.hsvc_major;
NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL,
"==> nxge_init_hv_fzc_lp_op (major %d): channel %d op_type 0x%x "
"page_no %d ioaddr_pp $%p ioaddr_size 0x%llx",
major, channel, op_type, page_no, ioaddr_pp, ioaddr_size));
/* Call the transmit conf function. */
switch (major) {
case NIU_MAJOR_VER: /* 1 */
switch (op_type) {
case N2NIU_TX_LP_CONF:
io_fp = &nhd->hio.tx;
hverr = (*io_fp->lp_conf)((uint64_t)channel,
(uint64_t)page_no,
(uint64_t)ioaddr_pp,
(uint64_t)ioaddr_size);
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_hv_fzc_lp_op(tx_conf): major %d "
"op 0x%x hverr 0x%x", major, op_type, hverr));
break;
case N2NIU_TX_LP_INFO:
io_fp = &nhd->hio.tx;
hverr = (*io_fp->lp_info)((uint64_t)channel,
(uint64_t)page_no,
(uint64_t *)ioaddr_pp,
(uint64_t *)ioaddr_size);
break;
case N2NIU_RX_LP_CONF:
io_fp = &nhd->hio.rx;
hverr = (*io_fp->lp_conf)((uint64_t)channel,
(uint64_t)page_no,
(uint64_t)ioaddr_pp,
(uint64_t)ioaddr_size);
break;
case N2NIU_RX_LP_INFO:
io_fp = &nhd->hio.rx;
hverr = (*io_fp->lp_info)((uint64_t)channel,
(uint64_t)page_no,
(uint64_t *)ioaddr_pp,
(uint64_t *)ioaddr_size);
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_hv_fzc_lp_op(rx_conf): major %d "
"op 0x%x hverr 0x%x", major, op_type, hverr));
break;
default:
hverr = EINVAL;
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"==> nxge_init_hv_fzc_lp_op(rx_conf): major %d "
"invalid op 0x%x hverr 0x%x", major,
op_type, hverr));
break;
}
break;
case NIU_MAJOR_VER_2: /* 2 */
switch (op_type) {
case N2NIU_TX_LP_CONF:
io_fp = &nhd->hio.tx;
hverr = (*io_fp->lp_cfgh_conf)(nxgep->niu_cfg_hdl,
(uint64_t)channel,
(uint64_t)page_no, ioaddr_pp, ioaddr_size);
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_hv_fzc_lp_op(tx_conf): major %d "
"op 0x%x hverr 0x%x", major, op_type, hverr));
break;
case N2NIU_TX_LP_INFO:
io_fp = &nhd->hio.tx;
hverr = (*io_fp->lp_cfgh_info)(nxgep->niu_cfg_hdl,
(uint64_t)channel,
(uint64_t)page_no,
(uint64_t *)ioaddr_pp,
(uint64_t *)ioaddr_size);
break;
case N2NIU_RX_LP_CONF:
io_fp = &nhd->hio.rx;
hverr = (*io_fp->lp_cfgh_conf)(nxgep->niu_cfg_hdl,
(uint64_t)channel,
(uint64_t)page_no,
(uint64_t)ioaddr_pp,
(uint64_t)ioaddr_size);
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"==> nxge_init_hv_fzc_lp_op(rx_conf): major %d "
"hverr 0x%x", major, hverr));
break;
case N2NIU_RX_LP_INFO:
io_fp = &nhd->hio.rx;
hverr = (*io_fp->lp_cfgh_info)(nxgep->niu_cfg_hdl,
(uint64_t)channel,
(uint64_t)page_no,
(uint64_t *)ioaddr_pp,
(uint64_t *)ioaddr_size);
break;
default:
hverr = EINVAL;
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"==> nxge_init_hv_fzc_lp_op(rx_conf): major %d "
"invalid op 0x%x hverr 0x%x", major,
op_type, hverr));
break;
}
break;
default:
hverr = EINVAL;
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"==> nxge_init_hv_fzc_lp_op(rx_conf): invalid major %d "
"op 0x%x hverr 0x%x", major, op_type, hverr));
break;
}
NXGE_DEBUG_MSG((nxgep, DMA_CTL,
"<== nxge_init_hv_fzc_lp_op: 0x%x", hverr));
return (hverr);
}
#endif /* sun4v and NIU_LP_WORKAROUND */
|