From patchwork Thu Aug 15 02:09:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Lixu X-Patchwork-Id: 819591 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 0132C8F6D for ; Thu, 15 Aug 2024 02:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723687816; cv=none; b=Qiil93OYlU6ml01gIJ1UwCta/gopuH2PoJPrtKLa/1JX9cx0uak5OXbpc9t0ZKFiTgA19AboqRuGC2r0gBZp3uOR9AP0i5PoQzOHog1HbpM9012ie5JCMWYuAhBzTC+Xszp+FTGnwmgrirhXffZamU40rZpfdT8I/hpMlm+7NUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723687816; c=relaxed/simple; bh=NPCHo1P97QcUOplo6nm44XwDM4ia3zlrYgn6JHMPR/w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fvHxgJakZi6AHaLy8HUyMclxdxa8zKK0oygpJYy5sUuCiOGe28aJEjff/qp+kywcikiOi+0SgFF9fkvKuk42rmItuMW9r9SHCBOvEs5T5HHCHdCAOACBDWSYFssP3uYq6F5WIZ1b1tzlmhHfda34upccohERYGRoaFXruWp8lzs= 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=UdAJhW0h; arc=none smtp.client-ip=198.175.65.19 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="UdAJhW0h" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723687815; x=1755223815; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NPCHo1P97QcUOplo6nm44XwDM4ia3zlrYgn6JHMPR/w=; b=UdAJhW0hUzWI0bNICTcJGze54G6XhOCaUw6T8i9RGY8HUSTjzLYTpMfu hpzlU9a4rGIeHO5U9XAXMrJTxc8N6wLWcjNYzA+ULU3Y6BUi5g1DFaIo0 G4b2Wi0W2kd3eae8wHHlojshQxqsRHqfEV7TYRwHA9JiDSnDXrPCGiNhv s3sRmYjkowYlNdoP4yo0sJUAILAdmGdYPylYeSrGomEzZY8Q1Ai4gmjpy 03zBoIwNd/wjD/tNRIQQq+8yqjHQnbJ8kae+RUJbdH4Epo5gxM/4YJSwD hIZsFv2KoRxf1yzCKeKG5K8SwvK9mqu1VQPB+wZvczC5qswemjTUEaTmo w==; X-CSE-ConnectionGUID: DdmcHO9GTCSDxJv37PpIng== X-CSE-MsgGUID: YbV0d3lnT5+ZVqZIIV/dJA== X-IronPort-AV: E=McAfee;i="6700,10204,11164"; a="21796113" X-IronPort-AV: E=Sophos;i="6.10,147,1719903600"; d="scan'208";a="21796113" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2024 19:10:09 -0700 X-CSE-ConnectionGUID: Q4TYVX9WTiC9B4IYmgMVtg== X-CSE-MsgGUID: H4ax1UEHTzWWen3P+k2OjQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,147,1719903600"; d="scan'208";a="63635446" Received: from ipg-l-lixuzha.sh.intel.com ([10.239.153.157]) by fmviesa005.fm.intel.com with ESMTP; 14 Aug 2024 19:10:04 -0700 From: Zhang Lixu To: linux-input@vger.kernel.org, srinivas.pandruvada@linux.intel.com, jikos@kernel.org, benjamin.tissoires@redhat.com Cc: lixu.zhang@intel.com, hemin.han@intel.com, yoshi.wang@intel.com, even.xu@intel.com, ilpo.jarvinen@linux.intel.com Subject: [PATCH v2 1/3] Documentation: hid: intel-ish-hid: Add vendor custom firmware loading Date: Thu, 15 Aug 2024 10:09:59 +0800 Message-Id: <20240815021001.936277-2-lixu.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815021001.936277-1-lixu.zhang@intel.com> References: <20240815021001.936277-1-lixu.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add ISH firmware loading guidelines for vendor custom firmware. Signed-off-by: Zhang Lixu Acked-by: Srinivas Pandruvada --- 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 55cbaa719a79..2adc174fb576 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 Thu Aug 15 02:10:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Lixu X-Patchwork-Id: 819851 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 A520E9475 for ; Thu, 15 Aug 2024 02:10:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723687818; cv=none; b=gUzRYsq8kIhyZbrPFj57To0bcaZpbUkaniM/sEXzq8e0ukXwE1O32VRwUQtMIgOkqN0ZW4/wuj6NJ0X0F1iZGU3y2j5N+mjgK7JFFNejXzyEwF/e0cucVX+9nHr+IWbk3BT1YjCz6mffstSIl6JR5Er/3cZ1AtXTsXyZC5Otju8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723687818; c=relaxed/simple; bh=iLPwaTSVPkO34boqcOe77hU9ZzsSLX55jYi9pFMku8s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DJfYcXK/rQb2R6Dk1S1VWfC80x0aF/G1h/3hMqTP+6PMdRN3szMfOrVvblZiKD4Qpk4bNAF4bzgRW0kZN0+yPmOKFQF1vh2zdvWsJ6C22VXxwLJyUqsAswDW9Ke/GymBUF2nXg+OfqnoADcLZKDcqYbeiHlfvl6StinSp1mQveo= 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=lsqlpxDc; arc=none smtp.client-ip=198.175.65.19 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="lsqlpxDc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723687817; x=1755223817; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iLPwaTSVPkO34boqcOe77hU9ZzsSLX55jYi9pFMku8s=; b=lsqlpxDcwjWnh7GJm+yt8mD/aSQYi4t5c5R06e5RgIhQia2OgXCrJflZ 3pgpHUZFJ1pUZiAJztI2D1VwsaXq9EtcIvO3PdWZJGK8rf2Cobqm6b9Ay Usd5JzxG8gr+DWQEEcOjx1s2/gKdcXNbH5q9Oyaku8q1fLDNzPzHeEDIZ vCNP63VTnpB7hDEAXLCR/28hYdq1f5juk2EieiEfh3CqIKo1H0HDl7Jaf kZsItxVJbio8J9fBKOH2NrHVlnymZtATwjrYkKZBC50gaFrEzOKLrOJpZ oL2nNSf/CW7d4J8DqFs+bsmSUC1nUbIxGrJzptJvAjyPoe6lUlus0dMAw g==; X-CSE-ConnectionGUID: Nl2hwebnRr2ZNlpxv/SUEQ== X-CSE-MsgGUID: 9+cHjIUyTFGRrIhZWjEbwQ== X-IronPort-AV: E=McAfee;i="6700,10204,11164"; a="21796129" X-IronPort-AV: E=Sophos;i="6.10,147,1719903600"; d="scan'208";a="21796129" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2024 19:10:11 -0700 X-CSE-ConnectionGUID: RudW+FGJSE6RxiSQ+RZuGw== X-CSE-MsgGUID: 5j+yA5zaSryk+u5TT/bmbw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,147,1719903600"; d="scan'208";a="63635486" Received: from ipg-l-lixuzha.sh.intel.com ([10.239.153.157]) by fmviesa005.fm.intel.com with ESMTP; 14 Aug 2024 19:10:08 -0700 From: Zhang Lixu To: linux-input@vger.kernel.org, srinivas.pandruvada@linux.intel.com, jikos@kernel.org, benjamin.tissoires@redhat.com Cc: lixu.zhang@intel.com, hemin.han@intel.com, yoshi.wang@intel.com, even.xu@intel.com, ilpo.jarvinen@linux.intel.com Subject: [PATCH v2 2/3] HID: intel-ish-hid: Use CPU generation string in driver_data Date: Thu, 15 Aug 2024 10:10:00 +0800 Message-Id: <20240815021001.936277-3-lixu.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815021001.936277-1-lixu.zhang@intel.com> References: <20240815021001.936277-1-lixu.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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 f82428d7f6c3..f20463082dc4 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 181838c3d7ac..cdacce0a4c9d 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 fcca070bdecb..ff11ee4e38ed 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 Thu Aug 15 02:10:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Lixu X-Patchwork-Id: 819590 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 F3CF3BA20 for ; Thu, 15 Aug 2024 02:10:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723687818; cv=none; b=UmDRszKxdZUXkkbWnktL3CV7BaiOZqdHKLSbxalpmWeNlF8gRQoEA2id1lb2kJQKITr9drFrgKbr5i5wY1/HRzoa8wyieOwUsJXpjVFwE5z2ABcsVA+rMSkGGKO0HYAbcrg2rwp3kQ13glnyUNh2VPqXC2hb0sOL986bdpmjLHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723687818; c=relaxed/simple; bh=qy6rFW2Ca7IeP9dj5MULCx0bT5yDxg5gpzSH1XS5jNo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=h7VYggo9GmGh0xmkY0Y8ahQ7wPnRZ8Fp/0aK5g0quGdZh556P5PV7HFG+PgxoOcH7obR2tQzQdIeftsnhQvNEl1aIYzOv9/9Cg9xDYpyfU0n1/A1qBlse6Eb/D1/jCqn5plaVCJT+yNBYa12qhjhXfm6qcY9Z+e5K9CWs7dbfCA= 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=O57W7cQc; arc=none smtp.client-ip=198.175.65.19 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="O57W7cQc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723687817; x=1755223817; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qy6rFW2Ca7IeP9dj5MULCx0bT5yDxg5gpzSH1XS5jNo=; b=O57W7cQcZ8bXypYW79wMb5VgDf0/U3olt1pmaXfQ7iS9MKhNEDkQ0wcu Xon/lZZirpTzNZNhEmlo/goZ9ap9J5XPPhAVDgITsXcnUzFLMrUonNhR9 lRkvJPFLfjQC6joP/qZd+Jbul0CLkg2bjt6SgUjPkDSF4oTqP2aJRKcGK YP18YXsumK2k82hHpZwXJc2XbiomDduwRDZV/fT/4amqxIL353DFSwbqj S2KLASbUe75yoiIzsTOXOCr6XdLzJViMCJ3X32UMFD9ZGey9MUaGkTFYM m+Qj6YYMTVLrfy8k5bPTniuUDp6vAv1f4V7QRj2V83H/KgeQvse9iqUZH Q==; X-CSE-ConnectionGUID: txOaXGqoS3KtWolFzuq7bg== X-CSE-MsgGUID: 4HjgE24CS2G/Yz9PRz0Zvg== X-IronPort-AV: E=McAfee;i="6700,10204,11164"; a="21796133" X-IronPort-AV: E=Sophos;i="6.10,147,1719903600"; d="scan'208";a="21796133" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2024 19:10:14 -0700 X-CSE-ConnectionGUID: tP7paeRbQymVObfduXp++A== X-CSE-MsgGUID: D1tukIZyR9KMK5nGborGIw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,147,1719903600"; d="scan'208";a="63635503" Received: from ipg-l-lixuzha.sh.intel.com ([10.239.153.157]) by fmviesa005.fm.intel.com with ESMTP; 14 Aug 2024 19:10:11 -0700 From: Zhang Lixu To: linux-input@vger.kernel.org, srinivas.pandruvada@linux.intel.com, jikos@kernel.org, benjamin.tissoires@redhat.com Cc: lixu.zhang@intel.com, hemin.han@intel.com, yoshi.wang@intel.com, even.xu@intel.com, ilpo.jarvinen@linux.intel.com Subject: [PATCH v2 3/3] hid: intel-ish-hid: Add support for vendor customized firmware loading Date: Thu, 15 Aug 2024 10:10:01 +0800 Message-Id: <20240815021001.936277-4-lixu.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815021001.936277-1-lixu.zhang@intel.com> References: <20240815021001.936277-1-lixu.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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 f20463082dc4..aae0d965b47b 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 ff11ee4e38ed..f76c4437a1f5 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); } /**