From b8b6b5d37acc515d0ab51b54af71c9fffbfb0777 Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Thu, 14 Apr 2011 21:25:32 +0000 Subject: [PATCH] Make CAM report devices with ATA/SATA transport to devstat(9) as IDE. --- sys/cam/ata/ata_da.c | 6 ++++++ sys/cam/cam_ccb.h | 8 ++++++++ sys/cam/scsi/scsi_cd.c | 7 ++++--- sys/cam/scsi/scsi_ch.c | 9 ++++++++- sys/cam/scsi/scsi_da.c | 6 ++++++ sys/cam/scsi/scsi_pass.c | 15 +++++++++++++-- sys/cam/scsi/scsi_pt.c | 11 +++++++++-- sys/cam/scsi/scsi_sa.c | 10 ++++++++-- sys/cam/scsi/scsi_sg.c | 8 +++++++- 9 files changed, 69 insertions(+), 11 deletions(-) diff --git a/sys/cam/ata/ata_da.c b/sys/cam/ata/ata_da.c index 8f5d53e73121..33bd426d5de1 100644 --- a/sys/cam/ata/ata_da.c +++ b/sys/cam/ata/ata_da.c @@ -792,6 +792,12 @@ adaregister(struct cam_periph *periph, void *arg) TUNABLE_INT_FETCH(announce_buf, &softc->write_cache); adagetparams(periph, cgd); softc->disk = disk_alloc(); + softc->disk->d_devstat = devstat_new_entry(periph->periph_name, + periph->unit_number, softc->params.secsize, + DEVSTAT_ALL_SUPPORTED, + DEVSTAT_TYPE_DIRECT | + XPORT_DEVSTAT_TYPE(cpi.transport), + DEVSTAT_PRIORITY_DISK); softc->disk->d_open = adaopen; softc->disk->d_close = adaclose; softc->disk->d_strategy = adastrategy; diff --git a/sys/cam/cam_ccb.h b/sys/cam/cam_ccb.h index bee07e8674dd..981a5ed6ada5 100644 --- a/sys/cam/cam_ccb.h +++ b/sys/cam/cam_ccb.h @@ -258,6 +258,14 @@ typedef enum { XPORT_ISCSI, /* iSCSI */ } cam_xport; +#define XPORT_IS_ATA(t) ((t) == XPORT_ATA || (t) == XPORT_SATA) +#define XPORT_IS_SCSI(t) ((t) != XPORT_UNKNOWN && \ + (t) != XPORT_UNSPECIFIED && \ + !XPORT_IS_ATA(t)) +#define XPORT_DEVSTAT_TYPE(t) (XPORT_IS_ATA(t) ? DEVSTAT_TYPE_IF_IDE : \ + XPORT_IS_SCSI(t) ? DEVSTAT_TYPE_IF_SCSI : \ + DEVSTAT_TYPE_IF_OTHER) + #define PROTO_VERSION_UNKNOWN (UINT_MAX - 1) #define PROTO_VERSION_UNSPECIFIED UINT_MAX #define XPORT_VERSION_UNKNOWN (UINT_MAX - 1) diff --git a/sys/cam/scsi/scsi_cd.c b/sys/cam/scsi/scsi_cd.c index 4c49e2d3c913..6dc836f3597c 100644 --- a/sys/cam/scsi/scsi_cd.c +++ b/sys/cam/scsi/scsi_cd.c @@ -714,10 +714,11 @@ cdregister(struct cam_periph *periph, void *arg) */ cam_periph_unlock(periph); softc->disk = disk_alloc(); - softc->disk->d_devstat = devstat_new_entry("cd", + softc->disk->d_devstat = devstat_new_entry("cd", periph->unit_number, 0, - DEVSTAT_BS_UNAVAILABLE, - DEVSTAT_TYPE_CDROM | DEVSTAT_TYPE_IF_SCSI, + DEVSTAT_BS_UNAVAILABLE, + DEVSTAT_TYPE_CDROM | + XPORT_DEVSTAT_TYPE(cpi.transport), DEVSTAT_PRIORITY_CD); softc->disk->d_open = cdopen; softc->disk->d_close = cdclose; diff --git a/sys/cam/scsi/scsi_ch.c b/sys/cam/scsi/scsi_ch.c index 107f22b2ed9f..4d33cd9d32b8 100644 --- a/sys/cam/scsi/scsi_ch.c +++ b/sys/cam/scsi/scsi_ch.c @@ -322,6 +322,7 @@ chregister(struct cam_periph *periph, void *arg) { struct ch_softc *softc; struct ccb_getdev *cgd; + struct ccb_pathinq cpi; cgd = (struct ccb_getdev *)arg; if (periph == NULL) { @@ -347,6 +348,11 @@ chregister(struct cam_periph *periph, void *arg) periph->softc = softc; softc->quirks = CH_Q_NONE; + bzero(&cpi, sizeof(cpi)); + xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL); + cpi.ccb_h.func_code = XPT_PATH_INQ; + xpt_action((union ccb *)&cpi); + /* * Changers don't have a blocksize, and obviously don't support * tagged queueing. @@ -355,7 +361,8 @@ chregister(struct cam_periph *periph, void *arg) softc->device_stats = devstat_new_entry("ch", periph->unit_number, 0, DEVSTAT_NO_BLOCKSIZE | DEVSTAT_NO_ORDERED_TAGS, - SID_TYPE(&cgd->inq_data)| DEVSTAT_TYPE_IF_SCSI, + SID_TYPE(&cgd->inq_data) | + XPORT_DEVSTAT_TYPE(cpi.transport), DEVSTAT_PRIORITY_OTHER); /* Register the device */ diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c index 77901775918a..61c793463587 100644 --- a/sys/cam/scsi/scsi_da.c +++ b/sys/cam/scsi/scsi_da.c @@ -1292,6 +1292,12 @@ daregister(struct cam_periph *periph, void *arg) mtx_unlock(periph->sim->mtx); softc->disk = disk_alloc(); + softc->disk->d_devstat = devstat_new_entry(periph->periph_name, + periph->unit_number, 0, + DEVSTAT_BS_UNAVAILABLE, + SID_TYPE(&cgd->inq_data) | + XPORT_DEVSTAT_TYPE(cpi.transport), + DEVSTAT_PRIORITY_DISK); softc->disk->d_open = daopen; softc->disk->d_close = daclose; softc->disk->d_strategy = dastrategy; diff --git a/sys/cam/scsi/scsi_pass.c b/sys/cam/scsi/scsi_pass.c index 294113697d89..e7ecb35d0fd8 100644 --- a/sys/cam/scsi/scsi_pass.c +++ b/sys/cam/scsi/scsi_pass.c @@ -230,6 +230,7 @@ passregister(struct cam_periph *periph, void *arg) { struct pass_softc *softc; struct ccb_getdev *cgd; + struct ccb_pathinq cpi; int no_tags; cgd = (struct ccb_getdev *)arg; @@ -254,10 +255,20 @@ passregister(struct cam_periph *periph, void *arg) bzero(softc, sizeof(*softc)); softc->state = PASS_STATE_NORMAL; - softc->pd_type = SID_TYPE(&cgd->inq_data); + if (cgd->protocol == PROTO_SCSI || cgd->protocol == PROTO_ATAPI) + softc->pd_type = SID_TYPE(&cgd->inq_data); + else if (cgd->protocol == PROTO_SATAPM) + softc->pd_type = T_ENCLOSURE; + else + softc->pd_type = T_DIRECT; periph->softc = softc; + bzero(&cpi, sizeof(cpi)); + xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL); + cpi.ccb_h.func_code = XPT_PATH_INQ; + xpt_action((union ccb *)&cpi); + /* * We pass in 0 for a blocksize, since we don't * know what the blocksize of this device is, if @@ -270,7 +281,7 @@ passregister(struct cam_periph *periph, void *arg) DEVSTAT_NO_BLOCKSIZE | (no_tags ? DEVSTAT_NO_ORDERED_TAGS : 0), softc->pd_type | - DEVSTAT_TYPE_IF_SCSI | + XPORT_DEVSTAT_TYPE(cpi.transport) | DEVSTAT_TYPE_PASS, DEVSTAT_PRIORITY_PASS); diff --git a/sys/cam/scsi/scsi_pt.c b/sys/cam/scsi/scsi_pt.c index 34217509ac64..1abb45ed325e 100644 --- a/sys/cam/scsi/scsi_pt.c +++ b/sys/cam/scsi/scsi_pt.c @@ -252,6 +252,7 @@ ptctor(struct cam_periph *periph, void *arg) { struct pt_softc *softc; struct ccb_getdev *cgd; + struct ccb_pathinq cpi; cgd = (struct ccb_getdev *)arg; if (periph == NULL) { @@ -280,12 +281,18 @@ ptctor(struct cam_periph *periph, void *arg) softc->io_timeout = SCSI_PT_DEFAULT_TIMEOUT * 1000; periph->softc = softc; - + + bzero(&cpi, sizeof(cpi)); + xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL); + cpi.ccb_h.func_code = XPT_PATH_INQ; + xpt_action((union ccb *)&cpi); + cam_periph_unlock(periph); softc->device_stats = devstat_new_entry("pt", periph->unit_number, 0, DEVSTAT_NO_BLOCKSIZE, - SID_TYPE(&cgd->inq_data) | DEVSTAT_TYPE_IF_SCSI, + SID_TYPE(&cgd->inq_data) | + XPORT_DEVSTAT_TYPE(cpi.transport), DEVSTAT_PRIORITY_OTHER); softc->dev = make_dev(&pt_cdevsw, periph->unit_number, UID_ROOT, diff --git a/sys/cam/scsi/scsi_sa.c b/sys/cam/scsi/scsi_sa.c index 331f9a2b05d8..0d3ef1a9ee08 100644 --- a/sys/cam/scsi/scsi_sa.c +++ b/sys/cam/scsi/scsi_sa.c @@ -1431,6 +1431,7 @@ saregister(struct cam_periph *periph, void *arg) { struct sa_softc *softc; struct ccb_getdev *cgd; + struct ccb_pathinq cpi; caddr_t match; int i; @@ -1479,15 +1480,20 @@ saregister(struct cam_periph *periph, void *arg) } else softc->quirks = SA_QUIRK_NONE; + bzero(&cpi, sizeof(cpi)); + xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL); + cpi.ccb_h.func_code = XPT_PATH_INQ; + xpt_action((union ccb *)&cpi); + /* - * The SA driver supports a blocksize, but we don't know the + * The SA driver supports a blocksize, but we don't know the * blocksize until we media is inserted. So, set a flag to * indicate that the blocksize is unavailable right now. */ cam_periph_unlock(periph); softc->device_stats = devstat_new_entry("sa", periph->unit_number, 0, DEVSTAT_BS_UNAVAILABLE, SID_TYPE(&cgd->inq_data) | - DEVSTAT_TYPE_IF_SCSI, DEVSTAT_PRIORITY_TAPE); + XPORT_DEVSTAT_TYPE(cpi.transport), DEVSTAT_PRIORITY_TAPE); softc->devs.ctl_dev = make_dev(&sa_cdevsw, SAMINOR(SA_CTLDEV, 0, SA_ATYPE_R), UID_ROOT, GID_OPERATOR, diff --git a/sys/cam/scsi/scsi_sg.c b/sys/cam/scsi/scsi_sg.c index 09d30a6aace4..2a989e72bd96 100644 --- a/sys/cam/scsi/scsi_sg.c +++ b/sys/cam/scsi/scsi_sg.c @@ -258,6 +258,7 @@ sgregister(struct cam_periph *periph, void *arg) { struct sg_softc *softc; struct ccb_getdev *cgd; + struct ccb_pathinq cpi; int no_tags; cgd = (struct ccb_getdev *)arg; @@ -284,6 +285,11 @@ sgregister(struct cam_periph *periph, void *arg) TAILQ_INIT(&softc->rdwr_done); periph->softc = softc; + bzero(&cpi, sizeof(cpi)); + xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL); + cpi.ccb_h.func_code = XPT_PATH_INQ; + xpt_action((union ccb *)&cpi); + /* * We pass in 0 for all blocksize, since we don't know what the * blocksize of the device is, if it even has a blocksize. @@ -295,7 +301,7 @@ sgregister(struct cam_periph *periph, void *arg) DEVSTAT_NO_BLOCKSIZE | (no_tags ? DEVSTAT_NO_ORDERED_TAGS : 0), softc->pd_type | - DEVSTAT_TYPE_IF_SCSI | + XPORT_DEVSTAT_TYPE(cpi.transport) | DEVSTAT_TYPE_PASS, DEVSTAT_PRIORITY_PASS);