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