00e1467b935c76f650f2cbaa7b4446e5bc755351
[carl9170fw.git] / tools / carlu / src / usb.h
1 /*
2  * carl9170user - userspace testing utility for ar9170 devices
3  *
4  * USB back-end 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_USB_H
24 #define __CARL9170USER_USB_H
25
26 #include "SDL.h"
27 #include "SDL_thread.h"
28 #include "libusb.h"
29 #include "frame.h"
30 #include "list.h"
31
32 #include "fwcmd.h"
33 #include <unistd.h>
34
35 #define AR9170_RX_BULK_BUFS             16
36 #define AR9170_RX_BULK_BUF_SIZE         8192
37 #define AR9170_RX_BULK_IRQ_SIZE         64
38
39 /* endpoints */
40 #define AR9170_EP_TX                            (LIBUSB_ENDPOINT_OUT | AR9170_USB_EP_TX)
41 #define AR9170_EP_RX                            (LIBUSB_ENDPOINT_IN  | AR9170_USB_EP_RX)
42 #define AR9170_EP_IRQ                           (LIBUSB_ENDPOINT_IN  | AR9170_USB_EP_IRQ)
43 #define AR9170_EP_CMD                           (LIBUSB_ENDPOINT_OUT | AR9170_USB_EP_CMD)
44
45 #define AR9170_TX_MAX_ACTIVE_URBS               8
46
47 #define CARL9170_FIRMWARE_FILE "/lib/firmware/carl9170-1"
48 void carlusb_reset_txep(struct carlu *ar);
49
50 struct carlusb {
51         struct carlu common;
52         libusb_device_handle *dev;
53         libusb_context *ctx;
54
55         SDL_Thread *event_thread;
56         bool stop_event_polling;
57
58         struct libusb_transfer *rx_ring[AR9170_RX_BULK_BUFS];
59
60         struct libusb_transfer *rx_interrupt;
61         unsigned char irq_buf[AR9170_RX_BULK_IRQ_SIZE];
62
63         union {
64                 unsigned char buf[CARL9170_MAX_CMD_LEN];
65                 struct carl9170_cmd cmd;
66                 struct carl9170_rsp rsp;
67         } cmd;
68
69         struct list_head tx_queue;
70         SDL_mutex *tx_queue_lock;
71         unsigned int tx_queue_len;
72
73         struct list_head dev_list;
74         unsigned int idx;
75
76         unsigned int miniboot_size;
77         unsigned int rx_max;
78
79         int event_pipe[2];
80 };
81
82 int usb_init(void);
83 void usb_exit(void);
84
85 struct carlu *carlusb_probe(void);
86 void carlusb_close(struct carlu *ar);
87
88 void carlusb_tx(struct carlu *ar, struct frame *frame);
89 int carlusb_fw_check(struct carlusb *ar);
90
91 int carlusb_cmd(struct carlu *_ar, uint8_t oid, uint8_t *cmd, size_t clen,
92                 uint8_t *rsp, size_t rlen);
93
94 int carlusb_print_known_devices(void);
95
96 #endif /* __CARL9170USER_USB_H */