Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
config WLAN_VENDOR_QUANTENNA
bool "Quantenna wireless cards support"
default y
---help---
If you have a wireless card belonging to this class, say Y.
Note that the answer to this question doesn't directly affect the
kernel: saying N will just cause the configurator to skip all the
questions about these cards. If you say Y, you will be asked for
your specific card in the following questions.
if WLAN_VENDOR_QUANTENNA
source "drivers/net/wireless/quantenna/qtnfmac/Kconfig"
endif # WLAN_VENDOR_QUANTENNA
+6
View File
@@ -0,0 +1,6 @@
#
# Copyright (c) 2015-2016 Quantenna Communications, Inc.
# All rights reserved.
#
obj-$(CONFIG_QTNFMAC) += qtnfmac/
@@ -0,0 +1,19 @@
config QTNFMAC
tristate
depends on QTNFMAC_PEARL_PCIE
default m if QTNFMAC_PEARL_PCIE=m
default y if QTNFMAC_PEARL_PCIE=y
config QTNFMAC_PEARL_PCIE
tristate "Quantenna QSR10g PCIe support"
default n
depends on PCI && CFG80211
select QTNFMAC
select FW_LOADER
select CRC32
---help---
This option adds support for wireless adapters based on Quantenna
802.11ac QSR10g (aka Pearl) FullMAC chipset running over PCIe.
If you choose to build it as a module, two modules will be built:
qtnfmac.ko and qtnfmac_pearl_pcie.ko.
@@ -0,0 +1,28 @@
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2015-2016 Quantenna Communications, Inc.
# All rights reserved.
#
ccflags-y += \
-Idrivers/net/wireless/quantenna/qtnfmac
obj-$(CONFIG_QTNFMAC) += qtnfmac.o
qtnfmac-objs += \
core.o \
commands.o \
trans.o \
cfg80211.o \
event.o \
util.o \
qlink_util.o
#
obj-$(CONFIG_QTNFMAC_PEARL_PCIE) += qtnfmac_pearl_pcie.o
qtnfmac_pearl_pcie-objs += \
shm_ipc.o \
pearl/pcie.o
qtnfmac_pearl_pcie-$(CONFIG_DEBUG_FS) += debug.o
@@ -0,0 +1,140 @@
/*
* Copyright (c) 2015 Quantenna Communications
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef QTNFMAC_BUS_H
#define QTNFMAC_BUS_H
#include <linux/netdevice.h>
#include <linux/workqueue.h>
#define QTNF_MAX_MAC 3
enum qtnf_fw_state {
QTNF_FW_STATE_RESET,
QTNF_FW_STATE_FW_DNLD_DONE,
QTNF_FW_STATE_BOOT_DONE,
QTNF_FW_STATE_ACTIVE,
QTNF_FW_STATE_DETACHED,
QTNF_FW_STATE_EP_DEAD,
};
struct qtnf_bus;
struct qtnf_bus_ops {
/* mgmt methods */
int (*preinit)(struct qtnf_bus *);
void (*stop)(struct qtnf_bus *);
/* control path methods */
int (*control_tx)(struct qtnf_bus *, struct sk_buff *);
/* data xfer methods */
int (*data_tx)(struct qtnf_bus *, struct sk_buff *);
void (*data_tx_timeout)(struct qtnf_bus *, struct net_device *);
void (*data_rx_start)(struct qtnf_bus *);
void (*data_rx_stop)(struct qtnf_bus *);
};
struct qtnf_bus {
struct device *dev;
enum qtnf_fw_state fw_state;
u32 chip;
u32 chiprev;
const struct qtnf_bus_ops *bus_ops;
struct qtnf_wmac *mac[QTNF_MAX_MAC];
struct qtnf_qlink_transport trans;
struct qtnf_hw_info hw_info;
char fwname[32];
struct napi_struct mux_napi;
struct net_device mux_dev;
struct completion firmware_init_complete;
struct workqueue_struct *workqueue;
struct work_struct fw_work;
struct work_struct event_work;
struct mutex bus_lock; /* lock during command/event processing */
struct dentry *dbg_dir;
/* bus private data */
char bus_priv[0] __aligned(sizeof(void *));
};
static inline void *get_bus_priv(struct qtnf_bus *bus)
{
if (WARN(!bus, "qtnfmac: invalid bus pointer"))
return NULL;
return &bus->bus_priv;
}
/* callback wrappers */
static inline int qtnf_bus_preinit(struct qtnf_bus *bus)
{
if (!bus->bus_ops->preinit)
return 0;
return bus->bus_ops->preinit(bus);
}
static inline void qtnf_bus_stop(struct qtnf_bus *bus)
{
if (!bus->bus_ops->stop)
return;
bus->bus_ops->stop(bus);
}
static inline int qtnf_bus_data_tx(struct qtnf_bus *bus, struct sk_buff *skb)
{
return bus->bus_ops->data_tx(bus, skb);
}
static inline void
qtnf_bus_data_tx_timeout(struct qtnf_bus *bus, struct net_device *ndev)
{
return bus->bus_ops->data_tx_timeout(bus, ndev);
}
static inline int qtnf_bus_control_tx(struct qtnf_bus *bus, struct sk_buff *skb)
{
return bus->bus_ops->control_tx(bus, skb);
}
static inline void qtnf_bus_data_rx_start(struct qtnf_bus *bus)
{
return bus->bus_ops->data_rx_start(bus);
}
static inline void qtnf_bus_data_rx_stop(struct qtnf_bus *bus)
{
return bus->bus_ops->data_rx_stop(bus);
}
static __always_inline void qtnf_bus_lock(struct qtnf_bus *bus)
{
mutex_lock(&bus->bus_lock);
}
static __always_inline void qtnf_bus_unlock(struct qtnf_bus *bus)
{
mutex_unlock(&bus->bus_lock);
}
/* interface functions from common layer */
int qtnf_core_attach(struct qtnf_bus *bus);
void qtnf_core_detach(struct qtnf_bus *bus);
void qtnf_txflowblock(struct device *dev, bool state);
void qtnf_txcomplete(struct device *dev, struct sk_buff *txp, bool success);
#endif /* QTNFMAC_BUS_H */
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _QTN_FMAC_CFG80211_H_
#define _QTN_FMAC_CFG80211_H_
#include <net/cfg80211.h>
#include "core.h"
int qtnf_wiphy_register(struct qtnf_hw_info *hw_info, struct qtnf_wmac *mac);
int qtnf_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev);
void qtnf_cfg80211_vif_reset(struct qtnf_vif *vif);
void qtnf_band_init_rates(struct ieee80211_supported_band *band);
void qtnf_band_setup_htvht_caps(struct qtnf_mac_info *macinfo,
struct ieee80211_supported_band *band);
#endif /* _QTN_FMAC_CFG80211_H_ */
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2016 Quantenna Communications, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef QLINK_COMMANDS_H_
#define QLINK_COMMANDS_H_
#include <linux/nl80211.h>
#include "core.h"
#include "bus.h"
int qtnf_cmd_send_init_fw(struct qtnf_bus *bus);
void qtnf_cmd_send_deinit_fw(struct qtnf_bus *bus);
int qtnf_cmd_get_hw_info(struct qtnf_bus *bus);
int qtnf_cmd_get_mac_info(struct qtnf_wmac *mac);
int qtnf_cmd_send_add_intf(struct qtnf_vif *vif, enum nl80211_iftype iftype,
u8 *mac_addr);
int qtnf_cmd_send_change_intf_type(struct qtnf_vif *vif,
enum nl80211_iftype iftype, u8 *mac_addr);
int qtnf_cmd_send_del_intf(struct qtnf_vif *vif);
int qtnf_cmd_band_info_get(struct qtnf_wmac *mac,
struct ieee80211_supported_band *band);
int qtnf_cmd_send_regulatory_config(struct qtnf_wmac *mac, const char *alpha2);
int qtnf_cmd_send_start_ap(struct qtnf_vif *vif,
const struct cfg80211_ap_settings *s);
int qtnf_cmd_send_stop_ap(struct qtnf_vif *vif);
int qtnf_cmd_send_register_mgmt(struct qtnf_vif *vif, u16 frame_type, bool reg);
int qtnf_cmd_send_mgmt_frame(struct qtnf_vif *vif, u32 cookie, u16 flags,
u16 freq, const u8 *buf, size_t len);
int qtnf_cmd_send_mgmt_set_appie(struct qtnf_vif *vif, u8 frame_type,
const u8 *buf, size_t len);
int qtnf_cmd_get_sta_info(struct qtnf_vif *vif, const u8 *sta_mac,
struct station_info *sinfo);
int qtnf_cmd_send_phy_params(struct qtnf_wmac *mac, u16 cmd_action,
void *data_buf);
int qtnf_cmd_send_add_key(struct qtnf_vif *vif, u8 key_index, bool pairwise,
const u8 *mac_addr, struct key_params *params);
int qtnf_cmd_send_del_key(struct qtnf_vif *vif, u8 key_index, bool pairwise,
const u8 *mac_addr);
int qtnf_cmd_send_set_default_key(struct qtnf_vif *vif, u8 key_index,
bool unicast, bool multicast);
int qtnf_cmd_send_set_default_mgmt_key(struct qtnf_vif *vif, u8 key_index);
int qtnf_cmd_send_add_sta(struct qtnf_vif *vif, const u8 *mac,
struct station_parameters *params);
int qtnf_cmd_send_change_sta(struct qtnf_vif *vif, const u8 *mac,
struct station_parameters *params);
int qtnf_cmd_send_del_sta(struct qtnf_vif *vif,
struct station_del_parameters *params);
int qtnf_cmd_send_scan(struct qtnf_wmac *mac);
int qtnf_cmd_send_connect(struct qtnf_vif *vif,
struct cfg80211_connect_params *sme);
int qtnf_cmd_send_disconnect(struct qtnf_vif *vif,
u16 reason_code);
int qtnf_cmd_send_updown_intf(struct qtnf_vif *vif,
bool up);
int qtnf_cmd_reg_notify(struct qtnf_bus *bus, struct regulatory_request *req);
int qtnf_cmd_get_chan_stats(struct qtnf_wmac *mac, u16 channel,
struct qtnf_chan_stats *stats);
int qtnf_cmd_send_chan_switch(struct qtnf_vif *vif,
struct cfg80211_csa_settings *params);
int qtnf_cmd_get_channel(struct qtnf_vif *vif, struct cfg80211_chan_def *chdef);
int qtnf_cmd_start_cac(const struct qtnf_vif *vif,
const struct cfg80211_chan_def *chdef,
u32 cac_time_ms);
int qtnf_cmd_set_mac_acl(const struct qtnf_vif *vif,
const struct cfg80211_acl_data *params);
int qtnf_cmd_send_pm_set(const struct qtnf_vif *vif, u8 pm_mode, int timeout);
int qtnf_cmd_send_wowlan_set(const struct qtnf_vif *vif,
const struct cfg80211_wowlan *wowl);
#endif /* QLINK_COMMANDS_H_ */
@@ -0,0 +1,812 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/if_ether.h>
#include "core.h"
#include "bus.h"
#include "trans.h"
#include "commands.h"
#include "cfg80211.h"
#include "event.h"
#include "util.h"
#define QTNF_DMP_MAX_LEN 48
#define QTNF_PRIMARY_VIF_IDX 0
struct qtnf_frame_meta_info {
u8 magic_s;
u8 ifidx;
u8 macid;
u8 magic_e;
} __packed;
struct qtnf_wmac *qtnf_core_get_mac(const struct qtnf_bus *bus, u8 macid)
{
struct qtnf_wmac *mac = NULL;
if (unlikely(macid >= QTNF_MAX_MAC)) {
pr_err("invalid MAC index %u\n", macid);
return NULL;
}
mac = bus->mac[macid];
if (unlikely(!mac)) {
pr_err("MAC%u: not initialized\n", macid);
return NULL;
}
return mac;
}
/* Netdev handler for open.
*/
static int qtnf_netdev_open(struct net_device *ndev)
{
netif_carrier_off(ndev);
qtnf_netdev_updown(ndev, 1);
return 0;
}
/* Netdev handler for close.
*/
static int qtnf_netdev_close(struct net_device *ndev)
{
netif_carrier_off(ndev);
qtnf_virtual_intf_cleanup(ndev);
qtnf_netdev_updown(ndev, 0);
return 0;
}
/* Netdev handler for data transmission.
*/
static netdev_tx_t
qtnf_netdev_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
{
struct qtnf_vif *vif;
struct qtnf_wmac *mac;
vif = qtnf_netdev_get_priv(ndev);
if (unlikely(skb->dev != ndev)) {
pr_err_ratelimited("invalid skb->dev");
dev_kfree_skb_any(skb);
return 0;
}
if (unlikely(vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)) {
pr_err_ratelimited("%s: VIF not initialized\n", ndev->name);
dev_kfree_skb_any(skb);
return 0;
}
mac = vif->mac;
if (unlikely(!mac)) {
pr_err_ratelimited("%s: NULL mac pointer", ndev->name);
dev_kfree_skb_any(skb);
return 0;
}
if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
pr_err_ratelimited("%s: invalid skb len %d\n", ndev->name,
skb->len);
dev_kfree_skb_any(skb);
ndev->stats.tx_dropped++;
return 0;
}
/* tx path is enabled: reset vif timeout */
vif->cons_tx_timeout_cnt = 0;
return qtnf_bus_data_tx(mac->bus, skb);
}
/* Netdev handler for getting stats.
*/
static void qtnf_netdev_get_stats64(struct net_device *ndev,
struct rtnl_link_stats64 *stats)
{
struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
unsigned int start;
int cpu;
netdev_stats_to_stats64(stats, &ndev->stats);
if (!vif->stats64)
return;
for_each_possible_cpu(cpu) {
struct pcpu_sw_netstats *stats64;
u64 rx_packets, rx_bytes;
u64 tx_packets, tx_bytes;
stats64 = per_cpu_ptr(vif->stats64, cpu);
do {
start = u64_stats_fetch_begin_irq(&stats64->syncp);
rx_packets = stats64->rx_packets;
rx_bytes = stats64->rx_bytes;
tx_packets = stats64->tx_packets;
tx_bytes = stats64->tx_bytes;
} while (u64_stats_fetch_retry_irq(&stats64->syncp, start));
stats->rx_packets += rx_packets;
stats->rx_bytes += rx_bytes;
stats->tx_packets += tx_packets;
stats->tx_bytes += tx_bytes;
}
}
/* Netdev handler for transmission timeout.
*/
static void qtnf_netdev_tx_timeout(struct net_device *ndev)
{
struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
struct qtnf_wmac *mac;
struct qtnf_bus *bus;
if (unlikely(!vif || !vif->mac || !vif->mac->bus))
return;
mac = vif->mac;
bus = mac->bus;
pr_warn("VIF%u.%u: Tx timeout- %lu\n", mac->macid, vif->vifid, jiffies);
qtnf_bus_data_tx_timeout(bus, ndev);
ndev->stats.tx_errors++;
if (++vif->cons_tx_timeout_cnt > QTNF_TX_TIMEOUT_TRSHLD) {
pr_err("Tx timeout threshold exceeded !\n");
pr_err("schedule interface %s reset !\n", netdev_name(ndev));
queue_work(bus->workqueue, &vif->reset_work);
}
}
static int qtnf_netdev_set_mac_address(struct net_device *ndev, void *addr)
{
struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
struct sockaddr *sa = addr;
int ret;
unsigned char old_addr[ETH_ALEN];
memcpy(old_addr, sa->sa_data, sizeof(old_addr));
ret = eth_mac_addr(ndev, sa);
if (ret)
return ret;
qtnf_scan_done(vif->mac, true);
ret = qtnf_cmd_send_change_intf_type(vif, vif->wdev.iftype,
sa->sa_data);
if (ret)
memcpy(ndev->dev_addr, old_addr, ETH_ALEN);
return ret;
}
/* Network device ops handlers */
const struct net_device_ops qtnf_netdev_ops = {
.ndo_open = qtnf_netdev_open,
.ndo_stop = qtnf_netdev_close,
.ndo_start_xmit = qtnf_netdev_hard_start_xmit,
.ndo_tx_timeout = qtnf_netdev_tx_timeout,
.ndo_get_stats64 = qtnf_netdev_get_stats64,
.ndo_set_mac_address = qtnf_netdev_set_mac_address,
};
static int qtnf_mac_init_single_band(struct wiphy *wiphy,
struct qtnf_wmac *mac,
enum nl80211_band band)
{
int ret;
wiphy->bands[band] = kzalloc(sizeof(*wiphy->bands[band]), GFP_KERNEL);
if (!wiphy->bands[band])
return -ENOMEM;
wiphy->bands[band]->band = band;
ret = qtnf_cmd_band_info_get(mac, wiphy->bands[band]);
if (ret) {
pr_err("MAC%u: band %u: failed to get chans info: %d\n",
mac->macid, band, ret);
return ret;
}
qtnf_band_init_rates(wiphy->bands[band]);
return 0;
}
static int qtnf_mac_init_bands(struct qtnf_wmac *mac)
{
struct wiphy *wiphy = priv_to_wiphy(mac);
int ret = 0;
if (mac->macinfo.bands_cap & QLINK_BAND_2GHZ) {
ret = qtnf_mac_init_single_band(wiphy, mac, NL80211_BAND_2GHZ);
if (ret)
goto out;
}
if (mac->macinfo.bands_cap & QLINK_BAND_5GHZ) {
ret = qtnf_mac_init_single_band(wiphy, mac, NL80211_BAND_5GHZ);
if (ret)
goto out;
}
if (mac->macinfo.bands_cap & QLINK_BAND_60GHZ)
ret = qtnf_mac_init_single_band(wiphy, mac, NL80211_BAND_60GHZ);
out:
return ret;
}
struct qtnf_vif *qtnf_mac_get_free_vif(struct qtnf_wmac *mac)
{
struct qtnf_vif *vif;
int i;
for (i = 0; i < QTNF_MAX_INTF; i++) {
vif = &mac->iflist[i];
if (vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)
return vif;
}
return NULL;
}
struct qtnf_vif *qtnf_mac_get_base_vif(struct qtnf_wmac *mac)
{
struct qtnf_vif *vif;
vif = &mac->iflist[QTNF_PRIMARY_VIF_IDX];
if (vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)
return NULL;
return vif;
}
void qtnf_mac_iface_comb_free(struct qtnf_wmac *mac)
{
struct ieee80211_iface_combination *comb;
int i;
if (mac->macinfo.if_comb) {
for (i = 0; i < mac->macinfo.n_if_comb; i++) {
comb = &mac->macinfo.if_comb[i];
kfree(comb->limits);
comb->limits = NULL;
}
kfree(mac->macinfo.if_comb);
mac->macinfo.if_comb = NULL;
}
}
void qtnf_mac_ext_caps_free(struct qtnf_wmac *mac)
{
if (mac->macinfo.extended_capabilities_len) {
kfree(mac->macinfo.extended_capabilities);
mac->macinfo.extended_capabilities = NULL;
kfree(mac->macinfo.extended_capabilities_mask);
mac->macinfo.extended_capabilities_mask = NULL;
mac->macinfo.extended_capabilities_len = 0;
}
}
static void qtnf_vif_reset_handler(struct work_struct *work)
{
struct qtnf_vif *vif = container_of(work, struct qtnf_vif, reset_work);
rtnl_lock();
if (vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED) {
rtnl_unlock();
return;
}
/* stop tx completely */
netif_tx_stop_all_queues(vif->netdev);
if (netif_carrier_ok(vif->netdev))
netif_carrier_off(vif->netdev);
qtnf_cfg80211_vif_reset(vif);
rtnl_unlock();
}
static void qtnf_mac_init_primary_intf(struct qtnf_wmac *mac)
{
struct qtnf_vif *vif = &mac->iflist[QTNF_PRIMARY_VIF_IDX];
vif->wdev.iftype = NL80211_IFTYPE_STATION;
vif->bss_priority = QTNF_DEF_BSS_PRIORITY;
vif->wdev.wiphy = priv_to_wiphy(mac);
INIT_WORK(&vif->reset_work, qtnf_vif_reset_handler);
vif->cons_tx_timeout_cnt = 0;
}
static void qtnf_mac_scan_finish(struct qtnf_wmac *mac, bool aborted)
{
struct cfg80211_scan_info info = {
.aborted = aborted,
};
mutex_lock(&mac->mac_lock);
if (mac->scan_req) {
cfg80211_scan_done(mac->scan_req, &info);
mac->scan_req = NULL;
}
mutex_unlock(&mac->mac_lock);
}
void qtnf_scan_done(struct qtnf_wmac *mac, bool aborted)
{
cancel_delayed_work_sync(&mac->scan_timeout);
qtnf_mac_scan_finish(mac, aborted);
}
static void qtnf_mac_scan_timeout(struct work_struct *work)
{
struct qtnf_wmac *mac =
container_of(work, struct qtnf_wmac, scan_timeout.work);
pr_warn("MAC%d: scan timed out\n", mac->macid);
qtnf_mac_scan_finish(mac, true);
}
static struct qtnf_wmac *qtnf_core_mac_alloc(struct qtnf_bus *bus,
unsigned int macid)
{
struct wiphy *wiphy;
struct qtnf_wmac *mac;
unsigned int i;
wiphy = qtnf_wiphy_allocate(bus);
if (!wiphy)
return ERR_PTR(-ENOMEM);
mac = wiphy_priv(wiphy);
mac->macid = macid;
mac->bus = bus;
for (i = 0; i < QTNF_MAX_INTF; i++) {
memset(&mac->iflist[i], 0, sizeof(struct qtnf_vif));
mac->iflist[i].wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
mac->iflist[i].mac = mac;
mac->iflist[i].vifid = i;
qtnf_sta_list_init(&mac->iflist[i].sta_list);
mutex_init(&mac->mac_lock);
INIT_DELAYED_WORK(&mac->scan_timeout, qtnf_mac_scan_timeout);
mac->iflist[i].stats64 =
netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
if (!mac->iflist[i].stats64)
pr_warn("VIF%u.%u: per cpu stats allocation failed\n",
macid, i);
}
qtnf_mac_init_primary_intf(mac);
bus->mac[macid] = mac;
return mac;
}
static const struct ethtool_ops qtnf_ethtool_ops = {
.get_drvinfo = cfg80211_get_drvinfo,
};
int qtnf_core_net_attach(struct qtnf_wmac *mac, struct qtnf_vif *vif,
const char *name, unsigned char name_assign_type)
{
struct wiphy *wiphy = priv_to_wiphy(mac);
struct net_device *dev;
void *qdev_vif;
int ret;
dev = alloc_netdev_mqs(sizeof(struct qtnf_vif *), name,
name_assign_type, ether_setup, 1, 1);
if (!dev) {
vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
return -ENOMEM;
}
vif->netdev = dev;
dev->netdev_ops = &qtnf_netdev_ops;
dev->needs_free_netdev = true;
dev_net_set(dev, wiphy_net(wiphy));
dev->ieee80211_ptr = &vif->wdev;
ether_addr_copy(dev->dev_addr, vif->mac_addr);
SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
dev->watchdog_timeo = QTNF_DEF_WDOG_TIMEOUT;
dev->tx_queue_len = 100;
dev->ethtool_ops = &qtnf_ethtool_ops;
qdev_vif = netdev_priv(dev);
*((void **)qdev_vif) = vif;
SET_NETDEV_DEV(dev, mac->bus->dev);
ret = register_netdevice(dev);
if (ret) {
free_netdev(dev);
vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
}
return ret;
}
static void qtnf_core_mac_detach(struct qtnf_bus *bus, unsigned int macid)
{
struct qtnf_wmac *mac;
struct wiphy *wiphy;
struct qtnf_vif *vif;
unsigned int i;
enum nl80211_band band;
mac = bus->mac[macid];
if (!mac)
return;
wiphy = priv_to_wiphy(mac);
for (i = 0; i < QTNF_MAX_INTF; i++) {
vif = &mac->iflist[i];
rtnl_lock();
if (vif->netdev &&
vif->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED) {
qtnf_virtual_intf_cleanup(vif->netdev);
qtnf_del_virtual_intf(wiphy, &vif->wdev);
}
rtnl_unlock();
qtnf_sta_list_free(&vif->sta_list);
free_percpu(vif->stats64);
}
if (mac->wiphy_registered)
wiphy_unregister(wiphy);
for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; ++band) {
if (!wiphy->bands[band])
continue;
kfree(wiphy->bands[band]->channels);
wiphy->bands[band]->n_channels = 0;
kfree(wiphy->bands[band]);
wiphy->bands[band] = NULL;
}
qtnf_mac_iface_comb_free(mac);
qtnf_mac_ext_caps_free(mac);
kfree(mac->macinfo.wowlan);
wiphy_free(wiphy);
bus->mac[macid] = NULL;
}
static int qtnf_core_mac_attach(struct qtnf_bus *bus, unsigned int macid)
{
struct qtnf_wmac *mac;
struct qtnf_vif *vif;
int ret;
if (!(bus->hw_info.mac_bitmap & BIT(macid))) {
pr_info("MAC%u is not active in FW\n", macid);
return 0;
}
mac = qtnf_core_mac_alloc(bus, macid);
if (IS_ERR(mac)) {
pr_err("MAC%u allocation failed\n", macid);
return PTR_ERR(mac);
}
ret = qtnf_cmd_get_mac_info(mac);
if (ret) {
pr_err("MAC%u: failed to get info\n", macid);
goto error;
}
vif = qtnf_mac_get_base_vif(mac);
if (!vif) {
pr_err("MAC%u: primary VIF is not ready\n", macid);
ret = -EFAULT;
goto error;
}
ret = qtnf_cmd_send_add_intf(vif, vif->wdev.iftype, vif->mac_addr);
if (ret) {
pr_err("MAC%u: failed to add VIF\n", macid);
goto error;
}
ret = qtnf_cmd_send_get_phy_params(mac);
if (ret) {
pr_err("MAC%u: failed to get PHY settings\n", macid);
goto error;
}
ret = qtnf_mac_init_bands(mac);
if (ret) {
pr_err("MAC%u: failed to init bands\n", macid);
goto error;
}
ret = qtnf_wiphy_register(&bus->hw_info, mac);
if (ret) {
pr_err("MAC%u: wiphy registration failed\n", macid);
goto error;
}
mac->wiphy_registered = 1;
rtnl_lock();
ret = qtnf_core_net_attach(mac, vif, "wlan%d", NET_NAME_ENUM);
rtnl_unlock();
if (ret) {
pr_err("MAC%u: failed to attach netdev\n", macid);
vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
vif->netdev = NULL;
goto error;
}
pr_debug("MAC%u initialized\n", macid);
return 0;
error:
qtnf_core_mac_detach(bus, macid);
return ret;
}
int qtnf_core_attach(struct qtnf_bus *bus)
{
unsigned int i;
int ret;
qtnf_trans_init(bus);
bus->fw_state = QTNF_FW_STATE_BOOT_DONE;
qtnf_bus_data_rx_start(bus);
bus->workqueue = alloc_ordered_workqueue("QTNF_BUS", 0);
if (!bus->workqueue) {
pr_err("failed to alloc main workqueue\n");
ret = -ENOMEM;
goto error;
}
INIT_WORK(&bus->event_work, qtnf_event_work_handler);
ret = qtnf_cmd_send_init_fw(bus);
if (ret) {
pr_err("failed to init FW: %d\n", ret);
goto error;
}
bus->fw_state = QTNF_FW_STATE_ACTIVE;
ret = qtnf_cmd_get_hw_info(bus);
if (ret) {
pr_err("failed to get HW info: %d\n", ret);
goto error;
}
if (bus->hw_info.ql_proto_ver != QLINK_PROTO_VER) {
pr_err("qlink version mismatch %u != %u\n",
QLINK_PROTO_VER, bus->hw_info.ql_proto_ver);
ret = -EPROTONOSUPPORT;
goto error;
}
if (bus->hw_info.num_mac > QTNF_MAX_MAC) {
pr_err("no support for number of MACs=%u\n",
bus->hw_info.num_mac);
ret = -ERANGE;
goto error;
}
for (i = 0; i < bus->hw_info.num_mac; i++) {
ret = qtnf_core_mac_attach(bus, i);
if (ret) {
pr_err("MAC%u: attach failed: %d\n", i, ret);
goto error;
}
}
return 0;
error:
qtnf_core_detach(bus);
return ret;
}
EXPORT_SYMBOL_GPL(qtnf_core_attach);
void qtnf_core_detach(struct qtnf_bus *bus)
{
unsigned int macid;
qtnf_bus_data_rx_stop(bus);
for (macid = 0; macid < QTNF_MAX_MAC; macid++)
qtnf_core_mac_detach(bus, macid);
if (bus->fw_state == QTNF_FW_STATE_ACTIVE)
qtnf_cmd_send_deinit_fw(bus);
bus->fw_state = QTNF_FW_STATE_DETACHED;
if (bus->workqueue) {
flush_workqueue(bus->workqueue);
destroy_workqueue(bus->workqueue);
}
kfree(bus->hw_info.rd);
bus->hw_info.rd = NULL;
qtnf_trans_free(bus);
}
EXPORT_SYMBOL_GPL(qtnf_core_detach);
static inline int qtnf_is_frame_meta_magic_valid(struct qtnf_frame_meta_info *m)
{
return m->magic_s == 0xAB && m->magic_e == 0xBA;
}
struct net_device *qtnf_classify_skb(struct qtnf_bus *bus, struct sk_buff *skb)
{
struct qtnf_frame_meta_info *meta;
struct net_device *ndev = NULL;
struct qtnf_wmac *mac;
struct qtnf_vif *vif;
meta = (struct qtnf_frame_meta_info *)
(skb_tail_pointer(skb) - sizeof(*meta));
if (unlikely(!qtnf_is_frame_meta_magic_valid(meta))) {
pr_err_ratelimited("invalid magic 0x%x:0x%x\n",
meta->magic_s, meta->magic_e);
goto out;
}
if (unlikely(meta->macid >= QTNF_MAX_MAC)) {
pr_err_ratelimited("invalid mac(%u)\n", meta->macid);
goto out;
}
if (unlikely(meta->ifidx >= QTNF_MAX_INTF)) {
pr_err_ratelimited("invalid vif(%u)\n", meta->ifidx);
goto out;
}
mac = bus->mac[meta->macid];
if (unlikely(!mac)) {
pr_err_ratelimited("mac(%d) does not exist\n", meta->macid);
goto out;
}
vif = &mac->iflist[meta->ifidx];
if (unlikely(vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)) {
pr_err_ratelimited("vif(%u) does not exists\n", meta->ifidx);
goto out;
}
ndev = vif->netdev;
if (unlikely(!ndev)) {
pr_err_ratelimited("netdev for wlan%u.%u does not exists\n",
meta->macid, meta->ifidx);
goto out;
}
__skb_trim(skb, skb->len - sizeof(*meta));
out:
return ndev;
}
EXPORT_SYMBOL_GPL(qtnf_classify_skb);
void qtnf_wake_all_queues(struct net_device *ndev)
{
struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
struct qtnf_wmac *mac;
struct qtnf_bus *bus;
int macid;
int i;
if (unlikely(!vif || !vif->mac || !vif->mac->bus))
return;
bus = vif->mac->bus;
for (macid = 0; macid < QTNF_MAX_MAC; macid++) {
if (!(bus->hw_info.mac_bitmap & BIT(macid)))
continue;
mac = bus->mac[macid];
for (i = 0; i < QTNF_MAX_INTF; i++) {
vif = &mac->iflist[i];
if (vif->netdev && netif_queue_stopped(vif->netdev))
netif_tx_wake_all_queues(vif->netdev);
}
}
}
EXPORT_SYMBOL_GPL(qtnf_wake_all_queues);
void qtnf_update_rx_stats(struct net_device *ndev, const struct sk_buff *skb)
{
struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
struct pcpu_sw_netstats *stats64;
if (unlikely(!vif || !vif->stats64)) {
ndev->stats.rx_packets++;
ndev->stats.rx_bytes += skb->len;
return;
}
stats64 = this_cpu_ptr(vif->stats64);
u64_stats_update_begin(&stats64->syncp);
stats64->rx_packets++;
stats64->rx_bytes += skb->len;
u64_stats_update_end(&stats64->syncp);
}
EXPORT_SYMBOL_GPL(qtnf_update_rx_stats);
void qtnf_update_tx_stats(struct net_device *ndev, const struct sk_buff *skb)
{
struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
struct pcpu_sw_netstats *stats64;
if (unlikely(!vif || !vif->stats64)) {
ndev->stats.tx_packets++;
ndev->stats.tx_bytes += skb->len;
return;
}
stats64 = this_cpu_ptr(vif->stats64);
u64_stats_update_begin(&stats64->syncp);
stats64->tx_packets++;
stats64->tx_bytes += skb->len;
u64_stats_update_end(&stats64->syncp);
}
EXPORT_SYMBOL_GPL(qtnf_update_tx_stats);
MODULE_AUTHOR("Quantenna Communications");
MODULE_DESCRIPTION("Quantenna 802.11 wireless LAN FullMAC driver.");
MODULE_LICENSE("GPL");
@@ -0,0 +1,178 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _QTN_FMAC_CORE_H_
#define _QTN_FMAC_CORE_H_
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/semaphore.h>
#include <linux/ip.h>
#include <linux/skbuff.h>
#include <linux/if_arp.h>
#include <linux/etherdevice.h>
#include <net/sock.h>
#include <net/lib80211.h>
#include <net/cfg80211.h>
#include <linux/vmalloc.h>
#include <linux/firmware.h>
#include <linux/ctype.h>
#include <linux/workqueue.h>
#include <linux/slab.h>
#include "qlink.h"
#include "trans.h"
#undef pr_fmt
#define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
#define QTNF_MAX_VSIE_LEN 255
#define QTNF_MAX_INTF 8
#define QTNF_MAX_EVENT_QUEUE_LEN 255
#define QTNF_SCAN_TIMEOUT_SEC 15
#define QTNF_DEF_BSS_PRIORITY 0
#define QTNF_DEF_WDOG_TIMEOUT 5
#define QTNF_TX_TIMEOUT_TRSHLD 100
extern const struct net_device_ops qtnf_netdev_ops;
struct qtnf_bus;
struct qtnf_vif;
struct qtnf_sta_node {
struct list_head list;
u8 mac_addr[ETH_ALEN];
};
struct qtnf_sta_list {
struct list_head head;
atomic_t size;
};
enum qtnf_sta_state {
QTNF_STA_DISCONNECTED,
QTNF_STA_CONNECTING,
QTNF_STA_CONNECTED
};
struct qtnf_vif {
struct wireless_dev wdev;
u8 bssid[ETH_ALEN];
u8 mac_addr[ETH_ALEN];
u8 vifid;
u8 bss_priority;
u8 bss_status;
enum qtnf_sta_state sta_state;
u16 mgmt_frames_bitmask;
struct net_device *netdev;
struct qtnf_wmac *mac;
struct work_struct reset_work;
struct qtnf_sta_list sta_list;
unsigned long cons_tx_timeout_cnt;
int generation;
struct pcpu_sw_netstats __percpu *stats64;
};
struct qtnf_mac_info {
u8 bands_cap;
u8 dev_mac[ETH_ALEN];
u8 num_tx_chain;
u8 num_rx_chain;
u16 max_ap_assoc_sta;
u32 frag_thr;
u32 rts_thr;
u8 lretry_limit;
u8 sretry_limit;
u8 coverage_class;
u8 radar_detect_widths;
u32 max_acl_mac_addrs;
struct ieee80211_ht_cap ht_cap_mod_mask;
struct ieee80211_vht_cap vht_cap_mod_mask;
struct ieee80211_iface_combination *if_comb;
size_t n_if_comb;
u8 *extended_capabilities;
u8 *extended_capabilities_mask;
u8 extended_capabilities_len;
struct wiphy_wowlan_support *wowlan;
};
struct qtnf_chan_stats {
u32 chan_num;
u32 cca_tx;
u32 cca_rx;
u32 cca_busy;
u32 cca_try;
s8 chan_noise;
};
struct qtnf_wmac {
u8 macid;
u8 wiphy_registered;
u8 macaddr[ETH_ALEN];
struct qtnf_bus *bus;
struct qtnf_mac_info macinfo;
struct qtnf_vif iflist[QTNF_MAX_INTF];
struct cfg80211_scan_request *scan_req;
struct mutex mac_lock; /* lock during wmac speicific ops */
struct delayed_work scan_timeout;
};
struct qtnf_hw_info {
u16 ql_proto_ver;
u8 num_mac;
u8 mac_bitmap;
u32 fw_ver;
u32 hw_capab;
struct ieee80211_regdomain *rd;
u8 total_tx_chain;
u8 total_rx_chain;
char fw_version[ETHTOOL_FWVERS_LEN];
u32 hw_version;
u8 max_scan_ssids;
};
struct qtnf_vif *qtnf_mac_get_free_vif(struct qtnf_wmac *mac);
struct qtnf_vif *qtnf_mac_get_base_vif(struct qtnf_wmac *mac);
void qtnf_mac_iface_comb_free(struct qtnf_wmac *mac);
void qtnf_mac_ext_caps_free(struct qtnf_wmac *mac);
struct wiphy *qtnf_wiphy_allocate(struct qtnf_bus *bus);
int qtnf_core_net_attach(struct qtnf_wmac *mac, struct qtnf_vif *priv,
const char *name, unsigned char name_assign_type);
void qtnf_main_work_queue(struct work_struct *work);
int qtnf_cmd_send_update_phy_params(struct qtnf_wmac *mac, u32 changed);
int qtnf_cmd_send_get_phy_params(struct qtnf_wmac *mac);
struct qtnf_wmac *qtnf_core_get_mac(const struct qtnf_bus *bus, u8 macid);
struct net_device *qtnf_classify_skb(struct qtnf_bus *bus, struct sk_buff *skb);
void qtnf_wake_all_queues(struct net_device *ndev);
void qtnf_update_rx_stats(struct net_device *ndev, const struct sk_buff *skb);
void qtnf_update_tx_stats(struct net_device *ndev, const struct sk_buff *skb);
void qtnf_virtual_intf_cleanup(struct net_device *ndev);
void qtnf_netdev_updown(struct net_device *ndev, bool up);
void qtnf_scan_done(struct qtnf_wmac *mac, bool aborted);
static inline struct qtnf_vif *qtnf_netdev_get_priv(struct net_device *dev)
{
return *((void **)netdev_priv(dev));
}
#endif /* _QTN_FMAC_CORE_H_ */
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "debug.h"
#undef pr_fmt
#define pr_fmt(fmt) "qtnfmac dbg: %s: " fmt, __func__
void qtnf_debugfs_init(struct qtnf_bus *bus, const char *name)
{
bus->dbg_dir = debugfs_create_dir(name, NULL);
if (IS_ERR_OR_NULL(bus->dbg_dir)) {
pr_warn("failed to create debugfs root dir\n");
bus->dbg_dir = NULL;
}
}
void qtnf_debugfs_remove(struct qtnf_bus *bus)
{
debugfs_remove_recursive(bus->dbg_dir);
bus->dbg_dir = NULL;
}
void qtnf_debugfs_add_entry(struct qtnf_bus *bus, const char *name,
int (*fn)(struct seq_file *seq, void *data))
{
struct dentry *entry;
entry = debugfs_create_devm_seqfile(bus->dev, name, bus->dbg_dir, fn);
if (IS_ERR_OR_NULL(entry))
pr_warn("failed to add entry (%s)\n", name);
}
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _QTN_FMAC_DEBUG_H_
#define _QTN_FMAC_DEBUG_H_
#include <linux/debugfs.h>
#include "core.h"
#include "bus.h"
#ifdef CONFIG_DEBUG_FS
void qtnf_debugfs_init(struct qtnf_bus *bus, const char *name);
void qtnf_debugfs_remove(struct qtnf_bus *bus);
void qtnf_debugfs_add_entry(struct qtnf_bus *bus, const char *name,
int (*fn)(struct seq_file *seq, void *data));
#else
static inline void qtnf_debugfs_init(struct qtnf_bus *bus, const char *name)
{
}
static inline void qtnf_debugfs_remove(struct qtnf_bus *bus)
{
}
static inline void
qtnf_debugfs_add_entry(struct qtnf_bus *bus, const char *name,
int (*fn)(struct seq_file *seq, void *data))
{
}
#endif /* CONFIG_DEBUG_FS */
#endif /* _QTN_FMAC_DEBUG_H_ */
@@ -0,0 +1,584 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include "cfg80211.h"
#include "core.h"
#include "qlink.h"
#include "bus.h"
#include "trans.h"
#include "util.h"
#include "event.h"
#include "qlink_util.h"
static int
qtnf_event_handle_sta_assoc(struct qtnf_wmac *mac, struct qtnf_vif *vif,
const struct qlink_event_sta_assoc *sta_assoc,
u16 len)
{
const u8 *sta_addr;
u16 frame_control;
struct station_info *sinfo;
size_t payload_len;
u16 tlv_type;
u16 tlv_value_len;
size_t tlv_full_len;
const struct qlink_tlv_hdr *tlv;
int ret = 0;
if (unlikely(len < sizeof(*sta_assoc))) {
pr_err("VIF%u.%u: payload is too short (%u < %zu)\n",
mac->macid, vif->vifid, len, sizeof(*sta_assoc));
return -EINVAL;
}
if (vif->wdev.iftype != NL80211_IFTYPE_AP) {
pr_err("VIF%u.%u: STA_ASSOC event when not in AP mode\n",
mac->macid, vif->vifid);
return -EPROTO;
}
sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
if (!sinfo)
return -ENOMEM;
sta_addr = sta_assoc->sta_addr;
frame_control = le16_to_cpu(sta_assoc->frame_control);
pr_debug("VIF%u.%u: MAC:%pM FC:%x\n", mac->macid, vif->vifid, sta_addr,
frame_control);
qtnf_sta_list_add(vif, sta_addr);
sinfo->assoc_req_ies = NULL;
sinfo->assoc_req_ies_len = 0;
sinfo->generation = vif->generation;
payload_len = len - sizeof(*sta_assoc);
tlv = (const struct qlink_tlv_hdr *)sta_assoc->ies;
while (payload_len >= sizeof(*tlv)) {
tlv_type = le16_to_cpu(tlv->type);
tlv_value_len = le16_to_cpu(tlv->len);
tlv_full_len = tlv_value_len + sizeof(struct qlink_tlv_hdr);
if (tlv_full_len > payload_len) {
ret = -EINVAL;
goto out;
}
if (tlv_type == QTN_TLV_ID_IE_SET) {
const struct qlink_tlv_ie_set *ie_set;
unsigned int ie_len;
if (payload_len < sizeof(*ie_set)) {
ret = -EINVAL;
goto out;
}
ie_set = (const struct qlink_tlv_ie_set *)tlv;
ie_len = tlv_value_len -
(sizeof(*ie_set) - sizeof(ie_set->hdr));
if (ie_set->type == QLINK_IE_SET_ASSOC_REQ && ie_len) {
sinfo->assoc_req_ies = ie_set->ie_data;
sinfo->assoc_req_ies_len = ie_len;
}
}
payload_len -= tlv_full_len;
tlv = (struct qlink_tlv_hdr *)(tlv->val + tlv_value_len);
}
if (payload_len) {
ret = -EINVAL;
goto out;
}
cfg80211_new_sta(vif->netdev, sta_assoc->sta_addr, sinfo,
GFP_KERNEL);
out:
kfree(sinfo);
return ret;
}
static int
qtnf_event_handle_sta_deauth(struct qtnf_wmac *mac, struct qtnf_vif *vif,
const struct qlink_event_sta_deauth *sta_deauth,
u16 len)
{
const u8 *sta_addr;
u16 reason;
if (unlikely(len < sizeof(*sta_deauth))) {
pr_err("VIF%u.%u: payload is too short (%u < %zu)\n",
mac->macid, vif->vifid, len,
sizeof(struct qlink_event_sta_deauth));
return -EINVAL;
}
if (vif->wdev.iftype != NL80211_IFTYPE_AP) {
pr_err("VIF%u.%u: STA_DEAUTH event when not in AP mode\n",
mac->macid, vif->vifid);
return -EPROTO;
}
sta_addr = sta_deauth->sta_addr;
reason = le16_to_cpu(sta_deauth->reason);
pr_debug("VIF%u.%u: MAC:%pM reason:%x\n", mac->macid, vif->vifid,
sta_addr, reason);
if (qtnf_sta_list_del(vif, sta_addr))
cfg80211_del_sta(vif->netdev, sta_deauth->sta_addr,
GFP_KERNEL);
return 0;
}
static int
qtnf_event_handle_bss_join(struct qtnf_vif *vif,
const struct qlink_event_bss_join *join_info,
u16 len)
{
if (unlikely(len < sizeof(*join_info))) {
pr_err("VIF%u.%u: payload is too short (%u < %zu)\n",
vif->mac->macid, vif->vifid, len,
sizeof(struct qlink_event_bss_join));
return -EINVAL;
}
if (vif->wdev.iftype != NL80211_IFTYPE_STATION) {
pr_err("VIF%u.%u: BSS_JOIN event when not in STA mode\n",
vif->mac->macid, vif->vifid);
return -EPROTO;
}
if (vif->sta_state != QTNF_STA_CONNECTING) {
pr_err("VIF%u.%u: BSS_JOIN event when STA is not connecting\n",
vif->mac->macid, vif->vifid);
return -EPROTO;
}
pr_debug("VIF%u.%u: BSSID:%pM\n", vif->mac->macid, vif->vifid,
join_info->bssid);
cfg80211_connect_result(vif->netdev, join_info->bssid, NULL, 0, NULL,
0, le16_to_cpu(join_info->status), GFP_KERNEL);
if (le16_to_cpu(join_info->status) == WLAN_STATUS_SUCCESS) {
vif->sta_state = QTNF_STA_CONNECTED;
netif_carrier_on(vif->netdev);
} else {
vif->sta_state = QTNF_STA_DISCONNECTED;
}
return 0;
}
static int
qtnf_event_handle_bss_leave(struct qtnf_vif *vif,
const struct qlink_event_bss_leave *leave_info,
u16 len)
{
if (unlikely(len < sizeof(*leave_info))) {
pr_err("VIF%u.%u: payload is too short (%u < %zu)\n",
vif->mac->macid, vif->vifid, len,
sizeof(struct qlink_event_bss_leave));
return -EINVAL;
}
if (vif->wdev.iftype != NL80211_IFTYPE_STATION) {
pr_err("VIF%u.%u: BSS_LEAVE event when not in STA mode\n",
vif->mac->macid, vif->vifid);
return -EPROTO;
}
if (vif->sta_state != QTNF_STA_CONNECTED)
pr_warn("VIF%u.%u: BSS_LEAVE event when STA is not connected\n",
vif->mac->macid, vif->vifid);
pr_debug("VIF%u.%u: disconnected\n", vif->mac->macid, vif->vifid);
cfg80211_disconnected(vif->netdev, le16_to_cpu(leave_info->reason),
NULL, 0, 0, GFP_KERNEL);
vif->sta_state = QTNF_STA_DISCONNECTED;
netif_carrier_off(vif->netdev);
return 0;
}
static int
qtnf_event_handle_mgmt_received(struct qtnf_vif *vif,
const struct qlink_event_rxmgmt *rxmgmt,
u16 len)
{
const size_t min_len = sizeof(*rxmgmt) +
sizeof(struct ieee80211_hdr_3addr);
const struct ieee80211_hdr_3addr *frame = (void *)rxmgmt->frame_data;
const u16 frame_len = len - sizeof(*rxmgmt);
enum nl80211_rxmgmt_flags flags = 0;
if (unlikely(len < min_len)) {
pr_err("VIF%u.%u: payload is too short (%u < %zu)\n",
vif->mac->macid, vif->vifid, len, min_len);
return -EINVAL;
}
if (le32_to_cpu(rxmgmt->flags) & QLINK_RXMGMT_FLAG_ANSWERED)
flags |= NL80211_RXMGMT_FLAG_ANSWERED;
pr_debug("%s LEN:%u FC:%.4X SA:%pM\n", vif->netdev->name, frame_len,
le16_to_cpu(frame->frame_control), frame->addr2);
cfg80211_rx_mgmt(&vif->wdev, le32_to_cpu(rxmgmt->freq), rxmgmt->sig_dbm,
rxmgmt->frame_data, frame_len, flags);
return 0;
}
static int
qtnf_event_handle_scan_results(struct qtnf_vif *vif,
const struct qlink_event_scan_result *sr,
u16 len)
{
struct cfg80211_bss *bss;
struct ieee80211_channel *channel;
struct wiphy *wiphy = priv_to_wiphy(vif->mac);
enum cfg80211_bss_frame_type frame_type = CFG80211_BSS_FTYPE_UNKNOWN;
size_t payload_len;
u16 tlv_type;
u16 tlv_value_len;
size_t tlv_full_len;
const struct qlink_tlv_hdr *tlv;
const u8 *ies = NULL;
size_t ies_len = 0;
if (len < sizeof(*sr)) {
pr_err("VIF%u.%u: payload is too short\n", vif->mac->macid,
vif->vifid);
return -EINVAL;
}
channel = ieee80211_get_channel(wiphy, le16_to_cpu(sr->freq));
if (!channel) {
pr_err("VIF%u.%u: channel at %u MHz not found\n",
vif->mac->macid, vif->vifid, le16_to_cpu(sr->freq));
return -EINVAL;
}
payload_len = len - sizeof(*sr);
tlv = (struct qlink_tlv_hdr *)sr->payload;
while (payload_len >= sizeof(struct qlink_tlv_hdr)) {
tlv_type = le16_to_cpu(tlv->type);
tlv_value_len = le16_to_cpu(tlv->len);
tlv_full_len = tlv_value_len + sizeof(struct qlink_tlv_hdr);
if (tlv_full_len > payload_len)
return -EINVAL;
if (tlv_type == QTN_TLV_ID_IE_SET) {
const struct qlink_tlv_ie_set *ie_set;
unsigned int ie_len;
if (payload_len < sizeof(*ie_set))
return -EINVAL;
ie_set = (const struct qlink_tlv_ie_set *)tlv;
ie_len = tlv_value_len -
(sizeof(*ie_set) - sizeof(ie_set->hdr));
switch (ie_set->type) {
case QLINK_IE_SET_BEACON_IES:
frame_type = CFG80211_BSS_FTYPE_BEACON;
break;
case QLINK_IE_SET_PROBE_RESP_IES:
frame_type = CFG80211_BSS_FTYPE_PRESP;
break;
default:
frame_type = CFG80211_BSS_FTYPE_UNKNOWN;
}
if (ie_len) {
ies = ie_set->ie_data;
ies_len = ie_len;
}
}
payload_len -= tlv_full_len;
tlv = (struct qlink_tlv_hdr *)(tlv->val + tlv_value_len);
}
if (payload_len)
return -EINVAL;
bss = cfg80211_inform_bss(wiphy, channel, frame_type,
sr->bssid, get_unaligned_le64(&sr->tsf),
le16_to_cpu(sr->capab),
le16_to_cpu(sr->bintval), ies, ies_len,
DBM_TO_MBM(sr->sig_dbm), GFP_KERNEL);
if (!bss)
return -ENOMEM;
cfg80211_put_bss(wiphy, bss);
return 0;
}
static int
qtnf_event_handle_scan_complete(struct qtnf_wmac *mac,
const struct qlink_event_scan_complete *status,
u16 len)
{
if (len < sizeof(*status)) {
pr_err("MAC%u: payload is too short\n", mac->macid);
return -EINVAL;
}
qtnf_scan_done(mac, le32_to_cpu(status->flags) & QLINK_SCAN_ABORTED);
return 0;
}
static int
qtnf_event_handle_freq_change(struct qtnf_wmac *mac,
const struct qlink_event_freq_change *data,
u16 len)
{
struct wiphy *wiphy = priv_to_wiphy(mac);
struct cfg80211_chan_def chandef;
struct qtnf_vif *vif;
int i;
if (len < sizeof(*data)) {
pr_err("MAC%u: payload is too short\n", mac->macid);
return -EINVAL;
}
if (!wiphy->registered)
return 0;
qlink_chandef_q2cfg(wiphy, &data->chan, &chandef);
if (!cfg80211_chandef_valid(&chandef)) {
pr_err("MAC%u: bad channel freq=%u cf1=%u cf2=%u bw=%u\n",
mac->macid, chandef.chan->center_freq,
chandef.center_freq1, chandef.center_freq2,
chandef.width);
return -EINVAL;
}
pr_debug("MAC%d: new channel ieee=%u freq1=%u freq2=%u bw=%u\n",
mac->macid, chandef.chan->hw_value, chandef.center_freq1,
chandef.center_freq2, chandef.width);
for (i = 0; i < QTNF_MAX_INTF; i++) {
vif = &mac->iflist[i];
if (vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)
continue;
if (vif->netdev) {
mutex_lock(&vif->wdev.mtx);
cfg80211_ch_switch_notify(vif->netdev, &chandef);
mutex_unlock(&vif->wdev.mtx);
}
}
return 0;
}
static int qtnf_event_handle_radar(struct qtnf_vif *vif,
const struct qlink_event_radar *ev,
u16 len)
{
struct wiphy *wiphy = priv_to_wiphy(vif->mac);
struct cfg80211_chan_def chandef;
if (len < sizeof(*ev)) {
pr_err("MAC%u: payload is too short\n", vif->mac->macid);
return -EINVAL;
}
if (!wiphy->registered || !vif->netdev)
return 0;
qlink_chandef_q2cfg(wiphy, &ev->chan, &chandef);
if (!cfg80211_chandef_valid(&chandef)) {
pr_err("MAC%u: bad channel f1=%u f2=%u bw=%u\n",
vif->mac->macid,
chandef.center_freq1, chandef.center_freq2,
chandef.width);
return -EINVAL;
}
pr_info("%s: radar event=%u f1=%u f2=%u bw=%u\n",
vif->netdev->name, ev->event,
chandef.center_freq1, chandef.center_freq2,
chandef.width);
switch (ev->event) {
case QLINK_RADAR_DETECTED:
cfg80211_radar_event(wiphy, &chandef, GFP_KERNEL);
break;
case QLINK_RADAR_CAC_FINISHED:
if (!vif->wdev.cac_started)
break;
cfg80211_cac_event(vif->netdev, &chandef,
NL80211_RADAR_CAC_FINISHED, GFP_KERNEL);
break;
case QLINK_RADAR_CAC_ABORTED:
if (!vif->wdev.cac_started)
break;
cfg80211_cac_event(vif->netdev, &chandef,
NL80211_RADAR_CAC_ABORTED, GFP_KERNEL);
break;
case QLINK_RADAR_CAC_STARTED:
if (vif->wdev.cac_started)
break;
if (!wiphy_ext_feature_isset(wiphy,
NL80211_EXT_FEATURE_DFS_OFFLOAD))
break;
cfg80211_cac_event(vif->netdev, &chandef,
NL80211_RADAR_CAC_STARTED, GFP_KERNEL);
break;
default:
pr_warn("%s: unhandled radar event %u\n",
vif->netdev->name, ev->event);
break;
}
return 0;
}
static int qtnf_event_parse(struct qtnf_wmac *mac,
const struct sk_buff *event_skb)
{
const struct qlink_event *event;
struct qtnf_vif *vif = NULL;
int ret = -1;
u16 event_id;
u16 event_len;
event = (const struct qlink_event *)event_skb->data;
event_id = le16_to_cpu(event->event_id);
event_len = le16_to_cpu(event->mhdr.len);
if (likely(event->vifid < QTNF_MAX_INTF)) {
vif = &mac->iflist[event->vifid];
} else {
pr_err("invalid vif(%u)\n", event->vifid);
return -EINVAL;
}
switch (event_id) {
case QLINK_EVENT_STA_ASSOCIATED:
ret = qtnf_event_handle_sta_assoc(mac, vif, (const void *)event,
event_len);
break;
case QLINK_EVENT_STA_DEAUTH:
ret = qtnf_event_handle_sta_deauth(mac, vif,
(const void *)event,
event_len);
break;
case QLINK_EVENT_MGMT_RECEIVED:
ret = qtnf_event_handle_mgmt_received(vif, (const void *)event,
event_len);
break;
case QLINK_EVENT_SCAN_RESULTS:
ret = qtnf_event_handle_scan_results(vif, (const void *)event,
event_len);
break;
case QLINK_EVENT_SCAN_COMPLETE:
ret = qtnf_event_handle_scan_complete(mac, (const void *)event,
event_len);
break;
case QLINK_EVENT_BSS_JOIN:
ret = qtnf_event_handle_bss_join(vif, (const void *)event,
event_len);
break;
case QLINK_EVENT_BSS_LEAVE:
ret = qtnf_event_handle_bss_leave(vif, (const void *)event,
event_len);
break;
case QLINK_EVENT_FREQ_CHANGE:
ret = qtnf_event_handle_freq_change(mac, (const void *)event,
event_len);
break;
case QLINK_EVENT_RADAR:
ret = qtnf_event_handle_radar(vif, (const void *)event,
event_len);
break;
default:
pr_warn("unknown event type: %x\n", event_id);
break;
}
return ret;
}
static int qtnf_event_process_skb(struct qtnf_bus *bus,
const struct sk_buff *skb)
{
const struct qlink_event *event;
struct qtnf_wmac *mac;
int res;
if (unlikely(!skb || skb->len < sizeof(*event))) {
pr_err("invalid event buffer\n");
return -EINVAL;
}
event = (struct qlink_event *)skb->data;
mac = qtnf_core_get_mac(bus, event->macid);
pr_debug("new event id:%x len:%u mac:%u vif:%u\n",
le16_to_cpu(event->event_id), le16_to_cpu(event->mhdr.len),
event->macid, event->vifid);
if (unlikely(!mac))
return -ENXIO;
rtnl_lock();
res = qtnf_event_parse(mac, skb);
rtnl_unlock();
return res;
}
void qtnf_event_work_handler(struct work_struct *work)
{
struct qtnf_bus *bus = container_of(work, struct qtnf_bus, event_work);
struct sk_buff_head *event_queue = &bus->trans.event_queue;
struct sk_buff *current_event_skb = skb_dequeue(event_queue);
while (current_event_skb) {
qtnf_event_process_skb(bus, current_event_skb);
dev_kfree_skb_any(current_event_skb);
current_event_skb = skb_dequeue(event_queue);
}
}
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _QTN_FMAC_EVENT_H_
#define _QTN_FMAC_EVENT_H_
#include <linux/kernel.h>
#include <linux/module.h>
#include "qlink.h"
void qtnf_event_work_handler(struct work_struct *work);
#endif /* _QTN_FMAC_EVENT_H_ */
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _QTN_FMAC_PCIE_H_
#define _QTN_FMAC_PCIE_H_
#include <linux/dma-mapping.h>
#include <linux/io.h>
#include "pcie_regs_pearl.h"
#include "pcie_ipc.h"
#include "shm_ipc.h"
struct bus;
struct qtnf_pcie_bus_priv {
struct pci_dev *pdev;
/* lock for irq configuration changes */
spinlock_t irq_lock;
/* lock for tx reclaim operations */
spinlock_t tx_reclaim_lock;
/* lock for tx0 operations */
spinlock_t tx0_lock;
u8 msi_enabled;
u8 tx_stopped;
int mps;
struct workqueue_struct *workqueue;
struct tasklet_struct reclaim_tq;
void __iomem *sysctl_bar;
void __iomem *epmem_bar;
void __iomem *dmareg_bar;
struct qtnf_shm_ipc shm_ipc_ep_in;
struct qtnf_shm_ipc shm_ipc_ep_out;
struct qtnf_pcie_bda __iomem *bda;
void __iomem *pcie_reg_base;
u16 tx_bd_num;
u16 rx_bd_num;
struct sk_buff **tx_skb;
struct sk_buff **rx_skb;
struct qtnf_tx_bd *tx_bd_vbase;
dma_addr_t tx_bd_pbase;
struct qtnf_rx_bd *rx_bd_vbase;
dma_addr_t rx_bd_pbase;
dma_addr_t bd_table_paddr;
void *bd_table_vaddr;
u32 bd_table_len;
u32 rx_bd_w_index;
u32 rx_bd_r_index;
u32 tx_bd_w_index;
u32 tx_bd_r_index;
u32 pcie_irq_mask;
/* diagnostics stats */
u32 pcie_irq_count;
u32 pcie_irq_rx_count;
u32 pcie_irq_tx_count;
u32 pcie_irq_uf_count;
u32 tx_full_count;
u32 tx_done_count;
u32 tx_reclaim_done;
u32 tx_reclaim_req;
};
#endif /* _QTN_FMAC_PCIE_H_ */
@@ -0,0 +1,158 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _QTN_FMAC_PCIE_IPC_H_
#define _QTN_FMAC_PCIE_IPC_H_
#include <linux/types.h>
#include "shm_ipc_defs.h"
/* bitmap for EP status and flags: updated by EP, read by RC */
#define QTN_EP_HAS_UBOOT BIT(0)
#define QTN_EP_HAS_FIRMWARE BIT(1)
#define QTN_EP_REQ_UBOOT BIT(2)
#define QTN_EP_REQ_FIRMWARE BIT(3)
#define QTN_EP_ERROR_UBOOT BIT(4)
#define QTN_EP_ERROR_FIRMWARE BIT(5)
#define QTN_EP_FW_LOADRDY BIT(8)
#define QTN_EP_FW_SYNC BIT(9)
#define QTN_EP_FW_RETRY BIT(10)
#define QTN_EP_FW_QLINK_DONE BIT(15)
#define QTN_EP_FW_DONE BIT(16)
/* bitmap for RC status and flags: updated by RC, read by EP */
#define QTN_RC_PCIE_LINK BIT(0)
#define QTN_RC_NET_LINK BIT(1)
#define QTN_RC_FW_FLASHBOOT BIT(5)
#define QTN_RC_FW_QLINK BIT(7)
#define QTN_RC_FW_LOADRDY BIT(8)
#define QTN_RC_FW_SYNC BIT(9)
/* state transition timeouts */
#define QTN_FW_DL_TIMEOUT_MS 3000
#define QTN_FW_QLINK_TIMEOUT_MS 30000
#define QTN_EP_RESET_WAIT_MS 1000
#define PCIE_HDP_INT_RX_BITS (0 \
| PCIE_HDP_INT_EP_TXDMA \
| PCIE_HDP_INT_EP_TXEMPTY \
| PCIE_HDP_INT_HHBM_UF \
)
#define PCIE_HDP_INT_TX_BITS (0 \
| PCIE_HDP_INT_EP_RXDMA \
)
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
#define QTN_HOST_HI32(a) ((u32)(((u64)a) >> 32))
#define QTN_HOST_LO32(a) ((u32)(((u64)a) & 0xffffffffUL))
#define QTN_HOST_ADDR(h, l) ((((u64)h) << 32) | ((u64)l))
#else
#define QTN_HOST_HI32(a) 0
#define QTN_HOST_LO32(a) ((u32)(((u32)a) & 0xffffffffUL))
#define QTN_HOST_ADDR(h, l) ((u32)l)
#endif
#define QTN_SYSCTL_BAR 0
#define QTN_SHMEM_BAR 2
#define QTN_DMA_BAR 3
#define QTN_PCIE_BDA_VERSION 0x1002
#define PCIE_BDA_NAMELEN 32
#define PCIE_HHBM_MAX_SIZE 2048
#define SKB_BUF_SIZE 2048
#define QTN_PCIE_BOARDFLG "PCIEQTN"
#define QTN_PCIE_FW_DLMASK 0xF
#define QTN_PCIE_FW_BUFSZ 2048
#define QTN_ENET_ADDR_LENGTH 6
#define QTN_TXDONE_MASK ((u32)0x80000000)
#define QTN_GET_LEN(x) ((x) & 0xFFFF)
#define QTN_PCIE_TX_DESC_LEN_MASK 0xFFFF
#define QTN_PCIE_TX_DESC_LEN_SHIFT 0
#define QTN_PCIE_TX_DESC_PORT_MASK 0xF
#define QTN_PCIE_TX_DESC_PORT_SHIFT 16
#define QTN_PCIE_TX_DESC_TQE_BIT BIT(24)
#define QTN_EP_LHOST_TQE_PORT 4
enum qtnf_pcie_bda_ipc_flags {
QTN_PCIE_IPC_FLAG_HBM_MAGIC = BIT(0),
QTN_PCIE_IPC_FLAG_SHM_PIO = BIT(1),
};
struct qtnf_pcie_bda {
__le16 bda_len;
__le16 bda_version;
__le32 bda_pci_endian;
__le32 bda_ep_state;
__le32 bda_rc_state;
__le32 bda_dma_mask;
__le32 bda_msi_addr;
__le32 bda_flashsz;
u8 bda_boardname[PCIE_BDA_NAMELEN];
__le32 bda_rc_msi_enabled;
u8 bda_hhbm_list[PCIE_HHBM_MAX_SIZE];
__le32 bda_dsbw_start_index;
__le32 bda_dsbw_end_index;
__le32 bda_dsbw_total_bytes;
__le32 bda_rc_tx_bd_base;
__le32 bda_rc_tx_bd_num;
u8 bda_pcie_mac[QTN_ENET_ADDR_LENGTH];
struct qtnf_shm_ipc_region bda_shm_reg1 __aligned(4096); /* host TX */
struct qtnf_shm_ipc_region bda_shm_reg2 __aligned(4096); /* host RX */
} __packed;
struct qtnf_tx_bd {
__le32 addr;
__le32 addr_h;
__le32 info;
__le32 info_h;
} __packed;
struct qtnf_rx_bd {
__le32 addr;
__le32 addr_h;
__le32 info;
__le32 info_h;
__le32 next_ptr;
__le32 next_ptr_h;
} __packed;
enum qtnf_fw_loadtype {
QTN_FW_DBEGIN,
QTN_FW_DSUB,
QTN_FW_DEND,
QTN_FW_CTRL
};
struct qtnf_pcie_fw_hdr {
u8 boardflg[8];
__le32 fwsize;
__le32 seqnum;
__le32 type;
__le32 pktlen;
__le32 crc;
} __packed;
#endif /* _QTN_FMAC_PCIE_IPC_H_ */
@@ -0,0 +1,356 @@
/*
* Copyright (c) 2015 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef __PEARL_PCIE_H
#define __PEARL_PCIE_H
#define PCIE_GEN2_BASE (0xe9000000)
#define PCIE_GEN3_BASE (0xe7000000)
#define PEARL_CUR_PCIE_BASE (PCIE_GEN2_BASE)
#define PCIE_HDP_OFFSET (0x2000)
#define PCIE_HDP_CTRL(base) ((base) + 0x2c00)
#define PCIE_HDP_AXI_CTRL(base) ((base) + 0x2c04)
#define PCIE_HDP_HOST_WR_DESC0(base) ((base) + 0x2c10)
#define PCIE_HDP_HOST_WR_DESC0_H(base) ((base) + 0x2c14)
#define PCIE_HDP_HOST_WR_DESC1(base) ((base) + 0x2c18)
#define PCIE_HDP_HOST_WR_DESC1_H(base) ((base) + 0x2c1c)
#define PCIE_HDP_HOST_WR_DESC2(base) ((base) + 0x2c20)
#define PCIE_HDP_HOST_WR_DESC2_H(base) ((base) + 0x2c24)
#define PCIE_HDP_HOST_WR_DESC3(base) ((base) + 0x2c28)
#define PCIE_HDP_HOST_WR_DESC4_H(base) ((base) + 0x2c2c)
#define PCIE_HDP_RX_INT_CTRL(base) ((base) + 0x2c30)
#define PCIE_HDP_TX_INT_CTRL(base) ((base) + 0x2c34)
#define PCIE_HDP_INT_STATUS(base) ((base) + 0x2c38)
#define PCIE_HDP_INT_EN(base) ((base) + 0x2c3c)
#define PCIE_HDP_RX_DESC0_PTR(base) ((base) + 0x2c40)
#define PCIE_HDP_RX_DESC0_NOE(base) ((base) + 0x2c44)
#define PCIE_HDP_RX_DESC1_PTR(base) ((base) + 0x2c48)
#define PCIE_HDP_RX_DESC1_NOE(base) ((base) + 0x2c4c)
#define PCIE_HDP_RX_DESC2_PTR(base) ((base) + 0x2c50)
#define PCIE_HDP_RX_DESC2_NOE(base) ((base) + 0x2c54)
#define PCIE_HDP_RX_DESC3_PTR(base) ((base) + 0x2c58)
#define PCIE_HDP_RX_DESC3_NOE(base) ((base) + 0x2c5c)
#define PCIE_HDP_TX0_BASE_ADDR(base) ((base) + 0x2c60)
#define PCIE_HDP_TX1_BASE_ADDR(base) ((base) + 0x2c64)
#define PCIE_HDP_TX0_Q_CTRL(base) ((base) + 0x2c70)
#define PCIE_HDP_TX1_Q_CTRL(base) ((base) + 0x2c74)
#define PCIE_HDP_CFG0(base) ((base) + 0x2c80)
#define PCIE_HDP_CFG1(base) ((base) + 0x2c84)
#define PCIE_HDP_CFG2(base) ((base) + 0x2c88)
#define PCIE_HDP_CFG3(base) ((base) + 0x2c8c)
#define PCIE_HDP_CFG4(base) ((base) + 0x2c90)
#define PCIE_HDP_CFG5(base) ((base) + 0x2c94)
#define PCIE_HDP_CFG6(base) ((base) + 0x2c98)
#define PCIE_HDP_CFG7(base) ((base) + 0x2c9c)
#define PCIE_HDP_CFG8(base) ((base) + 0x2ca0)
#define PCIE_HDP_CFG9(base) ((base) + 0x2ca4)
#define PCIE_HDP_CFG10(base) ((base) + 0x2ca8)
#define PCIE_HDP_CFG11(base) ((base) + 0x2cac)
#define PCIE_INT(base) ((base) + 0x2cb0)
#define PCIE_INT_MASK(base) ((base) + 0x2cb4)
#define PCIE_MSI_MASK(base) ((base) + 0x2cb8)
#define PCIE_MSI_PNDG(base) ((base) + 0x2cbc)
#define PCIE_PRI_CFG(base) ((base) + 0x2cc0)
#define PCIE_PHY_CR(base) ((base) + 0x2cc4)
#define PCIE_HDP_CTAG_CTRL(base) ((base) + 0x2cf4)
#define PCIE_HDP_HHBM_BUF_PTR(base) ((base) + 0x2d00)
#define PCIE_HDP_HHBM_BUF_PTR_H(base) ((base) + 0x2d04)
#define PCIE_HDP_HHBM_BUF_FIFO_NOE(base) ((base) + 0x2d04)
#define PCIE_HDP_RX0DMA_CNT(base) ((base) + 0x2d10)
#define PCIE_HDP_RX1DMA_CNT(base) ((base) + 0x2d14)
#define PCIE_HDP_RX2DMA_CNT(base) ((base) + 0x2d18)
#define PCIE_HDP_RX3DMA_CNT(base) ((base) + 0x2d1c)
#define PCIE_HDP_TX0DMA_CNT(base) ((base) + 0x2d20)
#define PCIE_HDP_TX1DMA_CNT(base) ((base) + 0x2d24)
#define PCIE_HDP_RXDMA_CTRL(base) ((base) + 0x2d28)
#define PCIE_HDP_TX_HOST_Q_SZ_CTRL(base) ((base) + 0x2d2c)
#define PCIE_HDP_TX_HOST_Q_BASE_L(base) ((base) + 0x2d30)
#define PCIE_HDP_TX_HOST_Q_BASE_H(base) ((base) + 0x2d34)
#define PCIE_HDP_TX_HOST_Q_WR_PTR(base) ((base) + 0x2d38)
#define PCIE_HDP_TX_HOST_Q_RD_PTR(base) ((base) + 0x2d3c)
#define PCIE_HDP_TX_HOST_Q_STS(base) ((base) + 0x2d40)
/* Host HBM pool registers */
#define PCIE_HHBM_CSR_REG(base) ((base) + 0x2e00)
#define PCIE_HHBM_Q_BASE_REG(base) ((base) + 0x2e04)
#define PCIE_HHBM_Q_LIMIT_REG(base) ((base) + 0x2e08)
#define PCIE_HHBM_Q_WR_REG(base) ((base) + 0x2e0c)
#define PCIE_HHBM_Q_RD_REG(base) ((base) + 0x2e10)
#define PCIE_HHBM_POOL_DATA_0_H(base) ((base) + 0x2e90)
#define PCIE_HHBM_CONFIG(base) ((base) + 0x2f9c)
#define PCIE_HHBM_POOL_REQ_0(base) ((base) + 0x2f10)
#define PCIE_HHBM_POOL_DATA_0(base) ((base) + 0x2f40)
#define PCIE_HHBM_WATERMARK_MASKED_INT(base) ((base) + 0x2f68)
#define PCIE_HHBM_WATERMARK_INT(base) ((base) + 0x2f6c)
#define PCIE_HHBM_POOL_WATERMARK(base) ((base) + 0x2f70)
#define PCIE_HHBM_POOL_OVERFLOW_CNT(base) ((base) + 0x2f90)
#define PCIE_HHBM_POOL_UNDERFLOW_CNT(base) ((base) + 0x2f94)
#define HBM_INT_STATUS(base) ((base) + 0x2f9c)
#define PCIE_HHBM_POOL_CNFIG(base) ((base) + 0x2f9c)
/* host HBM bit field definition */
#define HHBM_CONFIG_SOFT_RESET (BIT(8))
#define HHBM_WR_REQ (BIT(0))
#define HHBM_RD_REQ (BIT(1))
#define HHBM_DONE (BIT(31))
#define HHBM_64BIT (BIT(10))
/* offsets for dual PCIE */
#define PCIE_PORT_LINK_CTL(base) ((base) + 0x0710)
#define PCIE_GEN2_CTL(base) ((base) + 0x080C)
#define PCIE_GEN3_OFF(base) ((base) + 0x0890)
#define PCIE_ATU_CTRL1(base) ((base) + 0x0904)
#define PCIE_ATU_CTRL2(base) ((base) + 0x0908)
#define PCIE_ATU_BASE_LOW(base) ((base) + 0x090C)
#define PCIE_ATU_BASE_HIGH(base) ((base) + 0x0910)
#define PCIE_ATU_BASE_LIMIT(base) ((base) + 0x0914)
#define PCIE_ATU_TGT_LOW(base) ((base) + 0x0918)
#define PCIE_ATU_TGT_HIGH(base) ((base) + 0x091C)
#define PCIE_DMA_WR_ENABLE(base) ((base) + 0x097C)
#define PCIE_DMA_WR_CHWTLOW(base) ((base) + 0x0988)
#define PCIE_DMA_WR_CHWTHIG(base) ((base) + 0x098C)
#define PCIE_DMA_WR_INTSTS(base) ((base) + 0x09BC)
#define PCIE_DMA_WR_INTMASK(base) ((base) + 0x09C4)
#define PCIE_DMA_WR_INTCLER(base) ((base) + 0x09C8)
#define PCIE_DMA_WR_DONE_IMWR_ADDR_L(base) ((base) + 0x09D0)
#define PCIE_DMA_WR_DONE_IMWR_ADDR_H(base) ((base) + 0x09D4)
#define PCIE_DMA_WR_ABORT_IMWR_ADDR_L(base) ((base) + 0x09D8)
#define PCIE_DMA_WR_ABORT_IMWR_ADDR_H(base) ((base) + 0x09DC)
#define PCIE_DMA_WR_IMWR_DATA(base) ((base) + 0x09E0)
#define PCIE_DMA_WR_LL_ERR_EN(base) ((base) + 0x0A00)
#define PCIE_DMA_WR_DOORBELL(base) ((base) + 0x0980)
#define PCIE_DMA_RD_ENABLE(base) ((base) + 0x099C)
#define PCIE_DMA_RD_DOORBELL(base) ((base) + 0x09A0)
#define PCIE_DMA_RD_CHWTLOW(base) ((base) + 0x09A8)
#define PCIE_DMA_RD_CHWTHIG(base) ((base) + 0x09AC)
#define PCIE_DMA_RD_INTSTS(base) ((base) + 0x0A10)
#define PCIE_DMA_RD_INTMASK(base) ((base) + 0x0A18)
#define PCIE_DMA_RD_INTCLER(base) ((base) + 0x0A1C)
#define PCIE_DMA_RD_ERR_STS_L(base) ((base) + 0x0A24)
#define PCIE_DMA_RD_ERR_STS_H(base) ((base) + 0x0A28)
#define PCIE_DMA_RD_LL_ERR_EN(base) ((base) + 0x0A34)
#define PCIE_DMA_RD_DONE_IMWR_ADDR_L(base) ((base) + 0x0A3C)
#define PCIE_DMA_RD_DONE_IMWR_ADDR_H(base) ((base) + 0x0A40)
#define PCIE_DMA_RD_ABORT_IMWR_ADDR_L(base) ((base) + 0x0A44)
#define PCIE_DMA_RD_ABORT_IMWR_ADDR_H(base) ((base) + 0x0A48)
#define PCIE_DMA_RD_IMWR_DATA(base) ((base) + 0x0A4C)
#define PCIE_DMA_CHNL_CONTEXT(base) ((base) + 0x0A6C)
#define PCIE_DMA_CHNL_CNTRL(base) ((base) + 0x0A70)
#define PCIE_DMA_XFR_SIZE(base) ((base) + 0x0A78)
#define PCIE_DMA_SAR_LOW(base) ((base) + 0x0A7C)
#define PCIE_DMA_SAR_HIGH(base) ((base) + 0x0A80)
#define PCIE_DMA_DAR_LOW(base) ((base) + 0x0A84)
#define PCIE_DMA_DAR_HIGH(base) ((base) + 0x0A88)
#define PCIE_DMA_LLPTR_LOW(base) ((base) + 0x0A8C)
#define PCIE_DMA_LLPTR_HIGH(base) ((base) + 0x0A90)
#define PCIE_DMA_WRLL_ERR_ENB(base) ((base) + 0x0A00)
#define PCIE_DMA_RDLL_ERR_ENB(base) ((base) + 0x0A34)
#define PCIE_DMABD_CHNL_CNTRL(base) ((base) + 0x8000)
#define PCIE_DMABD_XFR_SIZE(base) ((base) + 0x8004)
#define PCIE_DMABD_SAR_LOW(base) ((base) + 0x8008)
#define PCIE_DMABD_SAR_HIGH(base) ((base) + 0x800c)
#define PCIE_DMABD_DAR_LOW(base) ((base) + 0x8010)
#define PCIE_DMABD_DAR_HIGH(base) ((base) + 0x8014)
#define PCIE_DMABD_LLPTR_LOW(base) ((base) + 0x8018)
#define PCIE_DMABD_LLPTR_HIGH(base) ((base) + 0x801c)
#define PCIE_WRDMA0_CHNL_CNTRL(base) ((base) + 0x8000)
#define PCIE_WRDMA0_XFR_SIZE(base) ((base) + 0x8004)
#define PCIE_WRDMA0_SAR_LOW(base) ((base) + 0x8008)
#define PCIE_WRDMA0_SAR_HIGH(base) ((base) + 0x800c)
#define PCIE_WRDMA0_DAR_LOW(base) ((base) + 0x8010)
#define PCIE_WRDMA0_DAR_HIGH(base) ((base) + 0x8014)
#define PCIE_WRDMA0_LLPTR_LOW(base) ((base) + 0x8018)
#define PCIE_WRDMA0_LLPTR_HIGH(base) ((base) + 0x801c)
#define PCIE_WRDMA1_CHNL_CNTRL(base) ((base) + 0x8020)
#define PCIE_WRDMA1_XFR_SIZE(base) ((base) + 0x8024)
#define PCIE_WRDMA1_SAR_LOW(base) ((base) + 0x8028)
#define PCIE_WRDMA1_SAR_HIGH(base) ((base) + 0x802c)
#define PCIE_WRDMA1_DAR_LOW(base) ((base) + 0x8030)
#define PCIE_WRDMA1_DAR_HIGH(base) ((base) + 0x8034)
#define PCIE_WRDMA1_LLPTR_LOW(base) ((base) + 0x8038)
#define PCIE_WRDMA1_LLPTR_HIGH(base) ((base) + 0x803c)
#define PCIE_RDDMA0_CHNL_CNTRL(base) ((base) + 0x8040)
#define PCIE_RDDMA0_XFR_SIZE(base) ((base) + 0x8044)
#define PCIE_RDDMA0_SAR_LOW(base) ((base) + 0x8048)
#define PCIE_RDDMA0_SAR_HIGH(base) ((base) + 0x804c)
#define PCIE_RDDMA0_DAR_LOW(base) ((base) + 0x8050)
#define PCIE_RDDMA0_DAR_HIGH(base) ((base) + 0x8054)
#define PCIE_RDDMA0_LLPTR_LOW(base) ((base) + 0x8058)
#define PCIE_RDDMA0_LLPTR_HIGH(base) ((base) + 0x805c)
#define PCIE_RDDMA1_CHNL_CNTRL(base) ((base) + 0x8060)
#define PCIE_RDDMA1_XFR_SIZE(base) ((base) + 0x8064)
#define PCIE_RDDMA1_SAR_LOW(base) ((base) + 0x8068)
#define PCIE_RDDMA1_SAR_HIGH(base) ((base) + 0x806c)
#define PCIE_RDDMA1_DAR_LOW(base) ((base) + 0x8070)
#define PCIE_RDDMA1_DAR_HIGH(base) ((base) + 0x8074)
#define PCIE_RDDMA1_LLPTR_LOW(base) ((base) + 0x8078)
#define PCIE_RDDMA1_LLPTR_HIGH(base) ((base) + 0x807c)
#define PCIE_ID(base) ((base) + 0x0000)
#define PCIE_CMD(base) ((base) + 0x0004)
#define PCIE_BAR(base, n) ((base) + 0x0010 + ((n) << 2))
#define PCIE_CAP_PTR(base) ((base) + 0x0034)
#define PCIE_MSI_LBAR(base) ((base) + 0x0054)
#define PCIE_MSI_CTRL(base) ((base) + 0x0050)
#define PCIE_MSI_ADDR_L(base) ((base) + 0x0054)
#define PCIE_MSI_ADDR_H(base) ((base) + 0x0058)
#define PCIE_MSI_DATA(base) ((base) + 0x005C)
#define PCIE_MSI_MASK_BIT(base) ((base) + 0x0060)
#define PCIE_MSI_PEND_BIT(base) ((base) + 0x0064)
#define PCIE_DEVCAP(base) ((base) + 0x0074)
#define PCIE_DEVCTLSTS(base) ((base) + 0x0078)
#define PCIE_CMDSTS(base) ((base) + 0x0004)
#define PCIE_LINK_STAT(base) ((base) + 0x80)
#define PCIE_LINK_CTL2(base) ((base) + 0xa0)
#define PCIE_ASPM_L1_CTRL(base) ((base) + 0x70c)
#define PCIE_ASPM_LINK_CTRL(base) (PCIE_LINK_STAT)
#define PCIE_ASPM_L1_SUBSTATE_TIMING(base) ((base) + 0xB44)
#define PCIE_L1SUB_CTRL1(base) ((base) + 0x150)
#define PCIE_PMCSR(base) ((base) + 0x44)
#define PCIE_CFG_SPACE_LIMIT(base) ((base) + 0x100)
/* PCIe link defines */
#define PEARL_PCIE_LINKUP (0x7)
#define PEARL_PCIE_DATA_LINK (BIT(0))
#define PEARL_PCIE_PHY_LINK (BIT(1))
#define PEARL_PCIE_LINK_RST (BIT(3))
#define PEARL_PCIE_FATAL_ERR (BIT(5))
#define PEARL_PCIE_NONFATAL_ERR (BIT(6))
/* PCIe Lane defines */
#define PCIE_G2_LANE_X1 ((BIT(0)) << 16)
#define PCIE_G2_LANE_X2 ((BIT(0) | BIT(1)) << 16)
/* PCIe DLL link enable */
#define PCIE_DLL_LINK_EN ((BIT(0)) << 5)
#define PCIE_LINK_GEN1 (BIT(0))
#define PCIE_LINK_GEN2 (BIT(1))
#define PCIE_LINK_GEN3 (BIT(2))
#define PCIE_LINK_MODE(x) (((x) >> 16) & 0x7)
#define MSI_EN (BIT(0))
#define MSI_64_EN (BIT(7))
#define PCIE_MSI_ADDR_OFFSET(a) ((a) & 0xFFFF)
#define PCIE_MSI_ADDR_ALIGN(a) ((a) & (~0xFFFF))
#define PCIE_BAR_MASK(base, n) ((base) + 0x1010 + ((n) << 2))
#define PCIE_MAX_BAR (6)
#define PCIE_ATU_VIEW(base) ((base) + 0x0900)
#define PCIE_ATU_CTL1(base) ((base) + 0x0904)
#define PCIE_ATU_CTL2(base) ((base) + 0x0908)
#define PCIE_ATU_LBAR(base) ((base) + 0x090c)
#define PCIE_ATU_UBAR(base) ((base) + 0x0910)
#define PCIE_ATU_LAR(base) ((base) + 0x0914)
#define PCIE_ATU_LTAR(base) ((base) + 0x0918)
#define PCIE_ATU_UTAR(base) ((base) + 0x091c)
#define PCIE_MSI_ADDR_LOWER(base) ((base) + 0x0820)
#define PCIE_MSI_ADDR_UPPER(base) ((base) + 0x0824)
#define PCIE_MSI_ENABLE(base) ((base) + 0x0828)
#define PCIE_MSI_MASK_RC(base) ((base) + 0x082c)
#define PCIE_MSI_STATUS(base) ((base) + 0x0830)
#define PEARL_PCIE_MSI_REGION (0xce000000)
#define PEARL_PCIE_MSI_DATA (0)
#define PCIE_MSI_GPIO(base) ((base) + 0x0888)
#define PCIE_HDP_HOST_QUEUE_FULL (BIT(17))
#define USE_BAR_MATCH_MODE
#define PCIE_ATU_OB_REGION (BIT(0))
#define PCIE_ATU_EN_REGION (BIT(31))
#define PCIE_ATU_EN_MATCH (BIT(30))
#define PCIE_BASE_REGION (0xb0000000)
#define PCIE_MEM_MAP_SIZE (512 * 1024)
#define PCIE_OB_REG_REGION (0xcf000000)
#define PCIE_CONFIG_REGION (0xcf000000)
#define PCIE_CONFIG_SIZE (4096)
#define PCIE_CONFIG_CH (1)
/* inbound mapping */
#define PCIE_IB_BAR0 (0x00000000) /* ddr */
#define PCIE_IB_BAR0_CH (0)
#define PCIE_IB_BAR3 (0xe0000000) /* sys_reg */
#define PCIE_IB_BAR3_CH (1)
/* outbound mapping */
#define PCIE_MEM_CH (0)
#define PCIE_REG_CH (1)
#define PCIE_MEM_REGION (0xc0000000)
#define PCIE_MEM_SIZE (0x000fffff)
#define PCIE_MEM_TAR (0x80000000)
#define PCIE_MSI_REGION (0xce000000)
#define PCIE_MSI_SIZE (KBYTE(4) - 1)
#define PCIE_MSI_CH (1)
/* size of config region */
#define PCIE_CFG_SIZE (0x0000ffff)
#define PCIE_ATU_DIR_IB (BIT(31))
#define PCIE_ATU_DIR_OB (0)
#define PCIE_ATU_DIR_CFG (2)
#define PCIE_ATU_DIR_MATCH_IB (BIT(31) | BIT(30))
#define PCIE_DMA_WR_0 (0)
#define PCIE_DMA_WR_1 (1)
#define PCIE_DMA_RD_0 (2)
#define PCIE_DMA_RD_1 (3)
#define PCIE_DMA_CHNL_CNTRL_CB (BIT(0))
#define PCIE_DMA_CHNL_CNTRL_TCB (BIT(1))
#define PCIE_DMA_CHNL_CNTRL_LLP (BIT(2))
#define PCIE_DMA_CHNL_CNTRL_LIE (BIT(3))
#define PCIE_DMA_CHNL_CNTRL_RIE (BIT(4))
#define PCIE_DMA_CHNL_CNTRL_CSS (BIT(8))
#define PCIE_DMA_CHNL_CNTRL_LLE (BIT(9))
#define PCIE_DMA_CHNL_CNTRL_TLP (BIT(26))
#define PCIE_DMA_CHNL_CONTEXT_RD (BIT(31))
#define PCIE_DMA_CHNL_CONTEXT_WR (0)
#define PCIE_MAX_BAR (6)
/* PCIe HDP interrupt status definition */
#define PCIE_HDP_INT_EP_RXDMA (BIT(0))
#define PCIE_HDP_INT_HBM_UF (BIT(1))
#define PCIE_HDP_INT_RX_LEN_ERR (BIT(2))
#define PCIE_HDP_INT_RX_HDR_LEN_ERR (BIT(3))
#define PCIE_HDP_INT_EP_TXDMA (BIT(12))
#define PCIE_HDP_INT_HHBM_UF (BIT(13))
#define PCIE_HDP_INT_EP_TXEMPTY (BIT(15))
#define PCIE_HDP_INT_IPC (BIT(29))
/* PCIe interrupt status definition */
#define PCIE_INT_MSI (BIT(24))
#define PCIE_INT_INTX (BIT(23))
/* PCIe legacy INTx */
#define PEARL_PCIE_CFG0_OFFSET (0x6C)
#define PEARL_ASSERT_INTX (BIT(9))
/* SYS CTL regs */
#define QTN_PEARL_SYSCTL_LHOST_IRQ_OFFSET (0x001C)
#define QTN_PEARL_IPC_IRQ_WORD(irq) (BIT(irq) | BIT(irq + 16))
#define QTN_PEARL_LHOST_IPC_IRQ (6)
#define QTN_PEARL_LHOST_EP_RESET (7)
#endif /* __PEARL_PCIE_H */
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,196 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/nl80211.h>
#include "qlink_util.h"
u16 qlink_iface_type_to_nl_mask(u16 qlink_type)
{
u16 result = 0;
switch (qlink_type) {
case QLINK_IFTYPE_AP:
result |= BIT(NL80211_IFTYPE_AP);
break;
case QLINK_IFTYPE_STATION:
result |= BIT(NL80211_IFTYPE_STATION);
break;
case QLINK_IFTYPE_ADHOC:
result |= BIT(NL80211_IFTYPE_ADHOC);
break;
case QLINK_IFTYPE_MONITOR:
result |= BIT(NL80211_IFTYPE_MONITOR);
break;
case QLINK_IFTYPE_WDS:
result |= BIT(NL80211_IFTYPE_WDS);
break;
case QLINK_IFTYPE_AP_VLAN:
result |= BIT(NL80211_IFTYPE_AP_VLAN);
break;
}
return result;
}
u8 qlink_chan_width_mask_to_nl(u16 qlink_mask)
{
u8 result = 0;
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_5))
result |= BIT(NL80211_CHAN_WIDTH_5);
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_10))
result |= BIT(NL80211_CHAN_WIDTH_10);
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_20_NOHT))
result |= BIT(NL80211_CHAN_WIDTH_20_NOHT);
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_20))
result |= BIT(NL80211_CHAN_WIDTH_20);
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_40))
result |= BIT(NL80211_CHAN_WIDTH_40);
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_80))
result |= BIT(NL80211_CHAN_WIDTH_80);
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_80P80))
result |= BIT(NL80211_CHAN_WIDTH_80P80);
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_160))
result |= BIT(NL80211_CHAN_WIDTH_160);
return result;
}
static enum nl80211_chan_width qlink_chanwidth_to_nl(u8 qlw)
{
switch (qlw) {
case QLINK_CHAN_WIDTH_20_NOHT:
return NL80211_CHAN_WIDTH_20_NOHT;
case QLINK_CHAN_WIDTH_20:
return NL80211_CHAN_WIDTH_20;
case QLINK_CHAN_WIDTH_40:
return NL80211_CHAN_WIDTH_40;
case QLINK_CHAN_WIDTH_80:
return NL80211_CHAN_WIDTH_80;
case QLINK_CHAN_WIDTH_80P80:
return NL80211_CHAN_WIDTH_80P80;
case QLINK_CHAN_WIDTH_160:
return NL80211_CHAN_WIDTH_160;
case QLINK_CHAN_WIDTH_5:
return NL80211_CHAN_WIDTH_5;
case QLINK_CHAN_WIDTH_10:
return NL80211_CHAN_WIDTH_10;
default:
return -1;
}
}
static u8 qlink_chanwidth_nl_to_qlink(enum nl80211_chan_width nlwidth)
{
switch (nlwidth) {
case NL80211_CHAN_WIDTH_20_NOHT:
return QLINK_CHAN_WIDTH_20_NOHT;
case NL80211_CHAN_WIDTH_20:
return QLINK_CHAN_WIDTH_20;
case NL80211_CHAN_WIDTH_40:
return QLINK_CHAN_WIDTH_40;
case NL80211_CHAN_WIDTH_80:
return QLINK_CHAN_WIDTH_80;
case NL80211_CHAN_WIDTH_80P80:
return QLINK_CHAN_WIDTH_80P80;
case NL80211_CHAN_WIDTH_160:
return QLINK_CHAN_WIDTH_160;
case NL80211_CHAN_WIDTH_5:
return QLINK_CHAN_WIDTH_5;
case NL80211_CHAN_WIDTH_10:
return QLINK_CHAN_WIDTH_10;
default:
return -1;
}
}
void qlink_chandef_q2cfg(struct wiphy *wiphy,
const struct qlink_chandef *qch,
struct cfg80211_chan_def *chdef)
{
struct ieee80211_channel *chan;
chan = ieee80211_get_channel(wiphy, le16_to_cpu(qch->chan.center_freq));
chdef->chan = chan;
chdef->center_freq1 = le16_to_cpu(qch->center_freq1);
chdef->center_freq2 = le16_to_cpu(qch->center_freq2);
chdef->width = qlink_chanwidth_to_nl(qch->width);
}
void qlink_chandef_cfg2q(const struct cfg80211_chan_def *chdef,
struct qlink_chandef *qch)
{
struct ieee80211_channel *chan = chdef->chan;
qch->chan.hw_value = cpu_to_le16(chan->hw_value);
qch->chan.center_freq = cpu_to_le16(chan->center_freq);
qch->chan.flags = cpu_to_le32(chan->flags);
qch->center_freq1 = cpu_to_le16(chdef->center_freq1);
qch->center_freq2 = cpu_to_le16(chdef->center_freq2);
qch->width = qlink_chanwidth_nl_to_qlink(chdef->width);
}
enum qlink_hidden_ssid qlink_hidden_ssid_nl2q(enum nl80211_hidden_ssid nl_val)
{
switch (nl_val) {
case NL80211_HIDDEN_SSID_ZERO_LEN:
return QLINK_HIDDEN_SSID_ZERO_LEN;
case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
return QLINK_HIDDEN_SSID_ZERO_CONTENTS;
case NL80211_HIDDEN_SSID_NOT_IN_USE:
default:
return QLINK_HIDDEN_SSID_NOT_IN_USE;
}
}
bool qtnf_utils_is_bit_set(const u8 *arr, unsigned int bit,
unsigned int arr_max_len)
{
unsigned int idx = bit / BITS_PER_BYTE;
u8 mask = 1 << (bit - (idx * BITS_PER_BYTE));
if (idx >= arr_max_len)
return false;
return arr[idx] & mask;
}
void qlink_acl_data_cfg2q(const struct cfg80211_acl_data *acl,
struct qlink_acl_data *qacl)
{
switch (acl->acl_policy) {
case NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED:
qacl->policy =
cpu_to_le32(QLINK_ACL_POLICY_ACCEPT_UNLESS_LISTED);
break;
case NL80211_ACL_POLICY_DENY_UNLESS_LISTED:
qacl->policy = cpu_to_le32(QLINK_ACL_POLICY_DENY_UNLESS_LISTED);
break;
}
qacl->num_entries = cpu_to_le32(acl->n_acl_entries);
memcpy(qacl->mac_addrs, acl->mac_addrs,
acl->n_acl_entries * sizeof(*qacl->mac_addrs));
}
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _QTN_FMAC_QLINK_UTIL_H_
#define _QTN_FMAC_QLINK_UTIL_H_
#include <linux/types.h>
#include <linux/skbuff.h>
#include <net/cfg80211.h>
#include "qlink.h"
static inline void
qtnf_cmd_skb_put_buffer(struct sk_buff *skb, const u8 *buf_src, size_t len)
{
skb_put_data(skb, buf_src, len);
}
static inline void qtnf_cmd_skb_put_tlv_arr(struct sk_buff *skb,
u16 tlv_id, const u8 arr[],
size_t arr_len)
{
struct qlink_tlv_hdr *hdr = skb_put(skb, sizeof(*hdr) + arr_len);
hdr->type = cpu_to_le16(tlv_id);
hdr->len = cpu_to_le16(arr_len);
memcpy(hdr->val, arr, arr_len);
}
static inline void qtnf_cmd_skb_put_tlv_u8(struct sk_buff *skb, u16 tlv_id,
u8 value)
{
struct qlink_tlv_hdr *hdr = skb_put(skb, sizeof(*hdr) + sizeof(value));
hdr->type = cpu_to_le16(tlv_id);
hdr->len = cpu_to_le16(sizeof(value));
*hdr->val = value;
}
static inline void qtnf_cmd_skb_put_tlv_u16(struct sk_buff *skb,
u16 tlv_id, u16 value)
{
struct qlink_tlv_hdr *hdr = skb_put(skb, sizeof(*hdr) + sizeof(value));
__le16 tmp = cpu_to_le16(value);
hdr->type = cpu_to_le16(tlv_id);
hdr->len = cpu_to_le16(sizeof(value));
memcpy(hdr->val, &tmp, sizeof(tmp));
}
u16 qlink_iface_type_to_nl_mask(u16 qlink_type);
u8 qlink_chan_width_mask_to_nl(u16 qlink_mask);
void qlink_chandef_q2cfg(struct wiphy *wiphy,
const struct qlink_chandef *qch,
struct cfg80211_chan_def *chdef);
void qlink_chandef_cfg2q(const struct cfg80211_chan_def *chdef,
struct qlink_chandef *qch);
enum qlink_hidden_ssid qlink_hidden_ssid_nl2q(enum nl80211_hidden_ssid nl_val);
bool qtnf_utils_is_bit_set(const u8 *arr, unsigned int bit,
unsigned int arr_max_len);
void qlink_acl_data_cfg2q(const struct cfg80211_acl_data *acl,
struct qlink_acl_data *qacl);
#endif /* _QTN_FMAC_QLINK_UTIL_H_ */
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _QTN_HW_IDS_H_
#define _QTN_HW_IDS_H_
#include <linux/pci_ids.h>
#define PCIE_VENDOR_ID_QUANTENNA (0x1bb5)
/* PCIE Device IDs */
#define PCIE_DEVICE_ID_QTN_PEARL (0x0008)
/* FW names */
#define QTN_PCI_PEARL_FW_NAME "qtn/fmac_qsr10g.img"
#endif /* _QTN_HW_IDS_H_ */
@@ -0,0 +1,176 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/types.h>
#include <linux/io.h>
#include "shm_ipc.h"
#undef pr_fmt
#define pr_fmt(fmt) "qtnfmac shm_ipc: %s: " fmt, __func__
static bool qtnf_shm_ipc_has_new_data(struct qtnf_shm_ipc *ipc)
{
const u32 flags = readl(&ipc->shm_region->headroom.hdr.flags);
return (flags & QTNF_SHM_IPC_NEW_DATA);
}
static void qtnf_shm_handle_new_data(struct qtnf_shm_ipc *ipc)
{
size_t size;
bool rx_buff_ok = true;
struct qtnf_shm_ipc_region_header __iomem *shm_reg_hdr;
shm_reg_hdr = &ipc->shm_region->headroom.hdr;
size = readw(&shm_reg_hdr->data_len);
if (unlikely(size == 0 || size > QTN_IPC_MAX_DATA_SZ)) {
pr_err("wrong rx packet size: %zu\n", size);
rx_buff_ok = false;
} else {
memcpy_fromio(ipc->rx_data, ipc->shm_region->data, size);
}
writel(QTNF_SHM_IPC_ACK, &shm_reg_hdr->flags);
readl(&shm_reg_hdr->flags); /* flush PCIe write */
ipc->interrupt.fn(ipc->interrupt.arg);
if (likely(rx_buff_ok)) {
ipc->rx_packet_count++;
ipc->rx_callback.fn(ipc->rx_callback.arg, ipc->rx_data, size);
}
}
static void qtnf_shm_ipc_irq_work(struct work_struct *work)
{
struct qtnf_shm_ipc *ipc = container_of(work, struct qtnf_shm_ipc,
irq_work);
while (qtnf_shm_ipc_has_new_data(ipc))
qtnf_shm_handle_new_data(ipc);
}
static void qtnf_shm_ipc_irq_inbound_handler(struct qtnf_shm_ipc *ipc)
{
u32 flags;
flags = readl(&ipc->shm_region->headroom.hdr.flags);
if (flags & QTNF_SHM_IPC_NEW_DATA)
queue_work(ipc->workqueue, &ipc->irq_work);
}
static void qtnf_shm_ipc_irq_outbound_handler(struct qtnf_shm_ipc *ipc)
{
u32 flags;
if (!READ_ONCE(ipc->waiting_for_ack))
return;
flags = readl(&ipc->shm_region->headroom.hdr.flags);
if (flags & QTNF_SHM_IPC_ACK) {
WRITE_ONCE(ipc->waiting_for_ack, 0);
complete(&ipc->tx_completion);
}
}
int qtnf_shm_ipc_init(struct qtnf_shm_ipc *ipc,
enum qtnf_shm_ipc_direction direction,
struct qtnf_shm_ipc_region __iomem *shm_region,
struct workqueue_struct *workqueue,
const struct qtnf_shm_ipc_int *interrupt,
const struct qtnf_shm_ipc_rx_callback *rx_callback)
{
BUILD_BUG_ON(offsetof(struct qtnf_shm_ipc_region, data) !=
QTN_IPC_REG_HDR_SZ);
BUILD_BUG_ON(sizeof(struct qtnf_shm_ipc_region) > QTN_IPC_REG_SZ);
ipc->shm_region = shm_region;
ipc->direction = direction;
ipc->interrupt = *interrupt;
ipc->rx_callback = *rx_callback;
ipc->tx_packet_count = 0;
ipc->rx_packet_count = 0;
ipc->workqueue = workqueue;
ipc->waiting_for_ack = 0;
ipc->tx_timeout_count = 0;
switch (direction) {
case QTNF_SHM_IPC_OUTBOUND:
ipc->irq_handler = qtnf_shm_ipc_irq_outbound_handler;
break;
case QTNF_SHM_IPC_INBOUND:
ipc->irq_handler = qtnf_shm_ipc_irq_inbound_handler;
break;
default:
return -EINVAL;
}
INIT_WORK(&ipc->irq_work, qtnf_shm_ipc_irq_work);
init_completion(&ipc->tx_completion);
return 0;
}
void qtnf_shm_ipc_free(struct qtnf_shm_ipc *ipc)
{
complete_all(&ipc->tx_completion);
}
int qtnf_shm_ipc_send(struct qtnf_shm_ipc *ipc, const u8 *buf, size_t size)
{
int ret = 0;
struct qtnf_shm_ipc_region_header __iomem *shm_reg_hdr;
shm_reg_hdr = &ipc->shm_region->headroom.hdr;
if (unlikely(size > QTN_IPC_MAX_DATA_SZ))
return -E2BIG;
ipc->tx_packet_count++;
writew(size, &shm_reg_hdr->data_len);
memcpy_toio(ipc->shm_region->data, buf, size);
/* sync previous writes before proceeding */
dma_wmb();
WRITE_ONCE(ipc->waiting_for_ack, 1);
/* sync previous memory write before announcing new data ready */
wmb();
writel(QTNF_SHM_IPC_NEW_DATA, &shm_reg_hdr->flags);
readl(&shm_reg_hdr->flags); /* flush PCIe write */
ipc->interrupt.fn(ipc->interrupt.arg);
if (!wait_for_completion_timeout(&ipc->tx_completion,
QTN_SHM_IPC_ACK_TIMEOUT)) {
ret = -ETIMEDOUT;
ipc->tx_timeout_count++;
pr_err("TX ACK timeout\n");
}
/* now we're not waiting for ACK even in case of timeout */
WRITE_ONCE(ipc->waiting_for_ack, 0);
return ret;
}
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _QTN_FMAC_SHM_IPC_H_
#define _QTN_FMAC_SHM_IPC_H_
#include <linux/workqueue.h>
#include <linux/completion.h>
#include <linux/mutex.h>
#include <linux/spinlock.h>
#include "shm_ipc_defs.h"
#define QTN_SHM_IPC_ACK_TIMEOUT (2 * HZ)
struct qtnf_shm_ipc_int {
void (*fn)(void *arg);
void *arg;
};
struct qtnf_shm_ipc_rx_callback {
void (*fn)(void *arg, const u8 *buf, size_t len);
void *arg;
};
enum qtnf_shm_ipc_direction {
QTNF_SHM_IPC_OUTBOUND = BIT(0),
QTNF_SHM_IPC_INBOUND = BIT(1),
};
struct qtnf_shm_ipc {
struct qtnf_shm_ipc_region __iomem *shm_region;
enum qtnf_shm_ipc_direction direction;
size_t tx_packet_count;
size_t rx_packet_count;
size_t tx_timeout_count;
u8 waiting_for_ack;
u8 rx_data[QTN_IPC_MAX_DATA_SZ] __aligned(sizeof(u32));
struct qtnf_shm_ipc_int interrupt;
struct qtnf_shm_ipc_rx_callback rx_callback;
void (*irq_handler)(struct qtnf_shm_ipc *ipc);
struct workqueue_struct *workqueue;
struct work_struct irq_work;
struct completion tx_completion;
};
int qtnf_shm_ipc_init(struct qtnf_shm_ipc *ipc,
enum qtnf_shm_ipc_direction direction,
struct qtnf_shm_ipc_region __iomem *shm_region,
struct workqueue_struct *workqueue,
const struct qtnf_shm_ipc_int *interrupt,
const struct qtnf_shm_ipc_rx_callback *rx_callback);
void qtnf_shm_ipc_free(struct qtnf_shm_ipc *ipc);
int qtnf_shm_ipc_send(struct qtnf_shm_ipc *ipc, const u8 *buf, size_t size);
static inline void qtnf_shm_ipc_irq_handler(struct qtnf_shm_ipc *ipc)
{
ipc->irq_handler(ipc);
}
#endif /* _QTN_FMAC_SHM_IPC_H_ */
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _QTN_FMAC_SHM_IPC_DEFS_H_
#define _QTN_FMAC_SHM_IPC_DEFS_H_
#include <linux/types.h>
#define QTN_IPC_REG_HDR_SZ (32)
#define QTN_IPC_REG_SZ (4096)
#define QTN_IPC_MAX_DATA_SZ (QTN_IPC_REG_SZ - QTN_IPC_REG_HDR_SZ)
enum qtnf_shm_ipc_region_flags {
QTNF_SHM_IPC_NEW_DATA = BIT(0),
QTNF_SHM_IPC_ACK = BIT(1),
};
struct qtnf_shm_ipc_region_header {
__le32 flags;
__le16 data_len;
} __packed;
union qtnf_shm_ipc_region_headroom {
struct qtnf_shm_ipc_region_header hdr;
u8 headroom[QTN_IPC_REG_HDR_SZ];
} __packed;
struct qtnf_shm_ipc_region {
union qtnf_shm_ipc_region_headroom headroom;
u8 data[QTN_IPC_MAX_DATA_SZ];
} __packed;
#endif /* _QTN_FMAC_SHM_IPC_DEFS_H_ */
@@ -0,0 +1,226 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/types.h>
#include <linux/export.h>
#include <linux/slab.h>
#include "core.h"
#include "commands.h"
#include "event.h"
#include "bus.h"
#define QTNF_DEF_SYNC_CMD_TIMEOUT (5 * HZ)
int qtnf_trans_send_cmd_with_resp(struct qtnf_bus *bus, struct sk_buff *cmd_skb,
struct sk_buff **response_skb)
{
struct qtnf_cmd_ctl_node *ctl_node = &bus->trans.curr_cmd;
struct qlink_cmd *cmd = (void *)cmd_skb->data;
int ret = 0;
long status;
bool resp_not_handled = true;
struct sk_buff *resp_skb = NULL;
if (unlikely(!response_skb)) {
dev_kfree_skb(cmd_skb);
return -EFAULT;
}
spin_lock(&ctl_node->resp_lock);
ctl_node->seq_num++;
cmd->seq_num = cpu_to_le16(ctl_node->seq_num);
WARN(ctl_node->resp_skb, "qtnfmac: response skb not empty\n");
ctl_node->waiting_for_resp = true;
spin_unlock(&ctl_node->resp_lock);
ret = qtnf_bus_control_tx(bus, cmd_skb);
dev_kfree_skb(cmd_skb);
if (unlikely(ret))
goto out;
status = wait_for_completion_interruptible_timeout(
&ctl_node->cmd_resp_completion,
QTNF_DEF_SYNC_CMD_TIMEOUT);
spin_lock(&ctl_node->resp_lock);
resp_not_handled = ctl_node->waiting_for_resp;
resp_skb = ctl_node->resp_skb;
ctl_node->resp_skb = NULL;
ctl_node->waiting_for_resp = false;
spin_unlock(&ctl_node->resp_lock);
if (unlikely(status <= 0)) {
if (status == 0) {
ret = -ETIMEDOUT;
pr_err("response timeout\n");
} else {
ret = -EINTR;
pr_debug("interrupted\n");
}
}
if (unlikely(!resp_skb || resp_not_handled)) {
if (!ret)
ret = -EFAULT;
goto out;
}
ret = 0;
*response_skb = resp_skb;
out:
if (unlikely(resp_skb && resp_not_handled))
dev_kfree_skb(resp_skb);
return ret;
}
static void qtnf_trans_signal_cmdresp(struct qtnf_bus *bus, struct sk_buff *skb)
{
struct qtnf_cmd_ctl_node *ctl_node = &bus->trans.curr_cmd;
const struct qlink_resp *resp = (const struct qlink_resp *)skb->data;
const u16 recvd_seq_num = le16_to_cpu(resp->seq_num);
spin_lock(&ctl_node->resp_lock);
if (unlikely(!ctl_node->waiting_for_resp)) {
pr_err("unexpected response\n");
goto out_err;
}
if (unlikely(recvd_seq_num != ctl_node->seq_num)) {
pr_err("seq num mismatch\n");
goto out_err;
}
ctl_node->resp_skb = skb;
ctl_node->waiting_for_resp = false;
spin_unlock(&ctl_node->resp_lock);
complete(&ctl_node->cmd_resp_completion);
return;
out_err:
spin_unlock(&ctl_node->resp_lock);
dev_kfree_skb(skb);
}
static int qtnf_trans_event_enqueue(struct qtnf_bus *bus, struct sk_buff *skb)
{
struct qtnf_qlink_transport *trans = &bus->trans;
if (likely(skb_queue_len(&trans->event_queue) <
trans->event_queue_max_len)) {
skb_queue_tail(&trans->event_queue, skb);
queue_work(bus->workqueue, &bus->event_work);
} else {
pr_warn("event dropped due to queue overflow\n");
dev_kfree_skb(skb);
return -1;
}
return 0;
}
void qtnf_trans_init(struct qtnf_bus *bus)
{
struct qtnf_qlink_transport *trans = &bus->trans;
init_completion(&trans->curr_cmd.cmd_resp_completion);
spin_lock_init(&trans->curr_cmd.resp_lock);
spin_lock(&trans->curr_cmd.resp_lock);
trans->curr_cmd.seq_num = 0;
trans->curr_cmd.waiting_for_resp = false;
trans->curr_cmd.resp_skb = NULL;
spin_unlock(&trans->curr_cmd.resp_lock);
/* Init event handling related fields */
skb_queue_head_init(&trans->event_queue);
trans->event_queue_max_len = QTNF_MAX_EVENT_QUEUE_LEN;
}
static void qtnf_trans_free_events(struct qtnf_bus *bus)
{
struct sk_buff_head *event_queue = &bus->trans.event_queue;
struct sk_buff *current_event_skb = skb_dequeue(event_queue);
while (current_event_skb) {
dev_kfree_skb_any(current_event_skb);
current_event_skb = skb_dequeue(event_queue);
}
}
void qtnf_trans_free(struct qtnf_bus *bus)
{
if (!bus) {
pr_err("invalid bus pointer\n");
return;
}
qtnf_trans_free_events(bus);
}
int qtnf_trans_handle_rx_ctl_packet(struct qtnf_bus *bus, struct sk_buff *skb)
{
const struct qlink_msg_header *header = (void *)skb->data;
int ret = -1;
if (unlikely(skb->len < sizeof(*header))) {
pr_warn("packet is too small: %u\n", skb->len);
dev_kfree_skb(skb);
return -EINVAL;
}
if (unlikely(skb->len != le16_to_cpu(header->len))) {
pr_warn("cmd reply length mismatch: %u != %u\n",
skb->len, le16_to_cpu(header->len));
dev_kfree_skb(skb);
return -EFAULT;
}
switch (le16_to_cpu(header->type)) {
case QLINK_MSG_TYPE_CMDRSP:
if (unlikely(skb->len < sizeof(struct qlink_cmd))) {
pr_warn("cmd reply too short: %u\n", skb->len);
dev_kfree_skb(skb);
break;
}
qtnf_trans_signal_cmdresp(bus, skb);
break;
case QLINK_MSG_TYPE_EVENT:
if (unlikely(skb->len < sizeof(struct qlink_event))) {
pr_warn("event too short: %u\n", skb->len);
dev_kfree_skb(skb);
break;
}
ret = qtnf_trans_event_enqueue(bus, skb);
break;
default:
pr_warn("unknown packet type: %x\n", le16_to_cpu(header->type));
dev_kfree_skb(skb);
break;
}
return ret;
}
EXPORT_SYMBOL_GPL(qtnf_trans_handle_rx_ctl_packet);
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _QTN_FMAC_TRANS_H_
#define _QTN_FMAC_TRANS_H_
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/mutex.h>
#include "qlink.h"
#define QTNF_CMD_FLAG_RESP_REQ BIT(0)
#define QTNF_MAX_CMD_BUF_SIZE 2048
#define QTNF_DEF_CMD_HROOM 4
struct qtnf_bus;
struct qtnf_cmd_ctl_node {
struct completion cmd_resp_completion;
struct sk_buff *resp_skb;
u16 seq_num;
bool waiting_for_resp;
spinlock_t resp_lock; /* lock for resp_skb & waiting_for_resp changes */
};
struct qtnf_qlink_transport {
struct qtnf_cmd_ctl_node curr_cmd;
struct sk_buff_head event_queue;
size_t event_queue_max_len;
};
void qtnf_trans_init(struct qtnf_bus *bus);
void qtnf_trans_free(struct qtnf_bus *bus);
int qtnf_trans_send_next_cmd(struct qtnf_bus *bus);
int qtnf_trans_handle_rx_ctl_packet(struct qtnf_bus *bus, struct sk_buff *skb);
int qtnf_trans_send_cmd_with_resp(struct qtnf_bus *bus,
struct sk_buff *cmd_skb,
struct sk_buff **response_skb);
#endif /* _QTN_FMAC_TRANS_H_ */
@@ -0,0 +1,118 @@
/*
* Copyright (c) 2015-2016 Quantenna Communications, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "util.h"
void qtnf_sta_list_init(struct qtnf_sta_list *list)
{
if (unlikely(!list))
return;
INIT_LIST_HEAD(&list->head);
atomic_set(&list->size, 0);
}
struct qtnf_sta_node *qtnf_sta_list_lookup(struct qtnf_sta_list *list,
const u8 *mac)
{
struct qtnf_sta_node *node;
if (unlikely(!mac))
return NULL;
list_for_each_entry(node, &list->head, list) {
if (ether_addr_equal(node->mac_addr, mac))
return node;
}
return NULL;
}
struct qtnf_sta_node *qtnf_sta_list_lookup_index(struct qtnf_sta_list *list,
size_t index)
{
struct qtnf_sta_node *node;
if (qtnf_sta_list_size(list) <= index)
return NULL;
list_for_each_entry(node, &list->head, list) {
if (index-- == 0)
return node;
}
return NULL;
}
struct qtnf_sta_node *qtnf_sta_list_add(struct qtnf_vif *vif,
const u8 *mac)
{
struct qtnf_sta_list *list = &vif->sta_list;
struct qtnf_sta_node *node;
if (unlikely(!mac))
return NULL;
node = qtnf_sta_list_lookup(list, mac);
if (node)
goto done;
node = kzalloc(sizeof(*node), GFP_KERNEL);
if (unlikely(!node))
goto done;
ether_addr_copy(node->mac_addr, mac);
list_add_tail(&node->list, &list->head);
atomic_inc(&list->size);
++vif->generation;
done:
return node;
}
bool qtnf_sta_list_del(struct qtnf_vif *vif, const u8 *mac)
{
struct qtnf_sta_list *list = &vif->sta_list;
struct qtnf_sta_node *node;
bool ret = false;
node = qtnf_sta_list_lookup(list, mac);
if (node) {
list_del(&node->list);
atomic_dec(&list->size);
kfree(node);
++vif->generation;
ret = true;
}
return ret;
}
void qtnf_sta_list_free(struct qtnf_sta_list *list)
{
struct qtnf_sta_node *node, *tmp;
atomic_set(&list->size, 0);
list_for_each_entry_safe(node, tmp, &list->head, list) {
list_del(&node->list);
kfree(node);
}
INIT_LIST_HEAD(&list->head);
}
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2015 Quantenna Communications
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef QTNFMAC_UTIL_H
#define QTNFMAC_UTIL_H
#include <linux/kernel.h>
#include "core.h"
void qtnf_sta_list_init(struct qtnf_sta_list *list);
struct qtnf_sta_node *qtnf_sta_list_lookup(struct qtnf_sta_list *list,
const u8 *mac);
struct qtnf_sta_node *qtnf_sta_list_lookup_index(struct qtnf_sta_list *list,
size_t index);
struct qtnf_sta_node *qtnf_sta_list_add(struct qtnf_vif *vif,
const u8 *mac);
bool qtnf_sta_list_del(struct qtnf_vif *vif, const u8 *mac);
void qtnf_sta_list_free(struct qtnf_sta_list *list);
static inline size_t qtnf_sta_list_size(const struct qtnf_sta_list *list)
{
return atomic_read(&list->size);
}
static inline bool qtnf_sta_list_empty(const struct qtnf_sta_list *list)
{
return list_empty(&list->head);
}
#endif /* QTNFMAC_UTIL_H */