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