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) 2006, 2017 Oracle and/or its affiliates. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * This software is available to you under a choice of one of two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * licenses.  You may choose to be licensed under the terms of the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * General Public License (GPL) Version 2, available from the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * COPYING in the main directory of this source tree, or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * OpenIB.org BSD license below:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *     Redistribution and use in source and binary forms, with or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *     without modification, are permitted provided that the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *     conditions are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *      - Redistributions of source code must retain the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *        copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *        disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *      - Redistributions in binary form must reproduce the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *        copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *        disclaimer in the documentation and/or other materials
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *        provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include "rds.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include "loop.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static char * const rds_trans_modules[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	[RDS_TRANS_IB] = "rds_rdma",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	[RDS_TRANS_GAP] = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	[RDS_TRANS_TCP] = "rds_tcp",
^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) static struct rds_transport *transports[RDS_TRANS_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static DECLARE_RWSEM(rds_trans_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) void rds_trans_register(struct rds_transport *trans)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	BUG_ON(strlen(trans->t_name) + 1 > TRANSNAMSIZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	down_write(&rds_trans_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (transports[trans->t_type])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		printk(KERN_ERR "RDS Transport type %d already registered\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			trans->t_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		transports[trans->t_type] = trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		printk(KERN_INFO "Registered RDS/%s transport\n", trans->t_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	up_write(&rds_trans_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) EXPORT_SYMBOL_GPL(rds_trans_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) void rds_trans_unregister(struct rds_transport *trans)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	down_write(&rds_trans_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	transports[trans->t_type] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	printk(KERN_INFO "Unregistered RDS/%s transport\n", trans->t_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	up_write(&rds_trans_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) EXPORT_SYMBOL_GPL(rds_trans_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) void rds_trans_put(struct rds_transport *trans)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (trans)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		module_put(trans->t_owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) struct rds_transport *rds_trans_get_preferred(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 					      const struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 					      __u32 scope_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct rds_transport *ret = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	struct rds_transport *trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (ipv6_addr_v4mapped(addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if (*(u_int8_t *)&addr->s6_addr32[3] == IN_LOOPBACKNET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			return &rds_loop_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	} else if (ipv6_addr_loopback(addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		return &rds_loop_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	down_read(&rds_trans_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	for (i = 0; i < RDS_TRANS_COUNT; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		trans = transports[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		if (trans && (trans->laddr_check(net, addr, scope_id) == 0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		    (!trans->t_owner || try_module_get(trans->t_owner))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			ret = trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	up_read(&rds_trans_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct rds_transport *rds_trans_get(int t_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct rds_transport *ret = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct rds_transport *trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	down_read(&rds_trans_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	trans = transports[t_type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (!trans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		up_read(&rds_trans_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		if (rds_trans_modules[t_type])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			request_module(rds_trans_modules[t_type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		down_read(&rds_trans_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		trans = transports[t_type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (trans && trans->t_type == t_type &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	    (!trans->t_owner || try_module_get(trans->t_owner)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		ret = trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	up_read(&rds_trans_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^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)  * This returns the number of stats entries in the snapshot and only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  * copies them using the iter if there is enough space for them.  The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * caller passes in the global stats so that we can size and copy while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  * holding the lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) unsigned int rds_trans_stats_info_copy(struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 				       unsigned int avail)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct rds_transport *trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	unsigned int total = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	unsigned int part;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	rds_info_iter_unmap(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	down_read(&rds_trans_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	for (i = 0; i < RDS_TRANS_COUNT; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		trans = transports[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		if (!trans || !trans->stats_info_copy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		part = trans->stats_info_copy(iter, avail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		avail -= min(avail, part);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		total += part;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	up_read(&rds_trans_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	return total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }