bnx2i_sysfs.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* bnx2i_sysfs.c: QLogic NetXtreme II iSCSI driver.
  2. *
  3. * Copyright (c) 2004 - 2013 Broadcom Corporation
  4. * Copyright (c) 2014, QLogic Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation.
  9. *
  10. * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
  11. * Previously Maintained by: Eddie Wai (eddie.wai@broadcom.com)
  12. * Maintained by: QLogic-Storage-Upstream@qlogic.com
  13. */
  14. #include "bnx2i.h"
  15. /**
  16. * bnx2i_dev_to_hba - maps dev pointer to adapter struct
  17. * @dev: device pointer
  18. *
  19. * Map device to hba structure
  20. */
  21. static inline struct bnx2i_hba *bnx2i_dev_to_hba(struct device *dev)
  22. {
  23. struct Scsi_Host *shost = class_to_shost(dev);
  24. return iscsi_host_priv(shost);
  25. }
  26. /**
  27. * bnx2i_show_sq_info - return(s currently configured send queue (SQ) size
  28. * @dev: device pointer
  29. * @attr: device attribute (unused)
  30. * @buf: buffer to return current SQ size parameter
  31. *
  32. * Returns current SQ size parameter, this paramater determines the number
  33. * outstanding iSCSI commands supported on a connection
  34. */
  35. static ssize_t bnx2i_show_sq_info(struct device *dev,
  36. struct device_attribute *attr, char *buf)
  37. {
  38. struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
  39. return sprintf(buf, "0x%x\n", hba->max_sqes);
  40. }
  41. /**
  42. * bnx2i_set_sq_info - update send queue (SQ) size parameter
  43. * @dev: device pointer
  44. * @attr: device attribute (unused)
  45. * @buf: buffer to return current SQ size parameter
  46. * @count: parameter buffer size
  47. *
  48. * Interface for user to change shared queue size allocated for each conn
  49. * Must be within SQ limits and a power of 2. For the latter this is needed
  50. * because of how libiscsi preallocates tasks.
  51. */
  52. static ssize_t bnx2i_set_sq_info(struct device *dev,
  53. struct device_attribute *attr,
  54. const char *buf, size_t count)
  55. {
  56. struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
  57. u32 val;
  58. int max_sq_size;
  59. if (hba->ofld_conns_active)
  60. goto skip_config;
  61. if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
  62. max_sq_size = BNX2I_5770X_SQ_WQES_MAX;
  63. else
  64. max_sq_size = BNX2I_570X_SQ_WQES_MAX;
  65. if (sscanf(buf, " 0x%x ", &val) > 0) {
  66. if ((val >= BNX2I_SQ_WQES_MIN) && (val <= max_sq_size) &&
  67. (is_power_of_2(val)))
  68. hba->max_sqes = val;
  69. }
  70. return count;
  71. skip_config:
  72. printk(KERN_ERR "bnx2i: device busy, cannot change SQ size\n");
  73. return 0;
  74. }
  75. /**
  76. * bnx2i_show_ccell_info - returns command cell (HQ) size
  77. * @dev: device pointer
  78. * @attr: device attribute (unused)
  79. * @buf: buffer to return current SQ size parameter
  80. *
  81. * returns per-connection TCP history queue size parameter
  82. */
  83. static ssize_t bnx2i_show_ccell_info(struct device *dev,
  84. struct device_attribute *attr, char *buf)
  85. {
  86. struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
  87. return sprintf(buf, "0x%x\n", hba->num_ccell);
  88. }
  89. /**
  90. * bnx2i_get_link_state - set command cell (HQ) size
  91. * @dev: device pointer
  92. * @attr: device attribute (unused)
  93. * @buf: buffer to return current SQ size parameter
  94. * @count: parameter buffer size
  95. *
  96. * updates per-connection TCP history queue size parameter
  97. */
  98. static ssize_t bnx2i_set_ccell_info(struct device *dev,
  99. struct device_attribute *attr,
  100. const char *buf, size_t count)
  101. {
  102. u32 val;
  103. struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
  104. if (hba->ofld_conns_active)
  105. goto skip_config;
  106. if (sscanf(buf, " 0x%x ", &val) > 0) {
  107. if ((val >= BNX2I_CCELLS_MIN) &&
  108. (val <= BNX2I_CCELLS_MAX)) {
  109. hba->num_ccell = val;
  110. }
  111. }
  112. return count;
  113. skip_config:
  114. printk(KERN_ERR "bnx2i: device busy, cannot change CCELL size\n");
  115. return 0;
  116. }
  117. static DEVICE_ATTR(sq_size, S_IRUGO | S_IWUSR,
  118. bnx2i_show_sq_info, bnx2i_set_sq_info);
  119. static DEVICE_ATTR(num_ccell, S_IRUGO | S_IWUSR,
  120. bnx2i_show_ccell_info, bnx2i_set_ccell_info);
  121. struct device_attribute *bnx2i_dev_attributes[] = {
  122. &dev_attr_sq_size,
  123. &dev_attr_num_ccell,
  124. NULL
  125. };