162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci// Copyright 2014 Cisco Systems, Inc.  All rights reserved.
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci#include <linux/string.h>
562306a36Sopenharmony_ci#include <linux/device.h>
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#include "snic.h"
862306a36Sopenharmony_ci
962306a36Sopenharmony_cistatic ssize_t
1062306a36Sopenharmony_cisnic_show_sym_name(struct device *dev,
1162306a36Sopenharmony_ci		struct device_attribute *attr,
1262306a36Sopenharmony_ci		char *buf)
1362306a36Sopenharmony_ci{
1462306a36Sopenharmony_ci	struct snic *snic = shost_priv(class_to_shost(dev));
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci	return snprintf(buf, PAGE_SIZE, "%s\n", snic->name);
1762306a36Sopenharmony_ci}
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_cistatic ssize_t
2062306a36Sopenharmony_cisnic_show_state(struct device *dev,
2162306a36Sopenharmony_ci		struct device_attribute *attr,
2262306a36Sopenharmony_ci		char *buf)
2362306a36Sopenharmony_ci{
2462306a36Sopenharmony_ci	struct snic *snic = shost_priv(class_to_shost(dev));
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci	return snprintf(buf, PAGE_SIZE, "%s\n",
2762306a36Sopenharmony_ci			snic_state_str[snic_get_state(snic)]);
2862306a36Sopenharmony_ci}
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_cistatic ssize_t
3162306a36Sopenharmony_cisnic_show_drv_version(struct device *dev,
3262306a36Sopenharmony_ci		      struct device_attribute *attr,
3362306a36Sopenharmony_ci		      char *buf)
3462306a36Sopenharmony_ci{
3562306a36Sopenharmony_ci	return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION);
3662306a36Sopenharmony_ci}
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_cistatic ssize_t
3962306a36Sopenharmony_cisnic_show_link_state(struct device *dev,
4062306a36Sopenharmony_ci		     struct device_attribute *attr,
4162306a36Sopenharmony_ci		     char *buf)
4262306a36Sopenharmony_ci{
4362306a36Sopenharmony_ci	struct snic *snic = shost_priv(class_to_shost(dev));
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci	if (snic->config.xpt_type == SNIC_DAS)
4662306a36Sopenharmony_ci		snic->link_status = svnic_dev_link_status(snic->vdev);
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci	return snprintf(buf, PAGE_SIZE, "%s\n",
4962306a36Sopenharmony_ci			(snic->link_status) ? "Link Up" : "Link Down");
5062306a36Sopenharmony_ci}
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_cistatic DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL);
5362306a36Sopenharmony_cistatic DEVICE_ATTR(snic_state, S_IRUGO, snic_show_state, NULL);
5462306a36Sopenharmony_cistatic DEVICE_ATTR(drv_version, S_IRUGO, snic_show_drv_version, NULL);
5562306a36Sopenharmony_cistatic DEVICE_ATTR(link_state, S_IRUGO, snic_show_link_state, NULL);
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_cistatic struct attribute *snic_host_attrs[] = {
5862306a36Sopenharmony_ci	&dev_attr_snic_sym_name.attr,
5962306a36Sopenharmony_ci	&dev_attr_snic_state.attr,
6062306a36Sopenharmony_ci	&dev_attr_drv_version.attr,
6162306a36Sopenharmony_ci	&dev_attr_link_state.attr,
6262306a36Sopenharmony_ci	NULL,
6362306a36Sopenharmony_ci};
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_cistatic const struct attribute_group snic_host_attr_group = {
6662306a36Sopenharmony_ci	.attrs = snic_host_attrs
6762306a36Sopenharmony_ci};
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ciconst struct attribute_group *snic_host_groups[] = {
7062306a36Sopenharmony_ci	&snic_host_attr_group,
7162306a36Sopenharmony_ci	NULL
7262306a36Sopenharmony_ci};
73