Deleted Added
full compact
cam_xpt.c (45963) cam_xpt.c (46581)
1/*
2 * Implementation of the Common Access Method Transport (XPT) layer.
3 *
4 * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs.
5 * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 12 unchanged lines hidden (view full) ---

21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
1/*
2 * Implementation of the Common Access Method Transport (XPT) layer.
3 *
4 * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs.
5 * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 12 unchanged lines hidden (view full) ---

21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $Id: cam_xpt.c,v 1.53 1999/04/21 07:26:24 peter Exp $
29 * $Id: cam_xpt.c,v 1.54 1999/04/23 23:25:48 gibbs Exp $
30 */
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/types.h>
34#include <sys/malloc.h>
35#include <sys/device.h>
36#include <sys/kernel.h>
37#include <sys/conf.h>

--- 172 unchanged lines hidden (view full) ---

210 struct cam_ed *device;
211};
212
213struct xpt_quirk_entry {
214 struct scsi_inquiry_pattern inq_pat;
215 u_int8_t quirks;
216#define CAM_QUIRK_NOLUNS 0x01
217#define CAM_QUIRK_NOSERIAL 0x02
30 */
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/types.h>
34#include <sys/malloc.h>
35#include <sys/device.h>
36#include <sys/kernel.h>
37#include <sys/conf.h>

--- 172 unchanged lines hidden (view full) ---

210 struct cam_ed *device;
211};
212
213struct xpt_quirk_entry {
214 struct scsi_inquiry_pattern inq_pat;
215 u_int8_t quirks;
216#define CAM_QUIRK_NOLUNS 0x01
217#define CAM_QUIRK_NOSERIAL 0x02
218 u_int8_t mintags;
219 u_int8_t maxtags;
218 u_int mintags;
219 u_int maxtags;
220};
221
222typedef enum {
223 XPT_FLAG_OPEN = 0x01
224} xpt_flags;
225
226struct xpt_softc {
227 xpt_flags flags;

--- 709 unchanged lines hidden (view full) ---

937 case XPT_RESET_BUS:
938 if ((inccb->ccb_h.target_id != CAM_TARGET_WILDCARD)
939 || (inccb->ccb_h.target_lun != CAM_LUN_WILDCARD)) {
940 error = EINVAL;
941 break;
942 }
943 /* FALLTHROUGH */
944 case XPT_SCAN_LUN:
220};
221
222typedef enum {
223 XPT_FLAG_OPEN = 0x01
224} xpt_flags;
225
226struct xpt_softc {
227 xpt_flags flags;

--- 709 unchanged lines hidden (view full) ---

937 case XPT_RESET_BUS:
938 if ((inccb->ccb_h.target_id != CAM_TARGET_WILDCARD)
939 || (inccb->ccb_h.target_lun != CAM_LUN_WILDCARD)) {
940 error = EINVAL;
941 break;
942 }
943 /* FALLTHROUGH */
944 case XPT_SCAN_LUN:
945 case XPT_RESET_DEV:
945 case XPT_ENG_INQ: /* XXX not implemented yet */
946 case XPT_ENG_EXEC:
947
948 ccb = xpt_alloc_ccb();
949
950 /*
951 * Create a path using the bus, target, and lun the
952 * user passed in.

--- 491 unchanged lines hidden (view full) ---

1444 u_int speed;
1445 u_int freq;
1446
1447 if ((cts.valid & CCB_TRANS_SYNC_OFFSET_VALID) != 0
1448 && cts.sync_offset != 0) {
1449 freq = scsi_calc_syncsrate(cts.sync_period);
1450 speed = freq;
1451 } else {
946 case XPT_ENG_INQ: /* XXX not implemented yet */
947 case XPT_ENG_EXEC:
948
949 ccb = xpt_alloc_ccb();
950
951 /*
952 * Create a path using the bus, target, and lun the
953 * user passed in.

--- 491 unchanged lines hidden (view full) ---

1445 u_int speed;
1446 u_int freq;
1447
1448 if ((cts.valid & CCB_TRANS_SYNC_OFFSET_VALID) != 0
1449 && cts.sync_offset != 0) {
1450 freq = scsi_calc_syncsrate(cts.sync_period);
1451 speed = freq;
1452 } else {
1453 struct ccb_pathinq cpi;
1454
1455 /* Ask the SIM for its base transfer speed */
1456 xpt_setup_ccb(&cpi.ccb_h, path, /*priority*/1);
1457 cpi.ccb_h.func_code = XPT_PATH_INQ;
1458 xpt_action((union ccb *)&cpi);
1459
1460 speed = cpi.base_transfer_speed;
1452 freq = 0;
1461 freq = 0;
1453 speed = path->bus->sim->base_transfer_speed;
1454 }
1455 if ((cts.valid & CCB_TRANS_BUS_WIDTH_VALID) != 0)
1456 speed *= (0x01 << cts.bus_width);
1457 mb = speed / 1000;
1458 if (mb > 0)
1459 printf("%s%d: %d.%03dMB/s transfers",
1460 periph->periph_name, periph->unit_number,
1461 mb, speed % 1000);

