Aaron Young says:

====================
ldmvsw: Add ldmvsw driver

This series adds a new Logical Domains vSwitch (ldmvsw) driver.

The ldmvsw driver code will live in the drivers/net/ethernet/sun/
directory and will operate on Oracle systems running SPARC Linux in a
Logical Domains environment (typically in the control domain).

The ldmvsw driver is very similar in function to the existing sunvnet
driver. Ldmvsw creates a network interface for each "vsw-port" node
found in the Machine Description (MD) of a service domain. These
nodes correspond to ports on a vswitch created by the logical domains
manager. The created network interface(s) can be used by bridge/vswitch
software (such as the Linux bridge or Open vSwitch) to provide
guest domain(s) with network interconnectivity or connectivity
to a physical network.

Here is a example diagram of ldmvsw driver usage in a logical
domain environment to provide a guest domain with network connectivity
to a physical NIC on the service domain:

   +----------------+             +-----------------
   | Service Domain |             |  Guest domain  |
   |                |             |                |
   |  LinuxBridge   |             |                |
   |    |    |      |             |                |
   |   NIC Ldmvsw   |             |    Sunvnet     |
   +----------------+             +----------------+
        |    |           LDC              |
       LAN   ------------------------------

As stated, the sunvnet and ldmvsw drivers are _very_ similar in function.
They both create network interface(s) to receive/transmit network
traffic across LDC network channel(s). Since the driver is so similar
in function to sunvnet, the approach will be as follows to integrate
the driver and take advantage of common code:

Patch #1: Split sunvnet.c driver into sunvnet.c and sunvnet_common.c
Patch #2: Modify the sunvnet_common code and data structures to be compatible
          with both the sunvnet and ldmvsw drivers.
Patch #3: Add the new ldmvsw.c driver code
Patch #4: Checkpatch cleanup of the sunvnet/sunvnet_common code.

NOTE - Patch#1 renames a file (sunvnet.h -> sunvnet_common.h). When generating
the patches (using git format-patch), I had to use the --no-renames option
otherwise patch#1 would NOT apply using 'patch -p1' - which as I
understand is a requirement for patch acceptance. I wasn't sure if this
is proper thing to do.  Please advise if not. Thanks.

v2 changes:
  * change all EXPORT_SYMBOL declarations to EXPORT_SYMBOL_GPL
  * remove inline attribute for external function port_is_up_common()
  * Give all exported/global funcs in sunvnet_common.c a 'sunvnet_' prefix
    to avoid kernel global namespace pollution/collisions
  * ldmvsw.c: Order local variable declarations from longest to shortest line
  * ldmvsw.c: register the netdevice after all supporting state is ready/setup.
              NOTE: The consensus at Oracle is that the following functions
                    must be done AFTER register_netdev() - this is the same
                    ordering currently used in the sunvnet driver:
                    1. sunvnet_port_add_txq_common() - needs registered netdev
                    2. napi_enable() - requires registered netdev
                    3. vio_port_up() - as soon as this function is called
                                       LDC handshake messages will come in
                                       which must be handled by the napi code.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
David S. Miller 2016-03-18 19:33:05 -04:00
Родитель 1e6bb1a354 dc153f850d
Коммит 70063e9499
8 изменённых файлов: 2432 добавлений и 1821 удалений

Просмотреть файл

@ -102,6 +102,7 @@ CONFIG_SUNLANCE=m
CONFIG_HAPPYMEAL=m
CONFIG_SUNGEM=m
CONFIG_SUNVNET=m
CONFIG_LDMVSW=m
CONFIG_NET_PCI=y
CONFIG_E1000=m
CONFIG_E1000E=m

Просмотреть файл

