xref: /freebsd/sys/dev/rtwn/usb/rtwn_usb_var.h (revision 481314f620ac01a5a92c322e8ab4f310035872f9)
1 /*-
2  * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
3  * Copyright (c) 2016 Andriy Voskoboinyk <avos@FreeBSD.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  *
17  * $OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $
18  */
19 
20 #ifndef RTWN_USBVAR_H
21 #define RTWN_USBVAR_H
22 
23 #include <dev/rtwn/if_rtwnreg.h>	/* for struct rtwn_rx_stat_common */
24 
25 #define RTWN_USB_RXBUFSZ_UNIT		(512)
26 #define RTWN_USB_RXBUFSZ_MIN		( 4)
27 #define RTWN_USB_RXBUFSZ_DEF		(24)
28 #define RTWN_USB_RXBUFSZ_MAX		(64)
29 #define RTWN_USB_TXBUFSZ		(16 * 1024)
30 
31 #define RTWN_USB_RX_LIST_COUNT		16
32 #define RTWN_USB_TX_LIST_COUNT		16
33 
34 struct rtwn_data {
35 	uint8_t				*buf;
36 	/* 'id' is meaningful for beacons only */
37 	int				id;
38 	int				qid;
39 	uint16_t			buflen;
40 	struct mbuf			*m;
41 	struct ieee80211_node		*ni;
42 	STAILQ_ENTRY(rtwn_data)	next;
43 };
44 typedef STAILQ_HEAD(, rtwn_data) rtwn_datahead;
45 
46 enum {
47 	RTWN_BULK_RX,
48 	RTWN_BULK_TX_BE,	/* = WME_AC_BE */
49 	RTWN_BULK_TX_BK,	/* = WME_AC_BK */
50 	RTWN_BULK_TX_VI,	/* = WME_AC_VI */
51 	RTWN_BULK_TX_VO,	/* = WME_AC_VO */
52 	RTWN_BULK_EP_COUNT = 5,
53 };
54 
55 #define RTWN_EP_QUEUES		RTWN_BULK_RX
56 #define	RTWN_BULK_TX_FIRST	RTWN_BULK_TX_BE
57 
58 struct rtwn_usb_softc {
59 	struct rtwn_softc	uc_sc;		/* must be the first */
60 	struct usb_device	*uc_udev;
61 	struct usb_xfer		*uc_xfer[RTWN_BULK_EP_COUNT];
62 
63 	struct rtwn_data	uc_rx[RTWN_USB_RX_LIST_COUNT];
64 	rtwn_datahead		uc_rx_active;
65 	rtwn_datahead		uc_rx_inactive;
66 	int			uc_rx_buf_size;
67 
68 	struct rtwn_rx_stat_common uc_rx_stat;
69 	int			uc_rx_stat_len;
70 	int			uc_rx_off;
71 
72 	struct rtwn_data	uc_tx[RTWN_USB_TX_LIST_COUNT];
73 	rtwn_datahead		uc_tx_active[RTWN_BULK_EP_COUNT];
74 	rtwn_datahead		uc_tx_inactive;
75 	rtwn_datahead		uc_tx_pending[RTWN_BULK_EP_COUNT];
76 
77 	int			(*uc_align_rx)(int, int);
78 
79 	int			ntx;
80 	int			tx_agg_desc_num;
81 
82 	uint8_t			wme2qid[4];
83 };
84 #define RTWN_USB_SOFTC(sc)	((struct rtwn_usb_softc *)(sc))
85 
86 #define RTWN_USB_DEVINFO(c, i)		((c) | ((i) << 16))
87 #define RTWN_USB_DEVINFO_GET_CHIP(did)	((USB_GET_DRIVER_INFO(did)) & 0xffff)
88 #define RTWN_USB_DEVINFO_GET_IFACE(did)	((USB_GET_DRIVER_INFO(did)) >> 16)
89 
90 #define rtwn_usb_align_rx(_uc, _totlen, _len) \
91 	(((_uc)->uc_align_rx)((_totlen), (_len)))
92 
93 #endif	/* RTWN_USBVAR_H */
94