pata_serverworks.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. /*
  2. * pata_serverworks.c - Serverworks PATA for new ATA layer
  3. * (C) 2005 Red Hat Inc
  4. * (C) 2010 Bartlomiej Zolnierkiewicz
  5. *
  6. * based upon
  7. *
  8. * serverworks.c
  9. *
  10. * Copyright (C) 1998-2000 Michel Aubry
  11. * Copyright (C) 1998-2000 Andrzej Krzysztofowicz
  12. * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
  13. * Portions copyright (c) 2001 Sun Microsystems
  14. *
  15. *
  16. * RCC/ServerWorks IDE driver for Linux
  17. *
  18. * OSB4: `Open South Bridge' IDE Interface (fn 1)
  19. * supports UDMA mode 2 (33 MB/s)
  20. *
  21. * CSB5: `Champion South Bridge' IDE Interface (fn 1)
  22. * all revisions support UDMA mode 4 (66 MB/s)
  23. * revision A2.0 and up support UDMA mode 5 (100 MB/s)
  24. *
  25. * *** The CSB5 does not provide ANY register ***
  26. * *** to detect 80-conductor cable presence. ***
  27. *
  28. * CSB6: `Champion South Bridge' IDE Interface (optional: third channel)
  29. *
  30. * Documentation:
  31. * Available under NDA only. Errata info very hard to get.
  32. */
  33. #include <linux/kernel.h>
  34. #include <linux/module.h>
  35. #include <linux/pci.h>
  36. #include <linux/init.h>
  37. #include <linux/blkdev.h>
  38. #include <linux/delay.h>
  39. #include <scsi/scsi_host.h>
  40. #include <linux/libata.h>
  41. #define DRV_NAME "pata_serverworks"
  42. #define DRV_VERSION "0.4.3"
  43. #define SVWKS_CSB5_REVISION_NEW 0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */
  44. #define SVWKS_CSB6_REVISION 0xa0 /* min PCI_REVISION_ID for UDMA4 (A1.0) */
  45. /* Seagate Barracuda ATA IV Family drives in UDMA mode 5
  46. * can overrun their FIFOs when used with the CSB5 */
  47. static const char *csb_bad_ata100[] = {
  48. "ST320011A",
  49. "ST340016A",
  50. "ST360021A",
  51. "ST380021A",
  52. NULL
  53. };
  54. /**
  55. * dell_cable - Dell serverworks cable detection
  56. * @ap: ATA port to do cable detect
  57. *
  58. * Dell hide the 40/80 pin select for their interfaces in the top two
  59. * bits of the subsystem ID.
  60. */
  61. static int dell_cable(struct ata_port *ap) {
  62. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  63. if (pdev->subsystem_device & (1 << (ap->port_no + 14)))
  64. return ATA_CBL_PATA80;
  65. return ATA_CBL_PATA40;
  66. }
  67. /**
  68. * sun_cable - Sun Cobalt 'Alpine' cable detection
  69. * @ap: ATA port to do cable select
  70. *
  71. * Cobalt CSB5 IDE hides the 40/80pin in the top two bits of the
  72. * subsystem ID the same as dell. We could use one function but we may
  73. * need to extend the Dell one in future
  74. */
  75. static int sun_cable(struct ata_port *ap) {
  76. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  77. if (pdev->subsystem_device & (1 << (ap->port_no + 14)))
  78. return ATA_CBL_PATA80;
  79. return ATA_CBL_PATA40;
  80. }
  81. /**
  82. * osb4_cable - OSB4 cable detect
  83. * @ap: ATA port to check
  84. *
  85. * The OSB4 isn't UDMA66 capable so this is easy
  86. */
  87. static int osb4_cable(struct ata_port *ap) {
  88. return ATA_CBL_PATA40;
  89. }
  90. /**
  91. * csb_cable - CSB5/6 cable detect
  92. * @ap: ATA port to check
  93. *
  94. * Serverworks default arrangement is to use the drive side detection
  95. * only.
  96. */
  97. static int csb_cable(struct ata_port *ap) {
  98. return ATA_CBL_PATA_UNK;
  99. }
  100. struct sv_cable_table {
  101. int device;
  102. int subvendor;
  103. int (*cable_detect)(struct ata_port *ap);
  104. };
  105. /*
  106. * Note that we don't copy the old serverworks code because the old
  107. * code contains obvious mistakes
  108. */
  109. static struct sv_cable_table cable_detect[] = {
  110. { PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_VENDOR_ID_DELL, dell_cable },
  111. { PCI_DEVICE_ID_SERVERWORKS_CSB6IDE, PCI_VENDOR_ID_DELL, dell_cable },
  112. { PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_VENDOR_ID_SUN, sun_cable },
  113. { PCI_DEVICE_ID_SERVERWORKS_OSB4IDE, PCI_ANY_ID, osb4_cable },
  114. { PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_ANY_ID, csb_cable },
  115. { PCI_DEVICE_ID_SERVERWORKS_CSB6IDE, PCI_ANY_ID, csb_cable },
  116. { PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2, PCI_ANY_ID, csb_cable },
  117. { PCI_DEVICE_ID_SERVERWORKS_HT1000IDE, PCI_ANY_ID, csb_cable },
  118. { }
  119. };
  120. /**
  121. * serverworks_cable_detect - cable detection
  122. * @ap: ATA port
  123. *
  124. * Perform cable detection according to the device and subvendor
  125. * identifications
  126. */
  127. static int serverworks_cable_detect(struct ata_port *ap)
  128. {
  129. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  130. struct sv_cable_table *cb = cable_detect;
  131. while(cb->device) {
  132. if (cb->device == pdev->device &&
  133. (cb->subvendor == pdev->subsystem_vendor ||
  134. cb->subvendor == PCI_ANY_ID)) {
  135. return cb->cable_detect(ap);
  136. }
  137. cb++;
  138. }
  139. BUG();
  140. return -1; /* kill compiler warning */
  141. }
  142. /**
  143. * serverworks_is_csb - Check for CSB or OSB
  144. * @pdev: PCI device to check
  145. *
  146. * Returns true if the device being checked is known to be a CSB
  147. * series device.
  148. */
  149. static u8 serverworks_is_csb(struct pci_dev *pdev)
  150. {
  151. switch (pdev->device) {
  152. case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE:
  153. case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE:
  154. case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2:
  155. case PCI_DEVICE_ID_SERVERWORKS_HT1000IDE:
  156. return 1;
  157. default:
  158. break;
  159. }
  160. return 0;
  161. }
  162. /**
  163. * serverworks_osb4_filter - mode selection filter
  164. * @adev: ATA device
  165. * @mask: Mask of proposed modes
  166. *
  167. * Filter the offered modes for the device to apply controller
  168. * specific rules. OSB4 requires no UDMA for disks due to a FIFO
  169. * bug we hit.
  170. */
  171. static unsigned long serverworks_osb4_filter(struct ata_device *adev, unsigned long mask)
  172. {
  173. if (adev->class == ATA_DEV_ATA)
  174. mask &= ~ATA_MASK_UDMA;
  175. return mask;
  176. }
  177. /**
  178. * serverworks_csb_filter - mode selection filter
  179. * @adev: ATA device
  180. * @mask: Mask of proposed modes
  181. *
  182. * Check the blacklist and disable UDMA5 if matched
  183. */
  184. static unsigned long serverworks_csb_filter(struct ata_device *adev, unsigned long mask)
  185. {
  186. const char *p;
  187. char model_num[ATA_ID_PROD_LEN + 1];
  188. int i;
  189. /* Disk, UDMA */
  190. if (adev->class != ATA_DEV_ATA)
  191. return mask;
  192. /* Actually do need to check */
  193. ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
  194. for (i = 0; (p = csb_bad_ata100[i]) != NULL; i++) {
  195. if (!strcmp(p, model_num))
  196. mask &= ~(0xE0 << ATA_SHIFT_UDMA);
  197. }
  198. return mask;
  199. }
  200. /**
  201. * serverworks_set_piomode - set initial PIO mode data
  202. * @ap: ATA interface
  203. * @adev: ATA device
  204. *
  205. * Program the OSB4/CSB5 timing registers for PIO. The PIO register
  206. * load is done as a simple lookup.
  207. */
  208. static void serverworks_set_piomode(struct ata_port *ap, struct ata_device *adev)
  209. {
  210. static const u8 pio_mode[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 };
  211. int offset = 1 + 2 * ap->port_no - adev->devno;
  212. int devbits = (2 * ap->port_no + adev->devno) * 4;
  213. u16 csb5_pio;
  214. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  215. int pio = adev->pio_mode - XFER_PIO_0;
  216. pci_write_config_byte(pdev, 0x40 + offset, pio_mode[pio]);
  217. /* The OSB4 just requires the timing but the CSB series want the
  218. mode number as well */
  219. if (serverworks_is_csb(pdev)) {
  220. pci_read_config_word(pdev, 0x4A, &csb5_pio);
  221. csb5_pio &= ~(0x0F << devbits);
  222. pci_write_config_word(pdev, 0x4A, csb5_pio | (pio << devbits));
  223. }
  224. }
  225. /**
  226. * serverworks_set_dmamode - set initial DMA mode data
  227. * @ap: ATA interface
  228. * @adev: ATA device
  229. *
  230. * Program the MWDMA/UDMA modes for the serverworks OSB4/CSB5
  231. * chipset. The MWDMA mode values are pulled from a lookup table
  232. * while the chipset uses mode number for UDMA.
  233. */
  234. static void serverworks_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  235. {
  236. static const u8 dma_mode[] = { 0x77, 0x21, 0x20 };
  237. int offset = 1 + 2 * ap->port_no - adev->devno;
  238. int devbits = 2 * ap->port_no + adev->devno;
  239. u8 ultra;
  240. u8 ultra_cfg;
  241. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  242. pci_read_config_byte(pdev, 0x54, &ultra_cfg);
  243. pci_read_config_byte(pdev, 0x56 + ap->port_no, &ultra);
  244. ultra &= ~(0x0F << (adev->devno * 4));
  245. if (adev->dma_mode >= XFER_UDMA_0) {
  246. pci_write_config_byte(pdev, 0x44 + offset, 0x20);
  247. ultra |= (adev->dma_mode - XFER_UDMA_0)
  248. << (adev->devno * 4);
  249. ultra_cfg |= (1 << devbits);
  250. } else {
  251. pci_write_config_byte(pdev, 0x44 + offset,
  252. dma_mode[adev->dma_mode - XFER_MW_DMA_0]);
  253. ultra_cfg &= ~(1 << devbits);
  254. }
  255. pci_write_config_byte(pdev, 0x56 + ap->port_no, ultra);
  256. pci_write_config_byte(pdev, 0x54, ultra_cfg);
  257. }
  258. static struct scsi_host_template serverworks_sht = {
  259. ATA_BMDMA_SHT(DRV_NAME),
  260. };
  261. static struct ata_port_operations serverworks_osb4_port_ops = {
  262. .inherits = &ata_bmdma_port_ops,
  263. .cable_detect = serverworks_cable_detect,
  264. .mode_filter = serverworks_osb4_filter,
  265. .set_piomode = serverworks_set_piomode,
  266. .set_dmamode = serverworks_set_dmamode,
  267. };
  268. static struct ata_port_operations serverworks_csb_port_ops = {
  269. .inherits = &serverworks_osb4_port_ops,
  270. .mode_filter = serverworks_csb_filter,
  271. };
  272. static int serverworks_fixup_osb4(struct pci_dev *pdev)
  273. {
  274. u32 reg;
  275. struct pci_dev *isa_dev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  276. PCI_DEVICE_ID_SERVERWORKS_OSB4, NULL);
  277. if (isa_dev) {
  278. pci_read_config_dword(isa_dev, 0x64, &reg);
  279. reg &= ~0x00002000; /* disable 600ns interrupt mask */
  280. if (!(reg & 0x00004000))
  281. printk(KERN_DEBUG DRV_NAME ": UDMA not BIOS enabled.\n");
  282. reg |= 0x00004000; /* enable UDMA/33 support */
  283. pci_write_config_dword(isa_dev, 0x64, reg);
  284. pci_dev_put(isa_dev);
  285. return 0;
  286. }
  287. printk(KERN_WARNING DRV_NAME ": Unable to find bridge.\n");
  288. return -ENODEV;
  289. }
  290. static int serverworks_fixup_csb(struct pci_dev *pdev)
  291. {
  292. u8 btr;
  293. /* Third Channel Test */
  294. if (!(PCI_FUNC(pdev->devfn) & 1)) {
  295. struct pci_dev * findev = NULL;
  296. u32 reg4c = 0;
  297. findev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  298. PCI_DEVICE_ID_SERVERWORKS_CSB5, NULL);
  299. if (findev) {
  300. pci_read_config_dword(findev, 0x4C, &reg4c);
  301. reg4c &= ~0x000007FF;
  302. reg4c |= 0x00000040;
  303. reg4c |= 0x00000020;
  304. pci_write_config_dword(findev, 0x4C, reg4c);
  305. pci_dev_put(findev);
  306. }
  307. } else {
  308. struct pci_dev * findev = NULL;
  309. u8 reg41 = 0;
  310. findev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  311. PCI_DEVICE_ID_SERVERWORKS_CSB6, NULL);
  312. if (findev) {
  313. pci_read_config_byte(findev, 0x41, &reg41);
  314. reg41 &= ~0x40;
  315. pci_write_config_byte(findev, 0x41, reg41);
  316. pci_dev_put(findev);
  317. }
  318. }
  319. /* setup the UDMA Control register
  320. *
  321. * 1. clear bit 6 to enable DMA
  322. * 2. enable DMA modes with bits 0-1
  323. * 00 : legacy
  324. * 01 : udma2
  325. * 10 : udma2/udma4
  326. * 11 : udma2/udma4/udma5
  327. */
  328. pci_read_config_byte(pdev, 0x5A, &btr);
  329. btr &= ~0x40;
  330. if (!(PCI_FUNC(pdev->devfn) & 1))
  331. btr |= 0x2;
  332. else
  333. btr |= (pdev->revision >= SVWKS_CSB5_REVISION_NEW) ? 0x3 : 0x2;
  334. pci_write_config_byte(pdev, 0x5A, btr);
  335. return btr;
  336. }
  337. static void serverworks_fixup_ht1000(struct pci_dev *pdev)
  338. {
  339. u8 btr;
  340. /* Setup HT1000 SouthBridge Controller - Single Channel Only */
  341. pci_read_config_byte(pdev, 0x5A, &btr);
  342. btr &= ~0x40;
  343. btr |= 0x3;
  344. pci_write_config_byte(pdev, 0x5A, btr);
  345. }
  346. static int serverworks_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  347. {
  348. static const struct ata_port_info info[4] = {
  349. { /* OSB4 */
  350. .flags = ATA_FLAG_SLAVE_POSS,
  351. .pio_mask = ATA_PIO4,
  352. .mwdma_mask = ATA_MWDMA2,
  353. .udma_mask = ATA_UDMA2,
  354. .port_ops = &serverworks_osb4_port_ops
  355. }, { /* OSB4 no UDMA */
  356. .flags = ATA_FLAG_SLAVE_POSS,
  357. .pio_mask = ATA_PIO4,
  358. .mwdma_mask = ATA_MWDMA2,
  359. /* No UDMA */
  360. .port_ops = &serverworks_osb4_port_ops
  361. }, { /* CSB5 */
  362. .flags = ATA_FLAG_SLAVE_POSS,
  363. .pio_mask = ATA_PIO4,
  364. .mwdma_mask = ATA_MWDMA2,
  365. .udma_mask = ATA_UDMA4,
  366. .port_ops = &serverworks_csb_port_ops
  367. }, { /* CSB5 - later revisions*/
  368. .flags = ATA_FLAG_SLAVE_POSS,
  369. .pio_mask = ATA_PIO4,
  370. .mwdma_mask = ATA_MWDMA2,
  371. .udma_mask = ATA_UDMA5,
  372. .port_ops = &serverworks_csb_port_ops
  373. }
  374. };
  375. const struct ata_port_info *ppi[] = { &info[id->driver_data], NULL };
  376. int rc;
  377. rc = pcim_enable_device(pdev);
  378. if (rc)
  379. return rc;
  380. /* Force master latency timer to 64 PCI clocks */
  381. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x40);
  382. /* OSB4 : South Bridge and IDE */
  383. if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
  384. /* Select non UDMA capable OSB4 if we can't do fixups */
  385. if ( serverworks_fixup_osb4(pdev) < 0)
  386. ppi[0] = &info[1];
  387. }
  388. /* setup CSB5/CSB6 : South Bridge and IDE option RAID */
  389. else if ((pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) ||
  390. (pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
  391. (pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) {
  392. /* If the returned btr is the newer revision then
  393. select the right info block */
  394. if (serverworks_fixup_csb(pdev) == 3)
  395. ppi[0] = &info[3];
  396. /* Is this the 3rd channel CSB6 IDE ? */
  397. if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)
  398. ppi[1] = &ata_dummy_port_info;
  399. }
  400. /* setup HT1000E */
  401. else if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE)
  402. serverworks_fixup_ht1000(pdev);
  403. if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE)
  404. ata_pci_bmdma_clear_simplex(pdev);
  405. return ata_pci_bmdma_init_one(pdev, ppi, &serverworks_sht, NULL, 0);
  406. }
  407. #ifdef CONFIG_PM
  408. static int serverworks_reinit_one(struct pci_dev *pdev)
  409. {
  410. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  411. int rc;
  412. rc = ata_pci_device_do_resume(pdev);
  413. if (rc)
  414. return rc;
  415. /* Force master latency timer to 64 PCI clocks */
  416. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x40);
  417. switch (pdev->device) {
  418. case PCI_DEVICE_ID_SERVERWORKS_OSB4IDE:
  419. serverworks_fixup_osb4(pdev);
  420. break;
  421. case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE:
  422. ata_pci_bmdma_clear_simplex(pdev);
  423. /* fall through */
  424. case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE:
  425. case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2:
  426. serverworks_fixup_csb(pdev);
  427. break;
  428. case PCI_DEVICE_ID_SERVERWORKS_HT1000IDE:
  429. serverworks_fixup_ht1000(pdev);
  430. break;
  431. }
  432. ata_host_resume(host);
  433. return 0;
  434. }
  435. #endif
  436. static const struct pci_device_id serverworks[] = {
  437. { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE), 0},
  438. { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE), 2},
  439. { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE), 2},
  440. { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2), 2},
  441. { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000IDE), 2},
  442. { },
  443. };
  444. static struct pci_driver serverworks_pci_driver = {
  445. .name = DRV_NAME,
  446. .id_table = serverworks,
  447. .probe = serverworks_init_one,
  448. .remove = ata_pci_remove_one,
  449. #ifdef CONFIG_PM
  450. .suspend = ata_pci_device_suspend,
  451. .resume = serverworks_reinit_one,
  452. #endif
  453. };
  454. static int __init serverworks_init(void)
  455. {
  456. return pci_register_driver(&serverworks_pci_driver);
  457. }
  458. static void __exit serverworks_exit(void)
  459. {
  460. pci_unregister_driver(&serverworks_pci_driver);
  461. }
  462. MODULE_AUTHOR("Alan Cox");
  463. MODULE_DESCRIPTION("low-level driver for Serverworks OSB4/CSB5/CSB6");
  464. MODULE_LICENSE("GPL");
  465. MODULE_DEVICE_TABLE(pci, serverworks);
  466. MODULE_VERSION(DRV_VERSION);
  467. module_init(serverworks_init);
  468. module_exit(serverworks_exit);