| 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 |
| 3 | * Copyright (c) 2003-2005 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 | |
| 7aaef27 | 2005-04-17 16:32:42 -0500 | [diff] [blame] | 9 | #include <linux/vmalloc.h> |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 10 | |
| 11 | /* SYSFS attributes --------------------------------------------------------- */ |
| 12 | |
| 13 | static ssize_t |
| 14 | qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf, loff_t off, |
| 15 | size_t count) |
| 16 | { |
| 17 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 18 | struct device, kobj))); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 19 | char *rbuf = (char *)ha->fw_dump; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 20 | |
| 21 | if (ha->fw_dump_reading == 0) |
| 22 | return 0; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 23 | if (off > ha->fw_dump_len) |
| 24 | return 0; |
| 25 | if (off + count > ha->fw_dump_len) |
| 26 | count = ha->fw_dump_len - off; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 27 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 28 | memcpy(buf, &rbuf[off], count); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 29 | |
| 30 | return (count); |
| 31 | } |
| 32 | |
| 33 | static ssize_t |
| 34 | qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf, loff_t off, |
| 35 | size_t count) |
| 36 | { |
| 37 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 38 | struct device, kobj))); |
| 39 | int reading; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 40 | |
| 41 | if (off != 0) |
| 42 | return (0); |
| 43 | |
| 44 | reading = simple_strtol(buf, NULL, 10); |
| 45 | switch (reading) { |
| 46 | case 0: |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 47 | if (!ha->fw_dump_reading) |
| 48 | break; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 49 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 50 | qla_printk(KERN_INFO, ha, |
| 51 | "Firmware dump cleared on (%ld).\n", ha->host_no); |
| 52 | |
| 53 | ha->fw_dump_reading = 0; |
| 54 | ha->fw_dumped = 0; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 55 | break; |
| 56 | case 1: |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 57 | if (ha->fw_dumped && !ha->fw_dump_reading) { |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 58 | ha->fw_dump_reading = 1; |
| 59 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 60 | qla_printk(KERN_INFO, ha, |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 61 | "Raw firmware dump ready for read on (%ld).\n", |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 62 | ha->host_no); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 63 | } |
| 64 | break; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 65 | case 2: |
| 66 | qla2x00_alloc_fw_dump(ha); |
| 67 | break; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 68 | } |
| 69 | return (count); |
| 70 | } |
| 71 | |
| 72 | static struct bin_attribute sysfs_fw_dump_attr = { |
| 73 | .attr = { |
| 74 | .name = "fw_dump", |
| 75 | .mode = S_IRUSR | S_IWUSR, |
| 76 | .owner = THIS_MODULE, |
| 77 | }, |
| 78 | .size = 0, |
| 79 | .read = qla2x00_sysfs_read_fw_dump, |
| 80 | .write = qla2x00_sysfs_write_fw_dump, |
| 81 | }; |
| 82 | |
| 83 | static ssize_t |
| 84 | qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf, loff_t off, |
| 85 | size_t count) |
| 86 | { |
| 87 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 88 | struct device, kobj))); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 89 | unsigned long flags; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 90 | |
andrew.vasquez@qlogic.com | 1b3f636 | 2006-01-31 16:05:12 -0800 | [diff] [blame] | 91 | if (!capable(CAP_SYS_ADMIN) || off != 0) |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 92 | return 0; |
| 93 | |
| 94 | /* Read NVRAM. */ |
| 95 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 96 | ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->nvram_base, |
| 97 | ha->nvram_size); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 98 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 99 | |
andrew.vasquez@qlogic.com | 1b3f636 | 2006-01-31 16:05:12 -0800 | [diff] [blame] | 100 | return ha->nvram_size; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static ssize_t |
| 104 | qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, loff_t off, |
| 105 | size_t count) |
| 106 | { |
| 107 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 108 | struct device, kobj))); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 109 | unsigned long flags; |
| 110 | uint16_t cnt; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 111 | |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 112 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size) |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 113 | return 0; |
| 114 | |
| 115 | /* Checksum NVRAM. */ |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 116 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 117 | uint32_t *iter; |
| 118 | uint32_t chksum; |
| 119 | |
| 120 | iter = (uint32_t *)buf; |
| 121 | chksum = 0; |
| 122 | for (cnt = 0; cnt < ((count >> 2) - 1); cnt++) |
| 123 | chksum += le32_to_cpu(*iter++); |
| 124 | chksum = ~chksum + 1; |
| 125 | *iter = cpu_to_le32(chksum); |
| 126 | } else { |
| 127 | uint8_t *iter; |
| 128 | uint8_t chksum; |
| 129 | |
| 130 | iter = (uint8_t *)buf; |
| 131 | chksum = 0; |
| 132 | for (cnt = 0; cnt < count - 1; cnt++) |
| 133 | chksum += *iter++; |
| 134 | chksum = ~chksum + 1; |
| 135 | *iter = chksum; |
| 136 | } |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 137 | |
| 138 | /* Write NVRAM. */ |
| 139 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 140 | ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 141 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 142 | |
| 143 | return (count); |
| 144 | } |
| 145 | |
| 146 | static struct bin_attribute sysfs_nvram_attr = { |
| 147 | .attr = { |
| 148 | .name = "nvram", |
| 149 | .mode = S_IRUSR | S_IWUSR, |
| 150 | .owner = THIS_MODULE, |
| 151 | }, |
andrew.vasquez@qlogic.com | 1b3f636 | 2006-01-31 16:05:12 -0800 | [diff] [blame] | 152 | .size = 512, |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 153 | .read = qla2x00_sysfs_read_nvram, |
| 154 | .write = qla2x00_sysfs_write_nvram, |
| 155 | }; |
| 156 | |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 157 | static ssize_t |
| 158 | qla2x00_sysfs_read_optrom(struct kobject *kobj, char *buf, loff_t off, |
| 159 | size_t count) |
| 160 | { |
| 161 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 162 | struct device, kobj))); |
| 163 | |
| 164 | if (ha->optrom_state != QLA_SREADING) |
| 165 | return 0; |
| 166 | if (off > ha->optrom_size) |
| 167 | return 0; |
| 168 | if (off + count > ha->optrom_size) |
| 169 | count = ha->optrom_size - off; |
| 170 | |
| 171 | memcpy(buf, &ha->optrom_buffer[off], count); |
| 172 | |
| 173 | return count; |
| 174 | } |
| 175 | |
| 176 | static ssize_t |
| 177 | qla2x00_sysfs_write_optrom(struct kobject *kobj, char *buf, loff_t off, |
| 178 | size_t count) |
| 179 | { |
| 180 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 181 | struct device, kobj))); |
| 182 | |
| 183 | if (ha->optrom_state != QLA_SWRITING) |
| 184 | return -EINVAL; |
| 185 | if (off > ha->optrom_size) |
| 186 | return -ERANGE; |
| 187 | if (off + count > ha->optrom_size) |
| 188 | count = ha->optrom_size - off; |
| 189 | |
| 190 | memcpy(&ha->optrom_buffer[off], buf, count); |
| 191 | |
| 192 | return count; |
| 193 | } |
| 194 | |
| 195 | static struct bin_attribute sysfs_optrom_attr = { |
| 196 | .attr = { |
| 197 | .name = "optrom", |
| 198 | .mode = S_IRUSR | S_IWUSR, |
| 199 | .owner = THIS_MODULE, |
| 200 | }, |
| 201 | .size = OPTROM_SIZE_24XX, |
| 202 | .read = qla2x00_sysfs_read_optrom, |
| 203 | .write = qla2x00_sysfs_write_optrom, |
| 204 | }; |
| 205 | |
| 206 | static ssize_t |
| 207 | qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj, char *buf, loff_t off, |
| 208 | size_t count) |
| 209 | { |
| 210 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 211 | struct device, kobj))); |
| 212 | int val; |
| 213 | |
| 214 | if (off) |
| 215 | return 0; |
| 216 | |
| 217 | if (sscanf(buf, "%d", &val) != 1) |
| 218 | return -EINVAL; |
| 219 | |
| 220 | switch (val) { |
| 221 | case 0: |
| 222 | if (ha->optrom_state != QLA_SREADING && |
| 223 | ha->optrom_state != QLA_SWRITING) |
| 224 | break; |
| 225 | |
| 226 | ha->optrom_state = QLA_SWAITING; |
| 227 | vfree(ha->optrom_buffer); |
| 228 | ha->optrom_buffer = NULL; |
| 229 | break; |
| 230 | case 1: |
| 231 | if (ha->optrom_state != QLA_SWAITING) |
| 232 | break; |
| 233 | |
| 234 | ha->optrom_state = QLA_SREADING; |
| 235 | ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size); |
| 236 | if (ha->optrom_buffer == NULL) { |
| 237 | qla_printk(KERN_WARNING, ha, |
| 238 | "Unable to allocate memory for optrom retrieval " |
| 239 | "(%x).\n", ha->optrom_size); |
| 240 | |
| 241 | ha->optrom_state = QLA_SWAITING; |
| 242 | return count; |
| 243 | } |
| 244 | |
| 245 | memset(ha->optrom_buffer, 0, ha->optrom_size); |
| 246 | ha->isp_ops.read_optrom(ha, ha->optrom_buffer, 0, |
| 247 | ha->optrom_size); |
| 248 | break; |
| 249 | case 2: |
| 250 | if (ha->optrom_state != QLA_SWAITING) |
| 251 | break; |
| 252 | |
| 253 | ha->optrom_state = QLA_SWRITING; |
| 254 | ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size); |
| 255 | if (ha->optrom_buffer == NULL) { |
| 256 | qla_printk(KERN_WARNING, ha, |
| 257 | "Unable to allocate memory for optrom update " |
| 258 | "(%x).\n", ha->optrom_size); |
| 259 | |
| 260 | ha->optrom_state = QLA_SWAITING; |
| 261 | return count; |
| 262 | } |
| 263 | memset(ha->optrom_buffer, 0, ha->optrom_size); |
| 264 | break; |
| 265 | case 3: |
| 266 | if (ha->optrom_state != QLA_SWRITING) |
| 267 | break; |
| 268 | |
| 269 | ha->isp_ops.write_optrom(ha, ha->optrom_buffer, 0, |
| 270 | ha->optrom_size); |
| 271 | break; |
| 272 | } |
| 273 | return count; |
| 274 | } |
| 275 | |
| 276 | static struct bin_attribute sysfs_optrom_ctl_attr = { |
| 277 | .attr = { |
| 278 | .name = "optrom_ctl", |
| 279 | .mode = S_IWUSR, |
| 280 | .owner = THIS_MODULE, |
| 281 | }, |
| 282 | .size = 0, |
| 283 | .write = qla2x00_sysfs_write_optrom_ctl, |
| 284 | }; |
| 285 | |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 286 | static ssize_t |
| 287 | qla2x00_sysfs_read_vpd(struct kobject *kobj, char *buf, loff_t off, |
| 288 | size_t count) |
| 289 | { |
| 290 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 291 | struct device, kobj))); |
| 292 | unsigned long flags; |
| 293 | |
| 294 | if (!capable(CAP_SYS_ADMIN) || off != 0) |
| 295 | return 0; |
| 296 | |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 297 | /* Read NVRAM. */ |
| 298 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 299 | ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->vpd_base, ha->vpd_size); |
| 300 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 301 | |
| 302 | return ha->vpd_size; |
| 303 | } |
| 304 | |
| 305 | static ssize_t |
| 306 | qla2x00_sysfs_write_vpd(struct kobject *kobj, char *buf, loff_t off, |
| 307 | size_t count) |
| 308 | { |
| 309 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 310 | struct device, kobj))); |
| 311 | unsigned long flags; |
| 312 | |
| 313 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size) |
| 314 | return 0; |
| 315 | |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 316 | /* Write NVRAM. */ |
| 317 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 318 | ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count); |
| 319 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 320 | |
| 321 | return count; |
| 322 | } |
| 323 | |
| 324 | static struct bin_attribute sysfs_vpd_attr = { |
| 325 | .attr = { |
| 326 | .name = "vpd", |
| 327 | .mode = S_IRUSR | S_IWUSR, |
| 328 | .owner = THIS_MODULE, |
| 329 | }, |
| 330 | .size = 0, |
| 331 | .read = qla2x00_sysfs_read_vpd, |
| 332 | .write = qla2x00_sysfs_write_vpd, |
| 333 | }; |
| 334 | |
Andrew Vasquez | 88729e5 | 2006-06-23 16:10:50 -0700 | [diff] [blame] | 335 | static ssize_t |
| 336 | qla2x00_sysfs_read_sfp(struct kobject *kobj, char *buf, loff_t off, |
| 337 | size_t count) |
| 338 | { |
| 339 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 340 | struct device, kobj))); |
| 341 | uint16_t iter, addr, offset; |
| 342 | int rval; |
| 343 | |
| 344 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2) |
| 345 | return 0; |
| 346 | |
| 347 | addr = 0xa0; |
| 348 | for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE; |
| 349 | iter++, offset += SFP_BLOCK_SIZE) { |
| 350 | if (iter == 4) { |
| 351 | /* Skip to next device address. */ |
| 352 | addr = 0xa2; |
| 353 | offset = 0; |
| 354 | } |
| 355 | |
| 356 | rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset, |
| 357 | SFP_BLOCK_SIZE); |
| 358 | if (rval != QLA_SUCCESS) { |
| 359 | qla_printk(KERN_WARNING, ha, |
| 360 | "Unable to read SFP data (%x/%x/%x).\n", rval, |
| 361 | addr, offset); |
| 362 | count = 0; |
| 363 | break; |
| 364 | } |
| 365 | memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE); |
| 366 | buf += SFP_BLOCK_SIZE; |
| 367 | } |
| 368 | |
| 369 | return count; |
| 370 | } |
| 371 | |
| 372 | static struct bin_attribute sysfs_sfp_attr = { |
| 373 | .attr = { |
| 374 | .name = "sfp", |
| 375 | .mode = S_IRUSR | S_IWUSR, |
| 376 | .owner = THIS_MODULE, |
| 377 | }, |
| 378 | .size = SFP_DEV_SIZE * 2, |
| 379 | .read = qla2x00_sysfs_read_sfp, |
| 380 | }; |
| 381 | |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 382 | static struct sysfs_entry { |
| 383 | char *name; |
| 384 | struct bin_attribute *attr; |
| 385 | int is4GBp_only; |
| 386 | } bin_file_entries[] = { |
| 387 | { "fw_dump", &sysfs_fw_dump_attr, }, |
| 388 | { "nvram", &sysfs_nvram_attr, }, |
| 389 | { "optrom", &sysfs_optrom_attr, }, |
| 390 | { "optrom_ctl", &sysfs_optrom_ctl_attr, }, |
| 391 | { "vpd", &sysfs_vpd_attr, 1 }, |
| 392 | { "sfp", &sysfs_sfp_attr, 1 }, |
Randy Dunlap | 46ddab7 | 2006-11-27 09:35:42 -0800 | [diff] [blame] | 393 | { NULL }, |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 394 | }; |
| 395 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 396 | void |
| 397 | qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha) |
| 398 | { |
| 399 | struct Scsi_Host *host = ha->host; |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 400 | struct sysfs_entry *iter; |
| 401 | int ret; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 402 | |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 403 | for (iter = bin_file_entries; iter->name; iter++) { |
| 404 | if (iter->is4GBp_only && (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))) |
| 405 | continue; |
| 406 | |
| 407 | ret = sysfs_create_bin_file(&host->shost_gendev.kobj, |
| 408 | iter->attr); |
| 409 | if (ret) |
| 410 | qla_printk(KERN_INFO, ha, |
| 411 | "Unable to create sysfs %s binary attribute " |
| 412 | "(%d).\n", iter->name, ret); |
Andrew Vasquez | 7914d00 | 2006-06-23 16:10:55 -0700 | [diff] [blame] | 413 | } |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | void |
| 417 | qla2x00_free_sysfs_attr(scsi_qla_host_t *ha) |
| 418 | { |
| 419 | struct Scsi_Host *host = ha->host; |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 420 | struct sysfs_entry *iter; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 421 | |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 422 | for (iter = bin_file_entries; iter->name; iter++) { |
| 423 | if (iter->is4GBp_only && (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))) |
| 424 | continue; |
| 425 | |
Andrew Vasquez | 7914d00 | 2006-06-23 16:10:55 -0700 | [diff] [blame] | 426 | sysfs_remove_bin_file(&host->shost_gendev.kobj, |
Andrew Vasquez | f1663ad | 2006-10-13 09:33:37 -0700 | [diff] [blame] | 427 | iter->attr); |
Andrew Vasquez | 7914d00 | 2006-06-23 16:10:55 -0700 | [diff] [blame] | 428 | } |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 429 | |
| 430 | if (ha->beacon_blink_led == 1) |
| 431 | ha->isp_ops.beacon_off(ha); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 432 | } |
| 433 | |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 434 | /* Scsi_Host attributes. */ |
| 435 | |
| 436 | static ssize_t |
| 437 | qla2x00_drvr_version_show(struct class_device *cdev, char *buf) |
| 438 | { |
| 439 | return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str); |
| 440 | } |
| 441 | |
| 442 | static ssize_t |
| 443 | qla2x00_fw_version_show(struct class_device *cdev, char *buf) |
| 444 | { |
| 445 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 446 | char fw_str[30]; |
| 447 | |
| 448 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 449 | ha->isp_ops.fw_version_str(ha, fw_str)); |
| 450 | } |
| 451 | |
| 452 | static ssize_t |
| 453 | qla2x00_serial_num_show(struct class_device *cdev, char *buf) |
| 454 | { |
| 455 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 456 | uint32_t sn; |
| 457 | |
| 458 | sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1; |
| 459 | return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000, |
| 460 | sn % 100000); |
| 461 | } |
| 462 | |
| 463 | static ssize_t |
| 464 | qla2x00_isp_name_show(struct class_device *cdev, char *buf) |
| 465 | { |
| 466 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 467 | return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device); |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | static ssize_t |
| 471 | qla2x00_isp_id_show(struct class_device *cdev, char *buf) |
| 472 | { |
| 473 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 474 | return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n", |
| 475 | ha->product_id[0], ha->product_id[1], ha->product_id[2], |
| 476 | ha->product_id[3]); |
| 477 | } |
| 478 | |
| 479 | static ssize_t |
| 480 | qla2x00_model_name_show(struct class_device *cdev, char *buf) |
| 481 | { |
| 482 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 483 | return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number); |
| 484 | } |
| 485 | |
| 486 | static ssize_t |
| 487 | qla2x00_model_desc_show(struct class_device *cdev, char *buf) |
| 488 | { |
| 489 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 490 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 491 | ha->model_desc ? ha->model_desc: ""); |
| 492 | } |
| 493 | |
| 494 | static ssize_t |
| 495 | qla2x00_pci_info_show(struct class_device *cdev, char *buf) |
| 496 | { |
| 497 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 498 | char pci_info[30]; |
| 499 | |
| 500 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 501 | ha->isp_ops.pci_info_str(ha, pci_info)); |
| 502 | } |
| 503 | |
| 504 | static ssize_t |
| 505 | qla2x00_state_show(struct class_device *cdev, char *buf) |
| 506 | { |
| 507 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 508 | int len = 0; |
| 509 | |
| 510 | if (atomic_read(&ha->loop_state) == LOOP_DOWN || |
| 511 | atomic_read(&ha->loop_state) == LOOP_DEAD) |
| 512 | len = snprintf(buf, PAGE_SIZE, "Link Down\n"); |
| 513 | else if (atomic_read(&ha->loop_state) != LOOP_READY || |
| 514 | test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) || |
| 515 | test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) |
| 516 | len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n"); |
| 517 | else { |
| 518 | len = snprintf(buf, PAGE_SIZE, "Link Up - "); |
| 519 | |
| 520 | switch (ha->current_topology) { |
| 521 | case ISP_CFG_NL: |
| 522 | len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n"); |
| 523 | break; |
| 524 | case ISP_CFG_FL: |
| 525 | len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n"); |
| 526 | break; |
| 527 | case ISP_CFG_N: |
| 528 | len += snprintf(buf + len, PAGE_SIZE-len, |
| 529 | "N_Port to N_Port\n"); |
| 530 | break; |
| 531 | case ISP_CFG_F: |
| 532 | len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n"); |
| 533 | break; |
| 534 | default: |
| 535 | len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n"); |
| 536 | break; |
| 537 | } |
| 538 | } |
| 539 | return len; |
| 540 | } |
| 541 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 542 | static ssize_t |
| 543 | qla2x00_zio_show(struct class_device *cdev, char *buf) |
| 544 | { |
| 545 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 546 | int len = 0; |
| 547 | |
| 548 | switch (ha->zio_mode) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 549 | case QLA_ZIO_MODE_6: |
| 550 | len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n"); |
| 551 | break; |
| 552 | case QLA_ZIO_DISABLED: |
| 553 | len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n"); |
| 554 | break; |
| 555 | } |
| 556 | return len; |
| 557 | } |
| 558 | |
| 559 | static ssize_t |
| 560 | qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count) |
| 561 | { |
| 562 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 563 | int val = 0; |
| 564 | uint16_t zio_mode; |
| 565 | |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 566 | if (!IS_ZIO_SUPPORTED(ha)) |
| 567 | return -ENOTSUPP; |
| 568 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 569 | if (sscanf(buf, "%d", &val) != 1) |
| 570 | return -EINVAL; |
| 571 | |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 572 | if (val) |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 573 | zio_mode = QLA_ZIO_MODE_6; |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 574 | else |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 575 | zio_mode = QLA_ZIO_DISABLED; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 576 | |
| 577 | /* Update per-hba values and queue a reset. */ |
| 578 | if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) { |
| 579 | ha->zio_mode = zio_mode; |
| 580 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 581 | } |
| 582 | return strlen(buf); |
| 583 | } |
| 584 | |
| 585 | static ssize_t |
| 586 | qla2x00_zio_timer_show(struct class_device *cdev, char *buf) |
| 587 | { |
| 588 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 589 | |
| 590 | return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100); |
| 591 | } |
| 592 | |
| 593 | static ssize_t |
| 594 | qla2x00_zio_timer_store(struct class_device *cdev, const char *buf, |
| 595 | size_t count) |
| 596 | { |
| 597 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 598 | int val = 0; |
| 599 | uint16_t zio_timer; |
| 600 | |
| 601 | if (sscanf(buf, "%d", &val) != 1) |
| 602 | return -EINVAL; |
| 603 | if (val > 25500 || val < 100) |
| 604 | return -ERANGE; |
| 605 | |
| 606 | zio_timer = (uint16_t)(val / 100); |
| 607 | ha->zio_timer = zio_timer; |
| 608 | |
| 609 | return strlen(buf); |
| 610 | } |
| 611 | |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 612 | static ssize_t |
| 613 | qla2x00_beacon_show(struct class_device *cdev, char *buf) |
| 614 | { |
| 615 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 616 | int len = 0; |
| 617 | |
| 618 | if (ha->beacon_blink_led) |
| 619 | len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n"); |
| 620 | else |
| 621 | len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n"); |
| 622 | return len; |
| 623 | } |
| 624 | |
| 625 | static ssize_t |
| 626 | qla2x00_beacon_store(struct class_device *cdev, const char *buf, |
| 627 | size_t count) |
| 628 | { |
| 629 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 630 | int val = 0; |
| 631 | int rval; |
| 632 | |
| 633 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 634 | return -EPERM; |
| 635 | |
| 636 | if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) { |
| 637 | qla_printk(KERN_WARNING, ha, |
| 638 | "Abort ISP active -- ignoring beacon request.\n"); |
| 639 | return -EBUSY; |
| 640 | } |
| 641 | |
| 642 | if (sscanf(buf, "%d", &val) != 1) |
| 643 | return -EINVAL; |
| 644 | |
| 645 | if (val) |
| 646 | rval = ha->isp_ops.beacon_on(ha); |
| 647 | else |
| 648 | rval = ha->isp_ops.beacon_off(ha); |
| 649 | |
| 650 | if (rval != QLA_SUCCESS) |
| 651 | count = 0; |
| 652 | |
| 653 | return count; |
| 654 | } |
| 655 | |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 656 | static ssize_t |
| 657 | qla2x00_optrom_bios_version_show(struct class_device *cdev, char *buf) |
| 658 | { |
| 659 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 660 | |
| 661 | return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1], |
| 662 | ha->bios_revision[0]); |
| 663 | } |
| 664 | |
| 665 | static ssize_t |
| 666 | qla2x00_optrom_efi_version_show(struct class_device *cdev, char *buf) |
| 667 | { |
| 668 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 669 | |
| 670 | return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1], |
| 671 | ha->efi_revision[0]); |
| 672 | } |
| 673 | |
| 674 | static ssize_t |
| 675 | qla2x00_optrom_fcode_version_show(struct class_device *cdev, char *buf) |
| 676 | { |
| 677 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 678 | |
| 679 | return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1], |
| 680 | ha->fcode_revision[0]); |
| 681 | } |
| 682 | |
| 683 | static ssize_t |
| 684 | qla2x00_optrom_fw_version_show(struct class_device *cdev, char *buf) |
| 685 | { |
| 686 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 687 | |
| 688 | return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n", |
| 689 | ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2], |
| 690 | ha->fw_revision[3]); |
| 691 | } |
| 692 | |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 693 | static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, |
| 694 | NULL); |
| 695 | static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL); |
| 696 | static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL); |
| 697 | static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL); |
| 698 | static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL); |
| 699 | static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL); |
| 700 | static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL); |
| 701 | static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL); |
| 702 | static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL); |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 703 | static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, |
| 704 | qla2x00_zio_store); |
| 705 | static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show, |
| 706 | qla2x00_zio_timer_store); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 707 | static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show, |
| 708 | qla2x00_beacon_store); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 709 | static CLASS_DEVICE_ATTR(optrom_bios_version, S_IRUGO, |
| 710 | qla2x00_optrom_bios_version_show, NULL); |
| 711 | static CLASS_DEVICE_ATTR(optrom_efi_version, S_IRUGO, |
| 712 | qla2x00_optrom_efi_version_show, NULL); |
| 713 | static CLASS_DEVICE_ATTR(optrom_fcode_version, S_IRUGO, |
| 714 | qla2x00_optrom_fcode_version_show, NULL); |
| 715 | static CLASS_DEVICE_ATTR(optrom_fw_version, S_IRUGO, |
| 716 | qla2x00_optrom_fw_version_show, NULL); |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 717 | |
| 718 | struct class_device_attribute *qla2x00_host_attrs[] = { |
| 719 | &class_device_attr_driver_version, |
| 720 | &class_device_attr_fw_version, |
| 721 | &class_device_attr_serial_num, |
| 722 | &class_device_attr_isp_name, |
| 723 | &class_device_attr_isp_id, |
| 724 | &class_device_attr_model_name, |
| 725 | &class_device_attr_model_desc, |
| 726 | &class_device_attr_pci_info, |
| 727 | &class_device_attr_state, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 728 | &class_device_attr_zio, |
| 729 | &class_device_attr_zio_timer, |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 730 | &class_device_attr_beacon, |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 731 | &class_device_attr_optrom_bios_version, |
| 732 | &class_device_attr_optrom_efi_version, |
| 733 | &class_device_attr_optrom_fcode_version, |
| 734 | &class_device_attr_optrom_fw_version, |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 735 | NULL, |
| 736 | }; |
| 737 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 738 | /* Host attributes. */ |
| 739 | |
| 740 | static void |
| 741 | qla2x00_get_host_port_id(struct Scsi_Host *shost) |
| 742 | { |
| 743 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 744 | |
| 745 | fc_host_port_id(shost) = ha->d_id.b.domain << 16 | |
| 746 | ha->d_id.b.area << 8 | ha->d_id.b.al_pa; |
| 747 | } |
| 748 | |
| 749 | static void |
andrew.vasquez@qlogic.com | 0441401 | 2006-01-31 16:04:51 -0800 | [diff] [blame] | 750 | qla2x00_get_host_speed(struct Scsi_Host *shost) |
| 751 | { |
| 752 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 753 | uint32_t speed = 0; |
| 754 | |
| 755 | switch (ha->link_data_rate) { |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 756 | case PORT_SPEED_1GB: |
andrew.vasquez@qlogic.com | 0441401 | 2006-01-31 16:04:51 -0800 | [diff] [blame] | 757 | speed = 1; |
| 758 | break; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 759 | case PORT_SPEED_2GB: |
andrew.vasquez@qlogic.com | 0441401 | 2006-01-31 16:04:51 -0800 | [diff] [blame] | 760 | speed = 2; |
| 761 | break; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 762 | case PORT_SPEED_4GB: |
andrew.vasquez@qlogic.com | 0441401 | 2006-01-31 16:04:51 -0800 | [diff] [blame] | 763 | speed = 4; |
| 764 | break; |
| 765 | } |
| 766 | fc_host_speed(shost) = speed; |
| 767 | } |
| 768 | |
| 769 | static void |
andrew.vasquez@qlogic.com | 8d06762 | 2006-01-31 16:04:56 -0800 | [diff] [blame] | 770 | qla2x00_get_host_port_type(struct Scsi_Host *shost) |
| 771 | { |
| 772 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 773 | uint32_t port_type = FC_PORTTYPE_UNKNOWN; |
| 774 | |
| 775 | switch (ha->current_topology) { |
| 776 | case ISP_CFG_NL: |
| 777 | port_type = FC_PORTTYPE_LPORT; |
| 778 | break; |
| 779 | case ISP_CFG_FL: |
| 780 | port_type = FC_PORTTYPE_NLPORT; |
| 781 | break; |
| 782 | case ISP_CFG_N: |
| 783 | port_type = FC_PORTTYPE_PTP; |
| 784 | break; |
| 785 | case ISP_CFG_F: |
| 786 | port_type = FC_PORTTYPE_NPORT; |
| 787 | break; |
| 788 | } |
| 789 | fc_host_port_type(shost) = port_type; |
| 790 | } |
| 791 | |
| 792 | static void |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 793 | qla2x00_get_starget_node_name(struct scsi_target *starget) |
| 794 | { |
| 795 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); |
| 796 | scsi_qla_host_t *ha = to_qla_host(host); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 797 | fc_port_t *fcport; |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 798 | u64 node_name = 0; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 799 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 800 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 801 | if (starget->id == fcport->os_target_id) { |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 802 | node_name = wwn_to_u64(fcport->node_name); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 803 | break; |
| 804 | } |
| 805 | } |
| 806 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 807 | fc_starget_node_name(starget) = node_name; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | static void |
| 811 | qla2x00_get_starget_port_name(struct scsi_target *starget) |
| 812 | { |
| 813 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); |
| 814 | scsi_qla_host_t *ha = to_qla_host(host); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 815 | fc_port_t *fcport; |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 816 | u64 port_name = 0; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 817 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 818 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 819 | if (starget->id == fcport->os_target_id) { |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 820 | port_name = wwn_to_u64(fcport->port_name); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 821 | break; |
| 822 | } |
| 823 | } |
| 824 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 825 | fc_starget_port_name(starget) = port_name; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | static void |
| 829 | qla2x00_get_starget_port_id(struct scsi_target *starget) |
| 830 | { |
| 831 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); |
| 832 | scsi_qla_host_t *ha = to_qla_host(host); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 833 | fc_port_t *fcport; |
| 834 | uint32_t port_id = ~0U; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 835 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 836 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 837 | if (starget->id == fcport->os_target_id) { |
| 838 | port_id = fcport->d_id.b.domain << 16 | |
| 839 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 840 | break; |
| 841 | } |
| 842 | } |
| 843 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 844 | fc_starget_port_id(starget) = port_id; |
| 845 | } |
| 846 | |
| 847 | static void |
| 848 | qla2x00_get_rport_loss_tmo(struct fc_rport *rport) |
| 849 | { |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 850 | struct Scsi_Host *host = rport_to_shost(rport); |
| 851 | scsi_qla_host_t *ha = to_qla_host(host); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 852 | |
| 853 | rport->dev_loss_tmo = ha->port_down_retry_count + 5; |
| 854 | } |
| 855 | |
| 856 | static void |
| 857 | qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) |
| 858 | { |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 859 | struct Scsi_Host *host = rport_to_shost(rport); |
| 860 | scsi_qla_host_t *ha = to_qla_host(host); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 861 | |
| 862 | if (timeout) |
| 863 | ha->port_down_retry_count = timeout; |
| 864 | else |
| 865 | ha->port_down_retry_count = 1; |
| 866 | |
| 867 | rport->dev_loss_tmo = ha->port_down_retry_count + 5; |
| 868 | } |
| 869 | |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 870 | static int |
| 871 | qla2x00_issue_lip(struct Scsi_Host *shost) |
| 872 | { |
| 873 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 874 | |
| 875 | set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags); |
| 876 | return 0; |
| 877 | } |
| 878 | |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 879 | static struct fc_host_statistics * |
| 880 | qla2x00_get_fc_host_stats(struct Scsi_Host *shost) |
| 881 | { |
| 882 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 883 | int rval; |
| 884 | uint16_t mb_stat[1]; |
| 885 | link_stat_t stat_buf; |
| 886 | struct fc_host_statistics *pfc_host_stat; |
| 887 | |
Andrew Vasquez | 178779a | 2007-01-29 10:22:25 -0800 | [diff] [blame^] | 888 | rval = QLA_FUNCTION_FAILED; |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 889 | pfc_host_stat = &ha->fc_host_stat; |
| 890 | memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics)); |
| 891 | |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 892 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 893 | rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf, |
| 894 | sizeof(stat_buf) / 4, mb_stat); |
Andrew Vasquez | 178779a | 2007-01-29 10:22:25 -0800 | [diff] [blame^] | 895 | } else if (atomic_read(&ha->loop_state) == LOOP_READY && |
| 896 | !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) && |
| 897 | !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) && |
| 898 | !ha->dpc_active) { |
| 899 | /* Must be in a 'READY' state for statistics retrieval. */ |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 900 | rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf, |
| 901 | mb_stat); |
| 902 | } |
Andrew Vasquez | 178779a | 2007-01-29 10:22:25 -0800 | [diff] [blame^] | 903 | |
| 904 | if (rval != QLA_SUCCESS) |
| 905 | goto done; |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 906 | |
| 907 | pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt; |
| 908 | pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt; |
| 909 | pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt; |
| 910 | pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt; |
| 911 | pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt; |
| 912 | pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt; |
Andrew Vasquez | 178779a | 2007-01-29 10:22:25 -0800 | [diff] [blame^] | 913 | done: |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 914 | return pfc_host_stat; |
| 915 | } |
| 916 | |
Andrew Vasquez | 1620f7c | 2006-10-02 12:00:44 -0700 | [diff] [blame] | 917 | static void |
| 918 | qla2x00_get_host_symbolic_name(struct Scsi_Host *shost) |
| 919 | { |
| 920 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 921 | |
| 922 | qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost)); |
| 923 | } |
| 924 | |
Andrew Vasquez | a740a3f | 2006-10-02 12:00:45 -0700 | [diff] [blame] | 925 | static void |
| 926 | qla2x00_set_host_system_hostname(struct Scsi_Host *shost) |
| 927 | { |
| 928 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 929 | |
| 930 | set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags); |
| 931 | } |
| 932 | |
Andrew Vasquez | 90991c8 | 2006-10-02 12:00:46 -0700 | [diff] [blame] | 933 | static void |
| 934 | qla2x00_get_host_fabric_name(struct Scsi_Host *shost) |
| 935 | { |
| 936 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 937 | u64 node_name; |
| 938 | |
| 939 | if (ha->device_flags & SWITCH_FOUND) |
| 940 | node_name = wwn_to_u64(ha->fabric_node_name); |
| 941 | else |
| 942 | node_name = wwn_to_u64(ha->node_name); |
| 943 | |
| 944 | fc_host_fabric_name(shost) = node_name; |
| 945 | } |
| 946 | |
Andrew Vasquez | 7047fcd | 2006-10-02 12:00:47 -0700 | [diff] [blame] | 947 | static void |
| 948 | qla2x00_get_host_port_state(struct Scsi_Host *shost) |
| 949 | { |
| 950 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 951 | |
| 952 | if (!ha->flags.online) |
| 953 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; |
| 954 | else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT) |
| 955 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; |
| 956 | else |
| 957 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; |
| 958 | } |
| 959 | |
Andrew Vasquez | 1c97a12 | 2005-04-21 16:13:36 -0400 | [diff] [blame] | 960 | struct fc_function_template qla2xxx_transport_functions = { |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 961 | |
| 962 | .show_host_node_name = 1, |
| 963 | .show_host_port_name = 1, |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 964 | .show_host_supported_classes = 1, |
| 965 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 966 | .get_host_port_id = qla2x00_get_host_port_id, |
| 967 | .show_host_port_id = 1, |
andrew.vasquez@qlogic.com | 0441401 | 2006-01-31 16:04:51 -0800 | [diff] [blame] | 968 | .get_host_speed = qla2x00_get_host_speed, |
| 969 | .show_host_speed = 1, |
andrew.vasquez@qlogic.com | 8d06762 | 2006-01-31 16:04:56 -0800 | [diff] [blame] | 970 | .get_host_port_type = qla2x00_get_host_port_type, |
| 971 | .show_host_port_type = 1, |
Andrew Vasquez | 1620f7c | 2006-10-02 12:00:44 -0700 | [diff] [blame] | 972 | .get_host_symbolic_name = qla2x00_get_host_symbolic_name, |
| 973 | .show_host_symbolic_name = 1, |
Andrew Vasquez | a740a3f | 2006-10-02 12:00:45 -0700 | [diff] [blame] | 974 | .set_host_system_hostname = qla2x00_set_host_system_hostname, |
| 975 | .show_host_system_hostname = 1, |
Andrew Vasquez | 90991c8 | 2006-10-02 12:00:46 -0700 | [diff] [blame] | 976 | .get_host_fabric_name = qla2x00_get_host_fabric_name, |
| 977 | .show_host_fabric_name = 1, |
Andrew Vasquez | 7047fcd | 2006-10-02 12:00:47 -0700 | [diff] [blame] | 978 | .get_host_port_state = qla2x00_get_host_port_state, |
| 979 | .show_host_port_state = 1, |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 980 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 981 | .dd_fcrport_size = sizeof(struct fc_port *), |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 982 | .show_rport_supported_classes = 1, |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 983 | |
| 984 | .get_starget_node_name = qla2x00_get_starget_node_name, |
| 985 | .show_starget_node_name = 1, |
| 986 | .get_starget_port_name = qla2x00_get_starget_port_name, |
| 987 | .show_starget_port_name = 1, |
| 988 | .get_starget_port_id = qla2x00_get_starget_port_id, |
| 989 | .show_starget_port_id = 1, |
| 990 | |
| 991 | .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo, |
| 992 | .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo, |
| 993 | .show_rport_dev_loss_tmo = 1, |
| 994 | |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 995 | .issue_fc_host_lip = qla2x00_issue_lip, |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 996 | .get_fc_host_stats = qla2x00_get_fc_host_stats, |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 997 | }; |
| 998 | |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 999 | void |
| 1000 | qla2x00_init_host_attr(scsi_qla_host_t *ha) |
| 1001 | { |
andrew.vasquez@qlogic.com | dad9c8c | 2006-01-13 17:04:49 -0800 | [diff] [blame] | 1002 | fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name); |
| 1003 | fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 1004 | fc_host_supported_classes(ha->host) = FC_COS_CLASS3; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1005 | } |