serverworks.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. /*
  2. * Copyright (C) 1998-2000 Michel Aubry
  3. * Copyright (C) 1998-2000 Andrzej Krzysztofowicz
  4. * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
  5. * Copyright (C) 2007-2010 Bartlomiej Zolnierkiewicz
  6. * Portions copyright (c) 2001 Sun Microsystems
  7. *
  8. *
  9. * RCC/ServerWorks IDE driver for Linux
  10. *
  11. * OSB4: `Open South Bridge' IDE Interface (fn 1)
  12. * supports UDMA mode 2 (33 MB/s)
  13. *
  14. * CSB5: `Champion South Bridge' IDE Interface (fn 1)
  15. * all revisions support UDMA mode 4 (66 MB/s)
  16. * revision A2.0 and up support UDMA mode 5 (100 MB/s)
  17. *
  18. * *** The CSB5 does not provide ANY register ***
  19. * *** to detect 80-conductor cable presence. ***
  20. *
  21. * CSB6: `Champion South Bridge' IDE Interface (optional: third channel)
  22. *
  23. * HT1000: AKA BCM5785 - Hypertransport Southbridge for Opteron systems. IDE
  24. * controller same as the CSB6. Single channel ATA100 only.
  25. *
  26. * Documentation:
  27. * Available under NDA only. Errata info very hard to get.
  28. *
  29. */
  30. #include <linux/types.h>
  31. #include <linux/module.h>
  32. #include <linux/kernel.h>
  33. #include <linux/pci.h>
  34. #include <linux/ide.h>
  35. #include <linux/init.h>
  36. #include <asm/io.h>
  37. #define DRV_NAME "serverworks"
  38. #define SVWKS_CSB5_REVISION_NEW 0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */
  39. #define SVWKS_CSB6_REVISION 0xa0 /* min PCI_REVISION_ID for UDMA4 (A1.0) */
  40. /* Seagate Barracuda ATA IV Family drives in UDMA mode 5
  41. * can overrun their FIFOs when used with the CSB5 */
  42. static const char *svwks_bad_ata100[] = {
  43. "ST320011A",
  44. "ST340016A",
  45. "ST360021A",
  46. "ST380021A",
  47. NULL
  48. };
  49. static int check_in_drive_lists (ide_drive_t *drive, const char **list)
  50. {
  51. char *m = (char *)&drive->id[ATA_ID_PROD];
  52. while (*list)
  53. if (!strcmp(*list++, m))
  54. return 1;
  55. return 0;
  56. }
  57. static u8 svwks_udma_filter(ide_drive_t *drive)
  58. {
  59. struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
  60. if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE) {
  61. return 0x1f;
  62. } else if (dev->revision < SVWKS_CSB5_REVISION_NEW) {
  63. return 0x07;
  64. } else {
  65. u8 btr = 0, mode, mask;
  66. pci_read_config_byte(dev, 0x5A, &btr);
  67. mode = btr & 0x3;
  68. /* If someone decides to do UDMA133 on CSB5 the same
  69. issue will bite so be inclusive */
  70. if (mode > 2 && check_in_drive_lists(drive, svwks_bad_ata100))
  71. mode = 2;
  72. switch(mode) {
  73. case 3: mask = 0x3f; break;
  74. case 2: mask = 0x1f; break;
  75. case 1: mask = 0x07; break;
  76. default: mask = 0x00; break;
  77. }
  78. return mask;
  79. }
  80. }
  81. static u8 svwks_csb_check (struct pci_dev *dev)
  82. {
  83. switch (dev->device) {
  84. case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE:
  85. case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE:
  86. case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2:
  87. case PCI_DEVICE_ID_SERVERWORKS_HT1000IDE:
  88. return 1;
  89. default:
  90. break;
  91. }
  92. return 0;
  93. }
  94. static void svwks_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
  95. {
  96. static const u8 pio_modes[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 };
  97. static const u8 drive_pci[] = { 0x41, 0x40, 0x43, 0x42 };
  98. struct pci_dev *dev = to_pci_dev(hwif->dev);
  99. const u8 pio = drive->pio_mode - XFER_PIO_0;
  100. pci_write_config_byte(dev, drive_pci[drive->dn], pio_modes[pio]);
  101. if (svwks_csb_check(dev)) {
  102. u16 csb_pio = 0;
  103. pci_read_config_word(dev, 0x4a, &csb_pio);
  104. csb_pio &= ~(0x0f << (4 * drive->dn));
  105. csb_pio |= (pio << (4 * drive->dn));
  106. pci_write_config_word(dev, 0x4a, csb_pio);
  107. }
  108. }
  109. static void svwks_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive)
  110. {
  111. static const u8 udma_modes[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
  112. static const u8 dma_modes[] = { 0x77, 0x21, 0x20 };
  113. static const u8 drive_pci2[] = { 0x45, 0x44, 0x47, 0x46 };
  114. struct pci_dev *dev = to_pci_dev(hwif->dev);
  115. const u8 speed = drive->dma_mode;
  116. u8 unit = drive->dn & 1;
  117. u8 ultra_enable = 0, ultra_timing = 0, dma_timing = 0;
  118. pci_read_config_byte(dev, (0x56|hwif->channel), &ultra_timing);
  119. pci_read_config_byte(dev, 0x54, &ultra_enable);
  120. ultra_timing &= ~(0x0F << (4*unit));
  121. ultra_enable &= ~(0x01 << drive->dn);
  122. if (speed >= XFER_UDMA_0) {
  123. dma_timing |= dma_modes[2];
  124. ultra_timing |= (udma_modes[speed - XFER_UDMA_0] << (4 * unit));
  125. ultra_enable |= (0x01 << drive->dn);
  126. } else if (speed >= XFER_MW_DMA_0)
  127. dma_timing |= dma_modes[speed - XFER_MW_DMA_0];
  128. pci_write_config_byte(dev, drive_pci2[drive->dn], dma_timing);
  129. pci_write_config_byte(dev, (0x56|hwif->channel), ultra_timing);
  130. pci_write_config_byte(dev, 0x54, ultra_enable);
  131. }
  132. static int init_chipset_svwks(struct pci_dev *dev)
  133. {
  134. unsigned int reg;
  135. u8 btr;
  136. /* force Master Latency Timer value to 64 PCICLKs */
  137. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x40);
  138. /* OSB4 : South Bridge and IDE */
  139. if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
  140. struct pci_dev *isa_dev =
  141. pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  142. PCI_DEVICE_ID_SERVERWORKS_OSB4, NULL);
  143. if (isa_dev) {
  144. pci_read_config_dword(isa_dev, 0x64, &reg);
  145. reg &= ~0x00002000; /* disable 600ns interrupt mask */
  146. if(!(reg & 0x00004000))
  147. printk(KERN_DEBUG DRV_NAME " %s: UDMA not BIOS "
  148. "enabled.\n", pci_name(dev));
  149. reg |= 0x00004000; /* enable UDMA/33 support */
  150. pci_write_config_dword(isa_dev, 0x64, reg);
  151. pci_dev_put(isa_dev);
  152. }
  153. }
  154. /* setup CSB5/CSB6 : South Bridge and IDE option RAID */
  155. else if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) ||
  156. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
  157. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) {
  158. /* Third Channel Test */
  159. if (!(PCI_FUNC(dev->devfn) & 1)) {
  160. struct pci_dev * findev = NULL;
  161. u32 reg4c = 0;
  162. findev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  163. PCI_DEVICE_ID_SERVERWORKS_CSB5, NULL);
  164. if (findev) {
  165. pci_read_config_dword(findev, 0x4C, &reg4c);
  166. reg4c &= ~0x000007FF;
  167. reg4c |= 0x00000040;
  168. reg4c |= 0x00000020;
  169. pci_write_config_dword(findev, 0x4C, reg4c);
  170. pci_dev_put(findev);
  171. }
  172. outb_p(0x06, 0x0c00);
  173. dev->irq = inb_p(0x0c01);
  174. } else {
  175. struct pci_dev * findev = NULL;
  176. u8 reg41 = 0;
  177. findev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  178. PCI_DEVICE_ID_SERVERWORKS_CSB6, NULL);
  179. if (findev) {
  180. pci_read_config_byte(findev, 0x41, &reg41);
  181. reg41 &= ~0x40;
  182. pci_write_config_byte(findev, 0x41, reg41);
  183. pci_dev_put(findev);
  184. }
  185. /*
  186. * This is a device pin issue on CSB6.
  187. * Since there will be a future raid mode,
  188. * early versions of the chipset require the
  189. * interrupt pin to be set, and it is a compatibility
  190. * mode issue.
  191. */
  192. if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
  193. dev->irq = 0;
  194. }
  195. // pci_read_config_dword(dev, 0x40, &pioreg)
  196. // pci_write_config_dword(dev, 0x40, 0x99999999);
  197. // pci_read_config_dword(dev, 0x44, &dmareg);
  198. // pci_write_config_dword(dev, 0x44, 0xFFFFFFFF);
  199. /* setup the UDMA Control register
  200. *
  201. * 1. clear bit 6 to enable DMA
  202. * 2. enable DMA modes with bits 0-1
  203. * 00 : legacy
  204. * 01 : udma2
  205. * 10 : udma2/udma4
  206. * 11 : udma2/udma4/udma5
  207. */
  208. pci_read_config_byte(dev, 0x5A, &btr);
  209. btr &= ~0x40;
  210. if (!(PCI_FUNC(dev->devfn) & 1))
  211. btr |= 0x2;
  212. else
  213. btr |= (dev->revision >= SVWKS_CSB5_REVISION_NEW) ? 0x3 : 0x2;
  214. pci_write_config_byte(dev, 0x5A, btr);
  215. }
  216. /* Setup HT1000 SouthBridge Controller - Single Channel Only */
  217. else if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE) {
  218. pci_read_config_byte(dev, 0x5A, &btr);
  219. btr &= ~0x40;
  220. btr |= 0x3;
  221. pci_write_config_byte(dev, 0x5A, btr);
  222. }
  223. return 0;
  224. }
  225. static u8 ata66_svwks_svwks(ide_hwif_t *hwif)
  226. {
  227. return ATA_CBL_PATA80;
  228. }
  229. /* On Dell PowerEdge servers with a CSB5/CSB6, the top two bits
  230. * of the subsystem device ID indicate presence of an 80-pin cable.
  231. * Bit 15 clear = secondary IDE channel does not have 80-pin cable.
  232. * Bit 15 set = secondary IDE channel has 80-pin cable.
  233. * Bit 14 clear = primary IDE channel does not have 80-pin cable.
  234. * Bit 14 set = primary IDE channel has 80-pin cable.
  235. */
  236. static u8 ata66_svwks_dell(ide_hwif_t *hwif)
  237. {
  238. struct pci_dev *dev = to_pci_dev(hwif->dev);
  239. if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
  240. dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
  241. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE ||
  242. dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE))
  243. return ((1 << (hwif->channel + 14)) &
  244. dev->subsystem_device) ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
  245. return ATA_CBL_PATA40;
  246. }
  247. /* Sun Cobalt Alpine hardware avoids the 80-pin cable
  248. * detect issue by attaching the drives directly to the board.
  249. * This check follows the Dell precedent (how scary is that?!)
  250. *
  251. * WARNING: this only works on Alpine hardware!
  252. */
  253. static u8 ata66_svwks_cobalt(ide_hwif_t *hwif)
  254. {
  255. struct pci_dev *dev = to_pci_dev(hwif->dev);
  256. if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN &&
  257. dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
  258. dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE)
  259. return ((1 << (hwif->channel + 14)) &
  260. dev->subsystem_device) ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
  261. return ATA_CBL_PATA40;
  262. }
  263. static u8 svwks_cable_detect(ide_hwif_t *hwif)
  264. {
  265. struct pci_dev *dev = to_pci_dev(hwif->dev);
  266. /* Server Works */
  267. if (dev->subsystem_vendor == PCI_VENDOR_ID_SERVERWORKS)
  268. return ata66_svwks_svwks (hwif);
  269. /* Dell PowerEdge */
  270. if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL)
  271. return ata66_svwks_dell (hwif);
  272. /* Cobalt Alpine */
  273. if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN)
  274. return ata66_svwks_cobalt (hwif);
  275. /* Per Specified Design by OEM, and ASIC Architect */
  276. if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
  277. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2))
  278. return ATA_CBL_PATA80;
  279. return ATA_CBL_PATA40;
  280. }
  281. static const struct ide_port_ops osb4_port_ops = {
  282. .set_pio_mode = svwks_set_pio_mode,
  283. .set_dma_mode = svwks_set_dma_mode,
  284. };
  285. static const struct ide_port_ops svwks_port_ops = {
  286. .set_pio_mode = svwks_set_pio_mode,
  287. .set_dma_mode = svwks_set_dma_mode,
  288. .udma_filter = svwks_udma_filter,
  289. .cable_detect = svwks_cable_detect,
  290. };
  291. static const struct ide_port_info serverworks_chipsets[] = {
  292. { /* 0: OSB4 */
  293. .name = DRV_NAME,
  294. .init_chipset = init_chipset_svwks,
  295. .port_ops = &osb4_port_ops,
  296. .pio_mask = ATA_PIO4,
  297. .mwdma_mask = ATA_MWDMA2,
  298. .udma_mask = 0x00, /* UDMA is problematic on OSB4 */
  299. },
  300. { /* 1: CSB5 */
  301. .name = DRV_NAME,
  302. .init_chipset = init_chipset_svwks,
  303. .port_ops = &svwks_port_ops,
  304. .pio_mask = ATA_PIO4,
  305. .mwdma_mask = ATA_MWDMA2,
  306. .udma_mask = ATA_UDMA5,
  307. },
  308. { /* 2: CSB6 */
  309. .name = DRV_NAME,
  310. .init_chipset = init_chipset_svwks,
  311. .port_ops = &svwks_port_ops,
  312. .pio_mask = ATA_PIO4,
  313. .mwdma_mask = ATA_MWDMA2,
  314. .udma_mask = ATA_UDMA5,
  315. },
  316. { /* 3: CSB6-2 */
  317. .name = DRV_NAME,
  318. .init_chipset = init_chipset_svwks,
  319. .port_ops = &svwks_port_ops,
  320. .host_flags = IDE_HFLAG_SINGLE,
  321. .pio_mask = ATA_PIO4,
  322. .mwdma_mask = ATA_MWDMA2,
  323. .udma_mask = ATA_UDMA5,
  324. },
  325. { /* 4: HT1000 */
  326. .name = DRV_NAME,
  327. .init_chipset = init_chipset_svwks,
  328. .port_ops = &svwks_port_ops,
  329. .host_flags = IDE_HFLAG_SINGLE,
  330. .pio_mask = ATA_PIO4,
  331. .mwdma_mask = ATA_MWDMA2,
  332. .udma_mask = ATA_UDMA5,
  333. }
  334. };
  335. /**
  336. * svwks_init_one - called when a OSB/CSB is found
  337. * @dev: the svwks device
  338. * @id: the matching pci id
  339. *
  340. * Called when the PCI registration layer (or the IDE initialization)
  341. * finds a device matching our IDE device tables.
  342. */
  343. static int svwks_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  344. {
  345. struct ide_port_info d;
  346. u8 idx = id->driver_data;
  347. d = serverworks_chipsets[idx];
  348. if (idx == 1)
  349. d.host_flags |= IDE_HFLAG_CLEAR_SIMPLEX;
  350. else if (idx == 2 || idx == 3) {
  351. if ((PCI_FUNC(dev->devfn) & 1) == 0) {
  352. if (pci_resource_start(dev, 0) != 0x01f1)
  353. d.host_flags |= IDE_HFLAG_NON_BOOTABLE;
  354. d.host_flags |= IDE_HFLAG_SINGLE;
  355. } else
  356. d.host_flags &= ~IDE_HFLAG_SINGLE;
  357. }
  358. return ide_pci_init_one(dev, &d, NULL);
  359. }
  360. static const struct pci_device_id svwks_pci_tbl[] = {
  361. { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE), 0 },
  362. { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE), 1 },
  363. { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE), 2 },
  364. { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2), 3 },
  365. { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000IDE), 4 },
  366. { 0, },
  367. };
  368. MODULE_DEVICE_TABLE(pci, svwks_pci_tbl);
  369. static struct pci_driver svwks_pci_driver = {
  370. .name = "Serverworks_IDE",
  371. .id_table = svwks_pci_tbl,
  372. .probe = svwks_init_one,
  373. .remove = ide_pci_remove,
  374. .suspend = ide_pci_suspend,
  375. .resume = ide_pci_resume,
  376. };
  377. static int __init svwks_ide_init(void)
  378. {
  379. return ide_pci_register_driver(&svwks_pci_driver);
  380. }
  381. static void __exit svwks_ide_exit(void)
  382. {
  383. pci_unregister_driver(&svwks_pci_driver);
  384. }
  385. module_init(svwks_ide_init);
  386. module_exit(svwks_ide_exit);
  387. MODULE_AUTHOR("Michael Aubry. Andrzej Krzysztofowicz, Andre Hedrick, Bartlomiej Zolnierkiewicz");
  388. MODULE_DESCRIPTION("PCI driver module for Serverworks OSB4/CSB5/CSB6 IDE");
  389. MODULE_LICENSE("GPL");