1139749Simp/*-
2113584Ssimokawa * Copyright (c) 2003 Hidetoshi SHimokawa
3103285Sikob * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi SHimokawa
4103285Sikob * All rights reserved.
5103285Sikob *
6103285Sikob * Redistribution and use in source and binary forms, with or without
7103285Sikob * modification, are permitted provided that the following conditions
8103285Sikob * are met:
9103285Sikob * 1. Redistributions of source code must retain the above copyright
10103285Sikob *    notice, this list of conditions and the following disclaimer.
11103285Sikob * 2. Redistributions in binary form must reproduce the above copyright
12103285Sikob *    notice, this list of conditions and the following disclaimer in the
13103285Sikob *    documentation and/or other materials provided with the distribution.
14103285Sikob * 3. All advertising materials mentioning features or use of this software
15103285Sikob *    must display the acknowledgement as bellow:
16103285Sikob *
17103285Sikob *    This product includes software developed by K. Kobayashi and H. Shimokawa
18103285Sikob *
19103285Sikob * 4. The name of the author may not be used to endorse or promote products
20103285Sikob *    derived from this software without specific prior written permission.
21103285Sikob *
22103285Sikob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23103285Sikob * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24103285Sikob * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25103285Sikob * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26103285Sikob * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27103285Sikob * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28103285Sikob * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29103285Sikob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30103285Sikob * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31103285Sikob * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32103285Sikob * POSSIBILITY OF SUCH DAMAGE.
33103285Sikob *
34103285Sikob * $FreeBSD$
35103285Sikob *
36103285Sikob */
37113584Ssimokawa
38170374Ssimokawa#include <sys/taskqueue.h>
39170374Ssimokawa
40103285Sikobtypedef struct fwohci_softc {
41103285Sikob	struct firewire_comm fc;
42103285Sikob	bus_space_tag_t bst;
43103285Sikob	bus_space_handle_t bsh;
44103285Sikob	void *ih;
45127468Ssimokawa#if defined(__DragonFly__) || __FreeBSD_version < 500000
46103285Sikob	void *ih_cam;
47121506Ssimokawa	void *ih_bio;
48103285Sikob#endif
49103285Sikob	struct resource *bsr;
50103285Sikob	struct resource *irq_res;
51103285Sikob	struct fwohci_dbch{
52103285Sikob		u_int ndb;
53103285Sikob		u_int ndesc;
54103285Sikob		STAILQ_HEAD(, fwohcidb_tr) db_trq;
55103285Sikob		struct fwohcidb_tr *top, *bottom, *pdb_tr;
56103285Sikob		struct fw_xferq xferq;
57103285Sikob		int flags;
58108527Ssimokawa#define	FWOHCI_DBCH_INIT	(1<<0)
59103285Sikob#define	FWOHCI_DBCH_FULL	(1<<1)
60113584Ssimokawa		/* used only in receive context */
61113584Ssimokawa		int buf_offset;	/* signed */
62109379Ssimokawa#define FWOHCI_DBCH_MAX_PAGES	32
63113584Ssimokawa		/* Context programs buffer */
64113584Ssimokawa		struct fwdma_alloc_multi *am;
65113584Ssimokawa		bus_dma_tag_t dmat;
66108276Ssimokawa	} arrq, arrs, atrq, atrs, it[OHCI_DMA_ITCH], ir[OHCI_DMA_IRCH];
67103285Sikob	u_int maxrec;
68129585Sdfr	uint32_t *sid_buf;
69113584Ssimokawa	struct fwdma_alloc sid_dma;
70113584Ssimokawa	struct fwdma_alloc crom_dma;
71113584Ssimokawa	struct fwdma_alloc dummy_dma;
72129585Sdfr	uint32_t intmask, irstat, itstat;
73129585Sdfr	uint32_t intstat;
74170374Ssimokawa	struct task fwohci_task_busreset;
75170374Ssimokawa	struct task fwohci_task_sid;
76170374Ssimokawa	struct task fwohci_task_dma;
77167628Ssimokawa	int cycle_lost;
78103285Sikob} fwohci_softc_t;
79113584Ssimokawa
80124169Ssimokawavoid fwohci_intr (void *arg);
81124169Ssimokawaint fwohci_init (struct fwohci_softc *, device_t);
82124169Ssimokawavoid fwohci_poll (struct firewire_comm *, int, int);
83124169Ssimokawavoid fwohci_reset (struct fwohci_softc *, device_t);
84124169Ssimokawaint fwohci_detach (struct fwohci_softc *, device_t);
85124169Ssimokawaint fwohci_resume (struct fwohci_softc *, device_t);
86124169Ssimokawaint fwohci_stop (struct fwohci_softc *, device_t dev);
87