blob: 19ee55a6226cb5950226692a2435f35badb0b120 [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
Vikas Chaudharyee996a62012-08-22 07:55:05 -040020 if (is_qla40XX(ha))
Tej Parkash068237c82012-05-18 04:41:44 -040021 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
Vikas Chaudharyee996a62012-08-22 07:55:05 -040041 if (is_qla40XX(ha))
Tej Parkash068237c82012-05-18 04:41:44 -040042 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:
Vikas Chaudhary9661975f2013-01-20 23:51:02 -050077 /* Reset HBA and collect FW dump */
Vikas Chaudhary33693c72012-08-22 07:55:04 -040078 ha->isp_ops->idc_lock(ha);
79 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -040080 if (dev_state == QLA8XXX_DEV_READY) {
Vikas Chaudhary9661975f2013-01-20 23:51:02 -050081 ql4_printk(KERN_INFO, ha, "%s: Setting Need reset\n",
82 __func__);
Vikas Chaudhary33693c72012-08-22 07:55:04 -040083 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
84 QLA8XXX_DEV_NEED_RESET);
Vikas Chaudhary9661975f2013-01-20 23:51:02 -050085 if (is_qla8022(ha) ||
86 (is_qla8032(ha) &&
87 qla4_83xx_can_perform_reset(ha))) {
88 set_bit(AF_8XXX_RST_OWNER, &ha->flags);
89 set_bit(AF_FW_RECOVERY, &ha->flags);
90 ql4_printk(KERN_INFO, ha, "%s: Reset owner is 0x%x\n",
91 __func__, ha->func_num);
92 }
Tej Parkash068237c82012-05-18 04:41:44 -040093 } else
94 ql4_printk(KERN_INFO, ha,
95 "%s: Reset not performed as device state is 0x%x\n",
96 __func__, dev_state);
97
Vikas Chaudhary33693c72012-08-22 07:55:04 -040098 ha->isp_ops->idc_unlock(ha);
Tej Parkash068237c82012-05-18 04:41:44 -040099 break;
100 default:
101 /* do nothing */
102 break;
103 }
104
105 return count;
106}
107
108static struct bin_attribute sysfs_fw_dump_attr = {
109 .attr = {
110 .name = "fw_dump",
111 .mode = S_IRUSR | S_IWUSR,
112 },
113 .size = 0,
114 .read = qla4_8xxx_sysfs_read_fw_dump,
115 .write = qla4_8xxx_sysfs_write_fw_dump,
116};
117
118static struct sysfs_entry {
119 char *name;
120 struct bin_attribute *attr;
121} bin_file_entries[] = {
122 { "fw_dump", &sysfs_fw_dump_attr },
123 { NULL },
124};
125
126void qla4_8xxx_alloc_sysfs_attr(struct scsi_qla_host *ha)
127{
128 struct Scsi_Host *host = ha->host;
129 struct sysfs_entry *iter;
130 int ret;
131
132 for (iter = bin_file_entries; iter->name; iter++) {
133 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
134 iter->attr);
135 if (ret)
136 ql4_printk(KERN_ERR, ha,
137 "Unable to create sysfs %s binary attribute (%d).\n",
138 iter->name, ret);
139 }
140}
141
142void qla4_8xxx_free_sysfs_attr(struct scsi_qla_host *ha)
143{
144 struct Scsi_Host *host = ha->host;
145 struct sysfs_entry *iter;
146
147 for (iter = bin_file_entries; iter->name; iter++)
148 sysfs_remove_bin_file(&host->shost_gendev.kobj,
149 iter->attr);
150}
151
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -0700152/* Scsi_Host attributes. */
153static ssize_t
154qla4xxx_fw_version_show(struct device *dev,
155 struct device_attribute *attr, char *buf)
156{
157 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
158
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -0400159 if (is_qla80XX(ha))
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -0700160 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
161 ha->firmware_version[0],
162 ha->firmware_version[1],
163 ha->patch_number, ha->build_number);
164 else
165 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d.%02d\n",
166 ha->firmware_version[0],
167 ha->firmware_version[1],
168 ha->patch_number, ha->build_number);
169}
170
171static ssize_t
172qla4xxx_serial_num_show(struct device *dev, struct device_attribute *attr,
173 char *buf)
174{
175 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
176 return snprintf(buf, PAGE_SIZE, "%s\n", ha->serial_number);
177}
178
179static ssize_t
180qla4xxx_iscsi_version_show(struct device *dev, struct device_attribute *attr,
181 char *buf)
182{
183 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
184 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->iscsi_major,
185 ha->iscsi_minor);
186}
187
188static ssize_t
189qla4xxx_optrom_version_show(struct device *dev, struct device_attribute *attr,
190 char *buf)
191{
192 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
193 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d.%02d\n",
194 ha->bootload_major, ha->bootload_minor,
195 ha->bootload_patch, ha->bootload_build);
196}
197
Vikas Chaudhary91ec7ce2011-08-01 03:26:17 -0700198static ssize_t
199qla4xxx_board_id_show(struct device *dev, struct device_attribute *attr,
200 char *buf)
201{
202 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
203 return snprintf(buf, PAGE_SIZE, "0x%08X\n", ha->board_id);
204}
205
206static ssize_t
207qla4xxx_fw_state_show(struct device *dev, struct device_attribute *attr,
208 char *buf)
209{
210 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
211
212 qla4xxx_get_firmware_state(ha);
213 return snprintf(buf, PAGE_SIZE, "0x%08X%8X\n", ha->firmware_state,
214 ha->addl_fw_state);
215}
216
217static ssize_t
218qla4xxx_phy_port_cnt_show(struct device *dev, struct device_attribute *attr,
219 char *buf)
220{
221 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
222
Vikas Chaudharyee996a62012-08-22 07:55:05 -0400223 if (is_qla40XX(ha))
Vikas Chaudhary91ec7ce2011-08-01 03:26:17 -0700224 return -ENOSYS;
225
226 return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_cnt);
227}
228
229static ssize_t
230qla4xxx_phy_port_num_show(struct device *dev, struct device_attribute *attr,
231 char *buf)
232{
233 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
234
Vikas Chaudharyee996a62012-08-22 07:55:05 -0400235 if (is_qla40XX(ha))
Vikas Chaudhary91ec7ce2011-08-01 03:26:17 -0700236 return -ENOSYS;
237
238 return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_num);
239}
240
241static ssize_t
242qla4xxx_iscsi_func_cnt_show(struct device *dev, struct device_attribute *attr,
243 char *buf)
244{
245 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
246
Vikas Chaudharyee996a62012-08-22 07:55:05 -0400247 if (is_qla40XX(ha))
Vikas Chaudhary91ec7ce2011-08-01 03:26:17 -0700248 return -ENOSYS;
249
250 return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->iscsi_pci_func_cnt);
251}
252
253static ssize_t
254qla4xxx_hba_model_show(struct device *dev, struct device_attribute *attr,
255 char *buf)
256{
257 struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
258
259 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_name);
260}
261
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -0700262static DEVICE_ATTR(fw_version, S_IRUGO, qla4xxx_fw_version_show, NULL);
263static DEVICE_ATTR(serial_num, S_IRUGO, qla4xxx_serial_num_show, NULL);
264static DEVICE_ATTR(iscsi_version, S_IRUGO, qla4xxx_iscsi_version_show, NULL);
265static DEVICE_ATTR(optrom_version, S_IRUGO, qla4xxx_optrom_version_show, NULL);
Vikas Chaudhary91ec7ce2011-08-01 03:26:17 -0700266static DEVICE_ATTR(board_id, S_IRUGO, qla4xxx_board_id_show, NULL);
267static DEVICE_ATTR(fw_state, S_IRUGO, qla4xxx_fw_state_show, NULL);
268static DEVICE_ATTR(phy_port_cnt, S_IRUGO, qla4xxx_phy_port_cnt_show, NULL);
269static DEVICE_ATTR(phy_port_num, S_IRUGO, qla4xxx_phy_port_num_show, NULL);
270static DEVICE_ATTR(iscsi_func_cnt, S_IRUGO, qla4xxx_iscsi_func_cnt_show, NULL);
271static DEVICE_ATTR(hba_model, S_IRUGO, qla4xxx_hba_model_show, NULL);
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -0700272
273struct device_attribute *qla4xxx_host_attrs[] = {
274 &dev_attr_fw_version,
275 &dev_attr_serial_num,
276 &dev_attr_iscsi_version,
277 &dev_attr_optrom_version,
Vikas Chaudhary91ec7ce2011-08-01 03:26:17 -0700278 &dev_attr_board_id,
279 &dev_attr_fw_state,
280 &dev_attr_phy_port_cnt,
281 &dev_attr_phy_port_num,
282 &dev_attr_iscsi_func_cnt,
283 &dev_attr_hba_model,
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -0700284 NULL,
285};