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
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
|
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* gld - Generic LAN Driver
* media dependent routines
*/
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/stropts.h>
#include <sys/stream.h>
#include <sys/kmem.h>
#include <sys/stat.h>
#include <sys/modctl.h>
#include <sys/kstat.h>
#include <sys/debug.h>
#include <sys/byteorder.h>
#include <sys/strsun.h>
#include <sys/dlpi.h>
#include <sys/ethernet.h>
#include <sys/multidata.h>
#include <sys/gld.h>
#include <sys/gldpriv.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/sysmacros.h>
#include <sys/ib/clients/ibd/ibd.h>
#include <sys/pattr.h>
#define DLSAPLENGTH(macinfo) \
((macinfo)->gldm_addrlen + ABS((macinfo)->gldm_saplen))
#ifdef GLD_DEBUG
extern int gld_debug;
#endif
extern void gld_bitrevcopy(caddr_t src, caddr_t target, size_t n);
extern char *gld_macaddr_sprintf(char *, unsigned char *, int);
extern gld_vlan_t *gld_find_vlan(gld_mac_info_t *, uint32_t);
extern uint32_t gld_global_options;
static struct llc_snap_hdr llc_snap_def = {
LSAP_SNAP, /* DLSAP 0xaa */
LSAP_SNAP, /* SLSAP 0xaa */
CNTL_LLC_UI, /* Control 0x03 */
0x00, 0x00, 0x00, /* Org[3] */
0x00 /* Type */
};
#define ISETHERTYPE(snaphdr) \
(snaphdr->d_lsap == LSAP_SNAP && \
snaphdr->s_lsap == LSAP_SNAP && \
snaphdr->control == CNTL_LLC_UI && \
snaphdr->org[0] == 0 && \
snaphdr->org[1] == 0 && \
snaphdr->org[2] == 0)
/* ======== */
/* Ethernet */
/* ======== */
static mac_addr_t ether_broadcast = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
void
gld_init_ether(gld_mac_info_t *macinfo)
{
struct gldkstats *sp =
((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->kstatp->ks_data;
/* Assumptions we make for this medium */
ASSERT(macinfo->gldm_type == DL_ETHER);
ASSERT(macinfo->gldm_addrlen == 6);
ASSERT(macinfo->gldm_saplen == -2);
#ifndef lint
ASSERT(sizeof (struct ether_header) == 14);
ASSERT(sizeof (mac_addr_t) == 6);
#endif
kstat_named_init(&sp->glds_frame, "align_errors", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_crc, "fcs_errors", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_collisions, "collisions", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_nocarrier, "carrier_errors",
KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_defer, "defer_xmts", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_xmtlatecoll, "tx_late_collisions",
KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_short, "runt_errors", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_excoll, "ex_collisions", KSTAT_DATA_ULONG);
/*
* only initialize the new statistics if the driver
* knows about them.
*/
if (macinfo->gldm_driver_version != GLD_VERSION_200)
return;
kstat_named_init(&sp->glds_dot3_first_coll,
"first_collisions", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_dot3_multi_coll,
"multi_collisions", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_dot3_sqe_error,
"sqe_errors", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_dot3_mac_xmt_error,
"macxmt_errors", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_dot3_mac_rcv_error,
"macrcv_errors", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_dot3_frame_too_long,
"toolong_errors", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_duplex, "duplex", KSTAT_DATA_CHAR);
}
/*ARGSUSED*/
void
gld_uninit_ether(gld_mac_info_t *macinfo)
{
}
int
gld_interpret_ether(gld_mac_info_t *macinfo, mblk_t *mp, pktinfo_t *pktinfo,
packet_flag_t flags)
{
struct ether_header *mh;
gld_mac_pvt_t *mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
struct llc_snap_hdr *snaphdr;
mblk_t *pmp = NULL, *savemp = mp;
unsigned short typelen;
int ret = 0;
/*
* Quickly handle receive fastpath for IPQ hack.
*/
if (flags == GLD_RXQUICK) {
pktinfo->pktLen = msgdsize(mp);
/*
* Check whether the header is contiguous, which
* also implicitly makes sure the packet is big enough.
*/
if (MBLKL(mp) < sizeof (struct ether_header))
return (-1);
mh = (struct ether_header *)mp->b_rptr;
pktinfo->ethertype = REF_NET_USHORT(mh->ether_type);
pktinfo->isForMe = mac_eq(&mh->ether_dhost,
mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
pktinfo->macLen = sizeof (struct ether_header);
return (0);
}
bzero((void *)pktinfo, sizeof (*pktinfo));
pktinfo->pktLen = msgdsize(mp);
/* make sure packet has at least a whole mac header */
if (pktinfo->pktLen < sizeof (struct ether_header))
return (-1);
/* make sure the mac header falls into contiguous memory */
if (MBLKL(mp) < sizeof (struct ether_header)) {
if ((pmp = msgpullup(mp, -1)) == NULL) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"GLD: interpret_ether cannot msgpullup");
#endif
return (-1);
}
mp = pmp; /* this mblk contains the whole mac header */
}
mh = (struct ether_header *)mp->b_rptr;
/* Check to see if the mac is a broadcast or multicast address. */
if (mac_eq(&mh->ether_dhost, ether_broadcast, macinfo->gldm_addrlen))
pktinfo->isBroadcast = 1;
else if (mh->ether_dhost.ether_addr_octet[0] & 1)
pktinfo->isMulticast = 1;
typelen = REF_NET_USHORT(mh->ether_type);
/*
* If the hardware is capable of VLAN tag insertion
* strip out the VLAN tag info. Knowing hardware is
* capable of VLAN can be established by the presance
* of non null 'macinfo->gldm_send_tagged'.
*/
if (flags == GLD_TX) {
if ((typelen == ETHERTYPE_VLAN) &&
(macinfo->gldm_send_tagged != NULL)) {
struct ether_vlan_header *evhp;
uint16_t tci;
if ((MBLKL(mp) < sizeof (struct ether_vlan_header)) &&
(pullupmsg(mp, sizeof (struct ether_vlan_header))
== 0)) {
ret = -1;
goto out;
}
evhp = (struct ether_vlan_header *)mp->b_rptr;
tci = REF_NET_USHORT(evhp->ether_tci);
/*
* We don't allow the VID and priority are both zero.
*/
if ((GLD_VTAG_PRI((int32_t)tci) == 0 &&
GLD_VTAG_VID((int32_t)tci) == VLAN_VID_NONE) ||
(GLD_VTAG_CFI((uint32_t)tci)) != VLAN_CFI_ETHER) {
ret = -1;
goto out;
}
/*
* Remember the VTAG info in order to reinsert it,
* Then strip the tag. This is required because some
* drivers do not allow the size of message (passed
* by the gldm_send_tagged() function) to be greater
* than ETHERMAX.
*/
GLD_SAVE_MBLK_VTAG(savemp, GLD_TCI2VTAG(tci));
ovbcopy(mp->b_rptr, mp->b_rptr + VTAG_SIZE,
2 * ETHERADDRL);
mp->b_rptr += VTAG_SIZE;
}
goto out; /* Got all info we need for xmit case */
}
ASSERT(GLDM_LOCK_HELD(macinfo));
/*
* Deal with the mac header
*/
mac_copy(&mh->ether_dhost, pktinfo->dhost, macinfo->gldm_addrlen);
mac_copy(&mh->ether_shost, pktinfo->shost, macinfo->gldm_addrlen);
pktinfo->isLooped = mac_eq(pktinfo->shost,
mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
pktinfo->isForMe = mac_eq(pktinfo->dhost,
mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
pktinfo->macLen = sizeof (struct ether_header);
if (typelen > ETHERMTU) {
pktinfo->ethertype = typelen; /* use type interpretation */
goto out;
}
/*
* Packet is 802.3 so the ether type/length field
* specifies the number of bytes that should be present
* in the data field. Additional bytes are padding, and
* should be removed
*/
{
int delta = pktinfo->pktLen -
(sizeof (struct ether_header) + typelen);
if (delta > 0 && adjmsg(mp, -delta))
pktinfo->pktLen -= delta;
}
/*
* Before trying to look beyond the MAC header, make sure the LLC
* header exists, and that both it and any SNAP header are contiguous.
*/
if (pktinfo->pktLen < pktinfo->macLen + LLC_HDR1_LEN)
goto out; /* LLC hdr should have been there! */
pktinfo->isLLC = 1;
if (gld_global_options & GLD_OPT_NO_ETHRXSNAP ||
pktinfo->pktLen < pktinfo->macLen + LLC_SNAP_HDR_LEN)
goto out;
if (MBLKL(mp) < sizeof (struct ether_header) + LLC_SNAP_HDR_LEN &&
MBLKL(mp) < pktinfo->pktLen) {
/*
* we don't have the entire packet within the first mblk (and
* therefore we didn't do the msgpullup above), AND the first
* mblk may not contain all the data we need to look at.
*/
ASSERT(pmp == NULL); /* couldn't have done msgpullup above */
if ((pmp = msgpullup(mp, -1)) == NULL) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"GLD: interpret_ether cannot msgpullup2");
#endif
goto out; /* can't interpret this pkt further */
}
mp = pmp; /* this mblk should contain everything needed */
}
/*
* Check SAP/SNAP information for EtherType.
*/
snaphdr = (struct llc_snap_hdr *)(mp->b_rptr + pktinfo->macLen);
if (ISETHERTYPE(snaphdr)) {
pktinfo->ethertype = REF_NET_USHORT(snaphdr->type);
pktinfo->hdrLen = LLC_SNAP_HDR_LEN;
}
out:
if (pmp != NULL)
freemsg(pmp);
return (ret);
}
mblk_t *
gld_unitdata_ether(gld_t *gld, mblk_t *mp)
{
gld_mac_info_t *macinfo = gld->gld_mac_info;
dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_rptr;
struct gld_dlsap *gldp = DLSAP(dlp, dlp->dl_dest_addr_offset);
mac_addr_t dhost;
unsigned short typelen;
mblk_t *nmp;
struct ether_header *mh;
int hdrlen;
uint32_t vptag;
gld_vlan_t *gld_vlan;
ASSERT(macinfo);
/* extract needed info from the mblk before we maybe reuse it */
mac_copy(gldp->glda_addr, dhost, macinfo->gldm_addrlen);
/* look in the unitdata request for a sap, else use bound one */
if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
REF_HOST_USHORT(gldp->glda_sap) != 0)
typelen = REF_HOST_USHORT(gldp->glda_sap);
else
typelen = gld->gld_sap;
/*
* We take values less than or equal to ETHERMTU to mean that the
* packet should not have an encoded EtherType and so we use the
* IEEE 802.3 length interpretation of the type/length field.
*/
if (typelen <= ETHERMTU)
typelen = msgdsize(mp);
hdrlen = sizeof (struct ether_header);
/*
* Check to see if VLAN is enabled on this stream
* if so then make the header bigger to hold a clone
* vlan tag.
*/
gld_vlan = (gld_vlan_t *)gld->gld_vlan;
if (gld_vlan && (gld_vlan->gldv_id != VLAN_VID_NONE)) {
hdrlen += VTAG_SIZE;
vptag = gld_vlan->gldv_ptag;
}
/* need a buffer big enough for the headers */
nmp = mp->b_cont; /* where the packet payload M_DATA is */
if (DB_REF(nmp) == 1 && MBLKHEAD(nmp) >= hdrlen) {
/* it fits at the beginning of the first M_DATA block */
freeb(mp); /* don't need the M_PROTO anymore */
} else if (DB_REF(mp) == 1 && MBLKSIZE(mp) >= hdrlen) {
/* we can reuse the dl_unitdata_req M_PROTO mblk */
nmp = mp;
DB_TYPE(nmp) = M_DATA;
nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
} else {
/* we need to allocate one */
if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL)
return (NULL);
nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
linkb(nmp, mp->b_cont);
freeb(mp);
}
/* Got the space, now copy in the header components */
nmp->b_rptr -= sizeof (typelen);
SET_NET_USHORT(*(uint16_t *)nmp->b_rptr, typelen);
if (hdrlen > sizeof (struct ether_header)) {
nmp->b_rptr -= sizeof (uint16_t);
SET_NET_USHORT(*(uint16_t *)nmp->b_rptr, vptag);
vptag >>= 16;
nmp->b_rptr -= sizeof (uint16_t);
SET_NET_USHORT(*(uint16_t *)nmp->b_rptr, vptag);
}
nmp->b_rptr -= (ETHERADDRL * 2);
mh = (struct ether_header *)nmp->b_rptr;
mac_copy(dhost, &mh->ether_dhost, macinfo->gldm_addrlen);
/*
* We access the mac address without the mutex to prevent
* mutex contention (BUG 4211361)
*/
mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
&mh->ether_shost, macinfo->gldm_addrlen);
return (nmp);
}
/*
* Insert the VLAN tag into the packet. The packet now is an Ethernet header
* without VLAN tag information.
*/
mblk_t *
gld_insert_vtag_ether(mblk_t *mp, uint32_t vtag)
{
struct ether_vlan_header *evhp;
struct ether_header *ehp;
mblk_t *nmp;
if (vtag == VLAN_VID_NONE)
return (mp);
if (DB_REF(mp) == 1 && MBLKHEAD(mp) >= VTAG_SIZE) {
/* it fits at the beginning of the message block */
nmp = mp;
ovbcopy(nmp->b_rptr, nmp->b_rptr - VTAG_SIZE, 2 * ETHERADDRL);
nmp->b_rptr -= VTAG_SIZE;
evhp = (struct ether_vlan_header *)nmp->b_rptr;
} else {
/* we need to allocate one */
if ((nmp = allocb(sizeof (struct ether_vlan_header),
BPRI_MED)) == NULL) {
return (NULL);
}
nmp->b_wptr += sizeof (struct ether_vlan_header);
/* transfer the ether_header fields */
evhp = (struct ether_vlan_header *)nmp->b_rptr;
ehp = (struct ether_header *)mp->b_rptr;
mac_copy(&ehp->ether_dhost, &evhp->ether_dhost, ETHERADDRL);
mac_copy(&ehp->ether_shost, &evhp->ether_shost, ETHERADDRL);
bcopy(&ehp->ether_type, &evhp->ether_type, sizeof (uint16_t));
/* offset the mp of the MAC header length. */
mp->b_rptr += sizeof (struct ether_header);
if (MBLKL(mp) == 0) {
nmp->b_cont = mp->b_cont;
freeb(mp);
} else {
nmp->b_cont = mp;
}
}
SET_NET_USHORT(evhp->ether_tci, vtag);
vtag >>= 16;
SET_NET_USHORT(evhp->ether_tpid, vtag);
return (nmp);
}
mblk_t *
gld_fastpath_ether(gld_t *gld, mblk_t *mp)
{
gld_mac_info_t *macinfo = gld->gld_mac_info;
dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_cont->b_rptr;
struct gld_dlsap *gldp = DLSAP(dlp, dlp->dl_dest_addr_offset);
unsigned short typelen;
mblk_t *nmp;
struct ether_header *mh;
int hdrlen;
uint32_t vptag;
gld_vlan_t *gld_vlan;
ASSERT(macinfo);
/* look in the unitdata request for a sap, else use bound one */
if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
REF_HOST_USHORT(gldp->glda_sap) != 0)
typelen = REF_HOST_USHORT(gldp->glda_sap);
else
typelen = gld->gld_sap;
/*
* We only do fast-path for EtherType encoding because this is the only
* case where the media header will be consistent from packet to packet.
*/
if (typelen <= ETHERMTU)
return (NULL);
/*
* Initialize the fast path header to include the
* basic source address information and type field.
*/
hdrlen = sizeof (struct ether_header);
/*
* Check to see if VLAN is enabled on this stream
* if so then make the header bigger to hold a clone
* vlan tag.
*/
gld_vlan = (gld_vlan_t *)gld->gld_vlan;
if (gld_vlan && (gld_vlan->gldv_id != VLAN_VID_NONE)) {
hdrlen += VTAG_SIZE;
vptag = gld_vlan->gldv_ptag;
}
if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL)
return (NULL);
nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
/* Got the space, now copy in the header components */
nmp->b_rptr -= sizeof (typelen);
SET_NET_USHORT(*(uint16_t *)nmp->b_rptr, typelen);
/*
* If the header is for a VLAN stream, then add
* in the VLAN tag to the clone header.
*/
if (hdrlen > sizeof (struct ether_header)) {
nmp->b_rptr -= sizeof (uint16_t);
SET_NET_USHORT(*(uint16_t *)nmp->b_rptr, vptag);
vptag >>= 16;
nmp->b_rptr -= sizeof (uint16_t);
SET_NET_USHORT(*(uint16_t *)nmp->b_rptr, vptag);
}
nmp->b_rptr -= (ETHERADDRL * 2);
mh = (struct ether_header *)nmp->b_rptr;
mac_copy(gldp->glda_addr, &mh->ether_dhost, macinfo->gldm_addrlen);
GLDM_LOCK(macinfo, RW_WRITER);
mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
&mh->ether_shost, macinfo->gldm_addrlen);
GLDM_UNLOCK(macinfo);
return (nmp);
}
/* == */
/* IB */
/* == */
void
gld_init_ib(gld_mac_info_t *macinfo)
{
/*
* Currently, the generic stats maintained by GLD is
* sufficient for IPoIB.
*/
/* Assumptions we make for this medium */
ASSERT(macinfo->gldm_type == DL_IB);
ASSERT(macinfo->gldm_addrlen == IPOIB_ADDRL);
ASSERT(macinfo->gldm_saplen == -2);
}
/* ARGSUSED */
void
gld_uninit_ib(gld_mac_info_t *macinfo)
{
}
/*
* The packet format sent to the driver is:
* IPOIB_ADDRL bytes dest addr :: 2b sap :: 2b 0s :: data
* The packet format received from the driver is:
* IPOIB_GRH_SIZE bytes pseudo GRH :: 2b sap :: 2b 0s :: data.
*/
int
gld_interpret_ib(gld_mac_info_t *macinfo, mblk_t *mp, pktinfo_t *pktinfo,
packet_flag_t flags)
{
ipoib_pgrh_t *grh;
ipoib_ptxhdr_t *gldp;
mblk_t *pmp = NULL;
gld_mac_pvt_t *mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
/*
* Quickly handle receive fastpath for IPQ hack.
*/
if (flags == GLD_RXQUICK) {
pktinfo->pktLen = msgdsize(mp) - IPOIB_GRH_SIZE;
/*
* Check whether the header is contiguous, which
* also implicitly makes sure the packet is big enough.
*/
if (MBLKL(mp) < (IPOIB_GRH_SIZE + IPOIB_HDRSIZE))
return (-1);
/*
* Almost all times, unicast will not have
* a valid pgrh; quickly identify and ask for
* IPQ hack optimization only in that case.
*/
grh = (ipoib_pgrh_t *)mp->b_rptr;
if (grh->ipoib_vertcflow == 0) {
struct ipoib_header *ihp = (struct ipoib_header *)
(mp->b_rptr + IPOIB_GRH_SIZE);
pktinfo->isForMe = 1;
pktinfo->ethertype = REF_NET_USHORT(ihp->ipoib_type);
pktinfo->macLen = IPOIB_GRH_SIZE + IPOIB_HDRSIZE;
return (0);
} else {
return (-1);
}
}
/*
* Handle the GLD_TX, GLD_RX, GLD_RXLOOP cases now.
*/
ASSERT(flags != GLD_RXQUICK);
bzero((void *)pktinfo, sizeof (*pktinfo));
if (flags != GLD_RX) {
/*
* GLD_TX and GLD_RXLOOP cases.
*/
gldp = (ipoib_ptxhdr_t *)mp->b_rptr;
pktinfo->pktLen = msgdsize(mp);
/* make sure packet has at least a pseudo header */
if (pktinfo->pktLen < sizeof (ipoib_ptxhdr_t))
return (-1);
/* make sure the mac header falls into contiguous memory */
if (MBLKL(mp) < sizeof (ipoib_ptxhdr_t)) {
if ((pmp = msgpullup(mp, -1)) == NULL) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"GLD: interpret_ib "
"cannot msgpullup");
#endif
return (-1);
}
/* this mblk contains the whole mac header */
mp = pmp;
}
/*
* Check if mac is broadcast or multicast address; all these
* types of address have the top 4 bytes as 0x00FFFFFF.
*/
if (mac_eq(&gldp->ipoib_dest, macinfo->gldm_broadcast_addr,
sizeof (uint32_t))) {
if (mac_eq(&gldp->ipoib_dest,
macinfo->gldm_broadcast_addr, IPOIB_ADDRL))
pktinfo->isBroadcast = 1;
else
pktinfo->isMulticast = 1;
}
/*
* Only count bytes we will be sending over the wire
* or looping back.
*/
pktinfo->pktLen -= IPOIB_ADDRL;
if (flags == GLD_TX)
goto out; /* Got all info we need for xmit case */
/*
* Loopback case: this is a dup'ed message.
*/
mp->b_rptr += IPOIB_ADDRL;
mac_copy(&gldp->ipoib_dest, pktinfo->dhost, IPOIB_ADDRL);
mac_copy(mac_pvt->curr_macaddr, pktinfo->shost, IPOIB_ADDRL);
} else {
/*
* GLD_RX case; process packet sent from driver.
*/
ipoib_mac_t *mact, *tact;
ib_qpn_t dqpn;
pktinfo->pktLen = msgdsize(mp);
/* make sure packet has at least pgrh and mac header */
if (pktinfo->pktLen < (IPOIB_GRH_SIZE + IPOIB_HDRSIZE))
return (-1);
/* make sure the header falls into contiguous memory */
if (MBLKL(mp) < (IPOIB_GRH_SIZE + IPOIB_HDRSIZE)) {
if ((pmp = msgpullup(mp, -1)) == NULL) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"GLD: interpret_ib "
"cannot msgpullup2");
#endif
return (-1);
}
/* this mblk contains the whole mac header */
mp = pmp;
}
grh = (ipoib_pgrh_t *)mp->b_rptr;
mp->b_rptr += IPOIB_GRH_SIZE;
pktinfo->pktLen -= IPOIB_GRH_SIZE;
if (grh->ipoib_vertcflow) {
/*
* First, copy source address from grh.
*/
mact = (ipoib_mac_t *)pktinfo->shost;
mac_copy(&grh->ipoib_sqpn, &mact->ipoib_qpn,
IPOIB_ADDRL);
/*
* Then copy destination address from grh;
* first, the 16 bytes of GID.
*/
mact = (ipoib_mac_t *)pktinfo->dhost;
mac_copy(&grh->ipoib_dgid_pref,
&mact->ipoib_gidpref, IPOIB_ADDRL -
sizeof (mact->ipoib_qpn));
tact = (ipoib_mac_t *)mac_pvt->curr_macaddr;
/* Is this a multicast address */
if (*(uchar_t *)(grh->ipoib_dgid_pref) == 0xFF) {
/*
* Only check for hardware looping in
* multicast case. It is assumed higher
* layer code (IP) will stop unicast loops;
* ie will prevent a transmit to self.
*/
if (bcmp(&grh->ipoib_sqpn, tact,
IPOIB_ADDRL) == 0)
pktinfo->isLooped = 1;
tact = (ipoib_mac_t *)macinfo->
gldm_broadcast_addr;
if (mac_eq(tact->ipoib_gidpref,
grh->ipoib_dgid_pref,
IPOIB_ADDRL - sizeof (tact->ipoib_qpn)))
pktinfo->isBroadcast = 1;
else
pktinfo->isMulticast = 1;
/*
* Now copy the 4 bytes QPN part of the
* destination address.
*/
dqpn = htonl(IB_MC_QPN);
mac_copy(&dqpn, &mact->ipoib_qpn,
sizeof (mact->ipoib_qpn));
} else {
/*
* Now copy the 4 bytes QPN part of the
* destination address.
*/
mac_copy(&tact->ipoib_qpn, &mact->ipoib_qpn,
sizeof (mact->ipoib_qpn));
/*
* Any unicast packets received on IBA are
* for the node.
*/
pktinfo->isForMe = 1;
}
} else {
/*
* It can not be a IBA multicast packet.
* Must have been unicast to us. We do not
* have shost information, which is used in
* gld_addudind(); IP/ARP does not care.
*/
pktinfo->nosource = 1;
mac_copy(mac_pvt->curr_macaddr, pktinfo->dhost,
IPOIB_ADDRL);
/*
* Any unicast packets received on IBA are
* for the node.
*/
pktinfo->isForMe = 1;
}
}
ASSERT((flags == GLD_RX) || (flags == GLD_RXLOOP));
ASSERT(GLDM_LOCK_HELD(macinfo));
pktinfo->ethertype = REF_NET_USHORT(((ipoib_hdr_t *)
(mp->b_rptr))->ipoib_type);
pktinfo->macLen = IPOIB_HDRSIZE;
out:
if (pmp != NULL)
freemsg(pmp);
return (0);
}
/*
* The packet format sent to the driver is: 2b sap :: 2b 0s :: data
*/
void
gld_interpret_mdt_ib(gld_mac_info_t *macinfo, mblk_t *mp, pdescinfo_t *pinfo,
pktinfo_t *pktinfo, mdt_packet_flag_t flags)
{
gld_mac_pvt_t *mac_pvt;
multidata_t *dlmdp;
pattrinfo_t attr_info = { PATTR_DSTADDRSAP, };
pattr_t *patr;
ipoib_ptxhdr_t *dlap = NULL;
/*
* Per packet formatting.
*/
if (flags == GLD_MDT_TXPKT) {
ipoib_hdr_t *hptr;
uint_t seg;
if (PDESC_HDRL(pinfo) == 0)
return;
/*
* Update packet's link header.
*/
pinfo->hdr_rptr -= IPOIB_HDRSIZE;
hptr = (ipoib_hdr_t *)pinfo->hdr_rptr;
hptr->ipoib_mbz = htons(0);
hptr->ipoib_type = pktinfo->ethertype;
/*
* Total #bytes that will be put on wire.
*/
pktinfo->pktLen = PDESC_HDRL(pinfo);
for (seg = 0; seg < pinfo->pld_cnt; seg++)
pktinfo->pktLen += PDESC_PLDL(pinfo, seg);
return;
}
/*
* The following two cases of GLD_MDT_TX and GLD_MDT_RXLOOP are per
* MDT message processing.
*/
dlmdp = mmd_getmultidata(mp);
patr = mmd_getpattr(dlmdp, NULL, &attr_info);
ASSERT(patr != NULL);
ASSERT(macinfo->gldm_saplen == -2);
if (patr != NULL)
dlap = (ipoib_ptxhdr_t *)((pattr_addr_t *)attr_info.buf)->addr;
if (flags == GLD_MDT_TX) {
bzero((void *)pktinfo, sizeof (*pktinfo));
if (dlap == NULL)
return;
/*
* Check if mac is broadcast or multicast address; all these
* types of address have the top 4 bytes as 0x00FFFFFF.
*/
if (mac_eq(dlap, macinfo->gldm_broadcast_addr,
sizeof (uint32_t))) {
if (mac_eq(dlap, macinfo->gldm_broadcast_addr,
IPOIB_ADDRL))
pktinfo->isBroadcast = 1;
else
pktinfo->isMulticast = 1;
}
pktinfo->ethertype = REF_NET_USHORT(dlap->
ipoib_rhdr.ipoib_type);
} else {
ASSERT(flags == GLD_MDT_RXLOOP);
pktinfo->macLen = IPOIB_HDRSIZE;
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
mac_copy(mac_pvt->curr_macaddr, pktinfo->shost, IPOIB_ADDRL);
if (dlap == NULL)
return;
mac_copy(&dlap->ipoib_dest, pktinfo->dhost, IPOIB_ADDRL);
}
}
mblk_t *
gld_unitdata_ib(gld_t *gld, mblk_t *mp)
{
gld_mac_info_t *macinfo = gld->gld_mac_info;
dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_rptr;
ipoib_ptxhdr_t *gldp = IPOIBDLSAP(dlp, dlp->dl_dest_addr_offset);
ipoib_mac_t dhost;
unsigned short type;
mblk_t *nmp;
int hdrlen;
ASSERT(macinfo != NULL);
/* extract needed info from the mblk before we maybe reuse it */
mac_copy(&gldp->ipoib_dest, &dhost, IPOIB_ADDRL);
/* look in the unitdata request for a sap, else use bound one */
if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
REF_HOST_USHORT(gldp->ipoib_rhdr.ipoib_type) != 0)
type = REF_HOST_USHORT(gldp->ipoib_rhdr.ipoib_type);
else
type = gld->gld_sap;
hdrlen = sizeof (ipoib_ptxhdr_t);
/* need a buffer big enough for the headers */
nmp = mp->b_cont; /* where the packet payload M_DATA is */
if (DB_REF(nmp) == 1 && MBLKHEAD(nmp) >= hdrlen) {
/* it fits at the beginning of the first M_DATA block */
freeb(mp); /* don't need the M_PROTO anymore */
} else if (DB_REF(mp) == 1 && MBLKSIZE(mp) >= hdrlen) {
/* we can reuse the dl_unitdata_req M_PROTO mblk */
nmp = mp;
DB_TYPE(nmp) = M_DATA;
nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
} else {
/* we need to allocate one */
if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL)
return (NULL);
nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
linkb(nmp, mp->b_cont);
freeb(mp);
}
/* Got the space, now copy in the header components */
nmp->b_rptr -= sizeof (ipoib_ptxhdr_t);
gldp = (ipoib_ptxhdr_t *)nmp->b_rptr;
SET_NET_USHORT(gldp->ipoib_rhdr.ipoib_type, type);
gldp->ipoib_rhdr.ipoib_mbz = 0;
mac_copy(&dhost, &gldp->ipoib_dest, IPOIB_ADDRL);
return (nmp);
}
mblk_t *
gld_fastpath_ib(gld_t *gld, mblk_t *mp)
{
gld_mac_info_t *macinfo = gld->gld_mac_info;
dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_cont->b_rptr;
ipoib_ptxhdr_t *gldp = IPOIBDLSAP(dlp, dlp->dl_dest_addr_offset);
unsigned short type;
mblk_t *nmp;
ipoib_ptxhdr_t *tgldp;
int hdrlen;
ASSERT(macinfo != NULL);
/* look in the unitdata request for a sap, else use bound one */
if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
REF_HOST_USHORT(gldp->ipoib_rhdr.ipoib_type) != 0)
type = REF_HOST_USHORT(gldp->ipoib_rhdr.ipoib_type);
else
type = gld->gld_sap;
hdrlen = sizeof (ipoib_ptxhdr_t);
if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL)
return (NULL);
nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
/* Got the space, now copy in the header components */
nmp->b_rptr -= sizeof (ipoib_ptxhdr_t);
tgldp = (ipoib_ptxhdr_t *)nmp->b_rptr;
tgldp->ipoib_rhdr.ipoib_type = htons(type);
tgldp->ipoib_rhdr.ipoib_mbz = 0;
mac_copy(&gldp->ipoib_dest, &tgldp->ipoib_dest, IPOIB_ADDRL);
return (nmp);
}
/* ==== */
/* FDDI */
/* ==== */
void
gld_init_fddi(gld_mac_info_t *macinfo)
{
struct gldkstats *sp =
((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->kstatp->ks_data;
/* Assumptions we make for this medium */
ASSERT(macinfo->gldm_type == DL_FDDI);
ASSERT(macinfo->gldm_addrlen == 6);
ASSERT(macinfo->gldm_saplen == -2);
#ifndef lint
ASSERT(sizeof (struct fddi_mac_frm) == 13);
ASSERT(sizeof (mac_addr_t) == 6);
#endif
/* Wire address format is bit reversed from canonical format */
macinfo->gldm_options |= GLDOPT_CANONICAL_ADDR;
kstat_named_init(&sp->glds_fddi_mac_error,
"mac_errors", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_fddi_mac_lost,
"mac_lost_errors", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_fddi_mac_token,
"mac_tokens", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_fddi_mac_tvx_expired,
"mac_tvx_expired", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_fddi_mac_late,
"mac_late", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_fddi_mac_ring_op,
"mac_ring_ops", KSTAT_DATA_UINT32);
}
/*ARGSUSED*/
void
gld_uninit_fddi(gld_mac_info_t *macinfo)
{
}
int
gld_interpret_fddi(gld_mac_info_t *macinfo, mblk_t *mp, pktinfo_t *pktinfo,
packet_flag_t flags)
{
struct fddi_mac_frm *mh;
gld_mac_pvt_t *mac_pvt;
struct llc_snap_hdr *snaphdr;
mblk_t *pmp = NULL;
/*
* Quickly handle receive fastpath; FDDI does not support IPQ hack.
*/
if (flags == GLD_RXQUICK) {
pktinfo->pktLen = msgdsize(mp);
return (-1);
}
bzero((void *)pktinfo, sizeof (*pktinfo));
pktinfo->pktLen = msgdsize(mp);
/* make sure packet has at least a whole mac header */
if (pktinfo->pktLen < sizeof (struct fddi_mac_frm))
return (-1);
/* make sure the mac header falls into contiguous memory */
if (MBLKL(mp) < sizeof (struct fddi_mac_frm)) {
if ((pmp = msgpullup(mp, -1)) == NULL) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"GLD: interpret_fddi cannot msgpullup");
#endif
return (-1);
}
mp = pmp; /* this mblk contains the whole mac header */
}
mh = (struct fddi_mac_frm *)mp->b_rptr;
/* Check to see if the mac is a broadcast or multicast address. */
/* NB we are still in wire format (non canonical) */
/* mac_eq works because ether_broadcast is the same either way */
if (mac_eq(mh->fddi_dhost, ether_broadcast, macinfo->gldm_addrlen))
pktinfo->isBroadcast = 1;
else if (mh->fddi_dhost[0] & 0x80)
pktinfo->isMulticast = 1;
if (flags == GLD_TX)
goto out; /* Got all info we need for xmit case */
ASSERT(GLDM_LOCK_HELD(macinfo));
/*
* Deal with the mac header
*/
cmac_copy(mh->fddi_dhost, pktinfo->dhost,
macinfo->gldm_addrlen, macinfo);
cmac_copy(mh->fddi_shost, pktinfo->shost,
macinfo->gldm_addrlen, macinfo);
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
pktinfo->isLooped = mac_eq(pktinfo->shost,
mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
pktinfo->isForMe = mac_eq(pktinfo->dhost,
mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
pktinfo->macLen = sizeof (struct fddi_mac_frm);
/*
* Before trying to look beyond the MAC header, make sure the LLC
* header exists, and that both it and any SNAP header are contiguous.
*/
if (MBLKL(mp) < sizeof (struct fddi_mac_frm) + LLC_SNAP_HDR_LEN &&
MBLKL(mp) < pktinfo->pktLen) {
/*
* we don't have the entire packet within the first mblk (and
* therefore we didn't do the msgpullup above), AND the first
* mblk may not contain all the data we need to look at.
*/
ASSERT(pmp == NULL); /* couldn't have done msgpullup above */
if ((pmp = msgpullup(mp, -1)) == NULL) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"GLD: interpret_fddi cannot msgpullup2");
#endif
goto out; /* can't interpret this pkt further */
}
mp = pmp; /* this mblk should contain everything needed */
}
/*
* Check SAP/SNAP information.
*/
if ((mh->fddi_fc & 0x70) == 0x50) {
if (pktinfo->pktLen < pktinfo->macLen + LLC_HDR1_LEN)
goto out;
pktinfo->isLLC = 1;
if (pktinfo->pktLen < pktinfo->macLen + LLC_SNAP_HDR_LEN)
goto out;
snaphdr = (struct llc_snap_hdr *)(mp->b_rptr + pktinfo->macLen);
if (ISETHERTYPE(snaphdr)) {
pktinfo->ethertype = REF_NET_USHORT(snaphdr->type);
pktinfo->hdrLen = LLC_SNAP_HDR_LEN;
}
}
out:
if (pmp != NULL)
freemsg(pmp);
return (0);
}
mblk_t *
gld_unitdata_fddi(gld_t *gld, mblk_t *mp)
{
gld_mac_info_t *macinfo = gld->gld_mac_info;
dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_rptr;
struct gld_dlsap *gldp = DLSAP(dlp, dlp->dl_dest_addr_offset);
mac_addr_t dhost;
unsigned short type;
mblk_t *nmp;
struct fddi_mac_frm *mh;
int hdrlen;
ASSERT(macinfo);
/* extract needed info from the mblk before we maybe reuse it */
mac_copy(gldp->glda_addr, dhost, macinfo->gldm_addrlen);
/* look in the unitdata request for a sap, else use bound one */
if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
REF_HOST_USHORT(gldp->glda_sap) != 0)
type = REF_HOST_USHORT(gldp->glda_sap);
else
type = gld->gld_sap;
hdrlen = sizeof (struct fddi_mac_frm);
/*
* Check whether we need to do EtherType encoding or whether the packet
* is LLC.
*/
if (type > GLD_MAX_802_SAP)
hdrlen += sizeof (struct llc_snap_hdr);
/* need a buffer big enough for the headers */
nmp = mp->b_cont; /* where the packet payload M_DATA is */
if (DB_REF(nmp) == 1 && MBLKHEAD(nmp) >= hdrlen) {
/* it fits at the beginning of the first M_DATA block */
freeb(mp); /* don't need the M_PROTO anymore */
} else if (DB_REF(mp) == 1 && MBLKSIZE(mp) >= hdrlen) {
/* we can reuse the dl_unitdata_req M_PROTO mblk */
nmp = mp;
DB_TYPE(nmp) = M_DATA;
nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
} else {
/* we need to allocate one */
if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL)
return (NULL);
nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
linkb(nmp, mp->b_cont);
freeb(mp);
}
/* Got the space, now copy in the header components */
if (type > GLD_MAX_802_SAP) {
/* create the snap header */
struct llc_snap_hdr *snap;
nmp->b_rptr -= sizeof (struct llc_snap_hdr);
snap = (struct llc_snap_hdr *)(nmp->b_rptr);
*snap = llc_snap_def;
SET_NET_USHORT(snap->type, type);
}
nmp->b_rptr -= sizeof (struct fddi_mac_frm);
mh = (struct fddi_mac_frm *)nmp->b_rptr;
mh->fddi_fc = 0x50;
cmac_copy(dhost, mh->fddi_dhost, macinfo->gldm_addrlen, macinfo);
/*
* We access the mac address without the mutex to prevent
* mutex contention (BUG 4211361)
*/
cmac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
mh->fddi_shost, macinfo->gldm_addrlen, macinfo);
return (nmp);
}
mblk_t *
gld_fastpath_fddi(gld_t *gld, mblk_t *mp)
{
gld_mac_info_t *macinfo = gld->gld_mac_info;
dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_cont->b_rptr;
struct gld_dlsap *gldp = DLSAP(dlp, dlp->dl_dest_addr_offset);
unsigned short type;
mblk_t *nmp;
struct fddi_mac_frm *mh;
int hdrlen;
ASSERT(macinfo);
/* look in the unitdata request for a sap, else use bound one */
if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
REF_HOST_USHORT(gldp->glda_sap) != 0)
type = REF_HOST_USHORT(gldp->glda_sap);
else
type = gld->gld_sap;
hdrlen = sizeof (struct fddi_mac_frm);
/*
* Check whether we need to do EtherType encoding or whether the packet
* will be LLC.
*/
if (type > GLD_MAX_802_SAP)
hdrlen += sizeof (struct llc_snap_hdr);
if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL)
return (NULL);
nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
/* Got the space, now copy in the header components */
if (type > GLD_MAX_802_SAP) {
/* create the snap header */
struct llc_snap_hdr *snap;
nmp->b_rptr -= sizeof (struct llc_snap_hdr);
snap = (struct llc_snap_hdr *)(nmp->b_rptr);
*snap = llc_snap_def;
snap->type = htons(type); /* we know it's aligned */
}
nmp->b_rptr -= sizeof (struct fddi_mac_frm);
mh = (struct fddi_mac_frm *)nmp->b_rptr;
mh->fddi_fc = 0x50;
cmac_copy(gldp->glda_addr, mh->fddi_dhost,
macinfo->gldm_addrlen, macinfo);
GLDM_LOCK(macinfo, RW_WRITER);
cmac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
mh->fddi_shost, macinfo->gldm_addrlen, macinfo);
GLDM_UNLOCK(macinfo);
return (nmp);
}
/* ========== */
/* Token Ring */
/* ========== */
#define GLD_SR_VAR(macinfo) \
(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->data)
#define GLD_SR_HASH(macinfo) ((struct srtab **)GLD_SR_VAR(macinfo))
#define GLD_SR_MUTEX(macinfo) \
(&((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->datalock)
static void gld_sr_clear(gld_mac_info_t *);
static void gld_rcc_receive(gld_mac_info_t *, pktinfo_t *, struct gld_ri *,
uchar_t *, int);
static void gld_rcc_send(gld_mac_info_t *, queue_t *, uchar_t *,
struct gld_ri **, uchar_t *);
static mac_addr_t tokenbroadcastaddr2 = { 0xc0, 0x00, 0xff, 0xff, 0xff, 0xff };
static struct gld_ri ri_ste_def;
void
gld_init_tr(gld_mac_info_t *macinfo)
{
struct gldkstats *sp =
((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->kstatp->ks_data;
/* avoid endian-dependent code by initializing here instead of static */
ri_ste_def.len = 2;
ri_ste_def.rt = RT_STE;
ri_ste_def.mtu = RT_MTU_MAX;
ri_ste_def.dir = 0;
ri_ste_def.res = 0;
/* Assumptions we make for this medium */
ASSERT(macinfo->gldm_type == DL_TPR);
ASSERT(macinfo->gldm_addrlen == 6);
ASSERT(macinfo->gldm_saplen == -2);
#ifndef lint
ASSERT(sizeof (struct tr_mac_frm_nori) == 14);
ASSERT(sizeof (mac_addr_t) == 6);
#endif
mutex_init(GLD_SR_MUTEX(macinfo), NULL, MUTEX_DRIVER, NULL);
GLD_SR_VAR(macinfo) = kmem_zalloc(sizeof (struct srtab *)*SR_HASH_SIZE,
KM_SLEEP);
/* Default is RDE enabled for this medium */
((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_enabled =
ddi_getprop(DDI_DEV_T_NONE, macinfo->gldm_devinfo, 0,
"gld_rde_enable", 1);
/*
* Default is to use STE for unknown paths if RDE is enabled.
* If RDE is disabled, default is to use NULL RIF fields.
*
* It's possible to force use of STE for ALL packets:
* disable RDE but enable STE. This may be useful for
* non-transparent bridges, when it is not desired to run
* the RDE algorithms.
*/
((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_str_indicator_ste =
ddi_getprop(DDI_DEV_T_NONE, macinfo->gldm_devinfo, 0,
"gld_rde_str_indicator_ste",
((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_enabled);
/* Default 10 second route timeout on lack of activity */
{
int t = ddi_getprop(DDI_DEV_T_NONE, macinfo->gldm_devinfo, 0,
"gld_rde_timeout", 10);
if (t < 1)
t = 1; /* Let's be reasonable */
if (t > 600)
t = 600; /* Let's be reasonable */
/* We're using ticks (lbolts) for our timeout -- convert from seconds */
t = drv_usectohz(1000000 * t);
((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_timeout = t;
}
kstat_named_init(&sp->glds_dot5_line_error,
"line_errors", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_dot5_burst_error,
"burst_errors", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_dot5_signal_loss,
"signal_losses", KSTAT_DATA_UINT32);
/*
* only initialize the new statistics if the driver
* knows about them.
*/
if (macinfo->gldm_driver_version != GLD_VERSION_200)
return;
kstat_named_init(&sp->glds_dot5_ace_error,
"ace_errors", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_dot5_internal_error,
"internal_errors", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_dot5_lost_frame_error,
"lost_frame_errors", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_dot5_frame_copied_error,
"frame_copied_errors", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_dot5_token_error,
"token_errors", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_dot5_freq_error,
"freq_errors", KSTAT_DATA_UINT32);
}
void
gld_uninit_tr(gld_mac_info_t *macinfo)
{
mutex_destroy(GLD_SR_MUTEX(macinfo));
gld_sr_clear(macinfo);
kmem_free(GLD_SR_VAR(macinfo), sizeof (struct srtab *) * SR_HASH_SIZE);
}
int
gld_interpret_tr(gld_mac_info_t *macinfo, mblk_t *mp, pktinfo_t *pktinfo,
packet_flag_t flags)
{
struct tr_mac_frm *mh;
gld_mac_pvt_t *mac_pvt;
struct llc_snap_hdr *snaphdr;
mblk_t *pmp = NULL;
struct gld_ri *rh;
/*
* Quickly handle receive fastpath; TR does not support IPQ hack.
*/
if (flags == GLD_RXQUICK) {
pktinfo->pktLen = msgdsize(mp);
return (-1);
}
bzero((void *)pktinfo, sizeof (*pktinfo));
pktinfo->pktLen = msgdsize(mp);
/* make sure packet has at least a whole mac header */
if (pktinfo->pktLen < sizeof (struct tr_mac_frm_nori))
return (-1);
/* make sure the mac header falls into contiguous memory */
if (MBLKL(mp) < sizeof (struct tr_mac_frm_nori)) {
if ((pmp = msgpullup(mp, -1)) == NULL) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"GLD: interpret_tr cannot msgpullup");
#endif
return (-1);
}
mp = pmp; /* this mblk contains the whole mac header */
}
mh = (struct tr_mac_frm *)mp->b_rptr;
/* Check to see if the mac is a broadcast or multicast address. */
if (mac_eq(mh->tr_dhost, ether_broadcast, macinfo->gldm_addrlen) ||
mac_eq(mh->tr_dhost, tokenbroadcastaddr2, macinfo->gldm_addrlen))
pktinfo->isBroadcast = 1;
else if (mh->tr_dhost[0] & 0x80)
pktinfo->isMulticast = 1;
if (flags == GLD_TX)
goto out; /* Got all info we need for xmit case */
ASSERT(GLDM_LOCK_HELD(macinfo));
/*
* Deal with the mac header
*/
mac_copy(mh->tr_dhost, pktinfo->dhost, macinfo->gldm_addrlen);
mac_copy(mh->tr_shost, pktinfo->shost, macinfo->gldm_addrlen);
pktinfo->shost[0] &= ~0x80; /* turn off RIF indicator */
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
pktinfo->isLooped = mac_eq(pktinfo->shost,
mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
pktinfo->isForMe = mac_eq(pktinfo->dhost,
mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
rh = (struct gld_ri *)NULL;
pktinfo->macLen = sizeof (struct tr_mac_frm_nori);
/*
* Before trying to look beyond the MAC header, make sure the data
* structures are all contiguously where we can conveniently look at
* them. We'll use a worst-case estimate of how many bytes into the
* packet data we'll be needing to look. Things will be more efficient
* if the driver puts at least this much into the first mblk.
*
* Even after this, we still will have to do checks against the total
* length of the packet. A bad incoming packet may not hold all the
* data structures it says it does.
*/
if (MBLKL(mp) < sizeof (struct tr_mac_frm) +
LLC_HDR1_LEN + sizeof (struct rde_pdu) &&
MBLKL(mp) < pktinfo->pktLen) {
/*
* we don't have the entire packet within the first mblk (and
* therefore we didn't do the msgpullup above), AND the first
* mblk may not contain all the data we need to look at.
*/
ASSERT(pmp == NULL); /* couldn't have done msgpullup above */
if ((pmp = msgpullup(mp, -1)) == NULL) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"GLD: interpret_tr cannot msgpullup2");
#endif
goto out; /* can't interpret this pkt further */
}
mp = pmp; /* this mblk should contain everything needed */
mh = (struct tr_mac_frm *)mp->b_rptr; /* to look at RIF */
}
if (mh->tr_shost[0] & 0x80) {
/* Routing Information Field (RIF) is present */
if (pktinfo->pktLen < sizeof (struct tr_mac_frm_nori) + 2)
goto out; /* RIF should have been there! */
rh = (struct gld_ri *)&mh->tr_ri;
if ((rh->len & 1) || rh->len < 2) {
/* Bogus RIF, don't handle this packet */
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"GLD: received TR packet with "
"bogus RIF length %d",
rh->len);
#endif
goto out;
}
if (pktinfo->pktLen < sizeof (struct tr_mac_frm_nori) + rh->len)
goto out; /* RIF should have been there! */
pktinfo->macLen += rh->len;
}
if ((mh->tr_fc & 0xc0) == 0x40) {
if (pktinfo->pktLen < pktinfo->macLen + LLC_HDR1_LEN)
goto out;
pktinfo->isLLC = 1;
if (pktinfo->pktLen < pktinfo->macLen + LLC_SNAP_HDR_LEN)
goto out;
snaphdr = (struct llc_snap_hdr *)(mp->b_rptr + pktinfo->macLen);
if (ISETHERTYPE(snaphdr)) {
pktinfo->ethertype = REF_NET_USHORT(snaphdr->type);
pktinfo->hdrLen = LLC_SNAP_HDR_LEN;
}
/* Inform the Route Control Component of received LLC frame */
gld_rcc_receive(macinfo, pktinfo, rh,
mp->b_rptr + pktinfo->macLen,
pktinfo->pktLen - pktinfo->macLen);
}
out:
if (pmp != NULL)
freemsg(pmp);
return (0);
}
mblk_t *
gld_unitdata_tr(gld_t *gld, mblk_t *mp)
{
gld_mac_info_t *macinfo = gld->gld_mac_info;
dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_rptr;
struct gld_dlsap *gldp = DLSAP(dlp, dlp->dl_dest_addr_offset);
mac_addr_t dhost;
unsigned short type;
mblk_t *nmp, *llcmp, *pmp = NULL;
struct tr_mac_frm_nori *mh;
int hdrlen;
struct gld_ri *rh;
ASSERT(macinfo);
/* extract needed info from the mblk before we maybe reuse it */
mac_copy(gldp->glda_addr, dhost, macinfo->gldm_addrlen);
/* look in the unitdata request for a sap, else use bound one */
if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
REF_HOST_USHORT(gldp->glda_sap) != 0)
type = REF_HOST_USHORT(gldp->glda_sap);
else
type = gld->gld_sap;
/* includes maximum possible Routing Information Field (RIF) size */
hdrlen = sizeof (struct tr_mac_frm);
/*
* Check whether we need to do EtherType encoding or whether the packet
* is LLC.
*/
if (type > GLD_MAX_802_SAP)
hdrlen += sizeof (struct llc_snap_hdr);
/* need a buffer big enough for the headers */
llcmp = nmp = mp->b_cont; /* where the packet payload M_DATA is */
/*
* We are going to need to look at the LLC header, so make sure it
* is contiguously in a single mblk. If we're the ones who create
* the LLC header (below, in the case where sap > 0xff) then we don't
* have to worry about it here.
*/
ASSERT(nmp != NULL); /* gld_unitdata guarantees msgdsize > 0 */
if (type <= GLD_MAX_802_SAP) {
if (MBLKL(llcmp) < LLC_HDR1_LEN) {
llcmp = pmp = msgpullup(nmp, LLC_HDR1_LEN);
if (pmp == NULL) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"GLD: unitdata_tr "
"cannot msgpullup");
#endif
return (NULL);
}
}
}
if (DB_REF(nmp) == 1 && MBLKHEAD(nmp) >= hdrlen) {
/* it fits at the beginning of the first M_DATA block */
freeb(mp); /* don't need the M_PROTO anymore */
} else if (DB_REF(mp) == 1 && MBLKSIZE(mp) >= hdrlen) {
/* we can reuse the dl_unitdata_req M_PROTO mblk */
nmp = mp;
DB_TYPE(nmp) = M_DATA;
nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
} else {
/* we need to allocate one */
if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL) {
if (pmp != NULL)
freemsg(pmp);
return (NULL);
}
nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
linkb(nmp, mp->b_cont);
freeb(mp);
}
/* Got the space, now copy in the header components */
if (type > GLD_MAX_802_SAP) {
/* create the snap header */
struct llc_snap_hdr *snap;
llcmp = nmp; /* LLC header is going to be in this mblk */
nmp->b_rptr -= sizeof (struct llc_snap_hdr);
snap = (struct llc_snap_hdr *)(nmp->b_rptr);
*snap = llc_snap_def;
SET_NET_USHORT(snap->type, type);
}
/* Hold SR tables still while we maybe point at an entry */
mutex_enter(GLD_SR_MUTEX(macinfo));
gld_rcc_send(macinfo, WR(gld->gld_qptr), dhost, &rh, llcmp->b_rptr);
if (rh != NULL) {
/* copy in the RIF */
ASSERT(rh->len <= sizeof (struct gld_ri));
nmp->b_rptr -= rh->len;
bcopy((caddr_t)rh, (caddr_t)nmp->b_rptr, rh->len);
}
mutex_exit(GLD_SR_MUTEX(macinfo));
/* no longer need the pulled-up mblk */
if (pmp != NULL)
freemsg(pmp);
/*
* fill in token ring header
*/
nmp->b_rptr -= sizeof (struct tr_mac_frm_nori);
mh = (struct tr_mac_frm_nori *)nmp->b_rptr;
mh->tr_ac = 0x10;
mh->tr_fc = 0x40;
mac_copy(dhost, mh->tr_dhost, macinfo->gldm_addrlen);
/*
* We access the mac address without the mutex to prevent
* mutex contention (BUG 4211361)
*/
mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
mh->tr_shost, macinfo->gldm_addrlen);
if (rh != NULL)
mh->tr_shost[0] |= 0x80;
else
mh->tr_shost[0] &= ~0x80;
return (nmp);
}
/*
* We cannot have our client sending us "fastpath" M_DATA messages,
* because to do that we must provide to him a fixed MAC header to
* be prepended to each outgoing packet. But with Source Routing
* media, the length and content of the MAC header changes as the
* routes change, so there is no fixed header we can provide. So
* we decline to accept M_DATA messages if Source Routing is enabled.
*/
mblk_t *
gld_fastpath_tr(gld_t *gld, mblk_t *mp)
{
gld_mac_info_t *macinfo = gld->gld_mac_info;
dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_cont->b_rptr;
struct gld_dlsap *gldp = DLSAP(dlp, dlp->dl_dest_addr_offset);
unsigned short type;
mblk_t *nmp;
struct tr_mac_frm_nori *mh;
int hdrlen;
ASSERT(macinfo);
/*
* If we are doing Source Routing, then we cannot provide a fixed
* MAC header, so fail.
*/
if (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_enabled)
return (NULL);
/* look in the unitdata request for a sap, else use bound one */
if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
REF_HOST_USHORT(gldp->glda_sap) != 0)
type = REF_HOST_USHORT(gldp->glda_sap);
else
type = gld->gld_sap;
hdrlen = sizeof (struct tr_mac_frm_nori);
if (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_str_indicator_ste)
hdrlen += ri_ste_def.len;
/*
* Check whether we need to do EtherType encoding or whether the packet
* will be LLC.
*/
if (type > GLD_MAX_802_SAP)
hdrlen += sizeof (struct llc_snap_hdr);
if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL)
return (NULL);
nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
/* Got the space, now copy in the header components */
if (type > GLD_MAX_802_SAP) {
/* create the snap header */
struct llc_snap_hdr *snap;
nmp->b_rptr -= sizeof (struct llc_snap_hdr);
snap = (struct llc_snap_hdr *)(nmp->b_rptr);
*snap = llc_snap_def;
snap->type = htons(type); /* we know it's aligned */
}
/* RDE is disabled, use NULL RIF, or STE RIF */
if (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_str_indicator_ste) {
nmp->b_rptr -= ri_ste_def.len;
bcopy((caddr_t)&ri_ste_def, (caddr_t)nmp->b_rptr,
ri_ste_def.len);
}
/*
* fill in token ring header
*/
nmp->b_rptr -= sizeof (struct tr_mac_frm_nori);
mh = (struct tr_mac_frm_nori *)nmp->b_rptr;
mh->tr_ac = 0x10;
mh->tr_fc = 0x40;
mac_copy(gldp->glda_addr, mh->tr_dhost, macinfo->gldm_addrlen);
GLDM_LOCK(macinfo, RW_WRITER);
mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
mh->tr_shost, macinfo->gldm_addrlen);
GLDM_UNLOCK(macinfo);
if (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_str_indicator_ste)
mh->tr_shost[0] |= 0x80;
else
mh->tr_shost[0] &= ~0x80;
return (nmp);
}
/*
* Route Determination Entity (ISO 8802-2 / IEEE 802.2 : 1994, Section 9)
*
* RDE is an LLC layer entity. GLD is a MAC layer entity. The proper
* solution to this architectural anomaly is to move RDE support out of GLD
* and into LLC where it belongs. In particular, only LLC has the knowledge
* necessary to reply to XID and TEST packets. If and when it comes time to
* move RDE out of GLD to LLC, the LLC-to-GLD interface should be modified
* to use MA_UNITDATA structures rather than DL_UNITDATA structures. Of
* course, GLD will still have to continue to also support the DL_ structures
* as long as IP is not layered over LLC. Another, perhaps better, idea
* would be to make RDE an autopush module on top of the token ring drivers:
* RDE would sit between LLC and GLD. It would then also sit between IP and
* GLD, providing services to all clients of GLD/tokenring. In that case,
* GLD would still have to continue to support the DL_ interface for non-
* Token Ring interfaces, using the MA_ interface only for media supporting
* Source Routing media.
*
* At present, Token Ring is the only source routing medium we support.
* Since Token Ring is not at this time a strategic network medium for Sun,
* rather than devote a large amount of resources to creating a proper
* architecture and implementation of RDE, we do the minimum necessary to
* get it to work. The interface between the above token ring code and the
* below RDE code is designed to make it relatively easy to change to an
* MA_UNITDATA model later should this ever become a priority.
*/
static void gld_send_rqr(gld_mac_info_t *, uchar_t *, struct gld_ri *,
struct rde_pdu *, int);
static void gld_rde_pdu_req(gld_mac_info_t *, queue_t *, uchar_t *,
struct gld_ri *, uchar_t, uchar_t, uchar_t);
static void gld_get_route(gld_mac_info_t *, queue_t *, uchar_t *,
struct gld_ri **, uchar_t, uchar_t);
static void gld_reset_route(gld_mac_info_t *, queue_t *,
uchar_t *, uchar_t, uchar_t);
static void gld_rde_pdu_ind(gld_mac_info_t *, struct gld_ri *, struct rde_pdu *,
int);
static void gld_rif_ind(gld_mac_info_t *, struct gld_ri *, uchar_t *,
uchar_t, uchar_t);
static struct srtab **gld_sr_hash(struct srtab **, uchar_t *, int);
static struct srtab *gld_sr_lookup_entry(gld_mac_info_t *, uchar_t *);
static struct srtab *gld_sr_create_entry(gld_mac_info_t *, uchar_t *);
/*
* This routine implements a modified subset of the 802.2 RDE RCC receive
* actions:
* we implement RCC receive events 3 to 12 (ISO 8802-2:1994 9.6.3.4);
* we omit special handling for the NULL SAP;
* we omit XID/TEST handling;
* we pass all packets (including RDE) upstream to LLC.
*/
static void
gld_rcc_receive(gld_mac_info_t *macinfo, pktinfo_t *pktinfo, struct gld_ri *rh,
uchar_t *llcpkt, int llcpktlen)
{
struct llc_snap_hdr *snaphdr = (struct llc_snap_hdr *)(llcpkt);
if (!((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_enabled)
return;
/*
* First, ensure this packet wasn't something we received just
* because we were in promiscuous mode. Since none of the below
* code wants to see group addressed packets anyway, we can do
* this check up front. Since we're doing that, we can omit the
* checks for group addressed packets below.
*/
if (!pktinfo->isForMe)
return; /* Event 6 */
/* Process a subset of Route Determination Entity (RDE) packets */
if (snaphdr->d_lsap == LSAP_RDE) {
struct rde_pdu *pdu = (struct rde_pdu *)(llcpkt + LLC_HDR1_LEN);
int pdulen = llcpktlen - LLC_HDR1_LEN;
/* sanity check the PDU */
if ((pdulen < sizeof (struct rde_pdu)) ||
(snaphdr->s_lsap != LSAP_RDE))
return;
/* we only handle route discovery PDUs, not XID/TEST/other */
if (snaphdr->control != CNTL_LLC_UI)
return;
switch (pdu->rde_ptype) {
case RDE_RQC: /* Route Query Command; Events 8 - 11 */
gld_send_rqr(macinfo, pktinfo->shost, rh, pdu, pdulen);
/* FALLTHROUGH */
case RDE_RQR: /* Route Query Response; Event 12 */
case RDE_RS: /* Route Selected; Event 7 */
gld_rde_pdu_ind(macinfo, rh, pdu, pdulen);
break;
default: /* ignore if unrecognized ptype */
return;
}
return;
}
/* Consider routes seen in other IA SRF packets */
if (rh == NULL)
return; /* no RIF; Event 3 */
if ((rh->rt & 0x04) != 0)
return; /* not SRF; Event 5 */
gld_rif_ind(macinfo, rh, pktinfo->shost, snaphdr->s_lsap,
snaphdr->d_lsap); /* Event 4 */
}
/*
* Send RQR: 802.2 9.6.3.4.2(9) RCC Receive Events 8-11
*
* The routing processing really doesn't belong here; it should be handled in
* the LLC layer above. If that were the case then RDE could just send down
* an extra MA_UNITDATA_REQ with the info needed to construct the packet. But
* at the time we get control here, it's not a particularly good time to be
* constructing packets and trying to send them. Specifically, at this layer
* we need to construct the full media packet, which means the below routine
* knows that it is dealing with Token Ring media. If this were instead done
* via a proper MA_UNITDATA interface, the RDE stuff could all be completely
* media independent. But since TR is the only source routing medium we
* support, this works even though it is not clean.
*
* We "know" that the only time we can get here is from the "interpret"
* routine, and only when it was called at receive time.
*/
static void
gld_send_rqr(gld_mac_info_t *macinfo, uchar_t *shost, struct gld_ri *rh,
struct rde_pdu *pdu, int pdulen)
{
mblk_t *nmp;
int nlen;
struct tr_mac_frm_nori *nmh;
struct gld_ri *nrh;
struct llc_snap_hdr *nsnaphdr;
struct rde_pdu *npdu;
/* We know and assume we're on the receive path */
ASSERT(GLDM_LOCK_HELD(macinfo));
if (pdulen < sizeof (struct rde_pdu))
return; /* Bad incoming PDU */
nlen = sizeof (struct tr_mac_frm) + LLC_HDR1_LEN +
sizeof (struct rde_pdu);
if ((nmp = allocb(nlen, BPRI_MED)) == NULL)
return;
nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
nmp->b_rptr -= sizeof (struct rde_pdu);
npdu = (struct rde_pdu *)(nmp->b_rptr);
*npdu = *pdu; /* copy orig/target macaddr/saps */
npdu->rde_ver = 1;
npdu->rde_ptype = RDE_RQR;
mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
npdu->rde_target_mac, macinfo->gldm_addrlen);
nmp->b_rptr -= LLC_HDR1_LEN;
nsnaphdr = (struct llc_snap_hdr *)(nmp->b_rptr);
nsnaphdr->s_lsap = nsnaphdr->d_lsap = LSAP_RDE;
nsnaphdr->control = CNTL_LLC_UI;
if (rh == NULL || (rh->rt & 0x06) == 0x06 ||
rh->len > sizeof (struct gld_ri)) {
/* no RIF (Event 8), or RIF type STE (Event 9): send ARE RQR */
nmp->b_rptr -= 2;
nrh = (struct gld_ri *)(nmp->b_rptr);
nrh->len = 2;
nrh->rt = RT_ARE;
nrh->dir = 0;
nrh->res = 0;
nrh->mtu = RT_MTU_MAX;
} else {
/*
* RIF must be ARE (Event 10) or SRF (Event 11):
* send SRF (reverse) RQR
*/
ASSERT(rh->len <= sizeof (struct gld_ri));
nmp->b_rptr -= rh->len;
nrh = (struct gld_ri *)(nmp->b_rptr);
bcopy(rh, nrh, rh->len); /* copy incoming RIF */
nrh->rt = RT_SRF; /* make it SRF */
nrh->dir ^= 1; /* reverse direction */
}
nmp->b_rptr -= sizeof (struct tr_mac_frm_nori);
nmh = (struct tr_mac_frm_nori *)(nmp->b_rptr);
nmh->tr_ac = 0x10;
nmh->tr_fc = 0x40;
mac_copy(shost, nmh->tr_dhost, macinfo->gldm_addrlen);
mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
nmh->tr_shost, macinfo->gldm_addrlen);
nmh->tr_shost[0] |= 0x80; /* indicate RIF present */
/*
* Packet assembled; send it.
*
* As noted before, this is not really a good time to be trying to
* send out packets. We have no obvious queue to use if the packet
* can't be sent right away. We pick one arbitrarily.
*/
{
gld_vlan_t *vlan;
queue_t *q;
if ((vlan = gld_find_vlan(macinfo, VLAN_VID_NONE)) == NULL) {
/* oops, no vlan on the list for this macinfo! */
/* this should not happen */
freeb(nmp);
return;
}
q = vlan->gldv_str_next->gld_qptr;
/*
* Queue the packet and let gld_wsrv
* handle it, thus preventing a panic
* caused by v2 TR in promiscuous mode
* where it attempts to get the mutex
* in this thread while already holding
* it.
*/
(void) putbq(WR(q), nmp);
qenable(WR(q));
}
}
/*
* This routine implements a modified subset of the 802.2 RDE RCC send actions:
* we implement RCC send events 5 to 10 (ISO 8802-2:1994 9.6.3.5);
* we omit special handling for the NULL SAP;
* events 11 to 12 are handled by gld_rde_pdu_req below;
* we require an immediate response to our GET_ROUTE_REQUEST.
*/
static void
gld_rcc_send(gld_mac_info_t *macinfo, queue_t *q, uchar_t *dhost,
struct gld_ri **rhp, uchar_t *llcpkt)
{
struct llc_snap_hdr *snaphdr = (struct llc_snap_hdr *)(llcpkt);
/*
* Our caller has to take the mutex because: to avoid an extra bcopy
* of the RIF on every transmit, we pass back a pointer to our sr
* table entry via rhp. He has to keep the mutex until he has a
* chance to copy the RIF out into the outgoing packet, so that we
* don't modify the entry while he's trying to copy it. This is a
* little ugly, but saves the extra bcopy.
*/
ASSERT(mutex_owned(GLD_SR_MUTEX(macinfo)));
*rhp = (struct gld_ri *)NULL; /* start off clean (no RIF) */
if (!((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_enabled) {
/* RDE is disabled -- use NULL or STE always */
if (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->
rde_str_indicator_ste)
*rhp = &ri_ste_def; /* STE option */
return;
}
if (!(dhost[0] & 0x80)) {
/* individual address; Events 7 - 10 */
if ((snaphdr->control & 0xef) == 0xe3) {
/* TEST command, reset the route */
gld_reset_route(macinfo, q,
dhost, snaphdr->d_lsap, snaphdr->s_lsap);
}
gld_get_route(macinfo, q,
dhost, rhp, snaphdr->d_lsap, snaphdr->s_lsap);
}
if (*rhp == NULL) {
/*
* group address (Events 5 - 6),
* or no route available (Events 8 - 9):
* Need to send NSR or STE, as configured.
*/
if (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->
rde_str_indicator_ste)
*rhp = &ri_ste_def; /* STE option */
}
}
/*
* RCC send events 11 - 12
*
* At present we only handle the RQC ptype.
*
* We "know" that the only time we can get here is from the "unitdata"
* routine, called at wsrv time.
*
* If we ever implement the RS ptype (Event 13), this may no longer be true!
*/
static void
gld_rde_pdu_req(gld_mac_info_t *macinfo, queue_t *q, uchar_t *dhost,
struct gld_ri *rh, uchar_t dsap, uchar_t ssap, uchar_t ptype)
{
mblk_t *nmp;
int nlen;
struct tr_mac_frm_nori *nmh;
struct gld_ri *nrh;
struct llc_snap_hdr *nsnaphdr;
struct rde_pdu *npdu;
int srpresent = 0;
/* if you change this to process other types, review all code below */
ASSERT(ptype == RDE_RQC);
ASSERT(rh == NULL); /* RQC never uses SRF */
nlen = sizeof (struct tr_mac_frm) + LLC_HDR1_LEN +
sizeof (struct rde_pdu);
if ((nmp = allocb(nlen, BPRI_MED)) == NULL)
return;
nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
nmp->b_rptr -= sizeof (struct rde_pdu);
npdu = (struct rde_pdu *)(nmp->b_rptr);
npdu->rde_ver = 1;
npdu->rde_ptype = ptype;
mac_copy(dhost, &npdu->rde_target_mac, 6);
/*
* access the mac address without a mutex - take a risk -
* to prevent mutex contention (BUG 4211361)
*/
mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
&npdu->rde_orig_mac, 6);
npdu->rde_target_sap = dsap;
npdu->rde_orig_sap = ssap;
nmp->b_rptr -= LLC_HDR1_LEN;
nsnaphdr = (struct llc_snap_hdr *)(nmp->b_rptr);
nsnaphdr->s_lsap = nsnaphdr->d_lsap = LSAP_RDE;
nsnaphdr->control = CNTL_LLC_UI;
#if 0 /* we don't need this for now */
if (rh != NULL) {
/* send an SRF frame with specified RIF */
ASSERT(rh->len <= sizeof (struct gld_ri));
nmp->b_rptr -= rh->len;
nrh = (struct gld_ri *)(nmp->b_rptr);
bcopy(rh, nrh, rh->len);
ASSERT(nrh->rt == RT_SRF);
srpresent = 1;
} else
#endif
/* Need to send NSR or STE, as configured. */
if (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_str_indicator_ste) {
/* send an STE frame */
nmp->b_rptr -= 2;
nrh = (struct gld_ri *)(nmp->b_rptr);
nrh->len = 2;
nrh->rt = RT_STE;
nrh->dir = 0;
nrh->res = 0;
nrh->mtu = RT_MTU_MAX;
srpresent = 1;
} /* else send an NSR frame */
nmp->b_rptr -= sizeof (struct tr_mac_frm_nori);
nmh = (struct tr_mac_frm_nori *)(nmp->b_rptr);
nmh->tr_ac = 0x10;
nmh->tr_fc = 0x40;
mac_copy(dhost, nmh->tr_dhost, macinfo->gldm_addrlen);
/*
* access the mac address without a mutex - take a risk -
* to prevent mutex contention - BUG 4211361
*/
mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
nmh->tr_shost, macinfo->gldm_addrlen);
if (srpresent)
nmh->tr_shost[0] |= 0x80;
else
nmh->tr_shost[0] &= ~0x80;
/*
* Packet assembled; send it.
*
* Since we own the SR_MUTEX, we don't want to take the maclock
* mutex (since they are acquired in the opposite order on the
* receive path, so deadlock could occur). We could rearrange
* the code in gld_get_route() and drop the SR_MUTEX around the
* call to gld_rde_pdu_req(), but that's kind of ugly. Rather,
* we just refrain from calling gld_start() from here, and
* instead just queue the packet for wsrv to send next. Besides,
* it's more important to get the packet we're working on out
* quickly than this RQC.
*/
(void) putbq(WR(q), nmp);
qenable(WR(q));
}
/*
* Route Determination Component (RDC)
*
* We do not implement separate routes for each SAP, as specified by
* ISO 8802-2; instead we implement only one route per remote mac address.
*/
static void
gld_get_route(gld_mac_info_t *macinfo, queue_t *q, uchar_t *dhost,
struct gld_ri **rhp, uchar_t dsap, uchar_t ssap)
{
struct srtab *sr;
clock_t t = ddi_get_lbolt();
ASSERT(mutex_owned(GLD_SR_MUTEX(macinfo)));
sr = gld_sr_lookup_entry(macinfo, dhost);
if (sr == NULL) {
/*
* we have no entry -- never heard of this address:
* create an empty entry and initiate RQC
*/
sr = gld_sr_create_entry(macinfo, dhost);
gld_rde_pdu_req(macinfo, q, dhost, (struct gld_ri *)NULL,
dsap, ssap, RDE_RQC);
if (sr)
sr->sr_timer = t;
*rhp = NULL; /* we have no route yet */
return;
}
/* we have an entry; see if we know a route yet */
if (sr->sr_ri.len == 0) {
/* Have asked RQC, but no reply (yet) */
if (t - sr->sr_timer >
((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_timeout) {
/* RQR overdue, resend RQC */
gld_rde_pdu_req(macinfo, q, dhost,
(struct gld_ri *)NULL, dsap, ssap, RDE_RQC);
sr->sr_timer = t;
}
*rhp = NULL; /* we have no route yet */
return;
}
/* we know a route, or it's local */
/* if it might be stale, reset and get a new one */
if (t - sr->sr_timer >
((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_timeout) {
gld_rde_pdu_req(macinfo, q, dhost,
(struct gld_ri *)NULL, dsap, ssap, RDE_RQC);
sr->sr_ri.len = 0;
sr->sr_timer = t;
*rhp = NULL; /* we have no route */
return;
}
if (sr->sr_ri.len == 2) {
/* the remote site is on our local ring -- no route needed */
*rhp = NULL;
return;
}
*rhp = &sr->sr_ri; /* we have a route, return it */
}
/*
* zap the specified entry and reinitiate RQC
*/
static void
gld_reset_route(gld_mac_info_t *macinfo, queue_t *q,
uchar_t *dhost, uchar_t dsap, uchar_t ssap)
{
struct srtab *sr;
ASSERT(mutex_owned(GLD_SR_MUTEX(macinfo)));
sr = gld_sr_create_entry(macinfo, dhost);
gld_rde_pdu_req(macinfo, q, dhost, (struct gld_ri *)NULL,
dsap, ssap, RDE_RQC);
if (sr == NULL)
return;
sr->sr_ri.len = 0;
sr->sr_timer = ddi_get_lbolt();
}
/*
* This routine is called when an RDE PDU is received from our peer.
* If it is an RS (Route Selected) PDU, we adopt the specified route.
* If it is an RQR (reply to our previous RQC), we evaluate the
* specified route in comparison with our current known route, if any,
* and we keep the "better" of the two routes.
*/
static void
gld_rde_pdu_ind(gld_mac_info_t *macinfo, struct gld_ri *rh, struct rde_pdu *pdu,
int pdulen)
{
struct srtab *sr;
uchar_t *otherhost;
if (pdulen < sizeof (struct rde_pdu))
return; /* Bad incoming PDU */
if (pdu->rde_ptype == RDE_RQC)
return; /* ignore RQC */
if (pdu->rde_ptype != RDE_RQR && pdu->rde_ptype != RDE_RS) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN, "gld: bogus RDE ptype 0x%x received",
pdu->rde_ptype);
#endif
return;
}
if (rh == NULL) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"gld: bogus NULL RIF, ptype 0x%x received",
pdu->rde_ptype);
#endif
return;
}
ASSERT(rh->len >= 2);
ASSERT(rh->len <= sizeof (struct gld_ri));
ASSERT((rh->len & 1) == 0);
if (pdu->rde_ptype == RDE_RQR) {
/* A reply to our RQC has his address as target mac */
otherhost = pdu->rde_target_mac;
} else {
ASSERT(pdu->rde_ptype == RDE_RS);
/* An RS has his address as orig mac */
otherhost = pdu->rde_orig_mac;
}
mutex_enter(GLD_SR_MUTEX(macinfo));
if ((sr = gld_sr_create_entry(macinfo, otherhost)) == NULL) {
mutex_exit(GLD_SR_MUTEX(macinfo));
return; /* oh well, out of memory */
}
if (pdu->rde_ptype == RDE_RQR) {
/* see if new route is better than what we may already have */
if (sr->sr_ri.len != 0 &&
sr->sr_ri.len <= rh->len) {
mutex_exit(GLD_SR_MUTEX(macinfo));
return; /* we have one, and new one is no shorter */
}
}
/* adopt the new route */
bcopy((caddr_t)rh, (caddr_t)&sr->sr_ri, rh->len); /* copy incom RIF */
sr->sr_ri.rt = RT_SRF; /* make it a clean SRF */
sr->sr_ri.dir ^= 1; /* reverse direction */
sr->sr_timer = ddi_get_lbolt();
mutex_exit(GLD_SR_MUTEX(macinfo));
}
/*
* This routine is called when a packet with a RIF is received. Our
* policy is to adopt the route.
*/
/* ARGSUSED3 */
static void
gld_rif_ind(gld_mac_info_t *macinfo, struct gld_ri *rh, uchar_t *shost,
uchar_t ssap, uchar_t dsap)
{
struct srtab *sr;
ASSERT(rh != NULL); /* ensure RIF */
ASSERT((rh->rt & 0x04) == 0); /* ensure SRF */
ASSERT(rh->len >= 2);
ASSERT(rh->len <= sizeof (struct gld_ri));
ASSERT((rh->len & 1) == 0);
mutex_enter(GLD_SR_MUTEX(macinfo));
if ((sr = gld_sr_create_entry(macinfo, shost)) == NULL) {
mutex_exit(GLD_SR_MUTEX(macinfo));
return; /* oh well, out of memory */
}
/* we have an entry; fill it in */
bcopy((caddr_t)rh, (caddr_t)&sr->sr_ri, rh->len); /* copy incom RIF */
sr->sr_ri.rt = RT_SRF; /* make it a clean SRF */
sr->sr_ri.dir ^= 1; /* reverse direction */
sr->sr_timer = ddi_get_lbolt();
mutex_exit(GLD_SR_MUTEX(macinfo));
}
static struct srtab **
gld_sr_hash(struct srtab **sr_hash_tbl, uchar_t *addr, int addr_length)
{
uint_t hashval = 0;
while (--addr_length >= 0)
hashval ^= *addr++;
return (&sr_hash_tbl[hashval % SR_HASH_SIZE]);
}
static struct srtab *
gld_sr_lookup_entry(gld_mac_info_t *macinfo, uchar_t *macaddr)
{
struct srtab *sr;
ASSERT(mutex_owned(GLD_SR_MUTEX(macinfo)));
for (sr = *gld_sr_hash(GLD_SR_HASH(macinfo), macaddr,
macinfo->gldm_addrlen); sr; sr = sr->sr_next)
if (mac_eq(macaddr, sr->sr_mac, macinfo->gldm_addrlen))
return (sr);
return ((struct srtab *)0);
}
static struct srtab *
gld_sr_create_entry(gld_mac_info_t *macinfo, uchar_t *macaddr)
{
struct srtab *sr;
struct srtab **srp;
ASSERT(!(macaddr[0] & 0x80)); /* no group addresses here */
ASSERT(mutex_owned(GLD_SR_MUTEX(macinfo)));
srp = gld_sr_hash(GLD_SR_HASH(macinfo), macaddr, macinfo->gldm_addrlen);
for (sr = *srp; sr; sr = sr->sr_next)
if (mac_eq(macaddr, sr->sr_mac, macinfo->gldm_addrlen))
return (sr);
if (!(sr = kmem_zalloc(sizeof (struct srtab), KM_NOSLEEP))) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"gld: gld_sr_create_entry kmem_alloc failed");
#endif
return ((struct srtab *)0);
}
bcopy((caddr_t)macaddr, (caddr_t)sr->sr_mac, macinfo->gldm_addrlen);
sr->sr_next = *srp;
*srp = sr;
return (sr);
}
static void
gld_sr_clear(gld_mac_info_t *macinfo)
{
int i;
struct srtab **sr_hash_tbl = GLD_SR_HASH(macinfo);
struct srtab **srp, *sr;
/*
* Walk through the table, deleting all entries.
*
* Only called from uninit, so don't need the mutex.
*/
for (i = 0; i < SR_HASH_SIZE; i++) {
for (srp = &sr_hash_tbl[i]; (sr = *srp) != NULL; ) {
*srp = sr->sr_next;
kmem_free((char *)sr, sizeof (struct srtab));
}
}
}
#ifdef DEBUG
void
gld_sr_dump(gld_mac_info_t *macinfo)
{
int i, j;
struct srtab **sr_hash_tbl;
struct srtab *sr;
sr_hash_tbl = GLD_SR_HASH(macinfo);
if (sr_hash_tbl == NULL)
return;
mutex_enter(GLD_SR_MUTEX(macinfo));
/*
* Walk through the table, printing all entries
*/
cmn_err(CE_NOTE, "GLD Source Routing Table (0x%p):", (void *)macinfo);
cmn_err(CE_CONT, "Addr len,rt,dir,mtu,res rng,brg0 rng,brg1...\n");
for (i = 0; i < SR_HASH_SIZE; i++) {
for (sr = sr_hash_tbl[i]; sr; sr = sr->sr_next) {
cmn_err(CE_CONT,
"%x:%x:%x:%x:%x:%x %d,%x,%x,%x,%x ",
sr->sr_mac[0], sr->sr_mac[1], sr->sr_mac[2],
sr->sr_mac[3], sr->sr_mac[4], sr->sr_mac[5],
sr->sr_ri.len, sr->sr_ri.rt, sr->sr_ri.dir,
sr->sr_ri.mtu, sr->sr_ri.res);
if (sr->sr_ri.len)
for (j = 0; j < (sr->sr_ri.len - 2) / 2; j++)
cmn_err(CE_CONT, "%x ",
REF_NET_USHORT(*(unsigned short *)
&sr->sr_ri.rd[j]));
cmn_err(CE_CONT, "\n");
}
}
mutex_exit(GLD_SR_MUTEX(macinfo));
}
#endif
|