Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Kernel CAPI 2.0 Module - /proc/capi handling |
| 3 | * |
| 4 | * Copyright 1999 by Carsten Paeth <calle@calle.de> |
| 5 | * Copyright 2002 by Kai Germaschewski <kai@germaschewski.name> |
| 6 | * |
| 7 | * This software may be used and distributed according to the terms |
| 8 | * of the GNU General Public License, incorporated herein by reference. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | |
| 13 | #include "kcapi.h" |
| 14 | #include <linux/proc_fs.h> |
| 15 | #include <linux/seq_file.h> |
| 16 | #include <linux/init.h> |
| 17 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame^] | 18 | static char *state2str(unsigned short state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame^] | 20 | switch (state) { |
| 21 | case CAPI_CTR_DETECTED: return "detected"; |
| 22 | case CAPI_CTR_LOADING: return "loading"; |
| 23 | case CAPI_CTR_RUNNING: return "running"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | default: return "???"; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | // /proc/capi |
| 29 | // =========================================================================== |
| 30 | |
| 31 | // /proc/capi/controller: |
| 32 | // cnr driver cardstate name driverinfo |
| 33 | // /proc/capi/contrstats: |
| 34 | // cnr nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt |
| 35 | // --------------------------------------------------------------------------- |
| 36 | |
| 37 | static void *controller_start(struct seq_file *seq, loff_t *pos) |
| 38 | { |
| 39 | if (*pos < CAPI_MAXCONTR) |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame^] | 40 | return &capi_controller[*pos]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | return NULL; |
| 43 | } |
| 44 | |
| 45 | static void *controller_next(struct seq_file *seq, void *v, loff_t *pos) |
| 46 | { |
| 47 | ++*pos; |
| 48 | if (*pos < CAPI_MAXCONTR) |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame^] | 49 | return &capi_controller[*pos]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | return NULL; |
| 52 | } |
| 53 | |
| 54 | static void controller_stop(struct seq_file *seq, void *v) |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | static int controller_show(struct seq_file *seq, void *v) |
| 59 | { |
| 60 | struct capi_ctr *ctr = *(struct capi_ctr **) v; |
| 61 | |
| 62 | if (!ctr) |
| 63 | return 0; |
| 64 | |
| 65 | seq_printf(seq, "%d %-10s %-8s %-16s %s\n", |
| 66 | ctr->cnr, ctr->driver_name, |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame^] | 67 | state2str(ctr->state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | ctr->name, |
| 69 | ctr->procinfo ? ctr->procinfo(ctr) : ""); |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static int contrstats_show(struct seq_file *seq, void *v) |
| 75 | { |
| 76 | struct capi_ctr *ctr = *(struct capi_ctr **) v; |
| 77 | |
| 78 | if (!ctr) |
| 79 | return 0; |
| 80 | |
| 81 | seq_printf(seq, "%d %lu %lu %lu %lu\n", |
| 82 | ctr->cnr, |
| 83 | ctr->nrecvctlpkt, |
| 84 | ctr->nrecvdatapkt, |
| 85 | ctr->nsentctlpkt, |
| 86 | ctr->nsentdatapkt); |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 91 | static const struct seq_operations seq_controller_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | .start = controller_start, |
| 93 | .next = controller_next, |
| 94 | .stop = controller_stop, |
| 95 | .show = controller_show, |
| 96 | }; |
| 97 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 98 | static const struct seq_operations seq_contrstats_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | .start = controller_start, |
| 100 | .next = controller_next, |
| 101 | .stop = controller_stop, |
| 102 | .show = contrstats_show, |
| 103 | }; |
| 104 | |
| 105 | static int seq_controller_open(struct inode *inode, struct file *file) |
| 106 | { |
| 107 | return seq_open(file, &seq_controller_ops); |
| 108 | } |
| 109 | |
| 110 | static int seq_contrstats_open(struct inode *inode, struct file *file) |
| 111 | { |
| 112 | return seq_open(file, &seq_contrstats_ops); |
| 113 | } |
| 114 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 115 | static const struct file_operations proc_controller_ops = { |
Denis V. Lunev | ac41cfd | 2008-04-29 01:02:30 -0700 | [diff] [blame] | 116 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | .open = seq_controller_open, |
| 118 | .read = seq_read, |
| 119 | .llseek = seq_lseek, |
| 120 | .release = seq_release, |
| 121 | }; |
| 122 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 123 | static const struct file_operations proc_contrstats_ops = { |
Denis V. Lunev | ac41cfd | 2008-04-29 01:02:30 -0700 | [diff] [blame] | 124 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | .open = seq_contrstats_open, |
| 126 | .read = seq_read, |
| 127 | .llseek = seq_lseek, |
| 128 | .release = seq_release, |
| 129 | }; |
| 130 | |
| 131 | // /proc/capi/applications: |
| 132 | // applid l3cnt dblkcnt dblklen #ncci recvqueuelen |
| 133 | // /proc/capi/applstats: |
| 134 | // applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt |
| 135 | // --------------------------------------------------------------------------- |
| 136 | |
| 137 | static void * |
| 138 | applications_start(struct seq_file *seq, loff_t *pos) |
| 139 | { |
| 140 | if (*pos < CAPI_MAXAPPL) |
| 141 | return &capi_applications[*pos]; |
| 142 | |
| 143 | return NULL; |
| 144 | } |
| 145 | |
| 146 | static void * |
| 147 | applications_next(struct seq_file *seq, void *v, loff_t *pos) |
| 148 | { |
| 149 | ++*pos; |
| 150 | if (*pos < CAPI_MAXAPPL) |
| 151 | return &capi_applications[*pos]; |
| 152 | |
| 153 | return NULL; |
| 154 | } |
| 155 | |
| 156 | static void |
| 157 | applications_stop(struct seq_file *seq, void *v) |
| 158 | { |
| 159 | } |
| 160 | |
| 161 | static int |
| 162 | applications_show(struct seq_file *seq, void *v) |
| 163 | { |
| 164 | struct capi20_appl *ap = *(struct capi20_appl **) v; |
| 165 | |
| 166 | if (!ap) |
| 167 | return 0; |
| 168 | |
| 169 | seq_printf(seq, "%u %d %d %d\n", |
| 170 | ap->applid, |
| 171 | ap->rparam.level3cnt, |
| 172 | ap->rparam.datablkcnt, |
| 173 | ap->rparam.datablklen); |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static int |
| 179 | applstats_show(struct seq_file *seq, void *v) |
| 180 | { |
| 181 | struct capi20_appl *ap = *(struct capi20_appl **) v; |
| 182 | |
| 183 | if (!ap) |
| 184 | return 0; |
| 185 | |
| 186 | seq_printf(seq, "%u %lu %lu %lu %lu\n", |
| 187 | ap->applid, |
| 188 | ap->nrecvctlpkt, |
| 189 | ap->nrecvdatapkt, |
| 190 | ap->nsentctlpkt, |
| 191 | ap->nsentdatapkt); |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 196 | static const struct seq_operations seq_applications_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | .start = applications_start, |
| 198 | .next = applications_next, |
| 199 | .stop = applications_stop, |
| 200 | .show = applications_show, |
| 201 | }; |
| 202 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 203 | static const struct seq_operations seq_applstats_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | .start = applications_start, |
| 205 | .next = applications_next, |
| 206 | .stop = applications_stop, |
| 207 | .show = applstats_show, |
| 208 | }; |
| 209 | |
| 210 | static int |
| 211 | seq_applications_open(struct inode *inode, struct file *file) |
| 212 | { |
| 213 | return seq_open(file, &seq_applications_ops); |
| 214 | } |
| 215 | |
| 216 | static int |
| 217 | seq_applstats_open(struct inode *inode, struct file *file) |
| 218 | { |
| 219 | return seq_open(file, &seq_applstats_ops); |
| 220 | } |
| 221 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 222 | static const struct file_operations proc_applications_ops = { |
Denis V. Lunev | ac41cfd | 2008-04-29 01:02:30 -0700 | [diff] [blame] | 223 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | .open = seq_applications_open, |
| 225 | .read = seq_read, |
| 226 | .llseek = seq_lseek, |
| 227 | .release = seq_release, |
| 228 | }; |
| 229 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 230 | static const struct file_operations proc_applstats_ops = { |
Denis V. Lunev | ac41cfd | 2008-04-29 01:02:30 -0700 | [diff] [blame] | 231 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | .open = seq_applstats_open, |
| 233 | .read = seq_read, |
| 234 | .llseek = seq_lseek, |
| 235 | .release = seq_release, |
| 236 | }; |
| 237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | // --------------------------------------------------------------------------- |
| 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | static void *capi_driver_start(struct seq_file *seq, loff_t *pos) |
Hannes Eder | dfe925e | 2009-02-25 13:08:40 +0000 | [diff] [blame] | 241 | __acquires(&capi_drivers_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | read_lock(&capi_drivers_list_lock); |
Pavel Emelianov | 2b7c302 | 2007-07-17 04:04:18 -0700 | [diff] [blame] | 244 | return seq_list_start(&capi_drivers, *pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | static void *capi_driver_next(struct seq_file *seq, void *v, loff_t *pos) |
| 248 | { |
Pavel Emelianov | 2b7c302 | 2007-07-17 04:04:18 -0700 | [diff] [blame] | 249 | return seq_list_next(v, &capi_drivers, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | static void capi_driver_stop(struct seq_file *seq, void *v) |
Hannes Eder | dfe925e | 2009-02-25 13:08:40 +0000 | [diff] [blame] | 253 | __releases(&capi_drivers_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
| 255 | read_unlock(&capi_drivers_list_lock); |
| 256 | } |
| 257 | |
| 258 | static int capi_driver_show(struct seq_file *seq, void *v) |
| 259 | { |
Pavel Emelianov | 2b7c302 | 2007-07-17 04:04:18 -0700 | [diff] [blame] | 260 | struct capi_driver *drv = list_entry(v, struct capi_driver, list); |
| 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | seq_printf(seq, "%-32s %s\n", drv->name, drv->revision); |
| 263 | return 0; |
| 264 | } |
| 265 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 266 | static const struct seq_operations seq_capi_driver_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | .start = capi_driver_start, |
| 268 | .next = capi_driver_next, |
| 269 | .stop = capi_driver_stop, |
| 270 | .show = capi_driver_show, |
| 271 | }; |
| 272 | |
| 273 | static int |
| 274 | seq_capi_driver_open(struct inode *inode, struct file *file) |
| 275 | { |
| 276 | int err; |
| 277 | err = seq_open(file, &seq_capi_driver_ops); |
| 278 | return err; |
| 279 | } |
| 280 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 281 | static const struct file_operations proc_driver_ops = { |
Denis V. Lunev | ac41cfd | 2008-04-29 01:02:30 -0700 | [diff] [blame] | 282 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | .open = seq_capi_driver_open, |
| 284 | .read = seq_read, |
| 285 | .llseek = seq_lseek, |
| 286 | .release = seq_release, |
| 287 | }; |
| 288 | |
| 289 | // --------------------------------------------------------------------------- |
| 290 | |
| 291 | void __init |
| 292 | kcapi_proc_init(void) |
| 293 | { |
| 294 | proc_mkdir("capi", NULL); |
| 295 | proc_mkdir("capi/controllers", NULL); |
Denis V. Lunev | ac41cfd | 2008-04-29 01:02:30 -0700 | [diff] [blame] | 296 | proc_create("capi/controller", 0, NULL, &proc_controller_ops); |
| 297 | proc_create("capi/contrstats", 0, NULL, &proc_contrstats_ops); |
| 298 | proc_create("capi/applications", 0, NULL, &proc_applications_ops); |
| 299 | proc_create("capi/applstats", 0, NULL, &proc_applstats_ops); |
| 300 | proc_create("capi/driver", 0, NULL, &proc_driver_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | void __exit |
| 304 | kcapi_proc_exit(void) |
| 305 | { |
| 306 | remove_proc_entry("capi/driver", NULL); |
| 307 | remove_proc_entry("capi/controller", NULL); |
| 308 | remove_proc_entry("capi/contrstats", NULL); |
| 309 | remove_proc_entry("capi/applications", NULL); |
| 310 | remove_proc_entry("capi/applstats", NULL); |
| 311 | remove_proc_entry("capi/controllers", NULL); |
| 312 | remove_proc_entry("capi", NULL); |
| 313 | } |