168d57a07SSrinivasan Raju // SPDX-License-Identifier: GPL-2.0-only
268d57a07SSrinivasan Raju /*
368d57a07SSrinivasan Raju * Copyright (c) 2021 pureLiFi
468d57a07SSrinivasan Raju */
568d57a07SSrinivasan Raju
668d57a07SSrinivasan Raju #include <linux/netdevice.h>
768d57a07SSrinivasan Raju #include <linux/etherdevice.h>
868d57a07SSrinivasan Raju #include <linux/slab.h>
968d57a07SSrinivasan Raju #include <linux/usb.h>
1068d57a07SSrinivasan Raju #include <linux/gpio.h>
1168d57a07SSrinivasan Raju #include <linux/jiffies.h>
1268d57a07SSrinivasan Raju #include <net/ieee80211_radiotap.h>
1368d57a07SSrinivasan Raju
1468d57a07SSrinivasan Raju #include "chip.h"
1568d57a07SSrinivasan Raju #include "mac.h"
1668d57a07SSrinivasan Raju #include "usb.h"
1768d57a07SSrinivasan Raju
1868d57a07SSrinivasan Raju static const struct ieee80211_rate plfxlc_rates[] = {
1968d57a07SSrinivasan Raju { .bitrate = 10,
2068d57a07SSrinivasan Raju .hw_value = PURELIFI_CCK_RATE_1M,
2168d57a07SSrinivasan Raju .flags = 0 },
2268d57a07SSrinivasan Raju { .bitrate = 20,
2368d57a07SSrinivasan Raju .hw_value = PURELIFI_CCK_RATE_2M,
2468d57a07SSrinivasan Raju .hw_value_short = PURELIFI_CCK_RATE_2M
2568d57a07SSrinivasan Raju | PURELIFI_CCK_PREA_SHORT,
2668d57a07SSrinivasan Raju .flags = IEEE80211_RATE_SHORT_PREAMBLE },
2768d57a07SSrinivasan Raju { .bitrate = 55,
2868d57a07SSrinivasan Raju .hw_value = PURELIFI_CCK_RATE_5_5M,
2968d57a07SSrinivasan Raju .hw_value_short = PURELIFI_CCK_RATE_5_5M
3068d57a07SSrinivasan Raju | PURELIFI_CCK_PREA_SHORT,
3168d57a07SSrinivasan Raju .flags = IEEE80211_RATE_SHORT_PREAMBLE },
3268d57a07SSrinivasan Raju { .bitrate = 110,
3368d57a07SSrinivasan Raju .hw_value = PURELIFI_CCK_RATE_11M,
3468d57a07SSrinivasan Raju .hw_value_short = PURELIFI_CCK_RATE_11M
3568d57a07SSrinivasan Raju | PURELIFI_CCK_PREA_SHORT,
3668d57a07SSrinivasan Raju .flags = IEEE80211_RATE_SHORT_PREAMBLE },
3768d57a07SSrinivasan Raju { .bitrate = 60,
3868d57a07SSrinivasan Raju .hw_value = PURELIFI_OFDM_RATE_6M,
3968d57a07SSrinivasan Raju .flags = 0 },
4068d57a07SSrinivasan Raju { .bitrate = 90,
4168d57a07SSrinivasan Raju .hw_value = PURELIFI_OFDM_RATE_9M,
4268d57a07SSrinivasan Raju .flags = 0 },
4368d57a07SSrinivasan Raju { .bitrate = 120,
4468d57a07SSrinivasan Raju .hw_value = PURELIFI_OFDM_RATE_12M,
4568d57a07SSrinivasan Raju .flags = 0 },
4668d57a07SSrinivasan Raju { .bitrate = 180,
4768d57a07SSrinivasan Raju .hw_value = PURELIFI_OFDM_RATE_18M,
4868d57a07SSrinivasan Raju .flags = 0 },
4968d57a07SSrinivasan Raju { .bitrate = 240,
5068d57a07SSrinivasan Raju .hw_value = PURELIFI_OFDM_RATE_24M,
5168d57a07SSrinivasan Raju .flags = 0 },
5268d57a07SSrinivasan Raju { .bitrate = 360,
5368d57a07SSrinivasan Raju .hw_value = PURELIFI_OFDM_RATE_36M,
5468d57a07SSrinivasan Raju .flags = 0 },
5568d57a07SSrinivasan Raju { .bitrate = 480,
5668d57a07SSrinivasan Raju .hw_value = PURELIFI_OFDM_RATE_48M,
5768d57a07SSrinivasan Raju .flags = 0 },
5868d57a07SSrinivasan Raju { .bitrate = 540,
5968d57a07SSrinivasan Raju .hw_value = PURELIFI_OFDM_RATE_54M,
6068d57a07SSrinivasan Raju .flags = 0 }
6168d57a07SSrinivasan Raju };
6268d57a07SSrinivasan Raju
6368d57a07SSrinivasan Raju static const struct ieee80211_channel plfxlc_channels[] = {
6468d57a07SSrinivasan Raju { .center_freq = 2412, .hw_value = 1 },
6568d57a07SSrinivasan Raju { .center_freq = 2417, .hw_value = 2 },
6668d57a07SSrinivasan Raju { .center_freq = 2422, .hw_value = 3 },
6768d57a07SSrinivasan Raju { .center_freq = 2427, .hw_value = 4 },
6868d57a07SSrinivasan Raju { .center_freq = 2432, .hw_value = 5 },
6968d57a07SSrinivasan Raju { .center_freq = 2437, .hw_value = 6 },
7068d57a07SSrinivasan Raju { .center_freq = 2442, .hw_value = 7 },
7168d57a07SSrinivasan Raju { .center_freq = 2447, .hw_value = 8 },
7268d57a07SSrinivasan Raju { .center_freq = 2452, .hw_value = 9 },
7368d57a07SSrinivasan Raju { .center_freq = 2457, .hw_value = 10 },
7468d57a07SSrinivasan Raju { .center_freq = 2462, .hw_value = 11 },
7568d57a07SSrinivasan Raju { .center_freq = 2467, .hw_value = 12 },
7668d57a07SSrinivasan Raju { .center_freq = 2472, .hw_value = 13 },
7768d57a07SSrinivasan Raju { .center_freq = 2484, .hw_value = 14 },
7868d57a07SSrinivasan Raju };
7968d57a07SSrinivasan Raju
plfxlc_mac_preinit_hw(struct ieee80211_hw * hw,const u8 * hw_address)8068d57a07SSrinivasan Raju int plfxlc_mac_preinit_hw(struct ieee80211_hw *hw, const u8 *hw_address)
8168d57a07SSrinivasan Raju {
8268d57a07SSrinivasan Raju SET_IEEE80211_PERM_ADDR(hw, hw_address);
8368d57a07SSrinivasan Raju return 0;
8468d57a07SSrinivasan Raju }
8568d57a07SSrinivasan Raju
plfxlc_mac_init_hw(struct ieee80211_hw * hw)8668d57a07SSrinivasan Raju int plfxlc_mac_init_hw(struct ieee80211_hw *hw)
8768d57a07SSrinivasan Raju {
8868d57a07SSrinivasan Raju struct plfxlc_mac *mac = plfxlc_hw_mac(hw);
8968d57a07SSrinivasan Raju struct plfxlc_chip *chip = &mac->chip;
9068d57a07SSrinivasan Raju int r;
9168d57a07SSrinivasan Raju
9268d57a07SSrinivasan Raju r = plfxlc_chip_init_hw(chip);
9368d57a07SSrinivasan Raju if (r) {
9468d57a07SSrinivasan Raju dev_warn(plfxlc_mac_dev(mac), "init hw failed (%d)\n", r);
9568d57a07SSrinivasan Raju return r;
9668d57a07SSrinivasan Raju }
9768d57a07SSrinivasan Raju
9868d57a07SSrinivasan Raju dev_dbg(plfxlc_mac_dev(mac), "irq_disabled (%d)\n", irqs_disabled());
9968d57a07SSrinivasan Raju regulatory_hint(hw->wiphy, "00");
10068d57a07SSrinivasan Raju return r;
10168d57a07SSrinivasan Raju }
10268d57a07SSrinivasan Raju
plfxlc_mac_release(struct plfxlc_mac * mac)10368d57a07SSrinivasan Raju void plfxlc_mac_release(struct plfxlc_mac *mac)
10468d57a07SSrinivasan Raju {
10568d57a07SSrinivasan Raju plfxlc_chip_release(&mac->chip);
10668d57a07SSrinivasan Raju lockdep_assert_held(&mac->lock);
10768d57a07SSrinivasan Raju }
10868d57a07SSrinivasan Raju
plfxlc_op_start(struct ieee80211_hw * hw)10968d57a07SSrinivasan Raju int plfxlc_op_start(struct ieee80211_hw *hw)
11068d57a07SSrinivasan Raju {
11168d57a07SSrinivasan Raju plfxlc_hw_mac(hw)->chip.usb.initialized = 1;
11268d57a07SSrinivasan Raju return 0;
11368d57a07SSrinivasan Raju }
11468d57a07SSrinivasan Raju
plfxlc_op_stop(struct ieee80211_hw * hw)11568d57a07SSrinivasan Raju void plfxlc_op_stop(struct ieee80211_hw *hw)
11668d57a07SSrinivasan Raju {
11768d57a07SSrinivasan Raju struct plfxlc_mac *mac = plfxlc_hw_mac(hw);
11868d57a07SSrinivasan Raju
11968d57a07SSrinivasan Raju clear_bit(PURELIFI_DEVICE_RUNNING, &mac->flags);
12068d57a07SSrinivasan Raju }
12168d57a07SSrinivasan Raju
plfxlc_restore_settings(struct plfxlc_mac * mac)12268d57a07SSrinivasan Raju int plfxlc_restore_settings(struct plfxlc_mac *mac)
12368d57a07SSrinivasan Raju {
12468d57a07SSrinivasan Raju int beacon_interval, beacon_period;
12568d57a07SSrinivasan Raju struct sk_buff *beacon;
12668d57a07SSrinivasan Raju
12768d57a07SSrinivasan Raju spin_lock_irq(&mac->lock);
12868d57a07SSrinivasan Raju beacon_interval = mac->beacon.interval;
12968d57a07SSrinivasan Raju beacon_period = mac->beacon.period;
13068d57a07SSrinivasan Raju spin_unlock_irq(&mac->lock);
13168d57a07SSrinivasan Raju
13268d57a07SSrinivasan Raju if (mac->type != NL80211_IFTYPE_ADHOC)
13368d57a07SSrinivasan Raju return 0;
13468d57a07SSrinivasan Raju
13568d57a07SSrinivasan Raju if (mac->vif) {
1366e8912a5SShaul Triebitz beacon = ieee80211_beacon_get(mac->hw, mac->vif, 0);
13768d57a07SSrinivasan Raju if (beacon) {
13868d57a07SSrinivasan Raju /*beacon is hardcoded in firmware */
13968d57a07SSrinivasan Raju kfree_skb(beacon);
14068d57a07SSrinivasan Raju /* Returned skb is used only once and lowlevel
14168d57a07SSrinivasan Raju * driver is responsible for freeing it.
14268d57a07SSrinivasan Raju */
14368d57a07SSrinivasan Raju }
14468d57a07SSrinivasan Raju }
14568d57a07SSrinivasan Raju
14668d57a07SSrinivasan Raju plfxlc_set_beacon_interval(&mac->chip, beacon_interval,
14768d57a07SSrinivasan Raju beacon_period, mac->type);
14868d57a07SSrinivasan Raju
14968d57a07SSrinivasan Raju spin_lock_irq(&mac->lock);
15068d57a07SSrinivasan Raju mac->beacon.last_update = jiffies;
15168d57a07SSrinivasan Raju spin_unlock_irq(&mac->lock);
15268d57a07SSrinivasan Raju
15368d57a07SSrinivasan Raju return 0;
15468d57a07SSrinivasan Raju }
15568d57a07SSrinivasan Raju
plfxlc_mac_tx_status(struct ieee80211_hw * hw,struct sk_buff * skb,int ackssi,struct tx_status * tx_status)15668d57a07SSrinivasan Raju static void plfxlc_mac_tx_status(struct ieee80211_hw *hw,
15768d57a07SSrinivasan Raju struct sk_buff *skb,
15868d57a07SSrinivasan Raju int ackssi,
15968d57a07SSrinivasan Raju struct tx_status *tx_status)
16068d57a07SSrinivasan Raju {
16168d57a07SSrinivasan Raju struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
16268d57a07SSrinivasan Raju int success = 1;
16368d57a07SSrinivasan Raju
16468d57a07SSrinivasan Raju ieee80211_tx_info_clear_status(info);
16568d57a07SSrinivasan Raju if (tx_status)
16668d57a07SSrinivasan Raju success = !tx_status->failure;
16768d57a07SSrinivasan Raju
16868d57a07SSrinivasan Raju if (success)
16968d57a07SSrinivasan Raju info->flags |= IEEE80211_TX_STAT_ACK;
17068d57a07SSrinivasan Raju else
17168d57a07SSrinivasan Raju info->flags &= ~IEEE80211_TX_STAT_ACK;
17268d57a07SSrinivasan Raju
17368d57a07SSrinivasan Raju info->status.ack_signal = 50;
17468d57a07SSrinivasan Raju ieee80211_tx_status_irqsafe(hw, skb);
17568d57a07SSrinivasan Raju }
17668d57a07SSrinivasan Raju
plfxlc_mac_tx_to_dev(struct sk_buff * skb,int error)17768d57a07SSrinivasan Raju void plfxlc_mac_tx_to_dev(struct sk_buff *skb, int error)
17868d57a07SSrinivasan Raju {
17968d57a07SSrinivasan Raju struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
18068d57a07SSrinivasan Raju struct ieee80211_hw *hw = info->rate_driver_data[0];
18168d57a07SSrinivasan Raju struct plfxlc_mac *mac = plfxlc_hw_mac(hw);
18268d57a07SSrinivasan Raju struct sk_buff_head *q = NULL;
18368d57a07SSrinivasan Raju
18468d57a07SSrinivasan Raju ieee80211_tx_info_clear_status(info);
18568d57a07SSrinivasan Raju skb_pull(skb, sizeof(struct plfxlc_ctrlset));
18668d57a07SSrinivasan Raju
18768d57a07SSrinivasan Raju if (unlikely(error ||
18868d57a07SSrinivasan Raju (info->flags & IEEE80211_TX_CTL_NO_ACK))) {
18968d57a07SSrinivasan Raju ieee80211_tx_status_irqsafe(hw, skb);
19068d57a07SSrinivasan Raju return;
19168d57a07SSrinivasan Raju }
19268d57a07SSrinivasan Raju
19368d57a07SSrinivasan Raju q = &mac->ack_wait_queue;
19468d57a07SSrinivasan Raju
19568d57a07SSrinivasan Raju skb_queue_tail(q, skb);
19668d57a07SSrinivasan Raju while (skb_queue_len(q)/* > PURELIFI_MAC_MAX_ACK_WAITERS*/) {
19768d57a07SSrinivasan Raju plfxlc_mac_tx_status(hw, skb_dequeue(q),
19868d57a07SSrinivasan Raju mac->ack_pending ?
19968d57a07SSrinivasan Raju mac->ack_signal : 0,
20068d57a07SSrinivasan Raju NULL);
20168d57a07SSrinivasan Raju mac->ack_pending = 0;
20268d57a07SSrinivasan Raju }
20368d57a07SSrinivasan Raju }
20468d57a07SSrinivasan Raju
plfxlc_fill_ctrlset(struct plfxlc_mac * mac,struct sk_buff * skb)20568d57a07SSrinivasan Raju static int plfxlc_fill_ctrlset(struct plfxlc_mac *mac, struct sk_buff *skb)
20668d57a07SSrinivasan Raju {
20768d57a07SSrinivasan Raju unsigned int frag_len = skb->len;
20868d57a07SSrinivasan Raju struct plfxlc_ctrlset *cs;
20968d57a07SSrinivasan Raju u32 temp_payload_len = 0;
21068d57a07SSrinivasan Raju unsigned int tmp;
21168d57a07SSrinivasan Raju u32 temp_len = 0;
21268d57a07SSrinivasan Raju
21368d57a07SSrinivasan Raju if (skb_headroom(skb) < sizeof(struct plfxlc_ctrlset)) {
21468d57a07SSrinivasan Raju dev_dbg(plfxlc_mac_dev(mac), "Not enough hroom(1)\n");
21568d57a07SSrinivasan Raju return 1;
21668d57a07SSrinivasan Raju }
21768d57a07SSrinivasan Raju
21868d57a07SSrinivasan Raju cs = (void *)skb_push(skb, sizeof(struct plfxlc_ctrlset));
21968d57a07SSrinivasan Raju temp_payload_len = frag_len;
22068d57a07SSrinivasan Raju temp_len = temp_payload_len +
22168d57a07SSrinivasan Raju sizeof(struct plfxlc_ctrlset) -
22268d57a07SSrinivasan Raju sizeof(cs->id) - sizeof(cs->len);
22368d57a07SSrinivasan Raju
22468d57a07SSrinivasan Raju /* Data packet lengths must be multiple of four bytes and must
22568d57a07SSrinivasan Raju * not be a multiple of 512 bytes. First, it is attempted to
22668d57a07SSrinivasan Raju * append the data packet in the tailroom of the skb. In rare
22768d57a07SSrinivasan Raju * occasions, the tailroom is too small. In this case, the
22868d57a07SSrinivasan Raju * content of the packet is shifted into the headroom of the skb
22968d57a07SSrinivasan Raju * by memcpy. Headroom is allocated at startup (below in this
23068d57a07SSrinivasan Raju * file). Therefore, there will be always enough headroom. The
23168d57a07SSrinivasan Raju * call skb_headroom is an additional safety which might be
23268d57a07SSrinivasan Raju * dropped.
23368d57a07SSrinivasan Raju */
23468d57a07SSrinivasan Raju /* check if 32 bit aligned and align data */
23568d57a07SSrinivasan Raju tmp = skb->len & 3;
23668d57a07SSrinivasan Raju if (tmp) {
23768d57a07SSrinivasan Raju if (skb_tailroom(skb) < (3 - tmp)) {
23868d57a07SSrinivasan Raju if (skb_headroom(skb) >= 4 - tmp) {
23968d57a07SSrinivasan Raju u8 len;
24068d57a07SSrinivasan Raju u8 *src_pt;
24168d57a07SSrinivasan Raju u8 *dest_pt;
24268d57a07SSrinivasan Raju
24368d57a07SSrinivasan Raju len = skb->len;
24468d57a07SSrinivasan Raju src_pt = skb->data;
24568d57a07SSrinivasan Raju dest_pt = skb_push(skb, 4 - tmp);
24668d57a07SSrinivasan Raju memmove(dest_pt, src_pt, len);
24768d57a07SSrinivasan Raju } else {
24868d57a07SSrinivasan Raju return -ENOBUFS;
24968d57a07SSrinivasan Raju }
25068d57a07SSrinivasan Raju } else {
25168d57a07SSrinivasan Raju skb_put(skb, 4 - tmp);
25268d57a07SSrinivasan Raju }
25368d57a07SSrinivasan Raju temp_len += 4 - tmp;
25468d57a07SSrinivasan Raju }
25568d57a07SSrinivasan Raju
25668d57a07SSrinivasan Raju /* check if not multiple of 512 and align data */
25768d57a07SSrinivasan Raju tmp = skb->len & 0x1ff;
25868d57a07SSrinivasan Raju if (!tmp) {
25968d57a07SSrinivasan Raju if (skb_tailroom(skb) < 4) {
26068d57a07SSrinivasan Raju if (skb_headroom(skb) >= 4) {
26168d57a07SSrinivasan Raju u8 len = skb->len;
26268d57a07SSrinivasan Raju u8 *src_pt = skb->data;
26368d57a07SSrinivasan Raju u8 *dest_pt = skb_push(skb, 4);
26468d57a07SSrinivasan Raju
26568d57a07SSrinivasan Raju memmove(dest_pt, src_pt, len);
26668d57a07SSrinivasan Raju } else {
26768d57a07SSrinivasan Raju /* should never happen because
26868d57a07SSrinivasan Raju * sufficient headroom was reserved
26968d57a07SSrinivasan Raju */
27068d57a07SSrinivasan Raju return -ENOBUFS;
27168d57a07SSrinivasan Raju }
27268d57a07SSrinivasan Raju } else {
27368d57a07SSrinivasan Raju skb_put(skb, 4);
27468d57a07SSrinivasan Raju }
27568d57a07SSrinivasan Raju temp_len += 4;
27668d57a07SSrinivasan Raju }
27768d57a07SSrinivasan Raju
27868d57a07SSrinivasan Raju cs->id = cpu_to_be32(USB_REQ_DATA_TX);
27968d57a07SSrinivasan Raju cs->len = cpu_to_be32(temp_len);
28068d57a07SSrinivasan Raju cs->payload_len_nw = cpu_to_be32(temp_payload_len);
28168d57a07SSrinivasan Raju
28268d57a07SSrinivasan Raju return 0;
28368d57a07SSrinivasan Raju }
28468d57a07SSrinivasan Raju
plfxlc_op_tx(struct ieee80211_hw * hw,struct ieee80211_tx_control * control,struct sk_buff * skb)28568d57a07SSrinivasan Raju static void plfxlc_op_tx(struct ieee80211_hw *hw,
28668d57a07SSrinivasan Raju struct ieee80211_tx_control *control,
28768d57a07SSrinivasan Raju struct sk_buff *skb)
28868d57a07SSrinivasan Raju {
28968d57a07SSrinivasan Raju struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
29068d57a07SSrinivasan Raju struct plfxlc_header *plhdr = (void *)skb->data;
29168d57a07SSrinivasan Raju struct plfxlc_mac *mac = plfxlc_hw_mac(hw);
29268d57a07SSrinivasan Raju struct plfxlc_usb *usb = &mac->chip.usb;
29368d57a07SSrinivasan Raju unsigned long flags;
29468d57a07SSrinivasan Raju int r;
29568d57a07SSrinivasan Raju
29668d57a07SSrinivasan Raju r = plfxlc_fill_ctrlset(mac, skb);
29768d57a07SSrinivasan Raju if (r)
29868d57a07SSrinivasan Raju goto fail;
29968d57a07SSrinivasan Raju
30068d57a07SSrinivasan Raju info->rate_driver_data[0] = hw;
30168d57a07SSrinivasan Raju
30268d57a07SSrinivasan Raju if (plhdr->frametype == IEEE80211_FTYPE_DATA) {
30368d57a07SSrinivasan Raju u8 *dst_mac = plhdr->dmac;
30468d57a07SSrinivasan Raju u8 sidx;
30568d57a07SSrinivasan Raju bool found = false;
30668d57a07SSrinivasan Raju struct plfxlc_usb_tx *tx = &usb->tx;
30768d57a07SSrinivasan Raju
30868d57a07SSrinivasan Raju for (sidx = 0; sidx < MAX_STA_NUM; sidx++) {
30968d57a07SSrinivasan Raju if (!(tx->station[sidx].flag & STATION_CONNECTED_FLAG))
31068d57a07SSrinivasan Raju continue;
31168d57a07SSrinivasan Raju if (memcmp(tx->station[sidx].mac, dst_mac, ETH_ALEN))
31268d57a07SSrinivasan Raju continue;
31368d57a07SSrinivasan Raju found = true;
31468d57a07SSrinivasan Raju break;
31568d57a07SSrinivasan Raju }
31668d57a07SSrinivasan Raju
31768d57a07SSrinivasan Raju /* Default to broadcast address for unknown MACs */
31868d57a07SSrinivasan Raju if (!found)
31968d57a07SSrinivasan Raju sidx = STA_BROADCAST_INDEX;
32068d57a07SSrinivasan Raju
32168d57a07SSrinivasan Raju /* Stop OS from sending packets, if the queue is half full */
32268d57a07SSrinivasan Raju if (skb_queue_len(&tx->station[sidx].data_list) > 60)
32368d57a07SSrinivasan Raju ieee80211_stop_queues(plfxlc_usb_to_hw(usb));
32468d57a07SSrinivasan Raju
32568d57a07SSrinivasan Raju /* Schedule packet for transmission if queue is not full */
32668d57a07SSrinivasan Raju if (skb_queue_len(&tx->station[sidx].data_list) > 256)
32768d57a07SSrinivasan Raju goto fail;
32868d57a07SSrinivasan Raju skb_queue_tail(&tx->station[sidx].data_list, skb);
32968d57a07SSrinivasan Raju plfxlc_send_packet_from_data_queue(usb);
33068d57a07SSrinivasan Raju
33168d57a07SSrinivasan Raju } else {
33268d57a07SSrinivasan Raju spin_lock_irqsave(&usb->tx.lock, flags);
33368d57a07SSrinivasan Raju r = plfxlc_usb_wreq_async(&mac->chip.usb, skb->data, skb->len,
33468d57a07SSrinivasan Raju USB_REQ_DATA_TX, plfxlc_tx_urb_complete, skb);
33568d57a07SSrinivasan Raju spin_unlock_irqrestore(&usb->tx.lock, flags);
33668d57a07SSrinivasan Raju if (r)
33768d57a07SSrinivasan Raju goto fail;
33868d57a07SSrinivasan Raju }
33968d57a07SSrinivasan Raju return;
34068d57a07SSrinivasan Raju
34168d57a07SSrinivasan Raju fail:
34268d57a07SSrinivasan Raju dev_kfree_skb(skb);
34368d57a07SSrinivasan Raju }
34468d57a07SSrinivasan Raju
plfxlc_filter_ack(struct ieee80211_hw * hw,struct ieee80211_hdr * rx_hdr,struct ieee80211_rx_status * stats)34568d57a07SSrinivasan Raju static int plfxlc_filter_ack(struct ieee80211_hw *hw, struct ieee80211_hdr *rx_hdr,
34668d57a07SSrinivasan Raju struct ieee80211_rx_status *stats)
34768d57a07SSrinivasan Raju {
34868d57a07SSrinivasan Raju struct plfxlc_mac *mac = plfxlc_hw_mac(hw);
34968d57a07SSrinivasan Raju struct sk_buff_head *q;
35068d57a07SSrinivasan Raju int i, position = 0;
35168d57a07SSrinivasan Raju unsigned long flags;
35268d57a07SSrinivasan Raju struct sk_buff *skb;
35368d57a07SSrinivasan Raju bool found = false;
35468d57a07SSrinivasan Raju
35568d57a07SSrinivasan Raju if (!ieee80211_is_ack(rx_hdr->frame_control))
35668d57a07SSrinivasan Raju return 0;
35768d57a07SSrinivasan Raju
35868d57a07SSrinivasan Raju dev_dbg(plfxlc_mac_dev(mac), "ACK Received\n");
35968d57a07SSrinivasan Raju
36068d57a07SSrinivasan Raju /* code based on zy driver, this logic may need fix */
36168d57a07SSrinivasan Raju q = &mac->ack_wait_queue;
36268d57a07SSrinivasan Raju spin_lock_irqsave(&q->lock, flags);
36368d57a07SSrinivasan Raju
36468d57a07SSrinivasan Raju skb_queue_walk(q, skb) {
36568d57a07SSrinivasan Raju struct ieee80211_hdr *tx_hdr;
36668d57a07SSrinivasan Raju
36768d57a07SSrinivasan Raju position++;
36868d57a07SSrinivasan Raju
36968d57a07SSrinivasan Raju if (mac->ack_pending && skb_queue_is_first(q, skb))
37068d57a07SSrinivasan Raju continue;
37168d57a07SSrinivasan Raju if (mac->ack_pending == 0)
37268d57a07SSrinivasan Raju break;
37368d57a07SSrinivasan Raju
37468d57a07SSrinivasan Raju tx_hdr = (struct ieee80211_hdr *)skb->data;
37568d57a07SSrinivasan Raju if (likely(ether_addr_equal(tx_hdr->addr2, rx_hdr->addr1))) {
37668d57a07SSrinivasan Raju found = 1;
37768d57a07SSrinivasan Raju break;
37868d57a07SSrinivasan Raju }
37968d57a07SSrinivasan Raju }
38068d57a07SSrinivasan Raju
38168d57a07SSrinivasan Raju if (found) {
38268d57a07SSrinivasan Raju for (i = 1; i < position; i++)
38368d57a07SSrinivasan Raju skb = __skb_dequeue(q);
38468d57a07SSrinivasan Raju if (i == position) {
38568d57a07SSrinivasan Raju plfxlc_mac_tx_status(hw, skb,
38668d57a07SSrinivasan Raju mac->ack_pending ?
38768d57a07SSrinivasan Raju mac->ack_signal : 0,
38868d57a07SSrinivasan Raju NULL);
38968d57a07SSrinivasan Raju mac->ack_pending = 0;
39068d57a07SSrinivasan Raju }
39168d57a07SSrinivasan Raju
39268d57a07SSrinivasan Raju mac->ack_pending = skb_queue_len(q) ? 1 : 0;
39368d57a07SSrinivasan Raju mac->ack_signal = stats->signal;
39468d57a07SSrinivasan Raju }
39568d57a07SSrinivasan Raju
39668d57a07SSrinivasan Raju spin_unlock_irqrestore(&q->lock, flags);
39768d57a07SSrinivasan Raju return 1;
39868d57a07SSrinivasan Raju }
39968d57a07SSrinivasan Raju
plfxlc_mac_rx(struct ieee80211_hw * hw,const u8 * buffer,unsigned int length)40068d57a07SSrinivasan Raju int plfxlc_mac_rx(struct ieee80211_hw *hw, const u8 *buffer,
40168d57a07SSrinivasan Raju unsigned int length)
40268d57a07SSrinivasan Raju {
40368d57a07SSrinivasan Raju struct plfxlc_mac *mac = plfxlc_hw_mac(hw);
40468d57a07SSrinivasan Raju struct ieee80211_rx_status stats;
40568d57a07SSrinivasan Raju const struct rx_status *status;
40668d57a07SSrinivasan Raju unsigned int payload_length;
40768d57a07SSrinivasan Raju struct plfxlc_usb_tx *tx;
40868d57a07SSrinivasan Raju struct sk_buff *skb;
40968d57a07SSrinivasan Raju int need_padding;
41068d57a07SSrinivasan Raju __le16 fc;
41168d57a07SSrinivasan Raju int sidx;
41268d57a07SSrinivasan Raju
41368d57a07SSrinivasan Raju /* Packet blockade during disabled interface. */
41468d57a07SSrinivasan Raju if (!mac->vif)
41568d57a07SSrinivasan Raju return 0;
41668d57a07SSrinivasan Raju
41768d57a07SSrinivasan Raju status = (struct rx_status *)buffer;
41868d57a07SSrinivasan Raju
41968d57a07SSrinivasan Raju memset(&stats, 0, sizeof(stats));
42068d57a07SSrinivasan Raju
42168d57a07SSrinivasan Raju stats.flag = 0;
42268d57a07SSrinivasan Raju stats.freq = 2412;
42368d57a07SSrinivasan Raju stats.band = NL80211_BAND_LC;
42468d57a07SSrinivasan Raju mac->rssi = -15 * be16_to_cpu(status->rssi) / 10;
42568d57a07SSrinivasan Raju
42668d57a07SSrinivasan Raju stats.signal = mac->rssi;
42768d57a07SSrinivasan Raju
42868d57a07SSrinivasan Raju if (status->rate_idx > 7)
42968d57a07SSrinivasan Raju stats.rate_idx = 0;
43068d57a07SSrinivasan Raju else
43168d57a07SSrinivasan Raju stats.rate_idx = status->rate_idx;
43268d57a07SSrinivasan Raju
43368d57a07SSrinivasan Raju mac->crc_errors = be64_to_cpu(status->crc_error_count);
43468d57a07SSrinivasan Raju
43568d57a07SSrinivasan Raju /* TODO bad frame check for CRC error*/
43668d57a07SSrinivasan Raju if (plfxlc_filter_ack(hw, (struct ieee80211_hdr *)buffer, &stats) &&
43768d57a07SSrinivasan Raju !mac->pass_ctrl)
43868d57a07SSrinivasan Raju return 0;
43968d57a07SSrinivasan Raju
44068d57a07SSrinivasan Raju buffer += sizeof(struct rx_status);
44168d57a07SSrinivasan Raju payload_length = get_unaligned_be32(buffer);
44268d57a07SSrinivasan Raju
44368d57a07SSrinivasan Raju if (payload_length > 1560) {
44468d57a07SSrinivasan Raju dev_err(plfxlc_mac_dev(mac), " > MTU %u\n", payload_length);
44568d57a07SSrinivasan Raju return 0;
44668d57a07SSrinivasan Raju }
44768d57a07SSrinivasan Raju buffer += sizeof(u32);
44868d57a07SSrinivasan Raju
44968d57a07SSrinivasan Raju fc = get_unaligned((__le16 *)buffer);
45068d57a07SSrinivasan Raju need_padding = ieee80211_is_data_qos(fc) ^ ieee80211_has_a4(fc);
45168d57a07SSrinivasan Raju
45268d57a07SSrinivasan Raju tx = &mac->chip.usb.tx;
45368d57a07SSrinivasan Raju
45468d57a07SSrinivasan Raju for (sidx = 0; sidx < MAX_STA_NUM - 1; sidx++) {
45568d57a07SSrinivasan Raju if (memcmp(&buffer[10], tx->station[sidx].mac, ETH_ALEN))
45668d57a07SSrinivasan Raju continue;
45768d57a07SSrinivasan Raju if (tx->station[sidx].flag & STATION_CONNECTED_FLAG) {
45868d57a07SSrinivasan Raju tx->station[sidx].flag |= STATION_HEARTBEAT_FLAG;
45968d57a07SSrinivasan Raju break;
46068d57a07SSrinivasan Raju }
46168d57a07SSrinivasan Raju }
46268d57a07SSrinivasan Raju
46368d57a07SSrinivasan Raju if (sidx == MAX_STA_NUM - 1) {
46468d57a07SSrinivasan Raju for (sidx = 0; sidx < MAX_STA_NUM - 1; sidx++) {
46568d57a07SSrinivasan Raju if (tx->station[sidx].flag & STATION_CONNECTED_FLAG)
46668d57a07SSrinivasan Raju continue;
46768d57a07SSrinivasan Raju memcpy(tx->station[sidx].mac, &buffer[10], ETH_ALEN);
46868d57a07SSrinivasan Raju tx->station[sidx].flag |= STATION_CONNECTED_FLAG;
46968d57a07SSrinivasan Raju tx->station[sidx].flag |= STATION_HEARTBEAT_FLAG;
47068d57a07SSrinivasan Raju break;
47168d57a07SSrinivasan Raju }
47268d57a07SSrinivasan Raju }
47368d57a07SSrinivasan Raju
47468d57a07SSrinivasan Raju switch (buffer[0]) {
47568d57a07SSrinivasan Raju case IEEE80211_STYPE_PROBE_REQ:
47668d57a07SSrinivasan Raju dev_dbg(plfxlc_mac_dev(mac), "Probe request\n");
47768d57a07SSrinivasan Raju break;
47868d57a07SSrinivasan Raju case IEEE80211_STYPE_ASSOC_REQ:
47968d57a07SSrinivasan Raju dev_dbg(plfxlc_mac_dev(mac), "Association request\n");
48068d57a07SSrinivasan Raju break;
48168d57a07SSrinivasan Raju case IEEE80211_STYPE_AUTH:
48268d57a07SSrinivasan Raju dev_dbg(plfxlc_mac_dev(mac), "Authentication req\n");
48368d57a07SSrinivasan Raju break;
48468d57a07SSrinivasan Raju case IEEE80211_FTYPE_DATA:
48568d57a07SSrinivasan Raju dev_dbg(plfxlc_mac_dev(mac), "802.11 data frame\n");
48668d57a07SSrinivasan Raju break;
48768d57a07SSrinivasan Raju }
48868d57a07SSrinivasan Raju
48968d57a07SSrinivasan Raju skb = dev_alloc_skb(payload_length + (need_padding ? 2 : 0));
49068d57a07SSrinivasan Raju if (!skb)
49168d57a07SSrinivasan Raju return -ENOMEM;
49268d57a07SSrinivasan Raju
49368d57a07SSrinivasan Raju if (need_padding)
49468d57a07SSrinivasan Raju /* Make sure that the payload data is 4 byte aligned. */
49568d57a07SSrinivasan Raju skb_reserve(skb, 2);
49668d57a07SSrinivasan Raju
49768d57a07SSrinivasan Raju skb_put_data(skb, buffer, payload_length);
49868d57a07SSrinivasan Raju memcpy(IEEE80211_SKB_RXCB(skb), &stats, sizeof(stats));
49968d57a07SSrinivasan Raju ieee80211_rx_irqsafe(hw, skb);
50068d57a07SSrinivasan Raju return 0;
50168d57a07SSrinivasan Raju }
50268d57a07SSrinivasan Raju
plfxlc_op_add_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)50368d57a07SSrinivasan Raju static int plfxlc_op_add_interface(struct ieee80211_hw *hw,
50468d57a07SSrinivasan Raju struct ieee80211_vif *vif)
50568d57a07SSrinivasan Raju {
50668d57a07SSrinivasan Raju struct plfxlc_mac *mac = plfxlc_hw_mac(hw);
50768d57a07SSrinivasan Raju static const char * const iftype80211[] = {
50868d57a07SSrinivasan Raju [NL80211_IFTYPE_STATION] = "Station",
50968d57a07SSrinivasan Raju [NL80211_IFTYPE_ADHOC] = "Adhoc"
51068d57a07SSrinivasan Raju };
51168d57a07SSrinivasan Raju
51268d57a07SSrinivasan Raju if (mac->type != NL80211_IFTYPE_UNSPECIFIED)
51368d57a07SSrinivasan Raju return -EOPNOTSUPP;
51468d57a07SSrinivasan Raju
51568d57a07SSrinivasan Raju if (vif->type == NL80211_IFTYPE_ADHOC ||
51668d57a07SSrinivasan Raju vif->type == NL80211_IFTYPE_STATION) {
51768d57a07SSrinivasan Raju dev_dbg(plfxlc_mac_dev(mac), "%s %s\n", __func__,
51868d57a07SSrinivasan Raju iftype80211[vif->type]);
51968d57a07SSrinivasan Raju mac->type = vif->type;
52068d57a07SSrinivasan Raju mac->vif = vif;
52168d57a07SSrinivasan Raju return 0;
52268d57a07SSrinivasan Raju }
52368d57a07SSrinivasan Raju dev_dbg(plfxlc_mac_dev(mac), "unsupported iftype\n");
52468d57a07SSrinivasan Raju return -EOPNOTSUPP;
52568d57a07SSrinivasan Raju }
52668d57a07SSrinivasan Raju
plfxlc_op_remove_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)52768d57a07SSrinivasan Raju static void plfxlc_op_remove_interface(struct ieee80211_hw *hw,
52868d57a07SSrinivasan Raju struct ieee80211_vif *vif)
52968d57a07SSrinivasan Raju {
53068d57a07SSrinivasan Raju struct plfxlc_mac *mac = plfxlc_hw_mac(hw);
53168d57a07SSrinivasan Raju
53268d57a07SSrinivasan Raju mac->type = NL80211_IFTYPE_UNSPECIFIED;
53368d57a07SSrinivasan Raju mac->vif = NULL;
53468d57a07SSrinivasan Raju }
53568d57a07SSrinivasan Raju
plfxlc_op_config(struct ieee80211_hw * hw,u32 changed)53668d57a07SSrinivasan Raju static int plfxlc_op_config(struct ieee80211_hw *hw, u32 changed)
53768d57a07SSrinivasan Raju {
53868d57a07SSrinivasan Raju return 0;
53968d57a07SSrinivasan Raju }
54068d57a07SSrinivasan Raju
54168d57a07SSrinivasan Raju #define SUPPORTED_FIF_FLAGS \
54268d57a07SSrinivasan Raju (FIF_ALLMULTI | FIF_FCSFAIL | FIF_CONTROL | \
54368d57a07SSrinivasan Raju FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)
plfxlc_op_configure_filter(struct ieee80211_hw * hw,unsigned int changed_flags,unsigned int * new_flags,u64 multicast)54468d57a07SSrinivasan Raju static void plfxlc_op_configure_filter(struct ieee80211_hw *hw,
54568d57a07SSrinivasan Raju unsigned int changed_flags,
54668d57a07SSrinivasan Raju unsigned int *new_flags,
54768d57a07SSrinivasan Raju u64 multicast)
54868d57a07SSrinivasan Raju {
54968d57a07SSrinivasan Raju struct plfxlc_mc_hash hash = {
55068d57a07SSrinivasan Raju .low = multicast,
55168d57a07SSrinivasan Raju .high = multicast >> 32,
55268d57a07SSrinivasan Raju };
55368d57a07SSrinivasan Raju struct plfxlc_mac *mac = plfxlc_hw_mac(hw);
55468d57a07SSrinivasan Raju unsigned long flags;
55568d57a07SSrinivasan Raju
55668d57a07SSrinivasan Raju /* Only deal with supported flags */
55768d57a07SSrinivasan Raju *new_flags &= SUPPORTED_FIF_FLAGS;
55868d57a07SSrinivasan Raju
55968d57a07SSrinivasan Raju /* If multicast parameter
56068d57a07SSrinivasan Raju * (as returned by plfxlc_op_prepare_multicast)
56168d57a07SSrinivasan Raju * has changed, no bit in changed_flags is set. To handle this
56268d57a07SSrinivasan Raju * situation, we do not return if changed_flags is 0. If we do so,
56368d57a07SSrinivasan Raju * we will have some issue with IPv6 which uses multicast for link
56468d57a07SSrinivasan Raju * layer address resolution.
56568d57a07SSrinivasan Raju */
56668d57a07SSrinivasan Raju if (*new_flags & (FIF_ALLMULTI))
56768d57a07SSrinivasan Raju plfxlc_mc_add_all(&hash);
56868d57a07SSrinivasan Raju
56968d57a07SSrinivasan Raju spin_lock_irqsave(&mac->lock, flags);
57068d57a07SSrinivasan Raju mac->pass_failed_fcs = !!(*new_flags & FIF_FCSFAIL);
57168d57a07SSrinivasan Raju mac->pass_ctrl = !!(*new_flags & FIF_CONTROL);
57268d57a07SSrinivasan Raju mac->multicast_hash = hash;
57368d57a07SSrinivasan Raju spin_unlock_irqrestore(&mac->lock, flags);
57468d57a07SSrinivasan Raju
57568d57a07SSrinivasan Raju /* no handling required for FIF_OTHER_BSS as we don't currently
57668d57a07SSrinivasan Raju * do BSSID filtering
57768d57a07SSrinivasan Raju */
57868d57a07SSrinivasan Raju /* FIXME: in future it would be nice to enable the probe response
57968d57a07SSrinivasan Raju * filter (so that the driver doesn't see them) until
58068d57a07SSrinivasan Raju * FIF_BCN_PRBRESP_PROMISC is set. however due to atomicity here, we'd
58168d57a07SSrinivasan Raju * have to schedule work to enable prbresp reception, which might
58268d57a07SSrinivasan Raju * happen too late. For now we'll just listen and forward them all the
58368d57a07SSrinivasan Raju * time.
58468d57a07SSrinivasan Raju */
58568d57a07SSrinivasan Raju }
58668d57a07SSrinivasan Raju
plfxlc_op_bss_info_changed(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * bss_conf,u64 changes)58768d57a07SSrinivasan Raju static void plfxlc_op_bss_info_changed(struct ieee80211_hw *hw,
58868d57a07SSrinivasan Raju struct ieee80211_vif *vif,
58968d57a07SSrinivasan Raju struct ieee80211_bss_conf *bss_conf,
5907b7090b4SJohannes Berg u64 changes)
59168d57a07SSrinivasan Raju {
59268d57a07SSrinivasan Raju struct plfxlc_mac *mac = plfxlc_hw_mac(hw);
59368d57a07SSrinivasan Raju int associated;
59468d57a07SSrinivasan Raju
5957b7090b4SJohannes Berg dev_dbg(plfxlc_mac_dev(mac), "changes: %llx\n", changes);
59668d57a07SSrinivasan Raju
59768d57a07SSrinivasan Raju if (mac->type != NL80211_IFTYPE_ADHOC) { /* for STATION */
59868d57a07SSrinivasan Raju associated = is_valid_ether_addr(bss_conf->bssid);
59968d57a07SSrinivasan Raju goto exit_all;
60068d57a07SSrinivasan Raju }
60168d57a07SSrinivasan Raju /* for ADHOC */
60268d57a07SSrinivasan Raju associated = true;
60368d57a07SSrinivasan Raju if (changes & BSS_CHANGED_BEACON) {
6046e8912a5SShaul Triebitz struct sk_buff *beacon = ieee80211_beacon_get(hw, vif, 0);
60568d57a07SSrinivasan Raju
60668d57a07SSrinivasan Raju if (beacon) {
60768d57a07SSrinivasan Raju /*beacon is hardcoded in firmware */
60868d57a07SSrinivasan Raju kfree_skb(beacon);
60968d57a07SSrinivasan Raju /*Returned skb is used only once and
61068d57a07SSrinivasan Raju * low-level driver is
61168d57a07SSrinivasan Raju * responsible for freeing it.
61268d57a07SSrinivasan Raju */
61368d57a07SSrinivasan Raju }
61468d57a07SSrinivasan Raju }
61568d57a07SSrinivasan Raju
61668d57a07SSrinivasan Raju if (changes & BSS_CHANGED_BEACON_ENABLED) {
61768d57a07SSrinivasan Raju u16 interval = 0;
61868d57a07SSrinivasan Raju u8 period = 0;
61968d57a07SSrinivasan Raju
62068d57a07SSrinivasan Raju if (bss_conf->enable_beacon) {
62168d57a07SSrinivasan Raju period = bss_conf->dtim_period;
62268d57a07SSrinivasan Raju interval = bss_conf->beacon_int;
62368d57a07SSrinivasan Raju }
62468d57a07SSrinivasan Raju
62568d57a07SSrinivasan Raju spin_lock_irq(&mac->lock);
62668d57a07SSrinivasan Raju mac->beacon.period = period;
62768d57a07SSrinivasan Raju mac->beacon.interval = interval;
62868d57a07SSrinivasan Raju mac->beacon.last_update = jiffies;
62968d57a07SSrinivasan Raju spin_unlock_irq(&mac->lock);
63068d57a07SSrinivasan Raju
63168d57a07SSrinivasan Raju plfxlc_set_beacon_interval(&mac->chip, interval,
63268d57a07SSrinivasan Raju period, mac->type);
63368d57a07SSrinivasan Raju }
63468d57a07SSrinivasan Raju exit_all:
63568d57a07SSrinivasan Raju spin_lock_irq(&mac->lock);
63668d57a07SSrinivasan Raju mac->associated = associated;
63768d57a07SSrinivasan Raju spin_unlock_irq(&mac->lock);
63868d57a07SSrinivasan Raju }
63968d57a07SSrinivasan Raju
plfxlc_get_stats(struct ieee80211_hw * hw,struct ieee80211_low_level_stats * stats)64068d57a07SSrinivasan Raju static int plfxlc_get_stats(struct ieee80211_hw *hw,
64168d57a07SSrinivasan Raju struct ieee80211_low_level_stats *stats)
64268d57a07SSrinivasan Raju {
64368d57a07SSrinivasan Raju stats->dot11ACKFailureCount = 0;
64468d57a07SSrinivasan Raju stats->dot11RTSFailureCount = 0;
64568d57a07SSrinivasan Raju stats->dot11FCSErrorCount = 0;
64668d57a07SSrinivasan Raju stats->dot11RTSSuccessCount = 0;
64768d57a07SSrinivasan Raju return 0;
64868d57a07SSrinivasan Raju }
64968d57a07SSrinivasan Raju
65068d57a07SSrinivasan Raju static const char et_strings[][ETH_GSTRING_LEN] = {
65168d57a07SSrinivasan Raju "phy_rssi",
65268d57a07SSrinivasan Raju "phy_rx_crc_err"
65368d57a07SSrinivasan Raju };
65468d57a07SSrinivasan Raju
plfxlc_get_et_sset_count(struct ieee80211_hw * hw,struct ieee80211_vif * vif,int sset)65568d57a07SSrinivasan Raju static int plfxlc_get_et_sset_count(struct ieee80211_hw *hw,
65668d57a07SSrinivasan Raju struct ieee80211_vif *vif, int sset)
65768d57a07SSrinivasan Raju {
65868d57a07SSrinivasan Raju if (sset == ETH_SS_STATS)
65968d57a07SSrinivasan Raju return ARRAY_SIZE(et_strings);
66068d57a07SSrinivasan Raju
66168d57a07SSrinivasan Raju return 0;
66268d57a07SSrinivasan Raju }
66368d57a07SSrinivasan Raju
plfxlc_get_et_strings(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u32 sset,u8 * data)66468d57a07SSrinivasan Raju static void plfxlc_get_et_strings(struct ieee80211_hw *hw,
66568d57a07SSrinivasan Raju struct ieee80211_vif *vif,
66668d57a07SSrinivasan Raju u32 sset, u8 *data)
66768d57a07SSrinivasan Raju {
66868d57a07SSrinivasan Raju if (sset == ETH_SS_STATS)
669*03f9498aSDmitry Antipov memcpy(data, et_strings, sizeof(et_strings));
67068d57a07SSrinivasan Raju }
67168d57a07SSrinivasan Raju
plfxlc_get_et_stats(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ethtool_stats * stats,u64 * data)67268d57a07SSrinivasan Raju static void plfxlc_get_et_stats(struct ieee80211_hw *hw,
67368d57a07SSrinivasan Raju struct ieee80211_vif *vif,
67468d57a07SSrinivasan Raju struct ethtool_stats *stats, u64 *data)
67568d57a07SSrinivasan Raju {
67668d57a07SSrinivasan Raju struct plfxlc_mac *mac = plfxlc_hw_mac(hw);
67768d57a07SSrinivasan Raju
67868d57a07SSrinivasan Raju data[0] = mac->rssi;
67968d57a07SSrinivasan Raju data[1] = mac->crc_errors;
68068d57a07SSrinivasan Raju }
68168d57a07SSrinivasan Raju
plfxlc_set_rts_threshold(struct ieee80211_hw * hw,u32 value)68268d57a07SSrinivasan Raju static int plfxlc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
68368d57a07SSrinivasan Raju {
68468d57a07SSrinivasan Raju return 0;
68568d57a07SSrinivasan Raju }
68668d57a07SSrinivasan Raju
68768d57a07SSrinivasan Raju static const struct ieee80211_ops plfxlc_ops = {
68868d57a07SSrinivasan Raju .tx = plfxlc_op_tx,
689a790cc3aSAlexander Wetzel .wake_tx_queue = ieee80211_handle_wake_tx_queue,
69068d57a07SSrinivasan Raju .start = plfxlc_op_start,
69168d57a07SSrinivasan Raju .stop = plfxlc_op_stop,
69268d57a07SSrinivasan Raju .add_interface = plfxlc_op_add_interface,
69368d57a07SSrinivasan Raju .remove_interface = plfxlc_op_remove_interface,
69468d57a07SSrinivasan Raju .set_rts_threshold = plfxlc_set_rts_threshold,
69568d57a07SSrinivasan Raju .config = plfxlc_op_config,
69668d57a07SSrinivasan Raju .configure_filter = plfxlc_op_configure_filter,
69768d57a07SSrinivasan Raju .bss_info_changed = plfxlc_op_bss_info_changed,
69868d57a07SSrinivasan Raju .get_stats = plfxlc_get_stats,
69968d57a07SSrinivasan Raju .get_et_sset_count = plfxlc_get_et_sset_count,
70068d57a07SSrinivasan Raju .get_et_stats = plfxlc_get_et_stats,
70168d57a07SSrinivasan Raju .get_et_strings = plfxlc_get_et_strings,
70268d57a07SSrinivasan Raju };
70368d57a07SSrinivasan Raju
plfxlc_mac_alloc_hw(struct usb_interface * intf)70468d57a07SSrinivasan Raju struct ieee80211_hw *plfxlc_mac_alloc_hw(struct usb_interface *intf)
70568d57a07SSrinivasan Raju {
70668d57a07SSrinivasan Raju struct ieee80211_hw *hw;
70768d57a07SSrinivasan Raju struct plfxlc_mac *mac;
70868d57a07SSrinivasan Raju
70968d57a07SSrinivasan Raju hw = ieee80211_alloc_hw(sizeof(struct plfxlc_mac), &plfxlc_ops);
71068d57a07SSrinivasan Raju if (!hw) {
71168d57a07SSrinivasan Raju dev_dbg(&intf->dev, "out of memory\n");
71268d57a07SSrinivasan Raju return NULL;
71368d57a07SSrinivasan Raju }
71468d57a07SSrinivasan Raju set_wiphy_dev(hw->wiphy, &intf->dev);
71568d57a07SSrinivasan Raju
71668d57a07SSrinivasan Raju mac = plfxlc_hw_mac(hw);
71768d57a07SSrinivasan Raju memset(mac, 0, sizeof(*mac));
71868d57a07SSrinivasan Raju spin_lock_init(&mac->lock);
71968d57a07SSrinivasan Raju mac->hw = hw;
72068d57a07SSrinivasan Raju
72168d57a07SSrinivasan Raju mac->type = NL80211_IFTYPE_UNSPECIFIED;
72268d57a07SSrinivasan Raju
72368d57a07SSrinivasan Raju memcpy(mac->channels, plfxlc_channels, sizeof(plfxlc_channels));
72468d57a07SSrinivasan Raju memcpy(mac->rates, plfxlc_rates, sizeof(plfxlc_rates));
72568d57a07SSrinivasan Raju mac->band.n_bitrates = ARRAY_SIZE(plfxlc_rates);
72668d57a07SSrinivasan Raju mac->band.bitrates = mac->rates;
72768d57a07SSrinivasan Raju mac->band.n_channels = ARRAY_SIZE(plfxlc_channels);
72868d57a07SSrinivasan Raju mac->band.channels = mac->channels;
72968d57a07SSrinivasan Raju hw->wiphy->bands[NL80211_BAND_LC] = &mac->band;
73068d57a07SSrinivasan Raju hw->conf.chandef.width = NL80211_CHAN_WIDTH_20;
73168d57a07SSrinivasan Raju
73268d57a07SSrinivasan Raju ieee80211_hw_set(hw, RX_INCLUDES_FCS);
73368d57a07SSrinivasan Raju ieee80211_hw_set(hw, SIGNAL_DBM);
73468d57a07SSrinivasan Raju ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING);
73568d57a07SSrinivasan Raju ieee80211_hw_set(hw, MFP_CAPABLE);
73668d57a07SSrinivasan Raju
73768d57a07SSrinivasan Raju hw->wiphy->interface_modes =
73868d57a07SSrinivasan Raju BIT(NL80211_IFTYPE_STATION) |
73968d57a07SSrinivasan Raju BIT(NL80211_IFTYPE_ADHOC);
74068d57a07SSrinivasan Raju hw->max_signal = 100;
74168d57a07SSrinivasan Raju hw->queues = 1;
74268d57a07SSrinivasan Raju /* 4 for 32 bit alignment if no tailroom */
74368d57a07SSrinivasan Raju hw->extra_tx_headroom = sizeof(struct plfxlc_ctrlset) + 4;
74468d57a07SSrinivasan Raju /* Tell mac80211 that we support multi rate retries */
74568d57a07SSrinivasan Raju hw->max_rates = IEEE80211_TX_MAX_RATES;
74668d57a07SSrinivasan Raju hw->max_rate_tries = 18; /* 9 rates * 2 retries/rate */
74768d57a07SSrinivasan Raju
74868d57a07SSrinivasan Raju skb_queue_head_init(&mac->ack_wait_queue);
74968d57a07SSrinivasan Raju mac->ack_pending = 0;
75068d57a07SSrinivasan Raju
75168d57a07SSrinivasan Raju plfxlc_chip_init(&mac->chip, hw, intf);
75268d57a07SSrinivasan Raju
75368d57a07SSrinivasan Raju SET_IEEE80211_DEV(hw, &intf->dev);
75468d57a07SSrinivasan Raju return hw;
75568d57a07SSrinivasan Raju }
756