root/drivers/scsi/sr_ioctl.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sr_ioctl_done
  2. do_ioctl
  3. sr_ioctl

   1 #include <linux/kernel.h>
   2 #include <linux/sched.h>
   3 #include <linux/fs.h>
   4 #include <asm/segment.h>
   5 #include <linux/errno.h>
   6 
   7 #include "../block/blk.h"
   8 #include "scsi.h"
   9 #include "hosts.h"
  10 #include "sr.h"
  11 #include "scsi_ioctl.h"
  12 
  13 #include <linux/cdrom.h>
  14 
  15 #define IOCTL_RETRIES 3
  16 /* The CDROM is fairly slow, so we need a little extra time */
  17 #define IOCTL_TIMEOUT 200
  18 
  19 extern int scsi_ioctl (Scsi_Device *dev, int cmd, void *arg);
  20 
  21 static void sr_ioctl_done(Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
  22 {
  23   struct request * req;
  24   struct task_struct * p;
  25   
  26   req = &SCpnt->request;
  27   req->dev = 0xfffe; /* Busy, but indicate request done */
  28   
  29   if ((p = req->waiting) != NULL) {
  30     req->waiting = NULL;
  31     p->state = TASK_RUNNING;
  32     if (p->counter > current->counter)
  33       need_resched = 1;
  34   }
  35 }
  36 
  37 /* We do our own retries because we want to know what the specific
  38    error code is.  Normally the UNIT_ATTENTION code will automatically
  39    clear after one error */
  40 
  41 static int do_ioctl(int target, unsigned char * sr_cmd, void * buffer, unsigned buflength)
     /* [previous][next][first][last][top][bottom][index][help] */
  42 {
  43         Scsi_Cmnd * SCpnt;
  44         int result;
  45 
  46         SCpnt = allocate_device(NULL, scsi_CDs[target].device->index, 1);
  47         scsi_do_cmd(SCpnt,
  48                     (void *) sr_cmd, buffer, buflength, sr_ioctl_done, 
  49                     IOCTL_TIMEOUT, IOCTL_RETRIES);
  50 
  51 
  52         if (SCpnt->request.dev != 0xfffe){
  53           SCpnt->request.waiting = current;
  54           current->state = TASK_UNINTERRUPTIBLE;
  55           while (SCpnt->request.dev != 0xfffe) schedule();
  56         };
  57 
  58         result = SCpnt->result;
  59 
  60 /* Minimal error checking.  Ignore cases we know about, and report the rest. */
  61         if(driver_byte(result) != 0)
  62           switch(SCpnt->sense_buffer[2] & 0xf) {
  63           case UNIT_ATTENTION:
  64             scsi_CDs[target].device->changed = 1;
  65             printk("Disc change detected.\n");
  66             break;
  67           case NOT_READY: /* This happens if there is no disc in drive */
  68             printk("CDROM not ready.  Make sure there is a disc in the drive.\n");
  69             break;
  70           case ILLEGAL_REQUEST:
  71             printk("CDROM (ioctl) reports ILLEGAL REQUEST.\n");
  72             break;
  73           default:
  74             printk("SCSI CD error: host %d id %d lun %d return code = %03x\n", 
  75                    scsi_CDs[target].device->host->host_no, 
  76                    scsi_CDs[target].device->id,
  77                    scsi_CDs[target].device->lun,
  78                    result);
  79             printk("\tSense class %x, sense error %x, extended sense %x\n",
  80                    sense_class(SCpnt->sense_buffer[0]), 
  81                    sense_error(SCpnt->sense_buffer[0]),
  82                    SCpnt->sense_buffer[2] & 0xf);
  83             
  84         };
  85 
  86         result = SCpnt->result;
  87         SCpnt->request.dev = -1; /* Deallocate */
  88         wake_up(&scsi_devices[SCpnt->index].device_wait);
  89         /* Wake up a process waiting for device*/
  90         return result;
  91 }
  92 
  93 int sr_ioctl(struct inode * inode, struct file * file, unsigned int cmd, unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
  94 {
  95         u_char  sr_cmd[10];
  96 
  97         int dev = inode->i_rdev;
  98         int result, target;
  99 
 100         target = MINOR(dev);
 101         if (target >= NR_SR) return -ENODEV;
 102 
 103         switch (cmd) 
 104                 {
 105                 /* Sun-compatible */
 106                 case CDROMPAUSE:
 107 
 108                         sr_cmd[0] = SCMD_PAUSE_RESUME;
 109                         sr_cmd[1] = scsi_CDs[target].device->lun << 5;
 110                         sr_cmd[2] = sr_cmd[3] = sr_cmd[4] = 0;
 111                         sr_cmd[5] = sr_cmd[6] = sr_cmd[7] = 0;
 112                         sr_cmd[8] = 0;
 113                         sr_cmd[9] = 0;
 114 
 115                         result = do_ioctl(target, sr_cmd, NULL, 255);
 116                         return result;
 117 
 118                 case CDROMRESUME:
 119 
 120                         sr_cmd[0] = SCMD_PAUSE_RESUME;
 121                         sr_cmd[1] = scsi_CDs[target].device->lun << 5;
 122                         sr_cmd[2] = sr_cmd[3] = sr_cmd[4] = 0;
 123                         sr_cmd[5] = sr_cmd[6] = sr_cmd[7] = 0;
 124                         sr_cmd[8] = 1;
 125                         sr_cmd[9] = 0;
 126 
 127                         result = do_ioctl(target, sr_cmd, NULL, 255);
 128 
 129                         return result;
 130 
 131                 case CDROMPLAYMSF:
 132                         {
 133                         struct cdrom_msf msf;
 134                         memcpy_fromfs(&msf, (void *) arg, sizeof(msf));
 135 
 136                         sr_cmd[0] = SCMD_PLAYAUDIO_MSF;
 137                         sr_cmd[1] = scsi_CDs[target].device->lun << 5;
 138                         sr_cmd[2] = 0;
 139                         sr_cmd[3] = msf.cdmsf_min0;
 140                         sr_cmd[4] = msf.cdmsf_sec0;
 141                         sr_cmd[5] = msf.cdmsf_frame0;
 142                         sr_cmd[6] = msf.cdmsf_min1;
 143                         sr_cmd[7] = msf.cdmsf_sec1;
 144                         sr_cmd[8] = msf.cdmsf_frame1;
 145                         sr_cmd[9] = 0;
 146 
 147                         result = do_ioctl(target, sr_cmd, NULL, 255);
 148                         return result;
 149                         }
 150 
 151                 case CDROMPLAYTRKIND:
 152                         {
 153                         struct cdrom_ti ti;
 154                         memcpy_fromfs(&ti, (void *) arg, sizeof(ti));
 155 
 156                         sr_cmd[0] = SCMD_PLAYAUDIO_TI;
 157                         sr_cmd[1] = scsi_CDs[target].device->lun << 5;
 158                         sr_cmd[2] = 0;
 159                         sr_cmd[3] = 0;
 160                         sr_cmd[4] = ti.cdti_trk0;
 161                         sr_cmd[5] = ti.cdti_ind0;
 162                         sr_cmd[6] = 0;
 163                         sr_cmd[7] = ti.cdti_trk1;
 164                         sr_cmd[8] = ti.cdti_ind1;
 165                         sr_cmd[9] = 0;
 166 
 167                         result = do_ioctl(target, sr_cmd, NULL, 255);
 168 
 169                         return result;
 170                         }
 171 
 172                 case CDROMREADTOCHDR:
 173                         {
 174                         struct cdrom_tochdr tochdr;
 175                         char * buffer;
 176 
 177                         sr_cmd[0] = SCMD_READ_TOC;
 178                         sr_cmd[1] = ((scsi_CDs[target].device->lun) << 5) | 0x02;    /* MSF format */
 179                         sr_cmd[2] = sr_cmd[3] = sr_cmd[4] = sr_cmd[5] = 0;
 180                         sr_cmd[6] = 0;
 181                         sr_cmd[7] = 0;              /* MSB of length (12) */
 182                         sr_cmd[8] = 12;             /* LSB of length */
 183                         sr_cmd[9] = 0;
 184 
 185                         buffer = (unsigned char *) scsi_malloc(512);
 186                         if(!buffer) return -ENOMEM;
 187 
 188                         result = do_ioctl(target, sr_cmd, buffer, 12);
 189 
 190                         tochdr.cdth_trk0 = buffer[2];
 191                         tochdr.cdth_trk1 = buffer[3];
 192 
 193                         scsi_free(buffer, 512);
 194 
 195                         verify_area (VERIFY_WRITE, (void *) arg, sizeof (struct cdrom_tochdr));
 196                         memcpy_tofs ((void *) arg, &tochdr, sizeof (struct cdrom_tochdr));
 197                         
 198                         return result;
 199                         }
 200 
 201                 case CDROMREADTOCENTRY:
 202                         {
 203                         struct cdrom_tocentry tocentry;
 204                         char * buffer;
 205 
 206                         verify_area (VERIFY_READ, (void *) arg, sizeof (struct cdrom_tocentry));
 207                         memcpy_fromfs (&tocentry, (void *) arg, sizeof (struct cdrom_tocentry));
 208 
 209                         sr_cmd[0] = SCMD_READ_TOC;
 210                         sr_cmd[1] = ((scsi_CDs[target].device->lun) << 5) | 0x02;    /* MSF format */
 211                         sr_cmd[2] = sr_cmd[3] = sr_cmd[4] = sr_cmd[5] = 0;
 212                         sr_cmd[6] = tocentry.cdte_track;
 213                         sr_cmd[7] = 0;             /* MSB of length (12)  */
 214                         sr_cmd[8] = 12;            /* LSB of length */
 215                         sr_cmd[9] = 0;
 216 
 217                         buffer = (unsigned char *) scsi_malloc(512);
 218                         if(!buffer) return -ENOMEM;
 219 
 220                         result = do_ioctl (target, sr_cmd, buffer, 12);
 221 
 222                         if (tocentry.cdte_format == CDROM_MSF) {
 223                           tocentry.cdte_addr.msf.minute = buffer[9];
 224                           tocentry.cdte_addr.msf.second = buffer[10];
 225                           tocentry.cdte_addr.msf.frame = buffer[11];
 226                           tocentry.cdte_ctrl = buffer[5] & 0xf;
 227                         }
 228                         else
 229                           tocentry.cdte_addr.lba = (int) buffer[0];
 230 
 231                         scsi_free(buffer, 512);
 232 
 233                         verify_area (VERIFY_WRITE, (void *) arg, sizeof (struct cdrom_tocentry));
 234                         memcpy_tofs ((void *) arg, &tocentry, sizeof (struct cdrom_tocentry));
 235 
 236                         return result;
 237                         }
 238 
 239                 case CDROMSTOP:
 240                         sr_cmd[0] = START_STOP;
 241                         sr_cmd[1] = ((scsi_CDs[target].device->lun) << 5) | 1;
 242                         sr_cmd[2] = sr_cmd[3] = sr_cmd[5] = 0;
 243                         sr_cmd[4] = 0;
 244 
 245                         result = do_ioctl(target, sr_cmd, NULL, 255);
 246                         return result;
 247                         
 248                 case CDROMSTART:
 249                         sr_cmd[0] = START_STOP;
 250                         sr_cmd[1] = ((scsi_CDs[target].device->lun) << 5) | 1;
 251                         sr_cmd[2] = sr_cmd[3] = sr_cmd[5] = 0;
 252                         sr_cmd[4] = 1;
 253 
 254                         result = do_ioctl(target, sr_cmd, NULL, 255);
 255                         return result;
 256 
 257                 case CDROMEJECT:
 258                         if (scsi_CDs[target].device -> access_count == 1)
 259                           sr_ioctl (inode, NULL, SCSI_IOCTL_DOORUNLOCK, 0);
 260 
 261                         sr_cmd[0] = START_STOP;
 262                         sr_cmd[1] = ((scsi_CDs[target].device -> lun) << 5) | 1;
 263                         sr_cmd[2] = sr_cmd[3] = sr_cmd[5] = 0;
 264                         sr_cmd[4] = 0x02;
 265 
 266                         if (!(result = do_ioctl(target, sr_cmd, NULL, 255)))
 267                           scsi_CDs[target].device -> changed = 1;
 268 
 269                         return result;
 270 
 271                 case CDROMVOLCTRL:
 272                         {
 273                           char * buffer, * mask;
 274                           struct cdrom_volctrl volctrl;
 275 
 276                           verify_area (VERIFY_READ, (void *) arg, sizeof (struct cdrom_volctrl));
 277                           memcpy_fromfs (&volctrl, (void *) arg, sizeof (struct cdrom_volctrl));
 278 
 279                           /* First we get the current params so we can just twiddle the volume */
 280 
 281                           sr_cmd[0] = MODE_SENSE;
 282                           sr_cmd[1] = (scsi_CDs[target].device -> lun) << 5;
 283                           sr_cmd[2] = 0xe;    /* Want mode page 0xe, CDROM audio params */
 284                           sr_cmd[3] = 0;
 285                           sr_cmd[4] = 28;
 286                           sr_cmd[5] = 0;
 287 
 288                           buffer = (unsigned char *) scsi_malloc(512);
 289                           if(!buffer) return -ENOMEM;
 290 
 291                           if ((result = do_ioctl (target, sr_cmd, buffer, 28))) {
 292                             printk ("Hosed while obtaining audio mode page\n");
 293                             scsi_free(buffer, 512);
 294                             return result;
 295                           }
 296 
 297                           sr_cmd[0] = MODE_SENSE;
 298                           sr_cmd[1] = (scsi_CDs[target].device -> lun) << 5;
 299                           sr_cmd[2] = 0x4e;   /* Want the mask for mode page 0xe */
 300                           sr_cmd[3] = 0;
 301                           sr_cmd[4] = 28;
 302                           sr_cmd[5] = 0;
 303 
 304                           mask = (unsigned char *) scsi_malloc(512);
 305                           if(!mask) {
 306                             scsi_free(buffer, 512);
 307                             return -ENOMEM;
 308                           };
 309 
 310                           if ((result = do_ioctl (target, sr_cmd, mask, 28))) {
 311                             printk ("Hosed while obtaining mask for audio mode page\n");
 312                             scsi_free(buffer, 512);
 313                             scsi_free(mask, 512);
 314                             return result;
 315                           }
 316 
 317                           /* Now mask and substitute our own volume and reuse the rest */
 318                           buffer[0] = 0;  /* Clear reserved field */
 319 
 320                           buffer[21] = volctrl.channel0 & mask[21];
 321                           buffer[23] = volctrl.channel1 & mask[23];
 322                           buffer[25] = volctrl.channel2 & mask[25];
 323                           buffer[27] = volctrl.channel3 & mask[27];
 324 
 325                           sr_cmd[0] = MODE_SELECT;
 326                           sr_cmd[1] = ((scsi_CDs[target].device -> lun) << 5) | 0x10;    /* Params are SCSI-2 */
 327                           sr_cmd[2] = sr_cmd[3] = 0;
 328                           sr_cmd[4] = 28;
 329                           sr_cmd[5] = 0;
 330 
 331                           result = do_ioctl (target, sr_cmd, buffer, 28);
 332                           scsi_free(buffer, 512);
 333                           scsi_free(mask, 512);
 334                           return result;
 335                         }
 336 
 337                 case CDROMSUBCHNL:
 338                         {
 339                           struct cdrom_subchnl subchnl;
 340                           char * buffer;
 341                           
 342                           sr_cmd[0] = SCMD_READ_SUBCHANNEL;
 343                           sr_cmd[1] = ((scsi_CDs[target].device->lun) << 5) | 0x02;    /* MSF format */
 344                           sr_cmd[2] = 0x40;    /* I do want the subchannel info */
 345                           sr_cmd[3] = 0x01;    /* Give me current position info */
 346                           sr_cmd[4] = sr_cmd[5] = 0;
 347                           sr_cmd[6] = 0;
 348                           sr_cmd[7] = 0;
 349                           sr_cmd[8] = 16;
 350                           sr_cmd[9] = 0;
 351 
 352                           buffer = (unsigned char*) scsi_malloc(512);
 353                           if(!buffer) return -ENOMEM;
 354 
 355                           result = do_ioctl(target, sr_cmd, buffer, 16);
 356 
 357                           subchnl.cdsc_audiostatus = buffer[1];
 358                           subchnl.cdsc_format = CDROM_MSF;
 359                           subchnl.cdsc_ctrl = buffer[5] & 0xf;
 360                           subchnl.cdsc_trk = buffer[6];
 361                           subchnl.cdsc_ind = buffer[7];
 362 
 363                           subchnl.cdsc_reladdr.msf.minute = buffer[13];
 364                           subchnl.cdsc_reladdr.msf.second = buffer[14];
 365                           subchnl.cdsc_reladdr.msf.frame = buffer[15];
 366                           subchnl.cdsc_absaddr.msf.minute = buffer[9];
 367                           subchnl.cdsc_absaddr.msf.second = buffer[10];
 368                           subchnl.cdsc_absaddr.msf.frame = buffer[11];
 369 
 370                           scsi_free(buffer, 512);
 371 
 372                           verify_area (VERIFY_WRITE, (void *) arg, sizeof (struct cdrom_subchnl));
 373                           memcpy_tofs ((void *) arg, &subchnl, sizeof (struct cdrom_subchnl));
 374                           return result;
 375                         }
 376 
 377                 case CDROMREADMODE2:
 378                         return -EINVAL;
 379                 case CDROMREADMODE1:
 380                         return -EINVAL;
 381 
 382                 RO_IOCTLS(dev,arg);
 383                 default:
 384                         return scsi_ioctl(scsi_CDs[target].device,cmd,(void *) arg);
 385                 }
 386 }

/* [previous][next][first][last][top][bottom][index][help] */