Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | |
| 3 | #ifdef CONFIG_PROC_FS |
| 4 | #include <linux/errno.h> |
| 5 | #include <linux/kernel.h> |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 6 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/mm.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/proc_fs.h> |
| 10 | #include <linux/time.h> |
| 11 | #include <linux/seq_file.h> |
Joe Perches | f1e1004 | 2010-01-26 11:40:11 +0000 | [diff] [blame] | 12 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/atmmpc.h> |
| 14 | #include <linux/atm.h> |
| 15 | #include "mpc.h" |
| 16 | #include "mpoa_caches.h" |
| 17 | |
| 18 | /* |
| 19 | * mpoa_proc.c: Implementation MPOA client's proc |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 20 | * file system statistics |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #if 1 |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame^] | 24 | #define dprintk(format, args...) \ |
| 25 | printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args) /* debug */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #else |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame^] | 27 | #define dprintk(format, args...) \ |
| 28 | do { if (0) \ |
| 29 | printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args);\ |
| 30 | } while (0) |
| 31 | #endif |
| 32 | |
| 33 | #if 0 |
| 34 | #define ddprintk(format, args...) \ |
| 35 | printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args) /* debug */ |
| 36 | #else |
| 37 | #define ddprintk(format, args...) \ |
| 38 | do { if (0) \ |
| 39 | printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args);\ |
| 40 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #endif |
| 42 | |
| 43 | #define STAT_FILE_NAME "mpc" /* Our statistic file's name */ |
| 44 | |
| 45 | extern struct mpoa_client *mpcs; |
| 46 | extern struct proc_dir_entry *atm_proc_root; /* from proc.c. */ |
| 47 | |
| 48 | static int proc_mpc_open(struct inode *inode, struct file *file); |
| 49 | static ssize_t proc_mpc_write(struct file *file, const char __user *buff, |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 50 | size_t nbytes, loff_t *ppos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | static int parse_qos(const char *buff); |
| 53 | |
| 54 | /* |
| 55 | * Define allowed FILE OPERATIONS |
| 56 | */ |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 57 | static const struct file_operations mpc_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | .owner = THIS_MODULE, |
| 59 | .open = proc_mpc_open, |
| 60 | .read = seq_read, |
| 61 | .llseek = seq_lseek, |
| 62 | .write = proc_mpc_write, |
| 63 | .release = seq_release, |
| 64 | }; |
| 65 | |
| 66 | /* |
| 67 | * Returns the state of an ingress cache entry as a string |
| 68 | */ |
Joe Perches | f1e1004 | 2010-01-26 11:40:11 +0000 | [diff] [blame] | 69 | static const char *ingress_state_string(int state) |
| 70 | { |
| 71 | switch (state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | case INGRESS_RESOLVING: |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 73 | return "resolving "; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | case INGRESS_RESOLVED: |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 75 | return "resolved "; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | case INGRESS_INVALID: |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 77 | return "invalid "; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | case INGRESS_REFRESHING: |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 79 | return "refreshing "; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
Joe Perches | f1e1004 | 2010-01-26 11:40:11 +0000 | [diff] [blame] | 81 | |
| 82 | return ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /* |
| 86 | * Returns the state of an egress cache entry as a string |
| 87 | */ |
Joe Perches | f1e1004 | 2010-01-26 11:40:11 +0000 | [diff] [blame] | 88 | static const char *egress_state_string(int state) |
| 89 | { |
| 90 | switch (state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | case EGRESS_RESOLVED: |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 92 | return "resolved "; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | case EGRESS_PURGE: |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 94 | return "purge "; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | case EGRESS_INVALID: |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 96 | return "invalid "; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
Joe Perches | f1e1004 | 2010-01-26 11:40:11 +0000 | [diff] [blame] | 98 | |
| 99 | return ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /* |
| 103 | * FIXME: mpcs (and per-mpc lists) have no locking whatsoever. |
| 104 | */ |
| 105 | |
| 106 | static void *mpc_start(struct seq_file *m, loff_t *pos) |
| 107 | { |
| 108 | loff_t l = *pos; |
| 109 | struct mpoa_client *mpc; |
| 110 | |
| 111 | if (!l--) |
| 112 | return SEQ_START_TOKEN; |
| 113 | for (mpc = mpcs; mpc; mpc = mpc->next) |
| 114 | if (!l--) |
| 115 | return mpc; |
| 116 | return NULL; |
| 117 | } |
| 118 | |
| 119 | static void *mpc_next(struct seq_file *m, void *v, loff_t *pos) |
| 120 | { |
| 121 | struct mpoa_client *p = v; |
| 122 | (*pos)++; |
| 123 | return v == SEQ_START_TOKEN ? mpcs : p->next; |
| 124 | } |
| 125 | |
| 126 | static void mpc_stop(struct seq_file *m, void *v) |
| 127 | { |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | * READING function - called when the /proc/atm/mpoa file is read from. |
| 132 | */ |
| 133 | static int mpc_show(struct seq_file *m, void *v) |
| 134 | { |
| 135 | struct mpoa_client *mpc = v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | int i; |
| 137 | in_cache_entry *in_entry; |
| 138 | eg_cache_entry *eg_entry; |
| 139 | struct timeval now; |
| 140 | unsigned char ip_string[16]; |
| 141 | |
| 142 | if (v == SEQ_START_TOKEN) { |
| 143 | atm_mpoa_disp_qos(m); |
| 144 | return 0; |
| 145 | } |
| 146 | |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 147 | seq_printf(m, "\nInterface %d:\n\n", mpc->dev_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | seq_printf(m, "Ingress Entries:\nIP address State Holding time Packets fwded VPI VCI\n"); |
| 149 | do_gettimeofday(&now); |
| 150 | |
| 151 | for (in_entry = mpc->in_cache; in_entry; in_entry = in_entry->next) { |
Joe Perches | f1e1004 | 2010-01-26 11:40:11 +0000 | [diff] [blame] | 152 | sprintf(ip_string, "%pI4", &in_entry->ctrl_info.in_dst_ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | seq_printf(m, "%-16s%s%-14lu%-12u", |
Joe Perches | f1e1004 | 2010-01-26 11:40:11 +0000 | [diff] [blame] | 154 | ip_string, |
| 155 | ingress_state_string(in_entry->entry_state), |
| 156 | in_entry->ctrl_info.holding_time - |
| 157 | (now.tv_sec-in_entry->tv.tv_sec), |
| 158 | in_entry->packets_fwded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | if (in_entry->shortcut) |
Joe Perches | f1e1004 | 2010-01-26 11:40:11 +0000 | [diff] [blame] | 160 | seq_printf(m, " %-3d %-3d", |
| 161 | in_entry->shortcut->vpi, |
| 162 | in_entry->shortcut->vci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | seq_printf(m, "\n"); |
| 164 | } |
| 165 | |
| 166 | seq_printf(m, "\n"); |
| 167 | seq_printf(m, "Egress Entries:\nIngress MPC ATM addr\nCache-id State Holding time Packets recvd Latest IP addr VPI VCI\n"); |
| 168 | for (eg_entry = mpc->eg_cache; eg_entry; eg_entry = eg_entry->next) { |
| 169 | unsigned char *p = eg_entry->ctrl_info.in_MPC_data_ATM_addr; |
Joe Perches | f1e1004 | 2010-01-26 11:40:11 +0000 | [diff] [blame] | 170 | for (i = 0; i < ATM_ESA_LEN; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | seq_printf(m, "%02x", p[i]); |
| 172 | seq_printf(m, "\n%-16lu%s%-14lu%-15u", |
| 173 | (unsigned long)ntohl(eg_entry->ctrl_info.cache_id), |
| 174 | egress_state_string(eg_entry->entry_state), |
Joe Perches | f1e1004 | 2010-01-26 11:40:11 +0000 | [diff] [blame] | 175 | (eg_entry->ctrl_info.holding_time - |
| 176 | (now.tv_sec-eg_entry->tv.tv_sec)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | eg_entry->packets_rcvd); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | /* latest IP address */ |
Joe Perches | f1e1004 | 2010-01-26 11:40:11 +0000 | [diff] [blame] | 180 | sprintf(ip_string, "%pI4", &eg_entry->latest_ip_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | seq_printf(m, "%-16s", ip_string); |
| 182 | |
| 183 | if (eg_entry->shortcut) |
Joe Perches | f1e1004 | 2010-01-26 11:40:11 +0000 | [diff] [blame] | 184 | seq_printf(m, " %-3d %-3d", |
| 185 | eg_entry->shortcut->vpi, |
| 186 | eg_entry->shortcut->vci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | seq_printf(m, "\n"); |
| 188 | } |
| 189 | seq_printf(m, "\n"); |
| 190 | return 0; |
| 191 | } |
| 192 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 193 | static const struct seq_operations mpc_op = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | .start = mpc_start, |
| 195 | .next = mpc_next, |
| 196 | .stop = mpc_stop, |
| 197 | .show = mpc_show |
| 198 | }; |
| 199 | |
| 200 | static int proc_mpc_open(struct inode *inode, struct file *file) |
| 201 | { |
| 202 | return seq_open(file, &mpc_op); |
| 203 | } |
| 204 | |
| 205 | static ssize_t proc_mpc_write(struct file *file, const char __user *buff, |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 206 | size_t nbytes, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | { |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 208 | char *page, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | unsigned len; |
| 210 | |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 211 | if (nbytes == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | return 0; |
| 213 | |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 214 | if (nbytes >= PAGE_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | nbytes = PAGE_SIZE-1; |
| 216 | |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 217 | page = (char *)__get_free_page(GFP_KERNEL); |
| 218 | if (!page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | return -ENOMEM; |
| 220 | |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 221 | for (p = page, len = 0; len < nbytes; p++, len++) { |
| 222 | if (get_user(*p, buff++)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | free_page((unsigned long)page); |
| 224 | return -EFAULT; |
| 225 | } |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 226 | if (*p == '\0' || *p == '\n') |
| 227 | break; |
| 228 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 230 | *p = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
| 232 | if (!parse_qos(page)) |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 233 | printk("mpoa: proc_mpc_write: could not parse '%s'\n", page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 235 | free_page((unsigned long)page); |
| 236 | |
| 237 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static int parse_qos(const char *buff) |
| 241 | { |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 242 | /* possible lines look like this |
| 243 | * add 130.230.54.142 tx=max_pcr,max_sdu rx=max_pcr,max_sdu |
| 244 | */ |
| 245 | unsigned char ip[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | int tx_pcr, tx_sdu, rx_pcr, rx_sdu; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 247 | __be32 ipaddr; |
| 248 | struct atm_qos qos; |
| 249 | |
| 250 | memset(&qos, 0, sizeof(struct atm_qos)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | if (sscanf(buff, "del %hhu.%hhu.%hhu.%hhu", |
| 253 | ip, ip+1, ip+2, ip+3) == 4) { |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 254 | ipaddr = *(__be32 *)ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | return atm_mpoa_delete_qos(atm_mpoa_search_qos(ipaddr)); |
| 256 | } |
| 257 | |
| 258 | if (sscanf(buff, "add %hhu.%hhu.%hhu.%hhu tx=%d,%d rx=tx", |
| 259 | ip, ip+1, ip+2, ip+3, &tx_pcr, &tx_sdu) == 6) { |
| 260 | rx_pcr = tx_pcr; |
| 261 | rx_sdu = tx_sdu; |
| 262 | } else if (sscanf(buff, "add %hhu.%hhu.%hhu.%hhu tx=%d,%d rx=%d,%d", |
| 263 | ip, ip+1, ip+2, ip+3, &tx_pcr, &tx_sdu, &rx_pcr, &rx_sdu) != 8) |
| 264 | return 0; |
| 265 | |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 266 | ipaddr = *(__be32 *)ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | qos.txtp.traffic_class = ATM_CBR; |
| 268 | qos.txtp.max_pcr = tx_pcr; |
| 269 | qos.txtp.max_sdu = tx_sdu; |
| 270 | qos.rxtp.traffic_class = ATM_CBR; |
| 271 | qos.rxtp.max_pcr = rx_pcr; |
| 272 | qos.rxtp.max_sdu = rx_sdu; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 273 | qos.aal = ATM_AAL5; |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame^] | 274 | dprintk("parse_qos(): setting qos paramameters to tx=%d,%d rx=%d,%d\n", |
| 275 | qos.txtp.max_pcr, qos.txtp.max_sdu, |
| 276 | qos.rxtp.max_pcr, qos.rxtp.max_sdu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | atm_mpoa_add_qos(ipaddr, &qos); |
| 279 | return 1; |
| 280 | } |
| 281 | |
| 282 | /* |
| 283 | * INITIALIZATION function - called when module is initialized/loaded. |
| 284 | */ |
| 285 | int mpc_proc_init(void) |
| 286 | { |
| 287 | struct proc_dir_entry *p; |
| 288 | |
Wang Chen | 16e297b | 2008-02-28 13:55:45 -0800 | [diff] [blame] | 289 | p = proc_create(STAT_FILE_NAME, 0, atm_proc_root, &mpc_file_operations); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | if (!p) { |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 291 | pr_err("Unable to initialize /proc/atm/%s\n", STAT_FILE_NAME); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 292 | return -ENOMEM; |
| 293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * DELETING function - called when module is removed. |
| 299 | */ |
| 300 | void mpc_proc_clean(void) |
| 301 | { |
Joe Perches | f1e1004 | 2010-01-26 11:40:11 +0000 | [diff] [blame] | 302 | remove_proc_entry(STAT_FILE_NAME, atm_proc_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | #endif /* CONFIG_PROC_FS */ |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |