| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | #include <linux/module.h> | 
 | 2 | #include <linux/dcache.h> | 
 | 3 | #include <linux/debugfs.h> | 
 | 4 | #include <linux/delay.h> | 
 | 5 | #include <linux/mm.h> | 
| Geert Uytterhoeven | d8b0fb5 | 2007-10-08 09:43:02 +0200 | [diff] [blame] | 6 | #include <linux/string.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame^] | 7 | #include <linux/slab.h> | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 8 | #include <net/iw_handler.h> | 
| John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 9 | #include <net/lib80211.h> | 
| Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 10 |  | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 11 | #include "dev.h" | 
 | 12 | #include "decl.h" | 
 | 13 | #include "host.h" | 
| Dan Williams | 5bdb3ef | 2007-05-10 23:08:05 -0400 | [diff] [blame] | 14 | #include "debugfs.h" | 
| David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 15 | #include "cmd.h" | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 16 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 17 | static struct dentry *lbs_dir; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 18 | static char *szStates[] = { | 
 | 19 | 	"Connected", | 
 | 20 | 	"Disconnected" | 
 | 21 | }; | 
 | 22 |  | 
| Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 23 | #ifdef PROC_DEBUG | 
| Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 24 | static void lbs_debug_init(struct lbs_private *priv); | 
| Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 25 | #endif | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 26 |  | 
 | 27 | static int open_file_generic(struct inode *inode, struct file *file) | 
 | 28 | { | 
 | 29 | 	file->private_data = inode->i_private; | 
 | 30 | 	return 0; | 
 | 31 | } | 
 | 32 |  | 
 | 33 | static ssize_t write_file_dummy(struct file *file, const char __user *buf, | 
 | 34 |                                 size_t count, loff_t *ppos) | 
 | 35 | { | 
 | 36 |         return -EINVAL; | 
 | 37 | } | 
 | 38 |  | 
 | 39 | static const size_t len = PAGE_SIZE; | 
 | 40 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 41 | static ssize_t lbs_dev_info(struct file *file, char __user *userbuf, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 42 | 				  size_t count, loff_t *ppos) | 
 | 43 | { | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 44 | 	struct lbs_private *priv = file->private_data; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 45 | 	size_t pos = 0; | 
 | 46 | 	unsigned long addr = get_zeroed_page(GFP_KERNEL); | 
 | 47 | 	char *buf = (char *)addr; | 
 | 48 | 	ssize_t res; | 
| Kiran Divekar | ad43f8b | 2009-08-28 17:47:59 +0530 | [diff] [blame] | 49 | 	if (!buf) | 
 | 50 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 51 |  | 
 | 52 | 	pos += snprintf(buf+pos, len-pos, "state = %s\n", | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 53 | 				szStates[priv->connect_status]); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 54 | 	pos += snprintf(buf+pos, len-pos, "region_code = %02x\n", | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 55 | 				(u32) priv->regioncode); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 56 |  | 
 | 57 | 	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos); | 
 | 58 |  | 
 | 59 | 	free_page(addr); | 
 | 60 | 	return res; | 
 | 61 | } | 
 | 62 |  | 
 | 63 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 64 | static ssize_t lbs_getscantable(struct file *file, char __user *userbuf, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 65 | 				  size_t count, loff_t *ppos) | 
 | 66 | { | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 67 | 	struct lbs_private *priv = file->private_data; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 68 | 	size_t pos = 0; | 
 | 69 | 	int numscansdone = 0, res; | 
 | 70 | 	unsigned long addr = get_zeroed_page(GFP_KERNEL); | 
 | 71 | 	char *buf = (char *)addr; | 
| John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 72 | 	DECLARE_SSID_BUF(ssid); | 
| Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 73 | 	struct bss_descriptor * iter_bss; | 
| Kiran Divekar | ad43f8b | 2009-08-28 17:47:59 +0530 | [diff] [blame] | 74 | 	if (!buf) | 
 | 75 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 76 |  | 
 | 77 | 	pos += snprintf(buf+pos, len-pos, | 
| Holger Schurig | a2235ed | 2007-08-02 13:12:45 -0400 | [diff] [blame] | 78 | 		"# | ch  | rssi |       bssid       |   cap    | Qual | SSID \n"); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 79 |  | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 80 | 	mutex_lock(&priv->lock); | 
 | 81 | 	list_for_each_entry (iter_bss, &priv->network_list, list) { | 
| Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 82 | 		u16 ibss = (iter_bss->capability & WLAN_CAPABILITY_IBSS); | 
 | 83 | 		u16 privacy = (iter_bss->capability & WLAN_CAPABILITY_PRIVACY); | 
 | 84 | 		u16 spectrum_mgmt = (iter_bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 85 |  | 
| Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 86 | 		pos += snprintf(buf+pos, len-pos, "%02u| %03d | %04d | %pM |", | 
| Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 87 | 			numscansdone, iter_bss->channel, iter_bss->rssi, | 
| Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 88 | 			iter_bss->bssid); | 
| Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 89 | 		pos += snprintf(buf+pos, len-pos, " %04x-", iter_bss->capability); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 90 | 		pos += snprintf(buf+pos, len-pos, "%c%c%c |", | 
| Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 91 | 				ibss ? 'A' : 'I', privacy ? 'P' : ' ', | 
 | 92 | 				spectrum_mgmt ? 'S' : ' '); | 
| Holger Schurig | a2235ed | 2007-08-02 13:12:45 -0400 | [diff] [blame] | 93 | 		pos += snprintf(buf+pos, len-pos, " %04d |", SCAN_RSSI(iter_bss->rssi)); | 
| Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 94 | 		pos += snprintf(buf+pos, len-pos, " %s\n", | 
| John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 95 | 		                print_ssid(ssid, iter_bss->ssid, | 
 | 96 | 					   iter_bss->ssid_len)); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 97 |  | 
 | 98 | 		numscansdone++; | 
 | 99 | 	} | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 100 | 	mutex_unlock(&priv->lock); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 101 |  | 
 | 102 | 	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos); | 
 | 103 |  | 
 | 104 | 	free_page(addr); | 
 | 105 | 	return res; | 
 | 106 | } | 
 | 107 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 108 | static ssize_t lbs_sleepparams_write(struct file *file, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 109 | 				const char __user *user_buf, size_t count, | 
 | 110 | 				loff_t *ppos) | 
 | 111 | { | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 112 | 	struct lbs_private *priv = file->private_data; | 
| David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 113 | 	ssize_t buf_size, ret; | 
 | 114 | 	struct sleep_params sp; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 115 | 	int p1, p2, p3, p4, p5, p6; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 116 | 	unsigned long addr = get_zeroed_page(GFP_KERNEL); | 
 | 117 | 	char *buf = (char *)addr; | 
| Kiran Divekar | ad43f8b | 2009-08-28 17:47:59 +0530 | [diff] [blame] | 118 | 	if (!buf) | 
 | 119 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 120 |  | 
 | 121 | 	buf_size = min(count, len - 1); | 
 | 122 | 	if (copy_from_user(buf, user_buf, buf_size)) { | 
| David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 123 | 		ret = -EFAULT; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 124 | 		goto out_unlock; | 
 | 125 | 	} | 
| David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 126 | 	ret = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6); | 
 | 127 | 	if (ret != 6) { | 
 | 128 | 		ret = -EINVAL; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 129 | 		goto out_unlock; | 
 | 130 | 	} | 
