Deleted Added
full compact
scsi_cd.c (164906) scsi_cd.c (168752)
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>
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 $");
49__FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_cd.c 168752 2007-04-15 08:49:19Z scottl $");
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>
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#include <cam/cam_sim.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,
74
75#include <cam/scsi/scsi_message.h>
76#include <cam/scsi/scsi_da.h>
77#include <cam/scsi/scsi_cd.h>
78
79#define LEADOUT 0xaa /* leadout toc entry */
80
81struct cd_params {

--- 17 unchanged lines hidden (view full) ---

99 CD_FLAG_DISC_REMOVABLE = 0x0008,
100 CD_FLAG_TAGGED_QUEUING = 0x0010,
101 CD_FLAG_CHANGER = 0x0040,
102 CD_FLAG_ACTIVE = 0x0080,
103 CD_FLAG_SCHED_ON_COMP = 0x0100,
104 CD_FLAG_RETRY_UA = 0x0200,
105 CD_FLAG_VALID_MEDIA = 0x0400,
106 CD_FLAG_VALID_TOC = 0x0800,
106 CD_FLAG_SCTX_INIT = 0x1000
107 CD_FLAG_SCTX_INIT = 0x1000,
108 CD_FLAG_OPEN = 0x2000
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
109} cd_flags;
110
111typedef enum {
112 CD_CCB_PROBE = 0x01,
113 CD_CCB_BUFFER_IO = 0x02,
114 CD_CCB_WAITING = 0x03,
115 CD_CCB_TYPE_MASK = 0x0F,
116 CD_CCB_RETRY_UA = 0x10

--- 170 unchanged lines hidden (view full) ---

287static struct periph_driver cddriver =
288{
289 cdinit, "cd",
290 TAILQ_HEAD_INITIALIZER(cddriver.units), /* generation */ 0
291};
292
293PERIPHDRIVER_DECLARE(cd, cddriver);
294
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;
295#ifndef CHANGER_MIN_BUSY_SECONDS
296#define CHANGER_MIN_BUSY_SECONDS 5
297#endif
298#ifndef CHANGER_MAX_BUSY_SECONDS
299#define CHANGER_MAX_BUSY_SECONDS 15
300#endif
301
302static int changer_min_busy_seconds = CHANGER_MIN_BUSY_SECONDS;

--- 10 unchanged lines hidden (view full) ---

313
314struct cdchanger {
315 path_id_t path_id;
316 target_id_t target_id;
317 int num_devices;
318 struct camq devq;
319 struct timeval start_time;
320 struct cd_softc *cur_device;
322 struct callout_handle short_handle;
323 struct callout_handle long_handle;
321 struct callout short_handle;
322 struct callout long_handle;
324 volatile cd_changer_flags flags;
325 STAILQ_ENTRY(cdchanger) changer_links;
326 STAILQ_HEAD(chdevlist, cd_softc) chluns;
327};
328
323 volatile cd_changer_flags flags;
324 STAILQ_ENTRY(cdchanger) changer_links;
325 STAILQ_HEAD(chdevlist, cd_softc) chluns;
326};
327
328static struct mtx changerq_mtx;
329static STAILQ_HEAD(changerlist, cdchanger) changerq;
329static STAILQ_HEAD(changerlist, cdchanger) changerq;
330static int num_changers;
330
331
331
332static void
333cdinit(void)
334{
335 cam_status status;
336 struct cam_path *path;
337
332static void
333cdinit(void)
334{
335 cam_status status;
336 struct cam_path *path;
337
338 mtx_init(&changerq_mtx, "cdchangerq", "SCSI CD Changer List", MTX_DEF);
339 STAILQ_INIT(&changerq);
340
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{
341 /*
342 * Install a global async callback. This callback will
343 * receive async callbacks like "new device found".
344 */
345 status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID,
346 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
347
348 if (status == CAM_REQ_CMP) {

--- 13 unchanged lines hidden (view full) ---

362 printf("cd: Failed to attach master async callback "
363 "due to status 0x%x!\n", status);
364 }
365}
366
367static void
368cdoninvalidate(struct cam_periph *periph)
369{
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 /*
370 struct cd_softc *softc;
371 struct ccb_setasync csa;
372
373 softc = (struct cd_softc *)periph->softc;
374
375 /*
376 * De-register any async callbacks.
377 */
378 xpt_setup_ccb(&csa.ccb_h, periph->path,
379 /* priority */ 5);
380 csa.ccb_h.func_code = XPT_SASYNC_CB;
381 csa.event_enable = 0;
382 csa.callback = cdasync;
383 csa.callback_arg = periph;
384 xpt_action((union ccb *)&csa);
385
386 softc->flags |= CD_FLAG_INVALID;
387
388 /*
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);
389 * Return all queued I/O with ENXIO.
390 * XXX Handle any transactions queued to the card
391 * with XPT_ABORT_CCB.
392 */
393 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;
394
395 /*
396 * If this device is part of a changer, and it was scheduled
397 * to run, remove it from the run queue since we just nuked
398 * all of its scheduled I/O.
399 */
400 if ((softc->flags & CD_FLAG_CHANGER)
401 && (softc->pinfo.index != CAM_UNQUEUED_INDEX))
402 camq_remove(&softc->changer->devq, softc->pinfo.index);
403
404 disk_gone(softc->disk);
405 xpt_print(periph->path, "lost device\n");
406}
407
408static void
409cdcleanup(struct cam_periph *periph)
410{
411 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
412
413 softc = (struct cd_softc *)periph->softc;
414
415 xpt_print(periph->path, "removing device entry\n");
416
417 if ((softc->flags & CD_FLAG_SCTX_INIT) != 0
418 && sysctl_ctx_free(&softc->sysctl_ctx) != 0) {
419 xpt_print(periph->path, "can't remove sysctl context\n");
420 }
421
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) {
422 /*
423 * In the queued, non-active case, the device in question
424 * has already been removed from the changer run queue. Since this
425 * device is active, we need to de-activate it, and schedule
426 * another device to run. (if there is another one to run)
427 */
428 if ((softc->flags & CD_FLAG_CHANGER)
429 && (softc->flags & CD_FLAG_ACTIVE)) {

--- 13 unchanged lines hidden (view full) ---

443 * bogus pointer reference.
444 *
445 * The long timeout doesn't really matter, since we
446 * decrement the qfrozen_cnt to indicate that there is
447 * nothing in the active slot now. Therefore, there won't
448 * be any bogus pointer references there.
449 */
450 if (softc->changer->flags & CHANGER_SHORT_TMOUT_SCHED) {
459 untimeout(cdshorttimeout, softc->changer,
460 softc->changer->short_handle);
451 callout_stop(&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) {
452 softc->changer->flags &= ~CHANGER_SHORT_TMOUT_SCHED;
453 }
454 softc->changer->devq.qfrozen_cnt--;
455 softc->changer->flags |= CHANGER_MANUAL_CALL;
456 cdrunchangerqueue(softc->changer);
457 }
458
459 /*

--- 4 unchanged lines hidden (view full) ---

464 && (--softc->changer->num_devices == 0)) {
465
466 /*
467 * Theoretically, there shouldn't be any timeouts left, but
468 * I'm not completely sure that that will be the case. So,
469 * it won't hurt to check and see if there are any left.
470 */
471 if (softc->changer->flags & CHANGER_TIMEOUT_SCHED) {
481 untimeout(cdrunchangerqueue, softc->changer,
482 softc->changer->long_handle);
472 callout_stop(&softc->changer->long_handle);
483 softc->changer->flags &= ~CHANGER_TIMEOUT_SCHED;
484 }
485
486 if (softc->changer->flags & CHANGER_SHORT_TMOUT_SCHED) {
473 softc->changer->flags &= ~CHANGER_TIMEOUT_SCHED;
474 }
475
476 if (softc->changer->flags & CHANGER_SHORT_TMOUT_SCHED) {
487 untimeout(cdshorttimeout, softc->changer,
488 softc->changer->short_handle);
477 callout_stop(&softc->changer->short_handle);
489 softc->changer->flags &= ~CHANGER_SHORT_TMOUT_SCHED;
490 }
491
478 softc->changer->flags &= ~CHANGER_SHORT_TMOUT_SCHED;
479 }
480
481 mtx_lock(&changerq_mtx);
492 STAILQ_REMOVE(&changerq, softc->changer, cdchanger,
493 changer_links);
482 STAILQ_REMOVE(&changerq, softc->changer, cdchanger,
483 changer_links);
484 num_changers--;
485 mtx_unlock(&changerq_mtx);
494 xpt_print(periph->path, "removing changer entry\n");
495 free(softc->changer, M_DEVBUF);
486 xpt_print(periph->path, "removing changer entry\n");
487 free(softc->changer, M_DEVBUF);
496 num_changers--;
497 }
498 disk_destroy(softc->disk);
499 free(softc, M_DEVBUF);
488 }
489 disk_destroy(softc->disk);
490 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;
491}
492
493static void
494cdasync(void *callback_arg, u_int32_t code,
495 struct cam_path *path, void *arg)
496{
497 struct cam_periph *periph;
498

--- 30 unchanged lines hidden (view full) ---

529
530 break;
531 }
532 case AC_SENT_BDR:
533 case AC_BUS_RESET:
534 {
535 struct cd_softc *softc;
536 struct ccb_hdr *ccbh;
547 int s;
548
549 softc = (struct cd_softc *)periph->softc;
537
538 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;
539 /*
540 * Don't fail on the expected unit attention
541 * that will occur.
542 */
543 softc->flags |= CD_FLAG_RETRY_UA;
544 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
545 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;
546 /* FALLTHROUGH */
547 }
548 default:
549 cam_periph_async(periph, code, path, arg);
550 break;
551 }
552}
553
554static void
555cdsysctlinit(void *context, int pending)
556{
557 struct cam_periph *periph;
558 struct cd_softc *softc;
559 char tmpstr[80], tmpstr2[80];
560
561 periph = (struct cam_periph *)context;
575 softc = (struct cd_softc *)periph->softc;
562 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
563 return;
576
564
565 softc = (struct cd_softc *)periph->softc;
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);
566 snprintf(tmpstr, sizeof(tmpstr), "CAM CD unit %d", periph->unit_number);
567 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
568
569 mtx_lock(&Giant);
570
571 sysctl_ctx_init(&softc->sysctl_ctx);
572 softc->flags |= CD_FLAG_SCTX_INIT;
573 softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
574 SYSCTL_STATIC_CHILDREN(_kern_cam_cd), OID_AUTO,
575 tmpstr2, CTLFLAG_RD, 0, tmpstr);
576
577 if (softc->sysctl_tree == NULL) {
578 printf("cdsysctlinit: unable to allocate sysctl tree\n");
579 mtx_unlock(&Giant);
580 cam_periph_release(periph);
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);
581 return;
582 }
583
584 /*
585 * Now register the sysctl handler, so the user can the value on
586 * the fly.
587 */
588 SYSCTL_ADD_PROC(&softc->sysctl_ctx,SYSCTL_CHILDREN(softc->sysctl_tree),
589 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
590 &softc->minimum_command_size, 0, cdcmdsizesysctl, "I",
591 "Minimum CDB size");
592
593 mtx_unlock(&Giant);
594 cam_periph_release(periph);
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 */
595}
596
597/*
598 * We have a handler function for this so we can check the values when the
599 * user sets them, instead of every time we look at them.
600 */
601static int
602cdcmdsizesysctl(SYSCTL_HANDLER_ARGS)

