Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F151220385
D7289.id18685.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
16 KB
Referenced Files
None
Subscribers
None
D7289.id18685.diff
View Options
Index: sys/cam/ata/ata_xpt.c
===================================================================
--- sys/cam/ata/ata_xpt.c
+++ sys/cam/ata/ata_xpt.c
@@ -188,6 +188,11 @@
void *async_arg);
static void ata_action(union ccb *start_ccb);
static void ata_announce_periph(struct cam_periph *periph);
+static void ata_proto_announce(struct cam_ed *device);
+static void ata_proto_denounce(struct cam_ed *device);
+static void ata_proto_debug_out(union ccb *ccb);
+static void semb_proto_announce(struct cam_ed *device);
+static void semb_proto_denounce(struct cam_ed *device);
static int ata_dma = 1;
static int atapi_dma = 1;
@@ -195,18 +200,61 @@
TUNABLE_INT("hw.ata.ata_dma", &ata_dma);
TUNABLE_INT("hw.ata.atapi_dma", &atapi_dma);
-static struct xpt_xport ata_xport = {
+static struct xpt_xport_ops ata_xport_ops = {
.alloc_device = ata_alloc_device,
.action = ata_action,
.async = ata_dev_async,
.announce = ata_announce_periph,
};
+#define ATA_XPT_XPORT(x, X) \
+static struct xpt_xport ata_xport_ ## x = { \
+ .xport = XPORT_ ## X, \
+ .name = #x, \
+ .ops = &ata_xport_ops, \
+}; \
+CAM_XPT_XPORT(ata_xport_ ## x);
-struct xpt_xport *
-ata_get_xport(void)
-{
- return (&ata_xport);
-}
+ATA_XPT_XPORT(ata, ATA);
+ATA_XPT_XPORT(sata, SATA);
+
+#undef ATA_XPORT_XPORT
+
+static struct xpt_proto_ops ata_proto_ops_ata = {
+ .announce = ata_proto_announce,
+ .denounce = ata_proto_denounce,
+ .debug_out = ata_proto_debug_out,
+};
+static struct xpt_proto ata_proto_ata = {
+ .proto = PROTO_ATA,
+ .name = "ata",
+ .ops = &ata_proto_ops_ata,
+};
+
+static struct xpt_proto_ops ata_proto_ops_satapm = {
+ .announce = ata_proto_announce,
+ .denounce = ata_proto_denounce,
+ .debug_out = ata_proto_debug_out,
+};
+static struct xpt_proto ata_proto_satapm = {
+ .proto = PROTO_SATAPM,
+ .name = "satapm",
+ .ops = &ata_proto_ops_satapm,
+};
+
+static struct xpt_proto_ops ata_proto_ops_semb = {
+ .announce = semb_proto_announce,
+ .denounce = semb_proto_denounce,
+ .debug_out = ata_proto_debug_out,
+};
+static struct xpt_proto ata_proto_semb = {
+ .proto = PROTO_SEMB,
+ .name = "semb",
+ .ops = &ata_proto_ops_semb,
+};
+
+CAM_XPT_PROTO(ata_proto_ata);
+CAM_XPT_PROTO(ata_proto_satapm);
+CAM_XPT_PROTO(ata_proto_semb);
static void
probe_periph_init()
@@ -2088,3 +2136,40 @@
}
printf("\n");
}
+
+static void
+ata_proto_announce(struct cam_ed *device)
+{
+ ata_print_ident(&device->ident_data);
+}
+
+static void
+ata_proto_denounce(struct cam_ed *device)
+{
+ ata_print_ident_short(&device->ident_data);
+}
+
+static void
+semb_proto_announce(struct cam_ed *device)
+{
+ semb_print_ident((struct sep_identify_data *)&device->ident_data);
+}
+
+static void
+semb_proto_denounce(struct cam_ed *device)
+{
+ semb_print_ident_short((struct sep_identify_data *)&device->ident_data);
+}
+
+static void
+ata_proto_debug_out(union ccb *ccb)
+{
+ char cdb_str[(sizeof(struct ata_cmd) * 3) + 1];
+
+ if (ccb->ccb_h.func_code != XPT_ATA_IO)
+ return;
+
+ CAM_DEBUG(ccb->ccb_h.path,
+ CAM_DEBUG_CDB,("%s. ACB: %s\n", ata_op_string(&ccb->ataio.cmd),
+ ata_cmd_string(&ccb->ataio.cmd, cdb_str, sizeof(cdb_str))));
+}
Index: sys/cam/cam_xpt.c
===================================================================
--- sys/cam/cam_xpt.c
+++ sys/cam/cam_xpt.c
@@ -746,6 +746,19 @@
return 0;
}
+static struct xpt_proto *
+xpt_proto_find(cam_proto proto)
+{
+ struct xpt_proto **pp;
+
+ SET_FOREACH(pp, cam_xpt_proto_set) {
+ if ((*pp)->proto == proto)
+ return *pp;
+ }
+
+ return NULL;
+}
+
static void
xpt_rescan_done(struct cam_periph *periph, union ccb *done_ccb)
{
@@ -1012,6 +1025,7 @@
xpt_announce_periph(struct cam_periph *periph, char *announce_string)
{
struct cam_path *path = periph->path;
+ struct xpt_proto *proto;
cam_periph_assert(periph, MA_OWNED);
periph->flags |= CAM_PERIPH_ANNOUNCED;
@@ -1025,25 +1039,20 @@
path->target->target_id,
(uintmax_t)path->device->lun_id);
printf("%s%d: ", periph->periph_name, periph->unit_number);
- if (path->device->protocol == PROTO_SCSI)
- scsi_print_inquiry(&path->device->inq_data);
- else if (path->device->protocol == PROTO_ATA ||
- path->device->protocol == PROTO_SATAPM)
- ata_print_ident(&path->device->ident_data);
- else if (path->device->protocol == PROTO_SEMB)
- semb_print_ident(
- (struct sep_identify_data *)&path->device->ident_data);
- else if (path->device->protocol == PROTO_NVME)
- nvme_print_ident(path->device->nvme_cdata, path->device->nvme_data);
+ proto = xpt_proto_find(path->device->protocol);
+ if (proto)
+ proto->ops->announce(path->device);
else
- printf("Unknown protocol device\n");
+ printf("%s%d: Unknown protocol device %d\n",
+ periph->periph_name, periph->unit_number,
+ path->device->protocol);
if (path->device->serial_num_len > 0) {
/* Don't wrap the screen - print only the first 60 chars */
printf("%s%d: Serial Number %.60s\n", periph->periph_name,
periph->unit_number, path->device->serial_num);
}
/* Announce transport details. */
- (*(path->bus->xport->announce))(periph);
+ path->bus->xport->ops->announce(periph);
/* Announce command queueing. */
if (path->device->inq_flags & SID_CmdQue
|| path->device->flags & CAM_DEV_TAG_AFTER_COUNT) {
@@ -1069,6 +1078,7 @@
xpt_denounce_periph(struct cam_periph *periph)
{
struct cam_path *path = periph->path;
+ struct xpt_proto *proto;
cam_periph_assert(periph, MA_OWNED);
printf("%s%d at %s%d bus %d scbus%d target %d lun %jx\n",
@@ -1080,18 +1090,13 @@
path->target->target_id,
(uintmax_t)path->device->lun_id);
printf("%s%d: ", periph->periph_name, periph->unit_number);
- if (path->device->protocol == PROTO_SCSI)
- scsi_print_inquiry_short(&path->device->inq_data);
- else if (path->device->protocol == PROTO_ATA ||
- path->device->protocol == PROTO_SATAPM)
- ata_print_ident_short(&path->device->ident_data);
- else if (path->device->protocol == PROTO_SEMB)
- semb_print_ident_short(
- (struct sep_identify_data *)&path->device->ident_data);
- else if (path->device->protocol == PROTO_NVME)
- nvme_print_ident(path->device->nvme_cdata, path->device->nvme_data);
+ proto = xpt_proto_find(path->device->protocol);
+ if (proto)
+ proto->ops->denounce(path->device);
else
- printf("Unknown protocol device");
+ printf("%s%d: Unknown protocol device %d\n",
+ periph->periph_name, periph->unit_number,
+ path->device->protocol);
if (path->device->serial_num_len > 0)
printf(" s/n %.60s", path->device->serial_num);
printf(" detached\n");
@@ -2464,7 +2469,7 @@
xpt_action_name(start_ccb->ccb_h.func_code)));
start_ccb->ccb_h.status = CAM_REQ_INPROG;
- (*(start_ccb->ccb_h.path->bus->xport->action))(start_ccb);
+ (*(start_ccb->ccb_h.path->bus->xport->ops->action))(start_ccb);
}
void
@@ -3234,7 +3239,6 @@
static void
xpt_run_devq(struct cam_devq *devq)
{
- char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1];
int lock;
CAM_DEBUG_PRINT(CAM_DEBUG_XPT, ("xpt_run_devq\n"));
@@ -3246,6 +3250,7 @@
struct cam_ed *device;
union ccb *work_ccb;
struct cam_sim *sim;
+ struct xpt_proto *proto;
device = (struct cam_ed *)camq_remove(&devq->send_queue,
CAMQ_HEAD);
@@ -3311,32 +3316,12 @@
work_ccb->ccb_h.flags &= ~CAM_TAG_ACTION_VALID;
}
- switch (work_ccb->ccb_h.func_code) {
- case XPT_SCSI_IO:
- CAM_DEBUG(work_ccb->ccb_h.path,
- CAM_DEBUG_CDB,("%s. CDB: %s\n",
- scsi_op_desc(work_ccb->csio.cdb_io.cdb_bytes[0],
- &device->inq_data),
- scsi_cdb_string(work_ccb->csio.cdb_io.cdb_bytes,
- cdb_str, sizeof(cdb_str))));
- break;
- case XPT_ATA_IO:
- CAM_DEBUG(work_ccb->ccb_h.path,
- CAM_DEBUG_CDB,("%s. ACB: %s\n",
- ata_op_string(&work_ccb->ataio.cmd),
- ata_cmd_string(&work_ccb->ataio.cmd,
- cdb_str, sizeof(cdb_str))));
- break;
- case XPT_NVME_IO:
- CAM_DEBUG(work_ccb->ccb_h.path,
- CAM_DEBUG_CDB,("%s. NCB: %s\n",
- nvme_op_string(&work_ccb->nvmeio.cmd),
- nvme_cmd_string(&work_ccb->nvmeio.cmd,
- cdb_str, sizeof(cdb_str))));
- break;
- default:
- break;
- }
+ KASSERT(device == work_ccb->ccb_h.path->device,
+ ("device (%p) / path->device (%p) mismatch",
+ device, work_ccb->ccb_h.path->device));
+ proto = xpt_proto_find(device->protocol);
+ if (proto && proto->ops->debug_out)
+ proto->ops->debug_out(work_ccb);
/*
* Device queues can be shared among multiple SIM instances
@@ -3482,9 +3467,9 @@
struct cam_ed *new_device;
new_device =
- (*(bus->xport->alloc_device))(bus,
- target,
- lun_id);
+ (*(bus->xport->ops->alloc_device))(bus,
+ target,
+ lun_id);
if (new_device == NULL) {
status = CAM_RESRC_UNAVAIL;
} else {
@@ -3832,11 +3817,18 @@
/* Functions accessed by SIM drivers */
-static struct xpt_xport xport_default = {
+static struct xpt_xport_ops xport_default_ops = {
.alloc_device = xpt_alloc_device_default,
.action = xpt_action_default,
.async = xpt_dev_async_default,
};
+static struct xpt_xport xport_default = {
+ .xport = XPORT_UNKNOWN,
+ .name = "unknown",
+ .ops = &xport_default_ops,
+};
+
+CAM_XPT_XPORT(xport_default);
/*
* A sim structure, listing the SIM entry points and instance
@@ -3909,26 +3901,20 @@
xpt_action((union ccb *)&cpi);
if (cpi.ccb_h.status == CAM_REQ_CMP) {
- switch (cpi.transport) {
- case XPORT_SPI:
- case XPORT_SAS:
- case XPORT_FC:
- case XPORT_USB:
- case XPORT_ISCSI:
- case XPORT_SRP:
- case XPORT_PPB:
- new_bus->xport = scsi_get_xport();
- break;
- case XPORT_ATA:
- case XPORT_SATA:
- new_bus->xport = ata_get_xport();
- break;
- case XPORT_NVME:
- new_bus->xport = nvme_get_xport();
- break;
- default:
- new_bus->xport = &xport_default;
- break;
+ struct xpt_xport **xpt;
+
+ SET_FOREACH(xpt, cam_xpt_xport_set) {
+ if ((*xpt)->xport == cpi.transport) {
+ new_bus->xport = *xpt;
+ break;
+ }
+ }
+ if (new_bus->xport == NULL) {
+ xpt_print_path(path);
+ printf("No transport found for %d\n", cpi.transport);
+ xpt_release_bus(new_bus);
+ free(path, M_CAMXPT);
+ return (CAM_RESRC_UNAVAIL);
}
}
@@ -4138,7 +4124,7 @@
} else
relock = 0;
- (*(device->target->bus->xport->async))(async_code,
+ (*(device->target->bus->xport->ops->async))(async_code,
device->target->bus, device->target, device, async_arg);
xpt_async_bcast(&device->asyncs, async_code, path, async_arg);
Index: sys/cam/cam_xpt_internal.h
===================================================================
--- sys/cam/cam_xpt_internal.h
+++ sys/cam/cam_xpt_internal.h
@@ -48,7 +48,7 @@
void *async_arg);
typedef void (*xpt_announce_periph_func)(struct cam_periph *periph);
-struct xpt_xport {
+struct xpt_xport_ops {
xpt_alloc_device_func alloc_device;
xpt_release_device_func reldev;
xpt_action_func action;
@@ -56,6 +56,36 @@
xpt_announce_periph_func announce;
};
+struct xpt_xport {
+ cam_xport xport;
+ const char *name;
+ struct xpt_xport_ops *ops;
+};
+
+SET_DECLARE(cam_xpt_xport_set, struct xpt_xport);
+#define CAM_XPT_XPORT(data) \
+ DATA_SET(cam_xpt_xport_set, data)
+
+typedef void (*xpt_proto_announce_func)(struct cam_ed *);
+typedef void (*xpt_proto_debug_out_func)(union ccb *);
+
+struct xpt_proto_ops {
+ xpt_proto_announce_func announce;
+ xpt_proto_announce_func denounce;
+ xpt_proto_debug_out_func debug_out;
+};
+
+struct xpt_proto {
+ cam_proto proto;
+ const char *name;
+ struct xpt_proto_ops *ops;
+};
+
+SET_DECLARE(cam_xpt_proto_set, struct xpt_proto);
+#define CAM_XPT_PROTO(data) \
+ DATA_SET(cam_xpt_proto_set, data)
+
+
/*
* The CAM EDT (Existing Device Table) contains the device information for
* all devices for all busses in the system. The table contains a
@@ -167,10 +197,6 @@
struct cam_ed *device;
};
-struct xpt_xport * scsi_get_xport(void);
-struct xpt_xport * ata_get_xport(void);
-struct xpt_xport * nvme_get_xport(void);
-
struct cam_ed * xpt_alloc_device(struct cam_eb *bus,
struct cam_et *target,
lun_id_t lun_id);
Index: sys/cam/nvme/nvme_xpt.c
===================================================================
--- sys/cam/nvme/nvme_xpt.c
+++ sys/cam/nvme/nvme_xpt.c
@@ -152,20 +152,39 @@
void *async_arg);
static void nvme_action(union ccb *start_ccb);
static void nvme_announce_periph(struct cam_periph *periph);
+static void nvme_proto_announce(struct cam_ed *device);
+static void nvme_proto_denounce(struct cam_ed *device);
+static void nvme_proto_debug_out(union ccb *ccb);
-static struct xpt_xport nvme_xport = {
+static struct xpt_xport_ops nvme_xport_ops = {
.alloc_device = nvme_alloc_device,
.action = nvme_action,
.async = nvme_dev_async,
.announce = nvme_announce_periph,
};
+#define NVME_XPT_XPORT(x, X) \
+static struct xpt_xport nvme_xport_ ## x = { \
+ .xport = XPORT_ ## X, \
+ .name = #x, \
+ .ops = &nvme_xport_ops, \
+}; \
+CAM_XPT_XPORT(nvme_xport_ ## x);
-struct xpt_xport *
-nvme_get_xport(void)
-{
+NVME_XPT_XPORT(nvme, NVME);
- return (&nvme_xport);
-}
+#undef NVME_XPT_XPORT
+
+static struct xpt_proto_ops nvme_proto_ops = {
+ .announce = nvme_proto_announce,
+ .denounce = nvme_proto_denounce,
+ .debug_out = nvme_proto_debug_out,
+};
+static struct xpt_proto nvme_proto = {
+ .proto = PROTO_NVME,
+ .name = "nvme",
+ .ops = &nvme_proto_ops,
+};
+CAM_XPT_PROTO(nvme_proto);
static void
nvme_probe_periph_init()
@@ -603,3 +622,29 @@
/* XXX NVME STUFF HERE */
printf("\n");
}
+
+static void
+nvme_proto_announce(struct cam_ed *device)
+{
+ nvme_print_ident(device->nvme_cdata, device->nvme_data);
+}
+
+static void
+nvme_proto_denounce(struct cam_ed *device)
+{
+ nvme_print_ident(device->nvme_cdata, device->nvme_data);
+}
+
+static void
+nvme_proto_debug_out(union ccb *ccb)
+{
+ char cdb_str[(sizeof(struct nvme_command) * 3) + 1];
+
+ if (ccb->ccb_h.func_code != XPT_NVME_IO)
+ return;
+
+ CAM_DEBUG(ccb->ccb_h.path,
+ CAM_DEBUG_CDB,("%s. NCB: %s\n", nvme_op_string(&ccb->nvmeio.cmd),
+ nvme_cmd_string(&ccb->nvmeio.cmd, cdb_str, sizeof(cdb_str))));
+}
+
Index: sys/cam/scsi/scsi_xpt.c
===================================================================
--- sys/cam/scsi/scsi_xpt.c
+++ sys/cam/scsi/scsi_xpt.c
@@ -589,19 +589,45 @@
void *async_arg);
static void scsi_action(union ccb *start_ccb);
static void scsi_announce_periph(struct cam_periph *periph);
+static void scsi_proto_announce(struct cam_ed *device);
+static void scsi_proto_denounce(struct cam_ed *device);
+static void scsi_proto_debug_out(union ccb *ccb);
-static struct xpt_xport scsi_xport = {
+static struct xpt_xport_ops scsi_xport_ops = {
.alloc_device = scsi_alloc_device,
.action = scsi_action,
.async = scsi_dev_async,
.announce = scsi_announce_periph,
};
+#define SCSI_XPT_XPORT(x, X) \
+static struct xpt_xport scsi_xport_ ## x = { \
+ .xport = XPORT_ ## X, \
+ .name = #x, \
+ .ops = &scsi_xport_ops, \
+}; \
+CAM_XPT_XPORT(scsi_xport_ ## x);
-struct xpt_xport *
-scsi_get_xport(void)
-{
- return (&scsi_xport);
-}
+SCSI_XPT_XPORT(spi, SPI);
+SCSI_XPT_XPORT(sas, SAS);
+SCSI_XPT_XPORT(fc, FC);
+SCSI_XPT_XPORT(usb, USB);
+SCSI_XPT_XPORT(iscsi, ISCSI);
+SCSI_XPT_XPORT(srp, SRP);
+SCSI_XPT_XPORT(ppb, PPB);
+
+#undef SCSI_XPORT_XPORT
+
+static struct xpt_proto_ops scsi_proto_ops = {
+ .announce = scsi_proto_announce,
+ .denounce = scsi_proto_denounce,
+ .debug_out = scsi_proto_debug_out,
+};
+static struct xpt_proto scsi_proto = {
+ .proto = PROTO_SCSI,
+ .name = "scsi",
+ .ops = &scsi_proto_ops,
+};
+CAM_XPT_PROTO(scsi_proto);
static void
probe_periph_init()
@@ -3089,3 +3115,30 @@
printf("\n");
}
+static void
+scsi_proto_announce(struct cam_ed *device)
+{
+ scsi_print_inquiry(&device->inq_data);
+}
+
+static void
+scsi_proto_denounce(struct cam_ed *device)
+{
+ scsi_print_inquiry_short(&device->inq_data);
+}
+
+static void
+scsi_proto_debug_out(union ccb *ccb)
+{
+ char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1];
+ struct cam_ed *device;
+
+ if (ccb->ccb_h.func_code != XPT_SCSI_IO)
+ return;
+
+ device = ccb->ccb_h.path->device;
+ CAM_DEBUG(ccb->ccb_h.path,
+ CAM_DEBUG_CDB,("%s. CDB: %s\n",
+ scsi_op_desc(ccb->csio.cdb_io.cdb_bytes[0], &device->inq_data),
+ scsi_cdb_string(ccb->csio.cdb_io.cdb_bytes, cdb_str, sizeof(cdb_str))));
+}
Index: sys/modules/cam/Makefile
===================================================================
--- sys/modules/cam/Makefile
+++ sys/modules/cam/Makefile
@@ -2,7 +2,7 @@
S= ${.CURDIR}/../..
-.PATH: $S/cam $S/cam/scsi $S/cam/ata $S/${MACHINE}/${MACHINE}
+.PATH: $S/cam $S/cam/scsi $S/cam/ata $S/cam/nvme $S/${MACHINE}/${MACHINE}
KMOD= cam
@@ -41,6 +41,11 @@
SRCS+= ata_machdep.c
.endif
SRCS+= ata_pmp.c
+.if ${MACHINE_ARCH} == "amd64"
+SRCS+= nvme_all.c
+SRCS+= nvme_da.c
+SRCS+= nvme_xpt.c
+.endif
EXPORT_SYMS= YES # XXX evaluate
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Apr 7, 10:47 PM (12 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31053233
Default Alt Text
D7289.id18685.diff (16 KB)
Attached To
Mode
D7289: Switch to linker sets to find the xport callback object.
Attached
Detach File
Event Timeline
Log In to Comment