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