1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl>
4  */
5 
6 #ifndef __MT7601U_USB_H
7 #define __MT7601U_USB_H
8 
9 #include "mt7601u.h"
10 
11 #define MT7601U_FIRMWARE	"mt7601u.bin"
12 
13 #define MT_VEND_REQ_MAX_RETRY	10
14 #define MT_VEND_REQ_TOUT_MS	300
15 
16 #define MT_VEND_DEV_MODE_RESET	1
17 
18 #define MT_VEND_BUF		sizeof(__le32)
19 
20 enum mt_vendor_req {
21 	MT_VEND_DEV_MODE = 1,
22 	MT_VEND_WRITE = 2,
23 	MT_VEND_MULTI_READ = 7,
24 	MT_VEND_WRITE_FCE = 0x42,
25 };
26 
27 enum mt_usb_ep_in {
28 	MT_EP_IN_PKT_RX,
29 	MT_EP_IN_CMD_RESP,
30 	__MT_EP_IN_MAX,
31 };
32 
33 enum mt_usb_ep_out {
34 	MT_EP_OUT_INBAND_CMD,
35 	MT_EP_OUT_AC_BK,
36 	MT_EP_OUT_AC_BE,
37 	MT_EP_OUT_AC_VI,
38 	MT_EP_OUT_AC_VO,
39 	MT_EP_OUT_HCCA,
40 	__MT_EP_OUT_MAX,
41 };
42 
43 static inline struct usb_device *mt7601u_to_usb_dev(struct mt7601u_dev *mt7601u)
44 {
45 	return interface_to_usbdev(to_usb_interface(mt7601u->dev));
46 }
47 
48 static inline bool mt7601u_urb_has_error(struct urb *urb)
49 {
50 	return urb->status &&
51 		urb->status != -ENOENT &&
52 		urb->status != -ECONNRESET &&
53 		urb->status != -ESHUTDOWN;
54 }
55 
56 bool mt7601u_usb_alloc_buf(struct mt7601u_dev *dev, size_t len,
57 			   struct mt7601u_dma_buf *buf);
58 void mt7601u_usb_free_buf(struct mt7601u_dev *dev, struct mt7601u_dma_buf *buf);
59 int mt7601u_usb_submit_buf(struct mt7601u_dev *dev, int dir, int ep_idx,
60 			   struct mt7601u_dma_buf *buf, gfp_t gfp,
61 			   usb_complete_t complete_fn, void *context);
62 void mt7601u_complete_urb(struct urb *urb);
63 
64 int mt7601u_vendor_request(struct mt7601u_dev *dev, const u8 req,
65 			   const u8 direction, const u16 val, const u16 offset,
66 			   void *buf, const size_t buflen);
67 void mt7601u_vendor_reset(struct mt7601u_dev *dev);
68 int mt7601u_vendor_single_wr(struct mt7601u_dev *dev, const u8 req,
69 			     const u16 offset, const u32 val);
70 
71 #endif
72