// SPDX-License-Identifier: GPL-2.0-only /* * This file contains the major functions in WLAN * driver. It includes init, exit, open, close and main * thread etc..
*/
/* * This global structure is used to send the confirm_sleep command as * fast as possible down to the firmware.
*/ struct cmd_confirm_sleep confirm_sleep;
/* * the table to keep region code
*/
u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
{ 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
/* * FW rate table. FW refers to rates by their index in this table, not by the * rate value itself. Values of 0x00 are * reserved positions.
*/ static u8 fw_data_rates[MAX_RATES] =
{ 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
};
/** * lbs_fw_index_to_data_rate - use index to get the data rate * * @idx: The index of data rate * returns: data rate or 0
*/
u32 lbs_fw_index_to_data_rate(u8 idx)
{ if (idx >= sizeof(fw_data_rates))
idx = 0; return fw_data_rates[idx];
}
int lbs_set_iface_type(struct lbs_private *priv, enum nl80211_iftype type)
{ int ret = 0;
switch (type) { case NL80211_IFTYPE_MONITOR:
ret = lbs_set_monitor_mode(priv, 1); break; case NL80211_IFTYPE_STATION: if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
ret = lbs_set_monitor_mode(priv, 0); if (!ret)
ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 1); break; case NL80211_IFTYPE_ADHOC: if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
ret = lbs_set_monitor_mode(priv, 0); if (!ret)
ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 2); break; default:
ret = -ENOTSUPP;
} return ret;
}
int lbs_start_iface(struct lbs_private *priv)
{ struct cmd_ds_802_11_mac_address cmd; int ret;
if (priv->power_restore) {
ret = priv->power_restore(priv); if (ret) return ret;
}
ret = lbs_cmd_with_response(priv, CMD_802_11_MAC_ADDRESS, &cmd); if (ret) {
lbs_deb_net("set MAC address failed\n"); goto err;
}
ret = lbs_set_iface_type(priv, priv->wdev->iftype); if (ret) {
lbs_deb_net("set iface type failed\n"); goto err;
}
ret = lbs_set_11d_domain_info(priv); if (ret) {
lbs_deb_net("set 11d domain info failed\n"); goto err;
}
lbs_update_channel(priv);
priv->iface_running = true; return 0;
err: if (priv->power_save)
priv->power_save(priv); return ret;
}
/** * lbs_dev_open - open the ethX interface * * @dev: A pointer to &net_device structure * returns: 0 or -EBUSY if monitor mode active
*/ staticint lbs_dev_open(struct net_device *dev)
{ struct lbs_private *priv = dev->ml_priv; int ret = 0;
if (!priv->iface_running) {
ret = lbs_start_iface(priv); if (ret) goto out;
}
/* Disable command processing, and wait for all commands to complete */
lbs_deb_main("waiting for commands to complete\n");
wait_event(priv->waitq, lbs_command_queue_empty(priv));
lbs_deb_main("all commands completed\n");
if (priv->power_save)
ret = priv->power_save(priv);
return ret;
}
/** * lbs_eth_stop - close the ethX interface * * @dev: A pointer to &net_device structure * returns: 0
*/ staticint lbs_eth_stop(struct net_device *dev)
{ struct lbs_private *priv = dev->ml_priv;
if (priv->connect_status == LBS_CONNECTED)
lbs_disconnect(priv, WLAN_REASON_DEAUTH_LEAVING);
int lbs_set_mac_address(struct net_device *dev, void *addr)
{ int ret = 0; struct lbs_private *priv = dev->ml_priv; struct sockaddr *phwaddr = addr;
/* * Can only set MAC address when all interfaces are down, to be written * to the hardware when one of them is brought up.
*/ if (lbs_iface_active(priv)) return -EBUSY;
/* In case it was called from the mesh device */
dev = priv->dev;
memcpy(priv->current_addr, phwaddr->sa_data, ETH_ALEN);
eth_hw_addr_set(dev, phwaddr->sa_data); if (priv->mesh_dev)
eth_hw_addr_set(priv->mesh_dev, phwaddr->sa_data);
return ret;
}
staticinlineint mac_in_list(unsignedchar *list, int list_len, unsignedchar *mac)
{ while (list_len) { if (!memcmp(list, mac, ETH_ALEN)) return 1;
list += ETH_ALEN;
list_len--;
} return 0;
}
staticint lbs_add_mcast_addrs(struct cmd_ds_mac_multicast_adr *cmd, struct net_device *dev, int nr_addrs)
{ int i = nr_addrs; struct netdev_hw_addr *ha; int cnt;
if ((dev->flags & (IFF_UP|IFF_MULTICAST)) != (IFF_UP|IFF_MULTICAST)) return nr_addrs;
/* Once for priv->dev, again for priv->mesh_dev if it exists */
nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->dev, 0); if (nr_addrs >= 0 && priv->mesh_dev)
nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->mesh_dev, nr_addrs); if (nr_addrs < 0) goto do_allmulti;
if (nr_addrs) { int size = offsetof(struct cmd_ds_mac_multicast_adr,
maclist[6*nr_addrs]);
/** * lbs_thread - handles the major jobs in the LBS driver. * It handles all events generated by firmware, RX data received * from firmware and TX data sent from kernel. * * @data: A pointer to &lbs_thread structure * returns: 0
*/ staticint lbs_thread(void *data)
{ struct net_device *dev = data; struct lbs_private *priv = dev->ml_priv;
wait_queue_entry_t wait;
if (kthread_should_stop())
shouldsleep = 0; /* Bye */ elseif (priv->surpriseremoved)
shouldsleep = 1; /* We need to wait until we're _told_ to die */ elseif (priv->psstate == PS_STATE_SLEEP)
shouldsleep = 1; /* Sleep mode. Nothing we can do till it wakes */ elseif (priv->cmd_timed_out)
shouldsleep = 0; /* Command timed out. Recover */ elseif (!priv->fw_ready)
shouldsleep = 1; /* Firmware not ready. We're waiting for it */ elseif (priv->dnld_sent)
shouldsleep = 1; /* Something is en route to the device already */ elseif (priv->tx_pending_len > 0)
shouldsleep = 0; /* We've a packet to send */ elseif (priv->resp_len[priv->resp_idx])
shouldsleep = 0; /* We have a command response */ elseif (priv->cur_cmd)
shouldsleep = 1; /* Can't send a command; one already running */ elseif (!list_empty(&priv->cmdpendingq))
shouldsleep = 0; /* We have a command to send */ elseif (kfifo_len(&priv->event_fifo))
shouldsleep = 0; /* We have an event to process */ else
shouldsleep = 1; /* No command */
/* Reset card, but only when it isn't in the process
* of being shutdown anyway. */ if (!dev->dismantle && priv->reset_card)
priv->reset_card(priv);
}
priv->cmd_timed_out = 0;
if (!priv->fw_ready) continue;
/* Check if we need to confirm Sleep Request received previously */ if (priv->psstate == PS_STATE_PRE_SLEEP &&
!priv->dnld_sent && !priv->cur_cmd) { if (priv->connect_status == LBS_CONNECTED) {
lbs_deb_thread("pre-sleep, currenttxskb %p, " "dnld_sent %d, cur_cmd %p\n",
priv->currenttxskb, priv->dnld_sent,
priv->cur_cmd);
lbs_ps_confirm_sleep(priv);
} else { /* workaround for firmware sending * deauth/linkloss event immediately * after sleep request; remove this * after firmware fixes it
*/
priv->psstate = PS_STATE_AWAKE;
netdev_alert(dev, "ignore PS_SleepConfirm in non-connected state\n");
}
}
/* The PS state is changed during processing of Sleep Request * event above
*/ if ((priv->psstate == PS_STATE_SLEEP) ||
(priv->psstate == PS_STATE_PRE_SLEEP)) continue;
if (priv->is_deep_sleep) continue;
/* Execute the next command */ if (!priv->dnld_sent && !priv->cur_cmd)
lbs_execute_next_command(priv);
spin_lock_irq(&priv->driver_lock); if (!priv->dnld_sent && priv->tx_pending_len > 0) { int ret = priv->hw_host_to_card(priv, MVMS_DAT,
priv->tx_pending_buf,
priv->tx_pending_len); if (ret) {
lbs_deb_tx("host_to_card failed %d\n", ret);
priv->dnld_sent = DNLD_RES_RECEIVED;
} else {
mod_timer(&priv->tx_lockup_timer,
jiffies + (HZ * 5));
}
priv->tx_pending_len = 0; if (!priv->currenttxskb) { /* We can wake the queues immediately if we aren't
waiting for TX feedback */ if (priv->connect_status == LBS_CONNECTED)
netif_wake_queue(priv->dev); if (priv->mesh_dev &&
netif_running(priv->mesh_dev))
netif_wake_queue(priv->mesh_dev);
}
}
spin_unlock_irq(&priv->driver_lock);
}
/** * lbs_setup_firmware - gets the HW spec from the firmware and sets * some basic parameters * * @priv: A pointer to &struct lbs_private structure * returns: 0 or -1
*/ staticint lbs_setup_firmware(struct lbs_private *priv)
{ int ret = -1;
s16 curlevel = 0, minlevel = 0, maxlevel = 0;
/* Read MAC address from firmware */
eth_broadcast_addr(priv->current_addr);
ret = lbs_update_hw_spec(priv); if (ret) goto done;
/* Read power levels if available */
ret = lbs_get_tx_power(priv, &curlevel, &minlevel, &maxlevel); if (ret == 0) {
priv->txpower_cur = curlevel;
priv->txpower_min = minlevel;
priv->txpower_max = maxlevel;
}
/* Send cmd to FW to enable 11D function */
ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_11D_ENABLE, 1); if (ret) goto done;
ret = lbs_set_mac_control_sync(priv);
done: return ret;
}
int lbs_suspend(struct lbs_private *priv)
{ int ret;
if (priv->is_deep_sleep) {
ret = lbs_set_deep_sleep(priv, 0); if (ret) {
netdev_err(priv->dev, "deep sleep cancellation failed: %d\n", ret); return ret;
}
priv->deep_sleep_required = 1;
}
ret = lbs_set_host_sleep(priv, 1);
netif_device_detach(priv->dev); if (priv->mesh_dev)
netif_device_detach(priv->mesh_dev);
return ret;
}
EXPORT_SYMBOL_GPL(lbs_suspend);
int lbs_resume(struct lbs_private *priv)
{ int ret;
ret = lbs_set_host_sleep(priv, 0);
netif_device_attach(priv->dev); if (priv->mesh_dev)
netif_device_attach(priv->mesh_dev);
if (priv->deep_sleep_required) {
priv->deep_sleep_required = 0;
ret = lbs_set_deep_sleep(priv, 1); if (ret)
netdev_err(priv->dev, "deep sleep activation failed: %d\n", ret);
}
if (priv->setup_fw_on_resume)
ret = lbs_setup_firmware(priv);
return ret;
}
EXPORT_SYMBOL_GPL(lbs_resume);
/** * lbs_cmd_timeout_handler - handles the timeout of command sending. * It will re-send the same command again. * * @t: Context from which to retrieve a &struct lbs_private pointer
*/ staticvoid lbs_cmd_timeout_handler(struct timer_list *t)
{ struct lbs_private *priv = timer_container_of(priv, t, command_timer); unsignedlong flags;
/* * If the device didn't even acknowledge the command, reset the state * so that we don't block all future commands due to this one timeout.
*/ if (priv->dnld_sent == DNLD_CMD_SENT)
priv->dnld_sent = DNLD_RES_RECEIVED;
/** * lbs_tx_lockup_handler - handles the timeout of the passing of TX frames * to the hardware. This is known to frequently happen with SD8686 when * waking up after a Wake-on-WLAN-triggered resume. * * @t: Context from which to retrieve a &struct lbs_private pointer
*/ staticvoid lbs_tx_lockup_handler(struct timer_list *t)
{ struct lbs_private *priv = timer_container_of(priv, t,
tx_lockup_timer); unsignedlong flags;
spin_lock_irqsave(&priv->driver_lock, flags);
netdev_info(priv->dev, "TX lockup detected\n"); if (priv->reset_card)
priv->reset_card(priv);
/** * lbs_add_card - adds the card. It will probe the * card, allocate the lbs_priv and initialize the device. * * @card: A pointer to card * @dmdev: A pointer to &struct device * returns: A pointer to &struct lbs_private structure
*/ struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
{ struct net_device *dev; struct wireless_dev *wdev; struct lbs_private *priv = NULL; int err;
/* Allocate an Ethernet device and register it */
wdev = lbs_cfg_alloc(dmdev); if (IS_ERR(wdev)) {
err = PTR_ERR(wdev);
pr_err("cfg80211 init failed\n"); goto err_cfg;
}
if (priv->wiphy_registered)
lbs_scan_deinit(priv);
lbs_wait_for_firmware_load(priv);
/* worker thread destruction blocks on the in-flight command which * should have been cleared already in lbs_stop_card().
*/
lbs_deb_main("destroying worker thread\n");
destroy_workqueue(priv->work_thread);
lbs_deb_main("done destroying worker thread\n");
if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
priv->psmode = LBS802_11POWERMODECAM; /* no need to wakeup if already woken up, * on suspend, this exit ps command is not processed * the driver hangs
*/ if (priv->psstate != PS_STATE_FULL_POWER)
lbs_set_ps_mode(priv, PS_MODE_ACTION_EXIT_PS, true);
}
if (priv->is_deep_sleep) {
priv->is_deep_sleep = 0;
wake_up_interruptible(&priv->ds_awake_q);
}
/* If the netdev isn't registered, it means that lbs_start_card() was
* never called so we have nothing to do here. */ if (dev->reg_state != NETREG_REGISTERED) return;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.