Remove obsolete #include <linux/config.h>
[cascardo/linux.git] / drivers / s390 / block / dasd_devmap.c
index 1629b27..d729538 100644 (file)
@@ -13,9 +13,9 @@
  *
  */
 
-#include <linux/config.h>
 #include <linux/ctype.h>
 #include <linux/init.h>
+#include <linux/module.h>
 
 #include <asm/debug.h>
 #include <asm/uaccess.h>
@@ -26,7 +26,7 @@
 #include "dasd_int.h"
 
 kmem_cache_t *dasd_page_cache;
-EXPORT_SYMBOL(dasd_page_cache);
+EXPORT_SYMBOL_GPL(dasd_page_cache);
 
 /*
  * dasd_devmap_t is used to store the features and the relation
@@ -44,8 +44,23 @@ struct dasd_devmap {
         unsigned int devindex;
         unsigned short features;
        struct dasd_device *device;
+       struct dasd_uid uid;
 };
 
+/*
+ * dasd_servermap is used to store the server_id of all storage servers
+ * accessed by DASD device driver.
+ */
+struct dasd_servermap {
+       struct list_head list;
+       struct server_id {
+               char vendor[4];
+               char serial[15];
+       } sid;
+};
+
+static struct list_head dasd_serverlist;
+
 /*
  * Parameter parsing functions for dasd= parameter. The syntax is:
  *   <devno>           : (0x)?[0-9a-fA-F]+
@@ -62,6 +77,8 @@ struct dasd_devmap {
 
 int dasd_probeonly =  0;       /* is true, when probeonly mode is active */
 int dasd_autodetect = 0;       /* is true, when autodetection is active */
+int dasd_nopav = 0;            /* is true, when PAV is disabled */
+EXPORT_SYMBOL_GPL(dasd_nopav);
 
 /*
  * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
@@ -69,6 +86,8 @@ int dasd_autodetect = 0;      /* is true, when autodetection is active */
  * strings when running as a module.
  */
 static char *dasd[256];
+module_param_array(dasd, charp, NULL, 0);
+
 /*
  * Single spinlock to protect devmap structures and lists.
  */
