ide-cd.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  1. /*
  2. * ATAPI CD-ROM driver.
  3. *
  4. * Copyright (C) 1994-1996 Scott Snyder <snyder@fnald0.fnal.gov>
  5. * Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org>
  6. * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de>
  7. * Copyright (C) 2005, 2007-2009 Bartlomiej Zolnierkiewicz
  8. *
  9. * May be copied or modified under the terms of the GNU General Public
  10. * License. See linux/COPYING for more information.
  11. *
  12. * See Documentation/cdrom/ide-cd for usage information.
  13. *
  14. * Suggestions are welcome. Patches that work are more welcome though. ;-)
  15. *
  16. * Documentation:
  17. * Mt. Fuji (SFF8090 version 4) and ATAPI (SFF-8020i rev 2.6) standards.
  18. *
  19. * For historical changelog please see:
  20. * Documentation/ide/ChangeLog.ide-cd.1994-2004
  21. */
  22. #define DRV_NAME "ide-cd"
  23. #define PFX DRV_NAME ": "
  24. #define IDECD_VERSION "5.00"
  25. #include <linux/module.h>
  26. #include <linux/types.h>
  27. #include <linux/kernel.h>
  28. #include <linux/delay.h>
  29. #include <linux/timer.h>
  30. #include <linux/seq_file.h>
  31. #include <linux/slab.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/errno.h>
  34. #include <linux/cdrom.h>
  35. #include <linux/ide.h>
  36. #include <linux/completion.h>
  37. #include <linux/mutex.h>
  38. #include <linux/bcd.h>
  39. /* For SCSI -> ATAPI command conversion */
  40. #include <scsi/scsi.h>
  41. #include <linux/irq.h>
  42. #include <linux/io.h>
  43. #include <asm/byteorder.h>
  44. #include <linux/uaccess.h>
  45. #include <asm/unaligned.h>
  46. #include "ide-cd.h"
  47. static DEFINE_MUTEX(idecd_ref_mutex);
  48. static void ide_cd_release(struct device *);
  49. static struct cdrom_info *ide_cd_get(struct gendisk *disk)
  50. {
  51. struct cdrom_info *cd = NULL;
  52. mutex_lock(&idecd_ref_mutex);
  53. cd = ide_drv_g(disk, cdrom_info);
  54. if (cd) {
  55. if (ide_device_get(cd->drive))
  56. cd = NULL;
  57. else
  58. get_device(&cd->dev);
  59. }
  60. mutex_unlock(&idecd_ref_mutex);
  61. return cd;
  62. }
  63. static void ide_cd_put(struct cdrom_info *cd)
  64. {
  65. ide_drive_t *drive = cd->drive;
  66. mutex_lock(&idecd_ref_mutex);
  67. put_device(&cd->dev);
  68. ide_device_put(drive);
  69. mutex_unlock(&idecd_ref_mutex);
  70. }
  71. /*
  72. * Generic packet command support and error handling routines.
  73. */
  74. /* Mark that we've seen a media change and invalidate our internal buffers. */
  75. static void cdrom_saw_media_change(ide_drive_t *drive)
  76. {
  77. drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
  78. drive->atapi_flags &= ~IDE_AFLAG_TOC_VALID;
  79. }
  80. static int cdrom_log_sense(ide_drive_t *drive, struct request *rq)
  81. {
  82. struct request_sense *sense = &drive->sense_data;
  83. int log = 0;
  84. if (!sense || !rq || (rq->cmd_flags & REQ_QUIET))
  85. return 0;
  86. ide_debug_log(IDE_DBG_SENSE, "sense_key: 0x%x", sense->sense_key);
  87. switch (sense->sense_key) {
  88. case NO_SENSE:
  89. case RECOVERED_ERROR:
  90. break;
  91. case NOT_READY:
  92. /*
  93. * don't care about tray state messages for e.g. capacity
  94. * commands or in-progress or becoming ready
  95. */
  96. if (sense->asc == 0x3a || sense->asc == 0x04)
  97. break;
  98. log = 1;
  99. break;
  100. case ILLEGAL_REQUEST:
  101. /*
  102. * don't log START_STOP unit with LoEj set, since we cannot
  103. * reliably check if drive can auto-close
  104. */
  105. if (rq->cmd[0] == GPCMD_START_STOP_UNIT && sense->asc == 0x24)
  106. break;
  107. log = 1;
  108. break;
  109. case UNIT_ATTENTION:
  110. /*
  111. * Make good and sure we've seen this potential media change.
  112. * Some drives (i.e. Creative) fail to present the correct sense
  113. * key in the error register.
  114. */
  115. cdrom_saw_media_change(drive);
  116. break;
  117. default:
  118. log = 1;
  119. break;
  120. }
  121. return log;
  122. }
  123. static void cdrom_analyze_sense_data(ide_drive_t *drive,
  124. struct request *failed_command)
  125. {
  126. struct request_sense *sense = &drive->sense_data;
  127. struct cdrom_info *info = drive->driver_data;
  128. unsigned long sector;
  129. unsigned long bio_sectors;
  130. ide_debug_log(IDE_DBG_SENSE, "error_code: 0x%x, sense_key: 0x%x",
  131. sense->error_code, sense->sense_key);
  132. if (failed_command)
  133. ide_debug_log(IDE_DBG_SENSE, "failed cmd: 0x%x",
  134. failed_command->cmd[0]);
  135. if (!cdrom_log_sense(drive, failed_command))
  136. return;
  137. /*
  138. * If a read toc is executed for a CD-R or CD-RW medium where the first
  139. * toc has not been recorded yet, it will fail with 05/24/00 (which is a
  140. * confusing error)
  141. */
  142. if (failed_command && failed_command->cmd[0] == GPCMD_READ_TOC_PMA_ATIP)
  143. if (sense->sense_key == 0x05 && sense->asc == 0x24)
  144. return;
  145. /* current error */
  146. if (sense->error_code == 0x70) {
  147. switch (sense->sense_key) {
  148. case MEDIUM_ERROR:
  149. case VOLUME_OVERFLOW:
  150. case ILLEGAL_REQUEST:
  151. if (!sense->valid)
  152. break;
  153. if (failed_command == NULL ||
  154. failed_command->cmd_type != REQ_TYPE_FS)
  155. break;
  156. sector = (sense->information[0] << 24) |
  157. (sense->information[1] << 16) |
  158. (sense->information[2] << 8) |
  159. (sense->information[3]);
  160. if (queue_logical_block_size(drive->queue) == 2048)
  161. /* device sector size is 2K */
  162. sector <<= 2;
  163. bio_sectors = max(bio_sectors(failed_command->bio), 4U);
  164. sector &= ~(bio_sectors - 1);
  165. /*
  166. * The SCSI specification allows for the value
  167. * returned by READ CAPACITY to be up to 75 2K
  168. * sectors past the last readable block.
  169. * Therefore, if we hit a medium error within the
  170. * last 75 2K sectors, we decrease the saved size
  171. * value.
  172. */
  173. if (sector < get_capacity(info->disk) &&
  174. drive->probed_capacity - sector < 4 * 75)
  175. set_capacity(info->disk, sector);
  176. }
  177. }
  178. ide_cd_log_error(drive->name, failed_command, sense);
  179. }
  180. static void ide_cd_complete_failed_rq(ide_drive_t *drive, struct request *rq)
  181. {
  182. /*
  183. * For REQ_TYPE_SENSE, "rq->special" points to the original
  184. * failed request. Also, the sense data should be read
  185. * directly from rq which might be different from the original
  186. * sense buffer if it got copied during mapping.
  187. */
  188. struct request *failed = (struct request *)rq->special;
  189. void *sense = bio_data(rq->bio);
  190. if (failed) {
  191. if (failed->sense) {
  192. /*
  193. * Sense is always read into drive->sense_data.
  194. * Copy back if the failed request has its
  195. * sense pointer set.
  196. */
  197. memcpy(failed->sense, sense, 18);
  198. failed->sense_len = rq->sense_len;
  199. }
  200. cdrom_analyze_sense_data(drive, failed);
  201. if (ide_end_rq(drive, failed, -EIO, blk_rq_bytes(failed)))
  202. BUG();
  203. } else
  204. cdrom_analyze_sense_data(drive, NULL);
  205. }
  206. /*
  207. * Allow the drive 5 seconds to recover; some devices will return NOT_READY
  208. * while flushing data from cache.
  209. *
  210. * returns: 0 failed (write timeout expired)
  211. * 1 success
  212. */
  213. static int ide_cd_breathe(ide_drive_t *drive, struct request *rq)
  214. {
  215. struct cdrom_info *info = drive->driver_data;
  216. if (!rq->errors)
  217. info->write_timeout = jiffies + ATAPI_WAIT_WRITE_BUSY;
  218. rq->errors = 1;
  219. if (time_after(jiffies, info->write_timeout))
  220. return 0;
  221. else {
  222. struct request_queue *q = drive->queue;
  223. unsigned long flags;
  224. /*
  225. * take a breather relying on the unplug timer to kick us again
  226. */
  227. spin_lock_irqsave(q->queue_lock, flags);
  228. blk_plug_device(q);
  229. spin_unlock_irqrestore(q->queue_lock, flags);
  230. return 1;
  231. }
  232. }
  233. /**
  234. * Returns:
  235. * 0: if the request should be continued.
  236. * 1: if the request will be going through error recovery.
  237. * 2: if the request should be ended.
  238. */
  239. static int cdrom_decode_status(ide_drive_t *drive, u8 stat)
  240. {
  241. ide_hwif_t *hwif = drive->hwif;
  242. struct request *rq = hwif->rq;
  243. int err, sense_key, do_end_request = 0;
  244. /* get the IDE error register */
  245. err = ide_read_error(drive);
  246. sense_key = err >> 4;
  247. ide_debug_log(IDE_DBG_RQ, "cmd: 0x%x, rq->cmd_type: 0x%x, err: 0x%x, "
  248. "stat 0x%x",
  249. rq->cmd[0], rq->cmd_type, err, stat);
  250. if (rq->cmd_type == REQ_TYPE_SENSE) {
  251. /*
  252. * We got an error trying to get sense info from the drive
  253. * (probably while trying to recover from a former error).
  254. * Just give up.
  255. */
  256. rq->cmd_flags |= REQ_FAILED;
  257. return 2;
  258. }
  259. /* if we have an error, pass CHECK_CONDITION as the SCSI status byte */
  260. if (rq->cmd_type == REQ_TYPE_BLOCK_PC && !rq->errors)
  261. rq->errors = SAM_STAT_CHECK_CONDITION;
  262. if (blk_noretry_request(rq))
  263. do_end_request = 1;
  264. switch (sense_key) {
  265. case NOT_READY:
  266. if (rq->cmd_type == REQ_TYPE_FS && rq_data_dir(rq) == WRITE) {
  267. if (ide_cd_breathe(drive, rq))
  268. return 1;
  269. } else {
  270. cdrom_saw_media_change(drive);
  271. if (rq->cmd_type == REQ_TYPE_FS &&
  272. !(rq->cmd_flags & REQ_QUIET))
  273. printk(KERN_ERR PFX "%s: tray open\n",
  274. drive->name);
  275. }
  276. do_end_request = 1;
  277. break;
  278. case UNIT_ATTENTION:
  279. cdrom_saw_media_change(drive);
  280. if (rq->cmd_type != REQ_TYPE_FS)
  281. return 0;
  282. /*
  283. * Arrange to retry the request but be sure to give up if we've
  284. * retried too many times.
  285. */
  286. if (++rq->errors > ERROR_MAX)
  287. do_end_request = 1;
  288. break;
  289. case ILLEGAL_REQUEST:
  290. /*
  291. * Don't print error message for this condition -- SFF8090i
  292. * indicates that 5/24/00 is the correct response to a request
  293. * to close the tray if the drive doesn't have that capability.
  294. *
  295. * cdrom_log_sense() knows this!
  296. */
  297. if (rq->cmd[0] == GPCMD_START_STOP_UNIT)
  298. break;
  299. /* fall-through */
  300. case DATA_PROTECT:
  301. /*
  302. * No point in retrying after an illegal request or data
  303. * protect error.
  304. */
  305. if (!(rq->cmd_flags & REQ_QUIET))
  306. ide_dump_status(drive, "command error", stat);
  307. do_end_request = 1;
  308. break;
  309. case MEDIUM_ERROR:
  310. /*
  311. * No point in re-trying a zillion times on a bad sector.
  312. * If we got here the error is not correctable.
  313. */
  314. if (!(rq->cmd_flags & REQ_QUIET))
  315. ide_dump_status(drive, "media error "
  316. "(bad sector)", stat);
  317. do_end_request = 1;
  318. break;
  319. case BLANK_CHECK:
  320. /* disk appears blank? */
  321. if (!(rq->cmd_flags & REQ_QUIET))
  322. ide_dump_status(drive, "media error (blank)",
  323. stat);
  324. do_end_request = 1;
  325. break;
  326. default:
  327. if (rq->cmd_type != REQ_TYPE_FS)
  328. break;
  329. if (err & ~ATA_ABORTED) {
  330. /* go to the default handler for other errors */
  331. ide_error(drive, "cdrom_decode_status", stat);
  332. return 1;
  333. } else if (++rq->errors > ERROR_MAX)
  334. /* we've racked up too many retries, abort */
  335. do_end_request = 1;
  336. }
  337. if (rq->cmd_type != REQ_TYPE_FS) {
  338. rq->cmd_flags |= REQ_FAILED;
  339. do_end_request = 1;
  340. }
  341. /*
  342. * End a request through request sense analysis when we have sense data.
  343. * We need this in order to perform end of media processing.
  344. */
  345. if (do_end_request)
  346. goto end_request;
  347. /* if we got a CHECK_CONDITION status, queue a request sense command */
  348. if (stat & ATA_ERR)
  349. return ide_queue_sense_rq(drive, NULL) ? 2 : 1;
  350. return 1;
  351. end_request:
  352. if (stat & ATA_ERR) {
  353. hwif->rq = NULL;
  354. return ide_queue_sense_rq(drive, rq) ? 2 : 1;
  355. } else
  356. return 2;
  357. }
  358. static void ide_cd_request_sense_fixup(ide_drive_t *drive, struct ide_cmd *cmd)
  359. {
  360. struct request *rq = cmd->rq;
  361. ide_debug_log(IDE_DBG_FUNC, "rq->cmd[0]: 0x%x", rq->cmd[0]);
  362. /*
  363. * Some of the trailing request sense fields are optional,
  364. * and some drives don't send them. Sigh.
  365. */
  366. if (rq->cmd[0] == GPCMD_REQUEST_SENSE &&
  367. cmd->nleft > 0 && cmd->nleft <= 5)
  368. cmd->nleft = 0;
  369. }
  370. int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
  371. int write, void *buffer, unsigned *bufflen,
  372. struct request_sense *sense, int timeout,
  373. unsigned int cmd_flags)
  374. {
  375. struct cdrom_info *info = drive->driver_data;
  376. struct request_sense local_sense;
  377. int retries = 10;
  378. unsigned int flags = 0;
  379. if (!sense)
  380. sense = &local_sense;
  381. ide_debug_log(IDE_DBG_PC, "cmd[0]: 0x%x, write: 0x%x, timeout: %d, "
  382. "cmd_flags: 0x%x",
  383. cmd[0], write, timeout, cmd_flags);
  384. /* start of retry loop */
  385. do {
  386. struct request *rq;
  387. int error;
  388. rq = blk_get_request(drive->queue, write, __GFP_WAIT);
  389. memcpy(rq->cmd, cmd, BLK_MAX_CDB);
  390. rq->cmd_type = REQ_TYPE_ATA_PC;
  391. rq->sense = sense;
  392. rq->cmd_flags |= cmd_flags;
  393. rq->timeout = timeout;
  394. if (buffer) {
  395. error = blk_rq_map_kern(drive->queue, rq, buffer,
  396. *bufflen, GFP_NOIO);
  397. if (error) {
  398. blk_put_request(rq);
  399. return error;
  400. }
  401. }
  402. error = blk_execute_rq(drive->queue, info->disk, rq, 0);
  403. if (buffer)
  404. *bufflen = rq->resid_len;
  405. flags = rq->cmd_flags;
  406. blk_put_request(rq);
  407. /*
  408. * FIXME: we should probably abort/retry or something in case of
  409. * failure.
  410. */
  411. if (flags & REQ_FAILED) {
  412. /*
  413. * The request failed. Retry if it was due to a unit
  414. * attention status (usually means media was changed).
  415. */
  416. struct request_sense *reqbuf = sense;
  417. if (reqbuf->sense_key == UNIT_ATTENTION)
  418. cdrom_saw_media_change(drive);
  419. else if (reqbuf->sense_key == NOT_READY &&
  420. reqbuf->asc == 4 && reqbuf->ascq != 4) {
  421. /*
  422. * The drive is in the process of loading
  423. * a disk. Retry, but wait a little to give
  424. * the drive time to complete the load.
  425. */
  426. ssleep(2);
  427. } else {
  428. /* otherwise, don't retry */
  429. retries = 0;
  430. }
  431. --retries;
  432. }
  433. /* end of retry loop */
  434. } while ((flags & REQ_FAILED) && retries >= 0);
  435. /* return an error if the command failed */
  436. return (flags & REQ_FAILED) ? -EIO : 0;
  437. }
  438. static void ide_cd_error_cmd(ide_drive_t *drive, struct ide_cmd *cmd)
  439. {
  440. unsigned int nr_bytes = cmd->nbytes - cmd->nleft;
  441. if (cmd->tf_flags & IDE_TFLAG_WRITE)
  442. nr_bytes -= cmd->last_xfer_len;
  443. if (nr_bytes > 0)
  444. ide_complete_rq(drive, 0, nr_bytes);
  445. }
  446. static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
  447. {
  448. ide_hwif_t *hwif = drive->hwif;
  449. struct ide_cmd *cmd = &hwif->cmd;
  450. struct request *rq = hwif->rq;
  451. ide_expiry_t *expiry = NULL;
  452. int dma_error = 0, dma, thislen, uptodate = 0;
  453. int write = (rq_data_dir(rq) == WRITE) ? 1 : 0, rc = 0;
  454. int sense = (rq->cmd_type == REQ_TYPE_SENSE);
  455. unsigned int timeout;
  456. u16 len;
  457. u8 ireason, stat;
  458. ide_debug_log(IDE_DBG_PC, "cmd: 0x%x, write: 0x%x", rq->cmd[0], write);
  459. /* check for errors */
  460. dma = drive->dma;
  461. if (dma) {
  462. drive->dma = 0;
  463. drive->waiting_for_dma = 0;
  464. dma_error = hwif->dma_ops->dma_end(drive);
  465. ide_dma_unmap_sg(drive, cmd);
  466. if (dma_error) {
  467. printk(KERN_ERR PFX "%s: DMA %s error\n", drive->name,
  468. write ? "write" : "read");
  469. ide_dma_off(drive);
  470. }
  471. }
  472. /* check status */
  473. stat = hwif->tp_ops->read_status(hwif);
  474. if (!OK_STAT(stat, 0, BAD_R_STAT)) {
  475. rc = cdrom_decode_status(drive, stat);
  476. if (rc) {
  477. if (rc == 2)
  478. goto out_end;
  479. return ide_stopped;
  480. }
  481. }
  482. /* using dma, transfer is complete now */
  483. if (dma) {
  484. if (dma_error)
  485. return ide_error(drive, "dma error", stat);
  486. uptodate = 1;
  487. goto out_end;
  488. }
  489. ide_read_bcount_and_ireason(drive, &len, &ireason);
  490. thislen = (rq->cmd_type == REQ_TYPE_FS) ? len : cmd->nleft;
  491. if (thislen > len)
  492. thislen = len;
  493. ide_debug_log(IDE_DBG_PC, "DRQ: stat: 0x%x, thislen: %d",
  494. stat, thislen);
  495. /* If DRQ is clear, the command has completed. */
  496. if ((stat & ATA_DRQ) == 0) {
  497. if (rq->cmd_type == REQ_TYPE_FS) {
  498. /*
  499. * If we're not done reading/writing, complain.
  500. * Otherwise, complete the command normally.
  501. */
  502. uptodate = 1;
  503. if (cmd->nleft > 0) {
  504. printk(KERN_ERR PFX "%s: %s: data underrun "
  505. "(%u bytes)\n", drive->name, __func__,
  506. cmd->nleft);
  507. if (!write)
  508. rq->cmd_flags |= REQ_FAILED;
  509. uptodate = 0;
  510. }
  511. } else if (rq->cmd_type != REQ_TYPE_BLOCK_PC) {
  512. ide_cd_request_sense_fixup(drive, cmd);
  513. uptodate = cmd->nleft ? 0 : 1;
  514. /*
  515. * suck out the remaining bytes from the drive in an
  516. * attempt to complete the data xfer. (see BZ#13399)
  517. */
  518. if (!(stat & ATA_ERR) && !uptodate && thislen) {
  519. ide_pio_bytes(drive, cmd, write, thislen);
  520. uptodate = cmd->nleft ? 0 : 1;
  521. }
  522. if (!uptodate)
  523. rq->cmd_flags |= REQ_FAILED;
  524. }
  525. goto out_end;
  526. }
  527. rc = ide_check_ireason(drive, rq, len, ireason, write);
  528. if (rc)
  529. goto out_end;
  530. cmd->last_xfer_len = 0;
  531. ide_debug_log(IDE_DBG_PC, "data transfer, rq->cmd_type: 0x%x, "
  532. "ireason: 0x%x",
  533. rq->cmd_type, ireason);
  534. /* transfer data */
  535. while (thislen > 0) {
  536. int blen = min_t(int, thislen, cmd->nleft);
  537. if (cmd->nleft == 0)
  538. break;
  539. ide_pio_bytes(drive, cmd, write, blen);
  540. cmd->last_xfer_len += blen;
  541. thislen -= blen;
  542. len -= blen;
  543. if (sense && write == 0)
  544. rq->sense_len += blen;
  545. }
  546. /* pad, if necessary */
  547. if (len > 0) {
  548. if (rq->cmd_type != REQ_TYPE_FS || write == 0)
  549. ide_pad_transfer(drive, write, len);
  550. else {
  551. printk(KERN_ERR PFX "%s: confused, missing data\n",
  552. drive->name);
  553. blk_dump_rq_flags(rq, "cdrom_newpc_intr");
  554. }
  555. }
  556. if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
  557. timeout = rq->timeout;
  558. } else {
  559. timeout = ATAPI_WAIT_PC;
  560. if (rq->cmd_type != REQ_TYPE_FS)
  561. expiry = ide_cd_expiry;
  562. }
  563. hwif->expiry = expiry;
  564. ide_set_handler(drive, cdrom_newpc_intr, timeout);
  565. return ide_started;
  566. out_end:
  567. if (rq->cmd_type == REQ_TYPE_BLOCK_PC && rc == 0) {
  568. rq->resid_len = 0;
  569. blk_end_request_all(rq, 0);
  570. hwif->rq = NULL;
  571. } else {
  572. if (sense && uptodate)
  573. ide_cd_complete_failed_rq(drive, rq);
  574. if (rq->cmd_type == REQ_TYPE_FS) {
  575. if (cmd->nleft == 0)
  576. uptodate = 1;
  577. } else {
  578. if (uptodate <= 0 && rq->errors == 0)
  579. rq->errors = -EIO;
  580. }
  581. if (uptodate == 0 && rq->bio)
  582. ide_cd_error_cmd(drive, cmd);
  583. /* make sure it's fully ended */
  584. if (rq->cmd_type != REQ_TYPE_FS) {
  585. rq->resid_len -= cmd->nbytes - cmd->nleft;
  586. if (uptodate == 0 && (cmd->tf_flags & IDE_TFLAG_WRITE))
  587. rq->resid_len += cmd->last_xfer_len;
  588. }
  589. ide_complete_rq(drive, uptodate ? 0 : -EIO, blk_rq_bytes(rq));
  590. if (sense && rc == 2)
  591. ide_error(drive, "request sense failure", stat);
  592. }
  593. return ide_stopped;
  594. }
  595. static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
  596. {
  597. struct cdrom_info *cd = drive->driver_data;
  598. struct request_queue *q = drive->queue;
  599. int write = rq_data_dir(rq) == WRITE;
  600. unsigned short sectors_per_frame =
  601. queue_logical_block_size(q) >> SECTOR_BITS;
  602. ide_debug_log(IDE_DBG_RQ, "rq->cmd[0]: 0x%x, rq->cmd_flags: 0x%x, "
  603. "secs_per_frame: %u",
  604. rq->cmd[0], rq->cmd_flags, sectors_per_frame);
  605. if (write) {
  606. /* disk has become write protected */
  607. if (get_disk_ro(cd->disk))
  608. return ide_stopped;
  609. } else {
  610. /*
  611. * We may be retrying this request after an error. Fix up any
  612. * weirdness which might be present in the request packet.
  613. */
  614. q->prep_rq_fn(q, rq);
  615. }
  616. /* fs requests *must* be hardware frame aligned */
  617. if ((blk_rq_sectors(rq) & (sectors_per_frame - 1)) ||
  618. (blk_rq_pos(rq) & (sectors_per_frame - 1)))
  619. return ide_stopped;
  620. /* use DMA, if possible */
  621. drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
  622. if (write)
  623. cd->devinfo.media_written = 1;
  624. rq->timeout = ATAPI_WAIT_PC;
  625. return ide_started;
  626. }
  627. static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
  628. {
  629. ide_debug_log(IDE_DBG_PC, "rq->cmd[0]: 0x%x, rq->cmd_type: 0x%x",
  630. rq->cmd[0], rq->cmd_type);
  631. if (rq->cmd_type == REQ_TYPE_BLOCK_PC)
  632. rq->cmd_flags |= REQ_QUIET;
  633. else
  634. rq->cmd_flags &= ~REQ_FAILED;
  635. drive->dma = 0;
  636. /* sg request */
  637. if (rq->bio) {
  638. struct request_queue *q = drive->queue;
  639. char *buf = bio_data(rq->bio);
  640. unsigned int alignment;
  641. drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
  642. /*
  643. * check if dma is safe
  644. *
  645. * NOTE! The "len" and "addr" checks should possibly have
  646. * separate masks.
  647. */
  648. alignment = queue_dma_alignment(q) | q->dma_pad_mask;
  649. if ((unsigned long)buf & alignment
  650. || blk_rq_bytes(rq) & q->dma_pad_mask
  651. || object_is_on_stack(buf))
  652. drive->dma = 0;
  653. }
  654. }
  655. static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
  656. sector_t block)
  657. {
  658. struct ide_cmd cmd;
  659. int uptodate = 0, nsectors;
  660. ide_debug_log(IDE_DBG_RQ, "cmd: 0x%x, block: %llu",
  661. rq->cmd[0], (unsigned long long)block);
  662. if (drive->debug_mask & IDE_DBG_RQ)
  663. blk_dump_rq_flags(rq, "ide_cd_do_request");
  664. switch (rq->cmd_type) {
  665. case REQ_TYPE_FS:
  666. if (cdrom_start_rw(drive, rq) == ide_stopped)
  667. goto out_end;
  668. break;
  669. case REQ_TYPE_SENSE:
  670. case REQ_TYPE_BLOCK_PC:
  671. case REQ_TYPE_ATA_PC:
  672. if (!rq->timeout)
  673. rq->timeout = ATAPI_WAIT_PC;
  674. cdrom_do_block_pc(drive, rq);
  675. break;
  676. case REQ_TYPE_SPECIAL:
  677. /* right now this can only be a reset... */
  678. uptodate = 1;
  679. goto out_end;
  680. default:
  681. BUG();
  682. }
  683. /* prepare sense request for this command */
  684. ide_prep_sense(drive, rq);
  685. memset(&cmd, 0, sizeof(cmd));
  686. if (rq_data_dir(rq))
  687. cmd.tf_flags |= IDE_TFLAG_WRITE;
  688. cmd.rq = rq;
  689. if (rq->cmd_type == REQ_TYPE_FS || blk_rq_bytes(rq)) {
  690. ide_init_sg_cmd(&cmd, blk_rq_bytes(rq));
  691. ide_map_sg(drive, &cmd);
  692. }
  693. return ide_issue_pc(drive, &cmd);
  694. out_end:
  695. nsectors = blk_rq_sectors(rq);
  696. if (nsectors == 0)
  697. nsectors = 1;
  698. ide_complete_rq(drive, uptodate ? 0 : -EIO, nsectors << 9);
  699. return ide_stopped;
  700. }
  701. /*
  702. * Ioctl handling.
  703. *
  704. * Routines which queue packet commands take as a final argument a pointer to a
  705. * request_sense struct. If execution of the command results in an error with a
  706. * CHECK CONDITION status, this structure will be filled with the results of the
  707. * subsequent request sense command. The pointer can also be NULL, in which case
  708. * no sense information is returned.
  709. */
  710. static void msf_from_bcd(struct atapi_msf *msf)
  711. {
  712. msf->minute = bcd2bin(msf->minute);
  713. msf->second = bcd2bin(msf->second);
  714. msf->frame = bcd2bin(msf->frame);
  715. }
  716. int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense)
  717. {
  718. struct cdrom_info *info = drive->driver_data;
  719. struct cdrom_device_info *cdi = &info->devinfo;
  720. unsigned char cmd[BLK_MAX_CDB];
  721. ide_debug_log(IDE_DBG_FUNC, "enter");
  722. memset(cmd, 0, BLK_MAX_CDB);
  723. cmd[0] = GPCMD_TEST_UNIT_READY;
  724. /*
  725. * Sanyo 3 CD changer uses byte 7 of TEST_UNIT_READY to switch CDs
  726. * instead of supporting the LOAD_UNLOAD opcode.
  727. */
  728. cmd[7] = cdi->sanyo_slot % 3;
  729. return ide_cd_queue_pc(drive, cmd, 0, NULL, NULL, sense, 0, REQ_QUIET);
  730. }
  731. static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
  732. unsigned long *sectors_per_frame,
  733. struct request_sense *sense)
  734. {
  735. struct {
  736. __be32 lba;
  737. __be32 blocklen;
  738. } capbuf;
  739. int stat;
  740. unsigned char cmd[BLK_MAX_CDB];
  741. unsigned len = sizeof(capbuf);
  742. u32 blocklen;
  743. ide_debug_log(IDE_DBG_FUNC, "enter");
  744. memset(cmd, 0, BLK_MAX_CDB);
  745. cmd[0] = GPCMD_READ_CDVD_CAPACITY;
  746. stat = ide_cd_queue_pc(drive, cmd, 0, &capbuf, &len, sense, 0,
  747. REQ_QUIET);
  748. if (stat)
  749. return stat;
  750. /*
  751. * Sanity check the given block size, in so far as making
  752. * sure the sectors_per_frame we give to the caller won't
  753. * end up being bogus.
  754. */
  755. blocklen = be32_to_cpu(capbuf.blocklen);
  756. blocklen = (blocklen >> SECTOR_BITS) << SECTOR_BITS;
  757. switch (blocklen) {
  758. case 512:
  759. case 1024:
  760. case 2048:
  761. case 4096:
  762. break;
  763. default:
  764. printk_once(KERN_ERR PFX "%s: weird block size %u; "
  765. "setting default block size to 2048\n",
  766. drive->name, blocklen);
  767. blocklen = 2048;
  768. break;
  769. }
  770. *capacity = 1 + be32_to_cpu(capbuf.lba);
  771. *sectors_per_frame = blocklen >> SECTOR_BITS;
  772. ide_debug_log(IDE_DBG_PROBE, "cap: %lu, sectors_per_frame: %lu",
  773. *capacity, *sectors_per_frame);
  774. return 0;
  775. }
  776. static int cdrom_read_tocentry(ide_drive_t *drive, int trackno, int msf_flag,
  777. int format, char *buf, int buflen,
  778. struct request_sense *sense)
  779. {
  780. unsigned char cmd[BLK_MAX_CDB];
  781. ide_debug_log(IDE_DBG_FUNC, "enter");
  782. memset(cmd, 0, BLK_MAX_CDB);
  783. cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
  784. cmd[6] = trackno;
  785. cmd[7] = (buflen >> 8);
  786. cmd[8] = (buflen & 0xff);
  787. cmd[9] = (format << 6);
  788. if (msf_flag)
  789. cmd[1] = 2;
  790. return ide_cd_queue_pc(drive, cmd, 0, buf, &buflen, sense, 0, REQ_QUIET);
  791. }
  792. /* Try to read the entire TOC for the disk into our internal buffer. */
  793. int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
  794. {
  795. int stat, ntracks, i;
  796. struct cdrom_info *info = drive->driver_data;
  797. struct cdrom_device_info *cdi = &info->devinfo;
  798. struct atapi_toc *toc = info->toc;
  799. struct {
  800. struct atapi_toc_header hdr;
  801. struct atapi_toc_entry ent;
  802. } ms_tmp;
  803. long last_written;
  804. unsigned long sectors_per_frame = SECTORS_PER_FRAME;
  805. ide_debug_log(IDE_DBG_FUNC, "enter");
  806. if (toc == NULL) {
  807. /* try to allocate space */
  808. toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL);
  809. if (toc == NULL) {
  810. printk(KERN_ERR PFX "%s: No cdrom TOC buffer!\n",
  811. drive->name);
  812. return -ENOMEM;
  813. }
  814. info->toc = toc;
  815. }
  816. /*
  817. * Check to see if the existing data is still valid. If it is,
  818. * just return.
  819. */
  820. (void) cdrom_check_status(drive, sense);
  821. if (drive->atapi_flags & IDE_AFLAG_TOC_VALID)
  822. return 0;
  823. /* try to get the total cdrom capacity and sector size */
  824. stat = cdrom_read_capacity(drive, &toc->capacity, &sectors_per_frame,
  825. sense);
  826. if (stat)
  827. toc->capacity = 0x1fffff;
  828. set_capacity(info->disk, toc->capacity * sectors_per_frame);
  829. /* save a private copy of the TOC capacity for error handling */
  830. drive->probed_capacity = toc->capacity * sectors_per_frame;
  831. blk_queue_logical_block_size(drive->queue,
  832. sectors_per_frame << SECTOR_BITS);
  833. /* first read just the header, so we know how long the TOC is */
  834. stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr,
  835. sizeof(struct atapi_toc_header), sense);
  836. if (stat)
  837. return stat;
  838. if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) {
  839. toc->hdr.first_track = bcd2bin(toc->hdr.first_track);
  840. toc->hdr.last_track = bcd2bin(toc->hdr.last_track);
  841. }
  842. ntracks = toc->hdr.last_track - toc->hdr.first_track + 1;
  843. if (ntracks <= 0)
  844. return -EIO;
  845. if (ntracks > MAX_TRACKS)
  846. ntracks = MAX_TRACKS;
  847. /* now read the whole schmeer */
  848. stat = cdrom_read_tocentry(drive, toc->hdr.first_track, 1, 0,
  849. (char *)&toc->hdr,
  850. sizeof(struct atapi_toc_header) +
  851. (ntracks + 1) *
  852. sizeof(struct atapi_toc_entry), sense);
  853. if (stat && toc->hdr.first_track > 1) {
  854. /*
  855. * Cds with CDI tracks only don't have any TOC entries, despite
  856. * of this the returned values are
  857. * first_track == last_track = number of CDI tracks + 1,
  858. * so that this case is indistinguishable from the same layout
  859. * plus an additional audio track. If we get an error for the
  860. * regular case, we assume a CDI without additional audio
  861. * tracks. In this case the readable TOC is empty (CDI tracks
  862. * are not included) and only holds the Leadout entry.
  863. *
  864. * Heiko Eißfeldt.
  865. */
  866. ntracks = 0;
  867. stat = cdrom_read_tocentry(drive, CDROM_LEADOUT, 1, 0,
  868. (char *)&toc->hdr,
  869. sizeof(struct atapi_toc_header) +
  870. (ntracks + 1) *
  871. sizeof(struct atapi_toc_entry),
  872. sense);
  873. if (stat)
  874. return stat;
  875. if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) {
  876. toc->hdr.first_track = (u8)bin2bcd(CDROM_LEADOUT);
  877. toc->hdr.last_track = (u8)bin2bcd(CDROM_LEADOUT);
  878. } else {
  879. toc->hdr.first_track = CDROM_LEADOUT;
  880. toc->hdr.last_track = CDROM_LEADOUT;
  881. }
  882. }
  883. if (stat)
  884. return stat;
  885. toc->hdr.toc_length = be16_to_cpu(toc->hdr.toc_length);
  886. if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) {
  887. toc->hdr.first_track = bcd2bin(toc->hdr.first_track);
  888. toc->hdr.last_track = bcd2bin(toc->hdr.last_track);
  889. }
  890. for (i = 0; i <= ntracks; i++) {
  891. if (drive->atapi_flags & IDE_AFLAG_TOCADDR_AS_BCD) {
  892. if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD)
  893. toc->ent[i].track = bcd2bin(toc->ent[i].track);
  894. msf_from_bcd(&toc->ent[i].addr.msf);
  895. }
  896. toc->ent[i].addr.lba = msf_to_lba(toc->ent[i].addr.msf.minute,
  897. toc->ent[i].addr.msf.second,
  898. toc->ent[i].addr.msf.frame);
  899. }
  900. if (toc->hdr.first_track != CDROM_LEADOUT) {
  901. /* read the multisession information */
  902. stat = cdrom_read_tocentry(drive, 0, 0, 1, (char *)&ms_tmp,
  903. sizeof(ms_tmp), sense);
  904. if (stat)
  905. return stat;
  906. toc->last_session_lba = be32_to_cpu(ms_tmp.ent.addr.lba);
  907. } else {
  908. ms_tmp.hdr.last_track = CDROM_LEADOUT;
  909. ms_tmp.hdr.first_track = ms_tmp.hdr.last_track;
  910. toc->last_session_lba = msf_to_lba(0, 2, 0); /* 0m 2s 0f */
  911. }
  912. if (drive->atapi_flags & IDE_AFLAG_TOCADDR_AS_BCD) {
  913. /* re-read multisession information using MSF format */
  914. stat = cdrom_read_tocentry(drive, 0, 1, 1, (char *)&ms_tmp,
  915. sizeof(ms_tmp), sense);
  916. if (stat)
  917. return stat;
  918. msf_from_bcd(&ms_tmp.ent.addr.msf);
  919. toc->last_session_lba = msf_to_lba(ms_tmp.ent.addr.msf.minute,
  920. ms_tmp.ent.addr.msf.second,
  921. ms_tmp.ent.addr.msf.frame);
  922. }
  923. toc->xa_flag = (ms_tmp.hdr.first_track != ms_tmp.hdr.last_track);
  924. /* now try to get the total cdrom capacity */
  925. stat = cdrom_get_last_written(cdi, &last_written);
  926. if (!stat && (last_written > toc->capacity)) {
  927. toc->capacity = last_written;
  928. set_capacity(info->disk, toc->capacity * sectors_per_frame);
  929. drive->probed_capacity = toc->capacity * sectors_per_frame;
  930. }
  931. /* Remember that we've read this stuff. */
  932. drive->atapi_flags |= IDE_AFLAG_TOC_VALID;
  933. return 0;
  934. }
  935. int ide_cdrom_get_capabilities(ide_drive_t *drive, u8 *buf)
  936. {
  937. struct cdrom_info *info = drive->driver_data;
  938. struct cdrom_device_info *cdi = &info->devinfo;
  939. struct packet_command cgc;
  940. int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE;
  941. ide_debug_log(IDE_DBG_FUNC, "enter");
  942. if ((drive->atapi_flags & IDE_AFLAG_FULL_CAPS_PAGE) == 0)
  943. size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE;
  944. init_cdrom_command(&cgc, buf, size, CGC_DATA_UNKNOWN);
  945. do {
  946. /* we seem to get stat=0x01,err=0x00 the first time (??) */
  947. stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CAPABILITIES_PAGE, 0);
  948. if (!stat)
  949. break;
  950. } while (--attempts);
  951. return stat;
  952. }
  953. void ide_cdrom_update_speed(ide_drive_t *drive, u8 *buf)
  954. {
  955. struct cdrom_info *cd = drive->driver_data;
  956. u16 curspeed, maxspeed;
  957. ide_debug_log(IDE_DBG_FUNC, "enter");
  958. if (drive->atapi_flags & IDE_AFLAG_LE_SPEED_FIELDS) {
  959. curspeed = le16_to_cpup((__le16 *)&buf[8 + 14]);
  960. maxspeed = le16_to_cpup((__le16 *)&buf[8 + 8]);
  961. } else {
  962. curspeed = be16_to_cpup((__be16 *)&buf[8 + 14]);
  963. maxspeed = be16_to_cpup((__be16 *)&buf[8 + 8]);
  964. }
  965. ide_debug_log(IDE_DBG_PROBE, "curspeed: %u, maxspeed: %u",
  966. curspeed, maxspeed);
  967. cd->current_speed = DIV_ROUND_CLOSEST(curspeed, 176);
  968. cd->max_speed = DIV_ROUND_CLOSEST(maxspeed, 176);
  969. }
  970. #define IDE_CD_CAPABILITIES \
  971. (CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | CDC_SELECT_SPEED | \
  972. CDC_SELECT_DISC | CDC_MULTI_SESSION | CDC_MCN | CDC_MEDIA_CHANGED | \
  973. CDC_PLAY_AUDIO | CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R | \
  974. CDC_CD_RW | CDC_DVD | CDC_DVD_R | CDC_DVD_RAM | CDC_GENERIC_PACKET | \
  975. CDC_MO_DRIVE | CDC_MRW | CDC_MRW_W | CDC_RAM)
  976. static struct cdrom_device_ops ide_cdrom_dops = {
  977. .open = ide_cdrom_open_real,
  978. .release = ide_cdrom_release_real,
  979. .drive_status = ide_cdrom_drive_status,
  980. .media_changed = ide_cdrom_check_media_change_real,
  981. .tray_move = ide_cdrom_tray_move,
  982. .lock_door = ide_cdrom_lock_door,
  983. .select_speed = ide_cdrom_select_speed,
  984. .get_last_session = ide_cdrom_get_last_session,
  985. .get_mcn = ide_cdrom_get_mcn,
  986. .reset = ide_cdrom_reset,
  987. .audio_ioctl = ide_cdrom_audio_ioctl,
  988. .capability = IDE_CD_CAPABILITIES,
  989. .generic_packet = ide_cdrom_packet,
  990. };
  991. static int ide_cdrom_register(ide_drive_t *drive, int nslots)
  992. {
  993. struct cdrom_info *info = drive->driver_data;
  994. struct cdrom_device_info *devinfo = &info->devinfo;
  995. ide_debug_log(IDE_DBG_PROBE, "nslots: %d", nslots);
  996. devinfo->ops = &ide_cdrom_dops;
  997. devinfo->speed = info->current_speed;
  998. devinfo->capacity = nslots;
  999. devinfo->handle = drive;
  1000. strcpy(devinfo->name, drive->name);
  1001. if (drive->atapi_flags & IDE_AFLAG_NO_SPEED_SELECT)
  1002. devinfo->mask |= CDC_SELECT_SPEED;
  1003. devinfo->disk = info->disk;
  1004. return register_cdrom(devinfo);
  1005. }
  1006. static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
  1007. {
  1008. struct cdrom_info *cd = drive->driver_data;
  1009. struct cdrom_device_info *cdi = &cd->devinfo;
  1010. u8 buf[ATAPI_CAPABILITIES_PAGE_SIZE];
  1011. mechtype_t mechtype;
  1012. int nslots = 1;
  1013. ide_debug_log(IDE_DBG_PROBE, "media: 0x%x, atapi_flags: 0x%lx",
  1014. drive->media, drive->atapi_flags);
  1015. cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R |
  1016. CDC_DVD_RAM | CDC_SELECT_DISC | CDC_PLAY_AUDIO |
  1017. CDC_MO_DRIVE | CDC_RAM);
  1018. if (drive->media == ide_optical) {
  1019. cdi->mask &= ~(CDC_MO_DRIVE | CDC_RAM);
  1020. printk(KERN_ERR PFX "%s: ATAPI magneto-optical drive\n",
  1021. drive->name);
  1022. return nslots;
  1023. }
  1024. if (drive->atapi_flags & IDE_AFLAG_PRE_ATAPI12) {
  1025. drive->atapi_flags &= ~IDE_AFLAG_NO_EJECT;
  1026. cdi->mask &= ~CDC_PLAY_AUDIO;
  1027. return nslots;
  1028. }
  1029. /*
  1030. * We have to cheat a little here. the packet will eventually be queued
  1031. * with ide_cdrom_packet(), which extracts the drive from cdi->handle.
  1032. * Since this device hasn't been registered with the Uniform layer yet,
  1033. * it can't do this. Same goes for cdi->ops.
  1034. */
  1035. cdi->handle = drive;
  1036. cdi->ops = &ide_cdrom_dops;
  1037. if (ide_cdrom_get_capabilities(drive, buf))
  1038. return 0;
  1039. if ((buf[8 + 6] & 0x01) == 0)
  1040. drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
  1041. if (buf[8 + 6] & 0x08)
  1042. drive->atapi_flags &= ~IDE_AFLAG_NO_EJECT;
  1043. if (buf[8 + 3] & 0x01)
  1044. cdi->mask &= ~CDC_CD_R;
  1045. if (buf[8 + 3] & 0x02)
  1046. cdi->mask &= ~(CDC_CD_RW | CDC_RAM);
  1047. if (buf[8 + 2] & 0x38)
  1048. cdi->mask &= ~CDC_DVD;
  1049. if (buf[8 + 3] & 0x20)
  1050. cdi->mask &= ~(CDC_DVD_RAM | CDC_RAM);
  1051. if (buf[8 + 3] & 0x10)
  1052. cdi->mask &= ~CDC_DVD_R;
  1053. if ((buf[8 + 4] & 0x01) || (drive->atapi_flags & IDE_AFLAG_PLAY_AUDIO_OK))
  1054. cdi->mask &= ~CDC_PLAY_AUDIO;
  1055. mechtype = buf[8 + 6] >> 5;
  1056. if (mechtype == mechtype_caddy ||
  1057. mechtype == mechtype_popup ||
  1058. (drive->atapi_flags & IDE_AFLAG_NO_AUTOCLOSE))
  1059. cdi->mask |= CDC_CLOSE_TRAY;
  1060. if (cdi->sanyo_slot > 0) {
  1061. cdi->mask &= ~CDC_SELECT_DISC;
  1062. nslots = 3;
  1063. } else if (mechtype == mechtype_individual_changer ||
  1064. mechtype == mechtype_cartridge_changer) {
  1065. nslots = cdrom_number_of_slots(cdi);
  1066. if (nslots > 1)
  1067. cdi->mask &= ~CDC_SELECT_DISC;
  1068. }
  1069. ide_cdrom_update_speed(drive, buf);
  1070. printk(KERN_INFO PFX "%s: ATAPI", drive->name);
  1071. /* don't print speed if the drive reported 0 */
  1072. if (cd->max_speed)
  1073. printk(KERN_CONT " %dX", cd->max_speed);
  1074. printk(KERN_CONT " %s", (cdi->mask & CDC_DVD) ? "CD-ROM" : "DVD-ROM");
  1075. if ((cdi->mask & CDC_DVD_R) == 0 || (cdi->mask & CDC_DVD_RAM) == 0)
  1076. printk(KERN_CONT " DVD%s%s",
  1077. (cdi->mask & CDC_DVD_R) ? "" : "-R",
  1078. (cdi->mask & CDC_DVD_RAM) ? "" : "/RAM");
  1079. if ((cdi->mask & CDC_CD_R) == 0 || (cdi->mask & CDC_CD_RW) == 0)
  1080. printk(KERN_CONT " CD%s%s",
  1081. (cdi->mask & CDC_CD_R) ? "" : "-R",
  1082. (cdi->mask & CDC_CD_RW) ? "" : "/RW");
  1083. if ((cdi->mask & CDC_SELECT_DISC) == 0)
  1084. printk(KERN_CONT " changer w/%d slots", nslots);
  1085. else
  1086. printk(KERN_CONT " drive");
  1087. printk(KERN_CONT ", %dkB Cache\n",
  1088. be16_to_cpup((__be16 *)&buf[8 + 12]));
  1089. return nslots;
  1090. }
  1091. /* standard prep_rq_fn that builds 10 byte cmds */
  1092. static int ide_cdrom_prep_fs(struct request_queue *q, struct request *rq)
  1093. {
  1094. int hard_sect = queue_logical_block_size(q);
  1095. long block = (long)blk_rq_pos(rq) / (hard_sect >> 9);
  1096. unsigned long blocks = blk_rq_sectors(rq) / (hard_sect >> 9);
  1097. memset(rq->cmd, 0, BLK_MAX_CDB);
  1098. if (rq_data_dir(rq) == READ)
  1099. rq->cmd[0] = GPCMD_READ_10;
  1100. else
  1101. rq->cmd[0] = GPCMD_WRITE_10;
  1102. /*
  1103. * fill in lba
  1104. */
  1105. rq->cmd[2] = (block >> 24) & 0xff;
  1106. rq->cmd[3] = (block >> 16) & 0xff;
  1107. rq->cmd[4] = (block >> 8) & 0xff;
  1108. rq->cmd[5] = block & 0xff;
  1109. /*
  1110. * and transfer length
  1111. */
  1112. rq->cmd[7] = (blocks >> 8) & 0xff;
  1113. rq->cmd[8] = blocks & 0xff;
  1114. rq->cmd_len = 10;
  1115. return BLKPREP_OK;
  1116. }
  1117. /*
  1118. * Most of the SCSI commands are supported directly by ATAPI devices.
  1119. * This transform handles the few exceptions.
  1120. */
  1121. static int ide_cdrom_prep_pc(struct request *rq)
  1122. {
  1123. u8 *c = rq->cmd;
  1124. /* transform 6-byte read/write commands to the 10-byte version */
  1125. if (c[0] == READ_6 || c[0] == WRITE_6) {
  1126. c[8] = c[4];
  1127. c[5] = c[3];
  1128. c[4] = c[2];
  1129. c[3] = c[1] & 0x1f;
  1130. c[2] = 0;
  1131. c[1] &= 0xe0;
  1132. c[0] += (READ_10 - READ_6);
  1133. rq->cmd_len = 10;
  1134. return BLKPREP_OK;
  1135. }
  1136. /*
  1137. * it's silly to pretend we understand 6-byte sense commands, just
  1138. * reject with ILLEGAL_REQUEST and the caller should take the
  1139. * appropriate action
  1140. */
  1141. if (c[0] == MODE_SENSE || c[0] == MODE_SELECT) {
  1142. rq->errors = ILLEGAL_REQUEST;
  1143. return BLKPREP_KILL;
  1144. }
  1145. return BLKPREP_OK;
  1146. }
  1147. static int ide_cdrom_prep_fn(struct request_queue *q, struct request *rq)
  1148. {
  1149. if (rq->cmd_type == REQ_TYPE_FS)
  1150. return ide_cdrom_prep_fs(q, rq);
  1151. else if (rq->cmd_type == REQ_TYPE_BLOCK_PC)
  1152. return ide_cdrom_prep_pc(rq);
  1153. return 0;
  1154. }
  1155. struct cd_list_entry {
  1156. const char *id_model;
  1157. const char *id_firmware;
  1158. unsigned int cd_flags;
  1159. };
  1160. #ifdef CONFIG_IDE_PROC_FS
  1161. static sector_t ide_cdrom_capacity(ide_drive_t *drive)
  1162. {
  1163. unsigned long capacity, sectors_per_frame;
  1164. if (cdrom_read_capacity(drive, &capacity, &sectors_per_frame, NULL))
  1165. return 0;
  1166. return capacity * sectors_per_frame;
  1167. }
  1168. static int idecd_capacity_proc_show(struct seq_file *m, void *v)
  1169. {
  1170. ide_drive_t *drive = m->private;
  1171. seq_printf(m, "%llu\n", (long long)ide_cdrom_capacity(drive));
  1172. return 0;
  1173. }
  1174. static int idecd_capacity_proc_open(struct inode *inode, struct file *file)
  1175. {
  1176. return single_open(file, idecd_capacity_proc_show, PDE(inode)->data);
  1177. }
  1178. static const struct file_operations idecd_capacity_proc_fops = {
  1179. .owner = THIS_MODULE,
  1180. .open = idecd_capacity_proc_open,
  1181. .read = seq_read,
  1182. .llseek = seq_lseek,
  1183. .release = single_release,
  1184. };
  1185. static ide_proc_entry_t idecd_proc[] = {
  1186. { "capacity", S_IFREG|S_IRUGO, &idecd_capacity_proc_fops },
  1187. {}
  1188. };
  1189. static ide_proc_entry_t *ide_cd_proc_entries(ide_drive_t *drive)
  1190. {
  1191. return idecd_proc;
  1192. }
  1193. static const struct ide_proc_devset *ide_cd_proc_devsets(ide_drive_t *drive)
  1194. {
  1195. return NULL;
  1196. }
  1197. #endif
  1198. static const struct cd_list_entry ide_cd_quirks_list[] = {
  1199. /* SCR-3231 doesn't support the SET_CD_SPEED command. */
  1200. { "SAMSUNG CD-ROM SCR-3231", NULL, IDE_AFLAG_NO_SPEED_SELECT },
  1201. /* Old NEC260 (not R) was released before ATAPI 1.2 spec. */
  1202. { "NEC CD-ROM DRIVE:260", "1.01", IDE_AFLAG_TOCADDR_AS_BCD |
  1203. IDE_AFLAG_PRE_ATAPI12, },
  1204. /* Vertos 300, some versions of this drive like to talk BCD. */
  1205. { "V003S0DS", NULL, IDE_AFLAG_VERTOS_300_SSD, },
  1206. /* Vertos 600 ESD. */
  1207. { "V006E0DS", NULL, IDE_AFLAG_VERTOS_600_ESD, },
  1208. /*
  1209. * Sanyo 3 CD changer uses a non-standard command for CD changing
  1210. * (by default standard ATAPI support for CD changers is used).
  1211. */
  1212. { "CD-ROM CDR-C3 G", NULL, IDE_AFLAG_SANYO_3CD },
  1213. { "CD-ROM CDR-C3G", NULL, IDE_AFLAG_SANYO_3CD },
  1214. { "CD-ROM CDR_C36", NULL, IDE_AFLAG_SANYO_3CD },
  1215. /* Stingray 8X CD-ROM. */
  1216. { "STINGRAY 8422 IDE 8X CD-ROM 7-27-95", NULL, IDE_AFLAG_PRE_ATAPI12 },
  1217. /*
  1218. * ACER 50X CD-ROM and WPI 32X CD-ROM require the full spec length
  1219. * mode sense page capabilities size, but older drives break.
  1220. */
  1221. { "ATAPI CD ROM DRIVE 50X MAX", NULL, IDE_AFLAG_FULL_CAPS_PAGE },
  1222. { "WPI CDS-32X", NULL, IDE_AFLAG_FULL_CAPS_PAGE },
  1223. /* ACER/AOpen 24X CD-ROM has the speed fields byte-swapped. */
  1224. { "", "241N", IDE_AFLAG_LE_SPEED_FIELDS },
  1225. /*
  1226. * Some drives used by Apple don't advertise audio play
  1227. * but they do support reading TOC & audio datas.
  1228. */
  1229. { "MATSHITADVD-ROM SR-8187", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
  1230. { "MATSHITADVD-ROM SR-8186", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
  1231. { "MATSHITADVD-ROM SR-8176", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
  1232. { "MATSHITADVD-ROM SR-8174", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
  1233. { "Optiarc DVD RW AD-5200A", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
  1234. { "Optiarc DVD RW AD-7200A", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
  1235. { "Optiarc DVD RW AD-7543A", NULL, IDE_AFLAG_NO_AUTOCLOSE },
  1236. { "TEAC CD-ROM CD-224E", NULL, IDE_AFLAG_NO_AUTOCLOSE },
  1237. { NULL, NULL, 0 }
  1238. };
  1239. static unsigned int ide_cd_flags(u16 *id)
  1240. {
  1241. const struct cd_list_entry *cle = ide_cd_quirks_list;
  1242. while (cle->id_model) {
  1243. if (strcmp(cle->id_model, (char *)&id[ATA_ID_PROD]) == 0 &&
  1244. (cle->id_firmware == NULL ||
  1245. strstr((char *)&id[ATA_ID_FW_REV], cle->id_firmware)))
  1246. return cle->cd_flags;
  1247. cle++;
  1248. }
  1249. return 0;
  1250. }
  1251. static int ide_cdrom_setup(ide_drive_t *drive)
  1252. {
  1253. struct cdrom_info *cd = drive->driver_data;
  1254. struct cdrom_device_info *cdi = &cd->devinfo;
  1255. struct request_queue *q = drive->queue;
  1256. u16 *id = drive->id;
  1257. char *fw_rev = (char *)&id[ATA_ID_FW_REV];
  1258. int nslots;
  1259. ide_debug_log(IDE_DBG_PROBE, "enter");
  1260. blk_queue_prep_rq(q, ide_cdrom_prep_fn);
  1261. blk_queue_dma_alignment(q, 31);
  1262. blk_queue_update_dma_pad(q, 15);
  1263. q->unplug_delay = max((1 * HZ) / 1000, 1);
  1264. drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
  1265. drive->atapi_flags = IDE_AFLAG_NO_EJECT | ide_cd_flags(id);
  1266. if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) &&
  1267. fw_rev[4] == '1' && fw_rev[6] <= '2')
  1268. drive->atapi_flags |= (IDE_AFLAG_TOCTRACKS_AS_BCD |
  1269. IDE_AFLAG_TOCADDR_AS_BCD);
  1270. else if ((drive->atapi_flags & IDE_AFLAG_VERTOS_600_ESD) &&
  1271. fw_rev[4] == '1' && fw_rev[6] <= '2')
  1272. drive->atapi_flags |= IDE_AFLAG_TOCTRACKS_AS_BCD;
  1273. else if (drive->atapi_flags & IDE_AFLAG_SANYO_3CD)
  1274. /* 3 => use CD in slot 0 */
  1275. cdi->sanyo_slot = 3;
  1276. nslots = ide_cdrom_probe_capabilities(drive);
  1277. blk_queue_logical_block_size(q, CD_FRAMESIZE);
  1278. if (ide_cdrom_register(drive, nslots)) {
  1279. printk(KERN_ERR PFX "%s: %s failed to register device with the"
  1280. " cdrom driver.\n", drive->name, __func__);
  1281. cd->devinfo.handle = NULL;
  1282. return 1;
  1283. }
  1284. ide_proc_register_driver(drive, cd->driver);
  1285. return 0;
  1286. }
  1287. static void ide_cd_remove(ide_drive_t *drive)
  1288. {
  1289. struct cdrom_info *info = drive->driver_data;
  1290. ide_debug_log(IDE_DBG_FUNC, "enter");
  1291. ide_proc_unregister_driver(drive, info->driver);
  1292. device_del(&info->dev);
  1293. del_gendisk(info->disk);
  1294. mutex_lock(&idecd_ref_mutex);
  1295. put_device(&info->dev);
  1296. mutex_unlock(&idecd_ref_mutex);
  1297. }
  1298. static void ide_cd_release(struct device *dev)
  1299. {
  1300. struct cdrom_info *info = to_ide_drv(dev, cdrom_info);
  1301. struct cdrom_device_info *devinfo = &info->devinfo;
  1302. ide_drive_t *drive = info->drive;
  1303. struct gendisk *g = info->disk;
  1304. ide_debug_log(IDE_DBG_FUNC, "enter");
  1305. kfree(info->toc);
  1306. if (devinfo->handle == drive)
  1307. unregister_cdrom(devinfo);
  1308. drive->driver_data = NULL;
  1309. blk_queue_prep_rq(drive->queue, NULL);
  1310. g->private_data = NULL;
  1311. put_disk(g);
  1312. kfree(info);
  1313. }
  1314. static int ide_cd_probe(ide_drive_t *);
  1315. static struct ide_driver ide_cdrom_driver = {
  1316. .gen_driver = {
  1317. .owner = THIS_MODULE,
  1318. .name = "ide-cdrom",
  1319. .bus = &ide_bus_type,
  1320. },
  1321. .probe = ide_cd_probe,
  1322. .remove = ide_cd_remove,
  1323. .version = IDECD_VERSION,
  1324. .do_request = ide_cd_do_request,
  1325. #ifdef CONFIG_IDE_PROC_FS
  1326. .proc_entries = ide_cd_proc_entries,
  1327. .proc_devsets = ide_cd_proc_devsets,
  1328. #endif
  1329. };
  1330. static int idecd_open(struct block_device *bdev, fmode_t mode)
  1331. {
  1332. struct cdrom_info *info = ide_cd_get(bdev->bd_disk);
  1333. int rc = -ENOMEM;
  1334. if (!info)
  1335. return -ENXIO;
  1336. rc = cdrom_open(&info->devinfo, bdev, mode);
  1337. if (rc < 0)
  1338. ide_cd_put(info);
  1339. return rc;
  1340. }
  1341. static int idecd_release(struct gendisk *disk, fmode_t mode)
  1342. {
  1343. struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
  1344. cdrom_release(&info->devinfo, mode);
  1345. ide_cd_put(info);
  1346. return 0;
  1347. }
  1348. static int idecd_set_spindown(struct cdrom_device_info *cdi, unsigned long arg)
  1349. {
  1350. struct packet_command cgc;
  1351. char buffer[16];
  1352. int stat;
  1353. char spindown;
  1354. if (copy_from_user(&spindown, (void __user *)arg, sizeof(char)))
  1355. return -EFAULT;
  1356. init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN);
  1357. stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0);
  1358. if (stat)
  1359. return stat;
  1360. buffer[11] = (buffer[11] & 0xf0) | (spindown & 0x0f);
  1361. return cdrom_mode_select(cdi, &cgc);
  1362. }
  1363. static int idecd_get_spindown(struct cdrom_device_info *cdi, unsigned long arg)
  1364. {
  1365. struct packet_command cgc;
  1366. char buffer[16];
  1367. int stat;
  1368. char spindown;
  1369. init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN);
  1370. stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0);
  1371. if (stat)
  1372. return stat;
  1373. spindown = buffer[11] & 0x0f;
  1374. if (copy_to_user((void __user *)arg, &spindown, sizeof(char)))
  1375. return -EFAULT;
  1376. return 0;
  1377. }
  1378. static int idecd_ioctl(struct block_device *bdev, fmode_t mode,
  1379. unsigned int cmd, unsigned long arg)
  1380. {
  1381. struct cdrom_info *info = ide_drv_g(bdev->bd_disk, cdrom_info);
  1382. int err;
  1383. switch (cmd) {
  1384. case CDROMSETSPINDOWN:
  1385. return idecd_set_spindown(&info->devinfo, arg);
  1386. case CDROMGETSPINDOWN:
  1387. return idecd_get_spindown(&info->devinfo, arg);
  1388. default:
  1389. break;
  1390. }
  1391. err = generic_ide_ioctl(info->drive, bdev, cmd, arg);
  1392. if (err == -EINVAL)
  1393. err = cdrom_ioctl(&info->devinfo, bdev, mode, cmd, arg);
  1394. return err;
  1395. }
  1396. static int idecd_media_changed(struct gendisk *disk)
  1397. {
  1398. struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
  1399. return cdrom_media_changed(&info->devinfo);
  1400. }
  1401. static int idecd_revalidate_disk(struct gendisk *disk)
  1402. {
  1403. struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
  1404. struct request_sense sense;
  1405. ide_cd_read_toc(info->drive, &sense);
  1406. return 0;
  1407. }
  1408. static const struct block_device_operations idecd_ops = {
  1409. .owner = THIS_MODULE,
  1410. .open = idecd_open,
  1411. .release = idecd_release,
  1412. .locked_ioctl = idecd_ioctl,
  1413. .media_changed = idecd_media_changed,
  1414. .revalidate_disk = idecd_revalidate_disk
  1415. };
  1416. /* module options */
  1417. static unsigned long debug_mask;
  1418. module_param(debug_mask, ulong, 0644);
  1419. MODULE_DESCRIPTION("ATAPI CD-ROM Driver");
  1420. static int ide_cd_probe(ide_drive_t *drive)
  1421. {
  1422. struct cdrom_info *info;
  1423. struct gendisk *g;
  1424. struct request_sense sense;
  1425. ide_debug_log(IDE_DBG_PROBE, "driver_req: %s, media: 0x%x",
  1426. drive->driver_req, drive->media);
  1427. if (!strstr("ide-cdrom", drive->driver_req))
  1428. goto failed;
  1429. if (drive->media != ide_cdrom && drive->media != ide_optical)
  1430. goto failed;
  1431. drive->debug_mask = debug_mask;
  1432. drive->irq_handler = cdrom_newpc_intr;
  1433. info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL);
  1434. if (info == NULL) {
  1435. printk(KERN_ERR PFX "%s: Can't allocate a cdrom structure\n",
  1436. drive->name);
  1437. goto failed;
  1438. }
  1439. g = alloc_disk(1 << PARTN_BITS);
  1440. if (!g)
  1441. goto out_free_cd;
  1442. ide_init_disk(g, drive);
  1443. info->dev.parent = &drive->gendev;
  1444. info->dev.release = ide_cd_release;
  1445. dev_set_name(&info->dev, dev_name(&drive->gendev));
  1446. if (device_register(&info->dev))
  1447. goto out_free_disk;
  1448. info->drive = drive;
  1449. info->driver = &ide_cdrom_driver;
  1450. info->disk = g;
  1451. g->private_data = &info->driver;
  1452. drive->driver_data = info;
  1453. g->minors = 1;
  1454. g->driverfs_dev = &drive->gendev;
  1455. g->flags = GENHD_FL_CD | GENHD_FL_REMOVABLE;
  1456. if (ide_cdrom_setup(drive)) {
  1457. put_device(&info->dev);
  1458. goto failed;
  1459. }
  1460. ide_cd_read_toc(drive, &sense);
  1461. g->fops = &idecd_ops;
  1462. g->flags |= GENHD_FL_REMOVABLE;
  1463. add_disk(g);
  1464. return 0;
  1465. out_free_disk:
  1466. put_disk(g);
  1467. out_free_cd:
  1468. kfree(info);
  1469. failed:
  1470. return -ENODEV;
  1471. }
  1472. static void __exit ide_cdrom_exit(void)
  1473. {
  1474. driver_unregister(&ide_cdrom_driver.gen_driver);
  1475. }
  1476. static int __init ide_cdrom_init(void)
  1477. {
  1478. printk(KERN_INFO DRV_NAME " driver " IDECD_VERSION "\n");
  1479. return driver_register(&ide_cdrom_driver.gen_driver);
  1480. }
  1481. MODULE_ALIAS("ide:*m-cdrom*");
  1482. MODULE_ALIAS("ide-cd");
  1483. module_init(ide_cdrom_init);
  1484. module_exit(ide_cdrom_exit);
  1485. MODULE_LICENSE("GPL");