b234549ed843b5801d76d238713fef9a72ed23e0
[SCSI2SD.git] / software / SCSI2SD / src / mode.c
1 //      Copyright (C) 2013 Michael McMaster <michael@codesrc.com>\r
2 //  Copyright (C) 2014 Doug Brown <doug@downtowndougbrown.com>\r
3 //\r
4 //      This file is part of SCSI2SD.\r
5 //\r
6 //      SCSI2SD is free software: you can redistribute it and/or modify\r
7 //      it under the terms of the GNU General Public License as published by\r
8 //      the Free Software Foundation, either version 3 of the License, or\r
9 //      (at your option) any later version.\r
10 //\r
11 //      SCSI2SD is distributed in the hope that it will be useful,\r
12 //      but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 //      GNU General Public License for more details.\r
15 //\r
16 //      You should have received a copy of the GNU General Public License\r
17 //      along with SCSI2SD.  If not, see <http://www.gnu.org/licenses/>.\r
18 #pragma GCC push_options\r
19 #pragma GCC optimize("-flto")\r
20 \r
21 #include "device.h"\r
22 #include "scsi.h"\r
23 #include "mode.h"\r
24 #include "disk.h"\r
25 \r
26 #include <string.h>\r
27 \r
28 static const uint8 ReadWriteErrorRecoveryPage[] =\r
29 {\r
30 0x01, // Page code\r
31 0x0A, // Page length\r
32 \r
33 // VMS 5.5-2 is very particular regarding the mode page values.\r
34 // The required values for a SCSI2/NoTCQ device are:\r
35 // AWRE=0 ARRE=0 TB=1 RC=0 EER=? PER=1 DTE=1 DCR=?\r
36 // See ftp://www.digiater.nl/openvms/decus/vms94b/net94b/scsi_params_dkdriver.txt\r
37 // X-Newsgroups: comp.os.vms\r
38 // Subject: Re: VMS 6.1 vs. Seagate Disk Drives\r
39 // Message-Id: <32g87h$8q@nntpd.lkg.dec.com>\r
40 // From: weber@evms.enet.dec.com (Ralph O. Weber -- OpenVMS AXP)\r
41 // Date: 12 Aug 1994 16:32:49 GMT\r
42 0x26,\r
43 \r
44 0x00, // Don't try recovery algorithm during reads\r
45 0x00, // Correction span 0\r
46 0x00, // Head offset count 0,\r
47 0x00, // Data strobe offset count 0,\r
48 0x00, // Reserved\r
49 0x00, // Don't try recovery algorithm during writes\r
50 0x00, // Reserved\r
51 0x00, 0x00 // Recovery time limit 0 (use default)*/\r
52 };\r
53 \r
54 static const uint8 ReadWriteErrorRecoveryPage_SCSI1[] =\r
55 {\r
56 0x01, // Page code\r
57 0x06, // Page length\r
58 0x26,\r
59 0x00, // Don't try recovery algorithm during reads\r
60 0x00, // Correction span 0\r
61 0x00, // Head offset count 0,\r
62 0x00, // Data strobe offset count 0,\r
63 0xFF // Reserved\r
64 };\r
65 \r
66 static const uint8 DisconnectReconnectPage[] =\r
67 {\r
68 0x02, // Page code\r
69 0x0E, // Page length\r
70 0, // Buffer full ratio\r
71 0, // Buffer empty ratio\r
72 0x00, 10, // Bus inactivity limit, 100us increments. Allow 1ms.\r
73 0x00, 0x00, // Disconnect time limit\r
74 0x00, 0x00, // Connect time limit\r
75 0x00, 0x00, // Maximum burst size\r
76 0x00 ,// DTDC. Not used.\r
77 0x00, 0x00, 0x00 // Reserved\r
78 };\r
79 \r
80 static const uint8 DisconnectReconnectPage_SCSI1[] =\r
81 {\r
82 0x02, // Page code\r
83 0x0A, // Page length\r
84 0, // Buffer full ratio\r
85 0, // Buffer empty ratio\r
86 0x00, 10, // Bus inactivity limit, 100us increments. Allow 1ms.\r
87 0x00, 0x00, // Disconnect time limit\r
88 0x00, 0x00, // Connect time limit\r
89 0x00, 0x00 // Maximum burst size\r
90 };\r
91 \r
92 static const uint8 FormatDevicePage[] =\r
93 {\r
94 0x03 | 0x80, // Page code | PS (persist) bit.\r
95 0x16, // Page length\r
96 0x00, 0x00, // Single zone\r
97 0x00, 0x00, // No alternate sectors\r
98 0x00, 0x00, // No alternate tracks\r
99 0x00, 0x00, // No alternate tracks per lun\r
100 0x00, SCSI_SECTORS_PER_TRACK, // Sectors per track\r
101 0xFF, 0xFF, // Data bytes per physical sector. Configurable.\r
102 0x00, 0x01, // Interleave\r
103 0x00, 0x00, // Track skew factor\r
104 0x00, 0x00, // Cylinder skew factor\r
105 0xC0, // SSEC(set) HSEC(set) RMB SURF\r
106 0x00, 0x00, 0x00 // Reserved\r
107 };\r
108 \r
109 static const uint8 RigidDiskDriveGeometry[] =\r
110 {\r
111 0x04, // Page code\r
112 0x16, // Page length\r
113 0xFF, 0xFF, 0xFF, // Number of cylinders\r
114 SCSI_HEADS_PER_CYLINDER, // Number of heads\r
115 0xFF, 0xFF, 0xFF, // Starting cylinder-write precompensation\r
116 0xFF, 0xFF, 0xFF, // Starting cylinder-reduced write current\r
117 0x00, 0x1, // Drive step rate (units of 100ns)\r
118 0x00, 0x00, 0x00, // Landing zone cylinder\r
119 0x00, // RPL\r
120 0x00, // Rotational offset\r
121 0x00, // Reserved\r
122 5400 >> 8, 5400 & 0xFF, // Medium rotation rate (RPM)\r
123 0x00, 0x00 // Reserved\r
124 };\r
125 \r
126 static const uint8 RigidDiskDriveGeometry_SCSI1[] =\r
127 {\r
128 0x04, // Page code\r
129 0x12, // Page length\r
130 0xFF, 0xFF, 0xFF, // Number of cylinders\r
131 SCSI_HEADS_PER_CYLINDER, // Number of heads\r
132 0xFF, 0xFF, 0xFF, // Starting cylinder-write precompensation\r
133 0xFF, 0xFF, 0xFF, // Starting cylinder-reduced write current\r
134 0x00, 0x1, // Drive step rate (units of 100ns)\r
135 0x00, 0x00, 0x00, // Landing zone cylinder\r
136 0x00, // RPL\r
137 0x00, // Rotational offset\r
138 0x00 // Reserved\r
139 };\r
140 \r
141 static const uint8 CachingPage[] =\r
142 {\r
143 0x08, // Page Code\r
144 0x0A, // Page length\r
145 0x01, // Read cache disable\r
146 0x00, // No useful rention policy.\r
147 0x00, 0x00, // Pre-fetch always disabled\r
148 0x00, 0x00, // Minimum pre-fetch\r
149 0x00, 0x00, // Maximum pre-fetch\r
150 0x00, 0x00, // Maximum pre-fetch ceiling\r
151 };\r
152 \r
153 static const uint8 ControlModePage[] =\r
154 {\r
155 0x0A, // Page code\r
156 0x06, // Page length\r
157 0x00, // No logging\r
158 0x01, // Disable tagged queuing\r
159 0x00, // No async event notifications\r
160 0x00, // Reserved\r
161 0x00, 0x00 // AEN holdoff period.\r
162 };\r
163 \r
164 // Allow Apple 68k Drive Setup to format this drive.\r
165 // Code\r
166 static const uint8 AppleVendorPage[] =\r
167 {\r
168 0x30, // Page code\r
169 28, // Page length\r
170 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
171 'A','P','P','L','E',' ','C','O','M','P','U','T','E','R',',',' ','I','N','C','.'\r
172 };\r
173 \r
174 static void pageIn(int pc, int dataIdx, const uint8* pageData, int pageLen)\r
175 {\r
176         memcpy(&scsiDev.data[dataIdx], pageData, pageLen);\r
177 \r
178         if (pc == 0x01) // Mask out (un)changable values\r
179         {\r
180                 memset(&scsiDev.data[dataIdx+2], 0, pageLen - 2);\r
181         }\r
182 }\r
183 \r
184 static void doModeSense(\r
185         int sixByteCmd, int dbd, int pc, int pageCode, int allocLength)\r
186 {\r
187         ////////////// Mode Parameter Header\r
188         ////////////////////////////////////\r
189 \r
190         // Skip the Mode Data Length, we set that last.\r
191         int idx = 1;\r
192         if (!sixByteCmd) ++idx;\r
193 \r
194         uint8_t mediumType = 0;\r
195         uint8_t deviceSpecificParam = 0;\r
196         uint8_t density = 0;\r
197         switch (scsiDev.target->cfg->deviceType == CONFIG_OPTICAL)\r
198         {\r
199         case CONFIG_FIXED:\r
200         case CONFIG_REMOVEABLE:\r
201                 mediumType = 0; // We should support various floppy types here!\r
202                 // Contains cache bits (0) and a Write-Protect bit.\r
203                 deviceSpecificParam =\r
204                         (blockDev.state & DISK_WP) ? 0x80 : 0;\r
205                 density = 0; // reserved for direct access\r
206                 break;\r
207 \r
208         case CONFIG_FLOPPY_14MB:\r
209                 mediumType = 0x1E; // 90mm/3.5"\r
210                 deviceSpecificParam =\r
211                         (blockDev.state & DISK_WP) ? 0x80 : 0;\r
212                 density = 0; // reserved for direct access\r
213                 break;\r
214 \r
215         case CONFIG_OPTICAL:\r
216                 mediumType = 0x02; // 120mm CDROM, data only.\r
217                 deviceSpecificParam = 0;\r
218                 density = 0x01; // User data only, 2048bytes per sector.\r
219                 break;\r
220 \r
221         };\r
222 \r
223         scsiDev.data[idx++] = mediumType;\r
224         scsiDev.data[idx++] = deviceSpecificParam;\r
225 \r
226         if (sixByteCmd)\r
227         {\r
228                 if (dbd)\r
229                 {\r
230                         scsiDev.data[idx++] = 0; // No block descriptor\r
231                 }\r
232                 else\r
233                 {\r
234                         // One block descriptor of length 8 bytes.\r
235                         scsiDev.data[idx++] = 8;\r
236                 }\r
237         }\r
238         else\r
239         {\r
240                 scsiDev.data[idx++] = 0; // Reserved\r
241                 scsiDev.data[idx++] = 0; // Reserved\r
242                 if (dbd)\r
243                 {\r
244                         scsiDev.data[idx++] = 0; // No block descriptor\r
245                         scsiDev.data[idx++] = 0; // No block descriptor\r
246                 }\r
247                 else\r
248                 {\r
249                         // One block descriptor of length 8 bytes.\r
250                         scsiDev.data[idx++] = 0;\r
251                         scsiDev.data[idx++] = 8;\r
252                 }\r
253         }\r
254 \r
255         ////////////// Block Descriptor\r
256         ////////////////////////////////////\r
257         if (!dbd)\r
258         {\r
259                 scsiDev.data[idx++] = density;\r
260                 // Number of blocks\r
261                 // Zero == all remaining blocks shall have the medium\r
262                 // characteristics specified.\r
263                 scsiDev.data[idx++] = 0;\r
264                 scsiDev.data[idx++] = 0;\r
265                 scsiDev.data[idx++] = 0;\r
266 \r
267                 scsiDev.data[idx++] = 0; // reserved\r
268 \r
269                 // Block length\r
270                 uint32_t bytesPerSector = scsiDev.target->liveCfg.bytesPerSector;\r
271                 scsiDev.data[idx++] = bytesPerSector >> 16;\r
272                 scsiDev.data[idx++] = bytesPerSector >> 8;\r
273                 scsiDev.data[idx++] = bytesPerSector & 0xFF;\r
274         }\r
275 \r
276         int pageFound = 0;\r
277 \r
278         if (pageCode == 0x01 || pageCode == 0x3F)\r
279         {\r
280                 pageFound = 1;\r
281                 if ((scsiDev.compatMode >= COMPAT_SCSI2))\r
282                 {\r
283                         pageIn(pc, idx, ReadWriteErrorRecoveryPage, sizeof(ReadWriteErrorRecoveryPage));\r
284                         idx += sizeof(ReadWriteErrorRecoveryPage);\r
285                 }\r
286                 else\r
287                 {\r
288                         pageIn(pc, idx, ReadWriteErrorRecoveryPage_SCSI1, sizeof(ReadWriteErrorRecoveryPage_SCSI1));\r
289                         idx += sizeof(ReadWriteErrorRecoveryPage_SCSI1);\r
290                 }\r
291         }\r
292 \r
293         if (pageCode == 0x02 || pageCode == 0x3F)\r
294         {\r
295                 pageFound = 1;\r
296                 if ((scsiDev.compatMode >= COMPAT_SCSI2))\r
297                 {\r
298                         pageIn(pc, idx, DisconnectReconnectPage, sizeof(DisconnectReconnectPage));\r
299                         idx += sizeof(DisconnectReconnectPage);\r
300                 }\r
301                 else\r
302                 {\r
303                         pageIn(pc, idx, DisconnectReconnectPage_SCSI1, sizeof(DisconnectReconnectPage_SCSI1));\r
304                         idx += sizeof(DisconnectReconnectPage_SCSI1);\r
305                 }\r
306         }\r
307 \r
308         if (pageCode == 0x03 || pageCode == 0x3F)\r
309         {\r
310                 pageFound = 1;\r
311                 pageIn(pc, idx, FormatDevicePage, sizeof(FormatDevicePage));\r
312                 if (pc != 0x01)\r
313                 {\r
314                         // Fill out the configured bytes-per-sector\r
315                         uint32_t bytesPerSector = scsiDev.target->liveCfg.bytesPerSector;\r
316                         scsiDev.data[idx+12] = bytesPerSector >> 8;\r
317                         scsiDev.data[idx+13] = bytesPerSector & 0xFF;\r
318                 }\r
319                 else\r
320                 {\r
321                         // Set a mask for the changeable values.\r
322                         scsiDev.data[idx+12] = 0xFF;\r
323                         scsiDev.data[idx+13] = 0xFF;\r
324                 }\r
325 \r
326                 idx += sizeof(FormatDevicePage);\r
327         }\r
328 \r
329         if (pageCode == 0x04 || pageCode == 0x3F)\r
330         {\r
331                 pageFound = 1;\r
332                 if ((scsiDev.compatMode >= COMPAT_SCSI2))\r
333                 {\r
334                         pageIn(pc, idx, RigidDiskDriveGeometry, sizeof(RigidDiskDriveGeometry));\r
335                 }\r
336                 else\r
337                 {\r
338                         pageIn(pc, idx, RigidDiskDriveGeometry_SCSI1, sizeof(RigidDiskDriveGeometry_SCSI1));\r
339                 }\r
340 \r
341                 if (pc != 0x01)\r
342                 {\r
343                         // Need to fill out the number of cylinders.\r
344                         uint32 cyl;\r
345                         uint8 head;\r
346                         uint32 sector;\r
347                         LBA2CHS(\r
348                                 getScsiCapacity(\r
349                                         scsiDev.target->cfg->sdSectorStart,\r
350                                         scsiDev.target->liveCfg.bytesPerSector,\r
351                                         scsiDev.target->cfg->scsiSectors),\r
352                                 &cyl,\r
353                                 &head,\r
354                                 &sector);\r
355 \r
356                         scsiDev.data[idx+2] = cyl >> 16;\r
357                         scsiDev.data[idx+3] = cyl >> 8;\r
358                         scsiDev.data[idx+4] = cyl;\r
359 \r
360                         memcpy(&scsiDev.data[idx+6], &scsiDev.data[idx+2], 3);\r
361                         memcpy(&scsiDev.data[idx+9], &scsiDev.data[idx+2], 3);\r
362                 }\r
363 \r
364                 if ((scsiDev.compatMode >= COMPAT_SCSI2))\r
365                 {\r
366                         idx += sizeof(RigidDiskDriveGeometry);\r
367                 }\r
368                 else\r
369                 {\r
370                         idx += sizeof(RigidDiskDriveGeometry_SCSI1);\r
371                 }\r
372         }\r
373 \r
374         // DON'T output the following pages for SCSI1 hosts. They get upset when\r
375         // we have more data to send than the allocation length provided.\r
376         // (ie. Try not to output any more pages below this comment)\r
377 \r
378 \r
379         if ((scsiDev.compatMode >= COMPAT_SCSI2) &&\r
380                 (pageCode == 0x08 || pageCode == 0x3F))\r
381         {\r
382                 pageFound = 1;\r
383                 pageIn(pc, idx, CachingPage, sizeof(CachingPage));\r
384                 idx += sizeof(CachingPage);\r
385         }\r
386 \r
387         if ((scsiDev.compatMode >= COMPAT_SCSI2)\r
388                 && (pageCode == 0x0A || pageCode == 0x3F))\r
389         {\r
390                 pageFound = 1;\r
391                 pageIn(pc, idx, ControlModePage, sizeof(ControlModePage));\r
392                 idx += sizeof(ControlModePage);\r
393         }\r
394 \r
395         if ((\r
396                         (scsiDev.target->cfg->quirks == CONFIG_QUIRKS_APPLE) ||\r
397                         (idx + sizeof(AppleVendorPage) <= allocLength)\r
398                 ) &&\r
399                 (pageCode == 0x30 || pageCode == 0x3F))\r
400         {\r
401                 pageFound = 1;\r
402                 pageIn(pc, idx, AppleVendorPage, sizeof(AppleVendorPage));\r
403                 idx += sizeof(AppleVendorPage);\r
404         }\r
405 \r
406         if (!pageFound)\r
407         {\r
408                 // Unknown Page Code\r
409                 pageFound = 0;\r
410                 scsiDev.status = CHECK_CONDITION;\r
411                 scsiDev.target->sense.code = ILLEGAL_REQUEST;\r
412                 scsiDev.target->sense.asc = INVALID_FIELD_IN_CDB;\r
413                 scsiDev.phase = STATUS;\r
414         }\r
415         else\r
416         {\r
417                 // Go back and fill out the mode data length\r
418                 if (sixByteCmd)\r
419                 {\r
420                         // Cannot currently exceed limits. yay\r
421                         scsiDev.data[0] = idx - 1;\r
422                 }\r
423                 else\r
424                 {\r
425                         scsiDev.data[0] = ((idx - 2) >> 8);\r
426                         scsiDev.data[1] = (idx - 2);\r
427                 }\r
428 \r
429                 scsiDev.dataLen = idx > allocLength ? allocLength : idx;\r
430                 scsiDev.phase = DATA_IN;\r
431         }\r
432 }\r
433 \r
434 \r
435 // Callback after the DATA OUT phase is complete.\r
436 static void doModeSelect(void)\r
437 {\r
438         if (scsiDev.status == GOOD) // skip if we've already encountered an error\r
439         {\r
440                 // scsiDev.dataLen bytes are in scsiDev.data\r
441 \r
442                 int idx;\r
443                 int blockDescLen;\r
444                 if (scsiDev.cdb[0] == 0x55)\r
445                 {\r
446                         blockDescLen =\r
447                                 (((uint16_t)scsiDev.data[6]) << 8) |scsiDev.data[7];\r
448                         idx = 8;\r
449                 }\r
450                 else\r
451                 {\r
452                         blockDescLen = scsiDev.data[3];\r
453                         idx = 4;\r
454                 }\r
455 \r
456                 // The unwritten rule.  Blocksizes are normally set using the\r
457                 // block descriptor value, not by changing page 0x03.\r
458                 if (blockDescLen >= 8)\r
459                 {\r
460                         uint32_t bytesPerSector =\r
461                                 (((uint32_t)scsiDev.data[idx+5]) << 16) |\r
462                                 (((uint32_t)scsiDev.data[idx+6]) << 8) |\r
463                                 scsiDev.data[idx+7];\r
464                         if ((bytesPerSector < MIN_SECTOR_SIZE) ||\r
465                                 (bytesPerSector > MAX_SECTOR_SIZE))\r
466                         {\r
467                                 goto bad;\r
468                         }\r
469                         else\r
470                         {\r
471                                 scsiDev.target->liveCfg.bytesPerSector = bytesPerSector;\r
472                                 if (bytesPerSector != scsiDev.target->cfg->bytesPerSector)\r
473                                 {\r
474                                         configSave(scsiDev.target->targetId, bytesPerSector);\r
475                                 }\r
476                         }\r
477                 }\r
478                 idx += blockDescLen;\r
479 \r
480                 while (idx < scsiDev.dataLen)\r
481                 {\r
482                         int pageLen = scsiDev.data[idx + 1];\r
483                         if (idx + 2 + pageLen > scsiDev.dataLen) goto bad;\r
484 \r
485                         int pageCode = scsiDev.data[idx] & 0x3F;\r
486                         switch (pageCode)\r
487                         {\r
488                         case 0x03: // Format Device Page\r
489                         {\r
490                                 if (pageLen != 0x16) goto bad;\r
491 \r
492                                 // Fill out the configured bytes-per-sector\r
493                                 uint16_t bytesPerSector =\r
494                                         (((uint16_t)scsiDev.data[idx+12]) << 8) |\r
495                                         scsiDev.data[idx+13];\r
496 \r
497                                 // Sane values only, ok ?\r
498                                 if ((bytesPerSector < MIN_SECTOR_SIZE) ||\r
499                                         (bytesPerSector > MAX_SECTOR_SIZE))\r
500                                 {\r
501                                         goto bad;\r
502                                 }\r
503 \r
504                                 scsiDev.target->liveCfg.bytesPerSector = bytesPerSector;\r
505                                 if (scsiDev.cdb[1] & 1) // SP Save Pages flag\r
506                                 {\r
507                                         configSave(scsiDev.target->targetId, bytesPerSector);\r
508                                 }\r
509                         }\r
510                         break;\r
511                         //default:\r
512 \r
513                                 // Easiest to just ignore for now. We'll get here when changing\r
514                                 // the SCSI block size via the descriptor header.\r
515                         }\r
516                         idx += 2 + pageLen;\r
517                 }\r
518         }\r
519 \r
520         goto out;\r
521 bad:\r
522         scsiDev.status = CHECK_CONDITION;\r
523         scsiDev.target->sense.code = ILLEGAL_REQUEST;\r
524         scsiDev.target->sense.asc = INVALID_FIELD_IN_PARAMETER_LIST;\r
525 \r
526 out:\r
527         scsiDev.phase = STATUS;\r
528 }\r
529 \r
530 int scsiModeCommand()\r
531 {\r
532         int commandHandled = 1;\r
533 \r
534         uint8 command = scsiDev.cdb[0];\r
535 \r
536         // We don't currently support the setting of any parameters.\r
537         // (ie. no MODE SELECT(6) or MODE SELECT(10) commands)\r
538 \r
539         if (command == 0x1A)\r
540         {\r
541                 // MODE SENSE(6)\r
542                 int dbd = scsiDev.cdb[1] & 0x08; // Disable block descriptors\r
543                 int pc = scsiDev.cdb[2] >> 6; // Page Control\r
544                 int pageCode = scsiDev.cdb[2] & 0x3F;\r
545                 int allocLength = scsiDev.cdb[4];\r
546                 if (allocLength == 0) allocLength = 256;\r
547                 doModeSense(1, dbd, pc, pageCode, allocLength);\r
548         }\r
549         else if (command == 0x5A)\r
550         {\r
551                 // MODE SENSE(10)\r
552                 int dbd = scsiDev.cdb[1] & 0x08; // Disable block descriptors\r
553                 int pc = scsiDev.cdb[2] >> 6; // Page Control\r
554                 int pageCode = scsiDev.cdb[2] & 0x3F;\r
555                 int allocLength =\r
556                         (((uint16) scsiDev.cdb[7]) << 8) +\r
557                         scsiDev.cdb[8];\r
558                 doModeSense(0, dbd, pc, pageCode, allocLength);\r
559         }\r
560         else if (command == 0x15)\r
561         {\r
562                 // MODE SELECT(6)\r
563                 int len = scsiDev.cdb[4];\r
564                 if (len == 0)\r
565                 {\r
566                         // If len == 0, then transfer no data. From the SCSI 2 standard:\r
567                         //      A parameter list length of zero indicates that no data shall\r
568                         //      be transferred. This condition shall not be considered as an\r
569                         //              error.\r
570                         scsiDev.phase = STATUS;\r
571                 }\r
572                 else\r
573                 {\r
574                         scsiDev.dataLen = len;\r
575                         scsiDev.phase = DATA_OUT;\r
576                         scsiDev.postDataOutHook = doModeSelect;\r
577                 }\r
578         }\r
579         else if (command == 0x55)\r
580         {\r
581                 // MODE SELECT(10)\r
582                 int allocLength = (((uint16) scsiDev.cdb[7]) << 8) + scsiDev.cdb[8];\r
583                 if (allocLength == 0)\r
584                 {\r
585                         // If len == 0, then transfer no data. From the SCSI 2 standard:\r
586                         //      A parameter list length of zero indicates that no data shall\r
587                         //      be transferred. This condition shall not be considered as an\r
588                         //              error.\r
589                         scsiDev.phase = STATUS;\r
590                 }\r
591                 else\r
592                 {\r
593                         scsiDev.dataLen = allocLength;\r
594                         scsiDev.phase = DATA_OUT;\r
595                         scsiDev.postDataOutHook = doModeSelect;\r
596                 }\r
597         }\r
598         else\r
599         {\r
600                 commandHandled = 0;\r
601         }\r
602 \r
603         return commandHandled;\r
604 }\r
605 \r
606 #pragma GCC pop_options\r