1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright 2008 Cisco Systems, Inc. All rights reserved.
4 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
5 */
6 #include <linux/string.h>
7 #include <linux/device.h>
8 #include <scsi/scsi_host.h>
9 #include "fnic.h"
10
fnic_show_state(struct device * dev,struct device_attribute * attr,char * buf)11 static ssize_t fnic_show_state(struct device *dev,
12 struct device_attribute *attr, char *buf)
13 {
14 struct fc_lport *lp = shost_priv(class_to_shost(dev));
15 struct fnic *fnic = lport_priv(lp);
16
17 return sysfs_emit(buf, "%s\n", fnic_state_str[fnic->state]);
18 }
19
fnic_show_drv_version(struct device * dev,struct device_attribute * attr,char * buf)20 static ssize_t fnic_show_drv_version(struct device *dev,
21 struct device_attribute *attr, char *buf)
22 {
23 return sysfs_emit(buf, "%s\n", DRV_VERSION);
24 }
25
fnic_show_link_state(struct device * dev,struct device_attribute * attr,char * buf)26 static ssize_t fnic_show_link_state(struct device *dev,
27 struct device_attribute *attr, char *buf)
28 {
29 struct fc_lport *lp = shost_priv(class_to_shost(dev));
30
31 return sysfs_emit(buf, "%s\n", (lp->link_up) ? "Link Up" : "Link Down");
32 }
33
34 static DEVICE_ATTR(fnic_state, S_IRUGO, fnic_show_state, NULL);
35 static DEVICE_ATTR(drv_version, S_IRUGO, fnic_show_drv_version, NULL);
36 static DEVICE_ATTR(link_state, S_IRUGO, fnic_show_link_state, NULL);
37
38 static struct attribute *fnic_host_attrs[] = {
39 &dev_attr_fnic_state.attr,
40 &dev_attr_drv_version.attr,
41 &dev_attr_link_state.attr,
42 NULL,
43 };
44
45 static const struct attribute_group fnic_host_attr_group = {
46 .attrs = fnic_host_attrs
47 };
48
49 const struct attribute_group *fnic_host_groups[] = {
50 &fnic_host_attr_group,
51 NULL
52 };
53