/*-
* GPL LICENSE SUMMARY
- *
- * Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
- *
+ *
+ * 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
*/
#include <rte_config.h>
#include <exec-env/rte_kni_common.h>
+#include <kni_fifo.h>
#include "kni_dev.h"
#define WD_TIMEOUT 5 /*jiffies */
/* kni rx function pointer, with default to normal rx */
static kni_net_rx_t kni_net_rx_func = kni_net_rx_normal;
-
-/**
- * Adds num elements into the fifo. Return the number actually written
- */
-static inline unsigned
-kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num)
-{
- unsigned i = 0;
- unsigned fifo_write = fifo->write;
- unsigned fifo_read = fifo->read;
- unsigned new_write = fifo_write;
-
- for (i = 0; i < num; i++) {
- new_write = (new_write + 1) & (fifo->len - 1);
-
- if (new_write == fifo_read)
- break;
- fifo->buffer[fifo_write] = data[i];
- fifo_write = new_write;
- }
- fifo->write = fifo_write;
- return i;
-}
-
-/**
- * Get up to num elements from the fifo. Return the number actully read
- */
-static inline unsigned
-kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num)
-{
- unsigned i = 0;
- unsigned new_read = fifo->read;
- unsigned fifo_write = fifo->write;
- for (i = 0; i < num; i++) {
- if (new_read == fifo_write)
- break;
-
- data[i] = fifo->buffer[new_read];
- new_read = (new_read + 1) & (fifo->len - 1);
- }
- fifo->read = new_read;
- return i;
-}
-
-/**
- * Get the num of elements in the fifo
- */
-static inline unsigned
-kni_fifo_count(struct rte_kni_fifo *fifo)
-{
- return (fifo->len + fifo->write - fifo->read) &( fifo->len - 1);
-}
-
-/**
- * Get the num of available lements in the fifo
- */
-static inline unsigned
-kni_fifo_free_count(struct rte_kni_fifo *fifo)
-{
- return (fifo->read - fifo->write - 1) & (fifo->len - 1);
-}
-
/*
* Open and close
*/
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) {
skb->ip_summed = CHECKSUM_UNNECESSARY;
/* Call netif interface */
- netif_receive_skb(skb);
+ netif_rx(skb);
/* Update statistics */
kni->stats.rx_bytes += len;
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;
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)
skb_reserve(skb, 2);
memcpy(skb_put(skb, len), data_kva, len);
skb->dev = dev;
- skb->protocol = eth_type_trans(skb, dev);
skb->ip_summed = CHECKSUM_UNNECESSARY;
dev_kfree_skb(skb);
}
skb_reserve(skb, 2);
memcpy(skb_put(skb, len), data_kva, len);
skb->dev = dev;
- skb->protocol = eth_type_trans(skb, dev);
skb->ip_summed = CHECKSUM_UNNECESSARY;
kni->stats.rx_bytes += len;
/*
* Transmit a packet (called by the kernel)
*/
+#ifdef RTE_KNI_VHOST
+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
static int
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);
return NETDEV_TX_OK;
}
+#endif
/*
* Deal with a transmit timeout.
static int
kni_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
{
- struct kni_dev *kni = netdev_priv(dev);
- KNI_DBG("kni_net_ioctl %d\n", kni->port_id);
+ KNI_DBG("kni_net_ioctl %d\n",
+ ((struct kni_dev *)netdev_priv(dev))->group_id);
return 0;
}
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,
.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