From d289bf7bdd84d636054acb0b3d14a4708f8a8233 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Wed, 20 Feb 2008 13:20:50 -0800 Subject: firmware: move firmware_class from Documentation/ to samples/ Move the firmware_class sample drivers to samples/ so that they are buildable and can be maintained. Signed-off-by: Randy Dunlap Acked-by: Marcel Holtmann Signed-off-by: Greg Kroah-Hartman --- .../firmware_class/firmware_sample_driver.c | 115 ------------ .../firmware_sample_firmware_class.c | 207 --------------------- 2 files changed, 322 deletions(-) delete mode 100644 Documentation/firmware_class/firmware_sample_driver.c delete mode 100644 Documentation/firmware_class/firmware_sample_firmware_class.c (limited to 'Documentation') diff --git a/Documentation/firmware_class/firmware_sample_driver.c b/Documentation/firmware_class/firmware_sample_driver.c deleted file mode 100644 index 6865cbe075ec..000000000000 --- a/Documentation/firmware_class/firmware_sample_driver.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * firmware_sample_driver.c - - * - * Copyright (c) 2003 Manuel Estrada Sainz - * - * Sample code on how to use request_firmware() from drivers. - * - */ - -#include -#include -#include -#include -#include - -#include "linux/firmware.h" - -static struct device ghost_device = { - .bus_id = "ghost0", -}; - - -static void sample_firmware_load(char *firmware, int size) -{ - u8 buf[size+1]; - memcpy(buf, firmware, size); - buf[size] = '\0'; - printk(KERN_INFO "firmware_sample_driver: firmware: %s\n", buf); -} - -static void sample_probe_default(void) -{ - /* uses the default method to get the firmware */ - const struct firmware *fw_entry; - printk(KERN_INFO "firmware_sample_driver: a ghost device got inserted :)\n"); - - if(request_firmware(&fw_entry, "sample_driver_fw", &ghost_device)!=0) - { - printk(KERN_ERR - "firmware_sample_driver: Firmware not available\n"); - return; - } - - sample_firmware_load(fw_entry->data, fw_entry->size); - - release_firmware(fw_entry); - - /* finish setting up the device */ -} -static void sample_probe_specific(void) -{ - /* Uses some specific hotplug support to get the firmware from - * userspace directly into the hardware, or via some sysfs file */ - - /* NOTE: This currently doesn't work */ - - printk(KERN_INFO "firmware_sample_driver: a ghost device got inserted :)\n"); - - if(request_firmware(NULL, "sample_driver_fw", &ghost_device)!=0) - { - printk(KERN_ERR - "firmware_sample_driver: Firmware load failed\n"); - return; - } - - /* request_firmware blocks until userspace finished, so at - * this point the firmware should be already in the device */ - - /* finish setting up the device */ -} -static void sample_probe_async_cont(const struct firmware *fw, void *context) -{ - if(!fw){ - printk(KERN_ERR - "firmware_sample_driver: firmware load failed\n"); - return; - } - - printk(KERN_INFO "firmware_sample_driver: device pointer \"%s\"\n", - (char *)context); - sample_firmware_load(fw->data, fw->size); -} -static void sample_probe_async(void) -{ - /* Let's say that I can't sleep */ - int error; - error = request_firmware_nowait (THIS_MODULE, FW_ACTION_NOHOTPLUG, - "sample_driver_fw", &ghost_device, - "my device pointer", - sample_probe_async_cont); - if(error){ - printk(KERN_ERR - "firmware_sample_driver:" - " request_firmware_nowait failed\n"); - } -} - -static int sample_init(void) -{ - device_initialize(&ghost_device); - /* since there is no real hardware insertion I just call the - * sample probe functions here */ - sample_probe_specific(); - sample_probe_default(); - sample_probe_async(); - return 0; -} -static void __exit sample_exit(void) -{ -} - -module_init (sample_init); -module_exit (sample_exit); - -MODULE_LICENSE("GPL"); diff --git a/Documentation/firmware_class/firmware_sample_firmware_class.c b/Documentation/firmware_class/firmware_sample_firmware_class.c deleted file mode 100644 index 2de62854f0e5..000000000000 --- a/Documentation/firmware_class/firmware_sample_firmware_class.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * firmware_sample_firmware_class.c - - * - * Copyright (c) 2003 Manuel Estrada Sainz - * - * NOTE: This is just a probe of concept, if you think that your driver would - * be well served by this mechanism please contact me first. - * - * DON'T USE THIS CODE AS IS - * - */ - -#include -#include -#include -#include -#include -#include -#include - - -MODULE_AUTHOR("Manuel Estrada Sainz"); -MODULE_DESCRIPTION("Hackish sample for using firmware class directly"); -MODULE_LICENSE("GPL"); - -static inline struct class_device *to_class_dev(struct kobject *obj) -{ - return container_of(obj,struct class_device,kobj); -} -static inline -struct class_device_attribute *to_class_dev_attr(struct attribute *_attr) -{ - return container_of(_attr,struct class_device_attribute,attr); -} - -int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr); -int sysfs_remove_bin_file(struct kobject * kobj, struct bin_attribute * attr); - -struct firmware_priv { - char fw_id[FIRMWARE_NAME_MAX]; - s32 loading:2; - u32 abort:1; -}; - -extern struct class firmware_class; - -static ssize_t firmware_loading_show(struct class_device *class_dev, char *buf) -{ - struct firmware_priv *fw_priv = class_get_devdata(class_dev); - return sprintf(buf, "%d\n", fw_priv->loading); -} -static ssize_t firmware_loading_store(struct class_device *class_dev, - const char *buf, size_t count) -{ - struct firmware_priv *fw_priv = class_get_devdata(class_dev); - int prev_loading = fw_priv->loading; - - fw_priv->loading = simple_strtol(buf, NULL, 10); - - switch(fw_priv->loading){ - case -1: - /* abort load an panic */ - break; - case 1: - /* setup load */ - break; - case 0: - if(prev_loading==1){ - /* finish load and get the device back to working - * state */ - } - break; - } - - return count; -} -static CLASS_DEVICE_ATTR(loading, 0644, - firmware_loading_show, firmware_loading_store); - -static ssize_t firmware_data_read(struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buffer, loff_t offset, size_t count) -{ - struct class_device *class_dev = to_class_dev(kobj); - struct firmware_priv *fw_priv = class_get_devdata(class_dev); - - /* read from the devices firmware memory */ - - return count; -} -static ssize_t firmware_data_write(struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buffer, loff_t offset, size_t count) -{ - struct class_device *class_dev = to_class_dev(kobj); - struct firmware_priv *fw_priv = class_get_devdata(class_dev); - - /* write to the devices firmware memory */ - - return count; -} -static struct bin_attribute firmware_attr_data = { - .attr = {.name = "data", .mode = 0644}, - .size = 0, - .read = firmware_data_read, - .write = firmware_data_write, -}; -static int fw_setup_class_device(struct class_device *class_dev, - const char *fw_name, - struct device *device) -{ - int retval; - struct firmware_priv *fw_priv; - - fw_priv = kzalloc(sizeof(struct firmware_priv), GFP_KERNEL); - if (!fw_priv) { - retval = -ENOMEM; - goto out; - } - - memset(class_dev, 0, sizeof(*class_dev)); - - strncpy(fw_priv->fw_id, fw_name, FIRMWARE_NAME_MAX); - fw_priv->fw_id[FIRMWARE_NAME_MAX-1] = '\0'; - - strncpy(class_dev->class_id, device->bus_id, BUS_ID_SIZE); - class_dev->class_id[BUS_ID_SIZE-1] = '\0'; - class_dev->dev = device; - - class_dev->class = &firmware_class, - class_set_devdata(class_dev, fw_priv); - retval = class_device_register(class_dev); - if (retval){ - printk(KERN_ERR "%s: class_device_register failed\n", - __FUNCTION__); - goto error_free_fw_priv; - } - - retval = sysfs_create_bin_file(&class_dev->kobj, &firmware_attr_data); - if (retval){ - printk(KERN_ERR "%s: sysfs_create_bin_file failed\n", - __FUNCTION__); - goto error_unreg_class_dev; - } - - retval = class_device_create_file(class_dev, - &class_device_attr_loading); - if (retval){ - printk(KERN_ERR "%s: class_device_create_file failed\n", - __FUNCTION__); - goto error_remove_data; - } - - goto out; - -error_remove_data: - sysfs_remove_bin_file(&class_dev->kobj, &firmware_attr_data); -error_unreg_class_dev: - class_device_unregister(class_dev); -error_free_fw_priv: - kfree(fw_priv); -out: - return retval; -} -static void fw_remove_class_device(struct class_device *class_dev) -{ - struct firmware_priv *fw_priv = class_get_devdata(class_dev); - - class_device_remove_file(class_dev, &class_device_attr_loading); - sysfs_remove_bin_file(&class_dev->kobj, &firmware_attr_data); - class_device_unregister(class_dev); -} - -static struct class_device *class_dev; - -static struct device my_device = { - .bus_id = "my_dev0", -}; - -static int __init firmware_sample_init(void) -{ - int error; - - device_initialize(&my_device); - class_dev = kmalloc(sizeof(struct class_device), GFP_KERNEL); - if(!class_dev) - return -ENOMEM; - - error = fw_setup_class_device(class_dev, "my_firmware_image", - &my_device); - if(error){ - kfree(class_dev); - return error; - } - return 0; - -} -static void __exit firmware_sample_exit(void) -{ - struct firmware_priv *fw_priv = class_get_devdata(class_dev); - fw_remove_class_device(class_dev); - kfree(fw_priv); - kfree(class_dev); -} -module_init(firmware_sample_init); -module_exit(firmware_sample_exit); - -- cgit v1.2.3 From 58aca23226a19983571bd3b65167521fc64f5869 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Wed, 12 Mar 2008 00:57:22 +0100 Subject: PM: Handle device registrations during suspend/resume Modify the PM core to protect its data structures, specifically the dpm_active list, from being corrupted if a child of the currently suspending device is registered concurrently with its ->suspend() callback. In that case, since the new device (the child) is added to dpm_active after its parent, the PM core will attempt to suspend it after the parent, which is wrong. Introduce a new member of struct dev_pm_info, called 'sleeping', and use it to check if the parent of the device being added to dpm_active has been suspended, in which case the device registration fails. Also, use 'sleeping' for checking if the ordering of devices on dpm_active is correct. Introduce variable 'all_sleeping' that will be set to 'true' once all devices have been suspended and make new device registrations fail until 'all_sleeping' is reset to 'false', in order to avoid having unsuspended devices around while the system is going into a sleep state. Remove pm_sleep_rwsem which is not necessary any more. Special thanks to Alan Stern for discussions and suggestions that lead to the creation of this patch. Signed-off-by: Rafael J. Wysocki Acked-by: Pavel Machek Signed-off-by: Greg Kroah-Hartman --- Documentation/power/devices.txt | 5 ++++ drivers/base/core.c | 6 ++++- drivers/base/power/main.c | 57 +++++++++++++++++++---------------------- drivers/base/power/power.h | 23 +++-------------- include/linux/pm.h | 1 + 5 files changed, 40 insertions(+), 52 deletions(-) (limited to 'Documentation') diff --git a/Documentation/power/devices.txt b/Documentation/power/devices.txt index 461e4f1dbec4..421e7d00ffd0 100644 --- a/Documentation/power/devices.txt +++ b/Documentation/power/devices.txt @@ -196,6 +196,11 @@ its parent; and can't be removed or suspended after that parent. The policy is that the device tree should match hardware bus topology. (Or at least the control bus, for devices which use multiple busses.) +In particular, this means that a device registration may fail if the parent of +the device is suspending (ie. has been chosen by the PM core as the next +device to suspend) or has already suspended, as well as after all of the other +devices have been suspended. Device drivers must be prepared to cope with such +situations. Suspending Devices diff --git a/drivers/base/core.c b/drivers/base/core.c index 24198ad01976..79848e6c5db5 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -820,7 +820,11 @@ int device_add(struct device *dev) error = dpm_sysfs_add(dev); if (error) goto PMError; - device_pm_add(dev); + error = device_pm_add(dev); + if (error) { + dpm_sysfs_remove(dev); + goto PMError; + } error = bus_add_device(dev); if (error) goto BusError; diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 26de2c0fda80..0e3991a437c6 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -54,7 +54,8 @@ static LIST_HEAD(dpm_destroy); static DEFINE_MUTEX(dpm_list_mtx); -static DECLARE_RWSEM(pm_sleep_rwsem); +/* 'true' if all devices have been suspended, protected by dpm_list_mtx */ +static bool all_sleeping; int (*platform_enable_wakeup)(struct device *dev, int is_on); @@ -62,14 +63,28 @@ int (*platform_enable_wakeup)(struct device *dev, int is_on); * device_pm_add - add a device to the list of active devices * @dev: Device to be added to the list */ -void device_pm_add(struct device *dev) +int device_pm_add(struct device *dev) { + int error = 0; + pr_debug("PM: Adding info for %s:%s\n", dev->bus ? dev->bus->name : "No Bus", kobject_name(&dev->kobj)); mutex_lock(&dpm_list_mtx); - list_add_tail(&dev->power.entry, &dpm_active); + if ((dev->parent && dev->parent->power.sleeping) || all_sleeping) { + if (dev->parent->power.sleeping) + dev_warn(dev, + "parent %s is sleeping, will not add\n", + dev->parent->bus_id); + else + dev_warn(dev, "devices are sleeping, will not add\n"); + WARN_ON(true); + error = -EBUSY; + } else { + list_add_tail(&dev->power.entry, &dpm_active); + } mutex_unlock(&dpm_list_mtx); + return error; } /** @@ -107,32 +122,6 @@ void device_pm_schedule_removal(struct device *dev) } EXPORT_SYMBOL_GPL(device_pm_schedule_removal); -/** - * pm_sleep_lock - mutual exclusion for registration and suspend - * - * Returns 0 if no suspend is underway and device registration - * may proceed, otherwise -EBUSY. - */ -int pm_sleep_lock(void) -{ - if (down_read_trylock(&pm_sleep_rwsem)) - return 0; - - return -EBUSY; -} - -/** - * pm_sleep_unlock - mutual exclusion for registration and suspend - * - * This routine undoes the effect of device_pm_add_lock - * when a device's registration is complete. - */ -void pm_sleep_unlock(void) -{ - up_read(&pm_sleep_rwsem); -} - - /*------------------------- Resume routines -------------------------*/ /** @@ -242,11 +231,13 @@ static int resume_device(struct device *dev) static void dpm_resume(void) { mutex_lock(&dpm_list_mtx); + all_sleeping = false; while(!list_empty(&dpm_off)) { struct list_head *entry = dpm_off.next; struct device *dev = to_device(entry); list_move_tail(entry, &dpm_active); + dev->power.sleeping = false; mutex_unlock(&dpm_list_mtx); resume_device(dev); mutex_lock(&dpm_list_mtx); @@ -285,7 +276,6 @@ void device_resume(void) might_sleep(); dpm_resume(); unregister_dropped_devices(); - up_write(&pm_sleep_rwsem); } EXPORT_SYMBOL_GPL(device_resume); @@ -421,6 +411,9 @@ static int dpm_suspend(pm_message_t state) struct list_head *entry = dpm_active.prev; struct device *dev = to_device(entry); + WARN_ON(dev->parent && dev->parent->power.sleeping); + + dev->power.sleeping = true; mutex_unlock(&dpm_list_mtx); error = suspend_device(dev, state); mutex_lock(&dpm_list_mtx); @@ -432,11 +425,14 @@ static int dpm_suspend(pm_message_t state) (error == -EAGAIN ? " (please convert to suspend_late)" : "")); + dev->power.sleeping = false; break; } if (!list_empty(&dev->power.entry)) list_move(&dev->power.entry, &dpm_off); } + if (!error) + all_sleeping = true; mutex_unlock(&dpm_list_mtx); return error; @@ -454,7 +450,6 @@ int device_suspend(pm_message_t state) int error; might_sleep(); - down_write(&pm_sleep_rwsem); error = dpm_suspend(state); if (error) device_resume(); diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h index e32d3bdb92c1..a6894f2a4b99 100644 --- a/drivers/base/power/power.h +++ b/drivers/base/power/power.h @@ -11,30 +11,13 @@ static inline struct device *to_device(struct list_head *entry) return container_of(entry, struct device, power.entry); } -extern void device_pm_add(struct device *); +extern int device_pm_add(struct device *); extern void device_pm_remove(struct device *); -extern int pm_sleep_lock(void); -extern void pm_sleep_unlock(void); #else /* CONFIG_PM_SLEEP */ - -static inline void device_pm_add(struct device *dev) -{ -} - -static inline void device_pm_remove(struct device *dev) -{ -} - -static inline int pm_sleep_lock(void) -{ - return 0; -} - -static inline void pm_sleep_unlock(void) -{ -} +static inline int device_pm_add(struct device *dev) { return 0; } +static inline void device_pm_remove(struct device *dev) {} #endif diff --git a/include/linux/pm.h b/include/linux/pm.h index 015b735811b4..e6b9f29e27d7 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -183,6 +183,7 @@ typedef struct pm_message { struct dev_pm_info { pm_message_t power_state; unsigned can_wakeup:1; + bool sleeping:1; /* Owned by the PM core */ #ifdef CONFIG_PM_SLEEP unsigned should_wakeup:1; struct list_head entry; -- cgit v1.2.3 From 95bc6a10830de469eee94c17fb1c37b3b1430715 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Fri, 28 Mar 2008 14:22:52 -0700 Subject: PM: Remove legacy PM (fix) Source file was removed. Need to remove docbook reference also. Signed-off-by: Randy Dunlap Cc: Pavel Machek Cc: Rafael J. Wysocki Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- Documentation/DocBook/kernel-api.tmpl | 5 ----- 1 file changed, 5 deletions(-) (limited to 'Documentation') diff --git a/Documentation/DocBook/kernel-api.tmpl b/Documentation/DocBook/kernel-api.tmpl index dc0f30c3e571..488dd4a4945b 100644 --- a/Documentation/DocBook/kernel-api.tmpl +++ b/Documentation/DocBook/kernel-api.tmpl @@ -297,11 +297,6 @@ X!Earch/x86/kernel/mca_32.c !Ikernel/acct.c - - Power Management -!Ekernel/power/pm.c - - Device drivers infrastructure Device Drivers Base -- cgit v1.2.3 From 138fe4e069798d9aa948a5402ff15e58f483ee4e Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Date: Wed, 9 Apr 2008 19:50:41 -0700 Subject: Firmware: add iSCSI iBFT Support Add /sysfs/firmware/ibft/[initiator|targetX|ethernetX] directories along with text properties which export the the iSCSI Boot Firmware Table (iBFT) structure. What is iSCSI Boot Firmware Table? It is a mechanism for the iSCSI tools to extract from the machine NICs the iSCSI connection information so that they can automagically mount the iSCSI share/target. Currently the iSCSI information is hard-coded in the initrd. The /sysfs entries are read-only one-name-and-value fields. The usual set of data exposed is: # for a in `find /sys/firmware/ibft/ -type f -print`; do echo -n "$a: "; cat $a; done /sys/firmware/ibft/target0/target-name: iqn.2007.com.intel-sbx44:storage-10gb /sys/firmware/ibft/target0/nic-assoc: 0 /sys/firmware/ibft/target0/chap-type: 0 /sys/firmware/ibft/target0/lun: 00000000 /sys/firmware/ibft/target0/port: 3260 /sys/firmware/ibft/target0/ip-addr: 192.168.79.116 /sys/firmware/ibft/target0/flags: 3 /sys/firmware/ibft/target0/index: 0 /sys/firmware/ibft/ethernet0/mac: 00:11:25:9d:8b:01 /sys/firmware/ibft/ethernet0/vlan: 0 /sys/firmware/ibft/ethernet0/gateway: 192.168.79.254 /sys/firmware/ibft/ethernet0/origin: 0 /sys/firmware/ibft/ethernet0/subnet-mask: 255.255.252.0 /sys/firmware/ibft/ethernet0/ip-addr: 192.168.77.41 /sys/firmware/ibft/ethernet0/flags: 7 /sys/firmware/ibft/ethernet0/index: 0 /sys/firmware/ibft/initiator/initiator-name: iqn.2007-07.com:konrad.initiator /sys/firmware/ibft/initiator/flags: 3 /sys/firmware/ibft/initiator/index: 0 For full details of the IBFT structure please take a look at: ftp://ftp.software.ibm.com/systems/support/system_x_pdf/ibm_iscsi_boot_firmware_table_v1.02.pdf [akpm@linux-foundation.org: fix build] Signed-off-by: Konrad Rzeszutek Cc: Mike Christie Cc: Peter Jones Cc: James Bottomley Cc: Ingo Molnar Cc: Thomas Gleixner Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- Documentation/ABI/testing/sysfs-ibft | 23 + arch/x86/kernel/setup_32.c | 3 + arch/x86/kernel/setup_64.c | 4 + drivers/firmware/Kconfig | 20 + drivers/firmware/Makefile | 2 + drivers/firmware/iscsi_ibft.c | 982 +++++++++++++++++++++++++++++++++++ drivers/firmware/iscsi_ibft_find.c | 84 +++ include/linux/iscsi_ibft.h | 50 ++ 8 files changed, 1168 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-ibft create mode 100644 drivers/firmware/iscsi_ibft.c create mode 100644 drivers/firmware/iscsi_ibft_find.c create mode 100644 include/linux/iscsi_ibft.h (limited to 'Documentation') diff --git a/Documentation/ABI/testing/sysfs-ibft b/Documentation/ABI/testing/sysfs-ibft new file mode 100644 index 000000000000..c2b7d1154bec --- /dev/null +++ b/Documentation/ABI/testing/sysfs-ibft @@ -0,0 +1,23 @@ +What: /sys/firmware/ibft/initiator +Date: November 2007 +Contact: Konrad Rzeszutek +Description: The /sys/firmware/ibft/initiator directory will contain + files that expose the iSCSI Boot Firmware Table initiator data. + Usually this contains the Initiator name. + +What: /sys/firmware/ibft/targetX +Date: November 2007 +Contact: Konrad Rzeszutek +Description: The /sys/firmware/ibft/targetX directory will contain + files that expose the iSCSI Boot Firmware Table target data. + Usually this contains the target's IP address, boot LUN, + target name, and what NIC it is associated with. It can also + contain the CHAP name (and password), the reverse CHAP + name (and password) + +What: /sys/firmware/ibft/ethernetX +Date: November 2007 +Contact: Konrad Rzeszutek +Description: The /sys/firmware/ibft/ethernetX directory will contain + files that expose the iSCSI Boot Firmware Table NIC data. + This can this can the IP address, MAC, and gateway of the NIC. diff --git a/arch/x86/kernel/setup_32.c b/arch/x86/kernel/setup_32.c index 5b0bffb7fcc9..4ef91749959e 100644 --- a/arch/x86/kernel/setup_32.c +++ b/arch/x86/kernel/setup_32.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -689,6 +690,8 @@ void __init setup_bootmem_allocator(void) #endif numa_kva_reserve(); reserve_crashkernel(); + + reserve_ibft_region(); } /* diff --git a/arch/x86/kernel/setup_64.c b/arch/x86/kernel/setup_64.c index 674ef3510cdf..216c93bd9993 100644 --- a/arch/x86/kernel/setup_64.c +++ b/arch/x86/kernel/setup_64.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -434,6 +435,9 @@ void __init setup_arch(char **cmdline_p) } #endif reserve_crashkernel(); + + reserve_ibft_region(); + paging_init(); map_vsyscall(); diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index 05f02a326f1c..40ffd767647d 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -93,4 +93,24 @@ config DMIID information from userspace through /sys/class/dmi/id/ or if you want DMI-based module auto-loading. +config ISCSI_IBFT_FIND + bool "iSCSI Boot Firmware Table Attributes" + depends on X86 + default n + help + This option enables the kernel to find the region of memory + in which the ISCSI Boot Firmware Table (iBFT) resides. This + is necessary for iSCSI Boot Firmware Table Attributes module to work + properly. + +config ISCSI_IBFT + tristate "iSCSI Boot Firmware Table Attributes module" + depends on ISCSI_IBFT_FIND + default n + help + This option enables support for detection and exposing of iSCSI + Boot Firmware Table (iBFT) via sysfs to userspace. If you wish to + detect iSCSI boot parameters dynamically during system boot, say Y. + Otherwise, say N. + endmenu diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile index 8d4ebc805a50..4c9147154df8 100644 --- a/drivers/firmware/Makefile +++ b/drivers/firmware/Makefile @@ -8,3 +8,5 @@ obj-$(CONFIG_EFI_PCDP) += pcdp.o obj-$(CONFIG_DELL_RBU) += dell_rbu.o obj-$(CONFIG_DCDBAS) += dcdbas.o obj-$(CONFIG_DMIID) += dmi-id.o +obj-$(CONFIG_ISCSI_IBFT_FIND) += iscsi_ibft_find.o +obj-$(CONFIG_ISCSI_IBFT) += iscsi_ibft.o diff --git a/drivers/firmware/iscsi_ibft.c b/drivers/firmware/iscsi_ibft.c new file mode 100644 index 000000000000..8024e3bfd877 --- /dev/null +++ b/drivers/firmware/iscsi_ibft.c @@ -0,0 +1,982 @@ +/* + * Copyright 2007 Red Hat, Inc. + * by Peter Jones + * Copyright 2008 IBM, Inc. + * by Konrad Rzeszutek + * Copyright 2008 + * by Konrad Rzeszutek + * + * This code exposes the iSCSI Boot Format Table to userland via sysfs. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License v2.0 as published by + * the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Changelog: + * + * 14 Mar 2008 - Konrad Rzeszutek + * Updated comments and copyrights. (v0.4.9) + * + * 11 Feb 2008 - Konrad Rzeszutek + * Converted to using ibft_addr. (v0.4.8) + * + * 8 Feb 2008 - Konrad Rzeszutek + * Combined two functions in one: reserve_ibft_region. (v0.4.7) + * + * 30 Jan 2008 - Konrad Rzeszutek + * Added logic to handle IPv6 addresses. (v0.4.6) + * + * 25 Jan 2008 - Konrad Rzeszutek + * Added logic to handle badly not-to-spec iBFT. (v0.4.5) + * + * 4 Jan 2008 - Konrad Rzeszutek + * Added __init to function declarations. (v0.4.4) + * + * 21 Dec 2007 - Konrad Rzeszutek + * Updated kobject registration, combined unregister functions in one + * and code and style cleanup. (v0.4.3) + * + * 5 Dec 2007 - Konrad Rzeszutek + * Added end-markers to enums and re-organized kobject registration. (v0.4.2) + * + * 4 Dec 2007 - Konrad Rzeszutek + * Created 'device' sysfs link to the NIC and style cleanup. (v0.4.1) + * + * 28 Nov 2007 - Konrad Rzeszutek + * Added sysfs-ibft documentation, moved 'find_ibft' function to + * in its own file and added text attributes for every struct field. (v0.4) + * + * 21 Nov 2007 - Konrad Rzeszutek + * Added text attributes emulating OpenFirmware /proc/device-tree naming. + * Removed binary /sysfs interface (v0.3) + * + * 29 Aug 2007 - Konrad Rzeszutek + * Added functionality in setup.c to reserve iBFT region. (v0.2) + * + * 27 Aug 2007 - Konrad Rzeszutek + * First version exposing iBFT data via a binary /sysfs. (v0.1) + * + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define IBFT_ISCSI_VERSION "0.4.9" +#define IBFT_ISCSI_DATE "2008-Mar-14" + +MODULE_AUTHOR("Peter Jones and \ +Konrad Rzeszutek "); +MODULE_DESCRIPTION("sysfs interface to BIOS iBFT information"); +MODULE_LICENSE("GPL"); +MODULE_VERSION(IBFT_ISCSI_VERSION); + +struct ibft_hdr { + u8 id; + u8 version; + u16 length; + u8 index; + u8 flags; +} __attribute__((__packed__)); + +struct ibft_control { + struct ibft_hdr hdr; + u16 extensions; + u16 initiator_off; + u16 nic0_off; + u16 tgt0_off; + u16 nic1_off; + u16 tgt1_off; +} __attribute__((__packed__)); + +struct ibft_initiator { + struct ibft_hdr hdr; + char isns_server[16]; + char slp_server[16]; + char pri_radius_server[16]; + char sec_radius_server[16]; + u16 initiator_name_len; + u16 initiator_name_off; +} __attribute__((__packed__)); + +struct ibft_nic { + struct ibft_hdr hdr; + char ip_addr[16]; + u8 subnet_mask_prefix; + u8 origin; + char gateway[16]; + char primary_dns[16]; + char secondary_dns[16]; + char dhcp[16]; + u16 vlan; + char mac[6]; + u16 pci_bdf; + u16 hostname_len; + u16 hostname_off; +} __attribute__((__packed__)); + +struct ibft_tgt { + struct ibft_hdr hdr; + char ip_addr[16]; + u16 port; + char lun[8]; + u8 chap_type; + u8 nic_assoc; + u16 tgt_name_len; + u16 tgt_name_off; + u16 chap_name_len; + u16 chap_name_off; + u16 chap_secret_len; + u16 chap_secret_off; + u16 rev_chap_name_len; + u16 rev_chap_name_off; + u16 rev_chap_secret_len; + u16 rev_chap_secret_off; +} __attribute__((__packed__)); + +/* + * The kobject different types and its names. + * +*/ +enum ibft_id { + id_reserved = 0, /* We don't support. */ + id_control = 1, /* Should show up only once and is not exported. */ + id_initiator = 2, + id_nic = 3, + id_target = 4, + id_extensions = 5, /* We don't support. */ + id_end_marker, +}; + +/* + * We do not support the other types, hence the usage of NULL. + * This maps to the enum ibft_id. + */ +static const char *ibft_id_names[] = + {NULL, NULL, "initiator", "ethernet%d", "target%d", NULL, NULL}; + +/* + * The text attributes names for each of the kobjects. +*/ +enum ibft_eth_properties_enum { + ibft_eth_index, + ibft_eth_flags, + ibft_eth_ip_addr, + ibft_eth_subnet_mask, + ibft_eth_origin, + ibft_eth_gateway, + ibft_eth_primary_dns, + ibft_eth_secondary_dns, + ibft_eth_dhcp, + ibft_eth_vlan, + ibft_eth_mac, + /* ibft_eth_pci_bdf - this is replaced by link to the device itself. */ + ibft_eth_hostname, + ibft_eth_end_marker, +}; + +static const char *ibft_eth_properties[] = + {"index", "flags", "ip-addr", "subnet-mask", "origin", "gateway", + "primary-dns", "secondary-dns", "dhcp", "vlan", "mac", "hostname", + NULL}; + +enum ibft_tgt_properties_enum { + ibft_tgt_index, + ibft_tgt_flags, + ibft_tgt_ip_addr, + ibft_tgt_port, + ibft_tgt_lun, + ibft_tgt_chap_type, + ibft_tgt_nic_assoc, + ibft_tgt_name, + ibft_tgt_chap_name, + ibft_tgt_chap_secret, + ibft_tgt_rev_chap_name, + ibft_tgt_rev_chap_secret, + ibft_tgt_end_marker, +}; + +static const char *ibft_tgt_properties[] = + {"index", "flags", "ip-addr", "port", "lun", "chap-type", "nic-assoc", + "target-name", "chap-name", "chap-secret", "rev-chap-name", + "rev-chap-name-secret", NULL}; + +enum ibft_initiator_properties_enum { + ibft_init_index, + ibft_init_flags, + ibft_init_isns_server, + ibft_init_slp_server, + ibft_init_pri_radius_server, + ibft_init_sec_radius_server, + ibft_init_initiator_name, + ibft_init_end_marker, +}; + +static const char *ibft_initiator_properties[] = + {"index", "flags", "isns-server", "slp-server", "pri-radius-server", + "sec-radius-server", "initiator-name", NULL}; + +/* + * The kobject and attribute structures. + */ + +struct ibft_kobject { + struct ibft_table_header *header; + union { + struct ibft_initiator *initiator; + struct ibft_nic *nic; + struct ibft_tgt *tgt; + struct ibft_hdr *hdr; + }; + struct kobject kobj; + struct list_head node; +}; + +struct ibft_attribute { + struct attribute attr; + ssize_t (*show) (struct ibft_kobject *entry, + struct ibft_attribute *attr, char *buf); + union { + struct ibft_initiator *initiator; + struct ibft_nic *nic; + struct ibft_tgt *tgt; + struct ibft_hdr *hdr; + }; + struct kobject *kobj; + int type; /* The enum of the type. This can be any value of: + ibft_eth_properties_enum, ibft_tgt_properties_enum, + or ibft_initiator_properties_enum. */ + struct list_head node; +}; + +static LIST_HEAD(ibft_attr_list); +static LIST_HEAD(ibft_kobject_list); + +static const char nulls[16]; + +/* + * Helper functions to parse data properly. + */ +static ssize_t sprintf_ipaddr(char *buf, u8 *ip) +{ + char *str = buf; + + if (ip[0] == 0 && ip[1] == 0 && ip[2] == 0 && ip[3] == 0 && + ip[4] == 0 && ip[5] == 0 && ip[6] == 0 && ip[7] == 0 && + ip[8] == 0 && ip[9] == 0 && ip[10] == 0xff && ip[11] == 0xff) { + /* + * IPV4 + */ + str += sprintf(buf, NIPQUAD_FMT, ip[12], + ip[13], ip[14], ip[15]); + } else { + /* + * IPv6 + */ + str += sprintf(str, NIP6_FMT, ntohs(ip[0]), ntohs(ip[1]), + ntohs(ip[2]), ntohs(ip[3]), ntohs(ip[4]), + ntohs(ip[5]), ntohs(ip[6]), ntohs(ip[7])); + } + str += sprintf(str, "\n"); + return str - buf; +} + +static ssize_t sprintf_string(char *str, int len, char *buf) +{ + return sprintf(str, "%.*s\n", len, buf); +} + +/* + * Helper function to verify the IBFT header. + */ +static int ibft_verify_hdr(char *t, struct ibft_hdr *hdr, int id, int length) +{ + if (hdr->id != id) { + printk(KERN_ERR "iBFT error: We expected the " \ + "field header.id to have %d but " \ + "found %d instead!\n", id, hdr->id); + return -ENODEV; + } + if (hdr->length != length) { + printk(KERN_ERR "iBFT error: We expected the " \ + "field header.length to have %d but " \ + "found %d instead!\n", length, hdr->length); + return -ENODEV; + } + + return 0; +} + +static void ibft_release(struct kobject *kobj) +{ + struct ibft_kobject *ibft = + container_of(kobj, struct ibft_kobject, kobj); + kfree(ibft); +} + +/* + * Routines for parsing the iBFT data to be human readable. + */ +ssize_t ibft_attr_show_initiator(struct ibft_kobject *entry, + struct ibft_attribute *attr, + char *buf) +{ + struct ibft_initiator *initiator = entry->initiator; + void *ibft_loc = entry->header; + char *str = buf; + + if (!initiator) + return 0; + + switch (attr->type) { + case ibft_init_index: + str += sprintf(str, "%d\n", initiator->hdr.index); + break; + case ibft_init_flags: + str += sprintf(str, "%d\n", initiator->hdr.flags); + break; + case ibft_init_isns_server: + str += sprintf_ipaddr(str, initiator->isns_server); + break; + case ibft_init_slp_server: + str += sprintf_ipaddr(str, initiator->slp_server); + break; + case ibft_init_pri_radius_server: + str += sprintf_ipaddr(str, initiator->pri_radius_server); + break; + case ibft_init_sec_radius_server: + str += sprintf_ipaddr(str, initiator->sec_radius_server); + break; + case ibft_init_initiator_name: + str += sprintf_string(str, initiator->initiator_name_len, + (char *)ibft_loc + + initiator->initiator_name_off); + break; + default: + break; + } + + return str - buf; +} + +ssize_t ibft_attr_show_nic(struct ibft_kobject *entry, + struct ibft_attribute *attr, + char *buf) +{ + struct ibft_nic *nic = entry->nic; + void *ibft_loc = entry->header; + char *str = buf; + char *mac; + int val; + + if (!nic) + return 0; + + switch (attr->type) { + case ibft_eth_index: + str += sprintf(str, "%d\n", nic->hdr.index); + break; + case ibft_eth_flags: + str += sprintf(str, "%d\n", nic->hdr.flags); + break; + case ibft_eth_ip_addr: + str += sprintf_ipaddr(str, nic->ip_addr); + break; + case ibft_eth_subnet_mask: + val = ~((1 << (32-nic->subnet_mask_prefix))-1); + str += sprintf(str, NIPQUAD_FMT, + (u8)(val >> 24), (u8)(val >> 16), + (u8)(val >> 8), (u8)(val)); + break; + case ibft_eth_origin: + str += sprintf(str, "%d\n", nic->origin); + break; + case ibft_eth_gateway: + str += sprintf_ipaddr(str, nic->gateway); + break; + case ibft_eth_primary_dns: + str += sprintf_ipaddr(str, nic->primary_dns); + break; + case ibft_eth_secondary_dns: + str += sprintf_ipaddr(str, nic->secondary_dns); + break; + case ibft_eth_dhcp: + str += sprintf_ipaddr(str, nic->dhcp); + break; + case ibft_eth_vlan: + str += sprintf(str, "%d\n", nic->vlan); + break; + case ibft_eth_mac: + mac = nic->mac; + str += sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x\n", + (u8)mac[0], (u8)mac[1], (u8)mac[2], + (u8)mac[3], (u8)mac[4], (u8)mac[5]); + break; + case ibft_eth_hostname: + str += sprintf_string(str, nic->hostname_len, + (char *)ibft_loc + nic->hostname_off); + break; + default: + break; + } + + return str - buf; +}; + +ssize_t ibft_attr_show_target(struct ibft_kobject *entry, + struct ibft_attribute *attr, + char *buf) +{ + struct ibft_tgt *tgt = entry->tgt; + void *ibft_loc = entry->header; + char *str = buf; + int i; + + if (!tgt) + return 0; + + switch (attr->type) { + case ibft_tgt_index: + str += sprintf(str, "%d\n", tgt->hdr.index); + break; + case ibft_tgt_flags: + str += sprintf(str, "%d\n", tgt->hdr.flags); + break; + case ibft_tgt_ip_addr: + str += sprintf_ipaddr(str, tgt->ip_addr); + break; + case ibft_tgt_port: + str += sprintf(str, "%d\n", tgt->port); + break; + case ibft_tgt_lun: + for (i = 0; i < 8; i++) + str += sprintf(str, "%x", (u8)tgt->lun[i]); + str += sprintf(str, "\n"); + break; + case ibft_tgt_nic_assoc: + str += sprintf(str, "%d\n", tgt->nic_assoc); + break; + case ibft_tgt_chap_type: + str += sprintf(str, "%d\n", tgt->chap_type); + break; + case ibft_tgt_name: + str += sprintf_string(str, tgt->tgt_name_len, + (char *)ibft_loc + tgt->tgt_name_off); + break; + case ibft_tgt_chap_name: + str += sprintf_string(str, tgt->chap_name_len, + (char *)ibft_loc + tgt->chap_name_off); + break; + case ibft_tgt_chap_secret: + str += sprintf_string(str, tgt->chap_secret_len, + (char *)ibft_loc + tgt->chap_secret_off); + break; + case ibft_tgt_rev_chap_name: + str += sprintf_string(str, tgt->rev_chap_name_len, + (char *)ibft_loc + + tgt->rev_chap_name_off); + break; + case ibft_tgt_rev_chap_secret: + str += sprintf_string(str, tgt->rev_chap_secret_len, + (char *)ibft_loc + + tgt->rev_chap_secret_off); + break; + default: + break; + } + + return str - buf; +} + +/* + * The routine called for all sysfs attributes. + */ +static ssize_t ibft_show_attribute(struct kobject *kobj, + struct attribute *attr, + char *buf) +{ + struct ibft_kobject *dev = + container_of(kobj, struct ibft_kobject, kobj); + struct ibft_attribute *ibft_attr = + container_of(attr, struct ibft_attribute, attr); + ssize_t ret = -EIO; + char *str = buf; + + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (ibft_attr->show) + ret = ibft_attr->show(dev, ibft_attr, str); + + return ret; +} + +static struct sysfs_ops ibft_attr_ops = { + .show = ibft_show_attribute, +}; + +static struct kobj_type ibft_ktype = { + .release = ibft_release, + .sysfs_ops = &ibft_attr_ops, +}; + +static struct kset *ibft_kset; + +static int __init ibft_check_device(void) +{ + int len; + u8 *pos; + u8 csum = 0; + + len = ibft_addr->length; + + /* Sanity checking of iBFT. */ + if (ibft_addr->revision != 1) { + printk(KERN_ERR "iBFT module supports only revision 1, " \ + "while this is %d.\n", ibft_addr->revision); + return -ENOENT; + } + for (pos = (u8 *)ibft_addr; pos < (u8 *)ibft_addr + len; pos++) + csum += *pos; + + if (csum) { + printk(KERN_ERR "iBFT has incorrect checksum (0x%x)!\n", csum); + return -ENOENT; + } + + return 0; +} + +/* + * Helper function for ibft_register_kobjects. + */ +static int __init ibft_create_kobject(struct ibft_table_header *header, + struct ibft_hdr *hdr, + struct list_head *list) +{ + struct ibft_kobject *ibft_kobj = NULL; + struct ibft_nic *nic = (struct ibft_nic *)hdr; + struct pci_dev *pci_dev; + int rc = 0; + + ibft_kobj = kzalloc(sizeof(*ibft_kobj), GFP_KERNEL); + if (!ibft_kobj) + return -ENOMEM; + + ibft_kobj->header = header; + ibft_kobj->hdr = hdr; + + switch (hdr->id) { + case id_initiator: + rc = ibft_verify_hdr("initiator", hdr, id_initiator, + sizeof(*ibft_kobj->initiator)); + break; + case id_nic: + rc = ibft_verify_hdr("ethernet", hdr, id_nic, + sizeof(*ibft_kobj->nic)); + break; + case id_target: + rc = ibft_verify_hdr("target", hdr, id_target, + sizeof(*ibft_kobj->tgt)); + break; + case id_reserved: + case id_control: + case id_extensions: + /* Fields which we don't support. Ignore them */ + rc = 1; + break; + default: + printk(KERN_ERR "iBFT has unknown structure type (%d). " \ + "Report this bug to %.6s!\n", hdr->id, + header->oem_id); + rc = 1; + break; + } + + if (rc) { + /* Skip adding this kobject, but exit with non-fatal error. */ + kfree(ibft_kobj); + goto out_invalid_struct; + } + + ibft_kobj->kobj.kset = ibft_kset; + + rc = kobject_init_and_add(&ibft_kobj->kobj, &ibft_ktype, + NULL, ibft_id_names[hdr->id], hdr->index); + + if (rc) { + kfree(ibft_kobj); + goto out; + } + + kobject_uevent(&ibft_kobj->kobj, KOBJ_ADD); + + if (hdr->id == id_nic) { + /* + * We don't search for the device in other domains than + * zero. This is because on x86 platforms the BIOS + * executes only devices which are in domain 0. Furthermore, the + * iBFT spec doesn't have a domain id field :-( + */ + pci_dev = pci_get_bus_and_slot((nic->pci_bdf & 0xff00) >> 8, + (nic->pci_bdf & 0xff)); + if (pci_dev) { + rc = sysfs_create_link(&ibft_kobj->kobj, + &pci_dev->dev.kobj, "device"); + pci_dev_put(pci_dev); + } + } + + /* Nothing broke so lets add it to the list. */ + list_add_tail(&ibft_kobj->node, list); +out: + return rc; +out_invalid_struct: + /* Unsupported structs are skipped. */ + return 0; +} + +/* + * Scan the IBFT table structure for the NIC and Target fields. When + * found add them on the passed-in list. We do not support the other + * fields at this point, so they are skipped. + */ +static int __init ibft_register_kobjects(struct ibft_table_header *header, + struct list_head *list) +{ + struct ibft_control *control = NULL; + void *ptr, *end; + int rc = 0; + u16 offset; + u16 eot_offset; + + control = (void *)header + sizeof(*header); + end = (void *)control + control->hdr.length; + eot_offset = (void *)header + header->length - + (void *)control - sizeof(*header); + rc = ibft_verify_hdr("control", (struct ibft_hdr *)control, id_control, + sizeof(*control)); + + /* iBFT table safety checking */ + rc |= ((control->hdr.index) ? -ENODEV : 0); + if (rc) { + printk(KERN_ERR "iBFT error: Control header is invalid!\n"); + return rc; + } + for (ptr = &control->initiator_off; ptr < end; ptr += sizeof(u16)) { + offset = *(u16 *)ptr; + if (offset && offset < header->length && offset < eot_offset) { + rc = ibft_create_kobject(header, + (void *)header + offset, + list); + if (rc) + break; + } + } + + return rc; +} + +static void ibft_unregister(struct list_head *attr_list, + struct list_head *kobj_list) +{ + struct ibft_kobject *data = NULL, *n; + struct ibft_attribute *attr = NULL, *m; + + list_for_each_entry_safe(attr, m, attr_list, node) { + sysfs_remove_file(attr->kobj, &attr->attr); + list_del(&attr->node); + kfree(attr); + }; + list_del_init(attr_list); + + list_for_each_entry_safe(data, n, kobj_list, node) { + list_del(&data->node); + if (data->hdr->id == id_nic) + sysfs_remove_link(&data->kobj, "device"); + kobject_put(&data->kobj); + }; + list_del_init(kobj_list); +} + +static int __init ibft_create_attribute(struct ibft_kobject *kobj_data, + int type, + const char *name, + ssize_t (*show)(struct ibft_kobject *, + struct ibft_attribute*, + char *buf), + struct list_head *list) +{ + struct ibft_attribute *attr = NULL; + struct ibft_hdr *hdr = kobj_data->hdr; + + attr = kmalloc(sizeof(*attr), GFP_KERNEL); + if (!attr) + return -ENOMEM; + + attr->attr.name = name; + attr->attr.mode = S_IRUSR; + attr->attr.owner = THIS_MODULE; + + attr->hdr = hdr; + attr->show = show; + attr->kobj = &kobj_data->kobj; + attr->type = type; + + list_add_tail(&attr->node, list); + + return 0; +} + +/* + * Helper routiners to check to determine if the entry is valid + * in the proper iBFT structure. + */ +static int __init ibft_check_nic_for(struct ibft_nic *nic, int entry) +{ + int rc = 0; + + switch (entry) { + case ibft_eth_index: + case ibft_eth_flags: + rc = 1; + break; + case ibft_eth_ip_addr: + if (!memcmp(nic->dhcp, nulls, sizeof(nic->dhcp))) + rc = 1; + break; + case ibft_eth_subnet_mask: + if (!memcmp(nic->dhcp, nulls, sizeof(nic->dhcp))) + rc = 1; + break; + case ibft_eth_origin: + rc = 1; + break; + case ibft_eth_gateway: + if (memcmp(nic->gateway, nulls, sizeof(nic->gateway))) + rc = 1; + break; + case ibft_eth_primary_dns: + if (memcmp(nic->primary_dns, nulls, + sizeof(nic->primary_dns))) + rc = 1; + break; + case ibft_eth_secondary_dns: + if (memcmp(nic->secondary_dns, nulls, + sizeof(nic->secondary_dns))) + rc = 1; + break; + case ibft_eth_dhcp: + if (memcmp(nic->dhcp, nulls, sizeof(nic->dhcp))) + rc = 1; + break; + case ibft_eth_vlan: + case ibft_eth_mac: + rc = 1; + break; + case ibft_eth_hostname: + if (nic->hostname_off) + rc = 1; + break; + default: + break; + } + + return rc; +} + +static int __init ibft_check_tgt_for(struct ibft_tgt *tgt, int entry) +{ + int rc = 0; + + switch (entry) { + case ibft_tgt_index: + case ibft_tgt_flags: + case ibft_tgt_ip_addr: + case ibft_tgt_port: + case ibft_tgt_lun: + case ibft_tgt_nic_assoc: + case ibft_tgt_chap_type: + rc = 1; + case ibft_tgt_name: + if (tgt->tgt_name_len) + rc = 1; + break; + case ibft_tgt_chap_name: + case ibft_tgt_chap_secret: + if (tgt->chap_name_len) + rc = 1; + break; + case ibft_tgt_rev_chap_name: + case ibft_tgt_rev_chap_secret: + if (tgt->rev_chap_name_len) + rc = 1; + break; + default: + break; + } + + return rc; +} + +static int __init ibft_check_initiator_for(struct ibft_initiator *init, + int entry) +{ + int rc = 0; + + switch (entry) { + case ibft_init_index: + case ibft_init_flags: + rc = 1; + break; + case ibft_init_isns_server: + if (memcmp(init->isns_server, nulls, + sizeof(init->isns_server))) + rc = 1; + break; + case ibft_init_slp_server: + if (memcmp(init->slp_server, nulls, + sizeof(init->slp_server))) + rc = 1; + break; + case ibft_init_pri_radius_server: + if (memcmp(init->pri_radius_server, nulls, + sizeof(init->pri_radius_server))) + rc = 1; + break; + case ibft_init_sec_radius_server: + if (memcmp(init->sec_radius_server, nulls, + sizeof(init->sec_radius_server))) + rc = 1; + break; + case ibft_init_initiator_name: + if (init->initiator_name_len) + rc = 1; + break; + default: + break; + } + + return rc; +} + +/* + * Register the attributes for all of the kobjects. + */ +static int __init ibft_register_attributes(struct list_head *kobject_list, + struct list_head *attr_list) +{ + int rc = 0, i = 0; + struct ibft_kobject *data = NULL; + struct ibft_attribute *attr = NULL, *m; + + list_for_each_entry(data, kobject_list, node) { + switch (data->hdr->id) { + case id_nic: + for (i = 0; i < ibft_eth_end_marker && !rc; i++) + if (ibft_check_nic_for(data->nic, i)) + rc = ibft_create_attribute(data, i, + ibft_eth_properties[i], + ibft_attr_show_nic, attr_list); + break; + case id_target: + for (i = 0; i < ibft_tgt_end_marker && !rc; i++) + if (ibft_check_tgt_for(data->tgt, i)) + rc = ibft_create_attribute(data, i, + ibft_tgt_properties[i], + ibft_attr_show_target, + attr_list); + break; + case id_initiator: + for (i = 0; i < ibft_init_end_marker && !rc; i++) + if (ibft_check_initiator_for( + data->initiator, i)) + rc = ibft_create_attribute(data, i, + ibft_initiator_properties[i], + ibft_attr_show_initiator, + attr_list); + break; + default: + break; + } + if (rc) + break; + } + list_for_each_entry_safe(attr, m, attr_list, node) { + rc = sysfs_create_file(attr->kobj, &attr->attr); + if (rc) { + list_del(&attr->node); + kfree(attr); + break; + } + } + + return rc; +} + +/* + * ibft_init() - creates sysfs tree entries for the iBFT data. + */ +static int __init ibft_init(void) +{ + int rc = 0; + + ibft_kset = kset_create_and_add("ibft", NULL, firmware_kobj); + if (!ibft_kset) + return -ENOMEM; + + if (ibft_addr) { + printk(KERN_INFO "iBFT detected at 0x%lx.\n", + virt_to_phys((void *)ibft_addr)); + + rc = ibft_check_device(); + if (rc) + goto out_firmware_unregister; + + /* Scan the IBFT for data and register the kobjects. */ + rc = ibft_register_kobjects(ibft_addr, &ibft_kobject_list); + if (rc) + goto out_free; + + /* Register the attributes */ + rc = ibft_register_attributes(&ibft_kobject_list, + &ibft_attr_list); + if (rc) + goto out_free; + } else + printk(KERN_INFO "No iBFT detected.\n"); + + return 0; + +out_free: + ibft_unregister(&ibft_attr_list, &ibft_kobject_list); +out_firmware_unregister: + kset_unregister(ibft_kset); + return rc; +} + +static void __exit ibft_exit(void) +{ + ibft_unregister(&ibft_attr_list, &ibft_kobject_list); + kset_unregister(ibft_kset); +} + +module_init(ibft_init); +module_exit(ibft_exit); diff --git a/drivers/firmware/iscsi_ibft_find.c b/drivers/firmware/iscsi_ibft_find.c new file mode 100644 index 000000000000..d0e5fa4ea51b --- /dev/null +++ b/drivers/firmware/iscsi_ibft_find.c @@ -0,0 +1,84 @@ +/* + * Copyright 2007 Red Hat, Inc. + * by Peter Jones + * Copyright 2007 IBM, Inc. + * by Konrad Rzeszutek + * Copyright 2008 + * by Konrad Rzeszutek + * + * This code finds the iSCSI Boot Format Table. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License v2.0 as published by + * the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/* + * Physical location of iSCSI Boot Format Table. + */ +struct ibft_table_header *ibft_addr; +EXPORT_SYMBOL_GPL(ibft_addr); + +#define IBFT_SIGN "iBFT" +#define IBFT_SIGN_LEN 4 +#define IBFT_START 0x80000 /* 512kB */ +#define IBFT_END 0x100000 /* 1MB */ +#define VGA_MEM 0xA0000 /* VGA buffer */ +#define VGA_SIZE 0x20000 /* 128kB */ + + +/* + * Routine used to find the iSCSI Boot Format Table. The logical + * kernel address is set in the ibft_addr global variable. + */ +void __init reserve_ibft_region(void) +{ + unsigned long pos; + unsigned int len = 0; + void *virt; + + ibft_addr = 0; + + for (pos = IBFT_START; pos < IBFT_END; pos += 16) { + /* The table can't be inside the VGA BIOS reserved space, + * so skip that area */ + if (pos == VGA_MEM) + pos += VGA_SIZE; + virt = phys_to_virt(pos); + if (memcmp(virt, IBFT_SIGN, IBFT_SIGN_LEN) == 0) { + unsigned long *addr = + (unsigned long *)phys_to_virt(pos + 4); + len = *addr; + /* if the length of the table extends past 1M, + * the table cannot be valid. */ + if (pos + len <= (IBFT_END-1)) { + ibft_addr = (struct ibft_table_header *)virt; + break; + } + } + } + if (ibft_addr) + reserve_bootmem(pos, PAGE_ALIGN(len), BOOTMEM_DEFAULT); +} +EXPORT_SYMBOL_GPL(reserve_ibft_region); diff --git a/include/linux/iscsi_ibft.h b/include/linux/iscsi_ibft.h new file mode 100644 index 000000000000..6092487e2950 --- /dev/null +++ b/include/linux/iscsi_ibft.h @@ -0,0 +1,50 @@ +/* + * Copyright 2007 Red Hat, Inc. + * by Peter Jones + * Copyright 2007 IBM, Inc. + * by Konrad Rzeszutek + * Copyright 2008 + * by Konrad Rzeszutek + * + * This code exposes the iSCSI Boot Format Table to userland via sysfs. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License v2.0 as published by + * the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef ISCSI_IBFT_H +#define ISCSI_IBFT_H + +struct ibft_table_header { + char signature[4]; + u32 length; + u8 revision; + u8 checksum; + char oem_id[6]; + char oem_table_id[8]; + char reserved[24]; +} __attribute__((__packed__)); + +/* + * Logical location of iSCSI Boot Format Table. + * If the value is NULL there is no iBFT on the machine. + */ +extern struct ibft_table_header *ibft_addr; + +/* + * Routine used to find and reserve the iSCSI Boot Format Table. The + * mapped address is set in the ibft_addr variable. + */ +#ifdef CONFIG_ISCSI_IBFT_FIND +extern void __init reserve_ibft_region(void); +#else +static inline void reserve_ibft_region(void) { } +#endif + +#endif /* ISCSI_IBFT_H */ -- cgit v1.2.3 From 2424b5dd062cbe3e0578ae7b11a1b360ad22f451 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 7 Apr 2008 15:35:01 -0700 Subject: sysfs: refill attribute buffer when reading from offset 0 Requiring userspace to close and re-open sysfs attributes has been the policy since before 2.6.12. It allows userspace to get a consistent snapshot of kernel state and consume it with incremental reads and seeks. Now, if the file position is zero the kernel assumes userspace wants to see the new value. The application for this change is to allow a userspace RAID metadata handler to check the state of an array without causing any memory allocations. Thus not causing writeback to a raid array that might be blocked waiting for userspace to take action. Cc: Neil Brown Acked-by: Tejun Heo Signed-off-by: Dan Williams Signed-off-by: Greg Kroah-Hartman --- Documentation/filesystems/sysfs.txt | 9 +++++++-- fs/sysfs/file.c | 5 ++--- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'Documentation') diff --git a/Documentation/filesystems/sysfs.txt b/Documentation/filesystems/sysfs.txt index 4598ef7b622b..7f27b8f840d0 100644 --- a/Documentation/filesystems/sysfs.txt +++ b/Documentation/filesystems/sysfs.txt @@ -176,8 +176,10 @@ implementations: Recall that an attribute should only be exporting one value, or an array of similar values, so this shouldn't be that expensive. - This allows userspace to do partial reads and seeks arbitrarily over - the entire file at will. + This allows userspace to do partial reads and forward seeks + arbitrarily over the entire file at will. If userspace seeks back to + zero or does a pread(2) with an offset of '0' the show() method will + be called again, rearmed, to fill the buffer. - On write(2), sysfs expects the entire buffer to be passed during the first write. Sysfs then passes the entire buffer to the store() @@ -192,6 +194,9 @@ implementations: Other notes: +- Writing causes the show() method to be rearmed regardless of current + file position. + - The buffer will always be PAGE_SIZE bytes in length. On i386, this is 4096. diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index a859c32ff93a..ade9a7e6a757 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -129,7 +129,7 @@ sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos) ssize_t retval = 0; mutex_lock(&buffer->mutex); - if (buffer->needs_read_fill) { + if (buffer->needs_read_fill || *ppos == 0) { retval = fill_read_buffer(file->f_path.dentry,buffer); if (retval) goto out; @@ -410,8 +410,7 @@ static int sysfs_release(struct inode *inode, struct file *filp) * return POLLERR|POLLPRI, and select will return the fd whether * it is waiting for read, write, or exceptions. * Once poll/select indicates that the value has changed, you - * need to close and re-open the file, as simply seeking and reading - * again will not get new data, or reset the state of 'poll'. + * need to close and re-open the file, or seek to 0 and read again. * Reminder: this only works for attributes which actively support * it, and it is not possible to test an attribute from userspace * to see if it supports poll (Neither 'poll' nor 'select' return -- cgit v1.2.3