1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <stdio.h> 30*7c478bd9Sstevel@tonic-gate #include <string.h> 31*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 32*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 33*7c478bd9Sstevel@tonic-gate #include <libintl.h> 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #include "transport.h" 36*7c478bd9Sstevel@tonic-gate #include "toshiba.h" 37*7c478bd9Sstevel@tonic-gate #include "device.h" 38*7c478bd9Sstevel@tonic-gate #include "misc_scsi.h" 39*7c478bd9Sstevel@tonic-gate #include "util.h" 40*7c478bd9Sstevel@tonic-gate #include "main.h" 41*7c478bd9Sstevel@tonic-gate #include "msgs.h" 42*7c478bd9Sstevel@tonic-gate #include "mmc.h" 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate static int speed_tbl[4] = { 1, 2, 12, 4 }; 45*7c478bd9Sstevel@tonic-gate static uchar_t rev_speed_tbl[16] = { 0, 0, 1, 0, 3, 0, 0, 0, 0, 46*7c478bd9Sstevel@tonic-gate 0, 0, 0, 2, 0, 0, 0 }; 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate /* 49*7c478bd9Sstevel@tonic-gate * These are commands for using older Sun Toshiba drives. These 50*7c478bd9Sstevel@tonic-gate * commands are needed for reading CD TOC and audio extraction 51*7c478bd9Sstevel@tonic-gate * and changing speeds (used for audio extraction). 52*7c478bd9Sstevel@tonic-gate */ 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate int 55*7c478bd9Sstevel@tonic-gate read_toc_as_per_8020(int fd, int format, int trackno, int buflen, uchar_t *buf) 56*7c478bd9Sstevel@tonic-gate { 57*7c478bd9Sstevel@tonic-gate struct uscsi_cmd *scmd; 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate scmd = get_uscsi_cmd(); 60*7c478bd9Sstevel@tonic-gate scmd->uscsi_flags = USCSI_READ|USCSI_SILENT; 61*7c478bd9Sstevel@tonic-gate scmd->uscsi_timeout = 60; 62*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[0] = READ_TOC_CMD; 63*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[6] = trackno; 64*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[8] = buflen & 0xff; 65*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[7] = (buflen >> 8) & 0xff; 66*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[9] = (format << 6) & 0xc0; 67*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdblen = 10; 68*7c478bd9Sstevel@tonic-gate scmd->uscsi_bufaddr = (char *)buf; 69*7c478bd9Sstevel@tonic-gate scmd->uscsi_buflen = buflen; 70*7c478bd9Sstevel@tonic-gate if (uscsi(fd, scmd) < 0) 71*7c478bd9Sstevel@tonic-gate return (0); 72*7c478bd9Sstevel@tonic-gate return (1); 73*7c478bd9Sstevel@tonic-gate } 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate int 76*7c478bd9Sstevel@tonic-gate toshiba_read_audio(cd_device *target, uint_t start_blk, uint_t nblk, 77*7c478bd9Sstevel@tonic-gate uchar_t *buf) 78*7c478bd9Sstevel@tonic-gate { 79*7c478bd9Sstevel@tonic-gate struct uscsi_cmd *scmd; 80*7c478bd9Sstevel@tonic-gate int ret, retry; 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate scmd = get_uscsi_cmd(); 83*7c478bd9Sstevel@tonic-gate scmd->uscsi_flags = USCSI_READ|USCSI_SILENT; 84*7c478bd9Sstevel@tonic-gate scmd->uscsi_timeout = 60; 85*7c478bd9Sstevel@tonic-gate ((uchar_t *)scmd->uscsi_cdb)[0] = READ_AUDIO_CMD; 86*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[5] = start_blk & 0xff; 87*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[4] = (start_blk >> 8) & 0xff; 88*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[3] = (start_blk >> 16) & 0xff; 89*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[2] = (start_blk >> 24) & 0xff; 90*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[9] = nblk & 0xff; 91*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[8] = (nblk >> 8) & 0xff; 92*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[7] = (nblk >> 16) & 0xff; 93*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[6] = (nblk >> 24) & 0xff; 94*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdblen = 12; 95*7c478bd9Sstevel@tonic-gate scmd->uscsi_bufaddr = (char *)buf; 96*7c478bd9Sstevel@tonic-gate scmd->uscsi_buflen = nblk*2352; 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate for (retry = 0; retry < 3; retry++) { 99*7c478bd9Sstevel@tonic-gate ret = uscsi(target->d_fd, scmd); 100*7c478bd9Sstevel@tonic-gate if (ret >= 0) 101*7c478bd9Sstevel@tonic-gate break; 102*7c478bd9Sstevel@tonic-gate } 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate if (ret < 0) 105*7c478bd9Sstevel@tonic-gate return (0); 106*7c478bd9Sstevel@tonic-gate return (1); 107*7c478bd9Sstevel@tonic-gate } 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate int 110*7c478bd9Sstevel@tonic-gate toshiba_speed_ctrl(cd_device *dev, int cmd, int speed) 111*7c478bd9Sstevel@tonic-gate { 112*7c478bd9Sstevel@tonic-gate uchar_t *mpage; 113*7c478bd9Sstevel@tonic-gate struct uscsi_cmd *scmd; 114*7c478bd9Sstevel@tonic-gate int ret; 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate if ((cmd == GET_WRITE_SPEED) || (cmd == SET_WRITE_SPEED)) { 117*7c478bd9Sstevel@tonic-gate if (debug) { 118*7c478bd9Sstevel@tonic-gate (void) printf("toshiba_speed_ctrl: WRONG CMD %d\n", 119*7c478bd9Sstevel@tonic-gate cmd); 120*7c478bd9Sstevel@tonic-gate } 121*7c478bd9Sstevel@tonic-gate return (0); 122*7c478bd9Sstevel@tonic-gate } 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate if (cmd == SET_READ_SPEED) { 125*7c478bd9Sstevel@tonic-gate if (dev->d_cap & DEV_CAP_SETTING_SPEED_NOT_ALLOWED) { 126*7c478bd9Sstevel@tonic-gate if (verbose) 127*7c478bd9Sstevel@tonic-gate err_msg(gettext( 128*7c478bd9Sstevel@tonic-gate "Cannot set speed on this device.\n")); 129*7c478bd9Sstevel@tonic-gate return (0); 130*7c478bd9Sstevel@tonic-gate } 131*7c478bd9Sstevel@tonic-gate if (speed == 32) { 132*7c478bd9Sstevel@tonic-gate if (strncmp("SUN32XCD", 133*7c478bd9Sstevel@tonic-gate (const char *)&dev->d_inq[24], 8) == 0) 134*7c478bd9Sstevel@tonic-gate return (1); 135*7c478bd9Sstevel@tonic-gate } 136*7c478bd9Sstevel@tonic-gate if ((speed != 1) && (speed != 2) && (speed != 4) && 137*7c478bd9Sstevel@tonic-gate (speed != 12)) { 138*7c478bd9Sstevel@tonic-gate if (verbose) 139*7c478bd9Sstevel@tonic-gate err_msg(gettext( 140*7c478bd9Sstevel@tonic-gate "%dx speed is not supported by the device.\n")); 141*7c478bd9Sstevel@tonic-gate return (0); 142*7c478bd9Sstevel@tonic-gate } 143*7c478bd9Sstevel@tonic-gate } 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate ret = 0; 146*7c478bd9Sstevel@tonic-gate mpage = (uchar_t *)my_zalloc(16); 147*7c478bd9Sstevel@tonic-gate scmd = get_uscsi_cmd(); 148*7c478bd9Sstevel@tonic-gate scmd->uscsi_flags = USCSI_READ|USCSI_SILENT; 149*7c478bd9Sstevel@tonic-gate scmd->uscsi_timeout = 60; 150*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdblen = 6; 151*7c478bd9Sstevel@tonic-gate scmd->uscsi_bufaddr = (char *)mpage; 152*7c478bd9Sstevel@tonic-gate scmd->uscsi_buflen = 16; 153*7c478bd9Sstevel@tonic-gate /* 6 byte mode sense for older drives */ 154*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[0] = MODE_SENSE_6_CMD; 155*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[2] = 0x31; 156*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[4] = 16; 157*7c478bd9Sstevel@tonic-gate if (uscsi(dev->d_fd, scmd) < 0) 158*7c478bd9Sstevel@tonic-gate goto end_speed_ctrl; 159*7c478bd9Sstevel@tonic-gate if (cmd == GET_READ_SPEED) { 160*7c478bd9Sstevel@tonic-gate ret = speed_tbl[mpage[14] & 0x3]; 161*7c478bd9Sstevel@tonic-gate goto end_speed_ctrl; 162*7c478bd9Sstevel@tonic-gate } 163*7c478bd9Sstevel@tonic-gate if (cmd == SET_READ_SPEED) { 164*7c478bd9Sstevel@tonic-gate (void) memset(mpage, 0, 9); 165*7c478bd9Sstevel@tonic-gate mpage[3] = 8; 166*7c478bd9Sstevel@tonic-gate mpage[12] = 0x31; 167*7c478bd9Sstevel@tonic-gate mpage[13] = 2; 168*7c478bd9Sstevel@tonic-gate mpage[14] = rev_speed_tbl[speed]; 169*7c478bd9Sstevel@tonic-gate scmd = get_uscsi_cmd(); 170*7c478bd9Sstevel@tonic-gate scmd->uscsi_flags = USCSI_WRITE|USCSI_SILENT; 171*7c478bd9Sstevel@tonic-gate scmd->uscsi_timeout = 60; 172*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdblen = 6; 173*7c478bd9Sstevel@tonic-gate scmd->uscsi_bufaddr = (char *)mpage; 174*7c478bd9Sstevel@tonic-gate scmd->uscsi_buflen = 16; 175*7c478bd9Sstevel@tonic-gate /* 6 byte mode sense command for older drives */ 176*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[0] = MODE_SELECT_6_CMD; 177*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[1] = 0x10; 178*7c478bd9Sstevel@tonic-gate scmd->uscsi_cdb[4] = 16; 179*7c478bd9Sstevel@tonic-gate if (uscsi(dev->d_fd, scmd) < 0) 180*7c478bd9Sstevel@tonic-gate goto end_speed_ctrl; 181*7c478bd9Sstevel@tonic-gate ret = 1; 182*7c478bd9Sstevel@tonic-gate } 183*7c478bd9Sstevel@tonic-gate end_speed_ctrl: 184*7c478bd9Sstevel@tonic-gate free(mpage); 185*7c478bd9Sstevel@tonic-gate return (ret); 186*7c478bd9Sstevel@tonic-gate } 187