drivers/block/sunvdc.c

Source file repositories/reference/linux-study-clean/drivers/block/sunvdc.c

File Facts

System
Linux kernel
Corpus path
drivers/block/sunvdc.c
Extension
.c
Size
29210 bytes
Lines
1253
Domain
Driver Families
Bucket
drivers/block
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct blk_mq_ops vdc_mq_ops = {
	.queue_rq	= vdc_queue_rq,
};

static int probe_disk(struct vdc_port *port)
{
	struct queue_limits lim = {
		.physical_block_size		= port->vdisk_phys_blksz,
		.max_hw_sectors			= port->max_xfer_size,
		/* Each segment in a request is up to an aligned page in size. */
		.seg_boundary_mask		= PAGE_SIZE - 1,
		.max_segment_size		= PAGE_SIZE,
		.max_segments			= port->ring_cookies,
		.features			= BLK_FEAT_ROTATIONAL,
	};
	struct request_queue *q;
	struct gendisk *g;
	int err;

	err = vdc_port_up(port);
	if (err)
		return err;

	/* Using version 1.2 means vdisk_phys_blksz should be set unless the
	 * disk is reserved by another system.
	 */
	if (vdc_version_supported(port, 1, 2) && !port->vdisk_phys_blksz)
		return -ENODEV;

	if (vdc_version_supported(port, 1, 1)) {
		/* vdisk_size should be set during the handshake, if it wasn't
		 * then the underlying disk is reserved by another system
		 */
		if (port->vdisk_size == -1)
			return -ENODEV;
	} else {
		struct vio_disk_geom geom;

		err = generic_request(port, VD_OP_GET_DISKGEOM,
				      &geom, sizeof(geom));
		if (err < 0) {
			printk(KERN_ERR PFX "VD_OP_GET_DISKGEOM returns "
			       "error %d\n", err);
			return err;
		}
		port->vdisk_size = ((u64)geom.num_cyl *
				    (u64)geom.num_hd *
				    (u64)geom.num_sec);
	}

	err = blk_mq_alloc_sq_tag_set(&port->tag_set, &vdc_mq_ops,
			VDC_TX_RING_SIZE, 0);
	if (err)
		return err;

	g = blk_mq_alloc_disk(&port->tag_set, &lim, port);
	if (IS_ERR(g)) {
		printk(KERN_ERR PFX "%s: Could not allocate gendisk.\n",
		       port->vio.name);
		err = PTR_ERR(g);
		goto out_free_tag;
	}

	port->disk = g;
	q = g->queue;

	g->major = vdc_major;
	g->first_minor = port->vio.vdev->dev_no << PARTITION_SHIFT;
	g->minors = 1 << PARTITION_SHIFT;
	strcpy(g->disk_name, port->disk_name);

	g->fops = &vdc_fops;
	g->queue = q;
	g->private_data = port;

	set_capacity(g, port->vdisk_size);

	if (vdc_version_supported(port, 1, 1)) {
		switch (port->vdisk_mtype) {
		case VD_MEDIA_TYPE_CD:
			pr_info(PFX "Virtual CDROM %s\n", port->disk_name);
			g->flags |= GENHD_FL_REMOVABLE;
			set_disk_ro(g, 1);
			break;

		case VD_MEDIA_TYPE_DVD:
			pr_info(PFX "Virtual DVD %s\n", port->disk_name);
			g->flags |= GENHD_FL_REMOVABLE;
			set_disk_ro(g, 1);
			break;

Annotation

Implementation Notes