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