1 From e983cf526bfd8ea56b72490f7449c65ee4dd0a16 Mon Sep 17 00:00:00 2001
2 From: Li YanBo <dreamfly281@gmail.com>
3 Date: Mon, 27 Oct 2008 20:32:57 -0700
4 Subject: Staging: add agnx wireless driver
7 From: Li YanBo <dreamfly281@gmail.com>
9 This driver is for the Airgo AGNX00 wireless chip.
11 From: Li YanBo <dreamfly281@gmail.com>
12 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
14 drivers/staging/Kconfig | 2
15 drivers/staging/Makefile | 1
16 drivers/staging/agnx/Kconfig | 5
17 drivers/staging/agnx/Makefile | 8
18 drivers/staging/agnx/TODO | 22
19 drivers/staging/agnx/agnx.h | 156 ++++++
20 drivers/staging/agnx/debug.h | 418 ++++++++++++++++++
21 drivers/staging/agnx/pci.c | 650 ++++++++++++++++++++++++++++
22 drivers/staging/agnx/phy.c | 958 ++++++++++++++++++++++++++++++++++++++++++
23 drivers/staging/agnx/phy.h | 409 +++++++++++++++++
24 drivers/staging/agnx/rf.c | 894 +++++++++++++++++++++++++++++++++++++++
25 drivers/staging/agnx/sta.c | 219 +++++++++
26 drivers/staging/agnx/sta.h | 222 +++++++++
27 drivers/staging/agnx/table.c | 168 +++++++
28 drivers/staging/agnx/table.h | 10
29 drivers/staging/agnx/xmit.c | 819 +++++++++++++++++++++++++++++++++++
30 drivers/staging/agnx/xmit.h | 250 ++++++++++
31 17 files changed, 5211 insertions(+)
32 create mode 100644 drivers/staging/agnx/Kconfig
33 create mode 100644 drivers/staging/agnx/Makefile
34 create mode 100644 drivers/staging/agnx/TODO
35 create mode 100644 drivers/staging/agnx/agnx.h
36 create mode 100644 drivers/staging/agnx/debug.h
37 create mode 100644 drivers/staging/agnx/pci.c
38 create mode 100644 drivers/staging/agnx/phy.c
39 create mode 100644 drivers/staging/agnx/phy.h
40 create mode 100644 drivers/staging/agnx/rf.c
41 create mode 100644 drivers/staging/agnx/sta.c
42 create mode 100644 drivers/staging/agnx/sta.h
43 create mode 100644 drivers/staging/agnx/table.c
44 create mode 100644 drivers/staging/agnx/table.h
45 create mode 100644 drivers/staging/agnx/xmit.c
46 create mode 100644 drivers/staging/agnx/xmit.h
49 +++ b/drivers/staging/agnx/agnx.h
56 +#define PFX KBUILD_MODNAME ": "
58 +static inline u32 agnx_read32(void __iomem *mem_region, u32 offset)
60 + return ioread32(mem_region + offset);
63 +static inline void agnx_write32(void __iomem *mem_region, u32 offset, u32 val)
65 + iowrite32(val, mem_region + offset);
68 +/* static const struct ieee80211_rate agnx_rates_80211b[] = { */
71 +/* .flags = IEEE80211_RATE_CCK }, */
74 +/* .hw_value = -0x14, */
75 +/* .flags = IEEE80211_RATE_CCK_2 }, */
79 +/* .flags = IEEE80211_RATE_CCK_2 }, */
83 +/* .flags = IEEE80211_RATE_CCK_2 } */
87 +static const struct ieee80211_rate agnx_rates_80211g[] = {
88 +/* { .bitrate = 10, .hw_value = 1, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, */
89 +/* { .bitrate = 20, .hw_value = 2, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, */
90 +/* { .bitrate = 55, .hw_value = 3, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, */
91 +/* { .bitrate = 110, .hw_value = 4, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, */
92 + { .bitrate = 10, .hw_value = 1, },
93 + { .bitrate = 20, .hw_value = 2, },
94 + { .bitrate = 55, .hw_value = 3, },
95 + { .bitrate = 110, .hw_value = 4,},
97 + { .bitrate = 60, .hw_value = 0xB, },
98 + { .bitrate = 90, .hw_value = 0xF, },
99 + { .bitrate = 120, .hw_value = 0xA },
100 + { .bitrate = 180, .hw_value = 0xE, },
101 +// { .bitrate = 240, .hw_value = 0xd, },
102 + { .bitrate = 360, .hw_value = 0xD, },
103 + { .bitrate = 480, .hw_value = 0x8, },
104 + { .bitrate = 540, .hw_value = 0xC, },
107 +static const struct ieee80211_channel agnx_channels[] = {
108 + { .center_freq = 2412, .hw_value = 1, },
109 + { .center_freq = 2417, .hw_value = 2, },
110 + { .center_freq = 2422, .hw_value = 3, },
111 + { .center_freq = 2427, .hw_value = 4, },
112 + { .center_freq = 2432, .hw_value = 5, },
113 + { .center_freq = 2437, .hw_value = 6, },
114 + { .center_freq = 2442, .hw_value = 7, },
115 + { .center_freq = 2447, .hw_value = 8, },
116 + { .center_freq = 2452, .hw_value = 9, },
117 + { .center_freq = 2457, .hw_value = 10, },
118 + { .center_freq = 2462, .hw_value = 11, },
119 + { .center_freq = 2467, .hw_value = 12, },
120 + { .center_freq = 2472, .hw_value = 13, },
121 + { .center_freq = 2484, .hw_value = 14, },
124 +#define NUM_DRIVE_MODES 2
125 +/* Agnx operate mode */
128 + AGNX_MODE_80211A_OOB,
129 + AGNX_MODE_80211A_MIMO,
130 + AGNX_MODE_80211B_SHORT,
131 + AGNX_MODE_80211B_LONG,
133 + AGNX_MODE_80211G_OOB,
134 + AGNX_MODE_80211G_MIMO,
144 + struct pci_dev *pdev;
145 + struct ieee80211_hw *hw;
148 + struct mutex mutex;
149 + unsigned int init_status;
151 + void __iomem *ctl; /* pointer to base ram address */
152 + void __iomem *data; /* pointer to mem region #2 */
154 + struct agnx_ring rx;
155 + struct agnx_ring txm;
156 + struct agnx_ring txd;
158 + /* Need volatile? */
161 + struct delayed_work periodic_work; /* Periodic tasks like recalibrate*/
162 + struct ieee80211_low_level_stats stats;
164 +// unsigned int phymode;
167 + u8 bssid[ETH_ALEN];
171 + u8 mac_addr[ETH_ALEN];
174 + struct ieee80211_supported_band band;
178 +#define AGNX_CHAINS_MAX 6
179 +#define AGNX_PERIODIC_DELAY 60000 /* unit: ms */
180 +#define LOCAL_STAID 0 /* the station entry for the card itself */
181 +#define BSSID_STAID 1 /* the station entry for the bsssid AP */
182 +#define spi_delay() udelay(40)
183 +#define eeprom_delay() udelay(40)
184 +#define routing_table_delay() udelay(50)
186 +/* PDU pool MEM region #2 */
187 +#define AGNX_PDUPOOL 0x40000 /* PDU pool */
188 +#define AGNX_PDUPOOL_SIZE 0x8000 /* PDU pool size*/
189 +#define AGNX_PDU_TX_WQ 0x41000 /* PDU list TX workqueue */
190 +#define AGNX_PDU_FREE 0x41800 /* Free Pool */
191 +#define PDU_SIZE 0x80 /* Free Pool node size */
192 +#define PDU_FREE_CNT 0xd0 /* Free pool node count */
196 +extern void rf_chips_init(struct agnx_priv *priv);
197 +extern void spi_rc_write(void __iomem *mem_region, u32 chip_ids, u32 sw);
198 +extern void calibrate_oscillator(struct agnx_priv *priv);
199 +extern void do_calibration(struct agnx_priv *priv);
200 +extern void antenna_calibrate(struct agnx_priv *priv);
201 +extern void __antenna_calibrate(struct agnx_priv *priv);
202 +extern void print_offsets(struct agnx_priv *priv);
203 +extern int agnx_set_channel(struct agnx_priv *priv, unsigned int channel);
206 +#endif /* AGNX_H_ */
208 +++ b/drivers/staging/agnx/debug.h
210 +#ifndef AGNX_DEBUG_H_
211 +#define AGNX_DEBUG_H_
218 +#define AGNX_TRACE printk(KERN_ERR PFX "function:%s line:%d\n", __func__, __LINE__)
220 +#define PRINTK_LE16(prefix, var) printk(KERN_DEBUG PFX #prefix ": " #var " 0x%.4x\n", le16_to_cpu(var))
221 +#define PRINTK_LE32(prefix, var) printk(KERN_DEBUG PFX #prefix ": " #var " 0x%.8x\n", le32_to_cpu(var))
222 +#define PRINTK_U8(prefix, var) printk(KERN_DEBUG PFX #prefix ": " #var " 0x%.2x\n", var)
223 +#define PRINTK_BE16(prefix, var) printk(KERN_DEBUG PFX #prefix ": " #var " 0x%.4x\n", be16_to_cpu(var))
224 +#define PRINTK_BE32(prefix, var) printk(KERN_DEBUG PFX #prefix ": " #var " 0x%.8x\n", be32_to_cpu(var))
225 +#define PRINTK_BITS(prefix, field) printk(KERN_DEBUG PFX #prefix ": " #field ": 0x%x\n", (reg & field) >> field##_SHIFT)
227 +static inline void agnx_bug(char *reason)
229 + printk(KERN_ERR PFX "%s\n", reason);
233 +static inline void agnx_print_desc(struct agnx_desc *desc)
235 + u32 reg = be32_to_cpu(desc->frag);
237 + PRINTK_BITS(DESC, PACKET_LEN);
239 + if (reg & FIRST_FRAG) {
240 + PRINTK_BITS(DESC, FIRST_PACKET_MASK);
241 + PRINTK_BITS(DESC, FIRST_RESERV2);
242 + PRINTK_BITS(DESC, FIRST_TKIP_ERROR);
243 + PRINTK_BITS(DESC, FIRST_TKIP_PACKET);
244 + PRINTK_BITS(DESC, FIRST_RESERV1);
245 + PRINTK_BITS(DESC, FIRST_FRAG_LEN);
247 + PRINTK_BITS(DESC, SUB_RESERV2);
248 + PRINTK_BITS(DESC, SUB_TKIP_ERROR);
249 + PRINTK_BITS(DESC, SUB_TKIP_PACKET);
250 + PRINTK_BITS(DESC, SUB_RESERV1);
251 + PRINTK_BITS(DESC, SUB_FRAG_LEN);
254 + PRINTK_BITS(DESC, FIRST_FRAG);
255 + PRINTK_BITS(DESC, LAST_FRAG);
256 + PRINTK_BITS(DESC, OWNER);
260 +static inline void dump_ieee80211b_phy_hdr(__be32 _11b0, __be32 _11b1)
265 +static inline void agnx_print_hdr(struct agnx_hdr *hdr)
270 + reg = be32_to_cpu(hdr->reg0);
271 + PRINTK_BITS(HDR, RTS);
272 + PRINTK_BITS(HDR, MULTICAST);
273 + PRINTK_BITS(HDR, ACK);
274 + PRINTK_BITS(HDR, TM);
275 + PRINTK_BITS(HDR, RELAY);
276 + PRINTK_BITS(HDR, REVISED_FCS);
277 + PRINTK_BITS(HDR, NEXT_BUFFER_ADDR);
279 + reg = be32_to_cpu(hdr->reg1);
280 + PRINTK_BITS(HDR, MAC_HDR_LEN);
281 + PRINTK_BITS(HDR, DURATION_OVERIDE);
282 + PRINTK_BITS(HDR, PHY_HDR_OVERIDE);
283 + PRINTK_BITS(HDR, CRC_FAIL);
284 + PRINTK_BITS(HDR, SEQUENCE_NUMBER);
285 + PRINTK_BITS(HDR, BUFF_HEAD_ADDR);
287 + reg = be32_to_cpu(hdr->reg2);
288 + PRINTK_BITS(HDR, PDU_COUNT);
289 + PRINTK_BITS(HDR, WEP_KEY);
290 + PRINTK_BITS(HDR, USES_WEP_KEY);
291 + PRINTK_BITS(HDR, KEEP_ALIVE);
292 + PRINTK_BITS(HDR, BUFF_TAIL_ADDR);
294 + reg = be32_to_cpu(hdr->reg3);
295 + PRINTK_BITS(HDR, CTS_11G);
296 + PRINTK_BITS(HDR, RTS_11G);
297 + PRINTK_BITS(HDR, FRAG_SIZE);
298 + PRINTK_BITS(HDR, PAYLOAD_LEN);
299 + PRINTK_BITS(HDR, FRAG_NUM);
301 + reg = be32_to_cpu(hdr->reg4);
302 + PRINTK_BITS(HDR, RELAY_STAID);
303 + PRINTK_BITS(HDR, STATION_ID);
304 + PRINTK_BITS(HDR, WORKQUEUE_ID);
306 + reg = be32_to_cpu(hdr->reg5);
307 + /* printf the route flag */
308 + PRINTK_BITS(HDR, ROUTE_HOST);
309 + PRINTK_BITS(HDR, ROUTE_CARD_CPU);
310 + PRINTK_BITS(HDR, ROUTE_ENCRYPTION);
311 + PRINTK_BITS(HDR, ROUTE_TX);
312 + PRINTK_BITS(HDR, ROUTE_RX1);
313 + PRINTK_BITS(HDR, ROUTE_RX2);
314 + PRINTK_BITS(HDR, ROUTE_COMPRESSION);
316 + PRINTK_BE32(HDR, hdr->_11g0);
317 + PRINTK_BE32(HDR, hdr->_11g1);
318 + PRINTK_BE32(HDR, hdr->_11b0);
319 + PRINTK_BE32(HDR, hdr->_11b1);
321 + dump_ieee80211b_phy_hdr(hdr->_11b0, hdr->_11b1);
324 + for (i = 0; i < ARRAY_SIZE(hdr->mac_hdr); i++) {
326 + printk(KERN_DEBUG PFX "IEEE80211 HDR: ");
327 + printk("%.2x ", hdr->mac_hdr[i]);
328 + if (i + 1 == ARRAY_SIZE(hdr->mac_hdr))
332 + PRINTK_BE16(HDR, hdr->rts_duration);
333 + PRINTK_BE16(HDR, hdr->last_duration);
334 + PRINTK_BE16(HDR, hdr->sec_last_duration);
335 + PRINTK_BE16(HDR, hdr->other_duration);
336 + PRINTK_BE16(HDR, hdr->tx_other_duration);
337 + PRINTK_BE16(HDR, hdr->last_11g_len);
338 + PRINTK_BE16(HDR, hdr->other_11g_len);
339 + PRINTK_BE16(HDR, hdr->last_11b_len);
340 + PRINTK_BE16(HDR, hdr->other_11b_len);
343 + reg = be16_to_cpu(hdr->reg6);
344 + PRINTK_BITS(HDR, MBF);
345 + PRINTK_BITS(HDR, RSVD4);
347 + PRINTK_BE16(HDR, hdr->rx_frag_stat);
349 + PRINTK_BE32(HDR, hdr->time_stamp);
350 + PRINTK_BE32(HDR, hdr->phy_stats_hi);
351 + PRINTK_BE32(HDR, hdr->phy_stats_lo);
352 + PRINTK_BE32(HDR, hdr->mic_key0);
353 + PRINTK_BE32(HDR, hdr->mic_key1);
354 +} /* agnx_print_hdr */
357 +static inline void agnx_print_rx_hdr(struct agnx_hdr *hdr)
359 + agnx_print_hdr(hdr);
361 + PRINTK_BE16(HDR, hdr->rx.rx_packet_duration);
362 + PRINTK_BE16(HDR, hdr->rx.replay_cnt);
364 + PRINTK_U8(HDR, hdr->rx_channel);
367 +static inline void agnx_print_tx_hdr(struct agnx_hdr *hdr)
369 + agnx_print_hdr(hdr);
371 + PRINTK_U8(HDR, hdr->tx.long_retry_limit);
372 + PRINTK_U8(HDR, hdr->tx.short_retry_limit);
373 + PRINTK_U8(HDR, hdr->tx.long_retry_cnt);
374 + PRINTK_U8(HDR, hdr->tx.short_retry_cnt);
376 + PRINTK_U8(HDR, hdr->rx_channel);
380 +agnx_print_sta_power(struct agnx_priv *priv, unsigned int sta_idx)
382 + struct agnx_sta_power power;
385 + get_sta_power(priv, &power, sta_idx);
387 + reg = le32_to_cpu(power.reg);
388 + PRINTK_BITS(STA_POWER, SIGNAL);
389 + PRINTK_BITS(STA_POWER, RATE);
390 + PRINTK_BITS(STA_POWER, TIFS);
391 + PRINTK_BITS(STA_POWER, EDCF);
392 + PRINTK_BITS(STA_POWER, CHANNEL_BOND);
393 + PRINTK_BITS(STA_POWER, PHY_MODE);
394 + PRINTK_BITS(STA_POWER, POWER_LEVEL);
395 + PRINTK_BITS(STA_POWER, NUM_TRANSMITTERS);
399 +agnx_print_sta_tx_wq(struct agnx_priv *priv, unsigned int sta_idx, unsigned int wq_idx)
401 + struct agnx_sta_tx_wq tx_wq;
404 + get_sta_tx_wq(priv, &tx_wq, sta_idx, wq_idx);
406 + reg = le32_to_cpu(tx_wq.reg0);
407 + PRINTK_BITS(STA_TX_WQ, TAIL_POINTER);
408 + PRINTK_BITS(STA_TX_WQ, HEAD_POINTER_LOW);
410 + reg = le32_to_cpu(tx_wq.reg3);
411 + PRINTK_BITS(STA_TX_WQ, HEAD_POINTER_HIGH);
412 + PRINTK_BITS(STA_TX_WQ, ACK_POINTER_LOW);
414 + reg = le32_to_cpu(tx_wq.reg1);
415 + PRINTK_BITS(STA_TX_WQ, ACK_POINTER_HIGH);
416 + PRINTK_BITS(STA_TX_WQ, HEAD_TIMOUT_TAIL_PACK_CNT);
417 + PRINTK_BITS(STA_TX_WQ, ACK_TIMOUT_TAIL_PACK_CNT);
419 + reg = le32_to_cpu(tx_wq.reg2);
420 + PRINTK_BITS(STA_TX_WQ, HEAD_TIMOUT_WIN_LIM_BYTE_CNT);
421 + PRINTK_BITS(STA_TX_WQ, HEAD_TIMOUT_WIN_LIM_FRAG_CNT);
422 + PRINTK_BITS(STA_TX_WQ, WORK_QUEUE_ACK_TYPE);
423 + PRINTK_BITS(STA_TX_WQ, WORK_QUEUE_VALID);
426 +static inline void agnx_print_sta_traffic(struct agnx_sta_traffic *traffic)
430 + reg = le32_to_cpu(traffic->reg0);
431 + PRINTK_BITS(STA_TRAFFIC, ACK_TIMOUT_CNT);
432 + PRINTK_BITS(STA_TRAFFIC, TRAFFIC_ACK_TYPE);
433 + PRINTK_BITS(STA_TRAFFIC, NEW_PACKET);
434 + PRINTK_BITS(STA_TRAFFIC, TRAFFIC_VALID);
435 + PRINTK_BITS(STA_TRAFFIC, RX_HDR_DESC_POINTER);
437 + reg = le32_to_cpu(traffic->reg1);
438 + PRINTK_BITS(STA_TRAFFIC, RX_PACKET_TIMESTAMP);
439 + PRINTK_BITS(STA_TRAFFIC, TRAFFIC_RESERVED);
440 + PRINTK_BITS(STA_TRAFFIC, SV);
441 + PRINTK_BITS(STA_TRAFFIC, RX_SEQUENCE_NUM);
443 + PRINTK_LE32(STA_TRAFFIC, traffic->tx_replay_cnt_low);
445 + PRINTK_LE16(STA_TRAFFIC, traffic->tx_replay_cnt_high);
446 + PRINTK_LE16(STA_TRAFFIC, traffic->rx_replay_cnt_high);
448 + PRINTK_LE32(STA_TRAFFIC, traffic->rx_replay_cnt_low);
451 +static inline void agnx_print_sta(struct agnx_priv *priv, unsigned int sta_idx)
453 + struct agnx_sta station;
454 + struct agnx_sta *sta = &station;
458 + get_sta(priv, sta, sta_idx);
460 + for (i = 0; i < 4; i++)
461 + PRINTK_LE32(STA, sta->tx_session_keys[i]);
462 + for (i = 0; i < 4; i++)
463 + PRINTK_LE32(STA, sta->rx_session_keys[i]);
465 + reg = le32_to_cpu(sta->reg);
466 + PRINTK_BITS(STA, ID_1);
467 + PRINTK_BITS(STA, ID_0);
468 + PRINTK_BITS(STA, ENABLE_CONCATENATION);
469 + PRINTK_BITS(STA, ENABLE_DECOMPRESSION);
470 + PRINTK_BITS(STA, STA_RESERVED);
471 + PRINTK_BITS(STA, EAP);
472 + PRINTK_BITS(STA, ED_NULL);
473 + PRINTK_BITS(STA, ENCRYPTION_POLICY);
474 + PRINTK_BITS(STA, DEFINED_KEY_ID);
475 + PRINTK_BITS(STA, FIXED_KEY);
476 + PRINTK_BITS(STA, KEY_VALID);
477 + PRINTK_BITS(STA, STATION_VALID);
479 + PRINTK_LE32(STA, sta->tx_aes_blks_unicast);
480 + PRINTK_LE32(STA, sta->rx_aes_blks_unicast);
482 + PRINTK_LE16(STA, sta->aes_format_err_unicast_cnt);
483 + PRINTK_LE16(STA, sta->aes_replay_unicast);
485 + PRINTK_LE16(STA, sta->aes_decrypt_err_unicast);
486 + PRINTK_LE16(STA, sta->aes_decrypt_err_default);
488 + PRINTK_LE16(STA, sta->single_retry_packets);
489 + PRINTK_LE16(STA, sta->failed_tx_packets);
491 + PRINTK_LE16(STA, sta->muti_retry_packets);
492 + PRINTK_LE16(STA, sta->ack_timeouts);
494 + PRINTK_LE16(STA, sta->frag_tx_cnt);
495 + PRINTK_LE16(STA, sta->rts_brq_sent);
497 + PRINTK_LE16(STA, sta->tx_packets);
498 + PRINTK_LE16(STA, sta->cts_back_timeout);
500 + PRINTK_LE32(STA, sta->phy_stats_high);
501 + PRINTK_LE32(STA, sta->phy_stats_low);
503 +// for (i = 0; i < 8; i++)
504 + agnx_print_sta_traffic(sta->traffic + 0);
506 + PRINTK_LE16(STA, sta->traffic_class0_frag_success);
507 + PRINTK_LE16(STA, sta->traffic_class1_frag_success);
508 + PRINTK_LE16(STA, sta->traffic_class2_frag_success);
509 + PRINTK_LE16(STA, sta->traffic_class3_frag_success);
510 + PRINTK_LE16(STA, sta->traffic_class4_frag_success);
511 + PRINTK_LE16(STA, sta->traffic_class5_frag_success);
512 + PRINTK_LE16(STA, sta->traffic_class6_frag_success);
513 + PRINTK_LE16(STA, sta->traffic_class7_frag_success);
515 + PRINTK_LE16(STA, sta->num_frag_non_prime_rates);
516 + PRINTK_LE16(STA, sta->ack_timeout_non_prime_rates);
520 +static inline void dump_ieee80211_hdr(struct ieee80211_hdr *hdr, char *tag)
524 + DECLARE_MAC_BUF(mac);
526 + fctl = le16_to_cpu(hdr->frame_control);
527 + switch (fctl & IEEE80211_FCTL_FTYPE) {
528 + case IEEE80211_FTYPE_DATA:
529 + printk(PFX "%s DATA ", tag);
531 + case IEEE80211_FTYPE_CTL:
532 + printk(PFX "%s CTL ", tag);
534 + case IEEE80211_FTYPE_MGMT:
535 + printk(PFX "%s MGMT ", tag);
536 + switch(fctl & IEEE80211_FCTL_STYPE) {
537 + case IEEE80211_STYPE_ASSOC_REQ:
538 + printk("SubType: ASSOC_REQ ");
540 + case IEEE80211_STYPE_ASSOC_RESP:
541 + printk("SubType: ASSOC_RESP ");
543 + case IEEE80211_STYPE_REASSOC_REQ:
544 + printk("SubType: REASSOC_REQ ");
546 + case IEEE80211_STYPE_REASSOC_RESP:
547 + printk("SubType: REASSOC_RESP ");
549 + case IEEE80211_STYPE_PROBE_REQ:
550 + printk("SubType: PROBE_REQ ");
552 + case IEEE80211_STYPE_PROBE_RESP:
553 + printk("SubType: PROBE_RESP ");
555 + case IEEE80211_STYPE_BEACON:
556 + printk("SubType: BEACON ");
558 + case IEEE80211_STYPE_ATIM:
559 + printk("SubType: ATIM ");
561 + case IEEE80211_STYPE_DISASSOC:
562 + printk("SubType: DISASSOC ");
564 + case IEEE80211_STYPE_AUTH:
565 + printk("SubType: AUTH ");
567 + case IEEE80211_STYPE_DEAUTH:
568 + printk("SubType: DEAUTH ");
570 + case IEEE80211_STYPE_ACTION:
571 + printk("SubType: ACTION ");
574 + printk("SubType: Unknow\n");
578 + printk(PFX "%s Packet type: Unknow\n", tag);
581 + hdrlen = ieee80211_hdrlen(fctl);
584 + printk("FC=0x%04x DUR=0x%04x",
585 + fctl, le16_to_cpu(hdr->duration_id));
587 + printk(" A1=%s", print_mac(mac, hdr->addr1));
589 + printk(" A2=%s", print_mac(mac, hdr->addr2));
591 + printk(" A3=%s", print_mac(mac, hdr->addr3));
593 + printk(" A4=%s", print_mac(mac, hdr->addr4));
597 +static inline void dump_txm_registers(struct agnx_priv *priv)
599 + void __iomem *ctl = priv->ctl;
601 + for (i = 0; i <=0x1e8; i += 4) {
602 + printk(KERN_DEBUG PFX "TXM: %x---> 0x%.8x\n", i, ioread32(ctl + i));
605 +static inline void dump_rxm_registers(struct agnx_priv *priv)
607 + void __iomem *ctl = priv->ctl;
609 + for (i = 0; i <=0x108; i += 4)
610 + printk(KERN_DEBUG PFX "RXM: %x---> 0x%.8x\n", i, ioread32(ctl + 0x2000 + i));
612 +static inline void dump_bm_registers(struct agnx_priv *priv)
614 + void __iomem *ctl = priv->ctl;
616 + for (i = 0; i <=0x90; i += 4)
617 + printk(KERN_DEBUG PFX "BM: %x---> 0x%.8x\n", i, ioread32(ctl + 0x2c00 + i));
619 +static inline void dump_cir_registers(struct agnx_priv *priv)
621 + void __iomem *ctl = priv->ctl;
623 + for (i = 0; i <=0xb8; i += 4)
624 + printk(KERN_DEBUG PFX "CIR: %x---> 0x%.8x\n", i, ioread32(ctl + 0x3000 + i));
627 +#endif /* AGNX_DEBUG_H_ */
629 +++ b/drivers/staging/agnx/Kconfig
632 + tristate "Wireless Airgo AGNX support"
633 + depends on WLAN_80211 && MAC80211
635 + This is an experimental driver for Airgo AGNX00 wireless chip.
637 +++ b/drivers/staging/agnx/Makefile
639 +obj-$(CONFIG_AGNX) += agnx.o
648 +++ b/drivers/staging/agnx/pci.c
651 + * Airgo MIMO wireless driver
653 + * Copyright (c) 2007 Li YanBo <dreamfly281@gmail.com>
655 + * Thanks for Jeff Williams <angelbane@gmail.com> do reverse engineer
656 + * works and published the SPECS at http://airgo.wdwconsulting.net/mymoin
658 + * This program is free software; you can redistribute it and/or modify
659 + * it under the terms of the GNU General Public License version 2 as
660 + * published by the Free Software Foundation.
663 +#include <linux/init.h>
664 +#include <linux/etherdevice.h>
665 +#include <linux/pci.h>
666 +#include <linux/delay.h>
673 +MODULE_AUTHOR("Li YanBo <dreamfly281@gmail.com>");
674 +MODULE_DESCRIPTION("Airgo MIMO PCI wireless driver");
675 +MODULE_LICENSE("GPL");
677 +static struct pci_device_id agnx_pci_id_tbl[] __devinitdata = {
678 + { PCI_DEVICE(0x17cb, 0x0001) }, /* Beklin F5d8010, Netgear WGM511 etc */
679 + { PCI_DEVICE(0x17cb, 0x0002) }, /* Netgear Wpnt511 */
683 +MODULE_DEVICE_TABLE(pci, agnx_pci_id_tbl);
686 +static inline void agnx_interrupt_ack(struct agnx_priv *priv, u32 *reason)
688 + void __iomem *ctl = priv->ctl;
691 + if ( *reason & AGNX_STAT_RX ) {
692 + /* Mark complete RX */
693 + reg = ioread32(ctl + AGNX_CIR_RXCTL);
695 + iowrite32(reg, ctl + AGNX_CIR_RXCTL);
696 + /* disable Rx interrupt */
698 + if ( *reason & AGNX_STAT_TX ) {
699 + reg = ioread32(ctl + AGNX_CIR_TXDCTL);
701 + iowrite32(reg, ctl + AGNX_CIR_TXDCTL);
702 + *reason |= AGNX_STAT_TXD;
704 + reg = ioread32(ctl + AGNX_CIR_TXMCTL);
706 + iowrite32(reg, ctl + AGNX_CIR_TXMCTL);
707 + *reason |= AGNX_STAT_TXM;
710 + if ( *reason & AGNX_STAT_X ) {
711 +/* reg = ioread32(ctl + AGNX_INT_STAT); */
712 +/* iowrite32(reg, ctl + AGNX_INT_STAT); */
713 +/* /\* FIXME reinit interrupt mask *\/ */
714 +/* reg = 0xc390bf9 & ~IRQ_TX_BEACON; */
715 +/* reg &= ~IRQ_TX_DISABLE; */
716 +/* iowrite32(reg, ctl + AGNX_INT_MASK); */
717 +/* iowrite32(0x800, ctl + AGNX_CIR_BLKCTL); */
719 +} /* agnx_interrupt_ack */
721 +static irqreturn_t agnx_interrupt_handler(int irq, void *dev_id)
723 + struct ieee80211_hw *dev = dev_id;
724 + struct agnx_priv *priv = dev->priv;
725 + void __iomem *ctl = priv->ctl;
726 + irqreturn_t ret = IRQ_NONE;
729 + spin_lock(&priv->lock);
731 +// printk(KERN_ERR PFX "Get a interrupt %s\n", __func__);
733 + if (priv->init_status != AGNX_START)
736 + /* FiXME Here has no lock, Is this will lead to race? */
737 + irq_reason = ioread32(ctl + AGNX_CIR_BLKCTL);
738 + if (!(irq_reason & 0x7))
742 + priv->irq_status = ioread32(ctl + AGNX_INT_STAT);
744 +// printk(PFX "Interrupt reason is 0x%x\n", irq_reason);
745 + /* Make sure the txm and txd flags don't conflict with other unknown
746 + interrupt flag, maybe is not necessary */
749 + disable_rx_interrupt(priv);
750 + /* TODO Make sure the card finished initialized */
751 + agnx_interrupt_ack(priv, &irq_reason);
753 + if ( irq_reason & AGNX_STAT_RX )
754 + handle_rx_irq(priv);
755 + if ( irq_reason & AGNX_STAT_TXD )
756 + handle_txd_irq(priv);
757 + if ( irq_reason & AGNX_STAT_TXM )
758 + handle_txm_irq(priv);
759 + if ( irq_reason & AGNX_STAT_X )
760 + handle_other_irq(priv);
762 + enable_rx_interrupt(priv);
764 + spin_unlock(&priv->lock);
766 +} /* agnx_interrupt_handler */
770 +static int agnx_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
773 + return _agnx_tx(dev->priv, skb);
777 +static int agnx_get_mac_address(struct agnx_priv *priv)
779 + void __iomem *ctl = priv->ctl;
783 + /* Attention! directly read the MAC or other date from EEPROM will
784 + lead to cardbus(WGM511) lock up when write to PM PLL register */
785 + reg = agnx_read32(ctl, 0x3544);
787 + reg = agnx_read32(ctl, 0x354c);
789 + /* Get the mac address */
790 + reg = agnx_read32(ctl, 0x3544);
794 + reg = cpu_to_le32(reg);
795 + priv->mac_addr[0] = ((u8 *)®)[2];
796 + priv->mac_addr[1] = ((u8 *)®)[3];
797 + reg = agnx_read32(ctl, 0x3548);
799 + *((u32 *)(priv->mac_addr + 2)) = cpu_to_le32(reg);
801 + if (!is_valid_ether_addr(priv->mac_addr)) {
802 + DECLARE_MAC_BUF(mbuf);
803 + printk(KERN_WARNING PFX "read mac %s\n", print_mac(mbuf, priv->mac_addr));
804 + printk(KERN_WARNING PFX "Invalid hwaddr! Using random hwaddr\n");
805 + random_ether_addr(priv->mac_addr);
809 +} /* agnx_get_mac_address */
811 +static int agnx_alloc_rings(struct agnx_priv *priv)
816 + /* Allocate RX/TXM/TXD rings info */
817 + priv->rx.size = AGNX_RX_RING_SIZE;
818 + priv->txm.size = AGNX_TXM_RING_SIZE;
819 + priv->txd.size = AGNX_TXD_RING_SIZE;
821 + len = priv->rx.size + priv->txm.size + priv->txd.size;
823 +// priv->rx.info = kzalloc(sizeof(struct agnx_info) * len, GFP_KERNEL);
824 + priv->rx.info = kzalloc(sizeof(struct agnx_info) * len, GFP_ATOMIC);
825 + if (!priv->rx.info)
827 + priv->txm.info = priv->rx.info + priv->rx.size;
828 + priv->txd.info = priv->txm.info + priv->txm.size;
830 + /* Allocate RX/TXM/TXD descriptors */
831 + priv->rx.desc = pci_alloc_consistent(priv->pdev, sizeof(struct agnx_desc) * len,
833 + if (!priv->rx.desc) {
834 + kfree(priv->rx.info);
838 + priv->txm.desc = priv->rx.desc + priv->rx.size;
839 + priv->txm.dma = priv->rx.dma + sizeof(struct agnx_desc) * priv->rx.size;
840 + priv->txd.desc = priv->txm.desc + priv->txm.size;
841 + priv->txd.dma = priv->txm.dma + sizeof(struct agnx_desc) * priv->txm.size;
844 +} /* agnx_alloc_rings */
846 +static void rings_free(struct agnx_priv *priv)
848 + unsigned int len = priv->rx.size + priv->txm.size + priv->txd.size;
849 + unsigned long flags;
852 + spin_lock_irqsave(&priv->lock, flags);
853 + kfree(priv->rx.info);
854 + pci_free_consistent(priv->pdev, sizeof(struct agnx_desc) * len,
855 + priv->rx.desc, priv->rx.dma);
856 + spin_unlock_irqrestore(&priv->lock, flags);
860 +static void agnx_periodic_work_handler(struct work_struct *work)
862 + struct agnx_priv *priv = container_of(work, struct agnx_priv,
863 + periodic_work.work);
864 +// unsigned long flags;
865 + unsigned long delay;
867 + /* fixme: using mutex?? */
868 +// spin_lock_irqsave(&priv->lock, flags);
870 + /* TODO Recalibrate*/
871 +// calibrate_oscillator(priv);
872 +// antenna_calibrate(priv);
873 +// agnx_send_packet(priv, 997);
875 +/* if (debug == 3) */
876 +/* delay = msecs_to_jiffies(AGNX_PERIODIC_DELAY); */
878 + delay = msecs_to_jiffies(AGNX_PERIODIC_DELAY);
879 +// delay = round_jiffies(HZ * 15);
881 + queue_delayed_work(priv->hw->workqueue, &priv->periodic_work, delay);
883 +// spin_unlock_irqrestore(&priv->lock, flags);
887 +static int agnx_start(struct ieee80211_hw *dev)
889 + struct agnx_priv *priv = dev->priv;
890 + unsigned long delay;
894 + err = agnx_alloc_rings(priv);
896 + printk(KERN_ERR PFX "Can't alloc RX/TXM/TXD rings\n");
899 + err = request_irq(priv->pdev->irq, &agnx_interrupt_handler,
900 + IRQF_SHARED, "agnx_pci", dev);
902 + printk(KERN_ERR PFX "Failed to register IRQ handler\n");
910 + agnx_hw_init(priv);
915 + priv->init_status = AGNX_START;
916 +/* INIT_DELAYED_WORK(&priv->periodic_work, agnx_periodic_work_handler); */
917 +/* delay = msecs_to_jiffies(AGNX_PERIODIC_DELAY); */
918 +/* queue_delayed_work(priv->hw->workqueue, &priv->periodic_work, delay); */
923 +static void agnx_stop(struct ieee80211_hw *dev)
925 + struct agnx_priv *priv = dev->priv;
928 + priv->init_status = AGNX_STOP;
929 + /* make sure hardware will not generate irq */
930 + agnx_hw_reset(priv);
931 + free_irq(priv->pdev->irq, dev);
932 + flush_workqueue(priv->hw->workqueue);
933 +// cancel_delayed_work_sync(&priv->periodic_work);
934 + unfill_rings(priv);
938 +static int agnx_config(struct ieee80211_hw *dev,
939 + struct ieee80211_conf *conf)
941 + struct agnx_priv *priv = dev->priv;
942 + int channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
945 + spin_lock(&priv->lock);
946 + /* FIXME need priv lock? */
947 + if (channel != priv->channel) {
948 + priv->channel = channel;
949 + agnx_set_channel(priv, priv->channel);
952 + spin_unlock(&priv->lock);
956 +static int agnx_config_interface(struct ieee80211_hw *dev,
957 + struct ieee80211_vif *vif,
958 + struct ieee80211_if_conf *conf)
960 + struct agnx_priv *priv = dev->priv;
961 + void __iomem *ctl = priv->ctl;
964 + spin_lock(&priv->lock);
966 + if (memcmp(conf->bssid, priv->bssid, ETH_ALEN)) {
967 +// u32 reghi, reglo;
968 + agnx_set_bssid(priv, conf->bssid);
969 + memcpy(priv->bssid, conf->bssid, ETH_ALEN);
970 + hash_write(priv, conf->bssid, BSSID_STAID);
971 + sta_init(priv, BSSID_STAID);
972 + /* FIXME needed? */
973 + sta_power_init(priv, BSSID_STAID);
974 + agnx_write32(ctl, AGNX_BM_MTSM, 0xff & ~0x1);
976 + if (conf->ssid_len != priv->ssid_len ||
977 + memcmp(conf->ssid, priv->ssid, conf->ssid_len)) {
978 + agnx_set_ssid(priv, conf->ssid, conf->ssid_len);
979 + priv->ssid_len = conf->ssid_len;
980 + memcpy(priv->ssid, conf->ssid, conf->ssid_len);
982 + spin_unlock(&priv->lock);
984 +} /* agnx_config_interface */
987 +static void agnx_configure_filter(struct ieee80211_hw *dev,
988 + unsigned int changed_flags,
989 + unsigned int *total_flags,
990 + int mc_count, struct dev_mc_list *mclist)
992 + unsigned int new_flags = 0;
994 + *total_flags = new_flags;
998 +static int agnx_add_interface(struct ieee80211_hw *dev,
999 + struct ieee80211_if_init_conf *conf)
1001 + struct agnx_priv *priv = dev->priv;
1004 + spin_lock(&priv->lock);
1006 + if (priv->mode != NL80211_IFTYPE_MONITOR)
1007 + return -EOPNOTSUPP;
1009 + switch (conf->type) {
1010 + case NL80211_IFTYPE_STATION:
1011 + priv->mode = conf->type;
1014 + return -EOPNOTSUPP;
1017 + spin_unlock(&priv->lock);
1022 +static void agnx_remove_interface(struct ieee80211_hw *dev,
1023 + struct ieee80211_if_init_conf *conf)
1025 + struct agnx_priv *priv = dev->priv;
1029 + priv->mode = NL80211_IFTYPE_MONITOR;
1032 +static int agnx_get_stats(struct ieee80211_hw *dev,
1033 + struct ieee80211_low_level_stats *stats)
1035 + struct agnx_priv *priv = dev->priv;
1037 + spin_lock(&priv->lock);
1039 + memcpy(stats, &priv->stats, sizeof(*stats));
1040 + spin_unlock(&priv->lock);
1045 +static u64 agnx_get_tsft(struct ieee80211_hw *dev)
1047 + void __iomem *ctl = ((struct agnx_priv *)dev->priv)->ctl;
1053 + tsftl = ioread32(ctl + AGNX_TXM_TIMESTAMPLO);
1054 + tsft = ioread32(ctl + AGNX_TXM_TIMESTAMPHI);
1061 +static int agnx_get_tx_stats(struct ieee80211_hw *dev,
1062 + struct ieee80211_tx_queue_stats *stats)
1064 + struct agnx_priv *priv = dev->priv;
1067 + /* FIXME now we just using txd queue, but should using txm queue too */
1068 + stats[0].len = (priv->txd.idx - priv->txd.idx_sent) / 2;
1069 + stats[0].limit = priv->txd.size - 2;
1070 + stats[0].count = priv->txd.idx / 2;
1075 +static struct ieee80211_ops agnx_ops = {
1077 + .start = agnx_start,
1078 + .stop = agnx_stop,
1079 + .add_interface = agnx_add_interface,
1080 + .remove_interface = agnx_remove_interface,
1081 + .config = agnx_config,
1082 + .config_interface = agnx_config_interface,
1083 + .configure_filter = agnx_configure_filter,
1084 + .get_stats = agnx_get_stats,
1085 + .get_tx_stats = agnx_get_tx_stats,
1086 + .get_tsf = agnx_get_tsft
1089 +static void __devexit agnx_pci_remove(struct pci_dev *pdev)
1091 + struct ieee80211_hw *dev = pci_get_drvdata(pdev);
1092 + struct agnx_priv *priv = dev->priv;
1097 + ieee80211_unregister_hw(dev);
1098 + pci_iounmap(pdev, priv->ctl);
1099 + pci_iounmap(pdev, priv->data);
1100 + pci_release_regions(pdev);
1101 + pci_disable_device(pdev);
1103 + ieee80211_free_hw(dev);
1106 +static int __devinit agnx_pci_probe(struct pci_dev *pdev,
1107 + const struct pci_device_id *id)
1109 + struct ieee80211_hw *dev;
1110 + struct agnx_priv *priv;
1111 + u32 mem_addr0, mem_len0;
1112 + u32 mem_addr1, mem_len1;
1114 + DECLARE_MAC_BUF(mac);
1116 + err = pci_enable_device(pdev);
1118 + printk(KERN_ERR PFX "Can't enable new PCI device\n");
1122 + /* get pci resource */
1123 + mem_addr0 = pci_resource_start(pdev, 0);
1124 + mem_len0 = pci_resource_len(pdev, 0);
1125 + mem_addr1 = pci_resource_start(pdev, 1);
1126 + mem_len1 = pci_resource_len(pdev, 1);
1127 + printk(KERN_DEBUG PFX "Memaddr0 is %x, length is %x\n", mem_addr0, mem_len0);
1128 + printk(KERN_DEBUG PFX "Memaddr1 is %x, length is %x\n", mem_addr1, mem_len1);
1130 + err = pci_request_regions(pdev, "agnx-pci");
1132 + printk(KERN_ERR PFX "Can't obtain PCI resource\n");
1136 + if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) ||
1137 + pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK)) {
1138 + printk(KERN_ERR PFX "No suitable DMA available\n");
1139 + goto err_free_reg;
1142 + pci_set_master(pdev);
1143 + printk(KERN_DEBUG PFX "pdev->irq is %d\n", pdev->irq);
1145 + dev = ieee80211_alloc_hw(sizeof(*priv), &agnx_ops);
1147 + printk(KERN_ERR PFX "ieee80211 alloc failed\n");
1149 + goto err_free_reg;
1153 + memset(priv, 0, sizeof(*priv));
1154 + priv->mode = NL80211_IFTYPE_MONITOR;
1155 + priv->pdev = pdev;
1157 + spin_lock_init(&priv->lock);
1158 + priv->init_status = AGNX_UNINIT;
1160 + /* Map mem #1 and #2 */
1161 + priv->ctl = pci_iomap(pdev, 0, mem_len0);
1162 +// printk(KERN_DEBUG PFX"MEM1 mapped address is 0x%p\n", priv->ctl);
1164 + printk(KERN_ERR PFX "Can't map device memory\n");
1165 + goto err_free_dev;
1167 + priv->data = pci_iomap(pdev, 1, mem_len1);
1168 + printk(KERN_DEBUG PFX "MEM2 mapped address is 0x%p\n", priv->data);
1169 + if (!priv->data) {
1170 + printk(KERN_ERR PFX "Can't map device memory\n");
1171 + goto err_iounmap2;
1174 + pci_read_config_byte(pdev, PCI_REVISION_ID, &priv->revid);
1176 + priv->band.channels = (struct ieee80211_channel *)agnx_channels;
1177 + priv->band.n_channels = ARRAY_SIZE(agnx_channels);
1178 + priv->band.bitrates = (struct ieee80211_rate *)agnx_rates_80211g;
1179 + priv->band.n_bitrates = ARRAY_SIZE(agnx_rates_80211g);
1181 + /* Init ieee802.11 dev */
1182 + SET_IEEE80211_DEV(dev, &pdev->dev);
1183 + pci_set_drvdata(pdev, dev);
1184 + dev->extra_tx_headroom = sizeof(struct agnx_hdr);
1186 + /* FIXME It only include FCS in promious mode but not manage mode */
1187 +/* dev->flags = IEEE80211_HW_RX_INCLUDES_FCS; */
1188 + dev->channel_change_time = 5000;
1189 + dev->max_signal = 100;
1193 + agnx_get_mac_address(priv);
1195 + SET_IEEE80211_PERM_ADDR(dev, priv->mac_addr);
1197 +/* /\* FIXME *\/ */
1198 +/* for (i = 1; i < NUM_DRIVE_MODES; i++) { */
1199 +/* err = ieee80211_register_hwmode(dev, &priv->modes[i]); */
1201 +/* printk(KERN_ERR PFX "Can't register hwmode\n"); */
1202 +/* goto err_iounmap; */
1206 + priv->channel = 1;
1207 + dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
1209 + err = ieee80211_register_hw(dev);
1211 + printk(KERN_ERR PFX "Can't register hardware\n");
1215 + agnx_hw_reset(priv);
1218 + printk(PFX "%s: hwaddr %s, Rev 0x%02x\n", wiphy_name(dev->wiphy),
1219 + print_mac(mac, dev->wiphy->perm_addr), priv->revid);
1223 + pci_iounmap(pdev, priv->data);
1226 + pci_iounmap(pdev, priv->ctl);
1229 + pci_set_drvdata(pdev, NULL);
1230 + ieee80211_free_hw(dev);
1233 + pci_release_regions(pdev);
1235 + pci_disable_device(pdev);
1237 +} /* agnx_pci_probe*/
1241 +static int agnx_pci_suspend(struct pci_dev *pdev, pm_message_t state)
1243 + struct ieee80211_hw *dev = pci_get_drvdata(pdev);
1246 + ieee80211_stop_queues(dev);
1249 + pci_save_state(pdev);
1250 + pci_set_power_state(pdev, pci_choose_state(pdev, state));
1254 +static int agnx_pci_resume(struct pci_dev *pdev)
1256 + struct ieee80211_hw *dev = pci_get_drvdata(pdev);
1259 + pci_set_power_state(pdev, PCI_D0);
1260 + pci_restore_state(pdev);
1263 + ieee80211_wake_queues(dev);
1270 +#define agnx_pci_suspend NULL
1271 +#define agnx_pci_resume NULL
1273 +#endif /* CONFIG_PM */
1276 +static struct pci_driver agnx_pci_driver = {
1277 + .name = "agnx-pci",
1278 + .id_table = agnx_pci_id_tbl,
1279 + .probe = agnx_pci_probe,
1280 + .remove = __devexit_p(agnx_pci_remove),
1281 + .suspend = agnx_pci_suspend,
1282 + .resume = agnx_pci_resume,
1285 +static int __init agnx_pci_init(void)
1288 + return pci_register_driver(&agnx_pci_driver);
1291 +static void __exit agnx_pci_exit(void)
1294 + pci_unregister_driver(&agnx_pci_driver);
1298 +module_init(agnx_pci_init);
1299 +module_exit(agnx_pci_exit);
1301 +++ b/drivers/staging/agnx/phy.c
1304 + * Airgo MIMO wireless driver
1306 + * Copyright (c) 2007 Li YanBo <dreamfly281@gmail.com>
1308 + * Thanks for Jeff Williams <angelbane@gmail.com> do reverse engineer
1309 + * works and published the SPECS at http://airgo.wdwconsulting.net/mymoin
1311 + * This program is free software; you can redistribute it and/or modify
1312 + * it under the terms of the GNU General Public License version 2 as
1313 + * published by the Free Software Foundation.
1316 +#include <linux/init.h>
1317 +#include <linux/etherdevice.h>
1318 +#include <linux/pci.h>
1319 +#include <linux/delay.h>
1327 +u8 read_from_eeprom(struct agnx_priv *priv, u16 address)
1329 + void __iomem *ctl = priv->ctl;
1330 + struct agnx_eeprom cmd;
1333 + memset(&cmd, 0, sizeof(cmd));
1334 + cmd.cmd = EEPROM_CMD_READ << AGNX_EEPROM_COMMAND_SHIFT;
1335 + cmd.address = address;
1336 + /* Verify that the Status bit is clear */
1337 + /* Read Command and Address are written to the Serial Interface */
1338 + iowrite32(*(__le32 *)&cmd, ctl + AGNX_CIR_SERIALITF);
1339 + /* Wait for the Status bit to clear again */
1341 + /* Read from Data */
1342 + reg = ioread32(ctl + AGNX_CIR_SERIALITF);
1344 + cmd = *(struct agnx_eeprom *)®
1349 +static int card_full_reset(struct agnx_priv *priv)
1351 + void __iomem *ctl = priv->ctl;
1355 + reg = agnx_read32(ctl, AGNX_CIR_BLKCTL);
1356 + agnx_write32(ctl, AGNX_CIR_BLKCTL, 0x80);
1357 + reg = agnx_read32(ctl, AGNX_CIR_BLKCTL);
1361 +inline void enable_power_saving(struct agnx_priv *priv)
1363 + void __iomem *ctl = priv->ctl;
1366 + reg = agnx_read32(ctl, AGNX_PM_PMCTL);
1368 + agnx_write32(ctl, AGNX_PM_PMCTL, reg);
1371 +inline void disable_power_saving(struct agnx_priv *priv)
1373 + void __iomem *ctl = priv->ctl;
1376 + reg = agnx_read32(ctl, AGNX_PM_PMCTL);
1378 + agnx_write32(ctl, AGNX_PM_PMCTL, reg);
1382 +void disable_receiver(struct agnx_priv *priv)
1384 + void __iomem *ctl = priv->ctl;
1387 + /* FIXME Disable the receiver */
1388 + agnx_write32(ctl, AGNX_GCR_DISCOVMOD, 0x0);
1389 + /* Set gain control reset */
1390 + agnx_write32(ctl, AGNX_GCR_RSTGCTL, 0x1);
1391 + /* Reset gain control reset */
1392 + agnx_write32(ctl, AGNX_GCR_RSTGCTL, 0x0);
1396 +/* Fixme this shoule be disable RX, above is enable RX */
1397 +void enable_receiver(struct agnx_priv *priv)
1399 + void __iomem *ctl = priv->ctl;
1402 + /* Set adaptive gain control discovery mode */
1403 + agnx_write32(ctl, AGNX_GCR_DISCOVMOD, 0x3);
1404 + /* Set gain control reset */
1405 + agnx_write32(ctl, AGNX_GCR_RSTGCTL, 0x1);
1406 + /* Clear gain control reset */
1407 + agnx_write32(ctl, AGNX_GCR_RSTGCTL, 0x0);
1410 +static void mac_address_set(struct agnx_priv *priv)
1412 + void __iomem *ctl = priv->ctl;
1413 + u8 *mac_addr = priv->mac_addr;
1417 + reg = (mac_addr[0] << 24) | (mac_addr[1] << 16) | mac_addr[2] << 8 | mac_addr[3];
1418 + iowrite32(reg, ctl + AGNX_RXM_MACHI);
1419 + reg = (mac_addr[4] << 8) | mac_addr[5];
1420 + iowrite32(reg, ctl + AGNX_RXM_MACLO);
1423 +static void receiver_bssid_set(struct agnx_priv *priv, u8 *bssid)
1425 + void __iomem *ctl = priv->ctl;
1428 + disable_receiver(priv);
1430 + reg = bssid[0] << 24 | (bssid[1] << 16) | (bssid[2] << 8) | bssid[3];
1431 + iowrite32(reg, ctl + AGNX_RXM_BSSIDHI);
1432 + reg = (bssid[4] << 8) | bssid[5];
1433 + iowrite32(reg, ctl + AGNX_RXM_BSSIDLO);
1435 + /* Enable the receiver */
1436 + enable_receiver(priv);
1438 + /* Clear the TSF */
1439 +/* agnx_write32(ctl, AGNX_TXM_TSFLO, 0x0); */
1440 +/* agnx_write32(ctl, AGNX_TXM_TSFHI, 0x0); */
1441 + /* Clear the TBTT */
1442 + agnx_write32(ctl, AGNX_TXM_TBTTLO, 0x0);
1443 + agnx_write32(ctl, AGNX_TXM_TBTTHI, 0x0);
1444 + disable_receiver(priv);
1445 +} /* receiver_bssid_set */
1447 +static void band_management_init(struct agnx_priv *priv)
1449 + void __iomem *ctl = priv->ctl;
1450 + void __iomem *data = priv->data;
1455 + agnx_write32(ctl, AGNX_BM_TXWADDR, AGNX_PDU_TX_WQ);
1456 + agnx_write32(ctl, AGNX_CIR_ADDRWIN, 0x0);
1457 + memset_io(data + AGNX_PDUPOOL, 0x0, AGNX_PDUPOOL_SIZE);
1458 + agnx_write32(ctl, AGNX_BM_BMCTL, 0x200);
1460 + agnx_write32(ctl, AGNX_BM_CIPDUWCNT, 0x40);
1461 + agnx_write32(ctl, AGNX_BM_SPPDUWCNT, 0x2);
1462 + agnx_write32(ctl, AGNX_BM_RFPPDUWCNT, 0x0);
1463 + agnx_write32(ctl, AGNX_BM_RHPPDUWCNT, 0x22);
1465 + /* FIXME Initialize the Free Pool Linked List */
1466 + /* 1. Write the Address of the Next Node ((0x41800 + node*size)/size)
1467 + to the first word of each node. */
1468 + for (i = 0; i < PDU_FREE_CNT; i++) {
1469 + iowrite32((AGNX_PDU_FREE + (i+1)*PDU_SIZE)/PDU_SIZE,
1470 + data + AGNX_PDU_FREE + (PDU_SIZE * i));
1471 + /* The last node should be set to 0x0 */
1472 + if ((i + 1) == PDU_FREE_CNT)
1473 + memset_io(data + AGNX_PDU_FREE + (PDU_SIZE * i),
1477 + /* Head is First Pool address (0x41800) / size (0x80) */
1478 + agnx_write32(ctl, AGNX_BM_FPLHP, AGNX_PDU_FREE/PDU_SIZE);
1479 + /* Tail is Last Pool Address (0x47f80) / size (0x80) */
1480 + agnx_write32(ctl, AGNX_BM_FPLTP, 0x47f80/PDU_SIZE);
1481 + /* Count is Number of Nodes in the Pool (0xd0) */
1482 + agnx_write32(ctl, AGNX_BM_FPCNT, PDU_FREE_CNT);
1484 + /* Start all workqueue */
1485 + agnx_write32(ctl, AGNX_BM_CIWQCTL, 0x80000);
1486 + agnx_write32(ctl, AGNX_BM_CPULWCTL, 0x80000);
1487 + agnx_write32(ctl, AGNX_BM_CPUHWCTL, 0x80000);
1488 + agnx_write32(ctl, AGNX_BM_CPUTXWCTL, 0x80000);
1489 + agnx_write32(ctl, AGNX_BM_CPURXWCTL, 0x80000);
1490 + agnx_write32(ctl, AGNX_BM_SPRXWCTL, 0x80000);
1491 + agnx_write32(ctl, AGNX_BM_SPTXWCTL, 0x80000);
1492 + agnx_write32(ctl, AGNX_BM_RFPWCTL, 0x80000);
1494 + /* Enable the Band Management */
1495 + reg = agnx_read32(ctl, AGNX_BM_BMCTL);
1497 + agnx_write32(ctl, AGNX_BM_BMCTL, reg);
1498 +} /* band_managment_init */
1501 +static void system_itf_init(struct agnx_priv *priv)
1503 + void __iomem *ctl = priv->ctl;
1507 + agnx_write32(ctl, AGNX_SYSITF_GPIOUT, 0x0);
1508 + agnx_write32(ctl, AGNX_PM_TESTPHY, 0x11e143a);
1510 + if (priv->revid == 0) {
1511 + reg = agnx_read32(ctl, AGNX_SYSITF_SYSMODE);
1513 + agnx_write32(ctl, AGNX_SYSITF_SYSMODE, reg);
1515 + /* ??? What is that means? it should difference for differice type
1517 + agnx_write32(ctl, AGNX_CIR_SERIALITF, 0xfff81006);
1519 + agnx_write32(ctl, AGNX_SYSITF_GPIOIN, 0x1f0000);
1520 + agnx_write32(ctl, AGNX_SYSITF_GPIOUT, 0x5);
1521 + reg = agnx_read32(ctl, AGNX_SYSITF_GPIOIN);
1524 +static void encryption_init(struct agnx_priv *priv)
1526 + void __iomem *ctl = priv->ctl;
1529 + agnx_write32(ctl, AGNX_ENCRY_WEPKEY0, 0x0);
1530 + agnx_write32(ctl, AGNX_ENCRY_WEPKEY1, 0x0);
1531 + agnx_write32(ctl, AGNX_ENCRY_WEPKEY2, 0x0);
1532 + agnx_write32(ctl, AGNX_ENCRY_WEPKEY3, 0x0);
1533 + agnx_write32(ctl, AGNX_ENCRY_CCMRECTL, 0x8);
1536 +static void tx_management_init(struct agnx_priv *priv)
1538 + void __iomem *ctl = priv->ctl;
1539 + void __iomem *data = priv->data;
1543 + /* Fill out the ComputationalEngineLookupTable
1544 + * starting at memory #2 offset 0x800
1546 + tx_engine_lookup_tbl_init(priv);
1547 + memset_io(data + 0x1000, 0, 0xfe0);
1548 + /* Enable Transmission Management Functions */
1549 + agnx_write32(ctl, AGNX_TXM_ETMF, 0x3ff);
1550 + /* Write 0x3f to Transmission Template */
1551 + agnx_write32(ctl, AGNX_TXM_TXTEMP, 0x3f);
1553 + if (priv->revid >= 2)
1554 + agnx_write32(ctl, AGNX_TXM_SIFSPIFS, 0x1e140a0b);
1556 + agnx_write32(ctl, AGNX_TXM_SIFSPIFS, 0x1e190a0b);
1558 + reg = agnx_read32(ctl, AGNX_TXM_TIFSEIFS);
1561 + agnx_write32(ctl, AGNX_TXM_TIFSEIFS, reg);
1562 + reg = agnx_read32(ctl, AGNX_TXM_TIFSEIFS);
1563 + reg &= 0xffff00ff;
1565 + agnx_write32(ctl, AGNX_TXM_TIFSEIFS, reg);
1567 + agnx_write32(ctl, AGNX_TXM_CTL, 0x40000);
1569 + reg = agnx_read32(ctl, AGNX_TXM_TIFSEIFS);
1570 + reg &= 0xff00ffff;
1572 + agnx_write32(ctl, AGNX_TXM_TIFSEIFS, reg);
1573 + reg = agnx_read32(ctl, AGNX_TXM_PROBDELAY);
1574 + reg &= 0xff00ffff;
1575 + agnx_write32(ctl, AGNX_TXM_PROBDELAY, reg);
1576 + reg = agnx_read32(ctl, AGNX_TXM_TIFSEIFS);
1577 + reg &= 0x00ffffff;
1578 + reg |= 0x1c000000;
1579 + agnx_write32(ctl, AGNX_TXM_TIFSEIFS, reg);
1580 + reg = agnx_read32(ctl, AGNX_TXM_PROBDELAY);
1581 + reg &= 0x00ffffff;
1582 + reg |= 0x01000000;
1583 + agnx_write32(ctl, AGNX_TXM_PROBDELAY, reg);
1585 + /* # Set DIF 0-1,2-3,4-5,6-7 to defaults */
1586 + agnx_write32(ctl, AGNX_TXM_DIF01, 0x321d321d);
1587 + agnx_write32(ctl, AGNX_TXM_DIF23, 0x321d321d);
1588 + agnx_write32(ctl, AGNX_TXM_DIF45, 0x321d321d);
1589 + agnx_write32(ctl, AGNX_TXM_DIF67, 0x321d321d);
1591 + /* Max Ack timeout limit */
1592 + agnx_write32(ctl, AGNX_TXM_MAXACKTIM, 0x1e19);
1593 + /* Max RX Data Timeout count, */
1594 + reg = agnx_read32(ctl, AGNX_TXM_MAXRXTIME);
1595 + reg &= 0xffff0000;
1597 + agnx_write32(ctl, AGNX_TXM_MAXRXTIME, reg);
1599 + /* CF poll RX Timeout count */
1600 + reg = agnx_read32(ctl, AGNX_TXM_CFPOLLRXTIM);
1603 + agnx_write32(ctl, AGNX_TXM_CFPOLLRXTIM, reg);
1605 + /* Max Timeout Exceeded count, */
1606 + reg = agnx_read32(ctl, AGNX_TXM_MAXTIMOUT);
1607 + reg &= 0xff00ffff;
1609 + agnx_write32(ctl, AGNX_TXM_MAXTIMOUT, reg);
1611 + /* CF ack timeout limit for 11b */
1612 + reg = agnx_read32(ctl, AGNX_TXM_CFACKT11B);
1615 + agnx_write32(ctl, AGNX_TXM_CFACKT11B, reg);
1617 + /* Max CF Poll Timeout Count */
1618 + reg = agnx_read32(ctl, AGNX_TXM_CFPOLLRXTIM);
1619 + reg &= 0xffff0000;
1621 + agnx_write32(ctl, AGNX_TXM_CFPOLLRXTIM, reg);
1622 + /* CF Poll RX Timeout Count */
1623 + reg = agnx_read32(ctl, AGNX_TXM_CFPOLLRXTIM);
1624 + reg &= 0xffff0000;
1626 + agnx_write32(ctl, AGNX_TXM_CFPOLLRXTIM, reg);
1628 + /* # write default to */
1629 + /* 1. Schedule Empty Count */
1630 + agnx_write32(ctl, AGNX_TXM_SCHEMPCNT, 0x5);
1631 + /* 2. CFP Period Count */
1632 + agnx_write32(ctl, AGNX_TXM_CFPERCNT, 0x1);
1634 + agnx_write32(ctl, AGNX_TXM_CFPMDV, 0x10000);
1637 + reg = agnx_read32(ctl, AGNX_TXM_PROBDELAY);
1638 + reg &= 0xffff0000;
1640 + agnx_write32(ctl, AGNX_TXM_PROBDELAY, reg);
1642 + /* Max CCA count Slot */
1643 + reg = agnx_read32(ctl, AGNX_TXM_MAXCCACNTSLOT);
1644 + reg &= 0xffff00ff;
1646 + agnx_write32(ctl, AGNX_TXM_MAXCCACNTSLOT, reg);
1648 + /* Slot limit/1 msec Limit */
1649 + reg = agnx_read32(ctl, AGNX_TXM_SLOTLIMIT);
1650 + reg &= 0xff00ffff;
1652 + agnx_write32(ctl, AGNX_TXM_SLOTLIMIT, reg);
1654 + /* # Set CW #(0-7) to default */
1655 + agnx_write32(ctl, AGNX_TXM_CW0, 0xff0007);
1656 + agnx_write32(ctl, AGNX_TXM_CW1, 0xff0007);
1657 + agnx_write32(ctl, AGNX_TXM_CW2, 0xff0007);
1658 + agnx_write32(ctl, AGNX_TXM_CW3, 0xff0007);
1659 + agnx_write32(ctl, AGNX_TXM_CW4, 0xff0007);
1660 + agnx_write32(ctl, AGNX_TXM_CW5, 0xff0007);
1661 + agnx_write32(ctl, AGNX_TXM_CW6, 0xff0007);
1662 + agnx_write32(ctl, AGNX_TXM_CW7, 0xff0007);
1664 + /* # Set Short/Long limit #(0-7) to default */
1665 + agnx_write32(ctl, AGNX_TXM_SLBEALIM0, 0xa000a);
1666 + agnx_write32(ctl, AGNX_TXM_SLBEALIM1, 0xa000a);
1667 + agnx_write32(ctl, AGNX_TXM_SLBEALIM2, 0xa000a);
1668 + agnx_write32(ctl, AGNX_TXM_SLBEALIM3, 0xa000a);
1669 + agnx_write32(ctl, AGNX_TXM_SLBEALIM4, 0xa000a);
1670 + agnx_write32(ctl, AGNX_TXM_SLBEALIM5, 0xa000a);
1671 + agnx_write32(ctl, AGNX_TXM_SLBEALIM6, 0xa000a);
1672 + agnx_write32(ctl, AGNX_TXM_SLBEALIM7, 0xa000a);
1674 + reg = agnx_read32(ctl, AGNX_TXM_CTL);
1676 + agnx_write32(ctl, AGNX_TXM_CTL, reg);
1677 + /* Wait for bit 0 in Control Reg to clear */
1679 + reg = agnx_read32(ctl, AGNX_TXM_CTL);
1680 + /* Or 0x18000 to Control reg */
1681 + reg = agnx_read32(ctl, AGNX_TXM_CTL);
1683 + agnx_write32(ctl, AGNX_TXM_CTL, reg);
1684 + /* Wait for bit 0 in Control Reg to clear */
1686 + reg = agnx_read32(ctl, AGNX_TXM_CTL);
1688 + /* Set Listen Interval Count to default */
1689 + agnx_write32(ctl, AGNX_TXM_LISINTERCNT, 0x1);
1690 + /* Set DTIM period count to default */
1691 + agnx_write32(ctl, AGNX_TXM_DTIMPERICNT, 0x2000);
1692 +} /* tx_management_init */
1694 +static void rx_management_init(struct agnx_priv *priv)
1696 + void __iomem *ctl = priv->ctl;
1699 + /* Initialize the Routing Table */
1700 + routing_table_init(priv);
1702 + if (priv->revid >= 3) {
1703 + agnx_write32(ctl, 0x2074, 0x1f171710);
1704 + agnx_write32(ctl, 0x2078, 0x10100d0d);
1705 + agnx_write32(ctl, 0x207c, 0x11111010);
1708 + agnx_write32(ctl, AGNX_RXM_DELAY11, 0x0);
1709 + agnx_write32(ctl, AGNX_RXM_REQRATE, 0x8195e00);
1713 +static void agnx_timer_init(struct agnx_priv *priv)
1715 + void __iomem *ctl = priv->ctl;
1718 +/* /\* Write 0x249f00 (tick duration?) to Timer 1 *\/ */
1719 +/* agnx_write32(ctl, AGNX_TIMCTL_TIMER1, 0x249f00); */
1720 +/* /\* Write 0xe2 to Timer 1 Control *\/ */
1721 +/* agnx_write32(ctl, AGNX_TIMCTL_TIM1CTL, 0xe2); */
1723 + /* Write 0x249f00 (tick duration?) to Timer 1 */
1724 + agnx_write32(ctl, AGNX_TIMCTL_TIMER1, 0x0);
1725 + /* Write 0xe2 to Timer 1 Control */
1726 + agnx_write32(ctl, AGNX_TIMCTL_TIM1CTL, 0x0);
1728 + iowrite32(0xFFFFFFFF, priv->ctl + AGNX_TXM_BEACON_CTL);
1731 +static void power_manage_init(struct agnx_priv *priv)
1733 + void __iomem *ctl = priv->ctl;
1737 + agnx_write32(ctl, AGNX_PM_MACMSW, 0x1f);
1738 + agnx_write32(ctl, AGNX_PM_RFCTL, 0x1f);
1740 + reg = agnx_read32(ctl, AGNX_PM_PMCTL);
1743 + agnx_write32(ctl, AGNX_PM_PMCTL, reg);
1745 + if (priv->revid >= 3) {
1746 + reg = agnx_read32(ctl, AGNX_PM_SOFTRST);
1748 + agnx_write32(ctl, AGNX_PM_SOFTRST, reg);
1750 +} /* power_manage_init */
1753 +static void gain_ctlcnt_init(struct agnx_priv *priv)
1755 + void __iomem *ctl = priv->ctl;
1759 + agnx_write32(ctl, AGNX_GCR_TRACNT5, 0x119);
1760 + agnx_write32(ctl, AGNX_GCR_TRACNT6, 0x118);
1761 + agnx_write32(ctl, AGNX_GCR_TRACNT7, 0x117);
1763 + reg = agnx_read32(ctl, AGNX_PM_PMCTL);
1765 + agnx_write32(ctl, AGNX_PM_PMCTL, reg);
1767 + reg = agnx_read32(ctl, AGNX_PM_PMCTL);
1769 + agnx_write32(ctl, AGNX_PM_PMCTL, reg);
1771 + agnx_write32(ctl, AGNX_CIR_ADDRWIN, 0x0);
1773 + /* FIXME Write the initial Station Descriptor for the card */
1774 + sta_init(priv, LOCAL_STAID);
1775 + sta_init(priv, BSSID_STAID);
1777 + /* Enable staion 0 and 1 can do TX */
1778 + /* It seemed if we set other bit to 1 the bit 0 will
1779 + be auto change to 0 */
1780 + agnx_write32(ctl, AGNX_BM_TXTOPEER, 0x2 | 0x1);
1781 +// agnx_write32(ctl, AGNX_BM_TXTOPEER, 0x1);
1782 +} /* gain_ctlcnt_init */
1785 +static void phy_init(struct agnx_priv *priv)
1787 + void __iomem *ctl = priv->ctl;
1788 + void __iomem *data = priv->data;
1792 + /* Load InitialGainTable */
1793 + gain_table_init(priv);
1795 + agnx_write32(ctl, AGNX_CIR_ADDRWIN, 0x2000000);
1797 + /* Clear the following offsets in Memory Range #2: */
1798 + memset_io(data + 0x5040, 0, 0xa * 4);
1799 + memset_io(data + 0x5080, 0, 0xa * 4);
1800 + memset_io(data + 0x50c0, 0, 0xa * 4);
1801 + memset_io(data + 0x5400, 0, 0x80 * 4);
1802 + memset_io(data + 0x6000, 0, 0x280 * 4);
1803 + memset_io(data + 0x7000, 0, 0x280 * 4);
1804 + memset_io(data + 0x8000, 0, 0x280 * 4);
1806 + /* Initialize the Following Registers According to PCI Revision ID */
1807 + if (priv->revid == 0) {
1808 + /* fixme the part hasn't been update but below has been update
1809 + based on WGM511 */
1810 + agnx_write32(ctl, AGNX_ACI_LEN, 0xf);
1811 + agnx_write32(ctl, AGNX_ACI_TIMER1, 0x1d);
1812 + agnx_write32(ctl, AGNX_ACI_TIMER2, 0x3);
1813 + agnx_write32(ctl, AGNX_ACI_AICCHA0OVE, 0x11);
1814 + agnx_write32(ctl, AGNX_ACI_AICCHA1OVE, 0x0);
1815 + agnx_write32(ctl, AGNX_GCR_THD0A, 0x64);
1816 + agnx_write32(ctl, AGNX_GCR_THD0AL, 0x4b);
1817 + agnx_write32(ctl, AGNX_GCR_THD0B, 0x4b);
1818 + agnx_write32(ctl, AGNX_GCR_DUNSAT, 0x14);
1819 + agnx_write32(ctl, AGNX_GCR_DSAT, 0x24);
1820 + agnx_write32(ctl, AGNX_GCR_DFIRCAL, 0x8);
1821 + agnx_write32(ctl, AGNX_GCR_DGCTL11A, 0x1a);
1822 + agnx_write32(ctl, AGNX_GCR_DGCTL11B, 0x3);
1823 + agnx_write32(ctl, AGNX_GCR_GAININIT, 0xd);
1824 + agnx_write32(ctl, AGNX_GCR_THNOSIG, 0x1);
1825 + agnx_write32(ctl, AGNX_GCR_COARSTEP, 0x7);
1826 + agnx_write32(ctl, AGNX_GCR_SIFST11A, 0x28);
1827 + agnx_write32(ctl, AGNX_GCR_SIFST11B, 0x28);
1828 + reg = agnx_read32(ctl, AGNX_GCR_CWDETEC);
1830 + agnx_write32(ctl, AGNX_GCR_CWDETEC, reg);
1831 + agnx_write32(ctl, AGNX_GCR_0X38, 0x1e);
1832 + agnx_write32(ctl, AGNX_GCR_BOACT, 0x26);
1833 + agnx_write32(ctl, AGNX_GCR_DISCOVMOD, 0x3);
1834 + agnx_write32(ctl, AGNX_GCR_NLISTANT, 0x3);
1835 + agnx_write32(ctl, AGNX_GCR_NACTIANT, 0x3);
1836 + agnx_write32(ctl, AGNX_GCR_NMEASANT, 0x3);
1837 + agnx_write32(ctl, AGNX_GCR_NCAPTANT, 0x3);
1838 + agnx_write32(ctl, AGNX_GCR_THCAP11A, 0x0);
1839 + agnx_write32(ctl, AGNX_GCR_THCAP11B, 0x0);
1840 + agnx_write32(ctl, AGNX_GCR_THCAPRX11A, 0x0);
1841 + agnx_write32(ctl, AGNX_GCR_THCAPRX11B, 0x0);
1842 + agnx_write32(ctl, AGNX_GCR_THLEVDRO, 0x10);
1843 + agnx_write32(ctl, AGNX_GCR_MAXRXTIME11A, 0x1);
1844 + agnx_write32(ctl, AGNX_GCR_MAXRXTIME11B, 0x1);
1845 + agnx_write32(ctl, AGNX_GCR_CORRTIME, 0x190);
1846 + agnx_write32(ctl, AGNX_GCR_SIGHTH, 0x78);
1847 + agnx_write32(ctl, AGNX_GCR_SIGLTH, 0x1c);
1848 + agnx_write32(ctl, AGNX_GCR_CORRDROP, 0x0);
1849 + agnx_write32(ctl, AGNX_GCR_THCD, 0x0);
1850 + agnx_write32(ctl, AGNX_GCR_MAXPOWDIFF, 0x1);
1851 + agnx_write32(ctl, AGNX_GCR_TESTBUS, 0x0);
1852 + agnx_write32(ctl, AGNX_GCR_ANTCFG, 0x1f);
1853 + agnx_write32(ctl, AGNX_GCR_THJUMP, 0x14);
1854 + agnx_write32(ctl, AGNX_GCR_THPOWER, 0x0);
1855 + agnx_write32(ctl, AGNX_GCR_THPOWCLIP, 0x30);
1856 + agnx_write32(ctl, AGNX_GCR_THD0BTFEST, 0x32);
1857 + agnx_write32(ctl, AGNX_GCR_THRX11BPOWMIN, 0x19);
1858 + agnx_write32(ctl, AGNX_GCR_0X14c, 0x0);
1859 + agnx_write32(ctl, AGNX_GCR_0X150, 0x0);
1860 + agnx_write32(ctl, 0x9400, 0x0);
1861 + agnx_write32(ctl, 0x940c, 0x6ff);
1862 + agnx_write32(ctl, 0x9428, 0xa0);
1863 + agnx_write32(ctl, 0x9434, 0x0);
1864 + agnx_write32(ctl, 0x9c04, 0x15);
1865 + agnx_write32(ctl, 0x9c0c, 0x7f);
1866 + agnx_write32(ctl, 0x9c34, 0x0);
1867 + agnx_write32(ctl, 0xc000, 0x38d);
1868 + agnx_write32(ctl, 0x14018, 0x0);
1869 + agnx_write32(ctl, 0x16000, 0x1);
1870 + agnx_write32(ctl, 0x11004, 0x0);
1871 + agnx_write32(ctl, 0xec54, 0xa);
1872 + agnx_write32(ctl, 0xec1c, 0x5);
1873 + } else if (priv->revid > 0) {
1874 + agnx_write32(ctl, AGNX_ACI_LEN, 0xf);
1875 + agnx_write32(ctl, AGNX_ACI_TIMER1, 0x21);
1876 + agnx_write32(ctl, AGNX_ACI_TIMER2, 0x27);
1877 + agnx_write32(ctl, AGNX_ACI_AICCHA0OVE, 0x11);
1878 + agnx_write32(ctl, AGNX_ACI_AICCHA1OVE, 0x0);
1879 + agnx_write32(ctl, AGNX_GCR_DUNSAT, 0x14);
1880 + agnx_write32(ctl, AGNX_GCR_DSAT, 0x24);
1881 + agnx_write32(ctl, AGNX_GCR_DFIRCAL, 0x8);
1882 + agnx_write32(ctl, AGNX_GCR_DGCTL11A, 0x1a);
1883 + agnx_write32(ctl, AGNX_GCR_DGCTL11B, 0x3);
1884 + agnx_write32(ctl, AGNX_GCR_GAININIT, 0xd);
1885 + agnx_write32(ctl, AGNX_GCR_THNOSIG, 0x1);
1886 + agnx_write32(ctl, AGNX_GCR_COARSTEP, 0x7);
1887 + agnx_write32(ctl, AGNX_GCR_SIFST11A, 0x28);
1888 + agnx_write32(ctl, AGNX_GCR_SIFST11B, 0x28);
1889 + agnx_write32(ctl, AGNX_GCR_CWDETEC, 0x0);
1890 + agnx_write32(ctl, AGNX_GCR_0X38, 0x1e);
1891 +// agnx_write32(ctl, AGNX_GCR_BOACT, 0x26);
1892 + agnx_write32(ctl, AGNX_GCR_DISCOVMOD, 0x3);
1894 + agnx_write32(ctl, AGNX_GCR_THCAP11A, 0x32);
1895 + agnx_write32(ctl, AGNX_GCR_THCAP11B, 0x32);
1896 + agnx_write32(ctl, AGNX_GCR_THCAPRX11A, 0x32);
1897 + agnx_write32(ctl, AGNX_GCR_THCAPRX11B, 0x32);
1898 + agnx_write32(ctl, AGNX_GCR_THLEVDRO, 0x10);
1899 + agnx_write32(ctl, AGNX_GCR_MAXRXTIME11A, 0x1ad);
1900 + agnx_write32(ctl, AGNX_GCR_MAXRXTIME11B, 0xa10);
1901 + agnx_write32(ctl, AGNX_GCR_CORRTIME, 0x190);
1902 + agnx_write32(ctl, AGNX_GCR_CORRDROP, 0x0);
1903 + agnx_write32(ctl, AGNX_GCR_THCD, 0x0);
1904 + agnx_write32(ctl, AGNX_GCR_THCS, 0x0);
1905 + agnx_write32(ctl, AGNX_GCR_MAXPOWDIFF, 0x4);
1906 + agnx_write32(ctl, AGNX_GCR_TESTBUS, 0x0);
1907 + agnx_write32(ctl, AGNX_GCR_THJUMP, 0x1e);
1908 + agnx_write32(ctl, AGNX_GCR_THPOWER, 0x0);
1909 + agnx_write32(ctl, AGNX_GCR_THPOWCLIP, 0x2a);
1910 + agnx_write32(ctl, AGNX_GCR_THD0BTFEST, 0x3c);
1911 + agnx_write32(ctl, AGNX_GCR_THRX11BPOWMIN, 0x19);
1912 + agnx_write32(ctl, AGNX_GCR_0X14c, 0x0);
1913 + agnx_write32(ctl, AGNX_GCR_0X150, 0x0);
1914 + agnx_write32(ctl, AGNX_GCR_RXOVERIDE, 0x0);
1915 + agnx_write32(ctl, AGNX_GCR_WATCHDOG, 0x37);
1916 + agnx_write32(ctl, 0x9400, 0x0);
1917 + agnx_write32(ctl, 0x940c, 0x6ff);
1918 + agnx_write32(ctl, 0x9428, 0xa0);
1919 + agnx_write32(ctl, 0x9434, 0x0);
1920 + agnx_write32(ctl, 0x9c04, 0x15);
1921 + agnx_write32(ctl, 0x9c0c, 0x7f);
1922 + agnx_write32(ctl, 0x9c34, 0x0);
1923 + agnx_write32(ctl, 0xc000, 0x38d);
1924 + agnx_write32(ctl, 0x14014, 0x1000);
1925 + agnx_write32(ctl, 0x14018, 0x0);
1926 + agnx_write32(ctl, 0x16000, 0x1);
1927 + agnx_write32(ctl, 0x11004, 0x0);
1928 + agnx_write32(ctl, 0xec54, 0xa);
1929 + agnx_write32(ctl, 0xec1c, 0x50);
1930 + } else if (priv->revid > 1) {
1931 + reg = agnx_read32(ctl, 0xec18);
1933 + agnx_write32(ctl, 0xec18, reg);
1936 + /* Write the TX Fir Coefficient Table */
1937 + tx_fir_table_init(priv);
1939 + reg = agnx_read32(ctl, AGNX_PM_PMCTL);
1941 + agnx_write32(ctl, AGNX_PM_PMCTL, reg);
1942 + reg = agnx_read32(ctl, AGNX_PM_PLLCTL);
1944 + agnx_write32(ctl, AGNX_PM_PLLCTL, reg);
1946 +/* reg = agnx_read32(ctl, 0x1a030); */
1948 +/* agnx_write32(ctl, 0x1a030, reg); */
1950 + agnx_write32(ctl, AGNX_GCR_TRACNT4, 0x113);
1953 +static void chip_init(struct agnx_priv *priv)
1955 + void __iomem *ctl = priv->ctl;
1959 + band_management_init(priv);
1961 + rf_chips_init(priv);
1963 + reg = agnx_read32(ctl, AGNX_PM_PMCTL);
1965 + agnx_write32(ctl, AGNX_PM_PMCTL, reg);
1967 + /* Initialize the PHY */
1970 + encryption_init(priv);
1972 + tx_management_init(priv);
1974 + rx_management_init(priv);
1976 + power_manage_init(priv);
1978 + /* Initialize the Timers */
1979 + agnx_timer_init(priv);
1981 + /* Write 0xc390bf9 to Interrupt Mask (Disable TX) */
1982 + reg = 0xc390bf9 & ~IRQ_TX_BEACON;
1983 + reg &= ~IRQ_TX_DISABLE;
1984 + agnx_write32(ctl, AGNX_INT_MASK, reg);
1986 + reg = agnx_read32(ctl, AGNX_CIR_BLKCTL);
1988 + agnx_write32(ctl, AGNX_CIR_BLKCTL, reg);
1990 + /* set it when need get multicast enable? */
1991 + agnx_write32(ctl, AGNX_BM_MTSM, 0xff);
1995 +static inline void set_promis_and_managed(struct agnx_priv *priv)
1997 + void __iomem *ctl = priv->ctl;
1998 + agnx_write32(ctl, AGNX_SYSITF_SYSMODE, 0x10 | 0x2);
1999 + agnx_write32(ctl, AGNX_SYSITF_SYSMODE, 0x10 | 0x2);
2001 +static inline void set_learn_mode(struct agnx_priv *priv)
2003 + void __iomem *ctl = priv->ctl;
2004 + agnx_write32(ctl, AGNX_SYSITF_SYSMODE, 0x8);
2006 +static inline void set_scan_mode(struct agnx_priv *priv)
2008 + void __iomem *ctl = priv->ctl;
2009 + agnx_write32(ctl, AGNX_SYSITF_SYSMODE, 0x20);
2011 +static inline void set_promiscuous_mode(struct agnx_priv *priv)
2013 + void __iomem *ctl = priv->ctl;
2014 + /* agnx_write32(ctl, AGNX_SYSITF_SYSMODE, 0x210);*/
2015 + agnx_write32(ctl, AGNX_SYSITF_SYSMODE, 0x10);
2017 +static inline void set_managed_mode(struct agnx_priv *priv)
2019 + void __iomem *ctl = priv->ctl;
2020 + agnx_write32(ctl, AGNX_SYSITF_SYSMODE, 0x2);
2022 +static inline void set_adhoc_mode(struct agnx_priv *priv)
2024 + void __iomem *ctl = priv->ctl;
2025 + agnx_write32(ctl, AGNX_SYSITF_SYSMODE, 0x0);
2028 +static void unknow_register_write(struct agnx_priv *priv)
2030 + void __iomem *ctl = priv->ctl;
2032 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x0, 0x3e);
2033 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x4, 0xb2);
2034 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x8, 0x140);
2035 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0xc, 0x1C0);
2036 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x10, 0x1FF);
2037 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x14, 0x1DD);
2038 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x18, 0x15F);
2039 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x1c, 0xA1);
2040 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x20, 0x3E7);
2041 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x24, 0x36B);
2042 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x28, 0x348);
2043 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x2c, 0x37D);
2044 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x30, 0x3DE);
2045 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x34, 0x36);
2046 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x38, 0x64);
2047 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x3c, 0x57);
2048 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x40, 0x23);
2049 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x44, 0x3ED);
2050 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x48, 0x3C9);
2051 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x4c, 0x3CA);
2052 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x50, 0x3E7);
2053 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x54, 0x8);
2054 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x58, 0x1F);
2055 + agnx_write32(ctl, AGNX_UNKNOWN_BASE + 0x5c, 0x1a);
2058 +static void card_interface_init(struct agnx_priv *priv)
2060 + void __iomem *ctl = priv->ctl;
2061 + u8 bssid[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2067 + /* Clear RX Control and Enable RX queues */
2068 + agnx_write32(ctl, AGNX_CIR_RXCTL, 0x8);
2071 + /* Do a full reset of the card */
2072 + card_full_reset(priv);
2075 + /* Check and set Card Endianness */
2076 + reg = ioread32(priv->ctl + AGNX_CIR_ENDIAN);
2077 + /* TODO If not 0xB3B2B1B0 set to 0xB3B2B1B0 */
2078 + printk(KERN_INFO PFX "CIR_ENDIAN is %x\n", reg);
2081 + /* Config the eeprom */
2082 + agnx_write32(ctl, AGNX_CIR_SERIALITF, 0x7000086);
2084 + reg = agnx_read32(ctl, AGNX_CIR_SERIALITF);
2087 + agnx_write32(ctl, AGNX_PM_SOFTRST, 0x80000033);
2088 + reg = agnx_read32(ctl, 0xec50);
2090 + agnx_write32(ctl, 0xec50, reg);
2091 + agnx_write32(ctl, AGNX_PM_SOFTRST, 0x0);
2094 + reg = agnx_read32(ctl, AGNX_SYSITF_GPIOIN);
2096 + reg = agnx_read32(ctl, AGNX_CIR_SERIALITF);
2098 + /* Dump the eeprom */
2100 + char eeprom[0x100000/0x100];
2102 + for (i = 0; i < 0x100000; i += 0x100) {
2103 + agnx_write32(ctl, AGNX_CIR_SERIALITF, 0x3000000 + i);
2105 + reg = agnx_read32(ctl, AGNX_CIR_SERIALITF);
2107 + reg = agnx_read32(ctl, AGNX_CIR_SERIALITF);
2108 + eeprom[i/0x100] = reg & 0xFF;
2111 + print_hex_dump_bytes(PFX "EEPROM: ", DUMP_PREFIX_NONE, eeprom,
2112 + ARRAY_SIZE(eeprom));
2115 + spi_rc_write(ctl, RF_CHIP0, 0x26);
2116 + reg = agnx_read32(ctl, AGNX_SPI_RLSW);
2118 + /* Initialize the system interface */
2119 + system_itf_init(priv);
2122 + /* Chip Initialization (Polaris) */
2126 + /* Calibrate the antennae */
2127 + antenna_calibrate(priv);
2129 + reg = agnx_read32(ctl, 0xec50);
2131 + agnx_write32(ctl, 0xec50, reg);
2132 + agnx_write32(ctl, AGNX_PM_SOFTRST, 0x0);
2133 + agnx_write32(ctl, AGNX_PM_PLLCTL, 0x1);
2135 + reg = agnx_read32(ctl, AGNX_BM_BMCTL);
2137 + agnx_write32(ctl, AGNX_BM_BMCTL, reg);
2138 + enable_receiver(priv);
2139 + reg = agnx_read32(ctl, AGNX_SYSITF_SYSMODE);
2141 + agnx_write32(ctl, AGNX_SYSITF_SYSMODE, reg);
2142 + enable_receiver(priv);
2145 + /* Initialize Gain Control Counts */
2146 + gain_ctlcnt_init(priv);
2148 + /* Write Initial Station Power Template for this station(#0) */
2149 + sta_power_init(priv, LOCAL_STAID);
2152 + /* Initialize the rx,td,tm rings, for each node in the ring */
2158 + agnx_write32(ctl, AGNX_PM_SOFTRST, 0x80000033);
2159 + agnx_write32(ctl, 0xec50, 0xc);
2160 + agnx_write32(ctl, AGNX_PM_SOFTRST, 0x0);
2162 + /* FIXME Initialize the transmit control register */
2163 + agnx_write32(ctl, AGNX_TXM_CTL, 0x194c1);
2165 + enable_receiver(priv);
2168 + /* FIXME Set the Receive Control Mac Address to card address */
2169 + mac_address_set(priv);
2170 + enable_receiver(priv);
2173 + /* Set the recieve request rate */
2174 + /* FIXME Enable the request */
2175 + /* Check packet length */
2176 + /* Set maximum packet length */
2177 +/* agnx_write32(ctl, AGNX_RXM_REQRATE, 0x88195e00); */
2178 +/* enable_receiver(priv); */
2180 + /* Set the Receiver BSSID */
2181 + receiver_bssid_set(priv, bssid);
2183 + /* FIXME Set to managed mode */
2184 + set_managed_mode(priv);
2185 +// set_promiscuous_mode(priv);
2186 +/* set_scan_mode(priv); */
2187 +/* set_learn_mode(priv); */
2188 +// set_promis_and_managed(priv);
2189 +// set_adhoc_mode(priv);
2191 + /* Set the recieve request rate */
2192 + /* Check packet length */
2193 + agnx_write32(ctl, AGNX_RXM_REQRATE, 0x08000000);
2194 + reg = agnx_read32(ctl, AGNX_RXM_REQRATE);
2195 + /* Set maximum packet length */
2196 + reg |= 0x00195e00;
2197 + agnx_write32(ctl, AGNX_RXM_REQRATE, reg);
2199 + /* Configure the RX and TX interrupt */
2200 + reg = ENABLE_RX_INTERRUPT | RX_CACHE_LINE | FRAG_LEN_2048 | FRAG_BE;
2201 + agnx_write32(ctl, AGNX_CIR_RXCFG, reg);
2203 + reg = ENABLE_TX_INTERRUPT | TX_CACHE_LINE | FRAG_LEN_2048 | FRAG_BE;
2204 + agnx_write32(ctl, AGNX_CIR_TXCFG, reg);
2206 + /* Enable RX TX Interrupts */
2207 + agnx_write32(ctl, AGNX_CIR_RXCTL, 0x80);
2208 + agnx_write32(ctl, AGNX_CIR_TXMCTL, 0x80);
2209 + agnx_write32(ctl, AGNX_CIR_TXDCTL, 0x80);
2211 + /* FIXME Set the master control interrupt in block control */
2212 + agnx_write32(ctl, AGNX_CIR_BLKCTL, 0x800);
2214 + /* Enable RX and TX queues */
2215 + reg = agnx_read32(ctl, AGNX_CIR_RXCTL);
2217 + agnx_write32(ctl, AGNX_CIR_RXCTL, reg);
2218 + reg = agnx_read32(ctl, AGNX_CIR_TXMCTL);
2220 + agnx_write32(ctl, AGNX_CIR_TXMCTL, reg);
2221 + reg = agnx_read32(ctl, AGNX_CIR_TXDCTL);
2223 + agnx_write32(ctl, AGNX_CIR_TXDCTL, reg);
2225 + agnx_write32(ctl, AGNX_SYSITF_GPIOUT, 0x5);
2227 + /* unknow_register_write(priv); */
2228 + /* Update local card hash entry */
2229 + hash_write(priv, priv->mac_addr, LOCAL_STAID);
2234 + agnx_set_channel(priv, 1);
2236 +} /* agnx_card_interface_init */
2239 +void agnx_hw_init(struct agnx_priv *priv)
2243 + card_interface_init(priv);
2246 +int agnx_hw_reset(struct agnx_priv *priv)
2248 + return card_full_reset(priv);
2251 +int agnx_set_ssid(struct agnx_priv *priv, u8 *ssid, size_t ssid_len)
2257 +void agnx_set_bssid(struct agnx_priv *priv, u8 *bssid)
2259 + receiver_bssid_set(priv, bssid);
2262 +++ b/drivers/staging/agnx/phy.h
2264 +#ifndef AGNX_PHY_H_
2265 +#define AGNX_PHY_H_
2269 +/* Transmission Managment Registers */
2270 +#define AGNX_TXM_BASE 0x0000
2271 +#define AGNX_TXM_CTL 0x0000 /* control register */
2272 +#define AGNX_TXM_ETMF 0x0004 /* enable transmission management functions */
2273 +#define AGNX_TXM_TXTEMP 0x0008 /* transmission template */
2274 +#define AGNX_TXM_RETRYSTAID 0x000c /* Retry Station ID */
2275 +#define AGNX_TXM_TIMESTAMPLO 0x0010 /* Timestamp Lo */
2276 +#define AGNX_TXM_TIMESTAMPHI 0x0014 /* Timestamp Hi */
2277 +#define AGNX_TXM_TXDELAY 0x0018 /* tx delay */
2278 +#define AGNX_TXM_TBTTLO 0x0020 /* tbtt Lo */
2279 +#define AGNX_TXM_TBTTHI 0x0024 /* tbtt Hi */
2280 +#define AGNX_TXM_BEAINTER 0x0028 /* Beacon Interval */
2281 +#define AGNX_TXM_NAV 0x0030 /* NAV */
2282 +#define AGNX_TXM_CFPMDV 0x0034 /* CFP MDV */
2283 +#define AGNX_TXM_CFPERCNT 0x0038 /* CFP period count */
2284 +#define AGNX_TXM_PROBDELAY 0x003c /* probe delay */
2285 +#define AGNX_TXM_LISINTERCNT 0x0040 /* listen interval count */
2286 +#define AGNX_TXM_DTIMPERICNT 0x004c /* DTIM period count */
2288 +#define AGNX_TXM_BEACON_CTL 0x005c /* beacon control */
2290 +#define AGNX_TXM_SCHEMPCNT 0x007c /* schedule empty count */
2291 +#define AGNX_TXM_MAXTIMOUT 0x0084 /* max timeout exceed count */
2292 +#define AGNX_TXM_MAXCFPTIM 0x0088 /* max CF poll timeout count */
2293 +#define AGNX_TXM_MAXRXTIME 0x008c /* max RX timeout count */
2294 +#define AGNX_TXM_MAXACKTIM 0x0090 /* max ACK timeout count */
2295 +#define AGNX_TXM_DIF01 0x00a0 /* DIF 0-1 */
2296 +#define AGNX_TXM_DIF23 0x00a4 /* DIF 2-3 */
2297 +#define AGNX_TXM_DIF45 0x00a8 /* DIF 4-5 */
2298 +#define AGNX_TXM_DIF67 0x00ac /* DIF 6-7 */
2299 +#define AGNX_TXM_SIFSPIFS 0x00b0 /* SIFS/PIFS */
2300 +#define AGNX_TXM_TIFSEIFS 0x00b4 /* TIFS/EIFS */
2301 +#define AGNX_TXM_MAXCCACNTSLOT 0x00b8 /* max CCA count slot */
2302 +#define AGNX_TXM_SLOTLIMIT 0x00bc /* slot limit/1 msec limit */
2303 +#define AGNX_TXM_CFPOLLRXTIM 0x00f0 /* CF poll RX timeout count */
2304 +#define AGNX_TXM_CFACKT11B 0x00f4 /* CF ack timeout limit for 11b */
2305 +#define AGNX_TXM_CW0 0x0100 /* CW 0 */
2306 +#define AGNX_TXM_SLBEALIM0 0x0108 /* short/long beacon limit 0 */
2307 +#define AGNX_TXM_CW1 0x0120 /* CW 1 */
2308 +#define AGNX_TXM_SLBEALIM1 0x0128 /* short/long beacon limit 1 */
2309 +#define AGNX_TXM_CW2 0x0140 /* CW 2 */
2310 +#define AGNX_TXM_SLBEALIM2 0x0148 /* short/long beacon limit 2 */
2311 +#define AGNX_TXM_CW3 0x0160 /* CW 3 */
2312 +#define AGNX_TXM_SLBEALIM3 0x0168 /* short/long beacon limit 3 */
2313 +#define AGNX_TXM_CW4 0x0180 /* CW 4 */
2314 +#define AGNX_TXM_SLBEALIM4 0x0188 /* short/long beacon limit 4 */
2315 +#define AGNX_TXM_CW5 0x01a0 /* CW 5 */
2316 +#define AGNX_TXM_SLBEALIM5 0x01a8 /* short/long beacon limit 5 */
2317 +#define AGNX_TXM_CW6 0x01c0 /* CW 6 */
2318 +#define AGNX_TXM_SLBEALIM6 0x01c8 /* short/long beacon limit 6 */
2319 +#define AGNX_TXM_CW7 0x01e0 /* CW 7 */
2320 +#define AGNX_TXM_SLBEALIM7 0x01e8 /* short/long beacon limit 7 */
2321 +#define AGNX_TXM_BEACONTEMP 0x1000 /* beacon template */
2322 +#define AGNX_TXM_STAPOWTEMP 0x1a00 /* Station Power Template */
2324 +/* Receive Management Control Registers */
2325 +#define AGNX_RXM_BASE 0x2000
2326 +#define AGNX_RXM_REQRATE 0x2000 /* requested rate */
2327 +#define AGNX_RXM_MACHI 0x2004 /* first 4 bytes of mac address */
2328 +#define AGNX_RXM_MACLO 0x2008 /* last 2 bytes of mac address */
2329 +#define AGNX_RXM_BSSIDHI 0x200c /* bssid hi */
2330 +#define AGNX_RXM_BSSIDLO 0x2010 /* bssid lo */
2331 +#define AGNX_RXM_HASH_CMD_FLAG 0x2014 /* Flags for the RX Hash Command Default:0 */
2332 +#define AGNX_RXM_HASH_CMD_HIGH 0x2018 /* The High half of the Hash Command */
2333 +#define AGNX_RXM_HASH_CMD_LOW 0x201c /* The Low half of the Hash Command */
2334 +#define AGNX_RXM_ROUTAB 0x2020 /* routing table */
2335 +#define ROUTAB_SUBTYPE_SHIFT 24
2336 +#define ROUTAB_TYPE_SHIFT 28
2337 +#define ROUTAB_STATUS_SHIFT 30
2338 +#define ROUTAB_RW_SHIFT 31
2339 +#define ROUTAB_ROUTE_DROP 0xf00000 /* Drop */
2340 +#define ROUTAB_ROUTE_CPU 0x400000 /* CPU */
2341 +#define ROUTAB_ROUTE_ENCRY 0x500800 /* Encryption */
2342 +#define ROUTAB_ROUTE_RFP 0x800000 /* RFP */
2344 +#define ROUTAB_TYPE_MANAG 0x0 /* Management */
2345 +#define ROUTAB_TYPE_CTL 0x1 /* Control */
2346 +#define ROUTAB_TYPE_DATA 0x2 /* Data */
2348 +#define ROUTAB_SUBTYPE_DATA 0x0
2349 +#define ROUTAB_SUBTYPE_DATAACK 0x1
2350 +#define ROUTAB_SUBTYPE_DATAPOLL 0x2
2351 +#define ROUTAB_SUBTYPE_DATAPOLLACK 0x3
2352 +#define ROUTAB_SUBTYPE_NULL 0x4 /* NULL */
2353 +#define ROUTAB_SUBTYPE_NULLACK 0x5
2354 +#define ROUTAB_SUBTYPE_NULLPOLL 0x6
2355 +#define ROUTAB_SUBTYPE_NULLPOLLACK 0x7
2356 +#define ROUTAB_SUBTYPE_QOSDATA 0x8 /* QOS DATA */
2357 +#define ROUTAB_SUBTYPE_QOSDATAACK 0x9
2358 +#define ROUTAB_SUBTYPE_QOSDATAPOLL 0xa
2359 +#define ROUTAB_SUBTYPE_QOSDATAACKPOLL 0xb
2360 +#define ROUTAB_SUBTYPE_QOSNULL 0xc
2361 +#define ROUTAB_SUBTYPE_QOSNULLACK 0xd
2362 +#define ROUTAB_SUBTYPE_QOSNULLPOLL 0xe
2363 +#define ROUTAB_SUBTYPE_QOSNULLPOLLACK 0xf
2364 +#define AGNX_RXM_DELAY11 0x2024 /* delay 11(AB) */
2365 +#define AGNX_RXM_SOF_CNT 0x2028 /* SOF Count */
2366 +#define AGNX_RXM_FRAG_CNT 0x202c /* Fragment Count*/
2367 +#define AGNX_RXM_FCS_CNT 0x2030 /* FCS Count */
2368 +#define AGNX_RXM_BSSID_MISS_CNT 0x2034 /* BSSID Miss Count */
2369 +#define AGNX_RXM_PDU_ERR_CNT 0x2038 /* PDU Error Count */
2370 +#define AGNX_RXM_DEST_MISS_CNT 0x203C /* Destination Miss Count */
2371 +#define AGNX_RXM_DROP_CNT 0x2040 /* Drop Count */
2372 +#define AGNX_RXM_ABORT_CNT 0x2044 /* Abort Count */
2373 +#define AGNX_RXM_RELAY_CNT 0x2048 /* Relay Count */
2374 +#define AGNX_RXM_HASH_MISS_CNT 0x204c /* Hash Miss Count */
2375 +#define AGNX_RXM_SA_HI 0x2050 /* Address of received packet Hi */
2376 +#define AGNX_RXM_SA_LO 0x2054 /* Address of received packet Lo */
2377 +#define AGNX_RXM_HASH_DUMP_LST 0x2100 /* Contains Hash Data */
2378 +#define AGNX_RXM_HASH_DUMP_MST 0x2104 /* Contains Hash Data */
2379 +#define AGNX_RXM_HASH_DUMP_DATA 0x2108 /* The Station ID to dump */
2382 +/* Encryption Managment */
2383 +#define AGNX_ENCRY_BASE 0x2400
2384 +#define AGNX_ENCRY_WEPKEY0 0x2440 /* wep key #0 */
2385 +#define AGNX_ENCRY_WEPKEY1 0x2444 /* wep key #1 */
2386 +#define AGNX_ENCRY_WEPKEY2 0x2448 /* wep key #2 */
2387 +#define AGNX_ENCRY_WEPKEY3 0x244c /* wep key #3 */
2388 +#define AGNX_ENCRY_CCMRECTL 0x2460 /* ccm replay control */
2391 +/* Band Management Registers */
2392 +#define AGNX_BM_BASE 0x2c00
2393 +#define AGNX_BM_BMCTL 0x2c00 /* band management control */
2394 +#define AGNX_BM_TXWADDR 0x2c18 /* tx workqueue address start */
2395 +#define AGNX_BM_TXTOPEER 0x2c24 /* transmit to peers */
2396 +#define AGNX_BM_FPLHP 0x2c2c /* free pool list head pointer */
2397 +#define AGNX_BM_FPLTP 0x2c30 /* free pool list tail pointer */
2398 +#define AGNX_BM_FPCNT 0x2c34 /* free pool count */
2399 +#define AGNX_BM_CIPDUWCNT 0x2c38 /* card interface pdu workqueue count */
2400 +#define AGNX_BM_SPPDUWCNT 0x2c3c /* sp pdu workqueue count */
2401 +#define AGNX_BM_RFPPDUWCNT 0x2c40 /* rfp pdu workqueue count */
2402 +#define AGNX_BM_RHPPDUWCNT 0x2c44 /* rhp pdu workqueue count */
2403 +#define AGNX_BM_CIWQCTL 0x2c48 /* Card Interface WorkQueue Control */
2404 +#define AGNX_BM_CPUTXWCTL 0x2c50 /* cpu tx workqueue control */
2405 +#define AGNX_BM_CPURXWCTL 0x2c58 /* cpu rx workqueue control */
2406 +#define AGNX_BM_CPULWCTL 0x2c60 /* cpu low workqueue control */
2407 +#define AGNX_BM_CPUHWCTL 0x2c68 /* cpu high workqueue control */
2408 +#define AGNX_BM_SPTXWCTL 0x2c70 /* sp tx workqueue control */
2409 +#define AGNX_BM_SPRXWCTL 0x2c78 /* sp rx workqueue control */
2410 +#define AGNX_BM_RFPWCTL 0x2c80 /* RFP workqueue control */
2411 +#define AGNX_BM_MTSM 0x2c90 /* Multicast Transmit Station Mask */
2413 +/* Card Interface Registers (32bits) */
2414 +#define AGNX_CIR_BASE 0x3000
2415 +#define AGNX_CIR_BLKCTL 0x3000 /* block control*/
2416 +#define AGNX_STAT_TX 0x1
2417 +#define AGNX_STAT_RX 0x2
2418 +#define AGNX_STAT_X 0x4
2419 +/* Below two interrupt flags will be set by our but not CPU or the card */
2420 +#define AGNX_STAT_TXD 0x10
2421 +#define AGNX_STAT_TXM 0x20
2423 +#define AGNX_CIR_ADDRWIN 0x3004 /* Addressable Windows*/
2424 +#define AGNX_CIR_ENDIAN 0x3008 /* card endianness */
2425 +#define AGNX_CIR_SERIALITF 0x3020 /* serial interface */
2426 +#define AGNX_CIR_RXCFG 0x3040 /* receive config */
2427 +#define ENABLE_RX_INTERRUPT 0x20
2428 +#define RX_CACHE_LINE 0x8
2429 +/* the RX fragment length */
2430 +#define FRAG_LEN_256 0x0 /* 256B */
2431 +#define FRAG_LEN_512 0x1
2432 +#define FRAG_LEN_1024 0x2
2433 +#define FRAG_LEN_2048 0x3
2434 +#define FRAG_BE 0x10
2435 +#define AGNX_CIR_RXCTL 0x3050 /* receive control */
2436 +/* memory address, chipside */
2437 +#define AGNX_CIR_RXCMSTART 0x3054 /* receive client memory start */
2438 +#define AGNX_CIR_RXCMEND 0x3058 /* receive client memory end */
2439 +/* memory address, pci */
2440 +#define AGNX_CIR_RXHOSTADDR 0x3060 /* receive hostside address */
2441 +/* memory address, chipside */
2442 +#define AGNX_CIR_RXCLIADDR 0x3064 /* receive clientside address */
2443 +#define AGNX_CIR_RXDMACTL 0x3068 /* receive dma control */
2444 +#define AGNX_CIR_TXCFG 0x3080 /* transmit config */
2445 +#define AGNX_CIR_TXMCTL 0x3090 /* Transmit Management Control */
2446 +#define ENABLE_TX_INTERRUPT 0x20
2447 +#define TX_CACHE_LINE 0x8
2448 +#define AGNX_CIR_TXMSTART 0x3094 /* Transmit Management Start */
2449 +#define AGNX_CIR_TXMEND 0x3098 /* Transmit Management End */
2450 +#define AGNX_CIR_TXDCTL 0x30a0 /* transmit data control */
2451 +/* memeory address, chipset */
2452 +#define AGNX_CIR_TXDSTART 0x30a4 /* transmit data start */
2453 +#define AGNX_CIR_TXDEND 0x30a8 /* transmit data end */
2454 +#define AGNX_CIR_TXMHADDR 0x30b0 /* Transmit Management Hostside Address */
2455 +#define AGNX_CIR_TXMCADDR 0x30b4 /* Transmit Management Clientside Address */
2456 +#define AGNX_CIR_TXDMACTL 0x30b8 /* transmit dma control */
2459 +/* Power Managment Unit */
2460 +#define AGNX_PM_BASE 0x3c00
2461 +#define AGNX_PM_PMCTL 0x3c00 /* PM Control*/
2462 +#define AGNX_PM_MACMSW 0x3c08 /* MAC Manual Slow Work Enable */
2463 +#define AGNX_PM_RFCTL 0x3c0c /* RF Control */
2464 +#define AGNX_PM_PHYMW 0x3c14 /* Phy Mannal Work */
2465 +#define AGNX_PM_SOFTRST 0x3c18 /* PMU Soft Reset */
2466 +#define AGNX_PM_PLLCTL 0x3c1c /* PMU PLL control*/
2467 +#define AGNX_PM_TESTPHY 0x3c24 /* PMU Test Phy */
2470 +/* Interrupt Control interface */
2471 +#define AGNX_INT_BASE 0x4000
2472 +#define AGNX_INT_STAT 0x4000 /* interrupt status */
2473 +#define AGNX_INT_MASK 0x400c /* interrupt mask */
2475 +#define IRQ_TX_BEACON 0x1 /* TX Beacon */
2476 +#define IRQ_TX_RETRY 0x8 /* TX Retry Interrupt */
2477 +#define IRQ_TX_ACTIVITY 0x10 /* TX Activity */
2478 +#define IRQ_RX_ACTIVITY 0x20 /* RX Activity */
2479 +/* FIXME I guess that instead RX a none exist staion's packet or
2480 + the station hasn't been init */
2481 +#define IRQ_RX_X 0x40
2482 +#define IRQ_RX_Y 0x80 /* RX ? */
2483 +#define IRQ_RX_HASHHIT 0x100 /* RX Hash Hit */
2484 +#define IRQ_RX_FRAME 0x200 /* RX Frame */
2485 +#define IRQ_ERR_INT 0x400 /* Error Interrupt */
2486 +#define IRQ_TX_QUE_FULL 0x800 /* TX Workqueue Full */
2487 +#define IRQ_BANDMAN_ERR 0x10000 /* Bandwidth Management Error */
2488 +#define IRQ_TX_DISABLE 0x20000 /* TX Disable */
2489 +#define IRQ_RX_IVASESKEY 0x80000 /* RX Invalid Session Key */
2490 +#define IRQ_RX_KEYIDMIS 0x100000 /* RX key ID Mismatch */
2491 +#define IRQ_REP_THHIT 0x200000 /* Replay Threshold Hit */
2492 +#define IRQ_TIMER1 0x4000000 /* Timer1 */
2493 +#define IRQ_TIMER_CNT 0x10000000 /* Timer Count */
2494 +#define IRQ_PHY_FASTINT 0x20000000 /* Phy Fast Interrupt */
2495 +#define IRQ_PHY_SLOWINT 0x40000000 /* Phy Slow Interrupt */
2496 +#define IRQ_OTHER 0x80000000 /* Unknow interrupt */
2497 +#define AGNX_IRQ_ALL 0xffffffff
2499 +/* System Interface */
2500 +#define AGNX_SYSITF_BASE 0x4400
2501 +#define AGNX_SYSITF_SYSMODE 0x4400 /* system mode */
2502 +#define AGNX_SYSITF_GPIOIN 0x4410 /* GPIO In */
2503 +/* PIN lines for leds? */
2504 +#define AGNX_SYSITF_GPIOUT 0x4414 /* GPIO Out */
2506 +/* Timer Control */
2507 +#define AGNX_TIMCTL_TIMER1 0x4800 /* Timer 1 */
2508 +#define AGNX_TIMCTL_TIM1CTL 0x4808 /* Timer 1 Control */
2511 +/* Antenna Calibration Interface */
2512 +#define AGNX_ACI_BASE 0x5000
2513 +#define AGNX_ACI_MODE 0x5000 /* Mode */
2514 +#define AGNX_ACI_MEASURE 0x5004 /* Measure */
2515 +#define AGNX_ACI_SELCHAIN 0x5008 /* Select Chain */
2516 +#define AGNX_ACI_LEN 0x500c /* Length */
2517 +#define AGNX_ACI_TIMER1 0x5018 /* Timer 1 */
2518 +#define AGNX_ACI_TIMER2 0x501c /* Timer 2 */
2519 +#define AGNX_ACI_OFFSET 0x5020 /* Offset */
2520 +#define AGNX_ACI_STATUS 0x5030 /* Status */
2521 +#define CALI_IDLE 0x0
2522 +#define CALI_DONE 0x1
2523 +#define CALI_BUSY 0x2
2524 +#define CALI_ERR 0x3
2525 +#define AGNX_ACI_AICCHA0OVE 0x5034 /* AIC Channel 0 Override */
2526 +#define AGNX_ACI_AICCHA1OVE 0x5038 /* AIC Channel 1 Override */
2528 +/* Gain Control Registers */
2529 +#define AGNX_GCR_BASE 0x9000
2530 +/* threshold of primary antenna */
2531 +#define AGNX_GCR_THD0A 0x9000 /* threshold? D0 A */
2532 +/* low threshold of primary antenna */
2533 +#define AGNX_GCR_THD0AL 0x9004 /* threshold? D0 A low */
2534 +/* threshold of secondary antenna */
2535 +#define AGNX_GCR_THD0B 0x9008 /* threshold? D0_B */
2536 +#define AGNX_GCR_DUNSAT 0x900c /* d unsaturated */
2537 +#define AGNX_GCR_DSAT 0x9010 /* d saturated */
2538 +#define AGNX_GCR_DFIRCAL 0x9014 /* D Fir/Cal */
2539 +#define AGNX_GCR_DGCTL11A 0x9018 /* d gain control 11a */
2540 +#define AGNX_GCR_DGCTL11B 0x901c /* d gain control 11b */
2541 +/* strength of gain */
2542 +#define AGNX_GCR_GAININIT 0x9020 /* gain initialization */
2543 +#define AGNX_GCR_THNOSIG 0x9024 /* threhold no signal */
2544 +#define AGNX_GCR_COARSTEP 0x9028 /* coarse stepping */
2545 +#define AGNX_GCR_SIFST11A 0x902c /* sifx time 11a */
2546 +#define AGNX_GCR_SIFST11B 0x9030 /* sifx time 11b */
2547 +#define AGNX_GCR_CWDETEC 0x9034 /* cw detection */
2548 +#define AGNX_GCR_0X38 0x9038 /* ???? */
2549 +#define AGNX_GCR_BOACT 0x903c /* BO Active */
2550 +#define AGNX_GCR_BOINACT 0x9040 /* BO Inactive */
2551 +#define AGNX_GCR_BODYNA 0x9044 /* BO dynamic */
2552 +/* 802.11 mode(a,b,g) */
2553 +#define AGNX_GCR_DISCOVMOD 0x9048 /* discovery mode */
2554 +#define AGNX_GCR_NLISTANT 0x904c /* number of listening antenna */
2555 +#define AGNX_GCR_NACTIANT 0x9050 /* number of active antenna */
2556 +#define AGNX_GCR_NMEASANT 0x9054 /* number of measuring antenna */
2557 +#define AGNX_GCR_NCAPTANT 0x9058 /* number of capture antenna */
2558 +#define AGNX_GCR_THCAP11A 0x905c /* threshold capture 11a */
2559 +#define AGNX_GCR_THCAP11B 0x9060 /* threshold capture 11b */
2560 +#define AGNX_GCR_THCAPRX11A 0x9064 /* threshold capture rx 11a */
2561 +#define AGNX_GCR_THCAPRX11B 0x9068 /* threshold capture rx 11b */
2562 +#define AGNX_GCR_THLEVDRO 0x906c /* threshold level drop */
2563 +#define AGNX_GCR_GAINSET0 0x9070 /* Gainset 0 */
2564 +#define AGNX_GCR_GAINSET1 0x9074 /* Gainset 1 */
2565 +#define AGNX_GCR_GAINSET2 0x9078 /* Gainset 2 */
2566 +#define AGNX_GCR_MAXRXTIME11A 0x907c /* maximum rx time 11a */
2567 +#define AGNX_GCR_MAXRXTIME11B 0x9080 /* maximum rx time 11b */
2568 +#define AGNX_GCR_CORRTIME 0x9084 /* correction time */
2569 +/* reset the subsystem, 0 = disable, 1 = enable */
2570 +#define AGNX_GCR_RSTGCTL 0x9088 /* reset gain control */
2571 +/* channel receiving */
2572 +#define AGNX_GCR_RXCHANEL 0x908c /* receive channel */
2573 +#define AGNX_GCR_NOISE0 0x9090 /* Noise 0 */
2574 +#define AGNX_GCR_NOISE1 0x9094 /* Noise 1 */
2575 +#define AGNX_GCR_NOISE2 0x9098 /* Noise 2 */
2576 +#define AGNX_GCR_SIGHTH 0x909c /* Signal High Threshold */
2577 +#define AGNX_GCR_SIGLTH 0x90a0 /* Signal Low Threshold */
2578 +#define AGNX_GCR_CORRDROP 0x90a4 /* correction drop */
2579 +/* threshold of tertiay antenna */
2580 +#define AGNX_GCR_THCD 0x90a8 /* threshold? CD */
2581 +#define AGNX_GCR_THCS 0x90ac /* threshold? CS */
2582 +#define AGNX_GCR_MAXPOWDIFF 0x90b8 /* maximum power difference */
2583 +#define AGNX_GCR_TRACNT4 0x90ec /* Transition Count 4 */
2584 +#define AGNX_GCR_TRACNT5 0x90f0 /* transition count 5 */
2585 +#define AGNX_GCR_TRACNT6 0x90f4 /* transition count 6 */
2586 +#define AGNX_GCR_TRACNT7 0x90f8 /* transition coutn 7 */
2587 +#define AGNX_GCR_TESTBUS 0x911c /* test bus */
2588 +#define AGNX_GCR_CHAINNUM 0x9120 /* Number of Chains */
2589 +#define AGNX_GCR_ANTCFG 0x9124 /* Antenna Config */
2590 +#define AGNX_GCR_THJUMP 0x912c /* threhold jump */
2591 +#define AGNX_GCR_THPOWER 0x9130 /* threshold power */
2592 +#define AGNX_GCR_THPOWCLIP 0x9134 /* threshold power clip*/
2593 +#define AGNX_GCR_FORCECTLCLK 0x9138 /* Force Gain Control Clock */
2594 +#define AGNX_GCR_GAINSETWRITE 0x913c /* Gainset Write */
2595 +#define AGNX_GCR_THD0BTFEST 0x9140 /* threshold d0 b tf estimate */
2596 +#define AGNX_GCR_THRX11BPOWMIN 0x9144 /* threshold rx 11b power minimum */
2597 +#define AGNX_GCR_0X14c 0x914c /* ?? */
2598 +#define AGNX_GCR_0X150 0x9150 /* ?? */
2599 +#define AGNX_GCR_RXOVERIDE 0x9194 /* recieve override */
2600 +#define AGNX_GCR_WATCHDOG 0x91b0 /* watchdog timeout */
2603 +/* Spi Interface */
2604 +#define AGNX_SPI_BASE 0xdc00
2605 +#define AGNX_SPI_CFG 0xdc00 /* spi configuration */
2606 +/* Only accept 16 bits */
2607 +#define AGNX_SPI_WMSW 0xdc04 /* write most significant word */
2608 +/* Only accept 16 bits */
2609 +#define AGNX_SPI_WLSW 0xdc08 /* write least significant word */
2610 +#define AGNX_SPI_CTL 0xdc0c /* spi control */
2611 +#define AGNX_SPI_RMSW 0xdc10 /* read most significant word */
2612 +#define AGNX_SPI_RLSW 0xdc14 /* read least significant word */
2613 +/* SPI Control Mask */
2614 +#define SPI_READ_CTL 0x4000 /* read control */
2615 +#define SPI_BUSY_CTL 0x8000 /* busy control */
2616 +/* RF and synth chips in spi */
2617 +#define RF_CHIP0 0x400
2618 +#define RF_CHIP1 0x800
2619 +#define RF_CHIP2 0x1000
2620 +#define SYNTH_CHIP 0x2000
2622 +/* Unknown register */
2623 +#define AGNX_UNKNOWN_BASE 0x7800
2625 +/* FIXME MonitorGain */
2626 +#define AGNX_MONGCR_BASE 0x12000
2629 +#define AGNX_GAIN_TABLE 0x12400
2631 +/* The initial FIR coefficient table */
2632 +#define AGNX_FIR_BASE 0x19804
2634 +#define AGNX_ENGINE_LOOKUP_TBL 0x800
2636 +/* eeprom commands */
2637 +#define EEPROM_CMD_NULL 0x0 /* NULL */
2638 +#define EEPROM_CMD_WRITE 0x2 /* write */
2639 +#define EEPROM_CMD_READ 0x3 /* read */
2640 +#define EEPROM_CMD_STATUSREAD 0x5 /* status register read */
2641 +#define EEPROM_CMD_WRITEENABLE 0x6 /* write enable */
2642 +#define EEPROM_CMD_CONFIGURE 0x7 /* configure */
2644 +#define EEPROM_DATAFORCOFIGURE 0x6 /* ??? */
2646 +/* eeprom address */
2647 +#define EEPROM_ADDR_SUBVID 0x0 /* Sub Vendor ID */
2648 +#define EEPROM_ADDR_SUBSID 0x2 /* Sub System ID */
2649 +#define EEPROM_ADDR_MACADDR 0x146 /* MAC Address */
2650 +#define EEPROM_ADDR_LOTYPE 0x14f /* LO type */
2652 +struct agnx_eeprom {
2653 + u8 data; /* date */
2654 + u16 address; /* address in EEPROM */
2655 + u8 cmd; /* command, unknown, status */
2656 +} __attribute__((__packed__));
2658 +#define AGNX_EEPROM_COMMAND_SHIFT 5
2659 +#define AGNX_EEPROM_COMMAND_STAT 0x01
2661 +void disable_receiver(struct agnx_priv *priv);
2662 +void enable_receiver(struct agnx_priv *priv);
2663 +u8 read_from_eeprom(struct agnx_priv *priv, u16 address);
2664 +void agnx_hw_init(struct agnx_priv *priv);
2665 +int agnx_hw_reset(struct agnx_priv *priv);
2666 +int agnx_set_ssid(struct agnx_priv *priv, u8 *ssid, size_t ssid_len);
2667 +void agnx_set_bssid(struct agnx_priv *priv, u8 *bssid);
2668 +void enable_power_saving(struct agnx_priv *priv);
2669 +void disable_power_saving(struct agnx_priv *priv);
2670 +void calibrate_antenna_period(unsigned long data);
2672 +#endif /* AGNX_PHY_H_ */
2674 +++ b/drivers/staging/agnx/rf.c
2677 + * Airgo MIMO wireless driver
2679 + * Copyright (c) 2007 Li YanBo <dreamfly281@gmail.com>
2681 + * Thanks for Jeff Williams <angelbane@gmail.com> do reverse engineer
2682 + * works and published the SPECS at http://airgo.wdwconsulting.net/mymoin
2684 + * This program is free software; you can redistribute it and/or modify
2685 + * it under the terms of the GNU General Public License version 2 as
2686 + * published by the Free Software Foundation;
2689 +#include <linux/pci.h>
2690 +#include <linux/delay.h>
2697 +static inline void spi_write(void __iomem *region, u32 chip_ids, u32 sw,
2698 + u16 size, u32 control)
2701 + u32 lsw = sw & 0xffff; /* lower 16 bits of sw*/
2702 + u32 msw = sw >> 16; /* high 16 bits of sw */
2704 + /* FIXME Write Most Significant Word of the 32bit data to MSW */
2705 + /* FIXME And Least Significant Word to LSW */
2706 + iowrite32((lsw), region + AGNX_SPI_WLSW);
2707 + iowrite32((msw), region + AGNX_SPI_WMSW);
2708 + reg = chip_ids | size | control;
2709 + /* Write chip id(s), write size and busy control to Control Register */
2710 + iowrite32((reg), region + AGNX_SPI_CTL);
2711 + /* Wait for Busy control to clear */
2716 + * Write to SPI Synth register
2718 +static inline void spi_sy_write(void __iomem *region, u32 chip_ids, u32 sw)
2720 + /* FIXME the size 0x15 is a magic value*/
2721 + spi_write(region, chip_ids, sw, 0x15, SPI_BUSY_CTL);
2725 + * Write to SPI RF register
2727 +static inline void spi_rf_write(void __iomem *region, u32 chip_ids, u32 sw)
2729 + /* FIXME the size 0xd is a magic value*/
2730 + spi_write(region, chip_ids, sw, 0xd, SPI_BUSY_CTL);
2731 +} /* spi_rf_write */
2734 + * Write to SPI with Read Control bit set
2736 +inline void spi_rc_write(void __iomem *region, u32 chip_ids, u32 sw)
2738 + /* FIXME the size 0xe5 is a magic value */
2739 + spi_write(region, chip_ids, sw, 0xe5, SPI_BUSY_CTL|SPI_READ_CTL);
2742 +/* Get the active chains's count */
2743 +static int get_active_chains(struct agnx_priv *priv)
2745 + void __iomem *ctl = priv->ctl;
2750 + spi_rc_write(ctl, RF_CHIP0, 0x21);
2751 + reg = agnx_read32(ctl, AGNX_SPI_RLSW);
2755 + spi_rc_write(ctl, RF_CHIP1, 0x21);
2756 + reg = agnx_read32(ctl, AGNX_SPI_RLSW);
2760 + spi_rc_write(ctl, RF_CHIP2, 0x21);
2761 + reg = agnx_read32(ctl, AGNX_SPI_RLSW);
2765 + spi_rc_write(ctl, RF_CHIP0, 0x26);
2766 + reg = agnx_read32(ctl, AGNX_SPI_RLSW);
2768 + printk(KERN_WARNING PFX "Unmatched rf chips result\n");
2771 +} /* get_active_chains */
2773 +void rf_chips_init(struct agnx_priv *priv)
2775 + void __iomem *ctl = priv->ctl;
2780 + if (priv->revid == 1) {
2781 + reg = agnx_read32(ctl, AGNX_SYSITF_GPIOUT);
2783 + agnx_write32(ctl, AGNX_SYSITF_GPIOUT, reg);
2786 + /* Set SPI clock speed to 200NS */
2787 + reg = agnx_read32(ctl, AGNX_SPI_CFG);
2790 + agnx_write32(ctl, AGNX_SPI_CFG, reg);
2792 + /* Set SPI clock speed to 50NS */
2793 + reg = agnx_read32(ctl, AGNX_SPI_CFG);
2796 + agnx_write32(ctl, AGNX_SPI_CFG, reg);
2798 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1101);
2800 + num = get_active_chains(priv);
2801 + printk(KERN_INFO PFX "Active chains are %d\n", num);
2803 + reg = agnx_read32(ctl, AGNX_SPI_CFG);
2805 + agnx_write32(ctl, AGNX_SPI_CFG, reg);
2807 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1908);
2808 +} /* rf_chips_init */
2811 +static u32 channel_tbl[15][9] = {
2812 + {0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2813 + {1, 0x00, 0x00, 0x624, 0x00, 0x1a4, 0x28, 0x00, 0x1e},
2814 + {2, 0x00, 0x00, 0x615, 0x00, 0x1ae, 0x28, 0x00, 0x1e},
2815 + {3, 0x00, 0x00, 0x61a, 0x00, 0x1ae, 0x28, 0x00, 0x1e},
2816 + {4, 0x00, 0x00, 0x61f, 0x00, 0x1ae, 0x28, 0x00, 0x1e},
2817 + {5, 0x00, 0x00, 0x624, 0x00, 0x1ae, 0x28, 0x00, 0x1e},
2818 + {6, 0x00, 0x00, 0x61f, 0x00, 0x1b3, 0x28, 0x00, 0x1e},
2819 + {7, 0x00, 0x00, 0x624, 0x00, 0x1b3, 0x28, 0x00, 0x1e},
2820 + {8, 0x00, 0x00, 0x629, 0x00, 0x1b3, 0x28, 0x00, 0x1e},
2821 + {9, 0x00, 0x00, 0x624, 0x00, 0x1b8, 0x28, 0x00, 0x1e},
2822 + {10, 0x00, 0x00, 0x629, 0x00, 0x1b8, 0x28, 0x00, 0x1e},
2823 + {11, 0x00, 0x00, 0x62e, 0x00, 0x1b8, 0x28, 0x00, 0x1e},
2824 + {12, 0x00, 0x00, 0x633, 0x00, 0x1b8, 0x28, 0x00, 0x1e},
2825 + {13, 0x00, 0x00, 0x628, 0x00, 0x1b8, 0x28, 0x00, 0x1e},
2826 + {14, 0x00, 0x00, 0x644, 0x00, 0x1b8, 0x28, 0x00, 0x1e},
2831 +channel_tbl_write(struct agnx_priv *priv, unsigned int channel, unsigned int reg_num)
2833 + void __iomem *ctl = priv->ctl;
2836 + reg = channel_tbl[channel][reg_num];
2839 + spi_sy_write(ctl, SYNTH_CHIP, reg);
2842 +static void synth_freq_set(struct agnx_priv *priv, unsigned int channel)
2844 + void __iomem *ctl = priv->ctl;
2848 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1, 0x1201);
2850 + /* Set the Clock bits to 50NS */
2851 + reg = agnx_read32(ctl, AGNX_SPI_CFG);
2854 + agnx_write32(ctl, AGNX_SPI_CFG, reg);
2856 + /* Write 0x00c0 to LSW and 0x3 to MSW of Synth Chip */
2857 + spi_sy_write(ctl, SYNTH_CHIP, 0x300c0);
2859 + spi_sy_write(ctl, SYNTH_CHIP, 0x32);
2861 + /* # Write to Register 1 on the Synth Chip */
2862 + channel_tbl_write(priv, channel, 1);
2863 + /* # Write to Register 3 on the Synth Chip */
2864 + channel_tbl_write(priv, channel, 3);
2865 + /* # Write to Register 6 on the Synth Chip */
2866 + channel_tbl_write(priv, channel, 6);
2867 + /* # Write to Register 5 on the Synth Chip */
2868 + channel_tbl_write(priv, channel, 5);
2869 + /* # Write to register 8 on the Synth Chip */
2870 + channel_tbl_write(priv, channel, 8);
2872 + /* FIXME Clear the clock bits */
2873 + reg = agnx_read32(ctl, AGNX_SPI_CFG);
2875 + agnx_write32(ctl, AGNX_SPI_CFG, reg);
2876 +} /* synth_chip_init */
2879 +static void antenna_init(struct agnx_priv *priv, int num_antenna)
2881 + void __iomem *ctl = priv->ctl;
2883 + switch (num_antenna) {
2885 + agnx_write32(ctl, AGNX_GCR_NLISTANT, 1);
2886 + agnx_write32(ctl, AGNX_GCR_NMEASANT, 1);
2887 + agnx_write32(ctl, AGNX_GCR_NACTIANT, 1);
2888 + agnx_write32(ctl, AGNX_GCR_NCAPTANT, 1);
2890 + agnx_write32(ctl, AGNX_GCR_ANTCFG, 7);
2891 + agnx_write32(ctl, AGNX_GCR_BOACT, 34);
2892 + agnx_write32(ctl, AGNX_GCR_BOINACT, 34);
2893 + agnx_write32(ctl, AGNX_GCR_BODYNA, 30);
2895 + agnx_write32(ctl, AGNX_GCR_THD0A, 125);
2896 + agnx_write32(ctl, AGNX_GCR_THD0AL, 100);
2897 + agnx_write32(ctl, AGNX_GCR_THD0B, 90);
2899 + agnx_write32(ctl, AGNX_GCR_THD0BTFEST, 80);
2900 + agnx_write32(ctl, AGNX_GCR_SIGHTH, 100);
2901 + agnx_write32(ctl, AGNX_GCR_SIGLTH, 16);
2904 + agnx_write32(ctl, AGNX_GCR_NLISTANT, 2);
2905 + agnx_write32(ctl, AGNX_GCR_NMEASANT, 2);
2906 + agnx_write32(ctl, AGNX_GCR_NACTIANT, 2);
2907 + agnx_write32(ctl, AGNX_GCR_NCAPTANT, 2);
2908 + agnx_write32(ctl, AGNX_GCR_ANTCFG, 15);
2909 + agnx_write32(ctl, AGNX_GCR_BOACT, 36);
2910 + agnx_write32(ctl, AGNX_GCR_BOINACT, 36);
2911 + agnx_write32(ctl, AGNX_GCR_BODYNA, 32);
2912 + agnx_write32(ctl, AGNX_GCR_THD0A, 120);
2913 + agnx_write32(ctl, AGNX_GCR_THD0AL, 100);
2914 + agnx_write32(ctl, AGNX_GCR_THD0B, 80);
2915 + agnx_write32(ctl, AGNX_GCR_THD0BTFEST, 70);
2916 + agnx_write32(ctl, AGNX_GCR_SIGHTH, 100);
2917 + agnx_write32(ctl, AGNX_GCR_SIGLTH, 32);
2920 + agnx_write32(ctl, AGNX_GCR_NLISTANT, 3);
2921 + agnx_write32(ctl, AGNX_GCR_NMEASANT, 3);
2922 + agnx_write32(ctl, AGNX_GCR_NACTIANT, 3);
2923 + agnx_write32(ctl, AGNX_GCR_NCAPTANT, 3);
2924 + agnx_write32(ctl, AGNX_GCR_ANTCFG, 31);
2925 + agnx_write32(ctl, AGNX_GCR_BOACT, 36);
2926 + agnx_write32(ctl, AGNX_GCR_BOINACT, 36);
2927 + agnx_write32(ctl, AGNX_GCR_BODYNA, 32);
2928 + agnx_write32(ctl, AGNX_GCR_THD0A, 100);
2929 + agnx_write32(ctl, AGNX_GCR_THD0AL, 100);
2930 + agnx_write32(ctl, AGNX_GCR_THD0B, 70);
2931 + agnx_write32(ctl, AGNX_GCR_THD0BTFEST, 70);
2932 + agnx_write32(ctl, AGNX_GCR_SIGHTH, 100);
2933 + agnx_write32(ctl, AGNX_GCR_SIGLTH, 48);
2934 +// agnx_write32(ctl, AGNX_GCR_SIGLTH, 16);
2937 + printk(KERN_WARNING PFX "Unknow antenna number\n");
2939 +} /* antenna_init */
2941 +static void chain_update(struct agnx_priv *priv, u32 chain)
2943 + void __iomem *ctl = priv->ctl;
2947 + spi_rc_write(ctl, RF_CHIP0, 0x20);
2948 + reg = agnx_read32(ctl, AGNX_SPI_RLSW);
2951 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1, reg|0x1000);
2952 + else if (reg != 0x0)
2953 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, reg|0x1000);
2955 + if (chain == 3 || chain == 6) {
2956 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, reg|0x1000);
2957 + agnx_write32(ctl, AGNX_GCR_RXOVERIDE, 0x0);
2958 + } else if (chain == 2 || chain == 4) {
2959 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1, reg|0x1000);
2960 + spi_rf_write(ctl, RF_CHIP2, 0x1005);
2961 + agnx_write32(ctl, AGNX_GCR_RXOVERIDE, 0x824);
2962 + } else if (chain == 1) {
2963 + spi_rf_write(ctl, RF_CHIP0, reg|0x1000);
2964 + spi_rf_write(ctl, RF_CHIP1|RF_CHIP2, 0x1004);
2965 + agnx_write32(ctl, AGNX_GCR_RXOVERIDE, 0xc36);
2969 + spi_rc_write(ctl, RF_CHIP0, 0x22);
2970 + reg = agnx_read32(ctl, AGNX_SPI_RLSW);
2974 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1005);
2977 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1, 0x1201);
2980 + if (chain == 6 || chain == 4) {
2981 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1, 0x1202);
2982 + spi_rf_write(ctl, RF_CHIP2, 0x1005);
2983 + } else if (chain < 3) {
2984 + spi_rf_write(ctl, RF_CHIP0, 0x1202);
2985 + spi_rf_write(ctl, RF_CHIP1|RF_CHIP2, 0x1005);
2990 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1, 0x1203);
2991 + spi_rf_write(ctl, RF_CHIP2, 0x1201);
2992 + } else if (chain == 2) {
2993 + spi_rf_write(ctl, RF_CHIP0, 0x1203);
2994 + spi_rf_write(ctl, RF_CHIP2, 0x1200);
2995 + spi_rf_write(ctl, RF_CHIP1, 0x1201);
2996 + } else if (chain == 1) {
2997 + spi_rf_write(ctl, RF_CHIP0, 0x1203);
2998 + spi_rf_write(ctl, RF_CHIP1|RF_CHIP2, 0x1200);
2999 + } else if (chain == 4) {
3000 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1, 0x1203);
3001 + spi_rf_write(ctl, RF_CHIP2, 0x1201);
3003 + spi_rf_write(ctl, RF_CHIP0, 0x1203);
3004 + spi_rf_write(ctl, RF_CHIP1|RF_CHIP2, 0x1201);
3007 +} /* chain_update */
3009 +static void antenna_config(struct agnx_priv *priv)
3011 + void __iomem *ctl = priv->ctl;
3015 + /* Write 0x0 to the TX Management Control Register Enable bit */
3016 + reg = agnx_read32(ctl, AGNX_TXM_CTL);
3018 + agnx_write32(ctl, AGNX_TXM_CTL, reg);
3021 + /* Set initial value based on number of Antennae */
3022 + antenna_init(priv, 3);
3024 + /* FIXME Update Power Templates for current valid Stations */
3025 + /* sta_power_init(priv, 0);*/
3027 + /* FIXME the number of chains should get from eeprom*/
3028 + chain_update(priv, AGNX_CHAINS_MAX);
3029 +} /* antenna_config */
3031 +void calibrate_oscillator(struct agnx_priv *priv)
3033 + void __iomem *ctl = priv->ctl;
3037 + spi_rc_write(ctl, RF_CHIP0|RF_CHIP1, 0x1201);
3038 + reg = agnx_read32(ctl, AGNX_GCR_GAINSET1);
3040 + agnx_write32(ctl, AGNX_GCR_GAINSET1, reg);
3042 + agnx_write32(ctl, AGNX_GCR_GAINSETWRITE, 1);
3043 + agnx_write32(ctl, AGNX_GCR_RSTGCTL, 1);
3045 + agnx_write32(ctl, AGNX_ACI_LEN, 0x3ff);
3047 + agnx_write32(ctl, AGNX_ACI_TIMER1, 0x27);
3048 + agnx_write32(ctl, AGNX_ACI_TIMER2, 0x27);
3049 + /* (Residual DC Calibration) to Calibration Mode */
3050 + agnx_write32(ctl, AGNX_ACI_MODE, 0x2);
3052 + spi_rc_write(ctl, RF_CHIP0|RF_CHIP1, 0x1004);
3053 + agnx_write32(ctl, AGNX_ACI_LEN, 0x3ff);
3054 + /* (TX LO Calibration) to Calibration Mode */
3055 + agnx_write32(ctl, AGNX_ACI_MODE, 0x4);
3058 + u32 reg1, reg2, reg3;
3059 + /* Enable Power Saving Control */
3060 + enable_power_saving(priv);
3061 + /* Save the following registers to restore */
3062 + reg1 = ioread32(ctl + 0x11000);
3063 + reg2 = ioread32(ctl + 0xec50);
3064 + reg3 = ioread32(ctl + 0xec54);
3067 + agnx_write32(ctl, 0x11000, 0xcfdf);
3068 + agnx_write32(ctl, 0xec50, 0x70);
3069 + /* Restore the registers */
3070 + agnx_write32(ctl, 0x11000, reg1);
3071 + agnx_write32(ctl, 0xec50, reg2);
3072 + agnx_write32(ctl, 0xec54, reg3);
3073 + /* Disable Power Saving Control */
3074 + disable_power_saving(priv);
3077 + agnx_write32(ctl, AGNX_GCR_RSTGCTL, 0);
3078 +} /* calibrate_oscillator */
3081 +static void radio_channel_set(struct agnx_priv *priv, unsigned int channel)
3083 + void __iomem *ctl = priv->ctl;
3084 + unsigned int freq = priv->band.channels[channel - 1].center_freq;
3088 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1, 0x1201);
3089 + /* Set SPI Clock to 50 Ns */
3090 + reg = agnx_read32(ctl, AGNX_SPI_CFG);
3093 + agnx_write32(ctl, AGNX_SPI_CFG, reg);
3095 + /* Clear the Disable Tx interrupt bit in Interrupt Mask */
3096 +/* reg = agnx_read32(ctl, AGNX_INT_MASK); */
3097 +/* reg &= ~IRQ_TX_DISABLE; */
3098 +/* agnx_write32(ctl, AGNX_INT_MASK, reg); */
3100 + /* Band Selection */
3101 + reg = agnx_read32(ctl, AGNX_SYSITF_GPIOUT);
3103 + agnx_write32(ctl, AGNX_SYSITF_GPIOUT, reg);
3105 + /* FIXME Set the SiLabs Chip Frequency */
3106 + synth_freq_set(priv, channel);
3108 + reg = agnx_read32(ctl, AGNX_PM_SOFTRST);
3109 + reg |= 0x80100030;
3110 + agnx_write32(ctl, AGNX_PM_SOFTRST, reg);
3111 + reg = agnx_read32(ctl, AGNX_PM_PLLCTL);
3113 + agnx_write32(ctl, AGNX_PM_PLLCTL, reg);
3115 + agnx_write32(ctl, AGNX_SYSITF_GPIOUT, 0x5);
3117 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1100);
3119 + /* Load the MonitorGain Table */
3120 + monitor_gain_table_init(priv);
3122 + /* Load the TX Fir table */
3123 + tx_fir_table_init(priv);
3125 + reg = agnx_read32(ctl, AGNX_PM_PMCTL);
3127 + agnx_write32(ctl, AGNX_PM_PMCTL, reg);
3129 + spi_rc_write(ctl, RF_CHIP0|RF_CHIP1, 0x22);
3131 + reg = agnx_read32(ctl, AGNX_SPI_RLSW);
3134 + agnx_write32(ctl, AGNX_GCR_RXOVERIDE, 0xff);
3135 + agnx_write32(ctl, AGNX_GCR_DISCOVMOD, 0x3);
3137 + reg = agnx_read32(ctl, 0xec50);
3139 + agnx_write32(ctl, 0xec50, reg);
3141 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1, 0x1201);
3142 + agnx_write32(ctl, 0x11008, 0x1);
3143 + agnx_write32(ctl, 0x1100c, 0x0);
3144 + agnx_write32(ctl, 0x11008, 0x0);
3145 + agnx_write32(ctl, 0xec50, 0xc);
3147 + agnx_write32(ctl, AGNX_GCR_DISCOVMOD, 0x3);
3148 + agnx_write32(ctl, AGNX_GCR_RXOVERIDE, 0x0);
3149 + agnx_write32(ctl, 0x11010, 0x6e);
3150 + agnx_write32(ctl, 0x11014, 0x6c);
3152 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1, 0x1201);
3154 + /* Calibrate the Antenna */
3155 + /* antenna_calibrate(priv); */
3156 + /* Calibrate the TxLocalOscillator */
3157 + calibrate_oscillator(priv);
3159 + reg = agnx_read32(ctl, AGNX_PM_PMCTL);
3161 + agnx_write32(ctl, AGNX_PM_PMCTL, reg);
3162 + agnx_write32(ctl, AGNX_GCR_GAININIT, 0xa);
3163 + agnx_write32(ctl, AGNX_GCR_THCD, 0x0);
3165 + agnx_write32(ctl, 0x11018, 0xb);
3166 + agnx_write32(ctl, AGNX_GCR_DISCOVMOD, 0x0);
3168 + /* Write Frequency to Gain Control Channel */
3169 + agnx_write32(ctl, AGNX_GCR_RXCHANEL, freq);
3170 + /* Write 0x140000/Freq to 0x9c08 */
3171 + reg = 0x140000/freq;
3172 + agnx_write32(ctl, 0x9c08, reg);
3174 + reg = agnx_read32(ctl, AGNX_PM_SOFTRST);
3175 + reg &= ~0x80100030;
3176 + agnx_write32(ctl, AGNX_PM_SOFTRST, reg);
3178 + reg = agnx_read32(ctl, AGNX_PM_PLLCTL);
3181 + agnx_write32(ctl, AGNX_PM_PLLCTL, reg);
3183 + agnx_write32(ctl, AGNX_ACI_MODE, 0x0);
3185 +/* FIXME According to Number of Chains: */
3188 +/* 1. Write 0x1203 to RF Chip 0 */
3189 +/* 2. Write 0x1200 to RF Chips 1 +2 */
3191 +/* 1. Write 0x1203 to RF Chip 0 */
3192 +/* 2. Write 0x1200 to RF Chip 2 */
3193 +/* 3. Write 0x1201 to RF Chip 1 */
3195 +/* 1. Write 0x1203 to RF Chip 0 */
3196 +/* 2. Write 0x1201 to RF Chip 1 + 2 */
3198 +/* 1. Write 0x1203 to RF Chip 0 + 1 */
3199 +/* 2. Write 0x1200 to RF Chip 2 */
3202 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1, 0x1203);
3203 + spi_rf_write(ctl, RF_CHIP2, 0x1201);
3205 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1000);
3206 + agnx_write32(ctl, AGNX_GCR_RXOVERIDE, 0x0);
3208 + /* FIXME Set the Disable Tx interrupt bit in Interrupt Mask
3209 + (Or 0x20000 to Interrupt Mask) */
3210 +/* reg = agnx_read32(ctl, AGNX_INT_MASK); */
3211 +/* reg |= IRQ_TX_DISABLE; */
3212 +/* agnx_write32(ctl, AGNX_INT_MASK, reg); */
3214 + agnx_write32(ctl, AGNX_GCR_RSTGCTL, 0x1);
3215 + agnx_write32(ctl, AGNX_GCR_RSTGCTL, 0x0);
3217 + /* Configure the Antenna */
3218 + antenna_config(priv);
3220 + /* Write 0x0 to Discovery Mode Enable detect G, B, A packet? */
3221 + agnx_write32(ctl, AGNX_GCR_DISCOVMOD, 0);
3223 + reg = agnx_read32(ctl, AGNX_RXM_REQRATE);
3224 + reg |= 0x80000000;
3225 + agnx_write32(ctl, AGNX_RXM_REQRATE, reg);
3226 + agnx_write32(ctl, AGNX_GCR_RSTGCTL, 0x1);
3227 + agnx_write32(ctl, AGNX_GCR_RSTGCTL, 0x0);
3229 + /* enable radio on and the power LED */
3230 + reg = agnx_read32(ctl, AGNX_SYSITF_GPIOUT);
3233 + agnx_write32(ctl, AGNX_SYSITF_GPIOUT, reg);
3235 + reg = agnx_read32(ctl, AGNX_TXM_CTL);
3237 + agnx_write32(ctl, AGNX_TXM_CTL, reg);
3238 +} /* radio_channel_set */
3240 +static void base_band_filter_calibrate(struct agnx_priv *priv)
3242 + void __iomem *ctl = priv->ctl;
3244 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1700);
3245 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1001);
3246 + agnx_write32(ctl, AGNX_GCR_FORCECTLCLK, 0x0);
3247 + spi_rc_write(ctl, RF_CHIP0, 0x27);
3248 + spi_rc_write(ctl, RF_CHIP1, 0x27);
3249 + spi_rc_write(ctl, RF_CHIP2, 0x27);
3250 + agnx_write32(ctl, AGNX_GCR_FORCECTLCLK, 0x1);
3253 +static void print_offset(struct agnx_priv *priv, u32 chain)
3255 + void __iomem *ctl = priv->ctl;
3258 + iowrite32((chain), ctl + AGNX_ACI_SELCHAIN);
3260 + offset = (ioread32(ctl + AGNX_ACI_OFFSET));
3261 + printk(PFX "Chain is 0x%x, Offset is 0x%x\n", chain, offset);
3264 +void print_offsets(struct agnx_priv *priv)
3266 + print_offset(priv, 0);
3267 + print_offset(priv, 4);
3268 + print_offset(priv, 1);
3269 + print_offset(priv, 5);
3270 + print_offset(priv, 2);
3271 + print_offset(priv, 6);
3276 + u32 cali; /* calibrate value*/
3278 +#define NEED_CALIBRATE 0
3279 +#define SUCCESS_CALIBRATE 1
3283 +static void chain_calibrate(struct agnx_priv *priv, struct chains *chains,
3286 + void __iomem *ctl = priv->ctl;
3287 + u32 calibra = chains[num].cali;
3290 + calibra |= 0x1400;
3292 + calibra |= 0x1500;
3297 + spi_rf_write(ctl, RF_CHIP0, calibra);
3301 + spi_rf_write(ctl, RF_CHIP1, calibra);
3305 + spi_rf_write(ctl, RF_CHIP2, calibra);
3310 +} /* chain_calibrate */
3313 +static void inline get_calibrete_value(struct agnx_priv *priv, struct chains *chains,
3316 + void __iomem *ctl = priv->ctl;
3319 + iowrite32((num), ctl + AGNX_ACI_SELCHAIN);
3322 + offset = (ioread32(ctl + AGNX_ACI_OFFSET));
3324 + if (offset < 0xf) {
3325 + chains[num].status = SUCCESS_CALIBRATE;
3329 + if (num == 0 || num == 1 || num == 2) {
3330 + if ( 0 == chains[num].cali)
3331 + chains[num].cali = 0xff;
3333 + chains[num].cali--;
3335 + chains[num].cali++;
3337 + chains[num].status = NEED_CALIBRATE;
3340 +static inline void calibra_delay(struct agnx_priv *priv)
3342 + void __iomem *ctl = priv->ctl;
3344 + unsigned int i = 100;
3348 + reg = (ioread32(ctl + AGNX_ACI_STATUS));
3349 + if (reg == 0x4000)
3354 + printk(PFX "calibration failed\n");
3357 +void do_calibration(struct agnx_priv *priv)
3359 + void __iomem *ctl = priv->ctl;
3360 + struct chains chains[7];
3361 + unsigned int i, j;
3364 + for (i = 0; i < 7; i++) {
3368 + chains[i].cali = 0x7f;
3369 + chains[i].status = NEED_CALIBRATE;
3372 + /* FIXME 0x300 is a magic number */
3373 + for (j = 0; j < 0x300; j++) {
3374 + if (chains[0].status == SUCCESS_CALIBRATE &&
3375 + chains[1].status == SUCCESS_CALIBRATE &&
3376 + chains[2].status == SUCCESS_CALIBRATE &&
3377 + chains[4].status == SUCCESS_CALIBRATE &&
3378 + chains[5].status == SUCCESS_CALIBRATE &&
3379 + chains[6].status == SUCCESS_CALIBRATE)
3382 + /* Attention, there is no chain 3 */
3383 + for (i = 0; i < 7; i++) {
3386 + if (chains[i].status == NEED_CALIBRATE)
3387 + chain_calibrate(priv, chains, i);
3389 + /* Write 0x1 to Calibration Measure */
3390 + iowrite32((0x1), ctl + AGNX_ACI_MEASURE);
3391 + calibra_delay(priv);
3393 + for (i = 0; i < 7; i++) {
3397 + get_calibrete_value(priv, chains, i);
3400 + printk(PFX "Clibrate times is %d\n", j);
3401 + print_offsets(priv);
3402 +} /* do_calibration */
3404 +void antenna_calibrate(struct agnx_priv *priv)
3406 + void __iomem *ctl = priv->ctl;
3410 + agnx_write32(ctl, AGNX_GCR_NLISTANT, 0x3);
3411 + agnx_write32(ctl, AGNX_GCR_NMEASANT, 0x3);
3412 + agnx_write32(ctl, AGNX_GCR_NACTIANT, 0x3);
3413 + agnx_write32(ctl, AGNX_GCR_NCAPTANT, 0x3);
3415 + agnx_write32(ctl, AGNX_GCR_ANTCFG, 0x1f);
3416 + agnx_write32(ctl, AGNX_GCR_BOACT, 0x24);
3417 + agnx_write32(ctl, AGNX_GCR_BOINACT, 0x24);
3418 + agnx_write32(ctl, AGNX_GCR_BODYNA, 0x20);
3419 + agnx_write32(ctl, AGNX_GCR_THD0A, 0x64);
3420 + agnx_write32(ctl, AGNX_GCR_THD0AL, 0x64);
3421 + agnx_write32(ctl, AGNX_GCR_THD0B, 0x46);
3422 + agnx_write32(ctl, AGNX_GCR_THD0BTFEST, 0x3c);
3423 + agnx_write32(ctl, AGNX_GCR_SIGHTH, 0x64);
3424 + agnx_write32(ctl, AGNX_GCR_SIGLTH, 0x30);
3426 + spi_rc_write(ctl, RF_CHIP0, 0x20);
3429 + /* 1. Should read 0x0 */
3430 + reg = agnx_read32(ctl, AGNX_SPI_RLSW);
3432 + printk(KERN_WARNING PFX "Unmatched rf chips result\n");
3433 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1000);
3435 + agnx_write32(ctl, AGNX_GCR_RXOVERIDE, 0x0);
3437 + spi_rc_write(ctl, RF_CHIP0, 0x22);
3439 + reg = agnx_read32(ctl, AGNX_SPI_RLSW);
3441 + printk(KERN_WARNING PFX "Unmatched rf chips result\n");
3442 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1005);
3444 + agnx_write32(ctl, AGNX_GCR_RSTGCTL, 0x1);
3445 + agnx_write32(ctl, AGNX_GCR_RSTGCTL, 0x0);
3447 + reg = agnx_read32(ctl, AGNX_PM_SOFTRST);
3448 + reg |= 0x1c000032;
3449 + agnx_write32(ctl, AGNX_PM_SOFTRST, reg);
3450 + reg = agnx_read32(ctl, AGNX_PM_PLLCTL);
3452 + agnx_write32(ctl, AGNX_PM_PLLCTL, reg);
3454 + reg = agnx_read32(ctl, 0xec50);
3456 + agnx_write32(ctl, 0xec50, reg);
3458 + agnx_write32(ctl, AGNX_GCR_RXOVERIDE, 0xff8);
3459 + agnx_write32(ctl, AGNX_GCR_DISCOVMOD, 0x3);
3461 + agnx_write32(ctl, AGNX_GCR_CHAINNUM, 0x6);
3462 + agnx_write32(ctl, 0x19874, 0x0);
3463 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1700);
3465 + /* Calibrate the BaseBandFilter */
3466 + base_band_filter_calibrate(priv);
3468 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1002);
3470 + agnx_write32(ctl, AGNX_GCR_GAINSET0, 0x1d);
3471 + agnx_write32(ctl, AGNX_GCR_GAINSET1, 0x1d);
3472 + agnx_write32(ctl, AGNX_GCR_GAINSET2, 0x1d);
3473 + agnx_write32(ctl, AGNX_GCR_GAINSETWRITE, 0x1);
3475 + agnx_write32(ctl, AGNX_ACI_MODE, 0x1);
3476 + agnx_write32(ctl, AGNX_ACI_LEN, 0x3ff);
3478 + agnx_write32(ctl, AGNX_ACI_TIMER1, 0x27);
3479 + agnx_write32(ctl, AGNX_ACI_TIMER2, 0x27);
3481 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1400);
3482 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1500);
3484 + /* Measure Calibration */
3485 + agnx_write32(ctl, AGNX_ACI_MEASURE, 0x1);
3486 + calibra_delay(priv);
3488 + /* do calibration */
3489 + do_calibration(priv);
3491 + agnx_write32(ctl, AGNX_GCR_RXOVERIDE, 0x0);
3492 + agnx_write32(ctl, AGNX_ACI_TIMER1, 0x21);
3493 + agnx_write32(ctl, AGNX_ACI_TIMER2, 0x27);
3494 + agnx_write32(ctl, AGNX_ACI_LEN, 0xf);
3496 + reg = agnx_read32(ctl, AGNX_GCR_GAINSET0);
3498 + agnx_write32(ctl, AGNX_GCR_GAINSET0, reg);
3499 + reg = agnx_read32(ctl, AGNX_GCR_GAINSET1);
3501 + agnx_write32(ctl, AGNX_GCR_GAINSET1, reg);
3502 + reg = agnx_read32(ctl, AGNX_GCR_GAINSET2);
3504 + agnx_write32(ctl, AGNX_GCR_GAINSET2, reg);
3506 + agnx_write32(ctl, AGNX_GCR_GAINSETWRITE, 0x0);
3507 + disable_receiver(priv);
3508 +} /* antenna_calibrate */
3510 +void __antenna_calibrate(struct agnx_priv *priv)
3512 + void __iomem *ctl = priv->ctl;
3515 + /* Calibrate the BaseBandFilter */
3516 + /* base_band_filter_calibrate(priv); */
3517 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1002);
3520 + agnx_write32(ctl, AGNX_GCR_GAINSET0, 0x1d);
3521 + agnx_write32(ctl, AGNX_GCR_GAINSET1, 0x1d);
3522 + agnx_write32(ctl, AGNX_GCR_GAINSET2, 0x1d);
3524 + agnx_write32(ctl, AGNX_GCR_GAINSETWRITE, 0x1);
3526 + agnx_write32(ctl, AGNX_ACI_MODE, 0x1);
3527 + agnx_write32(ctl, AGNX_ACI_LEN, 0x3ff);
3530 + agnx_write32(ctl, AGNX_ACI_TIMER1, 0x27);
3531 + agnx_write32(ctl, AGNX_ACI_TIMER2, 0x27);
3532 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1400);
3533 + spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1500);
3534 + /* Measure Calibration */
3535 + agnx_write32(ctl, AGNX_ACI_MEASURE, 0x1);
3536 + calibra_delay(priv);
3537 + do_calibration(priv);
3538 + agnx_write32(ctl, AGNX_GCR_RXOVERIDE, 0x0);
3540 + agnx_write32(ctl, AGNX_ACI_TIMER1, 0x21);
3541 + agnx_write32(ctl, AGNX_ACI_TIMER2, 0x27);
3543 + agnx_write32(ctl, AGNX_ACI_LEN, 0xf);
3545 + reg = agnx_read32(ctl, AGNX_GCR_GAINSET0);
3547 + agnx_write32(ctl, AGNX_GCR_GAINSET0, reg);
3548 + reg = agnx_read32(ctl, AGNX_GCR_GAINSET1);
3550 + agnx_write32(ctl, AGNX_GCR_GAINSET1, reg);
3551 + reg = agnx_read32(ctl, AGNX_GCR_GAINSET2);
3553 + agnx_write32(ctl, AGNX_GCR_GAINSET2, reg);
3556 + agnx_write32(ctl, AGNX_GCR_GAINSETWRITE, 0x0);
3558 + /* Write 0x3 Gain Control Discovery Mode */
3559 + enable_receiver(priv);
3562 +int agnx_set_channel(struct agnx_priv *priv, unsigned int channel)
3566 + printk(KERN_ERR PFX "Channel is %d %s\n", channel, __func__);
3567 + radio_channel_set(priv, channel);
3571 +++ b/drivers/staging/agnx/sta.c
3573 +#include <linux/delay.h>
3574 +#include <linux/etherdevice.h>
3579 +void hash_read(struct agnx_priv *priv, u32 reghi, u32 reglo, u8 sta_id)
3581 + void __iomem *ctl = priv->ctl;
3584 + reglo |= 0x30000000;
3585 + reglo |= 0x40000000; /* Set status busy */
3586 + reglo |= sta_id << 16;
3588 + iowrite32(0, ctl + AGNX_RXM_HASH_CMD_FLAG);
3589 + iowrite32(reghi, ctl + AGNX_RXM_HASH_CMD_HIGH);
3590 + iowrite32(reglo, ctl + AGNX_RXM_HASH_CMD_LOW);
3592 + reghi = ioread32(ctl + AGNX_RXM_HASH_CMD_HIGH);
3593 + reglo = ioread32(ctl + AGNX_RXM_HASH_CMD_LOW);
3594 + printk(PFX "RX hash cmd are : %.8x%.8x\n", reghi, reglo);
3597 +void hash_write(struct agnx_priv *priv, u8 *mac_addr, u8 sta_id)
3599 + void __iomem *ctl = priv->ctl;
3602 + if (!is_valid_ether_addr(mac_addr))
3603 + printk(KERN_WARNING PFX "Update hash table: Invalid hwaddr!\n");
3605 + reghi = mac_addr[0] << 24 | mac_addr[1] << 16 | mac_addr[2] << 8 | mac_addr[3];
3606 + reglo = mac_addr[4] << 8 | mac_addr[5];
3607 + reglo |= 0x10000000; /* Set hash commmand */
3608 + reglo |= 0x40000000; /* Set status busy */
3609 + reglo |= sta_id << 16;
3611 + iowrite32(0, ctl + AGNX_RXM_HASH_CMD_FLAG);
3612 + iowrite32(reghi, ctl + AGNX_RXM_HASH_CMD_HIGH);
3613 + iowrite32(reglo, ctl + AGNX_RXM_HASH_CMD_LOW);
3615 + reglo = ioread32(ctl + AGNX_RXM_HASH_CMD_LOW);
3616 + if (!(reglo & 0x80000000))
3617 + printk(KERN_WARNING PFX "Update hash table failed\n");
3620 +void hash_delete(struct agnx_priv *priv, u32 reghi, u32 reglo, u8 sta_id)
3622 + void __iomem *ctl = priv->ctl;
3625 + reglo |= 0x20000000;
3626 + reglo |= 0x40000000; /* Set status busy */
3627 + reglo |= sta_id << 16;
3629 + iowrite32(0, ctl + AGNX_RXM_HASH_CMD_FLAG);
3630 + iowrite32(reghi, ctl + AGNX_RXM_HASH_CMD_HIGH);
3631 + iowrite32(reglo, ctl + AGNX_RXM_HASH_CMD_LOW);
3632 + reghi = ioread32(ctl + AGNX_RXM_HASH_CMD_HIGH);
3634 + reglo = ioread32(ctl + AGNX_RXM_HASH_CMD_LOW);
3635 + printk(PFX "RX hash cmd are : %.8x%.8x\n", reghi, reglo);
3639 +void hash_dump(struct agnx_priv *priv, u8 sta_id)
3641 + void __iomem *ctl = priv->ctl;
3644 + reglo = 0x0; /* dump command */
3645 + reglo|= 0x40000000; /* status bit */
3646 + iowrite32(reglo, ctl + AGNX_RXM_HASH_CMD_LOW);
3647 + iowrite32(sta_id << 16, ctl + AGNX_RXM_HASH_DUMP_DATA);
3651 + reghi = ioread32(ctl + AGNX_RXM_HASH_CMD_HIGH);
3652 + reglo = ioread32(ctl + AGNX_RXM_HASH_CMD_LOW);
3653 + printk(PFX "hash cmd are : %.8x%.8x\n", reghi, reglo);
3654 + reghi = ioread32(ctl + AGNX_RXM_HASH_CMD_FLAG);
3655 + printk(PFX "hash flag is : %.8x\n", reghi);
3656 + reghi = ioread32(ctl + AGNX_RXM_HASH_DUMP_MST);
3657 + reglo = ioread32(ctl + AGNX_RXM_HASH_DUMP_LST);
3658 + printk(PFX "hash dump mst lst: %.8x%.8x\n", reghi, reglo);
3659 + reghi = ioread32(ctl + AGNX_RXM_HASH_DUMP_DATA);
3660 + printk(PFX "hash dump data: %.8x\n", reghi);
3663 +void get_sta_power(struct agnx_priv *priv, struct agnx_sta_power *power, unsigned int sta_idx)
3665 + void __iomem *ctl = priv->ctl;
3666 + memcpy_fromio(power, ctl + AGNX_TXM_STAPOWTEMP + sizeof(*power) * sta_idx,
3671 +set_sta_power(struct agnx_priv *priv, struct agnx_sta_power *power, unsigned int sta_idx)
3673 + void __iomem *ctl = priv->ctl;
3674 + /* FIXME 2. Write Template to offset + station number */
3675 + memcpy_toio(ctl + AGNX_TXM_STAPOWTEMP + sizeof(*power) * sta_idx,
3676 + power, sizeof(*power));
3680 +void get_sta_tx_wq(struct agnx_priv *priv, struct agnx_sta_tx_wq *tx_wq,
3681 + unsigned int sta_idx, unsigned int wq_idx)
3683 + void __iomem *data = priv->data;
3684 + memcpy_fromio(tx_wq, data + AGNX_PDU_TX_WQ + sizeof(*tx_wq) * STA_TX_WQ_NUM * sta_idx +
3685 + sizeof(*tx_wq) * wq_idx, sizeof(*tx_wq));
3689 +inline void set_sta_tx_wq(struct agnx_priv *priv, struct agnx_sta_tx_wq *tx_wq,
3690 + unsigned int sta_idx, unsigned int wq_idx)
3692 + void __iomem *data = priv->data;
3693 + memcpy_toio(data + AGNX_PDU_TX_WQ + sizeof(*tx_wq) * STA_TX_WQ_NUM * sta_idx +
3694 + sizeof(*tx_wq) * wq_idx, tx_wq, sizeof(*tx_wq));
3698 +void get_sta(struct agnx_priv *priv, struct agnx_sta *sta, unsigned int sta_idx)
3700 + void __iomem *data = priv->data;
3702 + memcpy_fromio(sta, data + AGNX_PDUPOOL + sizeof(*sta) * sta_idx,
3706 +inline void set_sta(struct agnx_priv *priv, struct agnx_sta *sta, unsigned int sta_idx)
3708 + void __iomem *data = priv->data;
3710 + memcpy_toio(data + AGNX_PDUPOOL + sizeof(*sta) * sta_idx,
3711 + sta, sizeof(*sta));
3715 +void sta_power_init(struct agnx_priv *priv, unsigned int sta_idx)
3717 + struct agnx_sta_power power;
3721 + memset(&power, 0, sizeof(power));
3722 + reg = agnx_set_bits(EDCF, EDCF_SHIFT, 0x1);
3723 + power.reg = cpu_to_le32(reg);
3724 + set_sta_power(priv, &power, sta_idx);
3726 +} /* add_power_template */
3729 +/* @num: The #number of station that is visible to the card */
3730 +static void sta_tx_workqueue_init(struct agnx_priv *priv, unsigned int sta_idx)
3732 + struct agnx_sta_tx_wq tx_wq;
3736 + memset(&tx_wq, 0, sizeof(tx_wq));
3738 + reg = agnx_set_bits(WORK_QUEUE_VALID, WORK_QUEUE_VALID_SHIFT, 1);
3739 + reg |= agnx_set_bits(WORK_QUEUE_ACK_TYPE, WORK_QUEUE_ACK_TYPE_SHIFT, 1);
3740 +// reg |= agnx_set_bits(WORK_QUEUE_ACK_TYPE, WORK_QUEUE_ACK_TYPE_SHIFT, 0);
3741 + tx_wq.reg2 |= cpu_to_le32(reg);
3743 + /* Suppose all 8 traffic class are used */
3744 + for (i = 0; i < STA_TX_WQ_NUM; i++)
3745 + set_sta_tx_wq(priv, &tx_wq, sta_idx, i);
3746 +} /* sta_tx_workqueue_init */
3749 +static void sta_traffic_init(struct agnx_sta_traffic *traffic)
3752 + memset(traffic, 0, sizeof(*traffic));
3754 + reg = agnx_set_bits(NEW_PACKET, NEW_PACKET_SHIFT, 1);
3755 + reg |= agnx_set_bits(TRAFFIC_VALID, TRAFFIC_VALID_SHIFT, 1);
3756 +// reg |= agnx_set_bits(TRAFFIC_ACK_TYPE, TRAFFIC_ACK_TYPE_SHIFT, 1);
3757 + traffic->reg0 = cpu_to_le32(reg);
3759 + /* 3. setting RX Sequence Number to 4095 */
3760 + reg = agnx_set_bits(RX_SEQUENCE_NUM, RX_SEQUENCE_NUM_SHIFT, 4095);
3761 + traffic->reg1 = cpu_to_le32(reg);
3765 +/* @num: The #number of station that is visible to the card */
3766 +void sta_init(struct agnx_priv *priv, unsigned int sta_idx)
3768 + /* FIXME the length of sta is 256 bytes Is that
3769 + * dangerous to stack overflow? */
3770 + struct agnx_sta sta;
3774 + memset(&sta, 0, sizeof(sta));
3775 + /* Set valid to 1 */
3776 + reg = agnx_set_bits(STATION_VALID, STATION_VALID_SHIFT, 1);
3777 + /* Set Enable Concatenation to 0 (?) */
3778 + reg |= agnx_set_bits(ENABLE_CONCATENATION, ENABLE_CONCATENATION_SHIFT, 0);
3779 + /* Set Enable Decompression to 0 (?) */
3780 + reg |= agnx_set_bits(ENABLE_DECOMPRESSION, ENABLE_DECOMPRESSION_SHIFT, 0);
3781 + sta.reg = cpu_to_le32(reg);
3783 + /* Initialize each of the Traffic Class Structures by: */
3784 + for (i = 0; i < 8; i++)
3785 + sta_traffic_init(sta.traffic + i);
3787 + set_sta(priv, &sta, sta_idx);
3788 + sta_tx_workqueue_init(priv, sta_idx);
3789 +} /* sta_descriptor_init */
3793 +++ b/drivers/staging/agnx/sta.h
3795 +#ifndef AGNX_STA_H_
3796 +#define AGNX_STA_H_
3798 +#define STA_TX_WQ_NUM 8 /* The number of TX workqueue one STA has */
3800 +struct agnx_hash_cmd {
3802 +#define MACLO 0xFFFF0000
3803 +#define MACLO_SHIFT 16
3804 +#define STA_ID 0x0000FFF0
3805 +#define STA_ID_SHIFT 4
3806 +#define CMD 0x0000000C
3807 +#define CMD_SHIFT 2
3808 +#define STATUS 0x00000002
3809 +#define STATUS_SHIFT 1
3810 +#define PASS 0x00000001
3811 +#define PASS_SHIFT 1
3813 +}__attribute__((__packed__));
3817 + * Station Power Template
3818 + * FIXME Just for agn100 yet
3820 +struct agnx_sta_power {
3822 +#define SIGNAL 0x000000FF /* signal */
3823 +#define SIGNAL_SHIFT 0
3824 +#define RATE 0x00000F00
3825 +#define RATE_SHIFT 8
3826 +#define TIFS 0x00001000
3827 +#define TIFS_SHIFT 12
3828 +#define EDCF 0x00002000
3829 +#define EDCF_SHIFT 13
3830 +#define CHANNEL_BOND 0x00004000
3831 +#define CHANNEL_BOND_SHIFT 14
3832 +#define PHY_MODE 0x00038000
3833 +#define PHY_MODE_SHIFT 15
3834 +#define POWER_LEVEL 0x007C0000
3835 +#define POWER_LEVEL_SHIFT 18
3836 +#define NUM_TRANSMITTERS 0x00800000
3837 +#define NUM_TRANSMITTERS_SHIFT 23
3838 +} __attribute__((__packed__));
3841 + * TX Workqueue Descriptor
3843 +struct agnx_sta_tx_wq {
3845 +#define HEAD_POINTER_LOW 0xFF000000 /* Head pointer low */
3846 +#define HEAD_POINTER_LOW_SHIFT 24
3847 +#define TAIL_POINTER 0x00FFFFFF /* Tail pointer */
3848 +#define TAIL_POINTER_SHIFT 0
3851 +#define ACK_POINTER_LOW 0xFFFF0000 /* ACK pointer low */
3852 +#define ACK_POINTER_LOW_SHIFT 16
3853 +#define HEAD_POINTER_HIGH 0x0000FFFF /* Head pointer high */
3854 +#define HEAD_POINTER_HIGH_SHIFT 0
3857 +/* ACK timeout tail packet count */
3858 +#define ACK_TIMOUT_TAIL_PACK_CNT 0xFFF00000
3859 +#define ACK_TIMOUT_TAIL_PACK_CNT_SHIFT 20
3860 +/* Head timeout tail packet count */
3861 +#define HEAD_TIMOUT_TAIL_PACK_CNT 0x000FFF00
3862 +#define HEAD_TIMOUT_TAIL_PACK_CNT_SHIFT 8
3863 +#define ACK_POINTER_HIGH 0x000000FF /* ACK pointer high */
3864 +#define ACK_POINTER_HIGH_SHIFT 0
3867 +#define WORK_QUEUE_VALID 0x80000000 /* valid */
3868 +#define WORK_QUEUE_VALID_SHIFT 31
3869 +#define WORK_QUEUE_ACK_TYPE 0x40000000 /* ACK type */
3870 +#define WORK_QUEUE_ACK_TYPE_SHIFT 30
3871 +/* Head timeout window limit fragmentation count */
3872 +#define HEAD_TIMOUT_WIN_LIM_FRAG_CNT 0x3FFF0000
3873 +#define HEAD_TIMOUT_WIN_LIM_FRAG_CNT_SHIFT 16
3874 +/* Head timeout window limit byte count */
3875 +#define HEAD_TIMOUT_WIN_LIM_BYTE_CNT 0x0000FFFF
3876 +#define HEAD_TIMOUT_WIN_LIM_BYTE_CNT_SHIFT 0
3877 +} __attribute__((__packed__));
3881 + * Traffic Class Structure
3883 +struct agnx_sta_traffic {
3885 +#define ACK_TIMOUT_CNT 0xFF800000 /* ACK Timeout Counts */
3886 +#define ACK_TIMOUT_CNT_SHIFT 23
3887 +#define TRAFFIC_ACK_TYPE 0x00600000 /* ACK Type */
3888 +#define TRAFFIC_ACK_TYPE_SHIFT 21
3889 +#define NEW_PACKET 0x00100000 /* New Packet */
3890 +#define NEW_PACKET_SHIFT 20
3891 +#define TRAFFIC_VALID 0x00080000 /* Valid */
3892 +#define TRAFFIC_VALID_SHIFT 19
3893 +#define RX_HDR_DESC_POINTER 0x0007FFFF /* RX Header Descripter pointer */
3894 +#define RX_HDR_DESC_POINTER_SHIFT 0
3897 +#define RX_PACKET_TIMESTAMP 0xFFFF0000 /* RX Packet Timestamp */
3898 +#define RX_PACKET_TIMESTAMP_SHIFT 16
3899 +#define TRAFFIC_RESERVED 0x0000E000 /* Reserved */
3900 +#define TRAFFIC_RESERVED_SHIFT 13
3901 +#define SV 0x00001000 /* sv */
3902 +#define SV_SHIFT 12
3903 +#define RX_SEQUENCE_NUM 0x00000FFF /* RX Sequence Number */
3904 +#define RX_SEQUENCE_NUM_SHIFT 0
3906 + __le32 tx_replay_cnt_low; /* TX Replay Counter Low */
3908 + __le16 tx_replay_cnt_high; /* TX Replay Counter High */
3909 + __le16 rx_replay_cnt_high; /* RX Replay Counter High */
3911 + __be32 rx_replay_cnt_low; /* RX Replay Counter Low */
3912 +} __attribute__((__packed__));
3915 + * Station Descriptors
3918 + __le32 tx_session_keys[4]; /* Transmit Session Key (0-3) */
3919 + __le32 rx_session_keys[4]; /* Receive Session Key (0-3) */
3922 +#define ID_1 0xC0000000 /* id 1 */
3923 +#define ID_1_SHIFT 30
3924 +#define ID_0 0x30000000 /* id 0 */
3925 +#define ID_0_SHIFT 28
3926 +#define ENABLE_CONCATENATION 0x0FF00000 /* Enable concatenation */
3927 +#define ENABLE_CONCATENATION_SHIFT 20
3928 +#define ENABLE_DECOMPRESSION 0x000FF000 /* Enable decompression */
3929 +#define ENABLE_DECOMPRESSION_SHIFT 12
3930 +#define STA_RESERVED 0x00000C00 /* Reserved */
3931 +#define STA_RESERVED_SHIFT 10
3932 +#define EAP 0x00000200 /* EAP */
3933 +#define EAP_SHIFT 9
3934 +#define ED_NULL 0x00000100 /* ED NULL */
3935 +#define ED_NULL_SHIFT 8
3936 +#define ENCRYPTION_POLICY 0x000000E0 /* Encryption Policy */
3937 +#define ENCRYPTION_POLICY_SHIFT 5
3938 +#define DEFINED_KEY_ID 0x00000018 /* Defined Key ID */
3939 +#define DEFINED_KEY_ID_SHIFT 3
3940 +#define FIXED_KEY 0x00000004 /* Fixed Key */
3941 +#define FIXED_KEY_SHIFT 2
3942 +#define KEY_VALID 0x00000002 /* Key Valid */
3943 +#define KEY_VALID_SHIFT 1
3944 +#define STATION_VALID 0x00000001 /* Station Valid */
3945 +#define STATION_VALID_SHIFT 0
3947 + __le32 tx_aes_blks_unicast; /* TX AES Blks Unicast */
3948 + __le32 rx_aes_blks_unicast; /* RX AES Blks Unicast */
3950 + __le16 aes_format_err_unicast_cnt; /* AES Format Error Unicast Counts */
3951 + __le16 aes_replay_unicast; /* AES Replay Unicast */
3953 + __le16 aes_decrypt_err_unicast; /* AES Decrypt Error Unicast */
3954 + __le16 aes_decrypt_err_default; /* AES Decrypt Error default */
3956 + __le16 single_retry_packets; /* Single Retry Packets */
3957 + __le16 failed_tx_packets; /* Failed Tx Packets */
3959 + __le16 muti_retry_packets; /* Multiple Retry Packets */
3960 + __le16 ack_timeouts; /* ACK Timeouts */
3962 + __le16 frag_tx_cnt; /* Fragment TX Counts */
3963 + __le16 rts_brq_sent; /* RTS Brq Sent */
3965 + __le16 tx_packets; /* TX Packets */
3966 + __le16 cts_back_timeout; /* CTS Back Timeout */
3968 + __le32 phy_stats_high; /* PHY Stats High */
3969 + __le32 phy_stats_low; /* PHY Stats Low */
3971 + struct agnx_sta_traffic traffic[8]; /* Traffic Class Structure (8) */
3973 + __le16 traffic_class0_frag_success; /* Traffic Class 0 Fragment Success */
3974 + __le16 traffic_class1_frag_success; /* Traffic Class 1 Fragment Success */
3975 + __le16 traffic_class2_frag_success; /* Traffic Class 2 Fragment Success */
3976 + __le16 traffic_class3_frag_success; /* Traffic Class 3 Fragment Success */
3977 + __le16 traffic_class4_frag_success; /* Traffic Class 4 Fragment Success */
3978 + __le16 traffic_class5_frag_success; /* Traffic Class 5 Fragment Success */
3979 + __le16 traffic_class6_frag_success; /* Traffic Class 6 Fragment Success */
3980 + __le16 traffic_class7_frag_success; /* Traffic Class 7 Fragment Success */
3982 + __le16 num_frag_non_prime_rates; /* number of Fragments for non-prime rates */
3983 + __le16 ack_timeout_non_prime_rates; /* ACK Timeout for non-prime rates */
3985 +} __attribute__((__packed__));
3988 +struct agnx_beacon_hdr {
3989 + struct agnx_sta_power power; /* Tx Station Power Template */
3990 + u8 phy_hdr[6]; /* PHY Hdr */
3991 + u8 frame_len_lo; /* Frame Length Lo */
3992 + u8 frame_len_hi; /* Frame Length Hi */
3993 + u8 mac_hdr[24]; /* MAC Header */
3995 + /* 802.11(abg) beacon */
3996 +} __attribute__((__packed__));
3998 +void hash_write(struct agnx_priv *priv, u8 *mac_addr, u8 sta_id);
3999 +void hash_dump(struct agnx_priv *priv, u8 sta_id);
4000 +void hash_read(struct agnx_priv *priv, u32 reghi, u32 reglo, u8 sta_id);
4001 +void hash_delete(struct agnx_priv *priv, u32 reghi, u32 reglo, u8 sta_id);
4003 +void get_sta_power(struct agnx_priv *priv, struct agnx_sta_power *power, unsigned int sta_idx);
4004 +void set_sta_power(struct agnx_priv *priv, struct agnx_sta_power *power,
4005 + unsigned int sta_idx);
4006 +void get_sta_tx_wq(struct agnx_priv *priv, struct agnx_sta_tx_wq *tx_wq,
4007 + unsigned int sta_idx, unsigned int wq_idx);
4008 +void set_sta_tx_wq(struct agnx_priv *priv, struct agnx_sta_tx_wq *tx_wq,
4009 + unsigned int sta_idx, unsigned int wq_idx);
4010 +void get_sta(struct agnx_priv *priv, struct agnx_sta *sta, unsigned int sta_idx);
4011 +void set_sta(struct agnx_priv *priv, struct agnx_sta *sta, unsigned int sta_idx);
4013 +void sta_power_init(struct agnx_priv *priv, unsigned int num);
4014 +void sta_init(struct agnx_priv *priv, unsigned int num);
4016 +#endif /* AGNX_STA_H_ */
4018 +++ b/drivers/staging/agnx/table.c
4020 +#include <linux/pci.h>
4021 +#include <linux/delay.h>
4027 +tx_fir_table[] = { 0x19, 0x5d, 0xce, 0x151, 0x1c3, 0x1ff, 0x1ea, 0x17c, 0xcf,
4028 + 0x19, 0x38e, 0x350, 0x362, 0x3ad, 0x5, 0x44, 0x59, 0x49,
4029 + 0x21, 0x3f7, 0x3e0, 0x3e3, 0x3f3, 0x0 };
4031 +void tx_fir_table_init(struct agnx_priv *priv)
4033 + void __iomem *ctl = priv->ctl;
4036 + for (i = 0; i < ARRAY_SIZE(tx_fir_table); i++)
4037 + iowrite32(tx_fir_table[i], ctl + AGNX_FIR_BASE + i*4);
4038 +} /* fir_table_setup */
4042 +gain_table[] = { 0x8, 0x8, 0xf, 0x13, 0x17, 0x1b, 0x1f, 0x23, 0x27, 0x2b,
4043 + 0x2f, 0x33, 0x37, 0x3b, 0x3f, 0x43, 0x47, 0x4b, 0x4f,
4044 + 0x53, 0x57, 0x5b, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f,
4045 + 0x5f, 0x5f, 0x5f, 0x5f };
4047 +void gain_table_init(struct agnx_priv *priv)
4049 + void __iomem *ctl = priv->ctl;
4052 + for (i = 0; i < ARRAY_SIZE(gain_table); i++) {
4053 + iowrite32(gain_table[i], ctl + AGNX_GAIN_TABLE + i*4);
4054 + iowrite32(gain_table[i], ctl + AGNX_GAIN_TABLE + i*4 + 0x80);
4056 +} /* gain_table_init */
4058 +void monitor_gain_table_init(struct agnx_priv *priv)
4060 + void __iomem *ctl = priv->ctl;
4063 + for (i = 0; i < 0x44; i += 4) {
4064 + iowrite32(0x61, ctl + AGNX_MONGCR_BASE + i);
4065 + iowrite32(0x61, ctl + AGNX_MONGCR_BASE + 0x200 + i);
4067 + for (i = 0x44; i < 0x64; i += 4) {
4068 + iowrite32(0x6e, ctl + AGNX_MONGCR_BASE + i);
4069 + iowrite32(0x6e, ctl + AGNX_MONGCR_BASE + 0x200 + i);
4071 + for (i = 0x64; i < 0x94; i += 4) {
4072 + iowrite32(0x7a, ctl + AGNX_MONGCR_BASE + i);
4073 + iowrite32(0x7a, ctl + AGNX_MONGCR_BASE + 0x200 + i);
4075 + for (i = 0x94; i < 0xdc; i += 4) {
4076 + iowrite32(0x87, ctl + AGNX_MONGCR_BASE + i);
4077 + iowrite32(0x87, ctl + AGNX_MONGCR_BASE + 0x200 + i);
4079 + for (i = 0xdc; i < 0x148; i += 4) {
4080 + iowrite32(0x95, ctl + AGNX_MONGCR_BASE + i);
4081 + iowrite32(0x95, ctl + AGNX_MONGCR_BASE + 0x200 + i);
4083 + for (i = 0x148; i < 0x1e8; i += 4) {
4084 + iowrite32(0xa2, ctl + AGNX_MONGCR_BASE + i);
4085 + iowrite32(0xa2, ctl + AGNX_MONGCR_BASE + 0x200 + i);
4087 + for (i = 0x1e8; i <= 0x1fc; i += 4) {
4088 + iowrite32(0xb0, ctl + AGNX_MONGCR_BASE + i);
4089 + iowrite32(0xb0, ctl + AGNX_MONGCR_BASE + 0x200 + i);
4091 +} /* monitor_gain_table_init */
4094 +void routing_table_init(struct agnx_priv *priv)
4096 + void __iomem *ctl = priv->ctl;
4097 + unsigned int type, subtype;
4100 + disable_receiver(priv);
4102 + for ( type = 0; type < 0x3; type++ ) {
4103 + for (subtype = 0; subtype < 0x10; subtype++) {
4104 + /* 1. Set Routing table to R/W and to Return status on Read */
4105 + reg = (type << ROUTAB_TYPE_SHIFT) |
4106 + (subtype << ROUTAB_SUBTYPE_SHIFT);
4107 + reg |= (1 << ROUTAB_RW_SHIFT) | (1 << ROUTAB_STATUS_SHIFT);
4108 + if (type == ROUTAB_TYPE_DATA) {
4109 + /* NULL goes to RFP */
4110 + if (subtype == ROUTAB_SUBTYPE_NULL)
4111 +// reg |= ROUTAB_ROUTE_RFP;
4112 + reg |= ROUTAB_ROUTE_CPU;
4113 + /* QOS NULL goes to CPU */
4114 + else if (subtype == ROUTAB_SUBTYPE_QOSNULL)
4115 + reg |= ROUTAB_ROUTE_CPU;
4116 + /* All Data and QOS data subtypes go to Encryption */
4117 + else if ((subtype == ROUTAB_SUBTYPE_DATA) ||
4118 + (subtype == ROUTAB_SUBTYPE_DATAACK) ||
4119 + (subtype == ROUTAB_SUBTYPE_DATAPOLL) ||
4120 + (subtype == ROUTAB_SUBTYPE_DATAPOLLACK) ||
4121 + (subtype == ROUTAB_SUBTYPE_QOSDATA) ||
4122 + (subtype == ROUTAB_SUBTYPE_QOSDATAACK) ||
4123 + (subtype == ROUTAB_SUBTYPE_QOSDATAPOLL) ||
4124 + (subtype == ROUTAB_SUBTYPE_QOSDATAACKPOLL))
4125 + reg |= ROUTAB_ROUTE_ENCRY;
4126 +// reg |= ROUTAB_ROUTE_CPU;
4127 + /*Drop NULL and QOS NULL ack, poll and poll ack*/
4128 + else if ((subtype == ROUTAB_SUBTYPE_NULLACK) ||
4129 + (subtype == ROUTAB_SUBTYPE_QOSNULLACK) ||
4130 + (subtype == ROUTAB_SUBTYPE_NULLPOLL) ||
4131 + (subtype == ROUTAB_SUBTYPE_QOSNULLPOLL) ||
4132 + (subtype == ROUTAB_SUBTYPE_NULLPOLLACK) ||
4133 + (subtype == ROUTAB_SUBTYPE_QOSNULLPOLLACK))
4134 +// reg |= ROUTAB_ROUTE_DROP;
4135 + reg |= ROUTAB_ROUTE_CPU;
4138 + reg |= (ROUTAB_ROUTE_CPU);
4139 + iowrite32(reg, ctl + AGNX_RXM_ROUTAB);
4140 + /* Check to verify that the status bit cleared */
4141 + routing_table_delay();
4144 + enable_receiver(priv);
4145 +} /* routing_table_init */
4147 +void tx_engine_lookup_tbl_init(struct agnx_priv *priv)
4149 + void __iomem *data = priv->data;
4152 + for (i = 0; i <= 28; i += 4)
4153 + iowrite32(0xb00c, data + AGNX_ENGINE_LOOKUP_TBL + i);
4154 + for (i = 32; i <= 120; i += 8) {
4155 + iowrite32(0x1e58, data + AGNX_ENGINE_LOOKUP_TBL + i);
4156 + iowrite32(0xb00c, data + AGNX_ENGINE_LOOKUP_TBL + i + 4);
4159 + for (i = 128; i <= 156; i += 4)
4160 + iowrite32(0x980c, data + AGNX_ENGINE_LOOKUP_TBL + i);
4161 + for (i = 160; i <= 248; i += 8) {
4162 + iowrite32(0x1858, data + AGNX_ENGINE_LOOKUP_TBL + i);
4163 + iowrite32(0x980c, data + AGNX_ENGINE_LOOKUP_TBL + i + 4);
4166 + for (i = 256; i <= 284; i += 4)
4167 + iowrite32(0x980c, data + AGNX_ENGINE_LOOKUP_TBL + i);
4168 + for (i = 288; i <= 376; i += 8) {
4169 + iowrite32(0x1a58, data + AGNX_ENGINE_LOOKUP_TBL + i);
4170 + iowrite32(0x1858, data + AGNX_ENGINE_LOOKUP_TBL + i + 4);
4173 + for (i = 512; i <= 540; i += 4)
4174 + iowrite32(0xc00c, data + AGNX_ENGINE_LOOKUP_TBL + i);
4175 + for (i = 544; i <= 632; i += 8) {
4176 + iowrite32(0x2058, data + AGNX_ENGINE_LOOKUP_TBL + i);
4177 + iowrite32(0xc00c, data + AGNX_ENGINE_LOOKUP_TBL + i + 4);
4180 + for (i = 640; i <= 668; i += 4)
4181 + iowrite32(0xc80c, data + AGNX_ENGINE_LOOKUP_TBL + i);
4182 + for (i = 672; i <= 764; i += 8) {
4183 + iowrite32(0x2258, data + AGNX_ENGINE_LOOKUP_TBL + i);
4184 + iowrite32(0xc80c, data + AGNX_ENGINE_LOOKUP_TBL + i + 4);
4189 +++ b/drivers/staging/agnx/table.h
4191 +#ifndef AGNX_TABLE_H_
4192 +#define AGNX_TABLE_H_
4194 +void tx_fir_table_init(struct agnx_priv *priv);
4195 +void gain_table_init(struct agnx_priv *priv);
4196 +void monitor_gain_table_init(struct agnx_priv *priv);
4197 +void routing_table_init(struct agnx_priv *priv);
4198 +void tx_engine_lookup_tbl_init(struct agnx_priv *priv);
4200 +#endif /* AGNX_TABLE_H_ */
4202 +++ b/drivers/staging/agnx/TODO
4206 +The RX has can't receive OFDM packet correctly,
4207 +Guess it need be do RX calibrate.
4212 +1: The RX get too much "CRC failed" pakets, it make the card work very unstable,
4213 +2: After running a while, the card will get infinity "RX Frame" and "Error"
4214 +interrupt, not know the root reason so far, try to fix it
4215 +3: Using two tx queue txd and txm but not only txm.
4216 +4: Set the hdr correctly.
4217 +5: Try to do recalibrate correvtly
4218 +6: To support G mode in future
4219 +7: Fix the mac address can't be readed and set correctly in BE machine.
4220 +8: Fix include and exclude FCS in promisous mode and manage mode
4221 +9: Using sta_notify to notice sta change
4222 +10: Turn on frame reception at the end of start
4223 +11: Guess the card support HW_MULTICAST_FILTER
4224 +12: The tx process should be implment atomic?
4225 +13: Using mac80211 function to control the TX&RX LED.
4227 +++ b/drivers/staging/agnx/xmit.c
4230 + * Airgo MIMO wireless driver
4232 + * Copyright (c) 2007 Li YanBo <dreamfly281@gmail.com>
4234 + * Thanks for Jeff Williams <angelbane@gmail.com> do reverse engineer
4235 + * works and published the SPECS at http://airgo.wdwconsulting.net/mymoin
4237 + * This program is free software; you can redistribute it and/or modify
4238 + * it under the terms of the GNU General Public License version 2 as
4239 + * published by the Free Software Foundation.
4242 +#include <linux/pci.h>
4243 +#include <linux/delay.h>
4248 +unsigned int rx_frame_cnt = 0;
4249 +//unsigned int local_tx_sent_cnt = 0;
4251 +static inline void disable_rx_engine(struct agnx_priv *priv)
4253 + void __iomem *ctl = priv->ctl;
4254 + iowrite32(0x100, ctl + AGNX_CIR_RXCTL);
4255 + /* Wait for RX Control to have the Disable Rx Interrupt (0x100) set */
4256 + ioread32(ctl + AGNX_CIR_RXCTL);
4259 +static inline void enable_rx_engine(struct agnx_priv *priv)
4261 + void __iomem *ctl = priv->ctl;
4262 + iowrite32(0x80, ctl + AGNX_CIR_RXCTL);
4263 + ioread32(ctl + AGNX_CIR_RXCTL);
4266 +inline void disable_rx_interrupt(struct agnx_priv *priv)
4268 + void __iomem *ctl = priv->ctl;
4271 + disable_rx_engine(priv);
4272 + reg = ioread32(ctl + AGNX_CIR_RXCFG);
4274 + iowrite32(reg, ctl + AGNX_CIR_RXCFG);
4275 + ioread32(ctl + AGNX_CIR_RXCFG);
4278 +inline void enable_rx_interrupt(struct agnx_priv *priv)
4280 + void __iomem *ctl = priv->ctl;
4283 + reg = ioread32(ctl + AGNX_CIR_RXCFG);
4285 + iowrite32(reg, ctl + AGNX_CIR_RXCFG);
4286 + ioread32(ctl + AGNX_CIR_RXCFG);
4287 + enable_rx_engine(priv);
4290 +static inline void rx_desc_init(struct agnx_priv *priv, unsigned int idx)
4292 + struct agnx_desc *desc = priv->rx.desc + idx;
4293 + struct agnx_info *info = priv->rx.info + idx;
4295 + memset(info, 0, sizeof(*info));
4297 + info->dma_len = IEEE80211_MAX_RTS_THRESHOLD + sizeof(struct agnx_hdr);
4298 + info->skb = dev_alloc_skb(info->dma_len);
4299 + if (info->skb == NULL)
4300 + agnx_bug("refill err");
4302 + info->mapping = pci_map_single(priv->pdev, skb_tail_pointer(info->skb),
4303 + info->dma_len, PCI_DMA_FROMDEVICE);
4304 + memset(desc, 0, sizeof(*desc));
4305 + desc->dma_addr = cpu_to_be32(info->mapping);
4306 + /* Set the owner to the card */
4307 + desc->frag = cpu_to_be32(be32_to_cpu(desc->frag) | OWNER);
4310 +static inline void rx_desc_reinit(struct agnx_priv *priv, unsigned int idx)
4312 + struct agnx_info *info = priv->rx.info + idx;
4314 + /* Cause ieee80211 will free the skb buffer, so we needn't to free it again?! */
4315 + pci_unmap_single(priv->pdev, info->mapping, info->dma_len, PCI_DMA_FROMDEVICE);
4316 + rx_desc_init(priv, idx);
4319 +static inline void rx_desc_reusing(struct agnx_priv *priv, unsigned int idx)
4321 + struct agnx_desc *desc = priv->rx.desc + idx;
4322 + struct agnx_info *info = priv->rx.info + idx;
4324 + memset(desc, 0, sizeof(*desc));
4325 + desc->dma_addr = cpu_to_be32(info->mapping);
4326 + /* Set the owner to the card */
4327 + desc->frag = cpu_to_be32(be32_to_cpu(desc->frag) | OWNER);
4330 +static void rx_desc_free(struct agnx_priv *priv, unsigned int idx)
4332 + struct agnx_desc *desc = priv->rx.desc + idx;
4333 + struct agnx_info *info = priv->rx.info + idx;
4335 + BUG_ON(!desc || !info);
4336 + if (info->mapping)
4337 + pci_unmap_single(priv->pdev, info->mapping, info->dma_len, PCI_DMA_FROMDEVICE);
4339 + dev_kfree_skb(info->skb);
4340 + memset(info, 0, sizeof(*info));
4341 + memset(desc, 0, sizeof(*desc));
4344 +static inline void __tx_desc_free(struct agnx_priv *priv,
4345 + struct agnx_desc *desc, struct agnx_info *info)
4347 + BUG_ON(!desc || !info);
4348 + /* TODO make sure mapping, skb and len are consistency */
4349 + if (info->mapping)
4350 + pci_unmap_single(priv->pdev, info->mapping,
4351 + info->dma_len, PCI_DMA_TODEVICE);
4352 + if (info->type == PACKET)
4353 + dev_kfree_skb(info->skb);
4355 + memset(info, 0, sizeof(*info));
4356 + memset(desc, 0, sizeof(*desc));
4359 +static void txm_desc_free(struct agnx_priv *priv, unsigned int idx)
4361 + struct agnx_desc *desc = priv->txm.desc + idx;
4362 + struct agnx_info *info = priv->txm.info + idx;
4364 + __tx_desc_free(priv, desc, info);
4367 +static void txd_desc_free(struct agnx_priv *priv, unsigned int idx)
4369 + struct agnx_desc *desc = priv->txd.desc + idx;
4370 + struct agnx_info *info = priv->txd.info + idx;
4372 + __tx_desc_free(priv, desc, info);
4375 +int fill_rings(struct agnx_priv *priv)
4377 + void __iomem *ctl = priv->ctl;
4382 + priv->txd.idx_sent = priv->txm.idx_sent = 0;
4383 + priv->rx.idx = priv->txm.idx = priv->txd.idx = 0;
4385 + for (i = 0; i < priv->rx.size; i++)
4386 + rx_desc_init(priv, i);
4387 + for (i = 0; i < priv->txm.size; i++) {
4388 + memset(priv->txm.desc + i, 0, sizeof(struct agnx_desc));
4389 + memset(priv->txm.info + i, 0, sizeof(struct agnx_info));
4391 + for (i = 0; i < priv->txd.size; i++) {
4392 + memset(priv->txd.desc + i, 0, sizeof(struct agnx_desc));
4393 + memset(priv->txd.info + i, 0, sizeof(struct agnx_info));
4396 + /* FIXME Set the card RX TXM and TXD address */
4397 + agnx_write32(ctl, AGNX_CIR_RXCMSTART, priv->rx.dma);
4398 + agnx_write32(ctl, AGNX_CIR_RXCMEND, priv->txm.dma);
4400 + agnx_write32(ctl, AGNX_CIR_TXMSTART, priv->txm.dma);
4401 + agnx_write32(ctl, AGNX_CIR_TXMEND, priv->txd.dma);
4403 + agnx_write32(ctl, AGNX_CIR_TXDSTART, priv->txd.dma);
4404 + agnx_write32(ctl, AGNX_CIR_TXDEND, priv->txd.dma +
4405 + sizeof(struct agnx_desc) * priv->txd.size);
4407 + /* FIXME Relinquish control of rings to card */
4408 + reg = agnx_read32(ctl, AGNX_CIR_BLKCTL);
4410 + agnx_write32(ctl, AGNX_CIR_BLKCTL, reg);
4414 +void unfill_rings(struct agnx_priv *priv)
4416 + unsigned long flags;
4420 + spin_lock_irqsave(&priv->lock, flags);
4422 + for (i = 0; i < priv->rx.size; i++)
4423 + rx_desc_free(priv, i);
4424 + for (i = 0; i < priv->txm.size; i++)
4425 + txm_desc_free(priv, i);
4426 + for (i = 0; i < priv->txd.size; i++)
4427 + txd_desc_free(priv, i);
4429 + spin_unlock_irqrestore(&priv->lock, flags);
4432 +/* Extract the bitrate out of a CCK PLCP header.
4433 + copy from bcm43xx driver */
4434 +static inline u8 agnx_plcp_get_bitrate_cck(__be32 *phyhdr_11b)
4437 + switch (*(u8 *)phyhdr_11b) {
4447 + agnx_bug("Wrong plcp rate");
4452 +static inline u8 agnx_plcp_get_bitrate_ofdm(__be32 *phyhdr_11g)
4454 + u8 rate = *(u8 *)phyhdr_11g & 0xF;
4456 + printk(PFX "G mode rate is 0x%x\n", rate);
4461 +static void get_rx_stats(struct agnx_priv *priv, struct agnx_hdr *hdr,
4462 + struct ieee80211_rx_status *stat)
4464 + void __iomem *ctl = priv->ctl;
4467 + /* FIXME just for test */
4468 + int snr = 40; /* signal-to-noise ratio */
4470 + memset(stat, 0, sizeof(*stat));
4472 + rssi = (u8 *)&hdr->phy_stats_lo;
4473 +// stat->ssi = (rssi[0] + rssi[1] + rssi[2]) / 3;
4475 + noise = ioread32(ctl + AGNX_GCR_NOISE0);
4476 + noise += ioread32(ctl + AGNX_GCR_NOISE1);
4477 + noise += ioread32(ctl + AGNX_GCR_NOISE2);
4478 + stat->noise = noise / 3;
4479 + /* Signal quality */
4480 + //snr = stat->ssi - stat->noise;
4481 + if (snr >=0 && snr < 40)
4482 + stat->signal = 5 * snr / 2;
4483 + else if (snr >= 40)
4484 + stat->signal = 100;
4489 + if (hdr->_11b0 && !hdr->_11g0) {
4490 + stat->rate_idx = agnx_plcp_get_bitrate_cck(&hdr->_11b0);
4491 + } else if (!hdr->_11b0 && hdr->_11g0) {
4492 + printk(PFX "RX: Found G mode packet\n");
4493 + stat->rate_idx = agnx_plcp_get_bitrate_ofdm(&hdr->_11g0);
4495 + agnx_bug("Unknown packets type");
4498 + stat->band = IEEE80211_BAND_2GHZ;
4499 + stat->freq = agnx_channels[priv->channel - 1].center_freq;
4500 +// stat->antenna = 3;
4501 +// stat->mactime = be32_to_cpu(hdr->time_stamp);
4502 +// stat->channel = priv->channel;
4506 +static inline void combine_hdr_frag(struct ieee80211_hdr *ieeehdr,
4507 + struct sk_buff *skb)
4510 + unsigned int hdrlen;
4512 + fctl = le16_to_cpu(ieeehdr->frame_control);
4513 + hdrlen = ieee80211_hdrlen(fctl);
4515 + if (hdrlen < (2+2+6)/*minimum hdr*/ ||
4516 + hdrlen > sizeof(struct ieee80211_mgmt)) {
4517 + printk(KERN_ERR PFX "hdr len is %d\n", hdrlen);
4518 + agnx_bug("Wrong ieee80211 hdr detected");
4520 + skb_push(skb, hdrlen);
4521 + memcpy(skb->data, ieeehdr, hdrlen);
4522 +} /* combine_hdr_frag */
4524 +static inline int agnx_packet_check(struct agnx_priv *priv, struct agnx_hdr *agnxhdr,
4525 + unsigned packet_len)
4527 + if (agnx_get_bits(CRC_FAIL, CRC_FAIL_SHIFT, be32_to_cpu(agnxhdr->reg1)) == 1){
4528 + printk(PFX "RX: CRC check fail\n");
4531 + if (packet_len > 2048) {
4532 + printk(PFX "RX: Too long packet detected\n");
4536 + /* FIXME Just usable for Promious Mode, for Manage mode exclude FCS */
4537 +/* if (packet_len - sizeof(*agnxhdr) < FCS_LEN) { */
4538 +/* printk(PFX "RX: Too short packet detected\n"); */
4543 + priv->stats.dot11FCSErrorCount++;
4547 +void handle_rx_irq(struct agnx_priv *priv)
4549 + struct ieee80211_rx_status status;
4554 + struct agnx_desc *desc;
4556 + struct agnx_info *info;
4557 + struct agnx_hdr *hdr;
4558 + struct sk_buff *skb;
4559 + unsigned int i = priv->rx.idx % priv->rx.size;
4561 + desc = priv->rx.desc + i;
4562 + frag = be32_to_cpu(desc->frag);
4566 + info = priv->rx.info + i;
4568 + hdr = (struct agnx_hdr *)(skb->data);
4570 + len = (frag & PACKET_LEN) >> PACKET_LEN_SHIFT;
4571 + if (agnx_packet_check(priv, hdr, len) == -1) {
4572 + rx_desc_reusing(priv, i);
4575 + skb_put(skb, len);
4579 + fctl = le16_to_cpu(((struct ieee80211_hdr *)hdr->mac_hdr)->frame_control);
4580 + if ((fctl & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_BEACON)// && !(fctl & IEEE80211_STYPE_BEACON))
4581 + dump_ieee80211_hdr((struct ieee80211_hdr *)hdr->mac_hdr, "RX");
4584 + if (hdr->_11b0 && !hdr->_11g0) {
4586 +/* u16 fctl = le16_to_cpu(((struct ieee80211_hdr *)hdr->mac_hdr) */
4587 +/* ->frame_control); */
4588 +/* if ( (fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) { */
4589 +/* agnx_print_rx_hdr(hdr); */
4590 +// agnx_print_sta(priv, BSSID_STAID);
4591 +/* for (j = 0; j < 8; j++) */
4592 +/* agnx_print_sta_tx_wq(priv, BSSID_STAID, j); */
4595 + get_rx_stats(priv, hdr, &status);
4596 + skb_pull(skb, sizeof(*hdr));
4597 + combine_hdr_frag((struct ieee80211_hdr *)hdr->mac_hdr, skb);
4598 + } else if (!hdr->_11b0 && hdr->_11g0) {
4600 + agnx_print_rx_hdr(hdr);
4601 + agnx_print_sta(priv, BSSID_STAID);
4602 +// for (j = 0; j < 8; j++)
4603 + agnx_print_sta_tx_wq(priv, BSSID_STAID, 0);
4605 + print_hex_dump_bytes("agnx: RX_PACKET: ", DUMP_PREFIX_NONE,
4606 + skb->data, skb->len + 8);
4608 +// if (agnx_plcp_get_bitrate_ofdm(&hdr->_11g0) == 0)
4609 + get_rx_stats(priv, hdr, &status);
4610 + skb_pull(skb, sizeof(*hdr));
4611 + combine_hdr_frag((struct ieee80211_hdr *)
4612 + ((void *)&hdr->mac_hdr), skb);
4613 +// dump_ieee80211_hdr((struct ieee80211_hdr *)skb->data, "RX G");
4615 + agnx_bug("Unknown packets type");
4616 + ieee80211_rx_irqsafe(priv->hw, skb, &status);
4617 + rx_desc_reinit(priv, i);
4619 + } while ( priv->rx.idx++ );
4620 +} /* handle_rx_irq */
4622 +static inline void handle_tx_irq(struct agnx_priv *priv, struct agnx_ring *ring)
4624 + struct agnx_desc *desc;
4625 + struct agnx_info *info;
4628 + for (idx = ring->idx_sent; idx < ring->idx; idx++) {
4629 + unsigned int i = idx % ring->size;
4632 + desc = ring->desc + i;
4633 + info = ring->info + i;
4635 + frag = be32_to_cpu(desc->frag);
4636 + if (frag & OWNER) {
4637 + if (info->type == HEADER)
4640 + agnx_bug("TX error");
4643 + pci_unmap_single(priv->pdev, info->mapping, info->dma_len, PCI_DMA_TODEVICE);
4648 + len = info->skb->len - sizeof(struct agnx_hdr) + info->hdr_len;
4649 + // if (len == 614) {
4650 +// agnx_print_desc(desc);
4651 + if (info->type == PACKET) {
4652 +// agnx_print_tx_hdr((struct agnx_hdr *)info->skb->data);
4653 +/* agnx_print_sta_power(priv, LOCAL_STAID); */
4654 +/* agnx_print_sta(priv, LOCAL_STAID); */
4655 +/* // for (j = 0; j < 8; j++) */
4656 +/* agnx_print_sta_tx_wq(priv, LOCAL_STAID, 0); */
4657 +// agnx_print_sta_power(priv, BSSID_STAID);
4658 +// agnx_print_sta(priv, BSSID_STAID);
4659 +// for (j = 0; j < 8; j++)
4660 +// agnx_print_sta_tx_wq(priv, BSSID_STAID, 0);
4665 + if (info->type == PACKET) {
4666 +// dump_txm_registers(priv);
4667 +// dump_rxm_registers(priv);
4668 +// dump_bm_registers(priv);
4669 +// dump_cir_registers(priv);
4672 + if (info->type == PACKET) {
4673 +// struct ieee80211_hdr *hdr;
4674 + struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(info->skb);
4676 + skb_pull(info->skb, sizeof(struct agnx_hdr));
4677 + memcpy(skb_push(info->skb, info->hdr_len), &info->hdr, info->hdr_len);
4679 +// dump_ieee80211_hdr((struct ieee80211_hdr *)info->skb->data, "TX_HANDLE");
4680 +/* print_hex_dump_bytes("agnx: TX_HANDLE: ", DUMP_PREFIX_NONE, */
4681 +/* info->skb->data, info->skb->len); */
4683 + if (!(txi->flags & IEEE80211_TX_CTL_NO_ACK))
4684 + txi->flags |= IEEE80211_TX_STAT_ACK;
4686 + ieee80211_tx_status_irqsafe(priv->hw, info->skb);
4689 +/* info->tx_status.queue_number = (ring->size - i) / 2; */
4690 +/* ieee80211_tx_status_irqsafe(priv->hw, info->skb, &(info->tx_status)); */
4692 +/* dev_kfree_skb_irq(info->skb); */
4694 + memset(desc, 0, sizeof(*desc));
4695 + memset(info, 0, sizeof(*info));
4698 + ring->idx_sent = idx;
4699 + /* TODO fill the priv->low_level_stats */
4701 + /* ieee80211_wake_queue(priv->hw, 0); */
4704 +void handle_txm_irq(struct agnx_priv *priv)
4706 + handle_tx_irq(priv, &priv->txm);
4709 +void handle_txd_irq(struct agnx_priv *priv)
4711 + handle_tx_irq(priv, &priv->txd);
4714 +void handle_other_irq(struct agnx_priv *priv)
4716 +// void __iomem *ctl = priv->ctl;
4717 + u32 status = priv->irq_status;
4718 + void __iomem *ctl = priv->ctl;
4721 + if (status & IRQ_TX_BEACON) {
4722 + iowrite32(IRQ_TX_BEACON, ctl + AGNX_INT_STAT);
4723 + printk(PFX "IRQ: TX Beacon control is 0X%.8X\n", ioread32(ctl + AGNX_TXM_BEACON_CTL));
4724 + printk(PFX "IRQ: TX Beacon rx frame num: %d\n", rx_frame_cnt);
4726 + if (status & IRQ_TX_RETRY) {
4727 + reg = ioread32(ctl + AGNX_TXM_RETRYSTAID);
4728 + printk(PFX "IRQ: TX Retry, RETRY STA ID is %x\n", reg);
4730 + if (status & IRQ_TX_ACTIVITY)
4731 + printk(PFX "IRQ: TX Activity\n");
4732 + if (status & IRQ_RX_ACTIVITY)
4733 + printk(PFX "IRQ: RX Activity\n");
4734 + if (status & IRQ_RX_X)
4735 + printk(PFX "IRQ: RX X\n");
4736 + if (status & IRQ_RX_Y) {
4737 + reg = ioread32(ctl + AGNX_INT_MASK);
4739 + iowrite32(reg, ctl + AGNX_INT_MASK);
4740 + iowrite32(IRQ_RX_Y, ctl + AGNX_INT_STAT);
4741 + printk(PFX "IRQ: RX Y\n");
4743 + if (status & IRQ_RX_HASHHIT) {
4744 + reg = ioread32(ctl + AGNX_INT_MASK);
4745 + reg &= ~IRQ_RX_HASHHIT;
4746 + iowrite32(reg, ctl + AGNX_INT_MASK);
4747 + iowrite32(IRQ_RX_HASHHIT, ctl + AGNX_INT_STAT);
4748 + printk(PFX "IRQ: RX Hash Hit\n");
4751 + if (status & IRQ_RX_FRAME) {
4752 + reg = ioread32(ctl + AGNX_INT_MASK);
4753 + reg &= ~IRQ_RX_FRAME;
4754 + iowrite32(reg, ctl + AGNX_INT_MASK);
4755 + iowrite32(IRQ_RX_FRAME, ctl + AGNX_INT_STAT);
4756 + printk(PFX "IRQ: RX Frame\n");
4759 + if (status & IRQ_ERR_INT) {
4760 + iowrite32(IRQ_ERR_INT, ctl + AGNX_INT_STAT);
4761 +// agnx_hw_reset(priv);
4762 + printk(PFX "IRQ: Error Interrupt\n");
4764 + if (status & IRQ_TX_QUE_FULL)
4765 + printk(PFX "IRQ: TX Workqueue Full\n");
4766 + if (status & IRQ_BANDMAN_ERR)
4767 + printk(PFX "IRQ: Bandwidth Management Error\n");
4768 + if (status & IRQ_TX_DISABLE)
4769 + printk(PFX "IRQ: TX Disable\n");
4770 + if (status & IRQ_RX_IVASESKEY)
4771 + printk(PFX "IRQ: RX Invalid Session Key\n");
4772 + if (status & IRQ_REP_THHIT)
4773 + printk(PFX "IRQ: Replay Threshold Hit\n");
4774 + if (status & IRQ_TIMER1)
4775 + printk(PFX "IRQ: Timer1\n");
4776 + if (status & IRQ_TIMER_CNT)
4777 + printk(PFX "IRQ: Timer Count\n");
4778 + if (status & IRQ_PHY_FASTINT)
4779 + printk(PFX "IRQ: Phy Fast Interrupt\n");
4780 + if (status & IRQ_PHY_SLOWINT)
4781 + printk(PFX "IRQ: Phy Slow Interrupt\n");
4782 + if (status & IRQ_OTHER)
4783 + printk(PFX "IRQ: 0x80000000\n");
4784 +} /* handle_other_irq */
4787 +static inline void route_flag_set(struct agnx_hdr *txhdr)
4792 +/* reg = (0x7 << ROUTE_COMPRESSION_SHIFT) & ROUTE_COMPRESSION; */
4793 +/* txhdr->reg5 = cpu_to_be32(reg); */
4794 + txhdr->reg5 = (0xa << 0x0) | (0x7 << 0x18);
4795 +// txhdr->reg5 = cpu_to_be32((0xa << 0x0) | (0x7 << 0x18));
4796 +// txhdr->reg5 = cpu_to_be32(0x7 << 0x0);
4799 +/* Return 0 if no match */
4800 +static inline unsigned int get_power_level(unsigned int rate, unsigned int antennas_num)
4802 + unsigned int power_level;
4810 + case 120: power_level = 22; break;
4811 + case 180: power_level = 19; break;
4812 + case 240: power_level = 18; break;
4813 + case 360: power_level = 16; break;
4814 + case 480: power_level = 15; break;
4815 + case 540: power_level = 14; break;
4817 + agnx_bug("Error rate setting\n");
4820 + if (power_level && (antennas_num == 2))
4823 + return power_level;
4826 +static inline void fill_agnx_hdr(struct agnx_priv *priv, struct agnx_info *tx_info)
4828 + struct agnx_hdr *txhdr = (struct agnx_hdr *)tx_info->skb->data;
4830 + u16 fc = le16_to_cpu(*(__le16 *)&tx_info->hdr);
4833 + memset(txhdr, 0, sizeof(*txhdr));
4835 +// reg = agnx_set_bits(STATION_ID, STATION_ID_SHIFT, LOCAL_STAID);
4836 + reg = agnx_set_bits(STATION_ID, STATION_ID_SHIFT, BSSID_STAID);
4837 + reg |= agnx_set_bits(WORKQUEUE_ID, WORKQUEUE_ID_SHIFT, 0);
4838 + txhdr->reg4 = cpu_to_be32(reg);
4840 + /* Set the Hardware Sequence Number to 1? */
4841 + reg = agnx_set_bits(SEQUENCE_NUMBER, SEQUENCE_NUMBER_SHIFT, 0);
4842 +// reg = agnx_set_bits(SEQUENCE_NUMBER, SEQUENCE_NUMBER_SHIFT, 1);
4843 + reg |= agnx_set_bits(MAC_HDR_LEN, MAC_HDR_LEN_SHIFT, tx_info->hdr_len);
4844 + txhdr->reg1 = cpu_to_be32(reg);
4845 + /* Set the agnx_hdr's MAC header */
4846 + memcpy(txhdr->mac_hdr, &tx_info->hdr, tx_info->hdr_len);
4848 + reg = agnx_set_bits(ACK, ACK_SHIFT, 1);
4849 +// reg = agnx_set_bits(ACK, ACK_SHIFT, 0);
4850 + reg |= agnx_set_bits(MULTICAST, MULTICAST_SHIFT, 0);
4851 +// reg |= agnx_set_bits(MULTICAST, MULTICAST_SHIFT, 1);
4852 + reg |= agnx_set_bits(RELAY, RELAY_SHIFT, 0);
4853 + reg |= agnx_set_bits(TM, TM_SHIFT, 0);
4854 + txhdr->reg0 = cpu_to_be32(reg);
4856 + /* Set the long and short retry limits */
4857 + txhdr->tx.short_retry_limit = tx_info->txi->control.retry_limit;
4858 + txhdr->tx.long_retry_limit = tx_info->txi->control.retry_limit;
4861 + len = tx_info->skb->len - sizeof(*txhdr) + tx_info->hdr_len + FCS_LEN;
4862 + if (fc & IEEE80211_FCTL_PROTECTED)
4865 + reg = agnx_set_bits(FRAG_SIZE, FRAG_SIZE_SHIFT, len);
4866 + len = tx_info->skb->len - sizeof(*txhdr);
4867 + reg |= agnx_set_bits(PAYLOAD_LEN, PAYLOAD_LEN_SHIFT, len);
4868 + txhdr->reg3 = cpu_to_be32(reg);
4870 + route_flag_set(txhdr);
4873 +static void txm_power_set(struct agnx_priv *priv,
4874 + struct ieee80211_tx_info *txi)
4876 + struct agnx_sta_power power;
4880 + if (txi->tx_rate_idx < 0) {
4881 + /* For B mode Short Preamble */
4882 + reg = agnx_set_bits(PHY_MODE, PHY_MODE_SHIFT, AGNX_MODE_80211B_SHORT);
4883 +// control->tx_rate = -control->tx_rate;
4885 + reg = agnx_set_bits(PHY_MODE, PHY_MODE_SHIFT, AGNX_MODE_80211G);
4886 +// reg = agnx_set_bits(PHY_MODE, PHY_MODE_SHIFT, AGNX_MODE_80211B_LONG);
4887 + reg |= agnx_set_bits(SIGNAL, SIGNAL_SHIFT, 0xB);
4888 + reg |= agnx_set_bits(RATE, RATE_SHIFT, 0xB);
4889 +// reg |= agnx_set_bits(POWER_LEVEL, POWER_LEVEL_SHIFT, 15);
4890 + reg |= agnx_set_bits(POWER_LEVEL, POWER_LEVEL_SHIFT, 20);
4891 + /* if rate < 11M set it to 0 */
4892 + reg |= agnx_set_bits(NUM_TRANSMITTERS, NUM_TRANSMITTERS_SHIFT, 1);
4893 +// reg |= agnx_set_bits(EDCF, EDCF_SHIFT, 1);
4894 +// reg |= agnx_set_bits(TIFS, TIFS_SHIFT, 1);
4897 +// power.reg = cpu_to_le32(reg);
4899 +// set_sta_power(priv, &power, LOCAL_STAID);
4900 + set_sta_power(priv, &power, BSSID_STAID);
4903 +static inline int tx_packet_check(struct sk_buff *skb)
4905 + unsigned int ieee_len = ieee80211_get_hdrlen_from_skb(skb);
4906 + if (skb->len > 2048) {
4907 + printk(KERN_ERR PFX "length is %d\n", skb->len);
4908 + agnx_bug("Too long TX skb");
4912 + if (skb->len == ieee_len) {
4913 + printk(PFX "A strange TX packet\n");
4915 + /* tx_faile_irqsafe(); */
4920 +static int __agnx_tx(struct agnx_priv *priv, struct sk_buff *skb,
4921 + struct agnx_ring *ring)
4923 + struct agnx_desc *hdr_desc, *frag_desc;
4924 + struct agnx_info *hdr_info, *frag_info;
4925 + struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb);
4926 + unsigned long flags;
4929 + spin_lock_irqsave(&priv->lock, flags);
4931 + /* The RX interrupt need be Disable until this TX packet
4932 + is handled in the next tx interrupt */
4933 + disable_rx_interrupt(priv);
4937 +/* if (priv->txm_idx - priv->txm_idx_sent == AGNX_TXM_RING_SIZE - 2) */
4938 +/* ieee80211_stop_queue(priv->hw, 0); */
4940 + /* Set agnx header's info and desc */
4942 + hdr_desc = ring->desc + i;
4943 + hdr_info = ring->info + i;
4944 + hdr_info->hdr_len = ieee80211_get_hdrlen_from_skb(skb);
4945 + memcpy(&hdr_info->hdr, skb->data, hdr_info->hdr_len);
4947 + /* Add the agnx header to the front of the SKB */
4948 + skb_push(skb, sizeof(struct agnx_hdr) - hdr_info->hdr_len);
4950 + hdr_info->txi = txi;
4951 + hdr_info->dma_len = sizeof(struct agnx_hdr);
4952 + hdr_info->skb = skb;
4953 + hdr_info->type = HEADER;
4954 + fill_agnx_hdr(priv, hdr_info);
4955 + hdr_info->mapping = pci_map_single(priv->pdev, skb->data,
4956 + hdr_info->dma_len, PCI_DMA_TODEVICE);
4959 + frag |= agnx_set_bits(FIRST_FRAG, FIRST_FRAG_SHIFT, 1);
4960 + frag |= agnx_set_bits(LAST_FRAG, LAST_FRAG_SHIFT, 0);
4961 + frag |= agnx_set_bits(PACKET_LEN, PACKET_LEN_SHIFT, skb->len);
4962 + frag |= agnx_set_bits(FIRST_FRAG_LEN, FIRST_FRAG_LEN_SHIFT, 1);
4963 + frag |= agnx_set_bits(OWNER, OWNER_SHIFT, 1);
4964 + hdr_desc->frag = cpu_to_be32(frag);
4966 + hdr_desc->dma_addr = cpu_to_be32(hdr_info->mapping);
4969 + /* Set Frag's info and desc */
4970 + i = (i + 1) % ring->size;
4971 + frag_desc = ring->desc + i;
4972 + frag_info = ring->info + i;
4973 + memcpy(frag_info, hdr_info, sizeof(struct agnx_info));
4974 + frag_info->type = PACKET;
4975 + frag_info->dma_len = skb->len - hdr_info->dma_len;
4976 + frag_info->mapping = pci_map_single(priv->pdev, skb->data + hdr_info->dma_len,
4977 + frag_info->dma_len, PCI_DMA_TODEVICE);
4980 + frag |= agnx_set_bits(FIRST_FRAG, FIRST_FRAG_SHIFT, 0);
4981 + frag |= agnx_set_bits(LAST_FRAG, LAST_FRAG_SHIFT, 1);
4982 + frag |= agnx_set_bits(PACKET_LEN, PACKET_LEN_SHIFT, skb->len);
4983 + frag |= agnx_set_bits(SUB_FRAG_LEN, SUB_FRAG_LEN_SHIFT, frag_info->dma_len);
4984 + frag_desc->frag = cpu_to_be32(frag);
4986 + frag_desc->dma_addr = cpu_to_be32(frag_info->mapping);
4988 + txm_power_set(priv, txi);
4993 +/* len = skb->len - hdr_info->dma_len + hdr_info->hdr_len; */
4994 +/* // if (len == 614) { */
4995 +/* agnx_print_desc(hdr_desc); */
4996 +/* agnx_print_desc(frag_desc); */
4997 +/* agnx_print_tx_hdr((struct agnx_hdr *)skb->data); */
4998 +/* agnx_print_sta_power(priv, LOCAL_STAID); */
4999 +/* agnx_print_sta(priv, LOCAL_STAID); */
5000 +/* for (j = 0; j < 8; j++) */
5001 +/* agnx_print_sta_tx_wq(priv, LOCAL_STAID, j); */
5002 +/* agnx_print_sta_power(priv, BSSID_STAID); */
5003 +/* agnx_print_sta(priv, BSSID_STAID); */
5004 +/* for (j = 0; j < 8; j++) */
5005 +/* agnx_print_sta_tx_wq(priv, BSSID_STAID, j); */
5009 + spin_unlock_irqrestore(&priv->lock, flags);
5011 + /* FIXME ugly code */
5015 + reg = (ioread32(priv->ctl + AGNX_CIR_TXMCTL));
5017 + iowrite32((reg), priv->ctl + AGNX_CIR_TXMCTL);
5023 + reg = (ioread32(priv->ctl + AGNX_CIR_TXDCTL));
5025 + iowrite32((reg), priv->ctl + AGNX_CIR_TXDCTL);
5031 +int _agnx_tx(struct agnx_priv *priv, struct sk_buff *skb)
5035 + if (tx_packet_check(skb))
5038 +/* print_hex_dump_bytes("agnx: TX_PACKET: ", DUMP_PREFIX_NONE, */
5039 +/* skb->data, skb->len); */
5041 + fctl = le16_to_cpu(*((__le16 *)skb->data));
5043 + if ( (fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA )
5044 + return __agnx_tx(priv, skb, &priv->txd);
5046 + return __agnx_tx(priv, skb, &priv->txm);
5049 +++ b/drivers/staging/agnx/xmit.h
5051 +#ifndef AGNX_XMIT_H_
5052 +#define AGNX_XMIT_H_
5054 +#include <net/mac80211.h>
5058 +static inline u32 agnx_set_bits(u32 mask, u8 shift, u32 value)
5060 + return (value << shift) & mask;
5063 +static inline u32 agnx_get_bits(u32 mask, u8 shift, u32 value)
5065 + return (value & mask) >> shift;
5070 + __be16 rx_packet_duration; /* RX Packet Duration */
5071 + __be16 replay_cnt; /* Replay Count */
5072 +} __attribute__((__packed__));
5076 + u8 long_retry_limit; /* Long Retry Limit */
5077 + u8 short_retry_limit; /* Short Retry Limit */
5078 + u8 long_retry_cnt; /* Long Retry Count */
5079 + u8 short_retry_cnt; /* Short Retry Count */
5080 +} __attribute__((__packed__));
5083 +/* Copy from bcm43xx */
5084 +#define P4D_BYT3S(magic, nr_bytes) u8 __p4dding##magic[nr_bytes]
5085 +#define P4D_BYTES(line, nr_bytes) P4D_BYT3S(line, nr_bytes)
5086 +#define PAD_BYTES(nr_bytes) P4D_BYTES(__LINE__, nr_bytes)
5088 +#define P4D_BIT3S(magic, nr_bits) __be32 __padding##magic:nr_bits
5089 +#define P4D_BITS(line, nr_bits) P4D_BIT3S(line, nr_bits)
5090 +#define PAD_BITS(nr_bits) P4D_BITS(__LINE__, nr_bits)
5095 +#define RTS 0x80000000 /* RTS */
5096 +#define RTS_SHIFT 31
5097 +#define MULTICAST 0x40000000 /* multicast */
5098 +#define MULTICAST_SHIFT 30
5099 +#define ACK 0x30000000 /* ACK */
5100 +#define ACK_SHIFT 28
5101 +#define TM 0x08000000 /* TM */
5102 +#define TM_SHIFT 27
5103 +#define RELAY 0x04000000 /* Relay */
5104 +#define RELAY_SHIFT 26
5106 +#define REVISED_FCS 0x00380000 /* revised FCS */
5107 +#define REVISED_FCS_SHIFT 19
5108 +#define NEXT_BUFFER_ADDR 0x0007FFFF /* Next Buffer Address */
5109 +#define NEXT_BUFFER_ADDR_SHIFT 0
5112 +#define MAC_HDR_LEN 0xFC000000 /* MAC Header Length */
5113 +#define MAC_HDR_LEN_SHIFT 26
5114 +#define DURATION_OVERIDE 0x02000000 /* Duration Override */
5115 +#define DURATION_OVERIDE_SHIFT 25
5116 +#define PHY_HDR_OVERIDE 0x01000000 /* PHY Header Override */
5117 +#define PHY_HDR_OVERIDE_SHIFT 24
5118 +#define CRC_FAIL 0x00800000 /* CRC fail */
5119 +#define CRC_FAIL_SHIFT 23
5121 +#define SEQUENCE_NUMBER 0x00200000 /* Sequence Number */
5122 +#define SEQUENCE_NUMBER_SHIFT 21
5124 +#define BUFF_HEAD_ADDR 0x0007FFFF /* Buffer Head Address */
5125 +#define BUFF_HEAD_ADDR_SHIFT 0
5128 +#define PDU_COUNT 0xFC000000 /* PDU Count */
5129 +#define PDU_COUNT_SHIFT 26
5131 +#define WEP_KEY 0x00600000 /* WEP Key # */
5132 +#define WEP_KEY_SHIFT 21
5133 +#define USES_WEP_KEY 0x00100000 /* Uses WEP Key */
5134 +#define USES_WEP_KEY_SHIFT 20
5135 +#define KEEP_ALIVE 0x00080000 /* Keep alive */
5136 +#define KEEP_ALIVE_SHIFT 19
5137 +#define BUFF_TAIL_ADDR 0x0007FFFF /* Buffer Tail Address */
5138 +#define BUFF_TAIL_ADDR_SHIFT 0
5141 +#define CTS_11G 0x80000000 /* CTS in 11g */
5142 +#define CTS_11G_SHIFT 31
5143 +#define RTS_11G 0x40000000 /* RTS in 11g */
5144 +#define RTS_11G_SHIFT 30
5146 +#define FRAG_SIZE 0x0FFF0000 /* fragment size */
5147 +#define FRAG_SIZE_SHIFT 16
5148 +#define PAYLOAD_LEN 0x0000FFF0 /* payload length */
5149 +#define PAYLOAD_LEN_SHIFT 4
5150 +#define FRAG_NUM 0x0000000F /* number of frags */
5151 +#define FRAG_NUM_SHIFT 0
5155 +#define RELAY_STAID 0x0FFF0000 /* relayStald */
5156 +#define RELAY_STAID_SHIFT 16
5157 +#define STATION_ID 0x0000FFF0 /* Station ID */
5158 +#define STATION_ID_SHIFT 4
5159 +#define WORKQUEUE_ID 0x0000000F /* Workqueue ID */
5160 +#define WORKQUEUE_ID_SHIFT 0
5162 + /* FIXME this register maybe is LE? */
5165 +#define ROUTE_HOST 0x0F000000
5166 +#define ROUTE_HOST_SHIFT 24
5167 +#define ROUTE_CARD_CPU 0x00F00000
5168 +#define ROUTE_CARD_CPU_SHIFT 20
5169 +#define ROUTE_ENCRYPTION 0x000F0000
5170 +#define ROUTE_ENCRYPTION_SHIFT 16
5171 +#define ROUTE_TX 0x0000F000
5172 +#define ROUTE_TX_SHIFT 12
5173 +#define ROUTE_RX1 0x00000F00
5174 +#define ROUTE_RX1_SHIFT 8
5175 +#define ROUTE_RX2 0x000000F0
5176 +#define ROUTE_RX2_SHIFT 4
5177 +#define ROUTE_COMPRESSION 0x0000000F
5178 +#define ROUTE_COMPRESSION_SHIFT 0
5180 + __be32 _11g0; /* 11g */
5181 + __be32 _11g1; /* 11g */
5182 + __be32 _11b0; /* 11b */
5183 + __be32 _11b1; /* 11b */
5184 + u8 mac_hdr[32]; /* MAC header */
5186 + __be16 rts_duration; /* RTS duration */
5187 + __be16 last_duration; /* Last duration */
5188 + __be16 sec_last_duration; /* Second to Last duration */
5189 + __be16 other_duration; /* Other duration */
5190 + __be16 tx_last_duration; /* TX Last duration */
5191 + __be16 tx_other_duration; /* TX Other Duration */
5192 + __be16 last_11g_len; /* Length of last 11g */
5193 + __be16 other_11g_len; /* Lenght of other 11g */
5195 + __be16 last_11b_len; /* Length of last 11b */
5196 + __be16 other_11b_len; /* Lenght of other 11b */
5200 +#define MBF 0xF000 /* mbf */
5201 +#define MBF_SHIFT 12
5202 +#define RSVD4 0x0FFF /* rsvd4 */
5203 +#define RSVD4_SHIFT 0
5205 + __be16 rx_frag_stat; /* RX fragmentation status */
5207 + __be32 time_stamp; /* TimeStamp */
5208 + __be32 phy_stats_hi; /* PHY stats hi */
5209 + __be32 phy_stats_lo; /* PHY stats lo */
5210 + __be32 mic_key0; /* MIC key 0 */
5211 + __be32 mic_key1; /* MIC key 1 */
5213 + union { /* RX/TX Union */
5214 + struct agnx_rx rx;
5215 + struct agnx_tx tx;
5218 + u8 rx_channel; /* Recieve Channel */
5222 +} __attribute__((__packed__));
5226 +#define PACKET_LEN 0xFFF00000
5227 +#define PACKET_LEN_SHIFT 20
5228 +/* ------------------------------------------------ */
5229 +#define FIRST_PACKET_MASK 0x00080000
5230 +#define FIRST_PACKET_MASK_SHIFT 19
5231 +#define FIRST_RESERV2 0x00040000
5232 +#define FIRST_RESERV2_SHIFT 18
5233 +#define FIRST_TKIP_ERROR 0x00020000
5234 +#define FIRST_TKIP_ERROR_SHIFT 17
5235 +#define FIRST_TKIP_PACKET 0x00010000
5236 +#define FIRST_TKIP_PACKET_SHIFT 16
5237 +#define FIRST_RESERV1 0x0000F000
5238 +#define FIRST_RESERV1_SHIFT 12
5239 +#define FIRST_FRAG_LEN 0x00000FF8
5240 +#define FIRST_FRAG_LEN_SHIFT 3
5241 +/* ------------------------------------------------ */
5242 +#define SUB_RESERV2 0x000c0000
5243 +#define SUB_RESERV2_SHIFT 18
5244 +#define SUB_TKIP_ERROR 0x00020000
5245 +#define SUB_TKIP_ERROR_SHIFT 17
5246 +#define SUB_TKIP_PACKET 0x00010000
5247 +#define SUB_TKIP_PACKET_SHIFT 16
5248 +#define SUB_RESERV1 0x00008000
5249 +#define SUB_RESERV1_SHIFT 15
5250 +#define SUB_FRAG_LEN 0x00007FF8
5251 +#define SUB_FRAG_LEN_SHIFT 3
5252 +/* ------------------------------------------------ */
5253 +#define FIRST_FRAG 0x00000004
5254 +#define FIRST_FRAG_SHIFT 2
5255 +#define LAST_FRAG 0x00000002
5256 +#define LAST_FRAG_SHIFT 1
5257 +#define OWNER 0x00000001
5258 +#define OWNER_SHIFT 0
5261 +} __attribute__((__packed__));
5263 +enum {HEADER, PACKET};
5266 + struct sk_buff *skb;
5267 + dma_addr_t mapping;
5268 + u32 dma_len; /* dma buffer len */
5269 + /* Below fields only usful for tx */
5270 + u32 hdr_len; /* ieee80211 header length */
5271 + unsigned int type;
5272 + struct ieee80211_tx_info *txi;
5273 + struct ieee80211_hdr hdr;
5278 + struct agnx_desc *desc;
5280 + struct agnx_info *info;
5281 + /* Will lead to overflow when sent packet number enough? */
5283 + unsigned int idx_sent; /* only usful for txd and txm */
5284 + unsigned int size;
5287 +#define AGNX_RX_RING_SIZE 128
5288 +#define AGNX_TXD_RING_SIZE 256
5289 +#define AGNX_TXM_RING_SIZE 128
5291 +void disable_rx_interrupt(struct agnx_priv *priv);
5292 +void enable_rx_interrupt(struct agnx_priv *priv);
5293 +int fill_rings(struct agnx_priv *priv);
5294 +void unfill_rings(struct agnx_priv *priv);
5295 +void handle_rx_irq(struct agnx_priv *priv);
5296 +void handle_txd_irq(struct agnx_priv *priv);
5297 +void handle_txm_irq(struct agnx_priv *priv);
5298 +void handle_other_irq(struct agnx_priv *priv);
5299 +int _agnx_tx(struct agnx_priv *priv, struct sk_buff *skb);
5300 +#endif /* AGNX_XMIT_H_ */
5301 --- a/drivers/staging/Kconfig
5302 +++ b/drivers/staging/Kconfig
5303 @@ -43,4 +43,6 @@ source "drivers/staging/echo/Kconfig"
5305 source "drivers/staging/at76_usb/Kconfig"
5307 +source "drivers/staging/agnx/Kconfig"
5310 --- a/drivers/staging/Makefile
5311 +++ b/drivers/staging/Makefile
5312 @@ -13,3 +13,4 @@ obj-$(CONFIG_W35UND) += winbond/
5313 obj-$(CONFIG_PRISM2_USB) += wlan-ng/
5314 obj-$(CONFIG_ECHO) += echo/
5315 obj-$(CONFIG_USB_ATMEL) += at76_usb/
5316 +obj-$(CONFIG_AGNX) += agnx/