1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * QLogic Fibre Channel HBA Driver
4*4882a593Smuzhiyun * Copyright (c) 2003-2014 QLogic Corporation
5*4882a593Smuzhiyun */
6*4882a593Smuzhiyun #include "qla_def.h"
7*4882a593Smuzhiyun #include "qla_target.h"
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include <linux/kthread.h>
10*4882a593Smuzhiyun #include <linux/vmalloc.h>
11*4882a593Smuzhiyun #include <linux/slab.h>
12*4882a593Smuzhiyun #include <linux/delay.h>
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun static int qla24xx_vport_disable(struct fc_vport *, bool);
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun /* SYSFS attributes --------------------------------------------------------- */
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun static ssize_t
qla2x00_sysfs_read_fw_dump(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t off,size_t count)19*4882a593Smuzhiyun qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
20*4882a593Smuzhiyun struct bin_attribute *bin_attr,
21*4882a593Smuzhiyun char *buf, loff_t off, size_t count)
22*4882a593Smuzhiyun {
23*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
24*4882a593Smuzhiyun struct device, kobj)));
25*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
26*4882a593Smuzhiyun int rval = 0;
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun if (!(ha->fw_dump_reading || ha->mctp_dump_reading ||
29*4882a593Smuzhiyun ha->mpi_fw_dump_reading))
30*4882a593Smuzhiyun return 0;
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun mutex_lock(&ha->optrom_mutex);
33*4882a593Smuzhiyun if (IS_P3P_TYPE(ha)) {
34*4882a593Smuzhiyun if (off < ha->md_template_size) {
35*4882a593Smuzhiyun rval = memory_read_from_buffer(buf, count,
36*4882a593Smuzhiyun &off, ha->md_tmplt_hdr, ha->md_template_size);
37*4882a593Smuzhiyun } else {
38*4882a593Smuzhiyun off -= ha->md_template_size;
39*4882a593Smuzhiyun rval = memory_read_from_buffer(buf, count,
40*4882a593Smuzhiyun &off, ha->md_dump, ha->md_dump_size);
41*4882a593Smuzhiyun }
42*4882a593Smuzhiyun } else if (ha->mctp_dumped && ha->mctp_dump_reading) {
43*4882a593Smuzhiyun rval = memory_read_from_buffer(buf, count, &off, ha->mctp_dump,
44*4882a593Smuzhiyun MCTP_DUMP_SIZE);
45*4882a593Smuzhiyun } else if (ha->mpi_fw_dumped && ha->mpi_fw_dump_reading) {
46*4882a593Smuzhiyun rval = memory_read_from_buffer(buf, count, &off,
47*4882a593Smuzhiyun ha->mpi_fw_dump,
48*4882a593Smuzhiyun ha->mpi_fw_dump_len);
49*4882a593Smuzhiyun } else if (ha->fw_dump_reading) {
50*4882a593Smuzhiyun rval = memory_read_from_buffer(buf, count, &off, ha->fw_dump,
51*4882a593Smuzhiyun ha->fw_dump_len);
52*4882a593Smuzhiyun } else {
53*4882a593Smuzhiyun rval = 0;
54*4882a593Smuzhiyun }
55*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
56*4882a593Smuzhiyun return rval;
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun static ssize_t
qla2x00_sysfs_write_fw_dump(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t off,size_t count)60*4882a593Smuzhiyun qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
61*4882a593Smuzhiyun struct bin_attribute *bin_attr,
62*4882a593Smuzhiyun char *buf, loff_t off, size_t count)
63*4882a593Smuzhiyun {
64*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
65*4882a593Smuzhiyun struct device, kobj)));
66*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
67*4882a593Smuzhiyun int reading;
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun if (off != 0)
70*4882a593Smuzhiyun return (0);
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun reading = simple_strtol(buf, NULL, 10);
73*4882a593Smuzhiyun switch (reading) {
74*4882a593Smuzhiyun case 0:
75*4882a593Smuzhiyun if (!ha->fw_dump_reading)
76*4882a593Smuzhiyun break;
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x705d,
79*4882a593Smuzhiyun "Firmware dump cleared on (%ld).\n", vha->host_no);
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun if (IS_P3P_TYPE(ha)) {
82*4882a593Smuzhiyun qla82xx_md_free(vha);
83*4882a593Smuzhiyun qla82xx_md_prep(vha);
84*4882a593Smuzhiyun }
85*4882a593Smuzhiyun ha->fw_dump_reading = 0;
86*4882a593Smuzhiyun ha->fw_dumped = false;
87*4882a593Smuzhiyun break;
88*4882a593Smuzhiyun case 1:
89*4882a593Smuzhiyun if (ha->fw_dumped && !ha->fw_dump_reading) {
90*4882a593Smuzhiyun ha->fw_dump_reading = 1;
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x705e,
93*4882a593Smuzhiyun "Raw firmware dump ready for read on (%ld).\n",
94*4882a593Smuzhiyun vha->host_no);
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun break;
97*4882a593Smuzhiyun case 2:
98*4882a593Smuzhiyun qla2x00_alloc_fw_dump(vha);
99*4882a593Smuzhiyun break;
100*4882a593Smuzhiyun case 3:
101*4882a593Smuzhiyun if (IS_QLA82XX(ha)) {
102*4882a593Smuzhiyun qla82xx_idc_lock(ha);
103*4882a593Smuzhiyun qla82xx_set_reset_owner(vha);
104*4882a593Smuzhiyun qla82xx_idc_unlock(ha);
105*4882a593Smuzhiyun } else if (IS_QLA8044(ha)) {
106*4882a593Smuzhiyun qla8044_idc_lock(ha);
107*4882a593Smuzhiyun qla82xx_set_reset_owner(vha);
108*4882a593Smuzhiyun qla8044_idc_unlock(ha);
109*4882a593Smuzhiyun } else {
110*4882a593Smuzhiyun qla2x00_system_error(vha);
111*4882a593Smuzhiyun }
112*4882a593Smuzhiyun break;
113*4882a593Smuzhiyun case 4:
114*4882a593Smuzhiyun if (IS_P3P_TYPE(ha)) {
115*4882a593Smuzhiyun if (ha->md_tmplt_hdr)
116*4882a593Smuzhiyun ql_dbg(ql_dbg_user, vha, 0x705b,
117*4882a593Smuzhiyun "MiniDump supported with this firmware.\n");
118*4882a593Smuzhiyun else
119*4882a593Smuzhiyun ql_dbg(ql_dbg_user, vha, 0x709d,
120*4882a593Smuzhiyun "MiniDump not supported with this firmware.\n");
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun break;
123*4882a593Smuzhiyun case 5:
124*4882a593Smuzhiyun if (IS_P3P_TYPE(ha))
125*4882a593Smuzhiyun set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
126*4882a593Smuzhiyun break;
127*4882a593Smuzhiyun case 6:
128*4882a593Smuzhiyun if (!ha->mctp_dump_reading)
129*4882a593Smuzhiyun break;
130*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x70c1,
131*4882a593Smuzhiyun "MCTP dump cleared on (%ld).\n", vha->host_no);
132*4882a593Smuzhiyun ha->mctp_dump_reading = 0;
133*4882a593Smuzhiyun ha->mctp_dumped = 0;
134*4882a593Smuzhiyun break;
135*4882a593Smuzhiyun case 7:
136*4882a593Smuzhiyun if (ha->mctp_dumped && !ha->mctp_dump_reading) {
137*4882a593Smuzhiyun ha->mctp_dump_reading = 1;
138*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x70c2,
139*4882a593Smuzhiyun "Raw mctp dump ready for read on (%ld).\n",
140*4882a593Smuzhiyun vha->host_no);
141*4882a593Smuzhiyun }
142*4882a593Smuzhiyun break;
143*4882a593Smuzhiyun case 8:
144*4882a593Smuzhiyun if (!ha->mpi_fw_dump_reading)
145*4882a593Smuzhiyun break;
146*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x70e7,
147*4882a593Smuzhiyun "MPI firmware dump cleared on (%ld).\n", vha->host_no);
148*4882a593Smuzhiyun ha->mpi_fw_dump_reading = 0;
149*4882a593Smuzhiyun ha->mpi_fw_dumped = 0;
150*4882a593Smuzhiyun break;
151*4882a593Smuzhiyun case 9:
152*4882a593Smuzhiyun if (ha->mpi_fw_dumped && !ha->mpi_fw_dump_reading) {
153*4882a593Smuzhiyun ha->mpi_fw_dump_reading = 1;
154*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x70e8,
155*4882a593Smuzhiyun "Raw MPI firmware dump ready for read on (%ld).\n",
156*4882a593Smuzhiyun vha->host_no);
157*4882a593Smuzhiyun }
158*4882a593Smuzhiyun break;
159*4882a593Smuzhiyun case 10:
160*4882a593Smuzhiyun if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
161*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x70e9,
162*4882a593Smuzhiyun "Issuing MPI firmware dump on host#%ld.\n",
163*4882a593Smuzhiyun vha->host_no);
164*4882a593Smuzhiyun ha->isp_ops->mpi_fw_dump(vha, 0);
165*4882a593Smuzhiyun }
166*4882a593Smuzhiyun break;
167*4882a593Smuzhiyun }
168*4882a593Smuzhiyun return count;
169*4882a593Smuzhiyun }
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun static struct bin_attribute sysfs_fw_dump_attr = {
172*4882a593Smuzhiyun .attr = {
173*4882a593Smuzhiyun .name = "fw_dump",
174*4882a593Smuzhiyun .mode = S_IRUSR | S_IWUSR,
175*4882a593Smuzhiyun },
176*4882a593Smuzhiyun .size = 0,
177*4882a593Smuzhiyun .read = qla2x00_sysfs_read_fw_dump,
178*4882a593Smuzhiyun .write = qla2x00_sysfs_write_fw_dump,
179*4882a593Smuzhiyun };
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun static ssize_t
qla2x00_sysfs_read_nvram(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t off,size_t count)182*4882a593Smuzhiyun qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
183*4882a593Smuzhiyun struct bin_attribute *bin_attr,
184*4882a593Smuzhiyun char *buf, loff_t off, size_t count)
185*4882a593Smuzhiyun {
186*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
187*4882a593Smuzhiyun struct device, kobj)));
188*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
189*4882a593Smuzhiyun uint32_t faddr;
190*4882a593Smuzhiyun struct active_regions active_regions = { };
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun if (!capable(CAP_SYS_ADMIN))
193*4882a593Smuzhiyun return 0;
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun mutex_lock(&ha->optrom_mutex);
196*4882a593Smuzhiyun if (qla2x00_chip_is_down(vha)) {
197*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
198*4882a593Smuzhiyun return -EAGAIN;
199*4882a593Smuzhiyun }
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun if (!IS_NOCACHE_VPD_TYPE(ha)) {
202*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
203*4882a593Smuzhiyun goto skip;
204*4882a593Smuzhiyun }
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun faddr = ha->flt_region_nvram;
207*4882a593Smuzhiyun if (IS_QLA28XX(ha)) {
208*4882a593Smuzhiyun qla28xx_get_aux_images(vha, &active_regions);
209*4882a593Smuzhiyun if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
210*4882a593Smuzhiyun faddr = ha->flt_region_nvram_sec;
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun skip:
217*4882a593Smuzhiyun return memory_read_from_buffer(buf, count, &off, ha->nvram,
218*4882a593Smuzhiyun ha->nvram_size);
219*4882a593Smuzhiyun }
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun static ssize_t
qla2x00_sysfs_write_nvram(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t off,size_t count)222*4882a593Smuzhiyun qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
223*4882a593Smuzhiyun struct bin_attribute *bin_attr,
224*4882a593Smuzhiyun char *buf, loff_t off, size_t count)
225*4882a593Smuzhiyun {
226*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
227*4882a593Smuzhiyun struct device, kobj)));
228*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
229*4882a593Smuzhiyun uint16_t cnt;
230*4882a593Smuzhiyun
231*4882a593Smuzhiyun if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
232*4882a593Smuzhiyun !ha->isp_ops->write_nvram)
233*4882a593Smuzhiyun return -EINVAL;
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun /* Checksum NVRAM. */
236*4882a593Smuzhiyun if (IS_FWI2_CAPABLE(ha)) {
237*4882a593Smuzhiyun __le32 *iter = (__force __le32 *)buf;
238*4882a593Smuzhiyun uint32_t chksum;
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun chksum = 0;
241*4882a593Smuzhiyun for (cnt = 0; cnt < ((count >> 2) - 1); cnt++, iter++)
242*4882a593Smuzhiyun chksum += le32_to_cpu(*iter);
243*4882a593Smuzhiyun chksum = ~chksum + 1;
244*4882a593Smuzhiyun *iter = cpu_to_le32(chksum);
245*4882a593Smuzhiyun } else {
246*4882a593Smuzhiyun uint8_t *iter;
247*4882a593Smuzhiyun uint8_t chksum;
248*4882a593Smuzhiyun
249*4882a593Smuzhiyun iter = (uint8_t *)buf;
250*4882a593Smuzhiyun chksum = 0;
251*4882a593Smuzhiyun for (cnt = 0; cnt < count - 1; cnt++)
252*4882a593Smuzhiyun chksum += *iter++;
253*4882a593Smuzhiyun chksum = ~chksum + 1;
254*4882a593Smuzhiyun *iter = chksum;
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
258*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x705f,
259*4882a593Smuzhiyun "HBA not online, failing NVRAM update.\n");
260*4882a593Smuzhiyun return -EAGAIN;
261*4882a593Smuzhiyun }
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun mutex_lock(&ha->optrom_mutex);
264*4882a593Smuzhiyun if (qla2x00_chip_is_down(vha)) {
265*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
266*4882a593Smuzhiyun return -EAGAIN;
267*4882a593Smuzhiyun }
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun /* Write NVRAM. */
270*4882a593Smuzhiyun ha->isp_ops->write_nvram(vha, buf, ha->nvram_base, count);
271*4882a593Smuzhiyun ha->isp_ops->read_nvram(vha, ha->nvram, ha->nvram_base,
272*4882a593Smuzhiyun count);
273*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun ql_dbg(ql_dbg_user, vha, 0x7060,
276*4882a593Smuzhiyun "Setting ISP_ABORT_NEEDED\n");
277*4882a593Smuzhiyun /* NVRAM settings take effect immediately. */
278*4882a593Smuzhiyun set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
279*4882a593Smuzhiyun qla2xxx_wake_dpc(vha);
280*4882a593Smuzhiyun qla2x00_wait_for_chip_reset(vha);
281*4882a593Smuzhiyun
282*4882a593Smuzhiyun return count;
283*4882a593Smuzhiyun }
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun static struct bin_attribute sysfs_nvram_attr = {
286*4882a593Smuzhiyun .attr = {
287*4882a593Smuzhiyun .name = "nvram",
288*4882a593Smuzhiyun .mode = S_IRUSR | S_IWUSR,
289*4882a593Smuzhiyun },
290*4882a593Smuzhiyun .size = 512,
291*4882a593Smuzhiyun .read = qla2x00_sysfs_read_nvram,
292*4882a593Smuzhiyun .write = qla2x00_sysfs_write_nvram,
293*4882a593Smuzhiyun };
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun static ssize_t
qla2x00_sysfs_read_optrom(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t off,size_t count)296*4882a593Smuzhiyun qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
297*4882a593Smuzhiyun struct bin_attribute *bin_attr,
298*4882a593Smuzhiyun char *buf, loff_t off, size_t count)
299*4882a593Smuzhiyun {
300*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
301*4882a593Smuzhiyun struct device, kobj)));
302*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
303*4882a593Smuzhiyun ssize_t rval = 0;
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun mutex_lock(&ha->optrom_mutex);
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun if (ha->optrom_state != QLA_SREADING)
308*4882a593Smuzhiyun goto out;
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun rval = memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
311*4882a593Smuzhiyun ha->optrom_region_size);
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun out:
314*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun return rval;
317*4882a593Smuzhiyun }
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun static ssize_t
qla2x00_sysfs_write_optrom(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t off,size_t count)320*4882a593Smuzhiyun qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
321*4882a593Smuzhiyun struct bin_attribute *bin_attr,
322*4882a593Smuzhiyun char *buf, loff_t off, size_t count)
323*4882a593Smuzhiyun {
324*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
325*4882a593Smuzhiyun struct device, kobj)));
326*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
327*4882a593Smuzhiyun
328*4882a593Smuzhiyun mutex_lock(&ha->optrom_mutex);
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun if (ha->optrom_state != QLA_SWRITING) {
331*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
332*4882a593Smuzhiyun return -EINVAL;
333*4882a593Smuzhiyun }
334*4882a593Smuzhiyun if (off > ha->optrom_region_size) {
335*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
336*4882a593Smuzhiyun return -ERANGE;
337*4882a593Smuzhiyun }
338*4882a593Smuzhiyun if (off + count > ha->optrom_region_size)
339*4882a593Smuzhiyun count = ha->optrom_region_size - off;
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun memcpy(&ha->optrom_buffer[off], buf, count);
342*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun return count;
345*4882a593Smuzhiyun }
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun static struct bin_attribute sysfs_optrom_attr = {
348*4882a593Smuzhiyun .attr = {
349*4882a593Smuzhiyun .name = "optrom",
350*4882a593Smuzhiyun .mode = S_IRUSR | S_IWUSR,
351*4882a593Smuzhiyun },
352*4882a593Smuzhiyun .size = 0,
353*4882a593Smuzhiyun .read = qla2x00_sysfs_read_optrom,
354*4882a593Smuzhiyun .write = qla2x00_sysfs_write_optrom,
355*4882a593Smuzhiyun };
356*4882a593Smuzhiyun
357*4882a593Smuzhiyun static ssize_t
qla2x00_sysfs_write_optrom_ctl(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t off,size_t count)358*4882a593Smuzhiyun qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
359*4882a593Smuzhiyun struct bin_attribute *bin_attr,
360*4882a593Smuzhiyun char *buf, loff_t off, size_t count)
361*4882a593Smuzhiyun {
362*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
363*4882a593Smuzhiyun struct device, kobj)));
364*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
365*4882a593Smuzhiyun uint32_t start = 0;
366*4882a593Smuzhiyun uint32_t size = ha->optrom_size;
367*4882a593Smuzhiyun int val, valid;
368*4882a593Smuzhiyun ssize_t rval = count;
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun if (off)
371*4882a593Smuzhiyun return -EINVAL;
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun if (unlikely(pci_channel_offline(ha->pdev)))
374*4882a593Smuzhiyun return -EAGAIN;
375*4882a593Smuzhiyun
376*4882a593Smuzhiyun if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
377*4882a593Smuzhiyun return -EINVAL;
378*4882a593Smuzhiyun if (start > ha->optrom_size)
379*4882a593Smuzhiyun return -EINVAL;
380*4882a593Smuzhiyun if (size > ha->optrom_size - start)
381*4882a593Smuzhiyun size = ha->optrom_size - start;
382*4882a593Smuzhiyun
383*4882a593Smuzhiyun mutex_lock(&ha->optrom_mutex);
384*4882a593Smuzhiyun if (qla2x00_chip_is_down(vha)) {
385*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
386*4882a593Smuzhiyun return -EAGAIN;
387*4882a593Smuzhiyun }
388*4882a593Smuzhiyun switch (val) {
389*4882a593Smuzhiyun case 0:
390*4882a593Smuzhiyun if (ha->optrom_state != QLA_SREADING &&
391*4882a593Smuzhiyun ha->optrom_state != QLA_SWRITING) {
392*4882a593Smuzhiyun rval = -EINVAL;
393*4882a593Smuzhiyun goto out;
394*4882a593Smuzhiyun }
395*4882a593Smuzhiyun ha->optrom_state = QLA_SWAITING;
396*4882a593Smuzhiyun
397*4882a593Smuzhiyun ql_dbg(ql_dbg_user, vha, 0x7061,
398*4882a593Smuzhiyun "Freeing flash region allocation -- 0x%x bytes.\n",
399*4882a593Smuzhiyun ha->optrom_region_size);
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun vfree(ha->optrom_buffer);
402*4882a593Smuzhiyun ha->optrom_buffer = NULL;
403*4882a593Smuzhiyun break;
404*4882a593Smuzhiyun case 1:
405*4882a593Smuzhiyun if (ha->optrom_state != QLA_SWAITING) {
406*4882a593Smuzhiyun rval = -EINVAL;
407*4882a593Smuzhiyun goto out;
408*4882a593Smuzhiyun }
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun ha->optrom_region_start = start;
411*4882a593Smuzhiyun ha->optrom_region_size = size;
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun ha->optrom_state = QLA_SREADING;
414*4882a593Smuzhiyun ha->optrom_buffer = vzalloc(ha->optrom_region_size);
415*4882a593Smuzhiyun if (ha->optrom_buffer == NULL) {
416*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x7062,
417*4882a593Smuzhiyun "Unable to allocate memory for optrom retrieval "
418*4882a593Smuzhiyun "(%x).\n", ha->optrom_region_size);
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun ha->optrom_state = QLA_SWAITING;
421*4882a593Smuzhiyun rval = -ENOMEM;
422*4882a593Smuzhiyun goto out;
423*4882a593Smuzhiyun }
424*4882a593Smuzhiyun
425*4882a593Smuzhiyun if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
426*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x7063,
427*4882a593Smuzhiyun "HBA not online, failing NVRAM update.\n");
428*4882a593Smuzhiyun rval = -EAGAIN;
429*4882a593Smuzhiyun goto out;
430*4882a593Smuzhiyun }
431*4882a593Smuzhiyun
432*4882a593Smuzhiyun ql_dbg(ql_dbg_user, vha, 0x7064,
433*4882a593Smuzhiyun "Reading flash region -- 0x%x/0x%x.\n",
434*4882a593Smuzhiyun ha->optrom_region_start, ha->optrom_region_size);
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
437*4882a593Smuzhiyun ha->optrom_region_start, ha->optrom_region_size);
438*4882a593Smuzhiyun break;
439*4882a593Smuzhiyun case 2:
440*4882a593Smuzhiyun if (ha->optrom_state != QLA_SWAITING) {
441*4882a593Smuzhiyun rval = -EINVAL;
442*4882a593Smuzhiyun goto out;
443*4882a593Smuzhiyun }
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun /*
446*4882a593Smuzhiyun * We need to be more restrictive on which FLASH regions are
447*4882a593Smuzhiyun * allowed to be updated via user-space. Regions accessible
448*4882a593Smuzhiyun * via this method include:
449*4882a593Smuzhiyun *
450*4882a593Smuzhiyun * ISP21xx/ISP22xx/ISP23xx type boards:
451*4882a593Smuzhiyun *
452*4882a593Smuzhiyun * 0x000000 -> 0x020000 -- Boot code.
453*4882a593Smuzhiyun *
454*4882a593Smuzhiyun * ISP2322/ISP24xx type boards:
455*4882a593Smuzhiyun *
456*4882a593Smuzhiyun * 0x000000 -> 0x07ffff -- Boot code.
457*4882a593Smuzhiyun * 0x080000 -> 0x0fffff -- Firmware.
458*4882a593Smuzhiyun *
459*4882a593Smuzhiyun * ISP25xx type boards:
460*4882a593Smuzhiyun *
461*4882a593Smuzhiyun * 0x000000 -> 0x07ffff -- Boot code.
462*4882a593Smuzhiyun * 0x080000 -> 0x0fffff -- Firmware.
463*4882a593Smuzhiyun * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
464*4882a593Smuzhiyun *
465*4882a593Smuzhiyun * > ISP25xx type boards:
466*4882a593Smuzhiyun *
467*4882a593Smuzhiyun * None -- should go through BSG.
468*4882a593Smuzhiyun */
469*4882a593Smuzhiyun valid = 0;
470*4882a593Smuzhiyun if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
471*4882a593Smuzhiyun valid = 1;
472*4882a593Smuzhiyun else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
473*4882a593Smuzhiyun valid = 1;
474*4882a593Smuzhiyun if (!valid) {
475*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x7065,
476*4882a593Smuzhiyun "Invalid start region 0x%x/0x%x.\n", start, size);
477*4882a593Smuzhiyun rval = -EINVAL;
478*4882a593Smuzhiyun goto out;
479*4882a593Smuzhiyun }
480*4882a593Smuzhiyun
481*4882a593Smuzhiyun ha->optrom_region_start = start;
482*4882a593Smuzhiyun ha->optrom_region_size = size;
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun ha->optrom_state = QLA_SWRITING;
485*4882a593Smuzhiyun ha->optrom_buffer = vzalloc(ha->optrom_region_size);
486*4882a593Smuzhiyun if (ha->optrom_buffer == NULL) {
487*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x7066,
488*4882a593Smuzhiyun "Unable to allocate memory for optrom update "
489*4882a593Smuzhiyun "(%x)\n", ha->optrom_region_size);
490*4882a593Smuzhiyun
491*4882a593Smuzhiyun ha->optrom_state = QLA_SWAITING;
492*4882a593Smuzhiyun rval = -ENOMEM;
493*4882a593Smuzhiyun goto out;
494*4882a593Smuzhiyun }
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun ql_dbg(ql_dbg_user, vha, 0x7067,
497*4882a593Smuzhiyun "Staging flash region write -- 0x%x/0x%x.\n",
498*4882a593Smuzhiyun ha->optrom_region_start, ha->optrom_region_size);
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun break;
501*4882a593Smuzhiyun case 3:
502*4882a593Smuzhiyun if (ha->optrom_state != QLA_SWRITING) {
503*4882a593Smuzhiyun rval = -EINVAL;
504*4882a593Smuzhiyun goto out;
505*4882a593Smuzhiyun }
506*4882a593Smuzhiyun
507*4882a593Smuzhiyun if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
508*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x7068,
509*4882a593Smuzhiyun "HBA not online, failing flash update.\n");
510*4882a593Smuzhiyun rval = -EAGAIN;
511*4882a593Smuzhiyun goto out;
512*4882a593Smuzhiyun }
513*4882a593Smuzhiyun
514*4882a593Smuzhiyun ql_dbg(ql_dbg_user, vha, 0x7069,
515*4882a593Smuzhiyun "Writing flash region -- 0x%x/0x%x.\n",
516*4882a593Smuzhiyun ha->optrom_region_start, ha->optrom_region_size);
517*4882a593Smuzhiyun
518*4882a593Smuzhiyun rval = ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
519*4882a593Smuzhiyun ha->optrom_region_start, ha->optrom_region_size);
520*4882a593Smuzhiyun if (rval)
521*4882a593Smuzhiyun rval = -EIO;
522*4882a593Smuzhiyun break;
523*4882a593Smuzhiyun default:
524*4882a593Smuzhiyun rval = -EINVAL;
525*4882a593Smuzhiyun }
526*4882a593Smuzhiyun
527*4882a593Smuzhiyun out:
528*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
529*4882a593Smuzhiyun return rval;
530*4882a593Smuzhiyun }
531*4882a593Smuzhiyun
532*4882a593Smuzhiyun static struct bin_attribute sysfs_optrom_ctl_attr = {
533*4882a593Smuzhiyun .attr = {
534*4882a593Smuzhiyun .name = "optrom_ctl",
535*4882a593Smuzhiyun .mode = S_IWUSR,
536*4882a593Smuzhiyun },
537*4882a593Smuzhiyun .size = 0,
538*4882a593Smuzhiyun .write = qla2x00_sysfs_write_optrom_ctl,
539*4882a593Smuzhiyun };
540*4882a593Smuzhiyun
541*4882a593Smuzhiyun static ssize_t
qla2x00_sysfs_read_vpd(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t off,size_t count)542*4882a593Smuzhiyun qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
543*4882a593Smuzhiyun struct bin_attribute *bin_attr,
544*4882a593Smuzhiyun char *buf, loff_t off, size_t count)
545*4882a593Smuzhiyun {
546*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
547*4882a593Smuzhiyun struct device, kobj)));
548*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
549*4882a593Smuzhiyun uint32_t faddr;
550*4882a593Smuzhiyun struct active_regions active_regions = { };
551*4882a593Smuzhiyun
552*4882a593Smuzhiyun if (unlikely(pci_channel_offline(ha->pdev)))
553*4882a593Smuzhiyun return -EAGAIN;
554*4882a593Smuzhiyun
555*4882a593Smuzhiyun if (!capable(CAP_SYS_ADMIN))
556*4882a593Smuzhiyun return -EINVAL;
557*4882a593Smuzhiyun
558*4882a593Smuzhiyun if (!IS_NOCACHE_VPD_TYPE(ha))
559*4882a593Smuzhiyun goto skip;
560*4882a593Smuzhiyun
561*4882a593Smuzhiyun faddr = ha->flt_region_vpd << 2;
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun if (IS_QLA28XX(ha)) {
564*4882a593Smuzhiyun qla28xx_get_aux_images(vha, &active_regions);
565*4882a593Smuzhiyun if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
566*4882a593Smuzhiyun faddr = ha->flt_region_vpd_sec << 2;
567*4882a593Smuzhiyun
568*4882a593Smuzhiyun ql_dbg(ql_dbg_init, vha, 0x7070,
569*4882a593Smuzhiyun "Loading %s nvram image.\n",
570*4882a593Smuzhiyun active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
571*4882a593Smuzhiyun "primary" : "secondary");
572*4882a593Smuzhiyun }
573*4882a593Smuzhiyun
574*4882a593Smuzhiyun mutex_lock(&ha->optrom_mutex);
575*4882a593Smuzhiyun if (qla2x00_chip_is_down(vha)) {
576*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
577*4882a593Smuzhiyun return -EAGAIN;
578*4882a593Smuzhiyun }
579*4882a593Smuzhiyun
580*4882a593Smuzhiyun ha->isp_ops->read_optrom(vha, ha->vpd, faddr, ha->vpd_size);
581*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
582*4882a593Smuzhiyun
583*4882a593Smuzhiyun ha->isp_ops->read_optrom(vha, ha->vpd, faddr, ha->vpd_size);
584*4882a593Smuzhiyun skip:
585*4882a593Smuzhiyun return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
586*4882a593Smuzhiyun }
587*4882a593Smuzhiyun
588*4882a593Smuzhiyun static ssize_t
qla2x00_sysfs_write_vpd(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t off,size_t count)589*4882a593Smuzhiyun qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
590*4882a593Smuzhiyun struct bin_attribute *bin_attr,
591*4882a593Smuzhiyun char *buf, loff_t off, size_t count)
592*4882a593Smuzhiyun {
593*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
594*4882a593Smuzhiyun struct device, kobj)));
595*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
596*4882a593Smuzhiyun uint8_t *tmp_data;
597*4882a593Smuzhiyun
598*4882a593Smuzhiyun if (unlikely(pci_channel_offline(ha->pdev)))
599*4882a593Smuzhiyun return 0;
600*4882a593Smuzhiyun
601*4882a593Smuzhiyun if (qla2x00_chip_is_down(vha))
602*4882a593Smuzhiyun return 0;
603*4882a593Smuzhiyun
604*4882a593Smuzhiyun if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
605*4882a593Smuzhiyun !ha->isp_ops->write_nvram)
606*4882a593Smuzhiyun return 0;
607*4882a593Smuzhiyun
608*4882a593Smuzhiyun if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
609*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x706a,
610*4882a593Smuzhiyun "HBA not online, failing VPD update.\n");
611*4882a593Smuzhiyun return -EAGAIN;
612*4882a593Smuzhiyun }
613*4882a593Smuzhiyun
614*4882a593Smuzhiyun mutex_lock(&ha->optrom_mutex);
615*4882a593Smuzhiyun if (qla2x00_chip_is_down(vha)) {
616*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
617*4882a593Smuzhiyun return -EAGAIN;
618*4882a593Smuzhiyun }
619*4882a593Smuzhiyun
620*4882a593Smuzhiyun /* Write NVRAM. */
621*4882a593Smuzhiyun ha->isp_ops->write_nvram(vha, buf, ha->vpd_base, count);
622*4882a593Smuzhiyun ha->isp_ops->read_nvram(vha, ha->vpd, ha->vpd_base, count);
623*4882a593Smuzhiyun
624*4882a593Smuzhiyun /* Update flash version information for 4Gb & above. */
625*4882a593Smuzhiyun if (!IS_FWI2_CAPABLE(ha)) {
626*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
627*4882a593Smuzhiyun return -EINVAL;
628*4882a593Smuzhiyun }
629*4882a593Smuzhiyun
630*4882a593Smuzhiyun tmp_data = vmalloc(256);
631*4882a593Smuzhiyun if (!tmp_data) {
632*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
633*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x706b,
634*4882a593Smuzhiyun "Unable to allocate memory for VPD information update.\n");
635*4882a593Smuzhiyun return -ENOMEM;
636*4882a593Smuzhiyun }
637*4882a593Smuzhiyun ha->isp_ops->get_flash_version(vha, tmp_data);
638*4882a593Smuzhiyun vfree(tmp_data);
639*4882a593Smuzhiyun
640*4882a593Smuzhiyun mutex_unlock(&ha->optrom_mutex);
641*4882a593Smuzhiyun
642*4882a593Smuzhiyun return count;
643*4882a593Smuzhiyun }
644*4882a593Smuzhiyun
645*4882a593Smuzhiyun static struct bin_attribute sysfs_vpd_attr = {
646*4882a593Smuzhiyun .attr = {
647*4882a593Smuzhiyun .name = "vpd",
648*4882a593Smuzhiyun .mode = S_IRUSR | S_IWUSR,
649*4882a593Smuzhiyun },
650*4882a593Smuzhiyun .size = 0,
651*4882a593Smuzhiyun .read = qla2x00_sysfs_read_vpd,
652*4882a593Smuzhiyun .write = qla2x00_sysfs_write_vpd,
653*4882a593Smuzhiyun };
654*4882a593Smuzhiyun
655*4882a593Smuzhiyun static ssize_t
qla2x00_sysfs_read_sfp(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t off,size_t count)656*4882a593Smuzhiyun qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
657*4882a593Smuzhiyun struct bin_attribute *bin_attr,
658*4882a593Smuzhiyun char *buf, loff_t off, size_t count)
659*4882a593Smuzhiyun {
660*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
661*4882a593Smuzhiyun struct device, kobj)));
662*4882a593Smuzhiyun int rval;
663*4882a593Smuzhiyun
664*4882a593Smuzhiyun if (!capable(CAP_SYS_ADMIN) || off != 0 || count < SFP_DEV_SIZE)
665*4882a593Smuzhiyun return 0;
666*4882a593Smuzhiyun
667*4882a593Smuzhiyun mutex_lock(&vha->hw->optrom_mutex);
668*4882a593Smuzhiyun if (qla2x00_chip_is_down(vha)) {
669*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
670*4882a593Smuzhiyun return 0;
671*4882a593Smuzhiyun }
672*4882a593Smuzhiyun
673*4882a593Smuzhiyun rval = qla2x00_read_sfp_dev(vha, buf, count);
674*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
675*4882a593Smuzhiyun
676*4882a593Smuzhiyun if (rval)
677*4882a593Smuzhiyun return -EIO;
678*4882a593Smuzhiyun
679*4882a593Smuzhiyun return count;
680*4882a593Smuzhiyun }
681*4882a593Smuzhiyun
682*4882a593Smuzhiyun static struct bin_attribute sysfs_sfp_attr = {
683*4882a593Smuzhiyun .attr = {
684*4882a593Smuzhiyun .name = "sfp",
685*4882a593Smuzhiyun .mode = S_IRUSR | S_IWUSR,
686*4882a593Smuzhiyun },
687*4882a593Smuzhiyun .size = SFP_DEV_SIZE,
688*4882a593Smuzhiyun .read = qla2x00_sysfs_read_sfp,
689*4882a593Smuzhiyun };
690*4882a593Smuzhiyun
691*4882a593Smuzhiyun static ssize_t
qla2x00_sysfs_write_reset(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t off,size_t count)692*4882a593Smuzhiyun qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
693*4882a593Smuzhiyun struct bin_attribute *bin_attr,
694*4882a593Smuzhiyun char *buf, loff_t off, size_t count)
695*4882a593Smuzhiyun {
696*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
697*4882a593Smuzhiyun struct device, kobj)));
698*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
699*4882a593Smuzhiyun struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
700*4882a593Smuzhiyun int type;
701*4882a593Smuzhiyun uint32_t idc_control;
702*4882a593Smuzhiyun uint8_t *tmp_data = NULL;
703*4882a593Smuzhiyun
704*4882a593Smuzhiyun if (off != 0)
705*4882a593Smuzhiyun return -EINVAL;
706*4882a593Smuzhiyun
707*4882a593Smuzhiyun type = simple_strtol(buf, NULL, 10);
708*4882a593Smuzhiyun switch (type) {
709*4882a593Smuzhiyun case 0x2025c:
710*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x706e,
711*4882a593Smuzhiyun "Issuing ISP reset.\n");
712*4882a593Smuzhiyun
713*4882a593Smuzhiyun scsi_block_requests(vha->host);
714*4882a593Smuzhiyun if (IS_QLA82XX(ha)) {
715*4882a593Smuzhiyun ha->flags.isp82xx_no_md_cap = 1;
716*4882a593Smuzhiyun qla82xx_idc_lock(ha);
717*4882a593Smuzhiyun qla82xx_set_reset_owner(vha);
718*4882a593Smuzhiyun qla82xx_idc_unlock(ha);
719*4882a593Smuzhiyun } else if (IS_QLA8044(ha)) {
720*4882a593Smuzhiyun qla8044_idc_lock(ha);
721*4882a593Smuzhiyun idc_control = qla8044_rd_reg(ha,
722*4882a593Smuzhiyun QLA8044_IDC_DRV_CTRL);
723*4882a593Smuzhiyun qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL,
724*4882a593Smuzhiyun (idc_control | GRACEFUL_RESET_BIT1));
725*4882a593Smuzhiyun qla82xx_set_reset_owner(vha);
726*4882a593Smuzhiyun qla8044_idc_unlock(ha);
727*4882a593Smuzhiyun } else {
728*4882a593Smuzhiyun set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
729*4882a593Smuzhiyun qla2xxx_wake_dpc(vha);
730*4882a593Smuzhiyun }
731*4882a593Smuzhiyun qla2x00_wait_for_chip_reset(vha);
732*4882a593Smuzhiyun scsi_unblock_requests(vha->host);
733*4882a593Smuzhiyun break;
734*4882a593Smuzhiyun case 0x2025d:
735*4882a593Smuzhiyun if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
736*4882a593Smuzhiyun !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
737*4882a593Smuzhiyun return -EPERM;
738*4882a593Smuzhiyun
739*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x706f,
740*4882a593Smuzhiyun "Issuing MPI reset.\n");
741*4882a593Smuzhiyun
742*4882a593Smuzhiyun if (IS_QLA83XX(ha)) {
743*4882a593Smuzhiyun uint32_t idc_control;
744*4882a593Smuzhiyun
745*4882a593Smuzhiyun qla83xx_idc_lock(vha, 0);
746*4882a593Smuzhiyun __qla83xx_get_idc_control(vha, &idc_control);
747*4882a593Smuzhiyun idc_control |= QLA83XX_IDC_GRACEFUL_RESET;
748*4882a593Smuzhiyun __qla83xx_set_idc_control(vha, idc_control);
749*4882a593Smuzhiyun qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
750*4882a593Smuzhiyun QLA8XXX_DEV_NEED_RESET);
751*4882a593Smuzhiyun qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
752*4882a593Smuzhiyun qla83xx_idc_unlock(vha, 0);
753*4882a593Smuzhiyun break;
754*4882a593Smuzhiyun } else {
755*4882a593Smuzhiyun /* Make sure FC side is not in reset */
756*4882a593Smuzhiyun WARN_ON_ONCE(qla2x00_wait_for_hba_online(vha) !=
757*4882a593Smuzhiyun QLA_SUCCESS);
758*4882a593Smuzhiyun
759*4882a593Smuzhiyun /* Issue MPI reset */
760*4882a593Smuzhiyun scsi_block_requests(vha->host);
761*4882a593Smuzhiyun if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
762*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x7070,
763*4882a593Smuzhiyun "MPI reset failed.\n");
764*4882a593Smuzhiyun scsi_unblock_requests(vha->host);
765*4882a593Smuzhiyun break;
766*4882a593Smuzhiyun }
767*4882a593Smuzhiyun break;
768*4882a593Smuzhiyun case 0x2025e:
769*4882a593Smuzhiyun if (!IS_P3P_TYPE(ha) || vha != base_vha) {
770*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x7071,
771*4882a593Smuzhiyun "FCoE ctx reset not supported.\n");
772*4882a593Smuzhiyun return -EPERM;
773*4882a593Smuzhiyun }
774*4882a593Smuzhiyun
775*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x7072,
776*4882a593Smuzhiyun "Issuing FCoE ctx reset.\n");
777*4882a593Smuzhiyun set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
778*4882a593Smuzhiyun qla2xxx_wake_dpc(vha);
779*4882a593Smuzhiyun qla2x00_wait_for_fcoe_ctx_reset(vha);
780*4882a593Smuzhiyun break;
781*4882a593Smuzhiyun case 0x2025f:
782*4882a593Smuzhiyun if (!IS_QLA8031(ha))
783*4882a593Smuzhiyun return -EPERM;
784*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x70bc,
785*4882a593Smuzhiyun "Disabling Reset by IDC control\n");
786*4882a593Smuzhiyun qla83xx_idc_lock(vha, 0);
787*4882a593Smuzhiyun __qla83xx_get_idc_control(vha, &idc_control);
788*4882a593Smuzhiyun idc_control |= QLA83XX_IDC_RESET_DISABLED;
789*4882a593Smuzhiyun __qla83xx_set_idc_control(vha, idc_control);
790*4882a593Smuzhiyun qla83xx_idc_unlock(vha, 0);
791*4882a593Smuzhiyun break;
792*4882a593Smuzhiyun case 0x20260:
793*4882a593Smuzhiyun if (!IS_QLA8031(ha))
794*4882a593Smuzhiyun return -EPERM;
795*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x70bd,
796*4882a593Smuzhiyun "Enabling Reset by IDC control\n");
797*4882a593Smuzhiyun qla83xx_idc_lock(vha, 0);
798*4882a593Smuzhiyun __qla83xx_get_idc_control(vha, &idc_control);
799*4882a593Smuzhiyun idc_control &= ~QLA83XX_IDC_RESET_DISABLED;
800*4882a593Smuzhiyun __qla83xx_set_idc_control(vha, idc_control);
801*4882a593Smuzhiyun qla83xx_idc_unlock(vha, 0);
802*4882a593Smuzhiyun break;
803*4882a593Smuzhiyun case 0x20261:
804*4882a593Smuzhiyun ql_dbg(ql_dbg_user, vha, 0x70e0,
805*4882a593Smuzhiyun "Updating cache versions without reset ");
806*4882a593Smuzhiyun
807*4882a593Smuzhiyun tmp_data = vmalloc(256);
808*4882a593Smuzhiyun if (!tmp_data) {
809*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x70e1,
810*4882a593Smuzhiyun "Unable to allocate memory for VPD information update.\n");
811*4882a593Smuzhiyun return -ENOMEM;
812*4882a593Smuzhiyun }
813*4882a593Smuzhiyun ha->isp_ops->get_flash_version(vha, tmp_data);
814*4882a593Smuzhiyun vfree(tmp_data);
815*4882a593Smuzhiyun break;
816*4882a593Smuzhiyun }
817*4882a593Smuzhiyun return count;
818*4882a593Smuzhiyun }
819*4882a593Smuzhiyun
820*4882a593Smuzhiyun static struct bin_attribute sysfs_reset_attr = {
821*4882a593Smuzhiyun .attr = {
822*4882a593Smuzhiyun .name = "reset",
823*4882a593Smuzhiyun .mode = S_IWUSR,
824*4882a593Smuzhiyun },
825*4882a593Smuzhiyun .size = 0,
826*4882a593Smuzhiyun .write = qla2x00_sysfs_write_reset,
827*4882a593Smuzhiyun };
828*4882a593Smuzhiyun
829*4882a593Smuzhiyun static ssize_t
qla2x00_issue_logo(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t off,size_t count)830*4882a593Smuzhiyun qla2x00_issue_logo(struct file *filp, struct kobject *kobj,
831*4882a593Smuzhiyun struct bin_attribute *bin_attr,
832*4882a593Smuzhiyun char *buf, loff_t off, size_t count)
833*4882a593Smuzhiyun {
834*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
835*4882a593Smuzhiyun struct device, kobj)));
836*4882a593Smuzhiyun int type;
837*4882a593Smuzhiyun port_id_t did;
838*4882a593Smuzhiyun
839*4882a593Smuzhiyun if (!capable(CAP_SYS_ADMIN))
840*4882a593Smuzhiyun return 0;
841*4882a593Smuzhiyun
842*4882a593Smuzhiyun if (unlikely(pci_channel_offline(vha->hw->pdev)))
843*4882a593Smuzhiyun return 0;
844*4882a593Smuzhiyun
845*4882a593Smuzhiyun if (qla2x00_chip_is_down(vha))
846*4882a593Smuzhiyun return 0;
847*4882a593Smuzhiyun
848*4882a593Smuzhiyun type = simple_strtol(buf, NULL, 10);
849*4882a593Smuzhiyun
850*4882a593Smuzhiyun did.b.domain = (type & 0x00ff0000) >> 16;
851*4882a593Smuzhiyun did.b.area = (type & 0x0000ff00) >> 8;
852*4882a593Smuzhiyun did.b.al_pa = (type & 0x000000ff);
853*4882a593Smuzhiyun
854*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0xd04d, "portid=%02x%02x%02x done\n",
855*4882a593Smuzhiyun did.b.domain, did.b.area, did.b.al_pa);
856*4882a593Smuzhiyun
857*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x70e4, "%s: %d\n", __func__, type);
858*4882a593Smuzhiyun
859*4882a593Smuzhiyun qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, did);
860*4882a593Smuzhiyun return count;
861*4882a593Smuzhiyun }
862*4882a593Smuzhiyun
863*4882a593Smuzhiyun static struct bin_attribute sysfs_issue_logo_attr = {
864*4882a593Smuzhiyun .attr = {
865*4882a593Smuzhiyun .name = "issue_logo",
866*4882a593Smuzhiyun .mode = S_IWUSR,
867*4882a593Smuzhiyun },
868*4882a593Smuzhiyun .size = 0,
869*4882a593Smuzhiyun .write = qla2x00_issue_logo,
870*4882a593Smuzhiyun };
871*4882a593Smuzhiyun
872*4882a593Smuzhiyun static ssize_t
qla2x00_sysfs_read_xgmac_stats(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t off,size_t count)873*4882a593Smuzhiyun qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
874*4882a593Smuzhiyun struct bin_attribute *bin_attr,
875*4882a593Smuzhiyun char *buf, loff_t off, size_t count)
876*4882a593Smuzhiyun {
877*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
878*4882a593Smuzhiyun struct device, kobj)));
879*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
880*4882a593Smuzhiyun int rval;
881*4882a593Smuzhiyun uint16_t actual_size;
882*4882a593Smuzhiyun
883*4882a593Smuzhiyun if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
884*4882a593Smuzhiyun return 0;
885*4882a593Smuzhiyun
886*4882a593Smuzhiyun if (unlikely(pci_channel_offline(ha->pdev)))
887*4882a593Smuzhiyun return 0;
888*4882a593Smuzhiyun mutex_lock(&vha->hw->optrom_mutex);
889*4882a593Smuzhiyun if (qla2x00_chip_is_down(vha)) {
890*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
891*4882a593Smuzhiyun return 0;
892*4882a593Smuzhiyun }
893*4882a593Smuzhiyun
894*4882a593Smuzhiyun if (ha->xgmac_data)
895*4882a593Smuzhiyun goto do_read;
896*4882a593Smuzhiyun
897*4882a593Smuzhiyun ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
898*4882a593Smuzhiyun &ha->xgmac_data_dma, GFP_KERNEL);
899*4882a593Smuzhiyun if (!ha->xgmac_data) {
900*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
901*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x7076,
902*4882a593Smuzhiyun "Unable to allocate memory for XGMAC read-data.\n");
903*4882a593Smuzhiyun return 0;
904*4882a593Smuzhiyun }
905*4882a593Smuzhiyun
906*4882a593Smuzhiyun do_read:
907*4882a593Smuzhiyun actual_size = 0;
908*4882a593Smuzhiyun memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
909*4882a593Smuzhiyun
910*4882a593Smuzhiyun rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
911*4882a593Smuzhiyun XGMAC_DATA_SIZE, &actual_size);
912*4882a593Smuzhiyun
913*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
914*4882a593Smuzhiyun if (rval != QLA_SUCCESS) {
915*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x7077,
916*4882a593Smuzhiyun "Unable to read XGMAC data (%x).\n", rval);
917*4882a593Smuzhiyun count = 0;
918*4882a593Smuzhiyun }
919*4882a593Smuzhiyun
920*4882a593Smuzhiyun count = actual_size > count ? count : actual_size;
921*4882a593Smuzhiyun memcpy(buf, ha->xgmac_data, count);
922*4882a593Smuzhiyun
923*4882a593Smuzhiyun return count;
924*4882a593Smuzhiyun }
925*4882a593Smuzhiyun
926*4882a593Smuzhiyun static struct bin_attribute sysfs_xgmac_stats_attr = {
927*4882a593Smuzhiyun .attr = {
928*4882a593Smuzhiyun .name = "xgmac_stats",
929*4882a593Smuzhiyun .mode = S_IRUSR,
930*4882a593Smuzhiyun },
931*4882a593Smuzhiyun .size = 0,
932*4882a593Smuzhiyun .read = qla2x00_sysfs_read_xgmac_stats,
933*4882a593Smuzhiyun };
934*4882a593Smuzhiyun
935*4882a593Smuzhiyun static ssize_t
qla2x00_sysfs_read_dcbx_tlv(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t off,size_t count)936*4882a593Smuzhiyun qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
937*4882a593Smuzhiyun struct bin_attribute *bin_attr,
938*4882a593Smuzhiyun char *buf, loff_t off, size_t count)
939*4882a593Smuzhiyun {
940*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
941*4882a593Smuzhiyun struct device, kobj)));
942*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
943*4882a593Smuzhiyun int rval;
944*4882a593Smuzhiyun
945*4882a593Smuzhiyun if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
946*4882a593Smuzhiyun return 0;
947*4882a593Smuzhiyun
948*4882a593Smuzhiyun if (ha->dcbx_tlv)
949*4882a593Smuzhiyun goto do_read;
950*4882a593Smuzhiyun mutex_lock(&vha->hw->optrom_mutex);
951*4882a593Smuzhiyun if (qla2x00_chip_is_down(vha)) {
952*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
953*4882a593Smuzhiyun return 0;
954*4882a593Smuzhiyun }
955*4882a593Smuzhiyun
956*4882a593Smuzhiyun ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
957*4882a593Smuzhiyun &ha->dcbx_tlv_dma, GFP_KERNEL);
958*4882a593Smuzhiyun if (!ha->dcbx_tlv) {
959*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
960*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x7078,
961*4882a593Smuzhiyun "Unable to allocate memory for DCBX TLV read-data.\n");
962*4882a593Smuzhiyun return -ENOMEM;
963*4882a593Smuzhiyun }
964*4882a593Smuzhiyun
965*4882a593Smuzhiyun do_read:
966*4882a593Smuzhiyun memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
967*4882a593Smuzhiyun
968*4882a593Smuzhiyun rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
969*4882a593Smuzhiyun DCBX_TLV_DATA_SIZE);
970*4882a593Smuzhiyun
971*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
972*4882a593Smuzhiyun
973*4882a593Smuzhiyun if (rval != QLA_SUCCESS) {
974*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x7079,
975*4882a593Smuzhiyun "Unable to read DCBX TLV (%x).\n", rval);
976*4882a593Smuzhiyun return -EIO;
977*4882a593Smuzhiyun }
978*4882a593Smuzhiyun
979*4882a593Smuzhiyun memcpy(buf, ha->dcbx_tlv, count);
980*4882a593Smuzhiyun
981*4882a593Smuzhiyun return count;
982*4882a593Smuzhiyun }
983*4882a593Smuzhiyun
984*4882a593Smuzhiyun static struct bin_attribute sysfs_dcbx_tlv_attr = {
985*4882a593Smuzhiyun .attr = {
986*4882a593Smuzhiyun .name = "dcbx_tlv",
987*4882a593Smuzhiyun .mode = S_IRUSR,
988*4882a593Smuzhiyun },
989*4882a593Smuzhiyun .size = 0,
990*4882a593Smuzhiyun .read = qla2x00_sysfs_read_dcbx_tlv,
991*4882a593Smuzhiyun };
992*4882a593Smuzhiyun
993*4882a593Smuzhiyun static struct sysfs_entry {
994*4882a593Smuzhiyun char *name;
995*4882a593Smuzhiyun struct bin_attribute *attr;
996*4882a593Smuzhiyun int type;
997*4882a593Smuzhiyun } bin_file_entries[] = {
998*4882a593Smuzhiyun { "fw_dump", &sysfs_fw_dump_attr, },
999*4882a593Smuzhiyun { "nvram", &sysfs_nvram_attr, },
1000*4882a593Smuzhiyun { "optrom", &sysfs_optrom_attr, },
1001*4882a593Smuzhiyun { "optrom_ctl", &sysfs_optrom_ctl_attr, },
1002*4882a593Smuzhiyun { "vpd", &sysfs_vpd_attr, 1 },
1003*4882a593Smuzhiyun { "sfp", &sysfs_sfp_attr, 1 },
1004*4882a593Smuzhiyun { "reset", &sysfs_reset_attr, },
1005*4882a593Smuzhiyun { "issue_logo", &sysfs_issue_logo_attr, },
1006*4882a593Smuzhiyun { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
1007*4882a593Smuzhiyun { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
1008*4882a593Smuzhiyun { NULL },
1009*4882a593Smuzhiyun };
1010*4882a593Smuzhiyun
1011*4882a593Smuzhiyun void
qla2x00_alloc_sysfs_attr(scsi_qla_host_t * vha)1012*4882a593Smuzhiyun qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
1013*4882a593Smuzhiyun {
1014*4882a593Smuzhiyun struct Scsi_Host *host = vha->host;
1015*4882a593Smuzhiyun struct sysfs_entry *iter;
1016*4882a593Smuzhiyun int ret;
1017*4882a593Smuzhiyun
1018*4882a593Smuzhiyun for (iter = bin_file_entries; iter->name; iter++) {
1019*4882a593Smuzhiyun if (iter->type && !IS_FWI2_CAPABLE(vha->hw))
1020*4882a593Smuzhiyun continue;
1021*4882a593Smuzhiyun if (iter->type == 2 && !IS_QLA25XX(vha->hw))
1022*4882a593Smuzhiyun continue;
1023*4882a593Smuzhiyun if (iter->type == 3 && !(IS_CNA_CAPABLE(vha->hw)))
1024*4882a593Smuzhiyun continue;
1025*4882a593Smuzhiyun
1026*4882a593Smuzhiyun ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
1027*4882a593Smuzhiyun iter->attr);
1028*4882a593Smuzhiyun if (ret)
1029*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x00f3,
1030*4882a593Smuzhiyun "Unable to create sysfs %s binary attribute (%d).\n",
1031*4882a593Smuzhiyun iter->name, ret);
1032*4882a593Smuzhiyun else
1033*4882a593Smuzhiyun ql_dbg(ql_dbg_init, vha, 0x00f4,
1034*4882a593Smuzhiyun "Successfully created sysfs %s binary attribute.\n",
1035*4882a593Smuzhiyun iter->name);
1036*4882a593Smuzhiyun }
1037*4882a593Smuzhiyun }
1038*4882a593Smuzhiyun
1039*4882a593Smuzhiyun void
qla2x00_free_sysfs_attr(scsi_qla_host_t * vha,bool stop_beacon)1040*4882a593Smuzhiyun qla2x00_free_sysfs_attr(scsi_qla_host_t *vha, bool stop_beacon)
1041*4882a593Smuzhiyun {
1042*4882a593Smuzhiyun struct Scsi_Host *host = vha->host;
1043*4882a593Smuzhiyun struct sysfs_entry *iter;
1044*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1045*4882a593Smuzhiyun
1046*4882a593Smuzhiyun for (iter = bin_file_entries; iter->name; iter++) {
1047*4882a593Smuzhiyun if (iter->type && !IS_FWI2_CAPABLE(ha))
1048*4882a593Smuzhiyun continue;
1049*4882a593Smuzhiyun if (iter->type == 2 && !IS_QLA25XX(ha))
1050*4882a593Smuzhiyun continue;
1051*4882a593Smuzhiyun if (iter->type == 3 && !(IS_CNA_CAPABLE(ha)))
1052*4882a593Smuzhiyun continue;
1053*4882a593Smuzhiyun
1054*4882a593Smuzhiyun sysfs_remove_bin_file(&host->shost_gendev.kobj,
1055*4882a593Smuzhiyun iter->attr);
1056*4882a593Smuzhiyun }
1057*4882a593Smuzhiyun
1058*4882a593Smuzhiyun if (stop_beacon && ha->beacon_blink_led == 1)
1059*4882a593Smuzhiyun ha->isp_ops->beacon_off(vha);
1060*4882a593Smuzhiyun }
1061*4882a593Smuzhiyun
1062*4882a593Smuzhiyun /* Scsi_Host attributes. */
1063*4882a593Smuzhiyun
1064*4882a593Smuzhiyun static ssize_t
qla2x00_driver_version_show(struct device * dev,struct device_attribute * attr,char * buf)1065*4882a593Smuzhiyun qla2x00_driver_version_show(struct device *dev,
1066*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1067*4882a593Smuzhiyun {
1068*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
1069*4882a593Smuzhiyun }
1070*4882a593Smuzhiyun
1071*4882a593Smuzhiyun static ssize_t
qla2x00_fw_version_show(struct device * dev,struct device_attribute * attr,char * buf)1072*4882a593Smuzhiyun qla2x00_fw_version_show(struct device *dev,
1073*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1074*4882a593Smuzhiyun {
1075*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1076*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1077*4882a593Smuzhiyun char fw_str[128];
1078*4882a593Smuzhiyun
1079*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%s\n",
1080*4882a593Smuzhiyun ha->isp_ops->fw_version_str(vha, fw_str, sizeof(fw_str)));
1081*4882a593Smuzhiyun }
1082*4882a593Smuzhiyun
1083*4882a593Smuzhiyun static ssize_t
qla2x00_serial_num_show(struct device * dev,struct device_attribute * attr,char * buf)1084*4882a593Smuzhiyun qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
1085*4882a593Smuzhiyun char *buf)
1086*4882a593Smuzhiyun {
1087*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1088*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1089*4882a593Smuzhiyun uint32_t sn;
1090*4882a593Smuzhiyun
1091*4882a593Smuzhiyun if (IS_QLAFX00(vha->hw)) {
1092*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%s\n",
1093*4882a593Smuzhiyun vha->hw->mr.serial_num);
1094*4882a593Smuzhiyun } else if (IS_FWI2_CAPABLE(ha)) {
1095*4882a593Smuzhiyun qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE - 1);
1096*4882a593Smuzhiyun return strlen(strcat(buf, "\n"));
1097*4882a593Smuzhiyun }
1098*4882a593Smuzhiyun
1099*4882a593Smuzhiyun sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
1100*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
1101*4882a593Smuzhiyun sn % 100000);
1102*4882a593Smuzhiyun }
1103*4882a593Smuzhiyun
1104*4882a593Smuzhiyun static ssize_t
qla2x00_isp_name_show(struct device * dev,struct device_attribute * attr,char * buf)1105*4882a593Smuzhiyun qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
1106*4882a593Smuzhiyun char *buf)
1107*4882a593Smuzhiyun {
1108*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1109*4882a593Smuzhiyun
1110*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
1111*4882a593Smuzhiyun }
1112*4882a593Smuzhiyun
1113*4882a593Smuzhiyun static ssize_t
qla2x00_isp_id_show(struct device * dev,struct device_attribute * attr,char * buf)1114*4882a593Smuzhiyun qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
1115*4882a593Smuzhiyun char *buf)
1116*4882a593Smuzhiyun {
1117*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1118*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1119*4882a593Smuzhiyun
1120*4882a593Smuzhiyun if (IS_QLAFX00(vha->hw))
1121*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%s\n",
1122*4882a593Smuzhiyun vha->hw->mr.hw_version);
1123*4882a593Smuzhiyun
1124*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
1125*4882a593Smuzhiyun ha->product_id[0], ha->product_id[1], ha->product_id[2],
1126*4882a593Smuzhiyun ha->product_id[3]);
1127*4882a593Smuzhiyun }
1128*4882a593Smuzhiyun
1129*4882a593Smuzhiyun static ssize_t
qla2x00_model_name_show(struct device * dev,struct device_attribute * attr,char * buf)1130*4882a593Smuzhiyun qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
1131*4882a593Smuzhiyun char *buf)
1132*4882a593Smuzhiyun {
1133*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1134*4882a593Smuzhiyun
1135*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
1136*4882a593Smuzhiyun }
1137*4882a593Smuzhiyun
1138*4882a593Smuzhiyun static ssize_t
qla2x00_model_desc_show(struct device * dev,struct device_attribute * attr,char * buf)1139*4882a593Smuzhiyun qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
1140*4882a593Smuzhiyun char *buf)
1141*4882a593Smuzhiyun {
1142*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1143*4882a593Smuzhiyun
1144*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_desc);
1145*4882a593Smuzhiyun }
1146*4882a593Smuzhiyun
1147*4882a593Smuzhiyun static ssize_t
qla2x00_pci_info_show(struct device * dev,struct device_attribute * attr,char * buf)1148*4882a593Smuzhiyun qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
1149*4882a593Smuzhiyun char *buf)
1150*4882a593Smuzhiyun {
1151*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1152*4882a593Smuzhiyun char pci_info[30];
1153*4882a593Smuzhiyun
1154*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%s\n",
1155*4882a593Smuzhiyun vha->hw->isp_ops->pci_info_str(vha, pci_info,
1156*4882a593Smuzhiyun sizeof(pci_info)));
1157*4882a593Smuzhiyun }
1158*4882a593Smuzhiyun
1159*4882a593Smuzhiyun static ssize_t
qla2x00_link_state_show(struct device * dev,struct device_attribute * attr,char * buf)1160*4882a593Smuzhiyun qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
1161*4882a593Smuzhiyun char *buf)
1162*4882a593Smuzhiyun {
1163*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1164*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1165*4882a593Smuzhiyun int len = 0;
1166*4882a593Smuzhiyun
1167*4882a593Smuzhiyun if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
1168*4882a593Smuzhiyun atomic_read(&vha->loop_state) == LOOP_DEAD ||
1169*4882a593Smuzhiyun vha->device_flags & DFLG_NO_CABLE)
1170*4882a593Smuzhiyun len = scnprintf(buf, PAGE_SIZE, "Link Down\n");
1171*4882a593Smuzhiyun else if (atomic_read(&vha->loop_state) != LOOP_READY ||
1172*4882a593Smuzhiyun qla2x00_chip_is_down(vha))
1173*4882a593Smuzhiyun len = scnprintf(buf, PAGE_SIZE, "Unknown Link State\n");
1174*4882a593Smuzhiyun else {
1175*4882a593Smuzhiyun len = scnprintf(buf, PAGE_SIZE, "Link Up - ");
1176*4882a593Smuzhiyun
1177*4882a593Smuzhiyun switch (ha->current_topology) {
1178*4882a593Smuzhiyun case ISP_CFG_NL:
1179*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1180*4882a593Smuzhiyun break;
1181*4882a593Smuzhiyun case ISP_CFG_FL:
1182*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
1183*4882a593Smuzhiyun break;
1184*4882a593Smuzhiyun case ISP_CFG_N:
1185*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len,
1186*4882a593Smuzhiyun "N_Port to N_Port\n");
1187*4882a593Smuzhiyun break;
1188*4882a593Smuzhiyun case ISP_CFG_F:
1189*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
1190*4882a593Smuzhiyun break;
1191*4882a593Smuzhiyun default:
1192*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1193*4882a593Smuzhiyun break;
1194*4882a593Smuzhiyun }
1195*4882a593Smuzhiyun }
1196*4882a593Smuzhiyun return len;
1197*4882a593Smuzhiyun }
1198*4882a593Smuzhiyun
1199*4882a593Smuzhiyun static ssize_t
qla2x00_zio_show(struct device * dev,struct device_attribute * attr,char * buf)1200*4882a593Smuzhiyun qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1201*4882a593Smuzhiyun char *buf)
1202*4882a593Smuzhiyun {
1203*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1204*4882a593Smuzhiyun int len = 0;
1205*4882a593Smuzhiyun
1206*4882a593Smuzhiyun switch (vha->hw->zio_mode) {
1207*4882a593Smuzhiyun case QLA_ZIO_MODE_6:
1208*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
1209*4882a593Smuzhiyun break;
1210*4882a593Smuzhiyun case QLA_ZIO_DISABLED:
1211*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1212*4882a593Smuzhiyun break;
1213*4882a593Smuzhiyun }
1214*4882a593Smuzhiyun return len;
1215*4882a593Smuzhiyun }
1216*4882a593Smuzhiyun
1217*4882a593Smuzhiyun static ssize_t
qla2x00_zio_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)1218*4882a593Smuzhiyun qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1219*4882a593Smuzhiyun const char *buf, size_t count)
1220*4882a593Smuzhiyun {
1221*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1222*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1223*4882a593Smuzhiyun int val = 0;
1224*4882a593Smuzhiyun uint16_t zio_mode;
1225*4882a593Smuzhiyun
1226*4882a593Smuzhiyun if (!IS_ZIO_SUPPORTED(ha))
1227*4882a593Smuzhiyun return -ENOTSUPP;
1228*4882a593Smuzhiyun
1229*4882a593Smuzhiyun if (sscanf(buf, "%d", &val) != 1)
1230*4882a593Smuzhiyun return -EINVAL;
1231*4882a593Smuzhiyun
1232*4882a593Smuzhiyun if (val)
1233*4882a593Smuzhiyun zio_mode = QLA_ZIO_MODE_6;
1234*4882a593Smuzhiyun else
1235*4882a593Smuzhiyun zio_mode = QLA_ZIO_DISABLED;
1236*4882a593Smuzhiyun
1237*4882a593Smuzhiyun /* Update per-hba values and queue a reset. */
1238*4882a593Smuzhiyun if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1239*4882a593Smuzhiyun ha->zio_mode = zio_mode;
1240*4882a593Smuzhiyun set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1241*4882a593Smuzhiyun }
1242*4882a593Smuzhiyun return strlen(buf);
1243*4882a593Smuzhiyun }
1244*4882a593Smuzhiyun
1245*4882a593Smuzhiyun static ssize_t
qla2x00_zio_timer_show(struct device * dev,struct device_attribute * attr,char * buf)1246*4882a593Smuzhiyun qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1247*4882a593Smuzhiyun char *buf)
1248*4882a593Smuzhiyun {
1249*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1250*4882a593Smuzhiyun
1251*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
1252*4882a593Smuzhiyun }
1253*4882a593Smuzhiyun
1254*4882a593Smuzhiyun static ssize_t
qla2x00_zio_timer_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)1255*4882a593Smuzhiyun qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
1256*4882a593Smuzhiyun const char *buf, size_t count)
1257*4882a593Smuzhiyun {
1258*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1259*4882a593Smuzhiyun int val = 0;
1260*4882a593Smuzhiyun uint16_t zio_timer;
1261*4882a593Smuzhiyun
1262*4882a593Smuzhiyun if (sscanf(buf, "%d", &val) != 1)
1263*4882a593Smuzhiyun return -EINVAL;
1264*4882a593Smuzhiyun if (val > 25500 || val < 100)
1265*4882a593Smuzhiyun return -ERANGE;
1266*4882a593Smuzhiyun
1267*4882a593Smuzhiyun zio_timer = (uint16_t)(val / 100);
1268*4882a593Smuzhiyun vha->hw->zio_timer = zio_timer;
1269*4882a593Smuzhiyun
1270*4882a593Smuzhiyun return strlen(buf);
1271*4882a593Smuzhiyun }
1272*4882a593Smuzhiyun
1273*4882a593Smuzhiyun static ssize_t
qla_zio_threshold_show(struct device * dev,struct device_attribute * attr,char * buf)1274*4882a593Smuzhiyun qla_zio_threshold_show(struct device *dev, struct device_attribute *attr,
1275*4882a593Smuzhiyun char *buf)
1276*4882a593Smuzhiyun {
1277*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1278*4882a593Smuzhiyun
1279*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d exchanges\n",
1280*4882a593Smuzhiyun vha->hw->last_zio_threshold);
1281*4882a593Smuzhiyun }
1282*4882a593Smuzhiyun
1283*4882a593Smuzhiyun static ssize_t
qla_zio_threshold_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)1284*4882a593Smuzhiyun qla_zio_threshold_store(struct device *dev, struct device_attribute *attr,
1285*4882a593Smuzhiyun const char *buf, size_t count)
1286*4882a593Smuzhiyun {
1287*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1288*4882a593Smuzhiyun int val = 0;
1289*4882a593Smuzhiyun
1290*4882a593Smuzhiyun if (vha->hw->zio_mode != QLA_ZIO_MODE_6)
1291*4882a593Smuzhiyun return -EINVAL;
1292*4882a593Smuzhiyun if (sscanf(buf, "%d", &val) != 1)
1293*4882a593Smuzhiyun return -EINVAL;
1294*4882a593Smuzhiyun if (val < 0 || val > 256)
1295*4882a593Smuzhiyun return -ERANGE;
1296*4882a593Smuzhiyun
1297*4882a593Smuzhiyun atomic_set(&vha->hw->zio_threshold, val);
1298*4882a593Smuzhiyun return strlen(buf);
1299*4882a593Smuzhiyun }
1300*4882a593Smuzhiyun
1301*4882a593Smuzhiyun static ssize_t
qla2x00_beacon_show(struct device * dev,struct device_attribute * attr,char * buf)1302*4882a593Smuzhiyun qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1303*4882a593Smuzhiyun char *buf)
1304*4882a593Smuzhiyun {
1305*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1306*4882a593Smuzhiyun int len = 0;
1307*4882a593Smuzhiyun
1308*4882a593Smuzhiyun if (vha->hw->beacon_blink_led)
1309*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1310*4882a593Smuzhiyun else
1311*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1312*4882a593Smuzhiyun return len;
1313*4882a593Smuzhiyun }
1314*4882a593Smuzhiyun
1315*4882a593Smuzhiyun static ssize_t
qla2x00_beacon_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)1316*4882a593Smuzhiyun qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1317*4882a593Smuzhiyun const char *buf, size_t count)
1318*4882a593Smuzhiyun {
1319*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1320*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1321*4882a593Smuzhiyun int val = 0;
1322*4882a593Smuzhiyun int rval;
1323*4882a593Smuzhiyun
1324*4882a593Smuzhiyun if (IS_QLA2100(ha) || IS_QLA2200(ha))
1325*4882a593Smuzhiyun return -EPERM;
1326*4882a593Smuzhiyun
1327*4882a593Smuzhiyun if (sscanf(buf, "%d", &val) != 1)
1328*4882a593Smuzhiyun return -EINVAL;
1329*4882a593Smuzhiyun
1330*4882a593Smuzhiyun mutex_lock(&vha->hw->optrom_mutex);
1331*4882a593Smuzhiyun if (qla2x00_chip_is_down(vha)) {
1332*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
1333*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x707a,
1334*4882a593Smuzhiyun "Abort ISP active -- ignoring beacon request.\n");
1335*4882a593Smuzhiyun return -EBUSY;
1336*4882a593Smuzhiyun }
1337*4882a593Smuzhiyun
1338*4882a593Smuzhiyun if (val)
1339*4882a593Smuzhiyun rval = ha->isp_ops->beacon_on(vha);
1340*4882a593Smuzhiyun else
1341*4882a593Smuzhiyun rval = ha->isp_ops->beacon_off(vha);
1342*4882a593Smuzhiyun
1343*4882a593Smuzhiyun if (rval != QLA_SUCCESS)
1344*4882a593Smuzhiyun count = 0;
1345*4882a593Smuzhiyun
1346*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
1347*4882a593Smuzhiyun
1348*4882a593Smuzhiyun return count;
1349*4882a593Smuzhiyun }
1350*4882a593Smuzhiyun
1351*4882a593Smuzhiyun static ssize_t
qla2x00_beacon_config_show(struct device * dev,struct device_attribute * attr,char * buf)1352*4882a593Smuzhiyun qla2x00_beacon_config_show(struct device *dev, struct device_attribute *attr,
1353*4882a593Smuzhiyun char *buf)
1354*4882a593Smuzhiyun {
1355*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1356*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1357*4882a593Smuzhiyun uint16_t led[3] = { 0 };
1358*4882a593Smuzhiyun
1359*4882a593Smuzhiyun if (!IS_QLA2031(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1360*4882a593Smuzhiyun return -EPERM;
1361*4882a593Smuzhiyun
1362*4882a593Smuzhiyun if (ql26xx_led_config(vha, 0, led))
1363*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1364*4882a593Smuzhiyun
1365*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%#04hx %#04hx %#04hx\n",
1366*4882a593Smuzhiyun led[0], led[1], led[2]);
1367*4882a593Smuzhiyun }
1368*4882a593Smuzhiyun
1369*4882a593Smuzhiyun static ssize_t
qla2x00_beacon_config_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)1370*4882a593Smuzhiyun qla2x00_beacon_config_store(struct device *dev, struct device_attribute *attr,
1371*4882a593Smuzhiyun const char *buf, size_t count)
1372*4882a593Smuzhiyun {
1373*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1374*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1375*4882a593Smuzhiyun uint16_t options = BIT_0;
1376*4882a593Smuzhiyun uint16_t led[3] = { 0 };
1377*4882a593Smuzhiyun uint16_t word[4];
1378*4882a593Smuzhiyun int n;
1379*4882a593Smuzhiyun
1380*4882a593Smuzhiyun if (!IS_QLA2031(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1381*4882a593Smuzhiyun return -EPERM;
1382*4882a593Smuzhiyun
1383*4882a593Smuzhiyun n = sscanf(buf, "%hx %hx %hx %hx", word+0, word+1, word+2, word+3);
1384*4882a593Smuzhiyun if (n == 4) {
1385*4882a593Smuzhiyun if (word[0] == 3) {
1386*4882a593Smuzhiyun options |= BIT_3|BIT_2|BIT_1;
1387*4882a593Smuzhiyun led[0] = word[1];
1388*4882a593Smuzhiyun led[1] = word[2];
1389*4882a593Smuzhiyun led[2] = word[3];
1390*4882a593Smuzhiyun goto write;
1391*4882a593Smuzhiyun }
1392*4882a593Smuzhiyun return -EINVAL;
1393*4882a593Smuzhiyun }
1394*4882a593Smuzhiyun
1395*4882a593Smuzhiyun if (n == 2) {
1396*4882a593Smuzhiyun /* check led index */
1397*4882a593Smuzhiyun if (word[0] == 0) {
1398*4882a593Smuzhiyun options |= BIT_2;
1399*4882a593Smuzhiyun led[0] = word[1];
1400*4882a593Smuzhiyun goto write;
1401*4882a593Smuzhiyun }
1402*4882a593Smuzhiyun if (word[0] == 1) {
1403*4882a593Smuzhiyun options |= BIT_3;
1404*4882a593Smuzhiyun led[1] = word[1];
1405*4882a593Smuzhiyun goto write;
1406*4882a593Smuzhiyun }
1407*4882a593Smuzhiyun if (word[0] == 2) {
1408*4882a593Smuzhiyun options |= BIT_1;
1409*4882a593Smuzhiyun led[2] = word[1];
1410*4882a593Smuzhiyun goto write;
1411*4882a593Smuzhiyun }
1412*4882a593Smuzhiyun return -EINVAL;
1413*4882a593Smuzhiyun }
1414*4882a593Smuzhiyun
1415*4882a593Smuzhiyun return -EINVAL;
1416*4882a593Smuzhiyun
1417*4882a593Smuzhiyun write:
1418*4882a593Smuzhiyun if (ql26xx_led_config(vha, options, led))
1419*4882a593Smuzhiyun return -EFAULT;
1420*4882a593Smuzhiyun
1421*4882a593Smuzhiyun return count;
1422*4882a593Smuzhiyun }
1423*4882a593Smuzhiyun
1424*4882a593Smuzhiyun static ssize_t
qla2x00_optrom_bios_version_show(struct device * dev,struct device_attribute * attr,char * buf)1425*4882a593Smuzhiyun qla2x00_optrom_bios_version_show(struct device *dev,
1426*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1427*4882a593Smuzhiyun {
1428*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1429*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1430*4882a593Smuzhiyun
1431*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1432*4882a593Smuzhiyun ha->bios_revision[0]);
1433*4882a593Smuzhiyun }
1434*4882a593Smuzhiyun
1435*4882a593Smuzhiyun static ssize_t
qla2x00_optrom_efi_version_show(struct device * dev,struct device_attribute * attr,char * buf)1436*4882a593Smuzhiyun qla2x00_optrom_efi_version_show(struct device *dev,
1437*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1438*4882a593Smuzhiyun {
1439*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1440*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1441*4882a593Smuzhiyun
1442*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1443*4882a593Smuzhiyun ha->efi_revision[0]);
1444*4882a593Smuzhiyun }
1445*4882a593Smuzhiyun
1446*4882a593Smuzhiyun static ssize_t
qla2x00_optrom_fcode_version_show(struct device * dev,struct device_attribute * attr,char * buf)1447*4882a593Smuzhiyun qla2x00_optrom_fcode_version_show(struct device *dev,
1448*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1449*4882a593Smuzhiyun {
1450*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1451*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1452*4882a593Smuzhiyun
1453*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1454*4882a593Smuzhiyun ha->fcode_revision[0]);
1455*4882a593Smuzhiyun }
1456*4882a593Smuzhiyun
1457*4882a593Smuzhiyun static ssize_t
qla2x00_optrom_fw_version_show(struct device * dev,struct device_attribute * attr,char * buf)1458*4882a593Smuzhiyun qla2x00_optrom_fw_version_show(struct device *dev,
1459*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1460*4882a593Smuzhiyun {
1461*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1462*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1463*4882a593Smuzhiyun
1464*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1465*4882a593Smuzhiyun ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1466*4882a593Smuzhiyun ha->fw_revision[3]);
1467*4882a593Smuzhiyun }
1468*4882a593Smuzhiyun
1469*4882a593Smuzhiyun static ssize_t
qla2x00_optrom_gold_fw_version_show(struct device * dev,struct device_attribute * attr,char * buf)1470*4882a593Smuzhiyun qla2x00_optrom_gold_fw_version_show(struct device *dev,
1471*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1472*4882a593Smuzhiyun {
1473*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1474*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1475*4882a593Smuzhiyun
1476*4882a593Smuzhiyun if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1477*4882a593Smuzhiyun !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1478*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1479*4882a593Smuzhiyun
1480*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
1481*4882a593Smuzhiyun ha->gold_fw_version[0], ha->gold_fw_version[1],
1482*4882a593Smuzhiyun ha->gold_fw_version[2], ha->gold_fw_version[3]);
1483*4882a593Smuzhiyun }
1484*4882a593Smuzhiyun
1485*4882a593Smuzhiyun static ssize_t
qla2x00_total_isp_aborts_show(struct device * dev,struct device_attribute * attr,char * buf)1486*4882a593Smuzhiyun qla2x00_total_isp_aborts_show(struct device *dev,
1487*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1488*4882a593Smuzhiyun {
1489*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1490*4882a593Smuzhiyun
1491*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d\n",
1492*4882a593Smuzhiyun vha->qla_stats.total_isp_aborts);
1493*4882a593Smuzhiyun }
1494*4882a593Smuzhiyun
1495*4882a593Smuzhiyun static ssize_t
qla24xx_84xx_fw_version_show(struct device * dev,struct device_attribute * attr,char * buf)1496*4882a593Smuzhiyun qla24xx_84xx_fw_version_show(struct device *dev,
1497*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1498*4882a593Smuzhiyun {
1499*4882a593Smuzhiyun int rval = QLA_SUCCESS;
1500*4882a593Smuzhiyun uint16_t status[2] = { 0 };
1501*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1502*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1503*4882a593Smuzhiyun
1504*4882a593Smuzhiyun if (!IS_QLA84XX(ha))
1505*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1506*4882a593Smuzhiyun
1507*4882a593Smuzhiyun if (!ha->cs84xx->op_fw_version) {
1508*4882a593Smuzhiyun rval = qla84xx_verify_chip(vha, status);
1509*4882a593Smuzhiyun
1510*4882a593Smuzhiyun if (!rval && !status[0])
1511*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%u\n",
1512*4882a593Smuzhiyun (uint32_t)ha->cs84xx->op_fw_version);
1513*4882a593Smuzhiyun }
1514*4882a593Smuzhiyun
1515*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1516*4882a593Smuzhiyun }
1517*4882a593Smuzhiyun
1518*4882a593Smuzhiyun static ssize_t
qla2x00_serdes_version_show(struct device * dev,struct device_attribute * attr,char * buf)1519*4882a593Smuzhiyun qla2x00_serdes_version_show(struct device *dev, struct device_attribute *attr,
1520*4882a593Smuzhiyun char *buf)
1521*4882a593Smuzhiyun {
1522*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1523*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1524*4882a593Smuzhiyun
1525*4882a593Smuzhiyun if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1526*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1527*4882a593Smuzhiyun
1528*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1529*4882a593Smuzhiyun ha->serdes_version[0], ha->serdes_version[1],
1530*4882a593Smuzhiyun ha->serdes_version[2]);
1531*4882a593Smuzhiyun }
1532*4882a593Smuzhiyun
1533*4882a593Smuzhiyun static ssize_t
qla2x00_mpi_version_show(struct device * dev,struct device_attribute * attr,char * buf)1534*4882a593Smuzhiyun qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1535*4882a593Smuzhiyun char *buf)
1536*4882a593Smuzhiyun {
1537*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1538*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1539*4882a593Smuzhiyun
1540*4882a593Smuzhiyun if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha) &&
1541*4882a593Smuzhiyun !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1542*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1543*4882a593Smuzhiyun
1544*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
1545*4882a593Smuzhiyun ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
1546*4882a593Smuzhiyun ha->mpi_capabilities);
1547*4882a593Smuzhiyun }
1548*4882a593Smuzhiyun
1549*4882a593Smuzhiyun static ssize_t
qla2x00_phy_version_show(struct device * dev,struct device_attribute * attr,char * buf)1550*4882a593Smuzhiyun qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1551*4882a593Smuzhiyun char *buf)
1552*4882a593Smuzhiyun {
1553*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1554*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1555*4882a593Smuzhiyun
1556*4882a593Smuzhiyun if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
1557*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1558*4882a593Smuzhiyun
1559*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1560*4882a593Smuzhiyun ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
1561*4882a593Smuzhiyun }
1562*4882a593Smuzhiyun
1563*4882a593Smuzhiyun static ssize_t
qla2x00_flash_block_size_show(struct device * dev,struct device_attribute * attr,char * buf)1564*4882a593Smuzhiyun qla2x00_flash_block_size_show(struct device *dev,
1565*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1566*4882a593Smuzhiyun {
1567*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1568*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1569*4882a593Smuzhiyun
1570*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1571*4882a593Smuzhiyun }
1572*4882a593Smuzhiyun
1573*4882a593Smuzhiyun static ssize_t
qla2x00_vlan_id_show(struct device * dev,struct device_attribute * attr,char * buf)1574*4882a593Smuzhiyun qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1575*4882a593Smuzhiyun char *buf)
1576*4882a593Smuzhiyun {
1577*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1578*4882a593Smuzhiyun
1579*4882a593Smuzhiyun if (!IS_CNA_CAPABLE(vha->hw))
1580*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1581*4882a593Smuzhiyun
1582*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1583*4882a593Smuzhiyun }
1584*4882a593Smuzhiyun
1585*4882a593Smuzhiyun static ssize_t
qla2x00_vn_port_mac_address_show(struct device * dev,struct device_attribute * attr,char * buf)1586*4882a593Smuzhiyun qla2x00_vn_port_mac_address_show(struct device *dev,
1587*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1588*4882a593Smuzhiyun {
1589*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1590*4882a593Smuzhiyun
1591*4882a593Smuzhiyun if (!IS_CNA_CAPABLE(vha->hw))
1592*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1593*4882a593Smuzhiyun
1594*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%pMR\n", vha->fcoe_vn_port_mac);
1595*4882a593Smuzhiyun }
1596*4882a593Smuzhiyun
1597*4882a593Smuzhiyun static ssize_t
qla2x00_fabric_param_show(struct device * dev,struct device_attribute * attr,char * buf)1598*4882a593Smuzhiyun qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1599*4882a593Smuzhiyun char *buf)
1600*4882a593Smuzhiyun {
1601*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1602*4882a593Smuzhiyun
1603*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1604*4882a593Smuzhiyun }
1605*4882a593Smuzhiyun
1606*4882a593Smuzhiyun static ssize_t
qla2x00_thermal_temp_show(struct device * dev,struct device_attribute * attr,char * buf)1607*4882a593Smuzhiyun qla2x00_thermal_temp_show(struct device *dev,
1608*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1609*4882a593Smuzhiyun {
1610*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1611*4882a593Smuzhiyun uint16_t temp = 0;
1612*4882a593Smuzhiyun int rc;
1613*4882a593Smuzhiyun
1614*4882a593Smuzhiyun mutex_lock(&vha->hw->optrom_mutex);
1615*4882a593Smuzhiyun if (qla2x00_chip_is_down(vha)) {
1616*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
1617*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x70dc, "ISP reset active.\n");
1618*4882a593Smuzhiyun goto done;
1619*4882a593Smuzhiyun }
1620*4882a593Smuzhiyun
1621*4882a593Smuzhiyun if (vha->hw->flags.eeh_busy) {
1622*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
1623*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x70dd, "PCI EEH busy.\n");
1624*4882a593Smuzhiyun goto done;
1625*4882a593Smuzhiyun }
1626*4882a593Smuzhiyun
1627*4882a593Smuzhiyun rc = qla2x00_get_thermal_temp(vha, &temp);
1628*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
1629*4882a593Smuzhiyun if (rc == QLA_SUCCESS)
1630*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d\n", temp);
1631*4882a593Smuzhiyun
1632*4882a593Smuzhiyun done:
1633*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1634*4882a593Smuzhiyun }
1635*4882a593Smuzhiyun
1636*4882a593Smuzhiyun static ssize_t
qla2x00_fw_state_show(struct device * dev,struct device_attribute * attr,char * buf)1637*4882a593Smuzhiyun qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1638*4882a593Smuzhiyun char *buf)
1639*4882a593Smuzhiyun {
1640*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1641*4882a593Smuzhiyun int rval = QLA_FUNCTION_FAILED;
1642*4882a593Smuzhiyun uint16_t state[6];
1643*4882a593Smuzhiyun uint32_t pstate;
1644*4882a593Smuzhiyun
1645*4882a593Smuzhiyun if (IS_QLAFX00(vha->hw)) {
1646*4882a593Smuzhiyun pstate = qlafx00_fw_state_show(dev, attr, buf);
1647*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "0x%x\n", pstate);
1648*4882a593Smuzhiyun }
1649*4882a593Smuzhiyun
1650*4882a593Smuzhiyun mutex_lock(&vha->hw->optrom_mutex);
1651*4882a593Smuzhiyun if (qla2x00_chip_is_down(vha)) {
1652*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
1653*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x707c,
1654*4882a593Smuzhiyun "ISP reset active.\n");
1655*4882a593Smuzhiyun goto out;
1656*4882a593Smuzhiyun } else if (vha->hw->flags.eeh_busy) {
1657*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
1658*4882a593Smuzhiyun goto out;
1659*4882a593Smuzhiyun }
1660*4882a593Smuzhiyun
1661*4882a593Smuzhiyun rval = qla2x00_get_firmware_state(vha, state);
1662*4882a593Smuzhiyun mutex_unlock(&vha->hw->optrom_mutex);
1663*4882a593Smuzhiyun out:
1664*4882a593Smuzhiyun if (rval != QLA_SUCCESS) {
1665*4882a593Smuzhiyun memset(state, -1, sizeof(state));
1666*4882a593Smuzhiyun rval = qla2x00_get_firmware_state(vha, state);
1667*4882a593Smuzhiyun }
1668*4882a593Smuzhiyun
1669*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1670*4882a593Smuzhiyun state[0], state[1], state[2], state[3], state[4], state[5]);
1671*4882a593Smuzhiyun }
1672*4882a593Smuzhiyun
1673*4882a593Smuzhiyun static ssize_t
qla2x00_diag_requests_show(struct device * dev,struct device_attribute * attr,char * buf)1674*4882a593Smuzhiyun qla2x00_diag_requests_show(struct device *dev,
1675*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1676*4882a593Smuzhiyun {
1677*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1678*4882a593Smuzhiyun
1679*4882a593Smuzhiyun if (!IS_BIDI_CAPABLE(vha->hw))
1680*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1681*4882a593Smuzhiyun
1682*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%llu\n", vha->bidi_stats.io_count);
1683*4882a593Smuzhiyun }
1684*4882a593Smuzhiyun
1685*4882a593Smuzhiyun static ssize_t
qla2x00_diag_megabytes_show(struct device * dev,struct device_attribute * attr,char * buf)1686*4882a593Smuzhiyun qla2x00_diag_megabytes_show(struct device *dev,
1687*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1688*4882a593Smuzhiyun {
1689*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1690*4882a593Smuzhiyun
1691*4882a593Smuzhiyun if (!IS_BIDI_CAPABLE(vha->hw))
1692*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1693*4882a593Smuzhiyun
1694*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%llu\n",
1695*4882a593Smuzhiyun vha->bidi_stats.transfer_bytes >> 20);
1696*4882a593Smuzhiyun }
1697*4882a593Smuzhiyun
1698*4882a593Smuzhiyun static ssize_t
qla2x00_fw_dump_size_show(struct device * dev,struct device_attribute * attr,char * buf)1699*4882a593Smuzhiyun qla2x00_fw_dump_size_show(struct device *dev, struct device_attribute *attr,
1700*4882a593Smuzhiyun char *buf)
1701*4882a593Smuzhiyun {
1702*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1703*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1704*4882a593Smuzhiyun uint32_t size;
1705*4882a593Smuzhiyun
1706*4882a593Smuzhiyun if (!ha->fw_dumped)
1707*4882a593Smuzhiyun size = 0;
1708*4882a593Smuzhiyun else if (IS_P3P_TYPE(ha))
1709*4882a593Smuzhiyun size = ha->md_template_size + ha->md_dump_size;
1710*4882a593Smuzhiyun else
1711*4882a593Smuzhiyun size = ha->fw_dump_len;
1712*4882a593Smuzhiyun
1713*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d\n", size);
1714*4882a593Smuzhiyun }
1715*4882a593Smuzhiyun
1716*4882a593Smuzhiyun static ssize_t
qla2x00_allow_cna_fw_dump_show(struct device * dev,struct device_attribute * attr,char * buf)1717*4882a593Smuzhiyun qla2x00_allow_cna_fw_dump_show(struct device *dev,
1718*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1719*4882a593Smuzhiyun {
1720*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1721*4882a593Smuzhiyun
1722*4882a593Smuzhiyun if (!IS_P3P_TYPE(vha->hw))
1723*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1724*4882a593Smuzhiyun else
1725*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%s\n",
1726*4882a593Smuzhiyun vha->hw->allow_cna_fw_dump ? "true" : "false");
1727*4882a593Smuzhiyun }
1728*4882a593Smuzhiyun
1729*4882a593Smuzhiyun static ssize_t
qla2x00_allow_cna_fw_dump_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)1730*4882a593Smuzhiyun qla2x00_allow_cna_fw_dump_store(struct device *dev,
1731*4882a593Smuzhiyun struct device_attribute *attr, const char *buf, size_t count)
1732*4882a593Smuzhiyun {
1733*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1734*4882a593Smuzhiyun int val = 0;
1735*4882a593Smuzhiyun
1736*4882a593Smuzhiyun if (!IS_P3P_TYPE(vha->hw))
1737*4882a593Smuzhiyun return -EINVAL;
1738*4882a593Smuzhiyun
1739*4882a593Smuzhiyun if (sscanf(buf, "%d", &val) != 1)
1740*4882a593Smuzhiyun return -EINVAL;
1741*4882a593Smuzhiyun
1742*4882a593Smuzhiyun vha->hw->allow_cna_fw_dump = val != 0;
1743*4882a593Smuzhiyun
1744*4882a593Smuzhiyun return strlen(buf);
1745*4882a593Smuzhiyun }
1746*4882a593Smuzhiyun
1747*4882a593Smuzhiyun static ssize_t
qla2x00_pep_version_show(struct device * dev,struct device_attribute * attr,char * buf)1748*4882a593Smuzhiyun qla2x00_pep_version_show(struct device *dev, struct device_attribute *attr,
1749*4882a593Smuzhiyun char *buf)
1750*4882a593Smuzhiyun {
1751*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1752*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1753*4882a593Smuzhiyun
1754*4882a593Smuzhiyun if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1755*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1756*4882a593Smuzhiyun
1757*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1758*4882a593Smuzhiyun ha->pep_version[0], ha->pep_version[1], ha->pep_version[2]);
1759*4882a593Smuzhiyun }
1760*4882a593Smuzhiyun
1761*4882a593Smuzhiyun static ssize_t
qla2x00_min_supported_speed_show(struct device * dev,struct device_attribute * attr,char * buf)1762*4882a593Smuzhiyun qla2x00_min_supported_speed_show(struct device *dev,
1763*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1764*4882a593Smuzhiyun {
1765*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1766*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1767*4882a593Smuzhiyun
1768*4882a593Smuzhiyun if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1769*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1770*4882a593Smuzhiyun
1771*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%s\n",
1772*4882a593Smuzhiyun ha->min_supported_speed == 6 ? "64Gps" :
1773*4882a593Smuzhiyun ha->min_supported_speed == 5 ? "32Gps" :
1774*4882a593Smuzhiyun ha->min_supported_speed == 4 ? "16Gps" :
1775*4882a593Smuzhiyun ha->min_supported_speed == 3 ? "8Gps" :
1776*4882a593Smuzhiyun ha->min_supported_speed == 2 ? "4Gps" :
1777*4882a593Smuzhiyun ha->min_supported_speed != 0 ? "unknown" : "");
1778*4882a593Smuzhiyun }
1779*4882a593Smuzhiyun
1780*4882a593Smuzhiyun static ssize_t
qla2x00_max_supported_speed_show(struct device * dev,struct device_attribute * attr,char * buf)1781*4882a593Smuzhiyun qla2x00_max_supported_speed_show(struct device *dev,
1782*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
1783*4882a593Smuzhiyun {
1784*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1785*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1786*4882a593Smuzhiyun
1787*4882a593Smuzhiyun if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1788*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
1789*4882a593Smuzhiyun
1790*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%s\n",
1791*4882a593Smuzhiyun ha->max_supported_speed == 2 ? "64Gps" :
1792*4882a593Smuzhiyun ha->max_supported_speed == 1 ? "32Gps" :
1793*4882a593Smuzhiyun ha->max_supported_speed == 0 ? "16Gps" : "unknown");
1794*4882a593Smuzhiyun }
1795*4882a593Smuzhiyun
1796*4882a593Smuzhiyun static ssize_t
qla2x00_port_speed_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)1797*4882a593Smuzhiyun qla2x00_port_speed_store(struct device *dev, struct device_attribute *attr,
1798*4882a593Smuzhiyun const char *buf, size_t count)
1799*4882a593Smuzhiyun {
1800*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(dev));
1801*4882a593Smuzhiyun ulong type, speed;
1802*4882a593Smuzhiyun int oldspeed, rval;
1803*4882a593Smuzhiyun int mode = QLA_SET_DATA_RATE_LR;
1804*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1805*4882a593Smuzhiyun
1806*4882a593Smuzhiyun if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha)) {
1807*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x70d8,
1808*4882a593Smuzhiyun "Speed setting not supported \n");
1809*4882a593Smuzhiyun return -EINVAL;
1810*4882a593Smuzhiyun }
1811*4882a593Smuzhiyun
1812*4882a593Smuzhiyun rval = kstrtol(buf, 10, &type);
1813*4882a593Smuzhiyun if (rval)
1814*4882a593Smuzhiyun return rval;
1815*4882a593Smuzhiyun speed = type;
1816*4882a593Smuzhiyun if (type == 40 || type == 80 || type == 160 ||
1817*4882a593Smuzhiyun type == 320) {
1818*4882a593Smuzhiyun ql_dbg(ql_dbg_user, vha, 0x70d9,
1819*4882a593Smuzhiyun "Setting will be affected after a loss of sync\n");
1820*4882a593Smuzhiyun type = type/10;
1821*4882a593Smuzhiyun mode = QLA_SET_DATA_RATE_NOLR;
1822*4882a593Smuzhiyun }
1823*4882a593Smuzhiyun
1824*4882a593Smuzhiyun oldspeed = ha->set_data_rate;
1825*4882a593Smuzhiyun
1826*4882a593Smuzhiyun switch (type) {
1827*4882a593Smuzhiyun case 0:
1828*4882a593Smuzhiyun ha->set_data_rate = PORT_SPEED_AUTO;
1829*4882a593Smuzhiyun break;
1830*4882a593Smuzhiyun case 4:
1831*4882a593Smuzhiyun ha->set_data_rate = PORT_SPEED_4GB;
1832*4882a593Smuzhiyun break;
1833*4882a593Smuzhiyun case 8:
1834*4882a593Smuzhiyun ha->set_data_rate = PORT_SPEED_8GB;
1835*4882a593Smuzhiyun break;
1836*4882a593Smuzhiyun case 16:
1837*4882a593Smuzhiyun ha->set_data_rate = PORT_SPEED_16GB;
1838*4882a593Smuzhiyun break;
1839*4882a593Smuzhiyun case 32:
1840*4882a593Smuzhiyun ha->set_data_rate = PORT_SPEED_32GB;
1841*4882a593Smuzhiyun break;
1842*4882a593Smuzhiyun default:
1843*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x1199,
1844*4882a593Smuzhiyun "Unrecognized speed setting:%lx. Setting Autoneg\n",
1845*4882a593Smuzhiyun speed);
1846*4882a593Smuzhiyun ha->set_data_rate = PORT_SPEED_AUTO;
1847*4882a593Smuzhiyun }
1848*4882a593Smuzhiyun
1849*4882a593Smuzhiyun if (qla2x00_chip_is_down(vha) || (oldspeed == ha->set_data_rate))
1850*4882a593Smuzhiyun return -EINVAL;
1851*4882a593Smuzhiyun
1852*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x70da,
1853*4882a593Smuzhiyun "Setting speed to %lx Gbps \n", type);
1854*4882a593Smuzhiyun
1855*4882a593Smuzhiyun rval = qla2x00_set_data_rate(vha, mode);
1856*4882a593Smuzhiyun if (rval != QLA_SUCCESS)
1857*4882a593Smuzhiyun return -EIO;
1858*4882a593Smuzhiyun
1859*4882a593Smuzhiyun return strlen(buf);
1860*4882a593Smuzhiyun }
1861*4882a593Smuzhiyun
1862*4882a593Smuzhiyun static const struct {
1863*4882a593Smuzhiyun u16 rate;
1864*4882a593Smuzhiyun char *str;
1865*4882a593Smuzhiyun } port_speed_str[] = {
1866*4882a593Smuzhiyun { PORT_SPEED_4GB, "4" },
1867*4882a593Smuzhiyun { PORT_SPEED_8GB, "8" },
1868*4882a593Smuzhiyun { PORT_SPEED_16GB, "16" },
1869*4882a593Smuzhiyun { PORT_SPEED_32GB, "32" },
1870*4882a593Smuzhiyun { PORT_SPEED_64GB, "64" },
1871*4882a593Smuzhiyun { PORT_SPEED_10GB, "10" },
1872*4882a593Smuzhiyun };
1873*4882a593Smuzhiyun
1874*4882a593Smuzhiyun static ssize_t
qla2x00_port_speed_show(struct device * dev,struct device_attribute * attr,char * buf)1875*4882a593Smuzhiyun qla2x00_port_speed_show(struct device *dev, struct device_attribute *attr,
1876*4882a593Smuzhiyun char *buf)
1877*4882a593Smuzhiyun {
1878*4882a593Smuzhiyun struct scsi_qla_host *vha = shost_priv(dev_to_shost(dev));
1879*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
1880*4882a593Smuzhiyun ssize_t rval;
1881*4882a593Smuzhiyun u16 i;
1882*4882a593Smuzhiyun char *speed = "Unknown";
1883*4882a593Smuzhiyun
1884*4882a593Smuzhiyun rval = qla2x00_get_data_rate(vha);
1885*4882a593Smuzhiyun if (rval != QLA_SUCCESS) {
1886*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x70db,
1887*4882a593Smuzhiyun "Unable to get port speed rval:%zd\n", rval);
1888*4882a593Smuzhiyun return -EINVAL;
1889*4882a593Smuzhiyun }
1890*4882a593Smuzhiyun
1891*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(port_speed_str); i++) {
1892*4882a593Smuzhiyun if (port_speed_str[i].rate != ha->link_data_rate)
1893*4882a593Smuzhiyun continue;
1894*4882a593Smuzhiyun speed = port_speed_str[i].str;
1895*4882a593Smuzhiyun break;
1896*4882a593Smuzhiyun }
1897*4882a593Smuzhiyun
1898*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%s\n", speed);
1899*4882a593Smuzhiyun }
1900*4882a593Smuzhiyun
1901*4882a593Smuzhiyun /* ----- */
1902*4882a593Smuzhiyun
1903*4882a593Smuzhiyun static ssize_t
qlini_mode_show(struct device * dev,struct device_attribute * attr,char * buf)1904*4882a593Smuzhiyun qlini_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
1905*4882a593Smuzhiyun {
1906*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1907*4882a593Smuzhiyun int len = 0;
1908*4882a593Smuzhiyun
1909*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len,
1910*4882a593Smuzhiyun "Supported options: enabled | disabled | dual | exclusive\n");
1911*4882a593Smuzhiyun
1912*4882a593Smuzhiyun /* --- */
1913*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len, "Current selection: ");
1914*4882a593Smuzhiyun
1915*4882a593Smuzhiyun switch (vha->qlini_mode) {
1916*4882a593Smuzhiyun case QLA2XXX_INI_MODE_EXCLUSIVE:
1917*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len,
1918*4882a593Smuzhiyun QLA2XXX_INI_MODE_STR_EXCLUSIVE);
1919*4882a593Smuzhiyun break;
1920*4882a593Smuzhiyun case QLA2XXX_INI_MODE_DISABLED:
1921*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len,
1922*4882a593Smuzhiyun QLA2XXX_INI_MODE_STR_DISABLED);
1923*4882a593Smuzhiyun break;
1924*4882a593Smuzhiyun case QLA2XXX_INI_MODE_ENABLED:
1925*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len,
1926*4882a593Smuzhiyun QLA2XXX_INI_MODE_STR_ENABLED);
1927*4882a593Smuzhiyun break;
1928*4882a593Smuzhiyun case QLA2XXX_INI_MODE_DUAL:
1929*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len,
1930*4882a593Smuzhiyun QLA2XXX_INI_MODE_STR_DUAL);
1931*4882a593Smuzhiyun break;
1932*4882a593Smuzhiyun }
1933*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len, "\n");
1934*4882a593Smuzhiyun
1935*4882a593Smuzhiyun return len;
1936*4882a593Smuzhiyun }
1937*4882a593Smuzhiyun
1938*4882a593Smuzhiyun static char *mode_to_str[] = {
1939*4882a593Smuzhiyun "exclusive",
1940*4882a593Smuzhiyun "disabled",
1941*4882a593Smuzhiyun "enabled",
1942*4882a593Smuzhiyun "dual",
1943*4882a593Smuzhiyun };
1944*4882a593Smuzhiyun
1945*4882a593Smuzhiyun #define NEED_EXCH_OFFLOAD(_exchg) ((_exchg) > FW_DEF_EXCHANGES_CNT)
qla_set_ini_mode(scsi_qla_host_t * vha,int op)1946*4882a593Smuzhiyun static void qla_set_ini_mode(scsi_qla_host_t *vha, int op)
1947*4882a593Smuzhiyun {
1948*4882a593Smuzhiyun enum {
1949*4882a593Smuzhiyun NO_ACTION,
1950*4882a593Smuzhiyun MODE_CHANGE_ACCEPT,
1951*4882a593Smuzhiyun MODE_CHANGE_NO_ACTION,
1952*4882a593Smuzhiyun TARGET_STILL_ACTIVE,
1953*4882a593Smuzhiyun };
1954*4882a593Smuzhiyun int action = NO_ACTION;
1955*4882a593Smuzhiyun int set_mode = 0;
1956*4882a593Smuzhiyun u8 eo_toggle = 0; /* exchange offload flipped */
1957*4882a593Smuzhiyun
1958*4882a593Smuzhiyun switch (vha->qlini_mode) {
1959*4882a593Smuzhiyun case QLA2XXX_INI_MODE_DISABLED:
1960*4882a593Smuzhiyun switch (op) {
1961*4882a593Smuzhiyun case QLA2XXX_INI_MODE_DISABLED:
1962*4882a593Smuzhiyun if (qla_tgt_mode_enabled(vha)) {
1963*4882a593Smuzhiyun if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1964*4882a593Smuzhiyun vha->hw->flags.exchoffld_enabled)
1965*4882a593Smuzhiyun eo_toggle = 1;
1966*4882a593Smuzhiyun if (((vha->ql2xexchoffld !=
1967*4882a593Smuzhiyun vha->u_ql2xexchoffld) &&
1968*4882a593Smuzhiyun NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1969*4882a593Smuzhiyun eo_toggle) {
1970*4882a593Smuzhiyun /*
1971*4882a593Smuzhiyun * The number of exchange to be offload
1972*4882a593Smuzhiyun * was tweaked or offload option was
1973*4882a593Smuzhiyun * flipped
1974*4882a593Smuzhiyun */
1975*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
1976*4882a593Smuzhiyun } else {
1977*4882a593Smuzhiyun action = MODE_CHANGE_NO_ACTION;
1978*4882a593Smuzhiyun }
1979*4882a593Smuzhiyun } else {
1980*4882a593Smuzhiyun action = MODE_CHANGE_NO_ACTION;
1981*4882a593Smuzhiyun }
1982*4882a593Smuzhiyun break;
1983*4882a593Smuzhiyun case QLA2XXX_INI_MODE_EXCLUSIVE:
1984*4882a593Smuzhiyun if (qla_tgt_mode_enabled(vha)) {
1985*4882a593Smuzhiyun if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1986*4882a593Smuzhiyun vha->hw->flags.exchoffld_enabled)
1987*4882a593Smuzhiyun eo_toggle = 1;
1988*4882a593Smuzhiyun if (((vha->ql2xexchoffld !=
1989*4882a593Smuzhiyun vha->u_ql2xexchoffld) &&
1990*4882a593Smuzhiyun NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1991*4882a593Smuzhiyun eo_toggle) {
1992*4882a593Smuzhiyun /*
1993*4882a593Smuzhiyun * The number of exchange to be offload
1994*4882a593Smuzhiyun * was tweaked or offload option was
1995*4882a593Smuzhiyun * flipped
1996*4882a593Smuzhiyun */
1997*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
1998*4882a593Smuzhiyun } else {
1999*4882a593Smuzhiyun action = MODE_CHANGE_NO_ACTION;
2000*4882a593Smuzhiyun }
2001*4882a593Smuzhiyun } else {
2002*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2003*4882a593Smuzhiyun }
2004*4882a593Smuzhiyun break;
2005*4882a593Smuzhiyun case QLA2XXX_INI_MODE_DUAL:
2006*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2007*4882a593Smuzhiyun /* active_mode is target only, reset it to dual */
2008*4882a593Smuzhiyun if (qla_tgt_mode_enabled(vha)) {
2009*4882a593Smuzhiyun set_mode = 1;
2010*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2011*4882a593Smuzhiyun } else {
2012*4882a593Smuzhiyun action = MODE_CHANGE_NO_ACTION;
2013*4882a593Smuzhiyun }
2014*4882a593Smuzhiyun break;
2015*4882a593Smuzhiyun
2016*4882a593Smuzhiyun case QLA2XXX_INI_MODE_ENABLED:
2017*4882a593Smuzhiyun if (qla_tgt_mode_enabled(vha))
2018*4882a593Smuzhiyun action = TARGET_STILL_ACTIVE;
2019*4882a593Smuzhiyun else {
2020*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2021*4882a593Smuzhiyun set_mode = 1;
2022*4882a593Smuzhiyun }
2023*4882a593Smuzhiyun break;
2024*4882a593Smuzhiyun }
2025*4882a593Smuzhiyun break;
2026*4882a593Smuzhiyun
2027*4882a593Smuzhiyun case QLA2XXX_INI_MODE_EXCLUSIVE:
2028*4882a593Smuzhiyun switch (op) {
2029*4882a593Smuzhiyun case QLA2XXX_INI_MODE_EXCLUSIVE:
2030*4882a593Smuzhiyun if (qla_tgt_mode_enabled(vha)) {
2031*4882a593Smuzhiyun if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
2032*4882a593Smuzhiyun vha->hw->flags.exchoffld_enabled)
2033*4882a593Smuzhiyun eo_toggle = 1;
2034*4882a593Smuzhiyun if (((vha->ql2xexchoffld !=
2035*4882a593Smuzhiyun vha->u_ql2xexchoffld) &&
2036*4882a593Smuzhiyun NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
2037*4882a593Smuzhiyun eo_toggle)
2038*4882a593Smuzhiyun /*
2039*4882a593Smuzhiyun * The number of exchange to be offload
2040*4882a593Smuzhiyun * was tweaked or offload option was
2041*4882a593Smuzhiyun * flipped
2042*4882a593Smuzhiyun */
2043*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2044*4882a593Smuzhiyun else
2045*4882a593Smuzhiyun action = NO_ACTION;
2046*4882a593Smuzhiyun } else
2047*4882a593Smuzhiyun action = NO_ACTION;
2048*4882a593Smuzhiyun
2049*4882a593Smuzhiyun break;
2050*4882a593Smuzhiyun
2051*4882a593Smuzhiyun case QLA2XXX_INI_MODE_DISABLED:
2052*4882a593Smuzhiyun if (qla_tgt_mode_enabled(vha)) {
2053*4882a593Smuzhiyun if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
2054*4882a593Smuzhiyun vha->hw->flags.exchoffld_enabled)
2055*4882a593Smuzhiyun eo_toggle = 1;
2056*4882a593Smuzhiyun if (((vha->ql2xexchoffld !=
2057*4882a593Smuzhiyun vha->u_ql2xexchoffld) &&
2058*4882a593Smuzhiyun NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
2059*4882a593Smuzhiyun eo_toggle)
2060*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2061*4882a593Smuzhiyun else
2062*4882a593Smuzhiyun action = MODE_CHANGE_NO_ACTION;
2063*4882a593Smuzhiyun } else
2064*4882a593Smuzhiyun action = MODE_CHANGE_NO_ACTION;
2065*4882a593Smuzhiyun break;
2066*4882a593Smuzhiyun
2067*4882a593Smuzhiyun case QLA2XXX_INI_MODE_DUAL: /* exclusive -> dual */
2068*4882a593Smuzhiyun if (qla_tgt_mode_enabled(vha)) {
2069*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2070*4882a593Smuzhiyun set_mode = 1;
2071*4882a593Smuzhiyun } else
2072*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2073*4882a593Smuzhiyun break;
2074*4882a593Smuzhiyun
2075*4882a593Smuzhiyun case QLA2XXX_INI_MODE_ENABLED:
2076*4882a593Smuzhiyun if (qla_tgt_mode_enabled(vha))
2077*4882a593Smuzhiyun action = TARGET_STILL_ACTIVE;
2078*4882a593Smuzhiyun else {
2079*4882a593Smuzhiyun if (vha->hw->flags.fw_started)
2080*4882a593Smuzhiyun action = MODE_CHANGE_NO_ACTION;
2081*4882a593Smuzhiyun else
2082*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2083*4882a593Smuzhiyun }
2084*4882a593Smuzhiyun break;
2085*4882a593Smuzhiyun }
2086*4882a593Smuzhiyun break;
2087*4882a593Smuzhiyun
2088*4882a593Smuzhiyun case QLA2XXX_INI_MODE_ENABLED:
2089*4882a593Smuzhiyun switch (op) {
2090*4882a593Smuzhiyun case QLA2XXX_INI_MODE_ENABLED:
2091*4882a593Smuzhiyun if (NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg) !=
2092*4882a593Smuzhiyun vha->hw->flags.exchoffld_enabled)
2093*4882a593Smuzhiyun eo_toggle = 1;
2094*4882a593Smuzhiyun if (((vha->ql2xiniexchg != vha->u_ql2xiniexchg) &&
2095*4882a593Smuzhiyun NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg)) ||
2096*4882a593Smuzhiyun eo_toggle)
2097*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2098*4882a593Smuzhiyun else
2099*4882a593Smuzhiyun action = NO_ACTION;
2100*4882a593Smuzhiyun break;
2101*4882a593Smuzhiyun case QLA2XXX_INI_MODE_DUAL:
2102*4882a593Smuzhiyun case QLA2XXX_INI_MODE_DISABLED:
2103*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2104*4882a593Smuzhiyun break;
2105*4882a593Smuzhiyun default:
2106*4882a593Smuzhiyun action = MODE_CHANGE_NO_ACTION;
2107*4882a593Smuzhiyun break;
2108*4882a593Smuzhiyun }
2109*4882a593Smuzhiyun break;
2110*4882a593Smuzhiyun
2111*4882a593Smuzhiyun case QLA2XXX_INI_MODE_DUAL:
2112*4882a593Smuzhiyun switch (op) {
2113*4882a593Smuzhiyun case QLA2XXX_INI_MODE_DUAL:
2114*4882a593Smuzhiyun if (qla_tgt_mode_enabled(vha) ||
2115*4882a593Smuzhiyun qla_dual_mode_enabled(vha)) {
2116*4882a593Smuzhiyun if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
2117*4882a593Smuzhiyun vha->u_ql2xiniexchg) !=
2118*4882a593Smuzhiyun vha->hw->flags.exchoffld_enabled)
2119*4882a593Smuzhiyun eo_toggle = 1;
2120*4882a593Smuzhiyun
2121*4882a593Smuzhiyun if ((((vha->ql2xexchoffld +
2122*4882a593Smuzhiyun vha->ql2xiniexchg) !=
2123*4882a593Smuzhiyun (vha->u_ql2xiniexchg +
2124*4882a593Smuzhiyun vha->u_ql2xexchoffld)) &&
2125*4882a593Smuzhiyun NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
2126*4882a593Smuzhiyun vha->u_ql2xexchoffld)) || eo_toggle)
2127*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2128*4882a593Smuzhiyun else
2129*4882a593Smuzhiyun action = NO_ACTION;
2130*4882a593Smuzhiyun } else {
2131*4882a593Smuzhiyun if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
2132*4882a593Smuzhiyun vha->u_ql2xiniexchg) !=
2133*4882a593Smuzhiyun vha->hw->flags.exchoffld_enabled)
2134*4882a593Smuzhiyun eo_toggle = 1;
2135*4882a593Smuzhiyun
2136*4882a593Smuzhiyun if ((((vha->ql2xexchoffld + vha->ql2xiniexchg)
2137*4882a593Smuzhiyun != (vha->u_ql2xiniexchg +
2138*4882a593Smuzhiyun vha->u_ql2xexchoffld)) &&
2139*4882a593Smuzhiyun NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
2140*4882a593Smuzhiyun vha->u_ql2xexchoffld)) || eo_toggle)
2141*4882a593Smuzhiyun action = MODE_CHANGE_NO_ACTION;
2142*4882a593Smuzhiyun else
2143*4882a593Smuzhiyun action = NO_ACTION;
2144*4882a593Smuzhiyun }
2145*4882a593Smuzhiyun break;
2146*4882a593Smuzhiyun
2147*4882a593Smuzhiyun case QLA2XXX_INI_MODE_DISABLED:
2148*4882a593Smuzhiyun if (qla_tgt_mode_enabled(vha) ||
2149*4882a593Smuzhiyun qla_dual_mode_enabled(vha)) {
2150*4882a593Smuzhiyun /* turning off initiator mode */
2151*4882a593Smuzhiyun set_mode = 1;
2152*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2153*4882a593Smuzhiyun } else {
2154*4882a593Smuzhiyun action = MODE_CHANGE_NO_ACTION;
2155*4882a593Smuzhiyun }
2156*4882a593Smuzhiyun break;
2157*4882a593Smuzhiyun
2158*4882a593Smuzhiyun case QLA2XXX_INI_MODE_EXCLUSIVE:
2159*4882a593Smuzhiyun if (qla_tgt_mode_enabled(vha) ||
2160*4882a593Smuzhiyun qla_dual_mode_enabled(vha)) {
2161*4882a593Smuzhiyun set_mode = 1;
2162*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2163*4882a593Smuzhiyun } else {
2164*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2165*4882a593Smuzhiyun }
2166*4882a593Smuzhiyun break;
2167*4882a593Smuzhiyun
2168*4882a593Smuzhiyun case QLA2XXX_INI_MODE_ENABLED:
2169*4882a593Smuzhiyun if (qla_tgt_mode_enabled(vha) ||
2170*4882a593Smuzhiyun qla_dual_mode_enabled(vha)) {
2171*4882a593Smuzhiyun action = TARGET_STILL_ACTIVE;
2172*4882a593Smuzhiyun } else {
2173*4882a593Smuzhiyun action = MODE_CHANGE_ACCEPT;
2174*4882a593Smuzhiyun }
2175*4882a593Smuzhiyun }
2176*4882a593Smuzhiyun break;
2177*4882a593Smuzhiyun }
2178*4882a593Smuzhiyun
2179*4882a593Smuzhiyun switch (action) {
2180*4882a593Smuzhiyun case MODE_CHANGE_ACCEPT:
2181*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0xffff,
2182*4882a593Smuzhiyun "Mode change accepted. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2183*4882a593Smuzhiyun mode_to_str[vha->qlini_mode], mode_to_str[op],
2184*4882a593Smuzhiyun vha->ql2xexchoffld, vha->u_ql2xexchoffld,
2185*4882a593Smuzhiyun vha->ql2xiniexchg, vha->u_ql2xiniexchg);
2186*4882a593Smuzhiyun
2187*4882a593Smuzhiyun vha->qlini_mode = op;
2188*4882a593Smuzhiyun vha->ql2xexchoffld = vha->u_ql2xexchoffld;
2189*4882a593Smuzhiyun vha->ql2xiniexchg = vha->u_ql2xiniexchg;
2190*4882a593Smuzhiyun if (set_mode)
2191*4882a593Smuzhiyun qlt_set_mode(vha);
2192*4882a593Smuzhiyun vha->flags.online = 1;
2193*4882a593Smuzhiyun set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2194*4882a593Smuzhiyun break;
2195*4882a593Smuzhiyun
2196*4882a593Smuzhiyun case MODE_CHANGE_NO_ACTION:
2197*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0xffff,
2198*4882a593Smuzhiyun "Mode is set. No action taken. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2199*4882a593Smuzhiyun mode_to_str[vha->qlini_mode], mode_to_str[op],
2200*4882a593Smuzhiyun vha->ql2xexchoffld, vha->u_ql2xexchoffld,
2201*4882a593Smuzhiyun vha->ql2xiniexchg, vha->u_ql2xiniexchg);
2202*4882a593Smuzhiyun vha->qlini_mode = op;
2203*4882a593Smuzhiyun vha->ql2xexchoffld = vha->u_ql2xexchoffld;
2204*4882a593Smuzhiyun vha->ql2xiniexchg = vha->u_ql2xiniexchg;
2205*4882a593Smuzhiyun break;
2206*4882a593Smuzhiyun
2207*4882a593Smuzhiyun case TARGET_STILL_ACTIVE:
2208*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0xffff,
2209*4882a593Smuzhiyun "Target Mode is active. Unable to change Mode.\n");
2210*4882a593Smuzhiyun break;
2211*4882a593Smuzhiyun
2212*4882a593Smuzhiyun case NO_ACTION:
2213*4882a593Smuzhiyun default:
2214*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0xffff,
2215*4882a593Smuzhiyun "Mode unchange. No action taken. %d|%d pct %d|%d.\n",
2216*4882a593Smuzhiyun vha->qlini_mode, op,
2217*4882a593Smuzhiyun vha->ql2xexchoffld, vha->u_ql2xexchoffld);
2218*4882a593Smuzhiyun break;
2219*4882a593Smuzhiyun }
2220*4882a593Smuzhiyun }
2221*4882a593Smuzhiyun
2222*4882a593Smuzhiyun static ssize_t
qlini_mode_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)2223*4882a593Smuzhiyun qlini_mode_store(struct device *dev, struct device_attribute *attr,
2224*4882a593Smuzhiyun const char *buf, size_t count)
2225*4882a593Smuzhiyun {
2226*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2227*4882a593Smuzhiyun int ini;
2228*4882a593Smuzhiyun
2229*4882a593Smuzhiyun if (!buf)
2230*4882a593Smuzhiyun return -EINVAL;
2231*4882a593Smuzhiyun
2232*4882a593Smuzhiyun if (strncasecmp(QLA2XXX_INI_MODE_STR_EXCLUSIVE, buf,
2233*4882a593Smuzhiyun strlen(QLA2XXX_INI_MODE_STR_EXCLUSIVE)) == 0)
2234*4882a593Smuzhiyun ini = QLA2XXX_INI_MODE_EXCLUSIVE;
2235*4882a593Smuzhiyun else if (strncasecmp(QLA2XXX_INI_MODE_STR_DISABLED, buf,
2236*4882a593Smuzhiyun strlen(QLA2XXX_INI_MODE_STR_DISABLED)) == 0)
2237*4882a593Smuzhiyun ini = QLA2XXX_INI_MODE_DISABLED;
2238*4882a593Smuzhiyun else if (strncasecmp(QLA2XXX_INI_MODE_STR_ENABLED, buf,
2239*4882a593Smuzhiyun strlen(QLA2XXX_INI_MODE_STR_ENABLED)) == 0)
2240*4882a593Smuzhiyun ini = QLA2XXX_INI_MODE_ENABLED;
2241*4882a593Smuzhiyun else if (strncasecmp(QLA2XXX_INI_MODE_STR_DUAL, buf,
2242*4882a593Smuzhiyun strlen(QLA2XXX_INI_MODE_STR_DUAL)) == 0)
2243*4882a593Smuzhiyun ini = QLA2XXX_INI_MODE_DUAL;
2244*4882a593Smuzhiyun else
2245*4882a593Smuzhiyun return -EINVAL;
2246*4882a593Smuzhiyun
2247*4882a593Smuzhiyun qla_set_ini_mode(vha, ini);
2248*4882a593Smuzhiyun return strlen(buf);
2249*4882a593Smuzhiyun }
2250*4882a593Smuzhiyun
2251*4882a593Smuzhiyun static ssize_t
ql2xexchoffld_show(struct device * dev,struct device_attribute * attr,char * buf)2252*4882a593Smuzhiyun ql2xexchoffld_show(struct device *dev, struct device_attribute *attr,
2253*4882a593Smuzhiyun char *buf)
2254*4882a593Smuzhiyun {
2255*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2256*4882a593Smuzhiyun int len = 0;
2257*4882a593Smuzhiyun
2258*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len,
2259*4882a593Smuzhiyun "target exchange: new %d : current: %d\n\n",
2260*4882a593Smuzhiyun vha->u_ql2xexchoffld, vha->ql2xexchoffld);
2261*4882a593Smuzhiyun
2262*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len,
2263*4882a593Smuzhiyun "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2264*4882a593Smuzhiyun vha->host_no);
2265*4882a593Smuzhiyun
2266*4882a593Smuzhiyun return len;
2267*4882a593Smuzhiyun }
2268*4882a593Smuzhiyun
2269*4882a593Smuzhiyun static ssize_t
ql2xexchoffld_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)2270*4882a593Smuzhiyun ql2xexchoffld_store(struct device *dev, struct device_attribute *attr,
2271*4882a593Smuzhiyun const char *buf, size_t count)
2272*4882a593Smuzhiyun {
2273*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2274*4882a593Smuzhiyun int val = 0;
2275*4882a593Smuzhiyun
2276*4882a593Smuzhiyun if (sscanf(buf, "%d", &val) != 1)
2277*4882a593Smuzhiyun return -EINVAL;
2278*4882a593Smuzhiyun
2279*4882a593Smuzhiyun if (val > FW_MAX_EXCHANGES_CNT)
2280*4882a593Smuzhiyun val = FW_MAX_EXCHANGES_CNT;
2281*4882a593Smuzhiyun else if (val < 0)
2282*4882a593Smuzhiyun val = 0;
2283*4882a593Smuzhiyun
2284*4882a593Smuzhiyun vha->u_ql2xexchoffld = val;
2285*4882a593Smuzhiyun return strlen(buf);
2286*4882a593Smuzhiyun }
2287*4882a593Smuzhiyun
2288*4882a593Smuzhiyun static ssize_t
ql2xiniexchg_show(struct device * dev,struct device_attribute * attr,char * buf)2289*4882a593Smuzhiyun ql2xiniexchg_show(struct device *dev, struct device_attribute *attr,
2290*4882a593Smuzhiyun char *buf)
2291*4882a593Smuzhiyun {
2292*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2293*4882a593Smuzhiyun int len = 0;
2294*4882a593Smuzhiyun
2295*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len,
2296*4882a593Smuzhiyun "target exchange: new %d : current: %d\n\n",
2297*4882a593Smuzhiyun vha->u_ql2xiniexchg, vha->ql2xiniexchg);
2298*4882a593Smuzhiyun
2299*4882a593Smuzhiyun len += scnprintf(buf + len, PAGE_SIZE-len,
2300*4882a593Smuzhiyun "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2301*4882a593Smuzhiyun vha->host_no);
2302*4882a593Smuzhiyun
2303*4882a593Smuzhiyun return len;
2304*4882a593Smuzhiyun }
2305*4882a593Smuzhiyun
2306*4882a593Smuzhiyun static ssize_t
ql2xiniexchg_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)2307*4882a593Smuzhiyun ql2xiniexchg_store(struct device *dev, struct device_attribute *attr,
2308*4882a593Smuzhiyun const char *buf, size_t count)
2309*4882a593Smuzhiyun {
2310*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2311*4882a593Smuzhiyun int val = 0;
2312*4882a593Smuzhiyun
2313*4882a593Smuzhiyun if (sscanf(buf, "%d", &val) != 1)
2314*4882a593Smuzhiyun return -EINVAL;
2315*4882a593Smuzhiyun
2316*4882a593Smuzhiyun if (val > FW_MAX_EXCHANGES_CNT)
2317*4882a593Smuzhiyun val = FW_MAX_EXCHANGES_CNT;
2318*4882a593Smuzhiyun else if (val < 0)
2319*4882a593Smuzhiyun val = 0;
2320*4882a593Smuzhiyun
2321*4882a593Smuzhiyun vha->u_ql2xiniexchg = val;
2322*4882a593Smuzhiyun return strlen(buf);
2323*4882a593Smuzhiyun }
2324*4882a593Smuzhiyun
2325*4882a593Smuzhiyun static ssize_t
qla2x00_dif_bundle_statistics_show(struct device * dev,struct device_attribute * attr,char * buf)2326*4882a593Smuzhiyun qla2x00_dif_bundle_statistics_show(struct device *dev,
2327*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
2328*4882a593Smuzhiyun {
2329*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2330*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
2331*4882a593Smuzhiyun
2332*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE,
2333*4882a593Smuzhiyun "cross=%llu read=%llu write=%llu kalloc=%llu dma_alloc=%llu unusable=%u\n",
2334*4882a593Smuzhiyun ha->dif_bundle_crossed_pages, ha->dif_bundle_reads,
2335*4882a593Smuzhiyun ha->dif_bundle_writes, ha->dif_bundle_kallocs,
2336*4882a593Smuzhiyun ha->dif_bundle_dma_allocs, ha->pool.unusable.count);
2337*4882a593Smuzhiyun }
2338*4882a593Smuzhiyun
2339*4882a593Smuzhiyun static ssize_t
qla2x00_fw_attr_show(struct device * dev,struct device_attribute * attr,char * buf)2340*4882a593Smuzhiyun qla2x00_fw_attr_show(struct device *dev,
2341*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
2342*4882a593Smuzhiyun {
2343*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2344*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
2345*4882a593Smuzhiyun
2346*4882a593Smuzhiyun if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
2347*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
2348*4882a593Smuzhiyun
2349*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%llx\n",
2350*4882a593Smuzhiyun (uint64_t)ha->fw_attributes_ext[1] << 48 |
2351*4882a593Smuzhiyun (uint64_t)ha->fw_attributes_ext[0] << 32 |
2352*4882a593Smuzhiyun (uint64_t)ha->fw_attributes_h << 16 |
2353*4882a593Smuzhiyun (uint64_t)ha->fw_attributes);
2354*4882a593Smuzhiyun }
2355*4882a593Smuzhiyun
2356*4882a593Smuzhiyun static ssize_t
qla2x00_port_no_show(struct device * dev,struct device_attribute * attr,char * buf)2357*4882a593Smuzhiyun qla2x00_port_no_show(struct device *dev, struct device_attribute *attr,
2358*4882a593Smuzhiyun char *buf)
2359*4882a593Smuzhiyun {
2360*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2361*4882a593Smuzhiyun
2362*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%u\n", vha->hw->port_no);
2363*4882a593Smuzhiyun }
2364*4882a593Smuzhiyun
2365*4882a593Smuzhiyun static ssize_t
qla2x00_dport_diagnostics_show(struct device * dev,struct device_attribute * attr,char * buf)2366*4882a593Smuzhiyun qla2x00_dport_diagnostics_show(struct device *dev,
2367*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
2368*4882a593Smuzhiyun {
2369*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2370*4882a593Smuzhiyun
2371*4882a593Smuzhiyun if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw) &&
2372*4882a593Smuzhiyun !IS_QLA28XX(vha->hw))
2373*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
2374*4882a593Smuzhiyun
2375*4882a593Smuzhiyun if (!*vha->dport_data)
2376*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
2377*4882a593Smuzhiyun
2378*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
2379*4882a593Smuzhiyun vha->dport_data[0], vha->dport_data[1],
2380*4882a593Smuzhiyun vha->dport_data[2], vha->dport_data[3]);
2381*4882a593Smuzhiyun }
2382*4882a593Smuzhiyun static DEVICE_ATTR(dport_diagnostics, 0444,
2383*4882a593Smuzhiyun qla2x00_dport_diagnostics_show, NULL);
2384*4882a593Smuzhiyun
2385*4882a593Smuzhiyun static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_driver_version_show, NULL);
2386*4882a593Smuzhiyun static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
2387*4882a593Smuzhiyun static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
2388*4882a593Smuzhiyun static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
2389*4882a593Smuzhiyun static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
2390*4882a593Smuzhiyun static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
2391*4882a593Smuzhiyun static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
2392*4882a593Smuzhiyun static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
2393*4882a593Smuzhiyun static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
2394*4882a593Smuzhiyun static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
2395*4882a593Smuzhiyun static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
2396*4882a593Smuzhiyun qla2x00_zio_timer_store);
2397*4882a593Smuzhiyun static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
2398*4882a593Smuzhiyun qla2x00_beacon_store);
2399*4882a593Smuzhiyun static DEVICE_ATTR(beacon_config, 0644, qla2x00_beacon_config_show,
2400*4882a593Smuzhiyun qla2x00_beacon_config_store);
2401*4882a593Smuzhiyun static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
2402*4882a593Smuzhiyun qla2x00_optrom_bios_version_show, NULL);
2403*4882a593Smuzhiyun static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
2404*4882a593Smuzhiyun qla2x00_optrom_efi_version_show, NULL);
2405*4882a593Smuzhiyun static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
2406*4882a593Smuzhiyun qla2x00_optrom_fcode_version_show, NULL);
2407*4882a593Smuzhiyun static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
2408*4882a593Smuzhiyun NULL);
2409*4882a593Smuzhiyun static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
2410*4882a593Smuzhiyun qla2x00_optrom_gold_fw_version_show, NULL);
2411*4882a593Smuzhiyun static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
2412*4882a593Smuzhiyun NULL);
2413*4882a593Smuzhiyun static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
2414*4882a593Smuzhiyun NULL);
2415*4882a593Smuzhiyun static DEVICE_ATTR(serdes_version, 0444, qla2x00_serdes_version_show, NULL);
2416*4882a593Smuzhiyun static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
2417*4882a593Smuzhiyun static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
2418*4882a593Smuzhiyun static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
2419*4882a593Smuzhiyun NULL);
2420*4882a593Smuzhiyun static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
2421*4882a593Smuzhiyun static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
2422*4882a593Smuzhiyun qla2x00_vn_port_mac_address_show, NULL);
2423*4882a593Smuzhiyun static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
2424*4882a593Smuzhiyun static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
2425*4882a593Smuzhiyun static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
2426*4882a593Smuzhiyun static DEVICE_ATTR(diag_requests, S_IRUGO, qla2x00_diag_requests_show, NULL);
2427*4882a593Smuzhiyun static DEVICE_ATTR(diag_megabytes, S_IRUGO, qla2x00_diag_megabytes_show, NULL);
2428*4882a593Smuzhiyun static DEVICE_ATTR(fw_dump_size, S_IRUGO, qla2x00_fw_dump_size_show, NULL);
2429*4882a593Smuzhiyun static DEVICE_ATTR(allow_cna_fw_dump, S_IRUGO | S_IWUSR,
2430*4882a593Smuzhiyun qla2x00_allow_cna_fw_dump_show,
2431*4882a593Smuzhiyun qla2x00_allow_cna_fw_dump_store);
2432*4882a593Smuzhiyun static DEVICE_ATTR(pep_version, S_IRUGO, qla2x00_pep_version_show, NULL);
2433*4882a593Smuzhiyun static DEVICE_ATTR(min_supported_speed, 0444,
2434*4882a593Smuzhiyun qla2x00_min_supported_speed_show, NULL);
2435*4882a593Smuzhiyun static DEVICE_ATTR(max_supported_speed, 0444,
2436*4882a593Smuzhiyun qla2x00_max_supported_speed_show, NULL);
2437*4882a593Smuzhiyun static DEVICE_ATTR(zio_threshold, 0644,
2438*4882a593Smuzhiyun qla_zio_threshold_show,
2439*4882a593Smuzhiyun qla_zio_threshold_store);
2440*4882a593Smuzhiyun static DEVICE_ATTR_RW(qlini_mode);
2441*4882a593Smuzhiyun static DEVICE_ATTR_RW(ql2xexchoffld);
2442*4882a593Smuzhiyun static DEVICE_ATTR_RW(ql2xiniexchg);
2443*4882a593Smuzhiyun static DEVICE_ATTR(dif_bundle_statistics, 0444,
2444*4882a593Smuzhiyun qla2x00_dif_bundle_statistics_show, NULL);
2445*4882a593Smuzhiyun static DEVICE_ATTR(port_speed, 0644, qla2x00_port_speed_show,
2446*4882a593Smuzhiyun qla2x00_port_speed_store);
2447*4882a593Smuzhiyun static DEVICE_ATTR(port_no, 0444, qla2x00_port_no_show, NULL);
2448*4882a593Smuzhiyun static DEVICE_ATTR(fw_attr, 0444, qla2x00_fw_attr_show, NULL);
2449*4882a593Smuzhiyun
2450*4882a593Smuzhiyun
2451*4882a593Smuzhiyun struct device_attribute *qla2x00_host_attrs[] = {
2452*4882a593Smuzhiyun &dev_attr_driver_version,
2453*4882a593Smuzhiyun &dev_attr_fw_version,
2454*4882a593Smuzhiyun &dev_attr_serial_num,
2455*4882a593Smuzhiyun &dev_attr_isp_name,
2456*4882a593Smuzhiyun &dev_attr_isp_id,
2457*4882a593Smuzhiyun &dev_attr_model_name,
2458*4882a593Smuzhiyun &dev_attr_model_desc,
2459*4882a593Smuzhiyun &dev_attr_pci_info,
2460*4882a593Smuzhiyun &dev_attr_link_state,
2461*4882a593Smuzhiyun &dev_attr_zio,
2462*4882a593Smuzhiyun &dev_attr_zio_timer,
2463*4882a593Smuzhiyun &dev_attr_beacon,
2464*4882a593Smuzhiyun &dev_attr_beacon_config,
2465*4882a593Smuzhiyun &dev_attr_optrom_bios_version,
2466*4882a593Smuzhiyun &dev_attr_optrom_efi_version,
2467*4882a593Smuzhiyun &dev_attr_optrom_fcode_version,
2468*4882a593Smuzhiyun &dev_attr_optrom_fw_version,
2469*4882a593Smuzhiyun &dev_attr_84xx_fw_version,
2470*4882a593Smuzhiyun &dev_attr_total_isp_aborts,
2471*4882a593Smuzhiyun &dev_attr_serdes_version,
2472*4882a593Smuzhiyun &dev_attr_mpi_version,
2473*4882a593Smuzhiyun &dev_attr_phy_version,
2474*4882a593Smuzhiyun &dev_attr_flash_block_size,
2475*4882a593Smuzhiyun &dev_attr_vlan_id,
2476*4882a593Smuzhiyun &dev_attr_vn_port_mac_address,
2477*4882a593Smuzhiyun &dev_attr_fabric_param,
2478*4882a593Smuzhiyun &dev_attr_fw_state,
2479*4882a593Smuzhiyun &dev_attr_optrom_gold_fw_version,
2480*4882a593Smuzhiyun &dev_attr_thermal_temp,
2481*4882a593Smuzhiyun &dev_attr_diag_requests,
2482*4882a593Smuzhiyun &dev_attr_diag_megabytes,
2483*4882a593Smuzhiyun &dev_attr_fw_dump_size,
2484*4882a593Smuzhiyun &dev_attr_allow_cna_fw_dump,
2485*4882a593Smuzhiyun &dev_attr_pep_version,
2486*4882a593Smuzhiyun &dev_attr_min_supported_speed,
2487*4882a593Smuzhiyun &dev_attr_max_supported_speed,
2488*4882a593Smuzhiyun &dev_attr_zio_threshold,
2489*4882a593Smuzhiyun &dev_attr_dif_bundle_statistics,
2490*4882a593Smuzhiyun &dev_attr_port_speed,
2491*4882a593Smuzhiyun &dev_attr_port_no,
2492*4882a593Smuzhiyun &dev_attr_fw_attr,
2493*4882a593Smuzhiyun &dev_attr_dport_diagnostics,
2494*4882a593Smuzhiyun NULL, /* reserve for qlini_mode */
2495*4882a593Smuzhiyun NULL, /* reserve for ql2xiniexchg */
2496*4882a593Smuzhiyun NULL, /* reserve for ql2xexchoffld */
2497*4882a593Smuzhiyun NULL,
2498*4882a593Smuzhiyun };
2499*4882a593Smuzhiyun
qla_insert_tgt_attrs(void)2500*4882a593Smuzhiyun void qla_insert_tgt_attrs(void)
2501*4882a593Smuzhiyun {
2502*4882a593Smuzhiyun struct device_attribute **attr;
2503*4882a593Smuzhiyun
2504*4882a593Smuzhiyun /* advance to empty slot */
2505*4882a593Smuzhiyun for (attr = &qla2x00_host_attrs[0]; *attr; ++attr)
2506*4882a593Smuzhiyun continue;
2507*4882a593Smuzhiyun
2508*4882a593Smuzhiyun *attr = &dev_attr_qlini_mode;
2509*4882a593Smuzhiyun attr++;
2510*4882a593Smuzhiyun *attr = &dev_attr_ql2xiniexchg;
2511*4882a593Smuzhiyun attr++;
2512*4882a593Smuzhiyun *attr = &dev_attr_ql2xexchoffld;
2513*4882a593Smuzhiyun }
2514*4882a593Smuzhiyun
2515*4882a593Smuzhiyun /* Host attributes. */
2516*4882a593Smuzhiyun
2517*4882a593Smuzhiyun static void
qla2x00_get_host_port_id(struct Scsi_Host * shost)2518*4882a593Smuzhiyun qla2x00_get_host_port_id(struct Scsi_Host *shost)
2519*4882a593Smuzhiyun {
2520*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(shost);
2521*4882a593Smuzhiyun
2522*4882a593Smuzhiyun fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
2523*4882a593Smuzhiyun vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
2524*4882a593Smuzhiyun }
2525*4882a593Smuzhiyun
2526*4882a593Smuzhiyun static void
qla2x00_get_host_speed(struct Scsi_Host * shost)2527*4882a593Smuzhiyun qla2x00_get_host_speed(struct Scsi_Host *shost)
2528*4882a593Smuzhiyun {
2529*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(shost);
2530*4882a593Smuzhiyun u32 speed;
2531*4882a593Smuzhiyun
2532*4882a593Smuzhiyun if (IS_QLAFX00(vha->hw)) {
2533*4882a593Smuzhiyun qlafx00_get_host_speed(shost);
2534*4882a593Smuzhiyun return;
2535*4882a593Smuzhiyun }
2536*4882a593Smuzhiyun
2537*4882a593Smuzhiyun switch (vha->hw->link_data_rate) {
2538*4882a593Smuzhiyun case PORT_SPEED_1GB:
2539*4882a593Smuzhiyun speed = FC_PORTSPEED_1GBIT;
2540*4882a593Smuzhiyun break;
2541*4882a593Smuzhiyun case PORT_SPEED_2GB:
2542*4882a593Smuzhiyun speed = FC_PORTSPEED_2GBIT;
2543*4882a593Smuzhiyun break;
2544*4882a593Smuzhiyun case PORT_SPEED_4GB:
2545*4882a593Smuzhiyun speed = FC_PORTSPEED_4GBIT;
2546*4882a593Smuzhiyun break;
2547*4882a593Smuzhiyun case PORT_SPEED_8GB:
2548*4882a593Smuzhiyun speed = FC_PORTSPEED_8GBIT;
2549*4882a593Smuzhiyun break;
2550*4882a593Smuzhiyun case PORT_SPEED_10GB:
2551*4882a593Smuzhiyun speed = FC_PORTSPEED_10GBIT;
2552*4882a593Smuzhiyun break;
2553*4882a593Smuzhiyun case PORT_SPEED_16GB:
2554*4882a593Smuzhiyun speed = FC_PORTSPEED_16GBIT;
2555*4882a593Smuzhiyun break;
2556*4882a593Smuzhiyun case PORT_SPEED_32GB:
2557*4882a593Smuzhiyun speed = FC_PORTSPEED_32GBIT;
2558*4882a593Smuzhiyun break;
2559*4882a593Smuzhiyun case PORT_SPEED_64GB:
2560*4882a593Smuzhiyun speed = FC_PORTSPEED_64GBIT;
2561*4882a593Smuzhiyun break;
2562*4882a593Smuzhiyun default:
2563*4882a593Smuzhiyun speed = FC_PORTSPEED_UNKNOWN;
2564*4882a593Smuzhiyun break;
2565*4882a593Smuzhiyun }
2566*4882a593Smuzhiyun
2567*4882a593Smuzhiyun fc_host_speed(shost) = speed;
2568*4882a593Smuzhiyun }
2569*4882a593Smuzhiyun
2570*4882a593Smuzhiyun static void
qla2x00_get_host_port_type(struct Scsi_Host * shost)2571*4882a593Smuzhiyun qla2x00_get_host_port_type(struct Scsi_Host *shost)
2572*4882a593Smuzhiyun {
2573*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(shost);
2574*4882a593Smuzhiyun uint32_t port_type;
2575*4882a593Smuzhiyun
2576*4882a593Smuzhiyun if (vha->vp_idx) {
2577*4882a593Smuzhiyun fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
2578*4882a593Smuzhiyun return;
2579*4882a593Smuzhiyun }
2580*4882a593Smuzhiyun switch (vha->hw->current_topology) {
2581*4882a593Smuzhiyun case ISP_CFG_NL:
2582*4882a593Smuzhiyun port_type = FC_PORTTYPE_LPORT;
2583*4882a593Smuzhiyun break;
2584*4882a593Smuzhiyun case ISP_CFG_FL:
2585*4882a593Smuzhiyun port_type = FC_PORTTYPE_NLPORT;
2586*4882a593Smuzhiyun break;
2587*4882a593Smuzhiyun case ISP_CFG_N:
2588*4882a593Smuzhiyun port_type = FC_PORTTYPE_PTP;
2589*4882a593Smuzhiyun break;
2590*4882a593Smuzhiyun case ISP_CFG_F:
2591*4882a593Smuzhiyun port_type = FC_PORTTYPE_NPORT;
2592*4882a593Smuzhiyun break;
2593*4882a593Smuzhiyun default:
2594*4882a593Smuzhiyun port_type = FC_PORTTYPE_UNKNOWN;
2595*4882a593Smuzhiyun break;
2596*4882a593Smuzhiyun }
2597*4882a593Smuzhiyun
2598*4882a593Smuzhiyun fc_host_port_type(shost) = port_type;
2599*4882a593Smuzhiyun }
2600*4882a593Smuzhiyun
2601*4882a593Smuzhiyun static void
qla2x00_get_starget_node_name(struct scsi_target * starget)2602*4882a593Smuzhiyun qla2x00_get_starget_node_name(struct scsi_target *starget)
2603*4882a593Smuzhiyun {
2604*4882a593Smuzhiyun struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2605*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(host);
2606*4882a593Smuzhiyun fc_port_t *fcport;
2607*4882a593Smuzhiyun u64 node_name = 0;
2608*4882a593Smuzhiyun
2609*4882a593Smuzhiyun list_for_each_entry(fcport, &vha->vp_fcports, list) {
2610*4882a593Smuzhiyun if (fcport->rport &&
2611*4882a593Smuzhiyun starget->id == fcport->rport->scsi_target_id) {
2612*4882a593Smuzhiyun node_name = wwn_to_u64(fcport->node_name);
2613*4882a593Smuzhiyun break;
2614*4882a593Smuzhiyun }
2615*4882a593Smuzhiyun }
2616*4882a593Smuzhiyun
2617*4882a593Smuzhiyun fc_starget_node_name(starget) = node_name;
2618*4882a593Smuzhiyun }
2619*4882a593Smuzhiyun
2620*4882a593Smuzhiyun static void
qla2x00_get_starget_port_name(struct scsi_target * starget)2621*4882a593Smuzhiyun qla2x00_get_starget_port_name(struct scsi_target *starget)
2622*4882a593Smuzhiyun {
2623*4882a593Smuzhiyun struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2624*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(host);
2625*4882a593Smuzhiyun fc_port_t *fcport;
2626*4882a593Smuzhiyun u64 port_name = 0;
2627*4882a593Smuzhiyun
2628*4882a593Smuzhiyun list_for_each_entry(fcport, &vha->vp_fcports, list) {
2629*4882a593Smuzhiyun if (fcport->rport &&
2630*4882a593Smuzhiyun starget->id == fcport->rport->scsi_target_id) {
2631*4882a593Smuzhiyun port_name = wwn_to_u64(fcport->port_name);
2632*4882a593Smuzhiyun break;
2633*4882a593Smuzhiyun }
2634*4882a593Smuzhiyun }
2635*4882a593Smuzhiyun
2636*4882a593Smuzhiyun fc_starget_port_name(starget) = port_name;
2637*4882a593Smuzhiyun }
2638*4882a593Smuzhiyun
2639*4882a593Smuzhiyun static void
qla2x00_get_starget_port_id(struct scsi_target * starget)2640*4882a593Smuzhiyun qla2x00_get_starget_port_id(struct scsi_target *starget)
2641*4882a593Smuzhiyun {
2642*4882a593Smuzhiyun struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2643*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(host);
2644*4882a593Smuzhiyun fc_port_t *fcport;
2645*4882a593Smuzhiyun uint32_t port_id = ~0U;
2646*4882a593Smuzhiyun
2647*4882a593Smuzhiyun list_for_each_entry(fcport, &vha->vp_fcports, list) {
2648*4882a593Smuzhiyun if (fcport->rport &&
2649*4882a593Smuzhiyun starget->id == fcport->rport->scsi_target_id) {
2650*4882a593Smuzhiyun port_id = fcport->d_id.b.domain << 16 |
2651*4882a593Smuzhiyun fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2652*4882a593Smuzhiyun break;
2653*4882a593Smuzhiyun }
2654*4882a593Smuzhiyun }
2655*4882a593Smuzhiyun
2656*4882a593Smuzhiyun fc_starget_port_id(starget) = port_id;
2657*4882a593Smuzhiyun }
2658*4882a593Smuzhiyun
2659*4882a593Smuzhiyun static inline void
qla2x00_set_rport_loss_tmo(struct fc_rport * rport,uint32_t timeout)2660*4882a593Smuzhiyun qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2661*4882a593Smuzhiyun {
2662*4882a593Smuzhiyun rport->dev_loss_tmo = timeout ? timeout : 1;
2663*4882a593Smuzhiyun }
2664*4882a593Smuzhiyun
2665*4882a593Smuzhiyun static void
qla2x00_dev_loss_tmo_callbk(struct fc_rport * rport)2666*4882a593Smuzhiyun qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
2667*4882a593Smuzhiyun {
2668*4882a593Smuzhiyun struct Scsi_Host *host = rport_to_shost(rport);
2669*4882a593Smuzhiyun fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
2670*4882a593Smuzhiyun unsigned long flags;
2671*4882a593Smuzhiyun
2672*4882a593Smuzhiyun if (!fcport)
2673*4882a593Smuzhiyun return;
2674*4882a593Smuzhiyun
2675*4882a593Smuzhiyun /* Now that the rport has been deleted, set the fcport state to
2676*4882a593Smuzhiyun FCS_DEVICE_DEAD */
2677*4882a593Smuzhiyun qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
2678*4882a593Smuzhiyun
2679*4882a593Smuzhiyun /*
2680*4882a593Smuzhiyun * Transport has effectively 'deleted' the rport, clear
2681*4882a593Smuzhiyun * all local references.
2682*4882a593Smuzhiyun */
2683*4882a593Smuzhiyun spin_lock_irqsave(host->host_lock, flags);
2684*4882a593Smuzhiyun fcport->rport = fcport->drport = NULL;
2685*4882a593Smuzhiyun *((fc_port_t **)rport->dd_data) = NULL;
2686*4882a593Smuzhiyun spin_unlock_irqrestore(host->host_lock, flags);
2687*4882a593Smuzhiyun
2688*4882a593Smuzhiyun if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2689*4882a593Smuzhiyun return;
2690*4882a593Smuzhiyun
2691*4882a593Smuzhiyun if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2692*4882a593Smuzhiyun qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
2693*4882a593Smuzhiyun return;
2694*4882a593Smuzhiyun }
2695*4882a593Smuzhiyun }
2696*4882a593Smuzhiyun
2697*4882a593Smuzhiyun static void
qla2x00_terminate_rport_io(struct fc_rport * rport)2698*4882a593Smuzhiyun qla2x00_terminate_rport_io(struct fc_rport *rport)
2699*4882a593Smuzhiyun {
2700*4882a593Smuzhiyun fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
2701*4882a593Smuzhiyun
2702*4882a593Smuzhiyun if (!fcport)
2703*4882a593Smuzhiyun return;
2704*4882a593Smuzhiyun
2705*4882a593Smuzhiyun if (test_bit(UNLOADING, &fcport->vha->dpc_flags))
2706*4882a593Smuzhiyun return;
2707*4882a593Smuzhiyun
2708*4882a593Smuzhiyun if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2709*4882a593Smuzhiyun return;
2710*4882a593Smuzhiyun
2711*4882a593Smuzhiyun if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2712*4882a593Smuzhiyun qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
2713*4882a593Smuzhiyun return;
2714*4882a593Smuzhiyun }
2715*4882a593Smuzhiyun /*
2716*4882a593Smuzhiyun * At this point all fcport's software-states are cleared. Perform any
2717*4882a593Smuzhiyun * final cleanup of firmware resources (PCBs and XCBs).
2718*4882a593Smuzhiyun */
2719*4882a593Smuzhiyun if (fcport->loop_id != FC_NO_LOOP_ID) {
2720*4882a593Smuzhiyun if (IS_FWI2_CAPABLE(fcport->vha->hw))
2721*4882a593Smuzhiyun fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
2722*4882a593Smuzhiyun fcport->loop_id, fcport->d_id.b.domain,
2723*4882a593Smuzhiyun fcport->d_id.b.area, fcport->d_id.b.al_pa);
2724*4882a593Smuzhiyun else
2725*4882a593Smuzhiyun qla2x00_port_logout(fcport->vha, fcport);
2726*4882a593Smuzhiyun }
2727*4882a593Smuzhiyun }
2728*4882a593Smuzhiyun
2729*4882a593Smuzhiyun static int
qla2x00_issue_lip(struct Scsi_Host * shost)2730*4882a593Smuzhiyun qla2x00_issue_lip(struct Scsi_Host *shost)
2731*4882a593Smuzhiyun {
2732*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(shost);
2733*4882a593Smuzhiyun
2734*4882a593Smuzhiyun if (IS_QLAFX00(vha->hw))
2735*4882a593Smuzhiyun return 0;
2736*4882a593Smuzhiyun
2737*4882a593Smuzhiyun qla2x00_loop_reset(vha);
2738*4882a593Smuzhiyun return 0;
2739*4882a593Smuzhiyun }
2740*4882a593Smuzhiyun
2741*4882a593Smuzhiyun static struct fc_host_statistics *
qla2x00_get_fc_host_stats(struct Scsi_Host * shost)2742*4882a593Smuzhiyun qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
2743*4882a593Smuzhiyun {
2744*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(shost);
2745*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
2746*4882a593Smuzhiyun struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2747*4882a593Smuzhiyun int rval;
2748*4882a593Smuzhiyun struct link_statistics *stats;
2749*4882a593Smuzhiyun dma_addr_t stats_dma;
2750*4882a593Smuzhiyun struct fc_host_statistics *p = &vha->fc_host_stat;
2751*4882a593Smuzhiyun struct qla_qpair *qpair;
2752*4882a593Smuzhiyun int i;
2753*4882a593Smuzhiyun u64 ib = 0, ob = 0, ir = 0, or = 0;
2754*4882a593Smuzhiyun
2755*4882a593Smuzhiyun memset(p, -1, sizeof(*p));
2756*4882a593Smuzhiyun
2757*4882a593Smuzhiyun if (IS_QLAFX00(vha->hw))
2758*4882a593Smuzhiyun goto done;
2759*4882a593Smuzhiyun
2760*4882a593Smuzhiyun if (test_bit(UNLOADING, &vha->dpc_flags))
2761*4882a593Smuzhiyun goto done;
2762*4882a593Smuzhiyun
2763*4882a593Smuzhiyun if (unlikely(pci_channel_offline(ha->pdev)))
2764*4882a593Smuzhiyun goto done;
2765*4882a593Smuzhiyun
2766*4882a593Smuzhiyun if (qla2x00_chip_is_down(vha))
2767*4882a593Smuzhiyun goto done;
2768*4882a593Smuzhiyun
2769*4882a593Smuzhiyun stats = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stats), &stats_dma,
2770*4882a593Smuzhiyun GFP_KERNEL);
2771*4882a593Smuzhiyun if (!stats) {
2772*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x707d,
2773*4882a593Smuzhiyun "Failed to allocate memory for stats.\n");
2774*4882a593Smuzhiyun goto done;
2775*4882a593Smuzhiyun }
2776*4882a593Smuzhiyun
2777*4882a593Smuzhiyun rval = QLA_FUNCTION_FAILED;
2778*4882a593Smuzhiyun if (IS_FWI2_CAPABLE(ha)) {
2779*4882a593Smuzhiyun rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, 0);
2780*4882a593Smuzhiyun } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
2781*4882a593Smuzhiyun !ha->dpc_active) {
2782*4882a593Smuzhiyun /* Must be in a 'READY' state for statistics retrieval. */
2783*4882a593Smuzhiyun rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
2784*4882a593Smuzhiyun stats, stats_dma);
2785*4882a593Smuzhiyun }
2786*4882a593Smuzhiyun
2787*4882a593Smuzhiyun if (rval != QLA_SUCCESS)
2788*4882a593Smuzhiyun goto done_free;
2789*4882a593Smuzhiyun
2790*4882a593Smuzhiyun /* --- */
2791*4882a593Smuzhiyun for (i = 0; i < vha->hw->max_qpairs; i++) {
2792*4882a593Smuzhiyun qpair = vha->hw->queue_pair_map[i];
2793*4882a593Smuzhiyun if (!qpair)
2794*4882a593Smuzhiyun continue;
2795*4882a593Smuzhiyun ir += qpair->counters.input_requests;
2796*4882a593Smuzhiyun or += qpair->counters.output_requests;
2797*4882a593Smuzhiyun ib += qpair->counters.input_bytes;
2798*4882a593Smuzhiyun ob += qpair->counters.output_bytes;
2799*4882a593Smuzhiyun }
2800*4882a593Smuzhiyun ir += ha->base_qpair->counters.input_requests;
2801*4882a593Smuzhiyun or += ha->base_qpair->counters.output_requests;
2802*4882a593Smuzhiyun ib += ha->base_qpair->counters.input_bytes;
2803*4882a593Smuzhiyun ob += ha->base_qpair->counters.output_bytes;
2804*4882a593Smuzhiyun
2805*4882a593Smuzhiyun ir += vha->qla_stats.input_requests;
2806*4882a593Smuzhiyun or += vha->qla_stats.output_requests;
2807*4882a593Smuzhiyun ib += vha->qla_stats.input_bytes;
2808*4882a593Smuzhiyun ob += vha->qla_stats.output_bytes;
2809*4882a593Smuzhiyun /* --- */
2810*4882a593Smuzhiyun
2811*4882a593Smuzhiyun p->link_failure_count = le32_to_cpu(stats->link_fail_cnt);
2812*4882a593Smuzhiyun p->loss_of_sync_count = le32_to_cpu(stats->loss_sync_cnt);
2813*4882a593Smuzhiyun p->loss_of_signal_count = le32_to_cpu(stats->loss_sig_cnt);
2814*4882a593Smuzhiyun p->prim_seq_protocol_err_count = le32_to_cpu(stats->prim_seq_err_cnt);
2815*4882a593Smuzhiyun p->invalid_tx_word_count = le32_to_cpu(stats->inval_xmit_word_cnt);
2816*4882a593Smuzhiyun p->invalid_crc_count = le32_to_cpu(stats->inval_crc_cnt);
2817*4882a593Smuzhiyun if (IS_FWI2_CAPABLE(ha)) {
2818*4882a593Smuzhiyun p->lip_count = le32_to_cpu(stats->lip_cnt);
2819*4882a593Smuzhiyun p->tx_frames = le32_to_cpu(stats->tx_frames);
2820*4882a593Smuzhiyun p->rx_frames = le32_to_cpu(stats->rx_frames);
2821*4882a593Smuzhiyun p->dumped_frames = le32_to_cpu(stats->discarded_frames);
2822*4882a593Smuzhiyun p->nos_count = le32_to_cpu(stats->nos_rcvd);
2823*4882a593Smuzhiyun p->error_frames =
2824*4882a593Smuzhiyun le32_to_cpu(stats->dropped_frames) +
2825*4882a593Smuzhiyun le32_to_cpu(stats->discarded_frames);
2826*4882a593Smuzhiyun if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
2827*4882a593Smuzhiyun p->rx_words = le64_to_cpu(stats->fpm_recv_word_cnt);
2828*4882a593Smuzhiyun p->tx_words = le64_to_cpu(stats->fpm_xmit_word_cnt);
2829*4882a593Smuzhiyun } else {
2830*4882a593Smuzhiyun p->rx_words = ib >> 2;
2831*4882a593Smuzhiyun p->tx_words = ob >> 2;
2832*4882a593Smuzhiyun }
2833*4882a593Smuzhiyun }
2834*4882a593Smuzhiyun
2835*4882a593Smuzhiyun p->fcp_control_requests = vha->qla_stats.control_requests;
2836*4882a593Smuzhiyun p->fcp_input_requests = ir;
2837*4882a593Smuzhiyun p->fcp_output_requests = or;
2838*4882a593Smuzhiyun p->fcp_input_megabytes = ib >> 20;
2839*4882a593Smuzhiyun p->fcp_output_megabytes = ob >> 20;
2840*4882a593Smuzhiyun p->seconds_since_last_reset =
2841*4882a593Smuzhiyun get_jiffies_64() - vha->qla_stats.jiffies_at_last_reset;
2842*4882a593Smuzhiyun do_div(p->seconds_since_last_reset, HZ);
2843*4882a593Smuzhiyun
2844*4882a593Smuzhiyun done_free:
2845*4882a593Smuzhiyun dma_free_coherent(&ha->pdev->dev, sizeof(struct link_statistics),
2846*4882a593Smuzhiyun stats, stats_dma);
2847*4882a593Smuzhiyun done:
2848*4882a593Smuzhiyun return p;
2849*4882a593Smuzhiyun }
2850*4882a593Smuzhiyun
2851*4882a593Smuzhiyun static void
qla2x00_reset_host_stats(struct Scsi_Host * shost)2852*4882a593Smuzhiyun qla2x00_reset_host_stats(struct Scsi_Host *shost)
2853*4882a593Smuzhiyun {
2854*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(shost);
2855*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
2856*4882a593Smuzhiyun struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2857*4882a593Smuzhiyun struct link_statistics *stats;
2858*4882a593Smuzhiyun dma_addr_t stats_dma;
2859*4882a593Smuzhiyun int i;
2860*4882a593Smuzhiyun struct qla_qpair *qpair;
2861*4882a593Smuzhiyun
2862*4882a593Smuzhiyun memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2863*4882a593Smuzhiyun memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2864*4882a593Smuzhiyun for (i = 0; i < vha->hw->max_qpairs; i++) {
2865*4882a593Smuzhiyun qpair = vha->hw->queue_pair_map[i];
2866*4882a593Smuzhiyun if (!qpair)
2867*4882a593Smuzhiyun continue;
2868*4882a593Smuzhiyun memset(&qpair->counters, 0, sizeof(qpair->counters));
2869*4882a593Smuzhiyun }
2870*4882a593Smuzhiyun memset(&ha->base_qpair->counters, 0, sizeof(qpair->counters));
2871*4882a593Smuzhiyun
2872*4882a593Smuzhiyun vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2873*4882a593Smuzhiyun
2874*4882a593Smuzhiyun if (IS_FWI2_CAPABLE(ha)) {
2875*4882a593Smuzhiyun int rval;
2876*4882a593Smuzhiyun
2877*4882a593Smuzhiyun stats = dma_alloc_coherent(&ha->pdev->dev,
2878*4882a593Smuzhiyun sizeof(*stats), &stats_dma, GFP_KERNEL);
2879*4882a593Smuzhiyun if (!stats) {
2880*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x70d7,
2881*4882a593Smuzhiyun "Failed to allocate memory for stats.\n");
2882*4882a593Smuzhiyun return;
2883*4882a593Smuzhiyun }
2884*4882a593Smuzhiyun
2885*4882a593Smuzhiyun /* reset firmware statistics */
2886*4882a593Smuzhiyun rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, BIT_0);
2887*4882a593Smuzhiyun if (rval != QLA_SUCCESS)
2888*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x70de,
2889*4882a593Smuzhiyun "Resetting ISP statistics failed: rval = %d\n",
2890*4882a593Smuzhiyun rval);
2891*4882a593Smuzhiyun
2892*4882a593Smuzhiyun dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
2893*4882a593Smuzhiyun stats, stats_dma);
2894*4882a593Smuzhiyun }
2895*4882a593Smuzhiyun }
2896*4882a593Smuzhiyun
2897*4882a593Smuzhiyun static void
qla2x00_get_host_symbolic_name(struct Scsi_Host * shost)2898*4882a593Smuzhiyun qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
2899*4882a593Smuzhiyun {
2900*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(shost);
2901*4882a593Smuzhiyun
2902*4882a593Smuzhiyun qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost),
2903*4882a593Smuzhiyun sizeof(fc_host_symbolic_name(shost)));
2904*4882a593Smuzhiyun }
2905*4882a593Smuzhiyun
2906*4882a593Smuzhiyun static void
qla2x00_set_host_system_hostname(struct Scsi_Host * shost)2907*4882a593Smuzhiyun qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
2908*4882a593Smuzhiyun {
2909*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(shost);
2910*4882a593Smuzhiyun
2911*4882a593Smuzhiyun set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
2912*4882a593Smuzhiyun }
2913*4882a593Smuzhiyun
2914*4882a593Smuzhiyun static void
qla2x00_get_host_fabric_name(struct Scsi_Host * shost)2915*4882a593Smuzhiyun qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
2916*4882a593Smuzhiyun {
2917*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(shost);
2918*4882a593Smuzhiyun static const uint8_t node_name[WWN_SIZE] = {
2919*4882a593Smuzhiyun 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
2920*4882a593Smuzhiyun };
2921*4882a593Smuzhiyun u64 fabric_name = wwn_to_u64(node_name);
2922*4882a593Smuzhiyun
2923*4882a593Smuzhiyun if (vha->device_flags & SWITCH_FOUND)
2924*4882a593Smuzhiyun fabric_name = wwn_to_u64(vha->fabric_node_name);
2925*4882a593Smuzhiyun
2926*4882a593Smuzhiyun fc_host_fabric_name(shost) = fabric_name;
2927*4882a593Smuzhiyun }
2928*4882a593Smuzhiyun
2929*4882a593Smuzhiyun static void
qla2x00_get_host_port_state(struct Scsi_Host * shost)2930*4882a593Smuzhiyun qla2x00_get_host_port_state(struct Scsi_Host *shost)
2931*4882a593Smuzhiyun {
2932*4882a593Smuzhiyun scsi_qla_host_t *vha = shost_priv(shost);
2933*4882a593Smuzhiyun struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
2934*4882a593Smuzhiyun
2935*4882a593Smuzhiyun if (!base_vha->flags.online) {
2936*4882a593Smuzhiyun fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
2937*4882a593Smuzhiyun return;
2938*4882a593Smuzhiyun }
2939*4882a593Smuzhiyun
2940*4882a593Smuzhiyun switch (atomic_read(&base_vha->loop_state)) {
2941*4882a593Smuzhiyun case LOOP_UPDATE:
2942*4882a593Smuzhiyun fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2943*4882a593Smuzhiyun break;
2944*4882a593Smuzhiyun case LOOP_DOWN:
2945*4882a593Smuzhiyun if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
2946*4882a593Smuzhiyun fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2947*4882a593Smuzhiyun else
2948*4882a593Smuzhiyun fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2949*4882a593Smuzhiyun break;
2950*4882a593Smuzhiyun case LOOP_DEAD:
2951*4882a593Smuzhiyun fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2952*4882a593Smuzhiyun break;
2953*4882a593Smuzhiyun case LOOP_READY:
2954*4882a593Smuzhiyun fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
2955*4882a593Smuzhiyun break;
2956*4882a593Smuzhiyun default:
2957*4882a593Smuzhiyun fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
2958*4882a593Smuzhiyun break;
2959*4882a593Smuzhiyun }
2960*4882a593Smuzhiyun }
2961*4882a593Smuzhiyun
2962*4882a593Smuzhiyun static int
qla24xx_vport_create(struct fc_vport * fc_vport,bool disable)2963*4882a593Smuzhiyun qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
2964*4882a593Smuzhiyun {
2965*4882a593Smuzhiyun int ret = 0;
2966*4882a593Smuzhiyun uint8_t qos = 0;
2967*4882a593Smuzhiyun scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
2968*4882a593Smuzhiyun scsi_qla_host_t *vha = NULL;
2969*4882a593Smuzhiyun struct qla_hw_data *ha = base_vha->hw;
2970*4882a593Smuzhiyun int cnt;
2971*4882a593Smuzhiyun struct req_que *req = ha->req_q_map[0];
2972*4882a593Smuzhiyun struct qla_qpair *qpair;
2973*4882a593Smuzhiyun
2974*4882a593Smuzhiyun ret = qla24xx_vport_create_req_sanity_check(fc_vport);
2975*4882a593Smuzhiyun if (ret) {
2976*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x707e,
2977*4882a593Smuzhiyun "Vport sanity check failed, status %x\n", ret);
2978*4882a593Smuzhiyun return (ret);
2979*4882a593Smuzhiyun }
2980*4882a593Smuzhiyun
2981*4882a593Smuzhiyun vha = qla24xx_create_vhost(fc_vport);
2982*4882a593Smuzhiyun if (vha == NULL) {
2983*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
2984*4882a593Smuzhiyun return FC_VPORT_FAILED;
2985*4882a593Smuzhiyun }
2986*4882a593Smuzhiyun if (disable) {
2987*4882a593Smuzhiyun atomic_set(&vha->vp_state, VP_OFFLINE);
2988*4882a593Smuzhiyun fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
2989*4882a593Smuzhiyun } else
2990*4882a593Smuzhiyun atomic_set(&vha->vp_state, VP_FAILED);
2991*4882a593Smuzhiyun
2992*4882a593Smuzhiyun /* ready to create vport */
2993*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x7080,
2994*4882a593Smuzhiyun "VP entry id %d assigned.\n", vha->vp_idx);
2995*4882a593Smuzhiyun
2996*4882a593Smuzhiyun /* initialized vport states */
2997*4882a593Smuzhiyun atomic_set(&vha->loop_state, LOOP_DOWN);
2998*4882a593Smuzhiyun vha->vp_err_state = VP_ERR_PORTDWN;
2999*4882a593Smuzhiyun vha->vp_prev_err_state = VP_ERR_UNKWN;
3000*4882a593Smuzhiyun /* Check if physical ha port is Up */
3001*4882a593Smuzhiyun if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
3002*4882a593Smuzhiyun atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
3003*4882a593Smuzhiyun /* Don't retry or attempt login of this virtual port */
3004*4882a593Smuzhiyun ql_dbg(ql_dbg_user, vha, 0x7081,
3005*4882a593Smuzhiyun "Vport loop state is not UP.\n");
3006*4882a593Smuzhiyun atomic_set(&vha->loop_state, LOOP_DEAD);
3007*4882a593Smuzhiyun if (!disable)
3008*4882a593Smuzhiyun fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
3009*4882a593Smuzhiyun }
3010*4882a593Smuzhiyun
3011*4882a593Smuzhiyun if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
3012*4882a593Smuzhiyun if (ha->fw_attributes & BIT_4) {
3013*4882a593Smuzhiyun int prot = 0, guard;
3014*4882a593Smuzhiyun
3015*4882a593Smuzhiyun vha->flags.difdix_supported = 1;
3016*4882a593Smuzhiyun ql_dbg(ql_dbg_user, vha, 0x7082,
3017*4882a593Smuzhiyun "Registered for DIF/DIX type 1 and 3 protection.\n");
3018*4882a593Smuzhiyun if (ql2xenabledif == 1)
3019*4882a593Smuzhiyun prot = SHOST_DIX_TYPE0_PROTECTION;
3020*4882a593Smuzhiyun scsi_host_set_prot(vha->host,
3021*4882a593Smuzhiyun prot | SHOST_DIF_TYPE1_PROTECTION
3022*4882a593Smuzhiyun | SHOST_DIF_TYPE2_PROTECTION
3023*4882a593Smuzhiyun | SHOST_DIF_TYPE3_PROTECTION
3024*4882a593Smuzhiyun | SHOST_DIX_TYPE1_PROTECTION
3025*4882a593Smuzhiyun | SHOST_DIX_TYPE2_PROTECTION
3026*4882a593Smuzhiyun | SHOST_DIX_TYPE3_PROTECTION);
3027*4882a593Smuzhiyun
3028*4882a593Smuzhiyun guard = SHOST_DIX_GUARD_CRC;
3029*4882a593Smuzhiyun
3030*4882a593Smuzhiyun if (IS_PI_IPGUARD_CAPABLE(ha) &&
3031*4882a593Smuzhiyun (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3032*4882a593Smuzhiyun guard |= SHOST_DIX_GUARD_IP;
3033*4882a593Smuzhiyun
3034*4882a593Smuzhiyun scsi_host_set_guard(vha->host, guard);
3035*4882a593Smuzhiyun } else
3036*4882a593Smuzhiyun vha->flags.difdix_supported = 0;
3037*4882a593Smuzhiyun }
3038*4882a593Smuzhiyun
3039*4882a593Smuzhiyun if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
3040*4882a593Smuzhiyun &ha->pdev->dev)) {
3041*4882a593Smuzhiyun ql_dbg(ql_dbg_user, vha, 0x7083,
3042*4882a593Smuzhiyun "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
3043*4882a593Smuzhiyun goto vport_create_failed_2;
3044*4882a593Smuzhiyun }
3045*4882a593Smuzhiyun
3046*4882a593Smuzhiyun /* initialize attributes */
3047*4882a593Smuzhiyun fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
3048*4882a593Smuzhiyun fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
3049*4882a593Smuzhiyun fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
3050*4882a593Smuzhiyun fc_host_supported_classes(vha->host) =
3051*4882a593Smuzhiyun fc_host_supported_classes(base_vha->host);
3052*4882a593Smuzhiyun fc_host_supported_speeds(vha->host) =
3053*4882a593Smuzhiyun fc_host_supported_speeds(base_vha->host);
3054*4882a593Smuzhiyun
3055*4882a593Smuzhiyun qlt_vport_create(vha, ha);
3056*4882a593Smuzhiyun qla24xx_vport_disable(fc_vport, disable);
3057*4882a593Smuzhiyun
3058*4882a593Smuzhiyun if (!ql2xmqsupport || !ha->npiv_info)
3059*4882a593Smuzhiyun goto vport_queue;
3060*4882a593Smuzhiyun
3061*4882a593Smuzhiyun /* Create a request queue in QoS mode for the vport */
3062*4882a593Smuzhiyun for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
3063*4882a593Smuzhiyun if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
3064*4882a593Smuzhiyun && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
3065*4882a593Smuzhiyun 8) == 0) {
3066*4882a593Smuzhiyun qos = ha->npiv_info[cnt].q_qos;
3067*4882a593Smuzhiyun break;
3068*4882a593Smuzhiyun }
3069*4882a593Smuzhiyun }
3070*4882a593Smuzhiyun
3071*4882a593Smuzhiyun if (qos) {
3072*4882a593Smuzhiyun qpair = qla2xxx_create_qpair(vha, qos, vha->vp_idx, true);
3073*4882a593Smuzhiyun if (!qpair)
3074*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x7084,
3075*4882a593Smuzhiyun "Can't create qpair for VP[%d]\n",
3076*4882a593Smuzhiyun vha->vp_idx);
3077*4882a593Smuzhiyun else {
3078*4882a593Smuzhiyun ql_dbg(ql_dbg_multiq, vha, 0xc001,
3079*4882a593Smuzhiyun "Queue pair: %d Qos: %d) created for VP[%d]\n",
3080*4882a593Smuzhiyun qpair->id, qos, vha->vp_idx);
3081*4882a593Smuzhiyun ql_dbg(ql_dbg_user, vha, 0x7085,
3082*4882a593Smuzhiyun "Queue Pair: %d Qos: %d) created for VP[%d]\n",
3083*4882a593Smuzhiyun qpair->id, qos, vha->vp_idx);
3084*4882a593Smuzhiyun req = qpair->req;
3085*4882a593Smuzhiyun vha->qpair = qpair;
3086*4882a593Smuzhiyun }
3087*4882a593Smuzhiyun }
3088*4882a593Smuzhiyun
3089*4882a593Smuzhiyun vport_queue:
3090*4882a593Smuzhiyun vha->req = req;
3091*4882a593Smuzhiyun return 0;
3092*4882a593Smuzhiyun
3093*4882a593Smuzhiyun vport_create_failed_2:
3094*4882a593Smuzhiyun qla24xx_disable_vp(vha);
3095*4882a593Smuzhiyun qla24xx_deallocate_vp_id(vha);
3096*4882a593Smuzhiyun scsi_host_put(vha->host);
3097*4882a593Smuzhiyun return FC_VPORT_FAILED;
3098*4882a593Smuzhiyun }
3099*4882a593Smuzhiyun
3100*4882a593Smuzhiyun static int
qla24xx_vport_delete(struct fc_vport * fc_vport)3101*4882a593Smuzhiyun qla24xx_vport_delete(struct fc_vport *fc_vport)
3102*4882a593Smuzhiyun {
3103*4882a593Smuzhiyun scsi_qla_host_t *vha = fc_vport->dd_data;
3104*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
3105*4882a593Smuzhiyun uint16_t id = vha->vp_idx;
3106*4882a593Smuzhiyun
3107*4882a593Smuzhiyun set_bit(VPORT_DELETE, &vha->dpc_flags);
3108*4882a593Smuzhiyun
3109*4882a593Smuzhiyun while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
3110*4882a593Smuzhiyun test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
3111*4882a593Smuzhiyun msleep(1000);
3112*4882a593Smuzhiyun
3113*4882a593Smuzhiyun
3114*4882a593Smuzhiyun qla24xx_disable_vp(vha);
3115*4882a593Smuzhiyun qla2x00_wait_for_sess_deletion(vha);
3116*4882a593Smuzhiyun
3117*4882a593Smuzhiyun qla_nvme_delete(vha);
3118*4882a593Smuzhiyun vha->flags.delete_progress = 1;
3119*4882a593Smuzhiyun
3120*4882a593Smuzhiyun qlt_remove_target(ha, vha);
3121*4882a593Smuzhiyun
3122*4882a593Smuzhiyun fc_remove_host(vha->host);
3123*4882a593Smuzhiyun
3124*4882a593Smuzhiyun scsi_remove_host(vha->host);
3125*4882a593Smuzhiyun
3126*4882a593Smuzhiyun /* Allow timer to run to drain queued items, when removing vp */
3127*4882a593Smuzhiyun qla24xx_deallocate_vp_id(vha);
3128*4882a593Smuzhiyun
3129*4882a593Smuzhiyun if (vha->timer_active) {
3130*4882a593Smuzhiyun qla2x00_vp_stop_timer(vha);
3131*4882a593Smuzhiyun ql_dbg(ql_dbg_user, vha, 0x7086,
3132*4882a593Smuzhiyun "Timer for the VP[%d] has stopped\n", vha->vp_idx);
3133*4882a593Smuzhiyun }
3134*4882a593Smuzhiyun
3135*4882a593Smuzhiyun qla2x00_free_fcports(vha);
3136*4882a593Smuzhiyun
3137*4882a593Smuzhiyun mutex_lock(&ha->vport_lock);
3138*4882a593Smuzhiyun ha->cur_vport_count--;
3139*4882a593Smuzhiyun clear_bit(vha->vp_idx, ha->vp_idx_map);
3140*4882a593Smuzhiyun mutex_unlock(&ha->vport_lock);
3141*4882a593Smuzhiyun
3142*4882a593Smuzhiyun dma_free_coherent(&ha->pdev->dev, vha->gnl.size, vha->gnl.l,
3143*4882a593Smuzhiyun vha->gnl.ldma);
3144*4882a593Smuzhiyun
3145*4882a593Smuzhiyun vha->gnl.l = NULL;
3146*4882a593Smuzhiyun
3147*4882a593Smuzhiyun vfree(vha->scan.l);
3148*4882a593Smuzhiyun
3149*4882a593Smuzhiyun if (vha->qpair && vha->qpair->vp_idx == vha->vp_idx) {
3150*4882a593Smuzhiyun if (qla2xxx_delete_qpair(vha, vha->qpair) != QLA_SUCCESS)
3151*4882a593Smuzhiyun ql_log(ql_log_warn, vha, 0x7087,
3152*4882a593Smuzhiyun "Queue Pair delete failed.\n");
3153*4882a593Smuzhiyun }
3154*4882a593Smuzhiyun
3155*4882a593Smuzhiyun ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
3156*4882a593Smuzhiyun scsi_host_put(vha->host);
3157*4882a593Smuzhiyun return 0;
3158*4882a593Smuzhiyun }
3159*4882a593Smuzhiyun
3160*4882a593Smuzhiyun static int
qla24xx_vport_disable(struct fc_vport * fc_vport,bool disable)3161*4882a593Smuzhiyun qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
3162*4882a593Smuzhiyun {
3163*4882a593Smuzhiyun scsi_qla_host_t *vha = fc_vport->dd_data;
3164*4882a593Smuzhiyun
3165*4882a593Smuzhiyun if (disable)
3166*4882a593Smuzhiyun qla24xx_disable_vp(vha);
3167*4882a593Smuzhiyun else
3168*4882a593Smuzhiyun qla24xx_enable_vp(vha);
3169*4882a593Smuzhiyun
3170*4882a593Smuzhiyun return 0;
3171*4882a593Smuzhiyun }
3172*4882a593Smuzhiyun
3173*4882a593Smuzhiyun struct fc_function_template qla2xxx_transport_functions = {
3174*4882a593Smuzhiyun
3175*4882a593Smuzhiyun .show_host_node_name = 1,
3176*4882a593Smuzhiyun .show_host_port_name = 1,
3177*4882a593Smuzhiyun .show_host_supported_classes = 1,
3178*4882a593Smuzhiyun .show_host_supported_speeds = 1,
3179*4882a593Smuzhiyun
3180*4882a593Smuzhiyun .get_host_port_id = qla2x00_get_host_port_id,
3181*4882a593Smuzhiyun .show_host_port_id = 1,
3182*4882a593Smuzhiyun .get_host_speed = qla2x00_get_host_speed,
3183*4882a593Smuzhiyun .show_host_speed = 1,
3184*4882a593Smuzhiyun .get_host_port_type = qla2x00_get_host_port_type,
3185*4882a593Smuzhiyun .show_host_port_type = 1,
3186*4882a593Smuzhiyun .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
3187*4882a593Smuzhiyun .show_host_symbolic_name = 1,
3188*4882a593Smuzhiyun .set_host_system_hostname = qla2x00_set_host_system_hostname,
3189*4882a593Smuzhiyun .show_host_system_hostname = 1,
3190*4882a593Smuzhiyun .get_host_fabric_name = qla2x00_get_host_fabric_name,
3191*4882a593Smuzhiyun .show_host_fabric_name = 1,
3192*4882a593Smuzhiyun .get_host_port_state = qla2x00_get_host_port_state,
3193*4882a593Smuzhiyun .show_host_port_state = 1,
3194*4882a593Smuzhiyun
3195*4882a593Smuzhiyun .dd_fcrport_size = sizeof(struct fc_port *),
3196*4882a593Smuzhiyun .show_rport_supported_classes = 1,
3197*4882a593Smuzhiyun
3198*4882a593Smuzhiyun .get_starget_node_name = qla2x00_get_starget_node_name,
3199*4882a593Smuzhiyun .show_starget_node_name = 1,
3200*4882a593Smuzhiyun .get_starget_port_name = qla2x00_get_starget_port_name,
3201*4882a593Smuzhiyun .show_starget_port_name = 1,
3202*4882a593Smuzhiyun .get_starget_port_id = qla2x00_get_starget_port_id,
3203*4882a593Smuzhiyun .show_starget_port_id = 1,
3204*4882a593Smuzhiyun
3205*4882a593Smuzhiyun .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
3206*4882a593Smuzhiyun .show_rport_dev_loss_tmo = 1,
3207*4882a593Smuzhiyun
3208*4882a593Smuzhiyun .issue_fc_host_lip = qla2x00_issue_lip,
3209*4882a593Smuzhiyun .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
3210*4882a593Smuzhiyun .terminate_rport_io = qla2x00_terminate_rport_io,
3211*4882a593Smuzhiyun .get_fc_host_stats = qla2x00_get_fc_host_stats,
3212*4882a593Smuzhiyun .reset_fc_host_stats = qla2x00_reset_host_stats,
3213*4882a593Smuzhiyun
3214*4882a593Smuzhiyun .vport_create = qla24xx_vport_create,
3215*4882a593Smuzhiyun .vport_disable = qla24xx_vport_disable,
3216*4882a593Smuzhiyun .vport_delete = qla24xx_vport_delete,
3217*4882a593Smuzhiyun .bsg_request = qla24xx_bsg_request,
3218*4882a593Smuzhiyun .bsg_timeout = qla24xx_bsg_timeout,
3219*4882a593Smuzhiyun };
3220*4882a593Smuzhiyun
3221*4882a593Smuzhiyun struct fc_function_template qla2xxx_transport_vport_functions = {
3222*4882a593Smuzhiyun
3223*4882a593Smuzhiyun .show_host_node_name = 1,
3224*4882a593Smuzhiyun .show_host_port_name = 1,
3225*4882a593Smuzhiyun .show_host_supported_classes = 1,
3226*4882a593Smuzhiyun
3227*4882a593Smuzhiyun .get_host_port_id = qla2x00_get_host_port_id,
3228*4882a593Smuzhiyun .show_host_port_id = 1,
3229*4882a593Smuzhiyun .get_host_speed = qla2x00_get_host_speed,
3230*4882a593Smuzhiyun .show_host_speed = 1,
3231*4882a593Smuzhiyun .get_host_port_type = qla2x00_get_host_port_type,
3232*4882a593Smuzhiyun .show_host_port_type = 1,
3233*4882a593Smuzhiyun .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
3234*4882a593Smuzhiyun .show_host_symbolic_name = 1,
3235*4882a593Smuzhiyun .set_host_system_hostname = qla2x00_set_host_system_hostname,
3236*4882a593Smuzhiyun .show_host_system_hostname = 1,
3237*4882a593Smuzhiyun .get_host_fabric_name = qla2x00_get_host_fabric_name,
3238*4882a593Smuzhiyun .show_host_fabric_name = 1,
3239*4882a593Smuzhiyun .get_host_port_state = qla2x00_get_host_port_state,
3240*4882a593Smuzhiyun .show_host_port_state = 1,
3241*4882a593Smuzhiyun
3242*4882a593Smuzhiyun .dd_fcrport_size = sizeof(struct fc_port *),
3243*4882a593Smuzhiyun .show_rport_supported_classes = 1,
3244*4882a593Smuzhiyun
3245*4882a593Smuzhiyun .get_starget_node_name = qla2x00_get_starget_node_name,
3246*4882a593Smuzhiyun .show_starget_node_name = 1,
3247*4882a593Smuzhiyun .get_starget_port_name = qla2x00_get_starget_port_name,
3248*4882a593Smuzhiyun .show_starget_port_name = 1,
3249*4882a593Smuzhiyun .get_starget_port_id = qla2x00_get_starget_port_id,
3250*4882a593Smuzhiyun .show_starget_port_id = 1,
3251*4882a593Smuzhiyun
3252*4882a593Smuzhiyun .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
3253*4882a593Smuzhiyun .show_rport_dev_loss_tmo = 1,
3254*4882a593Smuzhiyun
3255*4882a593Smuzhiyun .issue_fc_host_lip = qla2x00_issue_lip,
3256*4882a593Smuzhiyun .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
3257*4882a593Smuzhiyun .terminate_rport_io = qla2x00_terminate_rport_io,
3258*4882a593Smuzhiyun .get_fc_host_stats = qla2x00_get_fc_host_stats,
3259*4882a593Smuzhiyun .reset_fc_host_stats = qla2x00_reset_host_stats,
3260*4882a593Smuzhiyun
3261*4882a593Smuzhiyun .bsg_request = qla24xx_bsg_request,
3262*4882a593Smuzhiyun .bsg_timeout = qla24xx_bsg_timeout,
3263*4882a593Smuzhiyun };
3264*4882a593Smuzhiyun
3265*4882a593Smuzhiyun static uint
qla2x00_get_host_supported_speeds(scsi_qla_host_t * vha,uint speeds)3266*4882a593Smuzhiyun qla2x00_get_host_supported_speeds(scsi_qla_host_t *vha, uint speeds)
3267*4882a593Smuzhiyun {
3268*4882a593Smuzhiyun uint supported_speeds = FC_PORTSPEED_UNKNOWN;
3269*4882a593Smuzhiyun
3270*4882a593Smuzhiyun if (speeds & FDMI_PORT_SPEED_64GB)
3271*4882a593Smuzhiyun supported_speeds |= FC_PORTSPEED_64GBIT;
3272*4882a593Smuzhiyun if (speeds & FDMI_PORT_SPEED_32GB)
3273*4882a593Smuzhiyun supported_speeds |= FC_PORTSPEED_32GBIT;
3274*4882a593Smuzhiyun if (speeds & FDMI_PORT_SPEED_16GB)
3275*4882a593Smuzhiyun supported_speeds |= FC_PORTSPEED_16GBIT;
3276*4882a593Smuzhiyun if (speeds & FDMI_PORT_SPEED_8GB)
3277*4882a593Smuzhiyun supported_speeds |= FC_PORTSPEED_8GBIT;
3278*4882a593Smuzhiyun if (speeds & FDMI_PORT_SPEED_4GB)
3279*4882a593Smuzhiyun supported_speeds |= FC_PORTSPEED_4GBIT;
3280*4882a593Smuzhiyun if (speeds & FDMI_PORT_SPEED_2GB)
3281*4882a593Smuzhiyun supported_speeds |= FC_PORTSPEED_2GBIT;
3282*4882a593Smuzhiyun if (speeds & FDMI_PORT_SPEED_1GB)
3283*4882a593Smuzhiyun supported_speeds |= FC_PORTSPEED_1GBIT;
3284*4882a593Smuzhiyun
3285*4882a593Smuzhiyun return supported_speeds;
3286*4882a593Smuzhiyun }
3287*4882a593Smuzhiyun
3288*4882a593Smuzhiyun void
qla2x00_init_host_attr(scsi_qla_host_t * vha)3289*4882a593Smuzhiyun qla2x00_init_host_attr(scsi_qla_host_t *vha)
3290*4882a593Smuzhiyun {
3291*4882a593Smuzhiyun struct qla_hw_data *ha = vha->hw;
3292*4882a593Smuzhiyun u32 speeds = 0, fdmi_speed = 0;
3293*4882a593Smuzhiyun
3294*4882a593Smuzhiyun fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
3295*4882a593Smuzhiyun fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
3296*4882a593Smuzhiyun fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
3297*4882a593Smuzhiyun fc_host_supported_classes(vha->host) = ha->base_qpair->enable_class_2 ?
3298*4882a593Smuzhiyun (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
3299*4882a593Smuzhiyun fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
3300*4882a593Smuzhiyun fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
3301*4882a593Smuzhiyun
3302*4882a593Smuzhiyun fdmi_speed = qla25xx_fdmi_port_speed_capability(ha);
3303*4882a593Smuzhiyun speeds = qla2x00_get_host_supported_speeds(vha, fdmi_speed);
3304*4882a593Smuzhiyun
3305*4882a593Smuzhiyun fc_host_supported_speeds(vha->host) = speeds;
3306*4882a593Smuzhiyun }
3307