Writing Device Drivers

scsi_pkt Structure

To execute SCSI commands, a target driver must first allocate a scsi_pkt(9S) structure for the command, specifying its own private data area length, the command status, and the command length. The HBA driver is responsible for implementing the packet allocation in the tran_init_pkt(9E) entry point. The HBA driver is also responsible for freeing the packet in its tran_destroy_pkt(9E) entry point. See scsi_pkt(9S) in Chapter 13, SCSI Target Drivers, for more information.

The scsi_pkt(9S) structure contains these fields:

		opaque_t					 	pkt_ha_private;		/* HBA private data */
 	struc	t	scsi_address		*pkt_address;	/* destination address */
 	opaque_t				pkt_private;		/* target driver private */
 	void					(*pkt_comp)();		/* pkt completion routine */
 	u_int					pkt_flags;			/* flags */
 	int					pkt_time;			/* completion timeout */
 	u_char				*pkt_scbp;			/* ptr to status block */
 	u_char				*pkt_cdbp;			/* ptr to command block */
 	ssize_t				pkt_resid;			/* bytes not transferred*/
 	u_int					pkt_state;			/* state of command */
 	u_int					pkt_statistics;	/* statistics */
 	u_char				pkt_reason;			/* pkt completion reason */

The HBA driver must modify the following fields during transport.

pkt_ha_private is a pointer to per-command HBA-driver private data.

pkt_address is a pointer to the scsi_address(9S) structure providing address information for this command.

pkt_private is a pointer to per-packet target-driver private data.

pkt_comp is a pointer to the target driver completion routine called by the HBA driver when the transport layer has completed this command.

pkt_flags are the flags for the command.

pkt_time specifies the completion timeout in seconds for the command.

pkt_scbp is a pointer to the status completion block for the command.

pkt_cdbp is a pointer to the command descriptor block (CDB) for the command.

pkt_resid is a count of the data bytes not transferred when the command has been completed or the amount of data for which resources have not been allocated.

pkt_state is the state of the command.

pkt_statistics provides a history of the events the command experienced while in the transport layer.

pkt_reason is the reason for command completion.