hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
....@@ -1,14 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * 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.
124 */
135
146 #include <linux/kernel.h>
....@@ -16,8 +8,8 @@
168 #include <linux/usb.h>
179
1810 #include "mt76x0.h"
19
-#include "usb.h"
20
-#include "trace.h"
11
+#include "mcu.h"
12
+#include "../mt76x02_usb.h"
2113
2214 static struct usb_device_id mt76x0_device_table[] = {
2315 { USB_DEVICE(0x148F, 0x7610) }, /* MT7610U */
....@@ -40,337 +32,313 @@
4032 { USB_DEVICE(0x20f4, 0x806b) }, /* TRENDnet TEW-806UBH */
4133 { USB_DEVICE(0x7392, 0xc711) }, /* Devolo Wifi ac Stick */
4234 { USB_DEVICE(0x0df6, 0x0079) }, /* Sitecom Europe B.V. ac Stick */
43
- { USB_DEVICE(0x2357, 0x0105) }, /* TP-LINK Archer T1U */
44
- { USB_DEVICE_AND_INTERFACE_INFO(0x0E8D, 0x7630, 0xff, 0x2, 0xff)}, /* MT7630U */
45
- { USB_DEVICE_AND_INTERFACE_INFO(0x0E8D, 0x7650, 0xff, 0x2, 0xff)}, /* MT7650U */
35
+ { USB_DEVICE(0x2357, 0x0123) }, /* TP-LINK T2UHP */
36
+ /* TP-LINK Archer T1U */
37
+ { USB_DEVICE(0x2357, 0x0105), .driver_info = 1, },
38
+ /* MT7630U */
39
+ { USB_DEVICE_AND_INTERFACE_INFO(0x0E8D, 0x7630, 0xff, 0x2, 0xff)},
40
+ /* MT7650U */
41
+ { USB_DEVICE_AND_INTERFACE_INFO(0x0E8D, 0x7650, 0xff, 0x2, 0xff)},
4642 { 0, }
4743 };
4844
49
-bool mt76x0_usb_alloc_buf(struct mt76x0_dev *dev, size_t len,
50
- struct mt76x0_dma_buf *buf)
45
+static void mt76x0_init_usb_dma(struct mt76x02_dev *dev)
5146 {
52
- struct usb_device *usb_dev = mt76x0_to_usb_dev(dev);
47
+ u32 val;
5348
54
- buf->len = len;
55
- buf->urb = usb_alloc_urb(0, GFP_KERNEL);
56
- buf->buf = usb_alloc_coherent(usb_dev, buf->len, GFP_KERNEL, &buf->dma);
49
+ val = mt76_rr(dev, MT_USB_DMA_CFG);
5750
58
- return !buf->urb || !buf->buf;
51
+ val |= MT_USB_DMA_CFG_RX_BULK_EN |
52
+ MT_USB_DMA_CFG_TX_BULK_EN;
53
+
54
+ /* disable AGGR_BULK_RX in order to receive one
55
+ * frame in each rx urb and avoid copies
56
+ */
57
+ val &= ~MT_USB_DMA_CFG_RX_BULK_AGG_EN;
58
+ mt76_wr(dev, MT_USB_DMA_CFG, val);
59
+
60
+ val = mt76_rr(dev, MT_COM_REG0);
61
+ if (val & 1)
62
+ dev_dbg(dev->mt76.dev, "MCU not ready\n");
63
+
64
+ val = mt76_rr(dev, MT_USB_DMA_CFG);
65
+
66
+ val |= MT_USB_DMA_CFG_RX_DROP_OR_PAD;
67
+ mt76_wr(dev, MT_USB_DMA_CFG, val);
68
+ val &= ~MT_USB_DMA_CFG_RX_DROP_OR_PAD;
69
+ mt76_wr(dev, MT_USB_DMA_CFG, val);
5970 }
6071
61
-void mt76x0_usb_free_buf(struct mt76x0_dev *dev, struct mt76x0_dma_buf *buf)
72
+static void mt76x0u_cleanup(struct mt76x02_dev *dev)
6273 {
63
- struct usb_device *usb_dev = mt76x0_to_usb_dev(dev);
64
-
65
- usb_free_coherent(usb_dev, buf->len, buf->buf, buf->dma);
66
- usb_free_urb(buf->urb);
74
+ clear_bit(MT76_STATE_INITIALIZED, &dev->mphy.state);
75
+ mt76x0_chip_onoff(dev, false, false);
76
+ mt76u_queues_deinit(&dev->mt76);
6777 }
6878
69
-int mt76x0_usb_submit_buf(struct mt76x0_dev *dev, int dir, int ep_idx,
70
- struct mt76x0_dma_buf *buf, gfp_t gfp,
71
- usb_complete_t complete_fn, void *context)
79
+static void mt76x0u_stop(struct ieee80211_hw *hw)
7280 {
73
- struct usb_device *usb_dev = mt76x0_to_usb_dev(dev);
74
- unsigned pipe;
81
+ struct mt76x02_dev *dev = hw->priv;
82
+
83
+ clear_bit(MT76_STATE_RUNNING, &dev->mphy.state);
84
+ cancel_delayed_work_sync(&dev->cal_work);
85
+ cancel_delayed_work_sync(&dev->mt76.mac_work);
86
+ mt76u_stop_tx(&dev->mt76);
87
+ mt76x02u_exit_beacon_config(dev);
88
+
89
+ if (test_bit(MT76_REMOVED, &dev->mphy.state))
90
+ return;
91
+
92
+ if (!mt76_poll(dev, MT_USB_DMA_CFG, MT_USB_DMA_CFG_TX_BUSY, 0, 1000))
93
+ dev_warn(dev->mt76.dev, "TX DMA did not stop\n");
94
+
95
+ mt76x0_mac_stop(dev);
96
+
97
+ if (!mt76_poll(dev, MT_USB_DMA_CFG, MT_USB_DMA_CFG_RX_BUSY, 0, 1000))
98
+ dev_warn(dev->mt76.dev, "RX DMA did not stop\n");
99
+}
100
+
101
+static int mt76x0u_start(struct ieee80211_hw *hw)
102
+{
103
+ struct mt76x02_dev *dev = hw->priv;
75104 int ret;
76105
77
- if (dir == USB_DIR_IN)
78
- pipe = usb_rcvbulkpipe(usb_dev, dev->in_ep[ep_idx]);
79
- else
80
- pipe = usb_sndbulkpipe(usb_dev, dev->out_ep[ep_idx]);
81
-
82
- usb_fill_bulk_urb(buf->urb, usb_dev, pipe, buf->buf, buf->len,
83
- complete_fn, context);
84
- buf->urb->transfer_dma = buf->dma;
85
- buf->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
86
-
87
- trace_mt76x0_submit_urb(&dev->mt76, buf->urb);
88
- ret = usb_submit_urb(buf->urb, gfp);
106
+ ret = mt76x02u_mac_start(dev);
89107 if (ret)
90
- dev_err(dev->mt76.dev, "Error: submit URB dir:%d ep:%d failed:%d\n",
91
- dir, ep_idx, ret);
92
- return ret;
108
+ return ret;
109
+
110
+ mt76x0_phy_calibrate(dev, true);
111
+ ieee80211_queue_delayed_work(dev->mt76.hw, &dev->mt76.mac_work,
112
+ MT_MAC_WORK_INTERVAL);
113
+ ieee80211_queue_delayed_work(dev->mt76.hw, &dev->cal_work,
114
+ MT_CALIBRATE_INTERVAL);
115
+ set_bit(MT76_STATE_RUNNING, &dev->mphy.state);
116
+ return 0;
93117 }
94118
95
-void mt76x0_complete_urb(struct urb *urb)
119
+static const struct ieee80211_ops mt76x0u_ops = {
120
+ .tx = mt76x02_tx,
121
+ .start = mt76x0u_start,
122
+ .stop = mt76x0u_stop,
123
+ .add_interface = mt76x02_add_interface,
124
+ .remove_interface = mt76x02_remove_interface,
125
+ .config = mt76x0_config,
126
+ .configure_filter = mt76x02_configure_filter,
127
+ .bss_info_changed = mt76x02_bss_info_changed,
128
+ .sta_state = mt76_sta_state,
129
+ .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
130
+ .set_key = mt76x02_set_key,
131
+ .conf_tx = mt76x02_conf_tx,
132
+ .sw_scan_start = mt76_sw_scan,
133
+ .sw_scan_complete = mt76x02_sw_scan_complete,
134
+ .ampdu_action = mt76x02_ampdu_action,
135
+ .sta_rate_tbl_update = mt76x02_sta_rate_tbl_update,
136
+ .set_rts_threshold = mt76x02_set_rts_threshold,
137
+ .wake_tx_queue = mt76_wake_tx_queue,
138
+ .get_txpower = mt76_get_txpower,
139
+ .get_survey = mt76_get_survey,
140
+ .set_tim = mt76_set_tim,
141
+ .release_buffered_frames = mt76_release_buffered_frames,
142
+ .get_antenna = mt76_get_antenna,
143
+};
144
+
145
+static int mt76x0u_init_hardware(struct mt76x02_dev *dev, bool reset)
96146 {
97
- struct completion *cmpl = urb->context;
147
+ int err;
98148
99
- complete(cmpl);
100
-}
149
+ mt76x0_chip_onoff(dev, true, reset);
101150
102
-int mt76x0_vendor_request(struct mt76x0_dev *dev, const u8 req,
103
- const u8 direction, const u16 val, const u16 offset,
104
- void *buf, const size_t buflen)
105
-{
106
- int i, ret;
107
- struct usb_device *usb_dev = mt76x0_to_usb_dev(dev);
108
- const u8 req_type = direction | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
109
- const unsigned int pipe = (direction == USB_DIR_IN) ?
110
- usb_rcvctrlpipe(usb_dev, 0) : usb_sndctrlpipe(usb_dev, 0);
151
+ if (!mt76x02_wait_for_mac(&dev->mt76))
152
+ return -ETIMEDOUT;
111153
112
- for (i = 0; i < MT_VEND_REQ_MAX_RETRY; i++) {
113
- ret = usb_control_msg(usb_dev, pipe, req, req_type,
114
- val, offset, buf, buflen,
115
- MT_VEND_REQ_TOUT_MS);
116
- trace_mt76x0_vend_req(&dev->mt76, pipe, req, req_type, val, offset,
117
- buf, buflen, ret);
154
+ err = mt76x0u_mcu_init(dev);
155
+ if (err < 0)
156
+ return err;
118157
119
- if (ret == -ENODEV)
120
- set_bit(MT76_REMOVED, &dev->mt76.state);
121
- if (ret >= 0 || ret == -ENODEV)
122
- return ret;
158
+ mt76x0_init_usb_dma(dev);
159
+ err = mt76x0_init_hardware(dev);
160
+ if (err < 0)
161
+ return err;
123162
124
- msleep(5);
125
- }
163
+ mt76x02u_init_beacon_config(dev);
126164
127
- dev_err(dev->mt76.dev, "Vendor request req:%02x off:%04x failed:%d\n",
128
- req, offset, ret);
129
-
130
- return ret;
131
-}
132
-
133
-void mt76x0_vendor_reset(struct mt76x0_dev *dev)
134
-{
135
- mt76x0_vendor_request(dev, MT_VEND_DEV_MODE, USB_DIR_OUT,
136
- MT_VEND_DEV_MODE_RESET, 0, NULL, 0);
137
-}
138
-
139
-static u32 mt76x0_rr(struct mt76_dev *dev, u32 offset)
140
-{
141
- struct mt76x0_dev *mdev = (struct mt76x0_dev *) dev;
142
- int ret;
143
- u32 val = ~0;
144
-
145
- WARN_ONCE(offset > USHRT_MAX, "read high off:%08x", offset);
146
-
147
- mutex_lock(&mdev->usb_ctrl_mtx);
148
-
149
- ret = mt76x0_vendor_request((struct mt76x0_dev *)dev, MT_VEND_MULTI_READ, USB_DIR_IN,
150
- 0, offset, mdev->data, MT_VEND_BUF);
151
- if (ret == MT_VEND_BUF)
152
- val = get_unaligned_le32(mdev->data);
153
- else if (ret > 0)
154
- dev_err(dev->dev, "Error: wrong size read:%d off:%08x\n",
155
- ret, offset);
156
-
157
- mutex_unlock(&mdev->usb_ctrl_mtx);
158
-
159
- trace_mt76x0_reg_read(dev, offset, val);
160
- return val;
161
-}
162
-
163
-int mt76x0_vendor_single_wr(struct mt76x0_dev *dev, const u8 req,
164
- const u16 offset, const u32 val)
165
-{
166
- struct mt76x0_dev *mdev = dev;
167
- int ret;
168
-
169
- mutex_lock(&mdev->usb_ctrl_mtx);
170
-
171
- ret = mt76x0_vendor_request(dev, req, USB_DIR_OUT,
172
- val & 0xffff, offset, NULL, 0);
173
- if (!ret)
174
- ret = mt76x0_vendor_request(dev, req, USB_DIR_OUT,
175
- val >> 16, offset + 2, NULL, 0);
176
-
177
- mutex_unlock(&mdev->usb_ctrl_mtx);
178
-
179
- return ret;
180
-}
181
-
182
-static void mt76x0_wr(struct mt76_dev *dev, u32 offset, u32 val)
183
-{
184
- struct mt76x0_dev *mdev = (struct mt76x0_dev *) dev;
185
- int ret;
186
-
187
- WARN_ONCE(offset > USHRT_MAX, "write high off:%08x", offset);
188
-
189
- mutex_lock(&mdev->usb_ctrl_mtx);
190
-
191
- put_unaligned_le32(val, mdev->data);
192
- ret = mt76x0_vendor_request(mdev, MT_VEND_MULTI_WRITE, USB_DIR_OUT,
193
- 0, offset, mdev->data, MT_VEND_BUF);
194
- trace_mt76x0_reg_write(dev, offset, val);
195
-
196
- mutex_unlock(&mdev->usb_ctrl_mtx);
197
-}
198
-
199
-static u32 mt76x0_rmw(struct mt76_dev *dev, u32 offset, u32 mask, u32 val)
200
-{
201
- val |= mt76x0_rr(dev, offset) & ~mask;
202
- mt76x0_wr(dev, offset, val);
203
- return val;
204
-}
205
-
206
-static void mt76x0_wr_copy(struct mt76_dev *dev, u32 offset,
207
- const void *data, int len)
208
-{
209
- WARN_ONCE(offset & 3, "unaligned write copy off:%08x", offset);
210
- WARN_ONCE(len & 3, "short write copy off:%08x", offset);
211
-
212
- mt76x0_burst_write_regs((struct mt76x0_dev *) dev, offset, data, len / 4);
213
-}
214
-
215
-void mt76x0_addr_wr(struct mt76x0_dev *dev, const u32 offset, const u8 *addr)
216
-{
217
- mt76_wr(dev, offset, get_unaligned_le32(addr));
218
- mt76_wr(dev, offset + 4, addr[4] | addr[5] << 8);
219
-}
220
-
221
-static int mt76x0_assign_pipes(struct usb_interface *usb_intf,
222
- struct mt76x0_dev *dev)
223
-{
224
- struct usb_endpoint_descriptor *ep_desc;
225
- struct usb_host_interface *intf_desc = usb_intf->cur_altsetting;
226
- unsigned i, ep_i = 0, ep_o = 0;
227
-
228
- BUILD_BUG_ON(sizeof(dev->in_ep) < __MT_EP_IN_MAX);
229
- BUILD_BUG_ON(sizeof(dev->out_ep) < __MT_EP_OUT_MAX);
230
-
231
- for (i = 0; i < intf_desc->desc.bNumEndpoints; i++) {
232
- ep_desc = &intf_desc->endpoint[i].desc;
233
-
234
- if (usb_endpoint_is_bulk_in(ep_desc) &&
235
- ep_i++ < __MT_EP_IN_MAX) {
236
- dev->in_ep[ep_i - 1] = usb_endpoint_num(ep_desc);
237
- dev->in_max_packet = usb_endpoint_maxp(ep_desc);
238
- /* Note: this is ignored by usb sub-system but vendor
239
- * code does it. We can drop this at some point.
240
- */
241
- dev->in_ep[ep_i - 1] |= USB_DIR_IN;
242
- } else if (usb_endpoint_is_bulk_out(ep_desc) &&
243
- ep_o++ < __MT_EP_OUT_MAX) {
244
- dev->out_ep[ep_o - 1] = usb_endpoint_num(ep_desc);
245
- dev->out_max_packet = usb_endpoint_maxp(ep_desc);
246
- }
247
- }
248
-
249
- if (ep_i != __MT_EP_IN_MAX || ep_o != __MT_EP_OUT_MAX) {
250
- dev_err(dev->mt76.dev, "Error: wrong pipe number in:%d out:%d\n",
251
- ep_i, ep_o);
252
- return -EINVAL;
253
- }
165
+ mt76_rmw(dev, MT_US_CYC_CFG, MT_US_CYC_CNT, 0x1e);
166
+ mt76_wr(dev, MT_TXOP_CTRL_CFG,
167
+ FIELD_PREP(MT_TXOP_TRUN_EN, 0x3f) |
168
+ FIELD_PREP(MT_TXOP_EXT_CCA_DLY, 0x58));
254169
255170 return 0;
256171 }
257172
258
-static int mt76x0_probe(struct usb_interface *usb_intf,
173
+static int mt76x0u_register_device(struct mt76x02_dev *dev)
174
+{
175
+ struct ieee80211_hw *hw = dev->mt76.hw;
176
+ struct mt76_usb *usb = &dev->mt76.usb;
177
+ int err;
178
+
179
+ usb->mcu.data = devm_kmalloc(dev->mt76.dev, MCU_RESP_URB_SIZE,
180
+ GFP_KERNEL);
181
+ if (!usb->mcu.data)
182
+ return -ENOMEM;
183
+
184
+ err = mt76u_alloc_queues(&dev->mt76);
185
+ if (err < 0)
186
+ goto out_err;
187
+
188
+ err = mt76x0u_init_hardware(dev, true);
189
+ if (err < 0)
190
+ goto out_err;
191
+
192
+ /* check hw sg support in order to enable AMSDU */
193
+ hw->max_tx_fragments = dev->mt76.usb.sg_en ? MT_TX_SG_MAX_SIZE : 1;
194
+ err = mt76x0_register_device(dev);
195
+ if (err < 0)
196
+ goto out_err;
197
+
198
+ set_bit(MT76_STATE_INITIALIZED, &dev->mphy.state);
199
+
200
+ return 0;
201
+
202
+out_err:
203
+ mt76x0u_cleanup(dev);
204
+ return err;
205
+}
206
+
207
+static int mt76x0u_probe(struct usb_interface *usb_intf,
259208 const struct usb_device_id *id)
260209 {
261
- struct usb_device *usb_dev = interface_to_usbdev(usb_intf);
262
- struct mt76x0_dev *dev;
263
- u32 asic_rev, mac_rev;
264
- int ret;
265
- static const struct mt76_bus_ops usb_ops = {
266
- .rr = mt76x0_rr,
267
- .wr = mt76x0_wr,
268
- .rmw = mt76x0_rmw,
269
- .copy = mt76x0_wr_copy,
210
+ static const struct mt76_driver_ops drv_ops = {
211
+ .drv_flags = MT_DRV_SW_RX_AIRTIME,
212
+ .survey_flags = SURVEY_INFO_TIME_TX,
213
+ .update_survey = mt76x02_update_channel,
214
+ .tx_prepare_skb = mt76x02u_tx_prepare_skb,
215
+ .tx_complete_skb = mt76x02u_tx_complete_skb,
216
+ .tx_status_data = mt76x02_tx_status_data,
217
+ .rx_skb = mt76x02_queue_rx_skb,
218
+ .sta_ps = mt76x02_sta_ps,
219
+ .sta_add = mt76x02_sta_add,
220
+ .sta_remove = mt76x02_sta_remove,
270221 };
222
+ struct usb_device *usb_dev = interface_to_usbdev(usb_intf);
223
+ struct mt76x02_dev *dev;
224
+ struct mt76_dev *mdev;
225
+ u32 mac_rev;
226
+ int ret;
271227
272
- dev = mt76x0_alloc_device(&usb_intf->dev);
273
- if (!dev)
228
+ mdev = mt76_alloc_device(&usb_intf->dev, sizeof(*dev), &mt76x0u_ops,
229
+ &drv_ops);
230
+ if (!mdev)
274231 return -ENOMEM;
232
+
233
+ dev = container_of(mdev, struct mt76x02_dev, mt76);
234
+ mutex_init(&dev->phy_mutex);
235
+
236
+ /* Quirk for Archer T1U */
237
+ if (id->driver_info)
238
+ dev->no_2ghz = true;
275239
276240 usb_dev = usb_get_dev(usb_dev);
277241 usb_reset_device(usb_dev);
278242
279243 usb_set_intfdata(usb_intf, dev);
280244
281
- dev->mt76.bus = &usb_ops;
282
-
283
- ret = mt76x0_assign_pipes(usb_intf, dev);
245
+ mt76x02u_init_mcu(mdev);
246
+ ret = mt76u_init(mdev, usb_intf, false);
284247 if (ret)
285248 goto err;
286249
287
- /* Disable the HW, otherwise MCU fail to initalize on hot reboot */
250
+ /* Disable the HW, otherwise MCU fail to initialize on hot reboot */
288251 mt76x0_chip_onoff(dev, false, false);
289252
290
- ret = mt76x0_wait_asic_ready(dev);
291
- if (ret)
253
+ if (!mt76x02_wait_for_mac(mdev)) {
254
+ ret = -ETIMEDOUT;
292255 goto err;
256
+ }
293257
294
- asic_rev = mt76_rr(dev, MT_ASIC_VERSION);
258
+ mdev->rev = mt76_rr(dev, MT_ASIC_VERSION);
295259 mac_rev = mt76_rr(dev, MT_MAC_CSR0);
296
- dev_info(dev->mt76.dev, "ASIC revision: %08x MAC revision: %08x\n",
297
- asic_rev, mac_rev);
260
+ dev_info(mdev->dev, "ASIC revision: %08x MAC revision: %08x\n",
261
+ mdev->rev, mac_rev);
262
+ if (!is_mt76x0(dev)) {
263
+ ret = -ENODEV;
264
+ goto err;
265
+ }
298266
299267 /* Note: vendor driver skips this check for MT76X0U */
300268 if (!(mt76_rr(dev, MT_EFUSE_CTRL) & MT_EFUSE_CTRL_SEL))
301
- dev_warn(dev->mt76.dev, "Warning: eFUSE not present\n");
269
+ dev_warn(mdev->dev, "Warning: eFUSE not present\n");
302270
303
- ret = mt76x0_init_hardware(dev, true);
304
- if (ret)
271
+ ret = mt76x0u_register_device(dev);
272
+ if (ret < 0)
305273 goto err;
306274
307
- ret = mt76x0_register_device(dev);
308
- if (ret)
309
- goto err_hw;
310
-
311
- set_bit(MT76_STATE_INITIALIZED, &dev->mt76.state);
312
-
313275 return 0;
314
-err_hw:
315
- mt76x0_cleanup(dev);
276
+
316277 err:
317278 usb_set_intfdata(usb_intf, NULL);
318279 usb_put_dev(interface_to_usbdev(usb_intf));
280
+ mt76_free_device(&dev->mt76);
319281
320
- destroy_workqueue(dev->stat_wq);
321
- ieee80211_free_hw(dev->mt76.hw);
322282 return ret;
323283 }
324284
325285 static void mt76x0_disconnect(struct usb_interface *usb_intf)
326286 {
327
- struct mt76x0_dev *dev = usb_get_intfdata(usb_intf);
328
- bool initalized = test_bit(MT76_STATE_INITIALIZED, &dev->mt76.state);
287
+ struct mt76x02_dev *dev = usb_get_intfdata(usb_intf);
288
+ bool initialized = test_bit(MT76_STATE_INITIALIZED, &dev->mphy.state);
329289
330
- if (!initalized)
290
+ if (!initialized)
331291 return;
332292
333293 ieee80211_unregister_hw(dev->mt76.hw);
334
- mt76x0_cleanup(dev);
294
+ mt76x0u_cleanup(dev);
335295
336296 usb_set_intfdata(usb_intf, NULL);
337297 usb_put_dev(interface_to_usbdev(usb_intf));
338298
339
- destroy_workqueue(dev->stat_wq);
340
- ieee80211_free_hw(dev->mt76.hw);
299
+ mt76_free_device(&dev->mt76);
341300 }
342301
343
-static int mt76x0_suspend(struct usb_interface *usb_intf, pm_message_t state)
302
+static int __maybe_unused mt76x0_suspend(struct usb_interface *usb_intf,
303
+ pm_message_t state)
344304 {
345
- struct mt76x0_dev *dev = usb_get_intfdata(usb_intf);
305
+ struct mt76x02_dev *dev = usb_get_intfdata(usb_intf);
346306
347
- mt76x0_cleanup(dev);
307
+ mt76u_stop_rx(&dev->mt76);
308
+ clear_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state);
309
+ mt76x0_chip_onoff(dev, false, false);
348310
349311 return 0;
350312 }
351313
352
-static int mt76x0_resume(struct usb_interface *usb_intf)
314
+static int __maybe_unused mt76x0_resume(struct usb_interface *usb_intf)
353315 {
354
- struct mt76x0_dev *dev = usb_get_intfdata(usb_intf);
316
+ struct mt76x02_dev *dev = usb_get_intfdata(usb_intf);
355317 int ret;
356318
357
- ret = mt76x0_init_hardware(dev, false);
358
- if (ret)
359
- return ret;
319
+ ret = mt76u_resume_rx(&dev->mt76);
320
+ if (ret < 0)
321
+ goto err;
360322
361
- set_bit(MT76_STATE_INITIALIZED, &dev->mt76.state);
323
+ ret = mt76x0u_init_hardware(dev, false);
324
+ if (ret)
325
+ goto err;
362326
363327 return 0;
328
+err:
329
+ mt76x0u_cleanup(dev);
330
+ return ret;
364331 }
365332
366333 MODULE_DEVICE_TABLE(usb, mt76x0_device_table);
367
-MODULE_FIRMWARE(MT7610_FIRMWARE);
334
+MODULE_FIRMWARE(MT7610E_FIRMWARE);
335
+MODULE_FIRMWARE(MT7610U_FIRMWARE);
368336 MODULE_LICENSE("GPL");
369337
370338 static struct usb_driver mt76x0_driver = {
371339 .name = KBUILD_MODNAME,
372340 .id_table = mt76x0_device_table,
373
- .probe = mt76x0_probe,
341
+ .probe = mt76x0u_probe,
374342 .disconnect = mt76x0_disconnect,
375343 .suspend = mt76x0_suspend,
376344 .resume = mt76x0_resume,