| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1 | /* |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 2 | * QLogic Fibre Channel HBA Driver |
| 3 | * Copyright (c) 2003-2005 QLogic Corporation |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4 | * |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 6 | */ |
| 7 | #include "qla_def.h" |
| 8 | |
| 7aaef27 | 2005-04-17 16:32:42 -0500 | [diff] [blame] | 9 | #include <linux/vmalloc.h> |
| 8482e118 | 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))); |
| 19 | |
| 20 | if (ha->fw_dump_reading == 0) |
| 21 | return 0; |
| 22 | if (off > ha->fw_dump_buffer_len) |
| 23 | return 0; |
| 24 | if (off + count > ha->fw_dump_buffer_len) |
| 25 | count = ha->fw_dump_buffer_len - off; |
| 26 | |
| 27 | memcpy(buf, &ha->fw_dump_buffer[off], count); |
| 28 | |
| 29 | return (count); |
| 30 | } |
| 31 | |
| 32 | static ssize_t |
| 33 | qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf, loff_t off, |
| 34 | size_t count) |
| 35 | { |
| 36 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 37 | struct device, kobj))); |
| 38 | int reading; |
| 39 | uint32_t dump_size; |
| 40 | |
| 41 | if (off != 0) |
| 42 | return (0); |
| 43 | |
| 44 | reading = simple_strtol(buf, NULL, 10); |
| 45 | switch (reading) { |
| 46 | case 0: |
| 47 | if (ha->fw_dump_reading == 1) { |
| 48 | qla_printk(KERN_INFO, ha, |
| 49 | "Firmware dump cleared on (%ld).\n", |
| 50 | ha->host_no); |
| 51 | |
| 52 | vfree(ha->fw_dump_buffer); |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame^] | 53 | if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 54 | free_pages((unsigned long)ha->fw_dump, |
| 55 | ha->fw_dump_order); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 56 | |
| 57 | ha->fw_dump_reading = 0; |
| 58 | ha->fw_dump_buffer = NULL; |
| 59 | ha->fw_dump = NULL; |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 60 | ha->fw_dumped = 0; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 61 | } |
| 62 | break; |
| 63 | case 1: |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 64 | if ((ha->fw_dump || ha->fw_dumped) && !ha->fw_dump_reading) { |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 65 | ha->fw_dump_reading = 1; |
| 66 | |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame^] | 67 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 68 | dump_size = FW_DUMP_SIZE_24XX; |
| 69 | else { |
| 70 | dump_size = FW_DUMP_SIZE_1M; |
| 71 | if (ha->fw_memory_size < 0x20000) |
| 72 | dump_size = FW_DUMP_SIZE_128K; |
| 73 | else if (ha->fw_memory_size < 0x80000) |
| 74 | dump_size = FW_DUMP_SIZE_512K; |
| 75 | } |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 76 | ha->fw_dump_buffer = (char *)vmalloc(dump_size); |
| 77 | if (ha->fw_dump_buffer == NULL) { |
| 78 | qla_printk(KERN_WARNING, ha, |
| 79 | "Unable to allocate memory for firmware " |
| 80 | "dump buffer (%d).\n", dump_size); |
| 81 | |
| 82 | ha->fw_dump_reading = 0; |
| 83 | return (count); |
| 84 | } |
| 85 | qla_printk(KERN_INFO, ha, |
| 86 | "Firmware dump ready for read on (%ld).\n", |
| 87 | ha->host_no); |
| 88 | memset(ha->fw_dump_buffer, 0, dump_size); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 89 | ha->isp_ops.ascii_fw_dump(ha); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 90 | ha->fw_dump_buffer_len = strlen(ha->fw_dump_buffer); |
| 91 | } |
| 92 | break; |
| 93 | } |
| 94 | return (count); |
| 95 | } |
| 96 | |
| 97 | static struct bin_attribute sysfs_fw_dump_attr = { |
| 98 | .attr = { |
| 99 | .name = "fw_dump", |
| 100 | .mode = S_IRUSR | S_IWUSR, |
| 101 | .owner = THIS_MODULE, |
| 102 | }, |
| 103 | .size = 0, |
| 104 | .read = qla2x00_sysfs_read_fw_dump, |
| 105 | .write = qla2x00_sysfs_write_fw_dump, |
| 106 | }; |
| 107 | |
| 108 | static ssize_t |
| 109 | qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf, loff_t off, |
| 110 | size_t count) |
| 111 | { |
| 112 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 113 | struct device, kobj))); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 114 | unsigned long flags; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 115 | |
andrew.vasquez@qlogic.com | 1b3f636 | 2006-01-31 16:05:12 -0800 | [diff] [blame] | 116 | if (!capable(CAP_SYS_ADMIN) || off != 0) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 117 | return 0; |
| 118 | |
| 119 | /* Read NVRAM. */ |
| 120 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 121 | ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->nvram_base, |
| 122 | ha->nvram_size); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 123 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 124 | |
andrew.vasquez@qlogic.com | 1b3f636 | 2006-01-31 16:05:12 -0800 | [diff] [blame] | 125 | return ha->nvram_size; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static ssize_t |
| 129 | qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, loff_t off, |
| 130 | size_t count) |
| 131 | { |
| 132 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 133 | struct device, kobj))); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 134 | unsigned long flags; |
| 135 | uint16_t cnt; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 136 | |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 137 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 138 | return 0; |
| 139 | |
| 140 | /* Checksum NVRAM. */ |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame^] | 141 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 142 | uint32_t *iter; |
| 143 | uint32_t chksum; |
| 144 | |
| 145 | iter = (uint32_t *)buf; |
| 146 | chksum = 0; |
| 147 | for (cnt = 0; cnt < ((count >> 2) - 1); cnt++) |
| 148 | chksum += le32_to_cpu(*iter++); |
| 149 | chksum = ~chksum + 1; |
| 150 | *iter = cpu_to_le32(chksum); |
| 151 | } else { |
| 152 | uint8_t *iter; |
| 153 | uint8_t chksum; |
| 154 | |
| 155 | iter = (uint8_t *)buf; |
| 156 | chksum = 0; |
| 157 | for (cnt = 0; cnt < count - 1; cnt++) |
| 158 | chksum += *iter++; |
| 159 | chksum = ~chksum + 1; |
| 160 | *iter = chksum; |
| 161 | } |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 162 | |
| 163 | /* Write NVRAM. */ |
| 164 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 165 | ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 166 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 167 | |
| 168 | return (count); |
| 169 | } |
| 170 | |
| 171 | static struct bin_attribute sysfs_nvram_attr = { |
| 172 | .attr = { |
| 173 | .name = "nvram", |
| 174 | .mode = S_IRUSR | S_IWUSR, |
| 175 | .owner = THIS_MODULE, |
| 176 | }, |
andrew.vasquez@qlogic.com | 1b3f636 | 2006-01-31 16:05:12 -0800 | [diff] [blame] | 177 | .size = 512, |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 178 | .read = qla2x00_sysfs_read_nvram, |
| 179 | .write = qla2x00_sysfs_write_nvram, |
| 180 | }; |
| 181 | |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 182 | static ssize_t |
| 183 | qla2x00_sysfs_read_optrom(struct kobject *kobj, char *buf, loff_t off, |
| 184 | size_t count) |
| 185 | { |
| 186 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 187 | struct device, kobj))); |
| 188 | |
| 189 | if (ha->optrom_state != QLA_SREADING) |
| 190 | return 0; |
| 191 | if (off > ha->optrom_size) |
| 192 | return 0; |
| 193 | if (off + count > ha->optrom_size) |
| 194 | count = ha->optrom_size - off; |
| 195 | |
| 196 | memcpy(buf, &ha->optrom_buffer[off], count); |
| 197 | |
| 198 | return count; |
| 199 | } |
| 200 | |
| 201 | static ssize_t |
| 202 | qla2x00_sysfs_write_optrom(struct kobject *kobj, char *buf, loff_t off, |
| 203 | size_t count) |
| 204 | { |
| 205 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 206 | struct device, kobj))); |
| 207 | |
| 208 | if (ha->optrom_state != QLA_SWRITING) |
| 209 | return -EINVAL; |
| 210 | if (off > ha->optrom_size) |
| 211 | return -ERANGE; |
| 212 | if (off + count > ha->optrom_size) |
| 213 | count = ha->optrom_size - off; |
| 214 | |
| 215 | memcpy(&ha->optrom_buffer[off], buf, count); |
| 216 | |
| 217 | return count; |
| 218 | } |
| 219 | |
| 220 | static struct bin_attribute sysfs_optrom_attr = { |
| 221 | .attr = { |
| 222 | .name = "optrom", |
| 223 | .mode = S_IRUSR | S_IWUSR, |
| 224 | .owner = THIS_MODULE, |
| 225 | }, |
| 226 | .size = OPTROM_SIZE_24XX, |
| 227 | .read = qla2x00_sysfs_read_optrom, |
| 228 | .write = qla2x00_sysfs_write_optrom, |
| 229 | }; |
| 230 | |
| 231 | static ssize_t |
| 232 | qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj, char *buf, loff_t off, |
| 233 | size_t count) |
| 234 | { |
| 235 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 236 | struct device, kobj))); |
| 237 | int val; |
| 238 | |
| 239 | if (off) |
| 240 | return 0; |
| 241 | |
| 242 | if (sscanf(buf, "%d", &val) != 1) |
| 243 | return -EINVAL; |
| 244 | |
| 245 | switch (val) { |
| 246 | case 0: |
| 247 | if (ha->optrom_state != QLA_SREADING && |
| 248 | ha->optrom_state != QLA_SWRITING) |
| 249 | break; |
| 250 | |
| 251 | ha->optrom_state = QLA_SWAITING; |
| 252 | vfree(ha->optrom_buffer); |
| 253 | ha->optrom_buffer = NULL; |
| 254 | break; |
| 255 | case 1: |
| 256 | if (ha->optrom_state != QLA_SWAITING) |
| 257 | break; |
| 258 | |
| 259 | ha->optrom_state = QLA_SREADING; |
| 260 | ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size); |
| 261 | if (ha->optrom_buffer == NULL) { |
| 262 | qla_printk(KERN_WARNING, ha, |
| 263 | "Unable to allocate memory for optrom retrieval " |
| 264 | "(%x).\n", ha->optrom_size); |
| 265 | |
| 266 | ha->optrom_state = QLA_SWAITING; |
| 267 | return count; |
| 268 | } |
| 269 | |
| 270 | memset(ha->optrom_buffer, 0, ha->optrom_size); |
| 271 | ha->isp_ops.read_optrom(ha, ha->optrom_buffer, 0, |
| 272 | ha->optrom_size); |
| 273 | break; |
| 274 | case 2: |
| 275 | if (ha->optrom_state != QLA_SWAITING) |
| 276 | break; |
| 277 | |
| 278 | ha->optrom_state = QLA_SWRITING; |
| 279 | ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size); |
| 280 | if (ha->optrom_buffer == NULL) { |
| 281 | qla_printk(KERN_WARNING, ha, |
| 282 | "Unable to allocate memory for optrom update " |
| 283 | "(%x).\n", ha->optrom_size); |
| 284 | |
| 285 | ha->optrom_state = QLA_SWAITING; |
| 286 | return count; |
| 287 | } |
| 288 | memset(ha->optrom_buffer, 0, ha->optrom_size); |
| 289 | break; |
| 290 | case 3: |
| 291 | if (ha->optrom_state != QLA_SWRITING) |
| 292 | break; |
| 293 | |
| 294 | ha->isp_ops.write_optrom(ha, ha->optrom_buffer, 0, |
| 295 | ha->optrom_size); |
| 296 | break; |
| 297 | } |
| 298 | return count; |
| 299 | } |
| 300 | |
| 301 | static struct bin_attribute sysfs_optrom_ctl_attr = { |
| 302 | .attr = { |
| 303 | .name = "optrom_ctl", |
| 304 | .mode = S_IWUSR, |
| 305 | .owner = THIS_MODULE, |
| 306 | }, |
| 307 | .size = 0, |
| 308 | .write = qla2x00_sysfs_write_optrom_ctl, |
| 309 | }; |
| 310 | |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 311 | void |
| 312 | qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha) |
| 313 | { |
| 314 | struct Scsi_Host *host = ha->host; |
| 315 | |
| 316 | sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr); |
| 317 | sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 318 | sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr); |
| 319 | sysfs_create_bin_file(&host->shost_gendev.kobj, |
| 320 | &sysfs_optrom_ctl_attr); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | void |
| 324 | qla2x00_free_sysfs_attr(scsi_qla_host_t *ha) |
| 325 | { |
| 326 | struct Scsi_Host *host = ha->host; |
| 327 | |
| 328 | sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr); |
| 329 | sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 330 | sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr); |
| 331 | sysfs_remove_bin_file(&host->shost_gendev.kobj, |
| 332 | &sysfs_optrom_ctl_attr); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 333 | |
| 334 | if (ha->beacon_blink_led == 1) |
| 335 | ha->isp_ops.beacon_off(ha); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 336 | } |
| 337 | |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 338 | /* Scsi_Host attributes. */ |
| 339 | |
| 340 | static ssize_t |
| 341 | qla2x00_drvr_version_show(struct class_device *cdev, char *buf) |
| 342 | { |
| 343 | return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str); |
| 344 | } |
| 345 | |
| 346 | static ssize_t |
| 347 | qla2x00_fw_version_show(struct class_device *cdev, char *buf) |
| 348 | { |
| 349 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 350 | char fw_str[30]; |
| 351 | |
| 352 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 353 | ha->isp_ops.fw_version_str(ha, fw_str)); |
| 354 | } |
| 355 | |
| 356 | static ssize_t |
| 357 | qla2x00_serial_num_show(struct class_device *cdev, char *buf) |
| 358 | { |
| 359 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 360 | uint32_t sn; |
| 361 | |
| 362 | sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1; |
| 363 | return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000, |
| 364 | sn % 100000); |
| 365 | } |
| 366 | |
| 367 | static ssize_t |
| 368 | qla2x00_isp_name_show(struct class_device *cdev, char *buf) |
| 369 | { |
| 370 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 371 | return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device); |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | static ssize_t |
| 375 | qla2x00_isp_id_show(struct class_device *cdev, char *buf) |
| 376 | { |
| 377 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 378 | return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n", |
| 379 | ha->product_id[0], ha->product_id[1], ha->product_id[2], |
| 380 | ha->product_id[3]); |
| 381 | } |
| 382 | |
| 383 | static ssize_t |
| 384 | qla2x00_model_name_show(struct class_device *cdev, char *buf) |
| 385 | { |
| 386 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 387 | return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number); |
| 388 | } |
| 389 | |
| 390 | static ssize_t |
| 391 | qla2x00_model_desc_show(struct class_device *cdev, char *buf) |
| 392 | { |
| 393 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 394 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 395 | ha->model_desc ? ha->model_desc: ""); |
| 396 | } |
| 397 | |
| 398 | static ssize_t |
| 399 | qla2x00_pci_info_show(struct class_device *cdev, char *buf) |
| 400 | { |
| 401 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 402 | char pci_info[30]; |
| 403 | |
| 404 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 405 | ha->isp_ops.pci_info_str(ha, pci_info)); |
| 406 | } |
| 407 | |
| 408 | static ssize_t |
| 409 | qla2x00_state_show(struct class_device *cdev, char *buf) |
| 410 | { |
| 411 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 412 | int len = 0; |
| 413 | |
| 414 | if (atomic_read(&ha->loop_state) == LOOP_DOWN || |
| 415 | atomic_read(&ha->loop_state) == LOOP_DEAD) |
| 416 | len = snprintf(buf, PAGE_SIZE, "Link Down\n"); |
| 417 | else if (atomic_read(&ha->loop_state) != LOOP_READY || |
| 418 | test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) || |
| 419 | test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) |
| 420 | len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n"); |
| 421 | else { |
| 422 | len = snprintf(buf, PAGE_SIZE, "Link Up - "); |
| 423 | |
| 424 | switch (ha->current_topology) { |
| 425 | case ISP_CFG_NL: |
| 426 | len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n"); |
| 427 | break; |
| 428 | case ISP_CFG_FL: |
| 429 | len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n"); |
| 430 | break; |
| 431 | case ISP_CFG_N: |
| 432 | len += snprintf(buf + len, PAGE_SIZE-len, |
| 433 | "N_Port to N_Port\n"); |
| 434 | break; |
| 435 | case ISP_CFG_F: |
| 436 | len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n"); |
| 437 | break; |
| 438 | default: |
| 439 | len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n"); |
| 440 | break; |
| 441 | } |
| 442 | } |
| 443 | return len; |
| 444 | } |
| 445 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 446 | static ssize_t |
| 447 | qla2x00_zio_show(struct class_device *cdev, char *buf) |
| 448 | { |
| 449 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 450 | int len = 0; |
| 451 | |
| 452 | switch (ha->zio_mode) { |
| 453 | case QLA_ZIO_MODE_5: |
| 454 | len += snprintf(buf + len, PAGE_SIZE-len, "Mode 5\n"); |
| 455 | break; |
| 456 | case QLA_ZIO_MODE_6: |
| 457 | len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n"); |
| 458 | break; |
| 459 | case QLA_ZIO_DISABLED: |
| 460 | len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n"); |
| 461 | break; |
| 462 | } |
| 463 | return len; |
| 464 | } |
| 465 | |
| 466 | static ssize_t |
| 467 | qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count) |
| 468 | { |
| 469 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 470 | int val = 0; |
| 471 | uint16_t zio_mode; |
| 472 | |
| 473 | if (sscanf(buf, "%d", &val) != 1) |
| 474 | return -EINVAL; |
| 475 | |
| 476 | switch (val) { |
| 477 | case 1: |
| 478 | zio_mode = QLA_ZIO_MODE_5; |
| 479 | break; |
| 480 | case 2: |
| 481 | zio_mode = QLA_ZIO_MODE_6; |
| 482 | break; |
| 483 | default: |
| 484 | zio_mode = QLA_ZIO_DISABLED; |
| 485 | break; |
| 486 | } |
| 487 | |
| 488 | /* Update per-hba values and queue a reset. */ |
| 489 | if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) { |
| 490 | ha->zio_mode = zio_mode; |
| 491 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 492 | } |
| 493 | return strlen(buf); |
| 494 | } |
| 495 | |
| 496 | static ssize_t |
| 497 | qla2x00_zio_timer_show(struct class_device *cdev, char *buf) |
| 498 | { |
| 499 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 500 | |
| 501 | return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100); |
| 502 | } |
| 503 | |
| 504 | static ssize_t |
| 505 | qla2x00_zio_timer_store(struct class_device *cdev, const char *buf, |
| 506 | size_t count) |
| 507 | { |
| 508 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 509 | int val = 0; |
| 510 | uint16_t zio_timer; |
| 511 | |
| 512 | if (sscanf(buf, "%d", &val) != 1) |
| 513 | return -EINVAL; |
| 514 | if (val > 25500 || val < 100) |
| 515 | return -ERANGE; |
| 516 | |
| 517 | zio_timer = (uint16_t)(val / 100); |
| 518 | ha->zio_timer = zio_timer; |
| 519 | |
| 520 | return strlen(buf); |
| 521 | } |
| 522 | |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 523 | static ssize_t |
| 524 | qla2x00_beacon_show(struct class_device *cdev, char *buf) |
| 525 | { |
| 526 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 527 | int len = 0; |
| 528 | |
| 529 | if (ha->beacon_blink_led) |
| 530 | len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n"); |
| 531 | else |
| 532 | len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n"); |
| 533 | return len; |
| 534 | } |
| 535 | |
| 536 | static ssize_t |
| 537 | qla2x00_beacon_store(struct class_device *cdev, const char *buf, |
| 538 | size_t count) |
| 539 | { |
| 540 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); |
| 541 | int val = 0; |
| 542 | int rval; |
| 543 | |
| 544 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 545 | return -EPERM; |
| 546 | |
| 547 | if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) { |
| 548 | qla_printk(KERN_WARNING, ha, |
| 549 | "Abort ISP active -- ignoring beacon request.\n"); |
| 550 | return -EBUSY; |
| 551 | } |
| 552 | |
| 553 | if (sscanf(buf, "%d", &val) != 1) |
| 554 | return -EINVAL; |
| 555 | |
| 556 | if (val) |
| 557 | rval = ha->isp_ops.beacon_on(ha); |
| 558 | else |
| 559 | rval = ha->isp_ops.beacon_off(ha); |
| 560 | |
| 561 | if (rval != QLA_SUCCESS) |
| 562 | count = 0; |
| 563 | |
| 564 | return count; |
| 565 | } |
| 566 | |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 567 | static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, |
| 568 | NULL); |
| 569 | static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL); |
| 570 | static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL); |
| 571 | static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL); |
| 572 | static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL); |
| 573 | static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL); |
| 574 | static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL); |
| 575 | static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL); |
| 576 | static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL); |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 577 | static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, |
| 578 | qla2x00_zio_store); |
| 579 | static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show, |
| 580 | qla2x00_zio_timer_store); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 581 | static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show, |
| 582 | qla2x00_beacon_store); |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 583 | |
| 584 | struct class_device_attribute *qla2x00_host_attrs[] = { |
| 585 | &class_device_attr_driver_version, |
| 586 | &class_device_attr_fw_version, |
| 587 | &class_device_attr_serial_num, |
| 588 | &class_device_attr_isp_name, |
| 589 | &class_device_attr_isp_id, |
| 590 | &class_device_attr_model_name, |
| 591 | &class_device_attr_model_desc, |
| 592 | &class_device_attr_pci_info, |
| 593 | &class_device_attr_state, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 594 | &class_device_attr_zio, |
| 595 | &class_device_attr_zio_timer, |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 596 | &class_device_attr_beacon, |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 597 | NULL, |
| 598 | }; |
| 599 | |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 600 | /* Host attributes. */ |
| 601 | |
| 602 | static void |
| 603 | qla2x00_get_host_port_id(struct Scsi_Host *shost) |
| 604 | { |
| 605 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 606 | |
| 607 | fc_host_port_id(shost) = ha->d_id.b.domain << 16 | |
| 608 | ha->d_id.b.area << 8 | ha->d_id.b.al_pa; |
| 609 | } |
| 610 | |
| 611 | static void |
andrew.vasquez@qlogic.com | 0441401 | 2006-01-31 16:04:51 -0800 | [diff] [blame] | 612 | qla2x00_get_host_speed(struct Scsi_Host *shost) |
| 613 | { |
| 614 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 615 | uint32_t speed = 0; |
| 616 | |
| 617 | switch (ha->link_data_rate) { |
| 618 | case LDR_1GB: |
| 619 | speed = 1; |
| 620 | break; |
| 621 | case LDR_2GB: |
| 622 | speed = 2; |
| 623 | break; |
| 624 | case LDR_4GB: |
| 625 | speed = 4; |
| 626 | break; |
| 627 | } |
| 628 | fc_host_speed(shost) = speed; |
| 629 | } |
| 630 | |
| 631 | static void |
andrew.vasquez@qlogic.com | 8d06762 | 2006-01-31 16:04:56 -0800 | [diff] [blame] | 632 | qla2x00_get_host_port_type(struct Scsi_Host *shost) |
| 633 | { |
| 634 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 635 | uint32_t port_type = FC_PORTTYPE_UNKNOWN; |
| 636 | |
| 637 | switch (ha->current_topology) { |
| 638 | case ISP_CFG_NL: |
| 639 | port_type = FC_PORTTYPE_LPORT; |
| 640 | break; |
| 641 | case ISP_CFG_FL: |
| 642 | port_type = FC_PORTTYPE_NLPORT; |
| 643 | break; |
| 644 | case ISP_CFG_N: |
| 645 | port_type = FC_PORTTYPE_PTP; |
| 646 | break; |
| 647 | case ISP_CFG_F: |
| 648 | port_type = FC_PORTTYPE_NPORT; |
| 649 | break; |
| 650 | } |
| 651 | fc_host_port_type(shost) = port_type; |
| 652 | } |
| 653 | |
| 654 | static void |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 655 | qla2x00_get_starget_node_name(struct scsi_target *starget) |
| 656 | { |
| 657 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); |
| 658 | scsi_qla_host_t *ha = to_qla_host(host); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 659 | fc_port_t *fcport; |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 660 | u64 node_name = 0; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 661 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 662 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 663 | if (starget->id == fcport->os_target_id) { |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 664 | node_name = wwn_to_u64(fcport->node_name); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 665 | break; |
| 666 | } |
| 667 | } |
| 668 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 669 | fc_starget_node_name(starget) = node_name; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | static void |
| 673 | qla2x00_get_starget_port_name(struct scsi_target *starget) |
| 674 | { |
| 675 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); |
| 676 | scsi_qla_host_t *ha = to_qla_host(host); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 677 | fc_port_t *fcport; |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 678 | u64 port_name = 0; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 679 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 680 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 681 | if (starget->id == fcport->os_target_id) { |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 682 | port_name = wwn_to_u64(fcport->port_name); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 683 | break; |
| 684 | } |
| 685 | } |
| 686 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 687 | fc_starget_port_name(starget) = port_name; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | static void |
| 691 | qla2x00_get_starget_port_id(struct scsi_target *starget) |
| 692 | { |
| 693 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); |
| 694 | scsi_qla_host_t *ha = to_qla_host(host); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 695 | fc_port_t *fcport; |
| 696 | uint32_t port_id = ~0U; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 697 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 698 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 699 | if (starget->id == fcport->os_target_id) { |
| 700 | port_id = fcport->d_id.b.domain << 16 | |
| 701 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 702 | break; |
| 703 | } |
| 704 | } |
| 705 | |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 706 | fc_starget_port_id(starget) = port_id; |
| 707 | } |
| 708 | |
| 709 | static void |
| 710 | qla2x00_get_rport_loss_tmo(struct fc_rport *rport) |
| 711 | { |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 712 | struct Scsi_Host *host = rport_to_shost(rport); |
| 713 | scsi_qla_host_t *ha = to_qla_host(host); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 714 | |
| 715 | rport->dev_loss_tmo = ha->port_down_retry_count + 5; |
| 716 | } |
| 717 | |
| 718 | static void |
| 719 | qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) |
| 720 | { |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 721 | struct Scsi_Host *host = rport_to_shost(rport); |
| 722 | scsi_qla_host_t *ha = to_qla_host(host); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 723 | |
| 724 | if (timeout) |
| 725 | ha->port_down_retry_count = timeout; |
| 726 | else |
| 727 | ha->port_down_retry_count = 1; |
| 728 | |
| 729 | rport->dev_loss_tmo = ha->port_down_retry_count + 5; |
| 730 | } |
| 731 | |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 732 | static int |
| 733 | qla2x00_issue_lip(struct Scsi_Host *shost) |
| 734 | { |
| 735 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 736 | |
| 737 | set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags); |
| 738 | return 0; |
| 739 | } |
| 740 | |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 741 | static struct fc_host_statistics * |
| 742 | qla2x00_get_fc_host_stats(struct Scsi_Host *shost) |
| 743 | { |
| 744 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 745 | int rval; |
| 746 | uint16_t mb_stat[1]; |
| 747 | link_stat_t stat_buf; |
| 748 | struct fc_host_statistics *pfc_host_stat; |
| 749 | |
| 750 | pfc_host_stat = &ha->fc_host_stat; |
| 751 | memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics)); |
| 752 | |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame^] | 753 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 754 | rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf, |
| 755 | sizeof(stat_buf) / 4, mb_stat); |
| 756 | } else { |
| 757 | rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf, |
| 758 | mb_stat); |
| 759 | } |
| 760 | if (rval != 0) { |
| 761 | qla_printk(KERN_WARNING, ha, |
| 762 | "Unable to retrieve host statistics (%d).\n", mb_stat[0]); |
| 763 | return pfc_host_stat; |
| 764 | } |
| 765 | |
| 766 | pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt; |
| 767 | pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt; |
| 768 | pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt; |
| 769 | pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt; |
| 770 | pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt; |
| 771 | pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt; |
| 772 | |
| 773 | return pfc_host_stat; |
| 774 | } |
| 775 | |
Andrew Vasquez | 1c97a12 | 2005-04-21 16:13:36 -0400 | [diff] [blame] | 776 | struct fc_function_template qla2xxx_transport_functions = { |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 777 | |
| 778 | .show_host_node_name = 1, |
| 779 | .show_host_port_name = 1, |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 780 | .show_host_supported_classes = 1, |
| 781 | |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 782 | .get_host_port_id = qla2x00_get_host_port_id, |
| 783 | .show_host_port_id = 1, |
andrew.vasquez@qlogic.com | 0441401 | 2006-01-31 16:04:51 -0800 | [diff] [blame] | 784 | .get_host_speed = qla2x00_get_host_speed, |
| 785 | .show_host_speed = 1, |
andrew.vasquez@qlogic.com | 8d06762 | 2006-01-31 16:04:56 -0800 | [diff] [blame] | 786 | .get_host_port_type = qla2x00_get_host_port_type, |
| 787 | .show_host_port_type = 1, |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 788 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 789 | .dd_fcrport_size = sizeof(struct fc_port *), |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 790 | .show_rport_supported_classes = 1, |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 791 | |
| 792 | .get_starget_node_name = qla2x00_get_starget_node_name, |
| 793 | .show_starget_node_name = 1, |
| 794 | .get_starget_port_name = qla2x00_get_starget_port_name, |
| 795 | .show_starget_port_name = 1, |
| 796 | .get_starget_port_id = qla2x00_get_starget_port_id, |
| 797 | .show_starget_port_id = 1, |
| 798 | |
| 799 | .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo, |
| 800 | .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo, |
| 801 | .show_rport_dev_loss_tmo = 1, |
| 802 | |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 803 | .issue_fc_host_lip = qla2x00_issue_lip, |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 804 | .get_fc_host_stats = qla2x00_get_fc_host_stats, |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 805 | }; |
| 806 | |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 807 | void |
| 808 | qla2x00_init_host_attr(scsi_qla_host_t *ha) |
| 809 | { |
andrew.vasquez@qlogic.com | dad9c8c | 2006-01-13 17:04:49 -0800 | [diff] [blame] | 810 | fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name); |
| 811 | fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 812 | fc_host_supported_classes(ha->host) = FC_COS_CLASS3; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 813 | } |