xref: /linux/drivers/net/wireless/realtek/rtlwifi/usb.h (revision 4b132aacb0768ac1e652cf517097ea6f237214b9)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright(c) 2009-2012  Realtek Corporation.*/
3 
4 #ifndef __RTL_USB_H__
5 #define __RTL_USB_H__
6 
7 #include <linux/skbuff.h>
8 
9 #define RTL_RX_DESC_SIZE		24
10 
11 #define RTL_USB_DEVICE(vend, prod, cfg) \
12 	.match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
13 	.idVendor = (vend), \
14 	.idProduct = (prod), \
15 	.driver_info = (kernel_ulong_t)&(cfg)
16 
17 #define USB_HIGH_SPEED_BULK_SIZE	512
18 #define USB_FULL_SPEED_BULK_SIZE	64
19 
20 #define RTL_USB_MAX_TXQ_NUM		4		/* max tx queue */
21 #define RTL_USB_MAX_EP_NUM		6		/* max ep number */
22 #define RTL_USB_MAX_BULKOUT_NUM		4
23 #define RTL_USB_MAX_TX_URBS_NUM		8
24 
25 enum rtl_txq {
26 	/* These definitions shall be consistent with value
27 	 * returned by skb_get_queue_mapping
28 	 *------------------------------------*/
29 	RTL_TXQ_BK,
30 	RTL_TXQ_BE,
31 	RTL_TXQ_VI,
32 	RTL_TXQ_VO,
33 	/*------------------------------------*/
34 	RTL_TXQ_BCN,
35 	RTL_TXQ_MGT,
36 	RTL_TXQ_HI,
37 
38 	/* Must be last */
39 	__RTL_TXQ_NUM,
40 };
41 
42 struct rtl_ep_map {
43 	u32 ep_mapping[__RTL_TXQ_NUM];
44 };
45 
46 struct _trx_info {
47 	struct rtl_usb *rtlusb;
48 	u32 ep_num;
49 };
50 
51 static inline void _rtl_install_trx_info(struct rtl_usb *rtlusb,
52 					 struct sk_buff *skb,
53 					 u32 ep_num)
54 {
55 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
56 
57 	info->rate_driver_data[0] = rtlusb;
58 	info->rate_driver_data[1] = (void *)(__kernel_size_t)ep_num;
59 }
60 
61 /*  Add suspend/resume later */
62 enum rtl_usb_state {
63 	USB_STATE_STOP	= 0,
64 	USB_STATE_START	= 1,
65 };
66 
67 #define IS_USB_STOP(rtlusb_ptr) (USB_STATE_STOP == (rtlusb_ptr)->state)
68 #define IS_USB_START(rtlusb_ptr) (USB_STATE_START == (rtlusb_ptr)->state)
69 #define SET_USB_STOP(rtlusb_ptr) \
70 	do {							\
71 		(rtlusb_ptr)->state = USB_STATE_STOP;		\
72 	} while (0)
73 
74 #define SET_USB_START(rtlusb_ptr)				\
75 	do { \
76 		(rtlusb_ptr)->state = USB_STATE_START;		\
77 	} while (0)
78 
79 struct rtl_usb {
80 	struct usb_device *udev;
81 	struct usb_interface *intf;
82 	enum rtl_usb_state state;
83 
84 	/* Bcn control register setting */
85 	u32 reg_bcn_ctrl_val;
86 	/* for 88/92cu card disable */
87 	u8	disablehwsm;
88 	/*QOS & EDCA */
89 	enum acm_method acm_method;
90 	/* irq  . HIMR,HIMR_EX */
91 	u32 irq_mask[2];
92 	bool irq_enabled;
93 
94 	u16 (*usb_mq_to_hwq)(__le16 fc, u16 mac80211_queue_index);
95 
96 	/* Tx */
97 	u8 out_ep_nums ;
98 	u8 out_eps[RTL_USB_MAX_BULKOUT_NUM];
99 	u8 out_queue_sel;
100 	struct rtl_ep_map ep_map;
101 
102 	u32 max_bulk_out_size;
103 	u32 tx_submitted_urbs;
104 	struct sk_buff_head tx_skb_queue[RTL_USB_MAX_EP_NUM];
105 
106 	struct usb_anchor tx_pending[RTL_USB_MAX_EP_NUM];
107 	struct usb_anchor tx_submitted;
108 
109 	struct sk_buff *(*usb_tx_aggregate_hdl)(struct ieee80211_hw *,
110 						struct sk_buff_head *);
111 	int (*usb_tx_post_hdl)(struct ieee80211_hw *,
112 			       struct urb *, struct sk_buff *);
113 	void (*usb_tx_cleanup)(struct ieee80211_hw *, struct sk_buff *);
114 
115 	/* Rx */
116 	u8 in_ep_nums;
117 	u32 in_ep;		/* Bulk IN endpoint number */
118 	u32 rx_max_size;	/* Bulk IN max buffer size */
119 	u32 rx_urb_num;		/* How many Bulk INs are submitted to host. */
120 	struct usb_anchor	rx_submitted;
121 	struct usb_anchor	rx_cleanup_urbs;
122 	struct tasklet_struct   rx_work_tasklet;
123 	struct sk_buff_head	rx_queue;
124 	void (*usb_rx_segregate_hdl)(struct ieee80211_hw *, struct sk_buff *,
125 				     struct sk_buff_head *);
126 	void (*usb_rx_hdl)(struct ieee80211_hw *, struct sk_buff *);
127 };
128 
129 struct rtl_usb_priv {
130 	struct bt_coexist_info bt_coexist;
131 	struct rtl_usb dev;
132 };
133 
134 #define rtl_usbpriv(hw)	 (((struct rtl_usb_priv *)(rtl_priv(hw))->priv))
135 #define rtl_usbdev(usbpriv)	(&((usbpriv)->dev))
136 
137 int rtl_usb_probe(struct usb_interface *intf,
138 		  const struct usb_device_id *id,
139 		  const struct rtl_hal_cfg *rtl92cu_hal_cfg);
140 void rtl_usb_disconnect(struct usb_interface *intf);
141 int rtl_usb_suspend(struct usb_interface *pusb_intf, pm_message_t message);
142 int rtl_usb_resume(struct usb_interface *pusb_intf);
143 
144 #endif
145