// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
* All rights reserved.
*/
#include <linux/irq.h>
#include <linux/kthread.h>
#include <linux/firmware.h>
#include <linux/netdevice.h>
#include <linux/inetdevice.h>
#include "wilc_wfi_cfgoperations.h"
static int dev_state_ev_handler(struct notifier_block *this,
unsigned long event, void *ptr)
{
struct in_ifaddr *dev_iface = ptr;
struct wilc_priv *priv;
struct host_if_drv *hif_drv;
struct net_device *dev;
struct wilc_vif *vif;
char wlan_dev_name[5] = "wlan0";
if (!dev_iface || !dev_iface->ifa_dev || !dev_iface->ifa_dev->dev)
return NOTIFY_DONE;
if (memcmp(dev_iface->ifa_label, "wlan0", 5) &&
memcmp(dev_iface->ifa_label, "p2p0", 4))
return NOTIFY_DONE;
dev = (struct net_device *)dev_iface->ifa_dev->dev;
if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
return NOTIFY_DONE;
priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
if (!priv)
return NOTIFY_DONE;
hif_drv = (struct host_if_drv *)priv->hif_drv;
vif = netdev_priv(dev);
if (!vif || !hif_drv)
return NOTIFY_DONE;
switch (event) {
case NETDEV_UP:
if (vif->iftype == WILC_STATION_MODE ||
vif->iftype == WILC_CLIENT_MODE) {
hif_drv->ifc_up = 1;
vif->obtaining_ip = false;
del_timer(&vif->during_ip_timer);
}
if (vif->wilc->enable_ps)
wilc_set_power_mgmt(vif, 1, 0);
break;
case NETDEV_DOWN:
if (vif->iftype == WILC_STATION_MODE ||
vif->iftype == WILC_CLIENT_MODE) {
hif_drv->ifc_up = 0;
vif->obtaining_ip = false;
}
if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
wilc_set_power_mgmt(vif, 0, 0);
wilc_resolve_disconnect_aberration(vif);
break;
default:
break;
}
return NOTIFY_DONE;
}
static irqreturn_t isr_uh_routine(int irq, void *user_data)
{
struct net_device *dev = user_data;
struct wilc_vif *vif = netdev_priv(dev);
struct wilc *wilc = vif->wilc;
if (wilc->close) {
netdev_err(dev, "Can't handle UH interrupt\n");
return IRQ_HANDLED;
}
return IRQ_WAKE_THREAD;
}
static irqreturn_t isr_bh_routine(int irq, void *userdata)
{
struct net_device *dev = userdata;
struct wilc_vif *vif = netdev_priv(userdata);
struct wilc *wilc = vif->wilc;
if (wilc->close) {
netdev_err(dev, "Can't handle BH interrupt\n");
return IRQ_HANDLED;
}
wilc_handle_isr(wilc);
return IRQ_HANDLED;
}
static int init_irq(struct net_device *dev)
{
int ret = 0;
struct wilc_vif *vif = netdev_priv(dev);