2 * carl9170user - userspace testing utility for ar9170 devices
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.
44 err("This is an error.\n");
45 warn("This is a warnig.\n");
46 info("This is an informative message.\n");
47 dbg("This is just utter useless babble.\n");
50 void carlu_frame_test(struct carlu *ar)
54 frame = carlu_alloc_frame(ar, 0x40);
55 frame_reserve(frame, 0x10);
57 memset(frame_put(frame, 0x10), 0x11, 0x10);
58 memset(frame_put(frame, 0x10), 0x22, 0x10);
59 memset(frame_push(frame, 0x10), 0x33, 0x10);
60 memset(frame_put(frame, 0x10), 0x44, 0x10);
62 print_hex_dump_bytes(INFO, "DATA:", frame->data, frame->len);
64 print_hex_dump_bytes(INFO, "PAYLOAD:", frame->payload, frame->alloced);
69 static void carlu_loopback_tx_cb(struct carlu *ar __unused,
70 struct frame *frame __unused)
74 static int carlu_loopback_cmd(struct carlu *ar __unused,
75 struct carl9170_rsp *cmd, void *buf __unused,
76 unsigned int len __unused)
80 switch (cmd->hdr.cmd) {
81 case CARL9170_RSP_TXCOMP:
83 dbg("received tx feedback (%d).\n", n);
85 for (i = 0; i < n; i++) {
86 dbg("cookie:%x success:%d rix:%d tries:%d queue:%d\n",
87 cmd->tx_status[i].cookie,
88 cmd->tx_status[i].success,
89 cmd->tx_status[i].rix,
90 cmd->tx_status[i].tries,
91 cmd->tx_status[i].queue);
100 static void carlu_loopback_rx(struct carlu *ar,
101 void *buf __unused, unsigned int len)
104 ar->rx_octets += len;
107 static void carlu_loopback_mark_tx_frames(struct frame *frame)
111 for (i = 0; i < frame->len; i++)
112 frame->data[i] = (uint8_t) i;
115 void carlu_loopback_test(struct carlu *ar, const unsigned int total_runs,
116 const unsigned int interval, const unsigned int min_len, const unsigned int max_len)
119 uint32_t start_time, total_time = 0;
120 float moctets, dtime;
121 unsigned int runs = 0, i = 0, j = 0, len;
124 if (min_len > max_len) {
125 err("stresstest: invalid parameters => min_len:%d > max_len:%d",
131 err("stresstest: invalid parameters => min_len is smaller than 4");
136 frame = carlu_alloc_frame(ar, len);
137 frame_put(frame, len);
139 carlu_loopback_mark_tx_frames(frame);
141 ar->rx_cb = carlu_loopback_rx;
142 ar->cmd_cb = carlu_loopback_cmd;
143 ar->tx_cb = carlu_loopback_tx_cb;
145 start_time = SDL_GetTicks();
146 while (runs <= total_runs) {
147 if (frame && carlu_tx(ar, frame) == 0) {
156 frame = carlu_alloc_frame(ar, len);
157 frame_put(frame, len);
159 carlu_loopback_mark_tx_frames(frame);
162 total_time = SDL_GetTicks() - start_time;
164 if (total_time >= interval) {
165 moctets = ((float)ar->tx_octets) / (1024.0f * 1024.0f);
166 dtime = ((float)total_time) / 1000;
167 info("%d: tx %d of %d => %.2f MiB in %.2f secs => %.4f MBits/s\n",
168 runs, i, j, moctets, dtime, (moctets * 8.0f) / dtime);
170 moctets = ((float)ar->rx_octets) / (1024.0f * 1024.0f);
171 info("%d: rx %d of %d => %.2f MiB in %.2f secs => %.4f MBits/s\n",
172 runs, ar->rxed, i, moctets, dtime, (moctets * 8.0f) / dtime);
174 if ((ar->rxed == 0 && i) || !i) {
175 ret = carlu_cmd_echo(ar, 0xdeadbeef);
177 warn("firmware crashed... echo_cmd: (%d)\n", ret);
188 start_time = SDL_GetTicks();
197 int carlu_gpio_test(struct carlu *ar)
208 CHK(carlu_cmd_read_mem(ar, AR9170_GPIO_REG_PORT_DATA, &gpio));
209 info("GPIO state:%x\n", gpio);
211 /* turn both LEDs on */
212 CHK(carlu_cmd_write_mem(ar, AR9170_GPIO_REG_PORT_DATA,
213 AR9170_GPIO_PORT_LED_0 | AR9170_GPIO_PORT_LED_1));
217 CHK(carlu_cmd_read_mem(ar, AR9170_GPIO_REG_PORT_DATA, &gpio));
218 info("GPIO state:%x\n", gpio);
220 /* turn LEDs off everything */
221 CHK(carlu_cmd_write_mem(ar, AR9170_GPIO_REG_PORT_DATA, 0));
223 CHK(carlu_cmd_read_mem(ar, AR9170_GPIO_REG_PORT_DATA, &gpio));
224 info("GPIO state:%x\n", gpio);