serverworks.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:21k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * linux/drivers/ide/serverworks.c Version 0.3 26 Oct 2001
  3.  *
  4.  * May be copied or modified under the terms of the GNU General Public License
  5.  *
  6.  * Copyright (C) 1998-2000 Michel Aubry
  7.  * Copyright (C) 1998-2000 Andrzej Krzysztofowicz
  8.  * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
  9.  * Portions copyright (c) 2001 Sun Microsystems
  10.  *
  11.  *
  12.  * RCC/ServerWorks IDE driver for Linux
  13.  *
  14.  *   OSB4: `Open South Bridge' IDE Interface (fn 1)
  15.  *         supports UDMA mode 2 (33 MB/s)
  16.  *
  17.  *   CSB5: `Champion South Bridge' IDE Interface (fn 1)
  18.  *         all revisions support UDMA mode 4 (66 MB/s)
  19.  *         revision A2.0 and up support UDMA mode 5 (100 MB/s)
  20.  *
  21.  *         *** The CSB5 does not provide ANY register ***
  22.  *         *** to detect 80-conductor cable presence. ***
  23.  *
  24.  *
  25.  * here's the default lspci:
  26.  *
  27.  * 00:0f.1 IDE interface: ServerWorks: Unknown device 0211 (prog-if 8a [Master SecP PriP])
  28.  * Control: I/O+ Mem- BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B-
  29.  * Status: Cap- 66Mhz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
  30.  * Latency: 255
  31.  * Region 4: I/O ports at c200
  32.  * 00: 66 11 11 02 05 01 00 02 00 8a 01 01 00 ff 80 00
  33.  * 10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  34.  * 20: 01 c2 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  35.  * 30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  36.  * 40: 99 99 99 99 ff ff ff ff 0c 0c 00 00 00 00 00 00
  37.  * 50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  38.  * 60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  39.  * 70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  40.  * 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  41.  * 90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  42.  * a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  43.  * b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  44.  * c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  45.  * d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  46.  * e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  47.  * f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  48.  *
  49.  * 00:0f.1 IDE interface: ServerWorks: Unknown device 0212 (rev 92) (prog-if 8a [Master SecP PriP])
  50.  *         Subsystem: ServerWorks: Unknown device 0212
  51.  *         Control: I/O+ Mem- BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
  52.  *         Status: Cap- 66Mhz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
  53.  *         Latency: 64, cache line size 08
  54.  *         Region 0: I/O ports at 01f0
  55.  *         Region 1: I/O ports at 03f4
  56.  *         Region 2: I/O ports at 0170
  57.  *         Region 3: I/O ports at 0374
  58.  *         Region 4: I/O ports at 08b0
  59.  *         Region 5: I/O ports at 1000
  60.  *
  61.  * 00:0f.1 IDE interface: ServerWorks: Unknown device 0212 (rev 92)
  62.  * 00: 66 11 12 02 05 00 00 02 92 8a 01 01 08 40 80 00
  63.  * 10: f1 01 00 00 f5 03 00 00 71 01 00 00 75 03 00 00
  64.  * 20: b1 08 00 00 01 10 00 00 00 00 00 00 66 11 12 02
  65.  * 30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  66.  * 40: 4f 4f 4f 4f 20 ff ff ff f0 50 44 44 00 00 00 00
  67.  * 50: 00 00 00 00 07 00 44 02 0f 04 03 00 00 00 00 00
  68.  * 60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  69.  * 70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  70.  * 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  71.  * 90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  72.  * a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  73.  * b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  74.  * c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  75.  * d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  76.  * e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  77.  * f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  78.  *
  79.  *
  80.  */
  81. #include <linux/config.h>
  82. #include <linux/types.h>
  83. #include <linux/kernel.h>
  84. #include <linux/ioport.h>
  85. #include <linux/pci.h>
  86. #include <linux/hdreg.h>
  87. #include <linux/ide.h>
  88. #include <linux/init.h>
  89. #include <linux/delay.h>
  90. #include <asm/io.h>
  91. #include "ide_modes.h"
  92. #define DISPLAY_SVWKS_TIMINGS 1
  93. #undef SVWKS_DEBUG_DRIVE_INFO
  94. #if defined(DISPLAY_SVWKS_TIMINGS) && defined(CONFIG_PROC_FS)
  95. #include <linux/stat.h>
  96. #include <linux/proc_fs.h>
  97. static struct pci_dev *bmide_dev;
  98. static byte svwks_revision = 0;
  99. static int svwks_get_info(char *, char **, off_t, int);
  100. extern int (*svwks_display_info)(char *, char **, off_t, int); /* ide-proc.c */
  101. extern char *ide_media_verbose(ide_drive_t *);
  102. static int svwks_get_info (char *buffer, char **addr, off_t offset, int count)
  103. {
  104. char *p = buffer;
  105. u32 bibma = pci_resource_start(bmide_dev, 4);
  106. u32 reg40, reg44;
  107. u16 reg48, reg56;
  108. u8  reg54, c0=0, c1=0;
  109. pci_read_config_dword(bmide_dev, 0x40, &reg40);
  110. pci_read_config_dword(bmide_dev, 0x44, &reg44);
  111. pci_read_config_word(bmide_dev, 0x48, &reg48);
  112. pci_read_config_byte(bmide_dev, 0x54, &reg54);
  113. pci_read_config_word(bmide_dev, 0x56, &reg56);
  114.         /*
  115.          * at that point bibma+0x2 et bibma+0xa are byte registers
  116.          * to investigate:
  117.          */
  118. c0 = inb_p((unsigned short)bibma + 0x02);
  119. c1 = inb_p((unsigned short)bibma + 0x0a);
  120. switch(bmide_dev->device) {
  121. case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE:
  122. p += sprintf(p, "n                            "
  123.      "ServerWorks CSB5 Chipset (rev %02x)n",
  124.      svwks_revision);
  125. break;
  126. case PCI_DEVICE_ID_SERVERWORKS_OSB4IDE:
  127. p += sprintf(p, "n                            "
  128.      "ServerWorks OSB4 Chipset (rev %02x)n",
  129.      svwks_revision);
  130. break;
  131. default:
  132. p += sprintf(p, "n                            "
  133.      "ServerWorks %04x Chipset (rev %02x)n",
  134.      bmide_dev->device, svwks_revision);
  135. break;
  136. }
  137. p += sprintf(p, "------------------------------- General Status ---------------------------------n");
  138. p += sprintf(p, "--------------- Primary Channel ---------------- Secondary Channel -------------n");
  139. p += sprintf(p, "                %sabled                         %sabledn",
  140. (c0&0x80) ? "dis" : " en",
  141. (c1&0x80) ? "dis" : " en");
  142. p += sprintf(p, "--------------- drive0 --------- drive1 -------- drive0 ---------- drive1 ------n");
  143. p += sprintf(p, "DMA enabled:    %s              %s             %s               %sn",
  144. (c0&0x20) ? "yes" : "no ",
  145. (c0&0x40) ? "yes" : "no ",
  146. (c1&0x20) ? "yes" : "no ",
  147. (c1&0x40) ? "yes" : "no " );
  148. p += sprintf(p, "UDMA enabled:   %s              %s             %s               %sn",
  149. (reg54 & 0x01) ? "yes" : "no ",
  150. (reg54 & 0x02) ? "yes" : "no ",
  151. (reg54 & 0x04) ? "yes" : "no ",
  152. (reg54 & 0x08) ? "yes" : "no " );
  153. p += sprintf(p, "UDMA enabled:   %s                %s               %s                 %sn",
  154. ((reg56&0x0005)==0x0005)?"5":
  155. ((reg56&0x0004)==0x0004)?"4":
  156. ((reg56&0x0003)==0x0003)?"3":
  157. ((reg56&0x0002)==0x0002)?"2":
  158. ((reg56&0x0001)==0x0001)?"1":
  159. ((reg56&0x000F))?"?":"0",
  160. ((reg56&0x0050)==0x0050)?"5":
  161. ((reg56&0x0040)==0x0040)?"4":
  162. ((reg56&0x0030)==0x0030)?"3":
  163. ((reg56&0x0020)==0x0020)?"2":
  164. ((reg56&0x0010)==0x0010)?"1":
  165. ((reg56&0x00F0))?"?":"0",
  166. ((reg56&0x0500)==0x0500)?"5":
  167. ((reg56&0x0400)==0x0400)?"4":
  168. ((reg56&0x0300)==0x0300)?"3":
  169. ((reg56&0x0200)==0x0200)?"2":
  170. ((reg56&0x0100)==0x0100)?"1":
  171. ((reg56&0x0F00))?"?":"0",
  172. ((reg56&0x5000)==0x5000)?"5":
  173. ((reg56&0x4000)==0x4000)?"4":
  174. ((reg56&0x3000)==0x3000)?"3":
  175. ((reg56&0x2000)==0x2000)?"2":
  176. ((reg56&0x1000)==0x1000)?"1":
  177. ((reg56&0xF000))?"?":"0");
  178. p += sprintf(p, "DMA enabled:    %s                %s               %s                 %sn",
  179. ((reg44&0x00002000)==0x00002000)?"2":
  180. ((reg44&0x00002100)==0x00002100)?"1":
  181. ((reg44&0x00007700)==0x00007700)?"0":
  182. ((reg44&0x0000FF00)==0x0000FF00)?"X":"?",
  183. ((reg44&0x00000020)==0x00000020)?"2":
  184. ((reg44&0x00000021)==0x00000021)?"1":
  185. ((reg44&0x00000077)==0x00000077)?"0":
  186. ((reg44&0x000000FF)==0x000000FF)?"X":"?",
  187. ((reg44&0x20000000)==0x20000000)?"2":
  188. ((reg44&0x21000000)==0x21000000)?"1":
  189. ((reg44&0x77000000)==0x77000000)?"0":
  190. ((reg44&0xFF000000)==0xFF000000)?"X":"?",
  191. ((reg44&0x00200000)==0x00200000)?"2":
  192. ((reg44&0x00210000)==0x00210000)?"1":
  193. ((reg44&0x00770000)==0x00770000)?"0":
  194. ((reg44&0x00FF0000)==0x00FF0000)?"X":"?");
  195. p += sprintf(p, "PIO  enabled:   %s                %s               %s                 %sn",
  196. ((reg40&0x00002000)==0x00002000)?"4":
  197. ((reg40&0x00002200)==0x00002200)?"3":
  198. ((reg40&0x00003400)==0x00003400)?"2":
  199. ((reg40&0x00004700)==0x00004700)?"1":
  200. ((reg40&0x00005D00)==0x00005D00)?"0":"?",
  201. ((reg40&0x00000020)==0x00000020)?"4":
  202. ((reg40&0x00000022)==0x00000022)?"3":
  203. ((reg40&0x00000034)==0x00000034)?"2":
  204. ((reg40&0x00000047)==0x00000047)?"1":
  205. ((reg40&0x0000005D)==0x0000005D)?"0":"?",
  206. ((reg40&0x20000000)==0x20000000)?"4":
  207. ((reg40&0x22000000)==0x22000000)?"3":
  208. ((reg40&0x34000000)==0x34000000)?"2":
  209. ((reg40&0x47000000)==0x47000000)?"1":
  210. ((reg40&0x5D000000)==0x5D000000)?"0":"?",
  211. ((reg40&0x00200000)==0x00200000)?"4":
  212. ((reg40&0x00220000)==0x00220000)?"3":
  213. ((reg40&0x00340000)==0x00340000)?"2":
  214. ((reg40&0x00470000)==0x00470000)?"1":
  215. ((reg40&0x005D0000)==0x005D0000)?"0":"?");
  216. return p-buffer;  /* => must be less than 4k! */
  217. }
  218. #endif  /* defined(DISPLAY_SVWKS_TIMINGS) && defined(CONFIG_PROC_FS) */
  219. #define SVWKS_CSB5_REVISION_NEW 0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */
  220. byte svwks_proc = 0;
  221. extern char *ide_xfer_verbose (byte xfer_rate);
  222. static struct pci_dev *isa_dev;
  223. static int svwks_tune_chipset (ide_drive_t *drive, byte speed)
  224. {
  225. byte udma_modes[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
  226. byte dma_modes[] = { 0x77, 0x21, 0x20 };
  227. byte pio_modes[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 };
  228. ide_hwif_t *hwif = HWIF(drive);
  229. struct pci_dev *dev = hwif->pci_dev;
  230. byte unit = (drive->select.b.unit & 0x01);
  231. byte csb5 = (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) ? 1 : 0;
  232. #ifdef CONFIG_BLK_DEV_IDEDMA
  233. unsigned long dma_base = hwif->dma_base;
  234. #endif /* CONFIG_BLK_DEV_IDEDMA */
  235. int err;
  236. byte drive_pci = 0x00;
  237. byte drive_pci2 = 0x00;
  238. byte drive_pci3 = hwif->channel ? 0x57 : 0x56;
  239. byte ultra_enable = 0x00;
  240. byte ultra_timing = 0x00;
  241. byte dma_timing = 0x00;
  242. byte pio_timing = 0x00;
  243. unsigned short csb5_pio = 0x00;
  244. byte pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
  245.         switch (drive->dn) {
  246. case 0: drive_pci = 0x41; drive_pci2 = 0x45; break;
  247. case 1: drive_pci = 0x40; drive_pci2 = 0x44; break;
  248. case 2: drive_pci = 0x43; drive_pci2 = 0x47; break;
  249. case 3: drive_pci = 0x42; drive_pci2 = 0x46; break;
  250. default:
  251. return -1;
  252. }
  253. pci_read_config_byte(dev, drive_pci, &pio_timing);
  254. pci_read_config_byte(dev, drive_pci2, &dma_timing);
  255. pci_read_config_byte(dev, drive_pci3, &ultra_timing);
  256. pci_read_config_word(dev, 0x4A, &csb5_pio);
  257. pci_read_config_byte(dev, 0x54, &ultra_enable);
  258. #ifdef DEBUG
  259. printk("%s: UDMA 0x%02x DMAPIO 0x%02x PIO 0x%02x ",
  260. drive->name, ultra_timing, dma_timing, pio_timing);
  261. #endif
  262. pio_timing &= ~0xFF;
  263. dma_timing &= ~0xFF;
  264. ultra_timing &= ~(0x0F << (4*unit));
  265. ultra_enable &= ~(0x01 << drive->dn);
  266. csb5_pio &= ~(0x0F << (4*drive->dn));
  267. switch(speed) {
  268. case XFER_PIO_4:
  269. case XFER_PIO_3:
  270. case XFER_PIO_2:
  271. case XFER_PIO_1:
  272. case XFER_PIO_0:
  273. pio_timing |= pio_modes[speed - XFER_PIO_0];
  274. csb5_pio   |= ((speed - XFER_PIO_0) << (4*drive->dn));
  275. break;
  276. #ifdef CONFIG_BLK_DEV_IDEDMA
  277. case XFER_MW_DMA_2:
  278. case XFER_MW_DMA_1:
  279. case XFER_MW_DMA_0:
  280. pio_timing |= pio_modes[pio];
  281. csb5_pio   |= (pio << (4*drive->dn));
  282. dma_timing |= dma_modes[speed - XFER_MW_DMA_0];
  283. break;
  284. case XFER_UDMA_5:
  285. case XFER_UDMA_4:
  286. case XFER_UDMA_3:
  287. case XFER_UDMA_2:
  288. case XFER_UDMA_1:
  289. case XFER_UDMA_0:
  290. pio_timing   |= pio_modes[pio];
  291. csb5_pio     |= (pio << (4*drive->dn));
  292. dma_timing   |= dma_modes[2];
  293. ultra_timing |= ((udma_modes[speed - XFER_UDMA_0]) << (4*unit));
  294. ultra_enable |= (0x01 << drive->dn);
  295. #endif
  296. default:
  297. break;
  298. }
  299. #ifdef DEBUG
  300. printk("%s: UDMA 0x%02x DMAPIO 0x%02x PIO 0x%02x ",
  301. drive->name, ultra_timing, dma_timing, pio_timing);
  302. #endif
  303. #if SVWKS_DEBUG_DRIVE_INFO
  304. printk("%s: %s drive%dn", drive->name, ide_xfer_verbose(speed), drive->dn);
  305. #endif /* SVWKS_DEBUG_DRIVE_INFO */
  306. if (!drive->init_speed)
  307. drive->init_speed = speed;
  308. pci_write_config_byte(dev, drive_pci, pio_timing);
  309. if (csb5)
  310. pci_write_config_word(dev, 0x4A, csb5_pio);
  311. #ifdef CONFIG_BLK_DEV_IDEDMA
  312. pci_write_config_byte(dev, drive_pci2, dma_timing);
  313. pci_write_config_byte(dev, drive_pci3, ultra_timing);
  314. pci_write_config_byte(dev, 0x54, ultra_enable);
  315. if (speed > XFER_PIO_4)
  316. outb(inb(dma_base+2)|(1<<(5+unit)), dma_base+2);
  317. else
  318. outb(inb(dma_base+2) & ~(1<<(5+unit)), dma_base+2);
  319. #endif /* CONFIG_BLK_DEV_IDEDMA */
  320. err = ide_config_drive_speed(drive, speed);
  321. drive->current_speed = speed;
  322. return err;
  323. }
  324. static void config_chipset_for_pio (ide_drive_t *drive)
  325. {
  326. unsigned short eide_pio_timing[6] = {960, 480, 240, 180, 120, 90};
  327. unsigned short xfer_pio = drive->id->eide_pio_modes;
  328. byte timing, speed, pio;
  329. pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
  330. if (xfer_pio> 4)
  331. xfer_pio = 0;
  332. if (drive->id->eide_pio_iordy > 0)
  333. for (xfer_pio = 5;
  334. xfer_pio>0 &&
  335. drive->id->eide_pio_iordy>eide_pio_timing[xfer_pio];
  336. xfer_pio--);
  337. else
  338. xfer_pio = (drive->id->eide_pio_modes & 4) ? 0x05 :
  339.    (drive->id->eide_pio_modes & 2) ? 0x04 :
  340.    (drive->id->eide_pio_modes & 1) ? 0x03 :
  341.    (drive->id->tPIO & 2) ? 0x02 :
  342.    (drive->id->tPIO & 1) ? 0x01 : xfer_pio;
  343. timing = (xfer_pio >= pio) ? xfer_pio : pio;
  344. switch(timing) {
  345. case 4: speed = XFER_PIO_4;break;
  346. case 3: speed = XFER_PIO_3;break;
  347. case 2: speed = XFER_PIO_2;break;
  348. case 1: speed = XFER_PIO_1;break;
  349. default:
  350. speed = (!drive->id->tPIO) ? XFER_PIO_0 : XFER_PIO_SLOW;
  351. break;
  352. }
  353. (void) svwks_tune_chipset(drive, speed);
  354. drive->current_speed = speed;
  355. }
  356. static void svwks_tune_drive (ide_drive_t *drive, byte pio)
  357. {
  358. byte speed;
  359. switch(pio) {
  360. case 4: speed = XFER_PIO_4;break;
  361. case 3: speed = XFER_PIO_3;break;
  362. case 2: speed = XFER_PIO_2;break;
  363. case 1: speed = XFER_PIO_1;break;
  364. default: speed = XFER_PIO_0;break;
  365. }
  366. (void) svwks_tune_chipset(drive, speed);
  367. }
  368. #ifdef CONFIG_BLK_DEV_IDEDMA
  369. static int config_chipset_for_dma (ide_drive_t *drive)
  370. {
  371. struct hd_driveid *id = drive->id;
  372. struct pci_dev *dev = HWIF(drive)->pci_dev;
  373. byte udma_66 = eighty_ninty_three(drive);
  374. int ultra66 = (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) ? 1 : 0;
  375. int ultra100  = (ultra66 && svwks_revision >= SVWKS_CSB5_REVISION_NEW) ? 1 : 0;
  376. byte speed;
  377. if ((id->dma_ultra & 0x0020) && (udma_66) && (ultra100)) {
  378. speed = XFER_UDMA_5;
  379. } else if (id->dma_ultra & 0x0010) {
  380. speed = ((udma_66) && (ultra66)) ? XFER_UDMA_4 : XFER_UDMA_2;
  381. } else if (id->dma_ultra & 0x0008) {
  382. speed = ((udma_66) && (ultra66)) ? XFER_UDMA_3 : XFER_UDMA_1;
  383. } else if (id->dma_ultra & 0x0004) {
  384. speed = XFER_UDMA_2;
  385. } else if (id->dma_ultra & 0x0002) {
  386. speed = XFER_UDMA_1;
  387. } else if (id->dma_ultra & 0x0001) {
  388. speed = XFER_UDMA_0;
  389. } else if (id->dma_mword & 0x0004) {
  390. speed = XFER_MW_DMA_2;
  391. } else if (id->dma_mword & 0x0002) {
  392. speed = XFER_MW_DMA_1;
  393. } else if (id->dma_1word & 0x0004) {
  394. speed = XFER_SW_DMA_2;
  395. } else {
  396. speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL);
  397. }
  398. (void) svwks_tune_chipset(drive, speed);
  399. return ((int) ((id->dma_ultra >> 11) & 7) ? ide_dma_on :
  400. ((id->dma_ultra >> 8) & 7) ? ide_dma_on :
  401. ((id->dma_mword >> 8) & 7) ? ide_dma_on :
  402. ((id->dma_1word >> 8) & 7) ? ide_dma_on :
  403.      ide_dma_off_quietly);
  404. }
  405. static int config_drive_xfer_rate (ide_drive_t *drive)
  406. {
  407. struct hd_driveid *id = drive->id;
  408. ide_dma_action_t dma_func = ide_dma_on;
  409. if (id && (id->capability & 1) && HWIF(drive)->autodma) {
  410. /* Consult the list of known "bad" drives */
  411. if (ide_dmaproc(ide_dma_bad_drive, drive)) {
  412. dma_func = ide_dma_off;
  413. goto fast_ata_pio;
  414. }
  415. dma_func = ide_dma_off_quietly;
  416. if (id->field_valid & 4) {
  417. if (id->dma_ultra & 0x003F) {
  418. /* Force if Capable UltraDMA */
  419. dma_func = config_chipset_for_dma(drive);
  420. if ((id->field_valid & 2) &&
  421.     (dma_func != ide_dma_on))
  422. goto try_dma_modes;
  423. }
  424. } else if (id->field_valid & 2) {
  425. try_dma_modes:
  426. if ((id->dma_mword & 0x0007) ||
  427.     (id->dma_1word & 0x007)) {
  428. /* Force if Capable regular DMA modes */
  429. dma_func = config_chipset_for_dma(drive);
  430. if (dma_func != ide_dma_on)
  431. goto no_dma_set;
  432. }
  433. } else if (ide_dmaproc(ide_dma_good_drive, drive)) {
  434. if (id->eide_dma_time > 150) {
  435. goto no_dma_set;
  436. }
  437. /* Consult the list of known "good" drives */
  438. dma_func = config_chipset_for_dma(drive);
  439. if (dma_func != ide_dma_on)
  440. goto no_dma_set;
  441. } else {
  442. goto fast_ata_pio;
  443. }
  444. } else if ((id->capability & 8) || (id->field_valid & 2)) {
  445. fast_ata_pio:
  446. dma_func = ide_dma_off_quietly;
  447. no_dma_set:
  448. config_chipset_for_pio(drive);
  449. }
  450. return HWIF(drive)->dmaproc(dma_func, drive);
  451. }
  452. static int svwks_dmaproc(ide_dma_action_t func, ide_drive_t *drive)
  453. {
  454. switch (func) {
  455. case ide_dma_check:
  456. return config_drive_xfer_rate(drive);
  457. case ide_dma_end:
  458. {
  459. ide_hwif_t *hwif = HWIF(drive);
  460. unsigned long dma_base = hwif->dma_base;
  461. if(inb(dma_base+0x02)&1)
  462. {
  463. #if 0
  464. int i;
  465. printk(KERN_ERR "Curious - OSB4 thinks the DMA is still running.n");
  466. for(i=0;i<10;i++)
  467. {
  468. if(!(inb(dma_base+0x02)&1))
  469. {
  470. printk(KERN_ERR "OSB4 now finished.n");
  471. break;
  472. }
  473. udelay(5);
  474. }
  475. #endif
  476. printk(KERN_CRIT "Serverworks OSB4 in impossible state.n");
  477. printk(KERN_CRIT "Disable UDMA or if you are using Seagate then try switching disk typesn");
  478. printk(KERN_CRIT "on this controller. Please report this event to osb4-bug@ide.cabal.tmn");
  479. #if 0
  480. /* Panic might sys_sync -> death by corrupt disk */
  481. panic("OSB4: continuing might cause disk corruption.n");
  482. #else
  483. printk(KERN_CRIT "OSB4: continuing might cause disk corruption.n");
  484. while(1)
  485. cpu_relax();
  486. #endif
  487. }
  488. /* and drop through */
  489. }
  490. default:
  491. break;
  492. }
  493. /* Other cases are done by generic IDE-DMA code. */
  494. return ide_dmaproc(func, drive);
  495. }
  496. #endif /* CONFIG_BLK_DEV_IDEDMA */
  497. unsigned int __init pci_init_svwks (struct pci_dev *dev, const char *name)
  498. {
  499. unsigned int reg;
  500. byte btr;
  501. /* save revision id to determine DMA capability */
  502. pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision);
  503. /* force Master Latency Timer value to 64 PCICLKs */
  504. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x40);
  505. /* OSB4 : South Bridge and IDE */
  506. if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
  507. isa_dev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS,
  508.   PCI_DEVICE_ID_SERVERWORKS_OSB4, NULL);
  509. if (isa_dev) {
  510. pci_read_config_dword(isa_dev, 0x64, &reg);
  511. reg &= ~0x00002000; /* disable 600ns interrupt mask */
  512. reg |=  0x00004000; /* enable UDMA/33 support */
  513. pci_write_config_dword(isa_dev, 0x64, reg);
  514. }
  515. }
  516. /* setup CSB5 : South Bridge and IDE */
  517. else if (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) {
  518. /* setup the UDMA Control register
  519.  *
  520.  * 1. clear bit 6 to enable DMA
  521.  * 2. enable DMA modes with bits 0-1
  522.  *      00 : legacy
  523.  *      01 : udma2
  524.  *      10 : udma2/udma4
  525.  *      11 : udma2/udma4/udma5
  526.  */
  527. pci_read_config_byte(dev, 0x5A, &btr);
  528. btr &= ~0x40;
  529. btr |= (svwks_revision >= SVWKS_CSB5_REVISION_NEW) ? 0x3 : 0x2;
  530. pci_write_config_byte(dev, 0x5A, btr);
  531. }
  532. #if defined(DISPLAY_SVWKS_TIMINGS) && defined(CONFIG_PROC_FS)
  533. if (!svwks_proc) {
  534. svwks_proc = 1;
  535. bmide_dev = dev;
  536. svwks_display_info = &svwks_get_info;
  537. }
  538. #endif /* DISPLAY_SVWKS_TIMINGS && CONFIG_PROC_FS */
  539. return 0;
  540. }
  541. /* On Dell PowerEdge servers with a CSB5, the top two bits of the subsystem
  542.  * device ID indicate presence of an 80-pin cable.
  543.  * Bit 15 clear = secondary IDE channel does not have 80-pin cable.
  544.  * Bit 15 set   = secondary IDE channel has 80-pin cable.
  545.  * Bit 14 clear = primary IDE channel does not have 80-pin cable.
  546.  * Bit 14 set   = primary IDE channel has 80-pin cable.
  547.  */
  548. static unsigned int __init ata66_svwks_dell (ide_hwif_t *hwif)
  549. {
  550. struct pci_dev *dev = hwif->pci_dev;
  551. if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
  552.     dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
  553.     dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE)
  554. return ((1 << (hwif->channel + 14)) &
  555. dev->subsystem_device) ? 1 : 0;
  556. return 0;
  557. }
  558. /* Sun Cobalt Alpine hardware avoids the 80-pin cable
  559.  * detect issue by attaching the drives directly to the board.
  560.  * This check follows the Dell precedent (how scary is that?!)
  561.  *
  562.  * WARNING: this only works on Alpine hardware!
  563.  */
  564. static unsigned int __init ata66_svwks_cobalt (ide_hwif_t *hwif)
  565. {
  566. struct pci_dev *dev = hwif->pci_dev;
  567. if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN &&
  568.     dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
  569.     dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE)
  570. return ((1 << (hwif->channel + 14)) &
  571. dev->subsystem_device) ? 1 : 0;
  572. return 0;
  573. }
  574. unsigned int __init ata66_svwks (ide_hwif_t *hwif)
  575. {
  576. struct pci_dev *dev = hwif->pci_dev;
  577. /* Dell PowerEdge */
  578. if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL)
  579. return ata66_svwks_dell (hwif);
  580. /* Cobalt Alpine */
  581. if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN)
  582. return ata66_svwks_cobalt (hwif);
  583. return 0;
  584. }
  585. void __init ide_init_svwks (ide_hwif_t *hwif)
  586. {
  587. if (!hwif->irq)
  588. hwif->irq = hwif->channel ? 15 : 14;
  589. hwif->tuneproc = &svwks_tune_drive;
  590. hwif->speedproc = &svwks_tune_chipset;
  591. #ifndef CONFIG_BLK_DEV_IDEDMA
  592. hwif->drives[0].autotune = 1;
  593. hwif->drives[1].autotune = 1;
  594. hwif->autodma = 0;
  595. #else /* CONFIG_BLK_DEV_IDEDMA */
  596. if (hwif->dma_base) {
  597. #ifdef CONFIG_IDEDMA_AUTO
  598. if (!noautodma)
  599. hwif->autodma = 1;
  600. #endif
  601. hwif->dmaproc = &svwks_dmaproc;
  602. } else {
  603. hwif->autodma = 0;
  604. hwif->drives[0].autotune = 1;
  605. hwif->drives[1].autotune = 1;
  606. }
  607. #endif /* !CONFIG_BLK_DEV_IDEDMA */
  608. }