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