Menu

[r10367]: / branches / dojo17 / patches / freebsd-vte.patch  Maximize  Restore  History

Download this file

3063 lines (3058 with data), 89.9 kB

   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
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
Index: sys/boot/forth/loader.conf
===================================================================
--- sys/boot/forth/loader.conf (revision 226546)
+++ sys/boot/forth/loader.conf (working copy)
@@ -327,6 +327,7 @@ if_tl_load="NO" # Texas Instruments TNETE100 ("T
if_tx_load="NO" # SMC 83c17x Fast Ethernet
if_txp_load="NO" # 3Com 3XP Typhoon/Sidewinder (3CR990)
if_vge_load="NO" # VIA VT6122 PCI Gigabit Ethernet
+if_vte_load="NO" # DM&P Vortex86 RDC R6040 Fast Ethernet
if_uath_load="NO" # Atheros USB wireless for AR5005UG & AR5005UX
if_udav_load="NO" # Davicom DM9601 USB Ethernet
if_upgt_load="NO" # Conexant/Intersil PrismGT USB wireless
Index: sys/conf/NOTES
===================================================================
--- sys/conf/NOTES (revision 226546)
+++ sys/conf/NOTES (working copy)
@@ -1935,6 +1935,7 @@ device miibus
# Technologies VT3043 `Rhine I' and VT86C100A `Rhine II' chips,
# including the D-Link DFE530TX (see 'rl' for DFE530TX+), the Hawking
# Technologies PN102TX, and the AOpen/Acer ALN-320.
+# vte: DM&P Vortex86 RDC R6040 Fast Ethernet
# vx: 3Com 3C590 and 3C595
# wb: Support for fast ethernet adapters based on the Winbond W89C840F chip.
# Note: this is not the same as the Winbond W89C940F, which is a
@@ -2007,6 +2008,7 @@ device stge # Sundance/Tamarack TC9021 gigabit E
device tl # Texas Instruments ThunderLAN
device tx # SMC EtherPower II (83c170 ``EPIC'')
device vr # VIA Rhine, Rhine II
+device vte # DM&P Vortex86 RDC R6040 Fast Ethernet
device wb # Winbond W89C840F
device xl # 3Com 3c90x (``Boomerang'', ``Cyclone'')
Index: sys/conf/files
===================================================================
--- sys/conf/files (revision 226546)
+++ sys/conf/files (working copy)
@@ -1280,6 +1280,7 @@ dev/mii/nsphy.c optional miibus | nsphy
dev/mii/nsphyter.c optional miibus | nsphyter
dev/mii/pnaphy.c optional miibus | pnaphy
dev/mii/qsphy.c optional miibus | qsphy
+dev/mii/rdcphy.c optional miibus | rdcphy
dev/mii/rgephy.c optional miibus | rgephy
dev/mii/rlphy.c optional miibus | rlphy
dev/mii/rlswitch.c optional rlswitch
@@ -1823,6 +1824,7 @@ dev/utopia/utopia.c optional utopia
dev/vge/if_vge.c optional vge
dev/vkbd/vkbd.c optional vkbd
dev/vr/if_vr.c optional vr pci
+dev/vte/if_vte.c optional vte pci
dev/vx/if_vx.c optional vx
dev/vx/if_vx_eisa.c optional vx eisa
dev/vx/if_vx_pci.c optional vx pci
Index: sys/dev/mii/miidevs
===================================================================
--- sys/dev/mii/miidevs (revision 226546)
+++ sys/dev/mii/miidevs (working copy)
@@ -59,6 +59,7 @@ oui JMICRON 0x001b8c JMicron Technologies
oui LEVEL1 0x00207b Level 1
oui NATSEMI 0x080017 National Semiconductor
oui QUALSEMI 0x006051 Quality Semiconductor
+oui RDC 0x000bb4 RDC Semiconductor
oui REALTEK 0x000020 RealTek Semicondctor
oui SEEQ 0x00a07d Seeq
oui SIS 0x00e006 Silicon Integrated Systems
@@ -212,6 +213,9 @@ model NATSEMI DP83865 0x0007 DP83865 10/100/1000
/* Quality Semiconductor PHYs */
model QUALSEMI QS6612 0x0000 QS6612 10/100 media interface
+/* RDC Semiconductor PHYs */
+model RDC R6040 0x0003 R6040 10/100 media interface
+
/* RealTek Semiconductor PHYs */
model REALTEK RTL8201L 0x0020 RTL8201L 10/100 media interface
model xxREALTEK RTL8305SC 0x0005 RTL8305SC 10/100 802.1q switch
Index: sys/dev/mii/rdcphy.c
===================================================================
--- sys/dev/mii/rdcphy.c (revision 0)
+++ sys/dev/mii/rdcphy.c (working copy)
@@ -0,0 +1,267 @@
+/*-
+ * Copyright (c) 2010, Pyun YongHyeon <yongari@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: http://svn.freebsd.org/base/releng/8.2/sys/dev/mii/rdcphy.c 216828 2010-12-30 23:50:25Z yongari $");
+
+/*
+ * Driver for the RDC Semiconductor R6040 10/100 PHY.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/socket.h>
+#include <sys/bus.h>
+
+#include <net/if.h>
+#include <net/if_media.h>
+
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+#include "miidevs.h"
+
+#include <dev/mii/rdcphyreg.h>
+
+#include "miibus_if.h"
+
+static device_probe_t rdcphy_probe;
+static device_attach_t rdcphy_attach;
+
+struct rdcphy_softc {
+ struct mii_softc mii_sc;
+ int mii_model;
+ int mii_link_tick;
+#define RDCPHY_MANNEG_TICK 3
+};
+
+static device_method_t rdcphy_methods[] = {
+ /* device interface */
+ DEVMETHOD(device_probe, rdcphy_probe),
+ DEVMETHOD(device_attach, rdcphy_attach),
+ DEVMETHOD(device_detach, mii_phy_detach),
+ DEVMETHOD(device_shutdown, bus_generic_shutdown),
+ KOBJMETHOD_END
+};
+
+static devclass_t rdcphy_devclass;
+
+static driver_t rdcphy_driver = {
+ "rdcphy",
+ rdcphy_methods,
+ sizeof(struct rdcphy_softc)
+};
+
+DRIVER_MODULE(rdcphy, miibus, rdcphy_driver, rdcphy_devclass, 0, 0);
+
+static int rdcphy_service(struct mii_softc *, struct mii_data *, int);
+static void rdcphy_status(struct mii_softc *);
+
+static const struct mii_phydesc rdcphys[] = {
+ MII_PHY_DESC(RDC, R6040),
+ MII_PHY_END
+};
+
+static int
+rdcphy_probe(device_t dev)
+{
+
+ return (mii_phy_dev_probe(dev, rdcphys, BUS_PROBE_DEFAULT));
+}
+
+static int
+rdcphy_attach(device_t dev)
+{
+ struct rdcphy_softc *rsc;
+ struct mii_softc *sc;
+ struct mii_attach_args *ma;
+ struct mii_data *mii;
+
+ rsc = device_get_softc(dev);
+ sc = &rsc->mii_sc;
+ ma = device_get_ivars(dev);
+ sc->mii_dev = device_get_parent(dev);
+ mii = ma->mii_data;
+ LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
+
+ sc->mii_flags = miibus_get_flags(dev);
+ sc->mii_inst = mii->mii_instance++;
+ sc->mii_phy = ma->mii_phyno;
+ sc->mii_service = rdcphy_service;
+ sc->mii_pdata = mii;
+
+ rsc->mii_model = MII_MODEL(ma->mii_id2);
+ if (bootverbose)
+ device_printf(dev, "OUI 0x%06x, model 0x%04x, rev. %d\n",
+ MII_OUI(ma->mii_id1, ma->mii_id2), MII_MODEL(ma->mii_id2),
+ MII_REV(ma->mii_id2));
+
+ mii_phy_reset(sc);
+
+ sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
+ if (sc->mii_capabilities & BMSR_EXTSTAT)
+ sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
+ device_printf(dev, " ");
+ mii_phy_add_media(sc);
+ printf("\n");
+
+ MIIBUS_MEDIAINIT(sc->mii_dev);
+ return (0);
+}
+
+static int
+rdcphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
+{
+ struct rdcphy_softc *rsc;
+ struct ifmedia_entry *ife;
+
+ rsc = (struct rdcphy_softc *)sc;
+ ife = mii->mii_media.ifm_cur;
+
+ switch (cmd) {
+ case MII_POLLSTAT:
+ break;
+
+ case MII_MEDIACHG:
+ /*
+ * If the interface is not up, don't do anything.
+ */
+ if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
+ break;
+
+ mii_phy_setmedia(sc);
+ switch (IFM_SUBTYPE(ife->ifm_media)) {
+ case IFM_100_TX:
+ case IFM_10_T:
+ /*
+ * Report fake lost link event to parent
+ * driver. This will stop MAC of parent
+ * driver and make it possible to reconfigure
+ * MAC after completion of link establishment.
+ * Note, the parent MAC seems to require
+ * restarting MAC when underlying any PHY
+ * configuration was changed even if the
+ * resolved speed/duplex was not changed at
+ * all.
+ */
+ mii->mii_media_status = 0;
+ mii->mii_media_active = IFM_ETHER | IFM_NONE;
+ rsc->mii_link_tick = RDCPHY_MANNEG_TICK;
+ /* Immediately report link down. */
+ mii_phy_update(sc, MII_MEDIACHG);
+ return (0);
+ default:
+ break;
+ }
+ break;
+
+ case MII_TICK:
+ if (mii_phy_tick(sc) == EJUSTRETURN)
+ return (0);
+ if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) {
+ /*
+ * It seems the PHY hardware does not correctly
+ * report link status changes when manual link
+ * configuration is in progress. It is also
+ * possible for the PHY to complete establishing
+ * a link within one second such that mii(4)
+ * did not notice the link change. To workaround
+ * the issue, emulate lost link event and wait
+ * for 3 seconds when manual link configuration
+ * is in progress. 3 seconds would be long
+ * enough to absorb transient link flips.
+ */
+ if (rsc->mii_link_tick > 0) {
+ rsc->mii_link_tick--;
+ return (0);
+ }
+ }
+ break;
+ }
+
+ /* Update the media status. */
+ rdcphy_status(sc);
+
+ /* Callback if something changed. */
+ mii_phy_update(sc, cmd);
+ return (0);
+}
+
+static void
+rdcphy_status(struct mii_softc *sc)
+{
+ struct mii_data *mii;
+ struct ifmedia_entry *ife;
+ int bmsr, bmcr, physts;
+
+ mii = sc->mii_pdata;
+ ife = mii->mii_media.ifm_cur;
+
+ mii->mii_media_status = IFM_AVALID;
+ mii->mii_media_active = IFM_ETHER;
+
+ bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
+ physts = PHY_READ(sc, MII_RDCPHY_STATUS);
+
+ if ((physts & STATUS_LINK_UP) != 0)
+ mii->mii_media_status |= IFM_ACTIVE;
+
+ bmcr = PHY_READ(sc, MII_BMCR);
+ if ((bmcr & BMCR_ISO) != 0) {
+ mii->mii_media_active |= IFM_NONE;
+ mii->mii_media_status = 0;
+ return;
+ }
+
+ if ((bmcr & BMCR_LOOP) != 0)
+ mii->mii_media_active |= IFM_LOOP;
+
+ if ((bmcr & BMCR_AUTOEN) != 0) {
+ if ((bmsr & BMSR_ACOMP) == 0) {
+ /* Erg, still trying, I guess... */
+ mii->mii_media_active |= IFM_NONE;
+ return;
+ }
+ }
+
+ switch (physts & STATUS_SPEED_MASK) {
+ case STATUS_SPEED_100:
+ mii->mii_media_active |= IFM_100_TX;
+ break;
+ case STATUS_SPEED_10:
+ mii->mii_media_active |= IFM_10_T;
+ break;
+ default:
+ mii->mii_media_active |= IFM_NONE;
+ return;
+ }
+ if ((physts & STATUS_FULL_DUPLEX) != 0)
+ mii->mii_media_active |= IFM_FDX | mii_phy_flowstatus(sc);
+ else
+ mii->mii_media_active |= IFM_HDX;
+}
Index: sys/dev/mii/rdcphyreg.h
===================================================================
--- sys/dev/mii/rdcphyreg.h (revision 0)
+++ sys/dev/mii/rdcphyreg.h (working copy)
@@ -0,0 +1,73 @@
+/*-
+ * Copyright (c) 2010, Pyun YongHyeon <yongari@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: http://svn.freebsd.org/base/releng/8.2/sys/dev/mii/rdcphyreg.h 216828 2010-12-30 23:50:25Z yongari $
+ */
+
+#ifndef _DEV_MII_RDCPHYREG_H_
+#define _DEV_MII_RDCPHYREG_H_
+
+#define MII_RDCPHY_DEBUG 0x11
+#define DEBUG_JABBER_DIS 0x0040
+#define DEBUG_LOOP_BACK_10MBPS 0x0400
+
+#define MII_RDCPHY_CTRL 0x14
+#define CTRL_SQE_ENB 0x0100
+#define CTRL_NEG_POLARITY 0x0400
+#define CTRL_AUTO_POLARITY 0x0800
+#define CTRL_MDIXSEL_RX 0x2000
+#define CTRL_MDIXSEL_TX 0x4000
+#define CTRL_AUTO_MDIX_DIS 0x8000
+
+#define MII_RDCPHY_CTRL2 0x15
+#define CTRL2_LED_DUPLEX 0x0000
+#define CTRL2_LED_DUPLEX_COL 0x0008
+#define CTRL2_LED_ACT 0x0010
+#define CTRL2_LED_SPEED_ACT 0x0018
+#define CTRL2_LED_BLK_100MBPS_DIS 0x0020
+#define CTRL2_LED_BLK_10MBPS_DIS 0x0040
+#define CTRL2_LED_BLK_LINK_ACT_DIS 0x0080
+#define CTRL2_SDT_THRESH_MASK 0x3E00
+#define CTRL2_TIMING_ERR_SEL 0x4000
+#define CTRL2_LED_BLK_80MS 0x8000
+#define CTRL2_LED_BLK_160MS 0x0000
+#define CTRL2_LED_MASK 0x0018
+
+#define MII_RDCPHY_STATUS 0x16
+#define STATUS_AUTO_MDIX_RX 0x0200
+#define STATUS_AUTO_MDIX_TX 0x0400
+#define STATUS_NEG_POLARITY 0x0800
+#define STATUS_FULL_DUPLEX 0x1000
+#define STATUS_SPEED_10 0x0000
+#define STATUS_SPEED_100 0x2000
+#define STATUS_SPEED_MASK 0x6000
+#define STATUS_LINK_UP 0x8000
+
+/* Analog test register 2 */
+#define MII_RDCPHY_TEST2 0x1A
+#define TEST2_PWR_DOWN 0x0200
+
+#endif /* _DEV_MII_RDCPHYREG_H_ */
Index: sys/dev/vte/if_vte.c
===================================================================
--- sys/dev/vte/if_vte.c (revision 0)
+++ sys/dev/vte/if_vte.c (working copy)
@@ -0,0 +1,2056 @@
+/*-
+ * Copyright (c) 2010, Pyun YongHyeon <yongari@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* Driver for DM&P Electronics, Inc, Vortex86 RDC R6040 FastEthernet. */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: http://svn.freebsd.org/base/releng/8.2/sys/dev/vte/if_vte.c 216829 2010-12-31 00:21:41Z yongari $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/endian.h>
+#include <sys/kernel.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
+#include <sys/rman.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+#include <sys/sysctl.h>
+
+#include <net/bpf.h>
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <net/ethernet.h>
+#include <net/if_dl.h>
+#include <net/if_llc.h>
+#include <net/if_media.h>
+#include <net/if_types.h>
+#include <net/if_vlan_var.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+
+#include <machine/bus.h>
+
+#if 0
+#include "if_vtereg.h"
+#include "if_vtevar.h"
+#else
+#include <dev/vte/if_vtereg.h>
+#include <dev/vte/if_vtevar.h>
+#endif
+
+/* "device miibus" required. See GENERIC if you get errors here. */
+#include "miibus_if.h"
+
+MODULE_DEPEND(vte, pci, 1, 1, 1);
+MODULE_DEPEND(vte, ether, 1, 1, 1);
+MODULE_DEPEND(vte, miibus, 1, 1, 1);
+
+/* Tunables. */
+static int tx_deep_copy = 1;
+TUNABLE_INT("hw.vte.tx_deep_copy", &tx_deep_copy);
+
+/*
+ * Devices supported by this driver.
+ */
+static const struct vte_ident vte_ident_table[] = {
+ { VENDORID_RDC, DEVICEID_RDC_R6040, "RDC R6040 FastEthernet"},
+ { 0, 0, NULL}
+};
+
+static int vte_attach(device_t);
+static int vte_detach(device_t);
+static int vte_dma_alloc(struct vte_softc *);
+static void vte_dma_free(struct vte_softc *);
+static void vte_dmamap_cb(void *, bus_dma_segment_t *, int, int);
+static struct vte_txdesc *
+ vte_encap(struct vte_softc *, struct mbuf **);
+static const struct vte_ident *
+ vte_find_ident(device_t);
+#ifndef __NO_STRICT_ALIGNMENT
+static struct mbuf *
+ vte_fixup_rx(struct ifnet *, struct mbuf *);
+#endif
+static void vte_get_macaddr(struct vte_softc *);
+static void vte_init(void *);
+static void vte_init_locked(struct vte_softc *);
+static int vte_init_rx_ring(struct vte_softc *);
+static int vte_init_tx_ring(struct vte_softc *);
+static void vte_intr(void *);
+static int vte_ioctl(struct ifnet *, u_long, caddr_t);
+static void vte_mac_config(struct vte_softc *);
+static int vte_miibus_readreg(device_t, int, int);
+static void vte_miibus_statchg(device_t);
+static int vte_miibus_writereg(device_t, int, int, int);
+static int vte_mediachange(struct ifnet *);
+static int vte_mediachange_locked(struct ifnet *);
+static void vte_mediastatus(struct ifnet *, struct ifmediareq *);
+static int vte_newbuf(struct vte_softc *, struct vte_rxdesc *);
+static int vte_probe(device_t);
+static void vte_reset(struct vte_softc *);
+static int vte_resume(device_t);
+static void vte_rxeof(struct vte_softc *);
+static void vte_rxfilter(struct vte_softc *);
+static int vte_shutdown(device_t);
+static void vte_start(struct ifnet *);
+static void vte_start_locked(struct vte_softc *);
+static void vte_start_mac(struct vte_softc *);
+static void vte_stats_clear(struct vte_softc *);
+static void vte_stats_update(struct vte_softc *);
+static void vte_stop(struct vte_softc *);
+static void vte_stop_mac(struct vte_softc *);
+static int vte_suspend(device_t);
+static void vte_sysctl_node(struct vte_softc *);
+static void vte_tick(void *);
+static void vte_txeof(struct vte_softc *);
+static void vte_watchdog(struct vte_softc *);
+static int sysctl_int_range(SYSCTL_HANDLER_ARGS, int, int);
+static int sysctl_hw_vte_int_mod(SYSCTL_HANDLER_ARGS);
+
+static device_method_t vte_methods[] = {
+ /* Device interface. */
+ DEVMETHOD(device_probe, vte_probe),
+ DEVMETHOD(device_attach, vte_attach),
+ DEVMETHOD(device_detach, vte_detach),
+ DEVMETHOD(device_shutdown, vte_shutdown),
+ DEVMETHOD(device_suspend, vte_suspend),
+ DEVMETHOD(device_resume, vte_resume),
+
+ /* MII interface. */
+ DEVMETHOD(miibus_readreg, vte_miibus_readreg),
+ DEVMETHOD(miibus_writereg, vte_miibus_writereg),
+ DEVMETHOD(miibus_statchg, vte_miibus_statchg),
+
+ KOBJMETHOD_END
+};
+
+static driver_t vte_driver = {
+ "vte",
+ vte_methods,
+ sizeof(struct vte_softc)
+};
+
+static devclass_t vte_devclass;
+
+DRIVER_MODULE(vte, pci, vte_driver, vte_devclass, 0, 0);
+DRIVER_MODULE(miibus, vte, miibus_driver, miibus_devclass, 0, 0);
+
+static int
+vte_miibus_readreg(device_t dev, int phy, int reg)
+{
+ struct vte_softc *sc;
+ int i;
+
+ sc = device_get_softc(dev);
+
+ CSR_WRITE_2(sc, VTE_MMDIO, MMDIO_READ |
+ (phy << MMDIO_PHY_ADDR_SHIFT) | (reg << MMDIO_REG_ADDR_SHIFT));
+ for (i = VTE_PHY_TIMEOUT; i > 0; i--) {
+ DELAY(5);
+ if ((CSR_READ_2(sc, VTE_MMDIO) & MMDIO_READ) == 0)
+ break;
+ }
+
+ if (i == 0) {
+ device_printf(sc->vte_dev, "phy read timeout : %d\n", reg);
+ return (0);
+ }
+
+ return (CSR_READ_2(sc, VTE_MMRD));
+}
+
+static int
+vte_miibus_writereg(device_t dev, int phy, int reg, int val)
+{
+ struct vte_softc *sc;
+ int i;
+
+ sc = device_get_softc(dev);
+
+ CSR_WRITE_2(sc, VTE_MMWD, val);
+ CSR_WRITE_2(sc, VTE_MMDIO, MMDIO_WRITE |
+ (phy << MMDIO_PHY_ADDR_SHIFT) | (reg << MMDIO_REG_ADDR_SHIFT));
+ for (i = VTE_PHY_TIMEOUT; i > 0; i--) {
+ DELAY(5);
+ if ((CSR_READ_2(sc, VTE_MMDIO) & MMDIO_WRITE) == 0)
+ break;
+ }
+
+ if (i == 0)
+ device_printf(sc->vte_dev, "phy write timeout : %d\n", reg);
+
+ return (0);
+}
+
+static void
+vte_miibus_statchg(device_t dev)
+{
+ struct vte_softc *sc;
+ struct mii_data *mii;
+ struct ifnet *ifp;
+ uint16_t val;
+
+ sc = device_get_softc(dev);
+
+ mii = device_get_softc(sc->vte_miibus);
+ ifp = sc->vte_ifp;
+ if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
+ return;
+
+ sc->vte_flags &= ~VTE_FLAG_LINK;
+ if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
+ (IFM_ACTIVE | IFM_AVALID)) {
+ switch (IFM_SUBTYPE(mii->mii_media_active)) {
+ case IFM_10_T:
+ case IFM_100_TX:
+ sc->vte_flags |= VTE_FLAG_LINK;
+ break;
+ default:
+ break;
+ }
+ }
+
+ /* Stop RX/TX MACs. */
+ vte_stop_mac(sc);
+ /* Program MACs with resolved duplex and flow control. */
+ if ((sc->vte_flags & VTE_FLAG_LINK) != 0) {
+ /*
+ * Timer waiting time : (63 + TIMER * 64) MII clock.
+ * MII clock : 25MHz(100Mbps) or 2.5MHz(10Mbps).
+ */
+ if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX)
+ val = 18 << VTE_IM_TIMER_SHIFT;
+ else
+ val = 1 << VTE_IM_TIMER_SHIFT;
+ val |= sc->vte_int_rx_mod << VTE_IM_BUNDLE_SHIFT;
+ /* 48.6us for 100Mbps, 50.8us for 10Mbps */
+ CSR_WRITE_2(sc, VTE_MRICR, val);
+
+ if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX)
+ val = 18 << VTE_IM_TIMER_SHIFT;
+ else
+ val = 1 << VTE_IM_TIMER_SHIFT;
+ val |= sc->vte_int_tx_mod << VTE_IM_BUNDLE_SHIFT;
+ /* 48.6us for 100Mbps, 50.8us for 10Mbps */
+ CSR_WRITE_2(sc, VTE_MTICR, val);
+
+ vte_mac_config(sc);
+ vte_start_mac(sc);
+ }
+}
+
+static void
+vte_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
+{
+ struct vte_softc *sc;
+ struct mii_data *mii;
+
+ sc = ifp->if_softc;
+ VTE_LOCK(sc);
+ if ((ifp->if_flags & IFF_UP) == 0) {
+ VTE_UNLOCK(sc);
+ return;
+ }
+ mii = device_get_softc(sc->vte_miibus);
+
+ mii_pollstat(mii);
+ VTE_UNLOCK(sc);
+ ifmr->ifm_status = mii->mii_media_status;
+ ifmr->ifm_active = mii->mii_media_active;
+}
+
+static int
+vte_mediachange(struct ifnet *ifp)
+{
+ struct vte_softc *sc;
+ int error;
+
+ sc = ifp->if_softc;
+ VTE_LOCK(sc);
+ error = vte_mediachange_locked(ifp);
+ VTE_UNLOCK(sc);
+ return (error);
+}
+
+static int
+vte_mediachange_locked(struct ifnet *ifp)
+{
+ struct vte_softc *sc;
+ struct mii_data *mii;
+ struct mii_softc *miisc;
+ int error;
+
+ sc = ifp->if_softc;
+ mii = device_get_softc(sc->vte_miibus);
+ if (mii->mii_instance != 0) {
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ mii_phy_reset(miisc);
+ }
+ error = mii_mediachg(mii);
+
+ return (error);
+}
+
+static const struct vte_ident *
+vte_find_ident(device_t dev)
+{
+ const struct vte_ident *ident;
+ uint16_t vendor, devid;
+
+ vendor = pci_get_vendor(dev);
+ devid = pci_get_device(dev);
+ for (ident = vte_ident_table; ident->name != NULL; ident++) {
+ if (vendor == ident->vendorid && devid == ident->deviceid)
+ return (ident);
+ }
+
+ return (NULL);
+}
+
+static int
+vte_probe(device_t dev)
+{
+ const struct vte_ident *ident;
+
+ ident = vte_find_ident(dev);
+ if (ident != NULL) {
+ device_set_desc(dev, ident->name);
+ return (BUS_PROBE_DEFAULT);
+ }
+
+ return (ENXIO);
+}
+
+static void
+vte_get_macaddr(struct vte_softc *sc)
+{
+ uint16_t mid;
+
+ /*
+ * It seems there is no way to reload station address and
+ * it is supposed to be set by BIOS.
+ */
+ mid = CSR_READ_2(sc, VTE_MID0L);
+ sc->vte_eaddr[0] = (mid >> 0) & 0xFF;
+ sc->vte_eaddr[1] = (mid >> 8) & 0xFF;
+ mid = CSR_READ_2(sc, VTE_MID0M);
+ sc->vte_eaddr[2] = (mid >> 0) & 0xFF;
+ sc->vte_eaddr[3] = (mid >> 8) & 0xFF;
+ mid = CSR_READ_2(sc, VTE_MID0H);
+ sc->vte_eaddr[4] = (mid >> 0) & 0xFF;
+ sc->vte_eaddr[5] = (mid >> 8) & 0xFF;
+}
+
+static int
+vte_attach(device_t dev)
+{
+ struct vte_softc *sc;
+ struct ifnet *ifp;
+ uint16_t macid;
+ int error, rid;
+
+ error = 0;
+ sc = device_get_softc(dev);
+ sc->vte_dev = dev;
+
+ mtx_init(&sc->vte_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
+ MTX_DEF);
+ callout_init_mtx(&sc->vte_tick_ch, &sc->vte_mtx, 0);
+ sc->vte_ident = vte_find_ident(dev);
+
+ /* Map the device. */
+ pci_enable_busmaster(dev);
+ sc->vte_res_id = PCIR_BAR(1);
+ sc->vte_res_type = SYS_RES_MEMORY;
+ sc->vte_res = bus_alloc_resource_any(dev, sc->vte_res_type,
+ &sc->vte_res_id, RF_ACTIVE);
+ if (sc->vte_res == NULL) {
+ sc->vte_res_id = PCIR_BAR(0);
+ sc->vte_res_type = SYS_RES_IOPORT;
+ sc->vte_res = bus_alloc_resource_any(dev, sc->vte_res_type,
+ &sc->vte_res_id, RF_ACTIVE);
+ if (sc->vte_res == NULL) {
+ device_printf(dev, "cannot map memory/ports.\n");
+ mtx_destroy(&sc->vte_mtx);
+ return (ENXIO);
+ }
+ }
+ if (bootverbose) {
+ device_printf(dev, "using %s space register mapping\n",
+ sc->vte_res_type == SYS_RES_MEMORY ? "memory" : "I/O");
+ device_printf(dev, "MAC Identifier : 0x%04x\n",
+ CSR_READ_2(sc, VTE_MACID));
+ macid = CSR_READ_2(sc, VTE_MACID_REV);
+ device_printf(dev, "MAC Id. 0x%02x, Rev. 0x%02x\n",
+ (macid & VTE_MACID_MASK) >> VTE_MACID_SHIFT,
+ (macid & VTE_MACID_REV_MASK) >> VTE_MACID_REV_SHIFT);
+ }
+
+ rid = 0;
+ sc->vte_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
+ RF_SHAREABLE | RF_ACTIVE);
+ if (sc->vte_irq == NULL) {
+ device_printf(dev, "cannot allocate IRQ resources.\n");
+ error = ENXIO;
+ goto fail;
+ }
+
+ /* Reset the ethernet controller. */
+ vte_reset(sc);
+
+ if ((error = vte_dma_alloc(sc) != 0))
+ goto fail;
+
+ /* Create device sysctl node. */
+ vte_sysctl_node(sc);
+
+ /* Load station address. */
+ vte_get_macaddr(sc);
+
+ ifp = sc->vte_ifp = if_alloc(IFT_ETHER);
+ if (ifp == NULL) {
+ device_printf(dev, "cannot allocate ifnet structure.\n");
+ error = ENXIO;
+ goto fail;
+ }
+
+ ifp->if_softc = sc;
+ if_initname(ifp, device_get_name(dev), device_get_unit(dev));
+ ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
+ ifp->if_ioctl = vte_ioctl;
+ ifp->if_start = vte_start;
+ ifp->if_init = vte_init;
+ ifp->if_snd.ifq_drv_maxlen = VTE_TX_RING_CNT - 1;
+ IFQ_SET_MAXLEN(&ifp->if_snd, ifp->if_snd.ifq_drv_maxlen);
+ IFQ_SET_READY(&ifp->if_snd);
+
+ /*
+ * Set up MII bus.
+ * BIOS would have initialized VTE_MPSCCR to catch PHY
+ * status changes so driver may be able to extract
+ * configured PHY address. Since it's common to see BIOS
+ * fails to initialize the register(including the sample
+ * board I have), let mii(4) probe it. This is more
+ * reliable than relying on BIOS's initialization.
+ *
+ * Advertising flow control capability to mii(4) was
+ * intentionally disabled due to severe problems in TX
+ * pause frame generation. See vte_rxeof() for more
+ * details.
+ */
+ error = mii_attach(dev, &sc->vte_miibus, ifp, vte_mediachange,
+ vte_mediastatus, BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0);
+ if (error != 0) {
+ device_printf(dev, "attaching PHYs failed\n");
+ goto fail;
+ }
+
+ ether_ifattach(ifp, sc->vte_eaddr);
+
+ /* VLAN capability setup. */
+ ifp->if_capabilities |= IFCAP_VLAN_MTU;
+ ifp->if_capenable = ifp->if_capabilities;
+ /* Tell the upper layer we support VLAN over-sized frames. */
+ ifp->if_hdrlen = sizeof(struct ether_vlan_header);
+
+ error = bus_setup_intr(dev, sc->vte_irq, INTR_TYPE_NET | INTR_MPSAFE,
+ NULL, vte_intr, sc, &sc->vte_intrhand);
+ if (error != 0) {
+ device_printf(dev, "could not set up interrupt handler.\n");
+ ether_ifdetach(ifp);
+ goto fail;
+ }
+
+fail:
+ if (error != 0)
+ vte_detach(dev);
+
+ return (error);
+}
+
+static int
+vte_detach(device_t dev)
+{
+ struct vte_softc *sc;
+ struct ifnet *ifp;
+
+ sc = device_get_softc(dev);
+
+ ifp = sc->vte_ifp;
+ if (device_is_attached(dev)) {
+ VTE_LOCK(sc);
+ vte_stop(sc);
+ VTE_UNLOCK(sc);
+ callout_drain(&sc->vte_tick_ch);
+ ether_ifdetach(ifp);
+ }
+
+ if (sc->vte_miibus != NULL) {
+ device_delete_child(dev, sc->vte_miibus);
+ sc->vte_miibus = NULL;
+ }
+ bus_generic_detach(dev);
+
+ if (sc->vte_intrhand != NULL) {
+ bus_teardown_intr(dev, sc->vte_irq, sc->vte_intrhand);
+ sc->vte_intrhand = NULL;
+ }
+ if (sc->vte_irq != NULL) {
+ bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vte_irq);
+ sc->vte_irq = NULL;
+ }
+ if (sc->vte_res != NULL) {
+ bus_release_resource(dev, sc->vte_res_type, sc->vte_res_id,
+ sc->vte_res);
+ sc->vte_res = NULL;
+ }
+ if (ifp != NULL) {
+ if_free(ifp);
+ sc->vte_ifp = NULL;
+ }
+ vte_dma_free(sc);
+ mtx_destroy(&sc->vte_mtx);
+
+ return (0);
+}
+
+#define VTE_SYSCTL_STAT_ADD32(c, h, n, p, d) \
+ SYSCTL_ADD_UINT(c, h, OID_AUTO, n, CTLFLAG_RD, p, 0, d)
+
+static void
+vte_sysctl_node(struct vte_softc *sc)
+{
+ struct sysctl_ctx_list *ctx;
+ struct sysctl_oid_list *child, *parent;
+ struct sysctl_oid *tree;
+ struct vte_hw_stats *stats;
+ int error;
+
+ stats = &sc->vte_stats;
+ ctx = device_get_sysctl_ctx(sc->vte_dev);
+ child = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->vte_dev));
+
+ SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "int_rx_mod",
+ CTLTYPE_INT | CTLFLAG_RW, &sc->vte_int_rx_mod, 0,
+ sysctl_hw_vte_int_mod, "I", "vte RX interrupt moderation");
+ SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "int_tx_mod",
+ CTLTYPE_INT | CTLFLAG_RW, &sc->vte_int_tx_mod, 0,
+ sysctl_hw_vte_int_mod, "I", "vte TX interrupt moderation");
+ /* Pull in device tunables. */
+ sc->vte_int_rx_mod = VTE_IM_RX_BUNDLE_DEFAULT;
+ error = resource_int_value(device_get_name(sc->vte_dev),
+ device_get_unit(sc->vte_dev), "int_rx_mod", &sc->vte_int_rx_mod);
+ if (error == 0) {
+ if (sc->vte_int_rx_mod < VTE_IM_BUNDLE_MIN ||
+ sc->vte_int_rx_mod > VTE_IM_BUNDLE_MAX) {
+ device_printf(sc->vte_dev, "int_rx_mod value out of "
+ "range; using default: %d\n",
+ VTE_IM_RX_BUNDLE_DEFAULT);
+ sc->vte_int_rx_mod = VTE_IM_RX_BUNDLE_DEFAULT;
+ }
+ }
+
+ sc->vte_int_tx_mod = VTE_IM_TX_BUNDLE_DEFAULT;
+ error = resource_int_value(device_get_name(sc->vte_dev),
+ device_get_unit(sc->vte_dev), "int_tx_mod", &sc->vte_int_tx_mod);
+ if (error == 0) {
+ if (sc->vte_int_tx_mod < VTE_IM_BUNDLE_MIN ||
+ sc->vte_int_tx_mod > VTE_IM_BUNDLE_MAX) {
+ device_printf(sc->vte_dev, "int_tx_mod value out of "
+ "range; using default: %d\n",
+ VTE_IM_TX_BUNDLE_DEFAULT);
+ sc->vte_int_tx_mod = VTE_IM_TX_BUNDLE_DEFAULT;
+ }
+ }
+
+ tree = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "stats", CTLFLAG_RD,
+ NULL, "VTE statistics");
+ parent = SYSCTL_CHILDREN(tree);
+
+ /* RX statistics. */
+ tree = SYSCTL_ADD_NODE(ctx, parent, OID_AUTO, "rx", CTLFLAG_RD,
+ NULL, "RX MAC statistics");
+ child = SYSCTL_CHILDREN(tree);
+ VTE_SYSCTL_STAT_ADD32(ctx, child, "good_frames",
+ &stats->rx_frames, "Good frames");
+ VTE_SYSCTL_STAT_ADD32(ctx, child, "good_bcast_frames",
+ &stats->rx_bcast_frames, "Good broadcast frames");
+ VTE_SYSCTL_STAT_ADD32(ctx, child, "good_mcast_frames",
+ &stats->rx_mcast_frames, "Good multicast frames");
+ VTE_SYSCTL_STAT_ADD32(ctx, child, "runt",
+ &stats->rx_runts, "Too short frames");
+ VTE_SYSCTL_STAT_ADD32(ctx, child, "crc_errs",
+ &stats->rx_crcerrs, "CRC errors");
+ VTE_SYSCTL_STAT_ADD32(ctx, child, "long_frames",
+ &stats->rx_long_frames,
+ "Frames that have longer length than maximum packet length");
+ VTE_SYSCTL_STAT_ADD32(ctx, child, "fifo_full",
+ &stats->rx_fifo_full, "FIFO full");
+ VTE_SYSCTL_STAT_ADD32(ctx, child, "desc_unavail",
+ &stats->rx_desc_unavail, "Descriptor unavailable frames");
+ VTE_SYSCTL_STAT_ADD32(ctx, child, "pause_frames",
+ &stats->rx_pause_frames, "Pause control frames");
+
+ /* TX statistics. */
+ tree = SYSCTL_ADD_NODE(ctx, parent, OID_AUTO, "tx", CTLFLAG_RD,
+ NULL, "TX MAC statistics");
+ child = SYSCTL_CHILDREN(tree);
+ VTE_SYSCTL_STAT_ADD32(ctx, child, "good_frames",
+ &stats->tx_frames, "Good frames");
+ VTE_SYSCTL_STAT_ADD32(ctx, child, "underruns",
+ &stats->tx_underruns, "FIFO underruns");
+ VTE_SYSCTL_STAT_ADD32(ctx, child, "late_colls",
+ &stats->tx_late_colls, "Late collisions");
+ VTE_SYSCTL_STAT_ADD32(ctx, child, "pause_frames",
+ &stats->tx_pause_frames, "Pause control frames");
+}
+
+#undef VTE_SYSCTL_STAT_ADD32
+
+struct vte_dmamap_arg {
+ bus_addr_t vte_busaddr;
+};
+
+static void
+vte_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
+{
+ struct vte_dmamap_arg *ctx;
+
+ if (error != 0)
+ return;
+
+ KASSERT(nsegs == 1, ("%s: %d segments returned!", __func__, nsegs));
+
+ ctx = (struct vte_dmamap_arg *)arg;
+ ctx->vte_busaddr = segs[0].ds_addr;
+}
+
+static int
+vte_dma_alloc(struct vte_softc *sc)
+{
+ struct vte_txdesc *txd;
+ struct vte_rxdesc *rxd;
+ struct vte_dmamap_arg ctx;
+ int error, i;
+
+ /* Create parent DMA tag. */
+ error = bus_dma_tag_create(
+ bus_get_dma_tag(sc->vte_dev), /* parent */
+ 1, 0, /* alignment, boundary */
+ BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
+ BUS_SPACE_MAXADDR, /* highaddr */
+ NULL, NULL, /* filter, filterarg */
+ BUS_SPACE_MAXSIZE_32BIT, /* maxsize */
+ 0, /* nsegments */
+ BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
+ 0, /* flags */
+ NULL, NULL, /* lockfunc, lockarg */
+ &sc->vte_cdata.vte_parent_tag);
+ if (error != 0) {
+ device_printf(sc->vte_dev,
+ "could not create parent DMA tag.\n");
+ goto fail;
+ }
+
+ /* Create DMA tag for TX descriptor ring. */
+ error = bus_dma_tag_create(
+ sc->vte_cdata.vte_parent_tag, /* parent */
+ VTE_TX_RING_ALIGN, 0, /* alignment, boundary */
+ BUS_SPACE_MAXADDR, /* lowaddr */
+ BUS_SPACE_MAXADDR, /* highaddr */
+ NULL, NULL, /* filter, filterarg */
+ VTE_TX_RING_SZ, /* maxsize */
+ 1, /* nsegments */
+ VTE_TX_RING_SZ, /* maxsegsize */
+ 0, /* flags */
+ NULL, NULL, /* lockfunc, lockarg */
+ &sc->vte_cdata.vte_tx_ring_tag);
+ if (error != 0) {
+ device_printf(sc->vte_dev,
+ "could not create TX ring DMA tag.\n");
+ goto fail;
+ }
+
+ /* Create DMA tag for RX free descriptor ring. */
+ error = bus_dma_tag_create(
+ sc->vte_cdata.vte_parent_tag, /* parent */
+ VTE_RX_RING_ALIGN, 0, /* alignment, boundary */
+ BUS_SPACE_MAXADDR, /* lowaddr */
+ BUS_SPACE_MAXADDR, /* highaddr */
+ NULL, NULL, /* filter, filterarg */
+ VTE_RX_RING_SZ, /* maxsize */
+ 1, /* nsegments */
+ VTE_RX_RING_SZ, /* maxsegsize */
+ 0, /* flags */
+ NULL, NULL, /* lockfunc, lockarg */
+ &sc->vte_cdata.vte_rx_ring_tag);
+ if (error != 0) {
+ device_printf(sc->vte_dev,
+ "could not create RX ring DMA tag.\n");
+ goto fail;
+ }
+
+ /* Allocate DMA'able memory and load the DMA map for TX ring. */
+ error = bus_dmamem_alloc(sc->vte_cdata.vte_tx_ring_tag,
+ (void **)&sc->vte_cdata.vte_tx_ring,
+ BUS_DMA_WAITOK | BUS_DMA_ZERO | BUS_DMA_COHERENT,
+ &sc->vte_cdata.vte_tx_ring_map);
+ if (error != 0) {
+ device_printf(sc->vte_dev,
+ "could not allocate DMA'able memory for TX ring.\n");
+ goto fail;
+ }
+ ctx.vte_busaddr = 0;
+ error = bus_dmamap_load(sc->vte_cdata.vte_tx_ring_tag,
+ sc->vte_cdata.vte_tx_ring_map, sc->vte_cdata.vte_tx_ring,
+ VTE_TX_RING_SZ, vte_dmamap_cb, &ctx, 0);
+ if (error != 0 || ctx.vte_busaddr == 0) {
+ device_printf(sc->vte_dev,
+ "could not load DMA'able memory for TX ring.\n");
+ goto fail;
+ }
+ sc->vte_cdata.vte_tx_ring_paddr = ctx.vte_busaddr;
+
+ /* Allocate DMA'able memory and load the DMA map for RX ring. */
+ error = bus_dmamem_alloc(sc->vte_cdata.vte_rx_ring_tag,
+ (void **)&sc->vte_cdata.vte_rx_ring,
+ BUS_DMA_WAITOK | BUS_DMA_ZERO | BUS_DMA_COHERENT,
+ &sc->vte_cdata.vte_rx_ring_map);
+ if (error != 0) {
+ device_printf(sc->vte_dev,
+ "could not allocate DMA'able memory for RX ring.\n");
+ goto fail;
+ }
+ ctx.vte_busaddr = 0;
+ error = bus_dmamap_load(sc->vte_cdata.vte_rx_ring_tag,
+ sc->vte_cdata.vte_rx_ring_map, sc->vte_cdata.vte_rx_ring,
+ VTE_RX_RING_SZ, vte_dmamap_cb, &ctx, 0);
+ if (error != 0 || ctx.vte_busaddr == 0) {
+ device_printf(sc->vte_dev,
+ "could not load DMA'able memory for RX ring.\n");
+ goto fail;
+ }
+ sc->vte_cdata.vte_rx_ring_paddr = ctx.vte_busaddr;
+
+ /* Create TX buffer parent tag. */
+ error = bus_dma_tag_create(
+ bus_get_dma_tag(sc->vte_dev), /* parent */
+ 1, 0, /* alignment, boundary */
+ BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
+ BUS_SPACE_MAXADDR, /* highaddr */
+ NULL, NULL, /* filter, filterarg */
+ BUS_SPACE_MAXSIZE_32BIT, /* maxsize */
+ 0, /* nsegments */
+ BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
+ 0, /* flags */
+ NULL, NULL, /* lockfunc, lockarg */
+ &sc->vte_cdata.vte_buffer_tag);
+ if (error != 0) {
+ device_printf(sc->vte_dev,
+ "could not create parent buffer DMA tag.\n");
+ goto fail;
+ }
+
+ /* Create DMA tag for TX buffers. */
+ error = bus_dma_tag_create(
+ sc->vte_cdata.vte_buffer_tag, /* parent */
+ 1, 0, /* alignment, boundary */
+ BUS_SPACE_MAXADDR, /* lowaddr */
+ BUS_SPACE_MAXADDR, /* highaddr */
+ NULL, NULL, /* filter, filterarg */
+ MCLBYTES, /* maxsize */
+ 1, /* nsegments */
+ MCLBYTES, /* maxsegsize */
+ 0, /* flags */
+ NULL, NULL, /* lockfunc, lockarg */
+ &sc->vte_cdata.vte_tx_tag);
+ if (error != 0) {
+ device_printf(sc->vte_dev, "could not create TX DMA tag.\n");
+ goto fail;
+ }
+
+ /* Create DMA tag for RX buffers. */
+ error = bus_dma_tag_create(
+ sc->vte_cdata.vte_buffer_tag, /* parent */
+ VTE_RX_BUF_ALIGN, 0, /* alignment, boundary */
+ BUS_SPACE_MAXADDR, /* lowaddr */
+ BUS_SPACE_MAXADDR, /* highaddr */
+ NULL, NULL, /* filter, filterarg */
+ MCLBYTES, /* maxsize */
+ 1, /* nsegments */
+ MCLBYTES, /* maxsegsize */
+ 0, /* flags */
+ NULL, NULL, /* lockfunc, lockarg */
+ &sc->vte_cdata.vte_rx_tag);
+ if (error != 0) {
+ device_printf(sc->vte_dev, "could not create RX DMA tag.\n");
+ goto fail;
+ }
+ /* Create DMA maps for TX buffers. */
+ for (i = 0; i < VTE_TX_RING_CNT; i++) {
+ txd = &sc->vte_cdata.vte_txdesc[i];
+ txd->tx_m = NULL;
+ txd->tx_dmamap = NULL;
+ error = bus_dmamap_create(sc->vte_cdata.vte_tx_tag, 0,
+ &txd->tx_dmamap);
+ if (error != 0) {
+ device_printf(sc->vte_dev,
+ "could not create TX dmamap.\n");
+ goto fail;
+ }
+ }
+ /* Create DMA maps for RX buffers. */
+ if ((error = bus_dmamap_create(sc->vte_cdata.vte_rx_tag, 0,
+ &sc->vte_cdata.vte_rx_sparemap)) != 0) {
+ device_printf(sc->vte_dev,
+ "could not create spare RX dmamap.\n");
+ goto fail;
+ }
+ for (i = 0; i < VTE_RX_RING_CNT; i++) {
+ rxd = &sc->vte_cdata.vte_rxdesc[i];
+ rxd->rx_m = NULL;
+ rxd->rx_dmamap = NULL;
+ error = bus_dmamap_create(sc->vte_cdata.vte_rx_tag, 0,
+ &rxd->rx_dmamap);
+ if (error != 0) {
+ device_printf(sc->vte_dev,
+ "could not create RX dmamap.\n");
+ goto fail;
+ }
+ }
+
+fail:
+ return (error);
+}
+
+static void
+vte_dma_free(struct vte_softc *sc)
+{
+ struct vte_txdesc *txd;
+ struct vte_rxdesc *rxd;
+ int i;
+
+ /* TX buffers. */
+ if (sc->vte_cdata.vte_tx_tag != NULL) {
+ for (i = 0; i < VTE_TX_RING_CNT; i++) {
+ txd = &sc->vte_cdata.vte_txdesc[i];
+ if (txd->tx_dmamap != NULL) {
+ bus_dmamap_destroy(sc->vte_cdata.vte_tx_tag,
+ txd->tx_dmamap);
+ txd->tx_dmamap = NULL;
+ }
+ }
+ bus_dma_tag_destroy(sc->vte_cdata.vte_tx_tag);
+ sc->vte_cdata.vte_tx_tag = NULL;
+ }
+ /* RX buffers */
+ if (sc->vte_cdata.vte_rx_tag != NULL) {
+ for (i = 0; i < VTE_RX_RING_CNT; i++) {
+ rxd = &sc->vte_cdata.vte_rxdesc[i];
+ if (rxd->rx_dmamap != NULL) {
+ bus_dmamap_destroy(sc->vte_cdata.vte_rx_tag,
+ rxd->rx_dmamap);
+ rxd->rx_dmamap = NULL;
+ }
+ }
+ if (sc->vte_cdata.vte_rx_sparemap != NULL) {
+ bus_dmamap_destroy(sc->vte_cdata.vte_rx_tag,
+ sc->vte_cdata.vte_rx_sparemap);
+ sc->vte_cdata.vte_rx_sparemap = NULL;
+ }
+ bus_dma_tag_destroy(sc->vte_cdata.vte_rx_tag);
+ sc->vte_cdata.vte_rx_tag = NULL;
+ }
+ /* TX descriptor ring. */
+ if (sc->vte_cdata.vte_tx_ring_tag != NULL) {
+ if (sc->vte_cdata.vte_tx_ring_map != NULL)
+ bus_dmamap_unload(sc->vte_cdata.vte_tx_ring_tag,
+ sc->vte_cdata.vte_tx_ring_map);
+ if (sc->vte_cdata.vte_tx_ring_map != NULL &&
+ sc->vte_cdata.vte_tx_ring != NULL)
+ bus_dmamem_free(sc->vte_cdata.vte_tx_ring_tag,
+ sc->vte_cdata.vte_tx_ring,
+ sc->vte_cdata.vte_tx_ring_map);
+ sc->vte_cdata.vte_tx_ring = NULL;
+ sc->vte_cdata.vte_tx_ring_map = NULL;
+ bus_dma_tag_destroy(sc->vte_cdata.vte_tx_ring_tag);
+ sc->vte_cdata.vte_tx_ring_tag = NULL;
+ }
+ /* RX ring. */
+ if (sc->vte_cdata.vte_rx_ring_tag != NULL) {
+ if (sc->vte_cdata.vte_rx_ring_map != NULL)
+ bus_dmamap_unload(sc->vte_cdata.vte_rx_ring_tag,
+ sc->vte_cdata.vte_rx_ring_map);
+ if (sc->vte_cdata.vte_rx_ring_map != NULL &&
+ sc->vte_cdata.vte_rx_ring != NULL)
+ bus_dmamem_free(sc->vte_cdata.vte_rx_ring_tag,
+ sc->vte_cdata.vte_rx_ring,
+ sc->vte_cdata.vte_rx_ring_map);
+ sc->vte_cdata.vte_rx_ring = NULL;
+ sc->vte_cdata.vte_rx_ring_map = NULL;
+ bus_dma_tag_destroy(sc->vte_cdata.vte_rx_ring_tag);
+ sc->vte_cdata.vte_rx_ring_tag = NULL;
+ }
+ if (sc->vte_cdata.vte_buffer_tag != NULL) {
+ bus_dma_tag_destroy(sc->vte_cdata.vte_buffer_tag);
+ sc->vte_cdata.vte_buffer_tag = NULL;
+ }
+ if (sc->vte_cdata.vte_parent_tag != NULL) {
+ bus_dma_tag_destroy(sc->vte_cdata.vte_parent_tag);
+ sc->vte_cdata.vte_parent_tag = NULL;
+ }
+}
+
+static int
+vte_shutdown(device_t dev)
+{
+
+ return (vte_suspend(dev));
+}
+
+static int
+vte_suspend(device_t dev)
+{
+ struct vte_softc *sc;
+ struct ifnet *ifp;
+
+ sc = device_get_softc(dev);
+
+ VTE_LOCK(sc);
+ ifp = sc->vte_ifp;
+ if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
+ vte_stop(sc);
+ VTE_UNLOCK(sc);
+
+ return (0);
+}
+
+static int
+vte_resume(device_t dev)
+{
+ struct vte_softc *sc;
+ struct ifnet *ifp;
+
+ sc = device_get_softc(dev);
+
+ VTE_LOCK(sc);
+ ifp = sc->vte_ifp;
+ if ((ifp->if_flags & IFF_UP) != 0) {
+ ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
+ vte_init_locked(sc);
+ }
+ VTE_UNLOCK(sc);
+
+ return (0);
+}
+
+static struct vte_txdesc *
+vte_encap(struct vte_softc *sc, struct mbuf **m_head)
+{
+ struct vte_txdesc *txd;
+ struct mbuf *m, *n;
+ bus_dma_segment_t txsegs[1];
+ int copy, error, nsegs, padlen;
+
+ VTE_LOCK_ASSERT(sc);
+
+ M_ASSERTPKTHDR((*m_head));
+
+ txd = &sc->vte_cdata.vte_txdesc[sc->vte_cdata.vte_tx_prod];
+ m = *m_head;
+ /*
+ * Controller doesn't auto-pad, so we have to make sure pad
+ * short frames out to the minimum frame length.
+ */
+ if (m->m_pkthdr.len < VTE_MIN_FRAMELEN)
+ padlen = VTE_MIN_FRAMELEN - m->m_pkthdr.len;
+ else
+ padlen = 0;
+
+ /*
+ * Controller does not support multi-fragmented TX buffers.
+ * Controller spends most of its TX processing time in
+ * de-fragmenting TX buffers. Either faster CPU or more
+ * advanced controller DMA engine is required to speed up
+ * TX path processing.
+ * To mitigate the de-fragmenting issue, perform deep copy
+ * from fragmented mbuf chains to a pre-allocated mbuf
+ * cluster with extra cost of kernel memory. For frames
+ * that is composed of single TX buffer, the deep copy is
+ * bypassed.
+ */
+ if (tx_deep_copy != 0) {
+ copy = 0;
+ if (m->m_next != NULL)
+ copy++;
+ if (padlen > 0 && (M_WRITABLE(m) == 0 ||
+ padlen > M_TRAILINGSPACE(m)))
+ copy++;
+ if (copy != 0) {
+ /* Avoid expensive m_defrag(9) and do deep copy. */
+ n = sc->vte_cdata.vte_txmbufs[sc->vte_cdata.vte_tx_prod];
+ m_copydata(m, 0, m->m_pkthdr.len, mtod(n, char *));
+ n->m_pkthdr.len = m->m_pkthdr.len;
+ n->m_len = m->m_pkthdr.len;
+ m = n;
+ txd->tx_flags |= VTE_TXMBUF;
+ }
+
+ if (padlen > 0) {
+ /* Zero out the bytes in the pad area. */
+ bzero(mtod(m, char *) + m->m_pkthdr.len, padlen);
+ m->m_pkthdr.len += padlen;
+ m->m_len = m->m_pkthdr.len;
+ }
+ } else {
+ if (M_WRITABLE(m) == 0) {
+ if (m->m_next != NULL || padlen > 0) {
+ /* Get a writable copy. */
+ m = m_dup(*m_head, M_DONTWAIT);
+ /* Release original mbuf chains. */
+ m_freem(*m_head);
+ if (m == NULL) {
+ *m_head = NULL;
+ return (NULL);
+ }
+ *m_head = m;
+ }
+ }
+
+ if (m->m_next != NULL) {
+ m = m_defrag(*m_head, M_DONTWAIT);
+ if (m == NULL) {
+ m_freem(*m_head);
+ *m_head = NULL;
+ return (NULL);
+ }
+ *m_head = m;
+ }
+
+ if (padlen > 0) {
+ if (M_TRAILINGSPACE(m) < padlen) {
+ m = m_defrag(*m_head, M_DONTWAIT);
+ if (m == NULL) {
+ m_freem(*m_head);
+ *m_head = NULL;
+ return (NULL);
+ }
+ *m_head = m;
+ }
+ /* Zero out the bytes in the pad area. */
+ bzero(mtod(m, char *) + m->m_pkthdr.len, padlen);
+ m->m_pkthdr.len += padlen;
+ m->m_len = m->m_pkthdr.len;
+ }
+ }
+
+ error = bus_dmamap_load_mbuf_sg(sc->vte_cdata.vte_tx_tag,
+ txd->tx_dmamap, m, txsegs, &nsegs, 0);
+ if (error != 0) {
+ txd->tx_flags &= ~VTE_TXMBUF;
+ return (NULL);
+ }
+ KASSERT(nsegs == 1, ("%s: %d segments returned!", __func__, nsegs));
+ bus_dmamap_sync(sc->vte_cdata.vte_tx_tag, txd->tx_dmamap,
+ BUS_DMASYNC_PREWRITE);
+
+ txd->tx_desc->dtlen = htole16(VTE_TX_LEN(txsegs[0].ds_len));
+ txd->tx_desc->dtbp = htole32(txsegs[0].ds_addr);
+ sc->vte_cdata.vte_tx_cnt++;
+ /* Update producer index. */
+ VTE_DESC_INC(sc->vte_cdata.vte_tx_prod, VTE_TX_RING_CNT);
+
+ /* Finally hand over ownership to controller. */
+ txd->tx_desc->dtst = htole16(VTE_DTST_TX_OWN);
+ txd->tx_m = m;
+
+ return (txd);
+}
+
+static void
+vte_start(struct ifnet *ifp)
+{
+ struct vte_softc *sc;
+
+ sc = ifp->if_softc;
+ VTE_LOCK(sc);
+ vte_start_locked(sc);
+ VTE_UNLOCK(sc);
+}
+
+static void
+vte_start_locked(struct vte_softc *sc)
+{
+ struct ifnet *ifp;
+ struct vte_txdesc *txd;
+ struct mbuf *m_head;
+ int enq;
+
+ ifp = sc->vte_ifp;
+
+ if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) !=
+ IFF_DRV_RUNNING || (sc->vte_flags & VTE_FLAG_LINK) == 0)
+ return;
+
+ for (enq = 0; !IFQ_DRV_IS_EMPTY(&ifp->if_snd); ) {
+ /* Reserve one free TX descriptor. */
+ if (sc->vte_cdata.vte_tx_cnt >= VTE_TX_RING_CNT - 1) {
+ ifp->if_drv_flags |= IFF_DRV_OACTIVE;
+ break;
+ }
+ IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
+ if (m_head == NULL)
+ break;
+ /*
+ * Pack the data into the transmit ring. If we
+ * don't have room, set the OACTIVE flag and wait
+ * for the NIC to drain the ring.
+ */
+ if ((txd = vte_encap(sc, &m_head)) == NULL) {
+ if (m_head != NULL)
+ IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
+ break;
+ }
+
+ enq++;
+ /*
+ * If there's a BPF listener, bounce a copy of this frame
+ * to him.
+ */
+ ETHER_BPF_MTAP(ifp, m_head);
+ /* Free consumed TX frame. */
+ if ((txd->tx_flags & VTE_TXMBUF) != 0)
+ m_freem(m_head);
+ }
+
+ if (enq > 0) {
+ bus_dmamap_sync(sc->vte_cdata.vte_tx_ring_tag,
+ sc->vte_cdata.vte_tx_ring_map, BUS_DMASYNC_PREREAD |
+ BUS_DMASYNC_PREWRITE);
+ CSR_WRITE_2(sc, VTE_TX_POLL, TX_POLL_START);
+ sc->vte_watchdog_timer = VTE_TX_TIMEOUT;
+ }
+}
+
+static void
+vte_watchdog(struct vte_softc *sc)
+{
+ struct ifnet *ifp;
+
+ VTE_LOCK_ASSERT(sc);
+
+ if (sc->vte_watchdog_timer == 0 || --sc->vte_watchdog_timer)
+ return;
+
+ ifp = sc->vte_ifp;
+ if_printf(sc->vte_ifp, "watchdog timeout -- resetting\n");
+ ifp->if_oerrors++;
+ ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
+ vte_init_locked(sc);
+ if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
+ vte_start_locked(sc);
+}
+
+static int
+vte_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+{
+ struct vte_softc *sc;
+ struct ifreq *ifr;
+ struct mii_data *mii;
+ int error;
+
+ sc = ifp->if_softc;
+ ifr = (struct ifreq *)data;
+ error = 0;
+ switch (cmd) {
+ case SIOCSIFFLAGS:
+ VTE_LOCK(sc);
+ if ((ifp->if_flags & IFF_UP) != 0) {
+ if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0 &&
+ ((ifp->if_flags ^ sc->vte_if_flags) &
+ (IFF_PROMISC | IFF_ALLMULTI)) != 0)
+ vte_rxfilter(sc);
+ else
+ vte_init_locked(sc);
+ } else if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
+ vte_stop(sc);
+ sc->vte_if_flags = ifp->if_flags;
+ VTE_UNLOCK(sc);
+ break;
+ case SIOCADDMULTI:
+ case SIOCDELMULTI:
+ VTE_LOCK(sc);
+ if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
+ vte_rxfilter(sc);
+ VTE_UNLOCK(sc);
+ break;
+ case SIOCSIFMEDIA:
+ case SIOCGIFMEDIA:
+ mii = device_get_softc(sc->vte_miibus);
+ error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, cmd);
+ break;
+ default:
+ error = ether_ioctl(ifp, cmd, data);
+ break;
+ }
+
+ return (error);
+}
+
+static void
+vte_mac_config(struct vte_softc *sc)
+{
+ struct mii_data *mii;
+ uint16_t mcr;
+
+ VTE_LOCK_ASSERT(sc);
+
+ mii = device_get_softc(sc->vte_miibus);
+ mcr = CSR_READ_2(sc, VTE_MCR0);
+ mcr &= ~(MCR0_FC_ENB | MCR0_FULL_DUPLEX);
+ if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) {
+ mcr |= MCR0_FULL_DUPLEX;
+#ifdef notyet
+ if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_TXPAUSE) != 0)
+ mcr |= MCR0_FC_ENB;
+ /*
+ * The data sheet is not clear whether the controller
+ * honors received pause frames or not. The is no
+ * separate control bit for RX pause frame so just
+ * enable MCR0_FC_ENB bit.
+ */
+ if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_RXPAUSE) != 0)
+ mcr |= MCR0_FC_ENB;
+#endif
+ }
+ CSR_WRITE_2(sc, VTE_MCR0, mcr);
+}
+
+static void
+vte_stats_clear(struct vte_softc *sc)
+{
+
+ /* Reading counter registers clears its contents. */
+ CSR_READ_2(sc, VTE_CNT_RX_DONE);
+ CSR_READ_2(sc, VTE_CNT_MECNT0);
+ CSR_READ_2(sc, VTE_CNT_MECNT1);
+ CSR_READ_2(sc, VTE_CNT_MECNT2);
+ CSR_READ_2(sc, VTE_CNT_MECNT3);
+ CSR_READ_2(sc, VTE_CNT_TX_DONE);
+ CSR_READ_2(sc, VTE_CNT_MECNT4);
+ CSR_READ_2(sc, VTE_CNT_PAUSE);
+}
+
+static void
+vte_stats_update(struct vte_softc *sc)
+{
+ struct vte_hw_stats *stat;
+ struct ifnet *ifp;
+ uint16_t value;
+
+ VTE_LOCK_ASSERT(sc);
+
+ ifp = sc->vte_ifp;
+ stat = &sc->vte_stats;
+
+ CSR_READ_2(sc, VTE_MECISR);
+ /* RX stats. */
+ stat->rx_frames += CSR_READ_2(sc, VTE_CNT_RX_DONE);
+ value = CSR_READ_2(sc, VTE_CNT_MECNT0);
+ stat->rx_bcast_frames += (value >> 8);
+ stat->rx_mcast_frames += (value & 0xFF);
+ value = CSR_READ_2(sc, VTE_CNT_MECNT1);
+ stat->rx_runts += (value >> 8);
+ stat->rx_crcerrs += (value & 0xFF);
+ value = CSR_READ_2(sc, VTE_CNT_MECNT2);
+ stat->rx_long_frames += (value & 0xFF);
+ value = CSR_READ_2(sc, VTE_CNT_MECNT3);
+ stat->rx_fifo_full += (value >> 8);
+ stat->rx_desc_unavail += (value & 0xFF);
+
+ /* TX stats. */
+ stat->tx_frames += CSR_READ_2(sc, VTE_CNT_TX_DONE);
+ value = CSR_READ_2(sc, VTE_CNT_MECNT4);
+ stat->tx_underruns += (value >> 8);
+ stat->tx_late_colls += (value & 0xFF);
+
+ value = CSR_READ_2(sc, VTE_CNT_PAUSE);
+ stat->tx_pause_frames += (value >> 8);
+ stat->rx_pause_frames += (value & 0xFF);
+
+ /* Update ifp counters. */
+ ifp->if_opackets = stat->tx_frames;
+ ifp->if_collisions = stat->tx_late_colls;
+ ifp->if_oerrors = stat->tx_late_colls + stat->tx_underruns;
+ ifp->if_ipackets = stat->rx_frames;
+ ifp->if_ierrors = stat->rx_crcerrs + stat->rx_runts +
+ stat->rx_long_frames + stat->rx_fifo_full;
+}
+
+static void
+vte_intr(void *arg)
+{
+ struct vte_softc *sc;
+ struct ifnet *ifp;
+ uint16_t status;
+ int n;
+
+ sc = (struct vte_softc *)arg;
+ VTE_LOCK(sc);
+
+ ifp = sc->vte_ifp;
+ /* Reading VTE_MISR acknowledges interrupts. */
+ status = CSR_READ_2(sc, VTE_MISR);
+ if ((status & VTE_INTRS) == 0) {
+ /* Not ours. */
+ VTE_UNLOCK(sc);
+ return;
+ }
+
+ /* Disable interrupts. */
+ CSR_WRITE_2(sc, VTE_MIER, 0);
+ for (n = 8; (status & VTE_INTRS) != 0;) {
+ if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
+ break;
+ if ((status & (MISR_RX_DONE | MISR_RX_DESC_UNAVAIL |
+ MISR_RX_FIFO_FULL)) != 0)
+ vte_rxeof(sc);
+ if ((status & MISR_TX_DONE) != 0)
+ vte_txeof(sc);
+ if ((status & MISR_EVENT_CNT_OFLOW) != 0)
+ vte_stats_update(sc);
+ if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
+ vte_start_locked(sc);
+ if (--n > 0)
+ status = CSR_READ_2(sc, VTE_MISR);
+ else
+ break;
+ }
+
+ if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) {
+ /* Re-enable interrupts. */
+ CSR_WRITE_2(sc, VTE_MIER, VTE_INTRS);
+ }
+ VTE_UNLOCK(sc);
+}
+
+static void
+vte_txeof(struct vte_softc *sc)
+{
+ struct ifnet *ifp;
+ struct vte_txdesc *txd;
+ uint16_t status;
+ int cons, prog;
+
+ VTE_LOCK_ASSERT(sc);
+
+ ifp = sc->vte_ifp;
+
+ if (sc->vte_cdata.vte_tx_cnt == 0)
+ return;
+ bus_dmamap_sync(sc->vte_cdata.vte_tx_ring_tag,
+ sc->vte_cdata.vte_tx_ring_map, BUS_DMASYNC_POSTREAD |
+ BUS_DMASYNC_POSTWRITE);
+ cons = sc->vte_cdata.vte_tx_cons;
+ /*
+ * Go through our TX list and free mbufs for those
+ * frames which have been transmitted.
+ */
+ for (prog = 0; sc->vte_cdata.vte_tx_cnt > 0; prog++) {
+ txd = &sc->vte_cdata.vte_txdesc[cons];
+ status = le16toh(txd->tx_desc->dtst);
+ if ((status & VTE_DTST_TX_OWN) != 0)
+ break;
+ sc->vte_cdata.vte_tx_cnt--;
+ /* Reclaim transmitted mbufs. */
+ bus_dmamap_sync(sc->vte_cdata.vte_tx_tag, txd->tx_dmamap,
+ BUS_DMASYNC_POSTWRITE);
+ bus_dmamap_unload(sc->vte_cdata.vte_tx_tag, txd->tx_dmamap);
+ if ((txd->tx_flags & VTE_TXMBUF) == 0)
+ m_freem(txd->tx_m);
+ txd->tx_flags &= ~VTE_TXMBUF;
+ txd->tx_m = NULL;
+ prog++;
+ VTE_DESC_INC(cons, VTE_TX_RING_CNT);
+ }
+
+ if (prog > 0) {
+ ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+ sc->vte_cdata.vte_tx_cons = cons;
+ /*
+ * Unarm watchdog timer only when there is no pending
+ * frames in TX queue.
+ */
+ if (sc->vte_cdata.vte_tx_cnt == 0)
+ sc->vte_watchdog_timer = 0;
+ }
+}
+
+static int
+vte_newbuf(struct vte_softc *sc, struct vte_rxdesc *rxd)
+{
+ struct mbuf *m;
+ bus_dma_segment_t segs[1];
+ bus_dmamap_t map;
+ int nsegs;
+
+ m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
+ if (m == NULL)
+ return (ENOBUFS);
+ m->m_len = m->m_pkthdr.len = MCLBYTES;
+ m_adj(m, sizeof(uint32_t));
+
+ if (bus_dmamap_load_mbuf_sg(sc->vte_cdata.vte_rx_tag,
+ sc->vte_cdata.vte_rx_sparemap, m, segs, &nsegs, 0) != 0) {
+ m_freem(m);
+ return (ENOBUFS);
+ }
+ KASSERT(nsegs == 1, ("%s: %d segments returned!", __func__, nsegs));
+
+ if (rxd->rx_m != NULL) {
+ bus_dmamap_sync(sc->vte_cdata.vte_rx_tag, rxd->rx_dmamap,
+ BUS_DMASYNC_POSTREAD);
+ bus_dmamap_unload(sc->vte_cdata.vte_rx_tag, rxd->rx_dmamap);
+ }
+ map = rxd->rx_dmamap;
+ rxd->rx_dmamap = sc->vte_cdata.vte_rx_sparemap;
+ sc->vte_cdata.vte_rx_sparemap = map;
+ bus_dmamap_sync(sc->vte_cdata.vte_rx_tag, rxd->rx_dmamap,
+ BUS_DMASYNC_PREREAD);
+ rxd->rx_m = m;
+ rxd->rx_desc->drbp = htole32(segs[0].ds_addr);
+ rxd->rx_desc->drlen = htole16(VTE_RX_LEN(segs[0].ds_len));
+ rxd->rx_desc->drst = htole16(VTE_DRST_RX_OWN);
+
+ return (0);
+}
+
+/*
+ * It's not supposed to see this controller on strict-alignment
+ * architectures but make it work for completeness.
+ */
+#ifndef __NO_STRICT_ALIGNMENT
+static struct mbuf *
+vte_fixup_rx(struct ifnet *ifp, struct mbuf *m)
+{
+ uint16_t *src, *dst;
+ int i;
+
+ src = mtod(m, uint16_t *);
+ dst = src - 1;
+
+ for (i = 0; i < (m->m_len / sizeof(uint16_t) + 1); i++)
+ *dst++ = *src++;
+ m->m_data -= ETHER_ALIGN;
+ return (m);
+}
+#endif
+
+static void
+vte_rxeof(struct vte_softc *sc)
+{
+ struct ifnet *ifp;
+ struct vte_rxdesc *rxd;
+ struct mbuf *m;
+ uint16_t status, total_len;
+ int cons, prog;
+
+ bus_dmamap_sync(sc->vte_cdata.vte_rx_ring_tag,
+ sc->vte_cdata.vte_rx_ring_map, BUS_DMASYNC_POSTREAD |
+ BUS_DMASYNC_POSTWRITE);
+ cons = sc->vte_cdata.vte_rx_cons;
+ ifp = sc->vte_ifp;
+ for (prog = 0; (ifp->if_drv_flags & IFF_DRV_RUNNING) != 0; prog++,
+ VTE_DESC_INC(cons, VTE_RX_RING_CNT)) {
+ rxd = &sc->vte_cdata.vte_rxdesc[cons];
+ status = le16toh(rxd->rx_desc->drst);
+ if ((status & VTE_DRST_RX_OWN) != 0)
+ break;
+ total_len = VTE_RX_LEN(le16toh(rxd->rx_desc->drlen));
+ m = rxd->rx_m;
+ if ((status & VTE_DRST_RX_OK) == 0) {
+ /* Discard errored frame. */
+ rxd->rx_desc->drlen =
+ htole16(MCLBYTES - sizeof(uint32_t));
+ rxd->rx_desc->drst = htole16(VTE_DRST_RX_OWN);
+ continue;
+ }
+ if (vte_newbuf(sc, rxd) != 0) {
+ ifp->if_iqdrops++;
+ rxd->rx_desc->drlen =
+ htole16(MCLBYTES - sizeof(uint32_t));
+ rxd->rx_desc->drst = htole16(VTE_DRST_RX_OWN);
+ continue;
+ }
+
+ /*
+ * It seems there is no way to strip FCS bytes.
+ */
+ m->m_pkthdr.len = m->m_len = total_len - ETHER_CRC_LEN;
+ m->m_pkthdr.rcvif = ifp;
+#ifndef __NO_STRICT_ALIGNMENT
+ vte_fixup_rx(ifp, m);
+#endif
+ VTE_UNLOCK(sc);
+ (*ifp->if_input)(ifp, m);
+ VTE_LOCK(sc);
+ }
+
+ if (prog > 0) {
+ /* Update the consumer index. */
+ sc->vte_cdata.vte_rx_cons = cons;
+ /*
+ * Sync updated RX descriptors such that controller see
+ * modified RX buffer addresses.
+ */
+ bus_dmamap_sync(sc->vte_cdata.vte_rx_ring_tag,
+ sc->vte_cdata.vte_rx_ring_map,
+ BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
+#ifdef notyet
+ /*
+ * Update residue counter. Controller does not
+ * keep track of number of available RX descriptors
+ * such that driver should have to update VTE_MRDCR
+ * to make controller know how many free RX
+ * descriptors were added to controller. This is
+ * a similar mechanism used in VIA velocity
+ * controllers and it indicates controller just
+ * polls OWN bit of current RX descriptor pointer.
+ * A couple of severe issues were seen on sample
+ * board where the controller continuously emits TX
+ * pause frames once RX pause threshold crossed.
+ * Once triggered it never recovered form that
+ * state, I couldn't find a way to make it back to
+ * work at least. This issue effectively
+ * disconnected the system from network. Also, the
+ * controller used 00:00:00:00:00:00 as source
+ * station address of TX pause frame. Probably this
+ * is one of reason why vendor recommends not to
+ * enable flow control on R6040 controller.
+ */
+ CSR_WRITE_2(sc, VTE_MRDCR, prog |
+ (((VTE_RX_RING_CNT * 2) / 10) <<
+ VTE_MRDCR_RX_PAUSE_THRESH_SHIFT));
+#endif
+ }
+}
+
+static void
+vte_tick(void *arg)
+{
+ struct vte_softc *sc;
+ struct mii_data *mii;
+
+ sc = (struct vte_softc *)arg;
+
+ VTE_LOCK_ASSERT(sc);
+
+ mii = device_get_softc(sc->vte_miibus);
+ mii_tick(mii);
+ vte_stats_update(sc);
+ vte_txeof(sc);
+ vte_watchdog(sc);
+ callout_reset(&sc->vte_tick_ch, hz, vte_tick, sc);
+}
+
+static void
+vte_reset(struct vte_softc *sc)
+{
+ uint16_t mcr;
+ int i;
+
+ mcr = CSR_READ_2(sc, VTE_MCR1);
+ CSR_WRITE_2(sc, VTE_MCR1, mcr | MCR1_MAC_RESET);
+ for (i = VTE_RESET_TIMEOUT; i > 0; i--) {
+ DELAY(10);
+ if ((CSR_READ_2(sc, VTE_MCR1) & MCR1_MAC_RESET) == 0)
+ break;
+ }
+ if (i == 0)
+ device_printf(sc->vte_dev, "reset timeout(0x%04x)!\n", mcr);
+ /*
+ * Follow the guide of vendor recommended way to reset MAC.
+ * Vendor confirms relying on MCR1_MAC_RESET of VTE_MCR1 is
+ * not reliable so manually reset internal state machine.
+ */
+ CSR_WRITE_2(sc, VTE_MACSM, 0x0002);
+ CSR_WRITE_2(sc, VTE_MACSM, 0);
+ DELAY(5000);
+}
+
+static void
+vte_init(void *xsc)
+{
+ struct vte_softc *sc;
+
+ sc = (struct vte_softc *)xsc;
+ VTE_LOCK(sc);
+ vte_init_locked(sc);
+ VTE_UNLOCK(sc);
+}
+
+static void
+vte_init_locked(struct vte_softc *sc)
+{
+ struct ifnet *ifp;
+ struct mii_data *mii;
+ bus_addr_t paddr;
+ uint8_t *eaddr;
+
+ VTE_LOCK_ASSERT(sc);
+
+ ifp = sc->vte_ifp;
+ mii = device_get_softc(sc->vte_miibus);
+
+ if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
+ return;
+ /*
+ * Cancel any pending I/O.
+ */
+ vte_stop(sc);
+ /*
+ * Reset the chip to a known state.
+ */
+ vte_reset(sc);
+
+ /* Initialize RX descriptors. */
+ if (vte_init_rx_ring(sc) != 0) {
+ device_printf(sc->vte_dev, "no memory for RX buffers.\n");
+ vte_stop(sc);
+ return;
+ }
+ if (vte_init_tx_ring(sc) != 0) {
+ device_printf(sc->vte_dev, "no memory for TX buffers.\n");
+ vte_stop(sc);
+ return;
+ }
+
+ /*
+ * Reprogram the station address. Controller supports up
+ * to 4 different station addresses so driver programs the
+ * first station address as its own ethernet address and
+ * configure the remaining three addresses as perfect
+ * multicast addresses.
+ */
+ eaddr = IF_LLADDR(sc->vte_ifp);
+ CSR_WRITE_2(sc, VTE_MID0L, eaddr[1] << 8 | eaddr[0]);
+ CSR_WRITE_2(sc, VTE_MID0M, eaddr[3] << 8 | eaddr[2]);
+ CSR_WRITE_2(sc, VTE_MID0H, eaddr[5] << 8 | eaddr[4]);
+
+ /* Set TX descriptor base addresses. */
+ paddr = sc->vte_cdata.vte_tx_ring_paddr;
+ CSR_WRITE_2(sc, VTE_MTDSA1, paddr >> 16);
+ CSR_WRITE_2(sc, VTE_MTDSA0, paddr & 0xFFFF);
+ /* Set RX descriptor base addresses. */
+ paddr = sc->vte_cdata.vte_rx_ring_paddr;
+ CSR_WRITE_2(sc, VTE_MRDSA1, paddr >> 16);
+ CSR_WRITE_2(sc, VTE_MRDSA0, paddr & 0xFFFF);
+ /*
+ * Initialize RX descriptor residue counter and set RX
+ * pause threshold to 20% of available RX descriptors.
+ * See comments on vte_rxeof() for details on flow control
+ * issues.
+ */
+ CSR_WRITE_2(sc, VTE_MRDCR, (VTE_RX_RING_CNT & VTE_MRDCR_RESIDUE_MASK) |
+ (((VTE_RX_RING_CNT * 2) / 10) << VTE_MRDCR_RX_PAUSE_THRESH_SHIFT));
+
+ /*
+ * Always use maximum frame size that controller can
+ * support. Otherwise received frames that has longer
+ * frame length than vte(4) MTU would be silently dropped
+ * in controller. This would break path-MTU discovery as
+ * sender wouldn't get any responses from receiver. The
+ * RX buffer size should be multiple of 4.
+ * Note, jumbo frames are silently ignored by controller
+ * and even MAC counters do not detect them.
+ */
+ CSR_WRITE_2(sc, VTE_MRBSR, VTE_RX_BUF_SIZE_MAX);
+
+ /* Configure FIFO. */
+ CSR_WRITE_2(sc, VTE_MBCR, MBCR_FIFO_XFER_LENGTH_16 |
+ MBCR_TX_FIFO_THRESH_64 | MBCR_RX_FIFO_THRESH_16 |
+ MBCR_SDRAM_BUS_REQ_TIMER_DEFAULT);
+
+ /*
+ * Configure TX/RX MACs. Actual resolved duplex and flow
+ * control configuration is done after detecting a valid
+ * link. Note, we don't generate early interrupt here
+ * as well since FreeBSD does not have interrupt latency
+ * problems like Windows.
+ */
+ CSR_WRITE_2(sc, VTE_MCR0, MCR0_ACCPT_LONG_PKT);
+ /*
+ * We manually keep track of PHY status changes to
+ * configure resolved duplex and flow control since only
+ * duplex configuration can be automatically reflected to
+ * MCR0.
+ */
+ CSR_WRITE_2(sc, VTE_MCR1, MCR1_PKT_LENGTH_1537 |
+ MCR1_EXCESS_COL_RETRY_16);
+
+ /* Initialize RX filter. */
+ vte_rxfilter(sc);
+
+ /* Disable TX/RX interrupt moderation control. */
+ CSR_WRITE_2(sc, VTE_MRICR, 0);
+ CSR_WRITE_2(sc, VTE_MTICR, 0);
+
+ /* Enable MAC event counter interrupts. */
+ CSR_WRITE_2(sc, VTE_MECIER, VTE_MECIER_INTRS);
+ /* Clear MAC statistics. */
+ vte_stats_clear(sc);
+
+ /* Acknowledge all pending interrupts and clear it. */
+ CSR_WRITE_2(sc, VTE_MIER, VTE_INTRS);
+ CSR_WRITE_2(sc, VTE_MISR, 0);
+
+ sc->vte_flags &= ~VTE_FLAG_LINK;
+ /* Switch to the current media. */
+ vte_mediachange_locked(ifp);
+
+ callout_reset(&sc->vte_tick_ch, hz, vte_tick, sc);
+
+ ifp->if_drv_flags |= IFF_DRV_RUNNING;
+ ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+}
+
+static void
+vte_stop(struct vte_softc *sc)
+{
+ struct ifnet *ifp;
+ struct vte_txdesc *txd;
+ struct vte_rxdesc *rxd;
+ int i;
+
+ VTE_LOCK_ASSERT(sc);
+ /*
+ * Mark the interface down and cancel the watchdog timer.
+ */
+ ifp = sc->vte_ifp;
+ ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
+ sc->vte_flags &= ~VTE_FLAG_LINK;
+ callout_stop(&sc->vte_tick_ch);
+ sc->vte_watchdog_timer = 0;
+ vte_stats_update(sc);
+ /* Disable interrupts. */
+ CSR_WRITE_2(sc, VTE_MIER, 0);
+ CSR_WRITE_2(sc, VTE_MECIER, 0);
+ /* Stop RX/TX MACs. */
+ vte_stop_mac(sc);
+ /* Clear interrupts. */
+ CSR_READ_2(sc, VTE_MISR);
+ /*
+ * Free TX/RX mbufs still in the queues.
+ */
+ for (i = 0; i < VTE_RX_RING_CNT; i++) {
+ rxd = &sc->vte_cdata.vte_rxdesc[i];
+ if (rxd->rx_m != NULL) {
+ bus_dmamap_sync(sc->vte_cdata.vte_rx_tag,
+ rxd->rx_dmamap, BUS_DMASYNC_POSTREAD);
+ bus_dmamap_unload(sc->vte_cdata.vte_rx_tag,
+ rxd->rx_dmamap);
+ m_freem(rxd->rx_m);
+ rxd->rx_m = NULL;
+ }
+ }
+ for (i = 0; i < VTE_TX_RING_CNT; i++) {
+ txd = &sc->vte_cdata.vte_txdesc[i];
+ if (txd->tx_m != NULL) {
+ bus_dmamap_sync(sc->vte_cdata.vte_tx_tag,
+ txd->tx_dmamap, BUS_DMASYNC_POSTWRITE);
+ bus_dmamap_unload(sc->vte_cdata.vte_tx_tag,
+ txd->tx_dmamap);
+ if ((txd->tx_flags & VTE_TXMBUF) == 0)
+ m_freem(txd->tx_m);
+ txd->tx_m = NULL;
+ txd->tx_flags &= ~VTE_TXMBUF;
+ }
+ }
+ /* Free TX mbuf pools used for deep copy. */
+ for (i = 0; i < VTE_TX_RING_CNT; i++) {
+ if (sc->vte_cdata.vte_txmbufs[i] != NULL) {
+ m_freem(sc->vte_cdata.vte_txmbufs[i]);
+ sc->vte_cdata.vte_txmbufs[i] = NULL;
+ }
+ }
+}
+
+static void
+vte_start_mac(struct vte_softc *sc)
+{
+ uint16_t mcr;
+ int i;
+
+ VTE_LOCK_ASSERT(sc);
+
+ /* Enable RX/TX MACs. */
+ mcr = CSR_READ_2(sc, VTE_MCR0);
+ if ((mcr & (MCR0_RX_ENB | MCR0_TX_ENB)) !=
+ (MCR0_RX_ENB | MCR0_TX_ENB)) {
+ mcr |= MCR0_RX_ENB | MCR0_TX_ENB;
+ CSR_WRITE_2(sc, VTE_MCR0, mcr);
+ for (i = VTE_TIMEOUT; i > 0; i--) {
+ mcr = CSR_READ_2(sc, VTE_MCR0);
+ if ((mcr & (MCR0_RX_ENB | MCR0_TX_ENB)) ==
+ (MCR0_RX_ENB | MCR0_TX_ENB))
+ break;
+ DELAY(10);
+ }
+ if (i == 0)
+ device_printf(sc->vte_dev,
+ "could not enable RX/TX MAC(0x%04x)!\n", mcr);
+ }
+}
+
+static void
+vte_stop_mac(struct vte_softc *sc)
+{
+ uint16_t mcr;
+ int i;
+
+ VTE_LOCK_ASSERT(sc);
+
+ /* Disable RX/TX MACs. */
+ mcr = CSR_READ_2(sc, VTE_MCR0);
+ if ((mcr & (MCR0_RX_ENB | MCR0_TX_ENB)) != 0) {
+ mcr &= ~(MCR0_RX_ENB | MCR0_TX_ENB);
+ CSR_WRITE_2(sc, VTE_MCR0, mcr);
+ for (i = VTE_TIMEOUT; i > 0; i--) {
+ mcr = CSR_READ_2(sc, VTE_MCR0);
+ if ((mcr & (MCR0_RX_ENB | MCR0_TX_ENB)) == 0)
+ break;
+ DELAY(10);
+ }
+ if (i == 0)
+ device_printf(sc->vte_dev,
+ "could not disable RX/TX MAC(0x%04x)!\n", mcr);
+ }
+}
+
+static int
+vte_init_tx_ring(struct vte_softc *sc)
+{
+ struct vte_tx_desc *desc;
+ struct vte_txdesc *txd;
+ bus_addr_t addr;
+ int i;
+
+ VTE_LOCK_ASSERT(sc);
+
+ sc->vte_cdata.vte_tx_prod = 0;
+ sc->vte_cdata.vte_tx_cons = 0;
+ sc->vte_cdata.vte_tx_cnt = 0;
+
+ /* Pre-allocate TX mbufs for deep copy. */
+ if (tx_deep_copy != 0) {
+ for (i = 0; i < VTE_TX_RING_CNT; i++) {
+ sc->vte_cdata.vte_txmbufs[i] = m_getcl(M_DONTWAIT,
+ MT_DATA, M_PKTHDR);
+ if (sc->vte_cdata.vte_txmbufs[i] == NULL)
+ return (ENOBUFS);
+ sc->vte_cdata.vte_txmbufs[i]->m_pkthdr.len = MCLBYTES;
+ sc->vte_cdata.vte_txmbufs[i]->m_len = MCLBYTES;
+ }
+ }
+ desc = sc->vte_cdata.vte_tx_ring;
+ bzero(desc, VTE_TX_RING_SZ);
+ for (i = 0; i < VTE_TX_RING_CNT; i++) {
+ txd = &sc->vte_cdata.vte_txdesc[i];
+ txd->tx_m = NULL;
+ if (i != VTE_TX_RING_CNT - 1)
+ addr = sc->vte_cdata.vte_tx_ring_paddr +
+ sizeof(struct vte_tx_desc) * (i + 1);
+ else
+ addr = sc->vte_cdata.vte_tx_ring_paddr +
+ sizeof(struct vte_tx_desc) * 0;
+ desc = &sc->vte_cdata.vte_tx_ring[i];
+ desc->dtnp = htole32(addr);
+ txd->tx_desc = desc;
+ }
+
+ bus_dmamap_sync(sc->vte_cdata.vte_tx_ring_tag,
+ sc->vte_cdata.vte_tx_ring_map, BUS_DMASYNC_PREREAD |
+ BUS_DMASYNC_PREWRITE);
+ return (0);
+}
+
+static int
+vte_init_rx_ring(struct vte_softc *sc)
+{
+ struct vte_rx_desc *desc;
+ struct vte_rxdesc *rxd;
+ bus_addr_t addr;
+ int i;
+
+ VTE_LOCK_ASSERT(sc);
+
+ sc->vte_cdata.vte_rx_cons = 0;
+ desc = sc->vte_cdata.vte_rx_ring;
+ bzero(desc, VTE_RX_RING_SZ);
+ for (i = 0; i < VTE_RX_RING_CNT; i++) {
+ rxd = &sc->vte_cdata.vte_rxdesc[i];
+ rxd->rx_m = NULL;
+ if (i != VTE_RX_RING_CNT - 1)
+ addr = sc->vte_cdata.vte_rx_ring_paddr +
+ sizeof(struct vte_rx_desc) * (i + 1);
+ else
+ addr = sc->vte_cdata.vte_rx_ring_paddr +
+ sizeof(struct vte_rx_desc) * 0;
+ desc = &sc->vte_cdata.vte_rx_ring[i];
+ desc->drnp = htole32(addr);
+ rxd->rx_desc = desc;
+ if (vte_newbuf(sc, rxd) != 0)
+ return (ENOBUFS);
+ }
+
+ bus_dmamap_sync(sc->vte_cdata.vte_rx_ring_tag,
+ sc->vte_cdata.vte_rx_ring_map, BUS_DMASYNC_PREREAD |
+ BUS_DMASYNC_PREWRITE);
+
+ return (0);
+}
+
+static void
+vte_rxfilter(struct vte_softc *sc)
+{
+ struct ifnet *ifp;
+ struct ifmultiaddr *ifma;
+ uint8_t *eaddr;
+ uint32_t crc;
+ uint16_t rxfilt_perf[VTE_RXFILT_PERFECT_CNT][3];
+ uint16_t mchash[4], mcr;
+ int i, nperf;
+
+ VTE_LOCK_ASSERT(sc);
+
+ ifp = sc->vte_ifp;
+
+ bzero(mchash, sizeof(mchash));
+ for (i = 0; i < VTE_RXFILT_PERFECT_CNT; i++) {
+ rxfilt_perf[i][0] = 0xFFFF;
+ rxfilt_perf[i][1] = 0xFFFF;
+ rxfilt_perf[i][2] = 0xFFFF;
+ }
+
+ mcr = CSR_READ_2(sc, VTE_MCR0);
+ mcr &= ~(MCR0_PROMISC | MCR0_BROADCAST | MCR0_MULTICAST);
+ if ((ifp->if_flags & IFF_BROADCAST) != 0)
+ mcr |= MCR0_BROADCAST;
+ if ((ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI)) != 0) {
+ if ((ifp->if_flags & IFF_PROMISC) != 0)
+ mcr |= MCR0_PROMISC;
+ if ((ifp->if_flags & IFF_ALLMULTI) != 0)
+ mcr |= MCR0_MULTICAST;
+ mchash[0] = 0xFFFF;
+ mchash[1] = 0xFFFF;
+ mchash[2] = 0xFFFF;
+ mchash[3] = 0xFFFF;
+ goto chipit;
+ }
+
+ nperf = 0;
+ if_maddr_rlock(ifp);
+ TAILQ_FOREACH(ifma, &sc->vte_ifp->if_multiaddrs, ifma_link) {
+ if (ifma->ifma_addr->sa_family != AF_LINK)
+ continue;
+ /*
+ * Program the first 3 multicast groups into
+ * the perfect filter. For all others, use the
+ * hash table.
+ */
+ if (nperf < VTE_RXFILT_PERFECT_CNT) {
+ eaddr = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
+ rxfilt_perf[nperf][0] = eaddr[1] << 8 | eaddr[0];
+ rxfilt_perf[nperf][1] = eaddr[3] << 8 | eaddr[2];
+ rxfilt_perf[nperf][2] = eaddr[5] << 8 | eaddr[4];
+ nperf++;
+ continue;
+ }
+ crc = ether_crc32_be(LLADDR((struct sockaddr_dl *)
+ ifma->ifma_addr), ETHER_ADDR_LEN);
+ mchash[crc >> 30] |= 1 << ((crc >> 26) & 0x0F);
+ }
+ if_maddr_runlock(ifp);
+ if (mchash[0] != 0 || mchash[1] != 0 || mchash[2] != 0 ||
+ mchash[3] != 0)
+ mcr |= MCR0_MULTICAST;
+
+chipit:
+ /* Program multicast hash table. */
+ CSR_WRITE_2(sc, VTE_MAR0, mchash[0]);
+ CSR_WRITE_2(sc, VTE_MAR1, mchash[1]);
+ CSR_WRITE_2(sc, VTE_MAR2, mchash[2]);
+ CSR_WRITE_2(sc, VTE_MAR3, mchash[3]);
+ /* Program perfect filter table. */
+ for (i = 0; i < VTE_RXFILT_PERFECT_CNT; i++) {
+ CSR_WRITE_2(sc, VTE_RXFILTER_PEEFECT_BASE + 8 * i + 0,
+ rxfilt_perf[i][0]);
+ CSR_WRITE_2(sc, VTE_RXFILTER_PEEFECT_BASE + 8 * i + 2,
+ rxfilt_perf[i][1]);
+ CSR_WRITE_2(sc, VTE_RXFILTER_PEEFECT_BASE + 8 * i + 4,
+ rxfilt_perf[i][2]);
+ }
+ CSR_WRITE_2(sc, VTE_MCR0, mcr);
+ CSR_READ_2(sc, VTE_MCR0);
+}
+
+static int
+sysctl_int_range(SYSCTL_HANDLER_ARGS, int low, int high)
+{
+ int error, value;
+
+ if (arg1 == NULL)
+ return (EINVAL);
+ value = *(int *)arg1;
+ error = sysctl_handle_int(oidp, &value, 0, req);
+ if (error || req->newptr == NULL)
+ return (error);
+ if (value < low || value > high)
+ return (EINVAL);
+ *(int *)arg1 = value;
+
+ return (0);
+}
+
+static int
+sysctl_hw_vte_int_mod(SYSCTL_HANDLER_ARGS)
+{
+
+ return (sysctl_int_range(oidp, arg1, arg2, req,
+ VTE_IM_BUNDLE_MIN, VTE_IM_BUNDLE_MAX));
+}
Index: sys/dev/vte/if_vtereg.h
===================================================================
--- sys/dev/vte/if_vtereg.h (revision 0)
+++ sys/dev/vte/if_vtereg.h (working copy)
@@ -0,0 +1,346 @@
+/*-
+ * Copyright (c) 2010, Pyun YongHyeon <yongari@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: http://svn.freebsd.org/base/releng/8.2/sys/dev/vte/if_vtereg.h 216829 2010-12-31 00:21:41Z yongari $
+ */
+
+#ifndef _IF_VTEREG_H
+#define _IF_VTEREG_H
+
+/*
+ * RDC Semiconductor PCI vendor ID
+ */
+#define VENDORID_RDC 0x17F3
+
+/*
+ * Vortex86 RDC R6040 FastEthernet device ID
+ */
+#define DEVICEID_RDC_R6040 0x6040 /* PMX-1000 */
+
+/* MAC control register 0 */
+#define VTE_MCR0 0x00
+#define MCR0_ACCPT_ERR 0x0001
+#define MCR0_RX_ENB 0x0002
+#define MCR0_ACCPT_RUNT 0x0004
+#define MCR0_ACCPT_LONG_PKT 0x0008
+#define MCR0_ACCPT_DRIBBLE 0x0010
+#define MCR0_PROMISC 0x0020
+#define MCR0_BROADCAST 0x0040
+#define MCR0_RX_EARLY_INTR 0x0080
+#define MCR0_MULTICAST 0x0100
+#define MCR0_FC_ENB 0x0200
+#define MCR0_TX_ENB 0x1000
+#define MCR0_TX_EARLY_INTR 0x4000
+#define MCR0_FULL_DUPLEX 0x8000
+
+/* MAC control register 1 */
+#define VTE_MCR1 0x04
+#define MCR1_MAC_RESET 0x0001
+#define MCR1_MAC_LOOPBACK 0x0002
+#define MCR1_EXCESS_COL_RETRANS_DIS 0x0004
+#define MCR1_AUTO_CHG_DUPLEX 0x0008
+#define MCR1_PKT_LENGTH_1518 0x0010
+#define MCR1_PKT_LENGTH_1522 0x0020
+#define MCR1_PKT_LENGTH_1534 0x0030
+#define MCR1_PKT_LENGTH_1537 0x0000
+#define MCR1_EARLY_INTR_THRESH_1129 0x0000
+#define MCR1_EARLY_INTR_THRESH_1257 0x0040
+#define MCR1_EARLY_INTR_THRESH_1385 0x0080
+#define MCR1_EARLY_INTR_THRESH_1513 0x00C0
+#define MCR1_EXCESS_COL_RETRY_16 0x0000
+#define MCR1_EXCESS_COL_RETRY_32 0x0100
+#define MCR1_FC_ACTIVE 0x0200
+#define MCR1_RX_DESC_HASH_IDX 0x4000
+#define MCR1_RX_UNICAST_HASH 0x8000
+
+#define MCR1_PKT_LENGTH_MASK 0x0030
+#define MCR1_EARLY_INTR_THRESH_MASK 0x00C0
+
+/* MAC bus control register */
+#define VTE_MBCR 0x08
+#define MBCR_FIFO_XFER_LENGTH_4 0x0000
+#define MBCR_FIFO_XFER_LENGTH_8 0x0001
+#define MBCR_FIFO_XFER_LENGTH_16 0x0002
+#define MBCR_FIFO_XFER_LENGTH_32 0x0003
+#define MBCR_TX_FIFO_THRESH_16 0x0000
+#define MBCR_TX_FIFO_THRESH_32 0x0004
+#define MBCR_TX_FIFO_THRESH_64 0x0008
+#define MBCR_TX_FIFO_THRESH_96 0x000C
+#define MBCR_RX_FIFO_THRESH_8 0x0000
+#define MBCR_RX_FIFO_THRESH_16 0x0010
+#define MBCR_RX_FIFO_THRESH_32 0x0020
+#define MBCR_RX_FIFO_THRESH_64 0x0030
+#define MBCR_SDRAM_BUS_REQ_TIMER_MASK 0x1F00
+#define MBCR_SDRAM_BUS_REQ_TIMER_SHIFT 8
+#define MBCR_SDRAM_BUS_REQ_TIMER_DEFAULT 0x1F00
+
+/* MAC TX interrupt control register */
+#define VTE_MTICR 0x0C
+#define MTICR_TX_TIMER_MASK 0x001F
+#define MTICR_TX_BUNDLE_MASK 0x0F00
+#define VTE_IM_TX_TIMER_DEFAULT 0x7F
+#define VTE_IM_TX_BUNDLE_DEFAULT 15
+
+#define VTE_IM_TIMER_MIN 0
+#define VTE_IM_TIMER_MAX 82
+#define VTE_IM_TIMER_MASK 0x001F
+#define VTE_IM_TIMER_SHIFT 0
+#define VTE_IM_BUNDLE_MIN 1
+#define VTE_IM_BUNDLE_MAX 15
+#define VTE_IM_BUNDLE_SHIFT 8
+
+/* MAC RX interrupt control register */
+#define VTE_MRICR 0x10
+#define MRICR_RX_TIMER_MASK 0x001F
+#define MRICR_RX_BUNDLE_MASK 0x0F00
+#define VTE_IM_RX_TIMER_DEFAULT 0x7F
+#define VTE_IM_RX_BUNDLE_DEFAULT 15
+
+/* MAC TX poll command register */
+#define VTE_TX_POLL 0x14
+#define TX_POLL_START 0x0001
+
+/* MAC RX buffer size register */
+#define VTE_MRBSR 0x18
+#define VTE_MRBSR_SIZE_MASK 0x03FF
+
+/* MAC RX descriptor control register */
+#define VTE_MRDCR 0x1A
+#define VTE_MRDCR_RESIDUE_MASK 0x00FF
+#define VTE_MRDCR_RX_PAUSE_THRESH_MASK 0xFF00
+#define VTE_MRDCR_RX_PAUSE_THRESH_SHIFT 8
+
+/* MAC Last status register */
+#define VTE_MLSR 0x1C
+#define MLSR_MULTICAST 0x0001
+#define MLSR_BROADCAST 0x0002
+#define MLSR_CRC_ERR 0x0004
+#define MLSR_RUNT 0x0008
+#define MLSR_LONG_PKT 0x0010
+#define MLSR_TRUNC 0x0020
+#define MLSR_DRIBBLE 0x0040
+#define MLSR_PHY_ERR 0x0080
+#define MLSR_TX_FIFO_UNDERRUN 0x0200
+#define MLSR_RX_DESC_UNAVAIL 0x0400
+#define MLSR_TX_EXCESS_COL 0x2000
+#define MLSR_TX_LATE_COL 0x4000
+#define MLSR_RX_FIFO_OVERRUN 0x8000
+
+/* MAC MDIO control register */
+#define VTE_MMDIO 0x20
+#define MMDIO_REG_ADDR_MASK 0x001F
+#define MMDIO_PHY_ADDR_MASK 0x1F00
+#define MMDIO_READ 0x2000
+#define MMDIO_WRITE 0x4000
+#define MMDIO_REG_ADDR_SHIFT 0
+#define MMDIO_PHY_ADDR_SHIFT 8
+
+/* MAC MDIO read data register */
+#define VTE_MMRD 0x24
+#define MMRD_DATA_MASK 0xFFFF
+
+/* MAC MDIO write data register */
+#define VTE_MMWD 0x28
+#define MMWD_DATA_MASK 0xFFFF
+
+/* MAC TX descriptor start address 0 */
+#define VTE_MTDSA0 0x2C
+
+/* MAC TX descriptor start address 1 */
+#define VTE_MTDSA1 0x30
+
+/* MAC RX descriptor start address 0 */
+#define VTE_MRDSA0 0x34
+
+/* MAC RX descriptor start address 1 */
+#define VTE_MRDSA1 0x38
+
+/* MAC Interrupt status register */
+#define VTE_MISR 0x3C
+#define MISR_RX_DONE 0x0001
+#define MISR_RX_DESC_UNAVAIL 0x0002
+#define MISR_RX_FIFO_FULL 0x0004
+#define MISR_RX_EARLY_INTR 0x0008
+#define MISR_TX_DONE 0x0010
+#define MISR_TX_EARLY_INTR 0x0080
+#define MISR_EVENT_CNT_OFLOW 0x0100
+#define MISR_PHY_MEDIA_CHG 0x0200
+
+/* MAC Interrupt enable register */
+#define VTE_MIER 0x40
+
+#define VTE_INTRS \
+ (MISR_RX_DONE | MISR_RX_DESC_UNAVAIL | MISR_RX_FIFO_FULL | \
+ MISR_TX_DONE | MISR_EVENT_CNT_OFLOW)
+
+/* MAC Event counter interrupt status register */
+#define VTE_MECISR 0x44
+#define MECISR_EC_RX_DONE 0x0001
+#define MECISR_EC_MULTICAST 0x0002
+#define MECISR_EC_BROADCAST 0x0004
+#define MECISR_EC_CRC_ERR 0x0008
+#define MECISR_EC_RUNT 0x0010
+#define MESCIR_EC_LONG_PKT 0x0020
+#define MESCIR_EC_RX_DESC_UNAVAIL 0x0080
+#define MESCIR_EC_RX_FIFO_FULL 0x0100
+#define MESCIR_EC_TX_DONE 0x0200
+#define MESCIR_EC_LATE_COL 0x0400
+#define MESCIR_EC_TX_UNDERRUN 0x0800
+
+/* MAC Event counter interrupt enable register */
+#define VTE_MECIER 0x48
+#define VTE_MECIER_INTRS \
+ (MECISR_EC_RX_DONE | MECISR_EC_MULTICAST | MECISR_EC_BROADCAST | \
+ MECISR_EC_CRC_ERR | MECISR_EC_RUNT | MESCIR_EC_LONG_PKT | \
+ MESCIR_EC_RX_DESC_UNAVAIL | MESCIR_EC_RX_FIFO_FULL | \
+ MESCIR_EC_TX_DONE | MESCIR_EC_LATE_COL | MESCIR_EC_TX_UNDERRUN)
+
+#define VTE_CNT_RX_DONE 0x50
+
+#define VTE_CNT_MECNT0 0x52
+
+#define VTE_CNT_MECNT1 0x54
+
+#define VTE_CNT_MECNT2 0x56
+
+#define VTE_CNT_MECNT3 0x58
+
+#define VTE_CNT_TX_DONE 0x5A
+
+#define VTE_CNT_MECNT4 0x5C
+
+#define VTE_CNT_PAUSE 0x5E
+
+/* MAC Hash table register */
+#define VTE_MAR0 0x60
+#define VTE_MAR1 0x62
+#define VTE_MAR2 0x64
+#define VTE_MAR3 0x66
+
+/* MAC station address and multicast address register */
+#define VTE_MID0L 0x68
+#define VTE_MID0M 0x6A
+#define VTE_MID0H 0x6C
+#define VTE_MID1L 0x70
+#define VTE_MID1M 0x72
+#define VTE_MID1H 0x74
+#define VTE_MID2L 0x78
+#define VTE_MID2M 0x7A
+#define VTE_MID2H 0x7C
+#define VTE_MID3L 0x80
+#define VTE_MID3M 0x82
+#define VTE_MID3H 0x84
+
+#define VTE_RXFILTER_PEEFECT_BASE VTE_MID1L
+#define VTE_RXFILT_PERFECT_CNT 3
+
+/* MAC PHY status change configuration register */
+#define VTE_MPSCCR 0x88
+#define MPSCCR_TIMER_DIVIDER_MASK 0x0007
+#define MPSCCR_PHY_ADDR_MASK 0x1F00
+#define MPSCCR_PHY_STS_CHG_ENB 0x8000
+#define MPSCCR_PHY_ADDR_SHIFT 8
+
+/* MAC PHY status register2 */
+#define VTE_MPSR 0x8A
+#define MPSR_LINK_UP 0x0001
+#define MPSR_SPEED_100 0x0002
+#define MPSR_FULL_DUPLEX 0x0004
+
+/* MAC Status machine(undocumented). */
+#define VTE_MACSM 0xAC
+
+/* MDC Speed control register */
+#define VTE_MDCSC 0xB6
+#define MDCSC_DEFAULT 0x0030
+
+/* MAC Identifier and revision register */
+#define VTE_MACID_REV 0xBC
+#define VTE_MACID_REV_MASK 0x00FF
+#define VTE_MACID_MASK 0xFF00
+#define VTE_MACID_REV_SHIFT 0
+#define VTE_MACID_SHIFT 8
+
+/* MAC Identifier register */
+#define VTE_MACID 0xBE
+
+/*
+ * RX descriptor
+ * - Added one more uint16_t member to align it 4 on bytes boundary.
+ * This does not affect operation of controller since it includes
+ * next pointer address.
+ */
+struct vte_rx_desc {
+ uint16_t drst;
+ uint16_t drlen;
+ uint32_t drbp;
+ uint32_t drnp;
+ uint16_t hidx;
+ uint16_t rsvd2;
+ uint16_t rsvd3;
+ uint16_t __pad; /* Not actual descriptor member. */
+};
+
+#define VTE_DRST_MID_MASK 0x0003
+#define VTE_DRST_MID_HIT 0x0004
+#define VTE_DRST_MULTICAST_HIT 0x0008
+#define VTE_DRST_MULTICAST 0x0010
+#define VTE_DRST_BROADCAST 0x0020
+#define VTE_DRST_CRC_ERR 0x0040
+#define VTE_DRST_RUNT 0x0080
+#define VTE_DRST_LONG 0x0100
+#define VTE_DRST_TRUNC 0x0200
+#define VTE_DRST_DRIBBLE 0x0400
+#define VTE_DRST_PHY_ERR 0x0800
+#define VTE_DRST_RX_OK 0x4000
+#define VTE_DRST_RX_OWN 0x8000
+
+#define VTE_RX_LEN(x) ((x) & 0x7FF)
+
+#define VTE_RX_HIDX(x) ((x) & 0x3F)
+
+/*
+ * TX descriptor
+ * - Added one more uint32_t member to align it on 16 bytes boundary.
+ */
+struct vte_tx_desc {
+ uint16_t dtst;
+ uint16_t dtlen;
+ uint32_t dtbp;
+ uint32_t dtnp;
+ uint32_t __pad; /* Not actual descriptor member. */
+};
+
+#define VTE_DTST_EXCESS_COL 0x0010
+#define VTE_DTST_LATE_COL 0x0020
+#define VTE_DTST_UNDERRUN 0x0040
+#define VTE_DTST_NO_CRC 0x2000
+#define VTE_DTST_TX_OK 0x4000
+#define VTE_DTST_TX_OWN 0x8000
+
+#define VTE_TX_LEN(x) ((x) & 0x7FF)
+
+#endif /* _IF_VTEREG_H */
Index: sys/dev/vte/if_vtevar.h
===================================================================
--- sys/dev/vte/if_vtevar.h (revision 0)
+++ sys/dev/vte/if_vtevar.h (working copy)
@@ -0,0 +1,169 @@
+/*-
+ * Copyright (c) 2010, Pyun YongHyeon <yongari@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: http://svn.freebsd.org/base/releng/8.2/sys/dev/vte/if_vtevar.h 216829 2010-12-31 00:21:41Z yongari $
+ */
+
+#ifndef _IF_VTEVAR_H
+#define _IF_VTEVAR_H
+
+#define VTE_TX_RING_CNT 64
+#define VTE_TX_RING_ALIGN 16
+/*
+ * The TX/RX descriptor format has no limitation for number of
+ * descriptors in TX/RX ring. However, the maximum number of
+ * descriptors that could be set as RX descriptor ring residue
+ * counter is 255. This effectively limits number of RX
+ * descriptors available to be less than or equal to 255.
+ */
+#define VTE_RX_RING_CNT 128
+#define VTE_RX_RING_ALIGN 16
+#define VTE_RX_BUF_ALIGN 4
+
+#define VTE_DESC_INC(x, y) ((x) = ((x) + 1) % (y))
+
+#define VTE_TX_RING_SZ \
+ (sizeof(struct vte_tx_desc) * VTE_TX_RING_CNT)
+#define VTE_RX_RING_SZ \
+ (sizeof(struct vte_rx_desc) * VTE_RX_RING_CNT)
+
+#define VTE_RX_BUF_SIZE_MAX (MCLBYTES - sizeof(uint32_t))
+
+#define VTE_MIN_FRAMELEN (ETHER_MIN_LEN - ETHER_CRC_LEN)
+
+struct vte_rxdesc {
+ struct mbuf *rx_m;
+ bus_dmamap_t rx_dmamap;
+ struct vte_rx_desc *rx_desc;
+};
+
+struct vte_txdesc {
+ struct mbuf *tx_m;
+ bus_dmamap_t tx_dmamap;
+ struct vte_tx_desc *tx_desc;
+ int tx_flags;
+#define VTE_TXMBUF 0x0001
+};
+
+struct vte_chain_data {
+ bus_dma_tag_t vte_parent_tag;
+ bus_dma_tag_t vte_buffer_tag;
+ bus_dma_tag_t vte_tx_tag;
+ struct vte_txdesc vte_txdesc[VTE_TX_RING_CNT];
+ struct mbuf *vte_txmbufs[VTE_TX_RING_CNT];
+ bus_dma_tag_t vte_rx_tag;
+ struct vte_rxdesc vte_rxdesc[VTE_RX_RING_CNT];
+ bus_dma_tag_t vte_tx_ring_tag;
+ bus_dmamap_t vte_tx_ring_map;
+ bus_dma_tag_t vte_rx_ring_tag;
+ bus_dmamap_t vte_rx_ring_map;
+ bus_dma_tag_t vte_rr_ring_tag;
+ bus_dmamap_t vte_rr_ring_map;
+ bus_dmamap_t vte_rx_sparemap;
+ bus_dma_tag_t vte_cmb_tag;
+ bus_dmamap_t vte_cmb_map;
+ bus_dma_tag_t vte_smb_tag;
+ bus_dmamap_t vte_smb_map;
+ struct vte_tx_desc *vte_tx_ring;
+ bus_addr_t vte_tx_ring_paddr;
+ struct vte_rx_desc *vte_rx_ring;
+ bus_addr_t vte_rx_ring_paddr;
+
+ int vte_tx_prod;
+ int vte_tx_cons;
+ int vte_tx_cnt;
+ int vte_rx_cons;
+};
+
+struct vte_hw_stats {
+ /* RX stats. */
+ uint32_t rx_frames;
+ uint32_t rx_bcast_frames;
+ uint32_t rx_mcast_frames;
+ uint32_t rx_runts;
+ uint32_t rx_crcerrs;
+ uint32_t rx_long_frames;
+ uint32_t rx_fifo_full;
+ uint32_t rx_desc_unavail;
+ uint32_t rx_pause_frames;
+
+ /* TX stats. */
+ uint32_t tx_frames;
+ uint32_t tx_underruns;
+ uint32_t tx_late_colls;
+ uint32_t tx_pause_frames;
+};
+
+struct vte_ident {
+ uint16_t vendorid;
+ uint16_t deviceid;
+ const char *name;
+};
+
+/*
+ * Software state per device.
+ */
+struct vte_softc {
+ struct ifnet *vte_ifp;
+ device_t vte_dev;
+ device_t vte_miibus;
+ struct resource *vte_res;
+ int vte_res_id;
+ int vte_res_type;
+ struct resource *vte_irq;
+ void *vte_intrhand;
+ const struct vte_ident *vte_ident;
+ uint8_t vte_eaddr[ETHER_ADDR_LEN];
+ int vte_flags;
+#define VTE_FLAG_LINK 0x8000
+
+ struct callout vte_tick_ch;
+ struct vte_hw_stats vte_stats;
+ struct vte_chain_data vte_cdata;
+ int vte_if_flags;
+ int vte_watchdog_timer;
+ int vte_int_rx_mod;
+ int vte_int_tx_mod;
+
+ struct mtx vte_mtx;
+};
+
+/* Register access macros. */
+#define CSR_WRITE_2(_sc, reg, val) \
+ bus_write_2((_sc)->vte_res, (reg), (val))
+#define CSR_READ_2(_sc, reg) \
+ bus_read_2((_sc)->vte_res, (reg))
+
+#define VTE_LOCK(_sc) mtx_lock(&(_sc)->vte_mtx)
+#define VTE_UNLOCK(_sc) mtx_unlock(&(_sc)->vte_mtx)
+#define VTE_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->vte_mtx, MA_OWNED)
+
+#define VTE_TX_TIMEOUT 5
+#define VTE_RESET_TIMEOUT 100
+#define VTE_TIMEOUT 1000
+#define VTE_PHY_TIMEOUT 1000
+
+#endif /* _IF_VTEVAR_H */
Index: sys/i386/conf/GENERIC
===================================================================
--- sys/i386/conf/GENERIC (revision 226546)
+++ sys/i386/conf/GENERIC (working copy)
@@ -247,6 +247,7 @@ device tl # Texas Instruments ThunderLAN
device tx # SMC EtherPower II (83c170 ``EPIC'')
device vge # VIA VT612x gigabit Ethernet
device vr # VIA Rhine, Rhine II
+device vte # DM&P Vortex86 RDC R6040 Fast Ethernet
device wb # Winbond W89C840F
device xl # 3Com 3c90x (``Boomerang'', ``Cyclone'')
Index: sys/modules/Makefile
===================================================================
--- sys/modules/Makefile (revision 226546)
+++ sys/modules/Makefile (working copy)
@@ -301,6 +301,7 @@ SUBDIR= ${_3dfx} \
vkbd \
${_vpo} \
vr \
+ vte \
vx \
wb \
${_wi} \
Index: sys/modules/mii/Makefile
===================================================================
--- sys/modules/mii/Makefile (revision 226546)
+++ sys/modules/mii/Makefile (working copy)
@@ -8,8 +8,8 @@ SRCS+= ciphy.c device_if.h
SRCS+= e1000phy.c exphy.c gentbi.c icsphy.c inphy.c ip1000phy.c jmphy.c
SRCS+= lxtphy.c miibus_if.c miibus_if.h mii.c miidevs.h mii_physubr.c
SRCS+= mlphy.c nsgphy.c nsphy.c nsphyter.c pci_if.h pnaphy.c qsphy.c
-SRCS+= rgephy.c rlphy.c ruephy.c tdkphy.c tlphy.c truephy.c ukphy.c
-SRCS+= ukphy_subr.c
+SRCS+= rdcphy.c rgephy.c rlphy.c ruephy.c tdkphy.c tlphy.c truephy.c
+SRCS+= ukphy.c ukphy_subr.c
SRCS+= xmphy.c
EXPORT_SYMS= mii_attach \
Index: sys/modules/vte/Makefile
===================================================================
--- sys/modules/vte/Makefile (revision 0)
+++ sys/modules/vte/Makefile (working copy)
@@ -0,0 +1,8 @@
+# $FreeBSD: http://svn.freebsd.org/base/releng/8.2/sys/modules/vte/Makefile 216829 2010-12-31 00:21:41Z yongari $
+
+.PATH: ${.CURDIR}/../../dev/vte
+
+KMOD= if_vte
+SRCS= if_vte.c device_if.h bus_if.h pci_if.h miibus_if.h
+
+.include <bsd.kmod.mk>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.