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