xref: /freebsd/sys/contrib/dev/rtw88/usb.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2018-2019  Realtek Corporation
3  */
4 
5 #ifndef __RTW_USB_H_
6 #define __RTW_USB_H_
7 
8 #define FW_8192C_START_ADDRESS		0x1000
9 #define FW_8192C_END_ADDRESS		0x5fff
10 
11 #define RTW_USB_MAX_RXTX_COUNT		128
12 #define RTW_USB_VENQT_MAX_BUF_SIZE	254
13 #define MAX_USBCTRL_VENDORREQ_TIMES	10
14 
15 #define RTW_USB_CMD_READ		0xc0
16 #define RTW_USB_CMD_WRITE		0x40
17 #define RTW_USB_CMD_REQ			0x05
18 
19 #define RTW_USB_VENQT_CMD_IDX		0x00
20 
21 #define RTW_USB_TX_SEL_HQ		BIT(0)
22 #define RTW_USB_TX_SEL_LQ		BIT(1)
23 #define RTW_USB_TX_SEL_NQ		BIT(2)
24 #define RTW_USB_TX_SEL_EQ		BIT(3)
25 
26 #define RTW_USB_BULK_IN_ADDR		0x80
27 #define RTW_USB_INT_IN_ADDR		0x81
28 
29 #define RTW_USB_HW_QUEUE_ENTRY		8
30 
31 #define RTW_USB_PACKET_OFFSET_SZ	8
32 #define RTW_USB_MAX_XMITBUF_SZ		(1024 * 20)
33 #define RTW_USB_MAX_RECVBUF_SZ		32768
34 
35 #define RTW_USB_RECVBUFF_ALIGN_SZ	8
36 
37 #define RTW_USB_RXAGG_SIZE		6
38 #define RTW_USB_RXAGG_TIMEOUT		10
39 
40 #define RTW_USB_RXCB_NUM		4
41 
42 #define RTW_USB_EP_MAX			4
43 
44 #define TX_DESC_QSEL_MAX		20
45 
46 #define RTW_USB_VENDOR_ID_REALTEK	0x0bda
47 
48 static inline struct rtw_usb *rtw_get_usb_priv(struct rtw_dev *rtwdev)
49 {
50 	return (struct rtw_usb *)rtwdev->priv;
51 }
52 
53 struct rx_usb_ctrl_block {
54 	struct rtw_dev *rtwdev;
55 	struct urb *rx_urb;
56 	struct sk_buff *rx_skb;
57 };
58 
59 struct rtw_usb_tx_data {
60 	u8 sn;
61 };
62 
63 struct rtw_usb {
64 	struct rtw_dev *rtwdev;
65 	struct usb_device *udev;
66 
67 	/* protects usb_data_index */
68 	spinlock_t usb_lock;
69 	__le32 *usb_data;
70 	unsigned int usb_data_index;
71 
72 	u8 pipe_interrupt;
73 	u8 pipe_in;
74 	u8 out_ep[RTW_USB_EP_MAX];
75 	int qsel_to_ep[TX_DESC_QSEL_MAX];
76 
77 	struct workqueue_struct *txwq, *rxwq;
78 
79 	struct sk_buff_head tx_queue[RTW_USB_EP_MAX];
80 	struct work_struct tx_work;
81 
82 	struct rx_usb_ctrl_block rx_cb[RTW_USB_RXCB_NUM];
83 	struct sk_buff_head rx_queue;
84 	struct work_struct rx_work;
85 };
86 
87 static inline struct rtw_usb_tx_data *rtw_usb_get_tx_data(struct sk_buff *skb)
88 {
89 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
90 
91 	BUILD_BUG_ON(sizeof(struct rtw_usb_tx_data) >
92 		     sizeof(info->status.status_driver_data));
93 
94 	return (struct rtw_usb_tx_data *)info->status.status_driver_data;
95 }
96 
97 int rtw_usb_probe(struct usb_interface *intf, const struct usb_device_id *id);
98 void rtw_usb_disconnect(struct usb_interface *intf);
99 
100 #endif
101