Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause
0002 /*
0003  * Copyright(c) 2016 Intel Corporation.
0004  */
0005 
0006 #include <rdma/ib_mad.h>
0007 #include "mad.h"
0008 #include "vt.h"
0009 
0010 /**
0011  * rvt_process_mad - process an incoming MAD packet
0012  * @ibdev: the infiniband device this packet came in on
0013  * @mad_flags: MAD flags
0014  * @port_num: the port number this packet came in on, 1 based from ib core
0015  * @in_wc: the work completion entry for this packet
0016  * @in_grh: the global route header for this packet
0017  * @in: the incoming MAD
0018  * @in_mad_size: size of the incoming MAD reply
0019  * @out: any outgoing MAD reply
0020  * @out_mad_size: size of the outgoing MAD reply
0021  * @out_mad_pkey_index: unused
0022  *
0023  * Note that the verbs framework has already done the MAD sanity checks,
0024  * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
0025  * MADs.
0026  *
0027  * This is called by the ib_mad module.
0028  *
0029  * Return: IB_MAD_RESULT_SUCCESS or error
0030  */
0031 int rvt_process_mad(struct ib_device *ibdev, int mad_flags, u32 port_num,
0032             const struct ib_wc *in_wc, const struct ib_grh *in_grh,
0033             const struct ib_mad_hdr *in, size_t in_mad_size,
0034             struct ib_mad_hdr *out, size_t *out_mad_size,
0035             u16 *out_mad_pkey_index)
0036 {
0037     /*
0038      * MAD processing is quite different between hfi1 and qib. Therefore
0039      * this is expected to be provided by the driver. Other drivers in the
0040      * future may choose to implement this but it should not be made into a
0041      * requirement.
0042      */
0043     return IB_MAD_RESULT_FAILURE;
0044 }
0045 
0046 static void rvt_send_mad_handler(struct ib_mad_agent *agent,
0047                  struct ib_mad_send_wc *mad_send_wc)
0048 {
0049     ib_free_send_mad(mad_send_wc->send_buf);
0050 }
0051 
0052 /**
0053  * rvt_create_mad_agents - create mad agents
0054  * @rdi: rvt dev struct
0055  *
0056  * If driver needs to be notified of mad agent creation then call back
0057  *
0058  * Return 0 on success
0059  */
0060 int rvt_create_mad_agents(struct rvt_dev_info *rdi)
0061 {
0062     struct ib_mad_agent *agent;
0063     struct rvt_ibport *rvp;
0064     int p;
0065     int ret;
0066 
0067     for (p = 0; p < rdi->dparms.nports; p++) {
0068         rvp = rdi->ports[p];
0069         agent = ib_register_mad_agent(&rdi->ibdev, p + 1,
0070                           IB_QPT_SMI,
0071                           NULL, 0, rvt_send_mad_handler,
0072                           NULL, NULL, 0);
0073         if (IS_ERR(agent)) {
0074             ret = PTR_ERR(agent);
0075             goto err;
0076         }
0077 
0078         rvp->send_agent = agent;
0079 
0080         if (rdi->driver_f.notify_create_mad_agent)
0081             rdi->driver_f.notify_create_mad_agent(rdi, p);
0082     }
0083 
0084     return 0;
0085 
0086 err:
0087     for (p = 0; p < rdi->dparms.nports; p++) {
0088         rvp = rdi->ports[p];
0089         if (rvp->send_agent) {
0090             agent = rvp->send_agent;
0091             rvp->send_agent = NULL;
0092             ib_unregister_mad_agent(agent);
0093             if (rdi->driver_f.notify_free_mad_agent)
0094                 rdi->driver_f.notify_free_mad_agent(rdi, p);
0095         }
0096     }
0097 
0098     return ret;
0099 }
0100 
0101 /**
0102  * rvt_free_mad_agents - free up mad agents
0103  * @rdi: rvt dev struct
0104  *
0105  * If driver needs notification of mad agent removal make the call back
0106  */
0107 void rvt_free_mad_agents(struct rvt_dev_info *rdi)
0108 {
0109     struct ib_mad_agent *agent;
0110     struct rvt_ibport *rvp;
0111     int p;
0112 
0113     for (p = 0; p < rdi->dparms.nports; p++) {
0114         rvp = rdi->ports[p];
0115         if (rvp->send_agent) {
0116             agent = rvp->send_agent;
0117             rvp->send_agent = NULL;
0118             ib_unregister_mad_agent(agent);
0119         }
0120         if (rvp->sm_ah) {
0121             rdma_destroy_ah(&rvp->sm_ah->ibah,
0122                     RDMA_DESTROY_AH_SLEEPABLE);
0123             rvp->sm_ah = NULL;
0124         }
0125 
0126         if (rdi->driver_f.notify_free_mad_agent)
0127             rdi->driver_f.notify_free_mad_agent(rdi, p);
0128     }
0129 }
0130