From patchwork Thu Feb 8 08:24:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Sundaravel X-Patchwork-Id: 198202 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp21797dyd; Thu, 8 Feb 2024 00:27:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFEfEjKXoY0yKrdq7HS1KcAbGd/N9GGpG4QB7swPoKGfeP+aEZ8gAEOiZyyNIgkFYMTfJhn X-Received: by 2002:a0c:ca91:0:b0:68c:9621:af26 with SMTP id a17-20020a0cca91000000b0068c9621af26mr7248448qvk.15.1707380865338; Thu, 08 Feb 2024 00:27:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707380865; cv=pass; d=google.com; s=arc-20160816; b=pol9W5B1kVUhaxHNPuJUpFdFxJZfH7OmMYPzhJF1YwjVBhQUHWuVxMUX3STp8kPkbQ ow8f/+951qEHg61tEIxz3K02yyVJavbJtIuLwIkpcRv9HWD71egtyQr2Y2rh7NGlDrdQ /n6NNKfoipmYDVeHD7Y5FWMvm6lkdsm39WZUBjzSvVtdeOi68jpYxfnJcpJUO7O7hd5j 4ptCtAvmqYotGlyoyxaMT8/LHvS9B/oEArm86uDB3k4BBa+FD26VY9SopM0dft4gwu1Z KPU/Ywn4UhNnGPv0zlG6O5O2Q6m1yL3hHMyoTUvgbeAGjD+BQWPU5vwP/K2mggHGRnK0 oFNg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=m2b1cGoGE6O9wuUG9B9+7/YSXWO8H0LBstm+bY//wdM=; fh=qSFjDasr53iwwBErFtS6QWBgqqP3OIl9B18JmtgJyNU=; b=s10/pAG2igfqN1sR17MaMFt0KmwpcgkVt3XgLid0ApqTvoG9uLgCM7RAXWZ+XonCsU o/WEYomPYXu8EsOltAOeVnb2rq+3EJsGAzKF86kFNOZujI9gvHDzdFn7puUXUtyboSiH VagrbA1HBMMKll+bW4Y8EDGA+NzmFNb7Ny/AnuMYtq8U5bV+h0e7CI6jd/FEYzcKelc8 PIrcNM2kgt73FtuBOEXYLGhOJDh2ucHPSN3qICeTt52jf5HKQ5dj9Agg1+lyCES3uSTS v/7U0Oi1jiyY1I2C7+ZwkwCXhexMSMsDwltpD5/5ZQk11sJP8QzZ0ZIYHG/I3upbKrIU hrAw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hoSVrYLZ; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-57615-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57615-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCXFMMVpfMbxFqnYfjOBq98ctGXG1EbxLdUCBrac9BKiz96Uf1RXJy5ulPKVNG+lNmcC9Ynb+XFpmBAfhGzbSeRzpVEOfg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id wg2-20020a05620a568200b007854f7e6c1csi2745425qkn.405.2024.02.08.00.27.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 00:27:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57615-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hoSVrYLZ; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-57615-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57615-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 24B6D1C2113F for ; Thu, 8 Feb 2024 08:27:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B2E86BB50; Thu, 8 Feb 2024 08:25:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hoSVrYLZ" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91A6267C71 for ; Thu, 8 Feb 2024 08:25:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380719; cv=none; b=XoDsmYmNqF8DnJiENInuZyES/6B3SLfJO4joaXo14h5FoQ4xqTNxclJyhZh0wez7c1A0KR9DS2SVfyi2uzf2LZKjRiJdgc/XvZGv0hdAkKpv/xY3Dfu0PaL5Y5HDZPH2e4G5UFoxm9rX3jHWBO8k55M4rWl5a870XnA2l9NrKa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380719; c=relaxed/simple; bh=IEidakVDTZ8Ejt2cZ7lVVYaAg1F/lqJZ86OjIL9IDlM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Lb2DSFbJRsD3R6DCp53tc+qyRK/B2ZwkampqgD2FduKR0JHHRgQ+BocjM4Ciavg6CtMO1NvIGPOootlo0g6dIvcHrjdnbKxWypu+8uBthJ5xqrJILAcj26jO5BRwiAVtTJXmJo38zIHY6LlykkF/zEx+aEeWIc2AtSGSwSSZlkI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hoSVrYLZ; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707380716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m2b1cGoGE6O9wuUG9B9+7/YSXWO8H0LBstm+bY//wdM=; b=hoSVrYLZrEEEc9G6pk+N2R+hcTpajJvHmVPZEAy5T/SjzWOmwme8ckqNBwOTOLWzceVAIw AJVMGwR4r1pVCOL6pwCSZK3jBaw0Ig4AROWOqiFRHxw92yZjoiSiFjfcm6rmxfqquw4XnT a1tcLywGnldghrhjfi3T6V0zMZdPhYQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-537-8Ve1q2OOOySylLJQVxvjlw-1; Thu, 08 Feb 2024 03:25:12 -0500 X-MC-Unique: 8Ve1q2OOOySylLJQVxvjlw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4C6D229AA2D2; Thu, 8 Feb 2024 08:25:12 +0000 (UTC) Received: from ksundara-mac.redhat.com (unknown [10.74.17.171]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB8BA111F9; Thu, 8 Feb 2024 08:25:06 +0000 (UTC) From: Karthik Sundaravel To: jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: pmenzel@molgen.mpg.de, jiri@resnulli.us, michal.swiatkowski@linux.intel.com, rjarry@redhat.com, aharivel@redhat.com, vchundur@redhat.com, ksundara@redhat.com, cfontain@redhat.com Subject: [PATCH v2] ice: Add get/set hw address for VFs using devlink commands Date: Thu, 8 Feb 2024 13:54:55 +0530 Message-Id: <20240208082455.66726-2-ksundara@redhat.com> In-Reply-To: <20240208082455.66726-1-ksundara@redhat.com> References: <20240208082455.66726-1-ksundara@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790318597927395986 X-GMAIL-MSGID: 1790318597927395986 Changing the MAC address of the VF ports are not available via devlink. Add the function handlers to set and get the HW address for the VF ports. Signed-off-by: Karthik Sundaravel --- drivers/net/ethernet/intel/ice/ice_devlink.c | 89 +++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ice/ice_devlink.c b/drivers/net/ethernet/intel/ice/ice_devlink.c index 80dc5445b50d..8455fa94a687 100644 --- a/drivers/net/ethernet/intel/ice/ice_devlink.c +++ b/drivers/net/ethernet/intel/ice/ice_devlink.c @@ -1576,6 +1576,92 @@ void ice_devlink_destroy_pf_port(struct ice_pf *pf) devlink_port_unregister(&pf->devlink_port); } +/** + * ice_devlink_port_get_vf_mac_address - .port_fn_hw_addr_get devlink handler + * @port: devlink port structure + * @hw_addr: MAC address of the port + * @hw_addr_len: length of MAC address + * @extack: extended netdev ack structure + * + * Callback for the devlink .port_fn_hw_addr_get operation + * Return: zero on success or an error code on failure. + */ + +static int ice_devlink_port_get_vf_mac_address(struct devlink_port *port, + u8 *hw_addr, int *hw_addr_len, + struct netlink_ext_ack *extack) +{ + struct devlink *devlink = port->devlink; + struct ice_pf *pf = devlink_priv(devlink); + struct device *dev = ice_pf_to_dev(pf); + struct devlink_port_attrs *attrs = &port->attrs; + struct devlink_port_pci_vf_attrs *pci_vf; + int vf_id; + struct ice_vf *vf; + + if (attrs->flavour == DEVLINK_PORT_FLAVOUR_PCI_VF) { + pci_vf = &attrs->pci_vf; + vf_id = pci_vf->vf; + } else { + dev_err(dev, "Unable to get the vf id for PF %d\n", pf->hw.pf_id); + return -EADDRNOTAVAIL; + } + vf = ice_get_vf_by_id(pf, vf_id); + if (!vf) { + dev_err(dev, "Unable to get the vf for PF %d\n", pf->hw.pf_id); + return -EINVAL; + } + ether_addr_copy(hw_addr, vf->dev_lan_addr); + *hw_addr_len = ETH_ALEN; + return 0; +} + +/** + * ice_devlink_port_set_vf_mac_address - .port_fn_hw_addr_set devlink handler + * @port: devlink port structure + * @hw_addr: MAC address of the port + * @hw_addr_len: length of MAC address + * @extack: extended netdev ack structure + * + * Callback for the devlink .port_fn_hw_addr_set operation + * Return: zero on success or an error code on failure. + */ +static int ice_devlink_port_set_vf_mac_address(struct devlink_port *port, + const u8 *hw_addr, + int hw_addr_len, + struct netlink_ext_ack *extack) +{ + struct devlink *devlink = port->devlink; + struct ice_pf *pf = devlink_priv(devlink); + struct device *dev = ice_pf_to_dev(pf); + struct net_device *netdev = port->type_eth.netdev; + struct devlink_port_attrs *attrs = &port->attrs; + struct devlink_port_pci_vf_attrs *pci_vf; + int vf_id; + u8 mac[ETH_ALEN]; + + if (attrs->flavour == DEVLINK_PORT_FLAVOUR_PCI_VF) { + pci_vf = &attrs->pci_vf; + vf_id = pci_vf->vf; + } else { + dev_err(dev, "Unable to get the vf id for PF %d\n", pf->hw.pf_id); + return -EADDRNOTAVAIL; + } + + if (!netdev) { + dev_err(dev, "Unable to get the netdev for PF %d\n", pf->hw.pf_id); + return -EADDRNOTAVAIL; + } + ether_addr_copy(mac, hw_addr); + + return ice_set_vf_mac(netdev, vf_id, mac); +} + +static const struct devlink_port_ops ice_devlink_vf_port_ops = { + .port_fn_hw_addr_get = ice_devlink_port_get_vf_mac_address, + .port_fn_hw_addr_set = ice_devlink_port_set_vf_mac_address, +}; + /** * ice_devlink_create_vf_port - Create a devlink port for this VF * @vf: the VF to create a port for @@ -1611,7 +1697,8 @@ int ice_devlink_create_vf_port(struct ice_vf *vf) devlink_port_attrs_set(devlink_port, &attrs); devlink = priv_to_devlink(pf); - err = devlink_port_register(devlink, devlink_port, vsi->idx); + err = devlink_port_register_with_ops(devlink, devlink_port, + vsi->idx, &ice_devlink_vf_port_ops); if (err) { dev_err(dev, "Failed to create devlink port for VF %d, error %d\n", vf->vf_id, err);