add diag.o for brcm-2.4 by default, add fixes for wap54g from Tomas Vanek
[openwrt.git] / openwrt / target / linux / package / switch / src / switch-core.c
index c0e5cc9..6b59b9b 100644 (file)
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  * $Id: $
+ *
+ * Basic doc of driver's /proc interface:
+ * /proc/switch/<interface>/
+ *   registers:              read-only
+ *   counters:               read-only
+ *   reset:                  write causes hardware reset
+ *   enable_vlan:            "0", "1"
+ *   port/<port-number>/
+ *     enabled:              "0", "1"
+ *     media:                "AUTO", "100FD", "100HD", "10FD", "10HD"
+ *   vlan/<port-number>/
+ *     ports: same syntax as for nvram's vlan*ports (eg. "1 2 3 4 5*")
  */
 
 #include <linux/config.h>
@@ -56,13 +68,6 @@ static struct file_operations switch_proc_fops = {
        write: switch_proc_write
 };
 
-static inline char *strdup(char *str)
-{
-       char *new = kmalloc(strlen(str) + 1, GFP_KERNEL);
-       strcpy(new, str);
-       return new;
-}
-
 static ssize_t switch_proc_read(struct file *file, char *buf, size_t count, loff_t *ppos)
 {
 #ifdef LINUX_2_4
@@ -131,30 +136,50 @@ static ssize_t switch_proc_write(struct file *file, const char *buf, size_t coun
        return ret;
 }
 
-static void add_handlers(switch_driver *driver, switch_config *handlers, struct proc_dir_entry *parent, int nr)
+static int handle_driver_name(void *driver, char *buf, int nr)
+{
+       char *name = ((switch_driver *) driver)->name;
+       return sprintf(buf, "%s\n", name);
+}
+
+static int handle_driver_version(void *driver, char *buf, int nr)
+{
+       char *version = ((switch_driver *) driver)->version;
+       strcpy(buf, version);
+       return sprintf(buf, "%s\n", version);
+}
+
+static void add_handler(switch_driver *driver, switch_config *handler, struct proc_dir_entry *parent, int nr)
 {
        switch_priv *priv = (switch_priv *) driver->data;
-       switch_proc_handler *tmp;
-       int i, mode;
        struct proc_dir_entry *p;
+       int mode;
+
+       switch_proc_handler *tmp;
+       tmp = (switch_proc_handler *) kmalloc(sizeof(switch_proc_handler), GFP_KERNEL);
+       INIT_LIST_HEAD(&tmp->list);
+       tmp->parent = parent;
+       tmp->nr = nr;
+       tmp->driver = driver;
+       memcpy(&tmp->handler, handler, sizeof(switch_config));
+       list_add(&tmp->list, &priv->data.list);
+       
+       mode = 0;
+       if (handler->read != NULL) mode |= S_IRUSR;
+       if (handler->write != NULL) mode |= S_IWUSR;
+       
+       if ((p = create_proc_entry(handler->name, mode, parent)) != NULL) {
+               p->data = (void *) tmp;
+               p->proc_fops = &switch_proc_fops;
+       }
+}
+
+static inline void add_handlers(switch_driver *driver, switch_config *handlers, struct proc_dir_entry *parent, int nr)
+{
+       int i;
        
        for (i = 0; handlers[i].name != NULL; i++) {
-               tmp = kmalloc(sizeof(switch_proc_handler), GFP_KERNEL);
-               INIT_LIST_HEAD(&tmp->list);
-               tmp->parent = parent;
-               tmp->nr = nr;
-               tmp->driver = driver;
-               memcpy(&tmp->handler, &(handlers[i]), sizeof(switch_config));
-               list_add(&tmp->list, &priv->data.list);
-               
-               mode = 0;
-               if (handlers[i].read != NULL) mode |= S_IRUSR;
-               if (handlers[i].write != NULL) mode |= S_IWUSR;
-               
-               if ((p = create_proc_entry(handlers[i].name, mode, parent)) != NULL) {
-                       p->data = (void *) tmp;
-                       p->proc_fops = &switch_proc_fops;
-               }
+               add_handler(driver, &(handlers[i]), parent, nr);
        }
 }              
 
@@ -202,6 +227,12 @@ static void do_unregister(switch_driver *driver)
        kfree(priv);
 }
 
+switch_config global_driver_handlers[] = {
+       {"driver", handle_driver_name, NULL},
+       {"version", handle_driver_version, NULL},
+       {NULL, NULL, NULL}
+};
+
 static int do_register(switch_driver *driver)
 {
        switch_priv *priv;
@@ -216,8 +247,10 @@ static int do_register(switch_driver *driver)
        
        priv->nr = drv_num++;
        priv->driver_dir = proc_mkdir(driver->interface, switch_root);
-       if (driver->driver_handlers != NULL)
+       if (driver->driver_handlers != NULL) {
                add_handlers(driver, driver->driver_handlers, priv->driver_dir, 0);
+               add_handlers(driver, global_driver_handlers, priv->driver_dir, 0);
+       }
        
        priv->port_dir = proc_mkdir("port", priv->driver_dir);
        priv->ports = kmalloc((driver->ports + 1) * sizeof(struct proc_dir_entry *), GFP_KERNEL);
@@ -417,7 +450,7 @@ static int __init switch_init()
 
 static void __exit switch_exit()
 {
-       remove_proc_entry("vlan", NULL);
+       remove_proc_entry("switch", NULL);
 }
 
 MODULE_AUTHOR("Felix Fietkau <openwrt@nbd.name>");
This page took 0.023445 seconds and 4 git commands to generate.