From patchwork Fri Mar 27 17:56:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 46438 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D1B3B21597 for ; Fri, 27 Mar 2015 17:57:36 +0000 (UTC) Received: by wixm2 with SMTP id m2sf6433803wix.0 for ; Fri, 27 Mar 2015 10:57:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=h6XnxKi4GAJfIxQ/p2ncoUu/PLOtN170vhfxA/ugv34=; b=NZyDrLZ/mMObX4ya3lm7GFjLmqtWjCul4OEpnE2tkhuz1FWS48xaWBrMaAzXchVxdv moU8HJeDHygaExJNIS2x6EyNmnByTfaTFCbgoNpcw2tW+tUGj3k9o8ono+MBkiOzZICl 24ABvITc/4P7EUVrgJQQ9WUSyZZoJ/rNX1U1B8NF7+pAwFDs+QZiKVfU0q+hDnP5FH2Y MBtyX9sEtxCeGLVbY2N6tAHaWw8S3lpTyncPLueYlDopQaTmvBCjsM6u5Qzz5YtF+FEJ Qoae5sst1eozwmXiWu8Lu8DZwVwRcNALLzJelHdSAQXuH6sOH1nHpJvGgLC/XLgdeW4X iSKw== X-Gm-Message-State: ALoCoQmrl51ZUDGM+TfIPofSWL4a04FtvhVeYprWI5rnbBtJBbk0XiDv3Spq683Zrx4gK++Khyu5 X-Received: by 10.112.17.105 with SMTP id n9mr4877984lbd.8.1427479056046; Fri, 27 Mar 2015 10:57:36 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.164 with SMTP id an4ls415061lac.19.gmail; Fri, 27 Mar 2015 10:57:35 -0700 (PDT) X-Received: by 10.112.145.230 with SMTP id sx6mr18655635lbb.70.1427479055887; Fri, 27 Mar 2015 10:57:35 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id m20si1840194lbg.107.2015.03.27.10.57.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Mar 2015 10:57:35 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbcmq2 with SMTP id mq2so69155137lbc.0 for ; Fri, 27 Mar 2015 10:57:35 -0700 (PDT) X-Received: by 10.152.5.72 with SMTP id q8mr1407935laq.73.1427479055742; Fri, 27 Mar 2015 10:57:35 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.57.201 with SMTP id k9csp30089lbq; Fri, 27 Mar 2015 10:57:35 -0700 (PDT) X-Received: by 10.229.227.71 with SMTP id iz7mr26973432qcb.0.1427479053639; Fri, 27 Mar 2015 10:57:33 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id p46si2559903qgp.124.2015.03.27.10.57.13 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 27 Mar 2015 10:57:33 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YbYVG-0008SB-L1; Fri, 27 Mar 2015 17:57:06 +0000 Received: from mail-lb0-f171.google.com ([209.85.217.171]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YbYV6-0008Rj-0K for lng-odp@lists.linaro.org; Fri, 27 Mar 2015 17:56:56 +0000 Received: by lboc7 with SMTP id c7so12256086lbo.1 for ; Fri, 27 Mar 2015 10:56:50 -0700 (PDT) X-Received: by 10.152.9.98 with SMTP id y2mr18615107laa.94.1427479010400; Fri, 27 Mar 2015 10:56:50 -0700 (PDT) Received: from cipriantemp.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id m8sm468335laf.14.2015.03.27.10.56.49 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Mar 2015 10:56:49 -0700 (PDT) From: Ciprian Barbu To: lng-odp@lists.linaro.org Date: Fri, 27 Mar 2015 19:56:39 +0200 Message-Id: <1427479000-25779-2-git-send-email-ciprian.barbu@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1427479000-25779-1-git-send-email-ciprian.barbu@linaro.org> References: <1427479000-25779-1-git-send-email-ciprian.barbu@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH NETMAP 1/2] linux-netmap: implement odp_pktio_mac_addr X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ciprian.barbu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Signed-off-by: Ciprian Barbu --- platform/linux-netmap/include/odp_packet_netmap.h | 6 +++ platform/linux-netmap/odp_packet_io.c | 4 ++ platform/linux-netmap/odp_packet_netmap.c | 51 +++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/platform/linux-netmap/include/odp_packet_netmap.h b/platform/linux-netmap/include/odp_packet_netmap.h index 24d7923..4b75a6d 100644 --- a/platform/linux-netmap/include/odp_packet_netmap.h +++ b/platform/linux-netmap/include/odp_packet_netmap.h @@ -54,4 +54,10 @@ int recv_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], */ int send_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], unsigned len); + +/** + * Get mac address + */ +void pkt_netmap_mac_addr(pkt_netmap_t * const pkt_nm, void *mac_addr, + int addr_size); #endif diff --git a/platform/linux-netmap/odp_packet_io.c b/platform/linux-netmap/odp_packet_io.c index 554d38e..1957ad0 100644 --- a/platform/linux-netmap/odp_packet_io.c +++ b/platform/linux-netmap/odp_packet_io.c @@ -864,6 +864,10 @@ int odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, int addr_size) } switch (entry->s.type) { + case ODP_PKTIO_TYPE_NETMAP: + pkt_netmap_mac_addr(&entry->s.pkt_nm, + mac_addr, addr_size); + break; case ODP_PKTIO_TYPE_SOCKET_BASIC: case ODP_PKTIO_TYPE_SOCKET_MMSG: memcpy(mac_addr, entry->s.pkt_sock.if_mac, diff --git a/platform/linux-netmap/odp_packet_netmap.c b/platform/linux-netmap/odp_packet_netmap.c index fb64db2..11954a2 100644 --- a/platform/linux-netmap/odp_packet_netmap.c +++ b/platform/linux-netmap/odp_packet_netmap.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -47,6 +48,7 @@ */ typedef struct netmap_dev_t { char ifname[IFNAMSIZ]; + unsigned char if_mac[ETH_ALEN]; odp_ticketlock_t rx_lock; odp_ticketlock_t tx_lock; } netmap_dev_t; @@ -141,6 +143,41 @@ done: return error; } +static void ethaddr_copy(unsigned char mac_dst[], unsigned char mac_src[]) +{ + memcpy(mac_dst, mac_src, ETH_ALEN); +} + +static int get_mac_addr(pkt_netmap_t *pkt_nm) +{ + struct ifreq ethreq; + int sockfd; + int err; + + sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); + if (sockfd == -1) { + ODP_ERR("socket(): %s\n", strerror(errno)); + goto error; + } + + memset(ðreq, 0, sizeof(ethreq)); + snprintf(ethreq.ifr_name, IFNAMSIZ, "%s", pkt_nm->nm_dev->ifname); + err = ioctl(sockfd, SIOCGIFHWADDR, ðreq); + if (err != 0) { + ODP_ERR("ioctl(SIOCGIFHWADDR): %s\n", strerror(errno)); + goto error; + } + ethaddr_copy(pkt_nm->nm_dev->if_mac, + (unsigned char *)ethreq.ifr_ifru.ifru_hwaddr.sa_data); + + return 0; + +error: + __odp_errno = errno; + + return -1; +} + int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, odp_pool_t pool) { @@ -240,6 +277,11 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, /* nm_do_ioctl(pkt_nm, SIOCETHTOOL, ETHTOOL_SRXCSUM); */ + ret = get_mac_addr(pkt_nm); + if (ret) + ODP_ERR("[%04d] Failed to get MAC addr\n", + odp_thread_id()); + ret = nm_do_ioctl(pkt_nm, SIOCETHTOOL, ETHTOOL_STXCSUM); if (ret) ODP_DBG("[%04d] ETHTOOL_STXCSUM not supported\n", @@ -366,3 +408,12 @@ out: return nb_tx; } + +inline void pkt_netmap_mac_addr(pkt_netmap_t * const pkt_nm, void *mac_addr, + int addr_size) +{ + if (addr_size < ETH_ALEN) + return; + + memcpy(mac_addr, pkt_nm->nm_dev->if_mac, ETH_ALEN); +}