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