[SCSI] bfa: fix test in bfad_os_fc_host_init()
[safe/jmp/linux-2.6] / drivers / scsi / scsi_proc.c
index a50958b..77fbddb 100644 (file)
 #include <linux/errno.h>
 #include <linux/blkdev.h>
 #include <linux/seq_file.h>
+#include <linux/mutex.h>
 #include <asm/uaccess.h>
 
 #include <scsi/scsi.h>
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_host.h>
+#include <scsi/scsi_transport.h>
 
 #include "scsi_priv.h"
 #include "scsi_logging.h"
 static struct proc_dir_entry *proc_scsi;
 
 /* Protect sht->present and sht->proc_dir */
-static DECLARE_MUTEX(global_host_template_sem);
+static DEFINE_MUTEX(global_host_template_mutex);
+
+/**
+ * proc_scsi_read - handle read from /proc by calling host's proc_info() command
+ * @buffer: passed to proc_info
+ * @start: passed to proc_info
+ * @offset: passed to proc_info
+ * @length: passed to proc_info
+ * @eof: returns whether length read was less than requested
+ * @data: pointer to a &struct Scsi_Host
+ */
 
 static int proc_scsi_read(char *buffer, char **start, off_t offset,
                          int length, int *eof, void *data)
@@ -55,6 +67,13 @@ static int proc_scsi_read(char *buffer, char **start, off_t offset,
        return n;
 }
 
+/**
+ * proc_scsi_write_proc - Handle write to /proc by calling host's proc_info()
+ * @file: not used
+ * @buf: source of data to write.
+ * @count: number of bytes (at most PROC_BLOCK_SIZE) to write.
+ * @data: pointer to &struct Scsi_Host
+ */
 static int proc_scsi_write_proc(struct file *file, const char __user *buf,
                            unsigned long count, void *data)
 {
@@ -78,36 +97,50 @@ out:
        return ret;
 }
 
+/**
+ * scsi_proc_hostdir_add - Create directory in /proc for a scsi host
+ * @sht: owner of this directory
+ *
+ * Sets sht->proc_dir to the new directory.
+ */
+
 void scsi_proc_hostdir_add(struct scsi_host_template *sht)
 {
        if (!sht->proc_info)
                return;
 
-       down(&global_host_template_sem);
+       mutex_lock(&global_host_template_mutex);
        if (!sht->present++) {
                sht->proc_dir = proc_mkdir(sht->proc_name, proc_scsi);
                if (!sht->proc_dir)
                        printk(KERN_ERR "%s: proc_mkdir failed for %s\n",
-                              __FUNCTION__, sht->proc_name);
-               else
-                       sht->proc_dir->owner = sht->module;
+                              __func__, sht->proc_name);
        }
-       up(&global_host_template_sem);
+       mutex_unlock(&global_host_template_mutex);
 }
 
+/**
+ * scsi_proc_hostdir_rm - remove directory in /proc for a scsi host
+ * @sht: owner of directory
+ */
 void scsi_proc_hostdir_rm(struct scsi_host_template *sht)
 {
        if (!sht->proc_info)
                return;
 
-       down(&global_host_template_sem);
+       mutex_lock(&global_host_template_mutex);
        if (!--sht->present && sht->proc_dir) {
                remove_proc_entry(sht->proc_name, proc_scsi);
                sht->proc_dir = NULL;
        }
-       up(&global_host_template_sem);
+       mutex_unlock(&global_host_template_mutex);
 }
 
+
+/**
+ * scsi_proc_host_add - Add entry for this host to appropriate /proc dir
+ * @shost: host to add
+ */
 void scsi_proc_host_add(struct Scsi_Host *shost)
 {
        struct scsi_host_template *sht = shost->hostt;
@@ -122,15 +155,18 @@ void scsi_proc_host_add(struct Scsi_Host *shost)
                        sht->proc_dir, proc_scsi_read, shost);
        if (!p) {
                printk(KERN_ERR "%s: Failed to register host %d in"
-                      "%s\n", __FUNCTION__, shost->host_no,
+                      "%s\n", __func__, shost->host_no,
                       sht->proc_name);
                return;
        } 
 
        p->write_proc = proc_scsi_write_proc;
