aboutsummaryrefslogtreecommitdiff
path: root/sys/cam/scsi/scsi_xpt.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/cam/scsi/scsi_xpt.c')
-rw-r--r--sys/cam/scsi/scsi_xpt.c56
1 files changed, 23 insertions, 33 deletions
diff --git a/sys/cam/scsi/scsi_xpt.c b/sys/cam/scsi/scsi_xpt.c
index 439dd2050a95..bef35243af98 100644
--- a/sys/cam/scsi/scsi_xpt.c
+++ b/sys/cam/scsi/scsi_xpt.c
@@ -1915,6 +1915,15 @@ typedef struct {
int lunindex[0];
} scsi_scan_bus_info;
+static void
+free_scan_info(scsi_scan_bus_info *scan_info)
+{
+ KASSERT(scan_info->cpi != NULL,
+ ("scan_info (%p) missing its ccb_pathinq CCB\n", scan_info));
+ xpt_free_ccb((union ccb *)scan_info->cpi);
+ free(scan_info, M_CAMXPT);
+}
+
/*
* To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
* As the scan progresses, scsi_scan_bus is used as the
@@ -1945,10 +1954,7 @@ scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
xpt_done(request_ccb);
return;
}
- xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
- request_ccb->ccb_h.pinfo.priority);
- work_ccb->ccb_h.func_code = XPT_PATH_INQ;
- xpt_action(work_ccb);
+ xpt_path_inq(&work_ccb->cpi, request_ccb->ccb_h.path);
if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
request_ccb->ccb_h.status = work_ccb->ccb_h.status;
xpt_free_ccb(work_ccb);
@@ -2037,16 +2043,14 @@ scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
printf(
"scsi_scan_bus: xpt_create_path failed with status %#x, bus scan halted\n",
status);
- free(scan_info, M_CAMXPT);
+ free_scan_info(scan_info);
request_ccb->ccb_h.status = status;
- xpt_free_ccb(work_ccb);
xpt_done(request_ccb);
break;
}
work_ccb = xpt_alloc_ccb_nowait();
if (work_ccb == NULL) {
- xpt_free_ccb((union ccb *)scan_info->cpi);
- free(scan_info, M_CAMXPT);
+ free_scan_info(scan_info);
xpt_free_path(path);
request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
xpt_done(request_ccb);
@@ -2179,16 +2183,16 @@ scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
* Check to see if we scan any further luns.
*/
if (next_target) {
- int done;
+ bool done;
/*
* Free the current request path- we're done with it.
*/
xpt_free_path(oldpath);
hop_again:
- done = 0;
+ done = false;
if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
- done = 1;
+ done = true;
} else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
scan_info->counter++;
if (scan_info->counter ==
@@ -2197,23 +2201,22 @@ scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
}
if (scan_info->counter >=
scan_info->cpi->max_target+1) {
- done = 1;
+ done = true;
}
} else {
scan_info->counter--;
if (scan_info->counter == 0) {
- done = 1;
+ done = true;
}
}
if (done) {
mtx_unlock(mtx);
xpt_free_ccb(request_ccb);
- xpt_free_ccb((union ccb *)scan_info->cpi);
request_ccb = scan_info->request_ccb;
CAM_DEBUG(request_ccb->ccb_h.path,
CAM_DEBUG_TRACE,
("SCAN done for %p\n", scan_info));
- free(scan_info, M_CAMXPT);
+ free_scan_info(scan_info);
request_ccb->ccb_h.status = CAM_REQ_CMP;
xpt_done(request_ccb);
break;
@@ -2233,9 +2236,8 @@ scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
"scsi_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);
request_ccb = scan_info->request_ccb;
- free(scan_info, M_CAMXPT);
+ free_scan_info(scan_info);
request_ccb->ccb_h.status = status;
xpt_done(request_ccb);
break;
@@ -2294,10 +2296,7 @@ scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
- memset(&cpi, 0, sizeof(cpi));
- xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
- cpi.ccb_h.func_code = XPT_PATH_INQ;
- xpt_action((union ccb *)&cpi);
+ xpt_path_inq(&cpi, path);
if (cpi.ccb_h.status != CAM_REQ_CMP) {
if (request_ccb != NULL) {
@@ -2421,10 +2420,7 @@ scsi_devise_transport(struct cam_path *path)
struct scsi_inquiry_data *inq_buf;
/* Get transport information from the SIM */
- memset(&cpi, 0, sizeof(cpi));
- xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
- cpi.ccb_h.func_code = XPT_PATH_INQ;
- xpt_action((union ccb *)&cpi);
+ xpt_path_inq(&cpi, path);
inq_buf = NULL;
if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
@@ -2732,10 +2728,7 @@ scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path
inq_data = &device->inq_data;
scsi = &cts->proto_specific.scsi;
- memset(&cpi, 0, sizeof(cpi));
- xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
- cpi.ccb_h.func_code = XPT_PATH_INQ;
- xpt_action((union ccb *)&cpi);
+ xpt_path_inq(&cpi, path);
/* SCSI specific sanity checking */
if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
@@ -3046,10 +3039,7 @@ _scsi_announce_periph(struct cam_periph *periph, u_int *speed, u_int *freq, stru
return;
/* Ask the SIM for its base transfer speed */
- memset(&cpi, 0, sizeof(cpi));
- xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
- cpi.ccb_h.func_code = XPT_PATH_INQ;
- xpt_action((union ccb *)&cpi);
+ xpt_path_inq(&cpi, path);
/* Report connection speed */
*speed = cpi.base_transfer_speed;