firewirereg.h revision 118293
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 118293 2003-08-01 04:51:21Z 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#else 74 dev_t dev[FWMAXNDMA+1]; 75#endif 76 struct firewire_comm *fc; 77}; 78 79#define FW_MAX_DMACH 0x20 80#define FW_MAX_DEVCH FW_MAX_DMACH 81#define FW_XFERTIMEOUT 1 82 83struct firewire_dev_comm { 84 device_t dev; 85 struct firewire_comm *fc; 86 void (*post_busreset) __P((void *)); 87 void (*post_explore) __P((void *)); 88}; 89 90struct tcode_info { 91 u_char hdr_len; /* IEEE1394 header length */ 92 u_char flag; 93#define FWTI_REQ (1 << 0) 94#define FWTI_RES (1 << 1) 95#define FWTI_TLABEL (1 << 2) 96#define FWTI_BLOCK_STR (1 << 3) 97#define FWTI_BLOCK_ASY (1 << 4) 98}; 99 100struct firewire_comm{ 101 device_t dev; 102 device_t bdev; 103 u_int16_t busid:10, 104 nodeid:6; 105 u_int mode; 106 u_int nport; 107 u_int speed; 108 u_int maxrec; 109 u_int irm; 110 u_int max_node; 111 u_int max_hop; 112 u_int max_asyretry; 113#define FWPHYASYST (1 << 0) 114 u_int retry_count; 115 u_int32_t ongobus:10, 116 ongonode:6, 117 ongoaddr:16; 118 struct fw_device *ongodev; 119 struct fw_eui64 ongoeui; 120#define FWMAXCSRDIR 16 121 SLIST_HEAD(, csrdir) ongocsr; 122 SLIST_HEAD(, csrdir) csrfree; 123 u_int32_t status; 124#define FWBUSNOTREADY (-1) 125#define FWBUSRESET 0 126#define FWBUSINIT 1 127#define FWBUSCYMELECT 2 128#define FWBUSMGRELECT 3 129#define FWBUSMGRDONE 4 130#define FWBUSEXPLORE 5 131#define FWBUSPHYCONF 6 132#define FWBUSEXPDONE 7 133#define FWBUSCOMPLETION 10 134 int nisodma; 135 struct fw_eui64 eui; 136 struct fw_xferq 137 *arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH]; 138 STAILQ_HEAD(, tlabel) tlabels[0x40]; 139 STAILQ_HEAD(, fw_bind) binds; 140 STAILQ_HEAD(, fw_device) devices; 141 STAILQ_HEAD(, fw_xfer) pending; 142 u_int sid_cnt; 143#define CSRSIZE 0x4000 144 u_int32_t csr_arc[CSRSIZE/4]; 145#define CROMSIZE 0x400 146 u_int32_t *config_rom; 147 struct crom_src_buf *crom_src_buf; 148 struct crom_src *crom_src; 149 struct crom_chunk *crom_root; 150 struct fw_topology_map *topology_map; 151 struct fw_speed_map *speed_map; 152 struct callout busprobe_callout; 153 struct callout bmr_callout; 154 struct callout timeout_callout; 155 struct callout retry_probe_callout; 156 u_int32_t (*cyctimer) __P((struct firewire_comm *)); 157 void (*ibr) __P((struct firewire_comm *)); 158 u_int32_t (*set_bmr) __P((struct firewire_comm *, u_int32_t)); 159 int (*ioctl) __P((dev_t, u_long, caddr_t, int, fw_proc *)); 160 int (*irx_enable) __P((struct firewire_comm *, int)); 161 int (*irx_disable) __P((struct firewire_comm *, int)); 162 int (*itx_enable) __P((struct firewire_comm *, int)); 163 int (*itx_disable) __P((struct firewire_comm *, int)); 164 void (*timeout) __P((void *)); 165 void (*poll) __P((struct firewire_comm *, int, int)); 166 void (*set_intr) __P((struct firewire_comm *, int)); 167 void (*irx_post) __P((struct firewire_comm *, u_int32_t *)); 168 void (*itx_post) __P((struct firewire_comm *, u_int32_t *)); 169 struct tcode_info *tcode; 170 bus_dma_tag_t dmat; 171}; 172#define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4]) 173 174struct csrdir{ 175 u_int32_t ongoaddr; 176 u_int32_t off; 177 SLIST_ENTRY(csrdir) link; 178}; 179 180struct fw_xferq { 181 int flag; 182#define FWXFERQ_CHTAGMASK 0xff 183#define FWXFERQ_RUNNING (1 << 8) 184#define FWXFERQ_STREAM (1 << 9) 185 186#define FWXFERQ_BULK (1 << 11) 187#define FWXFERQ_MODEMASK (7 << 10) 188 189#define FWXFERQ_EXTBUF (1 << 13) 190#define FWXFERQ_OPEN (1 << 14) 191 192#define FWXFERQ_HANDLER (1 << 16) 193#define FWXFERQ_WAKEUP (1 << 17) 194 void (*start) __P((struct firewire_comm*)); 195 int dmach; 196 STAILQ_HEAD(, fw_xfer) q; 197 u_int queued; 198 u_int maxq; 199 u_int psize; 200 STAILQ_HEAD(, fw_bind) binds; 201 struct fwdma_alloc_multi *buf; 202 u_int bnchunk; 203 u_int bnpacket; 204 struct fw_bulkxfer *bulkxfer; 205 STAILQ_HEAD(, fw_bulkxfer) stvalid; 206 STAILQ_HEAD(, fw_bulkxfer) stfree; 207 STAILQ_HEAD(, fw_bulkxfer) stdma; 208 struct fw_bulkxfer *stproc; 209 struct selinfo rsel; 210 caddr_t sc; 211 void (*hand) __P((struct fw_xferq *)); 212}; 213 214struct fw_bulkxfer{ 215 int poffset; 216 struct mbuf *mbuf; 217 STAILQ_ENTRY(fw_bulkxfer) link; 218 caddr_t start; 219 caddr_t end; 220 int resp; 221}; 222 223struct tlabel{ 224 struct fw_xfer *xfer; 225 STAILQ_ENTRY(tlabel) link; 226}; 227 228struct fw_bind{ 229 u_int32_t start_hi, start_lo, addrlen; 230 STAILQ_HEAD(, fw_xfer) xferlist; 231 STAILQ_ENTRY(fw_bind) fclist; 232 STAILQ_ENTRY(fw_bind) chlist; 233#define FWACT_NULL 0 234#define FWACT_XFER 2 235#define FWACT_CH 3 236 u_int8_t act_type; 237 u_int8_t sub; 238}; 239 240struct fw_xfer{ 241 caddr_t sc; 242 struct firewire_comm *fc; 243 struct fw_xferq *q; 244 struct timeval tv; 245 /* XXX should be removed */ 246 u_int32_t dst; /* XXX for if_fwe */ 247 u_int8_t spd; 248 int8_t resp; 249#define FWXF_INIT 0 250#define FWXF_INQ 1 251#define FWXF_START 2 252#define FWXF_SENT 3 253#define FWXF_SENTERR 4 254#define FWXF_BUSY 8 255#define FWXF_RCVD 10 256 u_int8_t state; 257 u_int8_t retry; 258 u_int8_t tl; 259 void (*retry_req) __P((struct fw_xfer *)); 260 union{ 261 void (*hand) __P((struct fw_xfer *)); 262 } act; 263 struct { 264 int len; 265 caddr_t buf; 266 } send, recv; 267 struct mbuf *mbuf; 268 STAILQ_ENTRY(fw_xfer) link; 269 struct malloc_type *malloc; 270}; 271void fw_sidrcv __P((struct firewire_comm *, u_int32_t *, u_int)); 272void fw_rcv __P((struct firewire_comm *, struct iovec *, int, u_int, u_int)); 273void fw_xfer_unload __P(( struct fw_xfer*)); 274void fw_xfer_free __P(( struct fw_xfer*)); 275struct fw_xfer *fw_xfer_alloc __P((struct malloc_type *)); 276struct fw_xfer *fw_xfer_alloc_buf __P((struct malloc_type *, int, int)); 277void fw_init __P((struct firewire_comm *)); 278int fw_tbuf_update __P((struct firewire_comm *, int, int)); 279int fw_rbuf_update __P((struct firewire_comm *, int, int)); 280void fw_asybusy __P((struct fw_xfer *)); 281int fw_bindadd __P((struct firewire_comm *, struct fw_bind *)); 282int fw_bindremove __P((struct firewire_comm *, struct fw_bind *)); 283int fw_asyreq __P((struct firewire_comm *, int, struct fw_xfer*)); 284void fw_busreset __P((struct firewire_comm *)); 285u_int16_t fw_crc16 __P((u_int32_t *, u_int32_t)); 286void fw_xfer_timeout __P((void *)); 287void fw_xfer_done __P((struct fw_xfer *)); 288void fw_asy_callback __P((struct fw_xfer *)); 289struct fw_device *fw_noderesolve_nodeid __P((struct firewire_comm *, int)); 290struct fw_device *fw_noderesolve_eui64 __P((struct firewire_comm *, struct fw_eui64 *)); 291struct fw_bind *fw_bindlookup __P((struct firewire_comm *, u_int32_t, u_int32_t)); 292void fw_drain_txq __P((struct firewire_comm *)); 293 294 295extern int firewire_debug; 296extern devclass_t firewire_devclass; 297 298#define FWPRI ((PZERO+8)|PCATCH) 299 300#if __FreeBSD_version >= 500000 301#define CALLOUT_INIT(x) callout_init(x, 0 /* mpsafe */) 302#else 303#define CALLOUT_INIT(x) callout_init(x) 304#endif 305 306MALLOC_DECLARE(M_FW); 307MALLOC_DECLARE(M_FWXFER); 308