Subject: [PATCH] [BZ 115289] ipl_tools: Add missing SCSI loadparm support
From: Michael Holzheu <holzheu@linux.vnet.ibm.com>

Description:  ipl_tools: Add missing SCSI loadparm support
Symptom:      IPL loadparm is not been be shown by "lsreipl" and cannot
              changed by "chreipl".
Problem:      Recent kernels support the loadparm also for SCSI IPL.
              The lsreipl/chreipl tools are not prepared for those
              kernels.
Solution:     Add support for SCSI loadparm:
              1) Show SCSI loadparm for lsreipl
              2) Allow setting of SCSI loadparm (-L option) for chreipl
Reproduction: Boot kernel with loadparm support and use lsreipl/chreipl.
Upstream-ID:  -
Problem-ID:   115289

Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
---
 ipl_tools/cmd_chreipl.c |   10 +++++++++-
 ipl_tools/cmd_lsreipl.c |   10 ++++++++++
 ipl_tools/man/chreipl.8 |    9 +++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)

--- a/ipl_tools/cmd_chreipl.c
+++ b/ipl_tools/cmd_chreipl.c
@@ -59,6 +59,7 @@ static const char *const usage_chreipl =
 "  -l  --lun <LUN>         Logical unit number of the FCP IPL device\n"
 "  -w  --wwpn <WWPN>       World Wide Port Name of the FCP IPL device\n"
 "  -b, --bootprog <BPROG>  Bootprog specification\n"
+"  -L, --loadparm <PARM>   Loadparm specification\n"
 "\n"
 "Options for nss target:\n"
 "  -n, --name <NAME>       Identifier of the NSS\n"
@@ -378,7 +379,7 @@ static void parse_pos_args(char *nargv[]
 
 static void check_fcp_opts(void)
 {
-	if (l.loadparm_set || l.nss_name_set)
+	if (l.nss_name_set)
 		ERR_EXIT("Invalid option for \"fcp\" target specified");
 	if (!(l.busid_set && l.wwpn_set && l.lun_set))
 		ERR_EXIT("The \"fcp\" target requires device, WWPN, "
@@ -546,6 +547,11 @@ static void chreipl_fcp(void)
 	if (!fcp_is_device(l.busid))
 		ERR_EXIT("Could not find FCP device \"%s\"", l.busid);
 	verify_write_access("reipl/fcp/device", "\"fcp\" re-IPL target");
+	/*
+	 * On old systems the FCP reipl loadparm cannot be set
+	 */
+	if (l.loadparm_set)
+		verify_write_access("reipl/fcp/loadparm", "loadparm");
 	if (l.bootparms_set) {
 		verify_write_access("reipl/fcp/scp_data", "boot parameters");
 		if (strlen(l.bootparms) > BOOTPARMS_FCP_MAX)
@@ -555,6 +561,8 @@ static void chreipl_fcp(void)
 	}
 	if (access("/sys/firmware/reipl/fcp/scp_data", W_OK) == 0)
 		write_str(l.bootparms, "reipl/fcp/scp_data");
+	if (access("/sys/firmware/reipl/fcp/loadparm", W_OK) == 0)
+		write_str(l.loadparm, "reipl/fcp/loadparm");
 	write_str(l.busid, "reipl/fcp/device");
 	write_str(l.wwpn, "reipl/fcp/wwpn");
 	write_str(l.lun, "reipl/fcp/lun");
--- a/ipl_tools/cmd_lsreipl.c
+++ b/ipl_tools/cmd_lsreipl.c
@@ -55,6 +55,9 @@ void print_fcp(int show_ipl, int dump)
 	char *dir = show_ipl ? "ipl" : "reipl/fcp";
 	char *path_bootparms = show_ipl ? "/sys/firmware/ipl/scp_data" :
 		"/sys/firmware/reipl/fcp/scp_data";
+	char *path_loadparm = show_ipl ? "/sys/firmware/ipl/loadparm" :
+		"/sys/firmware/reipl/fcp/loadparm";
+	char loadparm[9], loadparm_path[PATH_MAX];
 
 	if (dump)
 		printf("%-12s fcp_dump\n", get_ipl_banner(show_ipl));
@@ -66,6 +69,13 @@ void print_fcp(int show_ipl, int dump)
 	print_fw_str("Device:      %s\n", dir, "device");
 	print_fw_str("bootprog:    %s\n", dir, "bootprog");
 	print_fw_str("br_lba:      %s\n", dir, "br_lba");
+	if (access(path_loadparm, R_OK) == 0) {
+		sprintf(loadparm_path, "%s/%s", dir, "loadparm");
+		read_fw_str(loadparm, loadparm_path, sizeof(loadparm));
+		if (strcmp(loadparm, "        ") == 0)
+			loadparm[0] = 0;
+		printf("Loadparm:    \"%s\"\n", loadparm);
+	}
 	if (access(path_bootparms, R_OK) == 0)
 		print_fw_str("Bootparms:   \"%s\"\n", dir, "scp_data");
 }
--- a/ipl_tools/man/chreipl.8
+++ b/ipl_tools/man/chreipl.8
@@ -152,6 +152,15 @@ Specifies the logical unit number (LUN)
 .BR "\-b" " or " "\-\-bootprog"
 Specifies an entry in the FCP boot configuration by defining the IPL boot
 program selector. If omitted, '0' will be used.
+
+.TP
+.BR "\-L" " or " "\-\-loadparm"
+The loadparm for the fcp re-IPL target is not used to control the FCP boot
+configuration that is defined by the
+.BR zipl (8)
+boot menu. Instead it can be used to control higher level boot loaders
+like GRUB. For more details refer to distribution specific documentation.
+
 .PP
 \fBExamples:\fP
 .br
