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
net/ice: fix VXLAN/NVGRE flow matching
[dpdk.git]
/
drivers
/
net
/
af_packet
/
rte_eth_af_packet.c
diff --git
a/drivers/net/af_packet/rte_eth_af_packet.c
b/drivers/net/af_packet/rte_eth_af_packet.c
index
eb3cce3
..
2f6508f
100644
(file)
--- a/
drivers/net/af_packet/rte_eth_af_packet.c
+++ b/
drivers/net/af_packet/rte_eth_af_packet.c
@@
-6,6
+6,7
@@
* All rights reserved.
*/
* All rights reserved.
*/
+#include <rte_string_fns.h>
#include <rte_mbuf.h>
#include <rte_ethdev_driver.h>
#include <rte_ethdev_vdev.h>
#include <rte_mbuf.h>
#include <rte_ethdev_driver.h>
#include <rte_ethdev_vdev.h>
@@
-13,6
+14,7
@@
#include <rte_kvargs.h>
#include <rte_bus_vdev.h>
#include <rte_kvargs.h>
#include <rte_bus_vdev.h>
+#include <errno.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h>
#include <arpa/inet.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h>
#include <arpa/inet.h>
@@
-20,6
+22,7
@@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#include <poll.h>
#include <sys/mman.h>
#include <unistd.h>
#include <poll.h>
@@
-31,7
+34,6
@@
#define ETH_AF_PACKET_FRAMECOUNT_ARG "framecnt"
#define ETH_AF_PACKET_QDISC_BYPASS_ARG "qdisc_bypass"
#define ETH_AF_PACKET_FRAMECOUNT_ARG "framecnt"
#define ETH_AF_PACKET_QDISC_BYPASS_ARG "qdisc_bypass"
-#define DFLT_BLOCK_SIZE (1 << 12)
#define DFLT_FRAME_SIZE (1 << 11)
#define DFLT_FRAME_COUNT (1 << 9)
#define DFLT_FRAME_SIZE (1 << 11)
#define DFLT_FRAME_COUNT (1 << 9)
@@
-72,7
+74,7
@@
struct pmd_internals {
int if_index;
char *if_name;
int if_index;
char *if_name;
- struct ether_addr eth_addr;
+ struct
rte_
ether_addr eth_addr;
struct tpacket_req req;
struct tpacket_req req;
@@
-103,6
+105,10
@@
static int af_packet_logtype;
rte_log(RTE_LOG_ ## level, af_packet_logtype, \
"%s(): " fmt "\n", __func__, ##args)
rte_log(RTE_LOG_ ## level, af_packet_logtype, \
"%s(): " fmt "\n", __func__, ##args)
+#define PMD_LOG_ERRNO(level, fmt, args...) \
+ rte_log(RTE_LOG_ ## level, af_packet_logtype, \
+ "%s(): " fmt ":%s\n", __func__, ##args, strerror(errno))
+
static uint16_t
eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
{
static uint16_t
eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
{
@@
-305,7
+311,6
@@
eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
dev_info->max_rx_queues = (uint16_t)internals->nb_queues;
dev_info->max_tx_queues = (uint16_t)internals->nb_queues;
dev_info->min_rx_bufsize = 0;
dev_info->max_rx_queues = (uint16_t)internals->nb_queues;
dev_info->max_tx_queues = (uint16_t)internals->nb_queues;
dev_info->min_rx_bufsize = 0;
- dev_info->rx_offload_capa = DEV_RX_OFFLOAD_CRC_STRIP;
}
static int
}
static int
@@
-329,10
+334,9
@@
eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
internal->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS);
for (i = 0; i < imax; i++) {
igb_stats->q_opackets[i] = internal->tx_queue[i].tx_pkts;
internal->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS);
for (i = 0; i < imax; i++) {
igb_stats->q_opackets[i] = internal->tx_queue[i].tx_pkts;
- igb_stats->q_errors[i] = internal->tx_queue[i].err_pkts;
igb_stats->q_obytes[i] = internal->tx_queue[i].tx_bytes;
tx_total += igb_stats->q_opackets[i];
igb_stats->q_obytes[i] = internal->tx_queue[i].tx_bytes;
tx_total += igb_stats->q_opackets[i];
- tx_err_total += i
gb_stats->q_errors[i]
;
+ tx_err_total += i
nternal->tx_queue[i].err_pkts
;
tx_bytes_total += igb_stats->q_obytes[i];
}
tx_bytes_total += igb_stats->q_obytes[i];
}
@@
-434,8
+438,7
@@
eth_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
int ret;
int s;
unsigned int data_size = internals->req.tp_frame_size -
int ret;
int s;
unsigned int data_size = internals->req.tp_frame_size -
- TPACKET2_HDRLEN -
- sizeof(struct sockaddr_ll);
+ TPACKET2_HDRLEN;
if (mtu > data_size)
return -EINVAL;
if (mtu > data_size)
return -EINVAL;
@@
-444,7
+447,7
@@
eth_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
if (s < 0)
return -EINVAL;
if (s < 0)
return -EINVAL;
- s
nprintf(ifr.ifr_name, IFNAMSIZ, "%s", internals->if_name
);
+ s
trlcpy(ifr.ifr_name, internals->if_name, IFNAMSIZ
);
ret = ioctl(s, SIOCSIFMTU, &ifr);
close(s);
ret = ioctl(s, SIOCSIFMTU, &ifr);
close(s);
@@
-464,7
+467,7
@@
eth_dev_change_flags(char *if_name, uint32_t flags, uint32_t mask)
if (s < 0)
return;
if (s < 0)
return;
- s
nprintf(ifr.ifr_name, IFNAMSIZ, "%s", if_name
);
+ s
trlcpy(ifr.ifr_name, if_name, IFNAMSIZ
);
if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
goto out;
ifr.ifr_flags &= mask;
if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
goto out;
ifr.ifr_flags &= mask;
@@
-529,8
+532,6
@@
open_packet_iface(const char *key __rte_unused,
return 0;
}
return 0;
}
-static struct rte_vdev_driver pmd_af_packet_drv;
-
static int
rte_pmd_init_internals(struct rte_vdev_device *dev,
const int sockfd,
static int
rte_pmd_init_internals(struct rte_vdev_device *dev,
const int sockfd,
@@
-606,9
+607,7
@@
rte_pmd_init_internals(struct rte_vdev_device *dev,
return -1;
}
if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) {
return -1;
}
if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) {
- PMD_LOG(ERR,
- "%s: ioctl failed (SIOCGIFINDEX)",
- name);
+ PMD_LOG_ERRNO(ERR, "%s: ioctl failed (SIOCGIFINDEX)", name);
return -1;
}
(*internals)->if_name = strdup(pair->value);
return -1;
}
(*internals)->if_name = strdup(pair->value);
@@
-617,9
+616,7
@@
rte_pmd_init_internals(struct rte_vdev_device *dev,
(*internals)->if_index = ifr.ifr_ifindex;
if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) == -1) {
(*internals)->if_index = ifr.ifr_ifindex;
if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) == -1) {
- PMD_LOG(ERR,
- "%s: ioctl failed (SIOCGIFHWADDR)",
- name);
+ PMD_LOG_ERRNO(ERR, "%s: ioctl failed (SIOCGIFHWADDR)", name);
return -1;
}
memcpy(&(*internals)->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
return -1;
}
memcpy(&(*internals)->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
@@
-641,9
+638,9
@@
rte_pmd_init_internals(struct rte_vdev_device *dev,
/* Open an AF_PACKET socket for this queue... */
qsockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (qsockfd == -1) {
/* Open an AF_PACKET socket for this queue... */
qsockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (qsockfd == -1) {
- PMD_LOG(ERR,
+ PMD_LOG
_ERRNO
(ERR,
"%s: could not open AF_PACKET socket",
"%s: could not open AF_PACKET socket",
- name);
+ name);
return -1;
}
return -1;
}
@@
-651,7
+648,7
@@
rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_VERSION,
&tpver, sizeof(tpver));
if (rc == -1) {
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_VERSION,
&tpver, sizeof(tpver));
if (rc == -1) {
- PMD_LOG(ERR,
+ PMD_LOG
_ERRNO
(ERR,
"%s: could not set PACKET_VERSION on AF_PACKET socket for %s",
name, pair->value);
goto error;
"%s: could not set PACKET_VERSION on AF_PACKET socket for %s",
name, pair->value);
goto error;
@@
-661,7
+658,7
@@
rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_LOSS,
&discard, sizeof(discard));
if (rc == -1) {
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_LOSS,
&discard, sizeof(discard));
if (rc == -1) {
- PMD_LOG(ERR,
+ PMD_LOG
_ERRNO
(ERR,
"%s: could not set PACKET_LOSS on AF_PACKET socket for %s",
name, pair->value);
goto error;
"%s: could not set PACKET_LOSS on AF_PACKET socket for %s",
name, pair->value);
goto error;
@@
-671,7
+668,7
@@
rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_QDISC_BYPASS,
&qdisc_bypass, sizeof(qdisc_bypass));
if (rc == -1) {
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_QDISC_BYPASS,
&qdisc_bypass, sizeof(qdisc_bypass));
if (rc == -1) {
- PMD_LOG(ERR,
+ PMD_LOG
_ERRNO
(ERR,
"%s: could not set PACKET_QDISC_BYPASS on AF_PACKET socket for %s",
name, pair->value);
goto error;
"%s: could not set PACKET_QDISC_BYPASS on AF_PACKET socket for %s",
name, pair->value);
goto error;
@@
-682,7
+679,7
@@
rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_RX_RING, req, sizeof(*req));
if (rc == -1) {
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_RX_RING, req, sizeof(*req));
if (rc == -1) {
- PMD_LOG(ERR,
+ PMD_LOG
_ERRNO
(ERR,
"%s: could not set PACKET_RX_RING on AF_PACKET socket for %s",
name, pair->value);
goto error;
"%s: could not set PACKET_RX_RING on AF_PACKET socket for %s",
name, pair->value);
goto error;
@@
-690,7
+687,7
@@
rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_TX_RING, req, sizeof(*req));
if (rc == -1) {
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_TX_RING, req, sizeof(*req));
if (rc == -1) {
- PMD_LOG(ERR,
+ PMD_LOG
_ERRNO
(ERR,
"%s: could not set PACKET_TX_RING on AF_PACKET "
"socket for %s", name, pair->value);
goto error;
"%s: could not set PACKET_TX_RING on AF_PACKET "
"socket for %s", name, pair->value);
goto error;
@@
-703,7
+700,7
@@
rte_pmd_init_internals(struct rte_vdev_device *dev,
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_LOCKED,
qsockfd, 0);
if (rx_queue->map == MAP_FAILED) {
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_LOCKED,
qsockfd, 0);
if (rx_queue->map == MAP_FAILED) {
- PMD_LOG(ERR,
+ PMD_LOG
_ERRNO
(ERR,
"%s: call to mmap failed on AF_PACKET socket for %s",
name, pair->value);
goto error;
"%s: call to mmap failed on AF_PACKET socket for %s",
name, pair->value);
goto error;
@@
-740,9
+737,9
@@
rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = bind(qsockfd, (const struct sockaddr*)&sockaddr, sizeof(sockaddr));
if (rc == -1) {
rc = bind(qsockfd, (const struct sockaddr*)&sockaddr, sizeof(sockaddr));
if (rc == -1) {
- PMD_LOG(ERR,
+ PMD_LOG
_ERRNO
(ERR,
"%s: could not bind AF_PACKET socket to %s",
"%s: could not bind AF_PACKET socket to %s",
- name, pair->value);
+ name, pair->value);
goto error;
}
goto error;
}
@@
-750,9
+747,9
@@
rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_FANOUT,
&fanout_arg, sizeof(fanout_arg));
if (rc == -1) {
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_FANOUT,
&fanout_arg, sizeof(fanout_arg));
if (rc == -1) {
- PMD_LOG(ERR,
- "%s: could not set PACKET_FANOUT on AF_PACKET socket
"
-
"for %s",
name, pair->value);
+ PMD_LOG
_ERRNO
(ERR,
+ "%s: could not set PACKET_FANOUT on AF_PACKET socket
for %s",
+ name, pair->value);
goto error;
}
#endif
goto error;
}
#endif
@@
-813,7
+810,7
@@
rte_eth_from_packet(struct rte_vdev_device *dev,
struct rte_kvargs_pair *pair = NULL;
unsigned k_idx;
unsigned int blockcount;
struct rte_kvargs_pair *pair = NULL;
unsigned k_idx;
unsigned int blockcount;
- unsigned int blocksize
= DFLT_BLOCK_SIZE
;
+ unsigned int blocksize;
unsigned int framesize = DFLT_FRAME_SIZE;
unsigned int framecount = DFLT_FRAME_COUNT;
unsigned int qpairs = 1;
unsigned int framesize = DFLT_FRAME_SIZE;
unsigned int framecount = DFLT_FRAME_COUNT;
unsigned int qpairs = 1;
@@
-823,6
+820,8
@@
rte_eth_from_packet(struct rte_vdev_device *dev,
if (*sockfd < 0)
return -1;
if (*sockfd < 0)
return -1;
+ blocksize = getpagesize();
+
/*
* Walk arguments for configurable settings
*/
/*
* Walk arguments for configurable settings
*/
@@
-927,8
+926,7
@@
rte_pmd_af_packet_probe(struct rte_vdev_device *dev)
PMD_LOG(INFO, "Initializing pmd_af_packet for %s", name);
PMD_LOG(INFO, "Initializing pmd_af_packet for %s", name);
- if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
- strlen(rte_vdev_device_args(dev)) == 0) {
+ if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
eth_dev = rte_eth_dev_attach_secondary(name);
if (!eth_dev) {
PMD_LOG(ERR, "Failed to probe %s", name);
eth_dev = rte_eth_dev_attach_secondary(name);
if (!eth_dev) {
PMD_LOG(ERR, "Failed to probe %s", name);
@@
-988,6
+986,12
@@
rte_pmd_af_packet_remove(struct rte_vdev_device *dev)
if (eth_dev == NULL)
return -1;
if (eth_dev == NULL)
return -1;
+ /* mac_addrs must not be freed alone because part of dev_private */
+ eth_dev->data->mac_addrs = NULL;
+
+ if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+ return rte_eth_dev_release_port(eth_dev);
+
internals = eth_dev->data->dev_private;
for (q = 0; q < internals->nb_queues; q++) {
rte_free(internals->rx_queue[q].rd);
internals = eth_dev->data->dev_private;
for (q = 0; q < internals->nb_queues; q++) {
rte_free(internals->rx_queue[q].rd);
@@
-995,8
+999,6
@@
rte_pmd_af_packet_remove(struct rte_vdev_device *dev)
}
free(internals->if_name);
}
free(internals->if_name);
- rte_free(eth_dev->data->dev_private);
-
rte_eth_dev_release_port(eth_dev);
return 0;
rte_eth_dev_release_port(eth_dev);
return 0;