[zd1211-devs] [PATCH 3/3] Fix up coding style for switch() statements.

2006-04-18 Thread Greg KH
-- Hardware --

Conventions

I'm following the conventions of the USB specification to name
16-bit values words and 32-bit values double words (dwords). 

Overall

one config, one interface

four non-control endpoints
1: bulk out // data packets
2: bulk in  // data packets
3: int  in  // status info
4: bulk out // register accesses

Architecture

The ZD1211 chip provides the USB interface for the ZD1205
controller, which appears to provide media access control and
baseband processing. The ZD1211 connects to an RF module, which
appears to be the RF2559 on my hardware. But other RF modules have
been seen in the wild as Airoha AL2230.

Address Space

The ZD1211 provides an address space of word-size registers addressable
by word-size addresses. 65536 addresses of two-byte word registers result
in a 128 KByte address space overall.

The EEPROM code of the device is 0x800 words (4 KByte) large and is
mapped at the end of the address space at 0xf800. The EEPROM
appears to contain at offset 0x17 128 word registers.

The firmware is loaded at 0xee00 and is 5120 bytes (0xa00 words)
large and ends exactly before the EEPROM at 0xf800. It contains at
0xee1d (FW_BASE_ADDR_OFFSET) the address of 6 firmware word registers. 

The 32-bit registers (double words) are mapped at 0x9000
(CR_BASE_OFFSET). However even and odd addresses reference the
same word. So 0x9000 and 0x9001 reference the same word in the
zd1205. The next word is addressed by 0x9002 and 0x9003. We are
using always the even addresses and notify an error if odd
addresses are used while using the debug version of the driver.
There appear to exist less than 256 byte hardware registers, which are
followed by 0x500 bytes of other dword registers. These hardware
(physical) registers can only be written, if the CR_REG1 register
has the bit 7 (0x80) unset. If it is set write access to the
physical registers is not possible.

The original zydas driver maps the EEPROM and firmware registers
after the end of the zd1205 registers at 0x9900 and 0x9b00
respectively. This approach is not followed by my new driver (see
zd_types.h).

RF2559

The registers of this chip are written over a serial interface.
There is a bit indicating reading or writing followed by 5
register address bits and 18 data bits. Reading doesn't appear to
be supported by the ZD1211. The data can't be written directly by
the host CPU because of timing problems over USB.

Therefore an USB request USB_REQ_WRITE_RF is provided, which can
be used for a single register write of 24 bits. For each bit a 16
bit word is provided based on CR203. Bit RF_IF_LE (1) und RF_CLK
(2) are zeroed, bit RF_DATA (3) contains the data value. Following
the USB request id a value must be provided, which should be 2 for
almost all cases. It is followed by the number of bits and the
16-bit values for each bit.

The RF chip works on 374 MHz IF and is low-band injected at the
RF. The reference frequency is 20 MHz, which is provided by an
external oscillator. The frequency commands from the original
driver are correct under this conditions.

Scanning

For scanning the RX filter must be set accordingly and the radio
needs to be activated.

General WLAN programming

Wireless extension ioctls are serialized throught the rtnl mutex.

Receiving Data Frames

Received data frames must be read over the EP_DATA_IN endpoint. It
consists of 5 byte of the PCLP header, starting with the signal
header. The MAC data frame is following. The ZD1211 appends rx
status information at the end. Signal quality and strength can
only be computed together with PLCP

The 5 byte size of the PLCP header means, that the CCK PLCP header
is not completely provided, so you can't do a CRC16 check on your
own.

-- Driver Architecture --

This doesn't describe the current test implementation, but is
intended to lay out the final driver.

There are four modules:

mac - handles all the network specific function and integrates
  into the Linux stack
usb - contains all the code, which handles the USB bus
chip- All code which is accessing chip registers is located
  here. 
rf  - for each rf chip there should be a single file
  containing the rf-chip-specific code; the code should be
  embedded into the chip code by an rf-chip-independent
  interface

Data Structures

There are two types of data structures. There are data structures
send to the device and data structures never be used outside of
the kernel. The first type is marked with __attribute__((packed))
to make sure, that the there is no misunderstanding in the layout.

Fields smaller than a byte (for example u16 foobar:2) are only
allowed for in-kernel data structures.

Locking

Access to data structure is protected by spin locks. This is
independend of whether semaphore protection is in place or not.
Spin locks should not cross external linked functions
(non-static).

Keep in mind that the URB completion handler runs in interru

[zd1211-devs] [PATCH 3/3] Fix up coding style for switch() statements.

2006-04-18 Thread Greg KH
From: Greg Kroah-Hartman <[EMAIL PROTECTED]>

Signed-off-by: Greg Kroah-Hartman <[EMAIL PROTECTED]>

---

 zd_chip.c |   35 +--
 zd_mac.c  |   36 
 zd_rf.c   |6 --
 zd_usb.c  |   61 -
 4 files changed, 97 insertions(+), 41 deletions(-)

