23 #include <linux/slab.h>
24 #include <linux/module.h>
31 #define DEVICE_NAME "ps3disk"
33 #define BOUNCE_SIZE (64*1024)
35 #define PS3DISK_MAX_DISKS 16
36 #define PS3DISK_MINORS 16
39 #define PS3DISK_NAME "ps3d%c"
53 #define LV1_STORAGE_SEND_ATA_COMMAND (2)
54 #define LV1_STORAGE_ATA_HDDOUT (0x23)
84 static int ps3disk_major;
87 static const struct block_device_operations ps3disk_fops = {
96 struct req_iterator iter;
102 rq_for_each_segment(bvec, req, iter) {
105 "%s:%u: bio %u: %u segs %u sectors from %lu\n",
106 __func__, __LINE__, i, bio_segments(iter.bio),
107 bio_sectors(iter.bio), iter.bio->bi_sector);
110 buf = bvec_kmap_irq(bvec, &flags);
116 flush_kernel_dcache_page(bvec->bv_page);
117 bvec_kunmap_irq(buf, &flags);
127 const char *
op = write ?
"write" :
"read";
134 struct req_iterator iter;
136 rq_for_each_segment(bv, req, iter)
139 "%
s:%
u: %
s req has %
u bvecs
for %
u sectors\n",
140 __func__, __LINE__, op, n, blk_rq_sectors(req));
145 dev_dbg(&dev->
sbd.core,
"%s:%u: %s %llu sectors starting at %llu\n",
146 __func__, __LINE__, op, sectors, start_sector);
149 ps3disk_scatter_gather(dev, req, 1);
151 res = lv1_storage_write(dev->
sbd.dev_id, region_id,
152 start_sector, sectors, 0,
155 res = lv1_storage_read(dev->
sbd.dev_id, region_id,
156 start_sector, sectors, 0,
160 dev_err(&dev->
sbd.core,
"%s:%u: %s failed %d\n", __func__,
176 dev_dbg(&dev->
sbd.core,
"%s:%u: flush request\n", __func__, __LINE__);
178 res = lv1_storage_send_device_command(dev->
sbd.dev_id,
182 dev_err(&dev->
sbd.core,
"%s:%u: sync cache failed 0x%llx\n",
183 __func__, __LINE__, res);
197 dev_dbg(&dev->
sbd.core,
"%s:%u\n", __func__, __LINE__);
201 if (ps3disk_submit_flush_request(dev, req))
203 }
else if (req->cmd_type == REQ_TYPE_FS) {
204 if (ps3disk_submit_request_sg(dev, req))
220 dev_dbg(&dev->
sbd.core,
"%s:%u busy\n", __func__, __LINE__);
224 ps3disk_do_request(dev, q);
236 res = lv1_storage_get_async_status(dev->
sbd.dev_id, &tag, &status);
240 "%s:%u: tag mismatch, got %llx, expected %llx\n",
241 __func__, __LINE__, tag, dev->
tag);
244 dev_err(&dev->
sbd.core,
"%s:%u: res=%d status=0x%llx\n",
245 __func__, __LINE__, res, status);
249 priv = ps3_system_bus_get_drvdata(&dev->
sbd);
253 "%s:%u non-block layer request completed\n", __func__,
264 read = !rq_data_dir(req);
265 op = read ?
"read" :
"write";
268 dev_dbg(&dev->
sbd.core,
"%s:%u: %s failed 0x%llx\n", __func__,
269 __LINE__, op, status);
272 dev_dbg(&dev->
sbd.core,
"%s:%u: %s completed\n", __func__,
276 ps3disk_scatter_gather(dev, req, 0);
279 spin_lock(&priv->
lock);
282 ps3disk_do_request(dev, priv->
queue);
283 spin_unlock(&priv->
lock);
292 dev_dbg(&dev->
sbd.core,
"%s:%u: sync cache\n", __func__, __LINE__);
296 dev_err(&dev->
sbd.core,
"%s:%u: sync cache failed 0x%llx\n",
297 __func__, __LINE__, res);
311 for (i = 0; i < buf_words; i++)
316 static u64 ata_id_n_sectors(
const u16 *
id)
319 if (ata_id_has_lba48(
id))
324 if (ata_id_current_chs_valid(
id))
327 return id[1] *
id[3] *
id[6];
360 while (p > s && p[-1] ==
' ')
372 dev_dbg(&dev->
sbd.core,
"%s:%u: identify disk\n", __func__, __LINE__);
376 ata_cmnd.sector_count = 1;
384 sizeof(ata_cmnd), ata_cmnd.buffer,
387 dev_err(&dev->
sbd.core,
"%s:%u: identify disk failed 0x%llx\n",
388 __func__, __LINE__, res);
400 static unsigned long ps3disk_mask;
411 struct gendisk *gendisk;
415 "%s:%u: cannot handle block size %llu\n", __func__,
424 dev_err(&dev->
sbd.core,
"%s:%u: Too many disks\n", __func__,
438 ps3_system_bus_set_drvdata(_dev, priv);
450 goto fail_free_bounce;
452 ps3disk_identify(dev);
456 dev_err(&dev->
sbd.core,
"%s:%u: blk_init_queue failed\n",
463 queue->queuedata =
dev;
479 dev_err(&dev->
sbd.core,
"%s:%u: alloc_disk failed\n", __func__,
482 goto fail_cleanup_queue;
486 gendisk->major = ps3disk_major;
488 gendisk->fops = &ps3disk_fops;
489 gendisk->queue = queue;
490 gendisk->private_data =
dev;
491 gendisk->driverfs_dev = &dev->
sbd.core;
495 set_capacity(gendisk,
499 "%s is a %s (%llu MiB total, %lu MiB for OtherOS)\n",
501 get_capacity(gendisk) >> 11);
514 ps3_system_bus_set_drvdata(_dev,
NULL);
534 dev_notice(&dev->
sbd.core,
"Synchronizing disk cache\n");
535 ps3disk_sync_cache(dev);
539 ps3_system_bus_set_drvdata(_dev,
NULL);
547 .probe = ps3disk_probe,
548 .remove = ps3disk_remove,
549 .shutdown = ps3disk_remove,
553 static int __init ps3disk_init(
void)
557 if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
566 ps3disk_major =
error;
568 pr_info(
"%s:%u: registered block device major %d\n", __func__,
569 __LINE__, ps3disk_major);
578 static void __exit ps3disk_exit(
void)