Writing Device Drivers

tran_destroy_pkt(9E)

The tran_destroy_pkt(9E) entry point is the HBA driver function that deallocates scsi_pkt(9S) structures. The tran_destroy_pkt(9E) entry point is called when the target driver calls scsi_destroy_pkt(9F).

The tran_destroy_pkt(9E) entry point must free any DMA resources allocated for the packet. Freeing the DMA resources causes an implicit DMA synchronization if any cached data remained after the completion of the transfer. The tran_destroy_pkt(9E) entry point frees the SCSI packet itself by calling scsi_hba_pkt_free(9F).


Example 14-7 HBA Driver tran_destroy_pkt(9E) Entry Point

static void
isp_scsi_destroy_pkt(
	struct scsi_address	*ap,
	struct scsi_pkt		*pkt)
{
	struct isp_cmd *sp = (struct isp_cmd *)pkt->pkt_ha_private;

	/*
	 * Free the DMA, if any
	 */
	if (sp->cmd_flags & CFLAG_DMAVALID) {
		sp->cmd_flags &= ~CFLAG_DMAVALID;
		(void) ddi_dma_unbind_handle(sp->cmd_dmahandle);
		ddi_dma_free_handle(&sp->cmd_dmahandle);
		sp->cmd_dmahandle = NULL;
	}
	/*
	 * Free the pkt
	 */
	scsi_hba_pkt_free(ap, pkt);
}