| David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 131 | 	sp.sp_error = p1; | 
 | 132 | 	sp.sp_offset = p2; | 
 | 133 | 	sp.sp_stabletime = p3; | 
 | 134 | 	sp.sp_calcontrol = p4; | 
 | 135 | 	sp.sp_extsleepclk = p5; | 
 | 136 | 	sp.sp_reserved = p6; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 137 |  | 
| David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 138 | 	ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_SET, &sp); | 
 | 139 | 	if (!ret) | 
 | 140 | 		ret = count; | 
 | 141 | 	else if (ret > 0) | 
 | 142 | 		ret = -EINVAL; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 143 |  | 
 | 144 | out_unlock: | 
 | 145 | 	free_page(addr); | 
| David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 146 | 	return ret; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 147 | } | 
 | 148 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 149 | static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 150 | 				  size_t count, loff_t *ppos) | 
 | 151 | { | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 152 | 	struct lbs_private *priv = file->private_data; | 
| David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 153 | 	ssize_t ret; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 154 | 	size_t pos = 0; | 
| David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 155 | 	struct sleep_params sp; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 156 | 	unsigned long addr = get_zeroed_page(GFP_KERNEL); | 
 | 157 | 	char *buf = (char *)addr; | 
| Kiran Divekar | ad43f8b | 2009-08-28 17:47:59 +0530 | [diff] [blame] | 158 | 	if (!buf) | 
 | 159 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 160 |  | 
| David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 161 | 	ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_GET, &sp); | 
 | 162 | 	if (ret) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 163 | 		goto out_unlock; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 164 |  | 
| David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 165 | 	pos += snprintf(buf, len, "%d %d %d %d %d %d\n", sp.sp_error, | 
 | 166 | 			sp.sp_offset, sp.sp_stabletime, | 
 | 167 | 			sp.sp_calcontrol, sp.sp_extsleepclk, | 
 | 168 | 			sp.sp_reserved); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 169 |  | 
| David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 170 | 	ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 171 |  | 
 | 172 | out_unlock: | 
 | 173 | 	free_page(addr); | 
| David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 174 | 	return ret; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 175 | } | 
 | 176 |  | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 177 | /* | 
 | 178 |  * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might | 
 | 179 |  * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the | 
 | 180 |  * firmware. Here's an example: | 
 | 181 |  *	04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00 | 
 | 182 |  *	00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03 | 
 | 183 |  *	00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | 
 | 184 |  * | 
 | 185 |  * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length, | 
 | 186 |  * 00 00 are the data bytes of this TLV. For this TLV, their meaning is | 
 | 187 |  * defined in mrvlietypes_thresholds | 
 | 188 |  * | 
 | 189 |  * This function searches in this TLV data chunk for a given TLV type | 
 | 190 |  * and returns a pointer to the first data byte of the TLV, or to NULL | 
 | 191 |  * if the TLV hasn't been found. | 
 | 192 |  */ | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 193 | static void *lbs_tlv_find(uint16_t tlv_type, const uint8_t *tlv, uint16_t size) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 194 | { | 
| Dan Williams | 75b6a61 | 2009-05-22 20:03:09 -0400 | [diff] [blame] | 195 | 	struct mrvl_ie_header *tlv_h; | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 196 | 	uint16_t length; | 
 | 197 | 	ssize_t pos = 0; | 
 | 198 |  | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 199 | 	while (pos < size) { | 
| Dan Williams | 75b6a61 | 2009-05-22 20:03:09 -0400 | [diff] [blame] | 200 | 		tlv_h = (struct mrvl_ie_header *) tlv; | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 201 | 		if (!tlv_h->len) | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 202 | 			return NULL; | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 203 | 		if (tlv_h->type == cpu_to_le16(tlv_type)) | 
 | 204 | 			return tlv_h; | 
 | 205 | 		length = le16_to_cpu(tlv_h->len) + sizeof(*tlv_h); | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 206 | 		pos += length; | 
 | 207 | 		tlv += length; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 208 | 	} | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 209 | 	return NULL; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 210 | } | 
 | 211 |  | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 212 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 213 | static ssize_t lbs_threshold_read(uint16_t tlv_type, uint16_t event_mask, | 
 | 214 | 				  struct file *file, char __user *userbuf, | 
 | 215 | 				  size_t count, loff_t *ppos) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 216 | { | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 217 | 	struct cmd_ds_802_11_subscribe_event *subscribed; | 
| Dan Williams | 75b6a61 | 2009-05-22 20:03:09 -0400 | [diff] [blame] | 218 | 	struct mrvl_ie_thresholds *got; | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 219 | 	struct lbs_private *priv = file->private_data; | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 220 | 	ssize_t ret = 0; | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 221 | 	size_t pos = 0; | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 222 | 	char *buf; | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 223 | 	u8 value; | 
 | 224 | 	u8 freq; | 
| Holger Schurig | b6b8abe | 2007-12-10 12:19:55 +0100 | [diff] [blame] | 225 | 	int events = 0; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 226 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 227 | 	buf = (char *)get_zeroed_page(GFP_KERNEL); | 
 | 228 | 	if (!buf) | 
 | 229 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 230 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 231 | 	subscribed = kzalloc(sizeof(*subscribed), GFP_KERNEL); | 
 | 232 | 	if (!subscribed) { | 
 | 233 | 		ret = -ENOMEM; | 
 | 234 | 		goto out_page; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 235 | 	} | 
 | 236 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 237 | 	subscribed->hdr.size = cpu_to_le16(sizeof(*subscribed)); | 
 | 238 | 	subscribed->action = cpu_to_le16(CMD_ACT_GET); | 
 | 239 |  | 
 | 240 | 	ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, subscribed); | 
 | 241 | 	if (ret) | 
 | 242 | 		goto out_cmd; | 
 | 243 |  | 
