cam_periph.h revision 198708
1139743Simp/*- 239212Sgibbs * Data structures and definitions for CAM peripheral ("type") drivers. 339212Sgibbs * 439212Sgibbs * Copyright (c) 1997, 1998 Justin T. Gibbs. 539212Sgibbs * All rights reserved. 639212Sgibbs * 739212Sgibbs * Redistribution and use in source and binary forms, with or without 839212Sgibbs * modification, are permitted provided that the following conditions 939212Sgibbs * are met: 1039212Sgibbs * 1. Redistributions of source code must retain the above copyright 1139212Sgibbs * notice, this list of conditions, and the following disclaimer, 1239212Sgibbs * without modification, immediately at the beginning of the file. 1339212Sgibbs * 2. The name of the author may not be used to endorse or promote products 1439212Sgibbs * derived from this software without specific prior written permission. 1539212Sgibbs * 1639212Sgibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1739212Sgibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1839212Sgibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1939212Sgibbs * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 2039212Sgibbs * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2139212Sgibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2239212Sgibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2339212Sgibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2439212Sgibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2539212Sgibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2639212Sgibbs * SUCH DAMAGE. 2739212Sgibbs * 2850477Speter * $FreeBSD: head/sys/cam/cam_periph.h 198708 2009-10-31 10:43:38Z mav $ 2939212Sgibbs */ 3039212Sgibbs 3139212Sgibbs#ifndef _CAM_CAM_PERIPH_H 3239212Sgibbs#define _CAM_CAM_PERIPH_H 1 3339212Sgibbs 3439212Sgibbs#include <sys/queue.h> 35168876Sscottl#include <cam/cam_sim.h> 3639212Sgibbs 3755206Speter#ifdef _KERNEL 3839212Sgibbs 39111979Sphkstruct devstat; 40111979Sphk 4160168Sn_hibmaextern struct cam_periph *xpt_periph; 4258972Sn_hibma 4372119Speterextern struct periph_driver **periph_drivers; 4472119Spetervoid periphdriver_register(void *); 4539212Sgibbs 4672119Speter#include <sys/module.h> 4772119Speter#define PERIPHDRIVER_DECLARE(name, driver) \ 4872119Speter static int name ## _modevent(module_t mod, int type, void *data) \ 4972119Speter { \ 5072119Speter switch (type) { \ 5172119Speter case MOD_LOAD: \ 5272119Speter periphdriver_register(data); \ 5372119Speter break; \ 5472119Speter case MOD_UNLOAD: \ 5572119Speter printf(#name " module unload - not possible for this module type\n"); \ 5672119Speter return EINVAL; \ 57132199Sphk default: \ 58132199Sphk return EOPNOTSUPP; \ 5972119Speter } \ 6072119Speter return 0; \ 6172119Speter } \ 6272119Speter static moduledata_t name ## _mod = { \ 6372119Speter #name, \ 6472119Speter name ## _modevent, \ 6572119Speter (void *)&driver \ 6672119Speter }; \ 6772119Speter DECLARE_MODULE(name, name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY); \ 6872119Speter MODULE_DEPEND(name, cam, 1, 1, 1) 6972119Speter 7039212Sgibbstypedef void (periph_init_t)(void); /* 7139212Sgibbs * Callback informing the peripheral driver 7239212Sgibbs * it can perform it's initialization since 7339212Sgibbs * the XPT is now fully initialized. 7439212Sgibbs */ 7539212Sgibbstypedef periph_init_t *periph_init_func_t; 7639212Sgibbs 7739212Sgibbsstruct periph_driver { 7839212Sgibbs periph_init_func_t init; 7939212Sgibbs char *driver_name; 8060938Sjake TAILQ_HEAD(,cam_periph) units; 8139212Sgibbs u_int generation; 82198708Smav u_int flags; 83198708Smav#define CAM_PERIPH_DRV_EARLY 0x01 8439212Sgibbs}; 8539212Sgibbs 8639212Sgibbstypedef enum { 87136132Sscottl CAM_PERIPH_BIO 8839212Sgibbs} cam_periph_type; 8939212Sgibbs 9039212Sgibbs/* Generically usefull offsets into the peripheral private area */ 9139212Sgibbs#define ppriv_ptr0 periph_priv.entries[0].ptr 9239212Sgibbs#define ppriv_ptr1 periph_priv.entries[1].ptr 9339212Sgibbs#define ppriv_field0 periph_priv.entries[0].field 9439212Sgibbs#define ppriv_field1 periph_priv.entries[1].field 9539212Sgibbs 9639212Sgibbstypedef void periph_start_t (struct cam_periph *periph, 9739212Sgibbs union ccb *start_ccb); 9839212Sgibbstypedef cam_status periph_ctor_t (struct cam_periph *periph, 9939212Sgibbs void *arg); 10040603Skentypedef void periph_oninv_t (struct cam_periph *periph); 10139212Sgibbstypedef void periph_dtor_t (struct cam_periph *periph); 10239212Sgibbsstruct cam_periph { 10339212Sgibbs cam_pinfo pinfo; 10439212Sgibbs periph_start_t *periph_start; 10540603Sken periph_oninv_t *periph_oninval; 10639212Sgibbs periph_dtor_t *periph_dtor; 10739212Sgibbs char *periph_name; 10839212Sgibbs struct cam_path *path; /* Compiled path to device */ 10939212Sgibbs void *softc; 110168752Sscottl struct cam_sim *sim; 11139212Sgibbs u_int32_t unit_number; 11239212Sgibbs cam_periph_type type; 11339212Sgibbs u_int32_t flags; 11439212Sgibbs#define CAM_PERIPH_RUNNING 0x01 11539212Sgibbs#define CAM_PERIPH_LOCKED 0x02 11639212Sgibbs#define CAM_PERIPH_LOCK_WANTED 0x04 11739212Sgibbs#define CAM_PERIPH_INVALID 0x08 11839212Sgibbs#define CAM_PERIPH_NEW_DEV_FOUND 0x10 11940318Sken#define CAM_PERIPH_RECOVERY_INPROG 0x20 120168752Sscottl#define CAM_PERIPH_POLLED 0x40 12139212Sgibbs u_int32_t immediate_priority; 12239212Sgibbs u_int32_t refcount; 12360938Sjake SLIST_HEAD(, ccb_hdr) ccb_list; /* For "immediate" requests */ 12460938Sjake SLIST_ENTRY(cam_periph) periph_links; 12560938Sjake TAILQ_ENTRY(cam_periph) unit_links; 12639212Sgibbs ac_callback_t *deferred_callback; 12739212Sgibbs ac_code deferred_ac; 12839212Sgibbs}; 12939212Sgibbs 13039212Sgibbs#define CAM_PERIPH_MAXMAPS 2 13139212Sgibbs 13239212Sgibbsstruct cam_periph_map_info { 13339212Sgibbs int num_bufs_used; 13439212Sgibbs struct buf *bp[CAM_PERIPH_MAXMAPS]; 13539212Sgibbs}; 13639212Sgibbs 13740603Skencam_status cam_periph_alloc(periph_ctor_t *periph_ctor, 13840603Sken periph_oninv_t *periph_oninvalidate, 13940603Sken periph_dtor_t *periph_dtor, 14040603Sken periph_start_t *periph_start, 14158111Sn_hibma char *name, cam_periph_type type, struct cam_path *, 14258111Sn_hibma ac_callback_t *, ac_code, void *arg); 14339212Sgibbsstruct cam_periph *cam_periph_find(struct cam_path *path, char *name); 14439212Sgibbscam_status cam_periph_acquire(struct cam_periph *periph); 14539212Sgibbsvoid cam_periph_release(struct cam_periph *periph); 146186319Straszvoid cam_periph_release_locked(struct cam_periph *periph); 147168752Sscottlint cam_periph_hold(struct cam_periph *periph, int priority); 148168752Sscottlvoid cam_periph_unhold(struct cam_periph *periph); 14939212Sgibbsvoid cam_periph_invalidate(struct cam_periph *periph); 15039212Sgibbsint cam_periph_mapmem(union ccb *ccb, 15139212Sgibbs struct cam_periph_map_info *mapinfo); 15239212Sgibbsvoid cam_periph_unmapmem(union ccb *ccb, 15339212Sgibbs struct cam_periph_map_info *mapinfo); 15439212Sgibbsunion ccb *cam_periph_getccb(struct cam_periph *periph, 15539212Sgibbs u_int32_t priority); 15639212Sgibbsvoid cam_periph_ccbwait(union ccb *ccb); 15739212Sgibbsint cam_periph_runccb(union ccb *ccb, 15839212Sgibbs int (*error_routine)(union ccb *ccb, 15939212Sgibbs cam_flags camflags, 16039212Sgibbs u_int32_t sense_flags), 16139212Sgibbs cam_flags camflags, u_int32_t sense_flags, 16239212Sgibbs struct devstat *ds); 163194627Sscottlint cam_periph_ioctl(struct cam_periph *periph, u_long cmd, 16439212Sgibbs caddr_t addr, 16539212Sgibbs int (*error_routine)(union ccb *ccb, 16639212Sgibbs cam_flags camflags, 16739212Sgibbs u_int32_t sense_flags)); 16847412Sgibbsvoid cam_freeze_devq(struct cam_path *path); 16939212Sgibbsu_int32_t cam_release_devq(struct cam_path *path, u_int32_t relsim_flags, 17039212Sgibbs u_int32_t opening_reduction, u_int32_t timeout, 17139212Sgibbs int getcount_only); 17247412Sgibbsvoid cam_periph_async(struct cam_periph *periph, u_int32_t code, 17347412Sgibbs struct cam_path *path, void *arg); 17447412Sgibbsvoid cam_periph_bus_settle(struct cam_periph *periph, 17547412Sgibbs u_int bus_settle_ms); 17647412Sgibbsvoid cam_periph_freeze_after_event(struct cam_periph *periph, 17747412Sgibbs struct timeval* event_time, 17847412Sgibbs u_int duration_ms); 17939212Sgibbsint cam_periph_error(union ccb *ccb, cam_flags camflags, 18039212Sgibbs u_int32_t sense_flags, union ccb *save_ccb); 18139212Sgibbs 182168876Sscottlstatic __inline void 183168876Sscottlcam_periph_lock(struct cam_periph *periph) 184168876Sscottl{ 185168876Sscottl mtx_lock(periph->sim->mtx); 186168876Sscottl} 187168876Sscottl 188168876Sscottlstatic __inline void 189168876Sscottlcam_periph_unlock(struct cam_periph *periph) 190168876Sscottl{ 191168876Sscottl mtx_unlock(periph->sim->mtx); 192168876Sscottl} 193168876Sscottl 19455206Speter#endif /* _KERNEL */ 19539212Sgibbs#endif /* _CAM_CAM_PERIPH_H */ 196