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