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) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2007 Luca Bigliardi (shammash@artha.org).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Transport usage:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  ethN=vde,<vde_switch>,<mac addr>,<port>,<group>,<mode>,<description>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <net_kern.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <net_user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "vde.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) static void vde_init(struct net_device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	struct vde_init *init = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	struct uml_net_private *pri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	struct vde_data *vpri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	pri = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	vpri = (struct vde_data *) pri->user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	vpri->vde_switch = init->vde_switch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	vpri->descr = init->descr ? init->descr : "UML vde_transport";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	vpri->args = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	vpri->conn = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	vpri->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	printk("vde backend - %s, ", vpri->vde_switch ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	       vpri->vde_switch : "(default socket)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	vde_init_libstuff(vpri, init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int vde_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct vde_data *pri = (struct vde_data *) &lp->user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (pri->conn != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		return vde_user_read(pri->conn, skb_mac_header(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 				     skb->dev->mtu + ETH_HEADER_OTHER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	printk(KERN_ERR "vde_read - we have no VDECONN to read from");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	return -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static int vde_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct vde_data *pri = (struct vde_data *) &lp->user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (pri->conn != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		return vde_user_write((void *)pri->conn, skb->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 				      skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	printk(KERN_ERR "vde_write - we have no VDECONN to write to");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	return -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static const struct net_kern_info vde_kern_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	.init			= vde_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	.protocol		= eth_protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	.read			= vde_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	.write			= vde_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static int vde_setup(char *str, char **mac_out, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	struct vde_init *init = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	char *remain, *port_str = NULL, *mode_str = NULL, *last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	*init = ((struct vde_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		{ .vde_switch		= NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		  .descr		= NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		  .port			= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		  .group		= NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		  .mode			= 0 });
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	remain = split_if_spec(str, &init->vde_switch, mac_out, &port_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 				&init->group, &mode_str, &init->descr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (remain != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		printk(KERN_WARNING "vde_setup - Ignoring extra data :"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		       "'%s'\n", remain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (port_str != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		init->port = simple_strtoul(port_str, &last, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		if ((*last != '\0') || (last == port_str)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			printk(KERN_ERR "vde_setup - Bad port : '%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 						port_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (mode_str != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		init->mode = simple_strtoul(mode_str, &last, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		if ((*last != '\0') || (last == mode_str)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			printk(KERN_ERR "vde_setup - Bad mode : '%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 						mode_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	printk(KERN_INFO "Configured vde device: %s\n", init->vde_switch ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	       init->vde_switch : "(default socket)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static struct transport vde_transport = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	.list 		= LIST_HEAD_INIT(vde_transport.list),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	.name 		= "vde",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	.setup  	= vde_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	.user 		= &vde_user_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	.kern 		= &vde_kern_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	.private_size 	= sizeof(struct vde_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	.setup_size 	= sizeof(struct vde_init),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static int register_vde(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	register_transport(&vde_transport);
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) late_initcall(register_vde);