xref: /dflybsd-src/sys/netgraph7/bluetooth/drivers/ubt/ng_ubt_var.h (revision d2902f79a0a109703a9768bf031effa787c055ec)
1b06ebda0SMatthew Dillon /*
2b06ebda0SMatthew Dillon  * ng_ubt_var.h
3b06ebda0SMatthew Dillon  */
4b06ebda0SMatthew Dillon 
5b06ebda0SMatthew Dillon /*-
6*d2902f79SSascha Wildner  * Copyright (c) 2001-2009 Maksim Yevmenkin <m_evmenkin@yahoo.com>
7b06ebda0SMatthew Dillon  * All rights reserved.
8b06ebda0SMatthew Dillon  *
9b06ebda0SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
10b06ebda0SMatthew Dillon  * modification, are permitted provided that the following conditions
11b06ebda0SMatthew Dillon  * are met:
12b06ebda0SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
13b06ebda0SMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
14b06ebda0SMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
15b06ebda0SMatthew Dillon  *    notice, this list of conditions and the following disclaimer in the
16b06ebda0SMatthew Dillon  *    documentation and/or other materials provided with the distribution.
17b06ebda0SMatthew Dillon  *
18b06ebda0SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19b06ebda0SMatthew Dillon  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20b06ebda0SMatthew Dillon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21b06ebda0SMatthew Dillon  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22b06ebda0SMatthew Dillon  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23b06ebda0SMatthew Dillon  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24b06ebda0SMatthew Dillon  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25b06ebda0SMatthew Dillon  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26b06ebda0SMatthew Dillon  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27b06ebda0SMatthew Dillon  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28b06ebda0SMatthew Dillon  * SUCH DAMAGE.
29b06ebda0SMatthew Dillon  *
30b06ebda0SMatthew Dillon  * $Id: ng_ubt_var.h,v 1.2 2003/03/22 23:44:36 max Exp $
31*d2902f79SSascha Wildner  * $FreeBSD: head/sys/netgraph/bluetooth/drivers/ubt/ng_ubt_var.h 196219 2009-08-14 20:03:53Z jhb $
32b06ebda0SMatthew Dillon  */
33b06ebda0SMatthew Dillon 
34b06ebda0SMatthew Dillon #ifndef _NG_UBT_VAR_H_
35*d2902f79SSascha Wildner #define	_NG_UBT_VAR_H_	1
36b06ebda0SMatthew Dillon 
37b06ebda0SMatthew Dillon /* Debug printf's */
38*d2902f79SSascha Wildner #define	UBT_DEBUG(level, sc, fmt, ...)				\
39*d2902f79SSascha Wildner do {								\
40*d2902f79SSascha Wildner 	if ((sc)->sc_debug >= (level))				\
41*d2902f79SSascha Wildner 		device_printf((sc)->sc_dev, "%s:%d: " fmt, 	\
42*d2902f79SSascha Wildner 			__FUNCTION__, __LINE__,## __VA_ARGS__);	\
43*d2902f79SSascha Wildner } while (0)
44*d2902f79SSascha Wildner 
45*d2902f79SSascha Wildner #define	UBT_ALERT(...)		UBT_DEBUG(NG_UBT_ALERT_LEVEL, __VA_ARGS__)
46*d2902f79SSascha Wildner #define	UBT_ERR(...)		UBT_DEBUG(NG_UBT_ERR_LEVEL, __VA_ARGS__)
47*d2902f79SSascha Wildner #define	UBT_WARN(...)		UBT_DEBUG(NG_UBT_WARN_LEVEL, __VA_ARGS__)
48*d2902f79SSascha Wildner #define	UBT_INFO(...)		UBT_DEBUG(NG_UBT_INFO_LEVEL, __VA_ARGS__)
49*d2902f79SSascha Wildner 
50*d2902f79SSascha Wildner #define UBT_NG_LOCK(sc)		lockmgr(&(sc)->sc_ng_lock, LK_EXCLUSIVE)
51*d2902f79SSascha Wildner #define UBT_NG_UNLOCK(sc)	lockmgr(&(sc)->sc_ng_lock, LK_RELEASE)
52b06ebda0SMatthew Dillon 
53b06ebda0SMatthew Dillon /* Bluetooth USB control request type */
54b06ebda0SMatthew Dillon #define	UBT_HCI_REQUEST		0x20
55*d2902f79SSascha Wildner #define	UBT_DEFAULT_QLEN	64
56*d2902f79SSascha Wildner #define	UBT_ISOC_NFRAMES	32	/* should be factor of 8 */
57*d2902f79SSascha Wildner 
58*d2902f79SSascha Wildner /* Bluetooth USB defines */
59*d2902f79SSascha Wildner enum {
60*d2902f79SSascha Wildner 	/* Interface #0 transfers */
61*d2902f79SSascha Wildner 	UBT_IF_0_BULK_DT_WR = 0,
62*d2902f79SSascha Wildner 	UBT_IF_0_BULK_DT_RD,
63*d2902f79SSascha Wildner 	UBT_IF_0_INTR_DT_RD,
64*d2902f79SSascha Wildner 	UBT_IF_0_CTRL_DT_WR,
65*d2902f79SSascha Wildner 
66*d2902f79SSascha Wildner 	/* Interface #1 transfers */
67*d2902f79SSascha Wildner 	UBT_IF_1_ISOC_DT_RD1,
68*d2902f79SSascha Wildner 	UBT_IF_1_ISOC_DT_RD2,
69*d2902f79SSascha Wildner 	UBT_IF_1_ISOC_DT_WR1,
70*d2902f79SSascha Wildner 	UBT_IF_1_ISOC_DT_WR2,
71*d2902f79SSascha Wildner 
72*d2902f79SSascha Wildner 	UBT_N_TRANSFER,		/* total number of transfers */
73*d2902f79SSascha Wildner };
74b06ebda0SMatthew Dillon 
75b06ebda0SMatthew Dillon /* USB device softc structure */
76b06ebda0SMatthew Dillon struct ubt_softc {
77*d2902f79SSascha Wildner 	device_t		sc_dev;		/* for debug printf */
78*d2902f79SSascha Wildner 
79b06ebda0SMatthew Dillon 	/* State */
80b06ebda0SMatthew Dillon 	ng_ubt_node_debug_ep	sc_debug;	/* debug level */
81b06ebda0SMatthew Dillon 
82b06ebda0SMatthew Dillon 	ng_ubt_node_stat_ep	sc_stat;	/* statistic */
83*d2902f79SSascha Wildner #define	UBT_STAT_PCKTS_SENT(sc)		(sc)->sc_stat.pckts_sent ++
84*d2902f79SSascha Wildner #define	UBT_STAT_BYTES_SENT(sc, n)	(sc)->sc_stat.bytes_sent += (n)
85*d2902f79SSascha Wildner #define	UBT_STAT_PCKTS_RECV(sc)		(sc)->sc_stat.pckts_recv ++
86*d2902f79SSascha Wildner #define	UBT_STAT_BYTES_RECV(sc, n)	(sc)->sc_stat.bytes_recv += (n)
87*d2902f79SSascha Wildner #define	UBT_STAT_OERROR(sc)		(sc)->sc_stat.oerrors ++
88*d2902f79SSascha Wildner #define	UBT_STAT_IERROR(sc)		(sc)->sc_stat.ierrors ++
89*d2902f79SSascha Wildner #define	UBT_STAT_RESET(sc)	bzero(&(sc)->sc_stat, sizeof((sc)->sc_stat))
90b06ebda0SMatthew Dillon 
91b06ebda0SMatthew Dillon 	/* USB device specific */
92*d2902f79SSascha Wildner 	struct lock		sc_if_lock;	/* interfaces lock */
93*d2902f79SSascha Wildner 	struct usb_xfer	*sc_xfer[UBT_N_TRANSFER];
94b06ebda0SMatthew Dillon 
95*d2902f79SSascha Wildner 	struct lock		sc_ng_lock;	/* lock for shared NG data */
96b06ebda0SMatthew Dillon 
97*d2902f79SSascha Wildner 	/* HCI commands */
98b06ebda0SMatthew Dillon 	struct ng_bt_mbufq	sc_cmdq;	/* HCI command queue */
99*d2902f79SSascha Wildner #define	UBT_CTRL_BUFFER_SIZE	(sizeof(struct usb_device_request) +	\
100*d2902f79SSascha Wildner 				 sizeof(ng_hci_cmd_pkt_t) + NG_HCI_CMD_PKT_SIZE)
101*d2902f79SSascha Wildner #define	UBT_INTR_BUFFER_SIZE	(MCLBYTES-1)	/* reserve 1 byte for ID-tag */
102b06ebda0SMatthew Dillon 
103*d2902f79SSascha Wildner 	/* ACL data */
104b06ebda0SMatthew Dillon 	struct ng_bt_mbufq	sc_aclq;	/* ACL data queue */
105*d2902f79SSascha Wildner #define	UBT_BULK_READ_BUFFER_SIZE (MCLBYTES-1)	/* reserve 1 byte for ID-tag */
106*d2902f79SSascha Wildner #define	UBT_BULK_WRITE_BUFFER_SIZE (MCLBYTES)
107b06ebda0SMatthew Dillon 
108*d2902f79SSascha Wildner 	/* SCO data */
109b06ebda0SMatthew Dillon 	struct ng_bt_mbufq	sc_scoq;	/* SCO data queue */
110*d2902f79SSascha Wildner 	struct mbuf		*sc_isoc_in_buffer; /* SCO reassembly buffer */
111b06ebda0SMatthew Dillon 
112b06ebda0SMatthew Dillon 	/* Netgraph specific */
113b06ebda0SMatthew Dillon 	node_p			sc_node;	/* pointer back to node */
114b06ebda0SMatthew Dillon 	hook_p			sc_hook;	/* upstream hook */
115*d2902f79SSascha Wildner 
116*d2902f79SSascha Wildner 	/* Glue */
117*d2902f79SSascha Wildner 	int			sc_task_flags;	/* task flags */
118*d2902f79SSascha Wildner #define UBT_FLAG_T_PENDING	(1 << 0)	/* task pending */
119*d2902f79SSascha Wildner #define UBT_FLAG_T_STOP_ALL	(1 << 1)	/* stop all xfers */
120*d2902f79SSascha Wildner #define UBT_FLAG_T_START_ALL	(1 << 2)	/* start all read and isoc
121*d2902f79SSascha Wildner 						   write xfers */
122*d2902f79SSascha Wildner #define UBT_FLAG_T_START_CTRL	(1 << 3)	/* start control xfer (write) */
123*d2902f79SSascha Wildner #define UBT_FLAG_T_START_BULK	(1 << 4)	/* start bulk xfer (write) */
124*d2902f79SSascha Wildner 
125*d2902f79SSascha Wildner 	struct task		sc_task;
126b06ebda0SMatthew Dillon };
127b06ebda0SMatthew Dillon typedef struct ubt_softc	ubt_softc_t;
128b06ebda0SMatthew Dillon typedef struct ubt_softc *	ubt_softc_p;
129b06ebda0SMatthew Dillon 
130b06ebda0SMatthew Dillon #endif /* ndef _NG_UBT_VAR_H_ */
131b06ebda0SMatthew Dillon 
132