Home | History | Annotate | Line # | Download | only in ic
icpvar.h revision 1.12.12.1
      1  1.12.12.1      yamt /*	$NetBSD: icpvar.h,v 1.12.12.1 2012/10/30 17:21:04 yamt Exp $	*/
      2        1.1        ad 
      3        1.1        ad /*-
      4        1.2   thorpej  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
      5        1.1        ad  * All rights reserved.
      6        1.1        ad  *
      7        1.1        ad  * This code is derived from software contributed to The NetBSD Foundation
      8        1.2   thorpej  * by Andrew Doran, and by Jason R. Thorpe of Wasabi Systems, Inc.
      9        1.1        ad  *
     10        1.1        ad  * Redistribution and use in source and binary forms, with or without
     11        1.1        ad  * modification, are permitted provided that the following conditions
     12        1.1        ad  * are met:
     13        1.1        ad  * 1. Redistributions of source code must retain the above copyright
     14        1.1        ad  *    notice, this list of conditions and the following disclaimer.
     15        1.1        ad  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1        ad  *    notice, this list of conditions and the following disclaimer in the
     17        1.1        ad  *    documentation and/or other materials provided with the distribution.
     18        1.1        ad  *
     19        1.1        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1        ad  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1        ad  */
     31        1.1        ad 
     32        1.1        ad #ifndef _IC_ICPVAR_H_
     33        1.1        ad #define _IC_ICPVAR_H_
     34        1.1        ad 
     35        1.9        ad #include <sys/mutex.h>
     36        1.9        ad 
     37        1.2   thorpej #include <dev/ic/icp_ioctl.h>
     38        1.2   thorpej 
     39        1.1        ad /*
     40        1.1        ad  * Miscellaneous constants.
     41        1.1        ad  */
     42        1.1        ad #define ICP_RETRIES		6
     43        1.1        ad #define	ICP_WATCHDOG_FREQ	5
     44        1.1        ad #define	ICP_BUSY_WAIT_MS	2500
     45        1.6     perry #define	ICP_MAX_XFER		65536
     46        1.2   thorpej #define	ICP_UCMD_SCRATCH_SIZE	4096
     47        1.2   thorpej #define ICP_SCRATCH_SIZE	(8192 + ICP_UCMD_SCRATCH_SIZE)
     48        1.1        ad #define	ICP_SCRATCH_SENSE \
     49       1.11    bouyer     (ICP_SCRATCH_SIZE - sizeof(struct scsi_sense_data) * (ICP_NCCBS + ICP_NCCB_RESERVE))
     50        1.2   thorpej #define	ICP_SCRATCH_UCMD	(ICP_SCRATCH_SENSE - ICP_UCMD_SCRATCH_SIZE)
     51        1.1        ad 
     52        1.1        ad #define	ICP_NCCBS		ICP_MAX_CMDS
     53        1.1        ad #define	ICP_NCCB_RESERVE	4
     54        1.1        ad 
     55        1.1        ad /*
     56        1.1        ad  * Context structure for interrupt service.
     57        1.1        ad  */
     58        1.1        ad struct icp_intr_ctx {
     59        1.1        ad 	u_int32_t	info;
     60        1.1        ad 	u_int32_t	info2;
     61        1.1        ad 	u_int16_t	cmd_status;
     62        1.1        ad 	u_int16_t	service;
     63        1.1        ad 	u_int8_t	istatus;
     64        1.1        ad };
     65        1.1        ad 
     66        1.1        ad /*
     67        1.1        ad  * Command control block.
     68        1.1        ad  */
     69        1.1        ad struct icp_ccb {
     70        1.1        ad 	SIMPLEQ_ENTRY(icp_ccb) ic_chain;
     71        1.1        ad 	u_int		ic_service;
     72        1.1        ad 	u_int		ic_flags;
     73        1.1        ad 	u_int		ic_status;
     74        1.1        ad 	u_int		ic_ident;
     75        1.1        ad 	u_int		ic_nsgent;
     76        1.1        ad 	u_int		ic_cmdlen;
     77        1.1        ad 	u_int		ic_xfer_size;
     78        1.1        ad 	bus_dmamap_t	ic_xfer_map;
     79        1.1        ad 	struct icp_sg	*ic_sg;
     80  1.12.12.1      yamt 	device_t	ic_dv;
     81        1.1        ad 	void		*ic_context;
     82        1.1        ad 	void		(*ic_intr)(struct icp_ccb *);
     83        1.1        ad 	struct icp_cmd	ic_cmd;
     84        1.1        ad };
     85        1.1        ad #define	IC_XFER_IN	0x01	/* Map describes inbound xfer */
     86        1.1        ad #define	IC_XFER_OUT	0x02	/* Map describes outbound xfer */
     87        1.1        ad #define	IC_WAITING	0x04	/* We have waiters */
     88        1.1        ad #define	IC_COMPLETE	0x08	/* Command completed */
     89        1.1        ad #define	IC_ALLOCED	0x10	/* CCB allocated */
     90        1.2   thorpej #define	IC_UCMD		0x20	/* user ioctl */
     91        1.1        ad 
     92        1.1        ad /*
     93        1.1        ad  * Logical drive information.
     94        1.1        ad  */
     95        1.1        ad struct icp_cachedrv {
     96        1.1        ad 	u_int		cd_size;
     97        1.1        ad 	u_int		cd_type;
     98        1.1        ad };
     99        1.1        ad 
    100        1.1        ad /*
    101        1.3   thorpej  * Call-backs into the service back-ends (ld for cache service,
    102        1.3   thorpej  * icpsp for raw service).
    103        1.3   thorpej  */
    104        1.3   thorpej struct icp_servicecb {
    105       1.12    cegger 	void	(*iscb_openings)(device_t, int);
    106        1.3   thorpej };
    107        1.3   thorpej 
    108        1.3   thorpej /*
    109        1.1        ad  * Per-controller context.
    110        1.1        ad  */
    111        1.1        ad struct icp_softc {
    112  1.12.12.1      yamt 	device_t		icp_dv;
    113        1.1        ad 	void			*icp_ih;
    114        1.1        ad 	bus_dma_tag_t		icp_dmat;
    115        1.1        ad 	bus_space_tag_t		icp_dpmemt;
    116        1.1        ad 	bus_space_handle_t	icp_dpmemh;
    117        1.1        ad 	bus_addr_t		icp_dpmembase;
    118        1.1        ad 	bus_space_tag_t		icp_iot;
    119        1.1        ad 	bus_space_handle_t	icp_ioh;
    120        1.1        ad 	bus_addr_t		icp_iobase;
    121        1.1        ad 
    122        1.1        ad 	int			icp_class;
    123        1.2   thorpej 	u_int16_t		icp_fw_vers;
    124        1.1        ad 	u_int16_t		icp_ic_all_size;
    125        1.1        ad 	u_int8_t		icp_bus_cnt;
    126        1.1        ad 	u_int8_t		icp_bus_id[ICP_MAXBUS];
    127        1.1        ad 	struct icp_cachedrv	icp_cdr[ICP_MAX_HDRIVES];
    128        1.3   thorpej 	const struct icp_servicecb *icp_servicecb[ICP_MAX_HDRIVES + ICP_MAXBUS];
    129  1.12.12.1      yamt 	device_t		icp_children[ICP_MAX_HDRIVES + ICP_MAXBUS];
    130        1.1        ad 	int			icp_ndevs;
    131        1.1        ad 	int			icp_openings;
    132        1.3   thorpej 	int			icp_features;
    133        1.3   thorpej 	int			icp_nchan;
    134        1.1        ad 
    135        1.1        ad 	u_int32_t		icp_info;
    136        1.1        ad 	u_int32_t		icp_info2;
    137        1.1        ad 	u_int16_t		icp_status;
    138        1.2   thorpej 	u_int16_t		icp_service;
    139        1.1        ad 
    140        1.1        ad 	bus_dmamap_t		icp_scr_dmamap;
    141        1.1        ad 	bus_dma_segment_t	icp_scr_seg[1];
    142        1.8  christos 	void *			icp_scr;
    143        1.1        ad 
    144        1.1        ad 	struct icp_ccb		*icp_ccbs;
    145        1.1        ad 	u_int			icp_nccbs;
    146        1.2   thorpej 	u_int			icp_flags;
    147        1.3   thorpej 	u_int			icp_qfreeze;
    148        1.3   thorpej 	u_int			icp_running;
    149        1.1        ad 	SIMPLEQ_HEAD(,icp_ccb)	icp_ccb_freelist;
    150        1.1        ad 	SIMPLEQ_HEAD(,icp_ccb)	icp_ccb_queue;
    151        1.2   thorpej 	SIMPLEQ_HEAD(,icp_ccb)	icp_ucmd_queue;
    152        1.1        ad 	struct callout		icp_wdog_callout;
    153        1.1        ad 
    154        1.2   thorpej 	struct icp_ccb		*icp_ucmd_ccb;
    155        1.2   thorpej 
    156        1.2   thorpej 	/* Temporary buffer for event data. */
    157        1.2   thorpej 	gdt_evt_data		icp_evt;
    158        1.2   thorpej 
    159        1.1        ad 	void		(*icp_copy_cmd)(struct icp_softc *, struct icp_ccb *);
    160        1.1        ad 	u_int8_t	(*icp_get_status)(struct icp_softc *);
    161        1.1        ad 	void		(*icp_intr)(struct icp_softc *, struct icp_intr_ctx *);
    162        1.1        ad 	void		(*icp_release_event)(struct icp_softc *,
    163        1.1        ad 					     struct icp_ccb *);
    164        1.1        ad 	void		(*icp_set_sema0)(struct icp_softc *);
    165        1.1        ad 	int		(*icp_test_busy)(struct icp_softc *);
    166        1.2   thorpej 
    167        1.2   thorpej 	/*
    168        1.2   thorpej 	 * This info is needed by the user ioctl interface needed to
    169        1.2   thorpej 	 * support the ICP configuration tools.
    170        1.2   thorpej 	 */
    171        1.2   thorpej 	int			icp_pci_bus;
    172        1.2   thorpej 	int			icp_pci_device;
    173        1.2   thorpej 	int			icp_pci_device_id;
    174        1.2   thorpej 	int			icp_pci_subdevice_id;
    175        1.1        ad };
    176        1.1        ad 
    177        1.3   thorpej /* icp_features */
    178        1.3   thorpej #define	ICP_FEAT_CACHESERVICE	0x01	/* cache service usable */
    179        1.3   thorpej #define	ICP_FEAT_RAWSERVICE	0x02	/* raw service usable */
    180        1.3   thorpej 
    181        1.2   thorpej /* icp_flags */
    182        1.2   thorpej #define	ICP_F_WAIT_CCB		0x01	/* someone waiting for CCBs */
    183        1.3   thorpej #define	ICP_F_WAIT_FREEZE	0x02	/* someone waiting for qfreeze */
    184        1.2   thorpej 
    185        1.2   thorpej #define	ICP_HAS_WORK(icp)						\
    186        1.2   thorpej 	(! SIMPLEQ_EMPTY(&(icp)->icp_ccb_queue) ||			\
    187        1.2   thorpej 	 ! SIMPLEQ_EMPTY(&(icp)->icp_ucmd_queue))
    188        1.2   thorpej 
    189        1.2   thorpej #define	ICP_STAT_INCR(icp, x)						\
    190        1.2   thorpej do {									\
    191        1.2   thorpej 	/* XXX Globals, for now. XXX */					\
    192        1.2   thorpej 	icp_stats. ## x ## _act++;					\
    193        1.2   thorpej 	if (icp_stats. ## x ## _act > icp_stats. ## x ## _max)		\
    194        1.2   thorpej 		icp_stats. ## x ## _max = icp_stats. ## x ## _act;	\
    195        1.2   thorpej } while (/*CONSTCOND*/0)
    196        1.2   thorpej 
    197        1.2   thorpej #define	ICP_STAT_SET(icp, x, v)						\
    198        1.2   thorpej do {									\
    199        1.2   thorpej 	/* XXX Globals, for now. XXX */					\
    200        1.2   thorpej 	icp_stats. ## x ## _act = (v);					\
    201        1.2   thorpej 	if (icp_stats. ## x ## _act > icp_stats. ## x ## _max)		\
    202        1.2   thorpej 		icp_stats. ## x ## _max = icp_stats. ## x ## _act;	\
    203        1.2   thorpej } while (/*CONSTCOND*/0)
    204        1.2   thorpej 
    205        1.2   thorpej #define	ICP_STAT_DECR(icp, x)						\
    206        1.2   thorpej do {									\
    207        1.2   thorpej 	/* XXX Globals, for now. XXX */					\
    208        1.2   thorpej 	icp_stats. ## x ## _act--;					\
    209        1.2   thorpej } while (/*CONSTCOND*/0)
    210        1.2   thorpej 
    211        1.1        ad #define ICP_ISA		0x01
    212        1.1        ad #define ICP_EISA	0x02
    213        1.1        ad #define ICP_PCI		0x03
    214        1.1        ad #define ICP_PCINEW	0x04
    215        1.1        ad #define ICP_MPR		0x05
    216        1.1        ad #define ICP_CLASS_MASK	0x07
    217        1.1        ad #define ICP_FC		0x10
    218        1.1        ad #define ICP_CLASS(icp)	((icp)->icp_class & ICP_CLASS_MASK)
    219        1.1        ad 
    220        1.1        ad int	icp_init(struct icp_softc *, const char *);
    221        1.1        ad int	icp_intr(void *);
    222        1.1        ad 
    223        1.2   thorpej extern int icp_count;
    224        1.2   thorpej extern gdt_statist_t icp_stats;
    225        1.2   thorpej 
    226        1.1        ad /*
    227        1.1        ad  * Consumer interface.
    228        1.1        ad  */
    229        1.1        ad struct icp_attach_args {
    230        1.1        ad 	int		icpa_unit;
    231        1.1        ad };
    232        1.1        ad 
    233        1.1        ad #define	ICPA_UNIT_SCSI	100
    234        1.1        ad 
    235        1.1        ad struct icp_ccb	*icp_ccb_alloc(struct icp_softc *);
    236        1.2   thorpej struct icp_ccb	*icp_ccb_alloc_wait(struct icp_softc *);
    237        1.1        ad void	icp_ccb_enqueue(struct icp_softc *, struct icp_ccb *);
    238        1.1        ad void	icp_ccb_free(struct icp_softc *, struct icp_ccb *);
    239        1.1        ad int	icp_ccb_map(struct icp_softc *, struct icp_ccb *, void *, int, int);
    240        1.1        ad int	icp_ccb_poll(struct icp_softc *, struct icp_ccb *, int);
    241        1.1        ad void	icp_ccb_unmap(struct icp_softc *, struct icp_ccb *);
    242        1.1        ad int	icp_ccb_wait(struct icp_softc *, struct icp_ccb *, int);
    243        1.2   thorpej int	icp_ccb_wait_user(struct icp_softc *, struct icp_ccb *, int);
    244        1.1        ad int	icp_cmd(struct icp_softc *, u_int8_t, u_int16_t, u_int32_t, u_int32_t,
    245        1.1        ad 		u_int32_t);
    246        1.2   thorpej int	icp_ucmd(struct icp_softc *, gdt_ucmd_t *);
    247        1.3   thorpej int	icp_freeze(struct icp_softc *);
    248        1.3   thorpej void	icp_unfreeze(struct icp_softc *);
    249        1.3   thorpej 
    250        1.3   thorpej void	icp_rescan(struct icp_softc *, int);
    251        1.3   thorpej void	icp_rescan_all(struct icp_softc *);
    252        1.3   thorpej 
    253        1.3   thorpej void	icp_register_servicecb(struct icp_softc *, int,
    254        1.3   thorpej 	    const struct icp_servicecb *);
    255        1.2   thorpej 
    256        1.2   thorpej gdt_evt_str *icp_store_event(struct icp_softc *, u_int16_t, u_int16_t,
    257        1.2   thorpej 	    gdt_evt_data *);
    258        1.2   thorpej int	icp_read_event(struct icp_softc *, int, gdt_evt_str *);
    259        1.2   thorpej void	icp_readapp_event(struct icp_softc *, u_int8_t, gdt_evt_str *);
    260        1.2   thorpej void	icp_clear_events(struct icp_softc *);
    261        1.1        ad 
    262        1.9        ad extern kmutex_t icp_ioctl_mutex;
    263        1.9        ad 
    264        1.1        ad #endif	/* !_IC_ICPVAR_H_ */
    265