serverworks.c 19 KB

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