From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B174541E9F for ; Wed, 15 Mar 2023 14:41:01 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AB31640A7A; Wed, 15 Mar 2023 14:41:01 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mails.dpdk.org (Postfix) with ESMTP id 8406E40141; Wed, 15 Mar 2023 14:40:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678887659; x=1710423659; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=r2Uf1DOtJp8dRIlzOAEOx4vL3rOVpEIJiTe+A6GFQJA=; b=YFRHhYdFkhMhqJ7dj8wBTM0EdtrtVqW6TmDS76MjGAsofgABs79Rer2b AWThWfBuuvEnGIsQAqtIlIr9SdfvSa2Br7lc2LpqPL6aCTeftNHyzbV83 efTI7/FOYCRA/DjZa89E1eZT0LhZk9O/rYVlz72iQ2eUzEobfd+CZPmMU pz3iFgmIssxKKsBXXtPrBCWrjjmW0j0fRUDMe7ZiHsWJLQ+HMSBpurwhE OlNfgqYoURxCG0Nfh8mckr9rmjAtu2m0eFx2+xSfZvoHz59xQMXZbFJbz M6u12I6h1oeIkxMyhVMYGhSEcDtc4ELIDOGX7QrxyAlctW3ecDHbry4FI g==; X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="335192674" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="335192674" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 06:40:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="656763869" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="656763869" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orsmga006.jf.intel.com with ESMTP; 15 Mar 2023 06:40:58 -0700 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Wed, 15 Mar 2023 06:40:57 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Wed, 15 Mar 2023 06:40:57 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21 via Frontend Transport; Wed, 15 Mar 2023 06:40:57 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.169) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.21; Wed, 15 Mar 2023 06:40:57 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OC60dXz1dKot5eqI7cDdNq2chIZQXsmONs3C7zdPpWSHjmbtOE2fbuB9q0zwAuSuyZAbIDpamda05fW7Bs3ohsW8vvueePWrr7An+8TawHOanWzYIEobdk2eu20cK75tntjKeDPJpEbstUIW6RWQDpSsKLTWg85/nO1PkRmfEziMvQVAoM6RHIReUxBOySDF7O9sPtXWP0PF3Ug/KaW6I7R5DClyN0mzq/+B6bfwFs2Q2RJTDOdHdGzsWcVFed1G369fLbfgESDx7cb+J5DkfJ7fD8eWYRlGcrdYmAbl+aB9JuVQTvCpvm/4c5A+XVHmQYvxWwCHIZate7w8WL0l7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/iTpeNIaJHlxN7qcA814PDL6hPLxmqQlE38n/qv2sTI=; b=IwGVgBIg1vDSUhxPgp5ElBTl86PQs/eVz7EvBbSrfZcTXAbP2zImIvTSca2woJ1k7pE/N4a8BaLKURdzFjyCla23YwWTSayaGgDWzcJ037OhA6mAVsGpXOEBd3FlKn8xsyv+QAu2IfRJ2ngkueQaV/Oz25Y03gqA5QPyku4za/cqYPldXakyEmKyHgoDC1ZMSy0KG/5UHo9/aAWKsyeV+CLP8+n+4qsI44DCwDGSr/fJQrIGZ0zM3mrM1feJlRZFcm/p6l+p8Mwd9LXMpDP64FDHtaOyWAjw1ycP+EyuNaQ1rBJ/W/Vf+yFW6MfR7tE2Y+bx7aE1FNoAKGnfCdInIQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from DM4PR11MB5994.namprd11.prod.outlook.com (2603:10b6:8:5d::20) by SN7PR11MB6994.namprd11.prod.outlook.com (2603:10b6:806:2ad::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.26; Wed, 15 Mar 2023 13:40:55 +0000 Received: from DM4PR11MB5994.namprd11.prod.outlook.com ([fe80::2c5d:49cd:a9b4:f764]) by DM4PR11MB5994.namprd11.prod.outlook.com ([fe80::2c5d:49cd:a9b4:f764%8]) with mapi id 15.20.6178.029; Wed, 15 Mar 2023 13:40:55 +0000 From: "Zhang, Qi Z" To: "Deng, KaiwenX" , "dev@dpdk.org" CC: "stable@dpdk.org" , "Yang, Qiming" , "Zhou, YidingX" , "Wu, Jingjing" , "Xing, Beilei" Subject: RE: [PATCH v2] net/iavf: fix iavf query stats in intr thread Thread-Topic: [PATCH v2] net/iavf: fix iavf query stats in intr thread Thread-Index: AQHZUKTkURjtxHi4Mk6K5fUEbl25e6774HhQ Date: Wed, 15 Mar 2023 13:40:54 +0000 Message-ID: References: <20230222044001.1241845-1-kaiwenx.deng@intel.com> <20230307025533.1950861-1-kaiwenx.deng@intel.com> In-Reply-To: <20230307025533.1950861-1-kaiwenx.deng@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM4PR11MB5994:EE_|SN7PR11MB6994:EE_ x-ms-office365-filtering-correlation-id: 7a2c1174-2f1d-4d4a-1c29-08db255ae6a0 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: VZKjy5YZG/M3fQaU7zkYtGx/y7KtRHnrDOnCAMeeN+uRapMmbflAixl8US8J2JMglmWs7uv25rOMxPdeyyGzFyreBbi3Q/ICIqKZtAXdVv7oUaA2Nyf5g0mSDIC/0u7fGfIC5Y+qL78KCWtmRmBA7w5S2kSFnOA5sws1eGLHOIxY7hrgNEYaET9yfkVl0hMsiklqgbSLXAQv3McKnZpuUnmW7iCrWFSQ9oJSHRAF8nJ88k65RAM6Ghkw7F7mRe88/vJB977GG5xMg+hDvKfKJwID+HMuHtQCx9YFlM0k2IcLE6dsCJdPkffqECAwkcfXvEoLlixcZMN258/XgClYePrHUUAfmlDtxA+TjHk6DQcQ1e51TTw54YoJcGemg8LhZURa92Rpgh7ncafkcb79nycrvzLLGY3PmSLl0S3pqkotMde2fQT/9iChhdU5hsftCu2/b5gFrsX486esJOW1KCNwosEL48z2htnpOCh87pAI2HdJkoqHPp92cQt9SC/oi2SB4i++mFuBWHUKrAeJa1Z/wfoQfIoe4Ol2cPILnUG73Cq4qHv8JaBB/x2cwfKzYUileADF5o/OrGj8+F50nI9ooxhoJPlweQLZP6qkOMB1nvqYkp88Gn2NJIc3HelAv2l69eyE3Jg1cXqfhPjV0rCUYciBjk7oSEiLyP1Q3F4RtEUzCIMHuCFJMZkCsXtMH2R15jRC9rpw1MY0eMyTdw== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5994.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(346002)(39860400002)(376002)(366004)(396003)(136003)(451199018)(5660300002)(30864003)(83380400001)(7696005)(478600001)(9686003)(53546011)(71200400001)(107886003)(6506007)(26005)(186003)(38070700005)(55016003)(450100002)(76116006)(4326008)(33656002)(64756008)(66476007)(66446008)(52536014)(66946007)(8676002)(8936002)(41300700001)(66556008)(316002)(110136005)(86362001)(38100700002)(54906003)(122000001)(82960400001)(2906002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?mHqq6Sn2DhvaYJEy7ehKuUibHQPpJZfBrDThKjSIUb+m+ztrQ6bNsWvuyqfC?= =?us-ascii?Q?dJuLmRukGbS+CjxYDfo1mlTuo55Ov91i3SW5PqRaB5Gk/gKQY7ZQi8EXKk17?= =?us-ascii?Q?Yu3EkivvXHdRIMFQxdGWdWxc8SOb0XDRNvq/g/oe1AQPVuAsKR+cLwC4lWY7?= =?us-ascii?Q?uGRcxJgEHUhP+6yZONWb2R44amNGY2WgucjFsEKcNWxV2n+GvydjlarDxC8f?= =?us-ascii?Q?w/WA/xWbZ+vhGCGP+XysHo1oK1vJV78QA1WvapFLLofIjTmFbEF+3POgYe80?= =?us-ascii?Q?pbNERAlMfOBaU5I+2EyOaDTGxsdvhJQit5H7rf0lrOHoXbRS3X/bD50g/L9f?= =?us-ascii?Q?DQW+1kt8bU7mMkehT5Yw0OH0lxsrKFWFkVNXTohSO8PiN3jjZjFPloQfUgjY?= =?us-ascii?Q?lZirnLyvjA8/6lpReTP5mcsToVU0Zw/3sO426MuwIyRBG38j+NkjomsHy6qP?= =?us-ascii?Q?Iq2DiMhMhps8RAZFj1Sn5Y7ccfT/3nfxmefuhGAmMsGfi6RkvriyE11QTsOl?= =?us-ascii?Q?P6kB3lA/0ubif6/I07Jo4dCw5JTCd9GeN2KT24irEzRixRIKMNd7N2nNMtTE?= =?us-ascii?Q?eCIOE0mrm10+oLzubL5zgNFrfmfISw/o5K3YsvZyGQuVKnGIO88rlRRZ6CJn?= =?us-ascii?Q?/murpejOm9FSLmVRVCIlDg6gP1ZXX0psYs/dkSsNKND8BkLdg26NPGgdWDlO?= =?us-ascii?Q?RV9qlkFC/sh6e6HtGjtKeSn4czWvZjz7SqzGCTYMG6GGmF5elb9ddtnNyHob?= =?us-ascii?Q?tLdZ5nuUTT4DtRmNEBwqv28JzH4N/batQ3m0B0USsTYOIwSuMTyr5ryhYwyv?= =?us-ascii?Q?9fZ3neL0aeQaB/if2UmnmqRqbBThuG7iKtHNzOf6+fyqXNSCI5CtmErnq7N6?= =?us-ascii?Q?EHKKsyb0Kla8eAoqz3v6w5iOQtemShbrmI/2jfBT4gCoU8uuXXRYR1CFxSJH?= =?us-ascii?Q?rForTBledgBj/c+PWIaJL8mDmB8zjMt7GU3iWa55qFX2lAAPzEMXB8vUYOED?= =?us-ascii?Q?5HNRToV2hjSjxxB54ZWWDrY48e/9YaiZ7+XTVU9he25Q3xGtX2p1mWLXFtZy?= =?us-ascii?Q?LJ16lfuO/M7TEJH5sgJySepwTnMGXweIpTdSPsfKg5yfg9sqFP8yzMhG5rIL?= =?us-ascii?Q?PMSwNVaTlTecYBvNbScXLvFsMN9iWxwgvc7YOoot8ITY7gWofudcp/Q1Fr/u?= =?us-ascii?Q?wDtvoGKUCJHE24zHtXmXKybCWRO6N7QODFkrsR7gmNgwDNJ4HZyzSPuZL/Tr?= =?us-ascii?Q?7m9GFADIDSZyMHwHw/AGdtusZC0hUQqR4ptX3Eo1qRE8db4wQEqQ+9ZW9G00?= =?us-ascii?Q?njd9TXe07aXv8kIBIMXekml2a8hq7tcbokQHtyN9vOv4AAmtM8dVGNaYnbJi?= =?us-ascii?Q?mc6RQSMnwwXb+DqlRFQ3e0BoGjSnVMbncf0rHAN2luvySrUdgP82mpkkhcCV?= =?us-ascii?Q?bfANOvRI11KGCBSbtj5Xc1DIfpatecjbz8I5JHbv7smjxvLHzCUQw0+kG1fE?= =?us-ascii?Q?O9S3oTfFNmJBqsbJXnByAqFwjtBwrNuXxQ8VIGZ10LoGu0FGimBIj4TMivk8?= =?us-ascii?Q?cNjtUi7z+1TjRMiy2JKZmqaTZzAi7TC3l5UncIiX?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5994.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7a2c1174-2f1d-4d4a-1c29-08db255ae6a0 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Mar 2023 13:40:54.9437 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: h4jcWHNFYf1VzqGuiuFVMJnOsDnjtsbisvuJYKA6hW+BWqcvnd9WEOq3Qq2gzLt217PJPT/DtIp5cSMy4NZUcg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR11MB6994 X-OriginatorOrg: intel.com X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org > -----Original Message----- > From: Deng, KaiwenX > Sent: Tuesday, March 7, 2023 10:56 AM > To: dev@dpdk.org > Cc: stable@dpdk.org; Yang, Qiming ; Zhou, YidingX > ; Deng, KaiwenX ; Wu, > Jingjing ; Xing, Beilei ; Z= hang, > Qi Z > Subject: [PATCH v2] net/iavf: fix iavf query stats in intr thread >=20 > When iavf send query-stats command in eal-intr-thread through virtual > channel, there will be no response received from iavf_dev_virtchnl_handle= r > for this command during block and wait. This is because the improper implementation in iavf_execute_vf_cmd I assume without interrupt (in eal_intr_thread), we should able to query st= ats through virtchnl by pulling mode. Check out how "VIRTCHNL_OP_VERSION" was implemented. > Because iavf_dev_virtchnl_handler is also registered in eal-intr-thread. >=20 > When vf device is bonded as BONDING_MODE_TLB mode, the slave device > update callback will registered in alarm and called by eal-intr-thread, i= t > would also raise the above issue. >=20 > This commit adds local stats return to iavf_dev_stats_get immediately whe= n > it is called by eal-intr-thread. And updates local stats in iavf-virtchnl= -thread. >=20 > Fixes: cb5c1b91f76f ("net/iavf: add thread for event callbacks") > Fixes: 22b123a36d07 ("net/avf: initialize PMD") > Cc: stable@dpdk.org >=20 > Signed-off-by: Kaiwen Deng > --- > Changes since v1: > - Add lock to avoid race condition. > --- > --- > drivers/net/iavf/iavf.h | 10 ++- > drivers/net/iavf/iavf_ethdev.c | 37 ++++++++++-- > drivers/net/iavf/iavf_vchnl.c | 107 ++++++++++++++++++++++++--------- > 3 files changed, 118 insertions(+), 36 deletions(-) >=20 > diff --git a/drivers/net/iavf/iavf.h b/drivers/net/iavf/iavf.h index > 1edebab8dc..641dfa2e3b 100644 > --- a/drivers/net/iavf/iavf.h > +++ b/drivers/net/iavf/iavf.h > @@ -128,6 +128,8 @@ struct iavf_vsi { > uint16_t base_vector; > uint16_t msix_intr; /* The MSIX interrupt binds to VSI */ > struct iavf_eth_xstats eth_stats_offset; > + struct virtchnl_eth_stats eth_stats; > + rte_spinlock_t stats_lock; > }; >=20 > struct rte_flow; > @@ -325,6 +327,8 @@ struct iavf_adapter { > struct iavf_devargs devargs; > }; >=20 > +typedef void (*virtchnl_callback)(struct rte_eth_dev *dev, void *args); > + > /* IAVF_DEV_PRIVATE_TO */ > #define IAVF_DEV_PRIVATE_TO_ADAPTER(adapter) \ > ((struct iavf_adapter *)adapter) > @@ -424,8 +428,10 @@ _atomic_set_async_response_cmd(struct iavf_info > *vf, enum virtchnl_ops ops) } int iavf_check_api_version(struct iavf_ad= apter > *adapter); int iavf_get_vf_resource(struct iavf_adapter *adapter); -void > iavf_dev_event_handler_fini(void); > -int iavf_dev_event_handler_init(void); > +void iavf_dev_virtchnl_handler_fini(void); > +void iavf_dev_virtchnl_callback_post(struct rte_eth_dev *dev, > + virtchnl_callback cb, void *args); > +int iavf_dev_virtchnl_handler_init(void); > void iavf_handle_virtchnl_msg(struct rte_eth_dev *dev); int > iavf_enable_vlan_strip(struct iavf_adapter *adapter); int > iavf_disable_vlan_strip(struct iavf_adapter *adapter); diff --git > a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c index > 3196210f2c..772859d157 100644 > --- a/drivers/net/iavf/iavf_ethdev.c > +++ b/drivers/net/iavf/iavf_ethdev.c > @@ -1729,6 +1729,22 @@ iavf_update_stats(struct iavf_vsi *vsi, struct > virtchnl_eth_stats *nes) > iavf_stat_update_32(&oes->tx_discards, &nes->tx_discards); } >=20 > +static void iavf_dev_stats_get_callback(struct rte_eth_dev *dev, void > +*args) { > + struct virtchnl_eth_stats *eth_stats =3D (struct virtchnl_eth_stats > *)args; > + struct virtchnl_eth_stats *pstats =3D NULL; > + struct iavf_adapter *adapter =3D > + IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private); > + struct iavf_info *vf =3D IAVF_DEV_PRIVATE_TO_VF(dev->data- > >dev_private); > + struct iavf_vsi *vsi =3D &vf->vsi; > + int ret =3D iavf_query_stats(adapter, &pstats); > + if (ret =3D=3D 0) { > + rte_spinlock_lock(&vsi->stats_lock); > + rte_memcpy(eth_stats, pstats, sizeof(struct > virtchnl_eth_stats)); > + rte_spinlock_unlock(&vsi->stats_lock); > + } > +} > + > static int > iavf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) > { @@ -1738,9 +1754,17 @@ iavf_dev_stats_get(struct rte_eth_dev *dev, > struct rte_eth_stats *stats) > struct iavf_vsi *vsi =3D &vf->vsi; > struct virtchnl_eth_stats *pstats =3D NULL; > int ret; > - > - ret =3D iavf_query_stats(adapter, &pstats); > + int is_intr_thread =3D rte_thread_is_intr(); > + if (is_intr_thread) { > + pstats =3D &vsi->eth_stats; > + iavf_dev_virtchnl_callback_post(dev, > iavf_dev_stats_get_callback, (void *)pstats); > + ret =3D 0; > + } else { > + ret =3D iavf_query_stats(adapter, &pstats); > + } > if (ret =3D=3D 0) { > + if (is_intr_thread) > + rte_spinlock_lock(&vsi->stats_lock); > uint8_t crc_stats_len =3D (dev->data- > >dev_conf.rxmode.offloads & > RTE_ETH_RX_OFFLOAD_KEEP_CRC) ? > 0 : > RTE_ETHER_CRC_LEN; > @@ -1754,6 +1778,8 @@ iavf_dev_stats_get(struct rte_eth_dev *dev, struct > rte_eth_stats *stats) > stats->ibytes =3D pstats->rx_bytes; > stats->ibytes -=3D stats->ipackets * crc_stats_len; > stats->obytes =3D pstats->tx_bytes; > + if (is_intr_thread) > + rte_spinlock_unlock(&vsi->stats_lock); > } else { > PMD_DRV_LOG(ERR, "Get statistics failed"); > } > @@ -2571,10 +2597,13 @@ iavf_dev_init(struct rte_eth_dev *eth_dev) > struct iavf_hw *hw =3D IAVF_DEV_PRIVATE_TO_HW(adapter); > struct iavf_info *vf =3D IAVF_DEV_PRIVATE_TO_VF(adapter); > struct rte_pci_device *pci_dev =3D RTE_ETH_DEV_TO_PCI(eth_dev); > + struct iavf_vsi *vsi =3D &vf->vsi; > int ret =3D 0; >=20 > PMD_INIT_FUNC_TRACE(); >=20 > + rte_spinlock_init(&vsi->stats_lock); > + > /* assign ops func pointer */ > eth_dev->dev_ops =3D &iavf_eth_dev_ops; > eth_dev->rx_queue_count =3D iavf_dev_rxq_count; @@ -2634,7 > +2663,7 @@ iavf_dev_init(struct rte_eth_dev *eth_dev) > rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr, > ð_dev->data->mac_addrs[0]); >=20 > - if (iavf_dev_event_handler_init()) > + if (iavf_dev_virtchnl_handler_init()) > goto init_vf_err; >=20 > if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) > { @@ -2791,7 +2820,7 @@ iavf_dev_uninit(struct rte_eth_dev *dev) >=20 > iavf_dev_close(dev); >=20 > - iavf_dev_event_handler_fini(); > + iavf_dev_virtchnl_handler_fini(); >=20 > return 0; > } > diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.= c index > f92daf97f2..4136c97c45 100644 > --- a/drivers/net/iavf/iavf_vchnl.c > +++ b/drivers/net/iavf/iavf_vchnl.c > @@ -31,24 +31,36 @@ >=20 > #define MAX_EVENT_PENDING 16 >=20 > -struct iavf_event_element { > - TAILQ_ENTRY(iavf_event_element) next; > +struct iavf_virtchnl_element { > + TAILQ_ENTRY(iavf_virtchnl_element) next; > struct rte_eth_dev *dev; > - enum rte_eth_event_type event; > - void *param; > - size_t param_alloc_size; > - uint8_t param_alloc_data[0]; > + enum iavf_virchnl_handle_type { > + EVENT_TYPE =3D 0, > + CALL_TYPE > + } handle_type; > + union { > + struct event_param { > + enum rte_eth_event_type event; > + void *param; > + size_t param_alloc_size; > + uint8_t param_alloc_data[0]; > + } ep; > + struct call_param { > + virtchnl_callback cb; > + void *args; > + } cp; > + }; > }; >=20 > -struct iavf_event_handler { > +struct iavf_virtchnl_handler { > uint32_t ndev; > pthread_t tid; > int fd[2]; > pthread_mutex_t lock; > - TAILQ_HEAD(event_list, iavf_event_element) pending; > + TAILQ_HEAD(event_list, iavf_virtchnl_element) pending; > }; >=20 > -static struct iavf_event_handler event_handler =3D { > +static struct iavf_virtchnl_handler event_handler =3D { > .fd =3D {-1, -1}, > }; >=20 > @@ -60,10 +72,10 @@ static struct iavf_event_handler event_handler =3D > { #endif >=20 > static void * > -iavf_dev_event_handle(void *param __rte_unused) > +iavf_dev_virtchnl_handle(void *param __rte_unused) > { > - struct iavf_event_handler *handler =3D &event_handler; > - TAILQ_HEAD(event_list, iavf_event_element) pending; > + struct iavf_virtchnl_handler *handler =3D &event_handler; > + TAILQ_HEAD(event_list, iavf_virtchnl_element) pending; >=20 > while (true) { > char unused[MAX_EVENT_PENDING]; > @@ -76,10 +88,22 @@ iavf_dev_event_handle(void *param __rte_unused) > TAILQ_CONCAT(&pending, &handler->pending, next); > pthread_mutex_unlock(&handler->lock); >=20 > - struct iavf_event_element *pos, *save_next; > + struct iavf_virtchnl_element *pos, *save_next; > TAILQ_FOREACH_SAFE(pos, &pending, next, save_next) { > TAILQ_REMOVE(&pending, pos, next); > - rte_eth_dev_callback_process(pos->dev, pos->event, > pos->param); > + > + switch (pos->handle_type) { > + case EVENT_TYPE: > + rte_eth_dev_callback_process(pos->dev, > + pos->ep.event, pos->ep.param); > + break; > + case CALL_TYPE: > + pos->cp.cb(pos->dev, pos->cp.args); > + break; > + default: > + break; > + } > + > rte_free(pos); > } > } > @@ -92,19 +116,20 @@ iavf_dev_event_post(struct rte_eth_dev *dev, > enum rte_eth_event_type event, > void *param, size_t param_alloc_size) { > - struct iavf_event_handler *handler =3D &event_handler; > + struct iavf_virtchnl_handler *handler =3D &event_handler; > char notify_byte; > - struct iavf_event_element *elem =3D rte_malloc(NULL, sizeof(*elem) + > param_alloc_size, 0); > + struct iavf_virtchnl_element *elem =3D rte_malloc(NULL, sizeof(*elem) > + > +param_alloc_size, 0); > if (!elem) > return; > - > + elem->handle_type =3D EVENT_TYPE; > + struct event_param *ep =3D &elem->ep; > elem->dev =3D dev; > - elem->event =3D event; > - elem->param =3D param; > - elem->param_alloc_size =3D param_alloc_size; > + ep->event =3D event; > + ep->param =3D param; > + ep->param_alloc_size =3D param_alloc_size; > if (param && param_alloc_size) { > - rte_memcpy(elem->param_alloc_data, param, > param_alloc_size); > - elem->param =3D elem->param_alloc_data; > + rte_memcpy(ep->param_alloc_data, param, > param_alloc_size); > + ep->param =3D ep->param_alloc_data; > } >=20 > pthread_mutex_lock(&handler->lock); > @@ -115,10 +140,32 @@ iavf_dev_event_post(struct rte_eth_dev *dev, > RTE_SET_USED(nw); > } >=20 > +void > +iavf_dev_virtchnl_callback_post(struct rte_eth_dev *dev, > +virtchnl_callback cb, void *args) { > + struct iavf_virtchnl_handler *handler =3D &event_handler; > + char notify_byte; > + struct iavf_virtchnl_element *elem =3D rte_malloc(NULL, sizeof(*elem), > 0); > + if (!elem) > + return; > + elem->dev =3D dev; > + elem->handle_type =3D CALL_TYPE; > + struct call_param *cp =3D &elem->cp; > + cp->cb =3D cb; > + cp->args =3D args; > + > + pthread_mutex_lock(&handler->lock); > + TAILQ_INSERT_TAIL(&handler->pending, elem, next); > + pthread_mutex_unlock(&handler->lock); > + > + ssize_t nw =3D write(handler->fd[1], ¬ify_byte, 1); > + RTE_SET_USED(nw); > +} > + > int > -iavf_dev_event_handler_init(void) > +iavf_dev_virtchnl_handler_init(void) > { > - struct iavf_event_handler *handler =3D &event_handler; > + struct iavf_virtchnl_handler *handler =3D &event_handler; >=20 > if (__atomic_add_fetch(&handler->ndev, 1, __ATOMIC_RELAXED) !=3D 1) > return 0; > @@ -135,8 +182,8 @@ iavf_dev_event_handler_init(void) > TAILQ_INIT(&handler->pending); > pthread_mutex_init(&handler->lock, NULL); >=20 > - if (rte_ctrl_thread_create(&handler->tid, "iavf-event-thread", > - NULL, iavf_dev_event_handle, NULL)) { > + if (rte_ctrl_thread_create(&handler->tid, "iavf-virtchnl-thread", > + NULL, iavf_dev_virtchnl_handle, NULL)) { > __atomic_sub_fetch(&handler->ndev, 1, > __ATOMIC_RELAXED); > return -1; > } > @@ -145,9 +192,9 @@ iavf_dev_event_handler_init(void) } >=20 > void > -iavf_dev_event_handler_fini(void) > +iavf_dev_virtchnl_handler_fini(void) > { > - struct iavf_event_handler *handler =3D &event_handler; > + struct iavf_virtchnl_handler *handler =3D &event_handler; >=20 > if (__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED) !=3D 0) > return; > @@ -162,7 +209,7 @@ iavf_dev_event_handler_fini(void) > pthread_join(handler->tid, NULL); > pthread_mutex_destroy(&handler->lock); >=20 > - struct iavf_event_element *pos, *save_next; > + struct iavf_virtchnl_element *pos, *save_next; > TAILQ_FOREACH_SAFE(pos, &handler->pending, next, save_next) { > TAILQ_REMOVE(&handler->pending, pos, next); > rte_free(pos); > @@ -1408,7 +1455,7 @@ iavf_query_stats(struct iavf_adapter *adapter, > struct iavf_cmd_info args; > int err; >=20 > - if (adapter->closed) > + if (!adapter || adapter->closed) > return -EIO; >=20 > memset(&q_stats, 0, sizeof(q_stats)); > -- > 2.34.1