linux/drivers/scsi/snic/snic_attrs.c
<<
>>
Prefs
   1/*
   2 * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
   3 *
   4 * This program is free software; you may redistribute it and/or modify
   5 * it under the terms of the GNU General Public License as published by
   6 * the Free Software Foundation; version 2 of the License.
   7 *
   8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   9 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15 * SOFTWARE.
  16 */
  17
  18#include <linux/string.h>
  19#include <linux/device.h>
  20
  21#include "snic.h"
  22
  23static ssize_t
  24snic_show_sym_name(struct device *dev,
  25                struct device_attribute *attr,
  26                char *buf)
  27{
  28        struct snic *snic = shost_priv(class_to_shost(dev));
  29
  30        return snprintf(buf, PAGE_SIZE, "%s\n", snic->name);
  31}
  32
  33static ssize_t
  34snic_show_state(struct device *dev,
  35                struct device_attribute *attr,
  36                char *buf)
  37{
  38        struct snic *snic = shost_priv(class_to_shost(dev));
  39
  40        return snprintf(buf, PAGE_SIZE, "%s\n",
  41                        snic_state_str[snic_get_state(snic)]);
  42}
  43
  44static ssize_t
  45snic_show_drv_version(struct device *dev,
  46                      struct device_attribute *attr,
  47                      char *buf)
  48{
  49        return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION);
  50}
  51
  52static ssize_t
  53snic_show_link_state(struct device *dev,
  54                     struct device_attribute *attr,
  55                     char *buf)
  56{
  57        struct snic *snic = shost_priv(class_to_shost(dev));
  58
  59        if (snic->config.xpt_type == SNIC_DAS)
  60                snic->link_status = svnic_dev_link_status(snic->vdev);
  61
  62        return snprintf(buf, PAGE_SIZE, "%s\n",
  63                        (snic->link_status) ? "Link Up" : "Link Down");
  64}
  65
  66static DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL);
  67static DEVICE_ATTR(snic_state, S_IRUGO, snic_show_state, NULL);
  68static DEVICE_ATTR(drv_version, S_IRUGO, snic_show_drv_version, NULL);
  69static DEVICE_ATTR(link_state, S_IRUGO, snic_show_link_state, NULL);
  70
  71struct device_attribute *snic_attrs[] = {
  72        &dev_attr_snic_sym_name,
  73        &dev_attr_snic_state,
  74        &dev_attr_drv_version,
  75        &dev_attr_link_state,
  76        NULL,
  77};
  78