snic_attrs.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #include <linux/string.h>
  18. #include <linux/device.h>
  19. #include "snic.h"
  20. static ssize_t
  21. snic_show_sym_name(struct device *dev,
  22. struct device_attribute *attr,
  23. char *buf)
  24. {
  25. struct snic *snic = shost_priv(class_to_shost(dev));
  26. return snprintf(buf, PAGE_SIZE, "%s\n", snic->name);
  27. }
  28. static ssize_t
  29. snic_show_state(struct device *dev,
  30. struct device_attribute *attr,
  31. char *buf)
  32. {
  33. struct snic *snic = shost_priv(class_to_shost(dev));
  34. return snprintf(buf, PAGE_SIZE, "%s\n",
  35. snic_state_str[snic_get_state(snic)]);
  36. }
  37. static ssize_t
  38. snic_show_drv_version(struct device *dev,
  39. struct device_attribute *attr,
  40. char *buf)
  41. {
  42. return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION);
  43. }
  44. static ssize_t
  45. snic_show_link_state(struct device *dev,
  46. struct device_attribute *attr,
  47. char *buf)
  48. {
  49. struct snic *snic = shost_priv(class_to_shost(dev));
  50. if (snic->config.xpt_type == SNIC_DAS)
  51. snic->link_status = svnic_dev_link_status(snic->vdev);
  52. return snprintf(buf, PAGE_SIZE, "%s\n",
  53. (snic->link_status) ? "Link Up" : "Link Down");
  54. }
  55. static DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL);
  56. static DEVICE_ATTR(snic_state, S_IRUGO, snic_show_state, NULL);
  57. static DEVICE_ATTR(drv_version, S_IRUGO, snic_show_drv_version, NULL);
  58. static DEVICE_ATTR(link_state, S_IRUGO, snic_show_link_state, NULL);
  59. struct device_attribute *snic_attrs[] = {
  60. &dev_attr_snic_sym_name,
  61. &dev_attr_snic_state,
  62. &dev_attr_drv_version,
  63. &dev_attr_link_state,
  64. NULL,
  65. };