Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Copyright(c) 2016 Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * This file is provided under a dual BSD/GPLv2 license.  When using or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * redistributing this file, you may do so under either license.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * GPL LICENSE SUMMARY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * it under the terms of version 2 of the GNU General Public License as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * This program is distributed in the hope that it will be useful, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * BSD LICENSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *  - Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *    notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *  - Redistributions in binary form must reproduce the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *    notice, this list of conditions and the following disclaimer in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *    the documentation and/or other materials provided with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *    distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *  - Neither the name of Intel Corporation nor the names of its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *    contributors may be used to endorse or promote products derived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *    from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include <rdma/ib_mad.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #include "mad.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #include "vt.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * rvt_process_mad - process an incoming MAD packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * @ibdev: the infiniband device this packet came in on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * @mad_flags: MAD flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * @port_num: the port number this packet came in on, 1 based from ib core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * @in_wc: the work completion entry for this packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * @in_grh: the global route header for this packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * @in_mad: the incoming MAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * @out_mad: any outgoing MAD reply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * Note that the verbs framework has already done the MAD sanity checks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * MADs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * This is called by the ib_mad module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * Return: IB_MAD_RESULT_SUCCESS or error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) int rvt_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		    const struct ib_wc *in_wc, const struct ib_grh *in_grh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		    const struct ib_mad_hdr *in, size_t in_mad_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		    struct ib_mad_hdr *out, size_t *out_mad_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		    u16 *out_mad_pkey_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	 * MAD processing is quite different between hfi1 and qib. Therefore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	 * this is expected to be provided by the driver. Other drivers in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	 * future may choose to implement this but it should not be made into a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	 * requirement.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (ibport_num_to_idx(ibdev, port_num) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	return IB_MAD_RESULT_FAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static void rvt_send_mad_handler(struct ib_mad_agent *agent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 				 struct ib_mad_send_wc *mad_send_wc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	ib_free_send_mad(mad_send_wc->send_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * rvt_create_mad_agents - create mad agents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * @rdi: rvt dev struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * If driver needs to be notified of mad agent creation then call back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * Return 0 on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) int rvt_create_mad_agents(struct rvt_dev_info *rdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct ib_mad_agent *agent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct rvt_ibport *rvp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	int p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	for (p = 0; p < rdi->dparms.nports; p++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		rvp = rdi->ports[p];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		agent = ib_register_mad_agent(&rdi->ibdev, p + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 					      IB_QPT_SMI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 					      NULL, 0, rvt_send_mad_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 					      NULL, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		if (IS_ERR(agent)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			ret = PTR_ERR(agent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		rvp->send_agent = agent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		if (rdi->driver_f.notify_create_mad_agent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			rdi->driver_f.notify_create_mad_agent(rdi, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	for (p = 0; p < rdi->dparms.nports; p++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		rvp = rdi->ports[p];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		if (rvp->send_agent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			agent = rvp->send_agent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			rvp->send_agent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			ib_unregister_mad_agent(agent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			if (rdi->driver_f.notify_free_mad_agent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 				rdi->driver_f.notify_free_mad_agent(rdi, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * rvt_free_mad_agents - free up mad agents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * @rdi: rvt dev struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * If driver needs notification of mad agent removal make the call back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) void rvt_free_mad_agents(struct rvt_dev_info *rdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct ib_mad_agent *agent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	struct rvt_ibport *rvp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	int p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	for (p = 0; p < rdi->dparms.nports; p++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		rvp = rdi->ports[p];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		if (rvp->send_agent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			agent = rvp->send_agent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			rvp->send_agent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			ib_unregister_mad_agent(agent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		if (rvp->sm_ah) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			rdma_destroy_ah(&rvp->sm_ah->ibah,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 					RDMA_DESTROY_AH_SLEEPABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			rvp->sm_ah = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		if (rdi->driver_f.notify_free_mad_agent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			rdi->driver_f.notify_free_mad_agent(rdi, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)