Marek Belisko | c5e6156 | 2010-12-09 16:13:54 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ft1000_proc.c - ft1000 proc interface |
| 3 | * |
| 4 | * Copyright (C) 2009-2010 Quintec |
| 5 | * (C) 2010 Open-nandra |
| 6 | * <marek.belisko@open-nandra.com> |
| 7 | * |
| 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. |
| 11 | * |
| 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. |
| 16 | * |
| 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 |
| 20 | */ |
| 21 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 22 | #include <linux/module.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/proc_fs.h> |
David Howells | 207e390 | 2013-04-08 16:06:20 +0100 | [diff] [blame^] | 25 | #include <linux/seq_file.h> |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 26 | #include <linux/netdevice.h> |
| 27 | |
| 28 | |
| 29 | #include "ft1000_usb.h" |
| 30 | |
| 31 | #define FT1000_PROC_DIR "ft1000" |
| 32 | |
| 33 | |
David Howells | 207e390 | 2013-04-08 16:06:20 +0100 | [diff] [blame^] | 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]) |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 39 | |
David Howells | 207e390 | 2013-04-08 16:06:20 +0100 | [diff] [blame^] | 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]) |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 45 | |
| 46 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 47 | #define FTNET_PROC init_net.proc_net |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 48 | |
| 49 | |
Ondrej Zary | dedbc93 | 2012-12-02 18:51:40 +0100 | [diff] [blame] | 50 | int ft1000_read_dpram16 (struct ft1000_usb *ft1000dev, u16 indx, |
Marek Belisko | e2cb7da | 2010-11-03 11:19:47 +0100 | [diff] [blame] | 51 | u8 *buffer, u8 highlow); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 52 | |
| 53 | |
David Howells | 207e390 | 2013-04-08 16:06:20 +0100 | [diff] [blame^] | 54 | static int ft1000ReadProc(struct seq_file *m, void *v) |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 55 | { |
David Howells | 207e390 | 2013-04-08 16:06:20 +0100 | [diff] [blame^] | 56 | static const char *status[] = { |
Marek Belisko | 85d47cf | 2010-12-09 16:13:51 +0100 | [diff] [blame] | 57 | "Idle (Disconnect)", |
| 58 | "Searching", |
| 59 | "Active (Connected)", |
| 60 | "Waiting for L2", |
| 61 | "Sleep", |
| 62 | "No Coverage", |
| 63 | "", |
| 64 | "", |
| 65 | }; |
David Howells | 207e390 | 2013-04-08 16:06:20 +0100 | [diff] [blame^] | 66 | static const char *signal[] = { "", "*", "**", "***", "****" }; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 67 | |
David Howells | 207e390 | 2013-04-08 16:06:20 +0100 | [diff] [blame^] | 68 | struct net_device *dev = m->private; |
| 69 | struct ft1000_info *info = netdev_priv(dev); |
| 70 | int i; |
| 71 | unsigned short ledStat; |
| 72 | unsigned short conStat; |
Marek Belisko | 85d47cf | 2010-12-09 16:13:51 +0100 | [diff] [blame] | 73 | int strength; |
| 74 | int quality; |
| 75 | struct timeval tv; |
| 76 | time_t delta; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 77 | |
Marek Belisko | 85d47cf | 2010-12-09 16:13:51 +0100 | [diff] [blame] | 78 | if (info->ProgConStat != 0xFF) { |
Ondrej Zary | 3aa2303 | 2012-12-02 12:30:19 +0100 | [diff] [blame] | 79 | ft1000_read_dpram16(info->priv, FT1000_MAG_DSP_LED, |
Marek Belisko | e2cb7da | 2010-11-03 11:19:47 +0100 | [diff] [blame] | 80 | (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX); |
Marek Belisko | 85d47cf | 2010-12-09 16:13:51 +0100 | [diff] [blame] | 81 | info->LedStat = ntohs(ledStat); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 82 | |
Ondrej Zary | 3aa2303 | 2012-12-02 12:30:19 +0100 | [diff] [blame] | 83 | ft1000_read_dpram16(info->priv, FT1000_MAG_DSP_CON_STATE, |
Marek Belisko | 85d47cf | 2010-12-09 16:13:51 +0100 | [diff] [blame] | 84 | (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX); |
| 85 | info->ConStat = ntohs(conStat); |
| 86 | do_gettimeofday(&tv); |
| 87 | delta = (tv.tv_sec - info->ConTm); |
| 88 | } else { |
| 89 | info->ConStat = 0xf; |
| 90 | delta = 0; |
| 91 | } |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 92 | |
Marek Belisko | 85d47cf | 2010-12-09 16:13:51 +0100 | [diff] [blame] | 93 | i = (info->LedStat) & 0xf; |
| 94 | switch (i) { |
| 95 | case 0x1: |
| 96 | strength = 1; |
| 97 | break; |
| 98 | case 0x3: |
| 99 | strength = 2; |
| 100 | break; |
| 101 | case 0x7: |
| 102 | strength = 3; |
| 103 | break; |
| 104 | case 0xf: |
| 105 | strength = 4; |
| 106 | break; |
| 107 | default: |
| 108 | strength = 0; |
| 109 | } |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 110 | |
Marek Belisko | 85d47cf | 2010-12-09 16:13:51 +0100 | [diff] [blame] | 111 | i = (info->LedStat >> 8) & 0xf; |
| 112 | switch (i) { |
| 113 | case 0x1: |
| 114 | quality = 1; |
| 115 | break; |
| 116 | case 0x3: |
| 117 | quality = 2; |
| 118 | break; |
| 119 | case 0x7: |
| 120 | quality = 3; |
| 121 | break; |
| 122 | case 0xf: |
| 123 | quality = 4; |
| 124 | break; |
| 125 | default: |
| 126 | quality = 0; |
| 127 | } |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 128 | |
David Howells | 207e390 | 2013-04-08 16:06:20 +0100 | [diff] [blame^] | 129 | seq_printf(m, "Connection Time: %02ld:%02ld:%02ld\n", |
Marek Belisko | 85d47cf | 2010-12-09 16:13:51 +0100 | [diff] [blame] | 130 | ((delta / 3600) % 24), ((delta / 60) % 60), (delta % 60)); |
David Howells | 207e390 | 2013-04-08 16:06:20 +0100 | [diff] [blame^] | 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]); |
| 148 | return 0; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 149 | } |
| 150 | |
David Howells | 207e390 | 2013-04-08 16:06:20 +0100 | [diff] [blame^] | 151 | /* |
| 152 | * seq_file wrappers for procfile show routines. |
| 153 | */ |
| 154 | static int ft1000_proc_open(struct inode *inode, struct file *file) |
| 155 | { |
| 156 | return single_open(file, ft1000ReadProc, PDE_DATA(inode)); |
| 157 | } |
| 158 | |
| 159 | static const struct file_operations ft1000_proc_fops = { |
| 160 | .open = ft1000_proc_open, |
| 161 | .read = seq_read, |
| 162 | .llseek = seq_lseek, |
| 163 | .release = seq_release, |
| 164 | }; |
| 165 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 166 | static int |
Marek Belisko | 92914cc | 2010-12-09 16:13:50 +0100 | [diff] [blame] | 167 | ft1000NotifyProc(struct notifier_block *this, unsigned long event, void *ptr) |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 168 | { |
Marek Belisko | 92914cc | 2010-12-09 16:13:50 +0100 | [diff] [blame] | 169 | struct net_device *dev = ptr; |
Marek Belisko | 1a88a06 | 2010-10-16 22:37:27 +0200 | [diff] [blame] | 170 | struct ft1000_info *info; |
Marek Belisko | 92914cc | 2010-12-09 16:13:50 +0100 | [diff] [blame] | 171 | struct proc_dir_entry *ft1000_proc_file; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 172 | |
Marek Belisko | 92914cc | 2010-12-09 16:13:50 +0100 | [diff] [blame] | 173 | info = netdev_priv(dev); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 174 | |
Marek Belisko | 92914cc | 2010-12-09 16:13:50 +0100 | [diff] [blame] | 175 | switch (event) { |
| 176 | case NETDEV_CHANGENAME: |
| 177 | remove_proc_entry(info->netdevname, info->ft1000_proc_dir); |
David Howells | 207e390 | 2013-04-08 16:06:20 +0100 | [diff] [blame^] | 178 | ft1000_proc_file = |
| 179 | proc_create_data(dev->name, 0644, info->ft1000_proc_dir, |
| 180 | &ft1000_proc_fops, dev); |
Marek Belisko | 92914cc | 2010-12-09 16:13:50 +0100 | [diff] [blame] | 181 | snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name); |
| 182 | break; |
| 183 | } |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 184 | |
Marek Belisko | 92914cc | 2010-12-09 16:13:50 +0100 | [diff] [blame] | 185 | return NOTIFY_DONE; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static struct notifier_block ft1000_netdev_notifier = { |
Marek Belisko | 92914cc | 2010-12-09 16:13:50 +0100 | [diff] [blame] | 189 | .notifier_call = ft1000NotifyProc, |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | |
Marek Belisko | dab56ff | 2010-12-14 09:42:27 +0100 | [diff] [blame] | 193 | int ft1000_init_proc(struct net_device *dev) |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 194 | { |
Marek Belisko | 1a88a06 | 2010-10-16 22:37:27 +0200 | [diff] [blame] | 195 | struct ft1000_info *info; |
Marek Belisko | 04c6620 | 2010-12-09 16:13:48 +0100 | [diff] [blame] | 196 | struct proc_dir_entry *ft1000_proc_file; |
Devendra Naga | f884c19 | 2012-11-24 05:01:06 -0500 | [diff] [blame] | 197 | int ret = -EINVAL; |
Marek Belisko | 5fd866f | 2010-12-09 16:13:47 +0100 | [diff] [blame] | 198 | |
Joe Perches | e33196e | 2010-11-15 13:12:32 -0800 | [diff] [blame] | 199 | info = netdev_priv(dev); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 200 | |
Marek Belisko | 04c6620 | 2010-12-09 16:13:48 +0100 | [diff] [blame] | 201 | info->ft1000_proc_dir = proc_mkdir(FT1000_PROC_DIR, FTNET_PROC); |
Marek Belisko | 5fd866f | 2010-12-09 16:13:47 +0100 | [diff] [blame] | 202 | if (info->ft1000_proc_dir == NULL) { |
| 203 | printk(KERN_WARNING "Unable to create %s dir.\n", |
| 204 | FT1000_PROC_DIR); |
Marek Belisko | 5fd866f | 2010-12-09 16:13:47 +0100 | [diff] [blame] | 205 | goto fail; |
| 206 | } |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 207 | |
Marek Belisko | 04c6620 | 2010-12-09 16:13:48 +0100 | [diff] [blame] | 208 | ft1000_proc_file = |
David Howells | 207e390 | 2013-04-08 16:06:20 +0100 | [diff] [blame^] | 209 | proc_create_data(dev->name, 0644, info->ft1000_proc_dir, |
| 210 | &ft1000_proc_fops, dev); |
Marek Belisko | 04c6620 | 2010-12-09 16:13:48 +0100 | [diff] [blame] | 211 | |
David Howells | 207e390 | 2013-04-08 16:06:20 +0100 | [diff] [blame^] | 212 | if (!ft1000_proc_file) { |
Marek Belisko | 5fd866f | 2010-12-09 16:13:47 +0100 | [diff] [blame] | 213 | printk(KERN_WARNING "Unable to create /proc entry.\n"); |
Marek Belisko | 5fd866f | 2010-12-09 16:13:47 +0100 | [diff] [blame] | 214 | goto fail_entry; |
| 215 | } |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 216 | |
Marek Belisko | 04c6620 | 2010-12-09 16:13:48 +0100 | [diff] [blame] | 217 | snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name); |
| 218 | |
Marek Belisko | 5fd866f | 2010-12-09 16:13:47 +0100 | [diff] [blame] | 219 | ret = register_netdevice_notifier(&ft1000_netdev_notifier); |
| 220 | if (ret) |
| 221 | goto fail_notif; |
| 222 | |
| 223 | return 0; |
| 224 | |
| 225 | fail_notif: |
| 226 | remove_proc_entry(info->netdevname, info->ft1000_proc_dir); |
| 227 | fail_entry: |
| 228 | remove_proc_entry(FT1000_PROC_DIR, FTNET_PROC); |
| 229 | fail: |
| 230 | return ret; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 231 | } |
| 232 | |
Marek Belisko | dab56ff | 2010-12-14 09:42:27 +0100 | [diff] [blame] | 233 | void ft1000_cleanup_proc(struct ft1000_info *info) |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 234 | { |
Marek Belisko | 04c6620 | 2010-12-09 16:13:48 +0100 | [diff] [blame] | 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); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 238 | } |