ide-io.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772
  1. /*
  2. * IDE I/O functions
  3. *
  4. * Basic PIO and command management functionality.
  5. *
  6. * This code was split off from ide.c. See ide.c for history and original
  7. * copyrights.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2, or (at your option) any
  12. * later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * For the avoidance of doubt the "preferred form" of this code is one which
  20. * is in an open non patent encumbered format. Where cryptographic key signing
  21. * forms part of the process of creating an executable the information
  22. * including keys needed to generate an equivalently functional executable
  23. * are deemed to be part of the source code.
  24. */
  25. #include <linux/module.h>
  26. #include <linux/types.h>
  27. #include <linux/string.h>
  28. #include <linux/kernel.h>
  29. #include <linux/timer.h>
  30. #include <linux/mm.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/major.h>
  33. #include <linux/errno.h>
  34. #include <linux/genhd.h>
  35. #include <linux/blkpg.h>
  36. #include <linux/slab.h>
  37. #include <linux/init.h>
  38. #include <linux/pci.h>
  39. #include <linux/delay.h>
  40. #include <linux/ide.h>
  41. #include <linux/completion.h>
  42. #include <linux/reboot.h>
  43. #include <linux/cdrom.h>
  44. #include <linux/seq_file.h>
  45. #include <linux/device.h>
  46. #include <linux/kmod.h>
  47. #include <linux/scatterlist.h>
  48. #include <linux/bitops.h>
  49. #include <asm/byteorder.h>
  50. #include <asm/irq.h>
  51. #include <asm/uaccess.h>
  52. #include <asm/io.h>
  53. static int __ide_end_request(ide_drive_t *drive, struct request *rq,
  54. int uptodate, unsigned int nr_bytes, int dequeue)
  55. {
  56. int ret = 1;
  57. /*
  58. * if failfast is set on a request, override number of sectors and
  59. * complete the whole request right now
  60. */
  61. if (blk_noretry_request(rq) && end_io_error(uptodate))
  62. nr_bytes = rq->hard_nr_sectors << 9;
  63. if (!blk_fs_request(rq) && end_io_error(uptodate) && !rq->errors)
  64. rq->errors = -EIO;
  65. /*
  66. * decide whether to reenable DMA -- 3 is a random magic for now,
  67. * if we DMA timeout more than 3 times, just stay in PIO
  68. */
  69. if (drive->state == DMA_PIO_RETRY && drive->retry_pio <= 3) {
  70. drive->state = 0;
  71. ide_dma_on(drive);
  72. }
  73. if (!end_that_request_chunk(rq, uptodate, nr_bytes)) {
  74. add_disk_randomness(rq->rq_disk);
  75. if (dequeue) {
  76. if (!list_empty(&rq->queuelist))
  77. blkdev_dequeue_request(rq);
  78. HWGROUP(drive)->rq = NULL;
  79. }
  80. end_that_request_last(rq, uptodate);
  81. ret = 0;
  82. }
  83. return ret;
  84. }
  85. /**
  86. * ide_end_request - complete an IDE I/O
  87. * @drive: IDE device for the I/O
  88. * @uptodate:
  89. * @nr_sectors: number of sectors completed
  90. *
  91. * This is our end_request wrapper function. We complete the I/O
  92. * update random number input and dequeue the request, which if
  93. * it was tagged may be out of order.
  94. */
  95. int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
  96. {
  97. unsigned int nr_bytes = nr_sectors << 9;
  98. struct request *rq;
  99. unsigned long flags;
  100. int ret = 1;
  101. /*
  102. * room for locking improvements here, the calls below don't
  103. * need the queue lock held at all
  104. */
  105. spin_lock_irqsave(&ide_lock, flags);
  106. rq = HWGROUP(drive)->rq;
  107. if (!nr_bytes) {
  108. if (blk_pc_request(rq))
  109. nr_bytes = rq->data_len;
  110. else
  111. nr_bytes = rq->hard_cur_sectors << 9;
  112. }
  113. ret = __ide_end_request(drive, rq, uptodate, nr_bytes, 1);
  114. spin_unlock_irqrestore(&ide_lock, flags);
  115. return ret;
  116. }
  117. EXPORT_SYMBOL(ide_end_request);
  118. /*
  119. * Power Management state machine. This one is rather trivial for now,
  120. * we should probably add more, like switching back to PIO on suspend
  121. * to help some BIOSes, re-do the door locking on resume, etc...
  122. */
  123. enum {
  124. ide_pm_flush_cache = ide_pm_state_start_suspend,
  125. idedisk_pm_standby,
  126. idedisk_pm_restore_pio = ide_pm_state_start_resume,
  127. idedisk_pm_idle,
  128. ide_pm_restore_dma,
  129. };
  130. static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 stat, u8 error)
  131. {
  132. struct request_pm_state *pm = rq->data;
  133. if (drive->media != ide_disk)
  134. return;
  135. switch (pm->pm_step) {
  136. case ide_pm_flush_cache: /* Suspend step 1 (flush cache) complete */
  137. if (pm->pm_state == PM_EVENT_FREEZE)
  138. pm->pm_step = ide_pm_state_completed;
  139. else
  140. pm->pm_step = idedisk_pm_standby;
  141. break;
  142. case idedisk_pm_standby: /* Suspend step 2 (standby) complete */
  143. pm->pm_step = ide_pm_state_completed;
  144. break;
  145. case idedisk_pm_restore_pio: /* Resume step 1 complete */
  146. pm->pm_step = idedisk_pm_idle;
  147. break;
  148. case idedisk_pm_idle: /* Resume step 2 (idle) complete */
  149. pm->pm_step = ide_pm_restore_dma;
  150. break;
  151. }
  152. }
  153. static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
  154. {
  155. struct request_pm_state *pm = rq->data;
  156. ide_task_t *args = rq->special;
  157. memset(args, 0, sizeof(*args));
  158. switch (pm->pm_step) {
  159. case ide_pm_flush_cache: /* Suspend step 1 (flush cache) */
  160. if (drive->media != ide_disk)
  161. break;
  162. /* Not supported? Switch to next step now. */
  163. if (!drive->wcache || !ide_id_has_flush_cache(drive->id)) {
  164. ide_complete_power_step(drive, rq, 0, 0);
  165. return ide_stopped;
  166. }
  167. if (ide_id_has_flush_cache_ext(drive->id))
  168. args->tf.command = WIN_FLUSH_CACHE_EXT;
  169. else
  170. args->tf.command = WIN_FLUSH_CACHE;
  171. goto out_do_tf;
  172. case idedisk_pm_standby: /* Suspend step 2 (standby) */
  173. args->tf.command = WIN_STANDBYNOW1;
  174. goto out_do_tf;
  175. case idedisk_pm_restore_pio: /* Resume step 1 (restore PIO) */
  176. ide_set_max_pio(drive);
  177. /*
  178. * skip idedisk_pm_idle for ATAPI devices
  179. */
  180. if (drive->media != ide_disk)
  181. pm->pm_step = ide_pm_restore_dma;
  182. else
  183. ide_complete_power_step(drive, rq, 0, 0);
  184. return ide_stopped;
  185. case idedisk_pm_idle: /* Resume step 2 (idle) */
  186. args->tf.command = WIN_IDLEIMMEDIATE;
  187. goto out_do_tf;
  188. case ide_pm_restore_dma: /* Resume step 3 (restore DMA) */
  189. /*
  190. * Right now, all we do is call ide_set_dma(drive),
  191. * we could be smarter and check for current xfer_speed
  192. * in struct drive etc...
  193. */
  194. if (drive->hwif->dma_host_set == NULL)
  195. break;
  196. /*
  197. * TODO: respect ->using_dma setting
  198. */
  199. ide_set_dma(drive);
  200. break;
  201. }
  202. pm->pm_step = ide_pm_state_completed;
  203. return ide_stopped;
  204. out_do_tf:
  205. args->tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE;
  206. args->data_phase = TASKFILE_NO_DATA;
  207. return do_rw_taskfile(drive, args);
  208. }
  209. /**
  210. * ide_end_dequeued_request - complete an IDE I/O
  211. * @drive: IDE device for the I/O
  212. * @uptodate:
  213. * @nr_sectors: number of sectors completed
  214. *
  215. * Complete an I/O that is no longer on the request queue. This
  216. * typically occurs when we pull the request and issue a REQUEST_SENSE.
  217. * We must still finish the old request but we must not tamper with the
  218. * queue in the meantime.
  219. *
  220. * NOTE: This path does not handle barrier, but barrier is not supported
  221. * on ide-cd anyway.
  222. */
  223. int ide_end_dequeued_request(ide_drive_t *drive, struct request *rq,
  224. int uptodate, int nr_sectors)
  225. {
  226. unsigned long flags;
  227. int ret;
  228. spin_lock_irqsave(&ide_lock, flags);
  229. BUG_ON(!blk_rq_started(rq));
  230. ret = __ide_end_request(drive, rq, uptodate, nr_sectors << 9, 0);
  231. spin_unlock_irqrestore(&ide_lock, flags);
  232. return ret;
  233. }
  234. EXPORT_SYMBOL_GPL(ide_end_dequeued_request);
  235. /**
  236. * ide_complete_pm_request - end the current Power Management request
  237. * @drive: target drive
  238. * @rq: request
  239. *
  240. * This function cleans up the current PM request and stops the queue
  241. * if necessary.
  242. */
  243. static void ide_complete_pm_request (ide_drive_t *drive, struct request *rq)
  244. {
  245. unsigned long flags;
  246. #ifdef DEBUG_PM
  247. printk("%s: completing PM request, %s\n", drive->name,
  248. blk_pm_suspend_request(rq) ? "suspend" : "resume");
  249. #endif
  250. spin_lock_irqsave(&ide_lock, flags);
  251. if (blk_pm_suspend_request(rq)) {
  252. blk_stop_queue(drive->queue);
  253. } else {
  254. drive->blocked = 0;
  255. blk_start_queue(drive->queue);
  256. }
  257. blkdev_dequeue_request(rq);
  258. HWGROUP(drive)->rq = NULL;
  259. end_that_request_last(rq, 1);
  260. spin_unlock_irqrestore(&ide_lock, flags);
  261. }
  262. void ide_tf_read(ide_drive_t *drive, ide_task_t *task)
  263. {
  264. ide_hwif_t *hwif = drive->hwif;
  265. struct ide_taskfile *tf = &task->tf;
  266. if (task->tf_flags & IDE_TFLAG_IN_DATA) {
  267. u16 data = hwif->INW(IDE_DATA_REG);
  268. tf->data = data & 0xff;
  269. tf->hob_data = (data >> 8) & 0xff;
  270. }
  271. /* be sure we're looking at the low order bits */
  272. hwif->OUTB(drive->ctl & ~0x80, IDE_CONTROL_REG);
  273. if (task->tf_flags & IDE_TFLAG_IN_NSECT)
  274. tf->nsect = hwif->INB(IDE_NSECTOR_REG);
  275. if (task->tf_flags & IDE_TFLAG_IN_LBAL)
  276. tf->lbal = hwif->INB(IDE_SECTOR_REG);
  277. if (task->tf_flags & IDE_TFLAG_IN_LBAM)
  278. tf->lbam = hwif->INB(IDE_LCYL_REG);
  279. if (task->tf_flags & IDE_TFLAG_IN_LBAH)
  280. tf->lbah = hwif->INB(IDE_HCYL_REG);
  281. if (task->tf_flags & IDE_TFLAG_IN_DEVICE)
  282. tf->device = hwif->INB(IDE_SELECT_REG);
  283. if (task->tf_flags & IDE_TFLAG_LBA48) {
  284. hwif->OUTB(drive->ctl | 0x80, IDE_CONTROL_REG);
  285. if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
  286. tf->hob_feature = hwif->INB(IDE_FEATURE_REG);
  287. if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
  288. tf->hob_nsect = hwif->INB(IDE_NSECTOR_REG);
  289. if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
  290. tf->hob_lbal = hwif->INB(IDE_SECTOR_REG);
  291. if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
  292. tf->hob_lbam = hwif->INB(IDE_LCYL_REG);
  293. if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
  294. tf->hob_lbah = hwif->INB(IDE_HCYL_REG);
  295. }
  296. }
  297. /**
  298. * ide_end_drive_cmd - end an explicit drive command
  299. * @drive: command
  300. * @stat: status bits
  301. * @err: error bits
  302. *
  303. * Clean up after success/failure of an explicit drive command.
  304. * These get thrown onto the queue so they are synchronized with
  305. * real I/O operations on the drive.
  306. *
  307. * In LBA48 mode we have to read the register set twice to get
  308. * all the extra information out.
  309. */
  310. void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
  311. {
  312. ide_hwif_t *hwif = HWIF(drive);
  313. unsigned long flags;
  314. struct request *rq;
  315. spin_lock_irqsave(&ide_lock, flags);
  316. rq = HWGROUP(drive)->rq;
  317. spin_unlock_irqrestore(&ide_lock, flags);
  318. if (rq->cmd_type == REQ_TYPE_ATA_CMD) {
  319. u8 *args = (u8 *) rq->buffer;
  320. if (rq->errors == 0)
  321. rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT);
  322. if (args) {
  323. args[0] = stat;
  324. args[1] = err;
  325. args[2] = hwif->INB(IDE_NSECTOR_REG);
  326. }
  327. } else if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
  328. ide_task_t *args = (ide_task_t *) rq->special;
  329. if (rq->errors == 0)
  330. rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT);
  331. if (args) {
  332. struct ide_taskfile *tf = &args->tf;
  333. tf->error = err;
  334. tf->status = stat;
  335. args->tf_flags |= (IDE_TFLAG_IN_TF|IDE_TFLAG_IN_DEVICE);
  336. if (args->tf_flags & IDE_TFLAG_LBA48)
  337. args->tf_flags |= IDE_TFLAG_IN_HOB;
  338. ide_tf_read(drive, args);
  339. }
  340. } else if (blk_pm_request(rq)) {
  341. struct request_pm_state *pm = rq->data;
  342. #ifdef DEBUG_PM
  343. printk("%s: complete_power_step(step: %d, stat: %x, err: %x)\n",
  344. drive->name, rq->pm->pm_step, stat, err);
  345. #endif
  346. ide_complete_power_step(drive, rq, stat, err);
  347. if (pm->pm_step == ide_pm_state_completed)
  348. ide_complete_pm_request(drive, rq);
  349. return;
  350. }
  351. spin_lock_irqsave(&ide_lock, flags);
  352. blkdev_dequeue_request(rq);
  353. HWGROUP(drive)->rq = NULL;
  354. rq->errors = err;
  355. end_that_request_last(rq, !rq->errors);
  356. spin_unlock_irqrestore(&ide_lock, flags);
  357. }
  358. EXPORT_SYMBOL(ide_end_drive_cmd);
  359. /**
  360. * try_to_flush_leftover_data - flush junk
  361. * @drive: drive to flush
  362. *
  363. * try_to_flush_leftover_data() is invoked in response to a drive
  364. * unexpectedly having its DRQ_STAT bit set. As an alternative to
  365. * resetting the drive, this routine tries to clear the condition
  366. * by read a sector's worth of data from the drive. Of course,
  367. * this may not help if the drive is *waiting* for data from *us*.
  368. */
  369. static void try_to_flush_leftover_data (ide_drive_t *drive)
  370. {
  371. int i = (drive->mult_count ? drive->mult_count : 1) * SECTOR_WORDS;
  372. if (drive->media != ide_disk)
  373. return;
  374. while (i > 0) {
  375. u32 buffer[16];
  376. u32 wcount = (i > 16) ? 16 : i;
  377. i -= wcount;
  378. HWIF(drive)->ata_input_data(drive, buffer, wcount);
  379. }
  380. }
  381. static void ide_kill_rq(ide_drive_t *drive, struct request *rq)
  382. {
  383. if (rq->rq_disk) {
  384. ide_driver_t *drv;
  385. drv = *(ide_driver_t **)rq->rq_disk->private_data;
  386. drv->end_request(drive, 0, 0);
  387. } else
  388. ide_end_request(drive, 0, 0);
  389. }
  390. static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
  391. {
  392. ide_hwif_t *hwif = drive->hwif;
  393. if (stat & BUSY_STAT || ((stat & WRERR_STAT) && !drive->nowerr)) {
  394. /* other bits are useless when BUSY */
  395. rq->errors |= ERROR_RESET;
  396. } else if (stat & ERR_STAT) {
  397. /* err has different meaning on cdrom and tape */
  398. if (err == ABRT_ERR) {
  399. if (drive->select.b.lba &&
  400. /* some newer drives don't support WIN_SPECIFY */
  401. hwif->INB(IDE_COMMAND_REG) == WIN_SPECIFY)
  402. return ide_stopped;
  403. } else if ((err & BAD_CRC) == BAD_CRC) {
  404. /* UDMA crc error, just retry the operation */
  405. drive->crc_count++;
  406. } else if (err & (BBD_ERR | ECC_ERR)) {
  407. /* retries won't help these */
  408. rq->errors = ERROR_MAX;
  409. } else if (err & TRK0_ERR) {
  410. /* help it find track zero */
  411. rq->errors |= ERROR_RECAL;
  412. }
  413. }
  414. if ((stat & DRQ_STAT) && rq_data_dir(rq) == READ &&
  415. (hwif->host_flags & IDE_HFLAG_ERROR_STOPS_FIFO) == 0)
  416. try_to_flush_leftover_data(drive);
  417. if (rq->errors >= ERROR_MAX || blk_noretry_request(rq)) {
  418. ide_kill_rq(drive, rq);
  419. return ide_stopped;
  420. }
  421. if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
  422. rq->errors |= ERROR_RESET;
  423. if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
  424. ++rq->errors;
  425. return ide_do_reset(drive);
  426. }
  427. if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
  428. drive->special.b.recalibrate = 1;
  429. ++rq->errors;
  430. return ide_stopped;
  431. }
  432. static ide_startstop_t ide_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
  433. {
  434. ide_hwif_t *hwif = drive->hwif;
  435. if (stat & BUSY_STAT || ((stat & WRERR_STAT) && !drive->nowerr)) {
  436. /* other bits are useless when BUSY */
  437. rq->errors |= ERROR_RESET;
  438. } else {
  439. /* add decoding error stuff */
  440. }
  441. if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
  442. /* force an abort */
  443. hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG);
  444. if (rq->errors >= ERROR_MAX) {
  445. ide_kill_rq(drive, rq);
  446. } else {
  447. if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
  448. ++rq->errors;
  449. return ide_do_reset(drive);
  450. }
  451. ++rq->errors;
  452. }
  453. return ide_stopped;
  454. }
  455. ide_startstop_t
  456. __ide_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
  457. {
  458. if (drive->media == ide_disk)
  459. return ide_ata_error(drive, rq, stat, err);
  460. return ide_atapi_error(drive, rq, stat, err);
  461. }
  462. EXPORT_SYMBOL_GPL(__ide_error);
  463. /**
  464. * ide_error - handle an error on the IDE
  465. * @drive: drive the error occurred on
  466. * @msg: message to report
  467. * @stat: status bits
  468. *
  469. * ide_error() takes action based on the error returned by the drive.
  470. * For normal I/O that may well include retries. We deal with
  471. * both new-style (taskfile) and old style command handling here.
  472. * In the case of taskfile command handling there is work left to
  473. * do
  474. */
  475. ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, u8 stat)
  476. {
  477. struct request *rq;
  478. u8 err;
  479. err = ide_dump_status(drive, msg, stat);
  480. if ((rq = HWGROUP(drive)->rq) == NULL)
  481. return ide_stopped;
  482. /* retry only "normal" I/O: */
  483. if (!blk_fs_request(rq)) {
  484. rq->errors = 1;
  485. ide_end_drive_cmd(drive, stat, err);
  486. return ide_stopped;
  487. }
  488. if (rq->rq_disk) {
  489. ide_driver_t *drv;
  490. drv = *(ide_driver_t **)rq->rq_disk->private_data;
  491. return drv->error(drive, rq, stat, err);
  492. } else
  493. return __ide_error(drive, rq, stat, err);
  494. }
  495. EXPORT_SYMBOL_GPL(ide_error);
  496. ide_startstop_t __ide_abort(ide_drive_t *drive, struct request *rq)
  497. {
  498. if (drive->media != ide_disk)
  499. rq->errors |= ERROR_RESET;
  500. ide_kill_rq(drive, rq);
  501. return ide_stopped;
  502. }
  503. EXPORT_SYMBOL_GPL(__ide_abort);
  504. /**
  505. * ide_abort - abort pending IDE operations
  506. * @drive: drive the error occurred on
  507. * @msg: message to report
  508. *
  509. * ide_abort kills and cleans up when we are about to do a
  510. * host initiated reset on active commands. Longer term we
  511. * want handlers to have sensible abort handling themselves
  512. *
  513. * This differs fundamentally from ide_error because in
  514. * this case the command is doing just fine when we
  515. * blow it away.
  516. */
  517. ide_startstop_t ide_abort(ide_drive_t *drive, const char *msg)
  518. {
  519. struct request *rq;
  520. if (drive == NULL || (rq = HWGROUP(drive)->rq) == NULL)
  521. return ide_stopped;
  522. /* retry only "normal" I/O: */
  523. if (!blk_fs_request(rq)) {
  524. rq->errors = 1;
  525. ide_end_drive_cmd(drive, BUSY_STAT, 0);
  526. return ide_stopped;
  527. }
  528. if (rq->rq_disk) {
  529. ide_driver_t *drv;
  530. drv = *(ide_driver_t **)rq->rq_disk->private_data;
  531. return drv->abort(drive, rq);
  532. } else
  533. return __ide_abort(drive, rq);
  534. }
  535. /**
  536. * drive_cmd_intr - drive command completion interrupt
  537. * @drive: drive the completion interrupt occurred on
  538. *
  539. * drive_cmd_intr() is invoked on completion of a special DRIVE_CMD.
  540. * We do any necessary data reading and then wait for the drive to
  541. * go non busy. At that point we may read the error data and complete
  542. * the request
  543. */
  544. static ide_startstop_t drive_cmd_intr (ide_drive_t *drive)
  545. {
  546. struct request *rq = HWGROUP(drive)->rq;
  547. ide_hwif_t *hwif = HWIF(drive);
  548. u8 *args = (u8 *) rq->buffer;
  549. u8 stat = hwif->INB(IDE_STATUS_REG);
  550. int retries = 10;
  551. local_irq_enable_in_hardirq();
  552. if (rq->cmd_type == REQ_TYPE_ATA_CMD &&
  553. (stat & DRQ_STAT) && args && args[3]) {
  554. u8 io_32bit = drive->io_32bit;
  555. drive->io_32bit = 0;
  556. hwif->ata_input_data(drive, &args[4], args[3] * SECTOR_WORDS);
  557. drive->io_32bit = io_32bit;
  558. while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
  559. udelay(100);
  560. }
  561. if (!OK_STAT(stat, READY_STAT, BAD_STAT))
  562. return ide_error(drive, "drive_cmd", stat);
  563. /* calls ide_end_drive_cmd */
  564. ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
  565. return ide_stopped;
  566. }
  567. static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
  568. {
  569. tf->nsect = drive->sect;
  570. tf->lbal = drive->sect;
  571. tf->lbam = drive->cyl;
  572. tf->lbah = drive->cyl >> 8;
  573. tf->device = ((drive->head - 1) | drive->select.all) & ~ATA_LBA;
  574. tf->command = WIN_SPECIFY;
  575. }
  576. static void ide_tf_set_restore_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
  577. {
  578. tf->nsect = drive->sect;
  579. tf->command = WIN_RESTORE;
  580. }
  581. static void ide_tf_set_setmult_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
  582. {
  583. tf->nsect = drive->mult_req;
  584. tf->command = WIN_SETMULT;
  585. }
  586. static ide_startstop_t ide_disk_special(ide_drive_t *drive)
  587. {
  588. special_t *s = &drive->special;
  589. ide_task_t args;
  590. memset(&args, 0, sizeof(ide_task_t));
  591. args.data_phase = TASKFILE_NO_DATA;
  592. if (s->b.set_geometry) {
  593. s->b.set_geometry = 0;
  594. ide_tf_set_specify_cmd(drive, &args.tf);
  595. } else if (s->b.recalibrate) {
  596. s->b.recalibrate = 0;
  597. ide_tf_set_restore_cmd(drive, &args.tf);
  598. } else if (s->b.set_multmode) {
  599. s->b.set_multmode = 0;
  600. if (drive->mult_req > drive->id->max_multsect)
  601. drive->mult_req = drive->id->max_multsect;
  602. ide_tf_set_setmult_cmd(drive, &args.tf);
  603. } else if (s->all) {
  604. int special = s->all;
  605. s->all = 0;
  606. printk(KERN_ERR "%s: bad special flag: 0x%02x\n", drive->name, special);
  607. return ide_stopped;
  608. }
  609. args.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE |
  610. IDE_TFLAG_CUSTOM_HANDLER;
  611. do_rw_taskfile(drive, &args);
  612. return ide_started;
  613. }
  614. /*
  615. * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
  616. */
  617. static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
  618. {
  619. switch (req_pio) {
  620. case 202:
  621. case 201:
  622. case 200:
  623. case 102:
  624. case 101:
  625. case 100:
  626. return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
  627. case 9:
  628. case 8:
  629. return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
  630. case 7:
  631. case 6:
  632. return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
  633. default:
  634. return 0;
  635. }
  636. }
  637. /**
  638. * do_special - issue some special commands
  639. * @drive: drive the command is for
  640. *
  641. * do_special() is used to issue WIN_SPECIFY, WIN_RESTORE, and WIN_SETMULT
  642. * commands to a drive. It used to do much more, but has been scaled
  643. * back.
  644. */
  645. static ide_startstop_t do_special (ide_drive_t *drive)
  646. {
  647. special_t *s = &drive->special;
  648. #ifdef DEBUG
  649. printk("%s: do_special: 0x%02x\n", drive->name, s->all);
  650. #endif
  651. if (s->b.set_tune) {
  652. ide_hwif_t *hwif = drive->hwif;
  653. u8 req_pio = drive->tune_req;
  654. s->b.set_tune = 0;
  655. if (set_pio_mode_abuse(drive->hwif, req_pio)) {
  656. if (hwif->set_pio_mode == NULL)
  657. return ide_stopped;
  658. /*
  659. * take ide_lock for drive->[no_]unmask/[no_]io_32bit
  660. */
  661. if (req_pio == 8 || req_pio == 9) {
  662. unsigned long flags;
  663. spin_lock_irqsave(&ide_lock, flags);
  664. hwif->set_pio_mode(drive, req_pio);
  665. spin_unlock_irqrestore(&ide_lock, flags);
  666. } else
  667. hwif->set_pio_mode(drive, req_pio);
  668. } else {
  669. int keep_dma = drive->using_dma;
  670. ide_set_pio(drive, req_pio);
  671. if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
  672. if (keep_dma)
  673. ide_dma_on(drive);
  674. }
  675. }
  676. return ide_stopped;
  677. } else {
  678. if (drive->media == ide_disk)
  679. return ide_disk_special(drive);
  680. s->all = 0;
  681. drive->mult_req = 0;
  682. return ide_stopped;
  683. }
  684. }
  685. void ide_map_sg(ide_drive_t *drive, struct request *rq)
  686. {
  687. ide_hwif_t *hwif = drive->hwif;
  688. struct scatterlist *sg = hwif->sg_table;
  689. if (hwif->sg_mapped) /* needed by ide-scsi */
  690. return;
  691. if (rq->cmd_type != REQ_TYPE_ATA_TASKFILE) {
  692. hwif->sg_nents = blk_rq_map_sg(drive->queue, rq, sg);
  693. } else {
  694. sg_init_one(sg, rq->buffer, rq->nr_sectors * SECTOR_SIZE);
  695. hwif->sg_nents = 1;
  696. }
  697. }
  698. EXPORT_SYMBOL_GPL(ide_map_sg);
  699. void ide_init_sg_cmd(ide_drive_t *drive, struct request *rq)
  700. {
  701. ide_hwif_t *hwif = drive->hwif;
  702. hwif->nsect = hwif->nleft = rq->nr_sectors;
  703. hwif->cursg_ofs = 0;
  704. hwif->cursg = NULL;
  705. }
  706. EXPORT_SYMBOL_GPL(ide_init_sg_cmd);
  707. /**
  708. * execute_drive_command - issue special drive command
  709. * @drive: the drive to issue the command on
  710. * @rq: the request structure holding the command
  711. *
  712. * execute_drive_cmd() issues a special drive command, usually
  713. * initiated by ioctl() from the external hdparm program. The
  714. * command can be a drive command, drive task or taskfile
  715. * operation. Weirdly you can call it with NULL to wait for
  716. * all commands to finish. Don't do this as that is due to change
  717. */
  718. static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
  719. struct request *rq)
  720. {
  721. ide_hwif_t *hwif = HWIF(drive);
  722. u8 *args = rq->buffer;
  723. ide_task_t ltask;
  724. struct ide_taskfile *tf = &ltask.tf;
  725. if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
  726. ide_task_t *task = rq->special;
  727. if (task == NULL)
  728. goto done;
  729. hwif->data_phase = task->data_phase;
  730. switch (hwif->data_phase) {
  731. case TASKFILE_MULTI_OUT:
  732. case TASKFILE_OUT:
  733. case TASKFILE_MULTI_IN:
  734. case TASKFILE_IN:
  735. ide_init_sg_cmd(drive, rq);
  736. ide_map_sg(drive, rq);
  737. default:
  738. break;
  739. }
  740. return do_rw_taskfile(drive, task);
  741. }
  742. if (args == NULL)
  743. goto done;
  744. memset(&ltask, 0, sizeof(ltask));
  745. if (rq->cmd_type == REQ_TYPE_ATA_CMD) {
  746. #ifdef DEBUG
  747. printk("%s: DRIVE_CMD\n", drive->name);
  748. #endif
  749. tf->feature = args[2];
  750. if (args[0] == WIN_SMART) {
  751. tf->nsect = args[3];
  752. tf->lbal = args[1];
  753. tf->lbam = 0x4f;
  754. tf->lbah = 0xc2;
  755. ltask.tf_flags = IDE_TFLAG_OUT_TF;
  756. } else {
  757. tf->nsect = args[1];
  758. ltask.tf_flags = IDE_TFLAG_OUT_FEATURE |
  759. IDE_TFLAG_OUT_NSECT;
  760. }
  761. }
  762. tf->command = args[0];
  763. ide_tf_load(drive, &ltask);
  764. ide_execute_command(drive, args[0], &drive_cmd_intr, WAIT_WORSTCASE, NULL);
  765. return ide_started;
  766. done:
  767. /*
  768. * NULL is actually a valid way of waiting for
  769. * all current requests to be flushed from the queue.
  770. */
  771. #ifdef DEBUG
  772. printk("%s: DRIVE_CMD (null)\n", drive->name);
  773. #endif
  774. ide_end_drive_cmd(drive,
  775. hwif->INB(IDE_STATUS_REG),
  776. hwif->INB(IDE_ERROR_REG));
  777. return ide_stopped;
  778. }
  779. static void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
  780. {
  781. struct request_pm_state *pm = rq->data;
  782. if (blk_pm_suspend_request(rq) &&
  783. pm->pm_step == ide_pm_state_start_suspend)
  784. /* Mark drive blocked when starting the suspend sequence. */
  785. drive->blocked = 1;
  786. else if (blk_pm_resume_request(rq) &&
  787. pm->pm_step == ide_pm_state_start_resume) {
  788. /*
  789. * The first thing we do on wakeup is to wait for BSY bit to
  790. * go away (with a looong timeout) as a drive on this hwif may
  791. * just be POSTing itself.
  792. * We do that before even selecting as the "other" device on
  793. * the bus may be broken enough to walk on our toes at this
  794. * point.
  795. */
  796. int rc;
  797. #ifdef DEBUG_PM
  798. printk("%s: Wakeup request inited, waiting for !BSY...\n", drive->name);
  799. #endif
  800. rc = ide_wait_not_busy(HWIF(drive), 35000);
  801. if (rc)
  802. printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name);
  803. SELECT_DRIVE(drive);
  804. if (IDE_CONTROL_REG)
  805. HWIF(drive)->OUTB(drive->ctl, IDE_CONTROL_REG);
  806. rc = ide_wait_not_busy(HWIF(drive), 100000);
  807. if (rc)
  808. printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name);
  809. }
  810. }
  811. /**
  812. * start_request - start of I/O and command issuing for IDE
  813. *
  814. * start_request() initiates handling of a new I/O request. It
  815. * accepts commands and I/O (read/write) requests. It also does
  816. * the final remapping for weird stuff like EZDrive. Once
  817. * device mapper can work sector level the EZDrive stuff can go away
  818. *
  819. * FIXME: this function needs a rename
  820. */
  821. static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
  822. {
  823. ide_startstop_t startstop;
  824. sector_t block;
  825. BUG_ON(!blk_rq_started(rq));
  826. #ifdef DEBUG
  827. printk("%s: start_request: current=0x%08lx\n",
  828. HWIF(drive)->name, (unsigned long) rq);
  829. #endif
  830. /* bail early if we've exceeded max_failures */
  831. if (drive->max_failures && (drive->failures > drive->max_failures)) {
  832. rq->cmd_flags |= REQ_FAILED;
  833. goto kill_rq;
  834. }
  835. block = rq->sector;
  836. if (blk_fs_request(rq) &&
  837. (drive->media == ide_disk || drive->media == ide_floppy)) {
  838. block += drive->sect0;
  839. }
  840. /* Yecch - this will shift the entire interval,
  841. possibly killing some innocent following sector */
  842. if (block == 0 && drive->remap_0_to_1 == 1)
  843. block = 1; /* redirect MBR access to EZ-Drive partn table */
  844. if (blk_pm_request(rq))
  845. ide_check_pm_state(drive, rq);
  846. SELECT_DRIVE(drive);
  847. if (ide_wait_stat(&startstop, drive, drive->ready_stat, BUSY_STAT|DRQ_STAT, WAIT_READY)) {
  848. printk(KERN_ERR "%s: drive not ready for command\n", drive->name);
  849. return startstop;
  850. }
  851. if (!drive->special.all) {
  852. ide_driver_t *drv;
  853. /*
  854. * We reset the drive so we need to issue a SETFEATURES.
  855. * Do it _after_ do_special() restored device parameters.
  856. */
  857. if (drive->current_speed == 0xff)
  858. ide_config_drive_speed(drive, drive->desired_speed);
  859. if (rq->cmd_type == REQ_TYPE_ATA_CMD ||
  860. rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
  861. return execute_drive_cmd(drive, rq);
  862. else if (blk_pm_request(rq)) {
  863. struct request_pm_state *pm = rq->data;
  864. #ifdef DEBUG_PM
  865. printk("%s: start_power_step(step: %d)\n",
  866. drive->name, rq->pm->pm_step);
  867. #endif
  868. startstop = ide_start_power_step(drive, rq);
  869. if (startstop == ide_stopped &&
  870. pm->pm_step == ide_pm_state_completed)
  871. ide_complete_pm_request(drive, rq);
  872. return startstop;
  873. }
  874. drv = *(ide_driver_t **)rq->rq_disk->private_data;
  875. return drv->do_request(drive, rq, block);
  876. }
  877. return do_special(drive);
  878. kill_rq:
  879. ide_kill_rq(drive, rq);
  880. return ide_stopped;
  881. }
  882. /**
  883. * ide_stall_queue - pause an IDE device
  884. * @drive: drive to stall
  885. * @timeout: time to stall for (jiffies)
  886. *
  887. * ide_stall_queue() can be used by a drive to give excess bandwidth back
  888. * to the hwgroup by sleeping for timeout jiffies.
  889. */
  890. void ide_stall_queue (ide_drive_t *drive, unsigned long timeout)
  891. {
  892. if (timeout > WAIT_WORSTCASE)
  893. timeout = WAIT_WORSTCASE;
  894. drive->sleep = timeout + jiffies;
  895. drive->sleeping = 1;
  896. }
  897. EXPORT_SYMBOL(ide_stall_queue);
  898. #define WAKEUP(drive) ((drive)->service_start + 2 * (drive)->service_time)
  899. /**
  900. * choose_drive - select a drive to service
  901. * @hwgroup: hardware group to select on
  902. *
  903. * choose_drive() selects the next drive which will be serviced.
  904. * This is necessary because the IDE layer can't issue commands
  905. * to both drives on the same cable, unlike SCSI.
  906. */
  907. static inline ide_drive_t *choose_drive (ide_hwgroup_t *hwgroup)
  908. {
  909. ide_drive_t *drive, *best;
  910. repeat:
  911. best = NULL;
  912. drive = hwgroup->drive;
  913. /*
  914. * drive is doing pre-flush, ordered write, post-flush sequence. even
  915. * though that is 3 requests, it must be seen as a single transaction.
  916. * we must not preempt this drive until that is complete
  917. */
  918. if (blk_queue_flushing(drive->queue)) {
  919. /*
  920. * small race where queue could get replugged during
  921. * the 3-request flush cycle, just yank the plug since
  922. * we want it to finish asap
  923. */
  924. blk_remove_plug(drive->queue);
  925. return drive;
  926. }
  927. do {
  928. if ((!drive->sleeping || time_after_eq(jiffies, drive->sleep))
  929. && !elv_queue_empty(drive->queue)) {
  930. if (!best
  931. || (drive->sleeping && (!best->sleeping || time_before(drive->sleep, best->sleep)))
  932. || (!best->sleeping && time_before(WAKEUP(drive), WAKEUP(best))))
  933. {
  934. if (!blk_queue_plugged(drive->queue))
  935. best = drive;
  936. }
  937. }
  938. } while ((drive = drive->next) != hwgroup->drive);
  939. if (best && best->nice1 && !best->sleeping && best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) {
  940. long t = (signed long)(WAKEUP(best) - jiffies);
  941. if (t >= WAIT_MIN_SLEEP) {
  942. /*
  943. * We *may* have some time to spare, but first let's see if
  944. * someone can potentially benefit from our nice mood today..
  945. */
  946. drive = best->next;
  947. do {
  948. if (!drive->sleeping
  949. && time_before(jiffies - best->service_time, WAKEUP(drive))
  950. && time_before(WAKEUP(drive), jiffies + t))
  951. {
  952. ide_stall_queue(best, min_t(long, t, 10 * WAIT_MIN_SLEEP));
  953. goto repeat;
  954. }
  955. } while ((drive = drive->next) != best);
  956. }
  957. }
  958. return best;
  959. }
  960. /*
  961. * Issue a new request to a drive from hwgroup
  962. * Caller must have already done spin_lock_irqsave(&ide_lock, ..);
  963. *
  964. * A hwgroup is a serialized group of IDE interfaces. Usually there is
  965. * exactly one hwif (interface) per hwgroup, but buggy controllers (eg. CMD640)
  966. * may have both interfaces in a single hwgroup to "serialize" access.
  967. * Or possibly multiple ISA interfaces can share a common IRQ by being grouped
  968. * together into one hwgroup for serialized access.
  969. *
  970. * Note also that several hwgroups can end up sharing a single IRQ,
  971. * possibly along with many other devices. This is especially common in
  972. * PCI-based systems with off-board IDE controller cards.
  973. *
  974. * The IDE driver uses the single global ide_lock spinlock to protect
  975. * access to the request queues, and to protect the hwgroup->busy flag.
  976. *
  977. * The first thread into the driver for a particular hwgroup sets the
  978. * hwgroup->busy flag to indicate that this hwgroup is now active,
  979. * and then initiates processing of the top request from the request queue.
  980. *
  981. * Other threads attempting entry notice the busy setting, and will simply
  982. * queue their new requests and exit immediately. Note that hwgroup->busy
  983. * remains set even when the driver is merely awaiting the next interrupt.
  984. * Thus, the meaning is "this hwgroup is busy processing a request".
  985. *
  986. * When processing of a request completes, the completing thread or IRQ-handler
  987. * will start the next request from the queue. If no more work remains,
  988. * the driver will clear the hwgroup->busy flag and exit.
  989. *
  990. * The ide_lock (spinlock) is used to protect all access to the
  991. * hwgroup->busy flag, but is otherwise not needed for most processing in
  992. * the driver. This makes the driver much more friendlier to shared IRQs
  993. * than previous designs, while remaining 100% (?) SMP safe and capable.
  994. */
  995. static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
  996. {
  997. ide_drive_t *drive;
  998. ide_hwif_t *hwif;
  999. struct request *rq;
  1000. ide_startstop_t startstop;
  1001. int loops = 0;
  1002. /* for atari only: POSSIBLY BROKEN HERE(?) */
  1003. ide_get_lock(ide_intr, hwgroup);
  1004. /* caller must own ide_lock */
  1005. BUG_ON(!irqs_disabled());
  1006. while (!hwgroup->busy) {
  1007. hwgroup->busy = 1;
  1008. drive = choose_drive(hwgroup);
  1009. if (drive == NULL) {
  1010. int sleeping = 0;
  1011. unsigned long sleep = 0; /* shut up, gcc */
  1012. hwgroup->rq = NULL;
  1013. drive = hwgroup->drive;
  1014. do {
  1015. if (drive->sleeping && (!sleeping || time_before(drive->sleep, sleep))) {
  1016. sleeping = 1;
  1017. sleep = drive->sleep;
  1018. }
  1019. } while ((drive = drive->next) != hwgroup->drive);
  1020. if (sleeping) {
  1021. /*
  1022. * Take a short snooze, and then wake up this hwgroup again.
  1023. * This gives other hwgroups on the same a chance to
  1024. * play fairly with us, just in case there are big differences
  1025. * in relative throughputs.. don't want to hog the cpu too much.
  1026. */
  1027. if (time_before(sleep, jiffies + WAIT_MIN_SLEEP))
  1028. sleep = jiffies + WAIT_MIN_SLEEP;
  1029. #if 1
  1030. if (timer_pending(&hwgroup->timer))
  1031. printk(KERN_CRIT "ide_set_handler: timer already active\n");
  1032. #endif
  1033. /* so that ide_timer_expiry knows what to do */
  1034. hwgroup->sleeping = 1;
  1035. hwgroup->req_gen_timer = hwgroup->req_gen;
  1036. mod_timer(&hwgroup->timer, sleep);
  1037. /* we purposely leave hwgroup->busy==1
  1038. * while sleeping */
  1039. } else {
  1040. /* Ugly, but how can we sleep for the lock
  1041. * otherwise? perhaps from tq_disk?
  1042. */
  1043. /* for atari only */
  1044. ide_release_lock();
  1045. hwgroup->busy = 0;
  1046. }
  1047. /* no more work for this hwgroup (for now) */
  1048. return;
  1049. }
  1050. again:
  1051. hwif = HWIF(drive);
  1052. if (hwgroup->hwif->sharing_irq &&
  1053. hwif != hwgroup->hwif &&
  1054. hwif->io_ports[IDE_CONTROL_OFFSET]) {
  1055. /*
  1056. * set nIEN for previous hwif, drives in the
  1057. * quirk_list may not like intr setups/cleanups
  1058. */
  1059. if (drive->quirk_list != 1)
  1060. hwif->OUTB(drive->ctl | 2, IDE_CONTROL_REG);
  1061. }
  1062. hwgroup->hwif = hwif;
  1063. hwgroup->drive = drive;
  1064. drive->sleeping = 0;
  1065. drive->service_start = jiffies;
  1066. if (blk_queue_plugged(drive->queue)) {
  1067. printk(KERN_ERR "ide: huh? queue was plugged!\n");
  1068. break;
  1069. }
  1070. /*
  1071. * we know that the queue isn't empty, but this can happen
  1072. * if the q->prep_rq_fn() decides to kill a request
  1073. */
  1074. rq = elv_next_request(drive->queue);
  1075. if (!rq) {
  1076. hwgroup->busy = 0;
  1077. break;
  1078. }
  1079. /*
  1080. * Sanity: don't accept a request that isn't a PM request
  1081. * if we are currently power managed. This is very important as
  1082. * blk_stop_queue() doesn't prevent the elv_next_request()
  1083. * above to return us whatever is in the queue. Since we call
  1084. * ide_do_request() ourselves, we end up taking requests while
  1085. * the queue is blocked...
  1086. *
  1087. * We let requests forced at head of queue with ide-preempt
  1088. * though. I hope that doesn't happen too much, hopefully not
  1089. * unless the subdriver triggers such a thing in its own PM
  1090. * state machine.
  1091. *
  1092. * We count how many times we loop here to make sure we service
  1093. * all drives in the hwgroup without looping for ever
  1094. */
  1095. if (drive->blocked && !blk_pm_request(rq) && !(rq->cmd_flags & REQ_PREEMPT)) {
  1096. drive = drive->next ? drive->next : hwgroup->drive;
  1097. if (loops++ < 4 && !blk_queue_plugged(drive->queue))
  1098. goto again;
  1099. /* We clear busy, there should be no pending ATA command at this point. */
  1100. hwgroup->busy = 0;
  1101. break;
  1102. }
  1103. hwgroup->rq = rq;
  1104. /*
  1105. * Some systems have trouble with IDE IRQs arriving while
  1106. * the driver is still setting things up. So, here we disable
  1107. * the IRQ used by this interface while the request is being started.
  1108. * This may look bad at first, but pretty much the same thing
  1109. * happens anyway when any interrupt comes in, IDE or otherwise
  1110. * -- the kernel masks the IRQ while it is being handled.
  1111. */
  1112. if (masked_irq != IDE_NO_IRQ && hwif->irq != masked_irq)
  1113. disable_irq_nosync(hwif->irq);
  1114. spin_unlock(&ide_lock);
  1115. local_irq_enable_in_hardirq();
  1116. /* allow other IRQs while we start this request */
  1117. startstop = start_request(drive, rq);
  1118. spin_lock_irq(&ide_lock);
  1119. if (masked_irq != IDE_NO_IRQ && hwif->irq != masked_irq)
  1120. enable_irq(hwif->irq);
  1121. if (startstop == ide_stopped)
  1122. hwgroup->busy = 0;
  1123. }
  1124. }
  1125. /*
  1126. * Passes the stuff to ide_do_request
  1127. */
  1128. void do_ide_request(struct request_queue *q)
  1129. {
  1130. ide_drive_t *drive = q->queuedata;
  1131. ide_do_request(HWGROUP(drive), IDE_NO_IRQ);
  1132. }
  1133. /*
  1134. * un-busy the hwgroup etc, and clear any pending DMA status. we want to
  1135. * retry the current request in pio mode instead of risking tossing it
  1136. * all away
  1137. */
  1138. static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
  1139. {
  1140. ide_hwif_t *hwif = HWIF(drive);
  1141. struct request *rq;
  1142. ide_startstop_t ret = ide_stopped;
  1143. /*
  1144. * end current dma transaction
  1145. */
  1146. if (error < 0) {
  1147. printk(KERN_WARNING "%s: DMA timeout error\n", drive->name);
  1148. (void)HWIF(drive)->ide_dma_end(drive);
  1149. ret = ide_error(drive, "dma timeout error",
  1150. hwif->INB(IDE_STATUS_REG));
  1151. } else {
  1152. printk(KERN_WARNING "%s: DMA timeout retry\n", drive->name);
  1153. hwif->dma_timeout(drive);
  1154. }
  1155. /*
  1156. * disable dma for now, but remember that we did so because of
  1157. * a timeout -- we'll reenable after we finish this next request
  1158. * (or rather the first chunk of it) in pio.
  1159. */
  1160. drive->retry_pio++;
  1161. drive->state = DMA_PIO_RETRY;
  1162. ide_dma_off_quietly(drive);
  1163. /*
  1164. * un-busy drive etc (hwgroup->busy is cleared on return) and
  1165. * make sure request is sane
  1166. */
  1167. rq = HWGROUP(drive)->rq;
  1168. if (!rq)
  1169. goto out;
  1170. HWGROUP(drive)->rq = NULL;
  1171. rq->errors = 0;
  1172. if (!rq->bio)
  1173. goto out;
  1174. rq->sector = rq->bio->bi_sector;
  1175. rq->current_nr_sectors = bio_iovec(rq->bio)->bv_len >> 9;
  1176. rq->hard_cur_sectors = rq->current_nr_sectors;
  1177. rq->buffer = bio_data(rq->bio);
  1178. out:
  1179. return ret;
  1180. }
  1181. /**
  1182. * ide_timer_expiry - handle lack of an IDE interrupt
  1183. * @data: timer callback magic (hwgroup)
  1184. *
  1185. * An IDE command has timed out before the expected drive return
  1186. * occurred. At this point we attempt to clean up the current
  1187. * mess. If the current handler includes an expiry handler then
  1188. * we invoke the expiry handler, and providing it is happy the
  1189. * work is done. If that fails we apply generic recovery rules
  1190. * invoking the handler and checking the drive DMA status. We
  1191. * have an excessively incestuous relationship with the DMA
  1192. * logic that wants cleaning up.
  1193. */
  1194. void ide_timer_expiry (unsigned long data)
  1195. {
  1196. ide_hwgroup_t *hwgroup = (ide_hwgroup_t *) data;
  1197. ide_handler_t *handler;
  1198. ide_expiry_t *expiry;
  1199. unsigned long flags;
  1200. unsigned long wait = -1;
  1201. spin_lock_irqsave(&ide_lock, flags);
  1202. if (((handler = hwgroup->handler) == NULL) ||
  1203. (hwgroup->req_gen != hwgroup->req_gen_timer)) {
  1204. /*
  1205. * Either a marginal timeout occurred
  1206. * (got the interrupt just as timer expired),
  1207. * or we were "sleeping" to give other devices a chance.
  1208. * Either way, we don't really want to complain about anything.
  1209. */
  1210. if (hwgroup->sleeping) {
  1211. hwgroup->sleeping = 0;
  1212. hwgroup->busy = 0;
  1213. }
  1214. } else {
  1215. ide_drive_t *drive = hwgroup->drive;
  1216. if (!drive) {
  1217. printk(KERN_ERR "ide_timer_expiry: hwgroup->drive was NULL\n");
  1218. hwgroup->handler = NULL;
  1219. } else {
  1220. ide_hwif_t *hwif;
  1221. ide_startstop_t startstop = ide_stopped;
  1222. if (!hwgroup->busy) {
  1223. hwgroup->busy = 1; /* paranoia */
  1224. printk(KERN_ERR "%s: ide_timer_expiry: hwgroup->busy was 0 ??\n", drive->name);
  1225. }
  1226. if ((expiry = hwgroup->expiry) != NULL) {
  1227. /* continue */
  1228. if ((wait = expiry(drive)) > 0) {
  1229. /* reset timer */
  1230. hwgroup->timer.expires = jiffies + wait;
  1231. hwgroup->req_gen_timer = hwgroup->req_gen;
  1232. add_timer(&hwgroup->timer);
  1233. spin_unlock_irqrestore(&ide_lock, flags);
  1234. return;
  1235. }
  1236. }
  1237. hwgroup->handler = NULL;
  1238. /*
  1239. * We need to simulate a real interrupt when invoking
  1240. * the handler() function, which means we need to
  1241. * globally mask the specific IRQ:
  1242. */
  1243. spin_unlock(&ide_lock);
  1244. hwif = HWIF(drive);
  1245. /* disable_irq_nosync ?? */
  1246. disable_irq(hwif->irq);
  1247. /* local CPU only,
  1248. * as if we were handling an interrupt */
  1249. local_irq_disable();
  1250. if (hwgroup->polling) {
  1251. startstop = handler(drive);
  1252. } else if (drive_is_ready(drive)) {
  1253. if (drive->waiting_for_dma)
  1254. hwgroup->hwif->dma_lost_irq(drive);
  1255. (void)ide_ack_intr(hwif);
  1256. printk(KERN_WARNING "%s: lost interrupt\n", drive->name);
  1257. startstop = handler(drive);
  1258. } else {
  1259. if (drive->waiting_for_dma) {
  1260. startstop = ide_dma_timeout_retry(drive, wait);
  1261. } else
  1262. startstop =
  1263. ide_error(drive, "irq timeout", hwif->INB(IDE_STATUS_REG));
  1264. }
  1265. drive->service_time = jiffies - drive->service_start;
  1266. spin_lock_irq(&ide_lock);
  1267. enable_irq(hwif->irq);
  1268. if (startstop == ide_stopped)
  1269. hwgroup->busy = 0;
  1270. }
  1271. }
  1272. ide_do_request(hwgroup, IDE_NO_IRQ);
  1273. spin_unlock_irqrestore(&ide_lock, flags);
  1274. }
  1275. /**
  1276. * unexpected_intr - handle an unexpected IDE interrupt
  1277. * @irq: interrupt line
  1278. * @hwgroup: hwgroup being processed
  1279. *
  1280. * There's nothing really useful we can do with an unexpected interrupt,
  1281. * other than reading the status register (to clear it), and logging it.
  1282. * There should be no way that an irq can happen before we're ready for it,
  1283. * so we needn't worry much about losing an "important" interrupt here.
  1284. *
  1285. * On laptops (and "green" PCs), an unexpected interrupt occurs whenever
  1286. * the drive enters "idle", "standby", or "sleep" mode, so if the status
  1287. * looks "good", we just ignore the interrupt completely.
  1288. *
  1289. * This routine assumes __cli() is in effect when called.
  1290. *
  1291. * If an unexpected interrupt happens on irq15 while we are handling irq14
  1292. * and if the two interfaces are "serialized" (CMD640), then it looks like
  1293. * we could screw up by interfering with a new request being set up for
  1294. * irq15.
  1295. *
  1296. * In reality, this is a non-issue. The new command is not sent unless
  1297. * the drive is ready to accept one, in which case we know the drive is
  1298. * not trying to interrupt us. And ide_set_handler() is always invoked
  1299. * before completing the issuance of any new drive command, so we will not
  1300. * be accidentally invoked as a result of any valid command completion
  1301. * interrupt.
  1302. *
  1303. * Note that we must walk the entire hwgroup here. We know which hwif
  1304. * is doing the current command, but we don't know which hwif burped
  1305. * mysteriously.
  1306. */
  1307. static void unexpected_intr (int irq, ide_hwgroup_t *hwgroup)
  1308. {
  1309. u8 stat;
  1310. ide_hwif_t *hwif = hwgroup->hwif;
  1311. /*
  1312. * handle the unexpected interrupt
  1313. */
  1314. do {
  1315. if (hwif->irq == irq) {
  1316. stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);
  1317. if (!OK_STAT(stat, READY_STAT, BAD_STAT)) {
  1318. /* Try to not flood the console with msgs */
  1319. static unsigned long last_msgtime, count;
  1320. ++count;
  1321. if (time_after(jiffies, last_msgtime + HZ)) {
  1322. last_msgtime = jiffies;
  1323. printk(KERN_ERR "%s%s: unexpected interrupt, "
  1324. "status=0x%02x, count=%ld\n",
  1325. hwif->name,
  1326. (hwif->next==hwgroup->hwif) ? "" : "(?)", stat, count);
  1327. }
  1328. }
  1329. }
  1330. } while ((hwif = hwif->next) != hwgroup->hwif);
  1331. }
  1332. /**
  1333. * ide_intr - default IDE interrupt handler
  1334. * @irq: interrupt number
  1335. * @dev_id: hwif group
  1336. * @regs: unused weirdness from the kernel irq layer
  1337. *
  1338. * This is the default IRQ handler for the IDE layer. You should
  1339. * not need to override it. If you do be aware it is subtle in
  1340. * places
  1341. *
  1342. * hwgroup->hwif is the interface in the group currently performing
  1343. * a command. hwgroup->drive is the drive and hwgroup->handler is
  1344. * the IRQ handler to call. As we issue a command the handlers
  1345. * step through multiple states, reassigning the handler to the
  1346. * next step in the process. Unlike a smart SCSI controller IDE
  1347. * expects the main processor to sequence the various transfer
  1348. * stages. We also manage a poll timer to catch up with most
  1349. * timeout situations. There are still a few where the handlers
  1350. * don't ever decide to give up.
  1351. *
  1352. * The handler eventually returns ide_stopped to indicate the
  1353. * request completed. At this point we issue the next request
  1354. * on the hwgroup and the process begins again.
  1355. */
  1356. irqreturn_t ide_intr (int irq, void *dev_id)
  1357. {
  1358. unsigned long flags;
  1359. ide_hwgroup_t *hwgroup = (ide_hwgroup_t *)dev_id;
  1360. ide_hwif_t *hwif;
  1361. ide_drive_t *drive;
  1362. ide_handler_t *handler;
  1363. ide_startstop_t startstop;
  1364. spin_lock_irqsave(&ide_lock, flags);
  1365. hwif = hwgroup->hwif;
  1366. if (!ide_ack_intr(hwif)) {
  1367. spin_unlock_irqrestore(&ide_lock, flags);
  1368. return IRQ_NONE;
  1369. }
  1370. if ((handler = hwgroup->handler) == NULL || hwgroup->polling) {
  1371. /*
  1372. * Not expecting an interrupt from this drive.
  1373. * That means this could be:
  1374. * (1) an interrupt from another PCI device
  1375. * sharing the same PCI INT# as us.
  1376. * or (2) a drive just entered sleep or standby mode,
  1377. * and is interrupting to let us know.
  1378. * or (3) a spurious interrupt of unknown origin.
  1379. *
  1380. * For PCI, we cannot tell the difference,
  1381. * so in that case we just ignore it and hope it goes away.
  1382. *
  1383. * FIXME: unexpected_intr should be hwif-> then we can
  1384. * remove all the ifdef PCI crap
  1385. */
  1386. #ifdef CONFIG_BLK_DEV_IDEPCI
  1387. if (hwif->pci_dev && !hwif->pci_dev->vendor)
  1388. #endif /* CONFIG_BLK_DEV_IDEPCI */
  1389. {
  1390. /*
  1391. * Probably not a shared PCI interrupt,
  1392. * so we can safely try to do something about it:
  1393. */
  1394. unexpected_intr(irq, hwgroup);
  1395. #ifdef CONFIG_BLK_DEV_IDEPCI
  1396. } else {
  1397. /*
  1398. * Whack the status register, just in case
  1399. * we have a leftover pending IRQ.
  1400. */
  1401. (void) hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);
  1402. #endif /* CONFIG_BLK_DEV_IDEPCI */
  1403. }
  1404. spin_unlock_irqrestore(&ide_lock, flags);
  1405. return IRQ_NONE;
  1406. }
  1407. drive = hwgroup->drive;
  1408. if (!drive) {
  1409. /*
  1410. * This should NEVER happen, and there isn't much
  1411. * we could do about it here.
  1412. *
  1413. * [Note - this can occur if the drive is hot unplugged]
  1414. */
  1415. spin_unlock_irqrestore(&ide_lock, flags);
  1416. return IRQ_HANDLED;
  1417. }
  1418. if (!drive_is_ready(drive)) {
  1419. /*
  1420. * This happens regularly when we share a PCI IRQ with
  1421. * another device. Unfortunately, it can also happen
  1422. * with some buggy drives that trigger the IRQ before
  1423. * their status register is up to date. Hopefully we have
  1424. * enough advance overhead that the latter isn't a problem.
  1425. */
  1426. spin_unlock_irqrestore(&ide_lock, flags);
  1427. return IRQ_NONE;
  1428. }
  1429. if (!hwgroup->busy) {
  1430. hwgroup->busy = 1; /* paranoia */
  1431. printk(KERN_ERR "%s: ide_intr: hwgroup->busy was 0 ??\n", drive->name);
  1432. }
  1433. hwgroup->handler = NULL;
  1434. hwgroup->req_gen++;
  1435. del_timer(&hwgroup->timer);
  1436. spin_unlock(&ide_lock);
  1437. /* Some controllers might set DMA INTR no matter DMA or PIO;
  1438. * bmdma status might need to be cleared even for
  1439. * PIO interrupts to prevent spurious/lost irq.
  1440. */
  1441. if (hwif->ide_dma_clear_irq && !(drive->waiting_for_dma))
  1442. /* ide_dma_end() needs bmdma status for error checking.
  1443. * So, skip clearing bmdma status here and leave it
  1444. * to ide_dma_end() if this is dma interrupt.
  1445. */
  1446. hwif->ide_dma_clear_irq(drive);
  1447. if (drive->unmask)
  1448. local_irq_enable_in_hardirq();
  1449. /* service this interrupt, may set handler for next interrupt */
  1450. startstop = handler(drive);
  1451. spin_lock_irq(&ide_lock);
  1452. /*
  1453. * Note that handler() may have set things up for another
  1454. * interrupt to occur soon, but it cannot happen until
  1455. * we exit from this routine, because it will be the
  1456. * same irq as is currently being serviced here, and Linux
  1457. * won't allow another of the same (on any CPU) until we return.
  1458. */
  1459. drive->service_time = jiffies - drive->service_start;
  1460. if (startstop == ide_stopped) {
  1461. if (hwgroup->handler == NULL) { /* paranoia */
  1462. hwgroup->busy = 0;
  1463. ide_do_request(hwgroup, hwif->irq);
  1464. } else {
  1465. printk(KERN_ERR "%s: ide_intr: huh? expected NULL handler "
  1466. "on exit\n", drive->name);
  1467. }
  1468. }
  1469. spin_unlock_irqrestore(&ide_lock, flags);
  1470. return IRQ_HANDLED;
  1471. }
  1472. /**
  1473. * ide_init_drive_cmd - initialize a drive command request
  1474. * @rq: request object
  1475. *
  1476. * Initialize a request before we fill it in and send it down to
  1477. * ide_do_drive_cmd. Commands must be set up by this function. Right
  1478. * now it doesn't do a lot, but if that changes abusers will have a
  1479. * nasty surprise.
  1480. */
  1481. void ide_init_drive_cmd (struct request *rq)
  1482. {
  1483. memset(rq, 0, sizeof(*rq));
  1484. rq->cmd_type = REQ_TYPE_ATA_CMD;
  1485. rq->ref_count = 1;
  1486. }
  1487. EXPORT_SYMBOL(ide_init_drive_cmd);
  1488. /**
  1489. * ide_do_drive_cmd - issue IDE special command
  1490. * @drive: device to issue command
  1491. * @rq: request to issue
  1492. * @action: action for processing
  1493. *
  1494. * This function issues a special IDE device request
  1495. * onto the request queue.
  1496. *
  1497. * If action is ide_wait, then the rq is queued at the end of the
  1498. * request queue, and the function sleeps until it has been processed.
  1499. * This is for use when invoked from an ioctl handler.
  1500. *
  1501. * If action is ide_preempt, then the rq is queued at the head of
  1502. * the request queue, displacing the currently-being-processed
  1503. * request and this function returns immediately without waiting
  1504. * for the new rq to be completed. This is VERY DANGEROUS, and is
  1505. * intended for careful use by the ATAPI tape/cdrom driver code.
  1506. *
  1507. * If action is ide_end, then the rq is queued at the end of the
  1508. * request queue, and the function returns immediately without waiting
  1509. * for the new rq to be completed. This is again intended for careful
  1510. * use by the ATAPI tape/cdrom driver code.
  1511. */
  1512. int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t action)
  1513. {
  1514. unsigned long flags;
  1515. ide_hwgroup_t *hwgroup = HWGROUP(drive);
  1516. DECLARE_COMPLETION_ONSTACK(wait);
  1517. int where = ELEVATOR_INSERT_BACK, err;
  1518. int must_wait = (action == ide_wait || action == ide_head_wait);
  1519. rq->errors = 0;
  1520. /*
  1521. * we need to hold an extra reference to request for safe inspection
  1522. * after completion
  1523. */
  1524. if (must_wait) {
  1525. rq->ref_count++;
  1526. rq->end_io_data = &wait;
  1527. rq->end_io = blk_end_sync_rq;
  1528. }
  1529. spin_lock_irqsave(&ide_lock, flags);
  1530. if (action == ide_preempt)
  1531. hwgroup->rq = NULL;
  1532. if (action == ide_preempt || action == ide_head_wait) {
  1533. where = ELEVATOR_INSERT_FRONT;
  1534. rq->cmd_flags |= REQ_PREEMPT;
  1535. }
  1536. __elv_add_request(drive->queue, rq, where, 0);
  1537. ide_do_request(hwgroup, IDE_NO_IRQ);
  1538. spin_unlock_irqrestore(&ide_lock, flags);
  1539. err = 0;
  1540. if (must_wait) {
  1541. wait_for_completion(&wait);
  1542. if (rq->errors)
  1543. err = -EIO;
  1544. blk_put_request(rq);
  1545. }
  1546. return err;
  1547. }
  1548. EXPORT_SYMBOL(ide_do_drive_cmd);
  1549. void ide_pktcmd_tf_load(ide_drive_t *drive, u32 tf_flags, u16 bcount, u8 dma)
  1550. {
  1551. ide_task_t task;
  1552. memset(&task, 0, sizeof(task));
  1553. task.tf_flags = IDE_TFLAG_OUT_LBAH | IDE_TFLAG_OUT_LBAM |
  1554. IDE_TFLAG_OUT_FEATURE | tf_flags;
  1555. task.tf.feature = dma; /* Use PIO/DMA */
  1556. task.tf.lbam = bcount & 0xff;
  1557. task.tf.lbah = (bcount >> 8) & 0xff;
  1558. ide_tf_load(drive, &task);
  1559. }
  1560. EXPORT_SYMBOL_GPL(ide_pktcmd_tf_load);