svn commit: r250483 - in stable/8: sys/dev/mfi usr.sbin/mfiutil

Mark Johnston markj at FreeBSD.org
Fri May 10 21:11:20 UTC 2013


Author: markj
Date: Fri May 10 21:11:18 2013
New Revision: 250483
URL: http://svnweb.freebsd.org/changeset/base/250483

Log:
  MFC r249257:
    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.
  
  MFC r249258:
    Switch to a 2-clause license.

Added:
  stable/8/usr.sbin/mfiutil/mfi_bbu.c
     - copied, changed from r249257, head/usr.sbin/mfiutil/mfi_bbu.c
Modified:
  stable/8/sys/dev/mfi/mfi_debug.c
  stable/8/sys/dev/mfi/mfireg.h
  stable/8/usr.sbin/mfiutil/Makefile
  stable/8/usr.sbin/mfiutil/mfi_show.c
  stable/8/usr.sbin/mfiutil/mfi_volume.c
  stable/8/usr.sbin/mfiutil/mfiutil.8
  stable/8/usr.sbin/mfiutil/mfiutil.c
  stable/8/usr.sbin/mfiutil/mfiutil.h
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/dev/   (props changed)
  stable/8/sys/dev/mfi/   (props changed)
  stable/8/usr.sbin/mfiutil/   (props changed)

Modified: stable/8/sys/dev/mfi/mfi_debug.c
==============================================================================
--- stable/8/sys/dev/mfi/mfi_debug.c	Fri May 10 21:08:53 2013	(r250482)
+++ stable/8/sys/dev/mfi/mfi_debug.c	Fri May 10 21:11:18 2013	(r250483)
@@ -175,6 +175,15 @@ mfi_print_dcmd(struct mfi_softc *sc, dev
 	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: stable/8/sys/dev/mfi/mfireg.h
==============================================================================
--- stable/8/sys/dev/mfi/mfireg.h	Fri May 10 21:08:53 2013	(r250482)
+++ stable/8/sys/dev/mfi/mfireg.h	Fri May 10 21:11:18 2013	(r250483)
@@ -233,6 +233,9 @@ typedef enum {
 	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 @@ struct mfi_bbu_state {
 	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: stable/8/usr.sbin/mfiutil/Makefile
==============================================================================
--- stable/8/usr.sbin/mfiutil/Makefile	Fri May 10 21:08:53 2013	(r250482)
+++ stable/8/usr.sbin/mfiutil/Makefile	Fri May 10 21:11:18 2013	(r250483)
@@ -1,8 +1,8 @@
 # $FreeBSD$
 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

Copied and modified: stable/8/usr.sbin/mfiutil/mfi_bbu.c (from r249257, head/usr.sbin/mfiutil/mfi_bbu.c)
==============================================================================
--- head/usr.sbin/mfiutil/mfi_bbu.c	Mon Apr  8 17:46:45 2013	(r249257, copy source)
+++ stable/8/usr.sbin/mfiutil/mfi_bbu.c	Fri May 10 21:11:18 2013	(r250483)
@@ -10,9 +10,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. The names of the authors may not be used to endorse or promote
- *    products derived from this software without specific prior written
- *    permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

Modified: stable/8/usr.sbin/mfiutil/mfi_show.c
==============================================================================
--- stable/8/usr.sbin/mfiutil/mfi_show.c	Fri May 10 21:08:53 2013	(r250482)
+++ stable/8/usr.sbin/mfiutil/mfi_show.c	Fri May 10 21:11:18 2013	(r250483)
@@ -140,9 +140,11 @@ show_battery(int ac, char **av __unused)
 {
 	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 @@ show_battery(int ac, char **av __unused)
 		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 @@ show_battery(int ac, char **av __unused)
 	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: stable/8/usr.sbin/mfiutil/mfi_volume.c
==============================================================================
--- stable/8/usr.sbin/mfiutil/mfi_volume.c	Fri May 10 21:08:53 2013	(r250482)
+++ stable/8/usr.sbin/mfiutil/mfi_volume.c	Fri May 10 21:11:18 2013	(r250483)
@@ -363,7 +363,8 @@ volume_cache(int ac, char **av)
 			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: stable/8/usr.sbin/mfiutil/mfiutil.8
==============================================================================
--- stable/8/usr.sbin/mfiutil/mfiutil.8	Fri May 10 21:08:53 2013	(r250482)
+++ stable/8/usr.sbin/mfiutil/mfiutil.8	Fri May 10 21:11:18 2013	(r250483)
@@ -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,6 +571,33 @@ Stop a currently running patrol read ope
 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:

Modified: stable/8/usr.sbin/mfiutil/mfiutil.c
==============================================================================
--- stable/8/usr.sbin/mfiutil/mfiutil.c	Fri May 10 21:08:53 2013	(r250482)
+++ stable/8/usr.sbin/mfiutil/mfiutil.c	Fri May 10 21:11:18 2013	(r250483)
@@ -84,6 +84,8 @@ usage(void)
 	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: stable/8/usr.sbin/mfiutil/mfiutil.h
==============================================================================
--- stable/8/usr.sbin/mfiutil/mfiutil.h	Fri May 10 21:08:53 2013	(r250482)
+++ stable/8/usr.sbin/mfiutil/mfiutil.h	Fri May 10 21:11:18 2013	(r250483)
@@ -151,5 +151,12 @@ int	mfi_reconfig_supported(void);
 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 svn-src-stable-8 mailing list