xref: /openbmc/linux/drivers/scsi/snic/snic_attrs.c (revision 6726d552)
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright 2014 Cisco Systems, Inc.  All rights reserved.
3 
4 #include <linux/string.h>
5 #include <linux/device.h>
6 
7 #include "snic.h"
8 
9 static ssize_t
10 snic_show_sym_name(struct device *dev,
11 		struct device_attribute *attr,
12 		char *buf)
13 {
14 	struct snic *snic = shost_priv(class_to_shost(dev));
15 
16 	return snprintf(buf, PAGE_SIZE, "%s\n", snic->name);
17 }
18 
19 static ssize_t
20 snic_show_state(struct device *dev,
21 		struct device_attribute *attr,
22 		char *buf)
23 {
24 	struct snic *snic = shost_priv(class_to_shost(dev));
25 
26 	return snprintf(buf, PAGE_SIZE, "%s\n",
27 			snic_state_str[snic_get_state(snic)]);
28 }
29 
30 static ssize_t
31 snic_show_drv_version(struct device *dev,
32 		      struct device_attribute *attr,
33 		      char *buf)
34 {
35 	return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION);
36 }
37 
38 static ssize_t
39 snic_show_link_state(struct device *dev,
40 		     struct device_attribute *attr,
41 		     char *buf)
42 {
43 	struct snic *snic = shost_priv(class_to_shost(dev));
44 
45 	if (snic->config.xpt_type == SNIC_DAS)
46 		snic->link_status = svnic_dev_link_status(snic->vdev);
47 
48 	return snprintf(buf, PAGE_SIZE, "%s\n",
49 			(snic->link_status) ? "Link Up" : "Link Down");
50 }
51 
52 static DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL);
53 static DEVICE_ATTR(snic_state, S_IRUGO, snic_show_state, NULL);
54 static DEVICE_ATTR(drv_version, S_IRUGO, snic_show_drv_version, NULL);
55 static DEVICE_ATTR(link_state, S_IRUGO, snic_show_link_state, NULL);
56 
57 static struct attribute *snic_host_attrs[] = {
58 	&dev_attr_snic_sym_name.attr,
59 	&dev_attr_snic_state.attr,
60 	&dev_attr_drv_version.attr,
61 	&dev_attr_link_state.attr,
62 	NULL,
63 };
64 
65 static const struct attribute_group snic_host_attr_group = {
66 	.attrs = snic_host_attrs
67 };
68 
69 const struct attribute_group *snic_host_groups[] = {
70 	&snic_host_attr_group,
71 	NULL
72 };
73