Skip to content

Commit

Permalink
Merge branch 'bugfix/compatibility_with_higher_kernels' into 'master'
Browse files Browse the repository at this point in the history
Add support for Linux version 6.1.21

See merge request app-frameworks/esp_hosted!283
  • Loading branch information
mantriyogesh committed Apr 19, 2023
2 parents 81778f6 + 1294f8a commit cf871bb
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 22 deletions.
5 changes: 5 additions & 0 deletions esp_hosted_fg/host/linux/host_driver/esp32/esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,9 @@ struct esp_private {
struct esp_skb_cb {
struct esp_private *priv;
};

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 17, 0))
#define do_exit(code) kthread_complete_and_exit(NULL, code)
#endif

#endif
19 changes: 10 additions & 9 deletions esp_hosted_ng/host/esp_cfg80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ struct wireless_dev *esp_cfg80211_add_iface(struct wiphy *wiphy,
if (cmd_get_mac(esp_wdev))
goto free_and_return;

/* memcpy(ndev->dev_addr, esp_wdev->mac_address, ETH_ALEN);*/
ether_addr_copy(ndev->dev_addr, esp_wdev->mac_address);
eth_hw_addr_set(ndev, esp_wdev->mac_address);

esp_init_priv(ndev);

Expand Down Expand Up @@ -312,7 +311,8 @@ static ESP_MGMT_TX_PROTOTYPE()
}

static int esp_cfg80211_set_default_key(struct wiphy *wiphy,
struct net_device *dev, u8 key_index, bool unicast, bool multicast)
struct net_device *dev, INT_LINK_ID
u8 key_index, bool unicast, bool multicast)
{
struct esp_wifi_device *priv = NULL;

Expand All @@ -331,7 +331,8 @@ static int esp_cfg80211_set_default_key(struct wiphy *wiphy,
}

static int esp_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev,
u8 key_index, bool pairwise, const u8 *mac_addr)
INT_LINK_ID u8 key_index, bool pairwise,
const u8 *mac_addr)
{
struct esp_wifi_device *priv = NULL;

Expand All @@ -351,8 +352,8 @@ static int esp_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev,
}

static int esp_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev,
u8 key_index, bool pairwise, const u8 *mac_addr,
struct key_params *params)
INT_LINK_ID u8 key_index, bool pairwise,
const u8 *mac_addr, struct key_params *params)
{
struct esp_wifi_device *priv = NULL;

Expand All @@ -368,9 +369,9 @@ static int esp_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev,
}
printk(KERN_INFO "%s\n", __func__);

if (params->key_len == 0)
return esp_cfg80211_del_key(wiphy, dev, key_index, pairwise, mac_addr);

if (params->key_len == 0) {
return esp_cfg80211_del_key(wiphy, dev, ZERO_LINK_ID key_index, pairwise, mac_addr);
}
return cmd_add_key(priv, key_index, pairwise, mac_addr, params);
}

Expand Down
8 changes: 2 additions & 6 deletions esp_hosted_ng/host/esp_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,13 +564,9 @@ static void process_assoc_event(struct esp_wifi_device *priv,

printk(KERN_INFO "Connection status: %d\n", event->header.status);

if (!event->bssid) {
printk(KERN_INFO "bssid input as NULL. Ignoring the connect statuc event\n");
return;
}
memcpy(mac, event->bssid, MAC_ADDR_LEN);

cfg80211_rx_assoc_resp(priv->ndev, priv->bss, event->frame, event->frame_len,
CFG80211_RX_ASSOC_RESP(priv->ndev, priv->bss, event->frame, event->frame_len,
0, priv->assoc_req_ie, priv->assoc_req_ie_len);

#if 0
Expand Down Expand Up @@ -1309,7 +1305,7 @@ int cmd_scan_request(struct esp_wifi_device *priv, struct cfg80211_scan_request
sizeof(struct esp_payload_header));

/* TODO: Handle case of multiple SSIDs or channels */
if(request->ssids[0].ssid_len) {
if(request->ssids && request->ssids[0].ssid_len) {
memcpy(scan_req->ssid, request->ssids[0].ssid, MAX_SSID_LEN);
}

Expand Down
60 changes: 60 additions & 0 deletions esp_hosted_ng/host/include/esp_kernel_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,65 @@ static inline void *skb_put_data(struct sk_buff *skb, const void *data,
void esp_tx_timeout(struct net_device *ndev, unsigned int txqueue)
#endif

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 17, 0))
#define do_exit(code) kthread_complete_and_exit(NULL, code)
#endif

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0))
#define NETIF_RX_NI(skb) netif_rx(skb)
#else
#define NETIF_RX_NI(skb) netif_rx_ni(skb)
#endif

static inline
void CFG80211_RX_ASSOC_RESP(struct net_device *dev,
struct cfg80211_bss *bss,
const u8 *buf, size_t len,
int uapsd_queues,
const u8 *req_ies, size_t req_ies_len)
{
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0))
struct cfg80211_rx_assoc_resp resp = {0};

resp.links[0].bss = bss;
resp.buf = (u8 *)buf;
resp.len = len;
resp.req_ies = req_ies;
resp.uapsd_queues = uapsd_queues;
resp.req_ies_len = req_ies_len;

