2 * carl9170user - userspace testing utility for ar9170 devices
4 * register/memory/command access functions
6 * Copyright 2009, 2010 Christian Lamparter <chunkeey@googlemail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifndef __CARL9170USER_CMD_H
24 #define __CARL9170USER_CMD_H
28 int carlu_cmd_echo(struct carlu *ar, const uint32_t message);
29 int carlu_cmd_reboot(struct carlu *ar);
30 int carlu_cmd_read_eeprom(struct carlu *ar);
31 int carlu_cmd_mem_dump(struct carlu *ar, const uint32_t start,
32 const unsigned int len, void *_buf);
33 int carlu_cmd_write_mem(struct carlu *ar, const uint32_t addr,
36 struct carl9170_cmd *carlu_cmd_buf(struct carlu *ar,
37 const enum carl9170_cmd_oids cmd, const unsigned int len);
39 #define PAYLOAD_MAX (CARL9170_MAX_CMD_LEN / 4 - 1)
41 * Macros to facilitate writing multiple registers in a single
42 * write-combining USB command. Note that when the first group
43 * fails the whole thing will fail without any others attempted,
44 * but you won't know which write in the group failed.
46 #define carlu_regwrite_begin(ar) \
48 struct carlu *__ar = ar; \
49 unsigned int __nreg = 0; \
53 #define carlu_regwrite_flush() \
55 __err = carlusb_cmd(__ar, CARL9170_CMD_WREG, \
56 (u8 *)&__ar->cmd.cmd.data, 8 * __nreg, \
57 (u8 *)&__dummy, sizeof(__dummy)); \
60 goto __regwrite_out; \
63 #define carlu_regwrite(r, v) do { \
64 __ar->cmd.buf4[2 * __nreg + 1] = cpu_to_le32(r); \
65 __ar->cmd.buf4[2 * __nreg + 2] = cpu_to_le32(v); \
67 if ((__nreg >= PAYLOAD_MAX / 2)) { \
68 __err = carlusb_cmd(__ar, CARL9170_CMD_WREG, \
69 (u8 *)&__ar->cmd.cmd.data, 8 * __nreg, \
70 (u8 *)&__dummy, sizeof(__dummy)); \
74 goto __regwrite_out; \
78 #define carlu_regwrite_finish() \
80 if (__err == 0 && __nreg) \
81 carlu_regwrite_flush();
83 #define carlu_regwrite_result() \
88 #define carlu_async_get_buf() \
90 __cmd = carlu_cmd_buf(__carl, CARL9170_CMD_WREG_ASYNC, \
91 CARL9170_MAX_CMD_PAYLOAD_LEN); \
92 if (IS_ERR_OR_NULL(__cmd)) { \
93 __err = __cmd ? PTR_ERR(__cmd) : -ENOMEM; \
94 goto __async_regwrite_out; \
98 #define carlu_async_regwrite_begin(carl) \
100 int __nreg = 0, __err = 0; \
101 struct carlu *__carl = carl; \
102 struct carl9170_cmd *__cmd; \
103 carlu_async_get_buf(); \
105 #define carlu_async_regwrite_flush() \
107 __cmd->hdr.len = 8 * __nreg; \
108 __err = carlusb_cmd_async(__carl, __cmd, true); \
111 goto __async_regwrite_out; \
113 carlu_async_get_buf(); \
116 #define carlu_async_regwrite(r, v) do { \
117 __cmd->wreg.regs[__nreg].addr = cpu_to_le32(r); \
118 __cmd->wreg.regs[__nreg].val = cpu_to_le32(v); \
120 if ((__nreg >= PAYLOAD_MAX / 2)) \
121 carlu_async_regwrite_flush(); \
124 #define carlu_async_regwrite_finish() \
125 __async_regwrite_out : \
126 if (__err == 0 && __nreg) \
127 carlu_async_regwrite_flush();
129 #define carlu_async_regwrite_result() \
133 #endif /* __CARL9170USER_CMD_H */