David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1 | /* sunvdc.c: Sun LDOM Virtual Disk Client. |
| 2 | * |
David S. Miller | 3d452e5 | 2008-09-01 01:48:52 -0700 | [diff] [blame] | 3 | * Copyright (C) 2007, 2008 David S. Miller <davem@davemloft.net> |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <linux/module.h> |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/types.h> |
| 9 | #include <linux/blkdev.h> |
| 10 | #include <linux/hdreg.h> |
| 11 | #include <linux/genhd.h> |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 12 | #include <linux/cdrom.h> |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 13 | #include <linux/slab.h> |
| 14 | #include <linux/spinlock.h> |
| 15 | #include <linux/completion.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/list.h> |
David Miller | d91c5e8 | 2007-10-24 08:46:01 +0200 | [diff] [blame] | 19 | #include <linux/scatterlist.h> |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 20 | |
| 21 | #include <asm/vio.h> |
| 22 | #include <asm/ldc.h> |
| 23 | |
| 24 | #define DRV_MODULE_NAME "sunvdc" |
| 25 | #define PFX DRV_MODULE_NAME ": " |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 26 | #define DRV_MODULE_VERSION "1.2" |
| 27 | #define DRV_MODULE_RELDATE "November 24, 2014" |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 28 | |
Greg Kroah-Hartman | 8d85fce | 2012-12-21 15:13:49 -0800 | [diff] [blame] | 29 | static char version[] = |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 30 | DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; |
| 31 | MODULE_AUTHOR("David S. Miller (davem@davemloft.net)"); |
| 32 | MODULE_DESCRIPTION("Sun LDOM virtual disk client driver"); |
| 33 | MODULE_LICENSE("GPL"); |
| 34 | MODULE_VERSION(DRV_MODULE_VERSION); |
| 35 | |
Dwight Engen | d0aedcd | 2014-09-19 09:43:02 -0400 | [diff] [blame] | 36 | #define VDC_TX_RING_SIZE 512 |
Liam R. Howlett | f41e546 | 2017-02-01 14:09:26 -0500 | [diff] [blame] | 37 | #define VDC_DEFAULT_BLK_SIZE 512 |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 38 | |
Kees Cook | ff5d1a4 | 2018-10-08 08:46:51 -0700 | [diff] [blame] | 39 | #define MAX_XFER_BLKS (128 * 1024) |
| 40 | #define MAX_XFER_SIZE (MAX_XFER_BLKS / VDC_DEFAULT_BLK_SIZE) |
| 41 | #define MAX_RING_COOKIES ((MAX_XFER_BLKS / PAGE_SIZE) + 2) |
| 42 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 43 | #define WAITING_FOR_LINK_UP 0x01 |
| 44 | #define WAITING_FOR_TX_SPACE 0x02 |
| 45 | #define WAITING_FOR_GEN_CMD 0x04 |
| 46 | #define WAITING_FOR_ANY -1 |
| 47 | |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 48 | static struct workqueue_struct *sunvdc_wq; |
| 49 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 50 | struct vdc_req_entry { |
| 51 | struct request *req; |
| 52 | }; |
| 53 | |
| 54 | struct vdc_port { |
| 55 | struct vio_driver_state vio; |
| 56 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 57 | struct gendisk *disk; |
| 58 | |
| 59 | struct vdc_completion *cmp; |
| 60 | |
| 61 | u64 req_id; |
| 62 | u64 seq; |
| 63 | struct vdc_req_entry rq_arr[VDC_TX_RING_SIZE]; |
| 64 | |
| 65 | unsigned long ring_cookies; |
| 66 | |
| 67 | u64 max_xfer_size; |
| 68 | u32 vdisk_block_size; |
| 69 | |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 70 | u64 ldc_timeout; |
| 71 | struct timer_list ldc_reset_timer; |
| 72 | struct work_struct ldc_reset_work; |
| 73 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 74 | /* The server fills these in for us in the disk attribute |
| 75 | * ACK packet. |
| 76 | */ |
| 77 | u64 operations; |
| 78 | u32 vdisk_size; |
| 79 | u8 vdisk_type; |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 80 | u8 vdisk_mtype; |
Liam R. Howlett | f41e546 | 2017-02-01 14:09:26 -0500 | [diff] [blame] | 81 | u32 vdisk_phys_blksz; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 82 | |
| 83 | char disk_name[32]; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 86 | static void vdc_ldc_reset(struct vdc_port *port); |
| 87 | static void vdc_ldc_reset_work(struct work_struct *work); |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 88 | static void vdc_ldc_reset_timer(struct timer_list *t); |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 89 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 90 | static inline struct vdc_port *to_vdc_port(struct vio_driver_state *vio) |
| 91 | { |
| 92 | return container_of(vio, struct vdc_port, vio); |
| 93 | } |
| 94 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 95 | /* Ordered from largest major to lowest */ |
| 96 | static struct vio_version vdc_versions[] = { |
Liam R. Howlett | f41e546 | 2017-02-01 14:09:26 -0500 | [diff] [blame] | 97 | { .major = 1, .minor = 2 }, |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 98 | { .major = 1, .minor = 1 }, |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 99 | { .major = 1, .minor = 0 }, |
| 100 | }; |
| 101 | |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 102 | static inline int vdc_version_supported(struct vdc_port *port, |
| 103 | u16 major, u16 minor) |
| 104 | { |
| 105 | return port->vio.ver.major == major && port->vio.ver.minor >= minor; |
| 106 | } |
| 107 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 108 | #define VDCBLK_NAME "vdisk" |
| 109 | static int vdc_major; |
| 110 | #define PARTITION_SHIFT 3 |
| 111 | |
| 112 | static inline u32 vdc_tx_dring_avail(struct vio_dring_state *dr) |
| 113 | { |
| 114 | return vio_dring_avail(dr, VDC_TX_RING_SIZE); |
| 115 | } |
| 116 | |
| 117 | static int vdc_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
| 118 | { |
| 119 | struct gendisk *disk = bdev->bd_disk; |
Allen Pais | de5b73f | 2014-09-19 09:42:26 -0400 | [diff] [blame] | 120 | sector_t nsect = get_capacity(disk); |
| 121 | sector_t cylinders = nsect; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 122 | |
Allen Pais | de5b73f | 2014-09-19 09:42:26 -0400 | [diff] [blame] | 123 | geo->heads = 0xff; |
| 124 | geo->sectors = 0x3f; |
| 125 | sector_div(cylinders, geo->heads * geo->sectors); |
| 126 | geo->cylinders = cylinders; |
| 127 | if ((sector_t)(geo->cylinders + 1) * geo->heads * geo->sectors < nsect) |
| 128 | geo->cylinders = 0xffff; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 133 | /* Add ioctl/CDROM_GET_CAPABILITY to support cdrom_id in udev |
| 134 | * when vdisk_mtype is VD_MEDIA_TYPE_CD or VD_MEDIA_TYPE_DVD. |
| 135 | * Needed to be able to install inside an ldom from an iso image. |
| 136 | */ |
| 137 | static int vdc_ioctl(struct block_device *bdev, fmode_t mode, |
| 138 | unsigned command, unsigned long argument) |
| 139 | { |
| 140 | int i; |
| 141 | struct gendisk *disk; |
| 142 | |
| 143 | switch (command) { |
| 144 | case CDROMMULTISESSION: |
| 145 | pr_debug(PFX "Multisession CDs not supported\n"); |
| 146 | for (i = 0; i < sizeof(struct cdrom_multisession); i++) |
| 147 | if (put_user(0, (char __user *)(argument + i))) |
| 148 | return -EFAULT; |
| 149 | return 0; |
| 150 | |
| 151 | case CDROM_GET_CAPABILITY: |
| 152 | disk = bdev->bd_disk; |
| 153 | |
| 154 | if (bdev->bd_disk && (disk->flags & GENHD_FL_CD)) |
| 155 | return 0; |
| 156 | return -EINVAL; |
| 157 | |
| 158 | default: |
| 159 | pr_debug(PFX "ioctl %08x not supported\n", command); |
| 160 | return -EINVAL; |
| 161 | } |
| 162 | } |
| 163 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 164 | static const struct block_device_operations vdc_fops = { |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 165 | .owner = THIS_MODULE, |
| 166 | .getgeo = vdc_getgeo, |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 167 | .ioctl = vdc_ioctl, |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 168 | }; |
| 169 | |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 170 | static void vdc_blk_queue_start(struct vdc_port *port) |
| 171 | { |
| 172 | struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING]; |
| 173 | |
| 174 | /* restart blk queue when ring is half emptied. also called after |
| 175 | * handshake completes, so check for initial handshake before we've |
| 176 | * allocated a disk. |
| 177 | */ |
| 178 | if (port->disk && blk_queue_stopped(port->disk->queue) && |
| 179 | vdc_tx_dring_avail(dr) * 100 / VDC_TX_RING_SIZE >= 50) { |
| 180 | blk_start_queue(port->disk->queue); |
| 181 | } |
| 182 | |
| 183 | } |
| 184 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 185 | static void vdc_finish(struct vio_driver_state *vio, int err, int waiting_for) |
| 186 | { |
| 187 | if (vio->cmp && |
| 188 | (waiting_for == -1 || |
| 189 | vio->cmp->waiting_for == waiting_for)) { |
| 190 | vio->cmp->err = err; |
| 191 | complete(&vio->cmp->com); |
| 192 | vio->cmp = NULL; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | static void vdc_handshake_complete(struct vio_driver_state *vio) |
| 197 | { |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 198 | struct vdc_port *port = to_vdc_port(vio); |
| 199 | |
| 200 | del_timer(&port->ldc_reset_timer); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 201 | vdc_finish(vio, 0, WAITING_FOR_LINK_UP); |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 202 | vdc_blk_queue_start(port); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | static int vdc_handle_unknown(struct vdc_port *port, void *arg) |
| 206 | { |
| 207 | struct vio_msg_tag *pkt = arg; |
| 208 | |
| 209 | printk(KERN_ERR PFX "Received unknown msg [%02x:%02x:%04x:%08x]\n", |
| 210 | pkt->type, pkt->stype, pkt->stype_env, pkt->sid); |
| 211 | printk(KERN_ERR PFX "Resetting connection.\n"); |
| 212 | |
| 213 | ldc_disconnect(port->vio.lp); |
| 214 | |
| 215 | return -ECONNRESET; |
| 216 | } |
| 217 | |
| 218 | static int vdc_send_attr(struct vio_driver_state *vio) |
| 219 | { |
| 220 | struct vdc_port *port = to_vdc_port(vio); |
| 221 | struct vio_disk_attr_info pkt; |
| 222 | |
| 223 | memset(&pkt, 0, sizeof(pkt)); |
| 224 | |
| 225 | pkt.tag.type = VIO_TYPE_CTRL; |
| 226 | pkt.tag.stype = VIO_SUBTYPE_INFO; |
| 227 | pkt.tag.stype_env = VIO_ATTR_INFO; |
| 228 | pkt.tag.sid = vio_send_sid(vio); |
| 229 | |
| 230 | pkt.xfer_mode = VIO_DRING_MODE; |
| 231 | pkt.vdisk_block_size = port->vdisk_block_size; |
| 232 | pkt.max_xfer_size = port->max_xfer_size; |
| 233 | |
Sam Ravnborg | 3f4528d | 2009-01-06 13:20:38 -0800 | [diff] [blame] | 234 | viodbg(HS, "SEND ATTR xfer_mode[0x%x] blksz[%u] max_xfer[%llu]\n", |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 235 | pkt.xfer_mode, pkt.vdisk_block_size, pkt.max_xfer_size); |
| 236 | |
| 237 | return vio_ldc_send(&port->vio, &pkt, sizeof(pkt)); |
| 238 | } |
| 239 | |
| 240 | static int vdc_handle_attr(struct vio_driver_state *vio, void *arg) |
| 241 | { |
| 242 | struct vdc_port *port = to_vdc_port(vio); |
| 243 | struct vio_disk_attr_info *pkt = arg; |
| 244 | |
Sam Ravnborg | 3f4528d | 2009-01-06 13:20:38 -0800 | [diff] [blame] | 245 | viodbg(HS, "GOT ATTR stype[0x%x] ops[%llx] disk_size[%llu] disk_type[%x] " |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 246 | "mtype[0x%x] xfer_mode[0x%x] blksz[%u] max_xfer[%llu]\n", |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 247 | pkt->tag.stype, pkt->operations, |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 248 | pkt->vdisk_size, pkt->vdisk_type, pkt->vdisk_mtype, |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 249 | pkt->xfer_mode, pkt->vdisk_block_size, |
| 250 | pkt->max_xfer_size); |
| 251 | |
| 252 | if (pkt->tag.stype == VIO_SUBTYPE_ACK) { |
| 253 | switch (pkt->vdisk_type) { |
| 254 | case VD_DISK_TYPE_DISK: |
| 255 | case VD_DISK_TYPE_SLICE: |
| 256 | break; |
| 257 | |
| 258 | default: |
| 259 | printk(KERN_ERR PFX "%s: Bogus vdisk_type 0x%x\n", |
| 260 | vio->name, pkt->vdisk_type); |
| 261 | return -ECONNRESET; |
| 262 | } |
| 263 | |
| 264 | if (pkt->vdisk_block_size > port->vdisk_block_size) { |
| 265 | printk(KERN_ERR PFX "%s: BLOCK size increased " |
| 266 | "%u --> %u\n", |
| 267 | vio->name, |
| 268 | port->vdisk_block_size, pkt->vdisk_block_size); |
| 269 | return -ECONNRESET; |
| 270 | } |
| 271 | |
| 272 | port->operations = pkt->operations; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 273 | port->vdisk_type = pkt->vdisk_type; |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 274 | if (vdc_version_supported(port, 1, 1)) { |
| 275 | port->vdisk_size = pkt->vdisk_size; |
| 276 | port->vdisk_mtype = pkt->vdisk_mtype; |
| 277 | } |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 278 | if (pkt->max_xfer_size < port->max_xfer_size) |
| 279 | port->max_xfer_size = pkt->max_xfer_size; |
| 280 | port->vdisk_block_size = pkt->vdisk_block_size; |
Liam R. Howlett | f41e546 | 2017-02-01 14:09:26 -0500 | [diff] [blame] | 281 | |
| 282 | port->vdisk_phys_blksz = VDC_DEFAULT_BLK_SIZE; |
| 283 | if (vdc_version_supported(port, 1, 2)) |
| 284 | port->vdisk_phys_blksz = pkt->phys_block_size; |
| 285 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 286 | return 0; |
| 287 | } else { |
| 288 | printk(KERN_ERR PFX "%s: Attribute NACK\n", vio->name); |
| 289 | |
| 290 | return -ECONNRESET; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | static void vdc_end_special(struct vdc_port *port, struct vio_disk_desc *desc) |
| 295 | { |
| 296 | int err = desc->status; |
| 297 | |
| 298 | vdc_finish(&port->vio, -err, WAITING_FOR_GEN_CMD); |
| 299 | } |
| 300 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 301 | static void vdc_end_one(struct vdc_port *port, struct vio_dring_state *dr, |
| 302 | unsigned int index) |
| 303 | { |
| 304 | struct vio_disk_desc *desc = vio_dring_entry(dr, index); |
| 305 | struct vdc_req_entry *rqe = &port->rq_arr[index]; |
| 306 | struct request *req; |
| 307 | |
| 308 | if (unlikely(desc->hdr.state != VIO_DESC_DONE)) |
| 309 | return; |
| 310 | |
| 311 | ldc_unmap(port->vio.lp, desc->cookies, desc->ncookies); |
| 312 | desc->hdr.state = VIO_DESC_FREE; |
Dwight Engen | fe47c3c | 2014-12-11 12:26:15 -0500 | [diff] [blame] | 313 | dr->cons = vio_dring_next(dr, index); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 314 | |
| 315 | req = rqe->req; |
| 316 | if (req == NULL) { |
| 317 | vdc_end_special(port, desc); |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | rqe->req = NULL; |
| 322 | |
Christoph Hellwig | 2a842ac | 2017-06-03 09:38:04 +0200 | [diff] [blame] | 323 | __blk_end_request(req, (desc->status ? BLK_STS_IOERR : 0), desc->size); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 324 | |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 325 | vdc_blk_queue_start(port); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static int vdc_ack(struct vdc_port *port, void *msgbuf) |
| 329 | { |
| 330 | struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING]; |
| 331 | struct vio_dring_data *pkt = msgbuf; |
| 332 | |
| 333 | if (unlikely(pkt->dring_ident != dr->ident || |
| 334 | pkt->start_idx != pkt->end_idx || |
| 335 | pkt->start_idx >= VDC_TX_RING_SIZE)) |
| 336 | return 0; |
| 337 | |
| 338 | vdc_end_one(port, dr, pkt->start_idx); |
| 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | static int vdc_nack(struct vdc_port *port, void *msgbuf) |
| 344 | { |
| 345 | /* XXX Implement me XXX */ |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | static void vdc_event(void *arg, int event) |
| 350 | { |
| 351 | struct vdc_port *port = arg; |
| 352 | struct vio_driver_state *vio = &port->vio; |
| 353 | unsigned long flags; |
| 354 | int err; |
| 355 | |
| 356 | spin_lock_irqsave(&vio->lock, flags); |
| 357 | |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 358 | if (unlikely(event == LDC_EVENT_RESET)) { |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 359 | vio_link_state_change(vio, event); |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 360 | queue_work(sunvdc_wq, &port->ldc_reset_work); |
| 361 | goto out; |
| 362 | } |
| 363 | |
| 364 | if (unlikely(event == LDC_EVENT_UP)) { |
| 365 | vio_link_state_change(vio, event); |
| 366 | goto out; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | if (unlikely(event != LDC_EVENT_DATA_READY)) { |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 370 | pr_warn(PFX "Unexpected LDC event %d\n", event); |
| 371 | goto out; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | err = 0; |
| 375 | while (1) { |
| 376 | union { |
| 377 | struct vio_msg_tag tag; |
| 378 | u64 raw[8]; |
| 379 | } msgbuf; |
| 380 | |
| 381 | err = ldc_read(vio->lp, &msgbuf, sizeof(msgbuf)); |
| 382 | if (unlikely(err < 0)) { |
| 383 | if (err == -ECONNRESET) |
| 384 | vio_conn_reset(vio); |
| 385 | break; |
| 386 | } |
| 387 | if (err == 0) |
| 388 | break; |
| 389 | viodbg(DATA, "TAG [%02x:%02x:%04x:%08x]\n", |
| 390 | msgbuf.tag.type, |
| 391 | msgbuf.tag.stype, |
| 392 | msgbuf.tag.stype_env, |
| 393 | msgbuf.tag.sid); |
| 394 | err = vio_validate_sid(vio, &msgbuf.tag); |
| 395 | if (err < 0) |
| 396 | break; |
| 397 | |
| 398 | if (likely(msgbuf.tag.type == VIO_TYPE_DATA)) { |
| 399 | if (msgbuf.tag.stype == VIO_SUBTYPE_ACK) |
| 400 | err = vdc_ack(port, &msgbuf); |
| 401 | else if (msgbuf.tag.stype == VIO_SUBTYPE_NACK) |
| 402 | err = vdc_nack(port, &msgbuf); |
| 403 | else |
| 404 | err = vdc_handle_unknown(port, &msgbuf); |
| 405 | } else if (msgbuf.tag.type == VIO_TYPE_CTRL) { |
| 406 | err = vio_control_pkt_engine(vio, &msgbuf); |
| 407 | } else { |
| 408 | err = vdc_handle_unknown(port, &msgbuf); |
| 409 | } |
| 410 | if (err < 0) |
| 411 | break; |
| 412 | } |
| 413 | if (err < 0) |
| 414 | vdc_finish(&port->vio, err, WAITING_FOR_ANY); |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 415 | out: |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 416 | spin_unlock_irqrestore(&vio->lock, flags); |
| 417 | } |
| 418 | |
| 419 | static int __vdc_tx_trigger(struct vdc_port *port) |
| 420 | { |
| 421 | struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING]; |
| 422 | struct vio_dring_data hdr = { |
| 423 | .tag = { |
| 424 | .type = VIO_TYPE_DATA, |
| 425 | .stype = VIO_SUBTYPE_INFO, |
| 426 | .stype_env = VIO_DRING_DATA, |
| 427 | .sid = vio_send_sid(&port->vio), |
| 428 | }, |
| 429 | .dring_ident = dr->ident, |
| 430 | .start_idx = dr->prod, |
| 431 | .end_idx = dr->prod, |
| 432 | }; |
| 433 | int err, delay; |
| 434 | |
| 435 | hdr.seq = dr->snd_nxt; |
| 436 | delay = 1; |
| 437 | do { |
| 438 | err = vio_ldc_send(&port->vio, &hdr, sizeof(hdr)); |
| 439 | if (err > 0) { |
| 440 | dr->snd_nxt++; |
| 441 | break; |
| 442 | } |
| 443 | udelay(delay); |
| 444 | if ((delay <<= 1) > 128) |
| 445 | delay = 128; |
| 446 | } while (err == -EAGAIN); |
| 447 | |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 448 | if (err == -ENOTCONN) |
| 449 | vdc_ldc_reset(port); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 450 | return err; |
| 451 | } |
| 452 | |
| 453 | static int __send_request(struct request *req) |
| 454 | { |
| 455 | struct vdc_port *port = req->rq_disk->private_data; |
| 456 | struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING]; |
Kees Cook | ff5d1a4 | 2018-10-08 08:46:51 -0700 | [diff] [blame] | 457 | struct scatterlist sg[MAX_RING_COOKIES]; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 458 | struct vdc_req_entry *rqe; |
| 459 | struct vio_disk_desc *desc; |
| 460 | unsigned int map_perm; |
| 461 | int nsg, err, i; |
| 462 | u64 len; |
| 463 | u8 op; |
| 464 | |
Kees Cook | ff5d1a4 | 2018-10-08 08:46:51 -0700 | [diff] [blame] | 465 | if (WARN_ON(port->ring_cookies > MAX_RING_COOKIES)) |
| 466 | return -EINVAL; |
| 467 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 468 | map_perm = LDC_MAP_SHADOW | LDC_MAP_DIRECT | LDC_MAP_IO; |
| 469 | |
| 470 | if (rq_data_dir(req) == READ) { |
| 471 | map_perm |= LDC_MAP_W; |
| 472 | op = VD_OP_BREAD; |
| 473 | } else { |
| 474 | map_perm |= LDC_MAP_R; |
| 475 | op = VD_OP_BWRITE; |
| 476 | } |
| 477 | |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 478 | sg_init_table(sg, port->ring_cookies); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 479 | nsg = blk_rq_map_sg(req->q, req, sg); |
| 480 | |
| 481 | len = 0; |
| 482 | for (i = 0; i < nsg; i++) |
| 483 | len += sg[i].length; |
| 484 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 485 | desc = vio_dring_cur(dr); |
| 486 | |
| 487 | err = ldc_map_sg(port->vio.lp, sg, nsg, |
| 488 | desc->cookies, port->ring_cookies, |
| 489 | map_perm); |
| 490 | if (err < 0) { |
| 491 | printk(KERN_ERR PFX "ldc_map_sg() failure, err=%d.\n", err); |
| 492 | return err; |
| 493 | } |
| 494 | |
| 495 | rqe = &port->rq_arr[dr->prod]; |
| 496 | rqe->req = req; |
| 497 | |
| 498 | desc->hdr.ack = VIO_ACK_ENABLE; |
| 499 | desc->req_id = port->req_id; |
| 500 | desc->operation = op; |
| 501 | if (port->vdisk_type == VD_DISK_TYPE_DISK) { |
David S. Miller | 1bd4b28 | 2007-08-24 22:05:44 -0700 | [diff] [blame] | 502 | desc->slice = 0xff; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 503 | } else { |
| 504 | desc->slice = 0; |
| 505 | } |
| 506 | desc->status = ~0; |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 507 | desc->offset = (blk_rq_pos(req) << 9) / port->vdisk_block_size; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 508 | desc->size = len; |
| 509 | desc->ncookies = err; |
| 510 | |
| 511 | /* This has to be a non-SMP write barrier because we are writing |
| 512 | * to memory which is shared with the peer LDOM. |
| 513 | */ |
| 514 | wmb(); |
| 515 | desc->hdr.state = VIO_DESC_READY; |
| 516 | |
| 517 | err = __vdc_tx_trigger(port); |
| 518 | if (err < 0) { |
| 519 | printk(KERN_ERR PFX "vdc_tx_trigger() failure, err=%d\n", err); |
| 520 | } else { |
| 521 | port->req_id++; |
Dwight Engen | fe47c3c | 2014-12-11 12:26:15 -0500 | [diff] [blame] | 522 | dr->prod = vio_dring_next(dr, dr->prod); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 523 | } |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 524 | |
| 525 | return err; |
| 526 | } |
| 527 | |
Dwight Engen | d0aedcd | 2014-09-19 09:43:02 -0400 | [diff] [blame] | 528 | static void do_vdc_request(struct request_queue *rq) |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 529 | { |
Dwight Engen | d0aedcd | 2014-09-19 09:43:02 -0400 | [diff] [blame] | 530 | struct request *req; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 531 | |
Dwight Engen | d0aedcd | 2014-09-19 09:43:02 -0400 | [diff] [blame] | 532 | while ((req = blk_peek_request(rq)) != NULL) { |
| 533 | struct vdc_port *port; |
| 534 | struct vio_dring_state *dr; |
| 535 | |
| 536 | port = req->rq_disk->private_data; |
| 537 | dr = &port->vio.drings[VIO_DRIVER_TX_RING]; |
| 538 | if (unlikely(vdc_tx_dring_avail(dr) < 1)) |
| 539 | goto wait; |
| 540 | |
| 541 | blk_start_request(req); |
| 542 | |
| 543 | if (__send_request(req) < 0) { |
| 544 | blk_requeue_request(rq, req); |
| 545 | wait: |
| 546 | /* Avoid pointless unplugs. */ |
| 547 | blk_stop_queue(rq); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 548 | break; |
Dwight Engen | d0aedcd | 2014-09-19 09:43:02 -0400 | [diff] [blame] | 549 | } |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
| 553 | static int generic_request(struct vdc_port *port, u8 op, void *buf, int len) |
| 554 | { |
| 555 | struct vio_dring_state *dr; |
| 556 | struct vio_completion comp; |
| 557 | struct vio_disk_desc *desc; |
| 558 | unsigned int map_perm; |
| 559 | unsigned long flags; |
| 560 | int op_len, err; |
| 561 | void *req_buf; |
| 562 | |
David S. Miller | f4d9605 | 2013-02-14 11:49:01 -0800 | [diff] [blame] | 563 | if (!(((u64)1 << (u64)op) & port->operations)) |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 564 | return -EOPNOTSUPP; |
| 565 | |
| 566 | switch (op) { |
| 567 | case VD_OP_BREAD: |
| 568 | case VD_OP_BWRITE: |
| 569 | default: |
| 570 | return -EINVAL; |
| 571 | |
| 572 | case VD_OP_FLUSH: |
| 573 | op_len = 0; |
| 574 | map_perm = 0; |
| 575 | break; |
| 576 | |
| 577 | case VD_OP_GET_WCE: |
| 578 | op_len = sizeof(u32); |
| 579 | map_perm = LDC_MAP_W; |
| 580 | break; |
| 581 | |
| 582 | case VD_OP_SET_WCE: |
| 583 | op_len = sizeof(u32); |
| 584 | map_perm = LDC_MAP_R; |
| 585 | break; |
| 586 | |
| 587 | case VD_OP_GET_VTOC: |
| 588 | op_len = sizeof(struct vio_disk_vtoc); |
| 589 | map_perm = LDC_MAP_W; |
| 590 | break; |
| 591 | |
| 592 | case VD_OP_SET_VTOC: |
| 593 | op_len = sizeof(struct vio_disk_vtoc); |
| 594 | map_perm = LDC_MAP_R; |
| 595 | break; |
| 596 | |
| 597 | case VD_OP_GET_DISKGEOM: |
| 598 | op_len = sizeof(struct vio_disk_geom); |
| 599 | map_perm = LDC_MAP_W; |
| 600 | break; |
| 601 | |
| 602 | case VD_OP_SET_DISKGEOM: |
| 603 | op_len = sizeof(struct vio_disk_geom); |
| 604 | map_perm = LDC_MAP_R; |
| 605 | break; |
| 606 | |
| 607 | case VD_OP_SCSICMD: |
| 608 | op_len = 16; |
| 609 | map_perm = LDC_MAP_RW; |
| 610 | break; |
| 611 | |
| 612 | case VD_OP_GET_DEVID: |
| 613 | op_len = sizeof(struct vio_disk_devid); |
| 614 | map_perm = LDC_MAP_W; |
| 615 | break; |
| 616 | |
| 617 | case VD_OP_GET_EFI: |
| 618 | case VD_OP_SET_EFI: |
| 619 | return -EOPNOTSUPP; |
| 620 | break; |
| 621 | }; |
| 622 | |
| 623 | map_perm |= LDC_MAP_SHADOW | LDC_MAP_DIRECT | LDC_MAP_IO; |
| 624 | |
| 625 | op_len = (op_len + 7) & ~7; |
| 626 | req_buf = kzalloc(op_len, GFP_KERNEL); |
| 627 | if (!req_buf) |
| 628 | return -ENOMEM; |
| 629 | |
| 630 | if (len > op_len) |
| 631 | len = op_len; |
| 632 | |
| 633 | if (map_perm & LDC_MAP_R) |
| 634 | memcpy(req_buf, buf, len); |
| 635 | |
| 636 | spin_lock_irqsave(&port->vio.lock, flags); |
| 637 | |
| 638 | dr = &port->vio.drings[VIO_DRIVER_TX_RING]; |
| 639 | |
| 640 | /* XXX If we want to use this code generically we have to |
| 641 | * XXX handle TX ring exhaustion etc. |
| 642 | */ |
| 643 | desc = vio_dring_cur(dr); |
| 644 | |
| 645 | err = ldc_map_single(port->vio.lp, req_buf, op_len, |
| 646 | desc->cookies, port->ring_cookies, |
| 647 | map_perm); |
| 648 | if (err < 0) { |
| 649 | spin_unlock_irqrestore(&port->vio.lock, flags); |
| 650 | kfree(req_buf); |
| 651 | return err; |
| 652 | } |
| 653 | |
| 654 | init_completion(&comp.com); |
| 655 | comp.waiting_for = WAITING_FOR_GEN_CMD; |
| 656 | port->vio.cmp = ∁ |
| 657 | |
| 658 | desc->hdr.ack = VIO_ACK_ENABLE; |
| 659 | desc->req_id = port->req_id; |
| 660 | desc->operation = op; |
| 661 | desc->slice = 0; |
| 662 | desc->status = ~0; |
| 663 | desc->offset = 0; |
| 664 | desc->size = op_len; |
| 665 | desc->ncookies = err; |
| 666 | |
| 667 | /* This has to be a non-SMP write barrier because we are writing |
| 668 | * to memory which is shared with the peer LDOM. |
| 669 | */ |
| 670 | wmb(); |
| 671 | desc->hdr.state = VIO_DESC_READY; |
| 672 | |
| 673 | err = __vdc_tx_trigger(port); |
| 674 | if (err >= 0) { |
| 675 | port->req_id++; |
Dwight Engen | fe47c3c | 2014-12-11 12:26:15 -0500 | [diff] [blame] | 676 | dr->prod = vio_dring_next(dr, dr->prod); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 677 | spin_unlock_irqrestore(&port->vio.lock, flags); |
| 678 | |
| 679 | wait_for_completion(&comp.com); |
| 680 | err = comp.err; |
| 681 | } else { |
| 682 | port->vio.cmp = NULL; |
| 683 | spin_unlock_irqrestore(&port->vio.lock, flags); |
| 684 | } |
| 685 | |
| 686 | if (map_perm & LDC_MAP_W) |
| 687 | memcpy(buf, req_buf, len); |
| 688 | |
| 689 | kfree(req_buf); |
| 690 | |
| 691 | return err; |
| 692 | } |
| 693 | |
Greg Kroah-Hartman | 8d85fce | 2012-12-21 15:13:49 -0800 | [diff] [blame] | 694 | static int vdc_alloc_tx_ring(struct vdc_port *port) |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 695 | { |
| 696 | struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING]; |
| 697 | unsigned long len, entry_size; |
| 698 | int ncookies; |
| 699 | void *dring; |
| 700 | |
| 701 | entry_size = sizeof(struct vio_disk_desc) + |
| 702 | (sizeof(struct ldc_trans_cookie) * port->ring_cookies); |
| 703 | len = (VDC_TX_RING_SIZE * entry_size); |
| 704 | |
| 705 | ncookies = VIO_MAX_RING_COOKIES; |
| 706 | dring = ldc_alloc_exp_dring(port->vio.lp, len, |
| 707 | dr->cookies, &ncookies, |
| 708 | (LDC_MAP_SHADOW | |
| 709 | LDC_MAP_DIRECT | |
| 710 | LDC_MAP_RW)); |
| 711 | if (IS_ERR(dring)) |
| 712 | return PTR_ERR(dring); |
| 713 | |
| 714 | dr->base = dring; |
| 715 | dr->entry_size = entry_size; |
| 716 | dr->num_entries = VDC_TX_RING_SIZE; |
| 717 | dr->prod = dr->cons = 0; |
| 718 | dr->pending = VDC_TX_RING_SIZE; |
| 719 | dr->ncookies = ncookies; |
| 720 | |
| 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | static void vdc_free_tx_ring(struct vdc_port *port) |
| 725 | { |
| 726 | struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING]; |
| 727 | |
| 728 | if (dr->base) { |
| 729 | ldc_free_exp_dring(port->vio.lp, dr->base, |
| 730 | (dr->entry_size * dr->num_entries), |
| 731 | dr->cookies, dr->ncookies); |
| 732 | dr->base = NULL; |
| 733 | dr->entry_size = 0; |
| 734 | dr->num_entries = 0; |
| 735 | dr->pending = 0; |
| 736 | dr->ncookies = 0; |
| 737 | } |
| 738 | } |
| 739 | |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 740 | static int vdc_port_up(struct vdc_port *port) |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 741 | { |
| 742 | struct vio_completion comp; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 743 | |
| 744 | init_completion(&comp.com); |
| 745 | comp.err = 0; |
| 746 | comp.waiting_for = WAITING_FOR_LINK_UP; |
| 747 | port->vio.cmp = ∁ |
| 748 | |
| 749 | vio_port_up(&port->vio); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 750 | wait_for_completion(&comp.com); |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 751 | return comp.err; |
| 752 | } |
| 753 | |
| 754 | static void vdc_port_down(struct vdc_port *port) |
| 755 | { |
| 756 | ldc_disconnect(port->vio.lp); |
| 757 | ldc_unbind(port->vio.lp); |
| 758 | vdc_free_tx_ring(port); |
| 759 | vio_ldc_free(&port->vio); |
| 760 | } |
| 761 | |
| 762 | static int probe_disk(struct vdc_port *port) |
| 763 | { |
| 764 | struct request_queue *q; |
| 765 | struct gendisk *g; |
| 766 | int err; |
| 767 | |
| 768 | err = vdc_port_up(port); |
| 769 | if (err) |
| 770 | return err; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 771 | |
Liam R. Howlett | f41e546 | 2017-02-01 14:09:26 -0500 | [diff] [blame] | 772 | /* Using version 1.2 means vdisk_phys_blksz should be set unless the |
| 773 | * disk is reserved by another system. |
| 774 | */ |
| 775 | if (vdc_version_supported(port, 1, 2) && !port->vdisk_phys_blksz) |
| 776 | return -ENODEV; |
| 777 | |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 778 | if (vdc_version_supported(port, 1, 1)) { |
| 779 | /* vdisk_size should be set during the handshake, if it wasn't |
| 780 | * then the underlying disk is reserved by another system |
| 781 | */ |
| 782 | if (port->vdisk_size == -1) |
| 783 | return -ENODEV; |
| 784 | } else { |
Allen Pais | de5b73f | 2014-09-19 09:42:26 -0400 | [diff] [blame] | 785 | struct vio_disk_geom geom; |
| 786 | |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 787 | err = generic_request(port, VD_OP_GET_DISKGEOM, |
Allen Pais | de5b73f | 2014-09-19 09:42:26 -0400 | [diff] [blame] | 788 | &geom, sizeof(geom)); |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 789 | if (err < 0) { |
| 790 | printk(KERN_ERR PFX "VD_OP_GET_DISKGEOM returns " |
| 791 | "error %d\n", err); |
| 792 | return err; |
| 793 | } |
Allen Pais | de5b73f | 2014-09-19 09:42:26 -0400 | [diff] [blame] | 794 | port->vdisk_size = ((u64)geom.num_cyl * |
| 795 | (u64)geom.num_hd * |
| 796 | (u64)geom.num_sec); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 797 | } |
| 798 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 799 | q = blk_init_queue(do_vdc_request, &port->vio.lock); |
| 800 | if (!q) { |
| 801 | printk(KERN_ERR PFX "%s: Could not allocate queue.\n", |
| 802 | port->vio.name); |
| 803 | return -ENOMEM; |
| 804 | } |
| 805 | g = alloc_disk(1 << PARTITION_SHIFT); |
| 806 | if (!g) { |
| 807 | printk(KERN_ERR PFX "%s: Could not allocate gendisk.\n", |
| 808 | port->vio.name); |
| 809 | blk_cleanup_queue(q); |
| 810 | return -ENOMEM; |
| 811 | } |
| 812 | |
| 813 | port->disk = g; |
| 814 | |
Dwight Engen | 5eed69f | 2014-09-19 09:42:53 -0400 | [diff] [blame] | 815 | /* Each segment in a request is up to an aligned page in size. */ |
| 816 | blk_queue_segment_boundary(q, PAGE_SIZE - 1); |
| 817 | blk_queue_max_segment_size(q, PAGE_SIZE); |
| 818 | |
Martin K. Petersen | 8a78362 | 2010-02-26 00:20:39 -0500 | [diff] [blame] | 819 | blk_queue_max_segments(q, port->ring_cookies); |
Martin K. Petersen | 086fa5f | 2010-02-26 00:20:38 -0500 | [diff] [blame] | 820 | blk_queue_max_hw_sectors(q, port->max_xfer_size); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 821 | g->major = vdc_major; |
David S. Miller | 91ba3c2 | 2007-07-18 15:15:45 -0700 | [diff] [blame] | 822 | g->first_minor = port->vio.vdev->dev_no << PARTITION_SHIFT; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 823 | strcpy(g->disk_name, port->disk_name); |
| 824 | |
| 825 | g->fops = &vdc_fops; |
| 826 | g->queue = q; |
| 827 | g->private_data = port; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 828 | |
| 829 | set_capacity(g, port->vdisk_size); |
| 830 | |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 831 | if (vdc_version_supported(port, 1, 1)) { |
| 832 | switch (port->vdisk_mtype) { |
| 833 | case VD_MEDIA_TYPE_CD: |
| 834 | pr_info(PFX "Virtual CDROM %s\n", port->disk_name); |
| 835 | g->flags |= GENHD_FL_CD; |
| 836 | g->flags |= GENHD_FL_REMOVABLE; |
| 837 | set_disk_ro(g, 1); |
| 838 | break; |
| 839 | |
| 840 | case VD_MEDIA_TYPE_DVD: |
| 841 | pr_info(PFX "Virtual DVD %s\n", port->disk_name); |
| 842 | g->flags |= GENHD_FL_CD; |
| 843 | g->flags |= GENHD_FL_REMOVABLE; |
| 844 | set_disk_ro(g, 1); |
| 845 | break; |
| 846 | |
| 847 | case VD_MEDIA_TYPE_FIXED: |
| 848 | pr_info(PFX "Virtual Hard disk %s\n", port->disk_name); |
| 849 | break; |
| 850 | } |
| 851 | } |
| 852 | |
Liam R. Howlett | f41e546 | 2017-02-01 14:09:26 -0500 | [diff] [blame] | 853 | blk_queue_physical_block_size(q, port->vdisk_phys_blksz); |
| 854 | |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 855 | pr_info(PFX "%s: %u sectors (%u MB) protocol %d.%d\n", |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 856 | g->disk_name, |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 857 | port->vdisk_size, (port->vdisk_size >> (20 - 9)), |
| 858 | port->vio.ver.major, port->vio.ver.minor); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 859 | |
Dan Williams | 0d52c756 | 2016-06-15 19:44:20 -0700 | [diff] [blame] | 860 | device_add_disk(&port->vio.vdev->dev, g); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 861 | |
| 862 | return 0; |
| 863 | } |
| 864 | |
| 865 | static struct ldc_channel_config vdc_ldc_cfg = { |
| 866 | .event = vdc_event, |
| 867 | .mtu = 64, |
| 868 | .mode = LDC_MODE_UNRELIABLE, |
| 869 | }; |
| 870 | |
| 871 | static struct vio_driver_ops vdc_vio_ops = { |
| 872 | .send_attr = vdc_send_attr, |
| 873 | .handle_attr = vdc_handle_attr, |
| 874 | .handshake_complete = vdc_handshake_complete, |
| 875 | }; |
| 876 | |
Greg Kroah-Hartman | 8d85fce | 2012-12-21 15:13:49 -0800 | [diff] [blame] | 877 | static void print_version(void) |
David S. Miller | 80dc35d | 2007-07-17 21:46:00 -0700 | [diff] [blame] | 878 | { |
| 879 | static int version_printed; |
| 880 | |
| 881 | if (version_printed++ == 0) |
| 882 | printk(KERN_INFO "%s", version); |
| 883 | } |
| 884 | |
Jim Quigley | 3ee7059 | 2017-07-21 09:20:15 -0400 | [diff] [blame] | 885 | struct vdc_check_port_data { |
| 886 | int dev_no; |
| 887 | char *type; |
| 888 | }; |
| 889 | |
| 890 | static int vdc_device_probed(struct device *dev, void *arg) |
| 891 | { |
| 892 | struct vio_dev *vdev = to_vio_dev(dev); |
| 893 | struct vdc_check_port_data *port_data; |
| 894 | |
| 895 | port_data = (struct vdc_check_port_data *)arg; |
| 896 | |
| 897 | if ((vdev->dev_no == port_data->dev_no) && |
| 898 | (!(strcmp((char *)&vdev->type, port_data->type))) && |
| 899 | dev_get_drvdata(dev)) { |
| 900 | /* This device has already been configured |
| 901 | * by vdc_port_probe() |
| 902 | */ |
| 903 | return 1; |
| 904 | } else { |
| 905 | return 0; |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | /* Determine whether the VIO device is part of an mpgroup |
| 910 | * by locating all the virtual-device-port nodes associated |
| 911 | * with the parent virtual-device node for the VIO device |
| 912 | * and checking whether any of these nodes are vdc-ports |
| 913 | * which have already been configured. |
| 914 | * |
| 915 | * Returns true if this device is part of an mpgroup and has |
| 916 | * already been probed. |
| 917 | */ |
| 918 | static bool vdc_port_mpgroup_check(struct vio_dev *vdev) |
| 919 | { |
| 920 | struct vdc_check_port_data port_data; |
| 921 | struct device *dev; |
| 922 | |
| 923 | port_data.dev_no = vdev->dev_no; |
| 924 | port_data.type = (char *)&vdev->type; |
| 925 | |
| 926 | dev = device_find_child(vdev->dev.parent, &port_data, |
| 927 | vdc_device_probed); |
| 928 | |
| 929 | if (dev) |
| 930 | return true; |
| 931 | |
| 932 | return false; |
| 933 | } |
| 934 | |
Greg Kroah-Hartman | 8d85fce | 2012-12-21 15:13:49 -0800 | [diff] [blame] | 935 | static int vdc_port_probe(struct vio_dev *vdev, const struct vio_device_id *id) |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 936 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 937 | struct mdesc_handle *hp; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 938 | struct vdc_port *port; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 939 | int err; |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 940 | const u64 *ldc_timeout; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 941 | |
David S. Miller | 80dc35d | 2007-07-17 21:46:00 -0700 | [diff] [blame] | 942 | print_version(); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 943 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 944 | hp = mdesc_grab(); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 945 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 946 | err = -ENODEV; |
David S. Miller | 91ba3c2 | 2007-07-18 15:15:45 -0700 | [diff] [blame] | 947 | if ((vdev->dev_no << PARTITION_SHIFT) & ~(u64)MINORMASK) { |
Sam Ravnborg | 3f4528d | 2009-01-06 13:20:38 -0800 | [diff] [blame] | 948 | printk(KERN_ERR PFX "Port id [%llu] too large.\n", |
David S. Miller | 91ba3c2 | 2007-07-18 15:15:45 -0700 | [diff] [blame] | 949 | vdev->dev_no); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 950 | goto err_out_release_mdesc; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 951 | } |
| 952 | |
Jim Quigley | 3ee7059 | 2017-07-21 09:20:15 -0400 | [diff] [blame] | 953 | /* Check if this device is part of an mpgroup */ |
| 954 | if (vdc_port_mpgroup_check(vdev)) { |
| 955 | printk(KERN_WARNING |
| 956 | "VIO: Ignoring extra vdisk port %s", |
| 957 | dev_name(&vdev->dev)); |
| 958 | goto err_out_release_mdesc; |
| 959 | } |
| 960 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 961 | port = kzalloc(sizeof(*port), GFP_KERNEL); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 962 | err = -ENOMEM; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 963 | if (!port) { |
| 964 | printk(KERN_ERR PFX "Cannot allocate vdc_port.\n"); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 965 | goto err_out_release_mdesc; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 966 | } |
| 967 | |
David S. Miller | 91ba3c2 | 2007-07-18 15:15:45 -0700 | [diff] [blame] | 968 | if (vdev->dev_no >= 26) |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 969 | snprintf(port->disk_name, sizeof(port->disk_name), |
| 970 | VDCBLK_NAME "%c%c", |
David S. Miller | 91ba3c2 | 2007-07-18 15:15:45 -0700 | [diff] [blame] | 971 | 'a' + ((int)vdev->dev_no / 26) - 1, |
| 972 | 'a' + ((int)vdev->dev_no % 26)); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 973 | else |
| 974 | snprintf(port->disk_name, sizeof(port->disk_name), |
David S. Miller | 91ba3c2 | 2007-07-18 15:15:45 -0700 | [diff] [blame] | 975 | VDCBLK_NAME "%c", 'a' + ((int)vdev->dev_no % 26)); |
Allen Pais | 9bce218 | 2014-09-19 09:42:14 -0400 | [diff] [blame] | 976 | port->vdisk_size = -1; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 977 | |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 978 | /* Actual wall time may be double due to do_generic_file_read() doing |
| 979 | * a readahead I/O first, and once that fails it will try to read a |
| 980 | * single page. |
| 981 | */ |
| 982 | ldc_timeout = mdesc_get_property(hp, vdev->mp, "vdc-timeout", NULL); |
| 983 | port->ldc_timeout = ldc_timeout ? *ldc_timeout : 0; |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 984 | timer_setup(&port->ldc_reset_timer, vdc_ldc_reset_timer, 0); |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 985 | INIT_WORK(&port->ldc_reset_work, vdc_ldc_reset_work); |
| 986 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 987 | err = vio_driver_init(&port->vio, vdev, VDEV_DISK, |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 988 | vdc_versions, ARRAY_SIZE(vdc_versions), |
| 989 | &vdc_vio_ops, port->disk_name); |
| 990 | if (err) |
| 991 | goto err_out_free_port; |
| 992 | |
Liam R. Howlett | f41e546 | 2017-02-01 14:09:26 -0500 | [diff] [blame] | 993 | port->vdisk_block_size = VDC_DEFAULT_BLK_SIZE; |
Kees Cook | ff5d1a4 | 2018-10-08 08:46:51 -0700 | [diff] [blame] | 994 | port->max_xfer_size = MAX_XFER_SIZE; |
| 995 | port->ring_cookies = MAX_RING_COOKIES; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 996 | |
| 997 | err = vio_ldc_alloc(&port->vio, &vdc_ldc_cfg, port); |
| 998 | if (err) |
| 999 | goto err_out_free_port; |
| 1000 | |
| 1001 | err = vdc_alloc_tx_ring(port); |
| 1002 | if (err) |
| 1003 | goto err_out_free_ldc; |
| 1004 | |
| 1005 | err = probe_disk(port); |
| 1006 | if (err) |
| 1007 | goto err_out_free_tx_ring; |
| 1008 | |
Jim Quigley | 3ee7059 | 2017-07-21 09:20:15 -0400 | [diff] [blame] | 1009 | /* Note that the device driver_data is used to determine |
| 1010 | * whether the port has been probed. |
| 1011 | */ |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1012 | dev_set_drvdata(&vdev->dev, port); |
| 1013 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 1014 | mdesc_release(hp); |
| 1015 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1016 | return 0; |
| 1017 | |
| 1018 | err_out_free_tx_ring: |
| 1019 | vdc_free_tx_ring(port); |
| 1020 | |
| 1021 | err_out_free_ldc: |
| 1022 | vio_ldc_free(&port->vio); |
| 1023 | |
| 1024 | err_out_free_port: |
| 1025 | kfree(port); |
| 1026 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 1027 | err_out_release_mdesc: |
| 1028 | mdesc_release(hp); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1029 | return err; |
| 1030 | } |
| 1031 | |
| 1032 | static int vdc_port_remove(struct vio_dev *vdev) |
| 1033 | { |
| 1034 | struct vdc_port *port = dev_get_drvdata(&vdev->dev); |
| 1035 | |
| 1036 | if (port) { |
Dwight Engen | 31f4888 | 2014-12-11 12:25:42 -0500 | [diff] [blame] | 1037 | unsigned long flags; |
| 1038 | |
| 1039 | spin_lock_irqsave(&port->vio.lock, flags); |
| 1040 | blk_stop_queue(port->disk->queue); |
| 1041 | spin_unlock_irqrestore(&port->vio.lock, flags); |
| 1042 | |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 1043 | flush_work(&port->ldc_reset_work); |
| 1044 | del_timer_sync(&port->ldc_reset_timer); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1045 | del_timer_sync(&port->vio.timer); |
| 1046 | |
Dwight Engen | 31f4888 | 2014-12-11 12:25:42 -0500 | [diff] [blame] | 1047 | del_gendisk(port->disk); |
| 1048 | blk_cleanup_queue(port->disk->queue); |
| 1049 | put_disk(port->disk); |
| 1050 | port->disk = NULL; |
| 1051 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1052 | vdc_free_tx_ring(port); |
| 1053 | vio_ldc_free(&port->vio); |
| 1054 | |
| 1055 | dev_set_drvdata(&vdev->dev, NULL); |
| 1056 | |
| 1057 | kfree(port); |
| 1058 | } |
| 1059 | return 0; |
| 1060 | } |
| 1061 | |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 1062 | static void vdc_requeue_inflight(struct vdc_port *port) |
| 1063 | { |
| 1064 | struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING]; |
| 1065 | u32 idx; |
| 1066 | |
| 1067 | for (idx = dr->cons; idx != dr->prod; idx = vio_dring_next(dr, idx)) { |
| 1068 | struct vio_disk_desc *desc = vio_dring_entry(dr, idx); |
| 1069 | struct vdc_req_entry *rqe = &port->rq_arr[idx]; |
| 1070 | struct request *req; |
| 1071 | |
| 1072 | ldc_unmap(port->vio.lp, desc->cookies, desc->ncookies); |
| 1073 | desc->hdr.state = VIO_DESC_FREE; |
| 1074 | dr->cons = vio_dring_next(dr, idx); |
| 1075 | |
| 1076 | req = rqe->req; |
| 1077 | if (req == NULL) { |
| 1078 | vdc_end_special(port, desc); |
| 1079 | continue; |
| 1080 | } |
| 1081 | |
| 1082 | rqe->req = NULL; |
| 1083 | blk_requeue_request(port->disk->queue, req); |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | static void vdc_queue_drain(struct vdc_port *port) |
| 1088 | { |
| 1089 | struct request *req; |
| 1090 | |
| 1091 | while ((req = blk_fetch_request(port->disk->queue)) != NULL) |
Christoph Hellwig | 2a842ac | 2017-06-03 09:38:04 +0200 | [diff] [blame] | 1092 | __blk_end_request_all(req, BLK_STS_IOERR); |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 1093 | } |
| 1094 | |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 1095 | static void vdc_ldc_reset_timer(struct timer_list *t) |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 1096 | { |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 1097 | struct vdc_port *port = from_timer(port, t, ldc_reset_timer); |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 1098 | struct vio_driver_state *vio = &port->vio; |
| 1099 | unsigned long flags; |
| 1100 | |
| 1101 | spin_lock_irqsave(&vio->lock, flags); |
| 1102 | if (!(port->vio.hs_state & VIO_HS_COMPLETE)) { |
| 1103 | pr_warn(PFX "%s ldc down %llu seconds, draining queue\n", |
| 1104 | port->disk_name, port->ldc_timeout); |
| 1105 | vdc_queue_drain(port); |
| 1106 | vdc_blk_queue_start(port); |
| 1107 | } |
| 1108 | spin_unlock_irqrestore(&vio->lock, flags); |
| 1109 | } |
| 1110 | |
| 1111 | static void vdc_ldc_reset_work(struct work_struct *work) |
| 1112 | { |
| 1113 | struct vdc_port *port; |
| 1114 | struct vio_driver_state *vio; |
| 1115 | unsigned long flags; |
| 1116 | |
| 1117 | port = container_of(work, struct vdc_port, ldc_reset_work); |
| 1118 | vio = &port->vio; |
| 1119 | |
| 1120 | spin_lock_irqsave(&vio->lock, flags); |
| 1121 | vdc_ldc_reset(port); |
| 1122 | spin_unlock_irqrestore(&vio->lock, flags); |
| 1123 | } |
| 1124 | |
| 1125 | static void vdc_ldc_reset(struct vdc_port *port) |
| 1126 | { |
| 1127 | int err; |
| 1128 | |
| 1129 | assert_spin_locked(&port->vio.lock); |
| 1130 | |
| 1131 | pr_warn(PFX "%s ldc link reset\n", port->disk_name); |
| 1132 | blk_stop_queue(port->disk->queue); |
| 1133 | vdc_requeue_inflight(port); |
| 1134 | vdc_port_down(port); |
| 1135 | |
| 1136 | err = vio_ldc_alloc(&port->vio, &vdc_ldc_cfg, port); |
| 1137 | if (err) { |
| 1138 | pr_err(PFX "%s vio_ldc_alloc:%d\n", port->disk_name, err); |
| 1139 | return; |
| 1140 | } |
| 1141 | |
| 1142 | err = vdc_alloc_tx_ring(port); |
| 1143 | if (err) { |
| 1144 | pr_err(PFX "%s vio_alloc_tx_ring:%d\n", port->disk_name, err); |
| 1145 | goto err_free_ldc; |
| 1146 | } |
| 1147 | |
| 1148 | if (port->ldc_timeout) |
| 1149 | mod_timer(&port->ldc_reset_timer, |
| 1150 | round_jiffies(jiffies + HZ * port->ldc_timeout)); |
| 1151 | mod_timer(&port->vio.timer, round_jiffies(jiffies + HZ)); |
| 1152 | return; |
| 1153 | |
| 1154 | err_free_ldc: |
| 1155 | vio_ldc_free(&port->vio); |
| 1156 | } |
| 1157 | |
David S. Miller | 3d452e5 | 2008-09-01 01:48:52 -0700 | [diff] [blame] | 1158 | static const struct vio_device_id vdc_port_match[] = { |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1159 | { |
| 1160 | .type = "vdc-port", |
| 1161 | }, |
| 1162 | {}, |
| 1163 | }; |
Fabio Massimo Di Nitto | da68e08 | 2007-07-18 14:35:23 -0700 | [diff] [blame] | 1164 | MODULE_DEVICE_TABLE(vio, vdc_port_match); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1165 | |
| 1166 | static struct vio_driver vdc_port_driver = { |
| 1167 | .id_table = vdc_port_match, |
| 1168 | .probe = vdc_port_probe, |
| 1169 | .remove = vdc_port_remove, |
Benjamin Herrenschmidt | cb52d89 | 2012-03-26 19:06:30 +0000 | [diff] [blame] | 1170 | .name = "vdc_port", |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1171 | }; |
| 1172 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1173 | static int __init vdc_init(void) |
| 1174 | { |
| 1175 | int err; |
| 1176 | |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 1177 | sunvdc_wq = alloc_workqueue("sunvdc", 0, 0); |
| 1178 | if (!sunvdc_wq) |
| 1179 | return -ENOMEM; |
| 1180 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1181 | err = register_blkdev(0, VDCBLK_NAME); |
| 1182 | if (err < 0) |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 1183 | goto out_free_wq; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1184 | |
| 1185 | vdc_major = err; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1186 | |
| 1187 | err = vio_register_driver(&vdc_port_driver); |
| 1188 | if (err) |
David S. Miller | 80dc35d | 2007-07-17 21:46:00 -0700 | [diff] [blame] | 1189 | goto out_unregister_blkdev; |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1190 | |
| 1191 | return 0; |
| 1192 | |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1193 | out_unregister_blkdev: |
| 1194 | unregister_blkdev(vdc_major, VDCBLK_NAME); |
| 1195 | vdc_major = 0; |
| 1196 | |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 1197 | out_free_wq: |
| 1198 | destroy_workqueue(sunvdc_wq); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1199 | return err; |
| 1200 | } |
| 1201 | |
| 1202 | static void __exit vdc_exit(void) |
| 1203 | { |
| 1204 | vio_unregister_driver(&vdc_port_driver); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1205 | unregister_blkdev(vdc_major, VDCBLK_NAME); |
Dwight Engen | 76e74bb | 2014-12-11 12:26:17 -0500 | [diff] [blame] | 1206 | destroy_workqueue(sunvdc_wq); |
David S. Miller | 667ef3c | 2007-07-16 04:03:56 -0700 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | module_init(vdc_init); |
| 1210 | module_exit(vdc_exit); |