]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - net/caif/chnl_net.c
Merge branch 'master' into tk71
[mv-sheeva.git] / net / caif / chnl_net.c
index 4293e190ec5328f1da7f40065c9eefcdff5d1f66..6008d6dc18a02283fdff763ba2186190208a8003 100644 (file)
@@ -5,6 +5,8 @@
  * License terms: GNU General Public License (GPL) version 2
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
+
 #include <linux/version.h>
 #include <linux/fs.h>
 #include <linux/init.h>
@@ -28,9 +30,6 @@
 #define CONNECT_TIMEOUT (5 * HZ)
 #define CAIF_NET_DEFAULT_QUEUE_LEN 500
 
-#undef pr_debug
-#define pr_debug pr_warning
-
 /*This list is protected by the rtnl lock. */
 static LIST_HEAD(chnl_net_list);
 
@@ -77,6 +76,8 @@ static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
        struct chnl_net *priv  = container_of(layr, struct chnl_net, chnl);
        int pktlen;
        int err = 0;
+       const u8 *ip_version;
+       u8 buf;
 
        priv = container_of(layr, struct chnl_net, chnl);
 
@@ -91,7 +92,21 @@ static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
         * send the packet to the net stack.
         */
        skb->dev = priv->netdev;
-       skb->protocol = htons(ETH_P_IP);
+
+       /* check the version of IP */
+       ip_version = skb_header_pointer(skb, 0, 1, &buf);
+       if (!ip_version)
+               return -EINVAL;
+       switch (*ip_version >> 4) {
+       case 4:
+               skb->protocol = htons(ETH_P_IP);
+               break;
+       case 6:
+               skb->protocol = htons(ETH_P_IPV6);
+               break;
+       default:
+               return -EINVAL;
+       }
 
        /* If we change the header in loop mode, the checksum is corrupted. */
        if (priv->conn_req.protocol == CAIFPROTO_DATAGRAM_LOOP)
@@ -142,8 +157,7 @@ static void chnl_flowctrl_cb(struct cflayer *layr, enum caif_ctrlcmd flow,
                                int phyid)
 {
        struct chnl_net *priv = container_of(layr, struct chnl_net, chnl);
-       pr_debug("CAIF: %s(): NET flowctrl func called flow: %s\n",
-               __func__,
+       pr_debug("NET flowctrl func called flow: %s\n",
                flow == CAIF_CTRLCMD_FLOW_ON_IND ? "ON" :
                flow == CAIF_CTRLCMD_INIT_RSP ? "INIT" :
                flow == CAIF_CTRLCMD_FLOW_OFF_IND ? "OFF" :
@@ -196,12 +210,12 @@ static int chnl_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
        priv = netdev_priv(dev);
 
        if (skb->len > priv->netdev->mtu) {
-               pr_warning("CAIF: %s(): Size of skb exceeded MTU\n", __func__);
+               pr_warn("Size of skb exceeded MTU\n");
                return -ENOSPC;
        }
 
        if (!priv->flowenabled) {
-               pr_debug("CAIF: %s(): dropping packets flow off\n", __func__);
+               pr_debug("dropping packets flow off\n");
                return NETDEV_TX_BUSY;
        }
 
@@ -237,7 +251,7 @@ static int chnl_net_open(struct net_device *dev)
        ASSERT_RTNL();
        priv = netdev_priv(dev);
        if (!priv) {
-               pr_debug("CAIF: %s(): chnl_net_open: no priv\n", __func__);
+               pr_debug("chnl_net_open: no priv\n");
                return -ENODEV;
        }
 
@@ -246,18 +260,17 @@ static int chnl_net_open(struct net_device *dev)
                result = caif_connect_client(&priv->conn_req, &priv->chnl,
                                        &llifindex, &headroom, &tailroom);
                if (result != 0) {
-                               pr_debug("CAIF: %s(): err: "
-                                       "Unable to register and open device,"
-                                       " Err:%d\n",
-                                       __func__,
-                                       result);
+                               pr_debug("err: "
+                                        "Unable to register and open device,"
+                                        " Err:%d\n",
+                                        result);
                                goto error;
                }
 
                lldev = dev_get_by_index(dev_net(dev), llifindex);
 
                if (lldev == NULL) {
-                       pr_debug("CAIF: %s(): no interface?\n", __func__);
+                       pr_debug("no interface?\n");
                        result = -ENODEV;
                        goto error;
                }
@@ -279,9 +292,7 @@ static int chnl_net_open(struct net_device *dev)
                dev_put(lldev);
 
                if (mtu < 100) {
-                       pr_warning("CAIF: %s(): "
-                               "CAIF Interface MTU too small (%d)\n",
-                               __func__, mtu);
+                       pr_warn("CAIF Interface MTU too small (%d)\n", mtu);
                        result = -ENODEV;
                        goto error;
                }
@@ -296,33 +307,32 @@ static int chnl_net_open(struct net_device *dev)
        rtnl_lock();
 
        if (result == -ERESTARTSYS) {
-               pr_debug("CAIF: %s(): wait_event_interruptible"
-                        " woken by a signal\n", __func__);
+               pr_debug("wait_event_interruptible woken by a signal\n");
                result = -ERESTARTSYS;
                goto error;
        }
 
        if (result == 0) {
-               pr_debug("CAIF: %s(): connect timeout\n", __func__);
+               pr_debug("connect timeout\n");
                caif_disconnect_client(&priv->chnl);
                priv->state = CAIF_DISCONNECTED;
-               pr_debug("CAIF: %s(): state disconnected\n", __func__);
+               pr_debug("state disconnected\n");
                result = -ETIMEDOUT;
                goto error;
        }
 
        if (priv->state != CAIF_CONNECTED) {
-               pr_debug("CAIF: %s(): connect failed\n", __func__);
+               pr_debug("connect failed\n");
                result = -ECONNREFUSED;
                goto error;
        }
-       pr_debug("CAIF: %s(): CAIF Netdevice connected\n", __func__);
+       pr_debug("CAIF Netdevice connected\n");
        return 0;
 
 error:
        caif_disconnect_client(&priv->chnl);
        priv->state = CAIF_DISCONNECTED;
-       pr_debug("CAIF: %s(): state disconnected\n", __func__);
+       pr_debug("state disconnected\n");
        return result;
 
 }
@@ -384,9 +394,7 @@ static void ipcaif_net_setup(struct net_device *dev)
        priv->conn_req.sockaddr.u.dgm.connection_id = -1;
        priv->flowenabled = false;
 
-       ASSERT_RTNL();
        init_waitqueue_head(&priv->netmgmt_wq);
-       list_add(&priv->list_field, &chnl_net_list);
 }
 
 
@@ -413,7 +421,7 @@ static void caif_netlink_parms(struct nlattr *data[],
                                struct caif_connect_request *conn_req)
 {
        if (!data) {
-               pr_warning("CAIF: %s: no params data found\n", __func__);
+               pr_warn("no params data found\n");
                return;
        }
        if (data[IFLA_CAIF_IPV4_CONNID])
@@ -442,8 +450,9 @@ static int ipcaif_newlink(struct net *src_net, struct net_device *dev,
 
        ret = register_netdevice(dev);
        if (ret)
-               pr_warning("CAIF: %s(): device rtml registration failed\n",
-                          __func__);
+               pr_warn("device rtml registration failed\n");
+       else
+               list_add(&caifdev->list_field, &chnl_net_list);
        return ret;
 }