21 #include <linux/cdrom.h>
23 #include <linux/module.h>
24 #include <linux/slab.h>
26 #include <scsi/scsi.h>
37 #define DEVICE_NAME "ps3rom"
39 #define BOUNCE_SIZE (64*1024)
41 #define PS3ROM_MAX_SECTORS (BOUNCE_SIZE >> 9)
50 #define LV1_STORAGE_SEND_ATAPI_COMMAND (1)
76 static int ps3rom_slave_configure(
struct scsi_device *scsi_dev)
81 dev_dbg(&dev->
sbd.core,
"%s:%u: id %u, lun %u, channel %u\n", __func__,
82 __LINE__, scsi_dev->
id, scsi_dev->
lun, scsi_dev->
channel);
104 dev_dbg(&dev->
sbd.core,
"%s:%u: send ATAPI command 0x%02x\n", __func__,
109 atapi_cmnd.pktlen = 12;
110 atapi_cmnd.block_size = 1;
111 atapi_cmnd.blocks = atapi_cmnd.arglen = scsi_bufflen(cmd);
138 res = lv1_storage_send_device_command(dev->
sbd.dev_id,
140 lpar,
sizeof(atapi_cmnd),
142 atapi_cmnd.arglen, &dev->
tag);
145 "%s:%u: ATAPI command 0x%02x denied by policy\n",
146 __func__, __LINE__, opcode);
152 "%s:%u: ATAPI command 0x%02x failed %d\n", __func__,
153 __LINE__, opcode, res);
160 static inline unsigned int srb10_lba(
const struct scsi_cmnd *cmd)
162 return cmd->
cmnd[2] << 24 | cmd->
cmnd[3] << 16 | cmd->
cmnd[4] << 8 |
166 static inline unsigned int srb10_len(
const struct scsi_cmnd *cmd)
168 return cmd->
cmnd[7] << 8 | cmd->
cmnd[8];
177 dev_dbg(&dev->
sbd.core,
"%s:%u: read %u sectors starting at %u\n",
178 __func__, __LINE__, sectors, start_sector);
180 res = lv1_storage_read(dev->
sbd.dev_id,
184 dev_err(&dev->
sbd.core,
"%s:%u: read failed %d\n", __func__,
198 dev_dbg(&dev->
sbd.core,
"%s:%u: write %u sectors starting at %u\n",
199 __func__, __LINE__, sectors, start_sector);
203 res = lv1_storage_write(dev->
sbd.dev_id,
207 dev_err(&dev->
sbd.core,
"%s:%u: write failed %d\n", __func__,
215 static int ps3rom_queuecommand_lck(
struct scsi_cmnd *cmd,
230 opcode = cmd->
cmnd[0];
238 res = ps3rom_read_request(dev, cmd, srb10_lba(cmd),
243 res = ps3rom_write_request(dev, cmd, srb10_lba(cmd),
248 res = ps3rom_atapi_request(dev, cmd);
267 unsigned char *
asc,
unsigned char *
ascq)
272 *sense_key = (status >> 16) & 0xff;
273 *asc = (status >> 8) & 0xff;
274 *ascq = status & 0xff;
288 res = lv1_storage_get_async_status(dev->
sbd.dev_id, &tag, &status);
297 "%s:%u: tag mismatch, got %llx, expected %llx\n",
298 __func__, __LINE__, tag, dev->
tag);
301 dev_err(&dev->
sbd.core,
"%s:%u: res=%d status=0x%llx\n",
302 __func__, __LINE__, res, status);
306 host = ps3_system_bus_get_drvdata(&dev->
sbd);
307 priv = shost_priv(host);
315 len = scsi_sg_copy_from_buffer(cmd,
319 scsi_set_resid(cmd, scsi_bufflen(cmd) - len);
327 dev_err(&dev->
sbd.core,
"%s:%u: end error without autosense\n",
333 if (decode_lv1_status(status, &sense_key, &asc, &ascq)) {
349 .slave_configure = ps3rom_slave_configure,
350 .queuecommand = ps3rom_queuecommand,
371 "%s:%u: cannot handle block size %llu\n", __func__,
383 goto fail_free_bounce;
388 dev_err(&dev->
sbd.core,
"%s:%u: scsi_host_alloc failed\n",
393 priv = shost_priv(host);
394 ps3_system_bus_set_drvdata(&dev->
sbd, host);
401 error = scsi_add_host(host, &dev->
sbd.core);
403 dev_err(&dev->
sbd.core,
"%s:%u: scsi_host_alloc failed %d\n",
404 __func__, __LINE__, error);
414 ps3_system_bus_set_drvdata(&dev->
sbd,
NULL);
425 struct Scsi_Host *host = ps3_system_bus_get_drvdata(&dev->
sbd);
430 ps3_system_bus_set_drvdata(&dev->
sbd,
NULL);
439 .probe = ps3rom_probe,
440 .remove = ps3rom_remove
444 static int __init ps3rom_init(
void)
449 static void __exit ps3rom_exit(
void)