firewirereg.h revision 124169
1103285Sikob/* 2113584Ssimokawa * Copyright (c) 2003 Hidetoshi Shimokawa 3103285Sikob * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa 4103285Sikob * All rights reserved. 5103285Sikob * 6103285Sikob * Redistribution and use in source and binary forms, with or without 7103285Sikob * modification, are permitted provided that the following conditions 8103285Sikob * are met: 9103285Sikob * 1. Redistributions of source code must retain the above copyright 10103285Sikob * notice, this list of conditions and the following disclaimer. 11103285Sikob * 2. Redistributions in binary form must reproduce the above copyright 12103285Sikob * notice, this list of conditions and the following disclaimer in the 13103285Sikob * documentation and/or other materials provided with the distribution. 14103285Sikob * 3. All advertising materials mentioning features or use of this software 15103285Sikob * must display the acknowledgement as bellow: 16103285Sikob * 17103285Sikob * This product includes software developed by K. Kobayashi and H. Shimokawa 18103285Sikob * 19103285Sikob * 4. The name of the author may not be used to endorse or promote products 20103285Sikob * derived from this software without specific prior written permission. 21103285Sikob * 22103285Sikob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23103285Sikob * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24103285Sikob * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25103285Sikob * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26103285Sikob * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27103285Sikob * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28103285Sikob * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29103285Sikob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30103285Sikob * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31103285Sikob * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32103285Sikob * POSSIBILITY OF SUCH DAMAGE. 33103285Sikob * 34103285Sikob * $FreeBSD: head/sys/dev/firewire/firewirereg.h 124169 2004-01-06 14:30:47Z simokawa $ 35103285Sikob * 36103285Sikob */ 37103285Sikob 38103285Sikob#if __FreeBSD_version >= 500000 39103285Sikobtypedef struct thread fw_proc; 40103285Sikob#include <sys/selinfo.h> 41103285Sikob#else 42103285Sikobtypedef struct proc fw_proc; 43103285Sikob#include <sys/select.h> 44103285Sikob#endif 45103285Sikob 46113584Ssimokawa#include <sys/uio.h> 47113584Ssimokawa 48103285Sikob#define splfw splimp 49103285Sikob 50103285Sikobstruct fw_device{ 51103285Sikob u_int16_t dst; 52103285Sikob struct fw_eui64 eui; 53103285Sikob u_int8_t speed; 54103285Sikob u_int8_t maxrec; 55103285Sikob u_int8_t nport; 56103285Sikob u_int8_t power; 57103285Sikob#define CSRROMOFF 0x400 58103285Sikob#define CSRROMSIZE 0x400 59103285Sikob int rommax; /* offset from 0xffff f000 0000 */ 60103285Sikob u_int32_t csrrom[CSRROMSIZE/4]; 61103285Sikob int rcnt; 62106810Ssimokawa struct firewire_comm *fc; 63103285Sikob u_int32_t status; 64103285Sikob#define FWDEVINIT 1 65103285Sikob#define FWDEVATTACHED 2 66103285Sikob#define FWDEVINVAL 3 67110193Ssimokawa STAILQ_ENTRY(fw_device) link; 68103285Sikob}; 69109645Ssimokawa 70103285Sikobstruct firewire_softc { 71103285Sikob#if __FreeBSD_version >= 500000 72103285Sikob dev_t dev; 73103285Sikob#endif 74103285Sikob struct firewire_comm *fc; 75103285Sikob}; 76109645Ssimokawa 77103285Sikob#define FW_MAX_DMACH 0x20 78103285Sikob#define FW_MAX_DEVCH FW_MAX_DMACH 79103285Sikob#define FW_XFERTIMEOUT 1 80109645Ssimokawa 81103285Sikobstruct firewire_dev_comm { 82103285Sikob device_t dev; 83103285Sikob struct firewire_comm *fc; 84124169Ssimokawa void (*post_busreset) (void *); 85124169Ssimokawa void (*post_explore) (void *); 86103285Sikob}; 87103285Sikob 88103285Sikobstruct tcode_info { 89103285Sikob u_char hdr_len; /* IEEE1394 header length */ 90103285Sikob u_char flag; 91103285Sikob#define FWTI_REQ (1 << 0) 92103285Sikob#define FWTI_RES (1 << 1) 93103285Sikob#define FWTI_TLABEL (1 << 2) 94103285Sikob#define FWTI_BLOCK_STR (1 << 3) 95103285Sikob#define FWTI_BLOCK_ASY (1 << 4) 96103285Sikob}; 97103285Sikob 98103285Sikobstruct firewire_comm{ 99103285Sikob device_t dev; 100103285Sikob device_t bdev; 101103285Sikob u_int16_t busid:10, 102103285Sikob nodeid:6; 103103285Sikob u_int mode; 104103285Sikob u_int nport; 105103285Sikob u_int speed; 106103285Sikob u_int maxrec; 107103285Sikob u_int irm; 108103285Sikob u_int max_node; 109103285Sikob u_int max_hop; 110103285Sikob u_int max_asyretry; 111103285Sikob#define FWPHYASYST (1 << 0) 112103285Sikob u_int retry_count; 113103285Sikob u_int32_t ongobus:10, 114103285Sikob ongonode:6, 115103285Sikob ongoaddr:16; 116103285Sikob struct fw_device *ongodev; 117103285Sikob struct fw_eui64 ongoeui; 118103285Sikob#define FWMAXCSRDIR 16 119103285Sikob SLIST_HEAD(, csrdir) ongocsr; 120103285Sikob SLIST_HEAD(, csrdir) csrfree; 121103285Sikob u_int32_t status; 122116978Ssimokawa#define FWBUSNOTREADY (-1) 123103285Sikob#define FWBUSRESET 0 124103285Sikob#define FWBUSINIT 1 125103285Sikob#define FWBUSCYMELECT 2 126103285Sikob#define FWBUSMGRELECT 3 127103285Sikob#define FWBUSMGRDONE 4 128103285Sikob#define FWBUSEXPLORE 5 129103285Sikob#define FWBUSPHYCONF 6 130103285Sikob#define FWBUSEXPDONE 7 131103285Sikob#define FWBUSCOMPLETION 10 132103285Sikob int nisodma; 133109814Ssimokawa struct fw_eui64 eui; 134103285Sikob struct fw_xferq 135103285Sikob *arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH]; 136103285Sikob STAILQ_HEAD(, tlabel) tlabels[0x40]; 137103285Sikob STAILQ_HEAD(, fw_bind) binds; 138110193Ssimokawa STAILQ_HEAD(, fw_device) devices; 139103285Sikob u_int sid_cnt; 140103285Sikob#define CSRSIZE 0x4000 141103285Sikob u_int32_t csr_arc[CSRSIZE/4]; 142103285Sikob#define CROMSIZE 0x400 143103285Sikob u_int32_t *config_rom; 144116376Ssimokawa struct crom_src_buf *crom_src_buf; 145116376Ssimokawa struct crom_src *crom_src; 146116376Ssimokawa struct crom_chunk *crom_root; 147103285Sikob struct fw_topology_map *topology_map; 148103285Sikob struct fw_speed_map *speed_map; 149108853Ssimokawa struct callout busprobe_callout; 150110193Ssimokawa struct callout bmr_callout; 151110193Ssimokawa struct callout timeout_callout; 152110193Ssimokawa struct callout retry_probe_callout; 153124169Ssimokawa u_int32_t (*cyctimer) (struct firewire_comm *); 154124169Ssimokawa void (*ibr) (struct firewire_comm *); 155124169Ssimokawa u_int32_t (*set_bmr) (struct firewire_comm *, u_int32_t); 156124169Ssimokawa int (*ioctl) (dev_t, u_long, caddr_t, int, fw_proc *); 157124169Ssimokawa int (*irx_enable) (struct firewire_comm *, int); 158124169Ssimokawa int (*irx_disable) (struct firewire_comm *, int); 159124169Ssimokawa int (*itx_enable) (struct firewire_comm *, int); 160124169Ssimokawa int (*itx_disable) (struct firewire_comm *, int); 161124169Ssimokawa void (*timeout) (void *); 162124169Ssimokawa void (*poll) (struct firewire_comm *, int, int); 163124169Ssimokawa void (*set_intr) (struct firewire_comm *, int); 164124169Ssimokawa void (*irx_post) (struct firewire_comm *, u_int32_t *); 165124169Ssimokawa void (*itx_post) (struct firewire_comm *, u_int32_t *); 166103285Sikob struct tcode_info *tcode; 167113584Ssimokawa bus_dma_tag_t dmat; 168103285Sikob}; 169103285Sikob#define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4]) 170103285Sikob 171109645Ssimokawastruct csrdir{ 172109645Ssimokawa u_int32_t ongoaddr; 173109645Ssimokawa u_int32_t off; 174109645Ssimokawa SLIST_ENTRY(csrdir) link; 175109645Ssimokawa}; 176103285Sikob 177109645Ssimokawastruct fw_xferq { 178109645Ssimokawa int flag; 179109645Ssimokawa#define FWXFERQ_CHTAGMASK 0xff 180109645Ssimokawa#define FWXFERQ_RUNNING (1 << 8) 181109645Ssimokawa#define FWXFERQ_STREAM (1 << 9) 182109645Ssimokawa 183109645Ssimokawa#define FWXFERQ_BULK (1 << 11) 184109645Ssimokawa#define FWXFERQ_MODEMASK (7 << 10) 185109645Ssimokawa 186109645Ssimokawa#define FWXFERQ_EXTBUF (1 << 13) 187109645Ssimokawa#define FWXFERQ_OPEN (1 << 14) 188109645Ssimokawa 189109645Ssimokawa#define FWXFERQ_HANDLER (1 << 16) 190109645Ssimokawa#define FWXFERQ_WAKEUP (1 << 17) 191124169Ssimokawa void (*start) (struct firewire_comm*); 192118293Ssimokawa int dmach; 193113584Ssimokawa STAILQ_HEAD(, fw_xfer) q; 194109645Ssimokawa u_int queued; 195109645Ssimokawa u_int maxq; 196109645Ssimokawa u_int psize; 197109645Ssimokawa STAILQ_HEAD(, fw_bind) binds; 198113584Ssimokawa struct fwdma_alloc_multi *buf; 199109645Ssimokawa u_int bnchunk; 200109645Ssimokawa u_int bnpacket; 201109645Ssimokawa struct fw_bulkxfer *bulkxfer; 202109645Ssimokawa STAILQ_HEAD(, fw_bulkxfer) stvalid; 203109645Ssimokawa STAILQ_HEAD(, fw_bulkxfer) stfree; 204109890Ssimokawa STAILQ_HEAD(, fw_bulkxfer) stdma; 205109645Ssimokawa struct fw_bulkxfer *stproc; 206109645Ssimokawa struct selinfo rsel; 207109645Ssimokawa caddr_t sc; 208124169Ssimokawa void (*hand) (struct fw_xferq *); 209109645Ssimokawa}; 210109645Ssimokawa 211109645Ssimokawastruct fw_bulkxfer{ 212113584Ssimokawa int poffset; 213111942Ssimokawa struct mbuf *mbuf; 214109645Ssimokawa STAILQ_ENTRY(fw_bulkxfer) link; 215109645Ssimokawa caddr_t start; 216109645Ssimokawa caddr_t end; 217111942Ssimokawa int resp; 218109645Ssimokawa}; 219109645Ssimokawa 220109645Ssimokawastruct tlabel{ 221109645Ssimokawa struct fw_xfer *xfer; 222109645Ssimokawa STAILQ_ENTRY(tlabel) link; 223109645Ssimokawa}; 224109645Ssimokawa 225109645Ssimokawastruct fw_bind{ 226120660Ssimokawa u_int64_t start; 227120660Ssimokawa u_int64_t end; 228113584Ssimokawa STAILQ_HEAD(, fw_xfer) xferlist; 229109645Ssimokawa STAILQ_ENTRY(fw_bind) fclist; 230109645Ssimokawa STAILQ_ENTRY(fw_bind) chlist; 231113584Ssimokawa#define FWACT_NULL 0 232113584Ssimokawa#define FWACT_XFER 2 233113584Ssimokawa#define FWACT_CH 3 234113584Ssimokawa u_int8_t act_type; 235113584Ssimokawa u_int8_t sub; 236109645Ssimokawa}; 237109645Ssimokawa 238103285Sikobstruct fw_xfer{ 239103285Sikob caddr_t sc; 240103285Sikob struct firewire_comm *fc; 241103285Sikob struct fw_xferq *q; 242110577Ssimokawa struct timeval tv; 243113584Ssimokawa int8_t resp; 244103285Sikob#define FWXF_INIT 0 245103285Sikob#define FWXF_INQ 1 246103285Sikob#define FWXF_START 2 247103285Sikob#define FWXF_SENT 3 248103285Sikob#define FWXF_SENTERR 4 249103285Sikob#define FWXF_BUSY 8 250103285Sikob#define FWXF_RCVD 10 251113584Ssimokawa u_int8_t state; 252103285Sikob u_int8_t retry; 253103285Sikob u_int8_t tl; 254124169Ssimokawa void (*retry_req) (struct fw_xfer *); 255103285Sikob union{ 256124169Ssimokawa void (*hand) (struct fw_xfer *); 257103285Sikob } act; 258103285Sikob struct { 259120660Ssimokawa struct fw_pkt hdr; 260120660Ssimokawa u_int32_t *payload; 261120660Ssimokawa u_int16_t pay_len; 262120660Ssimokawa u_int8_t spd; 263103285Sikob } send, recv; 264103285Sikob struct mbuf *mbuf; 265103285Sikob STAILQ_ENTRY(fw_xfer) link; 266110269Ssimokawa struct malloc_type *malloc; 267103285Sikob}; 268120660Ssimokawa 269120660Ssimokawastruct fw_rcv_buf { 270120660Ssimokawa struct firewire_comm *fc; 271120660Ssimokawa struct fw_xfer *xfer; 272120660Ssimokawa struct iovec *vec; 273120660Ssimokawa u_int nvec; 274120660Ssimokawa u_int8_t spd; 275120660Ssimokawa}; 276120660Ssimokawa 277124169Ssimokawavoid fw_sidrcv (struct firewire_comm *, u_int32_t *, u_int); 278124169Ssimokawavoid fw_rcv (struct fw_rcv_buf *); 279124169Ssimokawavoid fw_xfer_unload ( struct fw_xfer*); 280124169Ssimokawavoid fw_xfer_free_buf ( struct fw_xfer*); 281124169Ssimokawavoid fw_xfer_free ( struct fw_xfer*); 282124169Ssimokawastruct fw_xfer *fw_xfer_alloc (struct malloc_type *); 283124169Ssimokawastruct fw_xfer *fw_xfer_alloc_buf (struct malloc_type *, int, int); 284124169Ssimokawavoid fw_init (struct firewire_comm *); 285124169Ssimokawaint fw_tbuf_update (struct firewire_comm *, int, int); 286124169Ssimokawaint fw_rbuf_update (struct firewire_comm *, int, int); 287124169Ssimokawavoid fw_asybusy (struct fw_xfer *); 288124169Ssimokawaint fw_bindadd (struct firewire_comm *, struct fw_bind *); 289124169Ssimokawaint fw_bindremove (struct firewire_comm *, struct fw_bind *); 290124169Ssimokawaint fw_asyreq (struct firewire_comm *, int, struct fw_xfer*); 291124169Ssimokawavoid fw_busreset (struct firewire_comm *); 292124169Ssimokawau_int16_t fw_crc16 (u_int32_t *, u_int32_t); 293124169Ssimokawavoid fw_xfer_timeout (void *); 294124169Ssimokawavoid fw_xfer_done (struct fw_xfer *); 295124169Ssimokawavoid fw_asy_callback (struct fw_xfer *); 296124169Ssimokawavoid fw_asy_callback_free (struct fw_xfer *); 297124169Ssimokawastruct fw_device *fw_noderesolve_nodeid (struct firewire_comm *, int); 298124169Ssimokawastruct fw_device *fw_noderesolve_eui64 (struct firewire_comm *, struct fw_eui64 *); 299124169Ssimokawastruct fw_bind *fw_bindlookup (struct firewire_comm *, u_int16_t, u_int32_t); 300124169Ssimokawavoid fw_drain_txq (struct firewire_comm *); 301124169Ssimokawaint fwdev_makedev (struct firewire_softc *); 302124169Ssimokawaint fwdev_destroydev (struct firewire_softc *); 303124169Ssimokawavoid fwdev_clone (void *, char *, int, dev_t *); 304103285Sikob 305103285Sikobextern int firewire_debug; 306103285Sikobextern devclass_t firewire_devclass; 307103285Sikob 308103285Sikob#define FWPRI ((PZERO+8)|PCATCH) 309103285Sikob 310111615Ssimokawa#if __FreeBSD_version >= 500000 311111615Ssimokawa#define CALLOUT_INIT(x) callout_init(x, 0 /* mpsafe */) 312111615Ssimokawa#else 313111615Ssimokawa#define CALLOUT_INIT(x) callout_init(x) 314111615Ssimokawa#endif 315111615Ssimokawa 316120660Ssimokawa#if __FreeBSD_version < 500000 317120660Ssimokawa/* compatibility shim for 4.X */ 318120660Ssimokawa#define bio buf 319120660Ssimokawa#define bio_bcount b_bcount 320120660Ssimokawa#define bio_cmd b_flags 321120660Ssimokawa#define bio_count b_count 322120660Ssimokawa#define bio_data b_data 323120660Ssimokawa#define bio_dev b_dev 324120660Ssimokawa#define bio_error b_error 325120660Ssimokawa#define bio_flags b_flags 326120660Ssimokawa#define bio_offset b_offset 327120660Ssimokawa#define bio_resid b_resid 328120660Ssimokawa#define BIO_ERROR B_ERROR 329120660Ssimokawa#define BIO_READ B_READ 330120660Ssimokawa#define BIO_WRITE B_WRITE 331120660Ssimokawa#define MIN(a,b) (((a)<(b))?(a):(b)) 332121780Ssimokawa#define MAX(a,b) (((a)>(b))?(a):(b)) 333120660Ssimokawa#endif 334120660Ssimokawa 335110195SsimokawaMALLOC_DECLARE(M_FW); 336110269SsimokawaMALLOC_DECLARE(M_FWXFER); 337