bnx2i_sysfs.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. * @buf: buffer to return current SQ size parameter
  30. *
  31. * Returns current SQ size parameter, this paramater determines the number
  32. * outstanding iSCSI commands supported on a connection
  33. */
  34. static ssize_t bnx2i_show_sq_info(struct device *dev,
  35. struct device_attribute *attr, char *buf)
  36. {
  37. struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
  38. return sprintf(buf, "0x%x\n", hba->max_sqes);
  39. }
  40. /**
  41. * bnx2i_set_sq_info - update send queue (SQ) size parameter
  42. * @dev: device pointer
  43. * @buf: buffer to return current SQ size parameter
  44. * @count: parameter buffer size
  45. *
  46. * Interface for user to change shared queue size allocated for each conn
  47. * Must be within SQ limits and a power of 2. For the latter this is needed
  48. * because of how libiscsi preallocates tasks.
  49. */
  50. static ssize_t bnx2i_set_sq_info(struct device *dev,
  51. struct device_attribute *attr,
  52. const char *buf, size_t count)
  53. {
  54. struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
  55. u32 val;
  56. int max_sq_size;
  57. if (hba->ofld_conns_active)
  58. goto skip_config;
  59. if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
  60. max_sq_size = BNX2I_5770X_SQ_WQES_MAX;
  61. else
  62. max_sq_size = BNX2I_570X_SQ_WQES_MAX;
  63. if (sscanf(buf, " 0x%x ", &val) > 0) {
  64. if ((val >= BNX2I_SQ_WQES_MIN) && (val <= max_sq_size) &&
  65. (is_power_of_2(val)))
  66. hba->max_sqes = val;
  67. }
  68. return count;
  69. skip_config:
  70. printk(KERN_ERR "bnx2i: device busy, cannot change SQ size\n");
  71. return 0;
  72. }
  73. /**
  74. * bnx2i_show_ccell_info - returns command cell (HQ) size
  75. * @dev: device pointer
  76. * @buf: buffer to return current SQ size parameter
  77. *
  78. * returns per-connection TCP history queue size parameter
  79. */
  80. static ssize_t bnx2i_show_ccell_info(struct device *dev,
  81. struct device_attribute *attr, char *buf)
  82. {
  83. struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
  84. return sprintf(buf, "0x%x\n", hba->num_ccell);
  85. }
  86. /**
  87. * bnx2i_get_link_state - set command cell (HQ) size
  88. * @dev: device pointer
  89. * @buf: buffer to return current SQ size parameter
  90. * @count: parameter buffer size
  91. *
  92. * updates per-connection TCP history queue size parameter
  93. */
  94. static ssize_t bnx2i_set_ccell_info(struct device *dev,
  95. struct device_attribute *attr,
  96. const char *buf, size_t count)
  97. {
  98. u32 val;
  99. struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
  100. if (hba->ofld_conns_active)
  101. goto skip_config;
  102. if (sscanf(buf, " 0x%x ", &val) > 0) {
  103. if ((val >= BNX2I_CCELLS_MIN) &&
  104. (val <= BNX2I_CCELLS_MAX)) {
  105. hba->num_ccell = val;
  106. }
  107. }
  108. return count;
  109. skip_config:
  110. printk(KERN_ERR "bnx2i: device busy, cannot change CCELL size\n");
  111. return 0;
  112. }
  113. static DEVICE_ATTR(sq_size, S_IRUGO | S_IWUSR,
  114. bnx2i_show_sq_info, bnx2i_set_sq_info);
  115. static DEVICE_ATTR(num_ccell, S_IRUGO | S_IWUSR,
  116. bnx2i_show_ccell_info, bnx2i_set_ccell_info);
  117. struct device_attribute *bnx2i_dev_attributes[] = {
  118. &dev_attr_sq_size,
  119. &dev_attr_num_ccell,
  120. NULL
  121. };