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) /* ldmvsw.c: Sun4v LDOM Virtual Switch Driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2016-2017 Oracle. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/ethtool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/if_vlan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #if defined(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/icmpv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <net/icmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <net/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <asm/vio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <asm/ldc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /* This driver makes use of the common code in sunvnet_common.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include "sunvnet_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /* Length of time before we decide the hardware is hung,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * and dev->tx_timeout() should be called to fix the problem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define VSW_TX_TIMEOUT			(10 * HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) /* Static HW Addr used for the network interfaces representing vsw ports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static u8 vsw_port_hwaddr[ETH_ALEN] = {0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define DRV_MODULE_NAME		"ldmvsw"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define DRV_MODULE_VERSION	"1.2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define DRV_MODULE_RELDATE	"March 4, 2017"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static char version[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) MODULE_AUTHOR("Oracle");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) MODULE_DESCRIPTION("Sun4v LDOM Virtual Switch Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) MODULE_VERSION(DRV_MODULE_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) /* Ordered from largest major to lowest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static struct vio_version vsw_versions[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	{ .major = 1, .minor = 8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	{ .major = 1, .minor = 7 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	{ .major = 1, .minor = 6 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	{ .major = 1, .minor = 0 },
^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 void vsw_get_drvinfo(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			    struct ethtool_drvinfo *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
^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 u32 vsw_get_msglevel(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	struct vnet_port *port = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	return port->vp->msg_enable;
^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) static void vsw_set_msglevel(struct net_device *dev, u32 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct vnet_port *port = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	port->vp->msg_enable = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static const struct ethtool_ops vsw_ethtool_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	.get_drvinfo		= vsw_get_drvinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	.get_msglevel		= vsw_get_msglevel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	.set_msglevel		= vsw_set_msglevel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	.get_link		= ethtool_op_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static LIST_HEAD(vnet_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static DEFINE_MUTEX(vnet_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) /* func arg to vnet_start_xmit_common() to get the proper tx port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static struct vnet_port *vsw_tx_port_find(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 					  struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	struct vnet_port *port = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	return port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static u16 vsw_select_queue(struct net_device *dev, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			    struct net_device *sb_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct vnet_port *port = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (!port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return port->q_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* Wrappers to common functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static netdev_tx_t vsw_start_xmit(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return sunvnet_start_xmit_common(skb, dev, vsw_tx_port_find);
^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) static void vsw_set_rx_mode(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct vnet_port *port = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return sunvnet_set_rx_mode_common(dev, port->vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int ldmvsw_open(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct vnet_port *port = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct vio_driver_state *vio = &port->vio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	/* reset the channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	vio_link_state_change(vio, LDC_EVENT_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	vnet_port_reset(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	vio_port_up(vio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) EXPORT_SYMBOL_GPL(ldmvsw_open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #ifdef CONFIG_NET_POLL_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static void vsw_poll_controller(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct vnet_port *port = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return sunvnet_poll_controller_common(dev, port->vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static const struct net_device_ops vsw_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	.ndo_open		= ldmvsw_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	.ndo_stop		= sunvnet_close_common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	.ndo_set_rx_mode	= vsw_set_rx_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	.ndo_set_mac_address	= sunvnet_set_mac_addr_common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	.ndo_validate_addr	= eth_validate_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	.ndo_tx_timeout		= sunvnet_tx_timeout_common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	.ndo_start_xmit		= vsw_start_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	.ndo_select_queue	= vsw_select_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #ifdef CONFIG_NET_POLL_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	.ndo_poll_controller    = vsw_poll_controller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static const char *local_mac_prop = "local-mac-address";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static const char *cfg_handle_prop = "cfg-handle";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static struct vnet *vsw_get_vnet(struct mdesc_handle *hp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				 u64 port_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 				 u64 *handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	struct vnet *vp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	struct vnet *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	const u64 *local_mac = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	const u64 *cfghandle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	u64 a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	/* Get the parent virtual-network-switch macaddr and cfghandle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	mdesc_for_each_arc(a, hp, port_node, MDESC_ARC_TYPE_BACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		u64 target = mdesc_arc_target(hp, a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		name = mdesc_get_property(hp, target, "name", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		if (!name || strcmp(name, "virtual-network-switch"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		local_mac = mdesc_get_property(hp, target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 					       local_mac_prop, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		cfghandle = mdesc_get_property(hp, target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 					       cfg_handle_prop, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (!local_mac || !cfghandle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		return ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	/* find or create associated vnet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	vp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	mutex_lock(&vnet_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	list_for_each_entry(iter, &vnet_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		if (iter->local_mac == *local_mac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			vp = iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if (!vp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		vp = kzalloc(sizeof(*vp), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		if (unlikely(!vp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			mutex_unlock(&vnet_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		spin_lock_init(&vp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		INIT_LIST_HEAD(&vp->port_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		INIT_LIST_HEAD(&vp->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		vp->local_mac = *local_mac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		list_add(&vp->list, &vnet_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	mutex_unlock(&vnet_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	*handle = (u64)*cfghandle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	return vp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static struct net_device *vsw_alloc_netdev(u8 hwaddr[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 					   struct vio_dev *vdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 					   u64 handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 					   u64 port_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	struct vnet_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	dev = alloc_etherdev_mqs(sizeof(*port), VNET_MAX_TXQS, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	dev->needed_headroom = VNET_PACKET_SKIP + 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	dev->needed_tailroom = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	for (i = 0; i < ETH_ALEN; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		dev->dev_addr[i] = hwaddr[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		dev->perm_addr[i] = dev->dev_addr[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	sprintf(dev->name, "vif%d.%d", (int)handle, (int)port_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	dev->netdev_ops = &vsw_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	dev->ethtool_ops = &vsw_ethtool_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	dev->watchdog_timeo = VSW_TX_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	dev->hw_features = NETIF_F_HW_CSUM | NETIF_F_SG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	dev->features = dev->hw_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	/* MTU range: 68 - 65535 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	dev->min_mtu = ETH_MIN_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	dev->max_mtu = VNET_MAX_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	SET_NETDEV_DEV(dev, &vdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	return dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static struct ldc_channel_config vsw_ldc_cfg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	.event		= sunvnet_event_common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	.mtu		= 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	.mode		= LDC_MODE_UNRELIABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static struct vio_driver_ops vsw_vio_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	.send_attr		= sunvnet_send_attr_common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	.handle_attr		= sunvnet_handle_attr_common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	.handshake_complete	= sunvnet_handshake_complete_common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static const char *remote_macaddr_prop = "remote-mac-address";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static const char *id_prop = "id";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static int vsw_port_probe(struct vio_dev *vdev, const struct vio_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	struct mdesc_handle *hp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	struct vnet_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	struct vnet *vp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	const u64 *rmac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	int len, i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	const u64 *port_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	u64 handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	hp = mdesc_grab();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	rmac = mdesc_get_property(hp, vdev->mp, remote_macaddr_prop, &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	if (!rmac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		pr_err("Port lacks %s property\n", remote_macaddr_prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		mdesc_release(hp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	port_id = mdesc_get_property(hp, vdev->mp, id_prop, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	if (!port_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		pr_err("Port lacks %s property\n", id_prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		mdesc_release(hp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	/* Get (or create) the vnet associated with this port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	vp = vsw_get_vnet(hp, vdev->mp, &handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	if (IS_ERR(vp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		err = PTR_ERR(vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		pr_err("Failed to get vnet for vsw-port\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		mdesc_release(hp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	mdesc_release(hp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	dev = vsw_alloc_netdev(vsw_port_hwaddr, vdev, handle, *port_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (IS_ERR(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		err = PTR_ERR(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		pr_err("Failed to alloc netdev for vsw-port\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	port = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	INIT_LIST_HEAD(&port->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	for (i = 0; i < ETH_ALEN; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		port->raddr[i] = (*rmac >> (5 - i) * 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	port->vp = vp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	port->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	port->switch_port = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	port->tso = false; /* no tso in vsw, misbehaves in bridge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	port->tsolen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	/* Mark the port as belonging to ldmvsw which directs the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	 * the common code to use the net_device in the vnet_port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	 * rather than the net_device in the vnet (which is used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	 * by sunvnet). This bit is used by the VNET_PORT_TO_NET_DEVICE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	 * macro.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	port->vsw = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	err = vio_driver_init(&port->vio, vdev, VDEV_NETWORK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			      vsw_versions, ARRAY_SIZE(vsw_versions),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 			      &vsw_vio_ops, dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		goto err_out_free_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	err = vio_ldc_alloc(&port->vio, &vsw_ldc_cfg, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		goto err_out_free_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	dev_set_drvdata(&vdev->dev, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	netif_napi_add(dev, &port->napi, sunvnet_poll_common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		       NAPI_POLL_WEIGHT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	spin_lock_irqsave(&vp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	list_add_rcu(&port->list, &vp->port_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	spin_unlock_irqrestore(&vp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	timer_setup(&port->clean_timer, sunvnet_clean_timer_expire_common, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	err = register_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		pr_err("Cannot register net device, aborting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		goto err_out_del_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	spin_lock_irqsave(&vp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	sunvnet_port_add_txq_common(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	spin_unlock_irqrestore(&vp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	napi_enable(&port->napi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	vio_port_up(&port->vio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	/* assure no carrier until we receive an LDC_EVENT_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	 * even if the vsw config script tries to force us up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	netif_carrier_off(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	netdev_info(dev, "LDOM vsw-port %pM\n", dev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	pr_info("%s: PORT ( remote-mac %pM%s )\n", dev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		port->raddr, " switch-port");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) err_out_del_timer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	del_timer_sync(&port->clean_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	list_del_rcu(&port->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	netif_napi_del(&port->napi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	dev_set_drvdata(&vdev->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	vio_ldc_free(&port->vio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) err_out_free_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static int vsw_port_remove(struct vio_dev *vdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	struct vnet_port *port = dev_get_drvdata(&vdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	if (port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		del_timer_sync(&port->vio.timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		del_timer_sync(&port->clean_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		napi_disable(&port->napi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		unregister_netdev(port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		list_del_rcu(&port->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		spin_lock_irqsave(&port->vp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		sunvnet_port_rm_txq_common(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		spin_unlock_irqrestore(&port->vp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		netif_napi_del(&port->napi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		sunvnet_port_free_tx_bufs_common(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		vio_ldc_free(&port->vio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		dev_set_drvdata(&vdev->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		free_netdev(port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static void vsw_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	struct vnet *vp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	/* just need to free up the vnet list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	mutex_lock(&vnet_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	while (!list_empty(&vnet_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		vp = list_first_entry(&vnet_list, struct vnet, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		list_del(&vp->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		/* vio_unregister_driver() should have cleaned up port_list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		if (!list_empty(&vp->port_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 			pr_err("Ports not removed by VIO subsystem!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		kfree(vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	mutex_unlock(&vnet_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) static const struct vio_device_id vsw_port_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		.type = "vsw-port",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) MODULE_DEVICE_TABLE(vio, vsw_port_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) static struct vio_driver vsw_port_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	.id_table	= vsw_port_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	.probe		= vsw_port_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	.remove		= vsw_port_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	.name		= "vsw_port",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static int __init vsw_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	pr_info("%s\n", version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	return vio_register_driver(&vsw_port_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) static void __exit vsw_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	vio_unregister_driver(&vsw_port_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	vsw_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) module_init(vsw_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) module_exit(vsw_exit);