RDMA/core: add port state cache
authorJack Wang <jinpu.wang@profitbricks.com>
Mon, 2 Jan 2017 12:17:36 +0000 (13:17 +0100)
committerDoug Ledford <dledford@redhat.com>
Fri, 13 Jan 2017 03:59:55 +0000 (22:59 -0500)
We need a port state cache in ib_core, later we will use in rdma_cm.

Signed-off-by: Jack Wang <jinpu.wang@profitbricks.com>
Reviewed-by: Michael Wang <yun.wang@profitbricks.com>
Acked-by: Sean Hefty <sean.hefty@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/core/cache.c
include/rdma/ib_verbs.h

index ae04826e82fc0982496f8b560c6465e6562f819c..87fd7c39fbc0f5bf4d30f128e7e91e614242b038 100644 (file)
@@ -1105,6 +1105,8 @@ static void ib_cache_update(struct ib_device *device,
        }
 
        device->cache.lmc_cache[port - rdma_start_port(device)] = tprops->lmc;
+       device->cache.port_state_cache[port - rdma_start_port(device)] =
+               tprops->state;
 
        write_unlock_irq(&device->cache.lock);
 
@@ -1164,7 +1166,11 @@ int ib_cache_setup_one(struct ib_device *device)
                                          (rdma_end_port(device) -
                                           rdma_start_port(device) + 1),
                                          GFP_KERNEL);
-       if (!device->cache.pkey_cache ||
+       device->cache.port_state_cache = kmalloc(sizeof *device->cache.port_state_cache *
+                                         (rdma_end_port(device) -
+                                          rdma_start_port(device) + 1),
+                                         GFP_KERNEL);
+       if (!device->cache.pkey_cache || !device->cache.port_state_cache ||
            !device->cache.lmc_cache) {
                err = -ENOMEM;
                goto free;
@@ -1190,6 +1196,7 @@ err:
 free:
        kfree(device->cache.pkey_cache);
        kfree(device->cache.lmc_cache);
+       kfree(device->cache.port_state_cache);
        return err;
 }
 
@@ -1211,6 +1218,7 @@ void ib_cache_release_one(struct ib_device *device)
        gid_table_release_one(device);
        kfree(device->cache.pkey_cache);
        kfree(device->cache.lmc_cache);
+       kfree(device->cache.port_state_cache);
 }
 
 void ib_cache_cleanup_one(struct ib_device *device)
index 958a24d8fae794547c486b5b025f3815c96f82e7..fafa988e0e9aa7417161f4a0875be5c7a249628c 100644 (file)
@@ -1781,6 +1781,7 @@ struct ib_cache {
        struct ib_pkey_cache  **pkey_cache;
        struct ib_gid_table   **gid_cache;
        u8                     *lmc_cache;
+       enum ib_port_state     *port_state_cache;
 };
 
 struct ib_dma_mapping_ops {