| Holger Schurig | b6b8abe | 2007-12-10 12:19:55 +0100 | [diff] [blame] | 244 | 	got = lbs_tlv_find(tlv_type, subscribed->tlv, sizeof(subscribed->tlv)); | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 245 | 	if (got) { | 
 | 246 | 		value = got->value; | 
 | 247 | 		freq  = got->freq; | 
| Holger Schurig | b6b8abe | 2007-12-10 12:19:55 +0100 | [diff] [blame] | 248 | 		events = le16_to_cpu(subscribed->events); | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 249 |  | 
 | 250 | 		pos += snprintf(buf, len, "%d %d %d\n", value, freq, | 
 | 251 | 				!!(events & event_mask)); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 252 | 	} | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 253 |  | 
 | 254 | 	ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); | 
 | 255 |  | 
 | 256 |  out_cmd: | 
| Holger Schurig | b6b8abe | 2007-12-10 12:19:55 +0100 | [diff] [blame] | 257 | 	kfree(subscribed); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 258 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 259 |  out_page: | 
 | 260 | 	free_page((unsigned long)buf); | 
 | 261 | 	return ret; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 262 | } | 
 | 263 |  | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 264 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 265 | static ssize_t lbs_threshold_write(uint16_t tlv_type, uint16_t event_mask, | 
 | 266 | 				   struct file *file, | 
 | 267 | 				   const char __user *userbuf, size_t count, | 
 | 268 | 				   loff_t *ppos) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 269 | { | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 270 | 	struct cmd_ds_802_11_subscribe_event *events; | 
| Dan Williams | 75b6a61 | 2009-05-22 20:03:09 -0400 | [diff] [blame] | 271 | 	struct mrvl_ie_thresholds *tlv; | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 272 | 	struct lbs_private *priv = file->private_data; | 
 | 273 | 	ssize_t buf_size; | 
 | 274 | 	int value, freq, new_mask; | 
 | 275 | 	uint16_t curr_mask; | 
 | 276 | 	char *buf; | 
 | 277 | 	int ret; | 
 | 278 |  | 
 | 279 | 	buf = (char *)get_zeroed_page(GFP_KERNEL); | 
 | 280 | 	if (!buf) | 
 | 281 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 282 |  | 
 | 283 | 	buf_size = min(count, len - 1); | 
 | 284 | 	if (copy_from_user(buf, userbuf, buf_size)) { | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 285 | 		ret = -EFAULT; | 
 | 286 | 		goto out_page; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 287 | 	} | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 288 | 	ret = sscanf(buf, "%d %d %d", &value, &freq, &new_mask); | 
 | 289 | 	if (ret != 3) { | 
 | 290 | 		ret = -EINVAL; | 
 | 291 | 		goto out_page; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 292 | 	} | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 293 | 	events = kzalloc(sizeof(*events), GFP_KERNEL); | 
 | 294 | 	if (!events) { | 
 | 295 | 		ret = -ENOMEM; | 
 | 296 | 		goto out_page; | 
 | 297 | 	} | 
 | 298 |  | 
 | 299 | 	events->hdr.size = cpu_to_le16(sizeof(*events)); | 
 | 300 | 	events->action = cpu_to_le16(CMD_ACT_GET); | 
 | 301 |  | 
 | 302 | 	ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events); | 
 | 303 | 	if (ret) | 
 | 304 | 		goto out_events; | 
 | 305 |  | 
 | 306 | 	curr_mask = le16_to_cpu(events->events); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 307 |  | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 308 | 	if (new_mask) | 
 | 309 | 		new_mask = curr_mask | event_mask; | 
 | 310 | 	else | 
 | 311 | 		new_mask = curr_mask & ~event_mask; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 312 |  | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 313 | 	/* Now everything is set and we can send stuff down to the firmware */ | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 314 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 315 | 	tlv = (void *)events->tlv; | 
 | 316 |  | 
 | 317 | 	events->action = cpu_to_le16(CMD_ACT_SET); | 
 | 318 | 	events->events = cpu_to_le16(new_mask); | 
 | 319 | 	tlv->header.type = cpu_to_le16(tlv_type); | 
 | 320 | 	tlv->header.len = cpu_to_le16(sizeof(*tlv) - sizeof(tlv->header)); | 
 | 321 | 	tlv->value = value; | 
 | 322 | 	if (tlv_type != TLV_TYPE_BCNMISS) | 
 | 323 | 		tlv->freq = freq; | 
 | 324 |  | 
