From owner-svn-src-stable@freebsd.org Fri Feb 2 23:19:21 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3674CED22B3; Fri, 2 Feb 2018 23:19:21 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D76AD861A7; Fri, 2 Feb 2018 23:19:20 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CDD5F22431; Fri, 2 Feb 2018 23:19:20 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w12NJKqq069951; Fri, 2 Feb 2018 23:19:20 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w12NJKto069946; Fri, 2 Feb 2018 23:19:20 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201802022319.w12NJKto069946@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Fri, 2 Feb 2018 23:19:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r328819 - in stable/11/sys/cam: . ata nvme scsi X-SVN-Group: stable-11 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: in stable/11/sys/cam: . ata nvme scsi X-SVN-Commit-Revision: 328819 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Feb 2018 23:19:21 -0000 Author: mav Date: Fri Feb 2 23:19:20 2018 New Revision: 328819 URL: https://svnweb.freebsd.org/changeset/base/328819 Log: MFC r303467 (by imp): Switch to linker sets to find the xport callback object. This eliminates the need to special case everything in cam_xpt for new transports. It is now a failure to not have a transport object when registering the bus as well. You can still, however, create a transport that's unspecified (XPT_) Modified: stable/11/sys/cam/ata/ata_xpt.c stable/11/sys/cam/cam_xpt.c stable/11/sys/cam/cam_xpt_internal.h stable/11/sys/cam/nvme/nvme_xpt.c stable/11/sys/cam/scsi/scsi_xpt.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/cam/ata/ata_xpt.c ============================================================================== --- stable/11/sys/cam/ata/ata_xpt.c Fri Feb 2 22:53:58 2018 (r328818) +++ stable/11/sys/cam/ata/ata_xpt.c Fri Feb 2 23:19:20 2018 (r328819) @@ -196,18 +196,24 @@ static int atapi_dma = 1; 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 void probe_periph_init() Modified: stable/11/sys/cam/cam_xpt.c ============================================================================== --- stable/11/sys/cam/cam_xpt.c Fri Feb 2 22:53:58 2018 (r328818) +++ stable/11/sys/cam/cam_xpt.c Fri Feb 2 23:19:20 2018 (r328819) @@ -1044,7 +1044,7 @@ xpt_announce_periph(struct cam_periph *periph, char *a 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) { @@ -2488,7 +2488,7 @@ xpt_action(union ccb *start_ccb) 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 @@ -3507,9 +3507,9 @@ xpt_compile_path(struct cam_path *new_path, struct cam 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 { @@ -3857,12 +3857,19 @@ xpt_release_ccb(union ccb *free_ccb) /* 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 * identification info is passed to xpt_bus_register to hook the SIM @@ -3931,27 +3938,21 @@ xpt_bus_register(struct cam_sim *sim, device_t parent, 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); + } } /* Notify interested parties */ @@ -4160,7 +4161,7 @@ xpt_async_process_dev(struct cam_ed *device, void *arg } 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); Modified: stable/11/sys/cam/cam_xpt_internal.h ============================================================================== --- stable/11/sys/cam/cam_xpt_internal.h Fri Feb 2 22:53:58 2018 (r328818) +++ stable/11/sys/cam/cam_xpt_internal.h Fri Feb 2 23:19:20 2018 (r328819) @@ -48,7 +48,7 @@ typedef void (*xpt_dev_async_func)(u_int32_t async_cod 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,16 @@ struct xpt_xport { 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) + /* * The CAM EDT (Existing Device Table) contains the device information for * all devices for all busses in the system. The table contains a @@ -166,10 +176,6 @@ struct cam_path { struct cam_et *target; 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, Modified: stable/11/sys/cam/nvme/nvme_xpt.c ============================================================================== --- stable/11/sys/cam/nvme/nvme_xpt.c Fri Feb 2 22:53:58 2018 (r328818) +++ stable/11/sys/cam/nvme/nvme_xpt.c Fri Feb 2 23:19:20 2018 (r328819) @@ -153,19 +153,23 @@ static void nvme_dev_async(u_int32_t async_code, static void nvme_action(union ccb *start_ccb); static void nvme_announce_periph(struct cam_periph *periph); -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 void nvme_probe_periph_init() Modified: stable/11/sys/cam/scsi/scsi_xpt.c ============================================================================== --- stable/11/sys/cam/scsi/scsi_xpt.c Fri Feb 2 22:53:58 2018 (r328818) +++ stable/11/sys/cam/scsi/scsi_xpt.c Fri Feb 2 23:19:20 2018 (r328819) @@ -590,18 +590,29 @@ static void scsi_dev_async(u_int32_t async_code, static void scsi_action(union ccb *start_ccb); static void scsi_announce_periph(struct cam_periph *periph); -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 void probe_periph_init()