Deleted Added
full compact
cam_xpt.c (212991) cam_xpt.c (214279)
1/*-
2 * Implementation of the Common Access Method Transport (XPT) layer.
3 *
4 * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs.
5 * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
1/*-
2 * Implementation of the Common Access Method Transport (XPT) layer.
3 *
4 * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs.
5 * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/cam/cam_xpt.c 212991 2010-09-22 05:17:18Z mav $");
31__FBSDID("$FreeBSD: head/sys/cam/cam_xpt.c 214279 2010-10-24 16:31:57Z brucec $");
32
33#include <sys/param.h>
34#include <sys/bus.h>
35#include <sys/systm.h>
36#include <sys/types.h>
37#include <sys/malloc.h>
38#include <sys/kernel.h>
39#include <sys/time.h>
40#include <sys/conf.h>
41#include <sys/fcntl.h>
32
33#include <sys/param.h>
34#include <sys/bus.h>
35#include <sys/systm.h>
36#include <sys/types.h>
37#include <sys/malloc.h>
38#include <sys/kernel.h>
39#include <sys/time.h>
40#include <sys/conf.h>
41#include <sys/fcntl.h>
42#include <sys/reboot.h>
43#include <sys/interrupt.h>
44#include <sys/sbuf.h>
45#include <sys/taskqueue.h>
46
47#include <sys/lock.h>
48#include <sys/mutex.h>
49#include <sys/sysctl.h>
50#include <sys/kthread.h>

--- 97 unchanged lines hidden (view full) ---

148typedef int xpt_pdrvfunc_t (struct periph_driver **pdrv, void *arg);
149
150/* Transport layer configuration information */
151static struct xpt_softc xsoftc;
152
153TUNABLE_INT("kern.cam.boot_delay", &xsoftc.boot_delay);
154SYSCTL_INT(_kern_cam, OID_AUTO, boot_delay, CTLFLAG_RDTUN,
155 &xsoftc.boot_delay, 0, "Bus registration wait time");
42#include <sys/interrupt.h>
43#include <sys/sbuf.h>
44#include <sys/taskqueue.h>
45
46#include <sys/lock.h>
47#include <sys/mutex.h>
48#include <sys/sysctl.h>
49#include <sys/kthread.h>

--- 97 unchanged lines hidden (view full) ---

147typedef int xpt_pdrvfunc_t (struct periph_driver **pdrv, void *arg);
148
149/* Transport layer configuration information */
150static struct xpt_softc xsoftc;
151
152TUNABLE_INT("kern.cam.boot_delay", &xsoftc.boot_delay);
153SYSCTL_INT(_kern_cam, OID_AUTO, boot_delay, CTLFLAG_RDTUN,
154 &xsoftc.boot_delay, 0, "Bus registration wait time");
156static int xpt_power_down = 0;
157TUNABLE_INT("kern.cam.power_down", &xpt_power_down);
158SYSCTL_INT(_kern_cam, OID_AUTO, power_down, CTLFLAG_RW,
159 &xpt_power_down, 0, "Power down devices on shutdown");
160
161/* Queues for our software interrupt handler */
162typedef TAILQ_HEAD(cam_isrq, ccb_hdr) cam_isrq_t;
163typedef TAILQ_HEAD(cam_simq, cam_sim) cam_simq_t;
164static cam_simq_t cam_simq;
165static struct mtx cam_simq_lock;
166
167/* Pointers to software interrupt handlers */

--- 77 unchanged lines hidden (view full) ---

245static struct cam_eb*
246 xpt_find_bus(path_id_t path_id);
247static struct cam_et*
248 xpt_find_target(struct cam_eb *bus, target_id_t target_id);
249static struct cam_ed*
250 xpt_find_device(struct cam_et *target, lun_id_t lun_id);
251static void xpt_config(void *arg);
252static xpt_devicefunc_t xptpassannouncefunc;
155
156/* Queues for our software interrupt handler */
157typedef TAILQ_HEAD(cam_isrq, ccb_hdr) cam_isrq_t;
158typedef TAILQ_HEAD(cam_simq, cam_sim) cam_simq_t;
159static cam_simq_t cam_simq;
160static struct mtx cam_simq_lock;
161
162/* Pointers to software interrupt handlers */

