2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
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.
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.
21 * Purpose: Handles the management command interface 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
44 static void vnt_cmd_timer_wait(struct vnt_private *priv, unsigned long msecs)
46 schedule_delayed_work(&priv->run_command_work, msecs_to_jiffies(msecs));
49 static int vnt_cmd_complete(struct vnt_private *priv)
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;
59 priv->command = priv->cmd_queue[priv->cmd_dequeue_idx];
61 ADD_ONE_WITH_WRAP_AROUND(priv->cmd_dequeue_idx, CMD_Q_SIZE);
62 priv->free_cmd_queue++;
63 priv->cmd_running = true;
65 switch (priv->command) {
66 case WLAN_CMD_INIT_MAC80211:
67 priv->command_state = WLAN_CMD_INIT_MAC80211_START;
70 case WLAN_CMD_TBTT_WAKEUP:
71 priv->command_state = WLAN_CMD_TBTT_WAKEUP_START;
74 case WLAN_CMD_BECON_SEND:
75 priv->command_state = WLAN_CMD_BECON_SEND_START;
78 case WLAN_CMD_SETPOWER:
79 priv->command_state = WLAN_CMD_SETPOWER_START;
82 case WLAN_CMD_CHANGE_ANTENNA:
83 priv->command_state = WLAN_CMD_CHANGE_ANTENNA_START;
90 vnt_cmd_timer_wait(priv, 0);
95 void vnt_run_command(struct work_struct *work)
97 struct vnt_private *priv =
98 container_of(work, struct vnt_private, run_command_work.work);
100 if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
103 if (priv->cmd_running != true)
106 switch (priv->command_state) {
107 case WLAN_CMD_INIT_MAC80211_START:
111 dev_info(&priv->usb->dev, "Starting mac80211\n");
113 if (vnt_init(priv)) {
114 /* If fail all ends TODO retry */
115 dev_err(&priv->usb->dev, "failed to start\n");
116 ieee80211_free_hw(priv->hw);
122 case WLAN_CMD_TBTT_WAKEUP_START:
123 vnt_next_tbtt_wakeup(priv);
126 case WLAN_CMD_BECON_SEND_START:
130 vnt_beacon_make(priv, priv->vif);
132 vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
136 case WLAN_CMD_SETPOWER_START:
138 vnt_rf_setpower(priv, priv->current_rate,
139 priv->hw->conf.chandef.chan->hw_value);
143 case WLAN_CMD_CHANGE_ANTENNA_START:
144 dev_dbg(&priv->usb->dev, "Change from Antenna%d to",
145 priv->rx_antenna_sel);
147 if (priv->rx_antenna_sel == 0) {
148 priv->rx_antenna_sel = 1;
149 if (priv->tx_rx_ant_inv == true)
150 vnt_set_antenna_mode(priv, ANT_RXA);
152 vnt_set_antenna_mode(priv, ANT_RXB);
154 priv->rx_antenna_sel = 0;
155 if (priv->tx_rx_ant_inv == true)
156 vnt_set_antenna_mode(priv, ANT_RXB);
158 vnt_set_antenna_mode(priv, ANT_RXA);
166 vnt_cmd_complete(priv);
169 int vnt_schedule_command(struct vnt_private *priv, enum vnt_cmd command)
172 if (priv->free_cmd_queue == 0)
175 priv->cmd_queue[priv->cmd_enqueue_idx] = command;
177 ADD_ONE_WITH_WRAP_AROUND(priv->cmd_enqueue_idx, CMD_Q_SIZE);
178 priv->free_cmd_queue--;
180 if (priv->cmd_running == false)
181 vnt_cmd_complete(priv);
187 void vnt_reset_command_timer(struct vnt_private *priv)
189 priv->free_cmd_queue = CMD_Q_SIZE;
190 priv->cmd_dequeue_idx = 0;
191 priv->cmd_enqueue_idx = 0;
192 priv->command_state = WLAN_CMD_IDLE;
193 priv->cmd_running = false;