e04e8da486b44dfac8eafe62374cb4cd595a6831
[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.len = cmd->hdr.len;
41         resp->hdr.cmd = cmd->hdr.cmd;
42         resp->hdr.ext = cmd->hdr.ext;
43         resp->hdr.seq |= cmd->hdr.seq;
44
45         switch (cmd->hdr.cmd & ~CARL9170_CMD_ASYNC_FLAG) {
46         case CARL9170_CMD_RREG:
47                 for (i = 0; i < (cmd->hdr.len / 4); i++)
48                         resp->rreg_res.vals[i] = get(cmd->rreg.regs[i]);
49                 break;
50
51         case CARL9170_CMD_WREG:
52                 resp->hdr.len = 0;
53                 for (i = 0; i < (cmd->hdr.len / 8); i++)
54                         set(cmd->wreg.regs[i].addr, cmd->wreg.regs[i].val);
55                 break;
56
57         case CARL9170_CMD_ECHO:
58                 memcpy(resp->echo.vals, cmd->echo.vals, cmd->hdr.len);
59                 break;
60
61         case CARL9170_CMD_SWRST:
62                 /*
63                  * Command has no payload, so the response
64                  * has no payload either.
65                  * resp->hdr.len = 0;
66                  */
67                 fw.wlan.mac_reset = CARL9170_MAC_RESET_FORCE;
68                 break;
69
70         case CARL9170_CMD_REBOOT:
71                 /*
72                  * resp->len = 0;
73                  */
74                 fw.reboot = 1;
75                 break;
76
77         case CARL9170_CMD_READ_TSF:
78                 resp->hdr.len = 8;
79                 read_tsf((uint32_t *)resp->tsf.tsf);
80                 break;
81
82 #ifdef CONFIG_CARL9170FW_CAB_QUEUE
83         case CARL9170_CMD_FLUSH_CAB:
84                 resp->hdr.len = 0;
85                 fw.wlan.cab_flush_trigger = CARL9170_CAB_TRIGGER_ARMED;
86                 fw.wlan.cab_flush_time = get_clock_counter() +
87                                          CARL9170_TBTT_DELTA;
88                 break;
89 #endif /* CONFIG_CARL9170FW_CAB_QUEUE */
90
91 #ifdef CONFIG_CARL9170FW_SECURITY_ENGINE
92         case CARL9170_CMD_EKEY:
93                 resp->hdr.len = 1;
94                 set_key(&cmd->setkey);
95                 break;
96
97         case CARL9170_CMD_DKEY:
98                 /* Disable Key */
99                 resp->hdr.len = 1;
100                 disable_key(&cmd->disablekey);
101                 break;
102 #endif /* CONFIG_CARL9170FW_SECURIT_ENGINE */
103
104 #ifdef CONFIG_CARL9170FW_RADIO_FUNCTIONS
105         case CARL9170_CMD_FREQUENCY:
106         case CARL9170_CMD_RF_INIT:
107                 rf_cmd(cmd, resp);
108                 break;
109
110         case CARL9170_CMD_FREQ_START:
111                 /*
112                  * resp->hdr.len = 0;
113                  */
114                 rf_notify_set_channel();
115                 break;
116
117 # ifdef CONFIG_CARL9170FW_PSM
118         case CARL9170_CMD_PSM:
119                 resp->hdr.len = 0;
120                 fw.phy.psm.state = le32_to_cpu(cmd->psm.state);
121                 rf_psm();
122                 break;
123 # endif /* CONFIG_CARL9170FW_PSM */
124 #endif /* CONFIG_CARL9170FW_RADIO_FUNCTIOS */
125
126         default:
127                 break;
128         }
129 }