Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ scsi_init_pkt(9F) — SunOS 5.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

scsi_destroy_pkt(9F)

scsi_dmaget(9F)

scsi_pktalloc(9F)

buf(9S)

scsi_pkt(9S)

scsi_init_pkt(9F)

NAME

scsi_init_pkt − prepare a complete SCSI packet

SYNOPSIS

#include <sys/scsi/scsi.h>

struct scsi_pkt ∗scsi_init_pkt(struct scsi_address ∗ap, struct scsi_pkt ∗pktp,

struct buf ∗bp, int cmdlen, int statuslen, int privatelen, int flags,

int (∗callback )(caddr_t), caddr_t arg);

ARGUMENTS

ap Pointer to a scsi_address structure. 

pktp A pointer to a scsi_pkt(9S) structure. 

bp Pointer to a buf(9S) structure. 

cmdlen The required length for the SCSI command descriptor block (CDB) in bytes. 

statuslen The required length for the SCSI status completion block (SCB) in bytes. 

privatelen The required length for the pkt_private area. 

flags The flag for creating the packet. 

callback A pointer to a callback function, NULL_FUNC, or SLEEP_FUNC. 

arg The callback function argument. 

INTERFACE LEVEL

Solaris architecture specific (SunDDI). 

DESCRIPTION

Target drivers use scsi_init_pkt() to request the transport layer to allocate a command packet for commands and, possibly, data transfers.  If pktp is NULL, a new scsi_pkt(9S) is allocated using scsi_pktalloc(9F).  The bp is a pointer to a buf(9S) structure.  If bp is non-NULL and contains a valid byte count, the buf(9S) structure is also set up for DMA transfer using scsi_dmaget(9F).  When the bp is allocated by scsi_alloc_consistent_buf(9F), the PKT_CONSISTENT flag must be set to ensure proper operation.  If privatelen is set then additional space is allocated for the pkt_private area of the scsi_pkt(9S), otherwise pkt_private is a pointer that is typically used to store the bp during execution of the command.  The flags are set into the command portion of the pkt.

The last argument arg is supplied to the callback function when it is invoked. 

callback indicates what the allocator routines should do when resources are not available:

NULL_FUNC Do not wait for resources. Return a NULL pointer. 

SLEEP_FUNC
Wait indefinitely for resources.

Other Values callback points to a function which is called when resources may have become available.  callback must return either 0 (indicating that it attempted to allocate resources but again failed to do so), in which case it is put back on a list to be called again later, or 1 indicating either success in allocating resources or indicating that it no longer cares for a retry. 

RETURN VALUES

The routine returns a pointer to an initialized scsi_pkt(9S) structure or a NULL pointer. 

CONTEXT

If callback is SLEEP_FUNC, then this routine may only be called from user-level code.  Otherwise, it may be called from either user or interrupt level.  The callback function may not block or call routines that block. 

EXAMPLES

To allocate a packet without DMA resources attached, use:

    pkt = scsi_init_pkt(&devp->sd_address, NULL, NULL, CDB_GROUP1,
          STATUS_LEN, sizeof (struct buf ∗), 0, sd_runout, sd_unit);

To allocate a packet with DMA resources attached use:

    pkt = scsi_init_pkt(&devp->sd_address, NULL, bp, CDB_GROUP1,
          STATUS_LEN, sizeof (struct buf ∗), 0, NULL_FUNC, NULL);

To attach DMA resources to a preallocated packet, use:

    pkt = scsi_init_pkt(&devp->sd_address, old_pkt, bp, 0,
          0, sizeof (struct buf ∗), 0, sd_runout, (caddr_t) sd_unit);

Since the packet is already allocated the cmdlen and statuslen are 0. 

To allocate a packet with consistent DMA resources attached, use:

    bp = scsi_alloc_consistent_buf(&devp->sd_address, NULL,
          SENSE_LENGTH, B_READ, SLEEP_FUNC, NULL);
    pkt = scsi_init_pkt(&devp->sd_address, NULL, bp, CDB_GROUP0,
          STATUS_LEN, sizeof (struct buf ∗), PKT_CONSISTENT,
          SLEEP_FUNC, NULL);

SEE ALSO

scsi_destroy_pkt(9F), scsi_dmaget(9F), scsi_pktalloc(9F), buf(9S), scsi_pkt(9S)

SunOS 5.1 Writing Device Drivers

SunOS 5.1  —  Last change: 21 Dec 1992

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026