cam_xpt.c

来自「基于组件方式开发操作系统的OSKIT源代码」· C语言 代码 · 共 2,349 行 · 第 1/5 页

C
2,349 行
字号
		CAM_QUIRK_NOSERIAL, /*mintags*/0, /*maxtags*/0	},	{		/*		 * Would repond to all LUNs if asked for.		 */		{			T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER",			"CP150", "*"		},		CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0	},	{		/*		 * Would repond to all LUNs if asked for.		 */		{			T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY",			"96X2*", "*"		},		CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0	},	{		/* Default tagged queuing parameters for all devices */		{		  T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,		  /*vendor*/"*", /*product*/"*", /*revision*/"*"		},		/*quirks*/0, /*mintags*/2, /*maxtags*/255	},};typedef enum {	DM_RET_COPY		= 0x01,	DM_RET_FLAG_MASK	= 0x0f,	DM_RET_NONE		= 0x00,	DM_RET_STOP		= 0x10,	DM_RET_DESCEND		= 0x20,	DM_RET_ERROR		= 0x30,	DM_RET_ACTION_MASK	= 0xf0} dev_match_ret;typedef enum {	XPT_DEPTH_BUS,	XPT_DEPTH_TARGET,	XPT_DEPTH_DEVICE,	XPT_DEPTH_PERIPH} xpt_traverse_depth;struct xpt_traverse_config {	xpt_traverse_depth	depth;	void			*tr_func;	void			*tr_arg;};typedef	int	xpt_busfunc_t (struct cam_eb *bus, void *arg);typedef	int	xpt_targetfunc_t (struct cam_et *target, void *arg);typedef	int	xpt_devicefunc_t (struct cam_ed *device, void *arg);typedef	int	xpt_periphfunc_t (struct cam_periph *periph, void *arg);typedef int	xpt_pdrvfunc_t (struct periph_driver **pdrv, void *arg);/* Transport layer configuration information */static struct xpt_softc xsoftc;/* Queues for our software interrupt handler */typedef TAILQ_HEAD(cam_isrq, ccb_hdr) cam_isrq_t;static cam_isrq_t cam_bioq;static cam_isrq_t cam_netq;/* "Pool" of inactive ccbs managed by xpt_alloc_ccb and xpt_free_ccb */static SLIST_HEAD(,ccb_hdr) ccb_freeq;static u_int xpt_max_ccbs;	/*				 * Maximum size of ccb pool.  Modified as				 * devices are added/removed or have their				 * opening counts changed.				 */static u_int xpt_ccb_count;	/* Current count of allocated ccbs */static struct cam_periph *xpt_periph;static periph_init_t xpt_periph_init;static periph_init_t probe_periph_init;static struct periph_driver xpt_driver ={	xpt_periph_init, "xpt",	TAILQ_HEAD_INITIALIZER(xpt_driver.units)};static struct periph_driver probe_driver ={	probe_periph_init, "probe",	TAILQ_HEAD_INITIALIZER(probe_driver.units)};DATA_SET(periphdriver_set, xpt_driver);DATA_SET(periphdriver_set, probe_driver);#define XPT_CDEV_MAJOR 104static d_open_t xptopen;static d_close_t xptclose;static d_ioctl_t xptioctl;static struct cdevsw xpt_cdevsw = {	/*d_open*/	xptopen,	/*d_close*/	xptclose,	/*d_read*/	noread,	/*d_write*/	nowrite,	/*d_ioctl*/	xptioctl,	/*d_stop*/	nostop,	/*d_reset*/	noreset,	/*d_devtotty*/	nodevtotty,	/*d_poll*/	NULL,	/*d_mmap*/	nommap,	/*d_strategy*/	nostrategy,	/*d_name*/	"xpt",	/*d_spare*/	NULL,	/*d_maj*/	-1,	/*d_dump*/	nodump,	/*d_psize*/	nopsize,	/*d_flags*/	0,	/*d_maxio*/	0,	/*b_maj*/	-1};static struct intr_config_hook *xpt_config_hook;/* Registered busses */static TAILQ_HEAD(,cam_eb) xpt_busses;static u_int bus_generation;/* Storage for debugging datastructures */#ifdef	CAMDEBUGstruct cam_path *cam_dpath;u_int32_t cam_dflags;#endif#if defined(CAM_DEBUG_FLAGS) && !defined(CAMDEBUG)#error "You must have options CAMDEBUG to use options CAM_DEBUG_FLAGS"#endif/* * In order to enable the CAM_DEBUG_* options, the user must have CAMDEBUG * enabled.  Also, the user must have either none, or all of CAM_DEBUG_BUS, * CAM_DEBUG_TARGET, and CAM_DEBUG_LUN specified. */#if defined(CAM_DEBUG_BUS) || defined(CAM_DEBUG_TARGET) \    || defined(CAM_DEBUG_LUN)#ifdef CAMDEBUG#if !defined(CAM_DEBUG_BUS) || !defined(CAM_DEBUG_TARGET) \    || !defined(CAM_DEBUG_LUN)#error "You must define all or none of CAM_DEBUG_BUS, CAM_DEBUG_TARGET \        and CAM_DEBUG_LUN"#endif /* !CAM_DEBUG_BUS || !CAM_DEBUG_TARGET || !CAM_DEBUG_LUN */#else /* !CAMDEBUG */#error "You must use options CAMDEBUG if you use the CAM_DEBUG_* options"#endif /* CAMDEBUG */#endif /* CAM_DEBUG_BUS || CAM_DEBUG_TARGET || CAM_DEBUG_LUN *//* Our boot-time initialization hook */static void	xpt_init(void *);SYSINIT(cam, SI_SUB_CONFIGURE, SI_ORDER_SECOND, xpt_init, NULL);static cam_status	xpt_compile_path(struct cam_path *new_path,					 struct cam_periph *perph,					 path_id_t path_id,					 target_id_t target_id,					 lun_id_t lun_id);static void		xpt_release_path(struct cam_path *path);static void		xpt_async_bcast(struct async_list *async_head,					u_int32_t async_code,					struct cam_path *path,					void *async_arg);static int 	 xptnextfreebus(path_id_t startbus);static int	 xptpathid(const char *sim_name, int sim_unit, int sim_bus,			   path_id_t *nextpath);static union ccb *xpt_get_ccb(struct cam_ed *device);static int	 xpt_schedule_dev(struct camq *queue, cam_pinfo *dev_pinfo,				  u_int32_t new_priority);static void	 xpt_run_dev_allocq(struct cam_eb *bus);static void	 xpt_run_dev_sendq(struct cam_eb *bus);static timeout_t xpt_release_devq_timeout;static timeout_t xpt_release_simq_timeout;static void	 xpt_release_bus(struct cam_eb *bus);static struct cam_et*		 xpt_alloc_target(struct cam_eb *bus, target_id_t target_id);static void	 xpt_release_target(struct cam_eb *bus, struct cam_et *target);static struct cam_ed*		 xpt_alloc_device(struct cam_eb *bus, struct cam_et *target,				  lun_id_t lun_id);static void	 xpt_release_device(struct cam_eb *bus, struct cam_et *target,				    struct cam_ed *device);static u_int32_t xpt_dev_ccbq_resize(struct cam_path *path, int newopenings);static struct cam_eb*		 xpt_find_bus(path_id_t path_id);static struct cam_et*		 xpt_find_target(struct cam_eb *bus, target_id_t target_id);static struct cam_ed*		 xpt_find_device(struct cam_et *target, lun_id_t lun_id);static void	 xpt_scan_bus(struct cam_periph *periph, union ccb *ccb);static void	 xpt_scan_lun(struct cam_periph *periph,			      struct cam_path *path, cam_flags flags,			      union ccb *ccb);static void	 xptscandone(struct cam_periph *periph, union ccb *done_ccb);static xpt_busfunc_t	xptconfigbuscountfunc;static xpt_busfunc_t	xptconfigfunc;static void	 xpt_config(void *arg);static xpt_devicefunc_t xptpassannouncefunc;static void	 xpt_finishconfig(struct cam_periph *periph, union ccb *ccb);static void	 xptaction(struct cam_sim *sim, union ccb *work_ccb);static swihand_t swi_camnet;static swihand_t swi_cambio;static void	 camisr(cam_isrq_t *queue);#if 0static void	 xptstart(struct cam_periph *periph, union ccb *work_ccb);static void	 xptasync(struct cam_periph *periph,			  u_int32_t code, cam_path *path);#endifstatic dev_match_ret	xptbusmatch(struct dev_match_pattern *patterns,				    int num_patterns, struct cam_eb *bus);static dev_match_ret	xptdevicematch(struct dev_match_pattern *patterns,				       int num_patterns, struct cam_ed *device);static dev_match_ret	xptperiphmatch(struct dev_match_pattern *patterns,				       int num_patterns,				       struct cam_periph *periph);static xpt_busfunc_t	xptedtbusfunc;static xpt_targetfunc_t	xptedttargetfunc;static xpt_devicefunc_t	xptedtdevicefunc;static xpt_periphfunc_t	xptedtperiphfunc;static xpt_pdrvfunc_t	xptplistpdrvfunc;static xpt_periphfunc_t	xptplistperiphfunc;static int		xptedtmatch(struct ccb_dev_match *cdm);static int		xptperiphlistmatch(struct ccb_dev_match *cdm);static int		xptbustraverse(struct cam_eb *start_bus,				       xpt_busfunc_t *tr_func, void *arg);static int		xpttargettraverse(struct cam_eb *bus,					  struct cam_et *start_target,					  xpt_targetfunc_t *tr_func, void *arg);static int		xptdevicetraverse(struct cam_et *target,					  struct cam_ed *start_device,					  xpt_devicefunc_t *tr_func, void *arg);static int		xptperiphtraverse(struct cam_ed *device,					  struct cam_periph *start_periph,					  xpt_periphfunc_t *tr_func, void *arg);static int		xptpdrvtraverse(struct periph_driver **start_pdrv,					xpt_pdrvfunc_t *tr_func, void *arg);static int		xptpdperiphtraverse(struct periph_driver **pdrv,					    struct cam_periph *start_periph,					    xpt_periphfunc_t *tr_func,					    void *arg);static xpt_busfunc_t	xptdefbusfunc;static xpt_targetfunc_t	xptdeftargetfunc;static xpt_devicefunc_t	xptdefdevicefunc;static xpt_periphfunc_t	xptdefperiphfunc;static int		xpt_for_all_busses(xpt_busfunc_t *tr_func, void *arg);#ifdef notusedyetstatic int		xpt_for_all_targets(xpt_targetfunc_t *tr_func,					    void *arg);#endifstatic int		xpt_for_all_devices(xpt_devicefunc_t *tr_func,					    void *arg);#ifdef notusedyetstatic int		xpt_for_all_periphs(xpt_periphfunc_t *tr_func,					    void *arg);#endifstatic xpt_devicefunc_t	xptsetasyncfunc;static xpt_busfunc_t	xptsetasyncbusfunc;static cam_status	xptregister(struct cam_periph *periph,				    void *arg);static cam_status	proberegister(struct cam_periph *periph,				      void *arg);static void	 probeschedule(struct cam_periph *probe_periph);static void	 probestart(struct cam_periph *periph, union ccb *start_ccb);static void	 probedone(struct cam_periph *periph, union ccb *done_ccb);static void	 probecleanup(struct cam_periph *periph);static void	 xpt_find_quirk(struct cam_ed *device);static void	 xpt_set_transfer_settings(struct ccb_trans_settings *cts,					   struct cam_ed *device,					   int async_update);static void	 xpt_toggle_tags(struct cam_path *path);static void	 xpt_start_tags(struct cam_path *path);static __inline int xpt_schedule_dev_allocq(struct cam_eb *bus,					    struct cam_ed *dev);static __inline int xpt_schedule_dev_sendq(struct cam_eb *bus,					   struct cam_ed *dev);static __inline int periph_is_queued(struct cam_periph *periph);static __inline int device_is_alloc_queued(struct cam_ed *device);static __inline int device_is_send_queued(struct cam_ed *device);static __inline int dev_allocq_is_runnable(struct cam_devq *devq);static __inline intxpt_schedule_dev_allocq(struct cam_eb *bus, struct cam_ed *dev){	int retval;	if (dev->ccbq.devq_openings > 0) {		if ((dev->flags & CAM_DEV_RESIZE_QUEUE_NEEDED) != 0) {			cam_ccbq_resize(&dev->ccbq,					dev->ccbq.dev_openings					+ dev->ccbq.dev_active);			dev->flags &= ~CAM_DEV_RESIZE_QUEUE_NEEDED;		}		/*		 * The priority of a device waiting for CCB resources		 * is that of the the highest priority peripheral driver		 * enqueued.		 */		retval = xpt_schedule_dev(&bus->sim->devq->alloc_queue,					  &dev->alloc_ccb_entry.pinfo,					  CAMQ_GET_HEAD(&dev->drvq)->priority);		} else {		retval = 0;	}	return (retval);}static __inline intxpt_schedule_dev_sendq(struct cam_eb *bus, struct cam_ed *dev){	int	retval;	if (dev->ccbq.dev_openings > 0) {		/*		 * The priority of a device waiting for controller		 * resources is that of the the highest priority CCB		 * enqueued.		 */		retval =		    xpt_schedule_dev(&bus->sim->devq->send_queue,				     &dev->send_ccb_entry.pinfo,				     CAMQ_GET_HEAD(&dev->ccbq.queue)->priority);	} else {		retval = 0;	}	return (retval);}static __inline intperiph_is_queued(struct cam_periph *periph){	return (periph->pinfo.index != CAM_UNQUEUED_INDEX);}static __inline intdevice_is_alloc_queued(struct cam_ed *device){	return (device->alloc_ccb_entry.pinfo.index != CAM_UNQUEUED_INDEX);}static __inline intdevice_is_send_queued(struct cam_ed *device){	return (device->send_ccb_entry.pinfo.index != CAM_UNQUEUED_INDEX);}static __inline intdev_allocq_is_runnable(struct cam_devq *devq){	/*	 * Have work to do.	 * Have space to do more work.	 * Allowed to do work.	 */	return ((devq->alloc_queue.qfrozen_cnt == 0)	     && (devq->alloc_queue.entries > 0)	     && (devq->alloc_openings > 0));}static voidxpt_periph_init(){	dev_t dev;	dev = makedev(XPT_CDEV_MAJOR, 0);	cdevsw_add(&dev, &xpt_cdevsw, NULL);}static voidprobe_periph_init(){}static voidxptdone(struct cam_periph *periph, union ccb *done_ccb){	/* Caller will release the CCB */	wakeup(&done_ccb->ccb_h.cbfcnp);}static intxptopen(dev_t dev, int flags, int fmt, struct proc *p){	int unit;	unit = minor(dev) & 0xff;	/*	 * Only allow read-write access.	 */	if (((flags & FWRITE) == 0) || ((flags & FREAD) == 0))		return(EPERM);	/*	 * We don't allow nonblocking access.	 */	if ((flags & O_NONBLOCK) != 0) {		printf("xpt%d: can't do nonblocking accesss\n", unit);		return(ENODEV);	}	/*	 * We only have one transport layer right now.  If someone accesses	 * us via something other than minor number 1, point out their	 * mistake.	 */	if (unit != 0) {		printf("xptopen: got invalid xpt unit %d\n", unit);		return(ENXIO);	}	/* Mark ourselves open */	xsoftc.flags |= XPT_FLAG_OPEN;		return(0);}static intxptclose(dev_t dev, int flag, int fmt, struct proc *p){	int unit;	unit = minor(dev) & 0xff;	/*	 * We only have one transport layer right now.  If someone accesses	 * us via something other than minor number 1, point out their	 * mistake.	 */	if (unit != 0) {		printf("xptclose: got invalid xpt unit %d\n", unit);		return(ENXIO);	}	/* Mark ourselves closed */	xsoftc.flags &= ~XPT_FLAG_OPEN;	return(0);}static intxptioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p){	int unit, error;	error = 0;	unit = minor(dev) & 0xff;	/*	 * We only have one transport layer right now.  If someone accesses	 * us via something other than minor number 1, point out their	 * mistake.	 */	if (unit != 0) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?