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