firewirereg.h revision 114069
1255736Sdavidch/* 2296071Sdavidcs * Copyright (c) 2003 Hidetoshi Shimokawa 3255736Sdavidch * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa 4255736Sdavidch * All rights reserved. 5255736Sdavidch * 6255736Sdavidch * Redistribution and use in source and binary forms, with or without 7255736Sdavidch * modification, are permitted provided that the following conditions 8255736Sdavidch * are met: 9255736Sdavidch * 1. Redistributions of source code must retain the above copyright 10255736Sdavidch * notice, this list of conditions and the following disclaimer. 11255736Sdavidch * 2. Redistributions in binary form must reproduce the above copyright 12255736Sdavidch * notice, this list of conditions and the following disclaimer in the 13255736Sdavidch * documentation and/or other materials provided with the distribution. 14296071Sdavidcs * 3. All advertising materials mentioning features or use of this software 15255736Sdavidch * must display the acknowledgement as bellow: 16255736Sdavidch * 17255736Sdavidch * This product includes software developed by K. Kobayashi and H. Shimokawa 18255736Sdavidch * 19255736Sdavidch * 4. The name of the author may not be used to endorse or promote products 20255736Sdavidch * derived from this software without specific prior written permission. 21255736Sdavidch * 22255736Sdavidch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23255736Sdavidch * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24255736Sdavidch * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25255736Sdavidch * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26255736Sdavidch * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27255736Sdavidch * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28255736Sdavidch * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29255736Sdavidch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30255736Sdavidch * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31255736Sdavidch * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32255736Sdavidch * POSSIBILITY OF SUCH DAMAGE. 33255736Sdavidch * 34255736Sdavidch * $FreeBSD: head/sys/dev/firewire/firewirereg.h 114069 2003-04-26 16:45:40Z simokawa $ 35255736Sdavidch * 36255736Sdavidch */ 37255736Sdavidch 38255736Sdavidch#if __FreeBSD_version >= 500000 39255736Sdavidchtypedef struct thread fw_proc; 40255736Sdavidch#include <sys/selinfo.h> 41255736Sdavidch#else 42255736Sdavidchtypedef struct proc fw_proc; 43255736Sdavidch#include <sys/select.h> 44255736Sdavidch#endif 45255736Sdavidch 46255736Sdavidch#include <sys/uio.h> 47255736Sdavidch 48255736Sdavidch#define splfw splimp 49255736Sdavidch 50255736Sdavidchstruct fw_device{ 51255736Sdavidch u_int16_t dst; 52255736Sdavidch struct fw_eui64 eui; 53255736Sdavidch u_int8_t speed; 54255736Sdavidch u_int8_t maxrec; 55255736Sdavidch u_int8_t nport; 56255736Sdavidch u_int8_t power; 57255736Sdavidch#define CSRROMOFF 0x400 58255736Sdavidch#define CSRROMSIZE 0x400 59255736Sdavidch int rommax; /* offset from 0xffff f000 0000 */ 60255736Sdavidch u_int32_t csrrom[CSRROMSIZE/4]; 61255736Sdavidch int rcnt; 62255736Sdavidch struct firewire_comm *fc; 63255736Sdavidch u_int32_t status; 64255736Sdavidch#define FWDEVINIT 1 65255736Sdavidch#define FWDEVATTACHED 2 66255736Sdavidch#define FWDEVINVAL 3 67255736Sdavidch STAILQ_ENTRY(fw_device) link; 68255736Sdavidch}; 69255736Sdavidch 70255736Sdavidchstruct firewire_softc { 71255736Sdavidch#if __FreeBSD_version >= 500000 72255736Sdavidch dev_t dev; 73255736Sdavidch#else 74255736Sdavidch dev_t dev[FWMAXNDMA+1]; 75255736Sdavidch#endif 76255736Sdavidch struct firewire_comm *fc; 77255736Sdavidch}; 78255736Sdavidch 79255736Sdavidch#define FW_MAX_DMACH 0x20 80255736Sdavidch#define FW_MAX_DEVCH FW_MAX_DMACH 81255736Sdavidch#define FW_XFERTIMEOUT 1 82255736Sdavidch 83255736Sdavidchstruct firewire_dev_comm { 84255736Sdavidch device_t dev; 85255736Sdavidch struct firewire_comm *fc; 86255736Sdavidch void (*post_busreset) __P((void *)); 87255736Sdavidch void (*post_explore) __P((void *)); 88255736Sdavidch}; 89255736Sdavidch 90255736Sdavidchstruct tcode_info { 91255736Sdavidch u_char hdr_len; /* IEEE1394 header length */ 92255736Sdavidch u_char flag; 93255736Sdavidch#define FWTI_REQ (1 << 0) 94255736Sdavidch#define FWTI_RES (1 << 1) 95255736Sdavidch#define FWTI_TLABEL (1 << 2) 96255736Sdavidch#define FWTI_BLOCK_STR (1 << 3) 97255736Sdavidch#define FWTI_BLOCK_ASY (1 << 4) 98255736Sdavidch}; 99255736Sdavidch 100255736Sdavidchstruct firewire_comm{ 101255736Sdavidch device_t dev; 102255736Sdavidch device_t bdev; 103255736Sdavidch u_int16_t busid:10, 104255736Sdavidch nodeid:6; 105255736Sdavidch u_int mode; 106255736Sdavidch u_int nport; 107255736Sdavidch u_int speed; 108255736Sdavidch u_int maxrec; 109255736Sdavidch u_int irm; 110255736Sdavidch u_int max_node; 111255736Sdavidch u_int max_hop; 112255736Sdavidch u_int max_asyretry; 113255736Sdavidch#define FWPHYASYST (1 << 0) 114255736Sdavidch u_int retry_count; 115255736Sdavidch u_int32_t ongobus:10, 116255736Sdavidch ongonode:6, 117255736Sdavidch ongoaddr:16; 118255736Sdavidch struct fw_device *ongodev; 119255736Sdavidch struct fw_eui64 ongoeui; 120255736Sdavidch#define FWMAXCSRDIR 16 121255736Sdavidch SLIST_HEAD(, csrdir) ongocsr; 122255736Sdavidch SLIST_HEAD(, csrdir) csrfree; 123255736Sdavidch u_int32_t status; 124255736Sdavidch#define FWBUSRESET 0 125255736Sdavidch#define FWBUSINIT 1 126255736Sdavidch#define FWBUSCYMELECT 2 127255736Sdavidch#define FWBUSMGRELECT 3 128255736Sdavidch#define FWBUSMGRDONE 4 129255736Sdavidch#define FWBUSEXPLORE 5 130255736Sdavidch#define FWBUSPHYCONF 6 131255736Sdavidch#define FWBUSEXPDONE 7 132255736Sdavidch#define FWBUSCOMPLETION 10 133255736Sdavidch int nisodma; 134255736Sdavidch struct fw_eui64 eui; 135255736Sdavidch struct fw_xferq 136255736Sdavidch *arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH]; 137255736Sdavidch STAILQ_HEAD(, tlabel) tlabels[0x40]; 138255736Sdavidch STAILQ_HEAD(, fw_bind) binds; 139255736Sdavidch STAILQ_HEAD(, fw_device) devices; 140255736Sdavidch STAILQ_HEAD(, fw_xfer) pending; 141255736Sdavidch u_int sid_cnt; 142255736Sdavidch#define CSRSIZE 0x4000 143255736Sdavidch u_int32_t csr_arc[CSRSIZE/4]; 144255736Sdavidch#define CROMSIZE 0x400 145255736Sdavidch u_int32_t *config_rom; 146255736Sdavidch struct fw_topology_map *topology_map; 147255736Sdavidch struct fw_speed_map *speed_map; 148255736Sdavidch struct callout busprobe_callout; 149255736Sdavidch struct callout bmr_callout; 150255736Sdavidch struct callout timeout_callout; 151255736Sdavidch struct callout retry_probe_callout; 152255736Sdavidch u_int32_t (*cyctimer) __P((struct firewire_comm *)); 153255736Sdavidch void (*ibr) __P((struct firewire_comm *)); 154255736Sdavidch u_int32_t (*set_bmr) __P((struct firewire_comm *, u_int32_t)); 155255736Sdavidch int (*ioctl) __P((dev_t, u_long, caddr_t, int, fw_proc *)); 156255736Sdavidch int (*irx_enable) __P((struct firewire_comm *, int)); 157255736Sdavidch int (*irx_disable) __P((struct firewire_comm *, int)); 158255736Sdavidch int (*itx_enable) __P((struct firewire_comm *, int)); 159255736Sdavidch int (*itx_disable) __P((struct firewire_comm *, int)); 160255736Sdavidch void (*timeout) __P((void *)); 161255736Sdavidch void (*poll) __P((struct firewire_comm *, int, int)); 162255736Sdavidch void (*set_intr) __P((struct firewire_comm *, int)); 163255736Sdavidch void (*irx_post) __P((struct firewire_comm *, u_int32_t *)); 164255736Sdavidch void (*itx_post) __P((struct firewire_comm *, u_int32_t *)); 165255736Sdavidch struct tcode_info *tcode; 166255736Sdavidch bus_dma_tag_t dmat; 167255736Sdavidch}; 168255736Sdavidch#define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4]) 169255736Sdavidch 170255736Sdavidchstruct csrdir{ 171255736Sdavidch u_int32_t ongoaddr; 172255736Sdavidch u_int32_t off; 173255736Sdavidch SLIST_ENTRY(csrdir) link; 174255736Sdavidch}; 175255736Sdavidch 176255736Sdavidchstruct fw_xferq { 177255736Sdavidch int flag; 178255736Sdavidch#define FWXFERQ_CHTAGMASK 0xff 179255736Sdavidch#define FWXFERQ_RUNNING (1 << 8) 180255736Sdavidch#define FWXFERQ_STREAM (1 << 9) 181255736Sdavidch 182255736Sdavidch#define FWXFERQ_BULK (1 << 11) 183255736Sdavidch#define FWXFERQ_MODEMASK (7 << 10) 184255736Sdavidch 185255736Sdavidch#define FWXFERQ_EXTBUF (1 << 13) 186255736Sdavidch#define FWXFERQ_OPEN (1 << 14) 187255736Sdavidch 188255736Sdavidch#define FWXFERQ_HANDLER (1 << 16) 189255736Sdavidch#define FWXFERQ_WAKEUP (1 << 17) 190255736Sdavidch 191255736Sdavidch void (*start) __P((struct firewire_comm*)); 192255736Sdavidch STAILQ_HEAD(, fw_xfer) q; 193255736Sdavidch u_int queued; 194255736Sdavidch u_int maxq; 195255736Sdavidch u_int psize; 196255736Sdavidch STAILQ_HEAD(, fw_bind) binds; 197255736Sdavidch struct fwdma_alloc_multi *buf; 198255736Sdavidch u_int bnchunk; 199255736Sdavidch u_int bnpacket; 200255736Sdavidch struct fw_bulkxfer *bulkxfer; 201255736Sdavidch STAILQ_HEAD(, fw_bulkxfer) stvalid; 202255736Sdavidch STAILQ_HEAD(, fw_bulkxfer) stfree; 203255736Sdavidch STAILQ_HEAD(, fw_bulkxfer) stdma; 204 struct fw_bulkxfer *stproc; 205 struct selinfo rsel; 206 caddr_t sc; 207 void (*hand) __P((struct fw_xferq *)); 208}; 209 210struct fw_bulkxfer{ 211 int poffset; 212 struct mbuf *mbuf; 213 STAILQ_ENTRY(fw_bulkxfer) link; 214 caddr_t start; 215 caddr_t end; 216 int resp; 217}; 218 219struct tlabel{ 220 struct fw_xfer *xfer; 221 STAILQ_ENTRY(tlabel) link; 222}; 223 224struct fw_bind{ 225 u_int32_t start_hi, start_lo, addrlen; 226 STAILQ_HEAD(, fw_xfer) xferlist; 227 STAILQ_ENTRY(fw_bind) fclist; 228 STAILQ_ENTRY(fw_bind) chlist; 229#define FWACT_NULL 0 230#define FWACT_XFER 2 231#define FWACT_CH 3 232 u_int8_t act_type; 233 u_int8_t sub; 234}; 235 236struct fw_xfer{ 237 caddr_t sc; 238 struct firewire_comm *fc; 239 struct fw_xferq *q; 240 struct timeval tv; 241 /* XXX should be removed */ 242 u_int32_t dst; /* XXX for if_fwe */ 243 u_int8_t spd; 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 int len; 261 caddr_t buf; 262 } send, recv; 263 struct mbuf *mbuf; 264 STAILQ_ENTRY(fw_xfer) link; 265 struct malloc_type *malloc; 266}; 267void fw_sidrcv __P((struct firewire_comm *, u_int32_t *, u_int)); 268void fw_rcv __P((struct firewire_comm *, struct iovec *, int, u_int, u_int)); 269void fw_xfer_unload __P(( struct fw_xfer*)); 270void fw_xfer_free __P(( struct fw_xfer*)); 271struct fw_xfer *fw_xfer_alloc __P((struct malloc_type *)); 272struct fw_xfer *fw_xfer_alloc_buf __P((struct malloc_type *, int, int)); 273void fw_init __P((struct firewire_comm *)); 274int fw_tbuf_update __P((struct firewire_comm *, int, int)); 275int fw_rbuf_update __P((struct firewire_comm *, int, int)); 276void fw_asybusy __P((struct fw_xfer *)); 277int fw_bindadd __P((struct firewire_comm *, struct fw_bind *)); 278int fw_bindremove __P((struct firewire_comm *, struct fw_bind *)); 279int fw_asyreq __P((struct firewire_comm *, int, struct fw_xfer*)); 280void fw_busreset __P((struct firewire_comm *)); 281u_int16_t fw_crc16 __P((u_int32_t *, u_int32_t)); 282void fw_xfer_timeout __P((void *)); 283void fw_xfer_done __P((struct fw_xfer *)); 284void fw_asy_callback __P((struct fw_xfer *)); 285struct fw_device *fw_noderesolve_nodeid __P((struct firewire_comm *, int)); 286struct fw_device *fw_noderesolve_eui64 __P((struct firewire_comm *, struct fw_eui64 *)); 287struct fw_bind *fw_bindlookup __P((struct firewire_comm *, u_int32_t, u_int32_t)); 288void fw_drain_txq __P((struct firewire_comm *)); 289 290 291extern int firewire_debug; 292extern devclass_t firewire_devclass; 293 294#define DV_BROADCAST_ON (1<<30) 295#define IP_CHANNELS 0x0234 296 297#define STATE_CLEAR 0x0000 298#define STATE_SET 0x0004 299#define NODE_IDS 0x0008 300#define RESET_START 0x000c 301#define SPLIT_TIMEOUT_HI 0x0018 302#define SPLIT_TIMEOUT_LO 0x001c 303#define CYCLE_TIME 0x0200 304#define BUS_TIME 0x0204 305#define BUSY_TIMEOUT 0x0210 306#define BUS_MGR_ID 0x021c 307#define BANDWIDTH_AV 0x0220 308#define CHANNELS_AV_HI 0x0224 309#define CHANNELS_AV_LO 0x0228 310 311#define CONF_ROM 0x0400 312 313#define TOPO_MAP 0x1000 314#define SPED_MAP 0x2000 315 316#define oMPR 0x900 317#define oPCR 0x904 318 319#define iMPR 0x980 320#define iPCR 0x984 321 322#define FWPRI ((PZERO+8)|PCATCH) 323 324#if __FreeBSD_version >= 500000 325#define CALLOUT_INIT(x) callout_init(x, 0 /* mpsafe */) 326#else 327#define CALLOUT_INIT(x) callout_init(x) 328#endif 329 330MALLOC_DECLARE(M_FW); 331MALLOC_DECLARE(M_FWXFER); 332