]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/infiniband/core/sa_query.c
IB/SA: Split struct sa_path_rec based on IB and ROCE specific fields
[karo-tx-linux.git] / drivers / infiniband / core / sa_query.c
index ee82aab8f7d90065c3ba41d59f03b5eeb754b619..88361c164d7392386073a3bc0d236484cd202747 100644 (file)
@@ -193,7 +193,7 @@ static u32 tid;
        .field_name          = "sa_path_rec:" #field
 
 static const struct ib_field path_rec_table[] = {
-       { PATH_REC_FIELD(service_id),
+       { PATH_REC_FIELD(ib.service_id),
          .offset_words = 0,
          .offset_bits  = 0,
          .size_bits    = 64 },
@@ -205,15 +205,15 @@ static const struct ib_field path_rec_table[] = {
          .offset_words = 6,
          .offset_bits  = 0,
          .size_bits    = 128 },
-       { PATH_REC_FIELD(dlid),
+       { PATH_REC_FIELD(ib.dlid),
          .offset_words = 10,
          .offset_bits  = 0,
          .size_bits    = 16 },
-       { PATH_REC_FIELD(slid),
+       { PATH_REC_FIELD(ib.slid),
          .offset_words = 10,
          .offset_bits  = 16,
          .size_bits    = 16 },
-       { PATH_REC_FIELD(raw_traffic),
+       { PATH_REC_FIELD(ib.raw_traffic),
          .offset_words = 11,
          .offset_bits  = 0,
          .size_bits    = 1 },
@@ -643,7 +643,7 @@ static void ib_nl_set_path_rec_attrs(struct sk_buff *skb,
 
        /* Now build the attributes */
        if (comp_mask & IB_SA_PATH_REC_SERVICE_ID) {
-               val64 = be64_to_cpu(sa_rec->service_id);
+               val64 = be64_to_cpu(sa_path_get_service_id(sa_rec));
                nla_put(skb, RDMA_NLA_F_MANDATORY | LS_NLA_TYPE_SERVICE_ID,
                        sizeof(val64), &val64);
        }
@@ -1110,9 +1110,9 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
        memset(ah_attr, 0, sizeof *ah_attr);
        ah_attr->type = rdma_ah_find_type(device, port_num);
 
-       rdma_ah_set_dlid(ah_attr, be16_to_cpu(rec->dlid));
+       rdma_ah_set_dlid(ah_attr, be16_to_cpu(sa_path_get_dlid(rec)));
        rdma_ah_set_sl(ah_attr, rec->sl);
-       rdma_ah_set_path_bits(ah_attr, be16_to_cpu(rec->slid) &
+       rdma_ah_set_path_bits(ah_attr, be16_to_cpu(sa_path_get_slid(rec)) &
                              get_src_path_mask(device, port_num));
        rdma_ah_set_port_num(ah_attr, port_num);
        rdma_ah_set_static_rate(ah_attr, rec->rate);
@@ -1121,9 +1121,13 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
        if (use_roce) {
                struct net_device *idev;
                struct net_device *resolved_dev;
-               struct rdma_dev_addr dev_addr = {.bound_dev_if = rec->ifindex,
-                                                .net = rec->net ? rec->net :
-                                                        &init_net};
+               struct rdma_dev_addr dev_addr = {
+                       .bound_dev_if = ((sa_path_get_ifindex(rec) >= 0) ?
+                                        sa_path_get_ifindex(rec) : 0),
+                       .net = sa_path_get_ndev(rec) ?
+                               sa_path_get_ndev(rec) :
+                               &init_net
+               };
                union {
                        struct sockaddr     _sockaddr;
                        struct sockaddr_in  _sockaddr_in;
@@ -1144,7 +1148,7 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
 
                if ((dev_addr.network == RDMA_NETWORK_IPV4 ||
                     dev_addr.network == RDMA_NETWORK_IPV6) &&
-                   rec->gid_type != IB_GID_TYPE_ROCE_UDP_ENCAP)
+                   rec->rec_type != SA_PATH_REC_TYPE_ROCE_V2)
                        return -EINVAL;
 
                idev = device->get_netdev(device, port_num);
@@ -1175,9 +1179,10 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
        }
 
        if (rec->hop_limit > 0 || use_roce) {
-               ret = ib_find_cached_gid_by_port(device, &rec->sgid,
-                                                rec->gid_type, port_num, ndev,
-                                                &gid_index);
+               enum ib_gid_type type = sa_conv_pathrec_to_gid_type(rec);
+
+               ret = ib_find_cached_gid_by_port(device, &rec->sgid, type,
+                                                port_num, ndev, &gid_index);
                if (ret) {
                        if (ndev)
                                dev_put(ndev);
@@ -1192,8 +1197,13 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
                        dev_put(ndev);
        }
 
-       if (use_roce)
-               memcpy(ah_attr->roce.dmac, rec->dmac, ETH_ALEN);
+       if (use_roce) {
+               u8 *dmac = sa_path_get_dmac(rec);
+
+               if (!dmac)
+                       return -EINVAL;
+               memcpy(ah_attr->roce.dmac, dmac, ETH_ALEN);
+       }
 
        return 0;
 }
@@ -1325,10 +1335,10 @@ static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query,
 
                ib_unpack(path_rec_table, ARRAY_SIZE(path_rec_table),
                          mad->data, &rec);
-               rec.net = NULL;
-               rec.ifindex = 0;
-               rec.gid_type = IB_GID_TYPE_IB;
-               eth_zero_addr(rec.dmac);
+               rec.rec_type = SA_PATH_REC_TYPE_IB;
+               sa_path_set_ndev(&rec, NULL);
+               sa_path_set_ifindex(&rec, 0);
+               sa_path_set_dmac_zero(&rec);
                query->callback(status, &rec, query->context);
        } else
                query->callback(status, NULL, query->context);
@@ -1385,6 +1395,9 @@ int ib_sa_path_rec_get(struct ib_sa_client *client,
        if (!sa_dev)
                return -ENODEV;
 
+       if (rec->rec_type != SA_PATH_REC_TYPE_IB)
+               return -EINVAL;
+
        port  = &sa_dev->port[port_num - sa_dev->start_port];
        agent = port->agent;