PageRenderTime 2946ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 2ms

/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

Large files files are truncated, but you can click here to view the full file

  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"));

Large files files are truncated, but you can click here to view the full file