Home | History | Annotate | Line # | Download | only in maple
maplevar.h revision 1.5
      1 /*	$NetBSD: maplevar.h,v 1.5 2002/11/15 13:30:21 itohy Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by ITOH Yasufumi.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*-
     40  * Copyright (c) 2001 Marcus Comstedt
     41  * All rights reserved.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  * 3. All advertising materials mentioning features or use of this software
     52  *    must display the following acknowledgement:
     53  *	This product includes software developed by Marcus Comstedt.
     54  * 4. Neither the name of The NetBSD Foundation nor the names of its
     55  *    contributors may be used to endorse or promote products derived
     56  *    from this software without specific prior written permission.
     57  *
     58  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     59  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     60  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     61  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     62  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     63  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     64  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     65  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     66  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     67  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     68  * POSSIBILITY OF SUCH DAMAGE.
     69  */
     70 
     71 #include <sys/queue.h>
     72 
     73 #define MAPLE_PORTS 4
     74 #define MAPLE_SUBUNITS 6
     75 
     76 #define MAPLE_NFUNC	32
     77 
     78 struct maple_func {
     79 	int		f_funcno;
     80 	struct maple_unit *f_unit;
     81 	struct device	*f_dev;
     82 
     83 	/* callback */
     84 	void		(*f_callback)(void *, struct maple_response *,
     85 			    int /*len*/, int /*flags*/);
     86 	void 		*f_arg;
     87 
     88 	u_int32_t	f_work;		/* for periodic GETCOND and ping */
     89 
     90 	/* periodic command request */
     91 	enum maple_periodic_stat {
     92 		MAPLE_PERIODIC_NONE,
     93 		MAPLE_PERIODIC_INQ,
     94 		MAPLE_PERIODIC_DEFERED
     95 	} f_periodic_stat;
     96 	TAILQ_ENTRY(maple_func)	f_periodicq;
     97 
     98 	/* command request */
     99 	int		f_command;
    100 	int		f_datalen;
    101 	void		*f_dataaddr;
    102 	enum maple_command_stat {
    103 		MAPLE_CMDSTAT_NONE,		/* not in queue */
    104 		MAPLE_CMDSTAT_ASYNC,		/* process immediately */
    105 		MAPLE_CMDSTAT_PERIODIC_DEFERED,	/* periodic but process imdtly*/
    106 		MAPLE_CMDSTAT_ASYNC_PERIODICQ,	/* async but on periodic queue*/
    107 		MAPLE_CMDSTAT_PERIODIC		/* process on periodic timing */
    108 	} f_cmdstat;
    109 	TAILQ_ENTRY(maple_func)	f_cmdq;
    110 };
    111 
    112 struct maple_unit {
    113 	int		port, subunit;
    114 	struct maple_func u_func[MAPLE_NFUNC];
    115 	u_int32_t	getcond_func_set;
    116 	int		u_ping_func;	/* function used for ping */
    117 	u_int32_t	u_noping;	/* stop ping (bitmap of function) */
    118 	struct maple_devinfo devinfo;
    119 
    120 	/* DMA status / function */
    121 	enum maple_dma_stat {
    122 		MAPLE_DMA_IDLE,		/* not in queue */
    123 		MAPLE_DMA_RETRY,	/* retrying last command (sc_retryq) */
    124 		MAPLE_DMA_PERIODIC,	/* periodic GETCOND */
    125 		MAPLE_DMA_ACMD,		/* asynchronous command */
    126 		MAPLE_DMA_PCMD,		/* command on periodic timing */
    127 		MAPLE_DMA_PROBE,	/* checking for insertion */
    128 		MAPLE_DMA_PING		/* checking for removal */
    129 	} u_dma_stat;
    130 	int	u_dma_func;
    131 
    132 	SIMPLEQ_ENTRY(maple_unit)	u_dmaq;
    133 
    134 	/* start of each receive buffer */
    135 	u_int32_t	*u_rxbuf;
    136   	u_int32_t	u_rxbuf_phys;
    137 
    138 	/* for restarting command */
    139 	int		u_command;
    140 	int		u_datalen;
    141 	void		*u_dataaddr;
    142 	enum maple_dma_stat u_saved_dma_stat;
    143 	int		u_retrycnt;
    144 #define MAPLE_RETRY_MAX	100	/* ~2s */
    145 	/*
    146 	 * The 2s retry is rather too long, but required to avoid
    147 	 * unwanted detach/attach.
    148 	 * If a Visual Memory (without cells) is inserted to a controller,
    149 	 * the controller (including the base device and the other unit
    150 	 * in the slot) stops responding for near 1 second.  If two VM are
    151 	 * inserted in succession, the period becomes near 2s.
    152 	 */
    153 
    154 	/* queue for probe/ping */
    155 	enum maple_queue_stat {
    156 		MAPLE_QUEUE_NONE,	/* not in queue */
    157 		MAPLE_QUEUE_PROBE,	/* checking for insertion */
    158 		MAPLE_QUEUE_PING	/* checking for removal */
    159 	} u_queuestat;
    160 	TAILQ_ENTRY(maple_unit)	u_q;
    161 	int			u_proberetry;	/* retry count (subunit != 0) */
    162 #define MAPLE_PROBERETRY_MAX	5
    163 };
    164 
    165 struct maple_softc {
    166 	struct device	sc_dev;
    167 
    168 	struct callout	maple_callout_ch;
    169 	struct proc	*event_thread;
    170 
    171 	int8_t		sc_port_unit_map[MAPLE_PORTS];
    172 	int		sc_port_units[MAPLE_PORTS];
    173 	int		sc_port_units_open[MAPLE_PORTS];
    174 
    175 	struct maple_unit sc_unit[MAPLE_PORTS][MAPLE_SUBUNITS];
    176 
    177 	u_int32_t *sc_txbuf;	/* start of allocated transmit buffer */
    178 	u_int32_t *sc_txpos;	/* current write position in tx buffer */
    179 	u_int32_t *sc_txlink;   /* start of last written frame */
    180 
    181 	u_int32_t sc_txbuf_phys;	/* 29-bit physical address */
    182 
    183 	void	*sc_intrhand;
    184 	int	sc_dmadone;		/* wchan */
    185 
    186 	int	sc_event;		/* periodic event is active / wchan */
    187 
    188 	SIMPLEQ_HEAD(maple_dmaq_head, maple_unit) sc_dmaq, sc_retryq;
    189 	TAILQ_HEAD(maple_unitq_head, maple_unit) sc_probeq, sc_pingq;
    190 	TAILQ_HEAD(maple_fnq_head, maple_func) sc_periodicq, sc_periodicdeferq;
    191 	TAILQ_HEAD(maple_cmdq_head, maple_func) sc_acmdq, sc_pcmdq;
    192 };
    193