Commit 6fb9cdbf2cdb2ea187e57ec2e16cc59df2adf86a
Committed by
Roland Dreier
1 parent
856c256f88
Exists in
master
and in
39 other branches
IB: Add caching of ports' LMC
Add an LMC cache to struct ib_device, and add a function ib_get_cached_lmc() to query the cache. Signed-off-by: Jack Morgenstein <jackm@mellanox.co.il> Signed-off-by: Sean Hefty <sean.hefty@intel.com> Signed-off-by: Roland Dreier <rolandd@cisco.com>
Showing 3 changed files with 43 additions and 1 deletions Side-by-side Diff
drivers/infiniband/core/cache.c
... | ... | @@ -191,6 +191,24 @@ |
191 | 191 | } |
192 | 192 | EXPORT_SYMBOL(ib_find_cached_pkey); |
193 | 193 | |
194 | +int ib_get_cached_lmc(struct ib_device *device, | |
195 | + u8 port_num, | |
196 | + u8 *lmc) | |
197 | +{ | |
198 | + unsigned long flags; | |
199 | + int ret = 0; | |
200 | + | |
201 | + if (port_num < start_port(device) || port_num > end_port(device)) | |
202 | + return -EINVAL; | |
203 | + | |
204 | + read_lock_irqsave(&device->cache.lock, flags); | |
205 | + *lmc = device->cache.lmc_cache[port_num - start_port(device)]; | |
206 | + read_unlock_irqrestore(&device->cache.lock, flags); | |
207 | + | |
208 | + return ret; | |
209 | +} | |
210 | +EXPORT_SYMBOL(ib_get_cached_lmc); | |
211 | + | |
194 | 212 | static void ib_cache_update(struct ib_device *device, |
195 | 213 | u8 port) |
196 | 214 | { |
... | ... | @@ -251,6 +269,8 @@ |
251 | 269 | device->cache.pkey_cache[port - start_port(device)] = pkey_cache; |
252 | 270 | device->cache.gid_cache [port - start_port(device)] = gid_cache; |
253 | 271 | |
272 | + device->cache.lmc_cache[port - start_port(device)] = tprops->lmc; | |
273 | + | |
254 | 274 | write_unlock_irq(&device->cache.lock); |
255 | 275 | |
256 | 276 | kfree(old_pkey_cache); |
... | ... | @@ -305,7 +325,13 @@ |
305 | 325 | kmalloc(sizeof *device->cache.gid_cache * |
306 | 326 | (end_port(device) - start_port(device) + 1), GFP_KERNEL); |
307 | 327 | |
308 | - if (!device->cache.pkey_cache || !device->cache.gid_cache) { | |
328 | + device->cache.lmc_cache = kmalloc(sizeof *device->cache.lmc_cache * | |
329 | + (end_port(device) - | |
330 | + start_port(device) + 1), | |
331 | + GFP_KERNEL); | |
332 | + | |
333 | + if (!device->cache.pkey_cache || !device->cache.gid_cache || | |
334 | + !device->cache.lmc_cache) { | |
309 | 335 | printk(KERN_WARNING "Couldn't allocate cache " |
310 | 336 | "for %s\n", device->name); |
311 | 337 | goto err; |
... | ... | @@ -333,6 +359,7 @@ |
333 | 359 | err: |
334 | 360 | kfree(device->cache.pkey_cache); |
335 | 361 | kfree(device->cache.gid_cache); |
362 | + kfree(device->cache.lmc_cache); | |
336 | 363 | } |
337 | 364 | |
338 | 365 | static void ib_cache_cleanup_one(struct ib_device *device) |
... | ... | @@ -349,6 +376,7 @@ |
349 | 376 | |
350 | 377 | kfree(device->cache.pkey_cache); |
351 | 378 | kfree(device->cache.gid_cache); |
379 | + kfree(device->cache.lmc_cache); | |
352 | 380 | } |
353 | 381 | |
354 | 382 | static struct ib_client cache_client = { |
include/rdma/ib_cache.h
... | ... | @@ -102,5 +102,18 @@ |
102 | 102 | u16 pkey, |
103 | 103 | u16 *index); |
104 | 104 | |
105 | +/** | |
106 | + * ib_get_cached_lmc - Returns a cached lmc table entry | |
107 | + * @device: The device to query. | |
108 | + * @port_num: The port number of the device to query. | |
109 | + * @lmc: The lmc value for the specified port for that device. | |
110 | + * | |
111 | + * ib_get_cached_lmc() fetches the specified lmc table entry stored in | |
112 | + * the local software cache. | |
113 | + */ | |
114 | +int ib_get_cached_lmc(struct ib_device *device, | |
115 | + u8 port_num, | |
116 | + u8 *lmc); | |
117 | + | |
105 | 118 | #endif /* _IB_CACHE_H */ |