1/*-
2 * Copyright (c) 1997 Justin T. Gibbs.
3 * Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 Kenneth D. Merry.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
--- 32 unchanged lines hidden (view full) ---
41 * functioning of this software in any circumstances.
42 *
43 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
44 *
45 * from: cd.c,v 1.83 1997/05/04 15:24:22 joerg Exp $
46 */
47
48#include <sys/cdefs.h>
49__FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_cd.c 164906 2006-12-05 07:45:28Z mjacob $");
50
51#include "opt_cd.h"
52
53#include <sys/param.h>
54#include <sys/systm.h>
55#include <sys/kernel.h>
56#include <sys/bio.h>
57#include <sys/conf.h>
--- 7 unchanged lines hidden (view full) ---
65#include <sys/taskqueue.h>
66#include <geom/geom_disk.h>
67
68#include <cam/cam.h>
69#include <cam/cam_ccb.h>
70#include <cam/cam_periph.h>
71#include <cam/cam_xpt_periph.h>
72#include <cam/cam_queue.h>
73
74#include <cam/scsi/scsi_message.h>
75#include <cam/scsi/scsi_da.h>
76#include <cam/scsi/scsi_cd.h>
77
78#define LEADOUT 0xaa /* leadout toc entry */
79
80struct cd_params {
--- 17 unchanged lines hidden (view full) ---
98 CD_FLAG_DISC_REMOVABLE = 0x0008,
99 CD_FLAG_TAGGED_QUEUING = 0x0010,
100 CD_FLAG_CHANGER = 0x0040,
101 CD_FLAG_ACTIVE = 0x0080,
102 CD_FLAG_SCHED_ON_COMP = 0x0100,
103 CD_FLAG_RETRY_UA = 0x0200,
104 CD_FLAG_VALID_MEDIA = 0x0400,
105 CD_FLAG_VALID_TOC = 0x0800,
106 CD_FLAG_SCTX_INIT = 0x1000
107} cd_flags;
108
109typedef enum {
110 CD_CCB_PROBE = 0x01,
111 CD_CCB_BUFFER_IO = 0x02,
112 CD_CCB_WAITING = 0x03,
113 CD_CCB_TYPE_MASK = 0x0F,
114 CD_CCB_RETRY_UA = 0x10
--- 170 unchanged lines hidden (view full) ---
285static struct periph_driver cddriver =
286{
287 cdinit, "cd",
288 TAILQ_HEAD_INITIALIZER(cddriver.units), /* generation */ 0
289};
290
291PERIPHDRIVER_DECLARE(cd, cddriver);
292
293
294static int num_changers;
295
296#ifndef CHANGER_MIN_BUSY_SECONDS
297#define CHANGER_MIN_BUSY_SECONDS 5
298#endif
299#ifndef CHANGER_MAX_BUSY_SECONDS
300#define CHANGER_MAX_BUSY_SECONDS 15
301#endif
302
303static int changer_min_busy_seconds = CHANGER_MIN_BUSY_SECONDS;
--- 10 unchanged lines hidden (view full) ---
314
315struct cdchanger {
316 path_id_t path_id;
317 target_id_t target_id;
318 int num_devices;
319 struct camq devq;
320 struct timeval start_time;
321 struct cd_softc *cur_device;
322 struct callout_handle short_handle;
323 struct callout_handle long_handle;
324 volatile cd_changer_flags flags;
325 STAILQ_ENTRY(cdchanger) changer_links;
326 STAILQ_HEAD(chdevlist, cd_softc) chluns;
327};
328
329static STAILQ_HEAD(changerlist, cdchanger) changerq;
330
331
332static void
333cdinit(void)
334{
335 cam_status status;
336 struct cam_path *path;
337
338 /*
339 * Install a global async callback. This callback will
340 * receive async callbacks like "new device found".
341 */
342 status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID,
343 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
344
345 if (status == CAM_REQ_CMP) {
--- 13 unchanged lines hidden (view full) ---
359 printf("cd: Failed to attach master async callback "
360 "due to status 0x%x!\n", status);
361 }
362}
363
364static void
365cdoninvalidate(struct cam_periph *periph)
366{
367 int s;
368 struct cd_softc *softc;
369 struct ccb_setasync csa;
370
371 softc = (struct cd_softc *)periph->softc;
372
373 /*
374 * De-register any async callbacks.
375 */
376 xpt_setup_ccb(&csa.ccb_h, periph->path,
377 /* priority */ 5);
378 csa.ccb_h.func_code = XPT_SASYNC_CB;
379 csa.event_enable = 0;
380 csa.callback = cdasync;
381 csa.callback_arg = periph;
382 xpt_action((union ccb *)&csa);
383
384 softc->flags |= CD_FLAG_INVALID;
385
386 /*
387 * Although the oninvalidate() routines are always called at
388 * splsoftcam, we need to be at splbio() here to keep the buffer
389 * queue from being modified while we traverse it.
390 */
391 s = splbio();
392
393 /*
394 * Return all queued I/O with ENXIO.
395 * XXX Handle any transactions queued to the card
396 * with XPT_ABORT_CCB.
397 */
398 bioq_flush(&softc->bio_queue, NULL, ENXIO);
399 splx(s);
400
401 /*
402 * If this device is part of a changer, and it was scheduled
403 * to run, remove it from the run queue since we just nuked
404 * all of its scheduled I/O.
405 */
406 if ((softc->flags & CD_FLAG_CHANGER)
407 && (softc->pinfo.index != CAM_UNQUEUED_INDEX))
408 camq_remove(&softc->changer->devq, softc->pinfo.index);
409
410 disk_gone(softc->disk);
411 xpt_print(periph->path, "lost device\n");
412}
413
414static void
415cdcleanup(struct cam_periph *periph)
416{
417 struct cd_softc *softc;
418 int s;
419
420 softc = (struct cd_softc *)periph->softc;
421
422 xpt_print(periph->path, "removing device entry\n");
423
424 if ((softc->flags & CD_FLAG_SCTX_INIT) != 0
425 && sysctl_ctx_free(&softc->sysctl_ctx) != 0) {
426 xpt_print(periph->path, "can't remove sysctl context\n");
427 }
428
429 s = splsoftcam();
430 /*
431 * In the queued, non-active case, the device in question
432 * has already been removed from the changer run queue. Since this
433 * device is active, we need to de-activate it, and schedule
434 * another device to run. (if there is another one to run)
435 */
436 if ((softc->flags & CD_FLAG_CHANGER)
437 && (softc->flags & CD_FLAG_ACTIVE)) {
--- 13 unchanged lines hidden (view full) ---
451 * bogus pointer reference.
452 *
453 * The long timeout doesn't really matter, since we
454 * decrement the qfrozen_cnt to indicate that there is
455 * nothing in the active slot now. Therefore, there won't
456 * be any bogus pointer references there.
457 */
458 if (softc->changer->flags & CHANGER_SHORT_TMOUT_SCHED) {
459 untimeout(cdshorttimeout, softc->changer,
460 softc->changer->short_handle);
461 softc->changer->flags &= ~CHANGER_SHORT_TMOUT_SCHED;
462 }
463 softc->changer->devq.qfrozen_cnt--;
464 softc->changer->flags |= CHANGER_MANUAL_CALL;
465 cdrunchangerqueue(softc->changer);
466 }
467
468 /*
--- 4 unchanged lines hidden (view full) ---
473 && (--softc->changer->num_devices == 0)) {
474
475 /*
476 * Theoretically, there shouldn't be any timeouts left, but
477 * I'm not completely sure that that will be the case. So,
478 * it won't hurt to check and see if there are any left.
479 */
480 if (softc->changer->flags & CHANGER_TIMEOUT_SCHED) {
481 untimeout(cdrunchangerqueue, softc->changer,
482 softc->changer->long_handle);
483 softc->changer->flags &= ~CHANGER_TIMEOUT_SCHED;
484 }
485
486 if (softc->changer->flags & CHANGER_SHORT_TMOUT_SCHED) {
487 untimeout(cdshorttimeout, softc->changer,
488 softc->changer->short_handle);
489 softc->changer->flags &= ~CHANGER_SHORT_TMOUT_SCHED;
490 }
491
492 STAILQ_REMOVE(&changerq, softc->changer, cdchanger,
493 changer_links);
494 xpt_print(periph->path, "removing changer entry\n");
495 free(softc->changer, M_DEVBUF);
496 num_changers--;
497 }
498 disk_destroy(softc->disk);
499 free(softc, M_DEVBUF);
500 splx(s);
501}
502
503static void
504cdasync(void *callback_arg, u_int32_t code,
505 struct cam_path *path, void *arg)
506{
507 struct cam_periph *periph;
508
--- 30 unchanged lines hidden (view full) ---
539
540 break;
541 }
542 case AC_SENT_BDR:
543 case AC_BUS_RESET:
544 {
545 struct cd_softc *softc;
546 struct ccb_hdr *ccbh;
547 int s;
548
549 softc = (struct cd_softc *)periph->softc;
550 s = splsoftcam();
551 /*
552 * Don't fail on the expected unit attention
553 * that will occur.
554 */
555 softc->flags |= CD_FLAG_RETRY_UA;
556 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
557 ccbh->ccb_state |= CD_CCB_RETRY_UA;
558 splx(s);
559 /* FALLTHROUGH */
560 }
561 default:
562 cam_periph_async(periph, code, path, arg);
563 break;
564 }
565}
566
567static void
568cdsysctlinit(void *context, int pending)
569{
570 struct cam_periph *periph;
571 struct cd_softc *softc;
572 char tmpstr[80], tmpstr2[80];
573
574 periph = (struct cam_periph *)context;
575 softc = (struct cd_softc *)periph->softc;
576
577 snprintf(tmpstr, sizeof(tmpstr), "CAM CD unit %d", periph->unit_number);
578 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
579
580 mtx_lock(&Giant);
581
582 sysctl_ctx_init(&softc->sysctl_ctx);
583 softc->flags |= CD_FLAG_SCTX_INIT;
584 softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
585 SYSCTL_STATIC_CHILDREN(_kern_cam_cd), OID_AUTO,
586 tmpstr2, CTLFLAG_RD, 0, tmpstr);
587
588 if (softc->sysctl_tree == NULL) {
589 printf("cdsysctlinit: unable to allocate sysctl tree\n");
590 mtx_unlock(&Giant);
591 return;
592 }
593
594 /*
595 * Now register the sysctl handler, so the user can the value on
596 * the fly.
597 */
598 SYSCTL_ADD_PROC(&softc->sysctl_ctx,SYSCTL_CHILDREN(softc->sysctl_tree),
599 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
600 &softc->minimum_command_size, 0, cdcmdsizesysctl, "I",
601 "Minimum CDB size");
602
603 mtx_unlock(&Giant);
604}
605
606/*
607 * We have a handler function for this so we can check the values when the
608 * user sets them, instead of every time we look at them.
609 */
610static int
611cdcmdsizesysctl(SYSCTL_HANDLER_ARGS)
--- 117 unchanged lines hidden (view full) ---
729 * yet. Unlike other SCSI peripheral drivers, we explicitly set
730 * the device type here to be CDROM, rather than just ORing in
731 * the device type. This is because this driver can attach to either
732 * CDROM or WORM devices, and we want this peripheral driver to
733 * show up in the devstat list as a CD peripheral driver, not a
734 * WORM peripheral driver. WORM drives will also have the WORM
735 * driver attached to them.
736 */
737 softc->disk = disk_alloc();
738 softc->disk->d_devstat = devstat_new_entry("cd",
739 periph->unit_number, 0,
740 DEVSTAT_BS_UNAVAILABLE,
741 DEVSTAT_TYPE_CDROM | DEVSTAT_TYPE_IF_SCSI,
742 DEVSTAT_PRIORITY_CD);
743 softc->disk->d_open = cdopen;
744 softc->disk->d_close = cdclose;
745 softc->disk->d_strategy = cdstrategy;
746 softc->disk->d_ioctl = cdioctl;
747 softc->disk->d_name = "cd";
748 softc->disk->d_unit = periph->unit_number;
749 softc->disk->d_drv1 = periph;
750 softc->disk->d_flags = DISKFLAG_NEEDSGIANT;
751 disk_create(softc->disk, DISK_VERSION);
752
753 /*
754 * Add an async callback so that we get
755 * notified if this device goes away.
756 */
757 xpt_setup_ccb(&csa.ccb_h, periph->path,
758 /* priority */ 5);
759 csa.ccb_h.func_code = XPT_SASYNC_CB;
--- 18 unchanged lines hidden (view full) ---
778 struct cam_periph *nperiph;
779 struct cam_path *path;
780 cam_status status;
781 int found;
782
783 /* Set the changer flag in the current device's softc */
784 softc->flags |= CD_FLAG_CHANGER;
785
786 if (num_changers == 0)
787 STAILQ_INIT(&changerq);
788
789 /*
790 * Now, look around for an existing changer device with the
791 * same path and target ID as the current device.
792 */
793 for (found = 0,
794 nchanger = (struct cdchanger *)STAILQ_FIRST(&changerq);
795 nchanger != NULL;
796 nchanger = STAILQ_NEXT(nchanger, changer_links)){
797 if ((nchanger->path_id == cgd->ccb_h.path_id)
798 && (nchanger->target_id == cgd->ccb_h.target_id)) {
799 found = 1;
800 break;
801 }
802 }
803
804 /*
805 * If we found a matching entry, just add this device to
806 * the list of devices on this changer.
807 */
808 if (found == 1) {
809 struct chdevlist *chlunhead;
810
--- 89 unchanged lines hidden (view full) ---
900
901 if (camq_init(&nchanger->devq, 1) != 0) {
902 softc->flags &= ~CD_FLAG_CHANGER;
903 printf("cdregister: changer support "
904 "disabled\n");
905 goto cdregisterexit;
906 }
907
908 num_changers++;
909
910 nchanger->path_id = cgd->ccb_h.path_id;
911 nchanger->target_id = cgd->ccb_h.target_id;
912
913 /* this is superfluous, but it makes things clearer */
914 nchanger->num_devices = 0;
915
916 STAILQ_INIT(&nchanger->chluns);
917
918 STAILQ_INSERT_TAIL(&changerq, nchanger,
919 changer_links);
920
921 /*
922 * Create a path with lun id 0, and see if we can
923 * find a matching device
924 */
925 status = xpt_create_path(&path, /*periph*/ periph,
926 cgd->ccb_h.path_id,
927 cgd->ccb_h.target_id, 0);
--- 45 unchanged lines hidden (view full) ---
973 }
974 STAILQ_INSERT_TAIL(&nchanger->chluns, softc,
975 changer_links);
976 }
977 }
978
979cdregisterexit:
980
981 /* Lock this peripheral until we are setup */
982 /* Can't block */
983 cam_periph_lock(periph, PRIBIO);
984
985 if ((softc->flags & CD_FLAG_CHANGER) == 0)
986 xpt_schedule(periph, /*priority*/5);
987 else
988 cdschedule(periph, /*priority*/ 5);
989
990 return(CAM_REQ_CMP);
991}
992
993static int
994cdopen(struct disk *dp)
995{
996 struct cam_periph *periph;
997 struct cd_softc *softc;
998 int error;
999 int s;
1000
1001 periph = (struct cam_periph *)dp->d_drv1;
1002 if (periph == NULL)
1003 return (ENXIO);
1004
1005 softc = (struct cd_softc *)periph->softc;
1006
1007 /*
1008 * Grab splsoftcam and hold it until we lock the peripheral.
1009 */
1010 s = splsoftcam();
1011 if (softc->flags & CD_FLAG_INVALID) {
1012 splx(s);
1013 return(ENXIO);
1014 }
1015
1016 if ((error = cam_periph_lock(periph, PRIBIO | PCATCH)) != 0) {
1017 splx(s);
1018 return (error);
1019 }
1020
1021 splx(s);
1022
1023 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
1024 return(ENXIO);
1025
1026 /*
1027 * Check for media, and set the appropriate flags. We don't bail
1028 * if we don't have media, but then we don't allow anything but the
1029 * CDIOCEJECT/CDIOCCLOSE ioctls if there is no media.
1030 */
1031 cdcheckmedia(periph);
1032
1033 cam_periph_unlock(periph);
1034
1035 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("leaving cdopen\n"));
1036
1037 return (error);
1038}
1039
1040static int
1041cdclose(struct disk *dp)
1042{
1043 struct cam_periph *periph;
1044 struct cd_softc *softc;
1045 int error;
1046
1047 periph = (struct cam_periph *)dp->d_drv1;
1048 if (periph == NULL)
1049 return (ENXIO);
1050
1051 softc = (struct cd_softc *)periph->softc;
1052
1053 if ((error = cam_periph_lock(periph, PRIBIO)) != 0)
1054 return (error);
1055
1056 if ((softc->flags & CD_FLAG_DISC_REMOVABLE) != 0)
1057 cdprevent(periph, PR_ALLOW);
1058
1059 /*
1060 * Since we're closing this CD, mark the blocksize as unavailable.
1061 * It will be marked as available when the CD is opened again.
1062 */
1063 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1064
1065 /*
1066 * We'll check the media and toc again at the next open().
1067 */
1068 softc->flags &= ~(CD_FLAG_VALID_MEDIA|CD_FLAG_VALID_TOC);
1069
1070 cam_periph_unlock(periph);
1071 cam_periph_release(periph);
1072
1073 return (0);
1074}
1075
1076static void
1077cdshorttimeout(void *arg)
1078{
1079 struct cdchanger *changer;
1080 int s;
1081
1082 s = splsoftcam();
1083
1084 changer = (struct cdchanger *)arg;
1085
1086 /* Always clear the short timeout flag, since that's what we're in */
1087 changer->flags &= ~CHANGER_SHORT_TMOUT_SCHED;
1088
1089 /*
1090 * Check to see if there is any more pending or outstanding I/O for
1091 * this device. If not, move it out of the active slot.
1092 */
1093 if ((bioq_first(&changer->cur_device->bio_queue) == NULL)
1094 && (changer->cur_device->outstanding_cmds == 0)) {
1095 changer->flags |= CHANGER_MANUAL_CALL;
1096 cdrunchangerqueue(changer);
1097 }
1098
1099 splx(s);
1100}
1101
1102/*
1103 * This is a wrapper for xpt_schedule. It only applies to changers.
1104 */
1105static void
1106cdschedule(struct cam_periph *periph, int priority)
1107{
1108 struct cd_softc *softc;
1109 int s;
1110
1111 s = splsoftcam();
1112
1113 softc = (struct cd_softc *)periph->softc;
1114
1115 /*
1116 * If this device isn't currently queued, and if it isn't
1117 * the active device, then we queue this device and run the
1118 * changer queue if there is no timeout scheduled to do it.
1119 * If this device is the active device, just schedule it
1120 * to run again. If this device is queued, there should be
--- 21 unchanged lines hidden (view full) ---
1142 && ((softc->changer->flags & CHANGER_NEED_TIMEOUT)==0)
1143 && ((softc->changer->flags & CHANGER_SHORT_TMOUT_SCHED)==0)){
1144 softc->changer->flags |= CHANGER_MANUAL_CALL;
1145 cdrunchangerqueue(softc->changer);
1146 }
1147 } else if ((softc->flags & CD_FLAG_ACTIVE)
1148 && ((softc->flags & CD_FLAG_SCHED_ON_COMP) == 0))
1149 xpt_schedule(periph, priority);
1150
1151 splx(s);
1152
1153}
1154
1155static void
1156cdrunchangerqueue(void *arg)
1157{
1158 struct cd_softc *softc;
1159 struct cdchanger *changer;
1160 int called_from_timeout;
1161 int s;
1162
1163 s = splsoftcam();
1164
1165 changer = (struct cdchanger *)arg;
1166
1167 /*
1168 * If we have NOT been called from cdstrategy() or cddone(), and
1169 * instead from a timeout routine, go ahead and clear the
1170 * timeout flag.
1171 */
1172 if ((changer->flags & CHANGER_MANUAL_CALL) == 0) {
1173 changer->flags &= ~CHANGER_TIMEOUT_SCHED;
1174 called_from_timeout = 1;
1175 } else
1176 called_from_timeout = 0;
1177
1178 /* Always clear the manual call flag */
1179 changer->flags &= ~CHANGER_MANUAL_CALL;
1180
1181 /* nothing to do if the queue is empty */
1182 if (changer->devq.entries <= 0) {
1183 splx(s);
1184 return;
1185 }
1186
1187 /*
1188 * If the changer queue is frozen, that means we have an active
1189 * device.
1190 */
1191 if (changer->devq.qfrozen_cnt > 0) {
1192
1193 if (changer->cur_device->outstanding_cmds > 0) {
1194 changer->cur_device->flags |= CD_FLAG_SCHED_ON_COMP;
1195 changer->cur_device->bufs_left =
1196 changer->cur_device->outstanding_cmds;
1197 if (called_from_timeout) {
1198 changer->long_handle =
1199 timeout(cdrunchangerqueue, changer,
1200 changer_max_busy_seconds * hz);
1201 changer->flags |= CHANGER_TIMEOUT_SCHED;
1202 }
1203 splx(s);
1204 return;
1205 }
1206
1207 /*
1208 * We always need to reset the frozen count and clear the
1209 * active flag.
1210 */
1211 changer->devq.qfrozen_cnt--;
1212 changer->cur_device->flags &= ~CD_FLAG_ACTIVE;
1213 changer->cur_device->flags &= ~CD_FLAG_SCHED_ON_COMP;
1214
1215 /*
1216 * Check to see whether the current device has any I/O left
1217 * to do. If so, requeue it at the end of the queue. If
1218 * not, there is no need to requeue it.
1219 */
1220 if (bioq_first(&changer->cur_device->bio_queue) != NULL) {
1221
1222 changer->cur_device->pinfo.generation =
1223 ++changer->devq.generation;
--- 13 unchanged lines hidden (view full) ---
1237 wakeup(&softc->changer);
1238 xpt_schedule(softc->periph, /*priority*/ 1);
1239
1240 /*
1241 * Get rid of any pending timeouts, and set a flag to schedule new
1242 * ones so this device gets its full time quantum.
1243 */
1244 if (changer->flags & CHANGER_TIMEOUT_SCHED) {
1245 untimeout(cdrunchangerqueue, changer, changer->long_handle);
1246 changer->flags &= ~CHANGER_TIMEOUT_SCHED;
1247 }
1248
1249 if (changer->flags & CHANGER_SHORT_TMOUT_SCHED) {
1250 untimeout(cdshorttimeout, changer, changer->short_handle);
1251 changer->flags &= ~CHANGER_SHORT_TMOUT_SCHED;
1252 }
1253
1254 /*
1255 * We need to schedule timeouts, but we only do this after the
1256 * first transaction has completed. This eliminates the changer
1257 * switch time.
1258 */
1259 changer->flags |= CHANGER_NEED_TIMEOUT;
1260
1261 splx(s);
1262}
1263
1264static void
1265cdchangerschedule(struct cd_softc *softc)
1266{
1267 struct cdchanger *changer;
1268 int s;
1269
1270 s = splsoftcam();
1271
1272 changer = softc->changer;
1273
1274 /*
1275 * If this is a changer, and this is the current device,
1276 * and this device has at least the minimum time quantum to
1277 * run, see if we can switch it out.
1278 */
1279 if ((softc->flags & CD_FLAG_ACTIVE)
--- 28 unchanged lines hidden (view full) ---
1308 && (softc->flags & CD_FLAG_ACTIVE)) {
1309
1310 /*
1311 * Now that the first transaction to this
1312 * particular device has completed, we can go ahead
1313 * and schedule our timeouts.
1314 */
1315 if ((changer->flags & CHANGER_TIMEOUT_SCHED) == 0) {
1316 changer->long_handle =
1317 timeout(cdrunchangerqueue, changer,
1318 changer_max_busy_seconds * hz);
1319 changer->flags |= CHANGER_TIMEOUT_SCHED;
1320 } else
1321 printf("cdchangerschedule: already have a long"
1322 " timeout!\n");
1323
1324 if ((changer->flags & CHANGER_SHORT_TMOUT_SCHED) == 0) {
1325 changer->short_handle =
1326 timeout(cdshorttimeout, changer,
1327 changer_min_busy_seconds * hz);
1328 changer->flags |= CHANGER_SHORT_TMOUT_SCHED;
1329 } else
1330 printf("cdchangerschedule: already have a short "
1331 "timeout!\n");
1332
1333 /*
1334 * We just scheduled timeouts, no need to schedule
1335 * more.
1336 */
1337 changer->flags &= ~CHANGER_NEED_TIMEOUT;
1338
1339 }
1340 splx(s);
1341}
1342
1343static int
1344cdrunccb(union ccb *ccb, int (*error_routine)(union ccb *ccb,
1345 u_int32_t cam_flags,
1346 u_int32_t sense_flags),
1347 u_int32_t cam_flags, u_int32_t sense_flags)
1348{
--- 12 unchanged lines hidden (view full) ---
1361
1362 return(error);
1363}
1364
1365static union ccb *
1366cdgetccb(struct cam_periph *periph, u_int32_t priority)
1367{
1368 struct cd_softc *softc;
1369 int s;
1370
1371 softc = (struct cd_softc *)periph->softc;
1372
1373 if (softc->flags & CD_FLAG_CHANGER) {
1374
1375 s = splsoftcam();
1376
1377 /*
1378 * This should work the first time this device is woken up,
1379 * but just in case it doesn't, we use a while loop.
1380 */
1381 while ((softc->flags & CD_FLAG_ACTIVE) == 0) {
1382 /*
1383 * If this changer isn't already queued, queue it up.
1384 */
--- 6 unchanged lines hidden (view full) ---
1391 }
1392 if (((softc->changer->flags & CHANGER_TIMEOUT_SCHED)==0)
1393 && ((softc->changer->flags & CHANGER_NEED_TIMEOUT)==0)
1394 && ((softc->changer->flags
1395 & CHANGER_SHORT_TMOUT_SCHED)==0)) {
1396 softc->changer->flags |= CHANGER_MANUAL_CALL;
1397 cdrunchangerqueue(softc->changer);
1398 } else
1399 tsleep(&softc->changer, PRIBIO, "cgticb", 0);
1400 }
1401 splx(s);
1402 }
1403 return(cam_periph_getccb(periph, priority));
1404}
1405
1406
1407/*
1408 * Actually translate the requested transfer into one the physical driver
1409 * can understand. The transfer is described by a buf and will include
1410 * only one physical transfer.
1411 */
1412static void
1413cdstrategy(struct bio *bp)
1414{
1415 struct cam_periph *periph;
1416 struct cd_softc *softc;
1417 int s;
1418
1419 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1420 if (periph == NULL) {
1421 biofinish(bp, NULL, ENXIO);
1422 return;
1423 }
1424
1425 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdstrategy\n"));
1426
1427 softc = (struct cd_softc *)periph->softc;
1428
1429 /*
1430 * Mask interrupts so that the pack cannot be invalidated until
1431 * after we are in the queue. Otherwise, we might not properly
1432 * clean up one of the buffers.
1433 */
1434 s = splbio();
1435
1436 /*
1437 * If the device has been made invalid, error out
1438 */
1439 if ((softc->flags & CD_FLAG_INVALID)) {
1440 splx(s);
1441 biofinish(bp, NULL, ENXIO);
1442 return;
1443 }
1444
1445 /*
1446 * If we don't have valid media, look for it before trying to
1447 * schedule the I/O.
1448 */
1449 if ((softc->flags & CD_FLAG_VALID_MEDIA) == 0) {
1450 int error;
1451
1452 error = cdcheckmedia(periph);
1453 if (error != 0) {
1454 splx(s);
1455 biofinish(bp, NULL, error);
1456 return;
1457 }
1458 }
1459
1460 /*
1461 * Place it in the queue of disk activities for this disk
1462 */
1463 bioq_disksort(&softc->bio_queue, bp);
1464
1465 splx(s);
1466
1467 /*
1468 * Schedule ourselves for performing the work. We do things
1469 * differently for changers.
1470 */
1471 if ((softc->flags & CD_FLAG_CHANGER) == 0)
1472 xpt_schedule(periph, /* XXX priority */1);
1473 else
1474 cdschedule(periph, /* priority */ 1);
1475
1476 return;
1477}
1478
1479static void
1480cdstart(struct cam_periph *periph, union ccb *start_ccb)
1481{
1482 struct cd_softc *softc;
1483 struct bio *bp;
1484 struct ccb_scsiio *csio;
1485 struct scsi_read_capacity_data *rcap;
1486 int s;
1487
1488 softc = (struct cd_softc *)periph->softc;
1489
1490 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdstart\n"));
1491
1492 switch (softc->state) {
1493 case CD_STATE_NORMAL:
1494 {
1495 int oldspl;
1496
1497 s = splbio();
1498 bp = bioq_first(&softc->bio_queue);
1499 if (periph->immediate_priority <= periph->pinfo.priority) {
1500 start_ccb->ccb_h.ccb_state = CD_CCB_WAITING;
1501
1502 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
1503 periph_links.sle);
1504 periph->immediate_priority = CAM_PRIORITY_NONE;
1505 splx(s);
1506 wakeup(&periph->ccb_list);
1507 } else if (bp == NULL) {
1508 splx(s);
1509 xpt_release_ccb(start_ccb);
1510 } else {
1511 bioq_remove(&softc->bio_queue, bp);
1512
1513 devstat_start_transaction_bio(softc->disk->d_devstat, bp);
1514
1515 scsi_read_write(&start_ccb->csio,
1516 /*retries*/4,
--- 7 unchanged lines hidden (view full) ---
1524 bp->bio_bcount / softc->params.blksize,
1525 /* data_ptr */ bp->bio_data,
1526 /* dxfer_len */ bp->bio_bcount,
1527 /* sense_len */ SSD_FULL_SIZE,
1528 /* timeout */ 30000);
1529 start_ccb->ccb_h.ccb_state = CD_CCB_BUFFER_IO;
1530
1531
1532 /*
1533 * Block out any asyncronous callbacks
1534 * while we touch the pending ccb list.
1535 */
1536 oldspl = splcam();
1537 LIST_INSERT_HEAD(&softc->pending_ccbs,
1538 &start_ccb->ccb_h, periph_links.le);
1539 softc->outstanding_cmds++;
1540 splx(oldspl);
1541
1542 /* We expect a unit attention from this device */
1543 if ((softc->flags & CD_FLAG_RETRY_UA) != 0) {
1544 start_ccb->ccb_h.ccb_state |= CD_CCB_RETRY_UA;
1545 softc->flags &= ~CD_FLAG_RETRY_UA;
1546 }
1547
1548 start_ccb->ccb_h.ccb_bp = bp;
1549 bp = bioq_first(&softc->bio_queue);
1550 splx(s);
1551
1552 xpt_action(start_ccb);
1553 }
1554 if (bp != NULL) {
1555 /* Have more work to do, so ensure we stay scheduled */
1556 xpt_schedule(periph, /* XXX priority */1);
1557 }
1558 break;
--- 37 unchanged lines hidden (view full) ---
1596 softc = (struct cd_softc *)periph->softc;
1597 csio = &done_ccb->csio;
1598
1599 switch (csio->ccb_h.ccb_state & CD_CCB_TYPE_MASK) {
1600 case CD_CCB_BUFFER_IO:
1601 {
1602 struct bio *bp;
1603 int error;
1604 int oldspl;
1605
1606 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
1607 error = 0;
1608
1609 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1610 int sf;
1611
1612 if ((done_ccb->ccb_h.ccb_state & CD_CCB_RETRY_UA) != 0)
--- 7 unchanged lines hidden (view full) ---
1620 * A retry was scheuled, so
1621 * just return.
1622 */
1623 return;
1624 }
1625 }
1626
1627 if (error != 0) {
1628 int s;
1629
1630 xpt_print(periph->path,
1631 "cddone: got error %#x back\n", error);
1632 s = splbio();
1633 bioq_flush(&softc->bio_queue, NULL, EIO);
1634 splx(s);
1635 bp->bio_resid = bp->bio_bcount;
1636 bp->bio_error = error;
1637 bp->bio_flags |= BIO_ERROR;
1638 cam_release_devq(done_ccb->ccb_h.path,
1639 /*relsim_flags*/0,
1640 /*reduction*/0,
1641 /*timeout*/0,
1642 /*getcount_only*/0);
--- 6 unchanged lines hidden (view full) ---
1649 * Short transfer ???
1650 * XXX: not sure this is correct for partial
1651 * transfers at EOM
1652 */
1653 bp->bio_flags |= BIO_ERROR;
1654 }
1655 }
1656
1657 /*
1658 * Block out any asyncronous callbacks
1659 * while we touch the pending ccb list.
1660 */
1661 oldspl = splcam();
1662 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
1663 softc->outstanding_cmds--;
1664 splx(oldspl);
1665
1666 if (softc->flags & CD_FLAG_CHANGER)
1667 cdchangerschedule(softc);
1668
1669 biofinish(bp, NULL, 0);
1670 break;
1671 }
1672 case CD_CCB_PROBE:
--- 174 unchanged lines hidden (view full) ---
1847 * Since our peripheral may be invalidated by an error
1848 * above or an external event, we must release our CCB
1849 * before releasing the probe lock on the peripheral.
1850 * The peripheral will only go away once the last lock
1851 * is removed, and we need it around for the CCB release
1852 * operation.
1853 */
1854 xpt_release_ccb(done_ccb);
1855 cam_periph_unlock(periph);
1856 return;
1857 }
1858 case CD_CCB_WAITING:
1859 {
1860 /* Caller will release the CCB */
1861 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
1862 ("trying to wakeup ccbwait\n"));
1863
--- 36 unchanged lines hidden (view full) ---
1900}
1901
1902static int
1903cdioctl(struct disk *dp, u_long cmd, void *addr, int flag, struct thread *td)
1904{
1905
1906 struct cam_periph *periph;
1907 struct cd_softc *softc;
1908 int error, nocopyout;
1909
1910 periph = (struct cam_periph *)dp->d_drv1;
1911 if (periph == NULL)
1912 return(ENXIO);
1913
1914 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdioctl\n"));
1915
1916 softc = (struct cd_softc *)periph->softc;
1917
1918 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
1919 ("trying to do ioctl %#lx\n", cmd));
1920
1921 error = cam_periph_lock(periph, PRIBIO | PCATCH);
1922
1923 if (error != 0)
1924 return(error);
1925 /*
1926 * If we don't have media loaded, check for it. If still don't
1927 * have media loaded, we can only do a load or eject.
1928 *
1929 * We only care whether media is loaded if this is a cd-specific ioctl
1930 * (thus the IOCGROUP check below). Note that this will break if
1931 * anyone adds any ioctls into the switch statement below that don't
1932 * have their ioctl group set to 'c'.
1933 */
1934 if (((softc->flags & CD_FLAG_VALID_MEDIA) == 0)
1935 && ((cmd != CDIOCCLOSE)
1936 && (cmd != CDIOCEJECT))
1937 && (IOCGROUP(cmd) == 'c')) {
1938 error = cdcheckmedia(periph);
1939 if (error != 0) {
1940 cam_periph_unlock(periph);
1941 return (error);
1942 }
1943 }
1944
1945 nocopyout = 0;
1946 switch (cmd) {
1947
1948 case CDIOCPLAYTRACKS:
1949 {
1950 struct ioc_play_track *args
1951 = (struct ioc_play_track *) addr;
1952 struct cd_mode_params params;
1953 union cd_pages *page;
1954
1955 params.alloc_len = sizeof(union cd_mode_data_6_10);
1956 params.mode_buf = malloc(params.alloc_len, M_TEMP,
1957 M_WAITOK | M_ZERO);
1958
1959 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
1960 ("trying to do CDIOCPLAYTRACKS\n"));
1961
1962 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
1963 if (error) {
1964 free(params.mode_buf, M_TEMP);
1965 break;
1966 }
1967 page = cdgetpage(¶ms);
1968
1969 page->audio.flags &= ~CD_PA_SOTC;
1970 page->audio.flags |= CD_PA_IMMED;
1971 error = cdsetmode(periph, ¶ms);
1972 free(params.mode_buf, M_TEMP);
1973 if (error)
1974 break;
1975
1976 /*
1977 * This was originally implemented with the PLAY
1978 * AUDIO TRACK INDEX command, but that command was
1979 * deprecated after SCSI-2. Most (all?) SCSI CDROM
1980 * drives support it but ATAPI and ATAPI-derivative
1981 * drives don't seem to support it. So we keep a
1982 * cache of the table of contents and translate
--- 45 unchanged lines hidden (view full) ---
2028 bin2bcd(args->end_track);
2029 }
2030 error = cdplaytracks(periph,
2031 args->start_track,
2032 args->start_index,
2033 args->end_track,
2034 args->end_index);
2035 }
2036 }
2037 break;
2038 case CDIOCPLAYMSF:
2039 {
2040 struct ioc_play_msf *args
2041 = (struct ioc_play_msf *) addr;
2042 struct cd_mode_params params;
2043 union cd_pages *page;
2044
2045 params.alloc_len = sizeof(union cd_mode_data_6_10);
2046 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2047 M_WAITOK | M_ZERO);
2048
2049 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2050 ("trying to do CDIOCPLAYMSF\n"));
2051
2052 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2053 if (error) {
2054 free(params.mode_buf, M_TEMP);
2055 break;
2056 }
2057 page = cdgetpage(¶ms);
2058
2059 page->audio.flags &= ~CD_PA_SOTC;
2060 page->audio.flags |= CD_PA_IMMED;
2061 error = cdsetmode(periph, ¶ms);
2062 free(params.mode_buf, M_TEMP);
2063 if (error)
2064 break;
2065 error = cdplaymsf(periph,
2066 args->start_m,
2067 args->start_s,
2068 args->start_f,
2069 args->end_m,
2070 args->end_s,
2071 args->end_f);
2072 }
2073 break;
2074 case CDIOCPLAYBLOCKS:
2075 {
2076 struct ioc_play_blocks *args
2077 = (struct ioc_play_blocks *) addr;
2078 struct cd_mode_params params;
2079 union cd_pages *page;
2080
2081 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2082 ("trying to do CDIOCPLAYBLOCKS\n"));
2083
2084 params.alloc_len = sizeof(union cd_mode_data_6_10);
2085 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2086 M_WAITOK | M_ZERO);
2087
2088 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2089 if (error) {
2090 free(params.mode_buf, M_TEMP);
2091 break;
2092 }
2093 page = cdgetpage(¶ms);
2094
2095 page->audio.flags &= ~CD_PA_SOTC;
2096 page->audio.flags |= CD_PA_IMMED;
2097 error = cdsetmode(periph, ¶ms);
2098 free(params.mode_buf, M_TEMP);
2099 if (error)
2100 break;
2101 error = cdplay(periph, args->blk, args->len);
2102 }
2103 break;
2104 case CDIOCREADSUBCHANNEL_SYSSPACE:
2105 nocopyout = 1;
2106 /* Fallthrough */
2107 case CDIOCREADSUBCHANNEL:
2108 {
2109 struct ioc_read_subchannel *args
2110 = (struct ioc_read_subchannel *) addr;
2111 struct cd_sub_channel_info *data;
2112 u_int32_t len = args->data_len;
2113
2114 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2115 ("trying to do CDIOCREADSUBCHANNEL\n"));
2116
2117 data = malloc(sizeof(struct cd_sub_channel_info),
2118 M_TEMP, M_WAITOK);
2119
2120 if ((len > sizeof(struct cd_sub_channel_info)) ||
2121 (len < sizeof(struct cd_sub_channel_header))) {
2122 printf(
2123 "scsi_cd: cdioctl: "
2124 "cdioreadsubchannel: error, len=%d\n",
2125 len);
2126 error = EINVAL;
2127 free(data, M_TEMP);
2128 break;
2129 }
2130
2131 if (softc->quirks & CD_Q_BCD_TRACKS)
2132 args->track = bin2bcd(args->track);
2133
2134 error = cdreadsubchannel(periph, args->address_format,
2135 args->data_format, args->track, data, len);
2136
2137 if (error) {
2138 free(data, M_TEMP);
2139 break;
2140 }
2141 if (softc->quirks & CD_Q_BCD_TRACKS)
2142 data->what.track_info.track_number =
2143 bcd2bin(data->what.track_info.track_number);
2144 len = min(len, ((data->header.data_len[0] << 8) +
2145 data->header.data_len[1] +
2146 sizeof(struct cd_sub_channel_header)));
2147 if (nocopyout == 0) {
2148 if (copyout(data, args->data, len) != 0) {
2149 error = EFAULT;
2150 }
2151 } else {
2152 bcopy(data, args->data, len);
2153 }
2154 free(data, M_TEMP);
2155 }
2156 break;
2157
2158 case CDIOREADTOCHEADER:
2159 {
2160 struct ioc_toc_header *th;
2161
2162 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2163 ("trying to do CDIOREADTOCHEADER\n"));
2164
2165 th = malloc(sizeof(struct ioc_toc_header), M_TEMP,
2166 M_WAITOK);
2167 error = cdreadtoc(periph, 0, 0, (u_int8_t *)th,
2168 sizeof (*th), /*sense_flags*/0);
2169 if (error) {
2170 free(th, M_TEMP);
2171 break;
2172 }
2173 if (softc->quirks & CD_Q_BCD_TRACKS) {
2174 /* we are going to have to convert the BCD
2175 * encoding on the cd to what is expected
2176 */
2177 th->starting_track =
2178 bcd2bin(th->starting_track);
2179 th->ending_track = bcd2bin(th->ending_track);
2180 }
2181 th->len = ntohs(th->len);
2182 bcopy(th, addr, sizeof(*th));
2183 free(th, M_TEMP);
2184 }
2185 break;
2186 case CDIOREADTOCENTRYS:
2187 {
2188 struct cd_tocdata *data;
2189 struct cd_toc_single *lead;
2190 struct ioc_read_toc_entry *te =
2191 (struct ioc_read_toc_entry *) addr;
2192 struct ioc_toc_header *th;
2193 u_int32_t len, readlen, idx, num;
2194 u_int32_t starting_track = te->starting_track;
2195
2196 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2197 ("trying to do CDIOREADTOCENTRYS\n"));
2198
2199 data = malloc(sizeof(*data), M_TEMP, M_WAITOK);
2200 lead = malloc(sizeof(*lead), M_TEMP, M_WAITOK);
2201
2202 if (te->data_len < sizeof(struct cd_toc_entry)
2203 || (te->data_len % sizeof(struct cd_toc_entry)) != 0
2204 || (te->address_format != CD_MSF_FORMAT
2205 && te->address_format != CD_LBA_FORMAT)) {
2206 error = EINVAL;
2207 printf("scsi_cd: error in readtocentries, "
2208 "returning EINVAL\n");
2209 free(data, M_TEMP);
2210 free(lead, M_TEMP);
2211 break;
2212 }
2213
2214 th = &data->header;
2215 error = cdreadtoc(periph, 0, 0, (u_int8_t *)th,
2216 sizeof (*th), /*sense_flags*/0);
2217 if (error) {
2218 free(data, M_TEMP);
2219 free(lead, M_TEMP);
2220 break;
2221 }
2222
2223 if (softc->quirks & CD_Q_BCD_TRACKS) {
2224 /* we are going to have to convert the BCD
2225 * encoding on the cd to what is expected
2226 */
2227 th->starting_track =
--- 6 unchanged lines hidden (view full) ---
2234 else if (starting_track == LEADOUT)
2235 starting_track = th->ending_track + 1;
2236 else if (starting_track < th->starting_track ||
2237 starting_track > th->ending_track + 1) {
2238 printf("scsi_cd: error in readtocentries, "
2239 "returning EINVAL\n");
2240 free(data, M_TEMP);
2241 free(lead, M_TEMP);
2242 error = EINVAL;
2243 break;
2244 }
2245
2246 /* calculate reading length without leadout entry */
2247 readlen = (th->ending_track - starting_track + 1) *
2248 sizeof(struct cd_toc_entry);
2249
--- 5 unchanged lines hidden (view full) ---
2255 readlen = len;
2256 }
2257 if (len > sizeof(data->entries)) {
2258 printf("scsi_cd: error in readtocentries, "
2259 "returning EINVAL\n");
2260 error = EINVAL;
2261 free(data, M_TEMP);
2262 free(lead, M_TEMP);
2263 break;
2264 }
2265 num = len / sizeof(struct cd_toc_entry);
2266
2267 if (readlen > 0) {
2268 error = cdreadtoc(periph, te->address_format,
2269 starting_track,
2270 (u_int8_t *)data,
2271 readlen + sizeof (*th),
2272 /*sense_flags*/0);
2273 if (error) {
2274 free(data, M_TEMP);
2275 free(lead, M_TEMP);
2276 break;
2277 }
2278 }
2279
2280 /* make leadout entry if needed */
2281 idx = starting_track + num - 1;
2282 if (softc->quirks & CD_Q_BCD_TRACKS)
2283 th->ending_track = bcd2bin(th->ending_track);
2284 if (idx == th->ending_track + 1) {
2285 error = cdreadtoc(periph, te->address_format,
2286 LEADOUT, (u_int8_t *)lead,
2287 sizeof(*lead),
2288 /*sense_flags*/0);
2289 if (error) {
2290 free(data, M_TEMP);
2291 free(lead, M_TEMP);
2292 break;
2293 }
2294 data->entries[idx - starting_track] =
2295 lead->entry;
2296 }
2297 if (softc->quirks & CD_Q_BCD_TRACKS) {
2298 for (idx = 0; idx < num - 1; idx++) {
2299 data->entries[idx].track =
2300 bcd2bin(data->entries[idx].track);
2301 }
2302 }
2303
2304 error = copyout(data->entries, te->data, len);
2305 free(data, M_TEMP);
2306 free(lead, M_TEMP);
2307 }
2308 break;
2309 case CDIOREADTOCENTRY:
2310 {
2311 struct cd_toc_single *data;
2312 struct ioc_read_toc_single_entry *te =
2313 (struct ioc_read_toc_single_entry *) addr;
2314 struct ioc_toc_header *th;
2315 u_int32_t track;
2316
2317 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2318 ("trying to do CDIOREADTOCENTRY\n"));
2319
2320 data = malloc(sizeof(*data), M_TEMP, M_WAITOK);
2321
2322 if (te->address_format != CD_MSF_FORMAT
2323 && te->address_format != CD_LBA_FORMAT) {
2324 printf("error in readtocentry, "
2325 " returning EINVAL\n");
2326 free(data, M_TEMP);
2327 error = EINVAL;
2328 break;
2329 }
2330
2331 th = &data->header;
2332 error = cdreadtoc(periph, 0, 0, (u_int8_t *)th,
2333 sizeof (*th), /*sense_flags*/0);
2334 if (error) {
2335 free(data, M_TEMP);
2336 break;
2337 }
2338
2339 if (softc->quirks & CD_Q_BCD_TRACKS) {
2340 /* we are going to have to convert the BCD
2341 * encoding on the cd to what is expected
2342 */
2343 th->starting_track =
--- 6 unchanged lines hidden (view full) ---
2350 else if (track == LEADOUT)
2351 /* OK */;
2352 else if (track < th->starting_track ||
2353 track > th->ending_track + 1) {
2354 printf("error in readtocentry, "
2355 " returning EINVAL\n");
2356 free(data, M_TEMP);
2357 error = EINVAL;
2358 break;
2359 }
2360
2361 error = cdreadtoc(periph, te->address_format, track,
2362 (u_int8_t *)data, sizeof(*data),
2363 /*sense_flags*/0);
2364 if (error) {
2365 free(data, M_TEMP);
2366 break;
2367 }
2368
2369 if (softc->quirks & CD_Q_BCD_TRACKS)
2370 data->entry.track = bcd2bin(data->entry.track);
2371 bcopy(&data->entry, &te->entry,
2372 sizeof(struct cd_toc_entry));
2373 free(data, M_TEMP);
2374 }
2375 break;
2376 case CDIOCSETPATCH:
2377 {
2378 struct ioc_patch *arg = (struct ioc_patch *)addr;
2379 struct cd_mode_params params;
2380 union cd_pages *page;
2381
2382 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2383 ("trying to do CDIOCSETPATCH\n"));
2384
2385 params.alloc_len = sizeof(union cd_mode_data_6_10);
2386 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2387 M_WAITOK | M_ZERO);
2388 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2389 if (error) {
2390 free(params.mode_buf, M_TEMP);
2391 break;
2392 }
2393 page = cdgetpage(¶ms);
2394
2395 page->audio.port[LEFT_PORT].channels =
2396 arg->patch[0];
2397 page->audio.port[RIGHT_PORT].channels =
2398 arg->patch[1];
2399 page->audio.port[2].channels = arg->patch[2];
2400 page->audio.port[3].channels = arg->patch[3];
2401 error = cdsetmode(periph, ¶ms);
2402 free(params.mode_buf, M_TEMP);
2403 }
2404 break;
2405 case CDIOCGETVOL:
2406 {
2407 struct ioc_vol *arg = (struct ioc_vol *) addr;
2408 struct cd_mode_params params;
2409 union cd_pages *page;
2410
2411 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2412 ("trying to do CDIOCGETVOL\n"));
2413
2414 params.alloc_len = sizeof(union cd_mode_data_6_10);
2415 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2416 M_WAITOK | M_ZERO);
2417 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2418 if (error) {
2419 free(params.mode_buf, M_TEMP);
2420 break;
2421 }
2422 page = cdgetpage(¶ms);
2423
2424 arg->vol[LEFT_PORT] =
2425 page->audio.port[LEFT_PORT].volume;
2426 arg->vol[RIGHT_PORT] =
2427 page->audio.port[RIGHT_PORT].volume;
2428 arg->vol[2] = page->audio.port[2].volume;
2429 arg->vol[3] = page->audio.port[3].volume;
2430 free(params.mode_buf, M_TEMP);
2431 }
2432 break;
2433 case CDIOCSETVOL:
2434 {
2435 struct ioc_vol *arg = (struct ioc_vol *) addr;
2436 struct cd_mode_params params;
2437 union cd_pages *page;
2438
2439 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2440 ("trying to do CDIOCSETVOL\n"));
2441
2442 params.alloc_len = sizeof(union cd_mode_data_6_10);
2443 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2444 M_WAITOK | M_ZERO);
2445 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2446 if (error) {
2447 free(params.mode_buf, M_TEMP);
2448 break;
2449 }
2450 page = cdgetpage(¶ms);
2451
2452 page->audio.port[LEFT_PORT].channels = CHANNEL_0;
2453 page->audio.port[LEFT_PORT].volume =
2454 arg->vol[LEFT_PORT];
2455 page->audio.port[RIGHT_PORT].channels = CHANNEL_1;
2456 page->audio.port[RIGHT_PORT].volume =
2457 arg->vol[RIGHT_PORT];
2458 page->audio.port[2].volume = arg->vol[2];
2459 page->audio.port[3].volume = arg->vol[3];
2460 error = cdsetmode(periph, ¶ms);
2461 free(params.mode_buf, M_TEMP);
2462 }
2463 break;
2464 case CDIOCSETMONO:
2465 {
2466 struct cd_mode_params params;
2467 union cd_pages *page;
2468
2469 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2470 ("trying to do CDIOCSETMONO\n"));
2471
2472 params.alloc_len = sizeof(union cd_mode_data_6_10);
2473 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2474 M_WAITOK | M_ZERO);
2475 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2476 if (error) {
2477 free(params.mode_buf, M_TEMP);
2478 break;
2479 }
2480 page = cdgetpage(¶ms);
2481
2482 page->audio.port[LEFT_PORT].channels =
2483 LEFT_CHANNEL | RIGHT_CHANNEL;
2484 page->audio.port[RIGHT_PORT].channels =
2485 LEFT_CHANNEL | RIGHT_CHANNEL;
2486 page->audio.port[2].channels = 0;
2487 page->audio.port[3].channels = 0;
2488 error = cdsetmode(periph, ¶ms);
2489 free(params.mode_buf, M_TEMP);
2490 }
2491 break;
2492 case CDIOCSETSTEREO:
2493 {
2494 struct cd_mode_params params;
2495 union cd_pages *page;
2496
2497 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2498 ("trying to do CDIOCSETSTEREO\n"));
2499
2500 params.alloc_len = sizeof(union cd_mode_data_6_10);
2501 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2502 M_WAITOK | M_ZERO);
2503 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2504 if (error) {
2505 free(params.mode_buf, M_TEMP);
2506 break;
2507 }
2508 page = cdgetpage(¶ms);
2509
2510 page->audio.port[LEFT_PORT].channels =
2511 LEFT_CHANNEL;
2512 page->audio.port[RIGHT_PORT].channels =
2513 RIGHT_CHANNEL;
2514 page->audio.port[2].channels = 0;
2515 page->audio.port[3].channels = 0;
2516 error = cdsetmode(periph, ¶ms);
2517 free(params.mode_buf, M_TEMP);
2518 }
2519 break;
2520 case CDIOCSETMUTE:
2521 {
2522 struct cd_mode_params params;
2523 union cd_pages *page;
2524
2525 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2526 ("trying to do CDIOCSETMUTE\n"));
2527
2528 params.alloc_len = sizeof(union cd_mode_data_6_10);
2529 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2530 M_WAITOK | M_ZERO);
2531 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2532 if (error) {
2533 free(¶ms, M_TEMP);
2534 break;
2535 }
2536 page = cdgetpage(¶ms);
2537
2538 page->audio.port[LEFT_PORT].channels = 0;
2539 page->audio.port[RIGHT_PORT].channels = 0;
2540 page->audio.port[2].channels = 0;
2541 page->audio.port[3].channels = 0;
2542 error = cdsetmode(periph, ¶ms);
2543 free(params.mode_buf, M_TEMP);
2544 }
2545 break;
2546 case CDIOCSETLEFT:
2547 {
2548 struct cd_mode_params params;
2549 union cd_pages *page;
2550
2551 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2552 ("trying to do CDIOCSETLEFT\n"));
2553
2554 params.alloc_len = sizeof(union cd_mode_data_6_10);
2555 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2556 M_WAITOK | M_ZERO);
2557
2558 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2559 if (error) {
2560 free(params.mode_buf, M_TEMP);
2561 break;
2562 }
2563 page = cdgetpage(¶ms);
2564
2565 page->audio.port[LEFT_PORT].channels = LEFT_CHANNEL;
2566 page->audio.port[RIGHT_PORT].channels = LEFT_CHANNEL;
2567 page->audio.port[2].channels = 0;
2568 page->audio.port[3].channels = 0;
2569 error = cdsetmode(periph, ¶ms);
2570 free(params.mode_buf, M_TEMP);
2571 }
2572 break;
2573 case CDIOCSETRIGHT:
2574 {
2575 struct cd_mode_params params;
2576 union cd_pages *page;
2577
2578 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2579 ("trying to do CDIOCSETRIGHT\n"));
2580
2581 params.alloc_len = sizeof(union cd_mode_data_6_10);
2582 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2583 M_WAITOK | M_ZERO);
2584
2585 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2586 if (error) {
2587 free(params.mode_buf, M_TEMP);
2588 break;
2589 }
2590 page = cdgetpage(¶ms);
2591
2592 page->audio.port[LEFT_PORT].channels = RIGHT_CHANNEL;
2593 page->audio.port[RIGHT_PORT].channels = RIGHT_CHANNEL;
2594 page->audio.port[2].channels = 0;
2595 page->audio.port[3].channels = 0;
2596 error = cdsetmode(periph, ¶ms);
2597 free(params.mode_buf, M_TEMP);
2598 }
2599 break;
2600 case CDIOCRESUME:
2601 error = cdpause(periph, 1);
2602 break;
2603 case CDIOCPAUSE:
2604 error = cdpause(periph, 0);
2605 break;
2606 case CDIOCSTART:
2607 error = cdstartunit(periph, 0);
2608 break;
2609 case CDIOCCLOSE:
2610 error = cdstartunit(periph, 1);
2611 break;
2612 case CDIOCSTOP:
2613 error = cdstopunit(periph, 0);
2614 break;
2615 case CDIOCEJECT:
2616 error = cdstopunit(periph, 1);
2617 break;
2618 case CDIOCALLOW:
2619 cdprevent(periph, PR_ALLOW);
2620 break;
2621 case CDIOCPREVENT:
2622 cdprevent(periph, PR_PREVENT);
2623 break;
2624 case CDIOCSETDEBUG:
2625 /* sc_link->flags |= (SDEV_DB1 | SDEV_DB2); */
2626 error = ENOTTY;
2627 break;
2628 case CDIOCCLRDEBUG:
2629 /* sc_link->flags &= ~(SDEV_DB1 | SDEV_DB2); */
2630 error = ENOTTY;
2631 break;
2632 case CDIOCRESET:
2633 /* return (cd_reset(periph)); */
2634 error = ENOTTY;
2635 break;
2636 case CDRIOCREADSPEED:
2637 error = cdsetspeed(periph, *(u_int32_t *)addr, CDR_MAX_SPEED);
2638 break;
2639 case CDRIOCWRITESPEED:
2640 error = cdsetspeed(periph, CDR_MAX_SPEED, *(u_int32_t *)addr);
2641 break;
2642 case DVDIOCSENDKEY:
2643 case DVDIOCREPORTKEY: {
2644 struct dvd_authinfo *authinfo;
2645
2646 authinfo = (struct dvd_authinfo *)addr;
2647
2648 if (cmd == DVDIOCREPORTKEY)
2649 error = cdreportkey(periph, authinfo);
2650 else
2651 error = cdsendkey(periph, authinfo);
2652 break;
2653 }
2654 case DVDIOCREADSTRUCTURE: {
2655 struct dvd_struct *dvdstruct;
2656
2657 dvdstruct = (struct dvd_struct *)addr;
2658
2659 error = cdreaddvdstructure(periph, dvdstruct);
2660
2661 break;
2662 }
2663 default:
2664 error = cam_periph_ioctl(periph, cmd, addr, cderror);
2665 break;
2666 }
2667
2668 cam_periph_unlock(periph);
2669
2670 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("leaving cdioctl\n"));
2671 if (error && bootverbose) {
2672 printf("scsi_cd.c::ioctl cmd=%08lx error=%d\n", cmd, error);
2673 }
2674
2675 return (error);
2676}
2677
2678static void
2679cdprevent(struct cam_periph *periph, int action)
2680{
2681 union ccb *ccb;
--- 182 unchanged lines hidden (view full) ---
2864 int error;
2865
2866 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdsize\n"));
2867
2868 softc = (struct cd_softc *)periph->softc;
2869
2870 ccb = cdgetccb(periph, /* priority */ 1);
2871
2872 rcap_buf = malloc(sizeof(struct scsi_read_capacity_data),
2873 M_TEMP, M_WAITOK);
2874
2875 scsi_read_capacity(&ccb->csio,
2876 /*retries*/ 1,
2877 cddone,
2878 MSG_SIMPLE_Q_TAG,
2879 rcap_buf,
2880 SSD_FULL_SIZE,
2881 /* timeout */20000);
--- 1347 unchanged lines hidden ---
2 * Copyright (c) 1997 Justin T. Gibbs.
3 * Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 Kenneth D. Merry.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
--- 32 unchanged lines hidden (view full) ---
41 * functioning of this software in any circumstances.
42 *
43 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
44 *
45 * from: cd.c,v 1.83 1997/05/04 15:24:22 joerg Exp $
46 */
47
48#include <sys/cdefs.h>
49__FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_cd.c 164906 2006-12-05 07:45:28Z mjacob $");
50
51#include "opt_cd.h"
52
53#include <sys/param.h>
54#include <sys/systm.h>
55#include <sys/kernel.h>
56#include <sys/bio.h>
57#include <sys/conf.h>
--- 7 unchanged lines hidden (view full) ---
65#include <sys/taskqueue.h>
66#include <geom/geom_disk.h>
67
68#include <cam/cam.h>
69#include <cam/cam_ccb.h>
70#include <cam/cam_periph.h>
71#include <cam/cam_xpt_periph.h>
72#include <cam/cam_queue.h>
73
74#include <cam/scsi/scsi_message.h>
75#include <cam/scsi/scsi_da.h>
76#include <cam/scsi/scsi_cd.h>
77
78#define LEADOUT 0xaa /* leadout toc entry */
79
80struct cd_params {
--- 17 unchanged lines hidden (view full) ---
98 CD_FLAG_DISC_REMOVABLE = 0x0008,
99 CD_FLAG_TAGGED_QUEUING = 0x0010,
100 CD_FLAG_CHANGER = 0x0040,
101 CD_FLAG_ACTIVE = 0x0080,
102 CD_FLAG_SCHED_ON_COMP = 0x0100,
103 CD_FLAG_RETRY_UA = 0x0200,
104 CD_FLAG_VALID_MEDIA = 0x0400,
105 CD_FLAG_VALID_TOC = 0x0800,
106 CD_FLAG_SCTX_INIT = 0x1000
107} cd_flags;
108
109typedef enum {
110 CD_CCB_PROBE = 0x01,
111 CD_CCB_BUFFER_IO = 0x02,
112 CD_CCB_WAITING = 0x03,
113 CD_CCB_TYPE_MASK = 0x0F,
114 CD_CCB_RETRY_UA = 0x10
--- 170 unchanged lines hidden (view full) ---
285static struct periph_driver cddriver =
286{
287 cdinit, "cd",
288 TAILQ_HEAD_INITIALIZER(cddriver.units), /* generation */ 0
289};
290
291PERIPHDRIVER_DECLARE(cd, cddriver);
292
293
294static int num_changers;
295
296#ifndef CHANGER_MIN_BUSY_SECONDS
297#define CHANGER_MIN_BUSY_SECONDS 5
298#endif
299#ifndef CHANGER_MAX_BUSY_SECONDS
300#define CHANGER_MAX_BUSY_SECONDS 15
301#endif
302
303static int changer_min_busy_seconds = CHANGER_MIN_BUSY_SECONDS;
--- 10 unchanged lines hidden (view full) ---
314
315struct cdchanger {
316 path_id_t path_id;
317 target_id_t target_id;
318 int num_devices;
319 struct camq devq;
320 struct timeval start_time;
321 struct cd_softc *cur_device;
322 struct callout_handle short_handle;
323 struct callout_handle long_handle;
324 volatile cd_changer_flags flags;
325 STAILQ_ENTRY(cdchanger) changer_links;
326 STAILQ_HEAD(chdevlist, cd_softc) chluns;
327};
328
329static STAILQ_HEAD(changerlist, cdchanger) changerq;
330
331
332static void
333cdinit(void)
334{
335 cam_status status;
336 struct cam_path *path;
337
338 /*
339 * Install a global async callback. This callback will
340 * receive async callbacks like "new device found".
341 */
342 status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID,
343 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
344
345 if (status == CAM_REQ_CMP) {
--- 13 unchanged lines hidden (view full) ---
359 printf("cd: Failed to attach master async callback "
360 "due to status 0x%x!\n", status);
361 }
362}
363
364static void
365cdoninvalidate(struct cam_periph *periph)
366{
367 int s;
368 struct cd_softc *softc;
369 struct ccb_setasync csa;
370
371 softc = (struct cd_softc *)periph->softc;
372
373 /*
374 * De-register any async callbacks.
375 */
376 xpt_setup_ccb(&csa.ccb_h, periph->path,
377 /* priority */ 5);
378 csa.ccb_h.func_code = XPT_SASYNC_CB;
379 csa.event_enable = 0;
380 csa.callback = cdasync;
381 csa.callback_arg = periph;
382 xpt_action((union ccb *)&csa);
383
384 softc->flags |= CD_FLAG_INVALID;
385
386 /*
387 * Although the oninvalidate() routines are always called at
388 * splsoftcam, we need to be at splbio() here to keep the buffer
389 * queue from being modified while we traverse it.
390 */
391 s = splbio();
392
393 /*
394 * Return all queued I/O with ENXIO.
395 * XXX Handle any transactions queued to the card
396 * with XPT_ABORT_CCB.
397 */
398 bioq_flush(&softc->bio_queue, NULL, ENXIO);
399 splx(s);
400
401 /*
402 * If this device is part of a changer, and it was scheduled
403 * to run, remove it from the run queue since we just nuked
404 * all of its scheduled I/O.
405 */
406 if ((softc->flags & CD_FLAG_CHANGER)
407 && (softc->pinfo.index != CAM_UNQUEUED_INDEX))
408 camq_remove(&softc->changer->devq, softc->pinfo.index);
409
410 disk_gone(softc->disk);
411 xpt_print(periph->path, "lost device\n");
412}
413
414static void
415cdcleanup(struct cam_periph *periph)
416{
417 struct cd_softc *softc;
418 int s;
419
420 softc = (struct cd_softc *)periph->softc;
421
422 xpt_print(periph->path, "removing device entry\n");
423
424 if ((softc->flags & CD_FLAG_SCTX_INIT) != 0
425 && sysctl_ctx_free(&softc->sysctl_ctx) != 0) {
426 xpt_print(periph->path, "can't remove sysctl context\n");
427 }
428
429 s = splsoftcam();
430 /*
431 * In the queued, non-active case, the device in question
432 * has already been removed from the changer run queue. Since this
433 * device is active, we need to de-activate it, and schedule
434 * another device to run. (if there is another one to run)
435 */
436 if ((softc->flags & CD_FLAG_CHANGER)
437 && (softc->flags & CD_FLAG_ACTIVE)) {
--- 13 unchanged lines hidden (view full) ---
451 * bogus pointer reference.
452 *
453 * The long timeout doesn't really matter, since we
454 * decrement the qfrozen_cnt to indicate that there is
455 * nothing in the active slot now. Therefore, there won't
456 * be any bogus pointer references there.
457 */
458 if (softc->changer->flags & CHANGER_SHORT_TMOUT_SCHED) {
459 untimeout(cdshorttimeout, softc->changer,
460 softc->changer->short_handle);
461 softc->changer->flags &= ~CHANGER_SHORT_TMOUT_SCHED;
462 }
463 softc->changer->devq.qfrozen_cnt--;
464 softc->changer->flags |= CHANGER_MANUAL_CALL;
465 cdrunchangerqueue(softc->changer);
466 }
467
468 /*
--- 4 unchanged lines hidden (view full) ---
473 && (--softc->changer->num_devices == 0)) {
474
475 /*
476 * Theoretically, there shouldn't be any timeouts left, but
477 * I'm not completely sure that that will be the case. So,
478 * it won't hurt to check and see if there are any left.
479 */
480 if (softc->changer->flags & CHANGER_TIMEOUT_SCHED) {
481 untimeout(cdrunchangerqueue, softc->changer,
482 softc->changer->long_handle);
483 softc->changer->flags &= ~CHANGER_TIMEOUT_SCHED;
484 }
485
486 if (softc->changer->flags & CHANGER_SHORT_TMOUT_SCHED) {
487 untimeout(cdshorttimeout, softc->changer,
488 softc->changer->short_handle);
489 softc->changer->flags &= ~CHANGER_SHORT_TMOUT_SCHED;
490 }
491
492 STAILQ_REMOVE(&changerq, softc->changer, cdchanger,
493 changer_links);
494 xpt_print(periph->path, "removing changer entry\n");
495 free(softc->changer, M_DEVBUF);
496 num_changers--;
497 }
498 disk_destroy(softc->disk);
499 free(softc, M_DEVBUF);
500 splx(s);
501}
502
503static void
504cdasync(void *callback_arg, u_int32_t code,
505 struct cam_path *path, void *arg)
506{
507 struct cam_periph *periph;
508
--- 30 unchanged lines hidden (view full) ---
539
540 break;
541 }
542 case AC_SENT_BDR:
543 case AC_BUS_RESET:
544 {
545 struct cd_softc *softc;
546 struct ccb_hdr *ccbh;
547 int s;
548
549 softc = (struct cd_softc *)periph->softc;
550 s = splsoftcam();
551 /*
552 * Don't fail on the expected unit attention
553 * that will occur.
554 */
555 softc->flags |= CD_FLAG_RETRY_UA;
556 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
557 ccbh->ccb_state |= CD_CCB_RETRY_UA;
558 splx(s);
559 /* FALLTHROUGH */
560 }
561 default:
562 cam_periph_async(periph, code, path, arg);
563 break;
564 }
565}
566
567static void
568cdsysctlinit(void *context, int pending)
569{
570 struct cam_periph *periph;
571 struct cd_softc *softc;
572 char tmpstr[80], tmpstr2[80];
573
574 periph = (struct cam_periph *)context;
575 softc = (struct cd_softc *)periph->softc;
576
577 snprintf(tmpstr, sizeof(tmpstr), "CAM CD unit %d", periph->unit_number);
578 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
579
580 mtx_lock(&Giant);
581
582 sysctl_ctx_init(&softc->sysctl_ctx);
583 softc->flags |= CD_FLAG_SCTX_INIT;
584 softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
585 SYSCTL_STATIC_CHILDREN(_kern_cam_cd), OID_AUTO,
586 tmpstr2, CTLFLAG_RD, 0, tmpstr);
587
588 if (softc->sysctl_tree == NULL) {
589 printf("cdsysctlinit: unable to allocate sysctl tree\n");
590 mtx_unlock(&Giant);
591 return;
592 }
593
594 /*
595 * Now register the sysctl handler, so the user can the value on
596 * the fly.
597 */
598 SYSCTL_ADD_PROC(&softc->sysctl_ctx,SYSCTL_CHILDREN(softc->sysctl_tree),
599 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
600 &softc->minimum_command_size, 0, cdcmdsizesysctl, "I",
601 "Minimum CDB size");
602
603 mtx_unlock(&Giant);
604}
605
606/*
607 * We have a handler function for this so we can check the values when the
608 * user sets them, instead of every time we look at them.
609 */
610static int
611cdcmdsizesysctl(SYSCTL_HANDLER_ARGS)
--- 117 unchanged lines hidden (view full) ---
729 * yet. Unlike other SCSI peripheral drivers, we explicitly set
730 * the device type here to be CDROM, rather than just ORing in
731 * the device type. This is because this driver can attach to either
732 * CDROM or WORM devices, and we want this peripheral driver to
733 * show up in the devstat list as a CD peripheral driver, not a
734 * WORM peripheral driver. WORM drives will also have the WORM
735 * driver attached to them.
736 */
737 softc->disk = disk_alloc();
738 softc->disk->d_devstat = devstat_new_entry("cd",
739 periph->unit_number, 0,
740 DEVSTAT_BS_UNAVAILABLE,
741 DEVSTAT_TYPE_CDROM | DEVSTAT_TYPE_IF_SCSI,
742 DEVSTAT_PRIORITY_CD);
743 softc->disk->d_open = cdopen;
744 softc->disk->d_close = cdclose;
745 softc->disk->d_strategy = cdstrategy;
746 softc->disk->d_ioctl = cdioctl;
747 softc->disk->d_name = "cd";
748 softc->disk->d_unit = periph->unit_number;
749 softc->disk->d_drv1 = periph;
750 softc->disk->d_flags = DISKFLAG_NEEDSGIANT;
751 disk_create(softc->disk, DISK_VERSION);
752
753 /*
754 * Add an async callback so that we get
755 * notified if this device goes away.
756 */
757 xpt_setup_ccb(&csa.ccb_h, periph->path,
758 /* priority */ 5);
759 csa.ccb_h.func_code = XPT_SASYNC_CB;
--- 18 unchanged lines hidden (view full) ---
778 struct cam_periph *nperiph;
779 struct cam_path *path;
780 cam_status status;
781 int found;
782
783 /* Set the changer flag in the current device's softc */
784 softc->flags |= CD_FLAG_CHANGER;
785
786 if (num_changers == 0)
787 STAILQ_INIT(&changerq);
788
789 /*
790 * Now, look around for an existing changer device with the
791 * same path and target ID as the current device.
792 */
793 for (found = 0,
794 nchanger = (struct cdchanger *)STAILQ_FIRST(&changerq);
795 nchanger != NULL;
796 nchanger = STAILQ_NEXT(nchanger, changer_links)){
797 if ((nchanger->path_id == cgd->ccb_h.path_id)
798 && (nchanger->target_id == cgd->ccb_h.target_id)) {
799 found = 1;
800 break;
801 }
802 }
803
804 /*
805 * If we found a matching entry, just add this device to
806 * the list of devices on this changer.
807 */
808 if (found == 1) {
809 struct chdevlist *chlunhead;
810
--- 89 unchanged lines hidden (view full) ---
900
901 if (camq_init(&nchanger->devq, 1) != 0) {
902 softc->flags &= ~CD_FLAG_CHANGER;
903 printf("cdregister: changer support "
904 "disabled\n");
905 goto cdregisterexit;
906 }
907
908 num_changers++;
909
910 nchanger->path_id = cgd->ccb_h.path_id;
911 nchanger->target_id = cgd->ccb_h.target_id;
912
913 /* this is superfluous, but it makes things clearer */
914 nchanger->num_devices = 0;
915
916 STAILQ_INIT(&nchanger->chluns);
917
918 STAILQ_INSERT_TAIL(&changerq, nchanger,
919 changer_links);
920
921 /*
922 * Create a path with lun id 0, and see if we can
923 * find a matching device
924 */
925 status = xpt_create_path(&path, /*periph*/ periph,
926 cgd->ccb_h.path_id,
927 cgd->ccb_h.target_id, 0);
--- 45 unchanged lines hidden (view full) ---
973 }
974 STAILQ_INSERT_TAIL(&nchanger->chluns, softc,
975 changer_links);
976 }
977 }
978
979cdregisterexit:
980
981 /* Lock this peripheral until we are setup */
982 /* Can't block */
983 cam_periph_lock(periph, PRIBIO);
984
985 if ((softc->flags & CD_FLAG_CHANGER) == 0)
986 xpt_schedule(periph, /*priority*/5);
987 else
988 cdschedule(periph, /*priority*/ 5);
989
990 return(CAM_REQ_CMP);
991}
992
993static int
994cdopen(struct disk *dp)
995{
996 struct cam_periph *periph;
997 struct cd_softc *softc;
998 int error;
999 int s;
1000
1001 periph = (struct cam_periph *)dp->d_drv1;
1002 if (periph == NULL)
1003 return (ENXIO);
1004
1005 softc = (struct cd_softc *)periph->softc;
1006
1007 /*
1008 * Grab splsoftcam and hold it until we lock the peripheral.
1009 */
1010 s = splsoftcam();
1011 if (softc->flags & CD_FLAG_INVALID) {
1012 splx(s);
1013 return(ENXIO);
1014 }
1015
1016 if ((error = cam_periph_lock(periph, PRIBIO | PCATCH)) != 0) {
1017 splx(s);
1018 return (error);
1019 }
1020
1021 splx(s);
1022
1023 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
1024 return(ENXIO);
1025
1026 /*
1027 * Check for media, and set the appropriate flags. We don't bail
1028 * if we don't have media, but then we don't allow anything but the
1029 * CDIOCEJECT/CDIOCCLOSE ioctls if there is no media.
1030 */
1031 cdcheckmedia(periph);
1032
1033 cam_periph_unlock(periph);
1034
1035 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("leaving cdopen\n"));
1036
1037 return (error);
1038}
1039
1040static int
1041cdclose(struct disk *dp)
1042{
1043 struct cam_periph *periph;
1044 struct cd_softc *softc;
1045 int error;
1046
1047 periph = (struct cam_periph *)dp->d_drv1;
1048 if (periph == NULL)
1049 return (ENXIO);
1050
1051 softc = (struct cd_softc *)periph->softc;
1052
1053 if ((error = cam_periph_lock(periph, PRIBIO)) != 0)
1054 return (error);
1055
1056 if ((softc->flags & CD_FLAG_DISC_REMOVABLE) != 0)
1057 cdprevent(periph, PR_ALLOW);
1058
1059 /*
1060 * Since we're closing this CD, mark the blocksize as unavailable.
1061 * It will be marked as available when the CD is opened again.
1062 */
1063 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1064
1065 /*
1066 * We'll check the media and toc again at the next open().
1067 */
1068 softc->flags &= ~(CD_FLAG_VALID_MEDIA|CD_FLAG_VALID_TOC);
1069
1070 cam_periph_unlock(periph);
1071 cam_periph_release(periph);
1072
1073 return (0);
1074}
1075
1076static void
1077cdshorttimeout(void *arg)
1078{
1079 struct cdchanger *changer;
1080 int s;
1081
1082 s = splsoftcam();
1083
1084 changer = (struct cdchanger *)arg;
1085
1086 /* Always clear the short timeout flag, since that's what we're in */
1087 changer->flags &= ~CHANGER_SHORT_TMOUT_SCHED;
1088
1089 /*
1090 * Check to see if there is any more pending or outstanding I/O for
1091 * this device. If not, move it out of the active slot.
1092 */
1093 if ((bioq_first(&changer->cur_device->bio_queue) == NULL)
1094 && (changer->cur_device->outstanding_cmds == 0)) {
1095 changer->flags |= CHANGER_MANUAL_CALL;
1096 cdrunchangerqueue(changer);
1097 }
1098
1099 splx(s);
1100}
1101
1102/*
1103 * This is a wrapper for xpt_schedule. It only applies to changers.
1104 */
1105static void
1106cdschedule(struct cam_periph *periph, int priority)
1107{
1108 struct cd_softc *softc;
1109 int s;
1110
1111 s = splsoftcam();
1112
1113 softc = (struct cd_softc *)periph->softc;
1114
1115 /*
1116 * If this device isn't currently queued, and if it isn't
1117 * the active device, then we queue this device and run the
1118 * changer queue if there is no timeout scheduled to do it.
1119 * If this device is the active device, just schedule it
1120 * to run again. If this device is queued, there should be
--- 21 unchanged lines hidden (view full) ---
1142 && ((softc->changer->flags & CHANGER_NEED_TIMEOUT)==0)
1143 && ((softc->changer->flags & CHANGER_SHORT_TMOUT_SCHED)==0)){
1144 softc->changer->flags |= CHANGER_MANUAL_CALL;
1145 cdrunchangerqueue(softc->changer);
1146 }
1147 } else if ((softc->flags & CD_FLAG_ACTIVE)
1148 && ((softc->flags & CD_FLAG_SCHED_ON_COMP) == 0))
1149 xpt_schedule(periph, priority);
1150
1151 splx(s);
1152
1153}
1154
1155static void
1156cdrunchangerqueue(void *arg)
1157{
1158 struct cd_softc *softc;
1159 struct cdchanger *changer;
1160 int called_from_timeout;
1161 int s;
1162
1163 s = splsoftcam();
1164
1165 changer = (struct cdchanger *)arg;
1166
1167 /*
1168 * If we have NOT been called from cdstrategy() or cddone(), and
1169 * instead from a timeout routine, go ahead and clear the
1170 * timeout flag.
1171 */
1172 if ((changer->flags & CHANGER_MANUAL_CALL) == 0) {
1173 changer->flags &= ~CHANGER_TIMEOUT_SCHED;
1174 called_from_timeout = 1;
1175 } else
1176 called_from_timeout = 0;
1177
1178 /* Always clear the manual call flag */
1179 changer->flags &= ~CHANGER_MANUAL_CALL;
1180
1181 /* nothing to do if the queue is empty */
1182 if (changer->devq.entries <= 0) {
1183 splx(s);
1184 return;
1185 }
1186
1187 /*
1188 * If the changer queue is frozen, that means we have an active
1189 * device.
1190 */
1191 if (changer->devq.qfrozen_cnt > 0) {
1192
1193 if (changer->cur_device->outstanding_cmds > 0) {
1194 changer->cur_device->flags |= CD_FLAG_SCHED_ON_COMP;
1195 changer->cur_device->bufs_left =
1196 changer->cur_device->outstanding_cmds;
1197 if (called_from_timeout) {
1198 changer->long_handle =
1199 timeout(cdrunchangerqueue, changer,
1200 changer_max_busy_seconds * hz);
1201 changer->flags |= CHANGER_TIMEOUT_SCHED;
1202 }
1203 splx(s);
1204 return;
1205 }
1206
1207 /*
1208 * We always need to reset the frozen count and clear the
1209 * active flag.
1210 */
1211 changer->devq.qfrozen_cnt--;
1212 changer->cur_device->flags &= ~CD_FLAG_ACTIVE;
1213 changer->cur_device->flags &= ~CD_FLAG_SCHED_ON_COMP;
1214
1215 /*
1216 * Check to see whether the current device has any I/O left
1217 * to do. If so, requeue it at the end of the queue. If
1218 * not, there is no need to requeue it.
1219 */
1220 if (bioq_first(&changer->cur_device->bio_queue) != NULL) {
1221
1222 changer->cur_device->pinfo.generation =
1223 ++changer->devq.generation;
--- 13 unchanged lines hidden (view full) ---
1237 wakeup(&softc->changer);
1238 xpt_schedule(softc->periph, /*priority*/ 1);
1239
1240 /*
1241 * Get rid of any pending timeouts, and set a flag to schedule new
1242 * ones so this device gets its full time quantum.
1243 */
1244 if (changer->flags & CHANGER_TIMEOUT_SCHED) {
1245 untimeout(cdrunchangerqueue, changer, changer->long_handle);
1246 changer->flags &= ~CHANGER_TIMEOUT_SCHED;
1247 }
1248
1249 if (changer->flags & CHANGER_SHORT_TMOUT_SCHED) {
1250 untimeout(cdshorttimeout, changer, changer->short_handle);
1251 changer->flags &= ~CHANGER_SHORT_TMOUT_SCHED;
1252 }
1253
1254 /*
1255 * We need to schedule timeouts, but we only do this after the
1256 * first transaction has completed. This eliminates the changer
1257 * switch time.
1258 */
1259 changer->flags |= CHANGER_NEED_TIMEOUT;
1260
1261 splx(s);
1262}
1263
1264static void
1265cdchangerschedule(struct cd_softc *softc)
1266{
1267 struct cdchanger *changer;
1268 int s;
1269
1270 s = splsoftcam();
1271
1272 changer = softc->changer;
1273
1274 /*
1275 * If this is a changer, and this is the current device,
1276 * and this device has at least the minimum time quantum to
1277 * run, see if we can switch it out.
1278 */
1279 if ((softc->flags & CD_FLAG_ACTIVE)
--- 28 unchanged lines hidden (view full) ---
1308 && (softc->flags & CD_FLAG_ACTIVE)) {
1309
1310 /*
1311 * Now that the first transaction to this
1312 * particular device has completed, we can go ahead
1313 * and schedule our timeouts.
1314 */
1315 if ((changer->flags & CHANGER_TIMEOUT_SCHED) == 0) {
1316 changer->long_handle =
1317 timeout(cdrunchangerqueue, changer,
1318 changer_max_busy_seconds * hz);
1319 changer->flags |= CHANGER_TIMEOUT_SCHED;
1320 } else
1321 printf("cdchangerschedule: already have a long"
1322 " timeout!\n");
1323
1324 if ((changer->flags & CHANGER_SHORT_TMOUT_SCHED) == 0) {
1325 changer->short_handle =
1326 timeout(cdshorttimeout, changer,
1327 changer_min_busy_seconds * hz);
1328 changer->flags |= CHANGER_SHORT_TMOUT_SCHED;
1329 } else
1330 printf("cdchangerschedule: already have a short "
1331 "timeout!\n");
1332
1333 /*
1334 * We just scheduled timeouts, no need to schedule
1335 * more.
1336 */
1337 changer->flags &= ~CHANGER_NEED_TIMEOUT;
1338
1339 }
1340 splx(s);
1341}
1342
1343static int
1344cdrunccb(union ccb *ccb, int (*error_routine)(union ccb *ccb,
1345 u_int32_t cam_flags,
1346 u_int32_t sense_flags),
1347 u_int32_t cam_flags, u_int32_t sense_flags)
1348{
--- 12 unchanged lines hidden (view full) ---
1361
1362 return(error);
1363}
1364
1365static union ccb *
1366cdgetccb(struct cam_periph *periph, u_int32_t priority)
1367{
1368 struct cd_softc *softc;
1369 int s;
1370
1371 softc = (struct cd_softc *)periph->softc;
1372
1373 if (softc->flags & CD_FLAG_CHANGER) {
1374
1375 s = splsoftcam();
1376
1377 /*
1378 * This should work the first time this device is woken up,
1379 * but just in case it doesn't, we use a while loop.
1380 */
1381 while ((softc->flags & CD_FLAG_ACTIVE) == 0) {
1382 /*
1383 * If this changer isn't already queued, queue it up.
1384 */
--- 6 unchanged lines hidden (view full) ---
1391 }
1392 if (((softc->changer->flags & CHANGER_TIMEOUT_SCHED)==0)
1393 && ((softc->changer->flags & CHANGER_NEED_TIMEOUT)==0)
1394 && ((softc->changer->flags
1395 & CHANGER_SHORT_TMOUT_SCHED)==0)) {
1396 softc->changer->flags |= CHANGER_MANUAL_CALL;
1397 cdrunchangerqueue(softc->changer);
1398 } else
1399 tsleep(&softc->changer, PRIBIO, "cgticb", 0);
1400 }
1401 splx(s);
1402 }
1403 return(cam_periph_getccb(periph, priority));
1404}
1405
1406
1407/*
1408 * Actually translate the requested transfer into one the physical driver
1409 * can understand. The transfer is described by a buf and will include
1410 * only one physical transfer.
1411 */
1412static void
1413cdstrategy(struct bio *bp)
1414{
1415 struct cam_periph *periph;
1416 struct cd_softc *softc;
1417 int s;
1418
1419 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1420 if (periph == NULL) {
1421 biofinish(bp, NULL, ENXIO);
1422 return;
1423 }
1424
1425 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdstrategy\n"));
1426
1427 softc = (struct cd_softc *)periph->softc;
1428
1429 /*
1430 * Mask interrupts so that the pack cannot be invalidated until
1431 * after we are in the queue. Otherwise, we might not properly
1432 * clean up one of the buffers.
1433 */
1434 s = splbio();
1435
1436 /*
1437 * If the device has been made invalid, error out
1438 */
1439 if ((softc->flags & CD_FLAG_INVALID)) {
1440 splx(s);
1441 biofinish(bp, NULL, ENXIO);
1442 return;
1443 }
1444
1445 /*
1446 * If we don't have valid media, look for it before trying to
1447 * schedule the I/O.
1448 */
1449 if ((softc->flags & CD_FLAG_VALID_MEDIA) == 0) {
1450 int error;
1451
1452 error = cdcheckmedia(periph);
1453 if (error != 0) {
1454 splx(s);
1455 biofinish(bp, NULL, error);
1456 return;
1457 }
1458 }
1459
1460 /*
1461 * Place it in the queue of disk activities for this disk
1462 */
1463 bioq_disksort(&softc->bio_queue, bp);
1464
1465 splx(s);
1466
1467 /*
1468 * Schedule ourselves for performing the work. We do things
1469 * differently for changers.
1470 */
1471 if ((softc->flags & CD_FLAG_CHANGER) == 0)
1472 xpt_schedule(periph, /* XXX priority */1);
1473 else
1474 cdschedule(periph, /* priority */ 1);
1475
1476 return;
1477}
1478
1479static void
1480cdstart(struct cam_periph *periph, union ccb *start_ccb)
1481{
1482 struct cd_softc *softc;
1483 struct bio *bp;
1484 struct ccb_scsiio *csio;
1485 struct scsi_read_capacity_data *rcap;
1486 int s;
1487
1488 softc = (struct cd_softc *)periph->softc;
1489
1490 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdstart\n"));
1491
1492 switch (softc->state) {
1493 case CD_STATE_NORMAL:
1494 {
1495 int oldspl;
1496
1497 s = splbio();
1498 bp = bioq_first(&softc->bio_queue);
1499 if (periph->immediate_priority <= periph->pinfo.priority) {
1500 start_ccb->ccb_h.ccb_state = CD_CCB_WAITING;
1501
1502 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
1503 periph_links.sle);
1504 periph->immediate_priority = CAM_PRIORITY_NONE;
1505 splx(s);
1506 wakeup(&periph->ccb_list);
1507 } else if (bp == NULL) {
1508 splx(s);
1509 xpt_release_ccb(start_ccb);
1510 } else {
1511 bioq_remove(&softc->bio_queue, bp);
1512
1513 devstat_start_transaction_bio(softc->disk->d_devstat, bp);
1514
1515 scsi_read_write(&start_ccb->csio,
1516 /*retries*/4,
--- 7 unchanged lines hidden (view full) ---
1524 bp->bio_bcount / softc->params.blksize,
1525 /* data_ptr */ bp->bio_data,
1526 /* dxfer_len */ bp->bio_bcount,
1527 /* sense_len */ SSD_FULL_SIZE,
1528 /* timeout */ 30000);
1529 start_ccb->ccb_h.ccb_state = CD_CCB_BUFFER_IO;
1530
1531
1532 /*
1533 * Block out any asyncronous callbacks
1534 * while we touch the pending ccb list.
1535 */
1536 oldspl = splcam();
1537 LIST_INSERT_HEAD(&softc->pending_ccbs,
1538 &start_ccb->ccb_h, periph_links.le);
1539 softc->outstanding_cmds++;
1540 splx(oldspl);
1541
1542 /* We expect a unit attention from this device */
1543 if ((softc->flags & CD_FLAG_RETRY_UA) != 0) {
1544 start_ccb->ccb_h.ccb_state |= CD_CCB_RETRY_UA;
1545 softc->flags &= ~CD_FLAG_RETRY_UA;
1546 }
1547
1548 start_ccb->ccb_h.ccb_bp = bp;
1549 bp = bioq_first(&softc->bio_queue);
1550 splx(s);
1551
1552 xpt_action(start_ccb);
1553 }
1554 if (bp != NULL) {
1555 /* Have more work to do, so ensure we stay scheduled */
1556 xpt_schedule(periph, /* XXX priority */1);
1557 }
1558 break;
--- 37 unchanged lines hidden (view full) ---
1596 softc = (struct cd_softc *)periph->softc;
1597 csio = &done_ccb->csio;
1598
1599 switch (csio->ccb_h.ccb_state & CD_CCB_TYPE_MASK) {
1600 case CD_CCB_BUFFER_IO:
1601 {
1602 struct bio *bp;
1603 int error;
1604 int oldspl;
1605
1606 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
1607 error = 0;
1608
1609 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1610 int sf;
1611
1612 if ((done_ccb->ccb_h.ccb_state & CD_CCB_RETRY_UA) != 0)
--- 7 unchanged lines hidden (view full) ---
1620 * A retry was scheuled, so
1621 * just return.
1622 */
1623 return;
1624 }
1625 }
1626
1627 if (error != 0) {
1628 int s;
1629
1630 xpt_print(periph->path,
1631 "cddone: got error %#x back\n", error);
1632 s = splbio();
1633 bioq_flush(&softc->bio_queue, NULL, EIO);
1634 splx(s);
1635 bp->bio_resid = bp->bio_bcount;
1636 bp->bio_error = error;
1637 bp->bio_flags |= BIO_ERROR;
1638 cam_release_devq(done_ccb->ccb_h.path,
1639 /*relsim_flags*/0,
1640 /*reduction*/0,
1641 /*timeout*/0,
1642 /*getcount_only*/0);
--- 6 unchanged lines hidden (view full) ---
1649 * Short transfer ???
1650 * XXX: not sure this is correct for partial
1651 * transfers at EOM
1652 */
1653 bp->bio_flags |= BIO_ERROR;
1654 }
1655 }
1656
1657 /*
1658 * Block out any asyncronous callbacks
1659 * while we touch the pending ccb list.
1660 */
1661 oldspl = splcam();
1662 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
1663 softc->outstanding_cmds--;
1664 splx(oldspl);
1665
1666 if (softc->flags & CD_FLAG_CHANGER)
1667 cdchangerschedule(softc);
1668
1669 biofinish(bp, NULL, 0);
1670 break;
1671 }
1672 case CD_CCB_PROBE:
--- 174 unchanged lines hidden (view full) ---
1847 * Since our peripheral may be invalidated by an error
1848 * above or an external event, we must release our CCB
1849 * before releasing the probe lock on the peripheral.
1850 * The peripheral will only go away once the last lock
1851 * is removed, and we need it around for the CCB release
1852 * operation.
1853 */
1854 xpt_release_ccb(done_ccb);
1855 cam_periph_unlock(periph);
1856 return;
1857 }
1858 case CD_CCB_WAITING:
1859 {
1860 /* Caller will release the CCB */
1861 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
1862 ("trying to wakeup ccbwait\n"));
1863
--- 36 unchanged lines hidden (view full) ---
1900}
1901
1902static int
1903cdioctl(struct disk *dp, u_long cmd, void *addr, int flag, struct thread *td)
1904{
1905
1906 struct cam_periph *periph;
1907 struct cd_softc *softc;
1908 int error, nocopyout;
1909
1910 periph = (struct cam_periph *)dp->d_drv1;
1911 if (periph == NULL)
1912 return(ENXIO);
1913
1914 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdioctl\n"));
1915
1916 softc = (struct cd_softc *)periph->softc;
1917
1918 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
1919 ("trying to do ioctl %#lx\n", cmd));
1920
1921 error = cam_periph_lock(periph, PRIBIO | PCATCH);
1922
1923 if (error != 0)
1924 return(error);
1925 /*
1926 * If we don't have media loaded, check for it. If still don't
1927 * have media loaded, we can only do a load or eject.
1928 *
1929 * We only care whether media is loaded if this is a cd-specific ioctl
1930 * (thus the IOCGROUP check below). Note that this will break if
1931 * anyone adds any ioctls into the switch statement below that don't
1932 * have their ioctl group set to 'c'.
1933 */
1934 if (((softc->flags & CD_FLAG_VALID_MEDIA) == 0)
1935 && ((cmd != CDIOCCLOSE)
1936 && (cmd != CDIOCEJECT))
1937 && (IOCGROUP(cmd) == 'c')) {
1938 error = cdcheckmedia(periph);
1939 if (error != 0) {
1940 cam_periph_unlock(periph);
1941 return (error);
1942 }
1943 }
1944
1945 nocopyout = 0;
1946 switch (cmd) {
1947
1948 case CDIOCPLAYTRACKS:
1949 {
1950 struct ioc_play_track *args
1951 = (struct ioc_play_track *) addr;
1952 struct cd_mode_params params;
1953 union cd_pages *page;
1954
1955 params.alloc_len = sizeof(union cd_mode_data_6_10);
1956 params.mode_buf = malloc(params.alloc_len, M_TEMP,
1957 M_WAITOK | M_ZERO);
1958
1959 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
1960 ("trying to do CDIOCPLAYTRACKS\n"));
1961
1962 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
1963 if (error) {
1964 free(params.mode_buf, M_TEMP);
1965 break;
1966 }
1967 page = cdgetpage(¶ms);
1968
1969 page->audio.flags &= ~CD_PA_SOTC;
1970 page->audio.flags |= CD_PA_IMMED;
1971 error = cdsetmode(periph, ¶ms);
1972 free(params.mode_buf, M_TEMP);
1973 if (error)
1974 break;
1975
1976 /*
1977 * This was originally implemented with the PLAY
1978 * AUDIO TRACK INDEX command, but that command was
1979 * deprecated after SCSI-2. Most (all?) SCSI CDROM
1980 * drives support it but ATAPI and ATAPI-derivative
1981 * drives don't seem to support it. So we keep a
1982 * cache of the table of contents and translate
--- 45 unchanged lines hidden (view full) ---
2028 bin2bcd(args->end_track);
2029 }
2030 error = cdplaytracks(periph,
2031 args->start_track,
2032 args->start_index,
2033 args->end_track,
2034 args->end_index);
2035 }
2036 }
2037 break;
2038 case CDIOCPLAYMSF:
2039 {
2040 struct ioc_play_msf *args
2041 = (struct ioc_play_msf *) addr;
2042 struct cd_mode_params params;
2043 union cd_pages *page;
2044
2045 params.alloc_len = sizeof(union cd_mode_data_6_10);
2046 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2047 M_WAITOK | M_ZERO);
2048
2049 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2050 ("trying to do CDIOCPLAYMSF\n"));
2051
2052 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2053 if (error) {
2054 free(params.mode_buf, M_TEMP);
2055 break;
2056 }
2057 page = cdgetpage(¶ms);
2058
2059 page->audio.flags &= ~CD_PA_SOTC;
2060 page->audio.flags |= CD_PA_IMMED;
2061 error = cdsetmode(periph, ¶ms);
2062 free(params.mode_buf, M_TEMP);
2063 if (error)
2064 break;
2065 error = cdplaymsf(periph,
2066 args->start_m,
2067 args->start_s,
2068 args->start_f,
2069 args->end_m,
2070 args->end_s,
2071 args->end_f);
2072 }
2073 break;
2074 case CDIOCPLAYBLOCKS:
2075 {
2076 struct ioc_play_blocks *args
2077 = (struct ioc_play_blocks *) addr;
2078 struct cd_mode_params params;
2079 union cd_pages *page;
2080
2081 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2082 ("trying to do CDIOCPLAYBLOCKS\n"));
2083
2084 params.alloc_len = sizeof(union cd_mode_data_6_10);
2085 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2086 M_WAITOK | M_ZERO);
2087
2088 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2089 if (error) {
2090 free(params.mode_buf, M_TEMP);
2091 break;
2092 }
2093 page = cdgetpage(¶ms);
2094
2095 page->audio.flags &= ~CD_PA_SOTC;
2096 page->audio.flags |= CD_PA_IMMED;
2097 error = cdsetmode(periph, ¶ms);
2098 free(params.mode_buf, M_TEMP);
2099 if (error)
2100 break;
2101 error = cdplay(periph, args->blk, args->len);
2102 }
2103 break;
2104 case CDIOCREADSUBCHANNEL_SYSSPACE:
2105 nocopyout = 1;
2106 /* Fallthrough */
2107 case CDIOCREADSUBCHANNEL:
2108 {
2109 struct ioc_read_subchannel *args
2110 = (struct ioc_read_subchannel *) addr;
2111 struct cd_sub_channel_info *data;
2112 u_int32_t len = args->data_len;
2113
2114 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2115 ("trying to do CDIOCREADSUBCHANNEL\n"));
2116
2117 data = malloc(sizeof(struct cd_sub_channel_info),
2118 M_TEMP, M_WAITOK);
2119
2120 if ((len > sizeof(struct cd_sub_channel_info)) ||
2121 (len < sizeof(struct cd_sub_channel_header))) {
2122 printf(
2123 "scsi_cd: cdioctl: "
2124 "cdioreadsubchannel: error, len=%d\n",
2125 len);
2126 error = EINVAL;
2127 free(data, M_TEMP);
2128 break;
2129 }
2130
2131 if (softc->quirks & CD_Q_BCD_TRACKS)
2132 args->track = bin2bcd(args->track);
2133
2134 error = cdreadsubchannel(periph, args->address_format,
2135 args->data_format, args->track, data, len);
2136
2137 if (error) {
2138 free(data, M_TEMP);
2139 break;
2140 }
2141 if (softc->quirks & CD_Q_BCD_TRACKS)
2142 data->what.track_info.track_number =
2143 bcd2bin(data->what.track_info.track_number);
2144 len = min(len, ((data->header.data_len[0] << 8) +
2145 data->header.data_len[1] +
2146 sizeof(struct cd_sub_channel_header)));
2147 if (nocopyout == 0) {
2148 if (copyout(data, args->data, len) != 0) {
2149 error = EFAULT;
2150 }
2151 } else {
2152 bcopy(data, args->data, len);
2153 }
2154 free(data, M_TEMP);
2155 }
2156 break;
2157
2158 case CDIOREADTOCHEADER:
2159 {
2160 struct ioc_toc_header *th;
2161
2162 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2163 ("trying to do CDIOREADTOCHEADER\n"));
2164
2165 th = malloc(sizeof(struct ioc_toc_header), M_TEMP,
2166 M_WAITOK);
2167 error = cdreadtoc(periph, 0, 0, (u_int8_t *)th,
2168 sizeof (*th), /*sense_flags*/0);
2169 if (error) {
2170 free(th, M_TEMP);
2171 break;
2172 }
2173 if (softc->quirks & CD_Q_BCD_TRACKS) {
2174 /* we are going to have to convert the BCD
2175 * encoding on the cd to what is expected
2176 */
2177 th->starting_track =
2178 bcd2bin(th->starting_track);
2179 th->ending_track = bcd2bin(th->ending_track);
2180 }
2181 th->len = ntohs(th->len);
2182 bcopy(th, addr, sizeof(*th));
2183 free(th, M_TEMP);
2184 }
2185 break;
2186 case CDIOREADTOCENTRYS:
2187 {
2188 struct cd_tocdata *data;
2189 struct cd_toc_single *lead;
2190 struct ioc_read_toc_entry *te =
2191 (struct ioc_read_toc_entry *) addr;
2192 struct ioc_toc_header *th;
2193 u_int32_t len, readlen, idx, num;
2194 u_int32_t starting_track = te->starting_track;
2195
2196 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2197 ("trying to do CDIOREADTOCENTRYS\n"));
2198
2199 data = malloc(sizeof(*data), M_TEMP, M_WAITOK);
2200 lead = malloc(sizeof(*lead), M_TEMP, M_WAITOK);
2201
2202 if (te->data_len < sizeof(struct cd_toc_entry)
2203 || (te->data_len % sizeof(struct cd_toc_entry)) != 0
2204 || (te->address_format != CD_MSF_FORMAT
2205 && te->address_format != CD_LBA_FORMAT)) {
2206 error = EINVAL;
2207 printf("scsi_cd: error in readtocentries, "
2208 "returning EINVAL\n");
2209 free(data, M_TEMP);
2210 free(lead, M_TEMP);
2211 break;
2212 }
2213
2214 th = &data->header;
2215 error = cdreadtoc(periph, 0, 0, (u_int8_t *)th,
2216 sizeof (*th), /*sense_flags*/0);
2217 if (error) {
2218 free(data, M_TEMP);
2219 free(lead, M_TEMP);
2220 break;
2221 }
2222
2223 if (softc->quirks & CD_Q_BCD_TRACKS) {
2224 /* we are going to have to convert the BCD
2225 * encoding on the cd to what is expected
2226 */
2227 th->starting_track =
--- 6 unchanged lines hidden (view full) ---
2234 else if (starting_track == LEADOUT)
2235 starting_track = th->ending_track + 1;
2236 else if (starting_track < th->starting_track ||
2237 starting_track > th->ending_track + 1) {
2238 printf("scsi_cd: error in readtocentries, "
2239 "returning EINVAL\n");
2240 free(data, M_TEMP);
2241 free(lead, M_TEMP);
2242 error = EINVAL;
2243 break;
2244 }
2245
2246 /* calculate reading length without leadout entry */
2247 readlen = (th->ending_track - starting_track + 1) *
2248 sizeof(struct cd_toc_entry);
2249
--- 5 unchanged lines hidden (view full) ---
2255 readlen = len;
2256 }
2257 if (len > sizeof(data->entries)) {
2258 printf("scsi_cd: error in readtocentries, "
2259 "returning EINVAL\n");
2260 error = EINVAL;
2261 free(data, M_TEMP);
2262 free(lead, M_TEMP);
2263 break;
2264 }
2265 num = len / sizeof(struct cd_toc_entry);
2266
2267 if (readlen > 0) {
2268 error = cdreadtoc(periph, te->address_format,
2269 starting_track,
2270 (u_int8_t *)data,
2271 readlen + sizeof (*th),
2272 /*sense_flags*/0);
2273 if (error) {
2274 free(data, M_TEMP);
2275 free(lead, M_TEMP);
2276 break;
2277 }
2278 }
2279
2280 /* make leadout entry if needed */
2281 idx = starting_track + num - 1;
2282 if (softc->quirks & CD_Q_BCD_TRACKS)
2283 th->ending_track = bcd2bin(th->ending_track);
2284 if (idx == th->ending_track + 1) {
2285 error = cdreadtoc(periph, te->address_format,
2286 LEADOUT, (u_int8_t *)lead,
2287 sizeof(*lead),
2288 /*sense_flags*/0);
2289 if (error) {
2290 free(data, M_TEMP);
2291 free(lead, M_TEMP);
2292 break;
2293 }
2294 data->entries[idx - starting_track] =
2295 lead->entry;
2296 }
2297 if (softc->quirks & CD_Q_BCD_TRACKS) {
2298 for (idx = 0; idx < num - 1; idx++) {
2299 data->entries[idx].track =
2300 bcd2bin(data->entries[idx].track);
2301 }
2302 }
2303
2304 error = copyout(data->entries, te->data, len);
2305 free(data, M_TEMP);
2306 free(lead, M_TEMP);
2307 }
2308 break;
2309 case CDIOREADTOCENTRY:
2310 {
2311 struct cd_toc_single *data;
2312 struct ioc_read_toc_single_entry *te =
2313 (struct ioc_read_toc_single_entry *) addr;
2314 struct ioc_toc_header *th;
2315 u_int32_t track;
2316
2317 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2318 ("trying to do CDIOREADTOCENTRY\n"));
2319
2320 data = malloc(sizeof(*data), M_TEMP, M_WAITOK);
2321
2322 if (te->address_format != CD_MSF_FORMAT
2323 && te->address_format != CD_LBA_FORMAT) {
2324 printf("error in readtocentry, "
2325 " returning EINVAL\n");
2326 free(data, M_TEMP);
2327 error = EINVAL;
2328 break;
2329 }
2330
2331 th = &data->header;
2332 error = cdreadtoc(periph, 0, 0, (u_int8_t *)th,
2333 sizeof (*th), /*sense_flags*/0);
2334 if (error) {
2335 free(data, M_TEMP);
2336 break;
2337 }
2338
2339 if (softc->quirks & CD_Q_BCD_TRACKS) {
2340 /* we are going to have to convert the BCD
2341 * encoding on the cd to what is expected
2342 */
2343 th->starting_track =
--- 6 unchanged lines hidden (view full) ---
2350 else if (track == LEADOUT)
2351 /* OK */;
2352 else if (track < th->starting_track ||
2353 track > th->ending_track + 1) {
2354 printf("error in readtocentry, "
2355 " returning EINVAL\n");
2356 free(data, M_TEMP);
2357 error = EINVAL;
2358 break;
2359 }
2360
2361 error = cdreadtoc(periph, te->address_format, track,
2362 (u_int8_t *)data, sizeof(*data),
2363 /*sense_flags*/0);
2364 if (error) {
2365 free(data, M_TEMP);
2366 break;
2367 }
2368
2369 if (softc->quirks & CD_Q_BCD_TRACKS)
2370 data->entry.track = bcd2bin(data->entry.track);
2371 bcopy(&data->entry, &te->entry,
2372 sizeof(struct cd_toc_entry));
2373 free(data, M_TEMP);
2374 }
2375 break;
2376 case CDIOCSETPATCH:
2377 {
2378 struct ioc_patch *arg = (struct ioc_patch *)addr;
2379 struct cd_mode_params params;
2380 union cd_pages *page;
2381
2382 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2383 ("trying to do CDIOCSETPATCH\n"));
2384
2385 params.alloc_len = sizeof(union cd_mode_data_6_10);
2386 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2387 M_WAITOK | M_ZERO);
2388 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2389 if (error) {
2390 free(params.mode_buf, M_TEMP);
2391 break;
2392 }
2393 page = cdgetpage(¶ms);
2394
2395 page->audio.port[LEFT_PORT].channels =
2396 arg->patch[0];
2397 page->audio.port[RIGHT_PORT].channels =
2398 arg->patch[1];
2399 page->audio.port[2].channels = arg->patch[2];
2400 page->audio.port[3].channels = arg->patch[3];
2401 error = cdsetmode(periph, ¶ms);
2402 free(params.mode_buf, M_TEMP);
2403 }
2404 break;
2405 case CDIOCGETVOL:
2406 {
2407 struct ioc_vol *arg = (struct ioc_vol *) addr;
2408 struct cd_mode_params params;
2409 union cd_pages *page;
2410
2411 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2412 ("trying to do CDIOCGETVOL\n"));
2413
2414 params.alloc_len = sizeof(union cd_mode_data_6_10);
2415 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2416 M_WAITOK | M_ZERO);
2417 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2418 if (error) {
2419 free(params.mode_buf, M_TEMP);
2420 break;
2421 }
2422 page = cdgetpage(¶ms);
2423
2424 arg->vol[LEFT_PORT] =
2425 page->audio.port[LEFT_PORT].volume;
2426 arg->vol[RIGHT_PORT] =
2427 page->audio.port[RIGHT_PORT].volume;
2428 arg->vol[2] = page->audio.port[2].volume;
2429 arg->vol[3] = page->audio.port[3].volume;
2430 free(params.mode_buf, M_TEMP);
2431 }
2432 break;
2433 case CDIOCSETVOL:
2434 {
2435 struct ioc_vol *arg = (struct ioc_vol *) addr;
2436 struct cd_mode_params params;
2437 union cd_pages *page;
2438
2439 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2440 ("trying to do CDIOCSETVOL\n"));
2441
2442 params.alloc_len = sizeof(union cd_mode_data_6_10);
2443 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2444 M_WAITOK | M_ZERO);
2445 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2446 if (error) {
2447 free(params.mode_buf, M_TEMP);
2448 break;
2449 }
2450 page = cdgetpage(¶ms);
2451
2452 page->audio.port[LEFT_PORT].channels = CHANNEL_0;
2453 page->audio.port[LEFT_PORT].volume =
2454 arg->vol[LEFT_PORT];
2455 page->audio.port[RIGHT_PORT].channels = CHANNEL_1;
2456 page->audio.port[RIGHT_PORT].volume =
2457 arg->vol[RIGHT_PORT];
2458 page->audio.port[2].volume = arg->vol[2];
2459 page->audio.port[3].volume = arg->vol[3];
2460 error = cdsetmode(periph, ¶ms);
2461 free(params.mode_buf, M_TEMP);
2462 }
2463 break;
2464 case CDIOCSETMONO:
2465 {
2466 struct cd_mode_params params;
2467 union cd_pages *page;
2468
2469 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2470 ("trying to do CDIOCSETMONO\n"));
2471
2472 params.alloc_len = sizeof(union cd_mode_data_6_10);
2473 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2474 M_WAITOK | M_ZERO);
2475 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2476 if (error) {
2477 free(params.mode_buf, M_TEMP);
2478 break;
2479 }
2480 page = cdgetpage(¶ms);
2481
2482 page->audio.port[LEFT_PORT].channels =
2483 LEFT_CHANNEL | RIGHT_CHANNEL;
2484 page->audio.port[RIGHT_PORT].channels =
2485 LEFT_CHANNEL | RIGHT_CHANNEL;
2486 page->audio.port[2].channels = 0;
2487 page->audio.port[3].channels = 0;
2488 error = cdsetmode(periph, ¶ms);
2489 free(params.mode_buf, M_TEMP);
2490 }
2491 break;
2492 case CDIOCSETSTEREO:
2493 {
2494 struct cd_mode_params params;
2495 union cd_pages *page;
2496
2497 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2498 ("trying to do CDIOCSETSTEREO\n"));
2499
2500 params.alloc_len = sizeof(union cd_mode_data_6_10);
2501 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2502 M_WAITOK | M_ZERO);
2503 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2504 if (error) {
2505 free(params.mode_buf, M_TEMP);
2506 break;
2507 }
2508 page = cdgetpage(¶ms);
2509
2510 page->audio.port[LEFT_PORT].channels =
2511 LEFT_CHANNEL;
2512 page->audio.port[RIGHT_PORT].channels =
2513 RIGHT_CHANNEL;
2514 page->audio.port[2].channels = 0;
2515 page->audio.port[3].channels = 0;
2516 error = cdsetmode(periph, ¶ms);
2517 free(params.mode_buf, M_TEMP);
2518 }
2519 break;
2520 case CDIOCSETMUTE:
2521 {
2522 struct cd_mode_params params;
2523 union cd_pages *page;
2524
2525 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2526 ("trying to do CDIOCSETMUTE\n"));
2527
2528 params.alloc_len = sizeof(union cd_mode_data_6_10);
2529 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2530 M_WAITOK | M_ZERO);
2531 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2532 if (error) {
2533 free(¶ms, M_TEMP);
2534 break;
2535 }
2536 page = cdgetpage(¶ms);
2537
2538 page->audio.port[LEFT_PORT].channels = 0;
2539 page->audio.port[RIGHT_PORT].channels = 0;
2540 page->audio.port[2].channels = 0;
2541 page->audio.port[3].channels = 0;
2542 error = cdsetmode(periph, ¶ms);
2543 free(params.mode_buf, M_TEMP);
2544 }
2545 break;
2546 case CDIOCSETLEFT:
2547 {
2548 struct cd_mode_params params;
2549 union cd_pages *page;
2550
2551 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2552 ("trying to do CDIOCSETLEFT\n"));
2553
2554 params.alloc_len = sizeof(union cd_mode_data_6_10);
2555 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2556 M_WAITOK | M_ZERO);
2557
2558 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2559 if (error) {
2560 free(params.mode_buf, M_TEMP);
2561 break;
2562 }
2563 page = cdgetpage(¶ms);
2564
2565 page->audio.port[LEFT_PORT].channels = LEFT_CHANNEL;
2566 page->audio.port[RIGHT_PORT].channels = LEFT_CHANNEL;
2567 page->audio.port[2].channels = 0;
2568 page->audio.port[3].channels = 0;
2569 error = cdsetmode(periph, ¶ms);
2570 free(params.mode_buf, M_TEMP);
2571 }
2572 break;
2573 case CDIOCSETRIGHT:
2574 {
2575 struct cd_mode_params params;
2576 union cd_pages *page;
2577
2578 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2579 ("trying to do CDIOCSETRIGHT\n"));
2580
2581 params.alloc_len = sizeof(union cd_mode_data_6_10);
2582 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2583 M_WAITOK | M_ZERO);
2584
2585 error = cdgetmode(periph, ¶ms, AUDIO_PAGE);
2586 if (error) {
2587 free(params.mode_buf, M_TEMP);
2588 break;
2589 }
2590 page = cdgetpage(¶ms);
2591
2592 page->audio.port[LEFT_PORT].channels = RIGHT_CHANNEL;
2593 page->audio.port[RIGHT_PORT].channels = RIGHT_CHANNEL;
2594 page->audio.port[2].channels = 0;
2595 page->audio.port[3].channels = 0;
2596 error = cdsetmode(periph, ¶ms);
2597 free(params.mode_buf, M_TEMP);
2598 }
2599 break;
2600 case CDIOCRESUME:
2601 error = cdpause(periph, 1);
2602 break;
2603 case CDIOCPAUSE:
2604 error = cdpause(periph, 0);
2605 break;
2606 case CDIOCSTART:
2607 error = cdstartunit(periph, 0);
2608 break;
2609 case CDIOCCLOSE:
2610 error = cdstartunit(periph, 1);
2611 break;
2612 case CDIOCSTOP:
2613 error = cdstopunit(periph, 0);
2614 break;
2615 case CDIOCEJECT:
2616 error = cdstopunit(periph, 1);
2617 break;
2618 case CDIOCALLOW:
2619 cdprevent(periph, PR_ALLOW);
2620 break;
2621 case CDIOCPREVENT:
2622 cdprevent(periph, PR_PREVENT);
2623 break;
2624 case CDIOCSETDEBUG:
2625 /* sc_link->flags |= (SDEV_DB1 | SDEV_DB2); */
2626 error = ENOTTY;
2627 break;
2628 case CDIOCCLRDEBUG:
2629 /* sc_link->flags &= ~(SDEV_DB1 | SDEV_DB2); */
2630 error = ENOTTY;
2631 break;
2632 case CDIOCRESET:
2633 /* return (cd_reset(periph)); */
2634 error = ENOTTY;
2635 break;
2636 case CDRIOCREADSPEED:
2637 error = cdsetspeed(periph, *(u_int32_t *)addr, CDR_MAX_SPEED);
2638 break;
2639 case CDRIOCWRITESPEED:
2640 error = cdsetspeed(periph, CDR_MAX_SPEED, *(u_int32_t *)addr);
2641 break;
2642 case DVDIOCSENDKEY:
2643 case DVDIOCREPORTKEY: {
2644 struct dvd_authinfo *authinfo;
2645
2646 authinfo = (struct dvd_authinfo *)addr;
2647
2648 if (cmd == DVDIOCREPORTKEY)
2649 error = cdreportkey(periph, authinfo);
2650 else
2651 error = cdsendkey(periph, authinfo);
2652 break;
2653 }
2654 case DVDIOCREADSTRUCTURE: {
2655 struct dvd_struct *dvdstruct;
2656
2657 dvdstruct = (struct dvd_struct *)addr;
2658
2659 error = cdreaddvdstructure(periph, dvdstruct);
2660
2661 break;
2662 }
2663 default:
2664 error = cam_periph_ioctl(periph, cmd, addr, cderror);
2665 break;
2666 }
2667
2668 cam_periph_unlock(periph);
2669
2670 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("leaving cdioctl\n"));
2671 if (error && bootverbose) {
2672 printf("scsi_cd.c::ioctl cmd=%08lx error=%d\n", cmd, error);
2673 }
2674
2675 return (error);
2676}
2677
2678static void
2679cdprevent(struct cam_periph *periph, int action)
2680{
2681 union ccb *ccb;
--- 182 unchanged lines hidden (view full) ---
2864 int error;
2865
2866 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdsize\n"));
2867
2868 softc = (struct cd_softc *)periph->softc;
2869
2870 ccb = cdgetccb(periph, /* priority */ 1);
2871
2872 rcap_buf = malloc(sizeof(struct scsi_read_capacity_data),
2873 M_TEMP, M_WAITOK);
2874
2875 scsi_read_capacity(&ccb->csio,
2876 /*retries*/ 1,
2877 cddone,
2878 MSG_SIMPLE_Q_TAG,
2879 rcap_buf,
2880 SSD_FULL_SIZE,
2881 /* timeout */20000);
--- 1347 unchanged lines hidden ---