--- 77 unchanged lines hidden (view full) ---

240static struct cam_eb*
241 xpt_find_bus(path_id_t path_id);
242static struct cam_et*
243 xpt_find_target(struct cam_eb *bus, target_id_t target_id);
244static struct cam_ed*
245 xpt_find_device(struct cam_et *target, lun_id_t lun_id);
246static void xpt_config(void *arg);
247static xpt_devicefunc_t xptpassannouncefunc;
253static void xpt_shutdown(void *arg, int howto);
254static void xptaction(struct cam_sim *sim, union ccb *work_ccb);
255static void xptpoll(struct cam_sim *sim);
256static void camisr(void *);
257static void camisr_runqueue(void *);
258static dev_match_ret xptbusmatch(struct dev_match_pattern *patterns,
259 u_int num_patterns, struct cam_eb *bus);
260static dev_match_ret xptdevicematch(struct dev_match_pattern *patterns,
261 u_int num_patterns,

--- 4271 unchanged lines hidden (view full) ---

4533 }
4534 } else
4535 cam_dpath = NULL;
4536#else /* !CAM_DEBUG_BUS */
4537 cam_dpath = NULL;
4538#endif /* CAM_DEBUG_BUS */
4539#endif /* CAMDEBUG */
4540
248static void xptaction(struct cam_sim *sim, union ccb *work_ccb);
249static void xptpoll(struct cam_sim *sim);
250static void camisr(void *);
251static void camisr_runqueue(void *);
252static dev_match_ret xptbusmatch(struct dev_match_pattern *patterns,
253 u_int num_patterns, struct cam_eb *bus);
254static dev_match_ret xptdevicematch(struct dev_match_pattern *patterns,
255 u_int num_patterns,

--- 4271 unchanged lines hidden (view full) ---

4527 }
4528 } else
4529 cam_dpath = NULL;
4530#else /* !CAM_DEBUG_BUS */
4531 cam_dpath = NULL;
4532#endif /* CAM_DEBUG_BUS */
4533#endif /* CAMDEBUG */
4534
4541 /* Register our shutdown event handler */
4542 if ((EVENTHANDLER_REGISTER(shutdown_final, xpt_shutdown,
4543 NULL, SHUTDOWN_PRI_FIRST)) == NULL) {
4544 printf("xpt_config: failed to register shutdown event.\n");
4545 }
4546
4547 periphdriver_init(1);
4548 xpt_hold_boot();
4549 callout_init(&xsoftc.boot_callout, 1);
4550 callout_reset(&xsoftc.boot_callout, hz * xsoftc.boot_delay / 1000,
4551 xpt_boot_delay, NULL);
4552 /* Fire up rescan thread. */
4553 if (kproc_create(xpt_scanner_thread, NULL, NULL, 0, 0, "xpt_thrd")) {
4554 printf("xpt_config: failed to create rescan thread.\n");

--- 65 unchanged lines hidden (view full) ---

4620 /* Release our hook so that the boot can continue. */
4621 config_intrhook_disestablish(xsoftc.xpt_config_hook);
4622 free(xsoftc.xpt_config_hook, M_CAMXPT);
4623 xsoftc.xpt_config_hook = NULL;
4624
4625 free(context, M_CAMXPT);
4626}
4627
4535 periphdriver_init(1);
4536 xpt_hold_boot();
4537 callout_init(&xsoftc.boot_callout, 1);
4538 callout_reset(&xsoftc.boot_callout, hz * xsoftc.boot_delay / 1000,
4539 xpt_boot_delay, NULL);
4540 /* Fire up rescan thread. */
4541 if (kproc_create(xpt_scanner_thread, NULL, NULL, 0, 0, "xpt_thrd")) {
4542 printf("xpt_config: failed to create rescan thread.\n");

--- 65 unchanged lines hidden (view full) ---

4608 /* Release our hook so that the boot can continue. */
4609 config_intrhook_disestablish(xsoftc.xpt_config_hook);
4610 free(xsoftc.xpt_config_hook, M_CAMXPT);
4611 xsoftc.xpt_config_hook = NULL;
4612
4613 free(context, M_CAMXPT);
4614}
4615
4628/*
4629 * Power down all devices when we are going to power down the system.
4630 */
4631static void
4632xpt_shutdown_dev_done(struct cam_periph *periph, union ccb *done_ccb)
4633{
4634
4635 /* No-op. We're polling. */
4636 return;
4637}
4638
4639static int
4640xpt_shutdown_dev(struct cam_ed *device, void *arg)
4641{
4642 union ccb ccb;
4643 struct cam_path path;
4644
4645 if (device->flags & CAM_DEV_UNCONFIGURED)
4646 return (1);
4647
4648 if (device->protocol == PROTO_ATA) {
4649 /* Only power down device if it supports power management. */
4650 if ((device->ident_data.support.command1 &
4651 ATA_SUPPORT_POWERMGT) == 0)
4652 return (1);
4653 } else if (device->protocol != PROTO_SCSI)
4654 return (1);
4655
4656 xpt_compile_path(&path,
4657 NULL,
4658 device->target->bus->path_id,
4659 device->target->target_id,
4660 device->lun_id);
4661 xpt_setup_ccb(&ccb.ccb_h, &path, CAM_PRIORITY_NORMAL);
4662 if (device->protocol == PROTO_ATA) {
4663 cam_fill_ataio(&ccb.ataio,
4664 1,
4665 xpt_shutdown_dev_done,
4666 CAM_DIR_NONE,
4667 0,
4668 NULL,
4669 0,
4670 30*1000);
4671 ata_28bit_cmd(&ccb.ataio, ATA_SLEEP, 0, 0, 0);
4672 } else {
4673 scsi_start_stop(&ccb.csio,
4674 /*retries*/1,
4675 xpt_shutdown_dev_done,
4676 MSG_SIMPLE_Q_TAG,
4677 /*start*/FALSE,
4678 /*load/eject*/FALSE,
4679 /*immediate*/TRUE,
4680 SSD_FULL_SIZE,
4681 /*timeout*/50*1000);
4682 }
4683 xpt_polled_action(&ccb);
4684
4685 if ((ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
4686 xpt_print(&path, "Device power down failed\n");
4687 if ((ccb.ccb_h.status & CAM_DEV_QFRZN) != 0)
4688 cam_release_devq(ccb.ccb_h.path,
4689 /*relsim_flags*/0,
4690 /*reduction*/0,
4691 /*timeout*/0,
4692 /*getcount_only*/0);
4693 xpt_release_path(&path);
4694 return (1);
4695}
4696
4697static void
4698xpt_shutdown(void * arg, int howto)
4699{
4700
4701 if (!xpt_power_down)
4702 return;
4703 if ((howto & RB_POWEROFF) == 0)
4704 return;
4705
4706 xpt_for_all_devices(xpt_shutdown_dev, NULL);
4707}
4708
4709cam_status
4710xpt_register_async(int event, ac_callback_t *cbfunc, void *cbarg,
4711 struct cam_path *path)
4712{
4713 struct ccb_setasync csa;
4714 cam_status status;
4715 int xptpath = 0;
4716

--- 218 unchanged lines hidden ---
4616cam_status
4617xpt_register_async(int event, ac_callback_t *cbfunc, void *cbarg,
4618 struct cam_path *path)
4619{
4620 struct ccb_setasync csa;
4621 cam_status status;
4622 int xptpath = 0;
4623

--- 218 unchanged lines hidden ---