@@ -51,9 +51,8 @@ struct ib_pkey_cache {
51
51
52
52
struct ib_update_work {
53
53
struct work_struct work ;
54
- struct ib_device * device ;
55
- u8 port_num ;
56
- bool enforce_security ;
54
+ struct ib_event event ;
55
+ bool enforce_security ;
57
56
};
58
57
59
58
union ib_gid zgid ;
@@ -130,7 +129,7 @@ static void dispatch_gid_change_event(struct ib_device *ib_dev, u8 port)
130
129
event .element .port_num = port ;
131
130
event .event = IB_EVENT_GID_CHANGE ;
132
131
133
- ib_dispatch_event (& event );
132
+ ib_dispatch_event_clients (& event );
134
133
}
135
134
136
135
static const char * const gid_type_str [] = {
@@ -1034,7 +1033,7 @@ int ib_get_cached_pkey(struct ib_device *device,
1034
1033
if (!rdma_is_port_valid (device , port_num ))
1035
1034
return - EINVAL ;
1036
1035
1037
- read_lock_irqsave (& device -> cache . lock , flags );
1036
+ read_lock_irqsave (& device -> cache_lock , flags );
1038
1037
1039
1038
cache = device -> port_data [port_num ].cache .pkey ;
1040
1039
@@ -1043,7 +1042,7 @@ int ib_get_cached_pkey(struct ib_device *device,
1043
1042
else
1044
1043
* pkey = cache -> table [index ];
1045
1044
1046
- read_unlock_irqrestore (& device -> cache . lock , flags );
1045
+ read_unlock_irqrestore (& device -> cache_lock , flags );
1047
1046
1048
1047
return ret ;
1049
1048
}
@@ -1058,9 +1057,9 @@ int ib_get_cached_subnet_prefix(struct ib_device *device,
1058
1057
if (!rdma_is_port_valid (device , port_num ))
1059
1058
return - EINVAL ;
1060
1059
1061
- read_lock_irqsave (& device -> cache . lock , flags );
1060
+ read_lock_irqsave (& device -> cache_lock , flags );
1062
1061
* sn_pfx = device -> port_data [port_num ].cache .subnet_prefix ;
1063
- read_unlock_irqrestore (& device -> cache . lock , flags );
1062
+ read_unlock_irqrestore (& device -> cache_lock , flags );
1064
1063
1065
1064
return 0 ;
1066
1065
}
@@ -1080,7 +1079,7 @@ int ib_find_cached_pkey(struct ib_device *device,
1080
1079
if (!rdma_is_port_valid (device , port_num ))
1081
1080
return - EINVAL ;
1082
1081
1083
- read_lock_irqsave (& device -> cache . lock , flags );
1082
+ read_lock_irqsave (& device -> cache_lock , flags );
1084
1083
1085
1084
cache = device -> port_data [port_num ].cache .pkey ;
1086
1085
@@ -1101,7 +1100,7 @@ int ib_find_cached_pkey(struct ib_device *device,
1101
1100
ret = 0 ;
1102
1101
}
1103
1102
1104
- read_unlock_irqrestore (& device -> cache . lock , flags );
1103
+ read_unlock_irqrestore (& device -> cache_lock , flags );
1105
1104
1106
1105
return ret ;
1107
1106
}
@@ -1120,7 +1119,7 @@ int ib_find_exact_cached_pkey(struct ib_device *device,
1120
1119
if (!rdma_is_port_valid (device , port_num ))
1121
1120
return - EINVAL ;
1122
1121
1123
- read_lock_irqsave (& device -> cache . lock , flags );
1122
+ read_lock_irqsave (& device -> cache_lock , flags );
1124
1123
1125
1124
cache = device -> port_data [port_num ].cache .pkey ;
1126
1125
@@ -1133,7 +1132,7 @@ int ib_find_exact_cached_pkey(struct ib_device *device,
1133
1132
break ;
1134
1133
}
1135
1134
1136
- read_unlock_irqrestore (& device -> cache . lock , flags );
1135
+ read_unlock_irqrestore (& device -> cache_lock , flags );
1137
1136
1138
1137
return ret ;
1139
1138
}
@@ -1149,9 +1148,9 @@ int ib_get_cached_lmc(struct ib_device *device,
1149
1148
if (!rdma_is_port_valid (device , port_num ))
1150
1149
return - EINVAL ;
1151
1150
1152
- read_lock_irqsave (& device -> cache . lock , flags );
1151
+ read_lock_irqsave (& device -> cache_lock , flags );
1153
1152
* lmc = device -> port_data [port_num ].cache .lmc ;
1154
- read_unlock_irqrestore (& device -> cache . lock , flags );
1153
+ read_unlock_irqrestore (& device -> cache_lock , flags );
1155
1154
1156
1155
return ret ;
1157
1156
}
@@ -1167,9 +1166,9 @@ int ib_get_cached_port_state(struct ib_device *device,
1167
1166
if (!rdma_is_port_valid (device , port_num ))
1168
1167
return - EINVAL ;
1169
1168
1170
- read_lock_irqsave (& device -> cache . lock , flags );
1169
+ read_lock_irqsave (& device -> cache_lock , flags );
1171
1170
* port_state = device -> port_data [port_num ].cache .port_state ;
1172
- read_unlock_irqrestore (& device -> cache . lock , flags );
1171
+ read_unlock_irqrestore (& device -> cache_lock , flags );
1173
1172
1174
1173
return ret ;
1175
1174
}
@@ -1381,21 +1380,20 @@ static int config_non_roce_gid_cache(struct ib_device *device,
1381
1380
return ret ;
1382
1381
}
1383
1382
1384
- static void ib_cache_update (struct ib_device * device ,
1385
- u8 port ,
1386
- bool enforce_security )
1383
+ static int
1384
+ ib_cache_update (struct ib_device * device , u8 port , bool enforce_security )
1387
1385
{
1388
1386
struct ib_port_attr * tprops = NULL ;
1389
1387
struct ib_pkey_cache * pkey_cache = NULL , * old_pkey_cache ;
1390
1388
int i ;
1391
1389
int ret ;
1392
1390
1393
1391
if (!rdma_is_port_valid (device , port ))
1394
- return ;
1392
+ return - EINVAL ;
1395
1393
1396
1394
tprops = kmalloc (sizeof * tprops , GFP_KERNEL );
1397
1395
if (!tprops )
1398
- return ;
1396
+ return - ENOMEM ;
1399
1397
1400
1398
ret = ib_query_port (device , port , tprops );
1401
1399
if (ret ) {
@@ -1413,8 +1411,10 @@ static void ib_cache_update(struct ib_device *device,
1413
1411
pkey_cache = kmalloc (struct_size (pkey_cache , table ,
1414
1412
tprops -> pkey_tbl_len ),
1415
1413
GFP_KERNEL );
1416
- if (!pkey_cache )
1414
+ if (!pkey_cache ) {
1415
+ ret = - ENOMEM ;
1417
1416
goto err ;
1417
+ }
1418
1418
1419
1419
pkey_cache -> table_len = tprops -> pkey_tbl_len ;
1420
1420
@@ -1428,7 +1428,7 @@ static void ib_cache_update(struct ib_device *device,
1428
1428
}
1429
1429
}
1430
1430
1431
- write_lock_irq (& device -> cache . lock );
1431
+ write_lock_irq (& device -> cache_lock );
1432
1432
1433
1433
old_pkey_cache = device -> port_data [port ].cache .pkey ;
1434
1434
@@ -1437,7 +1437,7 @@ static void ib_cache_update(struct ib_device *device,
1437
1437
device -> port_data [port ].cache .port_state = tprops -> state ;
1438
1438
1439
1439
device -> port_data [port ].cache .subnet_prefix = tprops -> subnet_prefix ;
1440
- write_unlock_irq (& device -> cache . lock );
1440
+ write_unlock_irq (& device -> cache_lock );
1441
1441
1442
1442
if (enforce_security )
1443
1443
ib_security_cache_change (device ,
@@ -1446,57 +1446,91 @@ static void ib_cache_update(struct ib_device *device,
1446
1446
1447
1447
kfree (old_pkey_cache );
1448
1448
kfree (tprops );
1449
- return ;
1449
+ return 0 ;
1450
1450
1451
1451
err :
1452
1452
kfree (pkey_cache );
1453
1453
kfree (tprops );
1454
+ return ret ;
1455
+ }
1456
+
1457
+ static void ib_cache_event_task (struct work_struct * _work )
1458
+ {
1459
+ struct ib_update_work * work =
1460
+ container_of (_work , struct ib_update_work , work );
1461
+ int ret ;
1462
+
1463
+ /* Before distributing the cache update event, first sync
1464
+ * the cache.
1465
+ */
1466
+ ret = ib_cache_update (work -> event .device , work -> event .element .port_num ,
1467
+ work -> enforce_security );
1468
+
1469
+ /* GID event is notified already for individual GID entries by
1470
+ * dispatch_gid_change_event(). Hence, notifiy for rest of the
1471
+ * events.
1472
+ */
1473
+ if (!ret && work -> event .event != IB_EVENT_GID_CHANGE )
1474
+ ib_dispatch_event_clients (& work -> event );
1475
+
1476
+ kfree (work );
1454
1477
}
1455
1478
1456
- static void ib_cache_task (struct work_struct * _work )
1479
+ static void ib_generic_event_task (struct work_struct * _work )
1457
1480
{
1458
1481
struct ib_update_work * work =
1459
1482
container_of (_work , struct ib_update_work , work );
1460
1483
1461
- ib_cache_update (work -> device ,
1462
- work -> port_num ,
1463
- work -> enforce_security );
1484
+ ib_dispatch_event_clients (& work -> event );
1464
1485
kfree (work );
1465
1486
}
1466
1487
1467
- static void ib_cache_event (struct ib_event_handler * handler ,
1468
- struct ib_event * event )
1488
+ static bool is_cache_update_event (const struct ib_event * event )
1489
+ {
1490
+ return (event -> event == IB_EVENT_PORT_ERR ||
1491
+ event -> event == IB_EVENT_PORT_ACTIVE ||
1492
+ event -> event == IB_EVENT_LID_CHANGE ||
1493
+ event -> event == IB_EVENT_PKEY_CHANGE ||
1494
+ event -> event == IB_EVENT_CLIENT_REREGISTER ||
1495
+ event -> event == IB_EVENT_GID_CHANGE );
1496
+ }
1497
+
1498
+ /**
1499
+ * ib_dispatch_event - Dispatch an asynchronous event
1500
+ * @event:Event to dispatch
1501
+ *
1502
+ * Low-level drivers must call ib_dispatch_event() to dispatch the
1503
+ * event to all registered event handlers when an asynchronous event
1504
+ * occurs.
1505
+ */
1506
+ void ib_dispatch_event (const struct ib_event * event )
1469
1507
{
1470
1508
struct ib_update_work * work ;
1471
1509
1472
- if (event -> event == IB_EVENT_PORT_ERR ||
1473
- event -> event == IB_EVENT_PORT_ACTIVE ||
1474
- event -> event == IB_EVENT_LID_CHANGE ||
1475
- event -> event == IB_EVENT_PKEY_CHANGE ||
1476
- event -> event == IB_EVENT_CLIENT_REREGISTER ||
1477
- event -> event == IB_EVENT_GID_CHANGE ) {
1478
- work = kmalloc (sizeof * work , GFP_ATOMIC );
1479
- if (work ) {
1480
- INIT_WORK (& work -> work , ib_cache_task );
1481
- work -> device = event -> device ;
1482
- work -> port_num = event -> element .port_num ;
1483
- if (event -> event == IB_EVENT_PKEY_CHANGE ||
1484
- event -> event == IB_EVENT_GID_CHANGE )
1485
- work -> enforce_security = true;
1486
- else
1487
- work -> enforce_security = false;
1488
-
1489
- queue_work (ib_wq , & work -> work );
1490
- }
1491
- }
1510
+ work = kzalloc (sizeof (* work ), GFP_ATOMIC );
1511
+ if (!work )
1512
+ return ;
1513
+
1514
+ if (is_cache_update_event (event ))
1515
+ INIT_WORK (& work -> work , ib_cache_event_task );
1516
+ else
1517
+ INIT_WORK (& work -> work , ib_generic_event_task );
1518
+
1519
+ work -> event = * event ;
1520
+ if (event -> event == IB_EVENT_PKEY_CHANGE ||
1521
+ event -> event == IB_EVENT_GID_CHANGE )
1522
+ work -> enforce_security = true;
1523
+
1524
+ queue_work (ib_wq , & work -> work );
1492
1525
}
1526
+ EXPORT_SYMBOL (ib_dispatch_event );
1493
1527
1494
1528
int ib_cache_setup_one (struct ib_device * device )
1495
1529
{
1496
1530
unsigned int p ;
1497
1531
int err ;
1498
1532
1499
- rwlock_init (& device -> cache . lock );
1533
+ rwlock_init (& device -> cache_lock );
1500
1534
1501
1535
err = gid_table_setup_one (device );
1502
1536
if (err )
@@ -1505,9 +1539,6 @@ int ib_cache_setup_one(struct ib_device *device)
1505
1539
rdma_for_each_port (device , p )
1506
1540
ib_cache_update (device , p , true);
1507
1541
1508
- INIT_IB_EVENT_HANDLER (& device -> cache .event_handler ,
1509
- device , ib_cache_event );
1510
- ib_register_event_handler (& device -> cache .event_handler );
1511
1542
return 0 ;
1512
1543
}
1513
1544
@@ -1529,14 +1560,12 @@ void ib_cache_release_one(struct ib_device *device)
1529
1560
1530
1561
void ib_cache_cleanup_one (struct ib_device * device )
1531
1562
{
1532
- /* The cleanup function unregisters the event handler,
1533
- * waits for all in-progress workqueue elements and cleans
1534
- * up the GID cache. This function should be called after
1535
- * the device was removed from the devices list and all
1536
- * clients were removed, so the cache exists but is
1563
+ /* The cleanup function waits for all in-progress workqueue
1564
+ * elements and cleans up the GID cache. This function should be
1565
+ * called after the device was removed from the devices list and
1566
+ * all clients were removed, so the cache exists but is
1537
1567
* non-functional and shouldn't be updated anymore.
1538
1568
*/
1539
- ib_unregister_event_handler (& device -> cache .event_handler );
1540
1569
flush_workqueue (ib_wq );
1541
1570
gid_table_cleanup_one (device );
1542
1571
0 commit comments