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