sr_ioctl.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. #include <linux/kernel.h>
  2. #include <linux/mm.h>
  3. #include <linux/fs.h>
  4. #include <linux/errno.h>
  5. #include <linux/string.h>
  6. #include <linux/blkdev.h>
  7. #include <linux/blkpg.h>
  8. #include <linux/cdrom.h>
  9. #include <linux/delay.h>
  10. #include <linux/slab.h>
  11. #include <asm/io.h>
  12. #include <asm/uaccess.h>
  13. #include <scsi/scsi.h>
  14. #include <scsi/scsi_dbg.h>
  15. #include <scsi/scsi_device.h>
  16. #include <scsi/scsi_eh.h>
  17. #include <scsi/scsi_host.h>
  18. #include <scsi/scsi_ioctl.h>
  19. #include <scsi/scsi_cmnd.h>
  20. #include "sr.h"
  21. #if 0
  22. #define DEBUG
  23. #endif
  24. /* The sr_is_xa() seems to trigger firmware bugs with some drives :-(
  25. * It is off by default and can be turned on with this module parameter */
  26. static int xa_test = 0;
  27. module_param(xa_test, int, S_IRUGO | S_IWUSR);
  28. /* primitive to determine whether we need to have GFP_DMA set based on
  29. * the status of the unchecked_isa_dma flag in the host structure */
  30. #define SR_GFP_DMA(cd) (((cd)->device->host->unchecked_isa_dma) ? GFP_DMA : 0)
  31. static int sr_read_tochdr(struct cdrom_device_info *cdi,
  32. struct cdrom_tochdr *tochdr)
  33. {
  34. struct scsi_cd *cd = cdi->handle;
  35. struct packet_command cgc;
  36. int result;
  37. unsigned char *buffer;
  38. buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
  39. if (!buffer)
  40. return -ENOMEM;
  41. memset(&cgc, 0, sizeof(struct packet_command));
  42. cgc.timeout = IOCTL_TIMEOUT;
  43. cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
  44. cgc.cmd[8] = 12; /* LSB of length */
  45. cgc.buffer = buffer;
  46. cgc.buflen = 12;
  47. cgc.quiet = 1;
  48. cgc.data_direction = DMA_FROM_DEVICE;
  49. result = sr_do_ioctl(cd, &cgc);
  50. tochdr->cdth_trk0 = buffer[2];
  51. tochdr->cdth_trk1 = buffer[3];
  52. kfree(buffer);
  53. return result;
  54. }
  55. static int sr_read_tocentry(struct cdrom_device_info *cdi,
  56. struct cdrom_tocentry *tocentry)
  57. {
  58. struct scsi_cd *cd = cdi->handle;
  59. struct packet_command cgc;
  60. int result;
  61. unsigned char *buffer;
  62. buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
  63. if (!buffer)
  64. return -ENOMEM;
  65. memset(&cgc, 0, sizeof(struct packet_command));
  66. cgc.timeout = IOCTL_TIMEOUT;
  67. cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
  68. cgc.cmd[1] |= (tocentry->cdte_format == CDROM_MSF) ? 0x02 : 0;
  69. cgc.cmd[6] = tocentry->cdte_track;
  70. cgc.cmd[8] = 12; /* LSB of length */
  71. cgc.buffer = buffer;
  72. cgc.buflen = 12;
  73. cgc.data_direction = DMA_FROM_DEVICE;
  74. result = sr_do_ioctl(cd, &cgc);
  75. tocentry->cdte_ctrl = buffer[5] & 0xf;
  76. tocentry->cdte_adr = buffer[5] >> 4;
  77. tocentry->cdte_datamode = (tocentry->cdte_ctrl & 0x04) ? 1 : 0;
  78. if (tocentry->cdte_format == CDROM_MSF) {
  79. tocentry->cdte_addr.msf.minute = buffer[9];
  80. tocentry->cdte_addr.msf.second = buffer[10];
  81. tocentry->cdte_addr.msf.frame = buffer[11];
  82. } else
  83. tocentry->cdte_addr.lba = (((((buffer[8] << 8) + buffer[9]) << 8)
  84. + buffer[10]) << 8) + buffer[11];
  85. kfree(buffer);
  86. return result;
  87. }
  88. #define IOCTL_RETRIES 3
  89. /* ATAPI drives don't have a SCMD_PLAYAUDIO_TI command. When these drives
  90. are emulating a SCSI device via the idescsi module, they need to have
  91. CDROMPLAYTRKIND commands translated into CDROMPLAYMSF commands for them */
  92. static int sr_fake_playtrkind(struct cdrom_device_info *cdi, struct cdrom_ti *ti)
  93. {
  94. struct cdrom_tocentry trk0_te, trk1_te;
  95. struct cdrom_tochdr tochdr;
  96. struct packet_command cgc;
  97. int ntracks, ret;
  98. ret = sr_read_tochdr(cdi, &tochdr);
  99. if (ret)
  100. return ret;
  101. ntracks = tochdr.cdth_trk1 - tochdr.cdth_trk0 + 1;
  102. if (ti->cdti_trk1 == ntracks)
  103. ti->cdti_trk1 = CDROM_LEADOUT;
  104. else if (ti->cdti_trk1 != CDROM_LEADOUT)
  105. ti->cdti_trk1 ++;
  106. trk0_te.cdte_track = ti->cdti_trk0;
  107. trk0_te.cdte_format = CDROM_MSF;
  108. trk1_te.cdte_track = ti->cdti_trk1;
  109. trk1_te.cdte_format = CDROM_MSF;
  110. ret = sr_read_tocentry(cdi, &trk0_te);
  111. if (ret)
  112. return ret;
  113. ret = sr_read_tocentry(cdi, &trk1_te);
  114. if (ret)
  115. return ret;
  116. memset(&cgc, 0, sizeof(struct packet_command));
  117. cgc.cmd[0] = GPCMD_PLAY_AUDIO_MSF;
  118. cgc.cmd[3] = trk0_te.cdte_addr.msf.minute;
  119. cgc.cmd[4] = trk0_te.cdte_addr.msf.second;
  120. cgc.cmd[5] = trk0_te.cdte_addr.msf.frame;
  121. cgc.cmd[6] = trk1_te.cdte_addr.msf.minute;
  122. cgc.cmd[7] = trk1_te.cdte_addr.msf.second;
  123. cgc.cmd[8] = trk1_te.cdte_addr.msf.frame;
  124. cgc.data_direction = DMA_NONE;
  125. cgc.timeout = IOCTL_TIMEOUT;
  126. return sr_do_ioctl(cdi->handle, &cgc);
  127. }
  128. static int sr_play_trkind(struct cdrom_device_info *cdi,
  129. struct cdrom_ti *ti)
  130. {
  131. struct scsi_cd *cd = cdi->handle;
  132. struct packet_command cgc;
  133. int result;
  134. memset(&cgc, 0, sizeof(struct packet_command));
  135. cgc.timeout = IOCTL_TIMEOUT;
  136. cgc.cmd[0] = GPCMD_PLAYAUDIO_TI;
  137. cgc.cmd[4] = ti->cdti_trk0;
  138. cgc.cmd[5] = ti->cdti_ind0;
  139. cgc.cmd[7] = ti->cdti_trk1;
  140. cgc.cmd[8] = ti->cdti_ind1;
  141. cgc.data_direction = DMA_NONE;
  142. result = sr_do_ioctl(cd, &cgc);
  143. if (result == -EDRIVE_CANT_DO_THIS)
  144. result = sr_fake_playtrkind(cdi, ti);
  145. return result;
  146. }
  147. /* We do our own retries because we want to know what the specific
  148. error code is. Normally the UNIT_ATTENTION code will automatically
  149. clear after one error */
  150. int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
  151. {
  152. struct scsi_device *SDev;
  153. struct scsi_sense_hdr sshdr;
  154. int result, err = 0, retries = 0;
  155. struct request_sense *sense = cgc->sense;
  156. SDev = cd->device;
  157. if (!sense) {
  158. sense = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
  159. if (!sense) {
  160. err = -ENOMEM;
  161. goto out;
  162. }
  163. }
  164. retry:
  165. if (!scsi_block_when_processing_errors(SDev)) {
  166. err = -ENODEV;
  167. goto out;
  168. }
  169. memset(sense, 0, sizeof(*sense));
  170. result = scsi_execute(SDev, cgc->cmd, cgc->data_direction,
  171. cgc->buffer, cgc->buflen, (char *)sense,
  172. cgc->timeout, IOCTL_RETRIES, 0, NULL);
  173. scsi_normalize_sense((char *)sense, sizeof(*sense), &sshdr);
  174. /* Minimal error checking. Ignore cases we know about, and report the rest. */
  175. if (driver_byte(result) != 0) {
  176. switch (sshdr.sense_key) {
  177. case UNIT_ATTENTION:
  178. SDev->changed = 1;
  179. if (!cgc->quiet)
  180. printk(KERN_INFO "%s: disc change detected.\n", cd->cdi.name);
  181. if (retries++ < 10)
  182. goto retry;
  183. err = -ENOMEDIUM;
  184. break;
  185. case NOT_READY: /* This happens if there is no disc in drive */
  186. if (sshdr.asc == 0x04 &&
  187. sshdr.ascq == 0x01) {
  188. /* sense: Logical unit is in process of becoming ready */
  189. if (!cgc->quiet)
  190. printk(KERN_INFO "%s: CDROM not ready yet.\n", cd->cdi.name);
  191. if (retries++ < 10) {
  192. /* sleep 2 sec and try again */
  193. ssleep(2);
  194. goto retry;
  195. } else {
  196. /* 20 secs are enough? */
  197. err = -ENOMEDIUM;
  198. break;
  199. }
  200. }
  201. if (!cgc->quiet)
  202. printk(KERN_INFO "%s: CDROM not ready. Make sure there is a disc in the drive.\n", cd->cdi.name);
  203. #ifdef DEBUG
  204. scsi_print_sense_hdr("sr", &sshdr);
  205. #endif
  206. err = -ENOMEDIUM;
  207. break;
  208. case ILLEGAL_REQUEST:
  209. err = -EIO;
  210. if (sshdr.asc == 0x20 &&
  211. sshdr.ascq == 0x00)
  212. /* sense: Invalid command operation code */
  213. err = -EDRIVE_CANT_DO_THIS;
  214. #ifdef DEBUG
  215. __scsi_print_command(cgc->cmd);
  216. scsi_print_sense_hdr("sr", &sshdr);
  217. #endif
  218. break;
  219. default:
  220. printk(KERN_ERR "%s: CDROM (ioctl) error, command: ", cd->cdi.name);
  221. __scsi_print_command(cgc->cmd);
  222. scsi_print_sense_hdr("sr", &sshdr);
  223. err = -EIO;
  224. }
  225. }
  226. /* Wake up a process waiting for device */
  227. out:
  228. if (!cgc->sense)
  229. kfree(sense);
  230. cgc->stat = err;
  231. return err;
  232. }
  233. /* ---------------------------------------------------------------------- */
  234. /* interface to cdrom.c */
  235. int sr_tray_move(struct cdrom_device_info *cdi, int pos)
  236. {
  237. Scsi_CD *cd = cdi->handle;
  238. struct packet_command cgc;
  239. memset(&cgc, 0, sizeof(struct packet_command));
  240. cgc.cmd[0] = GPCMD_START_STOP_UNIT;
  241. cgc.cmd[4] = (pos == 0) ? 0x03 /* close */ : 0x02 /* eject */ ;
  242. cgc.data_direction = DMA_NONE;
  243. cgc.timeout = IOCTL_TIMEOUT;
  244. return sr_do_ioctl(cd, &cgc);
  245. }
  246. int sr_lock_door(struct cdrom_device_info *cdi, int lock)
  247. {
  248. Scsi_CD *cd = cdi->handle;
  249. return scsi_set_medium_removal(cd->device, lock ?
  250. SCSI_REMOVAL_PREVENT : SCSI_REMOVAL_ALLOW);
  251. }
  252. int sr_drive_status(struct cdrom_device_info *cdi, int slot)
  253. {
  254. struct scsi_cd *cd = cdi->handle;
  255. struct scsi_sense_hdr sshdr;
  256. struct media_event_desc med;
  257. if (CDSL_CURRENT != slot) {
  258. /* we have no changer support */
  259. return -EINVAL;
  260. }
  261. if (!scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr))
  262. return CDS_DISC_OK;
  263. /* SK/ASC/ASCQ of 2/4/1 means "unit is becoming ready" */
  264. if (scsi_sense_valid(&sshdr) && sshdr.sense_key == NOT_READY
  265. && sshdr.asc == 0x04 && sshdr.ascq == 0x01)
  266. return CDS_DRIVE_NOT_READY;
  267. if (!cdrom_get_media_event(cdi, &med)) {
  268. if (med.media_present)
  269. return CDS_DISC_OK;
  270. else if (med.door_open)
  271. return CDS_TRAY_OPEN;
  272. else
  273. return CDS_NO_DISC;
  274. }
  275. /*
  276. * SK/ASC/ASCQ of 2/4/2 means "initialization required"
  277. * Using CD_TRAY_OPEN results in an START_STOP_UNIT to close
  278. * the tray, which resolves the initialization requirement.
  279. */
  280. if (scsi_sense_valid(&sshdr) && sshdr.sense_key == NOT_READY
  281. && sshdr.asc == 0x04 && sshdr.ascq == 0x02)
  282. return CDS_TRAY_OPEN;
  283. /*
  284. * 0x04 is format in progress .. but there must be a disc present!
  285. */
  286. if (sshdr.sense_key == NOT_READY && sshdr.asc == 0x04)
  287. return CDS_DISC_OK;
  288. /*
  289. * If not using Mt Fuji extended media tray reports,
  290. * just return TRAY_OPEN since ATAPI doesn't provide
  291. * any other way to detect this...
  292. */
  293. if (scsi_sense_valid(&sshdr) &&
  294. /* 0x3a is medium not present */
  295. sshdr.asc == 0x3a)
  296. return CDS_NO_DISC;
  297. else
  298. return CDS_TRAY_OPEN;
  299. return CDS_DRIVE_NOT_READY;
  300. }
  301. int sr_disk_status(struct cdrom_device_info *cdi)
  302. {
  303. Scsi_CD *cd = cdi->handle;
  304. struct cdrom_tochdr toc_h;
  305. struct cdrom_tocentry toc_e;
  306. int i, rc, have_datatracks = 0;
  307. /* look for data tracks */
  308. rc = sr_read_tochdr(cdi, &toc_h);
  309. if (rc)
  310. return (rc == -ENOMEDIUM) ? CDS_NO_DISC : CDS_NO_INFO;
  311. for (i = toc_h.cdth_trk0; i <= toc_h.cdth_trk1; i++) {
  312. toc_e.cdte_track = i;
  313. toc_e.cdte_format = CDROM_LBA;
  314. if (sr_read_tocentry(cdi, &toc_e))
  315. return CDS_NO_INFO;
  316. if (toc_e.cdte_ctrl & CDROM_DATA_TRACK) {
  317. have_datatracks = 1;
  318. break;
  319. }
  320. }
  321. if (!have_datatracks)
  322. return CDS_AUDIO;
  323. if (cd->xa_flag)
  324. return CDS_XA_2_1;
  325. else
  326. return CDS_DATA_1;
  327. }
  328. int sr_get_last_session(struct cdrom_device_info *cdi,
  329. struct cdrom_multisession *ms_info)
  330. {
  331. Scsi_CD *cd = cdi->handle;
  332. ms_info->addr.lba = cd->ms_offset;
  333. ms_info->xa_flag = cd->xa_flag || cd->ms_offset > 0;
  334. return 0;
  335. }
  336. int sr_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
  337. {
  338. Scsi_CD *cd = cdi->handle;
  339. struct packet_command cgc;
  340. char *buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
  341. int result;
  342. if (!buffer)
  343. return -ENOMEM;
  344. memset(&cgc, 0, sizeof(struct packet_command));
  345. cgc.cmd[0] = GPCMD_READ_SUBCHANNEL;
  346. cgc.cmd[2] = 0x40; /* I do want the subchannel info */
  347. cgc.cmd[3] = 0x02; /* Give me medium catalog number info */
  348. cgc.cmd[8] = 24;
  349. cgc.buffer = buffer;
  350. cgc.buflen = 24;
  351. cgc.data_direction = DMA_FROM_DEVICE;
  352. cgc.timeout = IOCTL_TIMEOUT;
  353. result = sr_do_ioctl(cd, &cgc);
  354. memcpy(mcn->medium_catalog_number, buffer + 9, 13);
  355. mcn->medium_catalog_number[13] = 0;
  356. kfree(buffer);
  357. return result;
  358. }
  359. int sr_reset(struct cdrom_device_info *cdi)
  360. {
  361. return 0;
  362. }
  363. int sr_select_speed(struct cdrom_device_info *cdi, int speed)
  364. {
  365. Scsi_CD *cd = cdi->handle;
  366. struct packet_command cgc;
  367. if (speed == 0)
  368. speed = 0xffff; /* set to max */
  369. else
  370. speed *= 177; /* Nx to kbyte/s */
  371. memset(&cgc, 0, sizeof(struct packet_command));
  372. cgc.cmd[0] = GPCMD_SET_SPEED; /* SET CD SPEED */
  373. cgc.cmd[2] = (speed >> 8) & 0xff; /* MSB for speed (in kbytes/sec) */
  374. cgc.cmd[3] = speed & 0xff; /* LSB */
  375. cgc.data_direction = DMA_NONE;
  376. cgc.timeout = IOCTL_TIMEOUT;
  377. if (sr_do_ioctl(cd, &cgc))
  378. return -EIO;
  379. return 0;
  380. }
  381. /* ----------------------------------------------------------------------- */
  382. /* this is called by the generic cdrom driver. arg is a _kernel_ pointer, */
  383. /* because the generic cdrom driver does the user access stuff for us. */
  384. /* only cdromreadtochdr and cdromreadtocentry are left - for use with the */
  385. /* sr_disk_status interface for the generic cdrom driver. */
  386. int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
  387. {
  388. switch (cmd) {
  389. case CDROMREADTOCHDR:
  390. return sr_read_tochdr(cdi, arg);
  391. case CDROMREADTOCENTRY:
  392. return sr_read_tocentry(cdi, arg);
  393. case CDROMPLAYTRKIND:
  394. return sr_play_trkind(cdi, arg);
  395. default:
  396. return -EINVAL;
  397. }
  398. }
  399. /* -----------------------------------------------------------------------
  400. * a function to read all sorts of funny cdrom sectors using the READ_CD
  401. * scsi-3 mmc command
  402. *
  403. * lba: linear block address
  404. * format: 0 = data (anything)
  405. * 1 = audio
  406. * 2 = data (mode 1)
  407. * 3 = data (mode 2)
  408. * 4 = data (mode 2 form1)
  409. * 5 = data (mode 2 form2)
  410. * blksize: 2048 | 2336 | 2340 | 2352
  411. */
  412. static int sr_read_cd(Scsi_CD *cd, unsigned char *dest, int lba, int format, int blksize)
  413. {
  414. struct packet_command cgc;
  415. #ifdef DEBUG
  416. printk("%s: sr_read_cd lba=%d format=%d blksize=%d\n",
  417. cd->cdi.name, lba, format, blksize);
  418. #endif
  419. memset(&cgc, 0, sizeof(struct packet_command));
  420. cgc.cmd[0] = GPCMD_READ_CD; /* READ_CD */
  421. cgc.cmd[1] = ((format & 7) << 2);
  422. cgc.cmd[2] = (unsigned char) (lba >> 24) & 0xff;
  423. cgc.cmd[3] = (unsigned char) (lba >> 16) & 0xff;
  424. cgc.cmd[4] = (unsigned char) (lba >> 8) & 0xff;
  425. cgc.cmd[5] = (unsigned char) lba & 0xff;
  426. cgc.cmd[8] = 1;
  427. switch (blksize) {
  428. case 2336:
  429. cgc.cmd[9] = 0x58;
  430. break;
  431. case 2340:
  432. cgc.cmd[9] = 0x78;
  433. break;
  434. case 2352:
  435. cgc.cmd[9] = 0xf8;
  436. break;
  437. default:
  438. cgc.cmd[9] = 0x10;
  439. break;
  440. }
  441. cgc.buffer = dest;
  442. cgc.buflen = blksize;
  443. cgc.data_direction = DMA_FROM_DEVICE;
  444. cgc.timeout = IOCTL_TIMEOUT;
  445. return sr_do_ioctl(cd, &cgc);
  446. }
  447. /*
  448. * read sectors with blocksizes other than 2048
  449. */
  450. static int sr_read_sector(Scsi_CD *cd, int lba, int blksize, unsigned char *dest)
  451. {
  452. struct packet_command cgc;
  453. int rc;
  454. /* we try the READ CD command first... */
  455. if (cd->readcd_known) {
  456. rc = sr_read_cd(cd, dest, lba, 0, blksize);
  457. if (-EDRIVE_CANT_DO_THIS != rc)
  458. return rc;
  459. cd->readcd_known = 0;
  460. printk("CDROM does'nt support READ CD (0xbe) command\n");
  461. /* fall & retry the other way */
  462. }
  463. /* ... if this fails, we switch the blocksize using MODE SELECT */
  464. if (blksize != cd->device->sector_size) {
  465. if (0 != (rc = sr_set_blocklength(cd, blksize)))
  466. return rc;
  467. }
  468. #ifdef DEBUG
  469. printk("%s: sr_read_sector lba=%d blksize=%d\n", cd->cdi.name, lba, blksize);
  470. #endif
  471. memset(&cgc, 0, sizeof(struct packet_command));
  472. cgc.cmd[0] = GPCMD_READ_10;
  473. cgc.cmd[2] = (unsigned char) (lba >> 24) & 0xff;
  474. cgc.cmd[3] = (unsigned char) (lba >> 16) & 0xff;
  475. cgc.cmd[4] = (unsigned char) (lba >> 8) & 0xff;
  476. cgc.cmd[5] = (unsigned char) lba & 0xff;
  477. cgc.cmd[8] = 1;
  478. cgc.buffer = dest;
  479. cgc.buflen = blksize;
  480. cgc.data_direction = DMA_FROM_DEVICE;
  481. cgc.timeout = IOCTL_TIMEOUT;
  482. rc = sr_do_ioctl(cd, &cgc);
  483. return rc;
  484. }
  485. /*
  486. * read a sector in raw mode to check the sector format
  487. * ret: 1 == mode2 (XA), 0 == mode1, <0 == error
  488. */
  489. int sr_is_xa(Scsi_CD *cd)
  490. {
  491. unsigned char *raw_sector;
  492. int is_xa;
  493. if (!xa_test)
  494. return 0;
  495. raw_sector = kmalloc(2048, GFP_KERNEL | SR_GFP_DMA(cd));
  496. if (!raw_sector)
  497. return -ENOMEM;
  498. if (0 == sr_read_sector(cd, cd->ms_offset + 16,
  499. CD_FRAMESIZE_RAW1, raw_sector)) {
  500. is_xa = (raw_sector[3] == 0x02) ? 1 : 0;
  501. } else {
  502. /* read a raw sector failed for some reason. */
  503. is_xa = -1;
  504. }
  505. kfree(raw_sector);
  506. #ifdef DEBUG
  507. printk("%s: sr_is_xa: %d\n", cd->cdi.name, is_xa);
  508. #endif
  509. return is_xa;
  510. }