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