From patchwork Tue Apr 30 20:40:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 1093492 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=mellanox.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b="hAxNlB6o"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44tth90dxyz9sCF for ; Wed, 1 May 2019 06:40:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727327AbfD3UkY (ORCPT ); Tue, 30 Apr 2019 16:40:24 -0400 Received: from mail-eopbgr30081.outbound.protection.outlook.com ([40.107.3.81]:37375 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727245AbfD3UkQ (ORCPT ); Tue, 30 Apr 2019 16:40:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5eKhtQhG73/bs7XS8YsiL44ljF/kqN58Aq36Id4RllI=; b=hAxNlB6ojBTu+o38zeEbJDWwQaQDwvFygqRa7iHnP+xn+A05zDMHgdQlu1xm47WXb/+t8yd/r1z05Tl2iXoGNBo+yl7f7+qM7FlCD8e1jQpCczr87Nq/JVswwSsipC3mrdPUOpM8xI0/nhz+oR7sLqSFFttjZx8Za5JCXf4GAtY= Received: from VI1PR05MB5902.eurprd05.prod.outlook.com (20.178.125.223) by VI1PR05MB6542.eurprd05.prod.outlook.com (20.179.27.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1835.15; Tue, 30 Apr 2019 20:40:10 +0000 Received: from VI1PR05MB5902.eurprd05.prod.outlook.com ([fe80::1d74:be4b:cfe9:59a2]) by VI1PR05MB5902.eurprd05.prod.outlook.com ([fe80::1d74:be4b:cfe9:59a2%5]) with mapi id 15.20.1835.018; Tue, 30 Apr 2019 20:40:10 +0000 From: Saeed Mahameed To: "David S. Miller" CC: "netdev@vger.kernel.org" , Bodong Wang , Vu Pham , Parav Pandit , Saeed Mahameed Subject: [net-next 13/15] net/mlx5: E-Switch, Use getter to access all vport array Thread-Topic: [net-next 13/15] net/mlx5: E-Switch, Use getter to access all vport array Thread-Index: AQHU/5TnWxff6GYL6kK1+xeEzWb1Mw== Date: Tue, 30 Apr 2019 20:40:09 +0000 Message-ID: <20190430203926.19284-14-saeedm@mellanox.com> References: <20190430203926.19284-1-saeedm@mellanox.com> In-Reply-To: <20190430203926.19284-1-saeedm@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.20.1 x-originating-ip: [209.116.155.178] x-clientproxiedby: BYAPR02CA0055.namprd02.prod.outlook.com (2603:10b6:a03:54::32) To VI1PR05MB5902.eurprd05.prod.outlook.com (2603:10a6:803:df::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=saeedm@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1d01be1c-19d4-475d-5dc0-08d6cdac0966 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:VI1PR05MB6542; x-ms-traffictypediagnostic: VI1PR05MB6542: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3513; x-forefront-prvs: 00235A1EEF x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(346002)(376002)(396003)(366004)(39860400002)(189003)(199004)(99286004)(25786009)(102836004)(53936002)(36756003)(386003)(478600001)(186003)(6506007)(7736002)(26005)(2616005)(476003)(446003)(52116002)(6436002)(4326008)(305945005)(5660300002)(76176011)(486006)(66066001)(11346002)(14454004)(107886003)(6512007)(6486002)(68736007)(71200400001)(2906002)(6916009)(81166006)(316002)(1076003)(97736004)(81156014)(66446008)(64756008)(66556008)(50226002)(66476007)(66946007)(73956011)(8936002)(54906003)(256004)(8676002)(3846002)(86362001)(14444005)(6116002)(71190400001); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR05MB6542; H:VI1PR05MB5902.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: r8vI20j9GvZRgmPEv8aTMCvwnQxHBHsTror0zww3MCIspfX7fanR3yXJ6mxYRCdbqV8jYSihzWkqeZyGcEJMpqy/S9uq0SWUNulCV7M212I0BTMONiL5a+xZWhaDyGwFR9HhqdRRrLqF+/u8lDQnr5tkdtcvk70FOJTiIPZZir+f7uFPt20f7hZ2H1/I/RepAwNsdQ9NfZHwgDIpLfb1bwx+w8ZWtKUXZJ4WIMiAtoEi6LzpPI4rpw85vURMfyVwB1BOUcvI8BEAADtDUhJUycFDdftYeY+ZlDrtUNXUNPGKfGUYPg0mSQ7uAEWetndRwdvkGKBtXsN8nJCNqm1NxjtNhR48Vwhohz6BVgxMwo5xZ1G8pxR3voQQiZnW0EDY9IcrBwSZuj9BkNklIg+ee6eBGDOLXSf2Fwq+SiQcy7M= MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d01be1c-19d4-475d-5dc0-08d6cdac0966 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Apr 2019 20:40:09.9069 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB6542 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Bodong Wang Some functions issue vport commands and access vport array using vport_index/vport_num interchangeably which is OK for VFs vports. However, this creates potential bug if those vports are not VFs (E.g, uplink, sf) where their vport_index don't equal to vport_num. Prepare code to access mlx5_vport structure using a getter function. Signed-off-by: Bodong Wang Signed-off-by: Vu Pham Reviewed-by: Parav Pandit Signed-off-by: Saeed Mahameed --- .../net/ethernet/mellanox/mlx5/core/eswitch.c | 18 +++++++++--------- .../net/ethernet/mellanox/mlx5/core/eswitch.h | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c index 41afc7bf8bd8..0107ce8bf659 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c @@ -72,8 +72,8 @@ static void esw_cleanup_vepa_rules(struct mlx5_eswitch *esw); MC_ADDR_CHANGE | \ PROMISC_CHANGE) -static struct mlx5_vport *mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, - u16 vport_num) +struct mlx5_vport *mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, + u16 vport_num) { u16 idx = mlx5_eswitch_vport_num_to_index(esw, vport_num); @@ -1916,7 +1916,7 @@ int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw, return -EINVAL; mutex_lock(&esw->state_lock); - evport = &esw->vports[vport]; + evport = mlx5_eswitch_get_vport(esw, vport); if (evport->info.spoofchk && !is_valid_ether_addr(mac)) mlx5_core_warn(esw->dev, @@ -1960,7 +1960,7 @@ int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw, return -EINVAL; mutex_lock(&esw->state_lock); - evport = &esw->vports[vport]; + evport = mlx5_eswitch_get_vport(esw, vport); err = mlx5_modify_vport_admin_state(esw->dev, MLX5_VPORT_STATE_OP_MOD_ESW_VPORT, @@ -1989,7 +1989,7 @@ int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw, if (!LEGAL_VPORT(esw, vport)) return -EINVAL; - evport = &esw->vports[vport]; + evport = mlx5_eswitch_get_vport(esw, vport); memset(ivi, 0, sizeof(*ivi)); ivi->vf = vport - 1; @@ -2020,7 +2020,7 @@ int __mlx5_eswitch_set_vport_vlan(struct mlx5_eswitch *esw, return -EINVAL; mutex_lock(&esw->state_lock); - evport = &esw->vports[vport]; + evport = mlx5_eswitch_get_vport(esw, vport); err = modify_esw_vport_cvlan(esw->dev, vport, vlan, qos, set_flags); if (err) @@ -2064,7 +2064,7 @@ int mlx5_eswitch_set_vport_spoofchk(struct mlx5_eswitch *esw, return -EINVAL; mutex_lock(&esw->state_lock); - evport = &esw->vports[vport]; + evport = mlx5_eswitch_get_vport(esw, vport); pschk = evport->info.spoofchk; evport->info.spoofchk = spoofchk; if (pschk && !is_valid_ether_addr(evport->info.mac)) @@ -2213,7 +2213,7 @@ int mlx5_eswitch_set_vport_trust(struct mlx5_eswitch *esw, return -EINVAL; mutex_lock(&esw->state_lock); - evport = &esw->vports[vport]; + evport = mlx5_eswitch_get_vport(esw, vport); evport->info.trusted = setting; if (evport->enabled) esw_vport_change_handle_locked(evport); @@ -2299,7 +2299,7 @@ int mlx5_eswitch_set_vport_rate(struct mlx5_eswitch *esw, int vport, return -EOPNOTSUPP; mutex_lock(&esw->state_lock); - evport = &esw->vports[vport]; + evport = mlx5_eswitch_get_vport(esw, vport); if (min_rate == evport->info.min_rate) goto set_max_rate; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h index fc512a5d0c4c..2e6b37d4fc7f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h @@ -488,6 +488,8 @@ void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw); #define mlx5_esw_for_each_vf_vport_num_reverse(esw, vport, nvfs) \ for ((vport) = (nvfs); (vport) >= MLX5_VPORT_FIRST_VF; (vport)--) +struct mlx5_vport *mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, + u16 vport_num); #else /* CONFIG_MLX5_ESWITCH */ /* eswitch API stubs */ static inline int mlx5_eswitch_init(struct mlx5_core_dev *dev) { return 0; }