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