carl9170 firmware: import 1.7.0
[carl9170fw.git] / tools / carlu / src / carlu.h
1 /*
2  * carl9170user - userspace testing utility for ar9170 devices
3  *
4  * common API declaration
5  *
6  * Copyright 2009, 2010 Christian Lamparter <chunkeey@googlemail.com>
7  *
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.
12  *
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.
17  *
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.
21  */
22
23 #ifndef __CARL9170USER_H
24 #define __CARL9170USER_H
25
26 #include "SDL.h"
27 #include "SDL_thread.h"
28
29 #include "carlfw.h"
30
31 #include "debug.h"
32 #include "hw.h"
33 #include "fwcmd.h"
34 #include "frame.h"
35 #include "eeprom.h"
36 #include "ieee80211.h"
37 #include "wlan.h"
38
39 struct carlu {
40         SDL_cond *resp_pend;
41         SDL_mutex *resp_lock;
42         uint8_t *resp_buf;
43         size_t resp_len;
44
45         int tx_pending;
46         uint8_t cookie;
47
48         void (*tx_cb)(struct carlu *, struct frame *);
49         void (*tx_fb_cb)(struct carlu *, struct frame *);
50         void (*rx_cb)(struct carlu *, void *, unsigned int);
51         int (*cmd_cb)(struct carlu *, struct carl9170_rsp *,
52                       void *, unsigned int);
53
54         struct carlfw *fw;
55
56         struct ar9170_eeprom eeprom;
57
58         struct frame_queue tx_sent_queue[__AR9170_NUM_TXQ];
59
60         SDL_mutex *mem_lock;
61         unsigned int dma_chunks;
62         unsigned int dma_chunk_size;
63         unsigned int used_dma_chunks;
64
65         unsigned int extra_headroom;
66         bool tx_stream;
67         bool rx_stream;
68
69         /* statistics */
70         unsigned int rxed;
71         unsigned int txed;
72
73         unsigned long tx_octets;
74         unsigned long rx_octets;
75 };
76
77 struct carlu_rate {
78         int8_t rix;
79         int8_t cnt;
80         uint8_t flags;
81 };
82
83 struct carlu_tx_info_tx {
84         unsigned int key;
85 };
86
87 struct carlu_tx_info {
88         uint32_t flags;
89
90         struct carlu_rate rates[CARL9170_TX_MAX_RATES];
91
92         union {
93                 struct carlu_tx_info_tx tx;
94         };
95 };
96
97 static inline struct carlu_tx_info *get_tx_info(struct frame *frame)
98 {
99         return (void *) frame->cb;
100 }
101
102 void *carlu_alloc_driver(size_t size);
103 void carlu_free_driver(struct carlu *ar);
104
105 int carlu_fw_check(struct carlu *ar);
106 void carlu_fw_info(struct carlu *ar);
107
108 void carlu_rx(struct carlu *ar, struct frame *frame);
109 int carlu_tx(struct carlu *ar, struct frame *frame);
110 void carlu_tx_feedback(struct carlu *ar,
111                           struct carl9170_rsp *cmd);
112 void carlu_handle_command(struct carlu *ar, void *buf, size_t len);
113
114 struct frame *carlu_alloc_frame(struct carlu *ar, unsigned int size);
115 void carlu_free_frame(struct carlu *ar, struct frame *frame);
116
117 int carlu_cmd_echo(struct carlu *ar, const uint32_t message);
118 int carlu_cmd_reboot(struct carlu *ar);
119 int carlu_cmd_read_eeprom(struct carlu *ar);
120 int carlu_cmd_mem_dump(struct carlu *ar, const uint32_t start,
121                         const unsigned int len, void *_buf);
122 int carlu_cmd_write_mem(struct carlu *ar, const uint32_t addr,
123                         const uint32_t val);
124
125 #endif /* __CARL9170USER_H */