• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * File: wcmd.c
20  *
21  * Purpose: Handles the management command interface functions
22  *
23  * Author: Lyndon Chen
24  *
25  * Date: May 8, 2003
26  *
27  * Functions:
28  *	vnt_cmd_complete - Command Complete function
29  *	vnt_schedule_command - Push Command and wait Command Scheduler to do
30  *	vnt_cmd_timer_wait- Call back timer
31  *
32  * Revision History:
33  *
34  */
35 
36 #include "device.h"
37 #include "mac.h"
38 #include "wcmd.h"
39 #include "power.h"
40 #include "usbpipe.h"
41 #include "rxtx.h"
42 #include "rf.h"
43 
vnt_cmd_timer_wait(struct vnt_private * priv,unsigned long msecs)44 static void vnt_cmd_timer_wait(struct vnt_private *priv, unsigned long msecs)
45 {
46 	schedule_delayed_work(&priv->run_command_work, msecs_to_jiffies(msecs));
47 }
48 
vnt_cmd_complete(struct vnt_private * priv)49 static int vnt_cmd_complete(struct vnt_private *priv)
50 {
51 
52 	priv->command_state = WLAN_CMD_IDLE;
53 	if (priv->free_cmd_queue == CMD_Q_SIZE) {
54 		/* Command Queue Empty */
55 		priv->cmd_running = false;
56 		return true;
57 	}
58 
59 	priv->command = priv->cmd_queue[priv->cmd_dequeue_idx];
60 
61 	ADD_ONE_WITH_WRAP_AROUND(priv->cmd_dequeue_idx, CMD_Q_SIZE);
62 	priv->free_cmd_queue++;
63 	priv->cmd_running = true;
64 
65 	switch (priv->command) {
66 	case WLAN_CMD_INIT_MAC80211:
67 		priv->command_state = WLAN_CMD_INIT_MAC80211_START;
68 		break;
69 
70 	case WLAN_CMD_TBTT_WAKEUP:
71 		priv->command_state = WLAN_CMD_TBTT_WAKEUP_START;
72 		break;
73 
74 	case WLAN_CMD_BECON_SEND:
75 		priv->command_state = WLAN_CMD_BECON_SEND_START;
76 		break;
77 
78 	case WLAN_CMD_SETPOWER:
79 		priv->command_state = WLAN_CMD_SETPOWER_START;
80 		break;
81 
82 	case WLAN_CMD_CHANGE_ANTENNA:
83 		priv->command_state = WLAN_CMD_CHANGE_ANTENNA_START;
84 		break;
85 
86 	default:
87 		break;
88 	}
89 
90 	vnt_cmd_timer_wait(priv, 0);
91 
92 	return true;
93 }
94 
vnt_run_command(struct work_struct * work)95 void vnt_run_command(struct work_struct *work)
96 {
97 	struct vnt_private *priv =
98 		container_of(work, struct vnt_private, run_command_work.work);
99 
100 	if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
101 		return;
102 
103 	if (priv->cmd_running != true)
104 		return;
105 
106 	switch (priv->command_state) {
107 	case WLAN_CMD_INIT_MAC80211_START:
108 		if (priv->mac_hw)
109 			break;
110 
111 		dev_info(&priv->usb->dev, "Starting mac80211\n");
112 
113 		if (vnt_init(priv)) {
114 			/* If fail all ends TODO retry */
115 			dev_err(&priv->usb->dev, "failed to start\n");
116 			usb_set_intfdata(priv->intf, NULL);
117 			ieee80211_free_hw(priv->hw);
118 			return;
119 		}
120 
121 		break;
122 
123 	case WLAN_CMD_TBTT_WAKEUP_START:
124 		vnt_next_tbtt_wakeup(priv);
125 		break;
126 
127 	case WLAN_CMD_BECON_SEND_START:
128 		if (!priv->vif)
129 			break;
130 
131 		vnt_beacon_make(priv, priv->vif);
132 
133 		vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
134 
135 		break;
136 
137 	case WLAN_CMD_SETPOWER_START:
138 
139 		vnt_rf_setpower(priv, priv->current_rate,
140 				priv->hw->conf.chandef.chan->hw_value);
141 
142 		break;
143 
144 	case WLAN_CMD_CHANGE_ANTENNA_START:
145 		dev_dbg(&priv->usb->dev, "Change from Antenna%d to",
146 							priv->rx_antenna_sel);
147 
148 		if (priv->rx_antenna_sel == 0) {
149 			priv->rx_antenna_sel = 1;
150 			if (priv->tx_rx_ant_inv == true)
151 				vnt_set_antenna_mode(priv, ANT_RXA);
152 			else
153 				vnt_set_antenna_mode(priv, ANT_RXB);
154 		} else {
155 			priv->rx_antenna_sel = 0;
156 			if (priv->tx_rx_ant_inv == true)
157 				vnt_set_antenna_mode(priv, ANT_RXB);
158 			else
159 				vnt_set_antenna_mode(priv, ANT_RXA);
160 		}
161 		break;
162 
163 	default:
164 		break;
165 	}
166 
167 	vnt_cmd_complete(priv);
168 }
169 
vnt_schedule_command(struct vnt_private * priv,enum vnt_cmd command)170 int vnt_schedule_command(struct vnt_private *priv, enum vnt_cmd command)
171 {
172 
173 	if (priv->free_cmd_queue == 0)
174 		return false;
175 
176 	priv->cmd_queue[priv->cmd_enqueue_idx] = command;
177 
178 	ADD_ONE_WITH_WRAP_AROUND(priv->cmd_enqueue_idx, CMD_Q_SIZE);
179 	priv->free_cmd_queue--;
180 
181 	if (priv->cmd_running == false)
182 		vnt_cmd_complete(priv);
183 
184 	return true;
185 
186 }
187 
vnt_reset_command_timer(struct vnt_private * priv)188 void vnt_reset_command_timer(struct vnt_private *priv)
189 {
190 	priv->free_cmd_queue = CMD_Q_SIZE;
191 	priv->cmd_dequeue_idx = 0;
192 	priv->cmd_enqueue_idx = 0;
193 	priv->command_state = WLAN_CMD_IDLE;
194 	priv->cmd_running = false;
195 }
196