diff options
Diffstat (limited to 'sys/cam')
101 files changed, 6294 insertions, 4101 deletions
diff --git a/sys/cam/README.quirks b/sys/cam/README.quirks index 707862b6a598..4ebb2dba7b61 100644 --- a/sys/cam/README.quirks +++ b/sys/cam/README.quirks @@ -1,4 +1,3 @@ -/* $FreeBSD$ */ FreeBSD Quirk Guidelines diff --git a/sys/cam/ata/ata_all.c b/sys/cam/ata/ata_all.c index 0e20e4b11544..f9a2b86f0c06 100644 --- a/sys/cam/ata/ata_all.c +++ b/sys/cam/ata/ata_all.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org> * All rights reserved. @@ -26,9 +26,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #ifdef _KERNEL @@ -467,7 +464,7 @@ ata_print_ident_sbuf(struct ata_params *ident_data, struct sbuf *sb) int version; ata_print_ident_short_sbuf(ident_data, sb); - sbuf_printf(sb, " "); + sbuf_putc(sb, ' '); proto = (ident_data->config == ATA_PROTO_CFA) ? "CFA" : (ident_data->config & ATA_PROTO_ATAPI) ? "ATAPI" : "ATA"; @@ -524,11 +521,11 @@ void ata_print_ident_short_sbuf(struct ata_params *ident_data, struct sbuf *sb) { - sbuf_printf(sb, "<"); + sbuf_putc(sb, '<'); cam_strvis_sbuf(sb, ident_data->model, sizeof(ident_data->model), 0); - sbuf_printf(sb, " "); + sbuf_putc(sb, ' '); cam_strvis_sbuf(sb, ident_data->revision, sizeof(ident_data->revision), 0); - sbuf_printf(sb, ">"); + sbuf_putc(sb, '>'); } void @@ -548,11 +545,11 @@ semb_print_ident_sbuf(struct sep_identify_data *ident_data, struct sbuf *sb) semb_print_ident_short_sbuf(ident_data, sb); - sbuf_printf(sb, " SEMB "); + sbuf_cat(sb, " SEMB "); cam_strvis_sbuf(sb, ident_data->interface_id, 6, 0); - sbuf_printf(sb, " "); + sbuf_putc(sb, ' '); cam_strvis_sbuf(sb, ident_data->interface_rev, 4, 0); - sbuf_printf(sb, " device\n"); + sbuf_cat(sb, " device\n"); } void @@ -571,15 +568,15 @@ void semb_print_ident_short_sbuf(struct sep_identify_data *ident_data, struct sbuf *sb) { - sbuf_printf(sb, "<"); + sbuf_putc(sb, '<'); cam_strvis_sbuf(sb, ident_data->vendor_id, 8, 0); - sbuf_printf(sb, " "); + sbuf_putc(sb, ' '); cam_strvis_sbuf(sb, ident_data->product_id, 16, 0); - sbuf_printf(sb, " "); + sbuf_putc(sb, ' '); cam_strvis_sbuf(sb, ident_data->product_rev, 4, 0); - sbuf_printf(sb, " "); + sbuf_putc(sb, ' '); cam_strvis_sbuf(sb, ident_data->firmware_rev, 4, 0); - sbuf_printf(sb, ">"); + sbuf_putc(sb, '>'); } uint32_t @@ -587,8 +584,8 @@ ata_logical_sector_size(struct ata_params *ident_data) { if ((ident_data->pss & ATA_PSS_VALID_MASK) == ATA_PSS_VALID_VALUE && (ident_data->pss & ATA_PSS_LSSABOVE512)) { - return (((u_int32_t)ident_data->lss_1 | - ((u_int32_t)ident_data->lss_2 << 16)) * 2); + return (((uint32_t)ident_data->lss_1 | + ((uint32_t)ident_data->lss_2 << 16)) * 2); } return (512); } @@ -761,9 +758,9 @@ ata_read_log(struct ccb_ataio *ataio, uint32_t retries, void ata_bswap(int8_t *buf, int len) { - u_int16_t *ptr = (u_int16_t*)(buf + len); + uint16_t *ptr = (uint16_t*)(buf + len); - while (--ptr >= (u_int16_t*)buf) + while (--ptr >= (uint16_t*)buf) *ptr = be16toh(*ptr); } @@ -1037,7 +1034,7 @@ ata_static_identify_match(caddr_t identbuffer, caddr_t table_entry) void semb_receive_diagnostic_results(struct ccb_ataio *ataio, - u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*), + uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*), uint8_t tag_action, int pcv, uint8_t page_code, uint8_t *data_ptr, uint16_t length, uint32_t timeout) { @@ -1058,7 +1055,7 @@ semb_receive_diagnostic_results(struct ccb_ataio *ataio, void semb_send_diagnostic(struct ccb_ataio *ataio, - u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), + uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, uint8_t *data_ptr, uint16_t length, uint32_t timeout) { @@ -1078,7 +1075,7 @@ semb_send_diagnostic(struct ccb_ataio *ataio, void semb_read_buffer(struct ccb_ataio *ataio, - u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*), + uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*), uint8_t tag_action, uint8_t page_code, uint8_t *data_ptr, uint16_t length, uint32_t timeout) { @@ -1099,7 +1096,7 @@ semb_read_buffer(struct ccb_ataio *ataio, void semb_write_buffer(struct ccb_ataio *ataio, - u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), + uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, uint8_t *data_ptr, uint16_t length, uint32_t timeout) { diff --git a/sys/cam/ata/ata_all.h b/sys/cam/ata/ata_all.h index ca635253511c..53d303329d77 100644 --- a/sys/cam/ata/ata_all.h +++ b/sys/cam/ata/ata_all.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org> * All rights reserved. @@ -24,8 +24,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef CAM_ATA_ALL_H @@ -42,49 +40,49 @@ union ccb; #define SID_DMA 0x10 /* Abuse inq_flags bit to track enabled DMA. */ struct ata_cmd { - u_int8_t flags; /* ATA command flags */ + uint8_t flags; /* ATA command flags */ #define CAM_ATAIO_48BIT 0x01 /* Command has 48-bit format */ #define CAM_ATAIO_FPDMA 0x02 /* FPDMA command */ #define CAM_ATAIO_CONTROL 0x04 /* Control, not a command */ #define CAM_ATAIO_NEEDRESULT 0x08 /* Request requires result. */ #define CAM_ATAIO_DMA 0x10 /* DMA command */ - u_int8_t command; - u_int8_t features; + uint8_t command; + uint8_t features; - u_int8_t lba_low; - u_int8_t lba_mid; - u_int8_t lba_high; - u_int8_t device; + uint8_t lba_low; + uint8_t lba_mid; + uint8_t lba_high; + uint8_t device; - u_int8_t lba_low_exp; - u_int8_t lba_mid_exp; - u_int8_t lba_high_exp; - u_int8_t features_exp; + uint8_t lba_low_exp; + uint8_t lba_mid_exp; + uint8_t lba_high_exp; + uint8_t features_exp; - u_int8_t sector_count; - u_int8_t sector_count_exp; - u_int8_t control; + uint8_t sector_count; + uint8_t sector_count_exp; + uint8_t control; }; struct ata_res { - u_int8_t flags; /* ATA command flags */ + uint8_t flags; /* ATA command flags */ #define CAM_ATAIO_48BIT 0x01 /* Command has 48-bit format */ - u_int8_t status; - u_int8_t error; + uint8_t status; + uint8_t error; - u_int8_t lba_low; - u_int8_t lba_mid; - u_int8_t lba_high; - u_int8_t device; + uint8_t lba_low; + uint8_t lba_mid; + uint8_t lba_high; + uint8_t device; - u_int8_t lba_low_exp; - u_int8_t lba_mid_exp; - u_int8_t lba_high_exp; + uint8_t lba_low_exp; + uint8_t lba_mid_exp; + uint8_t lba_high_exp; - u_int8_t sector_count; - u_int8_t sector_count_exp; + uint8_t sector_count; + uint8_t sector_count_exp; }; struct sep_identify_data { @@ -160,22 +158,22 @@ void semb_print_ident_short(struct sep_identify_data *ident_data); void semb_print_ident_short_sbuf(struct sep_identify_data *ident_data, struct sbuf *sb); void semb_receive_diagnostic_results(struct ccb_ataio *ataio, - u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*), + uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*), uint8_t tag_action, int pcv, uint8_t page_code, uint8_t *data_ptr, uint16_t allocation_length, uint32_t timeout); void semb_send_diagnostic(struct ccb_ataio *ataio, - u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), + uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, uint8_t *data_ptr, uint16_t param_list_length, uint32_t timeout); void semb_read_buffer(struct ccb_ataio *ataio, - u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*), + uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*), uint8_t tag_action, uint8_t page_code, uint8_t *data_ptr, uint16_t allocation_length, uint32_t timeout); void semb_write_buffer(struct ccb_ataio *ataio, - u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), + uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, uint8_t *data_ptr, uint16_t param_list_length, uint32_t timeout); diff --git a/sys/cam/ata/ata_da.c b/sys/cam/ata/ata_da.c index ee6ea0b18902..6e008cfc8d22 100644 --- a/sys/cam/ata/ata_da.c +++ b/sys/cam/ata/ata_da.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org> * All rights reserved. @@ -26,9 +26,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include "opt_ada.h" #include <sys/param.h> @@ -233,11 +230,11 @@ static const char *ada_delete_method_desc[] = #endif struct disk_params { - u_int8_t heads; - u_int8_t secs_per_track; - u_int32_t cylinders; - u_int32_t secsize; /* Number of bytes/logical sector */ - u_int64_t sectors; /* Total number sectors */ + uint8_t heads; + uint8_t secs_per_track; + uint32_t cylinders; + uint32_t secsize; /* Number of bytes/logical sector */ + uint64_t sectors; /* Total number sectors */ }; #define TRIM_MAX_BLOCKS 8 @@ -732,6 +729,22 @@ static struct ada_quirk_entry ada_quirk_table[] = }, { /* + * Samsung 860 SSDs + * 4k optimised, NCQ TRIM broken (normal TRIM fine) + */ + { T_DIRECT, SIP_MEDIA_FIXED, "*", "Samsung SSD 860*", "*" }, + /*quirks*/ADA_Q_4K | ADA_Q_NCQ_TRIM_BROKEN + }, + { + /* + * Samsung 870 SSDs + * 4k optimised, NCQ TRIM broken (normal TRIM fine) + */ + { T_DIRECT, SIP_MEDIA_FIXED, "*", "Samsung SSD 870*", "*" }, + /*quirks*/ADA_Q_4K | ADA_Q_NCQ_TRIM_BROKEN + }, + { + /* * Samsung SM863 Series SSDs (MZ7KM*) * 4k optimised, NCQ believed to be working */ @@ -817,6 +830,11 @@ static struct ada_quirk_entry ada_quirk_table[] = /*quirks*/ADA_Q_4K | ADA_Q_NCQ_TRIM_BROKEN }, { + /* Seagate IronWolf 110 SATA SSD NCQ Trim is unstable */ + { T_DIRECT, SIP_MEDIA_FIXED, "*", "ZA*NM*", "*" }, + /*quirks*/ADA_Q_4K | ADA_Q_NCQ_TRIM_BROKEN + }, + { /* Default */ { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, @@ -832,7 +850,7 @@ static periph_init_t adainit; static void adadiskgonecb(struct disk *dp); static periph_oninv_t adaoninvalidate; static periph_dtor_t adacleanup; -static void adaasync(void *callback_arg, u_int32_t code, +static void adaasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg); static int adabitsysctl(SYSCTL_HANDLER_ARGS); static int adaflagssysctl(SYSCTL_HANDLER_ARGS); @@ -856,8 +874,8 @@ static void adaprobedone(struct cam_periph *periph, union ccb *ccb); static void adazonedone(struct cam_periph *periph, union ccb *ccb); static void adadone(struct cam_periph *periph, union ccb *done_ccb); -static int adaerror(union ccb *ccb, u_int32_t cam_flags, - u_int32_t sense_flags); +static int adaerror(union ccb *ccb, uint32_t cam_flags, + uint32_t sense_flags); static callout_func_t adasendorderedtag; static void adashutdown(void *arg, int howto); static void adasuspend(void *arg); @@ -1128,7 +1146,7 @@ adadump(void *arg, void *virtual, off_t offset, size_t length) NULL, CAM_DIR_OUT, 0, - (u_int8_t *) virtual, + (uint8_t *) virtual, length, ada_default_timeout*1000); if ((softc->flags & ADA_FLAG_CAN_48BIT) && @@ -1300,7 +1318,7 @@ adasetdeletemethod(struct ada_softc *softc) } static void -adaasync(void *callback_arg, u_int32_t code, +adaasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg) { struct ccb_getdev cgd; @@ -1428,7 +1446,6 @@ adazonemodesysctl(SYSCTL_HANDLER_ARGS) static int adazonesupsysctl(SYSCTL_HANDLER_ARGS) { - char tmpbuf[180]; struct ada_softc *softc; struct sbuf sb; int error, first; @@ -1436,15 +1453,14 @@ adazonesupsysctl(SYSCTL_HANDLER_ARGS) softc = (struct ada_softc *)arg1; - error = 0; first = 1; - sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0); + sbuf_new_for_sysctl(&sb, NULL, 0, req); for (i = 0; i < sizeof(ada_zone_desc_table) / sizeof(ada_zone_desc_table[0]); i++) { if (softc->zone_flags & ada_zone_desc_table[i].value) { if (first == 0) - sbuf_printf(&sb, ", "); + sbuf_cat(&sb, ", "); else first = 0; sbuf_cat(&sb, ada_zone_desc_table[i].desc); @@ -1452,12 +1468,10 @@ adazonesupsysctl(SYSCTL_HANDLER_ARGS) } if (first == 1) - sbuf_printf(&sb, "None"); - - sbuf_finish(&sb); - - error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req); + sbuf_cat(&sb, "None"); + error = sbuf_finish(&sb); + sbuf_delete(&sb); return (error); } @@ -1545,11 +1559,11 @@ adasysctlinit(void *context, int pending) SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "unmapped_io", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, &softc->flags, (u_int)ADA_FLAG_UNMAPPEDIO, adabitsysctl, "I", - "Unmapped I/O support *DEPRECATED* gone in FreeBSD 14"); + "Use unmapped I/O. This sysctl is *DEPRECATED*, gone in FreeBSD 15"); SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "rotating", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, &softc->flags, (u_int)ADA_FLAG_ROTATING, adabitsysctl, "I", - "Rotating media *DEPRECATED* gone in FreeBSD 14"); + "Rotating media. This sysctl is *DEPRECATED*, gone in FreeBSD 15"); #ifdef CAM_TEST_FAILURE /* @@ -1684,7 +1698,7 @@ adaflagssysctl(SYSCTL_HANDLER_ARGS) if (softc->flags != 0) sbuf_printf(&sbuf, "0x%b", (unsigned)softc->flags, ADA_FLAG_STRING); else - sbuf_printf(&sbuf, "0"); + sbuf_putc(&sbuf, '0'); error = sbuf_finish(&sbuf); sbuf_delete(&sbuf); @@ -1845,9 +1859,11 @@ adaregister(struct cam_periph *periph, void *arg) TASK_INIT(&softc->sysctl_task, 0, adasysctlinit, periph); /* - * Register this media as a disk + * Take a reference on the periph while adastart is called to finish + * the probe. The reference will be dropped in adaprobedone at the + * end of probe. */ - (void)cam_periph_hold(periph, PRIBIO); + (void)cam_periph_acquire(periph); cam_periph_unlock(periph); snprintf(announce_buf, ADA_ANNOUNCETMP_SZ, "kern.cam.ada.%d.quirks", periph->unit_number); @@ -1905,19 +1921,6 @@ adaregister(struct cam_periph *periph, void *arg) softc->disk->d_name = "ada"; softc->disk->d_drv1 = periph; softc->disk->d_unit = periph->unit_number; - - /* - * Acquire a reference to the periph before we register with GEOM. - * We'll release this reference once GEOM calls us back (via - * adadiskgonecb()) telling us that our provider has been freed. - */ - if (cam_periph_acquire(periph) != 0) { - xpt_print(periph->path, "%s: lost periph during " - "registration!\n", __func__); - cam_periph_lock(periph); - return (CAM_REQ_CMP_ERR); - } - disk_create(softc->disk, DISK_VERSION); cam_periph_lock(periph); dp = &softc->params; @@ -1960,6 +1963,9 @@ adaregister(struct cam_periph *periph, void *arg) SBT_1S / ADA_ORDEREDTAG_INTERVAL * ada_default_timeout, 0, adasendorderedtag, softc, C_PREL(1)); + /* Released after probe when disk_create() call pass it to GEOM. */ + cam_periph_hold_boot(periph); + if (ADA_RA >= 0 && softc->flags & ADA_FLAG_CAN_RAHEAD) { softc->state = ADA_STATE_RAHEAD; } else if (ADA_WC >= 0 && softc->flags & ADA_FLAG_CAN_WCACHE) { @@ -1977,7 +1983,6 @@ adaregister(struct cam_periph *periph, void *arg) } xpt_schedule(periph, CAM_PRIORITY_DEV); - return(CAM_REQ_CMP); } @@ -2330,7 +2335,7 @@ adastart(struct cam_periph *periph, union ccb *start_ccb) case ADA_STATE_NORMAL: { struct bio *bp; - u_int8_t tag_code; + uint8_t tag_code; bp = cam_iosched_next_bio(softc->cam_iosched); if (bp == NULL) { @@ -2513,7 +2518,16 @@ adastart(struct cam_periph *periph, union ccb *start_ccb) error = ada_zone_cmd(periph, start_ccb, bp, &queue_ccb); if ((error != 0) || (queue_ccb == 0)) { + /* + * g_io_deliver will recurisvely call start + * routine for ENOMEM, so drop the periph + * lock to allow that recursion. + */ + if (error == ENOMEM) + cam_periph_unlock(periph); biofinish(bp, NULL, error); + if (error == ENOMEM) + cam_periph_lock(periph); xpt_release_ccb(start_ccb); return; } @@ -2705,10 +2719,17 @@ adaprobedone(struct cam_periph *periph, union ccb *ccb) adaschedule(periph); if ((softc->flags & ADA_FLAG_ANNOUNCED) == 0) { softc->flags |= ADA_FLAG_ANNOUNCED; - cam_periph_unhold(periph); - } else { - cam_periph_release_locked(periph); + + /* + * We'll release this reference once GEOM calls us back via + * adadiskgonecb(), telling us that our provider has been freed. + */ + if (cam_periph_acquire(periph) == 0) + disk_create(softc->disk, DISK_VERSION); + + cam_periph_release_boot(periph); } + cam_periph_release_locked(periph); } static void @@ -3384,7 +3405,7 @@ adadone(struct cam_periph *periph, union ccb *done_ccb) } static int -adaerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags) +adaerror(union ccb *ccb, uint32_t cam_flags, uint32_t sense_flags) { #ifdef CAM_IO_STATS struct ada_softc *softc; @@ -3417,8 +3438,8 @@ static void adasetgeom(struct ada_softc *softc, struct ccb_getdev *cgd) { struct disk_params *dp = &softc->params; - u_int64_t lbasize48; - u_int32_t lbasize; + uint64_t lbasize48; + uint32_t lbasize; u_int maxio, d_flags; size_t tmpsize; @@ -3429,27 +3450,27 @@ adasetgeom(struct ada_softc *softc, struct ccb_getdev *cgd) dp->heads = cgd->ident_data.current_heads; dp->secs_per_track = cgd->ident_data.current_sectors; dp->cylinders = cgd->ident_data.cylinders; - dp->sectors = (u_int32_t)cgd->ident_data.current_size_1 | - ((u_int32_t)cgd->ident_data.current_size_2 << 16); + dp->sectors = (uint32_t)cgd->ident_data.current_size_1 | + ((uint32_t)cgd->ident_data.current_size_2 << 16); } else { dp->heads = cgd->ident_data.heads; dp->secs_per_track = cgd->ident_data.sectors; dp->cylinders = cgd->ident_data.cylinders; dp->sectors = cgd->ident_data.cylinders * - (u_int32_t)(dp->heads * dp->secs_per_track); + (uint32_t)(dp->heads * dp->secs_per_track); } - lbasize = (u_int32_t)cgd->ident_data.lba_size_1 | - ((u_int32_t)cgd->ident_data.lba_size_2 << 16); + lbasize = (uint32_t)cgd->ident_data.lba_size_1 | + ((uint32_t)cgd->ident_data.lba_size_2 << 16); /* use the 28bit LBA size if valid or bigger than the CHS mapping */ if (cgd->ident_data.cylinders == 16383 || dp->sectors < lbasize) dp->sectors = lbasize; /* use the 48bit LBA size if valid */ - lbasize48 = ((u_int64_t)cgd->ident_data.lba_size48_1) | - ((u_int64_t)cgd->ident_data.lba_size48_2 << 16) | - ((u_int64_t)cgd->ident_data.lba_size48_3 << 32) | - ((u_int64_t)cgd->ident_data.lba_size48_4 << 48); + lbasize48 = ((uint64_t)cgd->ident_data.lba_size48_1) | + ((uint64_t)cgd->ident_data.lba_size48_2 << 16) | + ((uint64_t)cgd->ident_data.lba_size48_3 << 32) | + ((uint64_t)cgd->ident_data.lba_size48_4 << 48); if ((cgd->ident_data.support.command2 & ATA_SUPPORT_ADDRESS48) && lbasize48 > ATA_MAX_28BIT_LBA) dp->sectors = lbasize48; diff --git a/sys/cam/ata/ata_pmp.c b/sys/cam/ata/ata_pmp.c index 153d8e187d7a..51f60645a969 100644 --- a/sys/cam/ata/ata_pmp.c +++ b/sys/cam/ata/ata_pmp.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org> * All rights reserved. @@ -26,9 +26,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #ifdef _KERNEL @@ -113,7 +110,7 @@ struct pmp_softc { }; static periph_init_t pmpinit; -static void pmpasync(void *callback_arg, u_int32_t code, +static void pmpasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg); static void pmpsysctlinit(void *context, int pending); static periph_ctor_t pmpregister; @@ -262,7 +259,7 @@ pmpcleanup(struct cam_periph *periph) } static void -pmpasync(void *callback_arg, u_int32_t code, +pmpasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg) { struct cam_periph *periph; @@ -586,7 +583,7 @@ pmpdone(struct cam_periph *periph, union ccb *done_ccb) struct pmp_softc *softc; struct ccb_ataio *ataio; struct cam_path *dpath; - u_int32_t priority, res; + uint32_t priority, res; int i; softc = (struct pmp_softc *)periph->softc; diff --git a/sys/cam/ata/ata_xpt.c b/sys/cam/ata/ata_xpt.c index 2b299412b48e..7bdddc98511b 100644 --- a/sys/cam/ata/ata_xpt.c +++ b/sys/cam/ata/ata_xpt.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org> * All rights reserved. @@ -26,9 +26,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/bus.h> #include <sys/endian.h> @@ -61,11 +58,10 @@ __FBSDID("$FreeBSD$"); #include <cam/scsi/scsi_message.h> #include <cam/ata/ata_all.h> #include <machine/stdarg.h> /* for xpt_print below */ -#include "opt_cam.h" struct ata_quirk_entry { struct scsi_inquiry_pattern inq_pat; - u_int8_t quirks; + uint8_t quirks; #define CAM_QUIRK_MAXTAGS 0x01 u_int mintags; u_int maxtags; @@ -182,22 +178,17 @@ static void ata_get_transfer_settings(struct ccb_trans_settings *cts); static void ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path, int async_update); -static void ata_dev_async(u_int32_t async_code, +static void ata_dev_async(uint32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, void *async_arg); static void ata_action(union ccb *start_ccb); -static void ata_announce_periph(struct cam_periph *periph); static void ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb); -static void ata_proto_announce(struct cam_ed *device); static void ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb); -static void ata_proto_denounce(struct cam_ed *device); static void ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb); static void ata_proto_debug_out(union ccb *ccb); -static void semb_proto_announce(struct cam_ed *device); static void semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb); -static void semb_proto_denounce(struct cam_ed *device); static void semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb); static int ata_dma = 1; @@ -210,7 +201,6 @@ static struct xpt_xport_ops ata_xport_ops = { .alloc_device = ata_alloc_device, .action = ata_action, .async = ata_dev_async, - .announce = ata_announce_periph, .announce_sbuf = ata_announce_periph_sbuf, }; #define ATA_XPT_XPORT(x, X) \ @@ -227,9 +217,7 @@ ATA_XPT_XPORT(sata, SATA); #undef ATA_XPORT_XPORT static struct xpt_proto_ops ata_proto_ops_ata = { - .announce = ata_proto_announce, .announce_sbuf = ata_proto_announce_sbuf, - .denounce = ata_proto_denounce, .denounce_sbuf = ata_proto_denounce_sbuf, .debug_out = ata_proto_debug_out, }; @@ -240,9 +228,7 @@ static struct xpt_proto ata_proto_ata = { }; static struct xpt_proto_ops ata_proto_ops_satapm = { - .announce = ata_proto_announce, .announce_sbuf = ata_proto_announce_sbuf, - .denounce = ata_proto_denounce, .denounce_sbuf = ata_proto_denounce_sbuf, .debug_out = ata_proto_debug_out, }; @@ -253,9 +239,7 @@ static struct xpt_proto ata_proto_satapm = { }; static struct xpt_proto_ops ata_proto_ops_semb = { - .announce = semb_proto_announce, .announce_sbuf = semb_proto_announce_sbuf, - .denounce = semb_proto_denounce, .denounce_sbuf = semb_proto_denounce_sbuf, .debug_out = ata_proto_debug_out, }; @@ -380,7 +364,7 @@ aprobestart(struct cam_periph *periph, union ccb *start_ccb) aprobedone, /*flags*/CAM_DIR_IN, 0, - /*data_ptr*/(u_int8_t *)&softc->ident_data, + /*data_ptr*/(uint8_t *)&softc->ident_data, /*dxfer_len*/sizeof(softc->ident_data), 30 * 1000); if (path->device->protocol == PROTO_ATA) @@ -660,7 +644,7 @@ negotiate: /*retries*/1, aprobedone, MSG_SIMPLE_Q_TAG, - (u_int8_t *)inq_buf, + (uint8_t *)inq_buf, inquiry_len, /*evpd*/FALSE, /*page_code*/0, @@ -696,7 +680,7 @@ negotiate: aprobedone, /*flags*/CAM_DIR_IN, 0, - /*data_ptr*/(u_int8_t *)&softc->ident_data, + /*data_ptr*/(uint8_t *)&softc->ident_data, /*dxfer_len*/sizeof(softc->ident_data), 30 * 1000); ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x02, @@ -708,7 +692,7 @@ negotiate: aprobedone, /*flags*/CAM_DIR_IN, 0, - /*data_ptr*/(u_int8_t *)&softc->ident_data, + /*data_ptr*/(uint8_t *)&softc->ident_data, /*dxfer_len*/sizeof(softc->ident_data), 30 * 1000); ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x00, @@ -748,7 +732,7 @@ aprobedone(struct cam_periph *periph, union ccb *done_ccb) aprobe_softc *softc; struct cam_path *path; cam_status status; - u_int32_t priority; + uint32_t priority; u_int caps, oif; int changed, found = 1; static const uint8_t fake_device_id_hdr[8] = @@ -965,7 +949,7 @@ noerror: path->device->device_id_len = 0; } path->device->serial_num = - (u_int8_t *)malloc((sizeof(ident_buf->serial) + 1), + (uint8_t *)malloc((sizeof(ident_buf->serial) + 1), M_CAMXPT, M_NOWAIT); if (path->device->serial_num != NULL) { bcopy(ident_buf->serial, @@ -1003,7 +987,7 @@ noerror: path->bus->sim->max_tagged_dev_openings != 0) { /* Check if the SIM does not want queued commands. */ xpt_path_inq(&cpi, path); - if (cpi.ccb_h.status == CAM_REQ_CMP && + if (cam_ccb_success((union ccb *)&cpi) && (cpi.hba_inquiry & PI_TAG_ABLE)) { /* Report SIM which tags are allowed. */ bzero(&cts, sizeof(cts)); @@ -1162,7 +1146,7 @@ notsata: case PROBE_INQUIRY: case PROBE_FULL_INQUIRY: { - u_int8_t periph_qual, len; + uint8_t periph_qual, len; path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID; @@ -1481,7 +1465,7 @@ ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb) /* If there is PMP... */ if ((scan_info->cpi->hba_inquiry & PI_SATAPM) && (scan_info->counter == scan_info->cpi->max_target)) { - if (work_ccb->ccb_h.status == CAM_REQ_CMP) { + if (cam_ccb_success(work_ccb)) { /* everything else will be probed by it */ /* Free the current request path- we're done with it. */ xpt_free_path(work_ccb->ccb_h.path); @@ -2036,7 +2020,7 @@ ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path, * Handle any per-device event notifications that require action by the XPT. */ static void -ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target, +ata_dev_async(uint32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, void *async_arg) { /* @@ -2134,59 +2118,6 @@ _ata_announce_periph(struct cam_periph *periph, struct ccb_trans_settings *cts, } static void -ata_announce_periph(struct cam_periph *periph) -{ - struct ccb_trans_settings cts; - u_int speed, mb; - - bzero(&cts, sizeof(cts)); - _ata_announce_periph(periph, &cts, &speed); - if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) - return; - - mb = speed / 1000; - if (mb > 0) - printf("%s%d: %d.%03dMB/s transfers", - periph->periph_name, periph->unit_number, - mb, speed % 1000); - else - printf("%s%d: %dKB/s transfers", periph->periph_name, - periph->unit_number, speed); - /* Report additional information about connection */ - if (cts.transport == XPORT_ATA) { - struct ccb_trans_settings_pata *pata = - &cts.xport_specific.ata; - - printf(" ("); - if (pata->valid & CTS_ATA_VALID_MODE) - printf("%s, ", ata_mode2string(pata->mode)); - if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0) - printf("ATAPI %dbytes, ", pata->atapi); - if (pata->valid & CTS_ATA_VALID_BYTECOUNT) - printf("PIO %dbytes", pata->bytecount); - printf(")"); - } - if (cts.transport == XPORT_SATA) { - struct ccb_trans_settings_sata *sata = - &cts.xport_specific.sata; - - printf(" ("); - if (sata->valid & CTS_SATA_VALID_REVISION) - printf("SATA %d.x, ", sata->revision); - else - printf("SATA, "); - if (sata->valid & CTS_SATA_VALID_MODE) - printf("%s, ", ata_mode2string(sata->mode)); - if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0) - printf("ATAPI %dbytes, ", sata->atapi); - if (sata->valid & CTS_SATA_VALID_BYTECOUNT) - printf("PIO %dbytes", sata->bytecount); - printf(")"); - } - printf("\n"); -} - -static void ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb) { struct ccb_trans_settings cts; @@ -2210,33 +2141,33 @@ ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb) struct ccb_trans_settings_pata *pata = &cts.xport_specific.ata; - sbuf_printf(sb, " ("); + sbuf_cat(sb, " ("); if (pata->valid & CTS_ATA_VALID_MODE) sbuf_printf(sb, "%s, ", ata_mode2string(pata->mode)); if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0) sbuf_printf(sb, "ATAPI %dbytes, ", pata->atapi); if (pata->valid & CTS_ATA_VALID_BYTECOUNT) sbuf_printf(sb, "PIO %dbytes", pata->bytecount); - sbuf_printf(sb, ")"); + sbuf_putc(sb, ')'); } if (cts.transport == XPORT_SATA) { struct ccb_trans_settings_sata *sata = &cts.xport_specific.sata; - sbuf_printf(sb, " ("); + sbuf_cat(sb, " ("); if (sata->valid & CTS_SATA_VALID_REVISION) sbuf_printf(sb, "SATA %d.x, ", sata->revision); else - sbuf_printf(sb, "SATA, "); + sbuf_cat(sb, "SATA, "); if (sata->valid & CTS_SATA_VALID_MODE) sbuf_printf(sb, "%s, ", ata_mode2string(sata->mode)); if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0) sbuf_printf(sb, "ATAPI %dbytes, ", sata->atapi); if (sata->valid & CTS_SATA_VALID_BYTECOUNT) sbuf_printf(sb, "PIO %dbytes", sata->bytecount); - sbuf_printf(sb, ")"); + sbuf_putc(sb, ')'); } - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); } static void @@ -2246,18 +2177,6 @@ ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb) } static void -ata_proto_announce(struct cam_ed *device) -{ - ata_print_ident(&device->ident_data); -} - -static void -ata_proto_denounce(struct cam_ed *device) -{ - ata_print_ident_short(&device->ident_data); -} - -static void ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb) { ata_print_ident_short_sbuf(&device->ident_data, sb); @@ -2270,18 +2189,6 @@ semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb) } static void -semb_proto_announce(struct cam_ed *device) -{ - semb_print_ident((struct sep_identify_data *)&device->ident_data); -} - -static void -semb_proto_denounce(struct cam_ed *device) -{ - semb_print_ident_short((struct sep_identify_data *)&device->ident_data); -} - -static void semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb) { semb_print_ident_short_sbuf((struct sep_identify_data *)&device->ident_data, sb); diff --git a/sys/cam/cam.c b/sys/cam/cam.c index 5b7235e01314..d9cff3468da0 100644 --- a/sys/cam/cam.c +++ b/sys/cam/cam.c @@ -1,7 +1,7 @@ /*- * Generic utility routines for the Common Access Method layer. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997 Justin T. Gibbs. * All rights reserved. @@ -28,13 +28,11 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #ifdef _KERNEL #include <sys/systm.h> #include <sys/kernel.h> +#include <sys/memdesc.h> #include <sys/sysctl.h> #else /* _KERNEL */ #include <stdlib.h> @@ -51,6 +49,7 @@ __FBSDID("$FreeBSD$"); #ifdef _KERNEL #include <sys/libkern.h> +#include <machine/bus.h> #include <cam/cam_queue.h> #include <cam/cam_xpt.h> @@ -88,10 +87,12 @@ const struct cam_status_entry cam_status_table[] = { { CAM_REQ_TERMIO, "CCB request terminated by the host" }, { CAM_UNREC_HBA_ERROR, "Unrecoverable Host Bus Adapter Error" }, { CAM_REQ_TOO_BIG, "The request was too large for this host" }, - { CAM_REQUEUE_REQ, "Unconditionally Re-queue Request", }, + { CAM_REQUEUE_REQ, "Unconditionally Re-queue Request" }, { CAM_ATA_STATUS_ERROR, "ATA Status Error" }, { CAM_SCSI_IT_NEXUS_LOST,"Initiator/Target Nexus Lost" }, { CAM_SMP_STATUS_ERROR, "SMP Status Error" }, + { CAM_REQ_SOFTTIMEOUT, "Completed w/o error, but took too long" }, + { CAM_NVME_STATUS_ERROR, "NVME Status Error" }, { CAM_IDE, "Initiator Detected Error Message Received" }, { CAM_RESRC_UNAVAIL, "Resource Unavailable" }, { CAM_UNACKED_EVENT, "Unacknowledged Event by Host" }, @@ -121,14 +122,14 @@ SYSCTL_INT(_kern_cam, OID_AUTO, sort_io_queues, CTLFLAG_RWTUN, #endif void -cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen) +cam_strvis(uint8_t *dst, const uint8_t *src, int srclen, int dstlen) { cam_strvis_flag(dst, src, srclen, dstlen, CAM_STRVIS_FLAG_NONASCII_ESC); } void -cam_strvis_flag(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen, +cam_strvis_flag(uint8_t *dst, const uint8_t *src, int srclen, int dstlen, uint32_t flags) { struct sbuf sb; @@ -139,7 +140,7 @@ cam_strvis_flag(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen, } void -cam_strvis_sbuf(struct sbuf *sb, const u_int8_t *src, int srclen, +cam_strvis_sbuf(struct sbuf *sb, const uint8_t *src, int srclen, uint32_t flags) { @@ -201,7 +202,7 @@ cam_strvis_sbuf(struct sbuf *sb, const u_int8_t *src, int srclen, * Each '*' generates recursion, so keep the number of * in check. */ int -cam_strmatch(const u_int8_t *str, const u_int8_t *pattern, int str_len) +cam_strmatch(const uint8_t *str, const uint8_t *pattern, int str_len) { while (*pattern != '\0' && str_len > 0) { @@ -417,7 +418,7 @@ cam_error_string(struct cam_device *device, union ccb *ccb, char *str, ccb->ccb_h.func_code); break; } - sbuf_printf(&sb, "\n"); + sbuf_putc(&sb, '\n'); } if (flags & CAM_ESF_CAM_STATUS) { @@ -448,13 +449,13 @@ cam_error_string(struct cam_device *device, union ccb *ccb, char *str, if (proto_flags & CAM_EAF_PRINT_STATUS) { sbuf_cat(&sb, path_str); ata_status_sbuf(&ccb->ataio, &sb); - sbuf_printf(&sb, "\n"); + sbuf_putc(&sb, '\n'); } if (proto_flags & CAM_EAF_PRINT_RESULT) { sbuf_cat(&sb, path_str); - sbuf_printf(&sb, "RES: "); + sbuf_cat(&sb, "RES: "); ata_res_sbuf(&ccb->ataio.res, &sb); - sbuf_printf(&sb, "\n"); + sbuf_putc(&sb, '\n'); } break; @@ -571,3 +572,93 @@ cam_calc_geometry(struct ccb_calc_geometry *ccg, int extended) ccg->cylinders = ccg->volume_size / secs_per_cylinder; ccg->ccb_h.status = CAM_REQ_CMP; } + +#ifdef _KERNEL +struct memdesc +memdesc_ccb(union ccb *ccb) +{ + struct ccb_hdr *ccb_h; + void *data_ptr; + uint32_t dxfer_len; + uint16_t sglist_cnt; + + ccb_h = &ccb->ccb_h; + switch (ccb_h->func_code) { + case XPT_SCSI_IO: { + struct ccb_scsiio *csio; + + csio = &ccb->csio; + data_ptr = csio->data_ptr; + dxfer_len = csio->dxfer_len; + sglist_cnt = csio->sglist_cnt; + break; + } + case XPT_CONT_TARGET_IO: { + struct ccb_scsiio *ctio; + + ctio = &ccb->ctio; + data_ptr = ctio->data_ptr; + dxfer_len = ctio->dxfer_len; + sglist_cnt = ctio->sglist_cnt; + break; + } + case XPT_ATA_IO: { + struct ccb_ataio *ataio; + + ataio = &ccb->ataio; + data_ptr = ataio->data_ptr; + dxfer_len = ataio->dxfer_len; + sglist_cnt = 0; + break; + } + case XPT_NVME_IO: + case XPT_NVME_ADMIN: { + struct ccb_nvmeio *nvmeio; + + nvmeio = &ccb->nvmeio; + data_ptr = nvmeio->data_ptr; + dxfer_len = nvmeio->dxfer_len; + sglist_cnt = nvmeio->sglist_cnt; + break; + } + default: + panic("%s: Unsupported func code %d", __func__, + ccb_h->func_code); + } + + switch ((ccb_h->flags & CAM_DATA_MASK)) { + case CAM_DATA_VADDR: + return (memdesc_vaddr(data_ptr, dxfer_len)); + case CAM_DATA_PADDR: + return (memdesc_paddr((vm_paddr_t)(uintptr_t)data_ptr, + dxfer_len)); + case CAM_DATA_SG: + return (memdesc_vlist(data_ptr, sglist_cnt)); + case CAM_DATA_SG_PADDR: + return (memdesc_plist(data_ptr, sglist_cnt)); + case CAM_DATA_BIO: + return (memdesc_bio(data_ptr)); + default: + panic("%s: flags 0x%X unimplemented", __func__, ccb_h->flags); + } +} + +int +bus_dmamap_load_ccb(bus_dma_tag_t dmat, bus_dmamap_t map, union ccb *ccb, + bus_dmamap_callback_t *callback, void *callback_arg, + int flags) +{ + struct ccb_hdr *ccb_h; + struct memdesc mem; + + ccb_h = &ccb->ccb_h; + if ((ccb_h->flags & CAM_DIR_MASK) == CAM_DIR_NONE) { + callback(callback_arg, NULL, 0, 0); + return (0); + } + + mem = memdesc_ccb(ccb); + return (bus_dmamap_load_mem(dmat, map, &mem, callback, callback_arg, + flags)); +} +#endif diff --git a/sys/cam/cam.h b/sys/cam/cam.h index 6bec8b46f417..963c9798ddbc 100644 --- a/sys/cam/cam.h +++ b/sys/cam/cam.h @@ -1,7 +1,7 @@ /*- * Data structures and definitions for the CAM system. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997 Justin T. Gibbs. * All rights reserved. @@ -26,8 +26,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _CAM_CAM_H @@ -37,11 +35,14 @@ #include "opt_cam.h" #endif -#include <sys/cdefs.h> +#ifndef _KERNEL +#include <stdbool.h> +#include <stdio.h> +#endif typedef u_int path_id_t; typedef u_int target_id_t; -typedef u_int64_t lun_id_t; +typedef uint64_t lun_id_t; #define CAM_XPT_PATH_ID ((path_id_t)~0) #define CAM_BUS_WILDCARD ((path_id_t)~0) @@ -49,10 +50,10 @@ typedef u_int64_t lun_id_t; #define CAM_LUN_WILDCARD (~(u_int)0) #define CAM_EXTLUN_BYTE_SWIZZLE(lun) ( \ - ((((u_int64_t)lun) & 0xffff000000000000L) >> 48) | \ - ((((u_int64_t)lun) & 0x0000ffff00000000L) >> 16) | \ - ((((u_int64_t)lun) & 0x00000000ffff0000L) << 16) | \ - ((((u_int64_t)lun) & 0x000000000000ffffL) << 48)) + ((((uint64_t)lun) & 0xffff000000000000L) >> 48) | \ + ((((uint64_t)lun) & 0x0000ffff00000000L) >> 16) | \ + ((((uint64_t)lun) & 0x00000000ffff0000L) << 16) | \ + ((((uint64_t)lun) & 0x000000000000ffffL) << 48)) /* * Maximum length for a CAM CDB. @@ -83,15 +84,15 @@ typedef enum { * the queue giving round robin per priority level scheduling. */ typedef struct { - u_int32_t priority; + uint32_t priority; #define CAM_PRIORITY_HOST ((CAM_RL_HOST << 8) + 0x80) #define CAM_PRIORITY_BUS ((CAM_RL_BUS << 8) + 0x80) #define CAM_PRIORITY_XPT ((CAM_RL_XPT << 8) + 0x80) #define CAM_PRIORITY_DEV ((CAM_RL_DEV << 8) + 0x80) #define CAM_PRIORITY_OOB (CAM_RL_DEV << 8) #define CAM_PRIORITY_NORMAL ((CAM_RL_NORMAL << 8) + 0x80) -#define CAM_PRIORITY_NONE (u_int32_t)-1 - u_int32_t generation; +#define CAM_PRIORITY_NONE (uint32_t)-1 + uint32_t generation; int index; #define CAM_UNQUEUED_INDEX -1 #define CAM_ACTIVE_INDEX -2 @@ -237,7 +238,12 @@ typedef enum { CAM_REQ_SOFTTIMEOUT = 0x1f, /* - * 0x20 - 0x32 are unassigned + * NVME error, look at errro code in CCB + */ + CAM_NVME_STATUS_ERROR = 0x20, + + /* + * 0x21 - 0x32 are unassigned */ /* Initiator Detected Error */ @@ -377,13 +383,13 @@ typedef int (cam_quirkmatch_t)(caddr_t, caddr_t); caddr_t cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries, int entry_size, cam_quirkmatch_t *comp_func); -void cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen); -void cam_strvis_flag(u_int8_t *dst, const u_int8_t *src, int srclen, +void cam_strvis(uint8_t *dst, const uint8_t *src, int srclen, int dstlen); +void cam_strvis_flag(uint8_t *dst, const uint8_t *src, int srclen, int dstlen, uint32_t flags); -void cam_strvis_sbuf(struct sbuf *sb, const u_int8_t *src, int srclen, +void cam_strvis_sbuf(struct sbuf *sb, const uint8_t *src, int srclen, uint32_t flags); -int cam_strmatch(const u_int8_t *str, const u_int8_t *pattern, int str_len); +int cam_strmatch(const uint8_t *str, const uint8_t *pattern, int str_len); const struct cam_status_entry* cam_fetch_status_entry(cam_status status); #ifdef _KERNEL diff --git a/sys/cam/cam_ccb.h b/sys/cam/cam_ccb.h index 1ae310d399b7..15e136e8a072 100644 --- a/sys/cam/cam_ccb.h +++ b/sys/cam/cam_ccb.h @@ -1,7 +1,7 @@ /*- * Data structures and definitions for CAM Control Blocks (CCBs). * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997, 1998 Justin T. Gibbs. * All rights reserved. @@ -26,15 +26,12 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _CAM_CAM_CCB_H #define _CAM_CAM_CCB_H 1 #include <sys/queue.h> -#include <sys/cdefs.h> #include <sys/time.h> #include <sys/limits.h> #ifndef _KERNEL @@ -300,15 +297,17 @@ typedef enum { XPORT_SRP, /* SCSI RDMA Protocol */ XPORT_NVME, /* NVMe over PCIe */ XPORT_MMCSD, /* MMC, SD, SDIO card */ + XPORT_NVMF, /* NVMe over Fabrics */ } cam_xport; -#define XPORT_IS_NVME(t) ((t) == XPORT_NVME) +#define XPORT_IS_NVME(t) ((t) == XPORT_NVME || (t) == XPORT_NVMF) #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) && !XPORT_IS_NVME(t)) #define XPORT_DEVSTAT_TYPE(t) (XPORT_IS_ATA(t) ? DEVSTAT_TYPE_IF_IDE : \ XPORT_IS_SCSI(t) ? DEVSTAT_TYPE_IF_SCSI : \ + XPORT_IS_NVME(t) ? DEVSTAT_TYPE_IF_NVME : \ DEVSTAT_TYPE_IF_OTHER) #define PROTO_VERSION_UNKNOWN (UINT_MAX - 1) @@ -326,17 +325,17 @@ typedef union { typedef union { void *ptr; u_long field; - u_int8_t bytes[sizeof(uintptr_t)]; + uint8_t bytes[sizeof(uintptr_t)]; } ccb_priv_entry; typedef union { ccb_priv_entry entries[CCB_PERIPH_PRIV_SIZE]; - u_int8_t bytes[CCB_PERIPH_PRIV_SIZE * sizeof(ccb_priv_entry)]; + uint8_t bytes[CCB_PERIPH_PRIV_SIZE * sizeof(ccb_priv_entry)]; } ccb_ppriv_area; typedef union { ccb_priv_entry entries[CCB_SIM_PRIV_SIZE]; - u_int8_t bytes[CCB_SIM_PRIV_SIZE * sizeof(ccb_priv_entry)]; + uint8_t bytes[CCB_SIM_PRIV_SIZE * sizeof(ccb_priv_entry)]; } ccb_spriv_area; typedef struct { @@ -351,26 +350,26 @@ struct ccb_hdr { camq_entry sim_links; /* For chaining in the SIM layer */ camq_entry periph_links; /* For chaining in the type driver */ #if BYTE_ORDER == LITTLE_ENDIAN - u_int16_t retry_count; - u_int16_t alloc_flags; /* ccb_alloc_flags */ + uint16_t retry_count; + uint16_t alloc_flags; /* ccb_alloc_flags */ #else - u_int16_t alloc_flags; /* ccb_alloc_flags */ - u_int16_t retry_count; + uint16_t alloc_flags; /* ccb_alloc_flags */ + uint16_t retry_count; #endif void (*cbfcnp)(struct cam_periph *, union ccb *); /* Callback on completion function */ xpt_opcode func_code; /* XPT function code */ - u_int32_t status; /* Status returned by CAM subsystem */ + uint32_t status; /* Status returned by CAM subsystem */ struct cam_path *path; /* Compiled path for this ccb */ path_id_t path_id; /* Path ID for the request */ target_id_t target_id; /* Target device ID */ lun_id_t target_lun; /* Target LUN number */ - u_int32_t flags; /* ccb_flags */ - u_int32_t xflags; /* Extended flags */ + uint32_t flags; /* ccb_flags */ + uint32_t xflags; /* Extended flags */ ccb_ppriv_area periph_priv; ccb_spriv_area sim_priv; ccb_qos_area qos; - u_int32_t timeout; /* Hard timeout value in mseconds */ + uint32_t timeout; /* Hard timeout value in mseconds */ struct timeval softtimeout; /* Soft timeout value in sec + usec */ }; @@ -380,9 +379,9 @@ struct ccb_getdev { cam_proto protocol; struct scsi_inquiry_data inq_data; struct ata_params ident_data; - u_int8_t serial_num[252]; - u_int8_t inq_flags; - u_int8_t serial_num_len; + uint8_t serial_num[252]; + uint8_t inq_flags; + uint8_t serial_num_len; void *padding[2]; }; @@ -415,9 +414,9 @@ typedef enum { struct ccb_getdevlist { struct ccb_hdr ccb_h; char periph_name[DEV_IDLEN]; - u_int32_t unit_number; + uint32_t unit_number; unsigned int generation; - u_int32_t index; + uint32_t index; ccb_getdevlist_status_e status; }; @@ -432,7 +431,7 @@ typedef enum { struct periph_match_pattern { char periph_name[DEV_IDLEN]; - u_int32_t unit_number; + uint32_t unit_number; path_id_t path_id; target_id_t target_id; lun_id_t target_lun; @@ -475,8 +474,8 @@ typedef enum { struct bus_match_pattern { path_id_t path_id; char dev_name[DEV_IDLEN]; - u_int32_t unit_number; - u_int32_t bus_id; + uint32_t unit_number; + uint32_t bus_id; bus_pattern_flags flags; }; @@ -499,7 +498,7 @@ struct dev_match_pattern { struct periph_match_result { char periph_name[DEV_IDLEN]; - u_int32_t unit_number; + uint32_t unit_number; path_id_t path_id; target_id_t target_id; lun_id_t target_lun; @@ -523,8 +522,8 @@ struct device_match_result { struct bus_match_result { path_id_t path_id; char dev_name[DEV_IDLEN]; - u_int32_t unit_number; - u_int32_t bus_id; + uint32_t unit_number; + uint32_t bus_id; }; union match_result { @@ -579,11 +578,11 @@ struct ccb_dev_position { struct ccb_dev_match { struct ccb_hdr ccb_h; ccb_dev_match_status status; - u_int32_t num_patterns; - u_int32_t pattern_buf_len; + uint32_t num_patterns; + uint32_t pattern_buf_len; struct dev_match_pattern *patterns; - u_int32_t num_matches; - u_int32_t match_buf_len; + uint32_t num_matches; + uint32_t match_buf_len; struct dev_match_result *matches; struct ccb_dev_position pos; }; @@ -628,18 +627,18 @@ typedef enum { /* Path Inquiry CCB */ struct ccb_pathinq_settings_spi { - u_int8_t ppr_options; + uint8_t ppr_options; }; struct ccb_pathinq_settings_fc { - u_int64_t wwnn; /* world wide node name */ - u_int64_t wwpn; /* world wide port name */ - u_int32_t port; /* 24 bit port id, if known */ - u_int32_t bitrate; /* Mbps */ + uint64_t wwnn; /* world wide node name */ + uint64_t wwpn; /* world wide port name */ + uint32_t port; /* 24 bit port id, if known */ + uint32_t bitrate; /* Mbps */ }; struct ccb_pathinq_settings_sas { - u_int32_t bitrate; /* Mbps */ + uint32_t bitrate; /* Mbps */ }; #define NVME_DEV_NAME_LEN 52 @@ -655,28 +654,34 @@ struct ccb_pathinq_settings_nvme { _Static_assert(sizeof(struct ccb_pathinq_settings_nvme) == 64, "ccb_pathinq_settings_nvme too big"); +struct ccb_pathinq_settings_nvmf { + uint32_t nsid; /* Namespace ID for this path */ + uint8_t trtype; + char dev_name[NVME_DEV_NAME_LEN]; /* nvme controller dev name for this device */ +}; + #define PATHINQ_SETTINGS_SIZE 128 struct ccb_pathinq { struct ccb_hdr ccb_h; - u_int8_t version_num; /* Version number for the SIM/HBA */ - u_int8_t hba_inquiry; /* Mimic of INQ byte 7 for the HBA */ - u_int16_t target_sprt; /* Flags for target mode support */ - u_int32_t hba_misc; /* Misc HBA features */ - u_int16_t hba_eng_cnt; /* HBA engine count */ + uint8_t version_num; /* Version number for the SIM/HBA */ + uint8_t hba_inquiry; /* Mimic of INQ byte 7 for the HBA */ + uint16_t target_sprt; /* Flags for target mode support */ + uint32_t hba_misc; /* Misc HBA features */ + uint16_t hba_eng_cnt; /* HBA engine count */ /* Vendor Unique capabilities */ - u_int8_t vuhba_flags[VUHBALEN]; - u_int32_t max_target; /* Maximum supported Target */ - u_int32_t max_lun; /* Maximum supported Lun */ - u_int32_t async_flags; /* Installed Async handlers */ + uint8_t vuhba_flags[VUHBALEN]; + uint32_t max_target; /* Maximum supported Target */ + uint32_t max_lun; /* Maximum supported Lun */ + uint32_t async_flags; /* Installed Async handlers */ path_id_t hpath_id; /* Highest Path ID in the subsystem */ target_id_t initiator_id; /* ID of the HBA on the SCSI bus */ char sim_vid[SIM_IDLEN]; /* Vendor ID of the SIM */ char hba_vid[HBA_IDLEN]; /* Vendor ID of the HBA */ char dev_name[DEV_IDLEN];/* Device name for SIM */ - u_int32_t unit_number; /* Unit number for SIM */ - u_int32_t bus_id; /* Bus ID for SIM */ - u_int32_t base_transfer_speed;/* Base bus speed in KB/sec */ + uint32_t unit_number; /* Unit number for SIM */ + uint32_t bus_id; /* Bus ID for SIM */ + uint32_t base_transfer_speed;/* Base bus speed in KB/sec */ cam_proto protocol; u_int protocol_version; cam_xport transport; @@ -686,13 +691,14 @@ struct ccb_pathinq { struct ccb_pathinq_settings_fc fc; struct ccb_pathinq_settings_sas sas; struct ccb_pathinq_settings_nvme nvme; + struct ccb_pathinq_settings_nvmf nvmf; char ccb_pathinq_settings_opaque[PATHINQ_SETTINGS_SIZE]; } xport_specific; u_int maxio; /* Max supported I/O size, in bytes. */ - u_int16_t hba_vendor; /* HBA vendor ID */ - u_int16_t hba_device; /* HBA device ID */ - u_int16_t hba_subvendor; /* HBA subvendor ID */ - u_int16_t hba_subdevice; /* HBA subdevice ID */ + uint16_t hba_vendor; /* HBA vendor ID */ + uint16_t hba_device; /* HBA device ID */ + uint16_t hba_subvendor; /* HBA subvendor ID */ + uint16_t hba_subdevice; /* HBA subdevice ID */ }; /* Path Statistics CCB */ @@ -728,7 +734,7 @@ struct ccb_smpio { }; typedef union { - u_int8_t *sense_ptr; /* + uint8_t *sense_ptr; /* * Pointer to storage * for sense information */ @@ -737,9 +743,9 @@ typedef union { } sense_t; typedef union { - u_int8_t *cdb_ptr; /* Pointer to the CDB bytes to send */ + uint8_t *cdb_ptr; /* Pointer to the CDB bytes to send */ /* Area for the CDB send */ - u_int8_t cdb_bytes[IOCDBLEN]; + uint8_t cdb_bytes[IOCDBLEN]; } cdb_t; /* @@ -749,21 +755,21 @@ typedef union { struct ccb_scsiio { struct ccb_hdr ccb_h; union ccb *next_ccb; /* Ptr for next CCB for action */ - u_int8_t *req_map; /* Ptr to mapping info */ - u_int8_t *data_ptr; /* Ptr to the data buf/SG list */ - u_int32_t dxfer_len; /* Data transfer length */ + uint8_t *req_map; /* Ptr to mapping info */ + uint8_t *data_ptr; /* Ptr to the data buf/SG list */ + uint32_t dxfer_len; /* Data transfer length */ /* Autosense storage */ struct scsi_sense_data sense_data; - u_int8_t sense_len; /* Number of bytes to autosense */ - u_int8_t cdb_len; /* Number of bytes for the CDB */ - u_int16_t sglist_cnt; /* Number of SG list entries */ - u_int8_t scsi_status; /* Returned SCSI status */ - u_int8_t sense_resid; /* Autosense resid length: 2's comp */ - u_int32_t resid; /* Transfer residual length: 2's comp */ + uint8_t sense_len; /* Number of bytes to autosense */ + uint8_t cdb_len; /* Number of bytes for the CDB */ + uint16_t sglist_cnt; /* Number of SG list entries */ + uint8_t scsi_status; /* Returned SCSI status */ + uint8_t sense_resid; /* Autosense resid length: 2's comp */ + uint32_t resid; /* Transfer residual length: 2's comp */ cdb_t cdb_io; /* Union for CDB bytes/pointer */ - u_int8_t *msg_ptr; /* Pointer to the message buffer */ - u_int16_t msg_len; /* Number of bytes for the Message */ - u_int8_t tag_action; /* What to do for tag queueing */ + uint8_t *msg_ptr; /* Pointer to the message buffer */ + uint16_t msg_len; /* Number of bytes for the Message */ + uint8_t tag_action; /* What to do for tag queueing */ /* * The tag action should be either the define below (to send a * non-tagged transaction) or one of the defined scsi tag messages @@ -793,10 +799,10 @@ struct ccb_ataio { union ccb *next_ccb; /* Ptr for next CCB for action */ struct ata_cmd cmd; /* ATA command register set */ struct ata_res res; /* ATA result register set */ - u_int8_t *data_ptr; /* Ptr to the data buf/SG list */ - u_int32_t dxfer_len; /* Data transfer length */ - u_int32_t resid; /* Transfer residual length: 2's comp */ - u_int8_t ata_flags; /* Flags for the rest of the buffer */ + uint8_t *data_ptr; /* Ptr to the data buf/SG list */ + uint32_t dxfer_len; /* Data transfer length */ + uint32_t resid; /* Transfer residual length: 2's comp */ + uint8_t ata_flags; /* Flags for the rest of the buffer */ #define ATA_FLAG_AUX 0x1 #define ATA_FLAG_ICC 0x2 uint8_t icc; /* Isochronous Command Completion */ @@ -817,9 +823,9 @@ struct ccb_mmcio { struct ccb_accept_tio { struct ccb_hdr ccb_h; cdb_t cdb_io; /* Union for CDB bytes/pointer */ - u_int8_t cdb_len; /* Number of bytes for the CDB */ - u_int8_t tag_action; /* What to do for tag queueing */ - u_int8_t sense_len; /* Number of bytes of Sense Data */ + uint8_t cdb_len; /* Number of bytes for the CDB */ + uint8_t tag_action; /* What to do for tag queueing */ + uint8_t sense_len; /* Number of bytes of Sense Data */ uint8_t priority; /* Command priority for SIMPLE tag */ u_int tag_id; /* tag id from initator (target mode) */ u_int init_id; /* initiator id of who selected */ @@ -836,14 +842,14 @@ atio_cdb_ptr(struct ccb_accept_tio *ccb) /* Release SIM Queue */ struct ccb_relsim { struct ccb_hdr ccb_h; - u_int32_t release_flags; + uint32_t release_flags; #define RELSIM_ADJUST_OPENINGS 0x01 #define RELSIM_RELEASE_AFTER_TIMEOUT 0x02 #define RELSIM_RELEASE_AFTER_CMDCMPLT 0x04 #define RELSIM_RELEASE_AFTER_QEMPTY 0x08 - u_int32_t openings; - u_int32_t release_timeout; /* Abstract argument. */ - u_int32_t qfrozen_cnt; + uint32_t openings; + uint32_t release_timeout; /* Abstract argument. */ + uint32_t qfrozen_cnt; }; /* @@ -880,7 +886,7 @@ typedef enum { AC_BUS_RESET = 0x001 /* A SCSI bus reset occurred */ } ac_code; -typedef void ac_callback_t (void *softc, u_int32_t code, +typedef void ac_callback_t (void *softc, uint32_t code, struct cam_path *path, void *args); /* @@ -889,24 +895,24 @@ typedef void ac_callback_t (void *softc, u_int32_t code, * Generic arguments passed bac which are then interpreted between a per-system * contract number. */ -#define AC_CONTRACT_DATA_MAX (128 - sizeof (u_int64_t)) +#define AC_CONTRACT_DATA_MAX (128 - sizeof (uint64_t)) struct ac_contract { - u_int64_t contract_number; - u_int8_t contract_data[AC_CONTRACT_DATA_MAX]; + uint64_t contract_number; + uint8_t contract_data[AC_CONTRACT_DATA_MAX]; }; #define AC_CONTRACT_DEV_CHG 1 struct ac_device_changed { - u_int64_t wwpn; - u_int32_t port; + uint64_t wwpn; + uint32_t port; target_id_t target; - u_int8_t arrived; + uint8_t arrived; }; /* Set Asynchronous Callback CCB */ struct ccb_setasync { struct ccb_hdr ccb_h; - u_int32_t event_enable; /* Async Event enables */ + uint32_t event_enable; /* Async Event enables */ ac_callback_t *callback; void *callback_arg; }; @@ -914,7 +920,7 @@ struct ccb_setasync { /* Set Device Type CCB */ struct ccb_setdev { struct ccb_hdr ccb_h; - u_int8_t dev_type; /* Value for dev type field in EDT */ + uint8_t dev_type; /* Value for dev type field in EDT */ }; /* SCSI Control Functions */ @@ -984,16 +990,16 @@ struct ccb_trans_settings_fc { #define CTS_FC_VALID_WWPN 0x4000 #define CTS_FC_VALID_PORT 0x2000 #define CTS_FC_VALID_SPEED 0x1000 - u_int64_t wwnn; /* world wide node name */ - u_int64_t wwpn; /* world wide port name */ - u_int32_t port; /* 24 bit port id, if known */ - u_int32_t bitrate; /* Mbps */ + uint64_t wwnn; /* world wide node name */ + uint64_t wwpn; /* world wide port name */ + uint32_t port; /* 24 bit port id, if known */ + uint32_t bitrate; /* Mbps */ }; struct ccb_trans_settings_sas { u_int valid; /* Which fields to honor */ #define CTS_SAS_VALID_SPEED 0x1000 - u_int32_t bitrate; /* Mbps */ + uint32_t bitrate; /* Mbps */ }; struct ccb_trans_settings_pata { @@ -1052,6 +1058,13 @@ struct ccb_trans_settings_nvme uint8_t max_speed; /* PCIe generation for each lane */ }; +struct ccb_trans_settings_nvmf +{ + u_int valid; /* Which fields to honor */ +#define CTS_NVMF_VALID_TRTYPE 0x01 + uint8_t trtype; +}; + #include <cam/mmc/mmc_bus.h> struct ccb_trans_settings_mmc { struct mmc_ios ios; @@ -1124,6 +1137,7 @@ struct ccb_trans_settings { struct ccb_trans_settings_pata ata; struct ccb_trans_settings_sata sata; struct ccb_trans_settings_nvme nvme; + struct ccb_trans_settings_nvmf nvmf; } xport_specific; }; @@ -1133,11 +1147,11 @@ struct ccb_trans_settings { */ struct ccb_calc_geometry { struct ccb_hdr ccb_h; - u_int32_t block_size; - u_int64_t volume_size; - u_int32_t cylinders; - u_int8_t heads; - u_int8_t secs_per_track; + uint32_t block_size; + uint64_t volume_size; + uint32_t cylinders; + uint8_t heads; + uint8_t secs_per_track; }; /* @@ -1160,14 +1174,14 @@ struct ccb_sim_knob_settings_spi { struct ccb_sim_knob_settings_fc { u_int valid; - u_int64_t wwnn; /* world wide node name */ - u_int64_t wwpn; /* world wide port name */ + uint64_t wwnn; /* world wide node name */ + uint64_t wwpn; /* world wide port name */ u_int role; }; struct ccb_sim_knob_settings_sas { u_int valid; - u_int64_t wwnn; /* world wide node name */ + uint64_t wwnn; /* world wide node name */ u_int role; }; #define KNOB_SETTINGS_SIZE 128 @@ -1203,24 +1217,24 @@ struct ccb_debug { struct ccb_en_lun { struct ccb_hdr ccb_h; - u_int16_t grp6_len; /* Group 6 VU CDB length */ - u_int16_t grp7_len; /* Group 7 VU CDB length */ - u_int8_t enable; + uint16_t grp6_len; /* Group 6 VU CDB length */ + uint16_t grp7_len; /* Group 7 VU CDB length */ + uint8_t enable; }; /* old, barely used immediate notify, binary compatibility */ struct ccb_immed_notify { struct ccb_hdr ccb_h; struct scsi_sense_data sense_data; - u_int8_t sense_len; /* Number of bytes in sense buffer */ - u_int8_t initiator_id; /* Id of initiator that selected */ - u_int8_t message_args[7]; /* Message Arguments */ + uint8_t sense_len; /* Number of bytes in sense buffer */ + uint8_t initiator_id; /* Id of initiator that selected */ + uint8_t message_args[7]; /* Message Arguments */ }; struct ccb_notify_ack { struct ccb_hdr ccb_h; - u_int16_t seq_id; /* Sequence identifier */ - u_int8_t event; /* Event flags */ + uint16_t seq_id; /* Sequence identifier */ + uint8_t event; /* Event flags */ }; struct ccb_immediate_notify { @@ -1267,26 +1281,26 @@ typedef enum { struct ccb_eng_inq { struct ccb_hdr ccb_h; - u_int16_t eng_num; /* The engine number for this inquiry */ + uint16_t eng_num; /* The engine number for this inquiry */ ei_type eng_type; /* Returned engine type */ ei_algo eng_algo; /* Returned engine algorithm type */ - u_int32_t eng_memeory; /* Returned engine memory size */ + uint32_t eng_memeory; /* Returned engine memory size */ }; struct ccb_eng_exec { /* This structure must match SCSIIO size */ struct ccb_hdr ccb_h; - u_int8_t *pdrv_ptr; /* Ptr used by the peripheral driver */ - u_int8_t *req_map; /* Ptr for mapping info on the req. */ - u_int8_t *data_ptr; /* Pointer to the data buf/SG list */ - u_int32_t dxfer_len; /* Data transfer length */ - u_int8_t *engdata_ptr; /* Pointer to the engine buffer data */ - u_int16_t sglist_cnt; /* Num of scatter gather list entries */ - u_int32_t dmax_len; /* Destination data maximum length */ - u_int32_t dest_len; /* Destination data length */ + uint8_t *pdrv_ptr; /* Ptr used by the peripheral driver */ + uint8_t *req_map; /* Ptr for mapping info on the req. */ + uint8_t *data_ptr; /* Pointer to the data buf/SG list */ + uint32_t dxfer_len; /* Data transfer length */ + uint8_t *engdata_ptr; /* Pointer to the engine buffer data */ + uint16_t sglist_cnt; /* Num of scatter gather list entries */ + uint32_t dmax_len; /* Destination data maximum length */ + uint32_t dest_len; /* Destination data length */ int32_t src_resid; /* Source residual length: 2's comp */ - u_int32_t timeout; /* Timeout value */ - u_int16_t eng_num; /* Engine number for this request */ - u_int16_t vu_flags; /* Vendor Unique flags */ + uint32_t timeout; /* Timeout value */ + uint16_t eng_num; /* Engine number for this request */ + uint16_t vu_flags; /* Vendor Unique flags */ }; /* @@ -1386,12 +1400,12 @@ union ccb { __BEGIN_DECLS static __inline void -cam_fill_csio(struct ccb_scsiio *csio, u_int32_t retries, +cam_fill_csio(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int32_t flags, u_int8_t tag_action, - u_int8_t *data_ptr, u_int32_t dxfer_len, - u_int8_t sense_len, u_int8_t cdb_len, - u_int32_t timeout) + uint32_t flags, uint8_t tag_action, + uint8_t *data_ptr, uint32_t dxfer_len, + uint8_t sense_len, uint8_t cdb_len, + uint32_t timeout) { csio->ccb_h.func_code = XPT_SCSI_IO; csio->ccb_h.flags = flags; @@ -1411,11 +1425,11 @@ cam_fill_csio(struct ccb_scsiio *csio, u_int32_t retries, } static __inline void -cam_fill_ctio(struct ccb_scsiio *csio, u_int32_t retries, +cam_fill_ctio(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int32_t flags, u_int tag_action, u_int tag_id, - u_int init_id, u_int scsi_status, u_int8_t *data_ptr, - u_int32_t dxfer_len, u_int32_t timeout) + uint32_t flags, u_int tag_action, u_int tag_id, + u_int init_id, u_int scsi_status, uint8_t *data_ptr, + uint32_t dxfer_len, uint32_t timeout) { csio->ccb_h.func_code = XPT_CONT_TARGET_IO; csio->ccb_h.flags = flags; @@ -1433,11 +1447,11 @@ cam_fill_ctio(struct ccb_scsiio *csio, u_int32_t retries, } static __inline void -cam_fill_ataio(struct ccb_ataio *ataio, u_int32_t retries, +cam_fill_ataio(struct ccb_ataio *ataio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int32_t flags, u_int tag_action __unused, - u_int8_t *data_ptr, u_int32_t dxfer_len, - u_int32_t timeout) + uint32_t flags, u_int tag_action __unused, + uint8_t *data_ptr, uint32_t dxfer_len, + uint32_t timeout) { ataio->ccb_h.func_code = XPT_ATA_IO; ataio->ccb_h.flags = flags; @@ -1516,13 +1530,19 @@ cam_ccb_status(union ccb *ccb) return ((cam_status)(ccb->ccb_h.status & CAM_STATUS_MASK)); } +static inline bool +cam_ccb_success(union ccb *ccb) +{ + return (cam_ccb_status(ccb) == CAM_REQ_CMP); +} + void cam_calc_geometry(struct ccb_calc_geometry *ccg, int extended); static __inline void -cam_fill_nvmeio(struct ccb_nvmeio *nvmeio, u_int32_t retries, +cam_fill_nvmeio(struct ccb_nvmeio *nvmeio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int32_t flags, u_int8_t *data_ptr, u_int32_t dxfer_len, - u_int32_t timeout) + uint32_t flags, uint8_t *data_ptr, uint32_t dxfer_len, + uint32_t timeout) { nvmeio->ccb_h.func_code = XPT_NVME_IO; nvmeio->ccb_h.flags = flags; @@ -1534,10 +1554,10 @@ cam_fill_nvmeio(struct ccb_nvmeio *nvmeio, u_int32_t retries, } static __inline void -cam_fill_nvmeadmin(struct ccb_nvmeio *nvmeio, u_int32_t retries, +cam_fill_nvmeadmin(struct ccb_nvmeio *nvmeio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int32_t flags, u_int8_t *data_ptr, u_int32_t dxfer_len, - u_int32_t timeout) + uint32_t flags, uint8_t *data_ptr, uint32_t dxfer_len, + uint32_t timeout) { nvmeio->ccb_h.func_code = XPT_NVME_ADMIN; nvmeio->ccb_h.flags = flags; diff --git a/sys/cam/cam_compat.c b/sys/cam/cam_compat.c index 6893402a3d9c..fdb4ee8717ec 100644 --- a/sys/cam/cam_compat.c +++ b/sys/cam/cam_compat.c @@ -1,7 +1,7 @@ /*- * CAM ioctl compatibility shims * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2013 Scott Long * All rights reserved. @@ -29,9 +29,6 @@ * */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/types.h> @@ -52,8 +49,6 @@ __FBSDID("$FreeBSD$"); #include <cam/scsi/scsi_pass.h> -#include "opt_cam.h" - static int cam_compat_handle_0x17(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td, d_ioctl_t *cbfnp); static int cam_compat_handle_0x18(struct cdev *dev, u_long cmd, caddr_t addr, @@ -216,8 +211,8 @@ cam_compat_handle_0x17(struct cdev *dev, u_long cmd, caddr_t addr, int flag, cpi17 = (struct ccb_pathinq_0x17 *)hdr17; cpi17->version_num = cpi->version_num; cpi17->hba_inquiry = cpi->hba_inquiry; - cpi17->target_sprt = (u_int8_t)cpi->target_sprt; - cpi17->hba_misc = (u_int8_t)cpi->hba_misc; + cpi17->target_sprt = (uint8_t)cpi->target_sprt; + cpi17->hba_misc = (uint8_t)cpi->hba_misc; cpi17->hba_eng_cnt = cpi->hba_eng_cnt; bcopy(&cpi->vuhba_flags[0], &cpi17->vuhba_flags[0], VUHBALEN); cpi17->max_target = cpi->max_target; @@ -382,11 +377,13 @@ cam_compat_translate_dev_match_0x18(union ccb *ccb) struct dev_match_result *dm; struct dev_match_result_0x18 *dm18; struct cam_periph_map_info mapinfo; - int i; + int error, i; /* Remap the CCB into kernel address space */ bzero(&mapinfo, sizeof(mapinfo)); - cam_periph_mapmem(ccb, &mapinfo, maxphys); + error = cam_periph_mapmem(ccb, &mapinfo, maxphys); + if (error != 0) + return (error); dm = ccb->cdm.matches; /* Translate in-place: old fields are smaller */ @@ -434,21 +431,22 @@ cam_compat_translate_dev_match_0x18(union ccb *ccb) } } - cam_periph_unmapmem(ccb, &mapinfo); - - return (0); + return (cam_periph_unmapmem(ccb, &mapinfo)); } static int cam_compat_handle_0x19(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td, d_ioctl_t *cbfnp) { + struct cam_periph_map_info mapinfo; union ccb *ccb = (union ccb *)addr; - struct cam_periph_map_info mapinfo; + int error; if (cmd == CAMIOCOMMAND && ccb->ccb_h.func_code == XPT_DEV_MATCH) { bzero(&mapinfo, sizeof(mapinfo)); - cam_periph_mapmem(ccb, &mapinfo, maxphys); + error = cam_periph_mapmem(ccb, &mapinfo, maxphys); + if (error != 0) + return (error); for (int i = 0; i < ccb->cdm.num_patterns; i++) { struct dev_match_pattern *p = &ccb->cdm.patterns[i]; @@ -462,7 +460,9 @@ cam_compat_handle_0x19(struct cdev *dev, u_long cmd, caddr_t addr, int flag, p->pattern.periph_pattern.flags == 0x01f) p->pattern.periph_pattern.flags = PERIPH_MATCH_ANY; } - cam_periph_unmapmem(ccb, &mapinfo); + error = cam_periph_unmapmem(ccb, &mapinfo); + if (error != 0) + return (error); } return ((cbfnp)(dev, cmd, addr, flag, td)); } diff --git a/sys/cam/cam_compat.h b/sys/cam/cam_compat.h index 9a1996d230ce..37bb4a62fd87 100644 --- a/sys/cam/cam_compat.h +++ b/sys/cam/cam_compat.h @@ -1,7 +1,7 @@ /*- * CAM ioctl compatibility shims * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2013 Scott Long * All rights reserved. @@ -26,8 +26,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _CAM_CAM_COMPAT_H @@ -59,41 +57,41 @@ struct ccb_hdr_0x17 { camq_entry xpt_links; /* For chaining in the XPT layer */ camq_entry sim_links; /* For chaining in the SIM layer */ camq_entry periph_links; /* For chaining in the type driver */ - u_int32_t retry_count; + uint32_t retry_count; void (*cbfcnp)(struct cam_periph *, union ccb *); xpt_opcode func_code; /* XPT function code */ - u_int32_t status; /* Status returned by CAM subsystem */ + uint32_t status; /* Status returned by CAM subsystem */ struct cam_path *path; /* Compiled path for this ccb */ path_id_t path_id; /* Path ID for the request */ target_id_t target_id; /* Target device ID */ u_int target_lun; /* Target LUN number */ - u_int32_t flags; /* ccb_flags */ + uint32_t flags; /* ccb_flags */ ccb_ppriv_area periph_priv; ccb_spriv_area sim_priv; - u_int32_t timeout; /* Hard timeout value in seconds */ + uint32_t timeout; /* Hard timeout value in seconds */ struct callout *timeout_ch; }; struct ccb_pathinq_0x17 { struct ccb_hdr_0x17 ccb_h; - u_int8_t version_num; /* Version number for the SIM/HBA */ - u_int8_t hba_inquiry; /* Mimic of INQ byte 7 for the HBA */ - u_int8_t target_sprt; /* Flags for target mode support */ - u_int8_t hba_misc; /* Misc HBA features */ - u_int16_t hba_eng_cnt; /* HBA engine count */ + uint8_t version_num; /* Version number for the SIM/HBA */ + uint8_t hba_inquiry; /* Mimic of INQ byte 7 for the HBA */ + uint8_t target_sprt; /* Flags for target mode support */ + uint8_t hba_misc; /* Misc HBA features */ + uint16_t hba_eng_cnt; /* HBA engine count */ /* Vendor Unique capabilities */ - u_int8_t vuhba_flags[VUHBALEN]; - u_int32_t max_target; /* Maximum supported Target */ - u_int32_t max_lun; /* Maximum supported Lun */ - u_int32_t async_flags; /* Installed Async handlers */ + uint8_t vuhba_flags[VUHBALEN]; + uint32_t max_target; /* Maximum supported Target */ + uint32_t max_lun; /* Maximum supported Lun */ + uint32_t async_flags; /* Installed Async handlers */ path_id_t hpath_id; /* Highest Path ID in the subsystem */ target_id_t initiator_id; /* ID of the HBA on the SCSI bus */ char sim_vid[SIM_IDLEN]; /* Vendor ID of the SIM */ char hba_vid[HBA_IDLEN]; /* Vendor ID of the HBA */ char dev_name[DEV_IDLEN];/* Device name for SIM */ - u_int32_t unit_number; /* Unit number for SIM */ - u_int32_t bus_id; /* Bus ID for SIM */ - u_int32_t base_transfer_speed;/* Base bus speed in KB/sec */ + uint32_t unit_number; /* Unit number for SIM */ + uint32_t bus_id; /* Bus ID for SIM */ + uint32_t base_transfer_speed;/* Base bus speed in KB/sec */ cam_proto protocol; u_int protocol_version; cam_xport transport; @@ -105,10 +103,10 @@ struct ccb_pathinq_0x17 { char ccb_pathinq_settings_opaque[PATHINQ_SETTINGS_SIZE]; } xport_specific; u_int maxio; /* Max supported I/O size, in bytes. */ - u_int16_t hba_vendor; /* HBA vendor ID */ - u_int16_t hba_device; /* HBA device ID */ - u_int16_t hba_subvendor; /* HBA subvendor ID */ - u_int16_t hba_subdevice; /* HBA subdevice ID */ + uint16_t hba_vendor; /* HBA vendor ID */ + uint16_t hba_device; /* HBA device ID */ + uint16_t hba_subvendor; /* HBA subvendor ID */ + uint16_t hba_subdevice; /* HBA subdevice ID */ }; struct ccb_trans_settings_0x17 { @@ -147,21 +145,21 @@ struct ccb_hdr_0x18 { camq_entry xpt_links; /* For chaining in the XPT layer */ camq_entry sim_links; /* For chaining in the SIM layer */ camq_entry periph_links; /* For chaining in the type driver */ - u_int32_t retry_count; + uint32_t retry_count; void (*cbfcnp)(struct cam_periph *, union ccb *); xpt_opcode func_code; /* XPT function code */ - u_int32_t status; /* Status returned by CAM subsystem */ + uint32_t status; /* Status returned by CAM subsystem */ struct cam_path *path; /* Compiled path for this ccb */ path_id_t path_id; /* Path ID for the request */ target_id_t target_id; /* Target device ID */ u_int target_lun; /* Target LUN number */ - u_int64_t ext_lun; /* 64-bit LUN, more or less */ - u_int32_t flags; /* ccb_flags */ - u_int32_t xflags; /* extended ccb_flags */ + uint64_t ext_lun; /* 64-bit LUN, more or less */ + uint32_t flags; /* ccb_flags */ + uint32_t xflags; /* extended ccb_flags */ ccb_ppriv_area periph_priv; ccb_spriv_area sim_priv; ccb_qos_area qos; - u_int32_t timeout; /* Hard timeout value in seconds */ + uint32_t timeout; /* Hard timeout value in seconds */ struct timeval softtimeout; /* Soft timeout value in sec + usec */ }; @@ -196,7 +194,7 @@ struct dev_match_result_0x18 { union { struct { char periph_name[DEV_IDLEN]; - u_int32_t unit_number; + uint32_t unit_number; path_id_t path_id; target_id_t target_id; u_int target_lun; diff --git a/sys/cam/cam_debug.h b/sys/cam/cam_debug.h index fcea93401632..8c04b1fd7ce9 100644 --- a/sys/cam/cam_debug.h +++ b/sys/cam/cam_debug.h @@ -1,7 +1,7 @@ /*- * Macros for tracing/loging information in the CAM layer * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997 Justin T. Gibbs. * All rights reserved. @@ -26,8 +26,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _CAM_CAM_DEBUG_H #define _CAM_CAM_DEBUG_H 1 @@ -79,61 +77,50 @@ typedef enum { /* Path we want to debug */ extern struct cam_path *cam_dpath; /* Current debug levels set */ -extern u_int32_t cam_dflags; +extern uint32_t cam_dflags; /* Printf delay value (to prevent scrolling) */ -extern u_int32_t cam_debug_delay; +extern uint32_t cam_debug_delay; -/* Debugging macros. */ -#define CAM_DEBUGGED(path, flag) \ - (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags) \ - && (cam_dpath != NULL) \ - && (xpt_path_comp(cam_dpath, path) >= 0) \ - && (xpt_path_comp(cam_dpath, path) < 2)) - -#define CAM_DEBUG(path, flag, printfargs) \ - if (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags) \ - && (cam_dpath != NULL) \ - && (xpt_path_comp(cam_dpath, path) >= 0) \ - && (xpt_path_comp(cam_dpath, path) < 2)) { \ - xpt_print_path(path); \ - printf printfargs; \ - if (cam_debug_delay != 0) \ - DELAY(cam_debug_delay); \ - } +/* Helper routines -- helps conserve stack */ +struct cam_ed; +void xpt_cam_path_debug(struct cam_path *path, const char *fmt, ...); +void xpt_cam_dev_debug(struct cam_ed *dev, const char *fmt, ...); +void xpt_cam_debug(const char *fmt, ...); -#define CAM_DEBUG_DEV(dev, flag, printfargs) \ - if (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags) \ - && (cam_dpath != NULL) \ - && (xpt_path_comp_dev(cam_dpath, dev) >= 0) \ - && (xpt_path_comp_dev(cam_dpath, dev) < 2)) { \ - xpt_print_device(dev); \ - printf printfargs; \ - if (cam_debug_delay != 0) \ - DELAY(cam_debug_delay); \ +/* Stupid macro to remove a layer of parens */ +#define _CAM_X(...) __VA_ARGS__ + +/* Debugging macros. */ +#define CAM_DEBUGGED(path, flag) \ + (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags) \ + && (cam_dpath != NULL) \ + && (xpt_path_comp(cam_dpath, (path)) >= 0) \ + && (xpt_path_comp(cam_dpath, (path)) < 2)) + +#define CAM_DEBUG(path, flag, printfargs) \ + if (CAM_DEBUGGED(path, flag)) { \ + xpt_cam_path_debug(path, _CAM_X printfargs); \ } -#define CAM_DEBUG_PRINT(flag, printfargs) \ - if (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags)) { \ - printf("cam_debug: "); \ - printf printfargs; \ - if (cam_debug_delay != 0) \ - DELAY(cam_debug_delay); \ +#define CAM_DEBUG_DEV(dev, flag, printfargs) \ + if (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags) \ + && (cam_dpath != NULL) \ + && (xpt_path_comp_dev(cam_dpath, (dev)) >= 0) \ + && (xpt_path_comp_dev(cam_dpath, (dev)) < 2)) { \ + xpt_cam_dev_debug(dev, _CAM_X printfargs); \ } -#define CAM_DEBUG_PATH_PRINT(flag, path, printfargs) \ - if (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags)) { \ - xpt_print(path, "cam_debug: "); \ - printf printfargs; \ - if (cam_debug_delay != 0) \ - DELAY(cam_debug_delay); \ +#define CAM_DEBUG_PRINT(flag, printfargs) \ + if (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags)) { \ + xpt_cam_debug(_CAM_X printfargs); \ } #else /* !_KERNEL */ #define CAM_DEBUGGED(A, B) 0 #define CAM_DEBUG(A, B, C) +#define CAM_DEBUG_DEV(A, B, C) #define CAM_DEBUG_PRINT(A, B) -#define CAM_DEBUG_PATH_PRINT(A, B, C) #endif /* _KERNEL */ diff --git a/sys/cam/cam_iosched.c b/sys/cam/cam_iosched.c index d2912b644ada..471e6c355d69 100644 --- a/sys/cam/cam_iosched.c +++ b/sys/cam/cam_iosched.c @@ -1,7 +1,7 @@ /*- * CAM IO Scheduler Interface * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2015 Netflix, Inc. * @@ -9,34 +9,27 @@ * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions, and the following disclaimer, - * without modification, immediately at the beginning of the file. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ -#include "opt_cam.h" #include "opt_ddb.h" -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> - #include <sys/systm.h> #include <sys/kernel.h> #include <sys/bio.h> @@ -74,7 +67,7 @@ static SYSCTL_NODE(_kern_cam, OID_AUTO, iosched, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, #ifdef CAM_IOSCHED_DYNAMIC static bool do_dynamic_iosched = true; -SYSCTL_BOOL(_kern_cam_iosched, OID_AUTO, dynamic, CTLFLAG_RD | CTLFLAG_TUN, +SYSCTL_BOOL(_kern_cam_iosched, OID_AUTO, dynamic, CTLFLAG_RDTUN, &do_dynamic_iosched, 1, "Enable Dynamic I/O scheduler optimizations."); @@ -99,7 +92,7 @@ SYSCTL_BOOL(_kern_cam_iosched, OID_AUTO, dynamic, CTLFLAG_RD | CTLFLAG_TUN, * Note: See computation of EMA and EMVAR for acceptable ranges of alpha. */ static int alpha_bits = 9; -SYSCTL_INT(_kern_cam_iosched, OID_AUTO, alpha_bits, CTLFLAG_RW | CTLFLAG_TUN, +SYSCTL_INT(_kern_cam_iosched, OID_AUTO, alpha_bits, CTLFLAG_RWTUN, &alpha_bits, 1, "Bits in EMA's alpha."); @@ -1077,7 +1070,12 @@ cam_iosched_iop_stats_sysctl_init(struct cam_iosched_softc *isc, struct iop_stat CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, &ios->latencies, 0, cam_iosched_sysctl_latencies, "A", - "Array of power of 2 latency from 1ms to 1.024s"); + "Array of latencies, a geometric progresson from\n" + "kern.cam.iosched.bucket_base_us with a ratio of\n" + "kern.cam.iosched.bucket_ration / 100 from one to\n" + "the next. By default 20 steps from 20us to 10.485s\n" + "by doubling."); + } static void @@ -1636,7 +1634,7 @@ cam_iosched_queue_work(struct cam_iosched_softc *isc, struct bio *bp) { /* - * A BIO_SPEEDUP from the uppper layers means that they have a block + * A BIO_SPEEDUP from the upper layers means that they have a block * shortage. At the present, this is only sent when we're trying to * allocate blocks, but have a shortage before giving up. bio_length is * the size of their shortage. We will complete just enough BIO_DELETEs diff --git a/sys/cam/cam_iosched.h b/sys/cam/cam_iosched.h index 49909351a45a..c8e4341f5095 100644 --- a/sys/cam/cam_iosched.h +++ b/sys/cam/cam_iosched.h @@ -1,7 +1,7 @@ /*- * CAM IO Scheduler Interface * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2015 Netflix, Inc. * @@ -9,24 +9,22 @@ * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions, and the following disclaimer, - * without modification, immediately at the beginning of the file. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _CAM_CAM_IOSCHED_H diff --git a/sys/cam/cam_periph.c b/sys/cam/cam_periph.c index 8c7c6b53b473..e957edee67f1 100644 --- a/sys/cam/cam_periph.c +++ b/sys/cam/cam_periph.c @@ -1,7 +1,7 @@ /*- * Common functions for CAM "type" (peripheral) drivers. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997, 1998 Justin T. Gibbs. * Copyright (c) 1997, 1998, 1999, 2000 Kenneth D. Merry. @@ -29,9 +29,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/types.h> @@ -52,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include <cam/cam.h> #include <cam/cam_ccb.h> +#include <cam/cam_compat.h> #include <cam/cam_queue.h> #include <cam/cam_xpt_periph.h> #include <cam/cam_xpt_internal.h> @@ -77,20 +75,20 @@ static void camperiphfree(struct cam_periph *periph); static int camperiphscsistatuserror(union ccb *ccb, union ccb **orig_ccb, cam_flags camflags, - u_int32_t sense_flags, + uint32_t sense_flags, int *openings, - u_int32_t *relsim_flags, - u_int32_t *timeout, - u_int32_t *action, + uint32_t *relsim_flags, + uint32_t *timeout, + uint32_t *action, const char **action_string); static int camperiphscsisenseerror(union ccb *ccb, union ccb **orig_ccb, cam_flags camflags, - u_int32_t sense_flags, + uint32_t sense_flags, int *openings, - u_int32_t *relsim_flags, - u_int32_t *timeout, - u_int32_t *action, + uint32_t *relsim_flags, + uint32_t *timeout, + uint32_t *action, const char **action_string); static void cam_periph_devctl_notify(union ccb *ccb); @@ -530,6 +528,20 @@ cam_periph_unhold(struct cam_periph *periph) cam_periph_release_locked(periph); } +void +cam_periph_hold_boot(struct cam_periph *periph) +{ + + root_mount_hold_token(periph->periph_name, &periph->periph_rootmount); +} + +void +cam_periph_release_boot(struct cam_periph *periph) +{ + + root_mount_rel(&periph->periph_rootmount); +} + /* * Look for the next unit number that is not currently in use for this * peripheral type starting at "newunit". Also exclude unit numbers that @@ -794,9 +806,9 @@ cam_periph_mapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo, u_int maxmap) { int numbufs, i; - u_int8_t **data_ptrs[CAM_PERIPH_MAXMAPS]; - u_int32_t lengths[CAM_PERIPH_MAXMAPS]; - u_int32_t dirs[CAM_PERIPH_MAXMAPS]; + uint8_t **data_ptrs[CAM_PERIPH_MAXMAPS]; + uint32_t lengths[CAM_PERIPH_MAXMAPS]; + uint32_t dirs[CAM_PERIPH_MAXMAPS]; bzero(mapinfo, sizeof(*mapinfo)); if (maxmap == 0) @@ -811,15 +823,15 @@ cam_periph_mapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo, return(EINVAL); } if (ccb->cdm.pattern_buf_len > 0) { - data_ptrs[0] = (u_int8_t **)&ccb->cdm.patterns; + data_ptrs[0] = (uint8_t **)&ccb->cdm.patterns; lengths[0] = ccb->cdm.pattern_buf_len; dirs[0] = CAM_DIR_OUT; - data_ptrs[1] = (u_int8_t **)&ccb->cdm.matches; + data_ptrs[1] = (uint8_t **)&ccb->cdm.matches; lengths[1] = ccb->cdm.match_buf_len; dirs[1] = CAM_DIR_IN; numbufs = 2; } else { - data_ptrs[0] = (u_int8_t **)&ccb->cdm.matches; + data_ptrs[0] = (uint8_t **)&ccb->cdm.matches; lengths[0] = ccb->cdm.match_buf_len; dirs[0] = CAM_DIR_IN; numbufs = 1; @@ -1001,31 +1013,31 @@ fail: * Unmap memory segments mapped into kernel virtual address space by * cam_periph_mapmem(). */ -void +int cam_periph_unmapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo) { - int numbufs, i; - u_int8_t **data_ptrs[CAM_PERIPH_MAXMAPS]; - u_int32_t lengths[CAM_PERIPH_MAXMAPS]; - u_int32_t dirs[CAM_PERIPH_MAXMAPS]; + int error, numbufs, i; + uint8_t **data_ptrs[CAM_PERIPH_MAXMAPS]; + uint32_t lengths[CAM_PERIPH_MAXMAPS]; + uint32_t dirs[CAM_PERIPH_MAXMAPS]; if (mapinfo->num_bufs_used <= 0) { /* nothing to free and the process wasn't held. */ - return; + return (0); } switch (ccb->ccb_h.func_code) { case XPT_DEV_MATCH: if (ccb->cdm.pattern_buf_len > 0) { - data_ptrs[0] = (u_int8_t **)&ccb->cdm.patterns; + data_ptrs[0] = (uint8_t **)&ccb->cdm.patterns; lengths[0] = ccb->cdm.pattern_buf_len; dirs[0] = CAM_DIR_OUT; - data_ptrs[1] = (u_int8_t **)&ccb->cdm.matches; + data_ptrs[1] = (uint8_t **)&ccb->cdm.matches; lengths[1] = ccb->cdm.match_buf_len; dirs[1] = CAM_DIR_IN; numbufs = 2; } else { - data_ptrs[0] = (u_int8_t **)&ccb->cdm.matches; + data_ptrs[0] = (uint8_t **)&ccb->cdm.matches; lengths[0] = ccb->cdm.match_buf_len; dirs[0] = CAM_DIR_IN; numbufs = 1; @@ -1045,10 +1057,10 @@ cam_periph_unmapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo) numbufs = 1; break; case XPT_MMC_IO: - data_ptrs[0] = (u_int8_t **)&ccb->mmcio.cmd.data; + data_ptrs[0] = (uint8_t **)&ccb->mmcio.cmd.data; lengths[0] = sizeof(struct mmc_data *); dirs[0] = ccb->ccb_h.flags & CAM_DIR_MASK; - data_ptrs[1] = (u_int8_t **)&ccb->mmcio.cmd.data->data; + data_ptrs[1] = (uint8_t **)&ccb->mmcio.cmd.data->data; lengths[1] = ccb->mmcio.cmd.data->len; dirs[1] = ccb->ccb_h.flags & CAM_DIR_MASK; numbufs = 2; @@ -1076,12 +1088,11 @@ cam_periph_unmapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo) numbufs = 1; break; default: - /* allow ourselves to be swapped once again */ - PRELE(curproc); - return; - break; /* NOTREACHED */ + numbufs = 0; + break; } + error = 0; for (i = 0; i < numbufs; i++) { if (mapinfo->bp[i]) { /* unmap the buffer */ @@ -1091,8 +1102,12 @@ cam_periph_unmapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo) uma_zfree(pbuf_zone, mapinfo->bp[i]); } else { if (dirs[i] != CAM_DIR_OUT) { - copyout(*data_ptrs[i], mapinfo->orig[i], + int error1; + + error1 = copyout(*data_ptrs[i], mapinfo->orig[i], lengths[i]); + if (error == 0) + error = error1; } free(*data_ptrs[i], M_CAMPERIPH); } @@ -1103,13 +1118,15 @@ cam_periph_unmapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo) /* allow ourselves to be swapped once again */ PRELE(curproc); + + return (error); } int cam_periph_ioctl(struct cam_periph *periph, u_long cmd, caddr_t addr, int (*error_routine)(union ccb *ccb, cam_flags camflags, - u_int32_t sense_flags)) + uint32_t sense_flags)) { union ccb *ccb; int error; @@ -1118,6 +1135,7 @@ cam_periph_ioctl(struct cam_periph *periph, u_long cmd, caddr_t addr, error = found = 0; switch(cmd){ + case CAMGETPASSTHRU_0x19: case CAMGETPASSTHRU: ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL); xpt_setup_ccb(&ccb->ccb_h, @@ -1207,8 +1225,8 @@ int cam_periph_runccb(union ccb *ccb, int (*error_routine)(union ccb *ccb, cam_flags camflags, - u_int32_t sense_flags), - cam_flags camflags, u_int32_t sense_flags, + uint32_t sense_flags), + cam_flags camflags, uint32_t sense_flags, struct devstat *ds) { struct bintime *starttime; @@ -1246,7 +1264,7 @@ cam_periph_runccb(union ccb *ccb, * shutdown_post_sync event will run with the scheduler stopped, but * before we're officially dumping. To avoid hanging in adashutdown * initiated commands (or other similar situations), we have to test for - * either SCHEDULER_STOPPED() here as well. + * either dumping or SCHEDULER_STOPPED() here. * * To avoid locking problems, dumping/polling callers must call * without a periph lock held. @@ -1282,6 +1300,11 @@ cam_periph_runccb(union ccb *ccb, if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) error = 0; else if (error_routine != NULL) { + /* + * cbfcnp is modified by cam_periph_ccbwait so + * reset it before we call the error routine + * which may call xpt_done. + */ ccb->ccb_h.cbfcnp = cam_periph_done; error = (*error_routine)(ccb, camflags, sense_flags); } else @@ -1338,9 +1361,9 @@ cam_freeze_devq(struct cam_path *path) xpt_action((union ccb *)&ccb_h); } -u_int32_t -cam_release_devq(struct cam_path *path, u_int32_t relsim_flags, - u_int32_t openings, u_int32_t arg, +uint32_t +cam_release_devq(struct cam_path *path, uint32_t relsim_flags, + uint32_t openings, uint32_t arg, int getcount_only) { struct ccb_relsim crs; @@ -1366,7 +1389,7 @@ camperiphdone(struct cam_periph *periph, union ccb *done_ccb) cam_status status; struct scsi_start_stop_unit *scsi_cmd; int error = 0, error_code, sense_key, asc, ascq; - u_int16_t done_flags; + uint16_t done_flags; scsi_cmd = (struct scsi_start_stop_unit *) &done_ccb->csio.cdb_io.cdb_bytes; @@ -1464,7 +1487,7 @@ out: * and leave the rest to this function. */ void -cam_periph_async(struct cam_periph *periph, u_int32_t code, +cam_periph_async(struct cam_periph *periph, uint32_t code, struct cam_path *path, void *arg) { switch (code) { @@ -1519,9 +1542,9 @@ cam_periph_freeze_after_event(struct cam_periph *periph, static int camperiphscsistatuserror(union ccb *ccb, union ccb **orig_ccb, - cam_flags camflags, u_int32_t sense_flags, - int *openings, u_int32_t *relsim_flags, - u_int32_t *timeout, u_int32_t *action, const char **action_string) + cam_flags camflags, uint32_t sense_flags, + int *openings, uint32_t *relsim_flags, + uint32_t *timeout, uint32_t *action, const char **action_string) { struct cam_periph *periph; int error; @@ -1634,14 +1657,14 @@ camperiphscsistatuserror(union ccb *ccb, union ccb **orig_ccb, static int camperiphscsisenseerror(union ccb *ccb, union ccb **orig, - cam_flags camflags, u_int32_t sense_flags, - int *openings, u_int32_t *relsim_flags, - u_int32_t *timeout, u_int32_t *action, const char **action_string) + cam_flags camflags, uint32_t sense_flags, + int *openings, uint32_t *relsim_flags, + uint32_t *timeout, uint32_t *action, const char **action_string) { struct cam_periph *periph; union ccb *orig_ccb = ccb; int error, recoveryccb; - u_int16_t flags; + uint16_t flags; #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING) if (ccb->ccb_h.func_code == XPT_SCSI_IO && ccb->csio.bio != NULL) @@ -1858,7 +1881,7 @@ sense_error_done: */ int cam_periph_error(union ccb *ccb, cam_flags camflags, - u_int32_t sense_flags) + uint32_t sense_flags) { struct cam_path *newpath; union ccb *orig_ccb, *scan_ccb; @@ -1866,7 +1889,7 @@ cam_periph_error(union ccb *ccb, cam_flags camflags, const char *action_string; cam_status status; int frozen, error, openings, devctl_err; - u_int32_t action, relsim_flags, timeout; + uint32_t action, relsim_flags, timeout; action = SSQ_PRINT_SENSE; periph = xpt_path_periph(ccb->ccb_h.path); @@ -1888,6 +1911,8 @@ cam_periph_error(union ccb *ccb, cam_flags camflags, case CAM_SCSI_STATUS_ERROR: case CAM_ATA_STATUS_ERROR: case CAM_SMP_STATUS_ERROR: + case CAM_DEV_NOT_THERE: + case CAM_NVME_STATUS_ERROR: devctl_err++; break; default: @@ -1980,6 +2005,8 @@ cam_periph_error(union ccb *ccb, cam_flags camflags, relsim_flags = RELSIM_RELEASE_AFTER_TIMEOUT; /* FALLTHROUGH */ case CAM_ATA_STATUS_ERROR: + case CAM_NVME_STATUS_ERROR: + case CAM_SMP_STATUS_ERROR: case CAM_REQ_CMP_ERR: case CAM_CMD_TIMEOUT: case CAM_UNEXP_BUSFREE: @@ -2117,7 +2144,7 @@ cam_periph_devctl_notify(union ccb *ccb) sbuf_printf(&sb, "device=%s%d ", periph->periph_name, periph->unit_number); - sbuf_printf(&sb, "serial=\""); + sbuf_cat(&sb, "serial=\""); if ((cgd = (struct ccb_getdev *)xpt_alloc_ccb_nowait()) != NULL) { xpt_setup_ccb(&cgd->ccb_h, ccb->ccb_h.path, CAM_PRIORITY_NORMAL); @@ -2128,7 +2155,7 @@ cam_periph_devctl_notify(union ccb *ccb) sbuf_bcat(&sb, cgd->serial_num, cgd->serial_num_len); xpt_free_ccb((union ccb *)cgd); } - sbuf_printf(&sb, "\" "); + sbuf_cat(&sb, "\" "); sbuf_printf(&sb, "cam_status=\"0x%x\" ", ccb->ccb_h.status); switch (ccb->ccb_h.status & CAM_STATUS_MASK) { @@ -2144,24 +2171,54 @@ cam_periph_devctl_notify(union ccb *ccb) type = "error"; break; case CAM_ATA_STATUS_ERROR: - sbuf_printf(&sb, "RES=\""); + sbuf_cat(&sb, "RES=\""); ata_res_sbuf(&ccb->ataio.res, &sb); - sbuf_printf(&sb, "\" "); + sbuf_cat(&sb, "\" "); type = "error"; break; + case CAM_NVME_STATUS_ERROR: + { + struct ccb_nvmeio *n = &ccb->nvmeio; + + sbuf_printf(&sb, "sc=\"%02x\" sct=\"%02x\" cdw0=\"%08x\" ", + NVME_STATUS_GET_SC(n->cpl.status), + NVME_STATUS_GET_SCT(n->cpl.status), n->cpl.cdw0); + type = "error"; + break; + } default: type = "error"; break; } - if (ccb->ccb_h.func_code == XPT_SCSI_IO) { - sbuf_printf(&sb, "CDB=\""); + + switch (ccb->ccb_h.func_code) { + case XPT_SCSI_IO: + sbuf_cat(&sb, "CDB=\""); scsi_cdb_sbuf(scsiio_cdb_ptr(&ccb->csio), &sb); - sbuf_printf(&sb, "\" "); - } else if (ccb->ccb_h.func_code == XPT_ATA_IO) { - sbuf_printf(&sb, "ACB=\""); + sbuf_cat(&sb, "\" "); + break; + case XPT_ATA_IO: + sbuf_cat(&sb, "ACB=\""); ata_cmd_sbuf(&ccb->ataio.cmd, &sb); - sbuf_printf(&sb, "\" "); + sbuf_cat(&sb, "\" "); + break; + case XPT_NVME_IO: + case XPT_NVME_ADMIN: + { + struct ccb_nvmeio *n = &ccb->nvmeio; + struct nvme_command *cmd = &n->cmd; + + // XXX Likely should be nvme_cmd_sbuf + sbuf_printf(&sb, "opc=\"%02x\" fuse=\"%02x\" cid=\"%04x\" " + "nsid=\"%08x\" cdw10=\"%08x\" cdw11=\"%08x\" cdw12=\"%08x\" " + "cdw13=\"%08x\" cdw14=\"%08x\" cdw15=\"%08x\" ", + cmd->opc, cmd->fuse, cmd->cid, cmd->nsid, cmd->cdw10, + cmd->cdw11, cmd->cdw12, cmd->cdw13, cmd->cdw14, cmd->cdw15); + break; + } + default: + break; } if (sbuf_finish(&sb) == 0) diff --git a/sys/cam/cam_periph.h b/sys/cam/cam_periph.h index 9c323394797c..ad18ee6b204c 100644 --- a/sys/cam/cam_periph.h +++ b/sys/cam/cam_periph.h @@ -1,7 +1,7 @@ /*- * Data structures and definitions for CAM peripheral ("type") drivers. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997, 1998 Justin T. Gibbs. * All rights reserved. @@ -26,8 +26,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _CAM_CAM_PERIPH_H @@ -124,9 +122,9 @@ struct cam_periph { struct cam_path *path; /* Compiled path to device */ void *softc; struct cam_sim *sim; - u_int32_t unit_number; + uint32_t unit_number; cam_periph_type type; - u_int32_t flags; + uint32_t flags; #define CAM_PERIPH_RUNNING 0x01 #define CAM_PERIPH_LOCKED 0x02 #define CAM_PERIPH_LOCK_WANTED 0x04 @@ -142,7 +140,7 @@ struct cam_periph { uint32_t immediate_priority; int periph_allocating; int periph_allocated; - u_int32_t refcount; + uint32_t refcount; SLIST_HEAD(, ccb_hdr) ccb_list; /* For "immediate" requests */ SLIST_ENTRY(cam_periph) periph_links; TAILQ_ENTRY(cam_periph) unit_links; @@ -150,6 +148,7 @@ struct cam_periph { ac_code deferred_ac; struct task periph_run_task; uma_zone_t ccb_zone; + struct root_hold_token periph_rootmount; }; #define CAM_PERIPH_MAXMAPS 2 @@ -175,30 +174,32 @@ void cam_periph_release_locked(struct cam_periph *periph); void cam_periph_release_locked_buses(struct cam_periph *periph); int cam_periph_hold(struct cam_periph *periph, int priority); void cam_periph_unhold(struct cam_periph *periph); +void cam_periph_hold_boot(struct cam_periph *periph); +void cam_periph_release_boot(struct cam_periph *periph); void cam_periph_invalidate(struct cam_periph *periph); int cam_periph_mapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo, u_int maxmap); -void cam_periph_unmapmem(union ccb *ccb, +int cam_periph_unmapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo); union ccb *cam_periph_getccb(struct cam_periph *periph, - u_int32_t priority); + uint32_t priority); int cam_periph_runccb(union ccb *ccb, int (*error_routine)(union ccb *ccb, cam_flags camflags, - u_int32_t sense_flags), - cam_flags camflags, u_int32_t sense_flags, + uint32_t sense_flags), + cam_flags camflags, uint32_t sense_flags, struct devstat *ds); int cam_periph_ioctl(struct cam_periph *periph, u_long cmd, caddr_t addr, int (*error_routine)(union ccb *ccb, cam_flags camflags, - u_int32_t sense_flags)); + uint32_t sense_flags)); void cam_freeze_devq(struct cam_path *path); -u_int32_t cam_release_devq(struct cam_path *path, u_int32_t relsim_flags, - u_int32_t opening_reduction, u_int32_t arg, +uint32_t cam_release_devq(struct cam_path *path, uint32_t relsim_flags, + uint32_t opening_reduction, uint32_t arg, int getcount_only); -void cam_periph_async(struct cam_periph *periph, u_int32_t code, +void cam_periph_async(struct cam_periph *periph, uint32_t code, struct cam_path *path, void *arg); void cam_periph_bus_settle(struct cam_periph *periph, u_int bus_settle_ms); @@ -206,7 +207,7 @@ void cam_periph_freeze_after_event(struct cam_periph *periph, struct timeval* event_time, u_int duration_ms); int cam_periph_error(union ccb *ccb, cam_flags camflags, - u_int32_t sense_flags); + uint32_t sense_flags); int cam_periph_invalidate_sysctl(SYSCTL_HANDLER_ARGS); static __inline struct mtx * diff --git a/sys/cam/cam_queue.c b/sys/cam/cam_queue.c index 98d03283b80b..5f9aa35642de 100644 --- a/sys/cam/cam_queue.c +++ b/sys/cam/cam_queue.c @@ -1,7 +1,7 @@ /*- * CAM request queue management functions. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997 Justin T. Gibbs. * All rights reserved. @@ -28,9 +28,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/types.h> @@ -84,7 +81,7 @@ camq_fini(struct camq *queue) } } -u_int32_t +uint32_t camq_resize(struct camq *queue, int new_size) { cam_pinfo **new_array; @@ -166,7 +163,7 @@ camq_remove(struct camq *queue, int index) * element index and restore the Heap(0, num_elements) property. */ void -camq_change_priority(struct camq *queue, int index, u_int32_t new_priority) +camq_change_priority(struct camq *queue, int index, uint32_t new_priority) { if (new_priority > queue->queue_array[index]->priority) { queue->queue_array[index]->priority = new_priority; @@ -217,10 +214,10 @@ cam_devq_free(struct cam_devq *devq) free(devq, M_CAMDEVQ); } -u_int32_t +uint32_t cam_devq_resize(struct cam_devq *camq, int devices) { - u_int32_t retval; + uint32_t retval; retval = camq_resize(&camq->send_queue, devices); return (retval); @@ -253,7 +250,7 @@ cam_ccbq_free(struct cam_ccbq *ccbq) } } -u_int32_t +uint32_t cam_ccbq_resize(struct cam_ccbq *ccbq, int new_size) { int delta; diff --git a/sys/cam/cam_queue.h b/sys/cam/cam_queue.h index f1055543e768..edf97bd099b5 100644 --- a/sys/cam/cam_queue.h +++ b/sys/cam/cam_queue.h @@ -1,7 +1,7 @@ /*- * CAM request queue management definitions. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997 Justin T. Gibbs. * All rights reserved. @@ -26,8 +26,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _CAM_CAM_QUEUE_H @@ -51,8 +49,8 @@ struct camq { cam_pinfo **queue_array; int array_size; int entries; - u_int32_t generation; - u_int32_t qfrozen_cnt; + uint32_t generation; + uint32_t qfrozen_cnt; }; TAILQ_HEAD(ccb_hdr_tailq, ccb_hdr); @@ -85,14 +83,14 @@ int cam_devq_init(struct cam_devq *devq, int devices, void cam_devq_free(struct cam_devq *devq); -u_int32_t cam_devq_resize(struct cam_devq *camq, int openings); +uint32_t cam_devq_resize(struct cam_devq *camq, int openings); /* * Allocate a cam_ccb_queue structure and initialize it. */ struct cam_ccbq *cam_ccbq_alloc(int openings); -u_int32_t cam_ccbq_resize(struct cam_ccbq *ccbq, int devices); +uint32_t cam_ccbq_resize(struct cam_ccbq *ccbq, int devices); int cam_ccbq_init(struct cam_ccbq *ccbq, int openings); @@ -103,7 +101,7 @@ void cam_ccbq_fini(struct cam_ccbq *ccbq); /* * Resize a cam queue */ -u_int32_t camq_resize(struct camq *queue, int new_size); +uint32_t camq_resize(struct camq *queue, int new_size); /* * Initialize a camq structure. Return 0 on success, 1 on failure. @@ -140,7 +138,7 @@ cam_pinfo *camq_remove(struct camq *queue, int index); * maintaining queue order. */ void camq_change_priority(struct camq *queue, int index, - u_int32_t new_priority); + uint32_t new_priority); static __inline int cam_ccbq_pending_ccb_count(struct cam_ccbq *ccbq) diff --git a/sys/cam/cam_sim.c b/sys/cam/cam_sim.c index 2dbf581712f1..2bb60420ad84 100644 --- a/sys/cam/cam_sim.c +++ b/sys/cam/cam_sim.c @@ -1,7 +1,7 @@ /*- * Common functions for SCSI Interface Modules (SIMs). * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997 Justin T. Gibbs. * All rights reserved. @@ -28,9 +28,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/bus.h> #include <sys/kernel.h> @@ -44,7 +41,7 @@ __FBSDID("$FreeBSD$"); #include <cam/cam_sim.h> #include <cam/cam_xpt.h> -#define CAM_PATH_ANY (u_int32_t)-1 +#define CAM_PATH_ANY (uint32_t)-1 static MALLOC_DEFINE(M_CAMSIM, "CAM SIM", "CAM SIM buffers"); @@ -52,7 +49,7 @@ static struct mtx cam_sim_free_mtx; MTX_SYSINIT(cam_sim_free_init, &cam_sim_free_mtx, "CAM SIM free lock", MTX_DEF); struct cam_devq * -cam_simq_alloc(u_int32_t max_sim_transactions) +cam_simq_alloc(uint32_t max_sim_transactions) { return (cam_devq_alloc(/*size*/0, max_sim_transactions)); } @@ -101,7 +98,7 @@ cam_simq_free(struct cam_devq *devq) */ struct cam_sim * cam_sim_alloc(sim_action_func sim_action, sim_poll_func sim_poll, - const char *sim_name, void *softc, u_int32_t unit, + const char *sim_name, void *softc, uint32_t unit, struct mtx *mtx, int max_dev_transactions, int max_tagged_dev_transactions, struct cam_devq *queue) { @@ -209,7 +206,7 @@ cam_sim_hold(struct cam_sim *sim) } void -cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id) +cam_sim_set_path(struct cam_sim *sim, uint32_t path_id) { sim->path_id = path_id; } diff --git a/sys/cam/cam_sim.h b/sys/cam/cam_sim.h index 54e0ae3ed8d4..d668b9b86c21 100644 --- a/sys/cam/cam_sim.h +++ b/sys/cam/cam_sim.h @@ -1,7 +1,7 @@ /*- * Data structures and definitions for SCSI Interface Modules (SIMs). * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997 Justin T. Gibbs. * All rights reserved. @@ -26,8 +26,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _CAM_CAM_SIM_H @@ -50,23 +48,14 @@ struct cam_devq; typedef void (*sim_action_func)(struct cam_sim *sim, union ccb *ccb); typedef void (*sim_poll_func)(struct cam_sim *sim); -struct cam_devq * cam_simq_alloc(u_int32_t max_sim_transactions); +struct cam_devq * cam_simq_alloc(uint32_t max_sim_transactions); void cam_simq_free(struct cam_devq *devq); struct cam_sim * cam_sim_alloc(sim_action_func sim_action, sim_poll_func sim_poll, const char *sim_name, void *softc, - u_int32_t unit, - struct mtx *mtx, - int max_dev_transactions, - int max_tagged_dev_transactions, - struct cam_devq *queue); -struct cam_sim * cam_sim_alloc_dev(sim_action_func sim_action, - sim_poll_func sim_poll, - const char *sim_name, - void *softc, - device_t dev, + uint32_t unit, struct mtx *mtx, int max_dev_transactions, int max_tagged_dev_transactions, @@ -76,7 +65,7 @@ void cam_sim_hold(struct cam_sim *sim); void cam_sim_release(struct cam_sim *sim); /* Optional sim attributes may be set with these. */ -void cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id); +void cam_sim_set_path(struct cam_sim *sim, uint32_t path_id); /* Generically useful offsets into the sim private area */ #define spriv_ptr0 sim_priv.entries[0].ptr @@ -95,17 +84,17 @@ struct cam_sim { void *softc; struct mtx *mtx; TAILQ_ENTRY(cam_sim) links; - u_int32_t path_id;/* The Boot device may set this to 0? */ - u_int32_t unit_number; - u_int32_t bus_id; + uint32_t path_id;/* The Boot device may set this to 0? */ + uint32_t unit_number; + uint32_t bus_id; int max_tagged_dev_openings; int max_dev_openings; - u_int32_t flags; + uint32_t flags; struct cam_devq *devq; /* Device Queue to use for this SIM */ int refcount; /* References to the SIM. */ }; -static __inline u_int32_t +static __inline uint32_t cam_sim_path(const struct cam_sim *sim) { return (sim->path_id); @@ -123,13 +112,13 @@ cam_sim_softc(const struct cam_sim *sim) return (sim->softc); } -static __inline u_int32_t +static __inline uint32_t cam_sim_unit(const struct cam_sim *sim) { return (sim->unit_number); } -static __inline u_int32_t +static __inline uint32_t cam_sim_bus(const struct cam_sim *sim) { return (sim->bus_id); diff --git a/sys/cam/cam_xpt.c b/sys/cam/cam_xpt.c index f3e9f2772e62..68aa6faae9a3 100644 --- a/sys/cam/cam_xpt.c +++ b/sys/cam/cam_xpt.c @@ -1,7 +1,7 @@ /*- * Implementation of the Common Access Method Transport (XPT) layer. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs. * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry. @@ -31,9 +31,6 @@ #include "opt_printf.h" -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/bio.h> #include <sys/bus.h> @@ -73,8 +70,6 @@ __FBSDID("$FreeBSD$"); #include <machine/stdarg.h> /* for xpt_print below */ -#include "opt_cam.h" - /* Wild guess based on not wanting to grow the stack too much */ #define XPT_PRINT_MAXLEN 512 #ifdef PRINTF_BUFR_SIZE @@ -110,7 +105,6 @@ struct xpt_softc { TAILQ_HEAD(, ccb_hdr) ccb_scanq; int buses_to_config; int buses_config_done; - int announce_nosbuf; /* * Registered buses @@ -168,8 +162,6 @@ SYSCTL_INT(_kern_cam, OID_AUTO, boot_delay, CTLFLAG_RDTUN, &xsoftc.boot_delay, 0, "Bus registration wait time"); SYSCTL_UINT(_kern_cam, OID_AUTO, xpt_generation, CTLFLAG_RD, &xsoftc.xpt_generation, 0, "CAM peripheral generation count"); -SYSCTL_INT(_kern_cam, OID_AUTO, announce_nosbuf, CTLFLAG_RWTUN, - &xsoftc.announce_nosbuf, 0, "Don't use sbuf for announcements"); struct cam_doneq { struct mtx_padalign cam_doneq_mtx; @@ -214,10 +206,10 @@ static struct cdevsw xpt_cdevsw = { /* Storage for debugging datastructures */ struct cam_path *cam_dpath; -u_int32_t __read_mostly cam_dflags = CAM_DEBUG_FLAGS; +uint32_t __read_mostly cam_dflags = CAM_DEBUG_FLAGS; SYSCTL_UINT(_kern_cam, OID_AUTO, dflags, CTLFLAG_RWTUN, &cam_dflags, 0, "Enabled debug flags"); -u_int32_t cam_debug_delay = CAM_DEBUG_DELAY; +uint32_t cam_debug_delay = CAM_DEBUG_DELAY; SYSCTL_UINT(_kern_cam, OID_AUTO, debug_delay, CTLFLAG_RWTUN, &cam_debug_delay, 0, "Delay in us after each debug message"); @@ -236,7 +228,7 @@ DECLARE_MODULE(cam, cam_moduledata, SI_SUB_CONFIGURE, SI_ORDER_SECOND); MODULE_VERSION(cam, 1); static void xpt_async_bcast(struct async_list *async_head, - u_int32_t async_code, + uint32_t async_code, struct cam_path *path, void *async_arg); static path_id_t xptnextfreepathid(void); @@ -265,7 +257,7 @@ static struct cam_ed* static void xpt_config(void *arg); static void xpt_hold_boot_locked(void); static int xpt_schedule_dev(struct camq *queue, cam_pinfo *dev_pinfo, - u_int32_t new_priority); + uint32_t new_priority); static xpt_devicefunc_t xptpassannouncefunc; static void xptaction(struct cam_sim *sim, union ccb *work_ccb); static void xptpoll(struct cam_sim *sim); @@ -311,7 +303,7 @@ static xpt_targetfunc_t xptdeftargetfunc; static xpt_devicefunc_t xptdefdevicefunc; static xpt_periphfunc_t xptdefperiphfunc; static void xpt_finishconfig_task(void *context, int pending); -static void xpt_dev_async_default(u_int32_t async_code, +static void xpt_dev_async_default(uint32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, @@ -571,11 +563,9 @@ xptdoioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread * /* * Map the buffers back into user space. */ - cam_periph_unmapmem(inccb, &mapinfo); + error = cam_periph_unmapmem(inccb, &mapinfo); inccb->ccb_h.path = old_path; - - error = 0; break; } default: @@ -918,6 +908,8 @@ xpt_init(void *dummy) * perform other XPT functions. */ devq = cam_simq_alloc(16); + if (devq == NULL) + return (ENOMEM); xpt_sim = cam_sim_alloc(xptaction, xptpoll, "xpt", @@ -1048,45 +1040,13 @@ xpt_remove_periph(struct cam_periph *periph) void xpt_announce_periph(struct cam_periph *periph, char *announce_string) { - struct cam_path *path = periph->path; - struct xpt_proto *proto; - - cam_periph_assert(periph, MA_OWNED); - periph->flags |= CAM_PERIPH_ANNOUNCED; + char buf[128]; + struct sbuf sb; - printf("%s%d at %s%d bus %d scbus%d target %d lun %jx\n", - periph->periph_name, periph->unit_number, - path->bus->sim->sim_name, - path->bus->sim->unit_number, - path->bus->sim->bus_id, - path->bus->path_id, - path->target->target_id, - (uintmax_t)path->device->lun_id); - printf("%s%d: ", periph->periph_name, periph->unit_number); - proto = xpt_proto_find(path->device->protocol); - if (proto) - proto->ops->announce(path->device); - else - printf("%s%d: Unknown protocol device %d\n", - periph->periph_name, periph->unit_number, - path->device->protocol); - if (path->device->serial_num_len > 0) { - /* Don't wrap the screen - print only the first 60 chars */ - printf("%s%d: Serial Number %.60s\n", periph->periph_name, - periph->unit_number, path->device->serial_num); - } - /* Announce transport details. */ - path->bus->xport->ops->announce(periph); - /* Announce command queueing. */ - if (path->device->inq_flags & SID_CmdQue - || path->device->flags & CAM_DEV_TAG_AFTER_COUNT) { - printf("%s%d: Command Queueing enabled\n", - periph->periph_name, periph->unit_number); - } - /* Announce caller's details if they've passed in. */ - if (announce_string != NULL) - printf("%s%d: %s\n", periph->periph_name, - periph->unit_number, announce_string); + (void)sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN | SBUF_INCLUDENUL); + sbuf_set_drain(&sb, sbuf_printf_drain, NULL); + xpt_announce_periph_sbuf(periph, &sb, announce_string); + (void)sbuf_finish(&sb); } void @@ -1099,18 +1059,6 @@ xpt_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb, cam_periph_assert(periph, MA_OWNED); periph->flags |= CAM_PERIPH_ANNOUNCED; - /* Fall back to the non-sbuf method if necessary */ - if (xsoftc.announce_nosbuf != 0) { - xpt_announce_periph(periph, announce_string); - return; - } - proto = xpt_proto_find(path->device->protocol); - if (((proto != NULL) && (proto->ops->announce_sbuf == NULL)) || - (path->bus->xport->ops->announce_sbuf == NULL)) { - xpt_announce_periph(periph, announce_string); - return; - } - sbuf_printf(sb, "%s%d at %s%d bus %d scbus%d target %d lun %jx\n", periph->periph_name, periph->unit_number, path->bus->sim->sim_name, @@ -1120,12 +1068,11 @@ xpt_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb, path->target->target_id, (uintmax_t)path->device->lun_id); sbuf_printf(sb, "%s%d: ", periph->periph_name, periph->unit_number); - + proto = xpt_proto_find(path->device->protocol); if (proto) proto->ops->announce_sbuf(path->device, sb); else - sbuf_printf(sb, "%s%d: Unknown protocol device %d\n", - periph->periph_name, periph->unit_number, + sbuf_printf(sb, "Unknown protocol device %d\n", path->device->protocol); if (path->device->serial_num_len > 0) { /* Don't wrap the screen - print only the first 60 chars */ @@ -1160,11 +1107,6 @@ void xpt_announce_quirks_sbuf(struct cam_periph *periph, struct sbuf *sb, int quirks, char *bit_string) { - if (xsoftc.announce_nosbuf != 0) { - xpt_announce_quirks(periph, quirks, bit_string); - return; - } - if (quirks != 0) { sbuf_printf(sb, "%s%d: quirks=0x%b\n", periph->periph_name, periph->unit_number, quirks, bit_string); @@ -1174,29 +1116,13 @@ xpt_announce_quirks_sbuf(struct cam_periph *periph, struct sbuf *sb, void xpt_denounce_periph(struct cam_periph *periph) { - struct cam_path *path = periph->path; - struct xpt_proto *proto; + char buf[128]; + struct sbuf sb; - cam_periph_assert(periph, MA_OWNED); - printf("%s%d at %s%d bus %d scbus%d target %d lun %jx\n", - periph->periph_name, periph->unit_number, - path->bus->sim->sim_name, - path->bus->sim->unit_number, - path->bus->sim->bus_id, - path->bus->path_id, - path->target->target_id, - (uintmax_t)path->device->lun_id); - printf("%s%d: ", periph->periph_name, periph->unit_number); - proto = xpt_proto_find(path->device->protocol); - if (proto) - proto->ops->denounce(path->device); - else - printf("%s%d: Unknown protocol device %d\n", - periph->periph_name, periph->unit_number, - path->device->protocol); - if (path->device->serial_num_len > 0) - printf(" s/n %.60s", path->device->serial_num); - printf(" detached\n"); + (void)sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN | SBUF_INCLUDENUL); + sbuf_set_drain(&sb, sbuf_printf_drain, NULL); + xpt_denounce_periph_sbuf(periph, &sb); + (void)sbuf_finish(&sb); } void @@ -1207,17 +1133,6 @@ xpt_denounce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb) cam_periph_assert(periph, MA_OWNED); - /* Fall back to the non-sbuf method if necessary */ - if (xsoftc.announce_nosbuf != 0) { - xpt_denounce_periph(periph); - return; - } - proto = xpt_proto_find(path->device->protocol); - if ((proto != NULL) && (proto->ops->denounce_sbuf == NULL)) { - xpt_denounce_periph(periph); - return; - } - sbuf_printf(sb, "%s%d at %s%d bus %d scbus%d target %d lun %jx\n", periph->periph_name, periph->unit_number, path->bus->sim->sim_name, @@ -1227,16 +1142,15 @@ xpt_denounce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb) path->target->target_id, (uintmax_t)path->device->lun_id); sbuf_printf(sb, "%s%d: ", periph->periph_name, periph->unit_number); - + proto = xpt_proto_find(path->device->protocol); if (proto) proto->ops->denounce_sbuf(path->device, sb); else - sbuf_printf(sb, "%s%d: Unknown protocol device %d\n", - periph->periph_name, periph->unit_number, + sbuf_printf(sb, "Unknown protocol device %d", path->device->protocol); if (path->device->serial_num_len > 0) sbuf_printf(sb, " s/n %.60s", path->device->serial_num); - sbuf_printf(sb, " detached\n"); + sbuf_cat(sb, " detached\n"); } int @@ -2953,7 +2867,7 @@ call_sim: struct ccb_setasync *csa; struct async_node *cur_entry; struct async_list *async_head; - u_int32_t added; + uint32_t added; csa = &start_ccb->csa; added = csa->event_enable; @@ -3179,7 +3093,7 @@ xpt_sim_poll(struct cam_sim *sim) uint32_t xpt_poll_setup(union ccb *start_ccb) { - u_int32_t timeout; + uint32_t timeout; struct cam_sim *sim; struct cam_devq *devq; struct cam_ed *dev; @@ -3240,7 +3154,7 @@ xpt_pollwait(union ccb *start_ccb, uint32_t timeout) * target device has space for more transactions. */ void -xpt_schedule(struct cam_periph *periph, u_int32_t new_priority) +xpt_schedule(struct cam_periph *periph, uint32_t new_priority) { CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("xpt_schedule\n")); @@ -3261,10 +3175,10 @@ xpt_schedule(struct cam_periph *periph, u_int32_t new_priority) */ static int xpt_schedule_dev(struct camq *queue, cam_pinfo *pinfo, - u_int32_t new_priority) + uint32_t new_priority) { int retval; - u_int32_t old_priority; + uint32_t old_priority; CAM_DEBUG_PRINT(CAM_DEBUG_XPT, ("xpt_schedule_dev\n")); @@ -3494,7 +3408,7 @@ xpt_merge_ccb(union ccb *dst_ccb, union ccb *src_ccb) void xpt_setup_ccb_flags(struct ccb_hdr *ccb_h, struct cam_path *path, - u_int32_t priority, u_int32_t flags) + uint32_t priority, uint32_t flags) { CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_setup_ccb\n")); @@ -3517,7 +3431,7 @@ xpt_setup_ccb_flags(struct ccb_hdr *ccb_h, struct cam_path *path, } void -xpt_setup_ccb(struct ccb_hdr *ccb_h, struct cam_path *path, u_int32_t priority) +xpt_setup_ccb(struct ccb_hdr *ccb_h, struct cam_path *path, uint32_t priority) { xpt_setup_ccb_flags(ccb_h, path, priority, /*flags*/ 0); } @@ -3795,18 +3709,18 @@ xpt_print_path(struct cam_path *path) sbuf_delete(&sb); } -void -xpt_print_device(struct cam_ed *device) +static void +xpt_device_sbuf(struct cam_ed *device, struct sbuf *sb) { - if (device == NULL) - printf("(nopath): "); + sbuf_cat(sb, "(nopath): "); else { - printf("(noperiph:%s%d:%d:%d:%jx): ", device->sim->sim_name, - device->sim->unit_number, - device->sim->bus_id, - device->target->target_id, - (uintmax_t)device->lun_id); + sbuf_printf(sb, "(noperiph:%s%d:%d:%d:%jx): ", + device->sim->sim_name, + device->sim->unit_number, + device->sim->bus_id, + device->target->target_id, + (uintmax_t)device->lun_id); } } @@ -3829,51 +3743,48 @@ xpt_print(struct cam_path *path, const char *fmt, ...) sbuf_delete(&sb); } -int +char * xpt_path_string(struct cam_path *path, char *str, size_t str_len) { struct sbuf sb; - int len; sbuf_new(&sb, str, str_len, 0); - len = xpt_path_sbuf(path, &sb); + xpt_path_sbuf(path, &sb); sbuf_finish(&sb); - return (len); + return (str); } -int +void xpt_path_sbuf(struct cam_path *path, struct sbuf *sb) { if (path == NULL) - sbuf_printf(sb, "(nopath): "); + sbuf_cat(sb, "(nopath): "); else { if (path->periph != NULL) sbuf_printf(sb, "(%s%d:", path->periph->periph_name, path->periph->unit_number); else - sbuf_printf(sb, "(noperiph:"); + sbuf_cat(sb, "(noperiph:"); if (path->bus != NULL) sbuf_printf(sb, "%s%d:%d:", path->bus->sim->sim_name, path->bus->sim->unit_number, path->bus->sim->bus_id); else - sbuf_printf(sb, "nobus:"); + sbuf_cat(sb, "nobus:"); if (path->target != NULL) sbuf_printf(sb, "%d:", path->target->target_id); else - sbuf_printf(sb, "X:"); + sbuf_cat(sb, "X:"); if (path->device != NULL) sbuf_printf(sb, "%jx): ", (uintmax_t)path->device->lun_id); else - sbuf_printf(sb, "X): "); + sbuf_cat(sb, "X): "); } - - return(sbuf_len(sb)); } path_id_t @@ -4018,7 +3929,14 @@ xpt_bus_register(struct cam_sim *sim, device_t parent, uint32_t bus) xpt_path_inq(&cpi, path); - if (cpi.ccb_h.status == CAM_REQ_CMP) { + /* + * Use the results of PATH_INQ to pick a transport. Note that + * the xpt bus (which uses XPORT_UNSPECIFIED) always uses + * xport_default instead of a transport from + * cam_xpt_port_set. + */ + if (cam_ccb_success((union ccb *)&cpi) && + cpi.transport != XPORT_UNSPECIFIED) { struct xpt_xport **xpt; SET_FOREACH(xpt, cam_xpt_xport_set) { @@ -4027,11 +3945,11 @@ xpt_bus_register(struct cam_sim *sim, device_t parent, uint32_t bus) break; } } - if (new_bus->xport == NULL) { + if (new_bus->xport == &xport_default) { xpt_print(path, "No transport found for %d\n", cpi.transport); xpt_release_bus(new_bus); - free(path, M_CAMXPT); + xpt_free_path(path); return (EINVAL); } } @@ -4158,7 +4076,7 @@ xptpathid(const char *sim_name, int sim_unit, int sim_bus) } static const char * -xpt_async_string(u_int32_t async_code) +xpt_async_string(uint32_t async_code) { switch (async_code) { @@ -4181,7 +4099,7 @@ xpt_async_string(u_int32_t async_code) } static int -xpt_async_size(u_int32_t async_code) +xpt_async_size(uint32_t async_code) { switch (async_code) { @@ -4209,7 +4127,7 @@ xpt_async_process_dev(struct cam_ed *device, void *arg) union ccb *ccb = arg; struct cam_path *path = ccb->ccb_h.path; void *async_arg = ccb->casync.async_arg_ptr; - u_int32_t async_code = ccb->casync.async_code; + uint32_t async_code = ccb->casync.async_code; bool relock; if (path->device != device @@ -4278,7 +4196,7 @@ xpt_async_process(struct cam_periph *periph, union ccb *ccb) struct cam_eb *bus; struct cam_path *path; void *async_arg; - u_int32_t async_code; + uint32_t async_code; path = ccb->ccb_h.path; async_code = ccb->casync.async_code; @@ -4316,7 +4234,7 @@ xpt_async_process(struct cam_periph *periph, union ccb *ccb) static void xpt_async_bcast(struct async_list *async_head, - u_int32_t async_code, + uint32_t async_code, struct cam_path *path, void *async_arg) { struct async_node *cur_entry; @@ -4347,7 +4265,7 @@ xpt_async_bcast(struct async_list *async_head, } void -xpt_async(u_int32_t async_code, struct cam_path *path, void *async_arg) +xpt_async(uint32_t async_code, struct cam_path *path, void *async_arg) { union ccb *ccb; int size; @@ -4401,7 +4319,7 @@ xpt_async(u_int32_t async_code, struct cam_path *path, void *async_arg) } static void -xpt_dev_async_default(u_int32_t async_code, struct cam_eb *bus, +xpt_dev_async_default(uint32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, void *async_arg) { @@ -4434,7 +4352,7 @@ xpt_freeze_devq_device(struct cam_ed *dev, u_int count) return (freeze); } -u_int32_t +uint32_t xpt_freeze_devq(struct cam_path *path, u_int count) { struct cam_ed *dev = path->device; @@ -4449,7 +4367,7 @@ xpt_freeze_devq(struct cam_path *path, u_int count) return (freeze); } -u_int32_t +uint32_t xpt_freeze_simq(struct cam_sim *sim, u_int count) { struct cam_devq *devq; @@ -4692,7 +4610,7 @@ xpt_get_ccb(struct cam_periph *periph) } union ccb * -cam_periph_getccb(struct cam_periph *periph, u_int32_t priority) +cam_periph_getccb(struct cam_periph *periph, uint32_t priority) { struct ccb_hdr *ccb_h; @@ -4954,7 +4872,7 @@ xpt_release_device(struct cam_ed *device) taskqueue_enqueue(xsoftc.xpt_taskq, &device->device_destroy_task); } -u_int32_t +uint32_t xpt_dev_ccbq_resize(struct cam_path *path, int newopenings) { int result; @@ -5619,3 +5537,60 @@ xpt_action_name(uint32_t action) snprintf(buffer, sizeof(buffer), "%#x", action); return (buffer); } + +void +xpt_cam_path_debug(struct cam_path *path, const char *fmt, ...) +{ + struct sbuf sbuf; + char buf[XPT_PRINT_LEN]; /* balance to not eat too much stack */ + struct sbuf *sb = sbuf_new(&sbuf, buf, sizeof(buf), SBUF_FIXEDLEN); + va_list ap; + + sbuf_set_drain(sb, sbuf_printf_drain, NULL); + xpt_path_sbuf(path, sb); + va_start(ap, fmt); + sbuf_vprintf(sb, fmt, ap); + va_end(ap); + sbuf_finish(sb); + sbuf_delete(sb); + if (cam_debug_delay != 0) + DELAY(cam_debug_delay); +} + +void +xpt_cam_dev_debug(struct cam_ed *dev, const char *fmt, ...) +{ + struct sbuf sbuf; + char buf[XPT_PRINT_LEN]; /* balance to not eat too much stack */ + struct sbuf *sb = sbuf_new(&sbuf, buf, sizeof(buf), SBUF_FIXEDLEN); + va_list ap; + + sbuf_set_drain(sb, sbuf_printf_drain, NULL); + xpt_device_sbuf(dev, sb); + va_start(ap, fmt); + sbuf_vprintf(sb, fmt, ap); + va_end(ap); + sbuf_finish(sb); + sbuf_delete(sb); + if (cam_debug_delay != 0) + DELAY(cam_debug_delay); +} + +void +xpt_cam_debug(const char *fmt, ...) +{ + struct sbuf sbuf; + char buf[XPT_PRINT_LEN]; /* balance to not eat too much stack */ + struct sbuf *sb = sbuf_new(&sbuf, buf, sizeof(buf), SBUF_FIXEDLEN); + va_list ap; + + sbuf_set_drain(sb, sbuf_printf_drain, NULL); + sbuf_cat(sb, "cam_debug: "); + va_start(ap, fmt); + sbuf_vprintf(sb, fmt, ap); + va_end(ap); + sbuf_finish(sb); + sbuf_delete(sb); + if (cam_debug_delay != 0) + DELAY(cam_debug_delay); +} diff --git a/sys/cam/cam_xpt.h b/sys/cam/cam_xpt.h index b75025dbd4d3..06ef52580120 100644 --- a/sys/cam/cam_xpt.h +++ b/sys/cam/cam_xpt.h @@ -2,7 +2,7 @@ * Data structures and definitions for dealing with the * Common Access Method Transport (xpt) layer. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997 Justin T. Gibbs. * All rights reserved. @@ -27,24 +27,21 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _CAM_CAM_XPT_H #define _CAM_CAM_XPT_H 1 #ifdef _KERNEL -#include <sys/cdefs.h> #include <cam/cam_ccb.h> #endif +#include <sys/sbuf.h> /* Forward Declarations */ union ccb; struct cam_periph; struct cam_ed; struct cam_sim; -struct sbuf; /* * Definition of a CAM path. Paths are created from bus, target, and lun ids @@ -63,9 +60,9 @@ struct cam_path; */ struct async_node { SLIST_ENTRY(async_node) links; - u_int32_t event_enable; /* Async Event enables */ - u_int32_t event_lock; /* Take SIM lock for handlers. */ - void (*callback)(void *arg, u_int32_t code, + uint32_t event_enable; /* Async Event enables */ + uint32_t event_lock; /* Take SIM lock for handlers. */ + void (*callback)(void *arg, uint32_t code, struct cam_path *path, void *args); void *callback_arg; }; @@ -80,11 +77,11 @@ union ccb *xpt_alloc_ccb_nowait(void); void xpt_free_ccb(union ccb *free_ccb); void xpt_setup_ccb_flags(struct ccb_hdr *ccb_h, struct cam_path *path, - u_int32_t priority, - u_int32_t flags); + uint32_t priority, + uint32_t flags); void xpt_setup_ccb(struct ccb_hdr *ccb_h, struct cam_path *path, - u_int32_t priority); + uint32_t priority); void xpt_merge_ccb(union ccb *dst_ccb, union ccb *src_ccb); cam_status xpt_create_path(struct cam_path **new_path_ptr, @@ -105,9 +102,9 @@ int xpt_path_comp(struct cam_path *path1, struct cam_path *path2); int xpt_path_comp_dev(struct cam_path *path, struct cam_ed *dev); -int xpt_path_string(struct cam_path *path, char *str, +char * xpt_path_string(struct cam_path *path, char *str, size_t str_len); -int xpt_path_sbuf(struct cam_path *path, struct sbuf *sb); +void xpt_path_sbuf(struct cam_path *path, struct sbuf *sb); path_id_t xpt_path_path_id(struct cam_path *path); target_id_t xpt_path_target_id(struct cam_path *path); lun_id_t xpt_path_lun_id(struct cam_path *path); @@ -115,9 +112,8 @@ struct cam_sim *xpt_path_sim(struct cam_path *path); struct cam_periph *xpt_path_periph(struct cam_path *path); device_t xpt_path_sim_device(const struct cam_path *path); void xpt_print_path(struct cam_path *path); -void xpt_print_device(struct cam_ed *device); void xpt_print(struct cam_path *path, const char *fmt, ...); -void xpt_async(u_int32_t async_code, struct cam_path *path, +void xpt_async(uint32_t async_code, struct cam_path *path, void *async_arg); void xpt_rescan(union ccb *ccb); void xpt_hold_boot(void); diff --git a/sys/cam/cam_xpt_internal.h b/sys/cam/cam_xpt_internal.h index 18c8fc85b765..5a812e6e7d20 100644 --- a/sys/cam/cam_xpt_internal.h +++ b/sys/cam/cam_xpt_internal.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright 2009 Scott Long * All rights reserved. @@ -24,8 +24,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _CAM_CAM_XPT_INTERNAL_H @@ -43,7 +41,7 @@ typedef struct cam_ed * (*xpt_alloc_device_func)(struct cam_eb *bus, lun_id_t lun_id); typedef void (*xpt_release_device_func)(struct cam_ed *device); typedef void (*xpt_action_func)(union ccb *start_ccb); -typedef void (*xpt_dev_async_func)(u_int32_t async_code, +typedef void (*xpt_dev_async_func)(uint32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, @@ -56,7 +54,6 @@ struct xpt_xport_ops { xpt_release_device_func reldev; xpt_action_func action; xpt_dev_async_func async; - xpt_announce_periph_func announce; xpt_announce_periph_sbuf_func announce_sbuf; }; @@ -75,9 +72,7 @@ typedef void (*xpt_proto_announce_sbuf_func)(struct cam_ed *, struct sbuf *); typedef void (*xpt_proto_debug_out_func)(union ccb *); struct xpt_proto_ops { - xpt_proto_announce_func announce; xpt_proto_announce_sbuf_func announce_sbuf; - xpt_proto_announce_func denounce; xpt_proto_announce_sbuf_func denounce_sbuf; xpt_proto_debug_out_func debug_out; }; @@ -127,16 +122,16 @@ struct cam_ed { uint8_t *rcap_buf; struct ata_params ident_data; struct mmc_params mmc_ident_data; - u_int8_t inq_flags; /* + uint8_t inq_flags; /* * Current settings for inquiry flags. * This allows us to override settings * like disconnection and tagged * queuing for a device. */ - u_int8_t queue_flags; /* Queue flags from the control page */ - u_int8_t serial_num_len; - u_int8_t *serial_num; - u_int32_t flags; + uint8_t queue_flags; /* Queue flags from the control page */ + uint8_t serial_num_len; + uint8_t *serial_num; + uint32_t flags; #define CAM_DEV_UNCONFIGURED 0x01 #define CAM_DEV_REL_TIMEOUT_PENDING 0x02 #define CAM_DEV_REL_ON_COMPLETE 0x04 @@ -146,10 +141,10 @@ struct cam_ed { #define CAM_DEV_IN_DV 0x80 #define CAM_DEV_DV_HIT_BOTTOM 0x100 #define CAM_DEV_IDENTIFY_DATA_VALID 0x200 - u_int32_t tag_delay_count; + uint32_t tag_delay_count; #define CAM_TAG_DELAY_COUNT 5 - u_int32_t tag_saved_openings; - u_int32_t refcount; + uint32_t tag_saved_openings; + uint32_t refcount; struct callout callout; STAILQ_ENTRY(cam_ed) highpowerq_entry; struct mtx device_mtx; @@ -169,7 +164,7 @@ struct cam_et { TAILQ_ENTRY(cam_et) links; struct cam_eb *bus; target_id_t target_id; - u_int32_t refcount; + uint32_t refcount; u_int generation; struct timeval last_reset; u_int rpl_size; @@ -188,9 +183,9 @@ struct cam_eb { path_id_t path_id; struct cam_sim *sim; struct timeval last_reset; - u_int32_t flags; + uint32_t flags; #define CAM_EB_RUNQ_SCHEDULED 0x01 - u_int32_t refcount; + uint32_t refcount; u_int generation; device_t parent_dev; struct xpt_xport *xport; @@ -209,7 +204,7 @@ struct cam_ed * xpt_alloc_device(struct cam_eb *bus, lun_id_t lun_id); void xpt_acquire_device(struct cam_ed *device); void xpt_release_device(struct cam_ed *device); -u_int32_t xpt_dev_ccbq_resize(struct cam_path *path, int newopenings); +uint32_t xpt_dev_ccbq_resize(struct cam_path *path, int newopenings); void xpt_start_tags(struct cam_path *path); void xpt_stop_tags(struct cam_path *path); diff --git a/sys/cam/cam_xpt_periph.h b/sys/cam/cam_xpt_periph.h index f998d3bfa3b8..a95294a0f287 100644 --- a/sys/cam/cam_xpt_periph.h +++ b/sys/cam/cam_xpt_periph.h @@ -3,7 +3,7 @@ * Common Access Method Transport (xpt) layer from peripheral * drivers. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997 Justin T. Gibbs. * All rights reserved. @@ -28,8 +28,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _CAM_CAM_XPT_PERIPH_H @@ -41,7 +39,7 @@ /* Functions accessed by the peripheral drivers */ #ifdef _KERNEL void xpt_release_ccb(union ccb *released_ccb); -void xpt_schedule(struct cam_periph *perph, u_int32_t new_priority); +void xpt_schedule(struct cam_periph *perph, uint32_t new_priority); int32_t xpt_add_periph(struct cam_periph *periph); void xpt_remove_periph(struct cam_periph *periph); void xpt_announce_periph(struct cam_periph *periph, diff --git a/sys/cam/cam_xpt_sim.h b/sys/cam/cam_xpt_sim.h index 569ed09c23d2..3901c91daea2 100644 --- a/sys/cam/cam_xpt_sim.h +++ b/sys/cam/cam_xpt_sim.h @@ -2,7 +2,7 @@ * Data structures and definitions for dealing with the * Common Access Method Transport (xpt) layer. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997 Justin T. Gibbs. * All rights reserved. @@ -27,8 +27,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _CAM_CAM_XPT_SIM_H @@ -42,9 +40,9 @@ int xpt_bus_register(struct cam_sim *sim, device_t parent, uint32_t bus); int xpt_bus_deregister(path_id_t path_id); -u_int32_t xpt_freeze_simq(struct cam_sim *sim, u_int count); +uint32_t xpt_freeze_simq(struct cam_sim *sim, u_int count); void xpt_release_simq(struct cam_sim *sim, int run_queue); -u_int32_t xpt_freeze_devq(struct cam_path *path, u_int count); +uint32_t xpt_freeze_devq(struct cam_path *path, u_int count); void xpt_release_devq(struct cam_path *path, u_int count, int run_queue); void xpt_done(union ccb *done_ccb); diff --git a/sys/cam/ctl/README.ctl.txt b/sys/cam/ctl/README.ctl.txt index db8666ea99db..18e7aad5dc4f 100644 --- a/sys/cam/ctl/README.ctl.txt +++ b/sys/cam/ctl/README.ctl.txt @@ -1,4 +1,3 @@ -/* $FreeBSD$ */ CTL - CAM Target Layer Description diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c index 1fda5bde72c2..fac65e155890 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003-2009 Silicon Graphics International Corp. * Copyright (c) 2012 The FreeBSD Foundation @@ -44,9 +44,6 @@ * Author: Ken Merry <ken@FreeBSD.org> */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/ctype.h> @@ -86,6 +83,7 @@ __FBSDID("$FreeBSD$"); #include <cam/ctl/ctl_ha.h> #include <cam/ctl/ctl_private.h> #include <cam/ctl/ctl_debug.h> +#include <cam/ctl/ctl_nvme_all.h> #include <cam/ctl/ctl_scsi_all.h> #include <cam/ctl/ctl_error.h> @@ -127,72 +125,6 @@ const static struct scsi_da_rw_recovery_page rw_er_page_changeable = { /*recovery_time_limit*/{0, 0}, }; -const static struct scsi_format_page format_page_default = { - /*page_code*/SMS_FORMAT_DEVICE_PAGE, - /*page_length*/sizeof(struct scsi_format_page) - 2, - /*tracks_per_zone*/ {0, 0}, - /*alt_sectors_per_zone*/ {0, 0}, - /*alt_tracks_per_zone*/ {0, 0}, - /*alt_tracks_per_lun*/ {0, 0}, - /*sectors_per_track*/ {(CTL_DEFAULT_SECTORS_PER_TRACK >> 8) & 0xff, - CTL_DEFAULT_SECTORS_PER_TRACK & 0xff}, - /*bytes_per_sector*/ {0, 0}, - /*interleave*/ {0, 0}, - /*track_skew*/ {0, 0}, - /*cylinder_skew*/ {0, 0}, - /*flags*/ SFP_HSEC, - /*reserved*/ {0, 0, 0} -}; - -const static struct scsi_format_page format_page_changeable = { - /*page_code*/SMS_FORMAT_DEVICE_PAGE, - /*page_length*/sizeof(struct scsi_format_page) - 2, - /*tracks_per_zone*/ {0, 0}, - /*alt_sectors_per_zone*/ {0, 0}, - /*alt_tracks_per_zone*/ {0, 0}, - /*alt_tracks_per_lun*/ {0, 0}, - /*sectors_per_track*/ {0, 0}, - /*bytes_per_sector*/ {0, 0}, - /*interleave*/ {0, 0}, - /*track_skew*/ {0, 0}, - /*cylinder_skew*/ {0, 0}, - /*flags*/ 0, - /*reserved*/ {0, 0, 0} -}; - -const static struct scsi_rigid_disk_page rigid_disk_page_default = { - /*page_code*/SMS_RIGID_DISK_PAGE, - /*page_length*/sizeof(struct scsi_rigid_disk_page) - 2, - /*cylinders*/ {0, 0, 0}, - /*heads*/ CTL_DEFAULT_HEADS, - /*start_write_precomp*/ {0, 0, 0}, - /*start_reduced_current*/ {0, 0, 0}, - /*step_rate*/ {0, 0}, - /*landing_zone_cylinder*/ {0, 0, 0}, - /*rpl*/ SRDP_RPL_DISABLED, - /*rotational_offset*/ 0, - /*reserved1*/ 0, - /*rotation_rate*/ {(CTL_DEFAULT_ROTATION_RATE >> 8) & 0xff, - CTL_DEFAULT_ROTATION_RATE & 0xff}, - /*reserved2*/ {0, 0} -}; - -const static struct scsi_rigid_disk_page rigid_disk_page_changeable = { - /*page_code*/SMS_RIGID_DISK_PAGE, - /*page_length*/sizeof(struct scsi_rigid_disk_page) - 2, - /*cylinders*/ {0, 0, 0}, - /*heads*/ 0, - /*start_write_precomp*/ {0, 0, 0}, - /*start_reduced_current*/ {0, 0, 0}, - /*step_rate*/ {0, 0}, - /*landing_zone_cylinder*/ {0, 0, 0}, - /*rpl*/ 0, - /*rotational_offset*/ 0, - /*reserved1*/ 0, - /*rotation_rate*/ {0, 0}, - /*reserved2*/ {0, 0} -}; - const static struct scsi_da_verify_recovery_page verify_er_page_default = { /*page_code*/SMS_VERIFY_ERROR_RECOVERY_PAGE, /*page_length*/sizeof(struct scsi_da_verify_recovery_page) - 2, @@ -435,7 +367,7 @@ SYSCTL_INT(_kern_cam_ctl, OID_AUTO, max_luns, CTLFLAG_RDTUN, /* * Maximum number of ports registered at one time. */ -#define CTL_DEFAULT_MAX_PORTS 256 +#define CTL_DEFAULT_MAX_PORTS 1024 static int ctl_max_ports = CTL_DEFAULT_MAX_PORTS; TUNABLE_INT("kern.cam.ctl.max_ports", &ctl_max_ports); SYSCTL_INT(_kern_cam_ctl, OID_AUTO, max_ports, CTLFLAG_RDTUN, @@ -516,6 +448,8 @@ static int ctl_scsiio_lun_check(struct ctl_lun *lun, static void ctl_failover_lun(union ctl_io *io); static void ctl_scsiio_precheck(struct ctl_scsiio *ctsio); static int ctl_scsiio(struct ctl_scsiio *ctsio); +static void ctl_nvmeio_precheck(struct ctl_nvmeio *ctnio); +static int ctl_nvmeio(struct ctl_nvmeio *ctnio); static int ctl_target_reset(union ctl_io *io); static void ctl_do_lun_reset(struct ctl_lun *lun, uint32_t initidx, @@ -597,6 +531,38 @@ static moduledata_t ctl_moduledata = { DECLARE_MODULE(ctl, ctl_moduledata, SI_SUB_CONFIGURE, SI_ORDER_THIRD); MODULE_VERSION(ctl, 1); +static void +ctl_be_move_done(union ctl_io *io, bool samethr) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + io->scsiio.be_move_done(io, samethr); + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + io->nvmeio.be_move_done(io, samethr); + break; + default: + __assert_unreachable(); + } +} + +static void +ctl_continue_io(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + io->scsiio.io_cont(io); + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + io->nvmeio.io_cont(io); + break; + default: + __assert_unreachable(); + } +} + static struct ctl_frontend ha_frontend = { .name = "ha", @@ -654,6 +620,8 @@ ctl_ha_datamove(union ctl_io *io) uint32_t sg_entries_sent; int do_sg_copy, i, j; + CTL_IO_ASSERT(io, SCSI); + memset(&msg.dt, 0, sizeof(msg.dt)); msg.hdr.msg_type = CTL_MSG_DATAMOVE; msg.hdr.original_sc = io->io_hdr.remote_io; @@ -670,32 +638,32 @@ ctl_ha_datamove(union ctl_io *io) * us to get more than CTL_HA_MAX_SG_ENTRIES S/G entries, * then we need to break this up into multiple transfers. */ - if (io->scsiio.kern_sg_entries == 0) { + if (ctl_kern_sg_entries(io) == 0) { msg.dt.kern_sg_entries = 1; #if 0 if (io->io_hdr.flags & CTL_FLAG_BUS_ADDR) { - msg.dt.sg_list[0].addr = io->scsiio.kern_data_ptr; + msg.dt.sg_list[0].addr = ctl_kern_data_ptr(io); } else { /* XXX KDM use busdma here! */ msg.dt.sg_list[0].addr = - (void *)vtophys(io->scsiio.kern_data_ptr); + (void *)vtophys(ctl_kern_data_ptr(io)); } #else KASSERT((io->io_hdr.flags & CTL_FLAG_BUS_ADDR) == 0, ("HA does not support BUS_ADDR")); - msg.dt.sg_list[0].addr = io->scsiio.kern_data_ptr; + msg.dt.sg_list[0].addr = ctl_kern_data_ptr(io); #endif - msg.dt.sg_list[0].len = io->scsiio.kern_data_len; + msg.dt.sg_list[0].len = ctl_kern_data_len(io); do_sg_copy = 0; } else { - msg.dt.kern_sg_entries = io->scsiio.kern_sg_entries; + msg.dt.kern_sg_entries = ctl_kern_sg_entries(io); do_sg_copy = 1; } - msg.dt.kern_data_len = io->scsiio.kern_data_len; - msg.dt.kern_total_len = io->scsiio.kern_total_len; - msg.dt.kern_data_resid = io->scsiio.kern_data_resid; - msg.dt.kern_rel_offset = io->scsiio.kern_rel_offset; + msg.dt.kern_data_len = ctl_kern_data_len(io); + msg.dt.kern_total_len = ctl_kern_total_len(io); + msg.dt.kern_data_resid = ctl_kern_data_resid(io); + msg.dt.kern_rel_offset = ctl_kern_rel_offset(io); msg.dt.sg_sequence = 0; /* @@ -709,7 +677,7 @@ ctl_ha_datamove(union ctl_io *io) sizeof(msg.dt.sg_list[0])), msg.dt.kern_sg_entries - sg_entries_sent); if (do_sg_copy != 0) { - sgl = (struct ctl_sg_entry *)io->scsiio.kern_data_ptr; + sgl = (struct ctl_sg_entry *)ctl_kern_data_ptr(io); for (i = sg_entries_sent, j = 0; i < msg.dt.cur_sg_entries; i++, j++) { #if 0 @@ -1565,6 +1533,8 @@ ctl_isc_event_handler(ctl_ha_channel channel, ctl_ha_event event, int param) /* XXX KDM do something here */ break; } + CTL_IO_ASSERT(io, SCSI); + io->io_hdr.msg_type = CTL_MSG_DATAMOVE; io->io_hdr.flags |= CTL_FLAG_IO_ACTIVE; /* @@ -1638,6 +1608,8 @@ ctl_isc_event_handler(ctl_ha_channel channel, ctl_ha_event event, int param) * back to the initiator. */ io = msg->hdr.serializing_sc; + CTL_IO_ASSERT(io, SCSI); + io->io_hdr.msg_type = CTL_MSG_DATAMOVE_DONE; io->io_hdr.flags &= ~CTL_FLAG_DMA_INPROG; io->io_hdr.flags |= CTL_FLAG_IO_ACTIVE; @@ -2443,7 +2415,7 @@ ctl_serialize_other_sc_cmd(struct ctl_scsiio *ctsio) case CTL_ACTION_OVERLAP_TAG: LIST_REMOVE(&ctsio->io_hdr, ooa_links); mtx_unlock(&lun->lun_lock); - ctl_set_overlapped_tag(ctsio, ctsio->tag_num); + ctl_set_overlapped_tag(ctsio, ctsio->tag_num & 0xff); badjuju: ctl_copy_sense_data_back((union ctl_io *)ctsio, &msg_info); msg_info.hdr.original_sc = ctsio->io_hdr.remote_io; @@ -2479,6 +2451,8 @@ ctl_ioctl_fill_ooa(struct ctl_lun *lun, uint32_t *cur_fill_num, union ctl_io *io = (union ctl_io *)ioh; struct ctl_ooa_entry *entry; + CTL_IO_ASSERT(io, SCSI); + /* * If we've got more than we can fit, just count the * remaining entries. @@ -2491,6 +2465,7 @@ ctl_ioctl_fill_ooa(struct ctl_lun *lun, uint32_t *cur_fill_num, entry = &kern_entries[*cur_fill_num]; entry->tag_num = io->scsiio.tag_num; + entry->tag_type = io->scsiio.tag_type; entry->lun_num = lun->lun; #ifdef CTL_TIME_IO entry->start_bt = io->io_hdr.start_bt; @@ -2536,13 +2511,13 @@ ctl_sbuf_printf_esc(struct sbuf *sb, char *str, int size) for (; *str && str < end; str++) { switch (*str) { case '&': - retval = sbuf_printf(sb, "&"); + retval = sbuf_cat(sb, "&"); break; case '>': - retval = sbuf_printf(sb, ">"); + retval = sbuf_cat(sb, ">"); break; case '<': - retval = sbuf_printf(sb, "<"); + retval = sbuf_cat(sb, "<"); break; default: retval = sbuf_putc(sb, *str); @@ -2567,13 +2542,13 @@ ctl_id_sbuf(struct ctl_devid *id, struct sbuf *sb) desc = (struct scsi_vpd_id_descriptor *)id->data; switch (desc->id_type & SVPD_ID_TYPE_MASK) { case SVPD_ID_TYPE_T10: - sbuf_printf(sb, "t10."); + sbuf_cat(sb, "t10."); break; case SVPD_ID_TYPE_EUI64: - sbuf_printf(sb, "eui."); + sbuf_cat(sb, "eui."); break; case SVPD_ID_TYPE_NAA: - sbuf_printf(sb, "naa."); + sbuf_cat(sb, "naa."); break; case SVPD_ID_TYPE_SCSI_NAME: break; @@ -2588,7 +2563,7 @@ ctl_id_sbuf(struct ctl_devid *id, struct sbuf *sb) (char *)desc->identifier); break; case SVPD_ID_CODESET_UTF8: - sbuf_printf(sb, "%s", (char *)desc->identifier); + sbuf_cat(sb, (char *)desc->identifier); break; } } @@ -2977,6 +2952,12 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, } if (lun_req->args != NULL) { + if (lun_req->args_len > CTL_MAX_ARGS_LEN) { + lun_req->status = CTL_LUN_ERROR; + snprintf(lun_req->error_str, sizeof(lun_req->error_str), + "Too big args."); + break; + } packed = malloc(lun_req->args_len, M_CTL, M_WAITOK); if (copyin(lun_req->args, packed, lun_req->args_len) != 0) { free(packed, M_CTL); @@ -2998,6 +2979,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, } else lun_req->args_nvl = nvlist_create(0); + lun_req->result_nvl = NULL; retval = backend->ioctl(dev, cmd, addr, flag, td); nvlist_destroy(lun_req->args_nvl); lun_req->args_nvl = tmp_args_nvl; @@ -3083,7 +3065,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, break; } - sbuf_printf(sb, "<ctllunlist>\n"); + sbuf_cat(sb, "<ctllunlist>\n"); mtx_lock(&softc->ctl_lock); STAILQ_FOREACH(lun, &softc->lun_list, links) { @@ -3113,7 +3095,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, break; if (lun->backend == NULL) { - retval = sbuf_printf(sb, "</lun>\n"); + retval = sbuf_cat(sb, "</lun>\n"); if (retval != 0) break; continue; @@ -3132,7 +3114,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, if (retval != 0) break; - retval = sbuf_printf(sb, "\t<serial_number>"); + retval = sbuf_cat(sb, "\t<serial_number>"); if (retval != 0) break; @@ -3144,12 +3126,12 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, if (retval != 0) break; - retval = sbuf_printf(sb, "</serial_number>\n"); + retval = sbuf_cat(sb, "</serial_number>\n"); if (retval != 0) break; - retval = sbuf_printf(sb, "\t<device_id>"); + retval = sbuf_cat(sb, "\t<device_id>"); if (retval != 0) break; @@ -3161,7 +3143,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, if (retval != 0) break; - retval = sbuf_printf(sb, "</device_id>\n"); + retval = sbuf_cat(sb, "</device_id>\n"); if (retval != 0) break; @@ -3181,13 +3163,13 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, value = dnvlist_get_string( lun->be_lun->options, name, NULL); if (value != NULL) - sbuf_printf(sb, "%s", value); + sbuf_cat(sb, value); } sbuf_printf(sb, "</%s>\n", name); } - retval = sbuf_printf(sb, "</lun>\n"); + retval = sbuf_cat(sb, "</lun>\n"); if (retval != 0) break; @@ -3198,7 +3180,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, mtx_unlock(&softc->ctl_lock); if ((retval != 0) - || ((retval = sbuf_printf(sb, "</ctllunlist>\n")) != 0)) { + || ((retval = sbuf_cat(sb, "</ctllunlist>\n")) != 0)) { retval = 0; sbuf_delete(sb); list->status = CTL_LUN_LIST_NEED_MORE_SPACE; @@ -3235,6 +3217,23 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, retval = fe->ioctl(dev, cmd, addr, flag, td); break; } + case CTL_NVMF: { + struct ctl_nvmf *cn; + struct ctl_frontend *fe; + + cn = (struct ctl_nvmf *)addr; + + fe = ctl_frontend_find("nvmf"); + if (fe == NULL) { + cn->status = CTL_NVMF_ERROR; + snprintf(cn->error_str, sizeof(cn->error_str), + "Frontend \"nvmf\" not found."); + break; + } + + retval = fe->ioctl(dev, cmd, addr, flag, td); + break; + } case CTL_PORT_REQ: { struct ctl_req *req; struct ctl_frontend *fe; @@ -3254,6 +3253,12 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, } if (req->args != NULL) { + if (req->args_len > CTL_MAX_ARGS_LEN) { + req->status = CTL_LUN_ERROR; + snprintf(req->error_str, sizeof(req->error_str), + "Too big args."); + break; + } packed = malloc(req->args_len, M_CTL, M_WAITOK); if (copyin(req->args, packed, req->args_len) != 0) { free(packed, M_CTL); @@ -3275,6 +3280,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, } else req->args_nvl = nvlist_create(0); + req->result_nvl = NULL; if (fe->ioctl) retval = fe->ioctl(dev, cmd, addr, flag, td); else @@ -3341,7 +3347,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, break; } - sbuf_printf(sb, "<ctlportlist>\n"); + sbuf_cat(sb, "<ctlportlist>\n"); mtx_lock(&softc->ctl_lock); STAILQ_FOREACH(port, &softc->port_list, links) { @@ -3386,15 +3392,15 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, break; if (port->target_devid != NULL) { - sbuf_printf(sb, "\t<target>"); + sbuf_cat(sb, "\t<target>"); ctl_id_sbuf(port->target_devid, sb); - sbuf_printf(sb, "</target>\n"); + sbuf_cat(sb, "</target>\n"); } if (port->port_devid != NULL) { - sbuf_printf(sb, "\t<port>"); + sbuf_cat(sb, "\t<port>"); ctl_id_sbuf(port->port_devid, sb); - sbuf_printf(sb, "</port>\n"); + sbuf_cat(sb, "</port>\n"); } if (port->port_info != NULL) { @@ -3419,7 +3425,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, } if (port->lun_map != NULL) { - sbuf_printf(sb, "\t<lun_map>on</lun_map>\n"); + sbuf_cat(sb, "\t<lun_map>on</lun_map>\n"); for (j = 0; j < port->lun_map_size; j++) { plun = ctl_lun_map_from_port(port, j); if (plun == UINT32_MAX) @@ -3450,14 +3456,14 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, if (retval != 0) break; - retval = sbuf_printf(sb, "</targ_port>\n"); + retval = sbuf_cat(sb, "</targ_port>\n"); if (retval != 0) break; } mtx_unlock(&softc->ctl_lock); if ((retval != 0) - || ((retval = sbuf_printf(sb, "</ctlportlist>\n")) != 0)) { + || ((retval = sbuf_cat(sb, "</ctlportlist>\n")) != 0)) { retval = 0; sbuf_delete(sb); list->status = CTL_LUN_LIST_NEED_MORE_SPACE; @@ -4112,134 +4118,6 @@ ctl_init_page_index(struct ctl_lun *lun) (uint8_t *)lun->mode_pages.rw_er_page; break; } - case SMS_FORMAT_DEVICE_PAGE: { - struct scsi_format_page *format_page; - - KASSERT(page_index->subpage == SMS_SUBPAGE_PAGE_0, - ("subpage %#x for page %#x is incorrect!", - page_index->subpage, page_code)); - - /* - * Sectors per track are set above. Bytes per - * sector need to be set here on a per-LUN basis. - */ - memcpy(&lun->mode_pages.format_page[CTL_PAGE_CURRENT], - &format_page_default, - sizeof(format_page_default)); - memcpy(&lun->mode_pages.format_page[ - CTL_PAGE_CHANGEABLE], &format_page_changeable, - sizeof(format_page_changeable)); - memcpy(&lun->mode_pages.format_page[CTL_PAGE_DEFAULT], - &format_page_default, - sizeof(format_page_default)); - memcpy(&lun->mode_pages.format_page[CTL_PAGE_SAVED], - &format_page_default, - sizeof(format_page_default)); - - format_page = &lun->mode_pages.format_page[ - CTL_PAGE_CURRENT]; - scsi_ulto2b(lun->be_lun->blocksize, - format_page->bytes_per_sector); - - format_page = &lun->mode_pages.format_page[ - CTL_PAGE_DEFAULT]; - scsi_ulto2b(lun->be_lun->blocksize, - format_page->bytes_per_sector); - - format_page = &lun->mode_pages.format_page[ - CTL_PAGE_SAVED]; - scsi_ulto2b(lun->be_lun->blocksize, - format_page->bytes_per_sector); - - page_index->page_data = - (uint8_t *)lun->mode_pages.format_page; - break; - } - case SMS_RIGID_DISK_PAGE: { - struct scsi_rigid_disk_page *rigid_disk_page; - uint32_t sectors_per_cylinder; - uint64_t cylinders; -#ifndef __XSCALE__ - int shift; -#endif /* !__XSCALE__ */ - - KASSERT(page_index->subpage == SMS_SUBPAGE_PAGE_0, - ("subpage %#x for page %#x is incorrect!", - page_index->subpage, page_code)); - - /* - * Rotation rate and sectors per track are set - * above. We calculate the cylinders here based on - * capacity. Due to the number of heads and - * sectors per track we're using, smaller arrays - * may turn out to have 0 cylinders. Linux and - * FreeBSD don't pay attention to these mode pages - * to figure out capacity, but Solaris does. It - * seems to deal with 0 cylinders just fine, and - * works out a fake geometry based on the capacity. - */ - memcpy(&lun->mode_pages.rigid_disk_page[ - CTL_PAGE_DEFAULT], &rigid_disk_page_default, - sizeof(rigid_disk_page_default)); - memcpy(&lun->mode_pages.rigid_disk_page[ - CTL_PAGE_CHANGEABLE],&rigid_disk_page_changeable, - sizeof(rigid_disk_page_changeable)); - - sectors_per_cylinder = CTL_DEFAULT_SECTORS_PER_TRACK * - CTL_DEFAULT_HEADS; - - /* - * The divide method here will be more accurate, - * probably, but results in floating point being - * used in the kernel on i386 (__udivdi3()). On the - * XScale, though, __udivdi3() is implemented in - * software. - * - * The shift method for cylinder calculation is - * accurate if sectors_per_cylinder is a power of - * 2. Otherwise it might be slightly off -- you - * might have a bit of a truncation problem. - */ -#ifdef __XSCALE__ - cylinders = (lun->be_lun->maxlba + 1) / - sectors_per_cylinder; -#else - for (shift = 31; shift > 0; shift--) { - if (sectors_per_cylinder & (1 << shift)) - break; - } - cylinders = (lun->be_lun->maxlba + 1) >> shift; -#endif - - /* - * We've basically got 3 bytes, or 24 bits for the - * cylinder size in the mode page. If we're over, - * just round down to 2^24. - */ - if (cylinders > 0xffffff) - cylinders = 0xffffff; - - rigid_disk_page = &lun->mode_pages.rigid_disk_page[ - CTL_PAGE_DEFAULT]; - scsi_ulto3b(cylinders, rigid_disk_page->cylinders); - - if ((value = dnvlist_get_string(lun->be_lun->options, - "rpm", NULL)) != NULL) { - scsi_ulto2b(strtol(value, NULL, 0), - rigid_disk_page->rotation_rate); - } - - memcpy(&lun->mode_pages.rigid_disk_page[CTL_PAGE_CURRENT], - &lun->mode_pages.rigid_disk_page[CTL_PAGE_DEFAULT], - sizeof(rigid_disk_page_default)); - memcpy(&lun->mode_pages.rigid_disk_page[CTL_PAGE_SAVED], - &lun->mode_pages.rigid_disk_page[CTL_PAGE_DEFAULT], - sizeof(rigid_disk_page_default)); - - page_index->page_data = - (uint8_t *)lun->mode_pages.rigid_disk_page; - break; - } case SMS_VERIFY_ERROR_RECOVERY_PAGE: { KASSERT(page_index->subpage == SMS_SUBPAGE_PAGE_0, ("subpage %#x for page %#x is incorrect!", @@ -5095,6 +4973,91 @@ ctl_lun_capacity_changed(struct ctl_be_lun *be_lun) } } +void +ctl_lun_nsdata_ids(struct ctl_be_lun *be_lun, + struct nvme_namespace_data *nsdata) +{ + struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun; + struct scsi_vpd_id_descriptor *idd; + + if (lun->lun_devid == NULL) + return; + + idd = scsi_get_devid_desc((struct scsi_vpd_id_descriptor *) + lun->lun_devid->data, lun->lun_devid->len, scsi_devid_is_lun_naa); + if (idd != NULL) { + if (idd->length == 16) { + memcpy(nsdata->nguid, idd->identifier, 16); + return; + } + if (idd->length == 8) { + memcpy(nsdata->eui64, idd->identifier, 8); + return; + } + } + + idd = scsi_get_devid_desc((struct scsi_vpd_id_descriptor *) + lun->lun_devid->data, lun->lun_devid->len, scsi_devid_is_lun_eui64); + if (idd != NULL) { + if (idd->length == 8) { + memcpy(nsdata->eui64, idd->identifier, 8); + return; + } + } +} + +void +ctl_lun_nvme_ids(struct ctl_be_lun *be_lun, void *data) +{ + struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun; + struct scsi_vpd_id_descriptor *naa, *eui64, *uuid; + char *p; + + memset(data, 0, 4096); + + if (lun->lun_devid == NULL) + return; + + naa = scsi_get_devid_desc((struct scsi_vpd_id_descriptor *) + lun->lun_devid->data, lun->lun_devid->len, scsi_devid_is_lun_naa); + eui64 = scsi_get_devid_desc((struct scsi_vpd_id_descriptor *) + lun->lun_devid->data, lun->lun_devid->len, scsi_devid_is_lun_eui64); + uuid = scsi_get_devid_desc((struct scsi_vpd_id_descriptor *) + lun->lun_devid->data, lun->lun_devid->len, scsi_devid_is_lun_uuid); + + p = data; + + /* EUI64 */ + if ((naa != NULL && naa->length == 8) || eui64 != NULL) { + *p++ = 1; + *p++ = 8; + p += 2; + if (naa != NULL && naa->length == 8) + memcpy(p, naa->identifier, 8); + else + memcpy(p, eui64->identifier, 8); + p += 8; + } + + /* NGUID */ + if (naa != NULL && naa->length == 16) { + *p++ = 1; + *p++ = 16; + p += 2; + memcpy(p, naa->identifier, 16); + p += 16; + } + + /* UUID */ + if (uuid != NULL) { + *p++ = 1; + *p++ = uuid->length; + p += 2; + memcpy(p, uuid->identifier, uuid->length); + p += uuid->length; + } +} + /* * Backend "memory move is complete" callback for requests that never * make it down to say RAIDCore's configuration code. @@ -5105,8 +5068,6 @@ ctl_config_move_done(union ctl_io *io, bool samethr) int retval; CTL_DEBUG_PRINT(("ctl_config_move_done\n")); - KASSERT(io->io_hdr.io_type == CTL_IO_SCSI, - ("%s: unexpected I/O type %x", __func__, io->io_hdr.io_type)); if (ctl_debug & CTL_DEBUG_CDB_DATA) ctl_data_print(io); @@ -5120,7 +5081,7 @@ ctl_config_move_done(union ctl_io *io, bool samethr) * we'll need to know how to clean them up here as well. */ if (io->io_hdr.flags & CTL_FLAG_ALLOCATED) - free(io->scsiio.kern_data_ptr, M_CTL); + free(ctl_kern_data_ptr(io), M_CTL); ctl_done(io); retval = CTL_RETVAL_COMPLETE; } else { @@ -5141,7 +5102,17 @@ ctl_config_move_done(union ctl_io *io, bool samethr) * XXX KDM call ctl_scsiio() again for now, and check flag * bits to see whether we're allocated or not. */ - retval = ctl_scsiio(&io->scsiio); + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + retval = ctl_scsiio(&io->scsiio); + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + retval = ctl_nvmeio(&io->nvmeio); + break; + default: + __assert_unreachable(); + } } return (retval); } @@ -5165,7 +5136,7 @@ ctl_data_submit_done(union ctl_io *io) (io->io_hdr.flags & CTL_FLAG_ABORT) == 0 && ((io->io_hdr.status & CTL_STATUS_MASK) == CTL_STATUS_NONE || (io->io_hdr.status & CTL_STATUS_MASK) == CTL_SUCCESS)) { - io->scsiio.io_cont(io); + ctl_continue_io(io); return; } ctl_done(io); @@ -5192,7 +5163,7 @@ ctl_config_write_done(union ctl_io *io) (io->io_hdr.flags & CTL_FLAG_ABORT) == 0 && ((io->io_hdr.status & CTL_STATUS_MASK) == CTL_STATUS_NONE || (io->io_hdr.status & CTL_STATUS_MASK) == CTL_SUCCESS)) { - io->scsiio.io_cont(io); + ctl_continue_io(io); return; } /* @@ -5201,7 +5172,7 @@ ctl_config_write_done(union ctl_io *io) * no data, like start/stop unit, we need to check here. */ if (io->io_hdr.flags & CTL_FLAG_ALLOCATED) - buf = io->scsiio.kern_data_ptr; + buf = ctl_kern_data_ptr(io); else buf = NULL; ctl_done(io); @@ -5221,7 +5192,7 @@ ctl_config_read_done(union ctl_io *io) ((io->io_hdr.status & CTL_STATUS_MASK) != CTL_STATUS_NONE && (io->io_hdr.status & CTL_STATUS_MASK) != CTL_SUCCESS)) { if (io->io_hdr.flags & CTL_FLAG_ALLOCATED) - buf = io->scsiio.kern_data_ptr; + buf = ctl_kern_data_ptr(io); else buf = NULL; ctl_done(io); @@ -5236,7 +5207,7 @@ ctl_config_read_done(union ctl_io *io) * the I/O just yet. */ if (io->io_hdr.flags & CTL_FLAG_IO_CONT) { - io->scsiio.io_cont(io); + ctl_continue_io(io); return; } @@ -5694,6 +5665,8 @@ ctl_write_same_cont(union ctl_io *io) struct ctl_lba_len_flags *lbalen; int retval; + CTL_IO_ASSERT(io, SCSI); + ctsio = &io->scsiio; ctsio->io_hdr.status = CTL_STATUS_NONE; lbalen = (struct ctl_lba_len_flags *) @@ -6039,6 +6012,8 @@ ctl_do_mode_select(union ctl_io *io) uint16_t *len_left, *len_used; int retval, i; + CTL_IO_ASSERT(io, SCSI); + ctsio = &io->scsiio; page_index = NULL; page_len = 0; @@ -8257,7 +8232,7 @@ ctl_persistent_reserve_out(struct ctl_scsiio *ctsio) struct ctl_softc *softc = CTL_SOFTC(ctsio); struct ctl_lun *lun = CTL_LUN(ctsio); int retval; - u_int32_t param_len; + uint32_t param_len; struct scsi_per_res_out *cdb; struct scsi_per_res_out_parms* param; uint32_t residx; @@ -8952,6 +8927,8 @@ ctl_cnw_cont(union ctl_io *io) struct ctl_lba_len_flags *lbalen; int retval; + CTL_IO_ASSERT(io, SCSI); + ctsio = &io->scsiio; ctsio->io_hdr.status = CTL_STATUS_NONE; ctsio->io_hdr.flags &= ~CTL_FLAG_IO_CONT; @@ -10736,14 +10713,732 @@ ctl_read_toc(struct ctl_scsiio *ctsio) } /* + * For NVMe commands, parse the LBA and length. + */ +static bool +ctl_nvme_get_lba_len(struct ctl_nvmeio *ctnio, uint64_t *lba, uint32_t *len) +{ + CTL_IO_ASSERT(ctnio, NVME); + + switch (ctnio->cmd.opc) { + case NVME_OPC_WRITE: + case NVME_OPC_READ: + case NVME_OPC_WRITE_UNCORRECTABLE: + case NVME_OPC_COMPARE: + case NVME_OPC_WRITE_ZEROES: + case NVME_OPC_VERIFY: + *lba = (uint64_t)le32toh(ctnio->cmd.cdw11) << 32 | + le32toh(ctnio->cmd.cdw10); + *len = (le32toh(ctnio->cmd.cdw12) & 0xffff) + 1; + return (true); + default: + *lba = 0; + *len = 0; + return (false); + } +} + +static bool +ctl_nvme_fua(struct ctl_nvmeio *ctnio) +{ + return ((le32toh(ctnio->cmd.cdw12) & (1U << 30)) != 0); +} + +int +ctl_nvme_identify(struct ctl_nvmeio *ctnio) +{ + struct ctl_lun *lun = CTL_LUN(ctnio); + size_t len; + int retval; + uint8_t cns; + + CTL_DEBUG_PRINT(("ctl_nvme_identify\n")); + + CTL_IO_ASSERT(ctnio, NVME_ADMIN); + MPASS(ctnio->cmd.opc == NVME_OPC_IDENTIFY); + + /* + * The data buffer for Identify is always 4096 bytes, see + * 5.51.1 in NVMe base specification 1.4. + */ + len = 4096; + + ctnio->kern_data_ptr = malloc(len, M_CTL, M_WAITOK); + ctnio->kern_data_len = len; + ctnio->kern_total_len = len; + ctnio->kern_rel_offset = 0; + ctnio->kern_sg_entries = 0; + + ctl_nvme_set_success(ctnio); + ctnio->io_hdr.flags |= CTL_FLAG_ALLOCATED; + ctnio->be_move_done = ctl_config_move_done; + + /* + * If we don't have a LUN, return an empty result for CNS == 0. + */ + if (lun == NULL) { + cns = le32toh(ctnio->cmd.cdw10) & 0xff; + switch (cns) { + case 0: + memset(ctnio->kern_data_ptr, 0, len); + ctl_datamove((union ctl_io *)ctnio); + break; + default: + ctl_nvme_set_invalid_field(ctnio); + break; + } + return (CTL_RETVAL_COMPLETE); + } + + retval = lun->backend->config_read((union ctl_io *)ctnio); + return (retval); +} + +int +ctl_nvme_flush(struct ctl_nvmeio *ctnio) +{ + struct ctl_lun *lun = CTL_LUN(ctnio); + int retval; + + CTL_DEBUG_PRINT(("ctl_nvme_flush\n")); + + CTL_IO_ASSERT(ctnio, NVME); + MPASS(ctnio->cmd.opc == NVME_OPC_FLUSH); + + /* + * NVMe flushes always flush the entire namespace, not an LBA + * range. + */ + retval = lun->backend->config_write((union ctl_io *)ctnio); + + return (retval); +} + +int +ctl_nvme_read_write(struct ctl_nvmeio *ctnio) +{ + struct ctl_lun *lun = CTL_LUN(ctnio); + struct ctl_lba_len_flags *lbalen; + uint64_t lba; + uint32_t num_blocks; + int flags, retval; + bool isread; + + CTL_DEBUG_PRINT(("ctl_nvme_read_write: command: %#x\n", + ctnio->cmd.opc)); + + CTL_IO_ASSERT(ctnio, NVME); + MPASS(ctnio->cmd.opc == NVME_OPC_WRITE || + ctnio->cmd.opc == NVME_OPC_READ); + + flags = 0; + isread = ctnio->cmd.opc == NVME_OPC_READ; + ctl_nvme_get_lba_len(ctnio, &lba, &num_blocks); + + /* + * The first check is to make sure we're in bounds, the second + * check is to catch wrap-around problems. If the lba + num blocks + * is less than the lba, then we've wrapped around and the block + * range is invalid anyway. + */ + if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) + || ((lba + num_blocks) < lba)) { + ctl_nvme_set_lba_out_of_range(ctnio); + ctl_done((union ctl_io *)ctnio); + return (CTL_RETVAL_COMPLETE); + } + + /* + * Set FUA and/or DPO if caches are disabled. + * + * For a read this may not be quite correct for the block + * backend as any earlier writes to the LBA range should be + * flushed to backing store as part of the read. + */ + if (ctl_nvme_fua(ctnio)) { + flags |= CTL_LLF_FUA; + if (isread) + flags |= CTL_LLF_DPO; + } + + lbalen = (struct ctl_lba_len_flags *) + &ctnio->io_hdr.ctl_private[CTL_PRIV_LBA_LEN]; + lbalen->lba = lba; + lbalen->len = num_blocks; + lbalen->flags = (isread ? CTL_LLF_READ : CTL_LLF_WRITE) | flags; + + ctnio->kern_total_len = num_blocks * lun->be_lun->blocksize; + ctnio->kern_rel_offset = 0; + + CTL_DEBUG_PRINT(("ctl_nvme_read_write: calling data_submit()\n")); + + retval = lun->backend->data_submit((union ctl_io *)ctnio); + return (retval); +} + +int +ctl_nvme_write_uncorrectable(struct ctl_nvmeio *ctnio) +{ + struct ctl_lun *lun = CTL_LUN(ctnio); + struct ctl_lba_len_flags *lbalen; + uint64_t lba; + uint32_t num_blocks; + int retval; + + CTL_DEBUG_PRINT(("ctl_nvme_write_uncorrectable\n")); + + CTL_IO_ASSERT(ctnio, NVME); + MPASS(ctnio->cmd.opc == NVME_OPC_WRITE_UNCORRECTABLE); + + ctl_nvme_get_lba_len(ctnio, &lba, &num_blocks); + + /* + * The first check is to make sure we're in bounds, the second + * check is to catch wrap-around problems. If the lba + num blocks + * is less than the lba, then we've wrapped around and the block + * range is invalid anyway. + */ + if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) + || ((lba + num_blocks) < lba)) { + ctl_nvme_set_lba_out_of_range(ctnio); + ctl_done((union ctl_io *)ctnio); + return (CTL_RETVAL_COMPLETE); + } + + lbalen = (struct ctl_lba_len_flags *) + &ctnio->io_hdr.ctl_private[CTL_PRIV_LBA_LEN]; + lbalen->lba = lba; + lbalen->len = num_blocks; + lbalen->flags = 0; + retval = lun->backend->config_write((union ctl_io *)ctnio); + + return (retval); +} + +int +ctl_nvme_compare(struct ctl_nvmeio *ctnio) +{ + struct ctl_lun *lun = CTL_LUN(ctnio); + struct ctl_lba_len_flags *lbalen; + uint64_t lba; + uint32_t num_blocks; + int flags; + int retval; + + CTL_DEBUG_PRINT(("ctl_nvme_compare\n")); + + CTL_IO_ASSERT(ctnio, NVME); + MPASS(ctnio->cmd.opc == NVME_OPC_COMPARE); + + flags = 0; + ctl_nvme_get_lba_len(ctnio, &lba, &num_blocks); + if (ctl_nvme_fua(ctnio)) + flags |= CTL_LLF_FUA; + + /* + * The first check is to make sure we're in bounds, the second + * check is to catch wrap-around problems. If the lba + num blocks + * is less than the lba, then we've wrapped around and the block + * range is invalid anyway. + */ + if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) + || ((lba + num_blocks) < lba)) { + ctl_nvme_set_lba_out_of_range(ctnio); + ctl_done((union ctl_io *)ctnio); + return (CTL_RETVAL_COMPLETE); + } + + lbalen = (struct ctl_lba_len_flags *) + &ctnio->io_hdr.ctl_private[CTL_PRIV_LBA_LEN]; + lbalen->lba = lba; + lbalen->len = num_blocks; + lbalen->flags = CTL_LLF_COMPARE | flags; + ctnio->kern_total_len = num_blocks * lun->be_lun->blocksize; + ctnio->kern_rel_offset = 0; + + CTL_DEBUG_PRINT(("ctl_nvme_compare: calling data_submit()\n")); + retval = lun->backend->data_submit((union ctl_io *)ctnio); + return (retval); +} + +int +ctl_nvme_write_zeroes(struct ctl_nvmeio *ctnio) +{ + struct ctl_lun *lun = CTL_LUN(ctnio); + struct ctl_lba_len_flags *lbalen; + uint64_t lba; + uint32_t num_blocks; + int retval; + + CTL_DEBUG_PRINT(("ctl_nvme_write_zeroes\n")); + + CTL_IO_ASSERT(ctnio, NVME); + MPASS(ctnio->cmd.opc == NVME_OPC_WRITE_ZEROES); + + ctl_nvme_get_lba_len(ctnio, &lba, &num_blocks); + + /* + * The first check is to make sure we're in bounds, the second + * check is to catch wrap-around problems. If the lba + num blocks + * is less than the lba, then we've wrapped around and the block + * range is invalid anyway. + */ + if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) + || ((lba + num_blocks) < lba)) { + ctl_nvme_set_lba_out_of_range(ctnio); + ctl_done((union ctl_io *)ctnio); + return (CTL_RETVAL_COMPLETE); + } + + lbalen = (struct ctl_lba_len_flags *) + &ctnio->io_hdr.ctl_private[CTL_PRIV_LBA_LEN]; + lbalen->lba = lba; + lbalen->len = num_blocks; + lbalen->flags = 0; + retval = lun->backend->config_write((union ctl_io *)ctnio); + + return (retval); +} + +int +ctl_nvme_dataset_management(struct ctl_nvmeio *ctnio) +{ + struct ctl_lun *lun = CTL_LUN(ctnio); + struct nvme_dsm_range *r; + uint64_t lba; + uint32_t len, num_blocks; + u_int i, ranges; + int retval; + + CTL_DEBUG_PRINT(("ctl_nvme_dataset_management\n")); + + CTL_IO_ASSERT(ctnio, NVME); + MPASS(ctnio->cmd.opc == NVME_OPC_DATASET_MANAGEMENT); + + ranges = le32toh(ctnio->cmd.cdw10) & 0xff; + len = ranges * sizeof(struct nvme_dsm_range); + + /* + * If we've got a kernel request that hasn't been malloced yet, + * malloc it and tell the caller the data buffer is here. + */ + if ((ctnio->io_hdr.flags & CTL_FLAG_ALLOCATED) == 0) { + ctnio->kern_data_ptr = malloc(len, M_CTL, M_WAITOK); + ctnio->kern_data_len = len; + ctnio->kern_total_len = len; + ctnio->kern_rel_offset = 0; + ctnio->kern_sg_entries = 0; + ctnio->io_hdr.flags |= CTL_FLAG_ALLOCATED; + ctnio->be_move_done = ctl_config_move_done; + ctl_datamove((union ctl_io *)ctnio); + + return (CTL_RETVAL_COMPLETE); + } + + /* + * Require a flat buffer of the correct size. + */ + if (ctnio->kern_sg_entries > 0 || + ctnio->kern_total_len - ctnio->kern_data_resid != len) + return (CTL_RETVAL_ERROR); + + /* + * Verify that none of the ranges are out of bounds. + */ + r = (struct nvme_dsm_range *)ctnio->kern_data_ptr; + for (i = 0; i < ranges; i++) { + lba = le64toh(r[i].starting_lba); + num_blocks = le32toh(r[i].length); + if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) + || ((lba + num_blocks) < lba)) { + ctl_nvme_set_lba_out_of_range(ctnio); + ctl_done((union ctl_io *)ctnio); + return (CTL_RETVAL_COMPLETE); + } + } + + CTL_DEBUG_PRINT(("ctl_nvme_dataset_management: calling config_write()\n")); + retval = lun->backend->config_write((union ctl_io *)ctnio); + return (retval); +} + +int +ctl_nvme_verify(struct ctl_nvmeio *ctnio) +{ + struct ctl_lun *lun = CTL_LUN(ctnio); + struct ctl_lba_len_flags *lbalen; + uint64_t lba; + uint32_t num_blocks; + int flags; + int retval; + + CTL_DEBUG_PRINT(("ctl_nvme_verify\n")); + + CTL_IO_ASSERT(ctnio, NVME); + MPASS(ctnio->cmd.opc == NVME_OPC_VERIFY); + + flags = 0; + ctl_nvme_get_lba_len(ctnio, &lba, &num_blocks); + if (ctl_nvme_fua(ctnio)) + flags |= CTL_LLF_FUA; + + /* + * The first check is to make sure we're in bounds, the second + * check is to catch wrap-around problems. If the lba + num blocks + * is less than the lba, then we've wrapped around and the block + * range is invalid anyway. + */ + if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) + || ((lba + num_blocks) < lba)) { + ctl_nvme_set_lba_out_of_range(ctnio); + ctl_done((union ctl_io *)ctnio); + return (CTL_RETVAL_COMPLETE); + } + + lbalen = (struct ctl_lba_len_flags *) + &ctnio->io_hdr.ctl_private[CTL_PRIV_LBA_LEN]; + lbalen->lba = lba; + lbalen->len = num_blocks; + lbalen->flags = CTL_LLF_VERIFY | flags; + ctnio->kern_total_len = 0; + ctnio->kern_rel_offset = 0; + + CTL_DEBUG_PRINT(("ctl_nvme_verify: calling data_submit()\n")); + retval = lun->backend->data_submit((union ctl_io *)ctnio); + return (retval); +} + +static const struct ctl_nvme_cmd_entry * +ctl_nvme_get_cmd_entry(struct ctl_nvmeio *ctnio) +{ + const struct ctl_nvme_cmd_entry *entry; + + switch (ctnio->io_hdr.io_type) { + case CTL_IO_NVME: + entry = &nvme_nvm_cmd_table[ctnio->cmd.opc]; + break; + case CTL_IO_NVME_ADMIN: + entry = &nvme_admin_cmd_table[ctnio->cmd.opc]; + break; + default: + __assert_unreachable(); + } + return (entry); +} + +static const struct ctl_nvme_cmd_entry * +ctl_nvme_validate_command(struct ctl_nvmeio *ctnio) +{ + const struct ctl_nvme_cmd_entry *entry; + + entry = ctl_nvme_get_cmd_entry(ctnio); + if (entry->execute == NULL) { + ctl_nvme_set_invalid_opcode(ctnio); + ctl_done((union ctl_io *)ctnio); + return (NULL); + } + + /* Validate fused commands. */ + switch (NVMEV(NVME_CMD_FUSE, ctnio->cmd.fuse)) { + case NVME_FUSE_NORMAL: + break; + case NVME_FUSE_FIRST: + if (ctnio->io_hdr.io_type != CTL_IO_NVME || + ctnio->cmd.opc != NVME_OPC_COMPARE) { + ctl_nvme_set_invalid_field(ctnio); + ctl_done((union ctl_io *)ctnio); + return (NULL); + } + break; + case NVME_FUSE_SECOND: + if (ctnio->io_hdr.io_type != CTL_IO_NVME || + ctnio->cmd.opc != NVME_OPC_COMPARE) { + ctl_nvme_set_invalid_field(ctnio); + ctl_done((union ctl_io *)ctnio); + return (NULL); + } + break; + default: + ctl_nvme_set_invalid_field(ctnio); + ctl_done((union ctl_io *)ctnio); + return (NULL); + } + + return (entry); +} + +/* + * This is a simpler version of ctl_scsiio_lun_check that fails + * requests on a LUN without active media. + * + * Returns true if the command has been completed with an error. + */ +static bool +ctl_nvmeio_lun_check(struct ctl_lun *lun, + const struct ctl_nvme_cmd_entry *entry, struct ctl_nvmeio *ctnio) +{ + mtx_assert(&lun->lun_lock, MA_OWNED); + + if ((entry->flags & CTL_CMD_FLAG_OK_ON_NO_MEDIA) == 0) { + if ((lun->flags & (CTL_LUN_EJECTED | CTL_LUN_NO_MEDIA | + CTL_LUN_STOPPED)) != 0) { + ctl_nvme_set_namespace_not_ready(ctnio); + return (true); + } + } + + return (false); +} + +/* + * Check for blockage against the OOA (Order Of Arrival) queue. + * Assumptions: + * - pending_io is generally either incoming, or on the blocked queue + * - starting I/O is the I/O we want to start the check with. + */ +static ctl_action +ctl_nvme_check_ooa(struct ctl_lun *lun, union ctl_io *pending_io, + union ctl_io **starting_io, union ctl_io **aborted_io) +{ + union ctl_io *ooa_io = *starting_io; + + CTL_IO_ASSERT(pending_io, NVME, NVME_ADMIN); + + mtx_assert(&lun->lun_lock, MA_OWNED); + + *aborted_io = NULL; + + /* + * Aborted commands are not going to be executed and may even + * not report completion, so we don't care about their order. + * Let them complete ASAP to clean the OOA queue. + */ + if (__predict_false(pending_io->io_hdr.flags & CTL_FLAG_ABORT)) + return (CTL_ACTION_PASS); + + /* + * NVMe has rather simple command ordering requirements. In + * particular, there is no requirement on the controller to + * enforce a specific order for overlapping LBAs. The only + * constraint is that fused operations (Compare and Write), + * must be completed as a unit. + * + * To support fused operations, the following strategy is used: + * - the first half of a fused command is not enqueued to rtr + * until the second half is enqueued + * - the second half of a fused command blocks on the first + * half of a fuse command + * - subsequent commands block on the second half of the + * fused command + */ + + /* + * Is the previously submitted command the first half of a + * fused operation? + */ + if (ooa_io != NULL && + NVMEV(NVME_CMD_FUSE, ooa_io->nvmeio.cmd.fuse) == NVME_FUSE_FIRST) { + /* + * If this is the second half, enqueue the first half + * and block the second half on the first half. + */ + if (NVMEV(NVME_CMD_FUSE, pending_io->nvmeio.cmd.fuse) == + NVME_FUSE_SECOND) { + /* + * XXX: Do we need to wait for other rtr requests + * to drain so this is truly atomic? + */ + return (CTL_ACTION_FUSED); + } + + /* Abort the first half. */ + ctl_nvme_set_missing_fused_command(&ooa_io->nvmeio); + *aborted_io = ooa_io; + } else { + switch (NVMEV(NVME_CMD_FUSE, pending_io->nvmeio.cmd.fuse)) { + case NVME_FUSE_FIRST: + /* First half, wait for the second half. */ + return (CTL_ACTION_SKIP); + case NVME_FUSE_SECOND: + /* Second half without a matching first half, abort. */ + ctl_nvme_set_missing_fused_command(&pending_io->nvmeio); + *aborted_io = pending_io; + return (CTL_ACTION_SKIP); + } + } + + /* + * Scan the OOA queue looking for the most recent second half + * of a fused op. + */ + for (; ooa_io != NULL; + ooa_io = (union ctl_io *)LIST_NEXT(&ooa_io->io_hdr, ooa_links)) { + if (NVMEV(NVME_CMD_FUSE, ooa_io->nvmeio.cmd.fuse) == + NVME_FUSE_SECOND) { + *starting_io = ooa_io; + return (CTL_ACTION_BLOCK); + } + } + + *starting_io = NULL; + return (CTL_ACTION_PASS); +} + +static void +ctl_nvmeio_precheck(struct ctl_nvmeio *ctnio) +{ + struct ctl_softc *softc = CTL_SOFTC(ctnio); + struct ctl_lun *lun; + const struct ctl_nvme_cmd_entry *entry; + union ctl_io *bio, *aborted_io; + uint32_t targ_lun; + + lun = NULL; + targ_lun = ctnio->io_hdr.nexus.targ_mapped_lun; + if (targ_lun < ctl_max_luns) + lun = softc->ctl_luns[targ_lun]; + if (lun != NULL) { + /* + * If the LUN is invalid, pretend that it doesn't exist. + * It will go away as soon as all pending I/O has been + * completed. + */ + mtx_lock(&lun->lun_lock); + if (lun->flags & CTL_LUN_DISABLED) { + mtx_unlock(&lun->lun_lock); + lun = NULL; + } + } + CTL_LUN(ctnio) = lun; + if (lun != NULL) { + CTL_BACKEND_LUN(ctnio) = lun->be_lun; + + /* + * Every I/O goes into the OOA queue for a particular LUN, + * and stays there until completion. + */ +#ifdef CTL_TIME_IO + if (LIST_EMPTY(&lun->ooa_queue)) + lun->idle_time += getsbinuptime() - lun->last_busy; +#endif + LIST_INSERT_HEAD(&lun->ooa_queue, &ctnio->io_hdr, ooa_links); + } + + /* Get command entry and return error if it is unsupported. */ + entry = ctl_nvme_validate_command(ctnio); + if (entry == NULL) { + if (lun) + mtx_unlock(&lun->lun_lock); + return; + } + + ctnio->io_hdr.flags &= ~CTL_FLAG_DATA_MASK; + ctnio->io_hdr.flags |= entry->flags & CTL_FLAG_DATA_MASK; + + /* All NVMe commands other than IDENTIFY require a LUN. */ + if (lun == NULL) { + if (entry->flags & CTL_CMD_FLAG_OK_ON_NO_LUN) { + ctnio->io_hdr.flags |= CTL_FLAG_IS_WAS_ON_RTR; + ctl_enqueue_rtr((union ctl_io *)ctnio); + return; + } + + ctl_nvme_set_invalid_namespace(ctnio); + ctl_done((union ctl_io *)ctnio); + CTL_DEBUG_PRINT(("ctl_nvmeio_precheck: bailing out due to invalid LUN\n")); + return; + } else { + /* + * NVMe namespaces can only be backed by T_DIRECT LUNs. + */ + if (lun->be_lun->lun_type != T_DIRECT) { + mtx_unlock(&lun->lun_lock); + ctl_nvme_set_invalid_namespace(ctnio); + ctl_done((union ctl_io *)ctnio); + return; + } + } + + if (ctl_nvmeio_lun_check(lun, entry, ctnio) != 0) { + mtx_unlock(&lun->lun_lock); + ctl_done((union ctl_io *)ctnio); + return; + } + + bio = (union ctl_io *)LIST_NEXT(&ctnio->io_hdr, ooa_links); + switch (ctl_nvme_check_ooa(lun, (union ctl_io *)ctnio, &bio, + &aborted_io)) { + case CTL_ACTION_PASS: + ctnio->io_hdr.flags |= CTL_FLAG_IS_WAS_ON_RTR; + mtx_unlock(&lun->lun_lock); + ctl_enqueue_rtr((union ctl_io *)ctnio); + break; + case CTL_ACTION_FUSED: + /* Block the second half on the first half. */ + ctnio->io_hdr.blocker = bio; + TAILQ_INSERT_TAIL(&bio->io_hdr.blocked_queue, &ctnio->io_hdr, + blocked_links); + + /* Pass the first half. */ + bio->io_hdr.flags |= CTL_FLAG_IS_WAS_ON_RTR; + mtx_unlock(&lun->lun_lock); + ctl_enqueue_rtr(bio); + break; + case CTL_ACTION_SKIP: + mtx_unlock(&lun->lun_lock); + break; + case CTL_ACTION_BLOCK: + ctnio->io_hdr.blocker = bio; + TAILQ_INSERT_TAIL(&bio->io_hdr.blocked_queue, &ctnio->io_hdr, + blocked_links); + mtx_unlock(&lun->lun_lock); + break; + default: + __assert_unreachable(); + } + if (aborted_io != NULL) + ctl_done(aborted_io); +} + +static int +ctl_nvmeio(struct ctl_nvmeio *ctnio) +{ + const struct ctl_nvme_cmd_entry *entry; + int retval; + + CTL_DEBUG_PRINT(("ctl_nvmeio %s opc=%02X\n", + ctnio->io_hdr.io_type == CTL_IO_NVME ? "nvm" : "admin", + ctnio->cmd.opc)); + + entry = ctl_nvme_get_cmd_entry(ctnio); + MPASS(entry != NULL); + + /* + * If this I/O has been aborted, just send it straight to + * ctl_done() without executing it. + */ + if (ctnio->io_hdr.flags & CTL_FLAG_ABORT) { + ctl_done((union ctl_io *)ctnio); + return (CTL_RETVAL_COMPLETE); + } + + /* + * All the checks should have been handled by ctl_nvmeio_precheck(). + * We should be clear now to just execute the I/O. + */ + retval = entry->execute(ctnio); + + return (retval); +} + +/* * For known CDB types, parse the LBA and length. */ static int ctl_get_lba_len(union ctl_io *io, uint64_t *lba, uint64_t *len) { - KASSERT(io->io_hdr.io_type == CTL_IO_SCSI, - ("%s: unexpected I/O type %x", __func__, io->io_hdr.io_type)); + CTL_IO_ASSERT(io, SCSI); switch (io->scsiio.cdb[0]) { case COMPARE_AND_WRITE: { @@ -10923,8 +11618,7 @@ ctl_extent_check_unmap(union ctl_io *io, uint64_t lba2, uint64_t len2) uint64_t lba; uint32_t len; - KASSERT(io->io_hdr.io_type == CTL_IO_SCSI, - ("%s: unexpected I/O type %x", __func__, io->io_hdr.io_type)); + CTL_IO_ASSERT(io, SCSI); /* If not UNMAP -- go other way. */ if (io->scsiio.cdb[0] != UNMAP) @@ -10994,6 +11688,8 @@ static ctl_action ctl_check_for_blockage(struct ctl_lun *lun, union ctl_io *pending_io, const uint8_t *serialize_row, union ctl_io *ooa_io) { + CTL_IO_ASSERT(pending_io, SCSI); + CTL_IO_ASSERT(ooa_io, SCSI); /* * The initiator attempted multiple untagged commands at the same @@ -11102,6 +11798,8 @@ ctl_check_ooa(struct ctl_lun *lun, union ctl_io *pending_io, const uint8_t *serialize_row; ctl_action action; + CTL_IO_ASSERT(pending_io, SCSI); + mtx_assert(&lun->lun_lock, MA_OWNED); /* @@ -11151,7 +11849,7 @@ ctl_check_ooa(struct ctl_lun *lun, union ctl_io *pending_io, * we know for sure that the blocker I/O does no longer count. */ static void -ctl_try_unblock_io(struct ctl_lun *lun, union ctl_io *io, bool skip) +ctl_scsi_try_unblock_io(struct ctl_lun *lun, union ctl_io *io, bool skip) { struct ctl_softc *softc = lun->ctl_softc; union ctl_io *bio, *obio; @@ -11159,6 +11857,8 @@ ctl_try_unblock_io(struct ctl_lun *lun, union ctl_io *io, bool skip) union ctl_ha_msg msg_info; ctl_action action; + CTL_IO_ASSERT(io, SCSI); + mtx_assert(&lun->lun_lock, MA_OWNED); if (io->io_hdr.blocker == NULL) @@ -11244,6 +11944,72 @@ error: } } +static void +ctl_nvme_try_unblock_io(struct ctl_lun *lun, union ctl_io *io, bool skip) +{ + union ctl_io *bio; + const struct ctl_nvme_cmd_entry *entry; + + CTL_IO_ASSERT(io, NVME, NVME_ADMIN); + + mtx_assert(&lun->lun_lock, MA_OWNED); + + if (io->io_hdr.blocker == NULL) + return; + + /* + * If this is the second half of a fused operation, it should + * be the only io on the blocked list. If the first half + * failed, complete the second half with an appropriate error. + */ + bio = io->io_hdr.blocker; + if (NVMEV(NVME_CMD_FUSE, io->nvmeio.cmd.fuse) == NVME_FUSE_SECOND) { + MPASS(io == + (union ctl_io *)TAILQ_FIRST(&bio->io_hdr.blocked_queue)); + MPASS(TAILQ_NEXT(&io->io_hdr, blocked_links) == NULL); + + TAILQ_REMOVE(&bio->io_hdr.blocked_queue, &io->io_hdr, + blocked_links); + if (bio->io_hdr.status != CTL_SUCCESS) { + ctl_nvme_set_failed_fused_command(&io->nvmeio); + ctl_done(io); + return; + } + } else { + /* + * This must be a command that was blocked on the + * second half of a fused operation. + */ + MPASS(NVMEV(NVME_CMD_FUSE, bio->nvmeio.cmd.fuse) == + NVME_FUSE_SECOND); + TAILQ_REMOVE(&bio->io_hdr.blocked_queue, &io->io_hdr, + blocked_links); + } + + entry = ctl_nvme_get_cmd_entry(&io->nvmeio); + if (ctl_nvmeio_lun_check(lun, entry, &io->nvmeio) != 0) { + ctl_done(io); + return; + } + + io->io_hdr.flags |= CTL_FLAG_IS_WAS_ON_RTR; + ctl_enqueue_rtr(io); +} + +static void +ctl_try_unblock_io(struct ctl_lun *lun, union ctl_io *io, bool skip) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + return (ctl_scsi_try_unblock_io(lun, io, skip)); + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + return (ctl_nvme_try_unblock_io(lun, io, skip)); + default: + __assert_unreachable(); + } +} + /* * Try to unblock I/Os blocked by the specified I/O. * @@ -11399,6 +12165,8 @@ bailout: static void ctl_failover_io(union ctl_io *io, int have_lock) { + CTL_IO_ASSERT(io, SCSI); + ctl_set_busy(&io->scsiio); ctl_done(io); } @@ -11955,6 +12723,7 @@ ctl_abort_tasks_lun(struct ctl_lun *lun, uint32_t targ_port, uint32_t init_id, */ LIST_FOREACH(xioh, &lun->ooa_queue, ooa_links) { union ctl_io *xio = (union ctl_io *)xioh; + if ((targ_port == UINT32_MAX || targ_port == xioh->nexus.targ_port) && (init_id == UINT32_MAX || @@ -11966,6 +12735,7 @@ ctl_abort_tasks_lun(struct ctl_lun *lun, uint32_t targ_port, uint32_t init_id, if (!other_sc && !(lun->flags & CTL_LUN_PRIMARY_SC)) { union ctl_ha_msg msg_info; + CTL_IO_ASSERT(xio, SCSI); msg_info.hdr.nexus = xioh->nexus; msg_info.task.task_action = CTL_TASK_ABORT_TASK; msg_info.task.tag_num = xio->scsiio.tag_num; @@ -12106,6 +12876,8 @@ ctl_abort_task(union ctl_io *io) */ LIST_FOREACH(xioh, &lun->ooa_queue, ooa_links) { union ctl_io *xio = (union ctl_io *)xioh; + + CTL_IO_ASSERT(xio, SCSI); if ((xioh->nexus.targ_port != io->io_hdr.nexus.targ_port) || (xioh->nexus.initid != io->io_hdr.nexus.initid) || (xioh->flags & CTL_FLAG_ABORT)) @@ -12177,6 +12949,8 @@ ctl_query_task(union ctl_io *io, int task_set) mtx_unlock(&softc->ctl_lock); LIST_FOREACH(xioh, &lun->ooa_queue, ooa_links) { union ctl_io *xio = (union ctl_io *)xioh; + + CTL_IO_ASSERT(xio, SCSI); if ((xioh->nexus.targ_port != io->io_hdr.nexus.targ_port) || (xioh->nexus.initid != io->io_hdr.nexus.initid) || (xioh->flags & CTL_FLAG_ABORT)) @@ -12290,6 +13064,8 @@ ctl_handle_isc(union ctl_io *io) const struct ctl_cmd_entry *entry; uint32_t targ_lun; + CTL_IO_ASSERT(io, SCSI); + targ_lun = io->io_hdr.nexus.targ_mapped_lun; switch (io->io_hdr.msg_type) { case CTL_MSG_SERIALIZE: @@ -12425,6 +13201,8 @@ ctl_inject_error(struct ctl_lun *lun, union ctl_io *io) { struct ctl_error_desc *desc, *desc2; + CTL_IO_ASSERT(io, SCSI); + mtx_assert(&lun->lun_lock, MA_OWNED); STAILQ_FOREACH_SAFE(desc, &lun->error_list, links, desc2) { @@ -12503,12 +13281,7 @@ ctl_datamove_done_process(union ctl_io *io) { #ifdef CTL_TIME_IO struct bintime cur_bt; -#endif - - KASSERT(io->io_hdr.io_type == CTL_IO_SCSI, - ("%s: unexpected I/O type %x", __func__, io->io_hdr.io_type)); -#ifdef CTL_TIME_IO getbinuptime(&cur_bt); bintime_sub(&cur_bt, &io->io_hdr.dma_start_bt); bintime_add(&io->io_hdr.dma_bt, &cur_bt); @@ -12518,13 +13291,36 @@ ctl_datamove_done_process(union ctl_io *io) if ((io->io_hdr.port_status != 0) && ((io->io_hdr.status & CTL_STATUS_MASK) == CTL_STATUS_NONE || (io->io_hdr.status & CTL_STATUS_MASK) == CTL_SUCCESS)) { - ctl_set_internal_failure(&io->scsiio, /*sks_valid*/ 1, - /*retry_count*/ io->io_hdr.port_status); - } else if (io->scsiio.kern_data_resid != 0 && + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + ctl_set_internal_failure(&io->scsiio, /*sks_valid*/ 1, + /*retry_count*/ io->io_hdr.port_status); + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + if (io->io_hdr.flags & CTL_FLAG_ABORT) + ctl_nvme_set_command_aborted(&io->nvmeio); + else + ctl_nvme_set_data_transfer_error(&io->nvmeio); + break; + default: + __assert_unreachable(); + } + } else if (ctl_kern_data_resid(io) != 0 && (io->io_hdr.flags & CTL_FLAG_DATA_MASK) == CTL_FLAG_DATA_OUT && ((io->io_hdr.status & CTL_STATUS_MASK) == CTL_STATUS_NONE || (io->io_hdr.status & CTL_STATUS_MASK) == CTL_SUCCESS)) { - ctl_set_invalid_field_ciu(&io->scsiio); + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + ctl_set_invalid_field_ciu(&io->scsiio); + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + ctl_nvme_set_data_transfer_error(&io->nvmeio); + break; + default: + __assert_unreachable(); + } } else if (ctl_debug & CTL_DEBUG_CDB_DATA) ctl_data_print(io); } @@ -12534,7 +13330,7 @@ ctl_datamove_done(union ctl_io *io, bool samethr) { ctl_datamove_done_process(io); - io->scsiio.be_move_done(io, samethr); + ctl_be_move_done(io, samethr); } void @@ -12547,7 +13343,7 @@ ctl_datamove(union ctl_io *io) CTL_DEBUG_PRINT(("ctl_datamove\n")); /* No data transferred yet. Frontend must update this when done. */ - io->scsiio.kern_data_resid = io->scsiio.kern_data_len; + ctl_set_kern_data_resid(io, ctl_kern_data_len(io)); #ifdef CTL_TIME_IO getbinuptime(&io->io_hdr.dma_start_bt); @@ -12580,20 +13376,33 @@ ctl_datamove(union ctl_io *io) * the data move. */ if (io->io_hdr.flags & CTL_FLAG_ABORT) { - printf("ctl_datamove: tag 0x%04x on (%u:%u:%u) aborted\n", - io->scsiio.tag_num, io->io_hdr.nexus.initid, - io->io_hdr.nexus.targ_port, - io->io_hdr.nexus.targ_lun); + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + printf("ctl_datamove: tag 0x%jx on (%u:%u:%u) aborted\n", + io->scsiio.tag_num, io->io_hdr.nexus.initid, + io->io_hdr.nexus.targ_port, + io->io_hdr.nexus.targ_lun); + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + printf("ctl_datamove: CID 0x%x on (%u:%u:%u) aborted\n", + le16toh(io->nvmeio.cmd.cid), + io->io_hdr.nexus.initid, io->io_hdr.nexus.targ_port, + io->io_hdr.nexus.targ_lun); + break; + default: + __assert_unreachable(); + } io->io_hdr.port_status = 31337; ctl_datamove_done_process(io); - io->scsiio.be_move_done(io, true); + ctl_be_move_done(io, true); return; } /* Don't confuse frontend with zero length data move. */ - if (io->scsiio.kern_data_len == 0) { + if (ctl_kern_data_len(io) == 0) { ctl_datamove_done_process(io); - io->scsiio.be_move_done(io, true); + ctl_be_move_done(io, true); return; } @@ -12609,6 +13418,8 @@ ctl_send_datamove_done(union ctl_io *io, int have_lock) struct bintime cur_bt; #endif + CTL_IO_ASSERT(io, SCSI); + memset(&msg, 0, sizeof(msg)); msg.hdr.msg_type = CTL_MSG_DATAMOVE_DONE; msg.hdr.original_sc = io; @@ -12651,6 +13462,7 @@ ctl_datamove_remote_write_cb(struct ctl_ha_dt_req *rq) uint32_t i; io = rq->context; + CTL_IO_ASSERT(io, SCSI); if (rq->ret != CTL_HA_STATUS_SUCCESS) { printf("%s: ISC DMA write failed with error %d", __func__, @@ -12695,6 +13507,8 @@ ctl_datamove_remote_write(union ctl_io *io) int retval; void (*fe_datamove)(union ctl_io *io); + CTL_IO_ASSERT(io, SCSI); + /* * - Get the data from the host/HBA into local memory. * - DMA memory from the local controller to the remote controller. @@ -12723,6 +13537,8 @@ ctl_datamove_remote_dm_read_cb(union ctl_io *io, bool samethr) { uint32_t i; + CTL_IO_ASSERT(io, SCSI); + for (i = 0; i < io->scsiio.kern_sg_entries; i++) free(CTL_LSGLT(io)[i].addr, M_CTL); free(CTL_RSGL(io), M_CTL); @@ -12745,6 +13561,7 @@ ctl_datamove_remote_read_cb(struct ctl_ha_dt_req *rq) void (*fe_datamove)(union ctl_io *io); io = rq->context; + CTL_IO_ASSERT(io, SCSI); if (rq->ret != CTL_HA_STATUS_SUCCESS) { printf("%s: ISC DMA read failed with error %d\n", __func__, @@ -12779,6 +13596,8 @@ ctl_datamove_remote_sgl_setup(union ctl_io *io) int retval; int i; + CTL_IO_ASSERT(io, SCSI); + retval = 0; local_sglist = CTL_LSGL(io); len_to_go = io->scsiio.kern_data_len; @@ -12816,6 +13635,8 @@ ctl_datamove_remote_xfer(union ctl_io *io, unsigned command, rq = ctl_dt_req_alloc(); + CTL_IO_ASSERT(io, SCSI); + /* * If we failed to allocate the request, and if the DMA didn't fail * anyway, set busy status. This is just a resource allocation @@ -12949,7 +13770,7 @@ ctl_datamove_remote_read(union ctl_io *io) * datamove done message, or call the callback with an * error if there is a problem. */ - for (i = 0; i < io->scsiio.kern_sg_entries; i++) + for (i = 0; i < ctl_kern_sg_entries(io); i++) free(CTL_LSGLT(io)[i].addr, M_CTL); free(CTL_RSGL(io), M_CTL); CTL_RSGL(io) = NULL; @@ -12967,6 +13788,7 @@ ctl_datamove_remote_read(union ctl_io *io) static void ctl_datamove_remote(union ctl_io *io) { + CTL_IO_ASSERT(io, SCSI); mtx_assert(&((struct ctl_softc *)CTL_SOFTC(io))->ctl_lock, MA_NOTOWNED); @@ -12982,7 +13804,7 @@ ctl_datamove_remote(union ctl_io *io) * have been done if need be on the other controller. */ if (io->io_hdr.flags & CTL_FLAG_ABORT) { - printf("%s: tag 0x%04x on (%u:%u:%u) aborted\n", __func__, + printf("%s: tag 0x%jx on (%u:%u:%u) aborted\n", __func__, io->scsiio.tag_num, io->io_hdr.nexus.initid, io->io_hdr.nexus.targ_port, io->io_hdr.nexus.targ_lun); @@ -13019,28 +13841,10 @@ ctl_process_done(union ctl_io *io) char path_str[64]; struct sbuf sb; - ctl_scsi_path_string(io, path_str, sizeof(path_str)); + ctl_scsi_path_string(&io->io_hdr, path_str, sizeof(path_str)); sbuf_new(&sb, str, sizeof(str), SBUF_FIXEDLEN); - sbuf_cat(&sb, path_str); - switch (io->io_hdr.io_type) { - case CTL_IO_SCSI: - ctl_scsi_command_string(&io->scsiio, NULL, &sb); - sbuf_printf(&sb, "\n"); - sbuf_cat(&sb, path_str); - sbuf_printf(&sb, "Tag: 0x%04x/%d, Prio: %d\n", - io->scsiio.tag_num, io->scsiio.tag_type, - io->scsiio.priority); - break; - case CTL_IO_TASK: - sbuf_printf(&sb, "Task Action: %d Tag: 0x%04x/%d\n", - io->taskio.task_action, - io->taskio.tag_num, io->taskio.tag_type); - break; - default: - panic("%s: Invalid CTL I/O type %d\n", - __func__, io->io_hdr.io_type); - } + ctl_io_sbuf(io, &sb); sbuf_cat(&sb, path_str); sbuf_printf(&sb, "ctl_process_done: %jd seconds\n", (intmax_t)time_uptime - io->io_hdr.start_time); @@ -13051,6 +13855,8 @@ ctl_process_done(union ctl_io *io) switch (io->io_hdr.io_type) { case CTL_IO_SCSI: + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: break; case CTL_IO_TASK: if (ctl_debug & CTL_DEBUG_INFO) @@ -13081,6 +13887,8 @@ ctl_process_done(union ctl_io *io) uint8_t mrie = lun->MODE_IE.mrie; uint8_t per = ((lun->MODE_RWER.byte3 & SMS_RWER_PER) || (lun->MODE_VER.byte3 & SMS_VER_PER)); + + CTL_IO_ASSERT(io, SCSI); if (((mrie == SIEP_MRIE_REC_COND && per) || mrie == SIEP_MRIE_REC_UNCOND || mrie == SIEP_MRIE_NO_SENSE) && @@ -13114,7 +13922,9 @@ ctl_process_done(union ctl_io *io) * XXX KDM should we also track I/O latency? */ if ((io->io_hdr.status & CTL_STATUS_MASK) == CTL_SUCCESS && - io->io_hdr.io_type == CTL_IO_SCSI) { + (io->io_hdr.io_type == CTL_IO_SCSI || + io->io_hdr.io_type == CTL_IO_NVME || + io->io_hdr.io_type == CTL_IO_NVME_ADMIN)) { int type; #ifdef CTL_TIME_IO struct bintime bt; @@ -13131,7 +13941,7 @@ ctl_process_done(union ctl_io *io) else type = CTL_STATS_NO_IO; - lun->stats.bytes[type] += io->scsiio.kern_total_len; + lun->stats.bytes[type] += ctl_kern_total_len(io); lun->stats.operations[type] ++; lun->stats.dmas[type] += io->io_hdr.num_dmas; #ifdef CTL_TIME_IO @@ -13140,7 +13950,7 @@ ctl_process_done(union ctl_io *io) #endif mtx_lock(&port->port_lock); - port->stats.bytes[type] += io->scsiio.kern_total_len; + port->stats.bytes[type] += ctl_kern_total_len(io); port->stats.operations[type] ++; port->stats.dmas[type] += io->io_hdr.num_dmas; #ifdef CTL_TIME_IO @@ -13184,8 +13994,19 @@ bailout: * properly. The FETD is responsible for freeing the I/O and doing * whatever it needs to do to clean up its state. */ - if (io->io_hdr.flags & CTL_FLAG_ABORT) - ctl_set_task_aborted(&io->scsiio); + if (io->io_hdr.flags & CTL_FLAG_ABORT) { + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + ctl_set_task_aborted(&io->scsiio); + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + ctl_nvme_set_command_aborted(&io->nvmeio); + break; + default: + __assert_unreachable(); + } + } /* * If enabled, print command error status. @@ -13227,6 +14048,7 @@ ctl_queue_sense(union ctl_io *io) uint32_t initidx, p, targ_lun; CTL_DEBUG_PRINT(("ctl_queue_sense\n")); + CTL_IO_ASSERT(io, SCSI); targ_lun = ctl_lun_map_from_port(port, io->io_hdr.nexus.targ_lun); @@ -13274,7 +14096,22 @@ ctl_queue(union ctl_io *io) { struct ctl_port *port = CTL_PORT(io); - CTL_DEBUG_PRINT(("ctl_queue cdb[0]=%02X\n", io->scsiio.cdb[0])); + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + case CTL_IO_TASK: + CTL_DEBUG_PRINT(("ctl_queue cdb[0]=%02X\n", io->scsiio.cdb[0])); + break; + case CTL_IO_NVME: + CTL_DEBUG_PRINT(("ctl_queue nvme nvm cmd=%02X\n", + io->nvmeio.cmd.opc)); + break; + case CTL_IO_NVME_ADMIN: + CTL_DEBUG_PRINT(("ctl_queue nvme admin cmd=%02X\n", + io->nvmeio.cmd.opc)); + break; + default: + break; + } #ifdef CTL_TIME_IO io->io_hdr.start_time = time_uptime; @@ -13288,6 +14125,8 @@ ctl_queue(union ctl_io *io) switch (io->io_hdr.io_type) { case CTL_IO_SCSI: case CTL_IO_TASK: + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: if (ctl_debug & CTL_DEBUG_CDB) ctl_io_print(io); ctl_enqueue_incoming(io); @@ -13327,6 +14166,12 @@ ctl_run(union ctl_io *io) ctl_io_print(io); ctl_run_task(io); break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + if (ctl_debug & CTL_DEBUG_CDB) + ctl_io_print(io); + ctl_nvmeio_precheck(&io->nvmeio); + break; default: printf("ctl_run: unknown I/O type %d\n", io->io_hdr.io_type); return (EINVAL); @@ -13370,22 +14215,54 @@ ctl_done(union ctl_io *io) */ #if 0 if (io->io_hdr.flags & CTL_FLAG_ALREADY_DONE) { - printf("%s: type %d msg %d cdb %x iptl: " - "%u:%u:%u tag 0x%04x " - "flag %#x status %x\n", - __func__, - io->io_hdr.io_type, - io->io_hdr.msg_type, - io->scsiio.cdb[0], - io->io_hdr.nexus.initid, - io->io_hdr.nexus.targ_port, - io->io_hdr.nexus.targ_lun, - (io->io_hdr.io_type == - CTL_IO_TASK) ? - io->taskio.tag_num : - io->scsiio.tag_num, - io->io_hdr.flags, - io->io_hdr.status); + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + case CTL_IO_TASK: + printf("%s: type %d msg %d cdb %x iptl: " + "%u:%u:%u tag 0x%04lx " + "flag %#x status %x\n", + __func__, + io->io_hdr.io_type, + io->io_hdr.msg_type, + io->scsiio.cdb[0], + io->io_hdr.nexus.initid, + io->io_hdr.nexus.targ_port, + io->io_hdr.nexus.targ_lun, + (io->io_hdr.io_type == CTL_IO_TASK) ? + io->taskio.tag_num : + io->scsiio.tag_num, + io->io_hdr.flags, + io->io_hdr.status); + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + printf("%s: type %d msg %d opc %x iptl: " + "%u:%u:%u cid 0x%04x " + "flag %#x status %x\n", + __func__, + io->io_hdr.io_type, + io->io_hdr.msg_type, + io->nvmeio.cmd.opc, + io->io_hdr.nexus.initid, + io->io_hdr.nexus.targ_port, + io->io_hdr.nexus.targ_lun, + io->nvmeio.cmd.cid, + io->io_hdr.flags, + io->io_hdr.status); + break; + default: + printf("%s: type %d msg %d iptl: " + "%u:%u:%u flag %#x status %x\n", + __func__, + io->io_hdr.io_type, + io->io_hdr.msg_type, + io->io_hdr.nexus.initid, + io->io_hdr.nexus.targ_port, + io->io_hdr.nexus.targ_lun, + io->io_hdr.flags, + io->io_hdr.status); + break; + } } else io->io_hdr.flags |= CTL_FLAG_ALREADY_DONE; #endif @@ -13464,19 +14341,41 @@ ctl_work_thread(void *arg) if (io != NULL) { STAILQ_REMOVE_HEAD(&thr->incoming_queue, links); mtx_unlock(&thr->queue_lock); - if (io->io_hdr.io_type == CTL_IO_TASK) + switch (io->io_hdr.io_type) { + case CTL_IO_TASK: ctl_run_task(io); - else + break; + case CTL_IO_SCSI: ctl_scsiio_precheck(&io->scsiio); + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + ctl_nvmeio_precheck(&io->nvmeio); + break; + default: + __assert_unreachable(); + } continue; } io = (union ctl_io *)STAILQ_FIRST(&thr->rtr_queue); if (io != NULL) { STAILQ_REMOVE_HEAD(&thr->rtr_queue, links); mtx_unlock(&thr->queue_lock); - retval = ctl_scsiio(&io->scsiio); - if (retval != CTL_RETVAL_COMPLETE) - CTL_DEBUG_PRINT(("ctl_scsiio failed\n")); + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + retval = ctl_scsiio(&io->scsiio); + if (retval != CTL_RETVAL_COMPLETE) + CTL_DEBUG_PRINT(("ctl_scsiio failed\n")); + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + retval = ctl_nvmeio(&io->nvmeio); + if (retval != CTL_RETVAL_COMPLETE) + CTL_DEBUG_PRINT(("ctl_nvmeio failed\n")); + break; + default: + __assert_unreachable(); + } continue; } diff --git a/sys/cam/ctl/ctl.h b/sys/cam/ctl/ctl.h index be3e4a37b157..4b0ae45d6699 100644 --- a/sys/cam/ctl/ctl.h +++ b/sys/cam/ctl/ctl.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003 Silicon Graphics International Corp. * All rights reserved. @@ -30,7 +30,6 @@ * POSSIBILITY OF SUCH DAMAGES. * * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl.h#5 $ - * $FreeBSD$ */ /* * Function definitions used both within CTL and potentially in various CTL @@ -56,6 +55,7 @@ typedef enum { CTL_PORT_ISCSI = 0x10, CTL_PORT_SAS = 0x20, CTL_PORT_UMASS = 0x40, + CTL_PORT_NVMF = 0x80, CTL_PORT_ALL = 0xff, CTL_PORT_ISC = 0x100 // FC port for inter-shelf communication } ctl_port_type; @@ -130,7 +130,9 @@ typedef enum { #ifdef _KERNEL +#ifdef MALLOC_DECLARE /* from malloc.h */ MALLOC_DECLARE(M_CTL); +#endif struct ctl_page_index; @@ -138,9 +140,13 @@ struct ctl_page_index; SYSCTL_DECL(_kern_cam_ctl); #endif +struct cdev; struct ctl_lun; struct ctl_port; struct ctl_softc; +struct ctl_scsiio; +struct sbuf; +union ctl_io; /* * Put a string into an sbuf, escaping characters that are illegal or not diff --git a/sys/cam/ctl/ctl_backend.c b/sys/cam/ctl/ctl_backend.c index b7f154f6bfad..a2249b5d8f44 100644 --- a/sys/cam/ctl/ctl_backend.c +++ b/sys/cam/ctl/ctl_backend.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003 Silicon Graphics International Corp. * All rights reserved. @@ -37,9 +37,6 @@ * Author: Ken Merry <ken@FreeBSD.org> */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> diff --git a/sys/cam/ctl/ctl_backend.h b/sys/cam/ctl/ctl_backend.h index fe4e7f5df1d0..f3d65c34f2ac 100644 --- a/sys/cam/ctl/ctl_backend.h +++ b/sys/cam/ctl/ctl_backend.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003 Silicon Graphics International Corp. * Copyright (c) 2014-2017 Alexander Motin <mav@FreeBSD.org> @@ -31,7 +31,6 @@ * POSSIBILITY OF SUCH DAMAGES. * * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_backend.h#2 $ - * $FreeBSD$ */ /* * CTL backend driver definitions @@ -243,6 +242,17 @@ int ctl_lun_secondary(struct ctl_be_lun *be_lun); */ void ctl_lun_capacity_changed(struct ctl_be_lun *be_lun); +/* + * Populate unique ID fields in NVMe namespace data for a LUN. + */ +void ctl_lun_nsdata_ids(struct ctl_be_lun *be_lun, + struct nvme_namespace_data *nsdata); + +/* + * Populate the NVMe namespace identification descriptor list for a LUN. + */ +void ctl_lun_nvme_ids(struct ctl_be_lun *be_lun, void *data); + #endif /* _KERNEL */ #endif /* _CTL_BACKEND_H_ */ diff --git a/sys/cam/ctl/ctl_backend_block.c b/sys/cam/ctl/ctl_backend_block.c index 61c6c9274d97..55a5ce0d047a 100644 --- a/sys/cam/ctl/ctl_backend_block.c +++ b/sys/cam/ctl/ctl_backend_block.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003 Silicon Graphics International Corp. * Copyright (c) 2009-2011 Spectra Logic Corporation @@ -45,9 +45,6 @@ * * Author: Ken Merry <ken@FreeBSD.org> */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> @@ -122,6 +119,7 @@ __FBSDID("$FreeBSD$"); ((struct ctl_ptr_len_flags *)&(io)->io_hdr.ctl_private[CTL_PRIV_BACKEND]) #define ARGS(io) \ ((struct ctl_lba_len_flags *)&(io)->io_hdr.ctl_private[CTL_PRIV_LBA_LEN]) +#define DSM_RANGE(io) ((io)->io_hdr.ctl_private[CTL_PRIV_LBA_LEN].integer) SDT_PROVIDER_DEFINE(cbb); @@ -393,6 +391,39 @@ ctl_complete_beio(struct ctl_be_block_io *beio) } } +static void +ctl_be_block_io_error(union ctl_io *io, int bio_cmd, uint16_t retry_count) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + if (bio_cmd == BIO_FLUSH) { + /* XXX KDM is there is a better error here? */ + ctl_set_internal_failure(&io->scsiio, + /*sks_valid*/ 1, + retry_count); + } else { + ctl_set_medium_error(&io->scsiio, bio_cmd == BIO_READ); + } + break; + case CTL_IO_NVME: + switch (bio_cmd) { + case BIO_FLUSH: + case BIO_WRITE: + ctl_nvme_set_write_fault(&io->nvmeio); + break; + case BIO_READ: + ctl_nvme_set_unrecoverable_read_error(&io->nvmeio); + break; + default: + ctl_nvme_set_internal_error(&io->nvmeio); + break; + } + break; + default: + __assert_unreachable(); + } +} + static size_t cmp(uint8_t *a, uint8_t *b, size_t size) { @@ -411,7 +442,6 @@ ctl_be_block_compare(union ctl_io *io) struct ctl_be_block_io *beio; uint64_t off, res; int i; - uint8_t info[8]; beio = (struct ctl_be_block_io *)PRIV(io)->ptr; off = 0; @@ -424,15 +454,9 @@ ctl_be_block_compare(union ctl_io *io) break; } if (i < beio->num_segs) { - scsi_u64to8b(off, info); - ctl_set_sense(&io->scsiio, /*current_error*/ 1, - /*sense_key*/ SSD_KEY_MISCOMPARE, - /*asc*/ 0x1D, /*ascq*/ 0x00, - /*type*/ SSD_ELEM_INFO, - /*size*/ sizeof(info), /*data*/ &info, - /*type*/ SSD_ELEM_NONE); + ctl_io_set_compare_failure(io, off); } else - ctl_set_success(&io->scsiio); + ctl_io_set_success(io); } static int @@ -445,7 +469,7 @@ ctl_be_block_move_done(union ctl_io *io, bool samethr) beio = (struct ctl_be_block_io *)PRIV(io)->ptr; DPRINTF("entered\n"); - io->scsiio.kern_rel_offset += io->scsiio.kern_data_len; + ctl_add_kern_rel_offset(io, ctl_kern_data_len(io)); /* * We set status at this point for read and compare commands. @@ -454,7 +478,7 @@ ctl_be_block_move_done(union ctl_io *io, bool samethr) (io->io_hdr.status & CTL_STATUS_MASK) == CTL_STATUS_NONE) { lbalen = ARGS(io); if (lbalen->flags & CTL_LLF_READ) { - ctl_set_success(&io->scsiio); + ctl_io_set_success(io); } else if (lbalen->flags & CTL_LLF_COMPARE) { /* We have two data blocks ready for comparison. */ ctl_be_block_compare(io); @@ -548,19 +572,14 @@ ctl_be_block_biodone(struct bio *bio) error = beio->first_error; if (error != 0) { if (error == EOPNOTSUPP) { - ctl_set_invalid_opcode(&io->scsiio); + ctl_io_set_invalid_opcode(io); } else if (error == ENOSPC || error == EDQUOT) { - ctl_set_space_alloc_fail(&io->scsiio); + ctl_io_set_space_alloc_fail(io); } else if (error == EROFS || error == EACCES) { - ctl_set_hw_write_protected(&io->scsiio); - } else if (beio->bio_cmd == BIO_FLUSH) { - /* XXX KDM is there is a better error here? */ - ctl_set_internal_failure(&io->scsiio, - /*sks_valid*/ 1, - /*retry_count*/ 0xbad2); + ctl_io_set_hw_write_protected(io); } else { - ctl_set_medium_error(&io->scsiio, - beio->bio_cmd == BIO_READ); + ctl_be_block_io_error(io, beio->bio_cmd, + /*retry_count*/ 0xbad2); } ctl_complete_beio(beio); return; @@ -574,12 +593,12 @@ ctl_be_block_biodone(struct bio *bio) || (beio->bio_cmd == BIO_FLUSH) || (beio->bio_cmd == BIO_DELETE) || (ARGS(io)->flags & CTL_LLF_VERIFY)) { - ctl_set_success(&io->scsiio); + ctl_io_set_success(io); ctl_complete_beio(beio); } else { if ((ARGS(io)->flags & CTL_LLF_READ) && beio->beio_cont == NULL) { - ctl_set_success(&io->scsiio); + ctl_io_set_success(io); if (cbe_lun->serseq >= CTL_LUN_SERSEQ_SOFT) ctl_serseq_done(io); } @@ -617,12 +636,10 @@ ctl_be_block_flush_file(struct ctl_be_block_lun *be_lun, mtx_unlock(&be_lun->io_lock); if (error == 0) - ctl_set_success(&io->scsiio); + ctl_io_set_success(io); else { - /* XXX KDM is there is a better error here? */ - ctl_set_internal_failure(&io->scsiio, - /*sks_valid*/ 1, - /*retry_count*/ 0xbad1); + ctl_be_block_io_error(io, BIO_FLUSH, + /*retry_count*/ 0xbad1); } ctl_complete_beio(beio); @@ -707,7 +724,7 @@ ctl_be_block_dispatch_file(struct ctl_be_block_lun *be_lun, SDT_PROBE0(cbb, , read, file_done); if (error == 0 && xuio.uio_resid > 0) { /* - * If we red less then requested (EOF), then + * If we read less then requested (EOF), then * we should clean the rest of the buffer. */ s = beio->io_len - xuio.uio_resid; @@ -762,12 +779,11 @@ ctl_be_block_dispatch_file(struct ctl_be_block_lun *be_lun, */ if (error != 0) { if (error == ENOSPC || error == EDQUOT) { - ctl_set_space_alloc_fail(&io->scsiio); + ctl_io_set_space_alloc_fail(io); } else if (error == EROFS || error == EACCES) { - ctl_set_hw_write_protected(&io->scsiio); + ctl_io_set_hw_write_protected(io); } else { - ctl_set_medium_error(&io->scsiio, - beio->bio_cmd == BIO_READ); + ctl_be_block_io_error(io, beio->bio_cmd, 0); } ctl_complete_beio(beio); return; @@ -779,12 +795,12 @@ ctl_be_block_dispatch_file(struct ctl_be_block_lun *be_lun, */ if ((beio->bio_cmd == BIO_WRITE) || (ARGS(io)->flags & CTL_LLF_VERIFY)) { - ctl_set_success(&io->scsiio); + ctl_io_set_success(io); ctl_complete_beio(beio); } else { if ((ARGS(io)->flags & CTL_LLF_READ) && beio->beio_cont == NULL) { - ctl_set_success(&io->scsiio); + ctl_io_set_success(io); if (cbe_lun->serseq > CTL_LUN_SERSEQ_SOFT) ctl_serseq_done(io); } @@ -804,6 +820,8 @@ ctl_be_block_gls_file(struct ctl_be_block_lun *be_lun, DPRINTF("entered\n"); + CTL_IO_ASSERT(io, SCSI); + off = roff = ((off_t)lbalen->lba) * be_lun->cbe_lun.blocksize; vn_lock(be_lun->vn, LK_SHARED | LK_RETRY); error = VOP_IOCTL(be_lun->vn, FIOSEEKHOLE, &off, @@ -921,18 +939,18 @@ ctl_be_block_unmap_file(struct ctl_be_block_lun *be_lun, */ switch (error) { case 0: - ctl_set_success(&io->scsiio); + ctl_io_set_success(io); break; case ENOSPC: case EDQUOT: - ctl_set_space_alloc_fail(&io->scsiio); + ctl_io_set_space_alloc_fail(io); break; case EROFS: case EACCES: - ctl_set_hw_write_protected(&io->scsiio); + ctl_io_set_hw_write_protected(io); break; default: - ctl_set_medium_error(&io->scsiio, false); + ctl_be_block_io_error(io, BIO_DELETE, 0); } ctl_complete_beio(beio); } @@ -1011,12 +1029,11 @@ ctl_be_block_dispatch_zvol(struct ctl_be_block_lun *be_lun, */ if (error != 0) { if (error == ENOSPC || error == EDQUOT) { - ctl_set_space_alloc_fail(&io->scsiio); + ctl_io_set_space_alloc_fail(io); } else if (error == EROFS || error == EACCES) { - ctl_set_hw_write_protected(&io->scsiio); + ctl_io_set_hw_write_protected(io); } else { - ctl_set_medium_error(&io->scsiio, - beio->bio_cmd == BIO_READ); + ctl_be_block_io_error(io, beio->bio_cmd, 0); } ctl_complete_beio(beio); return; @@ -1028,12 +1045,12 @@ ctl_be_block_dispatch_zvol(struct ctl_be_block_lun *be_lun, */ if ((beio->bio_cmd == BIO_WRITE) || (ARGS(io)->flags & CTL_LLF_VERIFY)) { - ctl_set_success(&io->scsiio); + ctl_io_set_success(io); ctl_complete_beio(beio); } else { if ((ARGS(io)->flags & CTL_LLF_READ) && beio->beio_cont == NULL) { - ctl_set_success(&io->scsiio); + ctl_io_set_success(io); if (cbe_lun->serseq > CTL_LUN_SERSEQ_SOFT) ctl_serseq_done(io); } @@ -1055,6 +1072,8 @@ ctl_be_block_gls_zvol(struct ctl_be_block_lun *be_lun, DPRINTF("entered\n"); + CTL_IO_ASSERT(io, SCSI); + csw = devvn_refthread(be_lun->vn, &dev, &ref); if (csw == NULL) { status = 0; /* unknown up to the end */ @@ -1310,6 +1329,39 @@ ctl_be_block_getattr_dev(struct ctl_be_block_lun *be_lun, const char *attrname) } static void +ctl_be_block_namespace_data(struct ctl_be_block_lun *be_lun, + union ctl_io *io) +{ + struct ctl_be_lun *cbe_lun = &be_lun->cbe_lun; + struct nvme_namespace_data *nsdata; + + nsdata = (struct nvme_namespace_data *)io->nvmeio.kern_data_ptr; + memset(nsdata, 0, sizeof(*nsdata)); + nsdata->nsze = htole64(be_lun->size_blocks); + nsdata->ncap = nsdata->nsze; + nsdata->nuse = nsdata->nsze; + nsdata->nlbaf = 1 - 1; + nsdata->dlfeat = NVMEM(NVME_NS_DATA_DLFEAT_DWZ) | + NVMEF(NVME_NS_DATA_DLFEAT_READ, NVME_NS_DATA_DLFEAT_READ_00); + nsdata->flbas = NVMEF(NVME_NS_DATA_FLBAS_FORMAT, 0); + nsdata->lbaf[0] = NVMEF(NVME_NS_DATA_LBAF_LBADS, + ffs(cbe_lun->blocksize) - 1); + + ctl_lun_nsdata_ids(cbe_lun, nsdata); + ctl_config_read_done(io); +} + +static void +ctl_be_block_nvme_ids(struct ctl_be_block_lun *be_lun, + union ctl_io *io) +{ + struct ctl_be_lun *cbe_lun = &be_lun->cbe_lun; + + ctl_lun_nvme_ids(cbe_lun, io->nvmeio.kern_data_ptr); + ctl_config_read_done(io); +} + +static void ctl_be_block_cw_dispatch_sync(struct ctl_be_block_lun *be_lun, union ctl_io *io) { @@ -1362,6 +1414,8 @@ ctl_be_block_cw_dispatch_ws(struct ctl_be_block_lun *be_lun, DPRINTF("entered\n"); + CTL_IO_ASSERT(io, SCSI); + beio = (struct ctl_be_block_io *)PRIV(io)->ptr; lbalen = ARGS(io); @@ -1452,13 +1506,15 @@ ctl_be_block_cw_dispatch_ws(struct ctl_be_block_lun *be_lun, static void ctl_be_block_cw_dispatch_unmap(struct ctl_be_block_lun *be_lun, - union ctl_io *io) + union ctl_io *io) { struct ctl_be_block_io *beio; struct ctl_ptr_len_flags *ptrlen; DPRINTF("entered\n"); + CTL_IO_ASSERT(io, SCSI); + beio = (struct ctl_be_block_io *)PRIV(io)->ptr; ptrlen = (struct ctl_ptr_len_flags *)&io->io_hdr.ctl_private[CTL_PRIV_LBA_LEN]; @@ -1483,7 +1539,187 @@ ctl_be_block_cw_dispatch_unmap(struct ctl_be_block_lun *be_lun, } static void -ctl_be_block_cr_done(struct ctl_be_block_io *beio) +ctl_be_block_cw_dispatch_flush(struct ctl_be_block_lun *be_lun, + union ctl_io *io) +{ + struct ctl_be_block_io *beio; + + DPRINTF("entered\n"); + beio = (struct ctl_be_block_io *)PRIV(io)->ptr; + + beio->io_len = be_lun->size_bytes; + beio->io_offset = 0; + beio->io_arg = 1; + beio->bio_cmd = BIO_FLUSH; + beio->ds_trans_type = DEVSTAT_NO_DATA; + DPRINTF("FLUSH\n"); + be_lun->lun_flush(be_lun, beio); +} + +static void +ctl_be_block_cw_dispatch_wu(struct ctl_be_block_lun *be_lun, + union ctl_io *io) +{ + struct ctl_be_lun *cbe_lun = &be_lun->cbe_lun; + struct ctl_be_block_io *beio; + struct ctl_lba_len_flags *lbalen; + + CTL_IO_ASSERT(io, NVME); + + beio = (struct ctl_be_block_io *)PRIV(io)->ptr; + lbalen = ARGS(io); + + /* + * XXX: Not quite right as reads will return zeroes rather + * than failing. + */ + beio->io_offset = lbalen->lba * cbe_lun->blocksize; + beio->io_len = (uint64_t)lbalen->len * cbe_lun->blocksize; + beio->bio_cmd = BIO_DELETE; + beio->ds_trans_type = DEVSTAT_FREE; + + be_lun->unmap(be_lun, beio); +} + +static void +ctl_be_block_cw_dispatch_wz(struct ctl_be_block_lun *be_lun, + union ctl_io *io) +{ + struct ctl_be_block_softc *softc = be_lun->softc; + struct ctl_be_lun *cbe_lun = &be_lun->cbe_lun; + struct ctl_be_block_io *beio; + struct ctl_lba_len_flags *lbalen; + uint64_t len_left, lba; + uint32_t pb, pbo, adj; + int i, seglen; + + DPRINTF("entered\n"); + + CTL_IO_ASSERT(io, NVME); + + beio = (struct ctl_be_block_io *)PRIV(io)->ptr; + lbalen = ARGS(io); + + if ((le32toh(io->nvmeio.cmd.cdw12) & (1U << 25)) != 0 && + be_lun->unmap != NULL) { + beio->io_offset = lbalen->lba * cbe_lun->blocksize; + beio->io_len = (uint64_t)lbalen->len * cbe_lun->blocksize; + beio->bio_cmd = BIO_DELETE; + beio->ds_trans_type = DEVSTAT_FREE; + + be_lun->unmap(be_lun, beio); + return; + } + + beio->bio_cmd = BIO_WRITE; + beio->ds_trans_type = DEVSTAT_WRITE; + + DPRINTF("WRITE ZEROES at LBA %jx len %u\n", + (uintmax_t)lbalen->lba, lbalen->len); + + pb = cbe_lun->blocksize << be_lun->cbe_lun.pblockexp; + if (be_lun->cbe_lun.pblockoff > 0) + pbo = pb - cbe_lun->blocksize * be_lun->cbe_lun.pblockoff; + else + pbo = 0; + len_left = (uint64_t)lbalen->len * cbe_lun->blocksize; + for (i = 0, lba = 0; i < CTLBLK_MAX_SEGS && len_left > 0; i++) { + /* + * Setup the S/G entry for this chunk. + */ + seglen = MIN(CTLBLK_MAX_SEG, len_left); + if (pb > cbe_lun->blocksize) { + adj = ((lbalen->lba + lba) * cbe_lun->blocksize + + seglen - pbo) % pb; + if (seglen > adj) + seglen -= adj; + else + seglen -= seglen % cbe_lun->blocksize; + } else + seglen -= seglen % cbe_lun->blocksize; + ctl_alloc_seg(softc, &beio->sg_segs[i], seglen); + + DPRINTF("segment %d addr %p len %zd\n", i, + beio->sg_segs[i].addr, beio->sg_segs[i].len); + + beio->num_segs++; + len_left -= seglen; + + memset(beio->sg_segs[i].addr, 0, seglen); + lba += seglen / cbe_lun->blocksize; + } + + beio->io_offset = lbalen->lba * cbe_lun->blocksize; + beio->io_len = lba * cbe_lun->blocksize; + + /* We can not do all in one run. Correct and schedule rerun. */ + if (len_left > 0) { + lbalen->lba += lba; + lbalen->len -= lba; + beio->beio_cont = ctl_be_block_cw_done_ws; + } + + be_lun->dispatch(be_lun, beio); +} + +static void +ctl_be_block_cw_dispatch_dsm(struct ctl_be_block_lun *be_lun, + union ctl_io *io) +{ + struct ctl_be_lun *cbe_lun = &be_lun->cbe_lun; + struct ctl_be_block_io *beio; + struct nvme_dsm_range *r; + uint64_t lba; + uint32_t num_blocks; + u_int i, ranges; + + CTL_IO_ASSERT(io, NVME); + + beio = (struct ctl_be_block_io *)PRIV(io)->ptr; + + if (be_lun->unmap == NULL) { + ctl_free_beio(beio); + ctl_nvme_set_success(&io->nvmeio); + ctl_config_write_done(io); + return; + } + + ranges = le32toh(io->nvmeio.cmd.cdw10) & 0xff; + r = (struct nvme_dsm_range *)io->nvmeio.kern_data_ptr; + + /* Find the next range to delete. */ + for (i = DSM_RANGE(io); i < ranges; i++) { + if ((le32toh(r[i].attributes) & (1U << 2)) != 0) + break; + } + + /* If no range to delete, complete the operation. */ + if (i == ranges) { + ctl_free_beio(beio); + ctl_nvme_set_success(&io->nvmeio); + ctl_config_write_done(io); + return; + } + + /* If this is not the last range, request a rerun after this range. */ + if (i + 1 < ranges) { + DSM_RANGE(io) = i + 1; + beio->beio_cont = ctl_be_block_cw_done_ws; + } + + lba = le64toh(r[i].starting_lba); + num_blocks = le32toh(r[i].length); + + beio->io_offset = lba * cbe_lun->blocksize; + beio->io_len = (uint64_t)num_blocks * cbe_lun->blocksize; + beio->bio_cmd = BIO_DELETE; + beio->ds_trans_type = DEVSTAT_FREE; + + be_lun->unmap(be_lun, beio); +} + +static void +ctl_be_block_scsi_cr_done(struct ctl_be_block_io *beio) { union ctl_io *io; @@ -1493,8 +1729,8 @@ ctl_be_block_cr_done(struct ctl_be_block_io *beio) } static void -ctl_be_block_cr_dispatch(struct ctl_be_block_lun *be_lun, - union ctl_io *io) +ctl_be_block_scsi_cr_dispatch(struct ctl_be_block_lun *be_lun, + union ctl_io *io) { struct ctl_be_block_io *beio; struct ctl_be_block_softc *softc; @@ -1505,7 +1741,7 @@ ctl_be_block_cr_dispatch(struct ctl_be_block_lun *be_lun, beio = ctl_alloc_beio(softc); beio->io = io; beio->lun = be_lun; - beio->beio_cont = ctl_be_block_cr_done; + beio->beio_cont = ctl_be_block_scsi_cr_done; PRIV(io)->ptr = (void *)beio; switch (io->scsiio.cdb[0]) { @@ -1517,7 +1753,7 @@ ctl_be_block_cr_dispatch(struct ctl_be_block_lun *be_lun, if (be_lun->get_lba_status) be_lun->get_lba_status(be_lun, beio); else - ctl_be_block_cr_done(beio); + ctl_be_block_scsi_cr_done(beio); break; default: panic("Unhandled CDB type %#x", io->scsiio.cdb[0]); @@ -1526,6 +1762,45 @@ ctl_be_block_cr_dispatch(struct ctl_be_block_lun *be_lun, } static void +ctl_be_block_nvme_cr_dispatch(struct ctl_be_block_lun *be_lun, + union ctl_io *io) +{ + uint8_t cns; + + DPRINTF("entered\n"); + + MPASS(io->nvmeio.cmd.opc == NVME_OPC_IDENTIFY); + + cns = le32toh(io->nvmeio.cmd.cdw10) & 0xff; + switch (cns) { + case 0: + ctl_be_block_namespace_data(be_lun, io); + break; + case 3: + ctl_be_block_nvme_ids(be_lun, io); + break; + default: + __assert_unreachable(); + } +} + +static void +ctl_be_block_cr_dispatch(struct ctl_be_block_lun *be_lun, + union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + ctl_be_block_scsi_cr_dispatch(be_lun, io); + break; + case CTL_IO_NVME_ADMIN: + ctl_be_block_nvme_cr_dispatch(be_lun, io); + break; + default: + __assert_unreachable(); + } +} + +static void ctl_be_block_cw_done(struct ctl_be_block_io *beio) { union ctl_io *io; @@ -1536,19 +1811,15 @@ ctl_be_block_cw_done(struct ctl_be_block_io *beio) } static void -ctl_be_block_cw_dispatch(struct ctl_be_block_lun *be_lun, - union ctl_io *io) +ctl_be_block_scsi_cw_dispatch(struct ctl_be_block_lun *be_lun, + union ctl_io *io) { struct ctl_be_block_io *beio; - struct ctl_be_block_softc *softc; DPRINTF("entered\n"); - softc = be_lun->softc; - beio = ctl_alloc_beio(softc); - beio->io = io; - beio->lun = be_lun; - beio->beio_cont = ctl_be_block_cw_done; + beio = (struct ctl_be_block_io *)PRIV(io)->ptr; + switch (io->scsiio.tag_type) { case CTL_TAG_ORDERED: beio->ds_tag_type = DEVSTAT_TAG_ORDERED; @@ -1563,7 +1834,6 @@ ctl_be_block_cw_dispatch(struct ctl_be_block_lun *be_lun, beio->ds_tag_type = DEVSTAT_TAG_SIMPLE; break; } - PRIV(io)->ptr = (void *)beio; switch (io->scsiio.cdb[0]) { case SYNCHRONIZE_CACHE: @@ -1583,6 +1853,61 @@ ctl_be_block_cw_dispatch(struct ctl_be_block_lun *be_lun, } } +static void +ctl_be_block_nvme_cw_dispatch(struct ctl_be_block_lun *be_lun, + union ctl_io *io) +{ + struct ctl_be_block_io *beio; + + DPRINTF("entered\n"); + + beio = (struct ctl_be_block_io *)PRIV(io)->ptr; + beio->ds_tag_type = DEVSTAT_TAG_SIMPLE; + + switch (io->nvmeio.cmd.opc) { + case NVME_OPC_FLUSH: + ctl_be_block_cw_dispatch_flush(be_lun, io); + break; + case NVME_OPC_WRITE_UNCORRECTABLE: + ctl_be_block_cw_dispatch_wu(be_lun, io); + break; + case NVME_OPC_WRITE_ZEROES: + ctl_be_block_cw_dispatch_wz(be_lun, io); + break; + case NVME_OPC_DATASET_MANAGEMENT: + ctl_be_block_cw_dispatch_dsm(be_lun, io); + break; + default: + __assert_unreachable(); + } +} + +static void +ctl_be_block_cw_dispatch(struct ctl_be_block_lun *be_lun, + union ctl_io *io) +{ + struct ctl_be_block_io *beio; + struct ctl_be_block_softc *softc; + + softc = be_lun->softc; + beio = ctl_alloc_beio(softc); + beio->io = io; + beio->lun = be_lun; + beio->beio_cont = ctl_be_block_cw_done; + PRIV(io)->ptr = (void *)beio; + + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + ctl_be_block_scsi_cw_dispatch(be_lun, io); + break; + case CTL_IO_NVME: + ctl_be_block_nvme_cw_dispatch(be_lun, io); + break; + default: + __assert_unreachable(); + } +} + SDT_PROBE_DEFINE1(cbb, , read, start, "uint64_t"); SDT_PROBE_DEFINE1(cbb, , write, start, "uint64_t"); SDT_PROBE_DEFINE1(cbb, , read, alloc_done, "uint64_t"); @@ -1642,19 +1967,28 @@ ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun, bptrlen = PRIV(io); bptrlen->ptr = (void *)beio; - switch (io->scsiio.tag_type) { - case CTL_TAG_ORDERED: - beio->ds_tag_type = DEVSTAT_TAG_ORDERED; - break; - case CTL_TAG_HEAD_OF_QUEUE: - beio->ds_tag_type = DEVSTAT_TAG_HEAD; + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + switch (io->scsiio.tag_type) { + case CTL_TAG_ORDERED: + beio->ds_tag_type = DEVSTAT_TAG_ORDERED; + break; + case CTL_TAG_HEAD_OF_QUEUE: + beio->ds_tag_type = DEVSTAT_TAG_HEAD; + break; + case CTL_TAG_UNTAGGED: + case CTL_TAG_SIMPLE: + case CTL_TAG_ACA: + default: + beio->ds_tag_type = DEVSTAT_TAG_SIMPLE; + break; + } break; - case CTL_TAG_UNTAGGED: - case CTL_TAG_SIMPLE: - case CTL_TAG_ACA: - default: + case CTL_IO_NVME: beio->ds_tag_type = DEVSTAT_TAG_SIMPLE; break; + default: + __assert_unreachable(); } if (lbalen->flags & CTL_LLF_WRITE) { @@ -1703,16 +2037,16 @@ ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun, } if (bptrlen->len < lbalen->len) beio->beio_cont = ctl_be_block_next; - io->scsiio.be_move_done = ctl_be_block_move_done; + ctl_set_be_move_done(io, ctl_be_block_move_done); /* For compare we have separate S/G lists for read and datamove. */ if (beio->two_sglists) - io->scsiio.kern_data_ptr = (uint8_t *)&beio->sg_segs[CTLBLK_HALF_SEGS]; + ctl_set_kern_data_ptr(io, &beio->sg_segs[CTLBLK_HALF_SEGS]); else - io->scsiio.kern_data_ptr = (uint8_t *)beio->sg_segs; - io->scsiio.kern_data_len = beio->io_len; - io->scsiio.kern_sg_entries = beio->num_segs; - io->scsiio.kern_data_ref = ctl_refcnt_beio; - io->scsiio.kern_data_arg = beio; + ctl_set_kern_data_ptr(io, beio->sg_segs); + ctl_set_kern_data_len(io, beio->io_len); + ctl_set_kern_sg_entries(io, beio->num_segs); + ctl_set_kern_data_ref(io, ctl_refcnt_beio); + ctl_set_kern_data_arg(io, beio); io->io_hdr.flags |= CTL_FLAG_ALLOCATED; /* @@ -1752,7 +2086,7 @@ ctl_be_block_worker(void *context, int pending) mtx_unlock(&be_lun->queue_lock); beio = (struct ctl_be_block_io *)PRIV(io)->ptr; if (cbe_lun->flags & CTL_LUN_FLAG_NO_MEDIA) { - ctl_set_busy(&io->scsiio); + ctl_io_set_busy(io); ctl_complete_beio(beio); continue; } @@ -1765,7 +2099,7 @@ ctl_be_block_worker(void *context, int pending) STAILQ_REMOVE_HEAD(&be_lun->config_write_queue, links); mtx_unlock(&be_lun->queue_lock); if (cbe_lun->flags & CTL_LUN_FLAG_NO_MEDIA) { - ctl_set_busy(&io->scsiio); + ctl_io_set_busy(io); ctl_config_write_done(io); continue; } @@ -1778,7 +2112,7 @@ ctl_be_block_worker(void *context, int pending) STAILQ_REMOVE_HEAD(&be_lun->config_read_queue, links); mtx_unlock(&be_lun->queue_lock); if (cbe_lun->flags & CTL_LUN_FLAG_NO_MEDIA) { - ctl_set_busy(&io->scsiio); + ctl_io_set_busy(io); ctl_config_read_done(io); continue; } @@ -1791,7 +2125,7 @@ ctl_be_block_worker(void *context, int pending) STAILQ_REMOVE_HEAD(&be_lun->input_queue, links); mtx_unlock(&be_lun->queue_lock); if (cbe_lun->flags & CTL_LUN_FLAG_NO_MEDIA) { - ctl_set_busy(&io->scsiio); + ctl_io_set_busy(io); ctl_data_submit_done(io); continue; } @@ -1822,8 +2156,7 @@ ctl_be_block_submit(union ctl_io *io) be_lun = (struct ctl_be_block_lun *)CTL_BACKEND_LUN(io); - KASSERT(io->io_hdr.io_type == CTL_IO_SCSI, - ("%s: unexpected I/O type %x", __func__, io->io_hdr.io_type)); + CTL_IO_ASSERT(io, SCSI, NVME); PRIV(io)->len = 0; @@ -2698,7 +3031,7 @@ ctl_be_block_lun_shutdown(struct ctl_be_lun *cbe_lun) } static int -ctl_be_block_config_write(union ctl_io *io) +ctl_be_block_scsi_config_write(union ctl_io *io) { struct ctl_be_block_lun *be_lun; struct ctl_be_lun *cbe_lun; @@ -2783,7 +3116,50 @@ ctl_be_block_config_write(union ctl_io *io) } static int -ctl_be_block_config_read(union ctl_io *io) +ctl_be_block_nvme_config_write(union ctl_io *io) +{ + struct ctl_be_block_lun *be_lun; + + DPRINTF("entered\n"); + + be_lun = (struct ctl_be_block_lun *)CTL_BACKEND_LUN(io); + + switch (io->nvmeio.cmd.opc) { + case NVME_OPC_DATASET_MANAGEMENT: + DSM_RANGE(io) = 0; + /* FALLTHROUGH */ + case NVME_OPC_FLUSH: + case NVME_OPC_WRITE_UNCORRECTABLE: + case NVME_OPC_WRITE_ZEROES: + mtx_lock(&be_lun->queue_lock); + STAILQ_INSERT_TAIL(&be_lun->config_write_queue, &io->io_hdr, + links); + mtx_unlock(&be_lun->queue_lock); + taskqueue_enqueue(be_lun->io_taskqueue, &be_lun->io_task); + break; + default: + ctl_nvme_set_invalid_opcode(&io->nvmeio); + ctl_config_write_done(io); + break; + } + return (CTL_RETVAL_COMPLETE); +} + +static int +ctl_be_block_config_write(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + return (ctl_be_block_scsi_config_write(io)); + case CTL_IO_NVME: + return (ctl_be_block_nvme_config_write(io)); + default: + __assert_unreachable(); + } +} + +static int +ctl_be_block_scsi_config_read(union ctl_io *io) { struct ctl_be_block_lun *be_lun; int retval = 0; @@ -2824,18 +3200,71 @@ ctl_be_block_config_read(union ctl_io *io) } static int +ctl_be_block_nvme_config_read(union ctl_io *io) +{ + struct ctl_be_block_lun *be_lun; + + DPRINTF("entered\n"); + + be_lun = (struct ctl_be_block_lun *)CTL_BACKEND_LUN(io); + + switch (io->nvmeio.cmd.opc) { + case NVME_OPC_IDENTIFY: + { + uint8_t cns; + + cns = le32toh(io->nvmeio.cmd.cdw10) & 0xff; + switch (cns) { + case 0: + case 3: + mtx_lock(&be_lun->queue_lock); + STAILQ_INSERT_TAIL(&be_lun->config_read_queue, + &io->io_hdr, links); + mtx_unlock(&be_lun->queue_lock); + taskqueue_enqueue(be_lun->io_taskqueue, + &be_lun->io_task); + return (CTL_RETVAL_QUEUED); + default: + ctl_nvme_set_invalid_field(&io->nvmeio); + ctl_config_read_done(io); + break; + } + break; + } + default: + ctl_nvme_set_invalid_opcode(&io->nvmeio); + ctl_config_read_done(io); + break; + } + return (CTL_RETVAL_COMPLETE); +} + +static int +ctl_be_block_config_read(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + return (ctl_be_block_scsi_config_read(io)); + case CTL_IO_NVME_ADMIN: + return (ctl_be_block_nvme_config_read(io)); + default: + __assert_unreachable(); + } +} + +static int ctl_be_block_lun_info(struct ctl_be_lun *cbe_lun, struct sbuf *sb) { struct ctl_be_block_lun *lun = (struct ctl_be_block_lun *)cbe_lun; int retval; - retval = sbuf_printf(sb, "\t<num_threads>"); + retval = sbuf_cat(sb, "\t<num_threads>"); if (retval != 0) goto bailout; retval = sbuf_printf(sb, "%d", lun->num_threads); if (retval != 0) goto bailout; - retval = sbuf_printf(sb, "</num_threads>\n"); + retval = sbuf_cat(sb, "</num_threads>\n"); bailout: return (retval); diff --git a/sys/cam/ctl/ctl_backend_ramdisk.c b/sys/cam/ctl/ctl_backend_ramdisk.c index 9ddee1814aa1..49ed05f54a58 100644 --- a/sys/cam/ctl/ctl_backend_ramdisk.c +++ b/sys/cam/ctl/ctl_backend_ramdisk.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003, 2008 Silicon Graphics International Corp. * Copyright (c) 2012 The FreeBSD Foundation @@ -42,9 +42,6 @@ * Author: Ken Merry <ken@FreeBSD.org> */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> @@ -368,11 +365,10 @@ ctl_backend_ramdisk_cmp(union ctl_io *io) struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io); struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun; uint8_t *page; - uint8_t info[8]; uint64_t lba; u_int lbaoff, lbas, res, off; - lbas = io->scsiio.kern_data_len / cbe_lun->blocksize; + lbas = ctl_kern_data_len(io) / cbe_lun->blocksize; lba = ARGS(io)->lba + PRIV(io)->len - lbas; off = 0; for (; lbas > 0; lbas--, lba++) { @@ -380,7 +376,7 @@ ctl_backend_ramdisk_cmp(union ctl_io *io) lba >> cbe_lun->pblockexp, GP_READ); lbaoff = lba & ~(UINT_MAX << cbe_lun->pblockexp); page += lbaoff * cbe_lun->blocksize; - res = cmp(io->scsiio.kern_data_ptr + off, page, + res = cmp(ctl_kern_data_ptr(io) + off, page, cbe_lun->blocksize); off += res; if (res < cbe_lun->blocksize) @@ -388,14 +384,8 @@ ctl_backend_ramdisk_cmp(union ctl_io *io) } free(io->scsiio.kern_data_ptr, M_RAMDISK); if (lbas > 0) { - off += io->scsiio.kern_rel_offset - io->scsiio.kern_data_len; - scsi_u64to8b(off, info); - ctl_set_sense(&io->scsiio, /*current_error*/ 1, - /*sense_key*/ SSD_KEY_MISCOMPARE, - /*asc*/ 0x1D, /*ascq*/ 0x00, - /*type*/ SSD_ELEM_INFO, - /*size*/ sizeof(info), /*data*/ &info, - /*type*/ SSD_ELEM_NONE); + off += ctl_kern_rel_offset(io) - ctl_kern_data_len(io); + ctl_io_set_compare_failure(io, off); return (1); } return (0); @@ -408,9 +398,9 @@ ctl_backend_ramdisk_move_done(union ctl_io *io, bool samethr) (struct ctl_be_ramdisk_lun *)CTL_BACKEND_LUN(io); CTL_DEBUG_PRINT(("ctl_backend_ramdisk_move_done\n")); - if (io->scsiio.kern_sg_entries > 0) - free(io->scsiio.kern_data_ptr, M_RAMDISK); - io->scsiio.kern_rel_offset += io->scsiio.kern_data_len; + if (ctl_kern_sg_entries(io) > 0) + free(ctl_kern_data_ptr(io), M_RAMDISK); + ctl_add_kern_rel_offset(io, ctl_kern_data_len(io)); if ((io->io_hdr.flags & CTL_FLAG_ABORT) == 0 && (io->io_hdr.status & CTL_STATUS_MASK) == CTL_STATUS_NONE) { if (ARGS(io)->flags & CTL_LLF_COMPARE) { @@ -427,7 +417,7 @@ ctl_backend_ramdisk_move_done(union ctl_io *io, bool samethr) &be_lun->io_task); return (0); } - ctl_set_success(&io->scsiio); + ctl_io_set_success(io); } done: ctl_data_submit_done(io); @@ -444,10 +434,10 @@ ctl_backend_ramdisk_compare(union ctl_io *io) lbas = MIN(lbas, 131072 / cbe_lun->blocksize); len = lbas * cbe_lun->blocksize; - io->scsiio.be_move_done = ctl_backend_ramdisk_move_done; - io->scsiio.kern_data_ptr = malloc(len, M_RAMDISK, M_WAITOK); - io->scsiio.kern_data_len = len; - io->scsiio.kern_sg_entries = 0; + ctl_set_be_move_done(io, ctl_backend_ramdisk_move_done); + ctl_set_kern_data_ptr(io, malloc(len, M_RAMDISK, M_WAITOK)); + ctl_set_kern_data_len(io, len); + ctl_set_kern_sg_entries(io, 0); io->io_hdr.flags |= CTL_FLAG_ALLOCATED; PRIV(io)->len += lbas; ctl_datamove(io); @@ -472,17 +462,17 @@ ctl_backend_ramdisk_rw(union ctl_io *io) off = lbaoff * cbe_lun->blocksize; op = (ARGS(io)->flags & CTL_LLF_WRITE) ? GP_WRITE : GP_READ; if (sgs > 1) { - io->scsiio.kern_data_ptr = malloc(sizeof(struct ctl_sg_entry) * - sgs, M_RAMDISK, M_WAITOK); - sg_entries = (struct ctl_sg_entry *)io->scsiio.kern_data_ptr; + sg_entries = malloc(sizeof(struct ctl_sg_entry) * sgs, + M_RAMDISK, M_WAITOK); + ctl_set_kern_data_ptr(io, sg_entries); len = lbas * cbe_lun->blocksize; for (i = 0; i < sgs; i++) { page = ctl_backend_ramdisk_getpage(be_lun, (lba >> cbe_lun->pblockexp) + i, op); if (page == P_UNMAPPED || page == P_ANCHORED) { - free(io->scsiio.kern_data_ptr, M_RAMDISK); + free(sg_entries, M_RAMDISK); nospc: - ctl_set_space_alloc_fail(&io->scsiio); + ctl_io_set_space_alloc_fail(io); ctl_data_submit_done(io); return; } @@ -497,17 +487,17 @@ nospc: if (page == P_UNMAPPED || page == P_ANCHORED) goto nospc; sgs = 0; - io->scsiio.kern_data_ptr = page + off; + ctl_set_kern_data_ptr(io, page + off); } - io->scsiio.be_move_done = ctl_backend_ramdisk_move_done; - io->scsiio.kern_data_len = lbas * cbe_lun->blocksize; - io->scsiio.kern_sg_entries = sgs; + ctl_set_be_move_done(io, ctl_backend_ramdisk_move_done); + ctl_set_kern_data_len(io, lbas * cbe_lun->blocksize); + ctl_set_kern_sg_entries(io, sgs); io->io_hdr.flags |= CTL_FLAG_ALLOCATED; PRIV(io)->len += lbas; if ((ARGS(io)->flags & CTL_LLF_READ) && ARGS(io)->len <= PRIV(io)->len) { - ctl_set_success(&io->scsiio); + ctl_io_set_success(io); if (cbe_lun->serseq >= CTL_LUN_SERSEQ_SOFT) ctl_serseq_done(io); } @@ -520,7 +510,7 @@ ctl_backend_ramdisk_submit(union ctl_io *io) struct ctl_lba_len_flags *lbalen = ARGS(io); if (lbalen->flags & CTL_LLF_VERIFY) { - ctl_set_success(&io->scsiio); + ctl_io_set_success(io); ctl_data_submit_done(io); return (CTL_RETVAL_COMPLETE); } @@ -588,7 +578,7 @@ ctl_backend_ramdisk_gls(union ctl_io *io) } static int -ctl_backend_ramdisk_config_read(union ctl_io *io) +ctl_backend_ramdisk_scsi_config_read(union ctl_io *io) { int retval = 0; @@ -616,6 +606,89 @@ ctl_backend_ramdisk_config_read(union ctl_io *io) return (retval); } +static int +ramdisk_namespace_data(union ctl_io *io) +{ + struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io); + struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun; + struct nvme_namespace_data *nsdata; + + if (io->nvmeio.kern_data_len != sizeof(struct nvme_namespace_data) || + io->nvmeio.kern_sg_entries != 0) + return (CTL_RETVAL_ERROR); + + nsdata = (struct nvme_namespace_data *)io->nvmeio.kern_data_ptr; + memset(nsdata, 0, sizeof(*nsdata)); + nsdata->nsze = htole64(be_lun->size_blocks); + nsdata->ncap = htole64(be_lun->cap_bytes / cbe_lun->blocksize); + nsdata->nuse = htole64(be_lun->cap_used / cbe_lun->blocksize); + nsdata->nsfeat = NVMEM(NVME_NS_DATA_NSFEAT_THIN_PROV) | + NVMEM(NVME_NS_DATA_NSFEAT_DEALLOC); + nsdata->nlbaf = 1 - 1; + nsdata->dlfeat = NVMEM(NVME_NS_DATA_DLFEAT_DWZ) | + NVMEF(NVME_NS_DATA_DLFEAT_READ, NVME_NS_DATA_DLFEAT_READ_00); + nsdata->flbas = NVMEF(NVME_NS_DATA_FLBAS_FORMAT, 0); + nsdata->lbaf[0] = NVMEF(NVME_NS_DATA_LBAF_LBADS, + ffs(cbe_lun->blocksize) - 1); + + ctl_lun_nsdata_ids(cbe_lun, nsdata); + ctl_config_read_done(io); + return (CTL_RETVAL_COMPLETE); +} + +static int +ramdisk_nvme_ids(union ctl_io *io) +{ + struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io); + + if (io->nvmeio.kern_data_len != 4096 || io->nvmeio.kern_sg_entries != 0) + return (CTL_RETVAL_ERROR); + + ctl_lun_nvme_ids(cbe_lun, io->nvmeio.kern_data_ptr); + ctl_config_read_done(io); + return (CTL_RETVAL_COMPLETE); +} + +static int +ctl_backend_ramdisk_nvme_config_read(union ctl_io *io) +{ + switch (io->nvmeio.cmd.opc) { + case NVME_OPC_IDENTIFY: + { + uint8_t cns; + + cns = le32toh(io->nvmeio.cmd.cdw10) & 0xff; + switch (cns) { + case 0: + return (ramdisk_namespace_data(io)); + case 3: + return (ramdisk_nvme_ids(io)); + default: + ctl_nvme_set_invalid_field(&io->nvmeio); + ctl_config_read_done(io); + return (CTL_RETVAL_COMPLETE); + } + } + default: + ctl_nvme_set_invalid_opcode(&io->nvmeio); + ctl_config_read_done(io); + return (CTL_RETVAL_COMPLETE); + } +} + +static int +ctl_backend_ramdisk_config_read(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + return (ctl_backend_ramdisk_scsi_config_read(io)); + case CTL_IO_NVME_ADMIN: + return (ctl_backend_ramdisk_nvme_config_read(io)); + default: + __assert_unreachable(); + } +} + static void ctl_backend_ramdisk_delete(struct ctl_be_lun *cbe_lun, off_t lba, off_t len, int anchor) @@ -668,6 +741,8 @@ ctl_backend_ramdisk_ws(union ctl_io *io) uint64_t lba; u_int lbaoff, lbas; + CTL_IO_ASSERT(io, SCSI); + if (lbalen->flags & ~(SWS_LBDATA | SWS_UNMAP | SWS_ANCHOR | SWS_NDOB)) { ctl_set_invalid_field(&io->scsiio, /*sks_valid*/ 1, @@ -716,6 +791,8 @@ ctl_backend_ramdisk_unmap(union ctl_io *io) struct ctl_ptr_len_flags *ptrlen = (struct ctl_ptr_len_flags *)ARGS(io); struct scsi_unmap_desc *buf, *end; + CTL_IO_ASSERT(io, SCSI); + if ((ptrlen->flags & ~SU_ANCHOR) != 0) { ctl_set_invalid_field(&io->scsiio, /*sks_valid*/ 0, @@ -740,7 +817,7 @@ ctl_backend_ramdisk_unmap(union ctl_io *io) } static int -ctl_backend_ramdisk_config_write(union ctl_io *io) +ctl_backend_ramdisk_scsi_config_write(union ctl_io *io) { struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io); int retval = 0; @@ -795,6 +872,122 @@ ctl_backend_ramdisk_config_write(union ctl_io *io) return (retval); } +static void +ctl_backend_ramdisk_wu(union ctl_io *io) +{ + struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io); + struct ctl_lba_len_flags *lbalen = ARGS(io); + + CTL_IO_ASSERT(io, NVME); + + /* + * XXX: Not quite right as reads will return zeroes rather + * than failing. + */ + ctl_backend_ramdisk_delete(cbe_lun, lbalen->lba, lbalen->len, 1); + ctl_nvme_set_success(&io->nvmeio); + ctl_config_write_done(io); +} + +static void +ctl_backend_ramdisk_wz(union ctl_io *io) +{ + struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io); + struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun; + struct ctl_lba_len_flags *lbalen = ARGS(io); + uint8_t *page; + uint64_t lba; + u_int lbaoff, lbas; + + CTL_IO_ASSERT(io, NVME); + + if ((le32toh(io->nvmeio.cmd.cdw12) & (1U << 25)) != 0) { + ctl_backend_ramdisk_delete(cbe_lun, lbalen->lba, lbalen->len, + 0); + ctl_nvme_set_success(&io->nvmeio); + ctl_config_write_done(io); + return; + } + + for (lba = lbalen->lba, lbas = lbalen->len; lbas > 0; lba++, lbas--) { + page = ctl_backend_ramdisk_getpage(be_lun, + lba >> cbe_lun->pblockexp, GP_WRITE); + if (page == P_UNMAPPED || page == P_ANCHORED) { + ctl_nvme_set_space_alloc_fail(&io->nvmeio); + ctl_data_submit_done(io); + return; + } + lbaoff = lba & ~(UINT_MAX << cbe_lun->pblockexp); + page += lbaoff * cbe_lun->blocksize; + memset(page, 0, cbe_lun->blocksize); + } + ctl_nvme_set_success(&io->nvmeio); + ctl_config_write_done(io); +} + +static void +ctl_backend_ramdisk_dsm(union ctl_io *io) +{ + struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io); + struct nvme_dsm_range *r; + uint64_t lba; + uint32_t num_blocks; + u_int i, ranges; + + CTL_IO_ASSERT(io, NVME); + + ranges = le32toh(io->nvmeio.cmd.cdw10) & 0xff; + r = (struct nvme_dsm_range *)io->nvmeio.kern_data_ptr; + for (i = 0; i < ranges; i++) { + lba = le64toh(r[i].starting_lba); + num_blocks = le32toh(r[i].length); + if ((le32toh(r[i].attributes) & (1U << 2)) != 0) + ctl_backend_ramdisk_delete(cbe_lun, lba, num_blocks, 0); + } + + ctl_nvme_set_success(&io->nvmeio); + ctl_config_write_done(io); +} + +static int +ctl_backend_ramdisk_nvme_config_write(union ctl_io *io) +{ + switch (io->nvmeio.cmd.opc) { + case NVME_OPC_FLUSH: + /* We have no cache to flush. */ + ctl_nvme_set_success(&io->nvmeio); + ctl_config_write_done(io); + break; + case NVME_OPC_WRITE_UNCORRECTABLE: + ctl_backend_ramdisk_wu(io); + break; + case NVME_OPC_WRITE_ZEROES: + ctl_backend_ramdisk_wz(io); + break; + case NVME_OPC_DATASET_MANAGEMENT: + ctl_backend_ramdisk_dsm(io); + break; + default: + ctl_nvme_set_invalid_opcode(&io->nvmeio); + ctl_config_write_done(io); + break; + } + return (CTL_RETVAL_COMPLETE); +} + +static int +ctl_backend_ramdisk_config_write(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + return (ctl_backend_ramdisk_scsi_config_write(io)); + case CTL_IO_NVME: + return (ctl_backend_ramdisk_nvme_config_write(io)); + default: + __assert_unreachable(); + } +} + static uint64_t ctl_backend_ramdisk_lun_attr(struct ctl_be_lun *cbe_lun, const char *attrname) { diff --git a/sys/cam/ctl/ctl_cmd_table.c b/sys/cam/ctl/ctl_cmd_table.c index 2e512ec11c82..28d937edd7dc 100644 --- a/sys/cam/ctl/ctl_cmd_table.c +++ b/sys/cam/ctl/ctl_cmd_table.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003, 2004, 2005, 2009 Silicon Graphics International Corp. * Copyright (c) 2014-2015 Alexander Motin <mav@FreeBSD.org> @@ -31,7 +31,6 @@ * POSSIBILITY OF SUCH DAMAGES. * * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_cmd_table.c#4 $ - * $FreeBSD$ */ /* * CAM Target Layer command table. @@ -39,7 +38,6 @@ * Author: Ken Merry <ken@FreeBSD.org>, Kim Le */ -#include <sys/cdefs.h> #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> @@ -946,6 +944,7 @@ const struct ctl_cmd_entry ctl_cmd_table[256] = /* 08 READ(6) */ {ctl_read_write, CTL_SERIDX_READ, CTL_CMD_FLAG_OK_ON_DIRECT | CTL_FLAG_DATA_IN | + CTL_CMD_FLAG_OK_ON_CDROM | CTL_CMD_FLAG_ALLOW_ON_PR_WRESV, CTL_LUN_PAT_READ | CTL_LUN_PAT_RANGE, 6, {0x1f, 0xff, 0xff, 0xff, 0x07}}, @@ -1229,7 +1228,7 @@ const struct ctl_cmd_entry ctl_cmd_table[256] = CTL_CMD_FLAG_ALLOW_ON_PR_RESV | CTL_FLAG_DATA_IN, CTL_LUN_PAT_NONE, - 10, {0x02, 0x01, 0, 0, 0, 0xff, 0xff, 0xff, 0x07}}, + 10, {0xe1, 0, 0, 0x7e, 0, 0, 0xff, 0xff, 0x07}}, /* 4B PAUSE/RESUME */ {NULL, CTL_SERIDX_INVLD, CTL_CMD_FLAG_NONE, CTL_LUN_PAT_NONE}, diff --git a/sys/cam/ctl/ctl_debug.h b/sys/cam/ctl/ctl_debug.h index fcc5993888e8..f390ea1c1e44 100644 --- a/sys/cam/ctl/ctl_debug.h +++ b/sys/cam/ctl/ctl_debug.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003 Silicon Graphics International Corp. * All rights reserved. @@ -30,7 +30,6 @@ * POSSIBILITY OF SUCH DAMAGES. * * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_debug.h#2 $ - * $FreeBSD$ */ /* * CAM Target Layer debugging interface. diff --git a/sys/cam/ctl/ctl_error.c b/sys/cam/ctl/ctl_error.c index dae4deb9e5e7..d07541a1a986 100644 --- a/sys/cam/ctl/ctl_error.c +++ b/sys/cam/ctl/ctl_error.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003-2009 Silicon Graphics International Corp. * Copyright (c) 2011 Spectra Logic Corporation @@ -39,9 +39,6 @@ * Author: Ken Merry <ken@FreeBSD.org> */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> @@ -993,3 +990,222 @@ ctl_set_success(struct ctl_scsiio *ctsio) ctsio->sense_len = 0; ctsio->io_hdr.status = CTL_SUCCESS; } + +void +ctl_nvme_set_error(struct ctl_nvmeio *ctnio, uint8_t sc_type, + uint8_t sc_status) +{ + uint16_t status; + + memset(&ctnio->cpl, 0, sizeof(ctnio->cpl)); + status = NVMEF(NVME_STATUS_SCT, sc_type) | + NVMEF(NVME_STATUS_SC, sc_status); + ctnio->cpl.status = htole16(status); + ctnio->io_hdr.status = CTL_NVME_ERROR; +} + +void +ctl_nvme_set_generic_error(struct ctl_nvmeio *ctnio, uint8_t sc_status) +{ + ctl_nvme_set_error(ctnio, NVME_SCT_GENERIC, sc_status); +} + +void +ctl_nvme_set_invalid_opcode(struct ctl_nvmeio *ctnio) +{ + ctl_nvme_set_generic_error(ctnio, NVME_SC_INVALID_OPCODE); +} + +void +ctl_nvme_set_invalid_field(struct ctl_nvmeio *ctnio) +{ + ctl_nvme_set_generic_error(ctnio, NVME_SC_INVALID_FIELD); +} + +void +ctl_nvme_set_data_transfer_error(struct ctl_nvmeio *ctnio) +{ + ctl_nvme_set_generic_error(ctnio, NVME_SC_DATA_TRANSFER_ERROR); +} + +void +ctl_nvme_set_internal_error(struct ctl_nvmeio *ctnio) +{ + ctl_nvme_set_generic_error(ctnio, NVME_SC_INTERNAL_DEVICE_ERROR); +} + +void +ctl_nvme_set_invalid_namespace(struct ctl_nvmeio *ctnio) +{ + ctl_nvme_set_generic_error(ctnio, NVME_SC_INVALID_NAMESPACE_OR_FORMAT); +} + +void +ctl_nvme_set_command_aborted(struct ctl_nvmeio *ctnio) +{ + ctl_nvme_set_generic_error(ctnio, NVME_SC_COMMAND_ABORTED_BY_HOST); +} + +void +ctl_nvme_set_failed_fused_command(struct ctl_nvmeio *ctnio) +{ + ctl_nvme_set_generic_error(ctnio, NVME_SC_ABORTED_FAILED_FUSED); +} + +void +ctl_nvme_set_missing_fused_command(struct ctl_nvmeio *ctnio) +{ + ctl_nvme_set_generic_error(ctnio, NVME_SC_ABORTED_MISSING_FUSED); +} + +void +ctl_nvme_set_namespace_is_write_protected(struct ctl_nvmeio *ctnio) +{ + ctl_nvme_set_generic_error(ctnio, NVME_SC_NAMESPACE_IS_WRITE_PROTECTED); +} + +void +ctl_nvme_set_lba_out_of_range(struct ctl_nvmeio *ctnio) +{ + ctl_nvme_set_generic_error(ctnio, NVME_SC_LBA_OUT_OF_RANGE); +} + +void +ctl_nvme_set_namespace_not_ready(struct ctl_nvmeio *ctnio) +{ + ctl_nvme_set_generic_error(ctnio, NVME_SC_NAMESPACE_NOT_READY); +} + +void +ctl_nvme_set_write_fault(struct ctl_nvmeio *ctnio) +{ + ctl_nvme_set_error(ctnio, NVME_SCT_MEDIA_ERROR, + NVME_SC_WRITE_FAULTS); +} + +void +ctl_nvme_set_unrecoverable_read_error(struct ctl_nvmeio *ctnio) +{ + ctl_nvme_set_error(ctnio, NVME_SCT_MEDIA_ERROR, + NVME_SC_UNRECOVERED_READ_ERROR); +} + +void +ctl_nvme_set_compare_failure(struct ctl_nvmeio *ctnio) +{ + ctl_nvme_set_error(ctnio, NVME_SCT_MEDIA_ERROR, + NVME_SC_COMPARE_FAILURE); +} + +void +ctl_nvme_set_space_alloc_fail(struct ctl_nvmeio *ctnio) +{ + ctl_nvme_set_error(ctnio, NVME_SCT_MEDIA_ERROR, + NVME_SC_DEALLOCATED_OR_UNWRITTEN); +} + +void +ctl_nvme_set_success(struct ctl_nvmeio *ctnio) +{ + memset(&ctnio->cpl, 0, sizeof(ctnio->cpl)); + ctnio->io_hdr.status = CTL_SUCCESS; +} + +void +ctl_io_set_invalid_opcode(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + ctl_set_invalid_opcode(&io->scsiio); + break; + case CTL_IO_NVME: + ctl_nvme_set_invalid_opcode(&io->nvmeio); + break; + default: + __assert_unreachable(); + } +} + +void +ctl_io_set_hw_write_protected(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + ctl_set_hw_write_protected(&io->scsiio); + break; + case CTL_IO_NVME: + ctl_nvme_set_namespace_is_write_protected(&io->nvmeio); + break; + default: + __assert_unreachable(); + } +} + +void +ctl_io_set_busy(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + ctl_set_busy(&io->scsiio); + break; + case CTL_IO_NVME: + ctl_nvme_set_namespace_not_ready(&io->nvmeio); + break; + default: + __assert_unreachable(); + } +} + +void +ctl_io_set_compare_failure(union ctl_io *io, uint64_t offset) +{ + uint8_t info[8]; + + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + scsi_u64to8b(offset, info); + ctl_set_sense(&io->scsiio, /*current_error*/ 1, + /*sense_key*/ SSD_KEY_MISCOMPARE, + /*asc*/ 0x1D, /*ascq*/ 0x00, + /*type*/ SSD_ELEM_INFO, + /*size*/ sizeof(info), /*data*/ &info, + /*type*/ SSD_ELEM_NONE); + break; + case CTL_IO_NVME: + ctl_nvme_set_compare_failure(&io->nvmeio); + break; + default: + __assert_unreachable(); + } +} + +void +ctl_io_set_space_alloc_fail(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + ctl_set_space_alloc_fail(&io->scsiio); + break; + case CTL_IO_NVME: + ctl_nvme_set_space_alloc_fail(&io->nvmeio); + break; + default: + __assert_unreachable(); + } +} + +void +ctl_io_set_success(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + ctl_set_success(&io->scsiio); + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + ctl_nvme_set_success(&io->nvmeio); + break; + default: + __assert_unreachable(); + } +} diff --git a/sys/cam/ctl/ctl_error.h b/sys/cam/ctl/ctl_error.h index eb9e1fc5d1a0..fb2113bef048 100644 --- a/sys/cam/ctl/ctl_error.h +++ b/sys/cam/ctl/ctl_error.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003 Silicon Graphics International Corp. * Copyright (c) 2014-2015 Alexander Motin <mav@FreeBSD.org> @@ -31,7 +31,6 @@ * POSSIBILITY OF SUCH DAMAGES. * * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_error.h#1 $ - * $FreeBSD$ */ /* * Function definitions for various error reporting routines used both @@ -97,4 +96,31 @@ void ctl_set_hw_write_protected(struct ctl_scsiio *ctsio); void ctl_set_space_alloc_fail(struct ctl_scsiio *ctsio); void ctl_set_success(struct ctl_scsiio *ctsio); +void ctl_nvme_set_error(struct ctl_nvmeio *ctnio, uint8_t sc_type, + uint8_t sc_status); +void ctl_nvme_set_generic_error(struct ctl_nvmeio *ctnio, uint8_t sc_status); +void ctl_nvme_set_invalid_opcode(struct ctl_nvmeio *ctnio); +void ctl_nvme_set_invalid_field(struct ctl_nvmeio *ctnio); +void ctl_nvme_set_data_transfer_error(struct ctl_nvmeio *ctnio); +void ctl_nvme_set_internal_error(struct ctl_nvmeio *ctnio); +void ctl_nvme_set_invalid_namespace(struct ctl_nvmeio *ctnio); +void ctl_nvme_set_command_aborted(struct ctl_nvmeio *ctnio); +void ctl_nvme_set_failed_fused_command(struct ctl_nvmeio *ctnio); +void ctl_nvme_set_missing_fused_command(struct ctl_nvmeio *ctnio); +void ctl_nvme_set_namespace_is_write_protected(struct ctl_nvmeio *ctnio); +void ctl_nvme_set_lba_out_of_range(struct ctl_nvmeio *ctnio); +void ctl_nvme_set_namespace_not_ready(struct ctl_nvmeio *ctnio); +void ctl_nvme_set_write_fault(struct ctl_nvmeio *ctnio); +void ctl_nvme_set_unrecoverable_read_error(struct ctl_nvmeio *ctnio); +void ctl_nvme_set_compare_failure(struct ctl_nvmeio *ctnio); +void ctl_nvme_set_space_alloc_fail(struct ctl_nvmeio *ctnio); +void ctl_nvme_set_success(struct ctl_nvmeio *ctnio); + +void ctl_io_set_invalid_opcode(union ctl_io *io); +void ctl_io_set_hw_write_protected(union ctl_io *io); +void ctl_io_set_busy(union ctl_io *io); +void ctl_io_set_compare_failure(union ctl_io *io, uint64_t offset); +void ctl_io_set_space_alloc_fail(union ctl_io *io); +void ctl_io_set_success(union ctl_io *io); + #endif /* _CTL_ERROR_H_ */ diff --git a/sys/cam/ctl/ctl_frontend.c b/sys/cam/ctl/ctl_frontend.c index d481c1b8f003..1e4d130950c4 100644 --- a/sys/cam/ctl/ctl_frontend.c +++ b/sys/cam/ctl/ctl_frontend.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003 Silicon Graphics International Corp. * Copyright (c) 2014-2017 Alexander Motin <mav@FreeBSD.org> @@ -38,9 +38,6 @@ * Author: Ken Merry <ken@FreeBSD.org> */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> @@ -165,7 +162,7 @@ ctl_port_register(struct ctl_port *port) if ((port_num < 0) || (ctl_set_mask(softc->ctl_port_mask, port_num) < 0)) { mtx_unlock(&softc->ctl_lock); - return (1); + return (EBUSY); } softc->num_ports++; mtx_unlock(&softc->ctl_lock); diff --git a/sys/cam/ctl/ctl_frontend.h b/sys/cam/ctl/ctl_frontend.h index c9ab255cdde4..650ece567e46 100644 --- a/sys/cam/ctl/ctl_frontend.h +++ b/sys/cam/ctl/ctl_frontend.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003 Silicon Graphics International Corp. * Copyright (c) 2014-2017 Alexander Motin <mav@FreeBSD.org> @@ -31,7 +31,6 @@ * POSSIBILITY OF SUCH DAMAGES. * * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_frontend.h#2 $ - * $FreeBSD$ */ /* * CAM Target Layer front end registration hooks @@ -214,7 +213,7 @@ struct ctl_wwpn_iid { */ struct ctl_port { struct ctl_softc *ctl_softc; - struct ctl_frontend *frontend; + struct ctl_frontend *frontend; /* passed to CTL */ ctl_port_type port_type; /* passed to CTL */ int num_requested_ctl_io; /* passed to CTL */ char *port_name; /* passed to CTL */ diff --git a/sys/cam/ctl/ctl_frontend_cam_sim.c b/sys/cam/ctl/ctl_frontend_cam_sim.c index 0e61a80e452c..544912d602d9 100644 --- a/sys/cam/ctl/ctl_frontend_cam_sim.c +++ b/sys/cam/ctl/ctl_frontend_cam_sim.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 Silicon Graphics International Corp. * All rights reserved. @@ -38,9 +38,6 @@ * Author: Ken Merry <ken@FreeBSD.org> */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> diff --git a/sys/cam/ctl/ctl_frontend_ioctl.c b/sys/cam/ctl/ctl_frontend_ioctl.c index f326100cb013..7fc8deac82b3 100644 --- a/sys/cam/ctl/ctl_frontend_ioctl.c +++ b/sys/cam/ctl/ctl_frontend_ioctl.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003-2009 Silicon Graphics International Corp. * Copyright (c) 2012 The FreeBSD Foundation @@ -29,9 +29,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> @@ -75,7 +72,7 @@ struct ctl_fe_ioctl_params { struct cfi_port { TAILQ_ENTRY(cfi_port) link; - uint32_t cur_tag_num; + u_int cur_tag_num; struct cdev * dev; struct ctl_port port; }; @@ -632,9 +629,10 @@ ctl_ioctl_io(struct cdev *dev, u_long cmd, caddr_t addr, int flag, */ io->io_hdr.nexus.targ_port = cfi->port.targ_port; io->io_hdr.flags |= CTL_FLAG_USER_REQ; - if ((io->io_hdr.io_type == CTL_IO_SCSI) && - (io->scsiio.tag_type != CTL_TAG_UNTAGGED)) - io->scsiio.tag_num = cfi->cur_tag_num++; + if ((io->io_hdr.flags & CTL_FLAG_USER_TAG) == 0 && + io->io_hdr.io_type == CTL_IO_SCSI && + io->scsiio.tag_type != CTL_TAG_UNTAGGED) + io->scsiio.tag_num = atomic_fetchadd_int(&cfi->cur_tag_num, 1); retval = cfi_submit_wait(io); if (retval == 0) diff --git a/sys/cam/ctl/ctl_frontend_iscsi.c b/sys/cam/ctl/ctl_frontend_iscsi.c index b78c6a7d8441..fe3b1a943206 100644 --- a/sys/cam/ctl/ctl_frontend_iscsi.c +++ b/sys/cam/ctl/ctl_frontend_iscsi.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2012 The FreeBSD Foundation * @@ -26,17 +26,12 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ /* * CTL frontend for the iSCSI protocol. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/capsicum.h> #include <sys/condvar.h> @@ -1726,7 +1721,7 @@ cfiscsi_ioctl_list(struct ctl_iscsi *ci) return; } - sbuf_printf(sb, "<ctlislist>\n"); + sbuf_cat(sb, "<ctlislist>\n"); mtx_lock(&softc->lock); TAILQ_FOREACH(cs, &softc->sessions, cs_next) { if (cs->cs_target == NULL) @@ -1765,7 +1760,7 @@ cfiscsi_ioctl_list(struct ctl_iscsi *ci) break; } mtx_unlock(&softc->lock); - error = sbuf_printf(sb, "</ctlislist>\n"); + error = sbuf_cat(sb, "</ctlislist>\n"); if (error != 0) { sbuf_delete(sb); ci->status = CTL_ISCSI_LIST_NEED_MORE_SPACE; diff --git a/sys/cam/ctl/ctl_frontend_iscsi.h b/sys/cam/ctl/ctl_frontend_iscsi.h index 165f0ad79d70..c1fa3270eea1 100644 --- a/sys/cam/ctl/ctl_frontend_iscsi.h +++ b/sys/cam/ctl/ctl_frontend_iscsi.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2012 The FreeBSD Foundation * @@ -26,8 +26,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef CTL_FRONTEND_ISCSI_H diff --git a/sys/cam/ctl/ctl_ha.c b/sys/cam/ctl/ctl_ha.c index e2ecb9706f56..e94708028ee4 100644 --- a/sys/cam/ctl/ctl_ha.c +++ b/sys/cam/ctl/ctl_ha.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2015 Alexander Motin <mav@FreeBSD.org> * All rights reserved. @@ -26,9 +26,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/condvar.h> #include <sys/conf.h> @@ -167,17 +164,17 @@ ctl_ha_close(struct ha_softc *softc) report = 1; } if (so) { - SOCKBUF_LOCK(&so->so_rcv); + SOCK_RECVBUF_LOCK(so); soupcall_clear(so, SO_RCV); while (softc->ha_receiving) { wakeup(&softc->ha_receiving); - msleep(&softc->ha_receiving, SOCKBUF_MTX(&so->so_rcv), + msleep(&softc->ha_receiving, SOCK_RECVBUF_MTX(so), 0, "ha_rx exit", 0); } - SOCKBUF_UNLOCK(&so->so_rcv); - SOCKBUF_LOCK(&so->so_snd); + SOCK_RECVBUF_UNLOCK(so); + SOCK_SENDBUF_LOCK(so); soupcall_clear(so, SO_SND); - SOCKBUF_UNLOCK(&so->so_snd); + SOCK_SENDBUF_UNLOCK(so); softc->ha_so = NULL; if (softc->ha_connect) pause("reconnect", hz / 2); @@ -221,7 +218,7 @@ ctl_ha_rx_thread(void *arg) next = wire_hdr.length; else next = sizeof(wire_hdr); - SOCKBUF_LOCK(&so->so_rcv); + SOCK_RECVBUF_LOCK(so); while (sbavail(&so->so_rcv) < next || softc->ha_disconnect) { if (softc->ha_connected == 0 || softc->ha_disconnect || so->so_error || @@ -229,10 +226,10 @@ ctl_ha_rx_thread(void *arg) goto errout; } so->so_rcv.sb_lowat = next; - msleep(&softc->ha_receiving, SOCKBUF_MTX(&so->so_rcv), + msleep(&softc->ha_receiving, SOCK_RECVBUF_MTX(so), 0, "-", 0); } - SOCKBUF_UNLOCK(&so->so_rcv); + SOCK_RECVBUF_UNLOCK(so); if (wire_hdr.length == 0) { iov.iov_base = &wire_hdr; @@ -249,7 +246,7 @@ ctl_ha_rx_thread(void *arg) if (error != 0) { printf("%s: header receive error %d\n", __func__, error); - SOCKBUF_LOCK(&so->so_rcv); + SOCK_RECVBUF_LOCK(so); goto errout; } } else { @@ -262,7 +259,7 @@ ctl_ha_rx_thread(void *arg) errout: softc->ha_receiving = 0; wakeup(&softc->ha_receiving); - SOCKBUF_UNLOCK(&so->so_rcv); + SOCK_RECVBUF_UNLOCK(so); ctl_ha_conn_wake(softc); kthread_exit(); } @@ -283,13 +280,13 @@ ctl_ha_send(struct ha_softc *softc) break; } } - SOCKBUF_LOCK(&so->so_snd); + SOCK_SENDBUF_LOCK(so); if (sbspace(&so->so_snd) < softc->ha_sending->m_pkthdr.len) { so->so_snd.sb_lowat = softc->ha_sending->m_pkthdr.len; - SOCKBUF_UNLOCK(&so->so_snd); + SOCK_SENDBUF_UNLOCK(so); break; } - SOCKBUF_UNLOCK(&so->so_snd); + SOCK_SENDBUF_UNLOCK(so); error = sosend(softc->ha_so, NULL, NULL, softc->ha_sending, NULL, MSG_DONTWAIT, curthread); softc->ha_sending = NULL; @@ -312,14 +309,14 @@ ctl_ha_sock_setup(struct ha_softc *softc) if (error) printf("%s: soreserve failed %d\n", __func__, error); - SOCKBUF_LOCK(&so->so_rcv); + SOCK_RECVBUF_LOCK(so); so->so_rcv.sb_lowat = sizeof(struct ha_msg_wire); soupcall_set(so, SO_RCV, ctl_ha_rupcall, softc); - SOCKBUF_UNLOCK(&so->so_rcv); - SOCKBUF_LOCK(&so->so_snd); + SOCK_RECVBUF_UNLOCK(so); + SOCK_SENDBUF_LOCK(so); so->so_snd.sb_lowat = sizeof(struct ha_msg_wire); soupcall_set(so, SO_SND, ctl_ha_supcall, softc); - SOCKBUF_UNLOCK(&so->so_snd); + SOCK_SENDBUF_UNLOCK(so); bzero(&opt, sizeof(struct sockopt)); opt.sopt_dir = SOPT_SET; @@ -400,7 +397,7 @@ static int ctl_ha_accept(struct ha_softc *softc) { struct socket *lso, *so; - struct sockaddr *sap; + struct sockaddr_in sin = { .sin_len = sizeof(sin) }; int error; lso = softc->ha_lso; @@ -413,16 +410,11 @@ ctl_ha_accept(struct ha_softc *softc) goto out; } - sap = NULL; - error = soaccept(so, &sap); + error = soaccept(so, (struct sockaddr *)&sin); if (error != 0) { printf("%s: soaccept() error %d\n", __func__, error); - if (sap != NULL) - free(sap, M_SONAME); goto out; } - if (sap != NULL) - free(sap, M_SONAME); softc->ha_so = so; ctl_ha_sock_setup(softc); return (0); @@ -912,13 +904,16 @@ ctl_ha_msg_shutdown(struct ctl_softc *ctl_softc) { struct ha_softc *softc = &ha_softc; + if (SCHEDULER_STOPPED()) + return; + /* Disconnect and shutdown threads. */ mtx_lock(&softc->ha_lock); if (softc->ha_shutdown < 2) { softc->ha_shutdown = 1; softc->ha_wakeup = 1; wakeup(&softc->ha_wakeup); - while (softc->ha_shutdown < 2 && !SCHEDULER_STOPPED()) { + while (softc->ha_shutdown < 2) { msleep(&softc->ha_wakeup, &softc->ha_lock, 0, "shutdown", hz); } diff --git a/sys/cam/ctl/ctl_ha.h b/sys/cam/ctl/ctl_ha.h index 98f284d5c59d..49a55e16c547 100644 --- a/sys/cam/ctl/ctl_ha.h +++ b/sys/cam/ctl/ctl_ha.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003-2009 Silicon Graphics International Corp. * Copyright (c) 2011 Spectra Logic Corporation @@ -32,12 +32,13 @@ * POSSIBILITY OF SUCH DAMAGES. * * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_ha.h#1 $ - * $FreeBSD$ */ #ifndef _CTL_HA_H_ #define _CTL_HA_H_ +#include <sys/queue.h> + /* * CTL High Availability Modes: * diff --git a/sys/cam/ctl/ctl_io.h b/sys/cam/ctl/ctl_io.h index de312608da8e..6ce3970a0500 100644 --- a/sys/cam/ctl/ctl_io.h +++ b/sys/cam/ctl/ctl_io.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003 Silicon Graphics International Corp. * Copyright (c) 2014-2015 Alexander Motin <mav@FreeBSD.org> @@ -31,7 +31,6 @@ * POSSIBILITY OF SUCH DAMAGES. * * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_io.h#5 $ - * $FreeBSD$ */ /* * CAM Target Layer data movement structures/interface. @@ -46,6 +45,10 @@ #include <stdbool.h> #endif +#include <sys/queue.h> +#include <cam/scsi/scsi_all.h> +#include <dev/nvme/nvme.h> + #define CTL_MAX_CDBLEN 32 /* * Uncomment this next line to enable printing out times for I/Os @@ -72,6 +75,7 @@ typedef enum { CTL_SEL_TIMEOUT, /* Selection timeout, shouldn't happen here */ CTL_ERROR, /* General CTL error XXX expand on this? */ CTL_SCSI_ERROR, /* SCSI error, look at status byte/sense data */ + CTL_NVME_ERROR, /* NVMe error, look at NVMe completion */ CTL_CMD_ABORTED, /* Command aborted, don't return status */ CTL_STATUS_MASK = 0xfff,/* Mask off any status flags */ CTL_AUTOSENSE = 0x1000 /* Autosense performed */ @@ -88,7 +92,7 @@ typedef enum { CTL_FLAG_DATA_OUT = 0x00000002, /* DATA OUT */ CTL_FLAG_DATA_NONE = 0x00000003, /* no data */ CTL_FLAG_DATA_MASK = 0x00000003, - CTL_FLAG_DO_AUTOSENSE = 0x00000020, /* grab sense info */ + CTL_FLAG_USER_TAG = 0x00000020, /* userland provides tag */ CTL_FLAG_USER_REQ = 0x00000040, /* request came from userland */ CTL_FLAG_ALLOCATED = 0x00000100, /* data space allocated */ CTL_FLAG_ABORT_STATUS = 0x00000400, /* return TASK ABORTED status */ @@ -104,7 +108,7 @@ typedef enum { CTL_FLAG_IO_CONT = 0x00100000, /* Continue I/O instead of completing */ #if 0 - CTL_FLAG_ALREADY_DONE = 0x00200000 /* I/O already completed */ + CTL_FLAG_ALREADY_DONE = 0x00200000, /* I/O already completed */ #endif CTL_FLAG_NO_DATAMOVE = 0x00400000, CTL_FLAG_DMA_QUEUED = 0x00800000, /* DMA queued but not started*/ @@ -190,6 +194,8 @@ typedef enum { CTL_IO_NONE, CTL_IO_SCSI, CTL_IO_TASK, + CTL_IO_NVME, + CTL_IO_NVME_ADMIN, } ctl_io_type; struct ctl_nexus { @@ -261,6 +267,8 @@ typedef enum { union ctl_io; typedef void (*ctl_ref)(void *arg, int diff); +typedef int (*ctl_be_move_done_t)(union ctl_io *io, bool samethr); +typedef int (*ctl_io_cont)(union ctl_io *io); /* * SCSI passthrough I/O structure for the CAM Target Layer. Note @@ -328,13 +336,12 @@ struct ctl_scsiio { uint8_t scsi_status; /* SCSI status byte */ uint8_t seridx; /* Serialization index. */ uint8_t priority; /* Command priority */ - uint32_t residual; /* Unused */ - uint32_t tag_num; /* tag number */ + uint64_t tag_num; /* tag number */ ctl_tag_type tag_type; /* simple, ordered, head of queue,etc.*/ uint8_t cdb_len; /* CDB length */ uint8_t cdb[CTL_MAX_CDBLEN]; /* CDB */ - int (*be_move_done)(union ctl_io *io, bool samethr); /* called by fe */ - int (*io_cont)(union ctl_io *io); /* to continue processing */ + ctl_be_move_done_t be_move_done; /* called by fe */ + ctl_io_cont io_cont; /* to continue processing */ ctl_ref kern_data_ref; /* Method to reference/release data */ void *kern_data_arg; /* Opaque argument for kern_data_ref() */ }; @@ -373,16 +380,82 @@ typedef enum { struct ctl_taskio { struct ctl_io_hdr io_hdr; /* common to all I/O types */ ctl_task_type task_action; /* Target Reset, Abort, etc. */ - uint32_t tag_num; /* tag number */ + uint64_t tag_num; /* tag number */ ctl_tag_type tag_type; /* simple, ordered, etc. */ uint8_t task_status; /* Complete, Succeeded, etc. */ uint8_t task_resp[3];/* Response information */ }; /* + * NVME passthrough I/O structure for the CAM Target Layer. Note that + * this structure is used for both I/O and admin commands. + * + * Note: Make sure the io_hdr is *always* the first element in this + * structure. + */ +struct ctl_nvmeio { + struct ctl_io_hdr io_hdr; /* common to all I/O types */ + + /* + * The ext_* fields are generally intended for frontend use; CTL itself + * doesn't modify or use them. + */ + uint32_t ext_sg_entries; /* 0 = no S/G list, > 0 = num entries */ + uint8_t *ext_data_ptr; /* data buffer or S/G list */ + uint32_t ext_data_len; /* Data transfer length */ + uint32_t ext_data_filled; /* Amount of data filled so far */ + + /* + * The number of scatter/gather entries in the list pointed to + * by kern_data_ptr. 0 means there is no list, just a data pointer. + */ + uint32_t kern_sg_entries; + + /* + * The data pointer or a pointer to the scatter/gather list. + */ + uint8_t *kern_data_ptr; + + /* + * Length of the data buffer or scatter/gather list. It's also + * the length of this particular piece of the data transfer, + * ie. number of bytes expected to be transferred by the current + * invocation of frontend's datamove() callback. It's always + * less than or equal to kern_total_len. + */ + uint32_t kern_data_len; + + /* + * Total length of data to be transferred during this particular + * NVMe command, as decoded from the NVMe SQE. + */ + uint32_t kern_total_len; + + /* + * Amount of data left after the current data transfer. + */ + uint32_t kern_data_resid; + + /* + * Byte offset of this transfer, equal to the amount of data + * already transferred for this NVMe command during previous + * datamove() invocations. + */ + uint32_t kern_rel_offset; + + struct nvme_command cmd; /* SQE */ + struct nvme_completion cpl; /* CQE */ + bool success_sent; /* datamove already sent CQE */ + ctl_be_move_done_t be_move_done; /* called by fe */ + ctl_io_cont io_cont; /* to continue processing */ + ctl_ref kern_data_ref; /* Method to reference/release data */ + void *kern_data_arg; /* Opaque argument for kern_data_ref() */ +}; + +/* * HA link messages. */ -#define CTL_HA_VERSION 3 +#define CTL_HA_VERSION 4 /* * Used for CTL_MSG_LOGIN. @@ -483,7 +556,7 @@ struct ctl_ha_msg_dt { */ struct ctl_ha_msg_scsi { struct ctl_ha_msg_hdr hdr; - uint32_t tag_num; /* tag number */ + uint64_t tag_num; /* tag number */ ctl_tag_type tag_type; /* simple, ordered, etc. */ uint8_t cdb[CTL_MAX_CDBLEN]; /* CDB */ uint8_t cdb_len; /* CDB length */ @@ -502,7 +575,7 @@ struct ctl_ha_msg_scsi { struct ctl_ha_msg_task { struct ctl_ha_msg_hdr hdr; ctl_task_type task_action; /* Target Reset, Abort, etc. */ - uint32_t tag_num; /* tag number */ + uint64_t tag_num; /* tag number */ ctl_tag_type tag_type; /* simple, ordered, etc. */ }; @@ -587,10 +660,286 @@ union ctl_io { struct ctl_io_hdr io_hdr; /* common to all I/O types */ struct ctl_scsiio scsiio; /* Normal SCSI commands */ struct ctl_taskio taskio; /* SCSI task management/reset */ + struct ctl_nvmeio nvmeio; /* Normal and admin NVMe commands */ struct ctl_prio presio; /* update per. res info on other SC */ }; #ifdef _KERNEL +#define _CTL_IO_ASSERT_1(io, _1) \ + KASSERT((io)->io_hdr.io_type == CTL_IO_##_1, \ + ("%s: unexpected I/O type %x", __func__, (io)->io_hdr.io_type)) + +#define _CTL_IO_ASSERT_2(io, _1, _2) \ + KASSERT((io)->io_hdr.io_type == CTL_IO_##_1 || \ + (io)->io_hdr.io_type == CTL_IO_##_2, \ + ("%s: unexpected I/O type %x", __func__, (io)->io_hdr.io_type)) + +#define _CTL_IO_ASSERT_MACRO(io, _1, _2, NAME, ...) \ + NAME + +#define CTL_IO_ASSERT(...) \ + _CTL_IO_ASSERT_MACRO(__VA_ARGS__, _CTL_IO_ASSERT_2, \ + _CTL_IO_ASSERT_1)(__VA_ARGS__) + +static __inline uint32_t +ctl_kern_sg_entries(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + return (io->scsiio.kern_sg_entries); + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + return (io->nvmeio.kern_sg_entries); + default: + __assert_unreachable(); + } +} + +static __inline uint8_t * +ctl_kern_data_ptr(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + return (io->scsiio.kern_data_ptr); + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + return (io->nvmeio.kern_data_ptr); + default: + __assert_unreachable(); + } +} + +static __inline uint32_t +ctl_kern_data_len(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + return (io->scsiio.kern_data_len); + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + return (io->nvmeio.kern_data_len); + default: + __assert_unreachable(); + } +} + +static __inline uint32_t +ctl_kern_total_len(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + return (io->scsiio.kern_total_len); + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + return (io->nvmeio.kern_total_len); + default: + __assert_unreachable(); + } +} + +static __inline uint32_t +ctl_kern_data_resid(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + return (io->scsiio.kern_data_resid); + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + return (io->nvmeio.kern_data_resid); + default: + __assert_unreachable(); + } +} + +static __inline uint32_t +ctl_kern_rel_offset(union ctl_io *io) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + return (io->scsiio.kern_rel_offset); + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + return (io->nvmeio.kern_rel_offset); + default: + __assert_unreachable(); + } +} + +static __inline void +ctl_add_kern_rel_offset(union ctl_io *io, uint32_t offset) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + io->scsiio.kern_rel_offset += offset; + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + io->nvmeio.kern_rel_offset += offset; + break; + default: + __assert_unreachable(); + } +} + +static __inline void +ctl_set_kern_sg_entries(union ctl_io *io, uint32_t kern_sg_entries) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + io->scsiio.kern_sg_entries = kern_sg_entries; + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + io->nvmeio.kern_sg_entries = kern_sg_entries; + break; + default: + __assert_unreachable(); + } +} + +static __inline void +ctl_set_kern_data_ptr(union ctl_io *io, void *kern_data_ptr) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + io->scsiio.kern_data_ptr = kern_data_ptr; + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + io->nvmeio.kern_data_ptr = kern_data_ptr; + break; + default: + __assert_unreachable(); + } +} + +static __inline void +ctl_set_kern_data_len(union ctl_io *io, uint32_t kern_data_len) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + io->scsiio.kern_data_len = kern_data_len; + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + io->nvmeio.kern_data_len = kern_data_len; + break; + default: + __assert_unreachable(); + } +} + +static __inline void +ctl_set_kern_total_len(union ctl_io *io, uint32_t kern_total_len) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + io->scsiio.kern_total_len = kern_total_len; + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + io->nvmeio.kern_total_len = kern_total_len; + break; + default: + __assert_unreachable(); + } +} + +static __inline void +ctl_set_kern_data_resid(union ctl_io *io, uint32_t kern_data_resid) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + io->scsiio.kern_data_resid = kern_data_resid; + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + io->nvmeio.kern_data_resid = kern_data_resid; + break; + default: + __assert_unreachable(); + } +} + +static __inline void +ctl_set_kern_rel_offset(union ctl_io *io, uint32_t kern_rel_offset) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + io->scsiio.kern_rel_offset = kern_rel_offset; + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + io->nvmeio.kern_rel_offset = kern_rel_offset; + break; + default: + __assert_unreachable(); + } +} + +static __inline void +ctl_set_be_move_done(union ctl_io *io, ctl_be_move_done_t be_move_done) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + io->scsiio.be_move_done = be_move_done; + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + io->nvmeio.be_move_done = be_move_done; + break; + default: + __assert_unreachable(); + } +} + +static __inline void +ctl_set_io_cont(union ctl_io *io, ctl_io_cont io_cont) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + io->scsiio.io_cont = io_cont; + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + io->nvmeio.io_cont = io_cont; + break; + default: + __assert_unreachable(); + } +} + +static __inline void +ctl_set_kern_data_ref(union ctl_io *io, ctl_ref kern_data_ref) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + io->scsiio.kern_data_ref = kern_data_ref; + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + io->nvmeio.kern_data_ref = kern_data_ref; + break; + default: + __assert_unreachable(); + } +} + +static __inline void +ctl_set_kern_data_arg(union ctl_io *io, void *kern_data_arg) +{ + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + io->scsiio.kern_data_arg = kern_data_arg; + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + io->nvmeio.kern_data_arg = kern_data_arg; + break; + default: + __assert_unreachable(); + } +} union ctl_io *ctl_alloc_io(void *pool_ref); union ctl_io *ctl_alloc_io_nowait(void *pool_ref); diff --git a/sys/cam/ctl/ctl_ioctl.h b/sys/cam/ctl/ctl_ioctl.h index 5cb7f29d82a7..326e4c931f93 100644 --- a/sys/cam/ctl/ctl_ioctl.h +++ b/sys/cam/ctl/ctl_ioctl.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003 Silicon Graphics International Corp. * Copyright (c) 2011 Spectra Logic Corporation @@ -32,7 +32,6 @@ * POSSIBILITY OF SUCH DAMAGES. * * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_ioctl.h#4 $ - * $FreeBSD$ */ /* * CAM Target Layer ioctl interface. @@ -49,6 +48,8 @@ #include <sys/ioccom.h> #include <sys/nv.h> +#include <dev/nvmf/nvmf.h> +#include <dev/nvmf/nvmf_proto.h> #define CTL_DEFAULT_DEV "/dev/cam/ctl" /* @@ -256,7 +257,8 @@ struct ctl_ooa_entry { ctl_ooa_cmd_flags cmd_flags; uint8_t cdb[CTL_MAX_CDBLEN]; uint8_t cdb_len; - uint32_t tag_num; + uint64_t tag_num; + ctl_tag_type tag_type; uint32_t lun_num; struct bintime start_bt; }; @@ -460,6 +462,7 @@ struct ctl_lun_req { union ctl_lunreq_data reqdata; void * args; nvlist_t * args_nvl; +#define CTL_MAX_ARGS_LEN (1024 * 1024) size_t args_len; void * result; nvlist_t * result_nvl; @@ -760,6 +763,65 @@ struct ctl_lun_map { uint32_t lun; }; +/* + * NVMe over Fabrics status + * + * OK: Request completed successfully. + * + * ERROR: An error occurred, look at the error string for a + * description of the error. + */ +typedef enum { + CTL_NVMF_OK, + CTL_NVMF_ERROR, + CTL_NVMF_LIST_NEED_MORE_SPACE, + CTL_NVMF_ASSOCIATION_NOT_FOUND +} ctl_nvmf_status; + +typedef enum { + CTL_NVMF_HANDOFF, + CTL_NVMF_LIST, + CTL_NVMF_TERMINATE +} ctl_nvmf_type; + +struct ctl_nvmf_list_params { + uint32_t alloc_len; /* passed to kernel */ + char *conn_xml; /* filled in kernel */ + uint32_t fill_len; /* passed to userland */ + int spare[4]; +}; + +struct ctl_nvmf_terminate_params { + int cntlid; /* passed to kernel */ + char hostnqn[NVME_NQN_FIELD_SIZE]; + /* passed to kernel */ + int all; /* passed to kernel */ + int spare[4]; +}; + +union ctl_nvmf_data { + struct nvmf_handoff_controller_qpair handoff; + struct ctl_nvmf_list_params list; + struct ctl_nvmf_terminate_params terminate; +}; + +/* + * NVMe over Fabrics interface + * + * status: The status of the request. See above for the + * description of the values of this field. + * + * error_str: If the status indicates an error, this string will + * be filled in to describe the error. + */ +struct ctl_nvmf { + ctl_nvmf_type type; /* passed to kernel */ + union ctl_nvmf_data data; /* passed to kernel */ + ctl_nvmf_status status; /* passed to userland */ + char error_str[CTL_ERROR_STR_LEN]; + /* passed to userland */ +}; + #define CTL_IO _IOWR(CTL_MINOR, 0x00, union ctl_io) #define CTL_ENABLE_PORT _IOW(CTL_MINOR, 0x04, struct ctl_port_entry) #define CTL_DISABLE_PORT _IOW(CTL_MINOR, 0x05, struct ctl_port_entry) @@ -777,6 +839,7 @@ struct ctl_lun_map { #define CTL_LUN_MAP _IOW(CTL_MINOR, 0x28, struct ctl_lun_map) #define CTL_GET_LUN_STATS _IOWR(CTL_MINOR, 0x29, struct ctl_get_io_stats) #define CTL_GET_PORT_STATS _IOWR(CTL_MINOR, 0x2a, struct ctl_get_io_stats) +#define CTL_NVMF _IOWR(CTL_MINOR, 0x2b, struct ctl_nvmf) #endif /* _CTL_IOCTL_H_ */ diff --git a/sys/cam/ctl/ctl_nvme_all.c b/sys/cam/ctl/ctl_nvme_all.c new file mode 100644 index 000000000000..739efadf5614 --- /dev/null +++ b/sys/cam/ctl/ctl_nvme_all.c @@ -0,0 +1,244 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (C) 2012-2014 Intel Corporation + * All rights reserved. + * + * Copyright (c) 2023 Chelsio Communications, Inc. + */ + +#include <sys/types.h> +#include <sys/sbuf.h> +#ifndef _KERNEL +#include <sys/time.h> +#include <stdio.h> +#endif + +#include <dev/nvme/nvme.h> + +#include <cam/ctl/ctl_io.h> +#include <cam/ctl/ctl_nvme_all.h> + +/* XXX: This duplicates lists in nvme_qpair.c. */ + +#define OPC_ENTRY(x) [NVME_OPC_ ## x] = #x + +static const char *admin_opcode[256] = { + OPC_ENTRY(DELETE_IO_SQ), + OPC_ENTRY(CREATE_IO_SQ), + OPC_ENTRY(GET_LOG_PAGE), + OPC_ENTRY(DELETE_IO_CQ), + OPC_ENTRY(CREATE_IO_CQ), + OPC_ENTRY(IDENTIFY), + OPC_ENTRY(ABORT), + OPC_ENTRY(SET_FEATURES), + OPC_ENTRY(GET_FEATURES), + OPC_ENTRY(ASYNC_EVENT_REQUEST), + OPC_ENTRY(NAMESPACE_MANAGEMENT), + OPC_ENTRY(FIRMWARE_ACTIVATE), + OPC_ENTRY(FIRMWARE_IMAGE_DOWNLOAD), + OPC_ENTRY(DEVICE_SELF_TEST), + OPC_ENTRY(NAMESPACE_ATTACHMENT), + OPC_ENTRY(KEEP_ALIVE), + OPC_ENTRY(DIRECTIVE_SEND), + OPC_ENTRY(DIRECTIVE_RECEIVE), + OPC_ENTRY(VIRTUALIZATION_MANAGEMENT), + OPC_ENTRY(NVME_MI_SEND), + OPC_ENTRY(NVME_MI_RECEIVE), + OPC_ENTRY(CAPACITY_MANAGEMENT), + OPC_ENTRY(LOCKDOWN), + OPC_ENTRY(DOORBELL_BUFFER_CONFIG), + OPC_ENTRY(FABRICS_COMMANDS), + OPC_ENTRY(FORMAT_NVM), + OPC_ENTRY(SECURITY_SEND), + OPC_ENTRY(SECURITY_RECEIVE), + OPC_ENTRY(SANITIZE), + OPC_ENTRY(GET_LBA_STATUS), +}; + +static const char *nvm_opcode[256] = { + OPC_ENTRY(FLUSH), + OPC_ENTRY(WRITE), + OPC_ENTRY(READ), + OPC_ENTRY(WRITE_UNCORRECTABLE), + OPC_ENTRY(COMPARE), + OPC_ENTRY(WRITE_ZEROES), + OPC_ENTRY(DATASET_MANAGEMENT), + OPC_ENTRY(VERIFY), + OPC_ENTRY(RESERVATION_REGISTER), + OPC_ENTRY(RESERVATION_REPORT), + OPC_ENTRY(RESERVATION_ACQUIRE), + OPC_ENTRY(RESERVATION_RELEASE), + OPC_ENTRY(COPY), +}; + +void +ctl_nvme_command_string(struct ctl_nvmeio *ctnio, struct sbuf *sb) +{ + const char *s, *type; + + if (ctnio->io_hdr.io_type == CTL_IO_NVME_ADMIN) { + s = admin_opcode[ctnio->cmd.opc]; + type = "ADMIN"; + } else { + s = nvm_opcode[ctnio->cmd.opc]; + type = "NVM"; + } + if (s == NULL) + sbuf_printf(sb, "%s:0x%02x", type, ctnio->cmd.opc); + else + sbuf_printf(sb, "%s", s); +} + +#define SC_ENTRY(x) [NVME_SC_ ## x] = #x + +static const char *generic_status[256] = { + SC_ENTRY(SUCCESS), + SC_ENTRY(INVALID_OPCODE), + SC_ENTRY(INVALID_FIELD), + SC_ENTRY(COMMAND_ID_CONFLICT), + SC_ENTRY(DATA_TRANSFER_ERROR), + SC_ENTRY(ABORTED_POWER_LOSS), + SC_ENTRY(INTERNAL_DEVICE_ERROR), + SC_ENTRY(ABORTED_BY_REQUEST), + SC_ENTRY(ABORTED_SQ_DELETION), + SC_ENTRY(ABORTED_FAILED_FUSED), + SC_ENTRY(ABORTED_MISSING_FUSED), + SC_ENTRY(INVALID_NAMESPACE_OR_FORMAT), + SC_ENTRY(COMMAND_SEQUENCE_ERROR), + SC_ENTRY(INVALID_SGL_SEGMENT_DESCR), + SC_ENTRY(INVALID_NUMBER_OF_SGL_DESCR), + SC_ENTRY(DATA_SGL_LENGTH_INVALID), + SC_ENTRY(METADATA_SGL_LENGTH_INVALID), + SC_ENTRY(SGL_DESCRIPTOR_TYPE_INVALID), + SC_ENTRY(INVALID_USE_OF_CMB), + SC_ENTRY(PRP_OFFET_INVALID), + SC_ENTRY(ATOMIC_WRITE_UNIT_EXCEEDED), + SC_ENTRY(OPERATION_DENIED), + SC_ENTRY(SGL_OFFSET_INVALID), + SC_ENTRY(HOST_ID_INCONSISTENT_FORMAT), + SC_ENTRY(KEEP_ALIVE_TIMEOUT_EXPIRED), + SC_ENTRY(KEEP_ALIVE_TIMEOUT_INVALID), + SC_ENTRY(ABORTED_DUE_TO_PREEMPT), + SC_ENTRY(SANITIZE_FAILED), + SC_ENTRY(SANITIZE_IN_PROGRESS), + SC_ENTRY(SGL_DATA_BLOCK_GRAN_INVALID), + SC_ENTRY(NOT_SUPPORTED_IN_CMB), + SC_ENTRY(NAMESPACE_IS_WRITE_PROTECTED), + SC_ENTRY(COMMAND_INTERRUPTED), + SC_ENTRY(TRANSIENT_TRANSPORT_ERROR), + + SC_ENTRY(LBA_OUT_OF_RANGE), + SC_ENTRY(CAPACITY_EXCEEDED), + SC_ENTRY(NAMESPACE_NOT_READY), + SC_ENTRY(RESERVATION_CONFLICT), + SC_ENTRY(FORMAT_IN_PROGRESS), +}; + +static const char *command_specific_status[256] = { + SC_ENTRY(COMPLETION_QUEUE_INVALID), + SC_ENTRY(INVALID_QUEUE_IDENTIFIER), + SC_ENTRY(MAXIMUM_QUEUE_SIZE_EXCEEDED), + SC_ENTRY(ABORT_COMMAND_LIMIT_EXCEEDED), + SC_ENTRY(ASYNC_EVENT_REQUEST_LIMIT_EXCEEDED), + SC_ENTRY(INVALID_FIRMWARE_SLOT), + SC_ENTRY(INVALID_FIRMWARE_IMAGE), + SC_ENTRY(INVALID_INTERRUPT_VECTOR), + SC_ENTRY(INVALID_LOG_PAGE), + SC_ENTRY(INVALID_FORMAT), + SC_ENTRY(FIRMWARE_REQUIRES_RESET), + SC_ENTRY(INVALID_QUEUE_DELETION), + SC_ENTRY(FEATURE_NOT_SAVEABLE), + SC_ENTRY(FEATURE_NOT_CHANGEABLE), + SC_ENTRY(FEATURE_NOT_NS_SPECIFIC), + SC_ENTRY(FW_ACT_REQUIRES_NVMS_RESET), + SC_ENTRY(FW_ACT_REQUIRES_RESET), + SC_ENTRY(FW_ACT_REQUIRES_TIME), + SC_ENTRY(FW_ACT_PROHIBITED), + SC_ENTRY(OVERLAPPING_RANGE), + SC_ENTRY(NS_INSUFFICIENT_CAPACITY), + SC_ENTRY(NS_ID_UNAVAILABLE), + SC_ENTRY(NS_ALREADY_ATTACHED), + SC_ENTRY(NS_IS_PRIVATE), + SC_ENTRY(NS_NOT_ATTACHED), + SC_ENTRY(THIN_PROV_NOT_SUPPORTED), + SC_ENTRY(CTRLR_LIST_INVALID), + SC_ENTRY(SELF_TEST_IN_PROGRESS), + SC_ENTRY(BOOT_PART_WRITE_PROHIB), + SC_ENTRY(INVALID_CTRLR_ID), + SC_ENTRY(INVALID_SEC_CTRLR_STATE), + SC_ENTRY(INVALID_NUM_OF_CTRLR_RESRC), + SC_ENTRY(INVALID_RESOURCE_ID), + SC_ENTRY(SANITIZE_PROHIBITED_WPMRE), + SC_ENTRY(ANA_GROUP_ID_INVALID), + SC_ENTRY(ANA_ATTACH_FAILED), + + SC_ENTRY(CONFLICTING_ATTRIBUTES), + SC_ENTRY(INVALID_PROTECTION_INFO), + SC_ENTRY(ATTEMPTED_WRITE_TO_RO_PAGE), +}; + +static const char *media_error_status[256] = { + SC_ENTRY(WRITE_FAULTS), + SC_ENTRY(UNRECOVERED_READ_ERROR), + SC_ENTRY(GUARD_CHECK_ERROR), + SC_ENTRY(APPLICATION_TAG_CHECK_ERROR), + SC_ENTRY(REFERENCE_TAG_CHECK_ERROR), + SC_ENTRY(COMPARE_FAILURE), + SC_ENTRY(ACCESS_DENIED), + SC_ENTRY(DEALLOCATED_OR_UNWRITTEN), +}; + +static const char *path_related_status[256] = { + SC_ENTRY(INTERNAL_PATH_ERROR), + SC_ENTRY(ASYMMETRIC_ACCESS_PERSISTENT_LOSS), + SC_ENTRY(ASYMMETRIC_ACCESS_INACCESSIBLE), + SC_ENTRY(ASYMMETRIC_ACCESS_TRANSITION), + SC_ENTRY(CONTROLLER_PATHING_ERROR), + SC_ENTRY(HOST_PATHING_ERROR), + SC_ENTRY(COMMAND_ABORTED_BY_HOST), +}; + +void +ctl_nvme_status_string(struct ctl_nvmeio *ctnio, struct sbuf *sb) +{ + const char *s, *type; + uint16_t status; + + status = le16toh(ctnio->cpl.status); + switch (NVME_STATUS_GET_SCT(status)) { + case NVME_SCT_GENERIC: + s = generic_status[NVME_STATUS_GET_SC(status)]; + type = "GENERIC"; + break; + case NVME_SCT_COMMAND_SPECIFIC: + s = command_specific_status[NVME_STATUS_GET_SC(status)]; + type = "COMMAND SPECIFIC"; + break; + case NVME_SCT_MEDIA_ERROR: + s = media_error_status[NVME_STATUS_GET_SC(status)]; + type = "MEDIA ERROR"; + break; + case NVME_SCT_PATH_RELATED: + s = path_related_status[NVME_STATUS_GET_SC(status)]; + type = "PATH RELATED"; + break; + case NVME_SCT_VENDOR_SPECIFIC: + s = NULL; + type = "VENDOR SPECIFIC"; + break; + default: + s = "RESERVED"; + type = NULL; + break; + } + + if (s == NULL) + sbuf_printf(sb, "%s:0x%02x", type, NVME_STATUS_GET_SC(status)); + else + sbuf_printf(sb, "%s", s); + if (NVME_STATUS_GET_M(status) != 0) + sbuf_printf(sb, " M"); + if (NVME_STATUS_GET_DNR(status) != 0) + sbuf_printf(sb, " DNR"); +} diff --git a/sys/cam/ctl/ctl_nvme_all.h b/sys/cam/ctl/ctl_nvme_all.h new file mode 100644 index 000000000000..df0bf585c3ae --- /dev/null +++ b/sys/cam/ctl/ctl_nvme_all.h @@ -0,0 +1,17 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 Chelsio Communications, Inc. + */ + +#ifndef __CTL_NVME_ALL_H__ +#define __CTL_NVME_ALL_H__ + +__BEGIN_DECLS + +void ctl_nvme_command_string(struct ctl_nvmeio *ctnio, struct sbuf *sb); +void ctl_nvme_status_string(struct ctl_nvmeio *ctnio, struct sbuf *sb); + +__END_DECLS + +#endif /* !__CTL_NVME_ALL_H__ */ diff --git a/sys/cam/ctl/ctl_nvme_cmd_table.c b/sys/cam/ctl/ctl_nvme_cmd_table.c new file mode 100644 index 000000000000..39e60de62b7f --- /dev/null +++ b/sys/cam/ctl/ctl_nvme_cmd_table.c @@ -0,0 +1,35 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 Chelsio Communications, Inc. + */ + +#include <dev/nvme/nvme.h> + +#include <cam/ctl/ctl.h> +#include <cam/ctl/ctl_ha.h> +#include <cam/ctl/ctl_io.h> +#include <cam/ctl/ctl_ioctl.h> +#include <cam/ctl/ctl_private.h> + +/* Administrative Command Set (CTL_IO_NVME_ADMIN). */ +const struct ctl_nvme_cmd_entry nvme_admin_cmd_table[256] = +{ + [NVME_OPC_IDENTIFY] = { ctl_nvme_identify, CTL_FLAG_DATA_IN | + CTL_CMD_FLAG_OK_ON_NO_LUN }, +}; + +/* NVM Command Set (CTL_IO_NVME). */ +const struct ctl_nvme_cmd_entry nvme_nvm_cmd_table[256] = +{ + [NVME_OPC_FLUSH] = { ctl_nvme_flush, CTL_FLAG_DATA_NONE }, + [NVME_OPC_WRITE] = { ctl_nvme_read_write, CTL_FLAG_DATA_OUT }, + [NVME_OPC_READ] = { ctl_nvme_read_write, CTL_FLAG_DATA_IN }, + [NVME_OPC_WRITE_UNCORRECTABLE] = { ctl_nvme_write_uncorrectable, + CTL_FLAG_DATA_NONE }, + [NVME_OPC_COMPARE] = { ctl_nvme_compare, CTL_FLAG_DATA_OUT }, + [NVME_OPC_WRITE_ZEROES] = { ctl_nvme_write_zeroes, CTL_FLAG_DATA_NONE }, + [NVME_OPC_DATASET_MANAGEMENT] = { ctl_nvme_dataset_management, + CTL_FLAG_DATA_OUT }, + [NVME_OPC_VERIFY] = { ctl_nvme_verify, CTL_FLAG_DATA_NONE }, +}; diff --git a/sys/cam/ctl/ctl_private.h b/sys/cam/ctl/ctl_private.h index a891041e8f50..cd7e499c60a6 100644 --- a/sys/cam/ctl/ctl_private.h +++ b/sys/cam/ctl/ctl_private.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003, 2004, 2005, 2008 Silicon Graphics International Corp. * Copyright (c) 2014-2017 Alexander Motin <mav@FreeBSD.org> @@ -31,7 +31,6 @@ * POSSIBILITY OF SUCH DAMAGES. * * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_private.h#7 $ - * $FreeBSD$ */ /* * CAM Target Layer driver private data structures/definitions. @@ -42,6 +41,7 @@ #ifndef _CTL_PRIVATE_H_ #define _CTL_PRIVATE_H_ +#include <sys/sysctl.h> #include <cam/scsi/scsi_all.h> #include <cam/scsi/scsi_cd.h> #include <cam/scsi/scsi_da.h> @@ -78,7 +78,8 @@ typedef enum { CTL_ACTION_SKIP, CTL_ACTION_BLOCK, CTL_ACTION_OVERLAP, - CTL_ACTION_OVERLAP_TAG + CTL_ACTION_OVERLAP_TAG, + CTL_ACTION_FUSED, } ctl_action; /* @@ -139,6 +140,12 @@ struct ctl_cmd_entry { * after the opcode byte. */ }; +/* Only data flags are currently used for NVMe commands. */ +struct ctl_nvme_cmd_entry { + int (*execute)(struct ctl_nvmeio *); + ctl_io_flags flags; +}; + typedef enum { CTL_LUN_NONE = 0x000, CTL_LUN_CONTROL = 0x001, @@ -168,61 +175,6 @@ union ctl_softcs { /* * Mode page defaults. */ -#if 0 -/* - * These values make Solaris trim off some of the capacity. - */ -#define CTL_DEFAULT_SECTORS_PER_TRACK 63 -#define CTL_DEFAULT_HEADS 255 -/* - * These values seem to work okay. - */ -#define CTL_DEFAULT_SECTORS_PER_TRACK 63 -#define CTL_DEFAULT_HEADS 16 -/* - * These values work reasonably well. - */ -#define CTL_DEFAULT_SECTORS_PER_TRACK 512 -#define CTL_DEFAULT_HEADS 64 -#endif - -/* - * Solaris is somewhat picky about how many heads and sectors per track you - * have defined in mode pages 3 and 4. These values seem to cause Solaris - * to get the capacity more or less right when you run the format tool. - * They still have problems when dealing with devices larger than 1TB, - * but there isn't anything we can do about that. - * - * For smaller LUN sizes, this ends up causing the number of cylinders to - * work out to 0. Solaris actually recognizes that and comes up with its - * own bogus geometry to fit the actual capacity of the drive. They really - * should just give up on geometry and stick to the read capacity - * information alone for modern disk drives. - * - * One thing worth mentioning about Solaris' mkfs command is that it - * doesn't like sectors per track values larger than 256. 512 seems to - * work okay for format, but causes problems when you try to make a - * filesystem. - * - * Another caveat about these values: the product of these two values - * really should be a power of 2. This is because of the simplistic - * shift-based calculation that we have to use on the i386 platform to - * calculate the number of cylinders here. (If you use a divide, you end - * up calling __udivdi3(), which is a hardware FP call on the PC. On the - * XScale, it is done in software, so you can do that from inside the - * kernel.) - * - * So for the current values (256 S/T, 128 H), we get 32768, which works - * very nicely for calculating cylinders. - * - * If you want to change these values so that their product is no longer a - * power of 2, re-visit the calculation in ctl_init_page_index(). You may - * need to make it a bit more complicated to get the number of cylinders - * right. - */ -#define CTL_DEFAULT_SECTORS_PER_TRACK 256 -#define CTL_DEFAULT_HEADS 128 - #define CTL_DEFAULT_ROTATION_RATE SVPD_NON_ROTATING struct ctl_page_index; @@ -271,10 +223,6 @@ struct ctl_logical_block_provisioning_page { static const struct ctl_page_index page_index_template[] = { {SMS_RW_ERROR_RECOVERY_PAGE, 0, sizeof(struct scsi_da_rw_recovery_page), NULL, CTL_PAGE_FLAG_DIRECT | CTL_PAGE_FLAG_CDROM, NULL, ctl_default_page_handler}, - {SMS_FORMAT_DEVICE_PAGE, 0, sizeof(struct scsi_format_page), NULL, - CTL_PAGE_FLAG_DIRECT, NULL, NULL}, - {SMS_RIGID_DISK_PAGE, 0, sizeof(struct scsi_rigid_disk_page), NULL, - CTL_PAGE_FLAG_DIRECT, NULL, NULL}, {SMS_VERIFY_ERROR_RECOVERY_PAGE, 0, sizeof(struct scsi_da_verify_recovery_page), NULL, CTL_PAGE_FLAG_DIRECT | CTL_PAGE_FLAG_CDROM, NULL, ctl_default_page_handler}, {SMS_CACHING_PAGE, 0, sizeof(struct scsi_caching_page), NULL, @@ -300,8 +248,6 @@ static const struct ctl_page_index page_index_template[] = { struct ctl_mode_pages { struct scsi_da_rw_recovery_page rw_er_page[4]; - struct scsi_format_page format_page[4]; - struct scsi_rigid_disk_page rigid_disk_page[4]; struct scsi_da_verify_recovery_page verify_er_page[4]; struct scsi_caching_page caching_page[4]; struct scsi_control_page control_page[4]; @@ -313,8 +259,6 @@ struct ctl_mode_pages { }; #define MODE_RWER mode_pages.rw_er_page[CTL_PAGE_CURRENT] -#define MODE_FMT mode_pages.format_page[CTL_PAGE_CURRENT] -#define MODE_RDISK mode_pages.rigid_disk_page[CTL_PAGE_CURRENT] #define MODE_VER mode_pages.verify_er_page[CTL_PAGE_CURRENT] #define MODE_CACHING mode_pages.caching_page[CTL_PAGE_CURRENT] #define MODE_CTRL mode_pages.control_page[CTL_PAGE_CURRENT] @@ -475,6 +419,8 @@ struct ctl_softc { #ifdef _KERNEL extern const struct ctl_cmd_entry ctl_cmd_table[256]; +extern const struct ctl_nvme_cmd_entry nvme_admin_cmd_table[256]; +extern const struct ctl_nvme_cmd_entry nvme_nvm_cmd_table[256]; uint32_t ctl_get_initindex(struct ctl_nexus *nexus); int ctl_lun_map_init(struct ctl_port *port); @@ -522,6 +468,15 @@ int ctl_report_supported_tmf(struct ctl_scsiio *ctsio); int ctl_report_timestamp(struct ctl_scsiio *ctsio); int ctl_get_lba_status(struct ctl_scsiio *ctsio); +int ctl_nvme_identify(struct ctl_nvmeio *ctnio); +int ctl_nvme_flush(struct ctl_nvmeio *ctnio); +int ctl_nvme_read_write(struct ctl_nvmeio *ctnio); +int ctl_nvme_write_uncorrectable(struct ctl_nvmeio *ctnio); +int ctl_nvme_compare(struct ctl_nvmeio *ctnio); +int ctl_nvme_write_zeroes(struct ctl_nvmeio *ctnio); +int ctl_nvme_dataset_management(struct ctl_nvmeio *ctnio); +int ctl_nvme_verify(struct ctl_nvmeio *ctnio); + void ctl_tpc_init(struct ctl_softc *softc); void ctl_tpc_shutdown(struct ctl_softc *softc); void ctl_tpc_lun_init(struct ctl_lun *lun); diff --git a/sys/cam/ctl/ctl_scsi_all.c b/sys/cam/ctl/ctl_scsi_all.c index 98dba8cf2d83..84fa5656fb5f 100644 --- a/sys/cam/ctl/ctl_scsi_all.c +++ b/sys/cam/ctl/ctl_scsi_all.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Implementation of Utility functions for all SCSI device types. * @@ -32,9 +32,6 @@ */ #include <sys/param.h> - -__FBSDID("$FreeBSD$"); - #include <sys/types.h> #ifdef _KERNEL #include <sys/systm.h> @@ -112,12 +109,12 @@ ctl_scsi_command_string(struct ctl_scsiio *ctsio, } void -ctl_scsi_path_string(union ctl_io *io, char *path_str, int len) +ctl_scsi_path_string(struct ctl_io_hdr *hdr, char *path_str, int len) { snprintf(path_str, len, "(%u:%u:%u/%u): ", - io->io_hdr.nexus.initid, io->io_hdr.nexus.targ_port, - io->io_hdr.nexus.targ_lun, io->io_hdr.nexus.targ_mapped_lun); + hdr->nexus.initid, hdr->nexus.targ_port, + hdr->nexus.targ_lun, hdr->nexus.targ_mapped_lun); } /* @@ -133,14 +130,14 @@ ctl_scsi_sense_sbuf(struct ctl_scsiio *ctsio, if ((ctsio == NULL) || (sb == NULL)) return(-1); - ctl_scsi_path_string((union ctl_io *)ctsio, path_str, sizeof(path_str)); + ctl_scsi_path_string(&ctsio->io_hdr, path_str, sizeof(path_str)); if (flags & SSS_FLAG_PRINT_COMMAND) { sbuf_cat(sb, path_str); ctl_scsi_command_string(ctsio, inq_data, sb); - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); } scsi_sense_only_sbuf(&ctsio->sense_data, ctsio->sense_len, sb, diff --git a/sys/cam/ctl/ctl_scsi_all.h b/sys/cam/ctl/ctl_scsi_all.h index 91e41365cb49..ebf69c967978 100644 --- a/sys/cam/ctl/ctl_scsi_all.h +++ b/sys/cam/ctl/ctl_scsi_all.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs. * Copyright (c) 1997, 1998, 2003 Kenneth D. Merry. @@ -28,9 +28,6 @@ * * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_scsi_all.h#2 $ */ - -__FBSDID("$FreeBSD$"); - __BEGIN_DECLS const char * ctl_scsi_status_string(struct ctl_scsiio *ctsio); #ifdef _KERNEL @@ -46,7 +43,7 @@ int ctl_scsi_command_string(struct ctl_scsiio *ctsio, int ctl_scsi_sense_sbuf(struct ctl_scsiio *ctsio, struct scsi_inquiry_data *inq_data, struct sbuf *sb, scsi_sense_string_flags flags); -void ctl_scsi_path_string(union ctl_io *io, char *path_str, int strlen); +void ctl_scsi_path_string(struct ctl_io_hdr *hdr, char *path_str, int strlen); char *ctl_scsi_sense_string(struct ctl_scsiio *ctsio, struct scsi_inquiry_data *inq_data, char *str, int str_len); diff --git a/sys/cam/ctl/ctl_ser_table.c b/sys/cam/ctl/ctl_ser_table.c index be9ca6b34631..9af16168c352 100644 --- a/sys/cam/ctl/ctl_ser_table.c +++ b/sys/cam/ctl/ctl_ser_table.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003 Silicon Graphics International Corp. * All rights reserved. @@ -30,7 +30,6 @@ * POSSIBILITY OF SUCH DAMAGES. * * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_ser_table.c#1 $ - * $FreeBSD$ */ /* diff --git a/sys/cam/ctl/ctl_tpc.c b/sys/cam/ctl/ctl_tpc.c index 66ac2a1023e9..824a0debb25e 100644 --- a/sys/cam/ctl/ctl_tpc.c +++ b/sys/cam/ctl/ctl_tpc.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2014-2021 Alexander Motin <mav@FreeBSD.org> * All rights reserved. @@ -26,9 +26,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> diff --git a/sys/cam/ctl/ctl_tpc.h b/sys/cam/ctl/ctl_tpc.h index 109b11f2f26e..760db0fac678 100644 --- a/sys/cam/ctl/ctl_tpc.h +++ b/sys/cam/ctl/ctl_tpc.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2014 Alexander Motin <mav@FreeBSD.org> * All rights reserved. @@ -24,8 +24,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _CTL_TPC_H diff --git a/sys/cam/ctl/ctl_tpc_local.c b/sys/cam/ctl/ctl_tpc_local.c index ba6deada86a3..5b353046eda7 100644 --- a/sys/cam/ctl/ctl_tpc_local.c +++ b/sys/cam/ctl/ctl_tpc_local.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2014 Alexander Motin <mav@FreeBSD.org> * Copyright (c) 2004, 2005 Silicon Graphics International Corp. @@ -27,9 +27,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> @@ -61,7 +58,7 @@ __FBSDID("$FreeBSD$"); struct tpcl_softc { struct ctl_port port; - int cur_tag_num; + u_int cur_tag_num; }; static struct tpcl_softc tpcl_softc; diff --git a/sys/cam/ctl/ctl_util.c b/sys/cam/ctl/ctl_util.c index 245c3e89dfb9..3174c3c7cf40 100644 --- a/sys/cam/ctl/ctl_util.c +++ b/sys/cam/ctl/ctl_util.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003 Silicon Graphics International Corp. * All rights reserved. @@ -37,9 +37,6 @@ * Author: Ken Merry <ken@FreeBSD.org> */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #ifdef _KERNEL #include <sys/param.h> #include <sys/systm.h> @@ -59,6 +56,7 @@ __FBSDID("$FreeBSD$"); #include <sys/callout.h> #include <cam/scsi/scsi_all.h> #include <cam/ctl/ctl_io.h> +#include <cam/ctl/ctl_nvme_all.h> #include <cam/ctl/ctl_scsi_all.h> #include <cam/ctl/ctl_util.h> @@ -734,13 +732,13 @@ ctl_io_sbuf(union ctl_io *io, struct sbuf *sb) const char *task_desc; char path_str[64]; - ctl_scsi_path_string(io, path_str, sizeof(path_str)); + ctl_scsi_path_string(&io->io_hdr, path_str, sizeof(path_str)); switch (io->io_hdr.io_type) { case CTL_IO_SCSI: sbuf_cat(sb, path_str); ctl_scsi_command_string(&io->scsiio, NULL, sb); - sbuf_printf(sb, " Tag: %#x/%d, Prio: %d\n", + sbuf_printf(sb, " Tag: %#jx/%d, Prio: %d\n", io->scsiio.tag_num, io->scsiio.tag_type, io->scsiio.priority); break; @@ -754,14 +752,20 @@ ctl_io_sbuf(union ctl_io *io, struct sbuf *sb) sbuf_printf(sb, "Task Action: %s", task_desc); switch (io->taskio.task_action) { case CTL_TASK_ABORT_TASK: - sbuf_printf(sb, " Tag: %#x/%d\n", + sbuf_printf(sb, " Tag: %#jx/%d\n", io->taskio.tag_num, io->taskio.tag_type); break; default: - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); break; } break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + sbuf_cat(sb, path_str); + ctl_nvme_command_string(&io->nvmeio, sb); + sbuf_printf(sb, " CID: 0x%x\n", le16toh(io->nvmeio.cmd.cid)); + break; default: break; } @@ -787,7 +791,7 @@ ctl_io_error_sbuf(union ctl_io *io, struct scsi_inquiry_data *inq_data, } } - ctl_scsi_path_string(io, path_str, sizeof(path_str)); + ctl_scsi_path_string(&io->io_hdr, path_str, sizeof(path_str)); sbuf_cat(sb, path_str); if (status_desc == NULL) @@ -796,15 +800,29 @@ ctl_io_error_sbuf(union ctl_io *io, struct scsi_inquiry_data *inq_data, else sbuf_printf(sb, "CTL Status: %s\n", status_desc->description); - if ((io->io_hdr.io_type == CTL_IO_SCSI) - && ((io->io_hdr.status & CTL_STATUS_MASK) == CTL_SCSI_ERROR)) { - sbuf_cat(sb, path_str); - sbuf_printf(sb, "SCSI Status: %s\n", + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + if ((io->io_hdr.status & CTL_STATUS_MASK) == CTL_SCSI_ERROR) { + sbuf_cat(sb, path_str); + sbuf_printf(sb, "SCSI Status: %s\n", ctl_scsi_status_string(&io->scsiio)); - if (io->scsiio.scsi_status == SCSI_STATUS_CHECK_COND) - ctl_scsi_sense_sbuf(&io->scsiio, inq_data, - sb, SSS_FLAG_NONE); + if (io->scsiio.scsi_status == SCSI_STATUS_CHECK_COND) + ctl_scsi_sense_sbuf(&io->scsiio, inq_data, + sb, SSS_FLAG_NONE); + } + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + if ((io->io_hdr.status & CTL_STATUS_MASK) == CTL_NVME_ERROR) { + sbuf_cat(sb, path_str); + sbuf_printf(sb, "NVMe Status: "); + ctl_nvme_status_string(&io->nvmeio, sb); + sbuf_printf(sb, "\n"); + } + break; + default: + break; } } @@ -856,24 +874,34 @@ ctl_data_print(union ctl_io *io) char str[128]; char path_str[64]; struct sbuf sb; + uintmax_t tag_num; int i, j, len; - if (io->io_hdr.io_type != CTL_IO_SCSI) + switch (io->io_hdr.io_type) { + case CTL_IO_SCSI: + tag_num = io->scsiio.tag_num; + break; + case CTL_IO_NVME: + case CTL_IO_NVME_ADMIN: + tag_num = le16toh(io->nvmeio.cmd.cid); + break; + default: return; + } if (io->io_hdr.flags & CTL_FLAG_BUS_ADDR) return; - if (io->scsiio.kern_sg_entries > 0) /* XXX: Implement */ + if (ctl_kern_sg_entries(io) > 0) /* XXX: Implement */ return; - ctl_scsi_path_string(io, path_str, sizeof(path_str)); - len = min(io->scsiio.kern_data_len, 4096); + ctl_scsi_path_string(&io->io_hdr, path_str, sizeof(path_str)); + len = min(ctl_kern_data_len(io), 4096); for (i = 0; i < len; ) { sbuf_new(&sb, str, sizeof(str), SBUF_FIXEDLEN); sbuf_cat(&sb, path_str); - sbuf_printf(&sb, " %#6x:%04x:", io->scsiio.tag_num, i); + sbuf_printf(&sb, " %#jx:%04x:", tag_num, i); for (j = 0; j < 16 && i < len; i++, j++) { if (j == 8) sbuf_cat(&sb, " "); - sbuf_printf(&sb, " %02x", io->scsiio.kern_data_ptr[i]); + sbuf_printf(&sb, " %02x", ctl_kern_data_ptr(io)[i]); } sbuf_cat(&sb, "\n"); sbuf_finish(&sb); diff --git a/sys/cam/ctl/ctl_util.h b/sys/cam/ctl/ctl_util.h index ab5cf8a8f48f..9f4e1439dfa8 100644 --- a/sys/cam/ctl/ctl_util.h +++ b/sys/cam/ctl/ctl_util.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2003 Silicon Graphics International Corp. * All rights reserved. @@ -30,7 +30,6 @@ * POSSIBILITY OF SUCH DAMAGES. * * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_util.h#2 $ - * $FreeBSD$ */ /* * CAM Target Layer SCSI library interface diff --git a/sys/cam/ctl/scsi_ctl.c b/sys/cam/ctl/scsi_ctl.c index 8c141a88e155..68f1cabf6d07 100644 --- a/sys/cam/ctl/scsi_ctl.c +++ b/sys/cam/ctl/scsi_ctl.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2008, 2009 Silicon Graphics International Corp. * Copyright (c) 2014-2015 Alexander Motin <mav@FreeBSD.org> @@ -38,9 +38,6 @@ * Author: Ken Merry <ken@FreeBSD.org> */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/queue.h> #include <sys/systm.h> @@ -669,7 +666,7 @@ ctlfecleanup(struct cam_periph *periph) static void ctlfedata(struct ctlfe_lun_softc *softc, union ctl_io *io, ccb_flags *flags, uint8_t **data_ptr, uint32_t *dxfer_len, - u_int16_t *sglist_cnt) + uint16_t *sglist_cnt) { struct ctlfe_softc *bus_softc; struct ctlfe_cmd_info *cmd_info; @@ -1185,7 +1182,7 @@ ctlfedone(struct cam_periph *periph, union ccb *done_ccb) bcopy(atio_cdb_ptr(atio), io->scsiio.cdb, io->scsiio.cdb_len); #ifdef CTLFEDEBUG - printf("%s: %u:%u:%u: tag %04x CDB %02x\n", __func__, + printf("%s: %u:%u:%u: tag %jx CDB %02x\n", __func__, io->io_hdr.nexus.initid, io->io_hdr.nexus.targ_port, io->io_hdr.nexus.targ_lun, @@ -1911,8 +1908,7 @@ ctlfe_datamove(union ctl_io *io) struct cam_periph *periph; struct ctlfe_lun_softc *softc; - KASSERT(io->io_hdr.io_type == CTL_IO_SCSI, - ("%s: unexpected I/O type %x", __func__, io->io_hdr.io_type)); + CTL_IO_ASSERT(io, SCSI); io->scsiio.ext_data_filled = 0; ccb = PRIV_CCB(io); diff --git a/sys/cam/mmc/mmc.h b/sys/cam/mmc/mmc.h index 44c4aad05e33..9c2d17d67867 100644 --- a/sys/cam/mmc/mmc.h +++ b/sys/cam/mmc/mmc.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2014-2016 Ilya Bakulin. All rights reserved. * @@ -52,8 +52,6 @@ * * Inspired coded in sys/dev/mmc. Thanks to Warner Losh <imp@FreeBSD.org>, * Bernd Walter <tisco@FreeBSD.org>, and other authors. - * - * $FreeBSD$ */ #ifndef CAM_MMC_H @@ -64,7 +62,7 @@ * This structure describes an MMC/SD card */ struct mmc_params { - u_int8_t model[40]; /* Card model */ + uint8_t model[40]; /* Card model */ /* Card OCR */ uint32_t card_ocr; diff --git a/sys/cam/mmc/mmc_all.h b/sys/cam/mmc/mmc_all.h index cb8c1bc7ae2b..4f2cd1b68586 100644 --- a/sys/cam/mmc/mmc_all.h +++ b/sys/cam/mmc/mmc_all.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2014-2016 Ilya Bakulin. All rights reserved. * @@ -49,8 +49,6 @@ * herein shall be construed as an obligation by the SD Group, the SD-3C LLC * or the SD Card Association to disclose or distribute any technical * information, know-how or other confidential information to any third party. - * - * $FreeBSD$ */ /* diff --git a/sys/cam/mmc/mmc_bus.h b/sys/cam/mmc/mmc_bus.h index db77da510788..8567c47c81ed 100644 --- a/sys/cam/mmc/mmc_bus.h +++ b/sys/cam/mmc/mmc_bus.h @@ -1,5 +1,4 @@ /* * This file is in the public domain. - * $FreeBSD$ */ #include <dev/mmc/bridge.h> diff --git a/sys/cam/mmc/mmc_da.c b/sys/cam/mmc/mmc_da.c index d352f2d91415..597ba0efb47e 100644 --- a/sys/cam/mmc/mmc_da.c +++ b/sys/cam/mmc/mmc_da.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2006 Bernd Walter <tisco@FreeBSD.org> All rights reserved. * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org> All rights reserved. @@ -32,9 +32,6 @@ * Bernd Walter <tisco@FreeBSD.org>, and other authors. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - //#include "opt_sdda.h" #include <sys/param.h> @@ -166,7 +163,7 @@ static const char *mmc_errmsg[] = static disk_strategy_t sddastrategy; static dumper_t sddadump; static periph_init_t sddainit; -static void sddaasync(void *callback_arg, u_int32_t code, +static void sddaasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg); static periph_ctor_t sddaregister; static periph_dtor_t sddacleanup; @@ -174,8 +171,8 @@ static periph_start_t sddastart; static periph_oninv_t sddaoninvalidate; static void sddadone(struct cam_periph *periph, union ccb *done_ccb); -static int sddaerror(union ccb *ccb, u_int32_t cam_flags, - u_int32_t sense_flags); +static int sddaerror(union ccb *ccb, uint32_t cam_flags, + uint32_t sense_flags); static int mmc_handle_reply(union ccb *ccb); static uint16_t get_rca(struct cam_periph *periph); @@ -646,7 +643,7 @@ sddacleanup(struct cam_periph *periph) } static void -sddaasync(void *callback_arg, u_int32_t code, +sddaasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg) { struct ccb_getdev cgd; @@ -1285,12 +1282,12 @@ sdda_start_init(void *context, union ccb *start_ccb) /* Update info for CAM */ device->serial_num_len = strlen(softc->card_sn_string); - device->serial_num = (u_int8_t *)malloc((device->serial_num_len + 1), + device->serial_num = (uint8_t *)malloc((device->serial_num_len + 1), M_CAMXPT, M_NOWAIT); strlcpy(device->serial_num, softc->card_sn_string, device->serial_num_len + 1); device->device_id_len = strlen(softc->card_id_string); - device->device_id = (u_int8_t *)malloc((device->device_id_len + 1), + device->device_id = (uint8_t *)malloc((device->device_id_len + 1), M_CAMXPT, M_NOWAIT); strlcpy(device->device_id, softc->card_id_string, device->device_id_len + 1); @@ -2000,7 +1997,7 @@ sddadone(struct cam_periph *periph, union ccb *done_ccb) } static int -sddaerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags) +sddaerror(union ccb *ccb, uint32_t cam_flags, uint32_t sense_flags) { return(cam_periph_error(ccb, cam_flags, sense_flags)); } diff --git a/sys/cam/mmc/mmc_sim.c b/sys/cam/mmc/mmc_sim.c index 40330958574b..104916a41782 100644 --- a/sys/cam/mmc/mmc_sim.c +++ b/sys/cam/mmc/mmc_sim.c @@ -21,13 +21,8 @@ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/kernel.h> #include <sys/systm.h> diff --git a/sys/cam/mmc/mmc_sim.h b/sys/cam/mmc/mmc_sim.h index 18c49b3f57e8..fa45ad283bb1 100644 --- a/sys/cam/mmc/mmc_sim.h +++ b/sys/cam/mmc/mmc_sim.h @@ -21,8 +21,6 @@ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef __MMC_SIM_H__ diff --git a/sys/cam/mmc/mmc_sim_if.m b/sys/cam/mmc/mmc_sim_if.m index f7d3f4df5ebb..6640d5587a9a 100644 --- a/sys/cam/mmc/mmc_sim_if.m +++ b/sys/cam/mmc/mmc_sim_if.m @@ -1,5 +1,5 @@ #- -# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# SPDX-License-Identifier: BSD-2-Clause # # Copyright (c) 2020 Emmanuel Vadot <manu@FreeBSD.org> # @@ -24,7 +24,6 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# $FreeBSD$ #include <sys/types.h> #include <sys/callout.h> diff --git a/sys/cam/mmc/mmc_xpt.c b/sys/cam/mmc/mmc_xpt.c index 6a3ba02acecb..0947e0addf59 100644 --- a/sys/cam/mmc/mmc_xpt.c +++ b/sys/cam/mmc/mmc_xpt.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2013,2014 Ilya Bakulin <ilya@bakulin.de> * All rights reserved. @@ -26,9 +26,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/bus.h> #include <sys/endian.h> @@ -63,17 +60,17 @@ __FBSDID("$FreeBSD$"); #include <machine/stdarg.h> /* for xpt_print below */ #include <machine/_inttypes.h> /* for PRIu64 */ -#include "opt_cam.h" FEATURE(mmccam, "CAM-based MMC/SD/SDIO stack"); static struct cam_ed * mmc_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id); -static void mmc_dev_async(u_int32_t async_code, struct cam_eb *bus, +static void mmc_dev_async(uint32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, void *async_arg); static void mmc_action(union ccb *start_ccb); static void mmc_dev_advinfo(union ccb *start_ccb); -static void mmc_announce_periph(struct cam_periph *periph); +static void mmc_announce_periph_sbuf(struct cam_periph *periph, + struct sbuf *sb); static void mmc_scan_lun(struct cam_periph *periph, struct cam_path *path, cam_flags flags, union ccb *ccb); @@ -83,8 +80,8 @@ static void mmcprobe_start(struct cam_periph *periph, union ccb *start_ccb); static void mmcprobe_cleanup(struct cam_periph *periph); static void mmcprobe_done(struct cam_periph *periph, union ccb *done_ccb); -static void mmc_proto_announce(struct cam_ed *device); -static void mmc_proto_denounce(struct cam_ed *device); +static void mmc_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb); +static void mmc_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb); static void mmc_proto_debug_out(union ccb *ccb); typedef enum { @@ -147,7 +144,7 @@ static struct xpt_xport_ops mmc_xport_ops = { .alloc_device = mmc_alloc_device, .action = mmc_action, .async = mmc_dev_async, - .announce = mmc_announce_periph, + .announce_sbuf = mmc_announce_periph_sbuf, }; #define MMC_XPT_XPORT(x, X) \ @@ -161,8 +158,8 @@ static struct xpt_xport_ops mmc_xport_ops = { MMC_XPT_XPORT(mmc, MMCSD); static struct xpt_proto_ops mmc_proto_ops = { - .announce = mmc_proto_announce, - .denounce = mmc_proto_denounce, + .announce_sbuf = mmc_proto_announce_sbuf, + .denounce_sbuf = mmc_proto_denounce_sbuf, .debug_out = mmc_proto_debug_out, }; @@ -207,7 +204,7 @@ mmc_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id) } static void -mmc_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target, +mmc_dev_async(uint32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, void *async_arg) { @@ -377,7 +374,7 @@ mmc_dev_advinfo(union ccb *start_ccb) } static void -mmc_announce_periph(struct cam_periph *periph) +mmc_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb) { struct ccb_pathinq cpi; struct ccb_trans_settings cts; @@ -385,7 +382,7 @@ mmc_announce_periph(struct cam_periph *periph) cam_periph_assert(periph, MA_OWNED); - CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("mmc_announce_periph")); + CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("mmc_announce_periph_sbuf")); memset(&cts, 0, sizeof(cts)); xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL); @@ -431,9 +428,9 @@ mmc_print_ident(struct mmc_params *ident_data, struct sbuf *sb) bool space = false; sbuf_printf(sb, "Relative addr: %08x\n", ident_data->card_rca); - sbuf_printf(sb, "Card features: <"); + sbuf_cat(sb, "Card features: <"); if (ident_data->card_features & CARD_FEATURE_MMC) { - sbuf_printf(sb, "MMC"); + sbuf_cat(sb, "MMC"); space = true; } if (ident_data->card_features & CARD_FEATURE_MEMORY) { @@ -455,7 +452,7 @@ mmc_print_ident(struct mmc_params *ident_data, struct sbuf *sb) if (ident_data->card_features & CARD_FEATURE_18V) { sbuf_printf(sb, "%s1.8-Signaling", space ? " " : ""); } - sbuf_printf(sb, ">\n"); + sbuf_cat(sb, ">\n"); if (ident_data->card_features & CARD_FEATURE_MEMORY) sbuf_printf(sb, "Card memory OCR: %08x\n", @@ -466,29 +463,18 @@ mmc_print_ident(struct mmc_params *ident_data, struct sbuf *sb) sbuf_printf(sb, "Number of functions: %u\n", ident_data->sdio_func_count); } - - sbuf_finish(sb); - printf("%s", sbuf_data(sb)); - sbuf_clear(sb); } static void -mmc_proto_announce(struct cam_ed *device) +mmc_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb) { - struct sbuf sb; - char buffer[256]; - - sbuf_new(&sb, buffer, sizeof(buffer), SBUF_FIXEDLEN); - mmc_print_ident(&device->mmc_ident_data, &sb); - sbuf_finish(&sb); - sbuf_putbuf(&sb); + mmc_print_ident(&device->mmc_ident_data, sb); } static void -mmc_proto_denounce(struct cam_ed *device) +mmc_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb) { - - mmc_proto_announce(device); + mmc_proto_announce_sbuf(device, sb); } static void @@ -822,7 +808,7 @@ mmcprobe_done(struct cam_periph *periph, union ccb *done_ccb) int err; struct ccb_mmcio *mmcio; - u_int32_t priority; + uint32_t priority; CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("mmcprobe_done\n")); softc = (mmcprobe_softc *)periph->softc; diff --git a/sys/cam/nvme/nvme_all.c b/sys/cam/nvme/nvme_all.c index 1eafdb1cece6..a3c3d676b349 100644 --- a/sys/cam/nvme/nvme_all.c +++ b/sys/cam/nvme/nvme_all.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2015 Netflix, Inc. * @@ -7,27 +7,24 @@ * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer, - * without modification, immediately at the beginning of the file. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #ifdef _KERNEL @@ -89,17 +86,24 @@ void nvme_print_ident(const struct nvme_controller_data *cdata, const struct nvme_namespace_data *data, struct sbuf *sb) { + nvme_print_ident_short(cdata, data, sb); + sbuf_putc(sb, '\n'); +} - sbuf_printf(sb, "<"); +void +nvme_print_ident_short(const struct nvme_controller_data *cdata, + const struct nvme_namespace_data *data, struct sbuf *sb) +{ + sbuf_putc(sb, '<'); cam_strvis_sbuf(sb, cdata->mn, sizeof(cdata->mn), CAM_STRVIS_FLAG_NONASCII_SPC); - sbuf_printf(sb, " "); + sbuf_putc(sb, ' '); cam_strvis_sbuf(sb, cdata->fr, sizeof(cdata->fr), CAM_STRVIS_FLAG_NONASCII_SPC); - sbuf_printf(sb, " "); + sbuf_putc(sb, ' '); cam_strvis_sbuf(sb, cdata->sn, sizeof(cdata->sn), CAM_STRVIS_FLAG_NONASCII_SPC); - sbuf_printf(sb, ">\n"); + sbuf_putc(sb, '>'); } /* XXX need to do nvme admin opcodes too, but those aren't used yet by nda */ diff --git a/sys/cam/nvme/nvme_all.h b/sys/cam/nvme/nvme_all.h index da40dea1c7f1..2b6732fe7c74 100644 --- a/sys/cam/nvme/nvme_all.h +++ b/sys/cam/nvme/nvme_all.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2015 Netflix, Inc. * @@ -7,24 +7,22 @@ * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer, - * without modification, immediately at the beginning of the file. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ #ifndef CAM_NVME_NVME_ALL_H @@ -42,6 +40,8 @@ int nvme_identify_match(caddr_t identbuffer, caddr_t table_entry); struct sbuf; void nvme_print_ident(const struct nvme_controller_data *, const struct nvme_namespace_data *, struct sbuf *); +void nvme_print_ident_short(const struct nvme_controller_data *, + const struct nvme_namespace_data *, struct sbuf *); const char *nvme_op_string(const struct nvme_command *, int admin); const char *nvme_cmd_string(const struct nvme_command *, char *, size_t); void nvme_cmd_sbuf(const struct nvme_command *, struct sbuf *sb); diff --git a/sys/cam/nvme/nvme_da.c b/sys/cam/nvme/nvme_da.c index 1175a0e99b3c..41c552e2780a 100644 --- a/sys/cam/nvme/nvme_da.c +++ b/sys/cam/nvme/nvme_da.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2015 Netflix, Inc. * @@ -7,30 +7,27 @@ * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer, - * without modification, immediately at the beginning of the file. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. * * Derived from ata_da.c: * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org> */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #ifdef _KERNEL @@ -149,7 +146,7 @@ static disk_ioctl_t ndaioctl; static disk_strategy_t ndastrategy; static dumper_t ndadump; static periph_init_t ndainit; -static void ndaasync(void *callback_arg, u_int32_t code, +static void ndaasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg); static void ndasysctlinit(void *context, int pending); static int ndaflagssysctl(SYSCTL_HANDLER_ARGS); @@ -159,8 +156,8 @@ static periph_start_t ndastart; static periph_oninv_t ndaoninvalidate; static void ndadone(struct cam_periph *periph, union ccb *done_ccb); -static int ndaerror(union ccb *ccb, u_int32_t cam_flags, - u_int32_t sense_flags); +static int ndaerror(union ccb *ccb, uint32_t cam_flags, + uint32_t sense_flags); static void ndashutdown(void *arg, int howto); static void ndasuspend(void *arg); @@ -440,8 +437,9 @@ ndaioctl(struct disk *dp, u_long cmd, void *data, int fflag, * Tear down mapping and return status. */ cam_periph_unlock(periph); - cam_periph_unmapmem(ccb, &mapinfo); - error = (ccb->ccb_h.status == CAM_REQ_CMP) ? 0 : EIO; + error = cam_periph_unmapmem(ccb, &mapinfo); + if (!cam_ccb_success(ccb)) + error = EIO; out: cam_periph_lock(periph); xpt_release_ccb(ccb); @@ -646,7 +644,7 @@ ndacleanup(struct cam_periph *periph) } static void -ndaasync(void *callback_arg, u_int32_t code, +ndaasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg) { struct cam_periph *periph; @@ -813,7 +811,7 @@ ndaflagssysctl(SYSCTL_HANDLER_ARGS) if (softc->flags != 0) sbuf_printf(&sbuf, "0x%b", (unsigned)softc->flags, NDA_FLAG_STRING); else - sbuf_printf(&sbuf, "0"); + sbuf_putc(&sbuf, '0'); error = sbuf_finish(&sbuf); sbuf_delete(&sbuf); @@ -886,7 +884,7 @@ ndaregister(struct cam_periph *periph, void *arg) /* * Register this media as a disk */ - (void)cam_periph_hold(periph, PRIBIO); + (void)cam_periph_acquire(periph); cam_periph_unlock(periph); snprintf(announce_buf, sizeof(announce_buf), "kern.cam.nda.%d.quirks", periph->unit_number); @@ -913,18 +911,15 @@ ndaregister(struct cam_periph *periph, void *arg) else if (maxio > maxphys) maxio = maxphys; /* for safety */ disk->d_maxsize = maxio; - flbas_fmt = (nsd->flbas >> NVME_NS_DATA_FLBAS_FORMAT_SHIFT) & - NVME_NS_DATA_FLBAS_FORMAT_MASK; - lbads = (nsd->lbaf[flbas_fmt] >> NVME_NS_DATA_LBAF_LBADS_SHIFT) & - NVME_NS_DATA_LBAF_LBADS_MASK; + flbas_fmt = NVMEV(NVME_NS_DATA_FLBAS_FORMAT, nsd->flbas); + lbads = NVMEV(NVME_NS_DATA_LBAF_LBADS, nsd->lbaf[flbas_fmt]); disk->d_sectorsize = 1 << lbads; disk->d_mediasize = (off_t)(disk->d_sectorsize * nsd->nsze); disk->d_delmaxsize = disk->d_mediasize; disk->d_flags = DISKFLAG_DIRECT_COMPLETION; if (nvme_ctrlr_has_dataset_mgmt(cd)) disk->d_flags |= DISKFLAG_CANDELETE; - vwc_present = (cd->vwc >> NVME_CTRLR_DATA_VWC_PRESENT_SHIFT) & - NVME_CTRLR_DATA_VWC_PRESENT_MASK; + vwc_present = NVMEV(NVME_CTRLR_DATA_VWC_PRESENT, cd->vwc); if (vwc_present) disk->d_flags |= DISKFLAG_CANFLUSHCACHE; if ((cpi.hba_misc & PIM_UNMAPPED) != 0) { @@ -947,8 +942,8 @@ ndaregister(struct cam_periph *periph, void *arg) disk->d_hba_subdevice = cpi.hba_subdevice; snprintf(disk->d_attachment, sizeof(disk->d_attachment), "%s%d", cpi.dev_name, cpi.unit_number); - if (((nsd->nsfeat >> NVME_NS_DATA_NSFEAT_NPVALID_SHIFT) & - NVME_NS_DATA_NSFEAT_NPVALID_MASK) != 0 && nsd->npwg != 0) + if (NVMEV(NVME_NS_DATA_NSFEAT_NPVALID, nsd->nsfeat) != 0 && + nsd->npwg != 0) disk->d_stripesize = ((nsd->npwg + 1) * disk->d_sectorsize); else disk->d_stripesize = nsd->noiob * disk->d_sectorsize; @@ -964,20 +959,7 @@ ndaregister(struct cam_periph *periph, void *arg) if (nda_nvd_compat) disk_add_alias(disk, "nvd"); - /* - * Acquire a reference to the periph before we register with GEOM. - * We'll release this reference once GEOM calls us back (via - * ndadiskgonecb()) telling us that our provider has been freed. - */ - if (cam_periph_acquire(periph) != 0) { - xpt_print(periph->path, "%s: lost periph during " - "registration!\n", __func__); - cam_periph_lock(periph); - return (CAM_REQ_CMP_ERR); - } - disk_create(softc->disk, DISK_VERSION); cam_periph_lock(periph); - cam_periph_unhold(periph); snprintf(announce_buf, sizeof(announce_buf), "%juMB (%ju %u byte sectors)", @@ -1002,6 +984,15 @@ ndaregister(struct cam_periph *periph, void *arg) ndaasync, periph, periph->path); softc->state = NDA_STATE_NORMAL; + + /* + * We'll release this reference once GEOM calls us back via + * ndadiskgonecb(), telling us that our provider has been freed. + */ + if (cam_periph_acquire(periph) == 0) + disk_create(softc->disk, DISK_VERSION); + + cam_periph_release_locked(periph); return(CAM_REQ_CMP); } @@ -1086,7 +1077,17 @@ ndastart(struct cam_periph *periph, union ccb *start_ccb) trim = malloc(sizeof(*trim), M_NVMEDA, M_ZERO | M_NOWAIT); if (trim == NULL) { + /* + * We have to drop the periph lock when + * returning ENOMEM. g_io_deliver treats these + * request differently and will recursively call + * the start routine which causes us to get into + * ndastrategy with the periph lock held, + * leading to a panic when its acquired again. + */ + cam_periph_unlock(periph); biofinish(bp, NULL, ENOMEM); + cam_periph_lock(periph); xpt_release_ccb(start_ccb); ndaschedule(periph); return; @@ -1272,7 +1273,7 @@ ndadone(struct cam_periph *periph, union ccb *done_ccb) } static int -ndaerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags) +ndaerror(union ccb *ccb, uint32_t cam_flags, uint32_t sense_flags) { #ifdef CAM_IO_STATS struct nda_softc *softc; @@ -1288,12 +1289,8 @@ ndaerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags) softc->timeouts++; #endif break; - case CAM_REQ_ABORTED: case CAM_REQ_CMP_ERR: - case CAM_REQ_TERMIO: - case CAM_UNREC_HBA_ERROR: - case CAM_DATA_RUN_ERR: - case CAM_ATA_STATUS_ERROR: + case CAM_NVME_STATUS_ERROR: #ifdef CAM_IO_STATS softc->errors++; #endif diff --git a/sys/cam/nvme/nvme_xpt.c b/sys/cam/nvme/nvme_xpt.c index 88aa1197cc6c..d2cb6ff11fd4 100644 --- a/sys/cam/nvme/nvme_xpt.c +++ b/sys/cam/nvme/nvme_xpt.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2015 Netflix, Inc. * @@ -7,29 +7,26 @@ * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer, - * without modification, immediately at the beginning of the file. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. * * derived from ata_xpt.c: Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org> */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/bus.h> #include <sys/endian.h> @@ -61,7 +58,6 @@ __FBSDID("$FreeBSD$"); #include <cam/scsi/scsi_message.h> #include <cam/nvme/nvme_all.h> #include <machine/stdarg.h> /* for xpt_print below */ -#include "opt_cam.h" struct nvme_quirk_entry { u_int quirks; @@ -150,22 +146,25 @@ static struct cam_ed * nvme_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id); static void nvme_device_transport(struct cam_path *path); -static void nvme_dev_async(u_int32_t async_code, +static void nvme_dev_async(uint32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, void *async_arg); static void nvme_action(union ccb *start_ccb); -static void nvme_announce_periph(struct cam_periph *periph); -static void nvme_proto_announce(struct cam_ed *device); -static void nvme_proto_denounce(struct cam_ed *device); +static void nvme_announce_periph_sbuf(struct cam_periph *periph, + struct sbuf *sb); +static void nvme_proto_announce_sbuf(struct cam_ed *device, + struct sbuf *sb); +static void nvme_proto_denounce_sbuf(struct cam_ed *device, + struct sbuf *sb); static void nvme_proto_debug_out(union ccb *ccb); static struct xpt_xport_ops nvme_xport_ops = { .alloc_device = nvme_alloc_device, .action = nvme_action, .async = nvme_dev_async, - .announce = nvme_announce_periph, + .announce_sbuf = nvme_announce_periph_sbuf, }; #define NVME_XPT_XPORT(x, X) \ static struct xpt_xport nvme_xport_ ## x = { \ @@ -176,12 +175,13 @@ static struct xpt_xport nvme_xport_ ## x = { \ CAM_XPT_XPORT(nvme_xport_ ## x); NVME_XPT_XPORT(nvme, NVME); +NVME_XPT_XPORT(nvmf, NVMF); #undef NVME_XPT_XPORT static struct xpt_proto_ops nvme_proto_ops = { - .announce = nvme_proto_announce, - .denounce = nvme_proto_denounce, + .announce_sbuf = nvme_proto_announce_sbuf, + .denounce_sbuf = nvme_proto_denounce_sbuf, .debug_out = nvme_proto_debug_out, }; static struct xpt_proto nvme_proto = { @@ -310,7 +310,7 @@ nvme_probe_done(struct cam_periph *periph, union ccb *done_ccb) struct cam_path *path; struct scsi_vpd_device_id *did; struct scsi_vpd_id_descriptor *idd; - u_int32_t priority; + uint32_t priority; int found = 1, e, g, len; CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("nvme_probe_done\n")); @@ -373,7 +373,7 @@ device_fail: if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0) path->device->serial_num = NULL; path->device->serial_num_len = 0; } - path->device->serial_num = (u_int8_t *) + path->device->serial_num = (uint8_t *) malloc(NVME_SERIAL_NUMBER_LENGTH + 1, M_CAMXPT, M_NOWAIT); if (path->device->serial_num != NULL) { cam_strvis_flag(path->device->serial_num, @@ -430,7 +430,7 @@ device_fail: if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0) if (e < sizeof(nvme_data->eui64)) len += sizeof(struct scsi_vpd_id_descriptor) + 8; if (len > 0) { - path->device->device_id = (u_int8_t *) + path->device->device_id = (uint8_t *) malloc(SVPD_DEVICE_ID_HDR_LEN + len, M_CAMXPT, M_NOWAIT); } @@ -764,7 +764,7 @@ nvme_action(union ccb *start_ccb) * Handle any per-device event notifications that require action by the XPT. */ static void -nvme_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target, +nvme_dev_async(uint32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, void *async_arg) { @@ -783,14 +783,12 @@ nvme_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target, } static void -nvme_announce_periph(struct cam_periph *periph) +nvme_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb) { struct ccb_pathinq cpi; struct ccb_trans_settings cts; struct cam_path *path = periph->path; struct ccb_trans_settings_nvme *nvmex; - struct sbuf sb; - char buffer[120]; cam_periph_assert(periph, MA_OWNED); @@ -802,41 +800,34 @@ nvme_announce_periph(struct cam_periph *periph) xpt_action((union ccb*)&cts); if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) return; - nvmex = &cts.xport_specific.nvme; /* Ask the SIM for its base transfer speed */ xpt_path_inq(&cpi, periph->path); - sbuf_new(&sb, buffer, sizeof(buffer), SBUF_FIXEDLEN); - sbuf_printf(&sb, "%s%d: nvme version %d.%d", + sbuf_printf(sb, "%s%d: nvme version %d.%d", periph->periph_name, periph->unit_number, - NVME_MAJOR(nvmex->spec), - NVME_MINOR(nvmex->spec)); - if (nvmex->valid & CTS_NVME_VALID_LINK) - sbuf_printf(&sb, " x%d (max x%d) lanes PCIe Gen%d (max Gen%d) link", - nvmex->lanes, nvmex->max_lanes, - nvmex->speed, nvmex->max_speed); - sbuf_printf(&sb, "\n"); - sbuf_finish(&sb); - sbuf_putbuf(&sb); + NVME_MAJOR(cts.protocol_version), + NVME_MINOR(cts.protocol_version)); + if (cts.transport == XPORT_NVME) { + nvmex = &cts.proto_specific.nvme; + if (nvmex->valid & CTS_NVME_VALID_LINK) + sbuf_printf(sb, + " x%d (max x%d) lanes PCIe Gen%d (max Gen%d) link", + nvmex->lanes, nvmex->max_lanes, + nvmex->speed, nvmex->max_speed); + } + sbuf_putc(sb, '\n'); } static void -nvme_proto_announce(struct cam_ed *device) +nvme_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb) { - struct sbuf sb; - char buffer[120]; - - sbuf_new(&sb, buffer, sizeof(buffer), SBUF_FIXEDLEN); - nvme_print_ident(device->nvme_cdata, device->nvme_data, &sb); - sbuf_finish(&sb); - sbuf_putbuf(&sb); + nvme_print_ident(device->nvme_cdata, device->nvme_data, sb); } static void -nvme_proto_denounce(struct cam_ed *device) +nvme_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb) { - - nvme_proto_announce(device); + nvme_print_ident_short(device->nvme_cdata, device->nvme_data, sb); } static void diff --git a/sys/cam/scsi/scsi_all.c b/sys/cam/scsi/scsi_all.c index ff917c827f6b..07295f313cca 100644 --- a/sys/cam/scsi/scsi_all.c +++ b/sys/cam/scsi/scsi_all.c @@ -1,7 +1,7 @@ /*- * Implementation of Utility functions for all SCSI device types. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs. * Copyright (c) 1997, 1998, 2003 Kenneth D. Merry. @@ -29,9 +29,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/types.h> #include <sys/stdint.h> @@ -625,12 +622,12 @@ static struct op_table_entry scsi_op_codes[] = { }; const char * -scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data) +scsi_op_desc(uint16_t opcode, struct scsi_inquiry_data *inq_data) { caddr_t match; int i, j; - u_int32_t opmask; - u_int16_t pd_type; + uint32_t opmask; + uint16_t pd_type; int num_ops[2]; struct op_table_entry *table[2]; int num_tables; @@ -660,7 +657,7 @@ scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data) num_ops[1] = nitems(scsi_op_codes); num_tables = 2; } else { - /* + /* * If this is true, we have a vendor specific opcode that * wasn't covered in the quirk table. */ @@ -690,7 +687,7 @@ scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data) for (j = 0; j < num_tables; j++) { for (i = 0;i < num_ops[j] && table[j][i].opcode <= opcode; i++){ - if ((table[j][i].opcode == opcode) + if ((table[j][i].opcode == opcode) && ((table[j][i].opmask & opmask) != 0)) return(table[j][i].desc); } @@ -707,7 +704,7 @@ scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data) #else /* SCSI_NO_OP_STRINGS */ const char * -scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data) +scsi_op_desc(uint16_t opcode, struct scsi_inquiry_data *inq_data) { return(""); } @@ -717,14 +714,14 @@ scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data) #if !defined(SCSI_NO_SENSE_STRINGS) #define SST(asc, ascq, action, desc) \ asc, ascq, action, desc -#else +#else const char empty_string[] = ""; #define SST(asc, ascq, action, desc) \ asc, ascq, action, empty_string -#endif +#endif -const struct sense_key_table_entry sense_key_table[] = +const struct sense_key_table_entry sense_key_table[] = { { SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" }, { SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" }, @@ -745,7 +742,7 @@ const struct sense_key_table_entry sense_key_table[] = }; static struct asc_table_entry quantum_fireball_entries[] = { - { SST(0x04, 0x0b, SS_START | SSQ_DECREMENT_COUNT | ENXIO, + { SST(0x04, 0x0b, SS_START | SSQ_DECREMENT_COUNT | ENXIO, "Logical unit not ready, initializing cmd. required") } }; @@ -977,7 +974,7 @@ static struct asc_table_entry asc_table[] = { * * SCSI ASC/ASCQ Assignments * Numeric Sorted Listing - * as of 8/12/15 + * as of Sat Mar 25 2023 at 04:30 (using old columns) * * D - DIRECT ACCESS DEVICE (SBC-2) device column key * .T - SEQUENTIAL ACCESS DEVICE (SSC) ------------------- @@ -1072,11 +1069,17 @@ static struct asc_table_entry asc_table[] = { /* D */ { SST(0x00, 0x21, SS_RDEF, /* XXX TBD */ "Atomic command aborted due to ACA") }, + /* D */ + { SST(0x00, 0x22, SS_RDEF, /* XXX TBD */ + "Deferred microcode is pending") }, + /* D */ + { SST(0x00, 0x23, SS_RDEF, /* XXX TBD */ + "Overlapping atomic command in progress") }, /* D W O BK */ { SST(0x01, 0x00, SS_RDEF, "No index/sector signal") }, /* D WRO BK */ - { SST(0x02, 0x00, SS_RDEF, + { SST(0x02, 0x00, SS_FATAL | EIO, "No seek complete") }, /* DTL W O BK */ { SST(0x03, 0x00, SS_RDEF, @@ -1273,30 +1276,39 @@ static struct asc_table_entry asc_table[] = { /* D */ { SST(0x0B, 0x09, SS_NOP | SSQ_PRINT_SENSE, "Warning - device statistics notification available") }, - /* DTLPWROMAEBKVF */ + /* DTLPWROMAEBKV */ { SST(0x0B, 0x0A, SS_NOP | SSQ_PRINT_SENSE, "Warning - High critical temperature limit exceeded") }, - /* DTLPWROMAEBKVF */ + /* DTLPWROMAEBKV */ { SST(0x0B, 0x0B, SS_NOP | SSQ_PRINT_SENSE, "Warning - Low critical temperature limit exceeded") }, - /* DTLPWROMAEBKVF */ + /* DTLPWROMAEBKV */ { SST(0x0B, 0x0C, SS_NOP | SSQ_PRINT_SENSE, "Warning - High operating temperature limit exceeded") }, - /* DTLPWROMAEBKVF */ + /* DTLPWROMAEBKV */ { SST(0x0B, 0x0D, SS_NOP | SSQ_PRINT_SENSE, "Warning - Low operating temperature limit exceeded") }, - /* DTLPWROMAEBKVF */ + /* DTLPWROMAEBKV */ { SST(0x0B, 0x0E, SS_NOP | SSQ_PRINT_SENSE, "Warning - High citical humidity limit exceeded") }, - /* DTLPWROMAEBKVF */ + /* DTLPWROMAEBKV */ { SST(0x0B, 0x0F, SS_NOP | SSQ_PRINT_SENSE, "Warning - Low citical humidity limit exceeded") }, - /* DTLPWROMAEBKVF */ + /* DTLPWROMAEBKV */ { SST(0x0B, 0x10, SS_NOP | SSQ_PRINT_SENSE, "Warning - High operating humidity limit exceeded") }, - /* DTLPWROMAEBKVF */ + /* DTLPWROMAEBKV */ { SST(0x0B, 0x11, SS_NOP | SSQ_PRINT_SENSE, "Warning - Low operating humidity limit exceeded") }, + /* DTLPWROMAEBKVF */ + { SST(0x0B, 0x12, SS_NOP | SSQ_PRINT_SENSE, + "Warning - Microcode security at risk") }, + /* DTLPWROMAEBKVF */ + { SST(0x0B, 0x13, SS_NOP | SSQ_PRINT_SENSE, + "Warning - Microcode digital signature validation failure") }, + /* D */ + { SST(0x0B, 0x14, SS_NOP | SSQ_PRINT_SENSE, + "Warning - Physical element status change") }, /* T R */ { SST(0x0C, 0x00, SS_RDEF, "Write error") }, @@ -1577,7 +1589,7 @@ static struct asc_table_entry asc_table[] = { { SST(0x18, 0x07, SS_NOP | SSQ_PRINT_SENSE, "Recovered data with ECC - data rewritten") }, /* R */ - { SST(0x18, 0x08, SS_RDEF, /* XXX TBD */ + { SST(0x18, 0x08, SS_NOP | SSQ_PRINT_SENSE, "Recovered data with linking") }, /* D O K */ { SST(0x19, 0x00, SS_RDEF, @@ -1657,6 +1669,15 @@ static struct asc_table_entry asc_table[] = { /* T */ { SST(0x20, 0x0C, SS_FATAL | EINVAL, "Illegal command when not in append-only mode") }, + /* D */ + { SST(0x20, 0x0D, SS_FATAL | EINVAL, + "Not an administrative logical unit") }, + /* D */ + { SST(0x20, 0x0E, SS_FATAL | EINVAL, + "Not a subsidiary logical unit") }, + /* D */ + { SST(0x20, 0x0F, SS_FATAL | EINVAL, + "Not a conglomerate logical unit") }, /* DT WRO BK */ { SST(0x21, 0x00, SS_FATAL | EINVAL, "Logical block address out of range") }, @@ -1682,6 +1703,12 @@ static struct asc_table_entry asc_table[] = { { SST(0x21, 0x07, SS_RDEF, /* XXX TBD */ "Read boundary violation") }, /* D */ + { SST(0x21, 0x08, SS_FATAL | EINVAL, + "Misaligned write command") }, + /* D */ + { SST(0x21, 0x09, SS_FATAL | EINVAL, + "Attempt to access gap zone") }, + /* D */ { SST(0x22, 0x00, SS_FATAL | EINVAL, "Illegal function (use 20 00, 24 00, or 26 00)") }, /* DT P B */ @@ -1744,6 +1771,9 @@ static struct asc_table_entry asc_table[] = { /* DT R MAEBKV */ { SST(0x24, 0x08, SS_RDEF, /* XXX TBD */ "Invalid XCDB") }, + /* D */ + { SST(0x24, 0x09, SS_FATAL | EINVAL, + "Invalid fast format") }, /* DTLPWROMAEBKVF */ { SST(0x25, 0x00, SS_FATAL | ENXIO | SSQ_LOST, "Logical unit not supported") }, @@ -1807,6 +1837,15 @@ static struct asc_table_entry asc_table[] = { /* D */ { SST(0x26, 0x13, SS_RDEF, /* XXX TBD */ "Application tag mode page is invalid") }, + /* T */ + { SST(0x26, 0x14, SS_RDEF, /* XXX TBD */ + "Tape stream mirroring prevented") }, + /* T */ + { SST(0x26, 0x15, SS_FATAL | EINVAL, + "Copy source or copy destination not authorized") }, + /* D */ + { SST(0x26, 0x16, SS_FATAL | EINVAL, + "Fast copy not possible") }, /* DT WRO BK */ { SST(0x27, 0x00, SS_FATAL | EACCES, "Write protected") }, @@ -1935,6 +1974,9 @@ static struct asc_table_entry asc_table[] = { /* T M V */ { SST(0x2A, 0x15, SS_RDEF, /* XXX TBD */ "Medium removal prevention preempted") }, + /* D */ + { SST(0x2A, 0x16, SS_RDEF, /* XXX TBD */ + "Zone reset write pointer recommended") }, /* DTLPWRO K */ { SST(0x2B, 0x00, SS_RDEF, "Copy cannot execute since host cannot disconnect") }, @@ -1989,6 +2031,15 @@ static struct asc_table_entry asc_table[] = { /* D */ { SST(0x2C, 0x10, SS_RDEF, /* XXX TBD */ "Unwritten data in zone") }, + /* D */ + { SST(0x2C, 0x11, SS_FATAL | EINVAL, + "Descriptor format sense data required") }, + /* D */ + { SST(0x2C, 0x12, SS_FATAL | EINVAL, + "Zone is inactive") }, + /* DTPEROMAEBKVF */ + { SST(0x2C, 0x13, SS_FATAL | EINVAL, + "Well known logical unit access required") }, /* T */ { SST(0x2D, 0x00, SS_RDEF, "Overwrite error on update in place") }, @@ -2136,6 +2187,9 @@ static struct asc_table_entry asc_table[] = { /* D */ { SST(0x38, 0x07, SS_RDEF, /* XXX TBD */ "Thin provisioning soft threshold reached") }, + /* D */ + { SST(0x38, 0x08, SS_NOP | SSQ_PRINT_SENSE, + "Depopulation interrupted") }, /* DTL WROMAE K */ { SST(0x39, 0x00, SS_RDEF, "Saving parameters not supported") }, @@ -2238,6 +2292,9 @@ static struct asc_table_entry asc_table[] = { /* T */ { SST(0x3B, 0x1C, SS_RDEF, /* XXX TBD */ "Too many logical objects on partition to support operation") }, + /* M */ + { SST(0x3B, 0x20, SS_RDEF, /* XXX TBD */ + "Element static information changed") }, /* DTLPWROMAE K */ { SST(0x3D, 0x00, SS_RDEF, "Invalid bits in IDENTIFY message") }, @@ -2329,6 +2386,14 @@ static struct asc_table_entry asc_table[] = { { SST(0x3F, 0x17, SS_RDEF, /* XXX TBD */ "Zone transition to full") }, /* D */ + { SST(0x3F, 0x18, SS_RDEF, /* XXX TBD */ + "Bind completed") }, + /* D */ + { SST(0x3F, 0x19, SS_RDEF, /* XXX TBD */ + "Bind redirected") }, + /* D */ + { SST(0x3F, 0x1A, SS_RDEF, /* XXX TBD */ + "Subsidiary binding changed") }, { SST(0x40, 0x00, SS_RDEF, "RAM failure") }, /* deprecated - use 40 NN instead */ /* DTLPWROMAEBKVF */ @@ -2587,6 +2652,9 @@ static struct asc_table_entry asc_table[] = { /* D */ { SST(0x55, 0x10, SS_RDEF, /* XXX TBD */ "Maximum number of streams open") }, + /* D */ + { SST(0x55, 0x11, SS_RDEF, /* XXX TBD */ + "Insufficient resources to bind") }, /* R */ { SST(0x57, 0x00, SS_RDEF, "Unable to recover table-of-contents") }, @@ -3010,6 +3078,12 @@ static struct asc_table_entry asc_table[] = { /* DT B */ { SST(0x67, 0x0B, SS_RDEF, /* XXX TBD */ "ATA device feature not enabled") }, + /* D */ + { SST(0x67, 0x0C, SS_FATAL | EIO, + "Command rejected") }, + /* D */ + { SST(0x67, 0x0D, SS_FATAL | EINVAL, + "Explicit bind not allowed") }, /* A */ { SST(0x68, 0x00, SS_RDEF, "Logical unit not configured") }, @@ -3070,6 +3144,15 @@ static struct asc_table_entry asc_table[] = { /* R */ { SST(0x6F, 0x07, SS_RDEF, /* XXX TBD */ "Conflict in binding NONCE recording") }, + /* R */ + { SST(0x6F, 0x08, SS_FATAL | EPERM, + "Insufficient permission") }, + /* R */ + { SST(0x6F, 0x09, SS_FATAL | EINVAL, + "Invalid drive-host pairing server") }, + /* R */ + { SST(0x6F, 0x0A, SS_RDEF, /* XXX TBD */ + "Drive-host pairing suspended") }, /* T */ { SST(0x70, 0x00, SS_RDEF, "Decompression exception short: ASCQ = Algorithm ID") }, @@ -3392,7 +3475,7 @@ scsi_sense_desc(int sense_key, int asc, int ascq, */ scsi_sense_action scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data, - u_int32_t sense_flags) + uint32_t sense_flags) { const struct asc_table_entry *asc_entry; const struct sense_key_table_entry *sense_entry; @@ -3419,7 +3502,7 @@ scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data, * 1. Drop through (like we had been doing), thus treating * this as if the error were for the current command and * return and stop the current command. - * + * * 2. Issue a retry (like I made it do) thus hopefully * recovering the current transfer, and ignoring the * fact that we've dropped a command. @@ -3444,7 +3527,7 @@ scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data, else if (sense_entry != NULL) action = sense_entry->action; else - action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE; + action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE; if (sense_key == SSD_KEY_RECOVERED_ERROR) { /* @@ -3485,7 +3568,7 @@ scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data, } char * -scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len) +scsi_cdb_string(uint8_t *cdb_ptr, char *cdb_string, size_t len) { struct sbuf sb; int error; @@ -3511,9 +3594,9 @@ scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len) } void -scsi_cdb_sbuf(u_int8_t *cdb_ptr, struct sbuf *sb) +scsi_cdb_sbuf(uint8_t *cdb_ptr, struct sbuf *sb) { - u_int8_t cdb_len; + uint8_t cdb_len; int i; if (cdb_ptr == NULL) @@ -3602,7 +3685,7 @@ int scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb) #else /* !_KERNEL */ int -scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio, +scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio, struct sbuf *sb) #endif /* _KERNEL/!_KERNEL */ { @@ -3650,7 +3733,7 @@ scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio, } /* - * Iterate over sense descriptors. Each descriptor is passed into iter_func(). + * Iterate over sense descriptors. Each descriptor is passed into iter_func(). * If iter_func() returns 0, list traversal continues. If iter_func() * returns non-zero, list traversal is stopped. */ @@ -3705,7 +3788,7 @@ scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len, * header (which does not include the header itself) to * desc_len - cur_pos is correct. */ - if (header->length > (desc_len - cur_pos)) + if (header->length > (desc_len - cur_pos)) break; if (iter_func(sense, sense_len, header, arg) != 0) @@ -4149,7 +4232,7 @@ scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len, if ((SSD_FIXED_IS_PRESENT(sense, sense_len, cmd_spec_info) == 0) - || (SSD_FIXED_IS_FILLED(sense, cmd_spec_info) == 0)) + || (SSD_FIXED_IS_FILLED(sense, cmd_spec_info) == 0)) goto bailout; cmd_val = scsi_4btoul(sense->cmd_spec_info); @@ -4179,7 +4262,7 @@ scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len, } break; } - default: + default: goto bailout; break; } @@ -4487,9 +4570,9 @@ scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits) /* * XXX KDM this needs more descriptive decoding. */ - sbuf_printf(sb, "Stream Command Sense Data: "); + sbuf_cat(sb, "Stream Command Sense Data: "); if (stream_bits & SSD_DESC_STREAM_FM) { - sbuf_printf(sb, "Filemark"); + sbuf_cat(sb, "Filemark"); need_comma = 1; } @@ -4506,9 +4589,9 @@ void scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits) { - sbuf_printf(sb, "Block Command Sense Data: "); + sbuf_cat(sb, "Block Command Sense Data: "); if (block_bits & SSD_DESC_BLOCK_ILI) - sbuf_printf(sb, "ILI"); + sbuf_cat(sb, "ILI"); } void @@ -4630,7 +4713,7 @@ scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, * sense key, ASC, and ASCQ in the descriptor. */ sbuf_cat(sb, sense_key_desc); - sbuf_printf(sb, " asc:%x,%x (%s): ", progress->add_sense_code, + sbuf_printf(sb, " asc:%x,%x (%s): ", progress->add_sense_code, progress->add_sense_code_qual, asc_desc); scsi_progress_sbuf(sb, progress_val); } @@ -4842,7 +4925,7 @@ scsi_print_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len, (struct scsi_sense_data *)sense, sense_len, print_info->cdb, print_info->cdb_len, print_info->inq_data, header); - sbuf_printf(print_info->sb, "\n"); + sbuf_putc(print_info->sb, '\n'); break; } } @@ -4867,11 +4950,11 @@ scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len, scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key, &asc, &ascq, /*show_errors*/ 1); - sbuf_printf(sb, "SCSI sense: "); + sbuf_cat(sb, "SCSI sense: "); switch (error_code) { case SSD_DEFERRED_ERROR: case SSD_DESC_DEFERRED_ERROR: - sbuf_printf(sb, "Deferred error: "); + sbuf_cat(sb, "Deferred error: "); /* FALLTHROUGH */ case SSD_CURRENT_ERROR: @@ -4908,12 +4991,12 @@ scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len, &bits) == 0 && bits != 0) { sbuf_cat(sb, path_str); scsi_block_sbuf(sb, bits); - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); } else if (scsi_get_stream_info(sense, sense_len, inq_data, &bits) == 0 && bits != 0) { sbuf_cat(sb, path_str); scsi_stream_sbuf(sb, bits); - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); } /* @@ -4923,17 +5006,17 @@ scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len, &val, NULL) == 0) { sbuf_cat(sb, path_str); scsi_info_sbuf(sb, cdb, cdb_len, inq_data, val); - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); } - /* + /* * Print the FRU. */ if (scsi_get_sense_info(sense, sense_len, SSD_DESC_FRU, &val, NULL) == 0) { sbuf_cat(sb, path_str); scsi_fru_sbuf(sb, val); - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); } /* @@ -4943,7 +5026,7 @@ scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len, &val, NULL) == 0) { sbuf_cat(sb, path_str); scsi_command_sbuf(sb, cdb, cdb_len, inq_data, val); - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); } /* @@ -4952,7 +5035,7 @@ scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len, if (scsi_get_sks(sense, sense_len, sks) == 0) { sbuf_cat(sb, path_str); scsi_sks_sbuf(sb, sense_key, sks); - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); } /* @@ -4984,7 +5067,7 @@ scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len, * show_errors flag is set and they aren't present in the * sense data. This means that sense_len is 0. */ - sbuf_printf(sb, "No sense data present\n"); + sbuf_cat(sb, "No sense data present\n"); break; default: { sbuf_printf(sb, "Error code 0x%x", error_code); @@ -5002,7 +5085,7 @@ scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len, info); } } - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); break; } } @@ -5017,7 +5100,7 @@ scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb, scsi_sense_string_flags flags) #else /* !_KERNEL */ int -scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio, +scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio, struct sbuf *sb, scsi_sense_string_flags flags) #endif /* _KERNEL/!_KERNEL */ { @@ -5084,7 +5167,7 @@ scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio, #else /* !_KERNEL */ scsi_command_string(device, csio, sb); #endif /* _KERNEL/!_KERNEL */ - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); } /* @@ -5097,7 +5180,7 @@ scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio, #endif /* _KERNEL/!_KERNEL */ return(-1); } else { - /* + /* * bcopy the pointer to avoid unaligned access * errors on finicky architectures. We don't * ensure that the sense data is pointer aligned. @@ -5157,7 +5240,7 @@ scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio, } #ifdef _KERNEL -void +void scsi_sense_print(struct ccb_scsiio *csio) { struct sbuf sb; @@ -5174,7 +5257,7 @@ scsi_sense_print(struct ccb_scsiio *csio) #else /* !_KERNEL */ void -scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio, +scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio, FILE *ofile) { struct sbuf sb; @@ -5363,7 +5446,7 @@ scsi_get_ascq(struct scsi_sense_data *sense_data, u_int sense_len, void scsi_print_inquiry_sbuf(struct sbuf *sb, struct scsi_inquiry_data *inq_data) { - u_int8_t type; + uint8_t type; char *dtype, *qtype; type = SID_TYPE(inq_data); @@ -5458,7 +5541,7 @@ scsi_print_inquiry_sbuf(struct sbuf *sb, struct scsi_inquiry_data *inq_data) sbuf_printf(sb, "%s %s ", SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed", dtype); if (SID_ANSI_REV(inq_data) == SCSI_REV_0) - sbuf_printf(sb, "SCSI "); + sbuf_cat(sb, "SCSI "); else if (SID_ANSI_REV(inq_data) <= SCSI_REV_SPC) { sbuf_printf(sb, "SCSI-%d ", SID_ANSI_REV(inq_data)); } else { @@ -5483,13 +5566,13 @@ void scsi_print_inquiry_short_sbuf(struct sbuf *sb, struct scsi_inquiry_data *inq_data) { - sbuf_printf(sb, "<"); + sbuf_putc(sb, '<'); cam_strvis_sbuf(sb, inq_data->vendor, sizeof(inq_data->vendor), 0); - sbuf_printf(sb, " "); + sbuf_putc(sb, ' '); cam_strvis_sbuf(sb, inq_data->product, sizeof(inq_data->product), 0); - sbuf_printf(sb, " "); + sbuf_putc(sb, ' '); cam_strvis_sbuf(sb, inq_data->revision, sizeof(inq_data->revision), 0); - sbuf_printf(sb, "> "); + sbuf_cat(sb, "> "); } void @@ -5789,7 +5872,7 @@ scsi_transportid_sbuf(struct sbuf *sb, struct scsi_transportid_header *hdr, rdma = (struct scsi_transportid_rdma *)hdr; - sbuf_printf(sb, "RDMA address: 0x"); + sbuf_cat(sb, "RDMA address: 0x"); for (i = 0; i < sizeof(rdma->initiator_port_id); i++) sbuf_printf(sb, "%02x", rdma->initiator_port_id[i]); break; @@ -5799,8 +5882,8 @@ scsi_transportid_sbuf(struct sbuf *sb, struct scsi_transportid_header *hdr, uint8_t *iscsi_name = NULL; int nul_found = 0; - sbuf_printf(sb, "iSCSI address: "); - if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) == + sbuf_cat(sb, "iSCSI address: "); + if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) == SCSI_TRN_ISCSI_FORMAT_DEVICE) { struct scsi_transportid_iscsi_device *dev; @@ -5820,7 +5903,7 @@ scsi_transportid_sbuf(struct sbuf *sb, struct scsi_transportid_header *hdr, struct scsi_transportid_iscsi_port *port; port = (struct scsi_transportid_iscsi_port *)hdr; - + add_len = scsi_2btoul(port->additional_length); add_len = MIN(add_len, valid_len - __offsetof(struct scsi_transportid_iscsi_port, @@ -5834,11 +5917,11 @@ scsi_transportid_sbuf(struct sbuf *sb, struct scsi_transportid_header *hdr, break; } if (add_len == 0) { - sbuf_printf(sb, "not enough data"); + sbuf_cat(sb, "not enough data"); break; } /* - * This is supposed to be a NUL-terminated ASCII + * This is supposed to be a NUL-terminated ASCII * string, but you never know. So we're going to * check. We need to do this because there is no * sbuf equivalent of strncat(). @@ -6009,7 +6092,7 @@ scsi_parse_transportid_64bit(int proto_id, char *id_str, retval = 0; - value = strtouq(id_str, &endptr, 0); + value = strtouq(id_str, &endptr, 0); if (*endptr != '\0') { if (error_str != NULL) { snprintf(error_str, error_str_len, "%s: error " @@ -6254,7 +6337,7 @@ scsi_parse_transportid_rdma(char *id_str, struct scsi_transportid_header **hdr, */ if ((i % 2) == 0) cur_shift = 4; - else + else cur_shift = 0; c = tmpstr[i]; @@ -6275,7 +6358,7 @@ scsi_parse_transportid_rdma(char *id_str, struct scsi_transportid_header **hdr, } /* * The converted number can't be less than 0; the type is - * unsigned, and the subtraction logic will not give us + * unsigned, and the subtraction logic will not give us * a negative number. So we only need to make sure that * the value is not greater than 0xf. (i.e. make sure the * user didn't give us a value like "0x12jklmno"). @@ -6290,7 +6373,7 @@ scsi_parse_transportid_rdma(char *id_str, struct scsi_transportid_header **hdr, retval = 1; goto bailout; } - + rdma_id[j] |= c << cur_shift; } @@ -6369,7 +6452,7 @@ scsi_parse_transportid_iscsi(char *id_str, struct scsi_transportid_header **hdr, if (id_str[i] == sep_template[sep_pos]) { sep_pos++; continue; - } + } if (error_str != NULL) { snprintf(error_str, error_str_len, "%s: " "invalid separator in iSCSI name " @@ -6478,7 +6561,7 @@ scsi_parse_transportid_sop(char *id_str, struct scsi_transportid_header **hdr, retval = 1; goto bailout; } - if ((id_str == NULL) + if ((id_str == NULL) || (*id_str == '\0')) { if (error_str != NULL) { snprintf(error_str, error_str_len, "%s: no PCIe " @@ -6553,7 +6636,7 @@ scsi_parse_transportid_sop(char *id_str, struct scsi_transportid_header **hdr, snprintf(error_str, error_str_len, "%s: function value " "%lu greater than maximum %u", __func__, function, (device_spec == 0) ? - SCSI_TRN_SOP_FUNC_ALT_MAX : + SCSI_TRN_SOP_FUNC_ALT_MAX : SCSI_TRN_SOP_FUNC_NORM_MAX); } retval = 1; @@ -7000,7 +7083,7 @@ scsi_attrib_volcoh_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, vcr_len = *cur_ptr; cur_ptr++; - sbuf_printf(sb, "\n\tVolume Change Reference Value:"); + sbuf_cat(sb, "\n\tVolume Change Reference Value:"); switch (vcr_len) { case 0: @@ -7027,7 +7110,7 @@ scsi_attrib_volcoh_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, tmp_val = scsi_8btou64(cur_ptr); break; default: - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); sbuf_hexdump(sb, cur_ptr, vcr_len, NULL, 0); break; } @@ -7050,11 +7133,11 @@ scsi_attrib_volcoh_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, cur_ptr += sizeof(tmp_val); as_len = scsi_2btoul(cur_ptr); cur_ptr += sizeof(uint16_t); - sbuf_printf(sb, "\tApplication Client Specific Information: "); + sbuf_cat(sb, "\tApplication Client Specific Information: "); if (((as_len == SCSI_LTFS_VER0_LEN) || (as_len == SCSI_LTFS_VER1_LEN)) && (strncmp(cur_ptr, SCSI_LTFS_STR_NAME, SCSI_LTFS_STR_LEN) == 0)) { - sbuf_printf(sb, "LTFS\n"); + sbuf_cat(sb, "LTFS\n"); cur_ptr += SCSI_LTFS_STR_LEN + 1; if (cur_ptr[SCSI_LTFS_UUID_LEN] != '\0') cur_ptr[SCSI_LTFS_UUID_LEN] = '\0'; @@ -7063,7 +7146,7 @@ scsi_attrib_volcoh_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, /* XXX KDM check the length */ sbuf_printf(sb, "\tLTFS Version: %d\n", *cur_ptr); } else { - sbuf_printf(sb, "Unknown\n"); + sbuf_cat(sb, "Unknown\n"); sbuf_hexdump(sb, cur_ptr, as_len, NULL, 0); } @@ -7073,7 +7156,7 @@ bailout: int scsi_attrib_vendser_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, - uint32_t valid_len, uint32_t flags, + uint32_t valid_len, uint32_t flags, uint32_t output_flags, char *error_str, int error_str_len) { @@ -7149,7 +7232,7 @@ scsi_attrib_hexdump_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, num_ptr = hdr->attribute; if (print_len > 0) { - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); sbuf_hexdump(sb, num_ptr, print_len, NULL, 0); } @@ -7170,7 +7253,7 @@ scsi_attrib_int_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, number_size = scsi_2btoul(hdr->length); avail_len = valid_len - sizeof(*hdr); - if (avail_len < number_size) { + if (avail_len < number_size) { if (error_str != NULL) { snprintf(error_str, error_str_len, "Available " "length of attribute ID 0x%.4x %zu < field " @@ -7297,7 +7380,7 @@ scsi_attrib_ascii_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, int scsi_attrib_text_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, - uint32_t valid_len, uint32_t flags, + uint32_t valid_len, uint32_t flags, uint32_t output_flags, char *error_str, int error_str_len) { @@ -7442,7 +7525,7 @@ scsi_attrib_prefix_sbuf(struct sbuf *sb, uint32_t output_flags, if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_DESC) && (desc != NULL)) { - sbuf_printf(sb, "%s", desc); + sbuf_cat(sb, desc); need_space = 1; } @@ -7459,7 +7542,7 @@ scsi_attrib_prefix_sbuf(struct sbuf *sb, uint32_t output_flags, sbuf_printf(sb, "%s(%s)", (need_space) ? " " : "", (hdr->byte2 & SMA_READ_ONLY) ? "RO" : "RW"); } - sbuf_printf(sb, ": "); + sbuf_cat(sb, ": "); } int @@ -7537,16 +7620,16 @@ bailout: sbuf_printf(sb, " %s", entry->suffix); sbuf_trim(sb); - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); } return (retval); } void -scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries, +scsi_test_unit_ready(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, uint8_t sense_len, uint32_t timeout) { struct scsi_test_unit_ready *scsi_cmd; @@ -7567,10 +7650,10 @@ scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries, +scsi_request_sense(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action, - u_int8_t sense_len, u_int32_t timeout) + void *data_ptr, uint8_t dxfer_len, uint8_t tag_action, + uint8_t sense_len, uint32_t timeout) { struct scsi_request_sense *scsi_cmd; @@ -7592,11 +7675,11 @@ scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries, +scsi_inquiry(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len, - int evpd, u_int8_t page_code, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, uint8_t *inq_buf, uint32_t inq_len, + int evpd, uint8_t page_code, uint8_t sense_len, + uint32_t timeout) { struct scsi_inquiry *scsi_cmd; @@ -7616,7 +7699,7 @@ scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries, scsi_cmd->opcode = INQUIRY; if (evpd) { scsi_cmd->byte2 |= SI_EVPD; - scsi_cmd->page_code = page_code; + scsi_cmd->page_code = page_code; } scsi_ulto2b(inq_len, scsi_cmd->length); } @@ -7651,7 +7734,7 @@ scsi_mode_sense_subpage(struct ccb_scsiio *csio, uint32_t retries, uint32_t param_len, int minimum_cmd_size, uint8_t sense_len, uint32_t timeout) { - u_int8_t cdb_len; + uint8_t cdb_len; /* * Use the smallest possible command to perform the operation. @@ -7701,11 +7784,11 @@ scsi_mode_sense_subpage(struct ccb_scsiio *csio, uint32_t retries, } void -scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries, +scsi_mode_select(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int scsi_page_fmt, int save_pages, - u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, int scsi_page_fmt, int save_pages, + uint8_t *param_buf, uint32_t param_len, uint8_t sense_len, + uint32_t timeout) { scsi_mode_select_len(csio, retries, cbfcnp, tag_action, scsi_page_fmt, save_pages, param_buf, @@ -7713,14 +7796,14 @@ scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries, +scsi_mode_select_len(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int scsi_page_fmt, int save_pages, - u_int8_t *param_buf, u_int32_t param_len, - int minimum_cmd_size, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, int scsi_page_fmt, int save_pages, + uint8_t *param_buf, uint32_t param_len, + int minimum_cmd_size, uint8_t sense_len, + uint32_t timeout) { - u_int8_t cdb_len; + uint8_t cdb_len; /* * Use the smallest possible command to perform the operation. @@ -7771,15 +7854,15 @@ scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries, +scsi_log_sense(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t page_code, u_int8_t page, - int save_pages, int ppc, u_int32_t paramptr, - u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, uint8_t page_code, uint8_t page, + int save_pages, int ppc, uint32_t paramptr, + uint8_t *param_buf, uint32_t param_len, uint8_t sense_len, + uint32_t timeout) { struct scsi_log_sense *scsi_cmd; - u_int8_t cdb_len; + uint8_t cdb_len; scsi_cmd = (struct scsi_log_sense *)&csio->cdb_io.cdb_bytes; bzero(scsi_cmd, sizeof(*scsi_cmd)); @@ -7806,14 +7889,14 @@ scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries, +scsi_log_select(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t page_code, int save_pages, - int pc_reset, u_int8_t *param_buf, u_int32_t param_len, - u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, uint8_t page_code, int save_pages, + int pc_reset, uint8_t *param_buf, uint32_t param_len, + uint8_t sense_len, uint32_t timeout) { struct scsi_log_select *scsi_cmd; - u_int8_t cdb_len; + uint8_t cdb_len; scsi_cmd = (struct scsi_log_select *)&csio->cdb_io.cdb_bytes; bzero(scsi_cmd, sizeof(*scsi_cmd)); @@ -7842,10 +7925,10 @@ scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries, * Prevent or allow the user to remove the media */ void -scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries, +scsi_prevent(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t action, - u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, uint8_t action, + uint8_t sense_len, uint32_t timeout) { struct scsi_prevent *scsi_cmd; @@ -7868,11 +7951,11 @@ scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries, /* XXX allow specification of address and PMI bit and LBA */ void -scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries, +scsi_read_capacity(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, + uint8_t tag_action, struct scsi_read_capacity_data *rcap_buf, - u_int8_t sense_len, u_int32_t timeout) + uint8_t sense_len, uint32_t timeout) { struct scsi_read_capacity *scsi_cmd; @@ -7881,7 +7964,7 @@ scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries, cbfcnp, /*flags*/CAM_DIR_IN, tag_action, - /*data_ptr*/(u_int8_t *)rcap_buf, + /*data_ptr*/(uint8_t *)rcap_buf, /*dxfer_len*/sizeof(*rcap_buf), sense_len, sizeof(*scsi_cmd), @@ -7906,7 +7989,7 @@ scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries, cbfcnp, /*flags*/CAM_DIR_IN, tag_action, - /*data_ptr*/(u_int8_t *)rcap_buf, + /*data_ptr*/(uint8_t *)rcap_buf, /*dxfer_len*/rcap_buf_len, sense_len, sizeof(*scsi_cmd), @@ -7924,11 +8007,11 @@ scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries, } void -scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries, +scsi_report_luns(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t select_report, - struct scsi_report_luns_data *rpl_buf, u_int32_t alloc_len, - u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, uint8_t select_report, + struct scsi_report_luns_data *rpl_buf, uint32_t alloc_len, + uint8_t sense_len, uint32_t timeout) { struct scsi_report_luns *scsi_cmd; @@ -7937,7 +8020,7 @@ scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries, cbfcnp, /*flags*/CAM_DIR_IN, tag_action, - /*data_ptr*/(u_int8_t *)rpl_buf, + /*data_ptr*/(uint8_t *)rpl_buf, /*dxfer_len*/alloc_len, sense_len, sizeof(*scsi_cmd), @@ -7950,11 +8033,11 @@ scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries, +scsi_report_target_group(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t pdf, - void *buf, u_int32_t alloc_len, - u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, uint8_t pdf, + void *buf, uint32_t alloc_len, + uint8_t sense_len, uint32_t timeout) { struct scsi_target_group *scsi_cmd; @@ -7963,7 +8046,7 @@ scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries, cbfcnp, /*flags*/CAM_DIR_IN, tag_action, - /*data_ptr*/(u_int8_t *)buf, + /*data_ptr*/(uint8_t *)buf, /*dxfer_len*/alloc_len, sense_len, sizeof(*scsi_cmd), @@ -7976,11 +8059,11 @@ scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_report_timestamp(struct ccb_scsiio *csio, u_int32_t retries, +scsi_report_timestamp(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t pdf, - void *buf, u_int32_t alloc_len, - u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, uint8_t pdf, + void *buf, uint32_t alloc_len, + uint8_t sense_len, uint32_t timeout) { struct scsi_timestamp *scsi_cmd; @@ -7989,7 +8072,7 @@ scsi_report_timestamp(struct ccb_scsiio *csio, u_int32_t retries, cbfcnp, /*flags*/CAM_DIR_IN, tag_action, - /*data_ptr*/(u_int8_t *)buf, + /*data_ptr*/(uint8_t *)buf, /*dxfer_len*/alloc_len, sense_len, sizeof(*scsi_cmd), @@ -8002,10 +8085,10 @@ scsi_report_timestamp(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries, +scsi_set_target_group(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, void *buf, u_int32_t alloc_len, - u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, void *buf, uint32_t alloc_len, + uint8_t sense_len, uint32_t timeout) { struct scsi_target_group *scsi_cmd; @@ -8014,7 +8097,7 @@ scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries, cbfcnp, /*flags*/CAM_DIR_OUT, tag_action, - /*data_ptr*/(u_int8_t *)buf, + /*data_ptr*/(uint8_t *)buf, /*dxfer_len*/alloc_len, sense_len, sizeof(*scsi_cmd), @@ -8041,10 +8124,10 @@ scsi_create_timestamp(uint8_t *timestamp_6b_buf, } void -scsi_set_timestamp(struct ccb_scsiio *csio, u_int32_t retries, +scsi_set_timestamp(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, void *buf, u_int32_t alloc_len, - u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, void *buf, uint32_t alloc_len, + uint8_t sense_len, uint32_t timeout) { struct scsi_timestamp *scsi_cmd; @@ -8053,7 +8136,7 @@ scsi_set_timestamp(struct ccb_scsiio *csio, u_int32_t retries, cbfcnp, /*flags*/CAM_DIR_OUT, tag_action, - /*data_ptr*/(u_int8_t *) buf, + /*data_ptr*/(uint8_t *) buf, /*dxfer_len*/alloc_len, sense_len, sizeof(*scsi_cmd), @@ -8071,11 +8154,11 @@ scsi_set_timestamp(struct ccb_scsiio *csio, u_int32_t retries, * the whole cache. */ void -scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries, +scsi_synchronize_cache(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int32_t begin_lba, - u_int16_t lb_count, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, uint32_t begin_lba, + uint16_t lb_count, uint8_t sense_len, + uint32_t timeout) { struct scsi_sync_cache *scsi_cmd; @@ -8098,15 +8181,15 @@ scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries, +scsi_read_write(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int readop, u_int8_t byte2, - int minimum_cmd_size, u_int64_t lba, u_int32_t block_count, - u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, int readop, uint8_t byte2, + int minimum_cmd_size, uint64_t lba, uint32_t block_count, + uint8_t *data_ptr, uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout) { int read; - u_int8_t cdb_len; + uint8_t cdb_len; read = (readop & SCSI_RW_DIRMASK) == SCSI_RW_READ; @@ -8161,7 +8244,7 @@ scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries, } else if ((minimum_cmd_size < 16) && ((block_count & 0xffffffff) == block_count) && ((lba & 0xffffffff) == lba)) { - /* + /* * The block count is too big for a 10 byte CDB, use a 12 * byte CDB. */ @@ -8212,14 +8295,14 @@ scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries, +scsi_write_same(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t byte2, - int minimum_cmd_size, u_int64_t lba, u_int32_t block_count, - u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, uint8_t byte2, + int minimum_cmd_size, uint64_t lba, uint32_t block_count, + uint8_t *data_ptr, uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout) { - u_int8_t cdb_len; + uint8_t cdb_len; if ((minimum_cmd_size < 16) && ((block_count & 0xffff) == block_count) && ((lba & 0xffffffff) == lba)) { @@ -8281,11 +8364,11 @@ scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_ata_identify(struct ccb_scsiio *csio, u_int32_t retries, +scsi_ata_identify(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t *data_ptr, - u_int16_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, uint8_t *data_ptr, + uint16_t dxfer_len, uint8_t sense_len, + uint32_t timeout) { scsi_ata_pass(csio, retries, @@ -8314,11 +8397,11 @@ scsi_ata_identify(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_ata_trim(struct ccb_scsiio *csio, u_int32_t retries, +scsi_ata_trim(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int16_t block_count, - u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, uint16_t block_count, + uint8_t *data_ptr, uint16_t dxfer_len, uint8_t sense_len, + uint32_t timeout) { scsi_ata_pass_16(csio, retries, @@ -8447,9 +8530,9 @@ scsi_ata_pass(struct ccb_scsiio *csio, uint32_t retries, uint8_t protocol, uint8_t ata_flags, uint16_t features, uint16_t sector_count, uint64_t lba, uint8_t command, uint8_t device, uint8_t icc, uint32_t auxiliary, - uint8_t control, u_int8_t *data_ptr, uint32_t dxfer_len, + uint8_t control, uint8_t *data_ptr, uint32_t dxfer_len, uint8_t *cdb_storage, size_t cdb_storage_len, - int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout) + int minimum_cmd_size, uint8_t sense_len, uint32_t timeout) { uint32_t cam_flags; uint8_t *cdb_ptr; @@ -8475,7 +8558,7 @@ scsi_ata_pass(struct ccb_scsiio *csio, uint32_t retries, * If we have parameters that require a 48-bit ATA command, we have to * use the 16 byte ATA PASS-THROUGH command at least. */ - if (((lba > ATA_MAX_28BIT_LBA) + if (((lba > ATA_MAX_28BIT_LBA) || (sector_count > 255) || (features > 255) || (protocol & AP_EXTEND)) @@ -8612,13 +8695,13 @@ bailout: } void -scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries, +scsi_ata_pass_16(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int32_t flags, u_int8_t tag_action, - u_int8_t protocol, u_int8_t ata_flags, u_int16_t features, - u_int16_t sector_count, uint64_t lba, u_int8_t command, - u_int8_t control, u_int8_t *data_ptr, u_int16_t dxfer_len, - u_int8_t sense_len, u_int32_t timeout) + uint32_t flags, uint8_t tag_action, + uint8_t protocol, uint8_t ata_flags, uint16_t features, + uint16_t sector_count, uint64_t lba, uint8_t command, + uint8_t control, uint8_t *data_ptr, uint16_t dxfer_len, + uint8_t sense_len, uint32_t timeout) { struct ata_pass_16 *ata_cmd; @@ -8656,11 +8739,11 @@ scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries, +scsi_unmap(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t byte2, - u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, uint8_t byte2, + uint8_t *data_ptr, uint16_t dxfer_len, uint8_t sense_len, + uint32_t timeout) { struct scsi_unmap *scsi_cmd; @@ -8685,7 +8768,7 @@ scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries, +scsi_receive_diagnostic_results(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*), uint8_t tag_action, int pcv, uint8_t page_code, uint8_t *data_ptr, uint16_t allocation_length, @@ -8715,7 +8798,7 @@ scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries, +scsi_send_diagnostic(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, int unit_offline, int device_offline, int self_test, int page_format, int self_test_code, @@ -8756,7 +8839,7 @@ scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_get_physical_element_status(struct ccb_scsiio *csio, u_int32_t retries, +scsi_get_physical_element_status(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, uint8_t *data_ptr, uint16_t allocation_length, uint8_t report_type, @@ -8785,7 +8868,7 @@ scsi_get_physical_element_status(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_remove_element_and_truncate(struct ccb_scsiio *csio, u_int32_t retries, +scsi_remove_element_and_truncate(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, uint64_t requested_capacity, uint32_t element_id, @@ -8813,7 +8896,7 @@ scsi_remove_element_and_truncate(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_restore_elements_and_rebuild(struct ccb_scsiio *csio, u_int32_t retries, +scsi_restore_elements_and_rebuild(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, uint8_t sense_len, uint32_t timeout) @@ -8838,10 +8921,10 @@ scsi_restore_elements_and_rebuild(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries, +scsi_read_buffer(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*), uint8_t tag_action, int mode, - uint8_t buffer_id, u_int32_t offset, + uint8_t buffer_id, uint32_t offset, uint8_t *data_ptr, uint32_t allocation_length, uint8_t sense_len, uint32_t timeout) { @@ -8868,10 +8951,10 @@ scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries, +scsi_write_buffer(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, int mode, - uint8_t buffer_id, u_int32_t offset, + uint8_t buffer_id, uint32_t offset, uint8_t *data_ptr, uint32_t param_list_length, uint8_t sense_len, uint32_t timeout) { @@ -8897,11 +8980,11 @@ scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries, timeout); } -void -scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries, +void +scsi_start_stop(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int start, int load_eject, - int immediate, u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, int start, int load_eject, + int immediate, uint8_t sense_len, uint32_t timeout) { struct scsi_start_stop_unit *scsi_cmd; int extra_flags = 0; @@ -8932,13 +9015,13 @@ scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_read_attribute(struct ccb_scsiio *csio, u_int32_t retries, +scsi_read_attribute(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t service_action, - uint32_t element, u_int8_t elem_type, int logical_volume, - int partition, u_int32_t first_attribute, int cache, - u_int8_t *data_ptr, u_int32_t length, int sense_len, - u_int32_t timeout) + uint8_t tag_action, uint8_t service_action, + uint32_t element, uint8_t elem_type, int logical_volume, + int partition, uint32_t first_attribute, int cache, + uint8_t *data_ptr, uint32_t length, int sense_len, + uint32_t timeout) { struct scsi_read_attribute *scsi_cmd; @@ -8969,11 +9052,11 @@ scsi_read_attribute(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_write_attribute(struct ccb_scsiio *csio, u_int32_t retries, +scsi_write_attribute(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, uint32_t element, int logical_volume, - int partition, int wtc, u_int8_t *data_ptr, - u_int32_t length, int sense_len, u_int32_t timeout) + uint8_t tag_action, uint32_t element, int logical_volume, + int partition, int wtc, uint8_t *data_ptr, + uint32_t length, int sense_len, uint32_t timeout) { struct scsi_write_attribute *scsi_cmd; @@ -9001,7 +9084,7 @@ scsi_write_attribute(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_persistent_reserve_in(struct ccb_scsiio *csio, uint32_t retries, +scsi_persistent_reserve_in(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, int service_action, uint8_t *data_ptr, uint32_t dxfer_len, int sense_len, @@ -9029,7 +9112,7 @@ scsi_persistent_reserve_in(struct ccb_scsiio *csio, uint32_t retries, } void -scsi_persistent_reserve_out(struct ccb_scsiio *csio, uint32_t retries, +scsi_persistent_reserve_out(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, int service_action, int scope, int res_type, uint8_t *data_ptr, @@ -9058,7 +9141,7 @@ scsi_persistent_reserve_out(struct ccb_scsiio *csio, uint32_t retries, } void -scsi_security_protocol_in(struct ccb_scsiio *csio, uint32_t retries, +scsi_security_protocol_in(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, uint32_t security_protocol, uint32_t security_protocol_specific, int byte4, @@ -9074,7 +9157,7 @@ scsi_security_protocol_in(struct ccb_scsiio *csio, uint32_t retries, scsi_cmd->security_protocol = security_protocol; scsi_ulto2b(security_protocol_specific, - scsi_cmd->security_protocol_specific); + scsi_cmd->security_protocol_specific); scsi_cmd->byte4 = byte4; scsi_ulto4b(dxfer_len, scsi_cmd->length); @@ -9091,7 +9174,7 @@ scsi_security_protocol_in(struct ccb_scsiio *csio, uint32_t retries, } void -scsi_security_protocol_out(struct ccb_scsiio *csio, uint32_t retries, +scsi_security_protocol_out(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, uint32_t security_protocol, uint32_t security_protocol_specific, int byte4, @@ -9107,7 +9190,7 @@ scsi_security_protocol_out(struct ccb_scsiio *csio, uint32_t retries, scsi_cmd->security_protocol = security_protocol; scsi_ulto2b(security_protocol_specific, - scsi_cmd->security_protocol_specific); + scsi_cmd->security_protocol_specific); scsi_cmd->byte4 = byte4; scsi_ulto4b(dxfer_len, scsi_cmd->length); @@ -9124,7 +9207,7 @@ scsi_security_protocol_out(struct ccb_scsiio *csio, uint32_t retries, } void -scsi_report_supported_opcodes(struct ccb_scsiio *csio, uint32_t retries, +scsi_report_supported_opcodes(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, int options, int req_opcode, int req_service_action, uint8_t *data_ptr, @@ -9155,7 +9238,7 @@ scsi_report_supported_opcodes(struct ccb_scsiio *csio, uint32_t retries, timeout); } -/* +/* * Try make as good a match as possible with * available sub drivers */ @@ -9182,7 +9265,7 @@ scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry) return (-1); } -/* +/* * Try make as good a match as possible with * available sub drivers */ @@ -9322,7 +9405,8 @@ sysctl_scsi_delay(SYSCTL_HANDLER_ARGS) return (set_scsi_delay(delay)); } SYSCTL_PROC(_kern_cam, OID_AUTO, scsi_delay, - CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 0, sysctl_scsi_delay, "I", + CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NOFETCH | CTLFLAG_MPSAFE, + 0, 0, sysctl_scsi_delay, "I", "Delay to allow devices to settle after a SCSI bus reset (ms)"); static int diff --git a/sys/cam/scsi/scsi_all.h b/sys/cam/scsi/scsi_all.h index 3272f23b172e..7456998a4f88 100644 --- a/sys/cam/scsi/scsi_all.h +++ b/sys/cam/scsi/scsi_all.h @@ -13,8 +13,6 @@ * functioning of this software in any circumstances. * * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 - * - * $FreeBSD$ */ /* @@ -24,8 +22,8 @@ #ifndef _SCSI_SCSI_ALL_H #define _SCSI_SCSI_ALL_H 1 -#include <sys/cdefs.h> #ifdef _KERNEL +#include <sys/malloc.h> #include <machine/stdarg.h> #else #include <stdarg.h> @@ -72,6 +70,8 @@ typedef enum { SS_NOP = 0x000000, /* Do nothing */ SS_RETRY = 0x010000, /* Retry the command */ SS_FAIL = 0x020000, /* Bail out */ + + /* Actions larger than SS_START allocate a recovery CCB */ SS_START = 0x030000, /* Send a Start Unit command to the device, * then retry the original command. */ @@ -115,26 +115,26 @@ typedef enum { struct scsi_generic { - u_int8_t opcode; - u_int8_t bytes[11]; + uint8_t opcode; + uint8_t bytes[11]; }; struct scsi_request_sense { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define SRS_DESC 0x01 - u_int8_t unused[2]; - u_int8_t length; - u_int8_t control; + uint8_t unused[2]; + uint8_t length; + uint8_t control; }; struct scsi_test_unit_ready { - u_int8_t opcode; - u_int8_t byte2; - u_int8_t unused[3]; - u_int8_t control; + uint8_t opcode; + uint8_t byte2; + uint8_t unused[3]; + uint8_t control; }; struct scsi_receive_diag { @@ -168,30 +168,30 @@ struct scsi_send_diag { struct scsi_sense { - u_int8_t opcode; - u_int8_t byte2; - u_int8_t unused[2]; - u_int8_t length; - u_int8_t control; + uint8_t opcode; + uint8_t byte2; + uint8_t unused[2]; + uint8_t length; + uint8_t control; }; struct scsi_inquiry { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define SI_EVPD 0x01 #define SI_CMDDT 0x02 - u_int8_t page_code; - u_int8_t length[2]; - u_int8_t control; + uint8_t page_code; + uint8_t length[2]; + uint8_t control; }; struct scsi_mode_sense_6 { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define SMS_DBD 0x08 - u_int8_t page; + uint8_t page; #define SMS_PAGE_CODE 0x3F #define SMS_VENDOR_SPECIFIC_PAGE 0x00 #define SMS_DISCONNECT_RECONNECT_PAGE 0x02 @@ -208,44 +208,44 @@ struct scsi_mode_sense_6 #define SMS_PAGE_CTRL_CHANGEABLE 0x40 #define SMS_PAGE_CTRL_DEFAULT 0x80 #define SMS_PAGE_CTRL_SAVED 0xC0 - u_int8_t subpage; + uint8_t subpage; #define SMS_SUBPAGE_PAGE_0 0x00 #define SMS_SUBPAGE_ALL 0xff - u_int8_t length; - u_int8_t control; + uint8_t length; + uint8_t control; }; struct scsi_mode_sense_10 { - u_int8_t opcode; - u_int8_t byte2; /* same bits as small version */ + uint8_t opcode; + uint8_t byte2; /* same bits as small version */ #define SMS10_LLBAA 0x10 - u_int8_t page; /* same bits as small version */ - u_int8_t subpage; - u_int8_t unused[3]; - u_int8_t length[2]; - u_int8_t control; + uint8_t page; /* same bits as small version */ + uint8_t subpage; + uint8_t unused[3]; + uint8_t length[2]; + uint8_t control; }; struct scsi_mode_select_6 { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define SMS_SP 0x01 #define SMS_RTD 0x02 #define SMS_PF 0x10 - u_int8_t unused[2]; - u_int8_t length; - u_int8_t control; + uint8_t unused[2]; + uint8_t length; + uint8_t control; }; struct scsi_mode_select_10 { - u_int8_t opcode; - u_int8_t byte2; /* same bits as small version */ - u_int8_t unused[5]; - u_int8_t length[2]; - u_int8_t control; + uint8_t opcode; + uint8_t byte2; /* same bits as small version */ + uint8_t unused[5]; + uint8_t length[2]; + uint8_t control; }; /* @@ -253,68 +253,68 @@ struct scsi_mode_select_10 */ struct scsi_mode_hdr_6 { - u_int8_t datalen; - u_int8_t medium_type; - u_int8_t dev_specific; - u_int8_t block_descr_len; + uint8_t datalen; + uint8_t medium_type; + uint8_t dev_specific; + uint8_t block_descr_len; }; struct scsi_mode_hdr_10 { - u_int8_t datalen[2]; - u_int8_t medium_type; - u_int8_t dev_specific; - u_int8_t flags; + uint8_t datalen[2]; + uint8_t medium_type; + uint8_t dev_specific; + uint8_t flags; #define SMH_LONGLBA 0x01 - u_int8_t reserved; - u_int8_t block_descr_len[2]; + uint8_t reserved; + uint8_t block_descr_len[2]; }; struct scsi_mode_block_descr { - u_int8_t density_code; - u_int8_t num_blocks[3]; - u_int8_t reserved; - u_int8_t block_len[3]; + uint8_t density_code; + uint8_t num_blocks[3]; + uint8_t reserved; + uint8_t block_len[3]; }; struct scsi_mode_block_descr_dshort { - u_int8_t num_blocks[4]; - u_int8_t reserved; - u_int8_t block_len[3]; + uint8_t num_blocks[4]; + uint8_t reserved; + uint8_t block_len[3]; }; struct scsi_mode_block_descr_dlong { - u_int8_t num_blocks[8]; - u_int8_t reserved[4]; - u_int8_t block_len[4]; + uint8_t num_blocks[8]; + uint8_t reserved[4]; + uint8_t block_len[4]; }; struct scsi_per_res_in { - u_int8_t opcode; - u_int8_t action; + uint8_t opcode; + uint8_t action; #define SPRI_RK 0x00 #define SPRI_RR 0x01 #define SPRI_RC 0x02 #define SPRI_RS 0x03 - u_int8_t reserved[5]; - u_int8_t length[2]; + uint8_t reserved[5]; + uint8_t length[2]; #define SPRI_MAX_LEN 0xffff - u_int8_t control; + uint8_t control; }; struct scsi_per_res_in_header { - u_int8_t generation[4]; - u_int8_t length[4]; + uint8_t generation[4]; + uint8_t length[4]; }; struct scsi_per_res_key { - u_int8_t key[8]; + uint8_t key[8]; }; struct scsi_per_res_in_keys @@ -396,8 +396,8 @@ struct scsi_per_res_in_full struct scsi_per_res_out { - u_int8_t opcode; - u_int8_t action; + uint8_t opcode; + uint8_t action; #define SPRO_REGISTER 0x00 #define SPRO_RESERVE 0x01 #define SPRO_RELEASE 0x02 @@ -408,7 +408,7 @@ struct scsi_per_res_out #define SPRO_REG_MOVE 0x07 #define SPRO_REPL_LOST_RES 0x08 #define SPRO_ACTION_MASK 0x1f - u_int8_t scope_type; + uint8_t scope_type; #define SPR_SCOPE_MASK 0xf0 #define SPR_SCOPE_SHIFT 4 #define SPR_LU_SCOPE 0x00 @@ -424,28 +424,28 @@ struct scsi_per_res_out #define SPR_TYPE_EX_AC_RO 0x06 #define SPR_TYPE_WR_EX_AR 0x07 #define SPR_TYPE_EX_AC_AR 0x08 - u_int8_t reserved[2]; - u_int8_t length[4]; - u_int8_t control; + uint8_t reserved[2]; + uint8_t length[4]; + uint8_t control; }; struct scsi_per_res_out_parms { struct scsi_per_res_key res_key; - u_int8_t serv_act_res_key[8]; - u_int8_t scope_spec_address[4]; - u_int8_t flags; + uint8_t serv_act_res_key[8]; + uint8_t scope_spec_address[4]; + uint8_t flags; #define SPR_SPEC_I_PT 0x08 #define SPR_ALL_TG_PT 0x04 #define SPR_APTPL 0x01 - u_int8_t reserved1; - u_int8_t extent_length[2]; - u_int8_t transport_id_list[]; + uint8_t reserved1; + uint8_t extent_length[2]; + uint8_t transport_id_list[]; }; struct scsi_per_res_out_trans_ids { - u_int8_t additional_length[4]; - u_int8_t transport_ids[]; + uint8_t additional_length[4]; + uint8_t transport_ids[]; }; /* @@ -455,14 +455,14 @@ struct scsi_per_res_out_trans_ids { struct scsi_per_res_reg_move { struct scsi_per_res_key res_key; - u_int8_t serv_act_res_key[8]; - u_int8_t reserved; - u_int8_t flags; + uint8_t serv_act_res_key[8]; + uint8_t reserved; + uint8_t flags; #define SPR_REG_MOVE_UNREG 0x02 #define SPR_REG_MOVE_APTPL 0x01 - u_int8_t rel_trgt_port_id[2]; - u_int8_t transport_id_length[4]; - u_int8_t transport_id[]; + uint8_t rel_trgt_port_id[2]; + uint8_t transport_id_length[4]; + uint8_t transport_id[]; }; struct scsi_transportid_header @@ -569,11 +569,11 @@ struct scsi_transportid_sop struct scsi_log_sense { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define SLS_SP 0x01 #define SLS_PPC 0x02 - u_int8_t page; + uint8_t page; #define SLS_PAGE_CODE 0x3F #define SLS_SUPPORTED_PAGES_PAGE 0x00 #define SLS_OVERRUN_PAGE 0x01 @@ -594,44 +594,44 @@ struct scsi_log_sense #define SLS_PAGE_CTRL_CUMULATIVE 0x40 #define SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 #define SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 - u_int8_t subpage; + uint8_t subpage; #define SLS_SUPPORTED_SUBPAGES_SUBPAGE 0xff - u_int8_t reserved; - u_int8_t paramptr[2]; - u_int8_t length[2]; - u_int8_t control; + uint8_t reserved; + uint8_t paramptr[2]; + uint8_t length[2]; + uint8_t control; }; struct scsi_log_select { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; /* SLS_SP 0x01 */ #define SLS_PCR 0x02 - u_int8_t page; + uint8_t page; /* SLS_PAGE_CTRL_MASK 0xC0 */ /* SLS_PAGE_CTRL_THRESHOLD 0x00 */ /* SLS_PAGE_CTRL_CUMULATIVE 0x40 */ /* SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 */ /* SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 */ - u_int8_t reserved[4]; - u_int8_t length[2]; - u_int8_t control; + uint8_t reserved[4]; + uint8_t length[2]; + uint8_t control; }; struct scsi_log_header { - u_int8_t page; + uint8_t page; #define SL_PAGE_CODE 0x3F #define SL_SPF 0x40 #define SL_DS 0x80 - u_int8_t subpage; - u_int8_t datalen[2]; + uint8_t subpage; + uint8_t datalen[2]; }; struct scsi_log_param_header { - u_int8_t param_code[2]; - u_int8_t param_control; + uint8_t param_code[2]; + uint8_t param_control; #define SLP_LP 0x01 #define SLP_LBIN 0x02 #define SLP_TMC_MASK 0x0C @@ -643,7 +643,7 @@ struct scsi_log_param_header { #define SLP_TSD 0x20 #define SLP_DS 0x40 #define SLP_DU 0x80 - u_int8_t param_len; + uint8_t param_len; }; struct scsi_log_media_pct_used { @@ -709,9 +709,9 @@ struct scsi_log_temperature { }; struct scsi_control_page { - u_int8_t page_code; - u_int8_t page_length; - u_int8_t rlec; + uint8_t page_code; + uint8_t page_length; + uint8_t rlec; #define SCP_RLEC 0x01 /*Report Log Exception Cond*/ #define SCP_GLTSD 0x02 /*Global Logging target save disable */ @@ -722,28 +722,28 @@ struct scsi_control_page { #define SCP_TST_MASK 0xE0 /*Task Set Type Mask*/ #define SCP_TST_ONE 0x00 /*One Task Set*/ #define SCP_TST_SEPARATE 0x20 /*Separate Task Sets*/ - u_int8_t queue_flags; + uint8_t queue_flags; #define SCP_QUEUE_ALG_MASK 0xF0 #define SCP_QUEUE_ALG_RESTRICTED 0x00 #define SCP_QUEUE_ALG_UNRESTRICTED 0x10 #define SCP_NUAR 0x08 /*No UA on release*/ #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/ #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/ - u_int8_t eca_and_aen; + uint8_t eca_and_aen; #define SCP_EECA 0x80 /*Enable Extended CA*/ #define SCP_RAC 0x40 /*Report a check*/ #define SCP_SWP 0x08 /*Software Write Protect*/ #define SCP_RAENP 0x04 /*Ready AEN Permission*/ #define SCP_UAAENP 0x02 /*UA AEN Permission*/ #define SCP_EAENP 0x01 /*Error AEN Permission*/ - u_int8_t flags4; + uint8_t flags4; #define SCP_ATO 0x80 /*Application tag owner*/ #define SCP_TAS 0x40 /*Task aborted status*/ #define SCP_ATMPE 0x20 /*Application tag mode page*/ #define SCP_RWWP 0x10 /*Reject write without prot*/ - u_int8_t aen_holdoff_period[2]; - u_int8_t busy_timeout_period[2]; - u_int8_t extended_selftest_completion_time[2]; + uint8_t aen_holdoff_period[2]; + uint8_t busy_timeout_period[2]; + uint8_t extended_selftest_completion_time[2]; }; struct scsi_control_ext_page { @@ -762,18 +762,18 @@ struct scsi_control_ext_page { }; struct scsi_cache_page { - u_int8_t page_code; + uint8_t page_code; #define SCHP_PAGE_SAVABLE 0x80 /* Page is savable */ - u_int8_t page_length; - u_int8_t cache_flags; + uint8_t page_length; + uint8_t cache_flags; #define SCHP_FLAGS_WCE 0x04 /* Write Cache Enable */ #define SCHP_FLAGS_MF 0x02 /* Multiplication factor */ #define SCHP_FLAGS_RCD 0x01 /* Read Cache Disable */ - u_int8_t rw_cache_policy; - u_int8_t dis_prefetch[2]; - u_int8_t min_prefetch[2]; - u_int8_t max_prefetch[2]; - u_int8_t max_prefetch_ceil[2]; + uint8_t rw_cache_policy; + uint8_t dis_prefetch[2]; + uint8_t min_prefetch[2]; + uint8_t max_prefetch[2]; + uint8_t max_prefetch_ceil[2]; }; /* @@ -812,10 +812,10 @@ struct scsi_caching_page { }; struct scsi_info_exceptions_page { - u_int8_t page_code; + uint8_t page_code; #define SIEP_PAGE_SAVABLE 0x80 /* Page is savable */ - u_int8_t page_length; - u_int8_t info_flags; + uint8_t page_length; + uint8_t info_flags; #define SIEP_FLAGS_PERF 0x80 #define SIEP_FLAGS_EBF 0x20 #define SIEP_FLAGS_EWASC 0x10 @@ -823,15 +823,15 @@ struct scsi_info_exceptions_page { #define SIEP_FLAGS_TEST 0x04 #define SIEP_FLAGS_EBACKERR 0x02 #define SIEP_FLAGS_LOGERR 0x01 - u_int8_t mrie; + uint8_t mrie; #define SIEP_MRIE_NO 0x00 #define SIEP_MRIE_UA 0x02 #define SIEP_MRIE_REC_COND 0x03 #define SIEP_MRIE_REC_UNCOND 0x04 #define SIEP_MRIE_NO_SENSE 0x05 #define SIEP_MRIE_ON_REQ 0x06 - u_int8_t interval_timer[4]; - u_int8_t report_count[4]; + uint8_t interval_timer[4]; + uint8_t report_count[4]; }; struct scsi_logical_block_provisioning_page_descr { @@ -875,10 +875,10 @@ struct scsi_logical_block_provisioning_page { #define SCSI_PROTO_NONE 0x0f /* No specific protocol */ struct scsi_proto_specific_page { - u_int8_t page_code; + uint8_t page_code; #define SPSP_PAGE_SAVABLE 0x80 /* Page is savable */ - u_int8_t page_length; - u_int8_t protocol; + uint8_t page_length; + uint8_t protocol; #define SPSP_PROTO_FC SCSI_PROTO_FC #define SPSP_PROTO_SPI SCSI_PROTO_SPI #define SPSP_PROTO_SSA SCSI_PROTO_SSA @@ -895,15 +895,15 @@ struct scsi_proto_specific_page { struct scsi_reserve { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define SR_EXTENT 0x01 #define SR_ID_MASK 0x0e #define SR_3RDPTY 0x10 #define SR_LUN_MASK 0xe0 - u_int8_t resv_id; - u_int8_t length[2]; - u_int8_t control; + uint8_t resv_id; + uint8_t length[2]; + uint8_t control; }; struct scsi_reserve_10 { @@ -921,12 +921,12 @@ struct scsi_reserve_10 { struct scsi_release { - u_int8_t opcode; - u_int8_t byte2; - u_int8_t resv_id; - u_int8_t unused[1]; - u_int8_t length; - u_int8_t control; + uint8_t opcode; + uint8_t byte2; + uint8_t resv_id; + uint8_t unused[1]; + uint8_t length; + uint8_t control; }; struct scsi_release_10 { @@ -941,25 +941,25 @@ struct scsi_release_10 { struct scsi_prevent { - u_int8_t opcode; - u_int8_t byte2; - u_int8_t unused[2]; - u_int8_t how; - u_int8_t control; + uint8_t opcode; + uint8_t byte2; + uint8_t unused[2]; + uint8_t how; + uint8_t control; }; #define PR_PREVENT 0x01 #define PR_ALLOW 0x00 struct scsi_sync_cache { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define SSC_IMMED 0x02 #define SSC_RELADR 0x01 - u_int8_t begin_lba[4]; - u_int8_t reserved; - u_int8_t lb_count[2]; - u_int8_t control; + uint8_t begin_lba[4]; + uint8_t reserved; + uint8_t lb_count[2]; + uint8_t control; }; struct scsi_sync_cache_16 @@ -1011,19 +1011,19 @@ struct scsi_format_header_long { struct scsi_changedef { - u_int8_t opcode; - u_int8_t byte2; - u_int8_t unused1; - u_int8_t how; - u_int8_t unused[4]; - u_int8_t datalen; - u_int8_t control; + uint8_t opcode; + uint8_t byte2; + uint8_t unused1; + uint8_t how; + uint8_t unused[4]; + uint8_t datalen; + uint8_t control; }; struct scsi_read_buffer { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define RWB_MODE 0x1F #define RWB_MODE_HDR_DATA 0x00 #define RWB_MODE_VENDOR 0x01 @@ -1034,10 +1034,10 @@ struct scsi_read_buffer #define RWB_MODE_ECHO 0x0A #define RWB_MODE_ECHO_DESCR 0x0B #define RWB_MODE_ERROR_HISTORY 0x1C - u_int8_t buffer_id; - u_int8_t offset[3]; - u_int8_t length[3]; - u_int8_t control; + uint8_t buffer_id; + uint8_t offset[3]; + uint8_t length[3]; + uint8_t control; }; struct scsi_read_buffer_16 @@ -1052,18 +1052,18 @@ struct scsi_read_buffer_16 struct scsi_write_buffer { - u_int8_t opcode; - u_int8_t byte2; - u_int8_t buffer_id; - u_int8_t offset[3]; - u_int8_t length[3]; - u_int8_t control; + uint8_t opcode; + uint8_t byte2; + uint8_t buffer_id; + uint8_t offset[3]; + uint8_t length[3]; + uint8_t control; }; struct scsi_read_attribute { - u_int8_t opcode; - u_int8_t service_action; + uint8_t opcode; + uint8_t service_action; #define SRA_SA_ATTR_VALUES 0x00 #define SRA_SA_ATTR_LIST 0x01 #define SRA_SA_LOG_VOL_LIST 0x02 @@ -1071,42 +1071,42 @@ struct scsi_read_attribute #define SRA_SA_RESTRICTED 0x04 #define SRA_SA_SUPPORTED_ATTRS 0x05 #define SRA_SA_MASK 0x1f - u_int8_t element[2]; - u_int8_t elem_type; - u_int8_t logical_volume; - u_int8_t reserved1; - u_int8_t partition; - u_int8_t first_attribute[2]; - u_int8_t length[4]; - u_int8_t cache; + uint8_t element[2]; + uint8_t elem_type; + uint8_t logical_volume; + uint8_t reserved1; + uint8_t partition; + uint8_t first_attribute[2]; + uint8_t length[4]; + uint8_t cache; #define SRA_CACHE 0x01 - u_int8_t control; + uint8_t control; }; struct scsi_write_attribute { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define SWA_WTC 0x01 - u_int8_t element[3]; - u_int8_t logical_volume; - u_int8_t reserved1; - u_int8_t partition; - u_int8_t reserved2[2]; - u_int8_t length[4]; - u_int8_t reserved3; - u_int8_t control; + uint8_t element[3]; + uint8_t logical_volume; + uint8_t reserved1; + uint8_t partition; + uint8_t reserved2[2]; + uint8_t length[4]; + uint8_t reserved3; + uint8_t control; }; struct scsi_read_attribute_values { - u_int8_t length[4]; - u_int8_t attribute_0[0]; + uint8_t length[4]; + uint8_t attribute_0[0]; }; struct scsi_mam_attribute_header { - u_int8_t id[2]; + uint8_t id[2]; /* * Attributes obtained from SPC-4r36g (section 7.4.2.2) and * SSC-4r03 (section 4.2.21). @@ -1184,25 +1184,25 @@ struct scsi_mam_attribute_header #define SMA_ATTR_VENDOR_MEDIUM_MAX 0x13ff #define SMA_ATTR_VENDOR_HOST_MIN 0x1400 #define SMA_ATTR_VENDOR_HOST_MAX 0x17ff - u_int8_t byte2; + uint8_t byte2; #define SMA_FORMAT_BINARY 0x00 #define SMA_FORMAT_ASCII 0x01 #define SMA_FORMAT_TEXT 0x02 #define SMA_FORMAT_MASK 0x03 #define SMA_READ_ONLY 0x80 - u_int8_t length[2]; - u_int8_t attribute[0]; + uint8_t length[2]; + uint8_t attribute[0]; }; struct scsi_attrib_list_header { - u_int8_t length[4]; - u_int8_t first_attr_0[0]; + uint8_t length[4]; + uint8_t first_attr_0[0]; }; struct scsi_attrib_lv_list { - u_int8_t length[2]; - u_int8_t first_lv_number; - u_int8_t num_logical_volumes; + uint8_t length[2]; + uint8_t first_lv_number; + uint8_t num_logical_volumes; }; struct scsi_attrib_vendser { @@ -1256,8 +1256,8 @@ struct sbuf; struct scsi_attrib_table_entry { - u_int32_t id; - u_int32_t flags; + uint32_t id; + uint32_t flags; const char *desc; const char *suffix; int (*to_str)(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, @@ -1271,53 +1271,53 @@ struct scsi_attrib_table_entry struct scsi_rw_6 { - u_int8_t opcode; - u_int8_t addr[3]; + uint8_t opcode; + uint8_t addr[3]; /* only 5 bits are valid in the MSB address byte */ #define SRW_TOPADDR 0x1F - u_int8_t length; - u_int8_t control; + uint8_t length; + uint8_t control; }; struct scsi_rw_10 { - u_int8_t opcode; + uint8_t opcode; #define SRW10_RELADDR 0x01 /* EBP defined for WRITE(10) only */ #define SRW10_EBP 0x04 #define SRW10_FUA 0x08 #define SRW10_DPO 0x10 - u_int8_t byte2; - u_int8_t addr[4]; - u_int8_t reserved; - u_int8_t length[2]; - u_int8_t control; + uint8_t byte2; + uint8_t addr[4]; + uint8_t reserved; + uint8_t length[2]; + uint8_t control; }; struct scsi_rw_12 { - u_int8_t opcode; + uint8_t opcode; #define SRW12_RELADDR 0x01 #define SRW12_FUA 0x08 #define SRW12_DPO 0x10 - u_int8_t byte2; - u_int8_t addr[4]; - u_int8_t length[4]; - u_int8_t reserved; - u_int8_t control; + uint8_t byte2; + uint8_t addr[4]; + uint8_t length[4]; + uint8_t reserved; + uint8_t control; }; struct scsi_rw_16 { - u_int8_t opcode; + uint8_t opcode; #define SRW16_RELADDR 0x01 #define SRW16_FUA 0x08 #define SRW16_DPO 0x10 - u_int8_t byte2; - u_int8_t addr[8]; - u_int8_t length[4]; - u_int8_t reserved; - u_int8_t control; + uint8_t byte2; + uint8_t addr[8]; + uint8_t length[4]; + uint8_t reserved; + uint8_t control; }; struct scsi_write_atomic_16 @@ -1416,11 +1416,11 @@ struct scsi_write_verify_16 struct scsi_start_stop_unit { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define SSS_IMMED 0x01 - u_int8_t reserved[2]; - u_int8_t how; + uint8_t reserved[2]; + uint8_t how; #define SSS_START 0x01 #define SSS_LOEJ 0x02 #define SSS_PC_MASK 0xf0 @@ -1431,12 +1431,12 @@ struct scsi_start_stop_unit #define SSS_PC_LU_CONTROL 0x70 #define SSS_PC_FORCE_IDLE_0 0xa0 #define SSS_PC_FORCE_STANDBY_0 0xb0 - u_int8_t control; + uint8_t control; }; struct ata_pass_12 { - u_int8_t opcode; - u_int8_t protocol; + uint8_t opcode; + uint8_t protocol; #define AP_PROTO_HARD_RESET (0x00 << 1) #define AP_PROTO_SRST (0x01 << 1) #define AP_PROTO_NON_DATA (0x03 << 1) @@ -1452,21 +1452,21 @@ struct ata_pass_12 { #define AP_PROTO_RESP_INFO (0x0f << 1) #define AP_PROTO_MASK 0x1e #define AP_MULTI 0xe0 - u_int8_t flags; + uint8_t flags; #define AP_T_LEN 0x03 #define AP_BB 0x04 #define AP_T_DIR 0x08 #define AP_CK_COND 0x20 #define AP_OFFLINE 0x60 - u_int8_t features; - u_int8_t sector_count; - u_int8_t lba_low; - u_int8_t lba_mid; - u_int8_t lba_high; - u_int8_t device; - u_int8_t command; - u_int8_t reserved; - u_int8_t control; + uint8_t features; + uint8_t sector_count; + uint8_t lba_low; + uint8_t lba_mid; + uint8_t lba_high; + uint8_t device; + uint8_t command; + uint8_t reserved; + uint8_t control; }; struct scsi_maintenance_in @@ -2028,10 +2028,10 @@ struct scsi_report_all_rod_tokens_data }; struct ata_pass_16 { - u_int8_t opcode; - u_int8_t protocol; + uint8_t opcode; + uint8_t protocol; #define AP_EXTEND 0x01 - u_int8_t flags; + uint8_t flags; #define AP_FLAG_TLEN_NO_DATA (0 << 0) #define AP_FLAG_TLEN_FEAT (1 << 0) #define AP_FLAG_TLEN_SECT_CNT (2 << 0) @@ -2041,19 +2041,19 @@ struct ata_pass_16 { #define AP_FLAG_TDIR_TO_DEV (0 << 3) #define AP_FLAG_TDIR_FROM_DEV (1 << 3) #define AP_FLAG_CHK_COND (1 << 5) - u_int8_t features_ext; - u_int8_t features; - u_int8_t sector_count_ext; - u_int8_t sector_count; - u_int8_t lba_low_ext; - u_int8_t lba_low; - u_int8_t lba_mid_ext; - u_int8_t lba_mid; - u_int8_t lba_high_ext; - u_int8_t lba_high; - u_int8_t device; - u_int8_t command; - u_int8_t control; + uint8_t features_ext; + uint8_t features; + uint8_t sector_count_ext; + uint8_t sector_count; + uint8_t lba_low_ext; + uint8_t lba_low; + uint8_t lba_mid_ext; + uint8_t lba_mid; + uint8_t lba_high_ext; + uint8_t lba_high; + uint8_t device; + uint8_t command; + uint8_t control; }; struct ata_pass_32 { @@ -2104,7 +2104,6 @@ struct ata_pass_32 { #define WRITE_VERIFY_10 0x2E #define VERIFY_10 0x2F #define SYNCHRONIZE_CACHE 0x35 -#define READ_DEFECT_DATA_10 0x37 #define WRITE_BUFFER 0x3B #define READ_BUFFER 0x3C #define CHANGE_DEFINITION 0x40 @@ -2207,7 +2206,7 @@ struct ata_pass_32 { struct scsi_inquiry_data { - u_int8_t device; + uint8_t device; #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f) #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5) #define SID_QUAL_LU_CONNECTED 0x00 /* @@ -2243,12 +2242,12 @@ struct scsi_inquiry_data * qualifier. */ #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x04) != 0) - u_int8_t dev_qual2; + uint8_t dev_qual2; #define SID_QUAL2 0x7F #define SID_LU_CONG 0x40 #define SID_RMB 0x80 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & SID_RMB) != 0) - u_int8_t version; + uint8_t version; #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07) #define SCSI_REV_0 0 #define SCSI_REV_CCS 1 @@ -2261,16 +2260,16 @@ struct scsi_inquiry_data #define SID_ECMA 0x38 #define SID_ISO 0xC0 - u_int8_t response_format; + uint8_t response_format; #define SID_AENC 0x80 #define SID_TrmIOP 0x40 #define SID_NormACA 0x20 #define SID_HiSup 0x10 - u_int8_t additional_length; + uint8_t additional_length; #define SID_ADDITIONAL_LENGTH(iqd) \ ((iqd)->additional_length + \ __offsetof(struct scsi_inquiry_data, additional_length) + 1) - u_int8_t spc3_flags; + uint8_t spc3_flags; #define SPC3_SID_PROTECT 0x01 #define SPC3_SID_3PC 0x08 #define SPC3_SID_TPGS_MASK 0x30 @@ -2278,7 +2277,7 @@ struct scsi_inquiry_data #define SPC3_SID_TPGS_EXPLICIT 0x20 #define SPC3_SID_ACC 0x40 #define SPC3_SID_SCCS 0x80 - u_int8_t spc2_flags; + uint8_t spc2_flags; #define SPC2_SID_ADDR16 0x01 #define SPC2_SID_MChngr 0x08 #define SPC2_SID_MultiP 0x10 @@ -2290,7 +2289,7 @@ struct scsi_inquiry_data (((iqd)->flags & SID_CmdQue) && !((iqd)->spc2_flags & SPC2_SID_BQueue)) || \ (!((iqd)->flags & SID_CmdQue) && ((iqd)->spc2_flags & SPC2_SID_BQueue))) - u_int8_t flags; + uint8_t flags; #define SID_SftRe 0x01 #define SID_CmdQue 0x02 #define SID_Linked 0x08 @@ -2309,7 +2308,7 @@ struct scsi_inquiry_data * (SPC-2) Revision 14, Dated 11 November 1999 */ #define SID_VENDOR_SPECIFIC_0_SIZE 20 - u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE]; + uint8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE]; /* * An extension of SCSI Parallel Specific Values */ @@ -2319,24 +2318,24 @@ struct scsi_inquiry_data #define SID_SPI_CLOCK_DT 0x04 #define SID_SPI_CLOCK_DT_ST 0x0C #define SID_SPI_MASK 0x0F - u_int8_t spi3data; - u_int8_t reserved2; + uint8_t spi3data; + uint8_t reserved2; /* * Version Descriptors, stored 2 byte values. */ - u_int8_t version1[2]; - u_int8_t version2[2]; - u_int8_t version3[2]; - u_int8_t version4[2]; - u_int8_t version5[2]; - u_int8_t version6[2]; - u_int8_t version7[2]; - u_int8_t version8[2]; + uint8_t version1[2]; + uint8_t version2[2]; + uint8_t version3[2]; + uint8_t version4[2]; + uint8_t version5[2]; + uint8_t version6[2]; + uint8_t version7[2]; + uint8_t version8[2]; - u_int8_t reserved3[22]; + uint8_t reserved3[22]; #define SID_VENDOR_SPECIFIC_1_SIZE 160 - u_int8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE]; + uint8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE]; }; /* @@ -2345,14 +2344,14 @@ struct scsi_inquiry_data */ struct scsi_vpd_supported_page_list { - u_int8_t device; - u_int8_t page_code; + uint8_t device; + uint8_t page_code; #define SVPD_SUPPORTED_PAGE_LIST 0x00 #define SVPD_SUPPORTED_PAGES_HDR_LEN 4 - u_int8_t reserved; - u_int8_t length; /* number of VPD entries */ + uint8_t reserved; + uint8_t length; /* number of VPD entries */ #define SVPD_SUPPORTED_PAGES_SIZE 251 - u_int8_t list[SVPD_SUPPORTED_PAGES_SIZE]; + uint8_t list[SVPD_SUPPORTED_PAGES_SIZE]; }; /* @@ -2361,40 +2360,40 @@ struct scsi_vpd_supported_page_list */ struct scsi_vpd_supported_pages { - u_int8_t device; - u_int8_t page_code; - u_int8_t reserved; + uint8_t device; + uint8_t page_code; + uint8_t reserved; #define SVPD_SUPPORTED_PAGES 0x00 - u_int8_t length; - u_int8_t page_list[0]; + uint8_t length; + uint8_t page_list[0]; }; struct scsi_vpd_unit_serial_number { - u_int8_t device; - u_int8_t page_code; + uint8_t device; + uint8_t page_code; #define SVPD_UNIT_SERIAL_NUMBER 0x80 - u_int8_t reserved; - u_int8_t length; /* serial number length */ + uint8_t reserved; + uint8_t length; /* serial number length */ #define SVPD_SERIAL_NUM_SIZE 251 - u_int8_t serial_num[SVPD_SERIAL_NUM_SIZE]; + uint8_t serial_num[SVPD_SERIAL_NUM_SIZE]; }; struct scsi_vpd_device_id { - u_int8_t device; - u_int8_t page_code; + uint8_t device; + uint8_t page_code; #define SVPD_DEVICE_ID 0x83 #define SVPD_DEVICE_ID_MAX_SIZE 252 #define SVPD_DEVICE_ID_HDR_LEN \ __offsetof(struct scsi_vpd_device_id, desc_list) - u_int8_t length[2]; - u_int8_t desc_list[]; + uint8_t length[2]; + uint8_t desc_list[]; }; struct scsi_vpd_id_descriptor { - u_int8_t proto_codeset; + uint8_t proto_codeset; /* * See the SCSI_PROTO definitions above for the protocols. */ @@ -2403,7 +2402,7 @@ struct scsi_vpd_id_descriptor #define SVPD_ID_CODESET_ASCII 0x02 #define SVPD_ID_CODESET_UTF8 0x03 #define SVPD_ID_CODESET_MASK 0x0f - u_int8_t id_type; + uint8_t id_type; #define SVPD_ID_PIV 0x80 #define SVPD_ID_ASSOC_LUN 0x00 #define SVPD_ID_ASSOC_PORT 0x10 @@ -2421,23 +2420,23 @@ struct scsi_vpd_id_descriptor #define SVPD_ID_TYPE_PROTO 0x09 #define SVPD_ID_TYPE_UUID 0x0a #define SVPD_ID_TYPE_MASK 0x0f - u_int8_t reserved; - u_int8_t length; + uint8_t reserved; + uint8_t length; #define SVPD_DEVICE_ID_DESC_HDR_LEN \ __offsetof(struct scsi_vpd_id_descriptor, identifier) - u_int8_t identifier[]; + uint8_t identifier[]; }; struct scsi_vpd_id_t10 { - u_int8_t vendor[8]; - u_int8_t vendor_spec_id[0]; + uint8_t vendor[8]; + uint8_t vendor_spec_id[0]; }; struct scsi_vpd_id_eui64 { - u_int8_t ieee_company_id[3]; - u_int8_t extension_id[5]; + uint8_t ieee_company_id[3]; + uint8_t extension_id[5]; }; struct scsi_vpd_id_naa_basic @@ -2656,10 +2655,10 @@ struct scsi_vpd_port_designation_cont struct scsi_vpd_scsi_ports { - u_int8_t device; - u_int8_t page_code; + uint8_t device; + uint8_t page_code; #define SVPD_SCSI_PORTS 0x88 - u_int8_t page_length[2]; + uint8_t page_length[2]; struct scsi_vpd_port_designation design[]; }; @@ -2863,23 +2862,23 @@ _Static_assert(sizeof(struct scsi_vpd_block_device_characteristics) == 64, */ struct scsi_vpd_logical_block_prov { - u_int8_t device; - u_int8_t page_code; + uint8_t device; + uint8_t page_code; #define SVPD_LBP 0xB2 - u_int8_t page_length[2]; + uint8_t page_length[2]; #define SVPD_LBP_PL_BASIC 0x04 - u_int8_t threshold_exponent; - u_int8_t flags; + uint8_t threshold_exponent; + uint8_t flags; #define SVPD_LBP_UNMAP 0x80 #define SVPD_LBP_WS16 0x40 #define SVPD_LBP_WS10 0x20 #define SVPD_LBP_RZ 0x04 #define SVPD_LBP_ANC_SUP 0x02 #define SVPD_LBP_DP 0x01 - u_int8_t prov_type; + uint8_t prov_type; #define SVPD_LBP_RESOURCE 0x01 #define SVPD_LBP_THIN 0x02 - u_int8_t reserved; + uint8_t reserved; /* * Provisioning Group Descriptor can be here if SVPD_LBP_DP is set * Its size can be determined from page_length - 4 @@ -2891,29 +2890,29 @@ struct scsi_vpd_logical_block_prov */ struct scsi_vpd_block_limits { - u_int8_t device; - u_int8_t page_code; + uint8_t device; + uint8_t page_code; #define SVPD_BLOCK_LIMITS 0xB0 - u_int8_t page_length[2]; + uint8_t page_length[2]; #define SVPD_BL_PL_BASIC 0x10 #define SVPD_BL_PL_TP 0x3C - u_int8_t flags; + uint8_t flags; #define SVPD_BL_WSNZ 0x01 - u_int8_t max_cmp_write_len; - u_int8_t opt_txfer_len_grain[2]; - u_int8_t max_txfer_len[4]; - u_int8_t opt_txfer_len[4]; - u_int8_t max_prefetch[4]; - u_int8_t max_unmap_lba_cnt[4]; - u_int8_t max_unmap_blk_cnt[4]; - u_int8_t opt_unmap_grain[4]; - u_int8_t unmap_grain_align[4]; - u_int8_t max_write_same_length[8]; - u_int8_t max_atomic_transfer_length[4]; - u_int8_t atomic_alignment[4]; - u_int8_t atomic_transfer_length_granularity[4]; - u_int8_t max_atomic_transfer_length_with_atomic_boundary[4]; - u_int8_t max_atomic_boundary_size[4]; + uint8_t max_cmp_write_len; + uint8_t opt_txfer_len_grain[2]; + uint8_t max_txfer_len[4]; + uint8_t opt_txfer_len[4]; + uint8_t max_prefetch[4]; + uint8_t max_unmap_lba_cnt[4]; + uint8_t max_unmap_blk_cnt[4]; + uint8_t opt_unmap_grain[4]; + uint8_t unmap_grain_align[4]; + uint8_t max_write_same_length[8]; + uint8_t max_atomic_transfer_length[4]; + uint8_t atomic_alignment[4]; + uint8_t atomic_transfer_length_granularity[4]; + uint8_t max_atomic_transfer_length_with_atomic_boundary[4]; + uint8_t max_atomic_boundary_size[4]; }; /* @@ -2940,14 +2939,14 @@ struct scsi_vpd_zoned_bdc { struct scsi_read_capacity { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define SRC_RELADR 0x01 - u_int8_t addr[4]; - u_int8_t unused[2]; - u_int8_t pmi; + uint8_t addr[4]; + uint8_t unused[2]; + uint8_t pmi; #define SRC_PMI 0x01 - u_int8_t control; + uint8_t control; }; struct scsi_read_capacity_16 @@ -2965,8 +2964,8 @@ struct scsi_read_capacity_16 struct scsi_read_capacity_data { - u_int8_t addr[4]; - u_int8_t length[4]; + uint8_t addr[4]; + uint8_t length[4]; }; struct scsi_read_capacity_data_long @@ -3061,8 +3060,8 @@ struct scsi_report_luns_lundata { }; struct scsi_report_luns_data { - u_int8_t length[4]; /* length of LUN inventory, in bytes */ - u_int8_t reserved[4]; /* unused */ + uint8_t length[4]; /* length of LUN inventory, in bytes */ + uint8_t reserved[4]; /* unused */ /* * LUN inventory- we only support the type zero form for now. */ @@ -3298,13 +3297,13 @@ struct scsi_sense_data */ struct scsi_sense_data_fixed { - u_int8_t error_code; + uint8_t error_code; #define SSD_ERRCODE 0x7F #define SSD_CURRENT_ERROR 0x70 #define SSD_DEFERRED_ERROR 0x71 #define SSD_ERRCODE_VALID 0x80 - u_int8_t segment; - u_int8_t flags; + uint8_t segment; + uint8_t flags; #define SSD_KEY 0x0F #define SSD_KEY_NO_SENSE 0x00 #define SSD_KEY_RECOVERED_ERROR 0x01 @@ -3326,18 +3325,18 @@ struct scsi_sense_data_fixed #define SSD_ILI 0x20 #define SSD_EOM 0x40 #define SSD_FILEMARK 0x80 - u_int8_t info[4]; - u_int8_t extra_len; - u_int8_t cmd_spec_info[4]; - u_int8_t add_sense_code; - u_int8_t add_sense_code_qual; - u_int8_t fru; - u_int8_t sense_key_spec[3]; + uint8_t info[4]; + uint8_t extra_len; + uint8_t cmd_spec_info[4]; + uint8_t add_sense_code; + uint8_t add_sense_code_qual; + uint8_t fru; + uint8_t sense_key_spec[3]; #define SSD_SCS_VALID 0x80 #define SSD_FIELDPTR_CMD 0x40 #define SSD_BITPTR_VALID 0x08 #define SSD_BITPTR_VALUE 0x07 - u_int8_t extra_bytes[14]; + uint8_t extra_bytes[14]; #define SSD_FIXED_IS_PRESENT(sense, length, field) \ ((length >= (offsetof(struct scsi_sense_data_fixed, field) + \ sizeof(sense->field))) ? 1 :0) @@ -3674,30 +3673,30 @@ struct scsi_sense_vendor struct scsi_mode_header_6 { - u_int8_t data_length; /* Sense data length */ - u_int8_t medium_type; - u_int8_t dev_spec; - u_int8_t blk_desc_len; + uint8_t data_length; /* Sense data length */ + uint8_t medium_type; + uint8_t dev_spec; + uint8_t blk_desc_len; }; struct scsi_mode_header_10 { - u_int8_t data_length[2];/* Sense data length */ - u_int8_t medium_type; - u_int8_t dev_spec; - u_int8_t flags; + uint8_t data_length[2];/* Sense data length */ + uint8_t medium_type; + uint8_t dev_spec; + uint8_t flags; #define SMH_LONGLBA 0x01 - u_int8_t unused; - u_int8_t blk_desc_len[2]; + uint8_t unused; + uint8_t blk_desc_len[2]; }; struct scsi_mode_page_header { - u_int8_t page_code; + uint8_t page_code; #define SMPH_PS 0x80 #define SMPH_SPF 0x40 #define SMPH_PC_MASK 0x3f - u_int8_t page_length; + uint8_t page_length; }; struct scsi_mode_page_header_sp @@ -3709,10 +3708,10 @@ struct scsi_mode_page_header_sp struct scsi_mode_blk_desc { - u_int8_t density; - u_int8_t nblocks[3]; - u_int8_t reserved; - u_int8_t blklen[3]; + uint8_t density; + uint8_t nblocks[3]; + uint8_t reserved; + uint8_t blklen[3]; }; #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */ @@ -3734,8 +3733,8 @@ struct scsi_mode_blk_desc #define SCSI_STATUS_TASK_ABORTED 0x40 struct scsi_inquiry_pattern { - u_int8_t type; - u_int8_t media_type; + uint8_t type; + uint8_t media_type; #define SIP_MEDIA_REMOVABLE 0x01 #define SIP_MEDIA_FIXED 0x02 const char *vendor; @@ -3744,8 +3743,8 @@ struct scsi_inquiry_pattern { }; struct scsi_static_inquiry_pattern { - u_int8_t type; - u_int8_t media_type; + uint8_t type; + uint8_t media_type; char vendor[SID_VENDOR_SIZE+1]; char product[SID_PRODUCT_SIZE+1]; char revision[SID_REVISION_SIZE+1]; @@ -3760,21 +3759,21 @@ struct scsi_sense_quirk_entry { }; struct sense_key_table_entry { - u_int8_t sense_key; - u_int32_t action; + uint8_t sense_key; + uint32_t action; const char *desc; }; struct asc_table_entry { - u_int8_t asc; - u_int8_t ascq; - u_int32_t action; + uint8_t asc; + uint8_t ascq; + uint32_t action; const char *desc; }; struct op_table_entry { - u_int8_t opcode; - u_int32_t opmask; + uint8_t opcode; + uint32_t opmask; const char *desc; }; @@ -3820,7 +3819,7 @@ void scsi_sense_desc(int sense_key, int asc, int ascq, const char **sense_key_desc, const char **asc_desc); scsi_sense_action scsi_error_action(struct ccb_scsiio* csio, struct scsi_inquiry_data *inq_data, - u_int32_t sense_flags); + uint32_t sense_flags); const char * scsi_status_string(struct ccb_scsiio *csio); void scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len, @@ -3932,11 +3931,11 @@ void scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio, FILE *ofile); #endif /* _KERNEL */ -const char * scsi_op_desc(u_int16_t opcode, +const char * scsi_op_desc(uint16_t opcode, struct scsi_inquiry_data *inq_data); -char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, +char * scsi_cdb_string(uint8_t *cdb_ptr, char *cdb_string, size_t len); -void scsi_cdb_sbuf(u_int8_t *cdb_ptr, struct sbuf *sb); +void scsi_cdb_sbuf(uint8_t *cdb_ptr, struct sbuf *sb); void scsi_print_inquiry(struct scsi_inquiry_data *inq_data); void scsi_print_inquiry_sbuf(struct sbuf *sb, @@ -4079,32 +4078,32 @@ int scsi_attrib_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, size_t num_user_entries, int prefer_user_table, uint32_t output_flags, char *error_str, int error_str_len); -void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_test_unit_ready(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, - u_int8_t sense_len, u_int32_t timeout); + uint8_t tag_action, + uint8_t sense_len, uint32_t timeout); -void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_request_sense(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - void *data_ptr, u_int8_t dxfer_len, - u_int8_t tag_action, u_int8_t sense_len, - u_int32_t timeout); + void *data_ptr, uint8_t dxfer_len, + uint8_t tag_action, uint8_t sense_len, + uint32_t timeout); -void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_inquiry(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t *inq_buf, - u_int32_t inq_len, int evpd, u_int8_t page_code, - u_int8_t sense_len, u_int32_t timeout); + uint8_t tag_action, uint8_t *inq_buf, + uint32_t inq_len, int evpd, uint8_t page_code, + uint8_t sense_len, uint32_t timeout); -void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_mode_sense(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len, uint8_t sense_len, uint32_t timeout); -void scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_mode_sense_len(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len, @@ -4118,48 +4117,48 @@ void scsi_mode_sense_subpage(struct ccb_scsiio *csio, uint8_t *param_buf, uint32_t param_len, int minimum_cmd_size, uint8_t sense_len, uint32_t timeout); -void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_mode_select(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int scsi_page_fmt, - int save_pages, u_int8_t *param_buf, - u_int32_t param_len, u_int8_t sense_len, - u_int32_t timeout); + uint8_t tag_action, int scsi_page_fmt, + int save_pages, uint8_t *param_buf, + uint32_t param_len, uint8_t sense_len, + uint32_t timeout); -void scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_mode_select_len(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int scsi_page_fmt, - int save_pages, u_int8_t *param_buf, - u_int32_t param_len, int minimum_cmd_size, - u_int8_t sense_len, u_int32_t timeout); + uint8_t tag_action, int scsi_page_fmt, + int save_pages, uint8_t *param_buf, + uint32_t param_len, int minimum_cmd_size, + uint8_t sense_len, uint32_t timeout); -void scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_log_sense(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t page_code, - u_int8_t page, int save_pages, int ppc, - u_int32_t paramptr, u_int8_t *param_buf, - u_int32_t param_len, u_int8_t sense_len, - u_int32_t timeout); + uint8_t tag_action, uint8_t page_code, + uint8_t page, int save_pages, int ppc, + uint32_t paramptr, uint8_t *param_buf, + uint32_t param_len, uint8_t sense_len, + uint32_t timeout); -void scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_log_select(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, - union ccb *), u_int8_t tag_action, - u_int8_t page_code, int save_pages, - int pc_reset, u_int8_t *param_buf, - u_int32_t param_len, u_int8_t sense_len, - u_int32_t timeout); + union ccb *), uint8_t tag_action, + uint8_t page_code, int save_pages, + int pc_reset, uint8_t *param_buf, + uint32_t param_len, uint8_t sense_len, + uint32_t timeout); -void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_prevent(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t action, - u_int8_t sense_len, u_int32_t timeout); + uint8_t tag_action, uint8_t action, + uint8_t sense_len, uint32_t timeout); -void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_read_capacity(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, - union ccb *), u_int8_t tag_action, + union ccb *), uint8_t tag_action, struct scsi_read_capacity_data *, - u_int8_t sense_len, u_int32_t timeout); + uint8_t sense_len, uint32_t timeout); void scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, @@ -4167,53 +4166,53 @@ void scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries, uint8_t *rcap_buf, int rcap_buf_len, uint8_t sense_len, uint32_t timeout); -void scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_report_luns(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, - union ccb *), u_int8_t tag_action, - u_int8_t select_report, + union ccb *), uint8_t tag_action, + uint8_t select_report, struct scsi_report_luns_data *rpl_buf, - u_int32_t alloc_len, u_int8_t sense_len, - u_int32_t timeout); + uint32_t alloc_len, uint8_t sense_len, + uint32_t timeout); -void scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_report_target_group(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, - union ccb *), u_int8_t tag_action, - u_int8_t pdf, + union ccb *), uint8_t tag_action, + uint8_t pdf, void *buf, - u_int32_t alloc_len, u_int8_t sense_len, - u_int32_t timeout); + uint32_t alloc_len, uint8_t sense_len, + uint32_t timeout); -void scsi_report_timestamp(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_report_timestamp(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, - union ccb *), u_int8_t tag_action, - u_int8_t pdf, + union ccb *), uint8_t tag_action, + uint8_t pdf, void *buf, - u_int32_t alloc_len, u_int8_t sense_len, - u_int32_t timeout); + uint32_t alloc_len, uint8_t sense_len, + uint32_t timeout); -void scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_set_target_group(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, - union ccb *), u_int8_t tag_action, void *buf, - u_int32_t alloc_len, u_int8_t sense_len, - u_int32_t timeout); + union ccb *), uint8_t tag_action, void *buf, + uint32_t alloc_len, uint8_t sense_len, + uint32_t timeout); void scsi_create_timestamp(uint8_t *timestamp_6b_buf, uint64_t timestamp); -void scsi_set_timestamp(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_set_timestamp(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, - union ccb *), u_int8_t tag_action, - void *buf, u_int32_t alloc_len, - u_int8_t sense_len, u_int32_t timeout); + union ccb *), uint8_t tag_action, + void *buf, uint32_t alloc_len, + uint8_t sense_len, uint32_t timeout); void scsi_synchronize_cache(struct ccb_scsiio *csio, - u_int32_t retries, + uint32_t retries, void (*cbfcnp)(struct cam_periph *, - union ccb *), u_int8_t tag_action, - u_int32_t begin_lba, u_int16_t lb_count, - u_int8_t sense_len, u_int32_t timeout); + union ccb *), uint8_t tag_action, + uint32_t begin_lba, uint16_t lb_count, + uint8_t sense_len, uint32_t timeout); -void scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_receive_diagnostic_results(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*), uint8_t tag_action, int pcv, @@ -4221,7 +4220,7 @@ void scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries, uint16_t allocation_length, uint8_t sense_len, uint32_t timeout); -void scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_send_diagnostic(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, int unit_offline, int device_offline, int self_test, int page_format, @@ -4229,35 +4228,35 @@ void scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries, uint16_t param_list_length, uint8_t sense_len, uint32_t timeout); -void scsi_get_physical_element_status(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_get_physical_element_status(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, uint8_t *data_ptr, uint16_t allocation_length, uint8_t report_type, uint32_t starting_element, uint8_t sense_len, uint32_t timeout); -void scsi_remove_element_and_truncate(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_remove_element_and_truncate(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, uint64_t requested_capacity, uint32_t element_id, uint8_t sense_len, uint32_t timeout); -void scsi_restore_elements_and_rebuild(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_restore_elements_and_rebuild(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, uint8_t sense_len, uint32_t timeout); -void scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_read_buffer(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*), uint8_t tag_action, int mode, - uint8_t buffer_id, u_int32_t offset, + uint8_t buffer_id, uint32_t offset, uint8_t *data_ptr, uint32_t allocation_length, uint8_t sense_len, uint32_t timeout); -void scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_write_buffer(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, int mode, - uint8_t buffer_id, u_int32_t offset, + uint8_t buffer_id, uint32_t offset, uint8_t *data_ptr, uint32_t param_list_length, uint8_t sense_len, uint32_t timeout); @@ -4265,33 +4264,33 @@ void scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries, #define SCSI_RW_WRITE 0x0002 #define SCSI_RW_DIRMASK 0x0003 #define SCSI_RW_BIO 0x1000 -void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_read_write(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int readop, u_int8_t byte2, - int minimum_cmd_size, u_int64_t lba, - u_int32_t block_count, u_int8_t *data_ptr, - u_int32_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout); + uint8_t tag_action, int readop, uint8_t byte2, + int minimum_cmd_size, uint64_t lba, + uint32_t block_count, uint8_t *data_ptr, + uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout); -void scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_write_same(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t byte2, - int minimum_cmd_size, u_int64_t lba, - u_int32_t block_count, u_int8_t *data_ptr, - u_int32_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout); + uint8_t tag_action, uint8_t byte2, + int minimum_cmd_size, uint64_t lba, + uint32_t block_count, uint8_t *data_ptr, + uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout); -void scsi_ata_identify(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_ata_identify(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t *data_ptr, - u_int16_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout); + uint8_t tag_action, uint8_t *data_ptr, + uint16_t dxfer_len, uint8_t sense_len, + uint32_t timeout); -void scsi_ata_trim(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_ata_trim(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int16_t block_count, - u_int8_t *data_ptr, u_int16_t dxfer_len, - u_int8_t sense_len, u_int32_t timeout); + uint8_t tag_action, uint16_t block_count, + uint8_t *data_ptr, uint16_t dxfer_len, + uint8_t sense_len, uint32_t timeout); int scsi_ata_read_log(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), @@ -4312,40 +4311,40 @@ int scsi_ata_pass(struct ccb_scsiio *csio, uint32_t retries, uint8_t protocol, uint8_t ata_flags, uint16_t features, uint16_t sector_count, uint64_t lba, uint8_t command, uint8_t device, uint8_t icc, uint32_t auxiliary, - uint8_t control, u_int8_t *data_ptr, uint32_t dxfer_len, + uint8_t control, uint8_t *data_ptr, uint32_t dxfer_len, uint8_t *cdb_storage, size_t cdb_storage_len, - int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout); + int minimum_cmd_size, uint8_t sense_len, uint32_t timeout); -void scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_ata_pass_16(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int32_t flags, u_int8_t tag_action, - u_int8_t protocol, u_int8_t ata_flags, u_int16_t features, - u_int16_t sector_count, uint64_t lba, u_int8_t command, - u_int8_t control, u_int8_t *data_ptr, u_int16_t dxfer_len, - u_int8_t sense_len, u_int32_t timeout); + uint32_t flags, uint8_t tag_action, + uint8_t protocol, uint8_t ata_flags, uint16_t features, + uint16_t sector_count, uint64_t lba, uint8_t command, + uint8_t control, uint8_t *data_ptr, uint16_t dxfer_len, + uint8_t sense_len, uint32_t timeout); -void scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_unmap(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t byte2, - u_int8_t *data_ptr, u_int16_t dxfer_len, - u_int8_t sense_len, u_int32_t timeout); + uint8_t tag_action, uint8_t byte2, + uint8_t *data_ptr, uint16_t dxfer_len, + uint8_t sense_len, uint32_t timeout); -void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_start_stop(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int start, int load_eject, - int immediate, u_int8_t sense_len, u_int32_t timeout); -void scsi_read_attribute(struct ccb_scsiio *csio, u_int32_t retries, + uint8_t tag_action, int start, int load_eject, + int immediate, uint8_t sense_len, uint32_t timeout); +void scsi_read_attribute(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t service_action, - uint32_t element, u_int8_t elem_type, + uint8_t tag_action, uint8_t service_action, + uint32_t element, uint8_t elem_type, int logical_volume, int partition, - u_int32_t first_attribute, int cache, u_int8_t *data_ptr, - u_int32_t length, int sense_len, u_int32_t timeout); -void scsi_write_attribute(struct ccb_scsiio *csio, u_int32_t retries, + uint32_t first_attribute, int cache, uint8_t *data_ptr, + uint32_t length, int sense_len, uint32_t timeout); +void scsi_write_attribute(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, uint32_t element, - int logical_volume, int partition, int wtc, u_int8_t *data_ptr, - u_int32_t length, int sense_len, u_int32_t timeout); + uint8_t tag_action, uint32_t element, + int logical_volume, int partition, int wtc, uint8_t *data_ptr, + uint32_t length, int sense_len, uint32_t timeout); void scsi_security_protocol_in(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), @@ -4404,7 +4403,7 @@ int scsi_get_ascq(struct scsi_sense_data *sense, u_int sense_len, int show_errors); static __inline void -scsi_ulto2b(u_int32_t val, u_int8_t *bytes) +scsi_ulto2b(uint32_t val, uint8_t *bytes) { bytes[0] = (val >> 8) & 0xff; @@ -4412,7 +4411,7 @@ scsi_ulto2b(u_int32_t val, u_int8_t *bytes) } static __inline void -scsi_ulto3b(u_int32_t val, u_int8_t *bytes) +scsi_ulto3b(uint32_t val, uint8_t *bytes) { bytes[0] = (val >> 16) & 0xff; @@ -4421,7 +4420,7 @@ scsi_ulto3b(u_int32_t val, u_int8_t *bytes) } static __inline void -scsi_ulto4b(u_int32_t val, u_int8_t *bytes) +scsi_ulto4b(uint32_t val, uint8_t *bytes) { bytes[0] = (val >> 24) & 0xff; @@ -4431,7 +4430,7 @@ scsi_ulto4b(u_int32_t val, u_int8_t *bytes) } static __inline void -scsi_u64to8b(u_int64_t val, u_int8_t *bytes) +scsi_u64to8b(uint64_t val, uint8_t *bytes) { bytes[0] = (val >> 56) & 0xff; @@ -4513,7 +4512,7 @@ find_mode_page_6(struct scsi_mode_header_6 *mode_header) { void *page_start; - page_start = (void *)((u_int8_t *)&mode_header[1] + + page_start = (void *)((uint8_t *)&mode_header[1] + mode_header->blk_desc_len); return(page_start); @@ -4524,7 +4523,7 @@ find_mode_page_10(struct scsi_mode_header_10 *mode_header) { void *page_start; - page_start = (void *)((u_int8_t *)&mode_header[1] + + page_start = (void *)((uint8_t *)&mode_header[1] + scsi_2btoul(mode_header->blk_desc_len)); return(page_start); diff --git a/sys/cam/scsi/scsi_cd.c b/sys/cam/scsi/scsi_cd.c index 1618aa3fb500..540419d4f153 100644 --- a/sys/cam/scsi/scsi_cd.c +++ b/sys/cam/scsi/scsi_cd.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997 Justin T. Gibbs. * Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 Kenneth D. Merry. @@ -47,9 +47,6 @@ * from: cd.c,v 1.83 1997/05/04 15:24:22 joerg Exp $ */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include "opt_cd.h" #include <sys/param.h> @@ -83,7 +80,7 @@ __FBSDID("$FreeBSD$"); #define LEADOUT 0xaa /* leadout toc entry */ struct cd_params { - u_int32_t blksize; + uint32_t blksize; u_long disksize; }; @@ -251,53 +248,50 @@ static periph_ctor_t cdregister; static periph_dtor_t cdcleanup; static periph_start_t cdstart; static periph_oninv_t cdoninvalidate; -static void cdasync(void *callback_arg, u_int32_t code, +static void cdasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg); static int cdcmdsizesysctl(SYSCTL_HANDLER_ARGS); static int cdrunccb(union ccb *ccb, int (*error_routine)(union ccb *ccb, - u_int32_t cam_flags, - u_int32_t sense_flags), - u_int32_t cam_flags, u_int32_t sense_flags); + uint32_t cam_flags, + uint32_t sense_flags), + uint32_t cam_flags, uint32_t sense_flags); static void cddone(struct cam_periph *periph, union ccb *start_ccb); static union cd_pages *cdgetpage(struct cd_mode_params *mode_params); static int cdgetpagesize(int page_num); static void cdprevent(struct cam_periph *periph, int action); static void cdmediaprobedone(struct cam_periph *periph); -static int cdcheckmedia(struct cam_periph *periph, int do_wait); -#if 0 -static int cdsize(struct cam_periph *periph, u_int32_t *size); -#endif +static int cdcheckmedia(struct cam_periph *periph, bool do_wait); static int cd6byteworkaround(union ccb *ccb); -static int cderror(union ccb *ccb, u_int32_t cam_flags, - u_int32_t sense_flags); -static int cdreadtoc(struct cam_periph *periph, u_int32_t mode, - u_int32_t start, u_int8_t *data, - u_int32_t len, u_int32_t sense_flags); +static int cderror(union ccb *ccb, uint32_t cam_flags, + uint32_t sense_flags); +static int cdreadtoc(struct cam_periph *periph, uint32_t mode, + uint32_t start, uint8_t *data, + uint32_t len, uint32_t sense_flags); static int cdgetmode(struct cam_periph *periph, - struct cd_mode_params *data, u_int32_t page); + struct cd_mode_params *data, uint32_t page); static int cdsetmode(struct cam_periph *periph, struct cd_mode_params *data); -static int cdplay(struct cam_periph *periph, u_int32_t blk, - u_int32_t len); +static int cdplay(struct cam_periph *periph, uint32_t blk, + uint32_t len); static int cdreadsubchannel(struct cam_periph *periph, - u_int32_t mode, u_int32_t format, + uint32_t mode, uint32_t format, int track, struct cd_sub_channel_info *data, - u_int32_t len); -static int cdplaymsf(struct cam_periph *periph, u_int32_t startm, - u_int32_t starts, u_int32_t startf, - u_int32_t endm, u_int32_t ends, - u_int32_t endf); + uint32_t len); +static int cdplaymsf(struct cam_periph *periph, uint32_t startm, + uint32_t starts, uint32_t startf, + uint32_t endm, uint32_t ends, + uint32_t endf); static int cdplaytracks(struct cam_periph *periph, - u_int32_t strack, u_int32_t sindex, - u_int32_t etrack, u_int32_t eindex); -static int cdpause(struct cam_periph *periph, u_int32_t go); -static int cdstopunit(struct cam_periph *periph, u_int32_t eject); + uint32_t strack, uint32_t sindex, + uint32_t etrack, uint32_t eindex); +static int cdpause(struct cam_periph *periph, uint32_t go); +static int cdstopunit(struct cam_periph *periph, uint32_t eject); static int cdstartunit(struct cam_periph *periph, int load); static int cdsetspeed(struct cam_periph *periph, - u_int32_t rdspeed, u_int32_t wrspeed); + uint32_t rdspeed, uint32_t wrspeed); static int cdreportkey(struct cam_periph *periph, struct dvd_authinfo *authinfo); static int cdsendkey(struct cam_periph *periph, @@ -414,7 +408,7 @@ cdcleanup(struct cam_periph *periph) } static void -cdasync(void *callback_arg, u_int32_t code, +cdasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg) { struct cam_periph *periph; @@ -650,10 +644,10 @@ cdregister(struct cam_periph *periph, void *arg) softc->minimum_command_size = 6; /* - * Refcount and block open attempts until we are setup - * Can't block + * Take a reference on the periph while cdstart is called to finish the + * probe. The reference will be dropped in cddone at the end of probe. */ - (void)cam_periph_hold(periph, PRIBIO); + (void)cam_periph_acquire(periph); cam_periph_unlock(periph); /* * Load the user's default, if any. @@ -714,20 +708,6 @@ cdregister(struct cam_periph *periph, void *arg) softc->disk->d_hba_subdevice = cpi.hba_subdevice; snprintf(softc->disk->d_attachment, sizeof(softc->disk->d_attachment), "%s%d", cpi.dev_name, cpi.unit_number); - - /* - * Acquire a reference to the periph before we register with GEOM. - * We'll release this reference once GEOM calls us back (via - * dadiskgonecb()) telling us that our provider has been freed. - */ - if (cam_periph_acquire(periph) != 0) { - xpt_print(periph->path, "%s: lost periph during " - "registration!\n", __func__); - cam_periph_lock(periph); - return (CAM_REQ_CMP_ERR); - } - - disk_create(softc->disk, DISK_VERSION); cam_periph_lock(periph); /* @@ -748,6 +728,9 @@ cdregister(struct cam_periph *periph, void *arg) 0, cdmediapoll, periph, C_PREL(1)); } + /* Released after probe when disk_create() call pass it to GEOM. */ + cam_periph_hold_boot(periph); + xpt_schedule(periph, CAM_PRIORITY_DEV); return(CAM_REQ_CMP); } @@ -787,7 +770,7 @@ cdopen(struct disk *dp) * if we don't have media, but then we don't allow anything but the * CDIOCEJECT/CDIOCCLOSE ioctls if there is no media. */ - cdcheckmedia(periph, /*do_wait*/ 1); + cdcheckmedia(periph, /*do_wait*/ true); CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("leaving cdopen\n")); cam_periph_unhold(periph); @@ -839,9 +822,9 @@ cdclose(struct disk *dp) static int cdrunccb(union ccb *ccb, int (*error_routine)(union ccb *ccb, - u_int32_t cam_flags, - u_int32_t sense_flags), - u_int32_t cam_flags, u_int32_t sense_flags) + uint32_t cam_flags, + uint32_t sense_flags), + uint32_t cam_flags, uint32_t sense_flags) { struct cd_softc *softc; struct cam_periph *periph; @@ -893,7 +876,7 @@ cdstrategy(struct bio *bp) * check first. The I/O will get executed after the media check. */ if ((softc->flags & CD_FLAG_VALID_MEDIA) == 0) - cdcheckmedia(periph, /*do_wait*/ 0); + cdcheckmedia(periph, /*do_wait*/ false); else xpt_schedule(periph, CAM_PRIORITY_NORMAL); @@ -1385,7 +1368,16 @@ cddone(struct cam_periph *periph, union ccb *done_ccb) * operation. */ xpt_release_ccb(done_ccb); - cam_periph_unhold(periph); + + /* + * We'll release this reference once GEOM calls us back via + * cddiskgonecb(), telling us that our provider has been freed. + */ + if (cam_periph_acquire(periph) == 0) + disk_create(softc->disk, DISK_VERSION); + + cam_periph_release_boot(periph); + cam_periph_release_locked(periph); return; } case CD_CCB_TUR: @@ -1786,7 +1778,7 @@ cdioctl(struct disk *dp, u_long cmd, void *addr, int flag, struct thread *td) && ((cmd != CDIOCCLOSE) && (cmd != CDIOCEJECT)) && (IOCGROUP(cmd) == 'c')) { - error = cdcheckmedia(periph, /*do_wait*/ 1); + error = cdcheckmedia(periph, /*do_wait*/ true); if (error != 0) { cam_periph_unhold(periph); cam_periph_unlock(periph); @@ -1973,7 +1965,7 @@ cdioctl(struct disk *dp, u_long cmd, void *addr, int flag, struct thread *td) struct ioc_read_subchannel *args = (struct ioc_read_subchannel *) addr; struct cd_sub_channel_info *data; - u_int32_t len = args->data_len; + uint32_t len = args->data_len; data = malloc(sizeof(struct cd_sub_channel_info), M_SCSICD, M_WAITOK | M_ZERO); @@ -2028,7 +2020,7 @@ cdioctl(struct disk *dp, u_long cmd, void *addr, int flag, struct thread *td) CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE, ("trying to do CDIOREADTOCHEADER\n")); - error = cdreadtoc(periph, 0, 0, (u_int8_t *)th, + error = cdreadtoc(periph, 0, 0, (uint8_t *)th, sizeof (*th), /*sense_flags*/SF_NO_PRINT); if (error) { free(th, M_SCSICD); @@ -2059,8 +2051,8 @@ cdioctl(struct disk *dp, u_long cmd, void *addr, int flag, struct thread *td) struct ioc_read_toc_entry *te = (struct ioc_read_toc_entry *) addr; struct ioc_toc_header *th; - u_int32_t len, readlen, idx, num; - u_int32_t starting_track = te->starting_track; + uint32_t len, readlen, idx, num; + uint32_t starting_track = te->starting_track; data = malloc(sizeof(*data), M_SCSICD, M_WAITOK | M_ZERO); lead = malloc(sizeof(*lead), M_SCSICD, M_WAITOK | M_ZERO); @@ -2083,7 +2075,7 @@ cdioctl(struct disk *dp, u_long cmd, void *addr, int flag, struct thread *td) } th = &data->header; - error = cdreadtoc(periph, 0, 0, (u_int8_t *)th, + error = cdreadtoc(periph, 0, 0, (uint8_t *)th, sizeof (*th), /*sense_flags*/0); if (error) { free(data, M_SCSICD); @@ -2141,7 +2133,7 @@ cdioctl(struct disk *dp, u_long cmd, void *addr, int flag, struct thread *td) if (readlen > 0) { error = cdreadtoc(periph, te->address_format, starting_track, - (u_int8_t *)data, + (uint8_t *)data, readlen + sizeof (*th), /*sense_flags*/0); if (error) { @@ -2158,7 +2150,7 @@ cdioctl(struct disk *dp, u_long cmd, void *addr, int flag, struct thread *td) th->ending_track = bcd2bin(th->ending_track); if (idx == th->ending_track + 1) { error = cdreadtoc(periph, te->address_format, - LEADOUT, (u_int8_t *)lead, + LEADOUT, (uint8_t *)lead, sizeof(*lead), /*sense_flags*/0); if (error) { @@ -2190,7 +2182,7 @@ cdioctl(struct disk *dp, u_long cmd, void *addr, int flag, struct thread *td) struct ioc_read_toc_single_entry *te = (struct ioc_read_toc_single_entry *) addr; struct ioc_toc_header *th; - u_int32_t track; + uint32_t track; data = malloc(sizeof(*data), M_SCSICD, M_WAITOK | M_ZERO); @@ -2209,7 +2201,7 @@ cdioctl(struct disk *dp, u_long cmd, void *addr, int flag, struct thread *td) } th = &data->header; - error = cdreadtoc(periph, 0, 0, (u_int8_t *)th, + error = cdreadtoc(periph, 0, 0, (uint8_t *)th, sizeof (*th), /*sense_flags*/0); if (error) { free(data, M_SCSICD); @@ -2241,7 +2233,7 @@ cdioctl(struct disk *dp, u_long cmd, void *addr, int flag, struct thread *td) } error = cdreadtoc(periph, te->address_format, track, - (u_int8_t *)data, sizeof(*data), + (uint8_t *)data, sizeof(*data), /*sense_flags*/0); if (error) { free(data, M_SCSICD); @@ -2565,12 +2557,12 @@ cdioctl(struct disk *dp, u_long cmd, void *addr, int flag, struct thread *td) break; case CDRIOCREADSPEED: cam_periph_lock(periph); - error = cdsetspeed(periph, *(u_int32_t *)addr, CDR_MAX_SPEED); + error = cdsetspeed(periph, *(uint32_t *)addr, CDR_MAX_SPEED); cam_periph_unlock(periph); break; case CDRIOCWRITESPEED: cam_periph_lock(periph); - error = cdsetspeed(periph, CDR_MAX_SPEED, *(u_int32_t *)addr); + error = cdsetspeed(periph, CDR_MAX_SPEED, *(uint32_t *)addr); cam_periph_unlock(periph); break; case CDRIOCGETBLOCKSIZE: @@ -2679,6 +2671,7 @@ cdmediaprobedone(struct cam_periph *periph) softc->flags &= ~CD_FLAG_MEDIA_WAIT; wakeup(&softc->toc); } + cam_periph_release_locked(periph); } /* @@ -2687,7 +2680,7 @@ cdmediaprobedone(struct cam_periph *periph) */ static int -cdcheckmedia(struct cam_periph *periph, int do_wait) +cdcheckmedia(struct cam_periph *periph, bool do_wait) { struct cd_softc *softc; int error; @@ -2696,237 +2689,37 @@ cdcheckmedia(struct cam_periph *periph, int do_wait) softc = (struct cd_softc *)periph->softc; error = 0; - if ((do_wait != 0) - && ((softc->flags & CD_FLAG_MEDIA_WAIT) == 0)) { + /* Released by cdmediaprobedone(). */ + error = cam_periph_acquire(periph); + if (error != 0) + return (error); + + if (do_wait) softc->flags |= CD_FLAG_MEDIA_WAIT; - } if ((softc->flags & CD_FLAG_MEDIA_SCAN_ACT) == 0) { softc->state = CD_STATE_MEDIA_PREVENT; softc->flags |= CD_FLAG_MEDIA_SCAN_ACT; xpt_schedule(periph, CAM_PRIORITY_NORMAL); } - - if (do_wait == 0) - goto bailout; + if (!do_wait) + return (0); error = msleep(&softc->toc, cam_periph_mtx(periph), PRIBIO,"cdmedia",0); - if (error != 0) - goto bailout; - /* * Check to see whether we have a valid size from the media. We * may or may not have a valid TOC. */ - if ((softc->flags & CD_FLAG_VALID_MEDIA) == 0) + if (error == 0 && (softc->flags & CD_FLAG_VALID_MEDIA) == 0) error = EINVAL; -bailout: return (error); } -#if 0 -static int -cdcheckmedia(struct cam_periph *periph) -{ - struct cd_softc *softc; - struct ioc_toc_header *toch; - struct cd_toc_single leadout; - u_int32_t size, toclen; - int error, num_entries, cdindex; - - softc = (struct cd_softc *)periph->softc; - - cdprevent(periph, PR_PREVENT); - softc->disk->d_sectorsize = 2048; - softc->disk->d_mediasize = 0; - - /* - * Get the disc size and block size. If we can't get it, we don't - * have media, most likely. - */ - if ((error = cdsize(periph, &size)) != 0) { - softc->flags &= ~(CD_FLAG_VALID_MEDIA|CD_FLAG_VALID_TOC); - cdprevent(periph, PR_ALLOW); - return (error); - } else { - softc->flags |= CD_FLAG_SAW_MEDIA | CD_FLAG_VALID_MEDIA; - softc->disk->d_sectorsize = softc->params.blksize; - softc->disk->d_mediasize = - (off_t)softc->params.blksize * softc->params.disksize; - } - - /* - * Now we check the table of contents. This (currently) is only - * used for the CDIOCPLAYTRACKS ioctl. It may be used later to do - * things like present a separate entry in /dev for each track, - * like that acd(4) driver does. - */ - bzero(&softc->toc, sizeof(softc->toc)); - toch = &softc->toc.header; - /* - * We will get errors here for media that doesn't have a table of - * contents. According to the MMC-3 spec: "When a Read TOC/PMA/ATIP - * command is presented for a DDCD/CD-R/RW media, where the first TOC - * has not been recorded (no complete session) and the Format codes - * 0000b, 0001b, or 0010b are specified, this command shall be rejected - * with an INVALID FIELD IN CDB. Devices that are not capable of - * reading an incomplete session on DDC/CD-R/RW media shall report - * CANNOT READ MEDIUM - INCOMPATIBLE FORMAT." - * - * So this isn't fatal if we can't read the table of contents, it - * just means that the user won't be able to issue the play tracks - * ioctl, and likely lots of other stuff won't work either. They - * need to burn the CD before we can do a whole lot with it. So - * we don't print anything here if we get an error back. - */ - error = cdreadtoc(periph, 0, 0, (u_int8_t *)toch, sizeof(*toch), - SF_NO_PRINT); - /* - * Errors in reading the table of contents aren't fatal, we just - * won't have a valid table of contents cached. - */ - if (error != 0) { - error = 0; - bzero(&softc->toc, sizeof(softc->toc)); - goto bailout; - } - - if (softc->quirks & CD_Q_BCD_TRACKS) { - toch->starting_track = bcd2bin(toch->starting_track); - toch->ending_track = bcd2bin(toch->ending_track); - } - - /* Number of TOC entries, plus leadout */ - num_entries = (toch->ending_track - toch->starting_track) + 2; - - if (num_entries <= 0) - goto bailout; - - toclen = num_entries * sizeof(struct cd_toc_entry); - - error = cdreadtoc(periph, CD_MSF_FORMAT, toch->starting_track, - (u_int8_t *)&softc->toc, toclen + sizeof(*toch), - SF_NO_PRINT); - if (error != 0) { - error = 0; - bzero(&softc->toc, sizeof(softc->toc)); - goto bailout; - } - - if (softc->quirks & CD_Q_BCD_TRACKS) { - toch->starting_track = bcd2bin(toch->starting_track); - toch->ending_track = bcd2bin(toch->ending_track); - } - /* - * XXX KDM is this necessary? Probably only if the drive doesn't - * return leadout information with the table of contents. - */ - cdindex = toch->starting_track + num_entries -1; - if (cdindex == toch->ending_track + 1) { - error = cdreadtoc(periph, CD_MSF_FORMAT, LEADOUT, - (u_int8_t *)&leadout, sizeof(leadout), - SF_NO_PRINT); - if (error != 0) { - error = 0; - goto bailout; - } - softc->toc.entries[cdindex - toch->starting_track] = - leadout.entry; - } - if (softc->quirks & CD_Q_BCD_TRACKS) { - for (cdindex = 0; cdindex < num_entries - 1; cdindex++) { - softc->toc.entries[cdindex].track = - bcd2bin(softc->toc.entries[cdindex].track); - } - } - - softc->flags |= CD_FLAG_VALID_TOC; - - /* If the first track is audio, correct sector size. */ - if ((softc->toc.entries[0].control & 4) == 0) { - softc->disk->d_sectorsize = softc->params.blksize = 2352; - softc->disk->d_mediasize = - (off_t)softc->params.blksize * softc->params.disksize; - } - -bailout: - - /* - * We unconditionally (re)set the blocksize each time the - * CD device is opened. This is because the CD can change, - * and therefore the blocksize might change. - * XXX problems here if some slice or partition is still - * open with the old size? - */ - if ((softc->disk->d_devstat->flags & DEVSTAT_BS_UNAVAILABLE) != 0) - softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE; - softc->disk->d_devstat->block_size = softc->params.blksize; - - return (error); -} - -static int -cdsize(struct cam_periph *periph, u_int32_t *size) -{ - struct cd_softc *softc; - union ccb *ccb; - struct scsi_read_capacity_data *rcap_buf; - int error; - - CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdsize\n")); - - softc = (struct cd_softc *)periph->softc; - - ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL); - - /* XXX Should be M_WAITOK */ - rcap_buf = malloc(sizeof(struct scsi_read_capacity_data), - M_SCSICD, M_NOWAIT | M_ZERO); - if (rcap_buf == NULL) - return (ENOMEM); - - scsi_read_capacity(&ccb->csio, - /*retries*/ cd_retry_count, - /*cbfcnp*/NULL, - MSG_SIMPLE_Q_TAG, - rcap_buf, - SSD_FULL_SIZE, - /* timeout */20000); - - error = cdrunccb(ccb, cderror, /*cam_flags*/CAM_RETRY_SELTO, - /*sense_flags*/SF_RETRY_UA|SF_NO_PRINT); - - xpt_release_ccb(ccb); - - softc->params.disksize = scsi_4btoul(rcap_buf->addr) + 1; - softc->params.blksize = scsi_4btoul(rcap_buf->length); - /* Make sure we got at least some block size. */ - if (error == 0 && softc->params.blksize == 0) - error = EIO; - /* - * SCSI-3 mandates that the reported blocksize shall be 2048. - * Older drives sometimes report funny values, trim it down to - * 2048, or other parts of the kernel will get confused. - * - * XXX we leave drives alone that might report 512 bytes, as - * well as drives reporting more weird sizes like perhaps 4K. - */ - if (softc->params.blksize > 2048 && softc->params.blksize <= 2352) - softc->params.blksize = 2048; - - free(rcap_buf, M_SCSICD); - *size = softc->params.disksize; - - return (error); - -} -#endif - static int cd6byteworkaround(union ccb *ccb) { - u_int8_t *cdb; + uint8_t *cdb; struct cam_periph *periph; struct cd_softc *softc; struct cd_mode_params *params; @@ -3073,7 +2866,7 @@ cd6byteworkaround(union ccb *ccb) } static int -cderror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags) +cderror(union ccb *ccb, uint32_t cam_flags, uint32_t sense_flags) { struct cd_softc *softc; struct cam_periph *periph; @@ -3146,8 +2939,8 @@ cdmediapoll(void *arg) * Read table of contents */ static int -cdreadtoc(struct cam_periph *periph, u_int32_t mode, u_int32_t start, - u_int8_t *data, u_int32_t len, u_int32_t sense_flags) +cdreadtoc(struct cam_periph *periph, uint32_t mode, uint32_t start, + uint8_t *data, uint32_t len, uint32_t sense_flags) { struct ccb_scsiio *csio; union ccb *ccb; @@ -3180,9 +2973,9 @@ cdreadtoc(struct cam_periph *periph, u_int32_t mode, u_int32_t start, } static int -cdreadsubchannel(struct cam_periph *periph, u_int32_t mode, - u_int32_t format, int track, - struct cd_sub_channel_info *data, u_int32_t len) +cdreadsubchannel(struct cam_periph *periph, uint32_t mode, + uint32_t format, int track, + struct cd_sub_channel_info *data, uint32_t len) { struct scsi_read_subchannel *scsi_cmd; struct ccb_scsiio *csio; @@ -3200,7 +2993,7 @@ cdreadsubchannel(struct cam_periph *periph, u_int32_t mode, /* cbfcnp */ NULL, /* flags */ CAM_DIR_IN, /* tag_action */ MSG_SIMPLE_Q_TAG, - /* data_ptr */ (u_int8_t *)data, + /* data_ptr */ (uint8_t *)data, /* dxfer_len */ len, /* sense_len */ SSD_FULL_SIZE, sizeof(struct scsi_read_subchannel), @@ -3215,7 +3008,7 @@ cdreadsubchannel(struct cam_periph *periph, u_int32_t mode, scsi_cmd->byte2 = SRS_SUBQ; scsi_cmd->subchan_format = format; scsi_cmd->track = track; - scsi_ulto2b(len, (u_int8_t *)scsi_cmd->data_len); + scsi_ulto2b(len, (uint8_t *)scsi_cmd->data_len); scsi_cmd->control = 0; error = cdrunccb(ccb, cderror, /*cam_flags*/CAM_RETRY_SELTO, @@ -3232,7 +3025,7 @@ cdreadsubchannel(struct cam_periph *periph, u_int32_t mode, */ static int cdgetmode(struct cam_periph *periph, struct cd_mode_params *data, - u_int32_t page) + uint32_t page) { struct ccb_scsiio *csio; struct cd_softc *softc; @@ -3293,7 +3086,7 @@ cdgetmode(struct cam_periph *periph, struct cd_mode_params *data, * potentially access memory beyond our malloced region. */ if (error == 0) { - u_int32_t data_len; + uint32_t data_len; if (data->cdb_size == 10) { struct scsi_mode_header_10 *hdr10; @@ -3359,7 +3152,7 @@ cdsetmode(struct cam_periph *periph, struct cd_mode_params *data) if (cdb_size >= 10) { struct scsi_mode_header_10 *mode_header; - u_int32_t data_len; + uint32_t data_len; mode_header = (struct scsi_mode_header_10 *)data->mode_buf; @@ -3424,12 +3217,12 @@ cdsetmode(struct cam_periph *periph, struct cd_mode_params *data) } static int -cdplay(struct cam_periph *periph, u_int32_t blk, u_int32_t len) +cdplay(struct cam_periph *periph, uint32_t blk, uint32_t len) { struct ccb_scsiio *csio; union ccb *ccb; int error; - u_int8_t cdb_len; + uint8_t cdb_len; error = 0; ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL); @@ -3446,8 +3239,8 @@ cdplay(struct cam_periph *periph, u_int32_t blk, u_int32_t len) scsi_cmd = (struct scsi_play_10 *)&csio->cdb_io.cdb_bytes; bzero (scsi_cmd, sizeof(*scsi_cmd)); scsi_cmd->op_code = PLAY_10; - scsi_ulto4b(blk, (u_int8_t *)scsi_cmd->blk_addr); - scsi_ulto2b(len, (u_int8_t *)scsi_cmd->xfer_len); + scsi_ulto4b(blk, (uint8_t *)scsi_cmd->blk_addr); + scsi_ulto2b(len, (uint8_t *)scsi_cmd->xfer_len); cdb_len = sizeof(*scsi_cmd); } else { struct scsi_play_12 *scsi_cmd; @@ -3455,8 +3248,8 @@ cdplay(struct cam_periph *periph, u_int32_t blk, u_int32_t len) scsi_cmd = (struct scsi_play_12 *)&csio->cdb_io.cdb_bytes; bzero (scsi_cmd, sizeof(*scsi_cmd)); scsi_cmd->op_code = PLAY_12; - scsi_ulto4b(blk, (u_int8_t *)scsi_cmd->blk_addr); - scsi_ulto4b(len, (u_int8_t *)scsi_cmd->xfer_len); + scsi_ulto4b(blk, (uint8_t *)scsi_cmd->blk_addr); + scsi_ulto4b(len, (uint8_t *)scsi_cmd->xfer_len); cdb_len = sizeof(*scsi_cmd); } cam_fill_csio(csio, @@ -3479,8 +3272,8 @@ cdplay(struct cam_periph *periph, u_int32_t blk, u_int32_t len) } static int -cdplaymsf(struct cam_periph *periph, u_int32_t startm, u_int32_t starts, - u_int32_t startf, u_int32_t endm, u_int32_t ends, u_int32_t endf) +cdplaymsf(struct cam_periph *periph, uint32_t startm, uint32_t starts, + uint32_t startf, uint32_t endm, uint32_t ends, uint32_t endf) { struct scsi_play_msf *scsi_cmd; struct ccb_scsiio *csio; @@ -3524,8 +3317,8 @@ cdplaymsf(struct cam_periph *periph, u_int32_t startm, u_int32_t starts, } static int -cdplaytracks(struct cam_periph *periph, u_int32_t strack, u_int32_t sindex, - u_int32_t etrack, u_int32_t eindex) +cdplaytracks(struct cam_periph *periph, uint32_t strack, uint32_t sindex, + uint32_t etrack, uint32_t eindex) { struct scsi_play_track *scsi_cmd; struct ccb_scsiio *csio; @@ -3567,7 +3360,7 @@ cdplaytracks(struct cam_periph *periph, u_int32_t strack, u_int32_t sindex, } static int -cdpause(struct cam_periph *periph, u_int32_t go) +cdpause(struct cam_periph *periph, uint32_t go) { struct scsi_pause *scsi_cmd; struct ccb_scsiio *csio; @@ -3634,7 +3427,7 @@ cdstartunit(struct cam_periph *periph, int load) } static int -cdstopunit(struct cam_periph *periph, u_int32_t eject) +cdstopunit(struct cam_periph *periph, uint32_t eject) { union ccb *ccb; int error; @@ -3662,7 +3455,7 @@ cdstopunit(struct cam_periph *periph, u_int32_t eject) } static int -cdsetspeed(struct cam_periph *periph, u_int32_t rdspeed, u_int32_t wrspeed) +cdsetspeed(struct cam_periph *periph, uint32_t rdspeed, uint32_t wrspeed) { struct scsi_set_speed *scsi_cmd; struct ccb_scsiio *csio; @@ -3709,8 +3502,8 @@ static int cdreportkey(struct cam_periph *periph, struct dvd_authinfo *authinfo) { union ccb *ccb; - u_int8_t *databuf; - u_int32_t lba; + uint8_t *databuf; + uint32_t lba; int error; int length; @@ -3868,7 +3661,7 @@ static int cdsendkey(struct cam_periph *periph, struct dvd_authinfo *authinfo) { union ccb *ccb; - u_int8_t *databuf; + uint8_t *databuf; int length; int error; @@ -3883,7 +3676,7 @@ cdsendkey(struct cam_periph *periph, struct dvd_authinfo *authinfo) challenge_data = malloc(length, M_DEVBUF, M_WAITOK | M_ZERO); - databuf = (u_int8_t *)challenge_data; + databuf = (uint8_t *)challenge_data; scsi_ulto2b(length - sizeof(challenge_data->data_len), challenge_data->data_len); @@ -3900,7 +3693,7 @@ cdsendkey(struct cam_periph *periph, struct dvd_authinfo *authinfo) key2_data = malloc(length, M_DEVBUF, M_WAITOK | M_ZERO); - databuf = (u_int8_t *)key2_data; + databuf = (uint8_t *)key2_data; scsi_ulto2b(length - sizeof(key2_data->data_len), key2_data->data_len); @@ -3917,7 +3710,7 @@ cdsendkey(struct cam_periph *periph, struct dvd_authinfo *authinfo) rpc_data = malloc(length, M_DEVBUF, M_WAITOK | M_ZERO); - databuf = (u_int8_t *)rpc_data; + databuf = (uint8_t *)rpc_data; scsi_ulto2b(length - sizeof(rpc_data->data_len), rpc_data->data_len); @@ -3959,8 +3752,8 @@ static int cdreaddvdstructure(struct cam_periph *periph, struct dvd_struct *dvdstruct) { union ccb *ccb; - u_int8_t *databuf; - u_int32_t address; + uint8_t *databuf; + uint32_t address; int error; int length; @@ -4135,11 +3928,11 @@ bailout: } void -scsi_report_key(struct ccb_scsiio *csio, u_int32_t retries, +scsi_report_key(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int32_t lba, u_int8_t agid, - u_int8_t key_format, u_int8_t *data_ptr, u_int32_t dxfer_len, - u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, uint32_t lba, uint8_t agid, + uint8_t key_format, uint8_t *data_ptr, uint32_t dxfer_len, + uint8_t sense_len, uint32_t timeout) { struct scsi_report_key *scsi_cmd; @@ -4164,11 +3957,11 @@ scsi_report_key(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_send_key(struct ccb_scsiio *csio, u_int32_t retries, +scsi_send_key(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t agid, u_int8_t key_format, - u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, uint8_t agid, uint8_t key_format, + uint8_t *data_ptr, uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout) { struct scsi_send_key *scsi_cmd; @@ -4193,12 +3986,12 @@ scsi_send_key(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_read_dvd_structure(struct ccb_scsiio *csio, u_int32_t retries, +scsi_read_dvd_structure(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int32_t address, - u_int8_t layer_number, u_int8_t format, u_int8_t agid, - u_int8_t *data_ptr, u_int32_t dxfer_len, - u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, uint32_t address, + uint8_t layer_number, uint8_t format, uint8_t agid, + uint8_t *data_ptr, uint32_t dxfer_len, + uint8_t sense_len, uint32_t timeout) { struct scsi_read_dvd_structure *scsi_cmd; diff --git a/sys/cam/scsi/scsi_cd.h b/sys/cam/scsi/scsi_cd.h index 0968dafe4d2d..d67402859432 100644 --- a/sys/cam/scsi/scsi_cd.h +++ b/sys/cam/scsi/scsi_cd.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2000, 2002 Kenneth D. Merry * All rights reserved. @@ -43,7 +43,6 @@ * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 * * from: scsi_cd.h,v 1.10 1997/02/22 09:44:28 peter Exp $ - * $FreeBSD$ */ #ifndef _SCSI_SCSI_CD_H #define _SCSI_SCSI_CD_H 1 @@ -137,110 +136,110 @@ struct scsi_mechanism_status_header struct scsi_pause { - u_int8_t op_code; - u_int8_t byte2; - u_int8_t unused[6]; - u_int8_t resume; - u_int8_t control; + uint8_t op_code; + uint8_t byte2; + uint8_t unused[6]; + uint8_t resume; + uint8_t control; }; #define PA_PAUSE 1 #define PA_RESUME 0 struct scsi_play_msf { - u_int8_t op_code; - u_int8_t byte2; - u_int8_t unused; - u_int8_t start_m; - u_int8_t start_s; - u_int8_t start_f; - u_int8_t end_m; - u_int8_t end_s; - u_int8_t end_f; - u_int8_t control; + uint8_t op_code; + uint8_t byte2; + uint8_t unused; + uint8_t start_m; + uint8_t start_s; + uint8_t start_f; + uint8_t end_m; + uint8_t end_s; + uint8_t end_f; + uint8_t control; }; struct scsi_play_track { - u_int8_t op_code; - u_int8_t byte2; - u_int8_t unused[2]; - u_int8_t start_track; - u_int8_t start_index; - u_int8_t unused1; - u_int8_t end_track; - u_int8_t end_index; - u_int8_t control; + uint8_t op_code; + uint8_t byte2; + uint8_t unused[2]; + uint8_t start_track; + uint8_t start_index; + uint8_t unused1; + uint8_t end_track; + uint8_t end_index; + uint8_t control; }; struct scsi_play_10 { - u_int8_t op_code; - u_int8_t byte2; - u_int8_t blk_addr[4]; - u_int8_t unused; - u_int8_t xfer_len[2]; - u_int8_t control; + uint8_t op_code; + uint8_t byte2; + uint8_t blk_addr[4]; + uint8_t unused; + uint8_t xfer_len[2]; + uint8_t control; }; struct scsi_play_12 { - u_int8_t op_code; - u_int8_t byte2; /* same as above */ - u_int8_t blk_addr[4]; - u_int8_t xfer_len[4]; - u_int8_t unused; - u_int8_t control; + uint8_t op_code; + uint8_t byte2; /* same as above */ + uint8_t blk_addr[4]; + uint8_t xfer_len[4]; + uint8_t unused; + uint8_t control; }; struct scsi_play_rel_12 { - u_int8_t op_code; - u_int8_t byte2; /* same as above */ - u_int8_t blk_addr[4]; - u_int8_t xfer_len[4]; - u_int8_t track; - u_int8_t control; + uint8_t op_code; + uint8_t byte2; /* same as above */ + uint8_t blk_addr[4]; + uint8_t xfer_len[4]; + uint8_t track; + uint8_t control; }; struct scsi_read_header { - u_int8_t op_code; - u_int8_t byte2; - u_int8_t blk_addr[4]; - u_int8_t unused; - u_int8_t data_len[2]; - u_int8_t control; + uint8_t op_code; + uint8_t byte2; + uint8_t blk_addr[4]; + uint8_t unused; + uint8_t data_len[2]; + uint8_t control; }; struct scsi_read_subchannel { - u_int8_t op_code; - u_int8_t byte1; - u_int8_t byte2; + uint8_t op_code; + uint8_t byte1; + uint8_t byte2; #define SRS_SUBQ 0x40 - u_int8_t subchan_format; - u_int8_t unused[2]; - u_int8_t track; - u_int8_t data_len[2]; - u_int8_t control; + uint8_t subchan_format; + uint8_t unused[2]; + uint8_t track; + uint8_t data_len[2]; + uint8_t control; }; struct scsi_read_toc { - u_int8_t op_code; - u_int8_t byte2; - u_int8_t format; + uint8_t op_code; + uint8_t byte2; + uint8_t format; #define SRTOC_FORMAT_TOC 0x00 #define SRTOC_FORMAT_LAST_ADDR 0x01 #define SRTOC_FORMAT_QSUB_TOC 0x02 #define SRTOC_FORMAT_QSUB_PMA 0x03 #define SRTOC_FORMAT_ATIP 0x04 #define SRTOC_FORMAT_CD_TEXT 0x05 - u_int8_t unused[3]; - u_int8_t from_track; - u_int8_t data_len[2]; - u_int8_t control; + uint8_t unused[3]; + uint8_t from_track; + uint8_t data_len[2]; + uint8_t control; }; struct scsi_read_toc_hdr @@ -261,34 +260,34 @@ struct scsi_read_toc_type01_descr struct scsi_read_cd_capacity { - u_int8_t op_code; - u_int8_t byte2; - u_int8_t addr_3; /* Most Significant */ - u_int8_t addr_2; - u_int8_t addr_1; - u_int8_t addr_0; /* Least Significant */ - u_int8_t unused[3]; - u_int8_t control; + uint8_t op_code; + uint8_t byte2; + uint8_t addr_3; /* Most Significant */ + uint8_t addr_2; + uint8_t addr_1; + uint8_t addr_0; /* Least Significant */ + uint8_t unused[3]; + uint8_t control; }; struct scsi_set_speed { - u_int8_t opcode; - u_int8_t byte2; - u_int8_t readspeed[2]; - u_int8_t writespeed[2]; - u_int8_t reserved[5]; - u_int8_t control; + uint8_t opcode; + uint8_t byte2; + uint8_t readspeed[2]; + uint8_t writespeed[2]; + uint8_t reserved[5]; + uint8_t control; }; struct scsi_report_key { - u_int8_t opcode; - u_int8_t reserved0; - u_int8_t lba[4]; - u_int8_t reserved1[2]; - u_int8_t alloc_len[2]; - u_int8_t agid_keyformat; + uint8_t opcode; + uint8_t reserved0; + uint8_t lba[4]; + uint8_t reserved1[2]; + uint8_t alloc_len[2]; + uint8_t agid_keyformat; #define RK_KF_AGID_MASK 0xc0 #define RK_KF_AGID_SHIFT 6 #define RK_KF_KEYFORMAT_MASK 0x3f @@ -301,7 +300,7 @@ struct scsi_report_key #define RK_KF_RPC_SET 0x06 #define RF_KF_RPC_REPORT 0x08 #define RF_KF_INV_AGID 0x3f - u_int8_t control; + uint8_t control; }; /* @@ -309,20 +308,20 @@ struct scsi_report_key */ struct scsi_send_key { - u_int8_t opcode; - u_int8_t reserved[7]; - u_int8_t param_len[2]; - u_int8_t agid_keyformat; - u_int8_t control; + uint8_t opcode; + uint8_t reserved[7]; + uint8_t param_len[2]; + uint8_t agid_keyformat; + uint8_t control; }; struct scsi_read_dvd_structure { - u_int8_t opcode; - u_int8_t reserved; - u_int8_t address[4]; - u_int8_t layer_number; - u_int8_t format; + uint8_t opcode; + uint8_t reserved; + uint8_t address[4]; + uint8_t layer_number; + uint8_t format; #define RDS_FORMAT_PHYSICAL 0x00 #define RDS_FORMAT_COPYRIGHT 0x01 #define RDS_FORMAT_DISC_KEY 0x02 @@ -341,9 +340,9 @@ struct scsi_read_dvd_structure #define RDS_FORMAT_DCB 0x30 #define RDS_FORMAT_WRITE_PROT 0xc0 #define RDS_FORMAT_STRUCTURE_LIST 0xff - u_int8_t alloc_len[2]; - u_int8_t agid; - u_int8_t control; + uint8_t alloc_len[2]; + uint8_t agid; + uint8_t control; }; /* @@ -370,40 +369,40 @@ struct scsi_read_dvd_structure struct scsi_report_key_data_header { - u_int8_t data_len[2]; - u_int8_t reserved[2]; + uint8_t data_len[2]; + uint8_t reserved[2]; }; struct scsi_report_key_data_agid { - u_int8_t data_len[2]; - u_int8_t reserved[5]; - u_int8_t agid; + uint8_t data_len[2]; + uint8_t reserved[5]; + uint8_t agid; #define RKD_AGID_MASK 0xc0 #define RKD_AGID_SHIFT 6 }; struct scsi_report_key_data_challenge { - u_int8_t data_len[2]; - u_int8_t reserved0[2]; - u_int8_t challenge_key[10]; - u_int8_t reserved1[2]; + uint8_t data_len[2]; + uint8_t reserved0[2]; + uint8_t challenge_key[10]; + uint8_t reserved1[2]; }; struct scsi_report_key_data_key1_key2 { - u_int8_t data_len[2]; - u_int8_t reserved0[2]; - u_int8_t key1[5]; - u_int8_t reserved1[3]; + uint8_t data_len[2]; + uint8_t reserved0[2]; + uint8_t key1[5]; + uint8_t reserved1[3]; }; struct scsi_report_key_data_title { - u_int8_t data_len[2]; - u_int8_t reserved0[2]; - u_int8_t byte0; + uint8_t data_len[2]; + uint8_t reserved0[2]; + uint8_t byte0; #define RKD_TITLE_CPM 0x80 #define RKD_TITLE_CPM_SHIFT 7 #define RKD_TITLE_CP_SEC 0x40 @@ -414,26 +413,26 @@ struct scsi_report_key_data_title #define RKD_TITLE_CMGS_RSVD 0x10 #define RKD_TITLE_CMGS_1_GEN 0x20 #define RKD_TITLE_CMGS_NO_COPY 0x30 - u_int8_t title_key[5]; - u_int8_t reserved1[2]; + uint8_t title_key[5]; + uint8_t reserved1[2]; }; struct scsi_report_key_data_asf { - u_int8_t data_len[2]; - u_int8_t reserved[5]; - u_int8_t success; + uint8_t data_len[2]; + uint8_t reserved[5]; + uint8_t success; #define RKD_ASF_SUCCESS 0x01 }; struct scsi_report_key_data_rpc { - u_int8_t data_len[2]; - u_int8_t rpc_scheme0; + uint8_t data_len[2]; + uint8_t rpc_scheme0; #define RKD_RPC_SCHEME_UNKNOWN 0x00 #define RKD_RPC_SCHEME_PHASE_II 0x01 - u_int8_t reserved0; - u_int8_t byte4; + uint8_t reserved0; + uint8_t byte4; #define RKD_RPC_TYPE_MASK 0xC0 #define RKD_RPC_TYPE_SHIFT 6 #define RKD_RPC_TYPE_NONE 0x00 @@ -444,17 +443,17 @@ struct scsi_report_key_data_rpc #define RKD_RPC_VENDOR_RESET_SHIFT 3 #define RKD_RPC_USER_RESET_MASK 0x07 #define RKD_RPC_USER_RESET_SHIFT 0 - u_int8_t region_mask; - u_int8_t rpc_scheme1; - u_int8_t reserved1; + uint8_t region_mask; + uint8_t rpc_scheme1; + uint8_t reserved1; }; struct scsi_send_key_data_rpc { - u_int8_t data_len[2]; - u_int8_t reserved0[2]; - u_int8_t region_code; - u_int8_t reserved1[3]; + uint8_t data_len[2]; + uint8_t reserved0[2]; + uint8_t region_code; + uint8_t reserved1[3]; }; /* @@ -462,13 +461,13 @@ struct scsi_send_key_data_rpc */ struct scsi_read_dvd_struct_data_header { - u_int8_t data_len[2]; - u_int8_t reserved[2]; + uint8_t data_len[2]; + uint8_t reserved[2]; }; struct scsi_read_dvd_struct_data_layer_desc { - u_int8_t book_type_version; + uint8_t book_type_version; #define RDSD_BOOK_TYPE_DVD_ROM 0x00 #define RDSD_BOOK_TYPE_DVD_RAM 0x10 #define RDSD_BOOK_TYPE_DVD_R 0x20 @@ -481,7 +480,7 @@ struct scsi_read_dvd_struct_data_layer_desc * The lower 4 bits of this field is referred to as the "minimum * rate" field in MMC2, and the "maximum rate" field in MMC3. Ugh. */ - u_int8_t disc_size_max_rate; + uint8_t disc_size_max_rate; #define RDSD_DISC_SIZE_120MM 0x00 #define RDSD_DISC_SIZE_80MM 0x10 #define RDSD_DISC_SIZE_MASK 0xf0 @@ -491,7 +490,7 @@ struct scsi_read_dvd_struct_data_layer_desc #define RDSD_MAX_RATE_1008 0x02 #define RDSD_MAX_RATE_NOT_SPEC 0x0f #define RDSD_MAX_RATE_MASK 0x0f - u_int8_t layer_info; + uint8_t layer_info; #define RDSD_NUM_LAYERS_MASK 0x60 #define RDSD_NUM_LAYERS_SHIFT 5 #define RDSD_NL_ONE_LAYER 0x00 @@ -504,7 +503,7 @@ struct scsi_read_dvd_struct_data_layer_desc #define RDSD_LAYER_TYPE_RECORD 0x02 #define RDSD_LAYER_TYPE_RW 0x04 #define RDSD_LAYER_TYPE_MASK 0x0f - u_int8_t density; + uint8_t density; #define RDSD_LIN_DENSITY_0267 0x00 #define RDSD_LIN_DENSITY_0293 0x10 #define RDSD_LIN_DENSITY_0409_0435 0x20 @@ -517,65 +516,65 @@ struct scsi_read_dvd_struct_data_layer_desc #define RDSD_TRACK_DENSITY_080 0x01 #define RDSD_TRACK_DENSITY_0615 0x02 #define RDSD_TRACK_DENSITY_MASK 0x0f - u_int8_t zeros0; - u_int8_t main_data_start[3]; + uint8_t zeros0; + uint8_t main_data_start[3]; #define RDSD_MAIN_DATA_START_DVD_RO 0x30000 #define RDSD_MAIN_DATA_START_DVD_RW 0x31000 - u_int8_t zeros1; - u_int8_t main_data_end[3]; - u_int8_t zeros2; - u_int8_t end_sector_layer0[3]; - u_int8_t bca; + uint8_t zeros1; + uint8_t main_data_end[3]; + uint8_t zeros2; + uint8_t end_sector_layer0[3]; + uint8_t bca; #define RDSD_BCA 0x80 #define RDSD_BCA_MASK 0x80 #define RDSD_BCA_SHIFT 7 - u_int8_t media_specific[2031]; + uint8_t media_specific[2031]; }; struct scsi_read_dvd_struct_data_physical { - u_int8_t data_len[2]; - u_int8_t reserved[2]; + uint8_t data_len[2]; + uint8_t reserved[2]; struct scsi_read_dvd_struct_data_layer_desc layer_desc; }; struct scsi_read_dvd_struct_data_copyright { - u_int8_t data_len[2]; - u_int8_t reserved0[2]; - u_int8_t cps_type; + uint8_t data_len[2]; + uint8_t reserved0[2]; + uint8_t cps_type; #define RDSD_CPS_NOT_PRESENT 0x00 #define RDSD_CPS_DATA_EXISTS 0x01 - u_int8_t region_info; - u_int8_t reserved1[2]; + uint8_t region_info; + uint8_t reserved1[2]; }; struct scsi_read_dvd_struct_data_disc_key { - u_int8_t data_len[2]; - u_int8_t reserved[2]; - u_int8_t disc_key[2048]; + uint8_t data_len[2]; + uint8_t reserved[2]; + uint8_t disc_key[2048]; }; struct scsi_read_dvd_struct_data_bca { - u_int8_t data_len[2]; - u_int8_t reserved[2]; - u_int8_t bca_info[188]; /* XXX 12-188 bytes */ + uint8_t data_len[2]; + uint8_t reserved[2]; + uint8_t bca_info[188]; /* XXX 12-188 bytes */ }; struct scsi_read_dvd_struct_data_manufacturer { - u_int8_t data_len[2]; - u_int8_t reserved[2]; - u_int8_t manuf_info[2048]; + uint8_t data_len[2]; + uint8_t reserved[2]; + uint8_t manuf_info[2048]; }; struct scsi_read_dvd_struct_data_copy_manage { - u_int8_t data_len[2]; - u_int8_t reserved0[2]; - u_int8_t byte4; + uint8_t data_len[2]; + uint8_t reserved0[2]; + uint8_t byte4; #define RDSD_CPM_NO_COPYRIGHT 0x00 #define RDSD_CPM_HAS_COPYRIGHT 0x80 #define RDSD_CPM_MASK 0x80 @@ -583,14 +582,14 @@ struct scsi_read_dvd_struct_data_copy_manage #define RDSD_CMGS_ONE_COPY 0x20 #define RDSD_CMGS_NO_COPIES 0x30 #define RDSD_CMGS_MASK 0x30 - u_int8_t reserved1[3]; + uint8_t reserved1[3]; }; struct scsi_read_dvd_struct_data_prot_discid { - u_int8_t data_len[2]; - u_int8_t reserved[2]; - u_int8_t prot_discid_data[16]; + uint8_t data_len[2]; + uint8_t reserved[2]; + uint8_t prot_discid_data[16]; }; struct scsi_read_dvd_struct_data_disc_key_blk @@ -598,59 +597,59 @@ struct scsi_read_dvd_struct_data_disc_key_blk /* * Length is 0x6ffe == 28670 for CPRM, 0x3002 == 12990 for CSS2. */ - u_int8_t data_len[2]; - u_int8_t reserved; - u_int8_t total_packs; - u_int8_t disc_key_pack_data[28668]; + uint8_t data_len[2]; + uint8_t reserved; + uint8_t total_packs; + uint8_t disc_key_pack_data[28668]; }; struct scsi_read_dvd_struct_data_dds { - u_int8_t data_len[2]; - u_int8_t reserved[2]; - u_int8_t dds_info[2048]; + uint8_t data_len[2]; + uint8_t reserved[2]; + uint8_t dds_info[2048]; }; struct scsi_read_dvd_struct_data_medium_status { - u_int8_t data_len[2]; - u_int8_t reserved0[2]; - u_int8_t byte4; + uint8_t data_len[2]; + uint8_t reserved0[2]; + uint8_t byte4; #define RDSD_MS_CARTRIDGE 0x80 #define RDSD_MS_OUT 0x40 #define RDSD_MS_MSWI 0x08 #define RDSD_MS_CWP 0x04 #define RDSD_MS_PWP 0x02 - u_int8_t disc_type_id; + uint8_t disc_type_id; #define RDSD_DT_NEED_CARTRIDGE 0x00 #define RDSD_DT_NO_CART_NEEDED 0x01 - u_int8_t reserved1; - u_int8_t ram_swi_info; + uint8_t reserved1; + uint8_t ram_swi_info; #define RDSD_SWI_NO_BARE 0x01 #define RDSD_SWI_UNSPEC 0xff }; struct scsi_read_dvd_struct_data_spare_area { - u_int8_t data_len[2]; - u_int8_t reserved[2]; - u_int8_t unused_primary[4]; - u_int8_t unused_supl[4]; - u_int8_t allocated_supl[4]; + uint8_t data_len[2]; + uint8_t reserved[2]; + uint8_t unused_primary[4]; + uint8_t unused_supl[4]; + uint8_t allocated_supl[4]; }; struct scsi_read_dvd_struct_data_rmd_borderout { - u_int8_t data_len[2]; - u_int8_t reserved[2]; - u_int8_t rmd[30720]; /* maximum is 30720 bytes */ + uint8_t data_len[2]; + uint8_t reserved[2]; + uint8_t rmd[30720]; /* maximum is 30720 bytes */ }; struct scsi_read_dvd_struct_data_rmd { - u_int8_t data_len[2]; - u_int8_t reserved[2]; - u_int8_t last_sector_num[4]; - u_int8_t rmd_bytes[32768]; /* This is the maximum */ + uint8_t data_len[2]; + uint8_t reserved[2]; + uint8_t last_sector_num[4]; + uint8_t rmd_bytes[32768]; /* This is the maximum */ }; /* @@ -660,124 +659,124 @@ struct scsi_read_dvd_struct_data_rmd */ struct scsi_read_dvd_struct_data_leadin { - u_int8_t data_len[2]; - u_int8_t reserved0[2]; - u_int8_t field_id_1; - u_int8_t app_code; - u_int8_t disc_physical_data; - u_int8_t last_addr[3]; - u_int8_t reserved1[2]; - u_int8_t field_id_2; - u_int8_t rwp; - u_int8_t rwp_wavelength; - u_int8_t optimum_write_strategy; - u_int8_t reserved2[4]; - u_int8_t field_id_3; - u_int8_t manuf_id_17_12[6]; - u_int8_t reserved3; - u_int8_t field_id_4; - u_int8_t manuf_id_11_6[6]; - u_int8_t reserved4; - u_int8_t field_id_5; - u_int8_t manuf_id_5_0[6]; - u_int8_t reserved5[25]; + uint8_t data_len[2]; + uint8_t reserved0[2]; + uint8_t field_id_1; + uint8_t app_code; + uint8_t disc_physical_data; + uint8_t last_addr[3]; + uint8_t reserved1[2]; + uint8_t field_id_2; + uint8_t rwp; + uint8_t rwp_wavelength; + uint8_t optimum_write_strategy; + uint8_t reserved2[4]; + uint8_t field_id_3; + uint8_t manuf_id_17_12[6]; + uint8_t reserved3; + uint8_t field_id_4; + uint8_t manuf_id_11_6[6]; + uint8_t reserved4; + uint8_t field_id_5; + uint8_t manuf_id_5_0[6]; + uint8_t reserved5[25]; }; struct scsi_read_dvd_struct_data_disc_id { - u_int8_t data_len[2]; - u_int8_t reserved[4]; - u_int8_t random_num[2]; - u_int8_t year[4]; - u_int8_t month[2]; - u_int8_t day[2]; - u_int8_t hour[2]; - u_int8_t minute[2]; - u_int8_t second[2]; + uint8_t data_len[2]; + uint8_t reserved[4]; + uint8_t random_num[2]; + uint8_t year[4]; + uint8_t month[2]; + uint8_t day[2]; + uint8_t hour[2]; + uint8_t minute[2]; + uint8_t second[2]; }; struct scsi_read_dvd_struct_data_generic_dcb { - u_int8_t content_desc[4]; + uint8_t content_desc[4]; #define SCSI_RCB - u_int8_t unknown_desc_actions[4]; + uint8_t unknown_desc_actions[4]; #define RDSD_ACTION_RECORDING 0x0001 #define RDSD_ACTION_READING 0x0002 #define RDSD_ACTION_FORMAT 0x0004 #define RDSD_ACTION_MODIFY_DCB 0x0008 - u_int8_t vendor_id[32]; - u_int8_t dcb_data[32728]; + uint8_t vendor_id[32]; + uint8_t dcb_data[32728]; }; struct scsi_read_dvd_struct_data_dcb { - u_int8_t data_len[2]; - u_int8_t reserved[2]; + uint8_t data_len[2]; + uint8_t reserved[2]; struct scsi_read_dvd_struct_data_generic_dcb dcb; }; struct read_dvd_struct_write_prot { - u_int8_t data_len[2]; - u_int8_t reserved0[2]; - u_int8_t write_prot_status; + uint8_t data_len[2]; + uint8_t reserved0[2]; + uint8_t write_prot_status; #define RDSD_WPS_MSWI 0x08 #define RDSD_WPS_CWP 0x04 #define RDSD_WPS_PWP 0x02 #define RDSD_WPS_SWPP 0x01 - u_int8_t reserved[3]; + uint8_t reserved[3]; }; struct read_dvd_struct_list_entry { - u_int8_t format_code; - u_int8_t sds_rds; + uint8_t format_code; + uint8_t sds_rds; #define RDSD_SDS_NOT_WRITEABLE 0x00 #define RDSD_SDS_WRITEABLE 0x80 #define RDSD_SDS_MASK 0x80 #define RDSD_RDS_NOT_READABLE 0x00 #define RDSD_RDS_READABLE 0x40 #define RDSD_RDS_MASK 0x40 - u_int8_t struct_len[2]; + uint8_t struct_len[2]; }; struct read_dvd_struct_data_list { - u_int8_t data_len[2]; - u_int8_t reserved[2]; + uint8_t data_len[2]; + uint8_t reserved[2]; struct read_dvd_struct_list_entry entries[0]; }; struct scsi_read_cd_cap_data { - u_int8_t addr_3; /* Most significant */ - u_int8_t addr_2; - u_int8_t addr_1; - u_int8_t addr_0; /* Least significant */ - u_int8_t length_3; /* Most significant */ - u_int8_t length_2; - u_int8_t length_1; - u_int8_t length_0; /* Least significant */ + uint8_t addr_3; /* Most significant */ + uint8_t addr_2; + uint8_t addr_1; + uint8_t addr_0; /* Least significant */ + uint8_t length_3; /* Most significant */ + uint8_t length_2; + uint8_t length_1; + uint8_t length_0; /* Least significant */ }; struct cd_audio_page { - u_int8_t page_code; + uint8_t page_code; #define CD_PAGE_CODE 0x3F #define AUDIO_PAGE 0x0e #define CD_PAGE_PS 0x80 - u_int8_t param_len; - u_int8_t flags; + uint8_t param_len; + uint8_t flags; #define CD_PA_SOTC 0x02 #define CD_PA_IMMED 0x04 - u_int8_t unused[2]; - u_int8_t format_lba; + uint8_t unused[2]; + uint8_t format_lba; #define CD_PA_FORMAT_LBA 0x0F #define CD_PA_APR_VALID 0x80 - u_int8_t lb_per_sec[2]; + uint8_t lb_per_sec[2]; struct port_control { - u_int8_t channels; + uint8_t channels; #define CHANNEL 0x0F #define CHANNEL_0 1 #define CHANNEL_1 2 @@ -785,7 +784,7 @@ struct cd_audio_page #define CHANNEL_3 8 #define LEFT_CHANNEL CHANNEL_0 #define RIGHT_CHANNEL CHANNEL_1 - u_int8_t volume; + uint8_t volume; } port[4]; #define LEFT_PORT 0 #define RIGHT_PORT 1 @@ -852,30 +851,30 @@ struct cd_mode_params STAILQ_ENTRY(cd_mode_params) links; int cdb_size; int alloc_len; - u_int8_t *mode_buf; + uint8_t *mode_buf; }; __BEGIN_DECLS -void scsi_report_key(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_report_key(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int32_t lba, u_int8_t agid, - u_int8_t key_format, u_int8_t *data_ptr, - u_int32_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout); + uint8_t tag_action, uint32_t lba, uint8_t agid, + uint8_t key_format, uint8_t *data_ptr, + uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout); -void scsi_send_key(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_send_key(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t agid, u_int8_t key_format, - u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout); + uint8_t tag_action, uint8_t agid, uint8_t key_format, + uint8_t *data_ptr, uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout); -void scsi_read_dvd_structure(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_read_dvd_structure(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int32_t address, - u_int8_t layer_number, u_int8_t format, - u_int8_t agid, u_int8_t *data_ptr, - u_int32_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout); + uint8_t tag_action, uint32_t address, + uint8_t layer_number, uint8_t format, + uint8_t agid, uint8_t *data_ptr, + uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout); void scsi_read_toc(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), diff --git a/sys/cam/scsi/scsi_ch.c b/sys/cam/scsi/scsi_ch.c index bccca0e87726..89a817c1b488 100644 --- a/sys/cam/scsi/scsi_ch.c +++ b/sys/cam/scsi/scsi_ch.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-4-Clause) + * SPDX-License-Identifier: (BSD-2-Clause AND BSD-4-Clause) * * Copyright (c) 1997 Justin T. Gibbs. * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry. @@ -65,9 +65,6 @@ * $NetBSD: ch.c,v 1.34 1998/08/31 22:28:06 cgd Exp $ */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/queue.h> #include <sys/systm.h> @@ -96,13 +93,13 @@ __FBSDID("$FreeBSD$"); * ELEMENT STATUS). */ -static const u_int32_t CH_TIMEOUT_MODE_SENSE = 6000; -static const u_int32_t CH_TIMEOUT_MOVE_MEDIUM = 15 * 60 * 1000; -static const u_int32_t CH_TIMEOUT_EXCHANGE_MEDIUM = 15 * 60 * 1000; -static const u_int32_t CH_TIMEOUT_POSITION_TO_ELEMENT = 15 * 60 * 1000; -static const u_int32_t CH_TIMEOUT_READ_ELEMENT_STATUS = 5 * 60 * 1000; -static const u_int32_t CH_TIMEOUT_SEND_VOLTAG = 10000; -static const u_int32_t CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS = 500000; +static const uint32_t CH_TIMEOUT_MODE_SENSE = 6000; +static const uint32_t CH_TIMEOUT_MOVE_MEDIUM = 15 * 60 * 1000; +static const uint32_t CH_TIMEOUT_EXCHANGE_MEDIUM = 15 * 60 * 1000; +static const uint32_t CH_TIMEOUT_POSITION_TO_ELEMENT = 15 * 60 * 1000; +static const uint32_t CH_TIMEOUT_READ_ELEMENT_STATUS = 5 * 60 * 1000; +static const uint32_t CH_TIMEOUT_SEND_VOLTAG = 10000; +static const uint32_t CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS = 500000; typedef enum { CH_FLAG_INVALID = 0x001 @@ -162,12 +159,12 @@ struct ch_softc { * The following mask defines the legal combinations * of elements for the MOVE MEDIUM command. */ - u_int8_t sc_movemask[CHET_MAX + 1]; + uint8_t sc_movemask[CHET_MAX + 1]; /* * As above, but for EXCHANGE MEDIUM. */ - u_int8_t sc_exchangemask[CHET_MAX + 1]; + uint8_t sc_exchangemask[CHET_MAX + 1]; /* * Quirks; see below. XXX KDM not implemented yet @@ -183,12 +180,12 @@ static periph_ctor_t chregister; static periph_oninv_t choninvalidate; static periph_dtor_t chcleanup; static periph_start_t chstart; -static void chasync(void *callback_arg, u_int32_t code, +static void chasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg); static void chdone(struct cam_periph *periph, union ccb *done_ccb); -static int cherror(union ccb *ccb, u_int32_t cam_flags, - u_int32_t sense_flags); +static int cherror(union ccb *ccb, uint32_t cam_flags, + uint32_t sense_flags); static int chmove(struct cam_periph *periph, struct changer_move *cm); static int chexchange(struct cam_periph *periph, @@ -316,7 +313,7 @@ chcleanup(struct cam_periph *periph) } static void -chasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg) +chasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg) { struct cam_periph *periph; @@ -580,7 +577,7 @@ chstart(struct cam_periph *periph, union ccb *start_ccb) FALSE : TRUE, /* pc */ SMS_PAGE_CTRL_CURRENT, /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE, - /* param_buf */ (u_int8_t *)mode_buffer, + /* param_buf */ (uint8_t *)mode_buffer, /* param_len */ mode_buffer_len, /* sense_len */ SSD_FULL_SIZE, /* timeout */ CH_TIMEOUT_MODE_SENSE); @@ -732,7 +729,7 @@ chdone(struct cam_periph *periph, union ccb *done_ccb) } static int -cherror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags) +cherror(union ccb *ccb, uint32_t cam_flags, uint32_t sense_flags) { return (cam_periph_error(ccb, cam_flags, sense_flags)); @@ -861,7 +858,7 @@ static int chmove(struct cam_periph *periph, struct changer_move *cm) { struct ch_softc *softc; - u_int16_t fromelem, toelem; + uint16_t fromelem, toelem; union ccb *ccb; int error; @@ -915,7 +912,7 @@ static int chexchange(struct cam_periph *periph, struct changer_exchange *ce) { struct ch_softc *softc; - u_int16_t src, dst1, dst2; + uint16_t src, dst1, dst2; union ccb *ccb; int error; @@ -978,7 +975,7 @@ static int chposition(struct cam_periph *periph, struct changer_position *cp) { struct ch_softc *softc; - u_int16_t dst; + uint16_t dst; union ccb *ccb; int error; @@ -1047,13 +1044,13 @@ copy_voltag(struct changer_voltag *uvoltag, struct volume_tag *voltag) */ static void copy_element_status(struct ch_softc *softc, - u_int16_t flags, + uint16_t flags, struct read_element_status_descriptor *desc, struct changer_element_status *ces, int scsi_version) { - u_int16_t eaddr = scsi_2btoul(desc->eaddr); - u_int16_t et; + uint16_t eaddr = scsi_2btoul(desc->eaddr); + uint16_t et; struct volume_tag *pvol_tag = NULL, *avol_tag = NULL; struct read_element_status_device_id *devid = NULL; @@ -1442,8 +1439,8 @@ chsetvoltag(struct cam_periph *periph, { union ccb *ccb; struct ch_softc *softc; - u_int16_t ea; - u_int8_t sac; + uint16_t ea; + uint8_t sac; struct scsi_send_volume_tag_parameters ssvtp; int error; int i; @@ -1534,7 +1531,7 @@ chgetparams(struct cam_periph *periph) struct page_element_address_assignment *ea; struct page_device_capabilities *cap; int error, from, dbd; - u_int8_t *moves, *exchanges; + uint8_t *moves, *exchanges; error = 0; @@ -1574,7 +1571,7 @@ chgetparams(struct cam_periph *periph) /* dbd */ dbd, /* pc */ SMS_PAGE_CTRL_CURRENT, /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE, - /* param_buf */ (u_int8_t *)mode_buffer, + /* param_buf */ (uint8_t *)mode_buffer, /* param_len */ mode_buffer_len, /* sense_len */ SSD_FULL_SIZE, /* timeout */ CH_TIMEOUT_MODE_SENSE); @@ -1637,7 +1634,7 @@ chgetparams(struct cam_periph *periph) /* dbd */ dbd, /* pc */ SMS_PAGE_CTRL_CURRENT, /* page */ CH_DEVICE_CAP_PAGE, - /* param_buf */ (u_int8_t *)mode_buffer, + /* param_buf */ (uint8_t *)mode_buffer, /* param_len */ mode_buffer_len, /* sense_len */ SSD_FULL_SIZE, /* timeout */ CH_TIMEOUT_MODE_SENSE); @@ -1727,11 +1724,11 @@ chscsiversion(struct cam_periph *periph) } void -scsi_move_medium(struct ccb_scsiio *csio, u_int32_t retries, +scsi_move_medium(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int32_t tea, u_int32_t src, - u_int32_t dst, int invert, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, uint32_t tea, uint32_t src, + uint32_t dst, int invert, uint8_t sense_len, + uint32_t timeout) { struct scsi_move_medium *scsi_cmd; @@ -1760,11 +1757,11 @@ scsi_move_medium(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_exchange_medium(struct ccb_scsiio *csio, u_int32_t retries, +scsi_exchange_medium(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int32_t tea, u_int32_t src, - u_int32_t dst1, u_int32_t dst2, int invert1, - int invert2, u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, uint32_t tea, uint32_t src, + uint32_t dst1, uint32_t dst2, int invert1, + int invert2, uint8_t sense_len, uint32_t timeout) { struct scsi_exchange_medium *scsi_cmd; @@ -1797,10 +1794,10 @@ scsi_exchange_medium(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_position_to_element(struct ccb_scsiio *csio, u_int32_t retries, +scsi_position_to_element(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int32_t tea, u_int32_t dst, - int invert, u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, uint32_t tea, uint32_t dst, + int invert, uint8_t sense_len, uint32_t timeout) { struct scsi_position_to_element *scsi_cmd; @@ -1828,13 +1825,13 @@ scsi_position_to_element(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_read_element_status(struct ccb_scsiio *csio, u_int32_t retries, +scsi_read_element_status(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int voltag, u_int32_t sea, + uint8_t tag_action, int voltag, uint32_t sea, int curdata, int dvcid, - u_int32_t count, u_int8_t *data_ptr, - u_int32_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout) + uint32_t count, uint8_t *data_ptr, + uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout) { struct scsi_read_element_status *scsi_cmd; @@ -1867,10 +1864,10 @@ scsi_read_element_status(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_initialize_element_status(struct ccb_scsiio *csio, u_int32_t retries, +scsi_initialize_element_status(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, uint8_t sense_len, + uint32_t timeout) { struct scsi_initialize_element_status *scsi_cmd; @@ -1893,13 +1890,13 @@ scsi_initialize_element_status(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_send_volume_tag(struct ccb_scsiio *csio, u_int32_t retries, +scsi_send_volume_tag(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, - u_int16_t element_address, - u_int8_t send_action_code, + uint8_t tag_action, + uint16_t element_address, + uint8_t send_action_code, struct scsi_send_volume_tag_parameters *parameters, - u_int8_t sense_len, u_int32_t timeout) + uint8_t sense_len, uint32_t timeout) { struct scsi_send_volume_tag *scsi_cmd; @@ -1916,7 +1913,7 @@ scsi_send_volume_tag(struct ccb_scsiio *csio, u_int32_t retries, cbfcnp, /*flags*/ CAM_DIR_OUT, tag_action, - /* data_ptr */ (u_int8_t *) parameters, + /* data_ptr */ (uint8_t *) parameters, sizeof(*parameters), sense_len, sizeof(*scsi_cmd), diff --git a/sys/cam/scsi/scsi_ch.h b/sys/cam/scsi/scsi_ch.h index efab7a05d9fb..a8f980166600 100644 --- a/sys/cam/scsi/scsi_ch.h +++ b/sys/cam/scsi/scsi_ch.h @@ -1,4 +1,3 @@ -/* $FreeBSD$ */ /* $NetBSD: scsi_changer.h,v 1.11 1998/02/13 08:28:32 enami Exp $ */ /*- @@ -65,7 +64,6 @@ #ifndef _SCSI_SCSI_CH_H #define _SCSI_SCSI_CH_H 1 -#include <sys/cdefs.h> /* * SCSI command format @@ -76,17 +74,17 @@ * located at the destination element. */ struct scsi_exchange_medium { - u_int8_t opcode; + uint8_t opcode; #define EXCHANGE_MEDIUM 0xa6 - u_int8_t byte2; - u_int8_t tea[2]; /* transport element address */ - u_int8_t src[2]; /* source address */ - u_int8_t fdst[2]; /* first destination address */ - u_int8_t sdst[2]; /* second destination address */ - u_int8_t invert; + uint8_t byte2; + uint8_t tea[2]; /* transport element address */ + uint8_t src[2]; /* source address */ + uint8_t fdst[2]; /* first destination address */ + uint8_t sdst[2]; /* second destination address */ + uint8_t invert; #define EXCHANGE_MEDIUM_INV1 0x01 #define EXCHANGE_MEDIUM_INV2 0x02 - u_int8_t control; + uint8_t control; }; /* @@ -94,11 +92,11 @@ struct scsi_exchange_medium { * other status relevant to the element. */ struct scsi_initialize_element_status { - u_int8_t opcode; + uint8_t opcode; #define INITIALIZE_ELEMENT_STATUS 0x07 - u_int8_t byte2; - u_int8_t reserved[3]; - u_int8_t control; + uint8_t byte2; + uint8_t reserved[3]; + uint8_t control; }; /* @@ -106,15 +104,15 @@ struct scsi_initialize_element_status { * to the destination element. */ struct scsi_move_medium { - u_int8_t opcode; - u_int8_t byte2; - u_int8_t tea[2]; /* transport element address */ - u_int8_t src[2]; /* source element address */ - u_int8_t dst[2]; /* destination element address */ - u_int8_t reserved[2]; - u_int8_t invert; + uint8_t opcode; + uint8_t byte2; + uint8_t tea[2]; /* transport element address */ + uint8_t src[2]; /* source element address */ + uint8_t dst[2]; /* destination element address */ + uint8_t reserved[2]; + uint8_t invert; #define MOVE_MEDIUM_INVERT 0x01 - u_int8_t control; + uint8_t control; }; /* @@ -122,46 +120,46 @@ struct scsi_move_medium { * the destination element specified. */ struct scsi_position_to_element { - u_int8_t opcode; - u_int8_t byte2; - u_int8_t tea[2]; /* transport element address */ - u_int8_t dst[2]; /* destination element address */ - u_int8_t reserved[2]; - u_int8_t invert; + uint8_t opcode; + uint8_t byte2; + uint8_t tea[2]; /* transport element address */ + uint8_t dst[2]; /* destination element address */ + uint8_t reserved[2]; + uint8_t invert; #define POSITION_TO_ELEMENT_INVERT 0x01 - u_int8_t control; + uint8_t control; }; /* * Request that the changer report the status of its internal elements. */ struct scsi_read_element_status { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define READ_ELEMENT_STATUS_VOLTAG 0x10 /* report volume tag info */ /* ...next 4 bits are an element type code... */ - u_int8_t sea[2]; /* starting element address */ - u_int8_t count[2]; /* number of elements */ - u_int8_t flags; + uint8_t sea[2]; /* starting element address */ + uint8_t count[2]; /* number of elements */ + uint8_t flags; #define READ_ELEMENT_STATUS_DVCID 0x01 /* report device serial number */ #define READ_ELEMENT_STATUS_CURDATA 0x02 /* allow motion during command */ - u_int8_t len[3]; /* length of data buffer */ - u_int8_t reserved1; - u_int8_t control; + uint8_t len[3]; /* length of data buffer */ + uint8_t reserved1; + uint8_t control; }; struct scsi_request_volume_element_address { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define REQUEST_VOLUME_ELEMENT_ADDRESS_VOLTAG 0x10 /* ...next 4 bits are an element type code... */ - u_int8_t eaddr[2]; /* element address */ - u_int8_t count[2]; /* number of elements */ - u_int8_t reserved0; - u_int8_t len[3]; /* length of data buffer */ - u_int8_t reserved1; - u_int8_t control; + uint8_t eaddr[2]; /* element address */ + uint8_t count[2]; /* number of elements */ + uint8_t reserved0; + uint8_t len[3]; /* length of data buffer */ + uint8_t reserved1; + uint8_t control; }; /* XXX scsi_release */ @@ -178,20 +176,20 @@ struct scsi_request_volume_element_address { * followed by one or more read_element_status_pages. */ struct read_element_status_header { - u_int8_t fear[2]; /* first element address reported */ - u_int8_t count[2]; /* number of elements available */ - u_int8_t reserved; - u_int8_t nbytes[3]; /* byte count of all pages */ + uint8_t fear[2]; /* first element address reported */ + uint8_t count[2]; /* number of elements available */ + uint8_t reserved; + uint8_t nbytes[3]; /* byte count of all pages */ }; struct read_element_status_page_header { - u_int8_t type; /* element type code; see type codes below */ - u_int8_t flags; + uint8_t type; /* element type code; see type codes below */ + uint8_t flags; #define READ_ELEMENT_STATUS_AVOLTAG 0x40 #define READ_ELEMENT_STATUS_PVOLTAG 0x80 - u_int8_t edl[2]; /* element descriptor length */ - u_int8_t reserved; - u_int8_t nbytes[3]; /* byte count of all descriptors */ + uint8_t edl[2]; /* element descriptor length */ + uint8_t reserved; + uint8_t nbytes[3]; /* byte count of all descriptors */ }; /* @@ -199,29 +197,29 @@ struct read_element_status_page_header { */ struct volume_tag { - u_int8_t vif[32]; /* volume identification field */ - u_int8_t reserved[2]; - u_int8_t vsn[2]; /* volume sequence number */ + uint8_t vif[32]; /* volume identification field */ + uint8_t reserved[2]; + uint8_t vsn[2]; /* volume sequence number */ }; struct read_element_status_device_id { - u_int8_t prot_code_set; + uint8_t prot_code_set; #define READ_ELEMENT_STATUS_CODE_SET(p) ((p) & 0x0F) #define READ_ELEMENT_STATUS_PROTOCOL_ID(p) ((p) >> 4) - u_int8_t piv_assoc_designator_type; + uint8_t piv_assoc_designator_type; #define READ_ELEMENT_STATUS_PIV_SET 0x80 #define READ_ELEMENT_STATUS_ASSOCIATION(p) ((p) >> 4) #define READ_ELEMENT_STATUS_DESIGNATOR_TYPE(p) ((p) & 0x0F) - u_int8_t reserved2; - u_int8_t designator_length; - u_int8_t designator[256]; /* Allocate max length */ + uint8_t reserved2; + uint8_t designator_length; + uint8_t designator[256]; /* Allocate max length */ }; struct read_element_status_descriptor { - u_int8_t eaddr[2]; /* element address */ - u_int8_t flags1; + uint8_t eaddr[2]; /* element address */ + uint8_t flags1; #define READ_ELEMENT_STATUS_FULL 0x01 #define READ_ELEMENT_STATUS_IMPEXP 0x02 @@ -235,34 +233,34 @@ struct read_element_status_descriptor { #define READ_ELEMENT_STATUS_IE_MASK1 0x3f #define READ_ELEMENT_STATUS_DT_MASK1 0x0c - u_int8_t reserved0; - u_int8_t sense_code; - u_int8_t sense_qual; + uint8_t reserved0; + uint8_t sense_code; + uint8_t sense_qual; union { struct { - u_int8_t dt_scsi_flags; + uint8_t dt_scsi_flags; #define READ_ELEMENT_STATUS_DT_LUNMASK 0x07 #define READ_ELEMENT_STATUS_DT_LUVALID 0x10 #define READ_ELEMENT_STATUS_DT_IDVALID 0x20 #define READ_ELEMENT_STATUS_DT_NOTBUS 0x80 - u_int8_t dt_scsi_addr; - u_int8_t reserved1; + uint8_t dt_scsi_addr; + uint8_t reserved1; } scsi_2; /* reserved and obsolete (as of SCSI-3) fields */ - u_int8_t reserved_or_obsolete[3]; + uint8_t reserved_or_obsolete[3]; } dt_or_obsolete; - u_int8_t flags2; + uint8_t flags2; #define READ_ELEMENT_STATUS_INVERT 0x40 #define READ_ELEMENT_STATUS_SVALID 0x80 #define READ_ELEMENT_STATUS_ED 0x80 #define READ_ELEMENT_STATUS_MEDIA_TYPE_MASK 0x07 - u_int8_t ssea[2]; /* source storage element address */ + uint8_t ssea[2]; /* source storage element address */ union { struct volume_tag pvoltag; @@ -300,12 +298,12 @@ struct read_element_status_descriptor { */ struct scsi_send_volume_tag { - u_int8_t opcode; + uint8_t opcode; #define SEND_VOLUME_TAG 0xb6 - u_int8_t byte2; - u_int8_t ea[2]; /* element address */ - u_int8_t reserved2; - u_int8_t sac; /* send action code */ + uint8_t byte2; + uint8_t ea[2]; /* element address */ + uint8_t reserved2; + uint8_t sac; /* send action code */ #define SEND_VOLUME_TAG_ASSERT_PRIMARY 0x08 #define SEND_VOLUME_TAG_ASSERT_ALTERNATE 0x09 @@ -314,10 +312,10 @@ struct scsi_send_volume_tag { #define SEND_VOLUME_TAG_UNDEFINED_PRIMARY 0x0c #define SEND_VOLUME_TAG_UNDEFINED_ALTERNATE 0x0d - u_int8_t reserved4[2]; - u_int8_t pll[2]; /* parameter list length */ - u_int8_t reserved5; - u_int8_t control; + uint8_t reserved4[2]; + uint8_t pll[2]; /* parameter list length */ + uint8_t reserved5; + uint8_t control; }; /* @@ -325,11 +323,11 @@ struct scsi_send_volume_tag { */ struct scsi_send_volume_tag_parameters { - u_int8_t vitf[32]; /* volume tag identification template */ - u_int8_t reserved1[2]; - u_int8_t minvsn[2]; /* minimum volume sequence number */ - u_int8_t reserved2[2]; - u_int8_t maxvsn[2]; /* maximum volume sequence number */ + uint8_t vitf[32]; /* volume tag identification template */ + uint8_t reserved1[2]; + uint8_t minvsn[2]; /* minimum volume sequence number */ + uint8_t reserved2[2]; + uint8_t maxvsn[2]; /* maximum volume sequence number */ }; /* @@ -346,21 +344,21 @@ struct scsi_send_volume_tag_parameters { * DT Data transfer element (tape/disk drive) */ struct page_device_capabilities { - u_int8_t pg_code; /* page code (0x1f) */ - u_int8_t pg_length; /* page length (0x12) */ + uint8_t pg_code; /* page code (0x1f) */ + uint8_t pg_length; /* page length (0x12) */ /* * The STOR_xx bits indicate that an element of a given * type may provide independent storage for a unit of * media. The top four bits of this value are reserved. */ - u_int8_t stor; + uint8_t stor; #define STOR_MT 0x01 #define STOR_ST 0x02 #define STOR_IE 0x04 #define STOR_DT 0x08 - u_int8_t reserved0; + uint8_t reserved0; /* * The MOVE_TO_yy bits indicate the changer supports @@ -369,18 +367,18 @@ struct page_device_capabilities { * MOVE MEDIUM command is legal. The top four bits of each * of these values are reserved. */ - u_int8_t move_from[CHET_MAX + 1]; + uint8_t move_from[CHET_MAX + 1]; #define MOVE_TO_MT 0x01 #define MOVE_TO_ST 0x02 #define MOVE_TO_IE 0x04 #define MOVE_TO_DT 0x08 - u_int8_t reserved1[4]; + uint8_t reserved1[4]; /* * Similar to above, but for EXCHANGE MEDIUM. */ - u_int8_t exchange_with[CHET_MAX + 1]; + uint8_t exchange_with[CHET_MAX + 1]; #define EXCHANGE_WITH_MT 0x01 #define EXCHANGE_WITH_ST 0x02 #define EXCHANGE_WITH_IE 0x04 @@ -416,34 +414,34 @@ struct page_device_capabilities { * tells us how many drives exist in the changer. */ struct page_element_address_assignment { - u_int8_t pg_code; /* page code (0x1d) */ - u_int8_t pg_length; /* page length (0x12) */ + uint8_t pg_code; /* page code (0x1d) */ + uint8_t pg_length; /* page length (0x12) */ /* Medium transport element address */ - u_int8_t mtea[2]; + uint8_t mtea[2]; /* Number of medium transport elements */ - u_int8_t nmte[2]; + uint8_t nmte[2]; /* First storage element address */ - u_int8_t fsea[2]; + uint8_t fsea[2]; /* Number of storage elements */ - u_int8_t nse[2]; + uint8_t nse[2]; /* First import/export element address */ - u_int8_t fieea[2]; + uint8_t fieea[2]; /* Number of import/export elements */ - u_int8_t niee[2]; + uint8_t niee[2]; /* First data transfer element address */ - u_int8_t fdtea[2]; + uint8_t fdtea[2]; /* Number of data transfer elements */ - u_int8_t ndte[2]; + uint8_t ndte[2]; - u_int8_t reserved[2]; + uint8_t reserved[2]; }; /* @@ -457,56 +455,56 @@ struct page_element_address_assignment { * of 0). */ struct page_transport_geometry_parameters { - u_int8_t pg_code; /* page code (0x1e) */ - u_int8_t pg_length; /* page length; variable */ + uint8_t pg_code; /* page code (0x1e) */ + uint8_t pg_length; /* page length; variable */ /* Transport geometry descriptor(s) are here. */ - u_int8_t misc; + uint8_t misc; #define CAN_ROTATE 0x01 /* Member number in transport element set. */ - u_int8_t member; + uint8_t member; }; __BEGIN_DECLS -void scsi_move_medium(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_move_medium(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int32_t tea, u_int32_t src, - u_int32_t dst, int invert, u_int8_t sense_len, - u_int32_t timeout); + uint8_t tag_action, uint32_t tea, uint32_t src, + uint32_t dst, int invert, uint8_t sense_len, + uint32_t timeout); -void scsi_exchange_medium(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_exchange_medium(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int32_t tea, u_int32_t src, - u_int32_t dst1, u_int32_t dst2, int invert1, - int invert2, u_int8_t sense_len, u_int32_t timeout); + uint8_t tag_action, uint32_t tea, uint32_t src, + uint32_t dst1, uint32_t dst2, int invert1, + int invert2, uint8_t sense_len, uint32_t timeout); -void scsi_position_to_element(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_position_to_element(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int32_t tea, u_int32_t dst, - int invert, u_int8_t sense_len, - u_int32_t timeout); + uint8_t tag_action, uint32_t tea, uint32_t dst, + int invert, uint8_t sense_len, + uint32_t timeout); -void scsi_read_element_status(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_read_element_status(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int voltag, u_int32_t sea, + uint8_t tag_action, int voltag, uint32_t sea, int curdata, int dvcid, - u_int32_t count, u_int8_t *data_ptr, - u_int32_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout); + uint32_t count, uint8_t *data_ptr, + uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout); -void scsi_initialize_element_status(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_initialize_element_status(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t sense_len, - u_int32_t timeout); -void scsi_send_volume_tag(struct ccb_scsiio *csio, u_int32_t retries, + uint8_t tag_action, uint8_t sense_len, + uint32_t timeout); +void scsi_send_volume_tag(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, - u_int16_t element_address, - u_int8_t send_action_code, + uint8_t tag_action, + uint16_t element_address, + uint8_t send_action_code, struct scsi_send_volume_tag_parameters *parameters, - u_int8_t sense_len, u_int32_t timeout); + uint8_t sense_len, uint32_t timeout); __END_DECLS #endif /* _SCSI_SCSI_CH_H */ diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c index 4c298af3432d..59745231bca5 100644 --- a/sys/cam/scsi/scsi_da.c +++ b/sys/cam/scsi/scsi_da.c @@ -1,7 +1,7 @@ /*- * Implementation of SCSI Direct Access Peripheral driver for CAM. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997 Justin T. Gibbs. * All rights reserved. @@ -28,9 +28,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #ifdef _KERNEL @@ -140,7 +137,7 @@ typedef enum { "\013CAN_RC16" \ "\014PROBED" \ "\015DIRTY" \ - "\016ANNOUCNED" \ + "\016ANNOUNCED" \ "\017CAN_ATA_DMA" \ "\020CAN_ATA_LOG" \ "\021CAN_ATA_IDLOG" \ @@ -302,11 +299,11 @@ static const char *da_delete_method_desc[] = #define ccb_bp ppriv_ptr1 struct disk_params { - u_int8_t heads; - u_int32_t cylinders; - u_int8_t secs_per_track; - u_int32_t secsize; /* Number of bytes/sector */ - u_int64_t sectors; /* total number sectors */ + uint8_t heads; + uint32_t cylinders; + uint8_t secs_per_track; + uint32_t secsize; /* Number of bytes/sector */ + uint64_t sectors; /* total number sectors */ u_int stripesize; u_int stripeoffset; }; @@ -329,7 +326,6 @@ typedef enum { DA_REF_OPEN = 1, DA_REF_OPEN_HOLD, DA_REF_CLOSE_HOLD, - DA_REF_PROBE_HOLD, DA_REF_TUR, DA_REF_GEOM, DA_REF_SYSCTL, @@ -1401,6 +1397,22 @@ static struct da_quirk_entry da_quirk_table[] = }, { /* + * Samsung 860 SSDs + * 4k optimised & trim only works in 4k requests + 4k aligned + */ + { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 860*", "*" }, + /*quirks*/DA_Q_4K + }, + { + /* + * Samsung 870 SSDs + * 4k optimised & trim only works in 4k requests + 4k aligned + */ + { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 870*", "*" }, + /*quirks*/DA_Q_4K + }, + { + /* * Samsung 843T Series SSDs (MZ7WD*) * Samsung PM851 Series SSDs (MZ7TE*) * Samsung PM853T Series SSDs (MZ7GE*) @@ -1471,7 +1483,7 @@ static struct da_quirk_entry da_quirk_table[] = static disk_strategy_t dastrategy; static dumper_t dadump; static periph_init_t dainit; -static void daasync(void *callback_arg, u_int32_t code, +static void daasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg); static void dasysctlinit(void *context, int pending); static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS); @@ -1521,8 +1533,8 @@ static void dadone_probezone(struct cam_periph *periph, union ccb *done_ccb); static void dadone_tur(struct cam_periph *periph, union ccb *done_ccb); -static int daerror(union ccb *ccb, u_int32_t cam_flags, - u_int32_t sense_flags); +static int daerror(union ccb *ccb, uint32_t cam_flags, + uint32_t sense_flags); static void daprevent(struct cam_periph *periph, int action); static void dareprobe(struct cam_periph *periph); static void dasetgeom(struct cam_periph *periph, uint32_t block_len, @@ -1945,7 +1957,7 @@ dadump(void *arg, void *virtual, off_t offset, size_t length) /*minimum_cmd_size*/ softc->minimum_cmd_size, offset / secsize, length / secsize, - /*data_ptr*/(u_int8_t *) virtual, + /*data_ptr*/(uint8_t *) virtual, /*dxfer_len*/length, /*sense_len*/SSD_FULL_SIZE, da_default_timeout * 1000); @@ -2102,7 +2114,7 @@ dacleanup(struct cam_periph *periph) } static void -daasync(void *callback_arg, u_int32_t code, +daasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg) { struct cam_periph *periph; @@ -2354,11 +2366,11 @@ dasysctlinit(void *context, int pending) SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "rotating", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, &softc->flags, (u_int)DA_FLAG_ROTATING, dabitsysctl, "I", - "Rotating media *DEPRECATED* gone in FreeBSD 14"); + "Rotating media *DEPRECATED* gone in FreeBSD 15"); SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "unmapped_io", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, &softc->flags, (u_int)DA_FLAG_UNMAPPEDIO, dabitsysctl, "I", - "Unmapped I/O support *DEPRECATED* gone in FreeBSD 14"); + "Unmapped I/O support *DEPRECATED* gone in FreeBSD 15"); #ifdef CAM_TEST_FAILURE SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), @@ -2602,9 +2614,17 @@ daprobedone(struct cam_periph *periph, union ccb *ccb) wakeup(&softc->disk->d_mediasize); if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) { softc->flags |= DA_FLAG_ANNOUNCED; - da_periph_unhold(periph, DA_REF_PROBE_HOLD); - } else - da_periph_release_locked(periph, DA_REF_REPROBE); + + /* + * We'll release this reference once GEOM calls us back via + * dadiskgonecb(), telling us that our provider has been freed. + */ + if (da_periph_acquire(periph, DA_REF_GEOM) == 0) + disk_create(softc->disk, DISK_VERSION); + + cam_periph_release_boot(periph); + } + da_periph_release_locked(periph, DA_REF_REPROBE); } static void @@ -2660,7 +2680,7 @@ daflagssysctl(SYSCTL_HANDLER_ARGS) if (softc->flags != 0) sbuf_printf(&sbuf, "0x%b", (unsigned)softc->flags, DA_FLAG_STRING); else - sbuf_printf(&sbuf, "0"); + sbuf_putc(&sbuf, '0'); error = sbuf_finish(&sbuf); sbuf_delete(&sbuf); @@ -2730,7 +2750,6 @@ dazonemodesysctl(SYSCTL_HANDLER_ARGS) static int dazonesupsysctl(SYSCTL_HANDLER_ARGS) { - char tmpbuf[180]; struct da_softc *softc; struct sbuf sb; int error, first; @@ -2738,15 +2757,14 @@ dazonesupsysctl(SYSCTL_HANDLER_ARGS) softc = (struct da_softc *)arg1; - error = 0; first = 1; - sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0); + sbuf_new_for_sysctl(&sb, NULL, 0, req); for (i = 0; i < sizeof(da_zone_desc_table) / sizeof(da_zone_desc_table[0]); i++) { if (softc->zone_flags & da_zone_desc_table[i].value) { if (first == 0) - sbuf_printf(&sb, ", "); + sbuf_cat(&sb, ", "); else first = 0; sbuf_cat(&sb, da_zone_desc_table[i].desc); @@ -2754,12 +2772,10 @@ dazonesupsysctl(SYSCTL_HANDLER_ARGS) } if (first == 1) - sbuf_printf(&sb, "None"); - - sbuf_finish(&sb); - - error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req); + sbuf_cat(&sb, "None"); + error = sbuf_finish(&sb); + sbuf_delete(&sb); return (error); } @@ -2864,14 +2880,10 @@ daregister(struct cam_periph *periph, void *arg) } /* - * Take an exclusive section lock on the periph while dastart is called - * to finish the probe. The lock will be dropped in dadone at the end - * of probe. This locks out daopen and daclose from racing with the - * probe. - * - * XXX if cam_periph_hold returns an error, we don't hold a refcount. + * Take a reference on the periph while dastart is called to finish the + * probe. The reference will be dropped in dadone at the end of probe. */ - (void)da_periph_hold(periph, PRIBIO, DA_REF_PROBE_HOLD); + (void)da_periph_acquire(periph, DA_REF_REPROBE); /* * Schedule a periodic event to occasionally send an @@ -2967,20 +2979,6 @@ daregister(struct cam_periph *periph, void *arg) softc->disk->d_hba_subdevice = cpi.hba_subdevice; snprintf(softc->disk->d_attachment, sizeof(softc->disk->d_attachment), "%s%d", cpi.dev_name, cpi.unit_number); - - /* - * Acquire a reference to the periph before we register with GEOM. - * We'll release this reference once GEOM calls us back (via - * dadiskgonecb()) telling us that our provider has been freed. - */ - if (da_periph_acquire(periph, DA_REF_GEOM) != 0) { - xpt_print(periph->path, "%s: lost periph during " - "registration!\n", __func__); - cam_periph_lock(periph); - return (CAM_REQ_CMP_ERR); - } - - disk_create(softc->disk, DISK_VERSION); cam_periph_lock(periph); /* @@ -2995,14 +2993,6 @@ daregister(struct cam_periph *periph, void *arg) AC_INQ_CHANGED, daasync, periph, periph->path); /* - * Emit an attribute changed notification just in case - * physical path information arrived before our async - * event handler was registered, but after anyone attaching - * to our disk device polled it. - */ - disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT); - - /* * Schedule a periodic media polling events. */ callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0); @@ -3013,8 +3003,10 @@ daregister(struct cam_periph *periph, void *arg) 0, damediapoll, periph, C_PREL(1)); } - xpt_schedule(periph, CAM_PRIORITY_DEV); + /* Released after probe when disk_create() call pass it to GEOM. */ + cam_periph_hold_boot(periph); + xpt_schedule(periph, CAM_PRIORITY_DEV); return(CAM_REQ_CMP); } @@ -3463,10 +3455,19 @@ more: queue_ccb = 0; - error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb); + error = da_zone_cmd(periph, start_ccb, bp, &queue_ccb); if ((error != 0) || (queue_ccb == 0)) { + /* + * g_io_deliver will recurisvely call start + * routine for ENOMEM, so drop the periph + * lock to allow that recursion. + */ + if (error == ENOMEM) + cam_periph_unlock(periph); biofinish(bp, NULL, error); + if (error == ENOMEM) + cam_periph_lock(periph); xpt_release_ccb(start_ccb); return; } @@ -3622,7 +3623,7 @@ out: /*retries*/da_retry_count, /*cbfcnp*/dadone_probelbp, /*tag_action*/MSG_SIMPLE_Q_TAG, - /*inq_buf*/(u_int8_t *)lbp, + /*inq_buf*/(uint8_t *)lbp, /*inq_len*/sizeof(*lbp), /*evpd*/TRUE, /*page_code*/SVPD_LBP, @@ -3656,7 +3657,7 @@ out: /*retries*/da_retry_count, /*cbfcnp*/dadone_probeblklimits, /*tag_action*/MSG_SIMPLE_Q_TAG, - /*inq_buf*/(u_int8_t *)block_limits, + /*inq_buf*/(uint8_t *)block_limits, /*inq_len*/sizeof(*block_limits), /*evpd*/TRUE, /*page_code*/SVPD_BLOCK_LIMITS, @@ -3689,7 +3690,7 @@ out: /*retries*/da_retry_count, /*cbfcnp*/dadone_probebdc, /*tag_action*/MSG_SIMPLE_Q_TAG, - /*inq_buf*/(u_int8_t *)bdc, + /*inq_buf*/(uint8_t *)bdc, /*inq_len*/sizeof(*bdc), /*evpd*/TRUE, /*page_code*/SVPD_BDC, @@ -3727,7 +3728,7 @@ out: /*retries*/da_retry_count, /*cbfcnp*/dadone_probeata, /*tag_action*/MSG_SIMPLE_Q_TAG, - /*data_ptr*/(u_int8_t *)ata_params, + /*data_ptr*/(uint8_t *)ata_params, /*dxfer_len*/sizeof(*ata_params), /*sense_len*/SSD_FULL_SIZE, /*timeout*/da_default_timeout * 1000); @@ -3970,7 +3971,7 @@ out: /*retries*/da_retry_count, /*cbfcnp*/dadone_probezone, /*tag_action*/MSG_SIMPLE_Q_TAG, - /*inq_buf*/(u_int8_t *)bdc, + /*inq_buf*/(uint8_t *)bdc, /*inq_len*/sizeof(*bdc), /*evpd*/TRUE, /*page_code*/SVPD_ZONED_BDC, @@ -4216,6 +4217,9 @@ da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp) da_default_timeout * 1000); ccb->ccb_h.ccb_state = DA_CCB_DELETE; ccb->ccb_h.flags |= CAM_UNLOCKED; + softc->trim_count++; + softc->trim_ranges += ranges; + softc->trim_lbas += block_count; cam_iosched_submit_trim(softc->cam_iosched); } @@ -4276,6 +4280,9 @@ da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp) da_default_timeout * 1000); ccb->ccb_h.ccb_state = DA_CCB_DELETE; ccb->ccb_h.flags |= CAM_UNLOCKED; + softc->trim_count++; + softc->trim_ranges++; + softc->trim_lbas += count; cam_iosched_submit_trim(softc->cam_iosched); } @@ -4285,7 +4292,7 @@ cmd6workaround(union ccb *ccb) struct scsi_rw_6 cmd6; struct scsi_rw_10 *cmd10; struct da_softc *softc; - u_int8_t *cdb; + uint8_t *cdb; struct bio *bp; int frozen; @@ -4692,7 +4699,7 @@ dadone_probewp(struct cam_periph *periph, union ccb *done_ccb) { struct da_softc *softc; struct ccb_scsiio *csio; - u_int32_t priority; + uint32_t priority; CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probewp\n")); @@ -4776,7 +4783,7 @@ dadone_proberc(struct cam_periph *periph, union ccb *done_ccb) struct ccb_scsiio *csio; da_ccb_state state; char *announce_buf; - u_int32_t priority; + uint32_t priority; int lbp, n; CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_proberc\n")); @@ -5062,7 +5069,7 @@ dadone_probelbp(struct cam_periph *periph, union ccb *done_ccb) struct scsi_vpd_logical_block_prov *lbp; struct da_softc *softc; struct ccb_scsiio *csio; - u_int32_t priority; + uint32_t priority; CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probelbp\n")); @@ -5120,7 +5127,7 @@ dadone_probeblklimits(struct cam_periph *periph, union ccb *done_ccb) struct scsi_vpd_block_limits *block_limits; struct da_softc *softc; struct ccb_scsiio *csio; - u_int32_t priority; + uint32_t priority; CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeblklimits\n")); @@ -5214,7 +5221,7 @@ dadone_probebdc(struct cam_periph *periph, union ccb *done_ccb) struct scsi_vpd_block_device_characteristics *bdc; struct da_softc *softc; struct ccb_scsiio *csio; - u_int32_t priority; + uint32_t priority; CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probebdc\n")); @@ -5232,7 +5239,7 @@ dadone_probebdc(struct cam_periph *periph, union ccb *done_ccb) * Disable queue sorting for non-rotational media * by default. */ - u_int16_t old_rate = softc->disk->d_rotation_rate; + uint16_t old_rate = softc->disk->d_rotation_rate; valid_len = csio->dxfer_len - csio->resid; if (SBDC_IS_PRESENT(bdc, valid_len, @@ -5314,7 +5321,7 @@ dadone_probeata(struct cam_periph *periph, union ccb *done_ccb) struct ata_params *ata_params; struct ccb_scsiio *csio; struct da_softc *softc; - u_int32_t priority; + uint32_t priority; int continue_probe; int error; @@ -5453,7 +5460,7 @@ dadone_probeatalogdir(struct cam_periph *periph, union ccb *done_ccb) { struct da_softc *softc; struct ccb_scsiio *csio; - u_int32_t priority; + uint32_t priority; int error; CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatalogdir\n")); @@ -5534,7 +5541,7 @@ dadone_probeataiddir(struct cam_periph *periph, union ccb *done_ccb) { struct da_softc *softc; struct ccb_scsiio *csio; - u_int32_t priority; + uint32_t priority; int error; CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeataiddir\n")); @@ -5625,7 +5632,7 @@ dadone_probeatasup(struct cam_periph *periph, union ccb *done_ccb) { struct da_softc *softc; struct ccb_scsiio *csio; - u_int32_t priority; + uint32_t priority; int error; CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatasup\n")); @@ -5954,7 +5961,7 @@ dareprobe(struct cam_periph *periph) } static int -daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags) +daerror(union ccb *ccb, uint32_t cam_flags, uint32_t sense_flags) { struct da_softc *softc; struct cam_periph *periph; @@ -6318,11 +6325,11 @@ dashutdown(void * arg, int howto) * be moved so they are included both in the kernel and userland. */ void -scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries, +scsi_format_unit(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave, - u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, uint8_t byte2, uint16_t ileave, + uint8_t *data_ptr, uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout) { struct scsi_format_unit *scsi_cmd; @@ -6397,11 +6404,11 @@ scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries, } void -scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries, +scsi_sanitize(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t byte2, u_int16_t control, - u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, uint8_t byte2, uint16_t control, + uint8_t *data_ptr, uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout) { struct scsi_sanitize *scsi_cmd; diff --git a/sys/cam/scsi/scsi_da.h b/sys/cam/scsi/scsi_da.h index 2472eda6dc91..6ce025d15497 100644 --- a/sys/cam/scsi/scsi_da.h +++ b/sys/cam/scsi/scsi_da.h @@ -45,22 +45,19 @@ * functioning of this software in any circumstances. * * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 - * - * $FreeBSD$ */ #ifndef _SCSI_SCSI_DA_H #define _SCSI_SCSI_DA_H 1 -#include <sys/cdefs.h> struct scsi_rezero_unit { - u_int8_t opcode; + uint8_t opcode; #define SRZU_LUN_MASK 0xE0 - u_int8_t byte2; - u_int8_t reserved[3]; - u_int8_t control; + uint8_t byte2; + uint8_t reserved[3]; + uint8_t control; }; /* @@ -69,25 +66,25 @@ struct scsi_rezero_unit */ struct scsi_format_unit { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define FU_FORMAT_MASK SRDD10_DLIST_FORMAT_MASK #define FU_BLOCK_FORMAT SRDD10_BLOCK_FORMAT #define FU_BFI_FORMAT SRDD10_BYTES_FROM_INDEX_FORMAT #define FU_PHYS_FORMAT SRDD10_PHYSICAL_SECTOR_FORMAT #define FU_CMPLST 0x08 #define FU_FMT_DATA 0x10 - u_int8_t vendor_specific; - u_int8_t interleave[2]; - u_int8_t control; + uint8_t vendor_specific; + uint8_t interleave[2]; + uint8_t control; }; struct scsi_reassign_blocks { - u_int8_t opcode; - u_int8_t byte2; - u_int8_t unused[3]; - u_int8_t control; + uint8_t opcode; + uint8_t byte2; + uint8_t unused[3]; + uint8_t control; }; struct scsi_read_defect_data_10 @@ -113,25 +110,25 @@ struct scsi_read_defect_data_10 struct scsi_sanitize { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define SSZ_SERVICE_ACTION_OVERWRITE 0x01 #define SSZ_SERVICE_ACTION_BLOCK_ERASE 0x02 #define SSZ_SERVICE_ACTION_CRYPTO_ERASE 0x03 #define SSZ_SERVICE_ACTION_EXIT_MODE_FAILURE 0x1F #define SSZ_UNRESTRICTED_EXIT 0x20 #define SSZ_IMMED 0x80 - u_int8_t reserved[5]; - u_int8_t length[2]; - u_int8_t control; + uint8_t reserved[5]; + uint8_t length[2]; + uint8_t control; }; struct scsi_sanitize_parameter_list { - u_int8_t byte1; + uint8_t byte1; #define SSZPL_INVERT 0x80 - u_int8_t reserved; - u_int8_t length[2]; + uint8_t reserved; + uint8_t length[2]; /* Variable length initialization pattern. */ #define SSZPL_MAX_PATTERN_LENGTH 65535 }; @@ -251,8 +248,8 @@ struct scsi_report_zones_hdr { struct format_defect_list_header { - u_int8_t reserved; - u_int8_t byte2; + uint8_t reserved; + uint8_t byte2; #define FU_DLH_VS 0x01 #define FU_DLH_IMMED 0x02 #define FU_DLH_DSP 0x04 @@ -261,20 +258,20 @@ struct format_defect_list_header #define FU_DLH_DCRT 0x20 #define FU_DLH_DPRY 0x40 #define FU_DLH_FOV 0x80 - u_int8_t defect_list_length[2]; + uint8_t defect_list_length[2]; }; struct format_ipat_descriptor { - u_int8_t byte1; + uint8_t byte1; #define FU_INIT_NO_HDR 0x00 #define FU_INIT_LBA_MSB 0x40 #define FU_INIT_LBA_EACH 0x80 #define FU_INIT_SI 0x20 - u_int8_t pattern_type; + uint8_t pattern_type; #define FU_INIT_PAT_DEFAULT 0x00 #define FU_INIT_PAT_REPEAT 0x01 - u_int8_t pat_length[2]; + uint8_t pat_length[2]; }; struct scsi_read_format_capacities @@ -386,10 +383,10 @@ struct format_capacity_descriptor { struct scsi_reassign_blocks_data { - u_int8_t reserved[2]; - u_int8_t length[2]; + uint8_t reserved[2]; + uint8_t length[2]; struct { - u_int8_t dlbaddr[4]; /* defect logical block address */ + uint8_t dlbaddr[4]; /* defect logical block address */ } defect_descriptor[1]; }; @@ -400,61 +397,61 @@ struct scsi_reassign_blocks_data */ struct scsi_read_defect_data_hdr_10 { - u_int8_t reserved; + uint8_t reserved; #define SRDDH10_GLIST 0x08 #define SRDDH10_PLIST 0x10 #define SRDDH10_DLIST_FORMAT_MASK 0x07 #define SRDDH10_BLOCK_FORMAT 0x00 #define SRDDH10_BYTES_FROM_INDEX_FORMAT 0x04 #define SRDDH10_PHYSICAL_SECTOR_FORMAT 0x05 - u_int8_t format; - u_int8_t length[2]; + uint8_t format; + uint8_t length[2]; #define SRDDH10_MAX_LENGTH SRDD10_MAX_LENGTH - \ sizeof(struct scsi_read_defect_data_hdr_10) }; struct scsi_defect_desc_block { - u_int8_t address[4]; + uint8_t address[4]; }; struct scsi_defect_desc_long_block { - u_int8_t address[8]; + uint8_t address[8]; }; struct scsi_defect_desc_bytes_from_index { - u_int8_t cylinder[3]; - u_int8_t head; + uint8_t cylinder[3]; + uint8_t head; #define SDD_EXT_BFI_MADS 0x80000000 #define SDD_EXT_BFI_FLAG_MASK 0xf0000000 #define SDD_EXT_BFI_ENTIRE_TRACK 0x0fffffff - u_int8_t bytes_from_index[4]; + uint8_t bytes_from_index[4]; }; struct scsi_defect_desc_phys_sector { - u_int8_t cylinder[3]; - u_int8_t head; + uint8_t cylinder[3]; + uint8_t head; #define SDD_EXT_PHYS_MADS 0x80000000 #define SDD_EXT_PHYS_FLAG_MASK 0xf0000000 #define SDD_EXT_PHYS_ENTIRE_TRACK 0x0fffffff - u_int8_t sector[4]; + uint8_t sector[4]; }; struct scsi_read_defect_data_hdr_12 { - u_int8_t reserved; + uint8_t reserved; #define SRDDH12_GLIST 0x08 #define SRDDH12_PLIST 0x10 #define SRDDH12_DLIST_FORMAT_MASK 0x07 #define SRDDH12_BLOCK_FORMAT 0x00 #define SRDDH12_BYTES_FROM_INDEX_FORMAT 0x04 #define SRDDH12_PHYSICAL_SECTOR_FORMAT 0x05 - u_int8_t format; - u_int8_t generation[2]; - u_int8_t length[4]; + uint8_t format; + uint8_t generation[2]; + uint8_t length[4]; #define SRDDH12_MAX_LENGTH SRDD12_MAX_LENGTH - \ sizeof(struct scsi_read_defect_data_hdr_12) }; @@ -462,100 +459,100 @@ struct scsi_read_defect_data_hdr_12 union disk_pages /* this is the structure copied from osf */ { struct format_device_page { - u_int8_t pg_code; /* page code (should be 3) */ + uint8_t pg_code; /* page code (should be 3) */ #define SMS_FORMAT_DEVICE_PAGE 0x03 /* only 6 bits valid */ - u_int8_t pg_length; /* page length (should be 0x16) */ + uint8_t pg_length; /* page length (should be 0x16) */ #define SMS_FORMAT_DEVICE_PLEN 0x16 - u_int8_t trk_z_1; /* tracks per zone (MSB) */ - u_int8_t trk_z_0; /* tracks per zone (LSB) */ - u_int8_t alt_sec_1; /* alternate sectors per zone (MSB) */ - u_int8_t alt_sec_0; /* alternate sectors per zone (LSB) */ - u_int8_t alt_trk_z_1; /* alternate tracks per zone (MSB) */ - u_int8_t alt_trk_z_0; /* alternate tracks per zone (LSB) */ - u_int8_t alt_trk_v_1; /* alternate tracks per volume (MSB) */ - u_int8_t alt_trk_v_0; /* alternate tracks per volume (LSB) */ - u_int8_t ph_sec_t_1; /* physical sectors per track (MSB) */ - u_int8_t ph_sec_t_0; /* physical sectors per track (LSB) */ - u_int8_t bytes_s_1; /* bytes per sector (MSB) */ - u_int8_t bytes_s_0; /* bytes per sector (LSB) */ - u_int8_t interleave_1; /* interleave (MSB) */ - u_int8_t interleave_0; /* interleave (LSB) */ - u_int8_t trk_skew_1; /* track skew factor (MSB) */ - u_int8_t trk_skew_0; /* track skew factor (LSB) */ - u_int8_t cyl_skew_1; /* cylinder skew (MSB) */ - u_int8_t cyl_skew_0; /* cylinder skew (LSB) */ - u_int8_t flags; /* various */ + uint8_t trk_z_1; /* tracks per zone (MSB) */ + uint8_t trk_z_0; /* tracks per zone (LSB) */ + uint8_t alt_sec_1; /* alternate sectors per zone (MSB) */ + uint8_t alt_sec_0; /* alternate sectors per zone (LSB) */ + uint8_t alt_trk_z_1; /* alternate tracks per zone (MSB) */ + uint8_t alt_trk_z_0; /* alternate tracks per zone (LSB) */ + uint8_t alt_trk_v_1; /* alternate tracks per volume (MSB) */ + uint8_t alt_trk_v_0; /* alternate tracks per volume (LSB) */ + uint8_t ph_sec_t_1; /* physical sectors per track (MSB) */ + uint8_t ph_sec_t_0; /* physical sectors per track (LSB) */ + uint8_t bytes_s_1; /* bytes per sector (MSB) */ + uint8_t bytes_s_0; /* bytes per sector (LSB) */ + uint8_t interleave_1; /* interleave (MSB) */ + uint8_t interleave_0; /* interleave (LSB) */ + uint8_t trk_skew_1; /* track skew factor (MSB) */ + uint8_t trk_skew_0; /* track skew factor (LSB) */ + uint8_t cyl_skew_1; /* cylinder skew (MSB) */ + uint8_t cyl_skew_0; /* cylinder skew (LSB) */ + uint8_t flags; /* various */ #define DISK_FMT_SURF 0x10 #define DISK_FMT_RMB 0x20 #define DISK_FMT_HSEC 0x40 #define DISK_FMT_SSEC 0x80 - u_int8_t reserved21; - u_int8_t reserved22; - u_int8_t reserved23; + uint8_t reserved21; + uint8_t reserved22; + uint8_t reserved23; } format_device; struct rigid_geometry_page { - u_int8_t pg_code; /* page code (should be 4) */ + uint8_t pg_code; /* page code (should be 4) */ #define SMS_RIGID_GEOMETRY_PAGE 0x04 - u_int8_t pg_length; /* page length (should be 0x16) */ + uint8_t pg_length; /* page length (should be 0x16) */ #define SMS_RIGID_GEOMETRY_PLEN 0x16 - u_int8_t ncyl_2; /* number of cylinders (MSB) */ - u_int8_t ncyl_1; /* number of cylinders */ - u_int8_t ncyl_0; /* number of cylinders (LSB) */ - u_int8_t nheads; /* number of heads */ - u_int8_t st_cyl_wp_2; /* starting cyl., write precomp (MSB) */ - u_int8_t st_cyl_wp_1; /* starting cyl., write precomp */ - u_int8_t st_cyl_wp_0; /* starting cyl., write precomp (LSB) */ - u_int8_t st_cyl_rwc_2; /* starting cyl., red. write cur (MSB)*/ - u_int8_t st_cyl_rwc_1; /* starting cyl., red. write cur */ - u_int8_t st_cyl_rwc_0; /* starting cyl., red. write cur (LSB)*/ - u_int8_t driv_step_1; /* drive step rate (MSB) */ - u_int8_t driv_step_0; /* drive step rate (LSB) */ - u_int8_t land_zone_2; /* landing zone cylinder (MSB) */ - u_int8_t land_zone_1; /* landing zone cylinder */ - u_int8_t land_zone_0; /* landing zone cylinder (LSB) */ - u_int8_t rpl; /* rotational position locking (2 bits) */ - u_int8_t rot_offset; /* rotational offset */ - u_int8_t reserved19; - u_int8_t medium_rot_rate_1; /* medium rotation rate (RPM) (MSB) */ - u_int8_t medium_rot_rate_0; /* medium rotation rate (RPM) (LSB) */ - u_int8_t reserved22; - u_int8_t reserved23; + uint8_t ncyl_2; /* number of cylinders (MSB) */ + uint8_t ncyl_1; /* number of cylinders */ + uint8_t ncyl_0; /* number of cylinders (LSB) */ + uint8_t nheads; /* number of heads */ + uint8_t st_cyl_wp_2; /* starting cyl., write precomp (MSB) */ + uint8_t st_cyl_wp_1; /* starting cyl., write precomp */ + uint8_t st_cyl_wp_0; /* starting cyl., write precomp (LSB) */ + uint8_t st_cyl_rwc_2; /* starting cyl., red. write cur (MSB)*/ + uint8_t st_cyl_rwc_1; /* starting cyl., red. write cur */ + uint8_t st_cyl_rwc_0; /* starting cyl., red. write cur (LSB)*/ + uint8_t driv_step_1; /* drive step rate (MSB) */ + uint8_t driv_step_0; /* drive step rate (LSB) */ + uint8_t land_zone_2; /* landing zone cylinder (MSB) */ + uint8_t land_zone_1; /* landing zone cylinder */ + uint8_t land_zone_0; /* landing zone cylinder (LSB) */ + uint8_t rpl; /* rotational position locking (2 bits) */ + uint8_t rot_offset; /* rotational offset */ + uint8_t reserved19; + uint8_t medium_rot_rate_1; /* medium rotation rate (RPM) (MSB) */ + uint8_t medium_rot_rate_0; /* medium rotation rate (RPM) (LSB) */ + uint8_t reserved22; + uint8_t reserved23; } rigid_geometry; struct flexible_disk_page { - u_int8_t pg_code; /* page code (should be 5) */ + uint8_t pg_code; /* page code (should be 5) */ #define SMS_FLEXIBLE_GEOMETRY_PAGE 0x05 - u_int8_t pg_length; /* page length (should be 0x1E) */ + uint8_t pg_length; /* page length (should be 0x1E) */ #define SMS_FLEXIBLE_GEOMETRY_PLEN 0x1E - u_int8_t xfr_rate_1; /* transfer rate (MSB) */ - u_int8_t xfr_rate_0; /* transfer rate (LSB) */ - u_int8_t nheads; /* number of heads */ - u_int8_t sec_per_track; /* Sectors per track */ - u_int8_t bytes_s_1; /* bytes per sector (MSB) */ - u_int8_t bytes_s_0; /* bytes per sector (LSB) */ - u_int8_t ncyl_1; /* number of cylinders (MSB) */ - u_int8_t ncyl_0; /* number of cylinders (LSB) */ - u_int8_t st_cyl_wp_1; /* starting cyl., write precomp (MSB) */ - u_int8_t st_cyl_wp_0; /* starting cyl., write precomp (LSB) */ - u_int8_t st_cyl_rwc_1; /* starting cyl., red. write cur (MSB)*/ - u_int8_t st_cyl_rwc_0; /* starting cyl., red. write cur (LSB)*/ - u_int8_t driv_step_1; /* drive step rate (MSB) */ - u_int8_t driv_step_0; /* drive step rate (LSB) */ - u_int8_t driv_step_pw; /* drive step pulse width */ - u_int8_t head_stl_del_1;/* Head settle delay (MSB) */ - u_int8_t head_stl_del_0;/* Head settle delay (LSB) */ - u_int8_t motor_on_del; /* Motor on delay */ - u_int8_t motor_off_del; /* Motor off delay */ - u_int8_t trdy_ssn_mo; /* XXX ??? */ - u_int8_t spc; /* XXX ??? */ - u_int8_t write_comp; /* Write compensation */ - u_int8_t head_load_del; /* Head load delay */ - u_int8_t head_uload_del;/* Head un-load delay */ - u_int8_t pin32_pin2; - u_int8_t pin4_pint1; - u_int8_t medium_rot_rate_1; /* medium rotation rate (RPM) (MSB) */ - u_int8_t medium_rot_rate_0; /* medium rotation rate (RPM) (LSB) */ - u_int8_t reserved30; - u_int8_t reserved31; + uint8_t xfr_rate_1; /* transfer rate (MSB) */ + uint8_t xfr_rate_0; /* transfer rate (LSB) */ + uint8_t nheads; /* number of heads */ + uint8_t sec_per_track; /* Sectors per track */ + uint8_t bytes_s_1; /* bytes per sector (MSB) */ + uint8_t bytes_s_0; /* bytes per sector (LSB) */ + uint8_t ncyl_1; /* number of cylinders (MSB) */ + uint8_t ncyl_0; /* number of cylinders (LSB) */ + uint8_t st_cyl_wp_1; /* starting cyl., write precomp (MSB) */ + uint8_t st_cyl_wp_0; /* starting cyl., write precomp (LSB) */ + uint8_t st_cyl_rwc_1; /* starting cyl., red. write cur (MSB)*/ + uint8_t st_cyl_rwc_0; /* starting cyl., red. write cur (LSB)*/ + uint8_t driv_step_1; /* drive step rate (MSB) */ + uint8_t driv_step_0; /* drive step rate (LSB) */ + uint8_t driv_step_pw; /* drive step pulse width */ + uint8_t head_stl_del_1;/* Head settle delay (MSB) */ + uint8_t head_stl_del_0;/* Head settle delay (LSB) */ + uint8_t motor_on_del; /* Motor on delay */ + uint8_t motor_off_del; /* Motor off delay */ + uint8_t trdy_ssn_mo; /* XXX ??? */ + uint8_t spc; /* XXX ??? */ + uint8_t write_comp; /* Write compensation */ + uint8_t head_load_del; /* Head load delay */ + uint8_t head_uload_del;/* Head un-load delay */ + uint8_t pin32_pin2; + uint8_t pin4_pint1; + uint8_t medium_rot_rate_1; /* medium rotation rate (RPM) (MSB) */ + uint8_t medium_rot_rate_0; /* medium rotation rate (RPM) (LSB) */ + uint8_t reserved30; + uint8_t reserved31; } flexible_disk; }; @@ -609,10 +606,10 @@ struct scsi_rigid_disk_page { }; struct scsi_da_rw_recovery_page { - u_int8_t page_code; + uint8_t page_code; #define SMS_RW_ERROR_RECOVERY_PAGE 0x01 - u_int8_t page_length; - u_int8_t byte3; + uint8_t page_length; + uint8_t byte3; #define SMS_RWER_AWRE 0x80 #define SMS_RWER_ARRE 0x40 #define SMS_RWER_TB 0x20 @@ -621,29 +618,29 @@ struct scsi_da_rw_recovery_page { #define SMS_RWER_PER 0x04 #define SMS_RWER_DTE 0x02 #define SMS_RWER_DCR 0x01 - u_int8_t read_retry_count; - u_int8_t correction_span; - u_int8_t head_offset_count; - u_int8_t data_strobe_offset_cnt; - u_int8_t byte8; + uint8_t read_retry_count; + uint8_t correction_span; + uint8_t head_offset_count; + uint8_t data_strobe_offset_cnt; + uint8_t byte8; #define SMS_RWER_LBPERE 0x80 - u_int8_t write_retry_count; - u_int8_t reserved2; - u_int8_t recovery_time_limit[2]; + uint8_t write_retry_count; + uint8_t reserved2; + uint8_t recovery_time_limit[2]; }; struct scsi_da_verify_recovery_page { - u_int8_t page_code; + uint8_t page_code; #define SMS_VERIFY_ERROR_RECOVERY_PAGE 0x07 - u_int8_t page_length; - u_int8_t byte3; + uint8_t page_length; + uint8_t byte3; #define SMS_VER_EER 0x08 #define SMS_VER_PER 0x04 #define SMS_VER_DTE 0x02 #define SMS_VER_DCR 0x01 - u_int8_t read_retry_count; - u_int8_t reserved[6]; - u_int8_t recovery_time_limit[2]; + uint8_t read_retry_count; + uint8_t reserved[6]; + uint8_t recovery_time_limit[2]; }; __BEGIN_DECLS @@ -653,11 +650,11 @@ __BEGIN_DECLS * be moved so they are included both in the kernel and userland. */ #ifndef _KERNEL -void scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_format_unit(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave, - u_int8_t *data_ptr, u_int32_t dxfer_len, - u_int8_t sense_len, u_int32_t timeout); + uint8_t tag_action, uint8_t byte2, uint16_t ileave, + uint8_t *data_ptr, uint32_t dxfer_len, + uint8_t sense_len, uint32_t timeout); void scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), @@ -666,11 +663,11 @@ void scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries, uint32_t dxfer_len, int minimum_cmd_size, uint8_t sense_len, uint32_t timeout); -void scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_sanitize(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, u_int8_t byte2, u_int16_t control, - u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout); + uint8_t tag_action, uint8_t byte2, uint16_t control, + uint8_t *data_ptr, uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout); #endif /* !_KERNEL */ diff --git a/sys/cam/scsi/scsi_enc.c b/sys/cam/scsi/scsi_enc.c index b8afdf938a3a..4415e940cd96 100644 --- a/sys/cam/scsi/scsi_enc.c +++ b/sys/cam/scsi/scsi_enc.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2000 Matthew Jacob * All rights reserved. @@ -26,9 +26,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/conf.h> @@ -205,7 +202,7 @@ enc_dtor(struct cam_periph *periph) if (enc->enc_vec.softc_cleanup != NULL) enc->enc_vec.softc_cleanup(enc); - root_mount_rel(&enc->enc_rootmount); + cam_periph_release_boot(periph); ENC_FREE(enc); } @@ -842,7 +839,7 @@ enc_daemon(void *arg) * We've been through our state machine at least * once. Allow the transition to userland. */ - root_mount_rel(&enc->enc_rootmount); + cam_periph_release_boot(enc->periph); callout_reset_sbt(&enc->status_updater, 60 * SBT_1S, 0, enc_status_updater, enc, C_PREL(1)); @@ -937,9 +934,8 @@ enc_ctor(struct cam_periph *periph, void *arg) * through our state machine so that physical path data is * present. */ - if (enc->enc_vec.poll_status != NULL) { - root_mount_hold_token(periph->periph_name, &enc->enc_rootmount); - } + if (enc->enc_vec.poll_status != NULL) + cam_periph_hold_boot(periph); /* * The softc field is set only once the enc is fully initialized diff --git a/sys/cam/scsi/scsi_enc.h b/sys/cam/scsi/scsi_enc.h index f53a99f2b233..73dc272da218 100644 --- a/sys/cam/scsi/scsi_enc.h +++ b/sys/cam/scsi/scsi_enc.h @@ -1,6 +1,5 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD OR GPL-2.0) + * SPDX-License-Identifier: (BSD-2-Clause OR GPL-2.0) * * Copyright (c) 2000 by Matthew Jacob * All rights reserved. diff --git a/sys/cam/scsi/scsi_enc_internal.h b/sys/cam/scsi/scsi_enc_internal.h index e57634d065df..d47b54432abf 100644 --- a/sys/cam/scsi/scsi_enc_internal.h +++ b/sys/cam/scsi/scsi_enc_internal.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2000 Matthew Jacob * All rights reserved. @@ -24,8 +24,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ /* @@ -161,8 +159,6 @@ struct enc_softc { struct enc_fsm_state *enc_fsm_states; - struct root_hold_token enc_rootmount; - #define ENC_ANNOUNCE_SZ 400 char announce_buf[ENC_ANNOUNCE_SZ]; }; diff --git a/sys/cam/scsi/scsi_enc_safte.c b/sys/cam/scsi/scsi_enc_safte.c index 7539531302f9..78c5324fb6eb 100644 --- a/sys/cam/scsi/scsi_enc_safte.c +++ b/sys/cam/scsi/scsi_enc_safte.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2000 Matthew Jacob * All rights reserved. @@ -26,9 +26,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/conf.h> diff --git a/sys/cam/scsi/scsi_enc_ses.c b/sys/cam/scsi/scsi_enc_ses.c index 557038d9b9f6..c429e820a1fd 100644 --- a/sys/cam/scsi/scsi_enc_ses.c +++ b/sys/cam/scsi/scsi_enc_ses.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2000 Matthew Jacob * Copyright (c) 2010 Spectra Logic Corporation @@ -33,9 +33,6 @@ * Structures and routines specific && private to SES only */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/ctype.h> @@ -986,7 +983,7 @@ ses_paths_iter(enc_softc_t *enc, enc_element_t *elm, xpt_setup_ccb(&cgd.ccb_h, path, CAM_PRIORITY_NORMAL); cgd.ccb_h.func_code = XPT_GDEV_TYPE; xpt_action((union ccb *)&cgd); - if (cgd.ccb_h.status == CAM_REQ_CMP) + if (cam_ccb_success((union ccb *)&cgd)) callback(enc, elm, path, callback_arg); xpt_free_path(path); @@ -1065,7 +1062,7 @@ ses_setphyspath_callback(enc_softc_t *enc, enc_element_t *elm, 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_REQ_CMP) + if (cam_ccb_success((union ccb *)&cdai)) args->num_set++; } xpt_path_unlock(path); @@ -2271,12 +2268,12 @@ ses_get_elm_addlstatus_fc(enc_softc_t *enc, enc_cache_t *enc_cache, if (((p) & SES_SASOBJ_DEV_PHY_PROTOMASK) != 0) { \ sbuf_printf(sbp, " %s (", type); \ if ((p) & SES_SASOBJ_DEV_PHY_SMP) \ - sbuf_printf(sbp, " SMP"); \ + sbuf_cat(sbp, " SMP"); \ if ((p) & SES_SASOBJ_DEV_PHY_STP) \ - sbuf_printf(sbp, " STP"); \ + sbuf_cat(sbp, " STP"); \ if ((p) & SES_SASOBJ_DEV_PHY_SSP) \ - sbuf_printf(sbp, " SSP"); \ - sbuf_printf(sbp, " )"); \ + sbuf_cat(sbp, " SSP"); \ + sbuf_cat(sbp, " )"); \ } \ } while(0) @@ -2305,7 +2302,7 @@ ses_print_addl_data_sas_type0(char *sesname, struct sbuf *sbp, if (ses_elm_addlstatus_eip(addl->hdr)) sbuf_printf(sbp, " at slot %d", addl->proto_hdr.sas->type0_eip.dev_slot_num); - sbuf_printf(sbp, "\n"); + sbuf_putc(sbp, '\n'); if (addl->proto_data.sasdev_phys == NULL) return; for (i = 0;i < addl->proto_hdr.sas->base_hdr.num_phys;i++) { @@ -2313,13 +2310,13 @@ ses_print_addl_data_sas_type0(char *sesname, struct sbuf *sbp, sbuf_printf(sbp, "%s: phy %d:", sesname, i); if (ses_elm_sas_dev_phy_sata_dev(phy)) /* Spec says all other fields are specific values */ - sbuf_printf(sbp, " SATA device\n"); + sbuf_cat(sbp, " SATA device\n"); else { sbuf_printf(sbp, " SAS device type %d phy %d", ses_elm_sas_dev_phy_dev_type(phy), phy->phy_id); SES_PRINT_PORTS(phy->initiator_ports, "Initiator"); SES_PRINT_PORTS(phy->target_ports, "Target"); - sbuf_printf(sbp, "\n"); + sbuf_putc(sbp, '\n'); } sbuf_printf(sbp, "%s: phy %d: parent %jx addr %jx\n", sesname, i, @@ -2349,7 +2346,7 @@ ses_print_addl_data_sas_type1(char *sesname, struct sbuf *sbp, elmpriv = obj->elm_private; addl = &(elmpriv->addl); - sbuf_printf(sbp, ", SAS "); + sbuf_cat(sbp, ", SAS "); if (obj->elm_type == ELMTYP_SAS_EXP) { num_phys = addl->proto_hdr.sas->base_hdr.num_phys; sbuf_printf(sbp, "Expander: %d phys", num_phys); @@ -2422,7 +2419,7 @@ ses_print_addl_data(enc_softc_t *enc, enc_element_t *obj) sbuf_new(&out, NULL, 512, SBUF_AUTOEXTEND); ses_paths_iter(enc, obj, ses_elmdevname_callback, &name); if (sbuf_len(&name) == 0) - sbuf_printf(&name, "(none)"); + sbuf_cat(&name, "(none)"); sbuf_finish(&name); sbuf_printf(&sesname, "%s%d", enc->periph->periph_name, enc->periph->unit_number); @@ -2813,8 +2810,8 @@ ses_get_elm_desc(enc_softc_t *enc, encioc_elm_desc_t *elmd) } if (elmd->elm_desc_len > elmpriv->descr_len) elmd->elm_desc_len = elmpriv->descr_len; - copyout(elmpriv->descr, elmd->elm_desc_str, elmd->elm_desc_len); - return (0); + return (copyout(elmpriv->descr, elmd->elm_desc_str, + elmd->elm_desc_len)); } /** @@ -2830,7 +2827,7 @@ static int ses_get_elm_devnames(enc_softc_t *enc, encioc_elm_devnames_t *elmdn) { struct sbuf sb; - int len; + int error, len; len = elmdn->elm_names_size; if (len < 0) @@ -2842,10 +2839,13 @@ ses_get_elm_devnames(enc_softc_t *enc, encioc_elm_devnames_t *elmdn) ses_elmdevname_callback, &sb); sbuf_finish(&sb); elmdn->elm_names_len = sbuf_len(&sb); - copyout(sbuf_data(&sb), elmdn->elm_devnames, elmdn->elm_names_len + 1); + error = copyout(sbuf_data(&sb), elmdn->elm_devnames, + elmdn->elm_names_len + 1); sbuf_delete(&sb); cam_periph_lock(enc->periph); - return (elmdn->elm_names_len > 0 ? 0 : ENODEV); + if (error == 0 && elmdn->elm_names_len == 0) + error = ENODEV; + return (error); } /** @@ -2924,9 +2924,9 @@ ses_handle_string(enc_softc_t *enc, encioc_string_t *sstr, unsigned long ioc) size = rsize; if (size > sstr->bufsiz) size = sstr->bufsiz; - copyout(str, sstr->buf, size); + ret = copyout(str, sstr->buf, size); sstr->bufsiz = rsize; - return (size == rsize ? 0 : ENOMEM); + return (ret != 0 ? ret : (size == rsize ? 0 : ENOMEM)); case ENCIOC_GETENCID: if (ses_cache->ses_nsubencs < 1) return (ENODEV); @@ -2938,9 +2938,9 @@ ses_handle_string(enc_softc_t *enc, encioc_string_t *sstr, unsigned long ioc) size = rsize; if (size > sstr->bufsiz) size = sstr->bufsiz; - copyout(str, sstr->buf, size); + ret = copyout(str, sstr->buf, size); sstr->bufsiz = rsize; - return (size == rsize ? 0 : ENOMEM); + return (ret != 0 ? ret : (size == rsize ? 0 : ENOMEM)); default: return (EINVAL); } diff --git a/sys/cam/scsi/scsi_iu.h b/sys/cam/scsi/scsi_iu.h index 7e577715d550..243be20aa085 100644 --- a/sys/cam/scsi/scsi_iu.h +++ b/sys/cam/scsi/scsi_iu.h @@ -1,20 +1,19 @@ /*- * This file is in the public domain. - * $FreeBSD$ */ #ifndef _SCSI_SCSI_IU_H #define _SCSI_SCSI_IU_H 1 struct scsi_status_iu_header { - u_int8_t reserved[2]; - u_int8_t flags; + uint8_t reserved[2]; + uint8_t flags; #define SIU_SNSVALID 0x2 #define SIU_RSPVALID 0x1 - u_int8_t status; - u_int8_t sense_length[4]; - u_int8_t pkt_failures_length[4]; - u_int8_t pkt_failures[1]; + uint8_t status; + uint8_t sense_length[4]; + uint8_t pkt_failures_length[4]; + uint8_t pkt_failures[1]; }; #define SIU_PKTFAIL_OFFSET(siu) 12 diff --git a/sys/cam/scsi/scsi_message.h b/sys/cam/scsi/scsi_message.h index c6fb7fca4c2e..6ecacc96281e 100644 --- a/sys/cam/scsi/scsi_message.h +++ b/sys/cam/scsi/scsi_message.h @@ -1,6 +1,5 @@ /*- * This file is in the public domain. - * $FreeBSD$ */ /* Messages (1 byte) */ /* I/T (M)andatory or (O)ptional */ diff --git a/sys/cam/scsi/scsi_pass.c b/sys/cam/scsi/scsi_pass.c index 7f66ca458bd7..5a24f11e60e2 100644 --- a/sys/cam/scsi/scsi_pass.c +++ b/sys/cam/scsi/scsi_pass.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997, 1998, 2000 Justin T. Gibbs. * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry. @@ -27,9 +27,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> @@ -128,7 +125,7 @@ struct pass_io_req { struct pass_softc { pass_state state; pass_flags flags; - u_int8_t pd_type; + uint8_t pd_type; int open_count; u_int maxio; struct devstat *device_stats; @@ -165,7 +162,7 @@ static periph_dtor_t passcleanup; static periph_start_t passstart; static void pass_shutdown_kqueue(void *context, int pending); static void pass_add_physpath(void *context, int pending); -static void passasync(void *callback_arg, u_int32_t code, +static void passasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg); static void passdone(struct cam_periph *periph, union ccb *done_ccb); @@ -179,10 +176,12 @@ static int passmemsetup(struct cam_periph *periph, struct pass_io_req *io_req); static int passmemdone(struct cam_periph *periph, struct pass_io_req *io_req); -static int passerror(union ccb *ccb, u_int32_t cam_flags, - u_int32_t sense_flags); +static int passerror(union ccb *ccb, uint32_t cam_flags, + uint32_t sense_flags); static int passsendccb(struct cam_periph *periph, union ccb *ccb, union ccb *inccb); +static void passflags(union ccb *ccb, uint32_t *cam_flags, + uint32_t *sense_flags); static struct periph_driver passdriver = { @@ -483,7 +482,7 @@ out: } static void -passasync(void *callback_arg, u_int32_t code, +passasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg) { struct cam_periph *periph; @@ -912,19 +911,17 @@ passdone(struct cam_periph *periph, union ccb *done_ccb) xpt_print(periph->path, "%s: called for user CCB %p\n", __func__, io_req->user_ccb_ptr); #endif - if (((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) - && (done_ccb->ccb_h.flags & CAM_PASS_ERR_RECOVER) - && ((io_req->flags & PASS_IO_ABANDONED) == 0)) { + if (((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) && + ((io_req->flags & PASS_IO_ABANDONED) == 0)) { int error; + uint32_t cam_flags, sense_flags; - error = passerror(done_ccb, CAM_RETRY_SELTO, - SF_RETRY_UA | SF_NO_PRINT); + passflags(done_ccb, &cam_flags, &sense_flags); + error = passerror(done_ccb, cam_flags, sense_flags); if (error == ERESTART) { - /* - * A retry was scheduled, so - * just return. - */ + KASSERT(((sense_flags & SF_NO_RETRY) == 0), + ("passerror returned ERESTART with no retry requested\n")); return; } } @@ -1120,7 +1117,7 @@ static void passiocleanup(struct pass_softc *softc, struct pass_io_req *io_req) { union ccb *ccb; - u_int8_t **data_ptrs[CAM_PERIPH_MAXMAPS]; + uint8_t **data_ptrs[CAM_PERIPH_MAXMAPS]; int i, numbufs; ccb = &io_req->ccb; @@ -1130,10 +1127,10 @@ passiocleanup(struct pass_softc *softc, struct pass_io_req *io_req) numbufs = min(io_req->num_bufs, 2); if (numbufs == 1) { - data_ptrs[0] = (u_int8_t **)&ccb->cdm.matches; + data_ptrs[0] = (uint8_t **)&ccb->cdm.matches; } else { - data_ptrs[0] = (u_int8_t **)&ccb->cdm.patterns; - data_ptrs[1] = (u_int8_t **)&ccb->cdm.matches; + data_ptrs[0] = (uint8_t **)&ccb->cdm.patterns; + data_ptrs[1] = (uint8_t **)&ccb->cdm.matches; } break; case XPT_SCSI_IO: @@ -1308,15 +1305,15 @@ passmemsetup(struct cam_periph *periph, struct pass_io_req *io_req) return(EINVAL); } if (ccb->cdm.pattern_buf_len > 0) { - data_ptrs[0] = (u_int8_t **)&ccb->cdm.patterns; + data_ptrs[0] = (uint8_t **)&ccb->cdm.patterns; lengths[0] = ccb->cdm.pattern_buf_len; dirs[0] = CAM_DIR_OUT; - data_ptrs[1] = (u_int8_t **)&ccb->cdm.matches; + data_ptrs[1] = (uint8_t **)&ccb->cdm.matches; lengths[1] = ccb->cdm.match_buf_len; dirs[1] = CAM_DIR_IN; numbufs = 2; } else { - data_ptrs[0] = (u_int8_t **)&ccb->cdm.matches; + data_ptrs[0] = (uint8_t **)&ccb->cdm.matches; lengths[0] = ccb->cdm.match_buf_len; dirs[0] = CAM_DIR_IN; numbufs = 1; @@ -2230,24 +2227,46 @@ passsendccb(struct cam_periph *periph, union ccb *ccb, union ccb *inccb) * that request. Otherwise, it's up to the user to perform any * error recovery. */ - cam_periph_runccb(ccb, (ccb->ccb_h.flags & CAM_PASS_ERR_RECOVER) ? - passerror : NULL, /* cam_flags */ CAM_RETRY_SELTO, - /* sense_flags */ SF_RETRY_UA | SF_NO_PRINT, - softc->device_stats); + { + uint32_t cam_flags, sense_flags; + + passflags(ccb, &cam_flags, &sense_flags); + cam_periph_runccb(ccb, passerror, cam_flags, + sense_flags, softc->device_stats); + } cam_periph_unlock(periph); - cam_periph_unmapmem(ccb, &mapinfo); + error = cam_periph_unmapmem(ccb, &mapinfo); cam_periph_lock(periph); ccb->ccb_h.cbfcnp = NULL; ccb->ccb_h.periph_priv = inccb->ccb_h.periph_priv; bcopy(ccb, inccb, sizeof(union ccb)); - return(0); + return (error); +} + +/* + * Set the cam_flags and sense_flags based on whether or not the request wants + * error recovery. In order to log errors via devctl, we need to do at least + * minimal recovery. We do this by not retrying unit attention (we let the + * requester do it, or not, if appropriate) and specifically asking for no + * recovery, like we do during device probing. + */ +static void +passflags(union ccb *ccb, uint32_t *cam_flags, uint32_t *sense_flags) +{ + if ((ccb->ccb_h.flags & CAM_PASS_ERR_RECOVER) != 0) { + *cam_flags = CAM_RETRY_SELTO; + *sense_flags = SF_RETRY_UA | SF_NO_PRINT; + } else { + *cam_flags = 0; + *sense_flags = SF_NO_RETRY | SF_NO_RECOVERY | SF_NO_PRINT; + } } static int -passerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags) +passerror(union ccb *ccb, uint32_t cam_flags, uint32_t sense_flags) { return(cam_periph_error(ccb, cam_flags, sense_flags)); diff --git a/sys/cam/scsi/scsi_pass.h b/sys/cam/scsi/scsi_pass.h index 8fd7079e357c..3a69486c7c56 100644 --- a/sys/cam/scsi/scsi_pass.h +++ b/sys/cam/scsi/scsi_pass.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997, 1999 Kenneth D. Merry. * All rights reserved. @@ -23,8 +23,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _SCSI_PASS_H diff --git a/sys/cam/scsi/scsi_pt.c b/sys/cam/scsi/scsi_pt.c index 515bfc4b0aba..57d9df3f9dc1 100644 --- a/sys/cam/scsi/scsi_pt.c +++ b/sys/cam/scsi/scsi_pt.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Implementation of SCSI Processor Target Peripheral driver for CAM. * @@ -28,9 +28,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/queue.h> #include <sys/systm.h> @@ -90,7 +87,7 @@ static d_open_t ptopen; static d_close_t ptclose; static d_strategy_t ptstrategy; static periph_init_t ptinit; -static void ptasync(void *callback_arg, u_int32_t code, +static void ptasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg); static periph_ctor_t ptctor; static periph_oninv_t ptoninvalidate; @@ -99,14 +96,14 @@ static periph_start_t ptstart; static void ptdone(struct cam_periph *periph, union ccb *done_ccb); static d_ioctl_t ptioctl; -static int pterror(union ccb *ccb, u_int32_t cam_flags, - u_int32_t sense_flags); +static int pterror(union ccb *ccb, uint32_t cam_flags, + uint32_t sense_flags); -void scsi_send_receive(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_send_receive(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int tag_action, int readop, u_int byte2, - u_int32_t xfer_len, u_int8_t *data_ptr, - u_int8_t sense_len, u_int32_t timeout); + uint32_t xfer_len, uint8_t *data_ptr, + uint8_t sense_len, uint32_t timeout); static struct periph_driver ptdriver = { @@ -356,7 +353,7 @@ ptdtor(struct cam_periph *periph) } static void -ptasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg) +ptasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg) { struct cam_periph *periph; @@ -558,7 +555,7 @@ ptdone(struct cam_periph *periph, union ccb *done_ccb) } static int -pterror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags) +pterror(union ccb *ccb, uint32_t cam_flags, uint32_t sense_flags) { return(cam_periph_error(ccb, cam_flags, sense_flags)); @@ -603,11 +600,11 @@ ptioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td) } void -scsi_send_receive(struct ccb_scsiio *csio, u_int32_t retries, +scsi_send_receive(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int tag_action, int readop, u_int byte2, - u_int32_t xfer_len, u_int8_t *data_ptr, u_int8_t sense_len, - u_int32_t timeout) + uint32_t xfer_len, uint8_t *data_ptr, uint8_t sense_len, + uint32_t timeout) { struct scsi_send_receive *scsi_cmd; diff --git a/sys/cam/scsi/scsi_pt.h b/sys/cam/scsi/scsi_pt.h index b05f8590adf5..5c9e032ce02c 100644 --- a/sys/cam/scsi/scsi_pt.h +++ b/sys/cam/scsi/scsi_pt.h @@ -1,7 +1,7 @@ /*- * Structure and function declarations for Processor type devices. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1998 Justin T. Gibbs * All rights reserved. @@ -26,8 +26,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _SCSI_SCSI_PT_H @@ -35,10 +33,10 @@ struct scsi_send_receive { - u_int8_t opcode; - u_int8_t byte2; - u_int8_t xfer_len[3]; - u_int8_t control; + uint8_t opcode; + uint8_t byte2; + uint8_t xfer_len[3]; + uint8_t control; }; /* diff --git a/sys/cam/scsi/scsi_sa.c b/sys/cam/scsi/scsi_sa.c index 04d013d03a30..cfd48c98f30e 100644 --- a/sys/cam/scsi/scsi_sa.c +++ b/sys/cam/scsi/scsi_sa.c @@ -1,7 +1,7 @@ /*- * Implementation of SCSI Sequential Access Peripheral driver for CAM. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1999, 2000 Matthew Jacob * Copyright (c) 2013, 2014, 2015, 2021 Spectra Logic Corporation @@ -29,9 +29,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/queue.h> #ifdef _KERNEL @@ -392,22 +389,22 @@ struct sa_softc { int blk_gran; int blk_mask; int blk_shift; - u_int32_t max_blk; - u_int32_t min_blk; - u_int32_t maxio; - u_int32_t cpi_maxio; + uint32_t max_blk; + uint32_t min_blk; + uint32_t maxio; + uint32_t cpi_maxio; int allow_io_split; int inject_eom; int set_pews_status; - u_int32_t comp_algorithm; - u_int32_t saved_comp_algorithm; - u_int32_t media_blksize; - u_int32_t last_media_blksize; - u_int32_t media_numblks; - u_int8_t media_density; - u_int8_t speed; - u_int8_t scsi_rev; - u_int8_t dsreg; /* mtio mt_dsreg, redux */ + uint32_t comp_algorithm; + uint32_t saved_comp_algorithm; + uint32_t media_blksize; + uint32_t last_media_blksize; + uint32_t media_numblks; + uint8_t media_density; + uint8_t speed; + uint8_t scsi_rev; + uint8_t dsreg; /* mtio mt_dsreg, redux */ int buffer_mode; int filemarks; int last_resid_was_io; @@ -449,11 +446,11 @@ struct sa_softc { */ struct { struct scsi_sense_data _last_io_sense; - u_int64_t _last_io_resid; - u_int8_t _last_io_cdb[CAM_MAX_CDBLEN]; + uint64_t _last_io_resid; + uint8_t _last_io_cdb[CAM_MAX_CDBLEN]; struct scsi_sense_data _last_ctl_sense; - u_int64_t _last_ctl_resid; - u_int8_t _last_ctl_cdb[CAM_MAX_CDBLEN]; + uint64_t _last_ctl_resid; + uint8_t _last_ctl_cdb[CAM_MAX_CDBLEN]; #define last_io_sense errinfo._last_io_sense #define last_io_resid errinfo._last_io_resid #define last_io_cdb errinfo._last_io_cdb @@ -464,7 +461,7 @@ struct sa_softc { /* * Misc other flags/state */ - u_int32_t + uint32_t : 29, open_rdonly : 1, /* open read-only */ open_pending_mount : 1, /* open pending mount */ @@ -480,7 +477,7 @@ struct sa_softc { struct sa_quirk_entry { struct scsi_inquiry_pattern inq_pat; /* matching pattern */ sa_quirks quirks; /* specific quirk type */ - u_int32_t prefblk; /* preferred blocksize when in fixed mode */ + uint32_t prefblk; /* preferred blocksize when in fixed mode */ }; static struct sa_quirk_entry sa_quirk_table[] = @@ -596,21 +593,21 @@ static periph_ctor_t saregister; static periph_oninv_t saoninvalidate; static periph_dtor_t sacleanup; static periph_start_t sastart; -static void saasync(void *callback_arg, u_int32_t code, +static void saasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg); static void sadone(struct cam_periph *periph, union ccb *start_ccb); -static int saerror(union ccb *ccb, u_int32_t cam_flags, - u_int32_t sense_flags); +static int saerror(union ccb *ccb, uint32_t cam_flags, + uint32_t sense_flags); static int samarkswanted(struct cam_periph *); static int sacheckeod(struct cam_periph *periph); static int sagetparams(struct cam_periph *periph, sa_params params_to_get, - u_int32_t *blocksize, u_int8_t *density, - u_int32_t *numblocks, int *buff_mode, - u_int8_t *write_protect, u_int8_t *speed, + uint32_t *blocksize, uint8_t *density, + uint32_t *numblocks, int *buff_mode, + uint8_t *write_protect, uint8_t *speed, int *comp_supported, int *comp_enabled, - u_int32_t *comp_algorithm, + uint32_t *comp_algorithm, sa_comp_t *comp_page, struct scsi_control_data_prot_subpage *prot_page, int dp_size, @@ -619,9 +616,9 @@ static int sasetprot(struct cam_periph *periph, struct sa_prot_state *new_prot); static int sasetparams(struct cam_periph *periph, sa_params params_to_set, - u_int32_t blocksize, u_int8_t density, - u_int32_t comp_algorithm, - u_int32_t sense_flags); + uint32_t blocksize, uint8_t density, + uint32_t comp_algorithm, + uint32_t sense_flags); static int sasetsili(struct cam_periph *periph, struct mtparamset *ps, int num_params); static int saseteotwarn(struct cam_periph *periph, @@ -635,7 +632,7 @@ static struct sa_prot_map *safindprotent(char *name, struct sa_prot_map *table, int table_ents); static int sasetprotents(struct cam_periph *periph, struct mtparamset *ps, int num_params); -static struct sa_param_ent *safindparament(struct mtparamset *ps); +static const struct sa_param_ent *safindparament(struct mtparamset *ps); static int saparamsetlist(struct cam_periph *periph, struct mtsetlist *list, int need_copy); static int saextget(struct cdev *dev, struct cam_periph *periph, @@ -658,7 +655,7 @@ static int saerase(struct cam_periph *periph, int longerase); static int sawritefilemarks(struct cam_periph *periph, int nmarks, int setmarks, int immed); static int sagetpos(struct cam_periph *periph); -static int sardpos(struct cam_periph *periph, int, u_int32_t *); +static int sardpos(struct cam_periph *periph, int, uint32_t *); static int sasetpos(struct cam_periph *periph, int, struct mtlocate *); static void safilldenstypesb(struct sbuf *sb, int *indent, @@ -1358,7 +1355,7 @@ typedef enum { SA_PARAM_TYPE_NODE } sa_param_type; -struct sa_param_ent { +static const struct sa_param_ent { char *name; sa_param_type param_type; int (*set_func)(struct cam_periph *periph, struct mtparamset *ps, @@ -1369,7 +1366,7 @@ struct sa_param_ent { {"protection.", SA_PARAM_TYPE_NODE, sasetprotents } }; -static struct sa_param_ent * +static const struct sa_param_ent * safindparament(struct mtparamset *ps) { unsigned int i; @@ -1405,7 +1402,7 @@ saparamsetlist(struct cam_periph *periph, struct mtsetlist *list, int i, contig_ents; int error; struct mtparamset *params, *first; - struct sa_param_ent *first_ent; + const struct sa_param_ent *first_ent; error = 0; params = NULL; @@ -1446,7 +1443,7 @@ saparamsetlist(struct cam_periph *periph, struct mtsetlist *list, first = NULL; first_ent = NULL; for (i = 0; i < list->num_params; i++) { - struct sa_param_ent *ent; + const struct sa_param_ent *ent; ent = safindparament(¶ms[i]); if (ent == NULL) { @@ -1497,8 +1494,12 @@ saparamsetlist(struct cam_periph *periph, struct mtsetlist *list, bailout: if (need_copy != 0) { if (error != EFAULT) { + int error1; + cam_periph_unlock(periph); - copyout(params, list->params, list->param_len); + error1 = copyout(params, list->params, list->param_len); + if (error == 0) + error = error1; cam_periph_lock(periph); } free(params, M_SCSISA); @@ -1510,7 +1511,7 @@ static int sagetparams_common(struct cdev *dev, struct cam_periph *periph) { struct sa_softc *softc; - u_int8_t write_protect; + uint8_t write_protect; int comp_enabled, comp_supported, error; softc = (struct sa_softc *)periph->softc; @@ -2071,11 +2072,11 @@ extget_bailout: break; case MTIOCRDSPOS: PENDING_MOUNT_CHECK(softc, periph, dev); - error = sardpos(periph, 0, (u_int32_t *) arg); + error = sardpos(periph, 0, (uint32_t *) arg); break; case MTIOCRDHPOS: PENDING_MOUNT_CHECK(softc, periph, dev); - error = sardpos(periph, 1, (u_int32_t *) arg); + error = sardpos(periph, 1, (uint32_t *) arg); break; case MTIOCSLOCATE: case MTIOCHLOCATE: { @@ -2108,11 +2109,11 @@ extget_bailout: mode = 1; else mode = 2; - *((u_int32_t *) arg) = mode; + *((uint32_t *) arg) = mode; break; case MTIOCSETEOTMODEL: error = 0; - switch (*((u_int32_t *) arg)) { + switch (*((uint32_t *) arg)) { case 1: softc->quirks &= ~SA_QUIRK_2FM; softc->quirks |= SA_QUIRK_1FM; @@ -2289,7 +2290,7 @@ sacleanup(struct cam_periph *periph) } static void -saasync(void *callback_arg, u_int32_t code, +saasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg) { struct cam_periph *periph; @@ -2855,7 +2856,7 @@ again: xpt_release_ccb(start_ccb); biodone(done_bp); } else { - u_int32_t length; + uint32_t length; bioq_remove(&softc->bio_queue, bp); softc->queue_count--; @@ -3133,7 +3134,7 @@ sadone(struct cam_periph *periph, union ccb *done_ccb) if (!(csio->ccb_h.ccb_pflags & SA_POSITION_UPDATED) && (softc->blkno != (daddr_t) -1)) { if ((softc->flags & SA_FLAG_FIXED) != 0) { - u_int32_t l; + uint32_t l; if (softc->blk_shift != 0) { l = bp->bio_bcount >> softc->blk_shift; @@ -3231,7 +3232,7 @@ samount(struct cam_periph *periph, int oflags, struct cdev *dev) if ((softc->flags & SA_FLAG_TAPE_MOUNTED) == 0) { struct scsi_read_block_limits_data *rblim = NULL; int comp_enabled, comp_supported; - u_int8_t write_protect, guessing = 0; + uint8_t write_protect, guessing = 0; /* * Clear out old state. @@ -3376,7 +3377,7 @@ samount(struct cam_periph *periph, int oflags, struct cdev *dev) */ if (softc->media_density == SCSI_DEFAULT_DENSITY) { int i; - static u_int8_t ctry[] = { + static uint8_t ctry[] = { SCSI_DENSITY_HALFINCH_PE, SCSI_DENSITY_HALFINCH_6250C, SCSI_DENSITY_HALFINCH_6250, @@ -3663,7 +3664,7 @@ sacheckeod(struct cam_periph *periph) } static int -saerror(union ccb *ccb, u_int32_t cflgs, u_int32_t sflgs) +saerror(union ccb *ccb, uint32_t cflgs, uint32_t sflgs) { static const char *toobig = "%d-byte tape record bigger than supplied buffer\n"; @@ -3873,9 +3874,9 @@ saerror(union ccb *ccb, u_int32_t cflgs, u_int32_t sflgs) static int sagetparams(struct cam_periph *periph, sa_params params_to_get, - u_int32_t *blocksize, u_int8_t *density, u_int32_t *numblocks, - int *buff_mode, u_int8_t *write_protect, u_int8_t *speed, - int *comp_supported, int *comp_enabled, u_int32_t *comp_algorithm, + uint32_t *blocksize, uint8_t *density, uint32_t *numblocks, + int *buff_mode, uint8_t *write_protect, uint8_t *speed, + int *comp_supported, int *comp_enabled, uint32_t *comp_algorithm, sa_comp_t *tcs, struct scsi_control_data_prot_subpage *prot_page, int dp_size, int prot_changeable) { @@ -3885,7 +3886,7 @@ sagetparams(struct cam_periph *periph, sa_params params_to_get, struct scsi_mode_blk_desc *mode_blk; int mode_buffer_len; struct sa_softc *softc; - u_int8_t cpage; + uint8_t cpage; int error; cam_status status; @@ -4388,14 +4389,14 @@ bailout: */ static int sasetparams(struct cam_periph *periph, sa_params params_to_set, - u_int32_t blocksize, u_int8_t density, u_int32_t calg, - u_int32_t sense_flags) + uint32_t blocksize, uint8_t density, uint32_t calg, + uint32_t sense_flags) { struct sa_softc *softc; - u_int32_t current_blocksize; - u_int32_t current_calg; - u_int8_t current_density; - u_int8_t current_speed; + uint32_t current_blocksize; + uint32_t current_calg; + uint8_t current_density; + uint8_t current_speed; int comp_enabled, comp_supported; void *mode_buffer; int mode_buffer_len; @@ -5209,7 +5210,7 @@ sagetpos(struct cam_periph *periph) } static int -sardpos(struct cam_periph *periph, int hard, u_int32_t *blkptr) +sardpos(struct cam_periph *periph, int hard, uint32_t *blkptr) { struct scsi_tape_position_data loc; union ccb *ccb; @@ -5931,16 +5932,16 @@ saloadtimeouts(struct sa_softc *softc, union ccb *ccb) * Read tape block limits command. */ void -scsi_read_block_limits(struct ccb_scsiio *csio, u_int32_t retries, +scsi_read_block_limits(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, + uint8_t tag_action, struct scsi_read_block_limits_data *rlimit_buf, - u_int8_t sense_len, u_int32_t timeout) + uint8_t sense_len, uint32_t timeout) { struct scsi_read_block_limits *scsi_cmd; cam_fill_csio(csio, retries, cbfcnp, CAM_DIR_IN, tag_action, - (u_int8_t *)rlimit_buf, sizeof(*rlimit_buf), sense_len, + (uint8_t *)rlimit_buf, sizeof(*rlimit_buf), sense_len, sizeof(*scsi_cmd), timeout); scsi_cmd = (struct scsi_read_block_limits *)&csio->cdb_io.cdb_bytes; @@ -5949,11 +5950,11 @@ scsi_read_block_limits(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_sa_read_write(struct ccb_scsiio *csio, u_int32_t retries, +scsi_sa_read_write(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int readop, int sli, - int fixed, u_int32_t length, u_int8_t *data_ptr, - u_int32_t dxfer_len, u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, int readop, int sli, + int fixed, uint32_t length, uint8_t *data_ptr, + uint32_t dxfer_len, uint8_t sense_len, uint32_t timeout) { struct scsi_sa_rw *scsi_cmd; int read; @@ -5977,11 +5978,11 @@ scsi_sa_read_write(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_load_unload(struct ccb_scsiio *csio, u_int32_t retries, +scsi_load_unload(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int immediate, int eot, - int reten, int load, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, int immediate, int eot, + int reten, int load, uint8_t sense_len, + uint32_t timeout) { struct scsi_load_unload *scsi_cmd; @@ -6002,10 +6003,10 @@ scsi_load_unload(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_rewind(struct ccb_scsiio *csio, u_int32_t retries, +scsi_rewind(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int immediate, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, int immediate, uint8_t sense_len, + uint32_t timeout) { struct scsi_rewind *scsi_cmd; @@ -6020,10 +6021,10 @@ scsi_rewind(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_space(struct ccb_scsiio *csio, u_int32_t retries, +scsi_space(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, scsi_space_code code, - u_int32_t count, u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, scsi_space_code code, + uint32_t count, uint8_t sense_len, uint32_t timeout) { struct scsi_space *scsi_cmd; @@ -6038,11 +6039,11 @@ scsi_space(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_write_filemarks(struct ccb_scsiio *csio, u_int32_t retries, +scsi_write_filemarks(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int immediate, int setmark, - u_int32_t num_marks, u_int8_t sense_len, - u_int32_t timeout) + uint8_t tag_action, int immediate, int setmark, + uint32_t num_marks, uint8_t sense_len, + uint32_t timeout) { struct scsi_write_filemarks *scsi_cmd; @@ -6064,11 +6065,11 @@ scsi_write_filemarks(struct ccb_scsiio *csio, u_int32_t retries, * The reserve and release unit commands differ only by their opcodes. */ void -scsi_reserve_release_unit(struct ccb_scsiio *csio, u_int32_t retries, +scsi_reserve_release_unit(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int third_party, - int third_party_id, u_int8_t sense_len, - u_int32_t timeout, int reserve) + uint8_t tag_action, int third_party, + int third_party_id, uint8_t sense_len, + uint32_t timeout, int reserve) { struct scsi_reserve_release_unit *scsi_cmd; @@ -6091,10 +6092,10 @@ scsi_reserve_release_unit(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_erase(struct ccb_scsiio *csio, u_int32_t retries, +scsi_erase(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int immediate, int long_erase, - u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, int immediate, int long_erase, + uint8_t sense_len, uint32_t timeout) { struct scsi_erase *scsi_cmd; @@ -6117,16 +6118,16 @@ scsi_erase(struct ccb_scsiio *csio, u_int32_t retries, * Read Tape Position command. */ void -scsi_read_position(struct ccb_scsiio *csio, u_int32_t retries, +scsi_read_position(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int hardsoft, + uint8_t tag_action, int hardsoft, struct scsi_tape_position_data *sbp, - u_int8_t sense_len, u_int32_t timeout) + uint8_t sense_len, uint32_t timeout) { struct scsi_tape_read_position *scmd; cam_fill_csio(csio, retries, cbfcnp, CAM_DIR_IN, tag_action, - (u_int8_t *)sbp, sizeof (*sbp), sense_len, sizeof(*scmd), timeout); + (uint8_t *)sbp, sizeof (*sbp), sense_len, sizeof(*scmd), timeout); scmd = (struct scsi_tape_read_position *)&csio->cdb_io.cdb_bytes; bzero(scmd, sizeof(*scmd)); scmd->opcode = READ_POSITION; @@ -6137,11 +6138,11 @@ scsi_read_position(struct ccb_scsiio *csio, u_int32_t retries, * Read Tape Position command. */ void -scsi_read_position_10(struct ccb_scsiio *csio, u_int32_t retries, +scsi_read_position_10(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int service_action, - u_int8_t *data_ptr, u_int32_t length, - u_int32_t sense_len, u_int32_t timeout) + uint8_t tag_action, int service_action, + uint8_t *data_ptr, uint32_t length, + uint32_t sense_len, uint32_t timeout) { struct scsi_tape_read_position *scmd; @@ -6172,15 +6173,15 @@ scsi_read_position_10(struct ccb_scsiio *csio, u_int32_t retries, * Set Tape Position command. */ void -scsi_set_position(struct ccb_scsiio *csio, u_int32_t retries, +scsi_set_position(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int hardsoft, u_int32_t blkno, - u_int8_t sense_len, u_int32_t timeout) + uint8_t tag_action, int hardsoft, uint32_t blkno, + uint8_t sense_len, uint32_t timeout) { struct scsi_tape_locate *scmd; cam_fill_csio(csio, retries, cbfcnp, CAM_DIR_NONE, tag_action, - (u_int8_t *)NULL, 0, sense_len, sizeof(*scmd), timeout); + (uint8_t *)NULL, 0, sense_len, sizeof(*scmd), timeout); scmd = (struct scsi_tape_locate *)&csio->cdb_io.cdb_bytes; bzero(scmd, sizeof(*scmd)); scmd->opcode = LOCATE; @@ -6193,11 +6194,11 @@ scsi_set_position(struct ccb_scsiio *csio, u_int32_t retries, * XXX KDM figure out how to make a compatibility function. */ void -scsi_locate_10(struct ccb_scsiio *csio, u_int32_t retries, +scsi_locate_10(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int immed, int cp, int hard, - int64_t partition, u_int32_t block_address, - int sense_len, u_int32_t timeout) + uint8_t tag_action, int immed, int cp, int hard, + int64_t partition, uint32_t block_address, + int sense_len, uint32_t timeout) { struct scsi_tape_locate *scmd; @@ -6225,11 +6226,11 @@ scsi_locate_10(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_locate_16(struct ccb_scsiio *csio, u_int32_t retries, +scsi_locate_16(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int immed, int cp, u_int8_t dest_type, - int bam, int64_t partition, u_int64_t logical_id, - int sense_len, u_int32_t timeout) + uint8_t tag_action, int immed, int cp, uint8_t dest_type, + int bam, int64_t partition, uint64_t logical_id, + int sense_len, uint32_t timeout) { struct scsi_locate_16 *scsi_cmd; @@ -6260,11 +6261,11 @@ scsi_locate_16(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_report_density_support(struct ccb_scsiio *csio, u_int32_t retries, +scsi_report_density_support(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int media, int medium_type, - u_int8_t *data_ptr, u_int32_t length, - u_int32_t sense_len, u_int32_t timeout) + uint8_t tag_action, int media, int medium_type, + uint8_t *data_ptr, uint32_t length, + uint32_t sense_len, uint32_t timeout) { struct scsi_report_density_support *scsi_cmd; @@ -6292,10 +6293,10 @@ scsi_report_density_support(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_set_capacity(struct ccb_scsiio *csio, u_int32_t retries, +scsi_set_capacity(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int byte1, u_int32_t proportion, - u_int32_t sense_len, u_int32_t timeout) + uint8_t tag_action, int byte1, uint32_t proportion, + uint32_t sense_len, uint32_t timeout) { struct scsi_set_capacity *scsi_cmd; @@ -6320,11 +6321,11 @@ scsi_set_capacity(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_format_medium(struct ccb_scsiio *csio, u_int32_t retries, +scsi_format_medium(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int byte1, int byte2, - u_int8_t *data_ptr, u_int32_t dxfer_len, - u_int32_t sense_len, u_int32_t timeout) + uint8_t tag_action, int byte1, int byte2, + uint8_t *data_ptr, uint32_t dxfer_len, + uint32_t sense_len, uint32_t timeout) { struct scsi_format_medium *scsi_cmd; @@ -6351,10 +6352,10 @@ scsi_format_medium(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_allow_overwrite(struct ccb_scsiio *csio, u_int32_t retries, +scsi_allow_overwrite(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int allow_overwrite, int partition, - u_int64_t logical_id, u_int32_t sense_len, u_int32_t timeout) + uint8_t tag_action, int allow_overwrite, int partition, + uint64_t logical_id, uint32_t sense_len, uint32_t timeout) { struct scsi_allow_overwrite *scsi_cmd; diff --git a/sys/cam/scsi/scsi_sa.h b/sys/cam/scsi/scsi_sa.h index 908b16b684cf..3d8edcac7aa7 100644 --- a/sys/cam/scsi/scsi_sa.h +++ b/sys/cam/scsi/scsi_sa.h @@ -2,7 +2,7 @@ * Structure and function declarations for the * SCSI Sequential Access Peripheral driver for CAM. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1999, 2000 Matthew Jacob * Copyright (c) 2013, 2014, 2015 Spectra Logic Corporation @@ -28,62 +28,59 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _SCSI_SCSI_SA_H #define _SCSI_SCSI_SA_H 1 -#include <sys/cdefs.h> struct scsi_read_block_limits { - u_int8_t opcode; - u_int8_t byte2; - u_int8_t unused[3]; - u_int8_t control; + uint8_t opcode; + uint8_t byte2; + uint8_t unused[3]; + uint8_t control; }; struct scsi_read_block_limits_data { - u_int8_t gran; + uint8_t gran; #define RBL_GRAN_MASK 0x1F #define RBL_GRAN(rblim) ((rblim)->gran & RBL_GRAN_MASK) - u_int8_t maximum[3]; - u_int8_t minimum[2]; + uint8_t maximum[3]; + uint8_t minimum[2]; }; struct scsi_sa_rw { - u_int8_t opcode; - u_int8_t sli_fixed; + uint8_t opcode; + uint8_t sli_fixed; #define SAR_SLI 0x02 #define SARW_FIXED 0x01 - u_int8_t length[3]; - u_int8_t control; + uint8_t length[3]; + uint8_t control; }; struct scsi_load_unload { - u_int8_t opcode; - u_int8_t immediate; + uint8_t opcode; + uint8_t immediate; #define SLU_IMMED 0x01 - u_int8_t reserved[2]; - u_int8_t eot_reten_load; + uint8_t reserved[2]; + uint8_t eot_reten_load; #define SLU_EOT 0x04 #define SLU_RETEN 0x02 #define SLU_LOAD 0x01 - u_int8_t control; + uint8_t control; }; struct scsi_rewind { - u_int8_t opcode; - u_int8_t immediate; + uint8_t opcode; + uint8_t immediate; #define SREW_IMMED 0x01 - u_int8_t reserved[3]; - u_int8_t control; + uint8_t reserved[3]; + uint8_t control; }; typedef enum { @@ -97,21 +94,21 @@ typedef enum { struct scsi_space { - u_int8_t opcode; - u_int8_t code; + uint8_t opcode; + uint8_t code; #define SREW_IMMED 0x01 - u_int8_t count[3]; - u_int8_t control; + uint8_t count[3]; + uint8_t control; }; struct scsi_write_filemarks { - u_int8_t opcode; - u_int8_t byte2; + uint8_t opcode; + uint8_t byte2; #define SWFMRK_IMMED 0x01 #define SWFMRK_WSMK 0x02 - u_int8_t num_marks[3]; - u_int8_t control; + uint8_t num_marks[3]; + uint8_t control; }; /* @@ -120,14 +117,14 @@ struct scsi_write_filemarks */ struct scsi_reserve_release_unit { - u_int8_t opcode; - u_int8_t lun_thirdparty; + uint8_t opcode; + uint8_t lun_thirdparty; #define SRRU_LUN_MASK 0xE0 #define SRRU_3RD_PARTY 0x10 #define SRRU_3RD_SHAMT 1 #define SRRU_3RD_MASK 0xE - u_int8_t reserved[3]; - u_int8_t control; + uint8_t reserved[3]; + uint8_t control; }; /* @@ -135,13 +132,13 @@ struct scsi_reserve_release_unit */ struct scsi_erase { - u_int8_t opcode; - u_int8_t lun_imm_long; + uint8_t opcode; + uint8_t lun_imm_long; #define SE_LUN_MASK 0xE0 #define SE_LONG 0x1 #define SE_IMMED 0x2 - u_int8_t reserved[3]; - u_int8_t control; + uint8_t reserved[3]; + uint8_t control; }; /* @@ -149,12 +146,12 @@ struct scsi_erase */ struct scsi_set_capacity { - u_int8_t opcode; - u_int8_t byte1; + uint8_t opcode; + uint8_t byte1; #define SA_SSC_IMMED 0x01 - u_int8_t reserved; - u_int8_t cap_proportion[2]; - u_int8_t control; + uint8_t reserved; + uint8_t cap_proportion[2]; + uint8_t control; }; /* @@ -164,31 +161,31 @@ struct scsi_set_capacity */ struct scsi_format_medium { - u_int8_t opcode; - u_int8_t byte1; + uint8_t opcode; + uint8_t byte1; #define SFM_IMMED 0x01 #define SFM_VERIFY 0x02 - u_int8_t byte2; + uint8_t byte2; #define SFM_FORMAT_DEFAULT 0x00 #define SFM_FORMAT_PARTITION 0x01 #define SFM_FORMAT_DEF_PART 0x02 #define SFM_FORMAT_MASK 0x0f - u_int8_t length[2]; - u_int8_t control; + uint8_t length[2]; + uint8_t control; }; struct scsi_allow_overwrite { - u_int8_t opcode; - u_int8_t reserved1; - u_int8_t allow_overwrite; + uint8_t opcode; + uint8_t reserved1; + uint8_t allow_overwrite; #define SAO_ALLOW_OVERWRITE_DISABLED 0x00 #define SAO_ALLOW_OVERWRITE_CUR_POS 0x01 #define SAO_ALLOW_OVERWRITE_FORMAT 0x02 - u_int8_t partition; - u_int8_t logical_id[8]; - u_int8_t reserved2[3]; - u_int8_t control; + uint8_t partition; + uint8_t logical_id[8]; + uint8_t reserved2[3]; + uint8_t control; }; /* @@ -218,14 +215,14 @@ struct scsi_allow_overwrite /* See SCSI-II spec 9.3.3.1 */ struct scsi_dev_conf_page { - u_int8_t pagecode; /* 0x10 */ - u_int8_t pagelength; /* 0x0e */ - u_int8_t byte2; /* CAP, CAF, Active Format */ - u_int8_t active_partition; - u_int8_t wb_full_ratio; - u_int8_t rb_empty_ratio; - u_int8_t wrdelay_time[2]; - u_int8_t byte8; + uint8_t pagecode; /* 0x10 */ + uint8_t pagelength; /* 0x0e */ + uint8_t byte2; /* CAP, CAF, Active Format */ + uint8_t active_partition; + uint8_t wb_full_ratio; + uint8_t rb_empty_ratio; + uint8_t wrdelay_time[2]; + uint8_t byte8; #define SA_DBR 0x80 /* data buffer recovery */ #define SA_BIS 0x40 /* block identifiers supported */ #define SA_RSMK 0x20 /* report setmarks */ @@ -233,8 +230,8 @@ struct scsi_dev_conf_page { #define SA_SOCF_MASK 0x0c /* stop on consecutive formats */ #define SA_RBO 0x02 /* recover buffer order */ #define SA_REW 0x01 /* report early warning */ - u_int8_t gap_size; - u_int8_t byte10; + uint8_t gap_size; + uint8_t byte10; /* from SCSI-3: SSC-4 Working draft (2/14) 8.3.3 */ #define SA_EOD_DEF_MASK 0xe0 /* EOD defined */ #define SA_EEG 0x10 /* Enable EOD Generation */ @@ -242,12 +239,12 @@ struct scsi_dev_conf_page { #define SA_SOFT_WP 0x04 /* Software Write Protect */ #define SA_BAML 0x02 /* Block Address Mode Lock */ #define SA_BAM 0x01 /* Block Address Mode */ - u_int8_t ew_bufsize[3]; - u_int8_t sel_comp_alg; + uint8_t ew_bufsize[3]; + uint8_t sel_comp_alg; #define SA_COMP_NONE 0x00 #define SA_COMP_DEFAULT 0x01 /* the following is 'reserved' in SCSI-2 but is defined in SSC-r22 */ - u_int8_t extra_wp; + uint8_t extra_wp; #define SA_ASOC_WP 0x04 /* Associated Write Protect */ #define SA_PERS_WP 0x02 /* Persistent Write Protect */ #define SA_PERM_WP 0x01 /* Permanent Write Protect */ @@ -255,25 +252,25 @@ struct scsi_dev_conf_page { /* from SCSI-3: SSC-Rev10 (6/97) */ struct scsi_data_compression_page { - u_int8_t page_code; /* 0x0f */ - u_int8_t page_length; /* 0x0e */ - u_int8_t dce_and_dcc; + uint8_t page_code; /* 0x0f */ + uint8_t page_length; /* 0x0e */ + uint8_t dce_and_dcc; #define SA_DCP_DCE 0x80 /* Data compression enable */ #define SA_DCP_DCC 0x40 /* Data compression capable */ - u_int8_t dde_and_red; + uint8_t dde_and_red; #define SA_DCP_DDE 0x80 /* Data decompression enable */ #define SA_DCP_RED_MASK 0x60 /* Report Exception on Decomp. */ #define SA_DCP_RED_SHAMT 5 #define SA_DCP_RED_0 0x00 #define SA_DCP_RED_1 0x20 #define SA_DCP_RED_2 0x40 - u_int8_t comp_algorithm[4]; - u_int8_t decomp_algorithm[4]; - u_int8_t reserved[4]; + uint8_t comp_algorithm[4]; + uint8_t decomp_algorithm[4]; + uint8_t reserved[4]; }; typedef union { - struct { u_int8_t pagecode, pagelength; } hdr; + struct { uint8_t pagecode, pagelength; } hdr; struct scsi_dev_conf_page dconf; struct scsi_data_compression_page dcomp; } sa_comp_t; @@ -341,19 +338,19 @@ struct scsi_tape_ibm_rw_control { }; struct scsi_tape_read_position { - u_int8_t opcode; /* READ_POSITION */ - u_int8_t byte1; /* set LSB to read hardware block pos */ + uint8_t opcode; /* READ_POSITION */ + uint8_t byte1; /* set LSB to read hardware block pos */ #define SA_RPOS_SHORT_FORM 0x00 #define SA_RPOS_SHORT_VENDOR 0x01 #define SA_RPOS_LONG_FORM 0x06 #define SA_RPOS_EXTENDED_FORM 0x08 - u_int8_t reserved[5]; - u_int8_t length[2]; - u_int8_t control; + uint8_t reserved[5]; + uint8_t length[2]; + uint8_t control; }; struct scsi_tape_position_data { /* Short Form */ - u_int8_t flags; + uint8_t flags; #define SA_RPOS_BOP 0x80 /* Beginning of Partition */ #define SA_RPOS_EOP 0x40 /* End of Partition */ #define SA_RPOS_BCU 0x20 /* Block Count Unknown (SCSI3) */ @@ -362,31 +359,31 @@ struct scsi_tape_position_data { /* Short Form */ #define SA_RPOS_PERR 0x02 /* Position Error (SCSI3) */ #define SA_RPOS_BPEW 0x01 /* Beyond Programmable Early Warning */ #define SA_RPOS_UNCERTAIN SA_RPOS_BPU - u_int8_t partition; - u_int8_t reserved[2]; - u_int8_t firstblk[4]; - u_int8_t lastblk[4]; - u_int8_t reserved2; - u_int8_t nbufblk[3]; - u_int8_t nbufbyte[4]; + uint8_t partition; + uint8_t reserved[2]; + uint8_t firstblk[4]; + uint8_t lastblk[4]; + uint8_t reserved2; + uint8_t nbufblk[3]; + uint8_t nbufbyte[4]; }; struct scsi_tape_position_long_data { - u_int8_t flags; + uint8_t flags; #define SA_RPOS_LONG_BOP 0x80 /* Beginning of Partition */ #define SA_RPOS_LONG_EOP 0x40 /* End of Partition */ #define SA_RPOS_LONG_MPU 0x08 /* Mark Position Unknown */ #define SA_RPOS_LONG_LONU 0x04 /* Logical Object Number Unknown */ #define SA_RPOS_LONG_BPEW 0x01 /* Beyond Programmable Early Warning */ - u_int8_t reserved[3]; - u_int8_t partition[4]; - u_int8_t logical_object_num[8]; - u_int8_t logical_file_num[8]; - u_int8_t set_id[8]; + uint8_t reserved[3]; + uint8_t partition[4]; + uint8_t logical_object_num[8]; + uint8_t logical_file_num[8]; + uint8_t set_id[8]; }; struct scsi_tape_position_ext_data { - u_int8_t flags; + uint8_t flags; #define SA_RPOS_EXT_BOP 0x80 /* Beginning of Partition */ #define SA_RPOS_EXT_EOP 0x40 /* End of Partition */ #define SA_RPOS_EXT_LOCU 0x20 /* Logical Object Count Unknown */ @@ -394,32 +391,32 @@ struct scsi_tape_position_ext_data { #define SA_RPOS_EXT_LOLU 0x04 /* Logical Object Location Unknown */ #define SA_RPOS_EXT_PERR 0x02 /* Position Error */ #define SA_RPOS_EXT_BPEW 0x01 /* Beyond Programmable Early Warning */ - u_int8_t partition; - u_int8_t length[2]; - u_int8_t reserved; - u_int8_t num_objects[3]; - u_int8_t first_object[8]; - u_int8_t last_object[8]; - u_int8_t bytes_in_buffer[8]; + uint8_t partition; + uint8_t length[2]; + uint8_t reserved; + uint8_t num_objects[3]; + uint8_t first_object[8]; + uint8_t last_object[8]; + uint8_t bytes_in_buffer[8]; }; struct scsi_tape_locate { - u_int8_t opcode; - u_int8_t byte1; + uint8_t opcode; + uint8_t byte1; #define SA_SPOS_IMMED 0x01 #define SA_SPOS_CP 0x02 #define SA_SPOS_BT 0x04 - u_int8_t reserved1; - u_int8_t blkaddr[4]; + uint8_t reserved1; + uint8_t blkaddr[4]; #define SA_SPOS_MAX_BLK 0xffffffff - u_int8_t reserved2; - u_int8_t partition; - u_int8_t control; + uint8_t reserved2; + uint8_t partition; + uint8_t control; }; struct scsi_locate_16 { - u_int8_t opcode; - u_int8_t byte1; + uint8_t opcode; + uint8_t byte1; #define SA_LC_IMMEDIATE 0x01 #define SA_LC_CP 0x02 #define SA_LC_DEST_TYPE_MASK 0x38 @@ -428,64 +425,64 @@ struct scsi_locate_16 { #define SA_LC_DEST_FILE 0x01 #define SA_LC_DEST_SET 0x02 #define SA_LC_DEST_EOD 0x03 - u_int8_t byte2; + uint8_t byte2; #define SA_LC_BAM_IMPLICIT 0x00 #define SA_LC_BAM_EXPLICIT 0x01 - u_int8_t partition; - u_int8_t logical_id[8]; - u_int8_t reserved[3]; - u_int8_t control; + uint8_t partition; + uint8_t logical_id[8]; + uint8_t reserved[3]; + uint8_t control; }; struct scsi_report_density_support { - u_int8_t opcode; - u_int8_t byte1; + uint8_t opcode; + uint8_t byte1; #define SRDS_MEDIA 0x01 #define SRDS_MEDIUM_TYPE 0x02 - u_int8_t reserved[5]; - u_int8_t length[2]; + uint8_t reserved[5]; + uint8_t length[2]; #define SRDS_MAX_LENGTH 0xffff - u_int8_t control; + uint8_t control; }; struct scsi_density_hdr { - u_int8_t length[2]; - u_int8_t reserved[2]; - u_int8_t descriptor[]; + uint8_t length[2]; + uint8_t reserved[2]; + uint8_t descriptor[]; }; struct scsi_density_data { - u_int8_t primary_density_code; - u_int8_t secondary_density_code; - u_int8_t byte2; + uint8_t primary_density_code; + uint8_t secondary_density_code; + uint8_t byte2; #define SDD_DLV 0x01 #define SDD_DEFLT 0x20 #define SDD_DUP 0x40 #define SDD_WRTOK 0x80 - u_int8_t length[2]; + uint8_t length[2]; #define SDD_DEFAULT_LENGTH 52 - u_int8_t bits_per_mm[3]; - u_int8_t media_width[2]; - u_int8_t tracks[2]; - u_int8_t capacity[4]; - u_int8_t assigning_org[8]; - u_int8_t density_name[8]; - u_int8_t description[20]; + uint8_t bits_per_mm[3]; + uint8_t media_width[2]; + uint8_t tracks[2]; + uint8_t capacity[4]; + uint8_t assigning_org[8]; + uint8_t density_name[8]; + uint8_t description[20]; }; struct scsi_medium_type_data { - u_int8_t medium_type; - u_int8_t reserved1; - u_int8_t length[2]; + uint8_t medium_type; + uint8_t reserved1; + uint8_t length[2]; #define SMTD_DEFAULT_LENGTH 52 - u_int8_t num_density_codes; - u_int8_t primary_density_codes[9]; - u_int8_t media_width[2]; - u_int8_t medium_length[2]; - u_int8_t reserved2[2]; - u_int8_t assigning_org[8]; - u_int8_t medium_type_name[8]; - u_int8_t description[20]; + uint8_t num_density_codes; + uint8_t primary_density_codes[9]; + uint8_t media_width[2]; + uint8_t medium_length[2]; + uint8_t reserved2[2]; + uint8_t assigning_org[8]; + uint8_t medium_type_name[8]; + uint8_t description[20]; }; /* @@ -494,11 +491,11 @@ struct scsi_medium_type_data { */ struct scsi_vpd_mfg_serial_number { - u_int8_t device; - u_int8_t page_code; + uint8_t device; + uint8_t page_code; #define SVPD_MFG_SERIAL_NUMBER_PAGE_CODE 0xB1 - u_int8_t page_length[2]; - u_int8_t mfg_serial_num[]; + uint8_t page_length[2]; + uint8_t mfg_serial_num[]; }; /* @@ -973,110 +970,110 @@ struct tde_lb_enc_key_wrap_desc { #define SCSI_DENSITY_QIC_3080 0x29 __BEGIN_DECLS -void scsi_read_block_limits(struct ccb_scsiio *, u_int32_t, +void scsi_read_block_limits(struct ccb_scsiio *, uint32_t, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t, struct scsi_read_block_limits_data *, - u_int8_t , u_int32_t); + uint8_t, struct scsi_read_block_limits_data *, + uint8_t , uint32_t); -void scsi_sa_read_write(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_sa_read_write(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int readop, int sli, - int fixed, u_int32_t length, u_int8_t *data_ptr, - u_int32_t dxfer_len, u_int8_t sense_len, - u_int32_t timeout); + uint8_t tag_action, int readop, int sli, + int fixed, uint32_t length, uint8_t *data_ptr, + uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout); -void scsi_rewind(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_rewind(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int immediate, u_int8_t sense_len, - u_int32_t timeout); + uint8_t tag_action, int immediate, uint8_t sense_len, + uint32_t timeout); -void scsi_space(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_space(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, scsi_space_code code, - u_int32_t count, u_int8_t sense_len, u_int32_t timeout); + uint8_t tag_action, scsi_space_code code, + uint32_t count, uint8_t sense_len, uint32_t timeout); -void scsi_load_unload(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_load_unload(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int immediate, int eot, - int reten, int load, u_int8_t sense_len, - u_int32_t timeout); + uint8_t tag_action, int immediate, int eot, + int reten, int load, uint8_t sense_len, + uint32_t timeout); -void scsi_write_filemarks(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_write_filemarks(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int immediate, int setmark, - u_int32_t num_marks, u_int8_t sense_len, - u_int32_t timeout); + uint8_t tag_action, int immediate, int setmark, + uint32_t num_marks, uint8_t sense_len, + uint32_t timeout); -void scsi_reserve_release_unit(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_reserve_release_unit(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, - union ccb *), u_int8_t tag_action, + union ccb *), uint8_t tag_action, int third_party, int third_party_id, - u_int8_t sense_len, u_int32_t timeout, + uint8_t sense_len, uint32_t timeout, int reserve); -void scsi_erase(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_erase(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int immediate, int long_erase, - u_int8_t sense_len, u_int32_t timeout); + uint8_t tag_action, int immediate, int long_erase, + uint8_t sense_len, uint32_t timeout); void scsi_data_comp_page(struct scsi_data_compression_page *page, - u_int8_t dce, u_int8_t dde, u_int8_t red, - u_int32_t comp_algorithm, - u_int32_t decomp_algorithm); + uint8_t dce, uint8_t dde, uint8_t red, + uint32_t comp_algorithm, + uint32_t decomp_algorithm); -void scsi_read_position(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_read_position(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int hardsoft, + uint8_t tag_action, int hardsoft, struct scsi_tape_position_data *sbp, - u_int8_t sense_len, u_int32_t timeout); -void scsi_read_position_10(struct ccb_scsiio *csio, u_int32_t retries, + uint8_t sense_len, uint32_t timeout); +void scsi_read_position_10(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int service_action, - u_int8_t *data_ptr, u_int32_t length, - u_int32_t sense_len, u_int32_t timeout); + uint8_t tag_action, int service_action, + uint8_t *data_ptr, uint32_t length, + uint32_t sense_len, uint32_t timeout); -void scsi_set_position(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_set_position(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int hardsoft, u_int32_t blkno, - u_int8_t sense_len, u_int32_t timeout); + uint8_t tag_action, int hardsoft, uint32_t blkno, + uint8_t sense_len, uint32_t timeout); -void scsi_locate_10(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_locate_10(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int immed, int cp, int hard, - int64_t partition, u_int32_t block_address, - int sense_len, u_int32_t timeout); + uint8_t tag_action, int immed, int cp, int hard, + int64_t partition, uint32_t block_address, + int sense_len, uint32_t timeout); -void scsi_locate_16(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_locate_16(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int immed, int cp, - u_int8_t dest_type, int bam, int64_t partition, - u_int64_t logical_id, int sense_len, - u_int32_t timeout); + uint8_t tag_action, int immed, int cp, + uint8_t dest_type, int bam, int64_t partition, + uint64_t logical_id, int sense_len, + uint32_t timeout); -void scsi_report_density_support(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_report_density_support(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int media, - int medium_type, u_int8_t *data_ptr, - u_int32_t length, u_int32_t sense_len, - u_int32_t timeout); + uint8_t tag_action, int media, + int medium_type, uint8_t *data_ptr, + uint32_t length, uint32_t sense_len, + uint32_t timeout); -void scsi_set_capacity(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_set_capacity(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int byte1, u_int32_t proportion, - u_int32_t sense_len, u_int32_t timeout); + uint8_t tag_action, int byte1, uint32_t proportion, + uint32_t sense_len, uint32_t timeout); -void scsi_format_medium(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_format_medium(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int byte1, int byte2, - u_int8_t *data_ptr, u_int32_t length, - u_int32_t sense_len, u_int32_t timeout); + uint8_t tag_action, int byte1, int byte2, + uint8_t *data_ptr, uint32_t length, + uint32_t sense_len, uint32_t timeout); -void scsi_allow_overwrite(struct ccb_scsiio *csio, u_int32_t retries, +void scsi_allow_overwrite(struct ccb_scsiio *csio, uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int allow_overwrite, - int partition, u_int64_t logical_id, - u_int32_t sense_len, u_int32_t timeout); + uint8_t tag_action, int allow_overwrite, + int partition, uint64_t logical_id, + uint32_t sense_len, uint32_t timeout); __END_DECLS diff --git a/sys/cam/scsi/scsi_ses.h b/sys/cam/scsi/scsi_ses.h index 1ee3e12381f3..c9f3b893e60b 100644 --- a/sys/cam/scsi/scsi_ses.h +++ b/sys/cam/scsi/scsi_ses.h @@ -1,6 +1,5 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD OR GPL-2.0) + * SPDX-License-Identifier: (BSD-2-Clause OR GPL-2.0) * * Copyright (c) 2000 by Matthew Jacob * All rights reserved. diff --git a/sys/cam/scsi/scsi_sg.c b/sys/cam/scsi/scsi_sg.c index c0b2328b0c80..fec3bb157b52 100644 --- a/sys/cam/scsi/scsi_sg.c +++ b/sys/cam/scsi/scsi_sg.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2007 Scott Long * All rights reserved. @@ -31,9 +31,6 @@ * SG passthrough interface for SCSI. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> @@ -885,7 +882,7 @@ sgsendccb(struct cam_periph *periph, union ccb *ccb) { struct sg_softc *softc; struct cam_periph_map_info mapinfo; - int error; + int error, error1; softc = periph->softc; bzero(&mapinfo, sizeof(mapinfo)); @@ -910,7 +907,9 @@ sgsendccb(struct cam_periph *periph, union ccb *ccb) softc->device_stats); cam_periph_unlock(periph); - cam_periph_unmapmem(ccb, &mapinfo); + error1 = cam_periph_unmapmem(ccb, &mapinfo); + if (error == 0) + error = error1; cam_periph_lock(periph); return (error); diff --git a/sys/cam/scsi/scsi_sg.h b/sys/cam/scsi/scsi_sg.h index 210eec5f4f46..61f9912a9af9 100644 --- a/sys/cam/scsi/scsi_sg.h +++ b/sys/cam/scsi/scsi_sg.h @@ -1,7 +1,5 @@ /* * Structures and definitions for SCSI commands to the SG passthrough device. - * - * $FreeBSD$ */ #ifndef _SCSI_SG_H diff --git a/sys/cam/scsi/scsi_targ_bh.c b/sys/cam/scsi/scsi_targ_bh.c index 14edb254a0e5..234dd777d88d 100644 --- a/sys/cam/scsi/scsi_targ_bh.c +++ b/sys/cam/scsi/scsi_targ_bh.c @@ -1,7 +1,7 @@ /*- * Implementation of the Target Mode 'Black Hole device' for CAM. * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1999 Justin T. Gibbs. * All rights reserved. @@ -28,9 +28,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/queue.h> #include <sys/systm.h> @@ -103,8 +100,8 @@ struct targbh_cmd_desc { void* data; /* The data. Can be from backing_store or not */ void* backing_store;/* Backing store allocated for this descriptor*/ u_int max_size; /* Size of backing_store */ - u_int32_t timeout; - u_int8_t status; /* Status to return to initiator */ + uint32_t timeout; + uint8_t status; /* Status to return to initiator */ }; static struct scsi_inquiry_data no_lun_inq_data = @@ -129,7 +126,7 @@ static struct scsi_sense_data_fixed no_lun_sense_data = static const int request_sense_size = offsetof(struct scsi_sense_data_fixed, fru); static periph_init_t targbhinit; -static void targbhasync(void *callback_arg, u_int32_t code, +static void targbhasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg); static cam_status targbhenlun(struct cam_periph *periph); static cam_status targbhdislun(struct cam_periph *periph); @@ -139,8 +136,8 @@ static periph_start_t targbhstart; static void targbhdone(struct cam_periph *periph, union ccb *done_ccb); #ifdef NOTYET -static int targbherror(union ccb *ccb, u_int32_t cam_flags, - u_int32_t sense_flags); +static int targbherror(union ccb *ccb, uint32_t cam_flags, + uint32_t sense_flags); #endif static struct targbh_cmd_desc* targbhallocdescr(void); static void targbhfreedescr(struct targbh_cmd_desc *buf); @@ -172,7 +169,7 @@ targbhinit(void) } static void -targbhasync(void *callback_arg, u_int32_t code, +targbhasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg) { struct cam_path *new_path; @@ -537,7 +534,7 @@ targbhdone(struct cam_periph *periph, union ccb *done_ccb) { struct ccb_accept_tio *atio; struct targbh_cmd_desc *descr; - u_int8_t *cdb; + uint8_t *cdb; int priority; atio = &done_ccb->atio; @@ -731,7 +728,7 @@ targbhdone(struct cam_periph *periph, union ccb *done_ccb) #ifdef NOTYET static int -targbherror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags) +targbherror(union ccb *ccb, uint32_t cam_flags, uint32_t sense_flags) { return 0; } diff --git a/sys/cam/scsi/scsi_target.c b/sys/cam/scsi/scsi_target.c index 8640067cc531..034b528b415c 100644 --- a/sys/cam/scsi/scsi_target.c +++ b/sys/cam/scsi/scsi_target.c @@ -1,7 +1,7 @@ /*- * Generic SCSI Target Kernel Mode Driver * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2002 Nate Lawson. * Copyright (c) 1998, 1999, 2001, 2002 Justin T. Gibbs. @@ -29,9 +29,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> @@ -148,7 +145,7 @@ static void targfreeccb(struct targ_softc *softc, union ccb *ccb); static struct targ_cmd_descr * targgetdescr(struct targ_softc *softc); static periph_init_t targinit; -static void targasync(void *callback_arg, u_int32_t code, +static void targasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg); static void abort_all_pending(struct targ_softc *softc); static void notify_user(struct targ_softc *softc); @@ -637,8 +634,8 @@ targstart(struct cam_periph *periph, union ccb *start_ccb) xpt_print(periph->path, "targsendccb failed, err %d\n", error); xpt_release_ccb(start_ccb); - suword(&descr->user_ccb->ccb_h.status, - CAM_REQ_CMP_ERR); + (void)suword(&descr->user_ccb->ccb_h.status, + CAM_REQ_CMP_ERR); TAILQ_INSERT_TAIL(&softc->abort_queue, descr, tqe); notify_user(softc); } @@ -870,7 +867,10 @@ targread(struct cdev *dev, struct uio *uio, int ioflag) CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("targread aborted descr %p (%p)\n", user_descr, user_ccb)); - suword(&user_ccb->ccb_h.status, CAM_REQ_ABORTED); + if (suword(&user_ccb->ccb_h.status, CAM_REQ_ABORTED) != 0) { + error = EFAULT; + goto read_fail; + } cam_periph_unlock(softc->periph); error = uiomove((caddr_t)&user_ccb, sizeof(user_ccb), uio); cam_periph_lock(softc->periph); @@ -908,18 +908,29 @@ targreturnccb(struct targ_softc *softc, union ccb *ccb) u_ccbh = &descr->user_ccb->ccb_h; /* Copy out the central portion of the ccb_hdr */ - copyout(&ccb->ccb_h.retry_count, &u_ccbh->retry_count, - offsetof(struct ccb_hdr, periph_priv) - - offsetof(struct ccb_hdr, retry_count)); + error = copyout(&ccb->ccb_h.retry_count, &u_ccbh->retry_count, + offsetof(struct ccb_hdr, periph_priv) - + offsetof(struct ccb_hdr, retry_count)); + if (error != 0) { + xpt_print(softc->path, + "targreturnccb - CCB header copyout failed (%d)\n", error); + } /* Copy out the rest of the ccb (after the ccb_hdr) */ ccb_len = targccblen(ccb->ccb_h.func_code) - sizeof(struct ccb_hdr); - if (descr->mapinfo.num_bufs_used != 0) - cam_periph_unmapmem(ccb, &descr->mapinfo); - error = copyout(&ccb->ccb_h + 1, u_ccbh + 1, ccb_len); - if (error != 0) { - xpt_print(softc->path, - "targreturnccb - CCB copyout failed (%d)\n", error); + if (descr->mapinfo.num_bufs_used != 0) { + int error1; + + error1 = cam_periph_unmapmem(ccb, &descr->mapinfo); + if (error == 0) + error = error1; + } + if (error == 0) { + error = copyout(&ccb->ccb_h + 1, u_ccbh + 1, ccb_len); + if (error != 0) { + xpt_print(softc->path, + "targreturnccb - CCB copyout failed (%d)\n", error); + } } /* Free CCB or send back to devq. */ targfreeccb(softc, ccb); @@ -1003,7 +1014,7 @@ targinit(void) } static void -targasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg) +targasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg) { /* All events are handled in usermode by INOTs */ panic("targasync() called, should be an INOT instead"); diff --git a/sys/cam/scsi/scsi_targetio.h b/sys/cam/scsi/scsi_targetio.h index ca0384eb2da0..ce5aab557ee4 100644 --- a/sys/cam/scsi/scsi_targetio.h +++ b/sys/cam/scsi/scsi_targetio.h @@ -1,7 +1,7 @@ /*- * Ioctl definitions for the SCSI Target Driver * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2002 Nate Lawson. * Copyright (c) 1998 Justin T. Gibbs. @@ -27,8 +27,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _CAM_SCSI_SCSI_TARGETIO_H_ diff --git a/sys/cam/scsi/scsi_xpt.c b/sys/cam/scsi/scsi_xpt.c index 8c83ce08d635..45aae4a50669 100644 --- a/sys/cam/scsi/scsi_xpt.c +++ b/sys/cam/scsi/scsi_xpt.c @@ -1,7 +1,7 @@ /*- * Implementation of the SCSI Transport * - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs. * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry. @@ -29,9 +29,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/bus.h> #include <sys/systm.h> @@ -63,11 +60,10 @@ __FBSDID("$FreeBSD$"); #include <cam/scsi/scsi_message.h> #include <cam/scsi/scsi_pass.h> #include <machine/stdarg.h> /* for xpt_print below */ -#include "opt_cam.h" struct scsi_quirk_entry { struct scsi_inquiry_pattern inq_pat; - u_int8_t quirks; + uint8_t quirks; #define CAM_QUIRK_NOLUNS 0x01 #define CAM_QUIRK_NOVPDS 0x02 #define CAM_QUIRK_HILUNS 0x04 @@ -187,7 +183,7 @@ typedef struct { probe_action action; probe_flags flags; MD5_CTX context; - u_int8_t digest[16]; + uint8_t digest[16]; struct cam_periph *periph; } probe_softc; @@ -587,18 +583,15 @@ static void scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path, int async_update); static void scsi_toggle_tags(struct cam_path *path); -static void scsi_dev_async(u_int32_t async_code, +static void scsi_dev_async(uint32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, void *async_arg); static void scsi_action(union ccb *start_ccb); -static void scsi_announce_periph(struct cam_periph *periph); static void scsi_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb); -static void scsi_proto_announce(struct cam_ed *device); static void scsi_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb); -static void scsi_proto_denounce(struct cam_ed *device); static void scsi_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb); static void scsi_proto_debug_out(union ccb *ccb); @@ -608,7 +601,6 @@ static struct xpt_xport_ops scsi_xport_ops = { .alloc_device = scsi_alloc_device, .action = scsi_action, .async = scsi_dev_async, - .announce = scsi_announce_periph, .announce_sbuf = scsi_announce_periph_sbuf, }; #define SCSI_XPT_XPORT(x, X) \ @@ -630,9 +622,7 @@ SCSI_XPT_XPORT(ppb, PPB); #undef SCSI_XPORT_XPORT static struct xpt_proto_ops scsi_proto_ops = { - .announce = scsi_proto_announce, .announce_sbuf = scsi_proto_announce_sbuf, - .denounce = scsi_proto_denounce, .denounce_sbuf = scsi_proto_denounce_sbuf, .debug_out = scsi_proto_debug_out, }; @@ -820,7 +810,7 @@ again: /*retries*/4, probedone, MSG_SIMPLE_Q_TAG, - (u_int8_t *)inq_buf, + (uint8_t *)inq_buf, inquiry_len, /*evpd*/FALSE, /*page_code*/0, @@ -848,7 +838,7 @@ again: } scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG, RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size, - SSD_FULL_SIZE, 60000); break; + SSD_FULL_SIZE, 60000); break; } case PROBE_MODE_SENSE: @@ -896,7 +886,7 @@ again: /*retries*/4, probedone, MSG_SIMPLE_Q_TAG, - (u_int8_t *)vpd_list, + (uint8_t *)vpd_list, sizeof(*vpd_list), /*evpd*/TRUE, SVPD_SUPPORTED_PAGE_LIST, @@ -990,7 +980,7 @@ done: /*retries*/4, probedone, MSG_SIMPLE_Q_TAG, - (u_int8_t *)serial_buf, + (uint8_t *)serial_buf, sizeof(*serial_buf), /*evpd*/TRUE, SVPD_UNIT_SERIAL_NUMBER, @@ -1026,7 +1016,7 @@ done: /*retries*/4, probedone, MSG_SIMPLE_Q_TAG, - (u_int8_t *)inq_buf, + (uint8_t *)inq_buf, inquiry_len, /*evpd*/FALSE, /*page_code*/0, @@ -1172,7 +1162,7 @@ probedone(struct cam_periph *periph, union ccb *done_ccb) probe_softc *softc; struct cam_path *path; struct scsi_inquiry_data *inq_buf; - u_int32_t priority; + uint32_t priority; CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n")); @@ -1211,7 +1201,7 @@ out: case PROBE_FULL_INQUIRY: { if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) { - u_int8_t periph_qual; + uint8_t periph_qual; path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID; scsi_find_quirk(path->device); @@ -1423,9 +1413,9 @@ out: mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr; if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) { struct scsi_control_page *page; - u_int8_t *offset; + uint8_t *offset; - offset = ((u_int8_t *)&mode_hdr[1]) + offset = ((uint8_t *)&mode_hdr[1]) + mode_hdr->blk_desc_len; page = (struct scsi_control_page *)offset; path->device->queue_flags = page->queue_flags; @@ -1581,7 +1571,7 @@ probe_device_check: { struct ccb_scsiio *csio; struct scsi_vpd_unit_serial_number *serial_buf; - u_int32_t priority; + uint32_t priority; int changed; int have_serialnum; @@ -1600,7 +1590,7 @@ probe_device_check: && (serial_buf->length > 0)) { have_serialnum = 1; path->device->serial_num = - (u_int8_t *)malloc((serial_buf->length + 1), + (uint8_t *)malloc((serial_buf->length + 1), M_CAMXPT, M_NOWAIT); if (path->device->serial_num != NULL) { int start, slen; @@ -1642,7 +1632,7 @@ probe_device_check: */ if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) { MD5_CTX context; - u_int8_t digest[16]; + uint8_t digest[16]; MD5Init(&context); @@ -1832,7 +1822,7 @@ probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new, struct scsi_report_luns_data *old; u_int idx1, idx2, nlun_old, nlun_new; lun_id_t this_lun; - u_int8_t *ol, *nl; + uint8_t *ol, *nl; if (path->target == NULL) { return; @@ -2968,7 +2958,7 @@ scsi_toggle_tags(struct cam_path *path) * Handle any per-device event notifications that require action by the XPT. */ static void -scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target, +scsi_dev_async(uint32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, void *async_arg) { cam_status status; @@ -3127,13 +3117,13 @@ scsi_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb) if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0 && spi->bus_width > 0) { if (freq != 0) { - sbuf_printf(sb, ", "); + sbuf_cat(sb, ", "); } else { - sbuf_printf(sb, " ("); + sbuf_cat(sb, " ("); } sbuf_printf(sb, "%dbit)", 8 * (0x01 << spi->bus_width)); } else if (freq != 0) { - sbuf_printf(sb, ")"); + sbuf_putc(sb, ')'); } } if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) { @@ -3147,64 +3137,7 @@ scsi_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb) if (fc->valid & CTS_FC_VALID_PORT) sbuf_printf(sb, " PortID 0x%x", fc->port); } - sbuf_printf(sb, "\n"); -} - -static void -scsi_announce_periph(struct cam_periph *periph) -{ - struct ccb_trans_settings cts; - u_int speed, freq, mb; - - memset(&cts, 0, sizeof(cts)); - _scsi_announce_periph(periph, &speed, &freq, &cts); - if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) - return; - - mb = speed / 1000; - if (mb > 0) - printf("%s%d: %d.%03dMB/s transfers", - periph->periph_name, periph->unit_number, - mb, speed % 1000); - else - printf("%s%d: %dKB/s transfers", periph->periph_name, - periph->unit_number, speed); - /* Report additional information about SPI connections */ - if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) { - struct ccb_trans_settings_spi *spi; - - spi = &cts.xport_specific.spi; - if (freq != 0) { - printf(" (%d.%03dMHz%s, offset %d", freq / 1000, - freq % 1000, - (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0 - ? " DT" : "", - spi->sync_offset); - } - if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0 - && spi->bus_width > 0) { - if (freq != 0) { - printf(", "); - } else { - printf(" ("); - } - printf("%dbit)", 8 * (0x01 << spi->bus_width)); - } else if (freq != 0) { - printf(")"); - } - } - if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) { - struct ccb_trans_settings_fc *fc; - - fc = &cts.xport_specific.fc; - if (fc->valid & CTS_FC_VALID_WWNN) - printf(" WWNN 0x%llx", (long long) fc->wwnn); - if (fc->valid & CTS_FC_VALID_WWPN) - printf(" WWPN 0x%llx", (long long) fc->wwpn); - if (fc->valid & CTS_FC_VALID_PORT) - printf(" PortID 0x%x", fc->port); - } - printf("\n"); + sbuf_putc(sb, '\n'); } static void @@ -3214,24 +3147,12 @@ scsi_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb) } static void -scsi_proto_announce(struct cam_ed *device) -{ - scsi_print_inquiry(&device->inq_data); -} - -static void scsi_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb) { scsi_print_inquiry_short_sbuf(sb, &device->inq_data); } static void -scsi_proto_denounce(struct cam_ed *device) -{ - scsi_print_inquiry_short(&device->inq_data); -} - -static void scsi_proto_debug_out(union ccb *ccb) { char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1]; diff --git a/sys/cam/scsi/smp_all.c b/sys/cam/scsi/smp_all.c index 1b82327f9fb9..926222c27410 100644 --- a/sys/cam/scsi/smp_all.c +++ b/sys/cam/scsi/smp_all.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2010 Spectra Logic Corporation * All rights reserved. @@ -36,9 +36,6 @@ * Serial Management Protocol helper functions. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/types.h> #ifdef _KERNEL @@ -215,7 +212,7 @@ smp_command_decode(uint8_t *smp_request, int request_len, struct sbuf *sb, */ if ((cur_len < 6) && (line_len < (strlen(line_prefix) + 3))) { - sbuf_printf(sb, "..."); + sbuf_cat(sb, "..."); return; } if (cur_len < 3) { @@ -264,7 +261,7 @@ smp_error_sbuf(struct cam_device *device, struct ccb_smpio *smpio, cam_path_string(device, path_str, sizeof(path_str)); #endif smp_command_sbuf(smpio, sb, path_str, 80 - strlen(path_str), 80); - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); sbuf_cat(sb, path_str); sbuf_printf(sb, "SMP Error: %s (0x%x)\n", @@ -281,7 +278,7 @@ void smp_report_general_sbuf(struct smp_report_general_response *response, int response_len, struct sbuf *sb) { - sbuf_printf(sb, "Report General\n"); + sbuf_cat(sb, "Report General\n"); sbuf_printf(sb, "Response Length: %d words (%d bytes)\n", response->response_len, response->response_len * SMP_WORD_LEN); @@ -423,7 +420,7 @@ smp_report_manuf_info_sbuf(struct smp_report_manuf_info_response *response, char vendor[16], product[48], revision[16]; char comp_vendor[16]; - sbuf_printf(sb, "Report Manufacturer Information\n"); + sbuf_cat(sb, "Report Manufacturer Information\n"); sbuf_printf(sb, "Expander Change count: %d\n", scsi_2btoul(response->expander_change_count)); sbuf_printf(sb, "SAS 1.1 Format: %s\n", @@ -440,7 +437,7 @@ smp_report_manuf_info_sbuf(struct smp_report_manuf_info_response *response, uint8_t *curbyte; int line_start, line_cursor; - sbuf_printf(sb, "Vendor Specific Data:\n"); + sbuf_cat(sb, "Vendor Specific Data:\n"); /* * Print out the bytes roughly in the style of hd(1), but @@ -464,14 +461,14 @@ smp_report_manuf_info_sbuf(struct smp_report_manuf_info_response *response, sbuf_printf(sb, "%02x", *curbyte); if (line_cursor == 15) { - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); line_start = 1; } else sbuf_printf(sb, " %s", (line_cursor == 7) ? " " : ""); } if (line_cursor != 16) - sbuf_printf(sb, "\n"); + sbuf_putc(sb, '\n'); return; } diff --git a/sys/cam/scsi/smp_all.h b/sys/cam/scsi/smp_all.h index 7fe44d2807a9..3c310ee864c4 100644 --- a/sys/cam/scsi/smp_all.h +++ b/sys/cam/scsi/smp_all.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2010 Spectra Logic Corporation * All rights reserved. @@ -30,7 +30,6 @@ * POSSIBILITY OF SUCH DAMAGES. * * $Id: //depot/users/kenm/FreeBSD-test/sys/cam/scsi/smp_all.h#4 $ - * $FreeBSD$ */ /* |