#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 <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#include <poll.h>
#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)
uint16_t in_port;
volatile unsigned long rx_pkts;
- volatile unsigned long err_pkts;
volatile unsigned long rx_bytes;
};
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)
{
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];
- tx_err_total += igb_stats->q_errors[i];
+ tx_err_total += internal->tx_queue[i].err_pkts;
tx_bytes_total += igb_stats->q_obytes[i];
}
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,
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);
(*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);
/* 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",
- name);
+ name);
return -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;
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;
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;
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;
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;
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;
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",
- name, pair->value);
+ name, pair->value);
goto error;
}
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
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;
if (*sockfd < 0)
return -1;
+ blocksize = getpagesize();
+
/*
* Walk arguments for configurable settings
*/