pata_serverworks.c 13 KB

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