xref: /openbmc/linux/drivers/scsi/qedi/qedi_sysfs.c (revision 8730046c)
1 /*
2  * QLogic iSCSI Offload Driver
3  * Copyright (c) 2016 Cavium Inc.
4  *
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
7  * this source tree.
8  */
9 
10 #include "qedi.h"
11 #include "qedi_gbl.h"
12 #include "qedi_iscsi.h"
13 #include "qedi_dbg.h"
14 
15 static inline struct qedi_ctx *qedi_dev_to_hba(struct device *dev)
16 {
17 	struct Scsi_Host *shost = class_to_shost(dev);
18 
19 	return iscsi_host_priv(shost);
20 }
21 
22 static ssize_t qedi_show_port_state(struct device *dev,
23 				    struct device_attribute *attr,
24 				    char *buf)
25 {
26 	struct qedi_ctx *qedi = qedi_dev_to_hba(dev);
27 
28 	if (atomic_read(&qedi->link_state) == QEDI_LINK_UP)
29 		return sprintf(buf, "Online\n");
30 	else
31 		return sprintf(buf, "Linkdown\n");
32 }
33 
34 static ssize_t qedi_show_speed(struct device *dev,
35 			       struct device_attribute *attr, char *buf)
36 {
37 	struct qedi_ctx *qedi = qedi_dev_to_hba(dev);
38 	struct qed_link_output if_link;
39 
40 	qedi_ops->common->get_link(qedi->cdev, &if_link);
41 
42 	return sprintf(buf, "%d Gbit\n", if_link.speed / 1000);
43 }
44 
45 static DEVICE_ATTR(port_state, 0444, qedi_show_port_state, NULL);
46 static DEVICE_ATTR(speed, 0444, qedi_show_speed, NULL);
47 
48 struct device_attribute *qedi_shost_attrs[] = {
49 	&dev_attr_port_state,
50 	&dev_attr_speed,
51 	NULL
52 };
53