From patchwork Tue Jan 14 00:07:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanman Pradhan X-Patchwork-Id: 13938247 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D0F429B0; Tue, 14 Jan 2025 00:07:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736813231; cv=none; b=G/vkdMkOF7uOWbY4yN+RA1h7dxGxEcktpRWLgVXbnH+DvWQM9jM0VGdg+uNOz8yXqGK3ZK7qYhyoOfZNcdJgEWPC8J0DRVET29IQABwg3EMr6t6D+Kanok3a3btA/wc8j/CFTIE4louXIM6jmIb+q8kISBscxhQgIgCsjmJrXxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736813231; c=relaxed/simple; bh=jDz1AqHy9kVmzlLThGksZio6MPDBnKohThpfVT77dtY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tGFzfHzEvYd8zXWwQlOCTdKaKi/cYY/jhJLXywhuuF30GtbHAuUGnfGquKud2C5hG7YQahfYayrtwSbD/fMH870Oxh6ZNEl9v4QtOh1MsXX4jeI0HaBicIy1qpqEX5BG2YQz4Tv5bAHteFZvsjzbTc3XP+/7txGb9K7xNwrm2VM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RdwrA5Ix; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RdwrA5Ix" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-21669fd5c7cso87870725ad.3; Mon, 13 Jan 2025 16:07:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736813228; x=1737418028; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UqinG5bc4R8mduD4J0r80sXRxbkZhRD0K6VLj/i18Zs=; b=RdwrA5Ix7Rv7l59ohC5fyKyxPAtWSHWREjFuAkX/eagi8SbVLt+S5aAtGJZDPGZY/5 NX7JnShYpdKg49jyYdo/3hlNa0wfUbAKkHN/kBD5CDa1fW8SrCuu5ginzYLqu/f++0Dm Vfwv8WlSOgyRo0amZCjyyrNeizN7IOgElnMM9j6qoPj8zieNG0pj/ocDJgFcCfQ7poS6 ZPaK417ExkZAz+0gAOw49v4BQX3eQ51kbFYoGXkJCQ+kdhXd6Cji7AzyxKjEbs4z/nL7 5PLsQHOIr4YoGbM5kg37nKPW77iBlAjwN/ouVWkOTbItkILH6Fpyg4WxR8W2lrZ1BXxY G4NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736813228; x=1737418028; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UqinG5bc4R8mduD4J0r80sXRxbkZhRD0K6VLj/i18Zs=; b=mSLBMin0UqtSW13lnOKdAkPpDMXi++ac0TRMGhS7TdssaMG0vXsT5B1u50LuCr7qzr SAJgW9keeVYYBGOCQx17ALGkQ4SNe2gbGLnL32zGLwdTTrwdcSOinAqNJfhDjkMHTZes Rm6mQeDv3wGnBCPR2Vv5CZ/osVUHQUlYJzOcD86ltOgv3RHGGyVP5m0esoiVM1t+pOoc pDQP9RXWHKJR8yKaoBrA5KB3ffjbDS75bsktzk0+vX0SE7z7nZGMx46VMQ6JXMd0OYM8 mwcc+LXr2FKfrQ9mFMcjretNdqCXPVUd7uO8q8LiaFXpFOqdyF9vkmQa2Yg8ZRkApK/G 0DMw== X-Forwarded-Encrypted: i=1; AJvYcCUZM28IfgveX5o/z1Xuk7CdDeAc6eVVvioD4YiZe1ot5yiy0/5b5TgC81b6LlUulzOn6mHN+YXu0JGhCQ==@vger.kernel.org, AJvYcCXfUDtP7XywF0XB7ByrBu1oODL/2SHreeRk0uP9dDeOuPjP48xMuVgC2JkOOBgXrOJ+In7BrLoNJm+oV87D@vger.kernel.org X-Gm-Message-State: AOJu0YzJbFO3qrrFUu4Vn7Qkd9y6sgEPdMM8cc6ngfU6lLCWaov+4hkq RZ0SGEcpCqErrwoQ0rXU6SlGxtpzaJIhYOy/aulECWWaXXGW8z0hWBh2QeN6F50= X-Gm-Gg: ASbGncsqblLj0MoGR7eyKGMs68dV+2w+I+Tn3ugSb6Y1g8/Sejd1xEeNxFzZFCG5gni WYBhYGCYl3NSo97h7q90B8zJcOBrCCtHATrGVdNM/ntlNyvWqmRtL4hhuta0dtbaGfEzHPZh9rm kN/79n1undBa/fFEL4l6nh8nkLLg+z20Jlsmn/khfvhlWOr7p8xR6UbxFPBz3PsVUKIyOWSgW01 V5uLbhzQa+2Cui5lNjs57CDunkQW6T1UA6GjCipZ4nfKWy6z9n2JuU= X-Google-Smtp-Source: AGHT+IH9zalTXeJ5JjdVaMZ5kxZTumblylYHR0fnxBZeWPJquezB/aW+7gRC0IReJeHb2JcssgwZ2g== X-Received: by 2002:a05:6a20:2453:b0:1e1:9662:a6f2 with SMTP id adf61e73a8af0-1e88d0bffe4mr41203169637.35.1736813227661; Mon, 13 Jan 2025 16:07:07 -0800 (PST) Received: from localhost ([2a03:2880:ff:4a::]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72d406a5a32sm6717682b3a.173.2025.01.13.16.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 16:07:07 -0800 (PST) From: Sanman Pradhan To: netdev@vger.kernel.org Cc: alexanderduyck@fb.com, kuba@kernel.org, kernel-team@meta.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, kalesh-anakkur.purayil@broadcom.com, linux@roeck-us.net, mohsin.bashr@gmail.com, jdelvare@suse.com, horms@kernel.org, suhui@nfschina.com, linux-kernel@vger.kernel.org, vadim.fedorenko@linux.dev, linux-hwmon@vger.kernel.org, sanmanpradhan@meta.com, sanman.p211993@gmail.com Subject: [PATCH net-next 1/3] eth: fbnic: hwmon: Add completion infrastructure for firmware requests Date: Mon, 13 Jan 2025 16:07:03 -0800 Message-ID: <20250114000705.2081288-2-sanman.p211993@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250114000705.2081288-1-sanman.p211993@gmail.com> References: <20250114000705.2081288-1-sanman.p211993@gmail.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add infrastructure to support firmware request/response handling with completions. Add a completion structure to track message state including message type for matching, completion for waiting for response, and result for error propagation. Use existing spinlock to protect the writes. The data from the various response types will be added to the "union u" by subsequent commits. Signed-off-by: Sanman Pradhan Reviewed-by: Michal Swiatkowski --- drivers/net/ethernet/meta/fbnic/fbnic.h | 1 + drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 79 ++++++++++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 13 ++++ 3 files changed, 93 insertions(+) -- 2.43.5 diff --git a/drivers/net/ethernet/meta/fbnic/fbnic.h b/drivers/net/ethernet/meta/fbnic/fbnic.h index 50f97f5399ff..ad8ac5ac7be9 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic.h @@ -41,6 +41,7 @@ struct fbnic_dev { struct fbnic_fw_mbx mbx[FBNIC_IPC_MBX_INDICES]; struct fbnic_fw_cap fw_cap; + struct fbnic_fw_completion *cmpl_data; /* Lock protecting Tx Mailbox queue to prevent possible races */ spinlock_t fw_tx_lock; diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c index 8f7a2a19ddf8..320615a122e4 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c @@ -228,6 +228,63 @@ static void fbnic_mbx_process_tx_msgs(struct fbnic_dev *fbd) tx_mbx->head = head; } +static __maybe_unused int fbnic_mbx_map_req_w_cmpl(struct fbnic_dev *fbd, + struct fbnic_tlv_msg *msg, + struct fbnic_fw_completion *cmpl_data) +{ + unsigned long flags; + int err; + + spin_lock_irqsave(&fbd->fw_tx_lock, flags); + + /* If we are already waiting on a completion then abort */ + if (cmpl_data && fbd->cmpl_data) { + err = -EBUSY; + goto unlock_mbx; + } + + /* Record completion location and submit request */ + if (cmpl_data) + fbd->cmpl_data = cmpl_data; + + err = fbnic_mbx_map_msg(fbd, FBNIC_IPC_MBX_TX_IDX, msg, + le16_to_cpu(msg->hdr.len) * sizeof(u32), 1); + + /* If msg failed then clear completion data for next caller */ + if (err && cmpl_data) + fbd->cmpl_data = NULL; + +unlock_mbx: + spin_unlock_irqrestore(&fbd->fw_tx_lock, flags); + + return err; +} + +static void fbnic_fw_release_cmpl_data(struct kref *kref) +{ + struct fbnic_fw_completion *cmpl_data; + + cmpl_data = container_of(kref, struct fbnic_fw_completion, + ref_count); + kfree(cmpl_data); +} + +static __maybe_unused struct fbnic_fw_completion * +fbnic_fw_get_cmpl_by_type(struct fbnic_dev *fbd, u32 msg_type) +{ + struct fbnic_fw_completion *cmpl_data = NULL; + unsigned long flags; + + spin_lock_irqsave(&fbd->fw_tx_lock, flags); + if (fbd->cmpl_data && fbd->cmpl_data->msg_type == msg_type) { + cmpl_data = fbd->cmpl_data; + kref_get(&fbd->cmpl_data->ref_count); + } + spin_unlock_irqrestore(&fbd->fw_tx_lock, flags); + + return cmpl_data; +} + /** * fbnic_fw_xmit_simple_msg - Transmit a simple single TLV message w/o data * @fbd: FBNIC device structure @@ -802,3 +859,25 @@ void fbnic_get_fw_ver_commit_str(struct fbnic_dev *fbd, char *fw_version, fbnic_mk_full_fw_ver_str(mgmt->version, delim, mgmt->commit, fw_version, str_sz); } + +void fbnic_fw_init_cmpl(struct fbnic_fw_completion *fw_cmpl, + u32 msg_type) +{ + fw_cmpl->msg_type = msg_type; + init_completion(&fw_cmpl->done); + kref_init(&fw_cmpl->ref_count); +} + +void fbnic_fw_clear_compl(struct fbnic_dev *fbd) +{ + unsigned long flags; + + spin_lock_irqsave(&fbd->fw_tx_lock, flags); + fbd->cmpl_data = NULL; + spin_unlock_irqrestore(&fbd->fw_tx_lock, flags); +} + +void fbnic_fw_put_cmpl(struct fbnic_fw_completion *fw_cmpl) +{ + kref_put(&fw_cmpl->ref_count, fbnic_fw_release_cmpl_data); +} diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h index 221faf8c6756..ff304baade91 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h @@ -44,6 +44,15 @@ struct fbnic_fw_cap { u8 link_fec; }; +struct fbnic_fw_completion { + u32 msg_type; + struct completion done; + struct kref ref_count; + int result; + union { + } u; +}; + void fbnic_mbx_init(struct fbnic_dev *fbd); void fbnic_mbx_clean(struct fbnic_dev *fbd); void fbnic_mbx_poll(struct fbnic_dev *fbd); @@ -52,6 +61,10 @@ void fbnic_mbx_flush_tx(struct fbnic_dev *fbd); int fbnic_fw_xmit_ownership_msg(struct fbnic_dev *fbd, bool take_ownership); int fbnic_fw_init_heartbeat(struct fbnic_dev *fbd, bool poll); void fbnic_fw_check_heartbeat(struct fbnic_dev *fbd); +void fbnic_fw_init_cmpl(struct fbnic_fw_completion *cmpl_data, + u32 msg_type); +void fbnic_fw_clear_compl(struct fbnic_dev *fbd); +void fbnic_fw_put_cmpl(struct fbnic_fw_completion *cmpl_data); #define fbnic_mk_full_fw_ver_str(_rev_id, _delim, _commit, _str, _str_sz) \ do { \ From patchwork Tue Jan 14 00:07:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanman Pradhan X-Patchwork-Id: 13938248 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA7182C9A; Tue, 14 Jan 2025 00:07:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736813231; cv=none; b=QUXmpoZhvBQHazvU2V76L0tHssO8V15ZcEbbkla31oxc9sGjuBz2889EdUyRJzjrqNtATpCOj/W8NcoHh67/3ecRWUZbAcFQ+7RsJejLIyFUnVVwhkby1JeK7bHNiO22XepNJdPYmgP49i4Ecr3dAR9IsBgwqo3x/w/hUWfNfvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736813231; c=relaxed/simple; bh=Nor1WRck3wXAPi0VIO7sp1IPeuWYHCF8mQk1w2KsRxs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=segTkfqSKYvKkAf47XGERqKFc/t/KkIhOkq9DX+dKEqDpJKOoSUpBOrpbXJseAbB2sJnVWYmvr77IDNLG+8f0SYPkJDxD10FcJc5DNv8QDTfG0jPbdk+dYTuZvN8qtoQJJgfR8P7IyWAjBxE9TAem/98Hxb3j5qFSmDvlJ5nshY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lJCW0eTK; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lJCW0eTK" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2165cb60719so87383835ad.0; Mon, 13 Jan 2025 16:07:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736813229; x=1737418029; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nBxmq1t8/dhRnQdSNSLZESYohKM4MWtxVHXJFN7pUOI=; b=lJCW0eTK8tNaoteoZPfu98I24r2PKAu9IZEq964/DmYWEwQ31c98taX/fN6kYsSxCw WTYZDiWt1wSA90FWQF7aSdaEHZKmIWd0WsxVrzYqVa6y1UUaExNFEGRALa5gwnr5ZYuO exAGF5rof7vCTjELl028KoXdpJS/RR39oZjZIaOocUixq+wUn3WnLmco+5mgtDzjuHSi 5/aicoEZ25eAEVB/ccz/dUuo8KzKh2fk6boHuKwwH0H1XqL8TAgtRBwRzT2i0EIuigv5 Lp75TGs/eBEN49BWbEl9MOpZXrytqu3uIQwo4cNhNHhQwJTkhRXr/AXnCxvd90AXj0FF c4mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736813229; x=1737418029; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nBxmq1t8/dhRnQdSNSLZESYohKM4MWtxVHXJFN7pUOI=; b=N/NsmYBL67tY4keGAOrIb4xgxWaEbKgZMtcpIdKmhoqFK+Ozl8Ny8uDbXuOzSL8q0V VH5+NvTnysmNjJOdrdAw+l1hwbLtpWSacORivfqqJgkvRAb6EDvQJyDNJo9BmEoz0KKB la6b5WIMHVMvcorKcjrfNN0bn+mvtBpERZNOcyVpM6qig3Jh+uTL77zPANyPc+w7MZvj Lnb5R9TUYDuxGbhCpJF2p7psrN6NkRKR5RQzx/X8Owsl1l9tM8Logz/aWnZd9W4p6GDG V6AaFrtbBgkSfkLowX+6d5o+uQ2PneLjweg8qssaLDIJb/Q5YLVwdFgQdfcHKaUhn2Qf D/eg== X-Forwarded-Encrypted: i=1; AJvYcCV6VFK3qmHYcjsDrMMhPlR938J+94aqMGw/hNubaGdORk69Gxeu+U376WV61a25cRVof1HX4gvQHT4Oxq8f@vger.kernel.org, AJvYcCXC/7UqCAI/q0vZ0dG8XfOlbQgLJWK6zgy7BDlJFj6nOze0Z8XB8wam2aMej/U9OchYo/8HklZfCe/dFg==@vger.kernel.org X-Gm-Message-State: AOJu0Yx1QUQOvo85iGAVgNyZ6/A63shVzHor1GJjxbcKC3or4cFQcJzv WS2lEHq8qVehwGBbKcySUqBhvkNZPmrkdHnJkRxXQKSjQY49DZF7IfJ69fW7rE8= X-Gm-Gg: ASbGncvYe3+FV+t901B3gX7HWfs7GIGEQE7KOhe0jo24CfPQq5plOUnh8O0EGqTXxvi prdh6WFl2NmvFOvaRfjcxUDJgR2ExAE/sF6j79+kNusfaOPDY/Sjp+TbS1k44xcXGdlg5FcyTP/ SgwuKCiJFiUtsLTf2sc1pan18GWnfHI0ZYWYhpBCyskWs48dWnAM6d4khw7Zoar421fBvY6otn+ oLuS1Pa6ktXDj6hbxf0MxndH4C+a+zSqNEEEGz6z+KXqjG2TqUFyA== X-Google-Smtp-Source: AGHT+IGhYyUa2EoaX/RgSQJjnYDPEbFmy4xcTjVzx48DU2ggRMkZuAlkum/jB2a2obLvFLRu2j8mNQ== X-Received: by 2002:a05:6a00:3910:b0:72a:a9d9:5a82 with SMTP id d2e1a72fcca58-72d21deb996mr35454831b3a.0.1736813228809; Mon, 13 Jan 2025 16:07:08 -0800 (PST) Received: from localhost ([2a03:2880:ff:4::]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72d40549413sm6597703b3a.12.2025.01.13.16.07.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 16:07:08 -0800 (PST) From: Sanman Pradhan To: netdev@vger.kernel.org Cc: alexanderduyck@fb.com, kuba@kernel.org, kernel-team@meta.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, kalesh-anakkur.purayil@broadcom.com, linux@roeck-us.net, mohsin.bashr@gmail.com, jdelvare@suse.com, horms@kernel.org, suhui@nfschina.com, linux-kernel@vger.kernel.org, vadim.fedorenko@linux.dev, linux-hwmon@vger.kernel.org, sanmanpradhan@meta.com, sanman.p211993@gmail.com Subject: [PATCH net-next 2/3] eth: fbnic: hwmon: Add support for reading temperature and voltage sensors Date: Mon, 13 Jan 2025 16:07:04 -0800 Message-ID: <20250114000705.2081288-3-sanman.p211993@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250114000705.2081288-1-sanman.p211993@gmail.com> References: <20250114000705.2081288-1-sanman.p211993@gmail.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add support for reading temperature and voltage sensor data from firmware by implementing a new TSENE message type and response parsing. This adds message handler infrastructure to transmit sensor read requests and parse responses. The sensor data will be exposed through the driver's hwmon interface. Signed-off-by: Sanman Pradhan Reviewed-by: Michal Swiatkowski --- drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 89 ++++++++++++++++++++- drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 15 ++++ drivers/net/ethernet/meta/fbnic/fbnic_mac.c | 72 +++++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_mac.h | 7 ++ 4 files changed, 179 insertions(+), 4 deletions(-) -- 2.43.5 diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c index 320615a122e4..bbc7c1c0c37e 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c @@ -228,9 +228,9 @@ static void fbnic_mbx_process_tx_msgs(struct fbnic_dev *fbd) tx_mbx->head = head; } -static __maybe_unused int fbnic_mbx_map_req_w_cmpl(struct fbnic_dev *fbd, - struct fbnic_tlv_msg *msg, - struct fbnic_fw_completion *cmpl_data) +static int fbnic_mbx_map_req_w_cmpl(struct fbnic_dev *fbd, + struct fbnic_tlv_msg *msg, + struct fbnic_fw_completion *cmpl_data) { unsigned long flags; int err; @@ -269,7 +269,7 @@ static void fbnic_fw_release_cmpl_data(struct kref *kref) kfree(cmpl_data); } -static __maybe_unused struct fbnic_fw_completion * +static struct fbnic_fw_completion * fbnic_fw_get_cmpl_by_type(struct fbnic_dev *fbd, u32 msg_type) { struct fbnic_fw_completion *cmpl_data = NULL; @@ -708,6 +708,84 @@ void fbnic_fw_check_heartbeat(struct fbnic_dev *fbd) dev_warn(fbd->dev, "Failed to send heartbeat message\n"); } +/** + * fbnic_fw_xmit_tsene_read_msg - Create and transmit a sensor read request + * @fbd: FBNIC device structure + * @cmpl_data: Completion data structure to store sensor response + * + * Asks the firmware to provide an update with the latest sensor data. + * The response will contain temperature and voltage readings. + * + * Return: 0 on success, negative error value on failure + */ +int fbnic_fw_xmit_tsene_read_msg(struct fbnic_dev *fbd, + struct fbnic_fw_completion *cmpl_data) +{ + struct fbnic_tlv_msg *msg; + int err; + + if (!fbnic_fw_present(fbd)) + return -ENODEV; + + msg = fbnic_tlv_msg_alloc(FBNIC_TLV_MSG_ID_TSENE_READ_REQ); + if (!msg) + return -ENOMEM; + + err = fbnic_mbx_map_req_w_cmpl(fbd, msg, cmpl_data); + if (err) + goto free_message; + + return 0; + +free_message: + free_page((unsigned long)msg); + return err; +} + +static const struct fbnic_tlv_index fbnic_tsene_read_resp_index[] = { + FBNIC_TLV_ATTR_S32(FBNIC_TSENE_THERM), + FBNIC_TLV_ATTR_S32(FBNIC_TSENE_VOLT), + FBNIC_TLV_ATTR_S32(FBNIC_TSENE_ERROR), + FBNIC_TLV_ATTR_LAST +}; + +static int fbnic_fw_parse_tsene_read_resp(void *opaque, + struct fbnic_tlv_msg **results) +{ + struct fbnic_fw_completion *cmpl_data; + struct fbnic_dev *fbd = opaque; + int err = 0; + + /* Verify we have a completion pointer to provide with data */ + cmpl_data = fbnic_fw_get_cmpl_by_type(fbd, + FBNIC_TLV_MSG_ID_TSENE_READ_RESP); + if (!cmpl_data) + return -EINVAL; + + if (results[FBNIC_TSENE_ERROR]) { + err = fbnic_tlv_attr_get_unsigned(results[FBNIC_TSENE_ERROR]); + if (err) + goto exit_complete; + } + + if (!results[FBNIC_TSENE_THERM] || !results[FBNIC_TSENE_VOLT]) { + err = -EINVAL; + goto exit_complete; + } + + cmpl_data->u.tsene.millidegrees = + fbnic_tlv_attr_get_signed(results[FBNIC_TSENE_THERM]); + cmpl_data->u.tsene.millivolts = + fbnic_tlv_attr_get_signed(results[FBNIC_TSENE_VOLT]); + +exit_complete: + cmpl_data->result = err; + complete(&cmpl_data->done); + fbnic_fw_put_cmpl(cmpl_data); + + return err; +} + static const struct fbnic_tlv_parser fbnic_fw_tlv_parser[] = { FBNIC_TLV_PARSER(FW_CAP_RESP, fbnic_fw_cap_resp_index, fbnic_fw_parse_cap_resp), @@ -715,6 +793,9 @@ static const struct fbnic_tlv_parser fbnic_fw_tlv_parser[] = { fbnic_fw_parse_ownership_resp), FBNIC_TLV_PARSER(HEARTBEAT_RESP, fbnic_heartbeat_resp_index, fbnic_fw_parse_heartbeat_resp), + FBNIC_TLV_PARSER(TSENE_READ_RESP, + fbnic_tsene_read_resp_index, + fbnic_fw_parse_tsene_read_resp), FBNIC_TLV_MSG_ERROR }; diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h index ff304baade91..fe68333d51b1 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h @@ -50,6 +50,10 @@ struct fbnic_fw_completion { struct kref ref_count; int result; union { + struct { + s32 millivolts; + s32 millidegrees; + } tsene; } u; }; @@ -61,6 +65,8 @@ void fbnic_mbx_flush_tx(struct fbnic_dev *fbd); int fbnic_fw_xmit_ownership_msg(struct fbnic_dev *fbd, bool take_ownership); int fbnic_fw_init_heartbeat(struct fbnic_dev *fbd, bool poll); void fbnic_fw_check_heartbeat(struct fbnic_dev *fbd); +int fbnic_fw_xmit_tsene_read_msg(struct fbnic_dev *fbd, + struct fbnic_fw_completion *cmpl_data); void fbnic_fw_init_cmpl(struct fbnic_fw_completion *cmpl_data, u32 msg_type); void fbnic_fw_clear_compl(struct fbnic_dev *fbd); @@ -89,6 +95,8 @@ enum { FBNIC_TLV_MSG_ID_OWNERSHIP_RESP = 0x13, FBNIC_TLV_MSG_ID_HEARTBEAT_REQ = 0x14, FBNIC_TLV_MSG_ID_HEARTBEAT_RESP = 0x15, + FBNIC_TLV_MSG_ID_TSENE_READ_REQ = 0x3C, + FBNIC_TLV_MSG_ID_TSENE_READ_RESP = 0x3D, }; #define FBNIC_FW_CAP_RESP_VERSION_MAJOR CSR_GENMASK(31, 24) @@ -130,6 +138,13 @@ enum { FBNIC_FW_LINK_FEC_BASER = 3, }; +enum { + FBNIC_TSENE_THERM = 0x0, + FBNIC_TSENE_VOLT = 0x1, + FBNIC_TSENE_ERROR = 0x2, + FBNIC_TSENE_MSG_MAX +}; + enum { FBNIC_FW_OWNERSHIP_FLAG = 0x0, FBNIC_FW_OWNERSHIP_MSG_MAX diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c index 7b654d0a6dac..14291401f463 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c @@ -686,6 +686,77 @@ fbnic_mac_get_eth_mac_stats(struct fbnic_dev *fbd, bool reset, MAC_STAT_TX_BROADCAST); } +static int fbnic_mac_get_sensor_asic(struct fbnic_dev *fbd, int id, + long *val) +{ + struct fbnic_fw_completion *fw_cmpl; + int err = 0, retries = 5; + s32 *sensor; + + fw_cmpl = kzalloc(sizeof(*fw_cmpl), GFP_KERNEL); + if (!fw_cmpl) + return -ENOMEM; + + /* Initialize completion and queue it for FW to process */ + fbnic_fw_init_cmpl(fw_cmpl, FBNIC_TLV_MSG_ID_TSENE_READ_RESP); + + switch (id) { + case FBNIC_SENSOR_TEMP: + sensor = &fw_cmpl->u.tsene.millidegrees; + break; + case FBNIC_SENSOR_VOLTAGE: + sensor = &fw_cmpl->u.tsene.millivolts; + break; + default: + err = -EINVAL; + goto exit_free; + } + + err = fbnic_fw_xmit_tsene_read_msg(fbd, fw_cmpl); + if (err) { + dev_err(fbd->dev, + "Failed to transmit TSENE read msg, err %d\n", + err); + goto exit_free; + } + + /* Allow 2 seconds for reply, resend and try up to 5 times */ + while (!wait_for_completion_timeout(&fw_cmpl->done, 2 * HZ)) { + retries--; + + if (retries == 0) { + dev_err(fbd->dev, + "Timed out waiting for TSENE read\n"); + err = -ETIMEDOUT; + goto exit_cleanup; + } + + err = fbnic_fw_xmit_tsene_read_msg(fbd, NULL); + if (err) { + dev_err(fbd->dev, + "Failed to transmit TSENE read msg, err %d\n", + err); + goto exit_cleanup; + } + } + + /* Handle error returned by firmware */ + if (fw_cmpl->result) { + err = fw_cmpl->result; + dev_err(fbd->dev, "%s: Firmware returned error %d\n", + __func__, err); + goto exit_cleanup; + } + + *val = *sensor; +exit_cleanup: + fbnic_fw_clear_compl(fbd); +exit_free: + fbnic_fw_put_cmpl(fw_cmpl); + + return err; +} + static const struct fbnic_mac fbnic_mac_asic = { .init_regs = fbnic_mac_init_regs, .pcs_enable = fbnic_pcs_enable_asic, @@ -695,6 +766,7 @@ static const struct fbnic_mac fbnic_mac_asic = { .get_eth_mac_stats = fbnic_mac_get_eth_mac_stats, .link_down = fbnic_mac_link_down_asic, .link_up = fbnic_mac_link_up_asic, + .get_sensor = fbnic_mac_get_sensor_asic, }; /** diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_mac.h b/drivers/net/ethernet/meta/fbnic/fbnic_mac.h index 476239a9d381..05a591653e09 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_mac.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_mac.h @@ -47,6 +47,11 @@ enum { #define FBNIC_LINK_MODE_PAM4 (FBNIC_LINK_50R1) #define FBNIC_LINK_MODE_MASK (FBNIC_LINK_AUTO - 1) +enum fbnic_sensor_id { + FBNIC_SENSOR_TEMP, /* Temp in millidegrees Centigrade */ + FBNIC_SENSOR_VOLTAGE, /* Voltage in millivolts */ +}; + /* This structure defines the interface hooks for the MAC. The MAC hooks * will be configured as a const struct provided with a set of function * pointers. @@ -83,6 +88,8 @@ struct fbnic_mac { void (*link_down)(struct fbnic_dev *fbd); void (*link_up)(struct fbnic_dev *fbd, bool tx_pause, bool rx_pause); + + int (*get_sensor)(struct fbnic_dev *fbd, int id, long *val); }; int fbnic_mac_init(struct fbnic_dev *fbd); From patchwork Tue Jan 14 00:07:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanman Pradhan X-Patchwork-Id: 13938249 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5B508C0B; Tue, 14 Jan 2025 00:07:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736813232; cv=none; b=gJ7EI+2gbWmfUHmE8taZzEAefxjSbVzrbyHJOiqMn2TymVNeuZf7N5gbEnL1fBF8e4Wx5uvYLnZRIAoWSIvFw40VfRVdHbEiBWtu79XvXCSabcGtqR/P6/uYYQa3ORIid/yheo6UDhJtDOxgcZAebQGi3L2qoqJQpqSAjqvaOXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736813232; c=relaxed/simple; bh=xdE5TPZZ7Jibsnu9ChJ0E+7B5izKvQ0wVrCKOhI9BME=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r4XrKVBJS+GBBS559Oi4/YPj/RXxGIEEboq0Np4MT46RB3Zw09IAm7fpfcdad6ttMWCbzkVar4OAk1lS6rpmnPewgSZyzIXXbK+fhLkNQfUHGQlgdqwgYWVgggpFx9Crjb0SeUpr/oct1EZmGv2bDzNjqGAhHEBQMmKn+R+Vu3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mUjQQpq7; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mUjQQpq7" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-21a7ed0155cso83976425ad.3; Mon, 13 Jan 2025 16:07:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736813230; x=1737418030; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JNaWdNFIeTj7eNqwtykAY+wvCCFWg9mpXJ37B1tl9Lk=; b=mUjQQpq76xGxWPg72jf0PV4ER3kRelTjpUSz9hfzefZ2CCypM6Xn9EEEclFCzOHtPp g6VS1i3BsA24vCNve8SIHkWj+aotvGWsWRaQsNe57U+I1K2iLFeplslTQpg0gKsrSPC5 0wCdyIIzjUAlrjaVtmPf07mo004FWFBxVEmrz/n3qG4bI9kdSXhROPyp9IQ9r8IJw0Zo GsU2QXjuLUxiH0mM0rMgz5PIQqHYH29aZ6hJ4tkWFmkJoiuRAdSkDnbdIxcM2Iam74rb za6yYRMcOFN9gIyFnmHPWWQYgY8h25sZdtJJX/OTpXzR0+89fFqYKQUaitJXInBhU8Sn SR4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736813230; x=1737418030; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JNaWdNFIeTj7eNqwtykAY+wvCCFWg9mpXJ37B1tl9Lk=; b=lTAmNMrBcaPR0yK6Wg2bRM74c42XuDLvkf8wdSoRx1KvZQNmWTvXoFF1PtU1z+3ypM 9yJCSWtOXk/G40y7Og6msdcpeJnfFOoxJqGv6jV32d7NS7cxEtWiJlOgw31mkqMdiL/b PLGMD5vSye4YOP56XTUIgKl0o/DjJgOjKgIspbERBV30TFbwma/Wqq0agRgockL1fgZS A2d/aUFBX22J26kPuHTqRbfYdgXPZlbLqGF+L6X5XH4QWPgoBG6Nvn0oh2RZ+NcY+RQb lH4dLzujcbWgKR78xL1b5jN1IsMH3ph+W+rME2r6bAehJgnDmu0iGW3+xHAp7CdZwol4 sWKA== X-Forwarded-Encrypted: i=1; AJvYcCUii1cRNVAtwwYwL0aPatb4fzf4qoNLmpdD++b0oNvJUgPj46aot60LDyLuwdHIvMV4pMTcL6GjZq6ro/6y@vger.kernel.org, AJvYcCX7PudBXq9m2ublt+t5f2DBIeHlp+o5BZLjSf8G1fgi/ArC/7rQUl3XCVB9sHeasGupid0AM4KpzrUXVQ==@vger.kernel.org X-Gm-Message-State: AOJu0YwlBHI35wWavIlrCeOMX8OJQVVGgBYRX55D9EvIc46J4qgPRJ6s WX8dkh18iRf+u1E5Qcnt8oFOSGjkp2S5SoHGQ4HQkXVhpDQSZiqpEttGomsYKTY= X-Gm-Gg: ASbGncvoaAC3SeamKYsXfLo2xMdd0/2hxrlK5EkDS+kKJfjqwRmXzO4Q+6hxUxhmLXB TvlYIAPv15xGKhAUkV/6oRi9smtIwGC5CkwJA4A856XC6G3V1XcIobcKuEK3QLBQufPg9LqRsfr RWeUEwxobvJqizmHEnPtC3c51sF2M/O4CIc6SRfwNb+csPOC92VtWfyTbUgB0HzUr6q/MFOgE+6 Phq0BCaH7D1UhpqmHy1bVWOrxrhHMlPqJlAgfLYHYSikxKVO80iAOw= X-Google-Smtp-Source: AGHT+IG6rGCMxUTPfjgPXUbeGzRJBTT2qh0Iz4HxqJ765ewebhM4jJ/pQxh4PxVaEe73NbeEE8rMNw== X-Received: by 2002:a05:6a20:6a0a:b0:1e0:d380:fe71 with SMTP id adf61e73a8af0-1e88cf079f0mr37406576637.0.1736813229923; Mon, 13 Jan 2025 16:07:09 -0800 (PST) Received: from localhost ([2a03:2880:ff:12::]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-a317a07cce2sm7471752a12.4.2025.01.13.16.07.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 16:07:09 -0800 (PST) From: Sanman Pradhan To: netdev@vger.kernel.org Cc: alexanderduyck@fb.com, kuba@kernel.org, kernel-team@meta.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, kalesh-anakkur.purayil@broadcom.com, linux@roeck-us.net, mohsin.bashr@gmail.com, jdelvare@suse.com, horms@kernel.org, suhui@nfschina.com, linux-kernel@vger.kernel.org, vadim.fedorenko@linux.dev, linux-hwmon@vger.kernel.org, sanmanpradhan@meta.com, sanman.p211993@gmail.com Subject: [PATCH net-next 3/3] eth: fbnic: Add hardware monitoring support via HWMON interface Date: Mon, 13 Jan 2025 16:07:05 -0800 Message-ID: <20250114000705.2081288-4-sanman.p211993@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250114000705.2081288-1-sanman.p211993@gmail.com> References: <20250114000705.2081288-1-sanman.p211993@gmail.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch adds support for hardware monitoring to the fbnic driver, allowing for temperature and voltage sensor data to be exposed to userspace via the HWMON interface. The driver registers a HWMON device and provides callbacks for reading sensor data, enabling system admins to monitor the health and operating conditions of fbnic. Signed-off-by: Sanman Pradhan Reviewed-by: Michal Swiatkowski --- drivers/net/ethernet/meta/fbnic/Makefile | 1 + drivers/net/ethernet/meta/fbnic/fbnic.h | 4 + drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c | 81 +++++++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_pci.c | 3 + 4 files changed, 89 insertions(+) create mode 100644 drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c -- 2.43.5 diff --git a/drivers/net/ethernet/meta/fbnic/Makefile b/drivers/net/ethernet/meta/fbnic/Makefile index ea6214ca48e7..239b2258ec65 100644 --- a/drivers/net/ethernet/meta/fbnic/Makefile +++ b/drivers/net/ethernet/meta/fbnic/Makefile @@ -13,6 +13,7 @@ fbnic-y := fbnic_csr.o \ fbnic_ethtool.o \ fbnic_fw.o \ fbnic_hw_stats.o \ + fbnic_hwmon.o \ fbnic_irq.o \ fbnic_mac.o \ fbnic_netdev.o \ diff --git a/drivers/net/ethernet/meta/fbnic/fbnic.h b/drivers/net/ethernet/meta/fbnic/fbnic.h index ad8ac5ac7be9..14751f16e125 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic.h @@ -24,6 +24,7 @@ struct fbnic_dev { struct device *dev; struct net_device *netdev; struct dentry *dbg_fbd; + struct device *hwmon; u32 __iomem *uc_addr0; u32 __iomem *uc_addr4; @@ -150,6 +151,9 @@ void fbnic_devlink_unregister(struct fbnic_dev *fbd); int fbnic_fw_enable_mbx(struct fbnic_dev *fbd); void fbnic_fw_disable_mbx(struct fbnic_dev *fbd); +void fbnic_hwmon_register(struct fbnic_dev *fbd); +void fbnic_hwmon_unregister(struct fbnic_dev *fbd); + int fbnic_pcs_irq_enable(struct fbnic_dev *fbd); void fbnic_pcs_irq_disable(struct fbnic_dev *fbd); diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c b/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c new file mode 100644 index 000000000000..def8598aceec --- /dev/null +++ b/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#include + +#include "fbnic.h" +#include "fbnic_mac.h" + +static int fbnic_hwmon_sensor_id(enum hwmon_sensor_types type) +{ + if (type == hwmon_temp) + return FBNIC_SENSOR_TEMP; + if (type == hwmon_in) + return FBNIC_SENSOR_VOLTAGE; + + return -EOPNOTSUPP; +} + +static umode_t fbnic_hwmon_is_visible(const void *drvdata, + enum hwmon_sensor_types type, + u32 attr, int channel) +{ + if (type == hwmon_temp && attr == hwmon_temp_input) + return 0444; + if (type == hwmon_in && attr == hwmon_in_input) + return 0444; + + return 0; +} + +static int fbnic_hwmon_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + struct fbnic_dev *fbd = dev_get_drvdata(dev); + const struct fbnic_mac *mac = fbd->mac; + int id; + + id = fbnic_hwmon_sensor_id(type); + return id < 0 ? id : mac->get_sensor(fbd, id, val); +} + +static const struct hwmon_ops fbnic_hwmon_ops = { + .is_visible = fbnic_hwmon_is_visible, + .read = fbnic_hwmon_read, +}; + +static const struct hwmon_channel_info *fbnic_hwmon_info[] = { + HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT), + HWMON_CHANNEL_INFO(in, HWMON_I_INPUT), + NULL +}; + +static const struct hwmon_chip_info fbnic_chip_info = { + .ops = &fbnic_hwmon_ops, + .info = fbnic_hwmon_info, +}; + +void fbnic_hwmon_register(struct fbnic_dev *fbd) +{ + if (!IS_REACHABLE(CONFIG_HWMON)) + return; + + fbd->hwmon = hwmon_device_register_with_info(fbd->dev, "fbnic", + fbd, &fbnic_chip_info, + NULL); + if (IS_ERR(fbd->hwmon)) { + dev_notice(fbd->dev, + "Failed to register hwmon device %pe\n", + fbd->hwmon); + fbd->hwmon = NULL; + } +} + +void fbnic_hwmon_unregister(struct fbnic_dev *fbd) +{ + if (!IS_REACHABLE(CONFIG_HWMON) || !fbd->hwmon) + return; + + hwmon_device_unregister(fbd->hwmon); + fbd->hwmon = NULL; +} diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_pci.c b/drivers/net/ethernet/meta/fbnic/fbnic_pci.c index 2c96980d150d..6cbbc2ee3e1f 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_pci.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_pci.c @@ -296,6 +296,8 @@ static int fbnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) /* Capture snapshot of hardware stats so netdev can calculate delta */ fbnic_reset_hw_stats(fbd); + fbnic_hwmon_register(fbd); + if (!fbd->dsn) { dev_warn(&pdev->dev, "Reading serial number failed\n"); goto init_failure_mode; @@ -358,6 +360,7 @@ static void fbnic_remove(struct pci_dev *pdev) fbnic_netdev_free(fbd); } + fbnic_hwmon_unregister(fbd); fbnic_dbg_fbd_exit(fbd); fbnic_devlink_unregister(fbd); fbnic_fw_disable_mbx(fbd);