| Holger Schurig | a75eda4 | 2008-05-30 14:53:22 +0200 | [diff] [blame] | 325 | 	/* The command header, the action, the event mask, and one TLV */ | 
 | 326 | 	events->hdr.size = cpu_to_le16(sizeof(events->hdr) + 4 + sizeof(*tlv)); | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 327 |  | 
 | 328 | 	ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events); | 
 | 329 |  | 
 | 330 | 	if (!ret) | 
 | 331 | 		ret = count; | 
 | 332 |  out_events: | 
 | 333 | 	kfree(events); | 
 | 334 |  out_page: | 
 | 335 | 	free_page((unsigned long)buf); | 
 | 336 | 	return ret; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 337 | } | 
 | 338 |  | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 339 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 340 | static ssize_t lbs_lowrssi_read(struct file *file, char __user *userbuf, | 
 | 341 | 				size_t count, loff_t *ppos) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 342 | { | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 343 | 	return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW, | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 344 | 				  file, userbuf, count, ppos); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 345 | } | 
 | 346 |  | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 347 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 348 | static ssize_t lbs_lowrssi_write(struct file *file, const char __user *userbuf, | 
 | 349 | 				 size_t count, loff_t *ppos) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 350 | { | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 351 | 	return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW, | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 352 | 				   file, userbuf, count, ppos); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 353 | } | 
 | 354 |  | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 355 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 356 | static ssize_t lbs_lowsnr_read(struct file *file, char __user *userbuf, | 
 | 357 | 			       size_t count, loff_t *ppos) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 358 | { | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 359 | 	return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW, | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 360 | 				  file, userbuf, count, ppos); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 361 | } | 
 | 362 |  | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 363 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 364 | static ssize_t lbs_lowsnr_write(struct file *file, const char __user *userbuf, | 
 | 365 | 				size_t count, loff_t *ppos) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 366 | { | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 367 | 	return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW, | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 368 | 				   file, userbuf, count, ppos); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 369 | } | 
 | 370 |  | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 371 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 372 | static ssize_t lbs_failcount_read(struct file *file, char __user *userbuf, | 
 | 373 | 				  size_t count, loff_t *ppos) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 374 | { | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 375 | 	return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT, | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 376 | 				  file, userbuf, count, ppos); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 377 | } | 
 | 378 |  | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 379 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 380 | static ssize_t lbs_failcount_write(struct file *file, const char __user *userbuf, | 
 | 381 | 				   size_t count, loff_t *ppos) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 382 | { | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 383 | 	return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT, | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 384 | 				   file, userbuf, count, ppos); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 385 | } | 
 | 386 |  | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 387 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 388 | static ssize_t lbs_highrssi_read(struct file *file, char __user *userbuf, | 
 | 389 | 				 size_t count, loff_t *ppos) | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 390 | { | 
 | 391 | 	return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH, | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 392 | 				  file, userbuf, count, ppos); | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 393 | } | 
 | 394 |  | 
 | 395 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 396 | static ssize_t lbs_highrssi_write(struct file *file, const char __user *userbuf, | 
 | 397 | 				  size_t count, loff_t *ppos) | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 398 | { | 
 | 399 | 	return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH, | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 400 | 				   file, userbuf, count, ppos); | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 401 | } | 
 | 402 |  | 
 | 403 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 404 | static ssize_t lbs_highsnr_read(struct file *file, char __user *userbuf, | 
 | 405 | 				size_t count, loff_t *ppos) | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 406 | { | 
 | 407 | 	return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH, | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 408 | 				  file, userbuf, count, ppos); | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 409 | } | 
 | 410 |  | 
 | 411 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 412 | static ssize_t lbs_highsnr_write(struct file *file, const char __user *userbuf, | 
 | 413 | 				 size_t count, loff_t *ppos) | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 414 | { | 
 | 415 | 	return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH, | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 416 | 				   file, userbuf, count, ppos); | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 417 | } | 
 | 418 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 419 | static ssize_t lbs_bcnmiss_read(struct file *file, char __user *userbuf, | 
 | 420 | 				size_t count, loff_t *ppos) | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 421 | { | 
 | 422 | 	return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS, | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 423 | 				  file, userbuf, count, ppos); | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 424 | } | 
 | 425 |  | 
 | 426 |  | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 427 | static ssize_t lbs_bcnmiss_write(struct file *file, const char __user *userbuf, | 
 | 428 | 				 size_t count, loff_t *ppos) | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 429 | { | 
 | 430 | 	return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS, | 
| David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 431 | 				   file, userbuf, count, ppos); | 
| Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 432 | } | 
 | 433 |  | 
 | 434 |  | 
 | 435 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 436 | static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 437 | 				  size_t count, loff_t *ppos) | 
 | 438 | { | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 439 | 	struct lbs_private *priv = file->private_data; | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 440 | 	struct lbs_offset_value offval; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 441 | 	ssize_t pos = 0; | 
 | 442 | 	int ret; | 
 | 443 | 	unsigned long addr = get_zeroed_page(GFP_KERNEL); | 
 | 444 | 	char *buf = (char *)addr; | 
| Kiran Divekar | ad43f8b | 2009-08-28 17:47:59 +0530 | [diff] [blame] | 445 | 	if (!buf) | 
 | 446 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 447 |  | 
 | 448 | 	offval.offset = priv->mac_offset; | 
 | 449 | 	offval.value = 0; | 
 | 450 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 451 | 	ret = lbs_prepare_and_send_command(priv, | 
| Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 452 | 				CMD_MAC_REG_ACCESS, 0, | 
 | 453 | 				CMD_OPTION_WAITFORRSP, 0, &offval); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 454 | 	mdelay(10); | 
| Amitkumar Karwar | c0bbd57 | 2009-10-08 19:38:45 -0700 | [diff] [blame] | 455 | 	if (!ret) { | 
 | 456 | 		pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n", | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 457 | 				priv->mac_offset, priv->offsetvalue.value); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 458 |  | 
| Amitkumar Karwar | c0bbd57 | 2009-10-08 19:38:45 -0700 | [diff] [blame] | 459 | 		ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); | 
 | 460 | 	} | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 461 | 	free_page(addr); | 
 | 462 | 	return ret; | 
 | 463 | } | 
 | 464 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 465 | static ssize_t lbs_rdmac_write(struct file *file, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 466 | 				    const char __user *userbuf, | 
 | 467 | 				    size_t count, loff_t *ppos) | 
 | 468 | { | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 469 | 	struct lbs_private *priv = file->private_data; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 470 | 	ssize_t res, buf_size; | 
 | 471 | 	unsigned long addr = get_zeroed_page(GFP_KERNEL); | 
 | 472 | 	char *buf = (char *)addr; | 
| Kiran Divekar | ad43f8b | 2009-08-28 17:47:59 +0530 | [diff] [blame] | 473 | 	if (!buf) | 
 | 474 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 475 |  | 
 | 476 | 	buf_size = min(count, len - 1); | 
 | 477 | 	if (copy_from_user(buf, userbuf, buf_size)) { | 
 | 478 | 		res = -EFAULT; | 
 | 479 | 		goto out_unlock; | 
 | 480 | 	} | 
 | 481 | 	priv->mac_offset = simple_strtoul((char *)buf, NULL, 16); | 
 | 482 | 	res = count; | 
 | 483 | out_unlock: | 
 | 484 | 	free_page(addr); | 
 | 485 | 	return res; | 
 | 486 | } | 
 | 487 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 488 | static ssize_t lbs_wrmac_write(struct file *file, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 489 | 				    const char __user *userbuf, | 
 | 490 | 				    size_t count, loff_t *ppos) | 
 | 491 | { | 
 | 492 |  | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 493 | 	struct lbs_private *priv = file->private_data; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 494 | 	ssize_t res, buf_size; | 
 | 495 | 	u32 offset, value; | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 496 | 	struct lbs_offset_value offval; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 497 | 	unsigned long addr = get_zeroed_page(GFP_KERNEL); | 
 | 498 | 	char *buf = (char *)addr; | 
| Kiran Divekar | ad43f8b | 2009-08-28 17:47:59 +0530 | [diff] [blame] | 499 | 	if (!buf) | 
 | 500 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 501 |  | 
 | 502 | 	buf_size = min(count, len - 1); | 
 | 503 | 	if (copy_from_user(buf, userbuf, buf_size)) { | 
 | 504 | 		res = -EFAULT; | 
 | 505 | 		goto out_unlock; | 
 | 506 | 	} | 
 | 507 | 	res = sscanf(buf, "%x %x", &offset, &value); | 
 | 508 | 	if (res != 2) { | 
 | 509 | 		res = -EFAULT; | 
 | 510 | 		goto out_unlock; | 
 | 511 | 	} | 
 | 512 |  | 
 | 513 | 	offval.offset = offset; | 
 | 514 | 	offval.value = value; | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 515 | 	res = lbs_prepare_and_send_command(priv, | 
| Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 516 | 				CMD_MAC_REG_ACCESS, 1, | 
 | 517 | 				CMD_OPTION_WAITFORRSP, 0, &offval); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 518 | 	mdelay(10); | 
 | 519 |  | 
| Amitkumar Karwar | c0bbd57 | 2009-10-08 19:38:45 -0700 | [diff] [blame] | 520 | 	if (!res) | 
 | 521 | 		res = count; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 522 | out_unlock: | 
 | 523 | 	free_page(addr); | 
 | 524 | 	return res; | 
 | 525 | } | 
 | 526 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 527 | static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 528 | 				  size_t count, loff_t *ppos) | 
 | 529 | { | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 530 | 	struct lbs_private *priv = file->private_data; | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 531 | 	struct lbs_offset_value offval; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 532 | 	ssize_t pos = 0; | 
 | 533 | 	int ret; | 
 | 534 | 	unsigned long addr = get_zeroed_page(GFP_KERNEL); | 
 | 535 | 	char *buf = (char *)addr; | 
| Kiran Divekar | ad43f8b | 2009-08-28 17:47:59 +0530 | [diff] [blame] | 536 | 	if (!buf) | 
 | 537 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 538 |  | 
 | 539 | 	offval.offset = priv->bbp_offset; | 
 | 540 | 	offval.value = 0; | 
 | 541 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 542 | 	ret = lbs_prepare_and_send_command(priv, | 
| Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 543 | 				CMD_BBP_REG_ACCESS, 0, | 
 | 544 | 				CMD_OPTION_WAITFORRSP, 0, &offval); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 545 | 	mdelay(10); | 
| Amitkumar Karwar | c0bbd57 | 2009-10-08 19:38:45 -0700 | [diff] [blame] | 546 | 	if (!ret) { | 
 | 547 | 		pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n", | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 548 | 				priv->bbp_offset, priv->offsetvalue.value); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 549 |  | 
| Amitkumar Karwar | c0bbd57 | 2009-10-08 19:38:45 -0700 | [diff] [blame] | 550 | 		ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); | 
 | 551 | 	} | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 552 | 	free_page(addr); | 
 | 553 |  | 
 | 554 | 	return ret; | 
 | 555 | } | 
 | 556 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 557 | static ssize_t lbs_rdbbp_write(struct file *file, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 558 | 				    const char __user *userbuf, | 
 | 559 | 				    size_t count, loff_t *ppos) | 
 | 560 | { | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 561 | 	struct lbs_private *priv = file->private_data; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 562 | 	ssize_t res, buf_size; | 
 | 563 | 	unsigned long addr = get_zeroed_page(GFP_KERNEL); | 
 | 564 | 	char *buf = (char *)addr; | 
| Kiran Divekar | ad43f8b | 2009-08-28 17:47:59 +0530 | [diff] [blame] | 565 | 	if (!buf) | 
 | 566 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 567 |  | 
 | 568 | 	buf_size = min(count, len - 1); | 
 | 569 | 	if (copy_from_user(buf, userbuf, buf_size)) { | 
 | 570 | 		res = -EFAULT; | 
 | 571 | 		goto out_unlock; | 
 | 572 | 	} | 
 | 573 | 	priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16); | 
 | 574 | 	res = count; | 
 | 575 | out_unlock: | 
 | 576 | 	free_page(addr); | 
 | 577 | 	return res; | 
 | 578 | } | 
 | 579 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 580 | static ssize_t lbs_wrbbp_write(struct file *file, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 581 | 				    const char __user *userbuf, | 
 | 582 | 				    size_t count, loff_t *ppos) | 
 | 583 | { | 
 | 584 |  | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 585 | 	struct lbs_private *priv = file->private_data; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 586 | 	ssize_t res, buf_size; | 
 | 587 | 	u32 offset, value; | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 588 | 	struct lbs_offset_value offval; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 589 | 	unsigned long addr = get_zeroed_page(GFP_KERNEL); | 
 | 590 | 	char *buf = (char *)addr; | 
| Kiran Divekar | ad43f8b | 2009-08-28 17:47:59 +0530 | [diff] [blame] | 591 | 	if (!buf) | 
 | 592 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 593 |  | 
 | 594 | 	buf_size = min(count, len - 1); | 
 | 595 | 	if (copy_from_user(buf, userbuf, buf_size)) { | 
 | 596 | 		res = -EFAULT; | 
 | 597 | 		goto out_unlock; | 
 | 598 | 	} | 
 | 599 | 	res = sscanf(buf, "%x %x", &offset, &value); | 
 | 600 | 	if (res != 2) { | 
 | 601 | 		res = -EFAULT; | 
 | 602 | 		goto out_unlock; | 
 | 603 | 	} | 
 | 604 |  | 
 | 605 | 	offval.offset = offset; | 
 | 606 | 	offval.value = value; | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 607 | 	res = lbs_prepare_and_send_command(priv, | 
| Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 608 | 				CMD_BBP_REG_ACCESS, 1, | 
 | 609 | 				CMD_OPTION_WAITFORRSP, 0, &offval); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 610 | 	mdelay(10); | 
 | 611 |  | 
| Amitkumar Karwar | c0bbd57 | 2009-10-08 19:38:45 -0700 | [diff] [blame] | 612 | 	if (!res) | 
 | 613 | 		res = count; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 614 | out_unlock: | 
 | 615 | 	free_page(addr); | 
 | 616 | 	return res; | 
 | 617 | } | 
 | 618 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 619 | static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 620 | 				  size_t count, loff_t *ppos) | 
 | 621 | { | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 622 | 	struct lbs_private *priv = file->private_data; | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 623 | 	struct lbs_offset_value offval; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 624 | 	ssize_t pos = 0; | 
 | 625 | 	int ret; | 
 | 626 | 	unsigned long addr = get_zeroed_page(GFP_KERNEL); | 
 | 627 | 	char *buf = (char *)addr; | 
| Kiran Divekar | ad43f8b | 2009-08-28 17:47:59 +0530 | [diff] [blame] | 628 | 	if (!buf) | 
 | 629 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 630 |  | 
 | 631 | 	offval.offset = priv->rf_offset; | 
 | 632 | 	offval.value = 0; | 
 | 633 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 634 | 	ret = lbs_prepare_and_send_command(priv, | 
| Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 635 | 				CMD_RF_REG_ACCESS, 0, | 
 | 636 | 				CMD_OPTION_WAITFORRSP, 0, &offval); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 637 | 	mdelay(10); | 
| Amitkumar Karwar | c0bbd57 | 2009-10-08 19:38:45 -0700 | [diff] [blame] | 638 | 	if (!ret) { | 
 | 639 | 		pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n", | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 640 | 				priv->rf_offset, priv->offsetvalue.value); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 641 |  | 
| Amitkumar Karwar | c0bbd57 | 2009-10-08 19:38:45 -0700 | [diff] [blame] | 642 | 		ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); | 
 | 643 | 	} | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 644 | 	free_page(addr); | 
 | 645 |  | 
 | 646 | 	return ret; | 
 | 647 | } | 
 | 648 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 649 | static ssize_t lbs_rdrf_write(struct file *file, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 650 | 				    const char __user *userbuf, | 
 | 651 | 				    size_t count, loff_t *ppos) | 
 | 652 | { | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 653 | 	struct lbs_private *priv = file->private_data; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 654 | 	ssize_t res, buf_size; | 
 | 655 | 	unsigned long addr = get_zeroed_page(GFP_KERNEL); | 
 | 656 | 	char *buf = (char *)addr; | 
| Kiran Divekar | ad43f8b | 2009-08-28 17:47:59 +0530 | [diff] [blame] | 657 | 	if (!buf) | 
 | 658 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 659 |  | 
 | 660 | 	buf_size = min(count, len - 1); | 
 | 661 | 	if (copy_from_user(buf, userbuf, buf_size)) { | 
 | 662 | 		res = -EFAULT; | 
 | 663 | 		goto out_unlock; | 
 | 664 | 	} | 
| Jan Engelhardt | 4101dec | 2009-01-14 13:52:18 -0800 | [diff] [blame] | 665 | 	priv->rf_offset = simple_strtoul(buf, NULL, 16); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 666 | 	res = count; | 
 | 667 | out_unlock: | 
 | 668 | 	free_page(addr); | 
 | 669 | 	return res; | 
 | 670 | } | 
 | 671 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 672 | static ssize_t lbs_wrrf_write(struct file *file, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 673 | 				    const char __user *userbuf, | 
 | 674 | 				    size_t count, loff_t *ppos) | 
 | 675 | { | 
 | 676 |  | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 677 | 	struct lbs_private *priv = file->private_data; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 678 | 	ssize_t res, buf_size; | 
 | 679 | 	u32 offset, value; | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 680 | 	struct lbs_offset_value offval; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 681 | 	unsigned long addr = get_zeroed_page(GFP_KERNEL); | 
 | 682 | 	char *buf = (char *)addr; | 
| Kiran Divekar | ad43f8b | 2009-08-28 17:47:59 +0530 | [diff] [blame] | 683 | 	if (!buf) | 
 | 684 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 685 |  | 
 | 686 | 	buf_size = min(count, len - 1); | 
 | 687 | 	if (copy_from_user(buf, userbuf, buf_size)) { | 
 | 688 | 		res = -EFAULT; | 
 | 689 | 		goto out_unlock; | 
 | 690 | 	} | 
 | 691 | 	res = sscanf(buf, "%x %x", &offset, &value); | 
 | 692 | 	if (res != 2) { | 
 | 693 | 		res = -EFAULT; | 
 | 694 | 		goto out_unlock; | 
 | 695 | 	} | 
 | 696 |  | 
 | 697 | 	offval.offset = offset; | 
 | 698 | 	offval.value = value; | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 699 | 	res = lbs_prepare_and_send_command(priv, | 
| Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 700 | 				CMD_RF_REG_ACCESS, 1, | 
 | 701 | 				CMD_OPTION_WAITFORRSP, 0, &offval); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 702 | 	mdelay(10); | 
 | 703 |  | 
| Amitkumar Karwar | c0bbd57 | 2009-10-08 19:38:45 -0700 | [diff] [blame] | 704 | 	if (!res) | 
 | 705 | 		res = count; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 706 | out_unlock: | 
 | 707 | 	free_page(addr); | 
 | 708 | 	return res; | 
 | 709 | } | 
 | 710 |  | 
 | 711 | #define FOPS(fread, fwrite) { \ | 
 | 712 | 	.owner = THIS_MODULE, \ | 
 | 713 | 	.open = open_file_generic, \ | 
 | 714 | 	.read = (fread), \ | 
 | 715 | 	.write = (fwrite), \ | 
 | 716 | } | 
 | 717 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 718 | struct lbs_debugfs_files { | 
| Jan Engelhardt | 4101dec | 2009-01-14 13:52:18 -0800 | [diff] [blame] | 719 | 	const char *name; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 720 | 	int perm; | 
 | 721 | 	struct file_operations fops; | 
 | 722 | }; | 
 | 723 |  | 
