Changeset View
Changeset View
Standalone View
Standalone View
sbin/camcontrol/camcontrol.c
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | |||||
#include <cam/scsi/scsi_da.h> | #include <cam/scsi/scsi_da.h> | ||||
#include <cam/scsi/scsi_pass.h> | #include <cam/scsi/scsi_pass.h> | ||||
#include <cam/scsi/scsi_message.h> | #include <cam/scsi/scsi_message.h> | ||||
#include <cam/scsi/smp_all.h> | #include <cam/scsi/smp_all.h> | ||||
#include <cam/ata/ata_all.h> | #include <cam/ata/ata_all.h> | ||||
#include <cam/mmc/mmc_all.h> | #include <cam/mmc/mmc_all.h> | ||||
#include <camlib.h> | #include <camlib.h> | ||||
#include "camcontrol.h" | #include "camcontrol.h" | ||||
#include "nvmecontrol_ext.h" | |||||
typedef enum { | typedef enum { | ||||
CAM_CMD_NONE = 0x00000000, | CAM_CMD_NONE = 0x00000000, | ||||
CAM_CMD_DEVLIST = 0x00000001, | CAM_CMD_DEVLIST = 0x00000001, | ||||
CAM_CMD_TUR = 0x00000002, | CAM_CMD_TUR = 0x00000002, | ||||
CAM_CMD_INQUIRY = 0x00000003, | CAM_CMD_INQUIRY = 0x00000003, | ||||
CAM_CMD_STARTSTOP = 0x00000004, | CAM_CMD_STARTSTOP = 0x00000004, | ||||
CAM_CMD_RESCAN = 0x00000005, | CAM_CMD_RESCAN = 0x00000005, | ||||
▲ Show 20 Lines • Show All 684 Lines • ▼ Show 20 Lines | print_dev_mmcsd(struct device_match_result *dev_result, char *tmpstr) | ||||
} | } | ||||
cam_freeccb(ccb); | cam_freeccb(ccb); | ||||
cam_close_device(dev); | cam_close_device(dev); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
print_dev_nvme(struct device_match_result *dev_result, char *tmpstr) | nvme_get_cdata(struct cam_device *dev, struct nvme_controller_data *cdata) | ||||
{ | { | ||||
union ccb *ccb; | union ccb *ccb; | ||||
struct ccb_dev_advinfo *advi; | struct ccb_dev_advinfo *advi; | ||||
struct cam_device *dev; | |||||
struct nvme_controller_data cdata; | |||||
char vendor[64], product[64]; | |||||
dev = cam_open_btl(dev_result->path_id, dev_result->target_id, | |||||
dev_result->target_lun, O_RDWR, NULL); | |||||
if (dev == NULL) { | |||||
warnx("%s", cam_errbuf); | |||||
return (1); | |||||
} | |||||
ccb = cam_getccb(dev); | ccb = cam_getccb(dev); | ||||
if (ccb == NULL) { | if (ccb == NULL) { | ||||
warnx("couldn't allocate CCB"); | warnx("couldn't allocate CCB"); | ||||
cam_close_device(dev); | cam_close_device(dev); | ||||
return (1); | return (1); | ||||
} | } | ||||
advi = &ccb->cdai; | advi = &ccb->cdai; | ||||
advi->ccb_h.flags = CAM_DIR_IN; | advi->ccb_h.flags = CAM_DIR_IN; | ||||
advi->ccb_h.func_code = XPT_DEV_ADVINFO; | advi->ccb_h.func_code = XPT_DEV_ADVINFO; | ||||
advi->flags = CDAI_FLAG_NONE; | advi->flags = CDAI_FLAG_NONE; | ||||
advi->buftype = CDAI_TYPE_NVME_CNTRL; | advi->buftype = CDAI_TYPE_NVME_CNTRL; | ||||
advi->bufsiz = sizeof(struct nvme_controller_data); | advi->bufsiz = sizeof(struct nvme_controller_data); | ||||
advi->buf = (uint8_t *)&cdata; | advi->buf = (uint8_t *)cdata; | ||||
if (cam_send_ccb(dev, ccb) < 0) { | if (cam_send_ccb(dev, ccb) < 0) { | ||||
warn("error sending CAMIOCOMMAND ioctl"); | warn("error sending CAMIOCOMMAND ioctl"); | ||||
cam_freeccb(ccb); | cam_freeccb(ccb); | ||||
cam_close_device(dev); | cam_close_device(dev); | ||||
return(1); | return(1); | ||||
} | } | ||||
if (advi->ccb_h.status != CAM_REQ_CMP) { | if (advi->ccb_h.status != CAM_REQ_CMP) { | ||||
warnx("got CAM error %#x", advi->ccb_h.status); | warnx("got CAM error %#x", advi->ccb_h.status); | ||||
cam_freeccb(ccb); | cam_freeccb(ccb); | ||||
cam_close_device(dev); | cam_close_device(dev); | ||||
return(1); | return(1); | ||||
} | } | ||||
cam_freeccb(ccb); | |||||
return 0; | |||||
} | |||||
static int | |||||
print_dev_nvme(struct device_match_result *dev_result, char *tmpstr) | |||||
{ | |||||
struct cam_device *dev; | |||||
struct nvme_controller_data cdata; | |||||
char vendor[64], product[64]; | |||||
dev = cam_open_btl(dev_result->path_id, dev_result->target_id, | |||||
dev_result->target_lun, O_RDWR, NULL); | |||||
if (dev == NULL) { | |||||
warnx("%s", cam_errbuf); | |||||
return (1); | |||||
} | |||||
if (nvme_get_cdata(dev, &cdata)) | |||||
return (1); | |||||
cam_strvis(vendor, cdata.mn, sizeof(cdata.mn), sizeof(vendor)); | cam_strvis(vendor, cdata.mn, sizeof(cdata.mn), sizeof(vendor)); | ||||
cam_strvis(product, cdata.fr, sizeof(cdata.fr), sizeof(product)); | cam_strvis(product, cdata.fr, sizeof(cdata.fr), sizeof(product)); | ||||
sprintf(tmpstr, "<%s %s>", vendor, product); | sprintf(tmpstr, "<%s %s>", vendor, product); | ||||
cam_freeccb(ccb); | |||||
cam_close_device(dev); | cam_close_device(dev); | ||||
return (0); | return (0); | ||||
} | } | ||||
#ifndef MINIMALISTIC | #ifndef MINIMALISTIC | ||||
static int | static int | ||||
testunitready(struct cam_device *device, int task_attr, int retry_count, | testunitready(struct cam_device *device, int task_attr, int retry_count, | ||||
int timeout, int quiet) | int timeout, int quiet) | ||||
▲ Show 20 Lines • Show All 1,564 Lines • ▼ Show 20 Lines | ataidentify(struct cam_device *device, int retry_count, int timeout) | ||||
atacapprint(ident_buf); | atacapprint(ident_buf); | ||||
atahpa_print(ident_buf, hpasize, 0); | atahpa_print(ident_buf, hpasize, 0); | ||||
free(ident_buf); | free(ident_buf); | ||||
cam_freeccb(ccb); | cam_freeccb(ccb); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | |||||
nvmeidentify(struct cam_device *device, int retry_count __unused, int timeout __unused) | |||||
{ | |||||
struct nvme_controller_data cdata; | |||||
if (nvme_get_cdata(device, &cdata)) | |||||
return (1); | |||||
nvme_print_controller(&cdata); | |||||
return (0); | |||||
} | |||||
static int | |||||
identify(struct cam_device *device, int retry_count, int timeout) | |||||
{ | |||||
struct ccb_pathinq cpi; | |||||
if (get_cpi(device, &cpi) != 0) { | |||||
warnx("couldn't get CPI"); | |||||
return (-1); | |||||
} | |||||
if (cpi.protocol == PROTO_NVME) { | |||||
return (nvmeidentify(device, retry_count, timeout)); | |||||
} | |||||
return (ataidentify(device, retry_count, timeout)); | |||||
} | |||||
#endif /* MINIMALISTIC */ | #endif /* MINIMALISTIC */ | ||||
#ifndef MINIMALISTIC | #ifndef MINIMALISTIC | ||||
enum { | enum { | ||||
ATA_SECURITY_ACTION_PRINT, | ATA_SECURITY_ACTION_PRINT, | ||||
ATA_SECURITY_ACTION_FREEZE, | ATA_SECURITY_ACTION_FREEZE, | ||||
ATA_SECURITY_ACTION_UNLOCK, | ATA_SECURITY_ACTION_UNLOCK, | ||||
▲ Show 20 Lines • Show All 7,652 Lines • ▼ Show 20 Lines | case CAM_CMD_TUR: | ||||
error = testunitready(cam_dev, task_attr, retry_count, | error = testunitready(cam_dev, task_attr, retry_count, | ||||
timeout, 0); | timeout, 0); | ||||
break; | break; | ||||
case CAM_CMD_INQUIRY: | case CAM_CMD_INQUIRY: | ||||
error = scsidoinquiry(cam_dev, argc, argv, combinedopt, | error = scsidoinquiry(cam_dev, argc, argv, combinedopt, | ||||
task_attr, retry_count, timeout); | task_attr, retry_count, timeout); | ||||
break; | break; | ||||
case CAM_CMD_IDENTIFY: | case CAM_CMD_IDENTIFY: | ||||
error = ataidentify(cam_dev, retry_count, timeout); | error = identify(cam_dev, retry_count, timeout); | ||||
break; | break; | ||||
case CAM_CMD_STARTSTOP: | case CAM_CMD_STARTSTOP: | ||||
error = scsistart(cam_dev, arglist & CAM_ARG_START_UNIT, | error = scsistart(cam_dev, arglist & CAM_ARG_START_UNIT, | ||||
arglist & CAM_ARG_EJECT, task_attr, | arglist & CAM_ARG_EJECT, task_attr, | ||||
retry_count, timeout); | retry_count, timeout); | ||||
break; | break; | ||||
#endif /* MINIMALISTIC */ | #endif /* MINIMALISTIC */ | ||||
case CAM_CMD_RESCAN: | case CAM_CMD_RESCAN: | ||||
▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines |