GNU Linux-libre 4.19.264-gnu1
[releases.git] / drivers / net / wireless / mediatek / mt76 / mt76x0 / usb.h
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 __MT76X0U_USB_H
15 #define __MT76X0U_USB_H
16
17 #include "mt76x0.h"
18
19 #define MT7610_FIRMWARE "/*(DEBLOBBED)*/"
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 static inline struct usb_device *mt76x0_to_usb_dev(struct mt76x0_dev *mt76x0)
29 {
30         return interface_to_usbdev(to_usb_interface(mt76x0->mt76.dev));
31 }
32
33 static inline struct usb_device *mt76_to_usb_dev(struct mt76_dev *mt76)
34 {
35         return interface_to_usbdev(to_usb_interface(mt76->dev));
36 }
37
38 static inline bool mt76x0_urb_has_error(struct urb *urb)
39 {
40         return urb->status &&
41                 urb->status != -ENOENT &&
42                 urb->status != -ECONNRESET &&
43                 urb->status != -ESHUTDOWN;
44 }
45
46 bool mt76x0_usb_alloc_buf(struct mt76x0_dev *dev, size_t len,
47                            struct mt76x0_dma_buf *buf);
48 void mt76x0_usb_free_buf(struct mt76x0_dev *dev, struct mt76x0_dma_buf *buf);
49 int mt76x0_usb_submit_buf(struct mt76x0_dev *dev, int dir, int ep_idx,
50                            struct mt76x0_dma_buf *buf, gfp_t gfp,
51                            usb_complete_t complete_fn, void *context);
52 void mt76x0_complete_urb(struct urb *urb);
53
54 int mt76x0_vendor_request(struct mt76x0_dev *dev, const u8 req,
55                            const u8 direction, const u16 val, const u16 offset,
56                            void *buf, const size_t buflen);
57 void mt76x0_vendor_reset(struct mt76x0_dev *dev);
58 int mt76x0_vendor_single_wr(struct mt76x0_dev *dev, const u8 req,
59                              const u16 offset, const u32 val);
60
61 #endif