[Midnightbsd-cvs] src [9352] trunk: Add support for getting and setting BBU properties related to battery

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Mar 4 14:32:16 EST 2017


Revision: 9352
          http://svnweb.midnightbsd.org/src/?rev=9352
Author:   laffer1
Date:     2017-03-04 14:32:15 -0500 (Sat, 04 Mar 2017)
Log Message:
-----------
Add support for getting and setting BBU properties related to battery
  relearning. Specifically, add subcommands to mfiutil(8) which allow the
  user to set the BBU and autolearn modes when the firmware supports it,
  and add a subcommand which kicks off a battery relearn.

Obtained from: FreeBSD

Modified Paths:
--------------
    trunk/sys/dev/mfi/mfi_debug.c
    trunk/sys/dev/mfi/mfireg.h
    trunk/usr.sbin/mfiutil/Makefile
    trunk/usr.sbin/mfiutil/mfi_show.c
    trunk/usr.sbin/mfiutil/mfi_volume.c
    trunk/usr.sbin/mfiutil/mfiutil.8
    trunk/usr.sbin/mfiutil/mfiutil.c
    trunk/usr.sbin/mfiutil/mfiutil.h

Modified: trunk/sys/dev/mfi/mfi_debug.c
===================================================================
--- trunk/sys/dev/mfi/mfi_debug.c	2017-03-04 19:31:21 UTC (rev 9351)
+++ trunk/sys/dev/mfi/mfi_debug.c	2017-03-04 19:32:15 UTC (rev 9352)
@@ -175,6 +175,15 @@
 	case MFI_DCMD_LD_MAP_GET_INFO:
 		opcode = "LD_MAP_GET_INFO";
 		break;
+	case MFI_DCMD_BBU_START_LEARN:
+		opcode = "BBU_START_LEARN";
+		break;
+	case MFI_DCMD_BBU_GET_PROP:
+		opcode = "BBU_GET_PROP";
+		break;
+	case MFI_DCMD_BBU_SET_PROP:
+		opcode = "BBU_SET_PROP";
+		break;
 	default:
 		opcode = "UNKNOWN";
 		break;

Modified: trunk/sys/dev/mfi/mfireg.h
===================================================================
--- trunk/sys/dev/mfi/mfireg.h	2017-03-04 19:31:21 UTC (rev 9351)
+++ trunk/sys/dev/mfi/mfireg.h	2017-03-04 19:32:15 UTC (rev 9352)
@@ -233,6 +233,9 @@
 	MFI_DCMD_BBU_GET_STATUS =	0x05010000,
 	MFI_DCMD_BBU_GET_CAPACITY_INFO =0x05020000,
 	MFI_DCMD_BBU_GET_DESIGN_INFO =	0x05030000,
+	MFI_DCMD_BBU_START_LEARN =	0x05040000,
+	MFI_DCMD_BBU_GET_PROP =		0x05050100,
+	MFI_DCMD_BBU_SET_PROP =		0x05050200,
 	MFI_DCMD_CLUSTER =		0x08000000,
 	MFI_DCMD_CLUSTER_RESET_ALL =	0x08010100,
 	MFI_DCMD_CLUSTER_RESET_LD =	0x08010200
@@ -1359,6 +1362,15 @@
 	uint8_t			reserved[21];
 } __packed;
 
