From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0046.outbound.protection.outlook.com [104.47.38.46]) by dpdk.org (Postfix) with ESMTP id CF2AC1B121; Wed, 19 Sep 2018 23:59:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5AeCgIcujCn4PUjS0Kety5sgSiIdV/+VFYA1pk7LVh4=; b=PuIeDQLZo35Kccpq1RZkm7CM9f7N/1myqai1EXdURpXCwzHyppytXdP7rPSMXSz3AuE7rg1LnlpteHJu6qno+lobEEgeTWB/oAnHks9xDf2PF6W4vP6RVXV5iDMZ+ARptyynYrhHaIri62vD5cR51tKu6TBUNKwNTfjwCt63XBA= Received: from BYAPR07MB5365.namprd07.prod.outlook.com (20.177.125.18) by BYAPR07MB5703.namprd07.prod.outlook.com (20.178.0.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.17; Wed, 19 Sep 2018 21:59:44 +0000 Received: from BYAPR07MB5365.namprd07.prod.outlook.com ([fe80::2047:9647:f196:bde0]) by BYAPR07MB5365.namprd07.prod.outlook.com ([fe80::2047:9647:f196:bde0%6]) with mapi id 15.20.1143.017; Wed, 19 Sep 2018 21:59:44 +0000 From: "Mody, Rasesh" To: "dev@dpdk.org" CC: "Mody, Rasesh" , "ferruh.yigit@intel.com" , Dept-Eng DPDK Dev , "stable@dpdk.org" Thread-Topic: [PATCH 5/5] net/bnx2x: fix to add phy lock Thread-Index: AQHUUGQSujsXIoHuvEWj1mRQuTPa8w== Date: Wed, 19 Sep 2018 21:59:44 +0000 Message-ID: <1537394318-17682-5-git-send-email-rasesh.mody@cavium.com> References: <1537394318-17682-1-git-send-email-rasesh.mody@cavium.com> In-Reply-To: <1537394318-17682-1-git-send-email-rasesh.mody@cavium.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR04CA0003.namprd04.prod.outlook.com (2603:10b6:a03:40::16) To BYAPR07MB5365.namprd07.prod.outlook.com (2603:10b6:a03:64::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Rasesh.Mody@cavium.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [198.186.1.5] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; BYAPR07MB5703; 6:1QPyLb5+RF86ol3IT4nLxFwUknQLAsXMryq5hc3vvTK8t/wibQmGdktHuaV1hNE6GrjgJVVFDNqVl+9EMYrwgvFl8qlMjKsJ77EnGrEZlK0jZx7M/QNlEmvpzYUCq21xOeerYld8Grv452loyYdoag1BnRivJW442F4+MaZOUXpFjAAgnaWbAyfeH2oyL5jkYcsFfxmmIcGKZ6jqMKJBqJbYSBJxNATnlR5JEEVx62qRyk2vj1BiWdrm2wP4exjF2F4O7KTD0TNB3+hKT+APuPX5vEO+qTuqYwEiseD3rPxlXp6aVW71Tz2HHDOOWYzu2MyyVryQ//n9TUGFKXz6ljMGMCZP4r7W35VC7eEgS84CpXzZdV3Wqx9M0Rnat0R+lt01qdPW6IuxVgH/zUXBzuI8M6BM0zkpKXG2rIPdYJORhbCvM5++1YpIJv9EhFq4DqJdiwNGg35cILTAlc6w6w==; 5:6j90N4jWtdyDsamIId1YZ5fzH/qWnvkv9M+vDtsZVYY0eTN9y2EWGpRPv1EuFAp9UWV0YDpX1fo3o8JsqO1SXNCI1Ir3ymacL9oMF1WpgOgncIjvb9rLyxLfpcQnZ3HmOWtfBdSFG93kkzfYIir2MTNL8QWC5WulY5RMZop/x+Y=; 7:QaVunDQWyKYpwRJDtEXzKm/KB0u4IetPJwPqa6axPSmExPBDKEvjio+NtFzCDYd1Hu/E0jJ0hZCkVPd1+HbxafLZEBXptN9AMaSK24Fey5UGGI9w2ER0J2/YlP8H+k4velNZ04CwQLjud5/Yv9LhRC/TGobRbHopNDSy9ZRfxI60ajCJyWEmITM6vAnsRqvCPgbQY0F79wg+k5qr766rzujfynmhJyv/dAJUnJpatzK90xyWtLD8q2naaqMUUT5Z x-ms-office365-filtering-correlation-id: 088e19c5-7ef1-46e8-4884-08d61e7b34c1 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:BYAPR07MB5703; x-ms-traffictypediagnostic: BYAPR07MB5703: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823301075)(3231355)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(149027)(150027)(6041310)(20161123564045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(201708071742011)(7699051); SRVR:BYAPR07MB5703; BCL:0; PCL:0; RULEID:; SRVR:BYAPR07MB5703; x-forefront-prvs: 0800C0C167 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(1496009)(346002)(136003)(396003)(376002)(39850400004)(366004)(189003)(199004)(446003)(5660300001)(76176011)(2351001)(6486002)(7736002)(6116002)(6436002)(3846002)(99286004)(54906003)(6916009)(11346002)(476003)(486006)(105586002)(2616005)(478600001)(5640700003)(106356001)(305945005)(6512007)(97736004)(66066001)(52116002)(53936002)(2906002)(256004)(316002)(4326008)(2501003)(102836004)(2900100001)(81156014)(386003)(86362001)(81166006)(5250100002)(26005)(36756003)(8676002)(72206003)(14444005)(68736007)(8936002)(25786009)(1730700003)(14454004)(186003)(6506007); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR07MB5703; H:BYAPR07MB5365.namprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: Ck3/wKZqIGTQcPCOfd59RuK/mmjp6i+Lfcs1aNurqj2zZ1gt8GyaEGN1vCuAiHX2HO2zrBbdYXKtWPhKUyShKakBjUfm1uMNBDJ5WotL//0ok4CKn33MxBhjCq/E9ZPMupwe1a4ColHsl2tDGV3MLBQGJT3MjCWZoQ6oL0NvEKjyTXx+6HSAr8G6poDoF6PpmCWMlQC9aDhbjqwUE51ae9JtLCW6TPjKloQyv5Zx31Y9Dcer4zBT6hI9ZFqa9id4zCky4/+sx0urAs3is9rrVcaReSdI59rDLL9vlnJhXVEeegrS6rpDx9ljEPl9BQXaR+20YX9u4UrpvyUBstUDQxCUgKvBcWwKBVSkxqKvjgw= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-Network-Message-Id: 088e19c5-7ef1-46e8-4884-08d61e7b34c1 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Sep 2018 21:59:44.6185 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR07MB5703 Subject: [dpdk-dev] [PATCH 5/5] net/bnx2x: fix to add phy lock X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Sep 2018 21:59:46 -0000 This patch adds phy_lock, acquire/release the lock when performing PHY transactions. Without this fix driver can run into synchronization issues with management FW when modifying PHY settings. Fixes: 540a211084a7 ("bnx2x: driver core") Cc: stable@dpdk.org Signed-off-by: Rasesh Mody --- drivers/net/bnx2x/bnx2x.c | 59 ++++++++++++++++++++++++++++++++++++-= ---- drivers/net/bnx2x/bnx2x.h | 7 +++++ drivers/net/bnx2x/ecore_reg.h | 1 + 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/drivers/net/bnx2x/bnx2x.c b/drivers/net/bnx2x/bnx2x.c index 0225bea..2797593 100644 --- a/drivers/net/bnx2x/bnx2x.c +++ b/drivers/net/bnx2x/bnx2x.c @@ -112,6 +112,7 @@ static uint8_t bnx2x_chk_parity_attn(struct bnx2x_softc= *sc, uint8_t * global, static void bnx2x_update_rx_prod(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp, uint16_t rx_bd_prod, uint16_t rx_cq_prod); +static void bnx2x_link_report_locked(struct bnx2x_softc *sc); static void bnx2x_link_report(struct bnx2x_softc *sc); void bnx2x_link_status_update(struct bnx2x_softc *sc); static int bnx2x_alloc_mem(struct bnx2x_softc *sc); @@ -198,7 +199,8 @@ static int bnx2x_acquire_hw_lock(struct bnx2x_softc *sc= , uint32_t resource) uint32_t hw_lock_control_reg; int cnt; =20 - PMD_INIT_FUNC_TRACE(sc); + if (resource) + PMD_INIT_FUNC_TRACE(sc); =20 /* validate the resource is within range */ if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { @@ -234,7 +236,8 @@ static int bnx2x_acquire_hw_lock(struct bnx2x_softc *sc= , uint32_t resource) DELAY(5000); } =20 - PMD_DRV_LOG(NOTICE, sc, "Resource lock timeout!"); + PMD_DRV_LOG(NOTICE, sc, "Resource 0x%x resource_bit 0x%x lock timeout!", + resource, resource_bit); return -1; } =20 @@ -245,13 +248,14 @@ static int bnx2x_release_hw_lock(struct bnx2x_softc *= sc, uint32_t resource) int func =3D SC_FUNC(sc); uint32_t hw_lock_control_reg; =20 - PMD_INIT_FUNC_TRACE(sc); + if (resource) + PMD_INIT_FUNC_TRACE(sc); =20 /* validate the resource is within range */ if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { PMD_DRV_LOG(NOTICE, sc, - "resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE", - resource); + "(resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE)" + " resource_bit 0x%x", resource, resource_bit); return -1; } =20 @@ -275,6 +279,18 @@ static int bnx2x_release_hw_lock(struct bnx2x_softc *s= c, uint32_t resource) return 0; } =20 +static void bnx2x_acquire_phy_lock(struct bnx2x_softc *sc) +{ + BNX2X_PHY_LOCK(sc); + bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_MDIO); +} + +static void bnx2x_release_phy_lock(struct bnx2x_softc *sc) +{ + bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_MDIO); + BNX2X_PHY_UNLOCK(sc); +} + /* copy command into DMAE command memory and set DMAE command Go */ void bnx2x_post_dmae(struct bnx2x_softc *sc, struct dmae_command *dmae, in= t idx) { @@ -2903,7 +2919,7 @@ static void bnx2x_link_attn(struct bnx2x_softc *sc) } } =20 - bnx2x_link_report(sc); + bnx2x_link_report_locked(sc); =20 if (IS_MF(sc)) { bnx2x_link_sync_notify(sc); @@ -2942,6 +2958,7 @@ static void bnx2x_attn_int_asserted(struct bnx2x_soft= c *sc, uint32_t asserted) if (asserted & ATTN_HARD_WIRED_MASK) { if (asserted & ATTN_NIG_FOR_FUNC) { =20 + bnx2x_acquire_phy_lock(sc); /* save nig interrupt mask */ nig_mask =3D REG_RD(sc, nig_int_mask_addr); =20 @@ -3039,6 +3056,7 @@ static void bnx2x_attn_int_asserted(struct bnx2x_soft= c *sc, uint32_t asserted) =20 REG_WR(sc, nig_int_mask_addr, nig_mask); =20 + bnx2x_release_phy_lock(sc); } } =20 @@ -3838,8 +3856,10 @@ static void bnx2x_attn_int_deasserted3(struct bnx2x_= softc *sc, uint32_t attn) if (sc->link_vars.periodic_flags & ELINK_PERIODIC_FLAGS_LINK_EVENT) { /* sync with link */ + bnx2x_acquire_phy_lock(sc); sc->link_vars.periodic_flags &=3D ~ELINK_PERIODIC_FLAGS_LINK_EVENT; + bnx2x_release_phy_lock(sc); if (IS_MF(sc)) { bnx2x_link_sync_notify(sc); } @@ -4029,7 +4049,9 @@ static void bnx2x_attn_int_deasserted0(struct bnx2x_s= oftc *sc, uint32_t attn) } =20 if ((attn & sc->link_vars.aeu_int_mask) && sc->port.pmf) { + bnx2x_acquire_phy_lock(sc); elink_handle_module_detect_int(&sc->link_params); + bnx2x_release_phy_lock(sc); } =20 if (attn & HW_INTERRUT_ASSERT_SET_0) { @@ -6867,7 +6889,7 @@ static uint16_t bnx2x_get_mf_speed(struct bnx2x_softc= *sc) } =20 /* report link status to OS, should be called under phy_lock */ -static void bnx2x_link_report(struct bnx2x_softc *sc) +static void bnx2x_link_report_locked(struct bnx2x_softc *sc) { struct bnx2x_link_report_data cur_data; =20 @@ -6888,8 +6910,13 @@ static void bnx2x_link_report(struct bnx2x_softc *sc= ) return; } =20 + PMD_DRV_LOG(INFO, sc, "Change in link status : cur_data =3D %lx, last_rep= orted_link =3D %lx\n", + cur_data.link_report_flags, + sc->last_reported_link.link_report_flags); + sc->link_cnt++; =20 + PMD_DRV_LOG(INFO, sc, "link status change count =3D %x\n", sc->link_cnt); /* report new link params and remember the state for the next time */ rte_memcpy(&sc->last_reported_link, &cur_data, sizeof(cur_data)); =20 @@ -6941,6 +6968,14 @@ static void bnx2x_link_report(struct bnx2x_softc *sc= ) } } =20 +static void +bnx2x_link_report(struct bnx2x_softc *sc) +{ + bnx2x_acquire_phy_lock(sc); + bnx2x_link_report_locked(sc); + bnx2x_release_phy_lock(sc); +} + void bnx2x_link_status_update(struct bnx2x_softc *sc) { if (sc->state !=3D BNX2X_STATE_OPEN) { @@ -7019,6 +7054,8 @@ static int bnx2x_initial_phy_init(struct bnx2x_softc = *sc, int load_mode) =20 bnx2x_set_requested_fc(sc); =20 + bnx2x_acquire_phy_lock(sc); + if (load_mode =3D=3D LOAD_DIAG) { lp->loopback_mode =3D ELINK_LOOPBACK_XGXS; /* Prefer doing PHY loopback at 10G speed, if possible */ @@ -7038,6 +7075,8 @@ static int bnx2x_initial_phy_init(struct bnx2x_softc = *sc, int load_mode) =20 rc =3D elink_phy_init(&sc->link_params, &sc->link_vars); =20 + bnx2x_release_phy_lock(sc); + bnx2x_calc_fc_adv(sc); =20 if (sc->link_vars.link_up) { @@ -7088,7 +7127,9 @@ void bnx2x_periodic_callout(struct bnx2x_softc *sc) */ mb(); if (sc->port.pmf) { + bnx2x_acquire_phy_lock(sc); elink_period_func(&sc->link_params, &sc->link_vars); + bnx2x_release_phy_lock(sc); } } #ifdef BNX2X_PULSE @@ -9840,8 +9881,10 @@ static void bnx2x_common_init_phy(struct bnx2x_softc= *sc) shmem2_base[1] =3D SHMEM2_RD(sc, other_shmem2_base_addr); } =20 + bnx2x_acquire_phy_lock(sc); elink_common_init_phy(sc, shmem_base, shmem2_base, sc->devinfo.chip_id, 0); + bnx2x_release_phy_lock(sc); } =20 static void bnx2x_pf_disable(struct bnx2x_softc *sc) @@ -11320,7 +11363,9 @@ static int bnx2x_init_hw_func(struct bnx2x_softc *s= c) static void bnx2x_link_reset(struct bnx2x_softc *sc) { if (!BNX2X_NOMCP(sc)) { + bnx2x_acquire_phy_lock(sc); elink_lfa_reset(&sc->link_params, &sc->link_vars); + bnx2x_release_phy_lock(sc); } else { if (!CHIP_REV_IS_SLOW(sc)) { PMD_DRV_LOG(WARNING, sc, diff --git a/drivers/net/bnx2x/bnx2x.h b/drivers/net/bnx2x/bnx2x.h index 1cc5a6b..7478072 100644 --- a/drivers/net/bnx2x/bnx2x.h +++ b/drivers/net/bnx2x/bnx2x.h @@ -725,6 +725,13 @@ struct bnx2x_port { =20 uint32_t phy_addr; =20 + /* Used to synchronize phy accesses. */ + rte_spinlock_t phy_mtx; + char phy_mtx_name[32]; + +#define BNX2X_PHY_LOCK(sc) rte_spinlock_lock(&sc->port.phy_mtx) +#define BNX2X_PHY_UNLOCK(sc) rte_spinlock_unlock(&sc->port.phy_mtx) + /* * MCP scratchpad address for port specific statistics. * The device is responsible for writing statistcss diff --git a/drivers/net/bnx2x/ecore_reg.h b/drivers/net/bnx2x/ecore_reg.h index ae8a93b..d69e857 100644 --- a/drivers/net/bnx2x/ecore_reg.h +++ b/drivers/net/bnx2x/ecore_reg.h @@ -1967,6 +1967,7 @@ #define HW_LOCK_MAX_RESOURCE_VALUE 31 #define HW_LOCK_RESOURCE_DRV_FLAGS 10 #define HW_LOCK_RESOURCE_GPIO 1 +#define HW_LOCK_RESOURCE_MDIO 0 #define HW_LOCK_RESOURCE_NVRAM 12 #define HW_LOCK_RESOURCE_PORT0_ATT_MASK 3 #define HW_LOCK_RESOURCE_RECOVERY_LEADER_0 8 --=20 1.7.10.3