Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[pandora-kernel.git] / drivers / net / wireless / orinoco / main.c
index 413e9ab..1d60c7e 100644 (file)
@@ -254,7 +254,7 @@ void set_port_type(struct orinoco_private *priv)
 /* Device methods                                                   */
 /********************************************************************/
 
-static int orinoco_open(struct net_device *dev)
+int orinoco_open(struct net_device *dev)
 {
        struct orinoco_private *priv = ndev_priv(dev);
        unsigned long flags;
@@ -272,8 +272,9 @@ static int orinoco_open(struct net_device *dev)
 
        return err;
 }
+EXPORT_SYMBOL(orinoco_open);
 
-static int orinoco_stop(struct net_device *dev)
+int orinoco_stop(struct net_device *dev)
 {
        struct orinoco_private *priv = ndev_priv(dev);
        int err = 0;
@@ -281,25 +282,27 @@ static int orinoco_stop(struct net_device *dev)
        /* We mustn't use orinoco_lock() here, because we need to be
           able to close the interface even if hw_unavailable is set
           (e.g. as we're released after a PC Card removal) */
-       spin_lock_irq(&priv->lock);
+       orinoco_lock_irq(priv);
 
        priv->open = 0;
 
        err = __orinoco_down(priv);
 
-       spin_unlock_irq(&priv->lock);
+       orinoco_unlock_irq(priv);
 
        return err;
 }
+EXPORT_SYMBOL(orinoco_stop);
 
-static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
+struct net_device_stats *orinoco_get_stats(struct net_device *dev)
 {
        struct orinoco_private *priv = ndev_priv(dev);
 
        return &priv->stats;
 }
+EXPORT_SYMBOL(orinoco_get_stats);
 
-static void orinoco_set_multicast_list(struct net_device *dev)
+void orinoco_set_multicast_list(struct net_device *dev)
 {
        struct orinoco_private *priv = ndev_priv(dev);
        unsigned long flags;
@@ -313,8 +316,9 @@ static void orinoco_set_multicast_list(struct net_device *dev)
        __orinoco_set_multicast_list(dev);
        orinoco_unlock(priv, &flags);
 }
+EXPORT_SYMBOL(orinoco_set_multicast_list);
 
-static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
+int orinoco_change_mtu(struct net_device *dev, int new_mtu)
 {
        struct orinoco_private *priv = ndev_priv(dev);
 
@@ -330,6 +334,7 @@ static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
 
        return 0;
 }
+EXPORT_SYMBOL(orinoco_change_mtu);
 
 /********************************************************************/
 /* Tx path                                                          */
@@ -400,8 +405,8 @@ static netdev_tx_t orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
                memset(&desc, 0, sizeof(desc));
 
                *txcntl = cpu_to_le16(tx_control);
-               err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
-                                       txfid, 0);
+               err = hw->ops->bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
+                                         txfid, 0);
                if (err) {
                        if (net_ratelimit())
                                printk(KERN_ERR "%s: Error %d writing Tx "
@@ -414,8 +419,8 @@ static netdev_tx_t orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
                memset(&desc, 0, sizeof(desc));
 
                desc.tx_control = cpu_to_le16(tx_control);
-               err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
-                                       txfid, 0);
+               err = hw->ops->bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
+                                         txfid, 0);
                if (err) {
                        if (net_ratelimit())
                                printk(KERN_ERR "%s: Error %d writing Tx "
@@ -458,8 +463,8 @@ static netdev_tx_t orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
                memcpy(eh, &hdr, sizeof(hdr));
        }
 
-       err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
-                               txfid, HERMES_802_3_OFFSET);
+       err = hw->ops->bap_pwrite(hw, USER_BAP, skb->data, skb->len,
+                                 txfid, HERMES_802_3_OFFSET);
        if (err) {
                printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
                       dev->name, err);
@@ -490,8 +495,8 @@ static netdev_tx_t orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
                            skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
 
                /* Write the MIC */
