Harish Zunjarrao | 7ad633c | 2011-05-17 23:17:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLogic iSCSI HBA Driver |
| 3 | * Copyright (c) 2003-2011 QLogic Corporation |
| 4 | * |
| 5 | * See LICENSE.qla4xxx for copyright and licensing details. |
| 6 | */ |
| 7 | |
| 8 | #include "ql4_def.h" |
| 9 | #include "ql4_glbl.h" |
| 10 | #include "ql4_dbg.h" |
| 11 | |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 12 | static ssize_t |
| 13 | qla4_8xxx_sysfs_read_fw_dump(struct file *filep, struct kobject *kobj, |
| 14 | struct bin_attribute *ba, 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 | |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 20 | if (is_qla40XX(ha)) |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 21 | return -EINVAL; |
| 22 | |
| 23 | if (!test_bit(AF_82XX_DUMP_READING, &ha->flags)) |
| 24 | return 0; |
| 25 | |
| 26 | return memory_read_from_buffer(buf, count, &off, ha->fw_dump, |
| 27 | ha->fw_dump_size); |
| 28 | } |
| 29 | |
| 30 | static ssize_t |
| 31 | qla4_8xxx_sysfs_write_fw_dump(struct file *filep, struct kobject *kobj, |
| 32 | struct bin_attribute *ba, char *buf, loff_t off, |
| 33 | size_t count) |
| 34 | { |
| 35 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 36 | struct device, kobj))); |
| 37 | uint32_t dev_state; |
| 38 | long reading; |
| 39 | int ret = 0; |
| 40 | |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 41 | if (is_qla40XX(ha)) |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 42 | return -EINVAL; |
| 43 | |
| 44 | if (off != 0) |
| 45 | return ret; |
| 46 | |
| 47 | buf[1] = 0; |
| 48 | ret = kstrtol(buf, 10, &reading); |
| 49 | if (ret) { |
| 50 | ql4_printk(KERN_ERR, ha, "%s: Invalid input. Return err %d\n", |
| 51 | __func__, ret); |
| 52 | return ret; |
| 53 | } |
| 54 | |
| 55 | switch (reading) { |
| 56 | case 0: |
| 57 | /* clear dump collection flags */ |
| 58 | if (test_and_clear_bit(AF_82XX_DUMP_READING, &ha->flags)) { |
| 59 | clear_bit(AF_82XX_FW_DUMPED, &ha->flags); |
| 60 | /* Reload minidump template */ |
| 61 | qla4xxx_alloc_fw_dump(ha); |
| 62 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 63 | "Firmware template reloaded\n")); |
| 64 | } |
| 65 | break; |
| 66 | case 1: |
| 67 | /* Set flag to read dump */ |
| 68 | if (test_bit(AF_82XX_FW_DUMPED, &ha->flags) && |
| 69 | !test_bit(AF_82XX_DUMP_READING, &ha->flags)) { |
| 70 | set_bit(AF_82XX_DUMP_READING, &ha->flags); |
| 71 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 72 | "Raw firmware dump ready for read on (%ld).\n", |
| 73 | ha->host_no)); |
| 74 | } |
| 75 | break; |
| 76 | case 2: |
| 77 | /* Reset HBA */ |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 78 | ha->isp_ops->idc_lock(ha); |
| 79 | dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE); |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 80 | if (dev_state == QLA8XXX_DEV_READY) { |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 81 | ql4_printk(KERN_INFO, ha, |
| 82 | "%s: Setting Need reset, reset_owner is 0x%x.\n", |
| 83 | __func__, ha->func_num); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 84 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 85 | QLA8XXX_DEV_NEED_RESET); |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 86 | set_bit(AF_8XXX_RST_OWNER, &ha->flags); |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 87 | } else |
| 88 | ql4_printk(KERN_INFO, ha, |
| 89 | "%s: Reset not performed as device state is 0x%x\n", |
| 90 | __func__, dev_state); |
| 91 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 92 | ha->isp_ops->idc_unlock(ha); |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 93 | break; |
| 94 | default: |
| 95 | /* do nothing */ |
| 96 | break; |
| 97 | } |
| 98 | |
| 99 | return count; |
| 100 | } |
| 101 | |
| 102 | static struct bin_attribute sysfs_fw_dump_attr = { |
| 103 | .attr = { |
| 104 | .name = "fw_dump", |
| 105 | .mode = S_IRUSR | S_IWUSR, |
| 106 | }, |
| 107 | .size = 0, |
| 108 | .read = qla4_8xxx_sysfs_read_fw_dump, |
| 109 | .write = qla4_8xxx_sysfs_write_fw_dump, |
| 110 | }; |
| 111 | |
| 112 | static struct sysfs_entry { |
| 113 | char *name; |
| 114 | struct bin_attribute *attr; |
| 115 | } bin_file_entries[] = { |
| 116 | { "fw_dump", &sysfs_fw_dump_attr }, |
| 117 | { NULL }, |
| 118 | }; |
| 119 | |
| 120 | void qla4_8xxx_alloc_sysfs_attr(struct scsi_qla_host *ha) |
| 121 | { |
| 122 | struct Scsi_Host *host = ha->host; |
| 123 | struct sysfs_entry *iter; |
| 124 | int ret; |
| 125 | |
| 126 | for (iter = bin_file_entries; iter->name; iter++) { |
| 127 | ret = sysfs_create_bin_file(&host->shost_gendev.kobj, |
| 128 | iter->attr); |
| 129 | if (ret) |
| 130 | ql4_printk(KERN_ERR, ha, |
| 131 | "Unable to create sysfs %s binary attribute (%d).\n", |
| 132 | iter->name, ret); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | void qla4_8xxx_free_sysfs_attr(struct scsi_qla_host *ha) |
| 137 | { |
| 138 | struct Scsi_Host *host = ha->host; |
| 139 | struct sysfs_entry *iter; |
| 140 | |
| 141 | for (iter = bin_file_entries; iter->name; iter++) |
| 142 | sysfs_remove_bin_file(&host->shost_gendev.kobj, |
| 143 | iter->attr); |
| 144 | } |
| 145 | |
Harish Zunjarrao | 7ad633c | 2011-05-17 23:17:11 -0700 | [diff] [blame] | 146 | /* Scsi_Host attributes. */ |
| 147 | static ssize_t |
| 148 | qla4xxx_fw_version_show(struct device *dev, |
| 149 | struct device_attribute *attr, char *buf) |
| 150 | { |
| 151 | struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev)); |
| 152 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame^] | 153 | if (is_qla80XX(ha)) |
Harish Zunjarrao | 7ad633c | 2011-05-17 23:17:11 -0700 | [diff] [blame] | 154 | return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n", |
| 155 | ha->firmware_version[0], |
| 156 | ha->firmware_version[1], |
| 157 | ha->patch_number, ha->build_number); |
| 158 | else |
| 159 | return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d.%02d\n", |
| 160 | ha->firmware_version[0], |
| 161 | ha->firmware_version[1], |
| 162 | ha->patch_number, ha->build_number); |
| 163 | } |
| 164 | |
| 165 | static ssize_t |
| 166 | qla4xxx_serial_num_show(struct device *dev, struct device_attribute *attr, |
| 167 | char *buf) |
| 168 | { |
| 169 | struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev)); |
| 170 | return snprintf(buf, PAGE_SIZE, "%s\n", ha->serial_number); |
| 171 | } |
| 172 | |
| 173 | static ssize_t |
| 174 | qla4xxx_iscsi_version_show(struct device *dev, struct device_attribute *attr, |
| 175 | char *buf) |
| 176 | { |
| 177 | struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev)); |
| 178 | return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->iscsi_major, |
| 179 | ha->iscsi_minor); |
| 180 | } |
| 181 | |
| 182 | static ssize_t |
| 183 | qla4xxx_optrom_version_show(struct device *dev, struct device_attribute *attr, |
| 184 | char *buf) |
| 185 | { |
| 186 | struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev)); |
| 187 | return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d.%02d\n", |
| 188 | ha->bootload_major, ha->bootload_minor, |
| 189 | ha->bootload_patch, ha->bootload_build); |
| 190 | } |
| 191 | |
Vikas Chaudhary | 91ec7ce | 2011-08-01 03:26:17 -0700 | [diff] [blame] | 192 | static ssize_t |
| 193 | qla4xxx_board_id_show(struct device *dev, struct device_attribute *attr, |
| 194 | char *buf) |
| 195 | { |
| 196 | struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev)); |
| 197 | return snprintf(buf, PAGE_SIZE, "0x%08X\n", ha->board_id); |
| 198 | } |
| 199 | |
| 200 | static ssize_t |
| 201 | qla4xxx_fw_state_show(struct device *dev, struct device_attribute *attr, |
| 202 | char *buf) |
| 203 | { |
| 204 | struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev)); |
| 205 | |
| 206 | qla4xxx_get_firmware_state(ha); |
| 207 | return snprintf(buf, PAGE_SIZE, "0x%08X%8X\n", ha->firmware_state, |
| 208 | ha->addl_fw_state); |
| 209 | } |
| 210 | |
| 211 | static ssize_t |
| 212 | qla4xxx_phy_port_cnt_show(struct device *dev, struct device_attribute *attr, |
| 213 | char *buf) |
| 214 | { |
| 215 | struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev)); |
| 216 | |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 217 | if (is_qla40XX(ha)) |
Vikas Chaudhary | 91ec7ce | 2011-08-01 03:26:17 -0700 | [diff] [blame] | 218 | return -ENOSYS; |
| 219 | |
| 220 | return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_cnt); |
| 221 | } |
| 222 | |
| 223 | static ssize_t |
| 224 | qla4xxx_phy_port_num_show(struct device *dev, struct device_attribute *attr, |
| 225 | char *buf) |
| 226 | { |
| 227 | struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev)); |
| 228 | |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 229 | if (is_qla40XX(ha)) |
Vikas Chaudhary | 91ec7ce | 2011-08-01 03:26:17 -0700 | [diff] [blame] | 230 | return -ENOSYS; |
| 231 | |
| 232 | return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_num); |
| 233 | } |
| 234 | |
| 235 | static ssize_t |
| 236 | qla4xxx_iscsi_func_cnt_show(struct device *dev, struct device_attribute *attr, |
| 237 | char *buf) |
| 238 | { |
| 239 | struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev)); |
| 240 | |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 241 | if (is_qla40XX(ha)) |
Vikas Chaudhary | 91ec7ce | 2011-08-01 03:26:17 -0700 | [diff] [blame] | 242 | return -ENOSYS; |
| 243 | |
| 244 | return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->iscsi_pci_func_cnt); |
| 245 | } |
| 246 | |
| 247 | static ssize_t |
| 248 | qla4xxx_hba_model_show(struct device *dev, struct device_attribute *attr, |
| 249 | char *buf) |
| 250 | { |
| 251 | struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev)); |
| 252 | |
| 253 | return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_name); |
| 254 | } |
| 255 | |
Harish Zunjarrao | 7ad633c | 2011-05-17 23:17:11 -0700 | [diff] [blame] | 256 | static DEVICE_ATTR(fw_version, S_IRUGO, qla4xxx_fw_version_show, NULL); |
| 257 | static DEVICE_ATTR(serial_num, S_IRUGO, qla4xxx_serial_num_show, NULL); |
| 258 | static DEVICE_ATTR(iscsi_version, S_IRUGO, qla4xxx_iscsi_version_show, NULL); |
| 259 | static DEVICE_ATTR(optrom_version, S_IRUGO, qla4xxx_optrom_version_show, NULL); |
Vikas Chaudhary | 91ec7ce | 2011-08-01 03:26:17 -0700 | [diff] [blame] | 260 | static DEVICE_ATTR(board_id, S_IRUGO, qla4xxx_board_id_show, NULL); |
| 261 | static DEVICE_ATTR(fw_state, S_IRUGO, qla4xxx_fw_state_show, NULL); |
| 262 | static DEVICE_ATTR(phy_port_cnt, S_IRUGO, qla4xxx_phy_port_cnt_show, NULL); |
| 263 | static DEVICE_ATTR(phy_port_num, S_IRUGO, qla4xxx_phy_port_num_show, NULL); |
| 264 | static DEVICE_ATTR(iscsi_func_cnt, S_IRUGO, qla4xxx_iscsi_func_cnt_show, NULL); |
| 265 | static DEVICE_ATTR(hba_model, S_IRUGO, qla4xxx_hba_model_show, NULL); |
Harish Zunjarrao | 7ad633c | 2011-05-17 23:17:11 -0700 | [diff] [blame] | 266 | |
| 267 | struct device_attribute *qla4xxx_host_attrs[] = { |
| 268 | &dev_attr_fw_version, |
| 269 | &dev_attr_serial_num, |
| 270 | &dev_attr_iscsi_version, |
| 271 | &dev_attr_optrom_version, |
Vikas Chaudhary | 91ec7ce | 2011-08-01 03:26:17 -0700 | [diff] [blame] | 272 | &dev_attr_board_id, |
| 273 | &dev_attr_fw_state, |
| 274 | &dev_attr_phy_port_cnt, |
| 275 | &dev_attr_phy_port_num, |
| 276 | &dev_attr_iscsi_func_cnt, |
| 277 | &dev_attr_hba_model, |
Harish Zunjarrao | 7ad633c | 2011-05-17 23:17:11 -0700 | [diff] [blame] | 278 | NULL, |
| 279 | }; |