--- 576 unchanged lines hidden (view full) ---

2038 device->target->bus->path_id;
2039 cdm->matches[j].result.device_result.target_id =
2040 device->target->target_id;
2041 cdm->matches[j].result.device_result.target_lun =
2042 device->lun_id;
2043 bcopy(&device->inq_data,
2044 &cdm->matches[j].result.device_result.inq_data,
2045 sizeof(struct scsi_inquiry_data));
1462 }
1463 if ((cts.valid & CCB_TRANS_BUS_WIDTH_VALID) != 0)
1464 speed *= (0x01 << cts.bus_width);
1465 mb = speed / 1000;
1466 if (mb > 0)
1467 printf("%s%d: %d.%03dMB/s transfers",
1468 periph->periph_name, periph->unit_number,
1469 mb, speed % 1000);

--- 576 unchanged lines hidden (view full) ---

2046 device->target->bus->path_id;
2047 cdm->matches[j].result.device_result.target_id =
2048 device->target->target_id;
2049 cdm->matches[j].result.device_result.target_lun =
2050 device->lun_id;
2051 bcopy(&device->inq_data,
2052 &cdm->matches[j].result.device_result.inq_data,
2053 sizeof(struct scsi_inquiry_data));
2054
2055 /* Let the user know whether this device is unconfigured */
2056 if (device->flags & CAM_DEV_UNCONFIGURED)
2057 cdm->matches[j].result.device_result.flags =
2058 DEV_RESULT_UNCONFIGURED;
2059 else
2060 cdm->matches[j].result.device_result.flags =
2061 DEV_RESULT_NOFLAG;
2046 }
2047
2048 /*
2049 * If the user isn't interested in peripherals, don't descend
2050 * the tree any further.
2051 */
2052 if ((retval & DM_RET_ACTION_MASK) == DM_RET_STOP)
2053 return(1);

--- 2289 unchanged lines hidden (view full) ---

4343void
4344xpt_done(union ccb *done_ccb)
4345{
4346 int s;
4347
4348 s = splcam();
4349
4350 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("xpt_done\n"));
2062 }
2063
2064 /*
2065 * If the user isn't interested in peripherals, don't descend
2066 * the tree any further.
2067 */
2068 if ((retval & DM_RET_ACTION_MASK) == DM_RET_STOP)
2069 return(1);

--- 2289 unchanged lines hidden (view full) ---

