| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1 | /* |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 2 | * QLogic Fibre Channel HBA Driver |
Andrew Vasquez | 01e58d8 | 2008-04-03 13:13:13 -0700 | [diff] [blame] | 3 | * Copyright (c) 2003-2008 QLogic Corporation |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4 | * |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 6 | */ |
| 7 | #include "qla_def.h" |
| 8 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 9 | #include <linux/kthread.h> |
| 7aaef27 | 2005-04-17 16:32:42 -0500 | [diff] [blame] | 10 | #include <linux/vmalloc.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
FUJITA Tomonori | 00eabe7 | 2008-07-28 11:59:20 +0900 | [diff] [blame] | 12 | #include <linux/delay.h> |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 13 | |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 14 | static int qla24xx_vport_disable(struct fc_vport *, bool); |
Giridhar Malavali | 6e98016 | 2010-03-19 17:03:58 -0700 | [diff] [blame] | 15 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 16 | /* SYSFS attributes --------------------------------------------------------- */ |
| 17 | |
| 18 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 19 | qla2x00_sysfs_read_fw_dump(struct kobject *kobj, |
| 20 | struct bin_attribute *bin_attr, |
| 21 | char *buf, loff_t off, size_t count) |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 22 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 23 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 24 | struct device, kobj))); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 25 | struct qla_hw_data *ha = vha->hw; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 26 | |
| 27 | if (ha->fw_dump_reading == 0) |
| 28 | return 0; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 29 | |
Akinobu Mita | b3dc908 | 2008-07-24 08:31:47 -0700 | [diff] [blame] | 30 | return memory_read_from_buffer(buf, count, &off, ha->fw_dump, |
| 31 | ha->fw_dump_len); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 35 | qla2x00_sysfs_write_fw_dump(struct kobject *kobj, |
| 36 | struct bin_attribute *bin_attr, |
| 37 | char *buf, loff_t off, size_t count) |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 38 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 39 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 40 | struct device, kobj))); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 41 | struct qla_hw_data *ha = vha->hw; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 42 | int reading; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 43 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 44 | if (IS_QLA82XX(ha)) { |
| 45 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 46 | "Firmware dump not supported for ISP82xx\n")); |
| 47 | return count; |
| 48 | } |
| 49 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 50 | if (off != 0) |
| 51 | return (0); |
| 52 | |
| 53 | reading = simple_strtol(buf, NULL, 10); |
| 54 | switch (reading) { |
| 55 | case 0: |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 56 | if (!ha->fw_dump_reading) |
| 57 | break; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 58 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 59 | qla_printk(KERN_INFO, ha, |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 60 | "Firmware dump cleared on (%ld).\n", vha->host_no); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 61 | |
| 62 | ha->fw_dump_reading = 0; |
| 63 | ha->fw_dumped = 0; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 64 | break; |
| 65 | case 1: |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 66 | if (ha->fw_dumped && !ha->fw_dump_reading) { |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 67 | ha->fw_dump_reading = 1; |
| 68 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 69 | qla_printk(KERN_INFO, ha, |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 70 | "Raw firmware dump ready for read on (%ld).\n", |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 71 | vha->host_no); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 72 | } |
| 73 | break; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 74 | case 2: |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 75 | qla2x00_alloc_fw_dump(vha); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 76 | break; |
Andrew Vasquez | 68af081 | 2008-05-12 22:21:13 -0700 | [diff] [blame] | 77 | case 3: |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 78 | qla2x00_system_error(vha); |
Andrew Vasquez | 68af081 | 2008-05-12 22:21:13 -0700 | [diff] [blame] | 79 | break; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 80 | } |
| 81 | return (count); |
| 82 | } |
| 83 | |
| 84 | static struct bin_attribute sysfs_fw_dump_attr = { |
| 85 | .attr = { |
| 86 | .name = "fw_dump", |
| 87 | .mode = S_IRUSR | S_IWUSR, |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 88 | }, |
| 89 | .size = 0, |
| 90 | .read = qla2x00_sysfs_read_fw_dump, |
| 91 | .write = qla2x00_sysfs_write_fw_dump, |
| 92 | }; |
| 93 | |
| 94 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 95 | qla2x00_sysfs_read_nvram(struct kobject *kobj, |
| 96 | struct bin_attribute *bin_attr, |
| 97 | char *buf, loff_t off, size_t count) |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 98 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 99 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 100 | struct device, kobj))); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 101 | struct qla_hw_data *ha = vha->hw; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 102 | |
Akinobu Mita | b3dc908 | 2008-07-24 08:31:47 -0700 | [diff] [blame] | 103 | if (!capable(CAP_SYS_ADMIN)) |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 104 | return 0; |
| 105 | |
Andrew Vasquez | 6749ce3 | 2009-03-24 09:08:17 -0700 | [diff] [blame] | 106 | if (IS_NOCACHE_VPD_TYPE(ha)) |
Andrew Vasquez | 8f97975 | 2009-04-06 22:33:43 -0700 | [diff] [blame] | 107 | ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2, |
Andrew Vasquez | 6749ce3 | 2009-03-24 09:08:17 -0700 | [diff] [blame] | 108 | ha->nvram_size); |
Akinobu Mita | b3dc908 | 2008-07-24 08:31:47 -0700 | [diff] [blame] | 109 | return memory_read_from_buffer(buf, count, &off, ha->nvram, |
| 110 | ha->nvram_size); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 114 | qla2x00_sysfs_write_nvram(struct kobject *kobj, |
| 115 | struct bin_attribute *bin_attr, |
| 116 | char *buf, loff_t off, size_t count) |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 117 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 118 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 119 | struct device, kobj))); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 120 | struct qla_hw_data *ha = vha->hw; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 121 | uint16_t cnt; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 122 | |
Andrew Vasquez | 3d79038 | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 123 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size || |
| 124 | !ha->isp_ops->write_nvram) |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 125 | return 0; |
| 126 | |
| 127 | /* Checksum NVRAM. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 128 | if (IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 129 | uint32_t *iter; |
| 130 | uint32_t chksum; |
| 131 | |
| 132 | iter = (uint32_t *)buf; |
| 133 | chksum = 0; |
| 134 | for (cnt = 0; cnt < ((count >> 2) - 1); cnt++) |
| 135 | chksum += le32_to_cpu(*iter++); |
| 136 | chksum = ~chksum + 1; |
| 137 | *iter = cpu_to_le32(chksum); |
| 138 | } else { |
| 139 | uint8_t *iter; |
| 140 | uint8_t chksum; |
| 141 | |
| 142 | iter = (uint8_t *)buf; |
| 143 | chksum = 0; |
| 144 | for (cnt = 0; cnt < count - 1; cnt++) |
| 145 | chksum += *iter++; |
| 146 | chksum = ~chksum + 1; |
| 147 | *iter = chksum; |
| 148 | } |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 149 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 150 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) { |
| 151 | qla_printk(KERN_WARNING, ha, |
| 152 | "HBA not online, failing NVRAM update.\n"); |
| 153 | return -EAGAIN; |
| 154 | } |
| 155 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 156 | /* Write NVRAM. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 157 | ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count); |
| 158 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 159 | count); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 160 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 161 | /* NVRAM settings take effect immediately. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 162 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 163 | qla2xxx_wake_dpc(vha); |
| 164 | qla2x00_wait_for_chip_reset(vha); |
Andrew Vasquez | 26b8d348 | 2007-01-29 10:22:28 -0800 | [diff] [blame] | 165 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 166 | return (count); |
| 167 | } |
| 168 | |
| 169 | static struct bin_attribute sysfs_nvram_attr = { |
| 170 | .attr = { |
| 171 | .name = "nvram", |
| 172 | .mode = S_IRUSR | S_IWUSR, |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 173 | }, |
andrew.vasquez@qlogic.com | 1b3f636 | 2006-01-31 16:05:12 -0800 | [diff] [blame] | 174 | .size = 512, |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 175 | .read = qla2x00_sysfs_read_nvram, |
| 176 | .write = qla2x00_sysfs_write_nvram, |
| 177 | }; |
| 178 | |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 179 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 180 | qla2x00_sysfs_read_optrom(struct kobject *kobj, |
| 181 | struct bin_attribute *bin_attr, |
| 182 | char *buf, loff_t off, size_t count) |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 183 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 184 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 185 | struct device, kobj))); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 186 | struct qla_hw_data *ha = vha->hw; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 187 | |
| 188 | if (ha->optrom_state != QLA_SREADING) |
| 189 | return 0; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 190 | |
Akinobu Mita | b3dc908 | 2008-07-24 08:31:47 -0700 | [diff] [blame] | 191 | return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer, |
| 192 | ha->optrom_region_size); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 196 | qla2x00_sysfs_write_optrom(struct kobject *kobj, |
| 197 | struct bin_attribute *bin_attr, |
| 198 | char *buf, loff_t off, size_t count) |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 199 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 200 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 201 | struct device, kobj))); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 202 | struct qla_hw_data *ha = vha->hw; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 203 | |
| 204 | if (ha->optrom_state != QLA_SWRITING) |
| 205 | return -EINVAL; |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 206 | if (off > ha->optrom_region_size) |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 207 | return -ERANGE; |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 208 | if (off + count > ha->optrom_region_size) |
| 209 | count = ha->optrom_region_size - off; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 210 | |
| 211 | memcpy(&ha->optrom_buffer[off], buf, count); |
| 212 | |
| 213 | return count; |
| 214 | } |
| 215 | |
| 216 | static struct bin_attribute sysfs_optrom_attr = { |
| 217 | .attr = { |
| 218 | .name = "optrom", |
| 219 | .mode = S_IRUSR | S_IWUSR, |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 220 | }, |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 221 | .size = 0, |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 222 | .read = qla2x00_sysfs_read_optrom, |
| 223 | .write = qla2x00_sysfs_write_optrom, |
| 224 | }; |
| 225 | |
| 226 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 227 | qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj, |
| 228 | struct bin_attribute *bin_attr, |
| 229 | char *buf, loff_t off, size_t count) |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 230 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 231 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 232 | struct device, kobj))); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 233 | struct qla_hw_data *ha = vha->hw; |
| 234 | |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 235 | uint32_t start = 0; |
| 236 | uint32_t size = ha->optrom_size; |
| 237 | int val, valid; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 238 | |
| 239 | if (off) |
| 240 | return 0; |
| 241 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 242 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 243 | return 0; |
| 244 | |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 245 | if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1) |
| 246 | return -EINVAL; |
| 247 | if (start > ha->optrom_size) |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 248 | return -EINVAL; |
| 249 | |
| 250 | switch (val) { |
| 251 | case 0: |
| 252 | if (ha->optrom_state != QLA_SREADING && |
| 253 | ha->optrom_state != QLA_SWRITING) |
| 254 | break; |
| 255 | |
| 256 | ha->optrom_state = QLA_SWAITING; |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 257 | |
| 258 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 259 | "Freeing flash region allocation -- 0x%x bytes.\n", |
| 260 | ha->optrom_region_size)); |
| 261 | |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 262 | vfree(ha->optrom_buffer); |
| 263 | ha->optrom_buffer = NULL; |
| 264 | break; |
| 265 | case 1: |
| 266 | if (ha->optrom_state != QLA_SWAITING) |
| 267 | break; |
| 268 | |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 269 | ha->optrom_region_start = start; |
| 270 | ha->optrom_region_size = start + size > ha->optrom_size ? |
| 271 | ha->optrom_size - start : size; |
| 272 | |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 273 | ha->optrom_state = QLA_SREADING; |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 274 | ha->optrom_buffer = vmalloc(ha->optrom_region_size); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 275 | if (ha->optrom_buffer == NULL) { |
| 276 | qla_printk(KERN_WARNING, ha, |
| 277 | "Unable to allocate memory for optrom retrieval " |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 278 | "(%x).\n", ha->optrom_region_size); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 279 | |
| 280 | ha->optrom_state = QLA_SWAITING; |
| 281 | return count; |
| 282 | } |
| 283 | |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 284 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 285 | "Reading flash region -- 0x%x/0x%x.\n", |
| 286 | ha->optrom_region_start, ha->optrom_region_size)); |
| 287 | |
| 288 | memset(ha->optrom_buffer, 0, ha->optrom_region_size); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 289 | ha->isp_ops->read_optrom(vha, ha->optrom_buffer, |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 290 | ha->optrom_region_start, ha->optrom_region_size); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 291 | break; |
| 292 | case 2: |
| 293 | if (ha->optrom_state != QLA_SWAITING) |
| 294 | break; |
| 295 | |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 296 | /* |
| 297 | * We need to be more restrictive on which FLASH regions are |
| 298 | * allowed to be updated via user-space. Regions accessible |
| 299 | * via this method include: |
| 300 | * |
| 301 | * ISP21xx/ISP22xx/ISP23xx type boards: |
| 302 | * |
| 303 | * 0x000000 -> 0x020000 -- Boot code. |
| 304 | * |
| 305 | * ISP2322/ISP24xx type boards: |
| 306 | * |
| 307 | * 0x000000 -> 0x07ffff -- Boot code. |
| 308 | * 0x080000 -> 0x0fffff -- Firmware. |
| 309 | * |
| 310 | * ISP25xx type boards: |
| 311 | * |
| 312 | * 0x000000 -> 0x07ffff -- Boot code. |
| 313 | * 0x080000 -> 0x0fffff -- Firmware. |
| 314 | * 0x120000 -> 0x12ffff -- VPD and HBA parameters. |
| 315 | */ |
| 316 | valid = 0; |
| 317 | if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0) |
| 318 | valid = 1; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 319 | else if (start == (ha->flt_region_boot * 4) || |
| 320 | start == (ha->flt_region_fw * 4)) |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 321 | valid = 1; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 322 | else if (IS_QLA25XX(ha) || IS_QLA8XXX_TYPE(ha)) |
| 323 | valid = 1; |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 324 | if (!valid) { |
| 325 | qla_printk(KERN_WARNING, ha, |
| 326 | "Invalid start region 0x%x/0x%x.\n", start, size); |
| 327 | return -EINVAL; |
| 328 | } |
| 329 | |
| 330 | ha->optrom_region_start = start; |
| 331 | ha->optrom_region_size = start + size > ha->optrom_size ? |
| 332 | ha->optrom_size - start : size; |
| 333 | |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 334 | ha->optrom_state = QLA_SWRITING; |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 335 | ha->optrom_buffer = vmalloc(ha->optrom_region_size); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 336 | if (ha->optrom_buffer == NULL) { |
| 337 | qla_printk(KERN_WARNING, ha, |
| 338 | "Unable to allocate memory for optrom update " |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 339 | "(%x).\n", ha->optrom_region_size); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 340 | |
| 341 | ha->optrom_state = QLA_SWAITING; |
| 342 | return count; |
| 343 | } |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 344 | |
| 345 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 346 | "Staging flash region write -- 0x%x/0x%x.\n", |
| 347 | ha->optrom_region_start, ha->optrom_region_size)); |
| 348 | |
| 349 | memset(ha->optrom_buffer, 0, ha->optrom_region_size); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 350 | break; |
| 351 | case 3: |
| 352 | if (ha->optrom_state != QLA_SWRITING) |
| 353 | break; |
| 354 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 355 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) { |
| 356 | qla_printk(KERN_WARNING, ha, |
| 357 | "HBA not online, failing flash update.\n"); |
| 358 | return -EAGAIN; |
| 359 | } |
| 360 | |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 361 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 362 | "Writing flash region -- 0x%x/0x%x.\n", |
| 363 | ha->optrom_region_start, ha->optrom_region_size)); |
| 364 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 365 | ha->isp_ops->write_optrom(vha, ha->optrom_buffer, |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 366 | ha->optrom_region_start, ha->optrom_region_size); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 367 | break; |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 368 | default: |
| 369 | count = -EINVAL; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 370 | } |
| 371 | return count; |
| 372 | } |
| 373 | |
| 374 | static struct bin_attribute sysfs_optrom_ctl_attr = { |
| 375 | .attr = { |
| 376 | .name = "optrom_ctl", |
| 377 | .mode = S_IWUSR, |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 378 | }, |
| 379 | .size = 0, |
| 380 | .write = qla2x00_sysfs_write_optrom_ctl, |
| 381 | }; |
| 382 | |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 383 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 384 | qla2x00_sysfs_read_vpd(struct kobject *kobj, |
| 385 | struct bin_attribute *bin_attr, |
| 386 | char *buf, loff_t off, size_t count) |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 387 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 388 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 389 | struct device, kobj))); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 390 | struct qla_hw_data *ha = vha->hw; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 391 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 392 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 393 | return 0; |
| 394 | |
Akinobu Mita | b3dc908 | 2008-07-24 08:31:47 -0700 | [diff] [blame] | 395 | if (!capable(CAP_SYS_ADMIN)) |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 396 | return 0; |
| 397 | |
Andrew Vasquez | 6749ce3 | 2009-03-24 09:08:17 -0700 | [diff] [blame] | 398 | if (IS_NOCACHE_VPD_TYPE(ha)) |
| 399 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 400 | ha->vpd_size); |
Akinobu Mita | b3dc908 | 2008-07-24 08:31:47 -0700 | [diff] [blame] | 401 | return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size); |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 405 | qla2x00_sysfs_write_vpd(struct kobject *kobj, |
| 406 | struct bin_attribute *bin_attr, |
| 407 | char *buf, loff_t off, size_t count) |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 408 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 409 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 410 | struct device, kobj))); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 411 | struct qla_hw_data *ha = vha->hw; |
Lalit Chandivade | d0c3eef | 2009-03-24 09:08:09 -0700 | [diff] [blame] | 412 | uint8_t *tmp_data; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 413 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 414 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 415 | return 0; |
| 416 | |
Andrew Vasquez | 3d79038 | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 417 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size || |
| 418 | !ha->isp_ops->write_nvram) |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 419 | return 0; |
| 420 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 421 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) { |
| 422 | qla_printk(KERN_WARNING, ha, |
| 423 | "HBA not online, failing VPD update.\n"); |
| 424 | return -EAGAIN; |
| 425 | } |
| 426 | |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 427 | /* Write NVRAM. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 428 | ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count); |
| 429 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count); |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 430 | |
Lalit Chandivade | d0c3eef | 2009-03-24 09:08:09 -0700 | [diff] [blame] | 431 | /* Update flash version information for 4Gb & above. */ |
| 432 | if (!IS_FWI2_CAPABLE(ha)) |
| 433 | goto done; |
| 434 | |
| 435 | tmp_data = vmalloc(256); |
| 436 | if (!tmp_data) { |
| 437 | qla_printk(KERN_WARNING, ha, |
| 438 | "Unable to allocate memory for VPD information update.\n"); |
| 439 | goto done; |
| 440 | } |
| 441 | ha->isp_ops->get_flash_version(vha, tmp_data); |
| 442 | vfree(tmp_data); |
| 443 | done: |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 444 | return count; |
| 445 | } |
| 446 | |
| 447 | static struct bin_attribute sysfs_vpd_attr = { |
| 448 | .attr = { |
| 449 | .name = "vpd", |
| 450 | .mode = S_IRUSR | S_IWUSR, |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 451 | }, |
| 452 | .size = 0, |
| 453 | .read = qla2x00_sysfs_read_vpd, |
| 454 | .write = qla2x00_sysfs_write_vpd, |
| 455 | }; |
| 456 | |
Andrew Vasquez | 88729e5 | 2006-06-23 16:10:50 -0700 | [diff] [blame] | 457 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 458 | qla2x00_sysfs_read_sfp(struct kobject *kobj, |
| 459 | struct bin_attribute *bin_attr, |
| 460 | char *buf, loff_t off, size_t count) |
Andrew Vasquez | 88729e5 | 2006-06-23 16:10:50 -0700 | [diff] [blame] | 461 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 462 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
Andrew Vasquez | 88729e5 | 2006-06-23 16:10:50 -0700 | [diff] [blame] | 463 | struct device, kobj))); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 464 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 88729e5 | 2006-06-23 16:10:50 -0700 | [diff] [blame] | 465 | uint16_t iter, addr, offset; |
| 466 | int rval; |
| 467 | |
| 468 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2) |
| 469 | return 0; |
| 470 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 471 | if (ha->sfp_data) |
| 472 | goto do_read; |
| 473 | |
| 474 | ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, |
| 475 | &ha->sfp_data_dma); |
| 476 | if (!ha->sfp_data) { |
| 477 | qla_printk(KERN_WARNING, ha, |
| 478 | "Unable to allocate memory for SFP read-data.\n"); |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | do_read: |
| 483 | memset(ha->sfp_data, 0, SFP_BLOCK_SIZE); |
Andrew Vasquez | 88729e5 | 2006-06-23 16:10:50 -0700 | [diff] [blame] | 484 | addr = 0xa0; |
| 485 | for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE; |
| 486 | iter++, offset += SFP_BLOCK_SIZE) { |
| 487 | if (iter == 4) { |
| 488 | /* Skip to next device address. */ |
| 489 | addr = 0xa2; |
| 490 | offset = 0; |
| 491 | } |
| 492 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 493 | rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset, |
Andrew Vasquez | 88729e5 | 2006-06-23 16:10:50 -0700 | [diff] [blame] | 494 | SFP_BLOCK_SIZE); |
| 495 | if (rval != QLA_SUCCESS) { |
| 496 | qla_printk(KERN_WARNING, ha, |
| 497 | "Unable to read SFP data (%x/%x/%x).\n", rval, |
| 498 | addr, offset); |
| 499 | count = 0; |
| 500 | break; |
| 501 | } |
| 502 | memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE); |
| 503 | buf += SFP_BLOCK_SIZE; |
| 504 | } |
| 505 | |
| 506 | return count; |
| 507 | } |
| 508 | |
| 509 | static struct bin_attribute sysfs_sfp_attr = { |
| 510 | .attr = { |
| 511 | .name = "sfp", |
| 512 | .mode = S_IRUSR | S_IWUSR, |
Andrew Vasquez | 88729e5 | 2006-06-23 16:10:50 -0700 | [diff] [blame] | 513 | }, |
| 514 | .size = SFP_DEV_SIZE * 2, |
| 515 | .read = qla2x00_sysfs_read_sfp, |
| 516 | }; |
| 517 | |
Lalit Chandivade | 6e181be | 2009-03-26 08:49:17 -0700 | [diff] [blame] | 518 | static ssize_t |
| 519 | qla2x00_sysfs_write_reset(struct kobject *kobj, |
| 520 | struct bin_attribute *bin_attr, |
| 521 | char *buf, loff_t off, size_t count) |
| 522 | { |
| 523 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
| 524 | struct device, kobj))); |
| 525 | struct qla_hw_data *ha = vha->hw; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 526 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Lalit Chandivade | 6e181be | 2009-03-26 08:49:17 -0700 | [diff] [blame] | 527 | int type; |
| 528 | |
| 529 | if (off != 0) |
| 530 | return 0; |
| 531 | |
| 532 | type = simple_strtol(buf, NULL, 10); |
| 533 | switch (type) { |
| 534 | case 0x2025c: |
| 535 | qla_printk(KERN_INFO, ha, |
| 536 | "Issuing ISP reset on (%ld).\n", vha->host_no); |
| 537 | |
| 538 | scsi_block_requests(vha->host); |
| 539 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 540 | qla2xxx_wake_dpc(vha); |
| 541 | qla2x00_wait_for_chip_reset(vha); |
| 542 | scsi_unblock_requests(vha->host); |
| 543 | break; |
| 544 | case 0x2025d: |
| 545 | if (!IS_QLA81XX(ha)) |
| 546 | break; |
| 547 | |
| 548 | qla_printk(KERN_INFO, ha, |
| 549 | "Issuing MPI reset on (%ld).\n", vha->host_no); |
| 550 | |
| 551 | /* Make sure FC side is not in reset */ |
| 552 | qla2x00_wait_for_hba_online(vha); |
| 553 | |
| 554 | /* Issue MPI reset */ |
| 555 | scsi_block_requests(vha->host); |
| 556 | if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS) |
| 557 | qla_printk(KERN_WARNING, ha, |
| 558 | "MPI reset failed on (%ld).\n", vha->host_no); |
| 559 | scsi_unblock_requests(vha->host); |
| 560 | break; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 561 | case 0x2025e: |
| 562 | if (!IS_QLA82XX(ha) || vha != base_vha) { |
| 563 | qla_printk(KERN_INFO, ha, |
| 564 | "FCoE ctx reset not supported for host%ld.\n", |
| 565 | vha->host_no); |
| 566 | return count; |
| 567 | } |
| 568 | |
| 569 | qla_printk(KERN_INFO, ha, |
| 570 | "Issuing FCoE CTX reset on host%ld.\n", vha->host_no); |
| 571 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); |
| 572 | qla2xxx_wake_dpc(vha); |
| 573 | qla2x00_wait_for_fcoe_ctx_reset(vha); |
| 574 | break; |
Lalit Chandivade | 6e181be | 2009-03-26 08:49:17 -0700 | [diff] [blame] | 575 | } |
| 576 | return count; |
| 577 | } |
| 578 | |
| 579 | static struct bin_attribute sysfs_reset_attr = { |
| 580 | .attr = { |
| 581 | .name = "reset", |
| 582 | .mode = S_IWUSR, |
| 583 | }, |
| 584 | .size = 0, |
| 585 | .write = qla2x00_sysfs_write_reset, |
| 586 | }; |
| 587 | |
Joe Carnuccio | ad0ecd6 | 2009-03-24 09:08:12 -0700 | [diff] [blame] | 588 | static ssize_t |
| 589 | qla2x00_sysfs_write_edc(struct kobject *kobj, |
| 590 | struct bin_attribute *bin_attr, |
| 591 | char *buf, loff_t off, size_t count) |
| 592 | { |
| 593 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
| 594 | struct device, kobj))); |
| 595 | struct qla_hw_data *ha = vha->hw; |
| 596 | uint16_t dev, adr, opt, len; |
| 597 | int rval; |
| 598 | |
| 599 | ha->edc_data_len = 0; |
| 600 | |
| 601 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8) |
| 602 | return 0; |
| 603 | |
| 604 | if (!ha->edc_data) { |
| 605 | ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, |
| 606 | &ha->edc_data_dma); |
| 607 | if (!ha->edc_data) { |
| 608 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 609 | "Unable to allocate memory for EDC write.\n")); |
| 610 | return 0; |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | dev = le16_to_cpup((void *)&buf[0]); |
| 615 | adr = le16_to_cpup((void *)&buf[2]); |
| 616 | opt = le16_to_cpup((void *)&buf[4]); |
| 617 | len = le16_to_cpup((void *)&buf[6]); |
| 618 | |
| 619 | if (!(opt & BIT_0)) |
| 620 | if (len == 0 || len > DMA_POOL_SIZE || len > count - 8) |
| 621 | return -EINVAL; |
| 622 | |
| 623 | memcpy(ha->edc_data, &buf[8], len); |
| 624 | |
| 625 | rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma, |
| 626 | ha->edc_data, len, opt); |
| 627 | if (rval != QLA_SUCCESS) { |
| 628 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 629 | "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n", |
| 630 | rval, dev, adr, opt, len, *buf)); |
| 631 | return 0; |
| 632 | } |
| 633 | |
| 634 | return count; |
| 635 | } |
| 636 | |
| 637 | static struct bin_attribute sysfs_edc_attr = { |
| 638 | .attr = { |
| 639 | .name = "edc", |
| 640 | .mode = S_IWUSR, |
| 641 | }, |
| 642 | .size = 0, |
| 643 | .write = qla2x00_sysfs_write_edc, |
| 644 | }; |
| 645 | |
| 646 | static ssize_t |
| 647 | qla2x00_sysfs_write_edc_status(struct kobject *kobj, |
| 648 | struct bin_attribute *bin_attr, |
| 649 | char *buf, loff_t off, size_t count) |
| 650 | { |
| 651 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
| 652 | struct device, kobj))); |
| 653 | struct qla_hw_data *ha = vha->hw; |
| 654 | uint16_t dev, adr, opt, len; |
| 655 | int rval; |
| 656 | |
| 657 | ha->edc_data_len = 0; |
| 658 | |
| 659 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8) |
| 660 | return 0; |
| 661 | |
| 662 | if (!ha->edc_data) { |
| 663 | ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, |
| 664 | &ha->edc_data_dma); |
| 665 | if (!ha->edc_data) { |
| 666 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 667 | "Unable to allocate memory for EDC status.\n")); |
| 668 | return 0; |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | dev = le16_to_cpup((void *)&buf[0]); |
| 673 | adr = le16_to_cpup((void *)&buf[2]); |
| 674 | opt = le16_to_cpup((void *)&buf[4]); |
| 675 | len = le16_to_cpup((void *)&buf[6]); |
| 676 | |
| 677 | if (!(opt & BIT_0)) |
| 678 | if (len == 0 || len > DMA_POOL_SIZE) |
| 679 | return -EINVAL; |
| 680 | |
| 681 | memset(ha->edc_data, 0, len); |
| 682 | rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma, |
| 683 | ha->edc_data, len, opt); |
| 684 | if (rval != QLA_SUCCESS) { |
| 685 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 686 | "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n", |
| 687 | rval, dev, adr, opt, len)); |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | ha->edc_data_len = len; |
| 692 | |
| 693 | return count; |
| 694 | } |
| 695 | |
| 696 | static ssize_t |
| 697 | qla2x00_sysfs_read_edc_status(struct kobject *kobj, |
| 698 | struct bin_attribute *bin_attr, |
| 699 | char *buf, loff_t off, size_t count) |
| 700 | { |
| 701 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
| 702 | struct device, kobj))); |
| 703 | struct qla_hw_data *ha = vha->hw; |
| 704 | |
| 705 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0) |
| 706 | return 0; |
| 707 | |
| 708 | if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count) |
| 709 | return -EINVAL; |
| 710 | |
| 711 | memcpy(buf, ha->edc_data, ha->edc_data_len); |
| 712 | |
| 713 | return ha->edc_data_len; |
| 714 | } |
| 715 | |
| 716 | static struct bin_attribute sysfs_edc_status_attr = { |
| 717 | .attr = { |
| 718 | .name = "edc_status", |
| 719 | .mode = S_IRUSR | S_IWUSR, |
| 720 | }, |
| 721 | .size = 0, |
| 722 | .write = qla2x00_sysfs_write_edc_status, |
| 723 | .read = qla2x00_sysfs_read_edc_status, |
| 724 | }; |
| 725 | |
Andrew Vasquez | ce0423f | 2009-06-03 09:55:13 -0700 | [diff] [blame] | 726 | static ssize_t |
| 727 | qla2x00_sysfs_read_xgmac_stats(struct kobject *kobj, |
| 728 | struct bin_attribute *bin_attr, |
| 729 | char *buf, loff_t off, size_t count) |
| 730 | { |
| 731 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
| 732 | struct device, kobj))); |
| 733 | struct qla_hw_data *ha = vha->hw; |
| 734 | int rval; |
| 735 | uint16_t actual_size; |
| 736 | |
| 737 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE) |
| 738 | return 0; |
| 739 | |
| 740 | if (ha->xgmac_data) |
| 741 | goto do_read; |
| 742 | |
| 743 | ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE, |
| 744 | &ha->xgmac_data_dma, GFP_KERNEL); |
| 745 | if (!ha->xgmac_data) { |
| 746 | qla_printk(KERN_WARNING, ha, |
| 747 | "Unable to allocate memory for XGMAC read-data.\n"); |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | do_read: |
| 752 | actual_size = 0; |
| 753 | memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE); |
| 754 | |
| 755 | rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma, |
| 756 | XGMAC_DATA_SIZE, &actual_size); |
| 757 | if (rval != QLA_SUCCESS) { |
| 758 | qla_printk(KERN_WARNING, ha, |
| 759 | "Unable to read XGMAC data (%x).\n", rval); |
| 760 | count = 0; |
| 761 | } |
| 762 | |
| 763 | count = actual_size > count ? count: actual_size; |
| 764 | memcpy(buf, ha->xgmac_data, count); |
| 765 | |
| 766 | return count; |
| 767 | } |
| 768 | |
| 769 | static struct bin_attribute sysfs_xgmac_stats_attr = { |
| 770 | .attr = { |
| 771 | .name = "xgmac_stats", |
| 772 | .mode = S_IRUSR, |
| 773 | }, |
| 774 | .size = 0, |
| 775 | .read = qla2x00_sysfs_read_xgmac_stats, |
| 776 | }; |
| 777 | |
Andrew Vasquez | 11bbc1d | 2009-06-03 09:55:14 -0700 | [diff] [blame] | 778 | static ssize_t |
| 779 | qla2x00_sysfs_read_dcbx_tlv(struct kobject *kobj, |
| 780 | struct bin_attribute *bin_attr, |
| 781 | char *buf, loff_t off, size_t count) |
| 782 | { |
| 783 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
| 784 | struct device, kobj))); |
| 785 | struct qla_hw_data *ha = vha->hw; |
| 786 | int rval; |
| 787 | uint16_t actual_size; |
| 788 | |
| 789 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE) |
| 790 | return 0; |
| 791 | |
| 792 | if (ha->dcbx_tlv) |
| 793 | goto do_read; |
| 794 | |
| 795 | ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE, |
| 796 | &ha->dcbx_tlv_dma, GFP_KERNEL); |
| 797 | if (!ha->dcbx_tlv) { |
| 798 | qla_printk(KERN_WARNING, ha, |
| 799 | "Unable to allocate memory for DCBX TLV read-data.\n"); |
| 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | do_read: |
| 804 | actual_size = 0; |
| 805 | memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE); |
| 806 | |
| 807 | rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma, |
| 808 | DCBX_TLV_DATA_SIZE); |
| 809 | if (rval != QLA_SUCCESS) { |
| 810 | qla_printk(KERN_WARNING, ha, |
| 811 | "Unable to read DCBX TLV data (%x).\n", rval); |
| 812 | count = 0; |
| 813 | } |
| 814 | |
| 815 | memcpy(buf, ha->dcbx_tlv, count); |
| 816 | |
| 817 | return count; |
| 818 | } |
| 819 | |
| 820 | static struct bin_attribute sysfs_dcbx_tlv_attr = { |
| 821 | .attr = { |
| 822 | .name = "dcbx_tlv", |
| 823 | .mode = S_IRUSR, |
| 824 | }, |
| 825 | .size = 0, |
| 826 | .read = qla2x00_sysfs_read_dcbx_tlv, |
| 827 | }; |
| 828 | |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 829 | static struct sysfs_entry { |
| 830 | char *name; |
| 831 | struct bin_attribute *attr; |
| 832 | int is4GBp_only; |
| 833 | } bin_file_entries[] = { |
| 834 | { "fw_dump", &sysfs_fw_dump_attr, }, |
| 835 | { "nvram", &sysfs_nvram_attr, }, |
| 836 | { "optrom", &sysfs_optrom_attr, }, |
| 837 | { "optrom_ctl", &sysfs_optrom_ctl_attr, }, |
| 838 | { "vpd", &sysfs_vpd_attr, 1 }, |
| 839 | { "sfp", &sysfs_sfp_attr, 1 }, |
Lalit Chandivade | 6e181be | 2009-03-26 08:49:17 -0700 | [diff] [blame] | 840 | { "reset", &sysfs_reset_attr, }, |
Joe Carnuccio | ad0ecd6 | 2009-03-24 09:08:12 -0700 | [diff] [blame] | 841 | { "edc", &sysfs_edc_attr, 2 }, |
| 842 | { "edc_status", &sysfs_edc_status_attr, 2 }, |
Andrew Vasquez | ce0423f | 2009-06-03 09:55:13 -0700 | [diff] [blame] | 843 | { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 }, |
Andrew Vasquez | 11bbc1d | 2009-06-03 09:55:14 -0700 | [diff] [blame] | 844 | { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 }, |
Randy Dunlap | 46ddab7 | 2006-11-27 09:35:42 -0800 | [diff] [blame] | 845 | { NULL }, |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 846 | }; |
| 847 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 848 | void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 849 | qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha) |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 850 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 851 | struct Scsi_Host *host = vha->host; |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 852 | struct sysfs_entry *iter; |
| 853 | int ret; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 854 | |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 855 | for (iter = bin_file_entries; iter->name; iter++) { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 856 | if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw)) |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 857 | continue; |
Joe Carnuccio | ad0ecd6 | 2009-03-24 09:08:12 -0700 | [diff] [blame] | 858 | if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw)) |
| 859 | continue; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 860 | if (iter->is4GBp_only == 3 && !(IS_QLA8XXX_TYPE(vha->hw))) |
Andrew Vasquez | ce0423f | 2009-06-03 09:55:13 -0700 | [diff] [blame] | 861 | continue; |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 862 | |
| 863 | ret = sysfs_create_bin_file(&host->shost_gendev.kobj, |
| 864 | iter->attr); |
| 865 | if (ret) |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 866 | qla_printk(KERN_INFO, vha->hw, |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 867 | "Unable to create sysfs %s binary attribute " |
| 868 | "(%d).\n", iter->name, ret); |
Andrew Vasquez | 7914d00 | 2006-06-23 16:10:55 -0700 | [diff] [blame] | 869 | } |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 873 | qla2x00_free_sysfs_attr(scsi_qla_host_t *vha) |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 874 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 875 | struct Scsi_Host *host = vha->host; |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 876 | struct sysfs_entry *iter; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 877 | struct qla_hw_data *ha = vha->hw; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 878 | |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 879 | for (iter = bin_file_entries; iter->name; iter++) { |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 880 | if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 881 | continue; |
Joe Carnuccio | ad0ecd6 | 2009-03-24 09:08:12 -0700 | [diff] [blame] | 882 | if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha)) |
| 883 | continue; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 884 | if (iter->is4GBp_only == 3 && !!(IS_QLA8XXX_TYPE(vha->hw))) |
Andrew Vasquez | ce0423f | 2009-06-03 09:55:13 -0700 | [diff] [blame] | 885 | continue; |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 886 | |
Andrew Vasquez | 7914d00 | 2006-06-23 16:10:55 -0700 | [diff] [blame] | 887 | sysfs_remove_bin_file(&host->shost_gendev.kobj, |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 888 | iter->attr); |
Andrew Vasquez | 7914d00 | 2006-06-23 16:10:55 -0700 | [diff] [blame] | 889 | } |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 890 | |
| 891 | if (ha->beacon_blink_led == 1) |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 892 | ha->isp_ops->beacon_off(vha); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 893 | } |
| 894 | |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 895 | /* Scsi_Host attributes. */ |
| 896 | |
| 897 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 898 | qla2x00_drvr_version_show(struct device *dev, |
| 899 | struct device_attribute *attr, char *buf) |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 900 | { |
| 901 | return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str); |
| 902 | } |
| 903 | |
| 904 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 905 | qla2x00_fw_version_show(struct device *dev, |
| 906 | struct device_attribute *attr, char *buf) |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 907 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 908 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 909 | struct qla_hw_data *ha = vha->hw; |
| 910 | char fw_str[128]; |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 911 | |
| 912 | return snprintf(buf, PAGE_SIZE, "%s\n", |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 913 | ha->isp_ops->fw_version_str(vha, fw_str)); |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 917 | qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr, |
| 918 | char *buf) |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 919 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 920 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 921 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 922 | uint32_t sn; |
| 923 | |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 924 | if (IS_FWI2_CAPABLE(ha)) { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 925 | qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 926 | return snprintf(buf, PAGE_SIZE, "%s\n", buf); |
| 927 | } |
Andrew Vasquez | 8b7afc2 | 2007-10-19 15:59:19 -0700 | [diff] [blame] | 928 | |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 929 | sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1; |
| 930 | return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000, |
| 931 | sn % 100000); |
| 932 | } |
| 933 | |
| 934 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 935 | qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr, |
| 936 | char *buf) |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 937 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 938 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 939 | return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device); |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 943 | qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr, |
| 944 | char *buf) |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 945 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 946 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 947 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 948 | return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n", |
| 949 | ha->product_id[0], ha->product_id[1], ha->product_id[2], |
| 950 | ha->product_id[3]); |
| 951 | } |
| 952 | |
| 953 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 954 | qla2x00_model_name_show(struct device *dev, struct device_attribute *attr, |
| 955 | char *buf) |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 956 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 957 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 958 | return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number); |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 962 | qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr, |
| 963 | char *buf) |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 964 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 965 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 966 | return snprintf(buf, PAGE_SIZE, "%s\n", |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 967 | vha->hw->model_desc ? vha->hw->model_desc : ""); |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 971 | qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr, |
| 972 | char *buf) |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 973 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 974 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 975 | char pci_info[30]; |
| 976 | |
| 977 | return snprintf(buf, PAGE_SIZE, "%s\n", |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 978 | vha->hw->isp_ops->pci_info_str(vha, pci_info)); |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | static ssize_t |
Hannes Reinecke | bbd1ae4 | 2008-03-18 14:32:28 +0100 | [diff] [blame] | 982 | qla2x00_link_state_show(struct device *dev, struct device_attribute *attr, |
| 983 | char *buf) |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 984 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 985 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 986 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 987 | int len = 0; |
| 988 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 989 | if (atomic_read(&vha->loop_state) == LOOP_DOWN || |
| 990 | atomic_read(&vha->loop_state) == LOOP_DEAD) |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 991 | len = snprintf(buf, PAGE_SIZE, "Link Down\n"); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 992 | else if (atomic_read(&vha->loop_state) != LOOP_READY || |
| 993 | test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) || |
| 994 | test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 995 | len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n"); |
| 996 | else { |
| 997 | len = snprintf(buf, PAGE_SIZE, "Link Up - "); |
| 998 | |
| 999 | switch (ha->current_topology) { |
| 1000 | case ISP_CFG_NL: |
| 1001 | len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n"); |
| 1002 | break; |
| 1003 | case ISP_CFG_FL: |
| 1004 | len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n"); |
| 1005 | break; |
| 1006 | case ISP_CFG_N: |
| 1007 | len += snprintf(buf + len, PAGE_SIZE-len, |
| 1008 | "N_Port to N_Port\n"); |
| 1009 | break; |
| 1010 | case ISP_CFG_F: |
| 1011 | len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n"); |
| 1012 | break; |
| 1013 | default: |
| 1014 | len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n"); |
| 1015 | break; |
| 1016 | } |
| 1017 | } |
| 1018 | return len; |
| 1019 | } |
| 1020 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1021 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1022 | qla2x00_zio_show(struct device *dev, struct device_attribute *attr, |
| 1023 | char *buf) |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1024 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1025 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1026 | int len = 0; |
| 1027 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1028 | switch (vha->hw->zio_mode) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1029 | case QLA_ZIO_MODE_6: |
| 1030 | len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n"); |
| 1031 | break; |
| 1032 | case QLA_ZIO_DISABLED: |
| 1033 | len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n"); |
| 1034 | break; |
| 1035 | } |
| 1036 | return len; |
| 1037 | } |
| 1038 | |
| 1039 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1040 | qla2x00_zio_store(struct device *dev, struct device_attribute *attr, |
| 1041 | const char *buf, size_t count) |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1042 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1043 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 1044 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1045 | int val = 0; |
| 1046 | uint16_t zio_mode; |
| 1047 | |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1048 | if (!IS_ZIO_SUPPORTED(ha)) |
| 1049 | return -ENOTSUPP; |
| 1050 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1051 | if (sscanf(buf, "%d", &val) != 1) |
| 1052 | return -EINVAL; |
| 1053 | |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1054 | if (val) |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1055 | zio_mode = QLA_ZIO_MODE_6; |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1056 | else |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1057 | zio_mode = QLA_ZIO_DISABLED; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1058 | |
| 1059 | /* Update per-hba values and queue a reset. */ |
| 1060 | if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) { |
| 1061 | ha->zio_mode = zio_mode; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1062 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1063 | } |
| 1064 | return strlen(buf); |
| 1065 | } |
| 1066 | |
| 1067 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1068 | qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr, |
| 1069 | char *buf) |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1070 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1071 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1072 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1073 | return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100); |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1077 | qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr, |
| 1078 | const char *buf, size_t count) |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1079 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1080 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1081 | int val = 0; |
| 1082 | uint16_t zio_timer; |
| 1083 | |
| 1084 | if (sscanf(buf, "%d", &val) != 1) |
| 1085 | return -EINVAL; |
| 1086 | if (val > 25500 || val < 100) |
| 1087 | return -ERANGE; |
| 1088 | |
| 1089 | zio_timer = (uint16_t)(val / 100); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1090 | vha->hw->zio_timer = zio_timer; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1091 | |
| 1092 | return strlen(buf); |
| 1093 | } |
| 1094 | |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1095 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1096 | qla2x00_beacon_show(struct device *dev, struct device_attribute *attr, |
| 1097 | char *buf) |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1098 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1099 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1100 | int len = 0; |
| 1101 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1102 | if (vha->hw->beacon_blink_led) |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1103 | len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n"); |
| 1104 | else |
| 1105 | len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n"); |
| 1106 | return len; |
| 1107 | } |
| 1108 | |
| 1109 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1110 | qla2x00_beacon_store(struct device *dev, struct device_attribute *attr, |
| 1111 | const char *buf, size_t count) |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1112 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1113 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 1114 | struct qla_hw_data *ha = vha->hw; |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1115 | int val = 0; |
| 1116 | int rval; |
| 1117 | |
| 1118 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 1119 | return -EPERM; |
| 1120 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1121 | if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) { |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1122 | qla_printk(KERN_WARNING, ha, |
| 1123 | "Abort ISP active -- ignoring beacon request.\n"); |
| 1124 | return -EBUSY; |
| 1125 | } |
| 1126 | |
| 1127 | if (sscanf(buf, "%d", &val) != 1) |
| 1128 | return -EINVAL; |
| 1129 | |
| 1130 | if (val) |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1131 | rval = ha->isp_ops->beacon_on(vha); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1132 | else |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1133 | rval = ha->isp_ops->beacon_off(vha); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1134 | |
| 1135 | if (rval != QLA_SUCCESS) |
| 1136 | count = 0; |
| 1137 | |
| 1138 | return count; |
| 1139 | } |
| 1140 | |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 1141 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1142 | qla2x00_optrom_bios_version_show(struct device *dev, |
| 1143 | struct device_attribute *attr, char *buf) |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 1144 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1145 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 1146 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 1147 | return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1], |
| 1148 | ha->bios_revision[0]); |
| 1149 | } |
| 1150 | |
| 1151 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1152 | qla2x00_optrom_efi_version_show(struct device *dev, |
| 1153 | struct device_attribute *attr, char *buf) |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 1154 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1155 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 1156 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 1157 | return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1], |
| 1158 | ha->efi_revision[0]); |
| 1159 | } |
| 1160 | |
| 1161 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1162 | qla2x00_optrom_fcode_version_show(struct device *dev, |
| 1163 | struct device_attribute *attr, char *buf) |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 1164 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1165 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 1166 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 1167 | return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1], |
| 1168 | ha->fcode_revision[0]); |
| 1169 | } |
| 1170 | |
| 1171 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1172 | qla2x00_optrom_fw_version_show(struct device *dev, |
| 1173 | struct device_attribute *attr, char *buf) |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 1174 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1175 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 1176 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 1177 | return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n", |
| 1178 | ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2], |
| 1179 | ha->fw_revision[3]); |
| 1180 | } |
| 1181 | |
Harish Zunjarrao | e5f5f6f | 2008-07-10 16:55:49 -0700 | [diff] [blame] | 1182 | static ssize_t |
| 1183 | qla2x00_total_isp_aborts_show(struct device *dev, |
| 1184 | struct device_attribute *attr, char *buf) |
| 1185 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1186 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 1187 | struct qla_hw_data *ha = vha->hw; |
Harish Zunjarrao | e5f5f6f | 2008-07-10 16:55:49 -0700 | [diff] [blame] | 1188 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 1189 | ha->qla_stats.total_isp_aborts); |
| 1190 | } |
| 1191 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1192 | static ssize_t |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1193 | qla24xx_84xx_fw_version_show(struct device *dev, |
| 1194 | struct device_attribute *attr, char *buf) |
| 1195 | { |
| 1196 | int rval = QLA_SUCCESS; |
| 1197 | uint16_t status[2] = {0, 0}; |
| 1198 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 1199 | struct qla_hw_data *ha = vha->hw; |
| 1200 | |
Andrew Vasquez | 0b9dae6 | 2010-05-04 15:01:21 -0700 | [diff] [blame^] | 1201 | if (!IS_QLA84XX(ha)) |
| 1202 | return snprintf(buf, PAGE_SIZE, "\n"); |
| 1203 | |
| 1204 | if (ha->cs84xx && ha->cs84xx->op_fw_version == 0) |
| 1205 | rval = qla84xx_verify_chip(vha, status); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1206 | |
| 1207 | if ((rval == QLA_SUCCESS) && (status[0] == 0)) |
| 1208 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 1209 | (uint32_t)ha->cs84xx->op_fw_version); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1210 | |
| 1211 | return snprintf(buf, PAGE_SIZE, "\n"); |
| 1212 | } |
| 1213 | |
| 1214 | static ssize_t |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1215 | qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr, |
| 1216 | char *buf) |
| 1217 | { |
| 1218 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 1219 | struct qla_hw_data *ha = vha->hw; |
| 1220 | |
| 1221 | if (!IS_QLA81XX(ha)) |
| 1222 | return snprintf(buf, PAGE_SIZE, "\n"); |
| 1223 | |
Andrew Vasquez | 55a9615 | 2009-03-24 09:08:03 -0700 | [diff] [blame] | 1224 | return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n", |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1225 | ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2], |
Andrew Vasquez | 55a9615 | 2009-03-24 09:08:03 -0700 | [diff] [blame] | 1226 | ha->mpi_capabilities); |
| 1227 | } |
| 1228 | |
| 1229 | static ssize_t |
| 1230 | qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr, |
| 1231 | char *buf) |
| 1232 | { |
| 1233 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 1234 | struct qla_hw_data *ha = vha->hw; |
| 1235 | |
| 1236 | if (!IS_QLA81XX(ha)) |
| 1237 | return snprintf(buf, PAGE_SIZE, "\n"); |
| 1238 | |
| 1239 | return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n", |
| 1240 | ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1241 | } |
| 1242 | |
Lalit Chandivade | fbcbb5d | 2009-03-24 09:08:11 -0700 | [diff] [blame] | 1243 | static ssize_t |
| 1244 | qla2x00_flash_block_size_show(struct device *dev, |
| 1245 | struct device_attribute *attr, char *buf) |
| 1246 | { |
| 1247 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 1248 | struct qla_hw_data *ha = vha->hw; |
| 1249 | |
| 1250 | return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size); |
| 1251 | } |
| 1252 | |
Andrew Vasquez | bad7001 | 2009-04-06 22:33:38 -0700 | [diff] [blame] | 1253 | static ssize_t |
| 1254 | qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr, |
| 1255 | char *buf) |
| 1256 | { |
| 1257 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 1258 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1259 | if (!IS_QLA8XXX_TYPE(vha->hw)) |
Andrew Vasquez | bad7001 | 2009-04-06 22:33:38 -0700 | [diff] [blame] | 1260 | return snprintf(buf, PAGE_SIZE, "\n"); |
| 1261 | |
| 1262 | return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id); |
| 1263 | } |
| 1264 | |
| 1265 | static ssize_t |
| 1266 | qla2x00_vn_port_mac_address_show(struct device *dev, |
| 1267 | struct device_attribute *attr, char *buf) |
| 1268 | { |
| 1269 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 1270 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1271 | if (!IS_QLA8XXX_TYPE(vha->hw)) |
Andrew Vasquez | bad7001 | 2009-04-06 22:33:38 -0700 | [diff] [blame] | 1272 | return snprintf(buf, PAGE_SIZE, "\n"); |
| 1273 | |
| 1274 | return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n", |
| 1275 | vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4], |
| 1276 | vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2], |
| 1277 | vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]); |
| 1278 | } |
| 1279 | |
Andrew Vasquez | 7f77402 | 2009-06-03 09:55:12 -0700 | [diff] [blame] | 1280 | static ssize_t |
| 1281 | qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr, |
| 1282 | char *buf) |
| 1283 | { |
| 1284 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
| 1285 | |
| 1286 | return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap); |
| 1287 | } |
| 1288 | |
Andrew Vasquez | 656e891 | 2009-06-03 09:55:29 -0700 | [diff] [blame] | 1289 | static ssize_t |
| 1290 | qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr, |
| 1291 | char *buf) |
| 1292 | { |
| 1293 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1294 | int rval = QLA_FUNCTION_FAILED; |
Andrew Vasquez | 656e891 | 2009-06-03 09:55:29 -0700 | [diff] [blame] | 1295 | uint16_t state[5]; |
| 1296 | |
Santosh Vernekar | d6136f3 | 2010-03-19 16:59:20 -0700 | [diff] [blame] | 1297 | if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) || |
| 1298 | test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 1299 | DEBUG2_3_11(printk("%s(%ld): isp reset in progress.\n", |
| 1300 | __func__, vha->host_no)); |
| 1301 | else if (!vha->hw->flags.eeh_busy) |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1302 | rval = qla2x00_get_firmware_state(vha, state); |
Andrew Vasquez | 656e891 | 2009-06-03 09:55:29 -0700 | [diff] [blame] | 1303 | if (rval != QLA_SUCCESS) |
| 1304 | memset(state, -1, sizeof(state)); |
| 1305 | |
| 1306 | return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0], |
| 1307 | state[1], state[2], state[3], state[4]); |
| 1308 | } |
| 1309 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1310 | static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL); |
| 1311 | static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL); |
| 1312 | static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL); |
| 1313 | static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL); |
| 1314 | static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL); |
| 1315 | static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL); |
| 1316 | static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL); |
| 1317 | static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL); |
Hannes Reinecke | bbd1ae4 | 2008-03-18 14:32:28 +0100 | [diff] [blame] | 1318 | static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1319 | static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store); |
| 1320 | static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show, |
| 1321 | qla2x00_zio_timer_store); |
| 1322 | static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show, |
| 1323 | qla2x00_beacon_store); |
| 1324 | static DEVICE_ATTR(optrom_bios_version, S_IRUGO, |
| 1325 | qla2x00_optrom_bios_version_show, NULL); |
| 1326 | static DEVICE_ATTR(optrom_efi_version, S_IRUGO, |
| 1327 | qla2x00_optrom_efi_version_show, NULL); |
| 1328 | static DEVICE_ATTR(optrom_fcode_version, S_IRUGO, |
| 1329 | qla2x00_optrom_fcode_version_show, NULL); |
| 1330 | static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show, |
| 1331 | NULL); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1332 | static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show, |
| 1333 | NULL); |
Harish Zunjarrao | e5f5f6f | 2008-07-10 16:55:49 -0700 | [diff] [blame] | 1334 | static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show, |
| 1335 | NULL); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1336 | static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL); |
Andrew Vasquez | 55a9615 | 2009-03-24 09:08:03 -0700 | [diff] [blame] | 1337 | static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL); |
Lalit Chandivade | fbcbb5d | 2009-03-24 09:08:11 -0700 | [diff] [blame] | 1338 | static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show, |
| 1339 | NULL); |
Andrew Vasquez | bad7001 | 2009-04-06 22:33:38 -0700 | [diff] [blame] | 1340 | static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL); |
| 1341 | static DEVICE_ATTR(vn_port_mac_address, S_IRUGO, |
| 1342 | qla2x00_vn_port_mac_address_show, NULL); |
Andrew Vasquez | 7f77402 | 2009-06-03 09:55:12 -0700 | [diff] [blame] | 1343 | static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL); |
Andrew Vasquez | 656e891 | 2009-06-03 09:55:29 -0700 | [diff] [blame] | 1344 | static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL); |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 1345 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1346 | struct device_attribute *qla2x00_host_attrs[] = { |
| 1347 | &dev_attr_driver_version, |
| 1348 | &dev_attr_fw_version, |
| 1349 | &dev_attr_serial_num, |
| 1350 | &dev_attr_isp_name, |
| 1351 | &dev_attr_isp_id, |
| 1352 | &dev_attr_model_name, |
| 1353 | &dev_attr_model_desc, |
| 1354 | &dev_attr_pci_info, |
Hannes Reinecke | bbd1ae4 | 2008-03-18 14:32:28 +0100 | [diff] [blame] | 1355 | &dev_attr_link_state, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1356 | &dev_attr_zio, |
| 1357 | &dev_attr_zio_timer, |
| 1358 | &dev_attr_beacon, |
| 1359 | &dev_attr_optrom_bios_version, |
| 1360 | &dev_attr_optrom_efi_version, |
| 1361 | &dev_attr_optrom_fcode_version, |
| 1362 | &dev_attr_optrom_fw_version, |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1363 | &dev_attr_84xx_fw_version, |
Harish Zunjarrao | e5f5f6f | 2008-07-10 16:55:49 -0700 | [diff] [blame] | 1364 | &dev_attr_total_isp_aborts, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1365 | &dev_attr_mpi_version, |
Andrew Vasquez | 55a9615 | 2009-03-24 09:08:03 -0700 | [diff] [blame] | 1366 | &dev_attr_phy_version, |
Lalit Chandivade | fbcbb5d | 2009-03-24 09:08:11 -0700 | [diff] [blame] | 1367 | &dev_attr_flash_block_size, |
Andrew Vasquez | bad7001 | 2009-04-06 22:33:38 -0700 | [diff] [blame] | 1368 | &dev_attr_vlan_id, |
| 1369 | &dev_attr_vn_port_mac_address, |
Andrew Vasquez | 7f77402 | 2009-06-03 09:55:12 -0700 | [diff] [blame] | 1370 | &dev_attr_fabric_param, |
Andrew Vasquez | 656e891 | 2009-06-03 09:55:29 -0700 | [diff] [blame] | 1371 | &dev_attr_fw_state, |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 1372 | NULL, |
| 1373 | }; |
| 1374 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1375 | /* Host attributes. */ |
| 1376 | |
| 1377 | static void |
| 1378 | qla2x00_get_host_port_id(struct Scsi_Host *shost) |
| 1379 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1380 | scsi_qla_host_t *vha = shost_priv(shost); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1381 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1382 | fc_host_port_id(shost) = vha->d_id.b.domain << 16 | |
| 1383 | vha->d_id.b.area << 8 | vha->d_id.b.al_pa; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | static void |
andrew.vasquez@qlogic.com | 0441401 | 2006-01-31 16:04:51 -0800 | [diff] [blame] | 1387 | qla2x00_get_host_speed(struct Scsi_Host *shost) |
| 1388 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1389 | struct qla_hw_data *ha = ((struct scsi_qla_host *) |
| 1390 | (shost_priv(shost)))->hw; |
Andrew Vasquez | 2ae2b37 | 2008-04-03 13:13:14 -0700 | [diff] [blame] | 1391 | u32 speed = FC_PORTSPEED_UNKNOWN; |
andrew.vasquez@qlogic.com | 0441401 | 2006-01-31 16:04:51 -0800 | [diff] [blame] | 1392 | |
| 1393 | switch (ha->link_data_rate) { |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 1394 | case PORT_SPEED_1GB: |
Andrew Vasquez | 2ae2b37 | 2008-04-03 13:13:14 -0700 | [diff] [blame] | 1395 | speed = FC_PORTSPEED_1GBIT; |
andrew.vasquez@qlogic.com | 0441401 | 2006-01-31 16:04:51 -0800 | [diff] [blame] | 1396 | break; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 1397 | case PORT_SPEED_2GB: |
Andrew Vasquez | 2ae2b37 | 2008-04-03 13:13:14 -0700 | [diff] [blame] | 1398 | speed = FC_PORTSPEED_2GBIT; |
andrew.vasquez@qlogic.com | 0441401 | 2006-01-31 16:04:51 -0800 | [diff] [blame] | 1399 | break; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 1400 | case PORT_SPEED_4GB: |
Andrew Vasquez | 2ae2b37 | 2008-04-03 13:13:14 -0700 | [diff] [blame] | 1401 | speed = FC_PORTSPEED_4GBIT; |
andrew.vasquez@qlogic.com | 0441401 | 2006-01-31 16:04:51 -0800 | [diff] [blame] | 1402 | break; |
Seokmann Ju | da4541b | 2008-01-31 12:33:52 -0800 | [diff] [blame] | 1403 | case PORT_SPEED_8GB: |
Andrew Vasquez | 2ae2b37 | 2008-04-03 13:13:14 -0700 | [diff] [blame] | 1404 | speed = FC_PORTSPEED_8GBIT; |
Seokmann Ju | da4541b | 2008-01-31 12:33:52 -0800 | [diff] [blame] | 1405 | break; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1406 | case PORT_SPEED_10GB: |
| 1407 | speed = FC_PORTSPEED_10GBIT; |
| 1408 | break; |
andrew.vasquez@qlogic.com | 0441401 | 2006-01-31 16:04:51 -0800 | [diff] [blame] | 1409 | } |
| 1410 | fc_host_speed(shost) = speed; |
| 1411 | } |
| 1412 | |
| 1413 | static void |
andrew.vasquez@qlogic.com | 8d06762 | 2006-01-31 16:04:56 -0800 | [diff] [blame] | 1414 | qla2x00_get_host_port_type(struct Scsi_Host *shost) |
| 1415 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1416 | scsi_qla_host_t *vha = shost_priv(shost); |
andrew.vasquez@qlogic.com | 8d06762 | 2006-01-31 16:04:56 -0800 | [diff] [blame] | 1417 | uint32_t port_type = FC_PORTTYPE_UNKNOWN; |
| 1418 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1419 | if (vha->vp_idx) { |
Shyam Sundar | 2f2fa13 | 2008-05-12 22:21:07 -0700 | [diff] [blame] | 1420 | fc_host_port_type(shost) = FC_PORTTYPE_NPIV; |
| 1421 | return; |
| 1422 | } |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1423 | switch (vha->hw->current_topology) { |
andrew.vasquez@qlogic.com | 8d06762 | 2006-01-31 16:04:56 -0800 | [diff] [blame] | 1424 | case ISP_CFG_NL: |
| 1425 | port_type = FC_PORTTYPE_LPORT; |
| 1426 | break; |
| 1427 | case ISP_CFG_FL: |
| 1428 | port_type = FC_PORTTYPE_NLPORT; |
| 1429 | break; |
| 1430 | case ISP_CFG_N: |
| 1431 | port_type = FC_PORTTYPE_PTP; |
| 1432 | break; |
| 1433 | case ISP_CFG_F: |
| 1434 | port_type = FC_PORTTYPE_NPORT; |
| 1435 | break; |
| 1436 | } |
| 1437 | fc_host_port_type(shost) = port_type; |
| 1438 | } |
| 1439 | |
| 1440 | static void |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1441 | qla2x00_get_starget_node_name(struct scsi_target *starget) |
| 1442 | { |
| 1443 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1444 | scsi_qla_host_t *vha = shost_priv(host); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1445 | fc_port_t *fcport; |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 1446 | u64 node_name = 0; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1447 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1448 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Andrew Vasquez | 5ab5a4d | 2008-04-03 13:13:16 -0700 | [diff] [blame] | 1449 | if (fcport->rport && |
| 1450 | starget->id == fcport->rport->scsi_target_id) { |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 1451 | node_name = wwn_to_u64(fcport->node_name); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1452 | break; |
| 1453 | } |
| 1454 | } |
| 1455 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 1456 | fc_starget_node_name(starget) = node_name; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | static void |
| 1460 | qla2x00_get_starget_port_name(struct scsi_target *starget) |
| 1461 | { |
| 1462 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1463 | scsi_qla_host_t *vha = shost_priv(host); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1464 | fc_port_t *fcport; |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 1465 | u64 port_name = 0; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1466 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1467 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Andrew Vasquez | 5ab5a4d | 2008-04-03 13:13:16 -0700 | [diff] [blame] | 1468 | if (fcport->rport && |
| 1469 | starget->id == fcport->rport->scsi_target_id) { |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 1470 | port_name = wwn_to_u64(fcport->port_name); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1471 | break; |
| 1472 | } |
| 1473 | } |
| 1474 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 1475 | fc_starget_port_name(starget) = port_name; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | static void |
| 1479 | qla2x00_get_starget_port_id(struct scsi_target *starget) |
| 1480 | { |
| 1481 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1482 | scsi_qla_host_t *vha = shost_priv(host); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1483 | fc_port_t *fcport; |
| 1484 | uint32_t port_id = ~0U; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1485 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1486 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Andrew Vasquez | 5ab5a4d | 2008-04-03 13:13:16 -0700 | [diff] [blame] | 1487 | if (fcport->rport && |
| 1488 | starget->id == fcport->rport->scsi_target_id) { |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1489 | port_id = fcport->d_id.b.domain << 16 | |
| 1490 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 1491 | break; |
| 1492 | } |
| 1493 | } |
| 1494 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1495 | fc_starget_port_id(starget) = port_id; |
| 1496 | } |
| 1497 | |
| 1498 | static void |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1499 | qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) |
| 1500 | { |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1501 | if (timeout) |
Andrew Vasquez | 85821c9 | 2008-07-10 16:55:48 -0700 | [diff] [blame] | 1502 | rport->dev_loss_tmo = timeout; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1503 | else |
Andrew Vasquez | 85821c9 | 2008-07-10 16:55:48 -0700 | [diff] [blame] | 1504 | rport->dev_loss_tmo = 1; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1505 | } |
| 1506 | |
Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 1507 | static void |
| 1508 | qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport) |
| 1509 | { |
| 1510 | struct Scsi_Host *host = rport_to_shost(rport); |
| 1511 | fc_port_t *fcport = *(fc_port_t **)rport->dd_data; |
| 1512 | |
Seokmann Ju | 3c01b4f | 2009-01-22 09:45:38 -0800 | [diff] [blame] | 1513 | if (!fcport) |
| 1514 | return; |
| 1515 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1516 | if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags)) |
| 1517 | return; |
| 1518 | |
| 1519 | if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) { |
Seokmann Ju | b9b12f7 | 2009-03-24 09:08:18 -0700 | [diff] [blame] | 1520 | qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16); |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1521 | return; |
| 1522 | } |
Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 1523 | |
| 1524 | /* |
| 1525 | * Transport has effectively 'deleted' the rport, clear |
| 1526 | * all local references. |
| 1527 | */ |
| 1528 | spin_lock_irq(host->host_lock); |
| 1529 | fcport->rport = NULL; |
| 1530 | *((fc_port_t **)rport->dd_data) = NULL; |
| 1531 | spin_unlock_irq(host->host_lock); |
| 1532 | } |
| 1533 | |
| 1534 | static void |
| 1535 | qla2x00_terminate_rport_io(struct fc_rport *rport) |
| 1536 | { |
| 1537 | fc_port_t *fcport = *(fc_port_t **)rport->dd_data; |
| 1538 | |
Seokmann Ju | 3c01b4f | 2009-01-22 09:45:38 -0800 | [diff] [blame] | 1539 | if (!fcport) |
| 1540 | return; |
| 1541 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1542 | if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags)) |
| 1543 | return; |
| 1544 | |
Seokmann Ju | b9b12f7 | 2009-03-24 09:08:18 -0700 | [diff] [blame] | 1545 | if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) { |
| 1546 | qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16); |
| 1547 | return; |
| 1548 | } |
Andrew Vasquez | 6390d1f | 2008-08-13 21:36:56 -0700 | [diff] [blame] | 1549 | /* |
| 1550 | * At this point all fcport's software-states are cleared. Perform any |
| 1551 | * final cleanup of firmware resources (PCBs and XCBs). |
| 1552 | */ |
Andrew Vasquez | 6805c15 | 2009-06-03 09:55:27 -0700 | [diff] [blame] | 1553 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 1554 | !test_bit(UNLOADING, &fcport->vha->dpc_flags)) |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1555 | fcport->vha->hw->isp_ops->fabric_logout(fcport->vha, |
| 1556 | fcport->loop_id, fcport->d_id.b.domain, |
| 1557 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 1558 | } |
| 1559 | |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 1560 | static int |
| 1561 | qla2x00_issue_lip(struct Scsi_Host *shost) |
| 1562 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1563 | scsi_qla_host_t *vha = shost_priv(shost); |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 1564 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1565 | qla2x00_loop_reset(vha); |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 1566 | return 0; |
| 1567 | } |
| 1568 | |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 1569 | static struct fc_host_statistics * |
| 1570 | qla2x00_get_fc_host_stats(struct Scsi_Host *shost) |
| 1571 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1572 | scsi_qla_host_t *vha = shost_priv(shost); |
| 1573 | struct qla_hw_data *ha = vha->hw; |
| 1574 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 1575 | int rval; |
Andrew Vasquez | 43ef058 | 2008-01-17 09:02:08 -0800 | [diff] [blame] | 1576 | struct link_statistics *stats; |
| 1577 | dma_addr_t stats_dma; |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 1578 | struct fc_host_statistics *pfc_host_stat; |
| 1579 | |
| 1580 | pfc_host_stat = &ha->fc_host_stat; |
| 1581 | memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics)); |
| 1582 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1583 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1584 | goto done; |
| 1585 | |
| 1586 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 1587 | goto done; |
| 1588 | |
Andrew Vasquez | 43ef058 | 2008-01-17 09:02:08 -0800 | [diff] [blame] | 1589 | stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma); |
| 1590 | if (stats == NULL) { |
| 1591 | DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n", |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1592 | __func__, base_vha->host_no)); |
Andrew Vasquez | 43ef058 | 2008-01-17 09:02:08 -0800 | [diff] [blame] | 1593 | goto done; |
| 1594 | } |
| 1595 | memset(stats, 0, DMA_POOL_SIZE); |
| 1596 | |
| 1597 | rval = QLA_FUNCTION_FAILED; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1598 | if (IS_FWI2_CAPABLE(ha)) { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1599 | rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma); |
| 1600 | } else if (atomic_read(&base_vha->loop_state) == LOOP_READY && |
| 1601 | !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) && |
| 1602 | !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) && |
Andrew Vasquez | 178779a | 2007-01-29 10:22:25 -0800 | [diff] [blame] | 1603 | !ha->dpc_active) { |
| 1604 | /* Must be in a 'READY' state for statistics retrieval. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1605 | rval = qla2x00_get_link_status(base_vha, base_vha->loop_id, |
| 1606 | stats, stats_dma); |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 1607 | } |
Andrew Vasquez | 178779a | 2007-01-29 10:22:25 -0800 | [diff] [blame] | 1608 | |
| 1609 | if (rval != QLA_SUCCESS) |
Andrew Vasquez | 43ef058 | 2008-01-17 09:02:08 -0800 | [diff] [blame] | 1610 | goto done_free; |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 1611 | |
Andrew Vasquez | 43ef058 | 2008-01-17 09:02:08 -0800 | [diff] [blame] | 1612 | pfc_host_stat->link_failure_count = stats->link_fail_cnt; |
| 1613 | pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt; |
| 1614 | pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt; |
| 1615 | pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt; |
| 1616 | pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt; |
| 1617 | pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt; |
| 1618 | if (IS_FWI2_CAPABLE(ha)) { |
Harish Zunjarrao | 032d8dd | 2008-07-10 16:55:50 -0700 | [diff] [blame] | 1619 | pfc_host_stat->lip_count = stats->lip_cnt; |
Andrew Vasquez | 43ef058 | 2008-01-17 09:02:08 -0800 | [diff] [blame] | 1620 | pfc_host_stat->tx_frames = stats->tx_frames; |
| 1621 | pfc_host_stat->rx_frames = stats->rx_frames; |
| 1622 | pfc_host_stat->dumped_frames = stats->dumped_frames; |
| 1623 | pfc_host_stat->nos_count = stats->nos_rcvd; |
| 1624 | } |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 1625 | pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20; |
| 1626 | pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20; |
Andrew Vasquez | 43ef058 | 2008-01-17 09:02:08 -0800 | [diff] [blame] | 1627 | |
| 1628 | done_free: |
| 1629 | dma_pool_free(ha->s_dma_pool, stats, stats_dma); |
Andrew Vasquez | 178779a | 2007-01-29 10:22:25 -0800 | [diff] [blame] | 1630 | done: |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 1631 | return pfc_host_stat; |
| 1632 | } |
| 1633 | |
Andrew Vasquez | 1620f7c | 2006-10-02 12:00:44 -0700 | [diff] [blame] | 1634 | static void |
| 1635 | qla2x00_get_host_symbolic_name(struct Scsi_Host *shost) |
| 1636 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1637 | scsi_qla_host_t *vha = shost_priv(shost); |
Andrew Vasquez | 1620f7c | 2006-10-02 12:00:44 -0700 | [diff] [blame] | 1638 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1639 | qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost)); |
Andrew Vasquez | 1620f7c | 2006-10-02 12:00:44 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
Andrew Vasquez | a740a3f | 2006-10-02 12:00:45 -0700 | [diff] [blame] | 1642 | static void |
| 1643 | qla2x00_set_host_system_hostname(struct Scsi_Host *shost) |
| 1644 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1645 | scsi_qla_host_t *vha = shost_priv(shost); |
Andrew Vasquez | a740a3f | 2006-10-02 12:00:45 -0700 | [diff] [blame] | 1646 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1647 | set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags); |
Andrew Vasquez | a740a3f | 2006-10-02 12:00:45 -0700 | [diff] [blame] | 1648 | } |
| 1649 | |
Andrew Vasquez | 90991c8 | 2006-10-02 12:00:46 -0700 | [diff] [blame] | 1650 | static void |
| 1651 | qla2x00_get_host_fabric_name(struct Scsi_Host *shost) |
| 1652 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1653 | scsi_qla_host_t *vha = shost_priv(shost); |
Andrew Vasquez | 90991c8 | 2006-10-02 12:00:46 -0700 | [diff] [blame] | 1654 | u64 node_name; |
| 1655 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1656 | if (vha->device_flags & SWITCH_FOUND) |
| 1657 | node_name = wwn_to_u64(vha->fabric_node_name); |
Andrew Vasquez | 90991c8 | 2006-10-02 12:00:46 -0700 | [diff] [blame] | 1658 | else |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1659 | node_name = wwn_to_u64(vha->node_name); |
Andrew Vasquez | 90991c8 | 2006-10-02 12:00:46 -0700 | [diff] [blame] | 1660 | |
| 1661 | fc_host_fabric_name(shost) = node_name; |
| 1662 | } |
| 1663 | |
Andrew Vasquez | 7047fcd | 2006-10-02 12:00:47 -0700 | [diff] [blame] | 1664 | static void |
| 1665 | qla2x00_get_host_port_state(struct Scsi_Host *shost) |
| 1666 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1667 | scsi_qla_host_t *vha = shost_priv(shost); |
| 1668 | struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev); |
Andrew Vasquez | 7047fcd | 2006-10-02 12:00:47 -0700 | [diff] [blame] | 1669 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1670 | if (!base_vha->flags.online) |
Andrew Vasquez | 7047fcd | 2006-10-02 12:00:47 -0700 | [diff] [blame] | 1671 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1672 | else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT) |
Andrew Vasquez | 7047fcd | 2006-10-02 12:00:47 -0700 | [diff] [blame] | 1673 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; |
| 1674 | else |
| 1675 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; |
| 1676 | } |
| 1677 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1678 | static int |
| 1679 | qla24xx_vport_create(struct fc_vport *fc_vport, bool disable) |
| 1680 | { |
| 1681 | int ret = 0; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1682 | uint8_t qos = 0; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1683 | scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost); |
| 1684 | scsi_qla_host_t *vha = NULL; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1685 | struct qla_hw_data *ha = base_vha->hw; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1686 | uint16_t options = 0; |
| 1687 | int cnt; |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 1688 | struct req_que *req = ha->req_q_map[0]; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1689 | |
| 1690 | ret = qla24xx_vport_create_req_sanity_check(fc_vport); |
| 1691 | if (ret) { |
| 1692 | DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, " |
| 1693 | "status %x\n", ret)); |
| 1694 | return (ret); |
| 1695 | } |
| 1696 | |
| 1697 | vha = qla24xx_create_vhost(fc_vport); |
| 1698 | if (vha == NULL) { |
| 1699 | DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n", |
| 1700 | vha)); |
| 1701 | return FC_VPORT_FAILED; |
| 1702 | } |
| 1703 | if (disable) { |
| 1704 | atomic_set(&vha->vp_state, VP_OFFLINE); |
| 1705 | fc_vport_set_state(fc_vport, FC_VPORT_DISABLED); |
| 1706 | } else |
| 1707 | atomic_set(&vha->vp_state, VP_FAILED); |
| 1708 | |
| 1709 | /* ready to create vport */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1710 | qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n", |
| 1711 | vha->vp_idx); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1712 | |
| 1713 | /* initialized vport states */ |
| 1714 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 1715 | vha->vp_err_state= VP_ERR_PORTDWN; |
| 1716 | vha->vp_prev_err_state= VP_ERR_UNKWN; |
| 1717 | /* Check if physical ha port is Up */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1718 | if (atomic_read(&base_vha->loop_state) == LOOP_DOWN || |
| 1719 | atomic_read(&base_vha->loop_state) == LOOP_DEAD) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1720 | /* Don't retry or attempt login of this virtual port */ |
| 1721 | DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n", |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1722 | base_vha->host_no)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1723 | atomic_set(&vha->loop_state, LOOP_DEAD); |
| 1724 | if (!disable) |
| 1725 | fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN); |
| 1726 | } |
| 1727 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 1728 | if (scsi_add_host_with_dma(vha->host, &fc_vport->dev, |
| 1729 | &ha->pdev->dev)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1730 | DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n", |
| 1731 | vha->host_no, vha->vp_idx)); |
| 1732 | goto vport_create_failed_2; |
| 1733 | } |
| 1734 | |
| 1735 | /* initialize attributes */ |
| 1736 | fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name); |
| 1737 | fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name); |
| 1738 | fc_host_supported_classes(vha->host) = |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1739 | fc_host_supported_classes(base_vha->host); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1740 | fc_host_supported_speeds(vha->host) = |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1741 | fc_host_supported_speeds(base_vha->host); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1742 | |
| 1743 | qla24xx_vport_disable(fc_vport, disable); |
| 1744 | |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 1745 | if (ha->flags.cpu_affinity_enabled) { |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 1746 | req = ha->req_q_map[1]; |
| 1747 | goto vport_queue; |
| 1748 | } else if (ql2xmaxqueues == 1 || !ha->npiv_info) |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1749 | goto vport_queue; |
| 1750 | /* Create a request queue in QoS mode for the vport */ |
Anirban Chakraborty | 40859ae | 2009-06-03 09:55:16 -0700 | [diff] [blame] | 1751 | for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) { |
| 1752 | if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0 |
| 1753 | && memcmp(ha->npiv_info[cnt].node_name, vha->node_name, |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 1754 | 8) == 0) { |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1755 | qos = ha->npiv_info[cnt].q_qos; |
| 1756 | break; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1757 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1758 | } |
| 1759 | if (qos) { |
| 1760 | ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0, |
| 1761 | qos); |
| 1762 | if (!ret) |
| 1763 | qla_printk(KERN_WARNING, ha, |
| 1764 | "Can't create request queue for vp_idx:%d\n", |
| 1765 | vha->vp_idx); |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 1766 | else { |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1767 | DEBUG2(qla_printk(KERN_INFO, ha, |
Anirban Chakraborty | 40859ae | 2009-06-03 09:55:16 -0700 | [diff] [blame] | 1768 | "Request Que:%d (QoS: %d) created for vp_idx:%d\n", |
| 1769 | ret, qos, vha->vp_idx)); |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 1770 | req = ha->req_q_map[ret]; |
| 1771 | } |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1772 | } |
| 1773 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1774 | vport_queue: |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 1775 | vha->req = req; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1776 | return 0; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1777 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1778 | vport_create_failed_2: |
| 1779 | qla24xx_disable_vp(vha); |
| 1780 | qla24xx_deallocate_vp_id(vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1781 | scsi_host_put(vha->host); |
| 1782 | return FC_VPORT_FAILED; |
| 1783 | } |
| 1784 | |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 1785 | static int |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1786 | qla24xx_vport_delete(struct fc_vport *fc_vport) |
| 1787 | { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1788 | scsi_qla_host_t *vha = fc_vport->dd_data; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1789 | fc_port_t *fcport, *tfcport; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1790 | struct qla_hw_data *ha = vha->hw; |
| 1791 | uint16_t id = vha->vp_idx; |
Andrew Vasquez | c9c5ced | 2008-07-24 08:31:49 -0700 | [diff] [blame] | 1792 | |
| 1793 | while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) || |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1794 | test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) |
Andrew Vasquez | c9c5ced | 2008-07-24 08:31:49 -0700 | [diff] [blame] | 1795 | msleep(1000); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1796 | |
| 1797 | qla24xx_disable_vp(vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1798 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1799 | fc_remove_host(vha->host); |
| 1800 | |
| 1801 | scsi_remove_host(vha->host); |
| 1802 | |
| 1803 | list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) { |
| 1804 | list_del(&fcport->list); |
| 1805 | kfree(fcport); |
| 1806 | fcport = NULL; |
| 1807 | } |
| 1808 | |
| 1809 | qla24xx_deallocate_vp_id(vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1810 | |
Andrew Vasquez | 0d6e61b | 2009-08-25 11:36:19 -0700 | [diff] [blame] | 1811 | mutex_lock(&ha->vport_lock); |
| 1812 | ha->cur_vport_count--; |
| 1813 | clear_bit(vha->vp_idx, ha->vp_idx_map); |
| 1814 | mutex_unlock(&ha->vport_lock); |
| 1815 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1816 | if (vha->timer_active) { |
| 1817 | qla2x00_vp_stop_timer(vha); |
| 1818 | DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p " |
| 1819 | "has stopped\n", |
| 1820 | vha->host_no, vha->vp_idx, vha)); |
| 1821 | } |
| 1822 | |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 1823 | if (vha->req->id && !ha->flags.cpu_affinity_enabled) { |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1824 | if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS) |
Anirban Chakraborty | cf5a163 | 2009-02-08 20:50:13 -0800 | [diff] [blame] | 1825 | qla_printk(KERN_WARNING, ha, |
| 1826 | "Queue delete failed.\n"); |
| 1827 | } |
| 1828 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1829 | scsi_host_put(vha->host); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1830 | qla_printk(KERN_INFO, ha, "vport %d deleted\n", id); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1831 | return 0; |
| 1832 | } |
| 1833 | |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 1834 | static int |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1835 | qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable) |
| 1836 | { |
| 1837 | scsi_qla_host_t *vha = fc_vport->dd_data; |
| 1838 | |
| 1839 | if (disable) |
| 1840 | qla24xx_disable_vp(vha); |
| 1841 | else |
| 1842 | qla24xx_enable_vp(vha); |
| 1843 | |
| 1844 | return 0; |
| 1845 | } |
| 1846 | |
Andrew Vasquez | 1c97a12 | 2005-04-21 16:13:36 -0400 | [diff] [blame] | 1847 | struct fc_function_template qla2xxx_transport_functions = { |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1848 | |
| 1849 | .show_host_node_name = 1, |
| 1850 | .show_host_port_name = 1, |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 1851 | .show_host_supported_classes = 1, |
Andrew Vasquez | 2ae2b37 | 2008-04-03 13:13:14 -0700 | [diff] [blame] | 1852 | .show_host_supported_speeds = 1, |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 1853 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1854 | .get_host_port_id = qla2x00_get_host_port_id, |
| 1855 | .show_host_port_id = 1, |
andrew.vasquez@qlogic.com | 0441401 | 2006-01-31 16:04:51 -0800 | [diff] [blame] | 1856 | .get_host_speed = qla2x00_get_host_speed, |
| 1857 | .show_host_speed = 1, |
andrew.vasquez@qlogic.com | 8d06762 | 2006-01-31 16:04:56 -0800 | [diff] [blame] | 1858 | .get_host_port_type = qla2x00_get_host_port_type, |
| 1859 | .show_host_port_type = 1, |
Andrew Vasquez | 1620f7c | 2006-10-02 12:00:44 -0700 | [diff] [blame] | 1860 | .get_host_symbolic_name = qla2x00_get_host_symbolic_name, |
| 1861 | .show_host_symbolic_name = 1, |
Andrew Vasquez | a740a3f | 2006-10-02 12:00:45 -0700 | [diff] [blame] | 1862 | .set_host_system_hostname = qla2x00_set_host_system_hostname, |
| 1863 | .show_host_system_hostname = 1, |
Andrew Vasquez | 90991c8 | 2006-10-02 12:00:46 -0700 | [diff] [blame] | 1864 | .get_host_fabric_name = qla2x00_get_host_fabric_name, |
| 1865 | .show_host_fabric_name = 1, |
Andrew Vasquez | 7047fcd | 2006-10-02 12:00:47 -0700 | [diff] [blame] | 1866 | .get_host_port_state = qla2x00_get_host_port_state, |
| 1867 | .show_host_port_state = 1, |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1868 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1869 | .dd_fcrport_size = sizeof(struct fc_port *), |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 1870 | .show_rport_supported_classes = 1, |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1871 | |
| 1872 | .get_starget_node_name = qla2x00_get_starget_node_name, |
| 1873 | .show_starget_node_name = 1, |
| 1874 | .get_starget_port_name = qla2x00_get_starget_port_name, |
| 1875 | .show_starget_port_name = 1, |
| 1876 | .get_starget_port_id = qla2x00_get_starget_port_id, |
| 1877 | .show_starget_port_id = 1, |
| 1878 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1879 | .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo, |
| 1880 | .show_rport_dev_loss_tmo = 1, |
| 1881 | |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 1882 | .issue_fc_host_lip = qla2x00_issue_lip, |
Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 1883 | .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk, |
| 1884 | .terminate_rport_io = qla2x00_terminate_rport_io, |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 1885 | .get_fc_host_stats = qla2x00_get_fc_host_stats, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1886 | |
| 1887 | .vport_create = qla24xx_vport_create, |
| 1888 | .vport_disable = qla24xx_vport_disable, |
| 1889 | .vport_delete = qla24xx_vport_delete, |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1890 | .bsg_request = qla24xx_bsg_request, |
| 1891 | .bsg_timeout = qla24xx_bsg_timeout, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1892 | }; |
| 1893 | |
| 1894 | struct fc_function_template qla2xxx_transport_vport_functions = { |
| 1895 | |
| 1896 | .show_host_node_name = 1, |
| 1897 | .show_host_port_name = 1, |
| 1898 | .show_host_supported_classes = 1, |
| 1899 | |
| 1900 | .get_host_port_id = qla2x00_get_host_port_id, |
| 1901 | .show_host_port_id = 1, |
| 1902 | .get_host_speed = qla2x00_get_host_speed, |
| 1903 | .show_host_speed = 1, |
| 1904 | .get_host_port_type = qla2x00_get_host_port_type, |
| 1905 | .show_host_port_type = 1, |
| 1906 | .get_host_symbolic_name = qla2x00_get_host_symbolic_name, |
| 1907 | .show_host_symbolic_name = 1, |
| 1908 | .set_host_system_hostname = qla2x00_set_host_system_hostname, |
| 1909 | .show_host_system_hostname = 1, |
| 1910 | .get_host_fabric_name = qla2x00_get_host_fabric_name, |
| 1911 | .show_host_fabric_name = 1, |
| 1912 | .get_host_port_state = qla2x00_get_host_port_state, |
| 1913 | .show_host_port_state = 1, |
| 1914 | |
| 1915 | .dd_fcrport_size = sizeof(struct fc_port *), |
| 1916 | .show_rport_supported_classes = 1, |
| 1917 | |
| 1918 | .get_starget_node_name = qla2x00_get_starget_node_name, |
| 1919 | .show_starget_node_name = 1, |
| 1920 | .get_starget_port_name = qla2x00_get_starget_port_name, |
| 1921 | .show_starget_port_name = 1, |
| 1922 | .get_starget_port_id = qla2x00_get_starget_port_id, |
| 1923 | .show_starget_port_id = 1, |
| 1924 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1925 | .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo, |
| 1926 | .show_rport_dev_loss_tmo = 1, |
| 1927 | |
| 1928 | .issue_fc_host_lip = qla2x00_issue_lip, |
Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 1929 | .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk, |
| 1930 | .terminate_rport_io = qla2x00_terminate_rport_io, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1931 | .get_fc_host_stats = qla2x00_get_fc_host_stats, |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1932 | .bsg_request = qla24xx_bsg_request, |
| 1933 | .bsg_timeout = qla24xx_bsg_timeout, |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1934 | }; |
| 1935 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1936 | void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1937 | qla2x00_init_host_attr(scsi_qla_host_t *vha) |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1938 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1939 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 2ae2b37 | 2008-04-03 13:13:14 -0700 | [diff] [blame] | 1940 | u32 speed = FC_PORTSPEED_UNKNOWN; |
| 1941 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1942 | fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name); |
| 1943 | fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name); |
| 1944 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 1945 | fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports; |
| 1946 | fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count; |
Andrew Vasquez | 2ae2b37 | 2008-04-03 13:13:14 -0700 | [diff] [blame] | 1947 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1948 | if (IS_QLA8XXX_TYPE(ha)) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1949 | speed = FC_PORTSPEED_10GBIT; |
| 1950 | else if (IS_QLA25XX(ha)) |
Andrew Vasquez | 2ae2b37 | 2008-04-03 13:13:14 -0700 | [diff] [blame] | 1951 | speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT | |
| 1952 | FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1953 | else if (IS_QLA24XX_TYPE(ha)) |
Andrew Vasquez | 2ae2b37 | 2008-04-03 13:13:14 -0700 | [diff] [blame] | 1954 | speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT | |
| 1955 | FC_PORTSPEED_1GBIT; |
| 1956 | else if (IS_QLA23XX(ha)) |
| 1957 | speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT; |
| 1958 | else |
| 1959 | speed = FC_PORTSPEED_1GBIT; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1960 | fc_host_supported_speeds(vha->host) = speed; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1961 | } |