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