-               err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
-                                       txfid, HERMES_802_3_OFFSET + offset);
+               err = hw->ops->bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
+                                         txfid, HERMES_802_3_OFFSET + offset);
                if (err) {
                        printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
                               dev->name, err);
@@ -502,7 +507,7 @@ static netdev_tx_t orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
        /* Finally, we actually initiate the send */
        netif_stop_queue(dev);
 
-       err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
+       err = hw->ops->cmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
                                txfid, NULL);
        if (err) {
                netif_start_queue(dev);
@@ -572,9 +577,9 @@ static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
                return; /* Nothing's really happened */
 
        /* Read part of the frame header - we need status and addr1 */
-       err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
-                              sizeof(struct hermes_txexc_data),
-                              fid, 0);
+       err = hw->ops->bap_pread(hw, IRQ_BAP, &hdr,
+                                sizeof(struct hermes_txexc_data),
+                                fid, 0);
 
        hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
        stats->tx_errors++;
@@ -615,7 +620,7 @@ static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
        netif_wake_queue(dev);
 }
 
-static void orinoco_tx_timeout(struct net_device *dev)
+void orinoco_tx_timeout(struct net_device *dev)
 {
        struct orinoco_private *priv = ndev_priv(dev);
        struct net_device_stats *stats = &priv->stats;
@@ -630,6 +635,7 @@ static void orinoco_tx_timeout(struct net_device *dev)
 
        schedule_work(&priv->reset_work);
 }
+EXPORT_SYMBOL(orinoco_tx_timeout);
 
 /********************************************************************/
 /* Rx path (data frames)                                            */
@@ -764,9 +770,9 @@ static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
 
        /* If any, copy the data from the card to the skb */
        if (datalen > 0) {
-               err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
-                                      ALIGN(datalen, 2), rxfid,
-                                      HERMES_802_2_OFFSET);
+               err = hw->ops->bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
+                                        ALIGN(datalen, 2), rxfid,
+                                        HERMES_802_2_OFFSET);
                if (err) {
                        printk(KERN_ERR "%s: error %d reading monitor frame\n",
                               dev->name, err);
@@ -792,7 +798,7 @@ static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
        stats->rx_dropped++;
 }
 
-static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
+void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
 {
        struct orinoco_private *priv = ndev_priv(dev);
        struct net_device_stats *stats = &priv->stats;
@@ -814,8 +820,8 @@ static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
 
        rxfid = hermes_read_regn(hw, RXFID);
 
-       err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
-                              rxfid, 0);
+       err = hw->ops->bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
+                                rxfid, 0);
        if (err) {
                printk(KERN_ERR "%s: error %d reading Rx descriptor. "
                       "Frame dropped.\n", dev->name, err);
@@ -882,9 +888,9 @@ static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
           nothing is removed.  2 is for aligning the IP header.  */
        skb_reserve(skb, ETH_HLEN + 2);
 
-       err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
-                              ALIGN(length, 2), rxfid,
-                              HERMES_802_2_OFFSET);
+       err = hw->ops->bap_pread(hw, IRQ_BAP, skb_put(skb, length),
+                                ALIGN(length, 2), rxfid,
+                                HERMES_802_2_OFFSET);
        if (err) {
                printk(KERN_ERR "%s: error %d reading frame. "
                       "Frame dropped.\n", dev->name, err);
@@ -913,6 +919,7 @@ update_stats:
 out:
        kfree(desc);
 }