@@ -119,7 +138,7 @@ static inline int
 dasd_busid(char **str, int *id0, int *id1, int *devno)
 {
        int val, old_style;
+
        /* check for leading '0x' */
        old_style = 0;
        if ((*str)[0] == '0' && (*str)[1] == 'x') {
@@ -175,7 +194,7 @@ dasd_feature_list(char *str, char **endp)
        features = 0;
 
        while (1) {
-               for (len = 0; 
+               for (len = 0;
                     str[len] && str[len] != ':' && str[len] != ')'; len++);
                if (len == 2 && !strncmp(str, "ro", 2))
                        features |= DASD_FEATURE_READONLY;
@@ -224,19 +243,24 @@ dasd_parse_keyword( char *parsestring ) {
                length = strlen(parsestring);
                residual_str = parsestring + length;
         }
-       if (strncmp ("autodetect", parsestring, length) == 0) {
+       if (strncmp("autodetect", parsestring, length) == 0) {
                dasd_autodetect = 1;
                MESSAGE (KERN_INFO, "%s",
                         "turning to autodetection mode");
                 return residual_str;
         }
-        if (strncmp ("probeonly", parsestring, length) == 0) {
+       if (strncmp("probeonly", parsestring, length) == 0) {
                dasd_probeonly = 1;
                MESSAGE(KERN_INFO, "%s",
                        "turning to probeonly mode");
                 return residual_str;
         }
-        if (strncmp ("fixedbuffers", parsestring, length) == 0) {
+       if (strncmp("nopav", parsestring, length) == 0) {
+               dasd_nopav = 1;
+               MESSAGE(KERN_INFO, "%s", "disable PAV mode");
+               return residual_str;
+       }
+       if (strncmp("fixedbuffers", parsestring, length) == 0) {
                if (dasd_page_cache)
                        return residual_str;
                dasd_page_cache =
@@ -290,6 +314,8 @@ dasd_parse_range( char *parsestring ) {
        features = dasd_feature_list(str, &str);
        if (features < 0)
                return ERR_PTR(-EINVAL);
+       /* each device in dasd= parameter should be set initially online */
+       features |= DASD_FEATURE_INITIAL_ONLINE;
        while (from <= to) {
                sprintf(bus_id, "%01x.%01x.%04x",
                        from_id0, from_id1, from++);
@@ -355,7 +381,7 @@ dasd_parse(void)
  * Add a devmap for the device specified by busid. It is possible that
  * the devmap already exists (dasd= parameter). The order of the devices
  * added through this function will define the kdevs for the individual
- * devices. 
+ * devices.
  */
 static struct dasd_devmap *
 dasd_add_busid(char *bus_id, int features)
@@ -364,7 +390,7 @@ dasd_add_busid(char *bus_id, int features)
        int hash;
 
        new = (struct dasd_devmap *)
-               kmalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
+               kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
        if (!new)
                return ERR_PTR(-ENOMEM);
        spin_lock(&dasd_devmap_lock);
@@ -434,8 +460,7 @@ dasd_forget_ranges(void)
        spin_lock(&dasd_devmap_lock);
        for (i = 0; i < 256; i++) {
                list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
-                       if (devmap->device != NULL)
-                               BUG();
+                       BUG_ON(devmap->device != NULL);
                        list_del(&devmap->list);
                        kfree(devmap);
                }
@@ -544,8 +569,7 @@ dasd_delete_device(struct dasd_device *device)
 
        /* First remove device pointer from devmap. */
        devmap = dasd_find_busid(device->cdev->dev.bus_id);
-       if (IS_ERR(devmap))
-               BUG();
+       BUG_ON(IS_ERR(devmap));
        spin_lock(&dasd_devmap_lock);
        if (devmap->device != device) {
                spin_unlock(&dasd_devmap_lock);
@@ -628,7 +652,8 @@ dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
 }
 
 static ssize_t
-dasd_ro_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+dasd_ro_store(struct device *dev, struct device_attribute *attr,
+             const char *buf, size_t count)
 {
        struct dasd_devmap *devmap;
        int ro_flag;
@@ -656,7 +681,7 @@ static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
  * use_diag controls whether the driver should use diag rather than ssch
  * to talk to the device
  */
-static ssize_t 
+static ssize_t
 dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct dasd_devmap *devmap;
@@ -671,7 +696,8 @@ dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
 }
 
 static ssize_t
-dasd_use_diag_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+dasd_use_diag_store(struct device *dev, struct device_attribute *attr,
+                   const char *buf, size_t count)
 {
        struct dasd_devmap *devmap;
        ssize_t rc;
@@ -695,11 +721,11 @@ dasd_use_diag_store(struct device *dev, struct device_attribute *attr, const cha
        return rc;
 }
 
-static
-DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
+static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
 
 static ssize_t
-dasd_discipline_show(struct device *dev, struct device_attribute *attr, char *buf)
+dasd_discipline_show(struct device *dev, struct device_attribute *attr,
+                    char *buf)
 {
        struct dasd_devmap *devmap;
        char *dname;
@@ -715,10 +741,116 @@ dasd_discipline_show(struct device *dev, struct device_attribute *attr, char *bu
 
 static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
 
+static ssize_t
+dasd_alias_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct dasd_devmap *devmap;
+       int alias;
+
+       devmap = dasd_find_busid(dev->bus_id);
+       spin_lock(&dasd_devmap_lock);
+       if (!IS_ERR(devmap))
+               alias = devmap->uid.alias;
+       else
+               alias = 0;
+       spin_unlock(&dasd_devmap_lock);
+
+       return sprintf(buf, alias ? "1\n" : "0\n");
+}
+
+static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
+
+static ssize_t
+dasd_vendor_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct dasd_devmap *devmap;
+       char *vendor;
+
+       devmap = dasd_find_busid(dev->bus_id);
+       spin_lock(&dasd_devmap_lock);
+       if (!IS_ERR(devmap) && strlen(devmap->uid.vendor) > 0)
+               vendor = devmap->uid.vendor;
+       else
+               vendor = "";
+       spin_unlock(&dasd_devmap_lock);
+
+       return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
+}
+
+static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
+
+#define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial    */ 14 + 1 +\
+                    /* SSID   */ 4 + 1 + /* unit addr */ 2 + 1)
+
+static ssize_t
+dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct dasd_devmap *devmap;
+       char uid[UID_STRLEN];
+
+       devmap = dasd_find_busid(dev->bus_id);
+       spin_lock(&dasd_devmap_lock);
+       if (!IS_ERR(devmap) && strlen(devmap->uid.vendor) > 0)
+               snprintf(uid, sizeof(uid), "%s.%s.%04x.%02x",
+                        devmap->uid.vendor, devmap->uid.serial,
+                        devmap->uid.ssid, devmap->uid.unit_addr);
+       else
+               uid[0] = 0;
+       spin_unlock(&dasd_devmap_lock);
+
+       return snprintf(buf, PAGE_SIZE, "%s\n", uid);
+}
+
+static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
+
+/*
+ * extended error-reporting
+ */
+static ssize_t
+dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct dasd_devmap *devmap;
+       int eer_flag;
+
+       devmap = dasd_find_busid(dev->bus_id);
+       if (!IS_ERR(devmap) && devmap->device)
+               eer_flag = dasd_eer_enabled(devmap->device);
+       else
+               eer_flag = 0;
+       return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
+}
+
+static ssize_t
+dasd_eer_store(struct device *dev, struct device_attribute *attr,
+              const char *buf, size_t count)
+{
+       struct dasd_devmap *devmap;
+       int rc;
+
+       devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
+       if (IS_ERR(devmap))
+               return PTR_ERR(devmap);
+       if (!devmap->device)
+               return count;
+       if (buf[0] == '1') {
+               rc = dasd_eer_enable(devmap->device);
+               if (rc)
+                       return rc;
+       } else
+               dasd_eer_disable(devmap->device);
+       return count;
+}
+
+static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
+
 static struct attribute * dasd_attrs[] = {
        &dev_attr_readonly.attr,
        &dev_attr_discipline.attr,
+       &dev_attr_alias.attr,
+       &dev_attr_vendor.attr,
+       &dev_attr_uid.attr,
        &dev_attr_use_diag.attr,
+       &dev_attr_eer_enabled.attr,
        NULL,
 };
 
@@ -726,6 +858,79 @@ static struct attribute_group dasd_attr_group = {
        .attrs = dasd_attrs,
 };
 
+/*
+ * Check if the related storage server is already contained in the
+ * dasd_serverlist. If server is not contained, create new entry.
+ * Return 0 if server was already in serverlist,
+ *       1 if the server was added successfully
+ *      <0 in case of error.
+ */
+static int
+dasd_add_server(struct dasd_uid *uid)
+{
+       struct dasd_servermap *new, *tmp;
+
+       /* check if server is already contained */
+       list_for_each_entry(tmp, &dasd_serverlist, list)
+         // normale cmp?
+               if (strncmp(tmp->sid.vendor, uid->vendor,
+                           sizeof(tmp->sid.vendor)) == 0
+                   && strncmp(tmp->sid.serial, uid->serial,
+                              sizeof(tmp->sid.serial)) == 0)
+                       return 0;
+
+       new = (struct dasd_servermap *)
+               kzalloc(sizeof(struct dasd_servermap), GFP_KERNEL);
+       if (!new)
+               return -ENOMEM;
+
+       strncpy(new->sid.vendor, uid->vendor, sizeof(new->sid.vendor));
+       strncpy(new->sid.serial, uid->serial, sizeof(new->sid.serial));
+       list_add(&new->list, &dasd_serverlist);
+       return 1;
+}
+
+
+/*
+ * Return copy of the device unique identifier.
+ */
+int
+dasd_get_uid(struct ccw_device *cdev, struct dasd_uid *uid)
+{
+       struct dasd_devmap *devmap;
+
+       devmap = dasd_find_busid(cdev->dev.bus_id);
+       if (IS_ERR(devmap))
+               return PTR_ERR(devmap);
+       spin_lock(&dasd_devmap_lock);
+       *uid = devmap->uid;
+       spin_unlock(&dasd_devmap_lock);
+       return 0;
+}
+
+/*
+ * Register the given device unique identifier into devmap struct.
+ * Return 0 if server was already in serverlist,
+ *       1 if the server was added successful
+ *      <0 in case of error.
+ */
+int
+dasd_set_uid(struct ccw_device *cdev, struct dasd_uid *uid)
+{
+       struct dasd_devmap *devmap;
+       int rc;
+
+       devmap = dasd_find_busid(cdev->dev.bus_id);
+       if (IS_ERR(devmap))
+               return PTR_ERR(devmap);
+       spin_lock(&dasd_devmap_lock);
+       devmap->uid = *uid;
+       rc = dasd_add_server(uid);
+       spin_unlock(&dasd_devmap_lock);
+       return rc;
+}
+EXPORT_SYMBOL_GPL(dasd_set_uid);
+
 /*
  * Return value of the specified feature.
  */
@@ -736,7 +941,7 @@ dasd_get_feature(struct ccw_device *cdev, int feature)
 
        devmap = dasd_find_busid(cdev->dev.bus_id);
        if (IS_ERR(devmap))
-               return (int) PTR_ERR(devmap);
+               return PTR_ERR(devmap);
 
        return ((devmap->features & feature) != 0);
 }
@@ -752,7 +957,7 @@ dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
 
        devmap = dasd_find_busid(cdev->dev.bus_id);
        if (IS_ERR(devmap))
-               return (int) PTR_ERR(devmap);
+               return PTR_ERR(devmap);
 
        spin_lock(&dasd_devmap_lock);
        if (flag)
@@ -788,8 +993,10 @@ dasd_devmap_init(void)
        dasd_max_devindex = 0;
        for (i = 0; i < 256; i++)
                INIT_LIST_HEAD(&dasd_hashlists[i]);
-       return 0;
 
+       /* Initialize servermap structure. */
+       INIT_LIST_HEAD(&dasd_serverlist);
+       return 0;
 }
 
 void