xref: /linux/drivers/scsi/qedi/qedi_sysfs.c (revision 0526b56cbc3c489642bd6a5fe4b718dea7ef0ee8)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * QLogic iSCSI Offload Driver
4  * Copyright (c) 2016 Cavium Inc.
5  */
6 
7 #include "qedi.h"
8 #include "qedi_gbl.h"
9 #include "qedi_iscsi.h"
10 #include "qedi_dbg.h"
11 
12 static inline struct qedi_ctx *qedi_dev_to_hba(struct device *dev)
13 {
14 	struct Scsi_Host *shost = class_to_shost(dev);
15 
16 	return iscsi_host_priv(shost);
17 }
18 
19 static ssize_t port_state_show(struct device *dev,
20 			       struct device_attribute *attr,
21 			       char *buf)
22 {
23 	struct qedi_ctx *qedi = qedi_dev_to_hba(dev);
24 
25 	if (atomic_read(&qedi->link_state) == QEDI_LINK_UP)
26 		return sprintf(buf, "Online\n");
27 	else
28 		return sprintf(buf, "Linkdown\n");
29 }
30 
31 static ssize_t speed_show(struct device *dev,
32 			  struct device_attribute *attr, char *buf)
33 {
34 	struct qedi_ctx *qedi = qedi_dev_to_hba(dev);
35 	struct qed_link_output if_link;
36 
37 	qedi_ops->common->get_link(qedi->cdev, &if_link);
38 
39 	return sprintf(buf, "%d Gbit\n", if_link.speed / 1000);
40 }
41 
42 static DEVICE_ATTR_RO(port_state);
43 static DEVICE_ATTR_RO(speed);
44 
45 static struct attribute *qedi_shost_attrs[] = {
46 	&dev_attr_port_state.attr,
47 	&dev_attr_speed.attr,
48 	NULL
49 };
50 
51 static const struct attribute_group qedi_shost_attr_group = {
52 	.attrs = qedi_shost_attrs
53 };
54 
55 const struct attribute_group *qedi_shost_groups[] = {
56 	&qedi_shost_attr_group,
57 	NULL
58 };
59