srq.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * This file is part of the Chelsio T6 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2017-2018 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include "cxgb4.h"
  35. #include "t4_msg.h"
  36. #include "srq.h"
  37. struct srq_data *t4_init_srq(int srq_size)
  38. {
  39. struct srq_data *s;
  40. s = kvzalloc(sizeof(*s), GFP_KERNEL);
  41. if (!s)
  42. return NULL;
  43. s->srq_size = srq_size;
  44. init_completion(&s->comp);
  45. mutex_init(&s->lock);
  46. return s;
  47. }
  48. /* cxgb4_get_srq_entry: read the SRQ table entry
  49. * @dev: Pointer to the net_device
  50. * @idx: Index to the srq
  51. * @entryp: pointer to the srq entry
  52. *
  53. * Sends CPL_SRQ_TABLE_REQ message for the given index.
  54. * Contents will be returned in CPL_SRQ_TABLE_RPL message.
  55. *
  56. * Returns zero if the read is successful, else a error
  57. * number will be returned. Caller should not use the srq
  58. * entry if the return value is non-zero.
  59. *
  60. *
  61. */
  62. int cxgb4_get_srq_entry(struct net_device *dev,
  63. int srq_idx, struct srq_entry *entryp)
  64. {
  65. struct cpl_srq_table_req *req;
  66. struct adapter *adap;
  67. struct sk_buff *skb;
  68. struct srq_data *s;
  69. int rc = -ENODEV;
  70. adap = netdev2adap(dev);
  71. s = adap->srq;
  72. if (!(adap->flags & FULL_INIT_DONE) || !s)
  73. goto out;
  74. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  75. if (!skb)
  76. return -ENOMEM;
  77. req = (struct cpl_srq_table_req *)
  78. __skb_put_zero(skb, sizeof(*req));
  79. INIT_TP_WR(req, 0);
  80. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SRQ_TABLE_REQ,
  81. TID_TID_V(srq_idx) |
  82. TID_QID_V(adap->sge.fw_evtq.abs_id)));
  83. req->idx = srq_idx;
  84. mutex_lock(&s->lock);
  85. s->entryp = entryp;
  86. t4_mgmt_tx(adap, skb);
  87. rc = wait_for_completion_timeout(&s->comp, SRQ_WAIT_TO);
  88. if (rc)
  89. rc = 0;
  90. else /* !rc means we timed out */
  91. rc = -ETIMEDOUT;
  92. WARN_ON_ONCE(entryp->idx != srq_idx);
  93. mutex_unlock(&s->lock);
  94. out:
  95. return rc;
  96. }
  97. EXPORT_SYMBOL(cxgb4_get_srq_entry);
  98. void do_srq_table_rpl(struct adapter *adap,
  99. const struct cpl_srq_table_rpl *rpl)
  100. {
  101. unsigned int idx = TID_TID_G(GET_TID(rpl));
  102. struct srq_data *s = adap->srq;
  103. struct srq_entry *e;
  104. if (unlikely(rpl->status != CPL_CONTAINS_READ_RPL)) {
  105. dev_err(adap->pdev_dev,
  106. "Unexpected SRQ_TABLE_RPL status %u for entry %u\n",
  107. rpl->status, idx);
  108. goto out;
  109. }
  110. /* Store the read entry */
  111. e = s->entryp;
  112. e->valid = 1;
  113. e->idx = idx;
  114. e->pdid = SRQT_PDID_G(be64_to_cpu(rpl->rsvd_pdid));
  115. e->qlen = SRQT_QLEN_G(be32_to_cpu(rpl->qlen_qbase));
  116. e->qbase = SRQT_QBASE_G(be32_to_cpu(rpl->qlen_qbase));
  117. e->cur_msn = be16_to_cpu(rpl->cur_msn);
  118. e->max_msn = be16_to_cpu(rpl->max_msn);
  119. out:
  120. complete(&s->comp);
  121. }