bnx2i_sysfs.c 3.5 KB

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