Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  4 * All rights reserved.
  5 *
 
 
  6 * Purpose: Handles the management command interface functions
  7 *
  8 * Author: Lyndon Chen
  9 *
 10 * Date: May 8, 2003
 11 *
 12 * Functions:
 13 *	vnt_cmd_complete - Command Complete function
 14 *	vnt_schedule_command - Push Command and wait Command Scheduler to do
 15 *	vnt_cmd_timer_wait- Call back timer
 16 *
 17 * Revision History:
 18 *
 19 */
 20
 21#include "device.h"
 22#include "mac.h"
 23#include "wcmd.h"
 24#include "power.h"
 25#include "usbpipe.h"
 26#include "rxtx.h"
 27#include "rf.h"
 28
 29static void vnt_cmd_timer_wait(struct vnt_private *priv, unsigned long msecs)
 30{
 31	schedule_delayed_work(&priv->run_command_work, msecs_to_jiffies(msecs));
 32}
 33
 34static u32 add_one_with_wrap_around(u32 var, u8 modulo)
 35{
 36	if (var >= (modulo - 1))
 37		var = 0;
 38	else
 39		var++;
 40	return var;
 41}
 42
 43static int vnt_cmd_complete(struct vnt_private *priv)
 44{
 45	priv->command_state = WLAN_CMD_IDLE;
 46	if (priv->free_cmd_queue == CMD_Q_SIZE) {
 47		/* Command Queue Empty */
 48		priv->cmd_running = false;
 49		return true;
 50	}
 51
 52	priv->command = priv->cmd_queue[priv->cmd_dequeue_idx];
 53
 54	priv->cmd_dequeue_idx = add_one_with_wrap_around(priv->cmd_dequeue_idx, CMD_Q_SIZE);
 55	priv->free_cmd_queue++;
 56	priv->cmd_running = true;
 57
 58	switch (priv->command) {
 59	case WLAN_CMD_INIT_MAC80211:
 60		priv->command_state = WLAN_CMD_INIT_MAC80211_START;
 61		break;
 62
 63	case WLAN_CMD_TBTT_WAKEUP:
 64		priv->command_state = WLAN_CMD_TBTT_WAKEUP_START;
 65		break;
 66
 67	case WLAN_CMD_BECON_SEND:
 68		priv->command_state = WLAN_CMD_BECON_SEND_START;
 69		break;
 70
 71	case WLAN_CMD_SETPOWER:
 72		priv->command_state = WLAN_CMD_SETPOWER_START;
 73		break;
 74
 75	case WLAN_CMD_CHANGE_ANTENNA:
 76		priv->command_state = WLAN_CMD_CHANGE_ANTENNA_START;
 77		break;
 78
 79	default:
 80		break;
 81	}
 82
 83	vnt_cmd_timer_wait(priv, 0);
 84
 85	return true;
 86}
 87
 88void vnt_run_command(struct work_struct *work)
 89{
 90	struct vnt_private *priv =
 91		container_of(work, struct vnt_private, run_command_work.work);
 92
 93	if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
 94		return;
 95
 96	if (!priv->cmd_running)
 97		return;
 98
 99	switch (priv->command_state) {
100	case WLAN_CMD_INIT_MAC80211_START:
101		if (priv->mac_hw)
102			break;
103
104		dev_info(&priv->usb->dev, "Starting mac80211\n");
105
106		if (vnt_init(priv)) {
107			/* If fail all ends TODO retry */
108			dev_err(&priv->usb->dev, "failed to start\n");
109			usb_set_intfdata(priv->intf, NULL);
110			ieee80211_free_hw(priv->hw);
111			return;
112		}
113
114		break;
115
116	case WLAN_CMD_TBTT_WAKEUP_START:
117		vnt_next_tbtt_wakeup(priv);
118		break;
119
120	case WLAN_CMD_BECON_SEND_START:
121		if (!priv->vif)
122			break;
123
124		vnt_beacon_make(priv, priv->vif);
125
126		vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
127
128		break;
129
130	case WLAN_CMD_SETPOWER_START:
131
132		vnt_rf_setpower(priv, priv->hw->conf.chandef.chan);
 
133
134		break;
135
136	case WLAN_CMD_CHANGE_ANTENNA_START:
137		dev_dbg(&priv->usb->dev, "Change from Antenna%d to",
138			priv->rx_antenna_sel);
139
140		if (priv->rx_antenna_sel == 0) {
141			priv->rx_antenna_sel = 1;
142			if (priv->tx_rx_ant_inv)
143				vnt_set_antenna_mode(priv, ANT_RXA);
144			else
145				vnt_set_antenna_mode(priv, ANT_RXB);
146		} else {
147			priv->rx_antenna_sel = 0;
148			if (priv->tx_rx_ant_inv)
149				vnt_set_antenna_mode(priv, ANT_RXB);
150			else
151				vnt_set_antenna_mode(priv, ANT_RXA);
152		}
153		break;
154
155	default:
156		break;
157	}
158
159	vnt_cmd_complete(priv);
160}
161
162int vnt_schedule_command(struct vnt_private *priv, enum vnt_cmd command)
163{
164	if (priv->free_cmd_queue == 0)
165		return false;
166
167	priv->cmd_queue[priv->cmd_enqueue_idx] = command;
168
169	priv->cmd_enqueue_idx = add_one_with_wrap_around(priv->cmd_enqueue_idx, CMD_Q_SIZE);
170	priv->free_cmd_queue--;
171
172	if (!priv->cmd_running)
173		vnt_cmd_complete(priv);
174
175	return true;
176}
177
178void vnt_reset_command_timer(struct vnt_private *priv)
179{
180	priv->free_cmd_queue = CMD_Q_SIZE;
181	priv->cmd_dequeue_idx = 0;
182	priv->cmd_enqueue_idx = 0;
183	priv->command_state = WLAN_CMD_IDLE;
184	priv->cmd_running = false;
185}
v5.4
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  4 * All rights reserved.
  5 *
  6 * File: wcmd.c
  7 *
  8 * Purpose: Handles the management command interface functions
  9 *
 10 * Author: Lyndon Chen
 11 *
 12 * Date: May 8, 2003
 13 *
 14 * Functions:
 15 *	vnt_cmd_complete - Command Complete function
 16 *	vnt_schedule_command - Push Command and wait Command Scheduler to do
 17 *	vnt_cmd_timer_wait- Call back timer
 18 *
 19 * Revision History:
 20 *
 21 */
 22
 23#include "device.h"
 24#include "mac.h"
 25#include "wcmd.h"
 26#include "power.h"
 27#include "usbpipe.h"
 28#include "rxtx.h"
 29#include "rf.h"
 30
 31static void vnt_cmd_timer_wait(struct vnt_private *priv, unsigned long msecs)
 32{
 33	schedule_delayed_work(&priv->run_command_work, msecs_to_jiffies(msecs));
 34}
 35
 
 
 
 
 
 
 
 
 
 36static int vnt_cmd_complete(struct vnt_private *priv)
 37{
 38	priv->command_state = WLAN_CMD_IDLE;
 39	if (priv->free_cmd_queue == CMD_Q_SIZE) {
 40		/* Command Queue Empty */
 41		priv->cmd_running = false;
 42		return true;
 43	}
 44
 45	priv->command = priv->cmd_queue[priv->cmd_dequeue_idx];
 46
 47	ADD_ONE_WITH_WRAP_AROUND(priv->cmd_dequeue_idx, CMD_Q_SIZE);
 48	priv->free_cmd_queue++;
 49	priv->cmd_running = true;
 50
 51	switch (priv->command) {
 52	case WLAN_CMD_INIT_MAC80211:
 53		priv->command_state = WLAN_CMD_INIT_MAC80211_START;
 54		break;
 55
 56	case WLAN_CMD_TBTT_WAKEUP:
 57		priv->command_state = WLAN_CMD_TBTT_WAKEUP_START;
 58		break;
 59
 60	case WLAN_CMD_BECON_SEND:
 61		priv->command_state = WLAN_CMD_BECON_SEND_START;
 62		break;
 63
 64	case WLAN_CMD_SETPOWER:
 65		priv->command_state = WLAN_CMD_SETPOWER_START;
 66		break;
 67
 68	case WLAN_CMD_CHANGE_ANTENNA:
 69		priv->command_state = WLAN_CMD_CHANGE_ANTENNA_START;
 70		break;
 71
 72	default:
 73		break;
 74	}
 75
 76	vnt_cmd_timer_wait(priv, 0);
 77
 78	return true;
 79}
 80
 81void vnt_run_command(struct work_struct *work)
 82{
 83	struct vnt_private *priv =
 84		container_of(work, struct vnt_private, run_command_work.work);
 85
 86	if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
 87		return;
 88
 89	if (!priv->cmd_running)
 90		return;
 91
 92	switch (priv->command_state) {
 93	case WLAN_CMD_INIT_MAC80211_START:
 94		if (priv->mac_hw)
 95			break;
 96
 97		dev_info(&priv->usb->dev, "Starting mac80211\n");
 98
 99		if (vnt_init(priv)) {
100			/* If fail all ends TODO retry */
101			dev_err(&priv->usb->dev, "failed to start\n");
 
102			ieee80211_free_hw(priv->hw);
103			return;
104		}
105
106		break;
107
108	case WLAN_CMD_TBTT_WAKEUP_START:
109		vnt_next_tbtt_wakeup(priv);
110		break;
111
112	case WLAN_CMD_BECON_SEND_START:
113		if (!priv->vif)
114			break;
115
116		vnt_beacon_make(priv, priv->vif);
117
118		vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
119
120		break;
121
122	case WLAN_CMD_SETPOWER_START:
123
124		vnt_rf_setpower(priv, priv->current_rate,
125				priv->hw->conf.chandef.chan->hw_value);
126
127		break;
128
129	case WLAN_CMD_CHANGE_ANTENNA_START:
130		dev_dbg(&priv->usb->dev, "Change from Antenna%d to",
131			priv->rx_antenna_sel);
132
133		if (priv->rx_antenna_sel == 0) {
134			priv->rx_antenna_sel = 1;
135			if (priv->tx_rx_ant_inv)
136				vnt_set_antenna_mode(priv, ANT_RXA);
137			else
138				vnt_set_antenna_mode(priv, ANT_RXB);
139		} else {
140			priv->rx_antenna_sel = 0;
141			if (priv->tx_rx_ant_inv)
142				vnt_set_antenna_mode(priv, ANT_RXB);
143			else
144				vnt_set_antenna_mode(priv, ANT_RXA);
145		}
146		break;
147
148	default:
149		break;
150	}
151
152	vnt_cmd_complete(priv);
153}
154
155int vnt_schedule_command(struct vnt_private *priv, enum vnt_cmd command)
156{
157	if (priv->free_cmd_queue == 0)
158		return false;
159
160	priv->cmd_queue[priv->cmd_enqueue_idx] = command;
161
162	ADD_ONE_WITH_WRAP_AROUND(priv->cmd_enqueue_idx, CMD_Q_SIZE);
163	priv->free_cmd_queue--;
164
165	if (!priv->cmd_running)
166		vnt_cmd_complete(priv);
167
168	return true;
169}
170
171void vnt_reset_command_timer(struct vnt_private *priv)
172{
173	priv->free_cmd_queue = CMD_Q_SIZE;
174	priv->cmd_dequeue_idx = 0;
175	priv->cmd_enqueue_idx = 0;
176	priv->command_state = WLAN_CMD_IDLE;
177	priv->cmd_running = false;
178}