/* zd_mac.c
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/wireless.h>
#include <linux/usb.h>
#include <linux/jiffies.h>
#include <net/ieee80211_radiotap.h>
#include "zd_def.h"
#include "zd_chip.h"
#include "zd_mac.h"
#include "zd_ieee80211.h"
#include "zd_netdev.h"
#include "zd_rf.h"
#include "zd_util.h"
static void ieee_init(struct ieee80211_device *ieee);
static void softmac_init(struct ieee80211softmac_device *sm);
static void housekeeping_init(struct zd_mac *mac);
static void housekeeping_enable(struct zd_mac *mac);
static void housekeeping_disable(struct zd_mac *mac);
int zd_mac_init(struct zd_mac *mac,
struct net_device *netdev,
struct usb_interface *intf)
{
struct ieee80211_device *ieee = zd_netdev_ieee80211(netdev);
memset(mac, 0, sizeof(*mac));
spin_lock_init(&mac->lock);
mac->netdev = netdev;
ieee_init(ieee);
softmac_init(ieee80211_priv(netdev));
zd_chip_init(&mac->chip, netdev, intf);
housekeeping_init(mac);
return 0;
}
static int reset_channel(struct zd_mac *mac)
{
int r;
unsigned long flags;
const struct channel_range *range;
spin_lock_irqsave(&mac->lock, flags);
range = zd_channel_range(mac->regdomain);
if (!range->start) {
r = -EINVAL;
goto out;
}
mac->requested_channel = range->start;
r = 0;
out:
spin_unlock_irqrestore(&mac->lock, flags);
return r;
}
int zd_mac_init_hw(struct zd_mac *mac, u8 device_type)
{
int r;
struct zd_chip *chip = &mac->chip;
u8 addr[ETH_ALEN];
u8 default_regdomain;
r = zd_chip_enable_int(chip);
if (r)
goto out;
r = zd_chip_init_hw(chip, device_type);
if (r)
goto disable_int;
zd_get_e2p_mac_addr(chip, addr);
r = zd_write_mac_addr(chip, addr);
if (r)
goto disable_int;
ZD_ASSERT(!irqs_disabled());
spin_lock_irq(&mac->lock);
memcpy(mac->netdev->dev_addr, addr, ETH_ALEN);
spin_unlock_irq(&mac->lock);
r = zd_read_regdomain(chip, &default_regdomain);
if (r)
goto disable_int;
if (!zd_regdomain_supported(default_regdomain)) {
dev_dbg_f(zd_mac_dev(mac),
"Regulatory Domain %#04x is not supported.\n",
default_regdomain);
r = -EINVAL;
goto disable_int;
}
spin_lock_irq(&mac->lock);
mac->regdomain = mac->default_regdomain = default_regdomain;
spin_unlock_irq(&mac->lock);
r = reset_channel(mac);
if (r)
goto disable_int;
/* We must inform the device that we are doing encryption/decryption in
* software at the moment. */
<