Writing Device Drivers

detach() Entry Point (SCSI Target Drivers)

The detach(9E) entry point is the inverse of attach(9E). detach() must free all resources that were allocated in attach(). If successful, the detach should call scsi_unprobe(9F). The following example shows a target driver detach() routine.

Example 17–3 SCSI Target Driver detach(9E) Routine

static int
xxdetach(dev_info_t *dip, ddi_detach_cmd_t cmd)
    struct xxstate *xsp;
    switch (cmd) {
    case DDI_DETACH:
       * Normal detach(9E) operations, such as getting a
       * pointer to the state structure
      xsp->sdp->sd_private = (caddr_t)NULL;
      xsp->sdp->sd_sense = NULL;
       * Remove minor nodes.
       * Free resources, such as the state structure and properties.
          return (DDI_SUCCESS);
    case DDI_SUSPEND:
      /* For information, see the "Directory Memory Access (DMA)" */
      /* chapter in this book. */
      return (DDI_FAILURE);