From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by dpdk.org (Postfix) with ESMTP id E6C80594F for ; Wed, 21 May 2014 17:23:53 +0200 (CEST) Received: by mail-wi0-f172.google.com with SMTP id hi2so7847073wib.17 for ; Wed, 21 May 2014 08:24:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type; bh=tfn3dmzFSl/Nf7Zp0XOnQY5sdxRCg7VY9DvOkxiJ+rI=; b=Ddr112ptLGg6aOWmotojDadZiJd7tSwII8BgA4Jkio29n7dnvXQkscqDPml66mnsPX oJTD2e+9Dzxu4iMWnCEFIBo+arqIO7GP+nhwDzR2Tfkb88wIMEspLi9d+Z088MUgYVYj QVxO1orLYxLLAoS7DUwWTa8tOViwjA69Teu0oUseRuRXFtQ2Hh9P+bEwglWMyKFd4ENr qDA+VAKfQZEXE2R94FBfVHIlUOEdIZeDJOSCjqovlo+nPJKNOswdEA0JtXT98vFkJYtm A13+oBWid3QeHnsZITnCpSbhBleLV27pxalQH1tlpYWLHK7bzN0QS/Nlm0+YpF1Bwkmu 44GA== X-Gm-Message-State: ALoCoQna+HHX6fQE3NoWIObEN8gBUJx+w1ENxdBceeMJYM8Qc05Q87lW5LEjYxeYRnMGKOZK/Frv X-Received: by 10.180.218.163 with SMTP id ph3mr10985748wic.54.1400685843294; Wed, 21 May 2014 08:24:03 -0700 (PDT) Received: from [10.16.0.189] (6wind.net2.nerim.net. [213.41.180.237]) by mx.google.com with ESMTPSA id s3sm22951583wje.36.2014.05.21.08.24.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 21 May 2014 08:24:02 -0700 (PDT) Message-ID: <537CC510.6070202@6wind.com> Date: Wed, 21 May 2014 17:24:00 +0200 From: Ivan Boule User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.5.0 MIME-Version: 1.0 To: Stephen Hemminger References: <20140514185527.771828962@networkplumber.org> <20140514185750.257523699@networkplumber.org> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] [PATCH 5/6] ether: allow setting 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: Wed, 21 May 2014 15:23:54 -0000 Hi Stephen, Looking more precisely to your patch, I think that your requirement can beaddressed without adding a new `mac_addr_set` function into the [already overloaded] set of operations exported by a PMD. In fact, changing the default MAC address used by a port consists in executingthe following sequence of operations: 1- rte_eth_macaddr_get(port_id, &cur_mac_addr) to obtain the default MACaddress currently used by the port, 2- rte_eth_dev_mac_addr_remove(port_id, &cur_mac_addr) to remove thedefault MAC address currently used by the port, 3- rte_eth_dev_mac_addr_add(port_id, &new_mac_addr) to add the new defaultMAC address to be used by the port. This method takes advantage of the fact that the allocation of a freeentry into the array `data->mac_addrs` that contains the MAC addresses of a port searches the pool from the entry at index 0, which contains the default MAC address. This implementation simply needs to be mandatory from now. The actual implementation might look like this. Add the prototype of the function `rte_eth_dev_macaddr_set` in the file`rte_ethdev.h`: extern int rte_eth_dev_macaddr_set((uint8_t port_id, struct ether_addr *addr); And add the following generic implementation of the function `rte_eth_dev_macaddr_set`in the file `rte_ethdev.c`: int rte_eth_dev_macaddr_set(uint8_t port_id, struct ether_addr *addr) { struct rte_eth_dev *dev; struct ether_addr cur_addr; int diag; if (port_id >= nb_ports) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } if (is_zero_ether_addr(addr)) { PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n", port_id); return (-EINVAL); } dev = &rte_eth_devices[port_id]; /* * Check that both mac_addr_remove and mac_addr_add operations are * supported by the PMD of the port. */ FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP); FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP); rte_eth_macaddr_get(port_id, &cur_addr); diag = rte_eth_dev_mac_addr_remove(port_id, &cur_addr); if (diag < 0) return diag; return rte_eth_dev_mac_addr_add(port_id, addr); } Regards, Ivan On 05/15/2014 11:04 AM, Ivan Boule wrote: > Hi Stephen, > > By default, changing the [current] default MAC address of a device is > not equivalent to adding a MAC address to it ! At least, the minimum > to do should consist in: > 1. checking that the PMD exports both mac_addr_remove() > and mac_addr_add() functions, returning a NON_SUPPORTED error code > otherwise, > 2. removing the current default MAC address by invoking the PMD's > mac_addr_remove() function, > 3. adding the new MAC address by invoking the PMD's mac_addr_add() > function. > > Regards, > Ivan > > 2014-05-14 20:55 GMT+02:00 Stephen Hemminger > >: > > Allow setting the default Ethernet address used on device. > The underlying drivers allow it but the DPDK was blocking any > attempts to change Ethernet address on device. > > For most devices, this is just the same as filling in address > in mac address table entry 0, but for some devices this requires > special override. > > Signed-off-by: Stephen Hemminger > > > > --- a/lib/librte_ether/rte_ethdev.h 2014-05-14 > 11:44:27.373014227 -0700 > +++ b/lib/librte_ether/rte_ethdev.h 2014-05-14 > 11:44:27.373014227 -0700 > @@ -982,6 +982,11 @@ typedef void (*eth_mac_addr_add_t)(struc > struct ether_addr *mac_addr, > uint32_t index, > uint32_t vmdq); > +/**< @internal Change default MAC address */ > + > +typedef void (*eth_mac_addr_set_t)(struct rte_eth_dev *dev, > + struct ether_addr *mac_addr); > + > /**< @internal Set a MAC address into Receive Address Address > Register */ > > typedef int (*eth_uc_hash_table_set_t)(struct rte_eth_dev *dev, > @@ -1114,6 +1119,7 @@ struct eth_dev_ops { > priority_flow_ctrl_set_t priority_flow_ctrl_set; /**< > Setup priority flow control.*/ > eth_mac_addr_remove_t mac_addr_remove; /**< Remove > MAC address */ > eth_mac_addr_add_t mac_addr_add; /**< Add a MAC > address */ > + eth_mac_addr_set_t mac_addr_set; /**< Change > default MAC address */ > eth_uc_hash_table_set_t uc_hash_table_set; /**< Set > Unicast Table Array */ > eth_uc_all_hash_table_set_t uc_all_hash_table_set; /**< > Set Unicast hash bitmap */ > eth_mirror_rule_set_t mirror_rule_set; /**< Add a > traffic mirror rule.*/ > @@ -2538,6 +2544,21 @@ int rte_eth_dev_mac_addr_add(uint8_t por > int rte_eth_dev_mac_addr_remove(uint8_t port, struct ether_addr > *mac_addr); > > /** > + * Change the default MAC address > + * > + * @param port > + * The port identifier of the Ethernet device. > + * @param mac_addr > + * MAC address to remove. > + * @return > + * - (0) if successfully added or *mac_addr" was already added. > + * - (-ENOTSUP) if hardware doesn't support this feature. > + * - (-ENODEV) if *port* is invalid. > + * - (-EINVAL) if MAC address is invalid. > + */ > +int rte_eth_dev_macaddr_set(uint8_t port, struct ether_addr > *mac_addr); > + > +/** > * Update Redirection Table(RETA) of Receive Side Scaling of > Ethernet device. > * > * @param port > --- a/lib/librte_ether/rte_ethdev.c 2014-05-14 > 11:44:27.373014227 -0700 > +++ b/lib/librte_ether/rte_ethdev.c 2014-05-14 > 11:44:27.373014227 -0700 > @@ -1059,6 +1059,33 @@ rte_eth_macaddr_get(uint8_t port_id, str > } > > int > +rte_eth_dev_macaddr_set(uint8_t port_id, struct ether_addr *addr) > +{ > + struct rte_eth_dev *dev; > + > + if (port_id >= nb_ports) { > + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); > + return (-ENODEV); > + } > + if (is_zero_ether_addr(addr)) { > + PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC > address\n", port_id); > + return (-EINVAL); > + } > + dev = &rte_eth_devices[port_id]; > + > + if (*dev->dev_ops->mac_addr_set) > + (*dev->dev_ops->mac_addr_set)(dev, addr); > + else { > + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP); > + (*dev->dev_ops->mac_addr_add)(dev, addr, 0, 0); > + } > + > + ether_addr_copy(addr, &dev->data->mac_addrs[0]); > + > + return 0; > +} > + > +int > rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on) > { > struct rte_eth_dev *dev; > > > > -- > Ivan BOULE > 6WIND > Software Engineer > -- Ivan Boule 6WIND Development Engineer