+EXPORT_SYMBOL(__orinoco_ev_rx);
 
 static void orinoco_rx(struct net_device *dev,
                       struct hermes_rx_descriptor *desc,
@@ -1145,9 +1152,9 @@ static void orinoco_join_ap(struct work_struct *work)
                goto out;
 
        /* Read scan results from the firmware */
-       err = hermes_read_ltv(hw, USER_BAP,
-                             HERMES_RID_SCANRESULTSTABLE,
-                             MAX_SCAN_LEN, &len, buf);
+       err = hw->ops->read_ltv(hw, USER_BAP,
+                               HERMES_RID_SCANRESULTSTABLE,
+                               MAX_SCAN_LEN, &len, buf);
        if (err) {
                printk(KERN_ERR "%s: Cannot read scan results\n",
                       dev->name);
@@ -1194,8 +1201,8 @@ static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
        union iwreq_data wrqu;
        int err;
 
-       err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
-                             ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
+       err = hw->ops->read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
+                               ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
        if (err != 0)
                return;
 
@@ -1217,8 +1224,8 @@ static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
        if (!priv->has_wpa)
                return;
 
-       err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
-                             sizeof(buf), NULL, &buf);
+       err = hw->ops->read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
+                               sizeof(buf), NULL, &buf);
        if (err != 0)
                return;
 
@@ -1247,8 +1254,9 @@ static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
        if (!priv->has_wpa)
                return;
 
-       err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
-                             sizeof(buf), NULL, &buf);
+       err = hw->ops->read_ltv(hw, USER_BAP,
+                               HERMES_RID_CURRENT_ASSOC_RESP_INFO,
+                               sizeof(buf), NULL, &buf);
        if (err != 0)
                return;
 
@@ -1353,7 +1361,7 @@ static void orinoco_process_scan_results(struct work_struct *work)
        spin_unlock_irqrestore(&priv->scan_lock, flags);
 }
 
-static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
+void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
 {
        struct orinoco_private *priv = ndev_priv(dev);
        u16 infofid;
@@ -1371,8 +1379,8 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
        infofid = hermes_read_regn(hw, INFOFID);
 
        /* Read the info frame header - don't try too hard */
-       err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
-                              infofid, 0);
+       err = hw->ops->bap_pread(hw, IRQ_BAP, &info, sizeof(info),
+                                infofid, 0);
        if (err) {
                printk(KERN_ERR "%s: error %d reading info frame. "
                       "Frame dropped.\n", dev->name, err);
@@ -1393,8 +1401,8 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
                        len = sizeof(tallies);
                }
 
-               err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
-                                      infofid, sizeof(info));
+               err = hw->ops->bap_pread(hw, IRQ_BAP, &tallies, len,
+                                        infofid, sizeof(info));
                if (err)
                        break;
 
@@ -1429,8 +1437,8 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
                        break;
                }
 
-               err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
-                                      infofid, sizeof(info));
+               err = hw->ops->bap_pread(hw, IRQ_BAP, &linkstatus, len,
+                                        infofid, sizeof(info));
                if (err)
                        break;
                newstatus = le16_to_cpu(linkstatus.linkstatus);
@@ -1494,8 +1502,8 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
                }
 
                /* Read scan data */
-               err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
-                                      infofid, sizeof(info));
+               err = hw->ops->bap_pread(hw, IRQ_BAP, (void *) buf, len,
+                                        infofid, sizeof(info));
                if (err) {
                        kfree(buf);
                        qabort_scan(priv);
@@ -1547,8 +1555,8 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
                        break;
 
                /* Read scan data */
-               err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
-                                      infofid, sizeof(info));
+               err = hw->ops->bap_pread(hw, IRQ_BAP, (void *) bss, len,
+                                        infofid, sizeof(info));
                if (err)
                        kfree(bss);
                else
@@ -1571,6 +1579,7 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
 
        return;
 }
+EXPORT_SYMBOL(__orinoco_ev_info);
 
 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
 {
@@ -1647,7 +1656,7 @@ static int orinoco_reinit_firmware(struct orinoco_private *priv)
        struct hermes *hw = &priv->hw;
        int err;
 
-       err = hermes_init(hw);
+       err = hw->ops->init(hw);
        if (priv->do_fw_download && !err) {
                err = orinoco_download(priv);
                if (err)
@@ -1735,7 +1744,7 @@ void orinoco_reset(struct work_struct *work)
        }
 
        /* This has to be called from user context */
-       spin_lock_irq(&priv->lock);
+       orinoco_lock_irq(priv);
 
        priv->hw_unavailable--;
 
@@ -1750,7 +1759,7 @@ void orinoco_reset(struct work_struct *work)
                        dev->trans_start = jiffies;
        }
 
