pata_it821x.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. /*
  2. * pata_it821x.c - IT821x PATA for new ATA layer
  3. * (C) 2005 Red Hat Inc
  4. * Alan Cox <alan@redhat.com>
  5. * (C) 2007 Bartlomiej Zolnierkiewicz
  6. *
  7. * based upon
  8. *
  9. * it821x.c
  10. *
  11. * linux/drivers/ide/pci/it821x.c Version 0.09 December 2004
  12. *
  13. * Copyright (C) 2004 Red Hat <alan@redhat.com>
  14. *
  15. * May be copied or modified under the terms of the GNU General Public License
  16. * Based in part on the ITE vendor provided SCSI driver.
  17. *
  18. * Documentation available from
  19. * http://www.ite.com.tw/pc/IT8212F_V04.pdf
  20. * Some other documents are NDA.
  21. *
  22. * The ITE8212 isn't exactly a standard IDE controller. It has two
  23. * modes. In pass through mode then it is an IDE controller. In its smart
  24. * mode its actually quite a capable hardware raid controller disguised
  25. * as an IDE controller. Smart mode only understands DMA read/write and
  26. * identify, none of the fancier commands apply. The IT8211 is identical
  27. * in other respects but lacks the raid mode.
  28. *
  29. * Errata:
  30. * o Rev 0x10 also requires master/slave hold the same DMA timings and
  31. * cannot do ATAPI MWDMA.
  32. * o The identify data for raid volumes lacks CHS info (technically ok)
  33. * but also fails to set the LBA28 and other bits. We fix these in
  34. * the IDE probe quirk code.
  35. * o If you write LBA48 sized I/O's (ie > 256 sector) in smart mode
  36. * raid then the controller firmware dies
  37. * o Smart mode without RAID doesn't clear all the necessary identify
  38. * bits to reduce the command set to the one used
  39. *
  40. * This has a few impacts on the driver
  41. * - In pass through mode we do all the work you would expect
  42. * - In smart mode the clocking set up is done by the controller generally
  43. * but we must watch the other limits and filter.
  44. * - There are a few extra vendor commands that actually talk to the
  45. * controller but only work PIO with no IRQ.
  46. *
  47. * Vendor areas of the identify block in smart mode are used for the
  48. * timing and policy set up. Each HDD in raid mode also has a serial
  49. * block on the disk. The hardware extra commands are get/set chip status,
  50. * rebuild, get rebuild status.
  51. *
  52. * In Linux the driver supports pass through mode as if the device was
  53. * just another IDE controller. If the smart mode is running then
  54. * volumes are managed by the controller firmware and each IDE "disk"
  55. * is a raid volume. Even more cute - the controller can do automated
  56. * hotplug and rebuild.
  57. *
  58. * The pass through controller itself is a little demented. It has a
  59. * flaw that it has a single set of PIO/MWDMA timings per channel so
  60. * non UDMA devices restrict each others performance. It also has a
  61. * single clock source per channel so mixed UDMA100/133 performance
  62. * isn't perfect and we have to pick a clock. Thankfully none of this
  63. * matters in smart mode. ATAPI DMA is not currently supported.
  64. *
  65. * It seems the smart mode is a win for RAID1/RAID10 but otherwise not.
  66. *
  67. * TODO
  68. * - ATAPI and other speed filtering
  69. * - RAID configuration ioctls
  70. */
  71. #include <linux/kernel.h>
  72. #include <linux/module.h>
  73. #include <linux/pci.h>
  74. #include <linux/init.h>
  75. #include <linux/blkdev.h>
  76. #include <linux/delay.h>
  77. #include <scsi/scsi_host.h>
  78. #include <linux/libata.h>
  79. #define DRV_NAME "pata_it821x"
  80. #define DRV_VERSION "0.3.8"
  81. struct it821x_dev
  82. {
  83. unsigned int smart:1, /* Are we in smart raid mode */
  84. timing10:1; /* Rev 0x10 */
  85. u8 clock_mode; /* 0, ATA_50 or ATA_66 */
  86. u8 want[2][2]; /* Mode/Pri log for master slave */
  87. /* We need these for switching the clock when DMA goes on/off
  88. The high byte is the 66Mhz timing */
  89. u16 pio[2]; /* Cached PIO values */
  90. u16 mwdma[2]; /* Cached MWDMA values */
  91. u16 udma[2]; /* Cached UDMA values (per drive) */
  92. u16 last_device; /* Master or slave loaded ? */
  93. };
  94. #define ATA_66 0
  95. #define ATA_50 1
  96. #define ATA_ANY 2
  97. #define UDMA_OFF 0
  98. #define MWDMA_OFF 0
  99. /*
  100. * We allow users to force the card into non raid mode without
  101. * flashing the alternative BIOS. This is also necessary right now
  102. * for embedded platforms that cannot run a PC BIOS but are using this
  103. * device.
  104. */
  105. static int it8212_noraid;
  106. /**
  107. * it821x_program - program the PIO/MWDMA registers
  108. * @ap: ATA port
  109. * @adev: Device to program
  110. * @timing: Timing value (66Mhz in top 8bits, 50 in the low 8)
  111. *
  112. * Program the PIO/MWDMA timing for this channel according to the
  113. * current clock. These share the same register so are managed by
  114. * the DMA start/stop sequence as with the old driver.
  115. */
  116. static void it821x_program(struct ata_port *ap, struct ata_device *adev, u16 timing)
  117. {
  118. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  119. struct it821x_dev *itdev = ap->private_data;
  120. int channel = ap->port_no;
  121. u8 conf;
  122. /* Program PIO/MWDMA timing bits */
  123. if (itdev->clock_mode == ATA_66)
  124. conf = timing >> 8;
  125. else
  126. conf = timing & 0xFF;
  127. pci_write_config_byte(pdev, 0x54 + 4 * channel, conf);
  128. }
  129. /**
  130. * it821x_program_udma - program the UDMA registers
  131. * @ap: ATA port
  132. * @adev: ATA device to update
  133. * @timing: Timing bits. Top 8 are for 66Mhz bottom for 50Mhz
  134. *
  135. * Program the UDMA timing for this drive according to the
  136. * current clock. Handles the dual clocks and also knows about
  137. * the errata on the 0x10 revision. The UDMA errata is partly handled
  138. * here and partly in start_dma.
  139. */
  140. static void it821x_program_udma(struct ata_port *ap, struct ata_device *adev, u16 timing)
  141. {
  142. struct it821x_dev *itdev = ap->private_data;
  143. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  144. int channel = ap->port_no;
  145. int unit = adev->devno;
  146. u8 conf;
  147. /* Program UDMA timing bits */
  148. if (itdev->clock_mode == ATA_66)
  149. conf = timing >> 8;
  150. else
  151. conf = timing & 0xFF;
  152. if (itdev->timing10 == 0)
  153. pci_write_config_byte(pdev, 0x56 + 4 * channel + unit, conf);
  154. else {
  155. /* Early revision must be programmed for both together */
  156. pci_write_config_byte(pdev, 0x56 + 4 * channel, conf);
  157. pci_write_config_byte(pdev, 0x56 + 4 * channel + 1, conf);
  158. }
  159. }
  160. /**
  161. * it821x_clock_strategy
  162. * @ap: ATA interface
  163. * @adev: ATA device being updated
  164. *
  165. * Select between the 50 and 66Mhz base clocks to get the best
  166. * results for this interface.
  167. */
  168. static void it821x_clock_strategy(struct ata_port *ap, struct ata_device *adev)
  169. {
  170. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  171. struct it821x_dev *itdev = ap->private_data;
  172. u8 unit = adev->devno;
  173. struct ata_device *pair = ata_dev_pair(adev);
  174. int clock, altclock;
  175. u8 v;
  176. int sel = 0;
  177. /* Look for the most wanted clocking */
  178. if (itdev->want[0][0] > itdev->want[1][0]) {
  179. clock = itdev->want[0][1];
  180. altclock = itdev->want[1][1];
  181. } else {
  182. clock = itdev->want[1][1];
  183. altclock = itdev->want[0][1];
  184. }
  185. /* Master doesn't care does the slave ? */
  186. if (clock == ATA_ANY)
  187. clock = altclock;
  188. /* Nobody cares - keep the same clock */
  189. if (clock == ATA_ANY)
  190. return;
  191. /* No change */
  192. if (clock == itdev->clock_mode)
  193. return;
  194. /* Load this into the controller */
  195. if (clock == ATA_66)
  196. itdev->clock_mode = ATA_66;
  197. else {
  198. itdev->clock_mode = ATA_50;
  199. sel = 1;
  200. }
  201. pci_read_config_byte(pdev, 0x50, &v);
  202. v &= ~(1 << (1 + ap->port_no));
  203. v |= sel << (1 + ap->port_no);
  204. pci_write_config_byte(pdev, 0x50, v);
  205. /*
  206. * Reprogram the UDMA/PIO of the pair drive for the switch
  207. * MWDMA will be dealt with by the dma switcher
  208. */
  209. if (pair && itdev->udma[1-unit] != UDMA_OFF) {
  210. it821x_program_udma(ap, pair, itdev->udma[1-unit]);
  211. it821x_program(ap, pair, itdev->pio[1-unit]);
  212. }
  213. /*
  214. * Reprogram the UDMA/PIO of our drive for the switch.
  215. * MWDMA will be dealt with by the dma switcher
  216. */
  217. if (itdev->udma[unit] != UDMA_OFF) {
  218. it821x_program_udma(ap, adev, itdev->udma[unit]);
  219. it821x_program(ap, adev, itdev->pio[unit]);
  220. }
  221. }
  222. /**
  223. * it821x_passthru_set_piomode - set PIO mode data
  224. * @ap: ATA interface
  225. * @adev: ATA device
  226. *
  227. * Configure for PIO mode. This is complicated as the register is
  228. * shared by PIO and MWDMA and for both channels.
  229. */
  230. static void it821x_passthru_set_piomode(struct ata_port *ap, struct ata_device *adev)
  231. {
  232. /* Spec says 89 ref driver uses 88 */
  233. static const u16 pio[] = { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 };
  234. static const u8 pio_want[] = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY };
  235. struct it821x_dev *itdev = ap->private_data;
  236. int unit = adev->devno;
  237. int mode_wanted = adev->pio_mode - XFER_PIO_0;
  238. /* We prefer 66Mhz clock for PIO 0-3, don't care for PIO4 */
  239. itdev->want[unit][1] = pio_want[mode_wanted];
  240. itdev->want[unit][0] = 1; /* PIO is lowest priority */
  241. itdev->pio[unit] = pio[mode_wanted];
  242. it821x_clock_strategy(ap, adev);
  243. it821x_program(ap, adev, itdev->pio[unit]);
  244. }
  245. /**
  246. * it821x_passthru_set_dmamode - set initial DMA mode data
  247. * @ap: ATA interface
  248. * @adev: ATA device
  249. *
  250. * Set up the DMA modes. The actions taken depend heavily on the mode
  251. * to use. If UDMA is used as is hopefully the usual case then the
  252. * timing register is private and we need only consider the clock. If
  253. * we are using MWDMA then we have to manage the setting ourself as
  254. * we switch devices and mode.
  255. */
  256. static void it821x_passthru_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  257. {
  258. static const u16 dma[] = { 0x8866, 0x3222, 0x3121 };
  259. static const u8 mwdma_want[] = { ATA_ANY, ATA_66, ATA_ANY };
  260. static const u16 udma[] = { 0x4433, 0x4231, 0x3121, 0x2121, 0x1111, 0x2211, 0x1111 };
  261. static const u8 udma_want[] = { ATA_ANY, ATA_50, ATA_ANY, ATA_66, ATA_66, ATA_50, ATA_66 };
  262. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  263. struct it821x_dev *itdev = ap->private_data;
  264. int channel = ap->port_no;
  265. int unit = adev->devno;
  266. u8 conf;
  267. if (adev->dma_mode >= XFER_UDMA_0) {
  268. int mode_wanted = adev->dma_mode - XFER_UDMA_0;
  269. itdev->want[unit][1] = udma_want[mode_wanted];
  270. itdev->want[unit][0] = 3; /* UDMA is high priority */
  271. itdev->mwdma[unit] = MWDMA_OFF;
  272. itdev->udma[unit] = udma[mode_wanted];
  273. if (mode_wanted >= 5)
  274. itdev->udma[unit] |= 0x8080; /* UDMA 5/6 select on */
  275. /* UDMA on. Again revision 0x10 must do the pair */
  276. pci_read_config_byte(pdev, 0x50, &conf);
  277. if (itdev->timing10)
  278. conf &= channel ? 0x9F: 0xE7;
  279. else
  280. conf &= ~ (1 << (3 + 2 * channel + unit));
  281. pci_write_config_byte(pdev, 0x50, conf);
  282. it821x_clock_strategy(ap, adev);
  283. it821x_program_udma(ap, adev, itdev->udma[unit]);
  284. } else {
  285. int mode_wanted = adev->dma_mode - XFER_MW_DMA_0;
  286. itdev->want[unit][1] = mwdma_want[mode_wanted];
  287. itdev->want[unit][0] = 2; /* MWDMA is low priority */
  288. itdev->mwdma[unit] = dma[mode_wanted];
  289. itdev->udma[unit] = UDMA_OFF;
  290. /* UDMA bits off - Revision 0x10 do them in pairs */
  291. pci_read_config_byte(pdev, 0x50, &conf);
  292. if (itdev->timing10)
  293. conf |= channel ? 0x60: 0x18;
  294. else
  295. conf |= 1 << (3 + 2 * channel + unit);
  296. pci_write_config_byte(pdev, 0x50, conf);
  297. it821x_clock_strategy(ap, adev);
  298. }
  299. }
  300. /**
  301. * it821x_passthru_dma_start - DMA start callback
  302. * @qc: Command in progress
  303. *
  304. * Usually drivers set the DMA timing at the point the set_dmamode call
  305. * is made. IT821x however requires we load new timings on the
  306. * transitions in some cases.
  307. */
  308. static void it821x_passthru_bmdma_start(struct ata_queued_cmd *qc)
  309. {
  310. struct ata_port *ap = qc->ap;
  311. struct ata_device *adev = qc->dev;
  312. struct it821x_dev *itdev = ap->private_data;
  313. int unit = adev->devno;
  314. if (itdev->mwdma[unit] != MWDMA_OFF)
  315. it821x_program(ap, adev, itdev->mwdma[unit]);
  316. else if (itdev->udma[unit] != UDMA_OFF && itdev->timing10)
  317. it821x_program_udma(ap, adev, itdev->udma[unit]);
  318. ata_bmdma_start(qc);
  319. }
  320. /**
  321. * it821x_passthru_dma_stop - DMA stop callback
  322. * @qc: ATA command
  323. *
  324. * We loaded new timings in dma_start, as a result we need to restore
  325. * the PIO timings in dma_stop so that the next command issue gets the
  326. * right clock values.
  327. */
  328. static void it821x_passthru_bmdma_stop(struct ata_queued_cmd *qc)
  329. {
  330. struct ata_port *ap = qc->ap;
  331. struct ata_device *adev = qc->dev;
  332. struct it821x_dev *itdev = ap->private_data;
  333. int unit = adev->devno;
  334. ata_bmdma_stop(qc);
  335. if (itdev->mwdma[unit] != MWDMA_OFF)
  336. it821x_program(ap, adev, itdev->pio[unit]);
  337. }
  338. /**
  339. * it821x_passthru_dev_select - Select master/slave
  340. * @ap: ATA port
  341. * @device: Device number (not pointer)
  342. *
  343. * Device selection hook. If necessary perform clock switching
  344. */
  345. static void it821x_passthru_dev_select(struct ata_port *ap,
  346. unsigned int device)
  347. {
  348. struct it821x_dev *itdev = ap->private_data;
  349. if (itdev && device != itdev->last_device) {
  350. struct ata_device *adev = &ap->link.device[device];
  351. it821x_program(ap, adev, itdev->pio[adev->devno]);
  352. itdev->last_device = device;
  353. }
  354. ata_std_dev_select(ap, device);
  355. }
  356. /**
  357. * it821x_smart_qc_issue_prot - wrap qc issue prot
  358. * @qc: command
  359. *
  360. * Wrap the command issue sequence for the IT821x. We need to
  361. * perform out own device selection timing loads before the
  362. * usual happenings kick off
  363. */
  364. static unsigned int it821x_smart_qc_issue_prot(struct ata_queued_cmd *qc)
  365. {
  366. switch(qc->tf.command)
  367. {
  368. /* Commands the firmware supports */
  369. case ATA_CMD_READ:
  370. case ATA_CMD_READ_EXT:
  371. case ATA_CMD_WRITE:
  372. case ATA_CMD_WRITE_EXT:
  373. case ATA_CMD_PIO_READ:
  374. case ATA_CMD_PIO_READ_EXT:
  375. case ATA_CMD_PIO_WRITE:
  376. case ATA_CMD_PIO_WRITE_EXT:
  377. case ATA_CMD_READ_MULTI:
  378. case ATA_CMD_READ_MULTI_EXT:
  379. case ATA_CMD_WRITE_MULTI:
  380. case ATA_CMD_WRITE_MULTI_EXT:
  381. case ATA_CMD_ID_ATA:
  382. /* Arguably should just no-op this one */
  383. case ATA_CMD_SET_FEATURES:
  384. return ata_qc_issue_prot(qc);
  385. }
  386. printk(KERN_DEBUG "it821x: can't process command 0x%02X\n", qc->tf.command);
  387. return AC_ERR_INVALID;
  388. }
  389. /**
  390. * it821x_passthru_qc_issue_prot - wrap qc issue prot
  391. * @qc: command
  392. *
  393. * Wrap the command issue sequence for the IT821x. We need to
  394. * perform out own device selection timing loads before the
  395. * usual happenings kick off
  396. */
  397. static unsigned int it821x_passthru_qc_issue_prot(struct ata_queued_cmd *qc)
  398. {
  399. it821x_passthru_dev_select(qc->ap, qc->dev->devno);
  400. return ata_qc_issue_prot(qc);
  401. }
  402. /**
  403. * it821x_smart_set_mode - mode setting
  404. * @link: interface to set up
  405. * @unused: device that failed (error only)
  406. *
  407. * Use a non standard set_mode function. We don't want to be tuned.
  408. * The BIOS configured everything. Our job is not to fiddle. We
  409. * read the dma enabled bits from the PCI configuration of the device
  410. * and respect them.
  411. */
  412. static int it821x_smart_set_mode(struct ata_link *link, struct ata_device **unused)
  413. {
  414. struct ata_device *dev;
  415. ata_link_for_each_dev(dev, link) {
  416. if (ata_dev_enabled(dev)) {
  417. /* We don't really care */
  418. dev->pio_mode = XFER_PIO_0;
  419. dev->dma_mode = XFER_MW_DMA_0;
  420. /* We do need the right mode information for DMA or PIO
  421. and this comes from the current configuration flags */
  422. if (ata_id_has_dma(dev->id)) {
  423. ata_dev_printk(dev, KERN_INFO, "configured for DMA\n");
  424. dev->xfer_mode = XFER_MW_DMA_0;
  425. dev->xfer_shift = ATA_SHIFT_MWDMA;
  426. dev->flags &= ~ATA_DFLAG_PIO;
  427. } else {
  428. ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
  429. dev->xfer_mode = XFER_PIO_0;
  430. dev->xfer_shift = ATA_SHIFT_PIO;
  431. dev->flags |= ATA_DFLAG_PIO;
  432. }
  433. }
  434. }
  435. return 0;
  436. }
  437. /**
  438. * it821x_dev_config - Called each device identify
  439. * @adev: Device that has just been identified
  440. *
  441. * Perform the initial setup needed for each device that is chip
  442. * special. In our case we need to lock the sector count to avoid
  443. * blowing the brains out of the firmware with large LBA48 requests
  444. *
  445. * FIXME: When FUA appears we need to block FUA too. And SMART and
  446. * basically we need to filter commands for this chip.
  447. */
  448. static void it821x_dev_config(struct ata_device *adev)
  449. {
  450. unsigned char model_num[ATA_ID_PROD_LEN + 1];
  451. ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
  452. if (adev->max_sectors > 255)
  453. adev->max_sectors = 255;
  454. if (strstr(model_num, "Integrated Technology Express")) {
  455. /* RAID mode */
  456. printk(KERN_INFO "IT821x %sRAID%d volume",
  457. adev->id[147]?"Bootable ":"",
  458. adev->id[129]);
  459. if (adev->id[129] != 1)
  460. printk("(%dK stripe)", adev->id[146]);
  461. printk(".\n");
  462. }
  463. }
  464. /**
  465. * it821x_check_atapi_dma - ATAPI DMA handler
  466. * @qc: Command we are about to issue
  467. *
  468. * Decide if this ATAPI command can be issued by DMA on this
  469. * controller. Return 0 if it can be.
  470. */
  471. static int it821x_check_atapi_dma(struct ata_queued_cmd *qc)
  472. {
  473. struct ata_port *ap = qc->ap;
  474. struct it821x_dev *itdev = ap->private_data;
  475. /* Only use dma for transfers to/from the media. */
  476. if (qc->nbytes < 2048)
  477. return -EOPNOTSUPP;
  478. /* No ATAPI DMA in smart mode */
  479. if (itdev->smart)
  480. return -EOPNOTSUPP;
  481. /* No ATAPI DMA on rev 10 */
  482. if (itdev->timing10)
  483. return -EOPNOTSUPP;
  484. /* Cool */
  485. return 0;
  486. }
  487. /**
  488. * it821x_port_start - port setup
  489. * @ap: ATA port being set up
  490. *
  491. * The it821x needs to maintain private data structures and also to
  492. * use the standard PCI interface which lacks support for this
  493. * functionality. We instead set up the private data on the port
  494. * start hook, and tear it down on port stop
  495. */
  496. static int it821x_port_start(struct ata_port *ap)
  497. {
  498. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  499. struct it821x_dev *itdev;
  500. u8 conf;
  501. int ret = ata_sff_port_start(ap);
  502. if (ret < 0)
  503. return ret;
  504. itdev = devm_kzalloc(&pdev->dev, sizeof(struct it821x_dev), GFP_KERNEL);
  505. if (itdev == NULL)
  506. return -ENOMEM;
  507. ap->private_data = itdev;
  508. pci_read_config_byte(pdev, 0x50, &conf);
  509. if (conf & 1) {
  510. itdev->smart = 1;
  511. /* Long I/O's although allowed in LBA48 space cause the
  512. onboard firmware to enter the twighlight zone */
  513. /* No ATAPI DMA in this mode either */
  514. }
  515. /* Pull the current clocks from 0x50 */
  516. if (conf & (1 << (1 + ap->port_no)))
  517. itdev->clock_mode = ATA_50;
  518. else
  519. itdev->clock_mode = ATA_66;
  520. itdev->want[0][1] = ATA_ANY;
  521. itdev->want[1][1] = ATA_ANY;
  522. itdev->last_device = -1;
  523. if (pdev->revision == 0x10) {
  524. itdev->timing10 = 1;
  525. /* Need to disable ATAPI DMA for this case */
  526. if (!itdev->smart)
  527. printk(KERN_WARNING DRV_NAME": Revision 0x10, workarounds activated.\n");
  528. }
  529. return 0;
  530. }
  531. static struct scsi_host_template it821x_sht = {
  532. .module = THIS_MODULE,
  533. .name = DRV_NAME,
  534. .ioctl = ata_scsi_ioctl,
  535. .queuecommand = ata_scsi_queuecmd,
  536. .can_queue = ATA_DEF_QUEUE,
  537. .this_id = ATA_SHT_THIS_ID,
  538. .sg_tablesize = LIBATA_MAX_PRD,
  539. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  540. .emulated = ATA_SHT_EMULATED,
  541. .use_clustering = ATA_SHT_USE_CLUSTERING,
  542. .proc_name = DRV_NAME,
  543. .dma_boundary = ATA_DMA_BOUNDARY,
  544. .slave_configure = ata_scsi_slave_config,
  545. .slave_destroy = ata_scsi_slave_destroy,
  546. .bios_param = ata_std_bios_param,
  547. };
  548. static struct ata_port_operations it821x_smart_port_ops = {
  549. .set_mode = it821x_smart_set_mode,
  550. .tf_load = ata_tf_load,
  551. .tf_read = ata_tf_read,
  552. .mode_filter = ata_pci_default_filter,
  553. .check_status = ata_check_status,
  554. .check_atapi_dma= it821x_check_atapi_dma,
  555. .exec_command = ata_exec_command,
  556. .dev_select = ata_std_dev_select,
  557. .dev_config = it821x_dev_config,
  558. .freeze = ata_bmdma_freeze,
  559. .thaw = ata_bmdma_thaw,
  560. .error_handler = ata_bmdma_error_handler,
  561. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  562. .cable_detect = ata_cable_unknown,
  563. .bmdma_setup = ata_bmdma_setup,
  564. .bmdma_start = ata_bmdma_start,
  565. .bmdma_stop = ata_bmdma_stop,
  566. .bmdma_status = ata_bmdma_status,
  567. .qc_prep = ata_qc_prep,
  568. .qc_issue = it821x_smart_qc_issue_prot,
  569. .data_xfer = ata_data_xfer,
  570. .irq_handler = ata_interrupt,
  571. .irq_clear = ata_bmdma_irq_clear,
  572. .irq_on = ata_irq_on,
  573. .port_start = it821x_port_start,
  574. };
  575. static struct ata_port_operations it821x_passthru_port_ops = {
  576. .set_piomode = it821x_passthru_set_piomode,
  577. .set_dmamode = it821x_passthru_set_dmamode,
  578. .mode_filter = ata_pci_default_filter,
  579. .tf_load = ata_tf_load,
  580. .tf_read = ata_tf_read,
  581. .check_status = ata_check_status,
  582. .exec_command = ata_exec_command,
  583. .check_atapi_dma= it821x_check_atapi_dma,
  584. .dev_select = it821x_passthru_dev_select,
  585. .freeze = ata_bmdma_freeze,
  586. .thaw = ata_bmdma_thaw,
  587. .error_handler = ata_bmdma_error_handler,
  588. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  589. .cable_detect = ata_cable_unknown,
  590. .bmdma_setup = ata_bmdma_setup,
  591. .bmdma_start = it821x_passthru_bmdma_start,
  592. .bmdma_stop = it821x_passthru_bmdma_stop,
  593. .bmdma_status = ata_bmdma_status,
  594. .qc_prep = ata_qc_prep,
  595. .qc_issue = it821x_passthru_qc_issue_prot,
  596. .data_xfer = ata_data_xfer,
  597. .irq_clear = ata_bmdma_irq_clear,
  598. .irq_handler = ata_interrupt,
  599. .irq_on = ata_irq_on,
  600. .port_start = it821x_port_start,
  601. };
  602. static void it821x_disable_raid(struct pci_dev *pdev)
  603. {
  604. /* Reset local CPU, and set BIOS not ready */
  605. pci_write_config_byte(pdev, 0x5E, 0x01);
  606. /* Set to bypass mode, and reset PCI bus */
  607. pci_write_config_byte(pdev, 0x50, 0x00);
  608. pci_write_config_word(pdev, PCI_COMMAND,
  609. PCI_COMMAND_PARITY | PCI_COMMAND_IO |
  610. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  611. pci_write_config_word(pdev, 0x40, 0xA0F3);
  612. pci_write_config_dword(pdev,0x4C, 0x02040204);
  613. pci_write_config_byte(pdev, 0x42, 0x36);
  614. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x20);
  615. }
  616. static int it821x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  617. {
  618. u8 conf;
  619. static const struct ata_port_info info_smart = {
  620. .sht = &it821x_sht,
  621. .flags = ATA_FLAG_SLAVE_POSS,
  622. .pio_mask = 0x1f,
  623. .mwdma_mask = 0x07,
  624. .port_ops = &it821x_smart_port_ops
  625. };
  626. static const struct ata_port_info info_passthru = {
  627. .sht = &it821x_sht,
  628. .flags = ATA_FLAG_SLAVE_POSS,
  629. .pio_mask = 0x1f,
  630. .mwdma_mask = 0x07,
  631. .udma_mask = ATA_UDMA6,
  632. .port_ops = &it821x_passthru_port_ops
  633. };
  634. const struct ata_port_info *ppi[] = { NULL, NULL };
  635. static char *mode[2] = { "pass through", "smart" };
  636. /* Force the card into bypass mode if so requested */
  637. if (it8212_noraid) {
  638. printk(KERN_INFO DRV_NAME ": forcing bypass mode.\n");
  639. it821x_disable_raid(pdev);
  640. }
  641. pci_read_config_byte(pdev, 0x50, &conf);
  642. conf &= 1;
  643. printk(KERN_INFO DRV_NAME ": controller in %s mode.\n", mode[conf]);
  644. if (conf == 0)
  645. ppi[0] = &info_passthru;
  646. else
  647. ppi[0] = &info_smart;
  648. return ata_pci_init_one(pdev, ppi);
  649. }
  650. #ifdef CONFIG_PM
  651. static int it821x_reinit_one(struct pci_dev *pdev)
  652. {
  653. /* Resume - turn raid back off if need be */
  654. if (it8212_noraid)
  655. it821x_disable_raid(pdev);
  656. return ata_pci_device_resume(pdev);
  657. }
  658. #endif
  659. static const struct pci_device_id it821x[] = {
  660. { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8211), },
  661. { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8212), },
  662. { },
  663. };
  664. static struct pci_driver it821x_pci_driver = {
  665. .name = DRV_NAME,
  666. .id_table = it821x,
  667. .probe = it821x_init_one,
  668. .remove = ata_pci_remove_one,
  669. #ifdef CONFIG_PM
  670. .suspend = ata_pci_device_suspend,
  671. .resume = it821x_reinit_one,
  672. #endif
  673. };
  674. static int __init it821x_init(void)
  675. {
  676. return pci_register_driver(&it821x_pci_driver);
  677. }
  678. static void __exit it821x_exit(void)
  679. {
  680. pci_unregister_driver(&it821x_pci_driver);
  681. }
  682. MODULE_AUTHOR("Alan Cox");
  683. MODULE_DESCRIPTION("low-level driver for the IT8211/IT8212 IDE RAID controller");
  684. MODULE_LICENSE("GPL");
  685. MODULE_DEVICE_TABLE(pci, it821x);
  686. MODULE_VERSION(DRV_VERSION);
  687. module_param_named(noraid, it8212_noraid, int, S_IRUGO);
  688. MODULE_PARM_DESC(noraid, "Force card into bypass mode");
  689. module_init(it821x_init);
  690. module_exit(it821x_exit);