1 /*- 2 * Copyright (c) 2003 Hidetoshi Shimokawa 3 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the acknowledgement as bellow: 16 * 17 * This product includes software developed by K. Kobayashi and H. Shimokawa 18 * 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 * POSSIBILITY OF SUCH DAMAGE. 33 * 34 * $FreeBSD: src/sys/dev/firewire/firewirereg.h,v 1.49 2007/07/15 13:20:48 simokawa Exp $ 35 * 36 */ 37 #ifndef _FIREWIREREG_H 38 #define _FIREWIREREG_H 39 #ifdef __HAIKU__ 40 #include <OS.h> 41 #else 42 #ifdef __DragonFly__ 43 typedef d_thread_t fw_proc; 44 #include <sys/select.h> 45 #elif __FreeBSD_version >= 500000 46 typedef struct thread fw_proc; 47 #include <sys/selinfo.h> 48 #else 49 typedef struct proc fw_proc; 50 #include <sys/select.h> 51 #endif 52 #endif/*__HAIKU__*/ 53 54 #include <sys/uio.h> 55 56 #ifndef __HAIKU__ 57 #include <sys/mutex.h> 58 #include <sys/taskqueue.h> 59 #define splfw splimp 60 #else 61 #include <lock.h> 62 #include <dpc.h> 63 #include "fwglue.h" 64 #include "timer.h" 65 #endif 66 67 #define MAX_REQCOUNT 0xffff 68 69 STAILQ_HEAD(fw_xferlist, fw_xfer); 70 71 struct fw_device{ 72 uint16_t dst; 73 struct fw_eui64 eui; 74 uint8_t speed; 75 uint8_t maxrec; 76 uint8_t nport; 77 uint8_t power; 78 #define CSRROMOFF 0x400 79 #define CSRROMSIZE 0x400 80 int rommax; /* offset from 0xffff f000 0000 */ 81 uint32_t csrrom[CSRROMSIZE/4]; 82 int rcnt; 83 struct firewire_comm *fc; 84 uint32_t status; 85 #define FWDEVINIT 1 86 #define FWDEVATTACHED 2 87 #define FWDEVINVAL 3 88 STAILQ_ENTRY(fw_device) link; 89 }; 90 91 struct firewire_softc { 92 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 93 struct cdev *dev; 94 #endif 95 struct firewire_comm *fc; 96 }; 97 98 #define FW_MAX_DMACH 0x20 99 #define FW_MAX_DEVCH FW_MAX_DMACH 100 #define FW_XFERTIMEOUT 1 101 102 struct firewire_dev_comm { 103 #ifndef __HAIKU__ 104 device_t dev; 105 #endif 106 struct firewire_comm *fc; 107 void (*post_busreset) (void *); 108 void (*post_explore) (void *); 109 }; 110 111 struct tcode_info { 112 u_char hdr_len; /* IEEE1394 header length */ 113 u_char flag; 114 #define FWTI_REQ (1 << 0) 115 #define FWTI_RES (1 << 1) 116 #define FWTI_TLABEL (1 << 2) 117 #define FWTI_BLOCK_STR (1 << 3) 118 #define FWTI_BLOCK_ASY (1 << 4) 119 u_char valid_res; 120 }; 121 122 #ifdef __HAIKU__ 123 struct crom_src_buf { 124 struct crom_src src; 125 struct crom_chunk root; 126 struct crom_chunk vendor; 127 struct crom_chunk hw; 128 };//move from firewire.c to here 129 130 struct firewire_notify_hooks { 131 status_t (*device_attach)(struct firewire_softc *sc, void **cookie); 132 status_t (*device_detach)(struct firewire_softc *sc, void *cookie); 133 }; 134 135 struct firewire_child_info { 136 const char *child_name; 137 void *cookie; 138 struct firewire_notify_hooks notify_hooks; 139 struct firewire_child_info *link; 140 }; 141 #endif 142 143 struct firewire_comm{ 144 #ifndef __HAIKU__ 145 device_t dev; 146 device_t bdev; 147 #endif 148 uint16_t busid:10, 149 nodeid:6; 150 u_int mode; 151 u_int nport; 152 u_int speed; 153 u_int maxrec; 154 u_int irm; 155 u_int max_node; 156 u_int max_hop; 157 #define FWPHYASYST (1 << 0) 158 uint32_t status; 159 #define FWBUSDETACH (-2) 160 #define FWBUSNOTREADY (-1) 161 #define FWBUSRESET 0 162 #define FWBUSINIT 1 163 #define FWBUSCYMELECT 2 164 #define FWBUSMGRELECT 3 165 #define FWBUSMGRDONE 4 166 #define FWBUSEXPLORE 5 167 #define FWBUSPHYCONF 6 168 #define FWBUSEXPDONE 7 169 #define FWBUSCOMPLETION 10 170 int nisodma; 171 struct fw_eui64 eui; 172 struct fw_xferq 173 *arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH]; 174 struct fw_xferlist tlabels[0x40]; 175 u_char last_tlabel[0x40]; 176 STAILQ_HEAD(, fw_bind) binds; 177 STAILQ_HEAD(, fw_device) devices; 178 u_int sid_cnt; 179 #define CSRSIZE 0x4000 180 uint32_t csr_arc[CSRSIZE/4]; 181 #define CROMSIZE 0x400 182 uint32_t *config_rom; 183 struct crom_src_buf *crom_src_buf; 184 struct crom_src *crom_src; 185 struct crom_chunk *crom_root; 186 struct fw_topology_map *topology_map; 187 struct fw_speed_map *speed_map; 188 #ifndef __HAIKU__ 189 struct callout busprobe_callout; 190 struct callout bmr_callout; 191 struct callout timeout_callout; 192 struct task task_timeout; 193 #else 194 timer_id busprobe_callout; 195 timer_id bmr_callout; 196 timer_id timeout_callout; 197 #endif 198 uint32_t (*cyctimer) (struct firewire_comm *); 199 void (*ibr) (struct firewire_comm *); 200 uint32_t (*set_bmr) (struct firewire_comm *, uint32_t); 201 #ifndef __HAIKU__ 202 int (*ioctl) (struct cdev *, u_long, caddr_t, int, fw_proc *); 203 #else 204 int (*ioctl) (void *cookie, uint32 cmd, void *arg, size_t len); 205 #endif 206 int (*irx_enable) (struct firewire_comm *, int); 207 int (*irx_disable) (struct firewire_comm *, int); 208 int (*itx_enable) (struct firewire_comm *, int); 209 int (*itx_disable) (struct firewire_comm *, int); 210 void (*timeout) (void *); 211 void (*poll) (struct firewire_comm *, int, int); 212 void (*set_intr) (struct firewire_comm *, int); 213 void (*irx_post) (struct firewire_comm *, uint32_t *); 214 void (*itx_post) (struct firewire_comm *, uint32_t *); 215 struct tcode_info *tcode; 216 #ifndef __HAIKU__ 217 bus_dma_tag_t dmat; 218 struct mtx mtx; 219 struct mtx wait_lock; 220 struct taskqueue *taskqueue; 221 struct proc *probe_thread; 222 #else 223 benaphore mtx; 224 benaphore wait_lock; 225 void *taskqueue; 226 thread_id probe_thread; 227 sem_id Sem; 228 area_id crom_sid_Area; 229 struct firewire_child_info *childList; 230 #endif 231 }; 232 #define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4]) 233 234 #define FW_GMTX(fc) (&(fc)->mtx) 235 #define FW_GLOCK(fc) mtx_lock(FW_GMTX(fc)) 236 #define FW_GUNLOCK(fc) mtx_unlock(FW_GMTX(fc)) 237 #ifndef __HAIKU__ 238 #define FW_GLOCK_ASSERT(fc) mtx_assert(FW_GMTX(fc), MA_OWNED) 239 #else 240 #define FW_GLOCK_ASSERT(fc) 241 #endif 242 243 struct fw_xferq { 244 int flag; 245 #define FWXFERQ_CHTAGMASK 0xff 246 #define FWXFERQ_RUNNING (1 << 8) 247 #define FWXFERQ_STREAM (1 << 9) 248 249 #define FWXFERQ_BULK (1 << 11) 250 #define FWXFERQ_MODEMASK (7 << 10) 251 252 #define FWXFERQ_EXTBUF (1 << 13) 253 #define FWXFERQ_OPEN (1 << 14) 254 255 #define FWXFERQ_HANDLER (1 << 16) 256 #define FWXFERQ_WAKEUP (1 << 17) 257 void (*start) (struct firewire_comm*); 258 int dmach; 259 struct fw_xferlist q; 260 u_int queued; 261 u_int maxq; 262 u_int psize; 263 struct fwdma_alloc_multi *buf; 264 u_int bnchunk; 265 u_int bnpacket; 266 struct fw_bulkxfer *bulkxfer; 267 STAILQ_HEAD(, fw_bulkxfer) stvalid; 268 STAILQ_HEAD(, fw_bulkxfer) stfree; 269 STAILQ_HEAD(, fw_bulkxfer) stdma; 270 struct fw_bulkxfer *stproc; 271 // struct selinfo rsel; 272 caddr_t sc; 273 void (*hand) (struct fw_xferq *); 274 spinlock Spinlock; 275 sem_id Sem; 276 }; 277 278 struct fw_bulkxfer{ 279 int poffset; 280 // struct mbuf *mbuf; 281 STAILQ_ENTRY(fw_bulkxfer) link; 282 caddr_t start; 283 caddr_t end; 284 int resp; 285 }; 286 287 struct fw_bind{ 288 u_int64_t start; 289 u_int64_t end; 290 struct fw_xferlist xferlist; 291 STAILQ_ENTRY(fw_bind) fclist; 292 STAILQ_ENTRY(fw_bind) chlist; 293 void *sc; 294 }; 295 296 struct fw_xfer{ 297 caddr_t sc; 298 struct firewire_comm *fc; 299 struct fw_xferq *q; 300 // struct timeval tv; 301 bigtime_t tv; 302 303 int32_t resp; 304 #define FWXF_INIT 0x00 305 #define FWXF_INQ 0x01 306 #define FWXF_START 0x02 307 #define FWXF_SENT 0x04 308 #define FWXF_SENTERR 0x08 309 #define FWXF_BUSY 0x10 310 #define FWXF_RCVD 0x20 311 312 #define FWXF_WAKE 0x80 313 uint8_t flag; 314 int8_t tl; 315 void (*hand) (struct fw_xfer *); 316 struct send_recv{ 317 struct fw_pkt hdr; 318 uint32_t *payload; 319 area_id payArea; 320 bus_addr_t bus_addr; 321 uint16_t pay_len; 322 uint8_t spd; 323 } send, recv; 324 // struct mbuf *mbuf; 325 STAILQ_ENTRY(fw_xfer) link; 326 STAILQ_ENTRY(fw_xfer) tlabel; 327 // struct malloc_type *malloc; 328 sem_id Sem; 329 }; 330 331 struct fw_rcv_buf { 332 struct firewire_comm *fc; 333 struct fw_xfer *xfer; 334 struct iovec *vec; 335 u_int nvec; 336 uint8_t spd; 337 }; 338 //#ifndef __HAIKU__ 339 void fw_sidrcv (struct firewire_comm *, uint32_t *, u_int); 340 void fw_rcv (struct fw_rcv_buf *); 341 void fw_xfer_unload ( struct fw_xfer*); 342 void fw_xfer_free_buf ( struct fw_xfer*); 343 void fw_xfer_free ( struct fw_xfer*); 344 struct fw_xfer *fw_xfer_alloc (); 345 struct fw_xfer *fw_xfer_alloc_buf (int, int); 346 void fw_init (struct firewire_comm *); 347 int fw_tbuf_update (struct firewire_comm *, int, int); 348 int fw_rbuf_update (struct firewire_comm *, int, int); 349 int fw_bindadd (struct firewire_comm *, struct fw_bind *); 350 int fw_bindremove (struct firewire_comm *, struct fw_bind *); 351 int fw_xferlist_add (struct fw_xferlist *, int, int, int, 352 struct firewire_comm *, void *, void (*)(struct fw_xfer *)); 353 void fw_xferlist_remove (struct fw_xferlist *); 354 int fw_asyreq (struct firewire_comm *, int, struct fw_xfer*); 355 void fw_busreset (struct firewire_comm *, uint32_t); 356 uint16_t fw_crc16 (uint32_t *, uint32_t); 357 void fw_xfer_timeout (void *); 358 void fw_xfer_done (struct fw_xfer *); 359 void fw_xferwake (struct fw_xfer *); 360 int fw_xferwait (struct fw_xfer *); 361 void fw_asy_callback_free (struct fw_xfer *); 362 struct fw_device *fw_noderesolve_nodeid (struct firewire_comm *, int); 363 struct fw_device *fw_noderesolve_eui64 (struct firewire_comm *, struct fw_eui64 *); 364 struct fw_bind *fw_bindlookup (struct firewire_comm *, uint16_t, uint32_t); 365 void fw_drain_txq (struct firewire_comm *); 366 //int fwdev_makedev (struct firewire_softc *); 367 //int fwdev_destroydev (struct firewire_softc *); 368 //void fwdev_clone (void *, struct ucred *, char *, int, struct cdev **); 369 int fw_open_isodma(struct firewire_comm *, int); 370 //#endif 371 extern int firewire_debug; 372 #ifndef __HAIKU__ 373 extern devclass_t firewire_devclass; 374 #endif 375 extern int firewire_phydma_enable; 376 377 #ifndef __HAIKU__ 378 #ifdef __DragonFly__ 379 #define FWPRI PCATCH 380 #else 381 #define FWPRI ((PZERO+8)|PCATCH) 382 #endif 383 384 #if defined(__DragonFly__) || __FreeBSD_version < 500000 385 #define CALLOUT_INIT(x) callout_init(x) 386 #else 387 #define CALLOUT_INIT(x) callout_init(x, 1 /* mpsafe */) 388 #endif 389 390 #if defined(__DragonFly__) || __FreeBSD_version < 500000 391 /* compatibility shim for 4.X */ 392 #define bio buf 393 #define bio_bcount b_bcount 394 #define bio_cmd b_flags 395 #define bio_count b_count 396 #define bio_data b_data 397 #define bio_dev b_dev 398 #define bio_error b_error 399 #define bio_flags b_flags 400 #define bio_offset b_offset 401 #define bio_resid b_resid 402 #define BIO_ERROR B_ERROR 403 #define BIO_READ B_READ 404 #define BIO_WRITE B_WRITE 405 #define MIN(a,b) (((a)<(b))?(a):(b)) 406 #define MAX(a,b) (((a)>(b))?(a):(b)) 407 #endif 408 409 MALLOC_DECLARE(M_FW); 410 MALLOC_DECLARE(M_FWXFER); 411 #endif /*__HAIKU__*/ 412 413 #endif 414