serverworks.c 14 KB

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