kernel - Change callout in struct ccb_hdr
authorMatthew Dillon <dillon@apollo.backplane.com>
Mon, 4 Mar 2019 20:50:52 +0000 (12:50 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Mon, 4 Mar 2019 20:50:52 +0000 (12:50 -0800)
* Change the callout declaration in struct ccb_hdr from an embedded
  structure to a pointer, add padding to get the whole structure to its
  original size (prior to the recent callout patch).

* This removes an improper ABI dependency on the kernel struct callout
  structure which was causing 'camcontrol', and 'smartctl' (from
  smartmontools) to fail.

Testing: dillon, tuxillo

48 files changed:
sys/bus/cam/cam_ccb.h
sys/bus/cam/cam_periph.c
sys/bus/cam/cam_xpt.c
sys/bus/cam/cam_xpt_periph.h
sys/bus/cam/scsi/scsi_all.c
sys/bus/cam/scsi/scsi_cd.c
sys/bus/cam/scsi/scsi_da.c
sys/bus/cam/scsi/scsi_pass.c
sys/bus/cam/scsi/scsi_sg.c
sys/bus/cam/scsi/scsi_targ_bh.c
sys/bus/cam/scsi/scsi_target.c
sys/bus/u4b/storage/umass.c
sys/dev/disk/advansys/advansys.c
sys/dev/disk/advansys/advlib.c
sys/dev/disk/advansys/adwcam.c
sys/dev/disk/ahci/ahci_cam.c
sys/dev/disk/amd/amd.c
sys/dev/disk/buslogic/bt.c
sys/dev/disk/iscsi/initiator/isc_cam.c
sys/dev/disk/isp/isp_freebsd.c
sys/dev/disk/mpt/mpt_cam.c
sys/dev/disk/mpt/mpt_raid.c
sys/dev/disk/nata/atapi-cam.c
sys/dev/disk/ncr/ncr.c
sys/dev/disk/sbp/sbp.c
sys/dev/disk/sili/sili_cam.c
sys/dev/disk/sym/sym_hipd.c
sys/dev/disk/trm/trm.c
sys/dev/disk/vpo/vpo.c
sys/dev/raid/aac/aac_cam.c
sys/dev/raid/arcmsr/arcmsr.c
sys/dev/raid/asr/asr.c
sys/dev/raid/ciss/ciss.c
sys/dev/raid/dpt/dpt_scsi.c
sys/dev/raid/hpt27xx/hpt27xx_osm_bsd.c
sys/dev/raid/hptiop/hptiop.c
sys/dev/raid/hptmv/entry.c
sys/dev/raid/hptrr/hptrr_osm_bsd.c
sys/dev/raid/iir/iir.c
sys/dev/raid/mly/mly.c
sys/dev/raid/mpr/mpr_sas.c
sys/dev/raid/mpr/mpr_sas_lsi.c
sys/dev/raid/mps/mps_sas.c
sys/dev/raid/mrsas/mrsas_cam.c
sys/dev/raid/twa/tw_osl_cam.c
sys/dev/raid/tws/tws.c
sys/dev/raid/tws/tws_cam.c
sys/dev/virtual/virtio/scsi/virtio_scsi.c

index 62ac612..d37736f 100644 (file)
@@ -278,8 +278,8 @@ struct ccb_hdr {
        ccb_ppriv_area  periph_priv;
        ccb_spriv_area  sim_priv;
        u_int32_t       timeout;        /* Timeout value */
-       struct          callout timeout_ch;
-                                       /* Callout handle used for timeouts */
+       struct  callout *timeout_ch;    /* Callout handle used for timeouts */
+       char            pad[48];        /* user/kernel structure compat */
 };
 
 /* Get Device Information CCB */
index add943e..2f8429b 100644 (file)
@@ -602,21 +602,21 @@ camperiphfree(struct cam_periph *periph)
        xpt_remove_periph(periph);
 
        if (periph->flags & CAM_PERIPH_NEW_DEV_FOUND) {
-               union ccb ccb;
+               union ccb *ccb = xpt_alloc_ccb();
                void *arg;
 
                switch (periph->deferred_ac) {
                case AC_FOUND_DEVICE:
-                       ccb.ccb_h.func_code = XPT_GDEV_TYPE;
-                       xpt_setup_ccb(&ccb.ccb_h, periph->path, /*priority*/ 1);
-                       xpt_action(&ccb);
-                       arg = &ccb;
+                       ccb->ccb_h.func_code = XPT_GDEV_TYPE;
+                       xpt_setup_ccb(&ccb->ccb_h, periph->path, /*priority*/1);
+                       xpt_action(ccb);
+                       arg = ccb;
                        break;
                case AC_PATH_REGISTERED:
-                       ccb.ccb_h.func_code = XPT_PATH_INQ;
-                       xpt_setup_ccb(&ccb.ccb_h, periph->path, /*priority*/ 1);
-                       xpt_action(&ccb);
-                       arg = &ccb;
+                       ccb->ccb_h.func_code = XPT_PATH_INQ;
+                       xpt_setup_ccb(&ccb->ccb_h, periph->path, /*priority*/1);
+                       xpt_action(ccb);
+                       arg = ccb;
                        break;
                default:
                        arg = NULL;
@@ -624,6 +624,7 @@ camperiphfree(struct cam_periph *periph)
                }
                periph->deferred_callback(NULL, periph->deferred_ac,
                                          periph->path, arg);
+               xpt_free_ccb(&ccb->ccb_h);
        }
        xpt_free_path(periph->path);
        kfree(periph, M_CAMPERIPH);
@@ -990,12 +991,15 @@ cam_periph_runccb(union ccb *ccb,
 void
 cam_freeze_devq(struct cam_path *path)
 {
-       struct ccb_hdr ccb_h;
+       struct ccb_hdr *ccb_h;
+
+       ccb_h = &xpt_alloc_ccb()->ccb_h;
+       xpt_setup_ccb(ccb_h, path, /*priority*/1);
+       ccb_h->func_code = XPT_NOOP;
+       ccb_h->flags = CAM_DEV_QFREEZE;
+       xpt_action((union ccb *)ccb_h);
 
-       xpt_setup_ccb(&ccb_h, path, /*priority*/1);
-       ccb_h.func_code = XPT_NOOP;
-       ccb_h.flags = CAM_DEV_QFREEZE;
-       xpt_action((union ccb *)&ccb_h);
+       xpt_free_ccb(ccb_h);
 }
 
 u_int32_t
@@ -1003,17 +1007,23 @@ cam_release_devq(struct cam_path *path, u_int32_t relsim_flags,
                 u_int32_t openings, u_int32_t timeout,
                 int getcount_only)
 {
-       struct ccb_relsim crs;
-
-       xpt_setup_ccb(&crs.ccb_h, path,
-                     /*priority*/1);
-       crs.ccb_h.func_code = XPT_REL_SIMQ;
-       crs.ccb_h.flags = getcount_only ? CAM_DEV_QFREEZE : 0;
-       crs.release_flags = relsim_flags;
-       crs.openings = openings;
-       crs.release_timeout = timeout;
-       xpt_action((union ccb *)&crs);
-       return (crs.qfrozen_cnt);
+       struct ccb_relsim *crs;
+       uint32_t cnt;
+
+       crs = &xpt_alloc_ccb()->crs;
+
+       xpt_setup_ccb(&crs->ccb_h, path, /*priority*/1);
+       crs->ccb_h.func_code = XPT_REL_SIMQ;
+       crs->ccb_h.flags = getcount_only ? CAM_DEV_QFREEZE : 0;
+       crs->release_flags = relsim_flags;
+       crs->openings = openings;
+       crs->release_timeout = timeout;
+       xpt_action((union ccb *)crs);
+       cnt = crs->qfrozen_cnt;
+
+       xpt_free_ccb(&crs->ccb_h);
+
+       return cnt;
 }
 
 static void
@@ -1103,11 +1113,12 @@ camperiphdone(struct cam_periph *periph, union ccb *done_ccb)
                scsi_cmd = (struct scsi_start_stop_unit *)
                                &done_ccb->csio.cdb_io.cdb_bytes;
                if (sense != 0) {
-                       struct ccb_getdev cgd;
+                       struct ccb_getdev *cgd;
                        struct scsi_sense_data *sense;
                        int    error_code, sense_key, asc, ascq;        
                        scsi_sense_action err_action;
 
+                       cgd = &xpt_alloc_ccb()->cgd;
                        sense = &done_ccb->csio.sense_data;
                        scsi_extract_sense(sense, &error_code, 
                                           &sense_key, &asc, &ascq);
@@ -1115,12 +1126,14 @@ camperiphdone(struct cam_periph *periph, union ccb *done_ccb)
                        /*
                         * Grab the inquiry data for this device.
                         */
-                       xpt_setup_ccb(&cgd.ccb_h, done_ccb->ccb_h.path,
+                       xpt_setup_ccb(&cgd->ccb_h, done_ccb->ccb_h.path,
                                      /*priority*/ 1);
-                       cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-                       xpt_action((union ccb *)&cgd);
+                       cgd->ccb_h.func_code = XPT_GDEV_TYPE;
+                       xpt_action((union ccb *)cgd);
                        err_action = scsi_error_action(&done_ccb->csio,
-                                                      &cgd.inq_data, 0);
+                                                      &cgd->inq_data, 0);
+                       xpt_free_ccb(&cgd->ccb_h);
+                       cgd = NULL;     /* safety */
 
                        /*
                         * If the error is "invalid field in CDB", 
@@ -1253,12 +1266,14 @@ cam_periph_async(struct cam_periph *periph, u_int32_t code,
 void
 cam_periph_bus_settle(struct cam_periph *periph, u_int bus_settle)
 {
-       struct ccb_getdevstats cgds;
-
-       xpt_setup_ccb(&cgds.ccb_h, periph->path, /*priority*/1);
-       cgds.ccb_h.func_code = XPT_GDEV_STATS;
-       xpt_action((union ccb *)&cgds);
-       cam_periph_freeze_after_event(periph, &cgds.last_reset, bus_settle);
+       struct ccb_getdevstats *cgds;
+
+       cgds = &xpt_alloc_ccb()->cgds;
+       xpt_setup_ccb(&cgds->ccb_h, periph->path, /*priority*/1);
+       cgds->ccb_h.func_code = XPT_GDEV_STATS;
+       xpt_action((union ccb *)cgds);
+       cam_periph_freeze_after_event(periph, &cgds->last_reset, bus_settle);
+       xpt_free_ccb(&cgds->ccb_h);
 }
 
 void
@@ -1315,23 +1330,23 @@ camperiphscsistatuserror(union ccb *ccb, cam_flags camflags,
        case SCSI_STATUS_QUEUE_FULL:
        {
                /* no decrement */
-               struct ccb_getdevstats cgds;
+               struct ccb_getdevstats *cgds;
+
+               cgds = &xpt_alloc_ccb()->cgds;
 
                /*
                 * First off, find out what the current
                 * transaction counts are.
                 */
-               xpt_setup_ccb(&cgds.ccb_h,
-                             ccb->ccb_h.path,
-                             /*priority*/1);
-               cgds.ccb_h.func_code = XPT_GDEV_STATS;
-               xpt_action((union ccb *)&cgds);
+               xpt_setup_ccb(&cgds->ccb_h, ccb->ccb_h.path, /*priority*/1);
+               cgds->ccb_h.func_code = XPT_GDEV_STATS;
+               xpt_action((union ccb *)cgds);
 
                /*
                 * If we were the only transaction active, treat
                 * the QUEUE FULL as if it were a BUSY condition.
                 */
-               if (cgds.dev_active != 0) {
+               if (cgds->dev_active != 0) {
                        int total_openings;
 
                        /*
@@ -1341,13 +1356,13 @@ camperiphscsistatuserror(union ccb *ccb, cam_flags camflags,
                         * minimum allowed tag count for this
                         * device.
                         */
-                       total_openings = cgds.dev_active + cgds.dev_openings;
-                       *openings = cgds.dev_active;
-                       if (*openings < cgds.mintags)
-                               *openings = cgds.mintags;
-                       if (*openings < total_openings)
+                       total_openings = cgds->dev_active + cgds->dev_openings;
+                       *openings = cgds->dev_active;
+                       if (*openings < cgds->mintags)
+                               *openings = cgds->mintags;
+                       if (*openings < total_openings) {
                                *relsim_flags = RELSIM_ADJUST_OPENINGS;
-                       else {
+                       else {
                                /*
                                 * Some devices report queue full for
                                 * temporary resource shortages.  For
@@ -1367,8 +1382,10 @@ camperiphscsistatuserror(union ccb *ccb, cam_flags camflags,
                        if (bootverbose) {
                                xpt_print(ccb->ccb_h.path, "Queue Full\n");
                        }
+                       xpt_free_ccb(&cgds->ccb_h);
                        break;
                }
+               xpt_free_ccb(&cgds->ccb_h);
                /* FALLTHROUGH */
        }
        case SCSI_STATUS_BUSY:
@@ -1430,7 +1447,7 @@ camperiphscsisenseerror(union ccb *ccb, cam_flags camflags,
                error = ERESTART;
        } else {
                scsi_sense_action err_action;
-               struct ccb_getdev cgd;
+               struct ccb_getdev *cgd;
                const char *action_string;
                union ccb* print_ccb;
 
@@ -1446,13 +1463,14 @@ camperiphscsisenseerror(union ccb *ccb, cam_flags camflags,
                /*
                 * Grab the inquiry data for this device.
                 */
-               xpt_setup_ccb(&cgd.ccb_h, ccb->ccb_h.path, /*priority*/ 1);
-               cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-               xpt_action((union ccb *)&cgd);
+               cgd = &xpt_alloc_ccb()->cgd;
+               xpt_setup_ccb(&cgd->ccb_h, ccb->ccb_h.path, /*priority*/ 1);
+               cgd->ccb_h.func_code = XPT_GDEV_TYPE;
+               xpt_action((union ccb *)cgd);
 
                if ((ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0)
                        err_action = scsi_error_action(&ccb->csio,
-                                                      &cgd.inq_data,
+                                                      &cgd->inq_data,
                                                       sense_flags);
                else if ((ccb->ccb_h.flags & CAM_DIS_AUTOSENSE) == 0)
                        err_action = SS_REQSENSE;
@@ -1514,7 +1532,7 @@ camperiphscsisenseerror(union ccb *ccb, cam_flags camflags,
                         * Check for removable media and set
                         * load/eject flag appropriately.
                         */
-                       if (SID_IS_REMOVABLE(&cgd.inq_data))
+                       if (SID_IS_REMOVABLE(&cgd->inq_data))
                                le = TRUE;
                        else
                                le = FALSE;
@@ -1600,14 +1618,15 @@ camperiphscsisenseerror(union ccb *ccb, cam_flags camflags,
                }
 
 sense_error_done:
-               if ((err_action & SSQ_PRINT_SENSE) != 0
-                && (ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0) {
+               if ((err_action & SSQ_PRINT_SENSE) != 0 &&
+                   (ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0) {
                        cam_error_print(print_ccb, CAM_ESF_ALL, CAM_EPF_ALL);
                        xpt_print_path(ccb->ccb_h.path);
                        if (bootverbose)
                                scsi_sense_print(&print_ccb->csio);
                        kprintf("%s\n", action_string);
                }
+               xpt_free_ccb(&cgd->ccb_h);
        }
        return (error);
 }
index ceaec4e..b71a5c5 100644 (file)
@@ -1066,7 +1066,7 @@ xptioctl(struct dev_ioctl_args *ap)
                                            CAM_REQ_CMP){
                                error = EINVAL;
                                CAM_SIM_UNLOCK(bus->sim);
-                               xpt_free_ccb(ccb);
+                               xpt_free_ccb(&ccb->ccb_h);
                                break;
                        }
                        /* Ensure all of our fields are correct */
@@ -1077,12 +1077,14 @@ xptioctl(struct dev_ioctl_args *ap)
                        cam_periph_runccb(ccb, NULL, 0, 0, NULL);
                        bcopy(ccb, inccb, sizeof(union ccb));
                        xpt_free_path(ccb->ccb_h.path);
-                       xpt_free_ccb(ccb);
+                       xpt_free_ccb(&ccb->ccb_h);
                        CAM_SIM_UNLOCK(bus->sim);
                        break;
 
                case XPT_DEBUG: {
-                       union ccb ccb;
+                       union ccb *ccb;
+
+                       ccb = xpt_alloc_ccb();
 
                        /*
                         * This is an immediate CCB, so it's okay to
@@ -1095,24 +1097,28 @@ xptioctl(struct dev_ioctl_args *ap)
                         * Create a path using the bus, target, and lun the
                         * user passed in.
                         */
-                       if (xpt_create_path(&ccb.ccb_h.path, xpt_periph,
+                       if (xpt_create_path(&ccb->ccb_h.path, xpt_periph,
                                            inccb->ccb_h.path_id,
                                            inccb->ccb_h.target_id,
                                            inccb->ccb_h.target_lun) !=
                                            CAM_REQ_CMP){
                                error = EINVAL;
                                CAM_SIM_UNLOCK(bus->sim);
+                               xpt_free_ccb(&ccb->ccb_h);
                                break;
                        }
                        /* Ensure all of our fields are correct */
-                       xpt_setup_ccb(&ccb.ccb_h, ccb.ccb_h.path,
+                       xpt_setup_ccb(&ccb->ccb_h, ccb->ccb_h.path,
                                      inccb->ccb_h.pinfo.priority);
-                       xpt_merge_ccb(&ccb, inccb);
-                       ccb.ccb_h.cbfcnp = xptdone;
-                       xpt_action(&ccb);
+                       xpt_merge_ccb(ccb, inccb);
+                       ccb->ccb_h.cbfcnp = xptdone;
+                       xpt_action(ccb);
                        CAM_SIM_UNLOCK(bus->sim);
-                       bcopy(&ccb, inccb, sizeof(union ccb));
-                       xpt_free_path(ccb.ccb_h.path);
+                       bcopy(ccb, inccb, sizeof(union ccb));
+                       inccb->ccb_h.timeout_ch = NULL; /* SAFETY */
+                       xpt_free_path(ccb->ccb_h.path);
+                       xpt_free_ccb(&ccb->ccb_h);
+
                        break;
 
                }
@@ -1618,8 +1624,8 @@ xpt_remove_periph(struct cam_periph *periph)
 void
 xpt_announce_periph(struct cam_periph *periph, char *announce_string)
 {
-       struct  ccb_pathinq cpi;
-       struct  ccb_trans_settings cts;
+       struct  ccb_pathinq *cpi;
+       struct  ccb_trans_settings *cts;
        struct  cam_path *path;
        u_int   speed;
        u_int   freq;
@@ -1648,25 +1654,28 @@ xpt_announce_periph(struct cam_periph *periph, char *announce_string)
        }
 
        /* Acquire and report transfer speed */
-       xpt_setup_ccb(&cts.ccb_h, path, /*priority*/1);
-       cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
-       cts.type = CTS_TYPE_CURRENT_SETTINGS;
-       xpt_action((union ccb*)&cts);
-       if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+       cts = &xpt_alloc_ccb()->cts;
+       xpt_setup_ccb(&cts->ccb_h, path, /*priority*/1);
+       cts->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
+       cts->type = CTS_TYPE_CURRENT_SETTINGS;
+       xpt_action((union ccb*)cts);
+       if ((cts->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+               xpt_free_ccb(&cts->ccb_h);
                return;
        }
 
        /* Ask the SIM for its base transfer speed */
-       xpt_setup_ccb(&cpi.ccb_h, path, /*priority*/1);
-       cpi.ccb_h.func_code = XPT_PATH_INQ;
-       xpt_action((union ccb *)&cpi);
+       cpi = &xpt_alloc_ccb()->cpi;
+       xpt_setup_ccb(&cpi->ccb_h, path, /*priority*/1);
+       cpi->ccb_h.func_code = XPT_PATH_INQ;
+       xpt_action((union ccb *)cpi);
 
-       speed = cpi.base_transfer_speed;
+       speed = cpi->base_transfer_speed;
        freq = 0;
-       if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
+       if (cts->ccb_h.status == CAM_REQ_CMP && cts->transport == XPORT_SPI) {
                struct  ccb_trans_settings_spi *spi;
 
-               spi = &cts.xport_specific.spi;
+               spi = &cts->xport_specific.spi;
                if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
                  && spi->sync_offset != 0) {
                        freq = scsi_calc_syncsrate(spi->sync_period);
@@ -1676,15 +1685,15 @@ xpt_announce_periph(struct cam_periph *periph, char *announce_string)
                if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
                        speed *= (0x01 << spi->bus_width);
        }
-       if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
-               struct  ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
+       if (cts->ccb_h.status == CAM_REQ_CMP && cts->transport == XPORT_FC) {
+               struct  ccb_trans_settings_fc *fc = &cts->xport_specific.fc;
                if (fc->valid & CTS_FC_VALID_SPEED) {
                        speed = fc->bitrate;
                }
        }
 
-       if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
-               struct  ccb_trans_settings_sas *sas = &cts.xport_specific.sas;
+       if (cts->ccb_h.status == CAM_REQ_CMP && cts->transport == XPORT_SAS) {
+               struct  ccb_trans_settings_sas *sas = &cts->xport_specific.sas;
                if (sas->valid & CTS_SAS_VALID_SPEED) {
                        speed = sas->bitrate;
                }
@@ -1700,10 +1709,10 @@ xpt_announce_periph(struct cam_periph *periph, char *announce_string)
                       periph->unit_number, speed);
 
        /* Report additional information about SPI connections */
-       if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
+       if (cts->ccb_h.status == CAM_REQ_CMP && cts->transport == XPORT_SPI) {
                struct  ccb_trans_settings_spi *spi;
 
-               spi = &cts.xport_specific.spi;
+               spi = &cts->xport_specific.spi;
                if (freq != 0) {
                        kprintf(" (%d.%03dMHz%s, offset %d", freq / 1000,
                               freq % 1000,
@@ -1723,10 +1732,10 @@ xpt_announce_periph(struct cam_periph *periph, char *announce_string)
                        kprintf(")");
                }
        }
-       if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
+       if (cts->ccb_h.status == CAM_REQ_CMP && cts->transport == XPORT_FC) {
                struct  ccb_trans_settings_fc *fc;
 
-               fc = &cts.xport_specific.fc;
+               fc = &cts->xport_specific.fc;
                if (fc->valid & CTS_FC_VALID_WWNN)
                        kprintf(" WWNN 0x%llx", (long long) fc->wwnn);
                if (fc->valid & CTS_FC_VALID_WWPN)
@@ -1735,13 +1744,16 @@ xpt_announce_periph(struct cam_periph *periph, char *announce_string)
                        kprintf(" PortID 0x%x", fc->port);
        }
 
-       if (path->device->inq_flags & SID_CmdQue
-        || path->device->flags & CAM_DEV_TAG_AFTER_COUNT) {
+       if (path->device->inq_flags & SID_CmdQue ||
+           path->device->flags & CAM_DEV_TAG_AFTER_COUNT) {
                kprintf("\n%s%d: Command Queueing Enabled",
                       periph->periph_name, periph->unit_number);
        }
        kprintf("\n");
 
+       xpt_free_ccb(&cpi->ccb_h);
+       xpt_free_ccb(&cts->ccb_h);
+
        /*
         * We only want to print the caller's announce string if they've
         * passed one in..
@@ -2866,7 +2878,7 @@ static int
 xptsetasyncfunc(struct cam_ed *device, void *arg)
 {
        struct cam_path path;
-       struct ccb_getdev cgd;
+       struct ccb_getdev *cgd;
        struct async_node *cur_entry;
 
        cur_entry = (struct async_node *)arg;
@@ -2885,13 +2897,16 @@ xptsetasyncfunc(struct cam_ed *device, void *arg)
                         device->target->bus->path_id,
                         device->target->target_id,
                         device->lun_id);
-       xpt_setup_ccb(&cgd.ccb_h, &path, /*priority*/1);
-       cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-       xpt_action((union ccb *)&cgd);
+
+       cgd = &xpt_alloc_ccb()->cgd;
+       xpt_setup_ccb(&cgd->ccb_h, &path, /*priority*/1);
+       cgd->ccb_h.func_code = XPT_GDEV_TYPE;
+       xpt_action((union ccb *)cgd);
        cur_entry->callback(cur_entry->callback_arg,
                            AC_FOUND_DEVICE,
-                           &path, &cgd);
+                           &path, cgd);
        xpt_release_path(&path);
+       xpt_free_ccb(&cgd->ccb_h);
 
        return(1);
 }
@@ -2900,7 +2915,7 @@ static int
 xptsetasyncbusfunc(struct cam_eb *bus, void *arg)
 {
        struct cam_path path;
-       struct ccb_pathinq cpi;
+       struct ccb_pathinq *cpi;
        struct async_node *cur_entry;
 
        cur_entry = (struct async_node *)arg;
@@ -2909,13 +2924,15 @@ xptsetasyncbusfunc(struct cam_eb *bus, void *arg)
                         bus->sim->path_id,
                         CAM_TARGET_WILDCARD,
                         CAM_LUN_WILDCARD);
-       xpt_setup_ccb(&cpi.ccb_h, &path, /*priority*/1);
-       cpi.ccb_h.func_code = XPT_PATH_INQ;
-       xpt_action((union ccb *)&cpi);
+       cpi = &xpt_alloc_ccb()->cpi;
+       xpt_setup_ccb(&cpi->ccb_h, &path, /*priority*/1);
+       cpi->ccb_h.func_code = XPT_PATH_INQ;
+       xpt_action((union ccb *)cpi);
        cur_entry->callback(cur_entry->callback_arg,
                            AC_PATH_REGISTERED,
-                           &path, &cpi);
+                           &path, cpi);
        xpt_release_path(&path);
+       xpt_free_ccb(&cpi->ccb_h);
 
        return(1);
 }
@@ -3885,7 +3902,7 @@ void
 xpt_setup_ccb(struct ccb_hdr *ccb_h, struct cam_path *path, u_int32_t priority)
 {
        CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_setup_ccb\n"));
-       callout_init(&ccb_h->timeout_ch);
+       callout_init(ccb_h->timeout_ch);
        ccb_h->pinfo.priority = priority;
        ccb_h->path = path;
        ccb_h->path_id = path->bus->path_id;
@@ -4243,13 +4260,13 @@ xpt_release_ccb(union ccb *free_ccb)
 
        cam_ccbq_release_opening(&device->ccbq);
        if (sim->ccb_count > sim->max_ccbs) {
-               xpt_free_ccb(free_ccb);
+               xpt_free_ccb(&free_ccb->ccb_h);
                sim->ccb_count--;
        } else if (sim == &cam_dead_sim) {
-               xpt_free_ccb(free_ccb);
+               xpt_free_ccb(&free_ccb->ccb_h);
        } else  {
                SLIST_INSERT_HEAD(&sim->ccb_freeq, &free_ccb->ccb_h,
-                   xpt_links.sle);
+                                 xpt_links.sle);
        }
        if (sim->devq == NULL) {
                return;
@@ -4281,7 +4298,7 @@ xpt_bus_register(struct cam_sim *sim, u_int32_t bus)
 {
        struct cam_eb *new_bus;
        struct cam_eb *old_bus;
-       struct ccb_pathinq cpi;
+       struct ccb_pathinq *cpi;
 
        sim_lock_assert_owned(sim->lock);
 
@@ -4321,13 +4338,15 @@ xpt_bus_register(struct cam_sim *sim, u_int32_t bus)
        if (sim->path_id != CAM_XPT_PATH_ID) {
                struct cam_path path;
 
+               cpi = &xpt_alloc_ccb()->cpi;
                xpt_compile_path(&path, /*periph*/NULL, sim->path_id,
                                 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
-               xpt_setup_ccb(&cpi.ccb_h, &path, /*priority*/1);
-               cpi.ccb_h.func_code = XPT_PATH_INQ;
-               xpt_action((union ccb *)&cpi);
-               xpt_async(AC_PATH_REGISTERED, &path, &cpi);
+               xpt_setup_ccb(&cpi->ccb_h, &path, /*priority*/1);
+               cpi->ccb_h.func_code = XPT_PATH_INQ;
+               xpt_action((union ccb *)cpi);
+               xpt_async(AC_PATH_REGISTERED, &path, cpi);
                xpt_release_path(&path);
+               xpt_free_ccb(&cpi->ccb_h);
        }
        return (CAM_SUCCESS);
 }
@@ -4911,17 +4930,21 @@ xpt_alloc_ccb(void)
        union ccb *new_ccb;
 
        new_ccb = kmalloc(sizeof(*new_ccb), M_CAMXPT, M_INTWAIT | M_ZERO);
+       new_ccb->ccb_h.timeout_ch = kmalloc(sizeof(struct callout), M_CAMXPT,
+                                           M_INTWAIT | M_ZERO);
+
        return (new_ccb);
 }
 
 void
-xpt_free_ccb(union ccb *free_ccb)
+xpt_free_ccb(struct ccb_hdr *free_ccb)
 {
+       KKASSERT(free_ccb->timeout_ch != NULL);
+       kfree(free_ccb->timeout_ch, M_CAMXPT);
+       free_ccb->timeout_ch = NULL;
        kfree(free_ccb, M_CAMXPT);
 }
 
-
-
 /* Private XPT functions */
 
 /*
@@ -4941,7 +4964,7 @@ xpt_get_ccb(struct cam_ed *device)
        if ((new_ccb = (union ccb *)SLIST_FIRST(&sim->ccb_freeq)) == NULL) {
                new_ccb = xpt_alloc_ccb();
                if ((sim->flags & CAM_SIM_MPSAFE) == 0)
-                       callout_init(&new_ccb->ccb_h.timeout_ch);
+                       callout_init(new_ccb->ccb_h.timeout_ch);
                SLIST_INSERT_HEAD(&sim->ccb_freeq, &new_ccb->ccb_h,
                                  xpt_links.sle);
                sim->ccb_count++;
@@ -5315,7 +5338,7 @@ xpt_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
                xpt_action(work_ccb);
                if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
                        request_ccb->ccb_h.status = work_ccb->ccb_h.status;
-                       xpt_free_ccb(work_ccb);
+                       xpt_free_ccb(&work_ccb->ccb_h);
                        xpt_done(request_ccb);
                        return;
                }
@@ -5326,7 +5349,7 @@ xpt_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
                         * cannot perform the initiator role.
                         */
                        request_ccb->ccb_h.status = CAM_REQ_CMP;
-                       xpt_free_ccb(work_ccb);
+                       xpt_free_ccb(&work_ccb->ccb_h);
                        xpt_done(request_ccb);
                        return;
                }
@@ -5369,7 +5392,7 @@ xpt_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
                                       status);
                                kfree(scan_info, M_CAMXPT);
                                request_ccb->ccb_h.status = status;
-                               xpt_free_ccb(work_ccb);
+                               xpt_free_ccb(&work_ccb->ccb_h);
                                xpt_done(request_ccb);
                                break;
                        }
@@ -5478,8 +5501,8 @@ xpt_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
                                }
                        }
                        if (done) {
-                               xpt_free_ccb(request_ccb);
-                               xpt_free_ccb((union ccb *)scan_info->cpi);
+                               xpt_free_ccb(&request_ccb->ccb_h);
+                               xpt_free_ccb(&scan_info->cpi->ccb_h);
                                request_ccb = scan_info->request_ccb;
                                kfree(scan_info, M_CAMXPT);
                                request_ccb->ccb_h.status = CAM_REQ_CMP;
@@ -5497,8 +5520,8 @@ xpt_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
                                kprintf("xpt_scan_bus: xpt_create_path failed"
                                    " with status %#x, bus scan halted\n",
                                    status);
-                               xpt_free_ccb(request_ccb);
-                               xpt_free_ccb((union ccb *)scan_info->cpi);
+                               xpt_free_ccb(&request_ccb->ccb_h);
+                               xpt_free_ccb(&scan_info->cpi->ccb_h);
                                request_ccb = scan_info->request_ccb;
                                kfree(scan_info, M_CAMXPT);
                                request_ccb->ccb_h.status = status;
@@ -5506,7 +5529,7 @@ xpt_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
                                break;
                        }
                        xpt_setup_ccb(&request_ccb->ccb_h, path,
-                           request_ccb->ccb_h.pinfo.priority);
+                                     request_ccb->ccb_h.pinfo.priority);
                        request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
                        request_ccb->ccb_h.cbfcnp = xpt_scan_bus;
                        request_ccb->ccb_h.ppriv_ptr0 = scan_info;
@@ -5595,7 +5618,7 @@ static void
 xpt_scan_lun(struct cam_periph *periph, struct cam_path *path,
             cam_flags flags, union ccb *request_ccb)
 {
-       struct ccb_pathinq cpi;
+       struct ccb_pathinq *cpi;
        cam_status status;
        struct cam_path *new_path;
        struct cam_periph *old_periph;
@@ -5603,19 +5626,21 @@ xpt_scan_lun(struct cam_periph *periph, struct cam_path *path,
        CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
                  ("xpt_scan_lun\n"));
 
-       xpt_setup_ccb(&cpi.ccb_h, path, /*priority*/1);
-       cpi.ccb_h.func_code = XPT_PATH_INQ;
-       xpt_action((union ccb *)&cpi);
+       cpi = &xpt_alloc_ccb()->cpi;
+       xpt_setup_ccb(&cpi->ccb_h, path, /*priority*/1);
+       cpi->ccb_h.func_code = XPT_PATH_INQ;
+       xpt_action((union ccb *)cpi);
 
-       if (cpi.ccb_h.status != CAM_REQ_CMP) {
+       if (cpi->ccb_h.status != CAM_REQ_CMP) {
                if (request_ccb != NULL) {
-                       request_ccb->ccb_h.status = cpi.ccb_h.status;
+                       request_ccb->ccb_h.status = cpi->ccb_h.status;
                        xpt_done(request_ccb);
                }
+               xpt_free_ccb(&cpi->ccb_h);
                return;
        }
 
-       if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
+       if ((cpi->hba_misc & PIM_NOINITIATOR) != 0) {
                /*
                 * Can't scan the bus on an adapter that
                 * cannot perform the initiator role.
@@ -5624,11 +5649,13 @@ xpt_scan_lun(struct cam_periph *periph, struct cam_path *path,
                        request_ccb->ccb_h.status = CAM_REQ_CMP;
                        xpt_done(request_ccb);
                }
+               xpt_free_ccb(&cpi->ccb_h);
                return;
        }
+       xpt_free_ccb(&cpi->ccb_h);
 
        if (request_ccb == NULL) {
-               request_ccb = kmalloc(sizeof(union ccb), M_CAMXPT, M_INTWAIT);
+               request_ccb = xpt_alloc_ccb();
                new_path = kmalloc(sizeof(*new_path), M_CAMXPT, M_INTWAIT);
                status = xpt_compile_path(new_path, xpt_periph,
                                          path->bus->path_id,
@@ -5638,7 +5665,7 @@ xpt_scan_lun(struct cam_periph *periph, struct cam_path *path,
                if (status != CAM_REQ_CMP) {
                        xpt_print(path, "xpt_scan_lun: can't compile path, "
                            "can't continue\n");
-                       kfree(request_ccb, M_CAMXPT);
+                       xpt_free_ccb(&request_ccb->ccb_h);
                        kfree(new_path, M_CAMXPT);
                        return;
                }
@@ -5675,7 +5702,7 @@ xptscandone(struct cam_periph *periph, union ccb *done_ccb)
 {
        xpt_release_path(done_ccb->ccb_h.path);
        kfree(done_ccb->ccb_h.path, M_CAMXPT);
-       kfree(done_ccb, M_CAMXPT);
+       xpt_free_ccb(&done_ccb->ccb_h);
 }
 
 static cam_status
@@ -5725,16 +5752,17 @@ proberegister(struct cam_periph *periph, void *arg)
 static void
 probeschedule(struct cam_periph *periph)
 {
-       struct ccb_pathinq cpi;
+       struct ccb_pathinq *cpi;
        union ccb *ccb;
        probe_softc *softc;
 
        softc = (probe_softc *)periph->softc;
        ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
 
-       xpt_setup_ccb(&cpi.ccb_h, periph->path, /*priority*/1);
-       cpi.ccb_h.func_code = XPT_PATH_INQ;
-       xpt_action((union ccb *)&cpi);
+       cpi = &xpt_alloc_ccb()->cpi;
+       xpt_setup_ccb(&cpi->ccb_h, periph->path, /*priority*/1);
+       cpi->ccb_h.func_code = XPT_PATH_INQ;
+       xpt_action((union ccb *)cpi);
 
        /*
         * If a device has gone away and another device, or the same one,
@@ -5757,8 +5785,8 @@ probeschedule(struct cam_periph *periph)
        if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
         && (ccb->ccb_h.target_lun == 0)) {
                PROBE_SET_ACTION(softc, PROBE_TUR);
-       } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
-             && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
+       } else if ((cpi->hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
+             && (cpi->hba_misc & PIM_NOBUSRESET) != 0) {
                proberequestdefaultnegotiation(periph);
                PROBE_SET_ACTION(softc, PROBE_INQUIRY);
        } else {
@@ -5771,6 +5799,7 @@ probeschedule(struct cam_periph *periph)
                softc->flags &= ~PROBE_NO_ANNOUNCE;
 
        xpt_schedule(periph, ccb->ccb_h.pinfo.priority);
+       xpt_free_ccb(&cpi->ccb_h);
 }
 
 static void
@@ -5951,18 +5980,21 @@ probestart(struct cam_periph *periph, union ccb *start_ccb)
 static void
 proberequestdefaultnegotiation(struct cam_periph *periph)
 {
-       struct ccb_trans_settings cts;
+       struct ccb_trans_settings *cts;
 
-       xpt_setup_ccb(&cts.ccb_h, periph->path, /*priority*/1);
-       cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
-       cts.type = CTS_TYPE_USER_SETTINGS;
-       xpt_action((union ccb *)&cts);
-       if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+       cts = &xpt_alloc_ccb()->cts;
+       xpt_setup_ccb(&cts->ccb_h, periph->path, /*priority*/1);
+       cts->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
+       cts->type = CTS_TYPE_USER_SETTINGS;
+       xpt_action((union ccb *)cts);
+       if ((cts->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+               xpt_free_ccb(&cts->ccb_h);
                return;
        }
-       cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
-       cts.type = CTS_TYPE_CURRENT_SETTINGS;
-       xpt_action((union ccb *)&cts);
+       cts->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
+       cts->type = CTS_TYPE_CURRENT_SETTINGS;
+       xpt_action((union ccb *)cts);
+       xpt_free_ccb(&cts->ccb_h);
 }
 
 /*
@@ -5971,28 +6003,30 @@ proberequestdefaultnegotiation(struct cam_periph *periph)
 static int
 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
 {
-       struct ccb_trans_settings cts;
+       struct ccb_trans_settings *cts;
        struct ccb_trans_settings_spi *spi;
-
-       memset(&cts, 0, sizeof (cts));
-       xpt_setup_ccb(&cts.ccb_h, periph->path, /*priority*/1);
-       cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
-       cts.type = CTS_TYPE_CURRENT_SETTINGS;
-       xpt_action((union ccb *)&cts);
-       if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+       int result;
+
+       result = 0;
+       cts = &xpt_alloc_ccb()->cts;
+       xpt_setup_ccb(&cts->ccb_h, periph->path, /*priority*/1);
+       cts->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
+       cts->type = CTS_TYPE_CURRENT_SETTINGS;
+       xpt_action((union ccb *)cts);
+       if ((cts->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
                if (bootverbose) {
                        xpt_print(periph->path,
                            "failed to get current device settings\n");
                }
-               return (0);
+               goto done;
        }
-       if (cts.transport != XPORT_SPI) {
+       if (cts->transport != XPORT_SPI) {
                if (bootverbose) {
                        xpt_print(periph->path, "not SPI transport\n");
                }
-               return (0);
+               goto done;
        }
-       spi = &cts.xport_specific.spi;
+       spi = &cts->xport_specific.spi;
 
        /*
         * We cannot renegotiate sync rate if we don't have one.
@@ -6001,7 +6035,7 @@ proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
                if (bootverbose) {
                        xpt_print(periph->path, "no sync rate known\n");
                }
-               return (0);
+               goto done;
        }
 
        /*
@@ -6019,13 +6053,13 @@ proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
                if (bootverbose) {
                        xpt_print(periph->path, "no sync rate available\n");
                }
-               return (0);
+               goto done;
        }
 
        if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
                CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
                    ("hit async: giving up on DV\n"));
-               return (0);
+               goto done;
        }
 
 
@@ -6055,19 +6089,22 @@ proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
                            ("DV: period 0x%x\n", spi->sync_period));
                        kprintf("setting period to 0x%x\n", spi->sync_period);
                }
-               cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
-               cts.type = CTS_TYPE_CURRENT_SETTINGS;
-               xpt_action((union ccb *)&cts);
-               if ((cts.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
+               cts->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
+               cts->type = CTS_TYPE_CURRENT_SETTINGS;
+               xpt_action((union ccb *)cts);
+               if ((cts->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
                        break;
                }
                CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
                    ("DV: failed to set period 0x%x\n", spi->sync_period));
-               if (spi->sync_period == 0) {
-                       return (0);
-               }
+               if (spi->sync_period == 0)
+                       goto done;
        }
-       return (1);
+       result = 1;
+done:
+       xpt_free_ccb(&cts->ccb_h);
+
+       return result;
 }
 
 static void
@@ -6525,23 +6562,26 @@ sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
 static void
 xpt_devise_transport(struct cam_path *path)
 {
-       struct ccb_pathinq cpi;
-       struct ccb_trans_settings cts;
+       struct ccb_pathinq *cpi;
+       struct ccb_trans_settings *cts;
        struct scsi_inquiry_data *inq_buf;
 
        /* Get transport information from the SIM */
-       xpt_setup_ccb(&cpi.ccb_h, path, /*priority*/1);
-       cpi.ccb_h.func_code = XPT_PATH_INQ;
-       xpt_action((union ccb *)&cpi);
+       cpi = &xpt_alloc_ccb()->cpi;
+       cts = &xpt_alloc_ccb()->cts;
+
+       xpt_setup_ccb(&cpi->ccb_h, path, /*priority*/1);
+       cpi->ccb_h.func_code = XPT_PATH_INQ;
+       xpt_action((union ccb *)cpi);
 
        inq_buf = NULL;
        if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
                inq_buf = &path->device->inq_data;
        path->device->protocol = PROTO_SCSI;
        path->device->protocol_version =
-           inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
-       path->device->transport = cpi.transport;
-       path->device->transport_version = cpi.transport_version;
+           inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi->protocol_version;
+       path->device->transport = cpi->transport;
+       path->device->transport_version = cpi->transport_version;
 
        /*
         * Any device not using SPI3 features should
@@ -6590,24 +6630,27 @@ xpt_devise_transport(struct cam_path *path)
         */
 
        /* Tell the controller what we think */
-       xpt_setup_ccb(&cts.ccb_h, path, /*priority*/1);
-       cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
-       cts.type = CTS_TYPE_CURRENT_SETTINGS;
-       cts.transport = path->device->transport;
-       cts.transport_version = path->device->transport_version;
-       cts.protocol = path->device->protocol;
-       cts.protocol_version = path->device->protocol_version;
-       cts.proto_specific.valid = 0;
-       cts.xport_specific.valid = 0;
-       xpt_action((union ccb *)&cts);
+       xpt_setup_ccb(&cts->ccb_h, path, /*priority*/1);
+       cts->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
+       cts->type = CTS_TYPE_CURRENT_SETTINGS;
+       cts->transport = path->device->transport;
+       cts->transport_version = path->device->transport_version;
+       cts->protocol = path->device->protocol;
+       cts->protocol_version = path->device->protocol_version;
+       cts->proto_specific.valid = 0;
+       cts->xport_specific.valid = 0;
+       xpt_action((union ccb *)cts);
+
+       xpt_free_ccb(&cts->ccb_h);
+       xpt_free_ccb(&cpi->ccb_h);
 }
 
 static void
 xpt_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
                          int async_update)
 {
-       struct  ccb_pathinq cpi;
-       struct  ccb_trans_settings cur_cts;
+       struct  ccb_pathinq *cpi;
+       struct  ccb_trans_settings *cur_cts;
        struct  ccb_trans_settings_scsi *scsi;
        struct  ccb_trans_settings_scsi *cur_scsi;
        struct  cam_sim *sim;
@@ -6682,14 +6725,17 @@ xpt_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
                return;
        }
 
+       cpi = &xpt_alloc_ccb()->cpi;
+       cur_cts = &xpt_alloc_ccb()->cts;
+
        inq_data = &device->inq_data;
        scsi = &cts->proto_specific.scsi;
-       xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, /*priority*/1);
-       cpi.ccb_h.func_code = XPT_PATH_INQ;
-       xpt_action((union ccb *)&cpi);
+       xpt_setup_ccb(&cpi->ccb_h, cts->ccb_h.path, /*priority*/1);
+       cpi->ccb_h.func_code = XPT_PATH_INQ;
+       xpt_action((union ccb *)cpi);
 
        /* SCSI specific sanity checking */
-       if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
+       if ((cpi->hba_inquiry & PI_TAG_ABLE) == 0
         || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
         || (device->queue_flags & SCP_QUEUE_DQUE) != 0
         || (device->quirk->mintags == 0)) {
@@ -6705,14 +6751,14 @@ xpt_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
                 * Perform sanity checking against what the
                 * controller and device can do.
                 */
-               xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, /*priority*/1);
-               cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
-               cur_cts.type = cts->type;
-               xpt_action((union ccb *)&cur_cts);
-               if ((cur_cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
-                       return;
-               }
-               cur_scsi = &cur_cts.proto_specific.scsi;
+               xpt_setup_ccb(&cur_cts->ccb_h, cts->ccb_h.path, /*priority*/1);
+               cur_cts->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
+               cur_cts->type = cts->type;
+               xpt_action((union ccb *)cur_cts);
+               if ((cur_cts->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+                       goto done;
+               }
+               cur_scsi = &cur_cts->proto_specific.scsi;
                if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
                        scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
                        scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
@@ -6729,7 +6775,7 @@ xpt_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
 
                spi = &cts->xport_specific.spi;
 
-               cur_spi = &cur_cts.xport_specific.spi;
+               cur_spi = &cur_cts->xport_specific.spi;
 
                /* Fill in any gaps in what the user gave us */
                if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
@@ -6757,7 +6803,7 @@ xpt_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
                if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
                  && (inq_data->flags & SID_Sync) == 0
                  && cts->type == CTS_TYPE_CURRENT_SETTINGS)
-                || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
+                || ((cpi->hba_inquiry & PI_SDTR_ABLE) == 0)) {
                        /* Force async */
                        spi->sync_period = 0;
                        spi->sync_offset = 0;
@@ -6768,14 +6814,14 @@ xpt_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
                        if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
                          || (inq_data->flags & SID_WBus32) != 0
                          || cts->type == CTS_TYPE_USER_SETTINGS)
-                        && (cpi.hba_inquiry & PI_WIDE_32) != 0)
+                        && (cpi->hba_inquiry & PI_WIDE_32) != 0)
                                break;
                        /* Fall Through to 16-bit */
                case MSG_EXT_WDTR_BUS_16_BIT:
                        if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
                          || (inq_data->flags & SID_WBus16) != 0
                          || cts->type == CTS_TYPE_USER_SETTINGS)
-                        && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
+                        && (cpi->hba_inquiry & PI_WIDE_16) != 0) {
                                spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
                                break;
                        }
@@ -6787,7 +6833,7 @@ xpt_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
                        break;
                }
 
-               spi3caps = cpi.xport_specific.spi.ppr_options;
+               spi3caps = cpi->xport_specific.spi.ppr_options;
                if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
                 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
                        spi3caps &= inq_data->spi3data;
@@ -6886,6 +6932,9 @@ xpt_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
        }
        if (async_update == FALSE)
                (*(sim->sim_action))(sim, (union ccb *)cts);