-       spin_unlock_irq(&priv->lock);
+       orinoco_unlock_irq(priv);
 
        return;
  disable:
@@ -1984,7 +1993,7 @@ int orinoco_init(struct orinoco_private *priv)
        priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
 
        /* Initialize the firmware */
-       err = hermes_init(hw);
+       err = hw->ops->init(hw);
        if (err != 0) {
                dev_err(dev, "Failed to initialize firmware (err = %d)\n",
                        err);
@@ -2067,9 +2076,9 @@ int orinoco_init(struct orinoco_private *priv)
 
        /* Make the hardware available, as long as it hasn't been
         * removed elsewhere (e.g. by PCMCIA hot unplug) */
-       spin_lock_irq(&priv->lock);
+       orinoco_lock_irq(priv);
        priv->hw_unavailable--;
-       spin_unlock_irq(&priv->lock);
+       orinoco_unlock_irq(priv);
 
        dev_dbg(dev, "Ready\n");
 
@@ -2192,7 +2201,8 @@ EXPORT_SYMBOL(alloc_orinocodev);
  */
 int orinoco_if_add(struct orinoco_private *priv,
                   unsigned long base_addr,
-                  unsigned int irq)
+                  unsigned int irq,
+                  const struct net_device_ops *ops)
 {
        struct wiphy *wiphy = priv_to_wiphy(priv);
        struct wireless_dev *wdev;
@@ -2211,12 +2221,17 @@ int orinoco_if_add(struct orinoco_private *priv,
 
        /* Setup / override net_device fields */
        dev->ieee80211_ptr = wdev;
-       dev->netdev_ops = &orinoco_netdev_ops;
        dev->watchdog_timeo = HZ; /* 1 second timeout */
        dev->wireless_handlers = &orinoco_handler_def;
 #ifdef WIRELESS_SPY
        dev->wireless_data = &priv->wireless_data;
 #endif
+       /* Default to standard ops if not set */
+       if (ops)
+               dev->netdev_ops = ops;
+       else
+               dev->netdev_ops = &orinoco_netdev_ops;
+
        /* we use the default eth_mac_addr for setting the MAC addr */
 
        /* Reserve space in skb for the SNAP header */
@@ -2305,7 +2320,7 @@ int orinoco_up(struct orinoco_private *priv)
        unsigned long flags;
        int err;
 
-       spin_lock_irqsave(&priv->lock, flags);
+       priv->hw.ops->lock_irqsave(&priv->lock, &flags);
 
        err = orinoco_reinit_firmware(priv);
        if (err) {
@@ -2325,7 +2340,7 @@ int orinoco_up(struct orinoco_private *priv)
        }
 
 exit:
-       spin_unlock_irqrestore(&priv->lock, flags);
+       priv->hw.ops->unlock_irqrestore(&priv->lock, &flags);
 
        return 0;
 }
@@ -2337,7 +2352,7 @@ void orinoco_down(struct orinoco_private *priv)
        unsigned long flags;
        int err;
 
-       spin_lock_irqsave(&priv->lock, flags);
+       priv->hw.ops->lock_irqsave(&priv->lock, &flags);
        err = __orinoco_down(priv);
        if (err)
                printk(KERN_WARNING "%s: Error %d downing interface\n",
@@ -2345,7 +2360,7 @@ void orinoco_down(struct orinoco_private *priv)
 
        netif_device_detach(dev);
        priv->hw_unavailable++;
-       spin_unlock_irqrestore(&priv->lock, flags);
+       priv->hw.ops->unlock_irqrestore(&priv->lock, &flags);
 }
 EXPORT_SYMBOL(orinoco_down);