serverworks.c 13 KB

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