blob: d8294d6c9560a2127f5c7332015476e9055f1500 [file] [log] [blame]
Marek Beliskoc5e61562010-12-09 16:13:54 +01001/*
2 * ft1000_proc.c - ft1000 proc interface
3 *
4 * Copyright (C) 2009-2010 Quintec
5 * (C) 2010 Open-nandra
6 * <marek.belisko@open-nandra.com>
7 *
8 * This file is subject to the terms and conditions of the GNU General
9 * Public License. See the file "COPYING" in the main directory of this
10 * archive for more details.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
Marek Beliskof7c1be02010-09-22 07:56:27 +020022#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/proc_fs.h>
David Howells207e3902013-04-08 16:06:20 +010025#include <linux/seq_file.h>
Marek Beliskof7c1be02010-09-22 07:56:27 +020026#include <linux/netdevice.h>
27
28
29#include "ft1000_usb.h"
30
31#define FT1000_PROC_DIR "ft1000"
32
33
David Howells207e3902013-04-08 16:06:20 +010034#define seq_putx(m, message, size, var) \
35 seq_printf(m, message); \
36 for(i = 0; i < (size - 1); i++) \
37 seq_printf(m, "%02x:", var[i]); \
38 seq_printf(m, "%02x\n", var[i])
Marek Beliskof7c1be02010-09-22 07:56:27 +020039
David Howells207e3902013-04-08 16:06:20 +010040#define seq_putd(m, message, size, var) \
41 seq_printf(m, message); \
42 for(i = 0; i < (size - 1); i++) \
43 seq_printf(m, "%d.", var[i]); \
44 seq_printf(m, "%d\n", var[i])
Marek Beliskof7c1be02010-09-22 07:56:27 +020045
46
Marek Beliskof7c1be02010-09-22 07:56:27 +020047#define FTNET_PROC init_net.proc_net
Marek Beliskof7c1be02010-09-22 07:56:27 +020048
49
Ondrej Zarydedbc932012-12-02 18:51:40 +010050int ft1000_read_dpram16 (struct ft1000_usb *ft1000dev, u16 indx,
Marek Beliskoe2cb7da2010-11-03 11:19:47 +010051 u8 *buffer, u8 highlow);
Marek Beliskof7c1be02010-09-22 07:56:27 +020052
53
David Howells207e3902013-04-08 16:06:20 +010054static int ft1000ReadProc(struct seq_file *m, void *v)
Marek Beliskof7c1be02010-09-22 07:56:27 +020055{
David Howells207e3902013-04-08 16:06:20 +010056 static const char *status[] = {
Marek Belisko85d47cf2010-12-09 16:13:51 +010057 "Idle (Disconnect)",
58 "Searching",
59 "Active (Connected)",
60 "Waiting for L2",
61 "Sleep",
62 "No Coverage",
63 "",
64 "",
65 };
David Howells207e3902013-04-08 16:06:20 +010066 static const char *signal[] = { "", "*", "**", "***", "****" };
Marek Beliskof7c1be02010-09-22 07:56:27 +020067
David Howells207e3902013-04-08 16:06:20 +010068 struct net_device *dev = m->private;
69 struct ft1000_info *info = netdev_priv(dev);
70 int i;
71 unsigned short ledStat;
72 unsigned short conStat;
Marek Belisko85d47cf2010-12-09 16:13:51 +010073 int strength;
74 int quality;
75 struct timeval tv;
76 time_t delta;
Marek Beliskof7c1be02010-09-22 07:56:27 +020077
Marek Belisko85d47cf2010-12-09 16:13:51 +010078 if (info->ProgConStat != 0xFF) {
Ondrej Zary3aa23032012-12-02 12:30:19 +010079 ft1000_read_dpram16(info->priv, FT1000_MAG_DSP_LED,
Marek Beliskoe2cb7da2010-11-03 11:19:47 +010080 (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX);
Marek Belisko85d47cf2010-12-09 16:13:51 +010081 info->LedStat = ntohs(ledStat);
Marek Beliskof7c1be02010-09-22 07:56:27 +020082
Ondrej Zary3aa23032012-12-02 12:30:19 +010083 ft1000_read_dpram16(info->priv, FT1000_MAG_DSP_CON_STATE,
Marek Belisko85d47cf2010-12-09 16:13:51 +010084 (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX);
85 info->ConStat = ntohs(conStat);
86 do_gettimeofday(&tv);
87 delta = (tv.tv_sec - info->ConTm);
88 } else {
89 info->ConStat = 0xf;
90 delta = 0;
91 }
Marek Beliskof7c1be02010-09-22 07:56:27 +020092
Marek Belisko85d47cf2010-12-09 16:13:51 +010093 i = (info->LedStat) & 0xf;
94 switch (i) {
95 case 0x1:
96 strength = 1;
97 break;
98 case 0x3:
99 strength = 2;
100 break;
101 case 0x7:
102 strength = 3;
103 break;
104 case 0xf:
105 strength = 4;
106 break;
107 default:
108 strength = 0;
109 }
Marek Beliskof7c1be02010-09-22 07:56:27 +0200110
Marek Belisko85d47cf2010-12-09 16:13:51 +0100111 i = (info->LedStat >> 8) & 0xf;
112 switch (i) {
113 case 0x1:
114 quality = 1;
115 break;
116 case 0x3:
117 quality = 2;
118 break;
119 case 0x7:
120 quality = 3;
121 break;
122 case 0xf:
123 quality = 4;
124 break;
125 default:
126 quality = 0;
127 }
Marek Beliskof7c1be02010-09-22 07:56:27 +0200128
David Howells207e3902013-04-08 16:06:20 +0100129 seq_printf(m, "Connection Time: %02ld:%02ld:%02ld\n",
Marek Belisko85d47cf2010-12-09 16:13:51 +0100130 ((delta / 3600) % 24), ((delta / 60) % 60), (delta % 60));
David Howells207e3902013-04-08 16:06:20 +0100131 seq_printf(m, "Connection Time[s]: %ld\n", delta);
132 seq_printf(m, "Asic ID: %s\n",
133 (info->AsicID) == ELECTRABUZZ_ID ? "ELECTRABUZZ ASIC" : "MAGNEMITE ASIC");
134 seq_putx(m, "SKU: ", SKUSZ, info->Sku);
135 seq_putx(m, "EUI64: ", EUISZ, info->eui64);
136 seq_putd(m, "DSP version number: ", DSPVERSZ, info->DspVer);
137 seq_putx(m, "Hardware Serial Number: ", HWSERNUMSZ, info->HwSerNum);
138 seq_putx(m, "Caliberation Version: ", CALVERSZ, info->RfCalVer);
139 seq_putd(m, "Caliberation Date: ", CALDATESZ, info->RfCalDate);
140 seq_printf(m, "Media State: %s\n", (info->mediastate) ? "link" : "no link");
141 seq_printf(m, "Connection Status: %s\n", status[info->ConStat & 0x7]);
142 seq_printf(m, "RX packets: %ld\n", info->stats.rx_packets);
143 seq_printf(m, "TX packets: %ld\n", info->stats.tx_packets);
144 seq_printf(m, "RX bytes: %ld\n", info->stats.rx_bytes);
145 seq_printf(m, "TX bytes: %ld\n", info->stats.tx_bytes);
146 seq_printf(m, "Signal Strength: %s\n", signal[strength]);
147 seq_printf(m, "Signal Quality: %s\n", signal[quality]);
148 return 0;
Marek Beliskof7c1be02010-09-22 07:56:27 +0200149}
150
David Howells207e3902013-04-08 16:06:20 +0100151/*
152 * seq_file wrappers for procfile show routines.
153 */
154static int ft1000_proc_open(struct inode *inode, struct file *file)
155{
156 return single_open(file, ft1000ReadProc, PDE_DATA(inode));
157}
158
159static const struct file_operations ft1000_proc_fops = {
160 .open = ft1000_proc_open,
161 .read = seq_read,
162 .llseek = seq_lseek,
163 .release = seq_release,
164};
165
Marek Beliskof7c1be02010-09-22 07:56:27 +0200166static int
Marek Belisko92914cc2010-12-09 16:13:50 +0100167ft1000NotifyProc(struct notifier_block *this, unsigned long event, void *ptr)
Marek Beliskof7c1be02010-09-22 07:56:27 +0200168{
Marek Belisko92914cc2010-12-09 16:13:50 +0100169 struct net_device *dev = ptr;
Marek Belisko1a88a062010-10-16 22:37:27 +0200170 struct ft1000_info *info;
Marek Belisko92914cc2010-12-09 16:13:50 +0100171 struct proc_dir_entry *ft1000_proc_file;
Marek Beliskof7c1be02010-09-22 07:56:27 +0200172
Marek Belisko92914cc2010-12-09 16:13:50 +0100173 info = netdev_priv(dev);
Marek Beliskof7c1be02010-09-22 07:56:27 +0200174
Marek Belisko92914cc2010-12-09 16:13:50 +0100175 switch (event) {
176 case NETDEV_CHANGENAME:
177 remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
David Howells207e3902013-04-08 16:06:20 +0100178 ft1000_proc_file =
179 proc_create_data(dev->name, 0644, info->ft1000_proc_dir,
180 &ft1000_proc_fops, dev);
Marek Belisko92914cc2010-12-09 16:13:50 +0100181 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
182 break;
183 }
Marek Beliskof7c1be02010-09-22 07:56:27 +0200184
Marek Belisko92914cc2010-12-09 16:13:50 +0100185 return NOTIFY_DONE;
Marek Beliskof7c1be02010-09-22 07:56:27 +0200186}
187
188static struct notifier_block ft1000_netdev_notifier = {
Marek Belisko92914cc2010-12-09 16:13:50 +0100189 .notifier_call = ft1000NotifyProc,
Marek Beliskof7c1be02010-09-22 07:56:27 +0200190};
191
192
Marek Beliskodab56ff2010-12-14 09:42:27 +0100193int ft1000_init_proc(struct net_device *dev)
Marek Beliskof7c1be02010-09-22 07:56:27 +0200194{
Marek Belisko1a88a062010-10-16 22:37:27 +0200195 struct ft1000_info *info;
Marek Belisko04c66202010-12-09 16:13:48 +0100196 struct proc_dir_entry *ft1000_proc_file;
Devendra Nagaf884c192012-11-24 05:01:06 -0500197 int ret = -EINVAL;
Marek Belisko5fd866f2010-12-09 16:13:47 +0100198
Joe Perchese33196e2010-11-15 13:12:32 -0800199 info = netdev_priv(dev);
Marek Beliskof7c1be02010-09-22 07:56:27 +0200200
Marek Belisko04c66202010-12-09 16:13:48 +0100201 info->ft1000_proc_dir = proc_mkdir(FT1000_PROC_DIR, FTNET_PROC);
Marek Belisko5fd866f2010-12-09 16:13:47 +0100202 if (info->ft1000_proc_dir == NULL) {
203 printk(KERN_WARNING "Unable to create %s dir.\n",
204 FT1000_PROC_DIR);
Marek Belisko5fd866f2010-12-09 16:13:47 +0100205 goto fail;
206 }
Marek Beliskof7c1be02010-09-22 07:56:27 +0200207
Marek Belisko04c66202010-12-09 16:13:48 +0100208 ft1000_proc_file =
David Howells207e3902013-04-08 16:06:20 +0100209 proc_create_data(dev->name, 0644, info->ft1000_proc_dir,
210 &ft1000_proc_fops, dev);
Marek Belisko04c66202010-12-09 16:13:48 +0100211
David Howells207e3902013-04-08 16:06:20 +0100212 if (!ft1000_proc_file) {
Marek Belisko5fd866f2010-12-09 16:13:47 +0100213 printk(KERN_WARNING "Unable to create /proc entry.\n");
Marek Belisko5fd866f2010-12-09 16:13:47 +0100214 goto fail_entry;
215 }
Marek Beliskof7c1be02010-09-22 07:56:27 +0200216
Marek Belisko04c66202010-12-09 16:13:48 +0100217 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
218
Marek Belisko5fd866f2010-12-09 16:13:47 +0100219 ret = register_netdevice_notifier(&ft1000_netdev_notifier);
220 if (ret)
221 goto fail_notif;
222
223 return 0;
224
225fail_notif:
226 remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
227fail_entry:
228 remove_proc_entry(FT1000_PROC_DIR, FTNET_PROC);
229fail:
230 return ret;
Marek Beliskof7c1be02010-09-22 07:56:27 +0200231}
232
Marek Beliskodab56ff2010-12-14 09:42:27 +0100233void ft1000_cleanup_proc(struct ft1000_info *info)
Marek Beliskof7c1be02010-09-22 07:56:27 +0200234{
Marek Belisko04c66202010-12-09 16:13:48 +0100235 remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
236 remove_proc_entry(FT1000_PROC_DIR, FTNET_PROC);
237 unregister_netdevice_notifier(&ft1000_netdev_notifier);
Marek Beliskof7c1be02010-09-22 07:56:27 +0200238}