git: 3c0ad30d782b - stable/13 - iwlwifi: add sysctl to dump PCI IDs/ names / firmware-prefixes

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Wed, 08 Jun 2022 17:07:06 UTC
The branch stable/13 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=3c0ad30d782b69b2d7e64785bc6db4c6be1f3d52

commit 3c0ad30d782b69b2d7e64785bc6db4c6be1f3d52
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-05-18 16:05:49 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-06-08 16:11:18 +0000

    iwlwifi: add sysctl to dump PCI IDs/ names / firmware-prefixes
    
    Add a FreeBSD-specifc SYSCTL_PROC to dump the list of
    PCI IDs / name / firmware-prefix which can be post-processed
    for man pages (iwlwifi.4 and iwlwififw.4) or the wiki.
    
    The output still yields duplicates depending on by what information
    you need so one may wants to filter them out (try not to use sort/uniq).
    
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit 645886d028c85b3cb9fb36e96b1edc661cf4c0d8)
---
 sys/contrib/dev/iwlwifi/pcie/drv.c | 62 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/sys/contrib/dev/iwlwifi/pcie/drv.c b/sys/contrib/dev/iwlwifi/pcie/drv.c
index 536a40f1e5cc..6b9ce03850ec 100644
--- a/sys/contrib/dev/iwlwifi/pcie/drv.c
+++ b/sys/contrib/dev/iwlwifi/pcie/drv.c
@@ -1767,3 +1767,65 @@ void iwl_pci_unregister_driver(void)
 {
 	pci_unregister_driver(&iwl_pci_driver);
 }
+
+#if defined(__FreeBSD__)
+static int
+sysctl_iwlwifi_pci_ids_name(SYSCTL_HANDLER_ARGS)
+{
+	const struct pci_device_id *id;
+	struct sbuf *sb;
+	int error, i;
+
+	error = sysctl_wire_old_buffer(req, 0);
+	if (error != 0)
+		return (error);
+	sb = sbuf_new_for_sysctl(NULL, NULL, 512, req);
+	if (sb == NULL)
+		return (ENOMEM);
+
+	id = iwl_hw_card_ids;
+	while (id != NULL && id->vendor != 0) {
+
+		if ((id->driver_data & TRANS_CFG_MARKER) != 0) {
+			/* Skip and print them below. */
+
+		} else if (id->driver_data != 0) {
+			const struct iwl_cfg *cfg;
+
+			cfg = (void *)(id->driver_data & ~TRANS_CFG_MARKER);
+			sbuf_printf(sb, "%#06x/%#06x/%#06x/%#06x\t%s\t%s\n",
+			    id->vendor, id->device, id->subvendor, id->subdevice,
+			    cfg->name, cfg->fw_name_pre);
+		} else {
+			sbuf_printf(sb, "%#06x/%#06x/%#06x/%#06x\t%s\t%s\n",
+			    id->vendor, id->device, id->subvendor, id->subdevice,
+			    "","");
+		}
+		id++;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(iwl_dev_info_table); i++) {
+		const struct iwl_dev_info *dev_info = &iwl_dev_info_table[i];
+		const char *name;
+
+		if (dev_info->name)
+			name = dev_info->name;
+		else if (dev_info->cfg && dev_info->cfg->name)
+			name = dev_info->cfg->name;
+		else
+			name = "";
+
+		sbuf_printf(sb, "%#06x/%#06x/%#06x/%#06x\t%s\t%s\n",
+		    PCI_VENDOR_ID_INTEL, dev_info->device, PCI_ANY_ID, dev_info->subdevice,
+		    name, dev_info->cfg->fw_name_pre);
+	}
+
+	error = sbuf_finish(sb);
+	sbuf_delete(sb);
+
+	return (error);
+}
+SYSCTL_PROC(LINUXKPI_PARAM_PARENT, OID_AUTO, LINUXKPI_PARAM_NAME(pci_ids_name),
+    CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_SKIP | CTLFLAG_MPSAFE, NULL, 0,
+    sysctl_iwlwifi_pci_ids_name, "", "iwlwifi PCI IDs and names");
+#endif