aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/zd1211rw/zd_chip.c
diff options
context:
space:
mode:
authorDaniel Drake <dsd@gentoo.org>2007-11-19 10:00:29 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 18:04:47 -0500
commit459c51ad6e1fc19e91a53798358433d3c08cd09d (patch)
treefb86feacf1b229cb4ab6b36b4d1deaf4983b1e45 /drivers/net/wireless/zd1211rw/zd_chip.c
parent0765af4493193149505f118d04d9300f0a15c8f5 (diff)
zd1211rw: port to mac80211
This seems to be working smoothly now. Let's not hold back the mac80211 transition any further. This patch ports the existing driver from softmac to mac80211. Many thanks to everyone who helped out with the porting efforts. Signed-off-by: Daniel Drake <dsd@gentoo.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/zd1211rw/zd_chip.c')
-rw-r--r--drivers/net/wireless/zd1211rw/zd_chip.c121
1 files changed, 56 insertions, 65 deletions
diff --git a/drivers/net/wireless/zd1211rw/zd_chip.c b/drivers/net/wireless/zd1211rw/zd_chip.c
index f831b68f1b9c..ef9527c978b7 100644
--- a/drivers/net/wireless/zd1211rw/zd_chip.c
+++ b/drivers/net/wireless/zd1211rw/zd_chip.c
@@ -30,12 +30,12 @@
30#include "zd_rf.h" 30#include "zd_rf.h"
31 31
32void zd_chip_init(struct zd_chip *chip, 32void zd_chip_init(struct zd_chip *chip,
33 struct net_device *netdev, 33 struct ieee80211_hw *hw,
34 struct usb_interface *intf) 34 struct usb_interface *intf)
35{ 35{
36 memset(chip, 0, sizeof(*chip)); 36 memset(chip, 0, sizeof(*chip));
37 mutex_init(&chip->mutex); 37 mutex_init(&chip->mutex);
38 zd_usb_init(&chip->usb, netdev, intf); 38 zd_usb_init(&chip->usb, hw, intf);
39 zd_rf_init(&chip->rf); 39 zd_rf_init(&chip->rf);
40} 40}
41 41
@@ -50,7 +50,7 @@ void zd_chip_clear(struct zd_chip *chip)
50 50
51static int scnprint_mac_oui(struct zd_chip *chip, char *buffer, size_t size) 51static int scnprint_mac_oui(struct zd_chip *chip, char *buffer, size_t size)
52{ 52{
53 u8 *addr = zd_usb_to_netdev(&chip->usb)->dev_addr; 53 u8 *addr = zd_mac_get_perm_addr(zd_chip_to_mac(chip));
54 return scnprintf(buffer, size, "%02x-%02x-%02x", 54 return scnprintf(buffer, size, "%02x-%02x-%02x",
55 addr[0], addr[1], addr[2]); 55 addr[0], addr[1], addr[2]);
56} 56}
@@ -378,15 +378,18 @@ int zd_write_mac_addr(struct zd_chip *chip, const u8 *mac_addr)
378 }; 378 };
379 DECLARE_MAC_BUF(mac); 379 DECLARE_MAC_BUF(mac);
380 380
381 reqs[0].value = (mac_addr[3] << 24) 381 if (mac_addr) {
382 | (mac_addr[2] << 16) 382 reqs[0].value = (mac_addr[3] << 24)
383 | (mac_addr[1] << 8) 383 | (mac_addr[2] << 16)
384 | mac_addr[0]; 384 | (mac_addr[1] << 8)
385 reqs[1].value = (mac_addr[5] << 8) 385 | mac_addr[0];
386 | mac_addr[4]; 386 reqs[1].value = (mac_addr[5] << 8)
387 387 | mac_addr[4];
388 dev_dbg_f(zd_chip_dev(chip), 388 dev_dbg_f(zd_chip_dev(chip),
389 "mac addr %s\n", print_mac(mac, mac_addr)); 389 "mac addr %s\n", print_mac(mac, mac_addr));
390 } else {
391 dev_dbg_f(zd_chip_dev(chip), "set NULL mac\n");
392 }
390 393
391 mutex_lock(&chip->mutex); 394 mutex_lock(&chip->mutex);
392 r = zd_iowrite32a_locked(chip, reqs, ARRAY_SIZE(reqs)); 395 r = zd_iowrite32a_locked(chip, reqs, ARRAY_SIZE(reqs));
@@ -980,7 +983,7 @@ static int print_fw_version(struct zd_chip *chip)
980 return 0; 983 return 0;
981} 984}
982 985
983static int set_mandatory_rates(struct zd_chip *chip, enum ieee80211_std std) 986static int set_mandatory_rates(struct zd_chip *chip, int mode)
984{ 987{
985 u32 rates; 988 u32 rates;
986 ZD_ASSERT(mutex_is_locked(&chip->mutex)); 989 ZD_ASSERT(mutex_is_locked(&chip->mutex));
@@ -988,11 +991,11 @@ static int set_mandatory_rates(struct zd_chip *chip, enum ieee80211_std std)
988 * that the device is supporting. Until further notice we should try 991 * that the device is supporting. Until further notice we should try
989 * to support 802.11g also for full speed USB. 992 * to support 802.11g also for full speed USB.
990 */ 993 */
991 switch (std) { 994 switch (mode) {
992 case IEEE80211B: 995 case MODE_IEEE80211B:
993 rates = CR_RATE_1M|CR_RATE_2M|CR_RATE_5_5M|CR_RATE_11M; 996 rates = CR_RATE_1M|CR_RATE_2M|CR_RATE_5_5M|CR_RATE_11M;
994 break; 997 break;
995 case IEEE80211G: 998 case MODE_IEEE80211G:
996 rates = CR_RATE_1M|CR_RATE_2M|CR_RATE_5_5M|CR_RATE_11M| 999 rates = CR_RATE_1M|CR_RATE_2M|CR_RATE_5_5M|CR_RATE_11M|
997 CR_RATE_6M|CR_RATE_12M|CR_RATE_24M; 1000 CR_RATE_6M|CR_RATE_12M|CR_RATE_24M;
998 break; 1001 break;
@@ -1003,24 +1006,17 @@ static int set_mandatory_rates(struct zd_chip *chip, enum ieee80211_std std)
1003} 1006}
1004 1007
1005int zd_chip_set_rts_cts_rate_locked(struct zd_chip *chip, 1008int zd_chip_set_rts_cts_rate_locked(struct zd_chip *chip,
1006 u8 rts_rate, int preamble) 1009 int preamble)
1007{ 1010{
1008 int rts_mod = ZD_RX_CCK;
1009 u32 value = 0; 1011 u32 value = 0;
1010 1012
1011 /* Modulation bit */ 1013 dev_dbg_f(zd_chip_dev(chip), "preamble=%x\n", preamble);
1012 if (ZD_MODULATION_TYPE(rts_rate) == ZD_OFDM)
1013 rts_mod = ZD_RX_OFDM;
1014
1015 dev_dbg_f(zd_chip_dev(chip), "rts_rate=%x preamble=%x\n",
1016 rts_rate, preamble);
1017
1018 value |= ZD_PURE_RATE(rts_rate) << RTSCTS_SH_RTS_RATE;
1019 value |= rts_mod << RTSCTS_SH_RTS_MOD_TYPE;
1020 value |= preamble << RTSCTS_SH_RTS_PMB_TYPE; 1014 value |= preamble << RTSCTS_SH_RTS_PMB_TYPE;
1021 value |= preamble << RTSCTS_SH_CTS_PMB_TYPE; 1015 value |= preamble << RTSCTS_SH_CTS_PMB_TYPE;
1022 1016
1023 /* We always send 11M self-CTS messages, like the vendor driver. */ 1017 /* We always send 11M RTS/self-CTS messages, like the vendor driver. */
1018 value |= ZD_PURE_RATE(ZD_CCK_RATE_11M) << RTSCTS_SH_RTS_RATE;
1019 value |= ZD_RX_CCK << RTSCTS_SH_RTS_MOD_TYPE;
1024 value |= ZD_PURE_RATE(ZD_CCK_RATE_11M) << RTSCTS_SH_CTS_RATE; 1020 value |= ZD_PURE_RATE(ZD_CCK_RATE_11M) << RTSCTS_SH_CTS_RATE;
1025 value |= ZD_RX_CCK << RTSCTS_SH_CTS_MOD_TYPE; 1021 value |= ZD_RX_CCK << RTSCTS_SH_CTS_MOD_TYPE;
1026 1022
@@ -1109,7 +1105,7 @@ int zd_chip_init_hw(struct zd_chip *chip)
1109 * It might be discussed, whether we should suppport pure b mode for 1105 * It might be discussed, whether we should suppport pure b mode for
1110 * full speed USB. 1106 * full speed USB.
1111 */ 1107 */
1112 r = set_mandatory_rates(chip, IEEE80211G); 1108 r = set_mandatory_rates(chip, MODE_IEEE80211G);
1113 if (r) 1109 if (r)
1114 goto out; 1110 goto out;
1115 /* Disabling interrupts is certainly a smart thing here. 1111 /* Disabling interrupts is certainly a smart thing here.
@@ -1320,12 +1316,17 @@ out:
1320 return r; 1316 return r;
1321} 1317}
1322 1318
1323int zd_chip_set_basic_rates_locked(struct zd_chip *chip, u16 cr_rates) 1319int zd_chip_set_basic_rates(struct zd_chip *chip, u16 cr_rates)
1324{ 1320{
1325 ZD_ASSERT((cr_rates & ~(CR_RATES_80211B | CR_RATES_80211G)) == 0); 1321 int r;
1326 dev_dbg_f(zd_chip_dev(chip), "%x\n", cr_rates); 1322
1323 if (cr_rates & ~(CR_RATES_80211B|CR_RATES_80211G))
1324 return -EINVAL;
1327 1325
1328 return zd_iowrite32_locked(chip, cr_rates, CR_BASIC_RATE_TBL); 1326 mutex_lock(&chip->mutex);
1327 r = zd_iowrite32_locked(chip, cr_rates, CR_BASIC_RATE_TBL);
1328 mutex_unlock(&chip->mutex);
1329 return r;
1329} 1330}
1330 1331
1331static int ofdm_qual_db(u8 status_quality, u8 zd_rate, unsigned int size) 1332static int ofdm_qual_db(u8 status_quality, u8 zd_rate, unsigned int size)
@@ -1468,56 +1469,44 @@ u8 zd_rx_qual_percent(const void *rx_frame, unsigned int size,
1468{ 1469{
1469 return (status->frame_status&ZD_RX_OFDM) ? 1470 return (status->frame_status&ZD_RX_OFDM) ?
1470 ofdm_qual_percent(status->signal_quality_ofdm, 1471 ofdm_qual_percent(status->signal_quality_ofdm,
1471 zd_rate_from_ofdm_plcp_header(rx_frame), 1472 zd_rate_from_ofdm_plcp_header(rx_frame),
1472 size) : 1473 size) :
1473 cck_qual_percent(status->signal_quality_cck); 1474 cck_qual_percent(status->signal_quality_cck);
1474} 1475}
1475 1476
1476u8 zd_rx_strength_percent(u8 rssi) 1477/**
1477{ 1478 * zd_rx_rate - report zd-rate
1478 int r = (rssi*100) / 41; 1479 * @rx_frame - received frame
1479 if (r > 100) 1480 * @rx_status - rx_status as given by the device
1480 r = 100; 1481 *
1481 return (u8) r; 1482 * This function converts the rate as encoded in the received packet to the
1482} 1483 * zd-rate, we are using on other places in the driver.
1483 1484 */
1484u16 zd_rx_rate(const void *rx_frame, const struct rx_status *status) 1485u8 zd_rx_rate(const void *rx_frame, const struct rx_status *status)
1485{ 1486{
1486 static const u16 ofdm_rates[] = { 1487 u8 zd_rate;
1487 [ZD_OFDM_PLCP_RATE_6M] = 60,
1488 [ZD_OFDM_PLCP_RATE_9M] = 90,
1489 [ZD_OFDM_PLCP_RATE_12M] = 120,
1490 [ZD_OFDM_PLCP_RATE_18M] = 180,
1491 [ZD_OFDM_PLCP_RATE_24M] = 240,
1492 [ZD_OFDM_PLCP_RATE_36M] = 360,
1493 [ZD_OFDM_PLCP_RATE_48M] = 480,
1494 [ZD_OFDM_PLCP_RATE_54M] = 540,
1495 };
1496 u16 rate;
1497 if (status->frame_status & ZD_RX_OFDM) { 1488 if (status->frame_status & ZD_RX_OFDM) {
1498 /* Deals with PLCP OFDM rate (not zd_rates) */ 1489 zd_rate = zd_rate_from_ofdm_plcp_header(rx_frame);
1499 u8 ofdm_rate = zd_ofdm_plcp_header_rate(rx_frame);
1500 rate = ofdm_rates[ofdm_rate & 0xf];
1501 } else { 1490 } else {
1502 switch (zd_cck_plcp_header_signal(rx_frame)) { 1491 switch (zd_cck_plcp_header_signal(rx_frame)) {
1503 case ZD_CCK_PLCP_SIGNAL_1M: 1492 case ZD_CCK_PLCP_SIGNAL_1M:
1504 rate = 10; 1493 zd_rate = ZD_CCK_RATE_1M;
1505 break; 1494 break;
1506 case ZD_CCK_PLCP_SIGNAL_2M: 1495 case ZD_CCK_PLCP_SIGNAL_2M:
1507 rate = 20; 1496 zd_rate = ZD_CCK_RATE_2M;
1508 break; 1497 break;
1509 case ZD_CCK_PLCP_SIGNAL_5M5: 1498 case ZD_CCK_PLCP_SIGNAL_5M5:
1510 rate = 55; 1499 zd_rate = ZD_CCK_RATE_5_5M;
1511 break; 1500 break;
1512 case ZD_CCK_PLCP_SIGNAL_11M: 1501 case ZD_CCK_PLCP_SIGNAL_11M:
1513 rate = 110; 1502 zd_rate = ZD_CCK_RATE_11M;
1514 break; 1503 break;
1515 default: 1504 default:
1516 rate = 0; 1505 zd_rate = 0;
1517 } 1506 }
1518 } 1507 }
1519 1508
1520 return rate; 1509 return zd_rate;
1521} 1510}
1522 1511
1523int zd_chip_switch_radio_on(struct zd_chip *chip) 1512int zd_chip_switch_radio_on(struct zd_chip *chip)
@@ -1557,20 +1546,22 @@ void zd_chip_disable_int(struct zd_chip *chip)
1557 mutex_unlock(&chip->mutex); 1546 mutex_unlock(&chip->mutex);
1558} 1547}
1559 1548
1560int zd_chip_enable_rx(struct zd_chip *chip) 1549int zd_chip_enable_rxtx(struct zd_chip *chip)
1561{ 1550{
1562 int r; 1551 int r;
1563 1552
1564 mutex_lock(&chip->mutex); 1553 mutex_lock(&chip->mutex);
1554 zd_usb_enable_tx(&chip->usb);
1565 r = zd_usb_enable_rx(&chip->usb); 1555 r = zd_usb_enable_rx(&chip->usb);
1566 mutex_unlock(&chip->mutex); 1556 mutex_unlock(&chip->mutex);
1567 return r; 1557 return r;
1568} 1558}
1569 1559
1570void zd_chip_disable_rx(struct zd_chip *chip) 1560void zd_chip_disable_rxtx(struct zd_chip *chip)
1571{ 1561{
1572 mutex_lock(&chip->mutex); 1562 mutex_lock(&chip->mutex);
1573 zd_usb_disable_rx(&chip->usb); 1563 zd_usb_disable_rx(&chip->usb);
1564 zd_usb_disable_tx(&chip->usb);
1574 mutex_unlock(&chip->mutex); 1565 mutex_unlock(&chip->mutex);
1575} 1566}
1576 1567