2005-04-16 22:20:36 +00:00
|
|
|
/* File veth.c created by Kyle A. Lucke on Mon Aug 7 2000. */
|
|
|
|
/*
|
|
|
|
* IBM eServer iSeries Virtual Ethernet Device Driver
|
|
|
|
* Copyright (C) 2001 Kyle A. Lucke (klucke@us.ibm.com), IBM Corp.
|
|
|
|
* Substantially cleaned up by:
|
|
|
|
* Copyright (C) 2003 David Gibson <dwg@au1.ibm.com>, IBM Corporation.
|
2005-09-06 00:39:38 +00:00
|
|
|
* Copyright (C) 2004-2005 Michael Ellerman, IBM Corporation.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This module implements the virtual ethernet device for iSeries LPAR
|
|
|
|
* Linux. It uses hypervisor message passing to implement an
|
|
|
|
* ethernet-like network device communicating between partitions on
|
|
|
|
* the iSeries.
|
|
|
|
*
|
|
|
|
* The iSeries LPAR hypervisor currently allows for up to 16 different
|
|
|
|
* virtual ethernets. These are all dynamically configurable on
|
|
|
|
* OS/400 partitions, but dynamic configuration is not supported under
|
|
|
|
* Linux yet. An ethXX network device will be created for each
|
|
|
|
* virtual ethernet this partition is connected to.
|
|
|
|
*
|
|
|
|
* - This driver is responsible for routing packets to and from other
|
|
|
|
* partitions. The MAC addresses used by the virtual ethernets
|
|
|
|
* contains meaning and must not be modified.
|
|
|
|
*
|
|
|
|
* - Having 2 virtual ethernets to the same remote partition DOES NOT
|
|
|
|
* double the available bandwidth. The 2 devices will share the
|
|
|
|
* available hypervisor bandwidth.
|
|
|
|
*
|
|
|
|
* - If you send a packet to your own mac address, it will just be
|
|
|
|
* dropped, you won't get it on the receive side.
|
|
|
|
*
|
|
|
|
* - Multicast is implemented by sending the frame frame to every
|
|
|
|
* other partition. It is the responsibility of the receiving
|
|
|
|
* partition to filter the addresses desired.
|
|
|
|
*
|
|
|
|
* Tunable parameters:
|
|
|
|
*
|
|
|
|
* VETH_NUMBUFFERS: This compile time option defaults to 120. It
|
|
|
|
* controls how much memory Linux will allocate per remote partition
|
|
|
|
* it is communicating with. It can be thought of as the maximum
|
|
|
|
* number of packets outstanding to a remote partition at a time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/ethtool.h>
|
2006-05-15 03:39:47 +00:00
|
|
|
#include <linux/if_ether.h>
|
2005-10-14 04:51:42 +00:00
|
|
|
|
|
|
|
#include <asm/abs_addr.h>
|
2005-11-02 04:10:38 +00:00
|
|
|
#include <asm/iseries/mf.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/uaccess.h>
|
2006-12-15 04:42:50 +00:00
|
|
|
#include <asm/firmware.h>
|
2005-11-02 00:55:28 +00:00
|
|
|
#include <asm/iseries/hv_lp_config.h>
|
2005-11-02 02:46:07 +00:00
|
|
|
#include <asm/iseries/hv_types.h>
|
2005-11-02 01:08:31 +00:00
|
|
|
#include <asm/iseries/hv_lp_event.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/iommu.h>
|
|
|
|
#include <asm/vio.h>
|
|
|
|
|
2005-09-01 01:28:57 +00:00
|
|
|
#undef DEBUG
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
MODULE_AUTHOR("Kyle Lucke <klucke@us.ibm.com>");
|
|
|
|
MODULE_DESCRIPTION("iSeries Virtual ethernet driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2005-09-01 01:29:27 +00:00
|
|
|
#define VETH_EVENT_CAP (0)
|
|
|
|
#define VETH_EVENT_FRAMES (1)
|
|
|
|
#define VETH_EVENT_MONITOR (2)
|
|
|
|
#define VETH_EVENT_FRAMES_ACK (3)
|
2005-09-01 01:29:25 +00:00
|
|
|
|
|
|
|
#define VETH_MAX_ACKS_PER_MSG (20)
|
|
|
|
#define VETH_MAX_FRAMES_PER_MSG (6)
|
|
|
|
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_frames_data {
|
2005-09-01 01:29:25 +00:00
|
|
|
u32 addr[VETH_MAX_FRAMES_PER_MSG];
|
|
|
|
u16 len[VETH_MAX_FRAMES_PER_MSG];
|
|
|
|
u32 eofmask;
|
|
|
|
};
|
|
|
|
#define VETH_EOF_SHIFT (32-VETH_MAX_FRAMES_PER_MSG)
|
|
|
|
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_frames_ack_data {
|
2005-09-01 01:29:25 +00:00
|
|
|
u16 token[VETH_MAX_ACKS_PER_MSG];
|
|
|
|
};
|
|
|
|
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_cap_data {
|
2005-09-01 01:29:25 +00:00
|
|
|
u8 caps_version;
|
|
|
|
u8 rsvd1;
|
|
|
|
u16 num_buffers;
|
|
|
|
u16 ack_threshold;
|
|
|
|
u16 rsvd2;
|
|
|
|
u32 ack_timeout;
|
|
|
|
u32 rsvd3;
|
|
|
|
u64 rsvd4[3];
|
|
|
|
};
|
|
|
|
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_lpevent {
|
2005-09-01 01:29:25 +00:00
|
|
|
struct HvLpEvent base_event;
|
|
|
|
union {
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_cap_data caps_data;
|
|
|
|
struct veth_frames_data frames_data;
|
|
|
|
struct veth_frames_ack_data frames_ack_data;
|
2005-09-01 01:29:25 +00:00
|
|
|
} u;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2005-09-01 01:29:29 +00:00
|
|
|
#define DRV_NAME "iseries_veth"
|
|
|
|
#define DRV_VERSION "2.0"
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#define VETH_NUMBUFFERS (120)
|
|
|
|
#define VETH_ACKTIMEOUT (1000000) /* microseconds */
|
|
|
|
#define VETH_MAX_MCAST (12)
|
|
|
|
|
|
|
|
#define VETH_MAX_MTU (9000)
|
|
|
|
|
|
|
|
#if VETH_NUMBUFFERS < 10
|
|
|
|
#define ACK_THRESHOLD (1)
|
|
|
|
#elif VETH_NUMBUFFERS < 20
|
|
|
|
#define ACK_THRESHOLD (4)
|
|
|
|
#elif VETH_NUMBUFFERS < 40
|
|
|
|
#define ACK_THRESHOLD (10)
|
|
|
|
#else
|
|
|
|
#define ACK_THRESHOLD (20)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define VETH_STATE_SHUTDOWN (0x0001)
|
|
|
|
#define VETH_STATE_OPEN (0x0002)
|
|
|
|
#define VETH_STATE_RESET (0x0004)
|
|
|
|
#define VETH_STATE_SENTMON (0x0008)
|
|
|
|
#define VETH_STATE_SENTCAPS (0x0010)
|
|
|
|
#define VETH_STATE_GOTCAPACK (0x0020)
|
|
|
|
#define VETH_STATE_GOTCAPS (0x0040)
|
|
|
|
#define VETH_STATE_SENTCAPACK (0x0080)
|
|
|
|
#define VETH_STATE_READY (0x0100)
|
|
|
|
|
|
|
|
struct veth_msg {
|
|
|
|
struct veth_msg *next;
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_frames_data data;
|
2005-04-16 22:20:36 +00:00
|
|
|
int token;
|
2005-09-01 01:29:06 +00:00
|
|
|
int in_use;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct sk_buff *skb;
|
|
|
|
struct device *dev;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct veth_lpar_connection {
|
|
|
|
HvLpIndex remote_lp;
|
2006-11-22 14:57:56 +00:00
|
|
|
struct delayed_work statemachine_wq;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct veth_msg *msgs;
|
|
|
|
int num_events;
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_cap_data local_caps;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-09-01 01:29:09 +00:00
|
|
|
struct kobject kobject;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct timer_list ack_timer;
|
|
|
|
|
2005-09-01 01:29:17 +00:00
|
|
|
struct timer_list reset_timer;
|
|
|
|
unsigned int reset_timeout;
|
|
|
|
unsigned long last_contact;
|
|
|
|
int outstanding_tx;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
spinlock_t lock;
|
|
|
|
unsigned long state;
|
|
|
|
HvLpInstanceId src_inst;
|
|
|
|
HvLpInstanceId dst_inst;
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_lpevent cap_event, cap_ack_event;
|
2005-04-16 22:20:36 +00:00
|
|
|
u16 pending_acks[VETH_MAX_ACKS_PER_MSG];
|
|
|
|
u32 num_pending_acks;
|
|
|
|
|
|
|
|
int num_ack_events;
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_cap_data remote_caps;
|
2005-04-16 22:20:36 +00:00
|
|
|
u32 ack_timeout;
|
|
|
|
|
|
|
|
struct veth_msg *msg_stack_head;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct veth_port {
|
|
|
|
struct device *dev;
|
|
|
|
u64 mac_addr;
|
|
|
|
HvLpIndexMap lpar_map;
|
|
|
|
|
2005-09-01 01:29:18 +00:00
|
|
|
/* queue_lock protects the stopped_map and dev's queue. */
|
|
|
|
spinlock_t queue_lock;
|
|
|
|
HvLpIndexMap stopped_map;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-09-01 01:29:18 +00:00
|
|
|
/* mcast_gate protects promiscuous, num_mcast & mcast_addr. */
|
2005-04-16 22:20:36 +00:00
|
|
|
rwlock_t mcast_gate;
|
|
|
|
int promiscuous;
|
|
|
|
int num_mcast;
|
|
|
|
u64 mcast_addr[VETH_MAX_MCAST];
|
2005-09-01 01:29:21 +00:00
|
|
|
|
|
|
|
struct kobject kobject;
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static HvLpIndex this_lp;
|
|
|
|
static struct veth_lpar_connection *veth_cnx[HVMAXARCHITECTEDLPS]; /* = 0 */
|
|
|
|
static struct net_device *veth_dev[HVMAXARCHITECTEDVIRTUALLANS]; /* = 0 */
|
|
|
|
|
|
|
|
static int veth_start_xmit(struct sk_buff *skb, struct net_device *dev);
|
|
|
|
static void veth_recycle_msg(struct veth_lpar_connection *, struct veth_msg *);
|
2005-09-01 01:29:18 +00:00
|
|
|
static void veth_wake_queues(struct veth_lpar_connection *cnx);
|
|
|
|
static void veth_stop_queues(struct veth_lpar_connection *cnx);
|
2005-09-01 01:29:27 +00:00
|
|
|
static void veth_receive(struct veth_lpar_connection *, struct veth_lpevent *);
|
2005-09-01 01:29:09 +00:00
|
|
|
static void veth_release_connection(struct kobject *kobject);
|
2005-09-01 01:29:17 +00:00
|
|
|
static void veth_timed_ack(unsigned long ptr);
|
|
|
|
static void veth_timed_reset(unsigned long ptr);
|
2005-09-01 01:29:09 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Utility functions
|
|
|
|
*/
|
|
|
|
|
2005-09-01 01:28:57 +00:00
|
|
|
#define veth_info(fmt, args...) \
|
2005-09-01 01:29:29 +00:00
|
|
|
printk(KERN_INFO DRV_NAME ": " fmt, ## args)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define veth_error(fmt, args...) \
|
2005-09-01 01:29:29 +00:00
|
|
|
printk(KERN_ERR DRV_NAME ": Error: " fmt, ## args)
|
2005-09-01 01:28:57 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define veth_debug(fmt, args...) \
|
2005-09-01 01:29:29 +00:00
|
|
|
printk(KERN_DEBUG DRV_NAME ": " fmt, ## args)
|
2005-09-01 01:28:57 +00:00
|
|
|
#else
|
|
|
|
#define veth_debug(fmt, args...) do {} while (0)
|
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-09-01 01:29:05 +00:00
|
|
|
/* You must hold the connection's lock when you call this function. */
|
2005-04-16 22:20:36 +00:00
|
|
|
static inline void veth_stack_push(struct veth_lpar_connection *cnx,
|
|
|
|
struct veth_msg *msg)
|
|
|
|
{
|
|
|
|
msg->next = cnx->msg_stack_head;
|
|
|
|
cnx->msg_stack_head = msg;
|
|
|
|
}
|
|
|
|
|
2005-09-01 01:29:05 +00:00
|
|
|
/* You must hold the connection's lock when you call this function. */
|
2005-04-16 22:20:36 +00:00
|
|
|
static inline struct veth_msg *veth_stack_pop(struct veth_lpar_connection *cnx)
|
|
|
|
{
|
|
|
|
struct veth_msg *msg;
|
|
|
|
|
|
|
|
msg = cnx->msg_stack_head;
|
|
|
|
if (msg)
|
|
|
|
cnx->msg_stack_head = cnx->msg_stack_head->next;
|
2005-09-01 01:29:05 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2005-09-01 01:29:18 +00:00
|
|
|
/* You must hold the connection's lock when you call this function. */
|
|
|
|
static inline int veth_stack_is_empty(struct veth_lpar_connection *cnx)
|
|
|
|
{
|
|
|
|
return cnx->msg_stack_head == NULL;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static inline HvLpEvent_Rc
|
|
|
|
veth_signalevent(struct veth_lpar_connection *cnx, u16 subtype,
|
|
|
|
HvLpEvent_AckInd ackind, HvLpEvent_AckType acktype,
|
|
|
|
u64 token,
|
|
|
|
u64 data1, u64 data2, u64 data3, u64 data4, u64 data5)
|
|
|
|
{
|
|
|
|
return HvCallEvent_signalLpEventFast(cnx->remote_lp,
|
|
|
|
HvLpEvent_Type_VirtualLan,
|
|
|
|
subtype, ackind, acktype,
|
|
|
|
cnx->src_inst,
|
|
|
|
cnx->dst_inst,
|
|
|
|
token, data1, data2, data3,
|
|
|
|
data4, data5);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline HvLpEvent_Rc veth_signaldata(struct veth_lpar_connection *cnx,
|
|
|
|
u16 subtype, u64 token, void *data)
|
|
|
|
{
|
|
|
|
u64 *p = (u64 *) data;
|
|
|
|
|
|
|
|
return veth_signalevent(cnx, subtype, HvLpEvent_AckInd_NoAck,
|
|
|
|
HvLpEvent_AckType_ImmediateAck,
|
|
|
|
token, p[0], p[1], p[2], p[3], p[4]);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct veth_allocation {
|
|
|
|
struct completion c;
|
|
|
|
int num;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void veth_complete_allocation(void *parm, int number)
|
|
|
|
{
|
|
|
|
struct veth_allocation *vc = (struct veth_allocation *)parm;
|
|
|
|
|
|
|
|
vc->num = number;
|
|
|
|
complete(&vc->c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int veth_allocate_events(HvLpIndex rlp, int number)
|
|
|
|
{
|
2008-04-09 07:21:34 +00:00
|
|
|
struct veth_allocation vc =
|
|
|
|
{ COMPLETION_INITIALIZER_ONSTACK(vc.c), 0 };
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
mf_allocate_lp_events(rlp, HvLpEvent_Type_VirtualLan,
|
2005-09-01 01:29:27 +00:00
|
|
|
sizeof(struct veth_lpevent), number,
|
2005-04-16 22:20:36 +00:00
|
|
|
&veth_complete_allocation, &vc);
|
|
|
|
wait_for_completion(&vc.c);
|
|
|
|
|
|
|
|
return vc.num;
|
|
|
|
}
|
|
|
|
|
2005-09-01 01:29:20 +00:00
|
|
|
/*
|
|
|
|
* sysfs support
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct veth_cnx_attribute {
|
|
|
|
struct attribute attr;
|
|
|
|
ssize_t (*show)(struct veth_lpar_connection *, char *buf);
|
|
|
|
ssize_t (*store)(struct veth_lpar_connection *, const char *buf);
|
|
|
|
};
|
|
|
|
|
|
|
|
static ssize_t veth_cnx_attribute_show(struct kobject *kobj,
|
|
|
|
struct attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct veth_cnx_attribute *cnx_attr;
|
|
|
|
struct veth_lpar_connection *cnx;
|
|
|
|
|
|
|
|
cnx_attr = container_of(attr, struct veth_cnx_attribute, attr);
|
|
|
|
cnx = container_of(kobj, struct veth_lpar_connection, kobject);
|
|
|
|
|
|
|
|
if (!cnx_attr->show)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return cnx_attr->show(cnx, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CUSTOM_CNX_ATTR(_name, _format, _expression) \
|
|
|
|
static ssize_t _name##_show(struct veth_lpar_connection *cnx, char *buf)\
|
|
|
|
{ \
|
|
|
|
return sprintf(buf, _format, _expression); \
|
|
|
|
} \
|
|
|
|
struct veth_cnx_attribute veth_cnx_attr_##_name = __ATTR_RO(_name)
|
|
|
|
|
|
|
|
#define SIMPLE_CNX_ATTR(_name) \
|
|
|
|
CUSTOM_CNX_ATTR(_name, "%lu\n", (unsigned long)cnx->_name)
|
|
|
|
|
|
|
|
SIMPLE_CNX_ATTR(outstanding_tx);
|
|
|
|
SIMPLE_CNX_ATTR(remote_lp);
|
|
|
|
SIMPLE_CNX_ATTR(num_events);
|
|
|
|
SIMPLE_CNX_ATTR(src_inst);
|
|
|
|
SIMPLE_CNX_ATTR(dst_inst);
|
|
|
|
SIMPLE_CNX_ATTR(num_pending_acks);
|
|
|
|
SIMPLE_CNX_ATTR(num_ack_events);
|
|
|
|
CUSTOM_CNX_ATTR(ack_timeout, "%d\n", jiffies_to_msecs(cnx->ack_timeout));
|
|
|
|
CUSTOM_CNX_ATTR(reset_timeout, "%d\n", jiffies_to_msecs(cnx->reset_timeout));
|
|
|
|
CUSTOM_CNX_ATTR(state, "0x%.4lX\n", cnx->state);
|
|
|
|
CUSTOM_CNX_ATTR(last_contact, "%d\n", cnx->last_contact ?
|
|
|
|
jiffies_to_msecs(jiffies - cnx->last_contact) : 0);
|
|
|
|
|
|
|
|
#define GET_CNX_ATTR(_name) (&veth_cnx_attr_##_name.attr)
|
|
|
|
|
|
|
|
static struct attribute *veth_cnx_default_attrs[] = {
|
|
|
|
GET_CNX_ATTR(outstanding_tx),
|
|
|
|
GET_CNX_ATTR(remote_lp),
|
|
|
|
GET_CNX_ATTR(num_events),
|
|
|
|
GET_CNX_ATTR(reset_timeout),
|
|
|
|
GET_CNX_ATTR(last_contact),
|
|
|
|
GET_CNX_ATTR(state),
|
|
|
|
GET_CNX_ATTR(src_inst),
|
|
|
|
GET_CNX_ATTR(dst_inst),
|
|
|
|
GET_CNX_ATTR(num_pending_acks),
|
|
|
|
GET_CNX_ATTR(num_ack_events),
|
|
|
|
GET_CNX_ATTR(ack_timeout),
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct sysfs_ops veth_cnx_sysfs_ops = {
|
|
|
|
.show = veth_cnx_attribute_show
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct kobj_type veth_lpar_connection_ktype = {
|
|
|
|
.release = veth_release_connection,
|
|
|
|
.sysfs_ops = &veth_cnx_sysfs_ops,
|
|
|
|
.default_attrs = veth_cnx_default_attrs
|
|
|
|
};
|
|
|
|
|
2005-09-01 01:29:21 +00:00
|
|
|
struct veth_port_attribute {
|
|
|
|
struct attribute attr;
|
|
|
|
ssize_t (*show)(struct veth_port *, char *buf);
|
|
|
|
ssize_t (*store)(struct veth_port *, const char *buf);
|
|
|
|
};
|
|
|
|
|
|
|
|
static ssize_t veth_port_attribute_show(struct kobject *kobj,
|
|
|
|
struct attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct veth_port_attribute *port_attr;
|
|
|
|
struct veth_port *port;
|
|
|
|
|
|
|
|
port_attr = container_of(attr, struct veth_port_attribute, attr);
|
|
|
|
port = container_of(kobj, struct veth_port, kobject);
|
|
|
|
|
|
|
|
if (!port_attr->show)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return port_attr->show(port, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CUSTOM_PORT_ATTR(_name, _format, _expression) \
|
|
|
|
static ssize_t _name##_show(struct veth_port *port, char *buf) \
|
|
|
|
{ \
|
|
|
|
return sprintf(buf, _format, _expression); \
|
|
|
|
} \
|
|
|
|
struct veth_port_attribute veth_port_attr_##_name = __ATTR_RO(_name)
|
|
|
|
|
|
|
|
#define SIMPLE_PORT_ATTR(_name) \
|
|
|
|
CUSTOM_PORT_ATTR(_name, "%lu\n", (unsigned long)port->_name)
|
|
|
|
|
|
|
|
SIMPLE_PORT_ATTR(promiscuous);
|
|
|
|
SIMPLE_PORT_ATTR(num_mcast);
|
|
|
|
CUSTOM_PORT_ATTR(lpar_map, "0x%X\n", port->lpar_map);
|
|
|
|
CUSTOM_PORT_ATTR(stopped_map, "0x%X\n", port->stopped_map);
|
2009-01-06 14:40:06 +00:00
|
|
|
CUSTOM_PORT_ATTR(mac_addr, "0x%llX\n", port->mac_addr);
|
2005-09-01 01:29:21 +00:00
|
|
|
|
|
|
|
#define GET_PORT_ATTR(_name) (&veth_port_attr_##_name.attr)
|
|
|
|
static struct attribute *veth_port_default_attrs[] = {
|
|
|
|
GET_PORT_ATTR(mac_addr),
|
|
|
|
GET_PORT_ATTR(lpar_map),
|
|
|
|
GET_PORT_ATTR(stopped_map),
|
|
|
|
GET_PORT_ATTR(promiscuous),
|
|
|
|
GET_PORT_ATTR(num_mcast),
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct sysfs_ops veth_port_sysfs_ops = {
|
|
|
|
.show = veth_port_attribute_show
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct kobj_type veth_port_ktype = {
|
|
|
|
.sysfs_ops = &veth_port_sysfs_ops,
|
|
|
|
.default_attrs = veth_port_default_attrs
|
|
|
|
};
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* LPAR connection code
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline void veth_kick_statemachine(struct veth_lpar_connection *cnx)
|
|
|
|
{
|
2006-11-22 14:57:56 +00:00
|
|
|
schedule_delayed_work(&cnx->statemachine_wq, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void veth_take_cap(struct veth_lpar_connection *cnx,
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_lpevent *event)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cnx->lock, flags);
|
|
|
|
/* Receiving caps may mean the other end has just come up, so
|
|
|
|
* we need to reload the instance ID of the far end */
|
|
|
|
cnx->dst_inst =
|
|
|
|
HvCallEvent_getTargetLpInstanceId(cnx->remote_lp,
|
|
|
|
HvLpEvent_Type_VirtualLan);
|
|
|
|
|
|
|
|
if (cnx->state & VETH_STATE_GOTCAPS) {
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Received a second capabilities from LPAR %d.\n",
|
2005-04-16 22:20:36 +00:00
|
|
|
cnx->remote_lp);
|
|
|
|
event->base_event.xRc = HvLpEvent_Rc_BufferNotAvailable;
|
|
|
|
HvCallEvent_ackLpEvent((struct HvLpEvent *) event);
|
|
|
|
} else {
|
|
|
|
memcpy(&cnx->cap_event, event, sizeof(cnx->cap_event));
|
|
|
|
cnx->state |= VETH_STATE_GOTCAPS;
|
|
|
|
veth_kick_statemachine(cnx);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&cnx->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void veth_take_cap_ack(struct veth_lpar_connection *cnx,
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_lpevent *event)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cnx->lock, flags);
|
|
|
|
if (cnx->state & VETH_STATE_GOTCAPACK) {
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Received a second capabilities ack from LPAR %d.\n",
|
2005-04-16 22:20:36 +00:00
|
|
|
cnx->remote_lp);
|
|
|
|
} else {
|
|
|
|
memcpy(&cnx->cap_ack_event, event,
|
2009-10-02 16:55:19 +00:00
|
|
|
sizeof(cnx->cap_ack_event));
|
2005-04-16 22:20:36 +00:00
|
|
|
cnx->state |= VETH_STATE_GOTCAPACK;
|
|
|
|
veth_kick_statemachine(cnx);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&cnx->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void veth_take_monitor_ack(struct veth_lpar_connection *cnx,
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_lpevent *event)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cnx->lock, flags);
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_debug("cnx %d: lost connection.\n", cnx->remote_lp);
|
2005-09-01 01:29:00 +00:00
|
|
|
|
|
|
|
/* Avoid kicking the statemachine once we're shutdown.
|
|
|
|
* It's unnecessary and it could break veth_stop_connection(). */
|
|
|
|
|
|
|
|
if (! (cnx->state & VETH_STATE_SHUTDOWN)) {
|
|
|
|
cnx->state |= VETH_STATE_RESET;
|
|
|
|
veth_kick_statemachine(cnx);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&cnx->lock, flags);
|
|
|
|
}
|
|
|
|
|
2005-09-01 01:29:27 +00:00
|
|
|
static void veth_handle_ack(struct veth_lpevent *event)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
HvLpIndex rlp = event->base_event.xTargetLp;
|
|
|
|
struct veth_lpar_connection *cnx = veth_cnx[rlp];
|
|
|
|
|
|
|
|
BUG_ON(! cnx);
|
|
|
|
|
|
|
|
switch (event->base_event.xSubtype) {
|
2005-09-01 01:29:27 +00:00
|
|
|
case VETH_EVENT_CAP:
|
2005-04-16 22:20:36 +00:00
|
|
|
veth_take_cap_ack(cnx, event);
|
|
|
|
break;
|
2005-09-01 01:29:27 +00:00
|
|
|
case VETH_EVENT_MONITOR:
|
2005-04-16 22:20:36 +00:00
|
|
|
veth_take_monitor_ack(cnx, event);
|
|
|
|
break;
|
|
|
|
default:
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Unknown ack type %d from LPAR %d.\n",
|
|
|
|
event->base_event.xSubtype, rlp);
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2005-09-01 01:29:27 +00:00
|
|
|
static void veth_handle_int(struct veth_lpevent *event)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
HvLpIndex rlp = event->base_event.xSourceLp;
|
|
|
|
struct veth_lpar_connection *cnx = veth_cnx[rlp];
|
|
|
|
unsigned long flags;
|
2005-09-01 01:29:17 +00:00
|
|
|
int i, acked = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
BUG_ON(! cnx);
|
|
|
|
|
|
|
|
switch (event->base_event.xSubtype) {
|
2005-09-01 01:29:27 +00:00
|
|
|
case VETH_EVENT_CAP:
|
2005-04-16 22:20:36 +00:00
|
|
|
veth_take_cap(cnx, event);
|
|
|
|
break;
|
2005-09-01 01:29:27 +00:00
|
|
|
case VETH_EVENT_MONITOR:
|
2005-04-16 22:20:36 +00:00
|
|
|
/* do nothing... this'll hang out here til we're dead,
|
|
|
|
* and the hypervisor will return it for us. */
|
|
|
|
break;
|
2005-09-01 01:29:27 +00:00
|
|
|
case VETH_EVENT_FRAMES_ACK:
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&cnx->lock, flags);
|
2005-09-01 01:29:17 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < VETH_MAX_ACKS_PER_MSG; ++i) {
|
|
|
|
u16 msgnum = event->u.frames_ack_data.token[i];
|
|
|
|
|
2005-09-01 01:29:17 +00:00
|
|
|
if (msgnum < VETH_NUMBUFFERS) {
|
2005-04-16 22:20:36 +00:00
|
|
|
veth_recycle_msg(cnx, cnx->msgs + msgnum);
|
2005-09-01 01:29:17 +00:00
|
|
|
cnx->outstanding_tx--;
|
|
|
|
acked++;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2005-09-01 01:29:17 +00:00
|
|
|
|
2005-09-01 01:29:18 +00:00
|
|
|
if (acked > 0) {
|
2005-09-01 01:29:17 +00:00
|
|
|
cnx->last_contact = jiffies;
|
2005-09-01 01:29:18 +00:00
|
|
|
veth_wake_queues(cnx);
|
|
|
|
}
|
2005-09-01 01:29:17 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&cnx->lock, flags);
|
|
|
|
break;
|
2005-09-01 01:29:27 +00:00
|
|
|
case VETH_EVENT_FRAMES:
|
2005-04-16 22:20:36 +00:00
|
|
|
veth_receive(cnx, event);
|
|
|
|
break;
|
|
|
|
default:
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Unknown interrupt type %d from LPAR %d.\n",
|
|
|
|
event->base_event.xSubtype, rlp);
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static void veth_handle_event(struct HvLpEvent *event)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_lpevent *veth_event = (struct veth_lpevent *)event;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-01-12 02:47:43 +00:00
|
|
|
if (hvlpevent_is_ack(event))
|
2005-04-16 22:20:36 +00:00
|
|
|
veth_handle_ack(veth_event);
|
2006-01-12 02:47:43 +00:00
|
|
|
else
|
2005-04-16 22:20:36 +00:00
|
|
|
veth_handle_int(veth_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int veth_process_caps(struct veth_lpar_connection *cnx)
|
|
|
|
{
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_cap_data *remote_caps = &cnx->remote_caps;
|
2005-04-16 22:20:36 +00:00
|
|
|
int num_acks_needed;
|
|
|
|
|
|
|
|
/* Convert timer to jiffies */
|
|
|
|
cnx->ack_timeout = remote_caps->ack_timeout * HZ / 1000000;
|
|
|
|
|
|
|
|
if ( (remote_caps->num_buffers == 0)
|
|
|
|
|| (remote_caps->ack_threshold > VETH_MAX_ACKS_PER_MSG)
|
|
|
|
|| (remote_caps->ack_threshold == 0)
|
|
|
|
|| (cnx->ack_timeout == 0) ) {
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Received incompatible capabilities from LPAR %d.\n",
|
|
|
|
cnx->remote_lp);
|
2005-04-16 22:20:36 +00:00
|
|
|
return HvLpEvent_Rc_InvalidSubtypeData;
|
|
|
|
}
|
|
|
|
|
|
|
|
num_acks_needed = (remote_caps->num_buffers
|
|
|
|
/ remote_caps->ack_threshold) + 1;
|
|
|
|
|
|
|
|
/* FIXME: locking on num_ack_events? */
|
|
|
|
if (cnx->num_ack_events < num_acks_needed) {
|
|
|
|
int num;
|
|
|
|
|
|
|
|
num = veth_allocate_events(cnx->remote_lp,
|
|
|
|
num_acks_needed-cnx->num_ack_events);
|
|
|
|
if (num > 0)
|
|
|
|
cnx->num_ack_events += num;
|
|
|
|
|
|
|
|
if (cnx->num_ack_events < num_acks_needed) {
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Couldn't allocate enough ack events "
|
|
|
|
"for LPAR %d.\n", cnx->remote_lp);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return HvLpEvent_Rc_BufferNotAvailable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return HvLpEvent_Rc_Good;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: The gotos here are a bit dubious */
|
2006-11-22 14:57:56 +00:00
|
|
|
static void veth_statemachine(struct work_struct *work)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-11-22 14:57:56 +00:00
|
|
|
struct veth_lpar_connection *cnx =
|
|
|
|
container_of(work, struct veth_lpar_connection,
|
|
|
|
statemachine_wq.work);
|
2005-04-16 22:20:36 +00:00
|
|
|
int rlp = cnx->remote_lp;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
spin_lock_irq(&cnx->lock);
|
|
|
|
|
|
|
|
restart:
|
|
|
|
if (cnx->state & VETH_STATE_RESET) {
|
|
|
|
if (cnx->state & VETH_STATE_OPEN)
|
|
|
|
HvCallEvent_closeLpEventPath(cnx->remote_lp,
|
|
|
|
HvLpEvent_Type_VirtualLan);
|
|
|
|
|
2005-09-01 01:28:59 +00:00
|
|
|
/*
|
|
|
|
* Reset ack data. This prevents the ack_timer actually
|
|
|
|
* doing anything, even if it runs one more time when
|
|
|
|
* we drop the lock below.
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
memset(&cnx->pending_acks, 0xff, sizeof (cnx->pending_acks));
|
|
|
|
cnx->num_pending_acks = 0;
|
|
|
|
|
|
|
|
cnx->state &= ~(VETH_STATE_RESET | VETH_STATE_SENTMON
|
|
|
|
| VETH_STATE_OPEN | VETH_STATE_SENTCAPS
|
|
|
|
| VETH_STATE_GOTCAPACK | VETH_STATE_GOTCAPS
|
|
|
|
| VETH_STATE_SENTCAPACK | VETH_STATE_READY);
|
|
|
|
|
|
|
|
/* Clean up any leftover messages */
|
2005-09-01 01:29:17 +00:00
|
|
|
if (cnx->msgs) {
|
|
|
|
int i;
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < VETH_NUMBUFFERS; ++i)
|
|
|
|
veth_recycle_msg(cnx, cnx->msgs + i);
|
2005-09-01 01:29:17 +00:00
|
|
|
}
|
2005-09-01 01:29:18 +00:00
|
|
|
|
2005-09-01 01:29:17 +00:00
|
|
|
cnx->outstanding_tx = 0;
|
2005-09-01 01:29:18 +00:00
|
|
|
veth_wake_queues(cnx);
|
2005-09-01 01:28:59 +00:00
|
|
|
|
|
|
|
/* Drop the lock so we can do stuff that might sleep or
|
|
|
|
* take other locks. */
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irq(&cnx->lock);
|
2005-09-01 01:28:59 +00:00
|
|
|
|
|
|
|
del_timer_sync(&cnx->ack_timer);
|
2005-09-01 01:29:17 +00:00
|
|
|
del_timer_sync(&cnx->reset_timer);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irq(&cnx->lock);
|
2005-09-01 01:28:59 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (cnx->state & VETH_STATE_RESET)
|
|
|
|
goto restart;
|
2005-09-01 01:29:00 +00:00
|
|
|
|
|
|
|
/* Hack, wait for the other end to reset itself. */
|
|
|
|
if (! (cnx->state & VETH_STATE_SHUTDOWN)) {
|
|
|
|
schedule_delayed_work(&cnx->statemachine_wq, 5 * HZ);
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cnx->state & VETH_STATE_SHUTDOWN)
|
|
|
|
/* It's all over, do nothing */
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if ( !(cnx->state & VETH_STATE_OPEN) ) {
|
|
|
|
if (! cnx->msgs || (cnx->num_events < (2 + VETH_NUMBUFFERS)) )
|
|
|
|
goto cant_cope;
|
|
|
|
|
|
|
|
HvCallEvent_openLpEventPath(rlp, HvLpEvent_Type_VirtualLan);
|
|
|
|
cnx->src_inst =
|
|
|
|
HvCallEvent_getSourceLpInstanceId(rlp,
|
|
|
|
HvLpEvent_Type_VirtualLan);
|
|
|
|
cnx->dst_inst =
|
|
|
|
HvCallEvent_getTargetLpInstanceId(rlp,
|
|
|
|
HvLpEvent_Type_VirtualLan);
|
|
|
|
cnx->state |= VETH_STATE_OPEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (cnx->state & VETH_STATE_OPEN)
|
|
|
|
&& !(cnx->state & VETH_STATE_SENTMON) ) {
|
2005-09-01 01:29:27 +00:00
|
|
|
rc = veth_signalevent(cnx, VETH_EVENT_MONITOR,
|
2005-04-16 22:20:36 +00:00
|
|
|
HvLpEvent_AckInd_DoAck,
|
|
|
|
HvLpEvent_AckType_DeferredAck,
|
|
|
|
0, 0, 0, 0, 0, 0);
|
|
|
|
|
|
|
|
if (rc == HvLpEvent_Rc_Good) {
|
|
|
|
cnx->state |= VETH_STATE_SENTMON;
|
|
|
|
} else {
|
|
|
|
if ( (rc != HvLpEvent_Rc_PartitionDead)
|
|
|
|
&& (rc != HvLpEvent_Rc_PathClosed) )
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Error sending monitor to LPAR %d, "
|
|
|
|
"rc = %d\n", rlp, rc);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Oh well, hope we get a cap from the other
|
|
|
|
* end and do better when that kicks us */
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (cnx->state & VETH_STATE_OPEN)
|
|
|
|
&& !(cnx->state & VETH_STATE_SENTCAPS)) {
|
|
|
|
u64 *rawcap = (u64 *)&cnx->local_caps;
|
|
|
|
|
2005-09-01 01:29:27 +00:00
|
|
|
rc = veth_signalevent(cnx, VETH_EVENT_CAP,
|
2005-04-16 22:20:36 +00:00
|
|
|
HvLpEvent_AckInd_DoAck,
|
|
|
|
HvLpEvent_AckType_ImmediateAck,
|
|
|
|
0, rawcap[0], rawcap[1], rawcap[2],
|
|
|
|
rawcap[3], rawcap[4]);
|
|
|
|
|
|
|
|
if (rc == HvLpEvent_Rc_Good) {
|
|
|
|
cnx->state |= VETH_STATE_SENTCAPS;
|
|
|
|
} else {
|
|
|
|
if ( (rc != HvLpEvent_Rc_PartitionDead)
|
|
|
|
&& (rc != HvLpEvent_Rc_PathClosed) )
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Error sending caps to LPAR %d, "
|
|
|
|
"rc = %d\n", rlp, rc);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Oh well, hope we get a cap from the other
|
|
|
|
* end and do better when that kicks us */
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cnx->state & VETH_STATE_GOTCAPS)
|
|
|
|
&& !(cnx->state & VETH_STATE_SENTCAPACK)) {
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_cap_data *remote_caps = &cnx->remote_caps;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
memcpy(remote_caps, &cnx->cap_event.u.caps_data,
|
|
|
|
sizeof(*remote_caps));
|
|
|
|
|
|
|
|
spin_unlock_irq(&cnx->lock);
|
|
|
|
rc = veth_process_caps(cnx);
|
|
|
|
spin_lock_irq(&cnx->lock);
|
|
|
|
|
|
|
|
/* We dropped the lock, so recheck for anything which
|
|
|
|
* might mess us up */
|
|
|
|
if (cnx->state & (VETH_STATE_RESET|VETH_STATE_SHUTDOWN))
|
|
|
|
goto restart;
|
|
|
|
|
|
|
|
cnx->cap_event.base_event.xRc = rc;
|
|
|
|
HvCallEvent_ackLpEvent((struct HvLpEvent *)&cnx->cap_event);
|
|
|
|
if (rc == HvLpEvent_Rc_Good)
|
|
|
|
cnx->state |= VETH_STATE_SENTCAPACK;
|
|
|
|
else
|
|
|
|
goto cant_cope;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cnx->state & VETH_STATE_GOTCAPACK)
|
|
|
|
&& (cnx->state & VETH_STATE_GOTCAPS)
|
|
|
|
&& !(cnx->state & VETH_STATE_READY)) {
|
|
|
|
if (cnx->cap_ack_event.base_event.xRc == HvLpEvent_Rc_Good) {
|
|
|
|
/* Start the ACK timer */
|
|
|
|
cnx->ack_timer.expires = jiffies + cnx->ack_timeout;
|
|
|
|
add_timer(&cnx->ack_timer);
|
|
|
|
cnx->state |= VETH_STATE_READY;
|
|
|
|
} else {
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Caps rejected by LPAR %d, rc = %d\n",
|
|
|
|
rlp, cnx->cap_ack_event.base_event.xRc);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto cant_cope;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
spin_unlock_irq(&cnx->lock);
|
|
|
|
return;
|
|
|
|
|
|
|
|
cant_cope:
|
|
|
|
/* FIXME: we get here if something happens we really can't
|
|
|
|
* cope with. The link will never work once we get here, and
|
|
|
|
* all we can do is not lock the rest of the system up */
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Unrecoverable error on connection to LPAR %d, shutting down"
|
|
|
|
" (state = 0x%04lx)\n", rlp, cnx->state);
|
2005-04-16 22:20:36 +00:00
|
|
|
cnx->state |= VETH_STATE_SHUTDOWN;
|
|
|
|
spin_unlock_irq(&cnx->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int veth_init_connection(u8 rlp)
|
|
|
|
{
|
|
|
|
struct veth_lpar_connection *cnx;
|
|
|
|
struct veth_msg *msgs;
|
2007-12-18 06:05:35 +00:00
|
|
|
int i;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if ( (rlp == this_lp)
|
|
|
|
|| ! HvLpConfig_doLpsCommunicateOnVirtualLan(this_lp, rlp) )
|
|
|
|
return 0;
|
|
|
|
|
some kmalloc/memset ->kzalloc (tree wide)
Transform some calls to kmalloc/memset to a single kzalloc (or kcalloc).
Here is a short excerpt of the semantic patch performing
this transformation:
@@
type T2;
expression x;
identifier f,fld;
expression E;
expression E1,E2;
expression e1,e2,e3,y;
statement S;
@@
x =
- kmalloc
+ kzalloc
(E1,E2)
... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
- memset((T2)x,0,E1);
@@
expression E1,E2,E3;
@@
- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)
[akpm@linux-foundation.org: get kcalloc args the right way around]
Signed-off-by: Yoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: Roland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: Greg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 08:49:03 +00:00
|
|
|
cnx = kzalloc(sizeof(*cnx), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (! cnx)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
cnx->remote_lp = rlp;
|
|
|
|
spin_lock_init(&cnx->lock);
|
2006-11-22 14:57:56 +00:00
|
|
|
INIT_DELAYED_WORK(&cnx->statemachine_wq, veth_statemachine);
|
2005-09-01 01:29:17 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
init_timer(&cnx->ack_timer);
|
|
|
|
cnx->ack_timer.function = veth_timed_ack;
|
|
|
|
cnx->ack_timer.data = (unsigned long) cnx;
|
2005-09-01 01:29:17 +00:00
|
|
|
|
|
|
|
init_timer(&cnx->reset_timer);
|
|
|
|
cnx->reset_timer.function = veth_timed_reset;
|
|
|
|
cnx->reset_timer.data = (unsigned long) cnx;
|
|
|
|
cnx->reset_timeout = 5 * HZ * (VETH_ACKTIMEOUT / 1000000);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
memset(&cnx->pending_acks, 0xff, sizeof (cnx->pending_acks));
|
|
|
|
|
|
|
|
veth_cnx[rlp] = cnx;
|
|
|
|
|
2005-09-01 01:29:09 +00:00
|
|
|
/* This gets us 1 reference, which is held on behalf of the driver
|
|
|
|
* infrastructure. It's released at module unload. */
|
2007-12-18 06:05:35 +00:00
|
|
|
kobject_init(&cnx->kobject, &veth_lpar_connection_ktype);
|
2005-09-01 01:29:09 +00:00
|
|
|
|
some kmalloc/memset ->kzalloc (tree wide)
Transform some calls to kmalloc/memset to a single kzalloc (or kcalloc).
Here is a short excerpt of the semantic patch performing
this transformation:
@@
type T2;
expression x;
identifier f,fld;
expression E;
expression E1,E2;
expression e1,e2,e3,y;
statement S;
@@
x =
- kmalloc
+ kzalloc
(E1,E2)
... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
- memset((T2)x,0,E1);
@@
expression E1,E2,E3;
@@
- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)
[akpm@linux-foundation.org: get kcalloc args the right way around]
Signed-off-by: Yoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: Roland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: Greg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 08:49:03 +00:00
|
|
|
msgs = kcalloc(VETH_NUMBUFFERS, sizeof(struct veth_msg), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (! msgs) {
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Can't allocate buffers for LPAR %d.\n", rlp);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
cnx->msgs = msgs;
|
|
|
|
|
|
|
|
for (i = 0; i < VETH_NUMBUFFERS; i++) {
|
|
|
|
msgs[i].token = i;
|
|
|
|
veth_stack_push(cnx, msgs + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
cnx->num_events = veth_allocate_events(rlp, 2 + VETH_NUMBUFFERS);
|
|
|
|
|
|
|
|
if (cnx->num_events < (2 + VETH_NUMBUFFERS)) {
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Can't allocate enough events for LPAR %d.\n", rlp);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
cnx->local_caps.num_buffers = VETH_NUMBUFFERS;
|
|
|
|
cnx->local_caps.ack_threshold = ACK_THRESHOLD;
|
|
|
|
cnx->local_caps.ack_timeout = VETH_ACKTIMEOUT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-01 01:29:09 +00:00
|
|
|
static void veth_stop_connection(struct veth_lpar_connection *cnx)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-09-01 01:29:09 +00:00
|
|
|
if (!cnx)
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
spin_lock_irq(&cnx->lock);
|
|
|
|
cnx->state |= VETH_STATE_RESET | VETH_STATE_SHUTDOWN;
|
|
|
|
veth_kick_statemachine(cnx);
|
|
|
|
spin_unlock_irq(&cnx->lock);
|
|
|
|
|
2005-09-01 01:29:00 +00:00
|
|
|
/* There's a slim chance the reset code has just queued the
|
|
|
|
* statemachine to run in five seconds. If so we need to cancel
|
|
|
|
* that and requeue the work to run now. */
|
|
|
|
if (cancel_delayed_work(&cnx->statemachine_wq)) {
|
|
|
|
spin_lock_irq(&cnx->lock);
|
|
|
|
veth_kick_statemachine(cnx);
|
|
|
|
spin_unlock_irq(&cnx->lock);
|
|
|
|
}
|
|
|
|
|
2005-09-01 01:28:59 +00:00
|
|
|
/* Wait for the state machine to run. */
|
2005-04-16 22:20:36 +00:00
|
|
|
flush_scheduled_work();
|
2005-09-01 01:29:08 +00:00
|
|
|
}
|
|
|
|
|
2005-09-01 01:29:09 +00:00
|
|
|
static void veth_destroy_connection(struct veth_lpar_connection *cnx)
|
2005-09-01 01:29:08 +00:00
|
|
|
{
|
2005-09-01 01:29:09 +00:00
|
|
|
if (!cnx)
|
2005-09-01 01:29:08 +00:00
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (cnx->num_events > 0)
|
|
|
|
mf_deallocate_lp_events(cnx->remote_lp,
|
|
|
|
HvLpEvent_Type_VirtualLan,
|
|
|
|
cnx->num_events,
|
|
|
|
NULL, NULL);
|
|
|
|
if (cnx->num_ack_events > 0)
|
|
|
|
mf_deallocate_lp_events(cnx->remote_lp,
|
|
|
|
HvLpEvent_Type_VirtualLan,
|
|
|
|
cnx->num_ack_events,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
kfree(cnx->msgs);
|
2005-09-01 01:29:09 +00:00
|
|
|
veth_cnx[cnx->remote_lp] = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(cnx);
|
2005-09-01 01:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void veth_release_connection(struct kobject *kobj)
|
|
|
|
{
|
|
|
|
struct veth_lpar_connection *cnx;
|
|
|
|
cnx = container_of(kobj, struct veth_lpar_connection, kobject);
|
|
|
|
veth_stop_connection(cnx);
|
|
|
|
veth_destroy_connection(cnx);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* net_device code
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int veth_open(struct net_device *dev)
|
|
|
|
{
|
|
|
|
netif_start_queue(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int veth_close(struct net_device *dev)
|
|
|
|
{
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int veth_change_mtu(struct net_device *dev, int new_mtu)
|
|
|
|
{
|
|
|
|
if ((new_mtu < 68) || (new_mtu > VETH_MAX_MTU))
|
|
|
|
return -EINVAL;
|
|
|
|
dev->mtu = new_mtu;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void veth_set_multicast_list(struct net_device *dev)
|
|
|
|
{
|
2008-11-13 07:37:49 +00:00
|
|
|
struct veth_port *port = netdev_priv(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
write_lock_irqsave(&port->mcast_gate, flags);
|
|
|
|
|
2005-09-01 01:29:02 +00:00
|
|
|
if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
|
|
|
|
(dev->mc_count > VETH_MAX_MCAST)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
port->promiscuous = 1;
|
|
|
|
} else {
|
|
|
|
struct dev_mc_list *dmi = dev->mc_list;
|
|
|
|
int i;
|
|
|
|
|
2005-09-01 01:29:02 +00:00
|
|
|
port->promiscuous = 0;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Update table */
|
|
|
|
port->num_mcast = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < dev->mc_count; i++) {
|
|
|
|
u8 *addr = dmi->dmi_addr;
|
|
|
|
u64 xaddr = 0;
|
|
|
|
|
|
|
|
if (addr[0] & 0x01) {/* multicast address? */
|
|
|
|
memcpy(&xaddr, addr, ETH_ALEN);
|
|
|
|
port->mcast_addr[port->num_mcast] = xaddr;
|
|
|
|
port->num_mcast++;
|
|
|
|
}
|
|
|
|
dmi = dmi->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
write_unlock_irqrestore(&port->mcast_gate, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void veth_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
|
|
|
|
{
|
2005-09-01 01:29:29 +00:00
|
|
|
strncpy(info->driver, DRV_NAME, sizeof(info->driver) - 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
info->driver[sizeof(info->driver) - 1] = '\0';
|
2005-09-01 01:29:29 +00:00
|
|
|
strncpy(info->version, DRV_VERSION, sizeof(info->version) - 1);
|
|
|
|
info->version[sizeof(info->version) - 1] = '\0';
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int veth_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
|
|
|
|
{
|
|
|
|
ecmd->supported = (SUPPORTED_1000baseT_Full
|
|
|
|
| SUPPORTED_Autoneg | SUPPORTED_FIBRE);
|
|
|
|
ecmd->advertising = (SUPPORTED_1000baseT_Full
|
|
|
|
| SUPPORTED_Autoneg | SUPPORTED_FIBRE);
|
|
|
|
ecmd->port = PORT_FIBRE;
|
|
|
|
ecmd->transceiver = XCVR_INTERNAL;
|
|
|
|
ecmd->phy_address = 0;
|
|
|
|
ecmd->speed = SPEED_1000;
|
|
|
|
ecmd->duplex = DUPLEX_FULL;
|
|
|
|
ecmd->autoneg = AUTONEG_ENABLE;
|
|
|
|
ecmd->maxtxpkt = 120;
|
|
|
|
ecmd->maxrxpkt = 120;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 veth_get_link(struct net_device *dev)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-09-13 18:30:00 +00:00
|
|
|
static const struct ethtool_ops ops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.get_drvinfo = veth_get_drvinfo,
|
|
|
|
.get_settings = veth_get_settings,
|
|
|
|
.get_link = veth_get_link,
|
|
|
|
};
|
|
|
|
|
2009-04-15 12:52:43 +00:00
|
|
|
static const struct net_device_ops veth_netdev_ops = {
|
|
|
|
.ndo_open = veth_open,
|
|
|
|
.ndo_stop = veth_close,
|
|
|
|
.ndo_start_xmit = veth_start_xmit,
|
|
|
|
.ndo_change_mtu = veth_change_mtu,
|
|
|
|
.ndo_set_multicast_list = veth_set_multicast_list,
|
|
|
|
.ndo_set_mac_address = NULL,
|
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
|
|
|
};
|
|
|
|
|
2008-02-05 03:19:40 +00:00
|
|
|
static struct net_device *veth_probe_one(int vlan,
|
2006-05-15 03:39:47 +00:00
|
|
|
struct vio_dev *vio_dev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct net_device *dev;
|
|
|
|
struct veth_port *port;
|
2006-05-15 03:39:47 +00:00
|
|
|
struct device *vdev = &vio_dev->dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
int i, rc;
|
2006-05-15 03:39:47 +00:00
|
|
|
const unsigned char *mac_addr;
|
|
|
|
|
|
|
|
mac_addr = vio_get_attribute(vio_dev, "local-mac-address", NULL);
|
|
|
|
if (mac_addr == NULL)
|
|
|
|
mac_addr = vio_get_attribute(vio_dev, "mac-address", NULL);
|
|
|
|
if (mac_addr == NULL) {
|
|
|
|
veth_error("Unable to fetch MAC address from device tree.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
dev = alloc_etherdev(sizeof (struct veth_port));
|
|
|
|
if (! dev) {
|
|
|
|
veth_error("Unable to allocate net_device structure!\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-11-13 07:37:49 +00:00
|
|
|
port = netdev_priv(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-09-01 01:29:18 +00:00
|
|
|
spin_lock_init(&port->queue_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
rwlock_init(&port->mcast_gate);
|
2005-09-01 01:29:18 +00:00
|
|
|
port->stopped_map = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
for (i = 0; i < HVMAXARCHITECTEDLPS; i++) {
|
|
|
|
HvLpVirtualLanIndexMap map;
|
|
|
|
|
|
|
|
if (i == this_lp)
|
|
|
|
continue;
|
|
|
|
map = HvLpConfig_getVirtualLanIndexMapForLp(i);
|
|
|
|
if (map & (0x8000 >> vlan))
|
|
|
|
port->lpar_map |= (1 << i);
|
|
|
|
}
|
|
|
|
port->dev = vdev;
|
|
|
|
|
2006-05-15 03:39:47 +00:00
|
|
|
memcpy(dev->dev_addr, mac_addr, ETH_ALEN);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
dev->mtu = VETH_MAX_MTU;
|
|
|
|
|
2006-05-15 03:39:47 +00:00
|
|
|
memcpy(&port->mac_addr, mac_addr, ETH_ALEN);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-04-20 01:42:58 +00:00
|
|
|
dev->netdev_ops = &veth_netdev_ops;
|
2005-04-16 22:20:36 +00:00
|
|
|
SET_ETHTOOL_OPS(dev, &ops);
|
|
|
|
|
|
|
|
SET_NETDEV_DEV(dev, vdev);
|
|
|
|
|
|
|
|
rc = register_netdev(dev);
|
|
|
|
if (rc != 0) {
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Failed registering net device for vlan%d.\n", vlan);
|
2005-04-16 22:20:36 +00:00
|
|
|
free_netdev(dev);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-18 06:05:35 +00:00
|
|
|
kobject_init(&port->kobject, &veth_port_ktype);
|
2007-12-18 06:05:35 +00:00
|
|
|
if (0 != kobject_add(&port->kobject, &dev->dev.kobj, "veth_port"))
|
2005-09-01 01:29:21 +00:00
|
|
|
veth_error("Failed adding port for %s to sysfs.\n", dev->name);
|
|
|
|
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_info("%s attached to iSeries vlan %d (LPAR map = 0x%.4X)\n",
|
|
|
|
dev->name, vlan, port->lpar_map);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tx path
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int veth_transmit_to_one(struct sk_buff *skb, HvLpIndex rlp,
|
|
|
|
struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct veth_lpar_connection *cnx = veth_cnx[rlp];
|
2008-11-13 07:37:49 +00:00
|
|
|
struct veth_port *port = netdev_priv(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
HvLpEvent_Rc rc;
|
|
|
|
struct veth_msg *msg = NULL;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2005-09-01 01:29:19 +00:00
|
|
|
if (! cnx)
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cnx->lock, flags);
|
|
|
|
|
2005-05-12 07:47:27 +00:00
|
|
|
if (! (cnx->state & VETH_STATE_READY))
|
2005-09-01 01:29:19 +00:00
|
|
|
goto no_error;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-09-01 01:29:19 +00:00
|
|
|
if ((skb->len - ETH_HLEN) > VETH_MAX_MTU)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto drop;
|
|
|
|
|
|
|
|
msg = veth_stack_pop(cnx);
|
2005-09-01 01:29:19 +00:00
|
|
|
if (! msg)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto drop;
|
|
|
|
|
2005-09-01 01:29:06 +00:00
|
|
|
msg->in_use = 1;
|
2005-09-01 01:29:19 +00:00
|
|
|
msg->skb = skb_get(skb);
|
2005-09-01 01:29:06 +00:00
|
|
|
|
2005-09-01 01:29:07 +00:00
|
|
|
msg->data.addr[0] = dma_map_single(port->dev, skb->data,
|
|
|
|
skb->len, DMA_TO_DEVICE);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-07-26 02:44:49 +00:00
|
|
|
if (dma_mapping_error(port->dev, msg->data.addr[0]))
|
2005-04-16 22:20:36 +00:00
|
|
|
goto recycle_and_drop;
|
|
|
|
|
|
|
|
msg->dev = port->dev;
|
2005-09-01 01:29:07 +00:00
|
|
|
msg->data.len[0] = skb->len;
|
2005-04-16 22:20:36 +00:00
|
|
|
msg->data.eofmask = 1 << VETH_EOF_SHIFT;
|
2005-09-01 01:29:07 +00:00
|
|
|
|
2005-09-01 01:29:27 +00:00
|
|
|
rc = veth_signaldata(cnx, VETH_EVENT_FRAMES, msg->token, &msg->data);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (rc != HvLpEvent_Rc_Good)
|
|
|
|
goto recycle_and_drop;
|
|
|
|
|
2005-09-01 01:29:17 +00:00
|
|
|
/* If the timer's not already running, start it now. */
|
|
|
|
if (0 == cnx->outstanding_tx)
|
|
|
|
mod_timer(&cnx->reset_timer, jiffies + cnx->reset_timeout);
|
|
|
|
|
|
|
|
cnx->last_contact = jiffies;
|
|
|
|
cnx->outstanding_tx++;
|
|
|
|
|
2005-09-01 01:29:18 +00:00
|
|
|
if (veth_stack_is_empty(cnx))
|
|
|
|
veth_stop_queues(cnx);
|
|
|
|
|
2005-09-01 01:29:19 +00:00
|
|
|
no_error:
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&cnx->lock, flags);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
recycle_and_drop:
|
|
|
|
veth_recycle_msg(cnx, msg);
|
|
|
|
drop:
|
|
|
|
spin_unlock_irqrestore(&cnx->lock, flags);
|
2005-09-01 01:29:19 +00:00
|
|
|
return 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-09-01 01:29:19 +00:00
|
|
|
static void veth_transmit_to_many(struct sk_buff *skb,
|
2005-04-16 22:20:36 +00:00
|
|
|
HvLpIndexMap lpmask,
|
|
|
|
struct net_device *dev)
|
|
|
|
{
|
2005-09-01 01:29:19 +00:00
|
|
|
int i, success, error;
|
|
|
|
|
|
|
|
success = error = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
for (i = 0; i < HVMAXARCHITECTEDLPS; i++) {
|
|
|
|
if ((lpmask & (1 << i)) == 0)
|
|
|
|
continue;
|
|
|
|
|
2005-09-01 01:29:19 +00:00
|
|
|
if (veth_transmit_to_one(skb, i, dev))
|
|
|
|
error = 1;
|
|
|
|
else
|
|
|
|
success = 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-09-01 01:29:19 +00:00
|
|
|
if (error)
|
2007-10-04 00:41:50 +00:00
|
|
|
dev->stats.tx_errors++;
|
2005-09-01 01:29:19 +00:00
|
|
|
|
|
|
|
if (success) {
|
2007-10-04 00:41:50 +00:00
|
|
|
dev->stats.tx_packets++;
|
|
|
|
dev->stats.tx_bytes += skb->len;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int veth_start_xmit(struct sk_buff *skb, struct net_device *dev)
|
|
|
|
{
|
|
|
|
unsigned char *frame = skb->data;
|
2008-11-13 07:37:49 +00:00
|
|
|
struct veth_port *port = netdev_priv(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
HvLpIndexMap lpmask;
|
|
|
|
|
|
|
|
if (! (frame[0] & 0x01)) {
|
|
|
|
/* unicast packet */
|
|
|
|
HvLpIndex rlp = frame[5];
|
|
|
|
|
|
|
|
if ( ! ((1 << rlp) & port->lpar_map) ) {
|
|
|
|
dev_kfree_skb(skb);
|
2009-06-23 06:03:08 +00:00
|
|
|
return NETDEV_TX_OK;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lpmask = 1 << rlp;
|
|
|
|
} else {
|
|
|
|
lpmask = port->lpar_map;
|
|
|
|
}
|
|
|
|
|
2005-09-01 01:29:18 +00:00
|
|
|
veth_transmit_to_many(skb, lpmask, dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-09-01 01:29:18 +00:00
|
|
|
dev_kfree_skb(skb);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-06-23 06:03:08 +00:00
|
|
|
return NETDEV_TX_OK;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-09-01 01:29:06 +00:00
|
|
|
/* You must hold the connection's lock when you call this function. */
|
2005-04-16 22:20:36 +00:00
|
|
|
static void veth_recycle_msg(struct veth_lpar_connection *cnx,
|
|
|
|
struct veth_msg *msg)
|
|
|
|
{
|
|
|
|
u32 dma_address, dma_length;
|
|
|
|
|
2005-09-01 01:29:06 +00:00
|
|
|
if (msg->in_use) {
|
|
|
|
msg->in_use = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
dma_address = msg->data.addr[0];
|
|
|
|
dma_length = msg->data.len[0];
|
|
|
|
|
2008-07-26 02:44:49 +00:00
|
|
|
if (!dma_mapping_error(msg->dev, dma_address))
|
2005-09-01 01:29:07 +00:00
|
|
|
dma_unmap_single(msg->dev, dma_address, dma_length,
|
|
|
|
DMA_TO_DEVICE);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (msg->skb) {
|
|
|
|
dev_kfree_skb_any(msg->skb);
|
|
|
|
msg->skb = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&msg->data, 0, sizeof(msg->data));
|
|
|
|
veth_stack_push(cnx, msg);
|
2005-09-01 01:28:57 +00:00
|
|
|
} else if (cnx->state & VETH_STATE_OPEN) {
|
|
|
|
veth_error("Non-pending frame (# %d) acked by LPAR %d.\n",
|
|
|
|
cnx->remote_lp, msg->token);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-09-01 01:29:18 +00:00
|
|
|
static void veth_wake_queues(struct veth_lpar_connection *cnx)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
2005-09-01 01:29:18 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) {
|
|
|
|
struct net_device *dev = veth_dev[i];
|
|
|
|
struct veth_port *port;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (! dev)
|
|
|
|
continue;
|
|
|
|
|
2008-11-13 07:37:49 +00:00
|
|
|
port = netdev_priv(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (! (port->lpar_map & (1<<cnx->remote_lp)))
|
|
|
|
continue;
|
|
|
|
|
2005-09-01 01:29:18 +00:00
|
|
|
spin_lock_irqsave(&port->queue_lock, flags);
|
|
|
|
|
|
|
|
port->stopped_map &= ~(1 << cnx->remote_lp);
|
|
|
|
|
|
|
|
if (0 == port->stopped_map && netif_queue_stopped(dev)) {
|
|
|
|
veth_debug("cnx %d: woke queue for %s.\n",
|
|
|
|
cnx->remote_lp, dev->name);
|
|
|
|
netif_wake_queue(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2005-09-01 01:29:18 +00:00
|
|
|
spin_unlock_irqrestore(&port->queue_lock, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void veth_stop_queues(struct veth_lpar_connection *cnx)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) {
|
|
|
|
struct net_device *dev = veth_dev[i];
|
|
|
|
struct veth_port *port;
|
|
|
|
|
|
|
|
if (! dev)
|
|
|
|
continue;
|
|
|
|
|
2008-11-13 07:37:49 +00:00
|
|
|
port = netdev_priv(dev);
|
2005-09-01 01:29:18 +00:00
|
|
|
|
|
|
|
/* If this cnx is not on the vlan for this port, continue */
|
|
|
|
if (! (port->lpar_map & (1 << cnx->remote_lp)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
spin_lock(&port->queue_lock);
|
|
|
|
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
port->stopped_map |= (1 << cnx->remote_lp);
|
|
|
|
|
|
|
|
veth_debug("cnx %d: stopped queue for %s, map = 0x%x.\n",
|
|
|
|
cnx->remote_lp, dev->name, port->stopped_map);
|
|
|
|
|
|
|
|
spin_unlock(&port->queue_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-01 01:29:17 +00:00
|
|
|
static void veth_timed_reset(unsigned long ptr)
|
|
|
|
{
|
|
|
|
struct veth_lpar_connection *cnx = (struct veth_lpar_connection *)ptr;
|
|
|
|
unsigned long trigger_time, flags;
|
|
|
|
|
|
|
|
/* FIXME is it possible this fires after veth_stop_connection()?
|
|
|
|
* That would reschedule the statemachine for 5 seconds and probably
|
|
|
|
* execute it after the module's been unloaded. Hmm. */
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cnx->lock, flags);
|
|
|
|
|
|
|
|
if (cnx->outstanding_tx > 0) {
|
|
|
|
trigger_time = cnx->last_contact + cnx->reset_timeout;
|
|
|
|
|
|
|
|
if (trigger_time < jiffies) {
|
|
|
|
cnx->state |= VETH_STATE_RESET;
|
|
|
|
veth_kick_statemachine(cnx);
|
|
|
|
veth_error("%d packets not acked by LPAR %d within %d "
|
|
|
|
"seconds, resetting.\n",
|
|
|
|
cnx->outstanding_tx, cnx->remote_lp,
|
|
|
|
cnx->reset_timeout / HZ);
|
|
|
|
} else {
|
|
|
|
/* Reschedule the timer */
|
|
|
|
trigger_time = jiffies + cnx->reset_timeout;
|
|
|
|
mod_timer(&cnx->reset_timer, trigger_time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&cnx->lock, flags);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Rx path
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline int veth_frame_wanted(struct veth_port *port, u64 mac_addr)
|
|
|
|
{
|
|
|
|
int wanted = 0;
|
|
|
|
int i;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if ( (mac_addr == port->mac_addr) || (mac_addr == 0xffffffffffff0000) )
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
read_lock_irqsave(&port->mcast_gate, flags);
|
|
|
|
|
2005-09-01 01:29:02 +00:00
|
|
|
if (port->promiscuous) {
|
2005-04-16 22:20:36 +00:00
|
|
|
wanted = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < port->num_mcast; ++i) {
|
|
|
|
if (port->mcast_addr[i] == mac_addr) {
|
|
|
|
wanted = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
read_unlock_irqrestore(&port->mcast_gate, flags);
|
|
|
|
|
|
|
|
return wanted;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dma_chunk {
|
|
|
|
u64 addr;
|
|
|
|
u64 size;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define VETH_MAX_PAGES_PER_FRAME ( (VETH_MAX_MTU+PAGE_SIZE-2)/PAGE_SIZE + 1 )
|
|
|
|
|
|
|
|
static inline void veth_build_dma_list(struct dma_chunk *list,
|
|
|
|
unsigned char *p, unsigned long length)
|
|
|
|
{
|
|
|
|
unsigned long done;
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
/* FIXME: skbs are continguous in real addresses. Do we
|
|
|
|
* really need to break it into PAGE_SIZE chunks, or can we do
|
|
|
|
* it just at the granularity of iSeries real->absolute
|
|
|
|
* mapping? Indeed, given the way the allocator works, can we
|
|
|
|
* count on them being absolutely contiguous? */
|
2005-10-14 04:51:42 +00:00
|
|
|
list[0].addr = iseries_hv_addr(p);
|
2005-04-16 22:20:36 +00:00
|
|
|
list[0].size = min(length,
|
|
|
|
PAGE_SIZE - ((unsigned long)p & ~PAGE_MASK));
|
|
|
|
|
|
|
|
done = list[0].size;
|
|
|
|
while (done < length) {
|
2005-10-14 04:51:42 +00:00
|
|
|
list[i].addr = iseries_hv_addr(p + done);
|
2005-04-16 22:20:36 +00:00
|
|
|
list[i].size = min(length-done, PAGE_SIZE);
|
|
|
|
done += list[i].size;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void veth_flush_acks(struct veth_lpar_connection *cnx)
|
|
|
|
{
|
|
|
|
HvLpEvent_Rc rc;
|
|
|
|
|
2005-09-01 01:29:27 +00:00
|
|
|
rc = veth_signaldata(cnx, VETH_EVENT_FRAMES_ACK,
|
2005-04-16 22:20:36 +00:00
|
|
|
0, &cnx->pending_acks);
|
|
|
|
|
|
|
|
if (rc != HvLpEvent_Rc_Good)
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Failed acking frames from LPAR %d, rc = %d\n",
|
|
|
|
cnx->remote_lp, (int)rc);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
cnx->num_pending_acks = 0;
|
|
|
|
memset(&cnx->pending_acks, 0xff, sizeof(cnx->pending_acks));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void veth_receive(struct veth_lpar_connection *cnx,
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_lpevent *event)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-09-01 01:29:27 +00:00
|
|
|
struct veth_frames_data *senddata = &event->u.frames_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
int startchunk = 0;
|
|
|
|
int nchunks;
|
|
|
|
unsigned long flags;
|
|
|
|
HvLpDma_Rc rc;
|
|
|
|
|
|
|
|
do {
|
|
|
|
u16 length = 0;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct dma_chunk local_list[VETH_MAX_PAGES_PER_FRAME];
|
|
|
|
struct dma_chunk remote_list[VETH_MAX_FRAMES_PER_MSG];
|
|
|
|
u64 dest;
|
|
|
|
HvLpVirtualLanIndex vlan;
|
|
|
|
struct net_device *dev;
|
|
|
|
struct veth_port *port;
|
|
|
|
|
|
|
|
/* FIXME: do we need this? */
|
|
|
|
memset(local_list, 0, sizeof(local_list));
|
|
|
|
memset(remote_list, 0, sizeof(VETH_MAX_FRAMES_PER_MSG));
|
|
|
|
|
|
|
|
/* a 0 address marks the end of the valid entries */
|
|
|
|
if (senddata->addr[startchunk] == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* make sure that we have at least 1 EOF entry in the
|
|
|
|
* remaining entries */
|
|
|
|
if (! (senddata->eofmask >> (startchunk + VETH_EOF_SHIFT))) {
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Missing EOF fragment in event "
|
|
|
|
"eofmask = 0x%x startchunk = %d\n",
|
|
|
|
(unsigned)senddata->eofmask,
|
|
|
|
startchunk);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build list of chunks in this frame */
|
|
|
|
nchunks = 0;
|
|
|
|
do {
|
|
|
|
remote_list[nchunks].addr =
|
|
|
|
(u64) senddata->addr[startchunk+nchunks] << 32;
|
|
|
|
remote_list[nchunks].size =
|
|
|
|
senddata->len[startchunk+nchunks];
|
|
|
|
length += remote_list[nchunks].size;
|
|
|
|
} while (! (senddata->eofmask &
|
|
|
|
(1 << (VETH_EOF_SHIFT + startchunk + nchunks++))));
|
|
|
|
|
|
|
|
/* length == total length of all chunks */
|
|
|
|
/* nchunks == # of chunks in this frame */
|
|
|
|
|
|
|
|
if ((length - ETH_HLEN) > VETH_MAX_MTU) {
|
2005-09-01 01:28:57 +00:00
|
|
|
veth_error("Received oversize frame from LPAR %d "
|
|
|
|
"(length = %d)\n",
|
|
|
|
cnx->remote_lp, length);
|
2005-04-16 22:20:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb = alloc_skb(length, GFP_ATOMIC);
|
|
|
|
if (!skb)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
veth_build_dma_list(local_list, skb->data, length);
|
|
|
|
|
|
|
|
rc = HvCallEvent_dmaBufList(HvLpEvent_Type_VirtualLan,
|
|
|
|
event->base_event.xSourceLp,
|
|
|
|
HvLpDma_Direction_RemoteToLocal,
|
|
|
|
cnx->src_inst,
|
|
|
|
cnx->dst_inst,
|
|
|
|
HvLpDma_AddressType_RealAddress,
|
|
|
|
HvLpDma_AddressType_TceIndex,
|
2005-10-14 04:51:42 +00:00
|
|
|
iseries_hv_addr(&local_list),
|
|
|
|
iseries_hv_addr(&remote_list),
|
2005-04-16 22:20:36 +00:00
|
|
|
length);
|
|
|
|
if (rc != HvLpDma_Rc_Good) {
|
|
|
|
dev_kfree_skb_irq(skb);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
vlan = skb->data[9];
|
|
|
|
dev = veth_dev[vlan];
|
2005-05-12 07:55:08 +00:00
|
|
|
if (! dev) {
|
|
|
|
/*
|
|
|
|
* Some earlier versions of the driver sent
|
|
|
|
* broadcasts down all connections, even to lpars
|
|
|
|
* that weren't on the relevant vlan. So ignore
|
|
|
|
* packets belonging to a vlan we're not on.
|
|
|
|
* We can also be here if we receive packets while
|
|
|
|
* the driver is going down, because then dev is NULL.
|
|
|
|
*/
|
|
|
|
dev_kfree_skb_irq(skb);
|
2005-04-16 22:20:36 +00:00
|
|
|
continue;
|
2005-05-12 07:55:08 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-11-13 07:37:49 +00:00
|
|
|
port = netdev_priv(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
dest = *((u64 *) skb->data) & 0xFFFFFFFFFFFF0000;
|
|
|
|
|
|
|
|
if ((vlan > HVMAXARCHITECTEDVIRTUALLANS) || !port) {
|
|
|
|
dev_kfree_skb_irq(skb);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (! veth_frame_wanted(port, dest)) {
|
|
|
|
dev_kfree_skb_irq(skb);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_put(skb, length);
|
|
|
|
skb->protocol = eth_type_trans(skb, dev);
|
|
|
|
skb->ip_summed = CHECKSUM_NONE;
|
|
|
|
netif_rx(skb); /* send it up */
|
2007-10-04 00:41:50 +00:00
|
|
|
dev->stats.rx_packets++;
|
|
|
|
dev->stats.rx_bytes += length;
|
2005-04-16 22:20:36 +00:00
|
|
|
} while (startchunk += nchunks, startchunk < VETH_MAX_FRAMES_PER_MSG);
|
|
|
|
|
|
|
|
/* Ack it */
|
|
|
|
spin_lock_irqsave(&cnx->lock, flags);
|
|
|
|
BUG_ON(cnx->num_pending_acks > VETH_MAX_ACKS_PER_MSG);
|
|
|
|
|
|
|
|
cnx->pending_acks[cnx->num_pending_acks++] =
|
|
|
|
event->base_event.xCorrelationToken;
|
|
|
|
|
|
|
|
if ( (cnx->num_pending_acks >= cnx->remote_caps.ack_threshold)
|
|
|
|
|| (cnx->num_pending_acks >= VETH_MAX_ACKS_PER_MSG) )
|
|
|
|
veth_flush_acks(cnx);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&cnx->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void veth_timed_ack(unsigned long ptr)
|
|
|
|
{
|
|
|
|
struct veth_lpar_connection *cnx = (struct veth_lpar_connection *) ptr;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/* Ack all the events */
|
|
|
|
spin_lock_irqsave(&cnx->lock, flags);
|
|
|
|
if (cnx->num_pending_acks > 0)
|
|
|
|
veth_flush_acks(cnx);
|
|
|
|
|
|
|
|
/* Reschedule the timer */
|
|
|
|
cnx->ack_timer.expires = jiffies + cnx->ack_timeout;
|
|
|
|
add_timer(&cnx->ack_timer);
|
|
|
|
spin_unlock_irqrestore(&cnx->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int veth_remove(struct vio_dev *vdev)
|
|
|
|
{
|
2005-09-01 01:29:09 +00:00
|
|
|
struct veth_lpar_connection *cnx;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct net_device *dev;
|
2005-09-01 01:29:09 +00:00
|
|
|
struct veth_port *port;
|
|
|
|
int i;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-09-01 01:29:09 +00:00
|
|
|
dev = veth_dev[vdev->unit_address];
|
|
|
|
|
|
|
|
if (! dev)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
port = netdev_priv(dev);
|
|
|
|
|
|
|
|
for (i = 0; i < HVMAXARCHITECTEDLPS; i++) {
|
|
|
|
cnx = veth_cnx[i];
|
|
|
|
|
|
|
|
if (cnx && (port->lpar_map & (1 << i))) {
|
|
|
|
/* Drop our reference to connections on our VLAN */
|
|
|
|
kobject_put(&cnx->kobject);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2005-09-01 01:29:09 +00:00
|
|
|
|
|
|
|
veth_dev[vdev->unit_address] = NULL;
|
2005-09-01 01:29:21 +00:00
|
|
|
kobject_del(&port->kobject);
|
|
|
|
kobject_put(&port->kobject);
|
2005-09-01 01:29:09 +00:00
|
|
|
unregister_netdev(dev);
|
|
|
|
free_netdev(dev);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int veth_probe(struct vio_dev *vdev, const struct vio_device_id *id)
|
|
|
|
{
|
|
|
|
int i = vdev->unit_address;
|
|
|
|
struct net_device *dev;
|
2005-09-01 01:29:09 +00:00
|
|
|
struct veth_port *port;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-05-15 03:39:47 +00:00
|
|
|
dev = veth_probe_one(i, vdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (dev == NULL) {
|
|
|
|
veth_remove(vdev);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
veth_dev[i] = dev;
|
|
|
|
|
2005-09-01 01:29:09 +00:00
|
|
|
port = (struct veth_port*)netdev_priv(dev);
|
|
|
|
|
|
|
|
/* Start the state machine on each connection on this vlan. If we're
|
|
|
|
* the first dev to do so this will commence link negotiation */
|
|
|
|
for (i = 0; i < HVMAXARCHITECTEDLPS; i++) {
|
|
|
|
struct veth_lpar_connection *cnx;
|
|
|
|
|
|
|
|
if (! (port->lpar_map & (1 << i)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cnx = veth_cnx[i];
|
|
|
|
if (!cnx)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
kobject_get(&cnx->kobject);
|
|
|
|
veth_kick_statemachine(cnx);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* veth_device_table: Used by vio.c to match devices that we
|
|
|
|
* support.
|
|
|
|
*/
|
|
|
|
static struct vio_device_id veth_device_table[] __devinitdata = {
|
2006-05-15 03:39:47 +00:00
|
|
|
{ "network", "IBM,iSeries-l-lan" },
|
2005-08-17 06:42:59 +00:00
|
|
|
{ "", "" }
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(vio, veth_device_table);
|
|
|
|
|
|
|
|
static struct vio_driver veth_driver = {
|
|
|
|
.id_table = veth_device_table,
|
|
|
|
.probe = veth_probe,
|
2005-10-24 04:53:21 +00:00
|
|
|
.remove = veth_remove,
|
|
|
|
.driver = {
|
|
|
|
.name = DRV_NAME,
|
2005-10-24 05:12:22 +00:00
|
|
|
.owner = THIS_MODULE,
|
2005-10-24 04:53:21 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Module initialization/cleanup
|
|
|
|
*/
|
|
|
|
|
2006-12-15 04:42:50 +00:00
|
|
|
static void __exit veth_module_cleanup(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
2005-09-01 01:29:09 +00:00
|
|
|
struct veth_lpar_connection *cnx;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-09-01 01:29:09 +00:00
|
|
|
/* Disconnect our "irq" to stop events coming from the Hypervisor. */
|
2005-04-16 22:20:36 +00:00
|
|
|
HvLpEvent_unregisterHandler(HvLpEvent_Type_VirtualLan);
|
|
|
|
|
2005-09-01 01:29:09 +00:00
|
|
|
/* Make sure any work queued from Hypervisor callbacks is finished. */
|
2005-04-16 22:20:36 +00:00
|
|
|
flush_scheduled_work();
|
|
|
|
|
2005-09-01 01:29:09 +00:00
|
|
|
for (i = 0; i < HVMAXARCHITECTEDLPS; ++i) {
|
|
|
|
cnx = veth_cnx[i];
|
|
|
|
|
|
|
|
if (!cnx)
|
|
|
|
continue;
|
2005-05-12 08:09:45 +00:00
|
|
|
|
2005-09-01 01:29:20 +00:00
|
|
|
/* Remove the connection from sysfs */
|
|
|
|
kobject_del(&cnx->kobject);
|
2005-09-01 01:29:09 +00:00
|
|
|
/* Drop the driver's reference to the connection */
|
|
|
|
kobject_put(&cnx->kobject);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-09-01 01:29:09 +00:00
|
|
|
/* Unregister the driver, which will close all the netdevs and stop
|
|
|
|
* the connections when they're no longer referenced. */
|
|
|
|
vio_unregister_driver(&veth_driver);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
module_exit(veth_module_cleanup);
|
|
|
|
|
2006-12-15 04:42:50 +00:00
|
|
|
static int __init veth_module_init(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int rc;
|
|
|
|
|
2006-12-15 04:42:50 +00:00
|
|
|
if (!firmware_has_feature(FW_FEATURE_ISERIES))
|
|
|
|
return -ENODEV;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
this_lp = HvLpConfig_getLpIndex_outline();
|
|
|
|
|
|
|
|
for (i = 0; i < HVMAXARCHITECTEDLPS; ++i) {
|
|
|
|
rc = veth_init_connection(i);
|
2005-09-01 01:29:08 +00:00
|
|
|
if (rc != 0)
|
|
|
|
goto error;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HvLpEvent_registerHandler(HvLpEvent_Type_VirtualLan,
|
|
|
|
&veth_handle_event);
|
|
|
|
|
2005-09-01 01:29:08 +00:00
|
|
|
rc = vio_register_driver(&veth_driver);
|
|
|
|
if (rc != 0)
|
|
|
|
goto error;
|
|
|
|
|
2005-09-01 01:29:20 +00:00
|
|
|
for (i = 0; i < HVMAXARCHITECTEDLPS; ++i) {
|
|
|
|
struct kobject *kobj;
|
|
|
|
|
|
|
|
if (!veth_cnx[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
kobj = &veth_cnx[i]->kobject;
|
|
|
|
/* If the add failes, complain but otherwise continue */
|
2007-12-19 19:54:39 +00:00
|
|
|
if (0 != driver_add_kobj(&veth_driver.driver, kobj,
|
2007-12-18 06:05:35 +00:00
|
|
|
"cnx%.2d", veth_cnx[i]->remote_lp))
|
2005-09-01 01:29:20 +00:00
|
|
|
veth_error("cnx %d: Failed adding to sysfs.\n", i);
|
|
|
|
}
|
|
|
|
|
2005-09-01 01:29:08 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
for (i = 0; i < HVMAXARCHITECTEDLPS; ++i) {
|
2005-09-01 01:29:09 +00:00
|
|
|
veth_destroy_connection(veth_cnx[i]);
|
2005-09-01 01:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
module_init(veth_module_init);
|