aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmitkumar Karwar <akarwar@marvell.com>2011-04-15 23:50:42 -0400
committerJohn W. Linville <linville@tuxdriver.com>2011-04-19 15:38:04 -0400
commit2be7859f41e9bcef5b15bd23d63e01536344e3df (patch)
tree3c7dcec98f5811731fa4209d9d52d504bc4de036
parenta37316586d926a10d66b5585c5d91683d6468f68 (diff)
mwifiex: optimize driver initialization code
1) removal of unnecessary mwifiex_device structure 2) avoid passing adapter pointer to mwifiex_init_sw() 3) remove local variable drv_mode_info in mwifiex_add_card() 4) type change in mwifiex_bss_attr to match mwifiex_private 5) removal of more wordy comments Signed-off-by: Amitkumar Karwar <akarwar@marvell.com> Signed-off-by: Bing Zhao <bzhao@marvell.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--drivers/net/wireless/mwifiex/decl.h14
-rw-r--r--drivers/net/wireless/mwifiex/main.c81
-rw-r--r--drivers/net/wireless/mwifiex/main.h2
3 files changed, 33 insertions, 64 deletions
diff --git a/drivers/net/wireless/mwifiex/decl.h b/drivers/net/wireless/mwifiex/decl.h
index 8364b62c3298..0e90b0986ed8 100644
--- a/drivers/net/wireless/mwifiex/decl.h
+++ b/drivers/net/wireless/mwifiex/decl.h
@@ -113,11 +113,11 @@ struct mwifiex_txinfo {
113}; 113};
114 114
115struct mwifiex_bss_attr { 115struct mwifiex_bss_attr {
116 u32 bss_type; 116 u8 bss_type;
117 u32 frame_type; 117 u8 frame_type;
118 u32 active; 118 u8 active;
119 u32 bss_priority; 119 u8 bss_priority;
120 u32 bss_num; 120 u8 bss_num;
121}; 121};
122 122
123enum mwifiex_wmm_ac_e { 123enum mwifiex_wmm_ac_e {
@@ -126,8 +126,4 @@ enum mwifiex_wmm_ac_e {
126 WMM_AC_VI, 126 WMM_AC_VI,
127 WMM_AC_VO 127 WMM_AC_VO
128} __packed; 128} __packed;
129
130struct mwifiex_device {
131 struct mwifiex_bss_attr bss_attr[MWIFIEX_MAX_BSS_NUM];
132};
133#endif /* !_MWIFIEX_DECL_H_ */ 129#endif /* !_MWIFIEX_DECL_H_ */
diff --git a/drivers/net/wireless/mwifiex/main.c b/drivers/net/wireless/mwifiex/main.c
index 2c376dd4ad50..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,13 +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 struct mwifiex_adapter *adapter = NULL; 67 struct mwifiex_adapter *adapter;
72 u8 i = 0; 68 int i;
73 69
74 adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL); 70 adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL);
75 /* Allocate memory for adapter structure */
76 if (!adapter) 71 if (!adapter)
77 return -1; 72 return -1;
78 73
@@ -87,14 +82,13 @@ static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
87 goto error; 82 goto error;
88 83
89 adapter->priv_num = 0; 84 adapter->priv_num = 0;
90 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) { 85 for (i = 0; i < drv_mode_ptr->intf_num; i++) {
91 adapter->priv[i] = NULL; 86 adapter->priv[i] = NULL;
92 87
93 if (!mdevice->bss_attr[i].active) 88 if (!drv_mode_ptr->bss_attr[i].active)
94 continue; 89 continue;
95 90
96 /* For valid bss_attr, 91 /* Allocate memory for private structure */
97 allocate memory for private structure */
98 adapter->priv[i] = kzalloc(sizeof(struct mwifiex_private), 92 adapter->priv[i] = kzalloc(sizeof(struct mwifiex_private),
99 GFP_KERNEL); 93 GFP_KERNEL);
100 if (!adapter->priv[i]) { 94 if (!adapter->priv[i]) {
@@ -104,26 +98,26 @@ static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
104 } 98 }
105 99
106 adapter->priv_num++; 100 adapter->priv_num++;
107 memset(adapter->priv[i], 0,
108 sizeof(struct mwifiex_private));
109 adapter->priv[i]->adapter = adapter; 101 adapter->priv[i]->adapter = adapter;
110 /* Save bss_type, frame_type & bss_priority */ 102 /* Save bss_type, frame_type & bss_priority */
111 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;
112 adapter->priv[i]->frame_type = 104 adapter->priv[i]->frame_type =
113 (u8) mdevice->bss_attr[i].frame_type; 105 drv_mode_ptr->bss_attr[i].frame_type;
114 adapter->priv[i]->bss_priority = 106 adapter->priv[i]->bss_priority =
115 (u8) mdevice->bss_attr[i].bss_priority; 107 drv_mode_ptr->bss_attr[i].bss_priority;
116 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)
117 adapter->priv[i]->bss_role = MWIFIEX_BSS_ROLE_STA; 110 adapter->priv[i]->bss_role = MWIFIEX_BSS_ROLE_STA;
118 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)
119 adapter->priv[i]->bss_role = MWIFIEX_BSS_ROLE_UAP; 113 adapter->priv[i]->bss_role = MWIFIEX_BSS_ROLE_UAP;
120 114
121 /* Save bss_index & bss_num */ 115 /* Save bss_index & bss_num */
122 adapter->priv[i]->bss_index = i; 116 adapter->priv[i]->bss_index = i;
123 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;
124 } 118 }
119 adapter->drv_mode = drv_mode_ptr;
125 120
126 /* Initialize lock variables */
127 if (mwifiex_init_lock_list(adapter)) 121 if (mwifiex_init_lock_list(adapter))
128 goto error; 122 goto error;
129 123
@@ -131,16 +125,13 @@ static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
131 adapter->cmd_timer.function = mwifiex_cmd_timeout_func; 125 adapter->cmd_timer.function = mwifiex_cmd_timeout_func;
132 adapter->cmd_timer.data = (unsigned long) adapter; 126 adapter->cmd_timer.data = (unsigned long) adapter;
133 127
134 /* Return pointer of struct mwifiex_adapter */
135 *padapter = adapter;
136 return 0; 128 return 0;
137 129
138error: 130error:
139 dev_dbg(adapter->dev, "info: leave mwifiex_register with error\n"); 131 dev_dbg(adapter->dev, "info: leave mwifiex_register with error\n");
140 132
141 /* Free lock variables */
142 mwifiex_free_lock_list(adapter); 133 mwifiex_free_lock_list(adapter);
143 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) 134 for (i = 0; i < drv_mode_ptr->intf_num; i++)
144 kfree(adapter->priv[i]); 135 kfree(adapter->priv[i]);
145 kfree(adapter); 136 kfree(adapter);
146 137
@@ -335,10 +326,9 @@ exit_main_proc:
335 * and initializing the private structures. 326 * and initializing the private structures.
336 */ 327 */
337static int 328static int
338mwifiex_init_sw(void *card, struct mwifiex_if_ops *if_ops, void **pmwifiex) 329mwifiex_init_sw(void *card, struct mwifiex_if_ops *if_ops)
339{ 330{
340 int i; 331 int i;
341 struct mwifiex_device device;
342 struct mwifiex_drv_mode *drv_mode_ptr; 332 struct mwifiex_drv_mode *drv_mode_ptr;
343 333
344 /* find mwifiex_drv_mode entry from mwifiex_drv_mode_tbl */ 334 /* find mwifiex_drv_mode entry from mwifiex_drv_mode_tbl */
@@ -355,20 +345,7 @@ mwifiex_init_sw(void *card, struct mwifiex_if_ops *if_ops, void **pmwifiex)
355 return -1; 345 return -1;
356 } 346 }
357 347
358 memset(&device, 0, sizeof(struct mwifiex_device)); 348 if (mwifiex_register(card, if_ops, drv_mode_ptr))
359
360 for (i = 0; i < drv_mode_ptr->intf_num; i++) {
361 device.bss_attr[i].bss_type =
362 drv_mode_ptr->bss_attr[i].bss_type;
363 device.bss_attr[i].frame_type =
364 drv_mode_ptr->bss_attr[i].frame_type;
365 device.bss_attr[i].active = drv_mode_ptr->bss_attr[i].active;
366 device.bss_attr[i].bss_priority =
367 drv_mode_ptr->bss_attr[i].bss_priority;
368 device.bss_attr[i].bss_num = drv_mode_ptr->bss_attr[i].bss_num;
369 }
370
371 if (mwifiex_register(card, if_ops, &device, pmwifiex))
372 return -1; 349 return -1;
373 350
374 return 0; 351 return 0;
@@ -892,21 +869,19 @@ mwifiex_add_card(void *card, struct semaphore *sem,
892 struct mwifiex_if_ops *if_ops) 869 struct mwifiex_if_ops *if_ops)
893{ 870{
894 int i; 871 int i;
895 struct mwifiex_adapter *adapter = NULL; 872 struct mwifiex_adapter *adapter;
896 struct mwifiex_drv_mode *drv_mode_info = &mwifiex_drv_mode_tbl[0];
897 873
898 if (down_interruptible(sem)) 874 if (down_interruptible(sem))
899 goto exit_sem_err; 875 goto exit_sem_err;
900 876
901 if (mwifiex_init_sw(card, if_ops, (void **) &adapter)) { 877 if (mwifiex_init_sw(card, if_ops)) {
902 pr_err("%s: software init failed\n", __func__); 878 pr_err("%s: software init failed\n", __func__);
903 goto err_init_sw; 879 goto err_init_sw;
904 } 880 }
905 881
906 adapter->drv_mode = drv_mode_info; 882 adapter = g_adapter;
907 883
908 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; 884 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
909 /* PnP and power profile */
910 adapter->surprise_removed = false; 885 adapter->surprise_removed = false;
911 init_waitqueue_head(&adapter->init_wait_q); 886 init_waitqueue_head(&adapter->init_wait_q);
912 adapter->is_suspended = false; 887 adapter->is_suspended = false;
@@ -917,7 +892,6 @@ mwifiex_add_card(void *card, struct semaphore *sem,
917 adapter->cmd_wait_q.condition = false; 892 adapter->cmd_wait_q.condition = false;
918 adapter->cmd_wait_q.status = 0; 893 adapter->cmd_wait_q.status = 0;
919 894
920 /* Create workqueue */
921 adapter->workqueue = create_workqueue("MWIFIEX_WORK_QUEUE"); 895 adapter->workqueue = create_workqueue("MWIFIEX_WORK_QUEUE");
922 if (!adapter->workqueue) 896 if (!adapter->workqueue)
923 goto err_kmalloc; 897 goto err_kmalloc;
@@ -931,13 +905,13 @@ mwifiex_add_card(void *card, struct semaphore *sem,
931 goto err_registerdev; 905 goto err_registerdev;
932 } 906 }
933 907
934 /* Init FW and HW */
935 if (mwifiex_init_hw_fw(adapter)) { 908 if (mwifiex_init_hw_fw(adapter)) {
936 pr_err("%s: firmware init failed\n", __func__); 909 pr_err("%s: firmware init failed\n", __func__);
937 goto err_init_fw; 910 goto err_init_fw;
938 } 911 }
912
939 /* Add interfaces */ 913 /* Add interfaces */
940 for (i = 0; i < drv_mode_info->intf_num; i++) { 914 for (i = 0; i < adapter->drv_mode->intf_num; i++) {
941 if (!mwifiex_add_interface(adapter, i, 915 if (!mwifiex_add_interface(adapter, i,
942 adapter->drv_mode->bss_attr[i].bss_type)) { 916 adapter->drv_mode->bss_attr[i].bss_type)) {
943 goto err_add_intf; 917 goto err_add_intf;
@@ -952,7 +926,6 @@ err_add_intf:
952 for (i = 0; i < adapter->priv_num; i++) 926 for (i = 0; i < adapter->priv_num; i++)
953 mwifiex_remove_interface(adapter, i); 927 mwifiex_remove_interface(adapter, i);
954err_init_fw: 928err_init_fw:
955 /* Unregister device */
956 pr_debug("info: %s: unregister device\n", __func__); 929 pr_debug("info: %s: unregister device\n", __func__);
957 adapter->if_ops.unregister_dev(adapter); 930 adapter->if_ops.unregister_dev(adapter);
958err_registerdev: 931err_registerdev:
diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
index 2d296dcc210e..1b503038270e 100644
--- a/drivers/net/wireless/mwifiex/main.h
+++ b/drivers/net/wireless/mwifiex/main.h
@@ -872,7 +872,7 @@ mwifiex_copy_rates(u8 *dest, u32 pos, u8 *src, int len)
872 */ 872 */
873static inline struct mwifiex_private * 873static inline struct mwifiex_private *
874mwifiex_get_priv_by_id(struct mwifiex_adapter *adapter, 874mwifiex_get_priv_by_id(struct mwifiex_adapter *adapter,
875 u32 bss_num, u32 bss_type) 875 u8 bss_num, u8 bss_type)
876{ 876{
877 int i; 877 int i;
878 878