From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wg0-f43.google.com (mail-wg0-f43.google.com [74.125.82.43]) by dpdk.org (Postfix) with ESMTP id 7A238C424 for ; Sat, 6 Jun 2015 01:16:32 +0200 (CEST) Received: by wgv5 with SMTP id 5so66809153wgv.1 for ; Fri, 05 Jun 2015 16:16:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DPK4vYPf1N6O8x31U2R3X6rP9gzBZBQB3DKCYhoNTkE=; b=cIr1lj3rzW3dHLr9YwtMz2IIA7x5/l6PyeAlJab4qubLESbpimxmRjLwx9w+XKiF5N OLeNwjASPg0fEOd2+HoNNBFECPXSCIRfVObdbwSMMDIZ6tL3cWZiGvmzfANLQ3CZDuhO lZKxXEWNm/cD85+fy+PsiR8ZTdkrRZRD8+82fKktvc/Q0YhwtqYM04Ruxqv2rI9Vio4a hhswEFUR07mUwC/3wLdqECQI6WrtMj444y5/f2ThLEgmu+z5A5bAu+snmUvRjLQc510m c6foWPEiMgH2KdT2tu7mx4dIyO2Cmjvk8NDg4IOC5E+EQREqirAGZVnw9LHLP5x+4n2S msKQ== X-Gm-Message-State: ALoCoQlOVWbov72UillzLNO+GxUbyvfQkA1yy/mBt/dghNv/CZ8MxRaMEOYi0/3Q+rbo6niL+Dju X-Received: by 10.194.248.227 with SMTP id yp3mr10308187wjc.32.1433546192365; Fri, 05 Jun 2015 16:16:32 -0700 (PDT) Received: from 6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by mx.google.com with ESMTPSA id fa8sm5297304wib.14.2015.06.05.16.16.30 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 05 Jun 2015 16:16:31 -0700 (PDT) From: Adrien Mazarguil To: dev@dpdk.org Date: Sat, 6 Jun 2015 01:15:20 +0200 Message-Id: <1433546120-2254-17-git-send-email-adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1433546120-2254-1-git-send-email-adrien.mazarguil@6wind.com> References: <1433546120-2254-1-git-send-email-adrien.mazarguil@6wind.com> Subject: [dpdk-dev] [PATCH 16/16] mlx4: query netdevice to get initial MAC address X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jun 2015 23:16:32 -0000 From: Or Ami Querying the netdevice instead of deriving the port's MAC address from its GID is less prone to errors. There is no guarantee that the GID will always contain it nor that the algorithm won't change. Signed-off-by: Or Ami Signed-off-by: Olga Shern Signed-off-by: Adrien Mazarguil --- drivers/net/mlx4/mlx4.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index 4c4f693..04cc5e1 100644 --- a/drivers/net/mlx4/mlx4.c +++ b/drivers/net/mlx4/mlx4.c @@ -4427,22 +4427,25 @@ mlx4_ibv_device_to_pci_addr(const struct ibv_device *device, } /** - * Derive MAC address from port GID. + * Get MAC address by querying netdevice. * + * @param[in] priv + * struct priv for the requested device. * @param[out] mac * MAC address output buffer. - * @param port - * Physical port number. - * @param[in] gid - * Port GID. + * + * @return + * 0 on success, -1 on failure and errno is set. */ -static void -mac_from_gid(uint8_t (*mac)[ETHER_ADDR_LEN], uint32_t port, uint8_t *gid) +static int +priv_get_mac(struct priv *priv, uint8_t (*mac)[ETHER_ADDR_LEN]) { - memcpy(&(*mac)[0], gid + 8, 3); - memcpy(&(*mac)[3], gid + 13, 3); - if (port == 1) - (*mac)[0] ^= 2; + struct ifreq request; + + if (priv_ifreq(priv, SIOCGIFHWADDR, &request)) + return -1; + memcpy(mac, request.ifr_hwaddr.sa_data, ETHER_ADDR_LEN); + return 0; } /* Support up to 32 adapters. */ @@ -4604,7 +4607,6 @@ mlx4_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) struct ibv_exp_device_attr exp_device_attr; #endif /* HAVE_EXP_QUERY_DEVICE */ struct ether_addr mac; - union ibv_gid temp_gid; #ifdef HAVE_EXP_QUERY_DEVICE exp_device_attr.comp_mask = IBV_EXP_DEVICE_ATTR_EXP_CAP_FLAGS; @@ -4729,12 +4731,12 @@ mlx4_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) (void)mlx4_getenv_int; priv->vf = vf; - if (ibv_query_gid(ctx, port, 0, &temp_gid)) { - ERROR("ibv_query_gid() failure"); + /* Configure the first MAC address by default. */ + if (priv_get_mac(priv, &mac.addr_bytes)) { + ERROR("cannot get MAC address, is mlx4_en loaded?" + " (errno: %s)", strerror(errno)); goto port_error; } - /* Configure the first MAC address by default. */ - mac_from_gid(&mac.addr_bytes, port, temp_gid.raw); INFO("port %u MAC address is %02x:%02x:%02x:%02x:%02x:%02x", priv->port, mac.addr_bytes[0], mac.addr_bytes[1], -- 2.1.0