diff options
author | Parav Pandit <parav@mellanox.com> | 2018-05-22 13:33:46 -0400 |
---|---|---|
committer | Jason Gunthorpe <jgg@mellanox.com> | 2018-05-24 11:39:25 -0400 |
commit | 724631a9c6e98e39480c70047cc3fe2d1f25e1fc (patch) | |
tree | a9dc2a4439a1cdea36282dde6d64dc740594c816 /drivers/infiniband/core/cache.c | |
parent | 25e62655c79395c596601a35805c3c7376d097b6 (diff) |
IB/core: Introduce and use rdma_gid_table()
There are several places a gid table is accessed.
Have a helper tiny function rdma_gid_table() to avoid code
duplication at such places.
Signed-off-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Diffstat (limited to 'drivers/infiniband/core/cache.c')
-rw-r--r-- | drivers/infiniband/core/cache.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c index 82699f70e9b6..0d11538c2a25 100644 --- a/drivers/infiniband/core/cache.c +++ b/drivers/infiniband/core/cache.c | |||
@@ -159,6 +159,11 @@ int ib_cache_gid_parse_type_str(const char *buf) | |||
159 | } | 159 | } |
160 | EXPORT_SYMBOL(ib_cache_gid_parse_type_str); | 160 | EXPORT_SYMBOL(ib_cache_gid_parse_type_str); |
161 | 161 | ||
162 | static struct ib_gid_table *rdma_gid_table(struct ib_device *device, u8 port) | ||
163 | { | ||
164 | return device->cache.ports[port - rdma_start_port(device)].gid; | ||
165 | } | ||
166 | |||
162 | static void del_roce_gid(struct ib_device *device, u8 port_num, | 167 | static void del_roce_gid(struct ib_device *device, u8 port_num, |
163 | struct ib_gid_table *table, int ix) | 168 | struct ib_gid_table *table, int ix) |
164 | { | 169 | { |
@@ -376,7 +381,7 @@ static int __ib_cache_gid_add(struct ib_device *ib_dev, u8 port, | |||
376 | if (rdma_is_zero_gid(gid)) | 381 | if (rdma_is_zero_gid(gid)) |
377 | return -EINVAL; | 382 | return -EINVAL; |
378 | 383 | ||
379 | table = ib_dev->cache.ports[port - rdma_start_port(ib_dev)].gid; | 384 | table = rdma_gid_table(ib_dev, port); |
380 | 385 | ||
381 | mutex_lock(&table->lock); | 386 | mutex_lock(&table->lock); |
382 | 387 | ||
@@ -443,7 +448,7 @@ _ib_cache_gid_del(struct ib_device *ib_dev, u8 port, | |||
443 | int ret = 0; | 448 | int ret = 0; |
444 | int ix; | 449 | int ix; |
445 | 450 | ||
446 | table = ib_dev->cache.ports[port - rdma_start_port(ib_dev)].gid; | 451 | table = rdma_gid_table(ib_dev, port); |
447 | 452 | ||
448 | mutex_lock(&table->lock); | 453 | mutex_lock(&table->lock); |
449 | 454 | ||
@@ -482,7 +487,7 @@ int ib_cache_gid_del_all_netdev_gids(struct ib_device *ib_dev, u8 port, | |||
482 | int ix; | 487 | int ix; |
483 | bool deleted = false; | 488 | bool deleted = false; |
484 | 489 | ||
485 | table = ib_dev->cache.ports[port - rdma_start_port(ib_dev)].gid; | 490 | table = rdma_gid_table(ib_dev, port); |
486 | 491 | ||
487 | mutex_lock(&table->lock); | 492 | mutex_lock(&table->lock); |
488 | 493 | ||
@@ -506,7 +511,7 @@ static int __ib_cache_gid_get(struct ib_device *ib_dev, u8 port, int index, | |||
506 | { | 511 | { |
507 | struct ib_gid_table *table; | 512 | struct ib_gid_table *table; |
508 | 513 | ||
509 | table = ib_dev->cache.ports[port - rdma_start_port(ib_dev)].gid; | 514 | table = rdma_gid_table(ib_dev, port); |
510 | 515 | ||
511 | if (index < 0 || index >= table->sz) | 516 | if (index < 0 || index >= table->sz) |
512 | return -EINVAL; | 517 | return -EINVAL; |
@@ -599,7 +604,7 @@ int ib_find_cached_gid_by_port(struct ib_device *ib_dev, | |||
599 | if (!rdma_is_port_valid(ib_dev, port)) | 604 | if (!rdma_is_port_valid(ib_dev, port)) |
600 | return -ENOENT; | 605 | return -ENOENT; |
601 | 606 | ||
602 | table = ib_dev->cache.ports[port - rdma_start_port(ib_dev)].gid; | 607 | table = rdma_gid_table(ib_dev, port); |
603 | 608 | ||
604 | if (ndev) | 609 | if (ndev) |
605 | mask |= GID_ATTR_FIND_MASK_NETDEV; | 610 | mask |= GID_ATTR_FIND_MASK_NETDEV; |
@@ -657,7 +662,7 @@ static int ib_cache_gid_find_by_filter(struct ib_device *ib_dev, | |||
657 | !rdma_protocol_roce(ib_dev, port)) | 662 | !rdma_protocol_roce(ib_dev, port)) |
658 | return -EPROTONOSUPPORT; | 663 | return -EPROTONOSUPPORT; |
659 | 664 | ||
660 | table = ib_dev->cache.ports[port - rdma_start_port(ib_dev)].gid; | 665 | table = rdma_gid_table(ib_dev, port); |
661 | 666 | ||
662 | read_lock_irqsave(&table->rwlock, flags); | 667 | read_lock_irqsave(&table->rwlock, flags); |
663 | for (i = 0; i < table->sz; i++) { | 668 | for (i = 0; i < table->sz; i++) { |
@@ -756,7 +761,7 @@ void ib_cache_gid_set_default_gid(struct ib_device *ib_dev, u8 port, | |||
756 | unsigned int gid_type; | 761 | unsigned int gid_type; |
757 | unsigned long mask; | 762 | unsigned long mask; |
758 | 763 | ||
759 | table = ib_dev->cache.ports[port - rdma_start_port(ib_dev)].gid; | 764 | table = rdma_gid_table(ib_dev, port); |
760 | 765 | ||
761 | mask = GID_ATTR_FIND_MASK_GID_TYPE | | 766 | mask = GID_ATTR_FIND_MASK_GID_TYPE | |
762 | GID_ATTR_FIND_MASK_DEFAULT | | 767 | GID_ATTR_FIND_MASK_DEFAULT | |
@@ -877,7 +882,7 @@ int ib_get_cached_gid(struct ib_device *device, | |||
877 | if (!rdma_is_port_valid(device, port_num)) | 882 | if (!rdma_is_port_valid(device, port_num)) |
878 | return -EINVAL; | 883 | return -EINVAL; |
879 | 884 | ||
880 | table = device->cache.ports[port_num - rdma_start_port(device)].gid; | 885 | table = rdma_gid_table(device, port_num); |
881 | read_lock_irqsave(&table->rwlock, flags); | 886 | read_lock_irqsave(&table->rwlock, flags); |
882 | res = __ib_cache_gid_get(device, port_num, index, gid, gid_attr); | 887 | res = __ib_cache_gid_get(device, port_num, index, gid, gid_attr); |
883 | read_unlock_irqrestore(&table->rwlock, flags); | 888 | read_unlock_irqrestore(&table->rwlock, flags); |
@@ -1095,7 +1100,7 @@ static int config_non_roce_gid_cache(struct ib_device *device, | |||
1095 | 1100 | ||
1096 | gid_attr.device = device; | 1101 | gid_attr.device = device; |
1097 | gid_attr.port_num = port; | 1102 | gid_attr.port_num = port; |
1098 | table = device->cache.ports[port - rdma_start_port(device)].gid; | 1103 | table = rdma_gid_table(device, port); |
1099 | 1104 | ||
1100 | mutex_lock(&table->lock); | 1105 | mutex_lock(&table->lock); |
1101 | for (i = 0; i < gid_tbl_len; ++i) { | 1106 | for (i = 0; i < gid_tbl_len; ++i) { |
@@ -1128,7 +1133,7 @@ static void ib_cache_update(struct ib_device *device, | |||
1128 | if (!rdma_is_port_valid(device, port)) | 1133 | if (!rdma_is_port_valid(device, port)) |
1129 | return; | 1134 | return; |
1130 | 1135 | ||
1131 | table = device->cache.ports[port - rdma_start_port(device)].gid; | 1136 | table = rdma_gid_table(device, port); |
1132 | 1137 | ||
1133 | tprops = kmalloc(sizeof *tprops, GFP_KERNEL); | 1138 | tprops = kmalloc(sizeof *tprops, GFP_KERNEL); |
1134 | if (!tprops) | 1139 | if (!tprops) |