--- 117 unchanged lines hidden (view full) ---

720 * yet. Unlike other SCSI peripheral drivers, we explicitly set
721 * the device type here to be CDROM, rather than just ORing in
722 * the device type. This is because this driver can attach to either
723 * CDROM or WORM devices, and we want this peripheral driver to
724 * show up in the devstat list as a CD peripheral driver, not a
725 * WORM peripheral driver. WORM drives will also have the WORM
726 * driver attached to them.
727 */
728 cam_periph_unlock(periph);
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;
729 softc->disk = disk_alloc();
730 softc->disk->d_devstat = devstat_new_entry("cd",
731 periph->unit_number, 0,
732 DEVSTAT_BS_UNAVAILABLE,
733 DEVSTAT_TYPE_CDROM | DEVSTAT_TYPE_IF_SCSI,
734 DEVSTAT_PRIORITY_CD);
735 softc->disk->d_open = cdopen;
736 softc->disk->d_close = cdclose;
737 softc->disk->d_strategy = cdstrategy;
738 softc->disk->d_ioctl = cdioctl;
739 softc->disk->d_name = "cd";
740 softc->disk->d_unit = periph->unit_number;
741 softc->disk->d_drv1 = periph;
750 softc->disk->d_flags = DISKFLAG_NEEDSGIANT;
742 softc->disk->d_flags = 0;
751 disk_create(softc->disk, DISK_VERSION);
743 disk_create(softc->disk, DISK_VERSION);
744 cam_periph_lock(periph);
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
745
746 /*
747 * Add an async callback so that we get
748 * notified if this device goes away.
749 */
750 xpt_setup_ccb(&csa.ccb_h, periph->path,
751 /* priority */ 5);
752 csa.ccb_h.func_code = XPT_SASYNC_CB;

--- 18 unchanged lines hidden (view full) ---

