summarylogtreecommitdiffstats
path: root/ath.patch
blob: 559820938c9a09d4b6a15acfd5fcb6287305738f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
diff --git i/drivers/net/wireless/ath/ath9k/htc.h w/drivers/net/wireless/ath/ath9k/htc.h
index 16dff4b89a86..63eea0bc6097 100644
--- i/drivers/net/wireless/ath/ath9k/htc.h
+++ w/drivers/net/wireless/ath/ath9k/htc.h
@@ -604,6 +604,9 @@ void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw);
 
 struct base_eep_header *ath9k_htc_get_eeprom_base(struct ath9k_htc_priv *priv);
 
+// TODO make more generic: any argument instead of just 2 int32s
+int dbg_firmware_cmd(struct ath9k_htc_priv *priv, u8 cmd_id, u32 arguments[2]);
+
 #ifdef CONFIG_MAC80211_LEDS
 void ath9k_configure_leds(struct ath9k_htc_priv *priv);
 void ath9k_init_leds(struct ath9k_htc_priv *priv);
diff --git i/drivers/net/wireless/ath/ath9k/htc_drv_debug.c w/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
index dc79afd7e151..3e0d1a35ef6f 100644
--- i/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
+++ w/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
@@ -14,6 +14,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include <net/genetlink.h>
 #include "htc.h"
 
 static ssize_t read_file_tgt_int_stats(struct file *file, char __user *user_buf,
@@ -479,13 +480,298 @@ void ath9k_htc_get_et_stats(struct ieee80211_hw *hw,
 	WARN_ON(i != ATH9K_HTC_SSTATS_LEN);
 }
 
+struct ath9k_htc_priv *genl_ath9k_priv = NULL;
+
+enum {
+	ATH9K_HTC_A_UNSPEC,
+	ATH9K_HTC_A_STR,
+	ATH9K_HTC_A_REG,
+	ATH9K_HTC_A_VAL,
+	ATH9K_HTC_A_MAX,
+};
+
+enum {
+	ATH9K_HTC_C_UNSPEC,
+	ATH9K_C_ECHO,
+	ATH9K_C_SET,
+	ATH9K_C_RATE,
+	ATH9K_C_RESET,
+	ATH9K_C_MAX,
+};
+
+/* attribute policy: defines which attribute has which type (e.g int, char * etc)
+ * possible values defined in net/netlink.h 
+ */
+static struct nla_policy ath9k_htc_genl_policy[ATH9K_HTC_A_MAX] = {
+	[ATH9K_HTC_A_STR] = { .type = NLA_NUL_STRING },
+	[ATH9K_HTC_A_REG] = { .type = NLA_U32 },
+	[ATH9K_HTC_A_VAL] = { .type = NLA_U32 },
+};
+
+static struct genl_family ath9k_htc_gnl_family = {
+	.id = GENL_ID_GENERATE,
+	.hdrsize = 0,
+	.name = "ATH9K_HTC",
+	.version = 1,
+	.maxattr = ATH9K_HTC_A_MAX-1,
+};
+
+static int ath9k_echo(struct sk_buff *iskb, struct genl_info *info) {
+	struct nlattr *received_str_attr;
+	char *received_str;
+	struct sk_buff *skb;
+	int errc;
+	void *msg_head;
+
+	if (info == NULL)
+		goto out;
+
+	received_str_attr = info->attrs[ATH9K_HTC_A_STR];
+	if (received_str_attr) {
+		received_str = (char *)nla_data(received_str_attr);
+		if (received_str != NULL)
+			printk("ath9k_htc: got %s\n", received_str);
+		else
+			printk(KERN_ERR "error while receiving data\n");
+	} else {
+		printk(KERN_ERR "attribute %i not present\n", ATH9K_HTC_A_STR);
+	}
+
+	skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	if (skb == NULL)
+		goto out;
+
+	msg_head = genlmsg_put(skb, 0, info->snd_seq + 1, &ath9k_htc_gnl_family, 0, ATH9K_C_ECHO);
+	if (msg_head == NULL) {
+		errc = -ENOMEM;
+		goto out;
+	}
+	
+	errc = nla_put_string(skb, ATH9K_HTC_A_STR, "pong");
+	if (errc != 0)
+		goto out;
+
+	genlmsg_end(skb, msg_head);
+
+	errc = genlmsg_unicast(genl_info_net(info), skb, info->snd_portid);
+	if (errc != 0)
+		goto out;
+
+	return 0;
+
+out:
+	printk(KERN_ERR "an error occured in ath9k_echo:\n");
+
+	return 1;
+}
+
+static int ath9k_set_reg(struct sk_buff *iskb, struct genl_info *info) {
+	struct nlattr *received_int_attr;
+	u32 *received_reg = NULL;
+	u32 *received_val = NULL;
+	struct sk_buff *skb;
+	int errc;
+	void *msg_head;
+	u32 vals[2];
+
+	if (info == NULL)
+		goto out;
+
+	// TODO repeated code... simplify
+	received_int_attr = info->attrs[ATH9K_HTC_A_REG];
+	if (received_int_attr) {
+		received_reg = (u32*)nla_data(received_int_attr);
+		if(received_reg)
+			printk("ath9k_htc: reg %08x\n", *received_reg);
+	} else {
+		printk(KERN_ERR "attribute %i not present\n", ATH9K_HTC_A_REG);
+	}
+
+	received_int_attr = info->attrs[ATH9K_HTC_A_VAL];
+	if (received_int_attr) {
+		received_val = (u32*)nla_data(received_int_attr);
+		if(received_val)
+			printk("ath9k_htc: val %08x\n", *received_val);
+	} else {
+		printk(KERN_ERR "attribute %i not present\n", ATH9K_HTC_A_VAL);
+	}
+
+	if(received_reg)
+		vals[0] = *received_reg;
+
+	if(received_val)
+		vals[1] = *received_val;
+
+	dbg_firmware_cmd(genl_ath9k_priv, DBG_CMD_SET_REG, vals);
+
+	skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	if (skb == NULL)
+		goto out;
+
+	msg_head = genlmsg_put(skb, 0, info->snd_seq + 1, &ath9k_htc_gnl_family, 0, ATH9K_C_SET);
+	if (msg_head == NULL) {
+		errc = -ENOMEM;
+		goto out;
+	}
+	
+	errc = nla_put_string(skb, ATH9K_HTC_A_STR, "reg set successfully");
+	if (errc != 0)
+		goto out;
+
+	genlmsg_end(skb, msg_head);
+
+	errc = genlmsg_unicast(genl_info_net(info), skb, info->snd_portid);
+	if (errc != 0)
+		goto out;
+
+	return 0;
+
+out:
+	printk(KERN_ERR "an error occured\n");
+
+	return 1;
+}
+
+static int ath9k_set_rate(struct sk_buff *iskb, struct genl_info *info) {
+	struct nlattr *received_int_attr;
+	u32 *received_val = NULL;
+	struct sk_buff *skb;
+	int errc;
+	void *msg_head;
+	u32 vals[2];
+
+	if (info == NULL)
+		goto out;
+
+	// TODO repeated code... simplify
+	received_int_attr = info->attrs[ATH9K_HTC_A_VAL];
+	if (received_int_attr) {
+		received_val = (u32*)nla_data(received_int_attr);
+		if(received_val)
+			printk("ath9k_htc: val %08x\n", *received_val);
+	} else {
+		printk(KERN_ERR "attribute %i not present\n", ATH9K_HTC_A_VAL);
+	}
+
+	if(received_val)
+		vals[0] = *received_val;
+
+	dbg_firmware_cmd(genl_ath9k_priv, DBG_CMD_SET_RATE, vals);
+
+	skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	if (skb == NULL)
+		goto out;
+
+	msg_head = genlmsg_put(skb, 0, info->snd_seq + 1, &ath9k_htc_gnl_family, 0, ATH9K_C_RATE);
+	if (msg_head == NULL) {
+		errc = -ENOMEM;
+		goto out;
+	}
+	
+	errc = nla_put_string(skb, ATH9K_HTC_A_STR, "rate set successfully");
+	if (errc != 0)
+		goto out;
+
+	genlmsg_end(skb, msg_head);
+
+	errc = genlmsg_unicast(genl_info_net(info), skb, info->snd_portid);
+	if (errc != 0)
+		goto out;
+
+	return 0;
+
+out:
+	printk(KERN_ERR "an error occured\n");
+
+	return 1;
+}
+
+static int ath9k_reset(struct sk_buff *iskb, struct genl_info *info) {
+	struct sk_buff *skb;
+	int errc;
+	void *msg_head;
+	u32 vals[2];
+
+	if (info == NULL)
+		goto out;
+
+	dbg_firmware_cmd(genl_ath9k_priv, DBG_CMD_RESET, vals);
+
+	// TODO repeated code... simplify
+	skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	if (skb == NULL)
+		goto out;
+
+	msg_head = genlmsg_put(skb, 0, info->snd_seq + 1, &ath9k_htc_gnl_family, 0, ATH9K_C_RESET);
+	if (msg_head == NULL) {
+		errc = -ENOMEM;
+		goto out;
+	}
+	
+	errc = nla_put_string(skb, ATH9K_HTC_A_STR, "reset counters");
+	if (errc != 0)
+		goto out;
+
+	genlmsg_end(skb, msg_head);
+
+	errc = genlmsg_unicast(genl_info_net(info), skb, info->snd_portid);
+	if (errc != 0)
+		goto out;
+
+	return 0;
+
+out:
+	printk(KERN_ERR "an error occured\n");
+
+	return 1;
+}
+
+static struct genl_ops ath9k_htc_gnl_ops[] = {
+	{
+		.cmd = ATH9K_C_ECHO,
+		.flags = 0,
+		.policy = ath9k_htc_genl_policy,
+		.doit = ath9k_echo,
+		.dumpit = NULL,
+	},
+	{
+		.cmd = ATH9K_C_SET,
+		.flags = 0,
+		.policy = ath9k_htc_genl_policy,
+		.doit = ath9k_set_reg,
+		.dumpit = NULL,
+	},
+	{
+		.cmd = ATH9K_C_RATE,
+		.flags = 0,
+		.policy = ath9k_htc_genl_policy,
+		.doit = ath9k_set_rate,
+		.dumpit = NULL,
+	},
+	{
+		.cmd = ATH9K_C_RESET,
+		.flags = 0,
+		.policy = ath9k_htc_genl_policy,
+		.doit = ath9k_reset,
+		.dumpit = NULL,
+	},
+};
+
+
 void ath9k_htc_deinit_debug(struct ath9k_htc_priv *priv)
 {
+	int errc;
 	ath9k_cmn_spectral_deinit_debug(&priv->spec_priv);
+
+	errc = genl_unregister_family(&ath9k_htc_gnl_family);
+	if(errc != 0){
+		printk(KERN_ERR "unregister family %i\n", errc);
+	}
 }
 
 int ath9k_htc_init_debug(struct ath_hw *ah)
 {
+	int errc;
 	struct ath_common *common = ath9k_hw_common(ah);
 	struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
 
@@ -520,5 +806,14 @@ int ath9k_htc_init_debug(struct ath_hw *ah)
 	ath9k_cmn_debug_base_eeprom(priv->debug.debugfs_phy, priv->ah);
 	ath9k_cmn_debug_modal_eeprom(priv->debug.debugfs_phy, priv->ah);
 
+	/* ath9k_htc netlink interface */
+	// TODO only works with one interface at the same time!
+	genl_ath9k_priv = priv;
+	errc = genl_register_family_with_ops(&ath9k_htc_gnl_family, ath9k_htc_gnl_ops);
+	if (errc != 0) {
+		printk("genl_register_family_with_ops error\n");
+		return 1;
+	}
+
 	return 0;
 }
diff --git i/drivers/net/wireless/ath/ath9k/htc_drv_init.c w/drivers/net/wireless/ath/ath9k/htc_drv_init.c
index defacc6c9c99..df7ddfde9423 100644
--- i/drivers/net/wireless/ath/ath9k/htc_drv_init.c
+++ w/drivers/net/wireless/ath/ath9k/htc_drv_init.c
@@ -231,6 +231,59 @@ static void ath9k_reg_notifier(struct wiphy *wiphy,
 			       ath9k_hw_regulatory(priv->ah));
 }
 