-       p->owner = sht->module;
 }
 
+/**
+ * scsi_proc_host_rm - remove this host's entry from /proc
+ * @shost: which host
+ */
 void scsi_proc_host_rm(struct Scsi_Host *shost)
 {
        char name[10];
@@ -141,13 +177,24 @@ void scsi_proc_host_rm(struct Scsi_Host *shost)
        sprintf(name,"%d", shost->host_no);
        remove_proc_entry(name, shost->hostt->proc_dir);
 }
-
+/**
+ * proc_print_scsidevice - return data about this host
+ * @dev: A scsi device
+ * @data: &struct seq_file to output to.
+ *
+ * Description: prints Host, Channel, Id, Lun, Vendor, Model, Rev, Type,
+ * and revision.
+ */
 static int proc_print_scsidevice(struct device *dev, void *data)
 {
-       struct scsi_device *sdev = to_scsi_device(dev);
+       struct scsi_device *sdev;
        struct seq_file *s = data;
        int i;
 
+       if (!scsi_is_sdev_device(dev))
+               goto out;
+
+       sdev = to_scsi_device(dev);
        seq_printf(s,
                "Host: scsi%d Channel: %02d Id: %02d Lun: %02d\n  Vendor: ",
                sdev->host->host_no, sdev->channel, sdev->id, sdev->lun);
@@ -176,34 +223,60 @@ static int proc_print_scsidevice(struct device *dev, void *data)
 
        seq_printf(s, "\n");
 
-       seq_printf(s, "  Type:   %s ",
-                    sdev->type < MAX_SCSI_DEVICE_CODE ?
-              scsi_device_types[(int) sdev->type] : "Unknown          ");
-       seq_printf(s, "               ANSI"
-                    " SCSI revision: %02x", (sdev->scsi_level - 1) ?
-                    sdev->scsi_level - 1 : 1);
+       seq_printf(s, "  Type:   %s ", scsi_device_type(sdev->type));
+       seq_printf(s, "               ANSI  SCSI revision: %02x",
+                       sdev->scsi_level - (sdev->scsi_level > 1));
        if (sdev->scsi_level == 2)
                seq_printf(s, " CCS\n");
        else
                seq_printf(s, "\n");
 
+out:
        return 0;
 }
 
+/**
+ * scsi_add_single_device - Respond to user request to probe for/add device
+ * @host: user-supplied decimal integer
+ * @channel: user-supplied decimal integer
+ * @id: user-supplied decimal integer
+ * @lun: user-supplied decimal integer
+ *
+ * Description: called by writing "scsi add-single-device" to /proc/scsi/scsi.
+ *
+ * does scsi_host_lookup() and either user_scan() if that transport
+ * type supports it, or else scsi_scan_host_selected()
+ *
+ * Note: this seems to be aimed exclusively at SCSI parallel busses.
+ */
+
 static int scsi_add_single_device(uint host, uint channel, uint id, uint lun)
 {
        struct Scsi_Host *shost;
        int error = -ENXIO;
 
        shost = scsi_host_lookup(host);
-       if (IS_ERR(shost))
-               return PTR_ERR(shost);
+       if (!shost)
+               return error;
 
-       error = scsi_scan_host_selected(shost, channel, id, lun, 1);
+       if (shost->transportt->user_scan)
+               error = shost->transportt->user_scan(shost, channel, id, lun);
+       else
+               error = scsi_scan_host_selected(shost, channel, id, lun, 1);
        scsi_host_put(shost);
        return error;
 }
 
