Skip to content

Commit 740834b

Browse files
committed
s390/ipl: Introduce macros for (re)ipl sysfs attribute 'scp_data'
JIRA: https://issues.redhat.com/browse/RHEL-86670 commit 005ca01 Author: Alexander Egorenkov <[email protected]> Date: Fri May 10 12:41:27 2024 +0200 s390/ipl: Introduce macros for (re)ipl sysfs attribute 'scp_data' This is a refactoring change to reduce code duplication and improve code reuse. Acked-by: Heiko Carstens <[email protected]> Signed-off-by: Alexander Egorenkov <[email protected]> Signed-off-by: Alexander Gordeev <[email protected]> Signed-off-by: Thomas Huth <[email protected]>
1 parent 5eb1422 commit 740834b

File tree

1 file changed

+83
-163
lines changed

1 file changed

+83
-163
lines changed

arch/s390/kernel/ipl.c

Lines changed: 83 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,61 @@ static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
279279
sys_##_prefix##_##_name##_show, \
280280
sys_##_prefix##_##_name##_store)
281281

282+
#define IPL_ATTR_SCP_DATA_SHOW_FN(_prefix, _ipl_block) \
283+
static ssize_t sys_##_prefix##_scp_data_show(struct file *filp, \
284+
struct kobject *kobj, \
285+
struct bin_attribute *attr, \
286+
char *buf, loff_t off, \
287+
size_t count) \
288+
{ \
289+
size_t size = _ipl_block.scp_data_len; \
290+
void *scp_data = _ipl_block.scp_data; \
291+
\
292+
return memory_read_from_buffer(buf, count, &off, \
293+
scp_data, size); \
294+
}
295+
296+
#define IPL_ATTR_SCP_DATA_STORE_FN(_prefix, _ipl_block_hdr, _ipl_block, _ipl_bp_len, _ipl_bp0_len)\
297+
static ssize_t sys_##_prefix##_scp_data_store(struct file *filp, \
298+
struct kobject *kobj, \
299+
struct bin_attribute *attr, \
300+
char *buf, loff_t off, \
301+
size_t count) \
302+
{ \
303+
size_t scpdata_len = count; \
304+
size_t padding; \
305+
\
306+
if (off) \
307+
return -EINVAL; \
308+
\
309+
memcpy(_ipl_block.scp_data, buf, count); \
310+
if (scpdata_len % 8) { \
311+
padding = 8 - (scpdata_len % 8); \
312+
memset(_ipl_block.scp_data + scpdata_len, \
313+
0, padding); \
314+
scpdata_len += padding; \
315+
} \
316+
\
317+
_ipl_block_hdr.len = _ipl_bp_len + scpdata_len; \
318+
_ipl_block.len = _ipl_bp0_len + scpdata_len; \
319+
_ipl_block.scp_data_len = scpdata_len; \
320+
\
321+
return count; \
322+
}
323+
324+
#define DEFINE_IPL_ATTR_SCP_DATA_RO(_prefix, _ipl_block, _size) \
325+
IPL_ATTR_SCP_DATA_SHOW_FN(_prefix, _ipl_block) \
326+
static struct bin_attribute sys_##_prefix##_scp_data_attr = \
327+
__BIN_ATTR(scp_data, 0444, sys_##_prefix##_scp_data_show, \
328+
NULL, _size)
329+
330+
#define DEFINE_IPL_ATTR_SCP_DATA_RW(_prefix, _ipl_block_hdr, _ipl_block, _ipl_bp_len, _ipl_bp0_len, _size)\
331+
IPL_ATTR_SCP_DATA_SHOW_FN(_prefix, _ipl_block) \
332+
IPL_ATTR_SCP_DATA_STORE_FN(_prefix, _ipl_block_hdr, _ipl_block, _ipl_bp_len, _ipl_bp0_len)\
333+
static struct bin_attribute sys_##_prefix##_scp_data_attr = \
334+
__BIN_ATTR(scp_data, 0644, sys_##_prefix##_scp_data_show, \
335+
sys_##_prefix##_scp_data_store, _size)
336+
282337
/*
283338
* ipl section
284339
*/
@@ -377,71 +432,38 @@ static ssize_t sys_ipl_device_show(struct kobject *kobj,
377432
static struct kobj_attribute sys_ipl_device_attr =
378433
__ATTR(device, 0444, sys_ipl_device_show, NULL);
379434

380-
static ssize_t ipl_parameter_read(struct file *filp, struct kobject *kobj,
381-
struct bin_attribute *attr, char *buf,
382-
loff_t off, size_t count)
435+
static ssize_t sys_ipl_parameter_read(struct file *filp, struct kobject *kobj,
436+
struct bin_attribute *attr, char *buf,
437+
loff_t off, size_t count)
383438
{
384439
return memory_read_from_buffer(buf, count, &off, &ipl_block,
385440
ipl_block.hdr.len);
386441
}
387-
static struct bin_attribute ipl_parameter_attr =
388-
__BIN_ATTR(binary_parameter, 0444, ipl_parameter_read, NULL,
442+
static struct bin_attribute sys_ipl_parameter_attr =
443+
__BIN_ATTR(binary_parameter, 0444, sys_ipl_parameter_read, NULL,
389444
PAGE_SIZE);
390445

391-
static ssize_t ipl_scp_data_read(struct file *filp, struct kobject *kobj,
392-
struct bin_attribute *attr, char *buf,
393-
loff_t off, size_t count)
394-
{
395-
unsigned int size = ipl_block.fcp.scp_data_len;
396-
void *scp_data = &ipl_block.fcp.scp_data;
397-
398-
return memory_read_from_buffer(buf, count, &off, scp_data, size);
399-
}
400-
401-
static ssize_t ipl_nvme_scp_data_read(struct file *filp, struct kobject *kobj,
402-
struct bin_attribute *attr, char *buf,
403-
loff_t off, size_t count)
404-
{
405-
unsigned int size = ipl_block.nvme.scp_data_len;
406-
void *scp_data = &ipl_block.nvme.scp_data;
407-
408-
return memory_read_from_buffer(buf, count, &off, scp_data, size);
409-
}
410-
411-
static ssize_t ipl_eckd_scp_data_read(struct file *filp, struct kobject *kobj,
412-
struct bin_attribute *attr, char *buf,
413-
loff_t off, size_t count)
414-
{
415-
unsigned int size = ipl_block.eckd.scp_data_len;
416-
void *scp_data = &ipl_block.eckd.scp_data;
417-
418-
return memory_read_from_buffer(buf, count, &off, scp_data, size);
419-
}
420-
421-
static struct bin_attribute ipl_scp_data_attr =
422-
__BIN_ATTR(scp_data, 0444, ipl_scp_data_read, NULL, PAGE_SIZE);
423-
424-
static struct bin_attribute ipl_nvme_scp_data_attr =
425-
__BIN_ATTR(scp_data, 0444, ipl_nvme_scp_data_read, NULL, PAGE_SIZE);
426-
427-
static struct bin_attribute ipl_eckd_scp_data_attr =
428-
__BIN_ATTR(scp_data, 0444, ipl_eckd_scp_data_read, NULL, PAGE_SIZE);
446+
DEFINE_IPL_ATTR_SCP_DATA_RO(ipl_fcp, ipl_block.fcp, PAGE_SIZE);
429447

430448
static struct bin_attribute *ipl_fcp_bin_attrs[] = {
431-
&ipl_parameter_attr,
432-
&ipl_scp_data_attr,
449+
&sys_ipl_parameter_attr,
450+
&sys_ipl_fcp_scp_data_attr,
433451
NULL,
434452
};
435453

454+
DEFINE_IPL_ATTR_SCP_DATA_RO(ipl_nvme, ipl_block.nvme, PAGE_SIZE);
455+
436456
static struct bin_attribute *ipl_nvme_bin_attrs[] = {
437-
&ipl_parameter_attr,
438-
&ipl_nvme_scp_data_attr,
457+
&sys_ipl_parameter_attr,
458+
&sys_ipl_nvme_scp_data_attr,
439459
NULL,
440460
};
441461

462+
DEFINE_IPL_ATTR_SCP_DATA_RO(ipl_eckd, ipl_block.eckd, PAGE_SIZE);
463+
442464
static struct bin_attribute *ipl_eckd_bin_attrs[] = {
443-
&ipl_parameter_attr,
444-
&ipl_eckd_scp_data_attr,
465+
&sys_ipl_parameter_attr,
466+
&sys_ipl_eckd_scp_data_attr,
445467
NULL,
446468
};
447469

@@ -780,44 +802,10 @@ static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
780802

781803
/* FCP reipl device attributes */
782804

783-
static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
784-
struct bin_attribute *attr,
785-
char *buf, loff_t off, size_t count)
786-
{
787-
size_t size = reipl_block_fcp->fcp.scp_data_len;
788-
void *scp_data = reipl_block_fcp->fcp.scp_data;
789-
790-
return memory_read_from_buffer(buf, count, &off, scp_data, size);
791-
}
792-
793-
static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
794-
struct bin_attribute *attr,
795-
char *buf, loff_t off, size_t count)
796-
{
797-
size_t scpdata_len = count;
798-
size_t padding;
799-
800-
801-
if (off)
802-
return -EINVAL;
803-
804-
memcpy(reipl_block_fcp->fcp.scp_data, buf, count);
805-
if (scpdata_len % 8) {
806-
padding = 8 - (scpdata_len % 8);
807-
memset(reipl_block_fcp->fcp.scp_data + scpdata_len,
808-
0, padding);
809-
scpdata_len += padding;
810-
}
811-
812-
reipl_block_fcp->hdr.len = IPL_BP_FCP_LEN + scpdata_len;
813-
reipl_block_fcp->fcp.len = IPL_BP0_FCP_LEN + scpdata_len;
814-
reipl_block_fcp->fcp.scp_data_len = scpdata_len;
815-
816-
return count;
817-
}
818-
static struct bin_attribute sys_reipl_fcp_scp_data_attr =
819-
__BIN_ATTR(scp_data, 0644, reipl_fcp_scpdata_read,
820-
reipl_fcp_scpdata_write, DIAG308_SCPDATA_SIZE);
805+
DEFINE_IPL_ATTR_SCP_DATA_RW(reipl_fcp, reipl_block_fcp->hdr,
806+
reipl_block_fcp->fcp,
807+
IPL_BP_FCP_LEN, IPL_BP0_FCP_LEN,
808+
DIAG308_SCPDATA_SIZE);
821809

822810
static struct bin_attribute *reipl_fcp_bin_attrs[] = {
823811
&sys_reipl_fcp_scp_data_attr,
@@ -938,44 +926,10 @@ static struct kobj_attribute sys_reipl_fcp_clear_attr =
938926

939927
/* NVME reipl device attributes */
940928

941-
static ssize_t reipl_nvme_scpdata_read(struct file *filp, struct kobject *kobj,
942-
struct bin_attribute *attr,
943-
char *buf, loff_t off, size_t count)
944-
{
945-
size_t size = reipl_block_nvme->nvme.scp_data_len;
946-
void *scp_data = reipl_block_nvme->nvme.scp_data;
947-
948-
return memory_read_from_buffer(buf, count, &off, scp_data, size);
949-
}
950-
951-
static ssize_t reipl_nvme_scpdata_write(struct file *filp, struct kobject *kobj,
952-
struct bin_attribute *attr,
953-
char *buf, loff_t off, size_t count)
954-
{
955-
size_t scpdata_len = count;
956-
size_t padding;
957-
958-
if (off)
959-
return -EINVAL;
960-
961-
memcpy(reipl_block_nvme->nvme.scp_data, buf, count);
962-
if (scpdata_len % 8) {
963-
padding = 8 - (scpdata_len % 8);
964-
memset(reipl_block_nvme->nvme.scp_data + scpdata_len,
965-
0, padding);
966-
scpdata_len += padding;
967-
}
968-
969-
reipl_block_nvme->hdr.len = IPL_BP_NVME_LEN + scpdata_len;
970-
reipl_block_nvme->nvme.len = IPL_BP0_NVME_LEN + scpdata_len;
971-
reipl_block_nvme->nvme.scp_data_len = scpdata_len;
972-
973-
return count;
974-
}
975-
976-
static struct bin_attribute sys_reipl_nvme_scp_data_attr =
977-
__BIN_ATTR(scp_data, 0644, reipl_nvme_scpdata_read,
978-
reipl_nvme_scpdata_write, DIAG308_SCPDATA_SIZE);
929+
DEFINE_IPL_ATTR_SCP_DATA_RW(reipl_nvme, reipl_block_nvme->hdr,
930+
reipl_block_nvme->nvme,
931+
IPL_BP_NVME_LEN, IPL_BP0_NVME_LEN,
932+
DIAG308_SCPDATA_SIZE);
979933

980934
static struct bin_attribute *reipl_nvme_bin_attrs[] = {
981935
&sys_reipl_nvme_scp_data_attr,
@@ -1071,44 +1025,10 @@ static struct attribute_group reipl_ccw_attr_group_lpar = {
10711025

10721026
/* ECKD reipl device attributes */
10731027

1074-
static ssize_t reipl_eckd_scpdata_read(struct file *filp, struct kobject *kobj,
1075-
struct bin_attribute *attr,
1076-
char *buf, loff_t off, size_t count)
1077-
{
1078-
size_t size = reipl_block_eckd->eckd.scp_data_len;
1079-
void *scp_data = reipl_block_eckd->eckd.scp_data;
1080-
1081-
return memory_read_from_buffer(buf, count, &off, scp_data, size);
1082-
}
1083-
1084-
static ssize_t reipl_eckd_scpdata_write(struct file *filp, struct kobject *kobj,
1085-
struct bin_attribute *attr,
1086-
char *buf, loff_t off, size_t count)
1087-
{
1088-
size_t scpdata_len = count;
1089-
size_t padding;
1090-
1091-
if (off)
1092-
return -EINVAL;
1093-
1094-
memcpy(reipl_block_eckd->eckd.scp_data, buf, count);
1095-
if (scpdata_len % 8) {
1096-
padding = 8 - (scpdata_len % 8);
1097-
memset(reipl_block_eckd->eckd.scp_data + scpdata_len,
1098-
0, padding);
1099-
scpdata_len += padding;
1100-
}
1101-
1102-
reipl_block_eckd->hdr.len = IPL_BP_ECKD_LEN + scpdata_len;
1103-
reipl_block_eckd->eckd.len = IPL_BP0_ECKD_LEN + scpdata_len;
1104-
reipl_block_eckd->eckd.scp_data_len = scpdata_len;
1105-
1106-
return count;
1107-
}
1108-
1109-
static struct bin_attribute sys_reipl_eckd_scp_data_attr =
1110-
__BIN_ATTR(scp_data, 0644, reipl_eckd_scpdata_read,
1111-
reipl_eckd_scpdata_write, DIAG308_SCPDATA_SIZE);
1028+
DEFINE_IPL_ATTR_SCP_DATA_RW(reipl_eckd, reipl_block_eckd->hdr,
1029+
reipl_block_eckd->eckd,
1030+
IPL_BP_ECKD_LEN, IPL_BP0_ECKD_LEN,
1031+
DIAG308_SCPDATA_SIZE);
11121032

11131033
static struct bin_attribute *reipl_eckd_bin_attrs[] = {
11141034
&sys_reipl_eckd_scp_data_attr,

0 commit comments

Comments
 (0)