1 /*
2  * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2
6  * as published by the Free Software Foundation
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  */
13 
14 #ifndef __MT7601U_USB_H
15 #define __MT7601U_USB_H
16 
17 #include "mt7601u.h"
18 
19 #define MT7601U_FIRMWARE	"mt7601u.bin"
20 
21 #define MT_VEND_REQ_MAX_RETRY	10
22 #define MT_VEND_REQ_TOUT_MS	300
23 
24 #define MT_VEND_DEV_MODE_RESET	1
25 
26 #define MT_VEND_BUF		sizeof(__le32)
27 
28 enum mt_vendor_req {
29 	MT_VEND_DEV_MODE = 1,
30 	MT_VEND_WRITE = 2,
31 	MT_VEND_MULTI_READ = 7,
32 	MT_VEND_WRITE_FCE = 0x42,
33 };
34 
35 enum mt_usb_ep_in {
36 	MT_EP_IN_PKT_RX,
37 	MT_EP_IN_CMD_RESP,
38 	__MT_EP_IN_MAX,
39 };
40 
41 enum mt_usb_ep_out {
42 	MT_EP_OUT_INBAND_CMD,
43 	MT_EP_OUT_AC_BK,
44 	MT_EP_OUT_AC_BE,
45 	MT_EP_OUT_AC_VI,
46 	MT_EP_OUT_AC_VO,
47 	MT_EP_OUT_HCCA,
48 	__MT_EP_OUT_MAX,
49 };
50 
51 static inline struct usb_device *mt7601u_to_usb_dev(struct mt7601u_dev *mt7601u)
52 {
53 	return interface_to_usbdev(to_usb_interface(mt7601u->dev));
54 }
55 
56 static inline bool mt7601u_urb_has_error(struct urb *urb)
57 {
58 	return urb->status &&
59 		urb->status != -ENOENT &&
60 		urb->status != -ECONNRESET &&
61 		urb->status != -ESHUTDOWN;
62 }
63 
64 bool mt7601u_usb_alloc_buf(struct mt7601u_dev *dev, size_t len,
65 			   struct mt7601u_dma_buf *buf);
66 void mt7601u_usb_free_buf(struct mt7601u_dev *dev, struct mt7601u_dma_buf *buf);
67 int mt7601u_usb_submit_buf(struct mt7601u_dev *dev, int dir, int ep_idx,
68 			   struct mt7601u_dma_buf *buf, gfp_t gfp,
69 			   usb_complete_t complete_fn, void *context);
70 void mt7601u_complete_urb(struct urb *urb);
71 
72 int mt7601u_vendor_request(struct mt7601u_dev *dev, const u8 req,
73 			   const u8 direction, const u16 val, const u16 offset,
74 			   void *buf, const size_t buflen);
75 void mt7601u_vendor_reset(struct mt7601u_dev *dev);
76 int mt7601u_vendor_single_wr(struct mt7601u_dev *dev, const u8 req,
77 			     const u16 offset, const u32 val);
78 
79 #endif
80