ocrdma_ah.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 "ocrdma.h"
  31. #include "ocrdma_verbs.h"
  32. #include "ocrdma_ah.h"
  33. #include "ocrdma_hw.h"
  34. static inline int set_av_attr(struct ocrdma_dev *dev, struct ocrdma_ah *ah,
  35. struct ib_ah_attr *attr, int pdid)
  36. {
  37. int status = 0;
  38. u16 vlan_tag; bool vlan_enabled = false;
  39. struct ocrdma_eth_vlan eth;
  40. struct ocrdma_grh grh;
  41. int eth_sz;
  42. memset(&eth, 0, sizeof(eth));
  43. memset(&grh, 0, sizeof(grh));
  44. ah->sgid_index = attr->grh.sgid_index;
  45. vlan_tag = rdma_get_vlan_id(&attr->grh.dgid);
  46. if (vlan_tag && (vlan_tag < 0x1000)) {
  47. eth.eth_type = cpu_to_be16(0x8100);
  48. eth.roce_eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE);
  49. vlan_tag |= (attr->sl & 7) << 13;
  50. eth.vlan_tag = cpu_to_be16(vlan_tag);
  51. eth_sz = sizeof(struct ocrdma_eth_vlan);
  52. vlan_enabled = true;
  53. } else {
  54. eth.eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE);
  55. eth_sz = sizeof(struct ocrdma_eth_basic);
  56. }
  57. memcpy(&eth.smac[0], &dev->nic_info.mac_addr[0], ETH_ALEN);
  58. status = ocrdma_resolve_dgid(dev, &attr->grh.dgid, &eth.dmac[0]);
  59. if (status)
  60. return status;
  61. status = ocrdma_query_gid(&dev->ibdev, 1, attr->grh.sgid_index,
  62. (union ib_gid *)&grh.sgid[0]);
  63. if (status)
  64. return status;
  65. grh.tclass_flow = cpu_to_be32((6 << 28) |
  66. (attr->grh.traffic_class << 24) |
  67. attr->grh.flow_label);
  68. /* 0x1b is next header value in GRH */
  69. grh.pdid_hoplimit = cpu_to_be32((pdid << 16) |
  70. (0x1b << 8) | attr->grh.hop_limit);
  71. memcpy(&grh.dgid[0], attr->grh.dgid.raw, sizeof(attr->grh.dgid.raw));
  72. memcpy(&ah->av->eth_hdr, &eth, eth_sz);
  73. memcpy((u8 *)ah->av + eth_sz, &grh, sizeof(struct ocrdma_grh));
  74. if (vlan_enabled)
  75. ah->av->valid |= OCRDMA_AV_VLAN_VALID;
  76. return status;
  77. }
  78. struct ib_ah *ocrdma_create_ah(struct ib_pd *ibpd, struct ib_ah_attr *attr)
  79. {
  80. u32 *ahid_addr;
  81. int status;
  82. struct ocrdma_ah *ah;
  83. struct ocrdma_pd *pd = get_ocrdma_pd(ibpd);
  84. struct ocrdma_dev *dev = get_ocrdma_dev(ibpd->device);
  85. if (!(attr->ah_flags & IB_AH_GRH))
  86. return ERR_PTR(-EINVAL);
  87. ah = kzalloc(sizeof *ah, GFP_ATOMIC);
  88. if (!ah)
  89. return ERR_PTR(-ENOMEM);
  90. status = ocrdma_alloc_av(dev, ah);
  91. if (status)
  92. goto av_err;
  93. status = set_av_attr(dev, ah, attr, pd->id);
  94. if (status)
  95. goto av_conf_err;
  96. /* if pd is for the user process, pass the ah_id to user space */
  97. if ((pd->uctx) && (pd->uctx->ah_tbl.va)) {
  98. ahid_addr = pd->uctx->ah_tbl.va + attr->dlid;
  99. *ahid_addr = ah->id;
  100. }
  101. return &ah->ibah;
  102. av_conf_err:
  103. ocrdma_free_av(dev, ah);
  104. av_err:
  105. kfree(ah);
  106. return ERR_PTR(status);
  107. }
  108. int ocrdma_destroy_ah(struct ib_ah *ibah)
  109. {
  110. struct ocrdma_ah *ah = get_ocrdma_ah(ibah);
  111. struct ocrdma_dev *dev = get_ocrdma_dev(ibah->device);
  112. ocrdma_free_av(dev, ah);
  113. kfree(ah);
  114. return 0;
  115. }
  116. int ocrdma_query_ah(struct ib_ah *ibah, struct ib_ah_attr *attr)
  117. {
  118. struct ocrdma_ah *ah = get_ocrdma_ah(ibah);
  119. struct ocrdma_av *av = ah->av;
  120. struct ocrdma_grh *grh;
  121. attr->ah_flags |= IB_AH_GRH;
  122. if (ah->av->valid & Bit(1)) {
  123. grh = (struct ocrdma_grh *)((u8 *)ah->av +
  124. sizeof(struct ocrdma_eth_vlan));
  125. attr->sl = be16_to_cpu(av->eth_hdr.vlan_tag) >> 13;
  126. } else {
  127. grh = (struct ocrdma_grh *)((u8 *)ah->av +
  128. sizeof(struct ocrdma_eth_basic));
  129. attr->sl = 0;
  130. }
  131. memcpy(&attr->grh.dgid.raw[0], &grh->dgid[0], sizeof(grh->dgid));
  132. attr->grh.sgid_index = ah->sgid_index;
  133. attr->grh.hop_limit = be32_to_cpu(grh->pdid_hoplimit) & 0xff;
  134. attr->grh.traffic_class = be32_to_cpu(grh->tclass_flow) >> 24;
  135. attr->grh.flow_label = be32_to_cpu(grh->tclass_flow) & 0x00ffffffff;
  136. return 0;
  137. }
  138. int ocrdma_modify_ah(struct ib_ah *ibah, struct ib_ah_attr *attr)
  139. {
  140. /* modify_ah is unsupported */
  141. return -ENOSYS;
  142. }
  143. int ocrdma_process_mad(struct ib_device *ibdev,
  144. int process_mad_flags,
  145. u8 port_num,
  146. struct ib_wc *in_wc,
  147. struct ib_grh *in_grh,
  148. struct ib_mad *in_mad, struct ib_mad *out_mad)
  149. {
  150. return IB_MAD_RESULT_SUCCESS;
  151. }