aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband
diff options
context:
space:
mode:
authorMoni Shoua <monis@mellanox.com>2013-12-12 11:03:13 -0500
committerRoland Dreier <roland@purestorage.com>2014-01-18 17:12:52 -0500
commitd487ee77740ccf79d7dc1935d4daa77887283028 (patch)
tree375490229b2140526ac3c8793e9433591e19bd79 /drivers/infiniband
parent7b85627b9f02f9b0fb2ef5f021807f4251135857 (diff)
IB/mlx4: Use IBoE (RoCE) IP based GIDs in the port GID table
Currently, the mlx4 driver set IBoE (RoCE) gids to encode related Ethernet netdevice interface MAC address and possibly VLAN id. Change this scheme such that gids encode interface IP addresses (both IP4 and IPv6). This requires learning the IP addresses which are of use by a netdevice associated with the HCA port, formatting them to gids and adding them to the port gid table. Furthermore, events of add and delete address are caught to maintain the gid table accordingly. Associated IP addresses may belong to a master of an Ethernet netdevice on top of that port so this should be considered when building and maintaining the gid table. Signed-off-by: Moni Shoua <monis@mellanox.com> Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: Roland Dreier <roland@purestorage.com>
Diffstat (limited to 'drivers/infiniband')
-rw-r--r--drivers/infiniband/hw/mlx4/main.c474
-rw-r--r--drivers/infiniband/hw/mlx4/mlx4_ib.h3
2 files changed, 334 insertions, 143 deletions
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index 1958c5ca792a..a776aabab44a 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -39,6 +39,8 @@
39#include <linux/inetdevice.h> 39#include <linux/inetdevice.h>
40#include <linux/rtnetlink.h> 40#include <linux/rtnetlink.h>
41#include <linux/if_vlan.h> 41#include <linux/if_vlan.h>
42#include <net/ipv6.h>
43#include <net/addrconf.h>
42 44
43#include <rdma/ib_smi.h> 45#include <rdma/ib_smi.h>
44#include <rdma/ib_user_verbs.h> 46#include <rdma/ib_user_verbs.h>
@@ -787,7 +789,6 @@ static int add_gid_entry(struct ib_qp *ibqp, union ib_gid *gid)
787int mlx4_ib_add_mc(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp, 789int mlx4_ib_add_mc(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp,
788 union ib_gid *gid) 790 union ib_gid *gid)
789{ 791{
790 u8 mac[6];
791 struct net_device *ndev; 792 struct net_device *ndev;
792 int ret = 0; 793 int ret = 0;
793 794
@@ -801,11 +802,7 @@ int mlx4_ib_add_mc(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp,
801 spin_unlock(&mdev->iboe.lock); 802 spin_unlock(&mdev->iboe.lock);
802 803
803 if (ndev) { 804 if (ndev) {
804 rdma_get_mcast_mac((struct in6_addr *)gid, mac);
805 rtnl_lock();
806 dev_mc_add(mdev->iboe.netdevs[mqp->port - 1], mac);
807 ret = 1; 805 ret = 1;
808 rtnl_unlock();
809 dev_put(ndev); 806 dev_put(ndev);
810 } 807 }
811 808
@@ -1025,6 +1022,8 @@ static int mlx4_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
1025 struct mlx4_ib_qp *mqp = to_mqp(ibqp); 1022 struct mlx4_ib_qp *mqp = to_mqp(ibqp);
1026 u64 reg_id; 1023 u64 reg_id;
1027 struct mlx4_ib_steering *ib_steering = NULL; 1024 struct mlx4_ib_steering *ib_steering = NULL;
1025 enum mlx4_protocol prot = (gid->raw[1] == 0x0e) ?
1026 MLX4_PROT_IB_IPV4 : MLX4_PROT_IB_IPV6;
1028 1027
1029 if (mdev->dev->caps.steering_mode == 1028 if (mdev->dev->caps.steering_mode ==
1030 MLX4_STEERING_MODE_DEVICE_MANAGED) { 1029 MLX4_STEERING_MODE_DEVICE_MANAGED) {
@@ -1036,7 +1035,7 @@ static int mlx4_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
1036 err = mlx4_multicast_attach(mdev->dev, &mqp->mqp, gid->raw, mqp->port, 1035 err = mlx4_multicast_attach(mdev->dev, &mqp->mqp, gid->raw, mqp->port,
1037 !!(mqp->flags & 1036 !!(mqp->flags &
1038 MLX4_IB_QP_BLOCK_MULTICAST_LOOPBACK), 1037 MLX4_IB_QP_BLOCK_MULTICAST_LOOPBACK),
1039 MLX4_PROT_IB_IPV6, &reg_id); 1038 prot, &reg_id);
1040 if (err) 1039 if (err)
1041 goto err_malloc; 1040 goto err_malloc;
1042 1041
@@ -1055,7 +1054,7 @@ static int mlx4_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
1055 1054
1056err_add: 1055err_add:
1057 mlx4_multicast_detach(mdev->dev, &mqp->mqp, gid->raw, 1056 mlx4_multicast_detach(mdev->dev, &mqp->mqp, gid->raw,
1058 MLX4_PROT_IB_IPV6, reg_id); 1057 prot, reg_id);
1059err_malloc: 1058err_malloc:
1060 kfree(ib_steering); 1059 kfree(ib_steering);
1061 1060
@@ -1083,10 +1082,11 @@ static int mlx4_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
1083 int err; 1082 int err;
1084 struct mlx4_ib_dev *mdev = to_mdev(ibqp->device); 1083 struct mlx4_ib_dev *mdev = to_mdev(ibqp->device);
1085 struct mlx4_ib_qp *mqp = to_mqp(ibqp); 1084 struct mlx4_ib_qp *mqp = to_mqp(ibqp);
1086 u8 mac[6];
1087 struct net_device *ndev; 1085 struct net_device *ndev;
1088 struct mlx4_ib_gid_entry *ge; 1086 struct mlx4_ib_gid_entry *ge;
1089 u64 reg_id = 0; 1087 u64 reg_id = 0;
1088 enum mlx4_protocol prot = (gid->raw[1] == 0x0e) ?
1089 MLX4_PROT_IB_IPV4 : MLX4_PROT_IB_IPV6;
1090 1090
1091 if (mdev->dev->caps.steering_mode == 1091 if (mdev->dev->caps.steering_mode ==
1092 MLX4_STEERING_MODE_DEVICE_MANAGED) { 1092 MLX4_STEERING_MODE_DEVICE_MANAGED) {
@@ -1109,7 +1109,7 @@ static int mlx4_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
1109 } 1109 }
1110 1110
1111 err = mlx4_multicast_detach(mdev->dev, &mqp->mqp, gid->raw, 1111 err = mlx4_multicast_detach(mdev->dev, &mqp->mqp, gid->raw,
1112 MLX4_PROT_IB_IPV6, reg_id); 1112 prot, reg_id);
1113 if (err) 1113 if (err)
1114 return err; 1114 return err;
1115 1115
@@ -1121,13 +1121,8 @@ static int mlx4_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
1121 if (ndev) 1121 if (ndev)
1122 dev_hold(ndev); 1122 dev_hold(ndev);
1123 spin_unlock(&mdev->iboe.lock); 1123 spin_unlock(&mdev->iboe.lock);
1124 rdma_get_mcast_mac((struct in6_addr *)gid, mac); 1124 if (ndev)
1125 if (ndev) {
1126 rtnl_lock();
1127 dev_mc_del(mdev->iboe.netdevs[ge->port - 1], mac);
1128 rtnl_unlock();
1129 dev_put(ndev); 1125 dev_put(ndev);
1130 }
1131 list_del(&ge->list); 1126 list_del(&ge->list);
1132 kfree(ge); 1127 kfree(ge);
1133 } else 1128 } else
@@ -1223,20 +1218,6 @@ static struct device_attribute *mlx4_class_attributes[] = {
1223 &dev_attr_board_id 1218 &dev_attr_board_id
1224}; 1219};
1225 1220
1226static void mlx4_addrconf_ifid_eui48(u8 *eui, u16 vlan_id, struct net_device *dev)
1227{
1228 memcpy(eui, dev->dev_addr, 3);
1229 memcpy(eui + 5, dev->dev_addr + 3, 3);
1230 if (vlan_id < 0x1000) {
1231 eui[3] = vlan_id >> 8;
1232 eui[4] = vlan_id & 0xff;
1233 } else {
1234 eui[3] = 0xff;
1235 eui[4] = 0xfe;
1236 }
1237 eui[0] ^= 2;
1238}
1239
1240static void update_gids_task(struct work_struct *work) 1221static void update_gids_task(struct work_struct *work)
1241{ 1222{
1242 struct update_gid_work *gw = container_of(work, struct update_gid_work, work); 1223 struct update_gid_work *gw = container_of(work, struct update_gid_work, work);
@@ -1259,161 +1240,318 @@ static void update_gids_task(struct work_struct *work)
1259 MLX4_CMD_WRAPPED); 1240 MLX4_CMD_WRAPPED);
1260 if (err) 1241 if (err)
1261 pr_warn("set port command failed\n"); 1242 pr_warn("set port command failed\n");
1262 else { 1243 else
1263 memcpy(gw->dev->iboe.gid_table[gw->port - 1], gw->gids, sizeof gw->gids);
1264 mlx4_ib_dispatch_event(gw->dev, gw->port, IB_EVENT_GID_CHANGE); 1244 mlx4_ib_dispatch_event(gw->dev, gw->port, IB_EVENT_GID_CHANGE);
1265 }
1266 1245
1267 mlx4_free_cmd_mailbox(dev, mailbox); 1246 mlx4_free_cmd_mailbox(dev, mailbox);
1268 kfree(gw); 1247 kfree(gw);
1269} 1248}
1270 1249
1271static int update_ipv6_gids(struct mlx4_ib_dev *dev, int port, int clear) 1250static void reset_gids_task(struct work_struct *work)
1272{ 1251{
1273 struct net_device *ndev = dev->iboe.netdevs[port - 1]; 1252 struct update_gid_work *gw =
1274 struct update_gid_work *work; 1253 container_of(work, struct update_gid_work, work);
1275 struct net_device *tmp; 1254 struct mlx4_cmd_mailbox *mailbox;
1255 union ib_gid *gids;
1256 int err;
1276 int i; 1257 int i;
1277 u8 *hits; 1258 struct mlx4_dev *dev = gw->dev->dev;
1278 int ret;
1279 union ib_gid gid;
1280 int free;
1281 int found;
1282 int need_update = 0;
1283 u16 vid;
1284 1259
1285 work = kzalloc(sizeof *work, GFP_ATOMIC); 1260 mailbox = mlx4_alloc_cmd_mailbox(dev);
1286 if (!work) 1261 if (IS_ERR(mailbox)) {
1287 return -ENOMEM; 1262 pr_warn("reset gid table failed\n");
1263 goto free;
1264 }
1288 1265
1289 hits = kzalloc(128, GFP_ATOMIC); 1266 gids = mailbox->buf;
1290 if (!hits) { 1267 memcpy(gids, gw->gids, sizeof(gw->gids));
1291 ret = -ENOMEM; 1268
1292 goto out; 1269 for (i = 1; i < gw->dev->num_ports + 1; i++) {
1270 if (mlx4_ib_port_link_layer(&gw->dev->ib_dev, i) ==
1271 IB_LINK_LAYER_ETHERNET) {
1272 err = mlx4_cmd(dev, mailbox->dma,
1273 MLX4_SET_PORT_GID_TABLE << 8 | i,
1274 1, MLX4_CMD_SET_PORT,
1275 MLX4_CMD_TIME_CLASS_B,
1276 MLX4_CMD_WRAPPED);
1277 if (err)
1278 pr_warn(KERN_WARNING
1279 "set port %d command failed\n", i);
1280 }
1293 } 1281 }
1294 1282
1295 rcu_read_lock(); 1283 mlx4_free_cmd_mailbox(dev, mailbox);
1296 for_each_netdev_rcu(&init_net, tmp) { 1284free:
1297 if (ndev && (tmp == ndev || rdma_vlan_dev_real_dev(tmp) == ndev)) { 1285 kfree(gw);
1298 gid.global.subnet_prefix = cpu_to_be64(0xfe80000000000000LL); 1286}
1299 vid = rdma_vlan_dev_vlan_id(tmp);
1300 mlx4_addrconf_ifid_eui48(&gid.raw[8], vid, ndev);
1301 found = 0;
1302 free = -1;
1303 for (i = 0; i < 128; ++i) {
1304 if (free < 0 &&
1305 !memcmp(&dev->iboe.gid_table[port - 1][i], &zgid, sizeof zgid))
1306 free = i;
1307 if (!memcmp(&dev->iboe.gid_table[port - 1][i], &gid, sizeof gid)) {
1308 hits[i] = 1;
1309 found = 1;
1310 break;
1311 }
1312 }
1313 1287
1314 if (!found) { 1288static int update_gid_table(struct mlx4_ib_dev *dev, int port,
1315 if (tmp == ndev && 1289 union ib_gid *gid, int clear)
1316 (memcmp(&dev->iboe.gid_table[port - 1][0], 1290{
1317 &gid, sizeof gid) || 1291 struct update_gid_work *work;
1318 !memcmp(&dev->iboe.gid_table[port - 1][0], 1292 int i;
1319 &zgid, sizeof gid))) { 1293 int need_update = 0;
1320 dev->iboe.gid_table[port - 1][0] = gid; 1294 int free = -1;
1321 ++need_update; 1295 int found = -1;
1322 hits[0] = 1; 1296 int max_gids;
1323 } else if (free >= 0) { 1297
1324 dev->iboe.gid_table[port - 1][free] = gid; 1298 max_gids = dev->dev->caps.gid_table_len[port];
1325 hits[free] = 1; 1299 for (i = 0; i < max_gids; ++i) {
1326 ++need_update; 1300 if (!memcmp(&dev->iboe.gid_table[port - 1][i], gid,
1327 } 1301 sizeof(*gid)))
1302 found = i;
1303
1304 if (clear) {
1305 if (found >= 0) {
1306 need_update = 1;
1307 dev->iboe.gid_table[port - 1][found] = zgid;
1308 break;
1328 } 1309 }
1310 } else {
1311 if (found >= 0)
1312 break;
1313
1314 if (free < 0 &&
1315 !memcmp(&dev->iboe.gid_table[port - 1][i], &zgid,
1316 sizeof(*gid)))
1317 free = i;
1329 } 1318 }
1330 } 1319 }
1331 rcu_read_unlock();
1332 1320
1333 for (i = 0; i < 128; ++i) 1321 if (found == -1 && !clear && free >= 0) {
1334 if (!hits[i]) { 1322 dev->iboe.gid_table[port - 1][free] = *gid;
1335 if (memcmp(&dev->iboe.gid_table[port - 1][i], &zgid, sizeof zgid)) 1323 need_update = 1;
1336 ++need_update; 1324 }
1337 dev->iboe.gid_table[port - 1][i] = zgid;
1338 }
1339 1325
1340 if (need_update) { 1326 if (!need_update)
1341 memcpy(work->gids, dev->iboe.gid_table[port - 1], sizeof work->gids); 1327 return 0;
1342 INIT_WORK(&work->work, update_gids_task); 1328
1343 work->port = port; 1329 work = kzalloc(sizeof(*work), GFP_ATOMIC);
1344 work->dev = dev; 1330 if (!work)
1345 queue_work(wq, &work->work); 1331 return -ENOMEM;
1346 } else 1332
1347 kfree(work); 1333 memcpy(work->gids, dev->iboe.gid_table[port - 1], sizeof(work->gids));
1334 INIT_WORK(&work->work, update_gids_task);
1335 work->port = port;
1336 work->dev = dev;
1337 queue_work(wq, &work->work);
1348 1338
1349 kfree(hits);
1350 return 0; 1339 return 0;
1340}
1351 1341
1352out: 1342static int reset_gid_table(struct mlx4_ib_dev *dev)
1353 kfree(work); 1343{
1354 return ret; 1344 struct update_gid_work *work;
1345
1346
1347 work = kzalloc(sizeof(*work), GFP_ATOMIC);
1348 if (!work)
1349 return -ENOMEM;
1350 memset(dev->iboe.gid_table, 0, sizeof(dev->iboe.gid_table));
1351 memset(work->gids, 0, sizeof(work->gids));
1352 INIT_WORK(&work->work, reset_gids_task);
1353 work->dev = dev;
1354 queue_work(wq, &work->work);
1355 return 0;
1355} 1356}
1356 1357
1357static void handle_en_event(struct mlx4_ib_dev *dev, int port, unsigned long event) 1358static int mlx4_ib_addr_event(int event, struct net_device *event_netdev,
1359 struct mlx4_ib_dev *ibdev, union ib_gid *gid)
1358{ 1360{
1359 switch (event) { 1361 struct mlx4_ib_iboe *iboe;
1360 case NETDEV_UP: 1362 int port = 0;
1361 case NETDEV_CHANGEADDR: 1363 struct net_device *real_dev = rdma_vlan_dev_real_dev(event_netdev) ?
1362 update_ipv6_gids(dev, port, 0); 1364 rdma_vlan_dev_real_dev(event_netdev) :
1363 break; 1365 event_netdev;
1366
1367 if (event != NETDEV_DOWN && event != NETDEV_UP)
1368 return 0;
1369
1370 if ((real_dev != event_netdev) &&
1371 (event == NETDEV_DOWN) &&
1372 rdma_link_local_addr((struct in6_addr *)gid))
1373 return 0;
1374
1375 iboe = &ibdev->iboe;
1376 spin_lock(&iboe->lock);
1377
1378 for (port = 1; port <= MLX4_MAX_PORTS; ++port)
1379 if ((netif_is_bond_master(real_dev) &&
1380 (real_dev == iboe->masters[port - 1])) ||
1381 (!netif_is_bond_master(real_dev) &&
1382 (real_dev == iboe->netdevs[port - 1])))
1383 update_gid_table(ibdev, port, gid,
1384 event == NETDEV_DOWN);
1385
1386 spin_unlock(&iboe->lock);
1387 return 0;
1364 1388
1365 case NETDEV_DOWN:
1366 update_ipv6_gids(dev, port, 1);
1367 dev->iboe.netdevs[port - 1] = NULL;
1368 }
1369} 1389}
1370 1390
1371static void netdev_added(struct mlx4_ib_dev *dev, int port) 1391static u8 mlx4_ib_get_dev_port(struct net_device *dev,
1392 struct mlx4_ib_dev *ibdev)
1372{ 1393{
1373 update_ipv6_gids(dev, port, 0); 1394 u8 port = 0;
1395 struct mlx4_ib_iboe *iboe;
1396 struct net_device *real_dev = rdma_vlan_dev_real_dev(dev) ?
1397 rdma_vlan_dev_real_dev(dev) : dev;
1398
1399 iboe = &ibdev->iboe;
1400 spin_lock(&iboe->lock);
1401
1402 for (port = 1; port <= MLX4_MAX_PORTS; ++port)
1403 if ((netif_is_bond_master(real_dev) &&
1404 (real_dev == iboe->masters[port - 1])) ||
1405 (!netif_is_bond_master(real_dev) &&
1406 (real_dev == iboe->netdevs[port - 1])))
1407 break;
1408
1409 spin_unlock(&iboe->lock);
1410
1411 if ((port == 0) || (port > MLX4_MAX_PORTS))
1412 return 0;
1413 else
1414 return port;
1374} 1415}
1375 1416
1376static void netdev_removed(struct mlx4_ib_dev *dev, int port) 1417static int mlx4_ib_inet_event(struct notifier_block *this, unsigned long event,
1418 void *ptr)
1377{ 1419{
1378 update_ipv6_gids(dev, port, 1); 1420 struct mlx4_ib_dev *ibdev;
1421 struct in_ifaddr *ifa = ptr;
1422 union ib_gid gid;
1423 struct net_device *event_netdev = ifa->ifa_dev->dev;
1424
1425 ipv6_addr_set_v4mapped(ifa->ifa_address, (struct in6_addr *)&gid);
1426
1427 ibdev = container_of(this, struct mlx4_ib_dev, iboe.nb_inet);
1428
1429 mlx4_ib_addr_event(event, event_netdev, ibdev, &gid);
1430 return NOTIFY_DONE;
1379} 1431}
1380 1432
1381static int mlx4_ib_netdev_event(struct notifier_block *this, unsigned long event, 1433#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1434static int mlx4_ib_inet6_event(struct notifier_block *this, unsigned long event,
1382 void *ptr) 1435 void *ptr)
1383{ 1436{
1384 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
1385 struct mlx4_ib_dev *ibdev; 1437 struct mlx4_ib_dev *ibdev;
1386 struct net_device *oldnd; 1438 struct inet6_ifaddr *ifa = ptr;
1439 union ib_gid *gid = (union ib_gid *)&ifa->addr;
1440 struct net_device *event_netdev = ifa->idev->dev;
1441
1442 ibdev = container_of(this, struct mlx4_ib_dev, iboe.nb_inet6);
1443
1444 mlx4_ib_addr_event(event, event_netdev, ibdev, gid);
1445 return NOTIFY_DONE;
1446}
1447#endif
1448
1449static void mlx4_ib_get_dev_addr(struct net_device *dev,
1450 struct mlx4_ib_dev *ibdev, u8 port)
1451{
1452 struct in_device *in_dev;
1453#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1454 struct inet6_dev *in6_dev;
1455 union ib_gid *pgid;
1456 struct inet6_ifaddr *ifp;
1457#endif
1458 union ib_gid gid;
1459
1460
1461 if ((port == 0) || (port > MLX4_MAX_PORTS))
1462 return;
1463
1464 /* IPv4 gids */
1465 in_dev = in_dev_get(dev);
1466 if (in_dev) {
1467 for_ifa(in_dev) {
1468 /*ifa->ifa_address;*/
1469 ipv6_addr_set_v4mapped(ifa->ifa_address,
1470 (struct in6_addr *)&gid);
1471 update_gid_table(ibdev, port, &gid, 0);
1472 }
1473 endfor_ifa(in_dev);
1474 in_dev_put(in_dev);
1475 }
1476#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1477 /* IPv6 gids */
1478 in6_dev = in6_dev_get(dev);
1479 if (in6_dev) {
1480 read_lock_bh(&in6_dev->lock);
1481 list_for_each_entry(ifp, &in6_dev->addr_list, if_list) {
1482 pgid = (union ib_gid *)&ifp->addr;
1483 update_gid_table(ibdev, port, pgid, 0);
1484 }
1485 read_unlock_bh(&in6_dev->lock);
1486 in6_dev_put(in6_dev);
1487 }
1488#endif
1489}
1490
1491static int mlx4_ib_init_gid_table(struct mlx4_ib_dev *ibdev)
1492{
1493 struct net_device *dev;
1494
1495 if (reset_gid_table(ibdev))
1496 return -1;
1497
1498 read_lock(&dev_base_lock);
1499
1500 for_each_netdev(&init_net, dev) {
1501 u8 port = mlx4_ib_get_dev_port(dev, ibdev);
1502 if (port)
1503 mlx4_ib_get_dev_addr(dev, ibdev, port);
1504 }
1505
1506 read_unlock(&dev_base_lock);
1507
1508 return 0;
1509}
1510
1511static void mlx4_ib_scan_netdevs(struct mlx4_ib_dev *ibdev)
1512{
1387 struct mlx4_ib_iboe *iboe; 1513 struct mlx4_ib_iboe *iboe;
1388 int port; 1514 int port;
1389 1515
1390 if (!net_eq(dev_net(dev), &init_net))
1391 return NOTIFY_DONE;
1392
1393 ibdev = container_of(this, struct mlx4_ib_dev, iboe.nb);
1394 iboe = &ibdev->iboe; 1516 iboe = &ibdev->iboe;
1395 1517
1396 spin_lock(&iboe->lock); 1518 spin_lock(&iboe->lock);
1397 mlx4_foreach_ib_transport_port(port, ibdev->dev) { 1519 mlx4_foreach_ib_transport_port(port, ibdev->dev) {
1398 oldnd = iboe->netdevs[port - 1]; 1520 struct net_device *old_master = iboe->masters[port - 1];
1521 struct net_device *curr_master;
1399 iboe->netdevs[port - 1] = 1522 iboe->netdevs[port - 1] =
1400 mlx4_get_protocol_dev(ibdev->dev, MLX4_PROT_ETH, port); 1523 mlx4_get_protocol_dev(ibdev->dev, MLX4_PROT_ETH, port);
1401 if (oldnd != iboe->netdevs[port - 1]) { 1524
1402 if (iboe->netdevs[port - 1]) 1525 if (iboe->netdevs[port - 1] &&
1403 netdev_added(ibdev, port); 1526 netif_is_bond_slave(iboe->netdevs[port - 1])) {
1404 else 1527 rtnl_lock();
1405 netdev_removed(ibdev, port); 1528 iboe->masters[port - 1] = netdev_master_upper_dev_get(
1529 iboe->netdevs[port - 1]);
1530 rtnl_unlock();
1406 } 1531 }
1407 } 1532 curr_master = iboe->masters[port - 1];
1408 1533
1409 if (dev == iboe->netdevs[0] || 1534 /* if bonding is used it is possible that we add it to masters
1410 (iboe->netdevs[0] && rdma_vlan_dev_real_dev(dev) == iboe->netdevs[0])) 1535 only after IP address is assigned to the net bonding
1411 handle_en_event(ibdev, 1, event); 1536 interface */
1412 else if (dev == iboe->netdevs[1] 1537 if (curr_master && (old_master != curr_master))
1413 || (iboe->netdevs[1] && rdma_vlan_dev_real_dev(dev) == iboe->netdevs[1])) 1538 mlx4_ib_get_dev_addr(curr_master, ibdev, port);
1414 handle_en_event(ibdev, 2, event); 1539 }
1415 1540
1416 spin_unlock(&iboe->lock); 1541 spin_unlock(&iboe->lock);
1542}
1543
1544static int mlx4_ib_netdev_event(struct notifier_block *this,
1545 unsigned long event, void *ptr)
1546{
1547 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
1548 struct mlx4_ib_dev *ibdev;
1549
1550 if (!net_eq(dev_net(dev), &init_net))
1551 return NOTIFY_DONE;
1552
1553 ibdev = container_of(this, struct mlx4_ib_dev, iboe.nb);
1554 mlx4_ib_scan_netdevs(ibdev);
1417 1555
1418 return NOTIFY_DONE; 1556 return NOTIFY_DONE;
1419} 1557}
@@ -1719,11 +1857,35 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
1719 if (mlx4_ib_init_sriov(ibdev)) 1857 if (mlx4_ib_init_sriov(ibdev))
1720 goto err_mad; 1858 goto err_mad;
1721 1859
1722 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_IBOE && !iboe->nb.notifier_call) { 1860 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_IBOE) {
1723 iboe->nb.notifier_call = mlx4_ib_netdev_event; 1861 if (!iboe->nb.notifier_call) {
1724 err = register_netdevice_notifier(&iboe->nb); 1862 iboe->nb.notifier_call = mlx4_ib_netdev_event;
1725 if (err) 1863 err = register_netdevice_notifier(&iboe->nb);
1726 goto err_sriov; 1864 if (err) {
1865 iboe->nb.notifier_call = NULL;
1866 goto err_notif;
1867 }
1868 }
1869 if (!iboe->nb_inet.notifier_call) {
1870 iboe->nb_inet.notifier_call = mlx4_ib_inet_event;
1871 err = register_inetaddr_notifier(&iboe->nb_inet);
1872 if (err) {
1873 iboe->nb_inet.notifier_call = NULL;
1874 goto err_notif;
1875 }
1876 }
1877#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1878 if (!iboe->nb_inet6.notifier_call) {
1879 iboe->nb_inet6.notifier_call = mlx4_ib_inet6_event;
1880 err = register_inet6addr_notifier(&iboe->nb_inet6);
1881 if (err) {
1882 iboe->nb_inet6.notifier_call = NULL;
1883 goto err_notif;
1884 }
1885 }
1886#endif
1887 mlx4_ib_scan_netdevs(ibdev);
1888 mlx4_ib_init_gid_table(ibdev);
1727 } 1889 }
1728 1890
1729 for (j = 0; j < ARRAY_SIZE(mlx4_class_attributes); ++j) { 1891 for (j = 0; j < ARRAY_SIZE(mlx4_class_attributes); ++j) {
@@ -1749,11 +1911,25 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
1749 return ibdev; 1911 return ibdev;
1750 1912
1751err_notif: 1913err_notif:
1752 if (unregister_netdevice_notifier(&ibdev->iboe.nb)) 1914 if (ibdev->iboe.nb.notifier_call) {
1753 pr_warn("failure unregistering notifier\n"); 1915 if (unregister_netdevice_notifier(&ibdev->iboe.nb))
1916 pr_warn("failure unregistering notifier\n");
1917 ibdev->iboe.nb.notifier_call = NULL;
1918 }
1919 if (ibdev->iboe.nb_inet.notifier_call) {
1920 if (unregister_inetaddr_notifier(&ibdev->iboe.nb_inet))
1921 pr_warn("failure unregistering notifier\n");
1922 ibdev->iboe.nb_inet.notifier_call = NULL;
1923 }
1924#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1925 if (ibdev->iboe.nb_inet6.notifier_call) {
1926 if (unregister_inet6addr_notifier(&ibdev->iboe.nb_inet6))
1927 pr_warn("failure unregistering notifier\n");
1928 ibdev->iboe.nb_inet6.notifier_call = NULL;
1929 }
1930#endif
1754 flush_workqueue(wq); 1931 flush_workqueue(wq);
1755 1932
1756err_sriov:
1757 mlx4_ib_close_sriov(ibdev); 1933 mlx4_ib_close_sriov(ibdev);
1758 1934
1759err_mad: 1935err_mad:
@@ -1795,6 +1971,18 @@ static void mlx4_ib_remove(struct mlx4_dev *dev, void *ibdev_ptr)
1795 pr_warn("failure unregistering notifier\n"); 1971 pr_warn("failure unregistering notifier\n");
1796 ibdev->iboe.nb.notifier_call = NULL; 1972 ibdev->iboe.nb.notifier_call = NULL;
1797 } 1973 }
1974 if (ibdev->iboe.nb_inet.notifier_call) {
1975 if (unregister_inetaddr_notifier(&ibdev->iboe.nb_inet))
1976 pr_warn("failure unregistering notifier\n");
1977 ibdev->iboe.nb_inet.notifier_call = NULL;
1978 }
1979#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1980 if (ibdev->iboe.nb_inet6.notifier_call) {
1981 if (unregister_inet6addr_notifier(&ibdev->iboe.nb_inet6))
1982 pr_warn("failure unregistering notifier\n");
1983 ibdev->iboe.nb_inet6.notifier_call = NULL;
1984 }
1985#endif
1798 iounmap(ibdev->uar_map); 1986 iounmap(ibdev->uar_map);
1799 for (p = 0; p < ibdev->num_ports; ++p) 1987 for (p = 0; p < ibdev->num_ports; ++p)
1800 if (ibdev->counters[p] != -1) 1988 if (ibdev->counters[p] != -1)
diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
index 036b663dd26e..133f41f42194 100644
--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
@@ -428,7 +428,10 @@ struct mlx4_ib_sriov {
428struct mlx4_ib_iboe { 428struct mlx4_ib_iboe {
429 spinlock_t lock; 429 spinlock_t lock;
430 struct net_device *netdevs[MLX4_MAX_PORTS]; 430 struct net_device *netdevs[MLX4_MAX_PORTS];
431 struct net_device *masters[MLX4_MAX_PORTS];
431 struct notifier_block nb; 432 struct notifier_block nb;
433 struct notifier_block nb_inet;
434 struct notifier_block nb_inet6;
432 union ib_gid gid_table[MLX4_MAX_PORTS][128]; 435 union ib_gid gid_table[MLX4_MAX_PORTS][128];
433}; 436};
434 437