From patchwork Tue Aug 19 05:56:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 35550 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2C51C20523 for ; Tue, 19 Aug 2014 05:57:08 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wp18sf40712399obc.9 for ; Mon, 18 Aug 2014 22:57:07 -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:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=XALQewuNI2IIJnKJ16xxdFNbjmFpxRn1YDxA39JufeQ=; b=VC09HnZHrT8z1PDyPZlOIqMQZv79IzWZMzimFRIhzKhMI5jFAPCUASc+MfHW4fLA0v 9j5JQ6o5Qz43HY/wTu5+wmK4X2GJgZXgnvqiGZFifnxWxBdXyyDCw7lFdU0HBZN8Uvb4 c3diMDh5TvQlLGLiWDy72pNcmi7pmLZ0SyeVS9jZSljO69HdoNCiaSe0cpbZScBTwPvl 961mVQlf4jlcBt6OZti/S1Y9e/w3h8ihHCePqDhbM4Fs8pTUehLlIpWzMCRt+N/Hz0MT /sMDAuZS476CtmyA/jt7FQq4kZegOWT2sDlKgQtan3RmQoFeik0O5OmtF7PZDvBUwiEs IO9g== X-Gm-Message-State: ALoCoQmsHKOY420WmX9QIP1RWQcN1U6qBgOUbf6gLTCv8+0WuOZ+3vUZoQwIQWUGswZnG9j+CCLj X-Received: by 10.182.56.200 with SMTP id c8mr21933468obq.7.1408427827773; Mon, 18 Aug 2014 22:57:07 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.49.83 with SMTP id p77ls2640368qga.97.gmail; Mon, 18 Aug 2014 22:57:07 -0700 (PDT) X-Received: by 10.52.160.10 with SMTP id xg10mr616819vdb.1.1408427827656; Mon, 18 Aug 2014 22:57:07 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id sr5si2209333vdc.86.2014.08.18.22.57.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Aug 2014 22:57:07 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id im17so6904378vcb.17 for ; Mon, 18 Aug 2014 22:57:07 -0700 (PDT) X-Received: by 10.221.44.69 with SMTP id uf5mr28690612vcb.4.1408427827552; Mon, 18 Aug 2014 22:57:07 -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.221.37.5 with SMTP id tc5csp212297vcb; Mon, 18 Aug 2014 22:57:07 -0700 (PDT) X-Received: by 10.221.5.137 with SMTP id og9mr28688840vcb.18.1408427827140; Mon, 18 Aug 2014 22:57:07 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id tb1si8221224vdc.96.2014.08.18.22.57.05 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 18 Aug 2014 22:57:07 -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-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XJcPo-0004NP-I3; Tue, 19 Aug 2014 05:57:04 +0000 Received: from mail-yk0-f175.google.com ([209.85.160.175]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XJcPi-0004M8-Vv for lng-odp@lists.linaro.org; Tue, 19 Aug 2014 05:56:59 +0000 Received: by mail-yk0-f175.google.com with SMTP id q200so5061065ykb.34 for ; Mon, 18 Aug 2014 22:56:53 -0700 (PDT) X-Received: by 10.236.27.105 with SMTP id d69mr59061081yha.72.1408427813770; Mon, 18 Aug 2014 22:56:53 -0700 (PDT) Received: from bala-PowerEdge-T110-II.caveonetworks.com ([111.93.218.67]) by mx.google.com with ESMTPSA id e10sm40237898yhh.40.2014.08.18.22.56.51 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Aug 2014 22:56:53 -0700 (PDT) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Tue, 19 Aug 2014 11:26:03 +0530 Message-Id: <1408427763-30086-1-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Topics: patch Subject: [lng-odp] [PATCH 1/1] API support to get mac address of an interface using odp_pktio_t 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: bala.manoharan@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.220.172 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 Regards, Bala Signed-off-by: Balasubramanian Manoharan --- include/odp_packet_io.h | 8 +++++++ platform/linux-generic/include/odp_packet_netmap.h | 1 + platform/linux-generic/odp_packet_io.c | 28 +++++++++++++++++++++- platform/linux-generic/odp_packet_netmap.c | 4 +++- platform/linux-generic/odp_packet_socket.c | 8 +++---- 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/include/odp_packet_io.h b/include/odp_packet_io.h index cfefac0..6c06520 100644 --- a/include/odp_packet_io.h +++ b/include/odp_packet_io.h @@ -129,6 +129,14 @@ void odp_pktio_set_input(odp_packet_t pkt, odp_pktio_t id); */ odp_pktio_t odp_pktio_get_input(odp_packet_t pkt); +/** + * Get mac address of the interface + * + * @param id ODP packet IO handle + * @param mac_addr Storage for Mac address of the packet IO interface (filled by function) + * @return 0 on success or -1 on error +**/ +int odp_pktio_get_mac_addr(odp_pktio_t id, unsigned char* mac_addr); #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/include/odp_packet_netmap.h b/platform/linux-generic/include/odp_packet_netmap.h index 57d9f2c..3693416 100644 --- a/platform/linux-generic/include/odp_packet_netmap.h +++ b/platform/linux-generic/include/odp_packet_netmap.h @@ -40,6 +40,7 @@ typedef struct { odp_queue_t tx_access; /* Used for exclusive access to send packets */ uint32_t if_flags; char ifname[32]; + unsigned char if_mac[ETH_ALEN]; } pkt_netmap_t; /** diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 33ade10..069b0e1 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -245,7 +245,7 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool, ODP_ERR("This type of I/O is not supported. Please recompile.\n"); break; } - + pktio_entry->s.params.type = params->type; unlock_entry(pktio_entry); return id; } @@ -535,3 +535,29 @@ int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num) return nbr; } +int odp_pktio_get_mac_addr(odp_pktio_t pkt, unsigned char* mac_addr){ + + pktio_entry_t * pktio_entry = get_entry(pkt); + if(!pktio_entry){ + printf("Invalid odp_pktio_t value\n"); + return ODP_PKTIO_INVALID; + } + switch(pktio_entry->s.params.type){ + case ODP_PKTIO_TYPE_SOCKET_BASIC: + case ODP_PKTIO_TYPE_SOCKET_MMSG: + memcpy(mac_addr, pktio_entry->s.pkt_sock.if_mac, ETH_ALEN); + break; + case ODP_PKTIO_TYPE_SOCKET_MMAP: + memcpy(mac_addr, pktio_entry->s.pkt_sock_mmap.if_mac, ETH_ALEN); + break; +#ifdef ODP_HAVE_NETMAP + case ODP_PKTIO_TYPE_NETMAP: + memcpy(mac_addr, pktio_entry->s.pkt_nm.if_mac, ETH_ALEN); + break; +#endif + default: + ODP_ERR("Invalid pktio type: %02x\n", pktio_entry->s.params.type); + return ODP_PKTIO_INVALID; + } + return 0; +} diff --git a/platform/linux-generic/odp_packet_netmap.c b/platform/linux-generic/odp_packet_netmap.c index e2215ab..e9e9f56 100644 --- a/platform/linux-generic/odp_packet_netmap.c +++ b/platform/linux-generic/odp_packet_netmap.c @@ -222,9 +222,11 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, ODP_ERR("Error: token creation failed\n"); return -1; } + if( 0 != socket_store_hw_addr(pkt_nm->if_mac, netdev) + return -1; odp_queue_enq(pkt_nm->tx_access, token); - + ODP_DBG("Wait for link to come up\n"); sleep(WAITLINK_TMO); ODP_DBG("Done\n"); diff --git a/platform/linux-generic/odp_packet_socket.c b/platform/linux-generic/odp_packet_socket.c index d44c333..d96aa8e 100644 --- a/platform/linux-generic/odp_packet_socket.c +++ b/platform/linux-generic/odp_packet_socket.c @@ -735,7 +735,7 @@ static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, const char *netdev) return 0; } -static int mmap_store_hw_addr(pkt_sock_mmap_t * const pkt_sock, +static int socket_store_hw_addr(int sockfd,unsigned char * if_mac, const char *netdev) { struct ifreq ethreq; @@ -744,13 +744,13 @@ static int mmap_store_hw_addr(pkt_sock_mmap_t * const pkt_sock, /* get MAC address */ memset(ðreq, 0, sizeof(ethreq)); strncpy(ethreq.ifr_name, netdev, IFNAMSIZ); - ret = ioctl(pkt_sock->sockfd, SIOCGIFHWADDR, ðreq); + ret = ioctl(sockfd, SIOCGIFHWADDR, ðreq); if (ret != 0) { perror("store_hw_addr() - ioctl(SIOCGIFHWADDR)"); return -1; } - ethaddr_copy(pkt_sock->if_mac, + ethaddr_copy(if_mac, (unsigned char *)ethreq.ifr_ifru.ifru_hwaddr.sa_data); return 0; @@ -805,7 +805,7 @@ int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, const char *netdev, if (ret != 0) return -1; - ret = mmap_store_hw_addr(pkt_sock, netdev); + ret = socket_store_hw_addr(pkt_sock->sockfd, pkt_sock->if_mac, netdev); if (ret != 0) return -1;