771 struct cam_periph *nperiph;
772 struct cam_path *path;
773 cam_status status;
774 int found;
775
776 /* Set the changer flag in the current device's softc */
777 softc->flags |= CD_FLAG_CHANGER;
778
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 */
779 /*
780 * Now, look around for an existing changer device with the
781 * same path and target ID as the current device.
782 */
783 mtx_lock(&changerq_mtx);
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 }
784 for (found = 0,
785 nchanger = (struct cdchanger *)STAILQ_FIRST(&changerq);
786 nchanger != NULL;
787 nchanger = STAILQ_NEXT(nchanger, changer_links)){
788 if ((nchanger->path_id == cgd->ccb_h.path_id)
789 && (nchanger->target_id == cgd->ccb_h.target_id)) {
790 found = 1;
791 break;
792 }
793 }
794 mtx_unlock(&changerq_mtx);
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
795
796 /*
797 * If we found a matching entry, just add this device to
798 * the list of devices on this changer.
799 */
800 if (found == 1) {
801 struct chdevlist *chlunhead;
802

--- 89 unchanged lines hidden (view full) ---

892
893 if (camq_init(&nchanger->devq, 1) != 0) {
894 softc->flags &= ~CD_FLAG_CHANGER;
895 printf("cdregister: changer support "
896 "disabled\n");
897 goto cdregisterexit;
898 }
899
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
900 nchanger->path_id = cgd->ccb_h.path_id;
901 nchanger->target_id = cgd->ccb_h.target_id;
902
903 /* this is superfluous, but it makes things clearer */
904 nchanger->num_devices = 0;
905
906 STAILQ_INIT(&nchanger->chluns);
907
908 callout_init_mtx(&nchanger->long_handle,
909 periph->sim->mtx, 0);
910 callout_init_mtx(&nchanger->short_handle,
911 periph->sim->mtx, 0);
912
913 mtx_lock(&changerq_mtx);
914 num_changers++;
918 STAILQ_INSERT_TAIL(&changerq, nchanger,
919 changer_links);
915 STAILQ_INSERT_TAIL(&changerq, nchanger,
916 changer_links);
917 mtx_unlock(&changerq_mtx);
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
918
919 /*
920 * Create a path with lun id 0, and see if we can
921 * find a matching device
922 */
923 status = xpt_create_path(&path, /*periph*/ periph,
924 cgd->ccb_h.path_id,
925 cgd->ccb_h.target_id, 0);

--- 45 unchanged lines hidden (view full) ---

971 }
972 STAILQ_INSERT_TAIL(&nchanger->chluns, softc,
973 changer_links);
974 }
975 }
976
977cdregisterexit:
978
981 /* Lock this peripheral until we are setup */
982 /* Can't block */
983 cam_periph_lock(periph, PRIBIO);
979 /*
980 * Refcount and block open attempts until we are setup
981 * Can't block
982 */
983 (void)cam_periph_hold(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;
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
999
1000 periph = (struct cam_periph *)dp->d_drv1;
1001 if (periph == NULL)
1002 return (ENXIO);
1003
1004 softc = (struct cd_softc *)periph->softc;
1005
1007 /*
1008 * Grab splsoftcam and hold it until we lock the peripheral.
1009 */
1010 s = splsoftcam();
1006 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
1007 return(ENXIO);
1008
1009 cam_periph_lock(periph);
1010
1011 if (softc->flags & CD_FLAG_INVALID) {
1011 if (softc->flags & CD_FLAG_INVALID) {
1012 splx(s);
1012 cam_periph_unlock(periph);
1013 cam_periph_release(periph);
1013 return(ENXIO);
1014 }
1015
1014 return(ENXIO);
1015 }
1016
1016 if ((error = cam_periph_lock(periph, PRIBIO | PCATCH)) != 0) {
1017 splx(s);
1017 if ((error = cam_periph_hold(periph, PRIBIO | PCATCH)) != 0) {
1018 cam_periph_unlock(periph);
1019 cam_periph_release(periph);
1018 return (error);
1019 }
1020
1020 return (error);
1021 }
1022
1021 splx(s);
1023 /* Closes aren't symmetrical with opens, so fix up the refcounting. */
1024 if (softc->flags & CD_FLAG_OPEN)
1025 cam_periph_release(periph);
1026 else
1027 softc->flags |= CD_FLAG_OPEN;
1022
1028
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
1029 /*
1030 * Check for media, and set the appropriate flags. We don't bail
1031 * if we don't have media, but then we don't allow anything but the
1032 * CDIOCEJECT/CDIOCCLOSE ioctls if there is no media.
1033 */
1034 cdcheckmedia(periph);
1035
1036 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("leaving cdopen\n"));
1037 cam_periph_unhold(periph);
1033 cam_periph_unlock(periph);
1034
1038 cam_periph_unlock(periph);
1039
1035 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("leaving cdopen\n"));
1036
1037 return (error);
1040 return (0);
1038}
1039
1040static int
1041cdclose(struct disk *dp)
1042{
1043 struct cam_periph *periph;
1044 struct cd_softc *softc;
1041}
1042
1043static int
1044cdclose(struct disk *dp)
1045{
1046 struct cam_periph *periph;
1047 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
1048
1049 periph = (struct cam_periph *)dp->d_drv1;
1050 if (periph == NULL)
1051 return (ENXIO);
1052
1053 softc = (struct cd_softc *)periph->softc;
1054
1053 if ((error = cam_periph_lock(periph, PRIBIO)) != 0)
1054 return (error);
1055 cam_periph_lock(periph);
1056 cam_periph_hold(periph, PRIBIO);
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 */
1057
1058 if ((softc->flags & CD_FLAG_DISC_REMOVABLE) != 0)
1059 cdprevent(periph, PR_ALLOW);
1060
1061 /*
1062 * Since we're closing this CD, mark the blocksize as unavailable.
1063 * It will be marked as available when the CD is opened again.
1064 */
1065 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1066
1067 /*
1068 * We'll check the media and toc again at the next open().
1069 */
1068 softc->flags &= ~(CD_FLAG_VALID_MEDIA|CD_FLAG_VALID_TOC);
1070 softc->flags &= ~(CD_FLAG_VALID_MEDIA|CD_FLAG_VALID_TOC|CD_FLAG_OPEN);
1069
1071
1072 cam_periph_unhold(periph);
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;
1073 cam_periph_unlock(periph);
1074 cam_periph_release(periph);
1075
1076 return (0);
1077}
1078
1079static void
1080cdshorttimeout(void *arg)
1081{
1082 struct cdchanger *changer;
1080 int s;
1081
1083
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 }
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;
1098}
1099
1100/*
1101 * This is a wrapper for xpt_schedule. It only applies to changers.
1102 */
1103static void
1104cdschedule(struct cam_periph *periph, int priority)
1105{
1106 struct cd_softc *softc;
1109 int s;
1110
1107
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);
1108 softc = (struct cd_softc *)periph->softc;
1109
1110 /*
1111 * If this device isn't currently queued, and if it isn't
1112 * the active device, then we queue this device and run the
1113 * changer queue if there is no timeout scheduled to do it.
1114 * If this device is the active device, just schedule it
1115 * to run again. If this device is queued, there should be

--- 21 unchanged lines hidden (view full) ---

1137 && ((softc->changer->flags & CHANGER_NEED_TIMEOUT)==0)
1138 && ((softc->changer->flags & CHANGER_SHORT_TMOUT_SCHED)==0)){
1139 softc->changer->flags |= CHANGER_MANUAL_CALL;
1140 cdrunchangerqueue(softc->changer);
1141 }
1142 } else if ((softc->flags & CD_FLAG_ACTIVE)
1143 && ((softc->flags & CD_FLAG_SCHED_ON_COMP) == 0))
1144 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;
1145}
1146
1147static void
1148cdrunchangerqueue(void *arg)
1149{
1150 struct cd_softc *softc;
1151 struct cdchanger *changer;
1152 int called_from_timeout;
1161 int s;
1162
1153
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) {
1154 changer = (struct cdchanger *)arg;
1155
1156 /*
1157 * If we have NOT been called from cdstrategy() or cddone(), and
1158 * instead from a timeout routine, go ahead and clear the
1159 * timeout flag.
1160 */
1161 if ((changer->flags & CHANGER_MANUAL_CALL) == 0) {
1162 changer->flags &= ~CHANGER_TIMEOUT_SCHED;
1163 called_from_timeout = 1;
1164 } else
1165 called_from_timeout = 0;
1166
1167 /* Always clear the manual call flag */
1168 changer->flags &= ~CHANGER_MANUAL_CALL;
1169
1170 /* nothing to do if the queue is empty */
1171 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
1172 return;
1173 }
1174
1175 /*
1176 * If the changer queue is frozen, that means we have an active
1177 * device.
1178 */
1179 if (changer->devq.qfrozen_cnt > 0) {
1180
1181 /*
1182 * We always need to reset the frozen count and clear the
1183 * active flag.
1184 */
1185 changer->devq.qfrozen_cnt--;
1186 changer->cur_device->flags &= ~CD_FLAG_ACTIVE;
1187 changer->cur_device->flags &= ~CD_FLAG_SCHED_ON_COMP;
1188
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) {
1189 if (changer->cur_device->outstanding_cmds > 0) {
1190 changer->cur_device->flags |= CD_FLAG_SCHED_ON_COMP;
1191 changer->cur_device->bufs_left =
1192 changer->cur_device->outstanding_cmds;
1193 if (called_from_timeout) {
1198 changer->long_handle =
1199 timeout(cdrunchangerqueue, changer,
1200 changer_max_busy_seconds * hz);
1194 callout_reset(&changer->long_handle,
1195 changer_max_busy_seconds * hz,
1196 cdrunchangerqueue, changer);
1201 changer->flags |= CHANGER_TIMEOUT_SCHED;
1202 }
1197 changer->flags |= CHANGER_TIMEOUT_SCHED;
1198 }
1203 splx(s);
1204 return;
1205 }
1206
1207 /*
1199 return;
1200 }
1201
1202 /*
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) {
1203 * Check to see whether the current device has any I/O left
1204 * to do. If so, requeue it at the end of the queue. If
1205 * not, there is no need to requeue it.
1206 */
1207 if (bioq_first(&changer->cur_device->bio_queue) != NULL) {
1208
1209 changer->cur_device->pinfo.generation =
1210 ++changer->devq.generation;

--- 13 unchanged lines hidden (view full) ---

1224 wakeup(&softc->changer);
1225 xpt_schedule(softc->periph, /*priority*/ 1);
1226
1227 /*
1228 * Get rid of any pending timeouts, and set a flag to schedule new
1229 * ones so this device gets its full time quantum.
1230 */
1231 if (changer->flags & CHANGER_TIMEOUT_SCHED) {
1245 untimeout(cdrunchangerqueue, changer, changer->long_handle);
1232 callout_stop(&changer->long_handle);
1246 changer->flags &= ~CHANGER_TIMEOUT_SCHED;
1247 }
1248
1249 if (changer->flags & CHANGER_SHORT_TMOUT_SCHED) {
1233 changer->flags &= ~CHANGER_TIMEOUT_SCHED;
1234 }
1235
1236 if (changer->flags & CHANGER_SHORT_TMOUT_SCHED) {
1250 untimeout(cdshorttimeout, changer, changer->short_handle);
1237 callout_stop(&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;
1238 changer->flags &= ~CHANGER_SHORT_TMOUT_SCHED;
1239 }
1240
1241 /*
1242 * We need to schedule timeouts, but we only do this after the
1243 * first transaction has completed. This eliminates the changer
1244 * switch time.
1245 */
1246 changer->flags |= CHANGER_NEED_TIMEOUT;
1260
1261 splx(s);
1262}
1263
1264static void
1265cdchangerschedule(struct cd_softc *softc)
1266{
1267 struct cdchanger *changer;
1247}
1248
1249static void
1250cdchangerschedule(struct cd_softc *softc)
1251{
1252 struct cdchanger *changer;
1268 int s;
1269
1253
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) {
1254 changer = softc->changer;
1255
1256 /*
1257 * If this is a changer, and this is the current device,
1258 * and this device has at least the minimum time quantum to
1259 * run, see if we can switch it out.
1260 */
1261 if ((softc->flags & CD_FLAG_ACTIVE)

--- 28 unchanged lines hidden (view full) ---

1290 && (softc->flags & CD_FLAG_ACTIVE)) {
1291
1292 /*
1293 * Now that the first transaction to this
1294 * particular device has completed, we can go ahead
1295 * and schedule our timeouts.
1296 */
1297 if ((changer->flags & CHANGER_TIMEOUT_SCHED) == 0) {
1316 changer->long_handle =
1317 timeout(cdrunchangerqueue, changer,
1318 changer_max_busy_seconds * hz);
1298 callout_reset(&changer->long_handle,
1299 changer_max_busy_seconds * hz,
1300 cdrunchangerqueue, changer);
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) {
1301 changer->flags |= CHANGER_TIMEOUT_SCHED;
1302 } else
1303 printf("cdchangerschedule: already have a long"
1304 " timeout!\n");
1305
1306 if ((changer->flags & CHANGER_SHORT_TMOUT_SCHED) == 0) {
1325 changer->short_handle =
1326 timeout(cdshorttimeout, changer,
1327 changer_min_busy_seconds * hz);
1307 callout_reset(&changer->short_handle,
1308 changer_min_busy_seconds * hz,
1309 cdshorttimeout, changer);
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 }
1310 changer->flags |= CHANGER_SHORT_TMOUT_SCHED;
1311 } else
1312 printf("cdchangerschedule: already have a short "
1313 "timeout!\n");
1314
1315 /*
1316 * We just scheduled timeouts, no need to schedule
1317 * more.
1318 */
1319 changer->flags &= ~CHANGER_NEED_TIMEOUT;
1320
1321 }
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;
1322}
1323
1324static int
1325cdrunccb(union ccb *ccb, int (*error_routine)(union ccb *ccb,
1326 u_int32_t cam_flags,
1327 u_int32_t sense_flags),
1328 u_int32_t cam_flags, u_int32_t sense_flags)
1329{

--- 12 unchanged lines hidden (view full) ---

1342
1343 return(error);
1344}
1345
1346static union ccb *
1347cdgetccb(struct cam_periph *periph, u_int32_t priority)
1348{
1349 struct cd_softc *softc;
1369 int s;
1370
1371 softc = (struct cd_softc *)periph->softc;
1372
1373 if (softc->flags & CD_FLAG_CHANGER) {
1350
1351 softc = (struct cd_softc *)periph->softc;
1352
1353 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
1354 /*
1355 * This should work the first time this device is woken up,
1356 * but just in case it doesn't, we use a while loop.
1357 */
1358 while ((softc->flags & CD_FLAG_ACTIVE) == 0) {
1359 /*
1360 * If this changer isn't already queued, queue it up.
1361 */

--- 6 unchanged lines hidden (view full) ---

1368 }
1369 if (((softc->changer->flags & CHANGER_TIMEOUT_SCHED)==0)
1370 && ((softc->changer->flags & CHANGER_NEED_TIMEOUT)==0)
1371 && ((softc->changer->flags
1372 & CHANGER_SHORT_TMOUT_SCHED)==0)) {
1373 softc->changer->flags |= CHANGER_MANUAL_CALL;
1374 cdrunchangerqueue(softc->changer);
1375 } else
1399 tsleep(&softc->changer, PRIBIO, "cgticb", 0);
1376 msleep(&softc->changer, periph->sim->mtx,
1377 PRIBIO, "cgticb", 0);
1400 }
1378 }
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;
1379 }
1380 return(cam_periph_getccb(periph, priority));
1381}
1382
1383
1384/*
1385 * Actually translate the requested transfer into one the physical driver
1386 * can understand. The transfer is described by a buf and will include
1387 * only one physical transfer.
1388 */
1389static void
1390cdstrategy(struct bio *bp)
1391{
1392 struct cam_periph *periph;
1393 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
1394
1395 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1396 if (periph == NULL) {
1397 biofinish(bp, NULL, ENXIO);
1398 return;
1399 }
1400
1401 cam_periph_lock(periph);
1425 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdstrategy\n"));
1426
1427 softc = (struct cd_softc *)periph->softc;
1428
1429 /*
1402 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdstrategy\n"));
1403
1404 softc = (struct cd_softc *)periph->softc;
1405
1406 /*
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)) {
1407 * If the device has been made invalid, error out
1408 */
1409 if ((softc->flags & CD_FLAG_INVALID)) {
1440 splx(s);
1410 cam_periph_unlock(periph);
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) {
1411 biofinish(bp, NULL, ENXIO);
1412 return;
1413 }
1414
1415 /*
1416 * If we don't have valid media, look for it before trying to
1417 * schedule the I/O.
1418 */
1419 if ((softc->flags & CD_FLAG_VALID_MEDIA) == 0) {
1420 int error;
1421
1422 error = cdcheckmedia(periph);
1423 if (error != 0) {
1454 splx(s);
1424 cam_periph_unlock(periph);
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
1425 biofinish(bp, NULL, error);
1426 return;
1427 }
1428 }
1429
1430 /*
1431 * Place it in the queue of disk activities for this disk
1432 */
1433 bioq_disksort(&softc->bio_queue, bp);
1434
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
1435 /*
1436 * Schedule ourselves for performing the work. We do things
1437 * differently for changers.
1438 */
1439 if ((softc->flags & CD_FLAG_CHANGER) == 0)
1440 xpt_schedule(periph, /* XXX priority */1);
1441 else
1442 cdschedule(periph, /* priority */ 1);
1443
1444 cam_periph_unlock(periph);
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;
1445 return;
1446}
1447
1448static void
1449cdstart(struct cam_periph *periph, union ccb *start_ccb)
1450{
1451 struct cd_softc *softc;
1452 struct bio *bp;
1453 struct ccb_scsiio *csio;
1454 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 {
1455
1456 softc = (struct cd_softc *)periph->softc;
1457
1458 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdstart\n"));
1459
1460 switch (softc->state) {
1461 case CD_STATE_NORMAL:
1462 {
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;
1463 bp = bioq_first(&softc->bio_queue);
1464 if (periph->immediate_priority <= periph->pinfo.priority) {
1465 start_ccb->ccb_h.ccb_state = CD_CCB_WAITING;
1466
1467 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
1468 periph_links.sle);
1469 periph->immediate_priority = CAM_PRIORITY_NONE;
1505 splx(s);
1506 wakeup(&periph->ccb_list);
1507 } else if (bp == NULL) {
1470 wakeup(&periph->ccb_list);
1471 } 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
1472 xpt_release_ccb(start_ccb);
1473 } else {
1474 bioq_remove(&softc->bio_queue, bp);
1475
1476 devstat_start_transaction_bio(softc->disk->d_devstat, bp);
1477
1478 scsi_read_write(&start_ccb->csio,
1479 /*retries*/4,

--- 7 unchanged lines hidden (view full) ---

1487 bp->bio_bcount / softc->params.blksize,
1488 /* data_ptr */ bp->bio_data,
1489 /* dxfer_len */ bp->bio_bcount,
1490 /* sense_len */ SSD_FULL_SIZE,
1491 /* timeout */ 30000);
1492 start_ccb->ccb_h.ccb_state = CD_CCB_BUFFER_IO;
1493
1494
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++;
1495 LIST_INSERT_HEAD(&softc->pending_ccbs,
1496 &start_ccb->ccb_h, periph_links.le);
1497 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);
1498
1499 /* We expect a unit attention from this device */
1500 if ((softc->flags & CD_FLAG_RETRY_UA) != 0) {
1501 start_ccb->ccb_h.ccb_state |= CD_CCB_RETRY_UA;
1502 softc->flags &= ~CD_FLAG_RETRY_UA;
1503 }
1504
1505 start_ccb->ccb_h.ccb_bp = bp;
1506 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;
1507
1508 xpt_action(start_ccb);
1509 }
1510 if (bp != NULL) {
1511 /* Have more work to do, so ensure we stay scheduled */
1512 xpt_schedule(periph, /* XXX priority */1);
1513 }
1514 break;

--- 37 unchanged lines hidden (view full) ---

1552 softc = (struct cd_softc *)periph->softc;
1553 csio = &done_ccb->csio;
1554
1555 switch (csio->ccb_h.ccb_state & CD_CCB_TYPE_MASK) {
1556 case CD_CCB_BUFFER_IO:
1557 {
1558 struct bio *bp;
1559 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) {
1560
1561 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
1562 error = 0;
1563
1564 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1565 int sf;
1566
1567 if ((done_ccb->ccb_h.ccb_state & CD_CCB_RETRY_UA) != 0)

--- 7 unchanged lines hidden (view full) ---

1575 * A retry was scheuled, so
1576 * just return.
1577 */
1578 return;
1579 }
1580 }
1581
1582 if (error != 0) {
1628 int s;
1629
1630 xpt_print(periph->path,
1631 "cddone: got error %#x back\n", error);
1583 xpt_print(periph->path,
1584 "cddone: got error %#x back\n", error);
1632 s = splbio();
1633 bioq_flush(&softc->bio_queue, NULL, EIO);
1585 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
1586 bp->bio_resid = bp->bio_bcount;
1587 bp->bio_error = error;
1588 bp->bio_flags |= BIO_ERROR;
1589 cam_release_devq(done_ccb->ccb_h.path,
1590 /*relsim_flags*/0,
1591 /*reduction*/0,
1592 /*timeout*/0,
1593 /*getcount_only*/0);

--- 6 unchanged lines hidden (view full) ---

1600 * Short transfer ???
1601 * XXX: not sure this is correct for partial
1602 * transfers at EOM
1603 */
1604 bp->bio_flags |= BIO_ERROR;
1605 }
1606 }
1607
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--;
1608 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
1609 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);
1610
1611 if (softc->flags & CD_FLAG_CHANGER)
1612 cdchangerschedule(softc);
1613
1614 biofinish(bp, NULL, 0);
1615 break;
1616 }
1617 case CD_CCB_PROBE:

