xref: /linux/drivers/scsi/snic/snic_attrs.c (revision 24168c5e6dfbdd5b414f048f47f75d64533296ca)
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 sysfs_emit(buf, "%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 sysfs_emit(buf, "%s\n", snic_state_str[snic_get_state(snic)]);
27 }
28 
29 static ssize_t
30 snic_show_drv_version(struct device *dev,
31 		      struct device_attribute *attr,
32 		      char *buf)
33 {
34 	return sysfs_emit(buf, "%s\n", SNIC_DRV_VERSION);
35 }
36 
37 static ssize_t
38 snic_show_link_state(struct device *dev,
39 		     struct device_attribute *attr,
40 		     char *buf)
41 {
42 	struct snic *snic = shost_priv(class_to_shost(dev));
43 
44 	if (snic->config.xpt_type == SNIC_DAS)
45 		snic->link_status = svnic_dev_link_status(snic->vdev);
46 
47 	return sysfs_emit(buf, "%s\n",
48 			  (snic->link_status) ? "Link Up" : "Link Down");
49 }
50 
51 static DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL);
52 static DEVICE_ATTR(snic_state, S_IRUGO, snic_show_state, NULL);
53 static DEVICE_ATTR(drv_version, S_IRUGO, snic_show_drv_version, NULL);
54 static DEVICE_ATTR(link_state, S_IRUGO, snic_show_link_state, NULL);
55 
56 static struct attribute *snic_host_attrs[] = {
57 	&dev_attr_snic_sym_name.attr,
58 	&dev_attr_snic_state.attr,
59 	&dev_attr_drv_version.attr,
60 	&dev_attr_link_state.attr,
61 	NULL,
62 };
63 
64 static const struct attribute_group snic_host_attr_group = {
65 	.attrs = snic_host_attrs
66 };
67 
68 const struct attribute_group *snic_host_groups[] = {
69 	&snic_host_attr_group,
70 	NULL
71 };
72