4359void
4360xpt_done(union ccb *done_ccb)
4361{
4362 int s;
4363
4364 s = splcam();
4365
4366 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("xpt_done\n"));
4351 switch (done_ccb->ccb_h.func_code) {
4352 case XPT_SCSI_IO:
4353 case XPT_ENG_EXEC:
4354 case XPT_TARGET_IO:
4355 case XPT_ACCEPT_TARGET_IO:
4356 case XPT_CONT_TARGET_IO:
4357 case XPT_IMMED_NOTIFY:
4358 case XPT_SCAN_BUS:
4359 case XPT_SCAN_LUN:
4360 {
4367 if ((done_ccb->ccb_h.func_code & XPT_FC_QUEUED) != 0) {
4361 /*
4362 * Queue up the request for handling by our SWI handler
4363 * any of the "non-immediate" type of ccbs.
4364 */
4365 switch (done_ccb->ccb_h.path->periph->type) {
4366 case CAM_PERIPH_BIO:
4367 TAILQ_INSERT_TAIL(&cam_bioq, &done_ccb->ccb_h,
4368 sim_links.tqe);
4369 done_ccb->ccb_h.pinfo.index = CAM_DONEQ_INDEX;
4370 setsoftcambio();
4371 break;
4372 case CAM_PERIPH_NET:
4373 TAILQ_INSERT_TAIL(&cam_netq, &done_ccb->ccb_h,
4374 sim_links.tqe);
4375 done_ccb->ccb_h.pinfo.index = CAM_DONEQ_INDEX;
4376 setsoftcamnet();
4377 break;
4378 }
4368 /*
4369 * Queue up the request for handling by our SWI handler
4370 * any of the "non-immediate" type of ccbs.
4371 */
4372 switch (done_ccb->ccb_h.path->periph->type) {
4373 case CAM_PERIPH_BIO:
4374 TAILQ_INSERT_TAIL(&cam_bioq, &done_ccb->ccb_h,
4375 sim_links.tqe);
4376 done_ccb->ccb_h.pinfo.index = CAM_DONEQ_INDEX;
4377 setsoftcambio();
4378 break;
4379 case CAM_PERIPH_NET:
4380 TAILQ_INSERT_TAIL(&cam_netq, &done_ccb->ccb_h,
4381 sim_links.tqe);
4382 done_ccb->ccb_h.pinfo.index = CAM_DONEQ_INDEX;
4383 setsoftcamnet();
4384 break;
4385 }
4379 break;
4380 }
4386 }
4381 default:
4382 break;
4383 }
4384 splx(s);
4385}
4386
4387union ccb *
4388xpt_alloc_ccb()
4389{
4390 union ccb *new_ccb;
4391

--- 1120 unchanged lines hidden (view full) ---

5512{
5513 struct cam_sim *sim;
5514 int qfrozen;
5515
5516 sim = cts->ccb_h.path->bus->sim;
5517 if (async_update == FALSE) {
5518 struct scsi_inquiry_data *inq_data;
5519 struct ccb_pathinq cpi;
4387 splx(s);
4388}
4389
4390union ccb *
4391xpt_alloc_ccb()
4392{
4393 union ccb *new_ccb;
4394

--- 1120 unchanged lines hidden (view full) ---

5515{
5516 struct cam_sim *sim;
5517 int qfrozen;
5518
5519 sim = cts->ccb_h.path->bus->sim;
5520 if (async_update == FALSE) {
5521 struct scsi_inquiry_data *inq_data;
5522 struct ccb_pathinq cpi;
5523 struct ccb_trans_settings cur_cts;
5520
5521 if (device == NULL) {
5522 cts->ccb_h.status = CAM_PATH_INVALID;
5523 xpt_done((union ccb *)cts);
5524 return;
5525 }
5526
5527 /*
5528 * Perform sanity checking against what the
5529 * controller and device can do.
5530 */
5531 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, /*priority*/1);
5532 cpi.ccb_h.func_code = XPT_PATH_INQ;
5533 xpt_action((union ccb *)&cpi);
5524
5525 if (device == NULL) {
5526 cts->ccb_h.status = CAM_PATH_INVALID;
5527 xpt_done((union ccb *)cts);
5528 return;
5529 }
5530
5531 /*
5532 * Perform sanity checking against what the
5533 * controller and device can do.
5534 */
5535 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, /*priority*/1);
5536 cpi.ccb_h.func_code = XPT_PATH_INQ;
5537 xpt_action((union ccb *)&cpi);
5534
5538 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, /*priority*/1);
5539 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
5540 cur_cts.flags = CCB_TRANS_CURRENT_SETTINGS;
5541 xpt_action((union ccb *)&cur_cts);
5535 inq_data = &device->inq_data;
5542 inq_data = &device->inq_data;
5543
5544 /* Fill in any gaps in what the user gave us */
5545 if ((cts->valid & CCB_TRANS_SYNC_RATE_VALID) == 0)
5546 cts->sync_period = cur_cts.sync_period;
5547 if ((cts->valid & CCB_TRANS_SYNC_OFFSET_VALID) == 0)
5548 cts->sync_offset = cur_cts.sync_offset;
5549 if ((cts->valid & CCB_TRANS_BUS_WIDTH_VALID) == 0)
5550 cts->bus_width = cur_cts.bus_width;
5551 if ((cts->valid & CCB_TRANS_DISC_VALID) == 0) {
5552 cts->flags &= ~CCB_TRANS_DISC_ENB;
5553 cts->flags |= cur_cts.flags & CCB_TRANS_DISC_ENB;
5554 }
5555 if ((cts->valid & CCB_TRANS_TQ_VALID) == 0) {
5556 cts->flags &= ~CCB_TRANS_TAG_ENB;
5557 cts->flags |= cur_cts.flags & CCB_TRANS_TAG_ENB;
5558 }
5559
5536 if ((inq_data->flags & SID_Sync) == 0
5537 || (cpi.hba_inquiry & PI_SDTR_ABLE) == 0) {
5538 /* Force async */
5539 cts->sync_period = 0;
5540 cts->sync_offset = 0;
5541 }
5542
5543 switch (cts->bus_width) {

--- 362 unchanged lines hidden (view full) ---

5906 cpi->max_target = 0;
5907 cpi->max_lun = 0;
5908 cpi->initiator_id = 0;
5909 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
5910 strncpy(cpi->hba_vid, "", HBA_IDLEN);
5911 strncpy(cpi->dev_name, sim->sim_name, DEV_IDLEN);
5912 cpi->unit_number = sim->unit_number;
5913 cpi->bus_id = sim->bus_id;
5560 if ((inq_data->flags & SID_Sync) == 0
5561 || (cpi.hba_inquiry & PI_SDTR_ABLE) == 0) {
5562 /* Force async */
5563 cts->sync_period = 0;
5564 cts->sync_offset = 0;
5565 }
5566
5567 switch (cts->bus_width) {

--- 362 unchanged lines hidden (view full) ---

5930 cpi->max_target = 0;
5931 cpi->max_lun = 0;
5932 cpi->initiator_id = 0;
5933 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
5934 strncpy(cpi->hba_vid, "", HBA_IDLEN);
5935 strncpy(cpi->dev_name, sim->sim_name, DEV_IDLEN);
5936 cpi->unit_number = sim->unit_number;
5937 cpi->bus_id = sim->bus_id;
5938 cpi->base_transfer_speed = 0;
5914 cpi->ccb_h.status = CAM_REQ_CMP;
5915 xpt_done(work_ccb);
5916 break;
5917 }
5918 default:
5919 work_ccb->ccb_h.status = CAM_REQ_INVALID;
5920 xpt_done(work_ccb);
5921 break;

--- 57 unchanged lines hidden (view full) ---

5979 device = send_ccb->ccb_h.path->device;
5980
5981 STAILQ_REMOVE_HEAD(hphead, xpt_links.stqe);
5982
5983 xpt_release_devq(send_ccb->ccb_h.path->device,
5984 TRUE);
5985 }
5986 }
5939 cpi->ccb_h.status = CAM_REQ_CMP;
5940 xpt_done(work_ccb);
5941 break;
5942 }
5943 default:
5944 work_ccb->ccb_h.status = CAM_REQ_INVALID;
5945 xpt_done(work_ccb);
5946 break;