+static void fancy_printk(u8* buffer, u8 id, u8 len) {
+	u8 temp[400];
+	int i;
+	int counth = 0;
+	int countc = 0;
+
+	for(i = 0; i < len; i++) {
+		sprintf(temp + (counth * 3), "%02x ", buffer[i]);
+		counth++;
+	}
+
+	sprintf(temp + (counth * 3), "| ");
+
+	for(i = 0; i < len; i++) {
+		if((buffer[i] > '!' && buffer[i] < '~') || buffer[i] == ' ') {
+			sprintf(temp + (counth * 3) + 2 + countc, "%c", buffer[i]);
+		} else {
+			sprintf(temp + (counth * 3) + 2 + countc, "%c", '.');
+		}
+		countc++;
+	}
+	printk(KERN_ERR "firmware: %s (cmd %d)\n", temp, id);
+}
+
+int dbg_firmware_cmd(struct ath9k_htc_priv *priv, u8 cmd_id, u32 arguments[2])
+{
+	struct dbg_cmd_request cmd;
+	struct dbg_cmd_response cmd_rsp;
+	int ret;
+
+	// Prepare command
+	memset(&cmd, 0, sizeof(cmd));
+	cmd.id = cmd_id;
+	if(arguments != NULL) {
+		cmd.args[0] = cpu_to_be32(arguments[0]);
+		cmd.args[1] = cpu_to_be32(arguments[1]);
+	}
+
+	// Prepare response
+	memset(&cmd_rsp, 0, sizeof(cmd_rsp));
+
+	do {
+		ret = ath9k_wmi_cmd(priv->wmi, WMI_DBGCMD_CMDID, (u8 *)&cmd, sizeof(cmd), (u8 *)&cmd_rsp, sizeof(cmd_rsp), HZ*2);
+		if (ret)
+			return -EINVAL;
+
+		if(cmd_rsp.length > 0)
+			fancy_printk(cmd_rsp.buffer, cmd_id, cmd_rsp.length);
+	} while(cmd_rsp.length != 0);
+
+	return 0;
+}
+
 static unsigned int ath9k_regread(void *hw_priv, u32 reg_offset)
 {
 	struct ath_hw *ah = (struct ath_hw *) hw_priv;
@@ -249,6 +302,9 @@ static unsigned int ath9k_regread(void *hw_priv, u32 reg_offset)
 		return -EIO;
 	}
 
