1 /*---------------------------------------------------------------------------
2 FT1000 driver for Flarion Flash OFDM NIC Device
3
4 Copyright (C) 2006 Patrik Ostrihon, All rights reserved.
5 Copyright (C) 2006 ProWeb Consulting, a.s, All rights reserved.
6
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 -----------------------------------------------------------------------------*/
18
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>
25 #include <asm/uaccess.h>
26 #include "ft1000.h"
27
28 #define FT1000_PROC "ft1000"
29 #define MAX_FILE_LEN 255
30
31 #define PUTM_TO_PAGE(len,page,args...) \
32 len += snprintf(page+len, PAGE_SIZE - len, args)
33
34 #define PUTX_TO_PAGE(len,page,message,size,var) \
35 len += snprintf(page+len, PAGE_SIZE - len, message); \
36 for(i = 0; i < (size - 1); i++) \
37 { \
38 len += snprintf(page+len, PAGE_SIZE - len, "%02x:", var[i]); \
39 } \
40 len += snprintf(page+len, PAGE_SIZE - len, "%02x\n", var[i])
41
42 #define PUTD_TO_PAGE(len,page,message,size,var) \
43 len += snprintf(page+len, PAGE_SIZE - len, message); \
44 for(i = 0; i < (size - 1); i++) \
45 { \
46 len += snprintf(page+len, PAGE_SIZE - len, "%d.", var[i]); \
47 } \
48 len += snprintf(page+len, PAGE_SIZE - len, "%d\n", var[i])
49
ft1000ReadProc(char * page,char ** start,off_t off,int count,int * eof,void * data)50 int ft1000ReadProc(char *page, char **start, off_t off,
51 int count, int *eof, void *data)
52 {
53 struct net_device *dev;
54 int len;
55 int i;
56 FT1000_INFO *info;
57 char *status[] =
58 { "Idle (Disconnect)", "Searching", "Active (Connected)",
59 "Waiting for L2", "Sleep", "No Coverage", "", ""
60 };
61 char *signal[] = { "", "*", "**", "***", "****" };
62 int strength;
63 int quality;
64 struct timeval tv;
65 time_t delta;
66
67 dev = (struct net_device *)data;
68 info = netdev_priv(dev);
69
70 if (off > 0) {
71 *eof = 1;
72 return 0;
73 }
74
75 /* Wrap-around */
76
77 if (info->AsicID == ELECTRABUZZ_ID) {
78 if (info->DspHibernateFlag == 0) {
79 if (info->ProgConStat != 0xFF) {
80 info->LedStat =
81 ft1000_read_dpram(dev, FT1000_DSP_LED);
82 info->ConStat =
83 ft1000_read_dpram(dev,
84 FT1000_DSP_CON_STATE);
85 } else {
86 info->ConStat = 0xf;
87 }
88 }
89 } else {
90 if (info->ProgConStat != 0xFF) {
91 info->LedStat =
92 ntohs(ft1000_read_dpram_mag_16
93 (dev, FT1000_MAG_DSP_LED,
94 FT1000_MAG_DSP_LED_INDX));
95 info->ConStat =
96 ntohs(ft1000_read_dpram_mag_16
97 (dev, FT1000_MAG_DSP_CON_STATE,
98 FT1000_MAG_DSP_CON_STATE_INDX));
99 } else {
100 info->ConStat = 0xf;
101 }
102 }
103
104 i = (info->LedStat) & 0xf;
105 switch (i) {
106 case 0x1:
107 strength = 1;
108 break;
109 case 0x3:
110 strength = 2;
111 break;
112 case 0x7:
113 strength = 3;
114 break;
115 case 0xf:
116 strength = 4;
117 break;
118 default:
119 strength = 0;
120 }
121
122 i = (info->LedStat >> 8) & 0xf;
123 switch (i) {
124 case 0x1:
125 quality = 1;
126 break;
127 case 0x3:
128 quality = 2;
129 break;
130 case 0x7:
131 quality = 3;
132 break;
133 case 0xf:
134 quality = 4;
135 break;
136 default:
137 quality = 0;
138 }
139
140 do_gettimeofday(&tv);
141 delta = (tv.tv_sec - info->ConTm);
142 len = 0;
143 PUTM_TO_PAGE(len, page, "Connection Time: %02ld:%02ld:%02ld\n",
144 ((delta / 3600) % 24), ((delta / 60) % 60), (delta % 60));
145 PUTM_TO_PAGE(len, page, "Connection Time[s]: %ld\n", delta);
146 PUTM_TO_PAGE(len, page, "Asic ID: %s\n",
147 (info->AsicID) ==
148 ELECTRABUZZ_ID ? "ELECTRABUZZ ASIC" : "MAGNEMITE ASIC");
149 PUTX_TO_PAGE(len, page, "SKU: ", SKUSZ, info->Sku);
150 PUTX_TO_PAGE(len, page, "EUI64: ", EUISZ, info->eui64);
151 PUTD_TO_PAGE(len, page, "DSP version number: ", DSPVERSZ, info->DspVer);
152 PUTX_TO_PAGE(len, page, "Hardware Serial Number: ", HWSERNUMSZ,
153 info->HwSerNum);
154 PUTX_TO_PAGE(len, page, "Caliberation Version: ", CALVERSZ,
155 info->RfCalVer);
156 PUTD_TO_PAGE(len, page, "Caliberation Date: ", CALDATESZ,
157 info->RfCalDate);
158 PUTM_TO_PAGE(len, page, "Media State: %s\n",
159 (info->mediastate) ? "link" : "no link");
160 PUTM_TO_PAGE(len, page, "Connection Status: %s\n",
161 status[((info->ConStat) & 0x7)]);
162 PUTM_TO_PAGE(len, page, "RX packets: %ld\n", info->stats.rx_packets);
163 PUTM_TO_PAGE(len, page, "TX packets: %ld\n", info->stats.tx_packets);
164 PUTM_TO_PAGE(len, page, "RX bytes: %ld\n", info->stats.rx_bytes);
165 PUTM_TO_PAGE(len, page, "TX bytes: %ld\n", info->stats.tx_bytes);
166 PUTM_TO_PAGE(len, page, "Signal Strength: %s\n", signal[strength]);
167 PUTM_TO_PAGE(len, page, "Signal Quality: %s\n", signal[quality]);
168 return len;
169 }
170
ft1000NotifyProc(struct notifier_block * this,unsigned long event,void * ptr)171 static int ft1000NotifyProc(struct notifier_block *this, unsigned long event,
172 void *ptr)
173 {
174 struct net_device *dev = ptr;
175 FT1000_INFO *info;
176
177 info = netdev_priv(dev);
178
179 switch (event) {
180 case NETDEV_CHANGENAME:
181 remove_proc_entry(info->netdevname, info->proc_ft1000);
182 create_proc_read_entry(dev->name, 0644, info->proc_ft1000,
183 ft1000ReadProc, dev);
184 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
185 break;
186 }
187 return NOTIFY_DONE;
188 }
189
190 static struct notifier_block ft1000_netdev_notifier = {
191 .notifier_call = ft1000NotifyProc
192 };
193
ft1000InitProc(struct net_device * dev)194 void ft1000InitProc(struct net_device *dev)
195 {
196 FT1000_INFO *info;
197
198 info = netdev_priv(dev);
199
200 info->proc_ft1000 = proc_mkdir(FT1000_PROC, init_net.proc_net);
201 create_proc_read_entry(dev->name, 0644, info->proc_ft1000,
202 ft1000ReadProc, dev);
203 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
204 register_netdevice_notifier(&ft1000_netdev_notifier);
205 }
206
ft1000CleanupProc(struct net_device * dev)207 void ft1000CleanupProc(struct net_device *dev)
208 {
209 FT1000_INFO *info;
210
211 info = netdev_priv(dev);
212
213 remove_proc_entry(dev->name, info->proc_ft1000);
214 remove_proc_entry(FT1000_PROC, init_net.proc_net);
215 unregister_netdevice_notifier(&ft1000_netdev_notifier);
216 }
217