+done:
+       xpt_free_ccb(&cur_cts->ccb_h);
+       xpt_free_ccb(&cpi->ccb_h);
 }
 
 static void
@@ -6904,31 +6953,34 @@ xpt_toggle_tags(struct cam_path *path)
        if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
         || ((dev->inq_flags & SID_CmdQue) != 0
          && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
-               struct ccb_trans_settings cts;
-
-               xpt_setup_ccb(&cts.ccb_h, path, 1);
-               cts.protocol = PROTO_SCSI;
-               cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
-               cts.transport = XPORT_UNSPECIFIED;
-               cts.transport_version = XPORT_VERSION_UNSPECIFIED;
-               cts.proto_specific.scsi.flags = 0;
-               cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
-               xpt_set_transfer_settings(&cts, path->device,
+               struct ccb_trans_settings *cts;
+
+               cts = &xpt_alloc_ccb()->cts;
+               xpt_setup_ccb(&cts->ccb_h, path, 1);
+               cts->protocol = PROTO_SCSI;
+               cts->protocol_version = PROTO_VERSION_UNSPECIFIED;
+               cts->transport = XPORT_UNSPECIFIED;
+               cts->transport_version = XPORT_VERSION_UNSPECIFIED;
+               cts->proto_specific.scsi.flags = 0;
+               cts->proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
+               xpt_set_transfer_settings(cts, path->device,
                                          /*async_update*/TRUE);
-               cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
-               xpt_set_transfer_settings(&cts, path->device,
+               cts->proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
+               xpt_set_transfer_settings(cts, path->device,
                                          /*async_update*/TRUE);
+               xpt_free_ccb(&cts->ccb_h);
        }
 }
 
 static void
 xpt_start_tags(struct cam_path *path)
 {
-       struct ccb_relsim crs;
+       struct ccb_relsim *crs;
        struct cam_ed *device;
        struct cam_sim *sim;
        int    newopenings;
 
+       crs = &xpt_alloc_ccb()->crs;
        device = path->device;
        sim = path->bus->sim;
        device->flags &= ~CAM_DEV_TAG_AFTER_COUNT;
@@ -6940,14 +6992,15 @@ xpt_start_tags(struct cam_path *path)
                newopenings = min(device->quirk->maxtags,
                                  sim->max_tagged_dev_openings);
        xpt_dev_ccbq_resize(path, newopenings);
-       xpt_setup_ccb(&crs.ccb_h, path, /*priority*/1);
-       crs.ccb_h.func_code = XPT_REL_SIMQ;
-       crs.release_flags = RELSIM_RELEASE_AFTER_QEMPTY;
-       crs.openings
-           = crs.release_timeout
-           = crs.qfrozen_cnt
+       xpt_setup_ccb(&crs->ccb_h, path, /*priority*/1);
+       crs->ccb_h.func_code = XPT_REL_SIMQ;
+       crs->release_flags = RELSIM_RELEASE_AFTER_QEMPTY;
+       crs->openings
+           = crs->release_timeout
+           = crs->qfrozen_cnt
            = 0;
-       xpt_action((union ccb *)&crs);
+       xpt_action((union ccb *)crs);
+       xpt_free_ccb(&crs->ccb_h);
 }
 
 static int busses_to_config;
@@ -6960,7 +7013,7 @@ xptconfigbuscountfunc(struct cam_eb *bus, void *arg)
 
        if (bus->counted_to_config == 0 && bus->path_id != CAM_XPT_PATH_ID) {
                struct cam_path path;
-               struct ccb_pathinq cpi;
+               struct ccb_pathinq *cpi;
                int can_negotiate;
 
                if (bootverbose) {
@@ -6973,18 +7026,22 @@ xptconfigbuscountfunc(struct cam_eb *bus, void *arg)
                                kprintf(" (unknown)\n");
                        }
                }
+
+               cpi = &xpt_alloc_ccb()->cpi;
+
                atomic_add_int(&busses_to_config, 1);
                bus->counted_to_config = 1;
                xpt_compile_path(&path, NULL, bus->path_id,
                                 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
-               xpt_setup_ccb(&cpi.ccb_h, &path, /*priority*/1);
-               cpi.ccb_h.func_code = XPT_PATH_INQ;
-               xpt_action((union ccb *)&cpi);
-               can_negotiate = cpi.hba_inquiry;
+               xpt_setup_ccb(&cpi->ccb_h, &path, /*priority*/1);
+               cpi->ccb_h.func_code = XPT_PATH_INQ;
+               xpt_action((union ccb *)cpi);
+               can_negotiate = cpi->hba_inquiry;
                can_negotiate &= (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE);
-               if ((cpi.hba_misc & PIM_NOBUSRESET) == 0 && can_negotiate)
+               if ((cpi->hba_misc & PIM_NOBUSRESET) == 0 && can_negotiate)
                        busses_to_reset++;
                xpt_release_path(&path);
+               xpt_free_ccb(&cpi->ccb_h);
        } else
        if (bus->counted_to_config == 0 && bus->path_id == CAM_XPT_PATH_ID) {
                /* this is our dummy periph/bus */
@@ -7014,7 +7071,7 @@ xptconfigfunc(struct cam_eb *bus, void *arg)
                        kprintf("xptconfigfunc: xpt_create_path failed with "
                               "status %#x for bus %d\n", status, bus->path_id);
                        kprintf("xptconfigfunc: halting bus configuration\n");
-                       xpt_free_ccb(work_ccb);
+                       xpt_free_ccb(&work_ccb->ccb_h);
                        xpt_uncount_bus(bus);
                        return(0);
                }
@@ -7209,7 +7266,7 @@ xpt_finishconfig(struct cam_periph *periph, union ccb *done_ccb)
                }
                xpt_uncount_bus(path->bus);
                xpt_free_path(path);
