Lines Matching +full:hs400 +full:- +full:cmd +full:- +full:int +full:- +full:delay
2 * Copyright (c) 1997-2007 Kenneth D. Merry
196 {"cmd", CAM_CMD_SCSI_CMD, CAM_ARG_NONE, scsicmd_opts},
209 {"devlist", CAM_CMD_DEVTREE, CAM_ARG_NONE, "-b"},
238 {"-?", CAM_CMD_USAGE, CAM_ARG_NONE, NULL},
239 {"-h", CAM_CMD_USAGE, CAM_ARG_NONE, NULL},
245 int num_periphs;
248 int device_id_len;
272 static int getdevlist(struct cam_device *device);
273 static int getdevtree(int argc, char **argv, char *combinedopt);
274 static int getdevtype(struct cam_device *device);
275 static int print_dev_scsi(struct device_match_result *dev_result, char *tmpstr);
276 static int print_dev_ata(struct device_match_result *dev_result, char *tmpstr);
277 static int print_dev_semb(struct device_match_result *dev_result, char *tmpstr);
278 static int print_dev_mmcsd(struct device_match_result *dev_result,
280 static int print_dev_nvme(struct device_match_result *dev_result, char *tmpstr);
281 static int requestsense(struct cam_device *device, int argc, char **argv,
282 char *combinedopt, int task_attr, int retry_count,
283 int timeout);
284 static int testunitready(struct cam_device *device, int task_attr,
285 int retry_count, int timeout, int quiet);
286 static int scsistart(struct cam_device *device, int startstop, int loadeject,
287 int task_attr, int retry_count, int timeout);
288 static int scsiinquiry(struct cam_device *device, int task_attr,
289 int retry_count, int timeout);
290 static int scsiserial(struct cam_device *device, int task_attr,
291 int retry_count, int timeout);
292 static int parse_btl(char *tstr, path_id_t *bus, target_id_t *target,
294 static int reprobe(struct cam_device *device);
295 static int dorescan_or_reset(int argc, char **argv, int rescan);
296 static int rescan_or_reset_bus(path_id_t bus, int rescan);
297 static int scanlun_or_reset_dev(path_id_t bus, target_id_t target,
298 lun_id_t lun, int scan);
299 static int readdefects(struct cam_device *device, int argc, char **argv,
300 char *combinedopt, int task_attr, int retry_count,
301 int timeout);
302 static void modepage(struct cam_device *device, int argc, char **argv,
303 char *combinedopt, int task_attr, int retry_count,
304 int timeout);
305 static int scsicmd(struct cam_device *device, int argc, char **argv,
306 char *combinedopt, int task_attr, int retry_count,
307 int timeout);
308 static int smpcmd(struct cam_device *device, int argc, char **argv,
309 char *combinedopt, int retry_count, int timeout);
310 static int mmcsdcmd(struct cam_device *device, int argc, char **argv,
311 char *combinedopt, int retry_count, int timeout);
312 static int smpreportgeneral(struct cam_device *device, int argc, char **argv,
313 char *combinedopt, int retry_count, int timeout);
314 static int smpphycontrol(struct cam_device *device, int argc, char **argv,
315 char *combinedopt, int retry_count, int timeout);
316 static int smpmaninfo(struct cam_device *device, int argc, char **argv,
317 char *combinedopt, int retry_count, int timeout);
318 static int getdevid(struct cam_devitem *item);
319 static int buildbusdevlist(struct cam_devlist *devlist);
323 static int smpphylist(struct cam_device *device, int argc, char **argv,
324 char *combinedopt, int retry_count, int timeout);
325 static int tagcontrol(struct cam_device *device, int argc, char **argv,
330 static int get_cpi(struct cam_device *device, struct ccb_pathinq *cpi);
331 static int get_cgd(struct cam_device *device, struct ccb_getdev *cgd);
332 static int get_print_cts(struct cam_device *device, int user_settings,
333 int quiet, struct ccb_trans_settings *cts);
334 static int ratecontrol(struct cam_device *device, int task_attr,
335 int retry_count, int timeout, int argc, char **argv,
337 static int scsiformat(struct cam_device *device, int argc, char **argv,
338 char *combinedopt, int task_attr, int retry_count,
339 int timeout);
340 static int sanitize(struct cam_device *device, int argc, char **argv,
341 char *combinedopt, int task_attr, int retry_count,
342 int timeout);
343 static int scsireportluns(struct cam_device *device, int argc, char **argv,
344 char *combinedopt, int task_attr, int retry_count,
345 int timeout);
346 static int scsireadcapacity(struct cam_device *device, int argc, char **argv,
347 char *combinedopt, int task_attr, int retry_count,
348 int timeout);
349 static int atapm(struct cam_device *device, int argc, char **argv,
350 char *combinedopt, int retry_count, int timeout);
351 static int atasecurity(struct cam_device *device, int retry_count, int timeout,
352 int argc, char **argv, char *combinedopt);
353 static int atahpa(struct cam_device *device, int retry_count, int timeout,
354 int argc, char **argv, char *combinedopt);
355 static int ataama(struct cam_device *device, int retry_count, int timeout,
356 int argc, char **argv, char *combinedopt);
357 static int scsiprintoneopcode(struct cam_device *device, int req_opcode,
358 int sa_set, int req_sa, uint8_t *buf,
360 static int scsiprintopcodes(struct cam_device *device, int td_req, uint8_t *buf,
362 static int scsiopcodes(struct cam_device *device, int argc, char **argv,
363 char *combinedopt, int task_attr, int retry_count,
364 int timeout, int verbose);
378 int num_matches = 0;
380 for (opts = table; (opts != NULL) && (opts->optname != NULL);
382 if (strncmp(opts->optname, arg, strlen(arg)) == 0) {
383 *cmdnum = opts->cmdnum;
384 *argnum = opts->argnum;
385 *subopt = opts->subopt;
397 static int
402 int error = 0;
406 ccb->ccb_h.func_code = XPT_GDEVLIST;
407 ccb->ccb_h.flags = CAM_DIR_NONE;
408 ccb->ccb_h.retry_count = 1;
409 ccb->cgdl.index = 0;
410 ccb->cgdl.status = CAM_GDEVLIST_MORE_DEVS;
411 while (ccb->cgdl.status == CAM_GDEVLIST_MORE_DEVS) {
420 switch (ccb->cgdl.status) {
437 ccb->cgdl.periph_name,
438 ccb->cgdl.unit_number,
439 ccb->cgdl.generation,
440 ccb->cgdl.index,
447 if (ccb->cgdl.status == CAM_GDEVLIST_LIST_CHANGED)
448 ccb->cgdl.index = 0;
456 static int
457 getdevtree(int argc, char **argv, char *combinedopt)
460 int bufsize, fd;
461 unsigned int i;
462 int need_close = 0;
463 int error = 0;
464 int skip_device = 0;
465 int busonly = 0;
466 int c;
468 while ((c = getopt(argc, argv, combinedopt)) != -1) {
479 if ((fd = open(XPT_DEVICE, O_RDWR)) == -1) {
513 if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
550 bus_result->path_id,
551 bus_result->dev_name,
552 bus_result->unit_number,
553 bus_result->bus_id,
567 if ((dev_result->flags
575 if (dev_result->protocol == PROTO_SCSI) {
581 } else if (dev_result->protocol == PROTO_ATA ||
582 dev_result->protocol == PROTO_SATAPM) {
588 } else if (dev_result->protocol == PROTO_MMCSD){
594 } else if (dev_result->protocol == PROTO_SEMB) {
600 } else if (dev_result->protocol == PROTO_NVME) {
614 fprintf(stdout, "%-33s at scbus%d "
617 dev_result->path_id,
618 dev_result->target_id,
619 (uintmax_t)dev_result->target_lun);
638 periph_result->periph_name,
639 periph_result->unit_number);
662 static int
666 int error;
671 error = get_device_type(cam_dev, -1, 0, 0, &dt);
680 static int
685 cam_strvis(vendor, dev_result->inq_data.vendor,
686 sizeof(dev_result->inq_data.vendor), sizeof(vendor));
687 cam_strvis(product, dev_result->inq_data.product,
688 sizeof(dev_result->inq_data.product), sizeof(product));
689 cam_strvis(revision, dev_result->inq_data.revision,
690 sizeof(dev_result->inq_data.revision), sizeof(revision));
696 static int
701 cam_strvis(product, dev_result->ident_data.model,
702 sizeof(dev_result->ident_data.model), sizeof(product));
703 cam_strvis(revision, dev_result->ident_data.revision,
704 sizeof(dev_result->ident_data.revision), sizeof(revision));
710 static int
716 sid = (struct sep_identify_data *)&dev_result->ident_data;
717 cam_strvis(vendor, sid->vendor_id,
718 sizeof(sid->vendor_id), sizeof(vendor));
719 cam_strvis(product, sid->product_id,
720 sizeof(sid->product_id), sizeof(product));
721 cam_strvis(revision, sid->product_rev,
722 sizeof(sid->product_rev), sizeof(revision));
723 cam_strvis(fw, sid->firmware_rev,
724 sizeof(sid->firmware_rev), sizeof(fw));
730 static int
738 dev = cam_open_btl(dev_result->path_id, dev_result->target_id,
739 dev_result->target_lun, O_RDWR, NULL);
752 advi = &ccb->cdai;
753 advi->ccb_h.flags = CAM_DIR_IN;
754 advi->ccb_h.func_code = XPT_DEV_ADVINFO;
755 advi->flags = CDAI_FLAG_NONE;
756 advi->buftype = CDAI_TYPE_MMC_PARAMS;
757 advi->bufsiz = sizeof(struct mmc_params);
758 advi->buf = (uint8_t *)&mmc_ident_data;
780 static int
793 advi = &ccb->cdai;
794 advi->ccb_h.flags = CAM_DIR_IN;
795 advi->ccb_h.func_code = XPT_DEV_ADVINFO;
796 advi->flags = CDAI_FLAG_NONE;
797 advi->buftype = CDAI_TYPE_NVME_CNTRL;
798 advi->bufsiz = sizeof(struct nvme_controller_data);
799 advi->buf = (uint8_t *)cdata;
807 if (advi->ccb_h.status != CAM_REQ_CMP) {
808 warnx("got CAM error %#x", advi->ccb_h.status);
817 static int
824 dev = cam_open_btl(dev_result->path_id, dev_result->target_id,
825 dev_result->target_lun, O_RDWR, NULL);
842 static int
843 requestsense(struct cam_device *device, int argc, char **argv,
844 char *combinedopt, int task_attr, int retry_count, int timeout)
846 int c;
847 int descriptor_sense = 0;
848 int do_hexdump = 0;
851 int error = 0;
854 while ((c = getopt(argc, argv, combinedopt)) != -1) {
874 CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
878 scsi_request_sense(&ccb->csio,
890 cdb = (struct scsi_request_sense *)&ccb->csio.cdb_io.cdb_bytes;
891 cdb->byte2 |= SRS_DESC;
894 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
897 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
912 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
919 returned_bytes = ccb->csio.dxfer_len - ccb->csio.resid;
936 &device->inq_data, scsiio_cdb_ptr(&ccb->csio),
937 ccb->csio.cdb_len);
950 static int
951 testunitready(struct cam_device *device, int task_attr, int retry_count,
952 int timeout, int quiet)
954 int error = 0;
959 scsi_test_unit_ready(&ccb->csio,
967 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
970 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
979 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
998 static int
999 scsistart(struct cam_device *device, int startstop, int loadeject,
1000 int task_attr, int retry_count, int timeout)
1003 int error = 0;
1011 * queueing is turned off, the tag action is a no-op. We override
1020 scsi_start_stop(&ccb->csio,
1031 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
1034 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
1042 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP)
1076 int
1077 scsidoinquiry(struct cam_device *device, int argc, char **argv,
1078 char *combinedopt, int task_attr, int retry_count, int timeout)
1080 int c;
1081 int error = 0;
1083 while ((c = getopt(argc, argv, combinedopt)) != -1) {
1121 static int
1122 scsiinquiry(struct cam_device *device, int task_attr, int retry_count,
1123 int timeout)
1127 int error = 0;
1152 * - The SCSI spec says that when a length field is only 1 byte,
1158 * 0, and don't return any data. One Pioneer DVD-R drive
1164 * - The second reason not to use the full inquiry data length is
1179 scsi_inquiry(&ccb->csio,
1191 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
1194 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
1202 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1218 fprintf(stdout, "%s%d: ", device->device_name,
1219 device->dev_unit_num);
1227 static int
1228 scsiserial(struct cam_device *device, int task_attr, int retry_count,
1229 int timeout)
1234 int error = 0;
1252 scsi_inquiry(&ccb->csio,
1264 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
1267 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
1276 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1292 bcopy(serial_buf->serial_num, serial_num, serial_buf->length);
1293 serial_num[serial_buf->length] = '\0';
1298 device->device_name, device->dev_unit_num);
1307 int
1315 int retval = 0;
1327 ccb->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1328 ccb->cts.type = CTS_TYPE_CURRENT_SETTINGS;
1331 || ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)) {
1351 if (ccb->cts.transport == XPORT_SPI) {
1353 &ccb->cts.xport_specific.spi;
1355 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) != 0) {
1356 freq = scsi_calc_syncsrate(spi->sync_period);
1359 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0) {
1360 speed *= (0x01 << spi->bus_width);
1362 } else if (ccb->cts.transport == XPORT_FC) {
1364 &ccb->cts.xport_specific.fc;
1366 if (fc->valid & CTS_FC_VALID_SPEED)
1367 speed = fc->bitrate;
1368 } else if (ccb->cts.transport == XPORT_SAS) {
1370 &ccb->cts.xport_specific.sas;
1372 if (sas->valid & CTS_SAS_VALID_SPEED)
1373 speed = sas->bitrate;
1374 } else if (ccb->cts.transport == XPORT_ATA) {
1376 &ccb->cts.xport_specific.ata;
1378 if (pata->valid & CTS_ATA_VALID_MODE)
1379 speed = ata_mode2speed(pata->mode);
1380 } else if (ccb->cts.transport == XPORT_SATA) {
1382 &ccb->cts.xport_specific.sata;
1384 if (sata->valid & CTS_SATA_VALID_REVISION)
1385 speed = ata_revision2speed(sata->revision);
1391 device->device_name, device->dev_unit_num,
1395 device->device_name, device->dev_unit_num,
1399 if (ccb->cts.transport == XPORT_SPI) {
1401 &ccb->cts.xport_specific.spi;
1403 if (((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0)
1404 && (spi->sync_offset != 0))
1406 freq % 1000, spi->sync_offset);
1408 if (((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
1409 && (spi->bus_width > 0)) {
1410 if (((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0)
1411 && (spi->sync_offset != 0)) {
1416 fprintf(stdout, "%dbit)", 8 * (0x01 << spi->bus_width));
1417 } else if (((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0)
1418 && (spi->sync_offset != 0)) {
1421 } else if (ccb->cts.transport == XPORT_ATA) {
1423 &ccb->cts.xport_specific.ata;
1426 if (pata->valid & CTS_ATA_VALID_MODE)
1427 printf("%s, ", ata_mode2string(pata->mode));
1428 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
1429 printf("ATAPI %dbytes, ", pata->atapi);
1430 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
1431 printf("PIO %dbytes", pata->bytecount);
1433 } else if (ccb->cts.transport == XPORT_SATA) {
1435 &ccb->cts.xport_specific.sata;
1438 if (sata->valid & CTS_SATA_VALID_REVISION)
1439 printf("SATA %d.x, ", sata->revision);
1442 if (sata->valid & CTS_SATA_VALID_MODE)
1443 printf("%s, ", ata_mode2string(sata->mode));
1444 if ((sata->valid & CTS_SATA_VALID_ATAPI) && sata->atapi != 0)
1445 printf("ATAPI %dbytes, ", sata->atapi);
1446 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
1447 printf("PIO %dbytes", sata->bytecount);
1451 if (ccb->cts.protocol == PROTO_SCSI) {
1453 &ccb->cts.proto_specific.scsi;
1454 if (scsi->valid & CTS_SCSI_VALID_TQ) {
1455 if (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) {
1471 atahpa_print(struct ata_params *parm, u_int64_t hpasize, int header)
1473 uint32_t lbasize = (uint32_t)parm->lba_size_1 |
1474 ((uint32_t)parm->lba_size_2 << 16);
1476 u_int64_t lbasize48 = ((u_int64_t)parm->lba_size48_1) |
1477 ((u_int64_t)parm->lba_size48_2 << 16) |
1478 ((u_int64_t)parm->lba_size48_3 << 32) |
1479 ((u_int64_t)parm->lba_size48_4 << 48);
1487 if (parm->support.command1 & ATA_SUPPORT_PROTECTED) {
1492 printf("HPA - Security ");
1493 if (parm->support.command2 & ATA_SUPPORT_MAXSECURITY)
1494 printf("yes %s\n", (parm->enabled.command2 &
1504 ataama_print(struct ata_params *parm, u_int64_t nativesize, int header)
1506 uint32_t lbasize = (uint32_t)parm->lba_size_1 |
1507 ((uint32_t)parm->lba_size_2 << 16);
1509 u_int64_t lbasize48 = ((u_int64_t)parm->lba_size48_1) |
1510 ((u_int64_t)parm->lba_size48_2 << 16) |
1511 ((u_int64_t)parm->lba_size48_3 << 32) |
1512 ((u_int64_t)parm->lba_size48_4 << 48);
1520 if (parm->support2 & ATA_SUPPORT_AMAX_ADDR) {
1529 static int
1534 if (parm->satacapabilities != 0xffff &&
1535 parm->satacapabilities != 0x0000)
1545 uint32_t lbasize = (uint32_t)parm->lba_size_1 |
1546 ((uint32_t)parm->lba_size_2 << 16);
1548 u_int64_t lbasize48 = ((u_int64_t)parm->lba_size48_1) |
1549 ((u_int64_t)parm->lba_size48_2 << 16) |
1550 ((u_int64_t)parm->lba_size48_3 << 32) |
1551 ((u_int64_t)parm->lba_size48_4 << 48);
1555 proto = (parm->config == ATA_PROTO_CFA) ? "CFA" :
1556 (parm->config & ATA_PROTO_ATAPI) ? "ATAPI" : "ATA";
1557 if (ata_version(parm->version_major) == 0) {
1559 } else if (ata_version(parm->version_major) <= 7) {
1560 printf("%s-%d", proto,
1561 ata_version(parm->version_major));
1562 } else if (ata_version(parm->version_major) == 8) {
1563 printf("%s8-ACS", proto);
1565 printf("ACS-%d %s",
1566 ata_version(parm->version_major) - 7, proto);
1568 if (parm->satacapabilities && parm->satacapabilities != 0xffff) {
1569 if (parm->satacapabilities & ATA_SATA_GEN3)
1571 else if (parm->satacapabilities & ATA_SATA_GEN2)
1573 else if (parm->satacapabilities & ATA_SATA_GEN1)
1580 printf("device model %.40s\n", parm->model);
1581 printf("firmware revision %.8s\n", parm->revision);
1582 printf("serial number %.20s\n", parm->serial);
1583 if (parm->enabled.extension & ATA_SUPPORT_64BITWWN) {
1585 parm->wwn[0], parm->wwn[1], parm->wwn[2], parm->wwn[3]);
1587 printf("additional product id %.8s\n", parm->product_id);
1588 if (parm->enabled.extension & ATA_SUPPORT_MEDIASN) {
1590 parm->media_serial);
1593 printf("cylinders %d\n", parm->cylinders);
1594 printf("heads %d\n", parm->heads);
1595 printf("sectors/track %d\n", parm->sectors);
1601 if (parm->config == ATA_PROTO_CFA ||
1602 (parm->support.command2 & ATA_SUPPORT_CFA))
1606 parm->capabilities1 & ATA_SUPPORT_LBA ? " " : " not ");
1613 parm->support.command2 & ATA_SUPPORT_ADDRESS48 ? " " : " not ");
1636 if ((parm->capabilities1 & ATA_SUPPORT_IORDY) == 0)
1641 parm->capabilities1 & ATA_SUPPORT_DMA ? " " : " not ");
1642 if (parm->capabilities1 & ATA_SUPPORT_DMA) {
1643 if (parm->mwdmamodes & 0xff) {
1645 if (parm->mwdmamodes & 0x04)
1647 else if (parm->mwdmamodes & 0x02)
1649 else if (parm->mwdmamodes & 0x01)
1653 if ((parm->atavalid & ATA_FLAG_88) &&
1654 (parm->udmamodes & 0xff)) {
1656 if (parm->udmamodes & 0x40)
1658 else if (parm->udmamodes & 0x20)
1660 else if (parm->udmamodes & 0x10)
1662 else if (parm->udmamodes & 0x08)
1664 else if (parm->udmamodes & 0x04)
1666 else if (parm->udmamodes & 0x02)
1668 else if (parm->udmamodes & 0x01)
1675 if (parm->media_rotation_rate == 1) {
1676 printf("media RPM non-rotating\n");
1677 } else if (parm->media_rotation_rate >= 0x0401 &&
1678 parm->media_rotation_rate <= 0xFFFE) {
1680 parm->media_rotation_rate);
1683 printf("Zoned-Device Commands ");
1684 switch (parm->support3 & ATA_SUPPORT_ZONE_MASK) {
1698 parm->support.command1 & ATA_SUPPORT_LOOKAHEAD ? "yes" : "no",
1699 parm->enabled.command1 & ATA_SUPPORT_LOOKAHEAD ? "yes" : "no");
1701 parm->support.command1 & ATA_SUPPORT_WRITECACHE ? "yes" : "no",
1702 parm->enabled.command1 & ATA_SUPPORT_WRITECACHE ? "yes" : "no");
1704 parm->support.command2 & ATA_SUPPORT_FLUSHCACHE ? "yes" : "no",
1705 parm->enabled.command2 & ATA_SUPPORT_FLUSHCACHE ? "yes" : "no");
1707 if (atasata(parm) && (parm->satacapabilities & ATA_SUPPORT_NCQ)) {
1709 ATA_QUEUE_LEN(parm->queue) + 1);
1711 parm->satacapabilities & ATA_SUPPORT_NCQ_PRIO ?
1713 printf("NCQ Non-Data Command %s\n",
1714 parm->satacapabilities2 & ATA_SUPPORT_NCQ_NON_DATA ?
1717 parm->satacapabilities2 & ATA_SUPPORT_NCQ_STREAM ?
1720 parm->satacapabilities2 & ATA_SUPPORT_RCVSND_FPDMA_QUEUED ?
1723 parm->satasupport & ATA_SUPPORT_NCQ_AUTOSENSE ?
1729 parm->support.command1 & ATA_SUPPORT_SMART ? "yes" : "no",
1730 parm->enabled.command1 & ATA_SUPPORT_SMART ? "yes" : "no");
1732 parm->support.command1 & ATA_SUPPORT_SECURITY ? "yes" : "no",
1733 parm->enabled.command1 & ATA_SUPPORT_SECURITY ? "yes" : "no");
1735 parm->support.command1 & ATA_SUPPORT_POWERMGT ? "yes" : "no",
1736 parm->enabled.command1 & ATA_SUPPORT_POWERMGT ? "yes" : "no");
1738 parm->support.command2 & ATA_SUPPORT_MICROCODE ? "yes" : "no",
1739 parm->enabled.command2 & ATA_SUPPORT_MICROCODE ? "yes" : "no");
1741 parm->support.command2 & ATA_SUPPORT_APM ? "yes" : "no",
1742 parm->enabled.command2 & ATA_SUPPORT_APM ? "yes" : "no");
1743 if (parm->support.command2 & ATA_SUPPORT_APM) {
1745 parm->apm_value & 0xff, parm->apm_value & 0xff);
1749 parm->support.command2 & ATA_SUPPORT_AUTOACOUSTIC ? "yes" :"no",
1750 parm->enabled.command2 & ATA_SUPPORT_AUTOACOUSTIC ? "yes" :"no");
1751 if (parm->support.command2 & ATA_SUPPORT_AUTOACOUSTIC) {
1753 ATA_ACOUSTIC_CURRENT(parm->acoustic),
1754 ATA_ACOUSTIC_CURRENT(parm->acoustic),
1755 ATA_ACOUSTIC_VENDOR(parm->acoustic),
1756 ATA_ACOUSTIC_VENDOR(parm->acoustic));
1760 parm->support.command2 & ATA_SUPPORT_NOTIFY ? "yes" : "no",
1761 parm->enabled.command2 & ATA_SUPPORT_NOTIFY ? "yes" : "no");
1762 printf("power-up in Standby %s %s\n",
1763 parm->support.command2 & ATA_SUPPORT_STANDBY ? "yes" : "no",
1764 parm->enabled.command2 & ATA_SUPPORT_STANDBY ? "yes" : "no");
1765 printf("write-read-verify %s %s",
1766 parm->support2 & ATA_SUPPORT_WRITEREADVERIFY ? "yes" : "no",
1767 parm->enabled2 & ATA_SUPPORT_WRITEREADVERIFY ? "yes" : "no");
1768 if (parm->support2 & ATA_SUPPORT_WRITEREADVERIFY) {
1770 parm->wrv_mode, parm->wrv_mode);
1774 parm->support.extension & ATA_SUPPORT_UNLOAD ? "yes" : "no",
1775 parm->enabled.extension & ATA_SUPPORT_UNLOAD ? "yes" : "no");
1777 parm->support.extension & ATA_SUPPORT_GENLOG ? "yes" : "no",
1778 parm->enabled.extension & ATA_SUPPORT_GENLOG ? "yes" : "no");
1779 printf("free-fall %s %s\n",
1780 parm->support2 & ATA_SUPPORT_FREEFALL ? "yes" : "no",
1781 parm->enabled2 & ATA_SUPPORT_FREEFALL ? "yes" : "no");
1783 parm->support2 & ATA_SUPPORT_SENSE_REPORT ? "yes" : "no",
1784 parm->enabled2 & ATA_SUPPORT_SENSE_REPORT ? "yes" : "no");
1786 parm->support2 & ATA_SUPPORT_EPC ? "yes" : "no",
1787 parm->enabled2 & ATA_SUPPORT_EPC ? "yes" : "no");
1789 parm->support2 & ATA_SUPPORT_DSN ? "yes" : "no",
1790 parm->enabled2 & ATA_SUPPORT_DSN ? "yes" : "no");
1792 if (parm->support_dsm & ATA_SUPPORT_DSM_TRIM) {
1794 printf("DSM - max 512byte blocks ");
1795 if (parm->max_dsm_blocks == 0x00)
1799 parm->max_dsm_blocks);
1801 printf("DSM - deterministic read ");
1802 if (parm->support3 & ATA_SUPPORT_DRAT) {
1803 if (parm->support3 & ATA_SUPPORT_RZAT)
1814 ((parm->tcg & 0xc000) == 0x4000) && (parm->tcg & ATA_SUPPORT_TCG) ?
1817 parm->support3 & ATA_ENCRYPTS_ALL_USER_DATA ? "yes" : "no");
1819 if (parm->multi & ATA_SUPPORT_SANITIZE) {
1821 parm->multi & ATA_SUPPORT_BLOCK_ERASE_EXT ? "block, " : "",
1822 parm->multi & ATA_SUPPORT_OVERWRITE_EXT ? "overwrite, " : "",
1823 parm->multi & ATA_SUPPORT_CRYPTO_SCRAMBLE_EXT ? "crypto" : "");
1824 printf("Sanitize - commands allowed %s\n",
1825 parm->multi & ATA_SUPPORT_SANITIZE_ALLOWED ? "yes" : "no");
1826 printf("Sanitize - antifreeze lock %s\n",
1827 parm->multi & ATA_SUPPORT_ANTIFREEZE_LOCK_EXT ? "yes" : "no");
1833 static int
1839 ata_pass_16 = (struct ata_pass_16 *)ccb->csio.cdb_io.cdb_bytes;
1840 ata_cmd.command = ata_pass_16->command;
1841 ata_cmd.control = ata_pass_16->control;
1842 ata_cmd.features = ata_pass_16->features;
1847 ccb->csio.ccb_h.timeout);
1851 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
1854 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
1862 * Consider any non-CAM_REQ_CMP status as error and report it here,
1865 if (!(ata_pass_16->flags & AP_FLAG_CHK_COND) &&
1866 (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1879 static int
1884 ata_op_string(&(ccb->ataio.cmd)),
1885 ccb->ataio.ccb_h.timeout);
1889 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
1892 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
1895 warn("error sending ATA %s", ata_op_string(&(ccb->ataio.cmd)));
1900 * Consider any non-CAM_REQ_CMP status as error and report it here,
1903 if (!(ccb->ataio.cmd.flags & CAM_ATAIO_NEEDRESULT) &&
1904 (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1905 warnx("ATA %s failed", ata_op_string(&(ccb->ataio.cmd)));
1916 static int
1917 ata_do_pass_16(struct cam_device *device, union ccb *ccb, int retries,
1921 uint16_t dxfer_len, int timeout)
1932 CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
1934 scsi_ata_pass_16(&ccb->csio,
1954 static int
1961 return (-1);
1973 static int
1974 ata_do_cmd(struct cam_device *device, union ccb *ccb, int retries,
1978 uint16_t dxfer_len, int timeout, int force48bit)
1980 int retval;
1983 if (retval == -1)
1993 CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->ataio);
1994 cam_fill_ataio(&ccb->ataio,
2004 ata_48bit_cmd(&ccb->ataio, command, features, lba, sector_count);
2006 ata_28bit_cmd(&ccb->ataio, command, features, lba, sector_count);
2009 ccb->ataio.cmd.flags |= CAM_ATAIO_NEEDRESULT;
2030 static int
2036 int retval;
2057 "last power-on or hardware reset");
2073 static int
2074 ata_read_native_max(struct cam_device *device, int retry_count,
2078 int error;
2079 u_int cmd, is48bit;
2082 is48bit = parm->support.command2 & ATA_SUPPORT_ADDRESS48;
2086 cmd = ATA_READ_NATIVE_MAX_ADDRESS48;
2089 cmd = ATA_READ_NATIVE_MAX_ADDRESS;
2099 /*command*/cmd,
2114 static int
2115 atahpa_set_max(struct cam_device *device, int retry_count,
2117 int is48bit, u_int64_t maxsize, int persist)
2119 int error;
2120 u_int cmd;
2126 cmd = ATA_SET_MAX_ADDRESS48;
2129 cmd = ATA_SET_MAX_ADDRESS;
2132 /* lba's are zero indexed so the max lba is requested max - 1 */
2134 maxsize--;
2143 /*command*/cmd,
2158 static int
2159 atahpa_password(struct cam_device *device, int retry_count,
2161 int is48bit, struct ata_set_max_pwd *pwd)
2163 u_int cmd;
2167 cmd = (is48bit) ? ATA_SET_MAX_ADDRESS48 : ATA_SET_MAX_ADDRESS;
2177 /*command*/cmd,
2187 static int
2188 atahpa_lock(struct cam_device *device, int retry_count,
2189 uint32_t timeout, union ccb *ccb, int is48bit)
2191 u_int cmd;
2195 cmd = (is48bit) ? ATA_SET_MAX_ADDRESS48 : ATA_SET_MAX_ADDRESS;
2204 /*command*/cmd,
2214 static int
2215 atahpa_unlock(struct cam_device *device, int retry_count,
2217 int is48bit, struct ata_set_max_pwd *pwd)
2219 u_int cmd;
2223 cmd = (is48bit) ? ATA_SET_MAX_ADDRESS48 : ATA_SET_MAX_ADDRESS;
2233 /*command*/cmd,
2243 static int
2244 atahpa_freeze_lock(struct cam_device *device, int retry_count,
2245 uint32_t timeout, union ccb *ccb, int is48bit)
2247 u_int cmd;
2251 cmd = (is48bit) ? ATA_SET_MAX_ADDRESS48 : ATA_SET_MAX_ADDRESS;
2260 /*command*/cmd,
2270 static int
2271 ata_get_native_max(struct cam_device *device, int retry_count,
2275 int error;
2299 static int
2300 ataama_set(struct cam_device *device, int retry_count,
2303 int error;
2305 /* lba's are zero indexed so the max lba is requested max - 1 */
2307 maxsize--;
2331 static int
2332 ataama_freeze(struct cam_device *device, int retry_count,
2353 int
2354 ata_do_identify(struct cam_device *device, int retry_count, int timeout,
2366 return (-1);
2373 return (-1);
2441 static int
2442 ataidentify(struct cam_device *device, int retry_count, int timeout)
2460 device->device_name, device->dev_unit_num);
2464 if (ident_buf->support.command1 & ATA_SUPPORT_PROTECTED) {
2468 if (ident_buf->support2 & ATA_SUPPORT_AMAX_ADDR) {
2473 printf("%s%d: ", device->device_name, device->dev_unit_num);
2486 static int
2487 nvmeidentify(struct cam_device *device, int retry_count __unused, int timeout __unused)
2498 static int
2499 identify(struct cam_device *device, int retry_count, int timeout)
2505 return (-1);
2553 struct ata_cmd cmd;
2555 bzero(&cmd, sizeof(cmd));
2556 cmd.command = command;
2557 printf("Issuing %s", ata_op_string(&cmd));
2560 /* pwd->password may not be null terminated */
2561 char pass[sizeof(pwd->password)+1];
2563 strlcpy(pass, pwd->password, sizeof(pass));
2566 (pwd->ctrl & ATA_SECURITY_PASSWORD_MASTER) ?
2571 (pwd->ctrl & ATA_SECURITY_LEVEL_MAXIMUM) ?
2579 static int
2581 int retry_count, uint32_t timeout, int quiet)
2604 static int
2606 int retry_count, uint32_t timeout,
2607 struct ata_security_password *pwd, int quiet)
2631 static int
2633 int retry_count, uint32_t timeout,
2634 struct ata_security_password *pwd, int quiet)
2658 static int
2664 " device:\n%s%d,%s%d: ", device->device_name,
2665 device->dev_unit_num, device->given_dev_name,
2666 device->given_unit_number);
2689 static int
2691 int retry_count, uint32_t timeout,
2693 struct ata_security_password *pwd, int quiet)
2695 int error;
2745 static int
2747 int retry_count, uint32_t timeout,
2748 struct ata_security_password *pwd, int quiet)
2779 parm->security_status);
2782 parm->security_status & ATA_SECURITY_SUPPORTED ? "yes" : "no");
2783 if (!(parm->security_status & ATA_SECURITY_SUPPORTED))
2786 parm->security_status & ATA_SECURITY_ENABLED ? "yes" : "no");
2788 parm->security_status & ATA_SECURITY_LOCKED ? "yes" : "no");
2790 parm->security_status & ATA_SECURITY_FROZEN ? "yes" : "no");
2792 parm->security_status & ATA_SECURITY_COUNT_EXP ? "yes" : "no");
2794 parm->security_status & ATA_SECURITY_LEVEL ? "maximum" : "high");
2796 parm->security_status & ATA_SECURITY_ENH_SUPP ? "yes" : "no");
2798 atasecurity_print_time(parm->erase_time);
2801 atasecurity_print_time(parm->enhanced_erase_time);
2804 parm->master_passwd_revision,
2805 parm->master_passwd_revision == 0x0000 ||
2806 parm->master_passwd_revision == 0xFFFF ? " (unsupported)" : "");
2814 static int
2815 ata_getpwd(uint8_t *passwd, int max, char opt)
2817 int len;
2821 warnx("-%c password is too long", opt);
2824 warnx("-%c password is missing", opt);
2826 } else if (optarg[0] == '-'){
2827 warnx("-%c password starts with '-' (generic arg?)", opt);
2830 warnx("-%c password conflicts with existing password from -%c",
2851 static int
2853 u_int64_t maxsize, int persist)
2858 device->device_name, device->dev_unit_num,
2859 device->given_dev_name, device->given_unit_number);
2882 static int
2883 atahpa(struct cam_device *device, int retry_count, int timeout,
2884 int argc, char **argv, char *combinedopt)
2890 int error, confirm, quiet, c, action, actions, persist;
2891 int security, is48bit, pwdsize;
2907 while ((c = getopt(argc, argv, combinedopt)) != -1) {
2980 printf("%s%d: ", device->device_name, device->dev_unit_num);
2987 if (ident_buf->support.command1 & ATA_SUPPORT_PROTECTED)
2997 if (!(ident_buf->support.command1 & ATA_SUPPORT_PROTECTED)) {
3004 if (security && !(ident_buf->support.command2 & ATA_SUPPORT_MAXSECURITY)) {
3011 is48bit = ident_buf->support.command2 & ATA_SUPPORT_ADDRESS48;
3091 static int
3092 ataama(struct cam_device *device, int retry_count, int timeout,
3093 int argc, char **argv, char *combinedopt)
3098 int error, quiet, c, action, actions;
3108 while ((c = getopt(argc, argv, combinedopt)) != -1) {
3150 printf("%s%d: ", device->device_name, device->dev_unit_num);
3157 if (ident_buf->support2 & ATA_SUPPORT_AMAX_ADDR)
3167 if (!(ident_buf->support2 & ATA_SUPPORT_AMAX_ADDR)) {
3212 static int
3213 atasecurity(struct cam_device *device, int retry_count, int timeout,
3214 int argc, char **argv, char *combinedopt)
3218 int error, confirm, quiet, c, action, actions, setpwd;
3219 int security_enabled, erase_timeout, pwdsize;
3237 while ((c = getopt(argc, argv, combinedopt)) != -1) {
3252 warnx("-U argument '%s' is invalid (must be "
3266 warnx("-l argument '%s' is unknown (must be "
3344 printf("%s%d: ", device->device_name, device->dev_unit_num);
3356 if ((ident_buf->support.command1 & ATA_SUPPORT_SECURITY) == 0) {
3366 security_enabled = ident_buf->security_status & ATA_SECURITY_ENABLED;
3381 pwd.revision = ident_buf->master_passwd_revision;
3383 --pwd.revision == 0) {
3405 if (ident_buf->security_status & ATA_SECURITY_LOCKED) {
3421 if (ident_buf->security_status & ATA_SECURITY_LOCKED) {
3447 ident_buf->erase_time);
3460 if (ident_buf->security_status & ATA_SECURITY_ENH_SUPP) {
3464 ident_buf->enhanced_erase_time);
3494 static int
3498 int fd;
3504 sizeof(ccb.cgdl.periph_name), &ccb.cgdl.unit_number) == -1) {
3514 if ((fd = open(XPT_DEVICE, O_RDWR)) == -1) {
3518 if (ioctl(fd, CAMGETPASSTHRU, &ccb) == -1) {
3532 entry ? entry->status_text : "Unknown",
3558 static int
3563 int convs = 0;
3608 static int
3609 dorescan_or_reset(int argc, char **argv, int rescan)
3613 int rv, error = 0;
3645 static int
3646 rescan_or_reset_bus(path_id_t bus, int rescan)
3649 int fd = -1, retval;
3650 int bufsize;
3669 ccb->ccb_h.func_code = rescan ? XPT_SCAN_BUS : XPT_RESET_BUS;
3670 ccb->ccb_h.path_id = bus;
3671 ccb->ccb_h.target_id = CAM_TARGET_WILDCARD;
3672 ccb->ccb_h.target_lun = CAM_LUN_WILDCARD;
3673 ccb->crcn.flags = CAM_FLAG_NONE;
3676 ccb->ccb_h.pinfo.priority = 5;
3678 if (ioctl(fd, CAMIOCOMMAND, ccb) == -1) {
3684 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3686 rescan ? "Re-scan" : "Reset", bus);
3689 rescan ? "Re-scan" : "Reset", bus,
3690 ccb->ccb_h.status & CAM_STATUS_MASK);
3703 * given bus is -1 (wildcard). We don't send a rescan or reset
3705 * no-op, sending a rescan to the xpt bus would result in a status of
3715 matchccb->ccb_h.func_code = XPT_DEV_MATCH;
3716 matchccb->ccb_h.path_id = CAM_BUS_WILDCARD;
3718 matchccb->cdm.match_buf_len = bufsize;
3719 matchccb->cdm.matches=(struct dev_match_result *)malloc(bufsize);
3720 if (matchccb->cdm.matches == NULL) {
3725 matchccb->cdm.num_matches = 0;
3727 matchccb->cdm.num_patterns = 1;
3728 matchccb->cdm.pattern_buf_len = sizeof(struct dev_match_pattern);
3730 matchccb->cdm.patterns = (struct dev_match_pattern *)malloc(
3731 matchccb->cdm.pattern_buf_len);
3732 if (matchccb->cdm.patterns == NULL) {
3737 matchccb->cdm.patterns[0].type = DEV_MATCH_BUS;
3738 matchccb->cdm.patterns[0].pattern.bus_pattern.flags = BUS_MATCH_ANY;
3741 unsigned int i;
3743 if (ioctl(fd, CAMIOCOMMAND, matchccb) == -1) {
3749 if ((matchccb->ccb_h.status != CAM_REQ_CMP)
3750 || ((matchccb->cdm.status != CAM_DEV_MATCH_LAST)
3751 && (matchccb->cdm.status != CAM_DEV_MATCH_MORE))) {
3753 matchccb->ccb_h.status, matchccb->cdm.status);
3758 for (i = 0; i < matchccb->cdm.num_matches; i++) {
3762 if (matchccb->cdm.matches[i].type != DEV_MATCH_BUS)
3765 bus_result =&matchccb->cdm.matches[i].result.bus_result;
3771 if (bus_result->path_id == CAM_XPT_PATH_ID)
3774 ccb->ccb_h.func_code = rescan ? XPT_SCAN_BUS :
3776 ccb->ccb_h.path_id = bus_result->path_id;
3777 ccb->ccb_h.target_id = CAM_TARGET_WILDCARD;
3778 ccb->ccb_h.target_lun = CAM_LUN_WILDCARD;
3779 ccb->crcn.flags = CAM_FLAG_NONE;
3782 ccb->ccb_h.pinfo.priority = 5;
3784 if (ioctl(fd, CAMIOCOMMAND, ccb) == -1) {
3790 if ((ccb->ccb_h.status & CAM_STATUS_MASK)==CAM_REQ_CMP){
3792 rescan? "Re-scan" : "Reset",
3793 bus_result->path_id);
3801 "%#x\n", rescan? "Re-scan" : "Reset",
3802 bus_result->path_id,
3803 ccb->ccb_h.status & CAM_STATUS_MASK);
3807 } while ((matchccb->ccb_h.status == CAM_REQ_CMP)
3808 && (matchccb->cdm.status == CAM_DEV_MATCH_MORE));
3812 if (fd != -1)
3816 free(matchccb->cdm.patterns);
3817 free(matchccb->cdm.matches);
3825 static int
3826 scanlun_or_reset_dev(path_id_t bus, target_id_t target, lun_id_t lun, int scan)
3830 int fd;
3849 fd = -1;
3904 scan? "Re-scan" : "Reset", bus, target, (uintmax_t)lun);
3908 scan? "Re-scan" : "Reset", bus, target, (uintmax_t)lun,
3924 static int
3925 readdefects(struct cam_device *device, int argc, char **argv,
3926 char *combinedopt, int task_attr, int retry_count, int timeout)
3940 unsigned int i;
3941 int c, error = 0;
3942 int mads = 0;
3947 while ((c = getopt(argc, argv, combinedopt)) != -1) {
3952 int entry_num = 0;
3955 warnx("%s: -f specified twice", __func__);
4030 * 12-byte command, we're always changing to the 12-byte command and
4062 CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
4064 scsi_read_defects(&ccb->csio,
4077 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
4085 valid_len = ccb->csio.dxfer_len - ccb->csio.resid;
4093 returned_length = scsi_2btoul(hdr10->length);
4094 returned_format = hdr10->format;
4105 returned_length = scsi_4btoul(hdr12->length);
4106 returned_format = hdr12->format;
4138 num_valid = min(returned_length, valid_len - hdr_size);
4144 if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
4147 int error_code, sense_key, asc, ascq;
4149 sense = &ccb->csio.sense_data;
4150 scsi_extract_sense_len(sense, ccb->csio.sense_len -
4151 ccb->csio.sense_resid, &error_code, &sense_key,
4187 * SBC-3 says that if the drive has more
4215 } else if ((ccb->ccb_h.status & CAM_STATUS_MASK) !=
4242 * We always limit the list length to the 10-byte maximum
4257 if (((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_SCSI_STATUS_ERROR)
4258 && (ccb->csio.scsi_status == SCSI_STATUS_CHECK_COND)
4259 && ((ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0)) {
4261 int error_code, sense_key, asc, ascq;
4263 sense = &ccb->csio.sense_data;
4264 scsi_extract_sense_len(sense, ccb->csio.sense_len -
4265 ccb->csio.sense_resid, &error_code, &sense_key, &asc,
4307 } else if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4357 mads ? " - " : "\n");
4363 mads ? " - " : "\n");
4393 mads ? " - " : "\n");
4399 mads ? " - " : "\n");
4475 reassignblocks(struct cam_device *device, uint32_t *blocks, int num_blocks)
4486 mode_sense(struct cam_device *device, int *cdb_len, int dbd, int llbaa, int pc,
4487 int page, int subpage, int task_attr, int retry_count, int timeout,
4488 uint8_t *data, int datalen)
4491 int error_code, sense_key, asc, ascq;
4505 CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
4507 scsi_mode_sense_subpage(&ccb->csio,
4520 if (llbaa && ccb->csio.cdb_len == 10) {
4522 (struct scsi_mode_sense_10 *)ccb->csio.cdb_io.cdb_bytes;
4523 cdb->byte2 |= SMS10_LLBAA;
4527 *cdb_len = ccb->csio.cdb_len;
4530 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
4533 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
4538 /* In case of ILLEGEL REQUEST try to fall back to 6-byte command. */
4540 ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID ||
4547 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4561 mode_select(struct cam_device *device, int cdb_len, int save_pages,
4562 int task_attr, int retry_count, int timeout, uint8_t *data, int datalen)
4565 int retval;
4572 scsi_mode_select_len(&ccb->csio,
4585 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
4588 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
4591 || ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)) {
4610 modepage(struct cam_device *device, int argc, char **argv, char *combinedopt,
4611 int task_attr, int retry_count, int timeout)
4614 int c, page = -1, subpage = 0, pc = 0, llbaa = 0;
4615 int binary = 0, cdb_len = 10, dbd = 0, desc = 0, edit = 0, list = 0;
4617 while ((c = getopt(argc, argv, combinedopt)) != -1) {
4661 if (desc && page == -1)
4664 if (page == -1 && list == 0)
4668 errx(1, "-d and -D are incompatible!");
4682 static int
4683 scsicmd(struct cam_device *device, int argc, char **argv, char *combinedopt,
4684 int task_attr, int retry_count, int timeout)
4692 int c, data_bytes = 0, valid_bytes;
4693 int cdb_len = 0;
4694 int atacmd_len = 0;
4695 int dmacmd = 0;
4696 int fpdmacmd = 0;
4697 int need_res = 0;
4699 int error = 0;
4700 int fd_data = 0, fd_res = 0;
4701 int retval;
4710 while ((c = getopt(argc, argv, combinedopt)) != -1) {
4716 hook.argc = argc - optind;
4738 hook.argc = argc - optind;
4778 hook.argc = argc - optind;
4784 * If the user supplied "-" instead of a format, he
4788 && (datastr[0] == '-'))
4814 hook.argc = argc - optind;
4826 * If the user supplied "-" instead of a format, he
4830 && (datastr[0] == '-'))
4839 hook.argc = argc - optind;
4843 if ((resstr != NULL) && (resstr[0] == '-'))
4858 int amt_to_read = data_bytes;
4863 if (amt_read == -1) {
4868 amt_to_read -= amt_read;
4881 * This is taken from the SCSI-3 draft spec.
4921 bcopy(cdb, &ccb->csio.cdb_io.cdb_bytes, cdb_len);
4923 cam_fill_csio(&ccb->csio,
4935 bcopy(atacmd, &ccb->ataio.cmd.command, atacmd_len);
4937 ccb->ataio.cmd.flags |= CAM_ATAIO_NEEDRESULT;
4939 ccb->ataio.cmd.flags |= CAM_ATAIO_DMA;
4941 ccb->ataio.cmd.flags |= CAM_ATAIO_FPDMA;
4943 cam_fill_ataio(&ccb->ataio,
4954 || ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)) {
4973 buff_decode_visit(&ccb->ataio.res.status, 11, resstr,
4979 ccb->ataio.res.status,
4980 ccb->ataio.res.error,
4981 ccb->ataio.res.lba_low,
4982 ccb->ataio.res.lba_mid,
4983 ccb->ataio.res.lba_high,
4984 ccb->ataio.res.device,
4985 ccb->ataio.res.lba_low_exp,
4986 ccb->ataio.res.lba_mid_exp,
4987 ccb->ataio.res.lba_high_exp,
4988 ccb->ataio.res.sector_count,
4989 ccb->ataio.res.sector_count_exp);
4995 valid_bytes = ccb->csio.dxfer_len - ccb->csio.resid;
4997 valid_bytes = ccb->ataio.dxfer_len - ccb->ataio.resid;
4998 if (((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP)
5007 int amt_to_write = valid_bytes;
5012 amt_to_write -= amt_written;
5015 if (amt_written == -1) {
5022 valid_bytes - amt_to_write, valid_bytes);
5037 static int
5038 camdebug(int argc, char **argv, char *combinedopt)
5040 int c, fd;
5046 int error = 0, rv;
5050 while ((c = getopt(argc, argv, combinedopt)) != -1) {
5085 argc -= optind;
5123 if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
5155 static int
5156 tagcontrol(struct cam_device *device, int argc, char **argv,
5159 int c;
5161 int numtags = -1;
5162 int retval = 0;
5163 int quiet = 0;
5173 while ((c = getopt(argc, argv, combinedopt)) != -1) {
5194 ccb->ccb_h.func_code = XPT_REL_SIMQ;
5195 ccb->ccb_h.flags = CAM_DEV_QFREEZE;
5196 ccb->crs.release_flags = RELSIM_ADJUST_OPENINGS;
5197 ccb->crs.openings = numtags;
5206 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5217 pathstr, ccb->crs.openings);
5220 CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cgds);
5222 ccb->ccb_h.func_code = XPT_GDEV_STATS;
5230 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5240 fprintf(stdout, "dev_openings %d\n", ccb->cgds.dev_openings);
5242 fprintf(stdout, "dev_active %d\n", ccb->cgds.dev_active);
5244 fprintf(stdout, "allocated %d\n", ccb->cgds.allocated);
5246 fprintf(stdout, "queued %d\n", ccb->cgds.queued);
5248 fprintf(stdout, "held %d\n", ccb->cgds.held);
5250 fprintf(stdout, "mintags %d\n", ccb->cgds.mintags);
5252 fprintf(stdout, "maxtags %d\n", ccb->cgds.maxtags);
5258 fprintf(stdout, "%d\n", ccb->cgds.dev_openings +
5259 ccb->cgds.dev_active);
5275 if (cts->transport == XPORT_SPI) {
5277 &cts->xport_specific.spi;
5279 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) != 0) {
5282 spi->sync_period);
5284 if (spi->sync_offset != 0) {
5287 freq = scsi_calc_syncsrate(spi->sync_period);
5293 if (spi->valid & CTS_SPI_VALID_SYNC_OFFSET) {
5295 spi->sync_offset);
5298 if (spi->valid & CTS_SPI_VALID_BUS_WIDTH) {
5300 (0x01 << spi->bus_width) * 8);
5303 if (spi->valid & CTS_SPI_VALID_DISC) {
5305 (spi->flags & CTS_SPI_FLAGS_DISC_ENB) ?
5309 if (cts->transport == XPORT_FC) {
5311 &cts->xport_specific.fc;
5313 if (fc->valid & CTS_FC_VALID_WWNN)
5315 (long long) fc->wwnn);
5316 if (fc->valid & CTS_FC_VALID_WWPN)
5318 (long long) fc->wwpn);
5319 if (fc->valid & CTS_FC_VALID_PORT)
5320 fprintf(stdout, "%sPortID: 0x%x\n", pathstr, fc->port);
5321 if (fc->valid & CTS_FC_VALID_SPEED)
5323 pathstr, fc->bitrate / 1000, fc->bitrate % 1000);
5325 if (cts->transport == XPORT_SAS) {
5327 &cts->xport_specific.sas;
5329 if (sas->valid & CTS_SAS_VALID_SPEED)
5331 pathstr, sas->bitrate / 1000, sas->bitrate % 1000);
5333 if (cts->transport == XPORT_ATA) {
5335 &cts->xport_specific.ata;
5337 if ((pata->valid & CTS_ATA_VALID_MODE) != 0) {
5339 ata_mode2string(pata->mode));
5341 if ((pata->valid & CTS_ATA_VALID_ATAPI) != 0) {
5343 pata->atapi);
5345 if ((pata->valid & CTS_ATA_VALID_BYTECOUNT) != 0) {
5347 pathstr, pata->bytecount);
5350 if (cts->transport == XPORT_SATA) {
5352 &cts->xport_specific.sata;
5354 if ((sata->valid & CTS_SATA_VALID_REVISION) != 0) {
5356 sata->revision);
5358 if ((sata->valid & CTS_SATA_VALID_MODE) != 0) {
5360 ata_mode2string(sata->mode));
5362 if ((sata->valid & CTS_SATA_VALID_ATAPI) != 0) {
5364 sata->atapi);
5366 if ((sata->valid & CTS_SATA_VALID_BYTECOUNT) != 0) {
5368 pathstr, sata->bytecount);
5370 if ((sata->valid & CTS_SATA_VALID_PM) != 0) {
5372 sata->pm_present);
5374 if ((sata->valid & CTS_SATA_VALID_TAGS) != 0) {
5376 sata->tags);
5378 if ((sata->valid & CTS_SATA_VALID_CAPS) != 0) {
5380 sata->caps);
5383 if (cts->transport == XPORT_NVME) {
5385 &cts->xport_specific.nvme;
5387 if (nvme->valid & CTS_NVME_VALID_LINK) {
5389 nvme->lanes, nvme->max_lanes);
5391 nvme->speed, nvme->max_speed);
5394 if (cts->transport == XPORT_NVMF) {
5396 &cts->xport_specific.nvmf;
5398 if (nvmf->valid & CTS_NVMF_VALID_TRTYPE) {
5400 nvmf_transport_type(nvmf->trtype));
5403 if (cts->protocol == PROTO_ATA) {
5405 &cts->proto_specific.ata;
5407 if (ata->valid & CTS_ATA_VALID_TQ) {
5409 (ata->flags & CTS_ATA_FLAGS_TAG_ENB) ?
5413 if (cts->protocol == PROTO_SCSI) {
5415 &cts->proto_specific.scsi;
5417 if (scsi->valid & CTS_SCSI_VALID_TQ) {
5419 (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) ?
5423 if (cts->protocol == PROTO_NVME) {
5425 &cts->proto_specific.nvme;
5427 if (nvme->valid & CTS_NVME_VALID_SPEC) {
5429 NVME_MAJOR(nvme->spec),
5430 NVME_MINOR(nvme->spec));
5438 static int
5442 int retval = 0;
5449 ccb->ccb_h.func_code = XPT_PATH_INQ;
5455 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5462 bcopy(&ccb->cpi, cpi, sizeof(struct ccb_pathinq));
5472 static int
5476 int retval = 0;
5483 ccb->ccb_h.func_code = XPT_GDEV_TYPE;
5489 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5496 bcopy(&ccb->cgd, cgd, sizeof(struct ccb_getdev));
5504 * Returns 1 if the device has the VPD page, 0 if it does not, and -1 on an
5507 int
5508 dev_has_vpd_page(struct cam_device *dev, uint8_t page_id, int retry_count,
5509 int timeout, int verbosemode)
5513 int i;
5514 int retval = 0;
5519 retval = -1;
5525 scsi_inquiry(&ccb->csio,
5537 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
5540 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
5545 retval = -1;
5549 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5553 retval = -1;
5572 * Returns 0 for success, non-zero for failure.
5574 int
5575 get_device_type(struct cam_device *dev, int retry_count, int timeout,
5576 int verbosemode, camcontrol_devtype *devtype)
5579 int retval;
5608 if (retry_count == -1) {
5610 * For a retry count of -1, used only the cached data to avoid
5616 * non-zero implies SATL.
5647 int
5653 int is48bit, camcontrol_devtype devtype)
5655 int retval = 0;
5658 cam_fill_ataio(&ccb->ataio,
5667 ata_48bit_cmd(&ccb->ataio, command, features, lba,
5670 ata_28bit_cmd(&ccb->ataio, command, features, lba,
5674 ccb->ataio.ata_flags |= ATA_FLAG_AUX;
5675 ccb->ataio.aux = auxiliary;
5679 ccb->ataio.cmd.flags |= CAM_ATAIO_NEEDRESULT;
5682 ccb->ataio.cmd.flags |= CAM_ATAIO_DMA;
5684 ccb->ataio.cmd.flags |= CAM_ATAIO_FPDMA;
5689 retval = scsi_ata_pass(&ccb->csio,
5717 * Returns: 0 -- success, 1 -- error, 2 -- lba truncated,
5718 * 4 -- count truncated, 6 -- lba and count truncated.
5720 int
5724 int retval;
5726 switch (ccb->ccb_h.func_code) {
5729 int error_code = 0, sense_key = 0, asc = 0, ascq = 0;
5733 * In this case, we have SCSI ATA PASS-THROUGH command, 12
5736 if (ccb->ccb_h.flags & CAM_CDB_POINTER)
5737 opcode = ccb->csio.cdb_io.cdb_ptr[0];
5739 opcode = ccb->csio.cdb_io.cdb_bytes[0];
5752 sense_len = ccb->csio.sense_len - ccb->csio.sense_resid;
5761 &ccb->csio.sense_data;
5772 *error = desc->error;
5773 *count = (desc->count_15_8 << 8) |
5774 desc->count_7_0;
5775 *lba = ((uint64_t)desc->lba_47_40 << 40) |
5776 ((uint64_t)desc->lba_39_32 << 32) |
5777 ((uint64_t)desc->lba_31_24 << 24) |
5778 (desc->lba_23_16 << 16) |
5779 (desc->lba_15_8 << 8) |
5780 desc->lba_7_0;
5781 *device = desc->device;
5782 *status = desc->status;
5786 * 12-byte ATA PASS-THROUGH command or a 16 or 32 byte
5788 * that the device is supposed to return 28-bit
5792 if ((desc->flags & SSD_DESC_ATA_FLAG_EXTEND) == 0){
5803 * In my understanding of SAT-5 specification, saying:
5823 scsi_get_sense_info(&ccb->csio.sense_data, sense_len,
5831 scsi_get_sense_info(&ccb->csio.sense_data, sense_len,
5853 res = &ccb->ataio.res;
5854 *error = res->error;
5855 *status = res->status;
5856 *device = res->device;
5857 *count = res->sector_count;
5858 *lba = (res->lba_high << 16) |
5859 (res->lba_mid << 8) |
5860 (res->lba_low);
5861 if (ccb->ataio.cmd.flags & CAM_ATAIO_48BIT) {
5862 *count |= (res->sector_count_exp << 8);
5863 *lba |= ((uint64_t)res->lba_low_exp << 24) |
5864 ((uint64_t)res->lba_mid_exp << 32) |
5865 ((uint64_t)res->lba_high_exp << 40);
5867 *lba |= (res->device & 0xf) << 24;
5884 "%s%d:", cpi->dev_name, cpi->unit_number);
5887 cpi->version_num);
5892 if ((i & cpi->hba_inquiry) == 0)
5932 if ((i & cpi->hba_misc) == 0)
5958 str = "do not send 6-byte commands";
5979 if ((i & cpi->target_sprt) == 0)
6010 cpi->hba_eng_cnt);
6012 cpi->max_target);
6014 cpi->max_lun);
6016 adapter_str, cpi->hpath_id);
6018 cpi->initiator_id);
6019 fprintf(stdout, "%s SIM vendor: %s\n", adapter_str, cpi->sim_vid);
6020 fprintf(stdout, "%s HBA vendor: %s\n", adapter_str, cpi->hba_vid);
6022 adapter_str, cpi->hba_vendor);
6024 adapter_str, cpi->hba_device);
6026 adapter_str, cpi->hba_subvendor);
6028 adapter_str, cpi->hba_subdevice);
6029 fprintf(stdout, "%s bus ID: %d\n", adapter_str, cpi->bus_id);
6031 if (cpi->base_transfer_speed > 1000)
6033 cpi->base_transfer_speed / 1000,
6034 cpi->base_transfer_speed % 1000);
6037 (cpi->base_transfer_speed % 1000) * 1000);
6039 adapter_str, cpi->maxio);
6042 static int
6043 get_print_cts(struct cam_device *device, int user_settings, int quiet,
6046 int retval;
6057 ccb->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
6060 ccb->cts.type = CTS_TYPE_CURRENT_SETTINGS;
6062 ccb->cts.type = CTS_TYPE_USER_SETTINGS;
6070 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
6080 cts_print(device, &ccb->cts);
6083 bcopy(&ccb->cts, cts, sizeof(struct ccb_trans_settings));
6092 static int
6093 ratecontrol(struct cam_device *device, int task_attr, int retry_count,
6094 int timeout, int argc, char **argv, char *combinedopt)
6096 int c;
6098 int user_settings = 0;
6099 int retval = 0;
6100 int disc_enable = -1, tag_enable = -1;
6101 int mode = -1;
6102 int offset = -1;
6103 double syncrate = -1;
6104 int bus_width = -1;
6105 int quiet = 0;
6106 int change_settings = 0, send_tur = 0;
6114 while ((c = getopt(argc, argv, combinedopt)) != -1) {
6128 warnx("-D argument \"%s\" is unknown", optarg);
6170 warnx("-T argument \"%s\" is unknown", optarg);
6203 retval = get_print_cts(device, user_settings, quiet, &ccb->cts);
6211 int didsettings = 0;
6218 if (ccb->cts.transport == XPORT_SPI)
6219 spi = &ccb->cts.xport_specific.spi;
6220 if (ccb->cts.transport == XPORT_ATA)
6221 pata = &ccb->cts.xport_specific.ata;
6222 if (ccb->cts.transport == XPORT_SATA)
6223 sata = &ccb->cts.xport_specific.sata;
6224 if (ccb->cts.protocol == PROTO_ATA)
6225 ata = &ccb->cts.proto_specific.ata;
6226 if (ccb->cts.protocol == PROTO_SCSI)
6227 scsi = &ccb->cts.proto_specific.scsi;
6228 ccb->cts.xport_specific.valid = 0;
6229 ccb->cts.proto_specific.valid = 0;
6230 if (spi && disc_enable != -1) {
6231 spi->valid |= CTS_SPI_VALID_DISC;
6233 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
6235 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
6238 if (tag_enable != -1) {
6246 ata->valid |= CTS_SCSI_VALID_TQ;
6248 ata->flags &= ~CTS_ATA_FLAGS_TAG_ENB;
6250 ata->flags |= CTS_ATA_FLAGS_TAG_ENB;
6253 scsi->valid |= CTS_SCSI_VALID_TQ;
6255 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
6257 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
6261 if (spi && offset != -1) {
6267 spi->valid |= CTS_SPI_VALID_SYNC_OFFSET;
6268 spi->sync_offset = offset;
6271 if (spi && syncrate != -1) {
6272 int prelim_sync_period;
6280 spi->valid |= CTS_SPI_VALID_SYNC_RATE;
6295 spi->sync_period =
6299 if (sata && syncrate != -1) {
6312 sata->revision = ata_speed2revision(syncrate * 100);
6313 if (sata->revision < 0) {
6318 sata->valid |= CTS_SATA_VALID_REVISION;
6321 if ((pata || sata) && mode != -1) {
6335 pata->mode = mode;
6336 pata->valid |= CTS_ATA_VALID_MODE;
6338 sata->mode = mode;
6339 sata->valid |= CTS_SATA_VALID_MODE;
6352 if (spi && bus_width != -1) {
6376 spi->valid |= CTS_SPI_VALID_BUS_WIDTH;
6377 spi->bus_width = bus_width >> 4;
6383 ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
6389 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
6412 (ccb->cts.transport == XPORT_ATA ||
6413 ccb->cts.transport == XPORT_SATA || send_tur)) {
6423 static int
6424 scsiformat(struct cam_device *device, int argc, char **argv,
6425 char *combinedopt, int task_attr, int retry_count, int timeout)
6428 int c;
6429 int ycount = 0, quiet = 0;
6430 int error = 0, retval = 0;
6431 int use_timeout = 10800 * 1000;
6432 int immediate = 1;
6437 int num_warnings = 0;
6438 int reportonly = 0;
6447 while ((c = getopt(argc, argv, combinedopt)) != -1) {
6503 int new_timeout = 0;
6541 scsi_format_unit(&ccb->csio,
6553 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
6556 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
6560 && ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP))) {
6577 * If we ran in non-immediate mode, we already checked for errors
6593 CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
6600 scsi_test_unit_ready(&ccb->csio,
6608 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
6622 status = ccb->ccb_h.status & CAM_STATUS_MASK;
6626 && ((ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0)) {
6628 int error_code, sense_key, asc, ascq;
6630 sense = &ccb->csio.sense_data;
6631 scsi_extract_sense_len(sense, ccb->csio.sense_len -
6632 ccb->csio.sense_resid, &error_code, &sense_key,
6636 * According to the SCSI-2 and SCSI-3 specs, a
6646 if ((scsi_get_sks(sense, ccb->csio.sense_len -
6647 ccb->csio.sense_resid, sks) == 0)
6669 scsi_sense_print(device, &ccb->csio,
6695 } while((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP);
6707 static int
6708 sanitize_wait_ata(struct cam_device *device, union ccb *ccb, int quiet,
6711 int retval;
6743 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
6744 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
6800 static int
6801 sanitize_wait_scsi(struct cam_device *device, union ccb *ccb, int task_attr, int quiet)
6803 int warnings = 0, retval;
6808 CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
6815 scsi_test_unit_ready(&ccb->csio,
6823 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
6836 status = ccb->ccb_h.status & CAM_STATUS_MASK;
6838 ((ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0)) {
6840 int error_code, sense_key, asc, ascq;
6842 sense = &ccb->csio.sense_data;
6843 scsi_extract_sense_len(sense, ccb->csio.sense_len -
6844 ccb->csio.sense_resid, &error_code, &sense_key,
6848 * According to the SCSI-3 spec, a drive that is in the
6858 if ((scsi_get_sks(sense, ccb->csio.sense_len -
6859 ccb->csio.sense_resid, sks) == 0)
6873 scsi_sense_print(device, &ccb->csio,
6896 } while ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP);
6900 static int
6901 sanitize(struct cam_device *device, int argc, char **argv,
6902 char *combinedopt, int task_attr, int retry_count, int timeout)
6906 int c;
6907 int ycount = 0, quiet = 0;
6908 int error = 0;
6909 int use_timeout;
6910 int immediate = 1;
6911 int invert = 0;
6912 int passes = 0;
6913 int ause = 0;
6914 int fd = -1;
6921 int reportonly = 0;
6927 error = get_device_type(device, -1, 0, 0, &dt);
6940 while ((c = getopt(argc, argv, combinedopt)) != -1) {
7005 warnx("overwrite action requires -P argument");
7048 pl->byte1 = 1;
7050 pl->byte1 = passes;
7052 pl->byte1 |= SSZPL_INVERT;
7053 scsi_ulto2b(sz, pl->length);
7058 arg = "-c";
7060 arg = "-I";
7062 arg = "-P";
7085 printf("%s%d: ", device->device_name,
7086 device->dev_unit_num);
7123 int new_timeout = 0;
7147 scsi_sanitize(&ccb->csio,
7158 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
7160 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
7213 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
7215 int error_code, sense_key, asc, ascq;
7217 if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
7219 sense = &ccb->csio.sense_data;
7220 scsi_extract_sense_len(sense, ccb->csio.sense_len -
7221 ccb->csio.sense_resid, &error_code, &sense_key,
7242 * If we ran in non-immediate mode, we already checked for errors
7274 static int
7275 scsireportluns(struct cam_device *device, int argc, char **argv,
7276 char *combinedopt, int task_attr, int retry_count, int timeout)
7279 int c, countonly, lunsonly;
7281 int alloc_len;
7284 int retval;
7299 while ((c = getopt(argc, argv, combinedopt)) != -1) {
7328 warnx("%s: you can only specify one of -c or -l", __func__);
7333 * According to SPC-4, the allocation length must be at least 16
7334 * bytes -- enough for the header and one LUN.
7348 scsi_report_luns(&ccb->csio,
7359 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
7362 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
7370 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
7377 list_len = scsi_4btoul(lundata->length);
7384 && (list_len > (alloc_len - sizeof(*lundata)))) {
7398 int no_more;
7401 for (j = 0; j < sizeof(lundata->luns[i].lundata); j += 2) {
7404 switch (lundata->luns[i].lundata[j] &
7407 if ((lundata->luns[i].lundata[j] &
7410 lundata->luns[i].lundata[j] &
7413 && ((lundata->luns[i].lundata[j+2] &
7418 lundata->luns[i].lundata[j+1]);
7422 tmplun[0] = lundata->luns[i].lundata[j] &
7424 tmplun[1] = lundata->luns[i].lundata[j+1];
7432 (lundata->luns[i].lundata[j+1] &
7434 lundata->luns[i].lundata[j] &
7436 lundata->luns[i].lundata[j+1] &
7440 int field_len_code, eam_code;
7442 eam_code = lundata->luns[i].lundata[j] &
7444 field_len_code = (lundata->luns[i].lundata[j] &
7450 lundata->luns[i].lundata[j+1]);
7470 bcopy(&lundata->luns[i].lundata[j+1],
7471 &tmp_lun[1], sizeof(tmp_lun) - 1);
7486 "%#x\n", lundata->luns[i].lundata[0] &
7509 static int
7510 scsireadcapacity(struct cam_device *device, int argc, char **argv,
7511 char *combinedopt, int task_attr, int retry_count, int timeout)
7514 int blocksizeonly, humanize, numblocks, quiet, sizeonly, baseten, longonly;
7519 int retval;
7520 int c;
7538 while ((c = getopt(argc, argv, combinedopt)) != -1) {
7570 warnx("%s: you can only specify one of -b or -N", __func__);
7577 warnx("%s: you can only specify one of -b or -s", __func__);
7584 warnx("%s: you can only specify one of -h/-H or -q", __func__);
7591 warnx("%s: you can only specify one of -h/-H or -b", __func__);
7599 scsi_read_capacity(&ccb->csio,
7608 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
7611 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
7619 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
7629 * A last block of 2^32-1 means that the true capacity is over 2TB,
7637 scsi_read_capacity_16(&ccb->csio,
7650 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
7653 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
7661 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
7678 int ret;
7686 if (ret == -1) {
7713 static int
7714 smpcmd(struct cam_device *device, int argc, char **argv, char *combinedopt,
7715 int retry_count, int timeout)
7717 int c, error = 0;
7720 int request_size = 0, response_size = 0;
7721 int fd_request = 0, fd_response = 0;
7724 int retval;
7725 int flags = 0;
7737 while ((c = getopt(argc, argv, combinedopt)) != -1) {
7748 hook.argc = argc - optind;
7754 * If the user supplied "-" instead of a format, he
7758 && (datastr[0] == '-'))
7777 hook.argc = argc - optind;
7789 * If the user supplied "-" instead of a format, he
7793 && (datastr[0] == '-'))
7812 int amt_to_read = request_size;
7817 if (amt_read == -1) {
7822 amt_to_read -= amt_read;
7829 warnx("%s: need both the request (-r) and response (-R) "
7837 cam_fill_smpio(&ccb->smpio,
7847 ccb->smpio.flags = SMP_FLAG_NONE;
7850 || ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)) {
7864 if (((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP)
7872 int amt_to_write = response_size;
7878 amt_to_write -= amt_written;
7881 if (amt_written == -1) {
7888 response_size - amt_to_write,
7906 static int
7907 mmcsdcmd(struct cam_device *device, int argc, char **argv, char *combinedopt,
7908 int retry_count, int timeout)
7910 int c, error = 0;
7913 int32_t mmc_flags = -1;
7914 int retval;
7915 int is_write = 0;
7916 int is_bw_4 = 0, is_bw_1 = 0;
7917 int is_frequency = 0;
7918 int is_highspeed = 0, is_stdspeed = 0;
7919 int is_info_request = 0;
7920 int flags = 0;
7927 int mmc_data_len = 0;
7939 bzero(&(&ccb->ccb_h)[1],
7940 sizeof(union ccb) - sizeof(struct ccb_hdr));
7942 while ((c = getopt(argc, argv, combinedopt)) != -1) {
8036 int len_arg = mmc_data_len;
8053 ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
8054 ccb->ccb_h.flags = 0;
8055 cts = &ccb->cts.proto_specific.mmc;
8056 cts->ios.bus_width = is_bw_4 == 1 ? bus_width_4 : bus_width_1;
8057 cts->ios_valid = MMC_BW;
8059 || ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)) {
8070 ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
8071 ccb->ccb_h.flags = 0;
8072 cts = &ccb->cts.proto_specific.mmc;
8073 cts->ios.clock = mmc_frequency;
8074 cts->ios_valid = MMC_CLK;
8076 || ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)) {
8088 ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
8089 ccb->ccb_h.flags = 0;
8090 cts = &ccb->cts.proto_specific.mmc;
8091 cts->ios.timing = is_highspeed == 1 ? bus_timing_hs : bus_timing_normal;
8092 cts->ios_valid = MMC_BT;
8094 || ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)) {
8105 ccb->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
8106 ccb->ccb_h.flags = 0;
8108 cts = &ccb->cts.proto_specific.mmc;
8110 || ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)) {
8115 printf("Host OCR: 0x%x\n", cts->host_ocr);
8116 printf("Min frequency: %u KHz\n", cts->host_f_min / 1000);
8117 printf("Max frequency: %u MHz\n", cts->host_f_max / 1000000);
8119 if (cts->host_caps & MMC_CAP_4_BIT_DATA)
8121 if (cts->host_caps & MMC_CAP_8_BIT_DATA)
8125 if (cts->host_caps & MMC_CAP_HSPEED)
8127 if (cts->host_caps & MMC_CAP_UHS_SDR12)
8129 if (cts->host_caps & MMC_CAP_UHS_SDR25)
8131 if (cts->host_caps & MMC_CAP_UHS_SDR50)
8133 if (cts->host_caps & MMC_CAP_UHS_SDR104)
8135 if (cts->host_caps & MMC_CAP_UHS_DDR50)
8137 if (cts->host_caps & MMC_CAP_MMC_DDR52_120)
8139 if (cts->host_caps & MMC_CAP_MMC_DDR52_180)
8141 if (cts->host_caps & MMC_CAP_MMC_HS200_120)
8143 if (cts->host_caps & MMC_CAP_MMC_HS200_180)
8145 if (cts->host_caps & MMC_CAP_MMC_HS400_120)
8146 printf(" Can do eMMC HS400 at 1.2V\n");
8147 if (cts->host_caps & MMC_CAP_MMC_HS400_180)
8148 printf(" Can do eMMC HS400 at 1.8V\n");
8151 if (cts->host_caps & MMC_CAP_SIGNALING_120)
8153 if (cts->host_caps & MMC_CAP_SIGNALING_180)
8155 if (cts->host_caps & MMC_CAP_SIGNALING_330)
8160 switch (cts->ios.bus_width) {
8172 cts->ios.clock / 1000000,
8173 (cts->ios.clock / 1000) % 1000,
8174 cts->ios.timing == bus_timing_hs ? " (high-speed timing)" : "");
8177 switch (cts->ios.vccq) {
8191 printf("CMD %d arg %d flags %02x\n", mmc_opcode, mmc_arg, mmc_flags);
8203 cam_fill_mmcio(&ccb->mmcio,
8214 || ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)) {
8228 if (((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP)) {
8230 ccb->mmcio.cmd.error, ccb->mmcio.cmd.resp[0],
8231 ccb->mmcio.cmd.resp[1],
8232 ccb->mmcio.cmd.resp[2],
8233 ccb->mmcio.cmd.resp[3]);
8238 SD_R5_DATA(ccb->mmcio.cmd.resp),
8239 (ccb->mmcio.cmd.resp[0] >> 12) & 0x3);
8246 printf("SEND_RELATIVE_ADDR: published RCA %02x\n", ccb->mmcio.cmd.resp[0] >> 16);
8249 printf("No command-specific decoder for CMD %d\n", mmc_opcode);
8264 static int
8265 smpreportgeneral(struct cam_device *device, int argc, char **argv,
8266 char *combinedopt, int retry_count, int timeout)
8272 int error = 0;
8273 int c, long_response = 0;
8274 int retval;
8286 while ((c = getopt(argc, argv, combinedopt)) != -1) {
8312 smp_report_general(&ccb->smpio,
8323 || ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)) {
8343 if ((response->long_response & SMP_RG_LONG_RESPONSE)
8345 ccb->ccb_h.status = CAM_REQ_INPROG;
8346 CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->smpio);
8398 static int
8399 smpphycontrol(struct cam_device *device, int argc, char **argv,
8400 char *combinedopt, int retry_count, int timeout)
8405 int long_response = 0;
8406 int retval = 0;
8407 int phy = -1;
8409 int phy_op_set = 0;
8411 int dev_name_set = 0;
8414 int slumber_partial = 0;
8415 int set_pp_timeout_val = 0;
8416 int c;
8428 while ((c = getopt(argc, argv, combinedopt)) != -1) {
8434 int enable = -1;
8514 "(-o) allowed", __func__);
8524 * future-proof it a bit, so options that are added
8575 if (phy == -1) {
8576 warnx("%s: a PHY (-p phy) argument is required",__func__);
8585 warnx("%s: -d name and -o setdevname arguments both "
8607 smp_phy_control(&ccb->smpio,
8627 || ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)) {
8661 static int
8662 smpmaninfo(struct cam_device *device, int argc, char **argv,
8663 char *combinedopt, int retry_count, int timeout)
8669 int long_response = 0;
8670 int retval = 0;
8671 int c;
8683 while ((c = getopt(argc, argv, combinedopt)) != -1) {
8695 smp_report_manuf_info(&ccb->smpio,
8706 || ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)) {
8748 static int
8751 int retval = 0;
8756 dev = cam_open_btl(item->dev_match.path_id,
8757 item->dev_match.target_id,
8758 item->dev_match.target_lun, O_RDWR, NULL);
8766 item->device_id_len = 0;
8780 ccb->ccb_h.func_code = XPT_DEV_ADVINFO;
8781 ccb->ccb_h.flags = CAM_DIR_IN;
8782 ccb->cdai.flags = CDAI_FLAG_NONE;
8783 ccb->cdai.buftype = CDAI_TYPE_SCSI_DEVID;
8784 ccb->cdai.bufsiz = item->device_id_len;
8785 if (item->device_id_len != 0)
8786 ccb->cdai.buf = (uint8_t *)item->device_id;
8794 if (ccb->ccb_h.status != CAM_REQ_CMP) {
8795 warnx("%s: CAM status %#x", __func__, ccb->ccb_h.status);
8800 if (item->device_id_len == 0) {
8805 if (ccb->cdai.provsiz == 0) {
8811 item->device_id_len = ccb->cdai.provsiz;
8812 item->device_id = malloc(item->device_id_len);
8813 if (item->device_id == NULL) {
8815 item->device_id_len);
8819 ccb->ccb_h.status = CAM_REQ_INPROG;
8836 static int
8840 int bufsize, fd = -1;
8843 int skip_device = 0;
8844 int retval = 0;
8846 if ((fd = open(XPT_DEVICE, O_RDWR)) == -1) {
8883 patterns[0].pattern.device_pattern.path_id = devlist->path_id;
8886 patterns[1].pattern.periph_pattern.path_id = devlist->path_id;
8893 unsigned int i;
8895 if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
8918 if (dev_result->flags &
8933 bcopy(dev_result, &item->dev_match,
8935 STAILQ_INSERT_TAIL(&devlist->dev_queue, item,
8952 item->num_periphs++;
8953 item->periph_matches = realloc(
8954 item->periph_matches,
8955 item->num_periphs *
8957 if (item->periph_matches == NULL) {
8963 bcopy(periph_result, &item->periph_matches[
8964 item->num_periphs - 1],
8981 if (fd != -1)
8999 STAILQ_FOREACH_SAFE(item, &devlist->dev_queue, links, item2) {
9000 STAILQ_REMOVE(&devlist->dev_queue, item, cam_devitem,
9002 free(item->device_id);
9003 free(item->periph_matches);
9013 STAILQ_FOREACH(item, &devlist->dev_queue, links) {
9019 idd = scsi_get_devid(item->device_id,
9020 item->device_id_len,
9025 if (scsi_8btou64(idd->identifier) == sasaddr)
9032 static int
9033 smpphylist(struct cam_device *device, int argc, char **argv,
9034 char *combinedopt, int retry_count, int timeout)
9042 int long_response = 0;
9043 int num_phys = 0;
9044 int quiet = 0;
9045 int retval;
9046 int i, c;
9076 while ((c = getopt(argc, argv, combinedopt)) != -1) {
9089 smp_report_general(&ccb->smpio,
9099 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
9102 || ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)) {
9118 num_phys = rgresponse->num_phys;
9127 devlist.path_id = device->path_id;
9159 int j;
9161 CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->smpio);
9163 ccb->ccb_h.status = CAM_REQ_INPROG;
9164 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
9166 smp_discover(&ccb->smpio,
9179 || (((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
9180 && (disresponse->function_result != SMP_FR_PHY_VACANT))) {
9196 if (disresponse->function_result == SMP_FR_PHY_VACANT) {
9202 if (disresponse->attached_device == SMP_DIS_AD_TYPE_NONE) {
9206 scsi_8btou64(disresponse->attached_sas_address));
9213 disresponse->attached_sas_address));
9221 dev_match = &item->dev_match;
9223 if (dev_match->protocol == PROTO_SCSI) {
9224 cam_strvis(vendor, dev_match->inq_data.vendor,
9225 sizeof(dev_match->inq_data.vendor),
9227 cam_strvis(product, dev_match->inq_data.product,
9228 sizeof(dev_match->inq_data.product),
9230 cam_strvis(revision, dev_match->inq_data.revision,
9231 sizeof(dev_match->inq_data.revision),
9235 } else if ((dev_match->protocol == PROTO_ATA)
9236 || (dev_match->protocol == PROTO_SATAPM)) {
9237 cam_strvis(product, dev_match->ident_data.model,
9238 sizeof(dev_match->ident_data.model),
9240 cam_strvis(revision, dev_match->ident_data.revision,
9241 sizeof(dev_match->ident_data.revision),
9247 fprintf(stdout, " %-33s ", tmpstr);
9252 if (item->num_periphs == 0) {
9258 for (j = 0; j < item->num_periphs; j++) {
9263 item->periph_matches[j].periph_name,
9264 item->periph_matches[j].unit_number);
9286 static int
9292 int retval;
9311 printf("%s%d: ", device->device_name, device->dev_unit_num);
9319 case 0x40: /* obsolete since ACS-3 */
9322 case 0x41: /* obsolete since ACS-3 */
9348 static int
9349 atapm(struct cam_device *device, int argc, char **argv,
9350 char *combinedopt, int retry_count, int timeout)
9353 int retval = 0;
9354 int t = -1;
9355 int c;
9357 u_char cmd, sc;
9366 while ((c = getopt(argc, argv, combinedopt)) != -1) {
9376 if (t == -1)
9377 cmd = ATA_IDLE_IMMEDIATE;
9379 cmd = ATA_IDLE_CMD;
9381 if (t == -1)
9382 cmd = ATA_STANDBY_IMMEDIATE;
9384 cmd = ATA_STANDBY_CMD;
9386 cmd = ATA_CHECK_POWER_MODE;
9388 t = -1;
9390 cmd = ATA_SLEEP;
9391 t = -1;
9402 sc = (t - 1) / (30 * 60) + 241;
9413 /*command*/cmd,
9422 if (retval == 0 && cmd == ATA_CHECK_POWER_MODE)
9429 static int
9430 ataaxm(struct cam_device *device, int argc, char **argv,
9431 char *combinedopt, int retry_count, int timeout)
9434 int retval = 0;
9435 int l = -1;
9436 int c;
9437 u_char cmd, sc;
9446 while ((c = getopt(argc, argv, combinedopt)) != -1) {
9457 if (l == -1)
9458 cmd = 0x85;
9460 cmd = 0x05;
9464 if (l == -1)
9465 cmd = 0xC2;
9467 cmd = 0x42;
9480 /*features*/cmd,
9492 int
9493 scsigetopcodes(struct cam_device *device, int opcode_set, int opcode,
9494 int show_sa_errors, int sa_set, int service_action,
9495 int timeout_desc, int task_attr, int retry_count, int timeout,
9496 int verbosemode, uint32_t *fill_len, uint8_t **data_ptr)
9505 int options = 0;
9506 int retval = 0;
9557 scsi_report_supported_opcodes(&ccb->csio,
9569 ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
9572 ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
9580 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
9588 valid_len = ccb->csio.dxfer_len - ccb->csio.resid;
9593 avail_len = scsi_4btoul(all_hdr->length) + sizeof(*all_hdr);
9599 cdb_length = scsi_2btoul(one->cdb_length);
9601 if (one->support & RSO_ONE_CTDP) {
9606 if (valid_len >= (avail_len + sizeof(td->length))) {
9607 avail_len += scsi_2btoul(td->length) +
9608 sizeof(td->length);
9636 static int
9637 scsiprintoneopcode(struct cam_device *device, int req_opcode, int sa_set,
9638 int req_sa, uint8_t *buf, uint32_t valid_len)
9644 unsigned int i;
9645 int retval = 0;
9661 op_desc = scsi_op_desc(req_opcode, &device->inq_data);
9669 switch (one->support & RSO_ONE_SUP_MASK) {
9682 printf("Command is supported, vendor-specific "
9687 one->support & RSO_ONE_SUP_MASK);
9699 cdb_len = scsi_2btoul(one->cdb_length);
9722 printf(" %02x", one->cdb_usage[i]);
9729 if ((one->support & RSO_ONE_CTDP) == 0)
9736 if (valid_len < (sizeof(*one) + cdb_len + sizeof(td->length)))
9741 td_len = scsi_2btoul(td->length);
9742 td_len += sizeof(td->length);
9758 printf("Command-specific: 0x%02x\n", td->cmd_specific);
9760 scsi_4btoul(td->nominal_time));
9762 scsi_4btoul(td->recommended_time));
9768 static int
9769 scsiprintopcodes(struct cam_device *device, int td_req, uint8_t *buf,
9776 int retval = 0;
9785 avail_len = scsi_4btoul(hdr->length);
9786 avail_len += sizeof(hdr->length);
9793 used_len = sizeof(hdr->length);
9795 printf("%-6s %4s %8s ",
9802 while ((avail_len - used_len) > sizeof(*desc)) {
9810 op_desc = scsi_op_desc(desc->opcode, &device->inq_data);
9814 printf("0x%02x %#4x %8u ", desc->opcode,
9815 scsi_2btoul(desc->service_action),
9816 scsi_2btoul(desc->cdb_length));
9820 if ((desc->flags & RSO_CTDP) == 0) {
9829 if (avail_len - used_len < sizeof(*td)) {
9836 td_len = scsi_2btoul(td->length);
9837 td_len += sizeof(td->length);
9849 printf(" 0x%02x %6u %6u %s\n", td->cmd_specific,
9850 scsi_4btoul(td->nominal_time),
9851 scsi_4btoul(td->recommended_time), op_desc);
9857 static int
9858 scsiopcodes(struct cam_device *device, int argc, char **argv,
9859 char *combinedopt, int task_attr, int retry_count, int timeout,
9860 int verbosemode)
9862 int c;
9864 int td_set = 0, opcode_set = 0, sa_set = 0;
9865 int show_sa_errors = 1;
9869 int retval = 0;
9871 while ((c = getopt(argc, argv, combinedopt)) != -1) {
9918 warnx("You must specify an opcode with -o if a service "
9945 static int
9949 int retval = 0;
9958 ccb->ccb_h.func_code = XPT_REPROBE_LUN;
9966 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
9979 usage(int printlong)
9984 " camcontrol devlist [-b] [-v]\n"
9985 " camcontrol periphlist [dev_id][-n dev_name] [-u unit]\n"
9987 " camcontrol sense [dev_id][generic args][-D][-x]\n"
9988 " camcontrol inquiry [dev_id][generic args] [-D] [-S] [-R]\n"
9989 " camcontrol identify [dev_id][generic args] [-v]\n"
9990 " camcontrol reportluns [dev_id][generic args] [-c] [-l] [-r report]\n"
9991 " camcontrol readcap [dev_id][generic args] [-b] [-h] [-H] [-N]\n"
9992 " [-q] [-s] [-l]\n"
10000 " camcontrol defects [dev_id][generic args] <-f format> [-P][-G]\n"
10001 " [-q][-s][-S offset][-X]\n"
10002 " camcontrol modepage [dev_id][generic args] <-m page | -l>\n"
10003 " [-P pagectl][-e | -b][-d]\n"
10004 " camcontrol cmd [dev_id][generic args]\n"
10005 " <-a cmd [args] | -c cmd [args]>\n"
10006 " [-d] [-f] [-i len fmt|-o len fmt [args]] [-r fmt]\n"
10008 " <-r len fmt [args]> <-R len fmt [args]>\n"
10009 " camcontrol smprg [dev_id][generic args][-l]\n"
10010 " camcontrol smppc [dev_id][generic args] <-p phy> [-l]\n"
10011 " [-o operation][-d name][-m rate][-M rate]\n"
10012 " [-T pp_timeout][-a enable|disable]\n"
10013 " [-A enable|disable][-s enable|disable]\n"
10014 " [-S enable|disable]\n"
10015 " camcontrol smpphylist [dev_id][generic args][-l][-q]\n"
10016 " camcontrol smpmaninfo [dev_id][generic args][-l]\n"
10017 " camcontrol debug [-I][-P][-T][-S][-X][-c]\n"
10019 " camcontrol tags [dev_id][generic args] [-N tags] [-q] [-v]\n"
10020 " camcontrol negotiate [dev_id][generic args] [-a][-c]\n"
10021 " [-D <enable|disable>][-M mode][-O offset]\n"
10022 " [-q][-R syncrate][-v][-T <enable|disable>]\n"
10023 " [-U][-W bus_width]\n"
10024 " camcontrol format [dev_id][generic args][-q][-r][-w][-y]\n"
10026 " [-a overwrite|block|crypto|exitfailure]\n"
10027 " [-c passes][-I][-P pattern][-q][-U][-r][-w]\n"
10028 " [-y]\n"
10029 " camcontrol idle [dev_id][generic args][-t time]\n"
10030 " camcontrol standby [dev_id][generic args][-t time]\n"
10033 " camcontrol apm [dev_id][generic args][-l level]\n"
10034 " camcontrol aam [dev_id][generic args][-l level]\n"
10035 " camcontrol fwdownload [dev_id][generic args] <-f fw_image> [-q]\n"
10036 " [-s][-y]\n"
10038 " <-d pwd | -e pwd | -f | -h pwd | -k pwd>\n"
10039 " [-l <high|maximum>] [-q] [-s pwd] [-T timeout]\n"
10040 " [-U <user|master>] [-y]\n"
10041 " camcontrol hpa [dev_id][generic args] [-f] [-l] [-P] [-p pwd]\n"
10042 " [-q] [-s max_sectors] [-U pwd] [-y]\n"
10043 " camcontrol ama [dev_id][generic args] [-f] [-q] [-s max_sectors]\n"
10044 " camcontrol persist [dev_id][generic args] <-i action|-o action>\n"
10045 " [-a][-I tid][-k key][-K sa_key][-p][-R rtp]\n"
10046 " [-s scope][-S][-T type][-U]\n"
10047 " camcontrol attrib [dev_id][generic args] <-r action|-w attr>\n"
10048 " [-a attr_num][-c][-e elem][-F form1,form1]\n"
10049 " [-p part][-s start][-T type][-V vol]\n"
10050 " camcontrol opcodes [dev_id][generic args][-o opcode][-s SA]\n"
10051 " [-N][-T]\n"
10052 " camcontrol zone [dev_id][generic args]<-c cmd> [-a] [-l LBA]\n"
10053 " [-o rep_opts] [-P print_opts]\n"
10054 " camcontrol epc [dev_id][generic_args]<-c cmd> [-d] [-D] [-e]\n"
10055 " [-H] [-p power_cond] [-P] [-r rst_src] [-s]\n"
10056 " [-S power_src] [-T timer]\n"
10057 " camcontrol timestamp [dev_id][generic_args] <-r [-f format|-m|-U]>|\n"
10058 " <-s <-f format -T time | -U >>\n"
10060 " camcontrol depop [dev_id] [-d | -l | -r] [-e element] [-c capacity]\n"
10061 " camcontrol mmcsdcmd [dev_id] [[-c mmc_opcode] [-a mmc_arg]\n"
10062 " [-f mmc_flags] [-l data_len]\n"
10063 " [-W [-b data_byte]]] |\n"
10064 " [-F frequency] |\n"
10065 " [-I]\n"
10066 " [-1 | -4]\n"
10067 " [-S high|normal]\n"
10090 "modepage display or edit (-e) the given mode page\n"
10091 "cmd send the given SCSI command, may need -i or -o as well\n"
10092 "smpcmd send the given SMP command, requires -o and -i\n"
10094 "smppc send the SMP PHY Control command, requires -p\n"
10116 "mmcsdcmd send the given MMC command, needs -c and -a as well\n"
10123 "-v be verbose, print out sense information\n"
10124 "-t timeout command timeout in seconds, overrides default timeout\n"
10125 "-n dev_name specify device name, e.g. \"da\", \"cd\"\n"
10126 "-u unit specify unit number, e.g. \"0\", \"5\"\n"
10127 "-E have the kernel attempt to perform SCSI error recovery\n"
10128 "-C count specify the SCSI command retry count (needs -E to work)\n"
10129 "-Q task_attr specify ordered, simple or head tag type for SCSI cmds\n"
10131 "-l list all available mode pages\n"
10132 "-m page specify the mode page to view or edit\n"
10133 "-e edit the specified mode page\n"
10134 "-b force view to binary mode\n"
10135 "-d disable block descriptors for mode sense\n"
10136 "-P pgctl page control field 0-3\n"
10138 "-f format specify defect list format (block, bfi or phys)\n"
10139 "-G get the grown defect list\n"
10140 "-P get the permanent defect list\n"
10142 "-D request descriptor sense data\n"
10143 "-x do a hexdump of the sense data\n"
10145 "-D get the standard inquiry data\n"
10146 "-S get the serial number\n"
10147 "-R get the transfer rate, etc.\n"
10149 "-c only report a count of available LUNs\n"
10150 "-l only print out luns, and not a count\n"
10151 "-r <reporttype> specify \"default\", \"wellknown\" or \"all\"\n"
10153 "-b only report the blocksize\n"
10154 "-h human readable device size, base 2\n"
10155 "-H human readable device size, base 10\n"
10156 "-N print the number of blocks instead of last block\n"
10157 "-q quiet, print numbers only\n"
10158 "-s only report the last block/device size\n"
10159 "cmd arguments:\n"
10160 "-c cdb [args] specify the SCSI CDB\n"
10161 "-i len fmt specify input data and input data format\n"
10162 "-o len fmt [args] specify output data and output data fmt\n"
10164 "-r len fmt [args] specify the SMP command to be sent\n"
10165 "-R len fmt [args] specify SMP response format\n"
10167 "-l specify the long response format\n"
10169 "-p phy specify the PHY to operate on\n"
10170 "-l specify the long request/response format\n"
10171 "-o operation specify the phy control operation\n"
10172 "-d name set the attached device name\n"
10173 "-m rate set the minimum physical link rate\n"
10174 "-M rate set the maximum physical link rate\n"
10175 "-T pp_timeout set the partial pathway timeout value\n"
10176 "-a enable|disable enable or disable SATA slumber\n"
10177 "-A enable|disable enable or disable SATA partial phy power\n"
10178 "-s enable|disable enable or disable SAS slumber\n"
10179 "-S enable|disable enable or disable SAS partial phy power\n"
10181 "-l specify the long response format\n"
10182 "-q only print phys with attached devices\n"
10184 "-l specify the long response format\n"
10186 "-I CAM_DEBUG_INFO -- scsi commands, errors, data\n"
10187 "-T CAM_DEBUG_TRACE -- routine flow tracking\n"
10188 "-S CAM_DEBUG_SUBTRACE -- internal routine command flow\n"
10189 "-c CAM_DEBUG_CDB -- print out SCSI CDBs only\n"
10191 "-N tags specify the number of tags to use for this device\n"
10192 "-q be quiet, don't report the number of tags\n"
10193 "-v report a number of tag-related parameters\n"
10195 "-a send a test unit ready after negotiation\n"
10196 "-c report/set current negotiation settings\n"
10197 "-D <arg> \"enable\" or \"disable\" disconnection\n"
10198 "-M mode set ATA mode\n"
10199 "-O offset set command delay offset\n"
10200 "-q be quiet, don't report anything\n"
10201 "-R syncrate synchronization rate in MHz\n"
10202 "-T <arg> \"enable\" or \"disable\" tagged queueing\n"
10203 "-U report/set user negotiation settings\n"
10204 "-W bus_width set the bus width in bits (8, 16 or 32)\n"
10205 "-v also print a Path Inquiry CCB for the controller\n"
10207 "-q be quiet, don't print status messages\n"
10208 "-r run in report only mode\n"
10209 "-w don't send immediate format command\n"
10210 "-y don't ask any questions\n"
10212 "-a operation operation mode: overwrite, block, crypto or exitfailure\n"
10213 "-c passes overwrite passes to perform (1 to 31)\n"
10214 "-I invert overwrite pattern after each pass\n"
10215 "-P pattern path to overwrite pattern file\n"
10216 "-q be quiet, don't print status messages\n"
10217 "-r run in report only mode\n"
10218 "-U run operation in unrestricted completion exit mode\n"
10219 "-w don't send immediate sanitize command\n"
10220 "-y don't ask any questions\n"
10222 "-t <arg> number of seconds before respective state.\n"
10224 "-f fw_image path to firmware image file\n"
10225 "-q don't print informational messages, only errors\n"
10226 "-s run in simulation mode\n"
10227 "-v print info for every firmware segment sent to device\n"
10228 "-y don't ask any questions\n"
10230 "-d pwd disable security using the given password for the selected\n"
10232 "-e pwd erase the device using the given pwd for the selected user\n"
10233 "-f freeze the security configuration of the specified device\n"
10234 "-h pwd enhanced erase the device using the given pwd for the\n"
10236 "-k pwd unlock the device using the given pwd for the selected\n"
10238 "-l <high|maximum> specifies which security level to set: high or maximum\n"
10239 "-q be quiet, do not print any status messages\n"
10240 "-s pwd password the device (enable security) using the given\n"
10242 "-T timeout overrides the timeout (seconds) used for erase operation\n"
10243 "-U <user|master> specifies which user to set: user or master\n"
10244 "-y don't ask any questions\n"
10246 "-f freeze the HPA configuration of the device\n"
10247 "-l lock the HPA configuration of the device\n"
10248 "-P make the HPA max sectors persist\n"
10249 "-p pwd Set the HPA configuration password required for unlock\n"
10251 "-q be quiet, do not print any status messages\n"
10252 "-s sectors configures the maximum user accessible sectors of the\n"
10254 "-U pwd unlock the HPA configuration of the device\n"
10255 "-y don't ask any questions\n"
10257 "-f freeze the AMA configuration of the device\n"
10258 "-q be quiet, do not print any status messages\n"
10259 "-s sectors configures the maximum user accessible sectors of the\n"
10262 "-i action specify read_keys, read_reservation, report_cap, or\n"
10264 "-o action specify register, register_ignore, reserve, release,\n"
10266 "-a set the All Target Ports (ALL_TG_PT) bit\n"
10267 "-I tid specify a Transport ID, e.g.: sas,0x1234567812345678\n"
10268 "-k key specify the Reservation Key\n"
10269 "-K sa_key specify the Service Action Reservation Key\n"
10270 "-p set the Activate Persist Through Power Loss bit\n"
10271 "-R rtp specify the Relative Target Port\n"
10272 "-s scope specify the scope: lun, extent, element or a number\n"
10273 "-S specify Transport ID for register, requires -I\n"
10274 "-T res_type specify the reservation type: read_shared, wr_ex, rd_ex,\n"
10276 "-U unregister the current initiator for register_move\n"
10278 "-r action specify attr_values, attr_list, lv_list, part_list, or\n"
10280 "-w attr specify an attribute to write, one -w argument per attr\n"
10281 "-a attr_num only display this attribute number\n"
10282 "-c get cached attributes\n"
10283 "-e elem_addr request attributes for the given element in a changer\n"
10284 "-F form1,form2 output format, comma separated list: text_esc, text_raw,\n"
10287 "-p partition request attributes for the given partition\n"
10288 "-s start_attr request attributes starting at the given number\n"
10289 "-T elem_type specify the element type (used with -e)\n"
10290 "-V logical_vol specify the logical volume ID\n"
10292 "-o opcode specify the individual opcode to list\n"
10293 "-s service_action specify the service action for the opcode\n"
10294 "-N do not return SCSI error for unsupported SA\n"
10295 "-T request nominal and recommended timeout values\n"
10297 "-c cmd required: rz, open, close, finish, or rwp\n"
10298 "-a apply the action to all zones\n"
10299 "-l LBA specify the zone starting LBA\n"
10300 "-o rep_opts report zones options: all, empty, imp_open, exp_open,\n"
10302 "-P print_opt report zones printing: normal, summary, script\n"
10304 "-c cmd required: restore, goto, timer, state, enable, disable,\n"
10306 "-d disable power mode (timer, state)\n"
10307 "-D delayed entry (goto)\n"
10308 "-e enable power mode (timer, state)\n"
10309 "-H hold power mode (goto)\n"
10310 "-p power_cond Idle_a, Idle_b, Idle_c, Standby_y, Standby_z (timer,\n"
10312 "-P only display power mode (status)\n"
10313 "-r rst_src restore settings from: default, saved (restore)\n"
10314 "-s save mode (timer, state, restore)\n"
10315 "-S power_src set power source: battery, nonbattery (source)\n"
10316 "-T timer set timer, seconds, .1 sec resolution (timer)\n"
10318 "-r report the timestamp of the device\n"
10319 "-f format report the timestamp of the device with the given\n"
10321 "-m report the timestamp of the device as milliseconds since\n"
10323 "-U report the time with UTC instead of the local time zone\n"
10324 "-s set the timestamp of the device\n"
10325 "-f format the format of the time string passed into strptime(3)\n"
10326 "-T time the time value passed into strptime(3)\n"
10327 "-U set the timestamp of the device to UTC time\n"
10329 "-d remove an element from service\n"
10330 "-l list status of all elements of drive\n"
10331 "-r restore all elements to service\n"
10332 "-e elm element to remove\n"
10333 "-c capacity requested new capacity\n"
10335 "-c mmc_cmd MMC command to send to the card\n"
10336 "-a mmc_arg Argument for the MMC command\n"
10337 "-f mmc_flag Flags to set for the MMC command\n"
10338 "-l data_len Expect data_len bytes of data in reply and display them\n"
10339 "-W Fill the data buffer before invoking the MMC command\n"
10340 "-b data_byte One byte of data to fill the data buffer with\n"
10341 "-F frequency Operating frequency to set on the controller\n"
10342 "-4 Set bus width to 4 bit\n"
10343 "-1 Set bus width to 8 bit\n"
10344 "-S high | std Set high-speed or standard timing\n"
10345 "-I Display various card and host controller information\n"
10349 int
10350 main(int argc, char **argv)
10352 int c;
10354 int unit = 0;
10356 int timeout = 0, retry_count = 1;
10362 int error = 0, optstart = 2;
10363 int task_attr = MSG_SIMPLE_Q_TAG;
10364 int devopen = 1;
10432 * (non-GPL!) command line parsing interface than getopt. I
10457 && (argc > 2 && argv[2][0] != '-')) {
10459 int rv;
10476 == -1)
10495 while ((c = getopt(argc, argv, combinedopt))!= -1){
10516 int table_entry = 0;