From patchwork Mon Sep 9 16:46:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1982695 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X2Xmy0d95z1y1p for ; Tue, 10 Sep 2024 02:47:13 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1snhXZ-0004dN-OQ; Mon, 09 Sep 2024 16:47:01 +0000 Received: from mail-pl1-f177.google.com ([209.85.214.177]) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1snhXY-0004c4-14 for kernel-team@lists.ubuntu.com; Mon, 09 Sep 2024 16:47:00 +0000 Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2054e22ce3fso39423345ad.2 for ; Mon, 09 Sep 2024 09:46:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725900418; x=1726505218; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jjLPAoGHn5QRTuzExWMHQugtbsdvt5zJIjlddwrIEpI=; b=uKYuGRSUvCENoasLhZTdy5pW1w5H29AvnfsSohd2nJN6fDh3aj34OHKtvKDZnQpnuB +wj4Nt/1HSsvs3EDACUrADAu8EtLUF2NCA19MDuxI8Vt84ck3yDyAgJgGSPeLX/XWkF8 9KuiM7qmvrQRtnpaNbsIltzDHfgmp6lj7LhzaJCrm3linHyV880n6ndihtvvOpFdW65h d4l/QBT3AwC/49fDvdMSYFX4gPpNvvIuw1lIpSTlfFni1xHOzhjS8vQQoWQXm2Q37ghd EPOTuBREObMqP3D+U7y3vzI7ozZ1Hwud620BX5R5Mq5P1QGsifMtZgeveGlpUnqwsw9P 1stw== X-Gm-Message-State: AOJu0Yw+qQ76WXhaCYXH0y++3H5azJf46zN4D7ZDauh9u0/NfpMaTZam +F/o+QdG5H8PCU/KI6Rro2+3j9PaoKBIXx+IcyZSTfCSZbVpHbNzFiCzWg== X-Google-Smtp-Source: AGHT+IGUjQeoyBRrqXl6LwXgLT+1UOXgHkn6oDOOhfmtAJgQCSWgyia6elOJG7rjwRV4Y5X/1Xdc4A== X-Received: by 2002:a17:902:e74a:b0:205:7b04:ddf2 with SMTP id d9443c01a7336-206f053b49bmr101083705ad.29.1725900417952; Mon, 09 Sep 2024 09:46:57 -0700 (PDT) Received: from localhost.localdomain (125-229-129-140.hinet-ip.hinet.net. [125.229.129.140]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20710f1f5cdsm35890535ad.227.2024.09.09.09.46.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 09:46:57 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/3][SRU][Unstable][Oracular] Documentation: hid: intel-ish-hid: Add vendor custom firmware loading Date: Tue, 10 Sep 2024 00:46:10 +0800 Message-ID: <20240909164612.3574008-2-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240909164612.3574008-1-vicamo.yang@canonical.com> References: <20240909164612.3574008-1-vicamo.yang@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.214.177; envelope-from=vicamo@gmail.com; helo=mail-pl1-f177.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Zhang Lixu BugLink: https://bugs.launchpad.net/bugs/2071698 Add ISH firmware loading guidelines for vendor custom firmware. Signed-off-by: Zhang Lixu Acked-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina (cherry picked from commit 87de1615194eeb43b14cf5355ede3bd2115e0ff4 linux-next) Signed-off-by: You-Sheng Yang --- Documentation/hid/intel-ish-hid.rst | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Documentation/hid/intel-ish-hid.rst b/Documentation/hid/intel-ish-hid.rst index 55cbaa719a794..2adc174fb576c 100644 --- a/Documentation/hid/intel-ish-hid.rst +++ b/Documentation/hid/intel-ish-hid.rst @@ -404,6 +404,35 @@ For more detailed information, please refer to the flow descriptions provided be | ISHTP Driver | | ISH Bootloader | +---------------+ +-----------------+ +Vendor Custom Firmware Loading +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The firmware running inside ISH can be provided by Intel or developed by vendors using the Firmware Development Kit (FDK) provided by Intel. +Intel will upstream the Intel-built firmware to the ``linux-firmware.git`` repository, located under the path ``intel/ish/``. For the Lunar Lake platform, the Intel-built ISH firmware will be named ``ish_lnlm.bin``. +Vendors who wish to upstream their custom firmware should follow these guidelines for naming their firmware files: + +- The firmware filename should use one of the following patterns: + + - ``ish_${intel_plat_gen}_${SYS_VENDOR_CRC32}_${PRODUCT_NAME_CRC32}_${PRODUCT_SKU_CRC32}.bin`` + - ``ish_${intel_plat_gen}_${SYS_VENDOR_CRC32}_${PRODUCT_SKU_CRC32}.bin`` + - ``ish_${intel_plat_gen}_${SYS_VENDOR_CRC32}_${PRODUCT_NAME_CRC32}.bin`` + - ``ish_${intel_plat_gen}_${SYS_VENDOR_CRC32}.bin`` + +- ``${intel_plat_gen}`` indicates the Intel platform generation (e.g., ``lnlm`` for Lunar Lake) and must not exceed 8 characters in length. +- ``${SYS_VENDOR_CRC32}`` is the CRC32 checksum of the ``sys_vendor`` value from the DMI field ``DMI_SYS_VENDOR``. +- ``${PRODUCT_NAME_CRC32}`` is the CRC32 checksum of the ``product_name`` value from the DMI field ``DMI_PRODUCT_NAME``. +- ``${PRODUCT_SKU_CRC32}`` is the CRC32 checksum of the ``product_sku`` value from the DMI field ``DMI_PRODUCT_SKU``. + +During system boot, the ISH Linux driver will attempt to load the firmware in the following order, prioritizing custom firmware with more precise matching patterns: + +1. ``intel/ish/ish_${intel_plat_gen}_${SYS_VENDOR_CRC32}_${PRODUCT_NAME_CRC32}_${PRODUCT_SKU_CRC32}.bin`` +2. ``intel/ish/ish_${intel_plat_gen}_${SYS_VENDOR_CRC32}_${PRODUCT_SKU_CRC32}.bin`` +3. ``intel/ish/ish_${intel_plat_gen}_${SYS_VENDOR_CRC32}_${PRODUCT_NAME_CRC32}.bin`` +4. ``intel/ish/ish_${intel_plat_gen}_${SYS_VENDOR_CRC32}.bin`` +5. ``intel/ish/ish_${intel_plat_gen}.bin`` + +The driver will load the first matching firmware and skip the rest. If no matching firmware is found, it will proceed to the next pattern in the specified order. If all searches fail, the default Intel firmware, listed last in the order above, will be loaded. + ISH Debugging ------------- From patchwork Mon Sep 9 16:46:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1982696 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X2Xn20zz6z1y1l for ; Tue, 10 Sep 2024 02:47:18 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1snhXh-0004fg-VE; Mon, 09 Sep 2024 16:47:09 +0000 Received: from mail-pl1-f173.google.com ([209.85.214.173]) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1snhXg-0004eU-3h for kernel-team@lists.ubuntu.com; Mon, 09 Sep 2024 16:47:08 +0000 Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2055136b612so54469915ad.0 for ; Mon, 09 Sep 2024 09:47:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725900426; x=1726505226; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iY4cm0W/faA1AI6/anht3i0GzBA3jpmxHsxiVSBUhcg=; b=YFxY1qn3fMURBHRSdZDD8W9OT3xkVmtns9QLDd5t+9+o5wvEOWr/+eS3fMxOxkLBXc d3NtCUQ0kNA/hMXmWloWhayRhpBaQ+KAOOvYbULVyKmx7XR/3jMuYuCoMESKTLdPOtx1 q0AEe1GrKNPqFUcd6K7gqx114DAhcXOzSzDsolk7D3nFgPE8HtmrEO8lo/bhCLKkBlf2 NbIlL9+VlJQw109sWhXsAuDWnvg2sOYot/Q+bDi2sfC20/ktuAEZHn5ssWgbBBOJslO6 SfxUrIIpNQS18hrqFVNvtAj/EFsMC6Kx43UoryPyRsfcIlcWPGSt8dmdCfi2O/H/1g78 UP1w== X-Gm-Message-State: AOJu0Yybqm9zeNk0aV7p+wIls7OLEDHa/I6wEbQDK0L6jHF7QCZ8pnm+ +47V5ejv16SX78cLXjhyVOJhXehOiHuhFFm1fH7KJalK7/nIAL+laSw3kw== X-Google-Smtp-Source: AGHT+IEkebRuSTg8wDyWgMusAfxJfpHvE3/08Ni8qncy41pOvMhuUHDGF5/7Z4ycsYfSgR/eYQCuGA== X-Received: by 2002:a17:902:e5d1:b0:202:38d8:161 with SMTP id d9443c01a7336-206f062465fmr154661515ad.57.1725900426028; Mon, 09 Sep 2024 09:47:06 -0700 (PDT) Received: from localhost.localdomain (125-229-129-140.hinet-ip.hinet.net. [125.229.129.140]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20710f1f5cdsm35890535ad.227.2024.09.09.09.47.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 09:47:05 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/3][SRU][Unstable][Oracular] HID: intel-ish-hid: Use CPU generation string in driver_data Date: Tue, 10 Sep 2024 00:46:11 +0800 Message-ID: <20240909164612.3574008-3-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240909164612.3574008-1-vicamo.yang@canonical.com> References: <20240909164612.3574008-1-vicamo.yang@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.214.173; envelope-from=vicamo@gmail.com; helo=mail-pl1-f173.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Zhang Lixu BugLink: https://bugs.launchpad.net/bugs/2071698 ISH allows vendors to customize ISH firmware. To differentiate different vendors and load the correct firmware, Intel defined a firmware file name format. As part of the filename, there is a "generation" string. To load correct format the driver must know the generation name to create file name. In the absence of any vendor specific firmware, default ISH firmware is loaded. Currently full ISH firmware file name is stored as part of driver data. This file name already includes the generation name. For example, for Lunar Lake, the name is ish_lnlm.bin, where "lnlm" is the generation. So instead of storing both generation name and ISH default firmware file name, just store generation name and create the default ISH firmware file name string during initialization. No functional changes are expected. Signed-off-by: Zhang Lixu Acked-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina (cherry picked from commit 641361538b68de29d97cc7bf535e50176dbdcfbf linux-next) Signed-off-by: You-Sheng Yang --- drivers/hid/intel-ish-hid/ipc/pci-ish.c | 8 ++++--- drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h | 8 ++++--- drivers/hid/intel-ish-hid/ishtp/loader.c | 23 ++++++++++++++++++--- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c b/drivers/hid/intel-ish-hid/ipc/pci-ish.c index f82428d7f6c3d..f20463082dc40 100644 --- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c +++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c @@ -28,11 +28,13 @@ enum ishtp_driver_data_index { ISHTP_DRIVER_DATA_LNL_M, }; -#define ISH_FW_FILENAME_LNL_M "intel/ish/ish_lnlm.bin" +#define ISH_FW_GEN_LNL_M "lnlm" + +#define ISH_FIRMWARE_PATH(gen) "intel/ish/ish_" gen ".bin" static struct ishtp_driver_data ishtp_driver_data[] = { [ISHTP_DRIVER_DATA_LNL_M] = { - .fw_filename = ISH_FW_FILENAME_LNL_M, + .fw_generation = ISH_FW_GEN_LNL_M, }, }; @@ -397,4 +399,4 @@ MODULE_AUTHOR("Srinivas Pandruvada "); MODULE_DESCRIPTION("Intel(R) Integrated Sensor Hub PCI Device Driver"); MODULE_LICENSE("GPL"); -MODULE_FIRMWARE(ISH_FW_FILENAME_LNL_M); +MODULE_FIRMWARE(ISH_FIRMWARE_PATH(ISH_FW_GEN_LNL_M)); diff --git a/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h b/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h index 181838c3d7ac9..cdacce0a4c9d7 100644 --- a/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h +++ b/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h @@ -129,13 +129,15 @@ struct ishtp_hw_ops { * ISHTP device instance. It allows for the storage of data that is unique to * a particular driver or hardware variant. * - * @fw_filename: The firmware filename associated with a specific hardware + * @fw_generation: The generation name associated with a specific hardware * variant of the Intel Integrated Sensor Hub (ISH). This allows * the driver to load the correct firmware based on the device's - * hardware variant. + * hardware variant. For example, "lnlm" for the Lunar Lake-M + * platform. The generation name must not exceed 8 characters + * in length. */ struct ishtp_driver_data { - char *fw_filename; + char *fw_generation; }; /** diff --git a/drivers/hid/intel-ish-hid/ishtp/loader.c b/drivers/hid/intel-ish-hid/ishtp/loader.c index fcca070bdecbe..ff11ee4e38ede 100644 --- a/drivers/hid/intel-ish-hid/ishtp/loader.c +++ b/drivers/hid/intel-ish-hid/ishtp/loader.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -192,6 +193,23 @@ static int prepare_dma_bufs(struct ishtp_device *dev, return 0; } +#define ISH_FW_FILE_DEFAULT_FMT "intel/ish/ish_%s.bin" + +#define ISH_FW_FILENAME_LEN_MAX 56 + +static int request_ish_firmware(const struct firmware **firmware_p, + struct device *dev) +{ + struct ishtp_device *ishtp = dev_get_drvdata(dev); + const char *gen; + char filename[ISH_FW_FILENAME_LEN_MAX]; + + gen = ishtp->driver_data->fw_generation; + snprintf(filename, sizeof(filename), ISH_FW_FILE_DEFAULT_FMT, gen); + + return request_firmware(firmware_p, filename, dev); +} + /** * ishtp_loader_work() - Load the ISHTP firmware * @work: The work structure @@ -220,7 +238,6 @@ void ishtp_loader_work(struct work_struct *work) struct loader_xfer_query query = { .header = cpu_to_le32(query_hdr.val32), }; struct loader_start start = { .header = cpu_to_le32(start_hdr.val32), }; union loader_recv_message recv_msg; - char *filename = dev->driver_data->fw_filename; const struct firmware *ish_fw; void *dma_bufs[FRAGMENT_MAX_NUM] = {}; u32 fragment_size; @@ -228,9 +245,9 @@ void ishtp_loader_work(struct work_struct *work) int retry = ISHTP_LOADER_RETRY_TIMES; int rv; - rv = request_firmware(&ish_fw, filename, dev->devc); + rv = request_ish_firmware(&ish_fw, dev->devc); if (rv < 0) { - dev_err(dev->devc, "request firmware %s failed:%d\n", filename, rv); + dev_err(dev->devc, "request ISH firmware failed:%d\n", rv); return; } From patchwork Mon Sep 9 16:46:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1982697 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X2Xn41sdrz1y1l for ; Tue, 10 Sep 2024 02:47:20 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1snhXk-0004i9-32; Mon, 09 Sep 2024 16:47:12 +0000 Received: from mail-pl1-f172.google.com ([209.85.214.172]) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1snhXh-0004ev-8F for kernel-team@lists.ubuntu.com; Mon, 09 Sep 2024 16:47:09 +0000 Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2068a7c9286so41577105ad.1 for ; Mon, 09 Sep 2024 09:47:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725900427; x=1726505227; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5sbExM16yrSoSW09AvzbhbosIAnZyKjRvx4qWQ9fQww=; b=uVk36lTeGlngvcs8/GPm/AYcQnfSJoK1NhZGo6XrymjrfVtYnfzHMuhvQSp8itSqhe c0zb1cbBao+GndFZsW045psVQ63v9SQyl5RtbS+BvzXP7RVh5v/32O3TSuKGzpvcRCdg ODAPU1AaL+PNaojdeRYJLrQwwNArodlQJWxwq5YlDiIXHVW4nz2x1v8EexfUahxb96yn 4oUC4zeVqVO9456RAT/HPyy7WrxeYh+RUzWwlC4eW1R0OwNKy/zRVvGrYi9ZN9WWHe1G g39skuiDKnsN3P2kIbtrpFcDqjhheZ0d3UmqoOQ6jsF49quA7M5lVJzwRTqBSht3k9yv 4Ztg== X-Gm-Message-State: AOJu0YyZ0EcLvAllZTL+QiSQ1YsCmE9//oWcOVo+rCb3dEnIu7EtoxBo jnjkf5l2gWqkikBSLpKLEq9UZF2GMY6ZWEz2WC2vZUBYKsvbD0+BeK1KyQ== X-Google-Smtp-Source: AGHT+IE6X6J4BOwaFSxApb0GWQHN1mA0ODJ11RYIuW/XsCehG1acKNHxQnYMgY9P5vFKWXQkj0UzSw== X-Received: by 2002:a17:902:cec1:b0:205:8407:6321 with SMTP id d9443c01a7336-206f04a01fcmr133554665ad.9.1725900427221; Mon, 09 Sep 2024 09:47:07 -0700 (PDT) Received: from localhost.localdomain (125-229-129-140.hinet-ip.hinet.net. [125.229.129.140]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20710f1f5cdsm35890535ad.227.2024.09.09.09.47.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 09:47:06 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 3/3][SRU][Unstable][Oracular] hid: intel-ish-hid: Add support for vendor customized firmware loading Date: Tue, 10 Sep 2024 00:46:12 +0800 Message-ID: <20240909164612.3574008-4-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240909164612.3574008-1-vicamo.yang@canonical.com> References: <20240909164612.3574008-1-vicamo.yang@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.214.172; envelope-from=vicamo@gmail.com; helo=mail-pl1-f172.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Zhang Lixu BugLink: https://bugs.launchpad.net/bugs/2071698 Enhance the firmware loader to support the loading of vendor-specific customized firmware for the Intel Integrated Sensor Hub (ISH). The loader now constructs firmware file names based on the DMI_SYS_VENDOR, DMI_PRODUCT_NAME, and DMI_PRODUCT_SKU information in Desktop Management Interface (DMI). The loader will attempt to load the firmware files following a specific naming convention in sequence. If successful, it will skip the remaining files. For more details, please refer to Documentation/hid/intel-ish-hid.rst. Signed-off-by: Zhang Lixu Acked-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina (cherry picked from commit aa4674c525e1e9a27f77e29fa71a4a5779a52ee4 linux-next) Signed-off-by: You-Sheng Yang --- drivers/hid/intel-ish-hid/ipc/pci-ish.c | 2 + drivers/hid/intel-ish-hid/ishtp/loader.c | 104 ++++++++++++++++++++++- 2 files changed, 103 insertions(+), 3 deletions(-) diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c b/drivers/hid/intel-ish-hid/ipc/pci-ish.c index f20463082dc40..aae0d965b47b5 100644 --- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c +++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c @@ -31,6 +31,7 @@ enum ishtp_driver_data_index { #define ISH_FW_GEN_LNL_M "lnlm" #define ISH_FIRMWARE_PATH(gen) "intel/ish/ish_" gen ".bin" +#define ISH_FIRMWARE_PATH_ALL "intel/ish/ish_*.bin" static struct ishtp_driver_data ishtp_driver_data[] = { [ISHTP_DRIVER_DATA_LNL_M] = { @@ -400,3 +401,4 @@ MODULE_DESCRIPTION("Intel(R) Integrated Sensor Hub PCI Device Driver"); MODULE_LICENSE("GPL"); MODULE_FIRMWARE(ISH_FIRMWARE_PATH(ISH_FW_GEN_LNL_M)); +MODULE_FIRMWARE(ISH_FIRMWARE_PATH_ALL); diff --git a/drivers/hid/intel-ish-hid/ishtp/loader.c b/drivers/hid/intel-ish-hid/ishtp/loader.c index ff11ee4e38ede..f76c4437a1f5f 100644 --- a/drivers/hid/intel-ish-hid/ishtp/loader.c +++ b/drivers/hid/intel-ish-hid/ishtp/loader.c @@ -35,8 +35,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -193,21 +195,117 @@ static int prepare_dma_bufs(struct ishtp_device *dev, return 0; } +#define ISH_FW_FILE_VENDOR_NAME_SKU_FMT "intel/ish/ish_%s_%08x_%08x_%08x.bin" +#define ISH_FW_FILE_VENDOR_SKU_FMT "intel/ish/ish_%s_%08x_%08x.bin" +#define ISH_FW_FILE_VENDOR_NAME_FMT "intel/ish/ish_%s_%08x_%08x.bin" +#define ISH_FW_FILE_VENDOR_FMT "intel/ish/ish_%s_%08x.bin" #define ISH_FW_FILE_DEFAULT_FMT "intel/ish/ish_%s.bin" #define ISH_FW_FILENAME_LEN_MAX 56 +#define ISH_CRC_INIT (~0u) +#define ISH_CRC_XOROUT (~0u) + +static int _request_ish_firmware(const struct firmware **firmware_p, + const char *name, struct device *dev) +{ + int ret; + + dev_dbg(dev, "Try to load firmware: %s\n", name); + ret = firmware_request_nowarn(firmware_p, name, dev); + if (!ret) + dev_info(dev, "load firmware: %s\n", name); + + return ret; +} + +/** + * request_ish_firmware() - Request and load the ISH firmware. + * @firmware_p: Pointer to the firmware image. + * @dev: Device for which firmware is being requested. + * + * This function attempts to load the Integrated Sensor Hub (ISH) firmware + * for the given device in the following order, prioritizing custom firmware + * with more precise matching patterns: + * + * ish_${fw_generation}_${SYS_VENDOR_CRC32}_$(PRODUCT_NAME_CRC32)_${PRODUCT_SKU_CRC32}.bin + * ish_${fw_generation}_${SYS_VENDOR_CRC32}_${PRODUCT_SKU_CRC32}.bin + * ish_${fw_generation}_${SYS_VENDOR_CRC32}_$(PRODUCT_NAME_CRC32).bin + * ish_${fw_generation}_${SYS_VENDOR_CRC32}.bin + * ish_${fw_generation}.bin + * + * The driver will load the first matching firmware and skip the rest. If no + * matching firmware is found, it will proceed to the next pattern in the + * specified order. If all searches fail, the default Intel firmware, listed + * last in the order above, will be loaded. + * + * The firmware file name is constructed using CRC32 checksums of strings. + * This is done to create a valid file name that does not contain spaces + * or special characters which may be present in the original strings. + * + * The CRC-32 algorithm uses the following parameters: + * Poly: 0x04C11DB7 + * Init: 0xFFFFFFFF + * RefIn: true + * RefOut: true + * XorOut: 0xFFFFFFFF + * + * Return: 0 on success, negative error code on failure. + */ static int request_ish_firmware(const struct firmware **firmware_p, struct device *dev) { + const char *gen, *sys_vendor, *product_name, *product_sku; struct ishtp_device *ishtp = dev_get_drvdata(dev); - const char *gen; + u32 vendor_crc, name_crc, sku_crc; char filename[ISH_FW_FILENAME_LEN_MAX]; + int ret; gen = ishtp->driver_data->fw_generation; - snprintf(filename, sizeof(filename), ISH_FW_FILE_DEFAULT_FMT, gen); + sys_vendor = dmi_get_system_info(DMI_SYS_VENDOR); + product_name = dmi_get_system_info(DMI_PRODUCT_NAME); + product_sku = dmi_get_system_info(DMI_PRODUCT_SKU); + + if (sys_vendor) + vendor_crc = crc32(ISH_CRC_INIT, sys_vendor, strlen(sys_vendor)) ^ ISH_CRC_XOROUT; + if (product_name) + name_crc = crc32(ISH_CRC_INIT, product_name, strlen(product_name)) ^ ISH_CRC_XOROUT; + if (product_sku) + sku_crc = crc32(ISH_CRC_INIT, product_sku, strlen(product_sku)) ^ ISH_CRC_XOROUT; + + if (sys_vendor && product_name && product_sku) { + snprintf(filename, sizeof(filename), ISH_FW_FILE_VENDOR_NAME_SKU_FMT, gen, + vendor_crc, name_crc, sku_crc); + ret = _request_ish_firmware(firmware_p, filename, dev); + if (!ret) + return 0; + } + + if (sys_vendor && product_sku) { + snprintf(filename, sizeof(filename), ISH_FW_FILE_VENDOR_SKU_FMT, gen, vendor_crc, + sku_crc); + ret = _request_ish_firmware(firmware_p, filename, dev); + if (!ret) + return 0; + } - return request_firmware(firmware_p, filename, dev); + if (sys_vendor && product_name) { + snprintf(filename, sizeof(filename), ISH_FW_FILE_VENDOR_NAME_FMT, gen, vendor_crc, + name_crc); + ret = _request_ish_firmware(firmware_p, filename, dev); + if (!ret) + return 0; + } + + if (sys_vendor) { + snprintf(filename, sizeof(filename), ISH_FW_FILE_VENDOR_FMT, gen, vendor_crc); + ret = _request_ish_firmware(firmware_p, filename, dev); + if (!ret) + return 0; + } + + snprintf(filename, sizeof(filename), ISH_FW_FILE_DEFAULT_FMT, gen); + return _request_ish_firmware(firmware_p, filename, dev); } /**