70static void usb_stor_scsiSenseParseBuffer(SCSI_CMD_T *srb,
71 Usb_Stor_Scsi_Sense_Hdr_u *the6,
72 Usb_Stor_Scsi_Sense_Hdr_10_u *the10,
int *length_p)
74 int i = 0, j = 0, element = 0;
77 SCATTER_LIST_T *sg = 0;
87 sg = (SCATTER_LIST_T *)srb->request_buff;
88 for (i = 0; i < srb->use_sg; i++)
90 length += sg[i].length;
92 if (element < USB_STOR_SCSI_SENSE_10_HDRSZ)
95 for (j = 0; j < sg[i].length; j++)
97 if (element < USB_STOR_SCSI_SENSE_HDRSZ)
100 the6->array[element] = (uint8_t *)&(sg[i].address[j]);
101 the10->array[element] = (uint8_t *)&(sg[i].address[j]);
103 else if (element < USB_STOR_SCSI_SENSE_10_HDRSZ)
106 the10->array[element] = (uint8_t *)&(sg[i].address[j]);
116 length = srb->request_bufflen;
117 buffer = srb->request_buff;
118 if (length < USB_STOR_SCSI_SENSE_10_HDRSZ)
119 UMAS_DEBUG(
"Buffer length smaller than header!!\n");
120 for (i = 0; i < USB_STOR_SCSI_SENSE_10_HDRSZ; i++)
122 if (i < USB_STOR_SCSI_SENSE_HDRSZ)
124 the6->array[i] = &(buffer[i]);
125 the10->array[i] = &(buffer[i]);
128 the10->array[i] = &(buffer[i]);
137static int usb_stor_scsiSense10to6(SCSI_CMD_T *the10)
140 int outputBufferSize = 0;
142 int i=0, j=0, element=0;
143 int sb=0,si=0,db=0,di=0;
145 SCATTER_LIST_T *sg = 0;
146 Usb_Stor_Scsi_Sense_Hdr_u the6Locations;
147 Usb_Stor_Scsi_Sense_Hdr_10_u the10Locations;
150 UMAS_VDEBUG(
"usb_stor_scsiSense10to6 - converting 10 byte sense data to 6 byte\n");
151 the10->cmnd[0] = the10->cmnd[0] & 0xBF;
154 usb_stor_scsiSenseParseBuffer(the10, &the6Locations, &the10Locations, &length);
157 outputBufferSize = *the10Locations.hdr.dataLengthLSB;
158 outputBufferSize += USB_STOR_SCSI_SENSE_HDRSZ;
161 if (outputBufferSize > length)
163 UMAS_DEBUG(
"usb_stor_scsiSense10to6 - Had to truncate MODE_SENSE_10 buffer into MODE_SENSE.\n");
164 UMAS_DEBUG(
"outputBufferSize is %d and length is %d.\n", outputBufferSize, length);
166 outputBufferSize = length;
169 if (*the10Locations.hdr.dataLengthMSB != 0)
171 UMAS_DEBUG(
"usb_stor_scsiSense10to6 - Command will be truncated to fit in SENSE6 buffer.\n");
172 *the6Locations.hdr.dataLength = 0xff;
176 *the6Locations.hdr.dataLength = *the10Locations.hdr.dataLengthLSB;
180 *the6Locations.hdr.mediumType = *the10Locations.hdr.mediumType;
181 *the6Locations.hdr.devSpecParms = *the10Locations.hdr.devSpecParms;
184 if (*the10Locations.hdr.blkDescLengthMSB != 0)
186 UMAS_DEBUG(
"usb_stor_scsiSense10to6 - Command will be truncated to fit in SENSE6 buffer.\n");
187 *the6Locations.hdr.blkDescLength = 0xff;
191 *the6Locations.hdr.blkDescLength = *the10Locations.hdr.blkDescLengthLSB;
194 if (the10->use_sg == 0)
196 buffer = the10->request_buff;
198 memcpy(&(buffer[USB_STOR_SCSI_SENSE_HDRSZ]),
199 &(buffer[USB_STOR_SCSI_SENSE_10_HDRSZ]),
200 outputBufferSize - USB_STOR_SCSI_SENSE_HDRSZ );
202 memset(&(buffer[outputBufferSize
203 -(USB_STOR_SCSI_SENSE_10_HDRSZ-USB_STOR_SCSI_SENSE_HDRSZ)]),
205 USB_STOR_SCSI_SENSE_10_HDRSZ-USB_STOR_SCSI_SENSE_HDRSZ);
209 sg = (SCATTER_LIST_T *) the10->request_buff;
211 for (i = 0; i < the10->use_sg; i++)
213 sgLength = sg[i].length;
214 for (j = 0; j < sgLength; j++ )
217 if (element == USB_STOR_SCSI_SENSE_HDRSZ)
222 if (element == USB_STOR_SCSI_SENSE_10_HDRSZ)
235 element = USB_STOR_SCSI_SENSE_HDRSZ;
236 while (element < outputBufferSize
237 -(USB_STOR_SCSI_SENSE_10_HDRSZ-USB_STOR_SCSI_SENSE_HDRSZ))
240 if ((sb >= the10->use_sg) || (si >= sg[sb].length) ||
241 (db >= the10->use_sg) || (di >= sg[db].length))
243 UMAS_DEBUG(
"usb_stor_scsiSense10to6 - Buffer overrun averted, this shouldn't happen!\n");
248 sg[db].address[di] = sg[sb].address[si];
251 if (sg[db].length - 1 == di)
262 if (sg[sb].length - 1 == si)
274 while (element < outputBufferSize)
277 if ((db >= the10->use_sg) || (di >= sg[db].length))
279 UMAS_DEBUG(
"usb_stor_scsiSense10to6 - Buffer overrun averted, this shouldn't happen!\n");
282 sg[db].address[di] = 0;
285 if (sg[db].length-1 == di)
301static int usb_stor_scsiSense6to10(SCSI_CMD_T* the6)
304 uint8_t tempBuffer[USB_STOR_SCSI_SENSE_10_HDRSZ-USB_STOR_SCSI_SENSE_HDRSZ], *buffer=0;
305 int outputBufferSize = 0;
307 int i = 0, j = 0, element = 0;
308 int sb = 0, si = 0, db = 0, di = 0;
309 int lsb = 0, lsi = 0, ldb = 0, ldi = 0;
310 SCATTER_LIST_T *sg = 0;
311 Usb_Stor_Scsi_Sense_Hdr_u the6Locations;
312 Usb_Stor_Scsi_Sense_Hdr_10_u the10Locations;
314 UMAS_VDEBUG(
"-- converting 6 byte sense data to 10 byte\n");
315 the6->cmnd[0] = the6->cmnd[0] | 0x40;
318 usb_stor_scsiSenseParseBuffer(the6, &the6Locations, &the10Locations, &length);
321 outputBufferSize = *the6Locations.hdr.dataLength;
322 outputBufferSize += USB_STOR_SCSI_SENSE_10_HDRSZ;
325 if (outputBufferSize > length)
327 UMAS_DEBUG(
"Had to truncate MODE_SENSE into MODE_SENSE_10 buffer.\n");
328 UMAS_DEBUG(
"outputBufferSize is %d and length is %d.\n", outputBufferSize, length);
330 outputBufferSize = length;
333 tempBuffer[2] = *the10Locations.hdr.blkDescLengthMSB;
334 tempBuffer[3] = *the10Locations.hdr.blkDescLengthLSB;
335 *the10Locations.hdr.blkDescLengthLSB = *the6Locations.hdr.blkDescLength;
336 *the10Locations.hdr.blkDescLengthMSB = 0;
339 tempBuffer[0] = *the10Locations.hdr.reserved1;
340 tempBuffer[1] = *the10Locations.hdr.reserved2;
341 *the10Locations.hdr.reserved1 = *the10Locations.hdr.reserved2 = 0;
344 *the10Locations.hdr.devSpecParms = *the6Locations.hdr.devSpecParms;
345 *the10Locations.hdr.mediumType = *the6Locations.hdr.mediumType;
348 *the10Locations.hdr.dataLengthLSB = *the6Locations.hdr.dataLength;
349 *the10Locations.hdr.dataLengthMSB = 0;
353 buffer = the6->request_buff;
355 memcpy(&(buffer[USB_STOR_SCSI_SENSE_10_HDRSZ]),
356 &(buffer[USB_STOR_SCSI_SENSE_HDRSZ]),
357 outputBufferSize-USB_STOR_SCSI_SENSE_10_HDRSZ);
359 memcpy(&(buffer[USB_STOR_SCSI_SENSE_10_HDRSZ]), tempBuffer,
360 USB_STOR_SCSI_SENSE_10_HDRSZ-USB_STOR_SCSI_SENSE_HDRSZ);
364 sg = (SCATTER_LIST_T *) the6->request_buff;
366 for (i = 0; i < the6->use_sg; i++)
368 for (j = 0; j < sg[i].length; j++)
371 if (element == USB_STOR_SCSI_SENSE_HDRSZ )
376 if (element == USB_STOR_SCSI_SENSE_10_HDRSZ)
390 element = length - 1;
394 di=sg[db].length - 1;
396 for (i = the6->use_sg - 1; i >= 0; i--)
398 for (j = sg[i].length - 1; j >= 0; j--)
401 if (element == length - 1
402 - (USB_STOR_SCSI_SENSE_10_HDRSZ-USB_STOR_SCSI_SENSE_HDRSZ))
416 - (USB_STOR_SCSI_SENSE_10_HDRSZ-USB_STOR_SCSI_SENSE_HDRSZ);
417 while (element >= USB_STOR_SCSI_SENSE_10_HDRSZ)
420 if (((sb <= lsb) && (si < lsi)) || ((db <= ldb) && (di < ldi)))
422 UMAS_DEBUG(
"Buffer overrun averted, this shouldn't happen!\n");
427 sg[db].address[di] = sg[sb].address[si];
433 di = sg[db].length - 1;
444 si = sg[sb].length - 1;
454 while ( element >= USB_STOR_SCSI_SENSE_HDRSZ )
457 if ((db <= ldb) && (di < ldi))
459 UMAS_DEBUG(
"Buffer overrun averted, this shouldn't happen!\n");
463 sg[db].address[di] = tempBuffer[element - USB_STOR_SCSI_SENSE_HDRSZ];
469 di = sg[db].length - 1;
488static void fix_inquiry_data(SCSI_CMD_T *srb)
493 if (srb->cmnd[0] != INQUIRY)
496 UMAS_DEBUG(
"Fixing INQUIRY data to show SCSI rev 2\n");
503 sg = (SCATTER_LIST_T *) srb->request_buff;
504 data_ptr = (uint8_t *) sg[0].address;
507 data_ptr = (uint8_t *)srb->request_buff;
518void UMAS_Qic157Command(SCSI_CMD_T *srb, UMAS_DATA_T *umas)
525 for (; srb->cmd_len<12; srb->cmd_len++)
526 srb->cmnd[srb->cmd_len] = 0;
532 UMAS_InvokeTransport(srb, umas);
535 fix_inquiry_data(srb);
541void UMAS_AtapiCommand(SCSI_CMD_T *srb, UMAS_DATA_T *umas)
554 for (; srb->cmd_len<12; srb->cmd_len++)
555 srb->cmnd[srb->cmd_len] = 0;
561 switch (srb->cmnd[0])
567 old_cmnd = srb->cmnd[0];
572 srb->cmnd[8] = srb->cmnd[4];
578 srb->cmnd[2] = srb->cmnd[2];
579 srb->cmnd[1] = srb->cmnd[1];
580 srb->cmnd[0] = srb->cmnd[0] | 0x40;
589 srb->cmnd[8] = srb->cmnd[4];
592 srb->cmnd[5] = srb->cmnd[3];
593 srb->cmnd[4] = srb->cmnd[2];
594 srb->cmnd[3] = srb->cmnd[1] & 0x1F;
596 srb->cmnd[1] = srb->cmnd[1] & 0xE0;
597 srb->cmnd[0] = srb->cmnd[0] | 0x20;
602 if (old_cmnd == MODE_SELECT)
603 usb_stor_scsiSense6to10(srb);
606 UMAS_InvokeTransport(srb, umas);
609 if ((old_cmnd == MODE_SENSE) && (status_byte(srb->result) == GOOD))
610 usb_stor_scsiSense10to6(srb);
613 fix_inquiry_data(srb);
619void UMAS_UfiCommand(SCSI_CMD_T *srb, UMAS_DATA_T *umas)
635 switch (srb->cmnd[0])
646 old_cmnd = srb->cmnd[0];
656 if (srb->cmnd[0] == MODE_SELECT)
657 srb->cmnd[8] = srb->cmnd[4];
666 srb->cmnd[2] = srb->cmnd[2];
667 srb->cmnd[1] = srb->cmnd[1];
668 srb->cmnd[0] = srb->cmnd[0] | 0x40;
688 srb->cmnd[8] = srb->cmnd[4];
691 srb->cmnd[5] = srb->cmnd[3];
692 srb->cmnd[4] = srb->cmnd[2];
693 srb->cmnd[3] = srb->cmnd[1] & 0x1F;
695 srb->cmnd[1] = srb->cmnd[1] & 0xE0;
696 srb->cmnd[0] = srb->cmnd[0] | 0x20;
701 if (old_cmnd == MODE_SELECT)
702 usb_stor_scsiSense6to10(srb);
705 UMAS_InvokeTransport(srb, umas);
708 if ((old_cmnd == MODE_SENSE) && (status_byte(srb->result) == GOOD))
709 usb_stor_scsiSense10to6(srb);
712 fix_inquiry_data(srb);
715void UMAS_TransparentScsiCommand(SCSI_CMD_T *srb, UMAS_DATA_T *umas)
722 if (umas->flags & UMAS_FL_MODE_XLATE)
725 if (srb->cmnd[0] == READ_6)
728 srb->cmnd[9] = umas->srb.cmnd[5];
731 srb->cmnd[8] = umas->srb.cmnd[6];
738 srb->cmnd[5] = umas->srb.cmnd[3];
739 srb->cmnd[4] = umas->srb.cmnd[2];
748 UMAS_DEBUG(
"Changing READ_6 to READ_10\n");
749 UMAS_DEBUG_ShowCommand(srb);
753 if (srb->cmnd[0] == WRITE_6)
756 srb->cmnd[9] = umas->srb.cmnd[5];
759 srb->cmnd[8] = umas->srb.cmnd[4];
766 srb->cmnd[5] = umas->srb.cmnd[3];
767 srb->cmnd[4] = umas->srb.cmnd[2];
776 UMAS_DEBUG(
"Changing WRITE_6 to WRITE_10\n");
777 UMAS_DEBUG_ShowCommand(&umas->srb);
782 UMAS_InvokeTransport(srb, umas);
785 fix_inquiry_data(srb);
NUC472/NUC442 peripheral access layer header file. This file contains all the peripheral register's d...
USB Host core driver header file.