xref: /linux/drivers/scsi/fnic/fnic_attrs.c (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1 /*
2  * Copyright 2008 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  *
5  * This program is free software; you may redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; version 2 of the License.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16  * SOFTWARE.
17  */
18 #include <linux/string.h>
19 #include <linux/device.h>
20 #include <scsi/scsi_host.h>
21 #include "fnic.h"
22 
23 static ssize_t fnic_show_state(struct device *dev,
24 			       struct device_attribute *attr, char *buf)
25 {
26 	struct fc_lport *lp = shost_priv(class_to_shost(dev));
27 	struct fnic *fnic = lport_priv(lp);
28 
29 	return snprintf(buf, PAGE_SIZE, "%s\n", fnic_state_str[fnic->state]);
30 }
31 
32 static ssize_t fnic_show_drv_version(struct device *dev,
33 				     struct device_attribute *attr, char *buf)
34 {
35 	return snprintf(buf, PAGE_SIZE, "%s\n", DRV_VERSION);
36 }
37 
38 static ssize_t fnic_show_link_state(struct device *dev,
39 				    struct device_attribute *attr, char *buf)
40 {
41 	struct fc_lport *lp = shost_priv(class_to_shost(dev));
42 
43 	return snprintf(buf, PAGE_SIZE, "%s\n", (lp->link_up)
44 			? "Link Up" : "Link Down");
45 }
46 
47 static DEVICE_ATTR(fnic_state, S_IRUGO, fnic_show_state, NULL);
48 static DEVICE_ATTR(drv_version, S_IRUGO, fnic_show_drv_version, NULL);
49 static DEVICE_ATTR(link_state, S_IRUGO, fnic_show_link_state, NULL);
50 
51 static struct attribute *fnic_host_attrs[] = {
52 	&dev_attr_fnic_state.attr,
53 	&dev_attr_drv_version.attr,
54 	&dev_attr_link_state.attr,
55 	NULL,
56 };
57 
58 static const struct attribute_group fnic_host_attr_group = {
59 	.attrs = fnic_host_attrs
60 };
61 
62 const struct attribute_group *fnic_host_groups[] = {
63 	&fnic_host_attr_group,
64 	NULL
65 };
66