Writing Device Drivers

Target Driver Instance Initialization

tran_tgt_init(9E)

The tran_tgt_init(9E) entry point allows the HBA to allocate and/or initialize any per-target resources. It also allows the HBA to qualify the device's address as valid and supportable for that particular HBA. By returning DDI_FAILURE, the instance of the target driver for that device will not be probed or attached.

This entry point is not required, and if none is supplied, the framework will attempt to probe and attach all possible instances of the appropriate target drivers.

 static int
 isp_tran_tgt_init(
 	dev_info_t					*hba_dip,
 	dev_info_t					*tgt_dip,
 	scsi_hba_tran_t					*tran,
 	struct scsi_device					*sd)
 {
 	return ((sd->sd_address.a_target < N_ISP_TARGETS_WIDE &&
 			sd->sd_address.a_lun < 8) ? DDI_SUCCESS : DDI_FAILURE);
 }

tran_tgt_probe(9E)

The tran_tgt_probe(9E) entry point enables the HBA to customize the operation of scsi_probe(9F), if necessary. This entry point is called only when the target driver calls scsi_probe(9F).

The HBA driver can retain the normal operation of scsi_probe(9F) by calling scsi_hba_probe(9F) and returning its return value.

This entry point is not required, and if not needed, the HBA driver should set the tran_tgt_probe vector in the scsi_hba_tran(9S) structure to point to scsi_hba_probe(9F).

scsi_probe(9F) allocates a scsi_inquiry(9S) structure and sets the sd_inq field of the scsi_device(9S) structure to point to the data in scsi_inquiry(9S). scsi_hba_probe(9F) handles this automatically. scsi_unprobe(9F) then frees the scsi_inquiry(9S) data.

Other than during the allocation of scsi_inquiry(9S) data, normally handled by scsi_hba_probe(9F), tran_tgt_probe(9E) must be stateless, as the same SCSI device might call it multiple times.


Note -

The allocation of the scsi_inquiry(9S) structure is handled automatically by scsi_hba_probe(9F). This is only of concern if custom scsi_probe(9F) handling is desired.


static int
 isp_tran_tgt_probe(
 	struct scsi_device	*sd,
 	int			(*callback)())
 {
 	Perform any special probe customization needed.
 	/*
 	 * Normal probe handling
 	 */
 	return (scsi_hba_probe(sd, callback));
 }

tran_tgt_free(9E)

The tran_tgt_free(9E) entry point enables the HBA to perform any deallocation or clean-up procedures for an instance of a target. This entry point is optional.

 static void
 isp_tran_tgt_free(
 	dev_info_t						*hba_dip,
 	dev_info_t						*tgt_dip,
 	scsi_hba_tran_t						*hba_tran,
 	struct scsi_device						*sd)
 {
 	Undo any special per-target initialization done 
		earlier in tran_tgt_init(9F) and tran_tgt_probe(9F).
 }