aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/orinoco/main.c
diff options
context:
space:
mode:
authorDavid Kilroy <kilroyd@googlemail.com>2009-02-04 18:05:53 -0500
committerJohn W. Linville <linville@tuxdriver.com>2009-02-13 13:44:27 -0500
commitcfeb1db6db80435ccf1f9b18ea71bb233f7db20c (patch)
tree2ee2486019315dcf770310345d89517f1d0d45f2 /drivers/net/wireless/orinoco/main.c
parent37a2e566f82de9a88fe119479162f9984af2180d (diff)
orinoco: Use accessor functions for bitrate tables
... when used by the WEXT ioctl functions. This will allow us to separate the card specific stuff from the WEXT code. Signed-off-by: David Kilroy <kilroyd@googlemail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/orinoco/main.c')
-rw-r--r--drivers/net/wireless/orinoco/main.c140
1 files changed, 81 insertions, 59 deletions
diff --git a/drivers/net/wireless/orinoco/main.c b/drivers/net/wireless/orinoco/main.c
index f49cabd70877..c5aad88e54d9 100644
--- a/drivers/net/wireless/orinoco/main.c
+++ b/drivers/net/wireless/orinoco/main.c
@@ -282,6 +282,33 @@ static inline void set_port_type(struct orinoco_private *priv)
282 } 282 }
283} 283}
284 284
285static int orinoco_get_bitratemode(int bitrate, int automatic)
286{
287 int ratemode = -1;
288 int i;
289
290 if ((bitrate != 10) && (bitrate != 20) &&
291 (bitrate != 55) && (bitrate != 110))
292 return ratemode;
293
294 for (i = 0; i < BITRATE_TABLE_SIZE; i++) {
295 if ((bitrate_table[i].bitrate == bitrate) &&
296 (bitrate_table[i].automatic == automatic)) {
297 ratemode = i;
298 break;
299 }
300 }
301 return ratemode;
302}
303
304static void orinoco_get_ratemode_cfg(int ratemode, int *bitrate, int *automatic)
305{
306 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
307
308 *bitrate = bitrate_table[ratemode].bitrate * 100000;
309 *automatic = bitrate_table[ratemode].automatic;
310}
311
285static inline u8 *orinoco_get_ie(u8 *data, size_t len, 312static inline u8 *orinoco_get_ie(u8 *data, size_t len,
286 enum ieee80211_eid eid) 313 enum ieee80211_eid eid)
287{ 314{
@@ -1794,6 +1821,50 @@ static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1794 return err; 1821 return err;
1795} 1822}
1796 1823
1824static int orinoco_hw_get_act_bitrate(struct orinoco_private *priv,
1825 int *bitrate)
1826{
1827 hermes_t *hw = &priv->hw;
1828 int i;
1829 int err = 0;
1830 u16 val;
1831
1832 err = hermes_read_wordrec(hw, USER_BAP,
1833 HERMES_RID_CURRENTTXRATE, &val);
1834 if (err)
1835 return err;
1836
1837 switch (priv->firmware_type) {
1838 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
1839 /* Note : in Lucent firmware, the return value of
1840 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
1841 * and therefore is totally different from the
1842 * encoding of HERMES_RID_CNFTXRATECONTROL.
1843 * Don't forget that 6Mb/s is really 5.5Mb/s */
1844 if (val == 6)
1845 *bitrate = 5500000;
1846 else
1847 *bitrate = val * 1000000;
1848 break;
1849 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
1850 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
1851 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
1852 if (bitrate_table[i].intersil_txratectrl == val)
1853 break;
1854
1855 if (i >= BITRATE_TABLE_SIZE)
1856 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
1857 priv->ndev->name, val);
1858
1859 *bitrate = bitrate_table[i].bitrate * 100000;
1860 break;
1861 default:
1862 BUG();
1863 }
1864
1865 return err;
1866}
1867
1797/* Set fixed AP address */ 1868/* Set fixed AP address */
1798static int __orinoco_hw_set_wap(struct orinoco_private *priv) 1869static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1799{ 1870{
@@ -3975,9 +4046,8 @@ static int orinoco_ioctl_setrate(struct net_device *dev,
3975 char *extra) 4046 char *extra)
3976{ 4047{
3977 struct orinoco_private *priv = netdev_priv(dev); 4048 struct orinoco_private *priv = netdev_priv(dev);
3978 int ratemode = -1; 4049 int ratemode;
3979 int bitrate; /* 100s of kilobits */ 4050 int bitrate; /* 100s of kilobits */
3980 int i;
3981 unsigned long flags; 4051 unsigned long flags;
3982 4052
3983 /* As the user space doesn't know our highest rate, it uses -1 4053 /* As the user space doesn't know our highest rate, it uses -1
@@ -3991,16 +4061,7 @@ static int orinoco_ioctl_setrate(struct net_device *dev,
3991 bitrate = rrq->value / 100000; 4061 bitrate = rrq->value / 100000;
3992 } 4062 }
3993 4063
3994 if ((bitrate != 10) && (bitrate != 20) && 4064 ratemode = orinoco_get_bitratemode(bitrate, !rrq->fixed);
3995 (bitrate != 55) && (bitrate != 110))
3996 return -EINVAL;
3997
3998 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3999 if ((bitrate_table[i].bitrate == bitrate) &&
4000 (bitrate_table[i].automatic == !rrq->fixed)) {
4001 ratemode = i;
4002 break;
4003 }
4004 4065
4005 if (ratemode == -1) 4066 if (ratemode == -1)
4006 return -EINVAL; 4067 return -EINVAL;
@@ -4019,65 +4080,26 @@ static int orinoco_ioctl_getrate(struct net_device *dev,
4019 char *extra) 4080 char *extra)
4020{ 4081{
4021 struct orinoco_private *priv = netdev_priv(dev); 4082 struct orinoco_private *priv = netdev_priv(dev);
4022 hermes_t *hw = &priv->hw;
4023 int err = 0; 4083 int err = 0;
4024 int ratemode; 4084 int bitrate, automatic;
4025 int i;
4026 u16 val;
4027 unsigned long flags; 4085 unsigned long flags;
4028 4086
4029 if (orinoco_lock(priv, &flags) != 0) 4087 if (orinoco_lock(priv, &flags) != 0)
4030 return -EBUSY; 4088 return -EBUSY;
4031 4089
4032 ratemode = priv->bitratemode; 4090 orinoco_get_ratemode_cfg(priv->bitratemode, &bitrate, &automatic);
4033
4034 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
4035
4036 rrq->value = bitrate_table[ratemode].bitrate * 100000;
4037 rrq->fixed = !bitrate_table[ratemode].automatic;
4038 rrq->disabled = 0;
4039 4091
4040 /* If the interface is running we try to find more about the 4092 /* If the interface is running we try to find more about the
4041 current mode */ 4093 current mode */
4042 if (netif_running(dev)) { 4094 if (netif_running(dev))
4043 err = hermes_read_wordrec(hw, USER_BAP, 4095 err = orinoco_hw_get_act_bitrate(priv, &bitrate);
4044 HERMES_RID_CURRENTTXRATE, &val);
4045 if (err)
4046 goto out;
4047 4096
4048 switch (priv->firmware_type) {
4049 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
4050 /* Note : in Lucent firmware, the return value of
4051 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
4052 * and therefore is totally different from the
4053 * encoding of HERMES_RID_CNFTXRATECONTROL.
4054 * Don't forget that 6Mb/s is really 5.5Mb/s */
4055 if (val == 6)
4056 rrq->value = 5500000;
4057 else
4058 rrq->value = val * 1000000;
4059 break;
4060 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
4061 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
4062 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
4063 if (bitrate_table[i].intersil_txratectrl == val) {
4064 ratemode = i;
4065 break;
4066 }
4067 if (i >= BITRATE_TABLE_SIZE)
4068 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
4069 dev->name, val);
4070
4071 rrq->value = bitrate_table[ratemode].bitrate * 100000;
4072 break;
4073 default:
4074 BUG();
4075 }
4076 }
4077
4078 out:
4079 orinoco_unlock(priv, &flags); 4097 orinoco_unlock(priv, &flags);
4080 4098
4099 rrq->value = bitrate;
4100 rrq->fixed = !automatic;
4101 rrq->disabled = 0;
4102
4081 return err; 4103 return err;
4082} 4104}
4083 4105