+struct mfi_bbu_properties {
+	uint32_t		auto_learn_period;
+	uint32_t		next_learn_time;
+	uint8_t			learn_delay_interval;
+	uint8_t			auto_learn_mode;
+	uint8_t			bbu_mode;
+	uint8_t			reserved[21];
+} __packed;
+
 union mfi_bbu_status_detail {
 	struct mfi_ibbu_state	ibbu;
 	struct mfi_bbu_state	bbu;

Modified: trunk/usr.sbin/mfiutil/Makefile
===================================================================
--- trunk/usr.sbin/mfiutil/Makefile	2017-03-04 19:31:21 UTC (rev 9351)
+++ trunk/usr.sbin/mfiutil/Makefile	2017-03-04 19:32:15 UTC (rev 9352)
@@ -1,8 +1,8 @@
 # $MidnightBSD$
 PROG=	mfiutil
 
-SRCS=	mfiutil.c mfi_cmd.c mfi_config.c mfi_drive.c mfi_evt.c mfi_flash.c \
-	mfi_patrol.c mfi_show.c mfi_volume.c
+SRCS=	mfiutil.c mfi_bbu.c mfi_cmd.c mfi_config.c mfi_drive.c mfi_evt.c \
+	mfi_flash.c mfi_patrol.c mfi_show.c mfi_volume.c
 MAN8=	mfiutil.8
 
 CFLAGS+= -fno-builtin-strftime

Modified: trunk/usr.sbin/mfiutil/mfi_show.c
===================================================================
--- trunk/usr.sbin/mfiutil/mfi_show.c	2017-03-04 19:31:21 UTC (rev 9351)
+++ trunk/usr.sbin/mfiutil/mfi_show.c	2017-03-04 19:32:15 UTC (rev 9352)
@@ -140,9 +140,11 @@
 {
 	struct mfi_bbu_capacity_info cap;
 	struct mfi_bbu_design_info design;
+	struct mfi_bbu_properties props;
 	struct mfi_bbu_status stat;
 	uint8_t status;
-	int comma, error, fd, show_capacity;
+	int comma, error, fd, show_capacity, show_props;
+	char buf[32];
 
 	if (ac != 1) {
 		warnx("show battery: extra arguments");
@@ -186,6 +188,14 @@
 		return (error);
 	}
 
+	if (mfi_bbu_get_props(fd, &props, &status) < 0) {
+		error = errno;
+		warn("Failed to get properties");
+		close(fd);
+		return (error);
+	}
+	show_props = (status == MFI_STAT_OK);
+
 	printf("mfi%d: Battery State:\n", mfi_unit);
 	printf("     Manufacture Date: %d/%d/%d\n", design.mfg_date >> 5 & 0x0f,
 	    design.mfg_date & 0x1f, design.mfg_date >> 9 & 0xffff);
@@ -205,6 +215,23 @@
 	printf("       Design Voltage: %d mV\n", design.design_voltage);
 	printf("      Current Voltage: %d mV\n", stat.voltage);
 	printf("          Temperature: %d C\n", stat.temperature);
+	if (show_props) {
+		mfi_autolearn_period(props.auto_learn_period, buf, sizeof(buf));
+		printf("     Autolearn period: %s\n", buf);
+		if (props.auto_learn_mode != 0)
+			snprintf(buf, sizeof(buf), "never");
+		else
+			mfi_next_learn_time(props.next_learn_time, buf,
+			    sizeof(buf));
+		printf("      Next learn time: %s\n", buf);
+		printf(" Learn delay interval: %u hour%s\n",
+		    props.learn_delay_interval,
+		    props.learn_delay_interval != 1 ? "s" : "");
+		mfi_autolearn_mode(props.auto_learn_mode, buf, sizeof(buf));
+		printf("       Autolearn mode: %s\n", buf);
+		if (props.bbu_mode != 0)
+			printf("             BBU Mode: %d\n", props.bbu_mode);
+	}
 	printf("               Status:");
 	comma = 0;
 	if (stat.fw_status & MFI_BBU_STATE_PACK_MISSING) {

Modified: trunk/usr.sbin/mfiutil/mfi_volume.c
===================================================================
--- trunk/usr.sbin/mfiutil/mfi_volume.c	2017-03-04 19:31:21 UTC (rev 9351)
+++ trunk/usr.sbin/mfiutil/mfi_volume.c	2017-03-04 19:32:15 UTC (rev 9352)
@@ -363,7 +363,8 @@
 			break;
 		}
 		if (props.default_cache_policy != props.current_cache_policy)
-			printf("Cache Disabled Due to Dead Battery\n");
+			printf(
+	"Cache disabled due to dead battery or ongoing battery relearn\n");
 		error = 0;
 	} else {
 		new = props;

Modified: trunk/usr.sbin/mfiutil/mfiutil.8
===================================================================
--- trunk/usr.sbin/mfiutil/mfiutil.8	2017-03-04 19:31:21 UTC (rev 9351)
+++ trunk/usr.sbin/mfiutil/mfiutil.8	2017-03-04 19:32:15 UTC (rev 9352)
@@ -141,6 +141,12 @@
 .Nm
 .Op Fl u Ar unit
 .Cm flash Ar file
+.Nm
+.Op Fl u Ar unit
+.Cm start learn
+.Nm
+.Op Fl u Ar unit
+.Cm bbu Ar setting Ar value
 .Sh DESCRIPTION
 The
 .Nm
@@ -565,7 +571,34 @@
 Updates the flash on the controller with the firmware stored in
 .Ar file .
 A reboot is required for the new firmware to take effect.
+.It Cm start learn
+Start a battery relearn.
+.It Cm bbu Ar setting Ar value
+Update battery backup unit (BBU) properties related to battery relearning.
+The following settings are configurable:
+.Bl -tag -width indent
+.It Cm learn-delay
+Add a delay to the next scheduled battery relearn event. This setting is
+given in hours and must lie in the range of 0 to 255.
+.It Cm autolearn-mode
+Enable or disable automatic periodic battery relearning.
+The setting may be set to
+.Dq enable
+or
+.Dq disable
+to respectively enable or disable the relearn cycle.
+Alternatively, a mode of 0, 1 or 2 may be given.
+Mode 0 enables periodic relearning, mode 1 disables it, and mode 2 disables
+it and logs a warning to the event log when it detects that a battery relearn
+should be performed.
+.It Cm bbu-mode
+Set the BBU's mode of operation. This setting is not supported by all BBUs.
+Where it is supported, the possible values are the integers between 1 and 5
+inclusive.
+Modes 1, 2 and 3 enable a transparent learn cycle, whereas modes 4 and 5 do not.
+The BBU's data retention time is greater when transparent learning is not used.
 .El
+.El
 .Sh EXAMPLES
 Configure the cache for volume mfid0 to cache only writes:
 .Pp

Modified: trunk/usr.sbin/mfiutil/mfiutil.c
===================================================================
--- trunk/usr.sbin/mfiutil/mfiutil.c	2017-03-04 19:31:21 UTC (rev 9351)
+++ trunk/usr.sbin/mfiutil/mfiutil.c	2017-03-04 19:32:15 UTC (rev 9352)
@@ -84,6 +84,8 @@
 	fprintf(stderr, "    start patrol              - start a patrol read\n");
 	fprintf(stderr, "    stop patrol               - stop a patrol read\n");
 	fprintf(stderr, "    flash <firmware>\n");
+	fprintf(stderr, "    start learn               - start a BBU relearn\n");
+	fprintf(stderr, "    bbu <setting> <value>     - set BBU properties\n");
 #ifdef DEBUG
 	fprintf(stderr, "    debug                     - debug 'show config'\n");
 	fprintf(stderr, "    dump                      - display 'saved' config\n");

Modified: trunk/usr.sbin/mfiutil/mfiutil.h
===================================================================
--- trunk/usr.sbin/mfiutil/mfiutil.h	2017-03-04 19:31:21 UTC (rev 9351)
+++ trunk/usr.sbin/mfiutil/mfiutil.h	2017-03-04 19:32:15 UTC (rev 9352)
@@ -151,5 +151,12 @@
 const char *mfi_status(u_int status_code);
 const char *mfi_drive_name(struct mfi_pd_info *pinfo, uint16_t device_id,
     uint32_t def);
+int	mfi_bbu_get_props(int fd, struct mfi_bbu_properties *props,
+	    uint8_t *statusp);
+int	mfi_bbu_set_props(int fd, struct mfi_bbu_properties *props,
+	    uint8_t *statusp);
+void	mfi_autolearn_period(uint32_t, char *, size_t);
+void	mfi_next_learn_time(uint32_t, char *, size_t);
+void	mfi_autolearn_mode(uint8_t, char *, size_t);
 
 #endif /* !__MFIUTIL_H__ */



More information about the Midnightbsd-cvs mailing list