| @@ -25,6 +25,7 @@ · 24 unmodified lines |
| 25 | 25 | #include "smc_core.h" |
| 26 | 26 | #include "smc_wr.h" |
| 27 | 27 | #include "smc.h" |
| 28 | +#include "smc_netlink.h" |
| 28 | 29 | |
| 29 | 30 | #define SMC_MAX_CQE 32766 /* max. # of completion queue elements */ |
| 30 | 31 | |
| @@ -326,6 +327,161 @@ int smc_ib_create_protection_domain(struct smc_link *lnk) · 295 unmodified lines |
| 326 | 327 | return rc; |
| 327 | 328 | } |
| 328 | 329 | |
| 330 | +static bool smcr_diag_is_dev_critical(struct smc_lgr_list *smc_lgr, |
| 331 | + struct smc_ib_device *smcibdev) |
| 332 | +{ |
| 333 | + struct smc_link_group *lgr; |
| 334 | + bool rc = false; |
| 335 | + int i; |
| 336 | + |
| 337 | + spin_lock_bh(&smc_lgr->lock); |
| 338 | + list_for_each_entry(lgr, &smc_lgr->list, list) { |
| 339 | + if (lgr->is_smcd) |
| 340 | + continue; |
| 341 | + for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { |
| 342 | + if (lgr->lnk[i].state == SMC_LNK_UNUSED || |
| 343 | + lgr->lnk[i].smcibdev != smcibdev) |
| 344 | + continue; |
| 345 | + if (lgr->type == SMC_LGR_SINGLE || |
| 346 | + lgr->type == SMC_LGR_ASYMMETRIC_LOCAL) { |
| 347 | + rc = true; |
| 348 | + goto out; |
| 349 | + } |
| 350 | + } |
| 351 | + } |
| 352 | +out: |
| 353 | + spin_unlock_bh(&smc_lgr->lock); |
| 354 | + return rc; |
| 355 | +} |
| 356 | + |
| 357 | +static int smc_nl_handle_dev_port(struct sk_buff *skb, |
| 358 | + struct ib_device *ibdev, |
| 359 | + struct smc_ib_device *smcibdev, |
| 360 | + int port) |
| 361 | +{ |
| 362 | + char smc_pnet[SMC_MAX_PNETID_LEN + 1]; |
| 363 | + struct nlattr *port_attrs; |
| 364 | + unsigned char port_state; |
| 365 | + int lnk_count = 0; |
| 366 | + |
| 367 | + port_attrs = nla_nest_start(skb, SMC_NLA_DEV_PORT + port); |
| 368 | + if (!port_attrs) |
| 369 | + goto errout; |
| 370 | + |
| 371 | + if (nla_put_u8(skb, SMC_NLA_DEV_PORT_PNET_USR, |
| 372 | + smcibdev->pnetid_by_user[port])) |
| 373 | + goto errattr; |
| 374 | + snprintf(smc_pnet, sizeof(smc_pnet), "%s", |
| 375 | + (char *)&smcibdev->pnetid[port]); |
| 376 | + if (nla_put_string(skb, SMC_NLA_DEV_PORT_PNETID, smc_pnet)) |
| 377 | + goto errattr; |
| 378 | + if (nla_put_u32(skb, SMC_NLA_DEV_PORT_NETDEV, |
| 379 | + smcibdev->ndev_ifidx[port])) |
| 380 | + goto errattr; |
| 381 | + if (nla_put_u8(skb, SMC_NLA_DEV_PORT_VALID, 1)) |
| 382 | + goto errattr; |
| 383 | + port_state = smc_ib_port_active(smcibdev, port + 1); |
| 384 | + if (nla_put_u8(skb, SMC_NLA_DEV_PORT_STATE, port_state)) |
| 385 | + goto errattr; |
| 386 | + lnk_count = atomic_read(&smcibdev->lnk_cnt_by_port[port]); |
| 387 | + if (nla_put_u32(skb, SMC_NLA_DEV_PORT_LNK_CNT, lnk_count)) |
| 388 | + goto errattr; |
| 389 | + nla_nest_end(skb, port_attrs); |
| 390 | + return 0; |
| 391 | +errattr: |
| 392 | + nla_nest_cancel(skb, port_attrs); |
| 393 | +errout: |
| 394 | + return -EMSGSIZE; |
| 395 | +} |
| 396 | + |
| 397 | +static int smc_nl_handle_smcr_dev(struct smc_ib_device *smcibdev, |
| 398 | + struct sk_buff *skb, |
| 399 | + struct netlink_callback *cb) |
| 400 | +{ |
| 401 | + char smc_ibname[IB_DEVICE_NAME_MAX + 1]; |
| 402 | + struct smc_pci_dev smc_pci_dev; |
| 403 | + struct pci_dev *pci_dev; |
| 404 | + unsigned char is_crit; |
| 405 | + struct nlattr *attrs; |
| 406 | + void *nlh; |
| 407 | + int i; |
| 408 | + |
| 409 | + nlh = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, |
| 410 | + &smc_gen_nl_family, NLM_F_MULTI, |
| 411 | + SMC_NETLINK_GET_DEV_SMCR); |
| 412 | + if (!nlh) |
| 413 | + goto errmsg; |
| 414 | + attrs = nla_nest_start(skb, SMC_GEN_DEV_SMCR); |
| 415 | + if (!attrs) |
| 416 | + goto errout; |
| 417 | + is_crit = smcr_diag_is_dev_critical(&smc_lgr_list, smcibdev); |
| 418 | + if (nla_put_u8(skb, SMC_NLA_DEV_IS_CRIT, is_crit)) |
| 419 | + goto errattr; |
| 420 | + memset(&smc_pci_dev, 0, sizeof(smc_pci_dev)); |
| 421 | + pci_dev = to_pci_dev(smcibdev->ibdev->dev.parent); |
| 422 | + smc_set_pci_values(pci_dev, &smc_pci_dev); |
| 423 | + if (nla_put_u32(skb, SMC_NLA_DEV_PCI_FID, smc_pci_dev.pci_fid)) |
| 424 | + goto errattr; |
| 425 | + if (nla_put_u16(skb, SMC_NLA_DEV_PCI_CHID, smc_pci_dev.pci_pchid)) |
| 426 | + goto errattr; |
| 427 | + if (nla_put_u16(skb, SMC_NLA_DEV_PCI_VENDOR, smc_pci_dev.pci_vendor)) |
| 428 | + goto errattr; |
| 429 | + if (nla_put_u16(skb, SMC_NLA_DEV_PCI_DEVICE, smc_pci_dev.pci_device)) |
| 430 | + goto errattr; |
| 431 | + if (nla_put_string(skb, SMC_NLA_DEV_PCI_ID, smc_pci_dev.pci_id)) |
| 432 | + goto errattr; |
| 433 | + snprintf(smc_ibname, sizeof(smc_ibname), "%s", smcibdev->ibdev->name); |
| 434 | + if (nla_put_string(skb, SMC_NLA_DEV_IB_NAME, smc_ibname)) |
| 435 | + goto errattr; |
| 436 | + for (i = 1; i <= SMC_MAX_PORTS; i++) { |
| 437 | + if (!rdma_is_port_valid(smcibdev->ibdev, i)) |
| 438 | + continue; |
| 439 | + if (smc_nl_handle_dev_port(skb, smcibdev->ibdev, |
| 440 | + smcibdev, i - 1)) |
| 441 | + goto errattr; |
| 442 | + } |
| 443 | + |
| 444 | + nla_nest_end(skb, attrs); |
| 445 | + genlmsg_end(skb, nlh); |
| 446 | + return 0; |
| 447 | + |
| 448 | +errattr: |
| 449 | + nla_nest_cancel(skb, attrs); |
| 450 | +errout: |
| 451 | + genlmsg_cancel(skb, nlh); |
| 452 | +errmsg: |
| 453 | + return -EMSGSIZE; |
| 454 | +} |
| 455 | + |
| 456 | +static void smc_nl_prep_smcr_dev(struct smc_ib_devices *dev_list, |
| 457 | + struct sk_buff *skb, |
| 458 | + struct netlink_callback *cb) |
| 459 | +{ |
| 460 | + struct smc_nl_dmp_ctx *cb_ctx = smc_nl_dmp_ctx(cb); |
| 461 | + struct smc_ib_device *smcibdev; |
| 462 | + int snum = cb_ctx->pos[0]; |
| 463 | + int num = 0; |
| 464 | + |
| 465 | + mutex_lock(&dev_list->mutex); |
| 466 | + list_for_each_entry(smcibdev, &dev_list->list, list) { |
| 467 | + if (num < snum) |
| 468 | + goto next; |
| 469 | + if (smc_nl_handle_smcr_dev(smcibdev, skb, cb)) |
| 470 | + goto errout; |
| 471 | +next: |
| 472 | + num++; |
| 473 | + } |
| 474 | +errout: |
| 475 | + mutex_unlock(&dev_list->mutex); |
| 476 | + cb_ctx->pos[0] = num; |
| 477 | +} |
| 478 | + |
| 479 | +int smcr_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb) |
| 480 | +{ |
| 481 | + smc_nl_prep_smcr_dev(&smc_ib_devices, skb, cb); |
| 482 | + return skb->len; |
| 483 | +} |
| 484 | + |
| 329 | 485 | static void smc_ib_qp_event_handler(struct ib_event *ibevent, void *priv) |
| 330 | 486 | { |
| 331 | 487 | struct smc_link *lnk = (struct smc_link *)priv; |