firewirereg.h revision 139749
1139823Simp/*- 221259Swollman * Copyright (c) 2003 Hidetoshi Shimokawa 321259Swollman * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa 421259Swollman * All rights reserved. 521259Swollman * 621259Swollman * Redistribution and use in source and binary forms, with or without 721259Swollman * modification, are permitted provided that the following conditions 821259Swollman * are met: 921259Swollman * 1. Redistributions of source code must retain the above copyright 1021259Swollman * notice, this list of conditions and the following disclaimer. 1121259Swollman * 2. Redistributions in binary form must reproduce the above copyright 1221259Swollman * notice, this list of conditions and the following disclaimer in the 1321259Swollman * documentation and/or other materials provided with the distribution. 1421259Swollman * 3. All advertising materials mentioning features or use of this software 1521259Swollman * must display the acknowledgement as bellow: 1621259Swollman * 1721259Swollman * This product includes software developed by K. Kobayashi and H. Shimokawa 1821259Swollman * 1921259Swollman * 4. The name of the author may not be used to endorse or promote products 2021259Swollman * derived from this software without specific prior written permission. 2121259Swollman * 2221259Swollman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2321259Swollman * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 2421259Swollman * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 2521259Swollman * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 2621259Swollman * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 2721259Swollman * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 2821259Swollman * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2921259Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 3050477Speter * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 3121259Swollman * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3221259Swollman * POSSIBILITY OF SUCH DAMAGE. 3321259Swollman * 3421259Swollman * $FreeBSD: head/sys/dev/firewire/firewirereg.h 139749 2005-01-06 01:43:34Z imp $ 3521259Swollman * 3621259Swollman */ 3721259Swollman 3821259Swollman#ifdef __DragonFly__ 3921259Swollmantypedef d_thread_t fw_proc; 4021259Swollman#include <sys/select.h> 4121259Swollman#elif __FreeBSD_version >= 500000 4221259Swollmantypedef struct thread fw_proc; 4321259Swollman#include <sys/selinfo.h> 4421259Swollman#else 4521259Swollmantypedef struct proc fw_proc; 4621259Swollman#include <sys/select.h> 4721259Swollman#endif 4821259Swollman 4921259Swollman#include <sys/uio.h> 5021259Swollman 51108533Sschweikh#define splfw splimp 5221259Swollman 5321259Swollmanstruct fw_device{ 5421259Swollman uint16_t dst; 5521259Swollman struct fw_eui64 eui; 56108533Sschweikh uint8_t speed; 5721259Swollman uint8_t maxrec; 5821259Swollman uint8_t nport; 5921259Swollman uint8_t power; 6021259Swollman#define CSRROMOFF 0x400 6121259Swollman#define CSRROMSIZE 0x400 6221259Swollman int rommax; /* offset from 0xffff f000 0000 */ 6321259Swollman uint32_t csrrom[CSRROMSIZE/4]; 6421259Swollman int rcnt; 6521259Swollman struct firewire_comm *fc; 6683366Sjulian uint32_t status; 6721259Swollman#define FWDEVINIT 1 6885074Sru#define FWDEVATTACHED 2 6921259Swollman#define FWDEVINVAL 3 7021259Swollman STAILQ_ENTRY(fw_device) link; 7121259Swollman}; 7221259Swollman 7321259Swollmanstruct firewire_softc { 7421259Swollman#if defined(__FreeBSD__) && __FreeBSD_version >= 500000 7569224Sjlemon struct cdev *dev; 7669152Sjlemon#endif 77126264Smlaier struct firewire_comm *fc; 7869224Sjlemon}; 7974914Sjhb 8074914Sjhb#define FW_MAX_DMACH 0x20 8183130Sjlemon#define FW_MAX_DEVCH FW_MAX_DMACH 82132712Srwatson#define FW_XFERTIMEOUT 1 8369152Sjlemon 84121816Sbrooksstruct firewire_dev_comm { 85121816Sbrooks device_t dev; 86130416Smlaier struct firewire_comm *fc; 87130416Smlaier void (*post_busreset) (void *); 8860938Sjake void (*post_explore) (void *); 8960938Sjake}; 9060938Sjake 9172084Sphkstruct tcode_info { 9221259Swollman u_char hdr_len; /* IEEE1394 header length */ 9321259Swollman u_char flag; 9421259Swollman#define FWTI_REQ (1 << 0) 9521259Swollman#define FWTI_RES (1 << 1) 9621259Swollman#define FWTI_TLABEL (1 << 2) 9721259Swollman#define FWTI_BLOCK_STR (1 << 3) 9821259Swollman#define FWTI_BLOCK_ASY (1 << 4) 9921259Swollman}; 10021259Swollman 10121259Swollmanstruct firewire_comm{ 10269152Sjlemon device_t dev; 10321259Swollman device_t bdev; 10421259Swollman uint16_t busid:10, 10521259Swollman nodeid:6; 10621259Swollman u_int mode; 10721259Swollman u_int nport; 10821259Swollman u_int speed; 10921259Swollman u_int maxrec; 11084380Smjacob u_int irm; 11184380Smjacob u_int max_node; 11284380Smjacob u_int max_hop; 11384380Smjacob u_int max_asyretry; 11486797Sluigi#define FWPHYASYST (1 << 0) 11586797Sluigi u_int retry_count; 11686797Sluigi uint32_t ongobus:10, 11786797Sluigi ongonode:6, 11886797Sluigi ongoaddr:16; 11986797Sluigi struct fw_device *ongodev; 12086797Sluigi struct fw_eui64 ongoeui; 12186797Sluigi#define FWMAXCSRDIR 16 12286797Sluigi SLIST_HEAD(, csrdir) ongocsr; 12386797Sluigi SLIST_HEAD(, csrdir) csrfree; 12486797Sluigi uint32_t status; 12586797Sluigi#define FWBUSNOTREADY (-1) 12686797Sluigi#define FWBUSRESET 0 12786797Sluigi#define FWBUSINIT 1 12886797Sluigi#define FWBUSCYMELECT 2 12984380Smjacob#define FWBUSMGRELECT 3 13021259Swollman#define FWBUSMGRDONE 4 13121259Swollman#define FWBUSEXPLORE 5 13260938Sjake#define FWBUSPHYCONF 6 133121816Sbrooks#define FWBUSEXPDONE 7 134121816Sbrooks#define FWBUSCOMPLETION 10 135121816Sbrooks int nisodma; 13621259Swollman struct fw_eui64 eui; 137128291Sluigi struct fw_xferq 138128291Sluigi *arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH]; 139128315Sluigi STAILQ_HEAD(, tlabel) tlabels[0x40]; 140128315Sluigi STAILQ_HEAD(, fw_bind) binds; 141128315Sluigi STAILQ_HEAD(, fw_device) devices; 142128315Sluigi u_int sid_cnt; 143128291Sluigi#define CSRSIZE 0x4000 144128315Sluigi uint32_t csr_arc[CSRSIZE/4]; 145128315Sluigi#define CROMSIZE 0x400 146128291Sluigi uint32_t *config_rom; 147133741Sjmg struct crom_src_buf *crom_src_buf; 14883130Sjlemon struct crom_src *crom_src; 149133261Smlaier struct crom_chunk *crom_root; 15021259Swollman struct fw_topology_map *topology_map; 15121259Swollman struct fw_speed_map *speed_map; 15221259Swollman struct callout busprobe_callout; 153106931Ssam struct callout bmr_callout; 154102052Ssobomax struct callout timeout_callout; 15583624Sjlemon struct callout retry_probe_callout; 15683624Sjlemon uint32_t (*cyctimer) (struct firewire_comm *); 15721259Swollman void (*ibr) (struct firewire_comm *); 15821259Swollman uint32_t (*set_bmr) (struct firewire_comm *, uint32_t); 15921259Swollman int (*ioctl) (struct cdev *, u_long, caddr_t, int, fw_proc *); 16021404Swollman int (*irx_enable) (struct firewire_comm *, int); 16121404Swollman int (*irx_disable) (struct firewire_comm *, int); 16221259Swollman int (*itx_enable) (struct firewire_comm *, int); 16321259Swollman int (*itx_disable) (struct firewire_comm *, int); 16492725Salfred void (*timeout) (void *); 16592725Salfred void (*poll) (struct firewire_comm *, int, int); 166106931Ssam void (*set_intr) (struct firewire_comm *, int); 167106931Ssam void (*irx_post) (struct firewire_comm *, uint32_t *); 16821259Swollman void (*itx_post) (struct firewire_comm *, uint32_t *); 16992725Salfred struct tcode_info *tcode; 17021259Swollman bus_dma_tag_t dmat; 17192725Salfred}; 17221259Swollman#define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4]) 17392725Salfred 17421259Swollmanstruct csrdir{ 17592725Salfred uint32_t ongoaddr; 17621404Swollman uint32_t off; 17792725Salfred SLIST_ENTRY(csrdir) link; 178137062Srwatson}; 179137062Srwatson 180137062Srwatsonstruct fw_xferq { 181137062Srwatson int flag; 182137062Srwatson#define FWXFERQ_CHTAGMASK 0xff 183130416Smlaier#define FWXFERQ_RUNNING (1 << 8) 184123220Simp#define FWXFERQ_STREAM (1 << 9) 185127828Sluigi 186127828Sluigi#define FWXFERQ_BULK (1 << 11) 187127828Sluigi#define FWXFERQ_MODEMASK (7 << 10) 188122524Srwatson 189121161Sume#define FWXFERQ_EXTBUF (1 << 13) 190127828Sluigi#define FWXFERQ_OPEN (1 << 14) 191127828Sluigi 192121161Sume#define FWXFERQ_HANDLER (1 << 16) 193121470Sume#define FWXFERQ_WAKEUP (1 << 17) 194121470Sume void (*start) (struct firewire_comm*); 195132712Srwatson int dmach; 19621259Swollman STAILQ_HEAD(, fw_xfer) q; 19769152Sjlemon u_int queued; 19892725Salfred u_int maxq; 19921259Swollman u_int psize; 200128376Sluigi STAILQ_HEAD(, fw_bind) binds; 201128376Sluigi struct fwdma_alloc_multi *buf; 202128376Sluigi u_int bnchunk; 203128376Sluigi u_int bnpacket; 20421259Swollman struct fw_bulkxfer *bulkxfer; 20521259Swollman STAILQ_HEAD(, fw_bulkxfer) stvalid; 20621259Swollman STAILQ_HEAD(, fw_bulkxfer) stfree; 20721259Swollman STAILQ_HEAD(, fw_bulkxfer) stdma; 20821259Swollman struct fw_bulkxfer *stproc; 20921259Swollman struct selinfo rsel; 210128871Sandre caddr_t sc; 21121259Swollman void (*hand) (struct fw_xferq *); 21258698Sjlemon}; 21321259Swollman 21421259Swollmanstruct fw_bulkxfer{ 21521259Swollman int poffset; 21621259Swollman struct mbuf *mbuf; 21721259Swollman STAILQ_ENTRY(fw_bulkxfer) link; 21821259Swollman caddr_t start; 21921259Swollman caddr_t end; 22021259Swollman int resp; 22121259Swollman}; 22221259Swollman 22321259Swollmanstruct tlabel{ 22421259Swollman struct fw_xfer *xfer; 22521259Swollman STAILQ_ENTRY(tlabel) link; 22621259Swollman}; 227136950Sjmg 22821259Swollmanstruct fw_bind{ 22953541Sshin u_int64_t start; 23053541Sshin u_int64_t end; 23153541Sshin STAILQ_HEAD(, fw_xfer) xferlist; 23253541Sshin STAILQ_ENTRY(fw_bind) fclist; 23321259Swollman STAILQ_ENTRY(fw_bind) chlist; 23421259Swollman#define FWACT_NULL 0 23521259Swollman#define FWACT_XFER 2 23621259Swollman#define FWACT_CH 3 23721259Swollman uint8_t act_type; 23821259Swollman uint8_t sub; 23972200Sbmilekic}; 24072200Sbmilekic 241130416Smlaierstruct fw_xfer{ 24269152Sjlemon caddr_t sc; 24369152Sjlemon struct firewire_comm *fc; 24469152Sjlemon struct fw_xferq *q; 24521259Swollman struct timeval tv; 24669152Sjlemon int8_t resp; 24769152Sjlemon#define FWXF_INIT 0 24869152Sjlemon#define FWXF_INQ 1 24969152Sjlemon#define FWXF_START 2 25069152Sjlemon#define FWXF_SENT 3 25169152Sjlemon#define FWXF_SENTERR 4 25269152Sjlemon#define FWXF_BUSY 8 25369152Sjlemon#define FWXF_RCVD 10 25469152Sjlemon uint8_t state; 25569152Sjlemon uint8_t retry; 25669152Sjlemon uint8_t tl; 25769152Sjlemon void (*retry_req) (struct fw_xfer *); 25869152Sjlemon union{ 25969152Sjlemon void (*hand) (struct fw_xfer *); 26069152Sjlemon } act; 26169152Sjlemon struct { 26269152Sjlemon struct fw_pkt hdr; 26369152Sjlemon uint32_t *payload; 26469152Sjlemon uint16_t pay_len; 26569152Sjlemon uint8_t spd; 26669152Sjlemon } send, recv; 26769152Sjlemon struct mbuf *mbuf; 26869152Sjlemon STAILQ_ENTRY(fw_xfer) link; 26969152Sjlemon struct malloc_type *malloc; 27069152Sjlemon}; 27169152Sjlemon 27269152Sjlemonstruct fw_rcv_buf { 27369152Sjlemon struct firewire_comm *fc; 27469152Sjlemon struct fw_xfer *xfer; 27569152Sjlemon struct iovec *vec; 27669152Sjlemon u_int nvec; 27769152Sjlemon uint8_t spd; 27869152Sjlemon}; 279136950Sjmg 28069152Sjlemonvoid fw_sidrcv (struct firewire_comm *, uint32_t *, u_int); 28169152Sjlemonvoid fw_rcv (struct fw_rcv_buf *); 28269152Sjlemonvoid fw_xfer_unload ( struct fw_xfer*); 28369152Sjlemonvoid fw_xfer_free_buf ( struct fw_xfer*); 28469152Sjlemonvoid fw_xfer_free ( struct fw_xfer*); 28569152Sjlemonstruct fw_xfer *fw_xfer_alloc (struct malloc_type *); 28669152Sjlemonstruct fw_xfer *fw_xfer_alloc_buf (struct malloc_type *, int, int); 28769152Sjlemonvoid fw_init (struct firewire_comm *); 28869152Sjlemonint fw_tbuf_update (struct firewire_comm *, int, int); 28969152Sjlemonint fw_rbuf_update (struct firewire_comm *, int, int); 29069152Sjlemonvoid fw_asybusy (struct fw_xfer *); 29169152Sjlemonint fw_bindadd (struct firewire_comm *, struct fw_bind *); 292130416Smlaierint fw_bindremove (struct firewire_comm *, struct fw_bind *); 293130416Smlaierint fw_asyreq (struct firewire_comm *, int, struct fw_xfer*); 294130416Smlaiervoid fw_busreset (struct firewire_comm *); 295130416Smlaieruint16_t fw_crc16 (uint32_t *, uint32_t); 29669152Sjlemonvoid fw_xfer_timeout (void *); 29769152Sjlemonvoid fw_xfer_done (struct fw_xfer *); 29869152Sjlemonvoid fw_asy_callback (struct fw_xfer *); 29969152Sjlemonvoid fw_asy_callback_free (struct fw_xfer *); 30069152Sjlemonstruct fw_device *fw_noderesolve_nodeid (struct firewire_comm *, int); 30169152Sjlemonstruct fw_device *fw_noderesolve_eui64 (struct firewire_comm *, struct fw_eui64 *); 30269152Sjlemonstruct fw_bind *fw_bindlookup (struct firewire_comm *, uint16_t, uint32_t); 30369152Sjlemonvoid fw_drain_txq (struct firewire_comm *); 30469152Sjlemonint fwdev_makedev (struct firewire_softc *); 305130416Smlaierint fwdev_destroydev (struct firewire_softc *); 306130416Smlaiervoid fwdev_clone (void *, char *, int, struct cdev **); 307130416Smlaier 308130416Smlaierextern int firewire_debug; 309130416Smlaierextern devclass_t firewire_devclass; 310130416Smlaier 31155205Speter#ifdef __DragonFly__ 312126264Smlaier#define FWPRI PCATCH 313126264Smlaier#else 314126264Smlaier#define FWPRI ((PZERO+8)|PCATCH) 315126264Smlaier#endif 316126264Smlaier 317126264Smlaier#if defined(__DragonFly__) || __FreeBSD_version < 500000 318126264Smlaier#define CALLOUT_INIT(x) callout_init(x) 319126264Smlaier#else 320126264Smlaier#define CALLOUT_INIT(x) callout_init(x, 0 /* mpsafe */) 321126264Smlaier#endif 322121470Sume 323121470Sume#if defined(__DragonFly__) || __FreeBSD_version < 500000 324121470Sume/* compatibility shim for 4.X */ 325121470Sume#define bio buf 326121470Sume#define bio_bcount b_bcount 327121470Sume#define bio_cmd b_flags 328121470Sume#define bio_count b_count 329136704Srwatson#define bio_data b_data 330136704Srwatson#define bio_dev b_dev 331136704Srwatson#define bio_error b_error 332136704Srwatson#define bio_flags b_flags 333136704Srwatson#define bio_offset b_offset 334136704Srwatson#define bio_resid b_resid 335136704Srwatson#define BIO_ERROR B_ERROR 336136704Srwatson#define BIO_READ B_READ 337136704Srwatson#define BIO_WRITE B_WRITE 338136704Srwatson#define MIN(a,b) (((a)<(b))?(a):(b)) 339137065Srwatson#define MAX(a,b) (((a)>(b))?(a):(b)) 340137065Srwatson#endif 341130416Smlaier 342130416SmlaierMALLOC_DECLARE(M_FW); 343130416SmlaierMALLOC_DECLARE(M_FWXFER); 344130416Smlaier