From patchwork Tue Feb 6 03:37:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Brady X-Patchwork-Id: 13546608 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 BC39C745C0 for ; Tue, 6 Feb 2024 03:38:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707190714; cv=none; b=A4kQzWgi3exyQ9YsPugzrXv+rs/mxbBvmaNQE3LDqzxWiTz9V39jVorkDPLkcQyYqcY3QeJyJ8bekPQfd8z6bI3HvMTjlE9sk12vBWhl+8eVhf5Mavy09/w1ZkqD8UuGN7IlTUk5fNvOOmjv3BMiWmwUKSZiJOhf0DcZXZY4mxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707190714; c=relaxed/simple; bh=aWtfT6JFijqob98T9YZ7Ow1M8g01mXZ2/2Uzh/JUQhQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gOzpN6r1y6RCye3H2ERpV/6tzRBmSWbyNh8JD5VCf4SrurrZKPQWen3zwFocLRb8ozBbs3qt00JKzjv7+eC15SPjoNj4cXr9T+uBtth79ms1GCrWgvF3BSdWw6X/d1wp3MJS53gaBzFyxGebPB2Ps4Ir2yLFXvEW4SXkHGMDRxE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=d4RFQ5qf; arc=none smtp.client-ip=198.175.65.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="d4RFQ5qf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707190713; x=1738726713; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aWtfT6JFijqob98T9YZ7Ow1M8g01mXZ2/2Uzh/JUQhQ=; b=d4RFQ5qfnfQUXLJ4wjWOsdnjuGZiZ7Woe5iqf/2aO9c40tCZ1m2F2FVw RS/zTSFfkSzgbwAYXrze2RBDxlgXb7rAMXCvl81yieLRMemElkZLoO1Tp 6tqlBl5EKrhe2vcw4lMzpJuWt+85dAnCIyx5PM3A+ceSROBH5es7cTyKc XvfmGBmLjxyFFp/uMQgD8g7W4W8W20pmJ4/hMbqfOCqKNxA+SXKq6bUec YYPjcL2juxiGtlixo1MmxyJpkni2ISFvBiuXnn9nreibs2dHU7jyBEkwT Zlq+Qh3rZFSvNjwzdoqH0wOMW8CMYGWIX85d8TXK9ZrHXBgSy4F9MZ1bS A==; X-IronPort-AV: E=McAfee;i="6600,9927,10975"; a="824811" X-IronPort-AV: E=Sophos;i="6.05,246,1701158400"; d="scan'208";a="824811" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 19:38:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,246,1701158400"; d="scan'208";a="5653929" Received: from dev1-atbrady.jf.intel.com ([10.166.241.35]) by orviesa004.jf.intel.com with ESMTP; 05 Feb 2024 19:38:32 -0800 From: Alan Brady To: intel-wired-lan@lists.osuosl.org Cc: netdev@vger.kernel.org, willemdebruijn.kernel@gmail.com, przemyslaw.kitszel@intel.com, igor.bagnucki@intel.com, aleksander.lobakin@intel.com, Alan Brady Subject: [PATCH v4 05/10 iwl-next] idpf: add async_handler for MAC filter messages Date: Mon, 5 Feb 2024 19:37:59 -0800 Message-Id: <20240206033804.1198416-6-alan.brady@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240206033804.1198416-1-alan.brady@intel.com> References: <20240206033804.1198416-1-alan.brady@intel.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org There are situations where the driver needs to add a MAC filter but we're explicitly not allowed to sleep so we can wait for a virtchnl message to complete. This adds an async_handler for asynchronously sent messages for MAC filters so that we can better handle if there's an error of some kind. If success we don't need to do anything else, but if we failed to program the new filter we really should remove it from our list of MAC filters. If we don't remove bad filters, what I expect to happen is after a reset of some kind we try to program the MAC filter again and it fails again. This is clearly wrong and I would expect to be confusing for the user. It could also be the failure is for a delete MAC filter message but those filters get deleted regardless. Not much we can do about a delete failure. Signed-off-by: Alan Brady --- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c index 6d95daf0637b..8756e151263d 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c @@ -3551,6 +3551,75 @@ u32 idpf_get_vport_id(struct idpf_vport *vport) return le32_to_cpu(vport_msg->vport_id); } +/** + * idpf_mac_filter_async_handler - Async callback for mac filters + * @adapter: private data struct + * @xn: transaction for message + * @ctlq_msg: received message + * + * In some scenarios driver can't sleep and wait for a reply (e.g.: stack is + * holding rtnl_lock) when adding a new mac filter. It puts us in a difficult + * situation to deal with errors returned on the reply. The best we can + * ultimately do is remove it from our list of mac filters and report the + * error. + */ +static int idpf_mac_filter_async_handler(struct idpf_adapter *adapter, + struct idpf_vc_xn *xn, + const struct idpf_ctlq_msg *ctlq_msg) +{ + struct virtchnl2_mac_addr_list *ma_list; + struct idpf_vport_config *vport_config; + struct virtchnl2_mac_addr *mac_addr; + struct idpf_mac_filter *f, *tmp; + struct list_head *ma_list_head; + struct idpf_vport *vport; + u16 num_entries; + int i; + + /* if success we're done, we're only here if something bad happened */ + if (!ctlq_msg->cookie.mbx.chnl_retval) + return 0; + + /* make sure at least struct is there */ + if (xn->reply_sz < sizeof(*ma_list)) + goto invalid_payload; + + ma_list = ctlq_msg->ctx.indirect.payload->va; + mac_addr = ma_list->mac_addr_list; + num_entries = le16_to_cpu(ma_list->num_mac_addr); + /* we should have received a buffer at least this big */ + if (xn->reply_sz < struct_size(ma_list, mac_addr_list, num_entries)) + goto invalid_payload; + + vport = idpf_vid_to_vport(adapter, le32_to_cpu(ma_list->vport_id)); + if (!vport) + goto invalid_payload; + + vport_config = adapter->vport_config[le32_to_cpu(ma_list->vport_id)]; + ma_list_head = &vport_config->user_config.mac_filter_list; + + /* We can't do much to reconcile bad filters at this point, however we + * should at least remove them from our list one way or the other so we + * have some idea what good filters we have. + */ + spin_lock_bh(&vport_config->mac_filter_list_lock); + list_for_each_entry_safe(f, tmp, ma_list_head, list) + for (i = 0; i < num_entries; i++) + if (ether_addr_equal(mac_addr[i].addr, f->macaddr)) + list_del(&f->list); + spin_unlock_bh(&vport_config->mac_filter_list_lock); + dev_err_ratelimited(&adapter->pdev->dev, "Received error sending MAC filter request (op %d)\n", + xn->vc_op); + + return 0; + +invalid_payload: + dev_err_ratelimited(&adapter->pdev->dev, "Received invalid MAC filter payload (op %d) (len %zd)\n", + xn->vc_op, xn->reply_sz); + + return -EINVAL; +} + /** * idpf_add_del_mac_filters - Add/del mac filters * @vport: Virtual port data structure @@ -3578,6 +3647,7 @@ int idpf_add_del_mac_filters(struct idpf_vport *vport, VIRTCHNL2_OP_DEL_MAC_ADDR; xn_params.timeout_ms = IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC; xn_params.async = async; + xn_params.async_handler = idpf_mac_filter_async_handler; vport_config = adapter->vport_config[np->vport_idx]; spin_lock_bh(&vport_config->mac_filter_list_lock);