smc_llc.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Shared Memory Communications over RDMA (SMC-R) and RoCE
  3. *
  4. * Link Layer Control (LLC)
  5. *
  6. * For now, we only support the necessary "confirm link" functionality
  7. * which happens for the first RoCE link after successful CLC handshake.
  8. *
  9. * Copyright IBM Corp. 2016
  10. *
  11. * Author(s): Klaus Wacker <Klaus.Wacker@de.ibm.com>
  12. * Ursula Braun <ubraun@linux.vnet.ibm.com>
  13. */
  14. #include <net/tcp.h>
  15. #include <rdma/ib_verbs.h>
  16. #include "smc.h"
  17. #include "smc_core.h"
  18. #include "smc_clc.h"
  19. #include "smc_llc.h"
  20. /********************************** send *************************************/
  21. struct smc_llc_tx_pend {
  22. };
  23. /* handler for send/transmission completion of an LLC msg */
  24. static void smc_llc_tx_handler(struct smc_wr_tx_pend_priv *pend,
  25. struct smc_link *link,
  26. enum ib_wc_status wc_status)
  27. {
  28. /* future work: handle wc_status error for recovery and failover */
  29. }
  30. /**
  31. * smc_llc_add_pending_send() - add LLC control message to pending WQE transmits
  32. * @link: Pointer to SMC link used for sending LLC control message.
  33. * @wr_buf: Out variable returning pointer to work request payload buffer.
  34. * @pend: Out variable returning pointer to private pending WR tracking.
  35. * It's the context the transmit complete handler will get.
  36. *
  37. * Reserves and pre-fills an entry for a pending work request send/tx.
  38. * Used by mid-level smc_llc_send_msg() to prepare for later actual send/tx.
  39. * Can sleep due to smc_get_ctrl_buf (if not in softirq context).
  40. *
  41. * Return: 0 on success, otherwise an error value.
  42. */
  43. static int smc_llc_add_pending_send(struct smc_link *link,
  44. struct smc_wr_buf **wr_buf,
  45. struct smc_wr_tx_pend_priv **pend)
  46. {
  47. int rc;
  48. rc = smc_wr_tx_get_free_slot(link, smc_llc_tx_handler, wr_buf, pend);
  49. if (rc < 0)
  50. return rc;
  51. BUILD_BUG_ON_MSG(
  52. sizeof(union smc_llc_msg) > SMC_WR_BUF_SIZE,
  53. "must increase SMC_WR_BUF_SIZE to at least sizeof(struct smc_llc_msg)");
  54. BUILD_BUG_ON_MSG(
  55. sizeof(union smc_llc_msg) != SMC_WR_TX_SIZE,
  56. "must adapt SMC_WR_TX_SIZE to sizeof(struct smc_llc_msg); if not all smc_wr upper layer protocols use the same message size any more, must start to set link->wr_tx_sges[i].length on each individual smc_wr_tx_send()");
  57. BUILD_BUG_ON_MSG(
  58. sizeof(struct smc_llc_tx_pend) > SMC_WR_TX_PEND_PRIV_SIZE,
  59. "must increase SMC_WR_TX_PEND_PRIV_SIZE to at least sizeof(struct smc_llc_tx_pend)");
  60. return 0;
  61. }
  62. /* high-level API to send LLC confirm link */
  63. int smc_llc_send_confirm_link(struct smc_link *link, u8 mac[],
  64. union ib_gid *gid,
  65. enum smc_llc_reqresp reqresp)
  66. {
  67. struct smc_link_group *lgr = container_of(link, struct smc_link_group,
  68. lnk[SMC_SINGLE_LINK]);
  69. struct smc_llc_msg_confirm_link *confllc;
  70. struct smc_wr_tx_pend_priv *pend;
  71. struct smc_wr_buf *wr_buf;
  72. int rc;
  73. rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
  74. if (rc)
  75. return rc;
  76. confllc = (struct smc_llc_msg_confirm_link *)wr_buf;
  77. memset(confllc, 0, sizeof(*confllc));
  78. confllc->hd.common.type = SMC_LLC_CONFIRM_LINK;
  79. confllc->hd.length = sizeof(struct smc_llc_msg_confirm_link);
  80. if (reqresp == SMC_LLC_RESP)
  81. confllc->hd.flags |= SMC_LLC_FLAG_RESP;
  82. memcpy(confllc->sender_mac, mac, ETH_ALEN);
  83. memcpy(confllc->sender_gid, gid, SMC_GID_SIZE);
  84. hton24(confllc->sender_qp_num, link->roce_qp->qp_num);
  85. /* confllc->link_num = SMC_SINGLE_LINK; already done by memset above */
  86. memcpy(confllc->link_uid, lgr->id, SMC_LGR_ID_SIZE);
  87. confllc->max_links = SMC_LINKS_PER_LGR_MAX;
  88. /* send llc message */
  89. rc = smc_wr_tx_send(link, pend);
  90. return rc;
  91. }
  92. /********************************* receive ***********************************/
  93. static void smc_llc_rx_confirm_link(struct smc_link *link,
  94. struct smc_llc_msg_confirm_link *llc)
  95. {
  96. struct smc_link_group *lgr;
  97. lgr = container_of(link, struct smc_link_group, lnk[SMC_SINGLE_LINK]);
  98. if (llc->hd.flags & SMC_LLC_FLAG_RESP) {
  99. if (lgr->role == SMC_SERV)
  100. complete(&link->llc_confirm_resp);
  101. } else {
  102. if (lgr->role == SMC_CLNT) {
  103. link->link_id = llc->link_num;
  104. complete(&link->llc_confirm);
  105. }
  106. }
  107. }
  108. static void smc_llc_rx_handler(struct ib_wc *wc, void *buf)
  109. {
  110. struct smc_link *link = (struct smc_link *)wc->qp->qp_context;
  111. union smc_llc_msg *llc = buf;
  112. if (wc->byte_len < sizeof(*llc))
  113. return; /* short message */
  114. if (llc->raw.hdr.length != sizeof(*llc))
  115. return; /* invalid message */
  116. if (llc->raw.hdr.common.type == SMC_LLC_CONFIRM_LINK)
  117. smc_llc_rx_confirm_link(link, &llc->confirm_link);
  118. }
  119. /***************************** init, exit, misc ******************************/
  120. static struct smc_wr_rx_handler smc_llc_rx_handlers[] = {
  121. {
  122. .handler = smc_llc_rx_handler,
  123. .type = SMC_LLC_CONFIRM_LINK
  124. },
  125. {
  126. .handler = NULL,
  127. }
  128. };
  129. int __init smc_llc_init(void)
  130. {
  131. struct smc_wr_rx_handler *handler;
  132. int rc = 0;
  133. for (handler = smc_llc_rx_handlers; handler->handler; handler++) {
  134. INIT_HLIST_NODE(&handler->list);
  135. rc = smc_wr_rx_register_handler(handler);
  136. if (rc)
  137. break;
  138. }
  139. return rc;
  140. }