PageRenderTime 104ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/staging/ath6kl/os/linux/ar6000_drv.c

https://bitbucket.org/wisechild/galaxy-nexus
C | 6260 lines | 4727 code | 967 blank | 566 comment | 955 complexity | ec75dce87d28aa6f7e4b128a4c77e336 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) 2004-2010 Atheros Communications Inc.
  3. // All rights reserved.
  4. //
  5. //
  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. //
  20. //
  21. // Author(s): ="Atheros"
  22. //------------------------------------------------------------------------------
  23. /*
  24. * This driver is a pseudo ethernet driver to access the Atheros AR6000
  25. * WLAN Device
  26. */
  27. #include "ar6000_drv.h"
  28. #include "cfg80211.h"
  29. #include "htc.h"
  30. #include "wmi_filter_linux.h"
  31. #include "epping_test.h"
  32. #include "wlan_config.h"
  33. #include "ar3kconfig.h"
  34. #include "ar6k_pal.h"
  35. #include "AR6002/addrs.h"
  36. /* LINUX_HACK_FUDGE_FACTOR -- this is used to provide a workaround for linux behavior. When
  37. * the meta data was added to the header it was found that linux did not correctly provide
  38. * enough headroom. However when more headroom was requested beyond what was truly needed
  39. * Linux gave the requested headroom. Therefore to get the necessary headroom from Linux
  40. * the driver requests more than is needed by the amount = LINUX_HACK_FUDGE_FACTOR */
  41. #define LINUX_HACK_FUDGE_FACTOR 16
  42. #define BDATA_BDADDR_OFFSET 28
  43. u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  44. u8 null_mac[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
  45. #ifdef DEBUG
  46. #define ATH_DEBUG_DBG_LOG ATH_DEBUG_MAKE_MODULE_MASK(0)
  47. #define ATH_DEBUG_WLAN_CONNECT ATH_DEBUG_MAKE_MODULE_MASK(1)
  48. #define ATH_DEBUG_WLAN_SCAN ATH_DEBUG_MAKE_MODULE_MASK(2)
  49. #define ATH_DEBUG_WLAN_TX ATH_DEBUG_MAKE_MODULE_MASK(3)
  50. #define ATH_DEBUG_WLAN_RX ATH_DEBUG_MAKE_MODULE_MASK(4)
  51. #define ATH_DEBUG_HTC_RAW ATH_DEBUG_MAKE_MODULE_MASK(5)
  52. #define ATH_DEBUG_HCI_BRIDGE ATH_DEBUG_MAKE_MODULE_MASK(6)
  53. static struct ath_debug_mask_description driver_debug_desc[] = {
  54. { ATH_DEBUG_DBG_LOG , "Target Debug Logs"},
  55. { ATH_DEBUG_WLAN_CONNECT , "WLAN connect"},
  56. { ATH_DEBUG_WLAN_SCAN , "WLAN scan"},
  57. { ATH_DEBUG_WLAN_TX , "WLAN Tx"},
  58. { ATH_DEBUG_WLAN_RX , "WLAN Rx"},
  59. { ATH_DEBUG_HTC_RAW , "HTC Raw IF tracing"},
  60. { ATH_DEBUG_HCI_BRIDGE , "HCI Bridge Setup"},
  61. { ATH_DEBUG_HCI_RECV , "HCI Recv tracing"},
  62. { ATH_DEBUG_HCI_DUMP , "HCI Packet dumps"},
  63. };
  64. ATH_DEBUG_INSTANTIATE_MODULE_VAR(driver,
  65. "driver",
  66. "Linux Driver Interface",
  67. ATH_DEBUG_MASK_DEFAULTS | ATH_DEBUG_WLAN_SCAN |
  68. ATH_DEBUG_HCI_BRIDGE,
  69. ATH_DEBUG_DESCRIPTION_COUNT(driver_debug_desc),
  70. driver_debug_desc);
  71. #endif
  72. #define IS_MAC_NULL(mac) (mac[0]==0 && mac[1]==0 && mac[2]==0 && mac[3]==0 && mac[4]==0 && mac[5]==0)
  73. #define IS_MAC_BCAST(mac) (*mac==0xff)
  74. #define DESCRIPTION "Driver to access the Atheros AR600x Device, version " __stringify(__VER_MAJOR_) "." __stringify(__VER_MINOR_) "." __stringify(__VER_PATCH_) "." __stringify(__BUILD_NUMBER_)
  75. MODULE_AUTHOR("Atheros Communications, Inc.");
  76. MODULE_DESCRIPTION(DESCRIPTION);
  77. MODULE_LICENSE("Dual BSD/GPL");
  78. #ifndef REORG_APTC_HEURISTICS
  79. #undef ADAPTIVE_POWER_THROUGHPUT_CONTROL
  80. #endif /* REORG_APTC_HEURISTICS */
  81. #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
  82. #define APTC_TRAFFIC_SAMPLING_INTERVAL 100 /* msec */
  83. #define APTC_UPPER_THROUGHPUT_THRESHOLD 3000 /* Kbps */
  84. #define APTC_LOWER_THROUGHPUT_THRESHOLD 2000 /* Kbps */
  85. typedef struct aptc_traffic_record {
  86. bool timerScheduled;
  87. struct timeval samplingTS;
  88. unsigned long bytesReceived;
  89. unsigned long bytesTransmitted;
  90. } APTC_TRAFFIC_RECORD;
  91. A_TIMER aptcTimer;
  92. APTC_TRAFFIC_RECORD aptcTR;
  93. #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
  94. #ifdef EXPORT_HCI_BRIDGE_INTERFACE
  95. // callbacks registered by HCI transport driver
  96. struct hci_transport_callbacks ar6kHciTransCallbacks = { NULL };
  97. #endif
  98. unsigned int processDot11Hdr = 0;
  99. char ifname[IFNAMSIZ] = {0,};
  100. int wlaninitmode = WLAN_INIT_MODE_DEFAULT;
  101. static bool bypasswmi;
  102. unsigned int debuglevel = 0;
  103. int tspecCompliance = ATHEROS_COMPLIANCE;
  104. unsigned int busspeedlow = 0;
  105. unsigned int onebitmode = 0;
  106. unsigned int skipflash = 0;
  107. unsigned int wmitimeout = 2;
  108. unsigned int wlanNodeCaching = 1;
  109. unsigned int enableuartprint = ENABLEUARTPRINT_DEFAULT;
  110. unsigned int logWmiRawMsgs = 0;
  111. unsigned int enabletimerwar = 0;
  112. unsigned int num_device = 1;
  113. unsigned int regscanmode;
  114. unsigned int fwmode = 1;
  115. unsigned int mbox_yield_limit = 99;
  116. unsigned int enablerssicompensation = 0;
  117. int reduce_credit_dribble = 1 + HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_HALF;
  118. int allow_trace_signal = 0;
  119. #ifdef CONFIG_HOST_TCMD_SUPPORT
  120. unsigned int testmode =0;
  121. #endif
  122. unsigned int irqprocmode = HIF_DEVICE_IRQ_SYNC_ONLY;//HIF_DEVICE_IRQ_ASYNC_SYNC;
  123. unsigned int panic_on_assert = 1;
  124. unsigned int nohifscattersupport = NOHIFSCATTERSUPPORT_DEFAULT;
  125. unsigned int setuphci = SETUPHCI_DEFAULT;
  126. unsigned int loghci = 0;
  127. unsigned int setupbtdev = SETUPBTDEV_DEFAULT;
  128. #ifndef EXPORT_HCI_BRIDGE_INTERFACE
  129. unsigned int ar3khcibaud = AR3KHCIBAUD_DEFAULT;
  130. unsigned int hciuartscale = HCIUARTSCALE_DEFAULT;
  131. unsigned int hciuartstep = HCIUARTSTEP_DEFAULT;
  132. #endif
  133. unsigned int csumOffload=0;
  134. unsigned int csumOffloadTest=0;
  135. unsigned int eppingtest=0;
  136. unsigned int mac_addr_method;
  137. unsigned int firmware_bridge;
  138. module_param_string(ifname, ifname, sizeof(ifname), 0644);
  139. module_param(wlaninitmode, int, 0644);
  140. module_param(bypasswmi, bool, 0644);
  141. module_param(debuglevel, uint, 0644);
  142. module_param(tspecCompliance, int, 0644);
  143. module_param(onebitmode, uint, 0644);
  144. module_param(busspeedlow, uint, 0644);
  145. module_param(skipflash, uint, 0644);
  146. module_param(wmitimeout, uint, 0644);
  147. module_param(wlanNodeCaching, uint, 0644);
  148. module_param(logWmiRawMsgs, uint, 0644);
  149. module_param(enableuartprint, uint, 0644);
  150. module_param(enabletimerwar, uint, 0644);
  151. module_param(fwmode, uint, 0644);
  152. module_param(mbox_yield_limit, uint, 0644);
  153. module_param(reduce_credit_dribble, int, 0644);
  154. module_param(allow_trace_signal, int, 0644);
  155. module_param(enablerssicompensation, uint, 0644);
  156. module_param(processDot11Hdr, uint, 0644);
  157. module_param(csumOffload, uint, 0644);
  158. #ifdef CONFIG_HOST_TCMD_SUPPORT
  159. module_param(testmode, uint, 0644);
  160. #endif
  161. module_param(irqprocmode, uint, 0644);
  162. module_param(nohifscattersupport, uint, 0644);
  163. module_param(panic_on_assert, uint, 0644);
  164. module_param(setuphci, uint, 0644);
  165. module_param(loghci, uint, 0644);
  166. module_param(setupbtdev, uint, 0644);
  167. #ifndef EXPORT_HCI_BRIDGE_INTERFACE
  168. module_param(ar3khcibaud, uint, 0644);
  169. module_param(hciuartscale, uint, 0644);
  170. module_param(hciuartstep, uint, 0644);
  171. #endif
  172. module_param(eppingtest, uint, 0644);
  173. /* in 2.6.10 and later this is now a pointer to a uint */
  174. unsigned int _mboxnum = HTC_MAILBOX_NUM_MAX;
  175. #define mboxnum &_mboxnum
  176. #ifdef DEBUG
  177. u32 g_dbg_flags = DBG_DEFAULTS;
  178. unsigned int debugflags = 0;
  179. int debugdriver = 0;
  180. unsigned int debughtc = 0;
  181. unsigned int debugbmi = 0;
  182. unsigned int debughif = 0;
  183. unsigned int txcreditsavailable[HTC_MAILBOX_NUM_MAX] = {0};
  184. unsigned int txcreditsconsumed[HTC_MAILBOX_NUM_MAX] = {0};
  185. unsigned int txcreditintrenable[HTC_MAILBOX_NUM_MAX] = {0};
  186. unsigned int txcreditintrenableaggregate[HTC_MAILBOX_NUM_MAX] = {0};
  187. module_param(debugflags, uint, 0644);
  188. module_param(debugdriver, int, 0644);
  189. module_param(debughtc, uint, 0644);
  190. module_param(debugbmi, uint, 0644);
  191. module_param(debughif, uint, 0644);
  192. module_param_array(txcreditsavailable, uint, mboxnum, 0644);
  193. module_param_array(txcreditsconsumed, uint, mboxnum, 0644);
  194. module_param_array(txcreditintrenable, uint, mboxnum, 0644);
  195. module_param_array(txcreditintrenableaggregate, uint, mboxnum, 0644);
  196. #endif /* DEBUG */
  197. unsigned int resetok = 1;
  198. unsigned int tx_attempt[HTC_MAILBOX_NUM_MAX] = {0};
  199. unsigned int tx_post[HTC_MAILBOX_NUM_MAX] = {0};
  200. unsigned int tx_complete[HTC_MAILBOX_NUM_MAX] = {0};
  201. unsigned int hifBusRequestNumMax = 40;
  202. unsigned int war23838_disabled = 0;
  203. #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
  204. unsigned int enableAPTCHeuristics = 1;
  205. #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
  206. module_param_array(tx_attempt, uint, mboxnum, 0644);
  207. module_param_array(tx_post, uint, mboxnum, 0644);
  208. module_param_array(tx_complete, uint, mboxnum, 0644);
  209. module_param(hifBusRequestNumMax, uint, 0644);
  210. module_param(war23838_disabled, uint, 0644);
  211. module_param(resetok, uint, 0644);
  212. #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
  213. module_param(enableAPTCHeuristics, uint, 0644);
  214. #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
  215. #ifdef BLOCK_TX_PATH_FLAG
  216. int blocktx = 0;
  217. module_param(blocktx, int, 0644);
  218. #endif /* BLOCK_TX_PATH_FLAG */
  219. typedef struct user_rssi_compensation_t {
  220. u16 customerID;
  221. union {
  222. u16 a_enable;
  223. u16 bg_enable;
  224. u16 enable;
  225. };
  226. s16 bg_param_a;
  227. s16 bg_param_b;
  228. s16 a_param_a;
  229. s16 a_param_b;
  230. u32 reserved;
  231. } USER_RSSI_CPENSATION;
  232. static USER_RSSI_CPENSATION rssi_compensation_param;
  233. static s16 rssi_compensation_table[96];
  234. int reconnect_flag = 0;
  235. static ar6k_pal_config_t ar6k_pal_config_g;
  236. /* Function declarations */
  237. static int ar6000_init_module(void);
  238. static void ar6000_cleanup_module(void);
  239. int ar6000_init(struct net_device *dev);
  240. static int ar6000_open(struct net_device *dev);
  241. static int ar6000_close(struct net_device *dev);
  242. static void ar6000_init_control_info(struct ar6_softc *ar);
  243. static int ar6000_data_tx(struct sk_buff *skb, struct net_device *dev);
  244. void ar6000_destroy(struct net_device *dev, unsigned int unregister);
  245. static void ar6000_detect_error(unsigned long ptr);
  246. static void ar6000_set_multicast_list(struct net_device *dev);
  247. static struct net_device_stats *ar6000_get_stats(struct net_device *dev);
  248. static void disconnect_timer_handler(unsigned long ptr);
  249. void read_rssi_compensation_param(struct ar6_softc *ar);
  250. /*
  251. * HTC service connection handlers
  252. */
  253. static int ar6000_avail_ev(void *context, void *hif_handle);
  254. static int ar6000_unavail_ev(void *context, void *hif_handle);
  255. int ar6000_configure_target(struct ar6_softc *ar);
  256. static void ar6000_target_failure(void *Instance, int Status);
  257. static void ar6000_rx(void *Context, struct htc_packet *pPacket);
  258. static void ar6000_rx_refill(void *Context,HTC_ENDPOINT_ID Endpoint);
  259. static void ar6000_tx_complete(void *Context, struct htc_packet_queue *pPackets);
  260. static HTC_SEND_FULL_ACTION ar6000_tx_queue_full(void *Context, struct htc_packet *pPacket);
  261. static void ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, u16 num);
  262. static void ar6000_deliver_frames_to_nw_stack(void * dev, void *osbuf);
  263. //static void ar6000_deliver_frames_to_bt_stack(void * dev, void *osbuf);
  264. static struct htc_packet *ar6000_alloc_amsdu_rxbuf(void *Context, HTC_ENDPOINT_ID Endpoint, int Length);
  265. static void ar6000_refill_amsdu_rxbufs(struct ar6_softc *ar, int Count);
  266. static void ar6000_cleanup_amsdu_rxbufs(struct ar6_softc *ar);
  267. static ssize_t
  268. ar6000_sysfs_bmi_read(struct file *fp, struct kobject *kobj,
  269. struct bin_attribute *bin_attr,
  270. char *buf, loff_t pos, size_t count);
  271. static ssize_t
  272. ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj,
  273. struct bin_attribute *bin_attr,
  274. char *buf, loff_t pos, size_t count);
  275. static int
  276. ar6000_sysfs_bmi_init(struct ar6_softc *ar);
  277. void ar6k_cleanup_hci_pal(struct ar6_softc *ar);
  278. static void
  279. ar6000_sysfs_bmi_deinit(struct ar6_softc *ar);
  280. int
  281. ar6000_sysfs_bmi_get_config(struct ar6_softc *ar, u32 mode);
  282. /*
  283. * Static variables
  284. */
  285. struct net_device *ar6000_devices[MAX_AR6000];
  286. static int is_netdev_registered;
  287. DECLARE_WAIT_QUEUE_HEAD(arEvent);
  288. static void ar6000_cookie_init(struct ar6_softc *ar);
  289. static void ar6000_cookie_cleanup(struct ar6_softc *ar);
  290. static void ar6000_free_cookie(struct ar6_softc *ar, struct ar_cookie * cookie);
  291. static struct ar_cookie *ar6000_alloc_cookie(struct ar6_softc *ar);
  292. static int ar6000_reinstall_keys(struct ar6_softc *ar,u8 key_op_ctrl);
  293. #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
  294. struct net_device *arApNetDev;
  295. #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
  296. static struct ar_cookie s_ar_cookie_mem[MAX_COOKIE_NUM];
  297. #define HOST_INTEREST_ITEM_ADDRESS(ar, item) \
  298. (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_HOST_INTEREST_ITEM_ADDRESS(item) : \
  299. (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_HOST_INTEREST_ITEM_ADDRESS(item) : 0))
  300. static struct net_device_ops ar6000_netdev_ops = {
  301. .ndo_init = NULL,
  302. .ndo_open = ar6000_open,
  303. .ndo_stop = ar6000_close,
  304. .ndo_get_stats = ar6000_get_stats,
  305. .ndo_start_xmit = ar6000_data_tx,
  306. .ndo_set_multicast_list = ar6000_set_multicast_list,
  307. };
  308. /* Debug log support */
  309. /*
  310. * Flag to govern whether the debug logs should be parsed in the kernel
  311. * or reported to the application.
  312. */
  313. #define REPORT_DEBUG_LOGS_TO_APP
  314. int
  315. ar6000_set_host_app_area(struct ar6_softc *ar)
  316. {
  317. u32 address, data;
  318. struct host_app_area_s host_app_area;
  319. /* Fetch the address of the host_app_area_s instance in the host interest area */
  320. address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar, hi_app_host_interest));
  321. if (ar6000_ReadRegDiag(ar->arHifDevice, &address, &data) != 0) {
  322. return A_ERROR;
  323. }
  324. address = TARG_VTOP(ar->arTargetType, data);
  325. host_app_area.wmi_protocol_ver = WMI_PROTOCOL_VERSION;
  326. if (ar6000_WriteDataDiag(ar->arHifDevice, address,
  327. (u8 *)&host_app_area,
  328. sizeof(struct host_app_area_s)) != 0)
  329. {
  330. return A_ERROR;
  331. }
  332. return 0;
  333. }
  334. u32 dbglog_get_debug_hdr_ptr(struct ar6_softc *ar)
  335. {
  336. u32 param;
  337. u32 address;
  338. int status;
  339. address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dbglog_hdr));
  340. if ((status = ar6000_ReadDataDiag(ar->arHifDevice, address,
  341. (u8 *)&param, 4)) != 0)
  342. {
  343. param = 0;
  344. }
  345. return param;
  346. }
  347. /*
  348. * The dbglog module has been initialized. Its ok to access the relevant
  349. * data stuctures over the diagnostic window.
  350. */
  351. void
  352. ar6000_dbglog_init_done(struct ar6_softc *ar)
  353. {
  354. ar->dbglog_init_done = true;
  355. }
  356. u32 dbglog_get_debug_fragment(s8 *datap, u32 len, u32 limit)
  357. {
  358. s32 *buffer;
  359. u32 count;
  360. u32 numargs;
  361. u32 length;
  362. u32 fraglen;
  363. count = fraglen = 0;
  364. buffer = (s32 *)datap;
  365. length = (limit >> 2);
  366. if (len <= limit) {
  367. fraglen = len;
  368. } else {
  369. while (count < length) {
  370. numargs = DBGLOG_GET_NUMARGS(buffer[count]);
  371. fraglen = (count << 2);
  372. count += numargs + 1;
  373. }
  374. }
  375. return fraglen;
  376. }
  377. void
  378. dbglog_parse_debug_logs(s8 *datap, u32 len)
  379. {
  380. s32 *buffer;
  381. u32 count;
  382. u32 timestamp;
  383. u32 debugid;
  384. u32 moduleid;
  385. u32 numargs;
  386. u32 length;
  387. count = 0;
  388. buffer = (s32 *)datap;
  389. length = (len >> 2);
  390. while (count < length) {
  391. debugid = DBGLOG_GET_DBGID(buffer[count]);
  392. moduleid = DBGLOG_GET_MODULEID(buffer[count]);
  393. numargs = DBGLOG_GET_NUMARGS(buffer[count]);
  394. timestamp = DBGLOG_GET_TIMESTAMP(buffer[count]);
  395. switch (numargs) {
  396. case 0:
  397. AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d)\n", moduleid, debugid, timestamp));
  398. break;
  399. case 1:
  400. AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x\n", moduleid, debugid,
  401. timestamp, buffer[count+1]));
  402. break;
  403. case 2:
  404. AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x, 0x%x\n", moduleid, debugid,
  405. timestamp, buffer[count+1], buffer[count+2]));
  406. break;
  407. default:
  408. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid args: %d\n", numargs));
  409. }
  410. count += numargs + 1;
  411. }
  412. }
  413. int
  414. ar6000_dbglog_get_debug_logs(struct ar6_softc *ar)
  415. {
  416. u32 data[8]; /* Should be able to accommodate struct dbglog_buf_s */
  417. u32 address;
  418. u32 length;
  419. u32 dropped;
  420. u32 firstbuf;
  421. u32 debug_hdr_ptr;
  422. if (!ar->dbglog_init_done) return A_ERROR;
  423. AR6000_SPIN_LOCK(&ar->arLock, 0);
  424. if (ar->dbgLogFetchInProgress) {
  425. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  426. return A_EBUSY;
  427. }
  428. /* block out others */
  429. ar->dbgLogFetchInProgress = true;
  430. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  431. debug_hdr_ptr = dbglog_get_debug_hdr_ptr(ar);
  432. printk("debug_hdr_ptr: 0x%x\n", debug_hdr_ptr);
  433. /* Get the contents of the ring buffer */
  434. if (debug_hdr_ptr) {
  435. address = TARG_VTOP(ar->arTargetType, debug_hdr_ptr);
  436. length = 4 /* sizeof(dbuf) */ + 4 /* sizeof(dropped) */;
  437. A_MEMZERO(data, sizeof(data));
  438. ar6000_ReadDataDiag(ar->arHifDevice, address, (u8 *)data, length);
  439. address = TARG_VTOP(ar->arTargetType, data[0] /* dbuf */);
  440. firstbuf = address;
  441. dropped = data[1]; /* dropped */
  442. length = 4 /* sizeof(next) */ + 4 /* sizeof(buffer) */ + 4 /* sizeof(bufsize) */ + 4 /* sizeof(length) */ + 4 /* sizeof(count) */ + 4 /* sizeof(free) */;
  443. A_MEMZERO(data, sizeof(data));
  444. ar6000_ReadDataDiag(ar->arHifDevice, address, (u8 *)&data, length);
  445. do {
  446. address = TARG_VTOP(ar->arTargetType, data[1] /* buffer*/);
  447. length = data[3]; /* length */
  448. if ((length) && (length <= data[2] /* bufsize*/)) {
  449. /* Rewind the index if it is about to overrun the buffer */
  450. if (ar->log_cnt > (DBGLOG_HOST_LOG_BUFFER_SIZE - length)) {
  451. ar->log_cnt = 0;
  452. }
  453. if(0 != ar6000_ReadDataDiag(ar->arHifDevice, address,
  454. (u8 *)&ar->log_buffer[ar->log_cnt], length))
  455. {
  456. break;
  457. }
  458. ar6000_dbglog_event(ar, dropped, (s8 *)&ar->log_buffer[ar->log_cnt], length);
  459. ar->log_cnt += length;
  460. } else {
  461. AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("Length: %d (Total size: %d)\n",
  462. data[3], data[2]));
  463. }
  464. address = TARG_VTOP(ar->arTargetType, data[0] /* next */);
  465. length = 4 /* sizeof(next) */ + 4 /* sizeof(buffer) */ + 4 /* sizeof(bufsize) */ + 4 /* sizeof(length) */ + 4 /* sizeof(count) */ + 4 /* sizeof(free) */;
  466. A_MEMZERO(data, sizeof(data));
  467. if(0 != ar6000_ReadDataDiag(ar->arHifDevice, address,
  468. (u8 *)&data, length))
  469. {
  470. break;
  471. }
  472. } while (address != firstbuf);
  473. }
  474. ar->dbgLogFetchInProgress = false;
  475. return 0;
  476. }
  477. void
  478. ar6000_dbglog_event(struct ar6_softc *ar, u32 dropped,
  479. s8 *buffer, u32 length)
  480. {
  481. #ifdef REPORT_DEBUG_LOGS_TO_APP
  482. #define MAX_WIRELESS_EVENT_SIZE 252
  483. /*
  484. * Break it up into chunks of MAX_WIRELESS_EVENT_SIZE bytes of messages.
  485. * There seems to be a limitation on the length of message that could be
  486. * transmitted to the user app via this mechanism.
  487. */
  488. u32 send, sent;
  489. sent = 0;
  490. send = dbglog_get_debug_fragment(&buffer[sent], length - sent,
  491. MAX_WIRELESS_EVENT_SIZE);
  492. while (send) {
  493. sent += send;
  494. send = dbglog_get_debug_fragment(&buffer[sent], length - sent,
  495. MAX_WIRELESS_EVENT_SIZE);
  496. }
  497. #else
  498. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Dropped logs: 0x%x\nDebug info length: %d\n",
  499. dropped, length));
  500. /* Interpret the debug logs */
  501. dbglog_parse_debug_logs((s8 *)buffer, length);
  502. #endif /* REPORT_DEBUG_LOGS_TO_APP */
  503. }
  504. static int __init
  505. ar6000_init_module(void)
  506. {
  507. static int probed = 0;
  508. int r;
  509. OSDRV_CALLBACKS osdrvCallbacks;
  510. a_module_debug_support_init();
  511. #ifdef DEBUG
  512. /* check for debug mask overrides */
  513. if (debughtc != 0) {
  514. ATH_DEBUG_SET_DEBUG_MASK(htc,debughtc);
  515. }
  516. if (debugbmi != 0) {
  517. ATH_DEBUG_SET_DEBUG_MASK(bmi,debugbmi);
  518. }
  519. if (debughif != 0) {
  520. ATH_DEBUG_SET_DEBUG_MASK(hif,debughif);
  521. }
  522. if (debugdriver != 0) {
  523. ATH_DEBUG_SET_DEBUG_MASK(driver,debugdriver);
  524. }
  525. #endif
  526. A_REGISTER_MODULE_DEBUG_INFO(driver);
  527. A_MEMZERO(&osdrvCallbacks,sizeof(osdrvCallbacks));
  528. osdrvCallbacks.deviceInsertedHandler = ar6000_avail_ev;
  529. osdrvCallbacks.deviceRemovedHandler = ar6000_unavail_ev;
  530. #ifdef CONFIG_PM
  531. osdrvCallbacks.deviceSuspendHandler = ar6000_suspend_ev;
  532. osdrvCallbacks.deviceResumeHandler = ar6000_resume_ev;
  533. osdrvCallbacks.devicePowerChangeHandler = ar6000_power_change_ev;
  534. #endif
  535. #ifdef DEBUG
  536. /* Set the debug flags if specified at load time */
  537. if(debugflags != 0)
  538. {
  539. g_dbg_flags = debugflags;
  540. }
  541. #endif
  542. if (probed) {
  543. return -ENODEV;
  544. }
  545. probed++;
  546. #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
  547. memset(&aptcTR, 0, sizeof(APTC_TRAFFIC_RECORD));
  548. #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
  549. r = HIFInit(&osdrvCallbacks);
  550. if (r)
  551. return r;
  552. return 0;
  553. }
  554. static void __exit
  555. ar6000_cleanup_module(void)
  556. {
  557. int i = 0;
  558. struct net_device *ar6000_netdev;
  559. #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
  560. /* Delete the Adaptive Power Control timer */
  561. if (timer_pending(&aptcTimer)) {
  562. del_timer_sync(&aptcTimer);
  563. }
  564. #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
  565. for (i=0; i < MAX_AR6000; i++) {
  566. if (ar6000_devices[i] != NULL) {
  567. ar6000_netdev = ar6000_devices[i];
  568. ar6000_devices[i] = NULL;
  569. ar6000_destroy(ar6000_netdev, 1);
  570. }
  571. }
  572. HIFShutDownDevice(NULL);
  573. a_module_debug_support_cleanup();
  574. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_cleanup: success\n"));
  575. }
  576. #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
  577. void
  578. aptcTimerHandler(unsigned long arg)
  579. {
  580. u32 numbytes;
  581. u32 throughput;
  582. struct ar6_softc *ar;
  583. int status;
  584. ar = (struct ar6_softc *)arg;
  585. A_ASSERT(ar != NULL);
  586. A_ASSERT(!timer_pending(&aptcTimer));
  587. AR6000_SPIN_LOCK(&ar->arLock, 0);
  588. /* Get the number of bytes transferred */
  589. numbytes = aptcTR.bytesTransmitted + aptcTR.bytesReceived;
  590. aptcTR.bytesTransmitted = aptcTR.bytesReceived = 0;
  591. /* Calculate and decide based on throughput thresholds */
  592. throughput = ((numbytes * 8)/APTC_TRAFFIC_SAMPLING_INTERVAL); /* Kbps */
  593. if (throughput < APTC_LOWER_THROUGHPUT_THRESHOLD) {
  594. /* Enable Sleep and delete the timer */
  595. A_ASSERT(ar->arWmiReady == true);
  596. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  597. status = wmi_powermode_cmd(ar->arWmi, REC_POWER);
  598. AR6000_SPIN_LOCK(&ar->arLock, 0);
  599. A_ASSERT(status == 0);
  600. aptcTR.timerScheduled = false;
  601. } else {
  602. A_TIMEOUT_MS(&aptcTimer, APTC_TRAFFIC_SAMPLING_INTERVAL, 0);
  603. }
  604. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  605. }
  606. #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
  607. static void
  608. ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, u16 num)
  609. {
  610. void * osbuf;
  611. while(num) {
  612. if((osbuf = A_NETBUF_ALLOC(AR6000_BUFFER_SIZE))) {
  613. A_NETBUF_ENQUEUE(q, osbuf);
  614. } else {
  615. break;
  616. }
  617. num--;
  618. }
  619. if(num) {
  620. A_PRINTF("%s(), allocation of netbuf failed", __func__);
  621. }
  622. }
  623. static struct bin_attribute bmi_attr = {
  624. .attr = {.name = "bmi", .mode = 0600},
  625. .read = ar6000_sysfs_bmi_read,
  626. .write = ar6000_sysfs_bmi_write,
  627. };
  628. static ssize_t
  629. ar6000_sysfs_bmi_read(struct file *fp, struct kobject *kobj,
  630. struct bin_attribute *bin_attr,
  631. char *buf, loff_t pos, size_t count)
  632. {
  633. int index;
  634. struct ar6_softc *ar;
  635. struct hif_device_os_device_info *osDevInfo;
  636. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Read %d bytes\n", (u32)count));
  637. for (index=0; index < MAX_AR6000; index++) {
  638. ar = (struct ar6_softc *)ar6k_priv(ar6000_devices[index]);
  639. osDevInfo = &ar->osDevInfo;
  640. if (kobj == (&(((struct device *)osDevInfo->pOSDevice)->kobj))) {
  641. break;
  642. }
  643. }
  644. if (index == MAX_AR6000) return 0;
  645. if ((BMIRawRead(ar->arHifDevice, (u8*)buf, count, true)) != 0) {
  646. return 0;
  647. }
  648. return count;
  649. }
  650. static ssize_t
  651. ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj,
  652. struct bin_attribute *bin_attr,
  653. char *buf, loff_t pos, size_t count)
  654. {
  655. int index;
  656. struct ar6_softc *ar;
  657. struct hif_device_os_device_info *osDevInfo;
  658. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Write %d bytes\n", (u32)count));
  659. for (index=0; index < MAX_AR6000; index++) {
  660. ar = (struct ar6_softc *)ar6k_priv(ar6000_devices[index]);
  661. osDevInfo = &ar->osDevInfo;
  662. if (kobj == (&(((struct device *)osDevInfo->pOSDevice)->kobj))) {
  663. break;
  664. }
  665. }
  666. if (index == MAX_AR6000) return 0;
  667. if ((BMIRawWrite(ar->arHifDevice, (u8*)buf, count)) != 0) {
  668. return 0;
  669. }
  670. return count;
  671. }
  672. static int
  673. ar6000_sysfs_bmi_init(struct ar6_softc *ar)
  674. {
  675. int status;
  676. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Creating sysfs entry\n"));
  677. A_MEMZERO(&ar->osDevInfo, sizeof(struct hif_device_os_device_info));
  678. /* Get the underlying OS device */
  679. status = HIFConfigureDevice(ar->arHifDevice,
  680. HIF_DEVICE_GET_OS_DEVICE,
  681. &ar->osDevInfo,
  682. sizeof(struct hif_device_os_device_info));
  683. if (status) {
  684. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI: Failed to get OS device info from HIF\n"));
  685. return A_ERROR;
  686. }
  687. /* Create a bmi entry in the sysfs filesystem */
  688. if ((sysfs_create_bin_file(&(((struct device *)ar->osDevInfo.pOSDevice)->kobj), &bmi_attr)) < 0)
  689. {
  690. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMI: Failed to create entry for bmi in sysfs filesystem\n"));
  691. return A_ERROR;
  692. }
  693. return 0;
  694. }
  695. static void
  696. ar6000_sysfs_bmi_deinit(struct ar6_softc *ar)
  697. {
  698. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Deleting sysfs entry\n"));
  699. sysfs_remove_bin_file(&(((struct device *)ar->osDevInfo.pOSDevice)->kobj), &bmi_attr);
  700. }
  701. #define bmifn(fn) do { \
  702. if ((fn) < 0) { \
  703. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__)); \
  704. return A_ERROR; \
  705. } \
  706. } while(0)
  707. #ifdef SOFTMAC_FILE_USED
  708. #define AR6002_MAC_ADDRESS_OFFSET 0x0A
  709. #define AR6003_MAC_ADDRESS_OFFSET 0x16
  710. static
  711. void calculate_crc(u32 TargetType, u8 *eeprom_data)
  712. {
  713. u16 *ptr_crc;
  714. u16 *ptr16_eeprom;
  715. u16 checksum;
  716. u32 i;
  717. u32 eeprom_size;
  718. if (TargetType == TARGET_TYPE_AR6001)
  719. {
  720. eeprom_size = 512;
  721. ptr_crc = (u16 *)eeprom_data;
  722. }
  723. else if (TargetType == TARGET_TYPE_AR6003)
  724. {
  725. eeprom_size = 1024;
  726. ptr_crc = (u16 *)((u8 *)eeprom_data + 0x04);
  727. }
  728. else
  729. {
  730. eeprom_size = 768;
  731. ptr_crc = (u16 *)((u8 *)eeprom_data + 0x04);
  732. }
  733. // Clear the crc
  734. *ptr_crc = 0;
  735. // Recalculate new CRC
  736. checksum = 0;
  737. ptr16_eeprom = (u16 *)eeprom_data;
  738. for (i = 0;i < eeprom_size; i += 2)
  739. {
  740. checksum = checksum ^ (*ptr16_eeprom);
  741. ptr16_eeprom++;
  742. }
  743. checksum = 0xFFFF ^ checksum;
  744. *ptr_crc = checksum;
  745. }
  746. static void
  747. ar6000_softmac_update(struct ar6_softc *ar, u8 *eeprom_data, size_t size)
  748. {
  749. const char *source = "random generated";
  750. const struct firmware *softmac_entry;
  751. u8 *ptr_mac;
  752. switch (ar->arTargetType) {
  753. case TARGET_TYPE_AR6002:
  754. ptr_mac = (u8 *)((u8 *)eeprom_data + AR6002_MAC_ADDRESS_OFFSET);
  755. break;
  756. case TARGET_TYPE_AR6003:
  757. ptr_mac = (u8 *)((u8 *)eeprom_data + AR6003_MAC_ADDRESS_OFFSET);
  758. break;
  759. default:
  760. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Invalid Target Type\n"));
  761. return;
  762. }
  763. printk(KERN_DEBUG "MAC from EEPROM %pM\n", ptr_mac);
  764. /* create a random MAC in case we cannot read file from system */
  765. ptr_mac[0] = 0;
  766. ptr_mac[1] = 0x03;
  767. ptr_mac[2] = 0x7F;
  768. ptr_mac[3] = random32() & 0xff;
  769. ptr_mac[4] = random32() & 0xff;
  770. ptr_mac[5] = random32() & 0xff;
  771. if ((A_REQUEST_FIRMWARE(&softmac_entry, "softmac", ((struct device *)ar->osDevInfo.pOSDevice))) == 0)
  772. {
  773. char *macbuf = A_MALLOC_NOWAIT(softmac_entry->size+1);
  774. if (macbuf) {
  775. unsigned int softmac[6];
  776. memcpy(macbuf, softmac_entry->data, softmac_entry->size);
  777. macbuf[softmac_entry->size] = '\0';
  778. if (sscanf(macbuf, "%02x:%02x:%02x:%02x:%02x:%02x",
  779. &softmac[0], &softmac[1], &softmac[2],
  780. &softmac[3], &softmac[4], &softmac[5])==6) {
  781. int i;
  782. for (i=0; i<6; ++i) {
  783. ptr_mac[i] = softmac[i] & 0xff;
  784. }
  785. source = "softmac file";
  786. }
  787. kfree(macbuf);
  788. }
  789. A_RELEASE_FIRMWARE(softmac_entry);
  790. }
  791. printk(KERN_DEBUG "MAC from %s %pM\n", source, ptr_mac);
  792. calculate_crc(ar->arTargetType, eeprom_data);
  793. }
  794. #endif /* SOFTMAC_FILE_USED */
  795. static int
  796. ar6000_transfer_bin_file(struct ar6_softc *ar, AR6K_BIN_FILE file, u32 address, bool compressed)
  797. {
  798. int status;
  799. const char *filename;
  800. const struct firmware *fw_entry;
  801. u32 fw_entry_size;
  802. u8 **buf;
  803. size_t *buf_len;
  804. switch (file) {
  805. case AR6K_OTP_FILE:
  806. buf = &ar->fw_otp;
  807. buf_len = &ar->fw_otp_len;
  808. if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
  809. filename = AR6003_REV1_OTP_FILE;
  810. } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
  811. filename = AR6003_REV2_OTP_FILE;
  812. } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) {
  813. filename = AR6003_REV3_OTP_FILE;
  814. } else {
  815. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
  816. return A_ERROR;
  817. }
  818. break;
  819. case AR6K_FIRMWARE_FILE:
  820. buf = &ar->fw;
  821. buf_len = &ar->fw_len;
  822. if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
  823. filename = AR6003_REV1_FIRMWARE_FILE;
  824. } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
  825. filename = AR6003_REV2_FIRMWARE_FILE;
  826. } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) {
  827. filename = AR6003_REV3_FIRMWARE_FILE;
  828. } else {
  829. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
  830. return A_ERROR;
  831. }
  832. if (eppingtest) {
  833. bypasswmi = true;
  834. if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
  835. filename = AR6003_REV1_EPPING_FIRMWARE_FILE;
  836. } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
  837. filename = AR6003_REV2_EPPING_FIRMWARE_FILE;
  838. } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) {
  839. filename = AR6003_REV3_EPPING_FIRMWARE_FILE;
  840. } else {
  841. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("eppingtest : unsupported firmware revision: %d\n",
  842. ar->arVersion.target_ver));
  843. return A_ERROR;
  844. }
  845. compressed = false;
  846. }
  847. #ifdef CONFIG_HOST_TCMD_SUPPORT
  848. if(testmode) {
  849. if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
  850. filename = AR6003_REV1_TCMD_FIRMWARE_FILE;
  851. } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
  852. filename = AR6003_REV2_TCMD_FIRMWARE_FILE;
  853. } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) {
  854. filename = AR6003_REV3_TCMD_FIRMWARE_FILE;
  855. } else {
  856. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
  857. return A_ERROR;
  858. }
  859. compressed = false;
  860. }
  861. #endif
  862. #ifdef HTC_RAW_INTERFACE
  863. if (!eppingtest && bypasswmi) {
  864. if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
  865. filename = AR6003_REV1_ART_FIRMWARE_FILE;
  866. } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
  867. filename = AR6003_REV2_ART_FIRMWARE_FILE;
  868. } else {
  869. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
  870. return A_ERROR;
  871. }
  872. compressed = false;
  873. }
  874. #endif
  875. break;
  876. case AR6K_PATCH_FILE:
  877. buf = &ar->fw_patch;
  878. buf_len = &ar->fw_patch_len;
  879. if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
  880. filename = AR6003_REV1_PATCH_FILE;
  881. } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
  882. filename = AR6003_REV2_PATCH_FILE;
  883. } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) {
  884. filename = AR6003_REV3_PATCH_FILE;
  885. } else {
  886. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
  887. return A_ERROR;
  888. }
  889. break;
  890. case AR6K_BOARD_DATA_FILE:
  891. buf = &ar->fw_data;
  892. buf_len = &ar->fw_data_len;
  893. if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
  894. filename = AR6003_REV1_BOARD_DATA_FILE;
  895. } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
  896. filename = AR6003_REV2_BOARD_DATA_FILE;
  897. } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) {
  898. filename = AR6003_REV3_BOARD_DATA_FILE;
  899. } else {
  900. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
  901. return A_ERROR;
  902. }
  903. break;
  904. default:
  905. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown file type: %d\n", file));
  906. return A_ERROR;
  907. }
  908. if (*buf == NULL) {
  909. if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) {
  910. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename));
  911. return A_ENOENT;
  912. }
  913. *buf = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
  914. *buf_len = fw_entry->size;
  915. A_RELEASE_FIRMWARE(fw_entry);
  916. }
  917. #ifdef SOFTMAC_FILE_USED
  918. if (file==AR6K_BOARD_DATA_FILE && *buf_len) {
  919. ar6000_softmac_update(ar, *buf, *buf_len);
  920. }
  921. #endif
  922. fw_entry_size = *buf_len;
  923. /* Load extended board data for AR6003 */
  924. if ((file==AR6K_BOARD_DATA_FILE) && *buf) {
  925. u32 board_ext_address;
  926. u32 board_ext_data_size;
  927. u32 board_data_size;
  928. board_ext_data_size = (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_BOARD_EXT_DATA_SZ : \
  929. (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_BOARD_EXT_DATA_SZ : 0));
  930. board_data_size = (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_BOARD_DATA_SZ : \
  931. (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_BOARD_DATA_SZ : 0));
  932. /* Determine where in Target RAM to write Board Data */
  933. bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data), (u8 *)&board_ext_address, 4));
  934. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board extended Data download address: 0x%x\n", board_ext_address));
  935. /* check whether the target has allocated memory for extended board data and file contains extended board data */
  936. if ((board_ext_address) && (*buf_len == (board_data_size + board_ext_data_size))) {
  937. u32 param;
  938. status = BMIWriteMemory(ar->arHifDevice, board_ext_address, (u8 *)(*buf + board_data_size), board_ext_data_size);
  939. if (status) {
  940. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__));
  941. return A_ERROR;
  942. }
  943. /* Record the fact that extended board Data IS initialized */
  944. param = (board_ext_data_size << 16) | 1;
  945. bmifn(BMIWriteMemory(ar->arHifDevice,
  946. HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data_config),
  947. (unsigned char *)&param, 4));
  948. }
  949. fw_entry_size = board_data_size;
  950. }
  951. if (compressed) {
  952. status = BMIFastDownload(ar->arHifDevice, address, *buf, fw_entry_size);
  953. } else {
  954. status = BMIWriteMemory(ar->arHifDevice, address, *buf, fw_entry_size);
  955. }
  956. if (status) {
  957. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__));
  958. return A_ERROR;
  959. }
  960. return 0;
  961. }
  962. int
  963. ar6000_update_bdaddr(struct ar6_softc *ar)
  964. {
  965. if (setupbtdev != 0) {
  966. u32 address;
  967. if (BMIReadMemory(ar->arHifDevice,
  968. HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data), (u8 *)&address, 4) != 0)
  969. {
  970. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for hi_board_data failed\n"));
  971. return A_ERROR;
  972. }
  973. if (BMIReadMemory(ar->arHifDevice, address + BDATA_BDADDR_OFFSET, (u8 *)ar->bdaddr, 6) != 0)
  974. {
  975. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for BD address failed\n"));
  976. return A_ERROR;
  977. }
  978. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BDADDR 0x%x:0x%x:0x%x:0x%x:0x%x:0x%x\n", ar->bdaddr[0],
  979. ar->bdaddr[1], ar->bdaddr[2], ar->bdaddr[3],
  980. ar->bdaddr[4], ar->bdaddr[5]));
  981. }
  982. return 0;
  983. }
  984. int
  985. ar6000_sysfs_bmi_get_config(struct ar6_softc *ar, u32 mode)
  986. {
  987. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Requesting device specific configuration\n"));
  988. if (mode == WLAN_INIT_MODE_UDEV) {
  989. char version[16];
  990. const struct firmware *fw_entry;
  991. /* Get config using udev through a script in user space */
  992. sprintf(version, "%2.2x", ar->arVersion.target_ver);
  993. if ((A_REQUEST_FIRMWARE(&fw_entry, version, ((struct device *)ar->osDevInfo.pOSDevice))) != 0)
  994. {
  995. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI: Failure to get configuration for target version: %s\n", version));
  996. return A_ERROR;
  997. }
  998. A_RELEASE_FIRMWARE(fw_entry);
  999. } else {
  1000. /* The config is contained within the driver itself */
  1001. int status;
  1002. u32 param, options, sleep, address;
  1003. /* Temporarily disable system sleep */
  1004. address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
  1005. bmifn(BMIReadSOCRegister(ar->arHifDevice, address, &param));
  1006. options = param;
  1007. param |= AR6K_OPTION_SLEEP_DISABLE;
  1008. bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
  1009. address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
  1010. bmifn(BMIReadSOCRegister(ar->arHifDevice, address, &param));
  1011. sleep = param;
  1012. param |= WLAN_SYSTEM_SLEEP_DISABLE_SET(1);
  1013. bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
  1014. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("old options: %d, old sleep: %d\n", options, sleep));
  1015. if (ar->arTargetType == TARGET_TYPE_AR6003) {
  1016. /* Program analog PLL register */
  1017. bmifn(BMIWriteSOCRegister(ar->arHifDevice, ANALOG_INTF_BASE_ADDRESS + 0x284, 0xF9104001));
  1018. /* Run at 80/88MHz by default */
  1019. param = CPU_CLOCK_STANDARD_SET(1);
  1020. } else {
  1021. /* Run at 40/44MHz by default */
  1022. param = CPU_CLOCK_STANDARD_SET(0);
  1023. }
  1024. address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
  1025. bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
  1026. param = 0;
  1027. if (ar->arTargetType == TARGET_TYPE_AR6002) {
  1028. bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_ext_clk_detected), (u8 *)&param, 4));
  1029. }
  1030. /* LPO_CAL.ENABLE = 1 if no external clk is detected */
  1031. if (param != 1) {
  1032. address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
  1033. param = LPO_CAL_ENABLE_SET(1);
  1034. bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
  1035. }
  1036. /* Venus2.0: Lower SDIO pad drive strength,
  1037. * temporary WAR to avoid SDIO CRC error */
  1038. if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
  1039. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("AR6K: Temporary WAR to avoid SDIO CRC error\n"));
  1040. param = 0x20;
  1041. address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
  1042. bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
  1043. address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
  1044. bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
  1045. address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
  1046. bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
  1047. address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
  1048. bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
  1049. }
  1050. #ifdef FORCE_INTERNAL_CLOCK
  1051. /* Ignore external clock, if any, and force use of internal clock */
  1052. if (ar->arTargetType == TARGET_TYPE_AR6003) {
  1053. /* hi_ext_clk_detected = 0 */
  1054. param = 0;
  1055. bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_ext_clk_detected), (u8 *)&param, 4));
  1056. /* CLOCK_CONTROL &= ~LF_CLK32 */
  1057. address = RTC_BASE_ADDRESS + CLOCK_CONTROL_ADDRESS;
  1058. bmifn(BMIReadSOCRegister(ar->arHifDevice, address, &param));
  1059. param &= (~CLOCK_CONTROL_LF_CLK32_SET(1));
  1060. bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
  1061. }
  1062. #endif /* FORCE_INTERNAL_CLOCK */
  1063. /* Transfer Board Data from Target EEPROM to Target RAM */
  1064. if (ar->arTargetType == TARGET_TYPE_AR6003) {
  1065. /* Determine where in Target RAM to write Board Data */
  1066. bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data), (u8 *)&address, 4));
  1067. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board Data download address: 0x%x\n", address));
  1068. /* Write EEPROM data to Target RAM */
  1069. if ((ar6000_transfer_bin_file(ar, AR6K_BOARD_DATA_FILE, address, false)) != 0) {
  1070. return A_ERROR;
  1071. }
  1072. /* Record the fact that Board Data IS initialized */
  1073. param = 1;
  1074. bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data_initialized), (u8 *)&param, 4));
  1075. /* Transfer One time Programmable data */
  1076. AR6K_APP_LOAD_ADDRESS(address, ar->arVersion.target_ver);
  1077. if (ar->arVersion.target_ver == AR6003_REV3_VERSION)
  1078. address = 0x1234;
  1079. status = ar6000_transfer_bin_file(ar, AR6K_OTP_FILE, address, true);
  1080. if (status == 0) {
  1081. /* Execute the OTP code */
  1082. param = 0;
  1083. AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver);
  1084. bmifn(BMIExecute(ar->arHifDevice, address, &param));
  1085. } else if (status != A_ENOENT) {
  1086. return A_ERROR;
  1087. }
  1088. } else {
  1089. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Programming of board data for chip %d not supported\n", ar->arTargetType));
  1090. return A_ERROR;
  1091. }
  1092. /* Download Target firmware */
  1093. AR6K_APP_LOAD_ADDRESS(address, ar->arVersion.target_ver);
  1094. if (ar->arVersion.target_ver == AR6003_REV3_VERSION)
  1095. address = 0x1234;
  1096. if ((ar6000_transfer_bin_file(ar, AR6K_FIRMWARE_FILE, address, true)) != 0) {
  1097. return A_ERROR;
  1098. }
  1099. /* Set starting address for firmware */
  1100. AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver);
  1101. bmifn(BMISetAppStart(ar->arHifDevice, address));
  1102. if(ar->arTargetType == TARGET_TYPE_AR6003) {
  1103. AR6K_DATASET_PATCH_ADDRESS(address, ar->arVersion.target_ver);
  1104. if ((ar6000_transfer_bin_file(ar, AR6K_PATCH_FILE,
  1105. address, false)) != 0)
  1106. return A_ERROR;
  1107. param = address;
  1108. bmifn(BMIWriteMemory(ar->arHifDevice,
  1109. HOST_INTEREST_ITEM_ADDRESS(ar, hi_dset_list_head),
  1110. (unsigned char *)&param, 4));
  1111. }
  1112. /* Restore system sleep */
  1113. address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
  1114. bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, sleep));
  1115. address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
  1116. param = options | 0x20;
  1117. bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
  1118. if (ar->arTargetType == TARGET_TYPE_AR6003) {
  1119. /* Configure GPIO AR6003 UART */
  1120. #ifndef CONFIG_AR600x_DEBUG_UART_TX_PIN
  1121. #define CONFIG_AR600x_DEBUG_UART_TX_PIN 8
  1122. #endif
  1123. param = CONFIG_AR600x_DEBUG_UART_TX_PIN;
  1124. bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dbg_uart_txpin), (u8 *)&param, 4));
  1125. #if (CONFIG_AR600x_DEBUG_UART_TX_PIN == 23)
  1126. {
  1127. address = GPIO_BASE_ADDRESS + CLOCK_GPIO_ADDRESS;
  1128. bmifn(BMIReadSOCRegister(ar->arHifDevice, address, &param));
  1129. param |= CLOCK_GPIO_BT_CLK_OUT_EN_SET(1);
  1130. bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
  1131. }
  1132. #endif
  1133. /* Configure GPIO for BT Reset */
  1134. #ifdef ATH6KL_CONFIG_GPIO_BT_RESET
  1135. #define CONFIG_AR600x_BT_RESET_PIN 0x16
  1136. param = CONFIG_AR600x_BT_RESET_PIN;
  1137. bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_hci_uart_support_pins), (u8 *)&param, 4));
  1138. #endif /* ATH6KL_CONFIG_GPIO_BT_RESET */
  1139. /* Configure UART flow control polarity */
  1140. #ifndef CONFIG_ATH6KL_BT_UART_FC_POLARITY
  1141. #define CONFIG_ATH6KL_BT_UART_FC_POLARITY 0
  1142. #endif
  1143. #if (CONFIG_ATH6KL_BT_UART_FC_POLARITY == 1)
  1144. if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
  1145. param = ((CONFIG_ATH6KL_BT_UART_FC_POLARITY << 1) & 0x2);
  1146. bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_hci_uart_pwr_mgmt_params), (u8 *)&param, 4));
  1147. }
  1148. #endif /* CONFIG_ATH6KL_BT_UART_FC_POLARITY */
  1149. }
  1150. #ifdef HTC_RAW_INTERFACE
  1151. if (!eppingtest && bypasswmi) {
  1152. /* Don't run BMIDone for ART mode and force resetok=0 */
  1153. resetok = 0;
  1154. msleep(1000);
  1155. }
  1156. #endif /* HTC_RAW_INTERFACE */
  1157. }
  1158. return 0;
  1159. }
  1160. int
  1161. ar6000_configure_target(struct ar6_softc *ar)
  1162. {
  1163. u32 param;
  1164. if (enableuartprint) {
  1165. param = 1;
  1166. if (BMIWriteMemory(ar->arHifDevice,
  1167. HOST_INTEREST_ITEM_ADDRESS(ar, hi_serial_enable),
  1168. (u8 *)&param,
  1169. 4)!= 0)
  1170. {
  1171. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enableuartprint failed \n"));
  1172. return A_ERROR;
  1173. }
  1174. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Serial console prints enabled\n"));
  1175. }
  1176. /* Tell target which HTC version it is used*/
  1177. param = HTC_PROTOCOL_VERSION;
  1178. if (BMIWriteMemory(ar->arHifDevice,
  1179. HOST_INTEREST_ITEM_ADDRESS(ar, hi_app_host_interest),
  1180. (u8 *)&param,
  1181. 4)!= 0)
  1182. {
  1183. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for htc version failed \n"));
  1184. return A_ERROR;
  1185. }
  1186. #ifdef CONFIG_HOST_TCMD_SUPPORT
  1187. if(testmode) {
  1188. ar->arTargetMode = AR6000_TCMD_MODE;
  1189. }else {
  1190. ar->arTargetMode = AR6000_WLAN_MODE;
  1191. }
  1192. #endif
  1193. if (enabletimerwar) {
  1194. u32 param;
  1195. if (BMIReadMemory(ar->arHifDevice,
  1196. HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
  1197. (u8 *)&param,
  1198. 4)!= 0)
  1199. {
  1200. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for enabletimerwar failed \n"));
  1201. return A_ERROR;
  1202. }
  1203. param |= HI_OPTION_TIMER_WAR;
  1204. if (BMIWriteMemory(ar->arHifDevice,
  1205. HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
  1206. (u8 *)&param,
  1207. 4) != 0)
  1208. {
  1209. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enabletimerwar failed \n"));
  1210. return A_ERROR;
  1211. }
  1212. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Timer WAR enabled\n"));
  1213. }
  1214. /* set the firmware mode to STA/IBSS/AP */
  1215. {
  1216. u32 param;
  1217. if (BMIReadMemory(ar->arHifDevice,
  1218. HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
  1219. (u8 *)&param,
  1220. 4)!= 0)
  1221. {
  1222. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for setting fwmode failed \n"));
  1223. return A_ERROR;
  1224. }
  1225. param |= (num_device << HI_OPTION_NUM_DEV_SHIFT);
  1226. param |= (fwmode << HI_OPTION_FW_MODE_SHIFT);
  1227. param |= (mac_addr_method << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
  1228. param |= (firmware_bridge << HI_OPTION_FW_BRIDGE_SHIFT);
  1229. if (BMIWriteMemory(ar->arHifDevice,
  1230. HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
  1231. (u8 *)&param,
  1232. 4) != 0)
  1233. {
  1234. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for setting fwmode failed \n"));
  1235. return A_ERROR;
  1236. }
  1237. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n"));
  1238. }
  1239. #ifdef ATH6KL_DISABLE_TARGET_DBGLOGS
  1240. {
  1241. u32 param;
  1242. if (BMIReadMemory(ar->arHifDevice,
  1243. HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
  1244. (u8 *)&param,
  1245. 4)!= 0)
  1246. {
  1247. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for disabling debug logs failed\n"));
  1248. return A_ERROR;
  1249. }
  1250. param |= HI_OPTION_DISABLE_DBGLOG;
  1251. if (BMIWriteMemory(ar->arHifDevice,
  1252. HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
  1253. (u8 *)&param,
  1254. 4) != 0)
  1255. {
  1256. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for HI_OPTION_DISABLE_DBGLOG\n"));
  1257. return A_ERROR;
  1258. }
  1259. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n"));
  1260. }
  1261. #endif /* ATH6KL_DISABLE_TARGET_DBGLOGS */
  1262. /*
  1263. * Hardcode the address use for the extended board data
  1264. * Ideally this should be pre-allocate by the OS at boot time
  1265. * But since it is a new feature and board data is loaded
  1266. * at init time, we have to workaround this from host.
  1267. * It is difficult to patch the firmware boot code,
  1268. * but possible in theory.
  1269. */
  1270. if (ar->arTargetType == TARGET_TYPE_AR6003) {
  1271. u32 ramReservedSz;
  1272. if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
  1273. param = AR6003_REV2_BOARD_EXT_DATA_ADDRESS;
  1274. ramReservedSz = AR6003_REV2_RAM_RESERVE_SIZE;
  1275. } else {
  1276. param = AR6003_REV3_BOARD_EXT_DATA_ADDRESS;
  1277. ramReservedSz = AR6003_REV3_RAM_RESERVE_SIZE;
  1278. }
  1279. if (BMIWriteMemory(ar->arHifDevice,
  1280. HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data),
  1281. (u8 *)&param, 4) != 0) {
  1282. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1283. ("BMIWriteMemory for "
  1284. "hi_board_ext_data failed\n"));
  1285. return A_ERROR;
  1286. }
  1287. if (BMIWriteMemory(ar->arHifDevice,
  1288. HOST_INTEREST_ITEM_ADDRESS(ar,
  1289. hi_end_RAM_reserve_sz),
  1290. (u8 *)&ramReservedSz, 4) != 0) {
  1291. AR_DEBUG_PRINTF(ATH_DEBUG_ERR ,
  1292. ("BMIWriteMemory for "
  1293. "hi_end_RAM_reserve_sz failed\n"));
  1294. return A_ERROR;
  1295. }
  1296. }
  1297. /* since BMIInit is called in the driver layer, we have to set the block
  1298. * size here for the target */
  1299. if (ar6000_set_htc_params(ar->arHifDevice, ar->arTargetType,
  1300. mbox_yield_limit, 0)) {
  1301. /* use default number of control buffers */
  1302. return A_ERROR;
  1303. }
  1304. if (setupbtdev != 0) {
  1305. if (ar6000_set_hci_bridge_flags(ar->arHifDevice,
  1306. ar->arTargetType,
  1307. setupbtdev)) {
  1308. return A_ERROR;
  1309. }
  1310. }
  1311. return 0;
  1312. }
  1313. static void
  1314. init_netdev(struct net_device *dev, char *name)
  1315. {
  1316. dev->netdev_ops = &ar6000_netdev_ops;
  1317. dev->watchdog_timeo = AR6000_TX_TIMEOUT;
  1318. /*
  1319. * We need the OS to provide us with more headroom in order to
  1320. * perform dix to 802.3, WMI header encap, and the HTC header
  1321. */
  1322. if (processDot11Hdr) {
  1323. dev->hard_header_len = sizeof(struct ieee80211_qosframe) + sizeof(ATH_LLC_SNAP_HDR) + sizeof(WMI_DATA_HDR) + HTC_HEADER_LEN + WMI_MAX_TX_META_SZ + LINUX_HACK_FUDGE_FACTOR;
  1324. } else {
  1325. dev->hard_header_len = ETH_HLEN + sizeof(ATH_LLC_SNAP_HDR) +
  1326. sizeof(WMI_DATA_HDR) + HTC_HEADER_LEN + WMI_MAX_TX_META_SZ + LINUX_HACK_FUDGE_FACTOR;
  1327. }
  1328. if (name[0])
  1329. {
  1330. strcpy(dev->name, name);
  1331. }
  1332. #ifdef CONFIG_CHECKSUM_OFFLOAD
  1333. if(csumOffload){
  1334. dev->features |= NETIF_F_IP_CSUM; /*advertise kernel capability to do TCP/UDP CSUM offload for IPV4*/
  1335. }
  1336. #endif
  1337. return;
  1338. }
  1339. static int __ath6kl_init_netdev(struct net_device *dev)
  1340. {
  1341. int r;
  1342. rtnl_lock();
  1343. r = ar6000_init(dev);
  1344. rtnl_unlock();
  1345. if (r) {
  1346. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_init\n"));
  1347. return r;
  1348. }
  1349. return 0;
  1350. }
  1351. #ifdef HTC_RAW_INTERFACE
  1352. static int ath6kl_init_netdev_wmi(struct net_device *dev)
  1353. {
  1354. if (!eppingtest && bypasswmi)
  1355. return 0;
  1356. return __ath6kl_init_netdev(dev);
  1357. }
  1358. #else
  1359. static int ath6kl_init_netdev_wmi(struct net_device *dev)
  1360. {
  1361. return __ath6kl_init_netdev(dev);
  1362. }
  1363. #endif
  1364. static int ath6kl_init_netdev(struct ar6_softc *ar)
  1365. {
  1366. int r;
  1367. r = ar6000_sysfs_bmi_get_config(ar, wlaninitmode);
  1368. if (r) {
  1369. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1370. ("ar6000_avail: "
  1371. "ar6000_sysfs_bmi_get_config failed\n"));
  1372. return r;
  1373. }
  1374. return ath6kl_init_netdev_wmi(ar->arNetDev);
  1375. }
  1376. /*
  1377. * HTC Event handlers
  1378. */
  1379. static int
  1380. ar6000_avail_ev(void *context, void *hif_handle)
  1381. {
  1382. int i;
  1383. struct net_device *dev;
  1384. void *ar_netif;
  1385. struct ar6_softc *ar;
  1386. int device_index = 0;
  1387. struct htc_init_info htcInfo;
  1388. struct wireless_dev *wdev;
  1389. int r = 0;
  1390. struct hif_device_os_device_info osDevInfo;
  1391. memset(&osDevInfo, 0, sizeof(osDevInfo));
  1392. if (HIFConfigureDevice(hif_handle, HIF_DEVICE_GET_OS_DEVICE,
  1393. &osDevInfo, sizeof(osDevInfo))) {
  1394. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: Failed to get OS device instance\n", __func__));
  1395. return A_ERROR;
  1396. }
  1397. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_available\n"));
  1398. for (i=0; i < MAX_AR6000; i++) {
  1399. if (ar6000_devices[i] == NULL) {
  1400. break;
  1401. }
  1402. }
  1403. if (i == MAX_AR6000) {
  1404. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_available: max devices reached\n"));
  1405. return A_ERROR;
  1406. }
  1407. /* Save this. It gives a bit better readability especially since */
  1408. /* we use another local "i" variable below. */
  1409. device_index = i;
  1410. wdev = ar6k_cfg80211_init(osDevInfo.pOSDevice);
  1411. if (IS_ERR(wdev)) {
  1412. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: ar6k_cfg80211_init failed\n", __func__));
  1413. return A_ERROR;
  1414. }
  1415. ar_netif = wdev_priv(wdev);
  1416. if (ar_netif == NULL) {
  1417. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Can't allocate ar6k priv memory\n", __func__));
  1418. return A_ERROR;
  1419. }
  1420. A_MEMZERO(ar_netif, sizeof(struct ar6_softc));
  1421. ar = (struct ar6_softc *)ar_netif;
  1422. ar->wdev = wdev;
  1423. wdev->iftype = NL80211_IFTYPE_STATION;
  1424. dev = alloc_netdev_mq(0, "wlan%d", ether_setup, 1);
  1425. if (!dev) {
  1426. printk(KERN_CRIT "AR6K: no memory for network device instance\n");
  1427. ar6k_cfg80211_deinit(ar);
  1428. return A_ERROR;
  1429. }
  1430. dev->ieee80211_ptr = wdev;
  1431. SET_NETDEV_DEV(dev, wiphy_dev(wdev->wiphy));
  1432. wdev->netdev = dev;
  1433. ar->arNetworkType = INFRA_NETWORK;
  1434. ar->smeState = SME_DISCONNECTED;
  1435. ar->arAutoAuthStage = AUTH_IDLE;
  1436. init_netdev(dev, ifname);
  1437. ar->arNetDev = dev;
  1438. ar->arHifDevice = hif_handle;
  1439. ar->arWlanState = WLAN_ENABLED;
  1440. ar->arDeviceIndex = device_index;
  1441. ar->arWlanPowerState = WLAN_POWER_STATE_ON;
  1442. ar->arWlanOff = false; /* We are in ON state */
  1443. #ifdef CONFIG_PM
  1444. ar->arWowState = WLAN_WOW_STATE_NONE;
  1445. ar->arBTOff = true; /* BT chip assumed to be OFF */
  1446. ar->arBTSharing = WLAN_CONFIG_BT_SHARING;
  1447. ar->arWlanOffConfig = WLAN_CONFIG_WLAN_OFF;
  1448. ar->arSuspendConfig = WLAN_CONFIG_PM_SUSPEND;
  1449. ar->arWow2Config = WLAN_CONFIG_PM_WOW2;
  1450. #endif /* CONFIG_PM */
  1451. A_INIT_TIMER(&ar->arHBChallengeResp.timer, ar6000_detect_error, dev);
  1452. ar->arHBChallengeResp.seqNum = 0;
  1453. ar->arHBChallengeResp.outstanding = false;
  1454. ar->arHBChallengeResp.missCnt = 0;
  1455. ar->arHBChallengeResp.frequency = AR6000_HB_CHALLENGE_RESP_FREQ_DEFAULT;
  1456. ar->arHBChallengeResp.missThres = AR6000_HB_CHALLENGE_RESP_MISS_THRES_DEFAULT;
  1457. ar6000_init_control_info(ar);
  1458. init_waitqueue_head(&arEvent);
  1459. sema_init(&ar->arSem, 1);
  1460. ar->bIsDestroyProgress = false;
  1461. INIT_HTC_PACKET_QUEUE(&ar->amsdu_rx_buffer_queue);
  1462. #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
  1463. A_INIT_TIMER(&aptcTimer, aptcTimerHandler, ar);
  1464. #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
  1465. A_INIT_TIMER(&ar->disconnect_timer, disconnect_timer_handler, dev);
  1466. BMIInit();
  1467. ar6000_sysfs_bmi_init(ar);
  1468. {
  1469. struct bmi_target_info targ_info;
  1470. r = BMIGetTargetInfo(ar->arHifDevice, &targ_info);
  1471. if (r)
  1472. goto avail_ev_failed;
  1473. ar->arVersion.target_ver = targ_info.target_ver;
  1474. ar->arTargetType = targ_info.target_type;
  1475. wdev->wiphy->hw_version = targ_info.target_ver;
  1476. }
  1477. r = ar6000_configure_target(ar);
  1478. if (r)
  1479. goto avail_ev_failed;
  1480. A_MEMZERO(&htcInfo,sizeof(htcInfo));
  1481. htcInfo.pContext = ar;
  1482. htcInfo.TargetFailure = ar6000_target_failure;
  1483. ar->arHtcTarget = HTCCreate(ar->arHifDevice,&htcInfo);
  1484. if (!ar->arHtcTarget) {
  1485. r = -ENOMEM;
  1486. goto avail_ev_failed;
  1487. }
  1488. spin_lock_init(&ar->arLock);
  1489. #ifdef WAPI_ENABLE
  1490. ar->arWapiEnable = 0;
  1491. #endif
  1492. if(csumOffload){
  1493. /*if external frame work is also needed, change and use an extended rxMetaVerion*/
  1494. ar->rxMetaVersion=WMI_META_VERSION_2;
  1495. }
  1496. ar->aggr_cntxt = aggr_init(ar6000_alloc_netbufs);
  1497. if (!ar->aggr_cntxt) {
  1498. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize aggr.\n", __func__));
  1499. r = -ENOMEM;
  1500. goto avail_ev_failed;
  1501. }
  1502. aggr_register_rx_dispatcher(ar->aggr_cntxt, (void *)dev, ar6000_deliver_frames_to_nw_stack);
  1503. HIFClaimDevice(ar->arHifDevice, ar);
  1504. /* We only register the device in the global list if we succeed. */
  1505. /* If the device is in the global list, it will be destroyed */
  1506. /* when the module is unloaded. */
  1507. ar6000_devices[device_index] = dev;
  1508. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("BMI enabled: %d\n", wlaninitmode));
  1509. if ((wlaninitmode == WLAN_INIT_MODE_UDEV) ||
  1510. (wlaninitmode == WLAN_INIT_MODE_DRV)) {
  1511. r = ath6kl_init_netdev(ar);
  1512. if (r)
  1513. goto avail_ev_failed;
  1514. }
  1515. /* This runs the init function if registered */
  1516. r = register_netdev(dev);
  1517. if (r) {
  1518. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: register_netdev failed\n"));
  1519. ar6000_destroy(dev, 0);
  1520. return r;
  1521. }
  1522. is_netdev_registered = 1;
  1523. #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
  1524. arApNetDev = NULL;
  1525. #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
  1526. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_avail: name=%s hifdevice=0x%lx, dev=0x%lx (%d), ar=0x%lx\n",
  1527. dev->name, (unsigned long)ar->arHifDevice, (unsigned long)dev, device_index,
  1528. (unsigned long)ar));
  1529. avail_ev_failed :
  1530. if (r)
  1531. ar6000_sysfs_bmi_deinit(ar);
  1532. return r;
  1533. }
  1534. static void ar6000_target_failure(void *Instance, int Status)
  1535. {
  1536. struct ar6_softc *ar = (struct ar6_softc *)Instance;
  1537. WMI_TARGET_ERROR_REPORT_EVENT errEvent;
  1538. static bool sip = false;
  1539. if (Status != 0) {
  1540. printk(KERN_ERR "ar6000_target_failure: target asserted \n");
  1541. if (timer_pending(&ar->arHBChallengeResp.timer)) {
  1542. A_UNTIMEOUT(&ar->arHBChallengeResp.timer);
  1543. }
  1544. /* try dumping target assertion information (if any) */
  1545. ar6000_dump_target_assert_info(ar->arHifDevice,ar->arTargetType);
  1546. /*
  1547. * Fetch the logs from the target via the diagnostic
  1548. * window.
  1549. */
  1550. ar6000_dbglog_get_debug_logs(ar);
  1551. /* Report the error only once */
  1552. if (!sip) {
  1553. sip = true;
  1554. errEvent.errorVal = WMI_TARGET_COM_ERR |
  1555. WMI_TARGET_FATAL_ERR;
  1556. }
  1557. }
  1558. }
  1559. static int
  1560. ar6000_unavail_ev(void *context, void *hif_handle)
  1561. {
  1562. struct ar6_softc *ar = (struct ar6_softc *)context;
  1563. /* NULL out it's entry in the global list */
  1564. ar6000_devices[ar->arDeviceIndex] = NULL;
  1565. ar6000_destroy(ar->arNetDev, 1);
  1566. return 0;
  1567. }
  1568. void
  1569. ar6000_restart_endpoint(struct net_device *dev)
  1570. {
  1571. int status = 0;
  1572. struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
  1573. BMIInit();
  1574. do {
  1575. if ( (status=ar6000_configure_target(ar))!= 0)
  1576. break;
  1577. if ( (status=ar6000_sysfs_bmi_get_config(ar, wlaninitmode)) != 0)
  1578. {
  1579. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_sysfs_bmi_get_config failed\n"));
  1580. break;
  1581. }
  1582. rtnl_lock();
  1583. status = (ar6000_init(dev)==0) ? 0 : A_ERROR;
  1584. rtnl_unlock();
  1585. if (status) {
  1586. break;
  1587. }
  1588. if (ar->arSsidLen && ar->arWlanState == WLAN_ENABLED) {
  1589. ar6000_connect_to_ap(ar);
  1590. }
  1591. } while (0);
  1592. if (status== 0) {
  1593. return;
  1594. }
  1595. ar6000_devices[ar->arDeviceIndex] = NULL;
  1596. ar6000_destroy(ar->arNetDev, 1);
  1597. }
  1598. void
  1599. ar6000_stop_endpoint(struct net_device *dev, bool keepprofile, bool getdbglogs)
  1600. {
  1601. struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
  1602. /* Stop the transmit queues */
  1603. netif_stop_queue(dev);
  1604. /* Disable the target and the interrupts associated with it */
  1605. if (ar->arWmiReady == true)
  1606. {
  1607. if (!bypasswmi)
  1608. {
  1609. bool disconnectIssued;
  1610. disconnectIssued = (ar->arConnected) || (ar->arConnectPending);
  1611. ar6000_disconnect(ar);
  1612. if (!keepprofile) {
  1613. ar6000_init_profile_info(ar);
  1614. }
  1615. A_UNTIMEOUT(&ar->disconnect_timer);
  1616. if (getdbglogs) {
  1617. ar6000_dbglog_get_debug_logs(ar);
  1618. }
  1619. ar->arWmiReady = false;
  1620. wmi_shutdown(ar->arWmi);
  1621. ar->arWmiEnabled = false;
  1622. ar->arWmi = NULL;
  1623. /*
  1624. * After wmi_shudown all WMI events will be dropped.
  1625. * We need to cleanup the buffers allocated in AP mode
  1626. * and give disconnect notification to stack, which usually
  1627. * happens in the disconnect_event.
  1628. * Simulate the disconnect_event by calling the function directly.
  1629. * Sometimes disconnect_event will be received when the debug logs
  1630. * are collected.
  1631. */
  1632. if (disconnectIssued) {
  1633. if(ar->arNetworkType & AP_NETWORK) {
  1634. ar6000_disconnect_event(ar, DISCONNECT_CMD, bcast_mac, 0, NULL, 0);
  1635. } else {
  1636. ar6000_disconnect_event(ar, DISCONNECT_CMD, ar->arBssid, 0, NULL, 0);
  1637. }
  1638. }
  1639. ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT;
  1640. ar->user_key_ctrl = 0;
  1641. }
  1642. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): WMI stopped\n", __func__));
  1643. }
  1644. else
  1645. {
  1646. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): WMI not ready 0x%lx 0x%lx\n",
  1647. __func__, (unsigned long) ar, (unsigned long) ar->arWmi));
  1648. /* Shut down WMI if we have started it */
  1649. if(ar->arWmiEnabled == true)
  1650. {
  1651. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): Shut down WMI\n", __func__));
  1652. wmi_shutdown(ar->arWmi);
  1653. ar->arWmiEnabled = false;
  1654. ar->arWmi = NULL;
  1655. }
  1656. }
  1657. if (ar->arHtcTarget != NULL) {
  1658. #ifdef EXPORT_HCI_BRIDGE_INTERFACE
  1659. if (NULL != ar6kHciTransCallbacks.cleanupTransport) {
  1660. ar6kHciTransCallbacks.cleanupTransport(NULL);
  1661. }
  1662. #else
  1663. // FIXME: workaround to reset BT's UART baud rate to default
  1664. if (NULL != ar->exitCallback) {
  1665. struct ar3k_config_info ar3kconfig;
  1666. int status;
  1667. A_MEMZERO(&ar3kconfig,sizeof(ar3kconfig));
  1668. ar6000_set_default_ar3kconfig(ar, (void *)&ar3kconfig);
  1669. status = ar->exitCallback(&ar3kconfig);
  1670. if (0 != status) {
  1671. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to reset AR3K baud rate! \n"));
  1672. }
  1673. }
  1674. // END workaround
  1675. if (setuphci)
  1676. ar6000_cleanup_hci(ar);
  1677. #endif
  1678. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Shutting down HTC .... \n"));
  1679. /* stop HTC */
  1680. HTCStop(ar->arHtcTarget);
  1681. }
  1682. if (resetok) {
  1683. /* try to reset the device if we can
  1684. * The driver may have been configure NOT to reset the target during
  1685. * a debug session */
  1686. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Attempting to reset target on instance destroy.... \n"));
  1687. if (ar->arHifDevice != NULL) {
  1688. bool coldReset = (ar->arTargetType == TARGET_TYPE_AR6003) ? true: false;
  1689. ar6000_reset_device(ar->arHifDevice, ar->arTargetType, true, coldReset);
  1690. }
  1691. } else {
  1692. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Host does not want target reset. \n"));
  1693. }
  1694. /* Done with cookies */
  1695. ar6000_cookie_cleanup(ar);
  1696. /* cleanup any allocated AMSDU buffers */
  1697. ar6000_cleanup_amsdu_rxbufs(ar);
  1698. }
  1699. /*
  1700. * We need to differentiate between the surprise and planned removal of the
  1701. * device because of the following consideration:
  1702. * - In case of surprise removal, the hcd already frees up the pending
  1703. * for the device and hence there is no need to unregister the function
  1704. * driver inorder to get these requests. For planned removal, the function
  1705. * driver has to explicitly unregister itself to have the hcd return all the
  1706. * pending requests before the data structures for the devices are freed up.
  1707. * Note that as per the current implementation, the function driver will
  1708. * end up releasing all the devices since there is no API to selectively
  1709. * release a particular device.
  1710. * - Certain commands issued to the target can be skipped for surprise
  1711. * removal since they will anyway not go through.
  1712. */
  1713. void
  1714. ar6000_destroy(struct net_device *dev, unsigned int unregister)
  1715. {
  1716. struct ar6_softc *ar;
  1717. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("+ar6000_destroy \n"));
  1718. if((dev == NULL) || ((ar = ar6k_priv(dev)) == NULL))
  1719. {
  1720. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(): Failed to get device structure.\n", __func__));
  1721. return;
  1722. }
  1723. ar->bIsDestroyProgress = true;
  1724. if (down_interruptible(&ar->arSem)) {
  1725. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(): down_interruptible failed \n", __func__));
  1726. return;
  1727. }
  1728. if (ar->arWlanPowerState != WLAN_POWER_STATE_CUT_PWR) {
  1729. /* only stop endpoint if we are not stop it in suspend_ev */
  1730. ar6000_stop_endpoint(dev, false, true);
  1731. }
  1732. ar->arWlanState = WLAN_DISABLED;
  1733. if (ar->arHtcTarget != NULL) {
  1734. /* destroy HTC */
  1735. HTCDestroy(ar->arHtcTarget);
  1736. }
  1737. if (ar->arHifDevice != NULL) {
  1738. /*release the device so we do not get called back on remove incase we
  1739. * we're explicity destroyed by module unload */
  1740. HIFReleaseDevice(ar->arHifDevice);
  1741. HIFShutDownDevice(ar->arHifDevice);
  1742. }
  1743. aggr_module_destroy(ar->aggr_cntxt);
  1744. /* Done with cookies */
  1745. ar6000_cookie_cleanup(ar);
  1746. /* cleanup any allocated AMSDU buffers */
  1747. ar6000_cleanup_amsdu_rxbufs(ar);
  1748. ar6000_sysfs_bmi_deinit(ar);
  1749. /* Cleanup BMI */
  1750. BMICleanup();
  1751. /* Clear the tx counters */
  1752. memset(tx_attempt, 0, sizeof(tx_attempt));
  1753. memset(tx_post, 0, sizeof(tx_post));
  1754. memset(tx_complete, 0, sizeof(tx_complete));
  1755. #ifdef HTC_RAW_INTERFACE
  1756. if (ar->arRawHtc) {
  1757. kfree(ar->arRawHtc);
  1758. ar->arRawHtc = NULL;
  1759. }
  1760. #endif
  1761. /* Free up the device data structure */
  1762. if (unregister && is_netdev_registered) {
  1763. unregister_netdev(dev);
  1764. is_netdev_registered = 0;
  1765. }
  1766. free_netdev(dev);
  1767. ar6k_cfg80211_deinit(ar);
  1768. #ifdef CONFIG_AP_VIRTUL_ADAPTER_SUPPORT
  1769. ar6000_remove_ap_interface();
  1770. #endif /*CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
  1771. kfree(ar->fw_otp);
  1772. kfree(ar->fw);
  1773. kfree(ar->fw_patch);
  1774. kfree(ar->fw_data);
  1775. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("-ar6000_destroy \n"));
  1776. }
  1777. static void disconnect_timer_handler(unsigned long ptr)
  1778. {
  1779. struct net_device *dev = (struct net_device *)ptr;
  1780. struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
  1781. A_UNTIMEOUT(&ar->disconnect_timer);
  1782. ar6000_init_profile_info(ar);
  1783. ar6000_disconnect(ar);
  1784. }
  1785. static void ar6000_detect_error(unsigned long ptr)
  1786. {
  1787. struct net_device *dev = (struct net_device *)ptr;
  1788. struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
  1789. WMI_TARGET_ERROR_REPORT_EVENT errEvent;
  1790. AR6000_SPIN_LOCK(&ar->arLock, 0);
  1791. if (ar->arHBChallengeResp.outstanding) {
  1792. ar->arHBChallengeResp.missCnt++;
  1793. } else {
  1794. ar->arHBChallengeResp.missCnt = 0;
  1795. }
  1796. if (ar->arHBChallengeResp.missCnt > ar->arHBChallengeResp.missThres) {
  1797. /* Send Error Detect event to the application layer and do not reschedule the error detection module timer */
  1798. ar->arHBChallengeResp.missCnt = 0;
  1799. ar->arHBChallengeResp.seqNum = 0;
  1800. errEvent.errorVal = WMI_TARGET_COM_ERR | WMI_TARGET_FATAL_ERR;
  1801. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  1802. return;
  1803. }
  1804. /* Generate the sequence number for the next challenge */
  1805. ar->arHBChallengeResp.seqNum++;
  1806. ar->arHBChallengeResp.outstanding = true;
  1807. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  1808. /* Send the challenge on the control channel */
  1809. if (wmi_get_challenge_resp_cmd(ar->arWmi, ar->arHBChallengeResp.seqNum, DRV_HB_CHALLENGE) != 0) {
  1810. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to send heart beat challenge\n"));
  1811. }
  1812. /* Reschedule the timer for the next challenge */
  1813. A_TIMEOUT_MS(&ar->arHBChallengeResp.timer, ar->arHBChallengeResp.frequency * 1000, 0);
  1814. }
  1815. void ar6000_init_profile_info(struct ar6_softc *ar)
  1816. {
  1817. ar->arSsidLen = 0;
  1818. A_MEMZERO(ar->arSsid, sizeof(ar->arSsid));
  1819. switch(fwmode) {
  1820. case HI_OPTION_FW_MODE_IBSS:
  1821. ar->arNetworkType = ar->arNextMode = ADHOC_NETWORK;
  1822. break;
  1823. case HI_OPTION_FW_MODE_BSS_STA:
  1824. ar->arNetworkType = ar->arNextMode = INFRA_NETWORK;
  1825. break;
  1826. case HI_OPTION_FW_MODE_AP:
  1827. ar->arNetworkType = ar->arNextMode = AP_NETWORK;
  1828. break;
  1829. }
  1830. ar->arDot11AuthMode = OPEN_AUTH;
  1831. ar->arAuthMode = NONE_AUTH;
  1832. ar->arPairwiseCrypto = NONE_CRYPT;
  1833. ar->arPairwiseCryptoLen = 0;
  1834. ar->arGroupCrypto = NONE_CRYPT;
  1835. ar->arGroupCryptoLen = 0;
  1836. A_MEMZERO(ar->arWepKeyList, sizeof(ar->arWepKeyList));
  1837. A_MEMZERO(ar->arReqBssid, sizeof(ar->arReqBssid));
  1838. A_MEMZERO(ar->arBssid, sizeof(ar->arBssid));
  1839. ar->arBssChannel = 0;
  1840. }
  1841. static void
  1842. ar6000_init_control_info(struct ar6_softc *ar)
  1843. {
  1844. ar->arWmiEnabled = false;
  1845. ar6000_init_profile_info(ar);
  1846. ar->arDefTxKeyIndex = 0;
  1847. A_MEMZERO(ar->arWepKeyList, sizeof(ar->arWepKeyList));
  1848. ar->arChannelHint = 0;
  1849. ar->arListenIntervalT = A_DEFAULT_LISTEN_INTERVAL;
  1850. ar->arListenIntervalB = 0;
  1851. ar->arVersion.host_ver = AR6K_SW_VERSION;
  1852. ar->arRssi = 0;
  1853. ar->arTxPwr = 0;
  1854. ar->arTxPwrSet = false;
  1855. ar->arSkipScan = 0;
  1856. ar->arBeaconInterval = 0;
  1857. ar->arBitRate = 0;
  1858. ar->arMaxRetries = 0;
  1859. ar->arWmmEnabled = true;
  1860. ar->intra_bss = 1;
  1861. ar->scan_triggered = 0;
  1862. A_MEMZERO(&ar->scParams, sizeof(ar->scParams));
  1863. ar->scParams.shortScanRatio = WMI_SHORTSCANRATIO_DEFAULT;
  1864. ar->scParams.scanCtrlFlags = DEFAULT_SCAN_CTRL_FLAGS;
  1865. /* Initialize the AP mode state info */
  1866. {
  1867. u8 ctr;
  1868. A_MEMZERO((u8 *)ar->sta_list, AP_MAX_NUM_STA * sizeof(sta_t));
  1869. /* init the Mutexes */
  1870. A_MUTEX_INIT(&ar->mcastpsqLock);
  1871. /* Init the PS queues */
  1872. for (ctr=0; ctr < AP_MAX_NUM_STA ; ctr++) {
  1873. A_MUTEX_INIT(&ar->sta_list[ctr].psqLock);
  1874. A_NETBUF_QUEUE_INIT(&ar->sta_list[ctr].psq);
  1875. }
  1876. ar->ap_profile_flag = 0;
  1877. A_NETBUF_QUEUE_INIT(&ar->mcastpsq);
  1878. memcpy(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3);
  1879. ar->ap_wmode = DEF_AP_WMODE_G;
  1880. ar->ap_dtim_period = DEF_AP_DTIM;
  1881. ar->ap_beacon_interval = DEF_BEACON_INTERVAL;
  1882. }
  1883. }
  1884. static int
  1885. ar6000_open(struct net_device *dev)
  1886. {
  1887. unsigned long flags;
  1888. struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
  1889. spin_lock_irqsave(&ar->arLock, flags);
  1890. if(ar->arWlanState == WLAN_DISABLED) {
  1891. ar->arWlanState = WLAN_ENABLED;
  1892. }
  1893. if( ar->arConnected || bypasswmi) {
  1894. netif_carrier_on(dev);
  1895. /* Wake up the queues */
  1896. netif_wake_queue(dev);
  1897. }
  1898. else
  1899. netif_carrier_off(dev);
  1900. spin_unlock_irqrestore(&ar->arLock, flags);
  1901. return 0;
  1902. }
  1903. static int
  1904. ar6000_close(struct net_device *dev)
  1905. {
  1906. struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
  1907. netif_stop_queue(dev);
  1908. ar6000_disconnect(ar);
  1909. if(ar->arWmiReady == true) {
  1910. if (wmi_scanparams_cmd(ar->arWmi, 0xFFFF, 0,
  1911. 0, 0, 0, 0, 0, 0, 0, 0) != 0) {
  1912. return -EIO;
  1913. }
  1914. ar->arWlanState = WLAN_DISABLED;
  1915. }
  1916. ar6k_cfg80211_scanComplete_event(ar, A_ECANCELED);
  1917. return 0;
  1918. }
  1919. /* connect to a service */
  1920. static int ar6000_connectservice(struct ar6_softc *ar,
  1921. struct htc_service_connect_req *pConnect,
  1922. char *pDesc)
  1923. {
  1924. int status;
  1925. struct htc_service_connect_resp response;
  1926. do {
  1927. A_MEMZERO(&response,sizeof(response));
  1928. status = HTCConnectService(ar->arHtcTarget,
  1929. pConnect,
  1930. &response);
  1931. if (status) {
  1932. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" Failed to connect to %s service status:%d \n",
  1933. pDesc, status));
  1934. break;
  1935. }
  1936. switch (pConnect->ServiceID) {
  1937. case WMI_CONTROL_SVC :
  1938. if (ar->arWmiEnabled) {
  1939. /* set control endpoint for WMI use */
  1940. wmi_set_control_ep(ar->arWmi, response.Endpoint);
  1941. }
  1942. /* save EP for fast lookup */
  1943. ar->arControlEp = response.Endpoint;
  1944. break;
  1945. case WMI_DATA_BE_SVC :
  1946. arSetAc2EndpointIDMap(ar, WMM_AC_BE, response.Endpoint);
  1947. break;
  1948. case WMI_DATA_BK_SVC :
  1949. arSetAc2EndpointIDMap(ar, WMM_AC_BK, response.Endpoint);
  1950. break;
  1951. case WMI_DATA_VI_SVC :
  1952. arSetAc2EndpointIDMap(ar, WMM_AC_VI, response.Endpoint);
  1953. break;
  1954. case WMI_DATA_VO_SVC :
  1955. arSetAc2EndpointIDMap(ar, WMM_AC_VO, response.Endpoint);
  1956. break;
  1957. default:
  1958. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ServiceID not mapped %d\n", pConnect->ServiceID));
  1959. status = A_EINVAL;
  1960. break;
  1961. }
  1962. } while (false);
  1963. return status;
  1964. }
  1965. void ar6000_TxDataCleanup(struct ar6_softc *ar)
  1966. {
  1967. /* flush all the data (non-control) streams
  1968. * we only flush packets that are tagged as data, we leave any control packets that
  1969. * were in the TX queues alone */
  1970. HTCFlushEndpoint(ar->arHtcTarget,
  1971. arAc2EndpointID(ar, WMM_AC_BE),
  1972. AR6K_DATA_PKT_TAG);
  1973. HTCFlushEndpoint(ar->arHtcTarget,
  1974. arAc2EndpointID(ar, WMM_AC_BK),
  1975. AR6K_DATA_PKT_TAG);
  1976. HTCFlushEndpoint(ar->arHtcTarget,
  1977. arAc2EndpointID(ar, WMM_AC_VI),
  1978. AR6K_DATA_PKT_TAG);
  1979. HTCFlushEndpoint(ar->arHtcTarget,
  1980. arAc2EndpointID(ar, WMM_AC_VO),
  1981. AR6K_DATA_PKT_TAG);
  1982. }
  1983. HTC_ENDPOINT_ID
  1984. ar6000_ac2_endpoint_id ( void * devt, u8 ac)
  1985. {
  1986. struct ar6_softc *ar = (struct ar6_softc *) devt;
  1987. return(arAc2EndpointID(ar, ac));
  1988. }
  1989. u8 ar6000_endpoint_id2_ac(void * devt, HTC_ENDPOINT_ID ep )
  1990. {
  1991. struct ar6_softc *ar = (struct ar6_softc *) devt;
  1992. return(arEndpoint2Ac(ar, ep ));
  1993. }
  1994. #if defined(CONFIG_ATH6KL_ENABLE_COEXISTENCE)
  1995. static int ath6kl_config_btcoex_params(struct ar6_softc *ar)
  1996. {
  1997. int r;
  1998. WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD sbcb_cmd;
  1999. WMI_SET_BTCOEX_FE_ANT_CMD sbfa_cmd;
  2000. /* Configure the type of BT collocated with WLAN */
  2001. memset(&sbcb_cmd, 0, sizeof(WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD));
  2002. sbcb_cmd.btcoexCoLocatedBTdev = ATH6KL_BT_DEV;
  2003. r = wmi_set_btcoex_colocated_bt_dev_cmd(ar->arWmi, &sbcb_cmd);
  2004. if (r) {
  2005. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  2006. ("Unable to set collocated BT type\n"));
  2007. return r;
  2008. }
  2009. /* Configure the type of BT collocated with WLAN */
  2010. memset(&sbfa_cmd, 0, sizeof(WMI_SET_BTCOEX_FE_ANT_CMD));
  2011. sbfa_cmd.btcoexFeAntType = ATH6KL_BT_ANTENNA;
  2012. r = wmi_set_btcoex_fe_ant_cmd(ar->arWmi, &sbfa_cmd);
  2013. if (r) {
  2014. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  2015. ("Unable to set fornt end antenna configuration\n"));
  2016. return r;
  2017. }
  2018. return 0;
  2019. }
  2020. #else
  2021. static int ath6kl_config_btcoex_params(struct ar6_softc *ar)
  2022. {
  2023. return 0;
  2024. }
  2025. #endif /* CONFIG_ATH6KL_ENABLE_COEXISTENCE */
  2026. /*
  2027. * This function applies WLAN specific configuration defined in wlan_config.h
  2028. */
  2029. int ar6000_target_config_wlan_params(struct ar6_softc *ar)
  2030. {
  2031. int status = 0;
  2032. #ifdef CONFIG_HOST_TCMD_SUPPORT
  2033. if (ar->arTargetMode != AR6000_WLAN_MODE) {
  2034. return 0;
  2035. }
  2036. #endif /* CONFIG_HOST_TCMD_SUPPORT */
  2037. /*
  2038. * configure the device for rx dot11 header rules 0,0 are the default values
  2039. * therefore this command can be skipped if the inputs are 0,FALSE,FALSE.Required
  2040. * if checksum offload is needed. Set RxMetaVersion to 2
  2041. */
  2042. if ((wmi_set_rx_frame_format_cmd(ar->arWmi,ar->rxMetaVersion, processDot11Hdr, processDot11Hdr)) != 0) {
  2043. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set the rx frame format.\n"));
  2044. status = A_ERROR;
  2045. }
  2046. status = ath6kl_config_btcoex_params(ar);
  2047. if (status)
  2048. return status;
  2049. #if WLAN_CONFIG_IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN
  2050. if ((wmi_pmparams_cmd(ar->arWmi, 0, 1, 0, 0, 1, IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN)) != 0) {
  2051. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set power save fail event policy\n"));
  2052. status = A_ERROR;
  2053. }
  2054. #endif
  2055. #if WLAN_CONFIG_DONOT_IGNORE_BARKER_IN_ERP
  2056. if ((wmi_set_lpreamble_cmd(ar->arWmi, 0, WMI_DONOT_IGNORE_BARKER_IN_ERP)) != 0) {
  2057. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set barker preamble policy\n"));
  2058. status = A_ERROR;
  2059. }
  2060. #endif
  2061. if ((wmi_set_keepalive_cmd(ar->arWmi, WLAN_CONFIG_KEEP_ALIVE_INTERVAL)) != 0) {
  2062. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set keep alive interval\n"));
  2063. status = A_ERROR;
  2064. }
  2065. #if WLAN_CONFIG_DISABLE_11N
  2066. {
  2067. WMI_SET_HT_CAP_CMD htCap;
  2068. memset(&htCap, 0, sizeof(WMI_SET_HT_CAP_CMD));
  2069. htCap.band = 0;
  2070. if ((wmi_set_ht_cap_cmd(ar->arWmi, &htCap)) != 0) {
  2071. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set ht capabilities \n"));
  2072. status = A_ERROR;
  2073. }
  2074. htCap.band = 1;
  2075. if ((wmi_set_ht_cap_cmd(ar->arWmi, &htCap)) != 0) {
  2076. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set ht capabilities \n"));
  2077. status = A_ERROR;
  2078. }
  2079. }
  2080. #endif /* WLAN_CONFIG_DISABLE_11N */
  2081. #ifdef ATH6K_CONFIG_OTA_MODE
  2082. if ((wmi_powermode_cmd(ar->arWmi, MAX_PERF_POWER)) != 0) {
  2083. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set power mode \n"));
  2084. status = A_ERROR;
  2085. }
  2086. #endif
  2087. if ((wmi_disctimeout_cmd(ar->arWmi, WLAN_CONFIG_DISCONNECT_TIMEOUT)) != 0) {
  2088. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set disconnect timeout \n"));
  2089. status = A_ERROR;
  2090. }
  2091. #if WLAN_CONFIG_DISABLE_TX_BURSTING
  2092. if ((wmi_set_wmm_txop(ar->arWmi, WMI_TXOP_DISABLED)) != 0) {
  2093. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set txop bursting \n"));
  2094. status = A_ERROR;
  2095. }
  2096. #endif
  2097. return status;
  2098. }
  2099. /* This function does one time initialization for the lifetime of the device */
  2100. int ar6000_init(struct net_device *dev)
  2101. {
  2102. struct ar6_softc *ar;
  2103. int status;
  2104. s32 timeleft;
  2105. s16 i;
  2106. int ret = 0;
  2107. if((ar = ar6k_priv(dev)) == NULL)
  2108. {
  2109. return -EIO;
  2110. }
  2111. if (wlaninitmode == WLAN_INIT_MODE_USR || wlaninitmode == WLAN_INIT_MODE_DRV) {
  2112. ar6000_update_bdaddr(ar);
  2113. if (enablerssicompensation) {
  2114. ar6000_copy_cust_data_from_target(ar->arHifDevice, ar->arTargetType);
  2115. read_rssi_compensation_param(ar);
  2116. for (i=-95; i<=0; i++) {
  2117. rssi_compensation_table[0-i] = rssi_compensation_calc(ar,i);
  2118. }
  2119. }
  2120. }
  2121. dev_hold(dev);
  2122. rtnl_unlock();
  2123. /* Do we need to finish the BMI phase */
  2124. if ((wlaninitmode == WLAN_INIT_MODE_USR || wlaninitmode == WLAN_INIT_MODE_DRV) &&
  2125. (BMIDone(ar->arHifDevice) != 0))
  2126. {
  2127. ret = -EIO;
  2128. goto ar6000_init_done;
  2129. }
  2130. if (!bypasswmi)
  2131. {
  2132. #if 0 /* TBDXXX */
  2133. if (ar->arVersion.host_ver != ar->arVersion.target_ver) {
  2134. A_PRINTF("WARNING: Host version 0x%x does not match Target "
  2135. " version 0x%x!\n",
  2136. ar->arVersion.host_ver, ar->arVersion.target_ver);
  2137. }
  2138. #endif
  2139. /* Indicate that WMI is enabled (although not ready yet) */
  2140. ar->arWmiEnabled = true;
  2141. if ((ar->arWmi = wmi_init((void *) ar)) == NULL)
  2142. {
  2143. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize WMI.\n", __func__));
  2144. ret = -EIO;
  2145. goto ar6000_init_done;
  2146. }
  2147. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Got WMI @ 0x%lx.\n", __func__,
  2148. (unsigned long) ar->arWmi));
  2149. }
  2150. do {
  2151. struct htc_service_connect_req connect;
  2152. /* the reason we have to wait for the target here is that the driver layer
  2153. * has to init BMI in order to set the host block size,
  2154. */
  2155. status = HTCWaitTarget(ar->arHtcTarget);
  2156. if (status) {
  2157. break;
  2158. }
  2159. A_MEMZERO(&connect,sizeof(connect));
  2160. /* meta data is unused for now */
  2161. connect.pMetaData = NULL;
  2162. connect.MetaDataLength = 0;
  2163. /* these fields are the same for all service endpoints */
  2164. connect.EpCallbacks.pContext = ar;
  2165. connect.EpCallbacks.EpTxCompleteMultiple = ar6000_tx_complete;
  2166. connect.EpCallbacks.EpRecv = ar6000_rx;
  2167. connect.EpCallbacks.EpRecvRefill = ar6000_rx_refill;
  2168. connect.EpCallbacks.EpSendFull = ar6000_tx_queue_full;
  2169. /* set the max queue depth so that our ar6000_tx_queue_full handler gets called.
  2170. * Linux has the peculiarity of not providing flow control between the
  2171. * NIC and the network stack. There is no API to indicate that a TX packet
  2172. * was sent which could provide some back pressure to the network stack.
  2173. * Under linux you would have to wait till the network stack consumed all sk_buffs
  2174. * before any back-flow kicked in. Which isn't very friendly.
  2175. * So we have to manage this ourselves */
  2176. connect.MaxSendQueueDepth = MAX_DEFAULT_SEND_QUEUE_DEPTH;
  2177. connect.EpCallbacks.RecvRefillWaterMark = AR6000_MAX_RX_BUFFERS / 4; /* set to 25 % */
  2178. if (0 == connect.EpCallbacks.RecvRefillWaterMark) {
  2179. connect.EpCallbacks.RecvRefillWaterMark++;
  2180. }
  2181. /* connect to control service */
  2182. connect.ServiceID = WMI_CONTROL_SVC;
  2183. status = ar6000_connectservice(ar,
  2184. &connect,
  2185. "WMI CONTROL");
  2186. if (status) {
  2187. break;
  2188. }
  2189. connect.LocalConnectionFlags |= HTC_LOCAL_CONN_FLAGS_ENABLE_SEND_BUNDLE_PADDING;
  2190. /* limit the HTC message size on the send path, although we can receive A-MSDU frames of
  2191. * 4K, we will only send ethernet-sized (802.3) frames on the send path. */
  2192. connect.MaxSendMsgSize = WMI_MAX_TX_DATA_FRAME_LENGTH;
  2193. /* to reduce the amount of committed memory for larger A_MSDU frames, use the recv-alloc threshold
  2194. * mechanism for larger packets */
  2195. connect.EpCallbacks.RecvAllocThreshold = AR6000_BUFFER_SIZE;
  2196. connect.EpCallbacks.EpRecvAllocThresh = ar6000_alloc_amsdu_rxbuf;
  2197. /* for the remaining data services set the connection flag to reduce dribbling,
  2198. * if configured to do so */
  2199. if (reduce_credit_dribble) {
  2200. connect.ConnectionFlags |= HTC_CONNECT_FLAGS_REDUCE_CREDIT_DRIBBLE;
  2201. /* the credit dribble trigger threshold is (reduce_credit_dribble - 1) for a value
  2202. * of 0-3 */
  2203. connect.ConnectionFlags &= ~HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK;
  2204. connect.ConnectionFlags |=
  2205. ((u16)reduce_credit_dribble - 1) & HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK;
  2206. }
  2207. /* connect to best-effort service */
  2208. connect.ServiceID = WMI_DATA_BE_SVC;
  2209. status = ar6000_connectservice(ar,
  2210. &connect,
  2211. "WMI DATA BE");
  2212. if (status) {
  2213. break;
  2214. }
  2215. /* connect to back-ground
  2216. * map this to WMI LOW_PRI */
  2217. connect.ServiceID = WMI_DATA_BK_SVC;
  2218. status = ar6000_connectservice(ar,
  2219. &connect,
  2220. "WMI DATA BK");
  2221. if (status) {
  2222. break;
  2223. }
  2224. /* connect to Video service, map this to
  2225. * to HI PRI */
  2226. connect.ServiceID = WMI_DATA_VI_SVC;
  2227. status = ar6000_connectservice(ar,
  2228. &connect,
  2229. "WMI DATA VI");
  2230. if (status) {
  2231. break;
  2232. }
  2233. /* connect to VO service, this is currently not
  2234. * mapped to a WMI priority stream due to historical reasons.
  2235. * WMI originally defined 3 priorities over 3 mailboxes
  2236. * We can change this when WMI is reworked so that priorities are not
  2237. * dependent on mailboxes */
  2238. connect.ServiceID = WMI_DATA_VO_SVC;
  2239. status = ar6000_connectservice(ar,
  2240. &connect,
  2241. "WMI DATA VO");
  2242. if (status) {
  2243. break;
  2244. }
  2245. A_ASSERT(arAc2EndpointID(ar,WMM_AC_BE) != 0);
  2246. A_ASSERT(arAc2EndpointID(ar,WMM_AC_BK) != 0);
  2247. A_ASSERT(arAc2EndpointID(ar,WMM_AC_VI) != 0);
  2248. A_ASSERT(arAc2EndpointID(ar,WMM_AC_VO) != 0);
  2249. /* setup access class priority mappings */
  2250. ar->arAcStreamPriMap[WMM_AC_BK] = 0; /* lowest */
  2251. ar->arAcStreamPriMap[WMM_AC_BE] = 1; /* */
  2252. ar->arAcStreamPriMap[WMM_AC_VI] = 2; /* */
  2253. ar->arAcStreamPriMap[WMM_AC_VO] = 3; /* highest */
  2254. #ifdef EXPORT_HCI_BRIDGE_INTERFACE
  2255. if (setuphci && (NULL != ar6kHciTransCallbacks.setupTransport)) {
  2256. struct hci_transport_misc_handles hciHandles;
  2257. hciHandles.netDevice = ar->arNetDev;
  2258. hciHandles.hifDevice = ar->arHifDevice;
  2259. hciHandles.htcHandle = ar->arHtcTarget;
  2260. status = (int)(ar6kHciTransCallbacks.setupTransport(&hciHandles));
  2261. }
  2262. #else
  2263. if (setuphci) {
  2264. /* setup HCI */
  2265. status = ar6000_setup_hci(ar);
  2266. }
  2267. #endif
  2268. } while (false);
  2269. if (status) {
  2270. ret = -EIO;
  2271. goto ar6000_init_done;
  2272. }
  2273. if (regscanmode) {
  2274. u32 param;
  2275. if (BMIReadMemory(ar->arHifDevice,
  2276. HOST_INTEREST_ITEM_ADDRESS(ar,
  2277. hi_option_flag),
  2278. (u8 *)&param,
  2279. 4) != 0) {
  2280. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  2281. ("BMIReadMemory forsetting "
  2282. "regscanmode failed\n"));
  2283. return A_ERROR;
  2284. }
  2285. if (regscanmode == 1)
  2286. param |= HI_OPTION_SKIP_REG_SCAN;
  2287. else if (regscanmode == 2)
  2288. param |= HI_OPTION_INIT_REG_SCAN;
  2289. if (BMIWriteMemory(ar->arHifDevice,
  2290. HOST_INTEREST_ITEM_ADDRESS(ar,
  2291. hi_option_flag),
  2292. (u8 *)&param,
  2293. 4) != 0) {
  2294. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  2295. ("BMIWriteMemory forsetting "
  2296. "regscanmode failed\n"));
  2297. return A_ERROR;
  2298. }
  2299. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Regulatory scan mode set\n"));
  2300. }
  2301. /*
  2302. * give our connected endpoints some buffers
  2303. */
  2304. ar6000_rx_refill(ar, ar->arControlEp);
  2305. ar6000_rx_refill(ar, arAc2EndpointID(ar,WMM_AC_BE));
  2306. /*
  2307. * We will post the receive buffers only for SPE or endpoint ping testing so we are
  2308. * making it conditional on the 'bypasswmi' flag.
  2309. */
  2310. if (bypasswmi) {
  2311. ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_BK));
  2312. ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_VI));
  2313. ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_VO));
  2314. }
  2315. /* allocate some buffers that handle larger AMSDU frames */
  2316. ar6000_refill_amsdu_rxbufs(ar,AR6000_MAX_AMSDU_RX_BUFFERS);
  2317. /* setup credit distribution */
  2318. ar6000_setup_credit_dist(ar->arHtcTarget, &ar->arCreditStateInfo);
  2319. /* Since cookies are used for HTC transports, they should be */
  2320. /* initialized prior to enabling HTC. */
  2321. ar6000_cookie_init(ar);
  2322. /* start HTC */
  2323. status = HTCStart(ar->arHtcTarget);
  2324. if (status) {
  2325. if (ar->arWmiEnabled == true) {
  2326. wmi_shutdown(ar->arWmi);
  2327. ar->arWmiEnabled = false;
  2328. ar->arWmi = NULL;
  2329. }
  2330. ar6000_cookie_cleanup(ar);
  2331. ret = -EIO;
  2332. goto ar6000_init_done;
  2333. }
  2334. if (!bypasswmi) {
  2335. /* Wait for Wmi event to be ready */
  2336. timeleft = wait_event_interruptible_timeout(arEvent,
  2337. (ar->arWmiReady == true), wmitimeout * HZ);
  2338. if (ar->arVersion.abi_ver != AR6K_ABI_VERSION) {
  2339. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ABI Version mismatch: Host(0x%x), Target(0x%x)\n", AR6K_ABI_VERSION, ar->arVersion.abi_ver));
  2340. #ifndef ATH6K_SKIP_ABI_VERSION_CHECK
  2341. ret = -EIO;
  2342. goto ar6000_init_done;
  2343. #endif /* ATH6K_SKIP_ABI_VERSION_CHECK */
  2344. }
  2345. if(!timeleft || signal_pending(current))
  2346. {
  2347. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI is not ready or wait was interrupted\n"));
  2348. ret = -EIO;
  2349. goto ar6000_init_done;
  2350. }
  2351. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() WMI is ready\n", __func__));
  2352. /* Communicate the wmi protocol verision to the target */
  2353. if ((ar6000_set_host_app_area(ar)) != 0) {
  2354. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set the host app area\n"));
  2355. }
  2356. ar6000_target_config_wlan_params(ar);
  2357. }
  2358. ar->arNumDataEndPts = 1;
  2359. if (bypasswmi) {
  2360. /* for tests like endpoint ping, the MAC address needs to be non-zero otherwise
  2361. * the data path through a raw socket is disabled */
  2362. dev->dev_addr[0] = 0x00;
  2363. dev->dev_addr[1] = 0x01;
  2364. dev->dev_addr[2] = 0x02;
  2365. dev->dev_addr[3] = 0xAA;
  2366. dev->dev_addr[4] = 0xBB;
  2367. dev->dev_addr[5] = 0xCC;
  2368. }
  2369. ar6000_init_done:
  2370. rtnl_lock();
  2371. dev_put(dev);
  2372. return ret;
  2373. }
  2374. void
  2375. ar6000_bitrate_rx(void *devt, s32 rateKbps)
  2376. {
  2377. struct ar6_softc *ar = (struct ar6_softc *)devt;
  2378. ar->arBitRate = rateKbps;
  2379. wake_up(&arEvent);
  2380. }
  2381. void
  2382. ar6000_ratemask_rx(void *devt, u32 ratemask)
  2383. {
  2384. struct ar6_softc *ar = (struct ar6_softc *)devt;
  2385. ar->arRateMask = ratemask;
  2386. wake_up(&arEvent);
  2387. }
  2388. void
  2389. ar6000_txPwr_rx(void *devt, u8 txPwr)
  2390. {
  2391. struct ar6_softc *ar = (struct ar6_softc *)devt;
  2392. ar->arTxPwr = txPwr;
  2393. wake_up(&arEvent);
  2394. }
  2395. void
  2396. ar6000_channelList_rx(void *devt, s8 numChan, u16 *chanList)
  2397. {
  2398. struct ar6_softc *ar = (struct ar6_softc *)devt;
  2399. memcpy(ar->arChannelList, chanList, numChan * sizeof (u16));
  2400. ar->arNumChannels = numChan;
  2401. wake_up(&arEvent);
  2402. }
  2403. u8 ar6000_ibss_map_epid(struct sk_buff *skb, struct net_device *dev, u32 *mapNo)
  2404. {
  2405. struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
  2406. u8 *datap;
  2407. ATH_MAC_HDR *macHdr;
  2408. u32 i, eptMap;
  2409. (*mapNo) = 0;
  2410. datap = A_NETBUF_DATA(skb);
  2411. macHdr = (ATH_MAC_HDR *)(datap + sizeof(WMI_DATA_HDR));
  2412. if (IEEE80211_IS_MULTICAST(macHdr->dstMac)) {
  2413. return ENDPOINT_2;
  2414. }
  2415. eptMap = -1;
  2416. for (i = 0; i < ar->arNodeNum; i ++) {
  2417. if (IEEE80211_ADDR_EQ(macHdr->dstMac, ar->arNodeMap[i].macAddress)) {
  2418. (*mapNo) = i + 1;
  2419. ar->arNodeMap[i].txPending ++;
  2420. return ar->arNodeMap[i].epId;
  2421. }
  2422. if ((eptMap == -1) && !ar->arNodeMap[i].txPending) {
  2423. eptMap = i;
  2424. }
  2425. }
  2426. if (eptMap == -1) {
  2427. eptMap = ar->arNodeNum;
  2428. ar->arNodeNum ++;
  2429. A_ASSERT(ar->arNodeNum <= MAX_NODE_NUM);
  2430. }
  2431. memcpy(ar->arNodeMap[eptMap].macAddress, macHdr->dstMac, IEEE80211_ADDR_LEN);
  2432. for (i = ENDPOINT_2; i <= ENDPOINT_5; i ++) {
  2433. if (!ar->arTxPending[i]) {
  2434. ar->arNodeMap[eptMap].epId = i;
  2435. break;
  2436. }
  2437. // No free endpoint is available, start redistribution on the inuse endpoints.
  2438. if (i == ENDPOINT_5) {
  2439. ar->arNodeMap[eptMap].epId = ar->arNexEpId;
  2440. ar->arNexEpId ++;
  2441. if (ar->arNexEpId > ENDPOINT_5) {
  2442. ar->arNexEpId = ENDPOINT_2;
  2443. }
  2444. }
  2445. }
  2446. (*mapNo) = eptMap + 1;
  2447. ar->arNodeMap[eptMap].txPending ++;
  2448. return ar->arNodeMap[eptMap].epId;
  2449. }
  2450. #ifdef DEBUG
  2451. static void ar6000_dump_skb(struct sk_buff *skb)
  2452. {
  2453. u_char *ch;
  2454. for (ch = A_NETBUF_DATA(skb);
  2455. (unsigned long)ch < ((unsigned long)A_NETBUF_DATA(skb) +
  2456. A_NETBUF_LEN(skb)); ch++)
  2457. {
  2458. AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("%2.2x ", *ch));
  2459. }
  2460. AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("\n"));
  2461. }
  2462. #endif
  2463. #ifdef HTC_TEST_SEND_PKTS
  2464. static void DoHTCSendPktsTest(struct ar6_softc *ar, int MapNo, HTC_ENDPOINT_ID eid, struct sk_buff *skb);
  2465. #endif
  2466. static int
  2467. ar6000_data_tx(struct sk_buff *skb, struct net_device *dev)
  2468. {
  2469. #define AC_NOT_MAPPED 99
  2470. struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
  2471. u8 ac = AC_NOT_MAPPED;
  2472. HTC_ENDPOINT_ID eid = ENDPOINT_UNUSED;
  2473. u32 mapNo = 0;
  2474. int len;
  2475. struct ar_cookie *cookie;
  2476. bool checkAdHocPsMapping = false,bMoreData = false;
  2477. HTC_TX_TAG htc_tag = AR6K_DATA_PKT_TAG;
  2478. u8 dot11Hdr = processDot11Hdr;
  2479. #ifdef CONFIG_PM
  2480. if (ar->arWowState != WLAN_WOW_STATE_NONE) {
  2481. A_NETBUF_FREE(skb);
  2482. return 0;
  2483. }
  2484. #endif /* CONFIG_PM */
  2485. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar6000_data_tx start - skb=0x%lx, data=0x%lx, len=0x%x\n",
  2486. (unsigned long)skb, (unsigned long)A_NETBUF_DATA(skb),
  2487. A_NETBUF_LEN(skb)));
  2488. /* If target is not associated */
  2489. if( (!ar->arConnected && !bypasswmi)
  2490. #ifdef CONFIG_HOST_TCMD_SUPPORT
  2491. /* TCMD doesn't support any data, free the buf and return */
  2492. || (ar->arTargetMode == AR6000_TCMD_MODE)
  2493. #endif
  2494. ) {
  2495. A_NETBUF_FREE(skb);
  2496. return 0;
  2497. }
  2498. do {
  2499. if (ar->arWmiReady == false && bypasswmi == 0) {
  2500. break;
  2501. }
  2502. #ifdef BLOCK_TX_PATH_FLAG
  2503. if (blocktx) {
  2504. break;
  2505. }
  2506. #endif /* BLOCK_TX_PATH_FLAG */
  2507. /* AP mode Power save processing */
  2508. /* If the dst STA is in sleep state, queue the pkt in its PS queue */
  2509. if (ar->arNetworkType == AP_NETWORK) {
  2510. ATH_MAC_HDR *datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb);
  2511. sta_t *conn = NULL;
  2512. /* If the dstMac is a Multicast address & atleast one of the
  2513. * associated STA is in PS mode, then queue the pkt to the
  2514. * mcastq
  2515. */
  2516. if (IEEE80211_IS_MULTICAST(datap->dstMac)) {
  2517. u8 ctr=0;
  2518. bool qMcast=false;
  2519. for (ctr=0; ctr<AP_MAX_NUM_STA; ctr++) {
  2520. if (STA_IS_PWR_SLEEP((&ar->sta_list[ctr]))) {
  2521. qMcast = true;
  2522. }
  2523. }
  2524. if(qMcast) {
  2525. /* If this transmit is not because of a Dtim Expiry q it */
  2526. if (ar->DTIMExpired == false) {
  2527. bool isMcastqEmpty = false;
  2528. A_MUTEX_LOCK(&ar->mcastpsqLock);
  2529. isMcastqEmpty = A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq);
  2530. A_NETBUF_ENQUEUE(&ar->mcastpsq, skb);
  2531. A_MUTEX_UNLOCK(&ar->mcastpsqLock);
  2532. /* If this is the first Mcast pkt getting queued
  2533. * indicate to the target to set the BitmapControl LSB
  2534. * of the TIM IE.
  2535. */
  2536. if (isMcastqEmpty) {
  2537. wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 1);
  2538. }
  2539. return 0;
  2540. } else {
  2541. /* This transmit is because of Dtim expiry. Determine if
  2542. * MoreData bit has to be set.
  2543. */
  2544. A_MUTEX_LOCK(&ar->mcastpsqLock);
  2545. if(!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) {
  2546. bMoreData = true;
  2547. }
  2548. A_MUTEX_UNLOCK(&ar->mcastpsqLock);
  2549. }
  2550. }
  2551. } else {
  2552. conn = ieee80211_find_conn(ar, datap->dstMac);
  2553. if (conn) {
  2554. if (STA_IS_PWR_SLEEP(conn)) {
  2555. /* If this transmit is not because of a PsPoll q it*/
  2556. if (!STA_IS_PS_POLLED(conn)) {
  2557. bool isPsqEmpty = false;
  2558. /* Queue the frames if the STA is sleeping */
  2559. A_MUTEX_LOCK(&conn->psqLock);
  2560. isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq);
  2561. A_NETBUF_ENQUEUE(&conn->psq, skb);
  2562. A_MUTEX_UNLOCK(&conn->psqLock);
  2563. /* If this is the first pkt getting queued
  2564. * for this STA, update the PVB for this STA
  2565. */
  2566. if (isPsqEmpty) {
  2567. wmi_set_pvb_cmd(ar->arWmi, conn->aid, 1);
  2568. }
  2569. return 0;
  2570. } else {
  2571. /* This tx is because of a PsPoll. Determine if
  2572. * MoreData bit has to be set
  2573. */
  2574. A_MUTEX_LOCK(&conn->psqLock);
  2575. if (!A_NETBUF_QUEUE_EMPTY(&conn->psq)) {
  2576. bMoreData = true;
  2577. }
  2578. A_MUTEX_UNLOCK(&conn->psqLock);
  2579. }
  2580. }
  2581. } else {
  2582. /* non existent STA. drop the frame */
  2583. A_NETBUF_FREE(skb);
  2584. return 0;
  2585. }
  2586. }
  2587. }
  2588. if (ar->arWmiEnabled) {
  2589. u8 csumStart=0;
  2590. u8 csumDest=0;
  2591. u8 csum=skb->ip_summed;
  2592. if(csumOffload && (csum==CHECKSUM_PARTIAL)){
  2593. csumStart = (skb->head + skb->csum_start - skb_network_header(skb) +
  2594. sizeof(ATH_LLC_SNAP_HDR));
  2595. csumDest=skb->csum_offset+csumStart;
  2596. }
  2597. if (A_NETBUF_HEADROOM(skb) < dev->hard_header_len - LINUX_HACK_FUDGE_FACTOR) {
  2598. struct sk_buff *newbuf;
  2599. /*
  2600. * We really should have gotten enough headroom but sometimes
  2601. * we still get packets with not enough headroom. Copy the packet.
  2602. */
  2603. len = A_NETBUF_LEN(skb);
  2604. newbuf = A_NETBUF_ALLOC(len);
  2605. if (newbuf == NULL) {
  2606. break;
  2607. }
  2608. A_NETBUF_PUT(newbuf, len);
  2609. memcpy(A_NETBUF_DATA(newbuf), A_NETBUF_DATA(skb), len);
  2610. A_NETBUF_FREE(skb);
  2611. skb = newbuf;
  2612. /* fall through and assemble header */
  2613. }
  2614. if (dot11Hdr) {
  2615. if (wmi_dot11_hdr_add(ar->arWmi,skb,ar->arNetworkType) != 0) {
  2616. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx-wmi_dot11_hdr_add failed\n"));
  2617. break;
  2618. }
  2619. } else {
  2620. if (wmi_dix_2_dot3(ar->arWmi, skb) != 0) {
  2621. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_dix_2_dot3 failed\n"));
  2622. break;
  2623. }
  2624. }
  2625. if(csumOffload && (csum ==CHECKSUM_PARTIAL)){
  2626. WMI_TX_META_V2 metaV2;
  2627. metaV2.csumStart =csumStart;
  2628. metaV2.csumDest = csumDest;
  2629. metaV2.csumFlags = 0x1;/*instruct target to calculate checksum*/
  2630. if (wmi_data_hdr_add(ar->arWmi, skb, DATA_MSGTYPE, bMoreData, dot11Hdr,
  2631. WMI_META_VERSION_2,&metaV2) != 0) {
  2632. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_data_hdr_add failed\n"));
  2633. break;
  2634. }
  2635. }
  2636. else
  2637. {
  2638. if (wmi_data_hdr_add(ar->arWmi, skb, DATA_MSGTYPE, bMoreData, dot11Hdr,0,NULL) != 0) {
  2639. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_data_hdr_add failed\n"));
  2640. break;
  2641. }
  2642. }
  2643. if ((ar->arNetworkType == ADHOC_NETWORK) &&
  2644. ar->arIbssPsEnable && ar->arConnected) {
  2645. /* flag to check adhoc mapping once we take the lock below: */
  2646. checkAdHocPsMapping = true;
  2647. } else {
  2648. /* get the stream mapping */
  2649. ac = wmi_implicit_create_pstream(ar->arWmi, skb, 0, ar->arWmmEnabled);
  2650. }
  2651. } else {
  2652. EPPING_HEADER *eppingHdr;
  2653. eppingHdr = A_NETBUF_DATA(skb);
  2654. if (IS_EPPING_PACKET(eppingHdr)) {
  2655. /* the stream ID is mapped to an access class */
  2656. ac = eppingHdr->StreamNo_h;
  2657. /* some EPPING packets cannot be dropped no matter what access class it was
  2658. * sent on. We can change the packet tag to guarantee it will not get dropped */
  2659. if (IS_EPING_PACKET_NO_DROP(eppingHdr)) {
  2660. htc_tag = AR6K_CONTROL_PKT_TAG;
  2661. }
  2662. if (ac == HCI_TRANSPORT_STREAM_NUM) {
  2663. /* pass this to HCI */
  2664. #ifndef EXPORT_HCI_BRIDGE_INTERFACE
  2665. if (!hci_test_send(ar,skb)) {
  2666. return 0;
  2667. }
  2668. #endif
  2669. /* set AC to discard this skb */
  2670. ac = AC_NOT_MAPPED;
  2671. } else {
  2672. /* a quirk of linux, the payload of the frame is 32-bit aligned and thus the addition
  2673. * of the HTC header will mis-align the start of the HTC frame, so we add some
  2674. * padding which will be stripped off in the target */
  2675. if (EPPING_ALIGNMENT_PAD > 0) {
  2676. A_NETBUF_PUSH(skb, EPPING_ALIGNMENT_PAD);
  2677. }
  2678. }
  2679. } else {
  2680. /* not a ping packet, drop it */
  2681. ac = AC_NOT_MAPPED;
  2682. }
  2683. }
  2684. } while (false);
  2685. /* did we succeed ? */
  2686. if ((ac == AC_NOT_MAPPED) && !checkAdHocPsMapping) {
  2687. /* cleanup and exit */
  2688. A_NETBUF_FREE(skb);
  2689. AR6000_STAT_INC(ar, tx_dropped);
  2690. AR6000_STAT_INC(ar, tx_aborted_errors);
  2691. return 0;
  2692. }
  2693. cookie = NULL;
  2694. /* take the lock to protect driver data */
  2695. AR6000_SPIN_LOCK(&ar->arLock, 0);
  2696. do {
  2697. if (checkAdHocPsMapping) {
  2698. eid = ar6000_ibss_map_epid(skb, dev, &mapNo);
  2699. }else {
  2700. eid = arAc2EndpointID (ar, ac);
  2701. }
  2702. /* validate that the endpoint is connected */
  2703. if (eid == 0 || eid == ENDPOINT_UNUSED ) {
  2704. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" eid %d is NOT mapped!\n", eid));
  2705. break;
  2706. }
  2707. /* allocate resource for this packet */
  2708. cookie = ar6000_alloc_cookie(ar);
  2709. if (cookie != NULL) {
  2710. /* update counts while the lock is held */
  2711. ar->arTxPending[eid]++;
  2712. ar->arTotalTxDataPending++;
  2713. }
  2714. } while (false);
  2715. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  2716. if (cookie != NULL) {
  2717. cookie->arc_bp[0] = (unsigned long)skb;
  2718. cookie->arc_bp[1] = mapNo;
  2719. SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
  2720. cookie,
  2721. A_NETBUF_DATA(skb),
  2722. A_NETBUF_LEN(skb),
  2723. eid,
  2724. htc_tag);
  2725. #ifdef DEBUG
  2726. if (debugdriver >= 3) {
  2727. ar6000_dump_skb(skb);
  2728. }
  2729. #endif
  2730. #ifdef HTC_TEST_SEND_PKTS
  2731. DoHTCSendPktsTest(ar,mapNo,eid,skb);
  2732. #endif
  2733. /* HTC interface is asynchronous, if this fails, cleanup will happen in
  2734. * the ar6000_tx_complete callback */
  2735. HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt);
  2736. } else {
  2737. /* no packet to send, cleanup */
  2738. A_NETBUF_FREE(skb);
  2739. AR6000_STAT_INC(ar, tx_dropped);
  2740. AR6000_STAT_INC(ar, tx_aborted_errors);
  2741. }
  2742. return 0;
  2743. }
  2744. int
  2745. ar6000_acl_data_tx(struct sk_buff *skb, struct net_device *dev)
  2746. {
  2747. struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
  2748. struct ar_cookie *cookie;
  2749. HTC_ENDPOINT_ID eid = ENDPOINT_UNUSED;
  2750. cookie = NULL;
  2751. AR6000_SPIN_LOCK(&ar->arLock, 0);
  2752. /* For now we send ACL on BE endpoint: We can also have a dedicated EP */
  2753. eid = arAc2EndpointID (ar, 0);
  2754. /* allocate resource for this packet */
  2755. cookie = ar6000_alloc_cookie(ar);
  2756. if (cookie != NULL) {
  2757. /* update counts while the lock is held */
  2758. ar->arTxPending[eid]++;
  2759. ar->arTotalTxDataPending++;
  2760. }
  2761. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  2762. if (cookie != NULL) {
  2763. cookie->arc_bp[0] = (unsigned long)skb;
  2764. cookie->arc_bp[1] = 0;
  2765. SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
  2766. cookie,
  2767. A_NETBUF_DATA(skb),
  2768. A_NETBUF_LEN(skb),
  2769. eid,
  2770. AR6K_DATA_PKT_TAG);
  2771. /* HTC interface is asynchronous, if this fails, cleanup will happen in
  2772. * the ar6000_tx_complete callback */
  2773. HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt);
  2774. } else {
  2775. /* no packet to send, cleanup */
  2776. A_NETBUF_FREE(skb);
  2777. AR6000_STAT_INC(ar, tx_dropped);
  2778. AR6000_STAT_INC(ar, tx_aborted_errors);
  2779. }
  2780. return 0;
  2781. }
  2782. #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
  2783. static void
  2784. tvsub(register struct timeval *out, register struct timeval *in)
  2785. {
  2786. if((out->tv_usec -= in->tv_usec) < 0) {
  2787. out->tv_sec--;
  2788. out->tv_usec += 1000000;
  2789. }
  2790. out->tv_sec -= in->tv_sec;
  2791. }
  2792. void
  2793. applyAPTCHeuristics(struct ar6_softc *ar)
  2794. {
  2795. u32 duration;
  2796. u32 numbytes;
  2797. u32 throughput;
  2798. struct timeval ts;
  2799. int status;
  2800. AR6000_SPIN_LOCK(&ar->arLock, 0);
  2801. if ((enableAPTCHeuristics) && (!aptcTR.timerScheduled)) {
  2802. do_gettimeofday(&ts);
  2803. tvsub(&ts, &aptcTR.samplingTS);
  2804. duration = ts.tv_sec * 1000 + ts.tv_usec / 1000; /* ms */
  2805. numbytes = aptcTR.bytesTransmitted + aptcTR.bytesReceived;
  2806. if (duration > APTC_TRAFFIC_SAMPLING_INTERVAL) {
  2807. /* Initialize the time stamp and byte count */
  2808. aptcTR.bytesTransmitted = aptcTR.bytesReceived = 0;
  2809. do_gettimeofday(&aptcTR.samplingTS);
  2810. /* Calculate and decide based on throughput thresholds */
  2811. throughput = ((numbytes * 8) / duration);
  2812. if (throughput > APTC_UPPER_THROUGHPUT_THRESHOLD) {
  2813. /* Disable Sleep and schedule a timer */
  2814. A_ASSERT(ar->arWmiReady == true);
  2815. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  2816. status = wmi_powermode_cmd(ar->arWmi, MAX_PERF_POWER);
  2817. AR6000_SPIN_LOCK(&ar->arLock, 0);
  2818. A_TIMEOUT_MS(&aptcTimer, APTC_TRAFFIC_SAMPLING_INTERVAL, 0);
  2819. aptcTR.timerScheduled = true;
  2820. }
  2821. }
  2822. }
  2823. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  2824. }
  2825. #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
  2826. static HTC_SEND_FULL_ACTION ar6000_tx_queue_full(void *Context, struct htc_packet *pPacket)
  2827. {
  2828. struct ar6_softc *ar = (struct ar6_softc *)Context;
  2829. HTC_SEND_FULL_ACTION action = HTC_SEND_FULL_KEEP;
  2830. bool stopNet = false;
  2831. HTC_ENDPOINT_ID Endpoint = HTC_GET_ENDPOINT_FROM_PKT(pPacket);
  2832. do {
  2833. if (bypasswmi) {
  2834. int accessClass;
  2835. if (HTC_GET_TAG_FROM_PKT(pPacket) == AR6K_CONTROL_PKT_TAG) {
  2836. /* don't drop special control packets */
  2837. break;
  2838. }
  2839. accessClass = arEndpoint2Ac(ar,Endpoint);
  2840. /* for endpoint ping testing drop Best Effort and Background */
  2841. if ((accessClass == WMM_AC_BE) || (accessClass == WMM_AC_BK)) {
  2842. action = HTC_SEND_FULL_DROP;
  2843. stopNet = false;
  2844. } else {
  2845. /* keep but stop the netqueues */
  2846. stopNet = true;
  2847. }
  2848. break;
  2849. }
  2850. if (Endpoint == ar->arControlEp) {
  2851. /* under normal WMI if this is getting full, then something is running rampant
  2852. * the host should not be exhausting the WMI queue with too many commands
  2853. * the only exception to this is during testing using endpointping */
  2854. AR6000_SPIN_LOCK(&ar->arLock, 0);
  2855. /* set flag to handle subsequent messages */
  2856. ar->arWMIControlEpFull = true;
  2857. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  2858. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI Control Endpoint is FULL!!! \n"));
  2859. /* no need to stop the network */
  2860. stopNet = false;
  2861. break;
  2862. }
  2863. /* if we get here, we are dealing with data endpoints getting full */
  2864. if (HTC_GET_TAG_FROM_PKT(pPacket) == AR6K_CONTROL_PKT_TAG) {
  2865. /* don't drop control packets issued on ANY data endpoint */
  2866. break;
  2867. }
  2868. if (ar->arNetworkType == ADHOC_NETWORK) {
  2869. /* in adhoc mode, we cannot differentiate traffic priorities so there is no need to
  2870. * continue, however we should stop the network */
  2871. stopNet = true;
  2872. break;
  2873. }
  2874. /* the last MAX_HI_COOKIE_NUM "batch" of cookies are reserved for the highest
  2875. * active stream */
  2876. if (ar->arAcStreamPriMap[arEndpoint2Ac(ar,Endpoint)] < ar->arHiAcStreamActivePri &&
  2877. ar->arCookieCount <= MAX_HI_COOKIE_NUM) {
  2878. /* this stream's priority is less than the highest active priority, we
  2879. * give preference to the highest priority stream by directing
  2880. * HTC to drop the packet that overflowed */
  2881. action = HTC_SEND_FULL_DROP;
  2882. /* since we are dropping packets, no need to stop the network */
  2883. stopNet = false;
  2884. break;
  2885. }
  2886. } while (false);
  2887. if (stopNet) {
  2888. AR6000_SPIN_LOCK(&ar->arLock, 0);
  2889. ar->arNetQueueStopped = true;
  2890. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  2891. /* one of the data endpoints queues is getting full..need to stop network stack
  2892. * the queue will resume in ar6000_tx_complete() */
  2893. netif_stop_queue(ar->arNetDev);
  2894. }
  2895. return action;
  2896. }
  2897. static void
  2898. ar6000_tx_complete(void *Context, struct htc_packet_queue *pPacketQueue)
  2899. {
  2900. struct ar6_softc *ar = (struct ar6_softc *)Context;
  2901. u32 mapNo = 0;
  2902. int status;
  2903. struct ar_cookie * ar_cookie;
  2904. HTC_ENDPOINT_ID eid;
  2905. bool wakeEvent = false;
  2906. struct sk_buff_head skb_queue;
  2907. struct htc_packet *pPacket;
  2908. struct sk_buff *pktSkb;
  2909. bool flushing = false;
  2910. skb_queue_head_init(&skb_queue);
  2911. /* lock the driver as we update internal state */
  2912. AR6000_SPIN_LOCK(&ar->arLock, 0);
  2913. /* reap completed packets */
  2914. while (!HTC_QUEUE_EMPTY(pPacketQueue)) {
  2915. pPacket = HTC_PACKET_DEQUEUE(pPacketQueue);
  2916. ar_cookie = (struct ar_cookie *)pPacket->pPktContext;
  2917. A_ASSERT(ar_cookie);
  2918. status = pPacket->Status;
  2919. pktSkb = (struct sk_buff *)ar_cookie->arc_bp[0];
  2920. eid = pPacket->Endpoint;
  2921. mapNo = ar_cookie->arc_bp[1];
  2922. A_ASSERT(pktSkb);
  2923. A_ASSERT(pPacket->pBuffer == A_NETBUF_DATA(pktSkb));
  2924. /* add this to the list, use faster non-lock API */
  2925. __skb_queue_tail(&skb_queue,pktSkb);
  2926. if (!status) {
  2927. A_ASSERT(pPacket->ActualLength == A_NETBUF_LEN(pktSkb));
  2928. }
  2929. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar6000_tx_complete skb=0x%lx data=0x%lx len=0x%x eid=%d ",
  2930. (unsigned long)pktSkb, (unsigned long)pPacket->pBuffer,
  2931. pPacket->ActualLength,
  2932. eid));
  2933. ar->arTxPending[eid]--;
  2934. if ((eid != ar->arControlEp) || bypasswmi) {
  2935. ar->arTotalTxDataPending--;
  2936. }
  2937. if (eid == ar->arControlEp)
  2938. {
  2939. if (ar->arWMIControlEpFull) {
  2940. /* since this packet completed, the WMI EP is no longer full */
  2941. ar->arWMIControlEpFull = false;
  2942. }
  2943. if (ar->arTxPending[eid] == 0) {
  2944. wakeEvent = true;
  2945. }
  2946. }
  2947. if (status) {
  2948. if (status == A_ECANCELED) {
  2949. /* a packet was flushed */
  2950. flushing = true;
  2951. }
  2952. AR6000_STAT_INC(ar, tx_errors);
  2953. if (status != A_NO_RESOURCE) {
  2954. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() -TX ERROR, status: 0x%x\n", __func__,
  2955. status));
  2956. }
  2957. } else {
  2958. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("OK\n"));
  2959. flushing = false;
  2960. AR6000_STAT_INC(ar, tx_packets);
  2961. ar->arNetStats.tx_bytes += A_NETBUF_LEN(pktSkb);
  2962. #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
  2963. aptcTR.bytesTransmitted += a_netbuf_to_len(pktSkb);
  2964. applyAPTCHeuristics(ar);
  2965. #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
  2966. }
  2967. // TODO this needs to be looked at
  2968. if ((ar->arNetworkType == ADHOC_NETWORK) && ar->arIbssPsEnable
  2969. && (eid != ar->arControlEp) && mapNo)
  2970. {
  2971. mapNo --;
  2972. ar->arNodeMap[mapNo].txPending --;
  2973. if (!ar->arNodeMap[mapNo].txPending && (mapNo == (ar->arNodeNum - 1))) {
  2974. u32 i;
  2975. for (i = ar->arNodeNum; i > 0; i --) {
  2976. if (!ar->arNodeMap[i - 1].txPending) {
  2977. A_MEMZERO(&ar->arNodeMap[i - 1], sizeof(struct ar_node_mapping));
  2978. ar->arNodeNum --;
  2979. } else {
  2980. break;
  2981. }
  2982. }
  2983. }
  2984. }
  2985. ar6000_free_cookie(ar, ar_cookie);
  2986. if (ar->arNetQueueStopped) {
  2987. ar->arNetQueueStopped = false;
  2988. }
  2989. }
  2990. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  2991. /* lock is released, we can freely call other kernel APIs */
  2992. /* free all skbs in our local list */
  2993. while (!skb_queue_empty(&skb_queue)) {
  2994. /* use non-lock version */
  2995. pktSkb = __skb_dequeue(&skb_queue);
  2996. A_NETBUF_FREE(pktSkb);
  2997. }
  2998. if ((ar->arConnected == true) || bypasswmi) {
  2999. if (!flushing) {
  3000. /* don't wake the queue if we are flushing, other wise it will just
  3001. * keep queueing packets, which will keep failing */
  3002. netif_wake_queue(ar->arNetDev);
  3003. }
  3004. }
  3005. if (wakeEvent) {
  3006. wake_up(&arEvent);
  3007. }
  3008. }
  3009. sta_t *
  3010. ieee80211_find_conn(struct ar6_softc *ar, u8 *node_addr)
  3011. {
  3012. sta_t *conn = NULL;
  3013. u8 i, max_conn;
  3014. switch(ar->arNetworkType) {
  3015. case AP_NETWORK:
  3016. max_conn = AP_MAX_NUM_STA;
  3017. break;
  3018. default:
  3019. max_conn=0;
  3020. break;
  3021. }
  3022. for (i = 0; i < max_conn; i++) {
  3023. if (IEEE80211_ADDR_EQ(node_addr, ar->sta_list[i].mac)) {
  3024. conn = &ar->sta_list[i];
  3025. break;
  3026. }
  3027. }
  3028. return conn;
  3029. }
  3030. sta_t *ieee80211_find_conn_for_aid(struct ar6_softc *ar, u8 aid)
  3031. {
  3032. sta_t *conn = NULL;
  3033. u8 ctr;
  3034. for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
  3035. if (ar->sta_list[ctr].aid == aid) {
  3036. conn = &ar->sta_list[ctr];
  3037. break;
  3038. }
  3039. }
  3040. return conn;
  3041. }
  3042. /*
  3043. * Receive event handler. This is called by HTC when a packet is received
  3044. */
  3045. int pktcount;
  3046. static void
  3047. ar6000_rx(void *Context, struct htc_packet *pPacket)
  3048. {
  3049. struct ar6_softc *ar = (struct ar6_softc *)Context;
  3050. struct sk_buff *skb = (struct sk_buff *)pPacket->pPktContext;
  3051. int minHdrLen;
  3052. u8 containsDot11Hdr = 0;
  3053. int status = pPacket->Status;
  3054. HTC_ENDPOINT_ID ept = pPacket->Endpoint;
  3055. A_ASSERT((status) ||
  3056. (pPacket->pBuffer == (A_NETBUF_DATA(skb) + HTC_HEADER_LEN)));
  3057. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_RX,("ar6000_rx ar=0x%lx eid=%d, skb=0x%lx, data=0x%lx, len=0x%x status:%d",
  3058. (unsigned long)ar, ept, (unsigned long)skb, (unsigned long)pPacket->pBuffer,
  3059. pPacket->ActualLength, status));
  3060. if (status) {
  3061. if (status != A_ECANCELED) {
  3062. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("RX ERR (%d) \n",status));
  3063. }
  3064. }
  3065. /* take lock to protect buffer counts
  3066. * and adaptive power throughput state */
  3067. AR6000_SPIN_LOCK(&ar->arLock, 0);
  3068. if (!status) {
  3069. AR6000_STAT_INC(ar, rx_packets);
  3070. ar->arNetStats.rx_bytes += pPacket->ActualLength;
  3071. #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
  3072. aptcTR.bytesReceived += a_netbuf_to_len(skb);
  3073. applyAPTCHeuristics(ar);
  3074. #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
  3075. A_NETBUF_PUT(skb, pPacket->ActualLength + HTC_HEADER_LEN);
  3076. A_NETBUF_PULL(skb, HTC_HEADER_LEN);
  3077. #ifdef DEBUG
  3078. if (debugdriver >= 2) {
  3079. ar6000_dump_skb(skb);
  3080. }
  3081. #endif /* DEBUG */
  3082. }
  3083. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  3084. skb->dev = ar->arNetDev;
  3085. if (status) {
  3086. AR6000_STAT_INC(ar, rx_errors);
  3087. A_NETBUF_FREE(skb);
  3088. } else if (ar->arWmiEnabled == true) {
  3089. if (ept == ar->arControlEp) {
  3090. /*
  3091. * this is a wmi control msg
  3092. */
  3093. #ifdef CONFIG_PM
  3094. ar6000_check_wow_status(ar, skb, true);
  3095. #endif /* CONFIG_PM */
  3096. wmi_control_rx(ar->arWmi, skb);
  3097. } else {
  3098. WMI_DATA_HDR *dhdr = (WMI_DATA_HDR *)A_NETBUF_DATA(skb);
  3099. bool is_amsdu;
  3100. u8 tid;
  3101. /*
  3102. * This check can be removed if after a while we do not
  3103. * see the warning. For now we leave it to ensure
  3104. * we drop these frames accordingly in case the
  3105. * target generates them for some reason. These
  3106. * were used for an internal PAL but that's not
  3107. * used or supported anymore. These frames should
  3108. * not come up from the target.
  3109. */
  3110. if (WARN_ON(WMI_DATA_HDR_GET_DATA_TYPE(dhdr) ==
  3111. WMI_DATA_HDR_DATA_TYPE_ACL)) {
  3112. AR6000_STAT_INC(ar, rx_errors);
  3113. A_NETBUF_FREE(skb);
  3114. return;
  3115. }
  3116. #ifdef CONFIG_PM
  3117. ar6000_check_wow_status(ar, NULL, false);
  3118. #endif /* CONFIG_PM */
  3119. /*
  3120. * this is a wmi data packet
  3121. */
  3122. // NWF
  3123. if (processDot11Hdr) {
  3124. minHdrLen = sizeof(WMI_DATA_HDR) + sizeof(struct ieee80211_frame) + sizeof(ATH_LLC_SNAP_HDR);
  3125. } else {
  3126. minHdrLen = sizeof (WMI_DATA_HDR) + sizeof(ATH_MAC_HDR) +
  3127. sizeof(ATH_LLC_SNAP_HDR);
  3128. }
  3129. /* In the case of AP mode we may receive NULL data frames
  3130. * that do not have LLC hdr. They are 16 bytes in size.
  3131. * Allow these frames in the AP mode.
  3132. * ACL data frames don't follow ethernet frame bounds for
  3133. * min length
  3134. */
  3135. if (ar->arNetworkType != AP_NETWORK &&
  3136. ((pPacket->ActualLength < minHdrLen) ||
  3137. (pPacket->ActualLength > AR6000_MAX_RX_MESSAGE_SIZE)))
  3138. {
  3139. /*
  3140. * packet is too short or too long
  3141. */
  3142. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("TOO SHORT or TOO LONG\n"));
  3143. AR6000_STAT_INC(ar, rx_errors);
  3144. AR6000_STAT_INC(ar, rx_length_errors);
  3145. A_NETBUF_FREE(skb);
  3146. } else {
  3147. u16 seq_no;
  3148. u8 meta_type;
  3149. #if 0
  3150. /* Access RSSI values here */
  3151. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("RSSI %d\n",
  3152. ((WMI_DATA_HDR *) A_NETBUF_DATA(skb))->rssi));
  3153. #endif
  3154. /* Get the Power save state of the STA */
  3155. if (ar->arNetworkType == AP_NETWORK) {
  3156. sta_t *conn = NULL;
  3157. u8 psState=0,prevPsState;
  3158. ATH_MAC_HDR *datap=NULL;
  3159. u16 offset;
  3160. meta_type = WMI_DATA_HDR_GET_META(dhdr);
  3161. psState = (((WMI_DATA_HDR *)A_NETBUF_DATA(skb))->info
  3162. >> WMI_DATA_HDR_PS_SHIFT) & WMI_DATA_HDR_PS_MASK;
  3163. offset = sizeof(WMI_DATA_HDR);
  3164. switch (meta_type) {
  3165. case 0:
  3166. break;
  3167. case WMI_META_VERSION_1:
  3168. offset += sizeof(WMI_RX_META_V1);
  3169. break;
  3170. case WMI_META_VERSION_2:
  3171. offset += sizeof(WMI_RX_META_V2);
  3172. break;
  3173. default:
  3174. break;
  3175. }
  3176. datap = (ATH_MAC_HDR *)(A_NETBUF_DATA(skb)+offset);
  3177. conn = ieee80211_find_conn(ar, datap->srcMac);
  3178. if (conn) {
  3179. /* if there is a change in PS state of the STA,
  3180. * take appropriate steps.
  3181. * 1. If Sleep-->Awake, flush the psq for the STA
  3182. * Clear the PVB for the STA.
  3183. * 2. If Awake-->Sleep, Starting queueing frames
  3184. * the STA.
  3185. */
  3186. prevPsState = STA_IS_PWR_SLEEP(conn);
  3187. if (psState) {
  3188. STA_SET_PWR_SLEEP(conn);
  3189. } else {
  3190. STA_CLR_PWR_SLEEP(conn);
  3191. }
  3192. if (prevPsState ^ STA_IS_PWR_SLEEP(conn)) {
  3193. if (!STA_IS_PWR_SLEEP(conn)) {
  3194. A_MUTEX_LOCK(&conn->psqLock);
  3195. while (!A_NETBUF_QUEUE_EMPTY(&conn->psq)) {
  3196. struct sk_buff *skb=NULL;
  3197. skb = A_NETBUF_DEQUEUE(&conn->psq);
  3198. A_MUTEX_UNLOCK(&conn->psqLock);
  3199. ar6000_data_tx(skb,ar->arNetDev);
  3200. A_MUTEX_LOCK(&conn->psqLock);
  3201. }
  3202. A_MUTEX_UNLOCK(&conn->psqLock);
  3203. /* Clear the PVB for this STA */
  3204. wmi_set_pvb_cmd(ar->arWmi, conn->aid, 0);
  3205. }
  3206. }
  3207. } else {
  3208. /* This frame is from a STA that is not associated*/
  3209. A_ASSERT(false);
  3210. }
  3211. /* Drop NULL data frames here */
  3212. if((pPacket->ActualLength < minHdrLen) ||
  3213. (pPacket->ActualLength > AR6000_MAX_RX_MESSAGE_SIZE)) {
  3214. A_NETBUF_FREE(skb);
  3215. goto rx_done;
  3216. }
  3217. }
  3218. is_amsdu = WMI_DATA_HDR_IS_AMSDU(dhdr) ? true : false;
  3219. tid = WMI_DATA_HDR_GET_UP(dhdr);
  3220. seq_no = WMI_DATA_HDR_GET_SEQNO(dhdr);
  3221. meta_type = WMI_DATA_HDR_GET_META(dhdr);
  3222. containsDot11Hdr = WMI_DATA_HDR_GET_DOT11(dhdr);
  3223. wmi_data_hdr_remove(ar->arWmi, skb);
  3224. switch (meta_type) {
  3225. case WMI_META_VERSION_1:
  3226. {
  3227. WMI_RX_META_V1 *pMeta = (WMI_RX_META_V1 *)A_NETBUF_DATA(skb);
  3228. A_PRINTF("META %d %d %d %d %x\n", pMeta->status, pMeta->rix, pMeta->rssi, pMeta->channel, pMeta->flags);
  3229. A_NETBUF_PULL((void*)skb, sizeof(WMI_RX_META_V1));
  3230. break;
  3231. }
  3232. case WMI_META_VERSION_2:
  3233. {
  3234. WMI_RX_META_V2 *pMeta = (WMI_RX_META_V2 *)A_NETBUF_DATA(skb);
  3235. if(pMeta->csumFlags & 0x1){
  3236. skb->ip_summed=CHECKSUM_COMPLETE;
  3237. skb->csum=(pMeta->csum);
  3238. }
  3239. A_NETBUF_PULL((void*)skb, sizeof(WMI_RX_META_V2));
  3240. break;
  3241. }
  3242. default:
  3243. break;
  3244. }
  3245. A_ASSERT(status == 0);
  3246. /* NWF: print the 802.11 hdr bytes */
  3247. if(containsDot11Hdr) {
  3248. status = wmi_dot11_hdr_remove(ar->arWmi,skb);
  3249. } else if(!is_amsdu) {
  3250. status = wmi_dot3_2_dix(skb);
  3251. }
  3252. if (status) {
  3253. /* Drop frames that could not be processed (lack of memory, etc.) */
  3254. A_NETBUF_FREE(skb);
  3255. goto rx_done;
  3256. }
  3257. if ((ar->arNetDev->flags & IFF_UP) == IFF_UP) {
  3258. if (ar->arNetworkType == AP_NETWORK) {
  3259. struct sk_buff *skb1 = NULL;
  3260. ATH_MAC_HDR *datap;
  3261. datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb);
  3262. if (IEEE80211_IS_MULTICAST(datap->dstMac)) {
  3263. /* Bcast/Mcast frames should be sent to the OS
  3264. * stack as well as on the air.
  3265. */
  3266. skb1 = skb_copy(skb,GFP_ATOMIC);
  3267. } else {
  3268. /* Search for a connected STA with dstMac as
  3269. * the Mac address. If found send the frame to
  3270. * it on the air else send the frame up the
  3271. * stack
  3272. */
  3273. sta_t *conn = NULL;
  3274. conn = ieee80211_find_conn(ar, datap->dstMac);
  3275. if (conn && ar->intra_bss) {
  3276. skb1 = skb;
  3277. skb = NULL;
  3278. } else if(conn && !ar->intra_bss) {
  3279. A_NETBUF_FREE(skb);
  3280. skb = NULL;
  3281. }
  3282. }
  3283. if (skb1) {
  3284. ar6000_data_tx(skb1, ar->arNetDev);
  3285. }
  3286. }
  3287. }
  3288. aggr_process_recv_frm(ar->aggr_cntxt, tid, seq_no, is_amsdu, (void **)&skb);
  3289. ar6000_deliver_frames_to_nw_stack((void *) ar->arNetDev, (void *)skb);
  3290. }
  3291. }
  3292. } else {
  3293. if (EPPING_ALIGNMENT_PAD > 0) {
  3294. A_NETBUF_PULL(skb, EPPING_ALIGNMENT_PAD);
  3295. }
  3296. ar6000_deliver_frames_to_nw_stack((void *)ar->arNetDev, (void *)skb);
  3297. }
  3298. rx_done:
  3299. return;
  3300. }
  3301. static void
  3302. ar6000_deliver_frames_to_nw_stack(void *dev, void *osbuf)
  3303. {
  3304. struct sk_buff *skb = (struct sk_buff *)osbuf;
  3305. if(skb) {
  3306. skb->dev = dev;
  3307. if ((skb->dev->flags & IFF_UP) == IFF_UP) {
  3308. #ifdef CONFIG_PM
  3309. ar6000_check_wow_status((struct ar6_softc *)ar6k_priv(dev), skb, false);
  3310. #endif /* CONFIG_PM */
  3311. skb->protocol = eth_type_trans(skb, skb->dev);
  3312. /*
  3313. * If this routine is called on a ISR (Hard IRQ) or DSR (Soft IRQ)
  3314. * or tasklet use the netif_rx to deliver the packet to the stack
  3315. * netif_rx will queue the packet onto the receive queue and mark
  3316. * the softirq thread has a pending action to complete. Kernel will
  3317. * schedule the softIrq kernel thread after processing the DSR.
  3318. *
  3319. * If this routine is called on a process context, use netif_rx_ni
  3320. * which will schedle the softIrq kernel thread after queuing the packet.
  3321. */
  3322. if (in_interrupt()) {
  3323. netif_rx(skb);
  3324. } else {
  3325. netif_rx_ni(skb);
  3326. }
  3327. } else {
  3328. A_NETBUF_FREE(skb);
  3329. }
  3330. }
  3331. }
  3332. #if 0
  3333. static void
  3334. ar6000_deliver_frames_to_bt_stack(void *dev, void *osbuf)
  3335. {
  3336. struct sk_buff *skb = (struct sk_buff *)osbuf;
  3337. if(skb) {
  3338. skb->dev = dev;
  3339. if ((skb->dev->flags & IFF_UP) == IFF_UP) {
  3340. skb->protocol = htons(ETH_P_CONTROL);
  3341. netif_rx(skb);
  3342. } else {
  3343. A_NETBUF_FREE(skb);
  3344. }
  3345. }
  3346. }
  3347. #endif
  3348. static void
  3349. ar6000_rx_refill(void *Context, HTC_ENDPOINT_ID Endpoint)
  3350. {
  3351. struct ar6_softc *ar = (struct ar6_softc *)Context;
  3352. void *osBuf;
  3353. int RxBuffers;
  3354. int buffersToRefill;
  3355. struct htc_packet *pPacket;
  3356. struct htc_packet_queue queue;
  3357. buffersToRefill = (int)AR6000_MAX_RX_BUFFERS -
  3358. HTCGetNumRecvBuffers(ar->arHtcTarget, Endpoint);
  3359. if (buffersToRefill <= 0) {
  3360. /* fast return, nothing to fill */
  3361. return;
  3362. }
  3363. INIT_HTC_PACKET_QUEUE(&queue);
  3364. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_RX,("ar6000_rx_refill: providing htc with %d buffers at eid=%d\n",
  3365. buffersToRefill, Endpoint));
  3366. for (RxBuffers = 0; RxBuffers < buffersToRefill; RxBuffers++) {
  3367. osBuf = A_NETBUF_ALLOC(AR6000_BUFFER_SIZE);
  3368. if (NULL == osBuf) {
  3369. break;
  3370. }
  3371. /* the HTC packet wrapper is at the head of the reserved area
  3372. * in the skb */
  3373. pPacket = (struct htc_packet *)(A_NETBUF_HEAD(osBuf));
  3374. /* set re-fill info */
  3375. SET_HTC_PACKET_INFO_RX_REFILL(pPacket,osBuf,A_NETBUF_DATA(osBuf),AR6000_BUFFER_SIZE,Endpoint);
  3376. /* add to queue */
  3377. HTC_PACKET_ENQUEUE(&queue,pPacket);
  3378. }
  3379. if (!HTC_QUEUE_EMPTY(&queue)) {
  3380. /* add packets */
  3381. HTCAddReceivePktMultiple(ar->arHtcTarget, &queue);
  3382. }
  3383. }
  3384. /* clean up our amsdu buffer list */
  3385. static void ar6000_cleanup_amsdu_rxbufs(struct ar6_softc *ar)
  3386. {
  3387. struct htc_packet *pPacket;
  3388. void *osBuf;
  3389. /* empty AMSDU buffer queue and free OS bufs */
  3390. while (true) {
  3391. AR6000_SPIN_LOCK(&ar->arLock, 0);
  3392. pPacket = HTC_PACKET_DEQUEUE(&ar->amsdu_rx_buffer_queue);
  3393. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  3394. if (NULL == pPacket) {
  3395. break;
  3396. }
  3397. osBuf = pPacket->pPktContext;
  3398. if (NULL == osBuf) {
  3399. A_ASSERT(false);
  3400. break;
  3401. }
  3402. A_NETBUF_FREE(osBuf);
  3403. }
  3404. }
  3405. /* refill the amsdu buffer list */
  3406. static void ar6000_refill_amsdu_rxbufs(struct ar6_softc *ar, int Count)
  3407. {
  3408. struct htc_packet *pPacket;
  3409. void *osBuf;
  3410. while (Count > 0) {
  3411. osBuf = A_NETBUF_ALLOC(AR6000_AMSDU_BUFFER_SIZE);
  3412. if (NULL == osBuf) {
  3413. break;
  3414. }
  3415. /* the HTC packet wrapper is at the head of the reserved area
  3416. * in the skb */
  3417. pPacket = (struct htc_packet *)(A_NETBUF_HEAD(osBuf));
  3418. /* set re-fill info */
  3419. SET_HTC_PACKET_INFO_RX_REFILL(pPacket,osBuf,A_NETBUF_DATA(osBuf),AR6000_AMSDU_BUFFER_SIZE,0);
  3420. AR6000_SPIN_LOCK(&ar->arLock, 0);
  3421. /* put it in the list */
  3422. HTC_PACKET_ENQUEUE(&ar->amsdu_rx_buffer_queue,pPacket);
  3423. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  3424. Count--;
  3425. }
  3426. }
  3427. /* callback to allocate a large receive buffer for a pending packet. This function is called when
  3428. * an HTC packet arrives whose length exceeds a threshold value
  3429. *
  3430. * We use a pre-allocated list of buffers of maximum AMSDU size (4K). Under linux it is more optimal to
  3431. * keep the allocation size the same to optimize cached-slab allocations.
  3432. *
  3433. * */
  3434. static struct htc_packet *ar6000_alloc_amsdu_rxbuf(void *Context, HTC_ENDPOINT_ID Endpoint, int Length)
  3435. {
  3436. struct htc_packet *pPacket = NULL;
  3437. struct ar6_softc *ar = (struct ar6_softc *)Context;
  3438. int refillCount = 0;
  3439. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_RX,("ar6000_alloc_amsdu_rxbuf: eid=%d, Length:%d\n",Endpoint,Length));
  3440. do {
  3441. if (Length <= AR6000_BUFFER_SIZE) {
  3442. /* shouldn't be getting called on normal sized packets */
  3443. A_ASSERT(false);
  3444. break;
  3445. }
  3446. if (Length > AR6000_AMSDU_BUFFER_SIZE) {
  3447. A_ASSERT(false);
  3448. break;
  3449. }
  3450. AR6000_SPIN_LOCK(&ar->arLock, 0);
  3451. /* allocate a packet from the list */
  3452. pPacket = HTC_PACKET_DEQUEUE(&ar->amsdu_rx_buffer_queue);
  3453. /* see if we need to refill again */
  3454. refillCount = AR6000_MAX_AMSDU_RX_BUFFERS - HTC_PACKET_QUEUE_DEPTH(&ar->amsdu_rx_buffer_queue);
  3455. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  3456. if (NULL == pPacket) {
  3457. break;
  3458. }
  3459. /* set actual endpoint ID */
  3460. pPacket->Endpoint = Endpoint;
  3461. } while (false);
  3462. if (refillCount >= AR6000_AMSDU_REFILL_THRESHOLD) {
  3463. ar6000_refill_amsdu_rxbufs(ar,refillCount);
  3464. }
  3465. return pPacket;
  3466. }
  3467. static void
  3468. ar6000_set_multicast_list(struct net_device *dev)
  3469. {
  3470. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000: Multicast filter not supported\n"));
  3471. }
  3472. static struct net_device_stats *
  3473. ar6000_get_stats(struct net_device *dev)
  3474. {
  3475. struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
  3476. return &ar->arNetStats;
  3477. }
  3478. void
  3479. ar6000_ready_event(void *devt, u8 *datap, u8 phyCap, u32 sw_ver, u32 abi_ver)
  3480. {
  3481. struct ar6_softc *ar = (struct ar6_softc *)devt;
  3482. struct net_device *dev = ar->arNetDev;
  3483. memcpy(dev->dev_addr, datap, AR6000_ETH_ADDR_LEN);
  3484. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("mac address = %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
  3485. dev->dev_addr[0], dev->dev_addr[1],
  3486. dev->dev_addr[2], dev->dev_addr[3],
  3487. dev->dev_addr[4], dev->dev_addr[5]));
  3488. ar->arPhyCapability = phyCap;
  3489. ar->arVersion.wlan_ver = sw_ver;
  3490. ar->arVersion.abi_ver = abi_ver;
  3491. /* Indicate to the waiting thread that the ready event was received */
  3492. ar->arWmiReady = true;
  3493. wake_up(&arEvent);
  3494. }
  3495. void ar6000_install_static_wep_keys(struct ar6_softc *ar)
  3496. {
  3497. u8 index;
  3498. u8 keyUsage;
  3499. for (index = WMI_MIN_KEY_INDEX; index <= WMI_MAX_KEY_INDEX; index++) {
  3500. if (ar->arWepKeyList[index].arKeyLen) {
  3501. keyUsage = GROUP_USAGE;
  3502. if (index == ar->arDefTxKeyIndex) {
  3503. keyUsage |= TX_USAGE;
  3504. }
  3505. wmi_addKey_cmd(ar->arWmi,
  3506. index,
  3507. WEP_CRYPT,
  3508. keyUsage,
  3509. ar->arWepKeyList[index].arKeyLen,
  3510. NULL,
  3511. ar->arWepKeyList[index].arKey, KEY_OP_INIT_VAL, NULL,
  3512. NO_SYNC_WMIFLAG);
  3513. }
  3514. }
  3515. }
  3516. void
  3517. add_new_sta(struct ar6_softc *ar, u8 *mac, u16 aid, u8 *wpaie,
  3518. u8 ielen, u8 keymgmt, u8 ucipher, u8 auth)
  3519. {
  3520. u8 free_slot=aid-1;
  3521. memcpy(ar->sta_list[free_slot].mac, mac, ATH_MAC_LEN);
  3522. memcpy(ar->sta_list[free_slot].wpa_ie, wpaie, ielen);
  3523. ar->sta_list[free_slot].aid = aid;
  3524. ar->sta_list[free_slot].keymgmt = keymgmt;
  3525. ar->sta_list[free_slot].ucipher = ucipher;
  3526. ar->sta_list[free_slot].auth = auth;
  3527. ar->sta_list_index = ar->sta_list_index | (1 << free_slot);
  3528. ar->arAPStats.sta[free_slot].aid = aid;
  3529. }
  3530. void
  3531. ar6000_connect_event(struct ar6_softc *ar, u16 channel, u8 *bssid,
  3532. u16 listenInterval, u16 beaconInterval,
  3533. NETWORK_TYPE networkType, u8 beaconIeLen,
  3534. u8 assocReqLen, u8 assocRespLen,
  3535. u8 *assocInfo)
  3536. {
  3537. union iwreq_data wrqu;
  3538. int i, beacon_ie_pos, assoc_resp_ie_pos, assoc_req_ie_pos;
  3539. static const char *tag1 = "ASSOCINFO(ReqIEs=";
  3540. static const char *tag2 = "ASSOCRESPIE=";
  3541. static const char *beaconIetag = "BEACONIE=";
  3542. char buf[WMI_CONTROL_MSG_MAX_LEN * 2 + strlen(tag1) + 1];
  3543. char *pos;
  3544. u8 key_op_ctrl;
  3545. unsigned long flags;
  3546. struct ieee80211req_key *ik;
  3547. CRYPTO_TYPE keyType = NONE_CRYPT;
  3548. if(ar->arNetworkType & AP_NETWORK) {
  3549. struct net_device *dev = ar->arNetDev;
  3550. if(memcmp(dev->dev_addr, bssid, ATH_MAC_LEN)==0) {
  3551. ar->arACS = channel;
  3552. ik = &ar->ap_mode_bkey;
  3553. switch(ar->arAuthMode) {
  3554. case NONE_AUTH:
  3555. if(ar->arPairwiseCrypto == WEP_CRYPT) {
  3556. ar6000_install_static_wep_keys(ar);
  3557. }
  3558. #ifdef WAPI_ENABLE
  3559. else if(ar->arPairwiseCrypto == WAPI_CRYPT) {
  3560. ap_set_wapi_key(ar, ik);
  3561. }
  3562. #endif
  3563. break;
  3564. case WPA_PSK_AUTH:
  3565. case WPA2_PSK_AUTH:
  3566. case (WPA_PSK_AUTH|WPA2_PSK_AUTH):
  3567. switch (ik->ik_type) {
  3568. case IEEE80211_CIPHER_TKIP:
  3569. keyType = TKIP_CRYPT;
  3570. break;
  3571. case IEEE80211_CIPHER_AES_CCM:
  3572. keyType = AES_CRYPT;
  3573. break;
  3574. default:
  3575. goto skip_key;
  3576. }
  3577. wmi_addKey_cmd(ar->arWmi, ik->ik_keyix, keyType, GROUP_USAGE,
  3578. ik->ik_keylen, (u8 *)&ik->ik_keyrsc,
  3579. ik->ik_keydata, KEY_OP_INIT_VAL, ik->ik_macaddr,
  3580. SYNC_BOTH_WMIFLAG);
  3581. break;
  3582. }
  3583. skip_key:
  3584. ar->arConnected = true;
  3585. return;
  3586. }
  3587. A_PRINTF("NEW STA %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x \n "
  3588. " AID=%d \n", bssid[0], bssid[1], bssid[2],
  3589. bssid[3], bssid[4], bssid[5], channel);
  3590. switch ((listenInterval>>8)&0xFF) {
  3591. case OPEN_AUTH:
  3592. A_PRINTF("AUTH: OPEN\n");
  3593. break;
  3594. case SHARED_AUTH:
  3595. A_PRINTF("AUTH: SHARED\n");
  3596. break;
  3597. default:
  3598. A_PRINTF("AUTH: Unknown\n");
  3599. break;
  3600. }
  3601. switch (listenInterval&0xFF) {
  3602. case WPA_PSK_AUTH:
  3603. A_PRINTF("KeyMgmt: WPA-PSK\n");
  3604. break;
  3605. case WPA2_PSK_AUTH:
  3606. A_PRINTF("KeyMgmt: WPA2-PSK\n");
  3607. break;
  3608. default:
  3609. A_PRINTF("KeyMgmt: NONE\n");
  3610. break;
  3611. }
  3612. switch (beaconInterval) {
  3613. case AES_CRYPT:
  3614. A_PRINTF("Cipher: AES\n");
  3615. break;
  3616. case TKIP_CRYPT:
  3617. A_PRINTF("Cipher: TKIP\n");
  3618. break;
  3619. case WEP_CRYPT:
  3620. A_PRINTF("Cipher: WEP\n");
  3621. break;
  3622. #ifdef WAPI_ENABLE
  3623. case WAPI_CRYPT:
  3624. A_PRINTF("Cipher: WAPI\n");
  3625. break;
  3626. #endif
  3627. default:
  3628. A_PRINTF("Cipher: NONE\n");
  3629. break;
  3630. }
  3631. add_new_sta(ar, bssid, channel /*aid*/,
  3632. assocInfo /* WPA IE */, assocRespLen /* IE len */,
  3633. listenInterval&0xFF /* Keymgmt */, beaconInterval /* cipher */,
  3634. (listenInterval>>8)&0xFF /* auth alg */);
  3635. /* Send event to application */
  3636. A_MEMZERO(&wrqu, sizeof(wrqu));
  3637. memcpy(wrqu.addr.sa_data, bssid, ATH_MAC_LEN);
  3638. wireless_send_event(ar->arNetDev, IWEVREGISTERED, &wrqu, NULL);
  3639. /* In case the queue is stopped when we switch modes, this will
  3640. * wake it up
  3641. */
  3642. netif_wake_queue(ar->arNetDev);
  3643. return;
  3644. }
  3645. ar6k_cfg80211_connect_event(ar, channel, bssid,
  3646. listenInterval, beaconInterval,
  3647. networkType, beaconIeLen,
  3648. assocReqLen, assocRespLen,
  3649. assocInfo);
  3650. memcpy(ar->arBssid, bssid, sizeof(ar->arBssid));
  3651. ar->arBssChannel = channel;
  3652. A_PRINTF("AR6000 connected event on freq %d ", channel);
  3653. A_PRINTF("with bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
  3654. " listenInterval=%d, beaconInterval = %d, beaconIeLen = %d assocReqLen=%d"
  3655. " assocRespLen =%d\n",
  3656. bssid[0], bssid[1], bssid[2],
  3657. bssid[3], bssid[4], bssid[5],
  3658. listenInterval, beaconInterval,
  3659. beaconIeLen, assocReqLen, assocRespLen);
  3660. if (networkType & ADHOC_NETWORK) {
  3661. if (networkType & ADHOC_CREATOR) {
  3662. A_PRINTF("Network: Adhoc (Creator)\n");
  3663. } else {
  3664. A_PRINTF("Network: Adhoc (Joiner)\n");
  3665. }
  3666. } else {
  3667. A_PRINTF("Network: Infrastructure\n");
  3668. }
  3669. if ((ar->arNetworkType == INFRA_NETWORK)) {
  3670. wmi_listeninterval_cmd(ar->arWmi, ar->arListenIntervalT, ar->arListenIntervalB);
  3671. }
  3672. if (beaconIeLen && (sizeof(buf) > (9 + beaconIeLen * 2))) {
  3673. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nBeaconIEs= "));
  3674. beacon_ie_pos = 0;
  3675. A_MEMZERO(buf, sizeof(buf));
  3676. sprintf(buf, "%s", beaconIetag);
  3677. pos = buf + 9;
  3678. for (i = beacon_ie_pos; i < beacon_ie_pos + beaconIeLen; i++) {
  3679. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
  3680. sprintf(pos, "%2.2x", assocInfo[i]);
  3681. pos += 2;
  3682. }
  3683. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
  3684. A_MEMZERO(&wrqu, sizeof(wrqu));
  3685. wrqu.data.length = strlen(buf);
  3686. wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
  3687. }
  3688. if (assocRespLen && (sizeof(buf) > (12 + (assocRespLen * 2))))
  3689. {
  3690. assoc_resp_ie_pos = beaconIeLen + assocReqLen +
  3691. sizeof(u16) + /* capinfo*/
  3692. sizeof(u16) + /* status Code */
  3693. sizeof(u16) ; /* associd */
  3694. A_MEMZERO(buf, sizeof(buf));
  3695. sprintf(buf, "%s", tag2);
  3696. pos = buf + 12;
  3697. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nAssocRespIEs= "));
  3698. /*
  3699. * The Association Response Frame w.o. the WLAN header is delivered to
  3700. * the host, so skip over to the IEs
  3701. */
  3702. for (i = assoc_resp_ie_pos; i < assoc_resp_ie_pos + assocRespLen - 6; i++)
  3703. {
  3704. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
  3705. sprintf(pos, "%2.2x", assocInfo[i]);
  3706. pos += 2;
  3707. }
  3708. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
  3709. A_MEMZERO(&wrqu, sizeof(wrqu));
  3710. wrqu.data.length = strlen(buf);
  3711. wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
  3712. }
  3713. if (assocReqLen && (sizeof(buf) > (17 + (assocReqLen * 2)))) {
  3714. /*
  3715. * assoc Request includes capability and listen interval. Skip these.
  3716. */
  3717. assoc_req_ie_pos = beaconIeLen +
  3718. sizeof(u16) + /* capinfo*/
  3719. sizeof(u16); /* listen interval */
  3720. A_MEMZERO(buf, sizeof(buf));
  3721. sprintf(buf, "%s", tag1);
  3722. pos = buf + 17;
  3723. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("AssocReqIEs= "));
  3724. for (i = assoc_req_ie_pos; i < assoc_req_ie_pos + assocReqLen - 4; i++) {
  3725. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
  3726. sprintf(pos, "%2.2x", assocInfo[i]);
  3727. pos += 2;
  3728. }
  3729. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
  3730. A_MEMZERO(&wrqu, sizeof(wrqu));
  3731. wrqu.data.length = strlen(buf);
  3732. wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
  3733. }
  3734. if (ar->user_savedkeys_stat == USER_SAVEDKEYS_STAT_RUN &&
  3735. ar->user_saved_keys.keyOk == true)
  3736. {
  3737. key_op_ctrl = KEY_OP_VALID_MASK & ~KEY_OP_INIT_TSC;
  3738. if (ar->user_key_ctrl & AR6000_USER_SETKEYS_RSC_UNCHANGED) {
  3739. key_op_ctrl &= ~KEY_OP_INIT_RSC;
  3740. } else {
  3741. key_op_ctrl |= KEY_OP_INIT_RSC;
  3742. }
  3743. ar6000_reinstall_keys(ar, key_op_ctrl);
  3744. }
  3745. netif_wake_queue(ar->arNetDev);
  3746. /* Update connect & link status atomically */
  3747. spin_lock_irqsave(&ar->arLock, flags);
  3748. ar->arConnected = true;
  3749. ar->arConnectPending = false;
  3750. netif_carrier_on(ar->arNetDev);
  3751. spin_unlock_irqrestore(&ar->arLock, flags);
  3752. /* reset the rx aggr state */
  3753. aggr_reset_state(ar->aggr_cntxt);
  3754. reconnect_flag = 0;
  3755. A_MEMZERO(&wrqu, sizeof(wrqu));
  3756. memcpy(wrqu.addr.sa_data, bssid, IEEE80211_ADDR_LEN);
  3757. wrqu.addr.sa_family = ARPHRD_ETHER;
  3758. wireless_send_event(ar->arNetDev, SIOCGIWAP, &wrqu, NULL);
  3759. if ((ar->arNetworkType == ADHOC_NETWORK) && ar->arIbssPsEnable) {
  3760. A_MEMZERO(ar->arNodeMap, sizeof(ar->arNodeMap));
  3761. ar->arNodeNum = 0;
  3762. ar->arNexEpId = ENDPOINT_2;
  3763. }
  3764. if (!ar->arUserBssFilter) {
  3765. wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
  3766. }
  3767. }
  3768. void ar6000_set_numdataendpts(struct ar6_softc *ar, u32 num)
  3769. {
  3770. A_ASSERT(num <= (HTC_MAILBOX_NUM_MAX - 1));
  3771. ar->arNumDataEndPts = num;
  3772. }
  3773. void
  3774. sta_cleanup(struct ar6_softc *ar, u8 i)
  3775. {
  3776. struct sk_buff *skb;
  3777. /* empty the queued pkts in the PS queue if any */
  3778. A_MUTEX_LOCK(&ar->sta_list[i].psqLock);
  3779. while (!A_NETBUF_QUEUE_EMPTY(&ar->sta_list[i].psq)) {
  3780. skb = A_NETBUF_DEQUEUE(&ar->sta_list[i].psq);
  3781. A_NETBUF_FREE(skb);
  3782. }
  3783. A_MUTEX_UNLOCK(&ar->sta_list[i].psqLock);
  3784. /* Zero out the state fields */
  3785. A_MEMZERO(&ar->arAPStats.sta[ar->sta_list[i].aid-1], sizeof(WMI_PER_STA_STAT));
  3786. A_MEMZERO(&ar->sta_list[i].mac, ATH_MAC_LEN);
  3787. A_MEMZERO(&ar->sta_list[i].wpa_ie, IEEE80211_MAX_IE);
  3788. ar->sta_list[i].aid = 0;
  3789. ar->sta_list[i].flags = 0;
  3790. ar->sta_list_index = ar->sta_list_index & ~(1 << i);
  3791. }
  3792. u8 remove_sta(struct ar6_softc *ar, u8 *mac, u16 reason)
  3793. {
  3794. u8 i, removed=0;
  3795. if(IS_MAC_NULL(mac)) {
  3796. return removed;
  3797. }
  3798. if(IS_MAC_BCAST(mac)) {
  3799. A_PRINTF("DEL ALL STA\n");
  3800. for(i=0; i < AP_MAX_NUM_STA; i++) {
  3801. if(!IS_MAC_NULL(ar->sta_list[i].mac)) {
  3802. sta_cleanup(ar, i);
  3803. removed = 1;
  3804. }
  3805. }
  3806. } else {
  3807. for(i=0; i < AP_MAX_NUM_STA; i++) {
  3808. if(memcmp(ar->sta_list[i].mac, mac, ATH_MAC_LEN)==0) {
  3809. A_PRINTF("DEL STA %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
  3810. " aid=%d REASON=%d\n", mac[0], mac[1], mac[2],
  3811. mac[3], mac[4], mac[5], ar->sta_list[i].aid, reason);
  3812. sta_cleanup(ar, i);
  3813. removed = 1;
  3814. break;
  3815. }
  3816. }
  3817. }
  3818. return removed;
  3819. }
  3820. void
  3821. ar6000_disconnect_event(struct ar6_softc *ar, u8 reason, u8 *bssid,
  3822. u8 assocRespLen, u8 *assocInfo, u16 protocolReasonStatus)
  3823. {
  3824. u8 i;
  3825. unsigned long flags;
  3826. union iwreq_data wrqu;
  3827. if(ar->arNetworkType & AP_NETWORK) {
  3828. union iwreq_data wrqu;
  3829. struct sk_buff *skb;
  3830. if(!remove_sta(ar, bssid, protocolReasonStatus)) {
  3831. return;
  3832. }
  3833. /* If there are no more associated STAs, empty the mcast PS q */
  3834. if (ar->sta_list_index == 0) {
  3835. A_MUTEX_LOCK(&ar->mcastpsqLock);
  3836. while (!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) {
  3837. skb = A_NETBUF_DEQUEUE(&ar->mcastpsq);
  3838. A_NETBUF_FREE(skb);
  3839. }
  3840. A_MUTEX_UNLOCK(&ar->mcastpsqLock);
  3841. /* Clear the LSB of the BitMapCtl field of the TIM IE */
  3842. if (ar->arWmiReady) {
  3843. wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 0);
  3844. }
  3845. }
  3846. if(!IS_MAC_BCAST(bssid)) {
  3847. /* Send event to application */
  3848. A_MEMZERO(&wrqu, sizeof(wrqu));
  3849. memcpy(wrqu.addr.sa_data, bssid, ATH_MAC_LEN);
  3850. wireless_send_event(ar->arNetDev, IWEVEXPIRED, &wrqu, NULL);
  3851. }
  3852. ar->arConnected = false;
  3853. return;
  3854. }
  3855. ar6k_cfg80211_disconnect_event(ar, reason, bssid,
  3856. assocRespLen, assocInfo,
  3857. protocolReasonStatus);
  3858. /* Send disconnect event to supplicant */
  3859. A_MEMZERO(&wrqu, sizeof(wrqu));
  3860. wrqu.addr.sa_family = ARPHRD_ETHER;
  3861. wireless_send_event(ar->arNetDev, SIOCGIWAP, &wrqu, NULL);
  3862. /* it is necessary to clear the host-side rx aggregation state */
  3863. aggr_reset_state(ar->aggr_cntxt);
  3864. A_UNTIMEOUT(&ar->disconnect_timer);
  3865. A_PRINTF("AR6000 disconnected");
  3866. if (bssid[0] || bssid[1] || bssid[2] || bssid[3] || bssid[4] || bssid[5]) {
  3867. A_PRINTF(" from %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ",
  3868. bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
  3869. }
  3870. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nDisconnect Reason is %d", reason));
  3871. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nProtocol Reason/Status Code is %d", protocolReasonStatus));
  3872. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nAssocResp Frame = %s",
  3873. assocRespLen ? " " : "NULL"));
  3874. for (i = 0; i < assocRespLen; i++) {
  3875. if (!(i % 0x10)) {
  3876. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
  3877. }
  3878. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
  3879. }
  3880. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
  3881. /*
  3882. * If the event is due to disconnect cmd from the host, only they the target
  3883. * would stop trying to connect. Under any other condition, target would
  3884. * keep trying to connect.
  3885. *
  3886. */
  3887. if( reason == DISCONNECT_CMD)
  3888. {
  3889. if ((!ar->arUserBssFilter) && (ar->arWmiReady)) {
  3890. wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
  3891. }
  3892. } else {
  3893. ar->arConnectPending = true;
  3894. if (((reason == ASSOC_FAILED) && (protocolReasonStatus == 0x11)) ||
  3895. ((reason == ASSOC_FAILED) && (protocolReasonStatus == 0x0) && (reconnect_flag == 1))) {
  3896. ar->arConnected = true;
  3897. return;
  3898. }
  3899. }
  3900. if ((reason == NO_NETWORK_AVAIL) && (ar->arWmiReady))
  3901. {
  3902. bss_t *pWmiSsidnode = NULL;
  3903. /* remove the current associated bssid node */
  3904. wmi_free_node (ar->arWmi, bssid);
  3905. /*
  3906. * In case any other same SSID nodes are present
  3907. * remove it, since those nodes also not available now
  3908. */
  3909. do
  3910. {
  3911. /*
  3912. * Find the nodes based on SSID and remove it
  3913. * NOTE :: This case will not work out for Hidden-SSID
  3914. */
  3915. pWmiSsidnode = wmi_find_Ssidnode (ar->arWmi, ar->arSsid, ar->arSsidLen, false, true);
  3916. if (pWmiSsidnode)
  3917. {
  3918. wmi_free_node (ar->arWmi, pWmiSsidnode->ni_macaddr);
  3919. }
  3920. } while (pWmiSsidnode);
  3921. }
  3922. /* Update connect & link status atomically */
  3923. spin_lock_irqsave(&ar->arLock, flags);
  3924. ar->arConnected = false;
  3925. netif_carrier_off(ar->arNetDev);
  3926. spin_unlock_irqrestore(&ar->arLock, flags);
  3927. if( (reason != CSERV_DISCONNECT) || (reconnect_flag != 1) ) {
  3928. reconnect_flag = 0;
  3929. }
  3930. if (reason != CSERV_DISCONNECT)
  3931. {
  3932. ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT;
  3933. ar->user_key_ctrl = 0;
  3934. }
  3935. netif_stop_queue(ar->arNetDev);
  3936. A_MEMZERO(ar->arBssid, sizeof(ar->arBssid));
  3937. ar->arBssChannel = 0;
  3938. ar->arBeaconInterval = 0;
  3939. ar6000_TxDataCleanup(ar);
  3940. }
  3941. void
  3942. ar6000_regDomain_event(struct ar6_softc *ar, u32 regCode)
  3943. {
  3944. A_PRINTF("AR6000 Reg Code = 0x%x\n", regCode);
  3945. ar->arRegCode = regCode;
  3946. }
  3947. void
  3948. ar6000_aggr_rcv_addba_req_evt(struct ar6_softc *ar, WMI_ADDBA_REQ_EVENT *evt)
  3949. {
  3950. if(evt->status == 0) {
  3951. aggr_recv_addba_req_evt(ar->aggr_cntxt, evt->tid, evt->st_seq_no, evt->win_sz);
  3952. }
  3953. }
  3954. void
  3955. ar6000_aggr_rcv_addba_resp_evt(struct ar6_softc *ar, WMI_ADDBA_RESP_EVENT *evt)
  3956. {
  3957. A_PRINTF("ADDBA RESP. tid %d status %d, sz %d\n", evt->tid, evt->status, evt->amsdu_sz);
  3958. if(evt->status == 0) {
  3959. }
  3960. }
  3961. void
  3962. ar6000_aggr_rcv_delba_req_evt(struct ar6_softc *ar, WMI_DELBA_EVENT *evt)
  3963. {
  3964. aggr_recv_delba_req_evt(ar->aggr_cntxt, evt->tid);
  3965. }
  3966. void register_pal_cb(ar6k_pal_config_t *palConfig_p)
  3967. {
  3968. ar6k_pal_config_g = *palConfig_p;
  3969. }
  3970. void
  3971. ar6000_hci_event_rcv_evt(struct ar6_softc *ar, WMI_HCI_EVENT *cmd)
  3972. {
  3973. void *osbuf = NULL;
  3974. s8 i;
  3975. u8 size, *buf;
  3976. int ret = 0;
  3977. size = cmd->evt_buf_sz + 4;
  3978. osbuf = A_NETBUF_ALLOC(size);
  3979. if (osbuf == NULL) {
  3980. ret = A_NO_MEMORY;
  3981. A_PRINTF("Error in allocating netbuf \n");
  3982. return;
  3983. }
  3984. A_NETBUF_PUT(osbuf, size);
  3985. buf = (u8 *)A_NETBUF_DATA(osbuf);
  3986. /* First 2-bytes carry HCI event/ACL data type
  3987. * the next 2 are free
  3988. */
  3989. *((short *)buf) = WMI_HCI_EVENT_EVENTID;
  3990. buf += sizeof(int);
  3991. memcpy(buf, cmd->buf, cmd->evt_buf_sz);
  3992. ar6000_deliver_frames_to_nw_stack(ar->arNetDev, osbuf);
  3993. if(loghci) {
  3994. A_PRINTF_LOG("HCI Event From PAL <-- \n");
  3995. for(i = 0; i < cmd->evt_buf_sz; i++) {
  3996. A_PRINTF_LOG("0x%02x ", cmd->buf[i]);
  3997. if((i % 10) == 0) {
  3998. A_PRINTF_LOG("\n");
  3999. }
  4000. }
  4001. A_PRINTF_LOG("\n");
  4002. A_PRINTF_LOG("==================================\n");
  4003. }
  4004. }
  4005. void
  4006. ar6000_neighborReport_event(struct ar6_softc *ar, int numAps, WMI_NEIGHBOR_INFO *info)
  4007. {
  4008. #if WIRELESS_EXT >= 18
  4009. struct iw_pmkid_cand *pmkcand;
  4010. #else /* WIRELESS_EXT >= 18 */
  4011. static const char *tag = "PRE-AUTH";
  4012. char buf[128];
  4013. #endif /* WIRELESS_EXT >= 18 */
  4014. union iwreq_data wrqu;
  4015. int i;
  4016. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("AR6000 Neighbor Report Event\n"));
  4017. for (i=0; i < numAps; info++, i++) {
  4018. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ",
  4019. info->bssid[0], info->bssid[1], info->bssid[2],
  4020. info->bssid[3], info->bssid[4], info->bssid[5]));
  4021. if (info->bssFlags & WMI_PREAUTH_CAPABLE_BSS) {
  4022. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("preauth-cap"));
  4023. }
  4024. if (info->bssFlags & WMI_PMKID_VALID_BSS) {
  4025. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,(" pmkid-valid\n"));
  4026. continue; /* we skip bss if the pmkid is already valid */
  4027. }
  4028. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("\n"));
  4029. A_MEMZERO(&wrqu, sizeof(wrqu));
  4030. #if WIRELESS_EXT >= 18
  4031. pmkcand = A_MALLOC_NOWAIT(sizeof(struct iw_pmkid_cand));
  4032. A_MEMZERO(pmkcand, sizeof(struct iw_pmkid_cand));
  4033. pmkcand->index = i;
  4034. pmkcand->flags = info->bssFlags;
  4035. memcpy(pmkcand->bssid.sa_data, info->bssid, ATH_MAC_LEN);
  4036. wrqu.data.length = sizeof(struct iw_pmkid_cand);
  4037. wireless_send_event(ar->arNetDev, IWEVPMKIDCAND, &wrqu, (char *)pmkcand);
  4038. kfree(pmkcand);
  4039. #else /* WIRELESS_EXT >= 18 */
  4040. snprintf(buf, sizeof(buf), "%s%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
  4041. tag,
  4042. info->bssid[0], info->bssid[1], info->bssid[2],
  4043. info->bssid[3], info->bssid[4], info->bssid[5],
  4044. i, info->bssFlags);
  4045. wrqu.data.length = strlen(buf);
  4046. wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
  4047. #endif /* WIRELESS_EXT >= 18 */
  4048. }
  4049. }
  4050. void
  4051. ar6000_tkip_micerr_event(struct ar6_softc *ar, u8 keyid, bool ismcast)
  4052. {
  4053. static const char *tag = "MLME-MICHAELMICFAILURE.indication";
  4054. char buf[128];
  4055. union iwreq_data wrqu;
  4056. /*
  4057. * For AP case, keyid will have aid of STA which sent pkt with
  4058. * MIC error. Use this aid to get MAC & send it to hostapd.
  4059. */
  4060. if (ar->arNetworkType == AP_NETWORK) {
  4061. sta_t *s = ieee80211_find_conn_for_aid(ar, (keyid >> 2));
  4062. if(!s){
  4063. A_PRINTF("AP TKIP MIC error received from Invalid aid / STA not found =%d\n", keyid);
  4064. return;
  4065. }
  4066. A_PRINTF("AP TKIP MIC error received from aid=%d\n", keyid);
  4067. snprintf(buf,sizeof(buf), "%s addr=%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
  4068. tag, s->mac[0],s->mac[1],s->mac[2],s->mac[3],s->mac[4],s->mac[5]);
  4069. } else {
  4070. ar6k_cfg80211_tkip_micerr_event(ar, keyid, ismcast);
  4071. A_PRINTF("AR6000 TKIP MIC error received for keyid %d %scast\n",
  4072. keyid & 0x3, ismcast ? "multi": "uni");
  4073. snprintf(buf, sizeof(buf), "%s(keyid=%d %sicast)", tag, keyid & 0x3,
  4074. ismcast ? "mult" : "un");
  4075. }
  4076. memset(&wrqu, 0, sizeof(wrqu));
  4077. wrqu.data.length = strlen(buf);
  4078. wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
  4079. }
  4080. void
  4081. ar6000_scanComplete_event(struct ar6_softc *ar, int status)
  4082. {
  4083. ar6k_cfg80211_scanComplete_event(ar, status);
  4084. if (!ar->arUserBssFilter) {
  4085. wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
  4086. }
  4087. if (ar->scan_triggered) {
  4088. if (status== 0) {
  4089. union iwreq_data wrqu;
  4090. A_MEMZERO(&wrqu, sizeof(wrqu));
  4091. wireless_send_event(ar->arNetDev, SIOCGIWSCAN, &wrqu, NULL);
  4092. }
  4093. ar->scan_triggered = 0;
  4094. }
  4095. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,( "AR6000 scan complete: %d\n", status));
  4096. }
  4097. void
  4098. ar6000_targetStats_event(struct ar6_softc *ar, u8 *ptr, u32 len)
  4099. {
  4100. u8 ac;
  4101. if(ar->arNetworkType == AP_NETWORK) {
  4102. WMI_AP_MODE_STAT *p = (WMI_AP_MODE_STAT *)ptr;
  4103. WMI_AP_MODE_STAT *ap = &ar->arAPStats;
  4104. if (len < sizeof(*p)) {
  4105. return;
  4106. }
  4107. for(ac=0;ac<AP_MAX_NUM_STA;ac++) {
  4108. ap->sta[ac].tx_bytes += p->sta[ac].tx_bytes;
  4109. ap->sta[ac].tx_pkts += p->sta[ac].tx_pkts;
  4110. ap->sta[ac].tx_error += p->sta[ac].tx_error;
  4111. ap->sta[ac].tx_discard += p->sta[ac].tx_discard;
  4112. ap->sta[ac].rx_bytes += p->sta[ac].rx_bytes;
  4113. ap->sta[ac].rx_pkts += p->sta[ac].rx_pkts;
  4114. ap->sta[ac].rx_error += p->sta[ac].rx_error;
  4115. ap->sta[ac].rx_discard += p->sta[ac].rx_discard;
  4116. }
  4117. } else {
  4118. WMI_TARGET_STATS *pTarget = (WMI_TARGET_STATS *)ptr;
  4119. TARGET_STATS *pStats = &ar->arTargetStats;
  4120. if (len < sizeof(*pTarget)) {
  4121. return;
  4122. }
  4123. // Update the RSSI of the connected bss.
  4124. if (ar->arConnected) {
  4125. bss_t *pConnBss = NULL;
  4126. pConnBss = wmi_find_node(ar->arWmi,ar->arBssid);
  4127. if (pConnBss)
  4128. {
  4129. pConnBss->ni_rssi = pTarget->cservStats.cs_aveBeacon_rssi;
  4130. pConnBss->ni_snr = pTarget->cservStats.cs_aveBeacon_snr;
  4131. wmi_node_return(ar->arWmi, pConnBss);
  4132. }
  4133. }
  4134. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 updating target stats\n"));
  4135. pStats->tx_packets += pTarget->txrxStats.tx_stats.tx_packets;
  4136. pStats->tx_bytes += pTarget->txrxStats.tx_stats.tx_bytes;
  4137. pStats->tx_unicast_pkts += pTarget->txrxStats.tx_stats.tx_unicast_pkts;
  4138. pStats->tx_unicast_bytes += pTarget->txrxStats.tx_stats.tx_unicast_bytes;
  4139. pStats->tx_multicast_pkts += pTarget->txrxStats.tx_stats.tx_multicast_pkts;
  4140. pStats->tx_multicast_bytes += pTarget->txrxStats.tx_stats.tx_multicast_bytes;
  4141. pStats->tx_broadcast_pkts += pTarget->txrxStats.tx_stats.tx_broadcast_pkts;
  4142. pStats->tx_broadcast_bytes += pTarget->txrxStats.tx_stats.tx_broadcast_bytes;
  4143. pStats->tx_rts_success_cnt += pTarget->txrxStats.tx_stats.tx_rts_success_cnt;
  4144. for(ac = 0; ac < WMM_NUM_AC; ac++)
  4145. pStats->tx_packet_per_ac[ac] += pTarget->txrxStats.tx_stats.tx_packet_per_ac[ac];
  4146. pStats->tx_errors += pTarget->txrxStats.tx_stats.tx_errors;
  4147. pStats->tx_failed_cnt += pTarget->txrxStats.tx_stats.tx_failed_cnt;
  4148. pStats->tx_retry_cnt += pTarget->txrxStats.tx_stats.tx_retry_cnt;
  4149. pStats->tx_mult_retry_cnt += pTarget->txrxStats.tx_stats.tx_mult_retry_cnt;
  4150. pStats->tx_rts_fail_cnt += pTarget->txrxStats.tx_stats.tx_rts_fail_cnt;
  4151. pStats->tx_unicast_rate = wmi_get_rate(pTarget->txrxStats.tx_stats.tx_unicast_rate);
  4152. pStats->rx_packets += pTarget->txrxStats.rx_stats.rx_packets;
  4153. pStats->rx_bytes += pTarget->txrxStats.rx_stats.rx_bytes;
  4154. pStats->rx_unicast_pkts += pTarget->txrxStats.rx_stats.rx_unicast_pkts;
  4155. pStats->rx_unicast_bytes += pTarget->txrxStats.rx_stats.rx_unicast_bytes;
  4156. pStats->rx_multicast_pkts += pTarget->txrxStats.rx_stats.rx_multicast_pkts;
  4157. pStats->rx_multicast_bytes += pTarget->txrxStats.rx_stats.rx_multicast_bytes;
  4158. pStats->rx_broadcast_pkts += pTarget->txrxStats.rx_stats.rx_broadcast_pkts;
  4159. pStats->rx_broadcast_bytes += pTarget->txrxStats.rx_stats.rx_broadcast_bytes;
  4160. pStats->rx_fragment_pkt += pTarget->txrxStats.rx_stats.rx_fragment_pkt;
  4161. pStats->rx_errors += pTarget->txrxStats.rx_stats.rx_errors;
  4162. pStats->rx_crcerr += pTarget->txrxStats.rx_stats.rx_crcerr;
  4163. pStats->rx_key_cache_miss += pTarget->txrxStats.rx_stats.rx_key_cache_miss;
  4164. pStats->rx_decrypt_err += pTarget->txrxStats.rx_stats.rx_decrypt_err;
  4165. pStats->rx_duplicate_frames += pTarget->txrxStats.rx_stats.rx_duplicate_frames;
  4166. pStats->rx_unicast_rate = wmi_get_rate(pTarget->txrxStats.rx_stats.rx_unicast_rate);
  4167. pStats->tkip_local_mic_failure
  4168. += pTarget->txrxStats.tkipCcmpStats.tkip_local_mic_failure;
  4169. pStats->tkip_counter_measures_invoked
  4170. += pTarget->txrxStats.tkipCcmpStats.tkip_counter_measures_invoked;
  4171. pStats->tkip_replays += pTarget->txrxStats.tkipCcmpStats.tkip_replays;
  4172. pStats->tkip_format_errors += pTarget->txrxStats.tkipCcmpStats.tkip_format_errors;
  4173. pStats->ccmp_format_errors += pTarget->txrxStats.tkipCcmpStats.ccmp_format_errors;
  4174. pStats->ccmp_replays += pTarget->txrxStats.tkipCcmpStats.ccmp_replays;
  4175. pStats->power_save_failure_cnt += pTarget->pmStats.power_save_failure_cnt;
  4176. pStats->noise_floor_calibation = pTarget->noise_floor_calibation;
  4177. pStats->cs_bmiss_cnt += pTarget->cservStats.cs_bmiss_cnt;
  4178. pStats->cs_lowRssi_cnt += pTarget->cservStats.cs_lowRssi_cnt;
  4179. pStats->cs_connect_cnt += pTarget->cservStats.cs_connect_cnt;
  4180. pStats->cs_disconnect_cnt += pTarget->cservStats.cs_disconnect_cnt;
  4181. pStats->cs_aveBeacon_snr = pTarget->cservStats.cs_aveBeacon_snr;
  4182. pStats->cs_aveBeacon_rssi = pTarget->cservStats.cs_aveBeacon_rssi;
  4183. if (enablerssicompensation) {
  4184. pStats->cs_aveBeacon_rssi =
  4185. rssi_compensation_calc(ar, pStats->cs_aveBeacon_rssi);
  4186. }
  4187. pStats->cs_lastRoam_msec = pTarget->cservStats.cs_lastRoam_msec;
  4188. pStats->cs_snr = pTarget->cservStats.cs_snr;
  4189. pStats->cs_rssi = pTarget->cservStats.cs_rssi;
  4190. pStats->lq_val = pTarget->lqVal;
  4191. pStats->wow_num_pkts_dropped += pTarget->wowStats.wow_num_pkts_dropped;
  4192. pStats->wow_num_host_pkt_wakeups += pTarget->wowStats.wow_num_host_pkt_wakeups;
  4193. pStats->wow_num_host_event_wakeups += pTarget->wowStats.wow_num_host_event_wakeups;
  4194. pStats->wow_num_events_discarded += pTarget->wowStats.wow_num_events_discarded;
  4195. pStats->arp_received += pTarget->arpStats.arp_received;
  4196. pStats->arp_matched += pTarget->arpStats.arp_matched;
  4197. pStats->arp_replied += pTarget->arpStats.arp_replied;
  4198. if (ar->statsUpdatePending) {
  4199. ar->statsUpdatePending = false;
  4200. wake_up(&arEvent);
  4201. }
  4202. }
  4203. }
  4204. void
  4205. ar6000_rssiThreshold_event(struct ar6_softc *ar, WMI_RSSI_THRESHOLD_VAL newThreshold, s16 rssi)
  4206. {
  4207. USER_RSSI_THOLD userRssiThold;
  4208. rssi = rssi + SIGNAL_QUALITY_NOISE_FLOOR;
  4209. if (enablerssicompensation) {
  4210. rssi = rssi_compensation_calc(ar, rssi);
  4211. }
  4212. /* Send an event to the app */
  4213. userRssiThold.tag = ar->rssi_map[newThreshold].tag;
  4214. userRssiThold.rssi = rssi;
  4215. A_PRINTF("rssi Threshold range = %d tag = %d rssi = %d\n", newThreshold,
  4216. userRssiThold.tag, userRssiThold.rssi);
  4217. }
  4218. void
  4219. ar6000_hbChallengeResp_event(struct ar6_softc *ar, u32 cookie, u32 source)
  4220. {
  4221. if (source != APP_HB_CHALLENGE) {
  4222. /* This would ignore the replys that come in after their due time */
  4223. if (cookie == ar->arHBChallengeResp.seqNum) {
  4224. ar->arHBChallengeResp.outstanding = false;
  4225. }
  4226. }
  4227. }
  4228. void
  4229. ar6000_reportError_event(struct ar6_softc *ar, WMI_TARGET_ERROR_VAL errorVal)
  4230. {
  4231. static const char * const errString[] = {
  4232. [WMI_TARGET_PM_ERR_FAIL] "WMI_TARGET_PM_ERR_FAIL",
  4233. [WMI_TARGET_KEY_NOT_FOUND] "WMI_TARGET_KEY_NOT_FOUND",
  4234. [WMI_TARGET_DECRYPTION_ERR] "WMI_TARGET_DECRYPTION_ERR",
  4235. [WMI_TARGET_BMISS] "WMI_TARGET_BMISS",
  4236. [WMI_PSDISABLE_NODE_JOIN] "WMI_PSDISABLE_NODE_JOIN"
  4237. };
  4238. A_PRINTF("AR6000 Error on Target. Error = 0x%x\n", errorVal);
  4239. /* One error is reported at a time, and errorval is a bitmask */
  4240. if(errorVal & (errorVal - 1))
  4241. return;
  4242. A_PRINTF("AR6000 Error type = ");
  4243. switch(errorVal)
  4244. {
  4245. case WMI_TARGET_PM_ERR_FAIL:
  4246. case WMI_TARGET_KEY_NOT_FOUND:
  4247. case WMI_TARGET_DECRYPTION_ERR:
  4248. case WMI_TARGET_BMISS:
  4249. case WMI_PSDISABLE_NODE_JOIN:
  4250. A_PRINTF("%s\n", errString[errorVal]);
  4251. break;
  4252. default:
  4253. A_PRINTF("INVALID\n");
  4254. break;
  4255. }
  4256. }
  4257. void
  4258. ar6000_cac_event(struct ar6_softc *ar, u8 ac, u8 cacIndication,
  4259. u8 statusCode, u8 *tspecSuggestion)
  4260. {
  4261. WMM_TSPEC_IE *tspecIe;
  4262. /*
  4263. * This is the TSPEC IE suggestion from AP.
  4264. * Suggestion provided by AP under some error
  4265. * cases, could be helpful for the host app.
  4266. * Check documentation.
  4267. */
  4268. tspecIe = (WMM_TSPEC_IE *)tspecSuggestion;
  4269. /*
  4270. * What do we do, if we get TSPEC rejection? One thought
  4271. * that comes to mind is implictly delete the pstream...
  4272. */
  4273. A_PRINTF("AR6000 CAC notification. "
  4274. "AC = %d, cacIndication = 0x%x, statusCode = 0x%x\n",
  4275. ac, cacIndication, statusCode);
  4276. }
  4277. void
  4278. ar6000_channel_change_event(struct ar6_softc *ar, u16 oldChannel,
  4279. u16 newChannel)
  4280. {
  4281. A_PRINTF("Channel Change notification\nOld Channel: %d, New Channel: %d\n",
  4282. oldChannel, newChannel);
  4283. }
  4284. #define AR6000_PRINT_BSSID(_pBss) do { \
  4285. A_PRINTF("%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ",\
  4286. (_pBss)[0],(_pBss)[1],(_pBss)[2],(_pBss)[3],\
  4287. (_pBss)[4],(_pBss)[5]); \
  4288. } while(0)
  4289. void
  4290. ar6000_roam_tbl_event(struct ar6_softc *ar, WMI_TARGET_ROAM_TBL *pTbl)
  4291. {
  4292. u8 i;
  4293. A_PRINTF("ROAM TABLE NO OF ENTRIES is %d ROAM MODE is %d\n",
  4294. pTbl->numEntries, pTbl->roamMode);
  4295. for (i= 0; i < pTbl->numEntries; i++) {
  4296. A_PRINTF("[%d]bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ", i,
  4297. pTbl->bssRoamInfo[i].bssid[0], pTbl->bssRoamInfo[i].bssid[1],
  4298. pTbl->bssRoamInfo[i].bssid[2],
  4299. pTbl->bssRoamInfo[i].bssid[3],
  4300. pTbl->bssRoamInfo[i].bssid[4],
  4301. pTbl->bssRoamInfo[i].bssid[5]);
  4302. A_PRINTF("RSSI %d RSSIDT %d LAST RSSI %d UTIL %d ROAM_UTIL %d"
  4303. " BIAS %d\n",
  4304. pTbl->bssRoamInfo[i].rssi,
  4305. pTbl->bssRoamInfo[i].rssidt,
  4306. pTbl->bssRoamInfo[i].last_rssi,
  4307. pTbl->bssRoamInfo[i].util,
  4308. pTbl->bssRoamInfo[i].roam_util,
  4309. pTbl->bssRoamInfo[i].bias);
  4310. }
  4311. }
  4312. void
  4313. ar6000_wow_list_event(struct ar6_softc *ar, u8 num_filters, WMI_GET_WOW_LIST_REPLY *wow_reply)
  4314. {
  4315. u8 i,j;
  4316. /*Each event now contains exactly one filter, see bug 26613*/
  4317. A_PRINTF("WOW pattern %d of %d patterns\n", wow_reply->this_filter_num, wow_reply->num_filters);
  4318. A_PRINTF("wow mode = %s host mode = %s\n",
  4319. (wow_reply->wow_mode == 0? "disabled":"enabled"),
  4320. (wow_reply->host_mode == 1 ? "awake":"asleep"));
  4321. /*If there are no patterns, the reply will only contain generic
  4322. WoW information. Pattern information will exist only if there are
  4323. patterns present. Bug 26716*/
  4324. /* If this event contains pattern information, display it*/
  4325. if (wow_reply->this_filter_num) {
  4326. i=0;
  4327. A_PRINTF("id=%d size=%d offset=%d\n",
  4328. wow_reply->wow_filters[i].wow_filter_id,
  4329. wow_reply->wow_filters[i].wow_filter_size,
  4330. wow_reply->wow_filters[i].wow_filter_offset);
  4331. A_PRINTF("wow pattern = ");
  4332. for (j=0; j< wow_reply->wow_filters[i].wow_filter_size; j++) {
  4333. A_PRINTF("%2.2x",wow_reply->wow_filters[i].wow_filter_pattern[j]);
  4334. }
  4335. A_PRINTF("\nwow mask = ");
  4336. for (j=0; j< wow_reply->wow_filters[i].wow_filter_size; j++) {
  4337. A_PRINTF("%2.2x",wow_reply->wow_filters[i].wow_filter_mask[j]);
  4338. }
  4339. A_PRINTF("\n");
  4340. }
  4341. }
  4342. /*
  4343. * Report the Roaming related data collected on the target
  4344. */
  4345. void
  4346. ar6000_display_roam_time(WMI_TARGET_ROAM_TIME *p)
  4347. {
  4348. A_PRINTF("Disconnect Data : BSSID: ");
  4349. AR6000_PRINT_BSSID(p->disassoc_bssid);
  4350. A_PRINTF(" RSSI %d DISASSOC Time %d NO_TXRX_TIME %d\n",
  4351. p->disassoc_bss_rssi,p->disassoc_time,
  4352. p->no_txrx_time);
  4353. A_PRINTF("Connect Data: BSSID: ");
  4354. AR6000_PRINT_BSSID(p->assoc_bssid);
  4355. A_PRINTF(" RSSI %d ASSOC Time %d TXRX_TIME %d\n",
  4356. p->assoc_bss_rssi,p->assoc_time,
  4357. p->allow_txrx_time);
  4358. }
  4359. void
  4360. ar6000_roam_data_event(struct ar6_softc *ar, WMI_TARGET_ROAM_DATA *p)
  4361. {
  4362. switch (p->roamDataType) {
  4363. case ROAM_DATA_TIME:
  4364. ar6000_display_roam_time(&p->u.roamTime);
  4365. break;
  4366. default:
  4367. break;
  4368. }
  4369. }
  4370. void
  4371. ar6000_bssInfo_event_rx(struct ar6_softc *ar, u8 *datap, int len)
  4372. {
  4373. struct sk_buff *skb;
  4374. WMI_BSS_INFO_HDR *bih = (WMI_BSS_INFO_HDR *)datap;
  4375. if (!ar->arMgmtFilter) {
  4376. return;
  4377. }
  4378. if (((ar->arMgmtFilter & IEEE80211_FILTER_TYPE_BEACON) &&
  4379. (bih->frameType != BEACON_FTYPE)) ||
  4380. ((ar->arMgmtFilter & IEEE80211_FILTER_TYPE_PROBE_RESP) &&
  4381. (bih->frameType != PROBERESP_FTYPE)))
  4382. {
  4383. return;
  4384. }
  4385. if ((skb = A_NETBUF_ALLOC_RAW(len)) != NULL) {
  4386. A_NETBUF_PUT(skb, len);
  4387. memcpy(A_NETBUF_DATA(skb), datap, len);
  4388. skb->dev = ar->arNetDev;
  4389. memcpy(skb_mac_header(skb), A_NETBUF_DATA(skb), 6);
  4390. skb->ip_summed = CHECKSUM_NONE;
  4391. skb->pkt_type = PACKET_OTHERHOST;
  4392. skb->protocol = __constant_htons(0x0019);
  4393. netif_rx(skb);
  4394. }
  4395. }
  4396. u32 wmiSendCmdNum;
  4397. int
  4398. ar6000_control_tx(void *devt, void *osbuf, HTC_ENDPOINT_ID eid)
  4399. {
  4400. struct ar6_softc *ar = (struct ar6_softc *)devt;
  4401. int status = 0;
  4402. struct ar_cookie *cookie = NULL;
  4403. int i;
  4404. #ifdef CONFIG_PM
  4405. if (ar->arWowState != WLAN_WOW_STATE_NONE) {
  4406. A_NETBUF_FREE(osbuf);
  4407. return A_EACCES;
  4408. }
  4409. #endif /* CONFIG_PM */
  4410. /* take lock to protect ar6000_alloc_cookie() */
  4411. AR6000_SPIN_LOCK(&ar->arLock, 0);
  4412. do {
  4413. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar_contrstatus = ol_tx: skb=0x%lx, len=0x%x eid =%d\n",
  4414. (unsigned long)osbuf, A_NETBUF_LEN(osbuf), eid));
  4415. if (ar->arWMIControlEpFull && (eid == ar->arControlEp)) {
  4416. /* control endpoint is full, don't allocate resources, we
  4417. * are just going to drop this packet */
  4418. cookie = NULL;
  4419. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" WMI Control EP full, dropping packet : 0x%lX, len:%d \n",
  4420. (unsigned long)osbuf, A_NETBUF_LEN(osbuf)));
  4421. } else {
  4422. cookie = ar6000_alloc_cookie(ar);
  4423. }
  4424. if (cookie == NULL) {
  4425. status = A_NO_MEMORY;
  4426. break;
  4427. }
  4428. if(logWmiRawMsgs) {
  4429. A_PRINTF("WMI cmd send, msgNo %d :", wmiSendCmdNum);
  4430. for(i = 0; i < a_netbuf_to_len(osbuf); i++)
  4431. A_PRINTF("%x ", ((u8 *)a_netbuf_to_data(osbuf))[i]);
  4432. A_PRINTF("\n");
  4433. }
  4434. wmiSendCmdNum++;
  4435. } while (false);
  4436. if (cookie != NULL) {
  4437. /* got a structure to send it out on */
  4438. ar->arTxPending[eid]++;
  4439. if (eid != ar->arControlEp) {
  4440. ar->arTotalTxDataPending++;
  4441. }
  4442. }
  4443. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  4444. if (cookie != NULL) {
  4445. cookie->arc_bp[0] = (unsigned long)osbuf;
  4446. cookie->arc_bp[1] = 0;
  4447. SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
  4448. cookie,
  4449. A_NETBUF_DATA(osbuf),
  4450. A_NETBUF_LEN(osbuf),
  4451. eid,
  4452. AR6K_CONTROL_PKT_TAG);
  4453. /* this interface is asynchronous, if there is an error, cleanup will happen in the
  4454. * TX completion callback */
  4455. HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt);
  4456. status = 0;
  4457. }
  4458. if (status) {
  4459. A_NETBUF_FREE(osbuf);
  4460. }
  4461. return status;
  4462. }
  4463. /* indicate tx activity or inactivity on a WMI stream */
  4464. void ar6000_indicate_tx_activity(void *devt, u8 TrafficClass, bool Active)
  4465. {
  4466. struct ar6_softc *ar = (struct ar6_softc *)devt;
  4467. HTC_ENDPOINT_ID eid ;
  4468. int i;
  4469. if (ar->arWmiEnabled) {
  4470. eid = arAc2EndpointID(ar, TrafficClass);
  4471. AR6000_SPIN_LOCK(&ar->arLock, 0);
  4472. ar->arAcStreamActive[TrafficClass] = Active;
  4473. if (Active) {
  4474. /* when a stream goes active, keep track of the active stream with the highest priority */
  4475. if (ar->arAcStreamPriMap[TrafficClass] > ar->arHiAcStreamActivePri) {
  4476. /* set the new highest active priority */
  4477. ar->arHiAcStreamActivePri = ar->arAcStreamPriMap[TrafficClass];
  4478. }
  4479. } else {
  4480. /* when a stream goes inactive, we may have to search for the next active stream
  4481. * that is the highest priority */
  4482. if (ar->arHiAcStreamActivePri == ar->arAcStreamPriMap[TrafficClass]) {
  4483. /* the highest priority stream just went inactive */
  4484. /* reset and search for the "next" highest "active" priority stream */
  4485. ar->arHiAcStreamActivePri = 0;
  4486. for (i = 0; i < WMM_NUM_AC; i++) {
  4487. if (ar->arAcStreamActive[i]) {
  4488. if (ar->arAcStreamPriMap[i] > ar->arHiAcStreamActivePri) {
  4489. /* set the new highest active priority */
  4490. ar->arHiAcStreamActivePri = ar->arAcStreamPriMap[i];
  4491. }
  4492. }
  4493. }
  4494. }
  4495. }
  4496. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  4497. } else {
  4498. /* for mbox ping testing, the traffic class is mapped directly as a stream ID,
  4499. * see handling of AR6000_XIOCTL_TRAFFIC_ACTIVITY_CHANGE in ioctl.c
  4500. * convert the stream ID to a endpoint */
  4501. eid = arAc2EndpointID(ar, TrafficClass);
  4502. }
  4503. /* notify HTC, this may cause credit distribution changes */
  4504. HTCIndicateActivityChange(ar->arHtcTarget,
  4505. eid,
  4506. Active);
  4507. }
  4508. void
  4509. ar6000_btcoex_config_event(struct ar6_softc *ar, u8 *ptr, u32 len)
  4510. {
  4511. WMI_BTCOEX_CONFIG_EVENT *pBtcoexConfig = (WMI_BTCOEX_CONFIG_EVENT *)ptr;
  4512. WMI_BTCOEX_CONFIG_EVENT *pArbtcoexConfig =&ar->arBtcoexConfig;
  4513. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 BTCOEX CONFIG EVENT \n"));
  4514. A_PRINTF("received config event\n");
  4515. pArbtcoexConfig->btProfileType = pBtcoexConfig->btProfileType;
  4516. pArbtcoexConfig->linkId = pBtcoexConfig->linkId;
  4517. switch (pBtcoexConfig->btProfileType) {
  4518. case WMI_BTCOEX_BT_PROFILE_SCO:
  4519. memcpy(&pArbtcoexConfig->info.scoConfigCmd, &pBtcoexConfig->info.scoConfigCmd,
  4520. sizeof(WMI_SET_BTCOEX_SCO_CONFIG_CMD));
  4521. break;
  4522. case WMI_BTCOEX_BT_PROFILE_A2DP:
  4523. memcpy(&pArbtcoexConfig->info.a2dpConfigCmd, &pBtcoexConfig->info.a2dpConfigCmd,
  4524. sizeof(WMI_SET_BTCOEX_A2DP_CONFIG_CMD));
  4525. break;
  4526. case WMI_BTCOEX_BT_PROFILE_ACLCOEX:
  4527. memcpy(&pArbtcoexConfig->info.aclcoexConfig, &pBtcoexConfig->info.aclcoexConfig,
  4528. sizeof(WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMD));
  4529. break;
  4530. case WMI_BTCOEX_BT_PROFILE_INQUIRY_PAGE:
  4531. memcpy(&pArbtcoexConfig->info.btinquiryPageConfigCmd, &pBtcoexConfig->info.btinquiryPageConfigCmd,
  4532. sizeof(WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMD));
  4533. break;
  4534. }
  4535. if (ar->statsUpdatePending) {
  4536. ar->statsUpdatePending = false;
  4537. wake_up(&arEvent);
  4538. }
  4539. }
  4540. void
  4541. ar6000_btcoex_stats_event(struct ar6_softc *ar, u8 *ptr, u32 len)
  4542. {
  4543. WMI_BTCOEX_STATS_EVENT *pBtcoexStats = (WMI_BTCOEX_STATS_EVENT *)ptr;
  4544. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 BTCOEX CONFIG EVENT \n"));
  4545. memcpy(&ar->arBtcoexStats, pBtcoexStats, sizeof(WMI_BTCOEX_STATS_EVENT));
  4546. if (ar->statsUpdatePending) {
  4547. ar->statsUpdatePending = false;
  4548. wake_up(&arEvent);
  4549. }
  4550. }
  4551. module_init(ar6000_init_module);
  4552. module_exit(ar6000_cleanup_module);
  4553. /* Init cookie queue */
  4554. static void
  4555. ar6000_cookie_init(struct ar6_softc *ar)
  4556. {
  4557. u32 i;
  4558. ar->arCookieList = NULL;
  4559. ar->arCookieCount = 0;
  4560. A_MEMZERO(s_ar_cookie_mem, sizeof(s_ar_cookie_mem));
  4561. for (i = 0; i < MAX_COOKIE_NUM; i++) {
  4562. ar6000_free_cookie(ar, &s_ar_cookie_mem[i]);
  4563. }
  4564. }
  4565. /* cleanup cookie queue */
  4566. static void
  4567. ar6000_cookie_cleanup(struct ar6_softc *ar)
  4568. {
  4569. /* It is gone .... */
  4570. ar->arCookieList = NULL;
  4571. ar->arCookieCount = 0;
  4572. }
  4573. /* Init cookie queue */
  4574. static void
  4575. ar6000_free_cookie(struct ar6_softc *ar, struct ar_cookie * cookie)
  4576. {
  4577. /* Insert first */
  4578. A_ASSERT(ar != NULL);
  4579. A_ASSERT(cookie != NULL);
  4580. cookie->arc_list_next = ar->arCookieList;
  4581. ar->arCookieList = cookie;
  4582. ar->arCookieCount++;
  4583. }
  4584. /* cleanup cookie queue */
  4585. static struct ar_cookie *
  4586. ar6000_alloc_cookie(struct ar6_softc *ar)
  4587. {
  4588. struct ar_cookie *cookie;
  4589. cookie = ar->arCookieList;
  4590. if(cookie != NULL)
  4591. {
  4592. ar->arCookieList = cookie->arc_list_next;
  4593. ar->arCookieCount--;
  4594. }
  4595. return cookie;
  4596. }
  4597. void
  4598. ar6000_tx_retry_err_event(void *devt)
  4599. {
  4600. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Tx retries reach maximum!\n"));
  4601. }
  4602. void
  4603. ar6000_snrThresholdEvent_rx(void *devt, WMI_SNR_THRESHOLD_VAL newThreshold, u8 snr)
  4604. {
  4605. WMI_SNR_THRESHOLD_EVENT event;
  4606. event.range = newThreshold;
  4607. event.snr = snr;
  4608. }
  4609. void
  4610. ar6000_lqThresholdEvent_rx(void *devt, WMI_LQ_THRESHOLD_VAL newThreshold, u8 lq)
  4611. {
  4612. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("lq threshold range %d, lq %d\n", newThreshold, lq));
  4613. }
  4614. u32 a_copy_to_user(void *to, const void *from, u32 n)
  4615. {
  4616. return(copy_to_user(to, from, n));
  4617. }
  4618. u32 a_copy_from_user(void *to, const void *from, u32 n)
  4619. {
  4620. return(copy_from_user(to, from, n));
  4621. }
  4622. int
  4623. ar6000_get_driver_cfg(struct net_device *dev,
  4624. u16 cfgParam,
  4625. void *result)
  4626. {
  4627. int ret = 0;
  4628. switch(cfgParam)
  4629. {
  4630. case AR6000_DRIVER_CFG_GET_WLANNODECACHING:
  4631. *((u32 *)result) = wlanNodeCaching;
  4632. break;
  4633. case AR6000_DRIVER_CFG_LOG_RAW_WMI_MSGS:
  4634. *((u32 *)result) = logWmiRawMsgs;
  4635. break;
  4636. default:
  4637. ret = EINVAL;
  4638. break;
  4639. }
  4640. return ret;
  4641. }
  4642. void
  4643. ar6000_keepalive_rx(void *devt, u8 configured)
  4644. {
  4645. struct ar6_softc *ar = (struct ar6_softc *)devt;
  4646. ar->arKeepaliveConfigured = configured;
  4647. wake_up(&arEvent);
  4648. }
  4649. void
  4650. ar6000_pmkid_list_event(void *devt, u8 numPMKID, WMI_PMKID *pmkidList,
  4651. u8 *bssidList)
  4652. {
  4653. u8 i, j;
  4654. A_PRINTF("Number of Cached PMKIDs is %d\n", numPMKID);
  4655. for (i = 0; i < numPMKID; i++) {
  4656. A_PRINTF("\nBSSID %d ", i);
  4657. for (j = 0; j < ATH_MAC_LEN; j++) {
  4658. A_PRINTF("%2.2x", bssidList[j]);
  4659. }
  4660. bssidList += (ATH_MAC_LEN + WMI_PMKID_LEN);
  4661. A_PRINTF("\nPMKID %d ", i);
  4662. for (j = 0; j < WMI_PMKID_LEN; j++) {
  4663. A_PRINTF("%2.2x", pmkidList->pmkid[j]);
  4664. }
  4665. pmkidList = (WMI_PMKID *)((u8 *)pmkidList + ATH_MAC_LEN +
  4666. WMI_PMKID_LEN);
  4667. }
  4668. }
  4669. void ar6000_pspoll_event(struct ar6_softc *ar,u8 aid)
  4670. {
  4671. sta_t *conn=NULL;
  4672. bool isPsqEmpty = false;
  4673. conn = ieee80211_find_conn_for_aid(ar, aid);
  4674. /* If the PS q for this STA is not empty, dequeue and send a pkt from
  4675. * the head of the q. Also update the More data bit in the WMI_DATA_HDR
  4676. * if there are more pkts for this STA in the PS q. If there are no more
  4677. * pkts for this STA, update the PVB for this STA.
  4678. */
  4679. A_MUTEX_LOCK(&conn->psqLock);
  4680. isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq);
  4681. A_MUTEX_UNLOCK(&conn->psqLock);
  4682. if (isPsqEmpty) {
  4683. /* TODO:No buffered pkts for this STA. Send out a NULL data frame */
  4684. } else {
  4685. struct sk_buff *skb = NULL;
  4686. A_MUTEX_LOCK(&conn->psqLock);
  4687. skb = A_NETBUF_DEQUEUE(&conn->psq);
  4688. A_MUTEX_UNLOCK(&conn->psqLock);
  4689. /* Set the STA flag to PSPolled, so that the frame will go out */
  4690. STA_SET_PS_POLLED(conn);
  4691. ar6000_data_tx(skb, ar->arNetDev);
  4692. STA_CLR_PS_POLLED(conn);
  4693. /* Clear the PVB for this STA if the queue has become empty */
  4694. A_MUTEX_LOCK(&conn->psqLock);
  4695. isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq);
  4696. A_MUTEX_UNLOCK(&conn->psqLock);
  4697. if (isPsqEmpty) {
  4698. wmi_set_pvb_cmd(ar->arWmi, conn->aid, 0);
  4699. }
  4700. }
  4701. }
  4702. void ar6000_dtimexpiry_event(struct ar6_softc *ar)
  4703. {
  4704. bool isMcastQueued = false;
  4705. struct sk_buff *skb = NULL;
  4706. /* If there are no associated STAs, ignore the DTIM expiry event.
  4707. * There can be potential race conditions where the last associated
  4708. * STA may disconnect & before the host could clear the 'Indicate DTIM'
  4709. * request to the firmware, the firmware would have just indicated a DTIM
  4710. * expiry event. The race is between 'clear DTIM expiry cmd' going
  4711. * from the host to the firmware & the DTIM expiry event happening from
  4712. * the firmware to the host.
  4713. */
  4714. if (ar->sta_list_index == 0) {
  4715. return;
  4716. }
  4717. A_MUTEX_LOCK(&ar->mcastpsqLock);
  4718. isMcastQueued = A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq);
  4719. A_MUTEX_UNLOCK(&ar->mcastpsqLock);
  4720. A_ASSERT(isMcastQueued == false);
  4721. /* Flush the mcast psq to the target */
  4722. /* Set the STA flag to DTIMExpired, so that the frame will go out */
  4723. ar->DTIMExpired = true;
  4724. A_MUTEX_LOCK(&ar->mcastpsqLock);
  4725. while (!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) {
  4726. skb = A_NETBUF_DEQUEUE(&ar->mcastpsq);
  4727. A_MUTEX_UNLOCK(&ar->mcastpsqLock);
  4728. ar6000_data_tx(skb, ar->arNetDev);
  4729. A_MUTEX_LOCK(&ar->mcastpsqLock);
  4730. }
  4731. A_MUTEX_UNLOCK(&ar->mcastpsqLock);
  4732. /* Reset the DTIMExpired flag back to 0 */
  4733. ar->DTIMExpired = false;
  4734. /* Clear the LSB of the BitMapCtl field of the TIM IE */
  4735. wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 0);
  4736. }
  4737. void
  4738. read_rssi_compensation_param(struct ar6_softc *ar)
  4739. {
  4740. u8 *cust_data_ptr;
  4741. //#define RSSICOMPENSATION_PRINT
  4742. #ifdef RSSICOMPENSATION_PRINT
  4743. s16 i;
  4744. cust_data_ptr = ar6000_get_cust_data_buffer(ar->arTargetType);
  4745. for (i=0; i<16; i++) {
  4746. A_PRINTF("cust_data_%d = %x \n", i, *(u8 *)cust_data_ptr);
  4747. cust_data_ptr += 1;
  4748. }
  4749. #endif
  4750. cust_data_ptr = ar6000_get_cust_data_buffer(ar->arTargetType);
  4751. rssi_compensation_param.customerID = *(u16 *)cust_data_ptr & 0xffff;
  4752. rssi_compensation_param.enable = *(u16 *)(cust_data_ptr+2) & 0xffff;
  4753. rssi_compensation_param.bg_param_a = *(u16 *)(cust_data_ptr+4) & 0xffff;
  4754. rssi_compensation_param.bg_param_b = *(u16 *)(cust_data_ptr+6) & 0xffff;
  4755. rssi_compensation_param.a_param_a = *(u16 *)(cust_data_ptr+8) & 0xffff;
  4756. rssi_compensation_param.a_param_b = *(u16 *)(cust_data_ptr+10) &0xffff;
  4757. rssi_compensation_param.reserved = *(u32 *)(cust_data_ptr+12);
  4758. #ifdef RSSICOMPENSATION_PRINT
  4759. A_PRINTF("customerID = 0x%x \n", rssi_compensation_param.customerID);
  4760. A_PRINTF("enable = 0x%x \n", rssi_compensation_param.enable);
  4761. A_PRINTF("bg_param_a = 0x%x and %d \n", rssi_compensation_param.bg_param_a, rssi_compensation_param.bg_param_a);
  4762. A_PRINTF("bg_param_b = 0x%x and %d \n", rssi_compensation_param.bg_param_b, rssi_compensation_param.bg_param_b);
  4763. A_PRINTF("a_param_a = 0x%x and %d \n", rssi_compensation_param.a_param_a, rssi_compensation_param.a_param_a);
  4764. A_PRINTF("a_param_b = 0x%x and %d \n", rssi_compensation_param.a_param_b, rssi_compensation_param.a_param_b);
  4765. A_PRINTF("Last 4 bytes = 0x%x \n", rssi_compensation_param.reserved);
  4766. #endif
  4767. if (rssi_compensation_param.enable != 0x1) {
  4768. rssi_compensation_param.enable = 0;
  4769. }
  4770. return;
  4771. }
  4772. s32 rssi_compensation_calc_tcmd(u32 freq, s32 rssi, u32 totalPkt)
  4773. {
  4774. if (freq > 5000)
  4775. {
  4776. if (rssi_compensation_param.enable)
  4777. {
  4778. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n"));
  4779. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d, totalPkt = %d\n", rssi,totalPkt));
  4780. rssi = rssi * rssi_compensation_param.a_param_a + totalPkt * rssi_compensation_param.a_param_b;
  4781. rssi = (rssi-50) /100;
  4782. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
  4783. }
  4784. }
  4785. else
  4786. {
  4787. if (rssi_compensation_param.enable)
  4788. {
  4789. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n"));
  4790. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d, totalPkt = %d\n", rssi,totalPkt));
  4791. rssi = rssi * rssi_compensation_param.bg_param_a + totalPkt * rssi_compensation_param.bg_param_b;
  4792. rssi = (rssi-50) /100;
  4793. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
  4794. }
  4795. }
  4796. return rssi;
  4797. }
  4798. s16 rssi_compensation_calc(struct ar6_softc *ar, s16 rssi)
  4799. {
  4800. if (ar->arBssChannel > 5000)
  4801. {
  4802. if (rssi_compensation_param.enable)
  4803. {
  4804. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n"));
  4805. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d\n", rssi));
  4806. rssi = rssi * rssi_compensation_param.a_param_a + rssi_compensation_param.a_param_b;
  4807. rssi = (rssi-50) /100;
  4808. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
  4809. }
  4810. }
  4811. else
  4812. {
  4813. if (rssi_compensation_param.enable)
  4814. {
  4815. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n"));
  4816. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d\n", rssi));
  4817. rssi = rssi * rssi_compensation_param.bg_param_a + rssi_compensation_param.bg_param_b;
  4818. rssi = (rssi-50) /100;
  4819. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
  4820. }
  4821. }
  4822. return rssi;
  4823. }
  4824. s16 rssi_compensation_reverse_calc(struct ar6_softc *ar, s16 rssi, bool Above)
  4825. {
  4826. s16 i;
  4827. if (ar->arBssChannel > 5000)
  4828. {
  4829. if (rssi_compensation_param.enable)
  4830. {
  4831. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n"));
  4832. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before rev compensation = %d\n", rssi));
  4833. rssi = rssi * 100;
  4834. rssi = (rssi - rssi_compensation_param.a_param_b) / rssi_compensation_param.a_param_a;
  4835. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after rev compensation = %d\n", rssi));
  4836. }
  4837. }
  4838. else
  4839. {
  4840. if (rssi_compensation_param.enable)
  4841. {
  4842. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n"));
  4843. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before rev compensation = %d\n", rssi));
  4844. if (Above) {
  4845. for (i=95; i>=0; i--) {
  4846. if (rssi <= rssi_compensation_table[i]) {
  4847. rssi = 0 - i;
  4848. break;
  4849. }
  4850. }
  4851. } else {
  4852. for (i=0; i<=95; i++) {
  4853. if (rssi >= rssi_compensation_table[i]) {
  4854. rssi = 0 - i;
  4855. break;
  4856. }
  4857. }
  4858. }
  4859. AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after rev compensation = %d\n", rssi));
  4860. }
  4861. }
  4862. return rssi;
  4863. }
  4864. #ifdef WAPI_ENABLE
  4865. void ap_wapi_rekey_event(struct ar6_softc *ar, u8 type, u8 *mac)
  4866. {
  4867. union iwreq_data wrqu;
  4868. char buf[20];
  4869. A_MEMZERO(buf, sizeof(buf));
  4870. strcpy(buf, "WAPI_REKEY");
  4871. buf[10] = type;
  4872. memcpy(&buf[11], mac, ATH_MAC_LEN);
  4873. A_MEMZERO(&wrqu, sizeof(wrqu));
  4874. wrqu.data.length = 10+1+ATH_MAC_LEN;
  4875. wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
  4876. A_PRINTF("WAPI REKEY - %d - %02x:%02x\n", type, mac[4], mac[5]);
  4877. }
  4878. #endif
  4879. static int
  4880. ar6000_reinstall_keys(struct ar6_softc *ar, u8 key_op_ctrl)
  4881. {
  4882. int status = 0;
  4883. struct ieee80211req_key *uik = &ar->user_saved_keys.ucast_ik;
  4884. struct ieee80211req_key *bik = &ar->user_saved_keys.bcast_ik;
  4885. CRYPTO_TYPE keyType = ar->user_saved_keys.keyType;
  4886. if (IEEE80211_CIPHER_CCKM_KRK != uik->ik_type) {
  4887. if (NONE_CRYPT == keyType) {
  4888. goto _reinstall_keys_out;
  4889. }
  4890. if (uik->ik_keylen) {
  4891. status = wmi_addKey_cmd(ar->arWmi, uik->ik_keyix,
  4892. ar->user_saved_keys.keyType, PAIRWISE_USAGE,
  4893. uik->ik_keylen, (u8 *)&uik->ik_keyrsc,
  4894. uik->ik_keydata, key_op_ctrl, uik->ik_macaddr, SYNC_BEFORE_WMIFLAG);
  4895. }
  4896. } else {
  4897. status = wmi_add_krk_cmd(ar->arWmi, uik->ik_keydata);
  4898. }
  4899. if (IEEE80211_CIPHER_CCKM_KRK != bik->ik_type) {
  4900. if (NONE_CRYPT == keyType) {
  4901. goto _reinstall_keys_out;
  4902. }
  4903. if (bik->ik_keylen) {
  4904. status = wmi_addKey_cmd(ar->arWmi, bik->ik_keyix,
  4905. ar->user_saved_keys.keyType, GROUP_USAGE,
  4906. bik->ik_keylen, (u8 *)&bik->ik_keyrsc,
  4907. bik->ik_keydata, key_op_ctrl, bik->ik_macaddr, NO_SYNC_WMIFLAG);
  4908. }
  4909. } else {
  4910. status = wmi_add_krk_cmd(ar->arWmi, bik->ik_keydata);
  4911. }
  4912. _reinstall_keys_out:
  4913. ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT;
  4914. ar->user_key_ctrl = 0;
  4915. return status;
  4916. }
  4917. void
  4918. ar6000_dset_open_req(
  4919. void *context,
  4920. u32 id,
  4921. u32 targHandle,
  4922. u32 targReplyFn,
  4923. u32 targReplyArg)
  4924. {
  4925. }
  4926. void
  4927. ar6000_dset_close(
  4928. void *context,
  4929. u32 access_cookie)
  4930. {
  4931. return;
  4932. }
  4933. void
  4934. ar6000_dset_data_req(
  4935. void *context,
  4936. u32 accessCookie,
  4937. u32 offset,
  4938. u32 length,
  4939. u32 targBuf,
  4940. u32 targReplyFn,
  4941. u32 targReplyArg)
  4942. {
  4943. }
  4944. int
  4945. ar6000_ap_mode_profile_commit(struct ar6_softc *ar)
  4946. {
  4947. WMI_CONNECT_CMD p;
  4948. unsigned long flags;
  4949. /* No change in AP's profile configuration */
  4950. if(ar->ap_profile_flag==0) {
  4951. A_PRINTF("COMMIT: No change in profile!!!\n");
  4952. return -ENODATA;
  4953. }
  4954. if(!ar->arSsidLen) {
  4955. A_PRINTF("SSID not set!!!\n");
  4956. return -ECHRNG;
  4957. }
  4958. switch(ar->arAuthMode) {
  4959. case NONE_AUTH:
  4960. if((ar->arPairwiseCrypto != NONE_CRYPT) &&
  4961. #ifdef WAPI_ENABLE
  4962. (ar->arPairwiseCrypto != WAPI_CRYPT) &&
  4963. #endif
  4964. (ar->arPairwiseCrypto != WEP_CRYPT)) {
  4965. A_PRINTF("Cipher not supported in AP mode Open auth\n");
  4966. return -EOPNOTSUPP;
  4967. }
  4968. break;
  4969. case WPA_PSK_AUTH:
  4970. case WPA2_PSK_AUTH:
  4971. case (WPA_PSK_AUTH|WPA2_PSK_AUTH):
  4972. break;
  4973. default:
  4974. A_PRINTF("This key mgmt type not supported in AP mode\n");
  4975. return -EOPNOTSUPP;
  4976. }
  4977. /* Update the arNetworkType */
  4978. ar->arNetworkType = ar->arNextMode;
  4979. A_MEMZERO(&p,sizeof(p));
  4980. p.ssidLength = ar->arSsidLen;
  4981. memcpy(p.ssid,ar->arSsid,p.ssidLength);
  4982. p.channel = ar->arChannelHint;
  4983. p.networkType = ar->arNetworkType;
  4984. p.dot11AuthMode = ar->arDot11AuthMode;
  4985. p.authMode = ar->arAuthMode;
  4986. p.pairwiseCryptoType = ar->arPairwiseCrypto;
  4987. p.pairwiseCryptoLen = ar->arPairwiseCryptoLen;
  4988. p.groupCryptoType = ar->arGroupCrypto;
  4989. p.groupCryptoLen = ar->arGroupCryptoLen;
  4990. p.ctrl_flags = ar->arConnectCtrlFlags;
  4991. wmi_ap_profile_commit(ar->arWmi, &p);
  4992. spin_lock_irqsave(&ar->arLock, flags);
  4993. ar->arConnected = true;
  4994. netif_carrier_on(ar->arNetDev);
  4995. spin_unlock_irqrestore(&ar->arLock, flags);
  4996. ar->ap_profile_flag = 0;
  4997. return 0;
  4998. }
  4999. int
  5000. ar6000_connect_to_ap(struct ar6_softc *ar)
  5001. {
  5002. /* The ssid length check prevents second "essid off" from the user,
  5003. to be treated as a connect cmd. The second "essid off" is ignored.
  5004. */
  5005. if((ar->arWmiReady == true) && (ar->arSsidLen > 0) && ar->arNetworkType!=AP_NETWORK)
  5006. {
  5007. int status;
  5008. if((ADHOC_NETWORK != ar->arNetworkType) &&
  5009. (NONE_AUTH==ar->arAuthMode) &&
  5010. (WEP_CRYPT==ar->arPairwiseCrypto)) {
  5011. ar6000_install_static_wep_keys(ar);
  5012. }
  5013. if (!ar->arUserBssFilter) {
  5014. if (wmi_bssfilter_cmd(ar->arWmi, ALL_BSS_FILTER, 0) != 0) {
  5015. return -EIO;
  5016. }
  5017. }
  5018. #ifdef WAPI_ENABLE
  5019. if (ar->arWapiEnable) {
  5020. ar->arPairwiseCrypto = WAPI_CRYPT;
  5021. ar->arPairwiseCryptoLen = 0;
  5022. ar->arGroupCrypto = WAPI_CRYPT;
  5023. ar->arGroupCryptoLen = 0;
  5024. ar->arAuthMode = NONE_AUTH;
  5025. ar->arConnectCtrlFlags |= CONNECT_IGNORE_WPAx_GROUP_CIPHER;
  5026. }
  5027. #endif
  5028. AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("Connect called with authmode %d dot11 auth %d"\
  5029. " PW crypto %d PW crypto Len %d GRP crypto %d"\
  5030. " GRP crypto Len %d\n",
  5031. ar->arAuthMode, ar->arDot11AuthMode,
  5032. ar->arPairwiseCrypto, ar->arPairwiseCryptoLen,
  5033. ar->arGroupCrypto, ar->arGroupCryptoLen));
  5034. reconnect_flag = 0;
  5035. /* Set the listen interval into 1000TUs or more. This value will be indicated to Ap in the conn.
  5036. later set it back locally at the STA to 100/1000 TUs depending on the power mode */
  5037. if ((ar->arNetworkType == INFRA_NETWORK)) {
  5038. wmi_listeninterval_cmd(ar->arWmi, max(ar->arListenIntervalT, (u16)A_MAX_WOW_LISTEN_INTERVAL), 0);
  5039. }
  5040. status = wmi_connect_cmd(ar->arWmi, ar->arNetworkType,
  5041. ar->arDot11AuthMode, ar->arAuthMode,
  5042. ar->arPairwiseCrypto, ar->arPairwiseCryptoLen,
  5043. ar->arGroupCrypto,ar->arGroupCryptoLen,
  5044. ar->arSsidLen, ar->arSsid,
  5045. ar->arReqBssid, ar->arChannelHint,
  5046. ar->arConnectCtrlFlags);
  5047. if (status) {
  5048. wmi_listeninterval_cmd(ar->arWmi, ar->arListenIntervalT, ar->arListenIntervalB);
  5049. if (!ar->arUserBssFilter) {
  5050. wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
  5051. }
  5052. return status;
  5053. }
  5054. if ((!(ar->arConnectCtrlFlags & CONNECT_DO_WPA_OFFLOAD)) &&
  5055. ((WPA_PSK_AUTH == ar->arAuthMode) || (WPA2_PSK_AUTH == ar->arAuthMode)))
  5056. {
  5057. A_TIMEOUT_MS(&ar->disconnect_timer, A_DISCONNECT_TIMER_INTERVAL, 0);
  5058. }
  5059. ar->arConnectCtrlFlags &= ~CONNECT_DO_WPA_OFFLOAD;
  5060. ar->arConnectPending = true;
  5061. return status;
  5062. }
  5063. return A_ERROR;
  5064. }
  5065. int
  5066. ar6000_disconnect(struct ar6_softc *ar)
  5067. {
  5068. if ((ar->arConnected == true) || (ar->arConnectPending == true)) {
  5069. wmi_disconnect_cmd(ar->arWmi);
  5070. /*
  5071. * Disconnect cmd is issued, clear connectPending.
  5072. * arConnected will be cleard in disconnect_event notification.
  5073. */
  5074. ar->arConnectPending = false;
  5075. }
  5076. return 0;
  5077. }
  5078. int
  5079. ar6000_ap_mode_get_wpa_ie(struct ar6_softc *ar, struct ieee80211req_wpaie *wpaie)
  5080. {
  5081. sta_t *conn = NULL;
  5082. conn = ieee80211_find_conn(ar, wpaie->wpa_macaddr);
  5083. A_MEMZERO(wpaie->wpa_ie, IEEE80211_MAX_IE);
  5084. A_MEMZERO(wpaie->rsn_ie, IEEE80211_MAX_IE);
  5085. if(conn) {
  5086. memcpy(wpaie->wpa_ie, conn->wpa_ie, IEEE80211_MAX_IE);
  5087. }
  5088. return 0;
  5089. }
  5090. int
  5091. is_iwioctl_allowed(u8 mode, u16 cmd)
  5092. {
  5093. if(cmd >= SIOCSIWCOMMIT && cmd <= SIOCGIWPOWER) {
  5094. cmd -= SIOCSIWCOMMIT;
  5095. if(sioctl_filter[cmd] == 0xFF) return 0;
  5096. if(sioctl_filter[cmd] & mode) return 0;
  5097. } else if(cmd >= SIOCIWFIRSTPRIV && cmd <= (SIOCIWFIRSTPRIV+30)) {
  5098. cmd -= SIOCIWFIRSTPRIV;
  5099. if(pioctl_filter[cmd] == 0xFF) return 0;
  5100. if(pioctl_filter[cmd] & mode) return 0;
  5101. } else {
  5102. return A_ERROR;
  5103. }
  5104. return A_ENOTSUP;
  5105. }
  5106. int
  5107. is_xioctl_allowed(u8 mode, int cmd)
  5108. {
  5109. if(sizeof(xioctl_filter)-1 < cmd) {
  5110. A_PRINTF("Filter for this cmd=%d not defined\n",cmd);
  5111. return 0;
  5112. }
  5113. if(xioctl_filter[cmd] == 0xFF) return 0;
  5114. if(xioctl_filter[cmd] & mode) return 0;
  5115. return A_ERROR;
  5116. }
  5117. #ifdef WAPI_ENABLE
  5118. int
  5119. ap_set_wapi_key(struct ar6_softc *ar, void *ikey)
  5120. {
  5121. struct ieee80211req_key *ik = (struct ieee80211req_key *)ikey;
  5122. KEY_USAGE keyUsage = 0;
  5123. int status;
  5124. if (memcmp(ik->ik_macaddr, bcast_mac, IEEE80211_ADDR_LEN) == 0) {
  5125. keyUsage = GROUP_USAGE;
  5126. } else {
  5127. keyUsage = PAIRWISE_USAGE;
  5128. }
  5129. A_PRINTF("WAPI_KEY: Type:%d ix:%d mac:%02x:%02x len:%d\n",
  5130. keyUsage, ik->ik_keyix, ik->ik_macaddr[4], ik->ik_macaddr[5],
  5131. ik->ik_keylen);
  5132. status = wmi_addKey_cmd(ar->arWmi, ik->ik_keyix, WAPI_CRYPT, keyUsage,
  5133. ik->ik_keylen, (u8 *)&ik->ik_keyrsc,
  5134. ik->ik_keydata, KEY_OP_INIT_VAL, ik->ik_macaddr,
  5135. SYNC_BOTH_WMIFLAG);
  5136. if (0 != status) {
  5137. return -EIO;
  5138. }
  5139. return 0;
  5140. }
  5141. #endif
  5142. void ar6000_peer_event(
  5143. void *context,
  5144. u8 eventCode,
  5145. u8 *macAddr)
  5146. {
  5147. u8 pos;
  5148. for (pos=0;pos<6;pos++)
  5149. printk("%02x: ",*(macAddr+pos));
  5150. printk("\n");
  5151. }
  5152. #ifdef HTC_TEST_SEND_PKTS
  5153. #define HTC_TEST_DUPLICATE 8
  5154. static void DoHTCSendPktsTest(struct ar6_softc *ar, int MapNo, HTC_ENDPOINT_ID eid, struct sk_buff *dupskb)
  5155. {
  5156. struct ar_cookie *cookie;
  5157. struct ar_cookie *cookieArray[HTC_TEST_DUPLICATE];
  5158. struct sk_buff *new_skb;
  5159. int i;
  5160. int pkts = 0;
  5161. struct htc_packet_queue pktQueue;
  5162. EPPING_HEADER *eppingHdr;
  5163. eppingHdr = A_NETBUF_DATA(dupskb);
  5164. if (eppingHdr->Cmd_h == EPPING_CMD_NO_ECHO) {
  5165. /* skip test if this is already a tx perf test */
  5166. return;
  5167. }
  5168. for (i = 0; i < HTC_TEST_DUPLICATE; i++,pkts++) {
  5169. AR6000_SPIN_LOCK(&ar->arLock, 0);
  5170. cookie = ar6000_alloc_cookie(ar);
  5171. if (cookie != NULL) {
  5172. ar->arTxPending[eid]++;
  5173. ar->arTotalTxDataPending++;
  5174. }
  5175. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  5176. if (NULL == cookie) {
  5177. break;
  5178. }
  5179. new_skb = A_NETBUF_ALLOC(A_NETBUF_LEN(dupskb));
  5180. if (new_skb == NULL) {
  5181. AR6000_SPIN_LOCK(&ar->arLock, 0);
  5182. ar6000_free_cookie(ar,cookie);
  5183. AR6000_SPIN_UNLOCK(&ar->arLock, 0);
  5184. break;
  5185. }
  5186. A_NETBUF_PUT_DATA(new_skb, A_NETBUF_DATA(dupskb), A_NETBUF_LEN(dupskb));
  5187. cookie->arc_bp[0] = (unsigned long)new_skb;
  5188. cookie->arc_bp[1] = MapNo;
  5189. SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
  5190. cookie,
  5191. A_NETBUF_DATA(new_skb),
  5192. A_NETBUF_LEN(new_skb),
  5193. eid,
  5194. AR6K_DATA_PKT_TAG);
  5195. cookieArray[i] = cookie;
  5196. {
  5197. EPPING_HEADER *pHdr = (EPPING_HEADER *)A_NETBUF_DATA(new_skb);
  5198. pHdr->Cmd_h = EPPING_CMD_NO_ECHO; /* do not echo the packet */
  5199. }
  5200. }
  5201. if (pkts == 0) {
  5202. return;
  5203. }
  5204. INIT_HTC_PACKET_QUEUE(&pktQueue);
  5205. for (i = 0; i < pkts; i++) {
  5206. HTC_PACKET_ENQUEUE(&pktQueue,&cookieArray[i]->HtcPkt);
  5207. }
  5208. HTCSendPktsMultiple(ar->arHtcTarget, &pktQueue);
  5209. }
  5210. #endif
  5211. #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
  5212. /*
  5213. * Add support for adding and removing a virtual adapter for soft AP.
  5214. * Some OS requires different adapters names for station and soft AP mode.
  5215. * To support these requirement, create and destroy a netdevice instance
  5216. * when the AP mode is operational. A full fledged support for virual device
  5217. * is not implemented. Rather a virtual interface is created and is linked
  5218. * with the existing physical device instance during the operation of the
  5219. * AP mode.
  5220. */
  5221. int ar6000_start_ap_interface(struct ar6_softc *ar)
  5222. {
  5223. struct ar_virtual_interface *arApDev;
  5224. /* Change net_device to point to AP instance */
  5225. arApDev = (struct ar_virtual_interface *)ar->arApDev;
  5226. ar->arNetDev = arApDev->arNetDev;
  5227. return 0;
  5228. }
  5229. int ar6000_stop_ap_interface(struct ar6_softc *ar)
  5230. {
  5231. struct ar_virtual_interface *arApDev;
  5232. /* Change net_device to point to sta instance */
  5233. arApDev = (struct ar_virtual_interface *)ar->arApDev;
  5234. if (arApDev) {
  5235. ar->arNetDev = arApDev->arStaNetDev;
  5236. }
  5237. return 0;
  5238. }
  5239. int ar6000_create_ap_interface(struct ar6_softc *ar, char *ap_ifname)
  5240. {
  5241. struct net_device *dev;
  5242. struct ar_virtual_interface *arApDev;
  5243. dev = alloc_etherdev(sizeof(struct ar_virtual_interface));
  5244. if (dev == NULL) {
  5245. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_create_ap_interface: can't alloc etherdev\n"));
  5246. return A_ERROR;
  5247. }
  5248. ether_setup(dev);
  5249. init_netdev(dev, ap_ifname);
  5250. dev->priv_flags &= ~IFF_TX_SKB_SHARING;
  5251. if (register_netdev(dev)) {
  5252. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_create_ap_interface: register_netdev failed\n"));
  5253. return A_ERROR;
  5254. }
  5255. arApDev = netdev_priv(dev);
  5256. arApDev->arDev = ar;
  5257. arApDev->arNetDev = dev;
  5258. arApDev->arStaNetDev = ar->arNetDev;
  5259. ar->arApDev = arApDev;
  5260. arApNetDev = dev;
  5261. /* Copy the MAC address */
  5262. memcpy(dev->dev_addr, ar->arNetDev->dev_addr, AR6000_ETH_ADDR_LEN);
  5263. return 0;
  5264. }
  5265. int ar6000_add_ap_interface(struct ar6_softc *ar, char *ap_ifname)
  5266. {
  5267. /* Interface already added, need not proceed further */
  5268. if (ar->arApDev != NULL) {
  5269. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_add_ap_interface: interface already present \n"));
  5270. return 0;
  5271. }
  5272. if (ar6000_create_ap_interface(ar, ap_ifname) != 0) {
  5273. return A_ERROR;
  5274. }
  5275. A_PRINTF("Add AP interface %s \n",ap_ifname);
  5276. return ar6000_start_ap_interface(ar);
  5277. }
  5278. int ar6000_remove_ap_interface(struct ar6_softc *ar)
  5279. {
  5280. if (arApNetDev) {
  5281. ar6000_stop_ap_interface(ar);
  5282. unregister_netdev(arApNetDev);
  5283. free_netdev(apApNetDev);
  5284. A_PRINTF("Remove AP interface\n");
  5285. }
  5286. ar->arApDev = NULL;
  5287. arApNetDev = NULL;
  5288. return 0;
  5289. }
  5290. #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
  5291. #ifdef EXPORT_HCI_BRIDGE_INTERFACE
  5292. EXPORT_SYMBOL(setupbtdev);
  5293. #endif