1 /*---------------------------------------------------------------------------
2 FT1000 driver for Flarion Flash OFDM NIC Device
4 Copyright (C) 2006 Patrik Ostrihon, All rights reserved.
5 Copyright (C) 2006 ProWeb Consulting, a.s, All rights reserved.
7 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 -----------------------------------------------------------------------------*/
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/proc_fs.h>
22 #include <linux/string.h>
23 #include <linux/vmalloc.h>
24 #include <linux/netdevice.h>
26 #include <asm/uaccess.h>
29 #define FT1000_PROC "ft1000"
30 #define MAX_FILE_LEN 255
32 #define PUTM_TO_PAGE(len,page,args...) \
33 len += snprintf(page+len, PAGE_SIZE - len, args)
35 #define PUTX_TO_PAGE(len,page,message,size,var) \
36 len += snprintf(page+len, PAGE_SIZE - len, message); \
37 for(i = 0; i < (size - 1); i++) \
39 len += snprintf(page+len, PAGE_SIZE - len, "%02x:", var[i]); \
41 len += snprintf(page+len, PAGE_SIZE - len, "%02x\n", var[i])
43 #define PUTD_TO_PAGE(len,page,message,size,var) \
44 len += snprintf(page+len, PAGE_SIZE - len, message); \
45 for(i = 0; i < (size - 1); i++) \
47 len += snprintf(page+len, PAGE_SIZE - len, "%d.", var[i]); \
49 len += snprintf(page+len, PAGE_SIZE - len, "%d\n", var[i])
51 int ft1000ReadProc(char *page, char **start, off_t off,
52 int count, int *eof, void *data)
54 struct net_device *dev;
57 struct ft1000_info *info;
59 { "Idle (Disconnect)", "Searching", "Active (Connected)",
60 "Waiting for L2", "Sleep", "No Coverage", "", ""
62 char *signal[] = { "", "*", "**", "***", "****" };
68 dev = (struct net_device *)data;
69 info = netdev_priv(dev);
78 if (info->AsicID == ELECTRABUZZ_ID) {
79 if (info->ProgConStat != 0xFF) {
81 ft1000_read_dpram(dev, FT1000_DSP_LED);
83 ft1000_read_dpram(dev,
84 FT1000_DSP_CON_STATE);
89 if (info->ProgConStat != 0xFF) {
91 ntohs(ft1000_read_dpram_mag_16
92 (dev, FT1000_MAG_DSP_LED,
93 FT1000_MAG_DSP_LED_INDX));
95 ntohs(ft1000_read_dpram_mag_16
96 (dev, FT1000_MAG_DSP_CON_STATE,
97 FT1000_MAG_DSP_CON_STATE_INDX));
103 i = (info->LedStat) & 0xf;
121 i = (info->LedStat >> 8) & 0xf;
139 do_gettimeofday(&tv);
140 delta = (tv.tv_sec - info->ConTm);
142 PUTM_TO_PAGE(len, page, "Connection Time: %02ld:%02ld:%02ld\n",
143 ((delta / 3600) % 24), ((delta / 60) % 60), (delta % 60));
144 PUTM_TO_PAGE(len, page, "Connection Time[s]: %ld\n", delta);
145 PUTM_TO_PAGE(len, page, "Asic ID: %s\n",
147 ELECTRABUZZ_ID ? "ELECTRABUZZ ASIC" : "MAGNEMITE ASIC");
148 PUTX_TO_PAGE(len, page, "SKU: ", SKUSZ, info->Sku);
149 PUTX_TO_PAGE(len, page, "EUI64: ", EUISZ, info->eui64);
150 PUTD_TO_PAGE(len, page, "DSP version number: ", DSPVERSZ, info->DspVer);
151 PUTX_TO_PAGE(len, page, "Hardware Serial Number: ", HWSERNUMSZ,
153 PUTX_TO_PAGE(len, page, "Caliberation Version: ", CALVERSZ,
155 PUTD_TO_PAGE(len, page, "Caliberation Date: ", CALDATESZ,
157 PUTM_TO_PAGE(len, page, "Media State: %s\n",
158 (info->mediastate) ? "link" : "no link");
159 PUTM_TO_PAGE(len, page, "Connection Status: %s\n",
160 status[((info->ConStat) & 0x7)]);
161 PUTM_TO_PAGE(len, page, "RX packets: %ld\n", info->stats.rx_packets);
162 PUTM_TO_PAGE(len, page, "TX packets: %ld\n", info->stats.tx_packets);
163 PUTM_TO_PAGE(len, page, "RX bytes: %ld\n", info->stats.rx_bytes);
164 PUTM_TO_PAGE(len, page, "TX bytes: %ld\n", info->stats.tx_bytes);
165 PUTM_TO_PAGE(len, page, "Signal Strength: %s\n", signal[strength]);
166 PUTM_TO_PAGE(len, page, "Signal Quality: %s\n", signal[quality]);
170 static int ft1000NotifyProc(struct notifier_block *this, unsigned long event,
173 struct net_device *dev = ptr;
174 struct ft1000_info *info;
176 info = netdev_priv(dev);
179 case NETDEV_CHANGENAME:
180 remove_proc_entry(info->netdevname, info->proc_ft1000);
181 create_proc_read_entry(dev->name, 0644, info->proc_ft1000,
182 ft1000ReadProc, dev);
183 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
189 static struct notifier_block ft1000_netdev_notifier = {
190 .notifier_call = ft1000NotifyProc
193 void ft1000InitProc(struct net_device *dev)
195 struct ft1000_info *info;
197 info = netdev_priv(dev);
199 info->proc_ft1000 = proc_mkdir(FT1000_PROC, init_net.proc_net);
200 create_proc_read_entry(dev->name, 0644, info->proc_ft1000,
201 ft1000ReadProc, dev);
202 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
203 register_netdevice_notifier(&ft1000_netdev_notifier);
206 void ft1000CleanupProc(struct net_device *dev)
208 struct ft1000_info *info;
210 info = netdev_priv(dev);
212 remove_proc_entry(dev->name, info->proc_ft1000);
213 remove_proc_entry(FT1000_PROC, init_net.proc_net);
214 unregister_netdevice_notifier(&ft1000_netdev_notifier);