Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp378475rbb; Sat, 24 Feb 2024 04:44:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXFmdBSK4Qgpvt6y6bxh0xVrnudqKyRw6GHtMThHVvJL4xKrMxLpG3CmwSktRxqG99YUTfRGQiM2taSon/S/q0KccMhJ1nEKF2DhHWYag== X-Google-Smtp-Source: AGHT+IHfIyPnkcOD8NGQdjRVLsrEpcaa/il2kbWFJDJjDfuzRooUsBEOYlExAKdNo9hzot0IWk3u X-Received: by 2002:a05:6358:8414:b0:17b:5df3:98fa with SMTP id b20-20020a056358841400b0017b5df398famr1593131rwk.19.1708778670350; Sat, 24 Feb 2024 04:44:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708778670; cv=pass; d=google.com; s=arc-20160816; b=LX1jIoJLZV4ULB5zCzewWfEK4zjB2TWWBe+7WvpnrMPLnivQEqk8trT+hMYIvLNnzk txHwXf8XLvqqXV8lxQ0NrpTLeBzPCTaTSdTxlYP60ScyzIft9r1GrEqa1XvBDucWsmdI qTDz03I2bQjx4VFL71QyPPALk8jxVXKaD8O8TPwm+RpEcFY3tog3+CjCznHgMPr4EXHa huWk74tOBsrkWBW6ZrqkOhcpbHLbZg+cHP2X5/x+Nf0ht96p3Hlii3VezMFSk3VhsIEM y+quKA6wd8j08/fq+g0thXixqZWfW9/7nMIwDbiLONE1aq0h1WPb9rXhiBhz38t724vZ kv7Q== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=/8cJq6gJYr9fItMmms3ESiKT1OC7cypwGkdjoZcf+Rc=; fh=o/v7EJKM6lwa/6lSMkCJulL8r4w4e1jtZ95Ifc1ztmw=; b=H030+0v1bDuSX+O4aYMm6g5K2ajo58WZZUfEqCcvCd4McWZdaCD6o13s3EbBt3BfW9 raCT8JLxLJh0CnZJOsd2iVyhjn7PiZvX/xAyHtCPWE26kwKEQ0ssgR7FaZOuduSN6hMB CrOjKUQWIX3soa1cYhstIhsYdiq+gcu4xkgnYXwCvlRCZk9gBxxOX9JWzGORA66NDNCS Ki3b81fLoIqsBWHnNj1RqZUcergI4UA/imj1BMSaY3bxa9z+qFcf+xe+cfW3zRey3os3 buRlAuq1GS9sSFzoi7UEzDcs8+Ermz/e+YOa32L1ED2UQ0miishAN1uDmqW2DC6ikRvE 1/5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X9kOIPc7; 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-79636-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79636-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c8-20020a05620a164800b00787a8f590d3si913921qko.547.2024.02.24.04.44.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 04:44:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79636-linux.lists.archive=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=X9kOIPc7; 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-79636-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79636-linux.lists.archive=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 DBF961C2112D for ; Sat, 24 Feb 2024 12:44:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE57E3F9C4; Sat, 24 Feb 2024 12:44:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="X9kOIPc7" 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 4C44D3C099 for ; Sat, 24 Feb 2024 12:44:23 +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=1708778665; cv=none; b=kjNWGOV0a/NdwBq5XtJIKjqf2/dVcvSG3RxGY7zFxfS/By4uAvYlUuSFW1JI7krwSreHlZNZETVBNUN/KPT6nbMdRDHsjU5TP/xVvPyryshJb5RtB61YDaNdbWBswhtZULfOXSXa6t+9LmnD4uc1TmPvDUu5HiYbvt6UdsL/fnw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708778665; c=relaxed/simple; bh=OmOCpzykCGpZfmK48YnLPvj1ug65eRzDoYKAnvWOBBM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=oIt3cj9zc9PJg/AI4ScnIOwKzeny8dwlPT4cUYE+XX9/To/HqqI6650VrciQhZ+Bj5BUAMcJu1pLVix/PUIjigy8gPORqs055ZKYWEnui9BZ171DI9eplRCFRwvGWQmEyJGeC/bOY4VxElG3AImwV75AxIGQ8huLKqMXxiGrnLk= 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=X9kOIPc7; 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=1708778662; 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; bh=/8cJq6gJYr9fItMmms3ESiKT1OC7cypwGkdjoZcf+Rc=; b=X9kOIPc7igOAVTMZKuUEAsIKPuLGtOAEHwOlehXTP/udzGifEdxk7JOQLTA61Sfv7UXCmZ X5WeL56KcppzOPG335uDrViIpuJnGvOF+dI/N+Fu4VNjmZTmVtgb3PKjiT41Je2lVNapX0 WlXQIx0jNp/A7QwGrxYFys2cfO82M4k= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-dqKOwW8dOVeR3GCN4KkXGg-1; Sat, 24 Feb 2024 07:44:17 -0500 X-MC-Unique: dqKOwW8dOVeR3GCN4KkXGg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 7E9E9800074; Sat, 24 Feb 2024 12:44:16 +0000 (UTC) Received: from ksundara-mac.redhat.com (unknown [10.74.16.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C9AB492BC6; Sat, 24 Feb 2024 12:44:09 +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 v4] ice: Add get/set hw address for VFs using devlink commands Date: Sat, 24 Feb 2024 18:14:06 +0530 Message-Id: <20240224124406.11369-1-ksundara@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 Changing the MAC address of the VFs are not available via devlink. Add the function handlers to set and get the HW address for the VFs. Signed-off-by: Karthik Sundaravel --- drivers/net/ethernet/intel/ice/ice_devlink.c | 88 +++++++++++++++++++- 1 file changed, 87 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..c3813edd6a76 100644 --- a/drivers/net/ethernet/intel/ice/ice_devlink.c +++ b/drivers/net/ethernet/intel/ice/ice_devlink.c @@ -1576,6 +1576,91 @@ 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_port_attrs *attrs = &port->attrs; + struct devlink_port_pci_vf_attrs *pci_vf; + struct devlink *devlink = port->devlink; + struct ice_pf *pf; + struct ice_vf *vf; + int vf_id; + + pf = devlink_priv(devlink); + if (attrs->flavour == DEVLINK_PORT_FLAVOUR_PCI_VF) { + pci_vf = &attrs->pci_vf; + vf_id = pci_vf->vf; + } else { + NL_SET_ERR_MSG_MOD(extack, "Unable to get the vf id"); + return -EADDRNOTAVAIL; + } + vf = ice_get_vf_by_id(pf, vf_id); + if (!vf) { + NL_SET_ERR_MSG_MOD(extack, "Unable to get the vf"); + return -EINVAL; + } + ether_addr_copy(hw_addr, vf->dev_lan_addr); + *hw_addr_len = ETH_ALEN; + + ice_put_vf(vf); + 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 net_device *netdev = port->type_eth.netdev; + struct devlink_port_attrs *attrs = &port->attrs; + struct devlink_port_pci_vf_attrs *pci_vf; + u8 mac[ETH_ALEN]; + int vf_id; + + if (attrs->flavour == DEVLINK_PORT_FLAVOUR_PCI_VF) { + pci_vf = &attrs->pci_vf; + vf_id = pci_vf->vf; + } else { + NL_SET_ERR_MSG_MOD(extack, "Unable to get the vf id"); + return -EADDRNOTAVAIL; + } + + if (!netdev) { + NL_SET_ERR_MSG_MOD(extack, "Unable to get the netdev"); + 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 +1696,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); -- 2.39.3 (Apple Git-145)