From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 975ACE72 for ; Tue, 9 Jun 2015 18:19:02 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP; 09 Jun 2015 08:52:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,581,1427785200"; d="scan'208";a="707992529" Received: from kmsmsx151.gar.corp.intel.com ([172.21.73.86]) by orsmga001.jf.intel.com with ESMTP; 09 Jun 2015 08:52:16 -0700 Received: from kmsmsx154.gar.corp.intel.com (172.21.73.14) by KMSMSX151.gar.corp.intel.com (172.21.73.86) with Microsoft SMTP Server (TLS) id 14.3.224.2; Tue, 9 Jun 2015 23:51:45 +0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by KMSMSX154.gar.corp.intel.com (172.21.73.14) with Microsoft SMTP Server (TLS) id 14.3.224.2; Tue, 9 Jun 2015 23:51:45 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.246]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.146]) with mapi id 14.03.0224.002; Tue, 9 Jun 2015 23:51:41 +0800 From: "Qiu, Michael" To: "He, Shaopeng" , "dev@dpdk.org" Thread-Topic: [PATCH 1/3] fm10k: update VLAN filter Thread-Index: AQHQnOAmXaXgmBv0PE2Jrtyhb10Apw== Date: Tue, 9 Jun 2015 15:51:41 +0000 Message-ID: <533710CFB86FA344BFBF2D6802E60286046959E4@SHSMSX101.ccr.corp.intel.com> References: <1433213937-21690-1-git-send-email-shaopeng.he@intel.com> <1433213937-21690-2-git-send-email-shaopeng.he@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH 1/3] fm10k: update VLAN filter 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: Tue, 09 Jun 2015 16:19:03 -0000 On 2015/6/2 10:59, He, Shaopeng wrote:=0A= > VLAN filter was updated to add/delete one static entry in MAC table for e= ach=0A= > combination of VLAN and MAC address. More sanity checks were added.=0A= >=0A= > Signed-off-by: Shaopeng He =0A= > ---=0A= > drivers/net/fm10k/fm10k.h | 23 +++++++++++++++++=0A= > drivers/net/fm10k/fm10k_ethdev.c | 55 ++++++++++++++++++++++++++++++++++= +++---=0A= > 2 files changed, 75 insertions(+), 3 deletions(-)=0A= >=0A= > diff --git a/drivers/net/fm10k/fm10k.h b/drivers/net/fm10k/fm10k.h=0A= > index ad7a7d1..3b95b72 100644=0A= > --- a/drivers/net/fm10k/fm10k.h=0A= > +++ b/drivers/net/fm10k/fm10k.h=0A= > @@ -109,11 +109,31 @@=0A= > =0A= > #define FM10K_VLAN_TAG_SIZE 4=0A= > =0A= > +/* Maximum number of MAC addresses per PF/VF */=0A= > +#define FM10K_MAX_MACADDR_NUM 1=0A= > +=0A= > +#define FM10K_UINT32_BIT_SIZE (CHAR_BIT * sizeof(uint32_t))=0A= > +#define FM10K_VFTA_SIZE (4096 / FM10K_UINT32_BIT_SIZE)=0A= > +=0A= > +/* vlan_id is a 12 bit number.=0A= > + * The VFTA array is actually a 4096 bit array, 128 of 32bit elements.= =0A= > + * 2^5 =3D 32. The val of lower 5 bits specifies the bit in the 32bit el= ement.=0A= > + * The higher 7 bit val specifies VFTA array index.=0A= > + */=0A= > +#define FM10K_VFTA_BIT(vlan_id) (1 << ((vlan_id) & 0x1F))=0A= > +#define FM10K_VFTA_IDX(vlan_id) ((vlan_id) >> 5)=0A= > +=0A= > +struct fm10k_macvlan_filter_info {=0A= > + uint16_t vlan_num; /* Total VLAN number */=0A= > + uint32_t vfta[FM10K_VFTA_SIZE]; /* VLAN bitmap */=0A= > +};=0A= > +=0A= > struct fm10k_dev_info {=0A= > volatile uint32_t enable;=0A= > volatile uint32_t glort;=0A= > /* Protect the mailbox to avoid race condition */=0A= > rte_spinlock_t mbx_lock;=0A= > + struct fm10k_macvlan_filter_info macvlan;=0A= > };=0A= > =0A= > /*=0A= > @@ -137,6 +157,9 @@ struct fm10k_adapter {=0A= > #define FM10K_DEV_PRIVATE_TO_MBXLOCK(adapter) \=0A= > (&(((struct fm10k_adapter *)adapter)->info.mbx_lock))=0A= > =0A= > +#define FM10K_DEV_PRIVATE_TO_MACVLAN(adapter) \=0A= > + (&(((struct fm10k_adapter *)adapter)->info.macvlan))=0A= > +=0A= > struct fm10k_rx_queue {=0A= > struct rte_mempool *mp;=0A= > struct rte_mbuf **sw_ring;=0A= > diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_e= thdev.c=0A= > index 3a26480..d2f3e44 100644=0A= > --- a/drivers/net/fm10k/fm10k_ethdev.c=0A= > +++ b/drivers/net/fm10k/fm10k_ethdev.c=0A= > @@ -819,15 +819,61 @@ fm10k_dev_infos_get(struct rte_eth_dev *dev,=0A= > static int=0A= > fm10k_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)= =0A= > {=0A= > - struct fm10k_hw *hw =3D FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private)= ;=0A= > + s32 result;=0A= > + uint32_t vid_idx, vid_bit, mac_index;=0A= > + struct fm10k_hw *hw;=0A= > + struct fm10k_macvlan_filter_info *macvlan;=0A= > + struct rte_eth_dev_data *data =3D dev->data;=0A= > =0A= > - PMD_INIT_FUNC_TRACE();=0A= > + hw =3D FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);=0A= > + macvlan =3D FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);=0A= > =0A= > /* @todo - add support for the VF */=0A= > if (hw->mac.type !=3D fm10k_mac_pf)=0A= > return -ENOTSUP;=0A= > =0A= > - return fm10k_update_vlan(hw, vlan_id, 0, on);=0A= > + if (vlan_id > ETH_VLAN_ID_MAX) {=0A= > + PMD_INIT_LOG(ERR, "Invalid vlan_id: must be < 4096");=0A= > + return (-EINVAL);=0A= > + }=0A= > +=0A= > + vid_idx =3D FM10K_VFTA_IDX(vlan_id);=0A= > + vid_bit =3D FM10K_VFTA_BIT(vlan_id);=0A= > + /* this VLAN ID is already in the VLAN filter table, return SUCCESS */= =0A= > + if (on && (macvlan->vfta[vid_idx] & vid_bit))=0A= > + return 0;=0A= > + /* this VLAN ID is NOT in the VLAN filter table, cannot remove */=0A= > + if (!on && !(macvlan->vfta[vid_idx] & vid_bit)) {=0A= > + PMD_INIT_LOG(ERR, "Invalid vlan_id: not existing "=0A= > + "in the VLAN filter table");=0A= > + return (-EINVAL);=0A= > + }=0A= > +=0A= > + fm10k_mbx_lock(hw);=0A= > + result =3D fm10k_update_vlan(hw, vlan_id, 0, on);=0A= =0A= Would it make sense about release the lock here? So that to make sure we=0A= do not hold this lock for a long time.=0A= =0A= =0A= > + if (FM10K_SUCCESS =3D=3D result) {=0A= > + if (on) {=0A= > + macvlan->vlan_num++;=0A= > + macvlan->vfta[vid_idx] |=3D vid_bit;=0A= > + } else {=0A= > + macvlan->vlan_num--;=0A= > + macvlan->vfta[vid_idx] &=3D ~vid_bit;=0A= > + }=0A= > +=0A= > + for (mac_index =3D 0; mac_index < FM10K_MAX_MACADDR_NUM;=0A= > + mac_index++) {=0A= > + if (is_zero_ether_addr(&data->mac_addrs[mac_index]))=0A= > + continue;=0A= > + fm10k_update_uc_addr(hw, hw->mac.dglort_map,=0A= > + data->mac_addrs[mac_index].addr_bytes,=0A= > + vlan_id, on, 0);=0A= > + }=0A= > + }=0A= > + fm10k_mbx_unlock(hw);=0A= > + if (FM10K_SUCCESS =3D=3D result)=0A= > + return 0;=0A= > + else=0A= > + return (-EIO);=0A= > }=0A= > =0A= > static inline int=0A= > @@ -1701,6 +1747,7 @@ eth_fm10k_dev_init(struct rte_eth_dev *dev)=0A= > {=0A= > struct fm10k_hw *hw =3D FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private)= ;=0A= > int diag;=0A= > + struct fm10k_macvlan_filter_info *macvlan;=0A= > =0A= > PMD_INIT_FUNC_TRACE();=0A= > =0A= > @@ -1715,6 +1762,8 @@ eth_fm10k_dev_init(struct rte_eth_dev *dev)=0A= > if (rte_eal_process_type() !=3D RTE_PROC_PRIMARY)=0A= > return 0;=0A= > =0A= > + macvlan =3D FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);=0A= > + memset(macvlan, 0, sizeof(*macvlan));=0A= > /* Vendor and Device ID need to be set before init of shared code */=0A= > memset(hw, 0, sizeof(*hw));=0A= > hw->device_id =3D dev->pci_dev->id.device_id;=0A= =0A=