drivers/ata/libata-zpodd.c

Source file repositories/reference/linux-study-clean/drivers/ata/libata-zpodd.c

File Facts

System
Linux kernel
Corpus path
drivers/ata/libata-zpodd.c
Extension
.c
Size
7396 bytes
Lines
295
Domain
Driver Families
Bucket
drivers/ata
Inferred role
Driver Families: implementation source
Status
source 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

struct zpodd {
	enum odd_mech_type	mech_type; /* init during probe, RO afterwards */
	struct ata_device	*dev;

	/* The following fields are synchronized by PM core. */
	bool			from_notify; /* resumed as a result of
					      * acpi wake notification */
	bool			zp_ready; /* ZP ready state */
	unsigned long		last_ready; /* last ZP ready timestamp */
	bool			zp_sampled; /* ZP ready state sampled */
	bool			powered_off; /* ODD is powered off
					      *	during suspend */
};

static int eject_tray(struct ata_device *dev)
{
	struct ata_taskfile tf;
	static const char cdb[ATAPI_CDB_LEN] = {  GPCMD_START_STOP_UNIT,
		0, 0, 0,
		0x02,     /* LoEj */
		0, 0, 0, 0, 0, 0, 0,
	};

	ata_tf_init(dev, &tf);
	tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
	tf.command = ATA_CMD_PACKET;
	tf.protocol = ATAPI_PROT_NODATA;

	return ata_exec_internal(dev, &tf, cdb, DMA_NONE, NULL, 0, 0);
}

/* Per the spec, only slot type and drawer type ODD can be supported */
static enum odd_mech_type zpodd_get_mech_type(struct ata_device *dev)
{
	char *buf;
	unsigned int ret;
	struct rm_feature_desc *desc;
	struct ata_taskfile tf;
	static const char cdb[ATAPI_CDB_LEN] = {  GPCMD_GET_CONFIGURATION,
			2,      /* only 1 feature descriptor requested */
			0, 3,   /* 3, removable medium feature */
			0, 0, 0,/* reserved */
			0, 16,
			0, 0, 0,
	};

	buf = kzalloc(16, GFP_KERNEL);
	if (!buf)
		return ODD_MECH_TYPE_UNSUPPORTED;
	desc = (void *)(buf + 8);

	ata_tf_init(dev, &tf);
	tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
	tf.command = ATA_CMD_PACKET;
	tf.protocol = ATAPI_PROT_PIO;
	tf.lbam = 16;

	ret = ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE,
				buf, 16, 0);
	if (ret) {
		kfree(buf);
		return ODD_MECH_TYPE_UNSUPPORTED;
	}

	if (be16_to_cpu(desc->feature_code) != 3) {
		kfree(buf);
		return ODD_MECH_TYPE_UNSUPPORTED;
	}

	if (desc->mech_type == 0 && desc->load == 0 && desc->eject == 1) {
		kfree(buf);
		return ODD_MECH_TYPE_SLOT;
	} else if (desc->mech_type == 1 && desc->load == 0 &&
		   desc->eject == 1) {
		kfree(buf);
		return ODD_MECH_TYPE_DRAWER;
	} else {
		kfree(buf);
		return ODD_MECH_TYPE_UNSUPPORTED;
	}
}

/* Test if ODD is zero power ready by sense code */
static bool zpready(struct ata_device *dev)
{
	u8 sense_key, *sense_buf;
	unsigned int ret, asc, ascq, add_len;
	struct zpodd *zpodd = dev->zpodd;

	ret = atapi_eh_tur(dev, &sense_key);

Annotation

Implementation Notes