2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2011 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
13 qla4_8xxx_sysfs_read_fw_dump(struct file *filep, struct kobject *kobj,
14 struct bin_attribute *ba, char *buf, loff_t off,
17 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
18 struct device, kobj)));
23 if (!test_bit(AF_82XX_DUMP_READING, &ha->flags))
26 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
31 qla4_8xxx_sysfs_write_fw_dump(struct file *filep, struct kobject *kobj,
32 struct bin_attribute *ba, char *buf, loff_t off,
35 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
36 struct device, kobj)));
48 ret = kstrtol(buf, 10, &reading);
50 ql4_printk(KERN_ERR, ha, "%s: Invalid input. Return err %d\n",
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"));
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",
78 qla4_8xxx_idc_lock(ha);
79 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
80 if (dev_state == QLA82XX_DEV_READY) {
81 ql4_printk(KERN_INFO, ha,
82 "%s: Setting Need reset, reset_owner is 0x%x.\n",
83 __func__, ha->func_num);
84 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
85 QLA82XX_DEV_NEED_RESET);
86 set_bit(AF_82XX_RST_OWNER, &ha->flags);
88 ql4_printk(KERN_INFO, ha,
89 "%s: Reset not performed as device state is 0x%x\n",
92 qla4_8xxx_idc_unlock(ha);
102 static struct bin_attribute sysfs_fw_dump_attr = {
105 .mode = S_IRUSR | S_IWUSR,
108 .read = qla4_8xxx_sysfs_read_fw_dump,
109 .write = qla4_8xxx_sysfs_write_fw_dump,
112 static struct sysfs_entry {
114 struct bin_attribute *attr;
115 } bin_file_entries[] = {
116 { "fw_dump", &sysfs_fw_dump_attr },
120 void qla4_8xxx_alloc_sysfs_attr(struct scsi_qla_host *ha)
122 struct Scsi_Host *host = ha->host;
123 struct sysfs_entry *iter;
126 for (iter = bin_file_entries; iter->name; iter++) {
127 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
130 ql4_printk(KERN_ERR, ha,
131 "Unable to create sysfs %s binary attribute (%d).\n",
136 void qla4_8xxx_free_sysfs_attr(struct scsi_qla_host *ha)
138 struct Scsi_Host *host = ha->host;
139 struct sysfs_entry *iter;
141 for (iter = bin_file_entries; iter->name; iter++)
142 sysfs_remove_bin_file(&host->shost_gendev.kobj,
146 /* Scsi_Host attributes. */
148 qla4xxx_fw_version_show(struct device *dev,
149 struct device_attribute *attr, char *buf)
151 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
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);
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);
166 qla4xxx_serial_num_show(struct device *dev, struct device_attribute *attr,
169 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
170 return snprintf(buf, PAGE_SIZE, "%s\n", ha->serial_number);
174 qla4xxx_iscsi_version_show(struct device *dev, struct device_attribute *attr,
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,
183 qla4xxx_optrom_version_show(struct device *dev, struct device_attribute *attr,
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);
193 qla4xxx_board_id_show(struct device *dev, struct device_attribute *attr,
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);
201 qla4xxx_fw_state_show(struct device *dev, struct device_attribute *attr,
204 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
206 qla4xxx_get_firmware_state(ha);
207 return snprintf(buf, PAGE_SIZE, "0x%08X%8X\n", ha->firmware_state,
212 qla4xxx_phy_port_cnt_show(struct device *dev, struct device_attribute *attr,
215 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
220 return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_cnt);
224 qla4xxx_phy_port_num_show(struct device *dev, struct device_attribute *attr,
227 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
232 return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_num);
236 qla4xxx_iscsi_func_cnt_show(struct device *dev, struct device_attribute *attr,
239 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
244 return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->iscsi_pci_func_cnt);
248 qla4xxx_hba_model_show(struct device *dev, struct device_attribute *attr,
251 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
253 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_name);
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);
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);
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,
274 &dev_attr_phy_port_cnt,
275 &dev_attr_phy_port_num,
276 &dev_attr_iscsi_func_cnt,