Daniel Drake | 66bb42f | 2007-11-19 16:20:12 +0000 | [diff] [blame] | 1 | /* ZD1211 USB-WLAN driver for Linux |
| 2 | * |
| 3 | * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de> |
| 4 | * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org> |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #ifndef _ZD_MAC_H |
| 22 | #define _ZD_MAC_H |
| 23 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 24 | #include <linux/kernel.h> |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 25 | #include <net/mac80211.h> |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 26 | |
| 27 | #include "zd_chip.h" |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 28 | #include "zd_ieee80211.h" |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 29 | |
| 30 | struct zd_ctrlset { |
| 31 | u8 modulation; |
| 32 | __le16 tx_length; |
| 33 | u8 control; |
| 34 | /* stores only the difference to tx_length on ZD1211B */ |
| 35 | __le16 packet_length; |
| 36 | __le16 current_length; |
| 37 | u8 service; |
| 38 | __le16 next_frame_length; |
| 39 | } __attribute__((packed)); |
| 40 | |
| 41 | #define ZD_CS_RESERVED_SIZE 25 |
| 42 | |
Ulrich Kunitz | 64f222c | 2007-08-06 01:24:31 +0100 | [diff] [blame] | 43 | /* The field modulation of struct zd_ctrlset controls the bit rate, the use |
| 44 | * of short or long preambles in 802.11b (CCK mode) or the use of 802.11a or |
| 45 | * 802.11g in OFDM mode. |
| 46 | * |
| 47 | * The term zd-rate is used for the combination of the modulation type flag |
| 48 | * and the "pure" rate value. |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 49 | */ |
Ulrich Kunitz | 64f222c | 2007-08-06 01:24:31 +0100 | [diff] [blame] | 50 | #define ZD_PURE_RATE_MASK 0x0f |
| 51 | #define ZD_MODULATION_TYPE_MASK 0x10 |
| 52 | #define ZD_RATE_MASK (ZD_PURE_RATE_MASK|ZD_MODULATION_TYPE_MASK) |
| 53 | #define ZD_PURE_RATE(modulation) ((modulation) & ZD_PURE_RATE_MASK) |
| 54 | #define ZD_MODULATION_TYPE(modulation) ((modulation) & ZD_MODULATION_TYPE_MASK) |
| 55 | #define ZD_RATE(modulation) ((modulation) & ZD_RATE_MASK) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 56 | |
Ulrich Kunitz | 64f222c | 2007-08-06 01:24:31 +0100 | [diff] [blame] | 57 | /* The two possible modulation types. Notify that 802.11b doesn't use the CCK |
| 58 | * codeing for the 1 and 2 MBit/s rate. We stay with the term here to remain |
| 59 | * consistent with uses the term at other places. |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 60 | */ |
Ulrich Kunitz | 64f222c | 2007-08-06 01:24:31 +0100 | [diff] [blame] | 61 | #define ZD_CCK 0x00 |
| 62 | #define ZD_OFDM 0x10 |
| 63 | |
| 64 | /* The ZD1211 firmware uses proprietary encodings of the 802.11b (CCK) rates. |
| 65 | * For OFDM the PLCP rate encodings are used. We combine these "pure" rates |
| 66 | * with the modulation type flag and call the resulting values zd-rates. |
| 67 | */ |
| 68 | #define ZD_CCK_RATE_1M (ZD_CCK|0x00) |
| 69 | #define ZD_CCK_RATE_2M (ZD_CCK|0x01) |
| 70 | #define ZD_CCK_RATE_5_5M (ZD_CCK|0x02) |
| 71 | #define ZD_CCK_RATE_11M (ZD_CCK|0x03) |
| 72 | #define ZD_OFDM_RATE_6M (ZD_OFDM|ZD_OFDM_PLCP_RATE_6M) |
| 73 | #define ZD_OFDM_RATE_9M (ZD_OFDM|ZD_OFDM_PLCP_RATE_9M) |
| 74 | #define ZD_OFDM_RATE_12M (ZD_OFDM|ZD_OFDM_PLCP_RATE_12M) |
| 75 | #define ZD_OFDM_RATE_18M (ZD_OFDM|ZD_OFDM_PLCP_RATE_18M) |
| 76 | #define ZD_OFDM_RATE_24M (ZD_OFDM|ZD_OFDM_PLCP_RATE_24M) |
| 77 | #define ZD_OFDM_RATE_36M (ZD_OFDM|ZD_OFDM_PLCP_RATE_36M) |
| 78 | #define ZD_OFDM_RATE_48M (ZD_OFDM|ZD_OFDM_PLCP_RATE_48M) |
| 79 | #define ZD_OFDM_RATE_54M (ZD_OFDM|ZD_OFDM_PLCP_RATE_54M) |
| 80 | |
| 81 | /* The bit 5 of the zd_ctrlset modulation field controls the preamble in CCK |
| 82 | * mode or the 802.11a/802.11g selection in OFDM mode. |
| 83 | */ |
| 84 | #define ZD_CCK_PREA_LONG 0x00 |
| 85 | #define ZD_CCK_PREA_SHORT 0x20 |
| 86 | #define ZD_OFDM_MODE_11G 0x00 |
| 87 | #define ZD_OFDM_MODE_11A 0x20 |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 88 | |
| 89 | /* zd_ctrlset control field */ |
| 90 | #define ZD_CS_NEED_RANDOM_BACKOFF 0x01 |
| 91 | #define ZD_CS_MULTICAST 0x02 |
| 92 | |
| 93 | #define ZD_CS_FRAME_TYPE_MASK 0x0c |
| 94 | #define ZD_CS_DATA_FRAME 0x00 |
| 95 | #define ZD_CS_PS_POLL_FRAME 0x04 |
| 96 | #define ZD_CS_MANAGEMENT_FRAME 0x08 |
| 97 | #define ZD_CS_NO_SEQUENCE_CTL_FRAME 0x0c |
| 98 | |
| 99 | #define ZD_CS_WAKE_DESTINATION 0x10 |
| 100 | #define ZD_CS_RTS 0x20 |
| 101 | #define ZD_CS_ENCRYPT 0x40 |
| 102 | #define ZD_CS_SELF_CTS 0x80 |
| 103 | |
| 104 | /* Incoming frames are prepended by a PLCP header */ |
| 105 | #define ZD_PLCP_HEADER_SIZE 5 |
| 106 | |
| 107 | struct rx_length_info { |
| 108 | __le16 length[3]; |
| 109 | __le16 tag; |
John W. Linville | a88556a | 2006-11-28 14:16:37 -0500 | [diff] [blame] | 110 | } __attribute__((packed)); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 111 | |
| 112 | #define RX_LENGTH_INFO_TAG 0x697e |
| 113 | |
| 114 | struct rx_status { |
Ulrich Kunitz | db888ae | 2006-08-29 23:50:29 +0100 | [diff] [blame] | 115 | u8 signal_quality_cck; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 116 | /* rssi */ |
| 117 | u8 signal_strength; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 118 | u8 signal_quality_ofdm; |
| 119 | u8 decryption_type; |
| 120 | u8 frame_status; |
John W. Linville | a88556a | 2006-11-28 14:16:37 -0500 | [diff] [blame] | 121 | } __attribute__((packed)); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 122 | |
| 123 | /* rx_status field decryption_type */ |
| 124 | #define ZD_RX_NO_WEP 0 |
| 125 | #define ZD_RX_WEP64 1 |
| 126 | #define ZD_RX_TKIP 2 |
| 127 | #define ZD_RX_AES 4 |
| 128 | #define ZD_RX_WEP128 5 |
| 129 | #define ZD_RX_WEP256 6 |
| 130 | |
| 131 | /* rx_status field frame_status */ |
| 132 | #define ZD_RX_FRAME_MODULATION_MASK 0x01 |
| 133 | #define ZD_RX_CCK 0x00 |
| 134 | #define ZD_RX_OFDM 0x01 |
| 135 | |
| 136 | #define ZD_RX_TIMEOUT_ERROR 0x02 |
| 137 | #define ZD_RX_FIFO_OVERRUN_ERROR 0x04 |
| 138 | #define ZD_RX_DECRYPTION_ERROR 0x08 |
| 139 | #define ZD_RX_CRC32_ERROR 0x10 |
| 140 | #define ZD_RX_NO_ADDR1_MATCH_ERROR 0x20 |
| 141 | #define ZD_RX_CRC16_ERROR 0x40 |
| 142 | #define ZD_RX_ERROR 0x80 |
| 143 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 144 | enum mac_flags { |
| 145 | MAC_FIXED_CHANNEL = 0x01, |
| 146 | }; |
| 147 | |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 148 | struct housekeeping { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 149 | struct delayed_work link_led_work; |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 150 | }; |
| 151 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 152 | /** |
| 153 | * struct zd_tx_skb_control_block - control block for tx skbuffs |
| 154 | * @control: &struct ieee80211_tx_control pointer |
| 155 | * @context: context pointer |
| 156 | * |
| 157 | * This structure is used to fill the cb field in an &sk_buff to transmit. |
| 158 | * The control field is NULL, if there is no requirement from the mac80211 |
| 159 | * stack to report about the packet ACK. This is the case if the flag |
| 160 | * IEEE80211_TXCTL_NO_ACK is not set in &struct ieee80211_tx_control. |
| 161 | */ |
| 162 | struct zd_tx_skb_control_block { |
| 163 | struct ieee80211_tx_control *control; |
| 164 | struct ieee80211_hw *hw; |
| 165 | void *context; |
| 166 | }; |
| 167 | |
Ulrich Kunitz | db888ae | 2006-08-29 23:50:29 +0100 | [diff] [blame] | 168 | #define ZD_MAC_STATS_BUFFER_SIZE 16 |
| 169 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 170 | #define ZD_MAC_MAX_ACK_WAITERS 10 |
| 171 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 172 | struct zd_mac { |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 173 | struct zd_chip chip; |
| 174 | spinlock_t lock; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 175 | struct ieee80211_hw *hw; |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 176 | struct housekeeping housekeeping; |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 177 | struct work_struct set_multicast_hash_work; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 178 | struct work_struct set_rts_cts_work; |
| 179 | struct work_struct set_rx_filter_work; |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 180 | struct zd_mc_hash multicast_hash; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 181 | u8 regdomain; |
| 182 | u8 default_regdomain; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 183 | int type; |
| 184 | int associated; |
| 185 | struct sk_buff_head ack_wait_queue; |
| 186 | struct ieee80211_channel channels[14]; |
| 187 | struct ieee80211_rate rates[12]; |
| 188 | struct ieee80211_hw_mode modes[2]; |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 189 | |
| 190 | /* Short preamble (used for RTS/CTS) */ |
| 191 | unsigned int short_preamble:1; |
| 192 | |
| 193 | /* flags to indicate update in progress */ |
| 194 | unsigned int updating_rts_rate:1; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 195 | |
| 196 | /* whether to pass frames with CRC errors to stack */ |
| 197 | unsigned int pass_failed_fcs:1; |
| 198 | |
| 199 | /* whether to pass control frames to stack */ |
| 200 | unsigned int pass_ctrl:1; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 201 | }; |
| 202 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 203 | static inline struct zd_mac *zd_hw_mac(struct ieee80211_hw *hw) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 204 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 205 | return hw->priv; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static inline struct zd_mac *zd_chip_to_mac(struct zd_chip *chip) |
| 209 | { |
| 210 | return container_of(chip, struct zd_mac, chip); |
| 211 | } |
| 212 | |
| 213 | static inline struct zd_mac *zd_usb_to_mac(struct zd_usb *usb) |
| 214 | { |
| 215 | return zd_chip_to_mac(zd_usb_to_chip(usb)); |
| 216 | } |
| 217 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 218 | static inline u8 *zd_mac_get_perm_addr(struct zd_mac *mac) |
| 219 | { |
| 220 | return mac->hw->wiphy->perm_addr; |
| 221 | } |
| 222 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 223 | #define zd_mac_dev(mac) (zd_chip_dev(&(mac)->chip)) |
| 224 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 225 | struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 226 | void zd_mac_clear(struct zd_mac *mac); |
| 227 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 228 | int zd_mac_preinit_hw(struct ieee80211_hw *hw); |
| 229 | int zd_mac_init_hw(struct ieee80211_hw *hw); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 230 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 231 | int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length); |
| 232 | void zd_mac_tx_failed(struct ieee80211_hw *hw); |
| 233 | void zd_mac_tx_to_dev(struct sk_buff *skb, int error); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 234 | |
| 235 | #ifdef DEBUG |
| 236 | void zd_dump_rx_status(const struct rx_status *status); |
| 237 | #else |
| 238 | #define zd_dump_rx_status(status) |
| 239 | #endif /* DEBUG */ |
| 240 | |
| 241 | #endif /* _ZD_MAC_H */ |