-               xpt_free_ccb(done_ccb);
+               xpt_free_ccb(&done_ccb->ccb_h);
                break;
        }
 }
@@ -7218,7 +7275,7 @@ cam_status
 xpt_register_async(int event, ac_callback_t *cbfunc, void *cbarg,
                   struct cam_path *path)
 {
-       struct ccb_setasync csa;
+       struct ccb_setasync *csa;
        cam_status status;
        int xptpath = 0;
 
@@ -7233,17 +7290,20 @@ xpt_register_async(int event, ac_callback_t *cbfunc, void *cbarg,
                xptpath = 1;
        }
 
-       xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5);
-       csa.ccb_h.func_code = XPT_SASYNC_CB;
-       csa.event_enable = event;
-       csa.callback = cbfunc;
-       csa.callback_arg = cbarg;
-       xpt_action((union ccb *)&csa);
-       status = csa.ccb_h.status;
+       csa = &xpt_alloc_ccb()->csa;
+       xpt_setup_ccb(&csa->ccb_h, path, /*priority*/5);
+       csa->ccb_h.func_code = XPT_SASYNC_CB;
+       csa->event_enable = event;
+       csa->callback = cbfunc;
+       csa->callback_arg = cbarg;
+       xpt_action((union ccb *)csa);
+       status = csa->ccb_h.status;
        if (xptpath) {
                xpt_free_path(path);
                lockmgr(&xsoftc.xpt_lock, LK_RELEASE);
        }
+       xpt_free_ccb(&csa->ccb_h);
+
        return (status);
 }
 
index 71dfe3e..b55ed42 100644 (file)
@@ -39,7 +39,7 @@
 #ifdef _KERNEL
 void           xpt_polled_action(union ccb *ccb);
 union ccb      *xpt_alloc_ccb(void);
-void           xpt_free_ccb(union ccb *free_ccb);
+void           xpt_free_ccb(struct ccb_hdr *free_ccb);
 void           xpt_release_ccb(union ccb *released_ccb);
 void           xpt_schedule(struct cam_periph *perph, u_int32_t new_priority);
 int32_t                xpt_add_periph(struct cam_periph *periph);
index 744ecb3..77d100d 100644 (file)
@@ -55,6 +55,7 @@
 #include "../cam.h"
 #include "../cam_ccb.h"
 #include "../cam_xpt.h"
+#include "../cam_xpt_periph.h"
 #include "scsi_all.h"
 #include <sys/sbuf.h>
 #ifndef _KERNEL
@@ -2997,27 +2998,31 @@ scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio,
        struct scsi_inquiry_data *inq_data;
        char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1];
 #ifdef _KERNEL
-       struct    ccb_getdev cgd;
+       struct    ccb_getdev *cgd;
+       struct    scsi_inquiry_data copy_data;
 #endif
 
 #ifdef _KERNEL
        /*
         * Get the device information.
         */
