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