| Jan Engelhardt | 4101dec | 2009-01-14 13:52:18 -0800 | [diff] [blame] | 724 | static const struct lbs_debugfs_files debugfs_files[] = { | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 725 | 	{ "info", 0444, FOPS(lbs_dev_info, write_file_dummy), }, | 
 | 726 | 	{ "getscantable", 0444, FOPS(lbs_getscantable, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 727 | 					write_file_dummy), }, | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 728 | 	{ "sleepparams", 0644, FOPS(lbs_sleepparams_read, | 
 | 729 | 				lbs_sleepparams_write), }, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 730 | }; | 
 | 731 |  | 
| Jan Engelhardt | 4101dec | 2009-01-14 13:52:18 -0800 | [diff] [blame] | 732 | static const struct lbs_debugfs_files debugfs_events_files[] = { | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 733 | 	{"low_rssi", 0644, FOPS(lbs_lowrssi_read, | 
 | 734 | 				lbs_lowrssi_write), }, | 
 | 735 | 	{"low_snr", 0644, FOPS(lbs_lowsnr_read, | 
 | 736 | 				lbs_lowsnr_write), }, | 
 | 737 | 	{"failure_count", 0644, FOPS(lbs_failcount_read, | 
 | 738 | 				lbs_failcount_write), }, | 
 | 739 | 	{"beacon_missed", 0644, FOPS(lbs_bcnmiss_read, | 
 | 740 | 				lbs_bcnmiss_write), }, | 
 | 741 | 	{"high_rssi", 0644, FOPS(lbs_highrssi_read, | 
 | 742 | 				lbs_highrssi_write), }, | 
 | 743 | 	{"high_snr", 0644, FOPS(lbs_highsnr_read, | 
 | 744 | 				lbs_highsnr_write), }, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 745 | }; | 
 | 746 |  | 
