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/seq_file.h>
26 #include <linux/netdevice.h>
29 #include "ft1000_usb.h"
31 #define FT1000_PROC_DIR "ft1000"
34 #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])
40 #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])
47 #define FTNET_PROC init_net.proc_net
50 int ft1000_read_dpram16 (struct ft1000_usb
*ft1000dev
, u16 indx
,
51 u8
*buffer
, u8 highlow
);
54 static int ft1000ReadProc(struct seq_file
*m
, void *v
)
56 static const char *status
[] = {
66 static const char *signal
[] = { "", "*", "**", "***", "****" };
68 struct net_device
*dev
= m
->private;
69 struct ft1000_info
*info
= netdev_priv(dev
);
71 unsigned short ledStat
;
72 unsigned short conStat
;
78 if (info
->ProgConStat
!= 0xFF) {
79 ft1000_read_dpram16(info
->priv
, FT1000_MAG_DSP_LED
,
80 (u8
*)&ledStat
, FT1000_MAG_DSP_LED_INDX
);
81 info
->LedStat
= ntohs(ledStat
);
83 ft1000_read_dpram16(info
->priv
, FT1000_MAG_DSP_CON_STATE
,
84 (u8
*)&conStat
, FT1000_MAG_DSP_CON_STATE_INDX
);
85 info
->ConStat
= ntohs(conStat
);
87 delta
= (tv
.tv_sec
- info
->ConTm
);
93 i
= (info
->LedStat
) & 0xf;
111 i
= (info
->LedStat
>> 8) & 0xf;
129 seq_printf(m
, "Connection Time: %02ld:%02ld:%02ld\n",
130 ((delta
/ 3600) % 24), ((delta
/ 60) % 60), (delta
% 60));
131 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
]);
152 * seq_file wrappers for procfile show routines.
154 static int ft1000_proc_open(struct inode
*inode
, struct file
*file
)
156 return single_open(file
, ft1000ReadProc
, PDE_DATA(inode
));
159 static const struct file_operations ft1000_proc_fops
= {
160 .open
= ft1000_proc_open
,
163 .release
= single_release
,
167 ft1000NotifyProc(struct notifier_block
*this, unsigned long event
, void *ptr
)
169 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
170 struct ft1000_info
*info
;
171 struct proc_dir_entry
*ft1000_proc_file
;
173 info
= netdev_priv(dev
);
176 case NETDEV_CHANGENAME
:
177 remove_proc_entry(info
->netdevname
, info
->ft1000_proc_dir
);
179 proc_create_data(dev
->name
, 0644, info
->ft1000_proc_dir
,
180 &ft1000_proc_fops
, dev
);
181 snprintf(info
->netdevname
, IFNAMSIZ
, "%s", dev
->name
);
188 static struct notifier_block ft1000_netdev_notifier
= {
189 .notifier_call
= ft1000NotifyProc
,
193 int ft1000_init_proc(struct net_device
*dev
)
195 struct ft1000_info
*info
;
196 struct proc_dir_entry
*ft1000_proc_file
;
199 info
= netdev_priv(dev
);
201 info
->ft1000_proc_dir
= proc_mkdir(FT1000_PROC_DIR
, FTNET_PROC
);
202 if (info
->ft1000_proc_dir
== NULL
) {
203 printk(KERN_WARNING
"Unable to create %s dir.\n",
209 proc_create_data(dev
->name
, 0644, info
->ft1000_proc_dir
,
210 &ft1000_proc_fops
, dev
);
212 if (!ft1000_proc_file
) {
213 printk(KERN_WARNING
"Unable to create /proc entry.\n");
217 snprintf(info
->netdevname
, IFNAMSIZ
, "%s", dev
->name
);
219 ret
= register_netdevice_notifier(&ft1000_netdev_notifier
);
226 remove_proc_entry(info
->netdevname
, info
->ft1000_proc_dir
);
228 remove_proc_entry(FT1000_PROC_DIR
, FTNET_PROC
);
233 void ft1000_cleanup_proc(struct ft1000_info
*info
)
235 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
);