Linux 4.18.10
[linux/fpc-iii.git] / drivers / scsi / qedi / qedi_sysfs.c
blobb10c48bd1428e6aac6a6448ee1f20dbf85ed7f37
1 /*
2 * QLogic iSCSI Offload Driver
3 * Copyright (c) 2016 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
7 * this source tree.
8 */
10 #include "qedi.h"
11 #include "qedi_gbl.h"
12 #include "qedi_iscsi.h"
13 #include "qedi_dbg.h"
15 static inline struct qedi_ctx *qedi_dev_to_hba(struct device *dev)
17 struct Scsi_Host *shost = class_to_shost(dev);
19 return iscsi_host_priv(shost);
22 static ssize_t qedi_show_port_state(struct device *dev,
23 struct device_attribute *attr,
24 char *buf)
26 struct qedi_ctx *qedi = qedi_dev_to_hba(dev);
28 if (atomic_read(&qedi->link_state) == QEDI_LINK_UP)
29 return sprintf(buf, "Online\n");
30 else
31 return sprintf(buf, "Linkdown\n");
34 static ssize_t qedi_show_speed(struct device *dev,
35 struct device_attribute *attr, char *buf)
37 struct qedi_ctx *qedi = qedi_dev_to_hba(dev);
38 struct qed_link_output if_link;
40 qedi_ops->common->get_link(qedi->cdev, &if_link);
42 return sprintf(buf, "%d Gbit\n", if_link.speed / 1000);
45 static DEVICE_ATTR(port_state, 0444, qedi_show_port_state, NULL);
46 static DEVICE_ATTR(speed, 0444, qedi_show_speed, NULL);
48 struct device_attribute *qedi_shost_attrs[] = {
49 &dev_attr_port_state,
50 &dev_attr_speed,
51 NULL