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