ocrdma_ah.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*******************************************************************
  2. * This file is part of the Emulex RoCE Device Driver for *
  3. * RoCE (RDMA over Converged Ethernet) adapters. *
  4. * Copyright (C) 2008-2012 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * *
  8. * This program is free software; you can redistribute it and/or *
  9. * modify it under the terms of version 2 of the GNU General *
  10. * Public License as published by the Free Software Foundation. *
  11. * This program is distributed in the hope that it will be useful. *
  12. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  13. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  14. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  15. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  16. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  17. * more details, a copy of which can be found in the file COPYING *
  18. * included with this package. *
  19. *
  20. * Contact Information:
  21. * linux-drivers@emulex.com
  22. *
  23. * Emulex
  24. * 3333 Susan Street
  25. * Costa Mesa, CA 92626
  26. *******************************************************************/
  27. #include <net/neighbour.h>
  28. #include <net/netevent.h>
  29. #include <rdma/ib_addr.h>
  30. #include <rdma/ib_cache.h>
  31. #include "ocrdma.h"
  32. #include "ocrdma_verbs.h"
  33. #include "ocrdma_ah.h"
  34. #include "ocrdma_hw.h"
  35. static inline int set_av_attr(struct ocrdma_ah *ah,
  36. struct ib_ah_attr *attr, int pdid)
  37. {
  38. int status = 0;
  39. u16 vlan_tag; bool vlan_enabled = false;
  40. struct ocrdma_dev *dev = ah->dev;
  41. struct ocrdma_eth_vlan eth;
  42. struct ocrdma_grh grh;
  43. int eth_sz;
  44. memset(&eth, 0, sizeof(eth));
  45. memset(&grh, 0, sizeof(grh));
  46. ah->sgid_index = attr->grh.sgid_index;
  47. vlan_tag = rdma_get_vlan_id(&attr->grh.dgid);
  48. if (vlan_tag && (vlan_tag < 0x1000)) {
  49. eth.eth_type = cpu_to_be16(0x8100);
  50. eth.roce_eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE);
  51. vlan_tag |= (attr->sl & 7) << 13;
  52. eth.vlan_tag = cpu_to_be16(vlan_tag);
  53. eth_sz = sizeof(struct ocrdma_eth_vlan);
  54. vlan_enabled = true;
  55. } else {
  56. eth.eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE);
  57. eth_sz = sizeof(struct ocrdma_eth_basic);
  58. }
  59. memcpy(&eth.smac[0], &dev->nic_info.mac_addr[0], ETH_ALEN);
  60. status = ocrdma_resolve_dgid(dev, &attr->grh.dgid, &eth.dmac[0]);
  61. if (status)
  62. return status;
  63. status = ocrdma_query_gid(&dev->ibdev, 1, attr->grh.sgid_index,
  64. (union ib_gid *)&grh.sgid[0]);
  65. if (status)
  66. return status;
  67. grh.tclass_flow = cpu_to_be32((6 << 28) |
  68. (attr->grh.traffic_class << 24) |
  69. attr->grh.flow_label);
  70. /* 0x1b is next header value in GRH */
  71. grh.pdid_hoplimit = cpu_to_be32((pdid << 16) |
  72. (0x1b << 8) | attr->grh.hop_limit);
  73. memcpy(&grh.dgid[0], attr->grh.dgid.raw, sizeof(attr->grh.dgid.raw));
  74. memcpy(&ah->av->eth_hdr, &eth, eth_sz);
  75. memcpy((u8 *)ah->av + eth_sz, &grh, sizeof(struct ocrdma_grh));
  76. if (vlan_enabled)
  77. ah->av->valid |= OCRDMA_AV_VLAN_VALID;
  78. return status;
  79. }
  80. struct ib_ah *ocrdma_create_ah(struct ib_pd *ibpd, struct ib_ah_attr *attr)
  81. {
  82. u32 *ahid_addr;
  83. int status;
  84. struct ocrdma_ah *ah;
  85. struct ocrdma_pd *pd = get_ocrdma_pd(ibpd);
  86. struct ocrdma_dev *dev = pd->dev;
  87. if (!(attr->ah_flags & IB_AH_GRH))
  88. return ERR_PTR(-EINVAL);
  89. ah = kzalloc(sizeof *ah, GFP_ATOMIC);
  90. if (!ah)
  91. return ERR_PTR(-ENOMEM);
  92. ah->dev = pd->dev;
  93. status = ocrdma_alloc_av(dev, ah);
  94. if (status)
  95. goto av_err;
  96. status = set_av_attr(ah, attr, pd->id);
  97. if (status)
  98. goto av_conf_err;
  99. /* if pd is for the user process, pass the ah_id to user space */
  100. if ((pd->uctx) && (pd->uctx->ah_tbl.va)) {
  101. ahid_addr = pd->uctx->ah_tbl.va + attr->dlid;
  102. *ahid_addr = ah->id;
  103. }
  104. return &ah->ibah;
  105. av_conf_err:
  106. ocrdma_free_av(dev, ah);
  107. av_err:
  108. kfree(ah);
  109. return ERR_PTR(status);
  110. }
  111. int ocrdma_destroy_ah(struct ib_ah *ibah)
  112. {
  113. struct ocrdma_ah *ah = get_ocrdma_ah(ibah);
  114. ocrdma_free_av(ah->dev, ah);
  115. kfree(ah);
  116. return 0;
  117. }
  118. int ocrdma_query_ah(struct ib_ah *ibah, struct ib_ah_attr *attr)
  119. {
  120. struct ocrdma_ah *ah = get_ocrdma_ah(ibah);
  121. struct ocrdma_av *av = ah->av;
  122. struct ocrdma_grh *grh;
  123. attr->ah_flags |= IB_AH_GRH;
  124. if (ah->av->valid & Bit(1)) {
  125. grh = (struct ocrdma_grh *)((u8 *)ah->av +
  126. sizeof(struct ocrdma_eth_vlan));
  127. attr->sl = be16_to_cpu(av->eth_hdr.vlan_tag) >> 13;
  128. } else {
  129. grh = (struct ocrdma_grh *)((u8 *)ah->av +
  130. sizeof(struct ocrdma_eth_basic));
  131. attr->sl = 0;
  132. }
  133. memcpy(&attr->grh.dgid.raw[0], &grh->dgid[0], sizeof(grh->dgid));
  134. attr->grh.sgid_index = ah->sgid_index;
  135. attr->grh.hop_limit = be32_to_cpu(grh->pdid_hoplimit) & 0xff;
  136. attr->grh.traffic_class = be32_to_cpu(grh->tclass_flow) >> 24;
  137. attr->grh.flow_label = be32_to_cpu(grh->tclass_flow) & 0x00ffffffff;
  138. return 0;
  139. }
  140. int ocrdma_modify_ah(struct ib_ah *ibah, struct ib_ah_attr *attr)
  141. {
  142. /* modify_ah is unsupported */
  143. return -ENOSYS;
  144. }
  145. int ocrdma_process_mad(struct ib_device *ibdev,
  146. int process_mad_flags,
  147. u8 port_num,
  148. struct ib_wc *in_wc,
  149. struct ib_grh *in_grh,
  150. struct ib_mad *in_mad, struct ib_mad *out_mad)
  151. {
  152. return IB_MAD_RESULT_SUCCESS;
  153. }