+	// Piggyback reading of firmware print buffer
+	dbg_firmware_cmd(priv, DBG_CMD_READ_MEMORY, NULL);
+
 	return be32_to_cpu(val);
 }
 
diff --git i/drivers/net/wireless/ath/ath9k/wmi.c w/drivers/net/wireless/ath/ath9k/wmi.c
index 64a354fa78ab..f34e0d6007a5 100644
--- i/drivers/net/wireless/ath/ath9k/wmi.c
+++ w/drivers/net/wireless/ath/ath9k/wmi.c
@@ -83,6 +83,11 @@ static const char *wmi_cmd_to_name(enum wmi_cmd_id wmi_cmd)
 		return "WMI_RX_STATS_CMDID";
 	case WMI_BITRATE_MASK_CMDID:
 		return "WMI_BITRATE_MASK_CMDID";
+	case WMI_REG_RMW_CMDID:
+		return "WMI_REG_RMW_CMDID"; // Bugfix
+	// New stuff
+	case WMI_DBGCMD_CMDID:
+		return "WMI_DBGCMD_CMDID";
 	}
 
 	return "Bogus";
@@ -334,6 +339,7 @@ int ath9k_wmi_cmd(struct wmi *wmi, enum wmi_cmd_id cmd_id,
 	if (!time_left) {
 		ath_dbg(common, WMI, "Timeout waiting for WMI command: %s\n",
 			wmi_cmd_to_name(cmd_id));
+		printk(KERN_ERR "ath9k_htc: Timeout waiting for command %s", wmi_cmd_to_name(cmd_id));
 		mutex_unlock(&wmi->op_mutex);
 		return -ETIMEDOUT;
 	}
diff --git i/drivers/net/wireless/ath/ath9k/wmi.h w/drivers/net/wireless/ath/ath9k/wmi.h
index 380175d5ecd7..0f9518b3ea1c 100644
--- i/drivers/net/wireless/ath/ath9k/wmi.h
+++ w/drivers/net/wireless/ath/ath9k/wmi.h
@@ -41,6 +41,25 @@ struct wmi_event_swba {
 	u8 beacon_pending;
 } __packed;
 
+// New stuff
+typedef enum {
+    DBG_CMD_READ_MEMORY,
+    DBG_CMD_TEST,
+    DBG_CMD_SET_REG,
+    DBG_CMD_SET_RATE,
+    DBG_CMD_RESET
+} DBG_CMD_ID;
+
+struct dbg_cmd_request {
+	u8 id;
+	__be32 args[2];
+} __packed;
+
+struct dbg_cmd_response {
+	u8 length;
+	u8 buffer[33]; // WMI does not allow big packets
+} __packed;
+
 /*
  * 64 - HTC header - WMI header - 1 / txstatus
  * And some other hdr. space is also accounted for.
@@ -113,6 +132,7 @@ enum wmi_cmd_id {
 	WMI_RX_STATS_CMDID,
 	WMI_BITRATE_MASK_CMDID,
 	WMI_REG_RMW_CMDID,
+  WMI_DBGCMD_CMDID,
 };
 
 enum wmi_event_id {