| Jan Engelhardt | 4101dec | 2009-01-14 13:52:18 -0800 | [diff] [blame] | 747 | static const struct lbs_debugfs_files debugfs_regs_files[] = { | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 748 | 	{"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), }, | 
 | 749 | 	{"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), }, | 
 | 750 | 	{"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), }, | 
 | 751 | 	{"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), }, | 
 | 752 | 	{"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), }, | 
 | 753 | 	{"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), }, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 754 | }; | 
 | 755 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 756 | void lbs_debugfs_init(void) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 757 | { | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 758 | 	if (!lbs_dir) | 
 | 759 | 		lbs_dir = debugfs_create_dir("lbs_wireless", NULL); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 760 |  | 
 | 761 | 	return; | 
 | 762 | } | 
 | 763 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 764 | void lbs_debugfs_remove(void) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 765 | { | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 766 | 	if (lbs_dir) | 
 | 767 | 		 debugfs_remove(lbs_dir); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 768 | 	return; | 
 | 769 | } | 
 | 770 |  | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 771 | void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 772 | { | 
 | 773 | 	int i; | 
| Jan Engelhardt | 4101dec | 2009-01-14 13:52:18 -0800 | [diff] [blame] | 774 | 	const struct lbs_debugfs_files *files; | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 775 | 	if (!lbs_dir) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 776 | 		goto exit; | 
 | 777 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 778 | 	priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 779 | 	if (!priv->debugfs_dir) | 
 | 780 | 		goto exit; | 
 | 781 |  | 
 | 782 | 	for (i=0; i<ARRAY_SIZE(debugfs_files); i++) { | 
 | 783 | 		files = &debugfs_files[i]; | 
 | 784 | 		priv->debugfs_files[i] = debugfs_create_file(files->name, | 
 | 785 | 							     files->perm, | 
 | 786 | 							     priv->debugfs_dir, | 
 | 787 | 							     priv, | 
 | 788 | 							     &files->fops); | 
 | 789 | 	} | 
 | 790 |  | 
 | 791 | 	priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir); | 
 | 792 | 	if (!priv->events_dir) | 
 | 793 | 		goto exit; | 
 | 794 |  | 
 | 795 | 	for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) { | 
 | 796 | 		files = &debugfs_events_files[i]; | 
 | 797 | 		priv->debugfs_events_files[i] = debugfs_create_file(files->name, | 
 | 798 | 							     files->perm, | 
 | 799 | 							     priv->events_dir, | 
 | 800 | 							     priv, | 
 | 801 | 							     &files->fops); | 
 | 802 | 	} | 
 | 803 |  | 
 | 804 | 	priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir); | 
 | 805 | 	if (!priv->regs_dir) | 
 | 806 | 		goto exit; | 
 | 807 |  | 
 | 808 | 	for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) { | 
 | 809 | 		files = &debugfs_regs_files[i]; | 
 | 810 | 		priv->debugfs_regs_files[i] = debugfs_create_file(files->name, | 
 | 811 | 							     files->perm, | 
 | 812 | 							     priv->regs_dir, | 
 | 813 | 							     priv, | 
 | 814 | 							     &files->fops); | 
 | 815 | 	} | 
 | 816 |  | 
 | 817 | #ifdef PROC_DEBUG | 
| Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 818 | 	lbs_debug_init(priv); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 819 | #endif | 
 | 820 | exit: | 
 | 821 | 	return; | 
 | 822 | } | 
 | 823 |  | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 824 | void lbs_debugfs_remove_one(struct lbs_private *priv) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 825 | { | 
 | 826 | 	int i; | 
 | 827 |  | 
 | 828 | 	for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) | 
 | 829 | 		debugfs_remove(priv->debugfs_regs_files[i]); | 
 | 830 |  | 
 | 831 | 	debugfs_remove(priv->regs_dir); | 
 | 832 |  | 
| Holger Schurig | 0b7db95 | 2007-05-24 23:47:34 -0400 | [diff] [blame] | 833 | 	for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 834 | 		debugfs_remove(priv->debugfs_events_files[i]); | 
 | 835 |  | 
 | 836 | 	debugfs_remove(priv->events_dir); | 
 | 837 | #ifdef PROC_DEBUG | 
 | 838 | 	debugfs_remove(priv->debugfs_debug); | 
 | 839 | #endif | 
 | 840 | 	for(i=0; i<ARRAY_SIZE(debugfs_files); i++) | 
 | 841 | 		debugfs_remove(priv->debugfs_files[i]); | 
| Holger Schurig | 0b7db95 | 2007-05-24 23:47:34 -0400 | [diff] [blame] | 842 | 	debugfs_remove(priv->debugfs_dir); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 843 | } | 
 | 844 |  | 
| Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 845 |  | 
 | 846 |  | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 847 | /* debug entry */ | 
 | 848 |  | 
| Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 849 | #ifdef PROC_DEBUG | 
 | 850 |  | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 851 | #define item_size(n)	(FIELD_SIZEOF(struct lbs_private, n)) | 
 | 852 | #define item_addr(n)	(offsetof(struct lbs_private, n)) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 853 |  | 
| Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 854 |  | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 855 | struct debug_data { | 
 | 856 | 	char name[32]; | 
 | 857 | 	u32 size; | 
| Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 858 | 	size_t addr; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 859 | }; | 
 | 860 |  | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 861 | /* To debug any member of struct lbs_private, simply add one line here. | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 862 |  */ | 
 | 863 | static struct debug_data items[] = { | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 864 | 	{"psmode", item_size(psmode), item_addr(psmode)}, | 
 | 865 | 	{"psstate", item_size(psstate), item_addr(psstate)}, | 
 | 866 | }; | 
 | 867 |  | 
| Tony Breeds | d2f11e0 | 2007-03-09 13:11:46 +1100 | [diff] [blame] | 868 | static int num_of_items = ARRAY_SIZE(items); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 869 |  | 
 | 870 | /** | 
 | 871 |  *  @brief proc read function | 
 | 872 |  * | 
 | 873 |  *  @param page	   pointer to buffer | 
 | 874 |  *  @param s       read data starting position | 
 | 875 |  *  @param off     offset | 
 | 876 |  *  @param cnt     counter | 
 | 877 |  *  @param eof     end of file flag | 
 | 878 |  *  @param data    data to output | 
 | 879 |  *  @return 	   number of output data | 
 | 880 |  */ | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 881 | static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 882 | 			size_t count, loff_t *ppos) | 
 | 883 | { | 
 | 884 | 	int val = 0; | 
 | 885 | 	size_t pos = 0; | 
 | 886 | 	ssize_t res; | 
 | 887 | 	char *p; | 
 | 888 | 	int i; | 
 | 889 | 	struct debug_data *d; | 
 | 890 | 	unsigned long addr = get_zeroed_page(GFP_KERNEL); | 
 | 891 | 	char *buf = (char *)addr; | 
| Kiran Divekar | ad43f8b | 2009-08-28 17:47:59 +0530 | [diff] [blame] | 892 | 	if (!buf) | 
 | 893 | 		return -ENOMEM; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 894 |  | 
 | 895 | 	p = buf; | 
 | 896 |  | 
 | 897 | 	d = (struct debug_data *)file->private_data; | 
 | 898 |  | 
 | 899 | 	for (i = 0; i < num_of_items; i++) { | 
 | 900 | 		if (d[i].size == 1) | 
 | 901 | 			val = *((u8 *) d[i].addr); | 
 | 902 | 		else if (d[i].size == 2) | 
 | 903 | 			val = *((u16 *) d[i].addr); | 
 | 904 | 		else if (d[i].size == 4) | 
 | 905 | 			val = *((u32 *) d[i].addr); | 
| Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 906 | 		else if (d[i].size == 8) | 
 | 907 | 			val = *((u64 *) d[i].addr); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 908 |  | 
 | 909 | 		pos += sprintf(p + pos, "%s=%d\n", d[i].name, val); | 
 | 910 | 	} | 
 | 911 |  | 
 | 912 | 	res = simple_read_from_buffer(userbuf, count, ppos, p, pos); | 
 | 913 |  | 
 | 914 | 	free_page(addr); | 
 | 915 | 	return res; | 
 | 916 | } | 
 | 917 |  | 
 | 918 | /** | 
 | 919 |  *  @brief proc write function | 
 | 920 |  * | 
 | 921 |  *  @param f	   file pointer | 
 | 922 |  *  @param buf     pointer to data buffer | 
 | 923 |  *  @param cnt     data number to write | 
 | 924 |  *  @param data    data to write | 
 | 925 |  *  @return 	   number of data | 
 | 926 |  */ | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 927 | static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 928 | 			    size_t cnt, loff_t *ppos) | 
 | 929 | { | 
 | 930 | 	int r, i; | 
 | 931 | 	char *pdata; | 
 | 932 | 	char *p; | 
 | 933 | 	char *p0; | 
 | 934 | 	char *p1; | 
 | 935 | 	char *p2; | 
 | 936 | 	struct debug_data *d = (struct debug_data *)f->private_data; | 
 | 937 |  | 
| Jesper Juhl | 655b4d1 | 2007-08-24 11:48:16 -0400 | [diff] [blame] | 938 | 	pdata = kmalloc(cnt, GFP_KERNEL); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 939 | 	if (pdata == NULL) | 
 | 940 | 		return 0; | 
 | 941 |  | 
 | 942 | 	if (copy_from_user(pdata, buf, cnt)) { | 
| Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 943 | 		lbs_deb_debugfs("Copy from user failed\n"); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 944 | 		kfree(pdata); | 
 | 945 | 		return 0; | 
 | 946 | 	} | 
 | 947 |  | 
 | 948 | 	p0 = pdata; | 
 | 949 | 	for (i = 0; i < num_of_items; i++) { | 
 | 950 | 		do { | 
 | 951 | 			p = strstr(p0, d[i].name); | 
 | 952 | 			if (p == NULL) | 
 | 953 | 				break; | 
 | 954 | 			p1 = strchr(p, '\n'); | 
 | 955 | 			if (p1 == NULL) | 
 | 956 | 				break; | 
 | 957 | 			p0 = p1++; | 
 | 958 | 			p2 = strchr(p, '='); | 
 | 959 | 			if (!p2) | 
 | 960 | 				break; | 
 | 961 | 			p2++; | 
| Tony Breeds | d2f11e0 | 2007-03-09 13:11:46 +1100 | [diff] [blame] | 962 | 			r = simple_strtoul(p2, NULL, 0); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 963 | 			if (d[i].size == 1) | 
 | 964 | 				*((u8 *) d[i].addr) = (u8) r; | 
 | 965 | 			else if (d[i].size == 2) | 
 | 966 | 				*((u16 *) d[i].addr) = (u16) r; | 
 | 967 | 			else if (d[i].size == 4) | 
 | 968 | 				*((u32 *) d[i].addr) = (u32) r; | 
| Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 969 | 			else if (d[i].size == 8) | 
 | 970 | 				*((u64 *) d[i].addr) = (u64) r; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 971 | 			break; | 
 | 972 | 		} while (1); | 
 | 973 | 	} | 
 | 974 | 	kfree(pdata); | 
 | 975 |  | 
| Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 976 | 	return (ssize_t)cnt; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 977 | } | 
 | 978 |  | 
