6 #include <linux/module.h>
7 #include <linux/kernel.h>
8 #include <linux/types.h>
12 #include <linux/slab.h>
17 #include <linux/list.h>
23 #define DRV_MODULE_NAME "sunvdc"
24 #define PFX DRV_MODULE_NAME ": "
25 #define DRV_MODULE_VERSION "1.0"
26 #define DRV_MODULE_RELDATE "June 25, 2007"
35 #define VDC_TX_RING_SIZE 256
37 #define WAITING_FOR_LINK_UP 0x01
38 #define WAITING_FOR_TX_SPACE 0x02
39 #define WAITING_FOR_GEN_CMD 0x04
40 #define WAITING_FOR_ANY -1
51 struct vdc_completion *
cmp;
82 { .major = 1, .minor = 0 },
85 #define VDCBLK_NAME "vdisk"
87 #define PARTITION_SHIFT 3
96 struct gendisk *disk = bdev->
bd_disk;
106 static const struct block_device_operations vdc_fops = {
108 .getgeo = vdc_getgeo,
114 (waiting_for == -1 ||
115 vio->
cmp->waiting_for == waiting_for)) {
145 memset(&pkt, 0,
sizeof(pkt));
156 viodbg(HS,
"SEND ATTR xfer_mode[0x%x] blksz[%u] max_xfer[%llu]\n",
157 pkt.xfer_mode, pkt.vdisk_block_size, pkt.max_xfer_size);
164 struct vdc_port *port = to_vdc_port(vio);
167 viodbg(HS,
"GOT ATTR stype[0x%x] ops[%llx] disk_size[%llu] disk_type[%x] "
168 "xfer_mode[0x%x] blksz[%u] max_xfer[%llu]\n",
231 vdc_end_special(port, desc);
239 if (blk_queue_stopped(port->
disk->queue))
258 static int vdc_nack(
struct vdc_port *port,
void *msgbuf)
264 static void vdc_event(
void *arg,
int event)
276 spin_unlock_irqrestore(&vio->
lock, flags);
282 spin_unlock_irqrestore(&vio->
lock, flags);
293 err =
ldc_read(vio->
lp, &msgbuf,
sizeof(msgbuf));
304 msgbuf.tag.stype_env,
312 err = vdc_ack(port, &msgbuf);
314 err = vdc_nack(port, &msgbuf);
316 err = vdc_handle_unknown(port, &msgbuf);
320 err = vdc_handle_unknown(port, &msgbuf);
327 spin_unlock_irqrestore(&vio->
lock, flags);
330 static int __vdc_tx_trigger(
struct vdc_port *port)
340 .dring_ident = dr->
ident,
341 .start_idx = dr->
prod,
355 if ((delay <<= 1) > 128)
362 static int __send_request(
struct request *req)
364 struct vdc_port *port = req->rq_disk->private_data;
369 unsigned int map_perm;
376 if (rq_data_dir(req) ==
READ) {
388 for (i = 0; i < nsg; i++)
391 if (
unlikely(vdc_tx_dring_avail(dr) < 1)) {
397 desc = vio_dring_cur(dr);
429 err = __vdc_tx_trigger(port);
449 if (__send_request(req) < 0)
454 static int generic_request(
struct vdc_port *port,
u8 op,
void *
buf,
int len)
459 unsigned int map_perm;
479 op_len =
sizeof(
u32);
484 op_len =
sizeof(
u32);
526 op_len = (op_len + 7) & ~7;
535 memcpy(req_buf, buf, len);
544 desc = vio_dring_cur(dr);
550 spin_unlock_irqrestore(&port->
vio.lock, flags);
555 init_completion(&comp.com);
557 port->
vio.cmp = ∁
574 err = __vdc_tx_trigger(port);
578 spin_unlock_irqrestore(&port->
vio.lock, flags);
584 spin_unlock_irqrestore(&port->
vio.lock, flags);
588 memcpy(buf, req_buf, len);
613 return PTR_ERR(dring);
625 static void vdc_free_tx_ring(
struct vdc_port *port)
641 static int probe_disk(
struct vdc_port *port)
648 init_completion(&comp.com);
651 port->
vio.cmp = ∁
696 g->major = vdc_major;
702 g->private_data =
port;
703 g->driverfs_dev = &port->
vio.vdev->dev;
723 .send_attr = vdc_send_attr,
724 .handle_attr = vdc_handle_attr,
725 .handshake_complete = vdc_handshake_complete,
728 static void __devinit print_version(
void)
730 static int version_printed;
732 if (version_printed++ == 0)
751 goto err_out_release_mdesc;
758 goto err_out_release_mdesc;
764 'a' + ((
int)vdev->
dev_no / 26) - 1,
765 'a' + ((
int)vdev->
dev_no % 26));
774 goto err_out_free_port;
783 goto err_out_free_port;
785 err = vdc_alloc_tx_ring(port);
787 goto err_out_free_ldc;
789 err = probe_disk(port);
791 goto err_out_free_tx_ring;
799 err_out_free_tx_ring:
800 vdc_free_tx_ring(port);
808 err_out_release_mdesc:
813 static int vdc_port_remove(
struct vio_dev *vdev)
820 vdc_free_tx_ring(port);
839 .id_table = vdc_port_match,
840 .probe = vdc_port_probe,
841 .remove = vdc_port_remove,
845 static int __init vdc_init(
void)
857 goto out_unregister_blkdev;
861 out_unregister_blkdev:
869 static void __exit vdc_exit(
void)