2 * QLogic FCoE Offload Driver
3 * Copyright (c) 2016-2017 Cavium Inc.
5 * This software is available under the terms of the GNU General Public License
6 * (GPL) Version 2, available from the file COPYING in the main directory of
11 inline bool qedf_is_vport(struct qedf_ctx
*qedf
)
13 return qedf
->lport
->vport
!= NULL
;
16 /* Get base qedf for physical port from vport */
17 static struct qedf_ctx
*qedf_get_base_qedf(struct qedf_ctx
*qedf
)
19 struct fc_lport
*lport
;
20 struct fc_lport
*base_lport
;
22 if (!(qedf_is_vport(qedf
)))
26 base_lport
= shost_priv(vport_to_shost(lport
->vport
));
27 return lport_priv(base_lport
);
31 qedf_fcoe_mac_show(struct device
*dev
,
32 struct device_attribute
*attr
, char *buf
)
34 struct fc_lport
*lport
= shost_priv(class_to_shost(dev
));
39 port_id
= fc_host_port_id(lport
->host
);
40 lport_src_id
[2] = (port_id
& 0x000000FF);
41 lport_src_id
[1] = (port_id
& 0x0000FF00) >> 8;
42 lport_src_id
[0] = (port_id
& 0x00FF0000) >> 16;
43 fc_fcoe_set_mac(fcoe_mac
, lport_src_id
);
45 return scnprintf(buf
, PAGE_SIZE
, "%pM\n", fcoe_mac
);
49 qedf_fka_period_show(struct device
*dev
,
50 struct device_attribute
*attr
, char *buf
)
52 struct fc_lport
*lport
= shost_priv(class_to_shost(dev
));
53 struct qedf_ctx
*qedf
= lport_priv(lport
);
56 if (qedf_is_vport(qedf
))
57 qedf
= qedf_get_base_qedf(qedf
);
59 if (qedf
->ctlr
.sel_fcf
)
60 fka_period
= qedf
->ctlr
.sel_fcf
->fka_period
;
62 return scnprintf(buf
, PAGE_SIZE
, "%d\n", fka_period
);
65 static DEVICE_ATTR(fcoe_mac
, S_IRUGO
, qedf_fcoe_mac_show
, NULL
);
66 static DEVICE_ATTR(fka_period
, S_IRUGO
, qedf_fka_period_show
, NULL
);
68 struct device_attribute
*qedf_host_attrs
[] = {
74 extern const struct qed_fcoe_ops
*qed_ops
;
76 void qedf_capture_grc_dump(struct qedf_ctx
*qedf
)
78 struct qedf_ctx
*base_qedf
;
80 /* Make sure we use the base qedf to take the GRC dump */
81 if (qedf_is_vport(qedf
))
82 base_qedf
= qedf_get_base_qedf(qedf
);
86 if (test_bit(QEDF_GRCDUMP_CAPTURE
, &base_qedf
->flags
)) {
87 QEDF_INFO(&(base_qedf
->dbg_ctx
), QEDF_LOG_INFO
,
88 "GRC Dump already captured.\n");
93 qedf_get_grc_dump(base_qedf
->cdev
, qed_ops
->common
,
94 &base_qedf
->grcdump
, &base_qedf
->grcdump_size
);
95 QEDF_ERR(&(base_qedf
->dbg_ctx
), "GRC Dump captured.\n");
96 set_bit(QEDF_GRCDUMP_CAPTURE
, &base_qedf
->flags
);
97 qedf_uevent_emit(base_qedf
->lport
->host
, QEDF_UEVENT_CODE_GRCDUMP
,
102 qedf_sysfs_read_grcdump(struct file
*filep
, struct kobject
*kobj
,
103 struct bin_attribute
*ba
, char *buf
, loff_t off
,
107 struct fc_lport
*lport
= shost_priv(dev_to_shost(container_of(kobj
,
108 struct device
, kobj
)));
109 struct qedf_ctx
*qedf
= lport_priv(lport
);
111 if (test_bit(QEDF_GRCDUMP_CAPTURE
, &qedf
->flags
)) {
112 ret
= memory_read_from_buffer(buf
, count
, &off
,
113 qedf
->grcdump
, qedf
->grcdump_size
);
115 QEDF_ERR(&(qedf
->dbg_ctx
), "GRC Dump not captured!\n");
122 qedf_sysfs_write_grcdump(struct file
*filep
, struct kobject
*kobj
,
123 struct bin_attribute
*ba
, char *buf
, loff_t off
,
126 struct fc_lport
*lport
= NULL
;
127 struct qedf_ctx
*qedf
= NULL
;
136 lport
= shost_priv(dev_to_shost(container_of(kobj
,
137 struct device
, kobj
)));
138 qedf
= lport_priv(lport
);
141 ret
= kstrtol(buf
, 10, &reading
);
143 QEDF_ERR(&(qedf
->dbg_ctx
), "Invalid input, err(%d)\n", ret
);
147 memset(msg
, 0, sizeof(msg
));
150 memset(qedf
->grcdump
, 0, qedf
->grcdump_size
);
151 clear_bit(QEDF_GRCDUMP_CAPTURE
, &qedf
->flags
);
154 qedf_capture_grc_dump(qedf
);
161 static struct bin_attribute sysfs_grcdump_attr
= {
164 .mode
= S_IRUSR
| S_IWUSR
,
167 .read
= qedf_sysfs_read_grcdump
,
168 .write
= qedf_sysfs_write_grcdump
,
171 static struct sysfs_bin_attrs bin_file_entries
[] = {
172 {"grcdump", &sysfs_grcdump_attr
},
176 void qedf_create_sysfs_ctx_attr(struct qedf_ctx
*qedf
)
178 qedf_create_sysfs_attr(qedf
->lport
->host
, bin_file_entries
);
181 void qedf_remove_sysfs_ctx_attr(struct qedf_ctx
*qedf
)
183 qedf_remove_sysfs_attr(qedf
->lport
->host
, bin_file_entries
);