git: 0d48d6d7bba7 - main - smartpqi: Add runtime sysctl for debug_level and log device state changes

From: John Hall <jrhall_at_FreeBSD.org>
Date: Thu, 07 May 2026 18:08:39 UTC
The branch main has been updated by jrhall:

URL: https://cgit.FreeBSD.org/src/commit/?id=0d48d6d7bba77d6c3736ce56ea5667bfbde89705

commit 0d48d6d7bba77d6c3736ce56ea5667bfbde89705
Author:     John Hall <jrhall@FreeBSD.org>
AuthorDate: 2026-05-04 21:43:27 +0000
Commit:     John Hall <jrhall@FreeBSD.org>
CommitDate: 2026-05-07 18:08:26 +0000

    smartpqi: Add runtime sysctl for debug_level and log device state changes
    
    The smartpqi driver did not log device add/remove or controller events
    to syslog, and hw.smartpqi.debug_level could only be set at boot via
    loader.conf with no runtime sysctl interface.
    
    Add a read-write sysctl at dev.smartpqi.N.debug_level for runtime
    debug level changes. Add device_printf calls for device addition,
    removal, and controller events (hotplug, hardware, physical/logical
    device, AIO state/config changes) so state changes always appear in
    dmesg. Add DBG_DISC logging for discovery state transitions. Fix
    spelling errors in strings and comments across the driver.
    
    Bump driver version to 14.4691.1.2000 / 15.2.1.2000.
    
    PR:             294161
    Reviewed by:    imp
    Approved by:    imp
    MFC after:      2 weeks
    
    Differential Revision:  https://reviews.freebsd.org/D56832
---
 sys/dev/smartpqi/smartpqi_cam.c        |  4 ++--
 sys/dev/smartpqi/smartpqi_defines.h    |  8 ++++----
 sys/dev/smartpqi/smartpqi_discovery.c  | 21 ++++++++++++++++++---
 sys/dev/smartpqi/smartpqi_event.c      | 17 ++++++++++++++---
 sys/dev/smartpqi/smartpqi_main.c       | 12 +++++++++++-
 sys/dev/smartpqi/smartpqi_misc.c       |  4 ++--
 sys/dev/smartpqi/smartpqi_queue.c      |  4 ++--
 sys/dev/smartpqi/smartpqi_request.c    |  4 ++--
 sys/dev/smartpqi/smartpqi_response.c   |  4 ++--
 sys/dev/smartpqi/smartpqi_sis.c        |  6 +++---
 sys/dev/smartpqi/smartpqi_structures.h |  4 ++--
 11 files changed, 62 insertions(+), 26 deletions(-)

