linux_wlan.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832
  1. #include "wilc_wfi_cfgoperations.h"
  2. #include "linux_wlan_common.h"
  3. #include "wilc_wlan_if.h"
  4. #include "wilc_wlan.h"
  5. #include <linux/slab.h>
  6. #include <linux/sched.h>
  7. #include <linux/delay.h>
  8. #include <linux/workqueue.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/irq.h>
  11. #include <linux/gpio.h>
  12. #include <linux/kthread.h>
  13. #include <linux/firmware.h>
  14. #include <linux/delay.h>
  15. #include <linux/init.h>
  16. #include <linux/netdevice.h>
  17. #include <linux/inetdevice.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/module.h>
  20. #include <linux/kernel.h>
  21. #include <linux/skbuff.h>
  22. #include <linux/version.h>
  23. #include <linux/semaphore.h>
  24. #ifdef WILC_SDIO
  25. #include "linux_wlan_sdio.h"
  26. #else
  27. #include "linux_wlan_spi.h"
  28. #endif
  29. #if defined(CUSTOMER_PLATFORM)
  30. /*
  31. TODO : Write power control functions as customer platform.
  32. */
  33. #else
  34. #define _linux_wlan_device_power_on() {}
  35. #define _linux_wlan_device_power_off() {}
  36. #define _linux_wlan_device_detection() {}
  37. #define _linux_wlan_device_removal() {}
  38. #endif
  39. extern bool g_obtainingIP;
  40. extern void resolve_disconnect_aberration(void *drvHandler);
  41. extern u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
  42. extern struct timer_list hDuringIpTimer;
  43. static int linux_wlan_device_power(int on_off)
  44. {
  45. PRINT_D(INIT_DBG, "linux_wlan_device_power.. (%d)\n", on_off);
  46. if (on_off) {
  47. _linux_wlan_device_power_on();
  48. } else {
  49. _linux_wlan_device_power_off();
  50. }
  51. return 0;
  52. }
  53. static int linux_wlan_device_detection(int on_off)
  54. {
  55. PRINT_D(INIT_DBG, "linux_wlan_device_detection.. (%d)\n", on_off);
  56. #ifdef WILC_SDIO
  57. if (on_off) {
  58. _linux_wlan_device_detection();
  59. } else {
  60. _linux_wlan_device_removal();
  61. }
  62. #endif
  63. return 0;
  64. }
  65. static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr);
  66. static struct notifier_block g_dev_notifier = {
  67. .notifier_call = dev_state_ev_handler
  68. };
  69. #define IRQ_WAIT 1
  70. #define IRQ_NO_WAIT 0
  71. /*
  72. * to sync between mac_close and module exit.
  73. * don't initialize or de-initialize from init/deinitlocks
  74. * to be initialized from module wilc_netdev_init and
  75. * deinitialized from mdoule_exit
  76. */
  77. static struct semaphore close_exit_sync;
  78. static int wlan_deinit_locks(struct net_device *dev);
  79. static void wlan_deinitialize_threads(struct net_device *dev);
  80. extern void WILC_WFI_monitor_rx(u8 *buff, u32 size);
  81. extern void WILC_WFI_p2p_rx(struct net_device *dev, u8 *buff, u32 size);
  82. static void linux_wlan_tx_complete(void *priv, int status);
  83. static int mac_init_fn(struct net_device *ndev);
  84. int mac_xmit(struct sk_buff *skb, struct net_device *dev);
  85. int mac_open(struct net_device *ndev);
  86. int mac_close(struct net_device *ndev);
  87. static struct net_device_stats *mac_stats(struct net_device *dev);
  88. static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd);
  89. static void wilc_set_multicast_list(struct net_device *dev);
  90. /*
  91. * for now - in frmw_to_linux there should be private data to be passed to it
  92. * and this data should be pointer to net device
  93. */
  94. struct wilc *g_linux_wlan;
  95. bool bEnablePS = true;
  96. static const struct net_device_ops wilc_netdev_ops = {
  97. .ndo_init = mac_init_fn,
  98. .ndo_open = mac_open,
  99. .ndo_stop = mac_close,
  100. .ndo_start_xmit = mac_xmit,
  101. .ndo_do_ioctl = mac_ioctl,
  102. .ndo_get_stats = mac_stats,
  103. .ndo_set_rx_mode = wilc_set_multicast_list,
  104. };
  105. static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr)
  106. {
  107. struct in_ifaddr *dev_iface = (struct in_ifaddr *)ptr;
  108. struct wilc_priv *priv;
  109. struct host_if_drv *pstrWFIDrv;
  110. struct net_device *dev;
  111. u8 *pIP_Add_buff;
  112. perInterface_wlan_t *nic;
  113. u8 null_ip[4] = {0};
  114. char wlan_dev_name[5] = "wlan0";
  115. if (dev_iface == NULL || dev_iface->ifa_dev == NULL || dev_iface->ifa_dev->dev == NULL) {
  116. PRINT_D(GENERIC_DBG, "dev_iface = NULL\n");
  117. return NOTIFY_DONE;
  118. }
  119. if ((memcmp(dev_iface->ifa_label, "wlan0", 5)) && (memcmp(dev_iface->ifa_label, "p2p0", 4))) {
  120. PRINT_D(GENERIC_DBG, "Interface is neither WLAN0 nor P2P0\n");
  121. return NOTIFY_DONE;
  122. }
  123. dev = (struct net_device *)dev_iface->ifa_dev->dev;
  124. if (dev->ieee80211_ptr == NULL || dev->ieee80211_ptr->wiphy == NULL) {
  125. PRINT_D(GENERIC_DBG, "No Wireless registerd\n");
  126. return NOTIFY_DONE;
  127. }
  128. priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
  129. if (priv == NULL) {
  130. PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
  131. return NOTIFY_DONE;
  132. }
  133. pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
  134. nic = netdev_priv(dev);
  135. if (nic == NULL || pstrWFIDrv == NULL) {
  136. PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
  137. return NOTIFY_DONE;
  138. }
  139. PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler +++\n"); /* tony */
  140. switch (event) {
  141. case NETDEV_UP:
  142. PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_UP %p\n", dev); /* tony */
  143. PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Obtained ===============\n\n");
  144. /*If we are in station mode or client mode*/
  145. if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) {
  146. pstrWFIDrv->IFC_UP = 1;
  147. g_obtainingIP = false;
  148. del_timer(&hDuringIpTimer);
  149. PRINT_D(GENERIC_DBG, "IP obtained , enable scan\n");
  150. }
  151. if (bEnablePS)
  152. host_int_set_power_mgmt(pstrWFIDrv, 1, 0);
  153. PRINT_D(GENERIC_DBG, "[%s] Up IP\n", dev_iface->ifa_label);
  154. pIP_Add_buff = (char *) (&(dev_iface->ifa_address));
  155. PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d\n", pIP_Add_buff[0], pIP_Add_buff[1], pIP_Add_buff[2], pIP_Add_buff[3]);
  156. host_int_setup_ipaddress(pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx);
  157. break;
  158. case NETDEV_DOWN:
  159. PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_DOWN %p\n", dev); /* tony */
  160. PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Released ===============\n\n");
  161. if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) {
  162. pstrWFIDrv->IFC_UP = 0;
  163. g_obtainingIP = false;
  164. }
  165. if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
  166. host_int_set_power_mgmt(pstrWFIDrv, 0, 0);
  167. resolve_disconnect_aberration(pstrWFIDrv);
  168. PRINT_D(GENERIC_DBG, "[%s] Down IP\n", dev_iface->ifa_label);
  169. pIP_Add_buff = null_ip;
  170. PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d\n", pIP_Add_buff[0], pIP_Add_buff[1], pIP_Add_buff[2], pIP_Add_buff[3]);
  171. host_int_setup_ipaddress(pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx);
  172. break;
  173. default:
  174. PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler event=default\n"); /* tony */
  175. PRINT_INFO(GENERIC_DBG, "[%s] unknown dev event: %lu\n", dev_iface->ifa_label, event);
  176. break;
  177. }
  178. return NOTIFY_DONE;
  179. }
  180. #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
  181. static irqreturn_t isr_uh_routine(int irq, void *user_data)
  182. {
  183. perInterface_wlan_t *nic;
  184. struct wilc *wilc;
  185. struct net_device *dev = (struct net_device *)user_data;
  186. nic = netdev_priv(dev);
  187. wilc = nic->wilc;
  188. PRINT_D(INT_DBG, "Interrupt received UH\n");
  189. /*While mac is closing cacncel the handling of any interrupts received*/
  190. if (wilc->close) {
  191. PRINT_ER("Driver is CLOSING: Can't handle UH interrupt\n");
  192. return IRQ_HANDLED;
  193. }
  194. return IRQ_WAKE_THREAD;
  195. }
  196. #endif
  197. irqreturn_t isr_bh_routine(int irq, void *userdata)
  198. {
  199. perInterface_wlan_t *nic;
  200. struct wilc *wilc;
  201. nic = netdev_priv(userdata);
  202. wilc = nic->wilc;
  203. /*While mac is closing cacncel the handling of any interrupts received*/
  204. if (wilc->close) {
  205. PRINT_ER("Driver is CLOSING: Can't handle BH interrupt\n");
  206. return IRQ_HANDLED;
  207. }
  208. PRINT_D(INT_DBG, "Interrupt received BH\n");
  209. wilc_handle_isr(wilc);
  210. return IRQ_HANDLED;
  211. }
  212. #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
  213. static int init_irq(struct net_device *dev)
  214. {
  215. int ret = 0;
  216. perInterface_wlan_t *nic;
  217. struct wilc *wl;
  218. nic = netdev_priv(dev);
  219. wl = nic->wilc;
  220. /*initialize GPIO and register IRQ num*/
  221. /*GPIO request*/
  222. if ((gpio_request(GPIO_NUM, "WILC_INTR") == 0) &&
  223. (gpio_direction_input(GPIO_NUM) == 0)) {
  224. #if defined(CUSTOMER_PLATFORM)
  225. /*
  226. TODO : save the registerd irq number to the private wilc context in kernel.
  227. *
  228. * ex) nic->dev_irq_num = gpio_to_irq(GPIO_NUM);
  229. */
  230. #else
  231. wl->dev_irq_num = gpio_to_irq(GPIO_NUM);
  232. #endif
  233. } else {
  234. ret = -1;
  235. PRINT_ER("could not obtain gpio for WILC_INTR\n");
  236. }
  237. if ((ret != -1) && (request_threaded_irq(wl->dev_irq_num, isr_uh_routine, isr_bh_routine,
  238. IRQF_TRIGGER_LOW | IRQF_ONESHOT, /*Without IRQF_ONESHOT the uh will remain kicked in and dont gave a chance to bh*/
  239. "WILC_IRQ", dev)) < 0) {
  240. PRINT_ER("Failed to request IRQ for GPIO: %d\n", GPIO_NUM);
  241. ret = -1;
  242. } else {
  243. PRINT_D(INIT_DBG, "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n",
  244. wl->dev_irq_num, GPIO_NUM);
  245. }
  246. return ret;
  247. }
  248. #endif
  249. static void deinit_irq(struct net_device *dev)
  250. {
  251. perInterface_wlan_t *nic;
  252. struct wilc *wilc;
  253. nic = netdev_priv(dev);
  254. wilc = nic->wilc;
  255. #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
  256. /* Deintialize IRQ */
  257. if (&wilc->dev_irq_num != 0) {
  258. free_irq(wilc->dev_irq_num, wilc);
  259. gpio_free(GPIO_NUM);
  260. }
  261. #endif
  262. }
  263. /*
  264. * OS functions
  265. */
  266. void linux_wlan_dbg(u8 *buff)
  267. {
  268. PRINT_D(INIT_DBG, "%d\n", *buff);
  269. }
  270. int linux_wlan_lock_timeout(void *vp, u32 timeout)
  271. {
  272. int error = -1;
  273. PRINT_D(LOCK_DBG, "Locking %p\n", vp);
  274. if (vp != NULL)
  275. error = down_timeout((struct semaphore *)vp, msecs_to_jiffies(timeout));
  276. else
  277. PRINT_ER("Failed, mutex is NULL\n");
  278. return error;
  279. }
  280. void linux_wlan_mac_indicate(struct wilc *wilc, int flag)
  281. {
  282. /*I have to do it that way becuase there is no mean to encapsulate device pointer
  283. * as a parameter
  284. */
  285. int status;
  286. if (flag == WILC_MAC_INDICATE_STATUS) {
  287. wilc_wlan_cfg_get_val(WID_STATUS, (unsigned char *)&status, 4);
  288. if (wilc->mac_status == WILC_MAC_STATUS_INIT) {
  289. wilc->mac_status = status;
  290. up(&wilc->sync_event);
  291. } else {
  292. wilc->mac_status = status;
  293. }
  294. if (wilc->mac_status == WILC_MAC_STATUS_CONNECT) { /* Connect */
  295. }
  296. } else if (flag == WILC_MAC_INDICATE_SCAN) {
  297. PRINT_D(GENERIC_DBG, "Scanning ...\n");
  298. }
  299. }
  300. struct net_device *GetIfHandler(struct wilc *wilc, u8 *pMacHeader)
  301. {
  302. u8 *Bssid, *Bssid1;
  303. int i = 0;
  304. Bssid = pMacHeader + 10;
  305. Bssid1 = pMacHeader + 4;
  306. for (i = 0; i < wilc->vif_num; i++)
  307. if (!memcmp(Bssid1, wilc->vif[i].bssid, ETH_ALEN) ||
  308. !memcmp(Bssid, wilc->vif[i].bssid, ETH_ALEN))
  309. return wilc->vif[i].ndev;
  310. PRINT_INFO(INIT_DBG, "Invalide handle\n");
  311. for (i = 0; i < 25; i++)
  312. PRINT_D(INIT_DBG, "%02x ", pMacHeader[i]);
  313. Bssid = pMacHeader + 18;
  314. Bssid1 = pMacHeader + 12;
  315. for (i = 0; i < wilc->vif_num; i++)
  316. if (!memcmp(Bssid1, wilc->vif[i].bssid, ETH_ALEN) ||
  317. !memcmp(Bssid, wilc->vif[i].bssid, ETH_ALEN))
  318. return wilc->vif[i].ndev;
  319. PRINT_INFO(INIT_DBG, "\n");
  320. return NULL;
  321. }
  322. int linux_wlan_set_bssid(struct net_device *wilc_netdev, u8 *pBSSID)
  323. {
  324. int i = 0;
  325. int ret = -1;
  326. perInterface_wlan_t *nic;
  327. struct wilc *wilc;
  328. nic = netdev_priv(wilc_netdev);
  329. wilc = nic->wilc;
  330. for (i = 0; i < wilc->vif_num; i++)
  331. if (wilc->vif[i].ndev == wilc_netdev) {
  332. memcpy(wilc->vif[i].bssid, pBSSID, 6);
  333. ret = 0;
  334. break;
  335. }
  336. return ret;
  337. }
  338. /*Function to get number of connected interfaces*/
  339. int linux_wlan_get_num_conn_ifcs(void)
  340. {
  341. u8 i = 0;
  342. u8 null_bssid[6] = {0};
  343. u8 ret_val = 0;
  344. for (i = 0; i < g_linux_wlan->vif_num; i++)
  345. if (memcmp(g_linux_wlan->vif[i].bssid, null_bssid, 6))
  346. ret_val++;
  347. return ret_val;
  348. }
  349. #define USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
  350. static int linux_wlan_txq_task(void *vp)
  351. {
  352. int ret, txq_count;
  353. perInterface_wlan_t *nic;
  354. struct wilc *wl;
  355. struct net_device *dev = vp;
  356. #if defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
  357. #define TX_BACKOFF_WEIGHT_INCR_STEP (1)
  358. #define TX_BACKOFF_WEIGHT_DECR_STEP (1)
  359. #define TX_BACKOFF_WEIGHT_MAX (7)
  360. #define TX_BACKOFF_WEIGHT_MIN (0)
  361. #define TX_BACKOFF_WEIGHT_UNIT_MS (10)
  362. int backoff_weight = TX_BACKOFF_WEIGHT_MIN;
  363. #endif
  364. nic = netdev_priv(dev);
  365. wl = nic->wilc;
  366. /* inform wilc1000_wlan_init that TXQ task is started. */
  367. up(&wl->txq_thread_started);
  368. while (1) {
  369. PRINT_D(TX_DBG, "txq_task Taking a nap :)\n");
  370. down(&wl->txq_event);
  371. /* wait_for_completion(&pd->txq_event); */
  372. PRINT_D(TX_DBG, "txq_task Who waked me up :$\n");
  373. if (wl->close) {
  374. /*Unlock the mutex in the mac_close function to indicate the exiting of the TX thread */
  375. up(&wl->txq_thread_started);
  376. while (!kthread_should_stop())
  377. schedule();
  378. PRINT_D(TX_DBG, "TX thread stopped\n");
  379. break;
  380. }
  381. PRINT_D(TX_DBG, "txq_task handle the sending packet and let me go to sleep.\n");
  382. #if !defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
  383. ret = wilc_wlan_handle_txq(dev, &txq_count);
  384. #else
  385. do {
  386. ret = wilc_wlan_handle_txq(dev, &txq_count);
  387. if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD /* && netif_queue_stopped(pd->wilc_netdev)*/) {
  388. PRINT_D(TX_DBG, "Waking up queue\n");
  389. /* netif_wake_queue(pd->wilc_netdev); */
  390. if (netif_queue_stopped(wl->vif[0].ndev))
  391. netif_wake_queue(wl->vif[0].ndev);
  392. if (netif_queue_stopped(wl->vif[1].ndev))
  393. netif_wake_queue(wl->vif[1].ndev);
  394. }
  395. if (ret == WILC_TX_ERR_NO_BUF) { /* failed to allocate buffers in chip. */
  396. do {
  397. /* Back off from sending packets for some time. */
  398. /* schedule_timeout will allow RX task to run and free buffers.*/
  399. /* set_current_state(TASK_UNINTERRUPTIBLE); */
  400. /* timeout = schedule_timeout(timeout); */
  401. msleep(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight);
  402. } while (/*timeout*/ 0);
  403. backoff_weight += TX_BACKOFF_WEIGHT_INCR_STEP;
  404. if (backoff_weight > TX_BACKOFF_WEIGHT_MAX)
  405. backoff_weight = TX_BACKOFF_WEIGHT_MAX;
  406. } else {
  407. if (backoff_weight > TX_BACKOFF_WEIGHT_MIN) {
  408. backoff_weight -= TX_BACKOFF_WEIGHT_DECR_STEP;
  409. if (backoff_weight < TX_BACKOFF_WEIGHT_MIN)
  410. backoff_weight = TX_BACKOFF_WEIGHT_MIN;
  411. }
  412. }
  413. /*TODO: drop packets after a certain time/number of retry count. */
  414. } while (ret == WILC_TX_ERR_NO_BUF && !wl->close); /* retry sending packets if no more buffers in chip. */
  415. #endif
  416. }
  417. return 0;
  418. }
  419. void linux_wlan_rx_complete(void)
  420. {
  421. PRINT_D(RX_DBG, "RX completed\n");
  422. }
  423. int linux_wlan_get_firmware(perInterface_wlan_t *p_nic)
  424. {
  425. perInterface_wlan_t *nic = p_nic;
  426. int ret = 0;
  427. const struct firmware *wilc_firmware;
  428. char *firmware;
  429. if (nic->iftype == AP_MODE)
  430. firmware = AP_FIRMWARE;
  431. else if (nic->iftype == STATION_MODE)
  432. firmware = STA_FIRMWARE;
  433. else {
  434. PRINT_D(INIT_DBG, "Get P2P_CONCURRENCY_FIRMWARE\n");
  435. firmware = P2P_CONCURRENCY_FIRMWARE;
  436. }
  437. if (nic == NULL) {
  438. PRINT_ER("NIC is NULL\n");
  439. goto _fail_;
  440. }
  441. if (&nic->wilc_netdev->dev == NULL) {
  442. PRINT_ER("&nic->wilc_netdev->dev is NULL\n");
  443. goto _fail_;
  444. }
  445. /* the firmare should be located in /lib/firmware in
  446. * root file system with the name specified above */
  447. #ifdef WILC_SDIO
  448. if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_sdio_func->dev) != 0) {
  449. PRINT_ER("%s - firmare not available\n", firmware);
  450. ret = -1;
  451. goto _fail_;
  452. }
  453. #else
  454. if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_spidev->dev) != 0) {
  455. PRINT_ER("%s - firmare not available\n", firmware);
  456. ret = -1;
  457. goto _fail_;
  458. }
  459. #endif
  460. g_linux_wlan->firmware = wilc_firmware;
  461. _fail_:
  462. return ret;
  463. }
  464. static int linux_wlan_start_firmware(perInterface_wlan_t *nic)
  465. {
  466. int ret = 0;
  467. /* start firmware */
  468. PRINT_D(INIT_DBG, "Starting Firmware ...\n");
  469. ret = wilc_wlan_start();
  470. if (ret < 0) {
  471. PRINT_ER("Failed to start Firmware\n");
  472. goto _fail_;
  473. }
  474. /* wait for mac ready */
  475. PRINT_D(INIT_DBG, "Waiting for Firmware to get ready ...\n");
  476. ret = linux_wlan_lock_timeout(&g_linux_wlan->sync_event, 5000);
  477. if (ret) {
  478. PRINT_D(INIT_DBG, "Firmware start timed out");
  479. goto _fail_;
  480. }
  481. /*
  482. * TODO: Driver shouoldn't wait forever for firmware to get started -
  483. * in case of timeout this should be handled properly
  484. */
  485. PRINT_D(INIT_DBG, "Firmware successfully started\n");
  486. _fail_:
  487. return ret;
  488. }
  489. static int linux_wlan_firmware_download(struct wilc *p_nic)
  490. {
  491. int ret = 0;
  492. if (!g_linux_wlan->firmware) {
  493. PRINT_ER("Firmware buffer is NULL\n");
  494. ret = -ENOBUFS;
  495. goto _FAIL_;
  496. }
  497. /**
  498. * do the firmware download
  499. **/
  500. PRINT_D(INIT_DBG, "Downloading Firmware ...\n");
  501. ret = wilc_wlan_firmware_download(g_linux_wlan->firmware->data,
  502. g_linux_wlan->firmware->size);
  503. if (ret < 0)
  504. goto _FAIL_;
  505. /* Freeing FW buffer */
  506. PRINT_D(INIT_DBG, "Freeing FW buffer ...\n");
  507. PRINT_D(INIT_DBG, "Releasing firmware\n");
  508. release_firmware(g_linux_wlan->firmware);
  509. PRINT_D(INIT_DBG, "Download Succeeded\n");
  510. _FAIL_:
  511. return ret;
  512. }
  513. /* startup configuration - could be changed later using iconfig*/
  514. static int linux_wlan_init_test_config(struct net_device *dev, struct wilc *p_nic)
  515. {
  516. unsigned char c_val[64];
  517. unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff};
  518. struct wilc_priv *priv;
  519. struct host_if_drv *pstrWFIDrv;
  520. PRINT_D(TX_DBG, "Start configuring Firmware\n");
  521. get_random_bytes(&mac_add[5], 1);
  522. get_random_bytes(&mac_add[4], 1);
  523. priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
  524. pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
  525. PRINT_D(INIT_DBG, "Host = %p\n", pstrWFIDrv);
  526. PRINT_D(INIT_DBG, "MAC address is : %02x-%02x-%02x-%02x-%02x-%02x\n", mac_add[0], mac_add[1], mac_add[2], mac_add[3], mac_add[4], mac_add[5]);
  527. wilc_get_chipid(0);
  528. *(int *)c_val = 1;
  529. if (!wilc_wlan_cfg_set(1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0))
  530. goto _fail_;
  531. /*to tell fw that we are going to use PC test - WILC specific*/
  532. c_val[0] = 0;
  533. if (!wilc_wlan_cfg_set(0, WID_PC_TEST_MODE, c_val, 1, 0, 0))
  534. goto _fail_;
  535. c_val[0] = INFRASTRUCTURE;
  536. if (!wilc_wlan_cfg_set(0, WID_BSS_TYPE, c_val, 1, 0, 0))
  537. goto _fail_;
  538. /* c_val[0] = RATE_AUTO; */
  539. c_val[0] = RATE_AUTO;
  540. if (!wilc_wlan_cfg_set(0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0))
  541. goto _fail_;
  542. c_val[0] = G_MIXED_11B_2_MODE;
  543. if (!wilc_wlan_cfg_set(0, WID_11G_OPERATING_MODE, c_val, 1, 0, 0))
  544. goto _fail_;
  545. c_val[0] = 1;
  546. if (!wilc_wlan_cfg_set(0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0))
  547. goto _fail_;
  548. c_val[0] = G_SHORT_PREAMBLE;
  549. if (!wilc_wlan_cfg_set(0, WID_PREAMBLE, c_val, 1, 0, 0))
  550. goto _fail_;
  551. c_val[0] = AUTO_PROT;
  552. if (!wilc_wlan_cfg_set(0, WID_11N_PROT_MECH, c_val, 1, 0, 0))
  553. goto _fail_;
  554. c_val[0] = ACTIVE_SCAN;
  555. if (!wilc_wlan_cfg_set(0, WID_SCAN_TYPE, c_val, 1, 0, 0))
  556. goto _fail_;
  557. c_val[0] = SITE_SURVEY_OFF;
  558. if (!wilc_wlan_cfg_set(0, WID_SITE_SURVEY, c_val, 1, 0, 0))
  559. goto _fail_;
  560. *((int *)c_val) = 0xffff; /* Never use RTS-CTS */
  561. if (!wilc_wlan_cfg_set(0, WID_RTS_THRESHOLD, c_val, 2, 0, 0))
  562. goto _fail_;
  563. *((int *)c_val) = 2346;
  564. if (!wilc_wlan_cfg_set(0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0))
  565. goto _fail_;
  566. /* SSID */
  567. /* -------------------------------------------------------------- */
  568. /* Configuration : String with length less than 32 bytes */
  569. /* Values to set : Any string with length less than 32 bytes */
  570. /* ( In BSS Station Set SSID to "" (null string) */
  571. /* to enable Broadcast SSID suppport ) */
  572. /* -------------------------------------------------------------- */
  573. c_val[0] = 0;
  574. if (!wilc_wlan_cfg_set(0, WID_BCAST_SSID, c_val, 1, 0, 0))
  575. goto _fail_;
  576. c_val[0] = 1;
  577. if (!wilc_wlan_cfg_set(0, WID_QOS_ENABLE, c_val, 1, 0, 0))
  578. goto _fail_;
  579. c_val[0] = NO_POWERSAVE;
  580. if (!wilc_wlan_cfg_set(0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0))
  581. goto _fail_;
  582. c_val[0] = NO_ENCRYPT; /* NO_ENCRYPT, 0x79 */
  583. if (!wilc_wlan_cfg_set(0, WID_11I_MODE, c_val, 1, 0, 0))
  584. goto _fail_;
  585. c_val[0] = OPEN_SYSTEM;
  586. if (!wilc_wlan_cfg_set(0, WID_AUTH_TYPE, c_val, 1, 0, 0))
  587. goto _fail_;
  588. /* WEP/802 11I Configuration */
  589. /* ------------------------------------------------------------------ */
  590. /* Configuration : WEP Key */
  591. /* Values (0x) : 5 byte for WEP40 and 13 bytes for WEP104 */
  592. /* In case more than 5 bytes are passed on for WEP 40 */
  593. /* only first 5 bytes will be used as the key */
  594. /* ------------------------------------------------------------------ */
  595. strcpy(c_val, "123456790abcdef1234567890");
  596. if (!wilc_wlan_cfg_set(0, WID_WEP_KEY_VALUE, c_val, (strlen(c_val) + 1), 0, 0))
  597. goto _fail_;
  598. /* WEP/802 11I Configuration */
  599. /* ------------------------------------------------------------------ */
  600. /* Configuration : AES/TKIP WPA/RSNA Pre-Shared Key */
  601. /* Values to set : Any string with length greater than equal to 8 bytes */
  602. /* and less than 64 bytes */
  603. /* ------------------------------------------------------------------ */
  604. strcpy(c_val, "12345678");
  605. if (!wilc_wlan_cfg_set(0, WID_11I_PSK, c_val, (strlen(c_val)), 0, 0))
  606. goto _fail_;
  607. /* IEEE802.1X Key Configuration */
  608. /* ------------------------------------------------------------------ */
  609. /* Configuration : Radius Server Access Secret Key */
  610. /* Values to set : Any string with length greater than equal to 8 bytes */
  611. /* and less than 65 bytes */
  612. /* ------------------------------------------------------------------ */
  613. strcpy(c_val, "password");
  614. if (!wilc_wlan_cfg_set(0, WID_1X_KEY, c_val, (strlen(c_val) + 1), 0, 0))
  615. goto _fail_;
  616. /* IEEE802.1X Server Address Configuration */
  617. /* ------------------------------------------------------------------ */
  618. /* Configuration : Radius Server IP Address */
  619. /* Values to set : Any valid IP Address */
  620. /* ------------------------------------------------------------------ */
  621. c_val[0] = 192;
  622. c_val[1] = 168;
  623. c_val[2] = 1;
  624. c_val[3] = 112;
  625. if (!wilc_wlan_cfg_set(0, WID_1X_SERV_ADDR, c_val, 4, 0, 0))
  626. goto _fail_;
  627. c_val[0] = 3;
  628. if (!wilc_wlan_cfg_set(0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0))
  629. goto _fail_;
  630. c_val[0] = 3;
  631. if (!wilc_wlan_cfg_set(0, WID_DTIM_PERIOD, c_val, 1, 0, 0))
  632. goto _fail_;
  633. c_val[0] = NORMAL_ACK;
  634. if (!wilc_wlan_cfg_set(0, WID_ACK_POLICY, c_val, 1, 0, 0))
  635. goto _fail_;
  636. c_val[0] = 0;
  637. if (!wilc_wlan_cfg_set(0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1, 0, 0))
  638. goto _fail_;
  639. c_val[0] = 48;
  640. if (!wilc_wlan_cfg_set(0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0, 0))
  641. goto _fail_;
  642. c_val[0] = 28;
  643. if (!wilc_wlan_cfg_set(0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0, 0))
  644. goto _fail_;
  645. /* Beacon Interval */
  646. /* -------------------------------------------------------------------- */
  647. /* Configuration : Sets the beacon interval value */
  648. /* Values to set : Any 16-bit value */
  649. /* -------------------------------------------------------------------- */
  650. *((int *)c_val) = 100;
  651. if (!wilc_wlan_cfg_set(0, WID_BEACON_INTERVAL, c_val, 2, 0, 0))
  652. goto _fail_;
  653. c_val[0] = REKEY_DISABLE;
  654. if (!wilc_wlan_cfg_set(0, WID_REKEY_POLICY, c_val, 1, 0, 0))
  655. goto _fail_;
  656. /* Rekey Time (s) (Used only when the Rekey policy is 2 or 4) */
  657. /* -------------------------------------------------------------------- */
  658. /* Configuration : Sets the Rekey Time (s) */
  659. /* Values to set : 32-bit value */
  660. /* -------------------------------------------------------------------- */
  661. *((int *)c_val) = 84600;
  662. if (!wilc_wlan_cfg_set(0, WID_REKEY_PERIOD, c_val, 4, 0, 0))
  663. goto _fail_;
  664. /* Rekey Packet Count (in 1000s; used when Rekey Policy is 3) */
  665. /* -------------------------------------------------------------------- */
  666. /* Configuration : Sets Rekey Group Packet count */
  667. /* Values to set : 32-bit Value */
  668. /* -------------------------------------------------------------------- */
  669. *((int *)c_val) = 500;
  670. if (!wilc_wlan_cfg_set(0, WID_REKEY_PACKET_COUNT, c_val, 4, 0, 0))
  671. goto _fail_;
  672. c_val[0] = 1;
  673. if (!wilc_wlan_cfg_set(0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0, 0))
  674. goto _fail_;
  675. c_val[0] = G_SELF_CTS_PROT;
  676. if (!wilc_wlan_cfg_set(0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0))
  677. goto _fail_;
  678. c_val[0] = 1; /* Enable N */
  679. if (!wilc_wlan_cfg_set(0, WID_11N_ENABLE, c_val, 1, 0, 0))
  680. goto _fail_;
  681. c_val[0] = HT_MIXED_MODE;
  682. if (!wilc_wlan_cfg_set(0, WID_11N_OPERATING_MODE, c_val, 1, 0, 0))
  683. goto _fail_;
  684. c_val[0] = 1; /* TXOP Prot disable in N mode: No RTS-CTS on TX A-MPDUs to save air-time. */
  685. if (!wilc_wlan_cfg_set(0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0, 0))
  686. goto _fail_;
  687. memcpy(c_val, mac_add, 6);
  688. if (!wilc_wlan_cfg_set(0, WID_MAC_ADDR, c_val, 6, 0, 0))
  689. goto _fail_;
  690. /**
  691. * AP only
  692. **/
  693. c_val[0] = DETECT_PROTECT_REPORT;
  694. if (!wilc_wlan_cfg_set(0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1, 0, 0))
  695. goto _fail_;
  696. c_val[0] = RTS_CTS_NONHT_PROT;
  697. if (!wilc_wlan_cfg_set(0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0))
  698. goto _fail_;
  699. c_val[0] = 0;
  700. if (!wilc_wlan_cfg_set(0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0, 0))
  701. goto _fail_;
  702. c_val[0] = MIMO_MODE;
  703. if (!wilc_wlan_cfg_set(0, WID_11N_SMPS_MODE, c_val, 1, 0, 0))
  704. goto _fail_;
  705. c_val[0] = 7;
  706. if (!wilc_wlan_cfg_set(0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0, 0))
  707. goto _fail_;
  708. c_val[0] = 1; /* Enable N with immediate block ack. */
  709. if (!wilc_wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, 1, 1))
  710. goto _fail_;
  711. return 0;
  712. _fail_:
  713. return -1;
  714. }
  715. /**************************/
  716. void wilc1000_wlan_deinit(struct net_device *dev)
  717. {
  718. perInterface_wlan_t *nic;
  719. struct wilc *wl;
  720. nic = netdev_priv(dev);
  721. wl = nic->wilc;
  722. if (!wl) {
  723. netdev_err(dev, "wl is NULL\n");
  724. return;
  725. }
  726. if (wl->initialized) {
  727. netdev_info(dev, "Deinitializing wilc1000...\n");
  728. #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
  729. /* johnny : remove */
  730. PRINT_D(INIT_DBG, "skip wilc_bus_set_default_speed\n");
  731. #else
  732. wilc_bus_set_default_speed();
  733. #endif
  734. PRINT_D(INIT_DBG, "Disabling IRQ\n");
  735. #ifdef WILC_SDIO
  736. mutex_lock(&wl->hif_cs);
  737. disable_sdio_interrupt();
  738. mutex_unlock(&wl->hif_cs);
  739. #endif
  740. if (&wl->txq_event != NULL)
  741. up(&wl->txq_event);
  742. PRINT_D(INIT_DBG, "Deinitializing Threads\n");
  743. wlan_deinitialize_threads(dev);
  744. PRINT_D(INIT_DBG, "Deinitializing IRQ\n");
  745. deinit_irq(dev);
  746. wilc_wlan_stop();
  747. PRINT_D(INIT_DBG, "Deinitializing WILC Wlan\n");
  748. wilc_wlan_cleanup(dev);
  749. #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
  750. #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
  751. PRINT_D(INIT_DBG, "Disabling IRQ 2\n");
  752. mutex_lock(&wl->hif_cs);
  753. disable_sdio_interrupt();
  754. mutex_unlock(&wl->hif_cs);
  755. #endif
  756. #endif
  757. /*De-Initialize locks*/
  758. PRINT_D(INIT_DBG, "Deinitializing Locks\n");
  759. wlan_deinit_locks(dev);
  760. /* announce that wilc1000 is not initialized */
  761. wl->initialized = false;
  762. PRINT_D(INIT_DBG, "wilc1000 deinitialization Done\n");
  763. } else {
  764. PRINT_D(INIT_DBG, "wilc1000 is not initialized\n");
  765. }
  766. }
  767. int wlan_init_locks(struct net_device *dev)
  768. {
  769. perInterface_wlan_t *nic;
  770. struct wilc *wl;
  771. nic = netdev_priv(dev);
  772. wl = nic->wilc;
  773. PRINT_D(INIT_DBG, "Initializing Locks ...\n");
  774. mutex_init(&wl->hif_cs);
  775. mutex_init(&wl->rxq_cs);
  776. spin_lock_init(&wl->txq_spinlock);
  777. sema_init(&wl->txq_add_to_head_cs, 1);
  778. sema_init(&wl->txq_event, 0);
  779. sema_init(&wl->cfg_event, 0);
  780. sema_init(&wl->sync_event, 0);
  781. sema_init(&wl->txq_thread_started, 0);
  782. return 0;
  783. }
  784. static int wlan_deinit_locks(struct net_device *dev)
  785. {
  786. perInterface_wlan_t *nic;
  787. struct wilc *wilc;
  788. nic = netdev_priv(dev);
  789. wilc = nic->wilc;
  790. PRINT_D(INIT_DBG, "De-Initializing Locks\n");
  791. if (&wilc->hif_cs != NULL)
  792. mutex_destroy(&wilc->hif_cs);
  793. if (&wilc->rxq_cs != NULL)
  794. mutex_destroy(&wilc->rxq_cs);
  795. return 0;
  796. }
  797. void linux_to_wlan(wilc_wlan_inp_t *nwi, struct wilc *nic)
  798. {
  799. PRINT_D(INIT_DBG, "Linux to Wlan services ...\n");
  800. nwi->os_context.os_private = (void *)nic;
  801. #ifdef WILC_SDIO
  802. nwi->io_func.io_type = HIF_SDIO;
  803. nwi->io_func.io_init = linux_sdio_init;
  804. nwi->io_func.io_deinit = linux_sdio_deinit;
  805. nwi->io_func.u.sdio.sdio_cmd52 = linux_sdio_cmd52;
  806. nwi->io_func.u.sdio.sdio_cmd53 = linux_sdio_cmd53;
  807. nwi->io_func.u.sdio.sdio_set_max_speed = linux_sdio_set_max_speed;
  808. nwi->io_func.u.sdio.sdio_set_default_speed = linux_sdio_set_default_speed;
  809. #else
  810. nwi->io_func.io_type = HIF_SPI;
  811. nwi->io_func.io_init = linux_spi_init;
  812. nwi->io_func.io_deinit = linux_spi_deinit;
  813. nwi->io_func.u.spi.spi_tx = linux_spi_write;
  814. nwi->io_func.u.spi.spi_rx = linux_spi_read;
  815. nwi->io_func.u.spi.spi_trx = linux_spi_write_read;
  816. nwi->io_func.u.spi.spi_max_speed = linux_spi_set_max_speed;
  817. #endif
  818. }
  819. int wlan_initialize_threads(struct net_device *dev)
  820. {
  821. perInterface_wlan_t *nic;
  822. struct wilc *wilc;
  823. int ret = 0;
  824. nic = netdev_priv(dev);
  825. wilc = nic->wilc;
  826. PRINT_D(INIT_DBG, "Initializing Threads ...\n");
  827. /* create tx task */
  828. PRINT_D(INIT_DBG, "Creating kthread for transmission\n");
  829. wilc->txq_thread = kthread_run(linux_wlan_txq_task, (void *)dev,
  830. "K_TXQ_TASK");
  831. if (!wilc->txq_thread) {
  832. PRINT_ER("couldn't create TXQ thread\n");
  833. ret = -ENOBUFS;
  834. goto _fail_2;
  835. }
  836. /* wait for TXQ task to start. */
  837. down(&wilc->txq_thread_started);
  838. return 0;
  839. _fail_2:
  840. /*De-Initialize 2nd thread*/
  841. wilc->close = 0;
  842. return ret;
  843. }
  844. static void wlan_deinitialize_threads(struct net_device *dev)
  845. {
  846. perInterface_wlan_t *nic;
  847. struct wilc *wl;
  848. nic = netdev_priv(dev);
  849. wl = nic->wilc;
  850. wl->close = 1;
  851. PRINT_D(INIT_DBG, "Deinitializing Threads\n");
  852. if (&wl->txq_event != NULL)
  853. up(&wl->txq_event);
  854. if (wl->txq_thread != NULL) {
  855. kthread_stop(wl->txq_thread);
  856. wl->txq_thread = NULL;
  857. }
  858. }
  859. int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
  860. {
  861. wilc_wlan_inp_t nwi;
  862. perInterface_wlan_t *nic = p_nic;
  863. int ret = 0;
  864. struct wilc *wl = nic->wilc;
  865. if (!wl->initialized) {
  866. wl->mac_status = WILC_MAC_STATUS_INIT;
  867. wl->close = 0;
  868. wlan_init_locks(dev);
  869. linux_to_wlan(&nwi, wl);
  870. ret = wilc_wlan_init(&nwi);
  871. if (ret < 0) {
  872. PRINT_ER("Initializing WILC_Wlan FAILED\n");
  873. ret = -EIO;
  874. goto _fail_locks_;
  875. }
  876. #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
  877. if (init_irq(dev)) {
  878. PRINT_ER("couldn't initialize IRQ\n");
  879. ret = -EIO;
  880. goto _fail_locks_;
  881. }
  882. #endif
  883. ret = wlan_initialize_threads(dev);
  884. if (ret < 0) {
  885. PRINT_ER("Initializing Threads FAILED\n");
  886. ret = -EIO;
  887. goto _fail_wilc_wlan_;
  888. }
  889. #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
  890. if (enable_sdio_interrupt()) {
  891. PRINT_ER("couldn't initialize IRQ\n");
  892. ret = -EIO;
  893. goto _fail_irq_init_;
  894. }
  895. #endif
  896. if (linux_wlan_get_firmware(nic)) {
  897. PRINT_ER("Can't get firmware\n");
  898. ret = -EIO;
  899. goto _fail_irq_enable_;
  900. }
  901. /*Download firmware*/
  902. ret = linux_wlan_firmware_download(wl);
  903. if (ret < 0) {
  904. PRINT_ER("Failed to download firmware\n");
  905. ret = -EIO;
  906. goto _fail_irq_enable_;
  907. }
  908. /* Start firmware*/
  909. ret = linux_wlan_start_firmware(nic);
  910. if (ret < 0) {
  911. PRINT_ER("Failed to start firmware\n");
  912. ret = -EIO;
  913. goto _fail_irq_enable_;
  914. }
  915. wilc_bus_set_max_speed();
  916. if (wilc_wlan_cfg_get(1, WID_FIRMWARE_VERSION, 1, 0)) {
  917. int size;
  918. char Firmware_ver[20];
  919. size = wilc_wlan_cfg_get_val(
  920. WID_FIRMWARE_VERSION,
  921. Firmware_ver, sizeof(Firmware_ver));
  922. Firmware_ver[size] = '\0';
  923. PRINT_D(INIT_DBG, "***** Firmware Ver = %s *******\n", Firmware_ver);
  924. }
  925. /* Initialize firmware with default configuration */
  926. ret = linux_wlan_init_test_config(dev, wl);
  927. if (ret < 0) {
  928. PRINT_ER("Failed to configure firmware\n");
  929. ret = -EIO;
  930. goto _fail_fw_start_;
  931. }
  932. wl->initialized = true;
  933. return 0; /*success*/
  934. _fail_fw_start_:
  935. wilc_wlan_stop();
  936. _fail_irq_enable_:
  937. #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
  938. disable_sdio_interrupt();
  939. _fail_irq_init_:
  940. #endif
  941. #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
  942. deinit_irq(dev);
  943. #endif
  944. wlan_deinitialize_threads(dev);
  945. _fail_wilc_wlan_:
  946. wilc_wlan_cleanup(dev);
  947. _fail_locks_:
  948. wlan_deinit_locks(dev);
  949. PRINT_ER("WLAN Iinitialization FAILED\n");
  950. } else {
  951. PRINT_D(INIT_DBG, "wilc1000 already initialized\n");
  952. }
  953. return ret;
  954. }
  955. /*
  956. * - this function will be called automatically by OS when module inserted.
  957. */
  958. int mac_init_fn(struct net_device *ndev)
  959. {
  960. /*Why we do this !!!*/
  961. netif_start_queue(ndev); /* ma */
  962. netif_stop_queue(ndev); /* ma */
  963. return 0;
  964. }
  965. /* This fn is called, when this device is setup using ifconfig */
  966. int mac_open(struct net_device *ndev)
  967. {
  968. perInterface_wlan_t *nic;
  969. /*No need for setting mac address here anymore,*/
  970. /*Just set it in init_test_config()*/
  971. unsigned char mac_add[ETH_ALEN] = {0};
  972. int ret = 0;
  973. int i = 0;
  974. struct wilc_priv *priv;
  975. struct wilc *wl;
  976. nic = netdev_priv(ndev);
  977. wl = nic->wilc;
  978. #ifdef WILC_SPI
  979. if (!wl|| !wl->wilc_spidev) {
  980. netdev_err(ndev, "wilc1000: SPI device not ready\n");
  981. return -ENODEV;
  982. }
  983. #endif
  984. nic = netdev_priv(ndev);
  985. priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
  986. PRINT_D(INIT_DBG, "MAC OPEN[%p]\n", ndev);
  987. ret = wilc_init_host_int(ndev);
  988. if (ret < 0) {
  989. PRINT_ER("Failed to initialize host interface\n");
  990. return ret;
  991. }
  992. /*initialize platform*/
  993. PRINT_D(INIT_DBG, "*** re-init ***\n");
  994. ret = wilc1000_wlan_init(ndev, nic);
  995. if (ret < 0) {
  996. PRINT_ER("Failed to initialize wilc1000\n");
  997. wilc_deinit_host_int(ndev);
  998. return ret;
  999. }
  1000. Set_machw_change_vir_if(ndev, false);
  1001. host_int_get_MacAddress(priv->hWILCWFIDrv, mac_add);
  1002. PRINT_D(INIT_DBG, "Mac address: %pM\n", mac_add);
  1003. /* loop through the NUM of supported devices and set the MAC address */
  1004. for (i = 0; i < wl->vif_num; i++) {
  1005. if (ndev == wl->vif[i].ndev) {
  1006. memcpy(wl->vif[i].src_addr, mac_add, ETH_ALEN);
  1007. wl->vif[i].hif_drv = priv->hWILCWFIDrv;
  1008. break;
  1009. }
  1010. }
  1011. /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
  1012. memcpy(ndev->dev_addr, wl->vif[i].src_addr, ETH_ALEN);
  1013. if (!is_valid_ether_addr(ndev->dev_addr)) {
  1014. PRINT_ER("Error: Wrong MAC address\n");
  1015. ret = -EINVAL;
  1016. goto _err_;
  1017. }
  1018. wilc_mgmt_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev->ieee80211_ptr,
  1019. nic->g_struct_frame_reg[0].frame_type, nic->g_struct_frame_reg[0].reg);
  1020. wilc_mgmt_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev->ieee80211_ptr,
  1021. nic->g_struct_frame_reg[1].frame_type, nic->g_struct_frame_reg[1].reg);
  1022. netif_wake_queue(ndev);
  1023. wl->open_ifcs++;
  1024. nic->mac_opened = 1;
  1025. return 0;
  1026. _err_:
  1027. wilc_deinit_host_int(ndev);
  1028. wilc1000_wlan_deinit(ndev);
  1029. return ret;
  1030. }
  1031. struct net_device_stats *mac_stats(struct net_device *dev)
  1032. {
  1033. perInterface_wlan_t *nic = netdev_priv(dev);
  1034. return &nic->netstats;
  1035. }
  1036. /* Setup the multicast filter */
  1037. static void wilc_set_multicast_list(struct net_device *dev)
  1038. {
  1039. struct netdev_hw_addr *ha;
  1040. struct wilc_priv *priv;
  1041. struct host_if_drv *pstrWFIDrv;
  1042. int i = 0;
  1043. priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
  1044. pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
  1045. if (!dev)
  1046. return;
  1047. PRINT_D(INIT_DBG, "Setting Multicast List with count = %d.\n", dev->mc.count);
  1048. if (dev->flags & IFF_PROMISC) {
  1049. /* Normally, we should configure the chip to retrive all packets
  1050. * but we don't wanna support this right now */
  1051. /* TODO: add promiscuous mode support */
  1052. PRINT_D(INIT_DBG, "Set promiscuous mode ON, retrive all packets\n");
  1053. return;
  1054. }
  1055. /* If there's more addresses than we handle, get all multicast
  1056. * packets and sort them out in software. */
  1057. if ((dev->flags & IFF_ALLMULTI) || (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) {
  1058. PRINT_D(INIT_DBG, "Disable multicast filter, retrive all multicast packets\n");
  1059. /* get all multicast packets */
  1060. host_int_setup_multicast_filter(pstrWFIDrv, false, 0);
  1061. return;
  1062. }
  1063. /* No multicast? Just get our own stuff */
  1064. if ((dev->mc.count) == 0) {
  1065. PRINT_D(INIT_DBG, "Enable multicast filter, retrive directed packets only.\n");
  1066. host_int_setup_multicast_filter(pstrWFIDrv, true, 0);
  1067. return;
  1068. }
  1069. /* Store all of the multicast addresses in the hardware filter */
  1070. netdev_for_each_mc_addr(ha, dev)
  1071. {
  1072. memcpy(gau8MulticastMacAddrList[i], ha->addr, ETH_ALEN);
  1073. PRINT_D(INIT_DBG, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i,
  1074. gau8MulticastMacAddrList[i][0], gau8MulticastMacAddrList[i][1], gau8MulticastMacAddrList[i][2], gau8MulticastMacAddrList[i][3], gau8MulticastMacAddrList[i][4], gau8MulticastMacAddrList[i][5]);
  1075. i++;
  1076. }
  1077. host_int_setup_multicast_filter(pstrWFIDrv, true, (dev->mc.count));
  1078. return;
  1079. }
  1080. static void linux_wlan_tx_complete(void *priv, int status)
  1081. {
  1082. struct tx_complete_data *pv_data = (struct tx_complete_data *)priv;
  1083. if (status == 1)
  1084. PRINT_D(TX_DBG, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
  1085. else
  1086. PRINT_D(TX_DBG, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
  1087. /* Free the SK Buffer, its work is done */
  1088. dev_kfree_skb(pv_data->skb);
  1089. kfree(pv_data);
  1090. }
  1091. int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
  1092. {
  1093. perInterface_wlan_t *nic;
  1094. struct tx_complete_data *tx_data = NULL;
  1095. int QueueCount;
  1096. char *pu8UdpBuffer;
  1097. struct iphdr *ih;
  1098. struct ethhdr *eth_h;
  1099. struct wilc *wilc;
  1100. nic = netdev_priv(ndev);
  1101. wilc = nic->wilc;
  1102. PRINT_D(TX_DBG, "Sending packet just received from TCP/IP\n");
  1103. /* Stop the network interface queue */
  1104. if (skb->dev != ndev) {
  1105. PRINT_ER("Packet not destined to this device\n");
  1106. return 0;
  1107. }
  1108. tx_data = kmalloc(sizeof(struct tx_complete_data), GFP_ATOMIC);
  1109. if (tx_data == NULL) {
  1110. PRINT_ER("Failed to allocate memory for tx_data structure\n");
  1111. dev_kfree_skb(skb);
  1112. netif_wake_queue(ndev);
  1113. return 0;
  1114. }
  1115. tx_data->buff = skb->data;
  1116. tx_data->size = skb->len;
  1117. tx_data->skb = skb;
  1118. eth_h = (struct ethhdr *)(skb->data);
  1119. if (eth_h->h_proto == 0x8e88)
  1120. PRINT_D(INIT_DBG, "EAPOL transmitted\n");
  1121. /*get source and dest ip addresses*/
  1122. ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
  1123. pu8UdpBuffer = (char *)ih + sizeof(struct iphdr);
  1124. if ((pu8UdpBuffer[1] == 68 && pu8UdpBuffer[3] == 67) || (pu8UdpBuffer[1] == 67 && pu8UdpBuffer[3] == 68))
  1125. PRINT_D(GENERIC_DBG, "DHCP Message transmitted, type:%x %x %x\n", pu8UdpBuffer[248], pu8UdpBuffer[249], pu8UdpBuffer[250]);
  1126. PRINT_D(TX_DBG, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data->size, tx_data->buff, tx_data->skb);
  1127. /* Send packet to MAC HW - for now the tx_complete function will be just status
  1128. * indicator. still not sure if I need to suspend host transmission till the tx_complete
  1129. * function called or not?
  1130. * allocated buffer will be freed in tx_complete function.
  1131. */
  1132. PRINT_D(TX_DBG, "Adding tx packet to TX Queue\n");
  1133. nic->netstats.tx_packets++;
  1134. nic->netstats.tx_bytes += tx_data->size;
  1135. tx_data->pBssid = wilc->vif[nic->u8IfIdx].bssid;
  1136. QueueCount = wilc_wlan_txq_add_net_pkt(ndev, (void *)tx_data,
  1137. tx_data->buff, tx_data->size,
  1138. linux_wlan_tx_complete);
  1139. if (QueueCount > FLOW_CONTROL_UPPER_THRESHOLD) {
  1140. netif_stop_queue(wilc->vif[0].ndev);
  1141. netif_stop_queue(wilc->vif[1].ndev);
  1142. }
  1143. return 0;
  1144. }
  1145. int mac_close(struct net_device *ndev)
  1146. {
  1147. struct wilc_priv *priv;
  1148. perInterface_wlan_t *nic;
  1149. struct host_if_drv *pstrWFIDrv;
  1150. struct wilc *wl;
  1151. nic = netdev_priv(ndev);
  1152. if ((nic == NULL) || (nic->wilc_netdev == NULL) || (nic->wilc_netdev->ieee80211_ptr == NULL) || (nic->wilc_netdev->ieee80211_ptr->wiphy == NULL)) {
  1153. PRINT_ER("nic = NULL\n");
  1154. return 0;
  1155. }
  1156. priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
  1157. wl = nic->wilc;
  1158. if (priv == NULL) {
  1159. PRINT_ER("priv = NULL\n");
  1160. return 0;
  1161. }
  1162. pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
  1163. PRINT_D(GENERIC_DBG, "Mac close\n");
  1164. if (!wl) {
  1165. PRINT_ER("wl = NULL\n");
  1166. return 0;
  1167. }
  1168. if (pstrWFIDrv == NULL) {
  1169. PRINT_ER("pstrWFIDrv = NULL\n");
  1170. return 0;
  1171. }
  1172. if ((wl->open_ifcs) > 0) {
  1173. wl->open_ifcs--;
  1174. } else {
  1175. PRINT_ER("ERROR: MAC close called while number of opened interfaces is zero\n");
  1176. return 0;
  1177. }
  1178. if (nic->wilc_netdev != NULL) {
  1179. /* Stop the network interface queue */
  1180. netif_stop_queue(nic->wilc_netdev);
  1181. wilc_deinit_host_int(nic->wilc_netdev);
  1182. }
  1183. if (wl->open_ifcs == 0) {
  1184. PRINT_D(GENERIC_DBG, "Deinitializing wilc1000\n");
  1185. wl->close = 1;
  1186. wilc1000_wlan_deinit(ndev);
  1187. WILC_WFI_deinit_mon_interface();
  1188. }
  1189. up(&close_exit_sync);
  1190. nic->mac_opened = 0;
  1191. return 0;
  1192. }
  1193. int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
  1194. {
  1195. u8 *buff = NULL;
  1196. s8 rssi;
  1197. u32 size = 0, length = 0;
  1198. perInterface_wlan_t *nic;
  1199. struct wilc_priv *priv;
  1200. s32 s32Error = 0;
  1201. struct wilc *wilc;
  1202. /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */
  1203. nic = netdev_priv(ndev);
  1204. wilc = nic->wilc;
  1205. if (!wilc->initialized)
  1206. return 0;
  1207. switch (cmd) {
  1208. /* ]] 2013-06-24 */
  1209. case SIOCSIWPRIV:
  1210. {
  1211. struct iwreq *wrq = (struct iwreq *) req; /* added by tony */
  1212. size = wrq->u.data.length;
  1213. if (size && wrq->u.data.pointer) {
  1214. buff = memdup_user(wrq->u.data.pointer, wrq->u.data.length);
  1215. if (IS_ERR(buff))
  1216. return PTR_ERR(buff);
  1217. if (strncasecmp(buff, "RSSI", length) == 0) {
  1218. priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
  1219. s32Error = host_int_get_rssi(priv->hWILCWFIDrv, &(rssi));
  1220. if (s32Error)
  1221. PRINT_ER("Failed to send get rssi param's message queue ");
  1222. PRINT_INFO(GENERIC_DBG, "RSSI :%d\n", rssi);
  1223. /*Rounding up the rssi negative value*/
  1224. rssi += 5;
  1225. snprintf(buff, size, "rssi %d", rssi);
  1226. if (copy_to_user(wrq->u.data.pointer, buff, size)) {
  1227. PRINT_ER("%s: failed to copy data to user buffer\n", __func__);
  1228. s32Error = -EFAULT;
  1229. goto done;
  1230. }
  1231. }
  1232. }
  1233. }
  1234. break;
  1235. default:
  1236. {
  1237. PRINT_INFO(GENERIC_DBG, "Command - %d - has been received\n", cmd);
  1238. s32Error = -EOPNOTSUPP;
  1239. goto done;
  1240. }
  1241. }
  1242. done:
  1243. kfree(buff);
  1244. return s32Error;
  1245. }
  1246. void frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset)
  1247. {
  1248. unsigned int frame_len = 0;
  1249. int stats;
  1250. unsigned char *buff_to_send = NULL;
  1251. struct sk_buff *skb;
  1252. struct net_device *wilc_netdev;
  1253. perInterface_wlan_t *nic;
  1254. wilc_netdev = GetIfHandler(wilc, buff);
  1255. if (wilc_netdev == NULL)
  1256. return;
  1257. buff += pkt_offset;
  1258. nic = netdev_priv(wilc_netdev);
  1259. if (size > 0) {
  1260. frame_len = size;
  1261. buff_to_send = buff;
  1262. /* Need to send the packet up to the host, allocate a skb buffer */
  1263. skb = dev_alloc_skb(frame_len);
  1264. if (skb == NULL) {
  1265. PRINT_ER("Low memory - packet droped\n");
  1266. return;
  1267. }
  1268. if (wilc == NULL || wilc_netdev == NULL)
  1269. PRINT_ER("wilc_netdev in wilc is NULL");
  1270. skb->dev = wilc_netdev;
  1271. if (skb->dev == NULL)
  1272. PRINT_ER("skb->dev is NULL\n");
  1273. /*
  1274. * for(i=0;i<40;i++)
  1275. * {
  1276. * if(i<frame_len)
  1277. * WILC_PRINTF("buff_to_send[%d]=%2x\n",i,buff_to_send[i]);
  1278. *
  1279. * }*/
  1280. /* skb_put(skb, frame_len); */
  1281. memcpy(skb_put(skb, frame_len), buff_to_send, frame_len);
  1282. /* WILC_PRINTF("After MEM_CPY\n"); */
  1283. /* nic = netdev_priv(wilc_netdev); */
  1284. skb->protocol = eth_type_trans(skb, wilc_netdev);
  1285. /* Send the packet to the stack by giving it to the bridge */
  1286. nic->netstats.rx_packets++;
  1287. nic->netstats.rx_bytes += frame_len;
  1288. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1289. stats = netif_rx(skb);
  1290. PRINT_D(RX_DBG, "netif_rx ret value is: %d\n", stats);
  1291. }
  1292. }
  1293. void WILC_WFI_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size)
  1294. {
  1295. int i = 0;
  1296. perInterface_wlan_t *nic;
  1297. /*Pass the frame on the monitor interface, if any.*/
  1298. /*Otherwise, pass it on p2p0 netdev, if registered on it*/
  1299. for (i = 0; i < wilc->vif_num; i++) {
  1300. nic = netdev_priv(wilc->vif[i].ndev);
  1301. if (nic->monitor_flag) {
  1302. WILC_WFI_monitor_rx(buff, size);
  1303. return;
  1304. }
  1305. }
  1306. nic = netdev_priv(wilc->vif[1].ndev); /* p2p0 */
  1307. if ((buff[0] == nic->g_struct_frame_reg[0].frame_type && nic->g_struct_frame_reg[0].reg) ||
  1308. (buff[0] == nic->g_struct_frame_reg[1].frame_type && nic->g_struct_frame_reg[1].reg))
  1309. WILC_WFI_p2p_rx(wilc->vif[1].ndev, buff, size);
  1310. }
  1311. void wl_wlan_cleanup(void)
  1312. {
  1313. int i = 0;
  1314. perInterface_wlan_t *nic[NUM_CONCURRENT_IFC];
  1315. if (g_linux_wlan &&
  1316. (g_linux_wlan->vif[0].ndev || g_linux_wlan->vif[1].ndev)) {
  1317. unregister_inetaddr_notifier(&g_dev_notifier);
  1318. for (i = 0; i < NUM_CONCURRENT_IFC; i++)
  1319. nic[i] = netdev_priv(g_linux_wlan->vif[i].ndev);
  1320. }
  1321. if (g_linux_wlan && g_linux_wlan->firmware)
  1322. release_firmware(g_linux_wlan->firmware);
  1323. if (g_linux_wlan &&
  1324. (g_linux_wlan->vif[0].ndev || g_linux_wlan->vif[1].ndev)) {
  1325. linux_wlan_lock_timeout(&close_exit_sync, 12 * 1000);
  1326. for (i = 0; i < NUM_CONCURRENT_IFC; i++)
  1327. if (g_linux_wlan->vif[i].ndev)
  1328. if (nic[i]->mac_opened)
  1329. mac_close(g_linux_wlan->vif[i].ndev);
  1330. for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
  1331. unregister_netdev(g_linux_wlan->vif[i].ndev);
  1332. wilc_free_wiphy(g_linux_wlan->vif[i].ndev);
  1333. free_netdev(g_linux_wlan->vif[i].ndev);
  1334. }
  1335. }
  1336. kfree(g_linux_wlan);
  1337. #if defined(WILC_DEBUGFS)
  1338. wilc_debugfs_remove();
  1339. #endif
  1340. linux_wlan_device_detection(0);
  1341. linux_wlan_device_power(0);
  1342. }
  1343. int wilc_netdev_init(struct wilc **wilc)
  1344. {
  1345. int i;
  1346. perInterface_wlan_t *nic;
  1347. struct net_device *ndev;
  1348. sema_init(&close_exit_sync, 0);
  1349. /*create the common structure*/
  1350. g_linux_wlan = kzalloc(sizeof(*g_linux_wlan), GFP_KERNEL);
  1351. if (!g_linux_wlan)
  1352. return -ENOMEM;
  1353. *wilc = g_linux_wlan;
  1354. register_inetaddr_notifier(&g_dev_notifier);
  1355. for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
  1356. /*allocate first ethernet device with perinterface_wlan_t as its private data*/
  1357. ndev = alloc_etherdev(sizeof(perInterface_wlan_t));
  1358. if (!ndev) {
  1359. PRINT_ER("Failed to allocate ethernet dev\n");
  1360. return -1;
  1361. }
  1362. nic = netdev_priv(ndev);
  1363. memset(nic, 0, sizeof(perInterface_wlan_t));
  1364. /*Name the Devices*/
  1365. if (i == 0) {
  1366. #if defined(NM73131) /* tony, 2012-09-20 */
  1367. strcpy(ndev->name, "wilc_eth%d");
  1368. #elif defined(PLAT_CLM9722) /* rachel */
  1369. strcpy(ndev->name, "eth%d");
  1370. #else /* PANDA_BOARD, PLAT_ALLWINNER_A10, PLAT_ALLWINNER_A20, PLAT_ALLWINNER_A31, PLAT_AML8726_M3 or PLAT_WMS8304 */
  1371. strcpy(ndev->name, "wlan%d");
  1372. #endif
  1373. } else
  1374. strcpy(ndev->name, "p2p%d");
  1375. nic->u8IfIdx = g_linux_wlan->vif_num;
  1376. nic->wilc_netdev = ndev;
  1377. nic->wilc = *wilc;
  1378. g_linux_wlan->vif[g_linux_wlan->vif_num].ndev = ndev;
  1379. g_linux_wlan->vif_num++;
  1380. ndev->netdev_ops = &wilc_netdev_ops;
  1381. {
  1382. struct wireless_dev *wdev;
  1383. /*Register WiFi*/
  1384. wdev = wilc_create_wiphy(ndev);
  1385. #ifdef WILC_SDIO
  1386. /* set netdev, tony */
  1387. SET_NETDEV_DEV(ndev, &local_sdio_func->dev);
  1388. #endif
  1389. if (wdev == NULL) {
  1390. PRINT_ER("Can't register WILC Wiphy\n");
  1391. return -1;
  1392. }
  1393. /*linking the wireless_dev structure with the netdevice*/
  1394. nic->wilc_netdev->ieee80211_ptr = wdev;
  1395. nic->wilc_netdev->ml_priv = nic;
  1396. wdev->netdev = nic->wilc_netdev;
  1397. nic->netstats.rx_packets = 0;
  1398. nic->netstats.tx_packets = 0;
  1399. nic->netstats.rx_bytes = 0;
  1400. nic->netstats.tx_bytes = 0;
  1401. }
  1402. if (register_netdev(ndev)) {
  1403. PRINT_ER("Device couldn't be registered - %s\n", ndev->name);
  1404. return -1; /* ERROR */
  1405. }
  1406. nic->iftype = STATION_MODE;
  1407. nic->mac_opened = 0;
  1408. }
  1409. #ifndef WILC_SDIO
  1410. if (!linux_spi_init(&g_linux_wlan->wilc_spidev)) {
  1411. PRINT_ER("Can't initialize SPI\n");
  1412. return -1; /* ERROR */
  1413. }
  1414. g_linux_wlan->wilc_spidev = wilc_spi_dev;
  1415. #else
  1416. g_linux_wlan->wilc_sdio_func = local_sdio_func;
  1417. #endif
  1418. return 0;
  1419. }
  1420. /*The 1st function called after module inserted*/
  1421. static int __init init_wilc_driver(void)
  1422. {
  1423. #ifdef WILC_SPI
  1424. struct wilc *wilc;
  1425. #endif
  1426. #if defined(WILC_DEBUGFS)
  1427. if (wilc_debugfs_init() < 0) {
  1428. PRINT_D(GENERIC_DBG, "fail to create debugfs for wilc driver\n");
  1429. return -1;
  1430. }
  1431. #endif
  1432. printk("IN INIT FUNCTION\n");
  1433. printk("*** WILC1000 driver VERSION=[10.2] FW_VER=[10.2] ***\n");
  1434. linux_wlan_device_power(1);
  1435. msleep(100);
  1436. linux_wlan_device_detection(1);
  1437. #ifdef WILC_SDIO
  1438. {
  1439. int ret;
  1440. ret = sdio_register_driver(&wilc_bus);
  1441. if (ret < 0)
  1442. PRINT_D(INIT_DBG, "init_wilc_driver: Failed register sdio driver\n");
  1443. return ret;
  1444. }
  1445. #else
  1446. PRINT_D(INIT_DBG, "Initializing netdev\n");
  1447. if (wilc_netdev_init(&wilc))
  1448. PRINT_ER("Couldn't initialize netdev\n");
  1449. return 0;
  1450. #endif
  1451. }
  1452. late_initcall(init_wilc_driver);
  1453. static void __exit exit_wilc_driver(void)
  1454. {
  1455. #ifndef WILC_SDIO
  1456. PRINT_D(INIT_DBG, "SPI unregister...\n");
  1457. spi_unregister_driver(&wilc_bus);
  1458. #else
  1459. PRINT_D(INIT_DBG, "SDIO unregister...\n");
  1460. sdio_unregister_driver(&wilc_bus);
  1461. #endif
  1462. }
  1463. module_exit(exit_wilc_driver);
  1464. MODULE_LICENSE("GPL");