blob: 21b369e0150f327b639b4d56f9165f83c675b650 [file] [log] [blame]
Marek Beliskof7c1be02010-09-22 07:56:27 +02001/*---------------------------------------------------------------------------
2 FT1000 driver for Flarion Flash OFDM NIC Device
Greg Kroah-Hartmanbf3146c2010-09-22 08:34:49 -07003
Marek Beliskof7c1be02010-09-22 07:56:27 +02004 Copyright (C) 2006 Patrik Ostrihon, All rights reserved.
5 Copyright (C) 2006 ProWeb Consulting, a.s, All rights reserved.
Greg Kroah-Hartmanbf3146c2010-09-22 08:34:49 -07006
Marek Beliskof7c1be02010-09-22 07:56:27 +02007 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2 of the License, or (at your option) any
10 later version. This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details. You should have received a copy of the GNU General Public
14 License along with this program; if not, write to the
15 Free Software Foundation, Inc., 59 Temple Place -
16 Suite 330, Boston, MA 02111-1307, USA.
17-----------------------------------------------------------------------------*/
18
19#include <linux/module.h>
20#include <linux/kernel.h>
21#include <linux/proc_fs.h>
David Howells207e3902013-04-08 16:06:20 +010022#include <linux/seq_file.h>
Marek Beliskof7c1be02010-09-22 07:56:27 +020023#include <linux/string.h>
24#include <linux/vmalloc.h>
25#include <linux/netdevice.h>
Paul Gortmakerc060ae72011-07-31 02:44:05 -040026#include <asm/io.h>
Marek Beliskof7c1be02010-09-22 07:56:27 +020027#include <asm/uaccess.h>
28#include "ft1000.h"
29
30#define FT1000_PROC "ft1000"
31#define MAX_FILE_LEN 255
32
David Howells207e3902013-04-08 16:06:20 +010033#define seq_putx(m, message, size, var) \
34 seq_printf(m, message); \
Devendra Naga95f28252012-07-07 17:35:18 +053035 for(i = 0; i < (size - 1); i++) { \
David Howells207e3902013-04-08 16:06:20 +010036 seq_printf(m, "%02x:", var[i]); \
Marek Beliskof7c1be02010-09-22 07:56:27 +020037 } \
David Howells207e3902013-04-08 16:06:20 +010038 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); \
Devendra Naga95f28252012-07-07 17:35:18 +053042 for(i = 0; i < (size - 1); i++) { \
David Howells207e3902013-04-08 16:06:20 +010043 seq_printf(m, "%d.", var[i]); \
Marek Beliskof7c1be02010-09-22 07:56:27 +020044 } \
David Howells207e3902013-04-08 16:06:20 +010045 seq_printf(m, "%d\n", var[i])
Marek Beliskof7c1be02010-09-22 07:56:27 +020046
David Howells207e3902013-04-08 16:06:20 +010047static int ft1000ReadProc(struct seq_file *m, void *v)
Marek Beliskof7c1be02010-09-22 07:56:27 +020048{
David Howells207e3902013-04-08 16:06:20 +010049 static const char *status[] = {
Devendra Naga95f28252012-07-07 17:35:18 +053050 "Idle (Disconnect)", "Searching", "Active (Connected)",
Marek Beliskof7c1be02010-09-22 07:56:27 +020051 "Waiting for L2", "Sleep", "No Coverage", "", ""
52 };
David Howells207e3902013-04-08 16:06:20 +010053 static const char *signal[] = { "", "*", "**", "***", "****" };
54
55 struct net_device *dev = m->private;
56 struct ft1000_info *info = netdev_priv(dev);
57 int i;
Marek Beliskof7c1be02010-09-22 07:56:27 +020058 int strength;
59 int quality;
60 struct timeval tv;
61 time_t delta;
62
Marek Beliskof7c1be02010-09-22 07:56:27 +020063 if (info->AsicID == ELECTRABUZZ_ID) {
Ondrej Zarycefe8ad2011-07-01 00:03:46 +020064 if (info->ProgConStat != 0xFF) {
65 info->LedStat =
66 ft1000_read_dpram(dev, FT1000_DSP_LED);
67 info->ConStat =
David Howells207e3902013-04-08 16:06:20 +010068 ft1000_read_dpram(dev, FT1000_DSP_CON_STATE);
Ondrej Zarycefe8ad2011-07-01 00:03:46 +020069 } else {
70 info->ConStat = 0xf;
Marek Beliskof7c1be02010-09-22 07:56:27 +020071 }
72 } else {
73 if (info->ProgConStat != 0xFF) {
74 info->LedStat =
David Howells207e3902013-04-08 16:06:20 +010075 ntohs(ft1000_read_dpram_mag_16(
76 dev, FT1000_MAG_DSP_LED,
77 FT1000_MAG_DSP_LED_INDX));
Marek Beliskof7c1be02010-09-22 07:56:27 +020078 info->ConStat =
David Howells207e3902013-04-08 16:06:20 +010079 ntohs(ft1000_read_dpram_mag_16(
80 dev, FT1000_MAG_DSP_CON_STATE,
81 FT1000_MAG_DSP_CON_STATE_INDX));
Marek Beliskof7c1be02010-09-22 07:56:27 +020082 } else {
83 info->ConStat = 0xf;
84 }
85 }
86
87 i = (info->LedStat) & 0xf;
88 switch (i) {
89 case 0x1:
90 strength = 1;
91 break;
92 case 0x3:
93 strength = 2;
94 break;
95 case 0x7:
96 strength = 3;
97 break;
98 case 0xf:
99 strength = 4;
100 break;
101 default:
102 strength = 0;
103 }
104
105 i = (info->LedStat >> 8) & 0xf;
106 switch (i) {
107 case 0x1:
108 quality = 1;
109 break;
110 case 0x3:
111 quality = 2;
112 break;
113 case 0x7:
114 quality = 3;
115 break;
116 case 0xf:
117 quality = 4;
118 break;
119 default:
120 quality = 0;
121 }
122
123 do_gettimeofday(&tv);
David Howells207e3902013-04-08 16:06:20 +0100124 delta = tv.tv_sec - info->ConTm;
125 seq_printf(m, "Connection Time: %02ld:%02ld:%02ld\n",
Marek Beliskof7c1be02010-09-22 07:56:27 +0200126 ((delta / 3600) % 24), ((delta / 60) % 60), (delta % 60));
David Howells207e3902013-04-08 16:06:20 +0100127 seq_printf(m, "Connection Time[s]: %ld\n", delta);
128 seq_printf(m, "Asic ID: %s\n",
129 info->AsicID ==
Marek Beliskof7c1be02010-09-22 07:56:27 +0200130 ELECTRABUZZ_ID ? "ELECTRABUZZ ASIC" : "MAGNEMITE ASIC");
David Howells207e3902013-04-08 16:06:20 +0100131 seq_putx(m, "SKU: ", SKUSZ, info->Sku);
132 seq_putx(m, "EUI64: ", EUISZ, info->eui64);
133 seq_putd(m, "DSP version number: ", DSPVERSZ, info->DspVer);
134 seq_putx(m, "Hardware Serial Number: ", HWSERNUMSZ, info->HwSerNum);
135 seq_putx(m, "Caliberation Version: ", CALVERSZ, info->RfCalVer);
136 seq_putd(m, "Caliberation Date: ", CALDATESZ, info->RfCalDate);
137 seq_printf(m, "Media State: %s\n",
Marek Beliskof7c1be02010-09-22 07:56:27 +0200138 (info->mediastate) ? "link" : "no link");
David Howells207e3902013-04-08 16:06:20 +0100139 seq_printf(m, "Connection Status: %s\n", status[info->ConStat & 0x7]);
140 seq_printf(m, "RX packets: %ld\n", info->stats.rx_packets);
141 seq_printf(m, "TX packets: %ld\n", info->stats.tx_packets);
142 seq_printf(m, "RX bytes: %ld\n", info->stats.rx_bytes);
143 seq_printf(m, "TX bytes: %ld\n", info->stats.tx_bytes);
144 seq_printf(m, "Signal Strength: %s\n", signal[strength]);
145 seq_printf(m, "Signal Quality: %s\n", signal[quality]);
146 return 0;
Marek Beliskof7c1be02010-09-22 07:56:27 +0200147}
148
David Howells207e3902013-04-08 16:06:20 +0100149/*
150 * seq_file wrappers for procfile show routines.
151 */
152static int ft1000_proc_open(struct inode *inode, struct file *file)
153{
154 return single_open(file, ft1000ReadProc, PDE_DATA(inode));
155}
156
157static const struct file_operations ft1000_proc_fops = {
158 .open = ft1000_proc_open,
159 .read = seq_read,
160 .llseek = seq_lseek,
161 .release = seq_release,
162};
163
Marek Beliskof7c1be02010-09-22 07:56:27 +0200164static int ft1000NotifyProc(struct notifier_block *this, unsigned long event,
165 void *ptr)
166{
167 struct net_device *dev = ptr;
Ondrej Zaryd3706552011-07-01 00:03:42 +0200168 struct ft1000_info *info;
Marek Beliskof7c1be02010-09-22 07:56:27 +0200169
Joe Perchese33196e2010-11-15 13:12:32 -0800170 info = netdev_priv(dev);
Marek Beliskof7c1be02010-09-22 07:56:27 +0200171
172 switch (event) {
173 case NETDEV_CHANGENAME:
Ondrej Zary3aa23032012-12-02 12:30:19 +0100174 remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
David Howells207e3902013-04-08 16:06:20 +0100175 proc_create_data(dev->name, 0644, info->ft1000_proc_dir,
176 &ft1000_proc_fops, dev);
Marek Beliskof7c1be02010-09-22 07:56:27 +0200177 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
178 break;
179 }
180 return NOTIFY_DONE;
181}
182
183static struct notifier_block ft1000_netdev_notifier = {
184 .notifier_call = ft1000NotifyProc
185};
186
187void ft1000InitProc(struct net_device *dev)
188{
Ondrej Zaryd3706552011-07-01 00:03:42 +0200189 struct ft1000_info *info;
Marek Beliskof7c1be02010-09-22 07:56:27 +0200190
Joe Perchese33196e2010-11-15 13:12:32 -0800191 info = netdev_priv(dev);
Marek Beliskof7c1be02010-09-22 07:56:27 +0200192
Ondrej Zary3aa23032012-12-02 12:30:19 +0100193 info->ft1000_proc_dir = proc_mkdir(FT1000_PROC, init_net.proc_net);
David Howells207e3902013-04-08 16:06:20 +0100194
195 proc_create_data(dev->name, 0644, info->ft1000_proc_dir,
196 &ft1000_proc_fops, dev);
197
Marek Beliskof7c1be02010-09-22 07:56:27 +0200198 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
199 register_netdevice_notifier(&ft1000_netdev_notifier);
200}
201
202void ft1000CleanupProc(struct net_device *dev)
203{
Ondrej Zaryd3706552011-07-01 00:03:42 +0200204 struct ft1000_info *info;
Marek Beliskof7c1be02010-09-22 07:56:27 +0200205
Joe Perchese33196e2010-11-15 13:12:32 -0800206 info = netdev_priv(dev);
Marek Beliskof7c1be02010-09-22 07:56:27 +0200207
Ondrej Zary3aa23032012-12-02 12:30:19 +0100208 remove_proc_entry(dev->name, info->ft1000_proc_dir);
Marek Beliskof7c1be02010-09-22 07:56:27 +0200209 remove_proc_entry(FT1000_PROC, init_net.proc_net);
210 unregister_netdevice_notifier(&ft1000_netdev_notifier);
211}