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_SUPER_SPEED_BULK_SIZE	1024
22 #define RTW_USB_HIGH_SPEED_BULK_SIZE	512
23 #define RTW_USB_FULL_SPEED_BULK_SIZE	64
24 
25 #define RTW_USB_TX_SEL_HQ		BIT(0)
26 #define RTW_USB_TX_SEL_LQ		BIT(1)
27 #define RTW_USB_TX_SEL_NQ		BIT(2)
28 #define RTW_USB_TX_SEL_EQ		BIT(3)
29 
30 #define RTW_USB_BULK_IN_ADDR		0x80
31 #define RTW_USB_INT_IN_ADDR		0x81
32 
33 #define RTW_USB_HW_QUEUE_ENTRY		8
34 
35 #define RTW_USB_PACKET_OFFSET_SZ	8
36 #define RTW_USB_MAX_XMITBUF_SZ		(1024 * 20)
37 #define RTW_USB_MAX_RECVBUF_SZ		32768
38 
39 #define RTW_USB_RECVBUFF_ALIGN_SZ	8
40 
41 #define RTW_USB_RXAGG_SIZE		6
42 #define RTW_USB_RXAGG_TIMEOUT		10
43 
44 #define RTW_USB_RXCB_NUM		4
45 
46 #define RTW_USB_EP_MAX			4
47 
48 #define TX_DESC_QSEL_MAX		20
49 
50 #define RTW_USB_VENDOR_ID_REALTEK	0x0bda
51 
52 static inline struct rtw_usb *rtw_get_usb_priv(struct rtw_dev *rtwdev)
53 {
54 	return (struct rtw_usb *)rtwdev->priv;
55 }
56 
57 struct rx_usb_ctrl_block {
58 	struct rtw_dev *rtwdev;
59 	struct urb *rx_urb;
60 	struct sk_buff *rx_skb;
61 	int n;
62 };
63 
64 struct rtw_usb_tx_data {
65 	u8 sn;
66 };
67 
68 struct rtw_usb {
69 	struct rtw_dev *rtwdev;
70 	struct usb_device *udev;
71 
72 	/* protects usb_data_index */
73 	spinlock_t usb_lock;
74 	__le32 *usb_data;
75 	unsigned int usb_data_index;
76 
77 	u32 bulkout_size;
78 	u8 pipe_interrupt;
79 	u8 pipe_in;
80 	u8 out_ep[RTW_USB_EP_MAX];
81 	u8 qsel_to_ep[TX_DESC_QSEL_MAX];
82 	u8 usb_txagg_num;
83 
84 	struct workqueue_struct *txwq, *rxwq;
85 
86 	struct sk_buff_head tx_queue[RTW_USB_EP_MAX];
87 	struct work_struct tx_work;
88 
89 	struct rx_usb_ctrl_block rx_cb[RTW_USB_RXCB_NUM];
90 	struct sk_buff_head rx_queue;
91 	struct work_struct rx_work;
92 };
93 
94 static inline struct rtw_usb_tx_data *rtw_usb_get_tx_data(struct sk_buff *skb)
95 {
96 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
97 
98 	BUILD_BUG_ON(sizeof(struct rtw_usb_tx_data) >
99 		     sizeof(info->status.status_driver_data));
100 
101 	return (struct rtw_usb_tx_data *)info->status.status_driver_data;
102 }
103 
104 int rtw_usb_probe(struct usb_interface *intf, const struct usb_device_id *id);
105 void rtw_usb_disconnect(struct usb_interface *intf);
106 
107 #endif
108