bnx2i_sysfs.c 3.6 KB

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