mbuf: replace data pointer by an offset
[dpdk.git] / lib / librte_eal / linuxapp / kni / kni_net.c
index fb4b3a8..dd95db5 100644 (file)
@@ -1,23 +1,23 @@
 /*-
  * GPL LICENSE SUMMARY
- * 
+ *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- * 
+ *
  *   This program is free software; you can redistribute it and/or modify
  *   it under the terms of version 2 of the GNU General Public License as
  *   published by the Free Software Foundation.
- * 
+ *
  *   This program is distributed in the hope that it will be useful, but
  *   WITHOUT ANY WARRANTY; without even the implied warranty of
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  *   General Public License for more details.
- * 
+ *
  *   You should have received a copy of the GNU General Public License
  *   along with this program; if not, write to the Free Software
  *   Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  *   The full GNU General Public License is included in this distribution
  *   in the file called LICENSE.GPL.
- * 
+ *
  *   Contact Information:
  *   Intel Corporation
  */
@@ -162,7 +162,8 @@ kni_net_rx_normal(struct kni_dev *kni)
        for (i = 0; i < num; i++) {
                kva = (void *)va[i] - kni->mbuf_va + kni->mbuf_kva;
                len = kva->data_len;
-               data_kva = kva->data - kni->mbuf_va + kni->mbuf_kva;
+               data_kva = kva->buf_addr + kva->data_off - kni->mbuf_va
+                               + kni->mbuf_kva;
 
                skb = dev_alloc_skb(len + 2);
                if (!skb) {
@@ -179,7 +180,7 @@ kni_net_rx_normal(struct kni_dev *kni)
                        skb->ip_summed = CHECKSUM_UNNECESSARY;
 
                        /* Call netif interface */
-                       netif_receive_skb(skb);
+                       netif_rx(skb);
 
                        /* Update statistics */
                        kni->stats.rx_bytes += len;
@@ -246,13 +247,14 @@ kni_net_rx_lo_fifo(struct kni_dev *kni)
                for (i = 0; i < num; i++) {
                        kva = (void *)va[i] - kni->mbuf_va + kni->mbuf_kva;
                        len = kva->pkt_len;
-                       data_kva = kva->data - kni->mbuf_va +
-                                               kni->mbuf_kva;
+                       data_kva = kva->buf_addr + kva->data_off -
+                                       kni->mbuf_va + kni->mbuf_kva;
 
                        alloc_kva = (void *)alloc_va[i] - kni->mbuf_va +
                                                        kni->mbuf_kva;
-                       alloc_data_kva = alloc_kva->data - kni->mbuf_va +
-                                                               kni->mbuf_kva;
+                       alloc_data_kva = alloc_kva->buf_addr +
+                                       alloc_kva->data_off - kni->mbuf_va +
+                                                       kni->mbuf_kva;
                        memcpy(alloc_data_kva, data_kva, len);
                        alloc_kva->pkt_len = len;
                        alloc_kva->data_len = len;
@@ -321,7 +323,8 @@ kni_net_rx_lo_fifo_skb(struct kni_dev *kni)
        for (i = 0; i < num; i++) {
                kva = (void *)va[i] - kni->mbuf_va + kni->mbuf_kva;
                len = kva->data_len;
-               data_kva = kva->data - kni->mbuf_va + kni->mbuf_kva;
+               data_kva = kva->buf_addr + kva->data_off - kni->mbuf_va +
+                               kni->mbuf_kva;
 
                skb = dev_alloc_skb(len + 2);
                if (skb == NULL)
@@ -382,10 +385,10 @@ static int
 kni_net_tx(struct sk_buff *skb, struct net_device *dev)
 {
        struct kni_dev *kni = netdev_priv(dev);
-       
+
        dev_kfree_skb(skb);
        kni->stats.tx_dropped++;
-       
+
        return NETDEV_TX_OK;
 }
 #else
@@ -423,7 +426,8 @@ kni_net_tx(struct sk_buff *skb, struct net_device *dev)
                void *data_kva;
 
                pkt_kva = (void *)pkt_va - kni->mbuf_va + kni->mbuf_kva;
-               data_kva = pkt_kva->data - kni->mbuf_va + kni->mbuf_kva;
+               data_kva = pkt_kva->buf_addr + pkt_kva->data_off - kni->mbuf_va
+                               + kni->mbuf_kva;
 
                len = skb->len;
                memcpy(data_kva, skb->data, len);
@@ -612,6 +616,21 @@ kni_net_rebuild_header(struct sk_buff *skb)
        return 0;
 }
 
+/**
+ * kni_net_set_mac - Change the Ethernet Address of the KNI NIC
+ * @netdev: network interface device structure
+ * @p: pointer to an address structure
+ *
+ * Returns 0 on success, negative on failure
+ **/
+static int kni_net_set_mac(struct net_device *netdev, void *p)
+{
+       struct sockaddr *addr = p;
+       if (!is_valid_ether_addr((unsigned char *)(addr->sa_data)))
+               return -EADDRNOTAVAIL;
+       memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+       return 0;
+}
 
 static const struct header_ops kni_net_header_ops = {
        .create  = kni_net_header,
@@ -628,6 +647,7 @@ static const struct net_device_ops kni_net_netdev_ops = {
        .ndo_do_ioctl = kni_net_ioctl,
        .ndo_get_stats = kni_net_stats,
        .ndo_tx_timeout = kni_net_tx_timeout,
+       .ndo_set_mac_address = kni_net_set_mac,
 };
 
 void