blob: c6d43a2a807dd4c2a032cf2c520db923dc7230b0 [file] [log] [blame]
David S. Miller667ef3c2007-07-16 04:03:56 -07001/* sunvdc.c: Sun LDOM Virtual Disk Client.
2 *
David S. Miller3d452e52008-09-01 01:48:52 -07003 * Copyright (C) 2007, 2008 David S. Miller <davem@davemloft.net>
David S. Miller667ef3c2007-07-16 04:03:56 -07004 */
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 Pais9bce2182014-09-19 09:42:14 -040012#include <linux/cdrom.h>
David S. Miller667ef3c2007-07-16 04:03:56 -070013#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 Millerd91c5e82007-10-24 08:46:01 +020019#include <linux/scatterlist.h>
David S. Miller667ef3c2007-07-16 04:03:56 -070020
21#include <asm/vio.h>
22#include <asm/ldc.h>
23
24#define DRV_MODULE_NAME "sunvdc"
25#define PFX DRV_MODULE_NAME ": "
Dwight Engen76e74bb2014-12-11 12:26:17 -050026#define DRV_MODULE_VERSION "1.2"
27#define DRV_MODULE_RELDATE "November 24, 2014"
David S. Miller667ef3c2007-07-16 04:03:56 -070028
Greg Kroah-Hartman8d85fce2012-12-21 15:13:49 -080029static char version[] =
David S. Miller667ef3c2007-07-16 04:03:56 -070030 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
31MODULE_AUTHOR("David S. Miller (davem@davemloft.net)");
32MODULE_DESCRIPTION("Sun LDOM virtual disk client driver");
33MODULE_LICENSE("GPL");
34MODULE_VERSION(DRV_MODULE_VERSION);
35
Dwight Engend0aedcd2014-09-19 09:43:02 -040036#define VDC_TX_RING_SIZE 512
David S. Miller667ef3c2007-07-16 04:03:56 -070037
38#define WAITING_FOR_LINK_UP 0x01
39#define WAITING_FOR_TX_SPACE 0x02
40#define WAITING_FOR_GEN_CMD 0x04
41#define WAITING_FOR_ANY -1
42
Young Xiaoa1ef7d52018-11-28 12:36:39 +000043#define VDC_MAX_RETRIES 10
44
Dwight Engen76e74bb2014-12-11 12:26:17 -050045static struct workqueue_struct *sunvdc_wq;
46
David S. Miller667ef3c2007-07-16 04:03:56 -070047struct vdc_req_entry {
48 struct request *req;
49};
50
51struct vdc_port {
52 struct vio_driver_state vio;
53
David S. Miller667ef3c2007-07-16 04:03:56 -070054 struct gendisk *disk;
55
56 struct vdc_completion *cmp;
57
58 u64 req_id;
59 u64 seq;
60 struct vdc_req_entry rq_arr[VDC_TX_RING_SIZE];
61
62 unsigned long ring_cookies;
63
64 u64 max_xfer_size;
65 u32 vdisk_block_size;
66
Dwight Engen76e74bb2014-12-11 12:26:17 -050067 u64 ldc_timeout;
68 struct timer_list ldc_reset_timer;
69 struct work_struct ldc_reset_work;
70
David S. Miller667ef3c2007-07-16 04:03:56 -070071 /* The server fills these in for us in the disk attribute
72 * ACK packet.
73 */
74 u64 operations;
75 u32 vdisk_size;
76 u8 vdisk_type;
Allen Pais9bce2182014-09-19 09:42:14 -040077 u8 vdisk_mtype;
David S. Miller667ef3c2007-07-16 04:03:56 -070078
79 char disk_name[32];
David S. Miller667ef3c2007-07-16 04:03:56 -070080};
81
Dwight Engen76e74bb2014-12-11 12:26:17 -050082static void vdc_ldc_reset(struct vdc_port *port);
83static void vdc_ldc_reset_work(struct work_struct *work);
84static void vdc_ldc_reset_timer(unsigned long _arg);
85
David S. Miller667ef3c2007-07-16 04:03:56 -070086static inline struct vdc_port *to_vdc_port(struct vio_driver_state *vio)
87{
88 return container_of(vio, struct vdc_port, vio);
89}
90
David S. Miller667ef3c2007-07-16 04:03:56 -070091/* Ordered from largest major to lowest */
92static struct vio_version vdc_versions[] = {
Allen Pais9bce2182014-09-19 09:42:14 -040093 { .major = 1, .minor = 1 },
David S. Miller667ef3c2007-07-16 04:03:56 -070094 { .major = 1, .minor = 0 },
95};
96
Allen Pais9bce2182014-09-19 09:42:14 -040097static inline int vdc_version_supported(struct vdc_port *port,
98 u16 major, u16 minor)
99{
100 return port->vio.ver.major == major && port->vio.ver.minor >= minor;
101}
102
David S. Miller667ef3c2007-07-16 04:03:56 -0700103#define VDCBLK_NAME "vdisk"
104static int vdc_major;
105#define PARTITION_SHIFT 3
106
107static inline u32 vdc_tx_dring_avail(struct vio_dring_state *dr)
108{
109 return vio_dring_avail(dr, VDC_TX_RING_SIZE);
110}
111
112static int vdc_getgeo(struct block_device *bdev, struct hd_geometry *geo)
113{
114 struct gendisk *disk = bdev->bd_disk;
Allen Paisde5b73f2014-09-19 09:42:26 -0400115 sector_t nsect = get_capacity(disk);
116 sector_t cylinders = nsect;
David S. Miller667ef3c2007-07-16 04:03:56 -0700117
Allen Paisde5b73f2014-09-19 09:42:26 -0400118 geo->heads = 0xff;
119 geo->sectors = 0x3f;
120 sector_div(cylinders, geo->heads * geo->sectors);
121 geo->cylinders = cylinders;
122 if ((sector_t)(geo->cylinders + 1) * geo->heads * geo->sectors < nsect)
123 geo->cylinders = 0xffff;
David S. Miller667ef3c2007-07-16 04:03:56 -0700124
125 return 0;
126}
127
Allen Pais9bce2182014-09-19 09:42:14 -0400128/* Add ioctl/CDROM_GET_CAPABILITY to support cdrom_id in udev
129 * when vdisk_mtype is VD_MEDIA_TYPE_CD or VD_MEDIA_TYPE_DVD.
130 * Needed to be able to install inside an ldom from an iso image.
131 */
132static int vdc_ioctl(struct block_device *bdev, fmode_t mode,
133 unsigned command, unsigned long argument)
134{
135 int i;
136 struct gendisk *disk;
137
138 switch (command) {
139 case CDROMMULTISESSION:
140 pr_debug(PFX "Multisession CDs not supported\n");
141 for (i = 0; i < sizeof(struct cdrom_multisession); i++)
142 if (put_user(0, (char __user *)(argument + i)))
143 return -EFAULT;
144 return 0;
145
146 case CDROM_GET_CAPABILITY:
147 disk = bdev->bd_disk;
148
149 if (bdev->bd_disk && (disk->flags & GENHD_FL_CD))
150 return 0;
151 return -EINVAL;
152
153 default:
154 pr_debug(PFX "ioctl %08x not supported\n", command);
155 return -EINVAL;
156 }
157}
158
Alexey Dobriyan83d5cde2009-09-21 17:01:13 -0700159static const struct block_device_operations vdc_fops = {
David S. Miller667ef3c2007-07-16 04:03:56 -0700160 .owner = THIS_MODULE,
161 .getgeo = vdc_getgeo,
Allen Pais9bce2182014-09-19 09:42:14 -0400162 .ioctl = vdc_ioctl,
David S. Miller667ef3c2007-07-16 04:03:56 -0700163};
164
Dwight Engen76e74bb2014-12-11 12:26:17 -0500165static void vdc_blk_queue_start(struct vdc_port *port)
166{
167 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
168
169 /* restart blk queue when ring is half emptied. also called after
170 * handshake completes, so check for initial handshake before we've
171 * allocated a disk.
172 */
173 if (port->disk && blk_queue_stopped(port->disk->queue) &&
174 vdc_tx_dring_avail(dr) * 100 / VDC_TX_RING_SIZE >= 50) {
175 blk_start_queue(port->disk->queue);
176 }
177
178}
179
David S. Miller667ef3c2007-07-16 04:03:56 -0700180static void vdc_finish(struct vio_driver_state *vio, int err, int waiting_for)
181{
182 if (vio->cmp &&
183 (waiting_for == -1 ||
184 vio->cmp->waiting_for == waiting_for)) {
185 vio->cmp->err = err;
186 complete(&vio->cmp->com);
187 vio->cmp = NULL;
188 }
189}
190
191static void vdc_handshake_complete(struct vio_driver_state *vio)
192{
Dwight Engen76e74bb2014-12-11 12:26:17 -0500193 struct vdc_port *port = to_vdc_port(vio);
194
195 del_timer(&port->ldc_reset_timer);
David S. Miller667ef3c2007-07-16 04:03:56 -0700196 vdc_finish(vio, 0, WAITING_FOR_LINK_UP);
Dwight Engen76e74bb2014-12-11 12:26:17 -0500197 vdc_blk_queue_start(port);
David S. Miller667ef3c2007-07-16 04:03:56 -0700198}
199
200static int vdc_handle_unknown(struct vdc_port *port, void *arg)
201{
202 struct vio_msg_tag *pkt = arg;
203
204 printk(KERN_ERR PFX "Received unknown msg [%02x:%02x:%04x:%08x]\n",
205 pkt->type, pkt->stype, pkt->stype_env, pkt->sid);
206 printk(KERN_ERR PFX "Resetting connection.\n");
207
208 ldc_disconnect(port->vio.lp);
209
210 return -ECONNRESET;
211}
212
213static int vdc_send_attr(struct vio_driver_state *vio)
214{
215 struct vdc_port *port = to_vdc_port(vio);
216 struct vio_disk_attr_info pkt;
217
218 memset(&pkt, 0, sizeof(pkt));
219
220 pkt.tag.type = VIO_TYPE_CTRL;
221 pkt.tag.stype = VIO_SUBTYPE_INFO;
222 pkt.tag.stype_env = VIO_ATTR_INFO;
223 pkt.tag.sid = vio_send_sid(vio);
224
225 pkt.xfer_mode = VIO_DRING_MODE;
226 pkt.vdisk_block_size = port->vdisk_block_size;
227 pkt.max_xfer_size = port->max_xfer_size;
228
Sam Ravnborg3f4528d2009-01-06 13:20:38 -0800229 viodbg(HS, "SEND ATTR xfer_mode[0x%x] blksz[%u] max_xfer[%llu]\n",
David S. Miller667ef3c2007-07-16 04:03:56 -0700230 pkt.xfer_mode, pkt.vdisk_block_size, pkt.max_xfer_size);
231
232 return vio_ldc_send(&port->vio, &pkt, sizeof(pkt));
233}
234
235static int vdc_handle_attr(struct vio_driver_state *vio, void *arg)
236{
237 struct vdc_port *port = to_vdc_port(vio);
238 struct vio_disk_attr_info *pkt = arg;
239
Sam Ravnborg3f4528d2009-01-06 13:20:38 -0800240 viodbg(HS, "GOT ATTR stype[0x%x] ops[%llx] disk_size[%llu] disk_type[%x] "
Allen Pais9bce2182014-09-19 09:42:14 -0400241 "mtype[0x%x] xfer_mode[0x%x] blksz[%u] max_xfer[%llu]\n",
David S. Miller667ef3c2007-07-16 04:03:56 -0700242 pkt->tag.stype, pkt->operations,
Allen Pais9bce2182014-09-19 09:42:14 -0400243 pkt->vdisk_size, pkt->vdisk_type, pkt->vdisk_mtype,
David S. Miller667ef3c2007-07-16 04:03:56 -0700244 pkt->xfer_mode, pkt->vdisk_block_size,
245 pkt->max_xfer_size);
246
247 if (pkt->tag.stype == VIO_SUBTYPE_ACK) {
248 switch (pkt->vdisk_type) {
249 case VD_DISK_TYPE_DISK:
250 case VD_DISK_TYPE_SLICE:
251 break;
252
253 default:
254 printk(KERN_ERR PFX "%s: Bogus vdisk_type 0x%x\n",
255 vio->name, pkt->vdisk_type);
256 return -ECONNRESET;
257 }
258
259 if (pkt->vdisk_block_size > port->vdisk_block_size) {
260 printk(KERN_ERR PFX "%s: BLOCK size increased "
261 "%u --> %u\n",
262 vio->name,
263 port->vdisk_block_size, pkt->vdisk_block_size);
264 return -ECONNRESET;
265 }
266
267 port->operations = pkt->operations;
David S. Miller667ef3c2007-07-16 04:03:56 -0700268 port->vdisk_type = pkt->vdisk_type;
Allen Pais9bce2182014-09-19 09:42:14 -0400269 if (vdc_version_supported(port, 1, 1)) {
270 port->vdisk_size = pkt->vdisk_size;
271 port->vdisk_mtype = pkt->vdisk_mtype;
272 }
David S. Miller667ef3c2007-07-16 04:03:56 -0700273 if (pkt->max_xfer_size < port->max_xfer_size)
274 port->max_xfer_size = pkt->max_xfer_size;
275 port->vdisk_block_size = pkt->vdisk_block_size;
276 return 0;
277 } else {
278 printk(KERN_ERR PFX "%s: Attribute NACK\n", vio->name);
279
280 return -ECONNRESET;
281 }
282}
283
284static void vdc_end_special(struct vdc_port *port, struct vio_disk_desc *desc)
285{
286 int err = desc->status;
287
288 vdc_finish(&port->vio, -err, WAITING_FOR_GEN_CMD);
289}
290
David S. Miller667ef3c2007-07-16 04:03:56 -0700291static void vdc_end_one(struct vdc_port *port, struct vio_dring_state *dr,
292 unsigned int index)
293{
294 struct vio_disk_desc *desc = vio_dring_entry(dr, index);
295 struct vdc_req_entry *rqe = &port->rq_arr[index];
296 struct request *req;
297
298 if (unlikely(desc->hdr.state != VIO_DESC_DONE))
299 return;
300
301 ldc_unmap(port->vio.lp, desc->cookies, desc->ncookies);
302 desc->hdr.state = VIO_DESC_FREE;
Dwight Engenfe47c3c2014-12-11 12:26:15 -0500303 dr->cons = vio_dring_next(dr, index);
David S. Miller667ef3c2007-07-16 04:03:56 -0700304
305 req = rqe->req;
306 if (req == NULL) {
307 vdc_end_special(port, desc);
308 return;
309 }
310
311 rqe->req = NULL;
312
Tejun Heo044208502009-04-28 13:06:08 +0900313 __blk_end_request(req, (desc->status ? -EIO : 0), desc->size);
David S. Miller667ef3c2007-07-16 04:03:56 -0700314
Dwight Engen76e74bb2014-12-11 12:26:17 -0500315 vdc_blk_queue_start(port);
David S. Miller667ef3c2007-07-16 04:03:56 -0700316}
317
318static int vdc_ack(struct vdc_port *port, void *msgbuf)
319{
320 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
321 struct vio_dring_data *pkt = msgbuf;
322
323 if (unlikely(pkt->dring_ident != dr->ident ||
324 pkt->start_idx != pkt->end_idx ||
325 pkt->start_idx >= VDC_TX_RING_SIZE))
326 return 0;
327
328 vdc_end_one(port, dr, pkt->start_idx);
329
330 return 0;
331}
332
333static int vdc_nack(struct vdc_port *port, void *msgbuf)
334{
335 /* XXX Implement me XXX */
336 return 0;
337}
338
339static void vdc_event(void *arg, int event)
340{
341 struct vdc_port *port = arg;
342 struct vio_driver_state *vio = &port->vio;
343 unsigned long flags;
344 int err;
345
346 spin_lock_irqsave(&vio->lock, flags);
347
Dwight Engen76e74bb2014-12-11 12:26:17 -0500348 if (unlikely(event == LDC_EVENT_RESET)) {
David S. Miller667ef3c2007-07-16 04:03:56 -0700349 vio_link_state_change(vio, event);
Dwight Engen76e74bb2014-12-11 12:26:17 -0500350 queue_work(sunvdc_wq, &port->ldc_reset_work);
351 goto out;
352 }
353
354 if (unlikely(event == LDC_EVENT_UP)) {
355 vio_link_state_change(vio, event);
356 goto out;
David S. Miller667ef3c2007-07-16 04:03:56 -0700357 }
358
359 if (unlikely(event != LDC_EVENT_DATA_READY)) {
Dwight Engen76e74bb2014-12-11 12:26:17 -0500360 pr_warn(PFX "Unexpected LDC event %d\n", event);
361 goto out;
David S. Miller667ef3c2007-07-16 04:03:56 -0700362 }
363
364 err = 0;
365 while (1) {
366 union {
367 struct vio_msg_tag tag;
368 u64 raw[8];
369 } msgbuf;
370
371 err = ldc_read(vio->lp, &msgbuf, sizeof(msgbuf));
372 if (unlikely(err < 0)) {
373 if (err == -ECONNRESET)
374 vio_conn_reset(vio);
375 break;
376 }
377 if (err == 0)
378 break;
379 viodbg(DATA, "TAG [%02x:%02x:%04x:%08x]\n",
380 msgbuf.tag.type,
381 msgbuf.tag.stype,
382 msgbuf.tag.stype_env,
383 msgbuf.tag.sid);
384 err = vio_validate_sid(vio, &msgbuf.tag);
385 if (err < 0)
386 break;
387
388 if (likely(msgbuf.tag.type == VIO_TYPE_DATA)) {
389 if (msgbuf.tag.stype == VIO_SUBTYPE_ACK)
390 err = vdc_ack(port, &msgbuf);
391 else if (msgbuf.tag.stype == VIO_SUBTYPE_NACK)
392 err = vdc_nack(port, &msgbuf);
393 else
394 err = vdc_handle_unknown(port, &msgbuf);
395 } else if (msgbuf.tag.type == VIO_TYPE_CTRL) {
396 err = vio_control_pkt_engine(vio, &msgbuf);
397 } else {
398 err = vdc_handle_unknown(port, &msgbuf);
399 }
400 if (err < 0)
401 break;
402 }
403 if (err < 0)
404 vdc_finish(&port->vio, err, WAITING_FOR_ANY);
Dwight Engen76e74bb2014-12-11 12:26:17 -0500405out:
David S. Miller667ef3c2007-07-16 04:03:56 -0700406 spin_unlock_irqrestore(&vio->lock, flags);
407}
408
409static int __vdc_tx_trigger(struct vdc_port *port)
410{
411 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
412 struct vio_dring_data hdr = {
413 .tag = {
414 .type = VIO_TYPE_DATA,
415 .stype = VIO_SUBTYPE_INFO,
416 .stype_env = VIO_DRING_DATA,
417 .sid = vio_send_sid(&port->vio),
418 },
419 .dring_ident = dr->ident,
420 .start_idx = dr->prod,
421 .end_idx = dr->prod,
422 };
423 int err, delay;
Young Xiaoa1ef7d52018-11-28 12:36:39 +0000424 int retries = 0;
David S. Miller667ef3c2007-07-16 04:03:56 -0700425
426 hdr.seq = dr->snd_nxt;
427 delay = 1;
428 do {
429 err = vio_ldc_send(&port->vio, &hdr, sizeof(hdr));
430 if (err > 0) {
431 dr->snd_nxt++;
432 break;
433 }
434 udelay(delay);
435 if ((delay <<= 1) > 128)
436 delay = 128;
Young Xiaoa1ef7d52018-11-28 12:36:39 +0000437 if (retries++ > VDC_MAX_RETRIES)
438 break;
David S. Miller667ef3c2007-07-16 04:03:56 -0700439 } while (err == -EAGAIN);
440
Dwight Engen76e74bb2014-12-11 12:26:17 -0500441 if (err == -ENOTCONN)
442 vdc_ldc_reset(port);
David S. Miller667ef3c2007-07-16 04:03:56 -0700443 return err;
444}
445
446static int __send_request(struct request *req)
447{
448 struct vdc_port *port = req->rq_disk->private_data;
449 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
450 struct scatterlist sg[port->ring_cookies];
451 struct vdc_req_entry *rqe;
452 struct vio_disk_desc *desc;
453 unsigned int map_perm;
454 int nsg, err, i;
455 u64 len;
456 u8 op;
457
458 map_perm = LDC_MAP_SHADOW | LDC_MAP_DIRECT | LDC_MAP_IO;
459
460 if (rq_data_dir(req) == READ) {
461 map_perm |= LDC_MAP_W;
462 op = VD_OP_BREAD;
463 } else {
464 map_perm |= LDC_MAP_R;
465 op = VD_OP_BWRITE;
466 }
467
Jens Axboe45711f12007-10-22 21:19:53 +0200468 sg_init_table(sg, port->ring_cookies);
David S. Miller667ef3c2007-07-16 04:03:56 -0700469 nsg = blk_rq_map_sg(req->q, req, sg);
470
471 len = 0;
472 for (i = 0; i < nsg; i++)
473 len += sg[i].length;
474
David S. Miller667ef3c2007-07-16 04:03:56 -0700475 desc = vio_dring_cur(dr);
476
477 err = ldc_map_sg(port->vio.lp, sg, nsg,
478 desc->cookies, port->ring_cookies,
479 map_perm);
480 if (err < 0) {
481 printk(KERN_ERR PFX "ldc_map_sg() failure, err=%d.\n", err);
482 return err;
483 }
484
485 rqe = &port->rq_arr[dr->prod];
486 rqe->req = req;
487
488 desc->hdr.ack = VIO_ACK_ENABLE;
489 desc->req_id = port->req_id;
490 desc->operation = op;
491 if (port->vdisk_type == VD_DISK_TYPE_DISK) {
David S. Miller1bd4b282007-08-24 22:05:44 -0700492 desc->slice = 0xff;
David S. Miller667ef3c2007-07-16 04:03:56 -0700493 } else {
494 desc->slice = 0;
495 }
496 desc->status = ~0;
Tejun Heo83096eb2009-05-07 22:24:39 +0900497 desc->offset = (blk_rq_pos(req) << 9) / port->vdisk_block_size;
David S. Miller667ef3c2007-07-16 04:03:56 -0700498 desc->size = len;
499 desc->ncookies = err;
500
501 /* This has to be a non-SMP write barrier because we are writing
502 * to memory which is shared with the peer LDOM.
503 */
504 wmb();
505 desc->hdr.state = VIO_DESC_READY;
506
507 err = __vdc_tx_trigger(port);
508 if (err < 0) {
509 printk(KERN_ERR PFX "vdc_tx_trigger() failure, err=%d\n", err);
510 } else {
511 port->req_id++;
Dwight Engenfe47c3c2014-12-11 12:26:15 -0500512 dr->prod = vio_dring_next(dr, dr->prod);
David S. Miller667ef3c2007-07-16 04:03:56 -0700513 }
David S. Miller667ef3c2007-07-16 04:03:56 -0700514
515 return err;
516}
517
Dwight Engend0aedcd2014-09-19 09:43:02 -0400518static void do_vdc_request(struct request_queue *rq)
David S. Miller667ef3c2007-07-16 04:03:56 -0700519{
Dwight Engend0aedcd2014-09-19 09:43:02 -0400520 struct request *req;
David S. Miller667ef3c2007-07-16 04:03:56 -0700521
Dwight Engend0aedcd2014-09-19 09:43:02 -0400522 while ((req = blk_peek_request(rq)) != NULL) {
523 struct vdc_port *port;
524 struct vio_dring_state *dr;
525
526 port = req->rq_disk->private_data;
527 dr = &port->vio.drings[VIO_DRIVER_TX_RING];
528 if (unlikely(vdc_tx_dring_avail(dr) < 1))
529 goto wait;
530
531 blk_start_request(req);
532
533 if (__send_request(req) < 0) {
534 blk_requeue_request(rq, req);
535wait:
536 /* Avoid pointless unplugs. */
537 blk_stop_queue(rq);
David S. Miller667ef3c2007-07-16 04:03:56 -0700538 break;
Dwight Engend0aedcd2014-09-19 09:43:02 -0400539 }
David S. Miller667ef3c2007-07-16 04:03:56 -0700540 }
541}
542
543static int generic_request(struct vdc_port *port, u8 op, void *buf, int len)
544{
545 struct vio_dring_state *dr;
546 struct vio_completion comp;
547 struct vio_disk_desc *desc;
548 unsigned int map_perm;
549 unsigned long flags;
550 int op_len, err;
551 void *req_buf;
552
David S. Millerf4d96052013-02-14 11:49:01 -0800553 if (!(((u64)1 << (u64)op) & port->operations))
David S. Miller667ef3c2007-07-16 04:03:56 -0700554 return -EOPNOTSUPP;
555
556 switch (op) {
557 case VD_OP_BREAD:
558 case VD_OP_BWRITE:
559 default:
560 return -EINVAL;
561
562 case VD_OP_FLUSH:
563 op_len = 0;
564 map_perm = 0;
565 break;
566
567 case VD_OP_GET_WCE:
568 op_len = sizeof(u32);
569 map_perm = LDC_MAP_W;
570 break;
571
572 case VD_OP_SET_WCE:
573 op_len = sizeof(u32);
574 map_perm = LDC_MAP_R;
575 break;
576
577 case VD_OP_GET_VTOC:
578 op_len = sizeof(struct vio_disk_vtoc);
579 map_perm = LDC_MAP_W;
580 break;
581
582 case VD_OP_SET_VTOC:
583 op_len = sizeof(struct vio_disk_vtoc);
584 map_perm = LDC_MAP_R;
585 break;
586
587 case VD_OP_GET_DISKGEOM:
588 op_len = sizeof(struct vio_disk_geom);
589 map_perm = LDC_MAP_W;
590 break;
591
592 case VD_OP_SET_DISKGEOM:
593 op_len = sizeof(struct vio_disk_geom);
594 map_perm = LDC_MAP_R;
595 break;
596
597 case VD_OP_SCSICMD:
598 op_len = 16;
599 map_perm = LDC_MAP_RW;
600 break;
601
602 case VD_OP_GET_DEVID:
603 op_len = sizeof(struct vio_disk_devid);
604 map_perm = LDC_MAP_W;
605 break;
606
607 case VD_OP_GET_EFI:
608 case VD_OP_SET_EFI:
609 return -EOPNOTSUPP;
610 break;
611 };
612
613 map_perm |= LDC_MAP_SHADOW | LDC_MAP_DIRECT | LDC_MAP_IO;
614
615 op_len = (op_len + 7) & ~7;
616 req_buf = kzalloc(op_len, GFP_KERNEL);
617 if (!req_buf)
618 return -ENOMEM;
619
620 if (len > op_len)
621 len = op_len;
622
623 if (map_perm & LDC_MAP_R)
624 memcpy(req_buf, buf, len);
625
626 spin_lock_irqsave(&port->vio.lock, flags);
627
628 dr = &port->vio.drings[VIO_DRIVER_TX_RING];
629
630 /* XXX If we want to use this code generically we have to
631 * XXX handle TX ring exhaustion etc.
632 */
633 desc = vio_dring_cur(dr);
634
635 err = ldc_map_single(port->vio.lp, req_buf, op_len,
636 desc->cookies, port->ring_cookies,
637 map_perm);
638 if (err < 0) {
639 spin_unlock_irqrestore(&port->vio.lock, flags);
640 kfree(req_buf);
641 return err;
642 }
643
644 init_completion(&comp.com);
645 comp.waiting_for = WAITING_FOR_GEN_CMD;
646 port->vio.cmp = &comp;
647
648 desc->hdr.ack = VIO_ACK_ENABLE;
649 desc->req_id = port->req_id;
650 desc->operation = op;
651 desc->slice = 0;
652 desc->status = ~0;
653 desc->offset = 0;
654 desc->size = op_len;
655 desc->ncookies = err;
656
657 /* This has to be a non-SMP write barrier because we are writing
658 * to memory which is shared with the peer LDOM.
659 */
660 wmb();
661 desc->hdr.state = VIO_DESC_READY;
662
663 err = __vdc_tx_trigger(port);
664 if (err >= 0) {
665 port->req_id++;
Dwight Engenfe47c3c2014-12-11 12:26:15 -0500666 dr->prod = vio_dring_next(dr, dr->prod);
David S. Miller667ef3c2007-07-16 04:03:56 -0700667 spin_unlock_irqrestore(&port->vio.lock, flags);
668
669 wait_for_completion(&comp.com);
670 err = comp.err;
671 } else {
672 port->vio.cmp = NULL;
673 spin_unlock_irqrestore(&port->vio.lock, flags);
674 }
675
676 if (map_perm & LDC_MAP_W)
677 memcpy(buf, req_buf, len);
678
679 kfree(req_buf);
680
681 return err;
682}
683
Greg Kroah-Hartman8d85fce2012-12-21 15:13:49 -0800684static int vdc_alloc_tx_ring(struct vdc_port *port)
David S. Miller667ef3c2007-07-16 04:03:56 -0700685{
686 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
687 unsigned long len, entry_size;
688 int ncookies;
689 void *dring;
690
691 entry_size = sizeof(struct vio_disk_desc) +
692 (sizeof(struct ldc_trans_cookie) * port->ring_cookies);
693 len = (VDC_TX_RING_SIZE * entry_size);
694
695 ncookies = VIO_MAX_RING_COOKIES;
696 dring = ldc_alloc_exp_dring(port->vio.lp, len,
697 dr->cookies, &ncookies,
698 (LDC_MAP_SHADOW |
699 LDC_MAP_DIRECT |
700 LDC_MAP_RW));
701 if (IS_ERR(dring))
702 return PTR_ERR(dring);
703
704 dr->base = dring;
705 dr->entry_size = entry_size;
706 dr->num_entries = VDC_TX_RING_SIZE;
707 dr->prod = dr->cons = 0;
708 dr->pending = VDC_TX_RING_SIZE;
709 dr->ncookies = ncookies;
710
711 return 0;
712}
713
714static void vdc_free_tx_ring(struct vdc_port *port)
715{
716 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
717
718 if (dr->base) {
719 ldc_free_exp_dring(port->vio.lp, dr->base,
720 (dr->entry_size * dr->num_entries),
721 dr->cookies, dr->ncookies);
722 dr->base = NULL;
723 dr->entry_size = 0;
724 dr->num_entries = 0;
725 dr->pending = 0;
726 dr->ncookies = 0;
727 }
728}
729
Dwight Engen76e74bb2014-12-11 12:26:17 -0500730static int vdc_port_up(struct vdc_port *port)
David S. Miller667ef3c2007-07-16 04:03:56 -0700731{
732 struct vio_completion comp;
David S. Miller667ef3c2007-07-16 04:03:56 -0700733
734 init_completion(&comp.com);
735 comp.err = 0;
736 comp.waiting_for = WAITING_FOR_LINK_UP;
737 port->vio.cmp = &comp;
738
739 vio_port_up(&port->vio);
David S. Miller667ef3c2007-07-16 04:03:56 -0700740 wait_for_completion(&comp.com);
Dwight Engen76e74bb2014-12-11 12:26:17 -0500741 return comp.err;
742}
743
744static void vdc_port_down(struct vdc_port *port)
745{
746 ldc_disconnect(port->vio.lp);
747 ldc_unbind(port->vio.lp);
748 vdc_free_tx_ring(port);
749 vio_ldc_free(&port->vio);
750}
751
752static int probe_disk(struct vdc_port *port)
753{
754 struct request_queue *q;
755 struct gendisk *g;
756 int err;
757
758 err = vdc_port_up(port);
759 if (err)
760 return err;
David S. Miller667ef3c2007-07-16 04:03:56 -0700761
Allen Pais9bce2182014-09-19 09:42:14 -0400762 if (vdc_version_supported(port, 1, 1)) {
763 /* vdisk_size should be set during the handshake, if it wasn't
764 * then the underlying disk is reserved by another system
765 */
766 if (port->vdisk_size == -1)
767 return -ENODEV;
768 } else {
Allen Paisde5b73f2014-09-19 09:42:26 -0400769 struct vio_disk_geom geom;
770
Allen Pais9bce2182014-09-19 09:42:14 -0400771 err = generic_request(port, VD_OP_GET_DISKGEOM,
Allen Paisde5b73f2014-09-19 09:42:26 -0400772 &geom, sizeof(geom));
Allen Pais9bce2182014-09-19 09:42:14 -0400773 if (err < 0) {
774 printk(KERN_ERR PFX "VD_OP_GET_DISKGEOM returns "
775 "error %d\n", err);
776 return err;
777 }
Allen Paisde5b73f2014-09-19 09:42:26 -0400778 port->vdisk_size = ((u64)geom.num_cyl *
779 (u64)geom.num_hd *
780 (u64)geom.num_sec);
David S. Miller667ef3c2007-07-16 04:03:56 -0700781 }
782
David S. Miller667ef3c2007-07-16 04:03:56 -0700783 q = blk_init_queue(do_vdc_request, &port->vio.lock);
784 if (!q) {
785 printk(KERN_ERR PFX "%s: Could not allocate queue.\n",
786 port->vio.name);
787 return -ENOMEM;
788 }
789 g = alloc_disk(1 << PARTITION_SHIFT);
790 if (!g) {
791 printk(KERN_ERR PFX "%s: Could not allocate gendisk.\n",
792 port->vio.name);
793 blk_cleanup_queue(q);
794 return -ENOMEM;
795 }
796
797 port->disk = g;
798
Dwight Engen5eed69f2014-09-19 09:42:53 -0400799 /* Each segment in a request is up to an aligned page in size. */
800 blk_queue_segment_boundary(q, PAGE_SIZE - 1);
801 blk_queue_max_segment_size(q, PAGE_SIZE);
802
Martin K. Petersen8a783622010-02-26 00:20:39 -0500803 blk_queue_max_segments(q, port->ring_cookies);
Martin K. Petersen086fa5f2010-02-26 00:20:38 -0500804 blk_queue_max_hw_sectors(q, port->max_xfer_size);
David S. Miller667ef3c2007-07-16 04:03:56 -0700805 g->major = vdc_major;
David S. Miller91ba3c22007-07-18 15:15:45 -0700806 g->first_minor = port->vio.vdev->dev_no << PARTITION_SHIFT;
David S. Miller667ef3c2007-07-16 04:03:56 -0700807 strcpy(g->disk_name, port->disk_name);
808
809 g->fops = &vdc_fops;
810 g->queue = q;
811 g->private_data = port;
David S. Miller667ef3c2007-07-16 04:03:56 -0700812
813 set_capacity(g, port->vdisk_size);
814
Allen Pais9bce2182014-09-19 09:42:14 -0400815 if (vdc_version_supported(port, 1, 1)) {
816 switch (port->vdisk_mtype) {
817 case VD_MEDIA_TYPE_CD:
818 pr_info(PFX "Virtual CDROM %s\n", port->disk_name);
819 g->flags |= GENHD_FL_CD;
820 g->flags |= GENHD_FL_REMOVABLE;
821 set_disk_ro(g, 1);
822 break;
823
824 case VD_MEDIA_TYPE_DVD:
825 pr_info(PFX "Virtual DVD %s\n", port->disk_name);
826 g->flags |= GENHD_FL_CD;
827 g->flags |= GENHD_FL_REMOVABLE;
828 set_disk_ro(g, 1);
829 break;
830
831 case VD_MEDIA_TYPE_FIXED:
832 pr_info(PFX "Virtual Hard disk %s\n", port->disk_name);
833 break;
834 }
835 }
836
837 pr_info(PFX "%s: %u sectors (%u MB) protocol %d.%d\n",
David S. Miller667ef3c2007-07-16 04:03:56 -0700838 g->disk_name,
Allen Pais9bce2182014-09-19 09:42:14 -0400839 port->vdisk_size, (port->vdisk_size >> (20 - 9)),
840 port->vio.ver.major, port->vio.ver.minor);
David S. Miller667ef3c2007-07-16 04:03:56 -0700841
Dan Williams0d52c7562016-06-15 19:44:20 -0700842 device_add_disk(&port->vio.vdev->dev, g);
David S. Miller667ef3c2007-07-16 04:03:56 -0700843
844 return 0;
845}
846
847static struct ldc_channel_config vdc_ldc_cfg = {
848 .event = vdc_event,
849 .mtu = 64,
850 .mode = LDC_MODE_UNRELIABLE,
851};
852
853static struct vio_driver_ops vdc_vio_ops = {
854 .send_attr = vdc_send_attr,
855 .handle_attr = vdc_handle_attr,
856 .handshake_complete = vdc_handshake_complete,
857};
858
Greg Kroah-Hartman8d85fce2012-12-21 15:13:49 -0800859static void print_version(void)
David S. Miller80dc35d2007-07-17 21:46:00 -0700860{
861 static int version_printed;
862
863 if (version_printed++ == 0)
864 printk(KERN_INFO "%s", version);
865}
866
Greg Kroah-Hartman8d85fce2012-12-21 15:13:49 -0800867static int vdc_port_probe(struct vio_dev *vdev, const struct vio_device_id *id)
David S. Miller667ef3c2007-07-16 04:03:56 -0700868{
David S. Miller43fdf272007-07-12 13:47:50 -0700869 struct mdesc_handle *hp;
David S. Miller667ef3c2007-07-16 04:03:56 -0700870 struct vdc_port *port;
David S. Miller667ef3c2007-07-16 04:03:56 -0700871 int err;
Dwight Engen76e74bb2014-12-11 12:26:17 -0500872 const u64 *ldc_timeout;
David S. Miller667ef3c2007-07-16 04:03:56 -0700873
David S. Miller80dc35d2007-07-17 21:46:00 -0700874 print_version();
David S. Miller667ef3c2007-07-16 04:03:56 -0700875
David S. Miller43fdf272007-07-12 13:47:50 -0700876 hp = mdesc_grab();
David S. Miller667ef3c2007-07-16 04:03:56 -0700877
David S. Miller43fdf272007-07-12 13:47:50 -0700878 err = -ENODEV;
David S. Miller91ba3c22007-07-18 15:15:45 -0700879 if ((vdev->dev_no << PARTITION_SHIFT) & ~(u64)MINORMASK) {
Sam Ravnborg3f4528d2009-01-06 13:20:38 -0800880 printk(KERN_ERR PFX "Port id [%llu] too large.\n",
David S. Miller91ba3c22007-07-18 15:15:45 -0700881 vdev->dev_no);
David S. Miller43fdf272007-07-12 13:47:50 -0700882 goto err_out_release_mdesc;
David S. Miller667ef3c2007-07-16 04:03:56 -0700883 }
884
885 port = kzalloc(sizeof(*port), GFP_KERNEL);
David S. Miller43fdf272007-07-12 13:47:50 -0700886 err = -ENOMEM;
David S. Miller667ef3c2007-07-16 04:03:56 -0700887 if (!port) {
888 printk(KERN_ERR PFX "Cannot allocate vdc_port.\n");
David S. Miller43fdf272007-07-12 13:47:50 -0700889 goto err_out_release_mdesc;
David S. Miller667ef3c2007-07-16 04:03:56 -0700890 }
891
David S. Miller91ba3c22007-07-18 15:15:45 -0700892 if (vdev->dev_no >= 26)
David S. Miller667ef3c2007-07-16 04:03:56 -0700893 snprintf(port->disk_name, sizeof(port->disk_name),
894 VDCBLK_NAME "%c%c",
David S. Miller91ba3c22007-07-18 15:15:45 -0700895 'a' + ((int)vdev->dev_no / 26) - 1,
896 'a' + ((int)vdev->dev_no % 26));
David S. Miller667ef3c2007-07-16 04:03:56 -0700897 else
898 snprintf(port->disk_name, sizeof(port->disk_name),
David S. Miller91ba3c22007-07-18 15:15:45 -0700899 VDCBLK_NAME "%c", 'a' + ((int)vdev->dev_no % 26));
Allen Pais9bce2182014-09-19 09:42:14 -0400900 port->vdisk_size = -1;
David S. Miller667ef3c2007-07-16 04:03:56 -0700901
Dwight Engen76e74bb2014-12-11 12:26:17 -0500902 /* Actual wall time may be double due to do_generic_file_read() doing
903 * a readahead I/O first, and once that fails it will try to read a
904 * single page.
905 */
906 ldc_timeout = mdesc_get_property(hp, vdev->mp, "vdc-timeout", NULL);
907 port->ldc_timeout = ldc_timeout ? *ldc_timeout : 0;
908 setup_timer(&port->ldc_reset_timer, vdc_ldc_reset_timer,
909 (unsigned long)port);
910 INIT_WORK(&port->ldc_reset_work, vdc_ldc_reset_work);
911
David S. Miller43fdf272007-07-12 13:47:50 -0700912 err = vio_driver_init(&port->vio, vdev, VDEV_DISK,
David S. Miller667ef3c2007-07-16 04:03:56 -0700913 vdc_versions, ARRAY_SIZE(vdc_versions),
914 &vdc_vio_ops, port->disk_name);
915 if (err)
916 goto err_out_free_port;
917
918 port->vdisk_block_size = 512;
919 port->max_xfer_size = ((128 * 1024) / port->vdisk_block_size);
920 port->ring_cookies = ((port->max_xfer_size *
921 port->vdisk_block_size) / PAGE_SIZE) + 2;
922
923 err = vio_ldc_alloc(&port->vio, &vdc_ldc_cfg, port);
924 if (err)
925 goto err_out_free_port;
926
927 err = vdc_alloc_tx_ring(port);
928 if (err)
929 goto err_out_free_ldc;
930
931 err = probe_disk(port);
932 if (err)
933 goto err_out_free_tx_ring;
934
David S. Miller667ef3c2007-07-16 04:03:56 -0700935 dev_set_drvdata(&vdev->dev, port);
936
David S. Miller43fdf272007-07-12 13:47:50 -0700937 mdesc_release(hp);
938
David S. Miller667ef3c2007-07-16 04:03:56 -0700939 return 0;
940
941err_out_free_tx_ring:
942 vdc_free_tx_ring(port);
943
944err_out_free_ldc:
945 vio_ldc_free(&port->vio);
946
947err_out_free_port:
948 kfree(port);
949
David S. Miller43fdf272007-07-12 13:47:50 -0700950err_out_release_mdesc:
951 mdesc_release(hp);
David S. Miller667ef3c2007-07-16 04:03:56 -0700952 return err;
953}
954
955static int vdc_port_remove(struct vio_dev *vdev)
956{
957 struct vdc_port *port = dev_get_drvdata(&vdev->dev);
958
959 if (port) {
Dwight Engen31f48882014-12-11 12:25:42 -0500960 unsigned long flags;
961
962 spin_lock_irqsave(&port->vio.lock, flags);
963 blk_stop_queue(port->disk->queue);
964 spin_unlock_irqrestore(&port->vio.lock, flags);
965
Dwight Engen76e74bb2014-12-11 12:26:17 -0500966 flush_work(&port->ldc_reset_work);
967 del_timer_sync(&port->ldc_reset_timer);
David S. Miller667ef3c2007-07-16 04:03:56 -0700968 del_timer_sync(&port->vio.timer);
969
Dwight Engen31f48882014-12-11 12:25:42 -0500970 del_gendisk(port->disk);
971 blk_cleanup_queue(port->disk->queue);
972 put_disk(port->disk);
973 port->disk = NULL;
974
David S. Miller667ef3c2007-07-16 04:03:56 -0700975 vdc_free_tx_ring(port);
976 vio_ldc_free(&port->vio);
977
978 dev_set_drvdata(&vdev->dev, NULL);
979
980 kfree(port);
981 }
982 return 0;
983}
984
Dwight Engen76e74bb2014-12-11 12:26:17 -0500985static void vdc_requeue_inflight(struct vdc_port *port)
986{
987 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
988 u32 idx;
989
990 for (idx = dr->cons; idx != dr->prod; idx = vio_dring_next(dr, idx)) {
991 struct vio_disk_desc *desc = vio_dring_entry(dr, idx);
992 struct vdc_req_entry *rqe = &port->rq_arr[idx];
993 struct request *req;
994
995 ldc_unmap(port->vio.lp, desc->cookies, desc->ncookies);
996 desc->hdr.state = VIO_DESC_FREE;
997 dr->cons = vio_dring_next(dr, idx);
998
999 req = rqe->req;
1000 if (req == NULL) {
1001 vdc_end_special(port, desc);
1002 continue;
1003 }
1004
1005 rqe->req = NULL;
1006 blk_requeue_request(port->disk->queue, req);
1007 }
1008}
1009
1010static void vdc_queue_drain(struct vdc_port *port)
1011{
1012 struct request *req;
1013
1014 while ((req = blk_fetch_request(port->disk->queue)) != NULL)
1015 __blk_end_request_all(req, -EIO);
1016}
1017
1018static void vdc_ldc_reset_timer(unsigned long _arg)
1019{
1020 struct vdc_port *port = (struct vdc_port *) _arg;
1021 struct vio_driver_state *vio = &port->vio;
1022 unsigned long flags;
1023
1024 spin_lock_irqsave(&vio->lock, flags);
1025 if (!(port->vio.hs_state & VIO_HS_COMPLETE)) {
1026 pr_warn(PFX "%s ldc down %llu seconds, draining queue\n",
1027 port->disk_name, port->ldc_timeout);
1028 vdc_queue_drain(port);
1029 vdc_blk_queue_start(port);
1030 }
1031 spin_unlock_irqrestore(&vio->lock, flags);
1032}
1033
1034static void vdc_ldc_reset_work(struct work_struct *work)
1035{
1036 struct vdc_port *port;
1037 struct vio_driver_state *vio;
1038 unsigned long flags;
1039
1040 port = container_of(work, struct vdc_port, ldc_reset_work);
1041 vio = &port->vio;
1042
1043 spin_lock_irqsave(&vio->lock, flags);
1044 vdc_ldc_reset(port);
1045 spin_unlock_irqrestore(&vio->lock, flags);
1046}
1047
1048static void vdc_ldc_reset(struct vdc_port *port)
1049{
1050 int err;
1051
1052 assert_spin_locked(&port->vio.lock);
1053
1054 pr_warn(PFX "%s ldc link reset\n", port->disk_name);
1055 blk_stop_queue(port->disk->queue);
1056 vdc_requeue_inflight(port);
1057 vdc_port_down(port);
1058
1059 err = vio_ldc_alloc(&port->vio, &vdc_ldc_cfg, port);
1060 if (err) {
1061 pr_err(PFX "%s vio_ldc_alloc:%d\n", port->disk_name, err);
1062 return;
1063 }
1064
1065 err = vdc_alloc_tx_ring(port);
1066 if (err) {
1067 pr_err(PFX "%s vio_alloc_tx_ring:%d\n", port->disk_name, err);
1068 goto err_free_ldc;
1069 }
1070
1071 if (port->ldc_timeout)
1072 mod_timer(&port->ldc_reset_timer,
1073 round_jiffies(jiffies + HZ * port->ldc_timeout));
1074 mod_timer(&port->vio.timer, round_jiffies(jiffies + HZ));
1075 return;
1076
1077err_free_ldc:
1078 vio_ldc_free(&port->vio);
1079}
1080
David S. Miller3d452e52008-09-01 01:48:52 -07001081static const struct vio_device_id vdc_port_match[] = {
David S. Miller667ef3c2007-07-16 04:03:56 -07001082 {
1083 .type = "vdc-port",
1084 },
1085 {},
1086};
Fabio Massimo Di Nittoda68e082007-07-18 14:35:23 -07001087MODULE_DEVICE_TABLE(vio, vdc_port_match);
David S. Miller667ef3c2007-07-16 04:03:56 -07001088
1089static struct vio_driver vdc_port_driver = {
1090 .id_table = vdc_port_match,
1091 .probe = vdc_port_probe,
1092 .remove = vdc_port_remove,
Benjamin Herrenschmidtcb52d892012-03-26 19:06:30 +00001093 .name = "vdc_port",
David S. Miller667ef3c2007-07-16 04:03:56 -07001094};
1095
David S. Miller667ef3c2007-07-16 04:03:56 -07001096static int __init vdc_init(void)
1097{
1098 int err;
1099
Dwight Engen76e74bb2014-12-11 12:26:17 -05001100 sunvdc_wq = alloc_workqueue("sunvdc", 0, 0);
1101 if (!sunvdc_wq)
1102 return -ENOMEM;
1103
David S. Miller667ef3c2007-07-16 04:03:56 -07001104 err = register_blkdev(0, VDCBLK_NAME);
1105 if (err < 0)
Dwight Engen76e74bb2014-12-11 12:26:17 -05001106 goto out_free_wq;
David S. Miller667ef3c2007-07-16 04:03:56 -07001107
1108 vdc_major = err;
David S. Miller667ef3c2007-07-16 04:03:56 -07001109
1110 err = vio_register_driver(&vdc_port_driver);
1111 if (err)
David S. Miller80dc35d2007-07-17 21:46:00 -07001112 goto out_unregister_blkdev;
David S. Miller667ef3c2007-07-16 04:03:56 -07001113
1114 return 0;
1115
David S. Miller667ef3c2007-07-16 04:03:56 -07001116out_unregister_blkdev:
1117 unregister_blkdev(vdc_major, VDCBLK_NAME);
1118 vdc_major = 0;
1119
Dwight Engen76e74bb2014-12-11 12:26:17 -05001120out_free_wq:
1121 destroy_workqueue(sunvdc_wq);
David S. Miller667ef3c2007-07-16 04:03:56 -07001122 return err;
1123}
1124
1125static void __exit vdc_exit(void)
1126{
1127 vio_unregister_driver(&vdc_port_driver);
David S. Miller667ef3c2007-07-16 04:03:56 -07001128 unregister_blkdev(vdc_major, VDCBLK_NAME);
Dwight Engen76e74bb2014-12-11 12:26:17 -05001129 destroy_workqueue(sunvdc_wq);
David S. Miller667ef3c2007-07-16 04:03:56 -07001130}
1131
1132module_init(vdc_init);
1133module_exit(vdc_exit);