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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * linux/drivers/ide/ide-taskfile.c Version 0.20 Oct 11, 2000
  3.  *
  4.  *  Copyright (C) 2000 Michael Cornwell <cornwell@acm.org>
  5.  *  Copyright (C) 2000 Andre Hedrick <andre@linux-ide.org>
  6.  *
  7.  *  May be copied or modified under the terms of the GNU General Public License
  8.  *
  9.  * IDE_DEBUG(__LINE__);
  10.  */
  11. #include <linux/config.h>
  12. #define __NO_VERSION__
  13. #include <linux/module.h>
  14. #include <linux/types.h>
  15. #include <linux/string.h>
  16. #include <linux/kernel.h>
  17. #include <linux/timer.h>
  18. #include <linux/mm.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/major.h>
  21. #include <linux/errno.h>
  22. #include <linux/genhd.h>
  23. #include <linux/blkpg.h>
  24. #include <linux/slab.h>
  25. #include <linux/pci.h>
  26. #include <linux/delay.h>
  27. #include <linux/hdreg.h>
  28. #include <linux/ide.h>
  29. #include <asm/byteorder.h>
  30. #include <asm/irq.h>
  31. #include <asm/uaccess.h>
  32. #include <asm/io.h>
  33. #include <asm/bitops.h>
  34. #ifdef CONFIG_IDE_TASKFILE_IO
  35. #  define __TASKFILE__IO
  36. #else /* CONFIG_IDE_TASKFILE_IO */
  37. #  undef __TASKFILE__IO
  38. #endif /* CONFIG_IDE_TASKFILE_IO */
  39. #define DEBUG_TASKFILE 0 /* unset when fixed */
  40. #if DEBUG_TASKFILE
  41. #define DTF(x...) printk(##x)
  42. #else
  43. #define DTF(x...)
  44. #endif
  45. inline u32 task_read_24 (ide_drive_t *drive)
  46. {
  47. return (IN_BYTE(IDE_HCYL_REG)<<16) |
  48. (IN_BYTE(IDE_LCYL_REG)<<8) |
  49.  IN_BYTE(IDE_SECTOR_REG);
  50. }
  51. static void ata_bswap_data (void *buffer, int wcount)
  52. {
  53. u16 *p = buffer;
  54. while (wcount--) {
  55. *p = *p << 8 | *p >> 8; p++;
  56. *p = *p << 8 | *p >> 8; p++;
  57. }
  58. }
  59. #if SUPPORT_VLB_SYNC
  60. /*
  61.  * Some localbus EIDE interfaces require a special access sequence
  62.  * when using 32-bit I/O instructions to transfer data.  We call this
  63.  * the "vlb_sync" sequence, which consists of three successive reads
  64.  * of the sector count register location, with interrupts disabled
  65.  * to ensure that the reads all happen together.
  66.  */
  67. static inline void task_vlb_sync (ide_ioreg_t port) {
  68. (void) inb (port);
  69. (void) inb (port);
  70. (void) inb (port);
  71. }
  72. #endif /* SUPPORT_VLB_SYNC */
  73. /*
  74.  * This is used for most PIO data transfers *from* the IDE interface
  75.  */
  76. void ata_input_data (ide_drive_t *drive, void *buffer, unsigned int wcount)
  77. {
  78. byte io_32bit = drive->io_32bit;
  79. if (io_32bit) {
  80. #if SUPPORT_VLB_SYNC
  81. if (io_32bit & 2) {
  82. unsigned long flags;
  83. __save_flags(flags); /* local CPU only */
  84. __cli(); /* local CPU only */
  85. task_vlb_sync(IDE_NSECTOR_REG);
  86. insl(IDE_DATA_REG, buffer, wcount);
  87. __restore_flags(flags); /* local CPU only */
  88. } else
  89. #endif /* SUPPORT_VLB_SYNC */
  90. insl(IDE_DATA_REG, buffer, wcount);
  91. } else {
  92. #if SUPPORT_SLOW_DATA_PORTS
  93. if (drive->slow) {
  94. unsigned short *ptr = (unsigned short *) buffer;
  95. while (wcount--) {
  96. *ptr++ = inw_p(IDE_DATA_REG);
  97. *ptr++ = inw_p(IDE_DATA_REG);
  98. }
  99. } else
  100. #endif /* SUPPORT_SLOW_DATA_PORTS */
  101. insw(IDE_DATA_REG, buffer, wcount<<1);
  102. }
  103. }
  104. /*
  105.  * This is used for most PIO data transfers *to* the IDE interface
  106.  */
  107. void ata_output_data (ide_drive_t *drive, void *buffer, unsigned int wcount)
  108. {
  109. byte io_32bit = drive->io_32bit;
  110. if (io_32bit) {
  111. #if SUPPORT_VLB_SYNC
  112. if (io_32bit & 2) {
  113. unsigned long flags;
  114. __save_flags(flags); /* local CPU only */
  115. __cli(); /* local CPU only */
  116. task_vlb_sync(IDE_NSECTOR_REG);
  117. outsl(IDE_DATA_REG, buffer, wcount);
  118. __restore_flags(flags); /* local CPU only */
  119. } else
  120. #endif /* SUPPORT_VLB_SYNC */
  121. outsl(IDE_DATA_REG, buffer, wcount);
  122. } else {
  123. #if SUPPORT_SLOW_DATA_PORTS
  124. if (drive->slow) {
  125. unsigned short *ptr = (unsigned short *) buffer;
  126. while (wcount--) {
  127. outw_p(*ptr++, IDE_DATA_REG);
  128. outw_p(*ptr++, IDE_DATA_REG);
  129. }
  130. } else
  131. #endif /* SUPPORT_SLOW_DATA_PORTS */
  132. outsw(IDE_DATA_REG, buffer, wcount<<1);
  133. }
  134. }
  135. static inline void taskfile_input_data (ide_drive_t *drive, void *buffer, unsigned int wcount)
  136. {
  137. ata_input_data(drive, buffer, wcount);
  138. if (drive->bswap)
  139. ata_bswap_data(buffer, wcount);
  140. }
  141. static inline void taskfile_output_data (ide_drive_t *drive, void *buffer, unsigned int wcount)
  142. {
  143. if (drive->bswap) {
  144. ata_bswap_data(buffer, wcount);
  145. ata_output_data(drive, buffer, wcount);
  146. ata_bswap_data(buffer, wcount);
  147. } else {
  148. ata_output_data(drive, buffer, wcount);
  149. }
  150. }
  151. ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
  152. {
  153. task_struct_t *taskfile = (task_struct_t *) task->tfRegister;
  154. hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister;
  155. struct hd_driveid *id = drive->id;
  156. byte HIHI = (drive->addressing) ? 0xE0 : 0xEF;
  157. /* (ks/hs): Moved to start, do not use for multiple out commands */
  158. if (task->handler != task_mulout_intr) {
  159. if (IDE_CONTROL_REG)
  160. OUT_BYTE(drive->ctl, IDE_CONTROL_REG); /* clear nIEN */
  161. SELECT_MASK(HWIF(drive), drive, 0);
  162. }
  163. if ((id->command_set_2 & 0x0400) &&
  164.     (id->cfs_enable_2 & 0x0400) &&
  165.     (drive->addressing == 1)) {
  166. OUT_BYTE(hobfile->feature, IDE_FEATURE_REG);
  167. OUT_BYTE(hobfile->sector_count, IDE_NSECTOR_REG);
  168. OUT_BYTE(hobfile->sector_number, IDE_SECTOR_REG);
  169. OUT_BYTE(hobfile->low_cylinder, IDE_LCYL_REG);
  170. OUT_BYTE(hobfile->high_cylinder, IDE_HCYL_REG);
  171. }
  172. OUT_BYTE(taskfile->feature, IDE_FEATURE_REG);
  173. OUT_BYTE(taskfile->sector_count, IDE_NSECTOR_REG);
  174. /* refers to number of sectors to transfer */
  175. OUT_BYTE(taskfile->sector_number, IDE_SECTOR_REG);
  176. /* refers to sector offset or start sector */
  177. OUT_BYTE(taskfile->low_cylinder, IDE_LCYL_REG);
  178. OUT_BYTE(taskfile->high_cylinder, IDE_HCYL_REG);
  179. OUT_BYTE((taskfile->device_head & HIHI) | drive->select.all, IDE_SELECT_REG);
  180. if (task->handler != NULL) {
  181. #if 0
  182. ide_set_handler (drive, task->handler, WAIT_CMD, NULL);
  183. OUT_BYTE(taskfile->command, IDE_COMMAND_REG);
  184. /*
  185.  * warning check for race between handler and prehandler for
  186.  * writing first block of data.  however since we are well
  187.  * inside the boundaries of the seek, we should be okay.
  188.  */
  189. if (task->prehandler != NULL) {
  190. return task->prehandler(drive, task->rq);
  191. }
  192. #else
  193. ide_startstop_t startstop;
  194. ide_set_handler (drive, task->handler, WAIT_CMD, NULL);
  195. OUT_BYTE(taskfile->command, IDE_COMMAND_REG);
  196. if (ide_wait_stat(&startstop, drive, DATA_READY, drive->bad_wstat, WAIT_DRQ)) {
  197. printk(KERN_ERR "%s: no DRQ after issuing %sn",
  198. drive->name,
  199. drive->mult_count ? "MULTWRITE" : "WRITE");
  200. return startstop;
  201. }
  202. /* (ks/hs): Fixed Multi Write */
  203. if ((taskfile->command != WIN_MULTWRITE) &&
  204.     (taskfile->command != WIN_MULTWRITE_EXT)) {
  205. struct request *rq = HWGROUP(drive)->rq;
  206. /* For Write_sectors we need to stuff the first sector */
  207. taskfile_output_data(drive, rq->buffer, SECTOR_WORDS);
  208. rq->current_nr_sectors--;
  209. } else {
  210. /* Stuff first sector(s) by implicitly calling the handler */
  211. if (!(drive_is_ready(drive))) {
  212. /* FIXME: Replace hard-coded 100, error handling? */
  213. int i;
  214. for (i=0; i<100; i++) {
  215. if (drive_is_ready(drive))
  216. break;
  217. }
  218. }
  219. return task->handler(drive);
  220. }
  221. #endif
  222. } else {
  223. /* for dma commands we down set the handler */
  224. if (drive->using_dma && !(HWIF(drive)->dmaproc(((taskfile->command == WIN_WRITEDMA) || (taskfile->command == WIN_WRITEDMA_EXT)) ? ide_dma_write : ide_dma_read, drive)));
  225. }
  226. return ide_started;
  227. }
  228. void do_taskfile (ide_drive_t *drive, struct hd_drive_task_hdr *taskfile, struct hd_drive_hob_hdr *hobfile, ide_handler_t *handler)
  229. {
  230. struct hd_driveid *id = drive->id;
  231. byte HIHI = (drive->addressing) ? 0xE0 : 0xEF;
  232. /* (ks/hs): Moved to start, do not use for multiple out commands */
  233. if (*handler != task_mulout_intr) {
  234. if (IDE_CONTROL_REG)
  235. OUT_BYTE(drive->ctl, IDE_CONTROL_REG);  /* clear nIEN */
  236. SELECT_MASK(HWIF(drive), drive, 0);
  237. }
  238. if ((id->command_set_2 & 0x0400) &&
  239.     (id->cfs_enable_2 & 0x0400) &&
  240.     (drive->addressing == 1)) {
  241. OUT_BYTE(hobfile->feature, IDE_FEATURE_REG);
  242. OUT_BYTE(hobfile->sector_count, IDE_NSECTOR_REG);
  243. OUT_BYTE(hobfile->sector_number, IDE_SECTOR_REG);
  244. OUT_BYTE(hobfile->low_cylinder, IDE_LCYL_REG);
  245. OUT_BYTE(hobfile->high_cylinder, IDE_HCYL_REG);
  246. }
  247. OUT_BYTE(taskfile->feature, IDE_FEATURE_REG);
  248. OUT_BYTE(taskfile->sector_count, IDE_NSECTOR_REG);
  249. /* refers to number of sectors to transfer */
  250. OUT_BYTE(taskfile->sector_number, IDE_SECTOR_REG);
  251. /* refers to sector offset or start sector */
  252. OUT_BYTE(taskfile->low_cylinder, IDE_LCYL_REG);
  253. OUT_BYTE(taskfile->high_cylinder, IDE_HCYL_REG);
  254. OUT_BYTE((taskfile->device_head & HIHI) | drive->select.all, IDE_SELECT_REG);
  255. if (handler != NULL) {
  256. ide_set_handler (drive, handler, WAIT_CMD, NULL);
  257. OUT_BYTE(taskfile->command, IDE_COMMAND_REG);
  258. } else {
  259. /* for dma commands we down set the handler */
  260. if (drive->using_dma && !(HWIF(drive)->dmaproc(((taskfile->command == WIN_WRITEDMA) || (taskfile->command == WIN_WRITEDMA_EXT)) ? ide_dma_write : ide_dma_read, drive)));
  261. }
  262. }
  263. #if 0
  264. ide_startstop_t flagged_taskfile (ide_drive_t *drive, ide_task_t *task)
  265. {
  266. task_struct_t *taskfile = (task_struct_t *) task->tfRegister;
  267. hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister;
  268. struct hd_driveid *id = drive->id;
  269. /*
  270.  * (KS) Check taskfile in/out flags.
  271.  * If set, then execute as it is defined.
  272.  * If not set, then define default settings.
  273.  * The default values are:
  274.  * write and read all taskfile registers (except data) 
  275.  * write and read the hob registers (sector,nsector,lcyl,hcyl)
  276.  */
  277. if (task->tf_out_flags.all == 0) {
  278. task->tf_out_flags.all = IDE_TASKFILE_STD_OUT_FLAGS;
  279. if ((id->command_set_2 & 0x0400) &&
  280.     (id->cfs_enable_2 & 0x0400) &&
  281.     (drive->addressing == 1)) {
  282. task->tf_out_flags.all != (IDE_HOB_STD_OUT_FLAGS << 8);
  283. }
  284.         }
  285. if (task->tf_in_flags.all == 0) {
  286. task->tf_in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
  287. if ((id->command_set_2 & 0x0400) &&
  288.     (id->cfs_enable_2 & 0x0400) &&
  289.     (drive->addressing == 1)) {
  290. task->tf_in_flags.all  != (IDE_HOB_STD_IN_FLAGS  << 8);
  291. }
  292.         }
  293. if (IDE_CONTROL_REG)
  294. OUT_BYTE(drive->ctl, IDE_CONTROL_REG); /* clear nIEN */
  295. SELECT_MASK(HWIF(drive), drive, 0);
  296. if (task->tf_out_flags.b.data) {
  297. unsigned short data =  taskfile->data + (hobfile->data << 8);
  298. OUT_WORD (data, IDE_DATA_REG);
  299. }
  300. /* (KS) send hob registers first */
  301. if (task->tf_out_flags.b.nsector_hob)
  302. OUT_BYTE(hobfile->sector_count, IDE_NSECTOR_REG);
  303. if (task->tf_out_flags.b.sector_hob)
  304. OUT_BYTE(hobfile->sector_number, IDE_SECTOR_REG);
  305. if (task->tf_out_flags.b.lcyl_hob)
  306. OUT_BYTE(hobfile->low_cylinder, IDE_LCYL_REG);
  307. if (task->tf_out_flags.b.hcyl_hob)
  308. OUT_BYTE(hobfile->high_cylinder, IDE_HCYL_REG);
  309. /* (KS) Send now the standard registers */
  310. if (task->tf_out_flags.b.error_feature)
  311. OUT_BYTE(taskfile->feature, IDE_FEATURE_REG);
  312. /* refers to number of sectors to transfer */
  313. if (task->tf_out_flags.b.nsector)
  314. OUT_BYTE(taskfile->sector_count, IDE_NSECTOR_REG);
  315. /* refers to sector offset or start sector */
  316. if (task->tf_out_flags.b.sector)
  317. OUT_BYTE(taskfile->sector_number, IDE_SECTOR_REG);
  318. if (task->tf_out_flags.b.lcyl)
  319. OUT_BYTE(taskfile->low_cylinder, IDE_LCYL_REG);
  320. if (task->tf_out_flags.b.hcyl)
  321. OUT_BYTE(taskfile->high_cylinder, IDE_HCYL_REG);
  322.         /*
  323.  * (KS) Do not modify the specified taskfile. We want to have a
  324.  * universal pass through, so we must execute ALL specified values.
  325.  *
  326.  * (KS) The drive head register is mandatory.
  327.  * Don't care about the out flags !
  328.  */
  329. OUT_BYTE(taskfile->device_head | drive->select.all, IDE_SELECT_REG);
  330. if (task->handler != NULL) {
  331. #if 0
  332. ide_set_handler (drive, task->handler, WAIT_CMD, NULL);
  333. OUT_BYTE(taskfile->command, IDE_COMMAND_REG);
  334. /*
  335.  * warning check for race between handler and prehandler for
  336.  * writing first block of data.  however since we are well
  337.  * inside the boundaries of the seek, we should be okay.
  338.  */
  339. if (task->prehandler != NULL) {
  340. return task->prehandler(drive, task->rq);
  341. }
  342. #else
  343. ide_startstop_t startstop;
  344. ide_set_handler (drive, task->handler, WAIT_CMD, NULL);
  345. /*
  346.  * (KS) The drive command register is also mandatory.
  347.  * Don't care about the out flags !
  348.  */
  349. OUT_BYTE(taskfile->command, IDE_COMMAND_REG);
  350. if (ide_wait_stat(&startstop, drive, DATA_READY, drive->bad_wstat, WAIT_DRQ)) {
  351. printk(KERN_ERR "%s: no DRQ after issuing %sn",
  352. drive->name,
  353. drive->mult_count ? "MULTWRITE" : "WRITE");
  354. return startstop;
  355. }
  356. /* (ks/hs): Fixed Multi Write */
  357. if ((taskfile->command != WIN_MULTWRITE) &&
  358.     (taskfile->command != WIN_MULTWRITE_EXT)) {
  359. struct request *rq = HWGROUP(drive)->rq;
  360. /* For Write_sectors we need to stuff the first sector */
  361. taskfile_output_data(drive, rq->buffer, SECTOR_WORDS);
  362. rq->current_nr_sectors--;
  363. } else {
  364. /* Stuff first sector(s) by implicitly calling the handler */
  365. if (!(drive_is_ready(drive))) {
  366. /* FIXME: Replace hard-coded 100, error handling? */
  367. int i;
  368. for (i=0; i<100; i++) {
  369. if (drive_is_ready(drive))
  370. break;
  371. }
  372. }
  373. return task->handler(drive);
  374. }
  375. #endif
  376. } else {
  377. /* for dma commands we down set the handler */
  378. if (drive->using_dma && !(HWIF(drive)->dmaproc(((taskfile->command == WIN_WRITEDMA) || (taskfile->command == WIN_WRITEDMA_EXT)) ? ide_dma_write : ide_dma_read, drive)));
  379. }
  380. return ide_started;
  381. }
  382. #endif
  383. #if 0
  384. /*
  385.  * Error reporting, in human readable form (luxurious, but a memory hog).
  386.  */
  387. byte taskfile_dump_status (ide_drive_t *drive, const char *msg, byte stat)
  388. {
  389. unsigned long flags;
  390. byte err = 0;
  391. __save_flags (flags); /* local CPU only */
  392. ide__sti(); /* local CPU only */
  393. printk("%s: %s: status=0x%02x", drive->name, msg, stat);
  394. #if FANCY_STATUS_DUMPS
  395. printk(" { ");
  396. if (stat & BUSY_STAT)
  397. printk("Busy ");
  398. else {
  399. if (stat & READY_STAT) printk("DriveReady ");
  400. if (stat & WRERR_STAT) printk("DeviceFault ");
  401. if (stat & SEEK_STAT) printk("SeekComplete ");
  402. if (stat & DRQ_STAT) printk("DataRequest ");
  403. if (stat & ECC_STAT) printk("CorrectedError ");
  404. if (stat & INDEX_STAT) printk("Index ");
  405. if (stat & ERR_STAT) printk("Error ");
  406. }
  407. printk("}");
  408. #endif  /* FANCY_STATUS_DUMPS */
  409. printk("n");
  410. if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
  411. err = GET_ERR();
  412. printk("%s: %s: error=0x%02x", drive->name, msg, err);
  413. #if FANCY_STATUS_DUMPS
  414. if (drive->media == ide_disk) {
  415. printk(" { ");
  416. if (err & ABRT_ERR) printk("DriveStatusError ");
  417. if (err & ICRC_ERR) printk("%s", (err & ABRT_ERR) ? "BadCRC " : "BadSector ");
  418. if (err & ECC_ERR) printk("UncorrectableError ");
  419. if (err & ID_ERR) printk("SectorIdNotFound ");
  420. if (err & TRK0_ERR) printk("TrackZeroNotFound ");
  421. if (err & MARK_ERR) printk("AddrMarkNotFound ");
  422. printk("}");
  423. if ((err & (BBD_ERR | ABRT_ERR)) == BBD_ERR || (err & (ECC_ERR|ID_ERR|MARK_ERR))) {
  424. if ((drive->id->command_set_2 & 0x0400) &&
  425.     (drive->id->cfs_enable_2 & 0x0400) &&
  426.     (drive->addressing == 1)) {
  427. __u64 sectors = 0;
  428. u32 low = 0, high = 0;
  429. low = task_read_24(drive);
  430. OUT_BYTE(0x80, IDE_CONTROL_REG);
  431. high = task_read_24(drive);
  432. sectors = ((__u64)high << 24) | low;
  433. printk(", LBAsect=%lld", sectors);
  434. } else {
  435. byte cur = IN_BYTE(IDE_SELECT_REG);
  436. if (cur & 0x40) { /* using LBA? */
  437. printk(", LBAsect=%ld", (unsigned long)
  438.  ((cur&0xf)<<24)
  439.  |(IN_BYTE(IDE_HCYL_REG)<<16)
  440.  |(IN_BYTE(IDE_LCYL_REG)<<8)
  441.  | IN_BYTE(IDE_SECTOR_REG));
  442. } else {
  443. printk(", CHS=%d/%d/%d",
  444.   (IN_BYTE(IDE_HCYL_REG)<<8) +
  445.    IN_BYTE(IDE_LCYL_REG),
  446.   cur & 0xf,
  447.   IN_BYTE(IDE_SECTOR_REG));
  448. }
  449. }
  450. if (HWGROUP(drive)->rq)
  451. printk(", sector=%llu", (__u64) HWGROUP(drive)->rq->sector);
  452. }
  453. }
  454. #endif  /* FANCY_STATUS_DUMPS */
  455. printk("n");
  456. }
  457. __restore_flags (flags); /* local CPU only */
  458. return err;
  459. }
  460. /*
  461.  * Clean up after success/failure of an explicit taskfile operation.
  462.  */
  463. void ide_end_taskfile (ide_drive_t *drive, byte stat, byte err)
  464. {
  465. unsigned long flags;
  466. struct request *rq;
  467. ide_task_t *args;
  468. task_ioreg_t command;
  469. spin_lock_irqsave(&io_request_lock, flags);
  470. rq = HWGROUP(drive)->rq;
  471. spin_unlock_irqrestore(&io_request_lock, flags);
  472. args = (ide_task_t *) rq->special;
  473. command = args->tfRegister[IDE_COMMAND_OFFSET];
  474. rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT);
  475. args->tfRegister[IDE_ERROR_OFFSET]   = err;
  476. args->tfRegister[IDE_NSECTOR_OFFSET] = IN_BYTE(IDE_NSECTOR_REG);
  477. args->tfRegister[IDE_SECTOR_OFFSET]  = IN_BYTE(IDE_SECTOR_REG);
  478. args->tfRegister[IDE_LCYL_OFFSET]    = IN_BYTE(IDE_LCYL_REG);
  479. args->tfRegister[IDE_HCYL_OFFSET]    = IN_BYTE(IDE_HCYL_REG);
  480. args->tfRegister[IDE_SELECT_OFFSET]  = IN_BYTE(IDE_SELECT_REG);
  481. args->tfRegister[IDE_STATUS_OFFSET]  = stat;
  482. if ((drive->id->command_set_2 & 0x0400) &&
  483.     (drive->id->cfs_enable_2 & 0x0400) &&
  484.     (drive->addressing == 1)) {
  485. OUT_BYTE(drive->ctl|0x80, IDE_CONTROL_REG_HOB);
  486. args->hobRegister[IDE_FEATURE_OFFSET_HOB] = IN_BYTE(IDE_FEATURE_REG);
  487. args->hobRegister[IDE_NSECTOR_OFFSET_HOB] = IN_BYTE(IDE_NSECTOR_REG);
  488. args->hobRegister[IDE_SECTOR_OFFSET_HOB]  = IN_BYTE(IDE_SECTOR_REG);
  489. args->hobRegister[IDE_LCYL_OFFSET_HOB]    = IN_BYTE(IDE_LCYL_REG);
  490. args->hobRegister[IDE_HCYL_OFFSET_HOB]    = IN_BYTE(IDE_HCYL_REG);
  491. }
  492. /* taskfile_settings_update(drive, args, command); */
  493. spin_lock_irqsave(&io_request_lock, flags);
  494. blkdev_dequeue_request(rq);
  495. HWGROUP(drive)->rq = NULL;
  496. end_that_request_last(rq);
  497. spin_unlock_irqrestore(&io_request_lock, flags);
  498. }
  499. /*
  500.  * try_to_flush_leftover_data() is invoked in response to a drive
  501.  * unexpectedly having its DRQ_STAT bit set.  As an alternative to
  502.  * resetting the drive, this routine tries to clear the condition
  503.  * by read a sector's worth of data from the drive.  Of course,
  504.  * this may not help if the drive is *waiting* for data from *us*.
  505.  */
  506. void task_try_to_flush_leftover_data (ide_drive_t *drive)
  507. {
  508. int i = (drive->mult_count ? drive->mult_count : 1) * SECTOR_WORDS;
  509. if (drive->media != ide_disk)
  510. return;
  511. while (i > 0) {
  512. u32 buffer[16];
  513. unsigned int wcount = (i > 16) ? 16 : i;
  514. i -= wcount;
  515. taskfile_input_data (drive, buffer, wcount);
  516. }
  517. }
  518. /*
  519.  * taskfile_error() takes action based on the error returned by the drive.
  520.  */
  521. ide_startstop_t taskfile_error (ide_drive_t *drive, const char *msg, byte stat)
  522. {
  523. struct request *rq;
  524. byte err;
  525.         err = taskfile_dump_status(drive, msg, stat);
  526. if (drive == NULL || (rq = HWGROUP(drive)->rq) == NULL)
  527. return ide_stopped;
  528. /* retry only "normal" I/O: */
  529. if (rq->cmd == IDE_DRIVE_TASKFILE) {
  530. rq->errors = 1;
  531. ide_end_taskfile(drive, stat, err);
  532. return ide_stopped;
  533. }
  534. if (stat & BUSY_STAT || ((stat & WRERR_STAT) && !drive->nowerr)) { /* other bits are useless when BUSY */
  535. rq->errors |= ERROR_RESET;
  536. } else {
  537. if (drive->media == ide_disk && (stat & ERR_STAT)) {
  538. /* err has different meaning on cdrom and tape */
  539. if (err == ABRT_ERR) {
  540. if (drive->select.b.lba && IN_BYTE(IDE_COMMAND_REG) == WIN_SPECIFY)
  541. return ide_stopped; /* some newer drives don't support WIN_SPECIFY */
  542. } else if ((err & (ABRT_ERR | ICRC_ERR)) == (ABRT_ERR | ICRC_ERR)) {
  543. drive->crc_count++; /* UDMA crc error -- just retry the operation */
  544. } else if (err & (BBD_ERR | ECC_ERR)) /* retries won't help these */
  545. rq->errors = ERROR_MAX;
  546. else if (err & TRK0_ERR) /* help it find track zero */
  547.                                 rq->errors |= ERROR_RECAL;
  548.                 }
  549.                 if ((stat & DRQ_STAT) && rq->cmd != WRITE)
  550.                         task_try_to_flush_leftover_data(drive);
  551. }
  552. if (GET_STAT() & (BUSY_STAT|DRQ_STAT))
  553. OUT_BYTE(WIN_IDLEIMMEDIATE,IDE_COMMAND_REG); /* force an abort */
  554. if (rq->errors >= ERROR_MAX) {
  555. if (drive->driver != NULL)
  556. DRIVER(drive)->end_request(0, HWGROUP(drive));
  557. else
  558. ide_end_request(0, HWGROUP(drive));
  559. } else {
  560. if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
  561. ++rq->errors;
  562. return ide_do_reset(drive);
  563. }
  564. if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
  565. drive->special.b.recalibrate = 1;
  566. ++rq->errors;
  567. }
  568. return ide_stopped;
  569. }
  570. #endif
  571. /*
  572.  * Handler for special commands without a data phase from ide-disk
  573.  */
  574. /*
  575.  * set_multmode_intr() is invoked on completion of a WIN_SETMULT cmd.
  576.  */
  577. ide_startstop_t set_multmode_intr (ide_drive_t *drive)
  578. {
  579. byte stat;
  580. if (OK_STAT(stat=GET_STAT(),READY_STAT,BAD_STAT)) {
  581. drive->mult_count = drive->mult_req;
  582. } else {
  583. drive->mult_req = drive->mult_count = 0;
  584. drive->special.b.recalibrate = 1;
  585. (void) ide_dump_status(drive, "set_multmode", stat);
  586. }
  587. return ide_stopped;
  588. }
  589. /*
  590.  * set_geometry_intr() is invoked on completion of a WIN_SPECIFY cmd.
  591.  */
  592. ide_startstop_t set_geometry_intr (ide_drive_t *drive)
  593. {
  594. byte stat;
  595. if (OK_STAT(stat=GET_STAT(),READY_STAT,BAD_STAT))
  596. return ide_stopped;
  597. if (stat & (ERR_STAT|DRQ_STAT))
  598. return ide_error(drive, "set_geometry_intr", stat);
  599. ide_set_handler(drive, &set_geometry_intr, WAIT_CMD, NULL);
  600. return ide_started;
  601. }
  602. /*
  603.  * recal_intr() is invoked on completion of a WIN_RESTORE (recalibrate) cmd.
  604.  */
  605. ide_startstop_t recal_intr (ide_drive_t *drive)
  606. {
  607. byte stat = GET_STAT();
  608. if (!OK_STAT(stat,READY_STAT,BAD_STAT))
  609. return ide_error(drive, "recal_intr", stat);
  610. return ide_stopped;
  611. }
  612. /*
  613.  * Handler for commands without a data phase
  614.  */
  615. ide_startstop_t task_no_data_intr (ide_drive_t *drive)
  616. {
  617. ide_task_t *args = HWGROUP(drive)->rq->special;
  618. byte stat = GET_STAT();
  619. ide__sti(); /* local CPU only */
  620. if (!OK_STAT(stat, READY_STAT, BAD_STAT))
  621. return ide_error(drive, "task_no_data_intr", stat); /* calls ide_end_drive_cmd */
  622. if (args)
  623. ide_end_drive_cmd (drive, stat, GET_ERR());
  624. return ide_stopped;
  625. }
  626. /*
  627.  * Handler for command with PIO data-in phase
  628.  */
  629. ide_startstop_t task_in_intr (ide_drive_t *drive)
  630. {
  631. byte stat = GET_STAT();
  632. byte io_32bit = drive->io_32bit;
  633. struct request *rq = HWGROUP(drive)->rq;
  634. char *pBuf = NULL;
  635. if (!OK_STAT(stat,DATA_READY,BAD_R_STAT)) {
  636. if (stat & (ERR_STAT|DRQ_STAT)) {
  637. return ide_error(drive, "task_in_intr", stat);
  638. }
  639. if (!(stat & BUSY_STAT)) {
  640. DTF("task_in_intr to Soon wait for next interruptn");
  641. ide_set_handler(drive, &task_in_intr, WAIT_CMD, NULL);
  642. return ide_started;  
  643. }
  644. }
  645. DTF("stat: %02xn", stat);
  646. pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
  647. DTF("Read: %p, rq->current_nr_sectors: %dn", pBuf, (int) rq->current_nr_sectors);
  648. drive->io_32bit = 0;
  649. taskfile_input_data(drive, pBuf, SECTOR_WORDS);
  650. drive->io_32bit = io_32bit;
  651. if (--rq->current_nr_sectors <= 0) {
  652. /* (hs): swapped next 2 lines */
  653. DTF("Request Ended stat: %02xn", GET_STAT());
  654. ide_end_request(1, HWGROUP(drive));
  655. } else {
  656. ide_set_handler(drive, &task_in_intr,  WAIT_CMD, NULL);
  657. return ide_started;
  658. }
  659. return ide_stopped;
  660. }
  661. #undef ALTSTAT_SCREW_UP
  662. #ifdef ALTSTAT_SCREW_UP
  663. /*
  664.  * (ks/hs): Poll Alternate Status Register to ensure
  665.  * that drive is not busy.
  666.  */
  667. byte altstat_multi_busy (ide_drive_t *drive, byte stat, const char *msg)
  668. {
  669. int i;
  670. DTF("multi%s: ASR = %xn", msg, stat);
  671. if (stat & BUSY_STAT) {
  672. /* (ks/hs): FIXME: Replace hard-coded 100, error handling? */
  673. for (i=0; i<100; i++) {
  674. stat = GET_ALTSTAT();
  675. if ((stat & BUSY_STAT) == 0)
  676. break;
  677. }
  678. }
  679. /*
  680.  * (ks/hs): Read Status AFTER Alternate Status Register
  681.  */
  682. return(GET_STAT());
  683. }
  684. /*
  685.  * (ks/hs): Poll Alternate status register to wait for drive
  686.  * to become ready for next transfer
  687.  */
  688. byte altstat_multi_poll (ide_drive_t *drive, byte stat, const char *msg)
  689. {
  690. /* (ks/hs): FIXME: Error handling, time-out? */
  691. while (stat & BUSY_STAT)
  692. stat = GET_ALTSTAT();
  693. DTF("multi%s: nsect=1, ASR = %xn", msg, stat);
  694. return(GET_STAT()); /* (ks/hs): Clear pending IRQ */
  695. }
  696. #endif /* ALTSTAT_SCREW_UP */
  697. /*
  698.  * Handler for command with Read Multiple
  699.  */
  700. ide_startstop_t task_mulin_intr (ide_drive_t *drive)
  701. {
  702. unsigned int msect, nsect;
  703. #ifdef ALTSTAT_SCREW_UP
  704. byte stat = altstat_multi_busy(drive, GET_ALTSTAT(), "read");
  705. #else
  706. byte stat = GET_STAT();
  707. #endif /* ALTSTAT_SCREW_UP */
  708. byte io_32bit = drive->io_32bit;
  709. struct request *rq = HWGROUP(drive)->rq;
  710. char *pBuf = NULL;
  711. if (!OK_STAT(stat,DATA_READY,BAD_R_STAT)) {
  712. if (stat & (ERR_STAT|DRQ_STAT)) {
  713. return ide_error(drive, "task_mulin_intr", stat);
  714. }
  715. /* no data yet, so wait for another interrupt */
  716. ide_set_handler(drive, &task_mulin_intr, WAIT_CMD, NULL);
  717. return ide_started;
  718. }
  719. /* (ks/hs): Fixed Multi-Sector transfer */
  720. msect = drive->mult_count;
  721. #ifdef ALTSTAT_SCREW_UP
  722. /*
  723.  * Screw the request we do not support bad data-phase setups!
  724.  * Either read and learn the ATA standard or crash yourself!
  725.  */
  726. if (!msect) {
  727. /*
  728.  * (ks/hs): Drive supports multi-sector transfer,
  729.  * drive->mult_count was not set
  730.  */
  731. nsect = 1;
  732. while (rq->current_nr_sectors) {
  733. pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
  734. DTF("Multiread: %p, nsect: %d, rq->current_nr_sectors: %ldn", pBuf, nsect, rq->current_nr_sectors);
  735. drive->io_32bit = 0;
  736. taskfile_input_data(drive, pBuf, nsect * SECTOR_WORDS);
  737. drive->io_32bit = io_32bit;
  738. rq->errors = 0;
  739. rq->current_nr_sectors -= nsect;
  740. stat = altstat_multi_poll(drive, GET_ALTSTAT(), "read");
  741. }
  742. ide_end_request(1, HWGROUP(drive));
  743. return ide_stopped;
  744. }
  745. #endif /* ALTSTAT_SCREW_UP */
  746. nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
  747. pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
  748. DTF("Multiread: %p, nsect: %d , rq->current_nr_sectors: %ldn",
  749. pBuf, nsect, rq->current_nr_sectors);
  750. drive->io_32bit = 0;
  751. taskfile_input_data(drive, pBuf, nsect * SECTOR_WORDS);
  752. drive->io_32bit = io_32bit;
  753. rq->errors = 0;
  754. rq->current_nr_sectors -= nsect;
  755. if (rq->current_nr_sectors != 0) {
  756. ide_set_handler(drive, &task_mulin_intr, WAIT_CMD, NULL);
  757. return ide_started;
  758. }
  759. ide_end_request(1, HWGROUP(drive));
  760. return ide_stopped;
  761. }
  762. ide_startstop_t pre_task_out_intr (ide_drive_t *drive, struct request *rq)
  763. {
  764. ide_task_t *args = rq->special;
  765. ide_startstop_t startstop;
  766. if (ide_wait_stat(&startstop, drive, DATA_READY, drive->bad_wstat, WAIT_DRQ)) {
  767. printk(KERN_ERR "%s: no DRQ after issuing %sn", drive->name, drive->mult_count ? "MULTWRITE" : "WRITE");
  768. return startstop;
  769. }
  770. /* (ks/hs): Fixed Multi Write */
  771. if ((args->tfRegister[IDE_COMMAND_OFFSET] != WIN_MULTWRITE) &&
  772.     (args->tfRegister[IDE_COMMAND_OFFSET] != WIN_MULTWRITE_EXT)) {
  773. /* For Write_sectors we need to stuff the first sector */
  774. taskfile_output_data(drive, rq->buffer, SECTOR_WORDS);
  775. rq->current_nr_sectors--;
  776. return ide_started;
  777. } else {
  778. /*
  779.  * (ks/hs): Stuff the first sector(s)
  780.  * by implicitly calling the handler
  781.  */
  782. if (!(drive_is_ready(drive))) {
  783. int i;
  784. /*
  785.  * (ks/hs): FIXME: Replace hard-coded
  786.  *               100, error handling?
  787.  */
  788. for (i=0; i<100; i++) {
  789. if (drive_is_ready(drive))
  790. break;
  791. }
  792. }
  793. return args->handler(drive);
  794. }
  795. return ide_started;
  796. }
  797. /*
  798.  * Handler for command with PIO data-out phase
  799.  */
  800. ide_startstop_t task_out_intr (ide_drive_t *drive)
  801. {
  802. byte stat = GET_STAT();
  803. byte io_32bit = drive->io_32bit;
  804. struct request *rq = HWGROUP(drive)->rq;
  805. char *pBuf = NULL;
  806. if (!rq->current_nr_sectors) { 
  807. ide_end_request(1, HWGROUP(drive));
  808. return ide_stopped;
  809. }
  810. if (!OK_STAT(stat,DRIVE_READY,drive->bad_wstat)) {
  811. return ide_error(drive, "task_out_intr", stat);
  812. }
  813. if ((rq->current_nr_sectors==1) ^ (stat & DRQ_STAT)) {
  814. rq = HWGROUP(drive)->rq;
  815. pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
  816. DTF("write: %p, rq->current_nr_sectors: %dn", pBuf, (int) rq->current_nr_sectors);
  817. drive->io_32bit = 0;
  818. taskfile_output_data(drive, pBuf, SECTOR_WORDS);
  819. drive->io_32bit = io_32bit;
  820. rq->errors = 0;
  821. rq->current_nr_sectors--;
  822. }
  823. if (rq->current_nr_sectors <= 0) {
  824. ide_end_request(1, HWGROUP(drive));
  825. } else {
  826. ide_set_handler(drive, &task_out_intr, WAIT_CMD, NULL);
  827. return ide_started;
  828. }
  829. return ide_stopped;
  830. }
  831. /*
  832.  * Handler for command write multiple
  833.  * Called directly from execute_drive_cmd for the first bunch of sectors,
  834.  * afterwards only by the ISR
  835.  */
  836. ide_startstop_t task_mulout_intr (ide_drive_t *drive)
  837. {
  838. unsigned int msect, nsect;
  839. #ifdef ALTSTAT_SCREW_UP
  840. byte stat = altstat_multi_busy(drive, GET_ALTSTAT(), "write");
  841. #else
  842. byte stat = GET_STAT();
  843. #endif /* ALTSTAT_SCREW_UP */
  844. byte io_32bit = drive->io_32bit;
  845. struct request *rq = HWGROUP(drive)->rq;
  846. ide_hwgroup_t *hwgroup = HWGROUP(drive);
  847. char *pBuf = NULL;
  848. /*
  849.  * (ks/hs): Handle last IRQ on multi-sector transfer,
  850.  * occurs after all data was sent
  851.  */
  852. if (rq->current_nr_sectors == 0) {
  853. if (stat & (ERR_STAT|DRQ_STAT))
  854. return ide_error(drive, "task_mulout_intr", stat);
  855. ide_end_request(1, HWGROUP(drive));
  856. return ide_stopped;
  857. }
  858. if (!OK_STAT(stat,DATA_READY,BAD_R_STAT)) {
  859. if (stat & (ERR_STAT|DRQ_STAT)) {
  860. return ide_error(drive, "task_mulout_intr", stat);
  861. }
  862. /* no data yet, so wait for another interrupt */
  863. if (hwgroup->handler == NULL)
  864. ide_set_handler(drive, &task_mulout_intr, WAIT_CMD, NULL);
  865. return ide_started;
  866. }
  867. /* (ks/hs): See task_mulin_intr */
  868. msect = drive->mult_count;
  869. #ifdef ALTSTAT_SCREW_UP
  870. /*
  871.  * Screw the request we do not support bad data-phase setups!
  872.  * Either read and learn the ATA standard or crash yourself!
  873.  */
  874. if (!msect) {
  875. nsect = 1;
  876. while (rq->current_nr_sectors) {
  877. pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
  878. DTF("Multiwrite: %p, nsect: %d, rq->current_nr_sectors: %ldn", pBuf, nsect, rq->current_nr_sectors);
  879. drive->io_32bit = 0;
  880. taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
  881. drive->io_32bit = io_32bit;
  882. rq->errors = 0;
  883. rq->current_nr_sectors -= nsect;
  884. stat = altstat_multi_poll(drive, GET_ALTSTAT(), "write");
  885. }
  886. ide_end_request(1, HWGROUP(drive));
  887. return ide_stopped;
  888. }
  889. #endif /* ALTSTAT_SCREW_UP */
  890. nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
  891. pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
  892. DTF("Multiwrite: %p, nsect: %d , rq->current_nr_sectors: %ldn",
  893. pBuf, nsect, rq->current_nr_sectors);
  894. drive->io_32bit = 0;
  895. taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
  896. drive->io_32bit = io_32bit;
  897. rq->errors = 0;
  898. rq->current_nr_sectors -= nsect;
  899. if (hwgroup->handler == NULL)
  900. ide_set_handler(drive, &task_mulout_intr, WAIT_CMD, NULL);
  901. return ide_started;
  902. }
  903. /* Called by internal to feature out type of command being called */
  904. ide_pre_handler_t * ide_pre_handler_parser (struct hd_drive_task_hdr *taskfile, struct hd_drive_hob_hdr *hobfile)
  905. {
  906. switch(taskfile->command) {
  907. /* IDE_DRIVE_TASK_RAW_WRITE */
  908. case CFA_WRITE_MULTI_WO_ERASE:
  909. case WIN_MULTWRITE:
  910. case WIN_MULTWRITE_EXT:
  911. // case WIN_WRITEDMA:
  912. // case WIN_WRITEDMA_QUEUED:
  913. // case WIN_WRITEDMA_EXT:
  914. // case WIN_WRITEDMA_QUEUED_EXT:
  915. /* IDE_DRIVE_TASK_OUT */
  916. case WIN_WRITE:
  917. case WIN_WRITE_VERIFY:
  918. case WIN_WRITE_BUFFER:
  919. case CFA_WRITE_SECT_WO_ERASE:
  920. case WIN_DOWNLOAD_MICROCODE:
  921. return &pre_task_out_intr;
  922. /* IDE_DRIVE_TASK_OUT */
  923. case WIN_SMART:
  924. if (taskfile->feature == SMART_WRITE_LOG_SECTOR)
  925. return &pre_task_out_intr;
  926. default:
  927. break;
  928. }
  929. return(NULL);
  930. }
  931. /* Called by internal to feature out type of command being called */
  932. ide_handler_t * ide_handler_parser (struct hd_drive_task_hdr *taskfile, struct hd_drive_hob_hdr *hobfile)
  933. {
  934. switch(taskfile->command) {
  935. case WIN_IDENTIFY:
  936. case WIN_PIDENTIFY:
  937. case CFA_TRANSLATE_SECTOR:
  938. case WIN_READ_BUFFER:
  939. case WIN_READ:
  940. case WIN_READ_EXT:
  941. return &task_in_intr;
  942. case WIN_SECURITY_DISABLE:
  943. case WIN_SECURITY_ERASE_UNIT:
  944. case WIN_SECURITY_SET_PASS:
  945. case WIN_SECURITY_UNLOCK:
  946. case WIN_DOWNLOAD_MICROCODE:
  947. case CFA_WRITE_SECT_WO_ERASE:
  948. case WIN_WRITE_BUFFER:
  949. case WIN_WRITE_VERIFY:
  950. case WIN_WRITE:
  951. case WIN_WRITE_EXT:
  952. return &task_out_intr;
  953. case WIN_MULTREAD:
  954. case WIN_MULTREAD_EXT:
  955. return &task_mulin_intr;
  956. case CFA_WRITE_MULTI_WO_ERASE:
  957. case WIN_MULTWRITE:
  958. case WIN_MULTWRITE_EXT:
  959. return &task_mulout_intr;
  960. case WIN_SMART:
  961. switch(taskfile->feature) {
  962. case SMART_READ_VALUES:
  963. case SMART_READ_THRESHOLDS:
  964. case SMART_READ_LOG_SECTOR:
  965. return &task_in_intr;
  966. case SMART_WRITE_LOG_SECTOR:
  967. return &task_out_intr;
  968. default:
  969. return &task_no_data_intr;
  970. }
  971. case CFA_REQ_EXT_ERROR_CODE:
  972. case CFA_ERASE_SECTORS:
  973. case WIN_VERIFY:
  974. case WIN_VERIFY_EXT:
  975. case WIN_SEEK:
  976. return &task_no_data_intr;
  977. case WIN_SPECIFY:
  978. return &set_geometry_intr;
  979. case WIN_RESTORE:
  980. return &recal_intr;
  981. case WIN_DIAGNOSE:
  982. case WIN_FLUSH_CACHE:
  983. case WIN_FLUSH_CACHE_EXT:
  984. case WIN_STANDBYNOW1:
  985. case WIN_STANDBYNOW2:
  986. case WIN_SLEEPNOW1:
  987. case WIN_SLEEPNOW2:
  988. case WIN_SETIDLE1:
  989. case WIN_CHECKPOWERMODE1:
  990. case WIN_CHECKPOWERMODE2:
  991. case WIN_GETMEDIASTATUS:
  992. case WIN_MEDIAEJECT:
  993. return &task_no_data_intr;
  994. case WIN_SETMULT:
  995. return &set_multmode_intr;
  996. case WIN_READ_NATIVE_MAX:
  997. case WIN_SET_MAX:
  998. case WIN_READ_NATIVE_MAX_EXT:
  999. case WIN_SET_MAX_EXT:
  1000. case WIN_SECURITY_ERASE_PREPARE:
  1001. case WIN_SECURITY_FREEZE_LOCK:
  1002. case WIN_DOORLOCK:
  1003. case WIN_DOORUNLOCK:
  1004. case WIN_SETFEATURES:
  1005. return &task_no_data_intr;
  1006. case DISABLE_SEAGATE:
  1007. case EXABYTE_ENABLE_NEST:
  1008. return &task_no_data_intr;
  1009. #ifdef CONFIG_BLK_DEV_IDEDMA
  1010. case WIN_READDMA:
  1011. case WIN_IDENTIFY_DMA:
  1012. case WIN_READDMA_QUEUED:
  1013. case WIN_READDMA_EXT:
  1014. case WIN_READDMA_QUEUED_EXT:
  1015. case WIN_WRITEDMA:
  1016. case WIN_WRITEDMA_QUEUED:
  1017. case WIN_WRITEDMA_EXT:
  1018. case WIN_WRITEDMA_QUEUED_EXT:
  1019. #endif
  1020. case WIN_FORMAT:
  1021. case WIN_INIT:
  1022. case WIN_DEVICE_RESET:
  1023. case WIN_QUEUED_SERVICE:
  1024. case WIN_PACKETCMD:
  1025. default:
  1026. return(NULL);
  1027. }
  1028. }
  1029. /* Called by ioctl to feature out type of command being called */
  1030. int ide_cmd_type_parser (ide_task_t *args)
  1031. {
  1032. struct hd_drive_task_hdr *taskfile = (struct hd_drive_task_hdr *) args->tfRegister;
  1033. struct hd_drive_hob_hdr *hobfile = (struct hd_drive_hob_hdr *) args->hobRegister;
  1034. args->prehandler = ide_pre_handler_parser(taskfile, hobfile);
  1035. args->handler = ide_handler_parser(taskfile, hobfile);
  1036. switch(args->tfRegister[IDE_COMMAND_OFFSET]) {
  1037. case WIN_IDENTIFY:
  1038. case WIN_PIDENTIFY:
  1039. return IDE_DRIVE_TASK_IN;
  1040. case CFA_TRANSLATE_SECTOR:
  1041. case WIN_READ:
  1042. case WIN_READ_BUFFER:
  1043. return IDE_DRIVE_TASK_IN;
  1044. case WIN_WRITE:
  1045. case WIN_WRITE_VERIFY:
  1046. case WIN_WRITE_BUFFER:
  1047. case CFA_WRITE_SECT_WO_ERASE:
  1048. case WIN_DOWNLOAD_MICROCODE:
  1049. return IDE_DRIVE_TASK_RAW_WRITE;
  1050. case WIN_MULTREAD:
  1051. return IDE_DRIVE_TASK_IN;
  1052. case CFA_WRITE_MULTI_WO_ERASE:
  1053. case WIN_MULTWRITE:
  1054. return IDE_DRIVE_TASK_RAW_WRITE;
  1055. case WIN_SECURITY_DISABLE:
  1056. case WIN_SECURITY_ERASE_UNIT:
  1057. case WIN_SECURITY_SET_PASS:
  1058. case WIN_SECURITY_UNLOCK:
  1059. return IDE_DRIVE_TASK_OUT;
  1060. case WIN_SMART:
  1061. args->tfRegister[IDE_LCYL_OFFSET] = SMART_LCYL_PASS;
  1062. args->tfRegister[IDE_HCYL_OFFSET] = SMART_HCYL_PASS;
  1063. switch(args->tfRegister[IDE_FEATURE_OFFSET]) {
  1064. case SMART_READ_VALUES:
  1065. case SMART_READ_THRESHOLDS:
  1066. case SMART_READ_LOG_SECTOR:
  1067. return IDE_DRIVE_TASK_IN;
  1068. case SMART_WRITE_LOG_SECTOR:
  1069. return IDE_DRIVE_TASK_OUT;
  1070. default:
  1071. return IDE_DRIVE_TASK_NO_DATA;
  1072. }
  1073. #ifdef CONFIG_BLK_DEV_IDEDMA
  1074. case WIN_READDMA:
  1075. case WIN_IDENTIFY_DMA:
  1076. case WIN_READDMA_QUEUED:
  1077. case WIN_READDMA_EXT:
  1078. case WIN_READDMA_QUEUED_EXT:
  1079. return IDE_DRIVE_TASK_IN;
  1080. case WIN_WRITEDMA:
  1081. case WIN_WRITEDMA_QUEUED:
  1082. case WIN_WRITEDMA_EXT:
  1083. case WIN_WRITEDMA_QUEUED_EXT:
  1084. return IDE_DRIVE_TASK_RAW_WRITE;
  1085. #endif
  1086. case WIN_SETFEATURES:
  1087. switch(args->tfRegister[IDE_FEATURE_OFFSET]) {
  1088. case SETFEATURES_XFER:
  1089. return IDE_DRIVE_TASK_SET_XFER;
  1090. case SETFEATURES_DIS_DEFECT:
  1091. case SETFEATURES_EN_APM:
  1092. case SETFEATURES_DIS_MSN:
  1093. case SETFEATURES_EN_RI:
  1094. case SETFEATURES_EN_SI:
  1095. case SETFEATURES_DIS_RPOD:
  1096. case SETFEATURES_DIS_WCACHE:
  1097. case SETFEATURES_EN_DEFECT:
  1098. case SETFEATURES_DIS_APM:
  1099. case SETFEATURES_EN_MSN:
  1100. case SETFEATURES_EN_RLA:
  1101. case SETFEATURES_PREFETCH:
  1102. case SETFEATURES_EN_RPOD:
  1103. case SETFEATURES_DIS_RI:
  1104. case SETFEATURES_DIS_SI:
  1105. default:
  1106. return IDE_DRIVE_TASK_NO_DATA;
  1107. }
  1108. case WIN_NOP:
  1109. case CFA_REQ_EXT_ERROR_CODE:
  1110. case CFA_ERASE_SECTORS:
  1111. case WIN_VERIFY:
  1112. case WIN_VERIFY_EXT:
  1113. case WIN_SEEK:
  1114. case WIN_SPECIFY:
  1115. case WIN_RESTORE:
  1116. case WIN_DIAGNOSE:
  1117. case WIN_FLUSH_CACHE:
  1118. case WIN_FLUSH_CACHE_EXT:
  1119. case WIN_STANDBYNOW1:
  1120. case WIN_STANDBYNOW2:
  1121. case WIN_SLEEPNOW1:
  1122. case WIN_SLEEPNOW2:
  1123. case WIN_SETIDLE1:
  1124. case DISABLE_SEAGATE:
  1125. case WIN_CHECKPOWERMODE1:
  1126. case WIN_CHECKPOWERMODE2:
  1127. case WIN_GETMEDIASTATUS:
  1128. case WIN_MEDIAEJECT:
  1129. case WIN_SETMULT:
  1130. case WIN_READ_NATIVE_MAX:
  1131. case WIN_SET_MAX:
  1132. case WIN_READ_NATIVE_MAX_EXT:
  1133. case WIN_SET_MAX_EXT:
  1134. case WIN_SECURITY_ERASE_PREPARE:
  1135. case WIN_SECURITY_FREEZE_LOCK:
  1136. case EXABYTE_ENABLE_NEST:
  1137. case WIN_DOORLOCK:
  1138. case WIN_DOORUNLOCK:
  1139. return IDE_DRIVE_TASK_NO_DATA;
  1140. case WIN_FORMAT:
  1141. case WIN_INIT:
  1142. case WIN_DEVICE_RESET:
  1143. case WIN_QUEUED_SERVICE:
  1144. case WIN_PACKETCMD:
  1145. default:
  1146. return IDE_DRIVE_TASK_INVALID;
  1147. }
  1148. }
  1149. /*
  1150.  * This function is intended to be used prior to invoking ide_do_drive_cmd().
  1151.  */
  1152. void ide_init_drive_taskfile (struct request *rq)
  1153. {
  1154. memset(rq, 0, sizeof(*rq));
  1155. rq->cmd = IDE_DRIVE_TASK_NO_DATA;
  1156. }
  1157. /*
  1158.  * This is kept for internal use only !!!
  1159.  * This is an internal call and nobody in user-space has a damn
  1160.  * reason to call this taskfile.
  1161.  *
  1162.  * ide_raw_taskfile is the one that user-space executes.
  1163.  */
  1164. int ide_wait_taskfile (ide_drive_t *drive, struct hd_drive_task_hdr *taskfile, struct hd_drive_hob_hdr *hobfile, byte *buf)
  1165. {
  1166. struct request rq;
  1167. ide_task_t args;
  1168. memset(&args, 0, sizeof(ide_task_t));
  1169. args.tfRegister[IDE_DATA_OFFSET]         = taskfile->data;
  1170. args.tfRegister[IDE_FEATURE_OFFSET]      = taskfile->feature;
  1171. args.tfRegister[IDE_NSECTOR_OFFSET]      = taskfile->sector_count;
  1172. args.tfRegister[IDE_SECTOR_OFFSET]       = taskfile->sector_number;
  1173. args.tfRegister[IDE_LCYL_OFFSET]         = taskfile->low_cylinder;
  1174. args.tfRegister[IDE_HCYL_OFFSET]         = taskfile->high_cylinder;
  1175. args.tfRegister[IDE_SELECT_OFFSET]       = taskfile->device_head;
  1176. args.tfRegister[IDE_COMMAND_OFFSET]      = taskfile->command;
  1177. args.hobRegister[IDE_DATA_OFFSET_HOB]    = hobfile->data;
  1178. args.hobRegister[IDE_FEATURE_OFFSET_HOB] = hobfile->feature;
  1179. args.hobRegister[IDE_NSECTOR_OFFSET_HOB] = hobfile->sector_count;
  1180. args.hobRegister[IDE_SECTOR_OFFSET_HOB]  = hobfile->sector_number;
  1181. args.hobRegister[IDE_LCYL_OFFSET_HOB]    = hobfile->low_cylinder;
  1182. args.hobRegister[IDE_HCYL_OFFSET_HOB]    = hobfile->high_cylinder;
  1183. args.hobRegister[IDE_SELECT_OFFSET_HOB]  = hobfile->device_head;
  1184. args.hobRegister[IDE_CONTROL_OFFSET_HOB] = hobfile->control;
  1185. ide_init_drive_taskfile(&rq);
  1186. /* This is kept for internal use only !!! */
  1187. args.command_type = ide_cmd_type_parser (&args);
  1188. if (args.command_type != IDE_DRIVE_TASK_NO_DATA)
  1189. rq.current_nr_sectors = rq.nr_sectors = (hobfile->sector_count << 8) | taskfile->sector_count;
  1190. rq.cmd = IDE_DRIVE_TASKFILE;
  1191. rq.buffer = buf;
  1192. rq.special = &args;
  1193. return ide_do_drive_cmd(drive, &rq, ide_wait);
  1194. }
  1195. int ide_raw_taskfile (ide_drive_t *drive, ide_task_t *args, byte *buf)
  1196. {
  1197. struct request rq;
  1198. ide_init_drive_taskfile(&rq);
  1199. rq.cmd = IDE_DRIVE_TASKFILE;
  1200. rq.buffer = buf;
  1201. if (args->command_type != IDE_DRIVE_TASK_NO_DATA)
  1202. rq.current_nr_sectors = rq.nr_sectors = (args->hobRegister[IDE_NSECTOR_OFFSET_HOB] << 8) | args->tfRegister[IDE_NSECTOR_OFFSET];
  1203. rq.special = args;
  1204. return ide_do_drive_cmd(drive, &rq, ide_wait);
  1205. }
  1206. #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
  1207. char * ide_ioctl_verbose (unsigned int cmd)
  1208. {
  1209. return("unknown");
  1210. }
  1211. char * ide_task_cmd_verbose (byte task)
  1212. {
  1213. return("unknown");
  1214. }
  1215. #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
  1216. /*
  1217.  *  The taskfile glue table
  1218.  *
  1219.  *  reqtask.data_phase reqtask.req_cmd
  1220.  *   args.command_type args.handler
  1221.  *
  1222.  *  TASKFILE_P_OUT_DMAQ ?? ??
  1223.  *  TASKFILE_P_IN_DMAQ ?? ??
  1224.  *  TASKFILE_P_OUT_DMA ?? ??
  1225.  *  TASKFILE_P_IN_DMA ?? ??
  1226.  *  TASKFILE_P_OUT ?? ??
  1227.  *  TASKFILE_P_IN ?? ??
  1228.  *
  1229.  *  TASKFILE_OUT_DMAQ IDE_DRIVE_TASK_RAW_WRITE NULL
  1230.  *  TASKFILE_IN_DMAQ IDE_DRIVE_TASK_IN NULL
  1231.  *
  1232.  *  TASKFILE_OUT_DMA IDE_DRIVE_TASK_RAW_WRITE NULL
  1233.  *  TASKFILE_IN_DMA IDE_DRIVE_TASK_IN NULL
  1234.  *
  1235.  *  TASKFILE_IN_OUT ?? ??
  1236.  *
  1237.  *  TASKFILE_MULTI_OUT IDE_DRIVE_TASK_RAW_WRITE task_mulout_intr
  1238.  *  TASKFILE_MULTI_IN IDE_DRIVE_TASK_IN task_mulin_intr
  1239.  *
  1240.  *  TASKFILE_OUT IDE_DRIVE_TASK_RAW_WRITE task_out_intr
  1241.  *  TASKFILE_OUT IDE_DRIVE_TASK_OUT task_out_intr
  1242.  *
  1243.  *  TASKFILE_IN IDE_DRIVE_TASK_IN task_in_intr
  1244.  *  TASKFILE_NO_DATA IDE_DRIVE_TASK_NO_DATA task_no_data_intr
  1245.  *
  1246.  *   IDE_DRIVE_TASK_SET_XFER task_no_data_intr
  1247.  *   IDE_DRIVE_TASK_INVALID
  1248.  *
  1249.  */
  1250. #define MAX_DMA (256*SECTOR_WORDS)
  1251. int ide_taskfile_ioctl (ide_drive_t *drive, struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
  1252. {
  1253. ide_task_request_t *req_task;
  1254. ide_task_t args;
  1255. byte *outbuf = NULL;
  1256. byte *inbuf = NULL;
  1257. task_ioreg_t *argsptr = args.tfRegister;
  1258. task_ioreg_t *hobsptr = args.hobRegister;
  1259. int err = 0;
  1260. int tasksize = sizeof(struct ide_task_request_s);
  1261. int taskin = 0;
  1262. int taskout = 0;
  1263. req_task = kmalloc(tasksize, GFP_KERNEL);
  1264. if (req_task == NULL) return -ENOMEM;
  1265. memset(req_task, 0, tasksize);
  1266. if (copy_from_user(req_task, (void *) arg, tasksize)) {
  1267. kfree(req_task);
  1268. return -EFAULT;
  1269. }
  1270. taskout = (int) req_task->out_size;
  1271. taskin  = (int) req_task->in_size;
  1272. if (taskout) {
  1273. int outtotal = tasksize;
  1274. outbuf = kmalloc(taskout, GFP_KERNEL);
  1275. if (outbuf == NULL) {
  1276. err = -ENOMEM;
  1277. goto abort;
  1278. }
  1279. memset(outbuf, 0, taskout);
  1280. if (copy_from_user(outbuf, (void *)arg + outtotal, taskout)) {
  1281. err = -EFAULT;
  1282. goto abort;
  1283. }
  1284. }
  1285. if (taskin) {
  1286. int intotal = tasksize + taskout;
  1287. inbuf = kmalloc(taskin, GFP_KERNEL);
  1288. if (inbuf == NULL) {
  1289. err = -ENOMEM;
  1290. goto abort;
  1291. }
  1292. memset(inbuf, 0, taskin);
  1293. if (copy_from_user(inbuf, (void *)arg + intotal , taskin)) {
  1294. err = -EFAULT;
  1295. goto abort;
  1296. }
  1297. }
  1298. memset(argsptr, 0, HDIO_DRIVE_TASK_HDR_SIZE);
  1299. memset(hobsptr, 0, HDIO_DRIVE_HOB_HDR_SIZE);
  1300. memcpy(argsptr, req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE);
  1301. memcpy(hobsptr, req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE);
  1302. args.tf_in_flags  = req_task->in_flags;
  1303. args.tf_out_flags = req_task->out_flags;
  1304. args.data_phase   = req_task->data_phase;
  1305. args.command_type = req_task->req_cmd;
  1306. #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
  1307. DTF("%s: ide_ioctl_cmd %s:  ide_task_cmd %sn",
  1308. drive->name,
  1309. ide_ioctl_verbose(cmd),
  1310. ide_task_cmd_verbose(args.tfRegister[IDE_COMMAND_OFFSET]));
  1311. #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
  1312. switch(req_task->data_phase) {
  1313. case TASKFILE_OUT_DMAQ:
  1314. case TASKFILE_OUT_DMA:
  1315. args.prehandler = NULL;
  1316. args.handler = NULL;
  1317. args.posthandler = NULL;
  1318. err = ide_raw_taskfile(drive, &args, outbuf);
  1319. break;
  1320. case TASKFILE_IN_DMAQ:
  1321. case TASKFILE_IN_DMA:
  1322. args.prehandler = NULL;
  1323. args.handler = NULL;
  1324. args.posthandler = NULL;
  1325. err = ide_raw_taskfile(drive, &args, inbuf);
  1326. break;
  1327. case TASKFILE_IN_OUT:
  1328. #if 0
  1329. args.prehandler = &pre_task_out_intr;
  1330. args.handler = &task_out_intr;
  1331. args.posthandler = NULL;
  1332. err = ide_raw_taskfile(drive, &args, outbuf);
  1333. args.prehandler = NULL;
  1334. args.handler = &task_in_intr;
  1335. args.posthandler = NULL;
  1336. err = ide_raw_taskfile(drive, &args, inbuf);
  1337. break;
  1338. #else
  1339. err = -EFAULT;
  1340. goto abort;
  1341. #endif
  1342. case TASKFILE_MULTI_OUT:
  1343. if (drive->mult_count) {
  1344. args.prehandler = &pre_task_out_intr;
  1345. args.handler = &task_mulout_intr;
  1346. args.posthandler = NULL;
  1347. err = ide_raw_taskfile(drive, &args, outbuf);
  1348. } else {
  1349. /* (hs): give up if multcount is not set */
  1350. printk("%s: %s Multimode Write " 
  1351. "multcount is not setn",
  1352.  drive->name, __FUNCTION__);
  1353. err = -EPERM;
  1354. goto abort;
  1355. }
  1356. break;
  1357. case TASKFILE_OUT:
  1358. args.prehandler = &pre_task_out_intr;
  1359. args.handler = &task_out_intr;
  1360. args.posthandler = NULL;
  1361. err = ide_raw_taskfile(drive, &args, outbuf);
  1362. break;
  1363. case TASKFILE_MULTI_IN:
  1364. if (drive->mult_count) {
  1365. args.prehandler = NULL;
  1366. args.handler = &task_mulin_intr;
  1367. args.posthandler = NULL;
  1368. err = ide_raw_taskfile(drive, &args, inbuf);
  1369. } else {
  1370. /* (hs): give up if multcount is not set */
  1371. printk("%s: %s Multimode Read failure " 
  1372. "multcount is not setn",
  1373. drive->name, __FUNCTION__);
  1374. err = -EPERM;
  1375. goto abort;
  1376. }
  1377. break;
  1378. case TASKFILE_IN:
  1379. args.prehandler = NULL;
  1380. args.handler = &task_in_intr;
  1381. args.posthandler = NULL;
  1382. err = ide_raw_taskfile(drive, &args, inbuf);
  1383. break;
  1384. case TASKFILE_NO_DATA:
  1385. args.prehandler = NULL;
  1386. args.handler = &task_no_data_intr;
  1387. args.posthandler = NULL;
  1388. err = ide_raw_taskfile(drive, &args, NULL);
  1389. break;
  1390. default:
  1391. args.prehandler = NULL;
  1392. args.handler = NULL;
  1393. args.posthandler = NULL;
  1394. err = -EFAULT;
  1395. goto abort;
  1396. }
  1397. memcpy(req_task->io_ports, &(args.tfRegister), HDIO_DRIVE_TASK_HDR_SIZE);
  1398. memcpy(req_task->hob_ports, &(args.hobRegister), HDIO_DRIVE_HOB_HDR_SIZE);
  1399. req_task->in_flags  = args.tf_in_flags;
  1400. req_task->out_flags = args.tf_out_flags;
  1401. if (copy_to_user((void *)arg, req_task, tasksize)) {
  1402. err = -EFAULT;
  1403. goto abort;
  1404. }
  1405. if (taskout) {
  1406. int outtotal = tasksize;
  1407. if (copy_to_user((void *)arg+outtotal, outbuf, taskout)) {
  1408. err = -EFAULT;
  1409. goto abort;
  1410. }
  1411. }
  1412. if (taskin) {
  1413. int intotal = tasksize + taskout;
  1414. if (copy_to_user((void *)arg+intotal, inbuf, taskin)) {
  1415. err = -EFAULT;
  1416. goto abort;
  1417. }
  1418. }
  1419. abort:
  1420. kfree(req_task);
  1421. if (outbuf != NULL)
  1422. kfree(outbuf);
  1423. if (inbuf != NULL)
  1424. kfree(inbuf);
  1425. return err;
  1426. }
  1427. EXPORT_SYMBOL(task_read_24);
  1428. EXPORT_SYMBOL(do_rw_taskfile);
  1429. EXPORT_SYMBOL(do_taskfile);
  1430. // EXPORT_SYMBOL(flagged_taskfile);
  1431. //EXPORT_SYMBOL(ide_end_taskfile);
  1432. EXPORT_SYMBOL(set_multmode_intr);
  1433. EXPORT_SYMBOL(set_geometry_intr);
  1434. EXPORT_SYMBOL(recal_intr);
  1435. EXPORT_SYMBOL(task_no_data_intr);
  1436. EXPORT_SYMBOL(task_in_intr);
  1437. EXPORT_SYMBOL(task_mulin_intr);
  1438. EXPORT_SYMBOL(pre_task_out_intr);
  1439. EXPORT_SYMBOL(task_out_intr);
  1440. EXPORT_SYMBOL(task_mulout_intr);
  1441. EXPORT_SYMBOL(ide_init_drive_taskfile);
  1442. EXPORT_SYMBOL(ide_wait_taskfile);
  1443. EXPORT_SYMBOL(ide_raw_taskfile);
  1444. EXPORT_SYMBOL(ide_pre_handler_parser);
  1445. EXPORT_SYMBOL(ide_handler_parser);
  1446. EXPORT_SYMBOL(ide_cmd_type_parser);
  1447. EXPORT_SYMBOL(ide_taskfile_ioctl);
  1448. #ifdef CONFIG_PKT_TASK_IOCTL
  1449. #if 0
  1450. {
  1451. { /* start cdrom */
  1452. struct cdrom_info *info = drive->driver_data;
  1453. if (info->dma) {
  1454. if (info->cmd == READ) {
  1455. info->dma = !HWIF(drive)->dmaproc(ide_dma_read, drive);
  1456. } else if (info->cmd == WRITE) {
  1457. info->dma = !HWIF(drive)->dmaproc(ide_dma_write, drive);
  1458. } else {
  1459. printk("ide-cd: DMA set, but not allowedn");
  1460. }
  1461. }
  1462. /* Set up the controller registers. */
  1463. OUT_BYTE (info->dma, IDE_FEATURE_REG);
  1464. OUT_BYTE (0, IDE_NSECTOR_REG);
  1465. OUT_BYTE (0, IDE_SECTOR_REG);
  1466. OUT_BYTE (xferlen & 0xff, IDE_LCYL_REG);
  1467. OUT_BYTE (xferlen >> 8  , IDE_HCYL_REG);
  1468. if (IDE_CONTROL_REG)
  1469. OUT_BYTE (drive->ctl, IDE_CONTROL_REG);
  1470. if (info->dma)
  1471. (void) (HWIF(drive)->dmaproc(ide_dma_begin, drive));
  1472. if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt) {
  1473. ide_set_handler (drive, handler, WAIT_CMD, cdrom_timer_expiry);
  1474. OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG); /* packet command */
  1475. return ide_started;
  1476. } else {
  1477. OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG); /* packet command */
  1478. return (*handler) (drive);
  1479. }
  1480. } /* end cdrom */
  1481. { /* start floppy */
  1482. idefloppy_floppy_t *floppy = drive->driver_data;
  1483. idefloppy_bcount_reg_t bcount;
  1484. int dma_ok = 0;
  1485. floppy->pc=pc; /* Set the current packet command */
  1486. pc->retries++;
  1487. pc->actually_transferred=0; /* We haven't transferred any data yet */
  1488. pc->current_position=pc->buffer;
  1489. bcount.all = IDE_MIN(pc->request_transfer, 63 * 1024);
  1490. #ifdef CONFIG_BLK_DEV_IDEDMA
  1491. if (test_and_clear_bit (PC_DMA_ERROR, &pc->flags)) {
  1492. (void) HWIF(drive)->dmaproc(ide_dma_off, drive);
  1493. }
  1494. if (test_bit (PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma)
  1495. dma_ok=!HWIF(drive)->dmaproc(test_bit (PC_WRITING, &pc->flags) ? ide_dma_write : ide_dma_read, drive);
  1496. #endif /* CONFIG_BLK_DEV_IDEDMA */
  1497. if (IDE_CONTROL_REG)
  1498. OUT_BYTE (drive->ctl,IDE_CONTROL_REG);
  1499. OUT_BYTE (dma_ok ? 1:0,IDE_FEATURE_REG); /* Use PIO/DMA */
  1500. OUT_BYTE (bcount.b.high,IDE_BCOUNTH_REG);
  1501. OUT_BYTE (bcount.b.low,IDE_BCOUNTL_REG);
  1502. OUT_BYTE (drive->select.all,IDE_SELECT_REG);
  1503. #ifdef CONFIG_BLK_DEV_IDEDMA
  1504. if (dma_ok) { /* Begin DMA, if necessary */
  1505. set_bit (PC_DMA_IN_PROGRESS, &pc->flags);
  1506. (void) (HWIF(drive)->dmaproc(ide_dma_begin, drive));
  1507. }
  1508. #endif /* CONFIG_BLK_DEV_IDEDMA */
  1509. } /* end floppy */
  1510. { /* start tape */
  1511. idetape_tape_t *tape = drive->driver_data;
  1512. #ifdef CONFIG_BLK_DEV_IDEDMA
  1513. if (test_and_clear_bit (PC_DMA_ERROR, &pc->flags)) {
  1514. printk (KERN_WARNING "ide-tape: DMA disabled, reverting to PIOn");
  1515. (void) HWIF(drive)->dmaproc(ide_dma_off, drive);
  1516. }
  1517. if (test_bit (PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma)
  1518. dma_ok=!HWIF(drive)->dmaproc(test_bit (PC_WRITING, &pc->flags) ? ide_dma_write : ide_dma_read, drive);
  1519. #endif /* CONFIG_BLK_DEV_IDEDMA */
  1520. if (IDE_CONTROL_REG)
  1521. OUT_BYTE (drive->ctl,IDE_CONTROL_REG);
  1522. OUT_BYTE (dma_ok ? 1:0,IDE_FEATURE_REG); /* Use PIO/DMA */
  1523. OUT_BYTE (bcount.b.high,IDE_BCOUNTH_REG);
  1524. OUT_BYTE (bcount.b.low,IDE_BCOUNTL_REG);
  1525. OUT_BYTE (drive->select.all,IDE_SELECT_REG);
  1526. #ifdef CONFIG_BLK_DEV_IDEDMA
  1527. if (dma_ok) { /* Begin DMA, if necessary */
  1528. set_bit (PC_DMA_IN_PROGRESS, &pc->flags);
  1529. (void) (HWIF(drive)->dmaproc(ide_dma_begin, drive));
  1530. }
  1531. #endif /* CONFIG_BLK_DEV_IDEDMA */
  1532. if (test_bit(IDETAPE_DRQ_INTERRUPT, &tape->flags)) {
  1533. ide_set_handler(drive, &idetape_transfer_pc, IDETAPE_WAIT_CMD, NULL);
  1534. OUT_BYTE(WIN_PACKETCMD, IDE_COMMAND_REG);
  1535. return ide_started;
  1536. } else {
  1537. OUT_BYTE(WIN_PACKETCMD, IDE_COMMAND_REG);
  1538. return idetape_transfer_pc(drive);
  1539. }
  1540. } /* end tape */
  1541. }
  1542. #endif
  1543. int pkt_taskfile_ioctl (ide_drive_t *drive, struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
  1544. {
  1545. #if 0
  1546. switch(req_task->data_phase) {
  1547. case TASKFILE_P_OUT_DMAQ:
  1548. case TASKFILE_P_IN_DMAQ:
  1549. case TASKFILE_P_OUT_DMA:
  1550. case TASKFILE_P_IN_DMA:
  1551. case TASKFILE_P_OUT:
  1552. case TASKFILE_P_IN:
  1553. }
  1554. #endif
  1555. return -ENOMSG;
  1556. }
  1557. EXPORT_SYMBOL(pkt_taskfile_ioctl);
  1558. #endif /* CONFIG_PKT_TASK_IOCTL */