git.droids-corp.org
/
dpdk.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
vfio: fix typo in doc for device setup
[dpdk.git]
/
lib
/
librte_eal
/
linuxapp
/
kni
/
kni_net.c
diff --git
a/lib/librte_eal/linuxapp/kni/kni_net.c
b/lib/librte_eal/linuxapp/kni/kni_net.c
index
dd95db5
..
fc82193
100644
(file)
--- a/
lib/librte_eal/linuxapp/kni/kni_net.c
+++ b/
lib/librte_eal/linuxapp/kni/kni_net.c
@@
-36,9
+36,10
@@
#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/kthread.h>
#include <linux/delay.h>
-#include <rte_config.h>
#include <exec-env/rte_kni_common.h>
#include <kni_fifo.h>
#include <exec-env/rte_kni_common.h>
#include <kni_fifo.h>
+
+#include "compat.h"
#include "kni_dev.h"
#define WD_TIMEOUT 5 /*jiffies */
#include "kni_dev.h"
#define WD_TIMEOUT 5 /*jiffies */
@@
-70,15
+71,6
@@
kni_net_open(struct net_device *dev)
struct rte_kni_request req;
struct kni_dev *kni = netdev_priv(dev);
struct rte_kni_request req;
struct kni_dev *kni = netdev_priv(dev);
- if (kni->lad_dev)
- memcpy(dev->dev_addr, kni->lad_dev->dev_addr, ETH_ALEN);
- else
- /*
- * Generate random mac address. eth_random_addr() is the newer
- * version of generating mac address in linux kernel.
- */
- random_ether_addr(dev->dev_addr);
-
netif_start_queue(dev);
memset(&req, 0, sizeof(req));
netif_start_queue(dev);
memset(&req, 0, sizeof(req));
@@
-88,7
+80,7
@@
kni_net_open(struct net_device *dev)
req.if_up = 1;
ret = kni_net_process_request(kni, &req);
req.if_up = 1;
ret = kni_net_process_request(kni, &req);
- return (ret == 0
? req.result : ret)
;
+ return (ret == 0
) ? req.result : ret
;
}
static int
}
static int
@@
-107,7
+99,7
@@
kni_net_release(struct net_device *dev)
req.if_up = 0;
ret = kni_net_process_request(kni, &req);
req.if_up = 0;
ret = kni_net_process_request(kni, &req);
- return (ret == 0
? req.result : ret)
;
+ return (ret == 0
) ? req.result : ret
;
}
/*
}
/*
@@
-131,7
+123,7
@@
kni_net_rx_normal(struct kni_dev *kni)
{
unsigned ret;
uint32_t len;
{
unsigned ret;
uint32_t len;
- unsigned i, num
, num_rq
, num_fq;
+ unsigned i, num
_rx
, num_fq;
struct rte_kni_mbuf *kva;
struct rte_kni_mbuf *va[MBUF_BURST_SZ];
void * data_kva;
struct rte_kni_mbuf *kva;
struct rte_kni_mbuf *va[MBUF_BURST_SZ];
void * data_kva;
@@
-139,29
+131,26
@@
kni_net_rx_normal(struct kni_dev *kni)
struct sk_buff *skb;
struct net_device *dev = kni->net_dev;
struct sk_buff *skb;
struct net_device *dev = kni->net_dev;
- /* Get the number of entries in rx_q */
- num_rq = kni_fifo_count(kni->rx_q);
-
/* Get the number of free entries in free_q */
num_fq = kni_fifo_free_count(kni->free_q);
/* Get the number of free entries in free_q */
num_fq = kni_fifo_free_count(kni->free_q);
-
- /* Calculate the number of entries to dequeue in rx_q */
- num = min(num_rq, num_fq);
- num = min(num, (unsigned)MBUF_BURST_SZ);
-
- /* Return if no entry in rx_q and no free entry in free_q */
- if (num == 0)
+ if (num_fq == 0) {
+ /* No room on the free_q, bail out */
return;
return;
+ }
+
+ /* Calculate the number of entries to dequeue from rx_q */
+ num_rx = min(num_fq, (unsigned)MBUF_BURST_SZ);
/* Burst dequeue from rx_q */
/* Burst dequeue from rx_q */
-
ret = kni_fifo_get(kni->rx_q, (void **)va, num
);
- if (
ret
== 0)
- return;
/* Failing should not happen */
+
num_rx = kni_fifo_get(kni->rx_q, (void **)va, num_rx
);
+ if (
num_rx
== 0)
+ return;
/* Transfer received packets to netif */
/* Transfer received packets to netif */
- for (i = 0; i < num; i++) {
+ for (i = 0; i < num
_rx
; i++) {
kva = (void *)va[i] - kni->mbuf_va + kni->mbuf_kva;
kva = (void *)va[i] - kni->mbuf_va + kni->mbuf_kva;
- len = kva->data_len;
+ len = kva->pkt_len;
+
data_kva = kva->buf_addr + kva->data_off - kni->mbuf_va
+ kni->mbuf_kva;
data_kva = kva->buf_addr + kva->data_off - kni->mbuf_va
+ kni->mbuf_kva;
@@
-170,27
+159,46
@@
kni_net_rx_normal(struct kni_dev *kni)
KNI_ERR("Out of mem, dropping pkts\n");
/* Update statistics */
kni->stats.rx_dropped++;
KNI_ERR("Out of mem, dropping pkts\n");
/* Update statistics */
kni->stats.rx_dropped++;
+ continue;
}
}
- else {
- /* Align IP on 16B boundary */
- skb_reserve(skb, 2);
+
+ /* Align IP on 16B boundary */
+ skb_reserve(skb, 2);
+
+ if (kva->nb_segs == 1) {
memcpy(skb_put(skb, len), data_kva, len);
memcpy(skb_put(skb, len), data_kva, len);
- skb->dev = dev;
-
skb->protocol = eth_type_trans(skb, dev)
;
-
skb->ip_summed = CHECKSUM_UNNECESSARY
;
+ } else {
+
int nb_segs
;
+
int kva_nb_segs = kva->nb_segs
;
- /* Call netif interface */
- netif_rx(skb);
+ for (nb_segs = 0; nb_segs < kva_nb_segs; nb_segs++) {
+ memcpy(skb_put(skb, kva->data_len),
+ data_kva, kva->data_len);
- /* Update statistics */
- kni->stats.rx_bytes += len;
- kni->stats.rx_packets++;
+ if (!kva->next)
+ break;
+
+ kva = kva->next - kni->mbuf_va + kni->mbuf_kva;
+ data_kva = kva->buf_addr + kva->data_off
+ - kni->mbuf_va + kni->mbuf_kva;
+ }
}
}
+
+ skb->dev = dev;
+ skb->protocol = eth_type_trans(skb, dev);
+ skb->ip_summed = CHECKSUM_UNNECESSARY;
+
+ /* Call netif interface */
+ netif_rx_ni(skb);
+
+ /* Update statistics */
+ kni->stats.rx_bytes += len;
+ kni->stats.rx_packets++;
}
/* Burst enqueue mbufs into free_q */
}
/* Burst enqueue mbufs into free_q */
- ret = kni_fifo_put(kni->free_q, (void **)va, num);
- if (ret != num)
+ ret = kni_fifo_put(kni->free_q, (void **)va, num
_rx
);
+ if (ret != num
_rx
)
/* Failing should not happen */
KNI_ERR("Fail to enqueue entries into free_q\n");
}
/* Failing should not happen */
KNI_ERR("Fail to enqueue entries into free_q\n");
}
@@
-322,7
+330,7
@@
kni_net_rx_lo_fifo_skb(struct kni_dev *kni)
/* Copy mbufs to sk buffer and then call tx interface */
for (i = 0; i < num; i++) {
kva = (void *)va[i] - kni->mbuf_va + kni->mbuf_kva;
/* Copy mbufs to sk buffer and then call tx interface */
for (i = 0; i < num; i++) {
kva = (void *)va[i] - kni->mbuf_va + kni->mbuf_kva;
- len = kva->
data
_len;
+ len = kva->
pkt
_len;
data_kva = kva->buf_addr + kva->data_off - kni->mbuf_va +
kni->mbuf_kva;
data_kva = kva->buf_addr + kva->data_off - kni->mbuf_va +
kni->mbuf_kva;
@@
-343,20
+351,39
@@
kni_net_rx_lo_fifo_skb(struct kni_dev *kni)
if (skb == NULL) {
KNI_ERR("Out of mem, dropping pkts\n");
kni->stats.rx_dropped++;
if (skb == NULL) {
KNI_ERR("Out of mem, dropping pkts\n");
kni->stats.rx_dropped++;
+ continue;
}
}
- else {
- /* Align IP on 16B boundary */
- skb_reserve(skb, 2);
+
+ /* Align IP on 16B boundary */
+ skb_reserve(skb, 2);
+
+ if (kva->nb_segs == 1) {
memcpy(skb_put(skb, len), data_kva, len);
memcpy(skb_put(skb, len), data_kva, len);
- skb->dev = dev;
- skb->ip_summed = CHECKSUM_UNNECESSARY;
+ } else {
+ int nb_segs;
+ int kva_nb_segs = kva->nb_segs;
- kni->stats.rx_bytes += len;
- kni->stats.rx_packets++;
+ for (nb_segs = 0; nb_segs < kva_nb_segs; nb_segs++) {
+ memcpy(skb_put(skb, kva->data_len),
+ data_kva, kva->data_len);
+
+ if (!kva->next)
+ break;
- /* call tx interface */
- kni_net_tx(skb, dev);
+ kva = kva->next - kni->mbuf_va + kni->mbuf_kva;
+ data_kva = kva->buf_addr + kva->data_off
+ - kni->mbuf_va + kni->mbuf_kva;
+ }
}
}
+
+ skb->dev = dev;
+ skb->ip_summed = CHECKSUM_UNNECESSARY;
+
+ kni->stats.rx_bytes += len;
+ kni->stats.rx_packets++;
+
+ /* call tx interface */
+ kni_net_tx(skb, dev);
}
/* enqueue all the mbufs from rx_q into free_q */
}
/* enqueue all the mbufs from rx_q into free_q */
@@
-401,7
+428,12
@@
kni_net_tx(struct sk_buff *skb, struct net_device *dev)
struct rte_kni_mbuf *pkt_kva = NULL;
struct rte_kni_mbuf *pkt_va = NULL;
struct rte_kni_mbuf *pkt_kva = NULL;
struct rte_kni_mbuf *pkt_va = NULL;
- dev->trans_start = jiffies; /* save the timestamp */
+ /* save the timestamp */
+#ifdef HAVE_TRANS_START_HELPER
+ netif_trans_update(dev);
+#else
+ dev->trans_start = jiffies;
+#endif
/* Check if the length of skb is less than mbuf size */
if (skb->len > kni->mbuf_size)
/* Check if the length of skb is less than mbuf size */
if (skb->len > kni->mbuf_size)
@@
-495,6
+527,11
@@
kni_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
return 0;
}
return 0;
}
+static void
+kni_net_set_rx_mode(struct net_device *dev)
+{
+}
+
static int
kni_net_change_mtu(struct net_device *dev, int new_mtu)
{
static int
kni_net_change_mtu(struct net_device *dev, int new_mtu)
{
@@
-511,7
+548,7
@@
kni_net_change_mtu(struct net_device *dev, int new_mtu)
if (ret == 0 && req.result == 0)
dev->mtu = new_mtu;
if (ret == 0 && req.result == 0)
dev->mtu = new_mtu;
- return (ret == 0
? req.result : ret)
;
+ return (ret == 0
) ? req.result : ret
;
}
/*
}
/*
@@
-597,13
+634,14
@@
kni_net_header(struct sk_buff *skb, struct net_device *dev,
memcpy(eth->h_dest, daddr ? daddr : dev->dev_addr, dev->addr_len);
eth->h_proto = htons(type);
memcpy(eth->h_dest, daddr ? daddr : dev->dev_addr, dev->addr_len);
eth->h_proto = htons(type);
- return
(dev->hard_header_len)
;
+ return
dev->hard_header_len
;
}
/*
* Re-fill the eth header
*/
}
/*
* Re-fill the eth header
*/
+#ifdef HAVE_REBUILD_HEADER
static int
kni_net_rebuild_header(struct sk_buff *skb)
{
static int
kni_net_rebuild_header(struct sk_buff *skb)
{
@@
-615,6
+653,7
@@
kni_net_rebuild_header(struct sk_buff *skb)
return 0;
}
return 0;
}
+#endif /* < 4.1.0 */
/**
* kni_net_set_mac - Change the Ethernet Address of the KNI NIC
/**
* kni_net_set_mac - Change the Ethernet Address of the KNI NIC
@@
-632,9
+671,22
@@
static int kni_net_set_mac(struct net_device *netdev, void *p)
return 0;
}
return 0;
}
+#ifdef HAVE_CHANGE_CARRIER_CB
+static int kni_net_change_carrier(struct net_device *dev, bool new_carrier)
+{
+ if (new_carrier)
+ netif_carrier_on(dev);
+ else
+ netif_carrier_off(dev);
+ return 0;
+}
+#endif
+
static const struct header_ops kni_net_header_ops = {
.create = kni_net_header,
static const struct header_ops kni_net_header_ops = {
.create = kni_net_header,
+#ifdef HAVE_REBUILD_HEADER
.rebuild = kni_net_rebuild_header,
.rebuild = kni_net_rebuild_header,
+#endif /* < 4.1.0 */
.cache = NULL, /* disable caching */
};
.cache = NULL, /* disable caching */
};
@@
-645,9
+697,13
@@
static const struct net_device_ops kni_net_netdev_ops = {
.ndo_start_xmit = kni_net_tx,
.ndo_change_mtu = kni_net_change_mtu,
.ndo_do_ioctl = kni_net_ioctl,
.ndo_start_xmit = kni_net_tx,
.ndo_change_mtu = kni_net_change_mtu,
.ndo_do_ioctl = kni_net_ioctl,
+ .ndo_set_rx_mode = kni_net_set_rx_mode,
.ndo_get_stats = kni_net_stats,
.ndo_tx_timeout = kni_net_tx_timeout,
.ndo_set_mac_address = kni_net_set_mac,
.ndo_get_stats = kni_net_stats,
.ndo_tx_timeout = kni_net_tx_timeout,
.ndo_set_mac_address = kni_net_set_mac,
+#ifdef HAVE_CHANGE_CARRIER_CB
+ .ndo_change_carrier = kni_net_change_carrier,
+#endif
};
void
};
void