^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Kernel CAPI 2.0 Module - /proc/capi handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright 1999 by Carsten Paeth <calle@calle.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2002 by Kai Germaschewski <kai@germaschewski.name>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * This software may be used and distributed according to the terms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * of the GNU General Public License, incorporated herein by reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "kcapi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static char *state2str(unsigned short state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) switch (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) case CAPI_CTR_DETECTED: return "detected";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) case CAPI_CTR_LOADING: return "loading";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) case CAPI_CTR_RUNNING: return "running";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) default: return "???";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) // /proc/capi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) // ===========================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) // /proc/capi/controller:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) // cnr driver cardstate name driverinfo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) // /proc/capi/contrstats:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) // cnr nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) // ---------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static void *controller_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) __acquires(capi_controller_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) mutex_lock(&capi_controller_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (*pos < CAPI_MAXCONTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return &capi_controller[*pos];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static void *controller_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (*pos < CAPI_MAXCONTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return &capi_controller[*pos];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static void controller_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) __releases(capi_controller_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) mutex_unlock(&capi_controller_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static int controller_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct capi_ctr *ctr = *(struct capi_ctr **) v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (!ctr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) seq_printf(seq, "%d %-10s %-8s %-16s %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) ctr->cnr, ctr->driver_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) state2str(ctr->state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ctr->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) ctr->procinfo ? ctr->procinfo(ctr) : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static int contrstats_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct capi_ctr *ctr = *(struct capi_ctr **) v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (!ctr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) seq_printf(seq, "%d %lu %lu %lu %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) ctr->cnr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) ctr->nrecvctlpkt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) ctr->nrecvdatapkt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ctr->nsentctlpkt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ctr->nsentdatapkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static const struct seq_operations seq_controller_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .start = controller_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .next = controller_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .stop = controller_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .show = controller_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static const struct seq_operations seq_contrstats_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .start = controller_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .next = controller_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .stop = controller_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .show = contrstats_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) // /proc/capi/applications:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) // applid l3cnt dblkcnt dblklen #ncci recvqueuelen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) // /proc/capi/applstats:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) // applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) // ---------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static void *applications_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) __acquires(capi_controller_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) mutex_lock(&capi_controller_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (*pos < CAPI_MAXAPPL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return &capi_applications[*pos];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) applications_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) ++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (*pos < CAPI_MAXAPPL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return &capi_applications[*pos];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static void applications_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) __releases(capi_controller_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) mutex_unlock(&capi_controller_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) applications_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct capi20_appl *ap = *(struct capi20_appl **) v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (!ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) seq_printf(seq, "%u %d %d %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ap->applid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ap->rparam.level3cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ap->rparam.datablkcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ap->rparam.datablklen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) applstats_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct capi20_appl *ap = *(struct capi20_appl **) v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (!ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) seq_printf(seq, "%u %lu %lu %lu %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) ap->applid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) ap->nrecvctlpkt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) ap->nrecvdatapkt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) ap->nsentctlpkt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ap->nsentdatapkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static const struct seq_operations seq_applications_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) .start = applications_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .next = applications_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .stop = applications_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) .show = applications_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static const struct seq_operations seq_applstats_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) .start = applications_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) .next = applications_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) .stop = applications_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) .show = applstats_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) // ---------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /* /proc/capi/drivers is always empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static ssize_t empty_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) size_t size, loff_t *off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static const struct proc_ops empty_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) .proc_read = empty_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) // ---------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) kcapi_proc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) proc_mkdir("capi", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) proc_mkdir("capi/controllers", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) proc_create_seq("capi/controller", 0, NULL, &seq_controller_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) proc_create_seq("capi/contrstats", 0, NULL, &seq_contrstats_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) proc_create_seq("capi/applications", 0, NULL, &seq_applications_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) proc_create_seq("capi/applstats", 0, NULL, &seq_applstats_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) proc_create("capi/driver", 0, NULL, &empty_proc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) kcapi_proc_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) remove_proc_entry("capi/driver", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) remove_proc_entry("capi/controller", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) remove_proc_entry("capi/contrstats", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) remove_proc_entry("capi/applications", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) remove_proc_entry("capi/applstats", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) remove_proc_entry("capi/controllers", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) remove_proc_entry("capi", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }