aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/mwifiex/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/mwifiex/main.c')
-rw-r--r--drivers/net/wireless/mwifiex/main.c174
1 files changed, 66 insertions, 108 deletions
diff --git a/drivers/net/wireless/mwifiex/main.c b/drivers/net/wireless/mwifiex/main.c
index ed89ca41a902..c5971880e7b3 100644
--- a/drivers/net/wireless/mwifiex/main.c
+++ b/drivers/net/wireless/mwifiex/main.c
@@ -40,14 +40,10 @@ static char fw_name[32] = DEFAULT_FW_NAME;
40/* Supported drv_mode table */ 40/* Supported drv_mode table */
41static struct mwifiex_drv_mode mwifiex_drv_mode_tbl[] = { 41static struct mwifiex_drv_mode mwifiex_drv_mode_tbl[] = {
42 { 42 {
43 /* drv_mode */ 43 .drv_mode = DRV_MODE_STA,
44 .drv_mode = DRV_MODE_STA, 44 .intf_num = ARRAY_SIZE(mwifiex_bss_sta),
45 /* intf number */ 45 .bss_attr = mwifiex_bss_sta,
46 .intf_num = ARRAY_SIZE(mwifiex_bss_sta), 46 },
47 /* bss_attr */
48 .bss_attr = mwifiex_bss_sta,
49 }
50 ,
51}; 47};
52 48
53/* 49/*
@@ -66,14 +62,12 @@ static struct mwifiex_drv_mode mwifiex_drv_mode_tbl[] = {
66 * proper cleanup before exiting. 62 * proper cleanup before exiting.
67 */ 63 */
68static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops, 64static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
69 struct mwifiex_device *mdevice, void **padapter) 65 struct mwifiex_drv_mode *drv_mode_ptr)
70{ 66{
71 int ret = 0; 67 struct mwifiex_adapter *adapter;
72 struct mwifiex_adapter *adapter = NULL; 68 int i;
73 u8 i = 0;
74 69
75 adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL); 70 adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL);
76 /* Allocate memory for adapter structure */
77 if (!adapter) 71 if (!adapter)
78 return -1; 72 return -1;
79 73
@@ -84,19 +78,17 @@ static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
84 memmove(&adapter->if_ops, if_ops, sizeof(struct mwifiex_if_ops)); 78 memmove(&adapter->if_ops, if_ops, sizeof(struct mwifiex_if_ops));
85 79
86 /* card specific initialization has been deferred until now .. */ 80 /* card specific initialization has been deferred until now .. */
87 ret = adapter->if_ops.init_if(adapter); 81 if (adapter->if_ops.init_if(adapter))
88 if (ret)
89 goto error; 82 goto error;
90 83
91 adapter->priv_num = 0; 84 adapter->priv_num = 0;
92 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) { 85 for (i = 0; i < drv_mode_ptr->intf_num; i++) {
93 adapter->priv[i] = NULL; 86 adapter->priv[i] = NULL;
94 87
95 if (!mdevice->bss_attr[i].active) 88 if (!drv_mode_ptr->bss_attr[i].active)
96 continue; 89 continue;
97 90
98 /* For valid bss_attr, 91 /* Allocate memory for private structure */
99 allocate memory for private structure */
100 adapter->priv[i] = kzalloc(sizeof(struct mwifiex_private), 92 adapter->priv[i] = kzalloc(sizeof(struct mwifiex_private),
101 GFP_KERNEL); 93 GFP_KERNEL);
102 if (!adapter->priv[i]) { 94 if (!adapter->priv[i]) {
@@ -106,26 +98,26 @@ static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
106 } 98 }
107 99
108 adapter->priv_num++; 100 adapter->priv_num++;
109 memset(adapter->priv[i], 0,
110 sizeof(struct mwifiex_private));
111 adapter->priv[i]->adapter = adapter; 101 adapter->priv[i]->adapter = adapter;
112 /* Save bss_type, frame_type & bss_priority */ 102 /* Save bss_type, frame_type & bss_priority */
113 adapter->priv[i]->bss_type = (u8) mdevice->bss_attr[i].bss_type; 103 adapter->priv[i]->bss_type = drv_mode_ptr->bss_attr[i].bss_type;
114 adapter->priv[i]->frame_type = 104 adapter->priv[i]->frame_type =
115 (u8) mdevice->bss_attr[i].frame_type; 105 drv_mode_ptr->bss_attr[i].frame_type;
116 adapter->priv[i]->bss_priority = 106 adapter->priv[i]->bss_priority =
117 (u8) mdevice->bss_attr[i].bss_priority; 107 drv_mode_ptr->bss_attr[i].bss_priority;
118 if (mdevice->bss_attr[i].bss_type == MWIFIEX_BSS_TYPE_STA) 108
109 if (drv_mode_ptr->bss_attr[i].bss_type == MWIFIEX_BSS_TYPE_STA)
119 adapter->priv[i]->bss_role = MWIFIEX_BSS_ROLE_STA; 110 adapter->priv[i]->bss_role = MWIFIEX_BSS_ROLE_STA;
120 else if (mdevice->bss_attr[i].bss_type == MWIFIEX_BSS_TYPE_UAP) 111 else if (drv_mode_ptr->bss_attr[i].bss_type ==
112 MWIFIEX_BSS_TYPE_UAP)
121 adapter->priv[i]->bss_role = MWIFIEX_BSS_ROLE_UAP; 113 adapter->priv[i]->bss_role = MWIFIEX_BSS_ROLE_UAP;
122 114
123 /* Save bss_index & bss_num */ 115 /* Save bss_index & bss_num */
124 adapter->priv[i]->bss_index = i; 116 adapter->priv[i]->bss_index = i;
125 adapter->priv[i]->bss_num = mdevice->bss_attr[i].bss_num; 117 adapter->priv[i]->bss_num = drv_mode_ptr->bss_attr[i].bss_num;
126 } 118 }
119 adapter->drv_mode = drv_mode_ptr;
127 120
128 /* Initialize lock variables */
129 if (mwifiex_init_lock_list(adapter)) 121 if (mwifiex_init_lock_list(adapter))
130 goto error; 122 goto error;
131 123
@@ -133,16 +125,13 @@ static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
133 adapter->cmd_timer.function = mwifiex_cmd_timeout_func; 125 adapter->cmd_timer.function = mwifiex_cmd_timeout_func;
134 adapter->cmd_timer.data = (unsigned long) adapter; 126 adapter->cmd_timer.data = (unsigned long) adapter;
135 127
136 /* Return pointer of struct mwifiex_adapter */
137 *padapter = adapter;
138 return 0; 128 return 0;
139 129
140error: 130error:
141 dev_dbg(adapter->dev, "info: leave mwifiex_register with error\n"); 131 dev_dbg(adapter->dev, "info: leave mwifiex_register with error\n");
142 132
143 /* Free lock variables */
144 mwifiex_free_lock_list(adapter); 133 mwifiex_free_lock_list(adapter);
145 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) 134 for (i = 0; i < drv_mode_ptr->intf_num; i++)
146 kfree(adapter->priv[i]); 135 kfree(adapter->priv[i]);
147 kfree(adapter); 136 kfree(adapter);
148 137
@@ -337,10 +326,9 @@ exit_main_proc:
337 * and initializing the private structures. 326 * and initializing the private structures.
338 */ 327 */
339static int 328static int
340mwifiex_init_sw(void *card, struct mwifiex_if_ops *if_ops, void **pmwifiex) 329mwifiex_init_sw(void *card, struct mwifiex_if_ops *if_ops)
341{ 330{
342 int i; 331 int i;
343 struct mwifiex_device device;
344 struct mwifiex_drv_mode *drv_mode_ptr; 332 struct mwifiex_drv_mode *drv_mode_ptr;
345 333
346 /* find mwifiex_drv_mode entry from mwifiex_drv_mode_tbl */ 334 /* find mwifiex_drv_mode entry from mwifiex_drv_mode_tbl */
@@ -357,20 +345,7 @@ mwifiex_init_sw(void *card, struct mwifiex_if_ops *if_ops, void **pmwifiex)
357 return -1; 345 return -1;
358 } 346 }
359 347
360 memset(&device, 0, sizeof(struct mwifiex_device)); 348 if (mwifiex_register(card, if_ops, drv_mode_ptr))
361
362 for (i = 0; i < drv_mode_ptr->intf_num; i++) {
363 device.bss_attr[i].bss_type =
364 drv_mode_ptr->bss_attr[i].bss_type;
365 device.bss_attr[i].frame_type =
366 drv_mode_ptr->bss_attr[i].frame_type;
367 device.bss_attr[i].active = drv_mode_ptr->bss_attr[i].active;
368 device.bss_attr[i].bss_priority =
369 drv_mode_ptr->bss_attr[i].bss_priority;
370 device.bss_attr[i].bss_num = drv_mode_ptr->bss_attr[i].bss_num;
371 }
372
373 if (mwifiex_register(card, if_ops, &device, pmwifiex))
374 return -1; 349 return -1;
375 350
376 return 0; 351 return 0;
@@ -505,7 +480,6 @@ mwifiex_fill_buffer(struct sk_buff *skb)
505 */ 480 */
506 do_gettimeofday(&tv); 481 do_gettimeofday(&tv);
507 skb->tstamp = timeval_to_ktime(tv); 482 skb->tstamp = timeval_to_ktime(tv);
508 return;
509} 483}
510 484
511/* 485/*
@@ -597,16 +571,23 @@ mwifiex_set_mac_address(struct net_device *dev, void *addr)
597{ 571{
598 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 572 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
599 struct sockaddr *hw_addr = (struct sockaddr *) addr; 573 struct sockaddr *hw_addr = (struct sockaddr *) addr;
574 int ret = 0;
600 575
601 memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN); 576 memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN);
602 577
603 if (mwifiex_request_set_mac_address(priv)) { 578 /* Send request to firmware */
604 dev_err(priv->adapter->dev, "set MAC address failed\n"); 579 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_MAC_ADDRESS,
605 return -EFAULT; 580 HostCmd_ACT_GEN_SET, 0, NULL);
606 } 581
582 if (!ret)
583 memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN);
584 else
585 dev_err(priv->adapter->dev, "set mac address failed: ret=%d"
586 "\n", ret);
587
607 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN); 588 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
608 589
609 return 0; 590 return ret;
610} 591}
611 592
612/* 593/*
@@ -615,7 +596,20 @@ mwifiex_set_mac_address(struct net_device *dev, void *addr)
615static void mwifiex_set_multicast_list(struct net_device *dev) 596static void mwifiex_set_multicast_list(struct net_device *dev)
616{ 597{
617 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 598 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
618 mwifiex_request_set_multicast_list(priv, dev); 599 struct mwifiex_multicast_list mcast_list;
600
601 if (dev->flags & IFF_PROMISC) {
602 mcast_list.mode = MWIFIEX_PROMISC_MODE;
603 } else if (dev->flags & IFF_ALLMULTI ||
604 netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) {
605 mcast_list.mode = MWIFIEX_ALL_MULTI_MODE;
606 } else {
607 mcast_list.mode = MWIFIEX_MULTICAST_MODE;
608 if (netdev_mc_count(dev))
609 mcast_list.num_multicast_addr =
610 mwifiex_copy_mcast_addr(&mcast_list, dev);
611 }
612 mwifiex_request_set_multicast_list(priv, &mcast_list);
619} 613}
620 614
621/* 615/*
@@ -677,9 +671,6 @@ mwifiex_init_priv_params(struct mwifiex_private *priv, struct net_device *dev)
677{ 671{
678 dev->netdev_ops = &mwifiex_netdev_ops; 672 dev->netdev_ops = &mwifiex_netdev_ops;
679 /* Initialize private structure */ 673 /* Initialize private structure */
680 init_waitqueue_head(&priv->ioctl_wait_q);
681 init_waitqueue_head(&priv->cmd_wait_q);
682 init_waitqueue_head(&priv->w_stats_wait_q);
683 priv->current_key_index = 0; 674 priv->current_key_index = 0;
684 priv->media_connected = false; 675 priv->media_connected = false;
685 memset(&priv->nick_name, 0, sizeof(priv->nick_name)); 676 memset(&priv->nick_name, 0, sizeof(priv->nick_name));
@@ -803,37 +794,9 @@ mwifiex_remove_interface(struct mwifiex_adapter *adapter, u8 bss_index)
803 wiphy_unregister(priv->wdev->wiphy); 794 wiphy_unregister(priv->wdev->wiphy);
804 wiphy_free(priv->wdev->wiphy); 795 wiphy_free(priv->wdev->wiphy);
805 kfree(priv->wdev); 796 kfree(priv->wdev);
806
807 return;
808} 797}
809 798
810/* 799/*
811 * Sends IOCTL request to shutdown firmware.
812 *
813 * This function allocates the IOCTL request buffer, fills it
814 * with requisite parameters and calls the IOCTL handler.
815 */
816int mwifiex_shutdown_fw(struct mwifiex_private *priv, u8 wait_option)
817{
818 struct mwifiex_wait_queue *wait = NULL;
819 int status = 0;
820
821 /* Allocate an IOCTL request buffer */
822 wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
823 if (!wait)
824 return -ENOMEM;
825
826 status = mwifiex_misc_ioctl_init_shutdown(priv->adapter, wait,
827 MWIFIEX_FUNC_SHUTDOWN);
828
829 status = mwifiex_request_ioctl(priv, wait, status, wait_option);
830
831 kfree(wait);
832 return status;
833}
834EXPORT_SYMBOL_GPL(mwifiex_shutdown_fw);
835
836/*
837 * This function check if command is pending. 800 * This function check if command is pending.
838 */ 801 */
839int is_command_pending(struct mwifiex_adapter *adapter) 802int is_command_pending(struct mwifiex_adapter *adapter)
@@ -905,30 +868,30 @@ int
905mwifiex_add_card(void *card, struct semaphore *sem, 868mwifiex_add_card(void *card, struct semaphore *sem,
906 struct mwifiex_if_ops *if_ops) 869 struct mwifiex_if_ops *if_ops)
907{ 870{
908 int status = 0;
909 int i; 871 int i;
910 struct mwifiex_adapter *adapter = NULL; 872 struct mwifiex_adapter *adapter;
911 struct mwifiex_drv_mode *drv_mode_info = &mwifiex_drv_mode_tbl[0];
912 873
913 if (down_interruptible(sem)) 874 if (down_interruptible(sem))
914 goto exit_sem_err; 875 goto exit_sem_err;
915 876
916 if (mwifiex_init_sw(card, if_ops, (void **) &adapter)) { 877 if (mwifiex_init_sw(card, if_ops)) {
917 pr_err("%s: software init failed\n", __func__); 878 pr_err("%s: software init failed\n", __func__);
918 goto err_init_sw; 879 goto err_init_sw;
919 } 880 }
920 881
921 adapter->drv_mode = drv_mode_info; 882 adapter = g_adapter;
922 883
923 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; 884 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
924 /* PnP and power profile */
925 adapter->surprise_removed = false; 885 adapter->surprise_removed = false;
926 init_waitqueue_head(&adapter->init_wait_q); 886 init_waitqueue_head(&adapter->init_wait_q);
927 adapter->is_suspended = false; 887 adapter->is_suspended = false;
928 adapter->hs_activated = false; 888 adapter->hs_activated = false;
929 init_waitqueue_head(&adapter->hs_activate_wait_q); 889 init_waitqueue_head(&adapter->hs_activate_wait_q);
890 adapter->cmd_wait_q_required = false;
891 init_waitqueue_head(&adapter->cmd_wait_q.wait);
892 adapter->cmd_wait_q.condition = false;
893 adapter->cmd_wait_q.status = 0;
930 894
931 /* Create workqueue */
932 adapter->workqueue = create_workqueue("MWIFIEX_WORK_QUEUE"); 895 adapter->workqueue = create_workqueue("MWIFIEX_WORK_QUEUE");
933 if (!adapter->workqueue) 896 if (!adapter->workqueue)
934 goto err_kmalloc; 897 goto err_kmalloc;
@@ -942,21 +905,18 @@ mwifiex_add_card(void *card, struct semaphore *sem,
942 goto err_registerdev; 905 goto err_registerdev;
943 } 906 }
944 907
945 /* Init FW and HW */
946 if (mwifiex_init_hw_fw(adapter)) { 908 if (mwifiex_init_hw_fw(adapter)) {
947 pr_err("%s: firmware init failed\n", __func__); 909 pr_err("%s: firmware init failed\n", __func__);
948 goto err_init_fw; 910 goto err_init_fw;
949 } 911 }
912
950 /* Add interfaces */ 913 /* Add interfaces */
951 for (i = 0; i < drv_mode_info->intf_num; i++) { 914 for (i = 0; i < adapter->drv_mode->intf_num; i++) {
952 if (!mwifiex_add_interface(adapter, i, 915 if (!mwifiex_add_interface(adapter, i,
953 adapter->drv_mode->bss_attr[i].bss_type)) { 916 adapter->drv_mode->bss_attr[i].bss_type)) {
954 status = -1; 917 goto err_add_intf;
955 break;
956 } 918 }
957 } 919 }
958 if (status)
959 goto err_add_intf;
960 920
961 up(sem); 921 up(sem);
962 922
@@ -966,7 +926,6 @@ err_add_intf:
966 for (i = 0; i < adapter->priv_num; i++) 926 for (i = 0; i < adapter->priv_num; i++)
967 mwifiex_remove_interface(adapter, i); 927 mwifiex_remove_interface(adapter, i);
968err_init_fw: 928err_init_fw:
969 /* Unregister device */
970 pr_debug("info: %s: unregister device\n", __func__); 929 pr_debug("info: %s: unregister device\n", __func__);
971 adapter->if_ops.unregister_dev(adapter); 930 adapter->if_ops.unregister_dev(adapter);
972err_registerdev: 931err_registerdev:
@@ -977,8 +936,8 @@ err_kmalloc:
977 (adapter->hw_status == MWIFIEX_HW_STATUS_READY)) { 936 (adapter->hw_status == MWIFIEX_HW_STATUS_READY)) {
978 pr_debug("info: %s: shutdown mwifiex\n", __func__); 937 pr_debug("info: %s: shutdown mwifiex\n", __func__);
979 adapter->init_wait_q_woken = false; 938 adapter->init_wait_q_woken = false;
980 status = mwifiex_shutdown_drv(adapter); 939
981 if (status == -EINPROGRESS) 940 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
982 wait_event_interruptible(adapter->init_wait_q, 941 wait_event_interruptible(adapter->init_wait_q,
983 adapter->init_wait_q_woken); 942 adapter->init_wait_q_woken);
984 } 943 }
@@ -1007,7 +966,6 @@ EXPORT_SYMBOL_GPL(mwifiex_add_card);
1007int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem) 966int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem)
1008{ 967{
1009 struct mwifiex_private *priv = NULL; 968 struct mwifiex_private *priv = NULL;
1010 int status;
1011 int i; 969 int i;
1012 970
1013 if (down_interruptible(sem)) 971 if (down_interruptible(sem))
@@ -1031,19 +989,19 @@ int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem)
1031 989
1032 dev_dbg(adapter->dev, "cmd: calling mwifiex_shutdown_drv...\n"); 990 dev_dbg(adapter->dev, "cmd: calling mwifiex_shutdown_drv...\n");
1033 adapter->init_wait_q_woken = false; 991 adapter->init_wait_q_woken = false;
1034 status = mwifiex_shutdown_drv(adapter); 992
1035 if (status == -EINPROGRESS) 993 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
1036 wait_event_interruptible(adapter->init_wait_q, 994 wait_event_interruptible(adapter->init_wait_q,
1037 adapter->init_wait_q_woken); 995 adapter->init_wait_q_woken);
1038 dev_dbg(adapter->dev, "cmd: mwifiex_shutdown_drv done\n"); 996 dev_dbg(adapter->dev, "cmd: mwifiex_shutdown_drv done\n");
1039 if (atomic_read(&adapter->rx_pending) || 997 if (atomic_read(&adapter->rx_pending) ||
1040 atomic_read(&adapter->tx_pending) || 998 atomic_read(&adapter->tx_pending) ||
1041 atomic_read(&adapter->ioctl_pending)) { 999 atomic_read(&adapter->cmd_pending)) {
1042 dev_err(adapter->dev, "rx_pending=%d, tx_pending=%d, " 1000 dev_err(adapter->dev, "rx_pending=%d, tx_pending=%d, "
1043 "ioctl_pending=%d\n", 1001 "cmd_pending=%d\n",
1044 atomic_read(&adapter->rx_pending), 1002 atomic_read(&adapter->rx_pending),
1045 atomic_read(&adapter->tx_pending), 1003 atomic_read(&adapter->tx_pending),
1046 atomic_read(&adapter->ioctl_pending)); 1004 atomic_read(&adapter->cmd_pending));
1047 } 1005 }
1048 1006
1049 /* Remove interface */ 1007 /* Remove interface */