+/**
+ * scsi_remove_single_device - Respond to user request to remove a device
+ * @host: user-supplied decimal integer
+ * @channel: user-supplied decimal integer
+ * @id: user-supplied decimal integer
+ * @lun: user-supplied decimal integer
+ *
+ * Description: called by writing "scsi remove-single-device" to
+ * /proc/scsi/scsi.  Does a scsi_device_lookup() and scsi_remove_device()
+ */
 static int scsi_remove_single_device(uint host, uint channel, uint id, uint lun)
 {
        struct scsi_device *sdev;
@@ -211,8 +284,8 @@ static int scsi_remove_single_device(uint host, uint channel, uint id, uint lun)
        int error = -ENXIO;
 
        shost = scsi_host_lookup(host);
-       if (IS_ERR(shost))
-               return PTR_ERR(shost);
+       if (!shost)
+               return error;
        sdev = scsi_device_lookup(shost, channel, id, lun);
        if (sdev) {
                scsi_remove_device(sdev);
@@ -224,6 +297,25 @@ static int scsi_remove_single_device(uint host, uint channel, uint id, uint lun)
        return error;
 }
 
+/**
+ * proc_scsi_write - handle writes to /proc/scsi/scsi
+ * @file: not used
+ * @buf: buffer to write
+ * @length: length of buf, at most PAGE_SIZE
+ * @ppos: not used
+ *
+ * Description: this provides a legacy mechanism to add or remove devices by
+ * Host, Channel, ID, and Lun.  To use,
+ * "echo 'scsi add-single-device 0 1 2 3' > /proc/scsi/scsi" or
+ * "echo 'scsi remove-single-device 0 1 2 3' > /proc/scsi/scsi" with
+ * "0 1 2 3" replaced by the Host, Channel, Id, and Lun.
+ *
+ * Note: this seems to be aimed at parallel SCSI. Most modern busses (USB,
+ * SATA, Firewire, Fibre Channel, etc) dynamically assign these values to
+ * provide a unique identifier and nothing more.
+ */
+
+
 static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
                               size_t length, loff_t *ppos)
 {
@@ -261,8 +353,6 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
                lun = simple_strtoul(p + 1, &p, 0);
 
                err = scsi_add_single_device(host, channel, id, lun);
-               if (err >= 0)
-                       err = length;
 
        /*
         * Usage: echo "scsi remove-single-device 0 1 2 3" >/proc/scsi/scsi
@@ -279,11 +369,23 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
                err = scsi_remove_single_device(host, channel, id, lun);
        }
 
+       /*
+        * convert success returns so that we return the 
+        * number of bytes consumed.
+        */
+       if (!err)
+               err = length;
+
  out:
        free_page((unsigned long)buffer);
        return err;
 }
 
+/**
+ * proc_scsi_show - show contents of /proc/scsi/scsi (attached devices)
+ * @s: output goes here
+ * @p: not used
+ */
 static int proc_scsi_show(struct seq_file *s, void *p)
 {
        seq_printf(s, "Attached devices:\n");
@@ -291,16 +393,24 @@ static int proc_scsi_show(struct seq_file *s, void *p)
        return 0;
 }
 
+/**
+ * proc_scsi_open - glue function
+ * @inode: not used
+ * @file: passed to single_open()
+ *
+ * Associates proc_scsi_show with this file
+ */
 static int proc_scsi_open(struct inode *inode, struct file *file)
 {
        /*
-        * We don't really needs this for the write case but it doesn't
+        * We don't really need this for the write case but it doesn't
         * harm either.
         */
        return single_open(file, proc_scsi_show, NULL);
 }
 
-static struct file_operations proc_scsi_operations = {
+static const struct file_operations proc_scsi_operations = {
+       .owner          = THIS_MODULE,
        .open           = proc_scsi_open,
        .read           = seq_read,
        .write          = proc_scsi_write,
@@ -308,6 +418,9 @@ static struct file_operations proc_scsi_operations = {
        .release        = single_release,
 };
 
+/**
+ * scsi_init_procfs - create scsi and scsi/scsi in procfs
+ */
 int __init scsi_init_procfs(void)
 {
        struct proc_dir_entry *pde;
@@ -316,10 +429,9 @@ int __init scsi_init_procfs(void)
        if (!proc_scsi)
                goto err1;
 
-       pde = create_proc_entry("scsi/scsi", 0, NULL);
+       pde = proc_create("scsi/scsi", 0, NULL, &proc_scsi_operations);
        if (!pde)
                goto err2;
-       pde->proc_fops = &proc_scsi_operations;
 
        return 0;
 
@@ -329,6 +441,9 @@ err1:
        return -ENOMEM;
 }
 
+/**
+ * scsi_exit_procfs - Remove scsi/scsi and scsi from procfs
+ */
 void scsi_exit_procfs(void)
 {
        remove_proc_entry("scsi/scsi", NULL);