blob: 8c877dc2e2e0216852cd67acc91d99ba8383c81d [file] [log] [blame]
Sujithfb9987d2010-03-17 14:25:25 +05301/*
2 * Copyright (c) 2010 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef WMI_H
18#define WMI_H
19
20
21struct wmi_event_txrate {
Sujith7f1f5a02010-04-16 11:54:03 +053022 __be32 txrate;
Sujithfb9987d2010-03-17 14:25:25 +053023 struct {
24 u8 rssi_thresh;
25 u8 per;
26 } rc_stats;
27} __packed;
28
29struct wmi_cmd_hdr {
Sujith7f1f5a02010-04-16 11:54:03 +053030 __be16 command_id;
31 __be16 seq_no;
Sujithfb9987d2010-03-17 14:25:25 +053032} __packed;
33
Sujith Manoharan29bbfb22011-04-13 11:22:51 +053034struct wmi_fw_version {
35 __be16 major;
36 __be16 minor;
37
38} __packed;
Sujith Manoharan1c165c92011-04-13 11:22:59 +053039
40struct wmi_event_swba {
41 __be64 tsf;
42 u8 beacon_pending;
43};
Sujith Manoharan16c56ae2011-04-13 11:25:18 +053044
45/*
46 * 64 - HTC header - WMI header - 1 / txstatus
47 * And some other hdr. space is also accounted for.
48 * 13 seems to be the magic number.
49 */
50#define HTC_MAX_TX_STATUS 13
51
52#define ATH9K_HTC_TXSTAT_ACK BIT(0)
53#define ATH9K_HTC_TXSTAT_FILT BIT(1)
54#define ATH9K_HTC_TXSTAT_RTC_CTS BIT(2)
55#define ATH9K_HTC_TXSTAT_MCS BIT(3)
56#define ATH9K_HTC_TXSTAT_CW40 BIT(4)
57#define ATH9K_HTC_TXSTAT_SGI BIT(5)
58
59/*
60 * Legacy rates are indicated as indices.
61 * HT rates are indicated as dot11 numbers.
62 * This allows us to resrict the rate field
63 * to 4 bits.
64 */
65#define ATH9K_HTC_TXSTAT_RATE 0x0f
66#define ATH9K_HTC_TXSTAT_RATE_S 0
67
68#define ATH9K_HTC_TXSTAT_EPID 0xf0
69#define ATH9K_HTC_TXSTAT_EPID_S 4
70
71struct __wmi_event_txstatus {
72 u8 cookie;
73 u8 ts_rate; /* Also holds EP ID */
74 u8 ts_flags;
75};
76
77struct wmi_event_txstatus {
78 u8 cnt;
79 struct __wmi_event_txstatus txstatus[HTC_MAX_TX_STATUS];
80} __packed;
81
Sujithfb9987d2010-03-17 14:25:25 +053082enum wmi_cmd_id {
83 WMI_ECHO_CMDID = 0x0001,
84 WMI_ACCESS_MEMORY_CMDID,
85
86 /* Commands to Target */
Sujith Manoharan29bbfb22011-04-13 11:22:51 +053087 WMI_GET_FW_VERSION,
Sujithfb9987d2010-03-17 14:25:25 +053088 WMI_DISABLE_INTR_CMDID,
89 WMI_ENABLE_INTR_CMDID,
Sujithfb9987d2010-03-17 14:25:25 +053090 WMI_ATH_INIT_CMDID,
91 WMI_ABORT_TXQ_CMDID,
92 WMI_STOP_TX_DMA_CMDID,
Sujithfb9987d2010-03-17 14:25:25 +053093 WMI_ABORT_TX_DMA_CMDID,
94 WMI_DRAIN_TXQ_CMDID,
95 WMI_DRAIN_TXQ_ALL_CMDID,
96 WMI_START_RECV_CMDID,
97 WMI_STOP_RECV_CMDID,
98 WMI_FLUSH_RECV_CMDID,
99 WMI_SET_MODE_CMDID,
Sujithfb9987d2010-03-17 14:25:25 +0530100 WMI_NODE_CREATE_CMDID,
101 WMI_NODE_REMOVE_CMDID,
102 WMI_VAP_REMOVE_CMDID,
103 WMI_VAP_CREATE_CMDID,
Sujithfb9987d2010-03-17 14:25:25 +0530104 WMI_REG_READ_CMDID,
105 WMI_REG_WRITE_CMDID,
106 WMI_RC_STATE_CHANGE_CMDID,
107 WMI_RC_RATE_UPDATE_CMDID,
Sujithfb9987d2010-03-17 14:25:25 +0530108 WMI_TARGET_IC_UPDATE_CMDID,
109 WMI_TGT_STATS_CMDID,
110 WMI_TX_AGGR_ENABLE_CMDID,
111 WMI_TGT_DETACH_CMDID,
Vivek Natarajan21cb9872010-08-18 19:57:49 +0530112 WMI_AGGR_LIMIT_CMD = 0x0026,
Sujithfb9987d2010-03-17 14:25:25 +0530113};
114
115enum wmi_event_id {
116 WMI_TGT_RDY_EVENTID = 0x1001,
117 WMI_SWBA_EVENTID,
118 WMI_FATAL_EVENTID,
119 WMI_TXTO_EVENTID,
120 WMI_BMISS_EVENTID,
Sujithfb9987d2010-03-17 14:25:25 +0530121 WMI_DELBA_EVENTID,
122 WMI_TXRATE_EVENTID,
Sujith Manoharan16c56ae2011-04-13 11:25:18 +0530123 WMI_TXSTATUS_EVENTID,
Sujithfb9987d2010-03-17 14:25:25 +0530124};
125
Sujith4a22fe12010-04-16 11:53:53 +0530126#define MAX_CMD_NUMBER 62
127
128struct register_write {
Sujith7f1f5a02010-04-16 11:54:03 +0530129 __be32 reg;
130 __be32 val;
Sujith4a22fe12010-04-16 11:53:53 +0530131};
132
Sujithfb9987d2010-03-17 14:25:25 +0530133struct wmi {
134 struct ath9k_htc_priv *drv_priv;
135 struct htc_target *htc;
136 enum htc_endpoint_id ctrl_epid;
137 struct mutex op_mutex;
138 struct completion cmd_wait;
Sujith6ce34ec2010-04-16 11:54:01 +0530139 enum wmi_cmd_id last_cmd_id;
Sujith Manoharanf4c88992011-04-13 11:23:52 +0530140 struct sk_buff_head wmi_event_queue;
141 struct tasklet_struct wmi_event_tasklet;
Sujithfb9987d2010-03-17 14:25:25 +0530142 u16 tx_seq_id;
143 u8 *cmd_rsp_buf;
144 u32 cmd_rsp_len;
145 bool stopped;
146
Sujithfb9987d2010-03-17 14:25:25 +0530147 spinlock_t wmi_lock;
Sujith4a22fe12010-04-16 11:53:53 +0530148
149 atomic_t mwrite_cnt;
150 struct register_write multi_write[MAX_CMD_NUMBER];
151 u32 multi_write_idx;
152 struct mutex multi_write_mutex;
Sujithfb9987d2010-03-17 14:25:25 +0530153};
154
155struct wmi *ath9k_init_wmi(struct ath9k_htc_priv *priv);
156void ath9k_deinit_wmi(struct ath9k_htc_priv *priv);
157int ath9k_wmi_connect(struct htc_target *htc, struct wmi *wmi,
158 enum htc_endpoint_id *wmi_ctrl_epid);
159int ath9k_wmi_cmd(struct wmi *wmi, enum wmi_cmd_id cmd_id,
160 u8 *cmd_buf, u32 cmd_len,
161 u8 *rsp_buf, u32 rsp_len,
162 u32 timeout);
Sujith Manoharanf4c88992011-04-13 11:23:52 +0530163void ath9k_wmi_event_tasklet(unsigned long data);
Sujith Manoharan73908672010-12-28 14:28:27 +0530164void ath9k_fatal_work(struct work_struct *work);
Sujith Manoharanf4c88992011-04-13 11:23:52 +0530165void ath9k_wmi_event_drain(struct ath9k_htc_priv *priv);
Sujithfb9987d2010-03-17 14:25:25 +0530166
167#define WMI_CMD(_wmi_cmd) \
168 do { \
169 ret = ath9k_wmi_cmd(priv->wmi, _wmi_cmd, NULL, 0, \
170 (u8 *) &cmd_rsp, \
Sujithba443702010-04-23 10:28:18 +0530171 sizeof(cmd_rsp), HZ*2); \
Sujithfb9987d2010-03-17 14:25:25 +0530172 } while (0)
173
174#define WMI_CMD_BUF(_wmi_cmd, _buf) \
175 do { \
176 ret = ath9k_wmi_cmd(priv->wmi, _wmi_cmd, \
177 (u8 *) _buf, sizeof(*_buf), \
Sujithba443702010-04-23 10:28:18 +0530178 &cmd_rsp, sizeof(cmd_rsp), HZ*2); \
Sujithfb9987d2010-03-17 14:25:25 +0530179 } while (0)
180
181#endif /* WMI_H */