Date: Thu, 8 Nov 2012 00:32:36 +0000 (UTC) From: Doug Ambrisko <ambrisko@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r242726 - head/sys/dev/mfi Message-ID: <201211080032.qA80Wad3039739@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ambrisko Date: Thu Nov 8 00:32:36 2012 New Revision: 242726 URL: http://svnweb.freebsd.org/changeset/base/242726 Log: Add support for SCSI pass through devices to be attached and detached. PR: 172864 Submitted by: rstone@ Modified: head/sys/dev/mfi/mfi.c head/sys/dev/mfi/mfi_cam.c head/sys/dev/mfi/mfivar.h Modified: head/sys/dev/mfi/mfi.c ============================================================================== --- head/sys/dev/mfi/mfi.c Thu Nov 8 00:24:26 2012 (r242725) +++ head/sys/dev/mfi/mfi.c Thu Nov 8 00:32:36 2012 (r242726) @@ -1577,6 +1577,11 @@ mfi_decode_evt(struct mfi_softc *sc, str sx_xunlock(&sc->mfi_config_lock); } } + if (sc->mfi_cam_rescan_cb != NULL && + (detail->code == MR_EVT_PD_INSERTED || + detail->code == MR_EVT_PD_REMOVED)) { + sc->mfi_cam_rescan_cb(sc, detail->args.pd.device_id); + } break; } } Modified: head/sys/dev/mfi/mfi_cam.c ============================================================================== --- head/sys/dev/mfi/mfi_cam.c Thu Nov 8 00:24:26 2012 (r242725) +++ head/sys/dev/mfi/mfi_cam.c Thu Nov 8 00:32:36 2012 (r242726) @@ -50,7 +50,9 @@ __FBSDID("$FreeBSD$"); #include <cam/cam.h> #include <cam/cam_ccb.h> #include <cam/cam_debug.h> +#include <cam/cam_periph.h> #include <cam/cam_sim.h> +#include <cam/cam_xpt_periph.h> #include <cam/cam_xpt_sim.h> #include <cam/scsi/scsi_all.h> #include <cam/scsi/scsi_message.h> @@ -63,12 +65,19 @@ __FBSDID("$FreeBSD$"); #include <dev/mfi/mfi_ioctl.h> #include <dev/mfi/mfivar.h> +enum mfip_state { + MFIP_STATE_NONE, + MFIP_STATE_DETACH, + MFIP_STATE_RESCAN +}; + struct mfip_softc { device_t dev; struct mfi_softc *mfi_sc; struct cam_devq *devq; struct cam_sim *sim; struct cam_path *path; + enum mfip_state state; }; static int mfip_probe(device_t); @@ -76,6 +85,7 @@ static int mfip_attach(device_t); static int mfip_detach(device_t); static void mfip_cam_action(struct cam_sim *, union ccb *); static void mfip_cam_poll(struct cam_sim *); +static void mfip_cam_rescan(struct mfi_softc *, uint32_t tid); static struct mfi_command * mfip_start(void *); static void mfip_done(struct mfi_command *cm); @@ -122,6 +132,7 @@ mfip_attach(device_t dev) mfisc = device_get_softc(device_get_parent(dev)); sc->dev = dev; + sc->state = MFIP_STATE_NONE; sc->mfi_sc = mfisc; mfisc->mfi_cam_start = mfip_start; @@ -137,6 +148,8 @@ mfip_attach(device_t dev) return (EINVAL); } + mfisc->mfi_cam_rescan_cb = mfip_cam_rescan; + mtx_lock(&mfisc->mfi_io_lock); if (xpt_bus_register(sc->sim, dev, 0) != 0) { device_printf(dev, "XPT bus registration failed\n"); @@ -159,6 +172,16 @@ mfip_detach(device_t dev) if (sc == NULL) return (EINVAL); + mtx_lock(&sc->mfi_sc->mfi_io_lock); + if (sc->state == MFIP_STATE_RESCAN) { + mtx_unlock(&sc->mfi_sc->mfi_io_lock); + return (EBUSY); + } + sc->state = MFIP_STATE_DETACH; + mtx_unlock(&sc->mfi_sc->mfi_io_lock); + + sc->mfi_sc->mfi_cam_rescan_cb = NULL; + if (sc->sim != NULL) { mtx_lock(&sc->mfi_sc->mfi_io_lock); xpt_bus_deregister(cam_sim_path(sc->sim)); @@ -266,6 +289,54 @@ mfip_cam_action(struct cam_sim *sim, uni return; } +static void +mfip_cam_rescan(struct mfi_softc *sc, uint32_t tid) +{ + union ccb *ccb; + struct mfip_softc *camsc; + struct cam_sim *sim; + device_t mfip_dev; + + mtx_lock(&Giant); + mfip_dev = device_find_child(sc->mfi_dev, "mfip", -1); + mtx_unlock(&Giant); + if (mfip_dev == NULL) { + device_printf(sc->mfi_dev, "Couldn't find mfip child device!\n"); + return; + } + + mtx_lock(&sc->mfi_io_lock); + camsc = device_get_softc(mfip_dev); + if (camsc->state == MFIP_STATE_DETACH) { + mtx_unlock(&sc->mfi_io_lock); + return; + } + camsc->state = MFIP_STATE_RESCAN; + mtx_unlock(&sc->mfi_io_lock); + + ccb = xpt_alloc_ccb_nowait(); + if (ccb == NULL) { + device_printf(sc->mfi_dev, + "Cannot allocate ccb for bus rescan.\n"); + return; + } + + sim = camsc->sim; + if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, cam_sim_path(sim), + tid, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { + xpt_free_ccb(ccb); + device_printf(sc->mfi_dev, + "Cannot create path for bus rescan.\n"); + return; + } + + xpt_rescan(ccb); + + mtx_lock(&sc->mfi_io_lock); + camsc->state = MFIP_STATE_NONE; + mtx_unlock(&sc->mfi_io_lock); +} + static struct mfi_command * mfip_start(void *data) { Modified: head/sys/dev/mfi/mfivar.h ============================================================================== --- head/sys/dev/mfi/mfivar.h Thu Nov 8 00:24:26 2012 (r242725) +++ head/sys/dev/mfi/mfivar.h Thu Nov 8 00:32:36 2012 (r242726) @@ -303,6 +303,8 @@ struct mfi_softc { TAILQ_HEAD(, ccb_hdr) mfi_cam_ccbq; struct mfi_command * (* mfi_cam_start)(void *); + void (*mfi_cam_rescan_cb)(struct mfi_softc *, + uint32_t); struct callout mfi_watchdog_callout; struct mtx mfi_io_lock; struct sx mfi_config_lock;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211080032.qA80Wad3039739>