cfg80211_rx_assoc_resp(dev, &resp);
#else
cfg80211_rx_assoc_resp(dev, bss, buf, len, uapsd_queues, req_ies, req_ies_len)
#endif
}


#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
static inline bool wireless_dev_current_bss_exists(struct wireless_dev *wdev)
{
if (wdev->links[0].client.current_bss)
return true;
return false;
}
#define INT_LINK_ID int link_id,
#define ZERO_LINK_ID 0,
#else
static inline bool wireless_dev_current_bss_exists(struct wireless_dev *wdev)
{
if (wdev->current_bss)
return true;
return false;
}
#define INT_LINK_ID
#define ZERO_LINK_ID
#endif

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0))
static inline void eth_hw_addr_set(struct net_device *dev, const u8 *addr)
{
ether_addr_copy(dev->dev_addr, addr, ETH_ALEN);
}
#endif

#endif
9 changes: 4 additions & 5 deletions esp_hosted_ng/host/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ static struct net_device_stats* esp_get_stats(struct net_device *ndev)
return &priv->stats;
}

#if 0
static int esp_set_mac_address(struct net_device *ndev, void *data)
{
struct esp_wifi_device *priv = netdev_priv(ndev);
Expand All @@ -306,11 +307,11 @@ static int esp_set_mac_address(struct net_device *ndev, void *data)
return -EINVAL;

printk(KERN_INFO "%s:%u %pM\n", __func__, __LINE__, priv->mac_address);
/* TODO Handle in correct way */
ether_addr_copy(ndev->dev_addr, priv->mac_address/*mac_addr->sa_data*/);
eth_hw_addr_set(ndev, priv->mac_address/*mac_addr->sa_data*/);

return 0;
}
#endif

static NDO_TX_TIMEOUT_PROTOTYPE()
{
Expand Down Expand Up @@ -388,7 +389,6 @@ static const struct net_device_ops esp_netdev_ops = {
.ndo_open = esp_open,
.ndo_stop = esp_stop,
.ndo_start_xmit = esp_hard_start_xmit,
.ndo_set_mac_address = esp_set_mac_address,
.ndo_validate_addr = eth_validate_addr,
.ndo_tx_timeout = esp_tx_timeout,
.ndo_get_stats = esp_get_stats,
Expand Down Expand Up @@ -657,8 +657,7 @@ static void process_rx_packet(struct esp_adapter *adapter, struct sk_buff *skb)

priv->stats.rx_bytes += skb->len;
/* Forward skb to kernel */
netif_rx_ni(skb);

NETIF_RX_NI(skb);
priv->stats.rx_packets++;
} else if (payload_header->packet_type == PACKET_TYPE_COMMAND_RESPONSE) {
process_cmd_resp(priv->adapter, skb);
Expand Down
1 change: 1 addition & 0 deletions esp_hosted_ng/host/sdio/esp_sdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <linux/kthread.h>
#include <linux/printk.h>
#include "esp_stats.h"
#include "include/esp_kernel_port.h"

#define MAX_WRITE_RETRIES 2
#define TX_MAX_PENDING_COUNT 200
Expand Down
49 changes: 47 additions & 2 deletions esp_hosted_ng/host/spi/esp_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ void process_event_esp_bootup(struct esp_adapter *adapter, u8 *evt_buf, u8 len)
ESP_MARK_SCAN_DONE(priv, true);

if (priv->ndev &&
priv->wdev.current_bss) {

wireless_dev_current_bss_exists(&priv->wdev)) {
CFG80211_DISCONNECTED(priv->ndev,
0, NULL, 0, false, GFP_KERNEL);
}
Expand Down Expand Up @@ -457,6 +456,52 @@ static void esp_spi_work(struct work_struct *work)
mutex_unlock(&spi_lock);
}

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,16,0))
#include <linux/platform_device.h>
static int __spi_controller_match(struct device *dev, const void *data)
{
struct spi_controller *ctlr;
const u16 *bus_num = data;

ctlr = container_of(dev, struct spi_controller, dev);

if(!ctlr) {
return 0;
}

return ctlr->bus_num == *bus_num;
}

static struct spi_controller *spi_busnum_to_master(u16 bus_num)
{
struct platform_device *pdev = NULL;
struct spi_master *master = NULL;
struct spi_controller *ctlr = NULL;
struct device *dev = NULL;

pdev = platform_device_alloc("pdev", PLATFORM_DEVID_NONE);
pdev->num_resources = 0;
platform_device_add(pdev);

master = spi_alloc_master(&pdev->dev, sizeof(void *));
if (!master) {
pr_err("Error: failed to allocate SPI master device\n");
platform_device_put(pdev);
return NULL;
}

dev = class_find_device(master->dev.class, NULL, &bus_num, __spi_controller_match);
if (dev) {
ctlr = container_of(dev, struct spi_controller, dev);
}

spi_master_put(master);
platform_device_put(pdev);

return ctlr;
}
#endif

static int spi_dev_init(int spi_clk_mhz)
{
int status = 0;
Expand Down

0 comments on commit cf871bb

Please sign in to comment.