Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ath9k.c 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011
  5. * Original from Linux kernel 3.0.1
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for any
  8. * purpose with or without fee is hereby granted, provided that the above
  9. * copyright notice and this permission notice appear in all copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  12. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  14. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  15. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  16. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include <ipxe/pci.h>
  20. #include "ath9k.h"
  21. static struct pci_device_id ath_pci_id_table[] = {
  22. PCI_ROM(0x168c, 0x0023, "ar5416", "Atheros 5416 PCI", 0), /* PCI */
  23. PCI_ROM(0x168c, 0x0024, "ar5416", "Atheros 5416 PCI-E", 0), /* PCI-E */
  24. PCI_ROM(0x168c, 0x0027, "ar9160", "Atheros 9160 PCI", 0), /* PCI */
  25. PCI_ROM(0x168c, 0x0029, "ar9280", "Atheros 9280 PCI", 0), /* PCI */
  26. PCI_ROM(0x168c, 0x002A, "ar9280", "Atheros 9280 PCI-E", 0), /* PCI-E */
  27. PCI_ROM(0x168c, 0x002B, "ar9285", "Atheros 9285 PCI-E", 0), /* PCI-E */
  28. PCI_ROM(0x168c, 0x002C, "ar2427", "Atheros 2427 PCI-E", 0), /* PCI-E 802.11n bonded out */
  29. PCI_ROM(0x168c, 0x002D, "ar9287", "Atheros 9287 PCI", 0), /* PCI */
  30. PCI_ROM(0x168c, 0x002E, "ar9287", "Atheros 9287 PCI-E", 0), /* PCI-E */
  31. PCI_ROM(0x168c, 0x0030, "ar9300", "Atheros 9300 PCI-E", 0), /* PCI-E AR9300 */
  32. PCI_ROM(0x168c, 0x0032, "ar9485", "Atheros 9485 PCI-E", 0), /* PCI-E AR9485 */
  33. };
  34. /* return bus cachesize in 4B word units */
  35. static void ath_pci_read_cachesize(struct ath_common *common, int *csz)
  36. {
  37. struct ath_softc *sc = (struct ath_softc *) common->priv;
  38. u8 u8tmp;
  39. pci_read_config_byte(sc->pdev, PCI_CACHE_LINE_SIZE, &u8tmp);
  40. *csz = (int)u8tmp;
  41. /*
  42. * This check was put in to avoid "unpleasant" consequences if
  43. * the bootrom has not fully initialized all PCI devices.
  44. * Sometimes the cache line size register is not set
  45. */
  46. if (*csz == 0)
  47. *csz = DEFAULT_CACHELINE >> 2; /* Use the default size */
  48. }
  49. static int ath_pci_eeprom_read(struct ath_common *common, u32 off, u16 *data)
  50. {
  51. struct ath_hw *ah = (struct ath_hw *) common->ah;
  52. common->ops->read(ah, AR5416_EEPROM_OFFSET +
  53. (off << AR5416_EEPROM_S));
  54. if (!ath9k_hw_wait(ah,
  55. AR_EEPROM_STATUS_DATA,
  56. AR_EEPROM_STATUS_DATA_BUSY |
  57. AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0,
  58. AH_WAIT_TIMEOUT)) {
  59. return 0;
  60. }
  61. *data = MS(common->ops->read(ah, AR_EEPROM_STATUS_DATA),
  62. AR_EEPROM_STATUS_DATA_VAL);
  63. return 1;
  64. }
  65. static void ath_pci_extn_synch_enable(struct ath_common *common)
  66. {
  67. struct ath_softc *sc = (struct ath_softc *) common->priv;
  68. struct pci_device *pdev = sc->pdev;
  69. u8 lnkctl;
  70. pci_read_config_byte(pdev, sc->sc_ah->caps.pcie_lcr_offset, &lnkctl);
  71. lnkctl |= 0x0080;
  72. pci_write_config_byte(pdev, sc->sc_ah->caps.pcie_lcr_offset, lnkctl);
  73. }
  74. static const struct ath_bus_ops ath_pci_bus_ops = {
  75. .ath_bus_type = ATH_PCI,
  76. .read_cachesize = ath_pci_read_cachesize,
  77. .eeprom_read = ath_pci_eeprom_read,
  78. .extn_synch_en = ath_pci_extn_synch_enable,
  79. };
  80. static int ath_pci_probe(struct pci_device *pdev)
  81. {
  82. void *mem;
  83. struct ath_softc *sc;
  84. struct net80211_device *dev;
  85. u8 csz;
  86. u16 subsysid;
  87. u32 val;
  88. int ret = 0;
  89. char hw_name[64];
  90. adjust_pci_device(pdev);
  91. /*
  92. * Cache line size is used to size and align various
  93. * structures used to communicate with the hardware.
  94. */
  95. pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
  96. if (csz == 0) {
  97. /*
  98. * Linux 2.4.18 (at least) writes the cache line size
  99. * register as a 16-bit wide register which is wrong.
  100. * We must have this setup properly for rx buffer
  101. * DMA to work so force a reasonable value here if it
  102. * comes up zero.
  103. */
  104. csz =16;
  105. pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
  106. }
  107. /*
  108. * The default setting of latency timer yields poor results,
  109. * set it to the value used by other systems. It may be worth
  110. * tweaking this setting more.
  111. */
  112. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
  113. /*
  114. * Disable the RETRY_TIMEOUT register (0x41) to keep
  115. * PCI Tx retries from interfering with C3 CPU state.
  116. */
  117. pci_read_config_dword(pdev, 0x40, &val);
  118. if ((val & 0x0000ff00) != 0)
  119. pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
  120. mem = ioremap(pdev->membase, 0x10000);
  121. if (!mem) {
  122. DBG("ath9K: PCI memory map error\n") ;
  123. ret = -EIO;
  124. goto err_iomap;
  125. }
  126. dev = net80211_alloc(sizeof(struct ath_softc));
  127. if (!dev) {
  128. DBG("ath9k: No memory for net80211_device\n");
  129. ret = -ENOMEM;
  130. goto err_alloc_hw;
  131. }
  132. pci_set_drvdata(pdev, dev);
  133. dev->netdev->dev = (struct device *)pdev;
  134. sc = dev->priv;
  135. sc->dev = dev;
  136. sc->pdev = pdev;
  137. sc->mem = mem;
  138. /* Will be cleared in ath9k_start() */
  139. sc->sc_flags |= SC_OP_INVALID;
  140. sc->irq = pdev->irq;
  141. pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subsysid);
  142. ret = ath9k_init_device(pdev->device, sc, subsysid, &ath_pci_bus_ops);
  143. if (ret) {
  144. DBG("ath9k: Failed to initialize device\n");
  145. goto err_init;
  146. }
  147. ath9k_hw_name(sc->sc_ah, hw_name, sizeof(hw_name));
  148. DBG("ath9k: %s mem=0x%lx, irq=%d\n",
  149. hw_name, (unsigned long)mem, pdev->irq);
  150. return 0;
  151. err_init:
  152. net80211_free(dev);
  153. err_alloc_hw:
  154. iounmap(mem);
  155. err_iomap:
  156. return ret;
  157. }
  158. static void ath_pci_remove(struct pci_device *pdev)
  159. {
  160. struct net80211_device *dev = pci_get_drvdata(pdev);
  161. struct ath_softc *sc = dev->priv;
  162. void *mem = sc->mem;
  163. if (!is_ath9k_unloaded)
  164. sc->sc_ah->ah_flags |= AH_UNPLUGGED;
  165. ath9k_deinit_device(sc);
  166. net80211_free(sc->dev);
  167. iounmap(mem);
  168. }
  169. struct pci_driver ath_pci_driver __pci_driver = {
  170. .id_count = ARRAY_SIZE(ath_pci_id_table),
  171. .ids = ath_pci_id_table,
  172. .probe = ath_pci_probe,
  173. .remove = ath_pci_remove,
  174. };