serverworks.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*
  2. * linux/drivers/ide/pci/serverworks.c Version 0.8 25 Ebr 2003
  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. * Portions copyright (c) 2001 Sun Microsystems
  8. *
  9. *
  10. * RCC/ServerWorks IDE driver for Linux
  11. *
  12. * OSB4: `Open South Bridge' IDE Interface (fn 1)
  13. * supports UDMA mode 2 (33 MB/s)
  14. *
  15. * CSB5: `Champion South Bridge' IDE Interface (fn 1)
  16. * all revisions support UDMA mode 4 (66 MB/s)
  17. * revision A2.0 and up support UDMA mode 5 (100 MB/s)
  18. *
  19. * *** The CSB5 does not provide ANY register ***
  20. * *** to detect 80-conductor cable presence. ***
  21. *
  22. * CSB6: `Champion South Bridge' IDE Interface (optional: third channel)
  23. *
  24. * HT1000: AKA BCM5785 - Hypertransport Southbridge for Opteron systems. IDE
  25. * controller same as the CSB6. Single channel ATA100 only.
  26. *
  27. * Documentation:
  28. * Available under NDA only. Errata info very hard to get.
  29. *
  30. */
  31. #include <linux/config.h>
  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 u8 svwks_revision = 0;
  54. static struct pci_dev *isa_dev;
  55. static int check_in_drive_lists (ide_drive_t *drive, const char **list)
  56. {
  57. while (*list)
  58. if (!strcmp(*list++, drive->id->model))
  59. return 1;
  60. return 0;
  61. }
  62. static u8 svwks_ratemask (ide_drive_t *drive)
  63. {
  64. struct pci_dev *dev = HWIF(drive)->pci_dev;
  65. u8 mode;
  66. if (!svwks_revision)
  67. pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision);
  68. if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE)
  69. return 2;
  70. if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
  71. u32 reg = 0;
  72. if (isa_dev)
  73. pci_read_config_dword(isa_dev, 0x64, &reg);
  74. /*
  75. * Don't enable UDMA on disk devices for the moment
  76. */
  77. if(drive->media == ide_disk)
  78. return 0;
  79. /* Check the OSB4 DMA33 enable bit */
  80. return ((reg & 0x00004000) == 0x00004000) ? 1 : 0;
  81. } else if (svwks_revision < SVWKS_CSB5_REVISION_NEW) {
  82. return 1;
  83. } else if (svwks_revision >= SVWKS_CSB5_REVISION_NEW) {
  84. u8 btr = 0;
  85. pci_read_config_byte(dev, 0x5A, &btr);
  86. mode = btr & 0x3;
  87. if (!eighty_ninty_three(drive))
  88. mode = min(mode, (u8)1);
  89. /* If someone decides to do UDMA133 on CSB5 the same
  90. issue will bite so be inclusive */
  91. if (mode > 2 && check_in_drive_lists(drive, svwks_bad_ata100))
  92. mode = 2;
  93. }
  94. if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
  95. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) &&
  96. (!(PCI_FUNC(dev->devfn) & 1)))
  97. mode = 2;
  98. return mode;
  99. }
  100. static u8 svwks_csb_check (struct pci_dev *dev)
  101. {
  102. switch (dev->device) {
  103. case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE:
  104. case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE:
  105. case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2:
  106. case PCI_DEVICE_ID_SERVERWORKS_HT1000IDE:
  107. return 1;
  108. default:
  109. break;
  110. }
  111. return 0;
  112. }
  113. static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
  114. {
  115. u8 udma_modes[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
  116. u8 dma_modes[] = { 0x77, 0x21, 0x20 };
  117. u8 pio_modes[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 };
  118. u8 drive_pci[] = { 0x41, 0x40, 0x43, 0x42 };
  119. u8 drive_pci2[] = { 0x45, 0x44, 0x47, 0x46 };
  120. ide_hwif_t *hwif = HWIF(drive);
  121. struct pci_dev *dev = hwif->pci_dev;
  122. u8 speed;
  123. u8 pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
  124. u8 unit = (drive->select.b.unit & 0x01);
  125. u8 csb5 = svwks_csb_check(dev);
  126. u8 ultra_enable = 0, ultra_timing = 0;
  127. u8 dma_timing = 0, pio_timing = 0;
  128. u16 csb5_pio = 0;
  129. if (xferspeed == 255) /* PIO auto-tuning */
  130. speed = XFER_PIO_0 + pio;
  131. else
  132. speed = ide_rate_filter(svwks_ratemask(drive), xferspeed);
  133. /* If we are about to put a disk into UDMA mode we screwed up.
  134. Our code assumes we never _ever_ do this on an OSB4 */
  135. if(dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4 &&
  136. drive->media == ide_disk && speed >= XFER_UDMA_0)
  137. BUG();
  138. pci_read_config_byte(dev, drive_pci[drive->dn], &pio_timing);
  139. pci_read_config_byte(dev, drive_pci2[drive->dn], &dma_timing);
  140. pci_read_config_byte(dev, (0x56|hwif->channel), &ultra_timing);
  141. pci_read_config_word(dev, 0x4A, &csb5_pio);
  142. pci_read_config_byte(dev, 0x54, &ultra_enable);
  143. /* Per Specified Design by OEM, and ASIC Architect */
  144. if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
  145. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) {
  146. if (!drive->init_speed) {
  147. u8 dma_stat = hwif->INB(hwif->dma_status);
  148. dma_pio:
  149. if (((ultra_enable << (7-drive->dn) & 0x80) == 0x80) &&
  150. ((dma_stat & (1<<(5+unit))) == (1<<(5+unit)))) {
  151. drive->current_speed = drive->init_speed = XFER_UDMA_0 + udma_modes[(ultra_timing >> (4*unit)) & ~(0xF0)];
  152. return 0;
  153. } else if ((dma_timing) &&
  154. ((dma_stat&(1<<(5+unit)))==(1<<(5+unit)))) {
  155. u8 dmaspeed = dma_timing;
  156. dma_timing &= ~0xFF;
  157. if ((dmaspeed & 0x20) == 0x20)
  158. dmaspeed = XFER_MW_DMA_2;
  159. else if ((dmaspeed & 0x21) == 0x21)
  160. dmaspeed = XFER_MW_DMA_1;
  161. else if ((dmaspeed & 0x77) == 0x77)
  162. dmaspeed = XFER_MW_DMA_0;
  163. else
  164. goto dma_pio;
  165. drive->current_speed = drive->init_speed = dmaspeed;
  166. return 0;
  167. } else if (pio_timing) {
  168. u8 piospeed = pio_timing;
  169. pio_timing &= ~0xFF;
  170. if ((piospeed & 0x20) == 0x20)
  171. piospeed = XFER_PIO_4;
  172. else if ((piospeed & 0x22) == 0x22)
  173. piospeed = XFER_PIO_3;
  174. else if ((piospeed & 0x34) == 0x34)
  175. piospeed = XFER_PIO_2;
  176. else if ((piospeed & 0x47) == 0x47)
  177. piospeed = XFER_PIO_1;
  178. else if ((piospeed & 0x5d) == 0x5d)
  179. piospeed = XFER_PIO_0;
  180. else
  181. goto oem_setup_failed;
  182. drive->current_speed = drive->init_speed = piospeed;
  183. return 0;
  184. }
  185. }
  186. }
  187. oem_setup_failed:
  188. pio_timing &= ~0xFF;
  189. dma_timing &= ~0xFF;
  190. ultra_timing &= ~(0x0F << (4*unit));
  191. ultra_enable &= ~(0x01 << drive->dn);
  192. csb5_pio &= ~(0x0F << (4*drive->dn));
  193. switch(speed) {
  194. case XFER_PIO_4:
  195. case XFER_PIO_3:
  196. case XFER_PIO_2:
  197. case XFER_PIO_1:
  198. case XFER_PIO_0:
  199. pio_timing |= pio_modes[speed - XFER_PIO_0];
  200. csb5_pio |= ((speed - XFER_PIO_0) << (4*drive->dn));
  201. break;
  202. case XFER_MW_DMA_2:
  203. case XFER_MW_DMA_1:
  204. case XFER_MW_DMA_0:
  205. pio_timing |= pio_modes[pio];
  206. csb5_pio |= (pio << (4*drive->dn));
  207. dma_timing |= dma_modes[speed - XFER_MW_DMA_0];
  208. break;
  209. case XFER_UDMA_5:
  210. case XFER_UDMA_4:
  211. case XFER_UDMA_3:
  212. case XFER_UDMA_2:
  213. case XFER_UDMA_1:
  214. case XFER_UDMA_0:
  215. pio_timing |= pio_modes[pio];
  216. csb5_pio |= (pio << (4*drive->dn));
  217. dma_timing |= dma_modes[2];
  218. ultra_timing |= ((udma_modes[speed - XFER_UDMA_0]) << (4*unit));
  219. ultra_enable |= (0x01 << drive->dn);
  220. default:
  221. break;
  222. }
  223. pci_write_config_byte(dev, drive_pci[drive->dn], pio_timing);
  224. if (csb5)
  225. pci_write_config_word(dev, 0x4A, csb5_pio);
  226. pci_write_config_byte(dev, drive_pci2[drive->dn], dma_timing);
  227. pci_write_config_byte(dev, (0x56|hwif->channel), ultra_timing);
  228. pci_write_config_byte(dev, 0x54, ultra_enable);
  229. return (ide_config_drive_speed(drive, speed));
  230. }
  231. static void config_chipset_for_pio (ide_drive_t *drive)
  232. {
  233. u16 eide_pio_timing[6] = {960, 480, 240, 180, 120, 90};
  234. u16 xfer_pio = drive->id->eide_pio_modes;
  235. u8 timing, speed, pio;
  236. pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
  237. if (xfer_pio > 4)
  238. xfer_pio = 0;
  239. if (drive->id->eide_pio_iordy > 0)
  240. for (xfer_pio = 5;
  241. xfer_pio>0 &&
  242. drive->id->eide_pio_iordy>eide_pio_timing[xfer_pio];
  243. xfer_pio--);
  244. else
  245. xfer_pio = (drive->id->eide_pio_modes & 4) ? 0x05 :
  246. (drive->id->eide_pio_modes & 2) ? 0x04 :
  247. (drive->id->eide_pio_modes & 1) ? 0x03 :
  248. (drive->id->tPIO & 2) ? 0x02 :
  249. (drive->id->tPIO & 1) ? 0x01 : xfer_pio;
  250. timing = (xfer_pio >= pio) ? xfer_pio : pio;
  251. switch(timing) {
  252. case 4: speed = XFER_PIO_4;break;
  253. case 3: speed = XFER_PIO_3;break;
  254. case 2: speed = XFER_PIO_2;break;
  255. case 1: speed = XFER_PIO_1;break;
  256. default:
  257. speed = (!drive->id->tPIO) ? XFER_PIO_0 : XFER_PIO_SLOW;
  258. break;
  259. }
  260. (void) svwks_tune_chipset(drive, speed);
  261. drive->current_speed = speed;
  262. }
  263. static void svwks_tune_drive (ide_drive_t *drive, u8 pio)
  264. {
  265. if(pio == 255)
  266. (void) svwks_tune_chipset(drive, 255);
  267. else
  268. (void) svwks_tune_chipset(drive, (XFER_PIO_0 + pio));
  269. }
  270. static int config_chipset_for_dma (ide_drive_t *drive)
  271. {
  272. u8 speed = ide_dma_speed(drive, svwks_ratemask(drive));
  273. if (!(speed))
  274. speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL);
  275. (void) svwks_tune_chipset(drive, speed);
  276. return ide_dma_enable(drive);
  277. }
  278. static int svwks_config_drive_xfer_rate (ide_drive_t *drive)
  279. {
  280. ide_hwif_t *hwif = HWIF(drive);
  281. struct hd_driveid *id = drive->id;
  282. drive->init_speed = 0;
  283. if ((id->capability & 1) && drive->autodma) {
  284. if (ide_use_dma(drive)) {
  285. if (config_chipset_for_dma(drive))
  286. return hwif->ide_dma_on(drive);
  287. }
  288. goto fast_ata_pio;
  289. } else if ((id->capability & 8) || (id->field_valid & 2)) {
  290. fast_ata_pio:
  291. config_chipset_for_pio(drive);
  292. // hwif->tuneproc(drive, 5);
  293. return hwif->ide_dma_off_quietly(drive);
  294. }
  295. /* IORDY not supported */
  296. return 0;
  297. }
  298. /* This can go soon */
  299. static int svwks_ide_dma_end (ide_drive_t *drive)
  300. {
  301. return __ide_dma_end(drive);
  302. }
  303. static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const char *name)
  304. {
  305. unsigned int reg;
  306. u8 btr;
  307. /* save revision id to determine DMA capability */
  308. pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision);
  309. /* force Master Latency Timer value to 64 PCICLKs */
  310. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x40);
  311. /* OSB4 : South Bridge and IDE */
  312. if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
  313. isa_dev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS,
  314. PCI_DEVICE_ID_SERVERWORKS_OSB4, NULL);
  315. if (isa_dev) {
  316. pci_read_config_dword(isa_dev, 0x64, &reg);
  317. reg &= ~0x00002000; /* disable 600ns interrupt mask */
  318. if(!(reg & 0x00004000))
  319. printk(KERN_DEBUG "%s: UDMA not BIOS enabled.\n", name);
  320. reg |= 0x00004000; /* enable UDMA/33 support */
  321. pci_write_config_dword(isa_dev, 0x64, reg);
  322. }
  323. }
  324. /* setup CSB5/CSB6 : South Bridge and IDE option RAID */
  325. else if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) ||
  326. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
  327. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) {
  328. /* Third Channel Test */
  329. if (!(PCI_FUNC(dev->devfn) & 1)) {
  330. struct pci_dev * findev = NULL;
  331. u32 reg4c = 0;
  332. findev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS,
  333. PCI_DEVICE_ID_SERVERWORKS_CSB5, NULL);
  334. if (findev) {
  335. pci_read_config_dword(findev, 0x4C, &reg4c);
  336. reg4c &= ~0x000007FF;
  337. reg4c |= 0x00000040;
  338. reg4c |= 0x00000020;
  339. pci_write_config_dword(findev, 0x4C, reg4c);
  340. }
  341. outb_p(0x06, 0x0c00);
  342. dev->irq = inb_p(0x0c01);
  343. #if 0
  344. printk("%s: device class (0x%04x)\n",
  345. name, dev->class);
  346. if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE) {
  347. dev->class &= ~0x000F0F00;
  348. // dev->class |= ~0x00000400;
  349. dev->class |= ~0x00010100;
  350. /**/
  351. }
  352. #endif
  353. } else {
  354. struct pci_dev * findev = NULL;
  355. u8 reg41 = 0;
  356. findev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS,
  357. PCI_DEVICE_ID_SERVERWORKS_CSB6, NULL);
  358. if (findev) {
  359. pci_read_config_byte(findev, 0x41, &reg41);
  360. reg41 &= ~0x40;
  361. pci_write_config_byte(findev, 0x41, reg41);
  362. }
  363. /*
  364. * This is a device pin issue on CSB6.
  365. * Since there will be a future raid mode,
  366. * early versions of the chipset require the
  367. * interrupt pin to be set, and it is a compatibility
  368. * mode issue.
  369. */
  370. if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
  371. dev->irq = 0;
  372. }
  373. // pci_read_config_dword(dev, 0x40, &pioreg)
  374. // pci_write_config_dword(dev, 0x40, 0x99999999);
  375. // pci_read_config_dword(dev, 0x44, &dmareg);
  376. // pci_write_config_dword(dev, 0x44, 0xFFFFFFFF);
  377. /* setup the UDMA Control register
  378. *
  379. * 1. clear bit 6 to enable DMA
  380. * 2. enable DMA modes with bits 0-1
  381. * 00 : legacy
  382. * 01 : udma2
  383. * 10 : udma2/udma4
  384. * 11 : udma2/udma4/udma5
  385. */
  386. pci_read_config_byte(dev, 0x5A, &btr);
  387. btr &= ~0x40;
  388. if (!(PCI_FUNC(dev->devfn) & 1))
  389. btr |= 0x2;
  390. else
  391. btr |= (svwks_revision >= SVWKS_CSB5_REVISION_NEW) ? 0x3 : 0x2;
  392. pci_write_config_byte(dev, 0x5A, btr);
  393. }
  394. /* Setup HT1000 SouthBridge Controller - Single Channel Only */
  395. else if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE) {
  396. pci_read_config_byte(dev, 0x5A, &btr);
  397. btr &= ~0x40;
  398. btr |= 0x3;
  399. pci_write_config_byte(dev, 0x5A, btr);
  400. }
  401. return (dev->irq) ? dev->irq : 0;
  402. }
  403. static unsigned int __devinit ata66_svwks_svwks (ide_hwif_t *hwif)
  404. {
  405. return 1;
  406. }
  407. /* On Dell PowerEdge servers with a CSB5/CSB6, the top two bits
  408. * of the subsystem device ID indicate presence of an 80-pin cable.
  409. * Bit 15 clear = secondary IDE channel does not have 80-pin cable.
  410. * Bit 15 set = secondary IDE channel has 80-pin cable.
  411. * Bit 14 clear = primary IDE channel does not have 80-pin cable.
  412. * Bit 14 set = primary IDE channel has 80-pin cable.
  413. */
  414. static unsigned int __devinit ata66_svwks_dell (ide_hwif_t *hwif)
  415. {
  416. struct pci_dev *dev = hwif->pci_dev;
  417. if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
  418. dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
  419. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE ||
  420. dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE))
  421. return ((1 << (hwif->channel + 14)) &
  422. dev->subsystem_device) ? 1 : 0;
  423. return 0;
  424. }
  425. /* Sun Cobalt Alpine hardware avoids the 80-pin cable
  426. * detect issue by attaching the drives directly to the board.
  427. * This check follows the Dell precedent (how scary is that?!)
  428. *
  429. * WARNING: this only works on Alpine hardware!
  430. */
  431. static unsigned int __devinit ata66_svwks_cobalt (ide_hwif_t *hwif)
  432. {
  433. struct pci_dev *dev = hwif->pci_dev;
  434. if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN &&
  435. dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
  436. dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE)
  437. return ((1 << (hwif->channel + 14)) &
  438. dev->subsystem_device) ? 1 : 0;
  439. return 0;
  440. }
  441. static unsigned int __devinit ata66_svwks (ide_hwif_t *hwif)
  442. {
  443. struct pci_dev *dev = hwif->pci_dev;
  444. /* Per Specified Design by OEM, and ASIC Architect */
  445. if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
  446. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2))
  447. return 1;
  448. /* Server Works */
  449. if (dev->subsystem_vendor == PCI_VENDOR_ID_SERVERWORKS)
  450. return ata66_svwks_svwks (hwif);
  451. /* Dell PowerEdge */
  452. if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL)
  453. return ata66_svwks_dell (hwif);
  454. /* Cobalt Alpine */
  455. if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN)
  456. return ata66_svwks_cobalt (hwif);
  457. return 0;
  458. }
  459. #undef CAN_SW_DMA
  460. static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
  461. {
  462. u8 dma_stat = 0;
  463. if (!hwif->irq)
  464. hwif->irq = hwif->channel ? 15 : 14;
  465. hwif->tuneproc = &svwks_tune_drive;
  466. hwif->speedproc = &svwks_tune_chipset;
  467. hwif->atapi_dma = 1;
  468. if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE)
  469. hwif->ultra_mask = 0x3f;
  470. hwif->mwdma_mask = 0x07;
  471. #ifdef CAN_SW_DMA
  472. hwif->swdma_mask = 0x07;
  473. #endif /* CAN_SW_DMA */
  474. hwif->autodma = 0;
  475. if (!hwif->dma_base) {
  476. hwif->drives[0].autotune = 1;
  477. hwif->drives[1].autotune = 1;
  478. return;
  479. }
  480. hwif->ide_dma_check = &svwks_config_drive_xfer_rate;
  481. if (hwif->pci_dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE)
  482. hwif->ide_dma_end = &svwks_ide_dma_end;
  483. else if (!(hwif->udma_four))
  484. hwif->udma_four = ata66_svwks(hwif);
  485. if (!noautodma)
  486. hwif->autodma = 1;
  487. dma_stat = hwif->INB(hwif->dma_status);
  488. hwif->drives[0].autodma = (dma_stat & 0x20);
  489. hwif->drives[1].autodma = (dma_stat & 0x40);
  490. hwif->drives[0].autotune = (!(dma_stat & 0x20));
  491. hwif->drives[1].autotune = (!(dma_stat & 0x40));
  492. // hwif->drives[0].autodma = hwif->autodma;
  493. // hwif->drives[1].autodma = hwif->autodma;
  494. }
  495. /*
  496. * We allow the BM-DMA driver to only work on enabled interfaces.
  497. */
  498. static void __devinit init_dma_svwks (ide_hwif_t *hwif, unsigned long dmabase)
  499. {
  500. struct pci_dev *dev = hwif->pci_dev;
  501. if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
  502. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) &&
  503. (!(PCI_FUNC(dev->devfn) & 1)) && (hwif->channel))
  504. return;
  505. ide_setup_dma(hwif, dmabase, 8);
  506. }
  507. static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d)
  508. {
  509. return ide_setup_pci_device(dev, d);
  510. }
  511. static int __devinit init_setup_csb6 (struct pci_dev *dev, ide_pci_device_t *d)
  512. {
  513. if (!(PCI_FUNC(dev->devfn) & 1)) {
  514. d->bootable = NEVER_BOARD;
  515. if (dev->resource[0].start == 0x01f1)
  516. d->bootable = ON_BOARD;
  517. }
  518. #if 0
  519. if ((IDE_PCI_DEVID_EQ(d->devid, DEVID_CSB6) &&
  520. (!(PCI_FUNC(dev->devfn) & 1)))
  521. d->autodma = AUTODMA;
  522. #endif
  523. d->channels = ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE ||
  524. dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2) &&
  525. (!(PCI_FUNC(dev->devfn) & 1))) ? 1 : 2;
  526. return ide_setup_pci_device(dev, d);
  527. }
  528. static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
  529. { /* 0 */
  530. .name = "SvrWks OSB4",
  531. .init_setup = init_setup_svwks,
  532. .init_chipset = init_chipset_svwks,
  533. .init_hwif = init_hwif_svwks,
  534. .channels = 2,
  535. .autodma = AUTODMA,
  536. .bootable = ON_BOARD,
  537. },{ /* 1 */
  538. .name = "SvrWks CSB5",
  539. .init_setup = init_setup_svwks,
  540. .init_chipset = init_chipset_svwks,
  541. .init_hwif = init_hwif_svwks,
  542. .init_dma = init_dma_svwks,
  543. .channels = 2,
  544. .autodma = AUTODMA,
  545. .bootable = ON_BOARD,
  546. },{ /* 2 */
  547. .name = "SvrWks CSB6",
  548. .init_setup = init_setup_csb6,
  549. .init_chipset = init_chipset_svwks,
  550. .init_hwif = init_hwif_svwks,
  551. .init_dma = init_dma_svwks,
  552. .channels = 2,
  553. .autodma = AUTODMA,
  554. .bootable = ON_BOARD,
  555. },{ /* 3 */
  556. .name = "SvrWks CSB6",
  557. .init_setup = init_setup_csb6,
  558. .init_chipset = init_chipset_svwks,
  559. .init_hwif = init_hwif_svwks,
  560. .init_dma = init_dma_svwks,
  561. .channels = 1, /* 2 */
  562. .autodma = AUTODMA,
  563. .bootable = ON_BOARD,
  564. },{ /* 4 */
  565. .name = "SvrWks HT1000",
  566. .init_setup = init_setup_svwks,
  567. .init_chipset = init_chipset_svwks,
  568. .init_hwif = init_hwif_svwks,
  569. .init_dma = init_dma_svwks,
  570. .channels = 1, /* 2 */
  571. .autodma = AUTODMA,
  572. .bootable = ON_BOARD,
  573. }
  574. };
  575. /**
  576. * svwks_init_one - called when a OSB/CSB is found
  577. * @dev: the svwks device
  578. * @id: the matching pci id
  579. *
  580. * Called when the PCI registration layer (or the IDE initialization)
  581. * finds a device matching our IDE device tables.
  582. */
  583. static int __devinit svwks_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  584. {
  585. ide_pci_device_t *d = &serverworks_chipsets[id->driver_data];
  586. return d->init_setup(dev, d);
  587. }
  588. static struct pci_device_id svwks_pci_tbl[] = {
  589. { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  590. { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
  591. { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
  592. { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
  593. { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
  594. { 0, },
  595. };
  596. MODULE_DEVICE_TABLE(pci, svwks_pci_tbl);
  597. static struct pci_driver driver = {
  598. .name = "Serverworks_IDE",
  599. .id_table = svwks_pci_tbl,
  600. .probe = svwks_init_one,
  601. };
  602. static int svwks_ide_init(void)
  603. {
  604. return ide_pci_register_driver(&driver);
  605. }
  606. module_init(svwks_ide_init);
  607. MODULE_AUTHOR("Michael Aubry. Andrzej Krzysztofowicz, Andre Hedrick");
  608. MODULE_DESCRIPTION("PCI driver module for Serverworks OSB4/CSB5/CSB6 IDE");
  609. MODULE_LICENSE("GPL");