@ -69,12 +69,28 @@ config CASSINI
Support for the Sun Cassini chip, aka Sun GigaSwift Ethernet. See also
<http://docs.oracle.com/cd/E19113-01/giga.ether.pci/817-4341-10/817-4341-10.pdf>.
config SUNVNET_COMMON
bool
depends on SUN_LDOMS
default y if SUN_LDOMS
config SUNVNET
tristate "Sun Virtual Network support"
depends on SUN_LDOMS
---help---
Support for virtual network devices under Sun Logical Domains.
config LDMVSW
tristate "Sun4v LDoms Virtual Switch support"
depends on SUN_LDOMS
---help---
Support for virtual switch devices under Sun4v Logical Domains.
This driver adds a network interface for every vsw-port node
found in the machine description of a service domain.
Linux bridge/switch software can use these interfaces for
guest domain network interconnectivity or guest domain
connection to a physical network on a service domain.
config NIU
tristate "Sun Neptune 10Gbit Ethernet support"
depends on PCI

Просмотреть файл

@ -7,5 +7,7 @@ obj-$(CONFIG_SUNQE) += sunqe.o
obj-$(CONFIG_SUNBMAC) += sunbmac.o
obj-$(CONFIG_SUNGEM) += sungem.o
obj-$(CONFIG_CASSINI) += cassini.o
obj-$(CONFIG_SUNVNET_COMMON) += sunvnet_common.o
obj-$(CONFIG_SUNVNET) += sunvnet.o
obj-$(CONFIG_LDMVSW) += ldmvsw.o
obj-$(CONFIG_NIU) += niu.o

Просмотреть файл

