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
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* ATA disk driver
*
* Handles the standard PCMCIA ATA interface
*
*/
#include <sys/errno.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/user.h>
#include <sys/buf.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <sys/uio.h>
#include <sys/fcntl.h>
#include <sys/cmn_err.h>
#include <sys/kmem.h>
#include <sys/sysmacros.h>
#include <sys/stat.h>
#include <sys/scsi/scsi.h>
#include <sys/fdio.h>
#include <sys/errno.h>
#include <sys/open.h>
#include <sys/varargs.h>
#include <sys/fs/pc_label.h>
#include <sys/hdio.h>
#include <sys/dkio.h>
#include <sys/dktp/dadkio.h>
#include <sys/dklabel.h>
#include <sys/vtoc.h>
#include <sys/types.h>
#include <sys/conf.h>
#include <sys/dditypes.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/dktp/cm.h>
#include <sys/dktp/fdisk.h>
#include <sys/fs/pc_label.h>
#include <sys/pctypes.h>
/*
* PCMCIA and DDI related header files
*/
#include <sys/pccard.h>
#include <sys/pcmcia/pcata.h>
int pcata_debug = 0;
static int pcata_detach(dev_info_t *devi, ddi_detach_cmd_t cmd);
static int pcata_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
static int pcata_att1(dev_info_t *dip, ata_soft_t *softp);
static int pcata_go(ata_unit_t *unitp);
static int pcata_wait(uint32_t port, ushort_t onbits, ushort_t offbits,
ata_soft_t *softp);
static int pcata_wait1(uint32_t port, ushort_t onbits, ushort_t offbits,
int interval, ata_soft_t *softp);
static void pcata_wait_complete(ata_soft_t *softp);
static uchar_t pcata_drive_type(ata_soft_t *softp, ushort_t *secbuf);
static int pcata_setpar(int drive, int heads, int sectors, ata_soft_t *softp);
static int pcata_dump(dev_t dev, caddr_t addr, daddr_t blkno, int nblk);
static int pcata_print(dev_t dev, char *str);
static int pcata_rdrw(dev_t dev, struct uio *uio, int flag);
static int pcata_read(dev_t dev, struct uio *uio, cred_t *cred_p);
static int pcata_write(dev_t dev, struct uio *uio, cred_t *cred_p);
#ifdef ATA_DEBUG
static void pcata_print_sttflag(int svalue);
#endif
static void pcata_clear_queues(ata_unit_t *unitp);
static void pcata_nack_packet(struct ata_cmpkt *pktp);
static void pcata_iosetup(ata_unit_t *unitp, struct ata_cmpkt *pktp);
static int pcata_send_data(ata_unit_t *unitp, int count);
static int pcata_get_data(ata_unit_t *unitp, int count);
struct cb_ops pcata_cb_ops = {
pcata_open, /* driver open routine */
pcata_close, /* driver close routine */
pcata_strategy, /* driver strategy routine */
pcata_print, /* driver print routine */
pcata_dump, /* driver dump routine */
pcata_read, /* driver read routine */
pcata_write, /* driver write routine */
pcata_ioctl, /* driver ioctl routine */
nodev, /* driver devmap routine */
nodev, /* driver mmap routine */
nodev, /* driver segmap routine */
nochpoll, /* driver chpoll routine */
pcata_prop_op, /* driver prop_op routine */
0, /* driver cb_str - STREAMS only */
D_NEW | D_MTSAFE, /* driver compatibility flag */
};
static struct dev_ops ata_ops = {
DEVO_REV, /* devo_rev, */
0, /* refcnt */
pcata_getinfo, /* info */
nulldev, /* identify */
nulldev, /* probe */
pcata_attach, /* attach */
pcata_detach, /* detach */
nulldev, /* reset */
&pcata_cb_ops, /* driver operations */
0
};
void *pcata_soft = NULL;
#include <sys/modctl.h>
extern struct mod_ops mod_driverops;
static struct modldrv modldrv = {
&mod_driverops, /* Type of module. This one is a driver */
"PCMCIA ATA disk controller %I%",
&ata_ops, /* driver ops */
};
static struct modlinkage modlinkage = {
MODREV_1, (void *)&modldrv, NULL
};
int
_init(void)
{
int status;
status = mod_install(&modlinkage);
if (status)
return (status);
status = ddi_soft_state_init(&pcata_soft, sizeof (ata_soft_t), 1);
return (status);
}
int
_fini(void)
{
int status;
status = mod_remove(&modlinkage);
if (!status)
ddi_soft_state_fini(&pcata_soft);
return (status);
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
static int
pcata_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
{
int instance = ddi_get_instance(dip);
ata_soft_t *softp;
int ret;
/* resume from a checkpoint */
if (cmd == DDI_RESUME)
return (DDI_SUCCESS);
if (cmd != DDI_ATTACH) {
#ifdef ATA_DEBUG
cmn_err(CE_CONT, "_attach returning FAILURE\n");
#endif
return (DDI_FAILURE);
}
/* Allocate soft state associated with this instance. */
ret = ddi_soft_state_zalloc(pcata_soft, ddi_get_instance(dip));
if (ret != DDI_SUCCESS) {
#ifdef ATA_DEBUG
cmn_err(CE_CONT, "_attach: Unable to alloc state\n");
#endif
return (DDI_FAILURE);
}
softp = ddi_get_soft_state(pcata_soft, instance);
#ifdef ATA_DEBUG
if (pcata_debug & DINIT)
cmn_err(CE_CONT, "_attach softp=%p\n", (void *)softp);
#endif
softp->dip = dip;
softp->instance = instance;
softp->ab_dip = dip;
softp->crashbuf = getrbuf(KM_SLEEP);
softp->flags = 0;
softp->card_state = 0;
softp->intr_pending = 0;
softp->softint_pending = 0;
softp->write_in_progress = 0;
softp->blk_open = 0;
softp->chr_open = 0;
softp->ejected_while_mounted = 0;
bzero(softp->lyr_open, sizeof (softp->lyr_open[NUM_PARTS]));
/*
* Initialize to 0 until it is incremented in pcram_check_media
*/
softp->checkmedia_flag = 0;
softp->ejected_media_flag = 0;
softp->media_state = DKIO_NONE;
/*
* if attach fails, Solaris won't call detach
* so we call detach here to release all flagged resources
*/
ret = pcata_att1(dip, softp);
if (ret == DDI_FAILURE) {
(void) pcata_detach(dip, DDI_DETACH);
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static int
pcata_att1(dev_info_t *dip, ata_soft_t *softp)
{
int ret;
client_reg_t client_reg;
sockmask_t sockmask;
map_log_socket_t map_log_socket;
cs_ddi_info_t cs_ddi_info;
get_status_t get_status;
/*
* create ata_mutex
*/
ret = ddi_get_soft_iblock_cookie(dip, DDI_SOFTINT_MED,
&softp->soft_blk_cookie);
if (ret != DDI_SUCCESS) {
#ifdef ATA_DEBUG
cmn_err(CE_CONT, "_attach: unable to get iblock cookie\n");
#endif
return (ret);
}
/*
* Setup the mutexii and condition variables.
* Initialize the mutex that protects the ATA registers.
*/
mutex_init(&softp->ata_mutex, NULL, MUTEX_DRIVER,
(void *)(softp->soft_blk_cookie));
mutex_init(&softp->label_mutex, NULL, MUTEX_DRIVER, NULL);
cv_init(&softp->readywait_cv, NULL, CV_DRIVER, NULL);
/* for DKIOCSTATE ioctl() */
cv_init(&softp->condvar_mediastate, NULL, CV_DRIVER, NULL);
softp->flags |= PCATA_DIDLOCKS;
/*
* link in soft interrupt
*/
ret = ddi_add_softintr(dip, DDI_SOFTINT_MED, &softp->softint_id,
NULL, NULL, pcata_intr, (caddr_t)softp);
if (ret != DDI_SUCCESS) {
#ifdef ATA_DEBUG
cmn_err(CE_CONT, "_attach: unable to get soft interrupt\n");
#endif
return (DDI_FAILURE);
}
softp->flags |= PCATA_SOFTINTROK;
/*
* Register with Card Services
*/
client_reg.Attributes =
INFO_IO_CLIENT | INFO_CARD_SHARE | INFO_CARD_EXCL;
client_reg.EventMask =
CS_EVENT_CARD_INSERTION |
CS_EVENT_CARD_REMOVAL |
CS_EVENT_CARD_REMOVAL_LOWP |
CS_EVENT_PM_RESUME |
CS_EVENT_CLIENT_INFO |
CS_EVENT_PM_SUSPEND |
CS_EVENT_REGISTRATION_COMPLETE;
client_reg.event_handler = (csfunction_t *)pcata_event;
client_reg.event_callback_args.client_data = softp;
client_reg.Version = _VERSION(2, 1);
client_reg.dip = dip;
(void) strcpy(client_reg.driver_name, pcata_name);
ret = csx_RegisterClient(&softp->client_handle, &client_reg);
if (ret != CS_SUCCESS) {
#ifdef ATA_DEBUG
cmn_err(CE_CONT, "_attach RegisterClient failed %s\n",
pcata_CS_etext(ret));
#endif
return (DDI_FAILURE);
}
mutex_init(&softp->event_hilock, NULL, MUTEX_DRIVER,
*(client_reg.iblk_cookie));
softp->flags |= PCATA_REGCLIENT;
/*
* Get logical socket number and store in softp struct
*/
ret = csx_MapLogSocket(softp->client_handle, &map_log_socket);
if (ret != CS_SUCCESS) {
#ifdef ATA_DEBUG
cmn_err(CE_CONT, "_attach: MapLogSocket failed %s\n",
pcata_CS_etext(ret));
#endif
return (DDI_FAILURE);
}
softp->sn = map_log_socket.PhySocket;
/*
*
*/
cs_ddi_info.Socket = softp->sn;
cs_ddi_info.driver_name = pcata_name;
cs_ddi_info.dip = dip;
cs_ddi_info.instance = softp->instance;
if ((ret = csx_CS_DDI_Info(&cs_ddi_info)) != CS_SUCCESS) {
#ifdef ATA_DEBUG
cmn_err(CE_CONT, "_attach: socket %d CS_DDI_Info failed %s\n",
softp->sn, pcata_CS_etext(ret));
#endif
return (DDI_FAILURE);
}
/*
* After the RequestSocketMask call, we start receiving events
*/
sockmask.EventMask = CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL;
ret = csx_RequestSocketMask(softp->client_handle, &sockmask);
if (ret != CS_SUCCESS) {
#ifdef ATA_DEBUG
cmn_err(CE_CONT, "_attach: RequestSocketMask failed %s\n",
pcata_CS_etext(ret));
#endif
return (DDI_FAILURE);
}
softp->flags |= PCATA_REQSOCKMASK;
/*
* We may not get the CARD_READY event
* until after we leave this function.
*/
mutex_enter(&softp->event_hilock);
softp->card_state |= PCATA_READY_WAIT;
mutex_exit(&softp->event_hilock);
(void) csx_GetStatus(softp->client_handle, &get_status);
if (get_status.raw_CardState & CS_STATUS_CARD_INSERTED) {
/* wait for drive to be initialized */
(void) pcata_readywait(softp);
if ((softp->card_state & PCATA_CARD_INSERTED) == 0 ||
(softp->flags & PCATA_READY) == 0) {
mutex_enter(&softp->ata_mutex);
mutex_enter(&softp->event_hilock);
softp->card_state &= ~PCATA_READY_WAIT;
mutex_exit(&softp->event_hilock);
mutex_exit(&softp->ata_mutex);
}
}
/*
* Wait for minor node creation before returning
*/
pcata_minor_wait(softp);
/*
* print banner to announce device
*/
ddi_report_dev(dip);
return (DDI_SUCCESS);
}
static int
pcata_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
{
int instance = ddi_get_instance(devi);
ata_soft_t *softp;
int ret;
if (cmd == DDI_SUSPEND)
return (DDI_SUCCESS);
if (cmd != DDI_DETACH)
return (DDI_FAILURE);
softp = ddi_get_soft_state(pcata_soft, instance);
/*
* Call the card_removal routine to do any final card cleanup
*/
if (CARD_PRESENT_VALID(softp)) {
(void) pcata_card_removal(softp, CS_EVENT_PRI_LOW);
}
/*
* Release our socket mask - note that we can't do much
* if we fail these calls other than to note that
* the system will probably panic shortly. Perhaps
* we should fail the detach in the case where these
* CS calls fail?
*/
if (softp->flags & PCATA_REQSOCKMASK) {
release_socket_mask_t rsm;
ret = csx_ReleaseSocketMask(softp->client_handle, &rsm);
if (ret != CS_SUCCESS) {
#ifdef ATA_DEBUG
cmn_err(CE_CONT, "_detach "
"ReleaseSocketMask failed %s\n",
pcata_CS_etext(ret));
#endif
}
}
/*
* Deregister with Card Services - we will stop getting
* events at this point.
*/
if (softp->flags & PCATA_REGCLIENT) {
ret = csx_DeregisterClient(softp->client_handle);
if (ret != CS_SUCCESS) {
#ifdef ATA_DEBUG
cmn_err(CE_CONT, "_detach: "
"DeregisterClient failed %s\n",
pcata_CS_etext(ret));
#endif
return (DDI_FAILURE);
}
softp->flags &= ~PCATA_REGCLIENT;
}
/* unregister the softintrrupt handler */
if (softp->flags & PCATA_SOFTINTROK) {
ddi_remove_softintr(softp->softint_id);
softp->flags &= ~PCATA_SOFTINTROK;
}
if (softp->flags & PCATA_DIDLOCKS) {
/*
* XXX/lcl make sure no threads are blocked
*/
mutex_destroy(&softp->ata_mutex);
mutex_destroy(&softp->event_hilock);
mutex_destroy(&softp->label_mutex);
cv_destroy(&softp->readywait_cv);
/* for DKIOCSTATE ioctl() */
cv_destroy(&softp->condvar_mediastate);
softp->flags &= ~PCATA_DIDLOCKS;
}
/* Free various structures and memory here. */
if (softp && softp->crashbuf)
freerbuf(softp->crashbuf);
/* Free the soft state structure here */
ddi_soft_state_free(pcata_soft, instance);
#ifdef ATA_DEBUG
if (pcata_debug & DPCM)
cmn_err(CE_NOTE, "successful detach\n");
#endif
return (DDI_SUCCESS);
}
/*
* Common controller object interface
*/
/*
* initiate a new I/O request
* either start it or add it to the request queue
*/
int
pcata_start(ata_unit_t *unitp, buf_t *bp, int blkno)
{
ata_soft_t *softp = unitp->a_blkp;
struct ata_cmpkt *pktp;
int ret;
int kf = 0;
ASSERT(mutex_owned(&softp->ata_mutex));
#ifdef ATA_DEBUG
if (pcata_debug & DENT) {
cmn_err(CE_CONT, "_start unitp=%p, bp=%p bp->b_private=%p\n",
(void *)unitp,
(void *)bp,
bp->b_private);
}
#endif
if (!CARD_PRESENT_VALID(softp))
return (CTL_SEND_FAILURE);
/* XXX/lcl why is this different from CARD_PRESENT_VALID */
if (softp->ab_status_flag & ATA_OFFLINE) {
return (CTL_SEND_FAILURE);
}
pktp = (struct ata_cmpkt *)kmem_zalloc(sizeof (*pktp), kf);
if (!pktp) {
cmn_err(CE_NOTE, "_start kmem_zalloc failed\n");
return (CTL_SEND_FAILURE);
}
#ifdef ATA_DEBUG
if (pcata_debug & DENT)
cmn_err(CE_CONT, "_start pktp=%p\n", (void *)pktp);
#endif
if ((bp->b_flags & B_PAGEIO) || (bp->b_flags & B_PHYS))
bp_mapin(bp);
pktp->ac_bytes_per_block = unitp->au_bytes_per_block;
pktp->ac_start_v_addr = bp->b_un.b_addr; /* xfer address */
pktp->cp_bytexfer = bp->b_bcount;
pktp->cp_bp = bp;
pktp->cp_ctl_private = unitp;
pktp->cp_srtsec = blkno;
if (bp->b_flags & B_READ) {
pktp->ac_direction = AT_IN;
pktp->ac_cdb = DCMD_READ;
} else {
pktp->ac_direction = AT_OUT;
pktp->ac_cdb = DCMD_WRITE;
}
/*
* b_private is set to 0xBEE by pcata_buf_setup
* which is called by an ioctl DIOCTL_RWCMD with a subcommand
* of either DADKIO_RWCMD_READ or DADKIO_RWCMD_WRITE
*
* these commands are used to do I/O through the IOCTL interface
*
* b_back contains a pointer to the ioctl packet struct (dadkio_rwcmd)
*/
if (bp->b_private == (void *)0xBEE)
pktp->cp_passthru = bp->b_back;
#ifdef ATA_DEBUG
if (pcata_debug & DIO) {
cmn_err(CE_CONT, "passthru command seen: 0x%p\n",
pktp->cp_passthru);
}
#endif
pcata_iosetup(unitp, pktp); /* fill a packet */
pktp->pkt_forw = 0;
#ifdef ATA_DEBUG
if (pcata_debug & DIO) {
cmn_err(CE_CONT, "_start: active: %c head: %c\n",
(softp->ab_active == NULL ? 'N' : 'Y'),
(softp->ab_head == NULL ? 'N' : 'Y'));
}
#endif
if (softp->ab_active == NULL) {
/*
* The controller is idle.
* Put the packet in ab_active....
*/
softp->ab_active = pktp;
/*
* ... and start it off
*/
ret = PCATA_GO_RETRY;
while (ret == PCATA_GO_RETRY) {
ret = pcata_go(unitp);
}
if (ret == DDI_FAILURE) {
cmn_err(CE_NOTE, "start_cmd failure \n");
softp->ab_active = NULL;
return (CTL_SEND_FAILURE);
}
} else {
/*
* the controller is busy now so put the packet
* on ab_head or ab_last.
*/
if (softp->ab_head == NULL)
softp->ab_head = pktp;
else
softp->ab_last->pkt_forw = pktp;
softp->ab_last = pktp;
}
return (CTL_SEND_SUCCESS);
}
/*
* initiate I/O for packet linked on ab_active
*/
static int
pcata_go(ata_unit_t *unitp)
{
ata_soft_t *softp = unitp->a_blkp;
struct ata_cmpkt *pktp = softp->ab_active;
uint32_t nbytes;
uint32_t start_sec;
uint32_t cyl;
uint32_t resid;
uchar_t head;
uchar_t drvheads;
uchar_t drvsectors;
uchar_t ac_devctl;
uchar_t ac_sec;
uchar_t ac_count;
uchar_t ac_lwcyl;
uchar_t ac_hicyl;
uchar_t ac_hd;
ASSERT(mutex_owned(&softp->ata_mutex));
if (pktp == NULL)
return (DDI_SUCCESS);
if (!CARD_PRESENT_VALID(softp)) {
pktp->ac_scb = DERR_ABORT;
pktp->cp_reason = CPS_CHKERR;
return (DDI_FAILURE);
}
#ifdef ATA_DEBUG
if (pcata_debug & DENT) {
cmn_err(CE_CONT, "_go (%p) altstatus %x error %x\n",
(void *)unitp,
csx_Get8(softp->handle, AT_ALTSTATUS),
csx_Get8(softp->handle, AT_ERROR));
cmn_err(CE_CONT, "_go handle=%p\n", softp->handle);
}
#endif
/*
* calculate drive address based on pktp->cp_srtsec
*/
start_sec = pktp->cp_srtsec;
drvheads = unitp->au_hd;
drvsectors = unitp->au_sec;
resid = start_sec / drvsectors;
head = resid % drvheads;
cyl = resid / drvheads;
nbytes = min(pktp->cp_resid, pktp->ac_bytes_per_block);
ac_count = (nbytes >> SCTRSHFT);
ac_devctl = unitp->au_ctl_bits;
ac_sec = (start_sec % drvsectors) + 1;
ac_hd = head | unitp->au_drive_bits;
ac_lwcyl = cyl;
ac_hicyl = (cyl >> 8);
#ifdef ATA_DEBUG
if (pcata_debug & DIO) {
cmn_err(CE_CONT,
"_go %s at lba=%d (%uc %uh %us) "
"%d sectors cmd=%x ctl=%x\n",
(pktp->ac_direction == AT_OUT) ? "WT" : "RD",
start_sec, cyl, head, ac_sec,
ac_count,
pktp->ac_cmd, ac_devctl);
}
#endif
if (pcata_wait(AT_ALTSTATUS, ATS_DRDY, ATS_BSY, softp))
return (DDI_FAILURE);
pcata_wait_complete(softp);
PCIDE_OUTB(softp->handle, AT_DEVCTL, ac_devctl);
PCIDE_OUTB(softp->handle, AT_SECT, ac_sec);
PCIDE_OUTB(softp->handle, AT_COUNT, ac_count);
PCIDE_OUTB(softp->handle, AT_LCYL, ac_lwcyl);
PCIDE_OUTB(softp->handle, AT_HCYL, ac_hicyl);
PCIDE_OUTB(softp->handle, AT_DRVHD, ac_hd);
/*
* the command should make the controller status show BSY
* the ISR intr_hi will not record status while the controller is BSY
* therefore set interrupt expected state now
* the next time we receive an interrupt and the controller is not BSY
* the ISR will do the right thing
*/
mutex_enter(&softp->hi_mutex);
softp->intr_pending++;
if (pktp->ac_direction == AT_OUT)
softp->write_in_progress++;
csx_Put8(softp->handle, AT_CMD, pktp->ac_cmd);
mutex_exit(&softp->hi_mutex);
/*
* If there's data to go along with the command, send it now.
*/
if (pktp->ac_direction == AT_OUT) {
if (pcata_send_data(unitp, nbytes) == DDI_FAILURE) {
if (pktp->cp_retry >= RETRY_CNT) {
pcata_clear_queues(unitp);
return (DDI_FAILURE);
} else {
pktp->cp_retry++;
cmn_err(CE_CONT, "_go: write failure,"
" retry=%d \n", pktp->cp_retry);
cmn_err(CE_CONT,
"_go at lba=%d (%uc %uh %us) "
"%d sectors cmd=%x ctl=%x \n",
start_sec, cyl, head, ac_sec,
ac_count,
pktp->ac_cmd, ac_devctl);
return (PCATA_GO_RETRY);
}
}
}
return (DDI_SUCCESS);
}
/*
* return value
* success means go on o next block
* failure means continue with current block
*/
static void
pcata_iocmpl(ata_soft_t *softp)
{
struct ata_cmpkt *pktp;
ata_unit_t *unitp;
int nbytes;
int ret;
uchar_t status;
uchar_t error;
ASSERT(mutex_owned(&softp->ata_mutex));
if (!CARD_PRESENT_VALID(softp)) {
cmn_err(CE_CONT, "?_iocmpl Device not present\n");
return;
}
pktp = softp->ab_active;
error = pktp->ac_error;
status = pktp->ac_status;
unitp = (ata_unit_t *)pktp->cp_ctl_private;
/*
* If there was an error, quit now
* XXX/lcl no retry is attempted?
*/
if ((status & ATS_ERR) || (error & ATE_ABORT)) {
#ifdef ATA_DEBUG
if (pcata_debug & DIO)
cmn_err(CE_CONT,
"_iocmpl I/O error status=%04x error=%04x\n",
status,
error);
#endif
pktp->cp_reason = CPS_CHKERR;
return;
}
nbytes = min(pktp->cp_resid, pktp->ac_bytes_per_block);
if (pktp->ac_direction == AT_IN) {
/*
* do the read of the block
*/
ret = pcata_get_data(unitp, nbytes);
if (ret == DDI_FAILURE) {
/*
* If the controller never presented the data
* and the error bit isn't set,
* there's a real problem. Kill it now.
*/
pcata_clear_queues(unitp);
return;
}
}
/*
* update counts...
*/
pktp->ac_v_addr += nbytes;
pktp->cp_resid -= nbytes;
pktp->cp_reason = CPS_SUCCESS;
pktp->cp_srtsec += (nbytes >> SCTRSHFT);
/* If last command was a GET_DEFECTS delay a bit */
if (pktp->ac_cmd == ATC_READDEFECTS)
drv_usecwait(1000);
}
int
pcata_intr_hi(ata_soft_t *softp)
{
/*
* In ata there is no hardware support to tell if the interrupt
* belongs to ata or not. So no checks necessary here. Later
* will check the buffer and see if we have started a transaction.
*/
int rval = DDI_INTR_UNCLAIMED;
struct ata_cmpkt *pktp;
uchar_t status;
uchar_t error;
#ifdef ATA_DEBUG
if (pcata_debug & DENT) {
cmn_err(CE_CONT,
"_intr_hi sn=%d status=%x intr_pending=%d "
"softint_pending=%d wr_in_prog=%d\n",
softp->sn, csx_Get8(softp->handle, AT_ALTSTATUS),
softp->intr_pending, softp->softint_pending,
softp->write_in_progress);
}
#endif
mutex_enter(&softp->hi_mutex);
/*
* this test is not redundant (don't remove it)
* it is part of card removal processing
* and prevents losing interrupt threads
*/
if (!CARD_PRESENT_VALID(softp)) {
mutex_exit(&softp->hi_mutex);
return (rval);
}
status = csx_Get8(softp->handle, AT_ALTSTATUS);
/*
* this is a shared interrupt
* if the controller is NOT busy,
* and an interrupt is expected
*/
if ((status & ATS_ERR) &&
((status & ATS_BSY) == 0) &&
(softp->intr_pending > 0)) {
cmn_err(CE_CONT,
"?_intr_hi sn=%d status=%x\n",
softp->sn, status);
/* handle aborted commands */
error = csx_Get8(softp->handle, AT_ERROR);
if ((error & ATE_ABORT) &&
(softp->write_in_progress > 0)) {
softp->write_in_progress = 0;
}
}
if ((status & ATS_BSY) == 0 &&
(softp->write_in_progress == 0) &&
(softp->intr_pending > 0)) {
/*
* Read the status register,
* this clears an interrupt from the ata device
*/
status = csx_Get8(softp->handle, AT_STATUS);
error = csx_Get8(softp->handle, AT_ERROR);
rval = DDI_INTR_CLAIMED;
softp->intr_pending--;
/*
* Make sure the interrupt is cleared, occasionally it is not
* cleared by the first status read.
*/
status = csx_Get8(softp->handle, AT_STATUS);
/* put the error status in the right place */
if ((pktp = softp->ab_active) != 0) {
pktp->ac_error = error;
pktp->ac_status = status;
}
}
mutex_exit(&softp->hi_mutex);
#ifdef ATA_DEBUG
if (pcata_debug & DENT)
cmn_err(CE_CONT,
"_intr_hi status=%x error=%x claimed=%d pending=%d\n",
status, error,
(rval == DDI_INTR_CLAIMED),
softp->intr_pending);
#endif
if ((rval == DDI_INTR_CLAIMED) &&
(softp->ab_active != NULL)) {
mutex_enter(&softp->hi_mutex);
softp->softint_pending++;
mutex_exit(&softp->hi_mutex);
ddi_trigger_softintr(softp->softint_id);
}
return (rval);
}
uint32_t
pcata_intr(char *parm)
{
ata_soft_t *softp = (ata_soft_t *)parm;
ata_unit_t *unitp;
struct ata_cmpkt *pktp;
buf_t *bp;
uint32_t nbytes;
uint32_t start_sec;
uint32_t cyl;
uint32_t resid;
uchar_t head;
uchar_t drvheads;
uchar_t drvsectors;
uchar_t ac_devctl;
uchar_t ac_sec;
uchar_t ac_count;
int ret;
#ifdef ATA_DEBUG
if (pcata_debug & DENT) {
cmn_err(CE_CONT, "_intr entry (%p) sn=%d softint_pending=%d\n",
(void *)softp, softp->sn, softp->softint_pending);
}
#endif
if (softp->softint_pending == 0) {
return (DDI_INTR_UNCLAIMED);
}
mutex_enter(&softp->ata_mutex);
if (softp->ab_active == NULL) {
cmn_err(CE_CONT, "?_intr No outstanding I/O\n");
goto done;
}
/* perform I/O completion */
pcata_iocmpl(softp);
if (!CARD_PRESENT_VALID(softp))
goto done;
/*
* if packet is done (either errors or all bytes transfered)
* pktp points to current packet
* ab_active is cleared
* else
* pktp is null
* ab_active is unchanged
*/
pktp = softp->ab_active;
if (pktp != NULL) {
if (pktp->cp_resid == 0 || pktp->cp_reason != CPS_SUCCESS) {
#ifdef ATA_DEBUG
if (pcata_debug & DENT) {
cmn_err(CE_CONT, "_intr retry=%d reason=%d"
" CPS_SUCCESS=%d pkpt=%p cp_resid = %d\n",
pktp->cp_retry, pktp->cp_reason,
CPS_SUCCESS, (void *)pktp,
pktp->cp_resid);
}
#endif
if ((pktp->cp_retry < RETRY_CNT) &&
(pktp->cp_reason != CPS_SUCCESS)) {
pktp->cp_retry++;
unitp = softp->ab_active->cp_ctl_private;
/*
* calculate drive address based on
* pktp->cp_srtsec
*/
start_sec = pktp->cp_srtsec;
drvheads = unitp->au_hd;
drvsectors = unitp->au_sec;
resid = start_sec / drvsectors;
head = resid % drvheads;
cyl = resid / drvheads;
nbytes = min(pktp->cp_resid,
pktp->ac_bytes_per_block);
ac_count = (nbytes >> SCTRSHFT);
ac_devctl = unitp->au_ctl_bits;
ac_sec = (start_sec % drvsectors) + 1;
cmn_err(CE_CONT, "_intr I/O failure,"
" retry %d\n", pktp->cp_retry);
cmn_err(CE_CONT,
"_intr %s at lba=%d (%uc %uh %us) "
"%d sectors cmd=%x ctl=%x\n",
(pktp->ac_direction == AT_OUT) ?
"write" : "read",
start_sec, cyl, head, ac_sec,
ac_count,
pktp->ac_cmd, ac_devctl);
pktp = 0;
} else {
/* I/O is complete or an error has occured */
softp->ab_active = NULL;
}
} else {
/* I/O is still in progress */
pktp = 0;
}
}
/*
* packet which caused this interrupt is now complete
*/
if (pktp) {
if ((pktp->ac_status & ATS_ERR) || (pktp->ac_error)) {
bioerror(pktp->cp_bp, EIO);
#ifdef ATA_DEBUG
cmn_err(CE_NOTE, "_intr ATA ERROR status=%x error=%x\n",
pktp->ac_status, pktp->ac_error);
#endif
}
bp = pktp->cp_bp;
bp->b_resid = bp->b_bcount - pktp->cp_bytexfer;
/* release the thread for the I/O just completed */
biodone(bp);
kmem_free((void *)pktp, sizeof (*pktp));
}
/* if ab_active is NULL attempt to dequeue next I/O request */
if (softp->ab_active == NULL && softp->ab_head != NULL) {
softp->ab_active = softp->ab_head;
softp->ab_head = softp->ab_head->pkt_forw;
#ifdef ATA_DEBUG
if (pcata_debug & DIO) {
cmn_err(CE_CONT,
"_start_next_cmd current:%p head:%p\n",
(void *)softp->ab_active,
(void *)softp->ab_head);
}
#endif
}
mutex_enter(&softp->hi_mutex);
softp->softint_pending--;
mutex_exit(&softp->hi_mutex);
/* if ab_active is not NULL, attempt to initiate I/O */
if (softp->ab_active != NULL) {
unitp = softp->ab_active->cp_ctl_private;
ret = PCATA_GO_RETRY;
while (ret == PCATA_GO_RETRY) {
ret = pcata_go(unitp);
}
}
goto exit;
done:
mutex_enter(&softp->hi_mutex);
softp->softint_pending--;
mutex_exit(&softp->hi_mutex);
exit:
mutex_exit(&softp->ata_mutex);
#ifdef ATA_DEBUG
if (pcata_debug & DENT)
cmn_err(CE_CONT, "_intr exit (%p)\n", (void *)softp);
#endif
return (DDI_INTR_CLAIMED);
}
/*
* XXX/lcl need determine if all drives or a single drive is to be cleared
* if all drives then eliminate tests for pktp->cp_ctl_private == unitp
* if single drive then examine usage of flag ATA_OFFLINE
*/
static void
pcata_clear_queues(ata_unit_t *unitp)
{
ata_soft_t *softp = unitp->a_blkp;
struct ata_cmpkt *pktp;
buf_t *bp;
ASSERT(mutex_owned(&softp->ata_mutex));
#ifdef ATA_DEBUG
if (pcata_debug & DENT) {
cmn_err(CE_CONT, "_clear_queues (%p)\n", (void *)unitp);
}
#endif
/*
* nack the active request
*/
softp->ab_status_flag |= ATA_OFFLINE;
pktp = softp->ab_active;
if (pktp && pktp->cp_ctl_private == unitp)
pcata_nack_packet(pktp);
/*
* now nack all queued requests
*/
for (pktp = softp->ab_head; pktp; pktp = pktp->pkt_forw) {
bp = pktp->cp_bp;
if (bp && ((bp->b_flags & B_DONE) == 0)) {
if ((pktp->ac_status & ATS_ERR) || (pktp->ac_error)) {
bioerror(bp, EIO);
}
/* release the thread for the I/O */
biodone(bp);
}
if (pktp->cp_ctl_private == unitp)
pcata_nack_packet(pktp);
}
}
static void
pcata_nack_packet(struct ata_cmpkt *pktp)
{
#ifdef ATA_DEBUG
if (pcata_debug & DENT)
cmn_err(CE_CONT, "pcata_nack_packet (%p)\n", (void *)pktp);
#endif
if (pktp != NULL) {
pktp->cp_reason = CPS_CHKERR;
pktp->ac_scb = DERR_ABORT;
}
}
/*
* pcata_wait -- wait for a register of a controller to achieve a
* specific state. Arguments are a mask of bits we care about,
* and two sub-masks. To return normally, all the bits in the
* first sub-mask must be ON, all the bits in the second sub-
* mask must be OFF. If 5 seconds pass without the controller
* achieving the desired bit configuration, we return 1, else
* 0.
*/
static int
pcata_wait(uint32_t port, ushort_t onbits, ushort_t offbits, ata_soft_t *softp)
{
register int i;
register ushort_t maskval;
int ival = csx_Get8(softp->handle, port);
for (i = 400000; i && (CARD_PRESENT_VALID(softp)); i--) {
maskval = csx_Get8(softp->handle, port);
if (((maskval & onbits) == onbits) &&
((maskval & offbits) == 0))
return (0);
drv_usecwait(10);
}
#ifdef ATA_DEBUG
cmn_err(CE_CONT, "_wait timeout: "
"sn=%d port=%x on: 0x%x off: 0x%x ival: 0x%x eval: 0x%x\n",
softp->sn, port, onbits, offbits, ival, maskval);
#endif
return (1);
}
/*
* Similar to pcata_wait but the timeout is much shorter. It is only used
* during initialization when long delays are noticable.
*/
static int
pcata_wait1(uint32_t port, ushort_t onbits, ushort_t offbits, int interval,
ata_soft_t *softp)
{
register int i;
register ushort_t maskval;
for (i = interval; i && (CARD_PRESENT_VALID(softp)); i--) {
maskval = csx_Get8(softp->handle, port);
if (((maskval & onbits) == onbits) &&
((maskval & offbits) == 0))
return (0);
drv_usecwait(10);
}
return (1);
}
/*
* Wait until the command interrupt has been serviced before starting
* another command.
*
*/
static void
pcata_wait_complete(ata_soft_t *softp)
{
int i;
for (i = 0; i < PCATA_WAIT_CNT &&
((softp->intr_pending > 0) || (softp->softint_pending > 0)); i++) {
drv_usecwait(10);
}
}
static int
pcata_send_data(ata_unit_t *unitp, int count)
{
ata_soft_t *softp = unitp->a_blkp;
struct ata_cmpkt *pktp = unitp->a_blkp->ab_active;
#ifdef ATA_DEBUG
if (pcata_debug & DENT) {
cmn_err(CE_CONT, "_send_data (%p, %x)\n",
(void *)unitp, count);
}
#endif
if (pcata_wait(AT_ALTSTATUS, ATS_DRQ, 0, softp)) {
cmn_err(CE_CONT, "_send_data - NOT READY\n");
mutex_enter(&softp->hi_mutex);
softp->write_in_progress = 0;
mutex_exit(&softp->hi_mutex);
return (DDI_FAILURE);
}
/*
* copy count bytes from pktp->v_addr to the data port
*/
#ifdef ATA_DEBUG
if (pcata_debug & DIO) {
cmn_err(CE_CONT, "_send_data: port=%x addr=0x%p count=0x%x\n",
unitp->a_blkp->ab_data,
(void *)pktp->ac_v_addr,
count);
}
#endif
if (!CARD_PRESENT_VALID(softp)) {
mutex_enter(&softp->hi_mutex);
softp->write_in_progress = 0;
mutex_exit(&softp->hi_mutex);
return (DDI_FAILURE);
}
mutex_enter(&softp->hi_mutex);
csx_RepPut16(softp->handle, (ushort_t *)pktp->ac_v_addr, AT_DATA,
(count >> 1), DDI_DEV_NO_AUTOINCR);
if (softp->write_in_progress > 0)
softp->write_in_progress--;
mutex_exit(&softp->hi_mutex);
#ifdef ATA_DEBUG
if (pcata_debug & DIO) {
cmn_err(CE_CONT, "_send_data: ");
pcata_print_sttflag(csx_Get8(softp->handle, AT_ALTSTATUS));
}
#endif
return (DDI_SUCCESS);
}
static int
pcata_get_data(ata_unit_t *unitp, int count)
{
ata_soft_t *softp = unitp->a_blkp;
register struct ata_cmpkt *pktp = unitp->a_blkp->ab_active;
if (pcata_wait(AT_ALTSTATUS, ATS_DRQ, 0, softp)) {
cmn_err(CE_CONT, "_get_data - NOT READY\n");
return (DDI_FAILURE);
}
/*
* copy count bytes from the data port to pktp->ac_v_addr
*/
#ifdef ATA_DEBUG
if (pcata_debug & DIO) {
cmn_err(CE_CONT, "_get_data port=%x addr=0x%p count=0x%x\n",
unitp->a_blkp->ab_data, (void *)pktp->ac_v_addr, count);
}
#endif
if (!CARD_PRESENT_VALID(softp))
return (DDI_FAILURE);
csx_RepGet8(softp->handle, (uchar_t *)pktp->ac_v_addr,
AT_DATA, count, DDI_DEV_NO_AUTOINCR);
#ifdef ATA_DEBUG
if (pcata_debug & DIO)
cmn_err(CE_CONT, "_get_data complete\n");
#endif
return (DDI_SUCCESS);
}
int
pcata_getedt(ata_soft_t *softp, int dmax)
{
ushort_t *secbuf;
struct atarpbuf *rpbp;
int drive, dcount;
char buf[41];
int i;
#ifdef ATA_DEBUG
if (pcata_debug & DENT) {
cmn_err(CE_CONT, "_getedt (%p)\n", (void *)softp);
}
#endif
/* toggle reset bit to trigger a software reset */
if (!(CARD_PRESENT_VALID(softp)))
return (DDI_FAILURE);
csx_Put8(softp->handle, AT_DEVCTL, AT_DEVCTL_D3|AT_SRST);
drv_usecwait(1000);
if (!(CARD_PRESENT_VALID(softp)))
return (DDI_FAILURE);
/*
* The interrupt disable command does not work reliably with
* all PC ATA cards. It is better to leave interupts enabled
* and process them as they occur.
*/
PCIDE_OUTB(softp->handle, AT_DEVCTL, ENABLE_INTERRUPT);
secbuf = (ushort_t *)kmem_zalloc(NBPSCTR, KM_NOSLEEP);
if (!secbuf) {
return (DDI_FAILURE);
}
for (dcount = drive = 0; drive < dmax; drive++) {
if (!(rpbp = (struct atarpbuf *)kmem_zalloc(
(sizeof (struct atarpbuf) +
sizeof (struct scsi_inquiry)), KM_NOSLEEP))) {
kmem_free(secbuf, NBPSCTR);
return (DDI_FAILURE);
}
/*
* load up with the drive number
*/
if (drive == 0) {
PCIDE_OUTB(softp->handle, AT_DRVHD, ATDH_DRIVE0);
} else {
PCIDE_OUTB(softp->handle, AT_DRVHD, ATDH_DRIVE1);
}
PCIDE_OUTB(softp->handle, AT_FEATURE, 0);
softp->ab_dev_type[drive] = pcata_drive_type(softp, secbuf);
if (softp->ab_dev_type[drive] == ATA_DEV_NONE) {
kmem_free(rpbp, (sizeof (struct atarpbuf) +
sizeof (struct scsi_inquiry)));
continue;
}
dcount++;
bcopy((caddr_t)secbuf, (caddr_t)rpbp, sizeof (struct atarpbuf));
mutex_enter(&softp->ata_mutex);
if (!(softp->card_state & PCATA_CARD_INSERTED)) {
kmem_free(rpbp, (sizeof (struct atarpbuf) +
sizeof (struct scsi_inquiry)));
dcount--;
mutex_exit(&softp->ata_mutex);
break;
}
softp->ab_rpbp[drive] = rpbp;
/*
* We need to swap the strings on both platforms.
*/
#ifdef _BIG_ENDIAN
pcata_byte_swap((char *)rpbp, sizeof (*rpbp));
#else
pcata_byte_swap(rpbp->atarp_drvser,
sizeof (rpbp->atarp_drvser));
pcata_byte_swap(rpbp->atarp_fw, sizeof (rpbp->atarp_fw));
pcata_byte_swap(rpbp->atarp_model, sizeof (rpbp->atarp_model));
#endif
mutex_exit(&softp->ata_mutex);
#ifdef ATA_DEBUG
if (pcata_debug & DINIT) {
(void) strncpy(buf,
rpbp->atarp_model, sizeof (rpbp->atarp_model));
buf[sizeof (rpbp->atarp_model)-1] = '\0';
/* truncate model */
for (i = sizeof (rpbp->atarp_model) - 2; i && buf[i] == ' ';
i--) {
buf[i] = '\0';
}
cmn_err(CE_CONT, "_getedt model %s, targ %d, stat %x, err %x\n",
buf,
drive,
csx_Get8(softp->handle, AT_STATUS),
csx_Get8(softp->handle, AT_ERROR));
cmn_err(CE_CONT, " cfg 0x%x, cyl %d, hd %d, sec/trk %d\n",
rpbp->atarp_config,
rpbp->atarp_fixcyls,
rpbp->atarp_heads,
rpbp->atarp_sectors);
cmn_err(CE_CONT, " mult1 0x%x, mult2 0x%x, dwcap 0x%x,"
" cap 0x%x\n",
rpbp->atarp_mult1,
rpbp->atarp_mult2,
rpbp->atarp_dwcap,
rpbp->atarp_cap);
cmn_err(CE_CONT, " piomode 0x%x, dmamode 0x%x,"
" advpiomode 0x%x\n",
rpbp->atarp_piomode,
rpbp->atarp_dmamode,
rpbp->atarp_advpiomode);
cmn_err(CE_CONT, " minpio %d, minpioflow %d",
rpbp->atarp_minpio,
rpbp->atarp_minpioflow);
cmn_err(CE_CONT, " valid 0x%x, dwdma 0x%x\n",
rpbp->atarp_validinfo,
rpbp->atarp_dworddma);
}
#endif
if (!(CARD_PRESENT_VALID(softp)))
return (DDI_FAILURE);
(void) csx_Get8(softp->handle, AT_STATUS);
(void) csx_Get8(softp->handle, AT_ERROR);
}
kmem_free(secbuf, NBPSCTR);
if (dcount == 0)
return (DDI_FAILURE);
for (dcount = drive = 0; drive < dmax; drive++) {
if ((rpbp = softp->ab_rpbp[drive]) == NULL) {
continue; /* no drive here */
}
if (softp->ab_dev_type[drive] != ATA_DEV_DISK) {
cmn_err(CE_CONT, "Unknown IDE attachment at 0x%x.\n",
softp->ab_cmd - AT_CMD);
continue;
}
/*
* feed some of the info back in a set_params call.
*/
mutex_enter(&softp->ata_mutex);
if (pcata_setpar(drive, rpbp->atarp_heads,
rpbp->atarp_sectors, softp)
== DDI_FAILURE) {
/*
* there should have been a drive here but it
* didn't respond properly. It stayed BUSY.
*/
if (softp->ab_rpbp[drive]) {
kmem_free(rpbp,
(sizeof (struct atarpbuf) +
sizeof (struct scsi_inquiry)));
}
softp->ab_rpbp[drive] = NULL;
softp->ab_dev_type[drive] = ATA_DEV_NONE;
mutex_exit(&softp->ata_mutex);
continue;
}
mutex_exit(&softp->ata_mutex);
dcount++;
}
#ifdef ATA_DEBUG
if (pcata_debug)
cmn_err(CE_CONT, "**** probed %d device%s 0x%x\n",
dcount, dcount == 1 ? "." : "s.",
softp->ab_cmd - AT_CMD);
#endif
return (dcount ? DDI_SUCCESS : DDI_FAILURE);
}
/*
* pcata_drive_type()
*/
static uchar_t
pcata_drive_type(ata_soft_t *softp, ushort_t *buf)
{
struct atarpbuf *rpbp = (struct atarpbuf *)buf;
if (pcata_wait1(AT_ALTSTATUS,
(ATS_DRDY | ATS_DSC), (ATS_BSY | ATS_ERR), 100000, softp))
return (ATA_DEV_NONE);
pcata_wait_complete(softp);
/*
* note: pcata_drive_type is only called by pcata_getedt()
* the drive (master/slave) is selected there
*/
/* command also known as IDENTIFY DEVICE */
mutex_enter(&softp->hi_mutex);
softp->intr_pending++;
csx_Put8(softp->handle, AT_CMD, ATC_READPARMS);
mutex_exit(&softp->hi_mutex);
if (pcata_wait1(AT_ALTSTATUS, ATS_DRQ, ATS_BSY, 1000000, softp)) {
#ifdef ATA_DEBUG
if (pcata_debug) {
cmn_err(CE_NOTE, "failed drive did not settle:");
pcata_print_sttflag(csx_Get8(softp->handle, AT_STATUS));
}
#endif
return (ATA_DEV_NONE);
}
csx_RepGet16(softp->handle, (ushort_t *)buf, AT_DATA, NBPSCTR >> 1,
DDI_DEV_NO_AUTOINCR);
#ifdef ATA_DEBUG
if (pcata_debug) {
if ((csx_Get8(softp->handle, AT_STATUS) & ATS_ERR) == 0) {
pcata_byte_swap(rpbp->atarp_model,
sizeof (rpbp->atarp_model));
rpbp->atarp_model[sizeof (rpbp->atarp_model)-1] = '\0';
cmn_err(CE_CONT, "succeeded: %s\n",
rpbp->atarp_model);
pcata_byte_swap(rpbp->atarp_model,
sizeof (rpbp->atarp_model));
} else {
cmn_err(CE_CONT, "failed drive drive read error.\n");
}
}
#endif
/*
* wait for the drive to recognize I've read all the data. some
* drives have been observed to take as much as 3msec to finish
* sending the data; allow 5 msec just in case.
*/
if (pcata_wait1(AT_ALTSTATUS, ATS_DRDY, ATS_BSY | ATS_DRQ, 500, softp))
return (ATA_DEV_NONE);
if (!CARD_PRESENT_VALID(softp))
return (ATA_DEV_NONE);
if (csx_Get8(softp->handle, AT_ALTSTATUS) & ATS_ERR)
return (ATA_DEV_NONE);
return (ATA_DEV_DISK);
}
/*
* Drive set params command.
*/
static int
pcata_setpar(int drive, int heads, int sectors, ata_soft_t *softp)
{
#ifdef ATA_DEBUG
if (pcata_debug & DINIT)
cmn_err(CE_CONT, "_setpar status=0x%x drive=%d heads=%d\n",
csx_Get8(softp->handle, AT_STATUS), drive, heads);
#endif
if (!CARD_PRESENT_VALID(softp))
return (DDI_FAILURE);
if (pcata_wait(AT_ALTSTATUS, ATS_DRDY, ATS_BSY, softp))
return (DDI_FAILURE);
pcata_wait_complete(softp);
PCIDE_OUTB(softp->handle, AT_DRVHD, (heads - 1) |
(drive == 0 ? ATDH_DRIVE0 : ATDH_DRIVE1));
PCIDE_OUTB(softp->handle, AT_COUNT, sectors);
mutex_enter(&softp->hi_mutex);
softp->intr_pending++;
csx_Put8(softp->handle, AT_CMD, ATC_SETPARAM);
mutex_exit(&softp->hi_mutex);
if (pcata_wait(AT_ALTSTATUS, 0, ATS_BSY, softp))
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
void
pcata_byte_swap(char *buf, int n)
{
int i;
char c;
n &= ~1;
for (i = 0; i < n; i += 2) {
c = buf[i];
buf[i] = buf[i + 1];
buf[i + 1] = c;
}
}
int
pcata_set_rw_multiple(ata_soft_t *softp, int drive)
{
int i;
int laststat;
char size;
char accepted_size = -1;
#ifdef ATA_DEBUG
if (pcata_debug & DENT) {
cmn_err(CE_CONT, "_set_rw_multiple (%p, %d)\n",
(void *)softp, drive);
}
#endif
if (!CARD_PRESENT_VALID(softp))
return (DDI_FAILURE);
/*
* Assume we're going to use read/write multiple until the controller
* says it doesn't understand them.
*/
softp->ab_rd_cmd[drive] = ATC_RDMULT;
softp->ab_wr_cmd[drive] = ATC_WRMULT;
/*
* set drive number
*/
PCIDE_OUTB(softp->handle, AT_DRVHD, drive == 0 ? ATDH_DRIVE0 :
ATDH_DRIVE1);
for (size = 32; size > 0 && accepted_size == -1 &&
CARD_PRESENT_VALID(softp); size >>= 1) {
if (pcata_wait(AT_ALTSTATUS, ATS_DRDY, ATS_BSY, softp))
return (DDI_FAILURE);
pcata_wait_complete(softp);
/*
* send the command
*/
PCIDE_OUTB(softp->handle, AT_COUNT, size);
mutex_enter(&softp->hi_mutex);
softp->intr_pending++;
csx_Put8(softp->handle, AT_CMD, ATC_SETMULT);
mutex_exit(&softp->hi_mutex);
if (pcata_wait(AT_ALTSTATUS, 0, ATS_BSY, softp))
/*
* there should have been a drive here but it
* didn't respond properly. It stayed BUSY.
* complete failure!
*/
return (DDI_FAILURE);
/*
* Wait for DRDY or error status
*/
for (i = 0; i < ATA_LOOP_CNT && CARD_PRESENT_VALID(softp);
i++) {
if (((laststat = csx_Get8(softp->handle, AT_ALTSTATUS))
& (ATS_DRDY | ATS_ERR)) != 0)
break;
drv_usecwait(10);
}
if (i == ATA_LOOP_CNT)
/*
* Didn't get ready OR error... complete failure!
* there should have been a drive here but it
* didn't respond properly. It didn't set ERR or DRQ.
*/
return (DDI_FAILURE);
/*
* See if DRQ or error
*/
if (laststat & ATS_ERR) {
/*
* there should have been a drive here but it
* didn't respond properly. There was an error.
* Try the next value.
*/
continue;
}
/*
* Got ready.. use the value that worked.
*/
accepted_size = size;
}
if (accepted_size == -1) {
/*
* None of the values worked...
* the controller responded correctly though so it probably
* doesn't support the read/write multiple commands.
*/
#ifdef ATA_DEBUG
if (pcata_debug & DENT) {
cmn_err(CE_CONT, "Using STD R/W cmds and setting"
"block factor to 1\n");
}
#endif
softp->ab_rd_cmd[drive] = ATC_RDSEC;
softp->ab_wr_cmd[drive] = ATC_WRSEC;
softp->ab_block_factor[drive] = 1;
softp->ab_max_transfer = 1;
return (DDI_SUCCESS);
}
if (accepted_size == 1) {
/*
* OK... Leave it at 1
*/
#ifdef ATA_DEBUG
if (pcata_debug & DENT) {
cmn_err(CE_CONT, "setting block factor to 1\n");
}
#endif
softp->ab_block_factor[drive] = accepted_size;
softp->ab_max_transfer = accepted_size;
return (DDI_SUCCESS);
}
accepted_size >>= 1;
/*
* Allow a user specified block factor to override the system chosen
* value. Only allow the user to reduce the value.
* -1 indicates the user didn't specify anything
*/
if ((softp->ab_block_factor[drive] != -1) &&
(softp->ab_block_factor[drive] < accepted_size))
accepted_size = softp->ab_block_factor[drive];
if (pcata_wait(AT_ALTSTATUS, ATS_DRDY, ATS_BSY, softp))
return (DDI_FAILURE);
pcata_wait_complete(softp);
PCIDE_OUTB(softp->handle, AT_COUNT, accepted_size);
mutex_enter(&softp->hi_mutex);
softp->intr_pending++;
csx_Put8(softp->handle, AT_CMD, ATC_SETMULT);
mutex_exit(&softp->hi_mutex);
if (pcata_wait(AT_ALTSTATUS, 0, ATS_BSY, softp))
/*
* there should have been a drive here but it
* didn't respond properly. It stayed BUSY.
*/
return (DDI_FAILURE);
#ifdef ATA_DEBUG
if (pcata_debug & DENT) {
cmn_err(CE_CONT, "setting block factor for drive %d to %d\n",
drive, accepted_size);
}
#endif
softp->ab_block_factor[drive] = accepted_size;
return (DDI_SUCCESS);
}
static int
pcata_dump(dev_t dev, caddr_t addr, daddr_t blkno, int nblk)
{
ata_soft_t *softp;
buf_t *bp;
void *instance;
if (pcata_getinfo(NULL, DDI_INFO_DEVT2INSTANCE, (void *)dev,
&instance) != DDI_SUCCESS)
return (ENODEV);
softp = ddi_get_soft_state(pcata_soft, (int)(uintptr_t)instance);
if (!softp) {
return (ENXIO);
}
if (!CARD_PRESENT_VALID(softp))
return (ENODEV);
bp = softp->crashbuf;
bp->b_un.b_addr = addr;
bp->b_edev = dev;
bp->b_dev = cmpdev(dev);
bp->b_bcount = nblk * DEV_BSIZE;
bp->b_flags |= B_WRITE | B_PHYS;
bp->b_blkno = blkno;
bp->b_private = 0;
/*
* If pcata_strategy() encounters an exception, or card_removal
* is called, before this is complete, it is possible that
* biodone will be called but the buffer (bp) wont
* be released unless B_ASYNC flag is set. So
* don't set B_ASYNC flag unless you mean it.
*/
(void) pcata_strategy(bp);
if (bp->b_error)
return (bp->b_error);
for (;;) {
if (!CARD_PRESENT_VALID(softp))
return (ENODEV);
if (bp->b_flags & B_DONE) {
if (bp->b_flags & B_ERROR)
return (bp->b_error);
else
return (0);
}
drv_usecwait(1000);
}
}
/* ddi print */
static int
pcata_print(dev_t dev, char *str)
{
void *instance;
ata_soft_t *softp;
/* get instance number */
if (pcata_getinfo(NULL, DDI_INFO_DEVT2INSTANCE, (void *)dev,
&instance) != DDI_SUCCESS) {
cmn_err(CE_CONT, "_print: pcata_getinfo"
"return ENODEV\n");
return (ENODEV);
}
if (!(softp = ddi_get_soft_state(pcata_soft,
(int)(uintptr_t)instance))) {
return (ENXIO);
}
cmn_err(CE_NOTE, "_print: socket %d %s", softp->sn, str);
return (0);
}
static int
pcata_rdrw(dev_t dev, struct uio *uio, int flag)
{
return (physio(pcata_strategy, (buf_t *)0, dev, flag, pcata_min, uio));
}
/* ARGSUSED2 */
static int
pcata_read(dev_t dev, struct uio *uio, cred_t *cred_p)
{
return (pcata_rdrw(dev, uio, B_READ));
}
/* ARGSUSED2 */
static int
pcata_write(dev_t dev, struct uio *uio, cred_t *cred_p)
{
return (pcata_rdrw(dev, uio, B_WRITE));
}
void
pcata_min(buf_t *bp)
{
ata_soft_t *softp;
void *instance;
if (pcata_getinfo(NULL, DDI_INFO_DEVT2INSTANCE, (void *)bp->b_edev,
&instance) != DDI_SUCCESS)
cmn_err(CE_CONT, "Error in pcata_min\n");
softp = ddi_get_soft_state(pcata_soft, (int)(uintptr_t)instance);
if ((ROUNDUP(bp->b_bcount, NBPSCTR) >> SCTRSHFT) >
softp->ab_max_transfer)
bp->b_bcount = softp->ab_max_transfer << SCTRSHFT;
}
static void
pcata_iosetup(ata_unit_t *unitp, struct ata_cmpkt *pktp)
{
uint32_t sec_count;
#ifdef ATA_DEBUG
if (pcata_debug & DENT) {
cmn_err(CE_CONT, "_iosetup (%p, %p)\n",
(void *)unitp, (void *)pktp);
}
#endif
/* check for error retry */
if (pktp->ac_flags & CFLAG_ERROR) {
pktp->ac_bytes_per_block = NBPSCTR;
sec_count = 1;
} else {
/*
* Limit requetst to ab_max_transfer sectors.
* The value is specified by the user in the
* max_transfer property. It must be in the range 1 to 256.
* When max_transfer is 0x100 it is bigger than 8 bits.
* The spec says 0 represents 256 so it should be OK.
*/
sec_count = min((pktp->cp_bytexfer >> SCTRSHFT),
unitp->a_blkp->ab_max_transfer);
}
pktp->ac_v_addr = pktp->ac_start_v_addr;
pktp->cp_resid = pktp->cp_bytexfer;
pktp->cp_bytexfer = sec_count << SCTRSHFT;
#ifdef ATA_DEBUG
if (pcata_debug & DIO) {
cmn_err(CE_CONT,
"_iosetup: asking for start 0x%lx count 0x%x\n",
pktp->cp_srtsec, pktp->cp_bytexfer >> SCTRSHFT);
}
#endif
/*
* setup the task file registers
*/
if (pktp->cp_passthru) {
switch (((struct dadkio_rwcmd *)(pktp->cp_passthru))->cmd) {
case DADKIO_RWCMD_READ:
pktp->ac_cmd = unitp->au_rd_cmd;
pktp->ac_direction = AT_IN;
break;
case DADKIO_RWCMD_WRITE:
pktp->ac_cmd = unitp->au_wr_cmd;
pktp->ac_direction = AT_OUT;
break;
}
} else {
switch (pktp->ac_cdb) {
case DCMD_READ:
case DCMD_WRITE:
case DCMD_RECAL:
case DCMD_SEEK:
case DCMD_RDVER:
switch (pktp->ac_cdb) {
case DCMD_READ:
pktp->ac_cmd = unitp->au_rd_cmd;
pktp->ac_direction = AT_IN;
break;
case DCMD_WRITE:
pktp->ac_cmd = unitp->au_wr_cmd;
pktp->ac_direction = AT_OUT;
break;
case DCMD_RECAL:
pktp->ac_cmd = ATC_RECAL;
pktp->ac_direction = AT_NO_DATA;
break;
case DCMD_SEEK:
pktp->ac_cmd = ATC_SEEK;
pktp->ac_direction = AT_NO_DATA;
break;
case DCMD_RDVER:
pktp->ac_cmd = ATC_RDVER;
pktp->ac_direction = AT_NO_DATA;
break;
}
break;
default:
cmn_err(CE_CONT, "_iosetup: "
"unrecognized cmd 0x%x\n",
pktp->ac_cdb);
break;
}
}
}
/* ARGSUSED */
int
pcata_spinup(ata_soft_t *softp, int slot)
{
if (!(CARD_PRESENT_VALID(softp)))
return (DDI_FAILURE);
if (pcata_wait(AT_ALTSTATUS, ATS_DRDY, ATS_BSY, softp))
return (DDI_FAILURE);
pcata_wait_complete(softp);
/* spin up the drive */
PCIDE_OUTB(softp->handle, AT_DRVHD, ATDH_DRIVE0);
mutex_enter(&softp->hi_mutex);
softp->intr_pending++;
csx_Put8(softp->handle, AT_CMD, ATC_IDLE_IMMED);
mutex_exit(&softp->hi_mutex);
if (pcata_wait(AT_ALTSTATUS,
(ATS_DRDY | ATS_DSC), (ATS_BSY | ATS_ERR), softp)) {
#ifdef ATA_DEBUG
cmn_err(CE_NOTE, "TIMEOUT SPINNING UP: ");
pcata_print_sttflag(csx_Get8(softp->handle, AT_ALTSTATUS));
#endif
return (DDI_FAILURE);
}
pcata_wait_complete(softp);
/* set the R/W multiple value decided at first init time */
PCIDE_OUTB(softp->handle, AT_COUNT, softp->ab_block_factor[0]);
mutex_enter(&softp->hi_mutex);
softp->intr_pending++;
csx_Put8(softp->handle, AT_CMD, ATC_SETMULT);
mutex_exit(&softp->hi_mutex);
if (pcata_wait(AT_STATUS, 0, ATS_BSY, softp)) {
/*
* there should have been a drive here but it
* didn't respond properly. It stayed BUSY.
*/
#ifdef ATA_DEBUG
cmn_err(CE_NOTE, "Error Spinning up ATA drive (after CPR)\n");
#endif
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
#ifdef ATA_DEBUG
static char *
ata_sttvals[] = { "err", "idx", "corr", "drq", "dsc", "dwf", "drdy", "bsy" };
static void
pcata_print_sttflag(int svalue)
{
int i;
char buf[80];
(void) sprintf(buf, "_sttflag = 0x%x [ ", svalue);
for (i = 7; i >= 0; i--, svalue <<= 1) {
if (svalue & 0x80) {
(void) strcat(buf, ata_sttvals[i]);
(void) strcat(buf, " ");
}
}
cmn_err(CE_CONT, "%s ]\n", buf);
}
#endif
|