carl9170 firmware: import 1.7.0
[carl9170fw.git] / carlfw / src / cmd.c
1 /*
2  * carl9170 firmware - used by the ar9170 wireless device
3  *
4  * Code to handle commands from the host driver.
5  *
6  * Copyright (c) 2000-2005 ZyDAS Technology Corporation
7  * Copyright (c) 2007-2009 Atheros Communications, Inc.
8  * Copyright    2009    Johannes Berg <johannes@sipsolutions.net>
9  * Copyright 2009, 2010 Christian Lamparter <chunkeey@googlemail.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #include "carl9170.h"
27 #include "io.h"
28 #include "cam.h"
29 #include "rf.h"
30 #include "printf.h"
31 #include "timer.h"
32 #include "wl.h"
33
34 void handle_cmd(struct carl9170_rsp *resp)
35 {
36         struct carl9170_cmd *cmd = &dma_mem.reserved.cmd.cmd;
37         unsigned int i;
38
39         /* copies cmd, len and extra fields */
40         resp->hdr.hdr_data = cmd->hdr.hdr_data;
41
42         switch (cmd->hdr.cmd) {
43         case CARL9170_CMD_RREG:
44                 for (i = 0; i < (cmd->hdr.len / 4); i++)
45                         resp->rreg_res.vals[i] = get(cmd->rreg.regs[i]);
46                 break;
47
48         case CARL9170_CMD_WREG:
49                 resp->hdr.len = 0;
50                 for (i = 0; i < (cmd->hdr.len / 8); i++)
51                         set(cmd->wreg.regs[i].addr, cmd->wreg.regs[i].val);
52                 break;
53
54         case CARL9170_CMD_ECHO:
55                 memcpy(resp->echo.vals, cmd->echo.vals, cmd->hdr.len);
56                 break;
57
58         case CARL9170_CMD_SWRST:
59                 resp->hdr.len = 0;
60                 fw.wlan.mac_reset = CARL9170_MAC_RESET_FORCE;
61                 break;
62
63         case CARL9170_CMD_REBOOT:
64                 /*
65                  * reboot does not return and generates no response
66                  * resp->len = 0;
67                  */
68
69                 reboot();
70                 break;
71
72         case CARL9170_CMD_READ_TSF:
73                 resp->hdr.len = 8;
74                 read_tsf((uint32_t *)resp->tsf.tsf);
75                 break;
76
77 #ifdef CONFIG_CARL9170FW_CAB_QUEUE
78         case CARL9170_CMD_FLUSH_CAB:
79                 resp->hdr.len = 0;
80                 fw.wlan.cab_flush_trigger = CARL9170_CAB_TRIGGER_ARMED;
81                 fw.wlan.cab_flush_time = get_clock_counter() +
82                                          CARL9170_TBTT_DELTA;
83                 break;
84 #endif /* CONFIG_CARL9170FW_CAB_QUEUE */
85
86 #ifdef CONFIG_CARL9170FW_SECURITY_ENGINE
87         case CARL9170_CMD_EKEY:
88                 resp->hdr.len = 1;
89                 set_key(&cmd->setkey);
90                 break;
91
92         case CARL9170_CMD_DKEY:
93                 /* Disable Key */
94                 resp->hdr.len = 1;
95                 disable_key(&cmd->disablekey);
96                 break;
97 #endif /* CONFIG_CARL9170FW_SECURIT_ENGINE */
98
99 #ifdef CONFIG_CARL9170FW_RADIO_FUNCTIONS
100         case CARL9170_CMD_FREQUENCY:
101         case CARL9170_CMD_RF_INIT:
102                 rf_cmd(cmd, resp);
103                 break;
104
105         case CARL9170_CMD_FREQ_START:
106                 resp->hdr.len = 0;
107                 rf_notify_set_channel();
108                 break;
109
110 # ifdef CONFIG_CARL9170FW_PSM
111         case CARL9170_CMD_PSM:
112                 resp->hdr.len = 0;
113                 fw.phy.psm.state = le32_to_cpu(cmd->psm.state);
114                 rf_psm();
115                 break;
116 # endif /* CONFIG_CARL9170FW_PSM */
117 #endif /* CONFIG_CARL9170FW_RADIO_FUNCTIOS */
118
119 #ifdef CONFIG_CARL9170FW_USB_WATCHDOG
120         case CARL9170_CMD_USB_WD:
121                 resp->hdr.len = 4;
122                 fw.usb.watchdog.state = le32_to_cpu(cmd->watchdog.state);
123                 break;
124
125 #endif /* CONFIG_CARL9170FW_USB_WATCHDOG */
126
127         default:
128                 break;
129         }
130 }