| Jan Engelhardt | 4101dec | 2009-01-14 13:52:18 -0800 | [diff] [blame] | 979 | static const struct file_operations lbs_debug_fops = { | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 980 | 	.owner = THIS_MODULE, | 
 | 981 | 	.open = open_file_generic, | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 982 | 	.write = lbs_debugfs_write, | 
 | 983 | 	.read = lbs_debugfs_read, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 984 | }; | 
 | 985 |  | 
 | 986 | /** | 
 | 987 |  *  @brief create debug proc file | 
 | 988 |  * | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 989 |  *  @param priv	   pointer struct lbs_private | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 990 |  *  @param dev     pointer net_device | 
 | 991 |  *  @return 	   N/A | 
 | 992 |  */ | 
| Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 993 | static void lbs_debug_init(struct lbs_private *priv) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 994 | { | 
 | 995 | 	int i; | 
 | 996 |  | 
 | 997 | 	if (!priv->debugfs_dir) | 
 | 998 | 		return; | 
 | 999 |  | 
 | 1000 | 	for (i = 0; i < num_of_items; i++) | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1001 | 		items[i].addr += (size_t) priv; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1002 |  | 
 | 1003 | 	priv->debugfs_debug = debugfs_create_file("debug", 0644, | 
 | 1004 | 						  priv->debugfs_dir, &items[0], | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1005 | 						  &lbs_debug_fops); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1006 | } | 
| Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 1007 | #endif |