Home | History | Annotate | Line # | Download | only in ieee1394
firewirereg.h revision 1.8
      1 /*	$NetBSD: firewirereg.h,v 1.8 2008/03/29 16:22:53 kiyohara 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: src/sys/dev/firewire/firewirereg.h,v 1.50 2007/07/20 03:42:57 simokawa 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 	fw_dev_t dev;
     68 	device_t sbp_dev;
     69 #elif defined(__NetBSD__)
     70 	device_t dev;
     71 	SLIST_HEAD(, firewire_dev_list) devlist;
     72 	void *si_drv1;
     73 	int si_iosize_max;
     74 #endif
     75 	struct firewire_comm *fc;
     76 };
     77 #if defined(__NetBSD__)
     78 struct firewire_dev_list {
     79 	SLIST_ENTRY(firewire_dev_list) link;
     80 	device_t dev;
     81 	struct fw_device *fwdev;
     82 };
     83 #endif
     84 
     85 #define FW_MAX_DMACH 0x20
     86 #define FW_MAX_DEVCH FW_MAX_DMACH
     87 #define FW_XFERTIMEOUT 1
     88 
     89 struct firewire_dev_comm {
     90 	device_t dev;
     91 	struct firewire_comm *fc;
     92 	void (*post_busreset) (void *);
     93 	void (*post_explore) (void *);
     94 };
     95 
     96 struct tcode_info {
     97 	u_char hdr_len;	/* IEEE1394 header length */
     98 	u_char flag;
     99 #define FWTI_REQ	(1 << 0)
    100 #define FWTI_RES	(1 << 1)
    101 #define FWTI_TLABEL	(1 << 2)
    102 #define FWTI_BLOCK_STR	(1 << 3)
    103 #define FWTI_BLOCK_ASY	(1 << 4)
    104 	u_char valid_res;
    105 };
    106 
    107 struct firewire_comm{
    108 	device_t dev;
    109 	device_t bdev;
    110 	uint16_t busid:10,
    111 		  nodeid:6;
    112 	u_int mode;
    113 	u_int nport;
    114 	u_int speed;
    115 	u_int maxrec;
    116 	u_int irm;
    117 	u_int max_node;
    118 	u_int max_hop;
    119 #define FWPHYASYST (1 << 0)
    120 	uint32_t status;
    121 #define	FWBUSDETACH	(-2)
    122 #define	FWBUSNOTREADY	(-1)
    123 #define	FWBUSRESET	0
    124 #define	FWBUSINIT	1
    125 #define	FWBUSCYMELECT	2
    126 #define	FWBUSMGRELECT	3
    127 #define	FWBUSMGRDONE	4
    128 #define	FWBUSEXPLORE	5
    129 #define	FWBUSPHYCONF	6
    130 #define	FWBUSEXPDONE	7
    131 #define	FWBUSCOMPLETION	10
    132 	int nisodma;
    133 	struct fw_eui64 eui;
    134 	struct fw_xferq
    135 		*arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH];
    136 	struct fw_xferlist tlabels[0x40];
    137 	u_char last_tlabel[0x40];
    138 	fw_mtx_t tlabel_lock;
    139 	STAILQ_HEAD(, fw_bind) binds;
    140 	STAILQ_HEAD(, fw_device) devices;
    141 	u_int  sid_cnt;
    142 #define CSRSIZE 0x4000
    143 	uint32_t csr_arc[CSRSIZE/4];
    144 #define CROMSIZE 0x400
    145 	uint32_t *config_rom;
    146 	struct crom_src_buf *crom_src_buf;
    147 	struct crom_src *crom_src;
    148 	struct crom_chunk *crom_root;
    149 	struct fw_topology_map *topology_map;
    150 	struct fw_speed_map *speed_map;
    151 	struct callout busprobe_callout;
    152 	struct callout bmr_callout;
    153 	struct callout timeout_callout;
    154 	fw_task_t task_timeout;
    155 	uint32_t (*cyctimer) (struct  firewire_comm *);
    156 	void (*ibr) (struct firewire_comm *);
    157 	uint32_t (*set_bmr) (struct firewire_comm *, uint32_t);
    158 	int (*ioctl) (fw_dev_t, u_long, void *, int, fw_proc_t);
    159 	int (*irx_enable) (struct firewire_comm *, int);
    160 	int (*irx_disable) (struct firewire_comm *, int);
    161 	int (*itx_enable) (struct firewire_comm *, int);
    162 	int (*itx_disable) (struct firewire_comm *, int);
    163 	void (*timeout) (void *);
    164 	void (*poll) (struct firewire_comm *, int, int);
    165 	void (*set_intr) (struct firewire_comm *, int);
    166 	void (*irx_post) (struct firewire_comm *, uint32_t *);
    167 	void (*itx_post) (struct firewire_comm *, uint32_t *);
    168 	const struct tcode_info *tcode;
    169 	bus_dma_tag_t dmat;
    170 	fw_mtx_t mtx;
    171 	fw_mtx_t wait_lock;
    172 	struct taskqueue *taskqueue;
    173 	fw_proc_t probe_thread;
    174 };
    175 #define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4])
    176 
    177 #define FW_GMTX(fc)		(&(fc)->mtx)
    178 #define FW_GLOCK(fc)		fw_mtx_lock(FW_GMTX(fc))
    179 #define FW_GUNLOCK(fc)		fw_mtx_unlock(FW_GMTX(fc))
    180 #define FW_GLOCK_ASSERT(fc)	fw_mtx_assert(FW_GMTX(fc), MA_OWNED)
    181 
    182 struct fw_xferq {
    183 	int flag;
    184 #define FWXFERQ_CHTAGMASK 0xff
    185 #define FWXFERQ_RUNNING (1 << 8)
    186 #define FWXFERQ_STREAM (1 << 9)
    187 
    188 #define FWXFERQ_BULK (1 << 11)
    189 #define FWXFERQ_MODEMASK (7 << 10)
    190 
    191 #define FWXFERQ_EXTBUF (1 << 13)
    192 #define FWXFERQ_OPEN (1 << 14)
    193 
    194 #define FWXFERQ_HANDLER (1 << 16)
    195 #define FWXFERQ_WAKEUP (1 << 17)
    196 	void (*start) (struct firewire_comm*);
    197 	int dmach;
    198 	struct fw_xferlist q;
    199 	u_int queued;
    200 	u_int maxq;
    201 	u_int psize;
    202 	struct fwdma_alloc_multi *buf;
    203 	u_int bnchunk;
    204 	u_int bnpacket;
    205 	struct fw_bulkxfer *bulkxfer;
    206 	STAILQ_HEAD(, fw_bulkxfer) stvalid;
    207 	STAILQ_HEAD(, fw_bulkxfer) stfree;
    208 	STAILQ_HEAD(, fw_bulkxfer) stdma;
    209 	struct fw_bulkxfer *stproc;
    210 	struct selinfo rsel;
    211 	void *sc;
    212 	void (*hand) (struct fw_xferq *);
    213 };
    214 
    215 struct fw_bulkxfer{
    216 	int poffset;
    217 	struct mbuf *mbuf;
    218 	STAILQ_ENTRY(fw_bulkxfer) link;
    219 	void *start;
    220 	void *end;
    221 	int resp;
    222 };
    223 
    224 struct fw_bind{
    225 	u_int64_t start;
    226 	u_int64_t end;
    227 	struct fw_xferlist xferlist;
    228 	STAILQ_ENTRY(fw_bind) fclist;
    229 	STAILQ_ENTRY(fw_bind) chlist;
    230 	void *sc;
    231 };
    232 
    233 struct fw_xfer{
    234 	void *sc;
    235 	struct firewire_comm *fc;
    236 	struct fw_xferq *q;
    237 	struct timeval tv;
    238 	int8_t resp;
    239 #define FWXF_INIT	0x00
    240 #define FWXF_INQ	0x01
    241 #define FWXF_START	0x02
    242 #define FWXF_SENT	0x04
    243 #define FWXF_SENTERR	0x08
    244 #define FWXF_BUSY	0x10
    245 #define FWXF_RCVD	0x20
    246 
    247 #define FWXF_WAKE	0x80
    248 	uint8_t flag;
    249 	int8_t tl;
    250 	void (*hand) (struct fw_xfer *);
    251 	struct {
    252 		struct fw_pkt hdr;
    253 		uint32_t *payload;
    254 		uint16_t pay_len;
    255 		uint8_t spd;
    256 	} send, recv;
    257 	struct mbuf *mbuf;
    258 	STAILQ_ENTRY(fw_xfer) link;
    259 	STAILQ_ENTRY(fw_xfer) tlabel;
    260 	struct malloc_type *malloc;
    261 };
    262 
    263 struct fw_rcv_buf {
    264 	struct firewire_comm *fc;
    265 	struct fw_xfer *xfer;
    266 	struct iovec *vec;
    267 	u_int nvec;
    268 	uint8_t spd;
    269 };
    270 
    271 void fw_sidrcv (struct firewire_comm *, uint32_t *, u_int);
    272 void fw_rcv (struct fw_rcv_buf *);
    273 void fw_xfer_unload ( struct fw_xfer*);
    274 void fw_xfer_free_buf ( struct fw_xfer*);
    275 void fw_xfer_free ( struct fw_xfer*);
    276 struct fw_xfer *fw_xfer_alloc (struct malloc_type *);
    277 struct fw_xfer *fw_xfer_alloc_buf (struct malloc_type *, int, int);
    278 void fw_init (struct firewire_comm *);
    279 int fw_tbuf_update (struct firewire_comm *, int, int);
    280 int fw_rbuf_update (struct firewire_comm *, int, int);
    281 int fw_bindadd (struct firewire_comm *, struct fw_bind *);
    282 int fw_bindremove (struct firewire_comm *, struct fw_bind *);
    283 int fw_xferlist_add (struct fw_xferlist *, struct malloc_type *, int, int, int,
    284     struct firewire_comm *, void *, void (*)(struct fw_xfer *));
    285 void fw_xferlist_remove (struct fw_xferlist *);
    286 int fw_asyreq (struct firewire_comm *, int, struct fw_xfer*);
    287 void fw_busreset (struct firewire_comm *, uint32_t);
    288 uint16_t fw_crc16 (uint32_t *, uint32_t);
    289 void fw_xfer_timeout (void *);
    290 void fw_xfer_done (struct fw_xfer *);
    291 void fw_xferwake  (struct fw_xfer *);
    292 int fw_xferwait (struct fw_xfer *);
    293 void fw_asy_callback_free (struct fw_xfer *);
    294 struct fw_device *fw_noderesolve_nodeid (struct firewire_comm *, int);
    295 struct fw_device *fw_noderesolve_eui64 (struct firewire_comm *, struct fw_eui64 *);
    296 struct fw_bind *fw_bindlookup (struct firewire_comm *, uint16_t, uint32_t);
    297 void fw_drain_txq (struct firewire_comm *);
    298 int fwdev_makedev (struct firewire_softc *);
    299 int fwdev_destroydev (struct firewire_softc *);
    300 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
    301 void fwdev_clone (void *, struct ucred *, char *, int, fw_dev_t *);
    302 #endif
    303 int fw_open_isodma(struct firewire_comm *, int);
    304 
    305 extern int firewire_debug;
    306 #if defined(__FreeBSD__)
    307 extern devclass_t firewire_devclass;
    308 #elif defined(__NetBSD__)
    309 extern struct cfdriver ieee1394if_cd;
    310 #endif
    311 extern int firewire_phydma_enable;
    312 
    313 #ifdef __DragonFly__
    314 #define		FWPRI		PCATCH
    315 #else
    316 #define		FWPRI		((PZERO+8)|PCATCH)
    317 #endif
    318 
    319 #if defined(__DragonFly__) || __FreeBSD_version < 500000 || defined(__NetBSD__)
    320 /* compatibility shim for 4.X */
    321 #define bio buf
    322 #define bio_bcount b_bcount
    323 #define bio_cmd b_flags
    324 #define bio_count b_count
    325 #define bio_data b_data
    326 #define bio_dev b_dev
    327 #define bio_error b_error
    328 #define bio_flags b_flags
    329 #if defined(__FreeBSD__)
    330 #define bio_offset b_offset
    331 #elif defined(__NetBSD__)
    332 #define bio_offset b_blkno
    333 #endif
    334 #define bio_resid b_resid
    335 #define BIO_READ B_READ
    336 #define BIO_WRITE B_WRITE
    337 #define MIN(a,b) (((a)<(b))?(a):(b))
    338 #define MAX(a,b) (((a)>(b))?(a):(b))
    339 #endif
    340 
    341 MALLOC_DECLARE(M_FW);
    342 MALLOC_DECLARE(M_FWXFER);
    343