]> bbs.cooldavid.org Git - net-next-2.6.git/blob - drivers/net/wireless/ath/carl9170/cmd.h
0fc83d2336fdcc602e546b6839391a6b4bbe7a2a
[net-next-2.6.git] / drivers / net / wireless / ath / carl9170 / cmd.h
1 /*
2  * Atheros CARL9170 driver
3  *
4  * Basic HW register/memory/command access functions
5  *
6  * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7  * Copyright 2010, Christian Lamparter <chunkeey@googlemail.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; see the file COPYING.  If not, see
21  * http://www.gnu.org/licenses/.
22  *
23  * This file incorporates work covered by the following copyright and
24  * permission notice:
25  *    Copyright (c) 2007-2008 Atheros Communications, Inc.
26  *
27  *    Permission to use, copy, modify, and/or distribute this software for any
28  *    purpose with or without fee is hereby granted, provided that the above
29  *    copyright notice and this permission notice appear in all copies.
30  *
31  *    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
32  *    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
33  *    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
34  *    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
35  *    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
36  *    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
37  *    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
38  */
39 #ifndef __CMD_H
40 #define __CMD_H
41
42 #include "carl9170.h"
43
44 /* basic HW access */
45 int carl9170_write_reg(struct ar9170 *ar, const u32 reg, const u32 val);
46 int carl9170_read_reg(struct ar9170 *ar, const u32 reg, u32 *val);
47 int carl9170_read_mreg(struct ar9170 *ar, const int nregs,
48                        const u32 *regs, u32 *out);
49 int carl9170_echo_test(struct ar9170 *ar, u32 v);
50 int carl9170_reboot(struct ar9170 *ar);
51 int carl9170_mac_reset(struct ar9170 *ar);
52 int carl9170_powersave(struct ar9170 *ar, const bool power_on);
53 int carl9170_bcn_ctrl(struct ar9170 *ar, const unsigned int vif_id,
54                        const u32 mode, const u32 addr, const u32 len);
55
56 static inline int carl9170_flush_cab(struct ar9170 *ar,
57                                      const unsigned int vif_id)
58 {
59         return carl9170_bcn_ctrl(ar, vif_id, CARL9170_BCN_CTRL_DRAIN, 0, 0);
60 }
61
62 struct carl9170_cmd *carl9170_cmd_buf(struct ar9170 *ar,
63         const enum carl9170_cmd_oids cmd, const unsigned int len);
64
65 /*
66  * Macros to facilitate writing multiple registers in a single
67  * write-combining USB command. Note that when the first group
68  * fails the whole thing will fail without any others attempted,
69  * but you won't know which write in the group failed.
70  */
71 #define carl9170_regwrite_begin(ar)                                     \
72 do {                                                                    \
73         int __nreg = 0, __err = 0;                                      \
74         struct ar9170 *__ar = ar;
75
76 #define carl9170_regwrite(r, v) do {                                    \
77         __ar->cmd_buf[2 * __nreg + 1] = cpu_to_le32(r);                 \
78         __ar->cmd_buf[2 * __nreg + 2] = cpu_to_le32(v);                 \
79         __nreg++;                                                       \
80         if ((__nreg >= PAYLOAD_MAX/2)) {                                \
81                 if (IS_ACCEPTING_CMD(__ar))                             \
82                         __err = carl9170_exec_cmd(__ar,                 \
83                                 CARL9170_CMD_WREG, 8 * __nreg,          \
84                                 (u8 *) &__ar->cmd_buf[1], 0, NULL);     \
85                 else                                                    \
86                         goto __regwrite_out;                            \
87                                                                         \
88                 __nreg = 0;                                             \
89                 if (__err)                                              \
90                         goto __regwrite_out;                            \
91         }                                                               \
92 } while (0)
93
94 #define carl9170_regwrite_finish()                                      \
95 __regwrite_out :                                                        \
96         if (__err == 0 && __nreg) {                                     \
97                 if (IS_ACCEPTING_CMD(__ar))                             \
98                         __err = carl9170_exec_cmd(__ar,                 \
99                                 CARL9170_CMD_WREG, 8 * __nreg,          \
100                                 (u8 *) &__ar->cmd_buf[1], 0, NULL);     \
101                 __nreg = 0;                                             \
102         }
103
104 #define carl9170_regwrite_result()                                      \
105         __err;                                                          \
106 } while (0);
107
108
109 #define carl9170_async_get_buf()                                        \
110 do {                                                                    \
111         __cmd = carl9170_cmd_buf(__carl, CARL9170_CMD_WREG_ASYNC,       \
112                                  CARL9170_MAX_CMD_PAYLOAD_LEN);         \
113         if (__cmd == NULL) {                                            \
114                 __err = -ENOMEM;                                        \
115                 goto __async_regwrite_out;                              \
116         }                                                               \
117 } while (0);
118
119 #define carl9170_async_regwrite_begin(carl)                             \
120 do {                                                                    \
121         int __nreg = 0, __err = 0;                                      \
122         struct ar9170 *__carl = carl;                                   \
123         struct carl9170_cmd *__cmd;                                     \
124         carl9170_async_get_buf();                                       \
125
126 #define carl9170_async_regwrite(r, v) do {                              \
127         __cmd->wreg.regs[__nreg].addr = cpu_to_le32(r);                 \
128         __cmd->wreg.regs[__nreg].val = cpu_to_le32(v);                  \
129         __nreg++;                                                       \
130         if ((__nreg >= PAYLOAD_MAX/2)) {                                \
131                 if (IS_ACCEPTING_CMD(__carl)) {                         \
132                         __cmd->hdr.len = 8 * __nreg;                    \
133                         __err = __carl9170_exec_cmd(__carl, __cmd, true);\
134                         __cmd = NULL;                                   \
135                         carl9170_async_get_buf();                       \
136                 } else {                                                \
137                         goto __async_regwrite_out;                      \
138                 }                                                       \
139                 __nreg = 0;                                             \
140                 if (__err)                                              \
141                         goto __async_regwrite_out;                      \
142         }                                                               \
143 } while (0)
144
145 #define carl9170_async_regwrite_finish()                                \
146 __async_regwrite_out :                                                  \
147         if (__err == 0 && __nreg) {                                     \
148                 __cmd->hdr.len = 8 * __nreg;                            \
149                 if (IS_ACCEPTING_CMD(__carl))                           \
150                         __err = __carl9170_exec_cmd(__carl, __cmd, true);\
151                 __nreg = 0;                                             \
152         }
153
154 #define carl9170_async_regwrite_result()                                \
155         __err;                                                          \
156 } while (0);
157
158 #endif /* __CMD_H */