xref: /openbmc/linux/drivers/scsi/fnic/fnic_attrs.c (revision 7cc39531)
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 
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 snprintf(buf, PAGE_SIZE, "%s\n", fnic_state_str[fnic->state]);
18 }
19 
20 static ssize_t fnic_show_drv_version(struct device *dev,
21 				     struct device_attribute *attr, char *buf)
22 {
23 	return snprintf(buf, PAGE_SIZE, "%s\n", DRV_VERSION);
24 }
25 
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 snprintf(buf, PAGE_SIZE, "%s\n", (lp->link_up)
32 			? "Link Up" : "Link Down");
33 }
34 
35 static DEVICE_ATTR(fnic_state, S_IRUGO, fnic_show_state, NULL);
36 static DEVICE_ATTR(drv_version, S_IRUGO, fnic_show_drv_version, NULL);
37 static DEVICE_ATTR(link_state, S_IRUGO, fnic_show_link_state, NULL);
38 
39 static struct attribute *fnic_host_attrs[] = {
40 	&dev_attr_fnic_state.attr,
41 	&dev_attr_drv_version.attr,
42 	&dev_attr_link_state.attr,
43 	NULL,
44 };
45 
46 static const struct attribute_group fnic_host_attr_group = {
47 	.attrs = fnic_host_attrs
48 };
49 
50 const struct attribute_group *fnic_host_groups[] = {
51 	&fnic_host_attr_group,
52 	NULL
53 };
54