Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'mt76-for-kvalo-2019-02-18' of https://github.com/nbd168/wireless

mt76 patches for 5.1

* beacon support for USB devices (mesh+ad-hoc only)
* mt76x0 tx power fixes
* fixes for encryption, calibration and ED/CCA
* more code unification
* USB fixes
* fix for using the correct hweight8 function

+524 -422
+2 -1
drivers/net/wireless/mediatek/mt76/Makefile
··· 4 4 obj-$(CONFIG_MT76x02_USB) += mt76x02-usb.o 5 5 6 6 mt76-y := \ 7 - mmio.o util.o trace.o dma.o mac80211.o debugfs.o eeprom.o tx.o agg-rx.o 7 + mmio.o util.o trace.o dma.o mac80211.o debugfs.o eeprom.o \ 8 + tx.o agg-rx.o mcu.o 8 9 9 10 mt76-usb-y := usb.o usb_trace.o usb_mcu.o 10 11
+26 -3
drivers/net/wireless/mediatek/mt76/dma.c
··· 242 242 iowrite32(q->head, &q->regs->cpu_idx); 243 243 } 244 244 245 + static int 246 + mt76_dma_tx_queue_skb_raw(struct mt76_dev *dev, enum mt76_txq_id qid, 247 + struct sk_buff *skb, u32 tx_info) 248 + { 249 + struct mt76_queue *q = &dev->q_tx[qid]; 250 + struct mt76_queue_buf buf; 251 + dma_addr_t addr; 252 + 253 + addr = dma_map_single(dev->dev, skb->data, skb->len, 254 + DMA_TO_DEVICE); 255 + if (dma_mapping_error(dev->dev, addr)) 256 + return -ENOMEM; 257 + 258 + buf.addr = addr; 259 + buf.len = skb->len; 260 + 261 + spin_lock_bh(&q->lock); 262 + mt76_dma_add_buf(dev, q, &buf, 1, tx_info, skb, NULL); 263 + mt76_dma_kick_queue(dev, q); 264 + spin_unlock_bh(&q->lock); 265 + 266 + return 0; 267 + } 268 + 245 269 int mt76_dma_tx_queue_skb(struct mt76_dev *dev, struct mt76_queue *q, 246 270 struct sk_buff *skb, struct mt76_wcid *wcid, 247 271 struct ieee80211_sta *sta) ··· 546 522 static const struct mt76_queue_ops mt76_dma_ops = { 547 523 .init = mt76_dma_init, 548 524 .alloc = mt76_dma_alloc_queue, 549 - .add_buf = mt76_dma_add_buf, 525 + .tx_queue_skb_raw = mt76_dma_tx_queue_skb_raw, 550 526 .tx_queue_skb = mt76_dma_tx_queue_skb, 551 527 .tx_cleanup = mt76_dma_tx_cleanup, 552 528 .rx_reset = mt76_dma_rx_reset, 553 529 .kick = mt76_dma_kick_queue, 554 530 }; 555 531 556 - int mt76_dma_attach(struct mt76_dev *dev) 532 + void mt76_dma_attach(struct mt76_dev *dev) 557 533 { 558 534 dev->queue_ops = &mt76_dma_ops; 559 - return 0; 560 535 } 561 536 EXPORT_SYMBOL_GPL(mt76_dma_attach); 562 537
+1 -1
drivers/net/wireless/mediatek/mt76/dma.h
··· 54 54 EVT_EVENT_DFS_DETECT_RSP, 55 55 }; 56 56 57 - int mt76_dma_attach(struct mt76_dev *dev); 57 + void mt76_dma_attach(struct mt76_dev *dev); 58 58 void mt76_dma_cleanup(struct mt76_dev *dev); 59 59 60 60 #endif
+8 -3
drivers/net/wireless/mediatek/mt76/mac80211.c
··· 124 124 bool vht) 125 125 { 126 126 struct ieee80211_sta_ht_cap *ht_cap = &sband->ht_cap; 127 - int i, nstream = __sw_hweight8(dev->antenna_mask); 127 + int i, nstream = hweight8(dev->antenna_mask); 128 128 struct ieee80211_sta_vht_cap *vht_cap; 129 129 u16 mcs_map = 0; 130 130 ··· 269 269 } 270 270 271 271 struct mt76_dev * 272 - mt76_alloc_device(unsigned int size, const struct ieee80211_ops *ops) 272 + mt76_alloc_device(struct device *pdev, unsigned int size, 273 + const struct ieee80211_ops *ops, 274 + const struct mt76_driver_ops *drv_ops) 273 275 { 274 276 struct ieee80211_hw *hw; 275 277 struct mt76_dev *dev; ··· 282 280 283 281 dev = hw->priv; 284 282 dev->hw = hw; 283 + dev->dev = pdev; 284 + dev->drv = drv_ops; 285 + 285 286 spin_lock_init(&dev->rx_lock); 286 287 spin_lock_init(&dev->lock); 287 288 spin_lock_init(&dev->cc_lock); ··· 726 721 int *dbm) 727 722 { 728 723 struct mt76_dev *dev = hw->priv; 729 - int n_chains = __sw_hweight8(dev->antenna_mask); 724 + int n_chains = hweight8(dev->antenna_mask); 730 725 731 726 *dbm = dev->txpower_cur / 2; 732 727
+60
drivers/net/wireless/mediatek/mt76/mcu.c
··· 1 + /* 2 + * Copyright (C) 2019 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> 3 + * 4 + * Permission to use, copy, modify, and/or distribute this software for any 5 + * purpose with or without fee is hereby granted, provided that the above 6 + * copyright notice and this permission notice appear in all copies. 7 + * 8 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 + */ 16 + 17 + #include "mt76.h" 18 + 19 + struct sk_buff * 20 + mt76_mcu_msg_alloc(const void *data, int head_len, 21 + int data_len, int tail_len) 22 + { 23 + struct sk_buff *skb; 24 + 25 + skb = alloc_skb(head_len + data_len + tail_len, 26 + GFP_KERNEL); 27 + if (!skb) 28 + return NULL; 29 + 30 + skb_reserve(skb, head_len); 31 + if (data && data_len) 32 + skb_put_data(skb, data, data_len); 33 + 34 + return skb; 35 + } 36 + EXPORT_SYMBOL_GPL(mt76_mcu_msg_alloc); 37 + 38 + /* mmio */ 39 + struct sk_buff *mt76_mcu_get_response(struct mt76_dev *dev, 40 + unsigned long expires) 41 + { 42 + unsigned long timeout; 43 + 44 + if (!time_is_after_jiffies(expires)) 45 + return NULL; 46 + 47 + timeout = expires - jiffies; 48 + wait_event_timeout(dev->mmio.mcu.wait, 49 + !skb_queue_empty(&dev->mmio.mcu.res_q), 50 + timeout); 51 + return skb_dequeue(&dev->mmio.mcu.res_q); 52 + } 53 + EXPORT_SYMBOL_GPL(mt76_mcu_get_response); 54 + 55 + void mt76_mcu_rx_event(struct mt76_dev *dev, struct sk_buff *skb) 56 + { 57 + skb_queue_tail(&dev->mmio.mcu.res_q, skb); 58 + wake_up(&dev->mmio.mcu.wait); 59 + } 60 + EXPORT_SYMBOL_GPL(mt76_mcu_rx_event);
+24 -8
drivers/net/wireless/mediatek/mt76/mt76.h
··· 87 87 struct mt76_dev *dev; 88 88 struct urb *urb; 89 89 size_t len; 90 + void *buf; 90 91 bool done; 91 92 }; 92 93 ··· 157 156 int (*tx_queue_skb)(struct mt76_dev *dev, struct mt76_queue *q, 158 157 struct sk_buff *skb, struct mt76_wcid *wcid, 159 158 struct ieee80211_sta *sta); 159 + 160 + int (*tx_queue_skb_raw)(struct mt76_dev *dev, enum mt76_txq_id qid, 161 + struct sk_buff *skb, u32 tx_info); 160 162 161 163 void *(*dequeue)(struct mt76_dev *dev, struct mt76_queue *q, bool flush, 162 164 int *len, u32 *info, bool *more); ··· 380 376 u16 out_max_packet; 381 377 u8 in_ep[__MT_EP_IN_MAX]; 382 378 u16 in_max_packet; 379 + bool sg_en; 383 380 384 381 struct mt76u_mcu { 385 382 struct mutex mutex; ··· 567 562 568 563 #define mt76_init_queues(dev) (dev)->mt76.queue_ops->init(&((dev)->mt76)) 569 564 #define mt76_queue_alloc(dev, ...) (dev)->mt76.queue_ops->alloc(&((dev)->mt76), __VA_ARGS__) 570 - #define mt76_queue_add_buf(dev, ...) (dev)->mt76.queue_ops->add_buf(&((dev)->mt76), __VA_ARGS__) 565 + #define mt76_tx_queue_skb_raw(dev, ...) (dev)->mt76.queue_ops->tx_queue_skb_raw(&((dev)->mt76), __VA_ARGS__) 571 566 #define mt76_queue_rx_reset(dev, ...) (dev)->mt76.queue_ops->rx_reset(&((dev)->mt76), __VA_ARGS__) 572 567 #define mt76_queue_tx_cleanup(dev, ...) (dev)->mt76.queue_ops->tx_cleanup(&((dev)->mt76), __VA_ARGS__) 573 568 #define mt76_queue_kick(dev, ...) (dev)->mt76.queue_ops->kick(&((dev)->mt76), __VA_ARGS__) ··· 587 582 return &msband->chan[idx]; 588 583 } 589 584 590 - struct mt76_dev *mt76_alloc_device(unsigned int size, 591 - const struct ieee80211_ops *ops); 585 + struct mt76_dev *mt76_alloc_device(struct device *pdev, unsigned int size, 586 + const struct ieee80211_ops *ops, 587 + const struct mt76_driver_ops *drv_ops); 592 588 int mt76_register_device(struct mt76_dev *dev, bool vht, 593 589 struct ieee80211_rate *rates, int n_rates); 594 590 void mt76_unregister_device(struct mt76_dev *dev); ··· 728 722 return qid + 1; 729 723 } 730 724 731 - static inline bool mt76u_check_sg(struct mt76_dev *dev) 725 + static inline int 726 + mt76u_bulk_msg(struct mt76_dev *dev, void *data, int len, int timeout) 732 727 { 733 728 struct usb_interface *intf = to_usb_interface(dev->dev); 734 729 struct usb_device *udev = interface_to_usbdev(intf); 730 + struct mt76_usb *usb = &dev->usb; 731 + unsigned int pipe; 732 + int sent; 735 733 736 - return (udev->bus->sg_tablesize > 0 && 737 - (udev->bus->no_sg_constraint || 738 - udev->speed == USB_SPEED_WIRELESS)); 734 + pipe = usb_sndbulkpipe(udev, usb->out_ep[MT_EP_OUT_INBAND_CMD]); 735 + return usb_bulk_msg(udev, pipe, data, len, &sent, timeout); 739 736 } 740 737 741 738 int mt76u_vendor_request(struct mt76_dev *dev, u8 req, ··· 749 740 int mt76u_init(struct mt76_dev *dev, struct usb_interface *intf); 750 741 void mt76u_deinit(struct mt76_dev *dev); 751 742 int mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf, 752 - int nsgs, int len, int sglen, gfp_t gfp); 743 + int len, int data_len, gfp_t gfp); 753 744 void mt76u_buf_free(struct mt76u_buf *buf); 754 745 int mt76u_submit_buf(struct mt76_dev *dev, int dir, int index, 755 746 struct mt76u_buf *buf, gfp_t gfp, ··· 759 750 void mt76u_stop_queues(struct mt76_dev *dev); 760 751 void mt76u_stop_stat_wk(struct mt76_dev *dev); 761 752 void mt76u_queues_deinit(struct mt76_dev *dev); 753 + 754 + struct sk_buff * 755 + mt76_mcu_msg_alloc(const void *data, int head_len, 756 + int data_len, int tail_len); 757 + void mt76_mcu_rx_event(struct mt76_dev *dev, struct sk_buff *skb); 758 + struct sk_buff *mt76_mcu_get_response(struct mt76_dev *dev, 759 + unsigned long expires); 762 760 763 761 void mt76u_mcu_complete_urb(struct urb *urb); 764 762 int mt76u_mcu_init_rx(struct mt76_dev *dev);
+8 -8
drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c
··· 152 152 return mt76x02_rate_power_val(val); 153 153 } 154 154 155 - void mt76x0_get_tx_power_per_rate(struct mt76x02_dev *dev) 155 + void mt76x0_get_tx_power_per_rate(struct mt76x02_dev *dev, 156 + struct ieee80211_channel *chan, 157 + struct mt76_rate_power *t) 156 158 { 157 - struct ieee80211_channel *chan = dev->mt76.chandef.chan; 158 159 bool is_2ghz = chan->band == NL80211_BAND_2GHZ; 159 - struct mt76_rate_power *t = &dev->mt76.rate_power; 160 160 u16 val, addr; 161 161 s8 delta; 162 162 ··· 189 189 addr = is_2ghz ? MT_EE_TX_POWER_BYRATE_BASE + 8 : 0x126; 190 190 val = mt76x02_eeprom_get(dev, addr); 191 191 t->ht[4] = t->ht[5] = t->vht[4] = t->vht[5] = s6_to_s8(val); 192 - t->ht[6] = t->vht[6] = s6_to_s8(val >> 8); 192 + t->ht[6] = t->ht[7] = t->vht[6] = t->vht[7] = s6_to_s8(val >> 8); 193 193 194 194 /* ht-vht mcs 1ss 0, 1, 2, 3 stbc */ 195 195 addr = is_2ghz ? MT_EE_TX_POWER_BYRATE_BASE + 14 : 0xec; ··· 205 205 206 206 /* vht mcs 8, 9 5GHz */ 207 207 val = mt76x02_eeprom_get(dev, 0x132); 208 - t->vht[7] = s6_to_s8(val); 209 - t->vht[8] = s6_to_s8(val >> 8); 208 + t->vht[8] = s6_to_s8(val); 209 + t->vht[9] = s6_to_s8(val >> 8); 210 210 211 211 delta = mt76x0_tssi_enabled(dev) ? 0 : mt76x0_get_delta(dev); 212 212 mt76x02_add_rate_power_offset(t, delta); 213 213 } 214 214 215 - void mt76x0_get_power_info(struct mt76x02_dev *dev, s8 *tp) 215 + void mt76x0_get_power_info(struct mt76x02_dev *dev, 216 + struct ieee80211_channel *chan, s8 *tp) 216 217 { 217 218 struct mt76x0_chan_map { 218 219 u8 chan; ··· 227 226 { 140, 26 }, { 151, 28 }, { 157, 30 }, { 161, 32 }, 228 227 { 167, 34 }, { 171, 36 }, { 175, 38 }, 229 228 }; 230 - struct ieee80211_channel *chan = dev->mt76.chandef.chan; 231 229 u8 offset, addr; 232 230 int i, idx = 0; 233 231 u16 data;
+5 -2
drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h
··· 25 25 26 26 int mt76x0_eeprom_init(struct mt76x02_dev *dev); 27 27 void mt76x0_read_rx_gain(struct mt76x02_dev *dev); 28 - void mt76x0_get_tx_power_per_rate(struct mt76x02_dev *dev); 29 - void mt76x0_get_power_info(struct mt76x02_dev *dev, s8 *tp); 28 + void mt76x0_get_tx_power_per_rate(struct mt76x02_dev *dev, 29 + struct ieee80211_channel *chan, 30 + struct mt76_rate_power *t); 31 + void mt76x0_get_power_info(struct mt76x02_dev *dev, 32 + struct ieee80211_channel *chan, s8 *tp); 30 33 31 34 static inline s8 s6_to_s8(u32 val) 32 35 {
+21 -18
drivers/net/wireless/mediatek/mt76/mt76x0/init.c
··· 18 18 #include "eeprom.h" 19 19 #include "mcu.h" 20 20 #include "initvals.h" 21 + #include "../mt76x02_phy.h" 21 22 22 23 static void mt76x0_vht_cap_mask(struct ieee80211_supported_band *sband) 23 24 { ··· 263 262 } 264 263 EXPORT_SYMBOL_GPL(mt76x0_init_hardware); 265 264 266 - struct mt76x02_dev * 267 - mt76x0_alloc_device(struct device *pdev, 268 - const struct mt76_driver_ops *drv_ops, 269 - const struct ieee80211_ops *ops) 265 + static void 266 + mt76x0_init_txpower(struct mt76x02_dev *dev, 267 + struct ieee80211_supported_band *sband) 270 268 { 271 - struct mt76x02_dev *dev; 272 - struct mt76_dev *mdev; 269 + struct ieee80211_channel *chan; 270 + struct mt76_rate_power t; 271 + s8 tp; 272 + int i; 273 273 274 - mdev = mt76_alloc_device(sizeof(*dev), ops); 275 - if (!mdev) 276 - return NULL; 274 + for (i = 0; i < sband->n_channels; i++) { 275 + chan = &sband->channels[i]; 277 276 278 - mdev->dev = pdev; 279 - mdev->drv = drv_ops; 277 + mt76x0_get_tx_power_per_rate(dev, chan, &t); 278 + mt76x0_get_power_info(dev, chan, &tp); 280 279 281 - dev = container_of(mdev, struct mt76x02_dev, mt76); 282 - mutex_init(&dev->phy_mutex); 283 - 284 - return dev; 280 + chan->max_power = (mt76x02_get_max_rate_power(&t) + tp) / 2; 281 + } 285 282 } 286 - EXPORT_SYMBOL_GPL(mt76x0_alloc_device); 287 283 288 284 int mt76x0_register_device(struct mt76x02_dev *dev) 289 285 { ··· 294 296 if (ret) 295 297 return ret; 296 298 297 - /* overwrite unsupported features */ 298 - if (dev->mt76.cap.has_5ghz) 299 + if (dev->mt76.cap.has_5ghz) { 300 + /* overwrite unsupported features */ 299 301 mt76x0_vht_cap_mask(&dev->mt76.sband_5g.sband); 302 + mt76x0_init_txpower(dev, &dev->mt76.sband_5g.sband); 303 + } 304 + 305 + if (dev->mt76.cap.has_2ghz) 306 + mt76x0_init_txpower(dev, &dev->mt76.sband_2g.sband); 300 307 301 308 mt76x02_init_debugfs(dev); 302 309
-4
drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
··· 50 50 } 51 51 52 52 /* Init */ 53 - struct mt76x02_dev * 54 - mt76x0_alloc_device(struct device *pdev, 55 - const struct mt76_driver_ops *drv_ops, 56 - const struct ieee80211_ops *ops); 57 53 int mt76x0_init_hardware(struct mt76x02_dev *dev); 58 54 int mt76x0_register_device(struct mt76x02_dev *dev); 59 55 void mt76x0_chip_onoff(struct mt76x02_dev *dev, bool enable, bool reset);
+12 -7
drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
··· 30 30 mt76x02_mac_start(dev); 31 31 mt76x0_phy_calibrate(dev, true); 32 32 ieee80211_queue_delayed_work(dev->mt76.hw, &dev->mac_work, 33 - MT_CALIBRATE_INTERVAL); 33 + MT_MAC_WORK_INTERVAL); 34 34 ieee80211_queue_delayed_work(dev->mt76.hw, &dev->cal_work, 35 35 MT_CALIBRATE_INTERVAL); 36 36 set_bit(MT76_STATE_RUNNING, &dev->mt76.state); ··· 174 174 .sta_remove = mt76x02_sta_remove, 175 175 }; 176 176 struct mt76x02_dev *dev; 177 + struct mt76_dev *mdev; 177 178 int ret; 178 179 179 180 ret = pcim_enable_device(pdev); ··· 191 190 if (ret) 192 191 return ret; 193 192 194 - dev = mt76x0_alloc_device(&pdev->dev, &drv_ops, &mt76x0e_ops); 195 - if (!dev) 193 + mdev = mt76_alloc_device(&pdev->dev, sizeof(*dev), &mt76x0e_ops, 194 + &drv_ops); 195 + if (!mdev) 196 196 return -ENOMEM; 197 197 198 - mt76_mmio_init(&dev->mt76, pcim_iomap_table(pdev)[0]); 198 + dev = container_of(mdev, struct mt76x02_dev, mt76); 199 + mutex_init(&dev->phy_mutex); 199 200 200 - dev->mt76.rev = mt76_rr(dev, MT_ASIC_VERSION); 201 - dev_info(dev->mt76.dev, "ASIC revision: %08x\n", dev->mt76.rev); 201 + mt76_mmio_init(mdev, pcim_iomap_table(pdev)[0]); 202 202 203 - ret = devm_request_irq(dev->mt76.dev, pdev->irq, mt76x02_irq_handler, 203 + mdev->rev = mt76_rr(dev, MT_ASIC_VERSION); 204 + dev_info(mdev->dev, "ASIC revision: %08x\n", mdev->rev); 205 + 206 + ret = devm_request_irq(mdev->dev, pdev->irq, mt76x02_irq_handler, 204 207 IRQF_SHARED, KBUILD_MODNAME, dev); 205 208 if (ret) 206 209 goto error;
+7 -4
drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
··· 847 847 struct mt76_rate_power *t = &dev->mt76.rate_power; 848 848 s8 info; 849 849 850 - mt76x0_get_tx_power_per_rate(dev); 851 - mt76x0_get_power_info(dev, &info); 850 + mt76x0_get_tx_power_per_rate(dev, dev->mt76.chandef.chan, t); 851 + mt76x0_get_power_info(dev, dev->mt76.chandef.chan, &info); 852 852 853 853 mt76x02_add_rate_power_offset(t, info); 854 854 mt76x02_limit_rate_power(t, dev->mt76.txpower_conf); 855 855 dev->mt76.txpower_cur = mt76x02_get_max_rate_power(t); 856 856 mt76x02_add_rate_power_offset(t, -info); 857 857 858 + dev->target_power = info; 858 859 mt76x02_phy_set_txpower(dev, info, info); 859 860 } 860 861 ··· 1007 1006 1008 1007 /* enable vco */ 1009 1008 mt76x0_rf_set(dev, MT_RF(0, 4), BIT(7)); 1010 - if (scan) 1009 + if (scan) { 1010 + mt76x02_edcca_init(dev, false); 1011 1011 return 0; 1012 + } 1012 1013 1013 1014 mt76x02_init_agc_gain(dev); 1014 1015 mt76x0_phy_calibrate(dev, false); 1015 1016 mt76x0_phy_set_txpower(dev); 1016 1017 1017 - mt76x02_edcca_init(dev); 1018 + mt76x02_edcca_init(dev, true); 1018 1019 1019 1020 ieee80211_queue_delayed_work(dev->mt76.hw, &dev->cal_work, 1020 1021 MT_CALIBRATE_INTERVAL);
+15 -11
drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
··· 118 118 119 119 mt76x0_phy_calibrate(dev, true); 120 120 ieee80211_queue_delayed_work(dev->mt76.hw, &dev->mac_work, 121 - MT_CALIBRATE_INTERVAL); 121 + MT_MAC_WORK_INTERVAL); 122 122 ieee80211_queue_delayed_work(dev->mt76.hw, &dev->cal_work, 123 123 MT_CALIBRATE_INTERVAL); 124 124 set_bit(MT76_STATE_RUNNING, &dev->mt76.state); ··· 206 206 goto out_err; 207 207 208 208 /* check hw sg support in order to enable AMSDU */ 209 - if (mt76u_check_sg(&dev->mt76)) 209 + if (dev->mt76.usb.sg_en) 210 210 hw->max_tx_fragments = MT_SG_MAX_SIZE; 211 211 else 212 212 hw->max_tx_fragments = 1; ··· 233 233 }; 234 234 struct usb_device *usb_dev = interface_to_usbdev(usb_intf); 235 235 struct mt76x02_dev *dev; 236 + struct mt76_dev *mdev; 236 237 u32 asic_rev, mac_rev; 237 238 int ret; 238 239 239 - dev = mt76x0_alloc_device(&usb_intf->dev, &drv_ops, 240 - &mt76x0u_ops); 241 - if (!dev) 240 + mdev = mt76_alloc_device(&usb_intf->dev, sizeof(*dev), &mt76x0u_ops, 241 + &drv_ops); 242 + if (!mdev) 242 243 return -ENOMEM; 244 + 245 + dev = container_of(mdev, struct mt76x02_dev, mt76); 246 + mutex_init(&dev->phy_mutex); 243 247 244 248 /* Quirk for Archer T1U */ 245 249 if (id->driver_info) ··· 254 250 255 251 usb_set_intfdata(usb_intf, dev); 256 252 257 - mt76x02u_init_mcu(&dev->mt76); 258 - ret = mt76u_init(&dev->mt76, usb_intf); 253 + mt76x02u_init_mcu(mdev); 254 + ret = mt76u_init(mdev, usb_intf); 259 255 if (ret) 260 256 goto err; 261 257 262 258 /* Disable the HW, otherwise MCU fail to initalize on hot reboot */ 263 259 mt76x0_chip_onoff(dev, false, false); 264 260 265 - if (!mt76x02_wait_for_mac(&dev->mt76)) { 261 + if (!mt76x02_wait_for_mac(mdev)) { 266 262 ret = -ETIMEDOUT; 267 263 goto err; 268 264 } 269 265 270 266 asic_rev = mt76_rr(dev, MT_ASIC_VERSION); 271 267 mac_rev = mt76_rr(dev, MT_MAC_CSR0); 272 - dev_info(dev->mt76.dev, "ASIC revision: %08x MAC revision: %08x\n", 268 + dev_info(mdev->dev, "ASIC revision: %08x MAC revision: %08x\n", 273 269 asic_rev, mac_rev); 274 270 275 271 /* Note: vendor driver skips this check for MT76X0U */ 276 272 if (!(mt76_rr(dev, MT_EFUSE_CTRL) & MT_EFUSE_CTRL_SEL)) 277 - dev_warn(dev->mt76.dev, "Warning: eFUSE not present\n"); 273 + dev_warn(mdev->dev, "Warning: eFUSE not present\n"); 278 274 279 275 ret = mt76x0u_register_device(dev); 280 276 if (ret < 0) ··· 286 282 usb_set_intfdata(usb_intf, NULL); 287 283 usb_put_dev(interface_to_usbdev(usb_intf)); 288 284 289 - ieee80211_free_hw(dev->mt76.hw); 285 + ieee80211_free_hw(mdev->hw); 290 286 return ret; 291 287 } 292 288
-6
drivers/net/wireless/mediatek/mt76/mt76x0/usb_mcu.c
··· 140 140 FIELD_PREP(MT_USB_DMA_CFG_RX_BULK_AGG_TOUT, 0x20)); 141 141 mt76x02u_mcu_fw_reset(dev); 142 142 usleep_range(5000, 6000); 143 - /* 144 - mt76x0_rmw(dev, MT_PBF_CFG, 0, (MT_PBF_CFG_TX0Q_EN | 145 - MT_PBF_CFG_TX1Q_EN | 146 - MT_PBF_CFG_TX2Q_EN | 147 - MT_PBF_CFG_TX3Q_EN)); 148 - */ 149 143 150 144 mt76_wr(dev, MT_FCE_PSE_CTRL, 1); 151 145
+5 -2
drivers/net/wireless/mediatek/mt76/mt76x02.h
··· 27 27 #include "mt76x02_dma.h" 28 28 29 29 #define MT_CALIBRATE_INTERVAL HZ 30 + #define MT_MAC_WORK_INTERVAL (HZ / 10) 30 31 31 32 #define MT_WATCHDOG_TIME (HZ / 10) 32 33 #define MT_TX_HANG_TH 10 ··· 74 73 75 74 struct mutex phy_mutex; 76 75 76 + u16 vif_mask; 77 + 77 78 u8 txdone_seq; 78 79 DECLARE_KFIFO_PTR(txstatus_fifo, struct mt76x02_tx_status); 79 80 ··· 117 114 bool ed_monitor; 118 115 u8 ed_trigger; 119 116 u8 ed_silent; 117 + ktime_t ed_time; 120 118 }; 121 119 122 120 extern struct ieee80211_rate mt76x02_rates[12]; ··· 132 128 struct ieee80211_sta *sta); 133 129 134 130 void mt76x02_config_mac_addr_list(struct mt76x02_dev *dev); 135 - void mt76x02_vif_init(struct mt76x02_dev *dev, struct ieee80211_vif *vif, 136 - unsigned int idx); 131 + 137 132 int mt76x02_add_interface(struct ieee80211_hw *hw, 138 133 struct ieee80211_vif *vif); 139 134 void mt76x02_remove_interface(struct ieee80211_hw *hw,
+1 -1
drivers/net/wireless/mediatek/mt76/mt76x02_dfs.c
··· 886 886 tasklet_disable(&dfs_pd->dfs_tasklet); 887 887 888 888 dev->ed_monitor = region == NL80211_DFS_ETSI; 889 - mt76x02_edcca_init(dev); 889 + mt76x02_edcca_init(dev, true); 890 890 891 891 dfs_pd->region = region; 892 892 mt76x02_dfs_init_params(dev);
+72 -18
drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
··· 291 291 292 292 memset(txwi, 0, sizeof(*txwi)); 293 293 294 + if (!info->control.hw_key && wcid && wcid->hw_key_idx != 0xff && 295 + ieee80211_has_protected(hdr->frame_control)) { 296 + wcid = NULL; 297 + ieee80211_get_tx_rates(info->control.vif, sta, skb, 298 + info->control.rates, 1); 299 + } 300 + 294 301 if (wcid) 295 302 txwi->wcid = wcid->idx; 296 303 else ··· 314 307 ccmp_pn[6] = pn >> 32; 315 308 ccmp_pn[7] = pn >> 40; 316 309 txwi->iv = *((__le32 *)&ccmp_pn[0]); 317 - txwi->eiv = *((__le32 *)&ccmp_pn[1]); 310 + txwi->eiv = *((__le32 *)&ccmp_pn[4]); 318 311 } 319 312 320 313 spin_lock_bh(&dev->mt76.lock); ··· 555 548 return 0; 556 549 } 557 550 558 - void mt76x02_mac_setaddr(struct mt76x02_dev *dev, u8 *addr) 551 + void mt76x02_mac_setaddr(struct mt76x02_dev *dev, const u8 *addr) 559 552 { 553 + static const u8 null_addr[ETH_ALEN] = {}; 554 + int i; 555 + 560 556 ether_addr_copy(dev->mt76.macaddr, addr); 561 557 562 558 if (!is_valid_ether_addr(dev->mt76.macaddr)) { ··· 573 563 mt76_wr(dev, MT_MAC_ADDR_DW1, 574 564 get_unaligned_le16(dev->mt76.macaddr + 4) | 575 565 FIELD_PREP(MT_MAC_ADDR_DW1_U2ME_MASK, 0xff)); 566 + 567 + mt76_wr(dev, MT_MAC_BSSID_DW0, 568 + get_unaligned_le32(dev->mt76.macaddr)); 569 + mt76_wr(dev, MT_MAC_BSSID_DW1, 570 + get_unaligned_le16(dev->mt76.macaddr + 4) | 571 + FIELD_PREP(MT_MAC_BSSID_DW1_MBSS_MODE, 3) | /* 8 APs + 8 STAs */ 572 + MT_MAC_BSSID_DW1_MBSS_LOCAL_BIT); 573 + 574 + for (i = 0; i < 16; i++) 575 + mt76x02_mac_set_bssid(dev, i, null_addr); 576 576 } 577 577 EXPORT_SYMBOL_GPL(mt76x02_mac_setaddr); 578 578 ··· 608 588 u16 rate = le16_to_cpu(rxwi->rate); 609 589 u16 tid_sn = le16_to_cpu(rxwi->tid_sn); 610 590 bool unicast = rxwi->rxinfo & cpu_to_le32(MT_RXINFO_UNICAST); 611 - int i, pad_len = 0, nstreams = dev->mt76.chainmask & 0xf; 591 + int pad_len = 0, nstreams = dev->mt76.chainmask & 0xf; 612 592 s8 signal; 613 593 u8 pn_len; 614 594 u8 wcid; ··· 668 648 669 649 status->chains = BIT(0); 670 650 signal = mt76x02_mac_get_rssi(dev, rxwi->rssi[0], 0); 671 - for (i = 0; i < nstreams; i++) { 672 - status->chains |= BIT(i); 673 - status->chain_signal[i] = mt76x02_mac_get_rssi(dev, 674 - rxwi->rssi[i], 675 - i); 676 - signal = max_t(s8, signal, status->chain_signal[i]); 651 + status->chain_signal[0] = signal; 652 + if (nstreams > 1) { 653 + status->chains |= BIT(1); 654 + status->chain_signal[1] = mt76x02_mac_get_rssi(dev, 655 + rxwi->rssi[1], 656 + 1); 657 + signal = max_t(s8, signal, status->chain_signal[1]); 677 658 } 678 659 status->signal = signal; 679 660 status->freq = dev->mt76.chandef.chan->center_freq; ··· 892 871 dev->ed_tx_blocked = !enable; 893 872 } 894 873 895 - void mt76x02_edcca_init(struct mt76x02_dev *dev) 874 + void mt76x02_edcca_init(struct mt76x02_dev *dev, bool enable) 896 875 { 897 876 dev->ed_trigger = 0; 898 877 dev->ed_silent = 0; 899 878 900 - if (dev->ed_monitor) { 879 + if (dev->ed_monitor && enable) { 901 880 struct ieee80211_channel *chan = dev->mt76.chandef.chan; 902 881 u8 ed_th = chan->band == NL80211_BAND_5GHZ ? 0x0e : 0x20; 903 882 ··· 920 899 } 921 900 } 922 901 mt76x02_edcca_tx_enable(dev, true); 902 + 903 + /* clear previous CCA timer value */ 904 + mt76_rr(dev, MT_ED_CCA_TIMER); 905 + dev->ed_time = ktime_get_boottime(); 923 906 } 924 907 EXPORT_SYMBOL_GPL(mt76x02_edcca_init); 925 908 926 - #define MT_EDCCA_TH 90 909 + #define MT_EDCCA_TH 92 927 910 #define MT_EDCCA_BLOCK_TH 2 928 911 static void mt76x02_edcca_check(struct mt76x02_dev *dev) 929 912 { 930 - u32 val, busy; 913 + ktime_t cur_time; 914 + u32 active, val, busy; 931 915 916 + cur_time = ktime_get_boottime(); 932 917 val = mt76_rr(dev, MT_ED_CCA_TIMER); 933 - busy = (val * 100) / jiffies_to_usecs(MT_CALIBRATE_INTERVAL); 918 + 919 + active = ktime_to_us(ktime_sub(cur_time, dev->ed_time)); 920 + dev->ed_time = cur_time; 921 + 922 + busy = (val * 100) / active; 934 923 busy = min_t(u32, busy, 100); 935 924 936 925 if (busy > MT_EDCCA_TH) { ··· 986 955 mt76_tx_status_check(&dev->mt76, NULL, false); 987 956 988 957 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mac_work, 989 - MT_CALIBRATE_INTERVAL); 958 + MT_MAC_WORK_INTERVAL); 990 959 } 991 960 992 961 void mt76x02_mac_set_bssid(struct mt76x02_dev *dev, u8 idx, const u8 *addr) ··· 1078 1047 return 0; 1079 1048 } 1080 1049 1081 - void mt76x02_mac_set_beacon_enable(struct mt76x02_dev *dev, 1082 - u8 vif_idx, bool val) 1050 + static void 1051 + __mt76x02_mac_set_beacon_enable(struct mt76x02_dev *dev, u8 vif_idx, 1052 + bool val, struct sk_buff *skb) 1083 1053 { 1084 1054 u8 old_mask = dev->beacon_mask; 1085 1055 bool en; ··· 1088 1056 1089 1057 if (val) { 1090 1058 dev->beacon_mask |= BIT(vif_idx); 1059 + if (skb) 1060 + mt76x02_mac_set_beacon(dev, vif_idx, skb); 1091 1061 } else { 1092 1062 dev->beacon_mask &= ~BIT(vif_idx); 1093 1063 mt76x02_mac_set_beacon(dev, vif_idx, NULL); ··· 1100 1066 1101 1067 en = dev->beacon_mask; 1102 1068 1103 - mt76_rmw_field(dev, MT_INT_TIMER_EN, MT_INT_TIMER_EN_PRE_TBTT_EN, en); 1104 1069 reg = MT_BEACON_TIME_CFG_BEACON_TX | 1105 1070 MT_BEACON_TIME_CFG_TBTT_EN | 1106 1071 MT_BEACON_TIME_CFG_TIMER_EN; 1107 1072 mt76_rmw(dev, MT_BEACON_TIME_CFG, reg, reg * en); 1108 1073 1074 + if (mt76_is_usb(dev)) 1075 + return; 1076 + 1077 + mt76_rmw_field(dev, MT_INT_TIMER_EN, MT_INT_TIMER_EN_PRE_TBTT_EN, en); 1109 1078 if (en) 1110 1079 mt76x02_irq_enable(dev, MT_INT_PRE_TBTT | MT_INT_TBTT); 1111 1080 else 1112 1081 mt76x02_irq_disable(dev, MT_INT_PRE_TBTT | MT_INT_TBTT); 1082 + } 1083 + 1084 + void mt76x02_mac_set_beacon_enable(struct mt76x02_dev *dev, 1085 + struct ieee80211_vif *vif, bool val) 1086 + { 1087 + u8 vif_idx = ((struct mt76x02_vif *)vif->drv_priv)->idx; 1088 + struct sk_buff *skb = NULL; 1089 + 1090 + if (mt76_is_mmio(dev)) 1091 + tasklet_disable(&dev->pre_tbtt_tasklet); 1092 + else if (val) 1093 + skb = ieee80211_beacon_get(mt76_hw(dev), vif); 1094 + 1095 + __mt76x02_mac_set_beacon_enable(dev, vif_idx, val, skb); 1096 + 1097 + if (mt76_is_mmio(dev)) 1098 + tasklet_enable(&dev->pre_tbtt_tasklet); 1113 1099 }
+4 -4
drivers/net/wireless/mediatek/mt76/mt76x02_mac.h
··· 191 191 void mt76x02_mac_set_tx_protection(struct mt76x02_dev *dev, bool legacy_prot, 192 192 int ht_mode); 193 193 void mt76x02_mac_set_rts_thresh(struct mt76x02_dev *dev, u32 val); 194 - void mt76x02_mac_setaddr(struct mt76x02_dev *dev, u8 *addr); 194 + void mt76x02_mac_setaddr(struct mt76x02_dev *dev, const u8 *addr); 195 195 void mt76x02_mac_write_txwi(struct mt76x02_dev *dev, struct mt76x02_txwi *txwi, 196 196 struct sk_buff *skb, struct mt76_wcid *wcid, 197 197 struct ieee80211_sta *sta, int len); ··· 204 204 void mt76x02_mac_set_bssid(struct mt76x02_dev *dev, u8 idx, const u8 *addr); 205 205 int mt76x02_mac_set_beacon(struct mt76x02_dev *dev, u8 vif_idx, 206 206 struct sk_buff *skb); 207 - void mt76x02_mac_set_beacon_enable(struct mt76x02_dev *dev, u8 vif_idx, 208 - bool val); 207 + void mt76x02_mac_set_beacon_enable(struct mt76x02_dev *dev, 208 + struct ieee80211_vif *vif, bool val); 209 209 210 - void mt76x02_edcca_init(struct mt76x02_dev *dev); 210 + void mt76x02_edcca_init(struct mt76x02_dev *dev, bool enable); 211 211 #endif
+9 -60
drivers/net/wireless/mediatek/mt76/mt76x02_mcu.c
··· 21 21 22 22 #include "mt76x02_mcu.h" 23 23 24 - static struct sk_buff *mt76x02_mcu_msg_alloc(const void *data, int len) 25 - { 26 - struct sk_buff *skb; 27 - 28 - skb = alloc_skb(len, GFP_KERNEL); 29 - if (!skb) 30 - return NULL; 31 - memcpy(skb_put(skb, len), data, len); 32 - 33 - return skb; 34 - } 35 - 36 - static struct sk_buff * 37 - mt76x02_mcu_get_response(struct mt76x02_dev *dev, unsigned long expires) 38 - { 39 - unsigned long timeout; 40 - 41 - if (!time_is_after_jiffies(expires)) 42 - return NULL; 43 - 44 - timeout = expires - jiffies; 45 - wait_event_timeout(dev->mt76.mmio.mcu.wait, 46 - !skb_queue_empty(&dev->mt76.mmio.mcu.res_q), 47 - timeout); 48 - return skb_dequeue(&dev->mt76.mmio.mcu.res_q); 49 - } 50 - 51 - static int 52 - mt76x02_tx_queue_mcu(struct mt76x02_dev *dev, enum mt76_txq_id qid, 53 - struct sk_buff *skb, int cmd, int seq) 54 - { 55 - struct mt76_queue *q = &dev->mt76.q_tx[qid]; 56 - struct mt76_queue_buf buf; 57 - dma_addr_t addr; 58 - u32 tx_info; 59 - 60 - tx_info = MT_MCU_MSG_TYPE_CMD | 61 - FIELD_PREP(MT_MCU_MSG_CMD_TYPE, cmd) | 62 - FIELD_PREP(MT_MCU_MSG_CMD_SEQ, seq) | 63 - FIELD_PREP(MT_MCU_MSG_PORT, CPU_TX_PORT) | 64 - FIELD_PREP(MT_MCU_MSG_LEN, skb->len); 65 - 66 - addr = dma_map_single(dev->mt76.dev, skb->data, skb->len, 67 - DMA_TO_DEVICE); 68 - if (dma_mapping_error(dev->mt76.dev, addr)) 69 - return -ENOMEM; 70 - 71 - buf.addr = addr; 72 - buf.len = skb->len; 73 - 74 - spin_lock_bh(&q->lock); 75 - mt76_queue_add_buf(dev, q, &buf, 1, tx_info, skb, NULL); 76 - mt76_queue_kick(dev, q); 77 - spin_unlock_bh(&q->lock); 78 - 79 - return 0; 80 - } 81 - 82 24 int mt76x02_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data, 83 25 int len, bool wait_resp) 84 26 { 85 27 struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76); 86 28 unsigned long expires = jiffies + HZ; 87 29 struct sk_buff *skb; 30 + u32 tx_info; 88 31 int ret; 89 32 u8 seq; 90 33 ··· 41 98 if (!seq) 42 99 seq = ++mdev->mmio.mcu.msg_seq & 0xf; 43 100 44 - ret = mt76x02_tx_queue_mcu(dev, MT_TXQ_MCU, skb, cmd, seq); 101 + tx_info = MT_MCU_MSG_TYPE_CMD | 102 + FIELD_PREP(MT_MCU_MSG_CMD_TYPE, cmd) | 103 + FIELD_PREP(MT_MCU_MSG_CMD_SEQ, seq) | 104 + FIELD_PREP(MT_MCU_MSG_PORT, CPU_TX_PORT) | 105 + FIELD_PREP(MT_MCU_MSG_LEN, skb->len); 106 + 107 + ret = mt76_tx_queue_skb_raw(dev, MT_TXQ_MCU, skb, tx_info); 45 108 if (ret) 46 109 goto out; 47 110 ··· 55 106 u32 *rxfce; 56 107 bool check_seq = false; 57 108 58 - skb = mt76x02_mcu_get_response(dev, expires); 109 + skb = mt76_mcu_get_response(&dev->mt76, expires); 59 110 if (!skb) { 60 111 dev_err(mdev->dev, 61 112 "MCU message %d (seq %d) timed out\n", cmd,
+6
drivers/net/wireless/mediatek/mt76/mt76x02_mcu.h
··· 96 96 u8 pad[2]; 97 97 }; 98 98 99 + static inline struct sk_buff * 100 + mt76x02_mcu_msg_alloc(const void *data, int len) 101 + { 102 + return mt76_mcu_msg_alloc(data, 0, len, 0); 103 + } 104 + 99 105 int mt76x02_mcu_cleanup(struct mt76x02_dev *dev); 100 106 int mt76x02_mcu_calibrate(struct mt76x02_dev *dev, int type, u32 param); 101 107 int mt76x02_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data,
+2 -10
drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c
··· 22 22 void mt76x02_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, 23 23 struct sk_buff *skb) 24 24 { 25 - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 26 25 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 27 26 struct mt76x02_dev *dev = hw->priv; 28 27 struct ieee80211_vif *vif = info->control.vif; ··· 32 33 33 34 msta = (struct mt76x02_sta *)control->sta->drv_priv; 34 35 wcid = &msta->wcid; 35 - /* sw encrypted frames */ 36 - if (!info->control.hw_key && wcid->hw_key_idx != 0xff && 37 - ieee80211_has_protected(hdr->frame_control)) 38 - control->sta = NULL; 39 - } 40 - 41 - if (vif && !control->sta) { 36 + } else if (vif) { 42 37 struct mt76x02_vif *mvif; 43 38 44 39 mvif = (struct mt76x02_vif *)vif->drv_priv; ··· 51 58 52 59 if (q == MT_RXQ_MCU) { 53 60 /* this is used just by mmio code */ 54 - skb_queue_tail(&mdev->mmio.mcu.res_q, skb); 55 - wake_up(&mdev->mmio.mcu.wait); 61 + mt76_mcu_rx_event(&dev->mt76, skb); 56 62 return; 57 63 } 58 64
+9 -5
drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c
··· 49 49 FIELD_PREP(MT_TXD_INFO_DPORT, port) | flags; 50 50 put_unaligned_le32(info, skb_push(skb, sizeof(info))); 51 51 52 + /* Add zero pad of 4 - 7 bytes */ 52 53 pad = round_up(skb->len, 4) + 4 - skb->len; 54 + 55 + /* First packet of a A-MSDU burst keeps track of the whole burst 56 + * length, need to update lenght of it and the last packet. 57 + */ 53 58 skb_walk_frags(skb, iter) { 54 59 last = iter; 55 60 if (!iter->next) { ··· 64 59 } 65 60 } 66 61 67 - if (unlikely(pad)) { 68 - if (skb_pad(last, pad)) 69 - return -ENOMEM; 70 - __skb_put(last, pad); 71 - } 62 + if (skb_pad(last, pad)) 63 + return -ENOMEM; 64 + __skb_put(last, pad); 65 + 72 66 return 0; 73 67 } 74 68
+18 -54
drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
··· 28 28 29 29 #define MT_TX_CPU_FROM_FCE_CPU_DESC_IDX 0x09a8 30 30 31 - static struct sk_buff * 32 - mt76x02u_mcu_msg_alloc(const void *data, int len) 33 - { 34 - struct sk_buff *skb; 35 - 36 - skb = alloc_skb(MT_CMD_HDR_LEN + len + 8, GFP_KERNEL); 37 - if (!skb) 38 - return NULL; 39 - 40 - skb_reserve(skb, MT_CMD_HDR_LEN); 41 - skb_put_data(skb, data, len); 42 - 43 - return skb; 44 - } 45 - 46 31 static void 47 32 mt76x02u_multiple_mcu_reads(struct mt76_dev *dev, u8 *data, int len) 48 33 { ··· 63 78 struct mt76_usb *usb = &dev->usb; 64 79 struct mt76u_buf *buf = &usb->mcu.res; 65 80 struct urb *urb = buf->urb; 81 + u8 *data = buf->buf; 66 82 int i, ret; 67 83 u32 rxfce; 68 - u8 *data; 69 84 70 85 for (i = 0; i < 5; i++) { 71 86 if (!wait_for_completion_timeout(&usb->mcu.cmpl, ··· 75 90 if (urb->status) 76 91 return -EIO; 77 92 78 - data = sg_virt(&urb->sg[0]); 79 93 if (usb->mcu.rp) 80 94 mt76x02u_multiple_mcu_reads(dev, data + 4, 81 95 urb->actual_length - 8); ··· 105 121 __mt76x02u_mcu_send_msg(struct mt76_dev *dev, struct sk_buff *skb, 106 122 int cmd, bool wait_resp) 107 123 { 108 - struct usb_interface *intf = to_usb_interface(dev->dev); 109 - struct usb_device *udev = interface_to_usbdev(intf); 110 124 struct mt76_usb *usb = &dev->usb; 111 - unsigned int pipe; 112 - int ret, sent; 125 + int ret; 113 126 u8 seq = 0; 114 127 u32 info; 115 128 116 129 if (test_bit(MT76_REMOVED, &dev->state)) 117 130 return 0; 118 131 119 - pipe = usb_sndbulkpipe(udev, usb->out_ep[MT_EP_OUT_INBAND_CMD]); 120 132 if (wait_resp) { 121 133 seq = ++usb->mcu.msg_seq & 0xf; 122 134 if (!seq) ··· 126 146 if (ret) 127 147 return ret; 128 148 129 - ret = usb_bulk_msg(udev, pipe, skb->data, skb->len, &sent, 500); 149 + ret = mt76u_bulk_msg(dev, skb->data, skb->len, 500); 130 150 if (ret) 131 151 return ret; 132 152 ··· 146 166 struct sk_buff *skb; 147 167 int err; 148 168 149 - skb = mt76x02u_mcu_msg_alloc(data, len); 169 + skb = mt76_mcu_msg_alloc(data, MT_CMD_HDR_LEN, len, 8); 150 170 if (!skb) 151 171 return -ENOMEM; 152 172 ··· 248 268 EXPORT_SYMBOL_GPL(mt76x02u_mcu_fw_reset); 249 269 250 270 static int 251 - __mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, struct mt76u_buf *buf, 271 + __mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, u8 *data, 252 272 const void *fw_data, int len, u32 dst_addr) 253 273 { 254 - u8 *data = sg_virt(&buf->urb->sg[0]); 255 - DECLARE_COMPLETION_ONSTACK(cmpl); 256 274 __le32 info; 257 275 u32 val; 258 - int err; 276 + int err, data_len; 259 277 260 278 info = cpu_to_le32(FIELD_PREP(MT_MCU_MSG_PORT, CPU_TX_PORT) | 261 279 FIELD_PREP(MT_MCU_MSG_LEN, len) | ··· 269 291 mt76u_single_wr(&dev->mt76, MT_VEND_WRITE_FCE, 270 292 MT_FCE_DMA_LEN, len << 16); 271 293 272 - buf->len = MT_CMD_HDR_LEN + len + sizeof(info); 273 - err = mt76u_submit_buf(&dev->mt76, USB_DIR_OUT, 274 - MT_EP_OUT_INBAND_CMD, 275 - buf, GFP_KERNEL, 276 - mt76u_mcu_complete_urb, &cmpl); 277 - if (err < 0) 294 + data_len = MT_CMD_HDR_LEN + len + sizeof(info); 295 + 296 + err = mt76u_bulk_msg(&dev->mt76, data, data_len, 1000); 297 + if (err) { 298 + dev_err(dev->mt76.dev, "firmware upload failed: %d\n", err); 278 299 return err; 279 - 280 - if (!wait_for_completion_timeout(&cmpl, 281 - msecs_to_jiffies(1000))) { 282 - dev_err(dev->mt76.dev, "firmware upload timed out\n"); 283 - usb_kill_urb(buf->urb); 284 - return -ETIMEDOUT; 285 - } 286 - 287 - if (mt76u_urb_error(buf->urb)) { 288 - dev_err(dev->mt76.dev, "firmware upload failed: %d\n", 289 - buf->urb->status); 290 - return buf->urb->status; 291 300 } 292 301 293 302 val = mt76_rr(dev, MT_TX_CPU_FROM_FCE_CPU_DESC_IDX); ··· 287 322 int mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, const void *data, 288 323 int data_len, u32 max_payload, u32 offset) 289 324 { 290 - int err, len, pos = 0, max_len = max_payload - 8; 291 - struct mt76u_buf buf; 325 + int len, err = 0, pos = 0, max_len = max_payload - 8; 326 + u8 *buf; 292 327 293 - err = mt76u_buf_alloc(&dev->mt76, &buf, 1, max_payload, max_payload, 294 - GFP_KERNEL); 295 - if (err < 0) 296 - return err; 328 + buf = kmalloc(max_payload, GFP_KERNEL); 329 + if (!buf) 330 + return -ENOMEM; 297 331 298 332 while (data_len > 0) { 299 333 len = min_t(int, data_len, max_len); 300 - err = __mt76x02u_mcu_fw_send_data(dev, &buf, data + pos, 334 + err = __mt76x02u_mcu_fw_send_data(dev, buf, data + pos, 301 335 len, offset + pos); 302 336 if (err < 0) 303 337 break; ··· 305 341 pos += len; 306 342 usleep_range(5000, 10000); 307 343 } 308 - mt76u_buf_free(&buf); 344 + kfree(buf); 309 345 310 346 return err; 311 347 }
+41 -38
drivers/net/wireless/mediatek/mt76/mt76x02_util.c
··· 140 140 hw->max_rate_tries = 1; 141 141 hw->extra_tx_headroom = 2; 142 142 143 + wiphy->interface_modes = 144 + BIT(NL80211_IFTYPE_STATION) | 145 + #ifdef CONFIG_MAC80211_MESH 146 + BIT(NL80211_IFTYPE_MESH_POINT) | 147 + #endif 148 + BIT(NL80211_IFTYPE_ADHOC); 149 + 143 150 if (mt76_is_usb(dev)) { 144 151 hw->extra_tx_headroom += sizeof(struct mt76x02_txwi) + 145 152 MT_DMA_HDR_LEN; 146 - wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); 147 153 } else { 148 154 INIT_DELAYED_WORK(&dev->wdt_work, mt76x02_wdt_work); 149 155 ··· 158 152 wiphy->reg_notifier = mt76x02_regd_notifier; 159 153 wiphy->iface_combinations = mt76x02_if_comb; 160 154 wiphy->n_iface_combinations = ARRAY_SIZE(mt76x02_if_comb); 161 - wiphy->interface_modes = 162 - BIT(NL80211_IFTYPE_STATION) | 163 - BIT(NL80211_IFTYPE_AP) | 164 - #ifdef CONFIG_MAC80211_MESH 165 - BIT(NL80211_IFTYPE_MESH_POINT) | 166 - #endif 167 - BIT(NL80211_IFTYPE_ADHOC); 168 - 155 + wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP); 169 156 wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; 170 - 171 - wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS); 172 157 173 158 /* init led callbacks */ 174 159 if (IS_ENABLED(CONFIG_MT76_LEDS)) { ··· 168 171 dev->mt76.led_cdev.blink_set = mt76x02_led_set_blink; 169 172 } 170 173 } 174 + 175 + wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS); 171 176 172 177 hw->sta_data_size = sizeof(struct mt76x02_sta); 173 178 hw->vif_data_size = sizeof(struct mt76x02_vif); ··· 267 268 } 268 269 EXPORT_SYMBOL_GPL(mt76x02_sta_remove); 269 270 270 - void mt76x02_vif_init(struct mt76x02_dev *dev, struct ieee80211_vif *vif, 271 - unsigned int idx) 271 + static void 272 + mt76x02_vif_init(struct mt76x02_dev *dev, struct ieee80211_vif *vif, 273 + unsigned int idx) 272 274 { 273 275 struct mt76x02_vif *mvif = (struct mt76x02_vif *)vif->drv_priv; 274 276 struct mt76_txq *mtxq; ··· 282 282 283 283 mt76_txq_init(&dev->mt76, vif->txq); 284 284 } 285 - EXPORT_SYMBOL_GPL(mt76x02_vif_init); 286 285 287 286 int 288 287 mt76x02_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) ··· 308 309 if (vif->type == NL80211_IFTYPE_STATION) 309 310 idx += 8; 310 311 312 + if (dev->vif_mask & BIT(idx)) 313 + return -EBUSY; 314 + 315 + /* Allow to change address in HW if we create first interface. */ 316 + if (!dev->vif_mask && !ether_addr_equal(dev->mt76.macaddr, vif->addr)) 317 + mt76x02_mac_setaddr(dev, vif->addr); 318 + 319 + dev->vif_mask |= BIT(idx); 320 + 311 321 mt76x02_vif_init(dev, vif, idx); 312 322 return 0; 313 323 } ··· 326 318 struct ieee80211_vif *vif) 327 319 { 328 320 struct mt76x02_dev *dev = hw->priv; 321 + struct mt76x02_vif *mvif = (struct mt76x02_vif *)vif->drv_priv; 329 322 330 323 mt76_txq_remove(&dev->mt76, vif->txq); 324 + dev->vif_mask &= ~BIT(mvif->idx); 331 325 } 332 326 EXPORT_SYMBOL_GPL(mt76x02_remove_interface); 333 327 ··· 431 421 } else { 432 422 if (idx == wcid->hw_key_idx) { 433 423 wcid->hw_key_idx = -1; 434 - wcid->sw_iv = true; 424 + wcid->sw_iv = false; 435 425 } 436 426 437 427 key = NULL; ··· 667 657 668 658 void mt76x02_init_beacon_config(struct mt76x02_dev *dev) 669 659 { 670 - static const u8 null_addr[ETH_ALEN] = {}; 671 660 int i; 672 661 673 - mt76_wr(dev, MT_MAC_BSSID_DW0, 674 - get_unaligned_le32(dev->mt76.macaddr)); 675 - mt76_wr(dev, MT_MAC_BSSID_DW1, 676 - get_unaligned_le16(dev->mt76.macaddr + 4) | 677 - FIELD_PREP(MT_MAC_BSSID_DW1_MBSS_MODE, 3) | /* 8 beacons */ 678 - MT_MAC_BSSID_DW1_MBSS_LOCAL_BIT); 662 + if (mt76_is_mmio(dev)) { 663 + /* Fire a pre-TBTT interrupt 8 ms before TBTT */ 664 + mt76_rmw_field(dev, MT_INT_TIMER_CFG, MT_INT_TIMER_CFG_PRE_TBTT, 665 + 8 << 4); 666 + mt76_rmw_field(dev, MT_INT_TIMER_CFG, MT_INT_TIMER_CFG_GP_TIMER, 667 + MT_DFS_GP_INTERVAL); 668 + mt76_wr(dev, MT_INT_TIMER_EN, 0); 669 + } 679 670 680 - /* Fire a pre-TBTT interrupt 8 ms before TBTT */ 681 - mt76_rmw_field(dev, MT_INT_TIMER_CFG, MT_INT_TIMER_CFG_PRE_TBTT, 682 - 8 << 4); 683 - mt76_rmw_field(dev, MT_INT_TIMER_CFG, MT_INT_TIMER_CFG_GP_TIMER, 684 - MT_DFS_GP_INTERVAL); 685 - mt76_wr(dev, MT_INT_TIMER_EN, 0); 686 - 671 + mt76_clear(dev, MT_BEACON_TIME_CFG, (MT_BEACON_TIME_CFG_TIMER_EN | 672 + MT_BEACON_TIME_CFG_SYNC_MODE | 673 + MT_BEACON_TIME_CFG_TBTT_EN | 674 + MT_BEACON_TIME_CFG_BEACON_TX)); 687 675 mt76_wr(dev, MT_BCN_BYPASS_MASK, 0xffff); 688 676 689 - for (i = 0; i < 8; i++) { 690 - mt76x02_mac_set_bssid(dev, i, null_addr); 677 + for (i = 0; i < 8; i++) 691 678 mt76x02_mac_set_beacon(dev, i, NULL); 692 - } 679 + 693 680 mt76x02_set_beacon_offsets(dev); 694 681 } 695 682 EXPORT_SYMBOL_GPL(mt76x02_init_beacon_config); ··· 704 697 if (changed & BSS_CHANGED_BSSID) 705 698 mt76x02_mac_set_bssid(dev, mvif->idx, info->bssid); 706 699 707 - if (changed & BSS_CHANGED_BEACON_ENABLED) { 708 - tasklet_disable(&dev->pre_tbtt_tasklet); 709 - mt76x02_mac_set_beacon_enable(dev, mvif->idx, 710 - info->enable_beacon); 711 - tasklet_enable(&dev->pre_tbtt_tasklet); 712 - } 700 + if (changed & BSS_CHANGED_BEACON_ENABLED) 701 + mt76x02_mac_set_beacon_enable(dev, vif, info->enable_beacon); 713 702 714 703 if (changed & BSS_CHANGED_HT || changed & BSS_CHANGED_ERP_CTS_PROT) 715 704 mt76x02_mac_set_tx_protection(dev, info->use_cts_prot,
-1
drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h
··· 49 49 50 50 extern const struct ieee80211_ops mt76x2_ops; 51 51 52 - struct mt76x02_dev *mt76x2_alloc_device(struct device *pdev); 53 52 int mt76x2_register_device(struct mt76x02_dev *dev); 54 53 55 54 void mt76x2_phy_power_on(struct mt76x02_dev *dev);
-1
drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2u.h
··· 29 29 30 30 extern const struct ieee80211_ops mt76x2u_ops; 31 31 32 - struct mt76x02_dev *mt76x2u_alloc_device(struct device *pdev); 33 32 int mt76x2u_register_device(struct mt76x02_dev *dev); 34 33 int mt76x2u_init_hardware(struct mt76x02_dev *dev); 35 34 void mt76x2u_cleanup(struct mt76x02_dev *dev);
+20 -6
drivers/net/wireless/mediatek/mt76/mt76x2/pci.c
··· 30 30 static int 31 31 mt76pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) 32 32 { 33 + static const struct mt76_driver_ops drv_ops = { 34 + .txwi_size = sizeof(struct mt76x02_txwi), 35 + .update_survey = mt76x02_update_channel, 36 + .tx_prepare_skb = mt76x02_tx_prepare_skb, 37 + .tx_complete_skb = mt76x02_tx_complete_skb, 38 + .rx_skb = mt76x02_queue_rx_skb, 39 + .rx_poll_complete = mt76x02_rx_poll_complete, 40 + .sta_ps = mt76x02_sta_ps, 41 + .sta_add = mt76x02_sta_add, 42 + .sta_remove = mt76x02_sta_remove, 43 + }; 33 44 struct mt76x02_dev *dev; 45 + struct mt76_dev *mdev; 34 46 int ret; 35 47 36 48 ret = pcim_enable_device(pdev); ··· 59 47 if (ret) 60 48 return ret; 61 49 62 - dev = mt76x2_alloc_device(&pdev->dev); 63 - if (!dev) 50 + mdev = mt76_alloc_device(&pdev->dev, sizeof(*dev), &mt76x2_ops, 51 + &drv_ops); 52 + if (!mdev) 64 53 return -ENOMEM; 65 54 66 - mt76_mmio_init(&dev->mt76, pcim_iomap_table(pdev)[0]); 55 + dev = container_of(mdev, struct mt76x02_dev, mt76); 56 + mt76_mmio_init(mdev, pcim_iomap_table(pdev)[0]); 67 57 mt76x2_reset_wlan(dev, false); 68 58 69 - dev->mt76.rev = mt76_rr(dev, MT_ASIC_VERSION); 70 - dev_info(dev->mt76.dev, "ASIC revision: %08x\n", dev->mt76.rev); 59 + mdev->rev = mt76_rr(dev, MT_ASIC_VERSION); 60 + dev_info(mdev->dev, "ASIC revision: %08x\n", mdev->rev); 71 61 72 - ret = devm_request_irq(dev->mt76.dev, pdev->irq, mt76x02_irq_handler, 62 + ret = devm_request_irq(mdev->dev, pdev->irq, mt76x02_irq_handler, 73 63 IRQF_SHARED, KBUILD_MODNAME, dev); 74 64 if (ret) 75 65 goto error;
+1 -30
drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c
··· 119 119 mt76_wr(dev, MT_MCU_CLOCK_CTL, 0x1401); 120 120 mt76_clear(dev, MT_FCE_L2_STUFF, MT_FCE_L2_STUFF_WR_MPDU_LEN_EN); 121 121 122 - mt76_wr(dev, MT_MAC_ADDR_DW0, get_unaligned_le32(macaddr)); 123 - mt76_wr(dev, MT_MAC_ADDR_DW1, get_unaligned_le16(macaddr + 4)); 124 - 122 + mt76x02_mac_setaddr(dev, macaddr); 125 123 mt76x02_init_beacon_config(dev); 126 124 if (!hard) 127 125 return 0; ··· 311 313 mt76x2_stop_hardware(dev); 312 314 mt76x02_dma_cleanup(dev); 313 315 mt76x02_mcu_cleanup(dev); 314 - } 315 - 316 - struct mt76x02_dev *mt76x2_alloc_device(struct device *pdev) 317 - { 318 - static const struct mt76_driver_ops drv_ops = { 319 - .txwi_size = sizeof(struct mt76x02_txwi), 320 - .update_survey = mt76x02_update_channel, 321 - .tx_prepare_skb = mt76x02_tx_prepare_skb, 322 - .tx_complete_skb = mt76x02_tx_complete_skb, 323 - .rx_skb = mt76x02_queue_rx_skb, 324 - .rx_poll_complete = mt76x02_rx_poll_complete, 325 - .sta_ps = mt76x02_sta_ps, 326 - .sta_add = mt76x02_sta_add, 327 - .sta_remove = mt76x02_sta_remove, 328 - }; 329 - struct mt76x02_dev *dev; 330 - struct mt76_dev *mdev; 331 - 332 - mdev = mt76_alloc_device(sizeof(*dev), &mt76x2_ops); 333 - if (!mdev) 334 - return NULL; 335 - 336 - dev = container_of(mdev, struct mt76x02_dev, mt76); 337 - mdev->dev = pdev; 338 - mdev->drv = &drv_ops; 339 - 340 - return dev; 341 316 } 342 317 343 318 int mt76x2_register_device(struct mt76x02_dev *dev)
+1 -1
drivers/net/wireless/mediatek/mt76/mt76x2/pci_main.c
··· 33 33 goto out; 34 34 35 35 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mac_work, 36 - MT_CALIBRATE_INTERVAL); 36 + MT_MAC_WORK_INTERVAL); 37 37 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->wdt_work, 38 38 MT_WATCHDOG_TIME); 39 39
+4 -2
drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c
··· 240 240 mt76_wr(dev, MT_BBP(AGC, 2), 0x00007070); 241 241 mt76_wr(dev, MT_TXOP_CTRL_CFG, 0x04101B3F); 242 242 243 - if (scan) 243 + if (scan) { 244 + mt76x02_edcca_init(dev, false); 244 245 return 0; 246 + } 245 247 246 248 mt76x2_phy_channel_calibrate(dev, true); 247 249 mt76x02_init_agc_gain(dev); ··· 256 254 0x38); 257 255 } 258 256 259 - mt76x02_edcca_init(dev); 257 + mt76x02_edcca_init(dev, true); 260 258 261 259 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->cal_work, 262 260 MT_CALIBRATE_INTERVAL);
+1 -1
drivers/net/wireless/mediatek/mt76/mt76x2/phy.c
··· 241 241 t.offset1 = txp.chain[1].tssi_offset; 242 242 mt76x2_mcu_tssi_comp(dev, &t); 243 243 244 - if (t.pa_mode || dev->cal.dpd_cal_done) 244 + if (t.pa_mode || dev->cal.dpd_cal_done || dev->ed_tx_blocked) 245 245 return; 246 246 247 247 usleep_range(10000, 20000);
+18 -6
drivers/net/wireless/mediatek/mt76/mt76x2/usb.c
··· 36 36 static int mt76x2u_probe(struct usb_interface *intf, 37 37 const struct usb_device_id *id) 38 38 { 39 + static const struct mt76_driver_ops drv_ops = { 40 + .tx_prepare_skb = mt76x02u_tx_prepare_skb, 41 + .tx_complete_skb = mt76x02u_tx_complete_skb, 42 + .tx_status_data = mt76x02_tx_status_data, 43 + .rx_skb = mt76x02_queue_rx_skb, 44 + .sta_add = mt76x02_sta_add, 45 + .sta_remove = mt76x02_sta_remove, 46 + }; 39 47 struct usb_device *udev = interface_to_usbdev(intf); 40 48 struct mt76x02_dev *dev; 49 + struct mt76_dev *mdev; 41 50 int err; 42 51 43 - dev = mt76x2u_alloc_device(&intf->dev); 44 - if (!dev) 52 + mdev = mt76_alloc_device(&intf->dev, sizeof(*dev), &mt76x2u_ops, 53 + &drv_ops); 54 + if (!mdev) 45 55 return -ENOMEM; 56 + 57 + dev = container_of(mdev, struct mt76x02_dev, mt76); 46 58 47 59 udev = usb_get_dev(udev); 48 60 usb_reset_device(udev); 49 61 50 - mt76x02u_init_mcu(&dev->mt76); 51 - err = mt76u_init(&dev->mt76, intf); 62 + mt76x02u_init_mcu(mdev); 63 + err = mt76u_init(mdev, intf); 52 64 if (err < 0) 53 65 goto err; 54 66 55 - dev->mt76.rev = mt76_rr(dev, MT_ASIC_VERSION); 56 - dev_info(dev->mt76.dev, "ASIC revision: %08x\n", dev->mt76.rev); 67 + mdev->rev = mt76_rr(dev, MT_ASIC_VERSION); 68 + dev_info(mdev->dev, "ASIC revision: %08x\n", mdev->rev); 57 69 58 70 err = mt76x2u_register_device(dev); 59 71 if (err < 0)
+2 -30
drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c
··· 134 134 return 0; 135 135 } 136 136 137 - struct mt76x02_dev *mt76x2u_alloc_device(struct device *pdev) 138 - { 139 - static const struct mt76_driver_ops drv_ops = { 140 - .tx_prepare_skb = mt76x02u_tx_prepare_skb, 141 - .tx_complete_skb = mt76x02u_tx_complete_skb, 142 - .tx_status_data = mt76x02_tx_status_data, 143 - .rx_skb = mt76x02_queue_rx_skb, 144 - .sta_add = mt76x02_sta_add, 145 - .sta_remove = mt76x02_sta_remove, 146 - }; 147 - struct mt76x02_dev *dev; 148 - struct mt76_dev *mdev; 149 - 150 - mdev = mt76_alloc_device(sizeof(*dev), &mt76x2u_ops); 151 - if (!mdev) 152 - return NULL; 153 - 154 - dev = container_of(mdev, struct mt76x02_dev, mt76); 155 - mdev->dev = pdev; 156 - mdev->drv = &drv_ops; 157 - 158 - return dev; 159 - } 160 - 161 137 int mt76x2u_init_hardware(struct mt76x02_dev *dev) 162 138 { 163 139 int i, k, err; ··· 183 207 mt76x02_mac_shared_key_setup(dev, i, k, NULL); 184 208 } 185 209 186 - mt76_clear(dev, MT_BEACON_TIME_CFG, 187 - MT_BEACON_TIME_CFG_TIMER_EN | 188 - MT_BEACON_TIME_CFG_SYNC_MODE | 189 - MT_BEACON_TIME_CFG_TBTT_EN | 190 - MT_BEACON_TIME_CFG_BEACON_TX); 210 + mt76x02_init_beacon_config(dev); 191 211 192 212 mt76_rmw(dev, MT_US_CYC_CFG, MT_US_CYC_CNT, 0x1e); 193 213 mt76_wr(dev, MT_TXOP_CTRL_CFG, 0x583f); ··· 228 256 goto fail; 229 257 230 258 /* check hw sg support in order to enable AMSDU */ 231 - if (mt76u_check_sg(&dev->mt76)) 259 + if (dev->mt76.usb.sg_en) 232 260 hw->max_tx_fragments = MT_SG_MAX_SIZE; 233 261 else 234 262 hw->max_tx_fragments = 1;
+2 -15
drivers/net/wireless/mediatek/mt76/mt76x2/usb_main.c
··· 28 28 goto out; 29 29 30 30 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mac_work, 31 - MT_CALIBRATE_INTERVAL); 31 + MT_MAC_WORK_INTERVAL); 32 32 set_bit(MT76_STATE_RUNNING, &dev->mt76.state); 33 33 34 34 out: ··· 44 44 clear_bit(MT76_STATE_RUNNING, &dev->mt76.state); 45 45 mt76x2u_stop_hw(dev); 46 46 mutex_unlock(&dev->mt76.mutex); 47 - } 48 - 49 - static int mt76x2u_add_interface(struct ieee80211_hw *hw, 50 - struct ieee80211_vif *vif) 51 - { 52 - struct mt76x02_dev *dev = hw->priv; 53 - unsigned int idx = 8; 54 - 55 - if (!ether_addr_equal(dev->mt76.macaddr, vif->addr)) 56 - mt76x02_mac_setaddr(dev, vif->addr); 57 - 58 - mt76x02_vif_init(dev, vif, idx); 59 - return 0; 60 47 } 61 48 62 49 static int ··· 112 125 .tx = mt76x02_tx, 113 126 .start = mt76x2u_start, 114 127 .stop = mt76x2u_stop, 115 - .add_interface = mt76x2u_add_interface, 128 + .add_interface = mt76x02_add_interface, 116 129 .remove_interface = mt76x02_remove_interface, 117 130 .sta_state = mt76_sta_state, 118 131 .set_key = mt76x02_set_key,
+1 -4
drivers/net/wireless/mediatek/mt76/tx.c
··· 205 205 { 206 206 struct sk_buff *skb, *tmp; 207 207 208 - if (pktid == MT_PACKET_ID_NO_ACK) 209 - return NULL; 210 - 211 208 skb_queue_walk_safe(&dev->status_list, skb, tmp) { 212 209 struct mt76_tx_cb *cb = mt76_tx_skb_cb(skb); 213 210 ··· 214 217 if (cb->pktid == pktid) 215 218 return skb; 216 219 217 - if (!pktid && 220 + if (pktid >= 0 && 218 221 !time_after(jiffies, cb->jiffies + MT_TX_STATUS_SKB_TIMEOUT)) 219 222 continue; 220 223
+111 -51
drivers/net/wireless/mediatek/mt76/usb.c
··· 22 22 #define MT_VEND_REQ_MAX_RETRY 10 23 23 #define MT_VEND_REQ_TOUT_MS 300 24 24 25 + static bool disable_usb_sg; 26 + module_param_named(disable_usb_sg, disable_usb_sg, bool, 0644); 27 + MODULE_PARM_DESC(disable_usb_sg, "Disable usb scatter-gather support"); 28 + 25 29 /* should be called with usb_ctrl_mtx locked */ 26 30 static int __mt76u_vendor_request(struct mt76_dev *dev, u8 req, 27 31 u8 req_type, u16 val, u16 offset, ··· 245 241 return mt76u_req_rd_rp(dev, base, data, n); 246 242 } 247 243 244 + static bool mt76u_check_sg(struct mt76_dev *dev) 245 + { 246 + struct usb_interface *intf = to_usb_interface(dev->dev); 247 + struct usb_device *udev = interface_to_usbdev(intf); 248 + 249 + return (!disable_usb_sg && udev->bus->sg_tablesize > 0 && 250 + (udev->bus->no_sg_constraint || 251 + udev->speed == USB_SPEED_WIRELESS)); 252 + } 253 + 248 254 static int 249 255 mt76u_set_endpoints(struct usb_interface *intf, 250 256 struct mt76_usb *usb) ··· 323 309 return i ? : -ENOMEM; 324 310 } 325 311 326 - int mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf, 327 - int nsgs, int len, int sglen, gfp_t gfp) 312 + static int 313 + mt76u_buf_alloc_sg(struct mt76_dev *dev, struct mt76u_buf *buf, 314 + int nsgs, int len, int sglen, gfp_t gfp) 328 315 { 329 316 buf->urb = usb_alloc_urb(0, gfp); 330 317 if (!buf->urb) ··· 341 326 342 327 return mt76u_fill_rx_sg(dev, buf, nsgs, len, sglen); 343 328 } 344 - EXPORT_SYMBOL_GPL(mt76u_buf_alloc); 329 + 330 + int mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf, 331 + int len, int data_len, gfp_t gfp) 332 + { 333 + struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN]; 334 + 335 + buf->urb = usb_alloc_urb(0, gfp); 336 + if (!buf->urb) 337 + return -ENOMEM; 338 + 339 + buf->buf = page_frag_alloc(&q->rx_page, len, gfp); 340 + if (!buf->buf) 341 + return -ENOMEM; 342 + 343 + buf->len = data_len; 344 + buf->dev = dev; 345 + 346 + return 0; 347 + } 345 348 346 349 void mt76u_buf_free(struct mt76u_buf *buf) 347 350 { 348 351 struct urb *urb = buf->urb; 352 + struct scatterlist *sg; 349 353 int i; 350 354 351 - for (i = 0; i < urb->num_sgs; i++) 352 - skb_free_frag(sg_virt(&urb->sg[i])); 355 + for (i = 0; i < urb->num_sgs; i++) { 356 + sg = &urb->sg[i]; 357 + if (!sg) 358 + continue; 359 + 360 + skb_free_frag(sg_virt(sg)); 361 + } 362 + if (buf->buf) 363 + skb_free_frag(buf->buf); 364 + 353 365 usb_free_urb(buf->urb); 354 366 } 355 367 EXPORT_SYMBOL_GPL(mt76u_buf_free); ··· 387 345 { 388 346 struct usb_interface *intf = to_usb_interface(dev->dev); 389 347 struct usb_device *udev = interface_to_usbdev(intf); 348 + u8 *data = buf->urb->num_sgs ? NULL : buf->buf; 390 349 unsigned int pipe; 391 350 392 351 if (dir == USB_DIR_IN) ··· 395 352 else 396 353 pipe = usb_sndbulkpipe(udev, dev->usb.out_ep[index]); 397 354 398 - usb_fill_bulk_urb(buf->urb, udev, pipe, NULL, buf->len, 355 + usb_fill_bulk_urb(buf->urb, udev, pipe, data, buf->len, 399 356 complete_fn, context); 400 357 trace_submit_urb(dev, buf->urb); 401 358 ··· 436 393 } 437 394 438 395 static int 439 - mt76u_process_rx_entry(struct mt76_dev *dev, struct urb *urb) 396 + mt76u_process_rx_entry(struct mt76_dev *dev, struct mt76u_buf *buf) 440 397 { 441 398 struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN]; 442 - u8 *data = sg_virt(&urb->sg[0]); 399 + struct urb *urb = buf->urb; 400 + u8 *data = urb->num_sgs ? sg_virt(&urb->sg[0]) : buf->buf; 443 401 int data_len, len, nsgs = 1; 444 402 struct sk_buff *skb; 445 403 ··· 451 407 if (len < 0) 452 408 return 0; 453 409 454 - data_len = min_t(int, len, urb->sg[0].length - MT_DMA_HDR_LEN); 410 + data_len = urb->num_sgs ? urb->sg[0].length : buf->len; 411 + data_len = min_t(int, len, data_len - MT_DMA_HDR_LEN); 455 412 if (MT_DMA_HDR_LEN + data_len > SKB_WITH_OVERHEAD(q->buf_size)) 456 413 return 0; 457 414 ··· 464 419 __skb_put(skb, data_len); 465 420 len -= data_len; 466 421 467 - while (len > 0) { 422 + while (len > 0 && urb->num_sgs) { 468 423 data_len = min_t(int, len, urb->sg[nsgs].length); 469 424 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, 470 425 sg_page(&urb->sg[nsgs]), ··· 492 447 case -ENOENT: 493 448 return; 494 449 default: 495 - dev_err(dev->dev, "rx urb failed: %d\n", urb->status); 450 + dev_err_ratelimited(dev->dev, "rx urb failed: %d\n", 451 + urb->status); 496 452 /* fall through */ 497 453 case 0: 498 454 break; ··· 510 464 spin_unlock_irqrestore(&q->lock, flags); 511 465 } 512 466 467 + static int 468 + mt76u_refill_rx(struct mt76_dev *dev, struct mt76_queue *q, 469 + struct mt76u_buf *buf, int nsgs) 470 + { 471 + if (dev->usb.sg_en) { 472 + return mt76u_fill_rx_sg(dev, buf, nsgs, q->buf_size, 473 + SKB_WITH_OVERHEAD(q->buf_size)); 474 + } else { 475 + buf->buf = page_frag_alloc(&q->rx_page, q->buf_size, 476 + GFP_ATOMIC); 477 + return buf->buf ? 0 : -ENOMEM; 478 + } 479 + } 480 + 513 481 static void mt76u_rx_tasklet(unsigned long data) 514 482 { 515 483 struct mt76_dev *dev = (struct mt76_dev *)data; 516 484 struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN]; 517 - int err, nsgs, buf_len = q->buf_size; 518 485 struct mt76u_buf *buf; 486 + int err, count; 519 487 520 488 rcu_read_lock(); 521 489 ··· 538 478 if (!buf) 539 479 break; 540 480 541 - nsgs = mt76u_process_rx_entry(dev, buf->urb); 542 - if (nsgs > 0) { 543 - err = mt76u_fill_rx_sg(dev, buf, nsgs, 544 - buf_len, 545 - SKB_WITH_OVERHEAD(buf_len)); 481 + count = mt76u_process_rx_entry(dev, buf); 482 + if (count > 0) { 483 + err = mt76u_refill_rx(dev, q, buf, count); 546 484 if (err < 0) 547 485 break; 548 486 } ··· 578 520 static int mt76u_alloc_rx(struct mt76_dev *dev) 579 521 { 580 522 struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN]; 581 - int i, err, nsgs; 523 + int i, err; 582 524 583 525 spin_lock_init(&q->rx_page_lock); 584 526 spin_lock_init(&q->lock); ··· 588 530 if (!q->entry) 589 531 return -ENOMEM; 590 532 591 - if (mt76u_check_sg(dev)) { 592 - q->buf_size = MT_RX_BUF_SIZE; 593 - nsgs = MT_SG_MAX_SIZE; 594 - } else { 595 - q->buf_size = PAGE_SIZE; 596 - nsgs = 1; 597 - } 598 - 599 - for (i = 0; i < MT_NUM_RX_ENTRIES; i++) { 600 - err = mt76u_buf_alloc(dev, &q->entry[i].ubuf, 601 - nsgs, q->buf_size, 602 - SKB_WITH_OVERHEAD(q->buf_size), 603 - GFP_KERNEL); 533 + q->buf_size = dev->usb.sg_en ? MT_RX_BUF_SIZE : PAGE_SIZE; 534 + q->ndesc = MT_NUM_RX_ENTRIES; 535 + for (i = 0; i < q->ndesc; i++) { 536 + if (dev->usb.sg_en) 537 + err = mt76u_buf_alloc_sg(dev, &q->entry[i].ubuf, 538 + MT_SG_MAX_SIZE, q->buf_size, 539 + SKB_WITH_OVERHEAD(q->buf_size), 540 + GFP_KERNEL); 541 + else 542 + err = mt76u_buf_alloc(dev, &q->entry[i].ubuf, 543 + q->buf_size, 544 + SKB_WITH_OVERHEAD(q->buf_size), 545 + GFP_KERNEL); 604 546 if (err < 0) 605 547 return err; 606 548 } 607 - q->ndesc = MT_NUM_RX_ENTRIES; 608 549 609 550 return mt76u_submit_rx_buffers(dev); 610 551 } ··· 748 691 { 749 692 struct usb_interface *intf = to_usb_interface(dev->dev); 750 693 struct usb_device *udev = interface_to_usbdev(intf); 751 - u8 ep = q2ep(q->hw_idx); 694 + u8 *data = NULL, ep = q2ep(q->hw_idx); 752 695 struct mt76u_buf *buf; 753 696 u16 idx = q->tail; 754 697 unsigned int pipe; ··· 765 708 buf = &q->entry[idx].ubuf; 766 709 buf->done = false; 767 710 768 - err = mt76u_tx_build_sg(skb, buf->urb); 769 - if (err < 0) 770 - return err; 711 + if (dev->usb.sg_en) { 712 + err = mt76u_tx_build_sg(skb, buf->urb); 713 + if (err < 0) 714 + return err; 715 + } else { 716 + data = skb->data; 717 + } 771 718 772 719 pipe = usb_sndbulkpipe(udev, dev->usb.out_ep[ep]); 773 - usb_fill_bulk_urb(buf->urb, udev, pipe, NULL, skb->len, 720 + usb_fill_bulk_urb(buf->urb, udev, pipe, data, skb->len, 774 721 mt76u_complete_tx, buf); 775 722 776 723 q->tail = (q->tail + 1) % q->ndesc; ··· 810 749 { 811 750 struct mt76u_buf *buf; 812 751 struct mt76_queue *q; 813 - size_t size; 814 752 int i, j; 815 753 816 - size = MT_SG_MAX_SIZE * sizeof(struct scatterlist); 817 754 for (i = 0; i < IEEE80211_NUM_ACS; i++) { 818 755 q = &dev->q_tx[i]; 819 756 spin_lock_init(&q->lock); ··· 833 774 if (!buf->urb) 834 775 return -ENOMEM; 835 776 836 - buf->urb->sg = devm_kzalloc(dev->dev, size, GFP_KERNEL); 837 - if (!buf->urb->sg) 838 - return -ENOMEM; 777 + if (dev->usb.sg_en) { 778 + size_t size = MT_SG_MAX_SIZE * 779 + sizeof(struct scatterlist); 780 + 781 + buf->urb->sg = devm_kzalloc(dev->dev, size, 782 + GFP_KERNEL); 783 + if (!buf->urb->sg) 784 + return -ENOMEM; 785 + } 839 786 } 840 787 } 841 788 return 0; ··· 903 838 904 839 err = mt76u_alloc_rx(dev); 905 840 if (err < 0) 906 - goto err; 841 + return err; 907 842 908 - err = mt76u_alloc_tx(dev); 909 - if (err < 0) 910 - goto err; 911 - 912 - return 0; 913 - err: 914 - mt76u_queues_deinit(dev); 915 - return err; 843 + return mt76u_alloc_tx(dev); 916 844 } 917 845 EXPORT_SYMBOL_GPL(mt76u_alloc_queues); 918 846 ··· 939 881 mutex_init(&usb->usb_ctrl_mtx); 940 882 dev->bus = &mt76u_ops; 941 883 dev->queue_ops = &usb_queue_ops; 884 + 885 + usb->sg_en = mt76u_check_sg(dev); 942 886 943 887 return mt76u_set_endpoints(intf, usb); 944 888 }
+7 -6
drivers/net/wireless/mediatek/mt76/usb_mcu.c
··· 29 29 struct mt76_usb *usb = &dev->usb; 30 30 int err; 31 31 32 - err = mt76u_buf_alloc(dev, &usb->mcu.res, 1, 33 - MCU_RESP_URB_SIZE, MCU_RESP_URB_SIZE, 34 - GFP_KERNEL); 32 + err = mt76u_buf_alloc(dev, &usb->mcu.res, MCU_RESP_URB_SIZE, 33 + MCU_RESP_URB_SIZE, GFP_KERNEL); 35 34 if (err < 0) 36 35 return err; 37 36 ··· 47 48 48 49 void mt76u_mcu_deinit(struct mt76_dev *dev) 49 50 { 50 - struct mt76_usb *usb = &dev->usb; 51 + struct mt76u_buf *buf = &dev->usb.mcu.res; 51 52 52 - usb_kill_urb(usb->mcu.res.urb); 53 - mt76u_buf_free(&usb->mcu.res); 53 + if (buf->urb) { 54 + usb_kill_urb(buf->urb); 55 + mt76u_buf_free(buf); 56 + } 54 57 } 55 58 EXPORT_SYMBOL_GPL(mt76u_mcu_deinit);