^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * PS3 Disk Storage Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2007 Sony Computer Entertainment Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright 2007 Sony Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/ata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/blk-mq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/lv1call.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <asm/ps3stor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <asm/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define DEVICE_NAME "ps3disk"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define BOUNCE_SIZE (64*1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define PS3DISK_MAX_DISKS 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define PS3DISK_MINORS 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define PS3DISK_NAME "ps3d%c"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct ps3disk_private {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) spinlock_t lock; /* Request queue spinlock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct request_queue *queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct blk_mq_tag_set tag_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct gendisk *gendisk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned int blocking_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) u64 raw_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) unsigned char model[ATA_ID_PROD_LEN+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define LV1_STORAGE_SEND_ATA_COMMAND (2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define LV1_STORAGE_ATA_HDDOUT (0x23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct lv1_ata_cmnd_block {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u16 features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u16 sector_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u16 LBA_low;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) u16 LBA_mid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u16 LBA_high;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) u8 device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u8 command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) u32 is_ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u32 proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) u32 in_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u32 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) u64 buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) u32 arglen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) enum lv1_ata_proto {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) NON_DATA_PROTO = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) PIO_DATA_IN_PROTO = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) PIO_DATA_OUT_PROTO = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) DMA_PROTO = 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) enum lv1_ata_in_out {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) DIR_WRITE = 0, /* memory -> device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) DIR_READ = 1 /* device -> memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static int ps3disk_major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static const struct block_device_operations ps3disk_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static void ps3disk_scatter_gather(struct ps3_storage_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct request *req, int gather)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) unsigned int offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct req_iterator iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct bio_vec bvec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) unsigned int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) void *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) rq_for_each_segment(bvec, req, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) dev_dbg(&dev->sbd.core, "%s:%u: bio %u: %u sectors from %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) __func__, __LINE__, i, bio_sectors(iter.bio),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) iter.bio->bi_iter.bi_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) size = bvec.bv_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) buf = bvec_kmap_irq(&bvec, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (gather)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) memcpy(dev->bounce_buf+offset, buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) memcpy(buf, dev->bounce_buf+offset, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) offset += size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) flush_kernel_dcache_page(bvec.bv_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) bvec_kunmap_irq(buf, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static blk_status_t ps3disk_submit_request_sg(struct ps3_storage_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct ps3disk_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int write = rq_data_dir(req), res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) const char *op = write ? "write" : "read";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) u64 start_sector, sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) unsigned int region_id = dev->regions[dev->region_idx].id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) unsigned int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct bio_vec bv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct req_iterator iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) rq_for_each_segment(bv, req, iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) dev_dbg(&dev->sbd.core,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) "%s:%u: %s req has %u bvecs for %u sectors\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) __func__, __LINE__, op, n, blk_rq_sectors(req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) start_sector = blk_rq_pos(req) * priv->blocking_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) sectors = blk_rq_sectors(req) * priv->blocking_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) dev_dbg(&dev->sbd.core, "%s:%u: %s %llu sectors starting at %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) __func__, __LINE__, op, sectors, start_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (write) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ps3disk_scatter_gather(dev, req, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) res = lv1_storage_write(dev->sbd.dev_id, region_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) start_sector, sectors, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) dev->bounce_lpar, &dev->tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) res = lv1_storage_read(dev->sbd.dev_id, region_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) start_sector, sectors, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) dev->bounce_lpar, &dev->tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) dev_err(&dev->sbd.core, "%s:%u: %s failed %d\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) __LINE__, op, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return BLK_STS_IOERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) priv->req = req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return BLK_STS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static blk_status_t ps3disk_submit_flush_request(struct ps3_storage_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct ps3disk_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) u64 res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) dev_dbg(&dev->sbd.core, "%s:%u: flush request\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) res = lv1_storage_send_device_command(dev->sbd.dev_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) LV1_STORAGE_ATA_HDDOUT, 0, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 0, &dev->tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) dev_err(&dev->sbd.core, "%s:%u: sync cache failed 0x%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) __func__, __LINE__, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return BLK_STS_IOERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) priv->req = req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return BLK_STS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static blk_status_t ps3disk_do_request(struct ps3_storage_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) dev_dbg(&dev->sbd.core, "%s:%u\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) switch (req_op(req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) case REQ_OP_FLUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return ps3disk_submit_flush_request(dev, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) case REQ_OP_READ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) case REQ_OP_WRITE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return ps3disk_submit_request_sg(dev, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) blk_dump_rq_flags(req, DEVICE_NAME " bad request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return BLK_STS_IOERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static blk_status_t ps3disk_queue_rq(struct blk_mq_hw_ctx *hctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) const struct blk_mq_queue_data *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct request_queue *q = hctx->queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct ps3_storage_device *dev = q->queuedata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct ps3disk_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) blk_status_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) blk_mq_start_request(bd->rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) spin_lock_irq(&priv->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) ret = ps3disk_do_request(dev, bd->rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) spin_unlock_irq(&priv->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static irqreturn_t ps3disk_interrupt(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct ps3_storage_device *dev = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct ps3disk_private *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) int res, read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) blk_status_t error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) u64 tag, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) const char *op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) res = lv1_storage_get_async_status(dev->sbd.dev_id, &tag, &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (tag != dev->tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) dev_err(&dev->sbd.core,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) "%s:%u: tag mismatch, got %llx, expected %llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) __func__, __LINE__, tag, dev->tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) dev_err(&dev->sbd.core, "%s:%u: res=%d status=0x%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) __func__, __LINE__, res, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) priv = ps3_system_bus_get_drvdata(&dev->sbd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) req = priv->req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) dev_dbg(&dev->sbd.core,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) "%s:%u non-block layer request completed\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) dev->lv1_status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) complete(&dev->done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (req_op(req) == REQ_OP_FLUSH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) op = "flush";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) read = !rq_data_dir(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) op = read ? "read" : "write";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) dev_dbg(&dev->sbd.core, "%s:%u: %s failed 0x%llx\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) __LINE__, op, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) error = BLK_STS_IOERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) dev_dbg(&dev->sbd.core, "%s:%u: %s completed\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) __LINE__, op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (read)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) ps3disk_scatter_gather(dev, req, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) spin_lock(&priv->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) priv->req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) blk_mq_end_request(req, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) spin_unlock(&priv->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) blk_mq_run_hw_queues(priv->queue, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static int ps3disk_sync_cache(struct ps3_storage_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) u64 res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) dev_dbg(&dev->sbd.core, "%s:%u: sync cache\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) res = ps3stor_send_command(dev, LV1_STORAGE_ATA_HDDOUT, 0, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) dev_err(&dev->sbd.core, "%s:%u: sync cache failed 0x%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) __func__, __LINE__, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* ATA helpers copied from drivers/ata/libata-core.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static void swap_buf_le16(u16 *buf, unsigned int buf_words)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) #ifdef __BIG_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) for (i = 0; i < buf_words; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) buf[i] = le16_to_cpu(buf[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) #endif /* __BIG_ENDIAN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static u64 ata_id_n_sectors(const u16 *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (ata_id_has_lba(id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (ata_id_has_lba48(id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return ata_id_u64(id, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return ata_id_u32(id, 60);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (ata_id_current_chs_valid(id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return ata_id_u32(id, 57);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return id[1] * id[3] * id[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static void ata_id_string(const u16 *id, unsigned char *s, unsigned int ofs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) unsigned int c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) while (len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) c = id[ofs] >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) *s = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) s++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) c = id[ofs] & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) *s = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) s++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) ofs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) len -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static void ata_id_c_string(const u16 *id, unsigned char *s, unsigned int ofs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) unsigned char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) WARN_ON(!(len & 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) ata_id_string(id, s, ofs, len - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) p = s + strnlen(s, len - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) while (p > s && p[-1] == ' ')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) p--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) *p = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) static int ps3disk_identify(struct ps3_storage_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) struct ps3disk_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct lv1_ata_cmnd_block ata_cmnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) u16 *id = dev->bounce_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) u64 res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) dev_dbg(&dev->sbd.core, "%s:%u: identify disk\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) memset(&ata_cmnd, 0, sizeof(struct lv1_ata_cmnd_block));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) ata_cmnd.command = ATA_CMD_ID_ATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) ata_cmnd.sector_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) ata_cmnd.size = ata_cmnd.arglen = ATA_ID_WORDS * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) ata_cmnd.buffer = dev->bounce_lpar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) ata_cmnd.proto = PIO_DATA_IN_PROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) ata_cmnd.in_out = DIR_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) res = ps3stor_send_command(dev, LV1_STORAGE_SEND_ATA_COMMAND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) ps3_mm_phys_to_lpar(__pa(&ata_cmnd)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) sizeof(ata_cmnd), ata_cmnd.buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) ata_cmnd.arglen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) dev_err(&dev->sbd.core, "%s:%u: identify disk failed 0x%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) __func__, __LINE__, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) swap_buf_le16(id, ATA_ID_WORDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) /* All we're interested in are raw capacity and model name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) priv->raw_capacity = ata_id_n_sectors(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) ata_id_c_string(id, priv->model, ATA_ID_PROD, sizeof(priv->model));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static unsigned long ps3disk_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) static DEFINE_MUTEX(ps3disk_mask_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static const struct blk_mq_ops ps3disk_mq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) .queue_rq = ps3disk_queue_rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static int ps3disk_probe(struct ps3_system_bus_device *_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) struct ps3_storage_device *dev = to_ps3_storage_device(&_dev->core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) struct ps3disk_private *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) unsigned int devidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct request_queue *queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct gendisk *gendisk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (dev->blk_size < 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) dev_err(&dev->sbd.core,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) "%s:%u: cannot handle block size %llu\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) __LINE__, dev->blk_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) BUILD_BUG_ON(PS3DISK_MAX_DISKS > BITS_PER_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) mutex_lock(&ps3disk_mask_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) devidx = find_first_zero_bit(&ps3disk_mask, PS3DISK_MAX_DISKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (devidx >= PS3DISK_MAX_DISKS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) dev_err(&dev->sbd.core, "%s:%u: Too many disks\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) mutex_unlock(&ps3disk_mask_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) __set_bit(devidx, &ps3disk_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) mutex_unlock(&ps3disk_mask_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) priv = kzalloc(sizeof(*priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (!priv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) ps3_system_bus_set_drvdata(_dev, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) spin_lock_init(&priv->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) dev->bounce_size = BOUNCE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) dev->bounce_buf = kmalloc(BOUNCE_SIZE, GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (!dev->bounce_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) goto fail_free_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) error = ps3stor_setup(dev, ps3disk_interrupt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) goto fail_free_bounce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) ps3disk_identify(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) queue = blk_mq_init_sq_queue(&priv->tag_set, &ps3disk_mq_ops, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) BLK_MQ_F_SHOULD_MERGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (IS_ERR(queue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) dev_err(&dev->sbd.core, "%s:%u: blk_mq_init_queue failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) error = PTR_ERR(queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) goto fail_teardown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) priv->queue = queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) queue->queuedata = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) blk_queue_max_hw_sectors(queue, dev->bounce_size >> 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) blk_queue_dma_alignment(queue, dev->blk_size-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) blk_queue_logical_block_size(queue, dev->blk_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) blk_queue_write_cache(queue, true, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) blk_queue_max_segments(queue, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) blk_queue_max_segment_size(queue, dev->bounce_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) gendisk = alloc_disk(PS3DISK_MINORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if (!gendisk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) dev_err(&dev->sbd.core, "%s:%u: alloc_disk failed\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) goto fail_cleanup_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) priv->gendisk = gendisk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) gendisk->major = ps3disk_major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) gendisk->first_minor = devidx * PS3DISK_MINORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) gendisk->fops = &ps3disk_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) gendisk->queue = queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) gendisk->private_data = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) snprintf(gendisk->disk_name, sizeof(gendisk->disk_name), PS3DISK_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) devidx+'a');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) priv->blocking_factor = dev->blk_size >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) set_capacity(gendisk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) dev->regions[dev->region_idx].size*priv->blocking_factor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) dev_info(&dev->sbd.core,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) "%s is a %s (%llu MiB total, %llu MiB for OtherOS)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) gendisk->disk_name, priv->model, priv->raw_capacity >> 11,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) get_capacity(gendisk) >> 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) device_add_disk(&dev->sbd.core, gendisk, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) fail_cleanup_queue:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) blk_cleanup_queue(queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) blk_mq_free_tag_set(&priv->tag_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) fail_teardown:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) ps3stor_teardown(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) fail_free_bounce:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) kfree(dev->bounce_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) fail_free_priv:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) kfree(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) ps3_system_bus_set_drvdata(_dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) mutex_lock(&ps3disk_mask_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) __clear_bit(devidx, &ps3disk_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) mutex_unlock(&ps3disk_mask_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static int ps3disk_remove(struct ps3_system_bus_device *_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) struct ps3_storage_device *dev = to_ps3_storage_device(&_dev->core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) struct ps3disk_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) mutex_lock(&ps3disk_mask_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) __clear_bit(MINOR(disk_devt(priv->gendisk)) / PS3DISK_MINORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) &ps3disk_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) mutex_unlock(&ps3disk_mask_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) del_gendisk(priv->gendisk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) blk_cleanup_queue(priv->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) blk_mq_free_tag_set(&priv->tag_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) put_disk(priv->gendisk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) dev_notice(&dev->sbd.core, "Synchronizing disk cache\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) ps3disk_sync_cache(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) ps3stor_teardown(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) kfree(dev->bounce_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) kfree(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) ps3_system_bus_set_drvdata(_dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) static struct ps3_system_bus_driver ps3disk = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) .match_id = PS3_MATCH_ID_STOR_DISK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) .core.name = DEVICE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) .core.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) .probe = ps3disk_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) .remove = ps3disk_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) .shutdown = ps3disk_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) static int __init ps3disk_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) error = register_blkdev(0, DEVICE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (error <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) printk(KERN_ERR "%s:%u: register_blkdev failed %d\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) __LINE__, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) ps3disk_major = error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) pr_info("%s:%u: registered block device major %d\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) __LINE__, ps3disk_major);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) error = ps3_system_bus_driver_register(&ps3disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) unregister_blkdev(ps3disk_major, DEVICE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) static void __exit ps3disk_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) ps3_system_bus_driver_unregister(&ps3disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) unregister_blkdev(ps3disk_major, DEVICE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) module_init(ps3disk_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) module_exit(ps3disk_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) MODULE_DESCRIPTION("PS3 Disk Storage Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) MODULE_AUTHOR("Sony Corporation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) MODULE_ALIAS(PS3_MODULE_ALIAS_STOR_DISK);