Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: hysdn_procconf.c,v 1.8.6.4 2001/09/23 22:24:54 kai Exp $ |
| 2 | * |
| 3 | * Linux driver for HYSDN cards, /proc/net filesystem dir and conf functions. |
| 4 | * |
| 5 | * written by Werner Cornelius (werner@titro.de) for Hypercope GmbH |
| 6 | * |
| 7 | * Copyright 1999 by Werner Cornelius (werner@titro.de) |
| 8 | * |
| 9 | * This software may be used and distributed according to the terms |
| 10 | * of the GNU General Public License, incorporated herein by reference. |
| 11 | * |
| 12 | */ |
| 13 | |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 14 | #include <linux/cred.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/poll.h> |
| 17 | #include <linux/proc_fs.h> |
| 18 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Arnd Bergmann | 76a6492 | 2010-07-11 11:18:53 +0000 | [diff] [blame] | 20 | #include <linux/mutex.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 21 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | #include "hysdn_defs.h" |
| 24 | |
Arnd Bergmann | 76a6492 | 2010-07-11 11:18:53 +0000 | [diff] [blame] | 25 | static DEFINE_MUTEX(hysdn_conf_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #define INFO_OUT_LEN 80 /* length of info line including lf */ |
| 28 | |
| 29 | /********************************************************/ |
| 30 | /* defines and data structure for conf write operations */ |
| 31 | /********************************************************/ |
| 32 | #define CONF_STATE_DETECT 0 /* waiting for detect */ |
| 33 | #define CONF_STATE_CONF 1 /* writing config data */ |
| 34 | #define CONF_STATE_POF 2 /* writing pof data */ |
| 35 | #define CONF_LINE_LEN 255 /* 255 chars max */ |
| 36 | |
| 37 | struct conf_writedata { |
| 38 | hysdn_card *card; /* card the device is connected to */ |
| 39 | int buf_size; /* actual number of bytes in the buffer */ |
| 40 | int needed_size; /* needed size when reading pof */ |
| 41 | int state; /* actual interface states from above constants */ |
Andrew Morton | c721bcc | 2006-03-25 03:07:04 -0800 | [diff] [blame] | 42 | unsigned char conf_line[CONF_LINE_LEN]; /* buffered conf line */ |
| 43 | unsigned short channel; /* active channel number */ |
| 44 | unsigned char *pof_buffer; /* buffer when writing pof */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | /***********************************************************************/ |
| 48 | /* process_line parses one config line and transfers it to the card if */ |
| 49 | /* necessary. */ |
| 50 | /* if the return value is negative an error occurred. */ |
| 51 | /***********************************************************************/ |
| 52 | static int |
| 53 | process_line(struct conf_writedata *cnf) |
| 54 | { |
Andrew Morton | c721bcc | 2006-03-25 03:07:04 -0800 | [diff] [blame] | 55 | unsigned char *cp = cnf->conf_line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | int i; |
| 57 | |
| 58 | if (cnf->card->debug_flags & LOG_CNF_LINE) |
| 59 | hysdn_addlog(cnf->card, "conf line: %s", cp); |
| 60 | |
| 61 | if (*cp == '-') { /* option */ |
| 62 | cp++; /* point to option char */ |
| 63 | |
| 64 | if (*cp++ != 'c') |
| 65 | return (0); /* option unknown or used */ |
| 66 | i = 0; /* start value for channel */ |
| 67 | while ((*cp <= '9') && (*cp >= '0')) |
| 68 | i = i * 10 + *cp++ - '0'; /* get decimal number */ |
| 69 | if (i > 65535) { |
| 70 | if (cnf->card->debug_flags & LOG_CNF_MISC) |
| 71 | hysdn_addlog(cnf->card, "conf channel invalid %d", i); |
| 72 | return (-ERR_INV_CHAN); /* invalid channel */ |
| 73 | } |
| 74 | cnf->channel = i & 0xFFFF; /* set new channel number */ |
| 75 | return (0); /* success */ |
| 76 | } /* option */ |
| 77 | if (*cp == '*') { /* line to send */ |
| 78 | if (cnf->card->debug_flags & LOG_CNF_DATA) |
| 79 | hysdn_addlog(cnf->card, "conf chan=%d %s", cnf->channel, cp); |
| 80 | return (hysdn_tx_cfgline(cnf->card, cnf->conf_line + 1, |
| 81 | cnf->channel)); /* send the line without * */ |
| 82 | } /* line to send */ |
| 83 | return (0); |
| 84 | } /* process_line */ |
| 85 | |
| 86 | /***********************************/ |
| 87 | /* conf file operations and tables */ |
| 88 | /***********************************/ |
| 89 | |
| 90 | /****************************************************/ |
| 91 | /* write conf file -> boot or send cfg line to card */ |
| 92 | /****************************************************/ |
| 93 | static ssize_t |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 94 | hysdn_conf_write(struct file *file, const char __user *buf, size_t count, loff_t *off) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
| 96 | struct conf_writedata *cnf; |
| 97 | int i; |
Andrew Morton | c721bcc | 2006-03-25 03:07:04 -0800 | [diff] [blame] | 98 | unsigned char ch, *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | if (!count) |
| 101 | return (0); /* nothing to handle */ |
| 102 | |
| 103 | if (!(cnf = file->private_data)) |
| 104 | return (-EFAULT); /* should never happen */ |
| 105 | |
| 106 | if (cnf->state == CONF_STATE_DETECT) { /* auto detect cnf or pof data */ |
| 107 | if (copy_from_user(&ch, buf, 1)) /* get first char for detect */ |
| 108 | return (-EFAULT); |
| 109 | |
| 110 | if (ch == 0x1A) { |
| 111 | /* we detected a pof file */ |
| 112 | if ((cnf->needed_size = pof_write_open(cnf->card, &cnf->pof_buffer)) <= 0) |
| 113 | return (cnf->needed_size); /* an error occurred -> exit */ |
| 114 | cnf->buf_size = 0; /* buffer is empty */ |
| 115 | cnf->state = CONF_STATE_POF; /* new state */ |
| 116 | } else { |
| 117 | /* conf data has been detected */ |
| 118 | cnf->buf_size = 0; /* buffer is empty */ |
| 119 | cnf->state = CONF_STATE_CONF; /* requested conf data write */ |
| 120 | if (cnf->card->state != CARD_STATE_RUN) |
| 121 | return (-ERR_NOT_BOOTED); |
| 122 | cnf->conf_line[CONF_LINE_LEN - 1] = 0; /* limit string length */ |
| 123 | cnf->channel = 4098; /* default channel for output */ |
| 124 | } |
| 125 | } /* state was auto detect */ |
| 126 | if (cnf->state == CONF_STATE_POF) { /* pof write active */ |
| 127 | i = cnf->needed_size - cnf->buf_size; /* bytes still missing for write */ |
| 128 | if (i <= 0) |
| 129 | return (-EINVAL); /* size error handling pof */ |
| 130 | |
| 131 | if (i < count) |
| 132 | count = i; /* limit requested number of bytes */ |
| 133 | if (copy_from_user(cnf->pof_buffer + cnf->buf_size, buf, count)) |
| 134 | return (-EFAULT); /* error while copying */ |
| 135 | cnf->buf_size += count; |
| 136 | |
| 137 | if (cnf->needed_size == cnf->buf_size) { |
| 138 | cnf->needed_size = pof_write_buffer(cnf->card, cnf->buf_size); /* write data */ |
| 139 | if (cnf->needed_size <= 0) { |
| 140 | cnf->card->state = CARD_STATE_BOOTERR; /* show boot error */ |
| 141 | return (cnf->needed_size); /* an error occurred */ |
| 142 | } |
| 143 | cnf->buf_size = 0; /* buffer is empty again */ |
| 144 | } |
| 145 | } |
| 146 | /* pof write active */ |
| 147 | else { /* conf write active */ |
| 148 | |
| 149 | if (cnf->card->state != CARD_STATE_RUN) { |
| 150 | if (cnf->card->debug_flags & LOG_CNF_MISC) |
| 151 | hysdn_addlog(cnf->card, "cnf write denied -> not booted"); |
| 152 | return (-ERR_NOT_BOOTED); |
| 153 | } |
| 154 | i = (CONF_LINE_LEN - 1) - cnf->buf_size; /* bytes available in buffer */ |
| 155 | if (i > 0) { |
| 156 | /* copy remaining bytes into buffer */ |
| 157 | |
| 158 | if (count > i) |
| 159 | count = i; /* limit transfer */ |
| 160 | if (copy_from_user(cnf->conf_line + cnf->buf_size, buf, count)) |
| 161 | return (-EFAULT); /* error while copying */ |
| 162 | |
| 163 | i = count; /* number of chars in buffer */ |
| 164 | cp = cnf->conf_line + cnf->buf_size; |
| 165 | while (i) { |
| 166 | /* search for end of line */ |
| 167 | if ((*cp < ' ') && (*cp != 9)) |
| 168 | break; /* end of line found */ |
| 169 | cp++; |
| 170 | i--; |
| 171 | } /* search for end of line */ |
| 172 | |
| 173 | if (i) { |
| 174 | /* delimiter found */ |
| 175 | *cp++ = 0; /* string termination */ |
| 176 | count -= (i - 1); /* subtract remaining bytes from count */ |
| 177 | while ((i) && (*cp < ' ') && (*cp != 9)) { |
| 178 | i--; /* discard next char */ |
| 179 | count++; /* mark as read */ |
| 180 | cp++; /* next char */ |
| 181 | } |
| 182 | cnf->buf_size = 0; /* buffer is empty after transfer */ |
| 183 | if ((i = process_line(cnf)) < 0) /* handle the line */ |
| 184 | count = i; /* return the error */ |
| 185 | } |
| 186 | /* delimiter found */ |
| 187 | else { |
| 188 | cnf->buf_size += count; /* add chars to string */ |
| 189 | if (cnf->buf_size >= CONF_LINE_LEN - 1) { |
| 190 | if (cnf->card->debug_flags & LOG_CNF_MISC) |
| 191 | hysdn_addlog(cnf->card, "cnf line too long %d chars pos %d", cnf->buf_size, count); |
| 192 | return (-ERR_CONF_LONG); |
| 193 | } |
| 194 | } /* not delimited */ |
| 195 | |
| 196 | } |
| 197 | /* copy remaining bytes into buffer */ |
| 198 | else { |
| 199 | if (cnf->card->debug_flags & LOG_CNF_MISC) |
| 200 | hysdn_addlog(cnf->card, "cnf line too long"); |
| 201 | return (-ERR_CONF_LONG); |
| 202 | } |
| 203 | } /* conf write active */ |
| 204 | |
| 205 | return (count); |
| 206 | } /* hysdn_conf_write */ |
| 207 | |
| 208 | /*******************************************/ |
| 209 | /* read conf file -> output card info data */ |
| 210 | /*******************************************/ |
| 211 | static ssize_t |
Akinobu Mita | ea23ec2 | 2008-06-10 12:50:14 -0700 | [diff] [blame] | 212 | hysdn_conf_read(struct file *file, char __user *buf, size_t count, loff_t *off) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { |
| 214 | char *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Akinobu Mita | ea23ec2 | 2008-06-10 12:50:14 -0700 | [diff] [blame] | 216 | if (!(file->f_mode & FMODE_READ)) |
| 217 | return -EPERM; /* no permission to read */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Akinobu Mita | ea23ec2 | 2008-06-10 12:50:14 -0700 | [diff] [blame] | 219 | if (!(cp = file->private_data)) |
| 220 | return -EFAULT; /* should never happen */ |
| 221 | |
| 222 | return simple_read_from_buffer(buf, count, off, cp, strlen(cp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | } /* hysdn_conf_read */ |
| 224 | |
| 225 | /******************/ |
| 226 | /* open conf file */ |
| 227 | /******************/ |
| 228 | static int |
| 229 | hysdn_conf_open(struct inode *ino, struct file *filep) |
| 230 | { |
| 231 | hysdn_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | struct conf_writedata *cnf; |
| 233 | char *cp, *tmp; |
| 234 | |
| 235 | /* now search the addressed card */ |
Arnd Bergmann | 76a6492 | 2010-07-11 11:18:53 +0000 | [diff] [blame] | 236 | mutex_lock(&hysdn_conf_mutex); |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 237 | card = PDE_DATA(ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL)) |
| 239 | hysdn_addlog(card, "config open for uid=%d gid=%d mode=0x%x", |
David Howells | d76b0d9 | 2008-11-14 10:39:25 +1100 | [diff] [blame] | 240 | filep->f_cred->fsuid, filep->f_cred->fsgid, |
| 241 | filep->f_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
| 243 | if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) { |
| 244 | /* write only access -> write boot file or conf line */ |
| 245 | |
| 246 | if (!(cnf = kmalloc(sizeof(struct conf_writedata), GFP_KERNEL))) { |
Arnd Bergmann | 76a6492 | 2010-07-11 11:18:53 +0000 | [diff] [blame] | 247 | mutex_unlock(&hysdn_conf_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | return (-EFAULT); |
| 249 | } |
| 250 | cnf->card = card; |
| 251 | cnf->buf_size = 0; /* nothing buffered */ |
| 252 | cnf->state = CONF_STATE_DETECT; /* start auto detect */ |
| 253 | filep->private_data = cnf; |
| 254 | |
| 255 | } else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) { |
| 256 | /* read access -> output card info data */ |
| 257 | |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 258 | if (!(tmp = kmalloc(INFO_OUT_LEN * 2 + 2, GFP_KERNEL))) { |
Arnd Bergmann | 76a6492 | 2010-07-11 11:18:53 +0000 | [diff] [blame] | 259 | mutex_unlock(&hysdn_conf_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | return (-EFAULT); /* out of memory */ |
| 261 | } |
| 262 | filep->private_data = tmp; /* start of string */ |
| 263 | |
| 264 | /* first output a headline */ |
| 265 | sprintf(tmp, "id bus slot type irq iobase dp-mem b-chans fax-chans state device"); |
| 266 | cp = tmp; /* start of string */ |
| 267 | while (*cp) |
| 268 | cp++; |
| 269 | while (((cp - tmp) % (INFO_OUT_LEN + 1)) != INFO_OUT_LEN) |
| 270 | *cp++ = ' '; |
| 271 | *cp++ = '\n'; |
| 272 | |
| 273 | /* and now the data */ |
| 274 | sprintf(cp, "%d %3d %4d %4d %3d 0x%04x 0x%08lx %7d %9d %3d %s", |
| 275 | card->myid, |
| 276 | card->bus, |
| 277 | PCI_SLOT(card->devfn), |
| 278 | card->brdtype, |
| 279 | card->irq, |
| 280 | card->iobase, |
| 281 | card->membase, |
| 282 | card->bchans, |
| 283 | card->faxchans, |
| 284 | card->state, |
| 285 | hysdn_net_getname(card)); |
| 286 | while (*cp) |
| 287 | cp++; |
| 288 | while (((cp - tmp) % (INFO_OUT_LEN + 1)) != INFO_OUT_LEN) |
| 289 | *cp++ = ' '; |
| 290 | *cp++ = '\n'; |
| 291 | *cp = 0; /* end of string */ |
| 292 | } else { /* simultaneous read/write access forbidden ! */ |
Arnd Bergmann | 76a6492 | 2010-07-11 11:18:53 +0000 | [diff] [blame] | 293 | mutex_unlock(&hysdn_conf_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | return (-EPERM); /* no permission this time */ |
| 295 | } |
Arnd Bergmann | 76a6492 | 2010-07-11 11:18:53 +0000 | [diff] [blame] | 296 | mutex_unlock(&hysdn_conf_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | return nonseekable_open(ino, filep); |
| 298 | } /* hysdn_conf_open */ |
| 299 | |
| 300 | /***************************/ |
| 301 | /* close a config file. */ |
| 302 | /***************************/ |
| 303 | static int |
| 304 | hysdn_conf_close(struct inode *ino, struct file *filep) |
| 305 | { |
| 306 | hysdn_card *card; |
| 307 | struct conf_writedata *cnf; |
| 308 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
Arnd Bergmann | 76a6492 | 2010-07-11 11:18:53 +0000 | [diff] [blame] | 310 | mutex_lock(&hysdn_conf_mutex); |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 311 | card = PDE_DATA(ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL)) |
| 313 | hysdn_addlog(card, "config close for uid=%d gid=%d mode=0x%x", |
David Howells | d76b0d9 | 2008-11-14 10:39:25 +1100 | [diff] [blame] | 314 | filep->f_cred->fsuid, filep->f_cred->fsgid, |
| 315 | filep->f_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
| 317 | if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) { |
| 318 | /* write only access -> write boot file or conf line */ |
| 319 | if (filep->private_data) { |
| 320 | cnf = filep->private_data; |
| 321 | |
| 322 | if (cnf->state == CONF_STATE_POF) |
| 323 | retval = pof_write_close(cnf->card); /* close the pof write */ |
| 324 | kfree(filep->private_data); /* free allocated memory for buffer */ |
| 325 | |
| 326 | } /* handle write private data */ |
| 327 | } else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) { |
| 328 | /* read access -> output card info data */ |
| 329 | |
Jesper Juhl | 3c7208f | 2005-11-07 01:01:29 -0800 | [diff] [blame] | 330 | kfree(filep->private_data); /* release memory */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } |
Arnd Bergmann | 76a6492 | 2010-07-11 11:18:53 +0000 | [diff] [blame] | 332 | mutex_unlock(&hysdn_conf_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | return (retval); |
| 334 | } /* hysdn_conf_close */ |
| 335 | |
| 336 | /******************************************************/ |
| 337 | /* table for conf filesystem functions defined above. */ |
| 338 | /******************************************************/ |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 339 | static const struct file_operations conf_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { |
Denis V. Lunev | ac41cfd | 2008-04-29 01:02:30 -0700 | [diff] [blame] | 341 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | .llseek = no_llseek, |
| 343 | .read = hysdn_conf_read, |
| 344 | .write = hysdn_conf_write, |
| 345 | .open = hysdn_conf_open, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 346 | .release = hysdn_conf_close, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | }; |
| 348 | |
| 349 | /*****************************/ |
| 350 | /* hysdn subdir in /proc/net */ |
| 351 | /*****************************/ |
| 352 | struct proc_dir_entry *hysdn_proc_entry = NULL; |
| 353 | |
| 354 | /*******************************************************************************/ |
| 355 | /* hysdn_procconf_init is called when the module is loaded and after the cards */ |
| 356 | /* have been detected. The needed proc dir and card config files are created. */ |
| 357 | /* The log init is called at last. */ |
| 358 | /*******************************************************************************/ |
| 359 | int |
| 360 | hysdn_procconf_init(void) |
| 361 | { |
| 362 | hysdn_card *card; |
Andrew Morton | c721bcc | 2006-03-25 03:07:04 -0800 | [diff] [blame] | 363 | unsigned char conf_name[20]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 365 | hysdn_proc_entry = proc_mkdir(PROC_SUBDIR_NAME, init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | if (!hysdn_proc_entry) { |
| 367 | printk(KERN_ERR "HYSDN: unable to create hysdn subdir\n"); |
| 368 | return (-1); |
| 369 | } |
| 370 | card = card_root; /* point to first card */ |
| 371 | while (card) { |
| 372 | |
| 373 | sprintf(conf_name, "%s%d", PROC_CONF_BASENAME, card->myid); |
Al Viro | 4d8e8d2 | 2013-03-28 18:56:21 -0400 | [diff] [blame] | 374 | if ((card->procconf = (void *) proc_create_data(conf_name, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 375 | S_IFREG | S_IRUGO | S_IWUSR, |
| 376 | hysdn_proc_entry, |
Al Viro | 4d8e8d2 | 2013-03-28 18:56:21 -0400 | [diff] [blame] | 377 | &conf_fops, |
| 378 | card)) != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | hysdn_proclog_init(card); /* init the log file entry */ |
| 380 | } |
| 381 | card = card->next; /* next entry */ |
| 382 | } |
| 383 | |
David S. Miller | cd141ee | 2011-02-09 13:54:26 -0800 | [diff] [blame] | 384 | printk(KERN_NOTICE "HYSDN: procfs initialised\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | return (0); |
| 386 | } /* hysdn_procconf_init */ |
| 387 | |
| 388 | /*************************************************************************************/ |
| 389 | /* hysdn_procconf_release is called when the module is unloaded and before the cards */ |
| 390 | /* resources are released. The module counter is assumed to be 0 ! */ |
| 391 | /*************************************************************************************/ |
| 392 | void |
| 393 | hysdn_procconf_release(void) |
| 394 | { |
| 395 | hysdn_card *card; |
Andrew Morton | c721bcc | 2006-03-25 03:07:04 -0800 | [diff] [blame] | 396 | unsigned char conf_name[20]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
| 398 | card = card_root; /* start with first card */ |
| 399 | while (card) { |
| 400 | |
| 401 | sprintf(conf_name, "%s%d", PROC_CONF_BASENAME, card->myid); |
| 402 | if (card->procconf) |
| 403 | remove_proc_entry(conf_name, hysdn_proc_entry); |
| 404 | |
| 405 | hysdn_proclog_release(card); /* init the log file entry */ |
| 406 | |
| 407 | card = card->next; /* point to next card */ |
| 408 | } |
| 409 | |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 410 | remove_proc_entry(PROC_SUBDIR_NAME, init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |