]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/scsi/qla2xxx/qla_attr.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[linux-2.6-omap-h63xx.git] / drivers / scsi / qla2xxx / qla_attr.c
index adf97320574bacd7b53f63a0be445805e379d8be..d61df036910c1f46579807e5a17b9fee1ff73417 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * QLogic Fibre Channel HBA Driver
- * Copyright (c)  2003-2005 QLogic Corporation
+ * Copyright (c)  2003-2008 QLogic Corporation
  *
  * See LICENSE.qla2xxx for copyright and licensing details.
  */
@@ -428,6 +428,19 @@ qla2x00_sysfs_read_sfp(struct kobject *kobj,
        if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
                return 0;
 
+       if (ha->sfp_data)
+               goto do_read;
+
+       ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
+           &ha->sfp_data_dma);
+       if (!ha->sfp_data) {
+               qla_printk(KERN_WARNING, ha,
+                   "Unable to allocate memory for SFP read-data.\n");
+               return 0;
+       }
+
+do_read:
+       memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
        addr = 0xa0;
        for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
            iter++, offset += SFP_BLOCK_SIZE) {
@@ -517,15 +530,17 @@ qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
 /* Scsi_Host attributes. */
 
 static ssize_t
-qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
+qla2x00_drvr_version_show(struct device *dev,
+                         struct device_attribute *attr, char *buf)
 {
        return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
 }
 
 static ssize_t
-qla2x00_fw_version_show(struct class_device *cdev, char *buf)
+qla2x00_fw_version_show(struct device *dev,
+                       struct device_attribute *attr, char *buf)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
        char fw_str[30];
 
        return snprintf(buf, PAGE_SIZE, "%s\n",
@@ -533,9 +548,10 @@ qla2x00_fw_version_show(struct class_device *cdev, char *buf)
 }
 
 static ssize_t
-qla2x00_serial_num_show(struct class_device *cdev, char *buf)
+qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
+                       char *buf)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
        uint32_t sn;
 
        if (IS_FWI2_CAPABLE(ha))
@@ -547,40 +563,45 @@ qla2x00_serial_num_show(struct class_device *cdev, char *buf)
 }
 
 static ssize_t
-qla2x00_isp_name_show(struct class_device *cdev, char *buf)
+qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
+                     char *buf)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
        return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
 }
 
 static ssize_t
-qla2x00_isp_id_show(struct class_device *cdev, char *buf)
+qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
+                   char *buf)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
        return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
            ha->product_id[0], ha->product_id[1], ha->product_id[2],
            ha->product_id[3]);
 }
 
 static ssize_t
-qla2x00_model_name_show(struct class_device *cdev, char *buf)
+qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
+                       char *buf)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
        return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
 }
 
 static ssize_t
-qla2x00_model_desc_show(struct class_device *cdev, char *buf)
+qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
+                       char *buf)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
        return snprintf(buf, PAGE_SIZE, "%s\n",
            ha->model_desc ? ha->model_desc: "");
 }
 
 static ssize_t
-qla2x00_pci_info_show(struct class_device *cdev, char *buf)
+qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
+                     char *buf)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
        char pci_info[30];
 
        return snprintf(buf, PAGE_SIZE, "%s\n",
@@ -588,9 +609,10 @@ qla2x00_pci_info_show(struct class_device *cdev, char *buf)
 }
 
 static ssize_t
-qla2x00_state_show(struct class_device *cdev, char *buf)
+qla2x00_state_show(struct device *dev, struct device_attribute *attr,
+                  char *buf)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
        int len = 0;
 
        if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
@@ -626,9 +648,10 @@ qla2x00_state_show(struct class_device *cdev, char *buf)
 }
 
 static ssize_t
-qla2x00_zio_show(struct class_device *cdev, char *buf)
+qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
+                char *buf)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
        int len = 0;
 
        switch (ha->zio_mode) {
@@ -643,9 +666,10 @@ qla2x00_zio_show(struct class_device *cdev, char *buf)
 }
 
 static ssize_t
-qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
+qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
+                 const char *buf, size_t count)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
        int val = 0;
        uint16_t zio_mode;
 
@@ -669,18 +693,19 @@ qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
 }
 
 static ssize_t
-qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
+qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
+                      char *buf)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
 
        return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
 }
 
 static ssize_t
-qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
-    size_t count)
+qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
+                       const char *buf, size_t count)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
        int val = 0;
        uint16_t zio_timer;
 
@@ -696,9 +721,10 @@ qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
 }
 
 static ssize_t
-qla2x00_beacon_show(struct class_device *cdev, char *buf)
+qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
+                   char *buf)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
        int len = 0;
 
        if (ha->beacon_blink_led)
@@ -709,10 +735,10 @@ qla2x00_beacon_show(struct class_device *cdev, char *buf)
 }
 
 static ssize_t
-qla2x00_beacon_store(struct class_device *cdev, const char *buf,
-    size_t count)
+qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
+                    const char *buf, size_t count)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
        int val = 0;
        int rval;
 
@@ -740,84 +766,86 @@ qla2x00_beacon_store(struct class_device *cdev, const char *buf,
 }
 
 static ssize_t
-qla2x00_optrom_bios_version_show(struct class_device *cdev, char *buf)
+qla2x00_optrom_bios_version_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
 
        return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
            ha->bios_revision[0]);
 }
 
 static ssize_t
-qla2x00_optrom_efi_version_show(struct class_device *cdev, char *buf)
+qla2x00_optrom_efi_version_show(struct device *dev,
+                               struct device_attribute *attr, char *buf)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
 
        return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
            ha->efi_revision[0]);
 }
 
 static ssize_t
-qla2x00_optrom_fcode_version_show(struct class_device *cdev, char *buf)
+qla2x00_optrom_fcode_version_show(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
 
        return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
            ha->fcode_revision[0]);
 }
 
 static ssize_t
-qla2x00_optrom_fw_version_show(struct class_device *cdev, char *buf)
+qla2x00_optrom_fw_version_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
 {
-       scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
+       scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
 
        return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
            ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
            ha->fw_revision[3]);
 }
 
-static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
-       NULL);
-static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
-static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
-static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
-static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
-static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
-static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
-static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
-static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
-static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
-    qla2x00_zio_store);
-static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
-    qla2x00_zio_timer_store);
-static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
-    qla2x00_beacon_store);
-static CLASS_DEVICE_ATTR(optrom_bios_version, S_IRUGO,
-    qla2x00_optrom_bios_version_show, NULL);
-static CLASS_DEVICE_ATTR(optrom_efi_version, S_IRUGO,
-    qla2x00_optrom_efi_version_show, NULL);
-static CLASS_DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
-    qla2x00_optrom_fcode_version_show, NULL);
-static CLASS_DEVICE_ATTR(optrom_fw_version, S_IRUGO,
-    qla2x00_optrom_fw_version_show, NULL);
-
-struct class_device_attribute *qla2x00_host_attrs[] = {
-       &class_device_attr_driver_version,
-       &class_device_attr_fw_version,
-       &class_device_attr_serial_num,
-       &class_device_attr_isp_name,
-       &class_device_attr_isp_id,
-       &class_device_attr_model_name,
-       &class_device_attr_model_desc,
-       &class_device_attr_pci_info,
-       &class_device_attr_state,
-       &class_device_attr_zio,
-       &class_device_attr_zio_timer,
-       &class_device_attr_beacon,
-       &class_device_attr_optrom_bios_version,
-       &class_device_attr_optrom_efi_version,
-       &class_device_attr_optrom_fcode_version,
-       &class_device_attr_optrom_fw_version,
+static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
+static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
+static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
+static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
+static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
+static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
+static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
+static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
+static DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
+static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
+static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
+                  qla2x00_zio_timer_store);
+static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
+                  qla2x00_beacon_store);
+static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
+                  qla2x00_optrom_bios_version_show, NULL);
+static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
+                  qla2x00_optrom_efi_version_show, NULL);
+static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
+                  qla2x00_optrom_fcode_version_show, NULL);
+static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
+                  NULL);
+
+struct device_attribute *qla2x00_host_attrs[] = {
+       &dev_attr_driver_version,
+       &dev_attr_fw_version,
+       &dev_attr_serial_num,
+       &dev_attr_isp_name,
+       &dev_attr_isp_id,
+       &dev_attr_model_name,
+       &dev_attr_model_desc,
+       &dev_attr_pci_info,
+       &dev_attr_state,
+       &dev_attr_zio,
+       &dev_attr_zio_timer,
+       &dev_attr_beacon,
+       &dev_attr_optrom_bios_version,
+       &dev_attr_optrom_efi_version,
+       &dev_attr_optrom_fcode_version,
+       &dev_attr_optrom_fw_version,
        NULL,
 };
 
@@ -835,18 +863,21 @@ qla2x00_get_host_port_id(struct Scsi_Host *shost)
 static void
 qla2x00_get_host_speed(struct Scsi_Host *shost)
 {
-       scsi_qla_host_t *ha = shost_priv(shost);
-       uint32_t speed = 0;
+       scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
+       u32 speed = FC_PORTSPEED_UNKNOWN;
 
        switch (ha->link_data_rate) {
        case PORT_SPEED_1GB:
-               speed = 1;
+               speed = FC_PORTSPEED_1GBIT;
                break;
        case PORT_SPEED_2GB:
-               speed = 2;
+               speed = FC_PORTSPEED_2GBIT;
                break;
        case PORT_SPEED_4GB:
-               speed = 4;
+               speed = FC_PORTSPEED_4GBIT;
+               break;
+       case PORT_SPEED_8GB:
+               speed = FC_PORTSPEED_8GBIT;
                break;
        }
        fc_host_speed(shost) = speed;
@@ -855,7 +886,7 @@ qla2x00_get_host_speed(struct Scsi_Host *shost)
 static void
 qla2x00_get_host_port_type(struct Scsi_Host *shost)
 {
-       scsi_qla_host_t *ha = shost_priv(shost);
+       scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
        uint32_t port_type = FC_PORTTYPE_UNKNOWN;
 
        switch (ha->current_topology) {
@@ -884,7 +915,8 @@ qla2x00_get_starget_node_name(struct scsi_target *starget)
        u64 node_name = 0;
 
        list_for_each_entry(fcport, &ha->fcports, list) {
-               if (starget->id == fcport->os_target_id) {
+               if (fcport->rport &&
+                   starget->id == fcport->rport->scsi_target_id) {
                        node_name = wwn_to_u64(fcport->node_name);
                        break;
                }
@@ -902,7 +934,8 @@ qla2x00_get_starget_port_name(struct scsi_target *starget)
        u64 port_name = 0;
 
        list_for_each_entry(fcport, &ha->fcports, list) {
-               if (starget->id == fcport->os_target_id) {
+               if (fcport->rport &&
+                   starget->id == fcport->rport->scsi_target_id) {
                        port_name = wwn_to_u64(fcport->port_name);
                        break;
                }
@@ -920,7 +953,8 @@ qla2x00_get_starget_port_id(struct scsi_target *starget)
        uint32_t port_id = ~0U;
 
        list_for_each_entry(fcport, &ha->fcports, list) {
-               if (starget->id == fcport->os_target_id) {
+               if (fcport->rport &&
+                   starget->id == fcport->rport->scsi_target_id) {
                        port_id = fcport->d_id.b.domain << 16 |
                            fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
                        break;
@@ -965,7 +999,7 @@ qla2x00_issue_lip(struct Scsi_Host *shost)
 static struct fc_host_statistics *
 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
 {
-       scsi_qla_host_t *ha = shost_priv(shost);
+       scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
        int rval;
        struct link_statistics *stats;
        dma_addr_t stats_dma;
@@ -1049,7 +1083,7 @@ qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
 static void
 qla2x00_get_host_port_state(struct Scsi_Host *shost)
 {
-       scsi_qla_host_t *ha = shost_priv(shost);
+       scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
 
        if (!ha->flags.online)
                fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
@@ -1180,6 +1214,7 @@ struct fc_function_template qla2xxx_transport_functions = {
        .show_host_node_name = 1,
        .show_host_port_name = 1,
        .show_host_supported_classes = 1,
+       .show_host_supported_speeds = 1,
 
        .get_host_port_id = qla2x00_get_host_port_id,
        .show_host_port_id = 1,
@@ -1260,9 +1295,23 @@ struct fc_function_template qla2xxx_transport_vport_functions = {
 void
 qla2x00_init_host_attr(scsi_qla_host_t *ha)
 {
+       u32 speed = FC_PORTSPEED_UNKNOWN;
+
        fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
        fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
        fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
        fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;;
        fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;
+
+       if (IS_QLA25XX(ha))
+               speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
+                   FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
+       else if (IS_QLA24XX_TYPE(ha))
+               speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
+                   FC_PORTSPEED_1GBIT;
+       else if (IS_QLA23XX(ha))
+               speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
+       else
+               speed = FC_PORTSPEED_1GBIT;
+       fc_host_supported_speeds(ha->host) = speed;
 }