1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
8 * Purpose: Handles the management command interface 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
31 static void vnt_cmd_timer_wait(struct vnt_private
*priv
, unsigned long msecs
)
33 schedule_delayed_work(&priv
->run_command_work
, msecs_to_jiffies(msecs
));
36 static int vnt_cmd_complete(struct vnt_private
*priv
)
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;
45 priv
->command
= priv
->cmd_queue
[priv
->cmd_dequeue_idx
];
47 ADD_ONE_WITH_WRAP_AROUND(priv
->cmd_dequeue_idx
, CMD_Q_SIZE
);
48 priv
->free_cmd_queue
++;
49 priv
->cmd_running
= true;
51 switch (priv
->command
) {
52 case WLAN_CMD_INIT_MAC80211
:
53 priv
->command_state
= WLAN_CMD_INIT_MAC80211_START
;
56 case WLAN_CMD_TBTT_WAKEUP
:
57 priv
->command_state
= WLAN_CMD_TBTT_WAKEUP_START
;
60 case WLAN_CMD_BECON_SEND
:
61 priv
->command_state
= WLAN_CMD_BECON_SEND_START
;
64 case WLAN_CMD_SETPOWER
:
65 priv
->command_state
= WLAN_CMD_SETPOWER_START
;
68 case WLAN_CMD_CHANGE_ANTENNA
:
69 priv
->command_state
= WLAN_CMD_CHANGE_ANTENNA_START
;
76 vnt_cmd_timer_wait(priv
, 0);
81 void vnt_run_command(struct work_struct
*work
)
83 struct vnt_private
*priv
=
84 container_of(work
, struct vnt_private
, run_command_work
.work
);
86 if (test_bit(DEVICE_FLAGS_DISCONNECTED
, &priv
->flags
))
89 if (!priv
->cmd_running
)
92 switch (priv
->command_state
) {
93 case WLAN_CMD_INIT_MAC80211_START
:
97 dev_info(&priv
->usb
->dev
, "Starting mac80211\n");
100 /* If fail all ends TODO retry */
101 dev_err(&priv
->usb
->dev
, "failed to start\n");
102 usb_set_intfdata(priv
->intf
, NULL
);
103 ieee80211_free_hw(priv
->hw
);
109 case WLAN_CMD_TBTT_WAKEUP_START
:
110 vnt_next_tbtt_wakeup(priv
);
113 case WLAN_CMD_BECON_SEND_START
:
117 vnt_beacon_make(priv
, priv
->vif
);
119 vnt_mac_reg_bits_on(priv
, MAC_REG_TCR
, TCR_AUTOBCNTX
);
123 case WLAN_CMD_SETPOWER_START
:
125 vnt_rf_setpower(priv
, priv
->hw
->conf
.chandef
.chan
);
129 case WLAN_CMD_CHANGE_ANTENNA_START
:
130 dev_dbg(&priv
->usb
->dev
, "Change from Antenna%d to",
131 priv
->rx_antenna_sel
);
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
);
138 vnt_set_antenna_mode(priv
, ANT_RXB
);
140 priv
->rx_antenna_sel
= 0;
141 if (priv
->tx_rx_ant_inv
)
142 vnt_set_antenna_mode(priv
, ANT_RXB
);
144 vnt_set_antenna_mode(priv
, ANT_RXA
);
152 vnt_cmd_complete(priv
);
155 int vnt_schedule_command(struct vnt_private
*priv
, enum vnt_cmd command
)
157 if (priv
->free_cmd_queue
== 0)
160 priv
->cmd_queue
[priv
->cmd_enqueue_idx
] = command
;
162 ADD_ONE_WITH_WRAP_AROUND(priv
->cmd_enqueue_idx
, CMD_Q_SIZE
);
163 priv
->free_cmd_queue
--;
165 if (!priv
->cmd_running
)
166 vnt_cmd_complete(priv
);
171 void vnt_reset_command_timer(struct vnt_private
*priv
)
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;