2 * ft1000_proc.c - ft1000 proc interface
4 * Copyright (C) 2009-2010 Quintec
6 * <marek.belisko@open-nandra.com>
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.
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.
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
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/proc_fs.h>
25 #include <linux/netdevice.h>
28 #include "ft1000_usb.h"
30 #define FT1000_PROC_DIR "ft1000"
33 #define PUTM_TO_PAGE(len,page,args...) \
34 len += snprintf(page+len, PAGE_SIZE - len, args)
36 #define PUTX_TO_PAGE(len,page,message,size,var) \
37 len += snprintf(page+len, PAGE_SIZE - len, message); \
38 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++) {\
46 len += snprintf(page+len, PAGE_SIZE - len, "%d.", var[i]); \
48 len += snprintf(page+len, PAGE_SIZE - len, "%d\n", var[i])
51 #define FTNET_PROC init_net.proc_net
54 int ft1000_read_dpram16 (struct ft1000_usb *ft1000dev, u16 indx,
55 u8 *buffer, u8 highlow);
59 ft1000ReadProc(char *page, char **start, off_t off, int count, int *eof,
62 struct net_device *dev;
65 unsigned short ledStat;
66 unsigned short conStat;
68 struct ft1000_info *info;
81 char *signal[] = { "", "*", "**", "***", "****" };
87 dev = (struct net_device *) data;
88 info = netdev_priv(dev);
96 if (info->ProgConStat != 0xFF) {
97 ft1000_read_dpram16(info->priv, FT1000_MAG_DSP_LED,
98 (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX);
99 info->LedStat = ntohs(ledStat);
101 ft1000_read_dpram16(info->priv, FT1000_MAG_DSP_CON_STATE,
102 (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX);
103 info->ConStat = ntohs(conStat);
104 do_gettimeofday(&tv);
105 delta = (tv.tv_sec - info->ConTm);
111 i = (info->LedStat) & 0xf;
129 i = (info->LedStat >> 8) & 0xf;
148 PUTM_TO_PAGE(len, page, "Connection Time: %02ld:%02ld:%02ld\n",
149 ((delta / 3600) % 24), ((delta / 60) % 60), (delta % 60));
150 PUTM_TO_PAGE(len, page, "Connection Time[s]: %ld\n", delta);
151 PUTM_TO_PAGE(len, page, "Asic ID: %s\n",
153 ELECTRABUZZ_ID ? "ELECTRABUZZ ASIC" : "MAGNEMITE ASIC");
154 PUTX_TO_PAGE(len, page, "SKU: ", SKUSZ, info->Sku);
155 PUTX_TO_PAGE(len, page, "EUI64: ", EUISZ, info->eui64);
156 PUTD_TO_PAGE(len, page, "DSP version number: ", DSPVERSZ, info->DspVer);
157 PUTX_TO_PAGE(len, page, "Hardware Serial Number: ", HWSERNUMSZ,
159 PUTX_TO_PAGE(len, page, "Caliberation Version: ", CALVERSZ,
161 PUTD_TO_PAGE(len, page, "Caliberation Date: ", CALDATESZ,
163 PUTM_TO_PAGE(len, page, "Media State: %s\n",
164 (info->mediastate) ? "link" : "no link");
165 PUTM_TO_PAGE(len, page, "Connection Status: %s\n",
166 status[((info->ConStat) & 0x7)]);
167 PUTM_TO_PAGE(len, page, "RX packets: %ld\n", info->stats.rx_packets);
168 PUTM_TO_PAGE(len, page, "TX packets: %ld\n", info->stats.tx_packets);
169 PUTM_TO_PAGE(len, page, "RX bytes: %ld\n", info->stats.rx_bytes);
170 PUTM_TO_PAGE(len, page, "TX bytes: %ld\n", info->stats.tx_bytes);
171 PUTM_TO_PAGE(len, page, "Signal Strength: %s\n", signal[strength]);
172 PUTM_TO_PAGE(len, page, "Signal Quality: %s\n", signal[quality]);
178 ft1000NotifyProc(struct notifier_block *this, unsigned long event, void *ptr)
180 struct net_device *dev = ptr;
181 struct ft1000_info *info;
182 struct proc_dir_entry *ft1000_proc_file;
184 info = netdev_priv(dev);
187 case NETDEV_CHANGENAME:
188 remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
189 ft1000_proc_file = create_proc_read_entry(dev->name, 0644,
190 info->ft1000_proc_dir,
191 ft1000ReadProc, dev);
192 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
199 static struct notifier_block ft1000_netdev_notifier = {
200 .notifier_call = ft1000NotifyProc,
204 int ft1000_init_proc(struct net_device *dev)
206 struct ft1000_info *info;
207 struct proc_dir_entry *ft1000_proc_file;
210 info = netdev_priv(dev);
212 info->ft1000_proc_dir = proc_mkdir(FT1000_PROC_DIR, FTNET_PROC);
213 if (info->ft1000_proc_dir == NULL) {
214 printk(KERN_WARNING "Unable to create %s dir.\n",
220 create_proc_read_entry(dev->name, 0644,
221 info->ft1000_proc_dir, ft1000ReadProc, dev);
223 if (ft1000_proc_file == NULL) {
224 printk(KERN_WARNING "Unable to create /proc entry.\n");
228 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
230 ret = register_netdevice_notifier(&ft1000_netdev_notifier);
237 remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
239 remove_proc_entry(FT1000_PROC_DIR, FTNET_PROC);
244 void ft1000_cleanup_proc(struct ft1000_info *info)
246 remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
247 remove_proc_entry(FT1000_PROC_DIR, FTNET_PROC);
248 unregister_netdevice_notifier(&ft1000_netdev_notifier);