0001
0002
0003
0004
0005
0006
0007 #include "rxe.h"
0008 #include "rxe_loc.h"
0009
0010 void rxe_init_av(struct rdma_ah_attr *attr, struct rxe_av *av)
0011 {
0012 rxe_av_from_attr(rdma_ah_get_port_num(attr), av, attr);
0013 rxe_av_fill_ip_info(av, attr);
0014 memcpy(av->dmac, attr->roce.dmac, ETH_ALEN);
0015 }
0016
0017 int rxe_av_chk_attr(struct rxe_dev *rxe, struct rdma_ah_attr *attr)
0018 {
0019 const struct ib_global_route *grh = rdma_ah_read_grh(attr);
0020 struct rxe_port *port;
0021 int type;
0022
0023 port = &rxe->port;
0024
0025 if (rdma_ah_get_ah_flags(attr) & IB_AH_GRH) {
0026 if (grh->sgid_index > port->attr.gid_tbl_len) {
0027 pr_warn("invalid sgid index = %d\n",
0028 grh->sgid_index);
0029 return -EINVAL;
0030 }
0031
0032 type = rdma_gid_attr_network_type(grh->sgid_attr);
0033 if (type < RDMA_NETWORK_IPV4 ||
0034 type > RDMA_NETWORK_IPV6) {
0035 pr_warn("invalid network type for rdma_rxe = %d\n",
0036 type);
0037 return -EINVAL;
0038 }
0039 }
0040
0041 return 0;
0042 }
0043
0044 void rxe_av_from_attr(u8 port_num, struct rxe_av *av,
0045 struct rdma_ah_attr *attr)
0046 {
0047 const struct ib_global_route *grh = rdma_ah_read_grh(attr);
0048
0049 memset(av, 0, sizeof(*av));
0050 memcpy(av->grh.dgid.raw, grh->dgid.raw, sizeof(grh->dgid.raw));
0051 av->grh.flow_label = grh->flow_label;
0052 av->grh.sgid_index = grh->sgid_index;
0053 av->grh.hop_limit = grh->hop_limit;
0054 av->grh.traffic_class = grh->traffic_class;
0055 av->port_num = port_num;
0056 }
0057
0058 void rxe_av_to_attr(struct rxe_av *av, struct rdma_ah_attr *attr)
0059 {
0060 struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
0061
0062 attr->type = RDMA_AH_ATTR_TYPE_ROCE;
0063
0064 memcpy(grh->dgid.raw, av->grh.dgid.raw, sizeof(av->grh.dgid.raw));
0065 grh->flow_label = av->grh.flow_label;
0066 grh->sgid_index = av->grh.sgid_index;
0067 grh->hop_limit = av->grh.hop_limit;
0068 grh->traffic_class = av->grh.traffic_class;
0069
0070 rdma_ah_set_ah_flags(attr, IB_AH_GRH);
0071 rdma_ah_set_port_num(attr, av->port_num);
0072 }
0073
0074 void rxe_av_fill_ip_info(struct rxe_av *av, struct rdma_ah_attr *attr)
0075 {
0076 const struct ib_gid_attr *sgid_attr = attr->grh.sgid_attr;
0077 int ibtype;
0078 int type;
0079
0080 rdma_gid2ip((struct sockaddr *)&av->sgid_addr, &sgid_attr->gid);
0081 rdma_gid2ip((struct sockaddr *)&av->dgid_addr,
0082 &rdma_ah_read_grh(attr)->dgid);
0083
0084 ibtype = rdma_gid_attr_network_type(sgid_attr);
0085
0086 switch (ibtype) {
0087 case RDMA_NETWORK_IPV4:
0088 type = RXE_NETWORK_TYPE_IPV4;
0089 break;
0090 case RDMA_NETWORK_IPV6:
0091 type = RXE_NETWORK_TYPE_IPV6;
0092 break;
0093 default:
0094
0095 type = 0;
0096 break;
0097 }
0098
0099 av->network_type = type;
0100 }
0101
0102 struct rxe_av *rxe_get_av(struct rxe_pkt_info *pkt, struct rxe_ah **ahp)
0103 {
0104 struct rxe_ah *ah;
0105 u32 ah_num;
0106
0107 if (ahp)
0108 *ahp = NULL;
0109
0110 if (!pkt || !pkt->qp)
0111 return NULL;
0112
0113 if (qp_type(pkt->qp) == IB_QPT_RC || qp_type(pkt->qp) == IB_QPT_UC)
0114 return &pkt->qp->pri_av;
0115
0116 if (!pkt->wqe)
0117 return NULL;
0118
0119 ah_num = pkt->wqe->wr.wr.ud.ah_num;
0120 if (ah_num) {
0121
0122 ah = rxe_pool_get_index(&pkt->rxe->ah_pool, ah_num);
0123 if (!ah) {
0124 pr_warn("Unable to find AH matching ah_num\n");
0125 return NULL;
0126 }
0127
0128 if (rxe_ah_pd(ah) != pkt->qp->pd) {
0129 pr_warn("PDs don't match for AH and QP\n");
0130 rxe_put(ah);
0131 return NULL;
0132 }
0133
0134 if (ahp)
0135 *ahp = ah;
0136 else
0137 rxe_put(ah);
0138
0139 return &ah->av;
0140 }
0141
0142
0143 return &pkt->wqe->wr.wr.ud.av;
0144 }