Writing Device Drivers


The getinfo(9E) routine for SCSI target drivers is much the same as for other drivers; see "getinfo()" for more information on DDI_INFO_DEVT2INSTANCE case. However, in the DDI_INFO_DEVT2DEVINFO case of the getinfo(9E) routine, the target driver must return a pointer to its dev_info node. This pointer can be saved in the driver state structure or can be retrieved from the sd_dev field of the scsi_device(9S) structure. Example 13-4shows an alternative SCSI target driver getinfo(9E) code fragment.

Example 13-4 Alternative SCSI Target Driver getinfo(9E) Code Fragment

		dev = (dev_t)arg;
		instance = getminor(dev);
		xsp = ddi_get_soft_state(statep, instance);
		if (xsp == NULL)
			return (DDI_FAILURE);
		*result = (void *)xsp->sdp->sd_dev;
		return (DDI_SUCCESS);