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 EEC18A0C41; Wed, 23 Jun 2021 09:54:11 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D51BF40040; Wed, 23 Jun 2021 09:54:11 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 27CFA4003E for ; Wed, 23 Jun 2021 09:54:09 +0200 (CEST) IronPort-SDR: 727e+WuonpN0f7tcyGKsU8WC1FVTAW68lgejDRW+PJuFw+j1BZC7TjEVLsZiqYMNuBGyLKHtED vY5HyIvp6A1A== X-IronPort-AV: E=McAfee;i="6200,9189,10023"; a="207153149" X-IronPort-AV: E=Sophos;i="5.83,293,1616482800"; d="scan'208";a="207153149" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2021 00:54:09 -0700 IronPort-SDR: CPc2M7Cagpl2g3Q72whSsaNGmgFLCzzkuYVFGhIGkCoSk9gtL9isPV8Mk38oU7XJCgPiiChxHn aaWcRxNbndUQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,293,1616482800"; d="scan'208";a="444881099" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga007.jf.intel.com with ESMTP; 23 Jun 2021 00:54:08 -0700 Received: from fmsmsx609.amr.corp.intel.com (10.18.126.89) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Wed, 23 Jun 2021 00:54:08 -0700 Received: from fmsmsx604.amr.corp.intel.com (10.18.126.84) by fmsmsx609.amr.corp.intel.com (10.18.126.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Wed, 23 Jun 2021 00:54:07 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4 via Frontend Transport; Wed, 23 Jun 2021 00:54:07 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.173) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2242.4; Wed, 23 Jun 2021 00:54:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M+8Ojm6TsqI+lbBALJtnz+37XDtFL3+1y2qkqNZvh0Klhx+a6TZChUcoDC04LTNb6z+mDSqnlJajZ8if94ZFmdR3IwjpJdrs4UKvUlRS4tAVxClLwovyyQ7eb6+4nOcg/I9WJJBnRUpElbkmkaRJG4eFHFJlyarAG/o8UaFm5rjCxobNc70b25qmIx06XnawFaXxConzqAfIbFBTU2Van370EJXhwMuOS+wNDiUgL9OPZbmNGmMyBeDNag/RzL/ny0S2EStALwgGCkuM0OLIkuBwBliNyo2zL4z1uWrXC0kzLg56Z+SPUYj5c4A200y2vtj8J6LJrSg800huiXWnvg== 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-SenderADCheck; bh=c29JhLN0k7lunOzy9zoSEtgQpIwsRu9v4r85FGTJEdU=; b=a8pt/AeMi5Xc+U49swexppFa/ek25j1y42jTQUQMIvIMzVRpRVbEwjt6gnK1sX62fr83rF5aUN+ySGGE8uZW+NM/mQ/+KzCAr6UCcFVGPF3SeAPbMTIw8SlRL+/d2lfVZOcXB9KIQc1DP2husAvMnj0xEkzbvOSAyvaX13ynNrImKUNkYStpG70MOYzh91PPiHo7QffzbKKcVJalKAzmy289LLFBJuUfCF6ZyNTZlWG1LsIQ46GmH+oYbYBjDn1y5EJpQFg6ZkQNUYXKG0liFQNTtrADPhYPeuwJXTUi7RR4b9f+Sm8aa0URXYlBafEmxCl9xdRz5i567HgOEVemWA== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=c29JhLN0k7lunOzy9zoSEtgQpIwsRu9v4r85FGTJEdU=; b=h+gyNhA0laiBGhTRGg4skb7tr8hmckrAn6esdp6sAjTwRLxm3w40zk4JGIQ8u6pyTP5uWRyoE5v4e2p02Nu7LkoVGs9Rjk2GbkShQIrWPjVTfNrkNCaxmyYQxIIjRqQRs6BhgMbbsLnLjDpytohybCK7Yis6+l2xqkR/Nk2xwXs= Received: from MN2PR11MB4063.namprd11.prod.outlook.com (2603:10b6:208:13f::22) by MN2PR11MB4094.namprd11.prod.outlook.com (2603:10b6:208:152::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.21; Wed, 23 Jun 2021 07:54:03 +0000 Received: from MN2PR11MB4063.namprd11.prod.outlook.com ([fe80::d447:3a7a:aad7:4d32]) by MN2PR11MB4063.namprd11.prod.outlook.com ([fe80::d447:3a7a:aad7:4d32%7]) with mapi id 15.20.4242.023; Wed, 23 Jun 2021 07:54:03 +0000 From: "Xia, Chenbo" To: Maxime Coquelin , "dev@dpdk.org" , "amorenoz@redhat.com" , "david.marchand@redhat.com" Thread-Topic: [PATCH v2 3/3] net/virtio: add MAC device config getter and setter Thread-Index: AQHXY4OMf/uoffDmcE+l5sd+yZR10ashQsUg Date: Wed, 23 Jun 2021 07:54:02 +0000 Message-ID: References: <20210617141718.173396-1-maxime.coquelin@redhat.com> <20210617141718.173396-4-maxime.coquelin@redhat.com> In-Reply-To: <20210617141718.173396-4-maxime.coquelin@redhat.com> Accept-Language: en-US, zh-CN Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.55.46.52] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d07977e9-cd9c-438b-37fb-08d9361c117f x-ms-traffictypediagnostic: MN2PR11MB4094: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3826; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: cu36UAuIEP3LnG3CI9jwH0C2ZIlDtj+Vzrm6cST3ndMnGyKhsF5Q7GAv5AsomEXP1jD7WW2ZJ3hGGkO+fdXKp6/sgrDjoknE1IfW86ywvB1TaVV+n0EpsY0qLpioVaSSyKtKp9Y05RkuyTB9kkv8r6V2mDLq8YdjLz7JFWMR+eFGjP+1ThZOq0SfVaEZo3C1Du9A3FUTasHVfDnK2e9QQmpHYDaDCx1/g33VartqYtImG3x8lrBemFQMzUK41pOHP8k3bCcFG2BJGQJ5rleGCE6ieZheFn5v1epRpdr9s5y3wFysw9h5zEU2kW0mzl8x6vZCsN10btrANnCmmwGmRu0/kgmJW1hVp//b5ZrW5Nqra0HqzU1TPkqVCAITJJn8Op5hxO1dYzq1j5Wv5XpWkSAm7txfx1lbPWZcw6/MZKkoAQylgvxmRaSGessIhwDkJC/TK49Py2T2euMBFXH02W7I9WlsOEvWMpuspZ99A5qmhMt2zWAIbGTd4ANBI1zFEllEKL3OQ6UzvhiP1kjVGHtL/okxaoraE9yjWf4XiJVcKBCMA4pEOvECeo4SZ2585UfQckybN/5C8/htoB/7CFJ/fBn1inboIJ0PKgj4jxLj+Jr0G8+cNTAn9DR7DTqMc1LdC4T+dkkhvAjElybWIg== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR11MB4063.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(136003)(39860400002)(346002)(396003)(366004)(71200400001)(66446008)(26005)(64756008)(66946007)(186003)(76116006)(316002)(110136005)(122000001)(38100700002)(5660300002)(33656002)(66556008)(66476007)(8676002)(53546011)(52536014)(83380400001)(86362001)(9686003)(55016002)(2906002)(7696005)(6506007)(478600001)(8936002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?fN3Ivtc+EUwWvigNM010TwijOs0MsIQ00sWA3S6adLXOnzdVHytAwOvuzKJY?= =?us-ascii?Q?NBCaVHA6d4bzSzc9SPPXaHI5O7Q6BAbkkZH21svbveznSOhH+WkTEhb8ZY36?= =?us-ascii?Q?qwA69Jq82crtRXc7u7YWI1n51URgal7w3eo3iCssO+cdXpRDDO4DDDQef/hk?= =?us-ascii?Q?UfR6tBf3LVRjwvJHEj0iH0Ze50exGGfEkCoI27g/57ifQSYjCBumo3H8yMiS?= =?us-ascii?Q?hH+v4soiIlCSeH8MnoK3E2pqF1clTZn7VcJNSraabfcXvbWJpKB+9b7WFk4Z?= =?us-ascii?Q?BWTVkeetYoprf6vr9yF78TU4jcka2/hkjQ3ZsxTJSEjJEcsRAOsAEF7mkELj?= =?us-ascii?Q?y2tN5+aH2W43DBtBStKPE7TVoWytzuezZEfc2ZICr8CyJ/zBjp460tZbyUF1?= =?us-ascii?Q?Qf6jieJiSWe18EjleUroMJ78WLiZwLbCGk4p/pcHZyCOCkdZranJMsPqVYG+?= =?us-ascii?Q?undur1PBs7Im6mkPgdNmyX8s6Z9przWsfHIjYcXMJNVu6PTXUyNYB3S5s/Tp?= =?us-ascii?Q?II4wjxB2RxCF2FQGEa7ugTLInAKloZYMqZ50Hr9xgpydNwDCKwo7Uprtv2j4?= =?us-ascii?Q?aLMg/DAP/O0b3/2jELzDJsBzBqhZtyL2klwr17XJ4dAlZ2rSfPw83f22klSj?= =?us-ascii?Q?9Xmi9ydCoqzL16Hu6jbwaEZsXUznX7wcQtQ3EiUYZZ5BKaL0zPXCj7fZINkf?= =?us-ascii?Q?uF0f5csj3FeR3UoW+adwglcPgWHzR8fg85rJeTXC3KLd2UphwvxxPWFuxskM?= =?us-ascii?Q?hp6xSBt+Vis9LCXmz4NUDZAEQd6dXumHC1PDIvPrZRqXhFIWTW+RcjbD67Lk?= =?us-ascii?Q?9UGc1WvfghhBEir530YvoGyP9RXYjX/l4WCBkZv739Y67nPZ3Uqsxz1h294K?= =?us-ascii?Q?Wx5zeNZTbZiLgHJyKao4gOycujZWylT+fw/qCYFRc72Gk8vVnIgoT7nNXiqm?= =?us-ascii?Q?LEPDIOz7IOE7m/DteD3XYzBAAI27TOoK2SFktZnj8S1KmFAEKz9dPBo+rsNc?= =?us-ascii?Q?8NKb1SYTTOkB7eM6O3hDQqmM90wHS02lMY9gY97gtUPi+MKTlAwOZRKTnaDc?= =?us-ascii?Q?p+tx3o3M0zNfr6Ha/qnWn3nfNtKg/tVIC7oUnz5bWzpY60a8enfnX5A/gG/c?= =?us-ascii?Q?x4vgogDjAKtCBi6s/qm4G6qN2JbRnj1prXgLvKn+C0IliTiDdHG7LHR8XRLw?= =?us-ascii?Q?C+tPGa2aKCosexGn5FKhD6Tp4sfKJZtp8POqqaQEwpthHdszADsMXHF0Xzhw?= =?us-ascii?Q?GISuAMdGaO2S/jEswbg2kwy1gLN8HymUnGvMsJhMIgY/oDU5GpS12bwoG354?= =?us-ascii?Q?5h0=3D?= x-ms-exchange-transport-forked: True 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: MN2PR11MB4063.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d07977e9-cd9c-438b-37fb-08d9361c117f X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Jun 2021 07:54:02.9200 (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: F3U9J9O/+q0X9pul/1nikeusUboMfq6NYhpYkPR4AlKE5d9RVRvOLq6u2GY6J5K1TzTBMGQnT5BPtcdjYwqzIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB4094 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v2 3/3] net/virtio: add MAC device config getter and setter X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" > -----Original Message----- > From: Maxime Coquelin > Sent: Thursday, June 17, 2021 10:17 PM > To: dev@dpdk.org; Xia, Chenbo ; amorenoz@redhat.com= ; > david.marchand@redhat.com > Cc: Maxime Coquelin > Subject: [PATCH v2 3/3] net/virtio: add MAC device config getter and > setter >=20 > This patch uses the new device config ops to get and set > the MAC address if supported. >=20 > If a valid MAC address is passed as devarg of the > Virtio-user PMD, the driver will try to store it in the > device config space. Otherwise the one provided in > the device config space will be used, if available. >=20 > Signed-off-by: Maxime Coquelin > --- > .../net/virtio/virtio_user/virtio_user_dev.c | 85 ++++++++++++++++--- > .../net/virtio/virtio_user/virtio_user_dev.h | 2 + > drivers/net/virtio/virtio_user_ethdev.c | 7 +- > 3 files changed, 81 insertions(+), 13 deletions(-) >=20 > diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c > b/drivers/net/virtio/virtio_user/virtio_user_dev.c > index ed55cd7524..1cd1e95f45 100644 > --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c > +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c > @@ -260,21 +260,84 @@ int virtio_user_stop_device(struct virtio_user_dev > *dev) > return -1; > } >=20 > -static inline void > -parse_mac(struct virtio_user_dev *dev, const char *mac) > +int > +virtio_user_dev_set_mac(struct virtio_user_dev *dev) > { > - struct rte_ether_addr tmp; > + int ret =3D 0; >=20 > - if (!mac) > - return; > + if (!(dev->device_features & (1ULL << VIRTIO_NET_F_MAC))) > + return -ENOTSUP; > + > + if (!dev->ops->set_config) > + return -ENOTSUP; > + > + ret =3D dev->ops->set_config(dev, dev->mac_addr, > + offsetof(struct virtio_net_config, mac), > + RTE_ETHER_ADDR_LEN); > + if (ret) > + PMD_DRV_LOG(ERR, "(%s) Failed to set MAC address in device", > dev->path); > + > + return ret; > +} > + > +int > +virtio_user_dev_get_mac(struct virtio_user_dev *dev) > +{ > + int ret =3D 0; > + > + if (!(dev->device_features & (1ULL << VIRTIO_NET_F_MAC))) > + return -ENOTSUP; > + > + if (!dev->ops->get_config) > + return -ENOTSUP; > + > + ret =3D dev->ops->get_config(dev, dev->mac_addr, > + offsetof(struct virtio_net_config, mac), > + RTE_ETHER_ADDR_LEN); > + if (ret) > + PMD_DRV_LOG(ERR, "(%s) Failed to get MAC address from device", > dev->path); > + > + return ret; > +} > + > +static void > +virtio_user_dev_init_mac(struct virtio_user_dev *dev, const char *mac) > +{ > + struct rte_ether_addr cmdline_mac; > + char buf[RTE_ETHER_ADDR_FMT_SIZE]; > + int ret; >=20 > - if (rte_ether_unformat_addr(mac, &tmp) =3D=3D 0) { > - memcpy(dev->mac_addr, &tmp, RTE_ETHER_ADDR_LEN); > + if (mac && rte_ether_unformat_addr(mac, &cmdline_mac) =3D=3D 0) { > + /* > + * MAC address was passed from command-line, try to store > + * it in the device if it supports it. Otherwise try to use > + * the device one. > + */ > + memcpy(dev->mac_addr, &cmdline_mac, RTE_ETHER_ADDR_LEN); > dev->mac_specified =3D 1; > + > + /* Setting MAC may fail, continue to get the device one in > this case */ > + virtio_user_dev_set_mac(dev); > + ret =3D virtio_user_dev_get_mac(dev); > + if (ret =3D=3D -ENOTSUP) > + goto out; > + > + if (memcmp(&cmdline_mac, dev->mac_addr, RTE_ETHER_ADDR_LEN)) > + PMD_DRV_LOG(INFO, "(%s) Device MAC update failed", dev- > >path); > } else { > - /* ignore the wrong mac, use random mac */ > - PMD_DRV_LOG(ERR, "wrong format of mac: %s", mac); > + ret =3D virtio_user_dev_get_mac(dev); > + if (ret) { > + PMD_DRV_LOG(ERR, "(%s) No valid MAC in devargs or device, > use random", > + dev->path); > + return; > + } > + > + dev->mac_specified =3D 1; > } > +out: > + rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, > + (struct rte_ether_addr *)dev->mac_addr); > + PMD_DRV_LOG(INFO, "(%s) MAC %s specified", dev->path, buf); > } >=20 > static int > @@ -509,8 +572,6 @@ virtio_user_dev_init(struct virtio_user_dev *dev, cha= r > *path, int queues, > dev->unsupported_features =3D 0; > dev->backend_type =3D backend_type; >=20 > - parse_mac(dev, mac); > - > if (*ifname) { > dev->ifname =3D *ifname; > *ifname =3D NULL; > @@ -538,6 +599,8 @@ virtio_user_dev_init(struct virtio_user_dev *dev, cha= r > *path, int queues, > return -1; > } >=20 > + virtio_user_dev_init_mac(dev, mac); > + > if (!mrg_rxbuf) > dev->unsupported_features |=3D (1ull << VIRTIO_NET_F_MRG_RXBUF); >=20 > diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h > b/drivers/net/virtio/virtio_user/virtio_user_dev.h > index 58ad5198b6..819f6463ba 100644 > --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h > +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h > @@ -77,6 +77,8 @@ uint8_t virtio_user_handle_mq(struct virtio_user_dev > *dev, uint16_t q_pairs); > int virtio_user_dev_set_status(struct virtio_user_dev *dev, uint8_t > status); > int virtio_user_dev_update_status(struct virtio_user_dev *dev); > int virtio_user_dev_update_link_state(struct virtio_user_dev *dev); > +int virtio_user_dev_set_mac(struct virtio_user_dev *dev); > +int virtio_user_dev_get_mac(struct virtio_user_dev *dev); > void virtio_user_dev_delayed_disconnect_handler(void *param); > int virtio_user_dev_server_reconnect(struct virtio_user_dev *dev); > extern const char * const virtio_user_backend_strings[]; > diff --git a/drivers/net/virtio/virtio_user_ethdev.c > b/drivers/net/virtio/virtio_user_ethdev.c > index 3ecbb4184a..90fcd6e7cc 100644 > --- a/drivers/net/virtio/virtio_user_ethdev.c > +++ b/drivers/net/virtio/virtio_user_ethdev.c > @@ -60,12 +60,15 @@ virtio_user_write_dev_config(struct virtio_hw *hw, > size_t offset, > struct virtio_user_dev *dev =3D virtio_user_get_dev(hw); >=20 > if ((offset =3D=3D offsetof(struct virtio_net_config, mac)) && > - (length =3D=3D RTE_ETHER_ADDR_LEN)) > + (length =3D=3D RTE_ETHER_ADDR_LEN)) { > for (i =3D 0; i < RTE_ETHER_ADDR_LEN; ++i) > dev->mac_addr[i] =3D ((const uint8_t *)src)[i]; > - else > + virtio_user_dev_set_mac(dev); > + virtio_user_dev_get_mac(dev); > + } else { > PMD_DRV_LOG(ERR, "not supported offset=3D%zu, len=3D%d", > offset, length); > + } > } >=20 > static void > -- > 2.31.1 Reviewed-by: Chenbo Xia