| .. | .. |
|---|
| 55 | 55 | |
|---|
| 56 | 56 | #include <rdma/ib_mad.h> |
|---|
| 57 | 57 | #include <rdma/ib_user_mad.h> |
|---|
| 58 | +#include <rdma/rdma_netlink.h> |
|---|
| 58 | 59 | |
|---|
| 59 | 60 | #include "core_priv.h" |
|---|
| 60 | 61 | |
|---|
| .. | .. |
|---|
| 89 | 90 | |
|---|
| 90 | 91 | struct ib_umad_port { |
|---|
| 91 | 92 | struct cdev cdev; |
|---|
| 92 | | - struct device *dev; |
|---|
| 93 | | - |
|---|
| 93 | + struct device dev; |
|---|
| 94 | 94 | struct cdev sm_cdev; |
|---|
| 95 | | - struct device *sm_dev; |
|---|
| 95 | + struct device sm_dev; |
|---|
| 96 | 96 | struct semaphore sm_sem; |
|---|
| 97 | 97 | |
|---|
| 98 | 98 | struct mutex file_mutex; |
|---|
| .. | .. |
|---|
| 105 | 105 | }; |
|---|
| 106 | 106 | |
|---|
| 107 | 107 | struct ib_umad_device { |
|---|
| 108 | | - struct kobject kobj; |
|---|
| 109 | | - struct ib_umad_port port[0]; |
|---|
| 108 | + struct kref kref; |
|---|
| 109 | + struct ib_umad_port ports[]; |
|---|
| 110 | 110 | }; |
|---|
| 111 | 111 | |
|---|
| 112 | 112 | struct ib_umad_file { |
|---|
| .. | .. |
|---|
| 131 | 131 | struct ib_user_mad mad; |
|---|
| 132 | 132 | }; |
|---|
| 133 | 133 | |
|---|
| 134 | | -static struct class *umad_class; |
|---|
| 134 | +struct ib_rmpp_mad_hdr { |
|---|
| 135 | + struct ib_mad_hdr mad_hdr; |
|---|
| 136 | + struct ib_rmpp_hdr rmpp_hdr; |
|---|
| 137 | +} __packed; |
|---|
| 138 | + |
|---|
| 139 | +#define CREATE_TRACE_POINTS |
|---|
| 140 | +#include <trace/events/ib_umad.h> |
|---|
| 135 | 141 | |
|---|
| 136 | 142 | static const dev_t base_umad_dev = MKDEV(IB_UMAD_MAJOR, IB_UMAD_MINOR_BASE); |
|---|
| 137 | 143 | static const dev_t base_issm_dev = MKDEV(IB_UMAD_MAJOR, IB_UMAD_MINOR_BASE) + |
|---|
| .. | .. |
|---|
| 139 | 145 | static dev_t dynamic_umad_dev; |
|---|
| 140 | 146 | static dev_t dynamic_issm_dev; |
|---|
| 141 | 147 | |
|---|
| 142 | | -static DECLARE_BITMAP(dev_map, IB_UMAD_MAX_PORTS); |
|---|
| 148 | +static DEFINE_IDA(umad_ida); |
|---|
| 143 | 149 | |
|---|
| 144 | | -static void ib_umad_add_one(struct ib_device *device); |
|---|
| 150 | +static int ib_umad_add_one(struct ib_device *device); |
|---|
| 145 | 151 | static void ib_umad_remove_one(struct ib_device *device, void *client_data); |
|---|
| 146 | 152 | |
|---|
| 147 | | -static void ib_umad_release_dev(struct kobject *kobj) |
|---|
| 153 | +static void ib_umad_dev_free(struct kref *kref) |
|---|
| 148 | 154 | { |
|---|
| 149 | 155 | struct ib_umad_device *dev = |
|---|
| 150 | | - container_of(kobj, struct ib_umad_device, kobj); |
|---|
| 156 | + container_of(kref, struct ib_umad_device, kref); |
|---|
| 151 | 157 | |
|---|
| 152 | 158 | kfree(dev); |
|---|
| 153 | 159 | } |
|---|
| 154 | 160 | |
|---|
| 155 | | -static struct kobj_type ib_umad_dev_ktype = { |
|---|
| 156 | | - .release = ib_umad_release_dev, |
|---|
| 157 | | -}; |
|---|
| 161 | +static void ib_umad_dev_get(struct ib_umad_device *dev) |
|---|
| 162 | +{ |
|---|
| 163 | + kref_get(&dev->kref); |
|---|
| 164 | +} |
|---|
| 165 | + |
|---|
| 166 | +static void ib_umad_dev_put(struct ib_umad_device *dev) |
|---|
| 167 | +{ |
|---|
| 168 | + kref_put(&dev->kref, ib_umad_dev_free); |
|---|
| 169 | +} |
|---|
| 158 | 170 | |
|---|
| 159 | 171 | static int hdr_size(struct ib_umad_file *file) |
|---|
| 160 | 172 | { |
|---|
| .. | .. |
|---|
| 206 | 218 | struct ib_umad_packet *packet = send_wc->send_buf->context[0]; |
|---|
| 207 | 219 | |
|---|
| 208 | 220 | dequeue_send(file, packet); |
|---|
| 209 | | - rdma_destroy_ah(packet->msg->ah); |
|---|
| 221 | + rdma_destroy_ah(packet->msg->ah, RDMA_DESTROY_AH_SLEEPABLE); |
|---|
| 210 | 222 | ib_free_send_mad(packet->msg); |
|---|
| 211 | 223 | |
|---|
| 212 | 224 | if (send_wc->status == IB_WC_RESP_TIMEOUT_ERR) { |
|---|
| .. | .. |
|---|
| 332 | 344 | return -EFAULT; |
|---|
| 333 | 345 | } |
|---|
| 334 | 346 | } |
|---|
| 347 | + |
|---|
| 348 | + trace_ib_umad_read_recv(file, &packet->mad.hdr, &recv_buf->mad->mad_hdr); |
|---|
| 349 | + |
|---|
| 335 | 350 | return hdr_size(file) + packet->length; |
|---|
| 336 | 351 | } |
|---|
| 337 | 352 | |
|---|
| .. | .. |
|---|
| 350 | 365 | |
|---|
| 351 | 366 | if (copy_to_user(buf, packet->mad.data, packet->length)) |
|---|
| 352 | 367 | return -EFAULT; |
|---|
| 368 | + |
|---|
| 369 | + trace_ib_umad_read_send(file, &packet->mad.hdr, |
|---|
| 370 | + (struct ib_mad_hdr *)&packet->mad.data); |
|---|
| 353 | 371 | |
|---|
| 354 | 372 | return size; |
|---|
| 355 | 373 | } |
|---|
| .. | .. |
|---|
| 481 | 499 | size_t count, loff_t *pos) |
|---|
| 482 | 500 | { |
|---|
| 483 | 501 | struct ib_umad_file *file = filp->private_data; |
|---|
| 502 | + struct ib_rmpp_mad_hdr *rmpp_mad_hdr; |
|---|
| 484 | 503 | struct ib_umad_packet *packet; |
|---|
| 485 | 504 | struct ib_mad_agent *agent; |
|---|
| 486 | 505 | struct rdma_ah_attr ah_attr; |
|---|
| 487 | 506 | struct ib_ah *ah; |
|---|
| 488 | | - struct ib_rmpp_mad *rmpp_mad; |
|---|
| 489 | 507 | __be64 *tid; |
|---|
| 490 | 508 | int ret, data_len, hdr_len, copy_offset, rmpp_active; |
|---|
| 491 | 509 | u8 base_version; |
|---|
| .. | .. |
|---|
| 493 | 511 | if (count < hdr_size(file) + IB_MGMT_RMPP_HDR) |
|---|
| 494 | 512 | return -EINVAL; |
|---|
| 495 | 513 | |
|---|
| 496 | | - packet = kzalloc(sizeof *packet + IB_MGMT_RMPP_HDR, GFP_KERNEL); |
|---|
| 514 | + packet = kzalloc(sizeof(*packet) + IB_MGMT_RMPP_HDR, GFP_KERNEL); |
|---|
| 497 | 515 | if (!packet) |
|---|
| 498 | 516 | return -ENOMEM; |
|---|
| 499 | 517 | |
|---|
| .. | .. |
|---|
| 515 | 533 | } |
|---|
| 516 | 534 | |
|---|
| 517 | 535 | mutex_lock(&file->mutex); |
|---|
| 536 | + |
|---|
| 537 | + trace_ib_umad_write(file, &packet->mad.hdr, |
|---|
| 538 | + (struct ib_mad_hdr *)&packet->mad.data); |
|---|
| 518 | 539 | |
|---|
| 519 | 540 | agent = __get_agent(file, packet->mad.hdr.id); |
|---|
| 520 | 541 | if (!agent) { |
|---|
| .. | .. |
|---|
| 544 | 565 | goto err_up; |
|---|
| 545 | 566 | } |
|---|
| 546 | 567 | |
|---|
| 547 | | - rmpp_mad = (struct ib_rmpp_mad *) packet->mad.data; |
|---|
| 548 | | - hdr_len = ib_get_mad_data_offset(rmpp_mad->mad_hdr.mgmt_class); |
|---|
| 568 | + rmpp_mad_hdr = (struct ib_rmpp_mad_hdr *)packet->mad.data; |
|---|
| 569 | + hdr_len = ib_get_mad_data_offset(rmpp_mad_hdr->mad_hdr.mgmt_class); |
|---|
| 549 | 570 | |
|---|
| 550 | | - if (ib_is_mad_class_rmpp(rmpp_mad->mad_hdr.mgmt_class) |
|---|
| 571 | + if (ib_is_mad_class_rmpp(rmpp_mad_hdr->mad_hdr.mgmt_class) |
|---|
| 551 | 572 | && ib_mad_kernel_rmpp_agent(agent)) { |
|---|
| 552 | 573 | copy_offset = IB_MGMT_RMPP_HDR; |
|---|
| 553 | | - rmpp_active = ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) & |
|---|
| 574 | + rmpp_active = ib_get_rmpp_flags(&rmpp_mad_hdr->rmpp_hdr) & |
|---|
| 554 | 575 | IB_MGMT_RMPP_FLAG_ACTIVE; |
|---|
| 555 | 576 | } else { |
|---|
| 556 | 577 | copy_offset = IB_MGMT_MAD_HDR; |
|---|
| .. | .. |
|---|
| 599 | 620 | tid = &((struct ib_mad_hdr *) packet->msg->mad)->tid; |
|---|
| 600 | 621 | *tid = cpu_to_be64(((u64) agent->hi_tid) << 32 | |
|---|
| 601 | 622 | (be64_to_cpup(tid) & 0xffffffff)); |
|---|
| 602 | | - rmpp_mad->mad_hdr.tid = *tid; |
|---|
| 623 | + rmpp_mad_hdr->mad_hdr.tid = *tid; |
|---|
| 603 | 624 | } |
|---|
| 604 | 625 | |
|---|
| 605 | 626 | if (!ib_mad_kernel_rmpp_agent(agent) |
|---|
| 606 | | - && ib_is_mad_class_rmpp(rmpp_mad->mad_hdr.mgmt_class) |
|---|
| 607 | | - && (ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) & IB_MGMT_RMPP_FLAG_ACTIVE)) { |
|---|
| 627 | + && ib_is_mad_class_rmpp(rmpp_mad_hdr->mad_hdr.mgmt_class) |
|---|
| 628 | + && (ib_get_rmpp_flags(&rmpp_mad_hdr->rmpp_hdr) & IB_MGMT_RMPP_FLAG_ACTIVE)) { |
|---|
| 608 | 629 | spin_lock_irq(&file->send_lock); |
|---|
| 609 | 630 | list_add_tail(&packet->list, &file->send_list); |
|---|
| 610 | 631 | spin_unlock_irq(&file->send_lock); |
|---|
| .. | .. |
|---|
| 632 | 653 | err_msg: |
|---|
| 633 | 654 | ib_free_send_mad(packet->msg); |
|---|
| 634 | 655 | err_ah: |
|---|
| 635 | | - rdma_destroy_ah(ah); |
|---|
| 656 | + rdma_destroy_ah(ah, RDMA_DESTROY_AH_SLEEPABLE); |
|---|
| 636 | 657 | err_up: |
|---|
| 637 | 658 | mutex_unlock(&file->mutex); |
|---|
| 638 | 659 | err: |
|---|
| .. | .. |
|---|
| 672 | 693 | mutex_lock(&file->mutex); |
|---|
| 673 | 694 | |
|---|
| 674 | 695 | if (!file->port->ib_dev) { |
|---|
| 675 | | - dev_notice(file->port->dev, |
|---|
| 696 | + dev_notice(&file->port->dev, |
|---|
| 676 | 697 | "ib_umad_reg_agent: invalid device\n"); |
|---|
| 677 | 698 | ret = -EPIPE; |
|---|
| 678 | 699 | goto out; |
|---|
| .. | .. |
|---|
| 684 | 705 | } |
|---|
| 685 | 706 | |
|---|
| 686 | 707 | if (ureq.qpn != 0 && ureq.qpn != 1) { |
|---|
| 687 | | - dev_notice(file->port->dev, |
|---|
| 708 | + dev_notice(&file->port->dev, |
|---|
| 688 | 709 | "ib_umad_reg_agent: invalid QPN %d specified\n", |
|---|
| 689 | 710 | ureq.qpn); |
|---|
| 690 | 711 | ret = -EINVAL; |
|---|
| .. | .. |
|---|
| 695 | 716 | if (!__get_agent(file, agent_id)) |
|---|
| 696 | 717 | goto found; |
|---|
| 697 | 718 | |
|---|
| 698 | | - dev_notice(file->port->dev, |
|---|
| 719 | + dev_notice(&file->port->dev, |
|---|
| 699 | 720 | "ib_umad_reg_agent: Max Agents (%u) reached\n", |
|---|
| 700 | 721 | IB_UMAD_MAX_AGENTS); |
|---|
| 701 | 722 | ret = -ENOMEM; |
|---|
| .. | .. |
|---|
| 740 | 761 | if (!file->already_used) { |
|---|
| 741 | 762 | file->already_used = 1; |
|---|
| 742 | 763 | if (!file->use_pkey_index) { |
|---|
| 743 | | - dev_warn(file->port->dev, |
|---|
| 764 | + dev_warn(&file->port->dev, |
|---|
| 744 | 765 | "process %s did not enable P_Key index support.\n", |
|---|
| 745 | 766 | current->comm); |
|---|
| 746 | | - dev_warn(file->port->dev, |
|---|
| 747 | | - " Documentation/infiniband/user_mad.txt has info on the new ABI.\n"); |
|---|
| 767 | + dev_warn(&file->port->dev, |
|---|
| 768 | + " Documentation/infiniband/user_mad.rst has info on the new ABI.\n"); |
|---|
| 748 | 769 | } |
|---|
| 749 | 770 | } |
|---|
| 750 | 771 | |
|---|
| .. | .. |
|---|
| 774 | 795 | mutex_lock(&file->mutex); |
|---|
| 775 | 796 | |
|---|
| 776 | 797 | if (!file->port->ib_dev) { |
|---|
| 777 | | - dev_notice(file->port->dev, |
|---|
| 798 | + dev_notice(&file->port->dev, |
|---|
| 778 | 799 | "ib_umad_reg_agent2: invalid device\n"); |
|---|
| 779 | 800 | ret = -EPIPE; |
|---|
| 780 | 801 | goto out; |
|---|
| .. | .. |
|---|
| 786 | 807 | } |
|---|
| 787 | 808 | |
|---|
| 788 | 809 | if (ureq.qpn != 0 && ureq.qpn != 1) { |
|---|
| 789 | | - dev_notice(file->port->dev, |
|---|
| 810 | + dev_notice(&file->port->dev, |
|---|
| 790 | 811 | "ib_umad_reg_agent2: invalid QPN %d specified\n", |
|---|
| 791 | 812 | ureq.qpn); |
|---|
| 792 | 813 | ret = -EINVAL; |
|---|
| .. | .. |
|---|
| 794 | 815 | } |
|---|
| 795 | 816 | |
|---|
| 796 | 817 | if (ureq.flags & ~IB_USER_MAD_REG_FLAGS_CAP) { |
|---|
| 797 | | - dev_notice(file->port->dev, |
|---|
| 818 | + dev_notice(&file->port->dev, |
|---|
| 798 | 819 | "ib_umad_reg_agent2 failed: invalid registration flags specified 0x%x; supported 0x%x\n", |
|---|
| 799 | 820 | ureq.flags, IB_USER_MAD_REG_FLAGS_CAP); |
|---|
| 800 | 821 | ret = -EINVAL; |
|---|
| .. | .. |
|---|
| 811 | 832 | if (!__get_agent(file, agent_id)) |
|---|
| 812 | 833 | goto found; |
|---|
| 813 | 834 | |
|---|
| 814 | | - dev_notice(file->port->dev, |
|---|
| 835 | + dev_notice(&file->port->dev, |
|---|
| 815 | 836 | "ib_umad_reg_agent2: Max Agents (%u) reached\n", |
|---|
| 816 | 837 | IB_UMAD_MAX_AGENTS); |
|---|
| 817 | 838 | ret = -ENOMEM; |
|---|
| .. | .. |
|---|
| 823 | 844 | req.mgmt_class = ureq.mgmt_class; |
|---|
| 824 | 845 | req.mgmt_class_version = ureq.mgmt_class_version; |
|---|
| 825 | 846 | if (ureq.oui & 0xff000000) { |
|---|
| 826 | | - dev_notice(file->port->dev, |
|---|
| 847 | + dev_notice(&file->port->dev, |
|---|
| 827 | 848 | "ib_umad_reg_agent2 failed: oui invalid 0x%08x\n", |
|---|
| 828 | 849 | ureq.oui); |
|---|
| 829 | 850 | ret = -EINVAL; |
|---|
| .. | .. |
|---|
| 972 | 993 | { |
|---|
| 973 | 994 | struct ib_umad_port *port; |
|---|
| 974 | 995 | struct ib_umad_file *file; |
|---|
| 975 | | - int ret = -ENXIO; |
|---|
| 996 | + int ret = 0; |
|---|
| 976 | 997 | |
|---|
| 977 | 998 | port = container_of(inode->i_cdev, struct ib_umad_port, cdev); |
|---|
| 978 | 999 | |
|---|
| 979 | 1000 | mutex_lock(&port->file_mutex); |
|---|
| 980 | 1001 | |
|---|
| 981 | | - if (!port->ib_dev) |
|---|
| 1002 | + if (!port->ib_dev) { |
|---|
| 1003 | + ret = -ENXIO; |
|---|
| 982 | 1004 | goto out; |
|---|
| 1005 | + } |
|---|
| 983 | 1006 | |
|---|
| 984 | | - ret = -ENOMEM; |
|---|
| 985 | | - file = kzalloc(sizeof *file, GFP_KERNEL); |
|---|
| 986 | | - if (!file) |
|---|
| 1007 | + if (!rdma_dev_access_netns(port->ib_dev, current->nsproxy->net_ns)) { |
|---|
| 1008 | + ret = -EPERM; |
|---|
| 987 | 1009 | goto out; |
|---|
| 1010 | + } |
|---|
| 1011 | + |
|---|
| 1012 | + file = kzalloc(sizeof(*file), GFP_KERNEL); |
|---|
| 1013 | + if (!file) { |
|---|
| 1014 | + ret = -ENOMEM; |
|---|
| 1015 | + goto out; |
|---|
| 1016 | + } |
|---|
| 988 | 1017 | |
|---|
| 989 | 1018 | mutex_init(&file->mutex); |
|---|
| 990 | 1019 | spin_lock_init(&file->send_lock); |
|---|
| .. | .. |
|---|
| 997 | 1026 | |
|---|
| 998 | 1027 | list_add_tail(&file->port_list, &port->file_list); |
|---|
| 999 | 1028 | |
|---|
| 1000 | | - ret = nonseekable_open(inode, filp); |
|---|
| 1001 | | - if (ret) { |
|---|
| 1002 | | - list_del(&file->port_list); |
|---|
| 1003 | | - kfree(file); |
|---|
| 1004 | | - goto out; |
|---|
| 1005 | | - } |
|---|
| 1006 | | - |
|---|
| 1007 | | - kobject_get(&port->umad_dev->kobj); |
|---|
| 1008 | | - |
|---|
| 1029 | + stream_open(inode, filp); |
|---|
| 1009 | 1030 | out: |
|---|
| 1010 | 1031 | mutex_unlock(&port->file_mutex); |
|---|
| 1011 | 1032 | return ret; |
|---|
| .. | .. |
|---|
| 1014 | 1035 | static int ib_umad_close(struct inode *inode, struct file *filp) |
|---|
| 1015 | 1036 | { |
|---|
| 1016 | 1037 | struct ib_umad_file *file = filp->private_data; |
|---|
| 1017 | | - struct ib_umad_device *dev = file->port->umad_dev; |
|---|
| 1018 | 1038 | struct ib_umad_packet *packet, *tmp; |
|---|
| 1019 | 1039 | int already_dead; |
|---|
| 1020 | 1040 | int i; |
|---|
| .. | .. |
|---|
| 1041 | 1061 | ib_unregister_mad_agent(file->agent[i]); |
|---|
| 1042 | 1062 | |
|---|
| 1043 | 1063 | mutex_unlock(&file->port->file_mutex); |
|---|
| 1044 | | - |
|---|
| 1064 | + mutex_destroy(&file->mutex); |
|---|
| 1045 | 1065 | kfree(file); |
|---|
| 1046 | | - kobject_put(&dev->kobj); |
|---|
| 1047 | | - |
|---|
| 1048 | 1066 | return 0; |
|---|
| 1049 | 1067 | } |
|---|
| 1050 | 1068 | |
|---|
| .. | .. |
|---|
| 1084 | 1102 | } |
|---|
| 1085 | 1103 | } |
|---|
| 1086 | 1104 | |
|---|
| 1105 | + if (!rdma_dev_access_netns(port->ib_dev, current->nsproxy->net_ns)) { |
|---|
| 1106 | + ret = -EPERM; |
|---|
| 1107 | + goto err_up_sem; |
|---|
| 1108 | + } |
|---|
| 1109 | + |
|---|
| 1087 | 1110 | ret = ib_modify_port(port->ib_dev, port->port_num, 0, &props); |
|---|
| 1088 | 1111 | if (ret) |
|---|
| 1089 | 1112 | goto err_up_sem; |
|---|
| 1090 | 1113 | |
|---|
| 1091 | 1114 | filp->private_data = port; |
|---|
| 1092 | 1115 | |
|---|
| 1093 | | - ret = nonseekable_open(inode, filp); |
|---|
| 1094 | | - if (ret) |
|---|
| 1095 | | - goto err_clr_sm_cap; |
|---|
| 1096 | | - |
|---|
| 1097 | | - kobject_get(&port->umad_dev->kobj); |
|---|
| 1098 | | - |
|---|
| 1116 | + nonseekable_open(inode, filp); |
|---|
| 1099 | 1117 | return 0; |
|---|
| 1100 | | - |
|---|
| 1101 | | -err_clr_sm_cap: |
|---|
| 1102 | | - swap(props.set_port_cap_mask, props.clr_port_cap_mask); |
|---|
| 1103 | | - ib_modify_port(port->ib_dev, port->port_num, 0, &props); |
|---|
| 1104 | 1118 | |
|---|
| 1105 | 1119 | err_up_sem: |
|---|
| 1106 | 1120 | up(&port->sm_sem); |
|---|
| .. | .. |
|---|
| 1124 | 1138 | |
|---|
| 1125 | 1139 | up(&port->sm_sem); |
|---|
| 1126 | 1140 | |
|---|
| 1127 | | - kobject_put(&port->umad_dev->kobj); |
|---|
| 1128 | | - |
|---|
| 1129 | 1141 | return ret; |
|---|
| 1130 | 1142 | } |
|---|
| 1131 | 1143 | |
|---|
| .. | .. |
|---|
| 1136 | 1148 | .llseek = no_llseek, |
|---|
| 1137 | 1149 | }; |
|---|
| 1138 | 1150 | |
|---|
| 1151 | +static struct ib_umad_port *get_port(struct ib_device *ibdev, |
|---|
| 1152 | + struct ib_umad_device *umad_dev, |
|---|
| 1153 | + unsigned int port) |
|---|
| 1154 | +{ |
|---|
| 1155 | + if (!umad_dev) |
|---|
| 1156 | + return ERR_PTR(-EOPNOTSUPP); |
|---|
| 1157 | + if (!rdma_is_port_valid(ibdev, port)) |
|---|
| 1158 | + return ERR_PTR(-EINVAL); |
|---|
| 1159 | + if (!rdma_cap_ib_mad(ibdev, port)) |
|---|
| 1160 | + return ERR_PTR(-EOPNOTSUPP); |
|---|
| 1161 | + |
|---|
| 1162 | + return &umad_dev->ports[port - rdma_start_port(ibdev)]; |
|---|
| 1163 | +} |
|---|
| 1164 | + |
|---|
| 1165 | +static int ib_umad_get_nl_info(struct ib_device *ibdev, void *client_data, |
|---|
| 1166 | + struct ib_client_nl_info *res) |
|---|
| 1167 | +{ |
|---|
| 1168 | + struct ib_umad_port *port = get_port(ibdev, client_data, res->port); |
|---|
| 1169 | + |
|---|
| 1170 | + if (IS_ERR(port)) |
|---|
| 1171 | + return PTR_ERR(port); |
|---|
| 1172 | + |
|---|
| 1173 | + res->abi = IB_USER_MAD_ABI_VERSION; |
|---|
| 1174 | + res->cdev = &port->dev; |
|---|
| 1175 | + return 0; |
|---|
| 1176 | +} |
|---|
| 1177 | + |
|---|
| 1139 | 1178 | static struct ib_client umad_client = { |
|---|
| 1140 | 1179 | .name = "umad", |
|---|
| 1141 | 1180 | .add = ib_umad_add_one, |
|---|
| 1142 | | - .remove = ib_umad_remove_one |
|---|
| 1181 | + .remove = ib_umad_remove_one, |
|---|
| 1182 | + .get_nl_info = ib_umad_get_nl_info, |
|---|
| 1143 | 1183 | }; |
|---|
| 1184 | +MODULE_ALIAS_RDMA_CLIENT("umad"); |
|---|
| 1144 | 1185 | |
|---|
| 1145 | | -static ssize_t show_ibdev(struct device *dev, struct device_attribute *attr, |
|---|
| 1186 | +static int ib_issm_get_nl_info(struct ib_device *ibdev, void *client_data, |
|---|
| 1187 | + struct ib_client_nl_info *res) |
|---|
| 1188 | +{ |
|---|
| 1189 | + struct ib_umad_port *port = get_port(ibdev, client_data, res->port); |
|---|
| 1190 | + |
|---|
| 1191 | + if (IS_ERR(port)) |
|---|
| 1192 | + return PTR_ERR(port); |
|---|
| 1193 | + |
|---|
| 1194 | + res->abi = IB_USER_MAD_ABI_VERSION; |
|---|
| 1195 | + res->cdev = &port->sm_dev; |
|---|
| 1196 | + return 0; |
|---|
| 1197 | +} |
|---|
| 1198 | + |
|---|
| 1199 | +static struct ib_client issm_client = { |
|---|
| 1200 | + .name = "issm", |
|---|
| 1201 | + .get_nl_info = ib_issm_get_nl_info, |
|---|
| 1202 | +}; |
|---|
| 1203 | +MODULE_ALIAS_RDMA_CLIENT("issm"); |
|---|
| 1204 | + |
|---|
| 1205 | +static ssize_t ibdev_show(struct device *dev, struct device_attribute *attr, |
|---|
| 1146 | 1206 | char *buf) |
|---|
| 1147 | 1207 | { |
|---|
| 1148 | 1208 | struct ib_umad_port *port = dev_get_drvdata(dev); |
|---|
| .. | .. |
|---|
| 1150 | 1210 | if (!port) |
|---|
| 1151 | 1211 | return -ENODEV; |
|---|
| 1152 | 1212 | |
|---|
| 1153 | | - return sprintf(buf, "%s\n", port->ib_dev->name); |
|---|
| 1213 | + return sprintf(buf, "%s\n", dev_name(&port->ib_dev->dev)); |
|---|
| 1154 | 1214 | } |
|---|
| 1155 | | -static DEVICE_ATTR(ibdev, S_IRUGO, show_ibdev, NULL); |
|---|
| 1215 | +static DEVICE_ATTR_RO(ibdev); |
|---|
| 1156 | 1216 | |
|---|
| 1157 | | -static ssize_t show_port(struct device *dev, struct device_attribute *attr, |
|---|
| 1217 | +static ssize_t port_show(struct device *dev, struct device_attribute *attr, |
|---|
| 1158 | 1218 | char *buf) |
|---|
| 1159 | 1219 | { |
|---|
| 1160 | 1220 | struct ib_umad_port *port = dev_get_drvdata(dev); |
|---|
| .. | .. |
|---|
| 1164 | 1224 | |
|---|
| 1165 | 1225 | return sprintf(buf, "%d\n", port->port_num); |
|---|
| 1166 | 1226 | } |
|---|
| 1167 | | -static DEVICE_ATTR(port, S_IRUGO, show_port, NULL); |
|---|
| 1227 | +static DEVICE_ATTR_RO(port); |
|---|
| 1168 | 1228 | |
|---|
| 1169 | | -static CLASS_ATTR_STRING(abi_version, S_IRUGO, |
|---|
| 1170 | | - __stringify(IB_USER_MAD_ABI_VERSION)); |
|---|
| 1229 | +static struct attribute *umad_class_dev_attrs[] = { |
|---|
| 1230 | + &dev_attr_ibdev.attr, |
|---|
| 1231 | + &dev_attr_port.attr, |
|---|
| 1232 | + NULL, |
|---|
| 1233 | +}; |
|---|
| 1234 | +ATTRIBUTE_GROUPS(umad_class_dev); |
|---|
| 1235 | + |
|---|
| 1236 | +static char *umad_devnode(struct device *dev, umode_t *mode) |
|---|
| 1237 | +{ |
|---|
| 1238 | + return kasprintf(GFP_KERNEL, "infiniband/%s", dev_name(dev)); |
|---|
| 1239 | +} |
|---|
| 1240 | + |
|---|
| 1241 | +static ssize_t abi_version_show(struct class *class, |
|---|
| 1242 | + struct class_attribute *attr, char *buf) |
|---|
| 1243 | +{ |
|---|
| 1244 | + return sprintf(buf, "%d\n", IB_USER_MAD_ABI_VERSION); |
|---|
| 1245 | +} |
|---|
| 1246 | +static CLASS_ATTR_RO(abi_version); |
|---|
| 1247 | + |
|---|
| 1248 | +static struct attribute *umad_class_attrs[] = { |
|---|
| 1249 | + &class_attr_abi_version.attr, |
|---|
| 1250 | + NULL, |
|---|
| 1251 | +}; |
|---|
| 1252 | +ATTRIBUTE_GROUPS(umad_class); |
|---|
| 1253 | + |
|---|
| 1254 | +static struct class umad_class = { |
|---|
| 1255 | + .name = "infiniband_mad", |
|---|
| 1256 | + .devnode = umad_devnode, |
|---|
| 1257 | + .class_groups = umad_class_groups, |
|---|
| 1258 | + .dev_groups = umad_class_dev_groups, |
|---|
| 1259 | +}; |
|---|
| 1260 | + |
|---|
| 1261 | +static void ib_umad_release_port(struct device *device) |
|---|
| 1262 | +{ |
|---|
| 1263 | + struct ib_umad_port *port = dev_get_drvdata(device); |
|---|
| 1264 | + struct ib_umad_device *umad_dev = port->umad_dev; |
|---|
| 1265 | + |
|---|
| 1266 | + ib_umad_dev_put(umad_dev); |
|---|
| 1267 | +} |
|---|
| 1268 | + |
|---|
| 1269 | +static void ib_umad_init_port_dev(struct device *dev, |
|---|
| 1270 | + struct ib_umad_port *port, |
|---|
| 1271 | + const struct ib_device *device) |
|---|
| 1272 | +{ |
|---|
| 1273 | + device_initialize(dev); |
|---|
| 1274 | + ib_umad_dev_get(port->umad_dev); |
|---|
| 1275 | + dev->class = &umad_class; |
|---|
| 1276 | + dev->parent = device->dev.parent; |
|---|
| 1277 | + dev_set_drvdata(dev, port); |
|---|
| 1278 | + dev->release = ib_umad_release_port; |
|---|
| 1279 | +} |
|---|
| 1171 | 1280 | |
|---|
| 1172 | 1281 | static int ib_umad_init_port(struct ib_device *device, int port_num, |
|---|
| 1173 | 1282 | struct ib_umad_device *umad_dev, |
|---|
| .. | .. |
|---|
| 1176 | 1285 | int devnum; |
|---|
| 1177 | 1286 | dev_t base_umad; |
|---|
| 1178 | 1287 | dev_t base_issm; |
|---|
| 1288 | + int ret; |
|---|
| 1179 | 1289 | |
|---|
| 1180 | | - devnum = find_first_zero_bit(dev_map, IB_UMAD_MAX_PORTS); |
|---|
| 1181 | | - if (devnum >= IB_UMAD_MAX_PORTS) |
|---|
| 1290 | + devnum = ida_alloc_max(&umad_ida, IB_UMAD_MAX_PORTS - 1, GFP_KERNEL); |
|---|
| 1291 | + if (devnum < 0) |
|---|
| 1182 | 1292 | return -1; |
|---|
| 1183 | 1293 | port->dev_num = devnum; |
|---|
| 1184 | | - set_bit(devnum, dev_map); |
|---|
| 1185 | 1294 | if (devnum >= IB_UMAD_NUM_FIXED_MINOR) { |
|---|
| 1186 | 1295 | base_umad = dynamic_umad_dev + devnum - IB_UMAD_NUM_FIXED_MINOR; |
|---|
| 1187 | 1296 | base_issm = dynamic_issm_dev + devnum - IB_UMAD_NUM_FIXED_MINOR; |
|---|
| .. | .. |
|---|
| 1191 | 1300 | } |
|---|
| 1192 | 1301 | |
|---|
| 1193 | 1302 | port->ib_dev = device; |
|---|
| 1303 | + port->umad_dev = umad_dev; |
|---|
| 1194 | 1304 | port->port_num = port_num; |
|---|
| 1195 | 1305 | sema_init(&port->sm_sem, 1); |
|---|
| 1196 | 1306 | mutex_init(&port->file_mutex); |
|---|
| 1197 | 1307 | INIT_LIST_HEAD(&port->file_list); |
|---|
| 1198 | 1308 | |
|---|
| 1309 | + ib_umad_init_port_dev(&port->dev, port, device); |
|---|
| 1310 | + port->dev.devt = base_umad; |
|---|
| 1311 | + dev_set_name(&port->dev, "umad%d", port->dev_num); |
|---|
| 1199 | 1312 | cdev_init(&port->cdev, &umad_fops); |
|---|
| 1200 | 1313 | port->cdev.owner = THIS_MODULE; |
|---|
| 1201 | | - cdev_set_parent(&port->cdev, &umad_dev->kobj); |
|---|
| 1202 | | - kobject_set_name(&port->cdev.kobj, "umad%d", port->dev_num); |
|---|
| 1203 | | - if (cdev_add(&port->cdev, base_umad, 1)) |
|---|
| 1314 | + |
|---|
| 1315 | + ret = cdev_device_add(&port->cdev, &port->dev); |
|---|
| 1316 | + if (ret) |
|---|
| 1204 | 1317 | goto err_cdev; |
|---|
| 1205 | 1318 | |
|---|
| 1206 | | - port->dev = device_create(umad_class, device->dev.parent, |
|---|
| 1207 | | - port->cdev.dev, port, |
|---|
| 1208 | | - "umad%d", port->dev_num); |
|---|
| 1209 | | - if (IS_ERR(port->dev)) |
|---|
| 1210 | | - goto err_cdev; |
|---|
| 1211 | | - |
|---|
| 1212 | | - if (device_create_file(port->dev, &dev_attr_ibdev)) |
|---|
| 1213 | | - goto err_dev; |
|---|
| 1214 | | - if (device_create_file(port->dev, &dev_attr_port)) |
|---|
| 1215 | | - goto err_dev; |
|---|
| 1216 | | - |
|---|
| 1319 | + ib_umad_init_port_dev(&port->sm_dev, port, device); |
|---|
| 1320 | + port->sm_dev.devt = base_issm; |
|---|
| 1321 | + dev_set_name(&port->sm_dev, "issm%d", port->dev_num); |
|---|
| 1217 | 1322 | cdev_init(&port->sm_cdev, &umad_sm_fops); |
|---|
| 1218 | 1323 | port->sm_cdev.owner = THIS_MODULE; |
|---|
| 1219 | | - cdev_set_parent(&port->sm_cdev, &umad_dev->kobj); |
|---|
| 1220 | | - kobject_set_name(&port->sm_cdev.kobj, "issm%d", port->dev_num); |
|---|
| 1221 | | - if (cdev_add(&port->sm_cdev, base_issm, 1)) |
|---|
| 1222 | | - goto err_sm_cdev; |
|---|
| 1223 | 1324 | |
|---|
| 1224 | | - port->sm_dev = device_create(umad_class, device->dev.parent, |
|---|
| 1225 | | - port->sm_cdev.dev, port, |
|---|
| 1226 | | - "issm%d", port->dev_num); |
|---|
| 1227 | | - if (IS_ERR(port->sm_dev)) |
|---|
| 1228 | | - goto err_sm_cdev; |
|---|
| 1229 | | - |
|---|
| 1230 | | - if (device_create_file(port->sm_dev, &dev_attr_ibdev)) |
|---|
| 1231 | | - goto err_sm_dev; |
|---|
| 1232 | | - if (device_create_file(port->sm_dev, &dev_attr_port)) |
|---|
| 1233 | | - goto err_sm_dev; |
|---|
| 1325 | + ret = cdev_device_add(&port->sm_cdev, &port->sm_dev); |
|---|
| 1326 | + if (ret) |
|---|
| 1327 | + goto err_dev; |
|---|
| 1234 | 1328 | |
|---|
| 1235 | 1329 | return 0; |
|---|
| 1236 | 1330 | |
|---|
| 1237 | | -err_sm_dev: |
|---|
| 1238 | | - device_destroy(umad_class, port->sm_cdev.dev); |
|---|
| 1239 | | - |
|---|
| 1240 | | -err_sm_cdev: |
|---|
| 1241 | | - cdev_del(&port->sm_cdev); |
|---|
| 1242 | | - |
|---|
| 1243 | 1331 | err_dev: |
|---|
| 1244 | | - device_destroy(umad_class, port->cdev.dev); |
|---|
| 1245 | | - |
|---|
| 1332 | + put_device(&port->sm_dev); |
|---|
| 1333 | + cdev_device_del(&port->cdev, &port->dev); |
|---|
| 1246 | 1334 | err_cdev: |
|---|
| 1247 | | - cdev_del(&port->cdev); |
|---|
| 1248 | | - clear_bit(devnum, dev_map); |
|---|
| 1249 | | - |
|---|
| 1250 | | - return -1; |
|---|
| 1335 | + put_device(&port->dev); |
|---|
| 1336 | + ida_free(&umad_ida, devnum); |
|---|
| 1337 | + return ret; |
|---|
| 1251 | 1338 | } |
|---|
| 1252 | 1339 | |
|---|
| 1253 | 1340 | static void ib_umad_kill_port(struct ib_umad_port *port) |
|---|
| .. | .. |
|---|
| 1255 | 1342 | struct ib_umad_file *file; |
|---|
| 1256 | 1343 | int id; |
|---|
| 1257 | 1344 | |
|---|
| 1258 | | - dev_set_drvdata(port->dev, NULL); |
|---|
| 1259 | | - dev_set_drvdata(port->sm_dev, NULL); |
|---|
| 1260 | | - |
|---|
| 1261 | | - device_destroy(umad_class, port->cdev.dev); |
|---|
| 1262 | | - device_destroy(umad_class, port->sm_cdev.dev); |
|---|
| 1263 | | - |
|---|
| 1264 | | - cdev_del(&port->cdev); |
|---|
| 1265 | | - cdev_del(&port->sm_cdev); |
|---|
| 1345 | + cdev_device_del(&port->sm_cdev, &port->sm_dev); |
|---|
| 1346 | + cdev_device_del(&port->cdev, &port->dev); |
|---|
| 1266 | 1347 | |
|---|
| 1267 | 1348 | mutex_lock(&port->file_mutex); |
|---|
| 1268 | 1349 | |
|---|
| 1350 | + /* Mark ib_dev NULL and block ioctl or other file ops to progress |
|---|
| 1351 | + * further. |
|---|
| 1352 | + */ |
|---|
| 1269 | 1353 | port->ib_dev = NULL; |
|---|
| 1270 | 1354 | |
|---|
| 1271 | 1355 | list_for_each_entry(file, &port->file_list, port_list) { |
|---|
| .. | .. |
|---|
| 1280 | 1364 | } |
|---|
| 1281 | 1365 | |
|---|
| 1282 | 1366 | mutex_unlock(&port->file_mutex); |
|---|
| 1283 | | - clear_bit(port->dev_num, dev_map); |
|---|
| 1367 | + |
|---|
| 1368 | + ida_free(&umad_ida, port->dev_num); |
|---|
| 1369 | + |
|---|
| 1370 | + /* balances device_initialize() */ |
|---|
| 1371 | + put_device(&port->sm_dev); |
|---|
| 1372 | + put_device(&port->dev); |
|---|
| 1284 | 1373 | } |
|---|
| 1285 | 1374 | |
|---|
| 1286 | | -static void ib_umad_add_one(struct ib_device *device) |
|---|
| 1375 | +static int ib_umad_add_one(struct ib_device *device) |
|---|
| 1287 | 1376 | { |
|---|
| 1288 | 1377 | struct ib_umad_device *umad_dev; |
|---|
| 1289 | 1378 | int s, e, i; |
|---|
| 1290 | 1379 | int count = 0; |
|---|
| 1380 | + int ret; |
|---|
| 1291 | 1381 | |
|---|
| 1292 | 1382 | s = rdma_start_port(device); |
|---|
| 1293 | 1383 | e = rdma_end_port(device); |
|---|
| 1294 | 1384 | |
|---|
| 1295 | | - umad_dev = kzalloc(sizeof *umad_dev + |
|---|
| 1296 | | - (e - s + 1) * sizeof (struct ib_umad_port), |
|---|
| 1297 | | - GFP_KERNEL); |
|---|
| 1385 | + umad_dev = kzalloc(struct_size(umad_dev, ports, e - s + 1), GFP_KERNEL); |
|---|
| 1298 | 1386 | if (!umad_dev) |
|---|
| 1299 | | - return; |
|---|
| 1387 | + return -ENOMEM; |
|---|
| 1300 | 1388 | |
|---|
| 1301 | | - kobject_init(&umad_dev->kobj, &ib_umad_dev_ktype); |
|---|
| 1302 | | - |
|---|
| 1389 | + kref_init(&umad_dev->kref); |
|---|
| 1303 | 1390 | for (i = s; i <= e; ++i) { |
|---|
| 1304 | 1391 | if (!rdma_cap_ib_mad(device, i)) |
|---|
| 1305 | 1392 | continue; |
|---|
| 1306 | 1393 | |
|---|
| 1307 | | - umad_dev->port[i - s].umad_dev = umad_dev; |
|---|
| 1308 | | - |
|---|
| 1309 | | - if (ib_umad_init_port(device, i, umad_dev, |
|---|
| 1310 | | - &umad_dev->port[i - s])) |
|---|
| 1394 | + ret = ib_umad_init_port(device, i, umad_dev, |
|---|
| 1395 | + &umad_dev->ports[i - s]); |
|---|
| 1396 | + if (ret) |
|---|
| 1311 | 1397 | goto err; |
|---|
| 1312 | 1398 | |
|---|
| 1313 | 1399 | count++; |
|---|
| 1314 | 1400 | } |
|---|
| 1315 | 1401 | |
|---|
| 1316 | | - if (!count) |
|---|
| 1402 | + if (!count) { |
|---|
| 1403 | + ret = -EOPNOTSUPP; |
|---|
| 1317 | 1404 | goto free; |
|---|
| 1405 | + } |
|---|
| 1318 | 1406 | |
|---|
| 1319 | 1407 | ib_set_client_data(device, &umad_client, umad_dev); |
|---|
| 1320 | 1408 | |
|---|
| 1321 | | - return; |
|---|
| 1409 | + return 0; |
|---|
| 1322 | 1410 | |
|---|
| 1323 | 1411 | err: |
|---|
| 1324 | 1412 | while (--i >= s) { |
|---|
| 1325 | 1413 | if (!rdma_cap_ib_mad(device, i)) |
|---|
| 1326 | 1414 | continue; |
|---|
| 1327 | 1415 | |
|---|
| 1328 | | - ib_umad_kill_port(&umad_dev->port[i - s]); |
|---|
| 1416 | + ib_umad_kill_port(&umad_dev->ports[i - s]); |
|---|
| 1329 | 1417 | } |
|---|
| 1330 | 1418 | free: |
|---|
| 1331 | | - kobject_put(&umad_dev->kobj); |
|---|
| 1419 | + /* balances kref_init */ |
|---|
| 1420 | + ib_umad_dev_put(umad_dev); |
|---|
| 1421 | + return ret; |
|---|
| 1332 | 1422 | } |
|---|
| 1333 | 1423 | |
|---|
| 1334 | 1424 | static void ib_umad_remove_one(struct ib_device *device, void *client_data) |
|---|
| 1335 | 1425 | { |
|---|
| 1336 | 1426 | struct ib_umad_device *umad_dev = client_data; |
|---|
| 1337 | | - int i; |
|---|
| 1427 | + unsigned int i; |
|---|
| 1338 | 1428 | |
|---|
| 1339 | | - if (!umad_dev) |
|---|
| 1340 | | - return; |
|---|
| 1341 | | - |
|---|
| 1342 | | - for (i = 0; i <= rdma_end_port(device) - rdma_start_port(device); ++i) { |
|---|
| 1343 | | - if (rdma_cap_ib_mad(device, i + rdma_start_port(device))) |
|---|
| 1344 | | - ib_umad_kill_port(&umad_dev->port[i]); |
|---|
| 1429 | + rdma_for_each_port (device, i) { |
|---|
| 1430 | + if (rdma_cap_ib_mad(device, i)) |
|---|
| 1431 | + ib_umad_kill_port( |
|---|
| 1432 | + &umad_dev->ports[i - rdma_start_port(device)]); |
|---|
| 1345 | 1433 | } |
|---|
| 1346 | | - |
|---|
| 1347 | | - kobject_put(&umad_dev->kobj); |
|---|
| 1348 | | -} |
|---|
| 1349 | | - |
|---|
| 1350 | | -static char *umad_devnode(struct device *dev, umode_t *mode) |
|---|
| 1351 | | -{ |
|---|
| 1352 | | - return kasprintf(GFP_KERNEL, "infiniband/%s", dev_name(dev)); |
|---|
| 1434 | + /* balances kref_init() */ |
|---|
| 1435 | + ib_umad_dev_put(umad_dev); |
|---|
| 1353 | 1436 | } |
|---|
| 1354 | 1437 | |
|---|
| 1355 | 1438 | static int __init ib_umad_init(void) |
|---|
| .. | .. |
|---|
| 1358 | 1441 | |
|---|
| 1359 | 1442 | ret = register_chrdev_region(base_umad_dev, |
|---|
| 1360 | 1443 | IB_UMAD_NUM_FIXED_MINOR * 2, |
|---|
| 1361 | | - "infiniband_mad"); |
|---|
| 1444 | + umad_class.name); |
|---|
| 1362 | 1445 | if (ret) { |
|---|
| 1363 | 1446 | pr_err("couldn't register device number\n"); |
|---|
| 1364 | 1447 | goto out; |
|---|
| .. | .. |
|---|
| 1366 | 1449 | |
|---|
| 1367 | 1450 | ret = alloc_chrdev_region(&dynamic_umad_dev, 0, |
|---|
| 1368 | 1451 | IB_UMAD_NUM_DYNAMIC_MINOR * 2, |
|---|
| 1369 | | - "infiniband_mad"); |
|---|
| 1452 | + umad_class.name); |
|---|
| 1370 | 1453 | if (ret) { |
|---|
| 1371 | 1454 | pr_err("couldn't register dynamic device number\n"); |
|---|
| 1372 | 1455 | goto out_alloc; |
|---|
| 1373 | 1456 | } |
|---|
| 1374 | 1457 | dynamic_issm_dev = dynamic_umad_dev + IB_UMAD_NUM_DYNAMIC_MINOR; |
|---|
| 1375 | 1458 | |
|---|
| 1376 | | - umad_class = class_create(THIS_MODULE, "infiniband_mad"); |
|---|
| 1377 | | - if (IS_ERR(umad_class)) { |
|---|
| 1378 | | - ret = PTR_ERR(umad_class); |
|---|
| 1459 | + ret = class_register(&umad_class); |
|---|
| 1460 | + if (ret) { |
|---|
| 1379 | 1461 | pr_err("couldn't create class infiniband_mad\n"); |
|---|
| 1380 | 1462 | goto out_chrdev; |
|---|
| 1381 | 1463 | } |
|---|
| 1382 | 1464 | |
|---|
| 1383 | | - umad_class->devnode = umad_devnode; |
|---|
| 1384 | | - |
|---|
| 1385 | | - ret = class_create_file(umad_class, &class_attr_abi_version.attr); |
|---|
| 1386 | | - if (ret) { |
|---|
| 1387 | | - pr_err("couldn't create abi_version attribute\n"); |
|---|
| 1388 | | - goto out_class; |
|---|
| 1389 | | - } |
|---|
| 1390 | | - |
|---|
| 1391 | 1465 | ret = ib_register_client(&umad_client); |
|---|
| 1392 | | - if (ret) { |
|---|
| 1393 | | - pr_err("couldn't register ib_umad client\n"); |
|---|
| 1466 | + if (ret) |
|---|
| 1394 | 1467 | goto out_class; |
|---|
| 1395 | | - } |
|---|
| 1468 | + |
|---|
| 1469 | + ret = ib_register_client(&issm_client); |
|---|
| 1470 | + if (ret) |
|---|
| 1471 | + goto out_client; |
|---|
| 1396 | 1472 | |
|---|
| 1397 | 1473 | return 0; |
|---|
| 1398 | 1474 | |
|---|
| 1475 | +out_client: |
|---|
| 1476 | + ib_unregister_client(&umad_client); |
|---|
| 1399 | 1477 | out_class: |
|---|
| 1400 | | - class_destroy(umad_class); |
|---|
| 1478 | + class_unregister(&umad_class); |
|---|
| 1401 | 1479 | |
|---|
| 1402 | 1480 | out_chrdev: |
|---|
| 1403 | 1481 | unregister_chrdev_region(dynamic_umad_dev, |
|---|
| .. | .. |
|---|
| 1413 | 1491 | |
|---|
| 1414 | 1492 | static void __exit ib_umad_cleanup(void) |
|---|
| 1415 | 1493 | { |
|---|
| 1494 | + ib_unregister_client(&issm_client); |
|---|
| 1416 | 1495 | ib_unregister_client(&umad_client); |
|---|
| 1417 | | - class_destroy(umad_class); |
|---|
| 1496 | + class_unregister(&umad_class); |
|---|
| 1418 | 1497 | unregister_chrdev_region(base_umad_dev, |
|---|
| 1419 | 1498 | IB_UMAD_NUM_FIXED_MINOR * 2); |
|---|
| 1420 | 1499 | unregister_chrdev_region(dynamic_umad_dev, |
|---|