--- 174 unchanged lines hidden (view full) ---

1792 * Since our peripheral may be invalidated by an error
1793 * above or an external event, we must release our CCB
1794 * before releasing the probe lock on the peripheral.
1795 * The peripheral will only go away once the last lock
1796 * is removed, and we need it around for the CCB release
1797 * operation.
1798 */
1799 xpt_release_ccb(done_ccb);
1855 cam_periph_unlock(periph);
1800 cam_periph_unhold(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;
1801 return;
1802 }
1803 case CD_CCB_WAITING:
1804 {
1805 /* Caller will release the CCB */
1806 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
1807 ("trying to wakeup ccbwait\n"));
1808

--- 36 unchanged lines hidden (view full) ---

1845}
1846
1847static int
1848cdioctl(struct disk *dp, u_long cmd, void *addr, int flag, struct thread *td)
1849{
1850
1851 struct cam_periph *periph;
1852 struct cd_softc *softc;
1908 int error, nocopyout;
1853 int nocopyout, error = 0;
1909
1910 periph = (struct cam_periph *)dp->d_drv1;
1911 if (periph == NULL)
1912 return(ENXIO);
1913
1854
1855 periph = (struct cam_periph *)dp->d_drv1;
1856 if (periph == NULL)
1857 return(ENXIO);
1858
1859 cam_periph_lock(periph);
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
1860 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdioctl\n"));
1861
1862 softc = (struct cd_softc *)periph->softc;
1863
1864 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
1865 ("trying to do ioctl %#lx\n", cmd));
1866
1921 error = cam_periph_lock(periph, PRIBIO | PCATCH);
1867 if ((error = cam_periph_hold(periph, PRIBIO | PCATCH)) != 0) {
1868 cam_periph_unlock(periph);
1869 cam_periph_release(periph);
1870 return (error);
1871 }
1922
1872
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);
1873 /*
1874 * If we don't have media loaded, check for it. If still don't
1875 * have media loaded, we can only do a load or eject.
1876 *
1877 * We only care whether media is loaded if this is a cd-specific ioctl
1878 * (thus the IOCGROUP check below). Note that this will break if
1879 * anyone adds any ioctls into the switch statement below that don't
1880 * have their ioctl group set to 'c'.
1881 */
1882 if (((softc->flags & CD_FLAG_VALID_MEDIA) == 0)
1883 && ((cmd != CDIOCCLOSE)
1884 && (cmd != CDIOCEJECT))
1885 && (IOCGROUP(cmd) == 'c')) {
1886 error = cdcheckmedia(periph);
1939 if (error != 0) {
1940 cam_periph_unlock(periph);
1941 return (error);
1942 }
1943 }
1887 }
1888 /*
1889 * Drop the lock here so later mallocs can use WAITOK. The periph
1890 * is essentially locked still with the cam_periph_hold call above.
1891 */
1892 cam_periph_unlock(periph);
1893 if (error != 0)
1894 return (error);
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
1895
1896 nocopyout = 0;
1897 switch (cmd) {
1898
1899 case CDIOCPLAYTRACKS:
1900 {
1901 struct ioc_play_track *args
1902 = (struct ioc_play_track *) addr;
1903 struct cd_mode_params params;
1904 union cd_pages *page;
1905
1906 params.alloc_len = sizeof(union cd_mode_data_6_10);
1907 params.mode_buf = malloc(params.alloc_len, M_TEMP,
1908 M_WAITOK | M_ZERO);
1909
1910 cam_periph_lock(periph);
1959 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
1960 ("trying to do CDIOCPLAYTRACKS\n"));
1961
1962 error = cdgetmode(periph, &params, AUDIO_PAGE);
1963 if (error) {
1964 free(params.mode_buf, M_TEMP);
1911 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
1912 ("trying to do CDIOCPLAYTRACKS\n"));
1913
1914 error = cdgetmode(periph, &params, AUDIO_PAGE);
1915 if (error) {
1916 free(params.mode_buf, M_TEMP);
1917 cam_periph_unlock(periph);
1965 break;
1966 }
1967 page = cdgetpage(&params);
1968
1969 page->audio.flags &= ~CD_PA_SOTC;
1970 page->audio.flags |= CD_PA_IMMED;
1971 error = cdsetmode(periph, &params);
1972 free(params.mode_buf, M_TEMP);
1918 break;
1919 }
1920 page = cdgetpage(&params);
1921
1922 page->audio.flags &= ~CD_PA_SOTC;
1923 page->audio.flags |= CD_PA_IMMED;
1924 error = cdsetmode(periph, &params);
1925 free(params.mode_buf, M_TEMP);
1973 if (error)
1926 if (error) {
1927 cam_periph_unlock(periph);
1974 break;
1928 break;
1929 }
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 }
1930
1931 /*
1932 * This was originally implemented with the PLAY
1933 * AUDIO TRACK INDEX command, but that command was
1934 * deprecated after SCSI-2. Most (all?) SCSI CDROM
1935 * drives support it but ATAPI and ATAPI-derivative
1936 * drives don't seem to support it. So we keep a
1937 * cache of the table of contents and translate

--- 45 unchanged lines hidden (view full) ---

1983 bin2bcd(args->end_track);
1984 }
1985 error = cdplaytracks(periph,
1986 args->start_track,
1987 args->start_index,
1988 args->end_track,
1989 args->end_index);
1990 }
1991 cam_periph_unlock(periph);
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
1992 }
1993 break;
1994 case CDIOCPLAYMSF:
1995 {
1996 struct ioc_play_msf *args
1997 = (struct ioc_play_msf *) addr;
1998 struct cd_mode_params params;
1999 union cd_pages *page;
2000
2001 params.alloc_len = sizeof(union cd_mode_data_6_10);
2002 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2003 M_WAITOK | M_ZERO);
2004
2005 cam_periph_lock(periph);
2049 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2050 ("trying to do CDIOCPLAYMSF\n"));
2051
2052 error = cdgetmode(periph, &params, AUDIO_PAGE);
2053 if (error) {
2054 free(params.mode_buf, M_TEMP);
2006 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2007 ("trying to do CDIOCPLAYMSF\n"));
2008
2009 error = cdgetmode(periph, &params, AUDIO_PAGE);
2010 if (error) {
2011 free(params.mode_buf, M_TEMP);
2012 cam_periph_unlock(periph);
2055 break;
2056 }
2057 page = cdgetpage(&params);
2058
2059 page->audio.flags &= ~CD_PA_SOTC;
2060 page->audio.flags |= CD_PA_IMMED;
2061 error = cdsetmode(periph, &params);
2062 free(params.mode_buf, M_TEMP);
2013 break;
2014 }
2015 page = cdgetpage(&params);
2016
2017 page->audio.flags &= ~CD_PA_SOTC;
2018 page->audio.flags |= CD_PA_IMMED;
2019 error = cdsetmode(periph, &params);
2020 free(params.mode_buf, M_TEMP);
2063 if (error)
2021 if (error) {
2022 cam_periph_unlock(periph);
2064 break;
2023 break;
2024 }
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);
2025 error = cdplaymsf(periph,
2026 args->start_m,
2027 args->start_s,
2028 args->start_f,
2029 args->end_m,
2030 args->end_s,
2031 args->end_f);
2032 cam_periph_unlock(periph);
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
2033 }
2034 break;
2035 case CDIOCPLAYBLOCKS:
2036 {
2037 struct ioc_play_blocks *args
2038 = (struct ioc_play_blocks *) addr;
2039 struct cd_mode_params params;
2040 union cd_pages *page;
2041
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
2042 params.alloc_len = sizeof(union cd_mode_data_6_10);
2043 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2044 M_WAITOK | M_ZERO);
2045
2046 cam_periph_lock(periph);
2047 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2048 ("trying to do CDIOCPLAYBLOCKS\n"));
2049
2050
2088 error = cdgetmode(periph, &params, AUDIO_PAGE);
2089 if (error) {
2090 free(params.mode_buf, M_TEMP);
2051 error = cdgetmode(periph, &params, AUDIO_PAGE);
2052 if (error) {
2053 free(params.mode_buf, M_TEMP);
2054 cam_periph_unlock(periph);
2091 break;
2092 }
2093 page = cdgetpage(&params);
2094
2095 page->audio.flags &= ~CD_PA_SOTC;
2096 page->audio.flags |= CD_PA_IMMED;
2097 error = cdsetmode(periph, &params);
2098 free(params.mode_buf, M_TEMP);
2055 break;
2056 }
2057 page = cdgetpage(&params);
2058
2059 page->audio.flags &= ~CD_PA_SOTC;
2060 page->audio.flags |= CD_PA_IMMED;
2061 error = cdsetmode(periph, &params);
2062 free(params.mode_buf, M_TEMP);
2099 if (error)
2063 if (error) {
2064 cam_periph_unlock(periph);
2100 break;
2065 break;
2066 }
2101 error = cdplay(periph, args->blk, args->len);
2067 error = cdplay(periph, args->blk, args->len);
2068 cam_periph_unlock(periph);
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
2069 }
2070 break;
2071 case CDIOCREADSUBCHANNEL_SYSSPACE:
2072 nocopyout = 1;
2073 /* Fallthrough */
2074 case CDIOCREADSUBCHANNEL:
2075 {
2076 struct ioc_read_subchannel *args
2077 = (struct ioc_read_subchannel *) addr;
2078 struct cd_sub_channel_info *data;
2079 u_int32_t len = args->data_len;
2080
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
2081 data = malloc(sizeof(struct cd_sub_channel_info),
2082 M_TEMP, M_WAITOK);
2083
2084 cam_periph_lock(periph);
2085 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2086 ("trying to do CDIOCREADSUBCHANNEL\n"));
2087
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);
2088 if ((len > sizeof(struct cd_sub_channel_info)) ||
2089 (len < sizeof(struct cd_sub_channel_header))) {
2090 printf(
2091 "scsi_cd: cdioctl: "
2092 "cdioreadsubchannel: error, len=%d\n",
2093 len);
2094 error = EINVAL;
2095 free(data, M_TEMP);
2096 cam_periph_unlock(periph);
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);
2097 break;
2098 }
2099
2100 if (softc->quirks & CD_Q_BCD_TRACKS)
2101 args->track = bin2bcd(args->track);
2102
2103 error = cdreadsubchannel(periph, args->address_format,
2104 args->data_format, args->track, data, len);
2105
2106 if (error) {
2107 free(data, M_TEMP);
2108 cam_periph_unlock(periph);
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)));
2109 break;
2110 }
2111 if (softc->quirks & CD_Q_BCD_TRACKS)
2112 data->what.track_info.track_number =
2113 bcd2bin(data->what.track_info.track_number);
2114 len = min(len, ((data->header.data_len[0] << 8) +
2115 data->header.data_len[1] +
2116 sizeof(struct cd_sub_channel_header)));
2117 cam_periph_unlock(periph);
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
2118 if (nocopyout == 0) {
2119 if (copyout(data, args->data, len) != 0) {
2120 error = EFAULT;
2121 }
2122 } else {
2123 bcopy(data, args->data, len);
2124 }
2125 free(data, M_TEMP);
2126 }
2127 break;
2128
2129 case CDIOREADTOCHEADER:
2130 {
2131 struct ioc_toc_header *th;
2132
2133 th = malloc(sizeof(struct ioc_toc_header), M_TEMP,
2134 M_WAITOK);
2135
2136 cam_periph_lock(periph);
2162 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2163 ("trying to do CDIOREADTOCHEADER\n"));
2164
2137 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2138 ("trying to do CDIOREADTOCHEADER\n"));
2139
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);
2140 error = cdreadtoc(periph, 0, 0, (u_int8_t *)th,
2141 sizeof (*th), /*sense_flags*/0);
2142 if (error) {
2143 free(th, M_TEMP);
2144 cam_periph_unlock(periph);
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);
2145 break;
2146 }
2147 if (softc->quirks & CD_Q_BCD_TRACKS) {
2148 /* we are going to have to convert the BCD
2149 * encoding on the cd to what is expected
2150 */
2151 th->starting_track =
2152 bcd2bin(th->starting_track);
2153 th->ending_track = bcd2bin(th->ending_track);
2154 }
2155 th->len = ntohs(th->len);
2156 bcopy(th, addr, sizeof(*th));
2157 free(th, M_TEMP);
2158 cam_periph_unlock(periph);
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
2159 }
2160 break;
2161 case CDIOREADTOCENTRYS:
2162 {
2163 struct cd_tocdata *data;
2164 struct cd_toc_single *lead;
2165 struct ioc_read_toc_entry *te =
2166 (struct ioc_read_toc_entry *) addr;
2167 struct ioc_toc_header *th;
2168 u_int32_t len, readlen, idx, num;
2169 u_int32_t starting_track = te->starting_track;
2170
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
2171 data = malloc(sizeof(*data), M_TEMP, M_WAITOK);
2172 lead = malloc(sizeof(*lead), M_TEMP, M_WAITOK);
2173
2174 cam_periph_lock(periph);
2175 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2176 ("trying to do CDIOREADTOCENTRYS\n"));
2177
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);
2178 if (te->data_len < sizeof(struct cd_toc_entry)
2179 || (te->data_len % sizeof(struct cd_toc_entry)) != 0
2180 || (te->address_format != CD_MSF_FORMAT
2181 && te->address_format != CD_LBA_FORMAT)) {
2182 error = EINVAL;
2183 printf("scsi_cd: error in readtocentries, "
2184 "returning EINVAL\n");
2185 free(data, M_TEMP);
2186 free(lead, M_TEMP);
2187 cam_periph_unlock(periph);
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);
2188 break;
2189 }
2190
2191 th = &data->header;
2192 error = cdreadtoc(periph, 0, 0, (u_int8_t *)th,
2193 sizeof (*th), /*sense_flags*/0);
2194 if (error) {
2195 free(data, M_TEMP);
2196 free(lead, M_TEMP);
2197 cam_periph_unlock(periph);
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);
2198 break;
2199 }
2200
2201 if (softc->quirks & CD_Q_BCD_TRACKS) {
2202 /* we are going to have to convert the BCD
2203 * encoding on the cd to what is expected
2204 */
2205 th->starting_track =

--- 6 unchanged lines hidden (view full) ---

2212 else if (starting_track == LEADOUT)
2213 starting_track = th->ending_track + 1;
2214 else if (starting_track < th->starting_track ||
2215 starting_track > th->ending_track + 1) {
2216 printf("scsi_cd: error in readtocentries, "
2217 "returning EINVAL\n");
2218 free(data, M_TEMP);
2219 free(lead, M_TEMP);
2220 cam_periph_unlock(periph);
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);
2221 error = EINVAL;
2222 break;
2223 }
2224
2225 /* calculate reading length without leadout entry */
2226 readlen = (th->ending_track - starting_track + 1) *
2227 sizeof(struct cd_toc_entry);
2228