--- 57 unchanged lines hidden (view full) ---

6004 device = send_ccb->ccb_h.path->device;
6005
6006 STAILQ_REMOVE_HEAD(hphead, xpt_links.stqe);
6007
6008 xpt_release_devq(send_ccb->ccb_h.path->device,
6009 TRUE);
6010 }
6011 }
5987 if ((ccb_h->func_code != XPT_ACCEPT_TARGET_IO)
5988 && (ccb_h->func_code != XPT_IMMED_NOTIFY)
5989 && (ccb_h->func_code != XPT_SCAN_LUN)
5990 && (ccb_h->func_code != XPT_SCAN_BUS)) {
6012 if ((ccb_h->func_code & XPT_FC_USER_CCB) == 0) {
5991 struct cam_ed *dev;
5992
5993 dev = ccb_h->path->device;
5994
5995 s = splcam();
5996 cam_ccbq_ccb_done(&dev->ccbq, (union ccb *)ccb_h);
5997
5998 ccb_h->path->bus->sim->devq->send_active--;

--- 44 unchanged lines hidden ---
6013 struct cam_ed *dev;
6014
6015 dev = ccb_h->path->device;
6016
6017 s = splcam();
6018 cam_ccbq_ccb_done(&dev->ccbq, (union ccb *)ccb_h);
6019
6020 ccb_h->path->bus->sim->devq->send_active--;

--- 44 unchanged lines hidden ---