fnic_attrs.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. static ssize_t fnic_show_state(struct device *dev,
  23. struct device_attribute *attr, char *buf)
  24. {
  25. struct fc_lport *lp = shost_priv(class_to_shost(dev));
  26. struct fnic *fnic = lport_priv(lp);
  27. return snprintf(buf, PAGE_SIZE, "%s\n", fnic_state_str[fnic->state]);
  28. }
  29. static ssize_t fnic_show_drv_version(struct device *dev,
  30. struct device_attribute *attr, char *buf)
  31. {
  32. return snprintf(buf, PAGE_SIZE, "%s\n", DRV_VERSION);
  33. }
  34. static ssize_t fnic_show_link_state(struct device *dev,
  35. struct device_attribute *attr, char *buf)
  36. {
  37. struct fc_lport *lp = shost_priv(class_to_shost(dev));
  38. return snprintf(buf, PAGE_SIZE, "%s\n", (lp->link_up)
  39. ? "Link Up" : "Link Down");
  40. }
  41. static DEVICE_ATTR(fnic_state, S_IRUGO, fnic_show_state, NULL);
  42. static DEVICE_ATTR(drv_version, S_IRUGO, fnic_show_drv_version, NULL);
  43. static DEVICE_ATTR(link_state, S_IRUGO, fnic_show_link_state, NULL);
  44. struct device_attribute *fnic_attrs[] = {
  45. &dev_attr_fnic_state,
  46. &dev_attr_drv_version,
  47. &dev_attr_link_state,
  48. NULL,
  49. };