--- 5 unchanged lines hidden (view full) ---

2234 readlen = len;
2235 }
2236 if (len > sizeof(data->entries)) {
2237 printf("scsi_cd: error in readtocentries, "
2238 "returning EINVAL\n");
2239 error = EINVAL;
2240 free(data, M_TEMP);
2241 free(lead, M_TEMP);
2242 cam_periph_unlock(periph);
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);
2243 break;
2244 }
2245 num = len / sizeof(struct cd_toc_entry);
2246
2247 if (readlen > 0) {
2248 error = cdreadtoc(periph, te->address_format,
2249 starting_track,
2250 (u_int8_t *)data,
2251 readlen + sizeof (*th),
2252 /*sense_flags*/0);
2253 if (error) {
2254 free(data, M_TEMP);
2255 free(lead, M_TEMP);
2256 cam_periph_unlock(periph);
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);
2257 break;
2258 }
2259 }
2260
2261 /* make leadout entry if needed */
2262 idx = starting_track + num - 1;
2263 if (softc->quirks & CD_Q_BCD_TRACKS)
2264 th->ending_track = bcd2bin(th->ending_track);
2265 if (idx == th->ending_track + 1) {
2266 error = cdreadtoc(periph, te->address_format,
2267 LEADOUT, (u_int8_t *)lead,
2268 sizeof(*lead),
2269 /*sense_flags*/0);
2270 if (error) {
2271 free(data, M_TEMP);
2272 free(lead, M_TEMP);
2273 cam_periph_unlock(periph);
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
2274 break;
2275 }
2276 data->entries[idx - starting_track] =
2277 lead->entry;
2278 }
2279 if (softc->quirks & CD_Q_BCD_TRACKS) {
2280 for (idx = 0; idx < num - 1; idx++) {
2281 data->entries[idx].track =
2282 bcd2bin(data->entries[idx].track);
2283 }
2284 }
2285
2286 cam_periph_unlock(periph);
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
2287 error = copyout(data->entries, te->data, len);
2288 free(data, M_TEMP);
2289 free(lead, M_TEMP);
2290 }
2291 break;
2292 case CDIOREADTOCENTRY:
2293 {
2294 struct cd_toc_single *data;
2295 struct ioc_read_toc_single_entry *te =
2296 (struct ioc_read_toc_single_entry *) addr;
2297 struct ioc_toc_header *th;
2298 u_int32_t track;
2299
2300 data = malloc(sizeof(*data), M_TEMP, M_WAITOK);
2301
2302 cam_periph_lock(periph);
2317 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2318 ("trying to do CDIOREADTOCENTRY\n"));
2319
2303 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2304 ("trying to do CDIOREADTOCENTRY\n"));
2305
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;
2306 if (te->address_format != CD_MSF_FORMAT
2307 && te->address_format != CD_LBA_FORMAT) {
2308 printf("error in readtocentry, "
2309 " returning EINVAL\n");
2310 free(data, M_TEMP);
2311 error = EINVAL;
2312 cam_periph_unlock(periph);
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);
2313 break;
2314 }
2315
2316 th = &data->header;
2317 error = cdreadtoc(periph, 0, 0, (u_int8_t *)th,
2318 sizeof (*th), /*sense_flags*/0);
2319 if (error) {
2320 free(data, M_TEMP);
2321 cam_periph_unlock(periph);
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;
2322 break;
2323 }
2324
2325 if (softc->quirks & CD_Q_BCD_TRACKS) {
2326 /* we are going to have to convert the BCD
2327 * encoding on the cd to what is expected
2328 */
2329 th->starting_track =

--- 6 unchanged lines hidden (view full) ---

2336 else if (track == LEADOUT)
2337 /* OK */;
2338 else if (track < th->starting_track ||
2339 track > th->ending_track + 1) {
2340 printf("error in readtocentry, "
2341 " returning EINVAL\n");
2342 free(data, M_TEMP);
2343 error = EINVAL;
2344 cam_periph_unlock(periph);
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);
2345 break;
2346 }
2347
2348 error = cdreadtoc(periph, te->address_format, track,
2349 (u_int8_t *)data, sizeof(*data),
2350 /*sense_flags*/0);
2351 if (error) {
2352 free(data, M_TEMP);
2353 cam_periph_unlock(periph);
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);
2354 break;
2355 }
2356
2357 if (softc->quirks & CD_Q_BCD_TRACKS)
2358 data->entry.track = bcd2bin(data->entry.track);
2359 bcopy(&data->entry, &te->entry,
2360 sizeof(struct cd_toc_entry));
2361 free(data, M_TEMP);
2362 cam_periph_unlock(periph);
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
2363 }
2364 break;
2365 case CDIOCSETPATCH:
2366 {
2367 struct ioc_patch *arg = (struct ioc_patch *)addr;
2368 struct cd_mode_params params;
2369 union cd_pages *page;
2370
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);
2371 params.alloc_len = sizeof(union cd_mode_data_6_10);
2372 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2373 M_WAITOK | M_ZERO);
2374
2375 cam_periph_lock(periph);
2376 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2377 ("trying to do CDIOCSETPATCH\n"));
2378
2388 error = cdgetmode(periph, &params, AUDIO_PAGE);
2389 if (error) {
2390 free(params.mode_buf, M_TEMP);
2379 error = cdgetmode(periph, &params, AUDIO_PAGE);
2380 if (error) {
2381 free(params.mode_buf, M_TEMP);
2382 cam_periph_unlock(periph);
2391 break;
2392 }
2393 page = cdgetpage(&params);
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, &params);
2402 free(params.mode_buf, M_TEMP);
2383 break;
2384 }
2385 page = cdgetpage(&params);
2386
2387 page->audio.port[LEFT_PORT].channels =
2388 arg->patch[0];
2389 page->audio.port[RIGHT_PORT].channels =
2390 arg->patch[1];
2391 page->audio.port[2].channels = arg->patch[2];
2392 page->audio.port[3].channels = arg->patch[3];
2393 error = cdsetmode(periph, &params);
2394 free(params.mode_buf, M_TEMP);
2395 cam_periph_unlock(periph);
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
2396 }
2397 break;
2398 case CDIOCGETVOL:
2399 {
2400 struct ioc_vol *arg = (struct ioc_vol *) addr;
2401 struct cd_mode_params params;
2402 union cd_pages *page;
2403
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);
2404 params.alloc_len = sizeof(union cd_mode_data_6_10);
2405 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2406 M_WAITOK | M_ZERO);
2407
2408 cam_periph_lock(periph);
2409 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2410 ("trying to do CDIOCGETVOL\n"));
2411
2417 error = cdgetmode(periph, &params, AUDIO_PAGE);
2418 if (error) {
2419 free(params.mode_buf, M_TEMP);
2412 error = cdgetmode(periph, &params, AUDIO_PAGE);
2413 if (error) {
2414 free(params.mode_buf, M_TEMP);
2415 cam_periph_unlock(periph);
2420 break;
2421 }
2422 page = cdgetpage(&params);
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);
2416 break;
2417 }
2418 page = cdgetpage(&params);
2419
2420 arg->vol[LEFT_PORT] =
2421 page->audio.port[LEFT_PORT].volume;
2422 arg->vol[RIGHT_PORT] =
2423 page->audio.port[RIGHT_PORT].volume;
2424 arg->vol[2] = page->audio.port[2].volume;
2425 arg->vol[3] = page->audio.port[3].volume;
2426 free(params.mode_buf, M_TEMP);
2427 cam_periph_unlock(periph);
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
2428 }
2429 break;
2430 case CDIOCSETVOL:
2431 {
2432 struct ioc_vol *arg = (struct ioc_vol *) addr;
2433 struct cd_mode_params params;
2434 union cd_pages *page;
2435
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);
2436 params.alloc_len = sizeof(union cd_mode_data_6_10);
2437 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2438 M_WAITOK | M_ZERO);
2439
2440 cam_periph_lock(periph);
2441 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2442 ("trying to do CDIOCSETVOL\n"));
2443
2445 error = cdgetmode(periph, &params, AUDIO_PAGE);
2446 if (error) {
2447 free(params.mode_buf, M_TEMP);
2444 error = cdgetmode(periph, &params, AUDIO_PAGE);
2445 if (error) {
2446 free(params.mode_buf, M_TEMP);
2447 cam_periph_unlock(periph);
2448 break;
2449 }
2450 page = cdgetpage(&params);
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, &params);
2448 break;
2449 }
2450 page = cdgetpage(&params);
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, &params);
2461 cam_periph_unlock(periph);
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
2462 free(params.mode_buf, M_TEMP);
2463 }
2464 break;
2465 case CDIOCSETMONO:
2466 {
2467 struct cd_mode_params params;
2468 union cd_pages *page;
2469
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);
2470 params.alloc_len = sizeof(union cd_mode_data_6_10);
2471 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2472 M_WAITOK | M_ZERO);
2473
2474 cam_periph_lock(periph);
2475 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2476 ("trying to do CDIOCSETMONO\n"));
2477
2475 error = cdgetmode(periph, &params, AUDIO_PAGE);
2476 if (error) {
2477 free(params.mode_buf, M_TEMP);
2478 error = cdgetmode(periph, &params, AUDIO_PAGE);
2479 if (error) {
2480 free(params.mode_buf, M_TEMP);
2481 cam_periph_unlock(periph);
2478 break;
2479 }
2480 page = cdgetpage(&params);
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, &params);
2482 break;
2483 }
2484 page = cdgetpage(&params);
2485
2486 page->audio.port[LEFT_PORT].channels =
2487 LEFT_CHANNEL | RIGHT_CHANNEL;
2488 page->audio.port[RIGHT_PORT].channels =
2489 LEFT_CHANNEL | RIGHT_CHANNEL;
2490 page->audio.port[2].channels = 0;
2491 page->audio.port[3].channels = 0;
2492 error = cdsetmode(periph, &params);
2493 cam_periph_unlock(periph);
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
2494 free(params.mode_buf, M_TEMP);
2495 }
2496 break;
2497 case CDIOCSETSTEREO:
2498 {
2499 struct cd_mode_params params;
2500 union cd_pages *page;
2501
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);
2502 params.alloc_len = sizeof(union cd_mode_data_6_10);
2503 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2504 M_WAITOK | M_ZERO);
2505
2506 cam_periph_lock(periph);
2507 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2508 ("trying to do CDIOCSETSTEREO\n"));
2509
2503 error = cdgetmode(periph, &params, AUDIO_PAGE);
2504 if (error) {
2505 free(params.mode_buf, M_TEMP);
2510 error = cdgetmode(periph, &params, AUDIO_PAGE);
2511 if (error) {
2512 free(params.mode_buf, M_TEMP);
2513 cam_periph_unlock(periph);
2506 break;
2507 }
2508 page = cdgetpage(&params);
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, &params);
2517 free(params.mode_buf, M_TEMP);
2514 break;
2515 }
2516 page = cdgetpage(&params);
2517
2518 page->audio.port[LEFT_PORT].channels =
2519 LEFT_CHANNEL;
2520 page->audio.port[RIGHT_PORT].channels =
2521 RIGHT_CHANNEL;
2522 page->audio.port[2].channels = 0;
2523 page->audio.port[3].channels = 0;
2524 error = cdsetmode(periph, &params);
2525 free(params.mode_buf, M_TEMP);
2526 cam_periph_unlock(periph);
2518 }
2519 break;
2520 case CDIOCSETMUTE:
2521 {
2522 struct cd_mode_params params;
2523 union cd_pages *page;
2524
2527 }
2528 break;
2529 case CDIOCSETMUTE:
2530 {
2531 struct cd_mode_params params;
2532 union cd_pages *page;
2533
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);
2534 params.alloc_len = sizeof(union cd_mode_data_6_10);
2535 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2536 M_WAITOK | M_ZERO);
2537
2538 cam_periph_lock(periph);
2539 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2540 ("trying to do CDIOCSETMUTE\n"));
2541
2531 error = cdgetmode(periph, &params, AUDIO_PAGE);
2532 if (error) {
2533 free(&params, M_TEMP);
2542 error = cdgetmode(periph, &params, AUDIO_PAGE);
2543 if (error) {
2544 free(&params, M_TEMP);
2545 cam_periph_unlock(periph);
2534 break;
2535 }
2536 page = cdgetpage(&params);
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, &params);
2543 free(params.mode_buf, M_TEMP);
2546 break;
2547 }
2548 page = cdgetpage(&params);
2549
2550 page->audio.port[LEFT_PORT].channels = 0;
2551 page->audio.port[RIGHT_PORT].channels = 0;
2552 page->audio.port[2].channels = 0;
2553 page->audio.port[3].channels = 0;
2554 error = cdsetmode(periph, &params);
2555 free(params.mode_buf, M_TEMP);
2556 cam_periph_unlock(periph);
2544 }
2545 break;
2546 case CDIOCSETLEFT:
2547 {
2548 struct cd_mode_params params;
2549 union cd_pages *page;
2550
2557 }
2558 break;
2559 case CDIOCSETLEFT:
2560 {
2561 struct cd_mode_params params;
2562 union cd_pages *page;
2563
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);
2564 params.alloc_len = sizeof(union cd_mode_data_6_10);
2565 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2566 M_WAITOK | M_ZERO);
2557
2567
2568 cam_periph_lock(periph);
2569 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2570 ("trying to do CDIOCSETLEFT\n"));
2571
2558 error = cdgetmode(periph, &params, AUDIO_PAGE);
2559 if (error) {
2560 free(params.mode_buf, M_TEMP);
2572 error = cdgetmode(periph, &params, AUDIO_PAGE);
2573 if (error) {
2574 free(params.mode_buf, M_TEMP);
2575 cam_periph_unlock(periph);
2561 break;
2562 }
2563 page = cdgetpage(&params);
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, &params);
2570 free(params.mode_buf, M_TEMP);
2576 break;
2577 }
2578 page = cdgetpage(&params);
2579
2580 page->audio.port[LEFT_PORT].channels = LEFT_CHANNEL;
2581 page->audio.port[RIGHT_PORT].channels = LEFT_CHANNEL;
2582 page->audio.port[2].channels = 0;
2583 page->audio.port[3].channels = 0;
2584 error = cdsetmode(periph, &params);
2585 free(params.mode_buf, M_TEMP);
2586 cam_periph_unlock(periph);
2571 }
2572 break;
2573 case CDIOCSETRIGHT:
2574 {
2575 struct cd_mode_params params;
2576 union cd_pages *page;
2577
2587 }
2588 break;
2589 case CDIOCSETRIGHT:
2590 {
2591 struct cd_mode_params params;
2592 union cd_pages *page;
2593
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
2594 params.alloc_len = sizeof(union cd_mode_data_6_10);
2595 params.mode_buf = malloc(params.alloc_len, M_TEMP,
2596 M_WAITOK | M_ZERO);
2597
2598 cam_periph_lock(periph);
2599 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2600 ("trying to do CDIOCSETRIGHT\n"));
2601
2585 error = cdgetmode(periph, &params, AUDIO_PAGE);
2586 if (error) {
2587 free(params.mode_buf, M_TEMP);
2602 error = cdgetmode(periph, &params, AUDIO_PAGE);
2603 if (error) {
2604 free(params.mode_buf, M_TEMP);
2605 cam_periph_unlock(periph);
2588 break;
2589 }
2590 page = cdgetpage(&params);
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, &params);
2597 free(params.mode_buf, M_TEMP);
2606 break;
2607 }
2608 page = cdgetpage(&params);
2609
2610 page->audio.port[LEFT_PORT].channels = RIGHT_CHANNEL;
2611 page->audio.port[RIGHT_PORT].channels = RIGHT_CHANNEL;
2612 page->audio.port[2].channels = 0;
2613 page->audio.port[3].channels = 0;
2614 error = cdsetmode(periph, &params);
2615 free(params.mode_buf, M_TEMP);
2616 cam_periph_unlock(periph);
2598 }
2599 break;
2600 case CDIOCRESUME:
2617 }
2618 break;
2619 case CDIOCRESUME:
2620 cam_periph_lock(periph);
2601 error = cdpause(periph, 1);
2621 error = cdpause(periph, 1);
2622 cam_periph_unlock(periph);
2602 break;
2603 case CDIOCPAUSE:
2623 break;
2624 case CDIOCPAUSE:
2625 cam_periph_lock(periph);
2604 error = cdpause(periph, 0);
2626 error = cdpause(periph, 0);
2627 cam_periph_unlock(periph);
2605 break;
2606 case CDIOCSTART:
2628 break;
2629 case CDIOCSTART:
2630 cam_periph_lock(periph);
2607 error = cdstartunit(periph, 0);
2631 error = cdstartunit(periph, 0);
2632 cam_periph_unlock(periph);
2608 break;
2609 case CDIOCCLOSE:
2633 break;
2634 case CDIOCCLOSE:
2635 cam_periph_lock(periph);
2610 error = cdstartunit(periph, 1);
2636 error = cdstartunit(periph, 1);
2637 cam_periph_unlock(periph);
2611 break;
2612 case CDIOCSTOP:
2638 break;
2639 case CDIOCSTOP:
2640 cam_periph_lock(periph);
2613 error = cdstopunit(periph, 0);
2641 error = cdstopunit(periph, 0);
2642 cam_periph_unlock(periph);
2614 break;
2615 case CDIOCEJECT:
2643 break;
2644 case CDIOCEJECT:
2645 cam_periph_lock(periph);
2616 error = cdstopunit(periph, 1);
2646 error = cdstopunit(periph, 1);
2647 cam_periph_unlock(periph);
2617 break;
2618 case CDIOCALLOW:
2648 break;
2649 case CDIOCALLOW:
2650 cam_periph_lock(periph);
2619 cdprevent(periph, PR_ALLOW);
2651 cdprevent(periph, PR_ALLOW);
2652 cam_periph_unlock(periph);
2620 break;
2621 case CDIOCPREVENT:
2653 break;
2654 case CDIOCPREVENT:
2655 cam_periph_lock(periph);
2622 cdprevent(periph, PR_PREVENT);
2656 cdprevent(periph, PR_PREVENT);
2657 cam_periph_unlock(periph);
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:
2658 break;
2659 case CDIOCSETDEBUG:
2660 /* sc_link->flags |= (SDEV_DB1 | SDEV_DB2); */
2661 error = ENOTTY;
2662 break;
2663 case CDIOCCLRDEBUG:
2664 /* sc_link->flags &= ~(SDEV_DB1 | SDEV_DB2); */
2665 error = ENOTTY;
2666 break;
2667 case CDIOCRESET:
2668 /* return (cd_reset(periph)); */
2669 error = ENOTTY;
2670 break;
2671 case CDRIOCREADSPEED:
2672 cam_periph_lock(periph);
2637 error = cdsetspeed(periph, *(u_int32_t *)addr, CDR_MAX_SPEED);
2673 error = cdsetspeed(periph, *(u_int32_t *)addr, CDR_MAX_SPEED);
2674 cam_periph_unlock(periph);
2638 break;
2639 case CDRIOCWRITESPEED:
2675 break;
2676 case CDRIOCWRITESPEED:
2677 cam_periph_lock(periph);
2640 error = cdsetspeed(periph, CDR_MAX_SPEED, *(u_int32_t *)addr);
2678 error = cdsetspeed(periph, CDR_MAX_SPEED, *(u_int32_t *)addr);
2679 cam_periph_unlock(periph);
2641 break;
2642 case DVDIOCSENDKEY:
2643 case DVDIOCREPORTKEY: {
2644 struct dvd_authinfo *authinfo;
2645
2646 authinfo = (struct dvd_authinfo *)addr;
2647
2680 break;
2681 case DVDIOCSENDKEY:
2682 case DVDIOCREPORTKEY: {
2683 struct dvd_authinfo *authinfo;
2684
2685 authinfo = (struct dvd_authinfo *)addr;
2686
2687 cam_periph_lock(periph);
2648 if (cmd == DVDIOCREPORTKEY)
2649 error = cdreportkey(periph, authinfo);
2650 else
2651 error = cdsendkey(periph, authinfo);
2688 if (cmd == DVDIOCREPORTKEY)
2689 error = cdreportkey(periph, authinfo);
2690 else
2691 error = cdsendkey(periph, authinfo);
2692 cam_periph_unlock(periph);
2652 break;
2653 }
2654 case DVDIOCREADSTRUCTURE: {
2655 struct dvd_struct *dvdstruct;
2656
2657 dvdstruct = (struct dvd_struct *)addr;
2658
2693 break;
2694 }
2695 case DVDIOCREADSTRUCTURE: {
2696 struct dvd_struct *dvdstruct;
2697
2698 dvdstruct = (struct dvd_struct *)addr;
2699
2700 cam_periph_lock(periph);
2659 error = cdreaddvdstructure(periph, dvdstruct);
2701 error = cdreaddvdstructure(periph, dvdstruct);
2702 cam_periph_unlock(periph);
2660
2661 break;
2662 }
2663 default:
2703
2704 break;
2705 }
2706 default:
2707 cam_periph_lock(periph);
2664 error = cam_periph_ioctl(periph, cmd, addr, cderror);
2708 error = cam_periph_ioctl(periph, cmd, addr, cderror);
2709 cam_periph_unlock(periph);
2665 break;
2666 }
2667
2710 break;
2711 }
2712
2668 cam_periph_unlock(periph);
2669
2713 cam_periph_lock(periph);
2714 cam_periph_unhold(periph);
2715
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 }
2716 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("leaving cdioctl\n"));
2717 if (error && bootverbose) {
2718 printf("scsi_cd.c::ioctl cmd=%08lx error=%d\n", cmd, error);
2719 }
2720 cam_periph_unlock(periph);
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
2721
2722 return (error);
2723}
2724
2725static void
2726cdprevent(struct cam_periph *periph, int action)
2727{
2728 union ccb *ccb;

--- 182 unchanged lines hidden (view full) ---

2911 int error;
2912
2913 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdsize\n"));
2914
2915 softc = (struct cd_softc *)periph->softc;
2916
2917 ccb = cdgetccb(periph, /* priority */ 1);
2918
2919 /* XXX Should be M_WAITOK */
2872 rcap_buf = malloc(sizeof(struct scsi_read_capacity_data),
2920 rcap_buf = malloc(sizeof(struct scsi_read_capacity_data),
2873 M_TEMP, M_WAITOK);
2921 M_TEMP, M_NOWAIT);
2922 if (rcap_buf == NULL)
2923 return (ENOMEM);
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 ---
2924
2925 scsi_read_capacity(&ccb->csio,
2926 /*retries*/ 1,
2927 cddone,
2928 MSG_SIMPLE_Q_TAG,
2929 rcap_buf,
2930 SSD_FULL_SIZE,
2931 /* timeout */20000);

--- 1347 unchanged lines hidden ---