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