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.
18 * Purpose: Handles the management command interface functions
25 * vnt_cmd_complete - Command Complete function
26 * vnt_schedule_command - Push Command and wait Command Scheduler to do
27 * vnt_cmd_timer_wait- Call back timer
41 static void vnt_cmd_timer_wait(struct vnt_private *priv, unsigned long msecs)
43 schedule_delayed_work(&priv->run_command_work, msecs_to_jiffies(msecs));
46 static int vnt_cmd_complete(struct vnt_private *priv)
48 priv->command_state = WLAN_CMD_IDLE;
49 if (priv->free_cmd_queue == CMD_Q_SIZE) {
50 /* Command Queue Empty */
51 priv->cmd_running = false;
55 priv->command = priv->cmd_queue[priv->cmd_dequeue_idx];
57 ADD_ONE_WITH_WRAP_AROUND(priv->cmd_dequeue_idx, CMD_Q_SIZE);
58 priv->free_cmd_queue++;
59 priv->cmd_running = true;
61 switch (priv->command) {
62 case WLAN_CMD_INIT_MAC80211:
63 priv->command_state = WLAN_CMD_INIT_MAC80211_START;
66 case WLAN_CMD_TBTT_WAKEUP:
67 priv->command_state = WLAN_CMD_TBTT_WAKEUP_START;
70 case WLAN_CMD_BECON_SEND:
71 priv->command_state = WLAN_CMD_BECON_SEND_START;
74 case WLAN_CMD_SETPOWER:
75 priv->command_state = WLAN_CMD_SETPOWER_START;
78 case WLAN_CMD_CHANGE_ANTENNA:
79 priv->command_state = WLAN_CMD_CHANGE_ANTENNA_START;
86 vnt_cmd_timer_wait(priv, 0);
91 void vnt_run_command(struct work_struct *work)
93 struct vnt_private *priv =
94 container_of(work, struct vnt_private, run_command_work.work);
96 if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
99 if (!priv->cmd_running)
102 switch (priv->command_state) {
103 case WLAN_CMD_INIT_MAC80211_START:
107 dev_info(&priv->usb->dev, "Starting mac80211\n");
109 if (vnt_init(priv)) {
110 /* If fail all ends TODO retry */
111 dev_err(&priv->usb->dev, "failed to start\n");
112 usb_set_intfdata(priv->intf, NULL);
113 ieee80211_free_hw(priv->hw);
119 case WLAN_CMD_TBTT_WAKEUP_START:
120 vnt_next_tbtt_wakeup(priv);
123 case WLAN_CMD_BECON_SEND_START:
127 vnt_beacon_make(priv, priv->vif);
129 vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
133 case WLAN_CMD_SETPOWER_START:
135 vnt_rf_setpower(priv, priv->current_rate,
136 priv->hw->conf.chandef.chan->hw_value);
140 case WLAN_CMD_CHANGE_ANTENNA_START:
141 dev_dbg(&priv->usb->dev, "Change from Antenna%d to",
142 priv->rx_antenna_sel);
144 if (priv->rx_antenna_sel == 0) {
145 priv->rx_antenna_sel = 1;
146 if (priv->tx_rx_ant_inv)
147 vnt_set_antenna_mode(priv, ANT_RXA);
149 vnt_set_antenna_mode(priv, ANT_RXB);
151 priv->rx_antenna_sel = 0;
152 if (priv->tx_rx_ant_inv)
153 vnt_set_antenna_mode(priv, ANT_RXB);
155 vnt_set_antenna_mode(priv, ANT_RXA);
163 vnt_cmd_complete(priv);
166 int vnt_schedule_command(struct vnt_private *priv, enum vnt_cmd command)
168 if (priv->free_cmd_queue == 0)
171 priv->cmd_queue[priv->cmd_enqueue_idx] = command;
173 ADD_ONE_WITH_WRAP_AROUND(priv->cmd_enqueue_idx, CMD_Q_SIZE);
174 priv->free_cmd_queue--;
176 if (!priv->cmd_running)
177 vnt_cmd_complete(priv);
182 void vnt_reset_command_timer(struct vnt_private *priv)
184 priv->free_cmd_queue = CMD_Q_SIZE;
185 priv->cmd_dequeue_idx = 0;
186 priv->cmd_enqueue_idx = 0;
187 priv->command_state = WLAN_CMD_IDLE;
188 priv->cmd_running = false;