X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Faf_packet%2Frte_eth_af_packet.c;h=dce76b04e553d3805819a193da84564983a1ca09;hb=44c63fcbd9c30d9d11dc40744bb25ebda8ae1c0f;hp=bc7daed5e2dea1df7898c1b3926e469054de6d38;hpb=323e7b667f18376c60351282950b28d4d0cc6165;p=dpdk.git diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index bc7daed5e2..dce76b04e5 100644 --- 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. */ +#include #include #include #include @@ -13,6 +14,7 @@ #include #include +#include #include #include #include @@ -20,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -31,7 +34,6 @@ #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) @@ -49,7 +51,6 @@ struct pkt_rx_queue { uint16_t in_port; volatile unsigned long rx_pkts; - volatile unsigned long err_pkts; volatile unsigned long rx_bytes; }; @@ -72,7 +73,7 @@ struct pmd_internals { int if_index; char *if_name; - struct ether_addr eth_addr; + struct rte_ether_addr eth_addr; struct tpacket_req req; @@ -103,6 +104,10 @@ static int af_packet_logtype; 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) { @@ -294,7 +299,7 @@ eth_dev_configure(struct rte_eth_dev *dev __rte_unused) return 0; } -static void +static int eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) { struct pmd_internals *internals = dev->data->dev_private; @@ -305,6 +310,8 @@ 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; + + return 0; } static int @@ -328,10 +335,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; - 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]; } @@ -343,7 +349,7 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats) return 0; } -static void +static int eth_stats_reset(struct rte_eth_dev *dev) { unsigned i; @@ -359,6 +365,8 @@ eth_stats_reset(struct rte_eth_dev *dev) internal->tx_queue[i].err_pkts = 0; internal->tx_queue[i].tx_bytes = 0; } + + return 0; } static void @@ -433,8 +441,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 - - TPACKET2_HDRLEN - - sizeof(struct sockaddr_ll); + TPACKET2_HDRLEN; if (mtu > data_size) return -EINVAL; @@ -443,7 +450,7 @@ eth_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) if (s < 0) return -EINVAL; - snprintf(ifr.ifr_name, IFNAMSIZ, "%s", internals->if_name); + strlcpy(ifr.ifr_name, internals->if_name, IFNAMSIZ); ret = ioctl(s, SIOCSIFMTU, &ifr); close(s); @@ -453,41 +460,47 @@ eth_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) return 0; } -static void +static int eth_dev_change_flags(char *if_name, uint32_t flags, uint32_t mask) { struct ifreq ifr; + int ret = 0; int s; s = socket(PF_INET, SOCK_DGRAM, 0); if (s < 0) - return; + return -errno; - snprintf(ifr.ifr_name, IFNAMSIZ, "%s", if_name); - if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0) + strlcpy(ifr.ifr_name, if_name, IFNAMSIZ); + if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0) { + ret = -errno; goto out; + } ifr.ifr_flags &= mask; ifr.ifr_flags |= flags; - if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0) + if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0) { + ret = -errno; goto out; + } out: close(s); + return ret; } -static void +static int eth_dev_promiscuous_enable(struct rte_eth_dev *dev) { struct pmd_internals *internals = dev->data->dev_private; - eth_dev_change_flags(internals->if_name, IFF_PROMISC, ~0); + return eth_dev_change_flags(internals->if_name, IFF_PROMISC, ~0); } -static void +static int eth_dev_promiscuous_disable(struct rte_eth_dev *dev) { struct pmd_internals *internals = dev->data->dev_private; - eth_dev_change_flags(internals->if_name, 0, ~IFF_PROMISC); + return eth_dev_change_flags(internals->if_name, 0, ~IFF_PROMISC); } static const struct eth_dev_ops ops = { @@ -528,8 +541,6 @@ open_packet_iface(const char *key __rte_unused, 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, @@ -605,9 +616,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, 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); @@ -616,9 +625,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, (*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); @@ -640,9 +647,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) { - PMD_LOG(ERR, + PMD_LOG_ERRNO(ERR, "%s: could not open AF_PACKET socket", - name); + name); return -1; } @@ -650,7 +657,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, 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; @@ -660,7 +667,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, 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; @@ -670,7 +677,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) { - 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; @@ -681,7 +688,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, 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; @@ -689,7 +696,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, 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; @@ -702,7 +709,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) { - PMD_LOG(ERR, + PMD_LOG_ERRNO(ERR, "%s: call to mmap failed on AF_PACKET socket for %s", name, pair->value); goto error; @@ -739,9 +746,9 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, 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; } @@ -749,9 +756,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) { - 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 @@ -812,7 +819,7 @@ rte_eth_from_packet(struct rte_vdev_device *dev, 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; @@ -822,6 +829,8 @@ rte_eth_from_packet(struct rte_vdev_device *dev, if (*sockfd < 0) return -1; + blocksize = getpagesize(); + /* * Walk arguments for configurable settings */ @@ -926,8 +935,7 @@ rte_pmd_af_packet_probe(struct rte_vdev_device *dev) 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); @@ -974,6 +982,7 @@ rte_pmd_af_packet_remove(struct rte_vdev_device *dev) { struct rte_eth_dev *eth_dev = NULL; struct pmd_internals *internals; + struct tpacket_req *req; unsigned q; PMD_LOG(INFO, "Closing AF_PACKET ethdev on numa socket %u", @@ -987,15 +996,22 @@ rte_pmd_af_packet_remove(struct rte_vdev_device *dev) 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; + req = &internals->req; for (q = 0; q < internals->nb_queues; q++) { + munmap(internals->rx_queue[q].map, + 2 * req->tp_block_size * req->tp_block_nr); rte_free(internals->rx_queue[q].rd); rte_free(internals->tx_queue[q].rd); } free(internals->if_name); - rte_free(eth_dev->data->dev_private); - rte_eth_dev_release_port(eth_dev); return 0;