162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright (c) 2010-2011 Atheros Communications Inc.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any
562306a36Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above
662306a36Sopenharmony_ci * copyright notice and this permission notice appear in all copies.
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
962306a36Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1062306a36Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1162306a36Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1262306a36Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1362306a36Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1462306a36Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1562306a36Sopenharmony_ci */
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#ifndef HTC_USB_H
1862306a36Sopenharmony_ci#define HTC_USB_H
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/* old firmware images */
2162306a36Sopenharmony_ci#define FIRMWARE_AR7010_1_1     "htc_7010.fw"
2262306a36Sopenharmony_ci#define FIRMWARE_AR9271         "htc_9271.fw"
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci/* supported Major FW version */
2562306a36Sopenharmony_ci#define MAJOR_VERSION_REQ 1
2662306a36Sopenharmony_ci#define MINOR_VERSION_REQ 3
2762306a36Sopenharmony_ci/* minimal and maximal supported Minor FW version. */
2862306a36Sopenharmony_ci#define FIRMWARE_MINOR_IDX_MAX  4
2962306a36Sopenharmony_ci#define FIRMWARE_MINOR_IDX_MIN  3
3062306a36Sopenharmony_ci#define HTC_FW_PATH	"ath9k_htc"
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define HTC_9271_MODULE_FW  HTC_FW_PATH "/htc_9271-" \
3362306a36Sopenharmony_ci			__stringify(MAJOR_VERSION_REQ) \
3462306a36Sopenharmony_ci			"." __stringify(FIRMWARE_MINOR_IDX_MAX) ".0.fw"
3562306a36Sopenharmony_ci#define HTC_7010_MODULE_FW  HTC_FW_PATH "/htc_7010-" \
3662306a36Sopenharmony_ci			__stringify(MAJOR_VERSION_REQ) \
3762306a36Sopenharmony_ci			"." __stringify(FIRMWARE_MINOR_IDX_MAX) ".0.fw"
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ciextern int htc_use_dev_fw;
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#define IS_AR7010_DEVICE(_v) (((_v) == AR9280_USB) || ((_v) == AR9287_USB))
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci#define AR9271_FIRMWARE       0x501000
4462306a36Sopenharmony_ci#define AR9271_FIRMWARE_TEXT  0x903000
4562306a36Sopenharmony_ci#define AR7010_FIRMWARE_TEXT  0x906000
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci#define FIRMWARE_DOWNLOAD       0x30
4862306a36Sopenharmony_ci#define FIRMWARE_DOWNLOAD_COMP  0x31
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci#define ATH_USB_RX_STREAM_MODE_TAG 0x4e00
5162306a36Sopenharmony_ci#define ATH_USB_TX_STREAM_MODE_TAG 0x697e
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci/* FIXME: Verify these numbers (with Windows) */
5462306a36Sopenharmony_ci#define MAX_TX_URB_NUM  8
5562306a36Sopenharmony_ci#define MAX_TX_BUF_NUM  256
5662306a36Sopenharmony_ci#define MAX_TX_BUF_SIZE 32768
5762306a36Sopenharmony_ci#define MAX_TX_AGGR_NUM 20
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#define MAX_RX_URB_NUM  8
6062306a36Sopenharmony_ci#define MAX_RX_BUF_SIZE 16384
6162306a36Sopenharmony_ci#define MAX_PKT_NUM_IN_TRANSFER 10
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define MAX_REG_OUT_URB_NUM  1
6462306a36Sopenharmony_ci#define MAX_REG_IN_URB_NUM   64
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci#define MAX_REG_IN_BUF_SIZE 64
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/* USB Endpoint definition */
6962306a36Sopenharmony_ci#define USB_WLAN_TX_PIPE  1
7062306a36Sopenharmony_ci#define USB_WLAN_RX_PIPE  2
7162306a36Sopenharmony_ci#define USB_REG_IN_PIPE   3
7262306a36Sopenharmony_ci#define USB_REG_OUT_PIPE  4
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define USB_MSG_TIMEOUT 1000 /* (ms) */
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci#define HIF_USB_MAX_RXPIPES 2
7762306a36Sopenharmony_ci#define HIF_USB_MAX_TXPIPES 4
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_cistruct tx_buf {
8062306a36Sopenharmony_ci	u8 *buf;
8162306a36Sopenharmony_ci	u16 len;
8262306a36Sopenharmony_ci	u16 offset;
8362306a36Sopenharmony_ci	struct urb *urb;
8462306a36Sopenharmony_ci	struct sk_buff_head skb_queue;
8562306a36Sopenharmony_ci	struct hif_device_usb *hif_dev;
8662306a36Sopenharmony_ci	struct list_head list;
8762306a36Sopenharmony_ci};
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_cistruct rx_buf {
9062306a36Sopenharmony_ci	struct sk_buff *skb;
9162306a36Sopenharmony_ci	struct hif_device_usb *hif_dev;
9262306a36Sopenharmony_ci};
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci#define HIF_USB_TX_STOP  BIT(0)
9562306a36Sopenharmony_ci#define HIF_USB_TX_FLUSH BIT(1)
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_cistruct hif_usb_tx {
9862306a36Sopenharmony_ci	u8 flags;
9962306a36Sopenharmony_ci	u8 tx_buf_cnt;
10062306a36Sopenharmony_ci	u16 tx_skb_cnt;
10162306a36Sopenharmony_ci	struct sk_buff_head tx_skb_queue;
10262306a36Sopenharmony_ci	struct list_head tx_buf;
10362306a36Sopenharmony_ci	struct list_head tx_pending;
10462306a36Sopenharmony_ci	spinlock_t tx_lock;
10562306a36Sopenharmony_ci};
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_cistruct cmd_buf {
10862306a36Sopenharmony_ci	struct sk_buff *skb;
10962306a36Sopenharmony_ci	struct hif_device_usb *hif_dev;
11062306a36Sopenharmony_ci};
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci#define HIF_USB_START BIT(0)
11362306a36Sopenharmony_ci#define HIF_USB_READY BIT(1)
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_cistruct hif_device_usb {
11662306a36Sopenharmony_ci	struct usb_device *udev;
11762306a36Sopenharmony_ci	struct usb_interface *interface;
11862306a36Sopenharmony_ci	const struct usb_device_id *usb_device_id;
11962306a36Sopenharmony_ci	const void *fw_data;
12062306a36Sopenharmony_ci	size_t fw_size;
12162306a36Sopenharmony_ci	struct completion fw_done;
12262306a36Sopenharmony_ci	struct htc_target *htc_handle;
12362306a36Sopenharmony_ci	struct hif_usb_tx tx;
12462306a36Sopenharmony_ci	struct usb_anchor regout_submitted;
12562306a36Sopenharmony_ci	struct usb_anchor rx_submitted;
12662306a36Sopenharmony_ci	struct usb_anchor reg_in_submitted;
12762306a36Sopenharmony_ci	struct usb_anchor mgmt_submitted;
12862306a36Sopenharmony_ci	struct sk_buff *remain_skb;
12962306a36Sopenharmony_ci	char fw_name[32];
13062306a36Sopenharmony_ci	int fw_minor_index;
13162306a36Sopenharmony_ci	int rx_remain_len;
13262306a36Sopenharmony_ci	int rx_pkt_len;
13362306a36Sopenharmony_ci	int rx_transfer_len;
13462306a36Sopenharmony_ci	int rx_pad_len;
13562306a36Sopenharmony_ci	spinlock_t rx_lock;
13662306a36Sopenharmony_ci	u8 flags; /* HIF_USB_* */
13762306a36Sopenharmony_ci};
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ciint ath9k_hif_usb_init(void);
14062306a36Sopenharmony_civoid ath9k_hif_usb_exit(void);
14162306a36Sopenharmony_civoid ath9k_hif_usb_dealloc_urbs(struct hif_device_usb *hif_dev);
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci#endif /* HTC_USB_H */
144