]> err.no Git - linux-2.6/blobdiff - drivers/net/wireless/rtl8187_dev.c
libertas: convert sleep/wake config direct commands
[linux-2.6] / drivers / net / wireless / rtl8187_dev.c
index 0ef887dd286795fe0cf22a24b019b845362dae48..c03834d5cb0b531a164d58992d06655181376ed9 100644 (file)
@@ -38,11 +38,45 @@ static struct usb_device_id rtl8187_table[] __devinitdata = {
        {USB_DEVICE(0x0846, 0x6a00)},
        /* HP */
        {USB_DEVICE(0x03f0, 0xca02)},
+       /* Sitecom */
+       {USB_DEVICE(0x0df6, 0x000d)},
        {}
 };
 
 MODULE_DEVICE_TABLE(usb, rtl8187_table);
 
+static const struct ieee80211_rate rtl818x_rates[] = {
+       { .bitrate = 10, .hw_value = 0, },
+       { .bitrate = 20, .hw_value = 1, },
+       { .bitrate = 55, .hw_value = 2, },
+       { .bitrate = 110, .hw_value = 3, },
+       { .bitrate = 60, .hw_value = 4, },
+       { .bitrate = 90, .hw_value = 5, },
+       { .bitrate = 120, .hw_value = 6, },
+       { .bitrate = 180, .hw_value = 7, },
+       { .bitrate = 240, .hw_value = 8, },
+       { .bitrate = 360, .hw_value = 9, },
+       { .bitrate = 480, .hw_value = 10, },
+       { .bitrate = 540, .hw_value = 11, },
+};
+
+static const struct ieee80211_channel rtl818x_channels[] = {
+       { .center_freq = 2412 },
+       { .center_freq = 2417 },
+       { .center_freq = 2422 },
+       { .center_freq = 2427 },
+       { .center_freq = 2432 },
+       { .center_freq = 2437 },
+       { .center_freq = 2442 },
+       { .center_freq = 2447 },
+       { .center_freq = 2452 },
+       { .center_freq = 2457 },
+       { .center_freq = 2462 },
+       { .center_freq = 2467 },
+       { .center_freq = 2472 },
+       { .center_freq = 2484 },
+};
+
 static void rtl8187_iowrite_async_cb(struct urb *urb)
 {
        kfree(urb->context);
@@ -111,10 +145,12 @@ void rtl8187_write_phy(struct ieee80211_hw *dev, u8 addr, u32 data)
 
 static void rtl8187_tx_cb(struct urb *urb)
 {
-       struct ieee80211_tx_status status = { {0} };
+       struct ieee80211_tx_status status;
        struct sk_buff *skb = (struct sk_buff *)urb->context;
        struct rtl8187_tx_info *info = (struct rtl8187_tx_info *)skb->cb;
 
+       memset(&status, 0, sizeof(status));
+
        usb_free_urb(info->urb);
        if (info->control)
                memcpy(&status.control, info->control, sizeof(status.control));
@@ -131,7 +167,8 @@ static int rtl8187_tx(struct ieee80211_hw *dev, struct sk_buff *skb,
        struct rtl8187_tx_hdr *hdr;
        struct rtl8187_tx_info *info;
        struct urb *urb;
-       u32 tmp;
+       __le16 rts_dur = 0;
+       u32 flags;
 
        urb = usb_alloc_urb(0, GFP_ATOMIC);
        if (!urb) {
@@ -139,24 +176,31 @@ static int rtl8187_tx(struct ieee80211_hw *dev, struct sk_buff *skb,
                return 0;
        }
 
-       hdr = (struct rtl8187_tx_hdr *)skb_push(skb, sizeof(*hdr));
-       tmp = skb->len - sizeof(*hdr);
-       tmp |= RTL8187_TX_FLAG_NO_ENCRYPT;
-       tmp |= control->rts_cts_rate << 19;
-       tmp |= control->tx_rate << 24;
-       if (ieee80211_get_morefrag((struct ieee80211_hdr *)skb))
-               tmp |= RTL8187_TX_FLAG_MORE_FRAG;
+       flags = skb->len;
+       flags |= RTL8187_TX_FLAG_NO_ENCRYPT;
+
+       BUG_ON(!control->tx_rate);
+
+       flags |= control->tx_rate->hw_value << 24;
+       if (ieee80211_get_morefrag((struct ieee80211_hdr *)skb->data))
+               flags |= RTL8187_TX_FLAG_MORE_FRAG;
        if (control->flags & IEEE80211_TXCTL_USE_RTS_CTS) {
-               tmp |= RTL8187_TX_FLAG_RTS;
-               hdr->rts_duration =
-                       ieee80211_rts_duration(dev, priv->if_id, skb->len, control);
+               BUG_ON(!control->rts_cts_rate);
+               flags |= RTL8187_TX_FLAG_RTS;
+               flags |= control->rts_cts_rate->hw_value << 19;
+               rts_dur = ieee80211_rts_duration(dev, priv->vif,
+                                                skb->len, control);
+       } else if (control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
+               BUG_ON(!control->rts_cts_rate);
+               flags |= RTL8187_TX_FLAG_CTS;
+               flags |= control->rts_cts_rate->hw_value << 19;
        }
-       if (control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)
-               tmp |= RTL8187_TX_FLAG_CTS;
-       hdr->flags = cpu_to_le32(tmp);
+
+       hdr = (struct rtl8187_tx_hdr *)skb_push(skb, sizeof(*hdr));
+       hdr->flags = cpu_to_le32(flags);
        hdr->len = 0;
-       tmp = control->retry_limit << 8;
-       hdr->retry = cpu_to_le32(tmp);
+       hdr->rts_duration = rts_dur;
+       hdr->retry = cpu_to_le32(control->retry_limit << 8);
 
        info = (struct rtl8187_tx_info *)skb->cb;
        info->control = kmemdup(control, sizeof(*control), GFP_ATOMIC);
@@ -219,11 +263,11 @@ static void rtl8187_rx_cb(struct urb *urb)
        rx_status.antenna = (hdr->signal >> 7) & 1;
        rx_status.signal = 64 - min(hdr->noise, (u8)64);
        rx_status.ssi = signal;
-       rx_status.rate = rate;
-       rx_status.freq = dev->conf.freq;
-       rx_status.channel = dev->conf.channel;
-       rx_status.phymode = dev->conf.phymode;
+       rx_status.rate_idx = rate;
+       rx_status.freq = dev->conf.channel->center_freq;
+       rx_status.band = dev->conf.channel->band;
        rx_status.mactime = le64_to_cpu(hdr->mac_time);
+       rx_status.flag |= RX_FLAG_TSFT;
        if (flags & (1 << 13))
                rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
        ieee80211_rx_irqsafe(dev, skb, &rx_status);
@@ -389,37 +433,19 @@ static int rtl8187_init_hw(struct ieee80211_hw *dev)
        rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FF7);
        msleep(100);
 
-       priv->rf_init(dev);
+       priv->rf->init(dev);
 
        rtl818x_iowrite16(priv, &priv->map->BRSR, 0x01F3);
-       reg = rtl818x_ioread16(priv, &priv->map->PGSELECT) & 0xfffe;
-       rtl818x_iowrite16(priv, &priv->map->PGSELECT, reg | 0x1);
+       reg = rtl818x_ioread8(priv, &priv->map->PGSELECT) & ~1;
+       rtl818x_iowrite8(priv, &priv->map->PGSELECT, reg | 1);
        rtl818x_iowrite16(priv, (__le16 *)0xFFFE, 0x10);
        rtl818x_iowrite8(priv, &priv->map->TALLY_SEL, 0x80);
        rtl818x_iowrite8(priv, (u8 *)0xFFFF, 0x60);
-       rtl818x_iowrite16(priv, &priv->map->PGSELECT, reg);
+       rtl818x_iowrite8(priv, &priv->map->PGSELECT, reg);
 
        return 0;
 }
 
-static void rtl8187_set_channel(struct ieee80211_hw *dev, int channel)
-{
-       u32 reg;
-       struct rtl8187_priv *priv = dev->priv;
-
-       reg = rtl818x_ioread32(priv, &priv->map->TX_CONF);
-       /* Enable TX loopback on MAC level to avoid TX during channel
-        * changes, as this has be seen to causes problems and the
-        * card will stop work until next reset
-        */
-       rtl818x_iowrite32(priv, &priv->map->TX_CONF,
-                         reg | RTL818X_TX_CONF_LOOPBACK_MAC);
-       msleep(10);
-       rtl8225_rf_set_channel(dev, channel);
-       msleep(10);
-       rtl818x_iowrite32(priv, &priv->map->TX_CONF, reg);
-}
-
 static int rtl8187_start(struct ieee80211_hw *dev)
 {
        struct rtl8187_priv *priv = dev->priv;
@@ -432,6 +458,9 @@ static int rtl8187_start(struct ieee80211_hw *dev)
 
        rtl818x_iowrite16(priv, &priv->map->INT_MASK, 0xFFFF);
 
+       rtl818x_iowrite32(priv, &priv->map->MAR[0], ~0);
+       rtl818x_iowrite32(priv, &priv->map->MAR[1], ~0);
+
        rtl8187_init_urbs(dev);
 
        reg = RTL818X_RX_CONF_ONLYERLPKT |
@@ -485,7 +514,7 @@ static void rtl8187_stop(struct ieee80211_hw *dev)
        reg &= ~RTL818X_CMD_RX_ENABLE;
        rtl818x_iowrite8(priv, &priv->map->CMD, reg);
 
-       rtl8225_rf_stop(dev);
+       priv->rf->stop(dev);
 
        rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
        reg = rtl818x_ioread8(priv, &priv->map->CONFIG4);
@@ -536,7 +565,19 @@ static void rtl8187_remove_interface(struct ieee80211_hw *dev,
 static int rtl8187_config(struct ieee80211_hw *dev, struct ieee80211_conf *conf)
 {
        struct rtl8187_priv *priv = dev->priv;
-       rtl8187_set_channel(dev, conf->channel);
+       u32 reg;
+
+       reg = rtl818x_ioread32(priv, &priv->map->TX_CONF);
+       /* Enable TX loopback on MAC level to avoid TX during channel
+        * changes, as this has be seen to causes problems and the
+        * card will stop work until next reset
+        */
+       rtl818x_iowrite32(priv, &priv->map->TX_CONF,
+                         reg | RTL818X_TX_CONF_LOOPBACK_MAC);
+       msleep(10);
+       priv->rf->set_chan(dev, conf);
+       msleep(10);
+       rtl818x_iowrite32(priv, &priv->map->TX_CONF, reg);
 
        rtl818x_iowrite8(priv, &priv->map->SIFS, 0x22);
 
@@ -559,14 +600,13 @@ static int rtl8187_config(struct ieee80211_hw *dev, struct ieee80211_conf *conf)
        return 0;
 }
 
-static int rtl8187_config_interface(struct ieee80211_hw *dev, int if_id,
+static int rtl8187_config_interface(struct ieee80211_hw *dev,
+                                   struct ieee80211_vif *vif,
                                    struct ieee80211_if_conf *conf)
 {
        struct rtl8187_priv *priv = dev->priv;
        int i;
 
-       priv->if_id = if_id;
-
        for (i = 0; i < ETH_ALEN; i++)
                rtl818x_iowrite8(priv, &priv->map->BSSID[i], conf->bssid[i]);
 
@@ -581,36 +621,31 @@ static int rtl8187_config_interface(struct ieee80211_hw *dev, int if_id,
 static void rtl8187_configure_filter(struct ieee80211_hw *dev,
                                     unsigned int changed_flags,
                                     unsigned int *total_flags,
-                                    int mc_count, struct dev_addr_list *mc_list)
+                                    int mc_count, struct dev_addr_list *mclist)
 {
        struct rtl8187_priv *priv = dev->priv;
 
-       *total_flags = 0;
-
-       if (changed_flags & FIF_PROMISC_IN_BSS)
-               priv->rx_conf ^= RTL818X_RX_CONF_NICMAC;
-       if (changed_flags & FIF_ALLMULTI)
-               priv->rx_conf ^= RTL818X_RX_CONF_MULTICAST;
        if (changed_flags & FIF_FCSFAIL)
                priv->rx_conf ^= RTL818X_RX_CONF_FCS;
        if (changed_flags & FIF_CONTROL)
                priv->rx_conf ^= RTL818X_RX_CONF_CTRL;
        if (changed_flags & FIF_OTHER_BSS)
                priv->rx_conf ^= RTL818X_RX_CONF_MONITOR;
-
-       if (mc_count > 0)
+       if (*total_flags & FIF_ALLMULTI || mc_count > 0)
                priv->rx_conf |= RTL818X_RX_CONF_MULTICAST;
+       else
+               priv->rx_conf &= ~RTL818X_RX_CONF_MULTICAST;
+
+       *total_flags = 0;
 
-       if (priv->rx_conf & RTL818X_RX_CONF_NICMAC)
-               *total_flags |= FIF_PROMISC_IN_BSS;
-       if (priv->rx_conf & RTL818X_RX_CONF_MULTICAST)
-               *total_flags |= FIF_ALLMULTI;
        if (priv->rx_conf & RTL818X_RX_CONF_FCS)
                *total_flags |= FIF_FCSFAIL;
        if (priv->rx_conf & RTL818X_RX_CONF_CTRL)
                *total_flags |= FIF_CONTROL;
        if (priv->rx_conf & RTL818X_RX_CONF_MONITOR)
                *total_flags |= FIF_OTHER_BSS;
+       if (priv->rx_conf & RTL818X_RX_CONF_MULTICAST)
+               *total_flags |= FIF_ALLMULTI;
 
        rtl818x_iowrite32_async(priv, &priv->map->RX_CONF, priv->rx_conf);
 }
@@ -684,19 +719,22 @@ static int __devinit rtl8187_probe(struct usb_interface *intf,
        usb_get_dev(udev);
 
        skb_queue_head_init(&priv->rx_queue);
+
+       BUILD_BUG_ON(sizeof(priv->channels) != sizeof(rtl818x_channels));
+       BUILD_BUG_ON(sizeof(priv->rates) != sizeof(rtl818x_rates));
+
        memcpy(priv->channels, rtl818x_channels, sizeof(rtl818x_channels));
        memcpy(priv->rates, rtl818x_rates, sizeof(rtl818x_rates));
        priv->map = (struct rtl818x_csr *)0xFF00;
-       priv->modes[0].mode = MODE_IEEE80211G;
-       priv->modes[0].num_rates = ARRAY_SIZE(rtl818x_rates);
-       priv->modes[0].rates = priv->rates;
-       priv->modes[0].num_channels = ARRAY_SIZE(rtl818x_channels);
-       priv->modes[0].channels = priv->channels;
-       priv->modes[1].mode = MODE_IEEE80211B;
-       priv->modes[1].num_rates = 4;
-       priv->modes[1].rates = priv->rates;
-       priv->modes[1].num_channels = ARRAY_SIZE(rtl818x_channels);
-       priv->modes[1].channels = priv->channels;
+
+       priv->band.band = IEEE80211_BAND_2GHZ;
+       priv->band.channels = priv->channels;
+       priv->band.n_channels = ARRAY_SIZE(rtl818x_channels);
+       priv->band.bitrates = priv->rates;
+       priv->band.n_bitrates = ARRAY_SIZE(rtl818x_rates);
+       dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
+
+
        priv->mode = IEEE80211_IF_TYPE_MNTR;
        dev->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
                     IEEE80211_HW_RX_INCLUDES_FCS;
@@ -705,10 +743,6 @@ static int __devinit rtl8187_probe(struct usb_interface *intf,
        dev->max_rssi = 65;
        dev->max_signal = 64;
 
-       for (i = 0; i < 2; i++)
-               if ((err = ieee80211_register_hwmode(dev, &priv->modes[i])))
-                       goto err_free_dev;
-
        eeprom.data = dev;
        eeprom.register_read = rtl8187_eeprom_register_read;
        eeprom.register_write = rtl8187_eeprom_register_write;
@@ -732,42 +766,35 @@ static int __devinit rtl8187_probe(struct usb_interface *intf,
        for (i = 0; i < 3; i++) {
                eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_CHAN_1 + i,
                                  &txpwr);
-               (*channel++).val = txpwr & 0xFF;
-               (*channel++).val = txpwr >> 8;
+               (*channel++).hw_value = txpwr & 0xFF;
+               (*channel++).hw_value = txpwr >> 8;
        }
        for (i = 0; i < 2; i++) {
                eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_CHAN_4 + i,
                                  &txpwr);
-               (*channel++).val = txpwr & 0xFF;
-               (*channel++).val = txpwr >> 8;
+               (*channel++).hw_value = txpwr & 0xFF;
+               (*channel++).hw_value = txpwr >> 8;
        }
        for (i = 0; i < 2; i++) {
                eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_CHAN_6 + i,
                                  &txpwr);
-               (*channel++).val = txpwr & 0xFF;
-               (*channel++).val = txpwr >> 8;
+               (*channel++).hw_value = txpwr & 0xFF;
+               (*channel++).hw_value = txpwr >> 8;
        }
 
        eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_BASE,
                          &priv->txpwr_base);
 
-       reg = rtl818x_ioread16(priv, &priv->map->PGSELECT) & ~1;
-       rtl818x_iowrite16(priv, &priv->map->PGSELECT, reg | 1);
+       reg = rtl818x_ioread8(priv, &priv->map->PGSELECT) & ~1;
+       rtl818x_iowrite8(priv, &priv->map->PGSELECT, reg | 1);
        /* 0 means asic B-cut, we should use SW 3 wire
         * bit-by-bit banging for radio. 1 means we can use
         * USB specific request to write radio registers */
        priv->asic_rev = rtl818x_ioread8(priv, (u8 *)0xFFFE) & 0x3;
-       rtl818x_iowrite16(priv, &priv->map->PGSELECT, reg);
+       rtl818x_iowrite8(priv, &priv->map->PGSELECT, reg);
        rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
 
-       rtl8225_write(dev, 0, 0x1B7);
-
-       if (rtl8225_read(dev, 8) != 0x588 || rtl8225_read(dev, 9) != 0x700)
-               priv->rf_init = rtl8225_rf_init;
-       else
-               priv->rf_init = rtl8225z2_rf_init;
-
-       rtl8225_write(dev, 0, 0x0B7);
+       priv->rf = rtl8187_detect_rf(dev);
 
        err = ieee80211_register_hw(dev);
        if (err) {
@@ -777,8 +804,7 @@ static int __devinit rtl8187_probe(struct usb_interface *intf,
 
        printk(KERN_INFO "%s: hwaddr %s, rtl8187 V%d + %s\n",
               wiphy_name(dev->wiphy), print_mac(mac, dev->wiphy->perm_addr),
-              priv->asic_rev, priv->rf_init == rtl8225_rf_init ?
-              "rtl8225" : "rtl8225z2");
+              priv->asic_rev, priv->rf->name);
 
        return 0;