Lines Matching +full:entry +full:- +full:method
2 * Copyright (c) 2004-2007 Voltaire, Inc. All rights reserved.
18 * - Redistributions of source code must retain the above
22 * - Redistributions in binary form must reproduce the above
40 #include <linux/dma-mapping.h>
60 struct trace_event_raw_ib_mad_send_template *entry) in create_mad_addr_info() argument
62 struct ib_ud_wr *wr = &mad_send_wr->send_wr; in create_mad_addr_info()
65 rdma_query_ah(wr->ah, &attr); in create_mad_addr_info()
68 entry->sl = attr.sl; in create_mad_addr_info()
69 entry->rqpn = wr->remote_qpn; in create_mad_addr_info()
70 entry->rqkey = wr->remote_qkey; in create_mad_addr_info()
71 entry->dlid = rdma_ah_get_dlid(&attr); in create_mad_addr_info()
91 static int method_in_use(struct ib_mad_mgmt_method_table **method,
118 struct ib_mad_port_private *entry; in __ib_get_mad_port() local
120 list_for_each_entry(entry, &ib_mad_port_list, port_list) { in __ib_get_mad_port()
121 if (entry->device == device && entry->port_num == port_num) in __ib_get_mad_port()
122 return entry; in __ib_get_mad_port()
134 struct ib_mad_port_private *entry; in ib_get_mad_port() local
138 entry = __ib_get_mad_port(device, port_num); in ib_get_mad_port()
141 return entry; in ib_get_mad_port()
159 return -1; in get_spl_qp_index()
165 return mgmt_class - IB_MGMT_CLASS_VENDOR_RANGE2_START; in vendor_class_index()
187 struct ib_mad_mgmt_method_table *method; in is_vendor_method_in_use() local
191 if (!memcmp(vendor_class->oui[i], mad_reg_req->oui, 3)) { in is_vendor_method_in_use()
192 method = vendor_class->method_table[i]; in is_vendor_method_in_use()
193 if (method) { in is_vendor_method_in_use()
194 if (method_in_use(&method, mad_reg_req)) in is_vendor_method_in_use()
206 return ((hdr->method & IB_MGMT_METHOD_RESP) || in ib_response_mad()
207 (hdr->method == IB_MGMT_METHOD_TRAP_REPRESS) || in ib_response_mad()
208 ((hdr->mgmt_class == IB_MGMT_CLASS_BM) && in ib_response_mad()
209 (hdr->attr_mod & IB_BM_ATTR_MOD_RESP))); in ib_response_mad()
214 * ib_register_mad_agent - Register to send/receive MADs
229 struct ib_mad_agent *ret = ERR_PTR(-EINVAL); in ib_register_mad_agent()
235 struct ib_mad_mgmt_method_table *method; in ib_register_mad_agent() local
241 return ERR_PTR(-EPROTONOSUPPORT); in ib_register_mad_agent()
245 if (qpn == -1) { in ib_register_mad_agent()
246 dev_dbg_ratelimited(&device->dev, "%s: invalid QP Type %d\n", in ib_register_mad_agent()
252 dev_dbg_ratelimited(&device->dev, in ib_register_mad_agent()
260 if (mad_reg_req->mgmt_class_version >= MAX_MGMT_VERSION) { in ib_register_mad_agent()
261 dev_dbg_ratelimited(&device->dev, in ib_register_mad_agent()
264 mad_reg_req->mgmt_class_version); in ib_register_mad_agent()
268 dev_dbg_ratelimited(&device->dev, in ib_register_mad_agent()
272 if (mad_reg_req->mgmt_class >= MAX_MGMT_CLASS) { in ib_register_mad_agent()
277 if (mad_reg_req->mgmt_class != in ib_register_mad_agent()
279 dev_dbg_ratelimited(&device->dev, in ib_register_mad_agent()
281 __func__, mad_reg_req->mgmt_class); in ib_register_mad_agent()
284 } else if (mad_reg_req->mgmt_class == 0) { in ib_register_mad_agent()
289 dev_dbg_ratelimited(&device->dev, in ib_register_mad_agent()
293 } else if (is_vendor_class(mad_reg_req->mgmt_class)) { in ib_register_mad_agent()
298 if (!is_vendor_oui(mad_reg_req->oui)) { in ib_register_mad_agent()
299 dev_dbg_ratelimited(&device->dev, in ib_register_mad_agent()
302 mad_reg_req->mgmt_class); in ib_register_mad_agent()
307 if (!ib_is_mad_class_rmpp(mad_reg_req->mgmt_class)) { in ib_register_mad_agent()
309 dev_dbg_ratelimited(&device->dev, in ib_register_mad_agent()
310 "%s: RMPP version for non-RMPP class 0x%x\n", in ib_register_mad_agent()
311 __func__, mad_reg_req->mgmt_class); in ib_register_mad_agent()
318 if ((mad_reg_req->mgmt_class != in ib_register_mad_agent()
320 (mad_reg_req->mgmt_class != in ib_register_mad_agent()
322 dev_dbg_ratelimited(&device->dev, in ib_register_mad_agent()
324 __func__, mad_reg_req->mgmt_class); in ib_register_mad_agent()
328 if ((mad_reg_req->mgmt_class == in ib_register_mad_agent()
330 (mad_reg_req->mgmt_class == in ib_register_mad_agent()
332 dev_dbg_ratelimited(&device->dev, in ib_register_mad_agent()
334 __func__, mad_reg_req->mgmt_class); in ib_register_mad_agent()
349 dev_dbg_ratelimited(&device->dev, "%s: Invalid port %u\n", in ib_register_mad_agent()
351 ret = ERR_PTR(-ENODEV); in ib_register_mad_agent()
358 if (!port_priv->qp_info[qpn].qp) { in ib_register_mad_agent()
359 dev_dbg_ratelimited(&device->dev, "%s: QP %d not supported\n", in ib_register_mad_agent()
361 ret = ERR_PTR(-EPROTONOSUPPORT); in ib_register_mad_agent()
368 ret = ERR_PTR(-ENOMEM); in ib_register_mad_agent()
375 ret = ERR_PTR(-ENOMEM); in ib_register_mad_agent()
381 mad_agent_priv->qp_info = &port_priv->qp_info[qpn]; in ib_register_mad_agent()
382 mad_agent_priv->reg_req = reg_req; in ib_register_mad_agent()
383 mad_agent_priv->agent.rmpp_version = rmpp_version; in ib_register_mad_agent()
384 mad_agent_priv->agent.device = device; in ib_register_mad_agent()
385 mad_agent_priv->agent.recv_handler = recv_handler; in ib_register_mad_agent()
386 mad_agent_priv->agent.send_handler = send_handler; in ib_register_mad_agent()
387 mad_agent_priv->agent.context = context; in ib_register_mad_agent()
388 mad_agent_priv->agent.qp = port_priv->qp_info[qpn].qp; in ib_register_mad_agent()
389 mad_agent_priv->agent.port_num = port_num; in ib_register_mad_agent()
390 mad_agent_priv->agent.flags = registration_flags; in ib_register_mad_agent()
391 spin_lock_init(&mad_agent_priv->lock); in ib_register_mad_agent()
392 INIT_LIST_HEAD(&mad_agent_priv->send_list); in ib_register_mad_agent()
393 INIT_LIST_HEAD(&mad_agent_priv->wait_list); in ib_register_mad_agent()
394 INIT_LIST_HEAD(&mad_agent_priv->done_list); in ib_register_mad_agent()
395 INIT_LIST_HEAD(&mad_agent_priv->rmpp_list); in ib_register_mad_agent()
396 INIT_DELAYED_WORK(&mad_agent_priv->timed_work, timeout_sends); in ib_register_mad_agent()
397 INIT_LIST_HEAD(&mad_agent_priv->local_list); in ib_register_mad_agent()
398 INIT_WORK(&mad_agent_priv->local_work, local_completions); in ib_register_mad_agent()
399 refcount_set(&mad_agent_priv->refcount, 1); in ib_register_mad_agent()
400 init_completion(&mad_agent_priv->comp); in ib_register_mad_agent()
402 ret2 = ib_mad_agent_security_setup(&mad_agent_priv->agent, qp_type); in ib_register_mad_agent()
412 ret2 = xa_alloc_cyclic(&ib_mad_clients, &mad_agent_priv->agent.hi_tid, in ib_register_mad_agent()
413 mad_agent_priv, XA_LIMIT(0, (1 << 24) - 1), in ib_register_mad_agent()
424 spin_lock_irq(&port_priv->reg_lock); in ib_register_mad_agent()
426 mgmt_class = convert_mgmt_class(mad_reg_req->mgmt_class); in ib_register_mad_agent()
428 class = port_priv->version[mad_reg_req-> in ib_register_mad_agent()
431 method = class->method_table[mgmt_class]; in ib_register_mad_agent()
432 if (method) { in ib_register_mad_agent()
433 if (method_in_use(&method, in ib_register_mad_agent()
442 vendor = port_priv->version[mad_reg_req-> in ib_register_mad_agent()
446 vendor_class = vendor->vendor_class[vclass]; in ib_register_mad_agent()
461 spin_unlock_irq(&port_priv->reg_lock); in ib_register_mad_agent()
464 return &mad_agent_priv->agent; in ib_register_mad_agent()
466 spin_unlock_irq(&port_priv->reg_lock); in ib_register_mad_agent()
467 xa_erase(&ib_mad_clients, mad_agent_priv->agent.hi_tid); in ib_register_mad_agent()
469 ib_mad_agent_security_cleanup(&mad_agent_priv->agent); in ib_register_mad_agent()
481 if (refcount_dec_and_test(&mad_agent_priv->refcount)) in deref_mad_agent()
482 complete(&mad_agent_priv->comp); in deref_mad_agent()
497 port_priv = mad_agent_priv->qp_info->port_priv; in unregister_mad_agent()
498 cancel_delayed_work(&mad_agent_priv->timed_work); in unregister_mad_agent()
500 spin_lock_irq(&port_priv->reg_lock); in unregister_mad_agent()
502 spin_unlock_irq(&port_priv->reg_lock); in unregister_mad_agent()
503 xa_erase(&ib_mad_clients, mad_agent_priv->agent.hi_tid); in unregister_mad_agent()
505 flush_workqueue(port_priv->wq); in unregister_mad_agent()
508 wait_for_completion(&mad_agent_priv->comp); in unregister_mad_agent()
511 ib_mad_agent_security_cleanup(&mad_agent_priv->agent); in unregister_mad_agent()
513 kfree(mad_agent_priv->reg_req); in unregister_mad_agent()
518 * ib_unregister_mad_agent - Unregisters a client from using MAD services
538 mad_queue = mad_list->mad_queue; in dequeue_mad()
539 spin_lock_irqsave(&mad_queue->lock, flags); in dequeue_mad()
540 list_del(&mad_list->list); in dequeue_mad()
541 mad_queue->count--; in dequeue_mad()
542 spin_unlock_irqrestore(&mad_queue->lock, flags); in dequeue_mad()
549 wc->wr_cqe = cqe; in build_smp_wc()
550 wc->status = IB_WC_SUCCESS; in build_smp_wc()
551 wc->opcode = IB_WC_RECV; in build_smp_wc()
552 wc->pkey_index = pkey_index; in build_smp_wc()
553 wc->byte_len = sizeof(struct ib_mad) + sizeof(struct ib_grh); in build_smp_wc()
554 wc->src_qp = IB_QP0; in build_smp_wc()
555 wc->qp = qp; in build_smp_wc()
556 wc->slid = slid; in build_smp_wc()
557 wc->sl = 0; in build_smp_wc()
558 wc->dlid_path_bits = 0; in build_smp_wc()
559 wc->port_num = port_num; in build_smp_wc()
564 return sizeof(struct ib_mad_private) + mp->mad_size; in mad_priv_size()
573 ret->mad_size = mad_size; in alloc_mad_private()
580 return rdma_max_mad_size(port_priv->device, port_priv->port_num); in port_mad_size()
585 return sizeof(struct ib_grh) + mp->mad_size; in mad_priv_dma_size()
597 struct ib_smp *smp = mad_send_wr->send_buf.mad; in handle_outgoing_dr_smp()
604 struct ib_device *device = mad_agent_priv->agent.device; in handle_outgoing_dr_smp()
607 struct ib_ud_wr *send_wr = &mad_send_wr->send_wr; in handle_outgoing_dr_smp()
608 size_t mad_size = port_mad_size(mad_agent_priv->qp_info->port_priv); in handle_outgoing_dr_smp()
611 bool opa = rdma_cap_opa_mad(mad_agent_priv->qp_info->port_priv->device, in handle_outgoing_dr_smp()
612 mad_agent_priv->qp_info->port_priv->port_num); in handle_outgoing_dr_smp()
615 smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) in handle_outgoing_dr_smp()
616 port_num = send_wr->port_num; in handle_outgoing_dr_smp()
618 port_num = mad_agent_priv->agent.port_num; in handle_outgoing_dr_smp()
626 if (opa && smp->class_version == OPA_SM_CLASS_VERSION) { in handle_outgoing_dr_smp()
632 ? opa_smp->route.dr.dr_dlid : opa_smp->route.dr.dr_slid) == in handle_outgoing_dr_smp()
637 ret = -EINVAL; in handle_outgoing_dr_smp()
638 dev_err(&device->dev, "OPA Invalid directed route\n"); in handle_outgoing_dr_smp()
641 opa_drslid = be32_to_cpu(opa_smp->route.dr.dr_slid); in handle_outgoing_dr_smp()
644 ret = -EINVAL; in handle_outgoing_dr_smp()
645 dev_err(&device->dev, "OPA Invalid dr_slid 0x%x\n", in handle_outgoing_dr_smp()
658 if ((ib_get_smp_direction(smp) ? smp->dr_dlid : smp->dr_slid) == in handle_outgoing_dr_smp()
662 ret = -EINVAL; in handle_outgoing_dr_smp()
663 dev_err(&device->dev, "Invalid directed route\n"); in handle_outgoing_dr_smp()
666 drslid = be16_to_cpu(smp->dr_slid); in handle_outgoing_dr_smp()
676 ret = -ENOMEM; in handle_outgoing_dr_smp()
679 local->mad_priv = NULL; in handle_outgoing_dr_smp()
680 local->recv_mad_agent = NULL; in handle_outgoing_dr_smp()
683 ret = -ENOMEM; in handle_outgoing_dr_smp()
688 build_smp_wc(mad_agent_priv->agent.qp, in handle_outgoing_dr_smp()
689 send_wr->wr.wr_cqe, drslid, in handle_outgoing_dr_smp()
690 send_wr->pkey_index, in handle_outgoing_dr_smp()
691 send_wr->port_num, &mad_wc); in handle_outgoing_dr_smp()
693 if (opa && smp->base_version == OPA_MGMT_BASE_VERSION) { in handle_outgoing_dr_smp()
694 mad_wc.byte_len = mad_send_wr->send_buf.hdr_len in handle_outgoing_dr_smp()
695 + mad_send_wr->send_buf.data_len in handle_outgoing_dr_smp()
700 ret = device->ops.process_mad(device, 0, port_num, &mad_wc, NULL, in handle_outgoing_dr_smp()
702 (struct ib_mad *)mad_priv->mad, &mad_size, in handle_outgoing_dr_smp()
706 if (ib_response_mad((const struct ib_mad_hdr *)mad_priv->mad) && in handle_outgoing_dr_smp()
707 mad_agent_priv->agent.recv_handler) { in handle_outgoing_dr_smp()
708 local->mad_priv = mad_priv; in handle_outgoing_dr_smp()
709 local->recv_mad_agent = mad_agent_priv; in handle_outgoing_dr_smp()
714 refcount_inc(&mad_agent_priv->refcount); in handle_outgoing_dr_smp()
723 port_priv = ib_get_mad_port(mad_agent_priv->agent.device, in handle_outgoing_dr_smp()
724 mad_agent_priv->agent.port_num); in handle_outgoing_dr_smp()
726 memcpy(mad_priv->mad, smp, mad_priv->mad_size); in handle_outgoing_dr_smp()
728 (const struct ib_mad_hdr *)mad_priv->mad); in handle_outgoing_dr_smp()
738 local->mad_priv = mad_priv; in handle_outgoing_dr_smp()
739 local->recv_mad_agent = recv_mad_agent; in handle_outgoing_dr_smp()
744 ret = -EINVAL; in handle_outgoing_dr_smp()
748 local->mad_send_wr = mad_send_wr; in handle_outgoing_dr_smp()
750 local->mad_send_wr->send_wr.pkey_index = out_mad_pkey_index; in handle_outgoing_dr_smp()
751 local->return_wc_byte_len = mad_size; in handle_outgoing_dr_smp()
754 refcount_inc(&mad_agent_priv->refcount); in handle_outgoing_dr_smp()
756 spin_lock_irqsave(&mad_agent_priv->lock, flags); in handle_outgoing_dr_smp()
757 list_add_tail(&local->completion_list, &mad_agent_priv->local_list); in handle_outgoing_dr_smp()
758 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); in handle_outgoing_dr_smp()
759 queue_work(mad_agent_priv->qp_info->port_priv->wq, in handle_outgoing_dr_smp()
760 &mad_agent_priv->local_work); in handle_outgoing_dr_smp()
770 seg_size = mad_size - hdr_len; in get_pad_size()
772 pad = seg_size - data_len % seg_size; in get_pad_size()
782 list_for_each_entry_safe(s, t, &mad_send_wr->rmpp_list, list) { in free_send_rmpp_list()
783 list_del(&s->list); in free_send_rmpp_list()
791 struct ib_mad_send_buf *send_buf = &send_wr->send_buf; in alloc_send_rmpp_list()
792 struct ib_rmpp_mad *rmpp_mad = send_buf->mad; in alloc_send_rmpp_list()
796 send_buf->seg_size = mad_size - send_buf->hdr_len; in alloc_send_rmpp_list()
797 send_buf->seg_rmpp_size = mad_size - IB_MGMT_RMPP_HDR; in alloc_send_rmpp_list()
798 seg_size = send_buf->seg_size; in alloc_send_rmpp_list()
799 pad = send_wr->pad; in alloc_send_rmpp_list()
802 for (left = send_buf->data_len + pad; left > 0; left -= seg_size) { in alloc_send_rmpp_list()
806 return -ENOMEM; in alloc_send_rmpp_list()
808 seg->num = ++send_buf->seg_count; in alloc_send_rmpp_list()
809 list_add_tail(&seg->list, &send_wr->rmpp_list); in alloc_send_rmpp_list()
814 memset(seg->data + seg_size - pad, 0, pad); in alloc_send_rmpp_list()
816 rmpp_mad->rmpp_hdr.rmpp_version = send_wr->mad_agent_priv-> in alloc_send_rmpp_list()
818 rmpp_mad->rmpp_hdr.rmpp_type = IB_MGMT_RMPP_TYPE_DATA; in alloc_send_rmpp_list()
819 ib_set_rmpp_flags(&rmpp_mad->rmpp_hdr, IB_MGMT_RMPP_FLAG_ACTIVE); in alloc_send_rmpp_list()
821 send_wr->cur_seg = container_of(send_wr->rmpp_list.next, in alloc_send_rmpp_list()
823 send_wr->last_ack_seg = send_wr->cur_seg; in alloc_send_rmpp_list()
829 return agent->rmpp_version && !(agent->flags & IB_MAD_USER_RMPP); in ib_mad_kernel_rmpp_agent()
849 opa = rdma_cap_opa_mad(mad_agent->device, mad_agent->port_num); in ib_create_send_mad()
861 return ERR_PTR(-EINVAL); in ib_create_send_mad()
864 return ERR_PTR(-EINVAL); in ib_create_send_mad()
869 return ERR_PTR(-ENOMEM); in ib_create_send_mad()
872 INIT_LIST_HEAD(&mad_send_wr->rmpp_list); in ib_create_send_mad()
873 mad_send_wr->send_buf.mad = buf; in ib_create_send_mad()
874 mad_send_wr->send_buf.hdr_len = hdr_len; in ib_create_send_mad()
875 mad_send_wr->send_buf.data_len = data_len; in ib_create_send_mad()
876 mad_send_wr->pad = pad; in ib_create_send_mad()
878 mad_send_wr->mad_agent_priv = mad_agent_priv; in ib_create_send_mad()
879 mad_send_wr->sg_list[0].length = hdr_len; in ib_create_send_mad()
880 mad_send_wr->sg_list[0].lkey = mad_agent->qp->pd->local_dma_lkey; in ib_create_send_mad()
884 data_len < mad_size - hdr_len) in ib_create_send_mad()
885 mad_send_wr->sg_list[1].length = data_len; in ib_create_send_mad()
887 mad_send_wr->sg_list[1].length = mad_size - hdr_len; in ib_create_send_mad()
889 mad_send_wr->sg_list[1].lkey = mad_agent->qp->pd->local_dma_lkey; in ib_create_send_mad()
891 mad_send_wr->mad_list.cqe.done = ib_mad_send_done; in ib_create_send_mad()
893 mad_send_wr->send_wr.wr.wr_cqe = &mad_send_wr->mad_list.cqe; in ib_create_send_mad()
894 mad_send_wr->send_wr.wr.sg_list = mad_send_wr->sg_list; in ib_create_send_mad()
895 mad_send_wr->send_wr.wr.num_sge = 2; in ib_create_send_mad()
896 mad_send_wr->send_wr.wr.opcode = IB_WR_SEND; in ib_create_send_mad()
897 mad_send_wr->send_wr.wr.send_flags = IB_SEND_SIGNALED; in ib_create_send_mad()
898 mad_send_wr->send_wr.remote_qpn = remote_qpn; in ib_create_send_mad()
899 mad_send_wr->send_wr.remote_qkey = IB_QP_SET_QKEY; in ib_create_send_mad()
900 mad_send_wr->send_wr.pkey_index = pkey_index; in ib_create_send_mad()
910 mad_send_wr->send_buf.mad_agent = mad_agent; in ib_create_send_mad()
911 refcount_inc(&mad_agent_priv->refcount); in ib_create_send_mad()
912 return &mad_send_wr->send_buf; in ib_create_send_mad()
952 list = &mad_send_wr->cur_seg->list; in ib_get_rmpp_segment()
954 if (mad_send_wr->cur_seg->num < seg_num) { in ib_get_rmpp_segment()
955 list_for_each_entry(mad_send_wr->cur_seg, list, list) in ib_get_rmpp_segment()
956 if (mad_send_wr->cur_seg->num == seg_num) in ib_get_rmpp_segment()
958 } else if (mad_send_wr->cur_seg->num > seg_num) { in ib_get_rmpp_segment()
959 list_for_each_entry_reverse(mad_send_wr->cur_seg, list, list) in ib_get_rmpp_segment()
960 if (mad_send_wr->cur_seg->num == seg_num) in ib_get_rmpp_segment()
963 return mad_send_wr->cur_seg->data; in ib_get_rmpp_segment()
969 if (mad_send_wr->send_buf.seg_count) in ib_get_payload()
970 return ib_get_rmpp_segment(&mad_send_wr->send_buf, in ib_get_payload()
971 mad_send_wr->seg_num); in ib_get_payload()
973 return mad_send_wr->send_buf.mad + in ib_get_payload()
974 mad_send_wr->send_buf.hdr_len; in ib_get_payload()
982 mad_agent_priv = container_of(send_buf->mad_agent, in ib_free_send_mad()
988 kfree(send_buf->mad); in ib_free_send_mad()
1003 qp_info = mad_send_wr->mad_agent_priv->qp_info; in ib_send_mad()
1004 mad_send_wr->mad_list.mad_queue = &qp_info->send_queue; in ib_send_mad()
1005 mad_send_wr->mad_list.cqe.done = ib_mad_send_done; in ib_send_mad()
1006 mad_send_wr->send_wr.wr.wr_cqe = &mad_send_wr->mad_list.cqe; in ib_send_mad()
1008 mad_agent = mad_send_wr->send_buf.mad_agent; in ib_send_mad()
1009 sge = mad_send_wr->sg_list; in ib_send_mad()
1010 sge[0].addr = ib_dma_map_single(mad_agent->device, in ib_send_mad()
1011 mad_send_wr->send_buf.mad, in ib_send_mad()
1014 if (unlikely(ib_dma_mapping_error(mad_agent->device, sge[0].addr))) in ib_send_mad()
1015 return -ENOMEM; in ib_send_mad()
1017 mad_send_wr->header_mapping = sge[0].addr; in ib_send_mad()
1019 sge[1].addr = ib_dma_map_single(mad_agent->device, in ib_send_mad()
1023 if (unlikely(ib_dma_mapping_error(mad_agent->device, sge[1].addr))) { in ib_send_mad()
1024 ib_dma_unmap_single(mad_agent->device, in ib_send_mad()
1025 mad_send_wr->header_mapping, in ib_send_mad()
1027 return -ENOMEM; in ib_send_mad()
1029 mad_send_wr->payload_mapping = sge[1].addr; in ib_send_mad()
1031 spin_lock_irqsave(&qp_info->send_queue.lock, flags); in ib_send_mad()
1032 if (qp_info->send_queue.count < qp_info->send_queue.max_active) { in ib_send_mad()
1034 ret = ib_post_send(mad_agent->qp, &mad_send_wr->send_wr.wr, in ib_send_mad()
1036 list = &qp_info->send_queue.list; in ib_send_mad()
1039 list = &qp_info->overflow_list; in ib_send_mad()
1043 qp_info->send_queue.count++; in ib_send_mad()
1044 list_add_tail(&mad_send_wr->mad_list.list, list); in ib_send_mad()
1046 spin_unlock_irqrestore(&qp_info->send_queue.lock, flags); in ib_send_mad()
1048 ib_dma_unmap_single(mad_agent->device, in ib_send_mad()
1049 mad_send_wr->header_mapping, in ib_send_mad()
1051 ib_dma_unmap_single(mad_agent->device, in ib_send_mad()
1052 mad_send_wr->payload_mapping, in ib_send_mad()
1059 * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated
1069 int ret = -EINVAL; in ib_post_send_mad()
1076 mad_agent_priv = mad_send_wr->mad_agent_priv; in ib_post_send_mad()
1079 mad_send_wr->send_wr.pkey_index); in ib_post_send_mad()
1083 if (!send_buf->mad_agent->send_handler || in ib_post_send_mad()
1084 (send_buf->timeout_ms && in ib_post_send_mad()
1085 !send_buf->mad_agent->recv_handler)) { in ib_post_send_mad()
1086 ret = -EINVAL; in ib_post_send_mad()
1090 if (!ib_is_mad_class_rmpp(((struct ib_mad_hdr *) send_buf->mad)->mgmt_class)) { in ib_post_send_mad()
1091 if (mad_agent_priv->agent.rmpp_version) { in ib_post_send_mad()
1092 ret = -EINVAL; in ib_post_send_mad()
1102 next_send_buf = send_buf->next; in ib_post_send_mad()
1103 mad_send_wr->send_wr.ah = send_buf->ah; in ib_post_send_mad()
1105 if (((struct ib_mad_hdr *) send_buf->mad)->mgmt_class == in ib_post_send_mad()
1115 mad_send_wr->tid = ((struct ib_mad_hdr *) send_buf->mad)->tid; in ib_post_send_mad()
1117 mad_send_wr->timeout = msecs_to_jiffies(send_buf->timeout_ms); in ib_post_send_mad()
1118 mad_send_wr->max_retries = send_buf->retries; in ib_post_send_mad()
1119 mad_send_wr->retries_left = send_buf->retries; in ib_post_send_mad()
1120 send_buf->retries = 0; in ib_post_send_mad()
1122 mad_send_wr->refcount = 1 + (mad_send_wr->timeout > 0); in ib_post_send_mad()
1123 mad_send_wr->status = IB_WC_SUCCESS; in ib_post_send_mad()
1126 refcount_inc(&mad_agent_priv->refcount); in ib_post_send_mad()
1127 spin_lock_irqsave(&mad_agent_priv->lock, flags); in ib_post_send_mad()
1128 list_add_tail(&mad_send_wr->agent_list, in ib_post_send_mad()
1129 &mad_agent_priv->send_list); in ib_post_send_mad()
1130 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); in ib_post_send_mad()
1132 if (ib_mad_kernel_rmpp_agent(&mad_agent_priv->agent)) { in ib_post_send_mad()
1140 spin_lock_irqsave(&mad_agent_priv->lock, flags); in ib_post_send_mad()
1141 list_del(&mad_send_wr->agent_list); in ib_post_send_mad()
1142 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); in ib_post_send_mad()
1156 * ib_free_recv_mad - Returns data buffers used to receive
1167 list_splice_init(&mad_recv_wc->rmpp_list, &free_list); in ib_free_recv_mad()
1183 static int method_in_use(struct ib_mad_mgmt_method_table **method, in method_in_use() argument
1188 for_each_set_bit(i, mad_reg_req->method_mask, IB_MGMT_MAX_METHODS) { in method_in_use()
1189 if ((*method)->agent[i]) { in method_in_use()
1190 pr_err("Method %d already in use\n", i); in method_in_use()
1191 return -EINVAL; in method_in_use()
1197 static int allocate_method_table(struct ib_mad_mgmt_method_table **method) in allocate_method_table() argument
1199 /* Allocate management method table */ in allocate_method_table()
1200 *method = kzalloc(sizeof **method, GFP_ATOMIC); in allocate_method_table()
1201 return (*method) ? 0 : (-ENOMEM); in allocate_method_table()
1207 static int check_method_table(struct ib_mad_mgmt_method_table *method) in check_method_table() argument
1212 if (method->agent[i]) in check_method_table()
1218 * Check to see if there are any method tables for this class still in use
1225 if (class->method_table[i]) in check_class_table()
1235 if (vendor_class->method_table[i]) in check_vendor_class()
1247 if (!memcmp(vendor_class->oui[i], oui, 3)) in find_vendor_oui()
1250 return -1; in find_vendor_oui()
1258 if (vendor->vendor_class[i]) in check_vendor_table()
1264 static void remove_methods_mad_agent(struct ib_mad_mgmt_method_table *method, in remove_methods_mad_agent() argument
1271 if (method->agent[i] == agent) in remove_methods_mad_agent()
1272 method->agent[i] = NULL; in remove_methods_mad_agent()
1281 struct ib_mad_mgmt_method_table **method; in add_nonoui_reg_req() local
1284 port_priv = agent_priv->qp_info->port_priv; in add_nonoui_reg_req()
1285 class = &port_priv->version[mad_reg_req->mgmt_class_version].class; in add_nonoui_reg_req()
1290 ret = -ENOMEM; in add_nonoui_reg_req()
1294 /* Allocate method table for this management class */ in add_nonoui_reg_req()
1295 method = &(*class)->method_table[mgmt_class]; in add_nonoui_reg_req()
1296 if ((ret = allocate_method_table(method))) in add_nonoui_reg_req()
1299 method = &(*class)->method_table[mgmt_class]; in add_nonoui_reg_req()
1300 if (!*method) { in add_nonoui_reg_req()
1301 /* Allocate method table for this management class */ in add_nonoui_reg_req()
1302 if ((ret = allocate_method_table(method))) in add_nonoui_reg_req()
1308 if (method_in_use(method, mad_reg_req)) in add_nonoui_reg_req()
1312 for_each_set_bit(i, mad_reg_req->method_mask, IB_MGMT_MAX_METHODS) in add_nonoui_reg_req()
1313 (*method)->agent[i] = agent_priv; in add_nonoui_reg_req()
1319 remove_methods_mad_agent(*method, agent_priv); in add_nonoui_reg_req()
1321 if (!check_method_table(*method)) { in add_nonoui_reg_req()
1322 /* If not, release management method table */ in add_nonoui_reg_req()
1323 kfree(*method); in add_nonoui_reg_req()
1324 *method = NULL; in add_nonoui_reg_req()
1326 ret = -EINVAL; in add_nonoui_reg_req()
1342 struct ib_mad_mgmt_method_table **method; in add_oui_reg_req() local
1343 int i, ret = -ENOMEM; in add_oui_reg_req()
1347 vclass = vendor_class_index(mad_reg_req->mgmt_class); in add_oui_reg_req()
1348 port_priv = agent_priv->qp_info->port_priv; in add_oui_reg_req()
1349 vendor_table = &port_priv->version[ in add_oui_reg_req()
1350 mad_reg_req->mgmt_class_version].vendor; in add_oui_reg_req()
1359 if (!(*vendor_table)->vendor_class[vclass]) { in add_oui_reg_req()
1365 (*vendor_table)->vendor_class[vclass] = vendor_class; in add_oui_reg_req()
1369 if (!memcmp((*vendor_table)->vendor_class[vclass]->oui[i], in add_oui_reg_req()
1370 mad_reg_req->oui, 3)) { in add_oui_reg_req()
1371 method = &(*vendor_table)->vendor_class[ in add_oui_reg_req()
1372 vclass]->method_table[i]; in add_oui_reg_req()
1373 if (!*method) in add_oui_reg_req()
1380 if (!is_vendor_oui((*vendor_table)->vendor_class[ in add_oui_reg_req()
1381 vclass]->oui[i])) { in add_oui_reg_req()
1382 method = &(*vendor_table)->vendor_class[ in add_oui_reg_req()
1383 vclass]->method_table[i]; in add_oui_reg_req()
1384 /* Allocate method table for this OUI */ in add_oui_reg_req()
1385 if (!*method) { in add_oui_reg_req()
1386 ret = allocate_method_table(method); in add_oui_reg_req()
1390 memcpy((*vendor_table)->vendor_class[vclass]->oui[i], in add_oui_reg_req()
1391 mad_reg_req->oui, 3); in add_oui_reg_req()
1395 dev_err(&agent_priv->agent.device->dev, "All OUI slots in use\n"); in add_oui_reg_req()
1400 if (method_in_use(method, mad_reg_req)) in add_oui_reg_req()
1404 for_each_set_bit(i, mad_reg_req->method_mask, IB_MGMT_MAX_METHODS) in add_oui_reg_req()
1405 (*method)->agent[i] = agent_priv; in add_oui_reg_req()
1411 remove_methods_mad_agent(*method, agent_priv); in add_oui_reg_req()
1413 if (!check_method_table(*method)) { in add_oui_reg_req()
1414 /* If not, release management method table */ in add_oui_reg_req()
1415 kfree(*method); in add_oui_reg_req()
1416 *method = NULL; in add_oui_reg_req()
1418 ret = -EINVAL; in add_oui_reg_req()
1421 (*vendor_table)->vendor_class[vclass] = NULL; in add_oui_reg_req()
1437 struct ib_mad_mgmt_method_table *method; in remove_mad_reg_req() local
1447 if (!agent_priv->reg_req) in remove_mad_reg_req()
1450 port_priv = agent_priv->qp_info->port_priv; in remove_mad_reg_req()
1451 mgmt_class = convert_mgmt_class(agent_priv->reg_req->mgmt_class); in remove_mad_reg_req()
1452 class = port_priv->version[ in remove_mad_reg_req()
1453 agent_priv->reg_req->mgmt_class_version].class; in remove_mad_reg_req()
1457 method = class->method_table[mgmt_class]; in remove_mad_reg_req()
1458 if (method) { in remove_mad_reg_req()
1460 remove_methods_mad_agent(method, agent_priv); in remove_mad_reg_req()
1462 if (!check_method_table(method)) { in remove_mad_reg_req()
1463 /* If not, release management method table */ in remove_mad_reg_req()
1464 kfree(method); in remove_mad_reg_req()
1465 class->method_table[mgmt_class] = NULL; in remove_mad_reg_req()
1470 port_priv->version[ in remove_mad_reg_req()
1471 agent_priv->reg_req-> in remove_mad_reg_req()
1482 mgmt_class = vendor_class_index(agent_priv->reg_req->mgmt_class); in remove_mad_reg_req()
1483 vendor = port_priv->version[ in remove_mad_reg_req()
1484 agent_priv->reg_req->mgmt_class_version].vendor; in remove_mad_reg_req()
1489 vendor_class = vendor->vendor_class[mgmt_class]; in remove_mad_reg_req()
1491 index = find_vendor_oui(vendor_class, agent_priv->reg_req->oui); in remove_mad_reg_req()
1494 method = vendor_class->method_table[index]; in remove_mad_reg_req()
1495 if (method) { in remove_mad_reg_req()
1497 remove_methods_mad_agent(method, agent_priv); in remove_mad_reg_req()
1502 if (!check_method_table(method)) { in remove_mad_reg_req()
1503 /* If not, release management method table */ in remove_mad_reg_req()
1504 kfree(method); in remove_mad_reg_req()
1505 vendor_class->method_table[index] = NULL; in remove_mad_reg_req()
1506 memset(vendor_class->oui[index], 0, 3); in remove_mad_reg_req()
1511 vendor->vendor_class[mgmt_class] = NULL; in remove_mad_reg_req()
1515 port_priv->version[ in remove_mad_reg_req()
1516 agent_priv->reg_req-> in remove_mad_reg_req()
1543 hi_tid = be64_to_cpu(mad_hdr->tid) >> 32; in find_mad_agent()
1546 if (mad_agent && !refcount_inc_not_zero(&mad_agent->refcount)) in find_mad_agent()
1551 struct ib_mad_mgmt_method_table *method; in find_mad_agent() local
1557 spin_lock_irqsave(&port_priv->reg_lock, flags); in find_mad_agent()
1559 * Routing is based on version, class, and method in find_mad_agent()
1562 if (mad_hdr->class_version >= MAX_MGMT_VERSION) in find_mad_agent()
1564 if (!is_vendor_class(mad_hdr->mgmt_class)) { in find_mad_agent()
1565 class = port_priv->version[ in find_mad_agent()
1566 mad_hdr->class_version].class; in find_mad_agent()
1569 if (convert_mgmt_class(mad_hdr->mgmt_class) >= in find_mad_agent()
1570 ARRAY_SIZE(class->method_table)) in find_mad_agent()
1572 method = class->method_table[convert_mgmt_class( in find_mad_agent()
1573 mad_hdr->mgmt_class)]; in find_mad_agent()
1574 if (method) in find_mad_agent()
1575 mad_agent = method->agent[mad_hdr->method & in find_mad_agent()
1578 vendor = port_priv->version[ in find_mad_agent()
1579 mad_hdr->class_version].vendor; in find_mad_agent()
1582 vendor_class = vendor->vendor_class[vendor_class_index( in find_mad_agent()
1583 mad_hdr->mgmt_class)]; in find_mad_agent()
1588 index = find_vendor_oui(vendor_class, vendor_mad->oui); in find_mad_agent()
1589 if (index == -1) in find_mad_agent()
1591 method = vendor_class->method_table[index]; in find_mad_agent()
1592 if (method) { in find_mad_agent()
1593 mad_agent = method->agent[mad_hdr->method & in find_mad_agent()
1598 refcount_inc(&mad_agent->refcount); in find_mad_agent()
1600 spin_unlock_irqrestore(&port_priv->reg_lock, flags); in find_mad_agent()
1603 if (mad_agent && !mad_agent->agent.recv_handler) { in find_mad_agent()
1604 dev_notice(&port_priv->device->dev, in find_mad_agent()
1606 &mad_agent->agent, port_priv->port_num); in find_mad_agent()
1619 u32 qp_num = qp_info->qp->qp_num; in validate_mad()
1622 if (mad_hdr->base_version != IB_MGMT_BASE_VERSION && in validate_mad()
1623 (!opa || mad_hdr->base_version != OPA_MGMT_BASE_VERSION)) { in validate_mad()
1625 mad_hdr->base_version, opa ? "(opa)" : ""); in validate_mad()
1630 if ((mad_hdr->mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED) || in validate_mad()
1631 (mad_hdr->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)) { in validate_mad()
1635 /* CM attributes other than ClassPortInfo only use Send method */ in validate_mad()
1636 if ((mad_hdr->mgmt_class == IB_MGMT_CLASS_CM) && in validate_mad()
1637 (mad_hdr->attr_id != IB_MGMT_CLASSPORTINFO_ATTR_ID) && in validate_mad()
1638 (mad_hdr->method != IB_MGMT_METHOD_SEND)) in validate_mad()
1655 return !mad_agent_priv->agent.rmpp_version || in is_rmpp_data_mad()
1656 !ib_mad_kernel_rmpp_agent(&mad_agent_priv->agent) || in is_rmpp_data_mad()
1657 !(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) & in is_rmpp_data_mad()
1659 (rmpp_mad->rmpp_hdr.rmpp_type == IB_MGMT_RMPP_TYPE_DATA); in is_rmpp_data_mad()
1665 return ((struct ib_mad_hdr *)(wr->send_buf.mad))->mgmt_class == in rcv_has_same_class()
1666 rwc->recv_buf.mad->mad_hdr.mgmt_class; in rcv_has_same_class()
1677 struct ib_device *device = mad_agent_priv->agent.device; in rcv_has_same_gid()
1678 u32 port_num = mad_agent_priv->agent.port_num; in rcv_has_same_gid()
1682 send_resp = ib_response_mad((struct ib_mad_hdr *)wr->send_buf.mad); in rcv_has_same_gid()
1683 rcv_resp = ib_response_mad(&rwc->recv_buf.mad->mad_hdr); in rcv_has_same_gid()
1689 if (rdma_query_ah(wr->send_buf.ah, &attr)) in rcv_has_same_gid()
1694 if (has_grh != !!(rwc->wc->wc_flags & IB_WC_GRH)) in rcv_has_same_gid()
1704 rwc->wc->dlid_path_bits) & in rcv_has_same_gid()
1705 ((1 << lmc) - 1))); in rcv_has_same_gid()
1711 grh->sgid_index, &sgid)) in rcv_has_same_gid()
1713 return !memcmp(sgid.raw, rwc->recv_buf.grh->dgid.raw, in rcv_has_same_gid()
1719 return rdma_ah_get_dlid(&attr) == rwc->wc->slid; in rcv_has_same_gid()
1721 return !memcmp(rdma_ah_read_grh(&attr)->dgid.raw, in rcv_has_same_gid()
1722 rwc->recv_buf.grh->sgid.raw, in rcv_has_same_gid()
1738 mad_hdr = &wc->recv_buf.mad->mad_hdr; in ib_find_send_mad()
1740 list_for_each_entry(wr, &mad_agent_priv->wait_list, agent_list) { in ib_find_send_mad()
1741 if ((wr->tid == mad_hdr->tid) && in ib_find_send_mad()
1747 (is_direct(mad_hdr->mgmt_class) || in ib_find_send_mad()
1749 return (wr->status == IB_WC_SUCCESS) ? wr : NULL; in ib_find_send_mad()
1756 list_for_each_entry(wr, &mad_agent_priv->send_list, agent_list) { in ib_find_send_mad()
1757 if (is_rmpp_data_mad(mad_agent_priv, wr->send_buf.mad) && in ib_find_send_mad()
1758 wr->tid == mad_hdr->tid && in ib_find_send_mad()
1759 wr->timeout && in ib_find_send_mad()
1765 (is_direct(mad_hdr->mgmt_class) || in ib_find_send_mad()
1768 return (wr->status == IB_WC_SUCCESS) ? wr : NULL; in ib_find_send_mad()
1775 mad_send_wr->timeout = 0; in ib_mark_mad_done()
1776 if (mad_send_wr->refcount == 1) in ib_mark_mad_done()
1777 list_move_tail(&mad_send_wr->agent_list, in ib_mark_mad_done()
1778 &mad_send_wr->mad_agent_priv->done_list); in ib_mark_mad_done()
1789 INIT_LIST_HEAD(&mad_recv_wc->rmpp_list); in ib_mad_complete_recv()
1791 mad_recv_wc->wc->pkey_index); in ib_mad_complete_recv()
1798 list_add(&mad_recv_wc->recv_buf.list, &mad_recv_wc->rmpp_list); in ib_mad_complete_recv()
1799 if (ib_mad_kernel_rmpp_agent(&mad_agent_priv->agent)) { in ib_mad_complete_recv()
1809 if (ib_response_mad(&mad_recv_wc->recv_buf.mad->mad_hdr)) { in ib_mad_complete_recv()
1810 spin_lock_irqsave(&mad_agent_priv->lock, flags); in ib_mad_complete_recv()
1813 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); in ib_mad_complete_recv()
1814 if (!ib_mad_kernel_rmpp_agent(&mad_agent_priv->agent) in ib_mad_complete_recv()
1815 && ib_is_mad_class_rmpp(mad_recv_wc->recv_buf.mad->mad_hdr.mgmt_class) in ib_mad_complete_recv()
1816 && (ib_get_rmpp_flags(&((struct ib_rmpp_mad *)mad_recv_wc->recv_buf.mad)->rmpp_hdr) in ib_mad_complete_recv()
1821 mad_agent_priv->agent.recv_handler( in ib_mad_complete_recv()
1822 &mad_agent_priv->agent, NULL, in ib_mad_complete_recv()
1835 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); in ib_mad_complete_recv()
1838 mad_agent_priv->agent.recv_handler( in ib_mad_complete_recv()
1839 &mad_agent_priv->agent, in ib_mad_complete_recv()
1840 &mad_send_wr->send_buf, in ib_mad_complete_recv()
1846 mad_send_wc.send_buf = &mad_send_wr->send_buf; in ib_mad_complete_recv()
1850 mad_agent_priv->agent.recv_handler(&mad_agent_priv->agent, NULL, in ib_mad_complete_recv()
1864 struct ib_smp *smp = (struct ib_smp *)recv->mad; in handle_ib_smi()
1869 rdma_cap_ib_switch(port_priv->device), in handle_ib_smi()
1871 port_priv->device->phys_port_cnt) == in handle_ib_smi()
1881 rdma_cap_ib_switch(port_priv->device), in handle_ib_smi()
1885 if (smi_check_local_smp(smp, port_priv->device) == IB_SMI_DISCARD) in handle_ib_smi()
1887 } else if (rdma_cap_ib_switch(port_priv->device)) { in handle_ib_smi()
1890 response->header.recv_wc.wc = &response->header.wc; in handle_ib_smi()
1891 response->header.recv_wc.recv_buf.mad = (struct ib_mad *)response->mad; in handle_ib_smi()
1892 response->header.recv_wc.recv_buf.grh = &response->grh; in handle_ib_smi()
1894 agent_send_response((const struct ib_mad_hdr *)response->mad, in handle_ib_smi()
1895 &response->grh, wc, in handle_ib_smi()
1896 port_priv->device, in handle_ib_smi()
1898 qp_info->qp->qp_num, in handle_ib_smi()
1899 response->mad_size, in handle_ib_smi()
1911 const struct ib_mad_hdr *recv_hdr = (const struct ib_mad_hdr *)recv->mad; in generate_unmatched_resp()
1912 struct ib_mad_hdr *resp_hdr = (struct ib_mad_hdr *)response->mad; in generate_unmatched_resp()
1914 if (recv_hdr->method == IB_MGMT_METHOD_GET || in generate_unmatched_resp()
1915 recv_hdr->method == IB_MGMT_METHOD_SET) { in generate_unmatched_resp()
1917 response->header.recv_wc.wc = &response->header.wc; in generate_unmatched_resp()
1918 response->header.recv_wc.recv_buf.mad = (struct ib_mad *)response->mad; in generate_unmatched_resp()
1919 response->header.recv_wc.recv_buf.grh = &response->grh; in generate_unmatched_resp()
1920 resp_hdr->method = IB_MGMT_METHOD_GET_RESP; in generate_unmatched_resp()
1921 resp_hdr->status = cpu_to_be16(IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD_ATTRIB); in generate_unmatched_resp()
1922 if (recv_hdr->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) in generate_unmatched_resp()
1923 resp_hdr->status |= IB_SMP_DIRECTION; in generate_unmatched_resp()
1925 if (opa && recv_hdr->base_version == OPA_MGMT_BASE_VERSION) { in generate_unmatched_resp()
1926 if (recv_hdr->mgmt_class == in generate_unmatched_resp()
1928 recv_hdr->mgmt_class == in generate_unmatched_resp()
1931 (struct opa_smp *)recv->mad); in generate_unmatched_resp()
1951 struct opa_smp *smp = (struct opa_smp *)recv->mad; in handle_opa_smi()
1956 rdma_cap_ib_switch(port_priv->device), in handle_opa_smi()
1958 port_priv->device->phys_port_cnt) == in handle_opa_smi()
1968 rdma_cap_ib_switch(port_priv->device), in handle_opa_smi()
1972 if (opa_smi_check_local_smp(smp, port_priv->device) == in handle_opa_smi()
1976 } else if (rdma_cap_ib_switch(port_priv->device)) { in handle_opa_smi()
1979 response->header.recv_wc.wc = &response->header.wc; in handle_opa_smi()
1980 response->header.recv_wc.recv_buf.opa_mad = in handle_opa_smi()
1981 (struct opa_mad *)response->mad; in handle_opa_smi()
1982 response->header.recv_wc.recv_buf.grh = &response->grh; in handle_opa_smi()
1984 agent_send_response((const struct ib_mad_hdr *)response->mad, in handle_opa_smi()
1985 &response->grh, wc, in handle_opa_smi()
1986 port_priv->device, in handle_opa_smi()
1988 qp_info->qp->qp_num, in handle_opa_smi()
1989 recv->header.wc.byte_len, in handle_opa_smi()
2007 struct ib_mad_hdr *mad_hdr = (struct ib_mad_hdr *)recv->mad; in handle_smi()
2009 if (opa && mad_hdr->base_version == OPA_MGMT_BASE_VERSION && in handle_smi()
2010 mad_hdr->class_version == OPA_SM_CLASS_VERSION) in handle_smi()
2019 struct ib_mad_port_private *port_priv = cq->cq_context; in ib_mad_recv_done()
2021 container_of(wc->wr_cqe, struct ib_mad_list_head, cqe); in ib_mad_recv_done()
2032 if (list_empty_careful(&port_priv->port_list)) in ib_mad_recv_done()
2035 if (wc->status != IB_WC_SUCCESS) { in ib_mad_recv_done()
2038 * state - error handling/shutdown code will cleanup in ib_mad_recv_done()
2043 qp_info = mad_list->mad_queue->qp_info; in ib_mad_recv_done()
2046 opa = rdma_cap_opa_mad(qp_info->port_priv->device, in ib_mad_recv_done()
2047 qp_info->port_priv->port_num); in ib_mad_recv_done()
2052 ib_dma_unmap_single(port_priv->device, in ib_mad_recv_done()
2053 recv->header.mapping, in ib_mad_recv_done()
2058 recv->header.wc = *wc; in ib_mad_recv_done()
2059 recv->header.recv_wc.wc = &recv->header.wc; in ib_mad_recv_done()
2061 if (opa && ((struct ib_mad_hdr *)(recv->mad))->base_version == OPA_MGMT_BASE_VERSION) { in ib_mad_recv_done()
2062 recv->header.recv_wc.mad_len = wc->byte_len - sizeof(struct ib_grh); in ib_mad_recv_done()
2063 recv->header.recv_wc.mad_seg_size = sizeof(struct opa_mad); in ib_mad_recv_done()
2065 recv->header.recv_wc.mad_len = sizeof(struct ib_mad); in ib_mad_recv_done()
2066 recv->header.recv_wc.mad_seg_size = sizeof(struct ib_mad); in ib_mad_recv_done()
2069 recv->header.recv_wc.recv_buf.mad = (struct ib_mad *)recv->mad; in ib_mad_recv_done()
2070 recv->header.recv_wc.recv_buf.grh = &recv->grh; in ib_mad_recv_done()
2073 if (!validate_mad((const struct ib_mad_hdr *)recv->mad, qp_info, opa)) in ib_mad_recv_done()
2077 (struct ib_mad_hdr *)recv->mad); in ib_mad_recv_done()
2079 mad_size = recv->mad_size; in ib_mad_recv_done()
2084 if (rdma_cap_ib_switch(port_priv->device)) in ib_mad_recv_done()
2085 port_num = wc->port_num; in ib_mad_recv_done()
2087 port_num = port_priv->port_num; in ib_mad_recv_done()
2089 if (((struct ib_mad_hdr *)recv->mad)->mgmt_class == in ib_mad_recv_done()
2098 if (port_priv->device->ops.process_mad) { in ib_mad_recv_done()
2099 ret = port_priv->device->ops.process_mad( in ib_mad_recv_done()
2100 port_priv->device, 0, port_priv->port_num, wc, in ib_mad_recv_done()
2101 &recv->grh, (const struct ib_mad *)recv->mad, in ib_mad_recv_done()
2102 (struct ib_mad *)response->mad, &mad_size, in ib_mad_recv_done()
2106 wc->pkey_index = resp_mad_pkey_index; in ib_mad_recv_done()
2112 agent_send_response((const struct ib_mad_hdr *)response->mad, in ib_mad_recv_done()
2113 &recv->grh, wc, in ib_mad_recv_done()
2114 port_priv->device, in ib_mad_recv_done()
2116 qp_info->qp->qp_num, in ib_mad_recv_done()
2123 mad_agent = find_mad_agent(port_priv, (const struct ib_mad_hdr *)recv->mad); in ib_mad_recv_done()
2126 ib_mad_complete_recv(mad_agent, &recv->header.recv_wc); in ib_mad_recv_done()
2134 agent_send_response((const struct ib_mad_hdr *)response->mad, &recv->grh, wc, in ib_mad_recv_done()
2135 port_priv->device, port_num, in ib_mad_recv_done()
2136 qp_info->qp->qp_num, mad_size, opa); in ib_mad_recv_done()
2153 if (list_empty(&mad_agent_priv->wait_list)) { in adjust_timeout()
2154 cancel_delayed_work(&mad_agent_priv->timed_work); in adjust_timeout()
2156 mad_send_wr = list_entry(mad_agent_priv->wait_list.next, in adjust_timeout()
2160 if (time_after(mad_agent_priv->timeout, in adjust_timeout()
2161 mad_send_wr->timeout)) { in adjust_timeout()
2162 mad_agent_priv->timeout = mad_send_wr->timeout; in adjust_timeout()
2163 delay = mad_send_wr->timeout - jiffies; in adjust_timeout()
2166 mod_delayed_work(mad_agent_priv->qp_info->port_priv->wq, in adjust_timeout()
2167 &mad_agent_priv->timed_work, delay); in adjust_timeout()
2179 mad_agent_priv = mad_send_wr->mad_agent_priv; in wait_for_response()
2180 list_del(&mad_send_wr->agent_list); in wait_for_response()
2182 delay = mad_send_wr->timeout; in wait_for_response()
2183 mad_send_wr->timeout += jiffies; in wait_for_response()
2186 list_for_each_prev(list_item, &mad_agent_priv->wait_list) { in wait_for_response()
2190 if (time_after(mad_send_wr->timeout, in wait_for_response()
2191 temp_mad_send_wr->timeout)) in wait_for_response()
2195 list_item = &mad_agent_priv->wait_list; in wait_for_response()
2198 list_add(&mad_send_wr->agent_list, list_item); in wait_for_response()
2201 if (mad_agent_priv->wait_list.next == &mad_send_wr->agent_list) in wait_for_response()
2202 mod_delayed_work(mad_agent_priv->qp_info->port_priv->wq, in wait_for_response()
2203 &mad_agent_priv->timed_work, delay); in wait_for_response()
2209 mad_send_wr->timeout = msecs_to_jiffies(timeout_ms); in ib_reset_mad_timeout()
2223 mad_agent_priv = mad_send_wr->mad_agent_priv; in ib_mad_complete_send_wr()
2224 spin_lock_irqsave(&mad_agent_priv->lock, flags); in ib_mad_complete_send_wr()
2225 if (ib_mad_kernel_rmpp_agent(&mad_agent_priv->agent)) { in ib_mad_complete_send_wr()
2232 if (mad_send_wc->status != IB_WC_SUCCESS && in ib_mad_complete_send_wr()
2233 mad_send_wr->status == IB_WC_SUCCESS) { in ib_mad_complete_send_wr()
2234 mad_send_wr->status = mad_send_wc->status; in ib_mad_complete_send_wr()
2235 mad_send_wr->refcount -= (mad_send_wr->timeout > 0); in ib_mad_complete_send_wr()
2238 if (--mad_send_wr->refcount > 0) { in ib_mad_complete_send_wr()
2239 if (mad_send_wr->refcount == 1 && mad_send_wr->timeout && in ib_mad_complete_send_wr()
2240 mad_send_wr->status == IB_WC_SUCCESS) { in ib_mad_complete_send_wr()
2247 list_del(&mad_send_wr->agent_list); in ib_mad_complete_send_wr()
2249 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); in ib_mad_complete_send_wr()
2251 if (mad_send_wr->status != IB_WC_SUCCESS) in ib_mad_complete_send_wr()
2252 mad_send_wc->status = mad_send_wr->status; in ib_mad_complete_send_wr()
2256 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent, in ib_mad_complete_send_wr()
2263 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); in ib_mad_complete_send_wr()
2268 struct ib_mad_port_private *port_priv = cq->cq_context; in ib_mad_send_done()
2270 container_of(wc->wr_cqe, struct ib_mad_list_head, cqe); in ib_mad_send_done()
2278 if (list_empty_careful(&port_priv->port_list)) in ib_mad_send_done()
2281 if (wc->status != IB_WC_SUCCESS) { in ib_mad_send_done()
2288 send_queue = mad_list->mad_queue; in ib_mad_send_done()
2289 qp_info = send_queue->qp_info; in ib_mad_send_done()
2291 trace_ib_mad_send_done_agent(mad_send_wr->mad_agent_priv); in ib_mad_send_done()
2295 ib_dma_unmap_single(mad_send_wr->send_buf.mad_agent->device, in ib_mad_send_done()
2296 mad_send_wr->header_mapping, in ib_mad_send_done()
2297 mad_send_wr->sg_list[0].length, DMA_TO_DEVICE); in ib_mad_send_done()
2298 ib_dma_unmap_single(mad_send_wr->send_buf.mad_agent->device, in ib_mad_send_done()
2299 mad_send_wr->payload_mapping, in ib_mad_send_done()
2300 mad_send_wr->sg_list[1].length, DMA_TO_DEVICE); in ib_mad_send_done()
2302 spin_lock_irqsave(&send_queue->lock, flags); in ib_mad_send_done()
2303 list_del(&mad_list->list); in ib_mad_send_done()
2306 if (send_queue->count-- > send_queue->max_active) { in ib_mad_send_done()
2307 mad_list = container_of(qp_info->overflow_list.next, in ib_mad_send_done()
2312 list_move_tail(&mad_list->list, &send_queue->list); in ib_mad_send_done()
2314 spin_unlock_irqrestore(&send_queue->lock, flags); in ib_mad_send_done()
2316 mad_send_wc.send_buf = &mad_send_wr->send_buf; in ib_mad_send_done()
2317 mad_send_wc.status = wc->status; in ib_mad_send_done()
2318 mad_send_wc.vendor_err = wc->vendor_err; in ib_mad_send_done()
2323 ret = ib_post_send(qp_info->qp, &queued_send_wr->send_wr.wr, in ib_mad_send_done()
2326 dev_err(&port_priv->device->dev, in ib_mad_send_done()
2329 wc->status = IB_WC_LOC_QP_OP_ERR; in ib_mad_send_done()
2341 spin_lock_irqsave(&qp_info->send_queue.lock, flags); in mark_sends_for_retry()
2342 list_for_each_entry(mad_list, &qp_info->send_queue.list, list) { in mark_sends_for_retry()
2346 mad_send_wr->retry = 1; in mark_sends_for_retry()
2348 spin_unlock_irqrestore(&qp_info->send_queue.lock, flags); in mark_sends_for_retry()
2355 container_of(wc->wr_cqe, struct ib_mad_list_head, cqe); in ib_mad_send_error()
2356 struct ib_mad_qp_info *qp_info = mad_list->mad_queue->qp_info; in ib_mad_send_error()
2361 * Send errors will transition the QP to SQE - move in ib_mad_send_error()
2366 if (wc->status == IB_WC_WR_FLUSH_ERR) { in ib_mad_send_error()
2367 if (mad_send_wr->retry) { in ib_mad_send_error()
2369 mad_send_wr->retry = 0; in ib_mad_send_error()
2371 ret = ib_post_send(qp_info->qp, &mad_send_wr->send_wr.wr, in ib_mad_send_error()
2382 attr->qp_state = IB_QPS_RTS; in ib_mad_send_error()
2383 attr->cur_qp_state = IB_QPS_SQE; in ib_mad_send_error()
2384 ret = ib_modify_qp(qp_info->qp, attr, in ib_mad_send_error()
2388 dev_err(&port_priv->device->dev, in ib_mad_send_error()
2389 "%s - ib_modify_qp to RTS: %d\n", in ib_mad_send_error()
2408 spin_lock_irqsave(&mad_agent_priv->lock, flags); in cancel_mads()
2410 &mad_agent_priv->send_list, agent_list) { in cancel_mads()
2411 if (mad_send_wr->status == IB_WC_SUCCESS) { in cancel_mads()
2412 mad_send_wr->status = IB_WC_WR_FLUSH_ERR; in cancel_mads()
2413 mad_send_wr->refcount -= (mad_send_wr->timeout > 0); in cancel_mads()
2418 list_splice_init(&mad_agent_priv->wait_list, &cancel_list); in cancel_mads()
2419 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); in cancel_mads()
2427 mad_send_wc.send_buf = &mad_send_wr->send_buf; in cancel_mads()
2428 list_del(&mad_send_wr->agent_list); in cancel_mads()
2429 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent, in cancel_mads()
2441 list_for_each_entry(mad_send_wr, &mad_agent_priv->wait_list, in find_send_wr()
2443 if (&mad_send_wr->send_buf == send_buf) in find_send_wr()
2447 list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list, in find_send_wr()
2450 mad_send_wr->send_buf.mad) && in find_send_wr()
2451 &mad_send_wr->send_buf == send_buf) in find_send_wr()
2465 return -EINVAL; in ib_modify_mad()
2467 mad_agent_priv = container_of(send_buf->mad_agent, in ib_modify_mad()
2469 spin_lock_irqsave(&mad_agent_priv->lock, flags); in ib_modify_mad()
2471 if (!mad_send_wr || mad_send_wr->status != IB_WC_SUCCESS) { in ib_modify_mad()
2472 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); in ib_modify_mad()
2473 return -EINVAL; in ib_modify_mad()
2476 active = (!mad_send_wr->timeout || mad_send_wr->refcount > 1); in ib_modify_mad()
2478 mad_send_wr->status = IB_WC_WR_FLUSH_ERR; in ib_modify_mad()
2479 mad_send_wr->refcount -= (mad_send_wr->timeout > 0); in ib_modify_mad()
2482 mad_send_wr->send_buf.timeout_ms = timeout_ms; in ib_modify_mad()
2484 mad_send_wr->timeout = msecs_to_jiffies(timeout_ms); in ib_modify_mad()
2488 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); in ib_modify_mad()
2507 opa = rdma_cap_opa_mad(mad_agent_priv->qp_info->port_priv->device, in local_completions()
2508 mad_agent_priv->qp_info->port_priv->port_num); in local_completions()
2510 spin_lock_irqsave(&mad_agent_priv->lock, flags); in local_completions()
2511 while (!list_empty(&mad_agent_priv->local_list)) { in local_completions()
2512 local = list_entry(mad_agent_priv->local_list.next, in local_completions()
2515 list_del(&local->completion_list); in local_completions()
2516 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); in local_completions()
2518 if (local->mad_priv) { in local_completions()
2520 recv_mad_agent = local->recv_mad_agent; in local_completions()
2522 dev_err(&mad_agent_priv->agent.device->dev, in local_completions()
2532 build_smp_wc(recv_mad_agent->agent.qp, in local_completions()
2533 local->mad_send_wr->send_wr.wr.wr_cqe, in local_completions()
2535 local->mad_send_wr->send_wr.pkey_index, in local_completions()
2536 recv_mad_agent->agent.port_num, &wc); in local_completions()
2538 local->mad_priv->header.recv_wc.wc = &wc; in local_completions()
2540 base_version = ((struct ib_mad_hdr *)(local->mad_priv->mad))->base_version; in local_completions()
2542 local->mad_priv->header.recv_wc.mad_len = local->return_wc_byte_len; in local_completions()
2543 local->mad_priv->header.recv_wc.mad_seg_size = sizeof(struct opa_mad); in local_completions()
2545 local->mad_priv->header.recv_wc.mad_len = sizeof(struct ib_mad); in local_completions()
2546 local->mad_priv->header.recv_wc.mad_seg_size = sizeof(struct ib_mad); in local_completions()
2549 INIT_LIST_HEAD(&local->mad_priv->header.recv_wc.rmpp_list); in local_completions()
2550 list_add(&local->mad_priv->header.recv_wc.recv_buf.list, in local_completions()
2551 &local->mad_priv->header.recv_wc.rmpp_list); in local_completions()
2552 local->mad_priv->header.recv_wc.recv_buf.grh = NULL; in local_completions()
2553 local->mad_priv->header.recv_wc.recv_buf.mad = in local_completions()
2554 (struct ib_mad *)local->mad_priv->mad; in local_completions()
2555 recv_mad_agent->agent.recv_handler( in local_completions()
2556 &recv_mad_agent->agent, in local_completions()
2557 &local->mad_send_wr->send_buf, in local_completions()
2558 &local->mad_priv->header.recv_wc); in local_completions()
2559 spin_lock_irqsave(&recv_mad_agent->lock, flags); in local_completions()
2561 spin_unlock_irqrestore(&recv_mad_agent->lock, flags); in local_completions()
2568 mad_send_wc.send_buf = &local->mad_send_wr->send_buf; in local_completions()
2569 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent, in local_completions()
2572 spin_lock_irqsave(&mad_agent_priv->lock, flags); in local_completions()
2575 kfree(local->mad_priv); in local_completions()
2578 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); in local_completions()
2585 if (!mad_send_wr->retries_left) in retry_send()
2586 return -ETIMEDOUT; in retry_send()
2588 mad_send_wr->retries_left--; in retry_send()
2589 mad_send_wr->send_buf.retries++; in retry_send()
2591 mad_send_wr->timeout = msecs_to_jiffies(mad_send_wr->send_buf.timeout_ms); in retry_send()
2593 if (ib_mad_kernel_rmpp_agent(&mad_send_wr->mad_agent_priv->agent)) { in retry_send()
2603 ret = -ECOMM; in retry_send()
2610 mad_send_wr->refcount++; in retry_send()
2611 list_add_tail(&mad_send_wr->agent_list, in retry_send()
2612 &mad_send_wr->mad_agent_priv->send_list); in retry_send()
2630 spin_lock_irqsave(&mad_agent_priv->lock, flags); in timeout_sends()
2631 while (!list_empty(&mad_agent_priv->wait_list)) { in timeout_sends()
2632 mad_send_wr = list_entry(mad_agent_priv->wait_list.next, in timeout_sends()
2636 if (time_after(mad_send_wr->timeout, jiffies)) { in timeout_sends()
2637 delay = mad_send_wr->timeout - jiffies; in timeout_sends()
2640 queue_delayed_work(mad_agent_priv->qp_info-> in timeout_sends()
2641 port_priv->wq, in timeout_sends()
2642 &mad_agent_priv->timed_work, delay); in timeout_sends()
2646 list_del_init(&mad_send_wr->agent_list); in timeout_sends()
2647 if (mad_send_wr->status == IB_WC_SUCCESS && in timeout_sends()
2651 list_add_tail(&mad_send_wr->agent_list, &local_list); in timeout_sends()
2653 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); in timeout_sends()
2656 if (mad_send_wr->status == IB_WC_SUCCESS) in timeout_sends()
2659 mad_send_wc.status = mad_send_wr->status; in timeout_sends()
2660 mad_send_wc.send_buf = &mad_send_wr->send_buf; in timeout_sends()
2661 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent, in timeout_sends()
2678 struct ib_mad_queue *recv_queue = &qp_info->recv_queue; in ib_mad_post_receive_mads()
2681 sg_list.lkey = qp_info->port_priv->pd->local_dma_lkey; in ib_mad_post_receive_mads()
2694 mad_priv = alloc_mad_private(port_mad_size(qp_info->port_priv), in ib_mad_post_receive_mads()
2697 ret = -ENOMEM; in ib_mad_post_receive_mads()
2702 sg_list.addr = ib_dma_map_single(qp_info->port_priv->device, in ib_mad_post_receive_mads()
2703 &mad_priv->grh, in ib_mad_post_receive_mads()
2706 if (unlikely(ib_dma_mapping_error(qp_info->port_priv->device, in ib_mad_post_receive_mads()
2709 ret = -ENOMEM; in ib_mad_post_receive_mads()
2712 mad_priv->header.mapping = sg_list.addr; in ib_mad_post_receive_mads()
2713 mad_priv->header.mad_list.mad_queue = recv_queue; in ib_mad_post_receive_mads()
2714 mad_priv->header.mad_list.cqe.done = ib_mad_recv_done; in ib_mad_post_receive_mads()
2715 recv_wr.wr_cqe = &mad_priv->header.mad_list.cqe; in ib_mad_post_receive_mads()
2718 spin_lock_irqsave(&recv_queue->lock, flags); in ib_mad_post_receive_mads()
2719 post = (++recv_queue->count < recv_queue->max_active); in ib_mad_post_receive_mads()
2720 list_add_tail(&mad_priv->header.mad_list.list, &recv_queue->list); in ib_mad_post_receive_mads()
2721 spin_unlock_irqrestore(&recv_queue->lock, flags); in ib_mad_post_receive_mads()
2722 ret = ib_post_recv(qp_info->qp, &recv_wr, NULL); in ib_mad_post_receive_mads()
2724 spin_lock_irqsave(&recv_queue->lock, flags); in ib_mad_post_receive_mads()
2725 list_del(&mad_priv->header.mad_list.list); in ib_mad_post_receive_mads()
2726 recv_queue->count--; in ib_mad_post_receive_mads()
2727 spin_unlock_irqrestore(&recv_queue->lock, flags); in ib_mad_post_receive_mads()
2728 ib_dma_unmap_single(qp_info->port_priv->device, in ib_mad_post_receive_mads()
2729 mad_priv->header.mapping, in ib_mad_post_receive_mads()
2733 dev_err(&qp_info->port_priv->device->dev, in ib_mad_post_receive_mads()
2751 if (!qp_info->qp) in cleanup_recv_queue()
2754 while (!list_empty(&qp_info->recv_queue.list)) { in cleanup_recv_queue()
2756 mad_list = list_entry(qp_info->recv_queue.list.next, in cleanup_recv_queue()
2765 list_del(&mad_list->list); in cleanup_recv_queue()
2767 ib_dma_unmap_single(qp_info->port_priv->device, in cleanup_recv_queue()
2768 recv->header.mapping, in cleanup_recv_queue()
2774 qp_info->recv_queue.count = 0; in cleanup_recv_queue()
2789 return -ENOMEM; in ib_mad_port_start()
2791 ret = ib_find_pkey(port_priv->device, port_priv->port_num, in ib_mad_port_start()
2797 qp = port_priv->qp_info[i].qp; in ib_mad_port_start()
2805 attr->qp_state = IB_QPS_INIT; in ib_mad_port_start()
2806 attr->pkey_index = pkey_index; in ib_mad_port_start()
2807 attr->qkey = (qp->qp_num == 0) ? 0 : IB_QP1_QKEY; in ib_mad_port_start()
2811 dev_err(&port_priv->device->dev, in ib_mad_port_start()
2817 attr->qp_state = IB_QPS_RTR; in ib_mad_port_start()
2820 dev_err(&port_priv->device->dev, in ib_mad_port_start()
2826 attr->qp_state = IB_QPS_RTS; in ib_mad_port_start()
2827 attr->sq_psn = IB_MAD_SEND_Q_PSN; in ib_mad_port_start()
2830 dev_err(&port_priv->device->dev, in ib_mad_port_start()
2837 ret = ib_req_notify_cq(port_priv->cq, IB_CQ_NEXT_COMP); in ib_mad_port_start()
2839 dev_err(&port_priv->device->dev, in ib_mad_port_start()
2846 if (!port_priv->qp_info[i].qp) in ib_mad_port_start()
2849 ret = ib_mad_post_receive_mads(&port_priv->qp_info[i], NULL); in ib_mad_port_start()
2851 dev_err(&port_priv->device->dev, in ib_mad_port_start()
2866 dev_err(&qp_info->port_priv->device->dev, in qp_event_handler()
2868 event->event, qp_info->qp->qp_num); in qp_event_handler()
2874 mad_queue->qp_info = qp_info; in init_mad_queue()
2875 mad_queue->count = 0; in init_mad_queue()
2876 spin_lock_init(&mad_queue->lock); in init_mad_queue()
2877 INIT_LIST_HEAD(&mad_queue->list); in init_mad_queue()
2883 qp_info->port_priv = port_priv; in init_mad_qp()
2884 init_mad_queue(qp_info, &qp_info->send_queue); in init_mad_qp()
2885 init_mad_queue(qp_info, &qp_info->recv_queue); in init_mad_qp()
2886 INIT_LIST_HEAD(&qp_info->overflow_list); in init_mad_qp()
2896 qp_init_attr.send_cq = qp_info->port_priv->cq; in create_mad_qp()
2897 qp_init_attr.recv_cq = qp_info->port_priv->cq; in create_mad_qp()
2904 qp_init_attr.port_num = qp_info->port_priv->port_num; in create_mad_qp()
2907 qp_info->qp = ib_create_qp(qp_info->port_priv->pd, &qp_init_attr); in create_mad_qp()
2908 if (IS_ERR(qp_info->qp)) { in create_mad_qp()
2909 dev_err(&qp_info->port_priv->device->dev, in create_mad_qp()
2912 ret = PTR_ERR(qp_info->qp); in create_mad_qp()
2916 qp_info->send_queue.max_active = mad_sendq_size; in create_mad_qp()
2917 qp_info->recv_queue.max_active = mad_recvq_size; in create_mad_qp()
2926 if (!qp_info->qp) in destroy_mad_qp()
2929 ib_destroy_qp(qp_info->qp); in destroy_mad_qp()
2945 return -EFAULT; in ib_mad_port_open()
2949 return -EFAULT; in ib_mad_port_open()
2954 return -ENOMEM; in ib_mad_port_open()
2956 port_priv->device = device; in ib_mad_port_open()
2957 port_priv->port_num = port_num; in ib_mad_port_open()
2958 spin_lock_init(&port_priv->reg_lock); in ib_mad_port_open()
2959 init_mad_qp(port_priv, &port_priv->qp_info[0]); in ib_mad_port_open()
2960 init_mad_qp(port_priv, &port_priv->qp_info[1]); in ib_mad_port_open()
2967 port_priv->pd = ib_alloc_pd(device, 0); in ib_mad_port_open()
2968 if (IS_ERR(port_priv->pd)) { in ib_mad_port_open()
2969 dev_err(&device->dev, "Couldn't create ib_mad PD\n"); in ib_mad_port_open()
2970 ret = PTR_ERR(port_priv->pd); in ib_mad_port_open()
2974 port_priv->cq = ib_alloc_cq(port_priv->device, port_priv, cq_size, 0, in ib_mad_port_open()
2976 if (IS_ERR(port_priv->cq)) { in ib_mad_port_open()
2977 dev_err(&device->dev, "Couldn't create ib_mad CQ\n"); in ib_mad_port_open()
2978 ret = PTR_ERR(port_priv->cq); in ib_mad_port_open()
2983 ret = create_mad_qp(&port_priv->qp_info[0], IB_QPT_SMI); in ib_mad_port_open()
2989 ret = create_mad_qp(&port_priv->qp_info[1], IB_QPT_GSI); in ib_mad_port_open()
2994 port_priv->wq = alloc_ordered_workqueue("ib_mad%u", WQ_MEM_RECLAIM, in ib_mad_port_open()
2996 if (!port_priv->wq) { in ib_mad_port_open()
2997 ret = -ENOMEM; in ib_mad_port_open()
3002 list_add_tail(&port_priv->port_list, &ib_mad_port_list); in ib_mad_port_open()
3007 dev_err(&device->dev, "Couldn't start port\n"); in ib_mad_port_open()
3015 list_del_init(&port_priv->port_list); in ib_mad_port_open()
3018 destroy_workqueue(port_priv->wq); in ib_mad_port_open()
3020 destroy_mad_qp(&port_priv->qp_info[1]); in ib_mad_port_open()
3022 destroy_mad_qp(&port_priv->qp_info[0]); in ib_mad_port_open()
3024 ib_free_cq(port_priv->cq); in ib_mad_port_open()
3025 cleanup_recv_queue(&port_priv->qp_info[1]); in ib_mad_port_open()
3026 cleanup_recv_queue(&port_priv->qp_info[0]); in ib_mad_port_open()
3028 ib_dealloc_pd(port_priv->pd); in ib_mad_port_open()
3049 dev_err(&device->dev, "Port %u not found\n", port_num); in ib_mad_port_close()
3050 return -ENODEV; in ib_mad_port_close()
3052 list_del_init(&port_priv->port_list); in ib_mad_port_close()
3055 destroy_workqueue(port_priv->wq); in ib_mad_port_close()
3056 destroy_mad_qp(&port_priv->qp_info[1]); in ib_mad_port_close()
3057 destroy_mad_qp(&port_priv->qp_info[0]); in ib_mad_port_close()
3058 ib_free_cq(port_priv->cq); in ib_mad_port_close()
3059 ib_dealloc_pd(port_priv->pd); in ib_mad_port_close()
3060 cleanup_recv_queue(&port_priv->qp_info[1]); in ib_mad_port_close()
3061 cleanup_recv_queue(&port_priv->qp_info[0]); in ib_mad_port_close()
3083 dev_err(&device->dev, "Couldn't open port %d\n", i); in ib_mad_init_device()
3088 dev_err(&device->dev, in ib_mad_init_device()
3095 return -EOPNOTSUPP; in ib_mad_init_device()
3101 dev_err(&device->dev, "Couldn't close port %d\n", i); in ib_mad_init_device()
3104 while (--i >= start) { in ib_mad_init_device()
3109 dev_err(&device->dev, in ib_mad_init_device()
3112 dev_err(&device->dev, "Couldn't close port %d\n", i); in ib_mad_init_device()
3126 dev_err(&device->dev, in ib_mad_remove_device()
3129 dev_err(&device->dev, "Couldn't close port %u\n", i); in ib_mad_remove_device()
3151 return -EINVAL; in ib_mad_init()