pcmcia: disable pcmcia ioctl for !ARM, prepare for removal
[safe/jmp/linux-2.6] / Documentation / connector / cn_test.c
index b7de82e..b07add3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     cn_test.c
  * 
- * 2004-2005 Copyright (c) Evgeniy Polyakov <johnpol@2ka.mipt.ru>
+ * 2004+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
  * All rights reserved.
  * 
  * This program is free software; you can redistribute it and/or modify
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#define pr_fmt(fmt) "cn_test: " fmt
+
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/skbuff.h>
 #include <linux/timer.h>
 
-#include "connector.h"
+#include <linux/connector.h>
 
-static struct cb_id cn_test_id = { 0x123, 0x456 };
+static struct cb_id cn_test_id = { CN_NETLINK_USERS + 3, 0x456 };
 static char cn_test_name[] = "cn_test";
 static struct sock *nls;
 static struct timer_list cn_test_timer;
 
-void cn_test_callback(void *data)
+static void cn_test_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
 {
-       struct cn_msg *msg = (struct cn_msg *)data;
-
-       printk("%s: %lu: idx=%x, val=%x, seq=%u, ack=%u, len=%d: %s.\n",
-              __func__, jiffies, msg->id.idx, msg->id.val,
-              msg->seq, msg->ack, msg->len, (char *)msg->data);
+       pr_info("%s: %lu: idx=%x, val=%x, seq=%u, ack=%u, len=%d: %s.\n",
+               __func__, jiffies, msg->id.idx, msg->id.val,
+               msg->seq, msg->ack, msg->len,
+               msg->len ? (char *)msg->data : "");
 }
 
+/*
+ * Do not remove this function even if no one is using it as
+ * this is an example of how to get notifications about new
+ * connector user registration
+ */
+#if 0
 static int cn_test_want_notify(void)
 {
        struct cn_ctl_msg *ctl;
@@ -57,9 +64,7 @@ static int cn_test_want_notify(void)
 
        skb = alloc_skb(size, GFP_ATOMIC);
        if (!skb) {
-               printk(KERN_ERR "Failed to allocate new skb with size=%u.\n",
-                      size);
-
+               pr_err("failed to allocate new skb with size=%u\n", size);
                return -ENOMEM;
        }
 
@@ -104,19 +109,20 @@ static int cn_test_want_notify(void)
        req->first = cn_test_id.val + 20;
        req->range = 10;
 
-       NETLINK_CB(skb).dst_groups = ctl->group;
+       NETLINK_CB(skb).dst_group = ctl->group;
        //netlink_broadcast(nls, skb, 0, ctl->group, GFP_ATOMIC);
        netlink_unicast(nls, skb, 0, 0);
 
-       printk(KERN_INFO "Request was sent. Group=0x%x.\n", ctl->group);
+       pr_info("request was sent: group=0x%x\n", ctl->group);
 
        return 0;
 
 nlmsg_failure:
-       printk(KERN_ERR "Failed to send %u.%u\n", msg->seq, msg->ack);
+       pr_err("failed to send %u.%u\n", msg->seq, msg->ack);
        kfree_skb(skb);
        return -EINVAL;
 }
+#endif
 
 static u32 cn_test_timer_counter;
 static void cn_test_timer_func(unsigned long __data)
@@ -124,9 +130,10 @@ static void cn_test_timer_func(unsigned long __data)
        struct cn_msg *m;
        char data[32];
 
-       m = kmalloc(sizeof(*m) + sizeof(data), GFP_ATOMIC);
+       pr_debug("%s: timer fired with data %lu\n", __func__, __data);
+
+       m = kzalloc(sizeof(*m) + sizeof(data), GFP_ATOMIC);
        if (m) {
-               memset(m, 0, sizeof(*m) + sizeof(data));
 
                memcpy(&m->id, &cn_test_id, sizeof(m->id));
                m->seq = cn_test_timer_counter;
@@ -138,13 +145,13 @@ static void cn_test_timer_func(unsigned long __data)
 
                memcpy(m + 1, data, m->len);
 
-               cn_netlink_send(m, 0, gfp_any());
+               cn_netlink_send(m, 0, GFP_ATOMIC);
                kfree(m);
        }
 
        cn_test_timer_counter++;
 
-       mod_timer(&cn_test_timer, jiffies + HZ);
+       mod_timer(&cn_test_timer, jiffies + msecs_to_jiffies(1000));
 }
 
 static int cn_test_init(void)
@@ -161,11 +168,11 @@ static int cn_test_init(void)
                goto err_out;
        }
 
-       init_timer(&cn_test_timer);
-       cn_test_timer.function = cn_test_timer_func;
-       cn_test_timer.expires = jiffies + HZ;
-       cn_test_timer.data = 0;
-       add_timer(&cn_test_timer);
+       setup_timer(&cn_test_timer, cn_test_timer_func, 0);
+       mod_timer(&cn_test_timer, jiffies + msecs_to_jiffies(1000));
+
+       pr_info("initialized with id={%u.%u}\n",
+               cn_test_id.idx, cn_test_id.val);
 
        return 0;
 
@@ -190,5 +197,5 @@ module_init(cn_test_init);
 module_exit(cn_test_fini);
 
 MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
+MODULE_AUTHOR("Evgeniy Polyakov <zbr@ioremap.net>");
 MODULE_DESCRIPTION("Connector's test module");