diff --git a/sys/dev/smartpqi/smartpqi_cam.c b/sys/dev/smartpqi/smartpqi_cam.c
index 690b38c9f855..6ded8aa97e39 100644
--- a/sys/dev/smartpqi/smartpqi_cam.c
+++ b/sys/dev/smartpqi/smartpqi_cam.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright 2016-2025 Microchip Technology, Inc. and/or its subsidiaries.
+ * Copyright 2016-2026 Microchip Technology, Inc. and/or its subsidiaries.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -1300,7 +1300,7 @@ register_sim(struct pqisrc_softstate *softs, int card_index)
 	csa.callback_arg = softs;
 	xpt_action((union ccb *)&csa);
 	if (csa.ccb_h.status != CAM_REQ_CMP) {
-		DBG_ERR("Unable to register smartpqi_aysnc handler: %d!\n",
+		DBG_ERR("Unable to register smartpqi_async handler: %d!\n",
 			csa.ccb_h.status);
 	}
 
diff --git a/sys/dev/smartpqi/smartpqi_defines.h b/sys/dev/smartpqi/smartpqi_defines.h
index 0277abd3e318..c4084f069588 100644
--- a/sys/dev/smartpqi/smartpqi_defines.h
+++ b/sys/dev/smartpqi/smartpqi_defines.h
@@ -1,5 +1,5 @@
 /*-
- * Copyright 2016-2025 Microchip Technology, Inc. and/or its subsidiaries.
+ * Copyright 2016-2026 Microchip Technology, Inc. and/or its subsidiaries.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -944,12 +944,12 @@ typedef uint8_t *passthru_buf_type_t;
 
 #define PQISRC_DRIVER_MAJOR		__FreeBSD__
 #if __FreeBSD__ <= 14
-#define PQISRC_DRIVER_MINOR	   4690
+#define PQISRC_DRIVER_MINOR	   4691
 #else
 #define PQISRC_DRIVER_MINOR	   2
 #endif
-#define PQISRC_DRIVER_RELEASE	   0
-#define PQISRC_DRIVER_REVISION   2008
+#define PQISRC_DRIVER_RELEASE	   1
+#define PQISRC_DRIVER_REVISION   2000
 
 #define STR(s)                          # s
 #define PQISRC_VERSION(a, b, c, d)      STR(a.b.c-d)
diff --git a/sys/dev/smartpqi/smartpqi_discovery.c b/sys/dev/smartpqi/smartpqi_discovery.c
index a7de5a149810..8682e6cabd7e 100644
--- a/sys/dev/smartpqi/smartpqi_discovery.c
+++ b/sys/dev/smartpqi/smartpqi_discovery.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright 2016-2025 Microchip Technology, Inc. and/or its subsidiaries.
+ * Copyright 2016-2026 Microchip Technology, Inc. and/or its subsidiaries.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -155,7 +155,7 @@ pqisrc_remove_target_bit(pqisrc_softstate_t *softs, int target)
 	softs->bit_map.bit_vector[target] = SLOT_AVAILABLE;
 }
 
-/* Use bit map to find availible targets */
+/* Use bit map to find available targets */
 int
 pqisrc_find_avail_target(pqisrc_softstate_t *softs)
 {
@@ -1423,7 +1423,11 @@ pqisrc_add_device(pqisrc_softstate_t *softs, pqi_scsi_dev_t *device)
 
 	if(device->expose_device) {
 		pqisrc_init_device_active_io(softs, device);
-		/* TBD: Call OS upper layer function to add the device entry */
+		device_printf(softs->os_specific.pqi_dev,
+		    "device added: vendor=%s model=%s B%d:T%d:L%d type=%s\n",
+		    device->vendor, device->model,
+		    device->bus, device->target, device->lun,
+		    device->is_physical_device ? "physical" : "logical");
 		os_add_device(softs,device);
 	}
 	DBG_FUNC("OUT\n");
@@ -1451,6 +1455,11 @@ pqisrc_remove_device(pqisrc_softstate_t *softs, pqi_scsi_dev_t *device)
 	}
 	/* Wait for device outstanding Io's */
 	pqisrc_wait_for_device_commands_to_complete(softs, device);
+	device_printf(softs->os_specific.pqi_dev,
+	    "device removed: vendor=%s model=%s B%d:T%d:L%d type=%s\n",
+	    device->vendor, device->model,
+	    device->bus, device->target, device->lun,
+	    device->is_physical_device ? "physical" : "logical");
 	/* Call OS upper layer function to remove the exposed device entry */
 	os_remove_device(softs,device);
 	DBG_FUNC("OUT\n");
@@ -1674,10 +1683,14 @@ pqisrc_update_device_list(pqisrc_softstate_t *softs,
 		case DEVICE_NOT_FOUND:
 			/* Device not found in existing list */
 			device->new_device = true;
+			DBG_DISC("new device found B%d:T%d:L%d\n",
+			    device->bus, device->target, device->lun);
 			break;
 		case DEVICE_CHANGED:
 			/* Actual device gone need to add device to list*/
 			device->new_device = true;
+			DBG_DISC("device changed B%d:T%d:L%d\n",
+			    device->bus, device->target, device->lun);
 			break;
 		case DEVICE_IN_REMOVE:
 			/*Older device with same target/lun is in removal stage*/
@@ -1686,6 +1699,8 @@ pqisrc_update_device_list(pqisrc_softstate_t *softs,
 			 * free call*/
 			device->new_device = false;
 			same_device->schedule_rescan = true;
+			DBG_DISC("device in removal B%d:T%d:L%d, scheduling rescan\n",
+			    device->bus, device->target, device->lun);
 			break;
 		default:
 			break;
diff --git a/sys/dev/smartpqi/smartpqi_event.c b/sys/dev/smartpqi/smartpqi_event.c
index 77a70f9fb031..c3c27c9e1c0b 100644
--- a/sys/dev/smartpqi/smartpqi_event.c
+++ b/sys/dev/smartpqi/smartpqi_event.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright 2016-2025 Microchip Technology, Inc. and/or its subsidiaries.
+ * Copyright 2016-2026 Microchip Technology, Inc. and/or its subsidiaries.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -204,6 +204,17 @@ pqisrc_process_event_intr_src(pqisrc_softstate_t *softs,int obq_id)
 		}
 
 		if (event_index >= 0) {
+			static const char *event_names[] = {
+				[PQI_EVENT_HOTPLUG]           = "hotplug",
+				[PQI_EVENT_HARDWARE]          = "hardware",
+				[PQI_EVENT_PHYSICAL_DEVICE]   = "physical device",
+				[PQI_EVENT_LOGICAL_DEVICE]    = "logical device",
+				[PQI_EVENT_AIO_STATE_CHANGE]  = "AIO state change",
+				[PQI_EVENT_AIO_CONFIG_CHANGE] = "AIO config change",
+			};
+			device_printf(softs->os_specific.pqi_dev,
+			    "event: %s (type=0x%x)\n",
+			    event_names[event_index], response.event_type);
 			if(response.request_acknowledge) {
 				pending_event = &softs->pending_events[event_index];
 				pending_event->pending = true;
@@ -385,7 +396,7 @@ pqisrc_report_event_config(pqisrc_softstate_t *softs)
 	pqi_event_config_request_t request;
 	pqi_event_config_t  *event_config_p ;
 	dma_mem_t  buf_report_event ;
-	/*bytes to be allocaed for report event config data-in buffer */
+	/*bytes to be allocated for report event config data-in buffer */
 	uint32_t alloc_size = sizeof(pqi_event_config_t) ;
 	memset(&request, 0 , sizeof(request));
 
@@ -446,7 +457,7 @@ pqisrc_set_event_config(pqisrc_softstate_t *softs)
 	pqi_event_config_request_t request;
 	pqi_event_config_t *event_config_p;
 	dma_mem_t buf_set_event;
-	/*bytes to be allocaed for set event config data-out buffer */
+	/*bytes to be allocated for set event config data-out buffer */
 	uint32_t alloc_size = sizeof(pqi_event_config_t);
 	memset(&request, 0 , sizeof(request));
 
diff --git a/sys/dev/smartpqi/smartpqi_main.c b/sys/dev/smartpqi/smartpqi_main.c
index 1f006939bf7c..fbfbcc962f35 100644
--- a/sys/dev/smartpqi/smartpqi_main.c
+++ b/sys/dev/smartpqi/smartpqi_main.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright 2016-2025 Microchip Technology, Inc. and/or its subsidiaries.
+ * Copyright 2016-2026 Microchip Technology, Inc. and/or its subsidiaries.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -427,6 +427,16 @@ smartpqi_attach(device_t dev)
 		goto out;
 	}
 
+	/* Register sysctl for runtime debug_level changes */
+	{
+		struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(dev);
+		struct sysctl_oid *tree = device_get_sysctl_tree(dev);
+
+		SYSCTL_ADD_ULONG(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
+		    "debug_level", CTLFLAG_RW, &logging_level,
+		    "Debug logging bitmask");
+	}
+
 	goto out;
 
 dma_out:
diff --git a/sys/dev/smartpqi/smartpqi_misc.c b/sys/dev/smartpqi/smartpqi_misc.c
index 6db0d80ed993..fd0b907aa252 100644
--- a/sys/dev/smartpqi/smartpqi_misc.c
+++ b/sys/dev/smartpqi/smartpqi_misc.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright 2016-2025 Microchip Technology, Inc. and/or its subsidiaries.
+ * Copyright 2016-2026 Microchip Technology, Inc. and/or its subsidiaries.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -252,7 +252,7 @@ bsd_set_hint_scatter_gather_config(struct pqisrc_softstate *softs)
 
 	DBG_FUNC("IN\n");
 
-	/* At least > 16 sg's required to wotk hint correctly.
+	/* At least > 16 sg's required to work hint correctly.
 	 * Default the sg count set by driver/controller. */
 
 	if ((!softs->hint.sg_segments) || (softs->hint.sg_segments >
diff --git a/sys/dev/smartpqi/smartpqi_queue.c b/sys/dev/smartpqi/smartpqi_queue.c
index e8a467531aa4..679d956f6f36 100644
--- a/sys/dev/smartpqi/smartpqi_queue.c
+++ b/sys/dev/smartpqi/smartpqi_queue.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright 2016-2025 Microchip Technology, Inc. and/or its subsidiaries.
+ * Copyright 2016-2026 Microchip Technology, Inc. and/or its subsidiaries.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -729,7 +729,7 @@ pqisrc_create_op_ibq(pqisrc_softstate_t *softs,
 				op_ib_q->pi_register_offset);
 	} else {
 		int i = 0;
-		DBG_WARN("Error Status Decsriptors\n");
+		DBG_WARN("Error Status Descriptors\n");
 		for (i = 0; i < 4; i++)
 			DBG_WARN(" %x\n",admin_resp.resp_type.create_op_iq.status_desc[i]);
 	}
diff --git a/sys/dev/smartpqi/smartpqi_request.c b/sys/dev/smartpqi/smartpqi_request.c
index c5f8ac3c41ba..655660615797 100644
--- a/sys/dev/smartpqi/smartpqi_request.c
+++ b/sys/dev/smartpqi/smartpqi_request.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright 2016-2025 Microchip Technology, Inc. and/or its subsidiaries.
+ * Copyright 2016-2026 Microchip Technology, Inc. and/or its subsidiaries.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -1998,7 +1998,7 @@ pqisrc_send_raid_tmf(pqisrc_softstate_t *softs, pqi_scsi_dev_t const *devp,
 
 	if (softs->timeout_in_tmf &&
 			tmf_type == SOP_TASK_MANAGEMENT_LUN_RESET) {
-		/* OS_TMF_TIMEOUT_SEC - 1 to accomodate driver processing */
+		/* OS_TMF_TIMEOUT_SEC - 1 to accommodate driver processing */
 		tmf_req.timeout_in_sec = OS_TMF_TIMEOUT_SEC - 1;
 	}
 
diff --git a/sys/dev/smartpqi/smartpqi_response.c b/sys/dev/smartpqi/smartpqi_response.c
index 38695860e520..1ae74a5b95ff 100644
--- a/sys/dev/smartpqi/smartpqi_response.c
+++ b/sys/dev/smartpqi/smartpqi_response.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright 2016-2025 Microchip Technology, Inc. and/or its subsidiaries.
+ * Copyright 2016-2026 Microchip Technology, Inc. and/or its subsidiaries.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -275,7 +275,7 @@ pqisrc_is_innocuous_error(pqisrc_softstate_t *softs, rcb_t *rcb, void *err_info)
 		if (raid_err->data_out_result == PQI_RAID_DATA_IN_OUT_UNDERFLOW)
 			return true;
 
-		/* We get these a alot: leave a tiny breadcrumb about the error,
+		/* We get these a lot: leave a tiny breadcrumb about the error,
 			but don't do full spew about it */
 		if (raid_err->status == PQI_AIO_STATUS_CHECK_CONDITION)
 		{
diff --git a/sys/dev/smartpqi/smartpqi_sis.c b/sys/dev/smartpqi/smartpqi_sis.c
index 82eb999ca4b8..99aa952eb149 100644
--- a/sys/dev/smartpqi/smartpqi_sis.c
+++ b/sys/dev/smartpqi/smartpqi_sis.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright 2016-2025 Microchip Technology, Inc. and/or its subsidiaries.
+ * Copyright 2016-2026 Microchip Technology, Inc. and/or its subsidiaries.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,7 +26,7 @@
 
 #include "smartpqi_includes.h"
 
-/* Function for disabling msix interrupots */
+/* Function for disabling msix interrupts */
 void
 sis_disable_msix(pqisrc_softstate_t *softs)
 {
@@ -96,7 +96,7 @@ sis_disable_interrupt(pqisrc_softstate_t *softs)
  			sis_disable_msix(softs);
 			break;
 		default:
-			DBG_ERR("Inerrupt mode none!\n");
+			DBG_ERR("Interrupt mode none!\n");
 			break;
 	}
 
diff --git a/sys/dev/smartpqi/smartpqi_structures.h b/sys/dev/smartpqi/smartpqi_structures.h
index 0c9ad375823d..ada6676ada8f 100644
--- a/sys/dev/smartpqi/smartpqi_structures.h
+++ b/sys/dev/smartpqi/smartpqi_structures.h
@@ -1,5 +1,5 @@
 /*-
- * Copyright 2016-2025 Microchip Technology, Inc. and/or its subsidiaries.
+ * Copyright 2016-2026 Microchip Technology, Inc. and/or its subsidiaries.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -1168,7 +1168,7 @@ typedef struct bmic_sense_feature_page_header {
 	uint8_t page;
 	uint8_t sub_page;
 	uint16_t total_length; /** Total length of the page.
-	* The length is the same wheteher the request buffer is too short or not.
+	* The length is the same whether the request buffer is too short or not.
 	* When printing out the page, only print the buffer length. */
 } OS_ATTRIBUTE_PACKED bmic_sense_feature_page_header_t;