@ -0,0 +1,468 @@
/* ldmvsw.c: Sun4v LDOM Virtual Switch Driver.
*
* Copyright (C) 2016 Oracle. All rights reserved.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/delay.h>
#include <linux/etherdevice.h>
#include <linux/ethtool.h>
#include <linux/highmem.h>
#include <linux/if_vlan.h>
#include <linux/init.h>
#include <linux/kconfig.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/netdevice.h>
#include <linux/slab.h>
#include <linux/types.h>
#if defined(CONFIG_IPV6)
#include <linux/icmpv6.h>
#endif
#include <net/ip.h>
#include <net/icmp.h>
#include <net/route.h>
#include <asm/vio.h>
#include <asm/ldc.h>
/* This driver makes use of the common code in sunvnet_common.c */
#include "sunvnet_common.h"
/* Length of time before we decide the hardware is hung,
* and dev->tx_timeout() should be called to fix the problem.
*/
#define VSW_TX_TIMEOUT (10 * HZ)
/* Static HW Addr used for the network interfaces representing vsw ports */
static u8 vsw_port_hwaddr[ETH_ALEN] = {0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
#define DRV_MODULE_NAME "ldmvsw"
#define DRV_MODULE_VERSION "1.0"
#define DRV_MODULE_RELDATE "Jan 15, 2016"
static char version[] =
DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
MODULE_AUTHOR("Oracle");
MODULE_DESCRIPTION("Sun4v LDOM Virtual Switch Driver");
MODULE_LICENSE("GPL");
MODULE_VERSION(DRV_MODULE_VERSION);
/* Ordered from largest major to lowest */
static struct vio_version vsw_versions[] = {
{ .major = 1, .minor = 8 },
{ .major = 1, .minor = 7 },
{ .major = 1, .minor = 6 },
{ .major = 1, .minor = 0 },
};
static void vsw_get_drvinfo(struct net_device *dev,
struct ethtool_drvinfo *info)
{
strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
}
static u32 vsw_get_msglevel(struct net_device *dev)
{
struct vnet_port *port = netdev_priv(dev);
return port->vp->msg_enable;
}
static void vsw_set_msglevel(struct net_device *dev, u32 value)
{
struct vnet_port *port = netdev_priv(dev);
port->vp->msg_enable = value;
}
static const struct ethtool_ops vsw_ethtool_ops = {
.get_drvinfo = vsw_get_drvinfo,
.get_msglevel = vsw_get_msglevel,
.set_msglevel = vsw_set_msglevel,
.get_link = ethtool_op_get_link,
};
static LIST_HEAD(vnet_list);
static DEFINE_MUTEX(vnet_list_mutex);
/* func arg to vnet_start_xmit_common() to get the proper tx port */
static struct vnet_port *vsw_tx_port_find(struct sk_buff *skb,
struct net_device *dev)
{
struct vnet_port *port = netdev_priv(dev);
return port;
}
static u16 vsw_select_queue(struct net_device *dev, struct sk_buff *skb,
void *accel_priv, select_queue_fallback_t fallback)
{
struct vnet_port *port = netdev_priv(dev);
if (!port)
return 0;
return port->q_index;
}
/* Wrappers to common functions */
static int vsw_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
return sunvnet_start_xmit_common(skb, dev, vsw_tx_port_find);
}
static void vsw_set_rx_mode(struct net_device *dev)
{
struct vnet_port *port = netdev_priv(dev);
return sunvnet_set_rx_mode_common(dev, port->vp);
}
#ifdef CONFIG_NET_POLL_CONTROLLER
static void vsw_poll_controller(struct net_device *dev)
{
struct vnet_port *port = netdev_priv(dev);
return sunvnet_poll_controller_common(dev, port->vp);
}
#endif
static const struct net_device_ops vsw_ops = {
.ndo_open = sunvnet_open_common,
.ndo_stop = sunvnet_close_common,
.ndo_set_rx_mode = vsw_set_rx_mode,
.ndo_set_mac_address = sunvnet_set_mac_addr_common,
.ndo_validate_addr = eth_validate_addr,
.ndo_tx_timeout = sunvnet_tx_timeout_common,
.ndo_change_mtu = sunvnet_change_mtu_common,
.ndo_start_xmit = vsw_start_xmit,
.ndo_select_queue = vsw_select_queue,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = vsw_poll_controller,
#endif
};
static const char *local_mac_prop = "local-mac-address";
static const char *cfg_handle_prop = "cfg-handle";
static struct vnet *vsw_get_vnet(struct mdesc_handle *hp,
u64 port_node,
u64 *handle)
{
struct vnet *vp;
struct vnet *iter;
const u64 *local_mac = NULL;
const u64 *cfghandle = NULL;
u64 a;
/* Get the parent virtual-network-switch macaddr and cfghandle */
mdesc_for_each_arc(a, hp, port_node, MDESC_ARC_TYPE_BACK) {
u64 target = mdesc_arc_target(hp, a);
const char *name;
name = mdesc_get_property(hp, target, "name", NULL);
if (!name || strcmp(name, "virtual-network-switch"))
continue;
local_mac = mdesc_get_property(hp, target,
local_mac_prop, NULL);
cfghandle = mdesc_get_property(hp, target,
cfg_handle_prop, NULL);
break;
}
if (!local_mac || !cfghandle)
return ERR_PTR(-ENODEV);
/* find or create associated vnet */
vp = NULL;
mutex_lock(&vnet_list_mutex);
list_for_each_entry(iter, &vnet_list, list) {
if (iter->local_mac == *local_mac) {
vp = iter;
break;
}
}
if (!vp) {
vp = kzalloc(sizeof(*vp), GFP_KERNEL);
if (unlikely(!vp)) {
mutex_unlock(&vnet_list_mutex);
return ERR_PTR(-ENOMEM);
}
spin_lock_init(&vp->lock);
INIT_LIST_HEAD(&vp->port_list);
INIT_LIST_HEAD(&vp->list);
vp->local_mac = *local_mac;
list_add(&vp->list, &vnet_list);
}
mutex_unlock(&vnet_list_mutex);
*handle = (u64)*cfghandle;
return vp;
}
static struct net_device *vsw_alloc_netdev(u8 hwaddr[],
struct vio_dev *vdev,
u64 handle,
u64 port_id)
{
struct net_device *dev;
struct vnet_port *port;
int i;
dev = alloc_etherdev_mqs(sizeof(*port), VNET_MAX_TXQS, 1);
if (!dev)
return ERR_PTR(-ENOMEM);
dev->needed_headroom = VNET_PACKET_SKIP + 8;
dev->needed_tailroom = 8;
for (i = 0; i < ETH_ALEN; i++) {
dev->dev_addr[i] = hwaddr[i];
dev->perm_addr[i] = dev->dev_addr[i];
}
sprintf(dev->name, "vif%d.%d", (int)handle, (int)port_id);
dev->netdev_ops = &vsw_ops;
dev->ethtool_ops = &vsw_ethtool_ops;
dev->watchdog_timeo = VSW_TX_TIMEOUT;
dev->hw_features = NETIF_F_TSO | NETIF_F_GSO | NETIF_F_GSO_SOFTWARE |
NETIF_F_HW_CSUM | NETIF_F_SG;
dev->features = dev->hw_features;
SET_NETDEV_DEV(dev, &vdev->dev);
return dev;
}
static struct ldc_channel_config vsw_ldc_cfg = {
.event = sunvnet_event_common,
.mtu = 64,
.mode = LDC_MODE_UNRELIABLE,
};
static struct vio_driver_ops vsw_vio_ops = {
.send_attr = sunvnet_send_attr_common,
.handle_attr = sunvnet_handle_attr_common,
.handshake_complete = sunvnet_handshake_complete_common,
};
static void print_version(void)
{
printk_once(KERN_INFO "%s", version);
}
static const char *remote_macaddr_prop = "remote-mac-address";
static const char *id_prop = "id";
static int vsw_port_probe(struct vio_dev *vdev, const struct vio_device_id *id)
{
struct mdesc_handle *hp;
struct vnet_port *port;
unsigned long flags;
struct vnet *vp;
struct net_device *dev;
const u64 *rmac;
int len, i, err;
const u64 *port_id;
u64 handle;
print_version();
hp = mdesc_grab();
rmac = mdesc_get_property(hp, vdev->mp, remote_macaddr_prop, &len);
err = -ENODEV;
if (!rmac) {
pr_err("Port lacks %s property\n", remote_macaddr_prop);
mdesc_release(hp);
return err;
}
port_id = mdesc_get_property(hp, vdev->mp, id_prop, NULL);
err = -ENODEV;
if (!port_id) {
pr_err("Port lacks %s property\n", id_prop);
mdesc_release(hp);
return err;
}
/* Get (or create) the vnet associated with this port */
vp = vsw_get_vnet(hp, vdev->mp, &handle);
if (unlikely(IS_ERR(vp))) {
err = PTR_ERR(vp);
pr_err("Failed to get vnet for vsw-port\n");
mdesc_release(hp);
return err;
}
mdesc_release(hp);
dev = vsw_alloc_netdev(vsw_port_hwaddr, vdev, handle, *port_id);
if (IS_ERR(dev)) {
err = PTR_ERR(dev);
pr_err("Failed to alloc netdev for vsw-port\n");
return err;
}
port = netdev_priv(dev);
INIT_LIST_HEAD(&port->list);
for (i = 0; i < ETH_ALEN; i++)
port->raddr[i] = (*rmac >> (5 - i) * 8) & 0xff;
port->vp = vp;
port->dev = dev;
port->switch_port = 1;
port->tso = true;
port->tsolen = 0;
/* Mark the port as belonging to ldmvsw which directs the
* the common code to use the net_device in the vnet_port
* rather than the net_device in the vnet (which is used
* by sunvnet). This bit is used by the VNET_PORT_TO_NET_DEVICE
* macro.
*/
port->vsw = 1;
err = vio_driver_init(&port->vio, vdev, VDEV_NETWORK,
vsw_versions, ARRAY_SIZE(vsw_versions),
&vsw_vio_ops, dev->name);
if (err)
goto err_out_free_dev;
err = vio_ldc_alloc(&port->vio, &vsw_ldc_cfg, port);
if (err)
goto err_out_free_dev;
dev_set_drvdata(&vdev->dev, port);
netif_napi_add(dev, &port->napi, sunvnet_poll_common,
NAPI_POLL_WEIGHT);
spin_lock_irqsave(&vp->lock, flags);
list_add_rcu(&port->list, &vp->port_list);
spin_unlock_irqrestore(&vp->lock, flags);
setup_timer(&port->clean_timer, sunvnet_clean_timer_expire_common,
(unsigned long)port);
err = register_netdev(dev);
if (err) {
pr_err("Cannot register net device, aborting\n");
goto err_out_del_timer;
}
spin_lock_irqsave(&vp->lock, flags);
sunvnet_port_add_txq_common(port);
spin_unlock_irqrestore(&vp->lock, flags);
napi_enable(&port->napi);
vio_port_up(&port->vio);
netdev_info(dev, "LDOM vsw-port %pM\n", dev->dev_addr);
pr_info("%s: PORT ( remote-mac %pM%s )\n", dev->name,
port->raddr, " switch-port");
return 0;
err_out_del_timer:
del_timer_sync(&port->clean_timer);
list_del_rcu(&port->list);
synchronize_rcu();
netif_napi_del(&port->napi);
dev_set_drvdata(&vdev->dev, NULL);
vio_ldc_free(&port->vio);
err_out_free_dev:
free_netdev(dev);
return err;
}
static int vsw_port_remove(struct vio_dev *vdev)
{
struct vnet_port *port = dev_get_drvdata(&vdev->dev);
unsigned long flags;
if (port) {
del_timer_sync(&port->vio.timer);
napi_disable(&port->napi);
list_del_rcu(&port->list);
synchronize_rcu();
del_timer_sync(&port->clean_timer);
spin_lock_irqsave(&port->vp->lock, flags);
sunvnet_port_rm_txq_common(port);
spin_unlock_irqrestore(&port->vp->lock, flags);
netif_napi_del(&port->napi);
sunvnet_port_free_tx_bufs_common(port);
vio_ldc_free(&port->vio);
dev_set_drvdata(&vdev->dev, NULL);
unregister_netdev(port->dev);
free_netdev(port->dev);
}
return 0;
}
static void vsw_cleanup(void)
{
struct vnet *vp;
/* just need to free up the vnet list */
mutex_lock(&vnet_list_mutex);
while (!list_empty(&vnet_list)) {
vp = list_first_entry(&vnet_list, struct vnet, list);
list_del(&vp->list);
/* vio_unregister_driver() should have cleaned up port_list */
if (!list_empty(&vp->port_list))
pr_err("Ports not removed by VIO subsystem!\n");
kfree(vp);
}
mutex_unlock(&vnet_list_mutex);
}
static const struct vio_device_id vsw_port_match[] = {
{
.type = "vsw-port",
},
{},
};
MODULE_DEVICE_TABLE(vio, vsw_port_match);
static struct vio_driver vsw_port_driver = {
.id_table = vsw_port_match,
.probe = vsw_port_probe,
.remove = vsw_port_remove,
.name = "vsw_port",
};
static int __init vsw_init(void)
{
return vio_register_driver(&vsw_port_driver);
}
static void __exit vsw_exit(void)
{
vio_unregister_driver(&vsw_port_driver);
vsw_cleanup();
}
module_init(vsw_init);
module_exit(vsw_exit);

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,114 +0,0 @@
#ifndef _SUNVNET_H
#define _SUNVNET_H
#include <linux/interrupt.h>
#define DESC_NCOOKIES(entry_size) \
((entry_size) - sizeof(struct vio_net_desc))
/* length of time before we decide the hardware is borked,
* and dev->tx_timeout() should be called to fix the problem
*/
#define VNET_TX_TIMEOUT (5 * HZ)
/* length of time (or less) we expect pending descriptors to be marked
* as VIO_DESC_DONE and skbs ready to be freed
*/
#define VNET_CLEAN_TIMEOUT ((HZ/100)+1)
#define VNET_MAXPACKET (65535ULL + ETH_HLEN + VLAN_HLEN)
#define VNET_TX_RING_SIZE 512
#define VNET_TX_WAKEUP_THRESH(dr) ((dr)->pending / 4)
#define VNET_MINTSO 2048 /* VIO protocol's minimum TSO len */
#define VNET_MAXTSO 65535 /* VIO protocol's maximum TSO len */
/* VNET packets are sent in buffers with the first 6 bytes skipped
* so that after the ethernet header the IPv4/IPv6 headers are aligned
* properly.
*/
#define VNET_PACKET_SKIP 6
#define VNET_MAXCOOKIES (VNET_MAXPACKET/PAGE_SIZE + 1)
struct vnet_tx_entry {
struct sk_buff *skb;
unsigned int ncookies;
struct ldc_trans_cookie cookies[VNET_MAXCOOKIES];
};
struct vnet;
struct vnet_port {
struct vio_driver_state vio;
struct hlist_node hash;
u8 raddr[ETH_ALEN];
unsigned switch_port:1;
unsigned tso:1;
unsigned __pad:14;
struct vnet *vp;
struct vnet_tx_entry tx_bufs[VNET_TX_RING_SIZE];
struct list_head list;
u32 stop_rx_idx;
bool stop_rx;
bool start_cons;
struct timer_list clean_timer;
u64 rmtu;
u16 tsolen;
struct napi_struct napi;
u32 napi_stop_idx;
bool napi_resume;
int rx_event;
u16 q_index;
};
static inline struct vnet_port *to_vnet_port(struct vio_driver_state *vio)
{
return container_of(vio, struct vnet_port, vio);
}
#define VNET_PORT_HASH_SIZE 16
#define VNET_PORT_HASH_MASK (VNET_PORT_HASH_SIZE - 1)
static inline unsigned int vnet_hashfn(u8 *mac)
{
unsigned int val = mac[4] ^ mac[5];
return val & (VNET_PORT_HASH_MASK);
}
struct vnet_mcast_entry {
u8 addr[ETH_ALEN];
u8 sent;
u8 hit;
struct vnet_mcast_entry *next;
};
struct vnet {
/* Protects port_list and port_hash. */
spinlock_t lock;
struct net_device *dev;
u32 msg_enable;
struct list_head port_list;
struct hlist_head port_hash[VNET_PORT_HASH_SIZE];
struct vnet_mcast_entry *mcast_list;
struct list_head list;
u64 local_mac;
int nports;
};
#endif /* _SUNVNET_H */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,145 @@
#ifndef _SUNVNETCOMMON_H
#define _SUNVNETCOMMON_H
#include <linux/interrupt.h>
/* length of time (or less) we expect pending descriptors to be marked
* as VIO_DESC_DONE and skbs ready to be freed
*/
#define VNET_CLEAN_TIMEOUT ((HZ / 100) + 1)
#define VNET_MAXPACKET (65535ULL + ETH_HLEN + VLAN_HLEN)
#define VNET_TX_RING_SIZE 512
#define VNET_TX_WAKEUP_THRESH(dr) ((dr)->pending / 4)
#define VNET_MINTSO 2048 /* VIO protocol's minimum TSO len */
#define VNET_MAXTSO 65535 /* VIO protocol's maximum TSO len */
/* VNET packets are sent in buffers with the first 6 bytes skipped
* so that after the ethernet header the IPv4/IPv6 headers are aligned
* properly.
*/
#define VNET_PACKET_SKIP 6
#define VNET_MAXCOOKIES (VNET_MAXPACKET / PAGE_SIZE + 1)
#define VNET_MAX_TXQS 16
struct vnet_tx_entry {
struct sk_buff *skb;
unsigned int ncookies;
struct ldc_trans_cookie cookies[VNET_MAXCOOKIES];
};
struct vnet;
/* Structure to describe a vnet-port or vsw-port in the MD.
* If the vsw bit is set, this structure represents a vswitch
* port, and the net_device can be found from ->dev. If the
* vsw bit is not set, the net_device is available from ->vp->dev.
* See the VNET_PORT_TO_NET_DEVICE macro below.
*/
struct vnet_port {
struct vio_driver_state vio;
struct hlist_node hash;
u8 raddr[ETH_ALEN];
unsigned switch_port:1;
unsigned tso:1;
unsigned vsw:1;
unsigned __pad:13;
struct vnet *vp;
struct net_device *dev;
struct vnet_tx_entry tx_bufs[VNET_TX_RING_SIZE];
struct list_head list;
u32 stop_rx_idx;
bool stop_rx;
bool start_cons;
struct timer_list clean_timer;
u64 rmtu;
u16 tsolen;
struct napi_struct napi;
u32 napi_stop_idx;
bool napi_resume;
int rx_event;
u16 q_index;
};
static inline struct vnet_port *to_vnet_port(struct vio_driver_state *vio)
{
return container_of(vio, struct vnet_port, vio);
}
#define VNET_PORT_HASH_SIZE 16
#define VNET_PORT_HASH_MASK (VNET_PORT_HASH_SIZE - 1)
static inline unsigned int vnet_hashfn(u8 *mac)
{
unsigned int val = mac[4] ^ mac[5];
return val & (VNET_PORT_HASH_MASK);
}
struct vnet_mcast_entry {
u8 addr[ETH_ALEN];
u8 sent;
u8 hit;
struct vnet_mcast_entry *next;
};
struct vnet {
/* Protects port_list and port_hash. */
spinlock_t lock;
struct net_device *dev;
u32 msg_enable;
struct list_head port_list;
struct hlist_head port_hash[VNET_PORT_HASH_SIZE];
struct vnet_mcast_entry *mcast_list;
struct list_head list;
u64 local_mac;
int nports;
};
/* Def used by common code to get the net_device from the proper location */
#define VNET_PORT_TO_NET_DEVICE(__port) \
((__port)->vsw ? (__port)->dev : (__port)->vp->dev)
/* Common funcs */
void sunvnet_clean_timer_expire_common(unsigned long port0);
int sunvnet_open_common(struct net_device *dev);
int sunvnet_close_common(struct net_device *dev);
void sunvnet_set_rx_mode_common(struct net_device *dev, struct vnet *vp);
int sunvnet_set_mac_addr_common(struct net_device *dev, void *p);
void sunvnet_tx_timeout_common(struct net_device *dev);
int sunvnet_change_mtu_common(struct net_device *dev, int new_mtu);
int sunvnet_start_xmit_common(struct sk_buff *skb, struct net_device *dev,
struct vnet_port *(*vnet_tx_port)
(struct sk_buff *, struct net_device *));
#ifdef CONFIG_NET_POLL_CONTROLLER
void sunvnet_poll_controller_common(struct net_device *dev, struct vnet *vp);
#endif
void sunvnet_event_common(void *arg, int event);
int sunvnet_send_attr_common(struct vio_driver_state *vio);
int sunvnet_handle_attr_common(struct vio_driver_state *vio, void *arg);
void sunvnet_handshake_complete_common(struct vio_driver_state *vio);
int sunvnet_poll_common(struct napi_struct *napi, int budget);
void sunvnet_port_free_tx_bufs_common(struct vnet_port *port);
bool sunvnet_port_is_up_common(struct vnet_port *vnet);
void sunvnet_port_add_txq_common(struct vnet_port *port);
void sunvnet_port_rm_txq_common(struct vnet_port *port);
#endif /* _SUNVNETCOMMON_H */