ar5523.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (c) 2006 Damien Bergamini <damien.bergamini@free.fr>
  3. * Copyright (c) 2006 Sam Leffler, Errno Consulting
  4. * Copyright (c) 2007 Christoph Hellwig <hch@lst.de>
  5. * Copyright (c) 2008-2009 Weongyo Jeong <weongyo@freebsd.org>
  6. * Copyright (c) 2012 Pontus Fuchs <pontus.fuchs@gmail.com>
  7. *
  8. * Permission to use, copy, modify, and/or distribute this software for any
  9. * purpose with or without fee is hereby granted, provided that the above
  10. * copyright notice and this permission notice appear in all copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  13. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  15. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  16. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  17. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  18. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19. */
  20. #define AR5523_FLAG_PRE_FIRMWARE (1 << 0)
  21. #define AR5523_FLAG_ABG (1 << 1)
  22. #define AR5523_FIRMWARE_FILE "ar5523.bin"
  23. #define AR5523_CMD_TX_PIPE 0x01
  24. #define AR5523_DATA_TX_PIPE 0x02
  25. #define AR5523_CMD_RX_PIPE 0x81
  26. #define AR5523_DATA_RX_PIPE 0x82
  27. #define ar5523_cmd_tx_pipe(dev) \
  28. usb_sndbulkpipe((dev), AR5523_CMD_TX_PIPE)
  29. #define ar5523_data_tx_pipe(dev) \
  30. usb_sndbulkpipe((dev), AR5523_DATA_TX_PIPE)
  31. #define ar5523_cmd_rx_pipe(dev) \
  32. usb_rcvbulkpipe((dev), AR5523_CMD_RX_PIPE)
  33. #define ar5523_data_rx_pipe(dev) \
  34. usb_rcvbulkpipe((dev), AR5523_DATA_RX_PIPE)
  35. #define AR5523_DATA_TIMEOUT 10000
  36. #define AR5523_CMD_TIMEOUT 1000
  37. #define AR5523_TX_DATA_COUNT 8
  38. #define AR5523_TX_DATA_RESTART_COUNT 2
  39. #define AR5523_RX_DATA_COUNT 16
  40. #define AR5523_RX_DATA_REFILL_COUNT 8
  41. #define AR5523_CMD_ID 1
  42. #define AR5523_DATA_ID 2
  43. #define AR5523_TX_WD_TIMEOUT (HZ * 2)
  44. #define AR5523_FLUSH_TIMEOUT (HZ * 3)
  45. enum AR5523_flags {
  46. AR5523_HW_UP,
  47. AR5523_USB_DISCONNECTED,
  48. AR5523_CONNECTED
  49. };
  50. struct ar5523_tx_cmd {
  51. struct ar5523 *ar;
  52. struct urb *urb_tx;
  53. void *buf_tx;
  54. void *odata;
  55. int olen;
  56. int flags;
  57. int res;
  58. struct completion done;
  59. };
  60. /* This struct is placed in tx_info->driver_data. It must not be larger
  61. * than IEEE80211_TX_INFO_DRIVER_DATA_SIZE.
  62. */
  63. struct ar5523_tx_data {
  64. struct list_head list;
  65. struct ar5523 *ar;
  66. struct urb *urb;
  67. };
  68. struct ar5523_rx_data {
  69. struct list_head list;
  70. struct ar5523 *ar;
  71. struct urb *urb;
  72. struct sk_buff *skb;
  73. };
  74. struct ar5523 {
  75. struct usb_device *dev;
  76. struct ieee80211_hw *hw;
  77. unsigned long flags;
  78. struct mutex mutex;
  79. struct workqueue_struct *wq;
  80. struct ar5523_tx_cmd tx_cmd;
  81. struct delayed_work stat_work;
  82. struct timer_list tx_wd_timer;
  83. struct work_struct tx_wd_work;
  84. struct work_struct tx_work;
  85. struct list_head tx_queue_pending;
  86. struct list_head tx_queue_submitted;
  87. spinlock_t tx_data_list_lock;
  88. wait_queue_head_t tx_flush_waitq;
  89. /* Queued + Submitted TX frames */
  90. atomic_t tx_nr_total;
  91. /* Submitted TX frames */
  92. atomic_t tx_nr_pending;
  93. void *rx_cmd_buf;
  94. struct urb *rx_cmd_urb;
  95. struct ar5523_rx_data rx_data[AR5523_RX_DATA_COUNT];
  96. spinlock_t rx_data_list_lock;
  97. struct list_head rx_data_free;
  98. struct list_head rx_data_used;
  99. atomic_t rx_data_free_cnt;
  100. struct work_struct rx_refill_work;
  101. unsigned int rxbufsz;
  102. u8 serial[16];
  103. struct ieee80211_channel channels[14];
  104. struct ieee80211_rate rates[12];
  105. struct ieee80211_supported_band band;
  106. struct ieee80211_vif *vif;
  107. };
  108. /* flags for sending firmware commands */
  109. #define AR5523_CMD_FLAG_READ (1 << 1)
  110. #define AR5523_CMD_FLAG_MAGIC (1 << 2)
  111. #define ar5523_dbg(ar, format, arg...) \
  112. dev_dbg(&(ar)->dev->dev, format, ## arg)
  113. /* On USB hot-unplug there can be a lot of URBs in flight and they'll all
  114. * fail. Instead of dealing with them in every possible place just surpress
  115. * any messages on USB disconnect.
  116. */
  117. #define ar5523_err(ar, format, arg...) \
  118. do { \
  119. if (!test_bit(AR5523_USB_DISCONNECTED, &ar->flags)) { \
  120. dev_err(&(ar)->dev->dev, format, ## arg); \
  121. } \
  122. } while (0)
  123. #define ar5523_info(ar, format, arg...) \
  124. dev_info(&(ar)->dev->dev, format, ## arg)