1 /* $NetBSD: firewirereg.h,v 1.20 2016/11/20 22:47:39 riastradh Exp $ */ 2 /*- 3 * Copyright (c) 2003 Hidetoshi Shimokawa 4 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the acknowledgement as bellow: 17 * 18 * This product includes software developed by K. Kobayashi and H. Shimokawa 19 * 20 * 4. The name of the author may not be used to endorse or promote products 21 * derived from this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 * POSSIBILITY OF SUCH DAMAGE. 34 * 35 * $FreeBSD: src/sys/dev/firewire/firewirereg.h,v 1.50 2007/07/20 03:42:57 simokawa Exp $ 36 * 37 */ 38 #ifndef _FIREWIREREG_H_ 39 #define _FIREWIREREG_H_ 40 41 #include <sys/selinfo.h> 42 #include <sys/uio.h> 43 44 #define PROJECT_STR "The NetBSD Project" 45 46 STAILQ_HEAD(fw_xferlist, fw_xfer); 47 48 struct fw_device { 49 uint16_t dst; 50 struct fw_eui64 eui; 51 uint8_t speed; 52 uint8_t maxrec; 53 uint8_t nport; 54 uint8_t power; 55 #define CSRROMOFF 0x400 56 #define CSRROMSIZE 0x400 57 int rommax; /* offset from 0xffff f000 0000 */ 58 uint32_t csrrom[CSRROMSIZE/4]; 59 int rcnt; 60 struct firewire_comm *fc; 61 uint32_t status; 62 #define FWDEVNEW 0 63 #define FWDEVINIT 1 64 #define FWDEVATTACHED 2 65 #define FWDEVINVAL 3 66 STAILQ_ENTRY(fw_device) link; 67 device_t dev; 68 }; 69 70 struct firewire_softc { 71 device_t dev; 72 SLIST_HEAD(, firewire_dev_list) devlist; 73 void *si_drv1; 74 struct firewire_comm *fc; 75 }; 76 77 struct firewire_dev_list { 78 SLIST_ENTRY(firewire_dev_list) link; 79 device_t dev; 80 struct fw_device *fwdev; 81 }; 82 83 #define FW_MAX_DMACH 0x20 84 #define FW_MAX_DEVCH FW_MAX_DMACH 85 #define FW_XFERTIMEOUT 1 86 87 struct firewire_dev_comm { 88 device_t dev; 89 struct firewire_comm *fc; 90 void (*post_busreset) (void *); 91 void (*post_explore) (void *); 92 }; 93 94 struct tcode_info { 95 u_char hdr_len; /* IEEE1394 header length */ 96 u_char flag; 97 #define FWTI_REQ (1 << 0) 98 #define FWTI_RES (1 << 1) 99 #define FWTI_TLABEL (1 << 2) 100 #define FWTI_BLOCK_STR (1 << 3) 101 #define FWTI_BLOCK_ASY (1 << 4) 102 u_char valid_res; 103 }; 104 105 struct firewire_comm { 106 device_t dev; 107 device_t bdev; 108 uint16_t busid:10, 109 nodeid:6; 110 u_int mode; 111 u_int nport; 112 u_int speed; 113 u_int maxrec; 114 u_int irm; 115 u_int max_node; 116 u_int max_hop; 117 #define FWPHYASYST (1 << 0) 118 uint32_t status; 119 #define FWBUSDETACHOK (-3) 120 #define FWBUSDETACH (-2) 121 #define FWBUSNOTREADY (-1) 122 #define FWBUSRESET 0 123 #define FWBUSINIT 1 124 #define FWBUSCYMELECT 2 125 #define FWBUSMGRELECT 3 126 #define FWBUSMGRDONE 4 127 #define FWBUSEXPLORE 5 128 #define FWBUSPHYCONF 6 129 #define FWBUSEXPDONE 7 130 #define FWBUSCOMPLETION 10 131 int nisodma; 132 struct fw_eui64 eui; 133 struct fw_xferq 134 *arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH]; 135 struct fw_xferlist tlabels[0x40]; 136 u_char last_tlabel[0x40]; 137 kmutex_t tlabel_lock; 138 STAILQ_HEAD(, fw_bind) binds; 139 STAILQ_HEAD(, fw_device) devices; 140 u_int sid_cnt; 141 #define CSRSIZE 0x4000 142 uint32_t csr_arc[CSRSIZE/4]; 143 #define CROMSIZE 0x400 144 uint32_t *config_rom; 145 struct crom_src_buf *crom_src_buf; 146 struct crom_src *crom_src; 147 struct crom_chunk *crom_root; 148 struct fw_topology_map *topology_map; 149 struct fw_speed_map *speed_map; 150 struct callout busprobe_callout; 151 struct callout bmr_callout; 152 struct callout timeout_callout; 153 uint32_t (*cyctimer) (struct firewire_comm *); 154 void (*ibr) (struct firewire_comm *); 155 uint32_t (*set_bmr) (struct firewire_comm *, uint32_t); 156 int (*ioctl) (dev_t, u_long, void *, int, struct lwp *); 157 int (*irx_enable) (struct firewire_comm *, int); 158 int (*irx_disable) (struct firewire_comm *, int); 159 int (*itx_enable) (struct firewire_comm *, int); 160 int (*itx_disable) (struct firewire_comm *, int); 161 void (*timeout) (struct firewire_comm *); 162 void (*set_intr) (struct firewire_comm *, int); 163 void (*irx_post) (struct firewire_comm *, uint32_t *); 164 void (*itx_post) (struct firewire_comm *, uint32_t *); 165 const struct tcode_info *tcode; 166 bus_dma_tag_t dmat; 167 kmutex_t fc_mtx; 168 kmutex_t wait_lock; 169 kcondvar_t fc_cv; 170 struct lwp *probe_thread; 171 }; 172 #define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4]) 173 174 175 struct fw_xferq { 176 int flag; 177 #define FWXFERQ_CHTAGMASK 0xff 178 #define FWXFERQ_RUNNING (1 << 8) 179 #define FWXFERQ_STREAM (1 << 9) 180 181 #define FWXFERQ_BULK (1 << 11) 182 #define FWXFERQ_MODEMASK (7 << 10) 183 184 #define FWXFERQ_EXTBUF (1 << 13) 185 #define FWXFERQ_OPEN (1 << 14) 186 187 #define FWXFERQ_HANDLER (1 << 16) 188 #define FWXFERQ_WAKEUP (1 << 17) 189 void (*start) (struct firewire_comm*); 190 int dmach; 191 struct fw_xferlist q; 192 u_int queued; 193 u_int maxq; 194 u_int psize; 195 struct fwdma_alloc_multi *buf; 196 u_int bnchunk; 197 u_int bnpacket; 198 struct fw_bulkxfer *bulkxfer; 199 STAILQ_HEAD(, fw_bulkxfer) stvalid; 200 STAILQ_HEAD(, fw_bulkxfer) stfree; 201 STAILQ_HEAD(, fw_bulkxfer) stdma; 202 struct fw_bulkxfer *stproc; 203 kcondvar_t cv; 204 struct selinfo rsel; 205 void *sc; 206 void (*hand) (struct fw_xferq *); 207 kmutex_t q_mtx; 208 }; 209 210 #define FW_GMTX(fc) (&(fc)->fc_mtx) 211 #define FW_GLOCK(fc) fw_mtx_lock(FW_GMTX(fc)) 212 #define FW_GUNLOCK(fc) fw_mtx_unlock(FW_GMTX(fc)) 213 #define FW_GLOCK_ASSERT(fc) fw_mtx_assert(FW_GMTX(fc), MA_OWNED) 214 215 struct fw_bulkxfer { 216 int poffset; 217 struct mbuf *mbuf; 218 STAILQ_ENTRY(fw_bulkxfer) link; 219 void *start; 220 void *end; 221 int resp; 222 }; 223 224 struct fw_bind { 225 u_int64_t start; 226 u_int64_t end; 227 struct fw_xferlist xferlist; 228 STAILQ_ENTRY(fw_bind) fclist; 229 STAILQ_ENTRY(fw_bind) chlist; 230 void *sc; 231 kmutex_t fwb_mtx; 232 }; 233 234 struct fw_xfer { 235 void *sc; 236 struct firewire_comm *fc; 237 struct fw_xferq *q; 238 struct timeval tv; 239 int8_t resp; 240 #define FWXF_INIT 0x00 241 #define FWXF_INQ 0x01 242 #define FWXF_START 0x02 243 #define FWXF_SENT 0x04 244 #define FWXF_SENTERR 0x08 245 #define FWXF_BUSY 0x10 246 #define FWXF_RCVD 0x20 247 248 #define FWXF_WAKE 0x80 249 uint8_t flag; 250 int8_t tl; 251 void (*hand) (struct fw_xfer *); 252 struct { 253 struct fw_pkt hdr; 254 uint32_t *payload; 255 uint16_t pay_len; 256 uint8_t spd; 257 } send, recv; 258 struct mbuf *mbuf; 259 STAILQ_ENTRY(fw_xfer) link; 260 STAILQ_ENTRY(fw_xfer) tlabel; 261 struct malloc_type *malloc; 262 kcondvar_t cv; 263 }; 264 265 struct fw_rcv_buf { 266 struct firewire_comm *fc; 267 struct fw_xfer *xfer; 268 struct iovec *vec; 269 u_int nvec; 270 uint8_t spd; 271 }; 272 273 int fw_tbuf_update (struct firewire_comm *, int, int); 274 int fw_rbuf_update (struct firewire_comm *, int, int); 275 int fwdev_makedev (struct firewire_softc *); 276 int fwdev_destroydev (struct firewire_softc *); 277 278 struct fw_device *fw_noderesolve_nodeid(struct firewire_comm *, int); 279 struct fw_device *fw_noderesolve_eui64(struct firewire_comm *, 280 struct fw_eui64 *); 281 int fw_asyreq(struct firewire_comm *, int, struct fw_xfer*); 282 void fw_xferwake(struct fw_xfer *); 283 int fw_xferwait(struct fw_xfer *); 284 void fw_drain_txq(struct firewire_comm *); 285 void fw_busreset(struct firewire_comm *, uint32_t); 286 void fw_init(struct firewire_comm *); 287 void fw_init_isodma(struct firewire_comm *); 288 void fw_destroy_isodma(struct firewire_comm *); 289 void fw_destroy(struct firewire_comm *); 290 struct fw_bind *fw_bindlookup(struct firewire_comm *, uint16_t, uint32_t); 291 int fw_bindadd(struct firewire_comm *, struct fw_bind *); 292 int fw_bindremove(struct firewire_comm *, struct fw_bind *); 293 int fw_xferlist_add(struct fw_xferlist *, struct malloc_type *, int, int, int, 294 struct firewire_comm *, void *, void (*)(struct fw_xfer *)); 295 void fw_xferlist_remove(struct fw_xferlist *); 296 struct fw_xfer *fw_xfer_alloc(struct malloc_type *); 297 struct fw_xfer *fw_xfer_alloc_buf(struct malloc_type *, int, int); 298 void fw_xfer_done(struct fw_xfer *); 299 void fw_xfer_unload(struct fw_xfer*); 300 void fw_xfer_free(struct fw_xfer*); 301 void fw_xfer_free_buf(struct fw_xfer*); 302 void fw_asy_callback_free(struct fw_xfer *); 303 void fw_sidrcv(struct firewire_comm *, uint32_t *, u_int); 304 void fw_rcv(struct fw_rcv_buf *); 305 uint16_t fw_crc16(uint32_t *, uint32_t); 306 int fw_open_isodma(struct firewire_comm *, int); 307 308 extern int firewire_debug; 309 extern int firewire_phydma_enable; 310 311 #define FWPRI ((PZERO+8)|PCATCH) 312 313 /* compatibility shim for 4.X */ 314 #define bio buf 315 #define bio_bcount b_bcount 316 #define bio_cmd b_flags 317 #define bio_count b_count 318 #define bio_data b_data 319 #define bio_dev b_dev 320 #define bio_error b_error 321 #define bio_flags b_flags 322 #define bio_offset b_blkno 323 #define bio_resid b_resid 324 #define BIO_READ B_READ 325 #define BIO_WRITE B_WRITE 326 327 #include <sys/mallocvar.h> 328 329 MALLOC_DECLARE(M_FW); 330 331 #endif /* _FIREWIREREG_H_ */ 332