snic_res.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * Copyright 2014 Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This program is free software; you may redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; version 2 of the License.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  9. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15. * SOFTWARE.
  16. */
  17. #include <linux/errno.h>
  18. #include <linux/types.h>
  19. #include <linux/pci.h>
  20. #include "wq_enet_desc.h"
  21. #include "cq_enet_desc.h"
  22. #include "vnic_resource.h"
  23. #include "vnic_dev.h"
  24. #include "vnic_wq.h"
  25. #include "vnic_cq.h"
  26. #include "vnic_intr.h"
  27. #include "vnic_stats.h"
  28. #include "snic.h"
  29. int
  30. snic_get_vnic_config(struct snic *snic)
  31. {
  32. struct vnic_snic_config *c = &snic->config;
  33. int ret;
  34. #define GET_CONFIG(m) \
  35. do { \
  36. ret = svnic_dev_spec(snic->vdev, \
  37. offsetof(struct vnic_snic_config, m), \
  38. sizeof(c->m), \
  39. &c->m); \
  40. if (ret) { \
  41. SNIC_HOST_ERR(snic->shost, \
  42. "Error getting %s, %d\n", #m, ret); \
  43. return ret; \
  44. } \
  45. } while (0)
  46. GET_CONFIG(wq_enet_desc_count);
  47. GET_CONFIG(maxdatafieldsize);
  48. GET_CONFIG(intr_timer);
  49. GET_CONFIG(intr_timer_type);
  50. GET_CONFIG(flags);
  51. GET_CONFIG(io_throttle_count);
  52. GET_CONFIG(port_down_timeout);
  53. GET_CONFIG(port_down_io_retries);
  54. GET_CONFIG(luns_per_tgt);
  55. GET_CONFIG(xpt_type);
  56. GET_CONFIG(hid);
  57. c->wq_enet_desc_count = min_t(u32,
  58. VNIC_SNIC_WQ_DESCS_MAX,
  59. max_t(u32,
  60. VNIC_SNIC_WQ_DESCS_MIN,
  61. c->wq_enet_desc_count));
  62. c->wq_enet_desc_count = ALIGN(c->wq_enet_desc_count, 16);
  63. c->maxdatafieldsize = min_t(u32,
  64. VNIC_SNIC_MAXDATAFIELDSIZE_MAX,
  65. max_t(u32,
  66. VNIC_SNIC_MAXDATAFIELDSIZE_MIN,
  67. c->maxdatafieldsize));
  68. c->io_throttle_count = min_t(u32,
  69. VNIC_SNIC_IO_THROTTLE_COUNT_MAX,
  70. max_t(u32,
  71. VNIC_SNIC_IO_THROTTLE_COUNT_MIN,
  72. c->io_throttle_count));
  73. c->port_down_timeout = min_t(u32,
  74. VNIC_SNIC_PORT_DOWN_TIMEOUT_MAX,
  75. c->port_down_timeout);
  76. c->port_down_io_retries = min_t(u32,
  77. VNIC_SNIC_PORT_DOWN_IO_RETRIES_MAX,
  78. c->port_down_io_retries);
  79. c->luns_per_tgt = min_t(u32,
  80. VNIC_SNIC_LUNS_PER_TARGET_MAX,
  81. max_t(u32,
  82. VNIC_SNIC_LUNS_PER_TARGET_MIN,
  83. c->luns_per_tgt));
  84. c->intr_timer = min_t(u32, VNIC_INTR_TIMER_MAX, c->intr_timer);
  85. SNIC_INFO("vNIC resources wq %d\n", c->wq_enet_desc_count);
  86. SNIC_INFO("vNIC mtu %d intr timer %d\n",
  87. c->maxdatafieldsize,
  88. c->intr_timer);
  89. SNIC_INFO("vNIC flags 0x%x luns per tgt %d\n",
  90. c->flags,
  91. c->luns_per_tgt);
  92. SNIC_INFO("vNIC io throttle count %d\n", c->io_throttle_count);
  93. SNIC_INFO("vNIC port down timeout %d port down io retries %d\n",
  94. c->port_down_timeout,
  95. c->port_down_io_retries);
  96. SNIC_INFO("vNIC back end type = %d\n", c->xpt_type);
  97. SNIC_INFO("vNIC hid = %d\n", c->hid);
  98. return 0;
  99. }
  100. void
  101. snic_get_res_counts(struct snic *snic)
  102. {
  103. snic->wq_count = svnic_dev_get_res_count(snic->vdev, RES_TYPE_WQ);
  104. SNIC_BUG_ON(snic->wq_count == 0);
  105. snic->cq_count = svnic_dev_get_res_count(snic->vdev, RES_TYPE_CQ);
  106. SNIC_BUG_ON(snic->cq_count == 0);
  107. snic->intr_count = svnic_dev_get_res_count(snic->vdev,
  108. RES_TYPE_INTR_CTRL);
  109. SNIC_BUG_ON(snic->intr_count == 0);
  110. }
  111. void
  112. snic_free_vnic_res(struct snic *snic)
  113. {
  114. unsigned int i;
  115. for (i = 0; i < snic->wq_count; i++)
  116. svnic_wq_free(&snic->wq[i]);
  117. for (i = 0; i < snic->cq_count; i++)
  118. svnic_cq_free(&snic->cq[i]);
  119. for (i = 0; i < snic->intr_count; i++)
  120. svnic_intr_free(&snic->intr[i]);
  121. }
  122. int
  123. snic_alloc_vnic_res(struct snic *snic)
  124. {
  125. enum vnic_dev_intr_mode intr_mode;
  126. unsigned int mask_on_assertion;
  127. unsigned int intr_offset;
  128. unsigned int err_intr_enable;
  129. unsigned int err_intr_offset;
  130. unsigned int i;
  131. int ret;
  132. intr_mode = svnic_dev_get_intr_mode(snic->vdev);
  133. SNIC_INFO("vNIC interrupt mode: %s\n",
  134. ((intr_mode == VNIC_DEV_INTR_MODE_INTX) ?
  135. "Legacy PCI INTx" :
  136. ((intr_mode == VNIC_DEV_INTR_MODE_MSI) ?
  137. "MSI" :
  138. ((intr_mode == VNIC_DEV_INTR_MODE_MSIX) ?
  139. "MSI-X" : "Unknown"))));
  140. /* only MSI-X is supported */
  141. SNIC_BUG_ON(intr_mode != VNIC_DEV_INTR_MODE_MSIX);
  142. SNIC_INFO("wq %d cq %d intr %d\n", snic->wq_count,
  143. snic->cq_count,
  144. snic->intr_count);
  145. /* Allocate WQs used for SCSI IOs */
  146. for (i = 0; i < snic->wq_count; i++) {
  147. ret = svnic_wq_alloc(snic->vdev,
  148. &snic->wq[i],
  149. i,
  150. snic->config.wq_enet_desc_count,
  151. sizeof(struct wq_enet_desc));
  152. if (ret)
  153. goto error_cleanup;
  154. }
  155. /* CQ for each WQ */
  156. for (i = 0; i < snic->wq_count; i++) {
  157. ret = svnic_cq_alloc(snic->vdev,
  158. &snic->cq[i],
  159. i,
  160. snic->config.wq_enet_desc_count,
  161. sizeof(struct cq_enet_wq_desc));
  162. if (ret)
  163. goto error_cleanup;
  164. }
  165. SNIC_BUG_ON(snic->cq_count != 2 * snic->wq_count);
  166. /* CQ for FW TO host */
  167. for (i = snic->wq_count; i < snic->cq_count; i++) {
  168. ret = svnic_cq_alloc(snic->vdev,
  169. &snic->cq[i],
  170. i,
  171. (snic->config.wq_enet_desc_count * 3),
  172. sizeof(struct snic_fw_req));
  173. if (ret)
  174. goto error_cleanup;
  175. }
  176. for (i = 0; i < snic->intr_count; i++) {
  177. ret = svnic_intr_alloc(snic->vdev, &snic->intr[i], i);
  178. if (ret)
  179. goto error_cleanup;
  180. }
  181. /*
  182. * Init WQ Resources.
  183. * WQ[0 to n] points to CQ[0 to n-1]
  184. * firmware to host comm points to CQ[n to m+1]
  185. */
  186. err_intr_enable = 1;
  187. err_intr_offset = snic->err_intr_offset;
  188. for (i = 0; i < snic->wq_count; i++) {
  189. svnic_wq_init(&snic->wq[i],
  190. i,
  191. err_intr_enable,
  192. err_intr_offset);
  193. }
  194. for (i = 0; i < snic->cq_count; i++) {
  195. intr_offset = i;
  196. svnic_cq_init(&snic->cq[i],
  197. 0 /* flow_control_enable */,
  198. 1 /* color_enable */,
  199. 0 /* cq_head */,
  200. 0 /* cq_tail */,
  201. 1 /* cq_tail_color */,
  202. 1 /* interrupt_enable */,
  203. 1 /* cq_entry_enable */,
  204. 0 /* cq_message_enable */,
  205. intr_offset,
  206. 0 /* cq_message_addr */);
  207. }
  208. /*
  209. * Init INTR resources
  210. * Assumption : snic is always in MSI-X mode
  211. */
  212. SNIC_BUG_ON(intr_mode != VNIC_DEV_INTR_MODE_MSIX);
  213. mask_on_assertion = 1;
  214. for (i = 0; i < snic->intr_count; i++) {
  215. svnic_intr_init(&snic->intr[i],
  216. snic->config.intr_timer,
  217. snic->config.intr_timer_type,
  218. mask_on_assertion);
  219. }
  220. /* init the stats memory by making the first call here */
  221. ret = svnic_dev_stats_dump(snic->vdev, &snic->stats);
  222. if (ret) {
  223. SNIC_HOST_ERR(snic->shost,
  224. "svnic_dev_stats_dump failed - x%x\n",
  225. ret);
  226. goto error_cleanup;
  227. }
  228. /* Clear LIF stats */
  229. svnic_dev_stats_clear(snic->vdev);
  230. ret = 0;
  231. return ret;
  232. error_cleanup:
  233. snic_free_vnic_res(snic);
  234. return ret;
  235. }
  236. void
  237. snic_log_q_error(struct snic *snic)
  238. {
  239. unsigned int i;
  240. u32 err_status;
  241. for (i = 0; i < snic->wq_count; i++) {
  242. err_status = ioread32(&snic->wq[i].ctrl->error_status);
  243. if (err_status)
  244. SNIC_HOST_ERR(snic->shost,
  245. "WQ[%d] error status %d\n",
  246. i,
  247. err_status);
  248. }
  249. } /* end of snic_log_q_error */