iPXE
ath5k.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
3  * Copyright (c) 2004-2005 Atheros Communications, Inc.
4  * Copyright (c) 2006 Devicescape Software, Inc.
5  * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
6  * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
7  *
8  * Modified for iPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>
9  * Original from Linux kernel 2.6.30.
10  *
11  * All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer,
18  * without modification.
19  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
20  * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
21  * redistribution must be conditioned upon including a substantially
22  * similar Disclaimer requirement for further binary redistribution.
23  * 3. Neither the names of the above-listed copyright holders nor the names
24  * of any contributors may be used to endorse or promote products derived
25  * from this software without specific prior written permission.
26  *
27  * Alternatively, this software may be distributed under the terms of the
28  * GNU General Public License ("GPL") version 2 as published by the Free
29  * Software Foundation.
30  *
31  * NO WARRANTY
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
35  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
36  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
37  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
40  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
42  * THE POSSIBILITY OF SUCH DAMAGES.
43  *
44  */
45 
46 FILE_LICENCE ( BSD3 );
47 FILE_SECBOOT ( FORBIDDEN );
48 
49 #include <stdlib.h>
50 #include <ipxe/malloc.h>
51 #include <ipxe/timer.h>
52 #include <ipxe/netdevice.h>
53 #include <ipxe/pci.h>
54 #include <ipxe/pci_io.h>
55 
56 #include "base.h"
57 #include "reg.h"
58 
59 #define ATH5K_CALIB_INTERVAL 10 /* Calibrate PHY every 10 seconds */
60 #define ATH5K_RETRIES 4 /* Number of times to retry packet sends */
61 #define ATH5K_DESC_ALIGN 16 /* Alignment for TX/RX descriptors */
62 
63 /******************\
64 * Internal defines *
65 \******************/
66 
67 /* Known PCI ids */
68 static struct pci_device_id ath5k_nics[] = {
69  PCI_ROM(0x10b7, 0x0013, "rdag675", "3com 3CRDAG675", AR5K_AR5212),
70  PCI_ROM(0x168c, 0x0007, "ath5210", "Atheros 5210", AR5K_AR5210),
71  PCI_ROM(0x168c, 0x0011, "ath5311", "Atheros 5311 (AHB)", AR5K_AR5211),
72  PCI_ROM(0x168c, 0x0012, "ath5211", "Atheros 5211", AR5K_AR5211),
73  PCI_ROM(0x168c, 0x0013, "ath5212", "Atheros 5212", AR5K_AR5212),
74  PCI_ROM(0x168c, 0x0014, "ath5212x14", "Atheros 5212 x14", AR5K_AR5212),
75  PCI_ROM(0x168c, 0x0015, "ath5212x15", "Atheros 5212 x15", AR5K_AR5212),
76  PCI_ROM(0x168c, 0x0016, "ath5212x16", "Atheros 5212 x16", AR5K_AR5212),
77  PCI_ROM(0x168c, 0x0017, "ath5212x17", "Atheros 5212 x17", AR5K_AR5212),
78  PCI_ROM(0x168c, 0x0018, "ath5212x18", "Atheros 5212 x18", AR5K_AR5212),
79  PCI_ROM(0x168c, 0x0019, "ath5212x19", "Atheros 5212 x19", AR5K_AR5212),
80  PCI_ROM(0x168c, 0x001a, "ath2413", "Atheros 2413 Griffin", AR5K_AR5212),
81  PCI_ROM(0x168c, 0x001b, "ath5413", "Atheros 5413 Eagle", AR5K_AR5212),
82  PCI_ROM(0x168c, 0x001c, "ath5212e", "Atheros 5212 PCI-E", AR5K_AR5212),
83  PCI_ROM(0x168c, 0x001d, "ath2417", "Atheros 2417 Nala", AR5K_AR5212),
84  PCI_ROM(0x168c, 0x0207, "ath5210e", "Atheros 5210 early", AR5K_AR5210),
85  PCI_ROM(0x168c, 0x1014, "ath5212m", "Ath 5212 miniPCI", AR5K_AR5212),
86  PCI_ROM(0xa727, 0x0013, "ath5212c","3com Ath 5212", AR5K_AR5212),
87 };
88 
89 #define ATH5K_SPMBL_NO 1
90 #define ATH5K_SPMBL_YES 2
91 #define ATH5K_SPMBL_BOTH 3
92 
93 static const struct {
97 } ath5k_rates[] = {
113  { 0, 0, 0 },
114 };
115 
116 #define ATH5K_NR_RATES 15
117 
118 /*
119  * Prototypes - PCI stack related functions
120  */
121 static int ath5k_probe(struct pci_device *pdev);
122 static void ath5k_remove(struct pci_device *pdev);
123 
124 struct pci_driver ath5k_pci_driver __pci_driver = {
125  .ids = ath5k_nics,
126  .id_count = sizeof(ath5k_nics) / sizeof(ath5k_nics[0]),
127  .probe = ath5k_probe,
128  .remove = ath5k_remove,
129 };
130 
131 
132 
133 /*
134  * Prototypes - MAC 802.11 stack related functions
135  */
136 static int ath5k_tx(struct net80211_device *dev, struct io_buffer *skb);
137 static int ath5k_reset(struct ath5k_softc *sc, struct net80211_channel *chan);
138 static int ath5k_reset_wake(struct ath5k_softc *sc);
139 static int ath5k_start(struct net80211_device *dev);
140 static void ath5k_stop(struct net80211_device *dev);
141 static int ath5k_config(struct net80211_device *dev, int changed);
142 static void ath5k_poll(struct net80211_device *dev);
143 static void ath5k_irq(struct net80211_device *dev, int enable);
144 
146  .open = ath5k_start,
147  .close = ath5k_stop,
148  .transmit = ath5k_tx,
149  .poll = ath5k_poll,
150  .irq = ath5k_irq,
151  .config = ath5k_config,
152 };
153 
154 /*
155  * Prototypes - Internal functions
156  */
157 /* Attach detach */
158 static int ath5k_attach(struct net80211_device *dev);
159 static void ath5k_detach(struct net80211_device *dev);
160 /* Channel/mode setup */
161 static unsigned int ath5k_copy_channels(struct ath5k_hw *ah,
162  struct net80211_channel *channels,
163  unsigned int mode,
164  unsigned int max);
165 static int ath5k_setup_bands(struct net80211_device *dev);
166 static int ath5k_chan_set(struct ath5k_softc *sc,
167  struct net80211_channel *chan);
168 static void ath5k_setcurmode(struct ath5k_softc *sc,
169  unsigned int mode);
170 static void ath5k_mode_setup(struct ath5k_softc *sc);
171 
172 /* Descriptor setup */
173 static int ath5k_desc_alloc(struct ath5k_softc *sc);
174 static void ath5k_desc_free(struct ath5k_softc *sc);
175 /* Buffers setup */
176 static int ath5k_rxbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf);
177 static int ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf);
178 
179 static inline void ath5k_txbuf_free(struct ath5k_softc *sc,
180  struct ath5k_buf *bf)
181 {
182  if (!bf->iob)
183  return;
184 
185  net80211_tx_complete(sc->dev, bf->iob, 0, ECANCELED);
186  bf->iob = NULL;
187 }
188 
189 static inline void ath5k_rxbuf_free(struct ath5k_softc *sc __unused,
190  struct ath5k_buf *bf)
191 {
192  free_iob(bf->iob);
193  bf->iob = NULL;
194 }
195 
196 /* Queues setup */
197 static int ath5k_txq_setup(struct ath5k_softc *sc,
198  int qtype, int subtype);
199 static void ath5k_txq_drainq(struct ath5k_softc *sc,
200  struct ath5k_txq *txq);
201 static void ath5k_txq_cleanup(struct ath5k_softc *sc);
202 static void ath5k_txq_release(struct ath5k_softc *sc);
203 /* Rx handling */
204 static int ath5k_rx_start(struct ath5k_softc *sc);
205 static void ath5k_rx_stop(struct ath5k_softc *sc);
206 /* Tx handling */
207 static void ath5k_tx_processq(struct ath5k_softc *sc,
208  struct ath5k_txq *txq);
209 
210 /* Interrupt handling */
211 static int ath5k_init(struct ath5k_softc *sc);
212 static int ath5k_stop_hw(struct ath5k_softc *sc);
213 
214 static void ath5k_calibrate(struct ath5k_softc *sc);
215 
216 /* Filter */
217 static void ath5k_configure_filter(struct ath5k_softc *sc);
218 
219 /********************\
220 * PCI Initialization *
221 \********************/
222 
223 #if DBGLVL_MAX
224 static const char *
225 ath5k_chip_name(enum ath5k_srev_type type, u16 val)
226 {
227  const char *name = "xxxxx";
228  unsigned int i;
229 
230  for (i = 0; i < ARRAY_SIZE(srev_names); i++) {
231  if (srev_names[i].sr_type != type)
232  continue;
233 
234  if ((val & 0xf0) == srev_names[i].sr_val)
235  name = srev_names[i].sr_name;
236 
237  if ((val & 0xff) == srev_names[i].sr_val) {
238  name = srev_names[i].sr_name;
239  break;
240  }
241  }
242 
243  return name;
244 }
245 #endif
246 
247 static int ath5k_probe(struct pci_device *pdev)
248 {
249  void *mem;
250  struct ath5k_softc *sc;
251  struct net80211_device *dev;
252  int ret;
253  u8 csz;
254 
255  adjust_pci_device(pdev);
256 
257  /*
258  * Cache line size is used to size and align various
259  * structures used to communicate with the hardware.
260  */
262  if (csz == 0) {
263  /*
264  * We must have this setup properly for rx buffer
265  * DMA to work so force a reasonable value here if it
266  * comes up zero.
267  */
268  csz = 16;
270  }
271  /*
272  * The default setting of latency timer yields poor results,
273  * set it to the value used by other systems. It may be worth
274  * tweaking this setting more.
275  */
277 
278  /*
279  * Disable the RETRY_TIMEOUT register (0x41) to keep
280  * PCI Tx retries from interfering with C3 CPU state.
281  */
282  pci_write_config_byte(pdev, 0x41, 0);
283 
284  mem = pci_ioremap(pdev, pdev->membase, 0x10000);
285  if (!mem) {
286  DBG("ath5k: cannot remap PCI memory region\n");
287  ret = -EIO;
288  goto err;
289  }
290 
291  /*
292  * Allocate dev (net80211 main struct)
293  * and dev->priv (driver private data)
294  */
295  dev = net80211_alloc(sizeof(*sc));
296  if (!dev) {
297  DBG("ath5k: cannot allocate 802.11 device\n");
298  ret = -ENOMEM;
299  goto err_map;
300  }
301 
302  /* Initialize driver private data */
303  sc = dev->priv;
304  sc->dev = dev;
305  sc->pdev = pdev;
306 
307  sc->hwinfo = zalloc(sizeof(*sc->hwinfo));
308  if (!sc->hwinfo) {
309  DBG("ath5k: cannot allocate 802.11 hardware info structure\n");
310  ret = -ENOMEM;
311  goto err_free;
312  }
313 
314  sc->hwinfo->flags = NET80211_HW_RX_HAS_FCS;
315  sc->hwinfo->signal_type = NET80211_SIGNAL_DB;
316  sc->hwinfo->signal_max = 40; /* 35dB should give perfect 54Mbps */
317  sc->hwinfo->channel_change_time = 5000;
318 
319  /* Avoid working with the device until setup is complete */
320  sc->status |= ATH_STAT_INVALID;
321 
322  sc->iobase = mem;
323  sc->cachelsz = csz * 4; /* convert to bytes */
324 
325  DBG("ath5k: register base at %p (%08lx)\n", sc->iobase, pdev->membase);
326  DBG("ath5k: cache line size %d\n", sc->cachelsz);
327 
328  /* Set private data */
329  pci_set_drvdata(pdev, dev);
330  dev->netdev->dev = (struct device *)pdev;
331 
332  /* Initialize device */
333  ret = ath5k_hw_attach(sc, pdev->id->driver_data, &sc->ah);
334  if (ret)
335  goto err_free_hwinfo;
336 
337  /* Finish private driver data initialization */
338  ret = ath5k_attach(dev);
339  if (ret)
340  goto err_ah;
341 
342 #if DBGLVL_MAX
343  DBG("Atheros AR%s chip found (MAC: 0x%x, PHY: 0x%x)\n",
344  ath5k_chip_name(AR5K_VERSION_MAC, sc->ah->ah_mac_srev),
345  sc->ah->ah_mac_srev, sc->ah->ah_phy_revision);
346 
347  if (!sc->ah->ah_single_chip) {
348  /* Single chip radio (!RF5111) */
349  if (sc->ah->ah_radio_5ghz_revision &&
350  !sc->ah->ah_radio_2ghz_revision) {
351  /* No 5GHz support -> report 2GHz radio */
353  DBG("RF%s 2GHz radio found (0x%x)\n",
354  ath5k_chip_name(AR5K_VERSION_RAD,
357  /* No 2GHz support (5110 and some
358  * 5Ghz only cards) -> report 5Ghz radio */
359  } else if (!(sc->ah->ah_capabilities.cap_mode & AR5K_MODE_BIT_11B)) {
360  DBG("RF%s 5GHz radio found (0x%x)\n",
361  ath5k_chip_name(AR5K_VERSION_RAD,
364  /* Multiband radio */
365  } else {
366  DBG("RF%s multiband radio found (0x%x)\n",
367  ath5k_chip_name(AR5K_VERSION_RAD,
370  }
371  }
372  /* Multi chip radio (RF5111 - RF2111) ->
373  * report both 2GHz/5GHz radios */
374  else if (sc->ah->ah_radio_5ghz_revision &&
375  sc->ah->ah_radio_2ghz_revision) {
376  DBG("RF%s 5GHz radio found (0x%x)\n",
377  ath5k_chip_name(AR5K_VERSION_RAD,
380  DBG("RF%s 2GHz radio found (0x%x)\n",
381  ath5k_chip_name(AR5K_VERSION_RAD,
384  }
385  }
386 #endif
387 
388  /* Ready to go */
389  sc->status &= ~ATH_STAT_INVALID;
390 
391  return 0;
392 err_ah:
393  ath5k_hw_detach(sc->ah);
394 err_free_hwinfo:
395  free(sc->hwinfo);
396 err_free:
397  net80211_free(dev);
398 err_map:
399  iounmap(mem);
400 err:
401  return ret;
402 }
403 
404 static void ath5k_remove(struct pci_device *pdev)
405 {
406  struct net80211_device *dev = pci_get_drvdata(pdev);
407  struct ath5k_softc *sc = dev->priv;
408 
409  ath5k_detach(dev);
410  ath5k_hw_detach(sc->ah);
411  iounmap(sc->iobase);
412  free(sc->hwinfo);
414 }
415 
416 
417 /***********************\
418 * Driver Initialization *
419 \***********************/
420 
421 static int
423 {
424  struct ath5k_softc *sc = dev->priv;
425  struct ath5k_hw *ah = sc->ah;
426  int ret;
427 
428  /*
429  * Collect the channel list. The 802.11 layer
430  * is resposible for filtering this list based
431  * on settings like the phy mode and regulatory
432  * domain restrictions.
433  */
434  ret = ath5k_setup_bands(dev);
435  if (ret) {
436  DBG("ath5k: can't get channels\n");
437  goto err;
438  }
439 
440  /* NB: setup here so ath5k_rate_update is happy */
441  if (ah->ah_modes & AR5K_MODE_BIT_11A)
443  else
445 
446  /*
447  * Allocate tx+rx descriptors and populate the lists.
448  */
449  ret = ath5k_desc_alloc(sc);
450  if (ret) {
451  DBG("ath5k: can't allocate descriptors\n");
452  goto err;
453  }
454 
455  /*
456  * Allocate hardware transmit queues. Note that hw functions
457  * handle reseting these queues at the needed time.
458  */
460  if (ret) {
461  DBG("ath5k: can't setup xmit queue\n");
462  goto err_desc;
463  }
464 
465  sc->last_calib_ticks = currticks();
466 
467  ret = ath5k_eeprom_read_mac(ah, sc->hwinfo->hwaddr);
468  if (ret) {
469  DBG("ath5k: unable to read address from EEPROM: 0x%04x\n",
470  sc->pdev->device);
471  goto err_queues;
472  }
473 
474  memset(sc->bssidmask, 0xff, ETH_ALEN);
476 
477  ret = net80211_register(sc->dev, &ath5k_ops, sc->hwinfo);
478  if (ret) {
479  DBG("ath5k: can't register ieee80211 hw\n");
480  goto err_queues;
481  }
482 
483  return 0;
484 err_queues:
485  ath5k_txq_release(sc);
486 err_desc:
487  ath5k_desc_free(sc);
488 err:
489  return ret;
490 }
491 
492 static void
494 {
495  struct ath5k_softc *sc = dev->priv;
496 
498  ath5k_desc_free(sc);
499  ath5k_txq_release(sc);
500 }
501 
502 
503 
504 
505 /********************\
506 * Channel/mode setup *
507 \********************/
508 
509 /*
510  * Convert IEEE channel number to MHz frequency.
511  */
512 static inline short
513 ath5k_ieee2mhz(short chan)
514 {
515  if (chan < 14)
516  return 2407 + 5 * chan;
517  if (chan == 14)
518  return 2484;
519  if (chan < 27)
520  return 2212 + 20 * chan;
521  return 5000 + 5 * chan;
522 }
523 
524 static unsigned int
526  struct net80211_channel *channels,
527  unsigned int mode, unsigned int max)
528 {
529  unsigned int i, count, size, chfreq, freq, ch;
530 
531  if (!(ah->ah_modes & (1 << mode)))
532  return 0;
533 
534  switch (mode) {
535  case AR5K_MODE_11A:
536  case AR5K_MODE_11A_TURBO:
537  /* 1..220, but 2GHz frequencies are filtered by check_channel */
538  size = 220;
539  chfreq = CHANNEL_5GHZ;
540  break;
541  case AR5K_MODE_11B:
542  case AR5K_MODE_11G:
543  case AR5K_MODE_11G_TURBO:
544  size = 26;
545  chfreq = CHANNEL_2GHZ;
546  break;
547  default:
548  return 0;
549  }
550 
551  for (i = 0, count = 0; i < size && max > 0; i++) {
552  ch = i + 1 ;
553  freq = ath5k_ieee2mhz(ch);
554 
555  /* Check if channel is supported by the chipset */
556  if (!ath5k_channel_ok(ah, freq, chfreq))
557  continue;
558 
559  /* Write channel info and increment counter */
560  channels[count].center_freq = freq;
561  channels[count].maxpower = 0; /* use regulatory */
562  channels[count].band = (chfreq == CHANNEL_2GHZ) ?
564  switch (mode) {
565  case AR5K_MODE_11A:
566  case AR5K_MODE_11G:
567  channels[count].hw_value = chfreq | CHANNEL_OFDM;
568  break;
569  case AR5K_MODE_11A_TURBO:
570  case AR5K_MODE_11G_TURBO:
571  channels[count].hw_value = chfreq |
573  break;
574  case AR5K_MODE_11B:
575  channels[count].hw_value = CHANNEL_B;
576  }
577 
578  count++;
579  max--;
580  }
581 
582  return count;
583 }
584 
585 static int
587 {
588  struct ath5k_softc *sc = dev->priv;
589  struct ath5k_hw *ah = sc->ah;
590  int max_c, count_c = 0;
591  int i;
592  int band;
593 
594  max_c = sizeof(sc->hwinfo->channels) / sizeof(sc->hwinfo->channels[0]);
595 
596  /* 2GHz band */
598  /* G mode */
599  band = NET80211_BAND_2GHZ;
602 
603  for (i = 0; i < 12; i++)
604  sc->hwinfo->rates[band][i] = ath5k_rates[i].bitrate;
605  sc->hwinfo->nr_rates[band] = 12;
606 
607  sc->hwinfo->nr_channels =
609  AR5K_MODE_11G, max_c);
610  count_c = sc->hwinfo->nr_channels;
611  max_c -= count_c;
612  } else if (sc->ah->ah_capabilities.cap_mode & AR5K_MODE_BIT_11B) {
613  /* B mode */
614  band = NET80211_BAND_2GHZ;
617 
618  for (i = 0; i < 4; i++)
619  sc->hwinfo->rates[band][i] = ath5k_rates[i].bitrate;
620  sc->hwinfo->nr_rates[band] = 4;
621 
622  sc->hwinfo->nr_channels =
624  AR5K_MODE_11B, max_c);
625  count_c = sc->hwinfo->nr_channels;
626  max_c -= count_c;
627  }
628 
629  /* 5GHz band, A mode */
631  band = NET80211_BAND_5GHZ;
633  sc->hwinfo->modes |= NET80211_MODE_A;
634 
635  for (i = 0; i < 8; i++)
636  sc->hwinfo->rates[band][i] = ath5k_rates[i+4].bitrate;
637  sc->hwinfo->nr_rates[band] = 8;
638 
639  sc->hwinfo->nr_channels =
641  AR5K_MODE_11B, max_c);
642  count_c = sc->hwinfo->nr_channels;
643  max_c -= count_c;
644  }
645 
646  return 0;
647 }
648 
649 /*
650  * Set/change channels. If the channel is really being changed,
651  * it's done by reseting the chip. To accomplish this we must
652  * first cleanup any pending DMA, then restart stuff after a la
653  * ath5k_init.
654  */
655 static int
656 ath5k_chan_set(struct ath5k_softc *sc, struct net80211_channel *chan)
657 {
658  if (chan->center_freq != sc->curchan->center_freq ||
659  chan->hw_value != sc->curchan->hw_value) {
660  /*
661  * To switch channels clear any pending DMA operations;
662  * wait long enough for the RX fifo to drain, reset the
663  * hardware at the new frequency, and then re-enable
664  * the relevant bits of the h/w.
665  */
666  DBG2("ath5k: resetting for channel change (%d -> %d MHz)\n",
667  sc->curchan->center_freq, chan->center_freq);
668  return ath5k_reset(sc, chan);
669  }
670 
671  return 0;
672 }
673 
674 static void
675 ath5k_setcurmode(struct ath5k_softc *sc, unsigned int mode)
676 {
677  sc->curmode = mode;
678 
679  if (mode == AR5K_MODE_11A) {
681  } else {
683  }
684 }
685 
686 static void
688 {
689  struct ath5k_hw *ah = sc->ah;
690  u32 rfilt;
691 
692  /* configure rx filter */
693  rfilt = sc->filter_flags;
694  ath5k_hw_set_rx_filter(ah, rfilt);
695 
698 
699  /* configure operational mode */
701 
703 }
704 
705 static inline int
707 {
708  int i;
709 
710  for (i = 0; i < ATH5K_NR_RATES; i++) {
711  if (ath5k_rates[i].hw_code == hw_rix)
712  return ath5k_rates[i].bitrate;
713  }
714 
715  DBG("ath5k: invalid rix %02x\n", hw_rix);
716  return 10; /* use lowest rate */
717 }
718 
720 {
721  int i;
722 
723  for (i = 0; i < ATH5K_NR_RATES; i++) {
724  if (ath5k_rates[i].bitrate == bitrate)
725  return ath5k_rates[i].hw_code;
726  }
727 
728  DBG("ath5k: invalid bitrate %d\n", bitrate);
729  return ATH5K_RATE_CODE_1M; /* use lowest rate */
730 }
731 
732 /***************\
733 * Buffers setup *
734 \***************/
735 
736 static struct io_buffer *
737 ath5k_rx_iob_alloc(struct ath5k_softc *sc, u32 *iob_addr)
738 {
739  struct io_buffer *iob;
740  unsigned int off;
741 
742  /*
743  * Allocate buffer with headroom_needed space for the
744  * fake physical layer header at the start.
745  */
746  iob = alloc_iob(sc->rxbufsize + sc->cachelsz - 1);
747 
748  if (!iob) {
749  DBG("ath5k: can't alloc iobuf of size %d\n",
750  sc->rxbufsize + sc->cachelsz - 1);
751  return NULL;
752  }
753 
754  *iob_addr = virt_to_bus(iob->data);
755 
756  /*
757  * Cache-line-align. This is important (for the
758  * 5210 at least) as not doing so causes bogus data
759  * in rx'd frames.
760  */
761  off = *iob_addr % sc->cachelsz;
762  if (off != 0) {
763  iob_reserve(iob, sc->cachelsz - off);
764  *iob_addr += sc->cachelsz - off;
765  }
766 
767  return iob;
768 }
769 
770 static int
771 ath5k_rxbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
772 {
773  struct ath5k_hw *ah = sc->ah;
774  struct io_buffer *iob = bf->iob;
775  struct ath5k_desc *ds;
776 
777  if (!iob) {
778  iob = ath5k_rx_iob_alloc(sc, &bf->iobaddr);
779  if (!iob)
780  return -ENOMEM;
781  bf->iob = iob;
782  }
783 
784  /*
785  * Setup descriptors. For receive we always terminate
786  * the descriptor list with a self-linked entry so we'll
787  * not get overrun under high load (as can happen with a
788  * 5212 when ANI processing enables PHY error frames).
789  *
790  * To insure the last descriptor is self-linked we create
791  * each descriptor as self-linked and add it to the end. As
792  * each additional descriptor is added the previous self-linked
793  * entry is ``fixed'' naturally. This should be safe even
794  * if DMA is happening. When processing RX interrupts we
795  * never remove/process the last, self-linked, entry on the
796  * descriptor list. This insures the hardware always has
797  * someplace to write a new frame.
798  */
799  ds = bf->desc;
800  ds->ds_link = bf->daddr; /* link to self */
801  ds->ds_data = bf->iobaddr;
802  if (ah->ah_setup_rx_desc(ah, ds,
803  iob_tailroom(iob), /* buffer size */
804  0) != 0) {
805  DBG("ath5k: error setting up RX descriptor for %zd bytes\n", iob_tailroom(iob));
806  return -EINVAL;
807  }
808 
809  if (sc->rxlink != NULL)
810  *sc->rxlink = bf->daddr;
811  sc->rxlink = &ds->ds_link;
812  return 0;
813 }
814 
815 static int
816 ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
817 {
818  struct ath5k_hw *ah = sc->ah;
819  struct ath5k_txq *txq = &sc->txq;
820  struct ath5k_desc *ds = bf->desc;
821  struct io_buffer *iob = bf->iob;
822  unsigned int pktlen, flags;
823  int ret;
824  u16 duration = 0;
825  u16 cts_rate = 0;
826 
828  bf->iobaddr = virt_to_bus(iob->data);
829  pktlen = iob_len(iob);
830 
831  /* FIXME: If we are in g mode and rate is a CCK rate
832  * subtract ah->ah_txpower.txp_cck_ofdm_pwr_delta
833  * from tx power (value is in dB units already) */
835  struct net80211_device *dev = sc->dev;
836 
838  cts_rate = sc->hw_rtscts_rate;
839  duration = net80211_cts_duration(dev, pktlen);
840  }
841  ret = ah->ah_setup_tx_desc(ah, ds, pktlen,
844  sc->hw_rate, ATH5K_RETRIES,
846  cts_rate, duration);
847  if (ret)
848  return ret;
849 
850  ds->ds_link = 0;
851  ds->ds_data = bf->iobaddr;
852 
853  list_add_tail(&bf->list, &txq->q);
854  if (txq->link == NULL) /* is this first packet? */
855  ath5k_hw_set_txdp(ah, txq->qnum, bf->daddr);
856  else /* no, so only link it */
857  *txq->link = bf->daddr;
858 
859  txq->link = &ds->ds_link;
861  mb();
862 
863  return 0;
864 }
865 
866 /*******************\
867 * Descriptors setup *
868 \*******************/
869 
870 static int
872 {
873  struct ath5k_desc *ds;
874  struct ath5k_buf *bf;
875  u32 da;
876  unsigned int i;
877  int ret;
878 
879  /* allocate descriptors */
880  sc->desc_len = sizeof(struct ath5k_desc) * (ATH_TXBUF + ATH_RXBUF + 1);
882  if (sc->desc == NULL) {
883  DBG("ath5k: can't allocate descriptors\n");
884  ret = -ENOMEM;
885  goto err;
886  }
887  memset(sc->desc, 0, sc->desc_len);
888  sc->desc_daddr = virt_to_bus(sc->desc);
889 
890  ds = sc->desc;
891  da = sc->desc_daddr;
892 
893  bf = calloc(ATH_TXBUF + ATH_RXBUF + 1, sizeof(struct ath5k_buf));
894  if (bf == NULL) {
895  DBG("ath5k: can't allocate buffer pointers\n");
896  ret = -ENOMEM;
897  goto err_free;
898  }
899  sc->bufptr = bf;
900 
901  INIT_LIST_HEAD(&sc->rxbuf);
902  for (i = 0; i < ATH_RXBUF; i++, bf++, ds++, da += sizeof(*ds)) {
903  bf->desc = ds;
904  bf->daddr = da;
905  list_add_tail(&bf->list, &sc->rxbuf);
906  }
907 
908  INIT_LIST_HEAD(&sc->txbuf);
909  sc->txbuf_len = ATH_TXBUF;
910  for (i = 0; i < ATH_TXBUF; i++, bf++, ds++, da += sizeof(*ds)) {
911  bf->desc = ds;
912  bf->daddr = da;
913  list_add_tail(&bf->list, &sc->txbuf);
914  }
915 
916  return 0;
917 
918 err_free:
919  free_phys(sc->desc, sc->desc_len);
920 err:
921  sc->desc = NULL;
922  return ret;
923 }
924 
925 static void
927 {
928  struct ath5k_buf *bf;
929 
930  list_for_each_entry(bf, &sc->txbuf, list)
931  ath5k_txbuf_free(sc, bf);
932  list_for_each_entry(bf, &sc->rxbuf, list)
933  ath5k_rxbuf_free(sc, bf);
934 
935  /* Free memory associated with all descriptors */
936  free_phys(sc->desc, sc->desc_len);
937 
938  free(sc->bufptr);
939  sc->bufptr = NULL;
940 }
941 
942 
943 
944 
945 
946 /**************\
947 * Queues setup *
948 \**************/
949 
950 static int
951 ath5k_txq_setup(struct ath5k_softc *sc, int qtype, int subtype)
952 {
953  struct ath5k_hw *ah = sc->ah;
954  struct ath5k_txq *txq;
955  struct ath5k_txq_info qi = {
956  .tqi_subtype = subtype,
957  .tqi_aifs = AR5K_TXQ_USEDEFAULT,
958  .tqi_cw_min = AR5K_TXQ_USEDEFAULT,
959  .tqi_cw_max = AR5K_TXQ_USEDEFAULT
960  };
961  int qnum;
962 
963  /*
964  * Enable interrupts only for EOL and DESC conditions.
965  * We mark tx descriptors to receive a DESC interrupt
966  * when a tx queue gets deep; otherwise waiting for the
967  * EOL to reap descriptors. Note that this is done to
968  * reduce interrupt load and this only defers reaping
969  * descriptors, never transmitting frames. Aside from
970  * reducing interrupts this also permits more concurrency.
971  * The only potential downside is if the tx queue backs
972  * up in which case the top half of the kernel may backup
973  * due to a lack of tx descriptors.
974  */
977  qnum = ath5k_hw_setup_tx_queue(ah, qtype, &qi);
978  if (qnum < 0) {
979  DBG("ath5k: can't set up a TX queue\n");
980  return -EIO;
981  }
982 
983  txq = &sc->txq;
984  if (!txq->setup) {
985  txq->qnum = qnum;
986  txq->link = NULL;
987  INIT_LIST_HEAD(&txq->q);
988  txq->setup = 1;
989  }
990  return 0;
991 }
992 
993 static void
994 ath5k_txq_drainq(struct ath5k_softc *sc, struct ath5k_txq *txq)
995 {
996  struct ath5k_buf *bf, *bf0;
997 
998  list_for_each_entry_safe(bf, bf0, &txq->q, list) {
999  ath5k_txbuf_free(sc, bf);
1000 
1001  list_del(&bf->list);
1002  list_add_tail(&bf->list, &sc->txbuf);
1003  sc->txbuf_len++;
1004  }
1005  txq->link = NULL;
1006 }
1007 
1008 /*
1009  * Drain the transmit queues and reclaim resources.
1010  */
1011 static void
1013 {
1014  struct ath5k_hw *ah = sc->ah;
1015 
1016  if (!(sc->status & ATH_STAT_INVALID)) {
1017  /* don't touch the hardware if marked invalid */
1018  if (sc->txq.setup) {
1020  DBG("ath5k: txq [%d] %x, link %p\n",
1021  sc->txq.qnum,
1022  ath5k_hw_get_txdp(ah, sc->txq.qnum),
1023  sc->txq.link);
1024  }
1025  }
1026 
1027  if (sc->txq.setup)
1028  ath5k_txq_drainq(sc, &sc->txq);
1029 }
1030 
1031 static void
1033 {
1034  if (sc->txq.setup) {
1036  sc->txq.setup = 0;
1037  }
1038 }
1039 
1040 
1041 
1042 
1043 /*************\
1044 * RX Handling *
1045 \*************/
1046 
1047 /*
1048  * Enable the receive h/w following a reset.
1049  */
1050 static int
1052 {
1053  struct ath5k_hw *ah = sc->ah;
1054  struct ath5k_buf *bf;
1055  int ret;
1056 
1058  if (sc->rxbufsize % sc->cachelsz != 0)
1059  sc->rxbufsize += sc->cachelsz - (sc->rxbufsize % sc->cachelsz);
1060 
1061  sc->rxlink = NULL;
1062 
1063  list_for_each_entry(bf, &sc->rxbuf, list) {
1064  ret = ath5k_rxbuf_setup(sc, bf);
1065  if (ret != 0)
1066  return ret;
1067  }
1068 
1069  bf = list_entry(sc->rxbuf.next, struct ath5k_buf, list);
1070 
1071  ath5k_hw_set_rxdp(ah, bf->daddr);
1072  ath5k_hw_start_rx_dma(ah); /* enable recv descriptors */
1073  ath5k_mode_setup(sc); /* set filters, etc. */
1074  ath5k_hw_start_rx_pcu(ah); /* re-enable PCU/DMA engine */
1075 
1076  return 0;
1077 }
1078 
1079 /*
1080  * Disable the receive h/w in preparation for a reset.
1081  */
1082 static void
1084 {
1085  struct ath5k_hw *ah = sc->ah;
1086 
1087  ath5k_hw_stop_rx_pcu(ah); /* disable PCU */
1088  ath5k_hw_set_rx_filter(ah, 0); /* clear recv filter */
1089  ath5k_hw_stop_rx_dma(ah); /* disable DMA engine */
1090 
1091  sc->rxlink = NULL; /* just in case */
1092 }
1093 
1094 static void
1096 {
1097  struct ath5k_rx_status rs;
1098  struct io_buffer *iob, *next_iob;
1099  u32 next_iob_addr;
1100  struct ath5k_buf *bf, *bf_last;
1101  struct ath5k_desc *ds;
1102  int ret;
1103 
1104  memset(&rs, 0, sizeof(rs));
1105 
1106  if (list_empty(&sc->rxbuf)) {
1107  DBG("ath5k: empty rx buf pool\n");
1108  return;
1109  }
1110 
1111  bf_last = list_entry(sc->rxbuf.prev, struct ath5k_buf, list);
1112 
1113  do {
1114  bf = list_entry(sc->rxbuf.next, struct ath5k_buf, list);
1115  assert(bf->iob != NULL);
1116  iob = bf->iob;
1117  ds = bf->desc;
1118 
1119  /*
1120  * last buffer must not be freed to ensure proper hardware
1121  * function. When the hardware finishes also a packet next to
1122  * it, we are sure, it doesn't use it anymore and we can go on.
1123  */
1124  if (bf_last == bf)
1125  bf->flags |= 1;
1126  if (bf->flags) {
1127  struct ath5k_buf *bf_next = list_entry(bf->list.next,
1128  struct ath5k_buf, list);
1129  ret = sc->ah->ah_proc_rx_desc(sc->ah, bf_next->desc,
1130  &rs);
1131  if (ret)
1132  break;
1133  bf->flags &= ~1;
1134  /* skip the overwritten one (even status is martian) */
1135  goto next;
1136  }
1137 
1138  ret = sc->ah->ah_proc_rx_desc(sc->ah, ds, &rs);
1139  if (ret) {
1140  if (ret != -EINPROGRESS) {
1141  DBG("ath5k: error in processing rx desc: %s\n",
1142  strerror(ret));
1143  net80211_rx_err(sc->dev, NULL, -ret);
1144  } else {
1145  /* normal return, reached end of
1146  available descriptors */
1147  }
1148  return;
1149  }
1150 
1151  if (rs.rs_more) {
1152  DBG("ath5k: unsupported fragmented rx\n");
1153  goto next;
1154  }
1155 
1156  if (rs.rs_status) {
1157  if (rs.rs_status & AR5K_RXERR_PHY) {
1158  /* These are uncommon, and may indicate a real problem. */
1159  net80211_rx_err(sc->dev, NULL, EIO);
1160  goto next;
1161  }
1162  if (rs.rs_status & AR5K_RXERR_CRC) {
1163  /* These occur *all the time*. */
1164  goto next;
1165  }
1166  if (rs.rs_status & AR5K_RXERR_DECRYPT) {
1167  /*
1168  * Decrypt error. If the error occurred
1169  * because there was no hardware key, then
1170  * let the frame through so the upper layers
1171  * can process it. This is necessary for 5210
1172  * parts which have no way to setup a ``clear''
1173  * key cache entry.
1174  *
1175  * XXX do key cache faulting
1176  */
1177  if (rs.rs_keyix == AR5K_RXKEYIX_INVALID &&
1178  !(rs.rs_status & AR5K_RXERR_CRC))
1179  goto accept;
1180  }
1181 
1182  /* any other error, unhandled */
1183  DBG("ath5k: packet rx status %x\n", rs.rs_status);
1184  goto next;
1185  }
1186 accept:
1187  next_iob = ath5k_rx_iob_alloc(sc, &next_iob_addr);
1188 
1189  /*
1190  * If we can't replace bf->iob with a new iob under memory
1191  * pressure, just skip this packet
1192  */
1193  if (!next_iob) {
1194  DBG("ath5k: dropping packet under memory pressure\n");
1195  goto next;
1196  }
1197 
1198  iob_put(iob, rs.rs_datalen);
1199 
1200  /* The MAC header is padded to have 32-bit boundary if the
1201  * packet payload is non-zero. However, iPXE only
1202  * supports standard 802.11 packets with 24-byte
1203  * header, so no padding correction should be needed.
1204  */
1205 
1206  DBG2("ath5k: rx %d bytes, signal %d\n", rs.rs_datalen,
1207  rs.rs_rssi);
1208 
1209  net80211_rx(sc->dev, iob, rs.rs_rssi,
1211 
1212  bf->iob = next_iob;
1213  bf->iobaddr = next_iob_addr;
1214 next:
1215  list_del(&bf->list);
1216  list_add_tail(&bf->list, &sc->rxbuf);
1217  } while (ath5k_rxbuf_setup(sc, bf) == 0);
1218 }
1219 
1220 
1221 
1222 
1223 /*************\
1224 * TX Handling *
1225 \*************/
1226 
1227 static void
1228 ath5k_tx_processq(struct ath5k_softc *sc, struct ath5k_txq *txq)
1229 {
1230  struct ath5k_tx_status ts;
1231  struct ath5k_buf *bf, *bf0;
1232  struct ath5k_desc *ds;
1233  struct io_buffer *iob;
1234  int ret;
1235 
1236  memset(&ts, 0, sizeof(ts));
1237 
1238  list_for_each_entry_safe(bf, bf0, &txq->q, list) {
1239  ds = bf->desc;
1240 
1241  ret = sc->ah->ah_proc_tx_desc(sc->ah, ds, &ts);
1242  if (ret) {
1243  if (ret != -EINPROGRESS) {
1244  DBG("ath5k: error in processing tx desc: %s\n",
1245  strerror(ret));
1246  } else {
1247  /* normal return, reached end of tx completions */
1248  }
1249  break;
1250  }
1251 
1252  iob = bf->iob;
1253  bf->iob = NULL;
1254 
1255  DBG2("ath5k: tx %zd bytes complete, %d retries\n",
1256  iob_len(iob), ts.ts_retry[0]);
1257 
1258  net80211_tx_complete(sc->dev, iob, ts.ts_retry[0],
1259  ts.ts_status ? EIO : 0);
1260 
1261  list_del(&bf->list);
1262  list_add_tail(&bf->list, &sc->txbuf);
1263  sc->txbuf_len++;
1264  }
1265 
1266  if (list_empty(&txq->q))
1267  txq->link = NULL;
1268 }
1269 
1270 static void
1272 {
1273  ath5k_tx_processq(sc, &sc->txq);
1274 }
1275 
1276 
1277 /********************\
1278 * Interrupt handling *
1279 \********************/
1280 
1281 static void
1282 ath5k_irq(struct net80211_device *dev, int enable)
1283 {
1284  struct ath5k_softc *sc = dev->priv;
1285  struct ath5k_hw *ah = sc->ah;
1286 
1287  sc->irq_ena = enable;
1288  ah->ah_ier = enable ? AR5K_IER_ENABLE : AR5K_IER_DISABLE;
1289 
1290  ath5k_hw_reg_write(ah, ah->ah_ier, AR5K_IER);
1291  ath5k_hw_set_imr(ah, sc->imask);
1292 }
1293 
1294 static int
1296 {
1297  struct ath5k_hw *ah = sc->ah;
1298  int ret, i;
1299 
1300  /*
1301  * Stop anything previously setup. This is safe
1302  * no matter this is the first time through or not.
1303  */
1304  ath5k_stop_hw(sc);
1305 
1306  /*
1307  * The basic interface to setting the hardware in a good
1308  * state is ``reset''. On return the hardware is known to
1309  * be powered up and with interrupts disabled. This must
1310  * be followed by initialization of the appropriate bits
1311  * and then setup of the interrupt mask.
1312  */
1313  sc->curchan = sc->dev->channels + sc->dev->channel;
1314  sc->curband = sc->curchan->band;
1318  ret = ath5k_reset(sc, NULL);
1319  if (ret)
1320  goto done;
1321 
1323 
1324  /*
1325  * Reset the key cache since some parts do not reset the
1326  * contents on initial power up or resume from suspend.
1327  */
1328  for (i = 0; i < AR5K_KEYTABLE_SIZE; i++)
1329  ath5k_hw_reset_key(ah, i);
1330 
1331  /* Set ack to be sent at low bit-rates */
1333 
1334  ret = 0;
1335 done:
1336  mb();
1337  return ret;
1338 }
1339 
1340 static int
1342 {
1343  struct ath5k_hw *ah = sc->ah;
1344 
1345  /*
1346  * Shutdown the hardware and driver:
1347  * stop output from above
1348  * disable interrupts
1349  * turn off timers
1350  * turn off the radio
1351  * clear transmit machinery
1352  * clear receive machinery
1353  * drain and release tx queues
1354  * reclaim beacon resources
1355  * power down hardware
1356  *
1357  * Note that some of this work is not possible if the
1358  * hardware is gone (invalid).
1359  */
1360 
1361  if (!(sc->status & ATH_STAT_INVALID)) {
1362  ath5k_hw_set_imr(ah, 0);
1363  }
1364  ath5k_txq_cleanup(sc);
1365  if (!(sc->status & ATH_STAT_INVALID)) {
1366  ath5k_rx_stop(sc);
1368  } else
1369  sc->rxlink = NULL;
1370 
1371  ath5k_rfkill_hw_stop(sc->ah);
1372 
1373  return 0;
1374 }
1375 
1376 static void
1378 {
1379  struct ath5k_softc *sc = dev->priv;
1380  struct ath5k_hw *ah = sc->ah;
1381  enum ath5k_int status;
1382  unsigned int counter = 1000;
1383 
1384  if (currticks() - sc->last_calib_ticks >
1386  ath5k_calibrate(sc);
1387  sc->last_calib_ticks = currticks();
1388  }
1389 
1390  if ((sc->status & ATH_STAT_INVALID) ||
1391  (sc->irq_ena && !ath5k_hw_is_intr_pending(ah)))
1392  return;
1393 
1394  do {
1395  ath5k_hw_get_isr(ah, &status); /* NB: clears IRQ too */
1396  DBGP("ath5k: status %#x/%#x\n", status, sc->imask);
1397  if (status & AR5K_INT_FATAL) {
1398  /*
1399  * Fatal errors are unrecoverable.
1400  * Typically these are caused by DMA errors.
1401  */
1402  DBG("ath5k: fatal error, resetting\n");
1403  ath5k_reset_wake(sc);
1404  } else if (status & AR5K_INT_RXORN) {
1405  DBG("ath5k: rx overrun, resetting\n");
1406  ath5k_reset_wake(sc);
1407  } else {
1408  if (status & AR5K_INT_RXEOL) {
1409  /*
1410  * NB: the hardware should re-read the link when
1411  * RXE bit is written, but it doesn't work at
1412  * least on older hardware revs.
1413  */
1414  DBG("ath5k: rx EOL\n");
1415  sc->rxlink = NULL;
1416  }
1417  if (status & AR5K_INT_TXURN) {
1418  /* bump tx trigger level */
1419  DBG("ath5k: tx underrun\n");
1421  }
1423  ath5k_handle_rx(sc);
1426  ath5k_handle_tx(sc);
1427  }
1428  } while (ath5k_hw_is_intr_pending(ah) && counter-- > 0);
1429 
1430  if (!counter)
1431  DBG("ath5k: too many interrupts, giving up for now\n");
1432 }
1433 
1434 /*
1435  * Periodically recalibrate the PHY to account
1436  * for temperature/environment changes.
1437  */
1438 static void
1440 {
1441  struct ath5k_hw *ah = sc->ah;
1442 
1444  /*
1445  * Rfgain is out of bounds, reset the chip
1446  * to load new gain values.
1447  */
1448  DBG("ath5k: resetting for calibration\n");
1449  ath5k_reset_wake(sc);
1450  }
1451  if (ath5k_hw_phy_calibrate(ah, sc->curchan))
1452  DBG("ath5k: calibration of channel %d failed\n",
1453  sc->curchan->channel_nr);
1454 }
1455 
1456 
1457 /********************\
1458 * Net80211 functions *
1459 \********************/
1460 
1461 static int
1462 ath5k_tx(struct net80211_device *dev, struct io_buffer *iob)
1463 {
1464  struct ath5k_softc *sc = dev->priv;
1465  struct ath5k_buf *bf;
1466  int rc;
1467 
1468  /*
1469  * The hardware expects the header padded to 4 byte boundaries.
1470  * iPXE only ever sends 24-byte headers, so no action necessary.
1471  */
1472 
1473  if (list_empty(&sc->txbuf)) {
1474  DBG("ath5k: dropping packet because no tx bufs available\n");
1475  return -ENOBUFS;
1476  }
1477 
1478  bf = list_entry(sc->txbuf.next, struct ath5k_buf, list);
1479  list_del(&bf->list);
1480  sc->txbuf_len--;
1481 
1482  bf->iob = iob;
1483 
1484  if ((rc = ath5k_txbuf_setup(sc, bf)) != 0) {
1485  bf->iob = NULL;
1486  list_add_tail(&bf->list, &sc->txbuf);
1487  sc->txbuf_len++;
1488  return rc;
1489  }
1490  return 0;
1491 }
1492 
1493 /*
1494  * Reset the hardware. If chan is not NULL, then also pause rx/tx
1495  * and change to the given channel.
1496  */
1497 static int
1498 ath5k_reset(struct ath5k_softc *sc, struct net80211_channel *chan)
1499 {
1500  struct ath5k_hw *ah = sc->ah;
1501  int ret;
1502 
1503  if (chan) {
1504  ath5k_hw_set_imr(ah, 0);
1505  ath5k_txq_cleanup(sc);
1506  ath5k_rx_stop(sc);
1507 
1508  sc->curchan = chan;
1509  sc->curband = chan->band;
1510  }
1511 
1512  ret = ath5k_hw_reset(ah, sc->curchan, 1);
1513  if (ret) {
1514  DBG("ath5k: can't reset hardware: %s\n", strerror(ret));
1515  return ret;
1516  }
1517 
1518  ret = ath5k_rx_start(sc);
1519  if (ret) {
1520  DBG("ath5k: can't start rx logic: %s\n", strerror(ret));
1521  return ret;
1522  }
1523 
1524  /*
1525  * Change channels and update the h/w rate map if we're switching;
1526  * e.g. 11a to 11b/g.
1527  *
1528  * We may be doing a reset in response to an ioctl that changes the
1529  * channel so update any state that might change as a result.
1530  *
1531  * XXX needed?
1532  */
1533 /* ath5k_chan_change(sc, c); */
1534 
1535  /* Reenable interrupts if necessary */
1536  ath5k_irq(sc->dev, sc->irq_ena);
1537 
1538  return 0;
1539 }
1540 
1541 static int ath5k_reset_wake(struct ath5k_softc *sc)
1542 {
1543  return ath5k_reset(sc, sc->curchan);
1544 }
1545 
1546 static int ath5k_start(struct net80211_device *dev)
1547 {
1548  struct ath5k_softc *sc = dev->priv;
1549  int ret;
1550 
1551  if ((ret = ath5k_init(sc)) != 0)
1552  return ret;
1553 
1554  sc->assoc = 0;
1557 
1558  return 0;
1559 }
1560 
1561 static void ath5k_stop(struct net80211_device *dev)
1562 {
1563  struct ath5k_softc *sc = dev->priv;
1564  u8 mac[ETH_ALEN] = {};
1565 
1566  ath5k_hw_set_lladdr(sc->ah, mac);
1567 
1568  ath5k_stop_hw(sc);
1569 }
1570 
1571 static int
1572 ath5k_config(struct net80211_device *dev, int changed)
1573 {
1574  struct ath5k_softc *sc = dev->priv;
1575  struct ath5k_hw *ah = sc->ah;
1576  struct net80211_channel *chan = &dev->channels[dev->channel];
1577  int ret;
1578 
1579  if (changed & NET80211_CFG_CHANNEL) {
1580  sc->power_level = chan->maxpower;
1581  if ((ret = ath5k_chan_set(sc, chan)) != 0)
1582  return ret;
1583  }
1584 
1585  if ((changed & NET80211_CFG_RATE) ||
1586  (changed & NET80211_CFG_PHY_PARAMS)) {
1587  int spmbl = ATH5K_SPMBL_NO;
1588  u16 rate = dev->rates[dev->rate];
1589  u16 slowrate = dev->rates[dev->rtscts_rate];
1590  int i;
1591 
1593  spmbl = ATH5K_SPMBL_YES;
1594 
1595  for (i = 0; i < ATH5K_NR_RATES; i++) {
1596  if (ath5k_rates[i].bitrate == rate &&
1597  (ath5k_rates[i].short_pmbl & spmbl))
1598  sc->hw_rate = ath5k_rates[i].hw_code;
1599 
1600  if (ath5k_rates[i].bitrate == slowrate &&
1601  (ath5k_rates[i].short_pmbl & spmbl))
1602  sc->hw_rtscts_rate = ath5k_rates[i].hw_code;
1603  }
1604  }
1605 
1606  if (changed & NET80211_CFG_ASSOC) {
1607  sc->assoc = !!(dev->state & NET80211_ASSOCIATED);
1608  if (sc->assoc) {
1609  memcpy(ah->ah_bssid, dev->bssid, ETH_ALEN);
1610  } else {
1611  memset(ah->ah_bssid, 0xff, ETH_ALEN);
1612  }
1613  ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
1614  }
1615 
1616  return 0;
1617 }
1618 
1619 /*
1620  * o always accept unicast, broadcast, and multicast traffic
1621  * o multicast traffic for all BSSIDs will be enabled if mac80211
1622  * says it should be
1623  * o maintain current state of phy ofdm or phy cck error reception.
1624  * If the hardware detects any of these type of errors then
1625  * ath5k_hw_get_rx_filter() will pass to us the respective
1626  * hardware filters to be able to receive these type of frames.
1627  * o probe request frames are accepted only when operating in
1628  * hostap, adhoc, or monitor modes
1629  * o enable promiscuous mode according to the interface state
1630  * o accept beacons:
1631  * - when operating in adhoc mode so the 802.11 layer creates
1632  * node table entries for peers,
1633  * - when operating in station mode for collecting rssi data when
1634  * the station is otherwise quiet, or
1635  * - when scanning
1636  */
1637 static void ath5k_configure_filter(struct ath5k_softc *sc)
1638 {
1639  struct ath5k_hw *ah = sc->ah;
1640  u32 mfilt[2], rfilt;
1641 
1642  /* Enable all multicast */
1643  mfilt[0] = ~0;
1644  mfilt[1] = ~0;
1645 
1646  /* Enable data frames and beacons */
1649 
1650  /* Set filters */
1651  ath5k_hw_set_rx_filter(ah, rfilt);
1652 
1653  /* Set multicast bits */
1654  ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
1655 
1656  /* Set the cached hw filter flags, this will alter actually
1657  * be set in HW */
1658  sc->filter_flags = rfilt;
1659 }
struct ath5k_txq txq
Definition: base.h:125
uint16_t u16
Definition: stdint.h:22
#define AR5K_RXERR_PHY
Definition: ath5k.h:582
struct ath5k_capabilities ah_capabilities
Definition: ath5k.h:1009
static void ath5k_rxbuf_free(struct ath5k_softc *sc __unused, struct ath5k_buf *bf)
Definition: ath5k.c:189
#define EINVAL
Invalid argument.
Definition: errno.h:429
unsigned long membase
Memory base.
Definition: pci.h:220
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1986
static void ath5k_remove(struct pci_device *pdev)
Definition: ath5k.c:404
#define PCI_CACHE_LINE_SIZE
PCI cache line size.
Definition: pci.h:48
unsigned int curmode
Definition: base.h:112
int modes
A bitwise OR of the 802.11x modes supported by this device.
Definition: net80211.h:450
void net80211_free(struct net80211_device *dev)
Free 802.11 device.
Definition: net80211.c:839
struct net80211_channel channels[NET80211_MAX_CHANNELS]
List of RF channels supported by the card.
Definition: net80211.h:498
static void ath5k_txq_cleanup(struct ath5k_softc *sc)
Definition: ath5k.c:1012
#define ath5k_hw_hasbssidmask(_ah)
Definition: base.h:141
#define iob_put(iobuf, len)
Definition: iobuf.h:125
#define ATH_TXBUF
Definition: base.h:54
#define TICKS_PER_SEC
Number of ticks per second.
Definition: timer.h:16
int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
ath5k_hw_stop_rx_dma - Stop DMA receive
Definition: ath5k_dma.c:66
A PCI driver.
Definition: pci.h:252
#define max(x, y)
Definition: ath.h:41
#define ATH5K_SPMBL_BOTH
Definition: ath5k.c:91
static struct io_buffer * ath5k_rx_iob_alloc(struct ath5k_softc *sc, u32 *iob_addr)
Definition: ath5k.c:737
int(* ah_proc_tx_desc)(struct ath5k_hw *, struct ath5k_desc *, struct ath5k_tx_status *)
Definition: ath5k.h:1062
int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
Definition: ath5k_pcu.c:497
u8 channel
The channel currently in use, as an index into the channels array.
Definition: net80211.h:812
#define ATH5K_CALIB_INTERVAL
Definition: ath5k.c:59
void __asmcall int val
Definition: setjmp.h:12
#define ATH_RXBUF
Definition: base.h:53
#define ATH5K_RATE_CODE_12M
Definition: ath5k.h:715
#define ATH5K_RATE_CODE_36M
Definition: ath5k.h:718
#define PCI_LATENCY_TIMER
PCI latency timer.
Definition: pci.h:51
struct list_head * next
Next list entry.
Definition: list.h:21
#define ATH5K_RATE_CODE_11M
Definition: ath5k.h:711
enum net80211_hw_info::@641 flags
A set of flags indicating peculiarities of this device.
static int ath5k_config(struct net80211_device *dev, int changed)
Definition: ath5k.c:1572
static void ath5k_detach(struct net80211_device *dev)
Definition: ath5k.c:493
#define ATH5K_RATE_CODE_2M
Definition: ath5k.h:709
u8 ts_retry[4]
Definition: ath5k.h:423
static int ath5k_hw_rix_to_bitrate(int hw_rix)
Definition: ath5k.c:706
int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
ath5k_hw_set_lladdr - Set station id
Definition: ath5k_pcu.c:201
#define ATH_STAT_INVALID
Definition: base.h:105
int ath5k_hw_phy_disable(struct ath5k_hw *ah)
Definition: ath5k_phy.c:1359
unsigned long driver_data
Arbitrary driver data.
Definition: pci.h:183
void net80211_rx_err(struct net80211_device *dev, struct io_buffer *iob, int rc)
Indicate an error in receiving a packet.
Definition: net80211.c:2789
#define AR5K_KEYTABLE_SIZE
Definition: reg.h:1853
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:153
struct list_head rxbuf
Definition: base.h:120
uint16_t mode
Acceleration mode.
Definition: ena.h:26
struct pci_device_id * ids
PCI ID table.
Definition: pci.h:254
void net80211_rx(struct net80211_device *dev, struct io_buffer *iob, int signal, u16 rate)
Handle receipt of 802.11 frame.
Definition: net80211.c:2690
uint32_t type
Operating system type.
Definition: ena.h:12
u8 rtscts_rate
The rate to use for RTS/CTS transmissions.
Definition: net80211.h:831
static int ath5k_txq_setup(struct ath5k_softc *sc, int qtype, int subtype)
Definition: ath5k.c:951
void ath5k_rfkill_hw_stop(struct ath5k_hw *ah)
Definition: ath5k_rfkill.c:98
uint16_t size
Buffer size.
Definition: dwmac.h:14
void net80211_unregister(struct net80211_device *dev)
Unregister 802.11 device from network stack.
Definition: net80211.c:825
static void ath5k_handle_tx(struct ath5k_softc *sc)
Definition: ath5k.c:1271
#define AR5K_RXERR_CRC
Definition: ath5k.h:581
#define AR5K_TXQ_USEDEFAULT
Definition: ath5k.h:250
static void ath5k_poll(struct net80211_device *dev)
Definition: ath5k.c:1377
int setup
Definition: base.h:78
int ath5k_hw_set_txdp(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
ath5k_hw_set_txdp - Set TX Descriptor's address for a specific queue
Definition: ath5k_dma.c:293
#define ATH5K_NR_RATES
Definition: ath5k.c:116
u32 ath5k_hw_get_txdp(struct ath5k_hw *ah, unsigned int queue)
ath5k_hw_get_txdp - Get TX Descriptor's address for a specific queue
Definition: ath5k_dma.c:262
iPXE timers
static int ath5k_reset_wake(struct ath5k_softc *sc)
Definition: ath5k.c:1541
static int ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
Definition: ath5k.c:816
unsigned signal_max
Maximum signal in arbitrary cases.
Definition: net80211.h:495
void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, int high)
ath5k_hw_set_ack_bitrate - set bitrate for ACKs
Definition: ath5k_pcu.c:96
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
#define ATH5K_RATE_CODE_6M
Definition: ath5k.h:713
u16 ah_phy_revision
Definition: ath5k.h:972
int irq_ena
Definition: base.h:96
static struct pci_device_id ath5k_nics[]
Definition: ath5k.c:68
int assoc
Definition: base.h:135
void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
ath5k_hw_set_associd - Set BSSID for association
Definition: ath5k_pcu.c:229
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:241
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:131
u16 ah_radio_5ghz_revision
Definition: ath5k.h:973
void ath5k_hw_start_rx_dma(struct ath5k_hw *ah)
ath5k_hw_start_rx_dma - Start DMA receive
Definition: ath5k_dma.c:55
ath5k_hw_get_isr - Get interrupt status
Definition: ath5k.h:955
void ath5k_rfkill_hw_start(struct ath5k_hw *ah)
Definition: ath5k_rfkill.c:81
#define ECANCELED
Operation canceled.
Definition: errno.h:344
#define AR5K_RXERR_DECRYPT
Definition: ath5k.h:584
static int ath5k_chan_set(struct ath5k_softc *sc, struct net80211_channel *chan)
Definition: ath5k.c:656
int(* open)(struct net80211_device *dev)
Open 802.11 device.
Definition: net80211.h:305
#define NET80211_BAND_BIT_5GHZ
Bitmask for the 5GHz band.
Definition: net80211.h:54
Dynamic memory allocation.
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
#define AR5K_RXKEYIX_INVALID
Definition: ath5k.h:586
#define NET80211_BAND_2GHZ
The 2.4 GHz ISM band, unlicensed in most countries.
Definition: net80211.h:45
#define ATH5K_RATE_CODE_18M
Definition: ath5k.h:716
uint8_t ch
Definition: registers.h:83
unsigned int txbuf_len
Definition: base.h:124
u16 rates[NET80211_NR_BANDS][NET80211_MAX_RATES]
List of transmission rates supported by the card, indexed by band.
Definition: net80211.h:508
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
struct io_buffer * iob
Definition: base.h:61
static struct net80211_device_operations ath5k_ops
Definition: ath5k.c:145
int ath5k_hw_start_tx_dma(struct ath5k_hw *ah, unsigned int queue)
ath5k_hw_start_tx_dma - Start DMA transmit for a specific queue
Definition: ath5k_dma.c:128
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:366
static short ath5k_ieee2mhz(short chan)
Definition: ath5k.c:513
Operations that must be implemented by an 802.11 driver.
Definition: net80211.h:293
#define ENOMEM
Not enough space.
Definition: errno.h:535
A hardware device.
Definition: device.h:77
int ath5k_channel_ok(struct ath5k_hw *ah, u16 freq, unsigned int flags)
Definition: ath5k_phy.c:831
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct pci_driver ath5k_pci_driver __pci_driver
Definition: ath5k.c:124
enum net80211_hw_info::@642 signal_type
Signal strength information that can be provided by the device.
u16 hw_value
Hardware channel value.
Definition: net80211.h:414
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:184
uint16_t device
Device ID.
Definition: pci.h:230
void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
ath5k_hw_set_rx_filter - Set rx filter
Definition: ath5k_pcu.c:454
#define DBGP(...)
Definition: compiler.h:532
#define AR5K_TXDESC_INTREQ
Definition: desc.h:332
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
u8 hwaddr[ETH_ALEN]
Default hardware MAC address.
Definition: net80211.h:447
u8 maxpower
Maximum allowable transmit power, in dBm.
Definition: net80211.h:425
u8 hw_code
Definition: ath5k.c:96
int ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
ath5k_hw_is_intr_pending - Check if we have pending interrupts
Definition: ath5k_dma.c:392
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:432
int curband
Definition: base.h:95
#define IEEE80211_TYP_FRAME_HEADER_LEN
Frame header length for frames we might work with.
Definition: ieee80211.h:60
u32 * link
Definition: base.h:76
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:94
struct ath5k_buf * bufptr
Definition: base.h:98
int nr_rates[NET80211_NR_BANDS]
Number of supported rates, indexed by band.
Definition: net80211.h:511
enum ath5k_int imask
Definition: base.h:115
static int ath5k_rx_start(struct ath5k_softc *sc)
Definition: ath5k.c:1051
struct list_head q
Definition: base.h:77
void ath5k_hw_set_rxdp(struct ath5k_hw *ah, u32 phys_addr)
ath5k_hw_set_rxdp - Set RX Descriptor's address
Definition: ath5k_dma.c:103
static void *__malloc calloc(size_t nmemb, size_t size)
Allocate cleared memory.
Definition: stdlib.h:46
int ath5k_hw_reset(struct ath5k_hw *ah, struct net80211_channel *channel, int change_channel)
Definition: ath5k_reset.c:691
static void ath5k_txq_release(struct ath5k_softc *sc)
Definition: ath5k.c:1032
u8 bssidmask[ETH_ALEN]
Definition: base.h:117
static unsigned int count
Number of entries.
Definition: dwmac.h:225
static int ath5k_stop_hw(struct ath5k_softc *sc)
Definition: ath5k.c:1341
void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
ath5k_hw_start_rx_pcu - Start RX engine
Definition: ath5k_pcu.c:385
#define NET80211_BAND_5GHZ
The band from 4.9 GHz to 5.7 GHz, which tends to be more restricted.
Definition: net80211.h:47
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:459
void * priv
Driver private data.
Definition: net80211.h:798
#define NET80211_PHY_USE_SHORT_PREAMBLE
Whether to use 802.11b short preamble operation.
Definition: net80211.h:260
enum ath5k_tx_queue_subtype tqi_subtype
Definition: ath5k.h:510
#define EINPROGRESS
Operation in progress.
Definition: errno.h:419
struct list_head list
Definition: base.h:57
#define NET80211_PHY_USE_PROTECTION
Whether to use RTS/CTS or CTS-to-self protection for transmissions.
Definition: net80211.h:251
Definition: base.h:74
uint8_t flags
Flags.
Definition: ena.h:18
unsigned int rxbufsize
Definition: base.h:119
struct net80211_device * net80211_alloc(size_t priv_size)
Allocate 802.11 device.
Definition: net80211.c:755
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
u16 duration
Microseconds to reserve link.
Definition: ieee80211.h:15
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
int pci_write_config_byte(struct pci_device *pci, unsigned int where, uint8_t value)
Write byte to PCI configuration space.
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
u16 center_freq
The center frequency for this channel.
Definition: net80211.h:411
uint8_t subtype
Slow protocols subtype.
Definition: eth_slow.h:13
static int ath5k_start(struct net80211_device *dev)
Definition: ath5k.c:1546
u32 desc_daddr
Definition: base.h:100
static const struct @10 ath5k_rates[]
u8 band
The band with which this channel is associated.
Definition: net80211.h:388
static int ath5k_reset(struct ath5k_softc *sc, struct net80211_channel *chan)
Definition: ath5k.c:1498
PCI bus.
#define NET80211_CFG_PHY_PARAMS
Low-level link parameters (short preamble, protection, etc) have changed.
Definition: net80211.h:90
A PCI device.
Definition: pci.h:211
void ath5k_hw_release_tx_queue(struct ath5k_hw *ah)
Definition: ath5k_qcu.c:87
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
#define NET80211_ASSOCIATED
Whether we have successfully associated with the network.
Definition: net80211.h:201
#define ATH5K_RETRIES
Definition: ath5k.c:60
Structure encapsulating the complete state of an 802.11 device.
Definition: net80211.h:786
#define AR5K_SET_SHORT_PREAMBLE
Definition: ath5k.h:728
size_t desc_len
Definition: base.h:101
static void ath5k_desc_free(struct ath5k_softc *sc)
Definition: ath5k.c:926
ath5k_srev_type
Definition: ath5k.h:277
An 802.11 RF channel.
Definition: net80211.h:385
#define CHANNEL_TURBO
Definition: ath5k.h:631
static size_t iob_tailroom(struct io_buffer *iobuf)
Calculate available space at end of an I/O buffer.
Definition: iobuf.h:180
#define ATH5K_RATE_CODE_48M
Definition: ath5k.h:719
#define ARRAY_SIZE(x)
Definition: efx_common.h:43
int ah_single_chip
Definition: ath5k.h:966
enum ath5k_int ath5k_hw_set_imr(struct ath5k_hw *ah, enum ath5k_int new_mask)
ath5k_hw_set_imr - Set interrupt mask
Definition: ath5k_dma.c:549
#define CHANNEL_OFDM
Definition: ath5k.h:633
struct net80211_channel * curchan
Definition: base.h:113
#define ATH5K_SPMBL_YES
Definition: ath5k.c:90
static void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg)
Definition: ath5k.h:1224
static void ath5k_txq_drainq(struct ath5k_softc *sc, struct ath5k_txq *txq)
Definition: ath5k.c:994
#define AR5K_RX_FILTER_BEACON
Definition: reg.h:1333
#define AR5K_TXQ_FLAG_TXEOLINT_ENABLE
Definition: ath5k.h:492
void ath5k_hw_stop_rx_pcu(struct ath5k_hw *ah)
at5k_hw_stop_rx_pcu - Stop RX engine
Definition: ath5k_pcu.c:399
unsigned int filter_flags
Definition: base.h:111
static void ath5k_handle_rx(struct ath5k_softc *sc)
Definition: ath5k.c:1095
#define ATH5K_SPMBL_NO
Definition: ath5k.c:89
#define NET80211_MODE_B
802.11b: 1-11 Mbps operation using DSSS/CCK signaling on the 2.4GHz band
Definition: net80211.h:66
#define ETH_ALEN
Definition: if_ether.h:9
void net80211_tx_complete(struct net80211_device *dev, struct io_buffer *iob, int retries, int rc)
Indicate the completed transmission of a packet.
Definition: net80211.c:2809
A PCI device ID list entry.
Definition: pci.h:175
u16 ah_radio_2ghz_revision
Definition: ath5k.h:974
uint32_t next
Next descriptor address.
Definition: dwmac.h:22
#define AR5K_TXKEYIX_INVALID
Definition: ath5k.h:587
u16 rates[NET80211_MAX_RATES]
A list of all possible TX rates we might use.
Definition: net80211.h:818
uint32_t ds
Definition: librm.h:140
static void ath5k_setcurmode(struct ath5k_softc *sc, unsigned int mode)
Definition: ath5k.c:675
Definition: base.h:56
static int ath5k_probe(struct pci_device *pdev)
Definition: ath5k.c:247
uint8_t status
Status.
Definition: ena.h:16
int phy_flags
Physical layer options.
Definition: net80211.h:983
int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
Definition: ath5k_dma.c:413
int(* ah_proc_rx_desc)(struct ath5k_hw *, struct ath5k_desc *, struct ath5k_rx_status *)
Definition: ath5k.h:1064
struct device * dev
Underlying hardware device.
Definition: netdevice.h:365
int ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version, struct ath5k_hw **ah)
ath5k_hw_attach - Check if hw is supported and init the needed structs
Definition: ath5k_attach.c:113
static unsigned int ath5k_copy_channels(struct ath5k_hw *ah, struct net80211_channel *channels, unsigned int mode, unsigned int max)
Definition: ath5k.c:525
u16 bitrate
Definition: ath5k.c:94
#define AR5K_TXDESC_CLRDMASK
Definition: desc.h:328
u32 daddr
Definition: base.h:60
#define AR5K_RX_FILTER_BCAST
Definition: reg.h:1331
Network device management.
struct pci_device * pdev
Definition: base.h:90
struct ieee80211_ie_channels_channel_band channels[0]
List of (start, length) channel bands we can use.
Definition: ieee80211.h:18
static int ath5k_rxbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
Definition: ath5k.c:771
struct ath5k_desc * desc
Definition: base.h:59
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:376
struct net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789
unsigned int qnum
Definition: base.h:75
FILE_LICENCE(BSD3)
#define iob_reserve(iobuf, len)
Definition: iobuf.h:72
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
static int ath5k_setup_bands(struct net80211_device *dev)
Definition: ath5k.c:586
int status
Definition: base.h:104
struct net80211_hw_info * hwinfo
Definition: base.h:94
#define AR5K_IER_ENABLE
Definition: reg.h:94
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:45
u16 cachelsz
Definition: base.h:102
int ath5k_hw_set_opmode(struct ath5k_hw *ah)
ath5k_hw_set_opmode - Set PCU operating mode
Definition: ath5k_pcu.c:49
int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
ath5k_hw_set_bssid_mask - filter out bssids we listen
Definition: ath5k_pcu.c:349
#define AR5K_TXDESC_CTSENA
Definition: desc.h:331
#define ENOBUFS
No buffer space available.
Definition: errno.h:499
PCI I/O API.
struct list_head * prev
Previous list entry.
Definition: list.h:23
static int ath5k_desc_alloc(struct ath5k_softc *sc)
Definition: ath5k.c:871
void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
Definition: ath5k_pcu.c:407
void * iobase
Definition: base.h:91
#define AR5K_IER_DISABLE
Definition: reg.h:93
#define AR5K_RX_FILTER_UCAST
Definition: reg.h:1329
#define NET80211_BAND_BIT_2GHZ
Bitmask for the 2GHz band.
Definition: net80211.h:52
#define CHANNEL_5GHZ
Definition: ath5k.h:635
void * data
Start of data.
Definition: iobuf.h:53
int nr_channels
Number of supported channels.
Definition: net80211.h:501
#define EIO
Input/output error.
Definition: errno.h:434
struct net80211_channel channels[NET80211_MAX_CHANNELS]
A list of all possible channels we might use.
Definition: net80211.h:806
u16 tqi_flags
Definition: ath5k.h:511
int power_level
Definition: base.h:134
void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.c:723
struct pci_device_id * id
Driver device ID.
Definition: pci.h:248
int ath5k_bitrate_to_hw_rix(int bitrate)
Definition: ath5k.c:719
#define ATH5K_RATE_CODE_5_5M
Definition: ath5k.h:710
int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, int increase)
ath5k_hw_update_tx_triglevel - Update tx trigger level
Definition: ath5k_dma.c:340
void iounmap(volatile const void *io_addr)
Unmap I/O address.
#define ATH5K_RATE_CODE_24M
Definition: ath5k.h:717
#define ATH5K_RATE_CODE_1M
Definition: ath5k.h:708
#define AR5K_TXQ_FLAG_TXDESCINT_ENABLE
Definition: ath5k.h:493
#define NET80211_CFG_RATE
Requested transmission rate (dev->rate) has changed.
Definition: net80211.h:84
int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
enum ath5k_rfgain ath5k_hw_gainf_calibrate(struct ath5k_hw *ah)
Definition: ath5k_phy.c:390
uint8_t ah
Definition: registers.h:85
void mb(void)
Memory barrier.
static u16 net80211_cts_duration(struct net80211_device *dev, int size)
Calculate duration field for a CTS control frame.
Definition: net80211.h:1179
struct net80211_device * dev
Definition: base.h:92
u8 short_pmbl
Definition: ath5k.c:95
#define AR5K_IER
Definition: reg.h:92
#define NET80211_CFG_CHANNEL
Channel choice (dev->channel) or regulatory parameters have changed.
Definition: net80211.h:81
int bands
A bitwise OR of the bands on which this device can communicate.
Definition: net80211.h:453
static int ath5k_init(struct ath5k_softc *sc)
Definition: ath5k.c:1295
u8 bssid[ETH_ALEN]
MAC address of the access point most recently associated.
Definition: net80211.h:954
static void ath5k_irq(struct net80211_device *dev, int enable)
Definition: ath5k.c:1282
int hw_rtscts_rate
Definition: base.h:138
u16 state
State of our association to the network.
Definition: net80211.h:921
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:388
u32 ah_mac_srev
Definition: ath5k.h:969
unsigned long currticks(void)
Get current system time in ticks.
Definition: timer.c:43
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define CHANNEL_B
Definition: ath5k.h:641
#define CHANNEL_2GHZ
Definition: ath5k.h:634
#define ATH5K_DESC_ALIGN
Definition: ath5k.c:61
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
FILE_SECBOOT(FORBIDDEN)
u8 channel_nr
A channel number interpreted according to the band.
Definition: net80211.h:405
#define list_entry(list, type, member)
Get the container of a list entry.
Definition: list.h:322
int last_calib_ticks
Definition: base.h:132
u16 rs_datalen
Definition: ath5k.h:570
int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
ath5k_hw_stop_tx_dma - Stop DMA transmit on a specific queue
Definition: ath5k_dma.c:168
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
unsigned int flags
Definition: base.h:58
int hw_rate
Definition: base.h:137
struct ath5k_hw * ah
Definition: base.h:93
unsigned channel_change_time
Estimate of the time required to change channels, in microseconds.
Definition: net80211.h:518
#define NET80211_CFG_ASSOC
Association has been established with a new BSS (dev->bssid)
Definition: net80211.h:87
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:308
int ath5k_hw_phy_calibrate(struct ath5k_hw *ah, struct net80211_channel *channel)
Definition: ath5k_phy.c:1346
static int ath5k_attach(struct net80211_device *dev)
Definition: ath5k.c:422
#define ATH5K_RATE_CODE_54M
Definition: ath5k.h:720
void ath5k_hw_detach(struct ath5k_hw *ah)
ath5k_hw_detach - Free the ath5k_hw struct
Definition: ath5k_attach.c:336
u8 rate
The rate currently in use, as an index into the rates array.
Definition: net80211.h:824
u32 * rxlink
Definition: base.h:121
struct list_head txbuf
Definition: base.h:123
struct bofm_section_header done
Definition: bofm_test.c:46
#define NET80211_MODE_G
802.11g: 54 Mbps operation using ERP/OFDM signaling on the 2.4GHz band
Definition: net80211.h:69
uint8_t u8
Definition: stdint.h:20
ath5k_int
enum ath5k_int - Hardware interrupt masks helpers
Definition: ath5k.h:806
uint32_t u32
Definition: stdint.h:24
#define ATH5K_RATE_CODE_9M
Definition: ath5k.h:714
int net80211_register(struct net80211_device *dev, struct net80211_device_operations *ops, struct net80211_hw_info *hw)
Register 802.11 device with network stack.
Definition: net80211.c:792
int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type, struct ath5k_txq_info *queue_info)
Definition: ath5k_qcu.c:56
#define NET80211_MODE_A
802.11a: 54 Mbps operation using OFDM signaling on the 5GHz band
Definition: net80211.h:63
static void ath5k_txbuf_free(struct ath5k_softc *sc, struct ath5k_buf *bf)
Definition: ath5k.c:179
void * malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition: malloc.c:707
static void ath5k_stop(struct net80211_device *dev)
Definition: ath5k.c:1561
struct ath5k_desc * desc
Definition: base.h:99
static void ath5k_mode_setup(struct ath5k_softc *sc)
Definition: ath5k.c:687
#define DBG2(...)
Definition: compiler.h:515
#define AR5K_RX_FILTER_MCAST
Definition: reg.h:1330
static void ath5k_rx_stop(struct ath5k_softc *sc)
Definition: ath5k.c:1083
static int ath5k_tx(struct net80211_device *dev, struct io_buffer *skb)
Definition: ath5k.c:1462
#define IEEE80211_MAX_LEN
Definition: ath5k.h:160
void * memset(void *dest, int character, size_t len) __nonnull
u32 iobaddr
Definition: base.h:62
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.
A persistent I/O buffer.
Definition: iobuf.h:38
static void ath5k_configure_filter(struct ath5k_softc *sc)
Definition: ath5k.c:1637
static void ath5k_calibrate(struct ath5k_softc *sc)
Definition: ath5k.c:1439
static void ath5k_tx_processq(struct ath5k_softc *sc, struct ath5k_txq *txq)
Definition: ath5k.c:1228