-       xpt_setup_ccb(&cgd.ccb_h,
+       cgd = &xpt_alloc_ccb()->cgd;
+       xpt_setup_ccb(&cgd->ccb_h,
                      csio->ccb_h.path,
                      /*priority*/ 1);
-       cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-       xpt_action((union ccb *)&cgd);
+       cgd->ccb_h.func_code = XPT_GDEV_TYPE;
+       xpt_action((union ccb *)cgd);
 
        /*
         * If the device is unconfigured, just pretend that it is a hard
         * drive.  scsi_op_desc() needs this.
         */
-       if (cgd.ccb_h.status == CAM_DEV_NOT_THERE)
-               cgd.inq_data.device = T_DIRECT;
+       if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
+               cgd->inq_data.device = T_DIRECT;
 
-       inq_data = &cgd.inq_data;
+       copy_data = cgd->inq_data;
+       inq_data = &copy_data;
+       xpt_free_ccb(&cgd->ccb_h);
 
 #else /* !_KERNEL */
 
@@ -3056,7 +3061,8 @@ scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio,
        struct    scsi_sense_data *sense;
        struct    scsi_inquiry_data *inq_data;
 #ifdef _KERNEL
-       struct    ccb_getdev cgd;
+       struct    ccb_getdev *cgd;
+       struct    scsi_inquiry_data copy_data;
 #endif /* _KERNEL */
        u_int32_t info;
        int       error_code;
@@ -3087,20 +3093,21 @@ scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio,
        /*
         * Get the device information.
         */
-       xpt_setup_ccb(&cgd.ccb_h,
-                     csio->ccb_h.path,
-                     /*priority*/ 1);
-       cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-       xpt_action((union ccb *)&cgd);
+       cgd = &xpt_alloc_ccb()->cgd;
+       xpt_setup_ccb(&cgd->ccb_h, csio->ccb_h.path, /*priority*/ 1);
+       cgd->ccb_h.func_code = XPT_GDEV_TYPE;
+       xpt_action((union ccb *)cgd);
 
        /*
         * If the device is unconfigured, just pretend that it is a hard
         * drive.  scsi_op_desc() needs this.
         */
-       if (cgd.ccb_h.status == CAM_DEV_NOT_THERE)
-               cgd.inq_data.device = T_DIRECT;
+       if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
+               cgd->inq_data.device = T_DIRECT;
 
-       inq_data = &cgd.inq_data;
+       copy_data = cgd->inq_data;
+       inq_data = &copy_data;
+       xpt_free_ccb(&cgd->ccb_h);
 
 #else /* !_KERNEL */
 
index bdf5788..1a95d7c 100644 (file)
@@ -662,7 +662,7 @@ static cam_status
 cdregister(struct cam_periph *periph, void *arg)
 {
        struct cd_softc *softc;
-       struct ccb_pathinq cpi;
+       struct ccb_pathinq *cpi;
        struct ccb_getdev *cgd;
        char tmpstr[80];
        caddr_t match;
@@ -707,11 +707,13 @@ cdregister(struct cam_periph *periph, void *arg)
                softc->quirks = CD_Q_NONE;
 
        /* Check if the SIM does not want 6 byte commands */
-       xpt_setup_ccb(&cpi.ccb_h, periph->path, /*priority*/1);
-       cpi.ccb_h.func_code = XPT_PATH_INQ;
-       xpt_action((union ccb *)&cpi);
-       if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
+       cpi = &xpt_alloc_ccb()->cpi;
+       xpt_setup_ccb(&cpi->ccb_h, periph->path, /*priority*/1);
+       cpi->ccb_h.func_code = XPT_PATH_INQ;
+       xpt_action((union ccb *)cpi);
+       if (cpi->ccb_h.status == CAM_REQ_CMP && (cpi->hba_misc & PIM_NO_6_BYTE))
                softc->quirks |= CD_Q_10_BYTE_ONLY;
+       xpt_free_ccb(&cpi->ccb_h);
 
        TASK_INIT(&softc->sysctl_task, 0, cdsysctlinit, periph);
 
@@ -1711,7 +1713,7 @@ cddone(struct cam_periph *periph, union ccb *done_ccb)
                                int sense_key, error_code;
                                int have_sense;
                                cam_status status;
-                               struct ccb_getdev cgd;
+                               struct ccb_getdev *cgd;
 
                                /* Don't wedge this device's queue */
                                cam_release_devq(done_ccb->ccb_h.path,
@@ -1722,11 +1724,12 @@ cddone(struct cam_periph *periph, union ccb *done_ccb)
 
                                status = done_ccb->ccb_h.status;
 
-                               xpt_setup_ccb(&cgd.ccb_h, 
+                               cgd = &xpt_alloc_ccb()->cgd;
+                               xpt_setup_ccb(&cgd->ccb_h,
                                              done_ccb->ccb_h.path,
                                              /* priority */ 1);
-                               cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-                               xpt_action((union ccb *)&cgd);
+                               cgd->ccb_h.func_code = XPT_GDEV_TYPE;
+                               xpt_action((union ccb *)cgd);
 
                                if (((csio->ccb_h.flags & CAM_SENSE_PHYS) != 0)
                                 || ((csio->ccb_h.flags & CAM_SENSE_PTR) != 0)
@@ -1753,7 +1756,7 @@ cddone(struct cam_periph *periph, union ccb *done_ccb)
                                        const char *asc_desc;
 
                                        scsi_sense_desc(sense_key, asc, ascq,
-                                                       &cgd.inq_data,
+                                                       &cgd->inq_data,
                                                        &sense_key_desc,
                                                        &asc_desc);
                                        ksnprintf(announce_buf,
@@ -1764,7 +1767,7 @@ cddone(struct cam_periph *periph, union ccb *done_ccb)
                                                asc_desc);
                                        info.d_media_blksize = 2048;
                                        doinfo = 1;
-                               } else if (SID_TYPE(&cgd.inq_data) == T_CDROM) {
+                               } else if (SID_TYPE(&cgd->inq_data) == T_CDROM) {
                                        /*
                                         * We only print out an error for
                                         * CDROM type devices.  For WORM
@@ -1806,6 +1809,7 @@ cddone(struct cam_periph *periph, union ccb *done_ccb)
                                        cam_periph_invalidate(periph);
                                        announce_buf[0] = '\0';
                                }
+                               xpt_free_ccb(&cgd->ccb_h);
                        }
                }
                kfree(rdcap, M_SCSICD);
@@ -2798,7 +2802,7 @@ cdcheckmedia(struct cam_periph *periph)
        struct cd_softc *softc;
        struct ioc_toc_header *toch;
        struct cd_toc_single leadout;
-       struct ccb_getdev cgd;
+       struct ccb_getdev *cgd;
        u_int32_t size, toclen;
        int error, num_entries, cdindex;
        int first_track_audio;
@@ -2823,16 +2827,19 @@ cdcheckmedia(struct cam_periph *periph)
         * Grab the inquiry data to get the vendor and product names.
         * Put them in the typename and packname for the label.
         */
-       xpt_setup_ccb(&cgd.ccb_h, periph->path, /*priority*/ 1);
-       cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-       xpt_action((union ccb *)&cgd);
+       cgd = &xpt_alloc_ccb()->cgd;
+       xpt_setup_ccb(&cgd->ccb_h, periph->path, /*priority*/ 1);
+       cgd->ccb_h.func_code = XPT_GDEV_TYPE;
+       xpt_action((union ccb *)cgd);
 
 #if 0
-       strncpy(label->d_typename, cgd.inq_data.vendor,
+       strncpy(label->d_typename, cgd->inq_data.vendor,
                min(SID_VENDOR_SIZE, sizeof(label->d_typename)));
-       strncpy(label->d_packname, cgd.inq_data.product,
+       strncpy(label->d_packname, cgd->inq_data.product,
                min(SID_PRODUCT_SIZE, sizeof(label->d_packname)));
 #endif
+       xpt_free_ccb(&cgd->ccb_h);
+
        /*
         * Clear the valid media and TOC flags until we've verified that we
         * have both.
index a89cf9b..055eb45 100644 (file)
@@ -518,7 +518,7 @@ daopen(struct dev_open_args *ap)
        softc->flags |= DA_FLAG_OPEN;
 
        if (error == 0) {
-               struct ccb_getdev cgd;
+               struct ccb_getdev *cgd;
 
                /* Build disk information structure */
                bzero(&info, sizeof(info));
@@ -528,9 +528,11 @@ daopen(struct dev_open_args *ap)
                 * Grab the inquiry data to get the vendor and product names.
                 * Put them in the typename and packname for the label.
                 */
-               xpt_setup_ccb(&cgd.ccb_h, periph->path, /*priority*/ 1);
-               cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-               xpt_action((union ccb *)&cgd);
+               cgd = &xpt_alloc_ccb()->cgd;
+               xpt_setup_ccb(&cgd->ccb_h, periph->path, /*priority*/ 1);
+               cgd->ccb_h.func_code = XPT_GDEV_TYPE;
+               xpt_action((union ccb *)cgd);
+               xpt_free_ccb(&cgd->ccb_h);
 
                /*
                 * Check to see whether or not the blocksize is set yet.
@@ -736,7 +738,7 @@ dadump(struct dev_dump_args *ap)
        struct      da_softc *softc;
        u_int       unit;
        u_int32_t   secsize;
-       struct      ccb_scsiio csio;
+       struct      ccb_scsiio *csio;
 
        unit = dkunit(dev);
        periph = cam_extend_get(daperiphs, unit);
@@ -752,15 +754,17 @@ dadump(struct dev_dump_args *ap)
                return (ENXIO);
        }
 
+       csio = &xpt_alloc_ccb()->csio;
+
        /*
         * because length == 0 means we are supposed to flush cache, we only
         * try to write something if length > 0.
         */
        if (ap->a_length > 0) {
-               xpt_setup_ccb(&csio.ccb_h, periph->path, /*priority*/1);
-               csio.ccb_h.flags |= CAM_POLLED;
-               csio.ccb_h.ccb_state = DA_CCB_DUMP;
-               scsi_read_write(&csio,
+               xpt_setup_ccb(&csio->ccb_h, periph->path, /*priority*/1);
+               csio->ccb_h.flags |= CAM_POLLED;
+               csio->ccb_h.ccb_state = DA_CCB_DUMP;
+               scsi_read_write(csio,
                                /*retries*/1,
                                dadone,
                                MSG_ORDERED_Q_TAG,
@@ -773,20 +777,21 @@ dadump(struct dev_dump_args *ap)
                                /*dxfer_len*/ap->a_length,
                                /*sense_len*/SSD_FULL_SIZE,
                                DA_DEFAULT_TIMEOUT * 1000);             
-               xpt_polled_action((union ccb *)&csio);
+               xpt_polled_action((union ccb *)csio);
 
-               if ((csio.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+               if ((csio->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
                        kprintf("Aborting dump due to I/O error.\n");
-                       if ((csio.ccb_h.status & CAM_STATUS_MASK) ==
+                       if ((csio->ccb_h.status & CAM_STATUS_MASK) ==
                             CAM_SCSI_STATUS_ERROR)
-                               scsi_sense_print(&csio);
+                               scsi_sense_print(csio);
                        else
                                kprintf("status == 0x%x, scsi status == 0x%x\n",
-                                      csio.ccb_h.status, csio.scsi_status);
+                                      csio->ccb_h.status, csio->scsi_status);
+                       cam_periph_unlock(periph);
+                       xpt_free_ccb(&csio->ccb_h);
                        return(EIO);
                }
-               cam_periph_unlock(periph);
-               return 0;
+               goto done;
        }
 
        /*
@@ -794,9 +799,9 @@ dadump(struct dev_dump_args *ap)
         */
        if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
 
-               xpt_setup_ccb(&csio.ccb_h, periph->path, /*priority*/1);
-               csio.ccb_h.ccb_state = DA_CCB_DUMP;
-               scsi_synchronize_cache(&csio,
+               xpt_setup_ccb(&csio->ccb_h, periph->path, /*priority*/1);
+               csio->ccb_h.ccb_state = DA_CCB_DUMP;
+               scsi_synchronize_cache(csio,
                                       /*retries*/1,
                                       /*cbfcnp*/dadone,
                                       MSG_SIMPLE_Q_TAG,
@@ -804,29 +809,32 @@ dadump(struct dev_dump_args *ap)
                                       /*lb_count*/0,
                                       SSD_FULL_SIZE,
                                       5 * 60 * 1000);
-               xpt_polled_action((union ccb *)&csio);
+               xpt_polled_action((union ccb *)csio);
 
-               if ((csio.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
-                       if ((csio.ccb_h.status & CAM_STATUS_MASK) ==
+               if ((csio->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+                       if ((csio->ccb_h.status & CAM_STATUS_MASK) ==
                             CAM_SCSI_STATUS_ERROR) {
                                int asc, ascq;
                                int sense_key, error_code;
 
-                               scsi_extract_sense(&csio.sense_data,
+                               scsi_extract_sense(&csio->sense_data,
                                                   &error_code,
                                                   &sense_key, 
                                                   &asc, &ascq);
                                if (sense_key != SSD_KEY_ILLEGAL_REQUEST)
-                                       scsi_sense_print(&csio);
+                                       scsi_sense_print(csio);
                        } else {
                                xpt_print(periph->path, "Synchronize cache "
                                    "failed, status == 0x%x, scsi status == "
-                                   "0x%x\n", csio.ccb_h.status,
-                                   csio.scsi_status);
+                                   "0x%x\n",
+                                   csio->ccb_h.status, csio->scsi_status);
                        }
                }
        }
+done:
        cam_periph_unlock(periph);
+       xpt_free_ccb(&csio->ccb_h);
+
        return (0);
 }
 
@@ -1089,7 +1097,7 @@ static cam_status
 daregister(struct cam_periph *periph, void *arg)
 {
        struct da_softc *softc;
-       struct ccb_pathinq cpi;
+       struct ccb_pathinq *cpi;
        struct ccb_getdev *cgd;
        char tmpstr[80];
        caddr_t match;
@@ -1159,11 +1167,11 @@ daregister(struct cam_periph *periph, void *arg)
        TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
 
        /* Check if the SIM does not want 6 byte commands */
-       bzero(&cpi, sizeof(cpi));
-       xpt_setup_ccb(&cpi.ccb_h, periph->path, /*priority*/1);
-       cpi.ccb_h.func_code = XPT_PATH_INQ;
-       xpt_action((union ccb *)&cpi);
-       if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
+       cpi = &xpt_alloc_ccb()->cpi;
+       xpt_setup_ccb(&cpi->ccb_h, periph->path, /*priority*/1);
+       cpi->ccb_h.func_code = XPT_PATH_INQ;
+       xpt_action((union ccb *)cpi);
+       if (cpi->ccb_h.status == CAM_REQ_CMP && (cpi->hba_misc & PIM_NO_6_BYTE))
                softc->quirks |= DA_Q_NO_6_BYTE;
 
        /*
@@ -1214,10 +1222,10 @@ daregister(struct cam_periph *periph, void *arg)
         */
        CAM_SIM_UNLOCK(periph->sim);
        disk_create(periph->unit_number, &softc->disk, &da_ops);
-       if (cpi.maxio == 0 || cpi.maxio > MAXPHYS)
+       if (cpi->maxio == 0 || cpi->maxio > MAXPHYS)
                softc->disk.d_rawdev->si_iosize_max = MAXPHYS;
        else
-               softc->disk.d_rawdev->si_iosize_max = cpi.maxio;
+               softc->disk.d_rawdev->si_iosize_max = cpi->maxio;
        if (bootverbose) {
                kprintf("%s%d: si_iosize_max:%d\n",
                    periph->periph_name,
@@ -1242,6 +1250,7 @@ daregister(struct cam_periph *periph, void *arg)
         * to finish the probe.  The reference will be dropped in dadone at
         * the end of probe.
         */
+       xpt_free_ccb(&cpi->ccb_h);
        cam_periph_hold(periph, 0);
        xpt_schedule(periph, /*priority*/5);
 
@@ -1818,7 +1827,7 @@ dadone(struct cam_periph *periph, union ccb *done_ccb)
                                int sense_key, error_code;
                                int have_sense;
                                cam_status status;
-                               struct ccb_getdev cgd;
+                               struct ccb_getdev *cgd;
 
                                /* Don't wedge this device's queue */
                                status = done_ccb->ccb_h.status;
@@ -1829,12 +1838,12 @@ dadone(struct cam_periph *periph, union ccb *done_ccb)
                                                         /*timeout*/0,
                                                         /*getcount_only*/0);
 
-
-                               xpt_setup_ccb(&cgd.ccb_h, 
+                               cgd = &xpt_alloc_ccb()->cgd;
+                               xpt_setup_ccb(&cgd->ccb_h,
                                              done_ccb->ccb_h.path,
                                              /* priority */ 1);
-                               cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-                               xpt_action((union ccb *)&cgd);
+                               cgd->ccb_h.func_code = XPT_GDEV_TYPE;
+                               xpt_action((union ccb *)cgd);
 
                                if (((csio->ccb_h.flags & CAM_SENSE_PHYS) != 0)
                                 || ((csio->ccb_h.flags & CAM_SENSE_PTR) != 0)
@@ -1861,7 +1870,7 @@ dadone(struct cam_periph *periph, union ccb *done_ccb)
                                        const char *asc_desc;
 
                                        scsi_sense_desc(sense_key, asc, ascq,
-                                                       &cgd.inq_data,
+                                                       &cgd->inq_data,
                                                        &sense_key_desc,
                                                        &asc_desc);
                                        ksnprintf(announce_buf,
@@ -1890,6 +1899,7 @@ dadone(struct cam_periph *periph, union ccb *done_ccb)
                                         */
                                        cam_periph_invalidate(periph);
                                } 
+                               xpt_free_ccb(&cgd->ccb_h);
                        }
                }
                kfree(csio->data_ptr, M_SCSIDA);
@@ -2192,7 +2202,7 @@ done:
 static void
 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector)
 {
-       struct ccb_calc_geometry ccg;
+       struct ccb_calc_geometry *ccg;
        struct da_softc *softc;
        struct disk_params *dp;
 
@@ -2209,15 +2219,16 @@ dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector)
         * up with something that will make this a bootable
         * device.
         */
-       xpt_setup_ccb(&ccg.ccb_h, periph->path, /*priority*/1);
-       ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
-       ccg.block_size = dp->secsize;
-       ccg.volume_size = dp->sectors;
-       ccg.heads = 0;
-       ccg.secs_per_track = 0;
-       ccg.cylinders = 0;
-       xpt_action((union ccb*)&ccg);
-       if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+       ccg = &xpt_alloc_ccb()->ccg;
+       xpt_setup_ccb(&ccg->ccb_h, periph->path, /*priority*/1);
+       ccg->ccb_h.func_code = XPT_CALC_GEOMETRY;
+       ccg->block_size = dp->secsize;
+       ccg->volume_size = dp->sectors;
+       ccg->heads = 0;
+       ccg->secs_per_track = 0;
+       ccg->cylinders = 0;
+       xpt_action((union ccb*)ccg);
+       if ((ccg->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
                /*
                 * We don't know what went wrong here- but just pick
                 * a geometry so we don't have nasty things like divide
@@ -2230,10 +2241,11 @@ dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector)
                        dp->cylinders = 1;
                }
        } else {
-               dp->heads = ccg.heads;
-               dp->secs_per_track = ccg.secs_per_track;
-               dp->cylinders = ccg.cylinders;
+               dp->heads = ccg->heads;
+               dp->secs_per_track = ccg->secs_per_track;
+               dp->cylinders = ccg->cylinders;
        }
+       xpt_free_ccb(&ccg->ccb_h);
 }
 
 /*
@@ -2247,7 +2259,7 @@ dashutdown(void * arg, int howto)
        struct da_softc *softc;
 
        TAILQ_FOREACH(periph, &dadriver.units, unit_links) {
-               union ccb ccb;
+               union ccb *ccb;
 
                cam_periph_lock(periph);
                softc = (struct da_softc *)periph->softc;
@@ -2262,10 +2274,11 @@ dashutdown(void * arg, int howto)
                        continue;
                }
 
-               xpt_setup_ccb(&ccb.ccb_h, periph->path, /*priority*/1);
+               ccb = xpt_alloc_ccb();
+               xpt_setup_ccb(&ccb->ccb_h, periph->path, /*priority*/1);
 
-               ccb.ccb_h.ccb_state = DA_CCB_DUMP;
-               scsi_synchronize_cache(&ccb.csio,
+               ccb->ccb_h.ccb_state = DA_CCB_DUMP;
+               scsi_synchronize_cache(&ccb->csio,
                                       /*retries*/1,
                                       /*cbfcnp*/dadone,
                                       MSG_SIMPLE_Q_TAG,
@@ -2274,36 +2287,37 @@ dashutdown(void * arg, int howto)
                                       SSD_FULL_SIZE,
                                       60 * 60 * 1000);
 
-               xpt_polled_action(&ccb);
+               xpt_polled_action(ccb);
 
-               if ((ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
-                       if (((ccb.ccb_h.status & CAM_STATUS_MASK) ==
+               if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+                       if (((ccb->ccb_h.status & CAM_STATUS_MASK) ==
                             CAM_SCSI_STATUS_ERROR)
-                        && (ccb.csio.scsi_status == SCSI_STATUS_CHECK_COND)){
+                        && (ccb->csio.scsi_status == SCSI_STATUS_CHECK_COND)){
                                int error_code, sense_key, asc, ascq;
 
-                               scsi_extract_sense(&ccb.csio.sense_data,
+                               scsi_extract_sense(&ccb->csio.sense_data,
                                                   &error_code, &sense_key,
                                                   &asc, &ascq);
 
                                if (sense_key != SSD_KEY_ILLEGAL_REQUEST)
-                                       scsi_sense_print(&ccb.csio);
+                                       scsi_sense_print(&ccb->csio);
                        } else {
                                xpt_print(periph->path, "Synchronize "
                                    "cache failed, status == 0x%x, scsi status "
-                                   "== 0x%x\n", ccb.ccb_h.status,
-                                   ccb.csio.scsi_status);
+                                   "== 0x%x\n", ccb->ccb_h.status,
+                                   ccb->csio.scsi_status);
                        }
                }
 
-               if ((ccb.ccb_h.status & CAM_DEV_QFRZN) != 0)
-                       cam_release_devq(ccb.ccb_h.path,
+               if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
+                       cam_release_devq(ccb->ccb_h.path,
                                         /*relsim_flags*/0,
                                         /*reduction*/0,
                                         /*timeout*/0,
                                         /*getcount_only*/0);
 
                cam_periph_unlock(periph);
+               xpt_free_ccb(&ccb->ccb_h);
        }
 }
 
index b38bd99..c4f7012 100644 (file)
@@ -502,7 +502,7 @@ passioctl(struct dev_ioctl_args *ap)
                error = passsendccb(periph, ccb, inccb);
 
                if (ccb_malloced)
-                       xpt_free_ccb(ccb);
+                       xpt_free_ccb(&ccb->ccb_h);
                else
                        xpt_release_ccb(ccb);
 
index 313f7f9..eb9ec50 100644 (file)
@@ -738,7 +738,7 @@ sgwrite(struct dev_write_args *ap)
 out_buf:
        kfree(buf, M_DEVBUF);
 out_ccb:
-       xpt_free_ccb(ccb);
+       xpt_free_ccb(&ccb->ccb_h);
 out_hdr:
        kfree(rdwr, M_DEVBUF);
        return (error);
@@ -843,7 +843,7 @@ search:
                error = uiomove(rdwr->buf, rdwr->buf_len, uio);
 
        cam_periph_lock(periph);
-       xpt_free_ccb(rdwr->ccb);
+       xpt_free_ccb(&rdwr->ccb->ccb_h);
        cam_periph_unlock(periph);
        kfree(rdwr->buf, M_DEVBUF);
        kfree(rdwr, M_DEVBUF);
index 8d7e55a..ca73793 100644 (file)
@@ -229,7 +229,7 @@ targbhasync(void *callback_arg, u_int32_t code,
 static cam_status
 targbhenlun(struct cam_periph *periph)
 {
-       union ccb immed_ccb;
+       union ccb *immed_ccb;
        struct targbh_softc *softc;
        cam_status status;
        int i;
@@ -239,15 +239,18 @@ targbhenlun(struct cam_periph *periph)
        if ((softc->flags & TARGBH_FLAG_LUN_ENABLED) != 0)
                return (CAM_REQ_CMP);
 
-       xpt_setup_ccb(&immed_ccb.ccb_h, periph->path, /*priority*/1);
-       immed_ccb.ccb_h.func_code = XPT_EN_LUN;
+       immed_ccb = xpt_alloc_ccb();
+       xpt_setup_ccb(&immed_ccb->ccb_h, periph->path, /*priority*/1);
+       immed_ccb->ccb_h.func_code = XPT_EN_LUN;
 
        /* Don't need support for any vendor specific commands */
-       immed_ccb.cel.grp6_len = 0;
-       immed_ccb.cel.grp7_len = 0;
-       immed_ccb.cel.enable = 1;
-       xpt_action(&immed_ccb);
-       status = immed_ccb.ccb_h.status;
+       immed_ccb->cel.grp6_len = 0;
+       immed_ccb->cel.grp7_len = 0;
+       immed_ccb->cel.enable = 1;
+       xpt_action(immed_ccb);
+       status = immed_ccb->ccb_h.status;
+       xpt_free_ccb(&immed_ccb->ccb_h);
+
        if (status != CAM_REQ_CMP) {
                xpt_print(periph->path,
                    "targbhenlun - Enable Lun Rejected with status 0x%x\n",
@@ -264,8 +267,7 @@ targbhenlun(struct cam_periph *periph)
        for (i = 0; i < MAX_ACCEPT; i++) {
                struct ccb_accept_tio *atio;
 
-               atio = kmalloc(sizeof(*atio), M_SCSIBH, M_INTWAIT);
-
+               atio = &xpt_alloc_ccb()->atio;
                atio->ccb_h.ccb_descr = targbhallocdescr();
 
                xpt_setup_ccb(&atio->ccb_h, periph->path, /*priority*/1);
@@ -275,7 +277,7 @@ targbhenlun(struct cam_periph *periph)
                status = atio->ccb_h.status;
                if (status != CAM_REQ_INPROG) {
                        targbhfreedescr(atio->ccb_h.ccb_descr);
-                       kfree(atio, M_SCSIBH);
+                       xpt_free_ccb(&atio->ccb_h);
                        break;
                }
                ((struct targbh_cmd_desc*)atio->ccb_h.ccb_descr)->atio_link =
@@ -298,7 +300,7 @@ targbhenlun(struct cam_periph *periph)
        for (i = 0; i < MAX_ACCEPT; i++) {
                struct ccb_immed_notify *inot;
 
-               inot = kmalloc(sizeof(*inot), M_SCSIBH, M_INTWAIT);
+               inot = &xpt_alloc_ccb()->cin;
 
                xpt_setup_ccb(&inot->ccb_h, periph->path, /*priority*/1);
                inot->ccb_h.func_code = XPT_IMMED_NOTIFY;
@@ -306,7 +308,7 @@ targbhenlun(struct cam_periph *periph)
                xpt_action((union ccb *)inot);
                status = inot->ccb_h.status;
                if (status != CAM_REQ_INPROG) {
-                       kfree(inot, M_SCSIBH);
+                       xpt_free_ccb(&inot->ccb_h);
                        break;
                }
                SLIST_INSERT_HEAD(&softc->immed_notify_slist, &inot->ccb_h,
@@ -327,10 +329,11 @@ targbhenlun(struct cam_periph *periph)
 static cam_status
 targbhdislun(struct cam_periph *periph)
 {
-       union ccb ccb;
+       union ccb *ccb;
        struct targbh_softc *softc;
        struct ccb_accept_tio* atio;
        struct ccb_hdr *ccb_h;
+       u_int32_t status;
 
        softc = (struct targbh_softc *)periph->softc;
        if ((softc->flags & TARGBH_FLAG_LUN_ENABLED) == 0)
@@ -338,39 +341,44 @@ targbhdislun(struct cam_periph *periph)
 
        /* XXX Block for Continue I/O completion */
 
+       ccb = xpt_alloc_ccb();
+
        /* Kill off all ACCECPT and IMMEDIATE CCBs */
        while ((atio = softc->accept_tio_list) != NULL) {
-               
                softc->accept_tio_list =
                    ((struct targbh_cmd_desc*)atio->ccb_h.ccb_descr)->atio_link;
-               xpt_setup_ccb(&ccb.cab.ccb_h, periph->path, /*priority*/1);
-               ccb.cab.ccb_h.func_code = XPT_ABORT;
-               ccb.cab.abort_ccb = (union ccb *)atio;
-               xpt_action(&ccb);
+               xpt_setup_ccb(&ccb->cab.ccb_h, periph->path, /*priority*/1);
+               ccb->cab.ccb_h.func_code = XPT_ABORT;
+               ccb->cab.abort_ccb = (union ccb *)atio;
+               xpt_action(ccb);
        }
 
        while ((ccb_h = SLIST_FIRST(&softc->immed_notify_slist)) != NULL) {
                SLIST_REMOVE_HEAD(&softc->immed_notify_slist, periph_links.sle);
-               xpt_setup_ccb(&ccb.cab.ccb_h, periph->path, /*priority*/1);
-               ccb.cab.ccb_h.func_code = XPT_ABORT;
-               ccb.cab.abort_ccb = (union ccb *)ccb_h;
-               xpt_action(&ccb);
+               xpt_setup_ccb(&ccb->cab.ccb_h, periph->path, /*priority*/1);
+               ccb->cab.ccb_h.func_code = XPT_ABORT;
+               ccb->cab.abort_ccb = (union ccb *)ccb_h;
+               xpt_action(ccb);
+               /* XXX xpt_free_ccb(ccb_h); needed? */
        }
 
        /*
         * Dissable this lun.
         */
-       xpt_setup_ccb(&ccb.cel.ccb_h, periph->path, /*priority*/1);
-       ccb.cel.ccb_h.func_code = XPT_EN_LUN;
-       ccb.cel.enable = 0;
-       xpt_action(&ccb);
+       xpt_setup_ccb(&ccb->cel.ccb_h, periph->path, /*priority*/1);
+       ccb->cel.ccb_h.func_code = XPT_EN_LUN;
+       ccb->cel.enable = 0;
+       xpt_action(ccb);
+
+       status = ccb->cel.ccb_h.status;
+       xpt_free_ccb(&ccb->ccb_h);
 
-       if (ccb.cel.ccb_h.status != CAM_REQ_CMP)
+       if (status != CAM_REQ_CMP)
                kprintf("targbhdislun - Disabling lun on controller failed "
-                      "with status 0x%x\n", ccb.cel.ccb_h.status);
+                      "with status 0x%x\n", status);
        else 
                softc->flags &= ~TARGBH_FLAG_LUN_ENABLED;
-       return (ccb.cel.ccb_h.status);
+       return (status);
 }
 
 static cam_status
@@ -533,7 +541,7 @@ targbhdone(struct cam_periph *periph, union ccb *done_ccb)
                if (softc->state == TARGBH_STATE_TEARDOWN
                 || atio->ccb_h.status == CAM_REQ_ABORTED) {
                        targbhfreedescr(descr);
-                       xpt_free_ccb(done_ccb);
+                       xpt_free_ccb(&done_ccb->ccb_h);
                        return;
                }
 
@@ -682,7 +690,7 @@ targbhdone(struct cam_periph *periph, union ccb *done_ccb)
                        break;
                } else {
                        targbhfreedescr(desc);
-                       kfree(atio, M_SCSIBH);
+                       xpt_free_ccb(&atio->ccb_h);
                }
                break;
        }
@@ -694,7 +702,7 @@ targbhdone(struct cam_periph *periph, union ccb *done_ccb)
                if (softc->state == TARGBH_STATE_TEARDOWN
                 || done_ccb->ccb_h.status == CAM_REQ_ABORTED) {
                        kprintf("Freed an immediate notify\n");
-                       xpt_free_ccb(done_ccb);
+                       xpt_free_ccb(&done_ccb->ccb_h);
                } else {
                        /* Requeue for another immediate event */
                        xpt_action(done_ccb);
index 3ebb48d..246465d 100644 (file)
@@ -285,26 +285,27 @@ targioctl(struct dev_ioctl_args *ap)
        case TARGIOCDEBUG:
        {
 #ifdef CAMDEBUG
-               struct ccb_debug cdbg;
+               struct ccb_debug *cdbg;
 
                /* If no periph available, disallow debugging changes */
                if ((softc->state & TARG_STATE_LUN_ENABLED) == 0) {
                        status = CAM_DEV_NOT_THERE;
                        break;
                }
-               bzero(&cdbg, sizeof cdbg);
+               cdbg = xpt_alloc_ccb();
                if (*((int *)ap->a_data) != 0)
-                       cdbg.flags = CAM_DEBUG_PERIPH;
+                       cdbg->flags = CAM_DEBUG_PERIPH;
                else
-                       cdbg.flags = CAM_DEBUG_NONE;
+                       cdbg->flags = CAM_DEBUG_NONE;
                cam_periph_lock(softc->periph);
-               xpt_setup_ccb(&cdbg.ccb_h, softc->path, /*priority*/0);
-               cdbg.ccb_h.func_code = XPT_DEBUG;
-               cdbg.ccb_h.cbfcnp = targdone;
+               xpt_setup_ccb(&cdbg->ccb_h, softc->path, /*priority*/0);
+               cdbg->ccb_h.func_code = XPT_DEBUG;
+               cdbg->ccb_h.cbfcnp = targdone;
 
-               xpt_action((union ccb *)&cdbg);
+               xpt_action((union ccb *)cdbg);
                cam_periph_unlock(softc->periph);
-               status = cdbg.ccb_h.status & CAM_STATUS_MASK;
+               status = cdbg->ccb_h.status & CAM_STATUS_MASK;
+               xpt_free_ccb(&cdbg->ccb_h);
 #else
                status = CAM_FUNC_NOTAVAIL;
 #endif
@@ -380,22 +381,25 @@ targwritefilt(struct knote *kn, long hint)
 static cam_status
 targendislun(struct cam_path *path, int enable, int grp6_len, int grp7_len)
 {
-       struct ccb_en_lun en_ccb;
+       struct ccb_en_lun *en_ccb;
        cam_status        status;
 
        /* Tell the lun to begin answering selects */
-       xpt_setup_ccb(&en_ccb.ccb_h, path, /*priority*/1);
-       en_ccb.ccb_h.func_code = XPT_EN_LUN;
+       en_ccb = &xpt_alloc_ccb()->cel;
+       xpt_setup_ccb(&en_ccb->ccb_h, path, /*priority*/1);
+       en_ccb->ccb_h.func_code = XPT_EN_LUN;
        /* Don't need support for any vendor specific commands */
-       en_ccb.grp6_len = grp6_len;
-       en_ccb.grp7_len = grp7_len;
-       en_ccb.enable = enable ? 1 : 0;
-       xpt_action((union ccb *)&en_ccb);
-       status = en_ccb.ccb_h.status & CAM_STATUS_MASK;
+       en_ccb->grp6_len = grp6_len;
+       en_ccb->grp7_len = grp7_len;
+       en_ccb->enable = enable ? 1 : 0;
+       xpt_action((union ccb *)en_ccb);
+       status = en_ccb->ccb_h.status & CAM_STATUS_MASK;
        if (status != CAM_REQ_CMP) {
                xpt_print(path, "%sable lun CCB rejected, status %#x\n",
                    enable ? "en" : "dis", status);
        }
+       xpt_free_ccb(&en_ccb->ccb_h);
+
        return (status);
 }
 
@@ -405,22 +409,23 @@ targenable(struct targ_softc *softc, struct cam_path *path, int grp6_len,
           int grp7_len)
 {
        struct cam_periph *periph;
-       struct ccb_pathinq cpi;
+       struct ccb_pathinq *cpi;
        cam_status         status;
 
        if ((softc->state & TARG_STATE_LUN_ENABLED) != 0)
                return (CAM_LUN_ALRDY_ENA);
 
        /* Make sure SIM supports target mode */
-       xpt_setup_ccb(&cpi.ccb_h, path, /*priority*/1);
-       cpi.ccb_h.func_code = XPT_PATH_INQ;
-       xpt_action((union ccb *)&cpi);
-       status = cpi.ccb_h.status & CAM_STATUS_MASK;
+       cpi = &xpt_alloc_ccb()->cpi;
+       xpt_setup_ccb(&cpi->ccb_h, path, /*priority*/1);
+       cpi->ccb_h.func_code = XPT_PATH_INQ;
+       xpt_action((union ccb *)cpi);
+       status = cpi->ccb_h.status & CAM_STATUS_MASK;
        if (status != CAM_REQ_CMP) {
                kprintf("pathinq failed, status %#x\n", status);
                goto enable_fail;
        }
-       if ((cpi.target_sprt & PIT_PROCESSOR) == 0) {
+       if ((cpi->target_sprt & PIT_PROCESSOR) == 0) {
                kprintf("controller does not support target mode\n");
                status = CAM_FUNC_NOTAVAIL;
                goto enable_fail;
@@ -466,6 +471,8 @@ targenable(struct targ_softc *softc, struct cam_path *path, int grp6_len,
        softc->state |= TARG_STATE_LUN_ENABLED;
 
 enable_fail:
+       xpt_free_ccb(&cpi->ccb_h);
+
        return (status);
 }
 
@@ -973,16 +980,20 @@ static union ccb *
 targgetccb(struct targ_softc *softc, xpt_opcode type, int priority)
 {
        union ccb *ccb;
-       int ccb_len;
 
+#if 0
+       int ccb_len;
        ccb_len = targccblen(type);
        ccb = kmalloc(ccb_len, M_TARG, M_INTWAIT);
+#endif
+       ccb = xpt_alloc_ccb();
        CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("getccb %p\n", ccb));
 
        xpt_setup_ccb(&ccb->ccb_h, softc->path, priority);
        ccb->ccb_h.func_code = type;
        ccb->ccb_h.cbfcnp = targdone;
        ccb->ccb_h.targ_descr = targgetdescr(softc);
+
        return (ccb);
 }
 
@@ -992,12 +1003,13 @@ targfreeccb(struct targ_softc *softc, union ccb *ccb)
        CAM_DEBUG_PRINT(CAM_DEBUG_PERIPH, ("targfreeccb descr %p and\n",
                        ccb->ccb_h.targ_descr));
        kfree(ccb->ccb_h.targ_descr, M_TARG);
+       ccb->ccb_h.targ_descr = NULL;   /* safety */
 
        switch (ccb->ccb_h.func_code) {
        case XPT_ACCEPT_TARGET_IO:
        case XPT_IMMED_NOTIFY:
                CAM_DEBUG_PRINT(CAM_DEBUG_PERIPH, ("freeing ccb %p\n", ccb));
-               kfree(ccb, M_TARG);
+               xpt_free_ccb(&ccb->ccb_h);
                break;
        default:
                /* Send back CCB if we got it from the periph */
@@ -1008,7 +1020,7 @@ targfreeccb(struct targ_softc *softc, union ccb *ccb)
                } else {
                        CAM_DEBUG_PRINT(CAM_DEBUG_PERIPH,
                                        ("freeing ccb %p\n", ccb));
-                       kfree(ccb, M_TARG);
+                       xpt_free_ccb(&ccb->ccb_h);
                }
                break;
        }
@@ -1055,7 +1067,7 @@ static void
 abort_all_pending(struct targ_softc *softc)
 {
        struct targ_cmd_descr   *descr;
-       struct ccb_abort         cab;
+       struct ccb_abort         *cab;
        struct ccb_hdr          *ccb_h;
        struct cam_sim          *sim;
 
@@ -1073,32 +1085,36 @@ abort_all_pending(struct targ_softc *softc)
         * Then abort all pending CCBs.
         * targdone() will return the aborted CCB via user_ccb_queue
         */
-       xpt_setup_ccb(&cab.ccb_h, softc->path, /*priority*/0);
-       cab.ccb_h.func_code = XPT_ABORT;
-       cab.ccb_h.status = CAM_REQ_CMP_ERR;
+       cab = &xpt_alloc_ccb()->cab;
+       xpt_setup_ccb(&cab->ccb_h, softc->path, /*priority*/0);
+       cab->ccb_h.func_code = XPT_ABORT;
+       cab->ccb_h.status = CAM_REQ_CMP_ERR;
        TAILQ_FOREACH(ccb_h, &softc->pending_ccb_queue, periph_links.tqe) {
                CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH,
                          ("Aborting pending CCB %p\n", ccb_h));
-               cab.abort_ccb = (union ccb *)ccb_h;
-               xpt_action((union ccb *)&cab);
-               if (cab.ccb_h.status != CAM_REQ_CMP) {
-                       xpt_print(cab.ccb_h.path,
+               cab->abort_ccb = (union ccb *)ccb_h;
+               xpt_action((union ccb *)cab);
+               if (cab->ccb_h.status != CAM_REQ_CMP) {
+                       xpt_print(cab->ccb_h.path,
                            "Unable to abort CCB, status %#x\n",
-                           cab.ccb_h.status);
+                           cab->ccb_h.status);
                }
        }
 
        /* If we aborted at least one pending CCB ok, wait for it. */
-       if (cab.ccb_h.status == CAM_REQ_CMP) {
+       if (cab->ccb_h.status == CAM_REQ_CMP) {
                sim = xpt_path_sim(softc->path);
                sim_lock_sleep(&softc->pending_ccb_queue, PCATCH, "tgabrt", 0,
                               sim->lock);
        }
 
        /* If we aborted anything from the work queue, wakeup user. */
-       if (!TAILQ_EMPTY(&softc->user_ccb_queue)
-        || !TAILQ_EMPTY(&softc->abort_queue))
+       if (!TAILQ_EMPTY(&softc->user_ccb_queue) ||
+           !TAILQ_EMPTY(&softc->abort_queue)) {
                notify_user(softc);
+       }
+
+       xpt_free_ccb(&cab->ccb_h);
 }
 
 /* Notify the user that data is ready */
index bfbf7ff..a885b27 100644 (file)
 #include <bus/cam/cam.h>
 #include <bus/cam/cam_ccb.h>
 #include <bus/cam/cam_sim.h>
+#include <bus/cam/cam_xpt.h>
 #include <bus/cam/cam_xpt_sim.h>
+#include <bus/cam/cam_xpt_periph.h>
+#include <bus/cam/cam_periph.h>
 #include <bus/cam/scsi/scsi_all.h>
 #include <bus/cam/scsi/scsi_da.h>
 
-#include <bus/cam/cam_periph.h>
-
-
 #if 0
 #define UMASS_EXT_BUFFER
 #ifdef UMASS_EXT_BUFFER
@@ -2140,7 +2140,7 @@ umass_cam_rescan_callback(struct cam_periph *periph, union ccb *ccb)
 #endif
 
        xpt_free_path(ccb->ccb_h.path);
-       kfree(ccb, M_USBDEV);
+       xpt_free_ccb(&ccb->ccb_h);
 }
 
 /*
@@ -2154,7 +2154,7 @@ umass_cam_rescan(void *addr)
        struct cam_path *path;
        union ccb *ccb;
 
-       ccb = kmalloc(sizeof(union ccb), M_USBDEV, M_INTWAIT|M_ZERO);
+       ccb = xpt_alloc_ccb();
 
        DPRINTF(sc, UDMASS_SCSI, "scbus%d: scanning for %s:%d:%d:%d\n",
            cam_sim_path(sc->sc_sim),
@@ -2163,7 +2163,7 @@ umass_cam_rescan(void *addr)
 
        if (xpt_create_path(&path, xpt_periph, cam_sim_path(sc->sc_sim),
            CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
-               kfree(ccb, M_USBDEV);
+               xpt_free_ccb(&ccb->ccb_h);
                return;
        }
 
index bd6c012..6180b8d 100644 (file)
@@ -154,7 +154,7 @@ adv_clear_state_really(struct adv_softc *adv, union ccb* ccb)
                         */
                        ccb_h = LIST_FIRST(&adv->pending_ccbs);
                        while (ccb_h != NULL) {
-                               callout_reset(&ccb_h->timeout_ch,
+                               callout_reset(ccb_h->timeout_ch,
                                    (ccb_h->timeout * hz) / 1000,
                                    adv_timeout, ccb_h);
                                ccb_h = LIST_NEXT(ccb_h, sim_links.le);
@@ -628,8 +628,8 @@ adv_execute_ccb(void *arg, bus_dma_segment_t *dm_segs,
        ccb_h->status |= CAM_SIM_QUEUED;
        LIST_INSERT_HEAD(&adv->pending_ccbs, ccb_h, sim_links.le);
        /* Schedule our timeout */
-       callout_reset(&ccb_h->timeout_ch, (ccb_h->timeout * hz)/1000,
-           adv_timeout, csio);
+       callout_reset(ccb_h->timeout_ch, (ccb_h->timeout * hz) / 1000,
+                     adv_timeout, csio);
        crit_exit();
 }
 
@@ -701,7 +701,7 @@ adv_timeout(void *arg)
 
                ccb_h = LIST_FIRST(&adv->pending_ccbs);
                while (ccb_h != NULL) {
-                       callout_stop(&ccb_h->timeout_ch);
+                       callout_stop(ccb_h->timeout_ch);
                        ccb_h = LIST_NEXT(ccb_h, sim_links.le);
                }
 
@@ -712,7 +712,7 @@ adv_timeout(void *arg)
                adv_abort_ccb(adv, ccb->ccb_h.target_id,
                              ccb->ccb_h.target_lun, ccb,
                              CAM_CMD_TIMEOUT, /*queued_only*/FALSE);
-               callout_reset(&ccb->ccb_h.timeout_ch, 2 * hz, adv_timeout, ccb);
+               callout_reset(ccb->ccb_h.timeout_ch, 2 * hz, adv_timeout, ccb);
        } else {
                /* Our attempt to perform an abort failed, go for a reset */
                xpt_print_path(ccb->ccb_h.path);
@@ -1125,7 +1125,7 @@ adv_done(struct adv_softc *adv, union ccb *ccb, u_int done_stat,
 
        cinfo = (struct adv_ccb_info *)ccb->ccb_h.ccb_cinfo_ptr;
        LIST_REMOVE(&ccb->ccb_h, sim_links.le);
-       callout_stop(&ccb->ccb_h.timeout_ch);
+       callout_stop(ccb->ccb_h.timeout_ch);
        if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
                bus_dmasync_op_t op;
 
@@ -1284,7 +1284,7 @@ adv_poll(struct cam_sim *sim)
 int
 adv_attach(struct adv_softc *adv)
 {
-       struct ccb_setasync csa;
+       struct ccb_setasync *csa;
        int max_sg;
 
        /*
@@ -1404,11 +1404,14 @@ adv_attach(struct adv_softc *adv)
                return (ENXIO);
        }
 
-       xpt_setup_ccb(&csa.ccb_h, adv->path, /*priority*/5);
-       csa.ccb_h.func_code = XPT_SASYNC_CB;
-       csa.event_enable = AC_FOUND_DEVICE|AC_LOST_DEVICE;
-       csa.callback = advasync;
-       csa.callback_arg = adv;
-       xpt_action((union ccb *)&csa);
+       csa = &xpt_alloc_ccb()->csa;
+       xpt_setup_ccb(&csa->ccb_h, adv->path, /*priority*/5);
+       csa->ccb_h.func_code = XPT_SASYNC_CB;
+       csa->event_enable = AC_FOUND_DEVICE|AC_LOST_DEVICE;
+       csa->callback = advasync;
+       csa->callback_arg = adv;
+       xpt_action((union ccb *)csa);
+       xpt_free_ccb(&csa->ccb_h);
+
        return (0);
 }
index 231cbaa..ff481ac 100644 (file)
@@ -61,6 +61,7 @@
 #include <bus/cam/scsi/scsi_message.h>
 #include <bus/cam/scsi/scsi_da.h>
 #include <bus/cam/scsi/scsi_cd.h>
+#include <bus/cam/cam_xpt_periph.h>
 
 #include <vm/vm.h>
 #include <vm/vm_param.h>
@@ -1016,7 +1017,7 @@ adv_isr_chip_halted(struct adv_softc *adv)
                 * Ensure we have enough time to actually
                 * retrieve the sense.
                 */
-               callout_reset(&ccb->ccb_h.timeout_ch, 5 * hz, adv_timeout, ccb);
+               callout_reset(ccb->ccb_h.timeout_ch, 5 * hz, adv_timeout, ccb);
        } else if (int_halt_code == ADV_HALT_SDTR_REJECTED) {
                struct  ext_msg out_msg;
 
@@ -1126,22 +1127,24 @@ adv_set_syncrate(struct adv_softc *adv, struct cam_path *path,
                         * Tell the SCSI layer about the
                         * new transfer parameters.
                         */
-                       struct  ccb_trans_settings neg;
-                       memset(&neg, 0, sizeof (neg));
-                       struct ccb_trans_settings_spi *spi =
-                           &neg.xport_specific.spi;
+                       struct ccb_trans_settings *neg;
+                       struct ccb_trans_settings_spi *spi;
 
-                       neg.protocol = PROTO_SCSI;
-                       neg.protocol_version = SCSI_REV_2;
-                       neg.transport = XPORT_SPI;
-                       neg.transport_version = 2;
+                       neg = &xpt_alloc_ccb()->cts;
+                       spi = &neg->xport_specific.spi;
+
+                       neg->protocol = PROTO_SCSI;
+                       neg->protocol_version = SCSI_REV_2;
+                       neg->transport = XPORT_SPI;
+                       neg->transport_version = 2;
 
                        spi->sync_offset = offset;
                        spi->sync_period = period;
                        spi->valid |= CTS_SPI_VALID_SYNC_OFFSET;
                        spi->valid |= CTS_SPI_VALID_SYNC_RATE;
-                       xpt_setup_ccb(&neg.ccb_h, path, /*priority*/1);
-                       xpt_async(AC_TRANSFER_NEG, path, &neg);
+                       xpt_setup_ccb(&neg->ccb_h, path, /*priority*/1);
+                       xpt_async(AC_TRANSFER_NEG, path, neg);
+                       xpt_free_ccb(&neg->ccb_h);
                }
        }
 
index e1fcd85..1debf2e 100644 (file)
@@ -61,6 +61,7 @@
 #include <bus/cam/cam_sim.h>
 #include <bus/cam/cam_xpt_sim.h>
 #include <bus/cam/cam_debug.h>
+#include <bus/cam/cam_xpt_periph.h>
 
 #include <bus/cam/scsi/scsi_message.h>
 
@@ -322,8 +323,9 @@ adwexecuteacb(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
        acb->state |= ACB_ACTIVE;
        ccb->ccb_h.status |= CAM_SIM_QUEUED;
        LIST_INSERT_HEAD(&adw->pending_ccbs, &ccb->ccb_h, sim_links.le);
-       callout_reset(&ccb->ccb_h.timeout_ch, (ccb->ccb_h.timeout * hz) / 1000,
-           adwtimeout, acb);
+       callout_reset(ccb->ccb_h.timeout_ch,
+                     (ccb->ccb_h.timeout * hz) / 1000,
+                     adwtimeout, acb);
 
        adw_send_acb(adw, acb, acbvtob(adw, acb));
 
@@ -1150,7 +1152,7 @@ adw_init(struct adw_softc *adw)
 int
 adw_attach(struct adw_softc *adw)
 {
-       struct ccb_setasync csa;
+       struct ccb_setasync *csa;
        int error;
 
        error = 0;
@@ -1188,12 +1190,14 @@ adw_attach(struct adw_softc *adw)
        if (xpt_create_path(&adw->path, /*periph*/NULL, cam_sim_path(adw->sim),
                            CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD)
           == CAM_REQ_CMP) {
-               xpt_setup_ccb(&csa.ccb_h, adw->path, /*priority*/5);
-               csa.ccb_h.func_code = XPT_SASYNC_CB;
-               csa.event_enable = AC_LOST_DEVICE;
-               csa.callback = adw_async;
-               csa.callback_arg = adw;
-               xpt_action((union ccb *)&csa);
+               csa = &xpt_alloc_ccb()->csa;
+               xpt_setup_ccb(&csa->ccb_h, adw->path, /*priority*/5);
+               csa->ccb_h.func_code = XPT_SASYNC_CB;
+               csa->event_enable = AC_LOST_DEVICE;
+               csa->callback = adw_async;
+               csa->callback_arg = adw;
+               xpt_action((union ccb *)csa);
+               xpt_free_ccb(&csa->ccb_h);
        }
 
 fail:
@@ -1292,7 +1296,7 @@ adw_intr(void *arg)
 
                /* Process CCB */
                ccb = acb->ccb;
-               callout_stop(&ccb->ccb_h.timeout_ch);
+               callout_stop(ccb->ccb_h.timeout_ch);
                if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
                        bus_dmasync_op_t op;
 
index 22bde8d..2375558 100644 (file)
@@ -726,7 +726,7 @@ ahci_cam_rescan_callback(struct cam_periph *periph, union ccb *ccb)
                ap->ap_flags |= AP_F_SCAN_COMPLETED;
                wakeup(&ap->ap_flags);
        }
-       xpt_free_ccb(ccb);
+       xpt_free_ccb(&ccb->ccb_h);
 }
 
 static void
index 2a5ea06..e2c8c89 100644 (file)
 #include <bus/cam/cam.h>
 #include <bus/cam/cam_ccb.h>
 #include <bus/cam/cam_sim.h>
+#include <bus/cam/cam_xpt.h>
 #include <bus/cam/cam_xpt_sim.h>
+#include <bus/cam/cam_xpt_periph.h>
 #include <bus/cam/cam_debug.h>
-
 #include <bus/cam/scsi/scsi_all.h>
 #include <bus/cam/scsi/scsi_message.h>
 
@@ -813,17 +814,19 @@ amdsetsync(struct amd_softc *amd, u_int target, u_int clockrate,
                if (xpt_create_path(&path, /*periph*/NULL,
                                    cam_sim_path(amd->psim), target,
                                    CAM_LUN_WILDCARD) == CAM_REQ_CMP) {
-                       struct ccb_trans_settings neg;
-                       struct ccb_trans_settings_spi *spi =
-                           &neg.xport_specific.spi;
-                       xpt_setup_ccb(&neg.ccb_h, path, /*priority*/1);
-                       memset(&neg, 0, sizeof (neg));
+                       struct ccb_trans_settings *neg;
+                       struct ccb_trans_settings_spi *spi;
+
+                       neg = &xpt_alloc_ccb()->cts;
+                       spi = &neg->xport_specific.spi;
+                       xpt_setup_ccb(&neg->ccb_h, path, /*priority*/1);
                        spi->sync_period = period;
                        spi->sync_offset = offset;
                        spi->valid = CTS_SPI_VALID_SYNC_RATE
                                  | CTS_SPI_VALID_SYNC_OFFSET;
-                       xpt_async(AC_TRANSFER_NEG, path, &neg);
+                       xpt_async(AC_TRANSFER_NEG, path, neg);
                        xpt_free_path(path);    
+                       xpt_free_ccb(&neg->ccb_h);
                }
        }
        if ((type & AMD_TRANS_GOAL) != 0) {
@@ -1471,17 +1474,21 @@ amdhandlemsgreject(struct amd_softc *amd)
                       amd->unit, amd->cur_target);
        } else if ((srb != NULL)
                && (srb->pccb->ccb_h.flags & CAM_TAG_ACTION_VALID) != 0) {
-               struct  ccb_trans_settings neg;
-               struct ccb_trans_settings_scsi *scsi = &neg.proto_specific.scsi;
+               struct ccb_trans_settings *neg;
+               struct ccb_trans_settings_scsi *scsi;
 
                kprintf("amd%d:%d: refuses tagged commands.  Performing "
                       "non-tagged I/O\n", amd->unit, amd->cur_target);
 
+               neg = &xpt_alloc_ccb()->cts;
+               scsi = &neg->proto_specific.scsi;
                amdsettags(amd, amd->cur_target, FALSE);
-               memset(&neg, 0, sizeof (neg));
                scsi->valid = CTS_SCSI_VALID_TQ;
-               xpt_setup_ccb(&neg.ccb_h, srb->pccb->ccb_h.path, /*priority*/1);
-               xpt_async(AC_TRANSFER_NEG, srb->pccb->ccb_h.path, &neg);
+               xpt_setup_ccb(&neg->ccb_h, srb->pccb->ccb_h.path, /*pri*/1);
+               xpt_async(AC_TRANSFER_NEG, srb->pccb->ccb_h.path, neg);
+               xpt_free_ccb(&neg->ccb_h);
+               neg = NULL; /* safety */
+               scsi = NULL; /* safety */
 
                /*
                 * Resend the identify for this CCB as the target
index 8cdedb5..d7d7b29 100644 (file)
@@ -54,6 +54,7 @@
 #include <bus/cam/cam_xpt_sim.h>
 #include <bus/cam/cam_debug.h>
 #include <bus/cam/scsi/scsi_message.h>
+#include <bus/cam/cam_xpt_periph.h>
 
 #include <vm/vm.h>
 #include <vm/pmap.h>
@@ -1538,24 +1539,27 @@ btdone(struct bt_softc *bt, struct bt_ccb *bccb, bt_mbi_comp_code_t comp_code)
                        break;
                case BTSTAT_TAGGED_MSG_REJECTED:
                {
-                       struct ccb_trans_settings neg; 
-                       struct ccb_trans_settings_scsi *scsi =
-                           &neg.proto_specific.scsi;
+                       struct ccb_trans_settings *neg;
+                       struct ccb_trans_settings_scsi *scsi;
+
+                       neg = &xpt_alloc_ccb()->cts;
+                       scsi = &neg->proto_specific.scsi;
 
-                       neg.protocol = PROTO_SCSI;
-                       neg.protocol_version = SCSI_REV_2;
-                       neg.transport = XPORT_SPI;
-                       neg.transport_version = 2;
+                       neg->protocol = PROTO_SCSI;
+                       neg->protocol_version = SCSI_REV_2;
+                       neg->transport = XPORT_SPI;
+                       neg->transport_version = 2;
                        scsi->valid = CTS_SCSI_VALID_TQ;
                        scsi->flags = 0;
                        xpt_print_path(csio->ccb_h.path);
                        kprintf("refuses tagged commands.  Performing "
                               "non-tagged I/O\n");
-                       xpt_setup_ccb(&neg.ccb_h, csio->ccb_h.path,
+                       xpt_setup_ccb(&neg->ccb_h, csio->ccb_h.path,
                                      /*priority*/1); 
-                       xpt_async(AC_TRANSFER_NEG, csio->ccb_h.path, &neg);
+                       xpt_async(AC_TRANSFER_NEG, csio->ccb_h.path, neg);
                        bt->tags_permitted &= ~(0x01 << csio->ccb_h.target_id);
                        csio->ccb_h.status = CAM_MSG_REJECT_REC;
+                       xpt_free_ccb(&neg->ccb_h);
                        break;
                }
                case BTSTAT_UNSUPPORTED_MSG_RECEIVED:
@@ -2035,7 +2039,7 @@ btfetchtransinfo(struct bt_softc *bt, struct ccb_trans_settings *cts)
                if (wide_active)
                        bus_width = MSG_EXT_WDTR_BUS_16_BIT;
        } else if ((bt->wide_permitted & targ_mask) != 0) {
-               struct ccb_getdev cgd;
+               struct ccb_getdev *cgd;
 
                /*
                 * Prior to rev 5.06L, wide status isn't provided,
@@ -2044,12 +2048,15 @@ btfetchtransinfo(struct bt_softc *bt, struct ccb_trans_settings *cts)
                 * data for the device indicates that it can handle
                 * wide transfers.
                 */
-               xpt_setup_ccb(&cgd.ccb_h, cts->ccb_h.path, /*priority*/1);
-               cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-               xpt_action((union ccb *)&cgd);
-               if ((cgd.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP
-                && (cgd.inq_data.flags & SID_WBus16) != 0)
+               cgd = &xpt_alloc_ccb()->cgd;
+               xpt_setup_ccb(&cgd->ccb_h, cts->ccb_h.path, /*priority*/1);
+               cgd->ccb_h.func_code = XPT_GDEV_TYPE;
+               xpt_action((union ccb *)cgd);
+               if ((cgd->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP &&
+                   (cgd->inq_data.flags & SID_WBus16) != 0) {
                        bus_width = MSG_EXT_WDTR_BUS_16_BIT;
+               }
+               xpt_free_ccb(&cgd->ccb_h);
        }
 
        if (bt->firmware_ver[0] >= '3') {
index bace329..226b0ad 100644 (file)
@@ -43,7 +43,9 @@
 #include <bus/cam/cam.h>
 #include <bus/cam/cam_ccb.h>
 #include <bus/cam/cam_sim.h>
+#include <bus/cam/cam_xpt.h>
 #include <bus/cam/cam_xpt_sim.h>
+#include <bus/cam/cam_xpt_periph.h>
 #include <bus/cam/cam_periph.h>
 
 #include <dev/disk/iscsi/initiator/iscsi.h>
@@ -100,9 +102,8 @@ _scan_callback(struct cam_periph *periph, union ccb *ccb)
 
      debug_called(8);
 
-     kfree(ccb, M_TEMP);
-
-     if(sp->flags & ISC_FFPWAIT) {
+     xpt_free_ccb(&ccb->ccb_h);
+     if (sp->flags & ISC_FFPWAIT) {
          sp->flags &= ~ISC_FFPWAIT;
          wakeup(sp);
      }
@@ -111,15 +112,13 @@ _scan_callback(struct cam_periph *periph, union ccb *ccb)
 static void
 _scan_target(isc_session_t *sp, int target)
 {
-     union ccb         *ccb;
+     union ccb *ccb;
 
      debug_called(8);
      sdebug(2, "target=%d", target);
 
-     if((ccb = kmalloc(sizeof(union ccb), M_TEMP, M_WAITOK | M_ZERO)) == NULL) {
-         xdebug("scan failed (can't allocate CCB)");
-         return;
-     }
+     ccb = xpt_alloc_ccb();
+
      CAM_LOCK(sp->isc);
      xpt_setup_ccb(&ccb->ccb_h, sp->cam_path, 5/*priority (low)*/);
      ccb->ccb_h.func_code      = XPT_SCAN_BUS;
index 3c99061..7696ed9 100644 (file)
@@ -84,7 +84,7 @@ static struct dev_ops isp_ops = {
 static int
 isp_attach_chan(ispsoftc_t *isp, struct cam_devq *devq, int chan)
 {
-       struct ccb_setasync csa;
+       struct ccb_setasync *csa;
        struct cam_sim *sim;
        struct cam_path *path;
 
@@ -112,12 +112,14 @@ isp_attach_chan(ispsoftc_t *isp, struct cam_devq *devq, int chan)
                cam_sim_free(sim);
                return (ENXIO);
        }
-       xpt_setup_ccb(&csa.ccb_h, path, 5);
-       csa.ccb_h.func_code = XPT_SASYNC_CB;
-       csa.event_enable = AC_LOST_DEVICE;
-       csa.callback = isp_cam_async;
-       csa.callback_arg = sim;
-       xpt_action((union ccb *)&csa);
+       csa = &xpt_alloc_ccb()->csa;
+       xpt_setup_ccb(&csa->ccb_h, path, 5);
+       csa->ccb_h.func_code = XPT_SASYNC_CB;
+       csa->event_enable = AC_LOST_DEVICE;
+       csa->callback = isp_cam_async;
+       csa->callback_arg = sim;
+       xpt_action((union ccb *)csa);
+       xpt_free_ccb(&csa->ccb_h);
 
        if (IS_SCSI(isp)) {
                struct isp_spi *spi = ISP_SPI_PC(isp, chan);
@@ -264,7 +266,7 @@ isp_detach(ispsoftc_t *isp)
 {
        struct cam_sim *sim;
        struct cam_path *path;
-       struct ccb_setasync csa;
+       struct ccb_setasync *csa;
        int chan;
 
        ISP_LOCK(isp);
@@ -293,12 +295,14 @@ isp_detach(ispsoftc_t *isp)
                        sim = ISP_SPI_PC(isp, chan)->sim;
                        path = ISP_SPI_PC(isp, chan)->path;
                }
-               xpt_setup_ccb(&csa.ccb_h, path, 5);
-               csa.ccb_h.func_code = XPT_SASYNC_CB;
-               csa.event_enable = 0;
-               csa.callback = isp_cam_async;
-               csa.callback_arg = sim;
-               xpt_action((union ccb *)&csa);
+               csa = &xpt_alloc_ccb()->csa;
+               xpt_setup_ccb(&csa->ccb_h, path, 5);
+               csa->ccb_h.func_code = XPT_SASYNC_CB;
+               csa->event_enable = 0;
+               csa->callback = isp_cam_async;
+               csa->callback_arg = sim;
+               xpt_action((union ccb *)csa);
+               xpt_free_ccb(&csa->ccb_h);
                xpt_free_path(path);
                xpt_bus_deregister(cam_sim_path(sim));
                cam_sim_free(sim);
@@ -3606,7 +3610,7 @@ isp_target_thread(ispsoftc_t *isp, int chan)
        xpt_action(ccb);
        ISP_UNLOCK(isp);
        if (ccb->ccb_h.status != CAM_REQ_CMP) {
-               xpt_free_ccb(ccb);
+               xpt_free_ccb(&ccb->ccb_h);
                xpt_print(periph->path, "failed to enable lun (0x%x)\n", ccb->ccb_h.status);
                goto out;
        }
@@ -3618,18 +3622,19 @@ isp_target_thread(ispsoftc_t *isp, int chan)
        xpt_action(ccb);
        ISP_UNLOCK(isp);
        if (ccb->ccb_h.status != CAM_REQ_CMP) {
-               xpt_free_ccb(ccb);
+               xpt_free_ccb(&ccb->ccb_h);
                xpt_print(wperiph->path, "failed to enable lun (0x%x)\n", ccb->ccb_h.status);
                goto out;
        }
-       xpt_free_ccb(ccb);
+       xpt_free_ccb(&ccb->ccb_h);
+       ccb = NULL; /* safety */
 
        /*
         * Add resources
         */
        ISP_GET_PC_ADDR(isp, chan, target_proc, wchan);
        for (i = 0; i < 4; i++) {
-               ccb = kmalloc(sizeof (*ccb), M_ISPTARG, M_WAITOK | M_ZERO);
+               ccb = xpt_alloc_ccb();
                xpt_setup_ccb(&ccb->ccb_h, wperiph->path, 1);
                ccb->ccb_h.func_code = XPT_ACCEPT_TARGET_IO;
                ccb->ccb_h.cbfcnp = isptarg_done;
@@ -3638,7 +3643,7 @@ isp_target_thread(ispsoftc_t *isp, int chan)
                ISP_UNLOCK(isp);
        }
        for (i = 0; i < NISP_TARG_CMDS; i++) {
-               ccb = kmalloc(sizeof (*ccb), M_ISPTARG, M_WAITOK | M_ZERO);
+               ccb = xpt_alloc_ccb();
                xpt_setup_ccb(&ccb->ccb_h, periph->path, 1);
                ccb->ccb_h.func_code = XPT_ACCEPT_TARGET_IO;
                ccb->ccb_h.cbfcnp = isptarg_done;
@@ -3647,7 +3652,7 @@ isp_target_thread(ispsoftc_t *isp, int chan)
                ISP_UNLOCK(isp);
        }
        for (i = 0; i < 4; i++) {
-               ccb = kmalloc(sizeof (*ccb), M_ISPTARG, M_WAITOK | M_ZERO);
+               ccb = xpt_alloc_ccb();
                xpt_setup_ccb(&ccb->ccb_h, wperiph->path, 1);
                ccb->ccb_h.func_code = XPT_IMMEDIATE_NOTIFY;
                ccb->ccb_h.cbfcnp = isptarg_done;
@@ -3656,7 +3661,7 @@ isp_target_thread(ispsoftc_t *isp, int chan)
                ISP_UNLOCK(isp);
        }
        for (i = 0; i < NISP_TARG_NOTIFIES; i++) {
-               ccb = kmalloc(sizeof (*ccb), M_ISPTARG, M_WAITOK | M_ZERO);
+               ccb = xpt_alloc_ccb();
                xpt_setup_ccb(&ccb->ccb_h, periph->path, 1);
                ccb->ccb_h.func_code = XPT_IMMEDIATE_NOTIFY;
                ccb->ccb_h.cbfcnp = isptarg_done;
@@ -3668,12 +3673,14 @@ isp_target_thread(ispsoftc_t *isp, int chan)
        /*
         * Now turn it all back on
         */
+       ccb = xpt_alloc_ccb();
        xpt_setup_ccb(&ccb->ccb_h, periph->path, 10);
        ccb->ccb_h.func_code = XPT_SET_SIM_KNOB;
        ccb->knob.xport_specific.fc.valid = KNOB_VALID_ROLE;
        ccb->knob.xport_specific.fc.role = KNOB_ROLE_TARGET;
        ISP_LOCK(isp);
        xpt_action(ccb);
+       xpt_free_ccb(&ccb->ccb_h);
        ISP_UNLOCK(isp);
 
        /*
@@ -3956,7 +3963,7 @@ isp_bus_scan_cb(struct cam_periph *periph, union ccb *ccb)
                        ccb->ccb_h.status);
 
        xpt_free_path(ccb->ccb_h.path);
-       kfree(ccb, M_TEMP);
+       xpt_free_ccb(&ccb->ccb_h);
 }
 
 static void
@@ -3979,7 +3986,7 @@ isp_make_here(ispsoftc_t *isp, int chan, int tgt)
        }
        if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, cam_sim_path(fc->sim), tgt, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                isp_prt(isp, ISP_LOGWARN, "unable to create path for rescan");
-               xpt_free_ccb(ccb);
+               xpt_free_ccb(&ccb->ccb_h);
                return;
        }
        xpt_setup_ccb(&ccb->ccb_h, ccb->ccb_h.path, 5/*priority (low)*/);
index 34d8ff0..d62d496 100644 (file)
  * $FreeBSD: src/sys/dev/mpt/mpt_cam.c,v 1.84 2012/02/11 12:03:44 marius Exp $
  */
 
+#include <bus/cam/cam.h>
+#include <bus/cam/cam_ccb.h>
+#include <bus/cam/cam_xpt.h>
+#include <bus/cam/cam_xpt_periph.h>
+
 #include <dev/disk/mpt/mpt.h>
 #include <dev/disk/mpt/mpt_cam.h>
 #include <dev/disk/mpt/mpt_raid.h>
@@ -2354,7 +2359,7 @@ static void
 mpt_cam_rescan_callback(struct cam_periph *periph, union ccb *ccb)
 {
     xpt_free_path(ccb->ccb_h.path);
-    kfree(ccb, M_TEMP);
+    xpt_free_ccb(&ccb->ccb_h);
 }
 
 static int
@@ -2408,21 +2413,20 @@ mpt_cam_event(struct mpt_softc *mpt, request_t *req,
                 * Allocate a CCB, create a wildcard path for this bus,
                 * and schedule a rescan.
                 */
-               ccb = kmalloc(sizeof(union ccb), M_TEMP, M_WAITOK | M_ZERO);
+               ccb = xpt_alloc_ccb();
 
                if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, pathid,
                    CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                        mpt_prt(mpt, "unable to create path for rescan\n");
-                       kfree(ccb, M_TEMP);
+                       xpt_free_ccb(&ccb->ccb_h);
                        break;
                }
 
-               xpt_setup_ccb(&ccb->ccb_h, ccb->ccb_h.path, 5/*priority (low)*/);
+               xpt_setup_ccb(&ccb->ccb_h, ccb->ccb_h.path, /*lowpri*/5);
                ccb->ccb_h.func_code = XPT_SCAN_BUS;
                ccb->ccb_h.cbfcnp = mpt_cam_rescan_callback;
                ccb->crcn.flags = CAM_FLAG_NONE;
                xpt_action(ccb);
-
                /* scan is now in progress */
 
                break;
@@ -2503,7 +2507,7 @@ mpt_cam_event(struct mpt_softc *mpt, request_t *req,
        {
                struct cam_sim *sim;
                struct cam_path *tmppath;
-               struct ccb_relsim crs;
+               struct ccb_relsim *crs;
                PTR_EVENT_DATA_QUEUE_FULL pqf;
                lun_id_t lun_id;
 
@@ -2524,16 +2528,18 @@ mpt_cam_event(struct mpt_softc *mpt, request_t *req,
                                    "XPT_REL_SIMQ");
                                break;
                        }
-                       xpt_setup_ccb(&crs.ccb_h, tmppath, 5);
-                       crs.ccb_h.func_code = XPT_REL_SIMQ;
-                       crs.ccb_h.flags = CAM_DEV_QFREEZE;
-                       crs.release_flags = RELSIM_ADJUST_OPENINGS;
-                       crs.openings = pqf->CurrentDepth - 1;
-                       xpt_action((union ccb *)&crs);
-                       if (crs.ccb_h.status != CAM_REQ_CMP) {
+                       crs = &xpt_alloc_ccb()->crs;
+                       xpt_setup_ccb(&crs->ccb_h, tmppath, 5);
+                       crs->ccb_h.func_code = XPT_REL_SIMQ;
+                       crs->ccb_h.flags = CAM_DEV_QFREEZE;
+                       crs->release_flags = RELSIM_ADJUST_OPENINGS;
+                       crs->openings = pqf->CurrentDepth - 1;
+                       xpt_action((union ccb *)crs);
+                       if (crs->ccb_h.status != CAM_REQ_CMP) {
                                mpt_prt(mpt, "XPT_REL_SIMQ failed\n");
                        }
                        xpt_free_path(tmppath);
+                       xpt_free_ccb(&crs->ccb_h);
                }
                break;
        }
@@ -2556,22 +2562,21 @@ mpt_cam_event(struct mpt_softc *mpt, request_t *req,
                        sim = mpt->sim;
                switch(psdsc->ReasonCode) {
                case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
-                       ccb = kmalloc(sizeof(union ccb), M_TEMP,
-                           M_WAITOK | M_ZERO);
+                       ccb = xpt_alloc_ccb();
                        if (xpt_create_path(&ccb->ccb_h.path, xpt_periph,
                            cam_sim_path(sim), psdsc->TargetID,
                            CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                                mpt_prt(mpt,
                                    "unable to create path for rescan\n");
-                               kfree(ccb, M_TEMP);
+                               xpt_free_ccb(&ccb->ccb_h);
                                break;
                        }
-                       xpt_setup_ccb(&ccb->ccb_h, ccb->ccb_h.path,
-                           5/*priority (low)*/);
+                       xpt_setup_ccb(&ccb->ccb_h, ccb->ccb_h.path, /*lopri*/5);
                        ccb->ccb_h.func_code = XPT_SCAN_BUS;
                        ccb->ccb_h.cbfcnp = mpt_cam_rescan_callback;
                        ccb->crcn.flags = CAM_FLAG_NONE;
                        xpt_action(ccb);
+                       /* scan now in progress */
                        break;
                case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
                        if (xpt_create_path(&tmppath, NULL, cam_sim_path(sim),
index f44dee2..ce00a34 100644 (file)
@@ -52,7 +52,9 @@
 #include <bus/cam/cam_ccb.h>
 #include <bus/cam/cam_periph.h>
 #include <bus/cam/cam_sim.h>
+#include <bus/cam/cam_xpt.h>
 #include <bus/cam/cam_xpt_sim.h>
+#include <bus/cam/cam_xpt_periph.h>
 
 #include <sys/callout.h>
 #include <sys/kthread.h>
@@ -272,7 +274,7 @@ mpt_raid_probe(struct mpt_softc *mpt)
 static int
 mpt_raid_attach(struct mpt_softc *mpt)
 {
-       struct ccb_setasync csa;
+       struct ccb_setasync *csa;
        mpt_handler_t    handler;
        int              error;
 
@@ -283,6 +285,7 @@ mpt_raid_attach(struct mpt_softc *mpt)
                mpt_prt(mpt, "Unable to spawn RAID thread!\n");
                goto cleanup;
        }
+       csa = &xpt_alloc_ccb()->csa;
 
        MPT_LOCK(mpt);
        handler.reply_handler = mpt_raid_reply_handler;
@@ -293,18 +296,19 @@ mpt_raid_attach(struct mpt_softc *mpt)
                goto cleanup;
        }
 
-       xpt_setup_ccb(&csa.ccb_h, mpt->path, 5);
-       csa.ccb_h.func_code = XPT_SASYNC_CB;
-       csa.event_enable = AC_FOUND_DEVICE;
-       csa.callback = mpt_raid_async;
-       csa.callback_arg = mpt;
-       xpt_action((union ccb *)&csa);
-       if (csa.ccb_h.status != CAM_REQ_CMP) {
+       xpt_setup_ccb(&csa->ccb_h, mpt->path, 5);
+       csa->ccb_h.func_code = XPT_SASYNC_CB;
+       csa->event_enable = AC_FOUND_DEVICE;
+       csa->callback = mpt_raid_async;
+       csa->callback_arg = mpt;
+       xpt_action((union ccb *)csa);
+       if (csa->ccb_h.status != CAM_REQ_CMP) {
                mpt_prt(mpt, "mpt_raid_attach: Unable to register "
                        "CAM async handler.\n");
        }
        MPT_UNLOCK(mpt);
 
+       xpt_free_ccb(&csa->ccb_h);
        mpt_raid_sysctl_attach(mpt);
        return (0);
 cleanup:
@@ -323,9 +327,10 @@ mpt_raid_enable(struct mpt_softc *mpt)
 static void
 mpt_raid_detach(struct mpt_softc *mpt)
 {
-       struct ccb_setasync csa;
+       struct ccb_setasync *csa;
        mpt_handler_t handler;
 
+       csa = &xpt_alloc_ccb()->csa;
        mpt_callout_drain(mpt, &mpt->raid_timer);
 
        MPT_LOCK(mpt);
@@ -333,13 +338,15 @@ mpt_raid_detach(struct mpt_softc *mpt)
        handler.reply_handler = mpt_raid_reply_handler;
        mpt_deregister_handler(mpt, MPT_HANDLER_REPLY, handler,
                               raid_handler_id);
-       xpt_setup_ccb(&csa.ccb_h, mpt->path, /*priority*/5);
-       csa.ccb_h.func_code = XPT_SASYNC_CB;
-       csa.event_enable = 0;
-       csa.callback = mpt_raid_async;
-       csa.callback_arg = mpt;
-       xpt_action((union ccb *)&csa);
+       xpt_setup_ccb(&csa->ccb_h, mpt->path, /*priority*/5);
+       csa->ccb_h.func_code = XPT_SASYNC_CB;
+       csa->event_enable = 0;
+       csa->callback = mpt_raid_async;
+       csa->callback_arg = mpt;
+       xpt_action((union ccb *)csa);
        MPT_UNLOCK(mpt);
+
+       xpt_free_ccb(&csa->ccb_h);
 }
 
 static void
@@ -718,8 +725,7 @@ mpt_raid_thread(void *arg)
                                kfree(ccb, M_TEMP);
                                mpt_prt(mpt, "Unable to rescan RAID Bus!\n");
                        } else {
-                               xpt_setup_ccb(&ccb->ccb_h, ccb->ccb_h.path,
-                                   5/*priority (low)*/);
+                               xpt_setup_ccb(&ccb->ccb_h, ccb->ccb_h.path, 5);
                                ccb->ccb_h.func_code = XPT_SCAN_BUS;
                                ccb->ccb_h.cbfcnp = mpt_cam_rescan_callback;
                                ccb->crcn.flags = CAM_FLAG_NONE;
@@ -1082,17 +1088,20 @@ static void
 mpt_adjust_queue_depth(struct mpt_softc *mpt, struct mpt_raid_volume *mpt_vol,
                       struct cam_path *path)
 {
-       struct ccb_relsim crs;
-
-       xpt_setup_ccb(&crs.ccb_h, path, /*priority*/5);
-       crs.ccb_h.func_code = XPT_REL_SIMQ;
-       crs.ccb_h.flags = CAM_DEV_QFREEZE;
-       crs.release_flags = RELSIM_ADJUST_OPENINGS;
-       crs.openings = mpt->raid_queue_depth;
-       xpt_action((union ccb *)&crs);
-       if (crs.ccb_h.status != CAM_REQ_CMP)
+       struct ccb_relsim *crs;
+
+       crs = &xpt_alloc_ccb()->crs;
+       xpt_setup_ccb(&crs->ccb_h, path, /*priority*/5);
+       crs->ccb_h.func_code = XPT_REL_SIMQ;
+       crs->ccb_h.flags = CAM_DEV_QFREEZE;
+       crs->release_flags = RELSIM_ADJUST_OPENINGS;
+       crs->openings = mpt->raid_queue_depth;
+       xpt_action((union ccb *)crs);
+       if (crs->ccb_h.status != CAM_REQ_CMP) {
                mpt_vol_prt(mpt, mpt_vol, "mpt_adjust_queue_depth failed "
-                           "with CAM status %#x\n", crs.ccb_h.status);
+                           "with CAM status %#x\n", crs->ccb_h.status);
+       }
+       xpt_free_ccb(&crs->ccb_h);
 }
 
 static void
index 8b6b74f..d49347f 100644 (file)
@@ -51,6 +51,7 @@
 #include <bus/cam/cam_xpt_sim.h>
 #include <bus/cam/cam_debug.h>
 #include <bus/cam/scsi/scsi_all.h>
+#include <bus/cam/cam_xpt_periph.h>
 
 #include "ata-all.h"
 #include "ata_if.h"
@@ -324,16 +325,20 @@ reinit_bus(struct atapi_xpt_softc *scp, enum reinit_reason reason) {
 static void
 setup_async_cb(struct atapi_xpt_softc *scp, uint32_t events)
 {
-    struct ccb_setasync csa;
+    struct ccb_setasync *csa;
+
+    csa = &xpt_alloc_ccb()->csa;
 
     get_mplock();
-    xpt_setup_ccb(&csa.ccb_h, scp->path, /*priority*/ 5);
-    csa.ccb_h.func_code = XPT_SASYNC_CB;
-    csa.event_enable = events;
-    csa.callback = &atapi_async;
-    csa.callback_arg = scp->sim;
-    xpt_action((union ccb *) &csa);
+    xpt_setup_ccb(&csa->ccb_h, scp->path, /*priority*/ 5);
+    csa->ccb_h.func_code = XPT_SASYNC_CB;
+    csa->event_enable = events;
+    csa->callback = &atapi_async;
+    csa->callback_arg = scp->sim;
+    xpt_action((union ccb *)csa);
     rel_mplock();
+
+    xpt_free_ccb(&csa->ccb_h);
 }
 
 static void
@@ -818,20 +823,22 @@ cam_rescan_callback(struct cam_periph *periph, union ccb *ccb)
                      ("Rescan succeeded\n"));
        }
        xpt_free_path(ccb->ccb_h.path);
-       kfree(ccb, M_ATACAM);
+       xpt_free_ccb(&ccb->ccb_h);
 }
 
 static void
 cam_rescan(struct cam_sim *sim)
 {
     struct cam_path *path;
-    union ccb *ccb = kmalloc(sizeof(union ccb), M_ATACAM, M_WAITOK | M_ZERO);
+    union ccb *ccb;
+
+    ccb = xpt_alloc_ccb();
 
     get_mplock();
     if (xpt_create_path(&path, xpt_periph, cam_sim_path(sim),
                        CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
        rel_mplock();
-       kfree(ccb, M_ATACAM);
+       xpt_free_ccb(&ccb->ccb_h);
        return;
     }
 
index 238b104..3977339 100644 (file)
 #include <bus/cam/cam.h>
 #include <bus/cam/cam_ccb.h>
 #include <bus/cam/cam_sim.h>
+#include <bus/cam/cam_xpt.h>
 #include <bus/cam/cam_xpt_sim.h>
+#include <bus/cam/cam_xpt_periph.h>
 #include <bus/cam/cam_debug.h>
 
+
 #include <bus/cam/scsi/scsi_all.h>
 #include <bus/cam/scsi/scsi_message.h>
 
@@ -4909,7 +4912,7 @@ static void
 ncr_setsync(ncb_p np, nccb_p cp, u_char scntl3, u_char sxfer, u_char period)
 {
        union   ccb *ccb;
-       struct  ccb_trans_settings neg; 
+       struct  ccb_trans_settings *neg;
        tcb_p   tp;
        int     div;
        u_int   target = INB (nc_sdid) & 0x0f;
@@ -4965,18 +4968,17 @@ ncr_setsync(ncb_p np, nccb_p cp, u_char scntl3, u_char sxfer, u_char period)
        ** Tell the SCSI layer about the
        ** new transfer parameters.
        */
-       memset(&neg, 0, sizeof (neg));
-       neg.protocol = PROTO_SCSI;
-       neg.protocol_version = SCSI_REV_2;
-       neg.transport = XPORT_SPI;
-       neg.transport_version = 2;
-       neg.xport_specific.spi.sync_period = period;
-       neg.xport_specific.spi.sync_offset = sxfer & 0x1f;
-       neg.xport_specific.spi.valid = CTS_SPI_VALID_SYNC_RATE
+       neg = &xpt_alloc_ccb()->cts;
+       neg->protocol = PROTO_SCSI;
+       neg->protocol_version = SCSI_REV_2;
+       neg->transport = XPORT_SPI;
+       neg->transport_version = 2;
+       neg->xport_specific.spi.sync_period = period;
+       neg->xport_specific.spi.sync_offset = sxfer & 0x1f;
+       neg->xport_specific.spi.valid = CTS_SPI_VALID_SYNC_RATE
                | CTS_SPI_VALID_SYNC_OFFSET;
-       xpt_setup_ccb(&neg.ccb_h, ccb->ccb_h.path,
-                     /*priority*/1);
-       xpt_async(AC_TRANSFER_NEG, ccb->ccb_h.path, &neg);
+       xpt_setup_ccb(&neg->ccb_h, ccb->ccb_h.path, /*priority*/1);
+       xpt_async(AC_TRANSFER_NEG, ccb->ccb_h.path, neg);
        
        /*
        **      set actual value and sync_status
@@ -4995,6 +4997,8 @@ ncr_setsync(ncb_p np, nccb_p cp, u_char scntl3, u_char sxfer, u_char period)
                cp->sync_status = sxfer;
                cp->wide_status = scntl3;
        }
+
+       xpt_free_ccb(&neg->ccb_h);
 }
 
 /*==========================================================
@@ -5010,7 +5014,7 @@ ncr_setsync(ncb_p np, nccb_p cp, u_char scntl3, u_char sxfer, u_char period)
 static void ncr_setwide (ncb_p np, nccb_p cp, u_char wide, u_char ack)
 {
        union   ccb *ccb;
-       struct  ccb_trans_settings neg;         
+       struct  ccb_trans_settings *neg;
        u_int   target = INB (nc_sdid) & 0x0f;
        tcb_p   tp;
        u_char  scntl3;
@@ -5042,20 +5046,21 @@ static void ncr_setwide (ncb_p np, nccb_p cp, u_char wide, u_char ack)
        tp->tinfo.wval = scntl3;
 
        /* Tell the SCSI layer about the new transfer params */
-       memset(&neg, 0, sizeof (neg));
-       neg.protocol = PROTO_SCSI;
-       neg.protocol_version = SCSI_REV_2;
-       neg.transport = XPORT_SPI;
-       neg.transport_version = 2;
-       neg.xport_specific.spi.bus_width = (scntl3 & EWS) ?
+       neg = &xpt_alloc_ccb()->cts;
+
+       neg->protocol = PROTO_SCSI;
+       neg->protocol_version = SCSI_REV_2;
+       neg->transport = XPORT_SPI;
+       neg->transport_version = 2;
+       neg->xport_specific.spi.bus_width = (scntl3 & EWS) ?
            MSG_EXT_WDTR_BUS_16_BIT : MSG_EXT_WDTR_BUS_8_BIT;
-       neg.xport_specific.spi.sync_period = 0;
-       neg.xport_specific.spi.sync_offset = 0;
-       neg.xport_specific.spi.valid = CTS_SPI_VALID_SYNC_RATE
+       neg->xport_specific.spi.sync_period = 0;
+       neg->xport_specific.spi.sync_offset = 0;
+       neg->xport_specific.spi.valid = CTS_SPI_VALID_SYNC_RATE
                | CTS_SPI_VALID_SYNC_OFFSET
                | CTS_SPI_VALID_BUS_WIDTH;
-       xpt_setup_ccb(&neg.ccb_h, ccb->ccb_h.path, /*priority*/1);
-       xpt_async(AC_TRANSFER_NEG, ccb->ccb_h.path, &neg);      
+       xpt_setup_ccb(&neg->ccb_h, ccb->ccb_h.path, /*priority*/1);
+       xpt_async(AC_TRANSFER_NEG, ccb->ccb_h.path, neg);
 
        /*
        **      set actual value and sync_status
@@ -5074,6 +5079,8 @@ static void ncr_setwide (ncb_p np, nccb_p cp, u_char wide, u_char ack)
                cp->sync_status = sxfer;
                cp->wide_status = scntl3;
        }
+
+       xpt_free_ccb(&neg->ccb_h);
 }
 
 /*==========================================================
index c0394ee..0063792 100644 (file)
@@ -52,6 +52,7 @@
 #include <bus/cam/cam_debug.h>
 #include <bus/cam/cam_periph.h>
 #include <bus/cam/scsi/scsi_all.h>
+#include <bus/cam/cam_xpt_periph.h>
 
 #include <bus/firewire/firewire.h>
 #include <bus/firewire/firewirereg.h>
@@ -949,7 +950,7 @@ END_DEBUG
        }
        sdev = sbp_next_dev(target, sdev->lun_id + 1);
        if (sdev == NULL) {
-               kfree(ccb, M_SBP);
+               xpt_free_ccb(&ccb->ccb_h);
                return;
        }
        /* reuse ccb */
@@ -977,7 +978,7 @@ SBP_DEBUG(0)
        sbp_show_sdev_info(sdev, 2);
        kprintf("sbp_cam_scan_target\n");
 END_DEBUG
-       ccb = kmalloc(sizeof(union ccb), M_SBP, M_WAITOK | M_ZERO);
+       ccb = xpt_alloc_ccb();
        xpt_setup_ccb(&ccb->ccb_h, sdev->path, SCAN_PRI);
        ccb->ccb_h.func_code = XPT_SCAN_LUN;
        ccb->ccb_h.cbfcnp = sbp_cam_scan_lun;
@@ -2584,7 +2585,7 @@ END_DEBUG
                        /* found */
                        STAILQ_REMOVE(&sdev->ocbs, ocb, sbp_ocb, ocb);
                        if (ocb->ccb != NULL)
-                               callout_stop(&ocb->ccb->ccb_h.timeout_ch);
+                               callout_stop(ocb->ccb->ccb_h.timeout_ch);
                        if (ntohl(ocb->orb[4]) & 0xffff) {
                                bus_dmamap_sync(sdev->target->sbp->dmat,
                                        ocb->dmamap,
@@ -2635,8 +2636,9 @@ END_DEBUG
        STAILQ_INSERT_TAIL(&sdev->ocbs, ocb, ocb);
 
        if (ocb->ccb != NULL)
-               callout_reset(&ocb->ccb->ccb_h.timeout_ch,
-                   (ocb->ccb->ccb_h.timeout * hz) / 1000, sbp_timeout, ocb);
+               callout_reset(ocb->ccb->ccb_h.timeout_ch,
+                             (ocb->ccb->ccb_h.timeout * hz) / 1000,
+                             sbp_timeout, ocb);
 
        if (prev != NULL) {
 SBP_DEBUG(2)
@@ -2698,7 +2700,7 @@ END_DEBUG
                bus_dmamap_unload(sdev->target->sbp->dmat, ocb->dmamap);
        }
        if (ocb->ccb != NULL) {
-               callout_stop(&ocb->ccb->ccb_h.timeout_ch);
+               callout_stop(ocb->ccb->ccb_h.timeout_ch);
                ocb->ccb->ccb_h.status = status;
                xpt_done(ocb->ccb);
        }
index 99fc1c8..86da74b 100644 (file)
@@ -720,7 +720,7 @@ sili_cam_rescan_callback(struct cam_periph *periph, union ccb *ccb)
                ap->ap_flags |= AP_F_SCAN_COMPLETED;
                wakeup(&ap->ap_flags);
        }
-       xpt_free_ccb(ccb);
+       xpt_free_ccb(&ccb->ccb_h);
 }
 
 static void
index cbb1e61..e5a3a23 100644 (file)
 #include <bus/cam/cam.h>
 #include <bus/cam/cam_ccb.h>
 #include <bus/cam/cam_sim.h>
+#include <bus/cam/cam_xpt.h>
 #include <bus/cam/cam_xpt_sim.h>
+#include <bus/cam/cam_xpt_periph.h>
 #include <bus/cam/cam_debug.h>
 
+
 #include <bus/cam/scsi/scsi_all.h>
 #include <bus/cam/scsi/scsi_message.h>
 
@@ -3443,7 +3446,7 @@ sym_getsync(hcb_p np, u_char dt, u_char sfac, u_char *divp, u_char *fakp)
 static void
 sym_xpt_async_transfer_neg(hcb_p np, int target, u_int spi_valid)
 {
-       struct ccb_trans_settings cts;
+       struct ccb_trans_settings *cts;
        struct cam_path *path;
        int sts;
        tcb_p tp = &np->target[target];
@@ -3453,16 +3456,16 @@ sym_xpt_async_transfer_neg(hcb_p np, int target, u_int spi_valid)
        if (sts != CAM_REQ_CMP)
                return;
 
-       bzero(&cts, sizeof(cts));
+       cts = &xpt_alloc_ccb()->cts;
 
-#define        cts__scsi (cts.proto_specific.scsi)
-#define        cts__spi  (cts.xport_specific.spi)
+#define        cts__scsi (cts->proto_specific.scsi)
+#define        cts__spi  (cts->xport_specific.spi)
 
-       cts.type      = CTS_TYPE_CURRENT_SETTINGS;
-       cts.protocol  = PROTO_SCSI;
-       cts.transport = XPORT_SPI;
-       cts.protocol_version  = tp->tinfo.current.scsi_version;
-       cts.transport_version = tp->tinfo.current.spi_version;
+       cts->type      = CTS_TYPE_CURRENT_SETTINGS;
+       cts->protocol  = PROTO_SCSI;
+       cts->transport = XPORT_SPI;
+       cts->protocol_version  = tp->tinfo.current.scsi_version;
+       cts->transport_version = tp->tinfo.current.spi_version;
 
        cts__spi.valid = spi_valid;
        if (spi_valid & CTS_SPI_VALID_SYNC_RATE)
@@ -3475,9 +3478,10 @@ sym_xpt_async_transfer_neg(hcb_p np, int target, u_int spi_valid)
                cts__spi.ppr_options = tp->tinfo.current.options;
 #undef cts__spi
 #undef cts__scsi
-       xpt_setup_ccb(&cts.ccb_h, path, /*priority*/1);
-       xpt_async(AC_TRANSFER_NEG, path, &cts);
+       xpt_setup_ccb(&cts->ccb_h, path, /*priority*/1);
+       xpt_async(AC_TRANSFER_NEG, path, cts);
        xpt_free_path(path);
+       xpt_free_ccb(&cts->ccb_h);
 }
 
 #define SYM_SPI_VALID_WDTR             \
index 5dbcce6..7c27bc7 100644 (file)
@@ -85,7 +85,9 @@
 #include <bus/cam/cam.h>
 #include <bus/cam/cam_ccb.h>
 #include <bus/cam/cam_sim.h>
+#include <bus/cam/cam_xpt.h>
 #include <bus/cam/cam_xpt_sim.h>
+#include <bus/cam/cam_xpt_periph.h>
 #include <bus/cam/cam_debug.h>
 
 #include <bus/cam/scsi/scsi_all.h>
@@ -2274,7 +2276,7 @@ static void
 trm_SetXferRate(PACB pACB,PSRB pSRB, PDCB pDCB)
 {
        union ccb       *pccb;
-       struct ccb_trans_settings neg;
+       struct ccb_trans_settings *neg;
        u_int16_t       cnt, i;
        u_int8_t        bval;
        PDCB            pDCBTemp;
@@ -2284,13 +2286,17 @@ trm_SetXferRate(PACB pACB,PSRB pSRB, PDCB pDCB)
         */
        TRM_DPRINTF("trm_SetXferRate\n");
        pccb = pSRB->pccb;
-       memset(&neg, 0, sizeof (neg));
-       neg.xport_specific.spi.sync_period = pDCB->tinfo.goal.period;
-       neg.xport_specific.spi.sync_offset = pDCB->tinfo.goal.offset;
-       neg.xport_specific.spi.valid =
+
+       neg = &xpt_alloc_ccb()->cts;
+
+       neg->xport_specific.spi.sync_period = pDCB->tinfo.goal.period;
+       neg->xport_specific.spi.sync_offset = pDCB->tinfo.goal.offset;
+       neg->xport_specific.spi.valid =
            CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
-       xpt_setup_ccb(&neg.ccb_h, pccb->ccb_h.path, /* priority */1);
-       xpt_async(AC_TRANSFER_NEG, pccb->ccb_h.path, &neg);
+       xpt_setup_ccb(&neg->ccb_h, pccb->ccb_h.path, /* priority */1);
+       xpt_async(AC_TRANSFER_NEG, pccb->ccb_h.path, neg);
+       xpt_free_ccb(&neg->ccb_h);
+
        if (!(pDCB->IdentifyMsg & 0x07)) {
                pDCBTemp = pACB->pLinkDCB;
                cnt = pACB->DeviceCnt;
@@ -2304,7 +2310,6 @@ trm_SetXferRate(PACB pACB,PSRB pSRB, PDCB pDCB)
                        pDCBTemp = pDCBTemp->pNextDCB;
                }
        }
-       return;
 }
 
 /*
index 2eeab11..89a0501 100644 (file)
 #include <bus/cam/cam.h>
 #include <bus/cam/cam_ccb.h>
 #include <bus/cam/cam_sim.h>
+#include <bus/cam/cam_xpt.h>
 #include <bus/cam/cam_xpt_sim.h>
+#include <bus/cam/cam_xpt_periph.h>
 #include <bus/cam/cam_debug.h>
 #include <bus/cam/cam_periph.h>
 
+
 #include <bus/cam/scsi/scsi_all.h>
 #include <bus/cam/scsi/scsi_message.h>
 #include <bus/cam/scsi/scsi_da.h>
@@ -173,15 +176,16 @@ vpo_attach(device_t dev)
 static void
 vpo_cam_rescan_callback(struct cam_periph *periph, union ccb *ccb)
 {
-        kfree(ccb, M_TEMP);
+       xpt_free_ccb(&ccb->ccb_h);
 }
 
 static void
 vpo_cam_rescan(struct vpo_data *vpo)
 {
         struct cam_path *path;
-        union ccb *ccb = kmalloc(sizeof(union ccb), M_TEMP, M_WAITOK | M_ZERO);
+        union ccb *ccb;
 
+       ccb = xpt_alloc_ccb();
         if (xpt_create_path(&path, xpt_periph, cam_sim_path(vpo->sim), 0, 0)
             != CAM_REQ_CMP) {
                /* A failure is benign as the user can do a manual rescan */
index 821d8a3..92a6e2b 100644 (file)
@@ -130,7 +130,7 @@ aac_cam_rescan(struct aac_softc *sc, uint32_t channel, uint32_t target_id)
                if (xpt_create_path(&ccb->ccb_h.path, xpt_periph,
                    cam_sim_path(camsc->sim),
                    target_id, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
-                       xpt_free_ccb(ccb);
+                       xpt_free_ccb(&ccb->ccb_h);
                        device_printf(sc->aac_dev,
                            "Cannot create path for bus rescan.\n");
                        return;
@@ -152,7 +152,7 @@ aac_bus_scan_cb(struct cam_periph *periph, union ccb *ccb)
                        ccb->ccb_h.status);
 
        xpt_free_path(ccb->ccb_h.path);
-       xpt_free_ccb(ccb);
+       xpt_free_ccb(&ccb->ccb_h);
 }
 
 static void
index 78b14b1..f2986a2 100644 (file)
@@ -1639,7 +1639,7 @@ static void arcmsr_rescanLun_cb(struct cam_periph *periph, union ccb *ccb)
                kprintf("arcmsr_rescanLun_cb: Rescan lun successfully!\n");
 */
        xpt_free_path(ccb->ccb_h.path);
-       xpt_free_ccb(ccb);
+       xpt_free_ccb(&ccb->ccb_h);
 }
 
 static void    arcmsr_rescan_lun(struct AdapterControlBlock *acb, int target, int lun)
@@ -1651,11 +1651,9 @@ static void      arcmsr_rescan_lun(struct AdapterControlBlock *acb, int target, int l
                return;
        if (xpt_create_path(&path, xpt_periph, cam_sim_path(acb->psim), target, lun) != CAM_REQ_CMP)
        {
-               xpt_free_ccb(ccb);
+               xpt_free_ccb(&ccb->ccb_h);
                return;
        }
-/*     kprintf("arcmsr_rescan_lun: Rescan Target=%x, Lun=%x\n", target, lun); */
-       bzero(ccb, sizeof(union ccb));
        xpt_setup_ccb(&ccb->ccb_h, path, 5);
        ccb->ccb_h.func_code = XPT_SCAN_LUN;
        ccb->ccb_h.cbfcnp = arcmsr_rescanLun_cb;
@@ -4748,7 +4746,7 @@ static int arcmsr_attach(device_t dev)
        return (0);
 
 xpt_path_failed:
-        xpt_free_ccb(ccb);
+        xpt_free_ccb(&ccb->ccb_h);
 xpt_ccb_failed:
        xpt_bus_deregister(cam_sim_path(acb->psim));
 xpt_bus_failed:
index ad5ecbc..c0ff6e5 100644 (file)
 #include <bus/cam/cam_ccb.h>
 #include <bus/cam/cam_sim.h>
 #include <bus/cam/cam_xpt_sim.h>
+#include <bus/cam/cam_xpt_periph.h>
 
 #include <bus/cam/scsi/scsi_all.h>
 #include <bus/cam/scsi/scsi_message.h>
@@ -780,8 +781,9 @@ ASR_ccbAdd(Asr_softc_t *sc, union asr_ccb *ccb)
                         */
                        ccb->ccb_h.timeout = 6 * 60 * 1000;
                }
-               callout_reset(&ccb->ccb_h.timeout_ch,
-                   (ccb->ccb_h.timeout * hz) / 1000, asr_timeout, ccb);
+               callout_reset(ccb->ccb_h.timeout_ch,
+                             (ccb->ccb_h.timeout * hz) / 1000,
+                             asr_timeout, ccb);
        }
        crit_exit();
 } /* ASR_ccbAdd */
@@ -793,7 +795,7 @@ static __inline void
 ASR_ccbRemove(Asr_softc_t *sc, union asr_ccb *ccb)
 {
        crit_enter();
-       callout_stop(&ccb->ccb_h.timeout_ch);
+       callout_stop(ccb->ccb_h.timeout_ch);
        LIST_REMOVE(&(ccb->ccb_h), sim_links.le);
        crit_exit();
 } /* ASR_ccbRemove */
@@ -1169,15 +1171,18 @@ ASR_rescan(Asr_softc_t *sc)
                                                          AC_LOST_DEVICE,
                                                          path, NULL);
                                                } else if (LastTID == (tid_t)-1) {
-                                                       struct ccb_getdev ccb;
+                                                       struct ccb_getdev *ccb;
+
+                                                       ccb = &xpt_alloc_ccb()->cgd;
 
                                                        xpt_setup_ccb(
-                                                         &(ccb.ccb_h),
+                                                         &ccb->ccb_h,
                                                          path, /*priority*/5);
                                                        xpt_async(
                                                          AC_FOUND_DEVICE,
                                                          path,
-                                                         &ccb);
+                                                         ccb);
+                                                       xpt_free_ccb(&ccb->ccb_h);
                                                } else {
                                                        xpt_async(
                                                          AC_INQ_CHANGED,
@@ -1300,8 +1305,9 @@ asr_timeout(void *arg)
                  cam_sim_unit(xpt_path_sim(ccb->ccb_h.path)), s);
                if (ASR_reset (sc) == ENXIO) {
                        /* Try again later */
-                       callout_reset(&ccb->ccb_h.timeout_ch,
-                           (ccb->ccb_h.timeout * hz) / 1000, asr_timeout, ccb);
+                       callout_reset(ccb->ccb_h.timeout_ch,
+                                     (ccb->ccb_h.timeout * hz) / 1000,
+                                     asr_timeout, ccb);
                }
                return;
        }
@@ -1315,8 +1321,9 @@ asr_timeout(void *arg)
        if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_CMD_TIMEOUT) {
                debug_asr_printf (" AGAIN\nreinitializing adapter\n");
                if (ASR_reset (sc) == ENXIO) {
-                       callout_reset(&ccb->ccb_h.timeout_ch,
-                           (ccb->ccb_h.timeout * hz) / 1000, asr_timeout, ccb);
+                       callout_reset(ccb->ccb_h.timeout_ch,
+                                     (ccb->ccb_h.timeout * hz) / 1000,
+                                     asr_timeout, ccb);
                }
                crit_exit();
                return;
@@ -1325,7 +1332,8 @@ asr_timeout(void *arg)
        /* If the BUS reset does not take, then an adapter reset is next! */
        ccb->ccb_h.status &= ~CAM_STATUS_MASK;
        ccb->ccb_h.status |= CAM_CMD_TIMEOUT;
-       callout_reset(&ccb->ccb_h.timeout_ch, (ccb->ccb_h.timeout * hz) / 1000,
+       callout_reset(ccb->ccb_h.timeout_ch,
+                     (ccb->ccb_h.timeout * hz) / 1000,
                      asr_timeout, ccb);
        ASR_resetBus (sc, cam_sim_bus(xpt_path_sim(ccb->ccb_h.path)));
        xpt_async (AC_BUS_RESET, ccb->ccb_h.path, NULL);
index 84387a1..036ae18 100644 (file)
@@ -93,6 +93,7 @@
 #include <bus/cam/cam_xpt_sim.h>
 #include <bus/cam/scsi/scsi_all.h>
 #include <bus/cam/scsi/scsi_message.h>
+#include <bus/cam/cam_xpt_periph.h>
 
 #include <machine/endian.h>
 #include <sys/rman.h>
@@ -2844,17 +2845,17 @@ ciss_cam_init(struct ciss_softc *sc)
 static void
 ciss_cam_rescan_target(struct ciss_softc *sc, int bus, int target)
 {
-    union ccb          *ccb;
+    union ccb *ccb;
 
     debug_called(1);
 
-    ccb = kmalloc(sizeof(union ccb), M_TEMP, M_WAITOK | M_ZERO);
+    ccb = xpt_alloc_ccb();
 
     if (xpt_create_path(&ccb->ccb_h.path, xpt_periph,
            cam_sim_path(sc->ciss_cam_sim[bus]),
            target, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
        ciss_printf(sc, "rescan failed (can't create path)\n");
-       kfree(ccb, M_TEMP);
+       xpt_free_ccb(&ccb->ccb_h);
        return;
     }
 
@@ -2885,7 +2886,7 @@ static void
 ciss_cam_rescan_callback(struct cam_periph *periph, union ccb *ccb)
 {
     xpt_free_path(ccb->ccb_h.path);
-    kfree(ccb, M_TEMP);
+    xpt_free_ccb(&ccb->ccb_h);
 }
 
 /************************************************************************
index aed7ff2..0f7dc9f 100644 (file)
@@ -775,7 +775,7 @@ dptexecuteccb(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
        dccb->state |= DCCB_ACTIVE;
        ccb->ccb_h.status |= CAM_SIM_QUEUED;
        LIST_INSERT_HEAD(&dpt->pending_ccb_list, &ccb->ccb_h, sim_links.le);
-       callout_reset(&ccb->ccb_h.timeout_ch, (ccb->ccb_h.timeout * hz) / 1000,
+       callout_reset(ccb->ccb_h.timeout_ch, (ccb->ccb_h.timeout * hz) / 1000,
                      dpttimeout, dccb);
        if (dpt_send_eata_command(dpt, &dccb->eata_ccb,
                                  dccb->eata_ccb.cp_busaddr,
@@ -1592,7 +1592,7 @@ dpt_intr(void *arg)
                }
                /* Process CCB */
                ccb = dccb->ccb;
-               callout_stop(&ccb->ccb_h.timeout_ch);
+               callout_stop(ccb->ccb_h.timeout_ch);
                if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
                        bus_dmasync_op_t op;
 
index 669685b..5985ae2 100644 (file)
@@ -425,7 +425,7 @@ static void os_cmddone(PCOMMAND pCmd)
 
        KdPrint(("os_cmddone(%p, %d)", pCmd, pCmd->Result));
 
-       callout_stop(&ccb->ccb_h.timeout_ch);
+       callout_stop(ccb->ccb_h.timeout_ch);
 
        switch(pCmd->Result) {
        case RETURN_SUCCESS:
@@ -527,7 +527,8 @@ static void hpt_io_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs
                bus_dmamap_sync(ext->vbus_ext->io_dmat, ext->dma_map, BUS_DMASYNC_PREWRITE);
        }
 
-       callout_reset(&ext->ccb->ccb_h.timeout_ch, HPT_OSM_TIMEOUT, hpt_timeout, pCmd);
+       callout_reset(ext->ccb->ccb_h.timeout_ch, HPT_OSM_TIMEOUT,
+                     hpt_timeout, pCmd);
        ldm_queue_cmd(pCmd);
 }
 
@@ -726,7 +727,8 @@ static void hpt_scsi_io(PVBUS_EXT vbus_ext, union ccb *ccb)
                                pCmd->psg[idx].eot = (idx==ccb->csio.sglist_cnt-1)? 1 : 0;
                        }
 
-                       callout_reset(&ccb->ccb_h.timeout_ch, HPT_OSM_TIMEOUT, hpt_timeout, pCmd);
+                       callout_reset(ccb->ccb_h.timeout_ch, HPT_OSM_TIMEOUT,
+                                     hpt_timeout, pCmd);
                        ldm_queue_cmd(pCmd);
                }
                else {
@@ -1033,7 +1035,7 @@ static void hpt_final_init(void *dummy)
        /* register CAM interface */
        ldm_for_each_vbus(vbus, vbus_ext) {
                struct cam_devq *devq;
-               struct ccb_setasync     ccb;
+               struct ccb_setasync *ccb;
 
                lockinit(&vbus_ext->lock, "hptsleeplock", 0, LK_CANRECURSE);
                if (bus_dma_tag_create(NULL,/* parent */
@@ -1099,12 +1101,14 @@ static void hpt_final_init(void *dummy)
                        return ;
                }
 
-               xpt_setup_ccb(&ccb.ccb_h, vbus_ext->path, /*priority*/5);
-               ccb.ccb_h.func_code = XPT_SASYNC_CB;
-               ccb.event_enable = AC_LOST_DEVICE;
-               ccb.callback = hpt_async;
-               ccb.callback_arg = vbus_ext;
-               xpt_action((union ccb *)&ccb);
+               ccb = &xpt_alloc_ccb()->csa;
+               xpt_setup_ccb(&ccb->ccb_h, vbus_ext->path, /*priority*/5);
+               ccb->ccb_h.func_code = XPT_SASYNC_CB;
+               ccb->event_enable = AC_LOST_DEVICE;
+               ccb->callback = hpt_async;
+               ccb->callback_arg = vbus_ext;
+               xpt_action((union ccb *)ccb);
+               xpt_free_ccb(&ccb->ccb_h);
 
                for (hba = vbus_ext->hba_list; hba; hba = hba->next) {
                        int rid = 0;
@@ -1344,7 +1348,7 @@ static int        hpt_rescan_bus(void)
                        rel_mplock();
                        return(EIO);
                }
-               ccb = kmalloc(sizeof(union ccb), M_TEMP, M_WAITOK);
+               ccb = xpt_alloc_ccb();
                bzero(ccb, sizeof(union ccb));
                xpt_setup_ccb(&ccb->ccb_h, path, 5);
                ccb->ccb_h.func_code = XPT_SCAN_BUS;
@@ -1366,6 +1370,5 @@ static    void    hpt_bus_scan_cb(struct cam_periph *periph, union ccb *ccb)
                KdPrint(("Scan bus successfully!"));
 
        xpt_free_path(ccb->ccb_h.path);
-       kfree(ccb, M_TEMP);
-       return;
+       xpt_free_ccb(&ccb->ccb_h);
 }
index a8f19b8..e353a4e 100644 (file)
@@ -637,7 +637,7 @@ static void hptiop_request_callback_mvfrey(struct hpt_iop_hba * hba,
 
                ccb = (union ccb *)srb->ccb;
 
-               callout_stop(&ccb->ccb_h.timeout_ch);
+               callout_stop(ccb->ccb_h.timeout_ch);
 
                if (ccb->ccb_h.flags & CAM_CDB_POINTER)
                        cdb = ccb->csio.cdb_io.cdb_ptr;
@@ -1394,7 +1394,7 @@ static int  hptiop_rescan_bus(struct hpt_iop_hba * hba)
                return(ENOMEM);
        if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, cam_sim_path(hba->sim),
                CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
-               xpt_free_ccb(ccb);
+               xpt_free_ccb(&ccb->ccb_h);
                return(EIO);
        }
 
@@ -1409,7 +1409,7 @@ static int  hptiop_rescan_bus(struct hpt_iop_hba * hba)
 static void hptiop_bus_scan_cb(struct cam_periph *periph, union ccb *ccb)
 {
        xpt_free_path(ccb->ccb_h.path);
-       kfree(ccb, M_TEMP);
+       xpt_free_ccb(&ccb->ccb_h);
 }
 
 static bus_dmamap_callback_t   hptiop_map_srb;
@@ -1878,7 +1878,7 @@ static int hptiop_attach(device_t dev)
        struct hpt_iop_request_set_config  set_config;
        int rid = 0;
        struct cam_devq *devq;
-       struct ccb_setasync ccb;
+       struct ccb_setasync *ccb;
        u_int32_t unit = device_get_unit(dev);
 
        device_printf(dev, "RocketRAID 3xxx/4xxx controller driver %s\n",
@@ -2031,12 +2031,15 @@ static int hptiop_attach(device_t dev)
                goto free_hba_path;
        }
 
-       xpt_setup_ccb(&ccb.ccb_h, hba->path, /*priority*/5);
-       ccb.ccb_h.func_code = XPT_SASYNC_CB;
-       ccb.event_enable = (AC_FOUND_DEVICE | AC_LOST_DEVICE);
-       ccb.callback = hptiop_async;
-       ccb.callback_arg = hba->sim;
-       xpt_action((union ccb *)&ccb);
+       ccb = &xpt_alloc_ccb()->csa;
+
+       xpt_setup_ccb(&ccb->ccb_h, hba->path, /*priority*/5);
+       ccb->ccb_h.func_code = XPT_SASYNC_CB;
+       ccb->event_enable = (AC_FOUND_DEVICE | AC_LOST_DEVICE);
+       ccb->callback = hptiop_async;
+       ccb->callback_arg = hba->sim;
+       xpt_action((union ccb *)ccb);
+       xpt_free_ccb(&ccb->ccb_h);
 
        rid = 0;
        if ((hba->irq_res = bus_alloc_resource(hba->pcidev, SYS_RES_IRQ,
@@ -2648,8 +2651,8 @@ static void hptiop_post_req_mvfrey(struct hpt_iop_hba *hba,
        BUS_SPACE_RD4_MVFREY2(inbound_write_ptr);
 
        if (req->header.type == IOP_REQUEST_TYPE_SCSI_COMMAND) {
-               callout_reset(&ccb->ccb_h.timeout_ch, 20*hz,
-                   hptiop_reset_adapter, hba);
+               callout_reset(ccb->ccb_h.timeout_ch, 20 * hz,
+                             hptiop_reset_adapter, hba);
        }
 }
 
@@ -2803,15 +2806,17 @@ static void hptiop_release_resource(struct hpt_iop_hba *hba)
 {
        int i;
        if (hba->path) {
-               struct ccb_setasync ccb;
-
-               xpt_setup_ccb(&ccb.ccb_h, hba->path, /*priority*/5);
-               ccb.ccb_h.func_code = XPT_SASYNC_CB;
-               ccb.event_enable = 0;
-               ccb.callback = hptiop_async;
-               ccb.callback_arg = hba->sim;
-               xpt_action((union ccb *)&ccb);
+               struct ccb_setasync *ccb;
+
+               ccb = &xpt_alloc_ccb()->csa;
+               xpt_setup_ccb(&ccb->ccb_h, hba->path, /*priority*/5);
+               ccb->ccb_h.func_code = XPT_SASYNC_CB;
+               ccb->event_enable = 0;
+               ccb->callback = hptiop_async;
+               ccb->callback_arg = hba->sim;
+               xpt_action((union ccb *)ccb);
                xpt_free_path(hba->path);
+               xpt_free_ccb(&ccb->ccb_h);
        }
 
        if (hba->sim) {
index 6619906..91b75fd 100644 (file)
 
 #include <bus/pci/pcireg.h>
 #include <bus/pci/pcivar.h>
+#include <bus/cam/cam.h>
+#include <bus/cam/cam_ccb.h>
+#include <bus/cam/cam_xpt.h>
+#include <bus/cam/cam_xpt_periph.h>
 
 #ifndef __KERNEL__
 #define __KERNEL__
@@ -2024,8 +2028,7 @@ hpt_attach(device_t dev)
                return(ENXIO);
        }
 
-
-       ccb = kmalloc(sizeof(*ccb), M_DEVBUF, M_WAITOK | M_ZERO);
+       ccb = xpt_alloc_ccb();
        ccb->ccb_h.pinfo.priority = 1;
        ccb->ccb_h.pinfo.index = CAM_UNQUEUED_INDEX;
 
@@ -2065,13 +2068,13 @@ hpt_attach(device_t dev)
                return ENXIO;
        }
 
-       xpt_setup_ccb(&(ccb->ccb_h), pAdapter->path, /*priority*/5);
+       xpt_setup_ccb(&ccb->ccb_h, pAdapter->path, /*priority*/5);
        ccb->ccb_h.func_code = XPT_SASYNC_CB;
        ccb->csa.event_enable = AC_LOST_DEVICE;
        ccb->csa.callback = hpt_async;
        ccb->csa.callback_arg = hpt_vsim;
        xpt_action(ccb);
-       kfree(ccb, M_DEVBUF);
+       xpt_free_ccb(&ccb->ccb_h);
 
        callout_init(&pAdapter->event_timer_connect);
        callout_init(&pAdapter->event_timer_disconnect);
@@ -2664,7 +2667,7 @@ hpt_io_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
                bus_dmamap_sync(pAdapter->io_dma_parent, pmap->dma_map, BUS_DMASYNC_PREWRITE);
        }
 
-       callout_reset(&ccb->ccb_h.timeout_ch, 20*hz, hpt_timeout, ccb);
+       callout_reset(ccb->ccb_h.timeout_ch, 20*hz, hpt_timeout, ccb);
        pVDev->pfnSendCommand(_VBUS_P pCmd);
        CheckPendingCall(_VBUS_P0);
 }
@@ -2860,7 +2863,8 @@ OsSendCommand(_VBUS_ARG union ccb *ccb)
                                        pCmd->pSgTable[idx].wSgFlag= (idx==ccb->csio.sglist_cnt-1)?SG_FLAG_EOT: 0;
                                }
 
-                               callout_reset(&ccb->ccb_h.timeout_ch, 20*hz, hpt_timeout, ccb);
+                               callout_reset(ccb->ccb_h.timeout_ch, 20 * hz,
+                                             hpt_timeout, ccb);
                                pVDev->pfnSendCommand(_VBUS_P pCmd);
                        }
                        else {
@@ -2904,7 +2908,7 @@ fOsCommandDone(_VBUS_ARG PCommand pCmd)
 
        KdPrint(("fOsCommandDone(pcmd=%p, result=%d)\n", pCmd, pCmd->Result));
 
-       callout_stop(&ccb->ccb_h.timeout_ch);
+       callout_stop(ccb->ccb_h.timeout_ch);
 
        switch(pCmd->Result) {
        case RETURN_SUCCESS:
index 4cd2e01..d744817 100644 (file)
@@ -1011,7 +1011,7 @@ static void hpt_final_init(void *dummy)
        /* register CAM interface */
        ldm_for_each_vbus(vbus, vbus_ext) {
                struct cam_devq *devq;
-               struct ccb_setasync     ccb;
+               struct ccb_setasync *ccb;
 
                if (bus_dma_tag_create(NULL,/* parent */
                                4,      /* alignment */
@@ -1082,12 +1082,14 @@ static void hpt_final_init(void *dummy)
                }
                hpt_unlock_vbus(vbus_ext);
 
-               xpt_setup_ccb(&ccb.ccb_h, vbus_ext->path, /*priority*/5);
-               ccb.ccb_h.func_code = XPT_SASYNC_CB;
-               ccb.event_enable = AC_LOST_DEVICE;
-               ccb.callback = hpt_async;
-               ccb.callback_arg = vbus_ext;
-               xpt_action((union ccb *)&ccb);
+               ccb = &xpt_alloc_ccb()->csa;
+               xpt_setup_ccb(&ccb->ccb_h, vbus_ext->path, /*priority*/5);
+               ccb->ccb_h.func_code = XPT_SASYNC_CB;
+               ccb->event_enable = AC_LOST_DEVICE;
+               ccb->callback = hpt_async;
+               ccb->callback_arg = vbus_ext;
+               xpt_action((union ccb *)ccb);
+               xpt_free_ccb(&ccb->ccb_h);
 
                for (hba = vbus_ext->hba_list; hba; hba = hba->next) {
                        int rid = 0;
@@ -1306,7 +1308,7 @@ invalid:
 static void    hpt_rescan_callback(struct cam_periph *periph, union ccb *ccb)
 {
        xpt_free_path(ccb->ccb_h.path);
-       xpt_free_ccb(ccb);
+       xpt_free_ccb(&ccb->ccb_h);
 }
 
 static int     hpt_rescan_bus(void)
@@ -1321,7 +1323,7 @@ static int        hpt_rescan_bus(void)
                if (xpt_create_path(&ccb->ccb_h.path, xpt_periph,
                    cam_sim_path(vbus_ext->sim),
                    CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
-                       xpt_free_ccb(ccb);
+                       xpt_free_ccb(&ccb->ccb_h);
                        return(EIO);
                }
 
index a787918..60cf20b 100644 (file)
@@ -1299,8 +1299,8 @@ gdtexecuteccb(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
 
     ccb->ccb_h.status |= CAM_SIM_QUEUED;
     /* timeout handling */
-    callout_reset(&ccb->ccb_h.timeout_ch, (ccb->ccb_h.timeout * hz) / 1000,
-        iir_timeout, gccb);
+    callout_reset(ccb->ccb_h.timeout_ch, (ccb->ccb_h.timeout * hz) / 1000,
+                 iir_timeout, gccb);
 
     gdt->sc_copy_cmd(gdt, gccb);
     crit_exit();
@@ -1804,7 +1804,7 @@ gdt_sync_event(struct gdt_softc *gdt, int service,
         kprintf("\n");
         return (0);
     } else {
-        callout_stop(&ccb->ccb_h.timeout_ch);
+        callout_stop(ccb->ccb_h.timeout_ch);
         if (gdt->sc_status == GDT_S_BSY) {
             GDT_DPRINTF(GDT_D_DEBUG, ("gdt_sync_event(%p) gccb %p busy\n",
                                       gdt, gccb));
index 8cd6de8..f56286a 100644 (file)
@@ -2012,7 +2012,7 @@ mly_cam_rescan_btl(struct mly_softc *sc, int bus, int target)
     if (xpt_create_path(&ccb->ccb_h.path, xpt_periph,
                        cam_sim_path(sc->mly_cam_sim[bus]), target, 0) != CAM_REQ_CMP) {
        mly_printf(sc, "rescan failed (can't create path)\n");
-       xpt_free_ccb(ccb);
+       xpt_free_ccb(&ccb->ccb_h);
        return;
     }
 
@@ -2027,7 +2027,7 @@ mly_cam_rescan_btl(struct mly_softc *sc, int bus, int target)
 static void
 mly_cam_rescan_callback(struct cam_periph *periph, union ccb *ccb)
 {
-    xpt_free_ccb(ccb);
+    xpt_free_ccb(&ccb->ccb_h);
 }
 
 /********************************************************************************
index 190e4ad..0d6a57e 100644 (file)
@@ -263,7 +263,7 @@ mprsas_free_tm(struct mpr_softc *sc, struct mpr_command *tm)
                    target_id);
                xpt_release_devq(tm->cm_ccb->ccb_h.path, 1, TRUE);
                xpt_free_path(tm->cm_ccb->ccb_h.path);
-               xpt_free_ccb(tm->cm_ccb);
+               xpt_free_ccb(&tm->cm_ccb->ccb_h);
        }
 
        mpr_free_high_priority_command(sc, tm);
@@ -277,7 +277,7 @@ mprsas_rescan_callback(struct cam_periph *periph, union ccb *ccb)
                        ccb->ccb_h.status);
 
        xpt_free_path(ccb->ccb_h.path);
-       xpt_free_ccb(ccb);
+       xpt_free_ccb(&ccb->ccb_h);
 }
 
 void
@@ -307,7 +307,7 @@ mprsas_rescan_target(struct mpr_softc *sc, struct mprsas_target *targ)
        if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, pathid, targetid,
            CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                mpr_dprint(sc, MPR_ERROR, "unable to create path for rescan\n");
-               xpt_free_ccb(ccb);
+               xpt_free_ccb(&ccb->ccb_h);
                return;
        }
 
@@ -3460,7 +3460,7 @@ mprsas_async(void *callback_arg, uint32_t code, struct cam_path *path,
                struct mprsas_target *target;
                struct mprsas_softc *sassc;
                struct scsi_read_capacity_data_long rcap_buf;
-               struct ccb_dev_advinfo cdai;
+               struct ccb_dev_advinfo *cdai;
                struct mprsas_lun *lun;
                lun_id_t lunid;
                int found_lun;
@@ -3521,21 +3521,24 @@ mprsas_async(void *callback_arg, uint32_t code, struct cam_path *path,
                }
 
                bzero(&rcap_buf, sizeof(rcap_buf));
-               xpt_setup_ccb(&cdai.ccb_h, path, CAM_PRIORITY_NORMAL);
-               cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
-               cdai.ccb_h.flags = CAM_DIR_IN;
-               cdai.buftype = CDAI_TYPE_RCAPLONG;
+               cdai = xpt_alloc_ccb();
+               xpt_setup_ccb(&cdai->ccb_h, path, CAM_PRIORITY_NORMAL);
+               cdai->ccb_h.func_code = XPT_DEV_ADVINFO;
+               cdai->ccb_h.flags = CAM_DIR_IN;
+               cdai->buftype = CDAI_TYPE_RCAPLONG;
 #if 0 /* (__FreeBSD_version >= 1100061) || \
     ((__FreeBSD_version >= 1001510) && (__FreeBSD_version < 1100000)) */
-               cdai.flags = CDAI_FLAG_NONE;
+               cdai->flags = CDAI_FLAG_NONE;
 #else
-               cdai.flags = 0;
+               cdai->flags = 0;
 #endif
-               cdai.bufsiz = sizeof(rcap_buf);
-               cdai.buf = (uint8_t *)&rcap_buf;
-               xpt_action((union ccb *)&cdai);
-               if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
-                       cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
+               cdai->bufsiz = sizeof(rcap_buf);
+               cdai->buf = (uint8_t *)&rcap_buf;
+               xpt_action((union ccb *)cdai);
+               if ((cdai->ccb_h.status & CAM_DEV_QFRZN) != 0)
+                       cam_release_devq(cdai->ccb_h.path, 0, 0, 0, FALSE);
+
+               xpt_free_ccb(&cdai->ccb_h);
 
                if ((mprsas_get_ccbstatus((union ccb *)&cdai) == CAM_REQ_CMP)
                    && (rcap_buf.prot & SRC16_PROT_EN)) {
@@ -3641,7 +3644,7 @@ mprsas_check_eedp(struct mpr_softc *sc, struct cam_path *path,
            CAM_REQ_CMP) {
                mpr_dprint(sc, MPR_ERROR, "Unable to create path for EEDP "
                    "support.\n");
-               xpt_free_ccb(ccb);
+               xpt_free_ccb(&ccb->ccb_h);
                return;
        }
 
@@ -3662,7 +3665,7 @@ mprsas_check_eedp(struct mpr_softc *sc, struct cam_path *path,
                        mpr_dprint(sc, MPR_ERROR, "Unable to alloc LUN for "
                            "EEDP support.\n");
                        xpt_free_path(local_path);
-                       xpt_free_ccb(ccb);
+                       xpt_free_ccb(&ccb->ccb_h);
                        return;
                }
                lun->lun_id = lunid;
@@ -3684,7 +3687,7 @@ mprsas_check_eedp(struct mpr_softc *sc, struct cam_path *path,
                mpr_dprint(sc, MPR_ERROR, "Unable to alloc read capacity "
                    "buffer for EEDP support.\n");
                xpt_free_path(ccb->ccb_h.path);
-               xpt_free_ccb(ccb);
+               xpt_free_ccb(&ccb->ccb_h);
                return;
        }
        xpt_setup_ccb(&ccb->ccb_h, local_path, CAM_PRIORITY_NORMAL);
@@ -3776,7 +3779,7 @@ mprsas_read_cap_done(struct cam_periph *periph, union ccb *done_ccb)
        // Finished with this CCB and path.
        kfree(rcap_buf, M_MPR);
        xpt_free_path(done_ccb->ccb_h.path);
-       xpt_free_ccb(done_ccb);
+       xpt_free_ccb(&done_ccb->ccb_h);
 }
 #endif /* (__FreeBSD_version < 901503) || \
           ((__FreeBSD_version >= 1000000) && (__FreeBSD_version < 1000006)) */
@@ -3800,7 +3803,7 @@ mprsas_prepare_for_tm(struct mpr_softc *sc, struct mpr_command *tm,
                path_id = cam_sim_path(sc->sassc->sim);
                if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, path_id,
                    target->tid, lun_id) != CAM_REQ_CMP) {
-                       xpt_free_ccb(ccb);
+                       xpt_free_ccb(&ccb->ccb_h);
                } else {
                        tm->cm_ccb = ccb;
                        tm->cm_targ = target;
index 2325f9a..3e9fa86 100644 (file)
@@ -1506,7 +1506,7 @@ mprsas_SSU_to_SATA_devices(struct mpr_softc *sc)
                            CAM_REQ_CMP) {
                                mpr_dprint(sc, MPR_ERROR, "Unable to create "
                                    "path to stop unit.\n");
-                               xpt_free_ccb(ccb);
+                               xpt_free_ccb(&ccb->ccb_h);
                                return;
                        }
                        xpt_path_string(ccb->ccb_h.path, path_str,
@@ -1580,7 +1580,7 @@ mprsas_stop_unit_done(struct cam_periph *periph, union ccb *done_ccb)
         * the SCSI Command process.
         */
        xpt_free_path(done_ccb->ccb_h.path);
-       xpt_free_ccb(done_ccb);
+       xpt_free_ccb(&done_ccb->ccb_h);
 }
 
 /**
index 5fa01c9..6e86075 100644 (file)
@@ -292,7 +292,7 @@ mpssas_rescan_target(struct mps_softc *sc, struct mpssas_target *targ)
        if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, pathid,
                            targetid, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                mps_dprint(sc, MPS_FAULT, "unable to create path for rescan\n");
-               xpt_free_ccb(ccb);
+               xpt_free_ccb(&ccb->ccb_h);
                return;
        }
 
@@ -2868,7 +2868,7 @@ mpssas_rescan_done(struct cam_periph *periph, union ccb *done_ccb)
        mps_dprint(sassc->sc, MPS_INFO, "Completing rescan for %s\n", path_str);
 
        xpt_free_path(done_ccb->ccb_h.path);
-       xpt_free_ccb(done_ccb);
+       xpt_free_ccb(&done_ccb->ccb_h);
 
 #if 1 /* __FreeBSD_version < 1000006 */
        /*
@@ -2960,7 +2960,7 @@ mpssas_async(void *callback_arg, uint32_t code, struct cam_path *path,
                struct mpssas_target *target;
                struct mpssas_softc *sassc;
                struct scsi_read_capacity_data_long rcap_buf;
-               struct ccb_dev_advinfo cdai;
+               struct ccb_dev_advinfo *cdai;
                struct mpssas_lun *lun;
                lun_id_t lunid;
                int found_lun;
@@ -3012,20 +3012,21 @@ mpssas_async(void *callback_arg, uint32_t code, struct cam_path *path,
                        SLIST_INSERT_HEAD(&target->luns, lun, lun_link);
                }
 
+               cdai = xpt_alloc_ccb();
                bzero(&rcap_buf, sizeof(rcap_buf));
-               xpt_setup_ccb(&cdai.ccb_h, path, CAM_PRIORITY_NORMAL);
-               cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
-               cdai.ccb_h.flags = CAM_DIR_IN;
-               cdai.buftype = CDAI_TYPE_RCAPLONG;
-               cdai.flags = 0;
-               cdai.bufsiz = sizeof(rcap_buf);
-               cdai.buf = (uint8_t *)&rcap_buf;
-               xpt_action((union ccb *)&cdai);
-               if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
-                       cam_release_devq(cdai.ccb_h.path,
+               xpt_setup_ccb(&cdai->ccb_h, path, CAM_PRIORITY_NORMAL);
+               cdai->ccb_h.func_code = XPT_DEV_ADVINFO;
+               cdai->ccb_h.flags = CAM_DIR_IN;
+               cdai->buftype = CDAI_TYPE_RCAPLONG;
+               cdai->flags = 0;
+               cdai->bufsiz = sizeof(rcap_buf);
+               cdai->buf = (uint8_t *)&rcap_buf;
+               xpt_action((union ccb *)cdai);
+               if ((cdai->ccb_h.status & CAM_DEV_QFRZN) != 0)
+                       cam_release_devq(cdai->ccb_h.path,
                                         0, 0, 0, FALSE);
 
-               if (((cdai.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP)
+               if (((cdai->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP)
                 && (rcap_buf.prot & SRC16_PROT_EN)) {
                        lun->eedp_formatted = TRUE;
                        lun->eedp_block_size = scsi_4btoul(rcap_buf.length);
@@ -3033,6 +3034,7 @@ mpssas_async(void *callback_arg, uint32_t code, struct cam_path *path,
                        lun->eedp_formatted = FALSE;
                        lun->eedp_block_size = 0;
                }
+               xpt_free_ccb(&cdai->ccb_h);
                break;
        }
        default:
@@ -3086,7 +3088,7 @@ mpssas_check_eedp(struct mpssas_softc *sassc)
                                mps_dprint(sc, MPS_FAULT, "Unable to create "
                                    "path for EEDP support\n");
                                kfree(rcap_buf, M_MPT2);
-                               xpt_free_ccb(ccb);
+                               xpt_free_ccb(&ccb->ccb_h);
                                return;
                        }
 
@@ -3158,7 +3160,7 @@ mpssas_check_eedp(struct mpssas_softc *sassc)
                        } else {
                                kfree(rcap_buf, M_MPT2);
                                xpt_free_path(ccb->ccb_h.path);
-                               xpt_free_ccb(ccb);
+                               xpt_free_ccb(&ccb->ccb_h);
                        }
                } while (found_periph);
        }
@@ -3227,7 +3229,7 @@ mpssas_read_cap_done(struct cam_periph *periph, union ccb *done_ccb)
        // Finished with this CCB and path.
        kfree(rcap_buf, M_MPT2);
        xpt_free_path(done_ccb->ccb_h.path);
-       xpt_free_ccb(done_ccb);
+       xpt_free_ccb(&done_ccb->ccb_h);
 }
 #endif /* __FreeBSD_version >= 1000006 */
 
index 456df66..5cf8e80 100644 (file)
@@ -1104,7 +1104,7 @@ static void
 mrsas_rescan_callback(struct cam_periph *periph, union ccb *ccb)
 {
        xpt_free_path(ccb->ccb_h.path);
-       xpt_free_ccb(ccb);
+       xpt_free_ccb(&ccb->ccb_h);
 }
 
 /*
@@ -1127,23 +1127,23 @@ int mrsas_bus_scan(struct mrsas_softc *sc)
     }
 
     if ((ccb_1 = xpt_alloc_ccb()) == NULL) {
-       xpt_free_ccb(ccb_0);
+       xpt_free_ccb(&ccb_0->ccb_h);
         lockmgr(&sc->sim_lock, LK_RELEASE);
         return(ENOMEM);
     } 
 
     if (xpt_create_path(&ccb_0->ccb_h.path, xpt_periph, cam_sim_path(sc->sim_0),
             CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP){
-        xpt_free_ccb(ccb_0);
-        xpt_free_ccb(ccb_1);
+        xpt_free_ccb(&ccb_0->ccb_h);
+        xpt_free_ccb(&ccb_1->ccb_h);
         lockmgr(&sc->sim_lock, LK_RELEASE);
         return(EIO);
     }
 
     if (xpt_create_path(&ccb_1->ccb_h.path, xpt_periph, cam_sim_path(sc->sim_1),
             CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP){
-        xpt_free_ccb(ccb_0);
-        xpt_free_ccb(ccb_1);
+        xpt_free_ccb(&ccb_0->ccb_h);
+        xpt_free_ccb(&ccb_1->ccb_h);
         lockmgr(&sc->sim_lock, LK_RELEASE);
         return(EIO);
     }
@@ -1182,7 +1182,7 @@ int mrsas_bus_scan_sim(struct mrsas_softc *sc, struct cam_sim *sim)
     }
     if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, cam_sim_path(sim),
             CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP){
-        xpt_free_ccb(ccb);
+        xpt_free_ccb(&ccb->ccb_h);
         lockmgr(&sc->sim_lock, LK_RELEASE);
         return(EIO);
     }
index 73cb900..7dbcdbd 100644 (file)
@@ -538,7 +538,7 @@ tw_osli_request_bus_scan(struct twa_softc *sc)
        lockmgr(sc->sim_lock, LK_EXCLUSIVE);
        if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, cam_sim_path(sc->sim),
            CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
-               xpt_free_ccb(ccb);
+               xpt_free_ccb(&ccb->ccb_h);
                lockmgr(sc->sim_lock, LK_RELEASE);
                return(EIO);
        }
index e0a405e..76f90ef 100644 (file)
@@ -40,6 +40,8 @@
 
 #include <bus/cam/cam.h>
 #include <bus/cam/cam_ccb.h>
+#include <bus/cam/cam_xpt.h>
+#include <bus/cam/cam_xpt_periph.h>
 
 static int     tws_msi_enable = 1;
 
@@ -395,7 +397,7 @@ tws_detach(device_t dev)
 
     kfree(sc->reqs, M_TWS);
     kfree(sc->sense_bufs, M_TWS);
-    kfree(sc->scan_ccb, M_TWS);
+    xpt_free_ccb(&sc->scan_ccb->ccb_h);
     kfree(sc->aen_q.q, M_TWS);
     kfree(sc->trace_q.q, M_TWS);
     lockuninit(&sc->q_lock);
@@ -537,7 +539,7 @@ tws_init(struct tws_softc *sc)
                       M_WAITOK | M_ZERO);
     sc->sense_bufs = kmalloc(sizeof(struct tws_sense) * tws_queue_depth, M_TWS,
                       M_WAITOK | M_ZERO);
-    sc->scan_ccb = kmalloc(sizeof(union ccb), M_TWS, M_WAITOK | M_ZERO);
+    sc->scan_ccb = xpt_alloc_ccb();
 
     if ( !tws_ctlr_ready(sc) )
         if( !tws_ctlr_reset(sc) )
index 5f40965..a06b2a7 100644 (file)
@@ -227,10 +227,8 @@ tws_bus_scan(struct tws_softc *sc)
 
     ccb = sc->scan_ccb;
 
-    bzero(ccb, sizeof(union ccb));
     if (xpt_create_path(&path, xpt_periph, cam_sim_path(sc->sim),
                   CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
-        kfree(ccb, M_TEMP);
         /* lockmgr(&sc->sim_lock, LK_RELEASE); */
         return(EIO);
     }
@@ -364,7 +362,7 @@ tws_scsi_complete(struct tws_request *req)
     tws_q_remove_request(sc, req, TWS_BUSY_Q);
     lockmgr(&sc->q_lock, LK_RELEASE);
 
-    callout_stop(&req->ccb_ptr->ccb_h.timeout_ch);
+    callout_stop(req->ccb_ptr->ccb_h.timeout_ch);
     tws_unmap_request(req->sc, req);
 
 
@@ -484,7 +482,7 @@ tws_cmd_complete(struct tws_request *req)
 {
     struct tws_softc *sc = req->sc;
 
-    callout_stop(&req->ccb_ptr->ccb_h.timeout_ch);
+    callout_stop(req->ccb_ptr->ccb_h.timeout_ch);
     tws_unmap_request(sc, req);
 
 }
@@ -595,7 +593,7 @@ tws_scsi_err_complete(struct tws_request *req, struct tws_command_header *hdr)
     xpt_done(ccb);
     lockmgr(&sc->sim_lock, LK_RELEASE);
 
-    callout_stop(&req->ccb_ptr->ccb_h.timeout_ch);
+    callout_stop(req->ccb_ptr->ccb_h.timeout_ch);
     tws_unmap_request(req->sc, req);
     lockmgr(&sc->q_lock, LK_EXCLUSIVE);
     tws_q_remove_request(sc, req, TWS_BUSY_Q);
@@ -626,7 +624,7 @@ tws_drain_busy_queue(struct tws_softc *sc)
     req = tws_q_remove_tail(sc, TWS_BUSY_Q);
     lockmgr(&sc->q_lock, LK_RELEASE);
     while ( req ) {
-       callout_stop(&req->ccb_ptr->ccb_h.timeout_ch);
+       callout_stop(req->ccb_ptr->ccb_h.timeout_ch);
         tws_unmap_request(req->sc, req);
 
         TWS_TRACE_DEBUG(sc, "drained", 0, req->request_id);
@@ -806,8 +804,8 @@ tws_execute_scsi(struct tws_softc *sc, union ccb *ccb)
      * and submit the I/O.
      */
     sc->stats.scsi_ios++;
-    callout_reset(&ccb_h->timeout_ch, (ccb_h->timeout * hz)/1000, tws_timeout,
-       req);
+    callout_reset(ccb_h->timeout_ch, (ccb_h->timeout * hz)/1000,
+                 tws_timeout, req);
     error = tws_map_request(sc, req);
     return(error);
 }
index e50768c..02dca8a 100644 (file)
@@ -717,31 +717,37 @@ vtscsi_cam_async(void *cb_arg, uint32_t code, struct cam_path *path, void *arg)
 static int
 vtscsi_register_async(struct vtscsi_softc *sc)
 {
-       struct ccb_setasync csa;
+       struct ccb_setasync *csa;
+       u_int32_t status;
 
-       xpt_setup_ccb(&csa.ccb_h, sc->vtscsi_path, 5);
-       csa.ccb_h.func_code = XPT_SASYNC_CB;
-       csa.event_enable = AC_LOST_DEVICE | AC_FOUND_DEVICE;
-       csa.callback = vtscsi_cam_async;
-       csa.callback_arg = sc->vtscsi_sim;
+       csa = &xpt_alloc_ccb()->csa;
 
-       xpt_action((union ccb *) &csa);
+       xpt_setup_ccb(&csa->ccb_h, sc->vtscsi_path, 5);
+       csa->ccb_h.func_code = XPT_SASYNC_CB;
+       csa->event_enable = AC_LOST_DEVICE | AC_FOUND_DEVICE;
+       csa->callback = vtscsi_cam_async;
+       csa->callback_arg = sc->vtscsi_sim;
 
-       return (csa.ccb_h.status);
+       xpt_action((union ccb *)csa);
+       status = csa->ccb_h.status;
+       xpt_free_ccb(&csa->ccb_h);
+
+       return status;
 }
 
 static void
 vtscsi_deregister_async(struct vtscsi_softc *sc)
 {
-       struct ccb_setasync csa;
-
-       xpt_setup_ccb(&csa.ccb_h, sc->vtscsi_path, 5);
-       csa.ccb_h.func_code = XPT_SASYNC_CB;
-       csa.event_enable = 0;
-       csa.callback = vtscsi_cam_async;
-       csa.callback_arg = sc->vtscsi_sim;
+       struct ccb_setasync *csa;
 
-       xpt_action((union ccb *) &csa);
+       csa = &xpt_alloc_ccb()->csa;
+       xpt_setup_ccb(&csa->ccb_h, sc->vtscsi_path, 5);
+       csa->ccb_h.func_code = XPT_SASYNC_CB;
+       csa->event_enable = 0;
+       csa->callback = vtscsi_cam_async;
+       csa->callback_arg = sc->vtscsi_sim;
+       xpt_action((union ccb *)csa);
+       xpt_free_ccb(&csa->ccb_h);
 }
 
 static void
@@ -1759,7 +1765,7 @@ static void
 vtscsi_cam_rescan_callback(struct cam_periph *periph, union ccb *ccb)
 {
        xpt_free_path(ccb->ccb_h.path);
-       xpt_free_ccb(ccb);
+       xpt_free_ccb(&ccb->ccb_h);
 }
 
 static void
@@ -1778,7 +1784,7 @@ vtscsi_execute_rescan(struct vtscsi_softc *sc, target_id_t target_id,
        status = xpt_create_path(&ccb->ccb_h.path, NULL,
            cam_sim_path(sc->vtscsi_sim), target_id, lun_id);
        if (status != CAM_REQ_CMP) {
-               xpt_free_ccb(ccb);
+               xpt_free_ccb(&ccb->ccb_h);
                return;
        }
 
@@ -1805,7 +1811,7 @@ vtscsi_execute_rescan_bus(struct vtscsi_softc *sc)
            cam_sim_path(sc->vtscsi_sim),
            CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
        if (status != CAM_REQ_CMP) {
-               xpt_free_ccb(ccb);
+               xpt_free_ccb(&ccb->ccb_h);
                return;
        }