blob: c681b2a355e137a99edcfd39e1c18b8c7dcbda11 [file] [log] [blame]
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001/*
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 Parkash068237c82012-05-18 04:41:44 -040012static ssize_t
13qla4_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
20 if (!is_qla8022(ha))
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
30static ssize_t
31qla4_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
41 if (!is_qla8022(ha))
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 */
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);
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
92 qla4_8xxx_idc_unlock(ha);
93 break;
94 default:
95 /* do nothing */
96 break;
97 }
98
99 return count;
100}
101
102static 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
112static 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
120void 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
136void 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 Zunjarrao7ad633c2011-05-17 23:17:11 -0700146/* Scsi_Host attributes. */
147static ssize_t
148qla4xxx_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
153 if (is_qla8022(ha))
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
165static ssize_t
166qla4xxx_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
173static ssize_t
174qla4xxx_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
182static ssize_t
183qla4xxx_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 Chaudhary91ec7ce2011-08-01 03:26:17 -0700192static ssize_t
193qla4xxx_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
200static ssize_t
201qla4xxx_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
211static ssize_t
212qla4xxx_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
217 if (!is_qla8022(ha))
218 return -ENOSYS;
219
220 return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_cnt);
221}
222
223static ssize_t
224qla4xxx_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
229 if (!is_qla8022(ha))
230 return -ENOSYS;
231
232 return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_num);
233}
234
235static ssize_t
236qla4xxx_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
241 if (!is_qla8022(ha))
242 return -ENOSYS;
243
244 return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->iscsi_pci_func_cnt);
245}
246
247static ssize_t
248qla4xxx_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 Zunjarrao7ad633c2011-05-17 23:17:11 -0700256static DEVICE_ATTR(fw_version, S_IRUGO, qla4xxx_fw_version_show, NULL);
257static DEVICE_ATTR(serial_num, S_IRUGO, qla4xxx_serial_num_show, NULL);
258static DEVICE_ATTR(iscsi_version, S_IRUGO, qla4xxx_iscsi_version_show, NULL);
259static DEVICE_ATTR(optrom_version, S_IRUGO, qla4xxx_optrom_version_show, NULL);
Vikas Chaudhary91ec7ce2011-08-01 03:26:17 -0700260static DEVICE_ATTR(board_id, S_IRUGO, qla4xxx_board_id_show, NULL);
261static DEVICE_ATTR(fw_state, S_IRUGO, qla4xxx_fw_state_show, NULL);
262static DEVICE_ATTR(phy_port_cnt, S_IRUGO, qla4xxx_phy_port_cnt_show, NULL);
263static DEVICE_ATTR(phy_port_num, S_IRUGO, qla4xxx_phy_port_num_show, NULL);
264static DEVICE_ATTR(iscsi_func_cnt, S_IRUGO, qla4xxx_iscsi_func_cnt_show, NULL);
265static DEVICE_ATTR(hba_model, S_IRUGO, qla4xxx_hba_model_show, NULL);
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -0700266
267struct 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 Chaudhary91ec7ce2011-08-01 03:26:17 -0700272 &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 Zunjarrao7ad633c2011-05-17 23:17:11 -0700278 NULL,
279};