Changeset 132a6073 in mainline
- Timestamp:
- 2011-07-25T16:56:55Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 41ff85b
- Parents:
- 358dc13
- Location:
- uspace
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbmast/scsi_ms.c
r358dc13 r132a6073 61 61 } 62 62 63 static void usbmast_dump_sense(usbmast_fun_t *mfun) 64 { 63 static void usbmast_dump_sense(scsi_sense_data_t *sense_buf) 64 { 65 unsigned sense_key; 66 67 sense_key = sense_buf->flags_key & 0x0f; 68 printf("Got sense data. Sense key: 0x%x (%s), ASC 0x%02x, " 69 "ASCQ 0x%02x.\n", sense_key, 70 scsi_get_sense_key_str(sense_key), 71 sense_buf->additional_code, 72 sense_buf->additional_cqual); 73 } 74 75 /** Run SCSI command. 76 * 77 * Run command and repeat in case of unit attention. 78 * XXX This is too simplified. 79 */ 80 static int usbmast_run_cmd(usbmast_fun_t *mfun, scsi_cmd_t *cmd) 81 { 82 uint8_t sense_key; 65 83 scsi_sense_data_t sense_buf; 66 unsigned sense_key; 67 int rc; 68 69 rc = usbmast_request_sense(mfun, &sense_buf, sizeof(sense_buf)); 70 if (rc == EOK) { 84 int rc; 85 86 do { 87 rc = usb_massstor_cmd(mfun, 0xDEADBEEF, cmd); 88 if (rc != EOK) { 89 usb_log_error("Inquiry transport failed, device %s: %s.\n", 90 mfun->mdev->ddf_dev->name, str_error(rc)); 91 return rc; 92 } 93 94 if (cmd->status == CMDS_GOOD) 95 return EOK; 96 97 usb_log_error("SCSI command failed, device %s.\n", 98 mfun->mdev->ddf_dev->name); 99 100 rc = usbmast_request_sense(mfun, &sense_buf, sizeof(sense_buf)); 101 if (rc != EOK) { 102 usb_log_error("Failed to read sense data.\n"); 103 return EIO; 104 } 105 106 /* Dump sense data to log */ 107 usbmast_dump_sense(&sense_buf); 108 109 /* Get sense key */ 71 110 sense_key = sense_buf.flags_key & 0x0f; 72 printf("Got sense data. Sense key: 0x%x (%s), ASC 0x%02x, " 73 "ASCQ 0x%02x.\n", sense_key, 74 scsi_get_sense_key_str(sense_key), 75 sense_buf.additional_code, 76 sense_buf.additional_cqual); 77 } else { 78 printf("Failed to read sense data.\n"); 79 } 111 112 if (sense_key == SCSI_SK_UNIT_ATTENTION) { 113 printf("Got unit attention. Re-trying command.\n"); 114 } 115 116 } while (sense_key == SCSI_SK_UNIT_ATTENTION); 117 118 /* Command status is not good, nevertheless transport succeeded. */ 119 return EOK; 80 120 } 81 121 … … 114 154 usb_log_error("Inquiry command failed, device %s.\n", 115 155 mfun->mdev->ddf_dev->name); 116 usbmast_dump_sense(mfun);117 156 return EIO; 118 157 } … … 214 253 cmd.data_in_size = sizeof(data); 215 254 216 rc = usb _massstor_cmd(mfun, 0xDEADBEEF, &cmd);255 rc = usbmast_run_cmd(mfun, &cmd); 217 256 218 257 if (rc != EOK) { … … 225 264 usb_log_error("Read Capacity (10) command failed, device %s.\n", 226 265 mfun->mdev->ddf_dev->name); 227 usbmast_dump_sense(mfun);228 266 return EIO; 229 267 } … … 252 290 { 253 291 scsi_cmd_t cmd; 254 scsi_cdb_read_1 2_t cdb;292 scsi_cdb_read_10_t cdb; 255 293 int rc; 256 294 … … 258 296 return ELIMIT; 259 297 260 if ( (uint64_t)nblocks * mfun->block_size > UINT32_MAX)298 if (nblocks > UINT16_MAX) 261 299 return ELIMIT; 262 300 263 301 memset(&cdb, 0, sizeof(cdb)); 264 cdb.op_code = SCSI_CMD_READ_1 2;302 cdb.op_code = SCSI_CMD_READ_10; 265 303 cdb.lba = host2uint32_t_be(ba); 266 cdb.xfer_len = host2uint 32_t_be(nblocks);304 cdb.xfer_len = host2uint16_t_be(nblocks); 267 305 268 306 memset(&cmd, 0, sizeof(cmd)); … … 272 310 cmd.data_in_size = nblocks * mfun->block_size; 273 311 274 rc = usb _massstor_cmd(mfun, 0xDEADBEEF, &cmd);312 rc = usbmast_run_cmd(mfun, &cmd); 275 313 276 314 if (rc != EOK) { 277 usb_log_error("Read (1 2) transport failed, device %s: %s.\n",315 usb_log_error("Read (10) transport failed, device %s: %s.\n", 278 316 mfun->mdev->ddf_dev->name, str_error(rc)); 279 317 return rc; … … 281 319 282 320 if (cmd.status != CMDS_GOOD) { 283 usb_log_error("Read (1 2) command failed, device %s.\n",321 usb_log_error("Read (10) command failed, device %s.\n", 284 322 mfun->mdev->ddf_dev->name); 285 usbmast_dump_sense(mfun);286 323 return EIO; 287 324 } … … 309 346 { 310 347 scsi_cmd_t cmd; 311 scsi_cdb_write_1 2_t cdb;348 scsi_cdb_write_10_t cdb; 312 349 int rc; 313 350 … … 315 352 return ELIMIT; 316 353 317 if ( (uint64_t)nblocks * mfun->block_size > UINT32_MAX)354 if (nblocks > UINT16_MAX) 318 355 return ELIMIT; 319 356 320 357 memset(&cdb, 0, sizeof(cdb)); 321 cdb.op_code = SCSI_CMD_WRITE_1 2;358 cdb.op_code = SCSI_CMD_WRITE_10; 322 359 cdb.lba = host2uint32_t_be(ba); 323 cdb.xfer_len = host2uint 32_t_be(nblocks);360 cdb.xfer_len = host2uint16_t_be(nblocks); 324 361 325 362 memset(&cmd, 0, sizeof(cmd)); … … 329 366 cmd.data_out_size = nblocks * mfun->block_size; 330 367 331 rc = usb _massstor_cmd(mfun, 0xDEADBEEF, &cmd);368 rc = usbmast_run_cmd(mfun, &cmd); 332 369 333 370 if (rc != EOK) { 334 usb_log_error("Write (1 2) transport failed, device %s: %s.\n",371 usb_log_error("Write (10) transport failed, device %s: %s.\n", 335 372 mfun->mdev->ddf_dev->name, str_error(rc)); 336 373 return rc; … … 338 375 339 376 if (cmd.status != CMDS_GOOD) { 340 usb_log_error("Write (1 2) command failed, device %s.\n",377 usb_log_error("Write (10) command failed, device %s.\n", 341 378 mfun->mdev->ddf_dev->name); 342 usbmast_dump_sense(mfun);343 379 return EIO; 344 380 } -
uspace/lib/scsi/include/scsi/sbc.h
r358dc13 r132a6073 56 56 }; 57 57 58 /** SCSI Read (10) command */ 59 typedef struct { 60 /** Operation code (SCSI_CMD_READ_10) */ 61 uint8_t op_code; 62 /** RdProtect, DPO, FUA, Reserved, FUA_NV, Obsolete */ 63 uint8_t flags; 64 /** Logical block address */ 65 uint32_t lba; 66 /** Reserved, Group Number */ 67 uint8_t group_no; 68 /** Transfer length */ 69 uint16_t xfer_len; 70 /** Control */ 71 uint8_t control; 72 } __attribute__((packed)) scsi_cdb_read_10_t; 73 58 74 /** SCSI Read (12) command */ 59 75 typedef struct { 60 76 /** Operation code (SCSI_CMD_READ_12) */ 61 77 uint8_t op_code; 62 /** RdProtect, DPO, FUA, Reserved, FUA_NV, Reserved*/78 /** RdProtect, DPO, FUA, Reserved, FUA_NV, Obsolete */ 63 79 uint8_t flags; 64 80 /** Logical block address */ … … 115 131 } scsi_read_capacity_10_data_t; 116 132 133 /** SCSI Write (10) command */ 134 typedef struct { 135 /** Operation code (SCSI_CMD_WRITE_10) */ 136 uint8_t op_code; 137 /** WrProtect, DPO, FUA, Reserved, FUA_NV, Obsolete */ 138 uint8_t flags; 139 /** Logical block address */ 140 uint32_t lba; 141 /** Reserved, Group Number */ 142 uint8_t group_no; 143 /** Transfer length */ 144 uint16_t xfer_len; 145 /** Control */ 146 uint8_t control; 147 } __attribute__((packed)) scsi_cdb_write_10_t; 148 117 149 /** SCSI Write (12) command */ 118 150 typedef struct { 119 151 /** Operation code (SCSI_CMD_WRITE_12) */ 120 152 uint8_t op_code; 121 /** WrProtect, DPO, FUA, Reserved, FUA_NV, Reserved*/153 /** WrProtect, DPO, FUA, Reserved, FUA_NV, Obsolete */ 122 154 uint8_t flags; 123 155 /** Logical block address */
Note:
See TracChangeset
for help on using the changeset viewer.