509cb7e43300aa1833293e7a6386765838783fbc
diff --git a/zd_chip.c b/zd_chip.c
index b72a188..1e257f1 100644
--- a/zd_chip.c
+++ b/zd_chip.c
@@ -1067,11 +1067,17 @@ int zd_chip_led_status(struct zd_chip *c
case LED_STATUS:
return (reg & mask) ? LED_ON : LED_OFF;
case LED_OFF:
-   reg &= ~mask; ret = LED_OFF; break;
+   reg &= ~mask;
+   ret = LED_OFF;
+   break;
case LED_FLIP:
-   reg ^= mask; ret = (reg&mask) ? LED_ON : LED_OFF; break;
+   reg ^= mask;
+   ret = (reg&mask) ? LED_ON : LED_OFF;
+   break;
case LED_ON:
-   reg |= mask; ret = LED_ON; break;
+   reg |= mask;
+   ret = LED_ON;
+   break;
default:
return -EINVAL;
}
@@ -1208,14 +1214,19 @@ static int to_dB(u32 x, u8 rate)
case ZD_OFDM_RATE_6M:
case ZD_OFDM_RATE_12M:
case ZD_OFDM_RATE_24M:
-   x /= 2; break;
+   x /= 2;
+   break;
case ZD_OFDM_RATE_9M:
case ZD_OFDM_RATE_18M:
case ZD_OFDM_RATE_36M:
case ZD_OFDM_RATE_54M:
-   x *= 3; x /= 4; break;
+   x *= 3;
+   x /= 4;
+   break;
case ZD_OFDM_RATE_48M:
-   x *= 2; x /= 3; break;
+   x *= 2;
+   x /= 3;
+   break;
default:
return -EINVAL;
}
@@ -1229,16 +1240,20 @@ static int to_dB(u32 x, u8 rate)
switch (rate) {
case ZD_OFDM_RATE_6M:
case ZD_OFDM_RATE_9M:
-   i += 3; break;
+   i += 3;
+   break;
case ZD_OFDM_RATE_12M:
case ZD_OFDM_RATE_18M:
-   i += 5; break;
+   i += 5;
+   break;
case ZD_OFDM_RATE_24M:
case ZD_OFDM_RATE_36M:
-   i += 9; break;
+   i += 9;
+   break;
case ZD_OFDM_RATE_48M:
case ZD_OFDM_RATE_54M:
-   i += 15; break;
+   i += 15;
+   break;
}
 
return i;
diff --git a/zd_mac.c b/zd_mac.c
index 0537078..2b39652 100644
--- a/zd_mac.c
+++ b/zd_mac.c
@@ -313,17 +313,28 @@ static u8 cs_typed_rate(u8 cs_rate)
 static u8 rate_to_cs_rate(u8 rate)
 {
switch (rate) {
-   case IEEE80211_CCK_RATE_2MB: return ZD_CS_CCK_RATE_2M;
-   case IEEE80211_CCK_RATE_5MB: return ZD_CS_CCK_RATE_5_5M;
-   case IEEE80211_CCK_RATE_11MB: return ZD_CS_CCK_RATE_11M;
-   case IEEE80211_OFDM_RATE_6MB: return ZD_OFDM_RATE_6M;
-   case IEEE80211_OFDM_RATE_9MB: return ZD_OFDM_RATE_9M;
-   case IEEE80211_OFDM_RATE_12MB: return ZD_OFDM_RATE_12M;
-   case IEEE80211_OFDM_RATE_18MB: return ZD_OFDM_RATE_18M;
-   case IEEE80211_OFDM_RATE_24MB: return ZD_OFDM_RATE_24M;
-   case IEEE80211_OFDM_RATE_36MB: return ZD_OFDM_RATE_36M;
-   case IEEE80211_OFDM_RATE_48MB: return ZD_OFDM_RATE_48M;
-   case IEEE80211_OFDM_RATE_54MB: return ZD_OFDM_RATE_54M;
+   case IEEE80211_CCK_RATE_2MB:
+   return ZD_CS_CCK_RATE_2M;
+   case IEEE80211_CCK_RATE_5MB:
+   return ZD_CS_CCK_RATE_5_5M;
+   case IEEE80211_CCK_RATE_11MB:
+   return ZD_CS_CCK_RATE_11M;
+   case IEEE80211_OFDM_RATE_6MB:
+   return ZD_OFDM_RATE_6M;
+   case IEEE80211_OFDM_RATE_9MB:
+   return ZD_OFDM_RATE_9M;
+   case IEEE80211_OFDM_RATE_12MB:
+   return ZD_OFDM_RATE_12M;
+   case IEEE80211_OFDM_RATE_18MB:
+   return ZD_OFDM_RATE_18M;
+   case IEEE80211_OFDM_RATE_24MB:
+   return ZD_OFDM_RATE_24M;
+   case IEEE80211_OFDM_RATE_36MB:
+   return ZD_OFDM_RATE_36M;
+   case IEEE80211_OFDM_RATE_48MB:
+   return ZD_OFDM_RATE_48M;
+   case IEEE80211_OFDM_RATE_54MB:
+   return ZD_OFDM_RATE_54M;
}
return ZD_CS_CCK_RATE_1M;
 }
@@ -565,7 +576,8 @@ static void cs_set_modulation(struct zd_
case IEEE80211_STYPE_PROBE_REQ:
case IEEE80211_STYPE_PROBE_RESP:
case IEEE80211_STYPE_PSPOLL:
-   cs_rate = ZD_CS_CCK_RATE_1M; break;
+   cs_rate = ZD_CS_CCK_RATE_1M;
+   break;
default:
cs_rate = get_max_basic_rate(mac);
}
diff --git a/zd_rf.c b/zd_rf.c
index 4dc1b44..94f50bc 100644
--- a/zd_rf.c
+++ b/zd_rf.c
@@ -67,9 +67,11 @@ int zd_rf_init_hw(struct zd_rf *rf, u8 t