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
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* PCIEHPC - The Standard PCI Express HotPlug Controller driver module. This
* driver can be used with PCI Express HotPlug controllers that
* are compatible with the PCI Express ver 1.0a specification.
*/
#include <sys/types.h>
#include <sys/note.h>
#include <sys/conf.h>
#include <sys/kmem.h>
#include <sys/debug.h>
#include <sys/vtrace.h>
#include <sys/modctl.h>
#include <sys/autoconf.h>
#include <sys/varargs.h>
#include <sys/ddi_impldefs.h>
#include <sys/pci.h>
#include <sys/time.h>
#include <sys/callb.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#if defined(__sparc)
#include <sys/pcie_impl.h>
#endif
#include <sys/hotplug/pci/pciehpc_impl.h>
/*
* Local data/functions
*/
/* mutex to protect pciehpc_head list */
static kmutex_t pciehpc_list_mutex;
/* pointer to linked list of pciehpc structures */
static pciehpc_t *pciehpc_head = NULL;
/* mutex to protect init/uninit controllers */
static kmutex_t pciehpc_init_mutex;
static int pciehpc_init_count = 0; /* count of pciehpc instances in use */
static pciehpc_t *pciehpc_create_soft_state(dev_info_t *dip);
static pciehpc_t *pciehpc_get_soft_state(dev_info_t *dip);
static void pciehpc_destroy_soft_state(dev_info_t *dip);
static char *pciehpc_led_state_text(hpc_led_state_t state);
static void pciehpc_attn_btn_handler(pciehpc_t *ctrl_p);
static void pciehpc_dev_info(pciehpc_t *ctrl_p);
static int pciehpc_pcie_dev(dev_info_t *dip, ddi_acc_handle_t handle);
#if defined(__sparc)
static void pciehpc_disable_errors(pciehpc_t *ctrl_p);
static void pciehpc_enable_errors(pciehpc_t *ctrl_p);
#endif
#ifdef DEBUG
int pciehpc_debug = 0;
static void pciehpc_dump_hpregs(pciehpc_t *ctrl_p);
#endif
/*
* Module linkage information for the kernel.
*/
extern struct mod_ops mod_miscops;
static struct modlmisc modlmisc =
{
&mod_miscops,
"PCIe hotplug driver v%I%",
};
static struct modlinkage modlinkage =
{
MODREV_1,
&modlmisc,
NULL
};
int
_init(void)
{
int error;
PCIEHPC_DEBUG3((CE_NOTE, "pciehpc: _init() called\n"));
mutex_init(&pciehpc_list_mutex, NULL, MUTEX_DRIVER, NULL);
mutex_init(&pciehpc_init_mutex, NULL, MUTEX_DRIVER, NULL);
if ((error = mod_install(&modlinkage)) != 0) {
mutex_destroy(&pciehpc_init_mutex);
mutex_destroy(&pciehpc_list_mutex);
}
return (error);
}
int
_fini(void)
{
int error;
PCIEHPC_DEBUG3((CE_NOTE, "pciehpc: _fini() called\n"));
mutex_enter(&pciehpc_init_mutex);
if (pciehpc_init_count != 0) {
mutex_exit(&pciehpc_init_mutex);
return (EBUSY);
}
error = mod_remove(&modlinkage);
if (error != 0) {
mutex_exit(&pciehpc_init_mutex);
return (error);
}
mutex_destroy(&pciehpc_list_mutex);
mutex_destroy(&pciehpc_init_mutex);
return (0);
}
int
_info(struct modinfo *modinfop)
{
PCIEHPC_DEBUG3((CE_NOTE, "pciehpc: _info() called\n"));
return (mod_info(&modlinkage, modinfop));
}
/*
* pciehpc_init()
*
* Initialize Hot Plug Controller if present. The arguments are:
* dip - Devinfo node pointer to the hot plug bus node
* regops - register ops to access HPC registers for non-standard
* HPC hw implementations (e.g: HPC in host PCI-E brdiges)
* This is NULL for standard HPC in PCIe bridges.
* Returns:
* DDI_SUCCESS for successful HPC initialization
* DDI_FAILURE for errors or if HPC hw not found
*/
int
pciehpc_init(dev_info_t *dip, pciehpc_regops_t *regops)
{
pciehpc_t *ctrl_p;
PCIEHPC_DEBUG3((CE_NOTE, "pciehpc_init() called (dip=%p)",
(void *)dip));
mutex_enter(&pciehpc_init_mutex);
/* Make sure that it is not already initialized */
if (pciehpc_get_soft_state(dip) != NULL) {
PCIEHPC_DEBUG((CE_WARN,
"%s%d: pciehpc instance already initialized!",
ddi_driver_name(dip), ddi_get_instance(dip)));
mutex_exit(&pciehpc_init_mutex);
return (DDI_SUCCESS);
}
/* allocate a new soft state structure */
ctrl_p = pciehpc_create_soft_state(dip);
/* get PCI device info */
pciehpc_dev_info(ctrl_p);
/* setup access handle for HPC regs */
if (regops != NULL) {
/* HPC access is non-standard; use the supplied reg ops */
ctrl_p->regops = *regops;
} else {
/* standard HPC in a PCIe bridge */
if (pciehpc_regs_setup(dip, 0, 0, &ctrl_p->regs_base,
&ctrl_p->cfghdl) != DDI_SUCCESS)
goto cleanup;
}
PCIEHPC_DISABLE_ERRORS(ctrl_p);
/*
* Set the platform specific hot plug mode.
*/
ctrl_p->hp_mode = PCIEHPC_NATIVE_HP_MODE; /* default is Native mode */
ctrl_p->ops.init_hpc_hw = pciehpc_hpc_init;
ctrl_p->ops.init_hpc_slotinfo = pciehpc_slotinfo_init;
ctrl_p->ops.disable_hpc_intr = pciehpc_disable_intr;
ctrl_p->ops.enable_hpc_intr = pciehpc_enable_intr;
ctrl_p->ops.uninit_hpc_hw = pciehpc_hpc_uninit;
ctrl_p->ops.uninit_hpc_slotinfo = pciehpc_slotinfo_uninit;
ctrl_p->ops.probe_hpc = pciehpc_probe_hpc;
#if defined(__i386) || defined(__amd64)
pciehpc_update_ops(ctrl_p);
#endif
if (regops == NULL) { /* it is a standard HPC in a PCIe bridge */
/* make sure we really have a hot plug controller */
if ((ctrl_p->ops.probe_hpc)(ctrl_p) != DDI_SUCCESS)
goto cleanup1;
}
/* initialize hot plug controller hw */
if ((ctrl_p->ops.init_hpc_hw)(ctrl_p) != DDI_SUCCESS)
goto cleanup1;
/* initialize slot information soft state structure */
if ((ctrl_p->ops.init_hpc_slotinfo)(ctrl_p) != DDI_SUCCESS)
goto cleanup2;
/* register the hot plug slot with HPS framework */
if (pciehpc_register_slot(ctrl_p) != DDI_SUCCESS)
goto cleanup3;
/* HPC initialization is complete now */
ctrl_p->soft_state |= PCIEHPC_SOFT_STATE_INITIALIZED;
ctrl_p->soft_state &= ~PCIEHPC_SOFT_STATE_UNINITIALIZED;
#ifdef DEBUG
/* For debug, dump the HPC registers */
if (pciehpc_debug > 2)
pciehpc_dump_hpregs(ctrl_p);
#endif
/* enable hot plug interrupts/event */
(void) (ctrl_p->ops.enable_hpc_intr)(ctrl_p);
pciehpc_init_count++;
mutex_exit(&pciehpc_init_mutex);
return (DDI_SUCCESS);
cleanup3:
(void) (ctrl_p->ops.uninit_hpc_slotinfo)(ctrl_p);
cleanup2:
(void) (ctrl_p->ops.uninit_hpc_hw)(ctrl_p);
cleanup1:
PCIEHPC_ENABLE_ERRORS(ctrl_p);
pciehpc_regs_teardown(&ctrl_p->cfghdl);
cleanup:
pciehpc_destroy_soft_state(dip);
mutex_exit(&pciehpc_init_mutex);
return (DDI_FAILURE);
}
/*
* Uninitialize HPC soft state structure and free up any resources
* used for the HPC instance.
*/
int
pciehpc_uninit(dev_info_t *dip)
{
pciehpc_t *ctrl_p;
PCIEHPC_DEBUG3((CE_NOTE, "pciehpc_uninit() called (dip=%p)\n",
(void *)dip));
mutex_enter(&pciehpc_init_mutex);
/* get the soft state structure for this dip */
if ((ctrl_p = pciehpc_get_soft_state(dip)) == NULL) {
mutex_exit(&pciehpc_init_mutex);
return (DDI_FAILURE);
}
/* disable interrupts */
(void) (ctrl_p->ops.disable_hpc_intr)(ctrl_p);
/* unregister the slot */
(void) pciehpc_unregister_slot(ctrl_p);
/* uninit any slot info data structures */
(void) (ctrl_p->ops.uninit_hpc_slotinfo)(ctrl_p);
/* uninitialize hpc, remove interrupt handler, etc. */
(void) (ctrl_p->ops.uninit_hpc_hw)(ctrl_p);
PCIEHPC_ENABLE_ERRORS(ctrl_p);
/* free up the HPC register mapping */
pciehpc_regs_teardown(&ctrl_p->cfghdl);
/* destroy the soft state structure */
pciehpc_destroy_soft_state(dip);
ASSERT(pciehpc_init_count != 0);
pciehpc_init_count--;
mutex_exit(&pciehpc_init_mutex);
return (DDI_SUCCESS);
}
/*
* Probe for the inband PCI-E hot plug controller. Returns DDI_SUCCESS
* if found. This function works only for the standard PCI-E bridge
* that has inband hot plug controller.
*
* NOTE: This won't work for Host-PCIE bridges.
*/
int
pciehpc_probe_hpc(pciehpc_t *ctrl_p)
{
uint8_t cap_ptr;
uint8_t cap_id;
uint16_t status;
/* Read the PCI configuration status register. */
status = pciehpc_reg_get16(ctrl_p, PCI_CONF_STAT);
/* check for capabilities list */
if (!(status & PCI_STAT_CAP)) {
/* no capabilities list */
return (DDI_FAILURE);
}
/* Get a pointer to the PCI capabilities list. */
cap_ptr = pciehpc_reg_get8(ctrl_p, PCI_BCNF_CAP_PTR);
cap_ptr &= 0xFC; /* mask off reserved bits */
/*
* Walk thru the capabilities list looking for PCI Express capability
* structure.
*/
while (cap_ptr != PCI_CAP_NEXT_PTR_NULL) {
cap_id = pciehpc_reg_get8(ctrl_p, (uint_t)cap_ptr);
PCIEHPC_DEBUG3((CE_NOTE, "pciehpc_probe_hpc() capability @"
" pointer=%02x (id=%02x)\n", cap_ptr, cap_id));
if (cap_id == PCI_CAP_ID_PCI_E) {
uint32_t slot_cap;
/* Read the PCI Express Slot Capabilities Register */
slot_cap = pciehpc_reg_get32(ctrl_p,
(uint_t)cap_ptr + PCIE_SLOTCAP);
/* Does it have PCI Express HotPlug capability? */
if (slot_cap & PCIE_SLOTCAP_HP_CAPABLE) {
/* Save the offset to PCI Express Capabilities structure */
ctrl_p->pcie_caps_reg_offset = cap_ptr;
return (DDI_SUCCESS);
}
}
/* Get the pointer to the next capability */
cap_ptr = pciehpc_reg_get8(ctrl_p, (uint_t)cap_ptr + 1);
cap_ptr &= 0xFC;
}
return (DDI_FAILURE);
}
/*
* Setup slot information for use with HPS framework.
*/
int
pciehpc_slotinfo_init(pciehpc_t *ctrl_p)
{
uint32_t slot_capabilities, link_capabilities;
pciehpc_slot_t *p = &ctrl_p->slot;
/*
* setup HPS framework slot ops structure
*/
p->slot_ops.hpc_version = HPC_SLOT_OPS_VERSION;
p->slot_ops.hpc_op_connect = pciehpc_slot_connect;
p->slot_ops.hpc_op_disconnect = pciehpc_slot_disconnect;
p->slot_ops.hpc_op_insert = NULL;
p->slot_ops.hpc_op_remove = NULL;
p->slot_ops.hpc_op_control = pciehpc_slot_control;
/*
* setup HPS framework slot information structure
*/
p->slot_info.version = HPC_SLOT_OPS_VERSION;
p->slot_info.slot_type = HPC_SLOT_TYPE_PCIE;
p->slot_info.slot_flags =
HPC_SLOT_CREATE_DEVLINK | HPC_SLOT_NO_AUTO_ENABLE;
p->slot_info.pci_slot_capabilities = HPC_SLOT_64BITS;
/* the device number is fixed as 0 as per the spec */
p->slot_info.pci_dev_num = 0;
/* read Slot Capabilities Register */
slot_capabilities = pciehpc_reg_get32(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCAP);
/* set slot-name/slot-number info */
pciehpc_set_slot_name(ctrl_p);
/* check if Attn Button present */
ctrl_p->has_attn = (slot_capabilities & PCIE_SLOTCAP_ATTN_BUTTON) ?
B_TRUE : B_FALSE;
/* check if Manual Retention Latch sensor present */
ctrl_p->has_mrl = (slot_capabilities & PCIE_SLOTCAP_MRL_SENSOR) ?
B_TRUE : B_FALSE;
/*
* PCI-E version 1.1 defines EMI Lock Present bit
* in Slot Capabilities register. Check for it.
*/
ctrl_p->has_emi_lock = (slot_capabilities &
PCIE_SLOTCAP_EMI_LOCK_PRESENT) ? B_TRUE : B_FALSE;
link_capabilities = pciehpc_reg_get32(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_LINKCAP);
ctrl_p->dll_active_rep = (link_capabilities &
PCIE_LINKCAP_DLL_ACTIVE_REP_CAPABLE) ? B_TRUE : B_FALSE;
if (ctrl_p->dll_active_rep)
cv_init(&ctrl_p->slot.dll_active_cv, NULL, CV_DRIVER, NULL);
/* initialize synchronization conditional variable */
cv_init(&ctrl_p->slot.cmd_comp_cv, NULL, CV_DRIVER, NULL);
ctrl_p->slot.command_pending = B_FALSE;
/* setup thread for handling ATTN button events */
if (ctrl_p->has_attn) {
PCIEHPC_DEBUG3((CE_NOTE,
"pciehpc_slotinfo_init: setting up ATTN button event "
"handler thread for slot %d\n", ctrl_p->slot.slotNum));
cv_init(&ctrl_p->slot.attn_btn_cv, NULL, CV_DRIVER, NULL);
ctrl_p->slot.attn_btn_pending = B_FALSE;
ctrl_p->slot.attn_btn_threadp = thread_create(NULL, 0,
pciehpc_attn_btn_handler,
(void *)ctrl_p, 0, &p0, TS_RUN, minclsyspri);
ctrl_p->slot.attn_btn_thread_exit = B_FALSE;
}
/* get current slot state from the hw */
pciehpc_get_slot_state(ctrl_p);
return (DDI_SUCCESS);
}
/*ARGSUSED*/
int
pciehpc_slotinfo_uninit(pciehpc_t *ctrl_p)
{
cv_destroy(&ctrl_p->slot.cmd_comp_cv);
if (ctrl_p->slot.attn_btn_threadp != NULL) {
mutex_enter(&ctrl_p->pciehpc_mutex);
ctrl_p->slot.attn_btn_thread_exit = B_TRUE;
cv_signal(&ctrl_p->slot.attn_btn_cv);
PCIEHPC_DEBUG3((CE_NOTE,
"pciehpc_slotinfo_uninit: waiting for ATTN thread exit\n"));
cv_wait(&ctrl_p->slot.attn_btn_cv, &ctrl_p->pciehpc_mutex);
PCIEHPC_DEBUG3((CE_NOTE,
"pciehpc_slotinfo_uninit: ATTN thread exit\n"));
cv_destroy(&ctrl_p->slot.attn_btn_cv);
ctrl_p->slot.attn_btn_threadp = NULL;
mutex_exit(&ctrl_p->pciehpc_mutex);
}
if (ctrl_p->dll_active_rep)
cv_destroy(&ctrl_p->slot.dll_active_cv);
return (DDI_SUCCESS);
}
/*
* Get the current state of the slot from the hw.
*/
void
pciehpc_get_slot_state(pciehpc_t *ctrl_p)
{
pciehpc_slot_t *p = &ctrl_p->slot;
uint16_t control, status;
/* read the Slot Control Register */
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
p->fault_led_state = HPC_LED_OFF; /* no fault led */
p->active_led_state = HPC_LED_OFF; /* no active led */
/* read the current Slot Status Register */
status = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS);
/* get POWER led state */
p->power_led_state =
pciehpc_led_state_to_hpc(pcie_slotctl_pwr_indicator_get(control));
/* get ATTN led state */
p->attn_led_state =
pciehpc_led_state_to_hpc(pcie_slotctl_attn_indicator_get(control));
if (!(status & PCIE_SLOTSTS_PRESENCE_DETECTED))
/* no device present; slot is empty */
p->slot_state = HPC_SLOT_EMPTY;
else if (!(control & PCIE_SLOTCTL_PWR_CONTROL))
/* device is present and powered up */
p->slot_state = HPC_SLOT_CONNECTED;
else
/* device is present and powered down */
p->slot_state = HPC_SLOT_DISCONNECTED;
}
/*
* pciehpc_regs_setup()
*
* Setup PCI-E config registers for DDI access functions.
*
* Note: This is same as pci_config_setup() except that this may be
* used to map specific reg set with an offset in the case of host
* PCI-E bridges.
*/
int
pciehpc_regs_setup(dev_info_t *dip, uint_t rnum, offset_t off,
caddr_t *addrp, ddi_acc_handle_t *handle)
{
ddi_device_acc_attr_t attr;
attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC;
attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
/* Check for fault management capabilities */
if (DDI_FM_ACC_ERR_CAP(ddi_fm_capable(dip)))
attr.devacc_attr_access = DDI_FLAGERR_ACC;
return (ddi_regs_map_setup(dip, rnum, addrp, off, 0, &attr, handle));
}
/*
* pciehpc_regs_teardown()
*
* Unmap config register set.
*
* Note: This is same as pci_config_teardown() function.
*/
void
pciehpc_regs_teardown(ddi_acc_handle_t *handle)
{
ddi_regs_map_free(handle);
}
/*
* Find the soft state structure for the HPC associated with the dip.
*/
static pciehpc_t *
pciehpc_get_soft_state(dev_info_t *dip)
{
pciehpc_t *ctrl_p;
mutex_enter(&pciehpc_list_mutex);
ctrl_p = pciehpc_head;
while (ctrl_p) {
if (ctrl_p->dip == dip) {
mutex_exit(&pciehpc_list_mutex);
return (ctrl_p);
}
ctrl_p = ctrl_p->nextp;
}
mutex_exit(&pciehpc_list_mutex);
return (NULL);
}
/*
* Allocate a soft state structure for the HPC associated with this dip.
*/
static pciehpc_t *
pciehpc_create_soft_state(dev_info_t *dip)
{
pciehpc_t *ctrl_p;
ctrl_p = kmem_zalloc(sizeof (pciehpc_t), KM_SLEEP);
ctrl_p->dip = dip;
mutex_enter(&pciehpc_list_mutex);
ctrl_p->nextp = pciehpc_head;
pciehpc_head = ctrl_p;
ctrl_p->soft_state = PCIEHPC_SOFT_STATE_UNINITIALIZED;
mutex_exit(&pciehpc_list_mutex);
return (ctrl_p);
}
/*
* Remove the HPC soft state structure from the linked list.
*/
static void
pciehpc_destroy_soft_state(dev_info_t *dip)
{
pciehpc_t **pp;
pciehpc_t *p;
mutex_enter(&pciehpc_list_mutex);
pp = &pciehpc_head;
while ((p = *pp) != NULL) {
if (p->dip == dip) {
*pp = p->nextp;
kmem_free(p, sizeof (pciehpc_t));
break;
}
pp = &(p->nextp);
}
mutex_exit(&pciehpc_list_mutex);
}
/*
* convert LED state from PCIE HPC definition to hpc_led_state_t
* definition.
*/
hpc_led_state_t
pciehpc_led_state_to_hpc(uint16_t state)
{
switch (state) {
case PCIE_SLOTCTL_INDICATOR_STATE_ON:
return (HPC_LED_ON);
case PCIE_SLOTCTL_INDICATOR_STATE_BLINK:
return (HPC_LED_BLINK);
case PCIE_SLOTCTL_INDICATOR_STATE_OFF:
default:
return (HPC_LED_OFF);
}
}
/*
* convert LED state from hpc_led_state_t definition to PCIE HPC
* definition.
*/
uint16_t
pciehpc_led_state_to_pciehpc(hpc_led_state_t state)
{
switch (state) {
case HPC_LED_ON:
return (PCIE_SLOTCTL_INDICATOR_STATE_ON);
case HPC_LED_BLINK:
return (PCIE_SLOTCTL_INDICATOR_STATE_BLINK);
case HPC_LED_OFF:
default:
return (PCIE_SLOTCTL_INDICATOR_STATE_OFF);
}
}
/*
* Initialize HPC hardware, install interrupt handler, etc. It doesn't
* enable hot plug interrupts.
*
* (Note: It is called only from pciehpc_init().)
*/
int
pciehpc_hpc_init(pciehpc_t *ctrl_p)
{
uint16_t reg;
/* read the Slot Control Register */
reg = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
/* disable all interrupts */
reg &= ~(SLOTCTL_SUPPORTED_INTRS_MASK);
pciehpc_reg_put16(ctrl_p, ctrl_p->pcie_caps_reg_offset +
PCIE_SLOTCTL, reg);
/* clear any interrupt status bits */
reg = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS);
pciehpc_reg_put16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS, reg);
/* initialize the interrupt mutex */
mutex_init(&ctrl_p->pciehpc_mutex, NULL, MUTEX_DRIVER,
(void *)PCIEHPC_INTR_PRI);
return (DDI_SUCCESS);
}
/*
* Uninitialize HPC hardware, uninstall interrupt handler, etc.
*
* (Note: It is called only from pciehpc_uninit().)
*/
int
pciehpc_hpc_uninit(pciehpc_t *ctrl_p)
{
/* disable interrupts */
(void) pciehpc_disable_intr(ctrl_p);
/* destroy the mutex */
mutex_destroy(&ctrl_p->pciehpc_mutex);
return (DDI_SUCCESS);
}
/*
* Disable hot plug interrupts.
* Note: this is only for Native hot plug mode.
*/
int
pciehpc_disable_intr(pciehpc_t *ctrl_p)
{
uint16_t reg;
/* read the Slot Control Register */
reg = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
/* disable all interrupts */
reg &= ~(SLOTCTL_SUPPORTED_INTRS_MASK);
pciehpc_reg_put16(ctrl_p, ctrl_p->pcie_caps_reg_offset +
PCIE_SLOTCTL, reg);
/* clear any interrupt status bits */
reg = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS);
pciehpc_reg_put16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS, reg);
return (DDI_SUCCESS);
}
/*
* Enable hot plug interrupts.
* Note: this is only for Native hot plug mode.
*/
int
pciehpc_enable_intr(pciehpc_t *ctrl_p)
{
uint16_t reg;
/* clear any interrupt status bits */
reg = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS);
pciehpc_reg_put16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS, reg);
/* read the Slot Control Register */
reg = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
/*
* enable interrupts: power fault detection interrupt is enabled
* only when the slot is 'connected', i.e. power is ON
*/
if (ctrl_p->slot.slot_state == HPC_SLOT_CONNECTED)
pciehpc_reg_put16(ctrl_p, ctrl_p->pcie_caps_reg_offset +
PCIE_SLOTCTL, reg | SLOTCTL_SUPPORTED_INTRS_MASK);
else
pciehpc_reg_put16(ctrl_p, ctrl_p->pcie_caps_reg_offset +
PCIE_SLOTCTL, reg | (SLOTCTL_SUPPORTED_INTRS_MASK &
~PCIE_SLOTCTL_PWR_FAULT_EN));
return (DDI_SUCCESS);
}
/*
* Register the PCI-E hot plug slot with HPS framework.
*/
int
pciehpc_register_slot(pciehpc_t *ctrl_p)
{
char nexus_path[MAXNAMELEN];
pciehpc_slot_t *p = &ctrl_p->slot;
/* get nexus path name */
(void) ddi_pathname(ctrl_p->dip, nexus_path);
/* register the slot with HPS framework */
if (hpc_slot_register(ctrl_p->dip, nexus_path,
&p->slot_info, &p->slot_handle,
&p->slot_ops, (caddr_t)ctrl_p, 0) != 0) {
PCIEHPC_DEBUG((CE_WARN,
"pciehpc_register_slot() failed to register slot %d\n",
p->slotNum));
return (DDI_FAILURE);
}
PCIEHPC_DEBUG3((CE_NOTE,
"pciehpc_register_slot(): registered slot %d\n", p->slotNum));
return (DDI_SUCCESS);
}
/*
* Unregister the PCI-E hot plug slot from the HPS framework.
*/
int
pciehpc_unregister_slot(pciehpc_t *ctrl_p)
{
pciehpc_slot_t *p = &ctrl_p->slot;
if (hpc_slot_unregister(&p->slot_handle) != 0) {
PCIEHPC_DEBUG((CE_WARN,
"pciehpc_unregister_slot() failed to unregister slot %d\n",
p->slotNum));
return (DDI_FAILURE);
}
PCIEHPC_DEBUG3((CE_NOTE,
"pciehpc_unregister_slot(): unregistered slot %d\n", p->slotNum));
return (DDI_SUCCESS);
}
/*
* pciehpc_intr()
*
* Interrupt handler for PCI-E Hot plug controller interrupts.
*
* Note: This is only for native mode hot plug. This is called
* by the nexus driver at interrupt context. Interrupt Service Routine
* registration is done by the nexus driver for both hot plug and
* non-hot plug interrupts. This function is called from the ISR
* of the nexus driver to handle hot-plug interrupts.
*/
int
pciehpc_intr(dev_info_t *dip)
{
pciehpc_t *ctrl_p;
uint16_t status, control;
/* get the soft state structure for this dip */
if ((ctrl_p = pciehpc_get_soft_state(dip)) == NULL)
return (DDI_INTR_UNCLAIMED);
mutex_enter(&ctrl_p->pciehpc_mutex);
/* make sure the controller soft state is initialized */
if (ctrl_p->soft_state & PCIEHPC_SOFT_STATE_UNINITIALIZED) {
mutex_exit(&ctrl_p->pciehpc_mutex);
return (DDI_INTR_UNCLAIMED);
}
/* if it is not NATIVE hot plug mode then return */
if (ctrl_p->hp_mode != PCIEHPC_NATIVE_HP_MODE) {
mutex_exit(&ctrl_p->pciehpc_mutex);
return (DDI_INTR_UNCLAIMED);
}
/* read the current slot status register */
status = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS);
/* check if there are any hot plug interrupts occurred */
if (!(status & SLOT_STATUS_EVENTS)) {
/* no hot plug events occurred */
mutex_exit(&ctrl_p->pciehpc_mutex);
return (DDI_INTR_UNCLAIMED);
}
/* clear the interrupt status bits */
pciehpc_reg_put16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS, status);
/* check for CMD COMPLETE interrupt */
if (status & PCIE_SLOTSTS_COMMAND_COMPLETED) {
PCIEHPC_DEBUG3((CE_NOTE,
"pciehpc_intr(): CMD COMPLETED interrupt received\n"));
/* wake up any one waiting for Command Completion event */
cv_signal(&ctrl_p->slot.cmd_comp_cv);
}
/* check for ATTN button interrupt */
if (status & PCIE_SLOTSTS_ATTN_BTN_PRESSED) {
PCIEHPC_DEBUG3((CE_NOTE,
"pciehpc_intr(): ATTN BUTTON interrupt received\n"));
/* if ATTN button event is still pending then cancel it */
if (ctrl_p->slot.attn_btn_pending == B_TRUE)
ctrl_p->slot.attn_btn_pending = B_FALSE;
else
ctrl_p->slot.attn_btn_pending = B_TRUE;
/* wake up the ATTN event handler */
cv_signal(&ctrl_p->slot.attn_btn_cv);
}
/* check for power fault interrupt */
if (status & PCIE_SLOTSTS_PWR_FAULT_DETECTED) {
PCIEHPC_DEBUG3((CE_NOTE,
"pciehpc_intr(): POWER FAULT interrupt received"
" on slot %d\n", ctrl_p->slot.slotNum));
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
if (control & PCIE_SLOTCTL_PWR_FAULT_EN) {
/* disable power fault detction interrupt */
pciehpc_reg_put16(ctrl_p, ctrl_p->pcie_caps_reg_offset +
PCIE_SLOTCTL, control & ~PCIE_SLOTCTL_PWR_FAULT_EN);
/* turn on ATTN LED */
pciehpc_set_led_state(ctrl_p, HPC_ATTN_LED, HPC_LED_OFF);
/* send the event to HPS framework */
(void) hpc_slot_event_notify(ctrl_p->slot.slot_handle,
HPC_EVENT_SLOT_POWER_FAULT, HPC_EVENT_NORMAL);
}
}
/* check for MRL SENSOR CHANGED interrupt */
if (status & PCIE_SLOTSTS_MRL_SENSOR_CHANGED) {
PCIEHPC_DEBUG3((CE_NOTE,
"pciehpc_intr(): MRL SENSOR CHANGED interrupt received"
" on slot %d\n", ctrl_p->slot.slotNum));
/* For now (phase-I), no action is taken on this event */
}
/* check for PRESENCE CHANGED interrupt */
if (status & PCIE_SLOTSTS_PRESENCE_CHANGED) {
PCIEHPC_DEBUG3((CE_NOTE,
"pciehpc_intr(): PRESENCE CHANGED interrupt received"
" on slot %d\n", ctrl_p->slot.slotNum));
if (status & PCIE_SLOTSTS_PRESENCE_DETECTED) {
/* card is inserted into the slot */
/* send the event to HPS framework */
(void) hpc_slot_event_notify(ctrl_p->slot.slot_handle,
HPC_EVENT_SLOT_INSERTION, HPC_EVENT_NORMAL);
} else {
/* card is removed from the slot */
/* make sure to disable power fault detction interrupt */
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
if (control & PCIE_SLOTCTL_PWR_FAULT_EN)
pciehpc_reg_put16(ctrl_p, ctrl_p->pcie_caps_reg_offset +
PCIE_SLOTCTL, control & ~PCIE_SLOTCTL_PWR_FAULT_EN);
/* turn off ATTN LED */
pciehpc_set_led_state(ctrl_p, HPC_ATTN_LED, HPC_LED_OFF);
/* send the event to HPS framework */
(void) hpc_slot_event_notify(ctrl_p->slot.slot_handle,
HPC_EVENT_SLOT_REMOVAL, HPC_EVENT_NORMAL);
}
}
/* check for DLL state changed interrupt */
if (ctrl_p->dll_active_rep &&
(status & PCIE_SLOTSTS_DLL_STATE_CHANGED)) {
PCIEHPC_DEBUG3((CE_NOTE,
"pciehpc_intr(): DLL STATE CHANGED interrupt received"
" on slot %d\n", ctrl_p->slot.slotNum));
cv_signal(&ctrl_p->slot.dll_active_cv);
}
mutex_exit(&ctrl_p->pciehpc_mutex);
return (DDI_INTR_CLAIMED);
}
#ifdef DEBUG
/*
* Dump PCI-E Hot Plug registers.
*/
static void
pciehpc_dump_hpregs(pciehpc_t *ctrl_p)
{
uint16_t control;
uint32_t capabilities;
capabilities = pciehpc_reg_get32(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCAP);
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
cmn_err(CE_NOTE, "pciehpc_dump_hpregs: Found PCI-E hot plug slot %d\n",
ctrl_p->slot.slotNum);
cmn_err(CE_NOTE, "Attention Button Present = %s",
capabilities & PCIE_SLOTCAP_ATTN_BUTTON ? "Yes":"No");
cmn_err(CE_NOTE, "Power controller Present = %s",
capabilities & PCIE_SLOTCAP_POWER_CONTROLLER ? "Yes":"No");
cmn_err(CE_NOTE, "MRL Sensor Present = %s",
capabilities & PCIE_SLOTCAP_MRL_SENSOR ? "Yes":"No");
cmn_err(CE_NOTE, "Attn Indicator Present = %s",
capabilities & PCIE_SLOTCAP_ATTN_INDICATOR ? "Yes":"No");
cmn_err(CE_NOTE, "Power Indicator Present = %s",
capabilities & PCIE_SLOTCAP_PWR_INDICATOR ? "Yes":"No");
cmn_err(CE_NOTE, "HotPlug Surprise = %s",
capabilities & PCIE_SLOTCAP_HP_SURPRISE ? "Yes":"No");
cmn_err(CE_NOTE, "HotPlug Capable = %s",
capabilities & PCIE_SLOTCAP_HP_CAPABLE ? "Yes":"No");
cmn_err(CE_NOTE, "Physical Slot Number = %d",
PCIE_SLOTCAP_PHY_SLOT_NUM(capabilities));
cmn_err(CE_NOTE, "Attn Button interrupt Enabled = %s",
control & PCIE_SLOTCTL_ATTN_BTN_EN ? "Yes":"No");
cmn_err(CE_NOTE, "Power Fault interrupt Enabled = %s",
control & PCIE_SLOTCTL_PWR_FAULT_EN ? "Yes":"No");
cmn_err(CE_NOTE, "MRL Sensor INTR Enabled = %s",
control & PCIE_SLOTCTL_MRL_SENSOR_EN ? "Yes":"No");
cmn_err(CE_NOTE, "Presence interrupt Enabled = %s",
control & PCIE_SLOTCTL_PRESENCE_CHANGE_EN ? "Yes":"No");
cmn_err(CE_NOTE, "Cmd Complete interrupt Enabled = %s",
control & PCIE_SLOTCTL_CMD_INTR_EN ? "Yes":"No");
cmn_err(CE_NOTE, "HotPlug interrupt Enabled = %s",
control & PCIE_SLOTCTL_HP_INTR_EN ? "Yes":"No");
cmn_err(CE_NOTE, "Power Indicator LED = %s", pciehpc_led_state_text(
pciehpc_led_state_to_hpc(pcie_slotctl_pwr_indicator_get(control))));
cmn_err(CE_NOTE, "Attn Indicator LED = %s",
pciehpc_led_state_text(pciehpc_led_state_to_hpc(
pcie_slotctl_attn_indicator_get(control))));
}
static char *
pciehpc_led_state_text(hpc_led_state_t state)
{
switch (state) {
case HPC_LED_ON:
return ("on");
case HPC_LED_OFF:
return ("off");
case HPC_LED_BLINK:
default:
return ("blink");
}
}
#endif /* DEBUG */
/*
* pciehpc_slot_connect()
*
* Connect power to the PCI-E slot.
*
* Returns: HPC_SUCCESS if the slot is powered up and enabled.
* HPC_ERR_FAILED if the slot can't be enabled.
*
* (Note: This function is called by HPS framework at kernel context only.)
*/
/*ARGSUSED*/
int
pciehpc_slot_connect(caddr_t ops_arg, hpc_slot_t slot_hdl,
void *data, uint_t flags)
{
uint16_t status, control;
pciehpc_t *ctrl_p = (pciehpc_t *)ops_arg;
ASSERT(slot_hdl == ctrl_p->slot.slot_handle);
mutex_enter(&ctrl_p->pciehpc_mutex);
/* get the current state of the slot */
pciehpc_get_slot_state(ctrl_p);
/* check if the slot is already in the 'connected' state */
if (ctrl_p->slot.slot_state == HPC_SLOT_CONNECTED) {
/* slot is already in the 'connected' state */
PCIEHPC_DEBUG3((CE_NOTE,
"pciehpc_slot_connect() slot %d already connected\n",
ctrl_p->slot.slotNum));
mutex_exit(&ctrl_p->pciehpc_mutex);
return (HPC_SUCCESS);
}
/* read the Slot Status Register */
status = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS);
/* make sure the MRL switch is closed if present */
if ((ctrl_p->has_mrl) && (status & PCIE_SLOTSTS_MRL_SENSOR_OPEN)) {
/* MRL switch is open */
cmn_err(CE_WARN, "MRL switch is open on slot %d\n",
ctrl_p->slot.slotNum);
goto cleanup;
}
/* make sure the slot has a device present */
if (!(status & PCIE_SLOTSTS_PRESENCE_DETECTED)) {
/* slot is empty */
PCIEHPC_DEBUG((CE_NOTE,
"slot %d is empty\n", ctrl_p->slot.slotNum));
goto cleanup;
}
/* get the current state of Slot Control Register */
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
/* check if the slot's power state is ON */
if (!(control & PCIE_SLOTCTL_PWR_CONTROL)) {
/* slot is already powered up */
PCIEHPC_DEBUG3((CE_NOTE,
"pciehpc_slot_connect() slot %d already connected\n",
ctrl_p->slot.slotNum));
ctrl_p->slot.slot_state = HPC_SLOT_CONNECTED;
mutex_exit(&ctrl_p->pciehpc_mutex);
return (HPC_SUCCESS);
}
/*
* Enable power to the slot involves:
* 1. Set power LED to blink and ATTN led to OFF.
* 2. Set power control ON in Slot Control Reigster and
* wait for Command Completed Interrupt or 1 sec timeout.
* 3. If Data Link Layer State Changed events are supported
* then wait for the event to indicate Data Layer Link
* is active. The time out value for this event is 1 second.
* This is specified in PCI-E version 1.1.
* 4. Set power LED to be ON.
*/
/* 1. set power LED to blink & ATTN led to OFF */
pciehpc_set_led_state(ctrl_p, HPC_POWER_LED, HPC_LED_BLINK);
pciehpc_set_led_state(ctrl_p, HPC_ATTN_LED, HPC_LED_OFF);
/* 2. set power control to ON */
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
control &= ~PCIE_SLOTCTL_PWR_CONTROL;
pciehpc_issue_hpc_command(ctrl_p, control);
/* 3. wait for DLL State Change event, if it's supported */
if (ctrl_p->dll_active_rep) {
status = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_LINKSTS);
if (!(status & PCIE_LINKSTS_DLL_LINK_ACTIVE)) {
/* wait 1 sec for the DLL State Changed event */
(void) cv_timedwait(&ctrl_p->slot.dll_active_cv,
&ctrl_p->pciehpc_mutex,
ddi_get_lbolt() +
SEC_TO_TICK(PCIEHPC_DLL_STATE_CHANGE_TIMEOUT));
/* check Link status */
status = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset +
PCIE_LINKSTS);
if (!(status & PCIE_LINKSTS_DLL_LINK_ACTIVE))
goto cleanup2;
}
/* wait 100ms after DLL_LINK_ACTIVE field reads 1b */
delay(drv_usectohz(100000));
} else {
/* wait 1 sec for link to come up */
delay(drv_usectohz(1000000));
}
/* check power is really turned ON */
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
if (control & PCIE_SLOTCTL_PWR_CONTROL) {
PCIEHPC_DEBUG((CE_NOTE,
"slot %d fails to turn on power on connect\n",
ctrl_p->slot.slotNum));
goto cleanup1;
}
/* enable power fault detection interrupt */
control |= PCIE_SLOTCTL_PWR_FAULT_EN;
pciehpc_issue_hpc_command(ctrl_p, control);
/* 4. Set power LED to be ON */
pciehpc_set_led_state(ctrl_p, HPC_POWER_LED, HPC_LED_ON);
/* if EMI is present, turn it ON */
if (ctrl_p->has_emi_lock) {
status = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS);
if (!(status & PCIE_SLOTSTS_EMI_LOCK_SET)) {
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
control |= PCIE_SLOTCTL_EMI_LOCK_CONTROL;
pciehpc_issue_hpc_command(ctrl_p, control);
/* wait 1 sec after toggling the state of EMI lock */
delay(drv_usectohz(1000000));
}
}
ctrl_p->slot.slot_state = HPC_SLOT_CONNECTED;
mutex_exit(&ctrl_p->pciehpc_mutex);
return (HPC_SUCCESS);
cleanup2:
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
/* if power is ON, set power control to OFF */
if (!(control & PCIE_SLOTCTL_PWR_CONTROL)) {
control |= PCIE_SLOTCTL_PWR_CONTROL;
pciehpc_issue_hpc_command(ctrl_p, control);
}
cleanup1:
/* set power led to OFF */
pciehpc_set_led_state(ctrl_p, HPC_POWER_LED, HPC_LED_OFF);
cleanup:
mutex_exit(&ctrl_p->pciehpc_mutex);
return (HPC_ERR_FAILED);
}
/*
* pciehpc_slot_disconnect()
*
* Disconnect power to the slot.
*
* Returns: HPC_SUCCESS if the slot is powered up and enabled.
* HPC_ERR_FAILED if the slot can't be enabled.
*
* (Note: This function is called by HPS framework at kernel context only.)
*/
/*ARGSUSED*/
int
pciehpc_slot_disconnect(caddr_t ops_arg, hpc_slot_t slot_hdl,
void *data, uint_t flags)
{
uint16_t status;
uint16_t control;
pciehpc_t *ctrl_p = (pciehpc_t *)ops_arg;
ASSERT(slot_hdl == ctrl_p->slot.slot_handle);
mutex_enter(&ctrl_p->pciehpc_mutex);
/* get the current state of the slot */
pciehpc_get_slot_state(ctrl_p);
/* check if the slot is already in the 'disconnected' state */
if (ctrl_p->slot.slot_state == HPC_SLOT_DISCONNECTED) {
/* slot is in the 'disconnected' state */
PCIEHPC_DEBUG3((CE_NOTE,
"pciehpc_slot_disconnect(): slot %d already disconnected\n",
ctrl_p->slot.slotNum));
ASSERT(ctrl_p->slot.power_led_state == HPC_LED_OFF);
mutex_exit(&ctrl_p->pciehpc_mutex);
return (HPC_SUCCESS);
}
/* read the Slot Status Register */
status = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS);
/* make sure the slot has a device present */
if (!(status & PCIE_SLOTSTS_PRESENCE_DETECTED)) {
/* slot is empty */
PCIEHPC_DEBUG((CE_NOTE,
"pciehpc_slot_disconnect(): slot %d is empty\n",
ctrl_p->slot.slotNum));
goto cleanup;
}
/*
* Disable power to the slot involves:
* 1. Set power LED to blink.
* 2. Set power control OFF in Slot Control Reigster and
* wait for Command Completed Interrupt or 1 sec timeout.
* 3. Set POWER led and ATTN led to be OFF.
*/
/* 1. set power LED to blink */
pciehpc_set_led_state(ctrl_p, HPC_POWER_LED, HPC_LED_BLINK);
/* disable power fault detection interrupt */
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
control &= ~PCIE_SLOTCTL_PWR_FAULT_EN;
pciehpc_issue_hpc_command(ctrl_p, control);
/* 2. set power control to OFF */
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
control |= PCIE_SLOTCTL_PWR_CONTROL;
pciehpc_issue_hpc_command(ctrl_p, control);
#ifdef DEBUG
/* check for power control bit to be OFF */
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
ASSERT(control & PCIE_SLOTCTL_PWR_CONTROL);
#endif
/* 3. Set power LED to be OFF */
pciehpc_set_led_state(ctrl_p, HPC_POWER_LED, HPC_LED_OFF);
pciehpc_set_led_state(ctrl_p, HPC_ATTN_LED, HPC_LED_OFF);
/* if EMI is present, turn it OFF */
if (ctrl_p->has_emi_lock) {
status = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS);
if (status & PCIE_SLOTSTS_EMI_LOCK_SET) {
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
control |= PCIE_SLOTCTL_EMI_LOCK_CONTROL;
pciehpc_issue_hpc_command(ctrl_p, control);
/* wait 1 sec after toggling the state of EMI lock */
delay(drv_usectohz(1000000));
}
}
ctrl_p->slot.slot_state = HPC_SLOT_DISCONNECTED;
mutex_exit(&ctrl_p->pciehpc_mutex);
return (HPC_SUCCESS);
cleanup:
mutex_exit(&ctrl_p->pciehpc_mutex);
return (HPC_ERR_FAILED);
}
/*ARGSUSED*/
int
pciehpc_slot_control(caddr_t ops_arg, hpc_slot_t slot_hdl,
int request, caddr_t arg)
{
pciehpc_t *ctrl_p;
hpc_led_info_t *led_info;
int ret = HPC_SUCCESS;
ctrl_p = (pciehpc_t *)ops_arg;
ASSERT(ctrl_p != NULL);
mutex_enter(&ctrl_p->pciehpc_mutex);
/* get the current slot state */
pciehpc_get_slot_state(ctrl_p);
switch (request) {
case HPC_CTRL_GET_SLOT_STATE:
*(hpc_slot_state_t *)arg = ctrl_p->slot.slot_state;
break;
case HPC_CTRL_GET_BOARD_TYPE:
if (ctrl_p->slot.slot_state == HPC_SLOT_EMPTY)
*(hpc_board_type_t *)arg = HPC_BOARD_UNKNOWN;
else
*(hpc_board_type_t *)arg = HPC_BOARD_PCI_HOTPLUG;
break;
case HPC_CTRL_GET_LED_STATE:
led_info = (hpc_led_info_t *)arg;
switch (led_info->led) {
case HPC_ATTN_LED:
led_info->state = ctrl_p->slot.attn_led_state;
break;
case HPC_POWER_LED:
led_info->state = ctrl_p->slot.power_led_state;
break;
case HPC_FAULT_LED:
case HPC_ACTIVE_LED:
led_info->state = HPC_LED_OFF;
break;
default:
PCIEHPC_DEBUG((CE_WARN, "pciehpc_slot_control:"
" unknown led state\n"));
ret = HPC_ERR_NOTSUPPORTED;
break;
}
break;
case HPC_CTRL_SET_LED_STATE:
led_info = (hpc_led_info_t *)arg;
switch (led_info->led) {
case HPC_ATTN_LED:
pciehpc_set_led_state(ctrl_p, led_info->led,
led_info->state);
break;
case HPC_POWER_LED:
PCIEHPC_DEBUG((CE_WARN, "pciehpc_slot_control: power"
" LED control is not allowed on slot #%d\n",
ctrl_p->slot.slotNum));
ret = HPC_ERR_NOTSUPPORTED;
break;
case HPC_FAULT_LED:
case HPC_ACTIVE_LED:
break;
default:
PCIEHPC_DEBUG((CE_WARN, "pciehpc_slot_control:"
" unknown led type %d\n", led_info->led));
ret = HPC_ERR_NOTSUPPORTED;
break;
}
break;
case HPC_CTRL_DEV_CONFIG_FAILURE:
/* turn the ATTN led ON for configure failure */
pciehpc_set_led_state(ctrl_p, HPC_ATTN_LED, HPC_LED_ON);
/* if power to the slot is still on then set Power led to ON */
if (ctrl_p->slot.slot_state == HPC_SLOT_CONNECTED)
pciehpc_set_led_state(ctrl_p, HPC_POWER_LED, HPC_LED_ON);
break;
case HPC_CTRL_DEV_UNCONFIG_FAILURE:
/* if power to the slot is still on then set Power led to ON */
if (ctrl_p->slot.slot_state == HPC_SLOT_CONNECTED)
pciehpc_set_led_state(ctrl_p, HPC_POWER_LED, HPC_LED_ON);
PCIEHPC_ENABLE_ERRORS(ctrl_p);
break;
case HPC_CTRL_ENABLE_AUTOCFG:
case HPC_CTRL_DISABLE_AUTOCFG:
/* no action is needed here */
break;
case HPC_CTRL_DISABLE_SLOT:
case HPC_CTRL_ENABLE_SLOT:
/* no action is needed here */
break;
case HPC_CTRL_DEV_CONFIG_START:
case HPC_CTRL_DEV_UNCONFIG_START:
PCIEHPC_DISABLE_ERRORS(ctrl_p);
/* no action is needed here */
break;
case HPC_CTRL_DEV_CONFIGURED:
case HPC_CTRL_DEV_UNCONFIGURED:
/* no action is needed here */
if (request == HPC_CTRL_DEV_CONFIGURED) {
/*EMPTY*/
PCIEHPC_ENABLE_ERRORS(ctrl_p);
}
break;
default:
PCIEHPC_DEBUG((CE_WARN,
"pciehpc_slot_control: unsupported operation\n"));
ret = HPC_ERR_NOTSUPPORTED;
}
mutex_exit(&ctrl_p->pciehpc_mutex);
return (ret);
}
/*
* Get the state of an LED.
*/
hpc_led_state_t
pciehpc_get_led_state(pciehpc_t *ctrl_p, hpc_led_t led)
{
uint16_t control;
uint16_t state;
/* get the current state of Slot Control register */
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
switch (led) {
case HPC_POWER_LED:
state = pcie_slotctl_pwr_indicator_get(control);
break;
case HPC_ATTN_LED:
state = pcie_slotctl_attn_indicator_get(control);
break;
default:
PCIEHPC_DEBUG((CE_WARN,
"pciehpc_get_led_state() invalid LED %d\n", led));
return (HPC_LED_OFF);
}
switch (state) {
case PCIE_SLOTCTL_INDICATOR_STATE_ON:
return (HPC_LED_ON);
case PCIE_SLOTCTL_INDICATOR_STATE_BLINK:
return (HPC_LED_BLINK);
case PCIE_SLOTCTL_INDICATOR_STATE_OFF:
default:
return (HPC_LED_OFF);
}
}
/*
* Set the state of an LED. It updates both hw and sw state.
*/
void
pciehpc_set_led_state(pciehpc_t *ctrl_p, hpc_led_t led, hpc_led_state_t state)
{
uint16_t control;
/* get the current state of Slot Control register */
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
switch (led) {
case HPC_POWER_LED:
/* clear led mask */
control &= ~PCIE_SLOTCTL_PWR_INDICATOR_MASK;
ctrl_p->slot.power_led_state = state;
break;
case HPC_ATTN_LED:
/* clear led mask */
control &= ~PCIE_SLOTCTL_ATTN_INDICATOR_MASK;
ctrl_p->slot.attn_led_state = state;
break;
default:
PCIEHPC_DEBUG((CE_WARN,
"pciehpc_set_led_state() invalid LED %d\n", led));
return;
}
switch (state) {
case HPC_LED_ON:
if (led == HPC_POWER_LED)
control = pcie_slotctl_pwr_indicator_set(control,
PCIE_SLOTCTL_INDICATOR_STATE_ON);
else if (led == HPC_ATTN_LED)
control = pcie_slotctl_attn_indicator_set(control,
PCIE_SLOTCTL_INDICATOR_STATE_ON);
break;
case HPC_LED_OFF:
if (led == HPC_POWER_LED)
control = pcie_slotctl_pwr_indicator_set(control,
PCIE_SLOTCTL_INDICATOR_STATE_OFF);
else if (led == HPC_ATTN_LED)
control = pcie_slotctl_attn_indicator_set(control,
PCIE_SLOTCTL_INDICATOR_STATE_OFF);
break;
case HPC_LED_BLINK:
if (led == HPC_POWER_LED)
control = pcie_slotctl_pwr_indicator_set(control,
PCIE_SLOTCTL_INDICATOR_STATE_BLINK);
else if (led == HPC_ATTN_LED)
control = pcie_slotctl_attn_indicator_set(control,
PCIE_SLOTCTL_INDICATOR_STATE_BLINK);
break;
default:
PCIEHPC_DEBUG((CE_WARN,
"pciehpc_set_led_state() invalid LED state %d\n", state));
return;
}
/* update the Slot Control Register */
pciehpc_issue_hpc_command(ctrl_p, control);
#ifdef DEBUG
/* get the current state of Slot Control register */
control = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL);
PCIEHPC_DEBUG3((CE_NOTE, "pciehpc_set_led_state: "
"slot %d power-led %s attn-led %s\n",
ctrl_p->slot.slotNum,
pciehpc_led_state_text(
pciehpc_led_state_to_hpc(
pcie_slotctl_pwr_indicator_get(control))),
pciehpc_led_state_text(
pciehpc_led_state_to_hpc(
pcie_slotctl_attn_indicator_get(control)))));
#endif
}
/*
* Send a command to the PCI-E Hot Plug Controller.
*
* NOTES: The PCI-E spec defines the following semantics for issuing hot plug
* commands.
* 1) If Command Complete events/interrupts are supported then software
* waits for Command Complete event after issuing a command (i.e writing
* to the Slot Control register). The command completion could take as
* long as 1 second so software should be prepared to wait for 1 second
* before issuing another command.
*
* 2) If Command Complete events/interrupts are not supported then
* software could issue multiple Slot Control writes without any delay
* between writes.
*/
void
pciehpc_issue_hpc_command(pciehpc_t *ctrl_p, uint16_t control)
{
uint16_t status;
uint32_t slot_cap;
/*
* PCI-E version 1.1 spec defines No Command Completed
* Support bit (bit#18) in Slot Capabilities register. If this
* bit is set then slot doesn't support notification of command
* completion events.
*/
slot_cap = pciehpc_reg_get32(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCAP);
/*
* If no Command Completion event is supported or it is ACPI
* hot plug mode then just issue the command and return.
*/
if ((slot_cap & PCIE_SLOTCAP_NO_CMD_COMP_SUPP) ||
(ctrl_p->hp_mode == PCIEHPC_ACPI_HP_MODE)) {
pciehpc_reg_put16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL, control);
return;
}
/*
* **************************************
* Command Complete events are supported.
* **************************************
*/
/*
* If HPC is not yet initialized then just poll for the Command
* Completion interrupt.
*/
if (!(ctrl_p->soft_state & PCIEHPC_SOFT_STATE_INITIALIZED)) {
int retry = PCIEHPC_CMD_WAIT_RETRY;
/* write the command to the HPC */
pciehpc_reg_put16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL,
control);
/* poll for status completion */
while (retry--) {
/* wait for 10 msec before checking the status */
delay(drv_usectohz(PCIEHPC_CMD_WAIT_TIME));
status = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS);
if (status & PCIE_SLOTSTS_COMMAND_COMPLETED) {
/* clear the status bits */
pciehpc_reg_put16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS,
status);
break;
}
}
return;
}
/* HPC is already initialized */
ASSERT(MUTEX_HELD(&ctrl_p->pciehpc_mutex));
/*
* If previous command is still pending then wait for its
* completion. i.e cv_wait()
*/
while (ctrl_p->slot.command_pending == B_TRUE)
cv_wait(&ctrl_p->slot.cmd_comp_cv, &ctrl_p->pciehpc_mutex);
/*
* Issue the command and wait for Command Completion or
* the 1 sec timeout.
*/
pciehpc_reg_put16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCTL, control);
ctrl_p->slot.command_pending = B_TRUE;
if (cv_timedwait(&ctrl_p->slot.cmd_comp_cv, &ctrl_p->pciehpc_mutex,
ddi_get_lbolt() + SEC_TO_TICK(1)) == -1) {
/* it is a timeout */
PCIEHPC_DEBUG2((CE_NOTE,
"pciehpc_issue_hpc_command: Command Complete"
" interrupt is not received for slot %d\n",
ctrl_p->slot.slotNum));
/* clear the status info in case interrupts are disabled? */
status = pciehpc_reg_get16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS);
if (status & PCIE_SLOTSTS_COMMAND_COMPLETED) {
/* clear the status bits */
pciehpc_reg_put16(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTSTS,
status);
}
}
ctrl_p->slot.command_pending = B_FALSE;
/* wake up any one waiting for issuing another command to HPC */
cv_signal(&ctrl_p->slot.cmd_comp_cv);
}
/*
* pciehcp_attn_btn_handler()
*
* This handles ATTN button pressed event as per the PCI-E 1.1 spec.
*/
static void
pciehpc_attn_btn_handler(pciehpc_t *ctrl_p)
{
hpc_led_state_t power_led_state;
callb_cpr_t cprinfo;
PCIEHPC_DEBUG3((CE_NOTE, "pciehpc_attn_btn_handler: thread started\n"));
CALLB_CPR_INIT(&cprinfo, &ctrl_p->pciehpc_mutex, callb_generic_cpr,
"pciehpc_attn_btn_handler");
mutex_enter(&ctrl_p->pciehpc_mutex);
/* wait for ATTN button event */
cv_wait(&ctrl_p->slot.attn_btn_cv, &ctrl_p->pciehpc_mutex);
while (ctrl_p->slot.attn_btn_thread_exit == B_FALSE) {
if (ctrl_p->slot.attn_btn_pending == B_TRUE) {
/* get the current state of power LED */
power_led_state = pciehpc_get_led_state(ctrl_p, HPC_POWER_LED);
/* Blink the Power LED while we wait for 5 seconds */
pciehpc_set_led_state(ctrl_p, HPC_POWER_LED, HPC_LED_BLINK);
/* wait for 5 seconds before taking any action */
if (cv_timedwait(&ctrl_p->slot.attn_btn_cv,
&ctrl_p->pciehpc_mutex,
ddi_get_lbolt() + SEC_TO_TICK(5)) == -1) {
/*
* It is a time out; make sure the ATTN pending flag is
* still ON before sending the event to HPS framework.
*/
if (ctrl_p->slot.attn_btn_pending == B_TRUE) {
/* send the ATTN button event to HPS framework */
ctrl_p->slot.attn_btn_pending = B_FALSE;
(void) hpc_slot_event_notify(
ctrl_p->slot.slot_handle,
HPC_EVENT_SLOT_ATTN, HPC_EVENT_NORMAL);
}
}
/* restore the power LED state */
pciehpc_set_led_state(ctrl_p, HPC_POWER_LED, power_led_state);
continue;
}
/* wait for another ATTN button event */
cv_wait(&ctrl_p->slot.attn_btn_cv, &ctrl_p->pciehpc_mutex);
}
PCIEHPC_DEBUG3((CE_NOTE, "pciehpc_attn_btn_handler: thread exit\n"));
cv_signal(&ctrl_p->slot.attn_btn_cv);
CALLB_CPR_EXIT(&cprinfo);
thread_exit();
}
/*
* Read/Write access to HPC registers. If platform nexus has non-standard
* HPC access mechanism then regops functions are used to do reads/writes.
*/
uint8_t
pciehpc_reg_get8(pciehpc_t *ctrl_p, uint_t off)
{
PCIEHPC_DEBUG3((CE_NOTE, "read reg8 (offset %x)", off));
if (ctrl_p->regops.get != NULL)
return ((uint8_t)ctrl_p->regops.get(ctrl_p->regops.cookie,
(off_t)off));
else
return (ddi_get8(ctrl_p->cfghdl,
(uint8_t *)(ctrl_p->regs_base + off)));
}
uint16_t
pciehpc_reg_get16(pciehpc_t *ctrl_p, uint_t off)
{
PCIEHPC_DEBUG3((CE_NOTE, "read reg16 (offset %x)", off));
if (ctrl_p->regops.get != NULL)
return ((uint16_t)ctrl_p->regops.get(ctrl_p->regops.cookie,
(off_t)off));
else
return (ddi_get16(ctrl_p->cfghdl,
(uint16_t *)(ctrl_p->regs_base + off)));
}
uint32_t
pciehpc_reg_get32(pciehpc_t *ctrl_p, uint_t off)
{
PCIEHPC_DEBUG3((CE_NOTE, "read reg32 (offset %x)", off));
if (ctrl_p->regops.get != NULL)
return ((uint32_t)ctrl_p->regops.get(ctrl_p->regops.cookie,
(off_t)off));
else
return (ddi_get32(ctrl_p->cfghdl,
(uint32_t *)(ctrl_p->regs_base + off)));
}
void
pciehpc_reg_put8(pciehpc_t *ctrl_p, uint_t off, uint8_t val)
{
PCIEHPC_DEBUG3((CE_NOTE, "write reg8 (offset %x, val %x)",
off, val));
if (ctrl_p->regops.put != NULL)
ctrl_p->regops.put(ctrl_p->regops.cookie, (off_t)off, (uint_t)val);
else
ddi_put8(ctrl_p->cfghdl,
(uint8_t *)(ctrl_p->regs_base + off), val);
}
void
pciehpc_reg_put16(pciehpc_t *ctrl_p, uint_t off, uint16_t val)
{
PCIEHPC_DEBUG3((CE_NOTE, "write reg16 (offset %x, val %x)",
off, val));
if (ctrl_p->regops.put != NULL)
ctrl_p->regops.put(ctrl_p->regops.cookie, (off_t)off, (uint_t)val);
else
ddi_put16(ctrl_p->cfghdl,
(uint16_t *)(ctrl_p->regs_base + off), val);
}
void
pciehpc_reg_put32(pciehpc_t *ctrl_p, uint_t off, uint32_t val)
{
PCIEHPC_DEBUG3((CE_NOTE, "write reg32 (offset %x, val %x)",
off, val));
if (ctrl_p->regops.put != NULL)
ctrl_p->regops.put(ctrl_p->regops.cookie, (off_t)off, (uint_t)val);
else
ddi_put32(ctrl_p->cfghdl,
(uint32_t *)(ctrl_p->regs_base + off), val);
}
static void
pciehpc_dev_info(pciehpc_t *ctrl_p)
{
pci_regspec_t *regspec;
int reglen;
dev_info_t *dip = ctrl_p->dip;
/*
* Check if it is a PCIe fabric hotplug nexus. This is specially
* not so for Rootcomplex nodes supporting PCIe hotplug.
* We save this information so as to implement hardening for
* fabric nodes only via pcie services.
*/
if (pciehpc_pcie_dev(dip, ctrl_p->cfghdl) == DDI_SUCCESS)
ctrl_p->soft_state |= PCIEHPC_SOFT_STATE_PCIE_DEV;
/* Get the device number. */
if (ddi_getlongprop(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS,
"reg", (caddr_t)®spec, ®len) != DDI_SUCCESS) {
return;
}
ctrl_p->bus = PCI_REG_BUS_G(regspec[0].pci_phys_hi);
ctrl_p->dev = PCI_REG_DEV_G(regspec[0].pci_phys_hi);
ctrl_p->func = PCI_REG_FUNC_G(regspec[0].pci_phys_hi);
kmem_free(regspec, reglen);
PCIEHPC_DEBUG3((CE_NOTE, "pciehpc_dev_info: bus=%x, dev=%x, func=%x",
ctrl_p->bus, ctrl_p->dev, ctrl_p->func));
}
/*
* setup slot name/slot-number info.
*/
void
pciehpc_set_slot_name(pciehpc_t *ctrl_p)
{
pciehpc_slot_t *p = &ctrl_p->slot;
uchar_t *slotname_data;
int *slotnum;
uint_t count;
int len;
int invalid_slotnum = 0;
uint32_t slot_capabilities;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, ctrl_p->dip,
DDI_PROP_DONTPASS, "physical-slot#", &slotnum, &count) ==
DDI_PROP_SUCCESS) {
p->slotNum = slotnum[0];
ddi_prop_free(slotnum);
} else {
slot_capabilities = pciehpc_reg_get32(ctrl_p,
ctrl_p->pcie_caps_reg_offset + PCIE_SLOTCAP);
p->slotNum = PCIE_SLOTCAP_PHY_SLOT_NUM(slot_capabilities);
}
if (!p->slotNum) { /* platform may not have initialized it */
PCIEHPC_DEBUG((CE_WARN, "%s#%d: Invalid slot number! ",
ddi_driver_name(ctrl_p->dip),
ddi_get_instance(ctrl_p->dip)));
p->slotNum = pciehpc_reg_get8(ctrl_p, PCI_BCNF_SECBUS);
invalid_slotnum = 1;
}
/*
* construct the slot_name:
* if "slot-names" property exists then use that name
* else if valid slot number exists then it is "pcie<slot-num>".
* else it will be "pcie<sec-bus-number>dev0"
*/
if (ddi_getlongprop(DDI_DEV_T_ANY, ctrl_p->dip, DDI_PROP_DONTPASS,
"slot-names", (caddr_t)&slotname_data,
&len) == DDI_PROP_SUCCESS) {
/*
* Note: for PCI-E slots, the device number is always 0 so the
* first (and only) string is the slot name for this slot.
*/
(void) sprintf(p->slot_info.pci_slot_name,
(char *)slotname_data + 4);
kmem_free(slotname_data, len);
} else {
if (invalid_slotnum)
(void) sprintf(p->slot_info.pci_slot_name, "pcie%ddev0",
p->slotNum);
else
(void) sprintf(p->slot_info.pci_slot_name, "pcie%d",
p->slotNum);
}
}
/*ARGSUSED*/
static int
pciehpc_pcie_dev(dev_info_t *dip, ddi_acc_handle_t handle)
{
/* get parent device's device_type property */
char *device_type;
int rc;
dev_info_t *pdip = ddi_get_parent(dip);
if (ddi_prop_lookup_string(DDI_DEV_T_ANY, pdip,
DDI_PROP_DONTPASS, "device_type", &device_type)
!= DDI_PROP_SUCCESS) {
PCIEHPC_DEBUG2((CE_NOTE, "device_type property missing for "
"%s#%d", ddi_get_name(pdip), ddi_get_instance(pdip)));
return (DDI_FAILURE);
}
PCIEHPC_DEBUG((CE_NOTE, "device_type=<%s>\n", device_type));
rc = DDI_FAILURE;
if (strcmp(device_type, "pciex") == 0)
rc = DDI_SUCCESS;
ddi_prop_free(device_type);
return (rc);
}
#if defined(__sparc)
static void
pciehpc_disable_errors(pciehpc_t *ctrl_p)
{
if (ctrl_p->soft_state & PCIEHPC_SOFT_STATE_PCIE_DEV) {
pcie_disable_errors(ctrl_p->dip, ctrl_p->cfghdl);
PCIEHPC_DEBUG3((CE_NOTE, "%s%d: pciehpc_disable_errors\n",
ddi_driver_name(ctrl_p->dip),
ddi_get_instance(ctrl_p->dip)));
}
}
static void
pciehpc_enable_errors(pciehpc_t *ctrl_p)
{
if (ctrl_p->soft_state & PCIEHPC_SOFT_STATE_PCIE_DEV) {
pcie_enable_errors(ctrl_p->dip, ctrl_p->cfghdl);
PCIEHPC_DEBUG3((CE_NOTE, "%s%d: pciehpc_enable_errors\n",
ddi_driver_name(ctrl_p->dip),
ddi_get_instance(ctrl_p->dip)));
}
}
#endif
|