blob: 3cbf4791bac17ce661e823d6f682e03bbbd62374 [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
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:
Malcolm Priestley60cecd22014-07-13 10:42:47 +010028 * vnt_cmd_complete - Command Complete function
Malcolm Priestleya83a8592014-07-13 10:42:53 +010029 * vnt_schedule_command - Push Command and wait Command Scheduler to do
Malcolm Priestley2cd98cd2014-07-13 10:42:48 +010030 * vnt_cmd_timer_wait- Call back timer
Forest Bond92b96792009-06-13 07:38:31 -040031 *
32 * Revision History:
33 *
34 */
35
Forest Bond92b96792009-06-13 07:38:31 -040036#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040037#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040038#include "wcmd.h"
Forest Bond92b96792009-06-13 07:38:31 -040039#include "power.h"
Malcolm Priestley62c85262014-05-26 13:59:07 +010040#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040041#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040042#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040043
Malcolm Priestley2cd98cd2014-07-13 10:42:48 +010044static void vnt_cmd_timer_wait(struct vnt_private *priv, unsigned long msecs)
Forest Bond92b96792009-06-13 07:38:31 -040045{
Malcolm Priestleye30546d2014-07-12 07:53:39 +010046 schedule_delayed_work(&priv->run_command_work, msecs_to_jiffies(msecs));
Forest Bond92b96792009-06-13 07:38:31 -040047}
48
Malcolm Priestley60cecd22014-07-13 10:42:47 +010049static 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
Malcolm Priestley60cecd22014-07-13 10:42:47 +010086 default:
87 break;
88 }
89
Malcolm Priestley2cd98cd2014-07-13 10:42:48 +010090 vnt_cmd_timer_wait(priv, 0);
Malcolm Priestley60cecd22014-07-13 10:42:47 +010091
92 return true;
93}
94
Malcolm Priestley592365ae4a2014-07-13 10:42:49 +010095void vnt_run_command(struct work_struct *work)
Forest Bond92b96792009-06-13 07:38:31 -040096{
Malcolm Priestleycf07bb82014-07-12 07:53:42 +010097 struct vnt_private *priv =
Malcolm Priestley94488a72013-09-27 16:48:14 +010098 container_of(work, struct vnt_private, run_command_work.work);
Forest Bond92b96792009-06-13 07:38:31 -040099
Malcolm Priestleycbcc9a32014-07-24 21:13:20 +0100100 if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
Malcolm Priestley17f3ced2013-10-14 19:51:45 +0100101 return;
102
Malcolm Priestley33a60b82014-07-13 10:42:45 +0100103 if (priv->cmd_running != true)
Nandini Hanumanthagowdacab086d2013-11-12 23:05:35 +0530104 return;
Forest Bond92b96792009-06-13 07:38:31 -0400105
Malcolm Priestleyad74e912014-07-13 10:42:42 +0100106 switch (priv->command_state) {
Malcolm Priestley30816f82014-06-25 21:14:27 +0100107 case WLAN_CMD_INIT_MAC80211_START:
Malcolm Priestleycf07bb82014-07-12 07:53:42 +0100108 if (priv->mac_hw)
Malcolm Priestley30816f82014-06-25 21:14:27 +0100109 break;
Forest Bond92b96792009-06-13 07:38:31 -0400110
Malcolm Priestleycf07bb82014-07-12 07:53:42 +0100111 dev_info(&priv->usb->dev, "Starting mac80211\n");
Malcolm Priestley30816f82014-06-25 21:14:27 +0100112
Malcolm Priestleycf07bb82014-07-12 07:53:42 +0100113 if (vnt_init(priv)) {
Malcolm Priestley30816f82014-06-25 21:14:27 +0100114 /* If fail all ends TODO retry */
Malcolm Priestleycf07bb82014-07-12 07:53:42 +0100115 dev_err(&priv->usb->dev, "failed to start\n");
116 ieee80211_free_hw(priv->hw);
Malcolm Priestley30816f82014-06-25 21:14:27 +0100117 return;
118 }
119
120 break;
Forest Bond92b96792009-06-13 07:38:31 -0400121
Nandini Hanumanthagowda97d59f82013-11-12 23:05:36 +0530122 case WLAN_CMD_TBTT_WAKEUP_START:
Malcolm Priestleycf07bb82014-07-12 07:53:42 +0100123 vnt_next_tbtt_wakeup(priv);
Nandini Hanumanthagowda97d59f82013-11-12 23:05:36 +0530124 break;
Forest Bond92b96792009-06-13 07:38:31 -0400125
Nandini Hanumanthagowda97d59f82013-11-12 23:05:36 +0530126 case WLAN_CMD_BECON_SEND_START:
Malcolm Priestleycf07bb82014-07-12 07:53:42 +0100127 if (!priv->vif)
Malcolm Priestleyf31a67a2014-06-25 21:14:30 +0100128 break;
129
Malcolm Priestleycf07bb82014-07-12 07:53:42 +0100130 vnt_beacon_make(priv, priv->vif);
Malcolm Priestleyf31a67a2014-06-25 21:14:30 +0100131
Malcolm Priestleycf07bb82014-07-12 07:53:42 +0100132 vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
Malcolm Priestleyf31a67a2014-06-25 21:14:30 +0100133
Nandini Hanumanthagowda97d59f82013-11-12 23:05:36 +0530134 break;
Forest Bond92b96792009-06-13 07:38:31 -0400135
Nandini Hanumanthagowda97d59f82013-11-12 23:05:36 +0530136 case WLAN_CMD_SETPOWER_START:
Forest Bond92b96792009-06-13 07:38:31 -0400137
Malcolm Priestley8b84c1d2014-07-20 15:33:19 +0100138 vnt_rf_setpower(priv, priv->current_rate,
Malcolm Priestleycf07bb82014-07-12 07:53:42 +0100139 priv->hw->conf.chandef.chan->hw_value);
Forest Bond92b96792009-06-13 07:38:31 -0400140
Nandini Hanumanthagowda97d59f82013-11-12 23:05:36 +0530141 break;
Forest Bond92b96792009-06-13 07:38:31 -0400142
Nandini Hanumanthagowda97d59f82013-11-12 23:05:36 +0530143 case WLAN_CMD_CHANGE_ANTENNA_START:
Malcolm Priestleyf7f04852014-07-12 07:53:48 +0100144 dev_dbg(&priv->usb->dev, "Change from Antenna%d to",
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100145 priv->rx_antenna_sel);
Malcolm Priestleycf07bb82014-07-12 07:53:42 +0100146
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100147 if (priv->rx_antenna_sel == 0) {
148 priv->rx_antenna_sel = 1;
149 if (priv->tx_rx_ant_inv == true)
Malcolm Priestley41868bf2014-07-16 22:21:52 +0100150 vnt_set_antenna_mode(priv, ANT_RXA);
Nandini Hanumanthagowdacab086d2013-11-12 23:05:35 +0530151 else
Malcolm Priestley41868bf2014-07-16 22:21:52 +0100152 vnt_set_antenna_mode(priv, ANT_RXB);
Nandini Hanumanthagowdacab086d2013-11-12 23:05:35 +0530153 } else {
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100154 priv->rx_antenna_sel = 0;
155 if (priv->tx_rx_ant_inv == true)
Malcolm Priestley41868bf2014-07-16 22:21:52 +0100156 vnt_set_antenna_mode(priv, ANT_RXB);
Nandini Hanumanthagowdacab086d2013-11-12 23:05:35 +0530157 else
Malcolm Priestley41868bf2014-07-16 22:21:52 +0100158 vnt_set_antenna_mode(priv, ANT_RXA);
Nandini Hanumanthagowdacab086d2013-11-12 23:05:35 +0530159 }
Nandini Hanumanthagowda97d59f82013-11-12 23:05:36 +0530160 break;
Forest Bond92b96792009-06-13 07:38:31 -0400161
Nandini Hanumanthagowda97d59f82013-11-12 23:05:36 +0530162 default:
Nandini Hanumanthagowda97d59f82013-11-12 23:05:36 +0530163 break;
Malcolm Priestleya83a8592014-07-13 10:42:53 +0100164 }
Forest Bond92b96792009-06-13 07:38:31 -0400165
Malcolm Priestley60cecd22014-07-13 10:42:47 +0100166 vnt_cmd_complete(priv);
Forest Bond92b96792009-06-13 07:38:31 -0400167}
168
Malcolm Priestley57981a62014-07-13 10:42:50 +0100169int vnt_schedule_command(struct vnt_private *priv, enum vnt_cmd command)
Forest Bond92b96792009-06-13 07:38:31 -0400170{
Forest Bond92b96792009-06-13 07:38:31 -0400171
Malcolm Priestley33a60b82014-07-13 10:42:45 +0100172 if (priv->free_cmd_queue == 0)
Nandini Hanumanthagowda820c9b12013-11-12 23:05:37 +0530173 return false;
Forest Bond92b96792009-06-13 07:38:31 -0400174
Malcolm Priestley33a60b82014-07-13 10:42:45 +0100175 priv->cmd_queue[priv->cmd_enqueue_idx] = command;
Forest Bond92b96792009-06-13 07:38:31 -0400176
Malcolm Priestley33a60b82014-07-13 10:42:45 +0100177 ADD_ONE_WITH_WRAP_AROUND(priv->cmd_enqueue_idx, CMD_Q_SIZE);
178 priv->free_cmd_queue--;
Malcolm Priestleyf7e9ed42014-07-12 07:53:46 +0100179
Malcolm Priestley33a60b82014-07-13 10:42:45 +0100180 if (priv->cmd_running == false)
Malcolm Priestley60cecd22014-07-13 10:42:47 +0100181 vnt_cmd_complete(priv);
Nandini Hanumanthagowda566597a2013-11-12 23:05:30 +0530182
Nandini Hanumanthagowda820c9b12013-11-12 23:05:37 +0530183 return true;
Forest Bond92b96792009-06-13 07:38:31 -0400184
185}
186
Malcolm Priestley68cc1612014-07-13 10:42:51 +0100187void vnt_reset_command_timer(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400188{
Malcolm Priestley33a60b82014-07-13 10:42:45 +0100189 priv->free_cmd_queue = CMD_Q_SIZE;
190 priv->cmd_dequeue_idx = 0;
191 priv->cmd_enqueue_idx = 0;
Malcolm Priestleyad74e912014-07-13 10:42:42 +0100192 priv->command_state = WLAN_CMD_IDLE;
Malcolm Priestley33a60b82014-07-13 10:42:45 +0100193 priv->cmd_running = false;
Forest Bond92b96792009-06-13 07:38:31 -0400194}