Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Export the iSCSI boot info to userland via sysfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2010 Red Hat, Inc.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2010 Mike Christie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/iscsi_boot_sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) MODULE_DESCRIPTION("sysfs interface and helpers to export iSCSI boot information");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * The kobject and attribute structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) struct iscsi_boot_attr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	struct attribute attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	ssize_t (*show) (void *data, int type, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * The routine called for all sysfs attributes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static ssize_t iscsi_boot_show_attribute(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 					 struct attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct iscsi_boot_kobj *boot_kobj =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 			container_of(kobj, struct iscsi_boot_kobj, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct iscsi_boot_attr *boot_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 			container_of(attr, struct iscsi_boot_attr, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	ssize_t ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	char *str = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (boot_kobj->show)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		ret = boot_kobj->show(boot_kobj->data, boot_attr->type, str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static const struct sysfs_ops iscsi_boot_attr_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.show = iscsi_boot_show_attribute,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static void iscsi_boot_kobj_release(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct iscsi_boot_kobj *boot_kobj =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			container_of(kobj, struct iscsi_boot_kobj, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (boot_kobj->release)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		boot_kobj->release(boot_kobj->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	kfree(boot_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static struct kobj_type iscsi_boot_ktype = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	.release = iscsi_boot_kobj_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	.sysfs_ops = &iscsi_boot_attr_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #define iscsi_boot_rd_attr(fnname, sysfs_name, attr_type)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static struct iscsi_boot_attr iscsi_boot_attr_##fnname = {	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	.attr	= { .name = __stringify(sysfs_name), .mode = 0444 },	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	.type	= attr_type,						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) /* Target attrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) iscsi_boot_rd_attr(tgt_index, index, ISCSI_BOOT_TGT_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) iscsi_boot_rd_attr(tgt_flags, flags, ISCSI_BOOT_TGT_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) iscsi_boot_rd_attr(tgt_ip, ip-addr, ISCSI_BOOT_TGT_IP_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) iscsi_boot_rd_attr(tgt_port, port, ISCSI_BOOT_TGT_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) iscsi_boot_rd_attr(tgt_lun, lun, ISCSI_BOOT_TGT_LUN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) iscsi_boot_rd_attr(tgt_chap, chap-type, ISCSI_BOOT_TGT_CHAP_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) iscsi_boot_rd_attr(tgt_nic, nic-assoc, ISCSI_BOOT_TGT_NIC_ASSOC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) iscsi_boot_rd_attr(tgt_name, target-name, ISCSI_BOOT_TGT_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) iscsi_boot_rd_attr(tgt_chap_name, chap-name, ISCSI_BOOT_TGT_CHAP_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) iscsi_boot_rd_attr(tgt_chap_secret, chap-secret, ISCSI_BOOT_TGT_CHAP_SECRET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) iscsi_boot_rd_attr(tgt_chap_rev_name, rev-chap-name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		   ISCSI_BOOT_TGT_REV_CHAP_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) iscsi_boot_rd_attr(tgt_chap_rev_secret, rev-chap-name-secret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		   ISCSI_BOOT_TGT_REV_CHAP_SECRET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static struct attribute *target_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	&iscsi_boot_attr_tgt_index.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	&iscsi_boot_attr_tgt_flags.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	&iscsi_boot_attr_tgt_ip.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	&iscsi_boot_attr_tgt_port.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	&iscsi_boot_attr_tgt_lun.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	&iscsi_boot_attr_tgt_chap.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	&iscsi_boot_attr_tgt_nic.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	&iscsi_boot_attr_tgt_name.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	&iscsi_boot_attr_tgt_chap_name.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	&iscsi_boot_attr_tgt_chap_secret.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	&iscsi_boot_attr_tgt_chap_rev_name.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	&iscsi_boot_attr_tgt_chap_rev_secret.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static umode_t iscsi_boot_tgt_attr_is_visible(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 					     struct attribute *attr, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct iscsi_boot_kobj *boot_kobj =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			container_of(kobj, struct iscsi_boot_kobj, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (attr ==  &iscsi_boot_attr_tgt_index.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 					     ISCSI_BOOT_TGT_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	else if (attr == &iscsi_boot_attr_tgt_flags.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 					     ISCSI_BOOT_TGT_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	else if (attr == &iscsi_boot_attr_tgt_ip.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 					      ISCSI_BOOT_TGT_IP_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	else if (attr == &iscsi_boot_attr_tgt_port.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 					      ISCSI_BOOT_TGT_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	else if (attr == &iscsi_boot_attr_tgt_lun.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 					      ISCSI_BOOT_TGT_LUN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	else if (attr == &iscsi_boot_attr_tgt_chap.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 					     ISCSI_BOOT_TGT_CHAP_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	else if (attr == &iscsi_boot_attr_tgt_nic.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 					     ISCSI_BOOT_TGT_NIC_ASSOC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	else if (attr == &iscsi_boot_attr_tgt_name.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 					     ISCSI_BOOT_TGT_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	else if (attr == &iscsi_boot_attr_tgt_chap_name.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 					     ISCSI_BOOT_TGT_CHAP_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	else if (attr == &iscsi_boot_attr_tgt_chap_secret.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 					     ISCSI_BOOT_TGT_CHAP_SECRET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	else if (attr == &iscsi_boot_attr_tgt_chap_rev_name.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 					     ISCSI_BOOT_TGT_REV_CHAP_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	else if (attr == &iscsi_boot_attr_tgt_chap_rev_secret.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 					     ISCSI_BOOT_TGT_REV_CHAP_SECRET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static struct attribute_group iscsi_boot_target_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	.attrs = target_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	.is_visible = iscsi_boot_tgt_attr_is_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /* Ethernet attrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) iscsi_boot_rd_attr(eth_index, index, ISCSI_BOOT_ETH_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) iscsi_boot_rd_attr(eth_flags, flags, ISCSI_BOOT_ETH_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) iscsi_boot_rd_attr(eth_ip, ip-addr, ISCSI_BOOT_ETH_IP_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) iscsi_boot_rd_attr(eth_prefix, prefix-len, ISCSI_BOOT_ETH_PREFIX_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) iscsi_boot_rd_attr(eth_subnet, subnet-mask, ISCSI_BOOT_ETH_SUBNET_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) iscsi_boot_rd_attr(eth_origin, origin, ISCSI_BOOT_ETH_ORIGIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) iscsi_boot_rd_attr(eth_gateway, gateway, ISCSI_BOOT_ETH_GATEWAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) iscsi_boot_rd_attr(eth_primary_dns, primary-dns, ISCSI_BOOT_ETH_PRIMARY_DNS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) iscsi_boot_rd_attr(eth_secondary_dns, secondary-dns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		   ISCSI_BOOT_ETH_SECONDARY_DNS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) iscsi_boot_rd_attr(eth_dhcp, dhcp, ISCSI_BOOT_ETH_DHCP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) iscsi_boot_rd_attr(eth_vlan, vlan, ISCSI_BOOT_ETH_VLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) iscsi_boot_rd_attr(eth_mac, mac, ISCSI_BOOT_ETH_MAC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) iscsi_boot_rd_attr(eth_hostname, hostname, ISCSI_BOOT_ETH_HOSTNAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static struct attribute *ethernet_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	&iscsi_boot_attr_eth_index.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	&iscsi_boot_attr_eth_flags.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	&iscsi_boot_attr_eth_ip.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	&iscsi_boot_attr_eth_prefix.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	&iscsi_boot_attr_eth_subnet.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	&iscsi_boot_attr_eth_origin.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	&iscsi_boot_attr_eth_gateway.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	&iscsi_boot_attr_eth_primary_dns.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	&iscsi_boot_attr_eth_secondary_dns.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	&iscsi_boot_attr_eth_dhcp.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	&iscsi_boot_attr_eth_vlan.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	&iscsi_boot_attr_eth_mac.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	&iscsi_boot_attr_eth_hostname.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static umode_t iscsi_boot_eth_attr_is_visible(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 					     struct attribute *attr, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct iscsi_boot_kobj *boot_kobj =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			container_of(kobj, struct iscsi_boot_kobj, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (attr ==  &iscsi_boot_attr_eth_index.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 					     ISCSI_BOOT_ETH_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	else if (attr ==  &iscsi_boot_attr_eth_flags.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 					     ISCSI_BOOT_ETH_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	else if (attr ==  &iscsi_boot_attr_eth_ip.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 					     ISCSI_BOOT_ETH_IP_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	else if (attr ==  &iscsi_boot_attr_eth_prefix.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 					     ISCSI_BOOT_ETH_PREFIX_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	else if (attr ==  &iscsi_boot_attr_eth_subnet.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 					     ISCSI_BOOT_ETH_SUBNET_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	else if (attr ==  &iscsi_boot_attr_eth_origin.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 					     ISCSI_BOOT_ETH_ORIGIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	else if (attr ==  &iscsi_boot_attr_eth_gateway.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 					     ISCSI_BOOT_ETH_GATEWAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	else if (attr ==  &iscsi_boot_attr_eth_primary_dns.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 					     ISCSI_BOOT_ETH_PRIMARY_DNS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	else if (attr ==  &iscsi_boot_attr_eth_secondary_dns.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 					     ISCSI_BOOT_ETH_SECONDARY_DNS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	else if (attr ==  &iscsi_boot_attr_eth_dhcp.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 					     ISCSI_BOOT_ETH_DHCP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	else if (attr ==  &iscsi_boot_attr_eth_vlan.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 					     ISCSI_BOOT_ETH_VLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	else if (attr ==  &iscsi_boot_attr_eth_mac.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 					     ISCSI_BOOT_ETH_MAC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	else if (attr ==  &iscsi_boot_attr_eth_hostname.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 					     ISCSI_BOOT_ETH_HOSTNAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static struct attribute_group iscsi_boot_ethernet_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	.attrs = ethernet_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	.is_visible = iscsi_boot_eth_attr_is_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /* Initiator attrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) iscsi_boot_rd_attr(ini_index, index, ISCSI_BOOT_INI_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) iscsi_boot_rd_attr(ini_flags, flags, ISCSI_BOOT_INI_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) iscsi_boot_rd_attr(ini_isns, isns-server, ISCSI_BOOT_INI_ISNS_SERVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) iscsi_boot_rd_attr(ini_slp, slp-server, ISCSI_BOOT_INI_SLP_SERVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) iscsi_boot_rd_attr(ini_primary_radius, pri-radius-server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		   ISCSI_BOOT_INI_PRI_RADIUS_SERVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) iscsi_boot_rd_attr(ini_secondary_radius, sec-radius-server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		   ISCSI_BOOT_INI_SEC_RADIUS_SERVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) iscsi_boot_rd_attr(ini_name, initiator-name, ISCSI_BOOT_INI_INITIATOR_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static struct attribute *initiator_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	&iscsi_boot_attr_ini_index.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	&iscsi_boot_attr_ini_flags.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	&iscsi_boot_attr_ini_isns.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	&iscsi_boot_attr_ini_slp.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	&iscsi_boot_attr_ini_primary_radius.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	&iscsi_boot_attr_ini_secondary_radius.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	&iscsi_boot_attr_ini_name.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static umode_t iscsi_boot_ini_attr_is_visible(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 					     struct attribute *attr, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	struct iscsi_boot_kobj *boot_kobj =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			container_of(kobj, struct iscsi_boot_kobj, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (attr ==  &iscsi_boot_attr_ini_index.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 					     ISCSI_BOOT_INI_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	if (attr ==  &iscsi_boot_attr_ini_flags.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 					     ISCSI_BOOT_INI_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (attr ==  &iscsi_boot_attr_ini_isns.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 					     ISCSI_BOOT_INI_ISNS_SERVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	if (attr ==  &iscsi_boot_attr_ini_slp.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 					     ISCSI_BOOT_INI_SLP_SERVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (attr ==  &iscsi_boot_attr_ini_primary_radius.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 					     ISCSI_BOOT_INI_PRI_RADIUS_SERVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	if (attr ==  &iscsi_boot_attr_ini_secondary_radius.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 					     ISCSI_BOOT_INI_SEC_RADIUS_SERVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (attr ==  &iscsi_boot_attr_ini_name.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 					     ISCSI_BOOT_INI_INITIATOR_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static struct attribute_group iscsi_boot_initiator_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	.attrs = initiator_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	.is_visible = iscsi_boot_ini_attr_is_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /* iBFT ACPI Table attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) iscsi_boot_rd_attr(acpitbl_signature, signature, ISCSI_BOOT_ACPITBL_SIGNATURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) iscsi_boot_rd_attr(acpitbl_oem_id, oem_id, ISCSI_BOOT_ACPITBL_OEM_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) iscsi_boot_rd_attr(acpitbl_oem_table_id, oem_table_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		   ISCSI_BOOT_ACPITBL_OEM_TABLE_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static struct attribute *acpitbl_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	&iscsi_boot_attr_acpitbl_signature.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	&iscsi_boot_attr_acpitbl_oem_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	&iscsi_boot_attr_acpitbl_oem_table_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static umode_t iscsi_boot_acpitbl_attr_is_visible(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 					     struct attribute *attr, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	struct iscsi_boot_kobj *boot_kobj =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			container_of(kobj, struct iscsi_boot_kobj, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	if (attr ==  &iscsi_boot_attr_acpitbl_signature.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 					     ISCSI_BOOT_ACPITBL_SIGNATURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (attr ==  &iscsi_boot_attr_acpitbl_oem_id.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 					     ISCSI_BOOT_ACPITBL_OEM_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	if (attr ==  &iscsi_boot_attr_acpitbl_oem_table_id.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		return boot_kobj->is_visible(boot_kobj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 					     ISCSI_BOOT_ACPITBL_OEM_TABLE_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static struct attribute_group iscsi_boot_acpitbl_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	.attrs = acpitbl_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	.is_visible = iscsi_boot_acpitbl_attr_is_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) static struct iscsi_boot_kobj *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) iscsi_boot_create_kobj(struct iscsi_boot_kset *boot_kset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		       struct attribute_group *attr_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		       const char *name, int index, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		       ssize_t (*show) (void *data, int type, char *buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		       umode_t (*is_visible) (void *data, int type),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		       void (*release) (void *data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	struct iscsi_boot_kobj *boot_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	boot_kobj = kzalloc(sizeof(*boot_kobj), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	if (!boot_kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	INIT_LIST_HEAD(&boot_kobj->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	boot_kobj->kobj.kset = boot_kset->kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	if (kobject_init_and_add(&boot_kobj->kobj, &iscsi_boot_ktype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 				 NULL, name, index)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		kobject_put(&boot_kobj->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	boot_kobj->data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	boot_kobj->show = show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	boot_kobj->is_visible = is_visible;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	boot_kobj->release = release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (sysfs_create_group(&boot_kobj->kobj, attr_group)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		 * We do not want to free this because the caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		 * will assume that since the creation call failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		 * the boot kobj was not setup and the normal release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		 * path is not being run.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		boot_kobj->release = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		kobject_put(&boot_kobj->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	boot_kobj->attr_group = attr_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	kobject_uevent(&boot_kobj->kobj, KOBJ_ADD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	/* Nothing broke so lets add it to the list. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	list_add_tail(&boot_kobj->list, &boot_kset->kobj_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	return boot_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static void iscsi_boot_remove_kobj(struct iscsi_boot_kobj *boot_kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	list_del(&boot_kobj->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	sysfs_remove_group(&boot_kobj->kobj, boot_kobj->attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	kobject_put(&boot_kobj->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)  * iscsi_boot_create_target() - create boot target sysfs dir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)  * @boot_kset: boot kset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  * @index: the target id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)  * @data: driver specific data for target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)  * @show: attr show function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)  * @is_visible: attr visibility function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)  * @release: release function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)  * Note: The boot sysfs lib will free the data passed in for the caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)  * when all refs to the target kobject have been released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct iscsi_boot_kobj *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) iscsi_boot_create_target(struct iscsi_boot_kset *boot_kset, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			 void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			 ssize_t (*show) (void *data, int type, char *buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			 umode_t (*is_visible) (void *data, int type),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 			 void (*release) (void *data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	return iscsi_boot_create_kobj(boot_kset, &iscsi_boot_target_attr_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 				      "target%d", index, data, show, is_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 				      release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) EXPORT_SYMBOL_GPL(iscsi_boot_create_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)  * iscsi_boot_create_initiator() - create boot initiator sysfs dir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)  * @boot_kset: boot kset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)  * @index: the initiator id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)  * @data: driver specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)  * @show: attr show function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)  * @is_visible: attr visibility function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)  * @release: release function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)  * Note: The boot sysfs lib will free the data passed in for the caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)  * when all refs to the initiator kobject have been released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) struct iscsi_boot_kobj *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) iscsi_boot_create_initiator(struct iscsi_boot_kset *boot_kset, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 			    void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			    ssize_t (*show) (void *data, int type, char *buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 			    umode_t (*is_visible) (void *data, int type),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 			    void (*release) (void *data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	return iscsi_boot_create_kobj(boot_kset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 				      &iscsi_boot_initiator_attr_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 				      "initiator", index, data, show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 				      is_visible, release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) EXPORT_SYMBOL_GPL(iscsi_boot_create_initiator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)  * iscsi_boot_create_ethernet() - create boot ethernet sysfs dir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)  * @boot_kset: boot kset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)  * @index: the ethernet device id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)  * @data: driver specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)  * @show: attr show function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)  * @is_visible: attr visibility function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)  * @release: release function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)  * Note: The boot sysfs lib will free the data passed in for the caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)  * when all refs to the ethernet kobject have been released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct iscsi_boot_kobj *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) iscsi_boot_create_ethernet(struct iscsi_boot_kset *boot_kset, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 			   void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 			   ssize_t (*show) (void *data, int type, char *buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 			   umode_t (*is_visible) (void *data, int type),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 			   void (*release) (void *data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	return iscsi_boot_create_kobj(boot_kset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 				      &iscsi_boot_ethernet_attr_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 				      "ethernet%d", index, data, show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 				      is_visible, release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) EXPORT_SYMBOL_GPL(iscsi_boot_create_ethernet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)  * iscsi_boot_create_acpitbl() - create boot acpi table sysfs dir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)  * @boot_kset: boot kset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)  * @index: not used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)  * @data: driver specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)  * @show: attr show function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)  * @is_visible: attr visibility function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)  * @release: release function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)  * Note: The boot sysfs lib will free the data passed in for the caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)  * when all refs to the acpitbl kobject have been released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) struct iscsi_boot_kobj *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) iscsi_boot_create_acpitbl(struct iscsi_boot_kset *boot_kset, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 			   void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 			   ssize_t (*show)(void *data, int type, char *buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 			   umode_t (*is_visible)(void *data, int type),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 			   void (*release)(void *data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	return iscsi_boot_create_kobj(boot_kset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 				      &iscsi_boot_acpitbl_attr_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 				      "acpi_header", index, data, show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 				      is_visible, release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) EXPORT_SYMBOL_GPL(iscsi_boot_create_acpitbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)  * iscsi_boot_create_kset() - creates root sysfs tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)  * @set_name: name of root dir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) struct iscsi_boot_kset *iscsi_boot_create_kset(const char *set_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	struct iscsi_boot_kset *boot_kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	boot_kset = kzalloc(sizeof(*boot_kset), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	if (!boot_kset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	boot_kset->kset = kset_create_and_add(set_name, NULL, firmware_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	if (!boot_kset->kset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		kfree(boot_kset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	INIT_LIST_HEAD(&boot_kset->kobj_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	return boot_kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) EXPORT_SYMBOL_GPL(iscsi_boot_create_kset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)  * iscsi_boot_create_host_kset() - creates root sysfs tree for a scsi host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)  * @hostno: host number of scsi host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) struct iscsi_boot_kset *iscsi_boot_create_host_kset(unsigned int hostno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	struct iscsi_boot_kset *boot_kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	char *set_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	set_name = kasprintf(GFP_KERNEL, "iscsi_boot%u", hostno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	if (!set_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	boot_kset = iscsi_boot_create_kset(set_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	kfree(set_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	return boot_kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) EXPORT_SYMBOL_GPL(iscsi_boot_create_host_kset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)  * iscsi_boot_destroy_kset() - destroy kset and kobjects under it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)  * @boot_kset: boot kset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)  * This will remove the kset and kobjects and attrs under it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) void iscsi_boot_destroy_kset(struct iscsi_boot_kset *boot_kset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	struct iscsi_boot_kobj *boot_kobj, *tmp_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	if (!boot_kset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	list_for_each_entry_safe(boot_kobj, tmp_kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 				 &boot_kset->kobj_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 		iscsi_boot_remove_kobj(boot_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	kset_unregister(boot_kset->kset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	kfree(boot_kset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) EXPORT_SYMBOL_GPL(iscsi_boot_destroy_kset);