mirror of
https://github.com/torvalds/linux.git
synced 2024-11-01 01:31:44 +00:00
[SPARC64]: Add LDOM virtual channel driver and VIO device layer.
Virtual devices on Sun Logical Domains are built on top of a virtual channel framework. This, with help of hypervisor interfaces, provides a link layer protocol with basic handshaking over which virtual device clients and servers communicate. Built on top of this is a VIO device protocol which has it's own handshaking and message types. At this layer attributes are exchanged (disk size, network device addresses, etc.) descriptor rings are registered, and data transfers are triggers and replied to. Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
8f41958bdd
commit
e53e97ce3c
@ -305,6 +305,12 @@ config SUN_IO
|
||||
bool
|
||||
default y
|
||||
|
||||
config SUN_LDOMS
|
||||
bool "Sun Logical Domains support"
|
||||
help
|
||||
Say Y here is you want to support virtual devices via
|
||||
Logical Domains.
|
||||
|
||||
config PCI
|
||||
bool "PCI support"
|
||||
select ARCH_SUPPORTS_MSI
|
||||
|
@ -26,6 +26,7 @@ obj-$(CONFIG_MODULES) += module.o
|
||||
obj-$(CONFIG_US3_FREQ) += us3_cpufreq.o
|
||||
obj-$(CONFIG_US2E_FREQ) += us2e_cpufreq.o
|
||||
obj-$(CONFIG_KPROBES) += kprobes.o
|
||||
obj-$(CONFIG_SUN_LDOMS) += ldc.o vio.o viohs.o
|
||||
obj-$(CONFIG_AUDIT) += audit.o
|
||||
obj-$(CONFIG_AUDIT)$(CONFIG_SPARC32_COMPAT) += compat_audit.o
|
||||
obj-y += $(obj-yy)
|
||||
|
2338
arch/sparc64/kernel/ldc.c
Normal file
2338
arch/sparc64/kernel/ldc.c
Normal file
File diff suppressed because it is too large
Load Diff
347
arch/sparc64/kernel/vio.c
Normal file
347
arch/sparc64/kernel/vio.c
Normal file
@ -0,0 +1,347 @@
|
||||
/* vio.c: Virtual I/O channel devices probing infrastructure.
|
||||
*
|
||||
* Copyright (c) 2003-2005 IBM Corp.
|
||||
* Dave Engebretsen engebret@us.ibm.com
|
||||
* Santiago Leon santil@us.ibm.com
|
||||
* Hollis Blanchard <hollisb@us.ibm.com>
|
||||
* Stephen Rothwell
|
||||
*
|
||||
* Adapted to sparc64 by David S. Miller davem@davemloft.net
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/irq.h>
|
||||
#include <linux/init.h>
|
||||
|
||||
#include <asm/mdesc.h>
|
||||
#include <asm/vio.h>
|
||||
|
||||
static inline int find_in_proplist(const char *list, const char *match,
|
||||
int len)
|
||||
{
|
||||
while (len > 0) {
|
||||
int l;
|
||||
|
||||
if (!strcmp(list, match))
|
||||
return 1;
|
||||
l = strlen(list) + 1;
|
||||
list += l;
|
||||
len -= l;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct vio_device_id *vio_match_device(
|
||||
const struct vio_device_id *matches,
|
||||
const struct vio_dev *dev)
|
||||
{
|
||||
const char *type, *compat;
|
||||
int len;
|
||||
|
||||
type = dev->type;
|
||||
compat = dev->compat;
|
||||
len = dev->compat_len;
|
||||
|
||||
while (matches->type[0] || matches->compat[0]) {
|
||||
int match = 1;
|
||||
if (matches->type[0]) {
|
||||
match &= type
|
||||
&& !strcmp(matches->type, type);
|
||||
}
|
||||
if (matches->compat[0]) {
|
||||
match &= compat &&
|
||||
find_in_proplist(compat, matches->compat, len);
|
||||
}
|
||||
if (match)
|
||||
return matches;
|
||||
matches++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int vio_bus_match(struct device *dev, struct device_driver *drv)
|
||||
{
|
||||
struct vio_dev *vio_dev = to_vio_dev(dev);
|
||||
struct vio_driver *vio_drv = to_vio_driver(drv);
|
||||
const struct vio_device_id *matches = vio_drv->id_table;
|
||||
|
||||
if (!matches)
|
||||
return 0;
|
||||
|
||||
return vio_match_device(matches, vio_dev) != NULL;
|
||||
}
|
||||
|
||||
static int vio_device_probe(struct device *dev)
|
||||
{
|
||||
struct vio_dev *vdev = to_vio_dev(dev);
|
||||
struct vio_driver *drv = to_vio_driver(dev->driver);
|
||||
const struct vio_device_id *id;
|
||||
int error = -ENODEV;
|
||||
|
||||
if (drv->probe) {
|
||||
id = vio_match_device(drv->id_table, vdev);
|
||||
if (id)
|
||||
error = drv->probe(vdev, id);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
static int vio_device_remove(struct device *dev)
|
||||
{
|
||||
struct vio_dev *vdev = to_vio_dev(dev);
|
||||
struct vio_driver *drv = to_vio_driver(dev->driver);
|
||||
|
||||
if (drv->remove)
|
||||
return drv->remove(vdev);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static ssize_t devspec_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct vio_dev *vdev = to_vio_dev(dev);
|
||||
const char *str = "none";
|
||||
|
||||
if (vdev->type) {
|
||||
if (!strcmp(vdev->type, "network"))
|
||||
str = "vnet";
|
||||
else if (!strcmp(vdev->type, "block"))
|
||||
str = "vdisk";
|
||||
}
|
||||
|
||||
return sprintf(buf, "%s\n", str);
|
||||
}
|
||||
|
||||
static struct device_attribute vio_dev_attrs[] = {
|
||||
__ATTR_RO(devspec),
|
||||
__ATTR_NULL
|
||||
};
|
||||
|
||||
static struct bus_type vio_bus_type = {
|
||||
.name = "vio",
|
||||
.dev_attrs = vio_dev_attrs,
|
||||
.match = vio_bus_match,
|
||||
.probe = vio_device_probe,
|
||||
.remove = vio_device_remove,
|
||||
};
|
||||
|
||||
int vio_register_driver(struct vio_driver *viodrv)
|
||||
{
|
||||
viodrv->driver.bus = &vio_bus_type;
|
||||
|
||||
return driver_register(&viodrv->driver);
|
||||
}
|
||||
EXPORT_SYMBOL(vio_register_driver);
|
||||
|
||||
void vio_unregister_driver(struct vio_driver *viodrv)
|
||||
{
|
||||
driver_unregister(&viodrv->driver);
|
||||
}
|
||||
EXPORT_SYMBOL(vio_unregister_driver);
|
||||
|
||||
struct mdesc_node *vio_find_endpoint(struct vio_dev *vdev)
|
||||
{
|
||||
struct mdesc_node *endp, *mp = vdev->mp;
|
||||
int i;
|
||||
|
||||
endp = NULL;
|
||||
for (i = 0; i < mp->num_arcs; i++) {
|
||||
struct mdesc_node *t;
|
||||
|
||||
if (strcmp(mp->arcs[i].name, "fwd"))
|
||||
continue;
|
||||
|
||||
t = mp->arcs[i].arc;
|
||||
if (strcmp(t->name, "channel-endpoint"))
|
||||
continue;
|
||||
|
||||
endp = t;
|
||||
break;
|
||||
}
|
||||
|
||||
return endp;
|
||||
}
|
||||
EXPORT_SYMBOL(vio_find_endpoint);
|
||||
|
||||
static void __devinit vio_dev_release(struct device *dev)
|
||||
{
|
||||
kfree(to_vio_dev(dev));
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
show_pciobppath_attr(struct device *dev, struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct vio_dev *vdev;
|
||||
struct device_node *dp;
|
||||
|
||||
vdev = to_vio_dev(dev);
|
||||
dp = vdev->dp;
|
||||
|
||||
return snprintf (buf, PAGE_SIZE, "%s\n", dp->full_name);
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(obppath, S_IRUSR | S_IRGRP | S_IROTH,
|
||||
show_pciobppath_attr, NULL);
|
||||
|
||||
struct device_node *cdev_node;
|
||||
|
||||
static struct vio_dev *root_vdev;
|
||||
static u64 cdev_cfg_handle;
|
||||
|
||||
static struct vio_dev *vio_create_one(struct mdesc_node *mp,
|
||||
struct device *parent)
|
||||
{
|
||||
const char *type, *compat;
|
||||
struct device_node *dp;
|
||||
struct vio_dev *vdev;
|
||||
const u64 *irq;
|
||||
int err, clen;
|
||||
|
||||
type = md_get_property(mp, "device-type", NULL);
|
||||
if (!type)
|
||||
type = md_get_property(mp, "name", NULL);
|
||||
compat = md_get_property(mp, "device-type", &clen);
|
||||
|
||||
vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
|
||||
if (!vdev) {
|
||||
printk(KERN_ERR "VIO: Could not allocate vio_dev\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vdev->mp = mp;
|
||||
vdev->type = type;
|
||||
vdev->compat = compat;
|
||||
vdev->compat_len = clen;
|
||||
|
||||
irq = md_get_property(mp, "tx-ino", NULL);
|
||||
if (irq)
|
||||
mp->irqs[0] = sun4v_build_virq(cdev_cfg_handle, *irq);
|
||||
|
||||
irq = md_get_property(mp, "rx-ino", NULL);
|
||||
if (irq)
|
||||
mp->irqs[1] = sun4v_build_virq(cdev_cfg_handle, *irq);
|
||||
|
||||
snprintf(vdev->dev.bus_id, BUS_ID_SIZE, "%lx", mp->node);
|
||||
vdev->dev.parent = parent;
|
||||
vdev->dev.bus = &vio_bus_type;
|
||||
vdev->dev.release = vio_dev_release;
|
||||
|
||||
if (parent == NULL) {
|
||||
dp = cdev_node;
|
||||
} else if (to_vio_dev(parent) == root_vdev) {
|
||||
dp = of_get_next_child(cdev_node, NULL);
|
||||
while (dp) {
|
||||
if (!strcmp(dp->type, type))
|
||||
break;
|
||||
|
||||
dp = of_get_next_child(cdev_node, dp);
|
||||
}
|
||||
} else {
|
||||
dp = to_vio_dev(parent)->dp;
|
||||
}
|
||||
vdev->dp = dp;
|
||||
|
||||
err = device_register(&vdev->dev);
|
||||
if (err) {
|
||||
printk(KERN_ERR "VIO: Could not register device %s, err=%d\n",
|
||||
vdev->dev.bus_id, err);
|
||||
kfree(vdev);
|
||||
return NULL;
|
||||
}
|
||||
if (vdev->dp)
|
||||
err = sysfs_create_file(&vdev->dev.kobj,
|
||||
&dev_attr_obppath.attr);
|
||||
|
||||
return vdev;
|
||||
}
|
||||
|
||||
static void walk_tree(struct mdesc_node *n, struct vio_dev *parent)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n->num_arcs; i++) {
|
||||
struct mdesc_node *mp;
|
||||
struct vio_dev *vdev;
|
||||
|
||||
if (strcmp(n->arcs[i].name, "fwd"))
|
||||
continue;
|
||||
|
||||
mp = n->arcs[i].arc;
|
||||
|
||||
vdev = vio_create_one(mp, &parent->dev);
|
||||
if (vdev && mp->num_arcs)
|
||||
walk_tree(mp, vdev);
|
||||
}
|
||||
}
|
||||
|
||||
static void create_devices(struct mdesc_node *root)
|
||||
{
|
||||
root_vdev = vio_create_one(root, NULL);
|
||||
if (!root_vdev) {
|
||||
printk(KERN_ERR "VIO: Coult not create root device.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
walk_tree(root, root_vdev);
|
||||
}
|
||||
|
||||
const char *channel_devices_node = "channel-devices";
|
||||
const char *channel_devices_compat = "SUNW,sun4v-channel-devices";
|
||||
const char *cfg_handle_prop = "cfg-handle";
|
||||
|
||||
static int __init vio_init(void)
|
||||
{
|
||||
struct mdesc_node *root;
|
||||
const char *compat;
|
||||
const u64 *cfg_handle;
|
||||
int err, len;
|
||||
|
||||
root = md_find_node_by_name(NULL, channel_devices_node);
|
||||
if (!root) {
|
||||
printk(KERN_INFO "VIO: No channel-devices MDESC node.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
cdev_node = of_find_node_by_name(NULL, "channel-devices");
|
||||
if (!cdev_node) {
|
||||
printk(KERN_INFO "VIO: No channel-devices OBP node.\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
compat = md_get_property(root, "compatible", &len);
|
||||
if (!compat) {
|
||||
printk(KERN_ERR "VIO: Channel devices lacks compatible "
|
||||
"property\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
if (!find_in_proplist(compat, channel_devices_compat, len)) {
|
||||
printk(KERN_ERR "VIO: Channel devices node lacks (%s) "
|
||||
"compat entry.\n", channel_devices_compat);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
cfg_handle = md_get_property(root, cfg_handle_prop, NULL);
|
||||
if (!cfg_handle) {
|
||||
printk(KERN_ERR "VIO: Channel devices lacks %s property\n",
|
||||
cfg_handle_prop);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
cdev_cfg_handle = *cfg_handle;
|
||||
|
||||
err = bus_register(&vio_bus_type);
|
||||
if (err) {
|
||||
printk(KERN_ERR "VIO: Could not register bus type err=%d\n",
|
||||
err);
|
||||
return err;
|
||||
}
|
||||
|
||||
create_devices(root);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
postcore_initcall(vio_init);
|
809
arch/sparc64/kernel/viohs.c
Normal file
809
arch/sparc64/kernel/viohs.c
Normal file
@ -0,0 +1,809 @@
|
||||
/* viohs.c: LDOM Virtual I/O handshake helper layer.
|
||||
*
|
||||
* Copyright (C) 2007 David S. Miller <davem@davemloft.net>
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include <asm/ldc.h>
|
||||
#include <asm/vio.h>
|
||||
|
||||
int vio_ldc_send(struct vio_driver_state *vio, void *data, int len)
|
||||
{
|
||||
int err, limit = 1000;
|
||||
|
||||
err = -EINVAL;
|
||||
while (limit-- > 0) {
|
||||
err = ldc_write(vio->lp, data, len);
|
||||
if (!err || (err != -EAGAIN))
|
||||
break;
|
||||
udelay(1);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(vio_ldc_send);
|
||||
|
||||
static int send_ctrl(struct vio_driver_state *vio,
|
||||
struct vio_msg_tag *tag, int len)
|
||||
{
|
||||
tag->sid = vio_send_sid(vio);
|
||||
return vio_ldc_send(vio, tag, len);
|
||||
}
|
||||
|
||||
static void init_tag(struct vio_msg_tag *tag, u8 type, u8 stype, u16 stype_env)
|
||||
{
|
||||
tag->type = type;
|
||||
tag->stype = stype;
|
||||
tag->stype_env = stype_env;
|
||||
}
|
||||
|
||||
static int send_version(struct vio_driver_state *vio, u16 major, u16 minor)
|
||||
{
|
||||
struct vio_ver_info pkt;
|
||||
|
||||
vio->_local_sid = (u32) sched_clock();
|
||||
|
||||
memset(&pkt, 0, sizeof(pkt));
|
||||
init_tag(&pkt.tag, VIO_TYPE_CTRL, VIO_SUBTYPE_INFO, VIO_VER_INFO);
|
||||
pkt.major = major;
|
||||
pkt.minor = minor;
|
||||
pkt.dev_class = vio->dev_class;
|
||||
|
||||
viodbg(HS, "SEND VERSION INFO maj[%u] min[%u] devclass[%u]\n",
|
||||
major, minor, vio->dev_class);
|
||||
|
||||
return send_ctrl(vio, &pkt.tag, sizeof(pkt));
|
||||
}
|
||||
|
||||
static int start_handshake(struct vio_driver_state *vio)
|
||||
{
|
||||
int err;
|
||||
|
||||
viodbg(HS, "START HANDSHAKE\n");
|
||||
|
||||
vio->hs_state = VIO_HS_INVALID;
|
||||
|
||||
err = send_version(vio,
|
||||
vio->ver_table[0].major,
|
||||
vio->ver_table[0].minor);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vio_link_state_change(struct vio_driver_state *vio, int event)
|
||||
{
|
||||
if (event == LDC_EVENT_UP) {
|
||||
vio->hs_state = VIO_HS_INVALID;
|
||||
|
||||
switch (vio->dev_class) {
|
||||
case VDEV_NETWORK:
|
||||
case VDEV_NETWORK_SWITCH:
|
||||
vio->dr_state = (VIO_DR_STATE_TXREQ |
|
||||
VIO_DR_STATE_RXREQ);
|
||||
break;
|
||||
|
||||
case VDEV_DISK:
|
||||
vio->dr_state = VIO_DR_STATE_TXREQ;
|
||||
break;
|
||||
case VDEV_DISK_SERVER:
|
||||
vio->dr_state = VIO_DR_STATE_RXREQ;
|
||||
break;
|
||||
}
|
||||
start_handshake(vio);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL(vio_link_state_change);
|
||||
|
||||
static int handshake_failure(struct vio_driver_state *vio)
|
||||
{
|
||||
struct vio_dring_state *dr;
|
||||
|
||||
/* XXX Put policy here... Perhaps start a timer to fire
|
||||
* XXX in 100 ms, which will bring the link up and retry
|
||||
* XXX the handshake.
|
||||
*/
|
||||
|
||||
viodbg(HS, "HANDSHAKE FAILURE\n");
|
||||
|
||||
vio->dr_state &= ~(VIO_DR_STATE_TXREG |
|
||||
VIO_DR_STATE_RXREG);
|
||||
|
||||
dr = &vio->drings[VIO_DRIVER_RX_RING];
|
||||
memset(dr, 0, sizeof(*dr));
|
||||
|
||||
kfree(vio->desc_buf);
|
||||
vio->desc_buf = NULL;
|
||||
vio->desc_buf_len = 0;
|
||||
|
||||
vio->hs_state = VIO_HS_INVALID;
|
||||
|
||||
return -ECONNRESET;
|
||||
}
|
||||
|
||||
static int process_unknown(struct vio_driver_state *vio, void *arg)
|
||||
{
|
||||
struct vio_msg_tag *pkt = arg;
|
||||
|
||||
viodbg(HS, "UNKNOWN CONTROL [%02x:%02x:%04x:%08x]\n",
|
||||
pkt->type, pkt->stype, pkt->stype_env, pkt->sid);
|
||||
|
||||
printk(KERN_ERR "vio: ID[%lu] Resetting connection.\n",
|
||||
vio->channel_id);
|
||||
|
||||
ldc_disconnect(vio->lp);
|
||||
|
||||
return -ECONNRESET;
|
||||
}
|
||||
|
||||
static int send_dreg(struct vio_driver_state *vio)
|
||||
{
|
||||
struct vio_dring_state *dr = &vio->drings[VIO_DRIVER_TX_RING];
|
||||
union {
|
||||
struct vio_dring_register pkt;
|
||||
char all[sizeof(struct vio_dring_register) +
|
||||
(sizeof(struct ldc_trans_cookie) *
|
||||
dr->ncookies)];
|
||||
} u;
|
||||
int i;
|
||||
|
||||
memset(&u, 0, sizeof(u));
|
||||
init_tag(&u.pkt.tag, VIO_TYPE_CTRL, VIO_SUBTYPE_INFO, VIO_DRING_REG);
|
||||
u.pkt.dring_ident = 0;
|
||||
u.pkt.num_descr = dr->num_entries;
|
||||
u.pkt.descr_size = dr->entry_size;
|
||||
u.pkt.options = VIO_TX_DRING;
|
||||
u.pkt.num_cookies = dr->ncookies;
|
||||
|
||||
viodbg(HS, "SEND DRING_REG INFO ndesc[%u] dsz[%u] opt[0x%x] "
|
||||
"ncookies[%u]\n",
|
||||
u.pkt.num_descr, u.pkt.descr_size, u.pkt.options,
|
||||
u.pkt.num_cookies);
|
||||
|
||||
for (i = 0; i < dr->ncookies; i++) {
|
||||
u.pkt.cookies[i] = dr->cookies[i];
|
||||
|
||||
viodbg(HS, "DRING COOKIE(%d) [%016llx:%016llx]\n",
|
||||
i,
|
||||
(unsigned long long) u.pkt.cookies[i].cookie_addr,
|
||||
(unsigned long long) u.pkt.cookies[i].cookie_size);
|
||||
}
|
||||
|
||||
return send_ctrl(vio, &u.pkt.tag, sizeof(u));
|
||||
}
|
||||
|
||||
static int send_rdx(struct vio_driver_state *vio)
|
||||
{
|
||||
struct vio_rdx pkt;
|
||||
|
||||
memset(&pkt, 0, sizeof(pkt));
|
||||
|
||||
init_tag(&pkt.tag, VIO_TYPE_CTRL, VIO_SUBTYPE_INFO, VIO_RDX);
|
||||
|
||||
viodbg(HS, "SEND RDX INFO\n");
|
||||
|
||||
return send_ctrl(vio, &pkt.tag, sizeof(pkt));
|
||||
}
|
||||
|
||||
static int send_attr(struct vio_driver_state *vio)
|
||||
{
|
||||
return vio->ops->send_attr(vio);
|
||||
}
|
||||
|
||||
static struct vio_version *find_by_major(struct vio_driver_state *vio,
|
||||
u16 major)
|
||||
{
|
||||
struct vio_version *ret = NULL;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < vio->ver_table_entries; i++) {
|
||||
struct vio_version *v = &vio->ver_table[i];
|
||||
if (v->major <= major) {
|
||||
ret = v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int process_ver_info(struct vio_driver_state *vio,
|
||||
struct vio_ver_info *pkt)
|
||||
{
|
||||
struct vio_version *vap;
|
||||
int err;
|
||||
|
||||
viodbg(HS, "GOT VERSION INFO maj[%u] min[%u] devclass[%u]\n",
|
||||
pkt->major, pkt->minor, pkt->dev_class);
|
||||
|
||||
if (vio->hs_state != VIO_HS_INVALID) {
|
||||
/* XXX Perhaps invoke start_handshake? XXX */
|
||||
memset(&vio->ver, 0, sizeof(vio->ver));
|
||||
vio->hs_state = VIO_HS_INVALID;
|
||||
}
|
||||
|
||||
vap = find_by_major(vio, pkt->major);
|
||||
|
||||
vio->_peer_sid = pkt->tag.sid;
|
||||
|
||||
if (!vap) {
|
||||
pkt->tag.stype = VIO_SUBTYPE_NACK;
|
||||
pkt->major = 0;
|
||||
pkt->minor = 0;
|
||||
viodbg(HS, "SEND VERSION NACK maj[0] min[0]\n");
|
||||
err = send_ctrl(vio, &pkt->tag, sizeof(*pkt));
|
||||
} else if (vap->major != pkt->major) {
|
||||
pkt->tag.stype = VIO_SUBTYPE_NACK;
|
||||
pkt->major = vap->major;
|
||||
pkt->minor = vap->minor;
|
||||
viodbg(HS, "SEND VERSION NACK maj[%u] min[%u]\n",
|
||||
pkt->major, pkt->minor);
|
||||
err = send_ctrl(vio, &pkt->tag, sizeof(*pkt));
|
||||
} else {
|
||||
struct vio_version ver = {
|
||||
.major = pkt->major,
|
||||
.minor = pkt->minor,
|
||||
};
|
||||
if (ver.minor > vap->minor)
|
||||
ver.minor = vap->minor;
|
||||
pkt->minor = ver.minor;
|
||||
pkt->tag.stype = VIO_SUBTYPE_ACK;
|
||||
viodbg(HS, "SEND VERSION ACK maj[%u] min[%u]\n",
|
||||
pkt->major, pkt->minor);
|
||||
err = send_ctrl(vio, &pkt->tag, sizeof(*pkt));
|
||||
if (err > 0) {
|
||||
vio->ver = ver;
|
||||
vio->hs_state = VIO_HS_GOTVERS;
|
||||
}
|
||||
}
|
||||
if (err < 0)
|
||||
return handshake_failure(vio);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int process_ver_ack(struct vio_driver_state *vio,
|
||||
struct vio_ver_info *pkt)
|
||||
{
|
||||
viodbg(HS, "GOT VERSION ACK maj[%u] min[%u] devclass[%u]\n",
|
||||
pkt->major, pkt->minor, pkt->dev_class);
|
||||
|
||||
if (vio->hs_state & VIO_HS_GOTVERS) {
|
||||
if (vio->ver.major != pkt->major ||
|
||||
vio->ver.minor != pkt->minor) {
|
||||
pkt->tag.stype = VIO_SUBTYPE_NACK;
|
||||
(void) send_ctrl(vio, &pkt->tag, sizeof(*pkt));
|
||||
return handshake_failure(vio);
|
||||
}
|
||||
} else {
|
||||
vio->ver.major = pkt->major;
|
||||
vio->ver.minor = pkt->minor;
|
||||
vio->hs_state = VIO_HS_GOTVERS;
|
||||
}
|
||||
|
||||
switch (vio->dev_class) {
|
||||
case VDEV_NETWORK:
|
||||
case VDEV_DISK:
|
||||
if (send_attr(vio) < 0)
|
||||
return handshake_failure(vio);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int process_ver_nack(struct vio_driver_state *vio,
|
||||
struct vio_ver_info *pkt)
|
||||
{
|
||||
struct vio_version *nver;
|
||||
|
||||
viodbg(HS, "GOT VERSION NACK maj[%u] min[%u] devclass[%u]\n",
|
||||
pkt->major, pkt->minor, pkt->dev_class);
|
||||
|
||||
if ((pkt->major == 0 && pkt->minor == 0) ||
|
||||
!(nver = find_by_major(vio, pkt->major)))
|
||||
return handshake_failure(vio);
|
||||
|
||||
if (send_version(vio, nver->major, nver->minor) < 0)
|
||||
return handshake_failure(vio);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int process_ver(struct vio_driver_state *vio, struct vio_ver_info *pkt)
|
||||
{
|
||||
switch (pkt->tag.stype) {
|
||||
case VIO_SUBTYPE_INFO:
|
||||
return process_ver_info(vio, pkt);
|
||||
|
||||
case VIO_SUBTYPE_ACK:
|
||||
return process_ver_ack(vio, pkt);
|
||||
|
||||
case VIO_SUBTYPE_NACK:
|
||||
return process_ver_nack(vio, pkt);
|
||||
|
||||
default:
|
||||
return handshake_failure(vio);
|
||||
};
|
||||
}
|
||||
|
||||
static int process_attr(struct vio_driver_state *vio, void *pkt)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (!(vio->hs_state & VIO_HS_GOTVERS))
|
||||
return handshake_failure(vio);
|
||||
|
||||
err = vio->ops->handle_attr(vio, pkt);
|
||||
if (err < 0) {
|
||||
return handshake_failure(vio);
|
||||
} else {
|
||||
vio->hs_state |= VIO_HS_GOT_ATTR;
|
||||
|
||||
if ((vio->dr_state & VIO_DR_STATE_TXREQ) &&
|
||||
!(vio->hs_state & VIO_HS_SENT_DREG)) {
|
||||
if (send_dreg(vio) < 0)
|
||||
return handshake_failure(vio);
|
||||
|
||||
vio->hs_state |= VIO_HS_SENT_DREG;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int all_drings_registered(struct vio_driver_state *vio)
|
||||
{
|
||||
int need_rx, need_tx;
|
||||
|
||||
need_rx = (vio->dr_state & VIO_DR_STATE_RXREQ);
|
||||
need_tx = (vio->dr_state & VIO_DR_STATE_TXREQ);
|
||||
|
||||
if (need_rx &&
|
||||
!(vio->dr_state & VIO_DR_STATE_RXREG))
|
||||
return 0;
|
||||
|
||||
if (need_tx &&
|
||||
!(vio->dr_state & VIO_DR_STATE_TXREG))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int process_dreg_info(struct vio_driver_state *vio,
|
||||
struct vio_dring_register *pkt)
|
||||
{
|
||||
struct vio_dring_state *dr;
|
||||
int i, len;
|
||||
|
||||
viodbg(HS, "GOT DRING_REG INFO ident[%llx] "
|
||||
"ndesc[%u] dsz[%u] opt[0x%x] ncookies[%u]\n",
|
||||
(unsigned long long) pkt->dring_ident,
|
||||
pkt->num_descr, pkt->descr_size, pkt->options,
|
||||
pkt->num_cookies);
|
||||
|
||||
if (!(vio->dr_state & VIO_DR_STATE_RXREQ))
|
||||
goto send_nack;
|
||||
|
||||
if (vio->dr_state & VIO_DR_STATE_RXREG)
|
||||
goto send_nack;
|
||||
|
||||
vio->desc_buf = kzalloc(pkt->descr_size, GFP_ATOMIC);
|
||||
if (!vio->desc_buf)
|
||||
goto send_nack;
|
||||
|
||||
vio->desc_buf_len = pkt->descr_size;
|
||||
|
||||
dr = &vio->drings[VIO_DRIVER_RX_RING];
|
||||
|
||||
dr->num_entries = pkt->num_descr;
|
||||
dr->entry_size = pkt->descr_size;
|
||||
dr->ncookies = pkt->num_cookies;
|
||||
for (i = 0; i < dr->ncookies; i++) {
|
||||
dr->cookies[i] = pkt->cookies[i];
|
||||
|
||||
viodbg(HS, "DRING COOKIE(%d) [%016llx:%016llx]\n",
|
||||
i,
|
||||
(unsigned long long)
|
||||
pkt->cookies[i].cookie_addr,
|
||||
(unsigned long long)
|
||||
pkt->cookies[i].cookie_size);
|
||||
}
|
||||
|
||||
pkt->tag.stype = VIO_SUBTYPE_ACK;
|
||||
pkt->dring_ident = ++dr->ident;
|
||||
|
||||
viodbg(HS, "SEND DRING_REG ACK ident[%llx]\n",
|
||||
(unsigned long long) pkt->dring_ident);
|
||||
|
||||
len = (sizeof(*pkt) +
|
||||
(dr->ncookies * sizeof(struct ldc_trans_cookie)));
|
||||
if (send_ctrl(vio, &pkt->tag, len) < 0)
|
||||
goto send_nack;
|
||||
|
||||
vio->dr_state |= VIO_DR_STATE_RXREG;
|
||||
|
||||
return 0;
|
||||
|
||||
send_nack:
|
||||
pkt->tag.stype = VIO_SUBTYPE_NACK;
|
||||
viodbg(HS, "SEND DRING_REG NACK\n");
|
||||
(void) send_ctrl(vio, &pkt->tag, sizeof(*pkt));
|
||||
|
||||
return handshake_failure(vio);
|
||||
}
|
||||
|
||||
static int process_dreg_ack(struct vio_driver_state *vio,
|
||||
struct vio_dring_register *pkt)
|
||||
{
|
||||
struct vio_dring_state *dr;
|
||||
|
||||
viodbg(HS, "GOT DRING_REG ACK ident[%llx] "
|
||||
"ndesc[%u] dsz[%u] opt[0x%x] ncookies[%u]\n",
|
||||
(unsigned long long) pkt->dring_ident,
|
||||
pkt->num_descr, pkt->descr_size, pkt->options,
|
||||
pkt->num_cookies);
|
||||
|
||||
dr = &vio->drings[VIO_DRIVER_TX_RING];
|
||||
|
||||
if (!(vio->dr_state & VIO_DR_STATE_TXREQ))
|
||||
return handshake_failure(vio);
|
||||
|
||||
dr->ident = pkt->dring_ident;
|
||||
vio->dr_state |= VIO_DR_STATE_TXREG;
|
||||
|
||||
if (all_drings_registered(vio)) {
|
||||
if (send_rdx(vio) < 0)
|
||||
return handshake_failure(vio);
|
||||
vio->hs_state = VIO_HS_SENT_RDX;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int process_dreg_nack(struct vio_driver_state *vio,
|
||||
struct vio_dring_register *pkt)
|
||||
{
|
||||
viodbg(HS, "GOT DRING_REG NACK ident[%llx] "
|
||||
"ndesc[%u] dsz[%u] opt[0x%x] ncookies[%u]\n",
|
||||
(unsigned long long) pkt->dring_ident,
|
||||
pkt->num_descr, pkt->descr_size, pkt->options,
|
||||
pkt->num_cookies);
|
||||
|
||||
return handshake_failure(vio);
|
||||
}
|
||||
|
||||
static int process_dreg(struct vio_driver_state *vio,
|
||||
struct vio_dring_register *pkt)
|
||||
{
|
||||
if (!(vio->hs_state & VIO_HS_GOTVERS))
|
||||
return handshake_failure(vio);
|
||||
|
||||
switch (pkt->tag.stype) {
|
||||
case VIO_SUBTYPE_INFO:
|
||||
return process_dreg_info(vio, pkt);
|
||||
|
||||
case VIO_SUBTYPE_ACK:
|
||||
return process_dreg_ack(vio, pkt);
|
||||
|
||||
case VIO_SUBTYPE_NACK:
|
||||
return process_dreg_nack(vio, pkt);
|
||||
|
||||
default:
|
||||
return handshake_failure(vio);
|
||||
}
|
||||
}
|
||||
|
||||
static int process_dunreg(struct vio_driver_state *vio,
|
||||
struct vio_dring_unregister *pkt)
|
||||
{
|
||||
struct vio_dring_state *dr = &vio->drings[VIO_DRIVER_RX_RING];
|
||||
|
||||
viodbg(HS, "GOT DRING_UNREG\n");
|
||||
|
||||
if (pkt->dring_ident != dr->ident)
|
||||
return 0;
|
||||
|
||||
vio->dr_state &= ~VIO_DR_STATE_RXREG;
|
||||
|
||||
memset(dr, 0, sizeof(*dr));
|
||||
|
||||
kfree(vio->desc_buf);
|
||||
vio->desc_buf = NULL;
|
||||
vio->desc_buf_len = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int process_rdx_info(struct vio_driver_state *vio, struct vio_rdx *pkt)
|
||||
{
|
||||
viodbg(HS, "GOT RDX INFO\n");
|
||||
|
||||
pkt->tag.stype = VIO_SUBTYPE_ACK;
|
||||
viodbg(HS, "SEND RDX ACK\n");
|
||||
if (send_ctrl(vio, &pkt->tag, sizeof(*pkt)) < 0)
|
||||
return handshake_failure(vio);
|
||||
|
||||
vio->hs_state |= VIO_HS_SENT_RDX_ACK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int process_rdx_ack(struct vio_driver_state *vio, struct vio_rdx *pkt)
|
||||
{
|
||||
viodbg(HS, "GOT RDX ACK\n");
|
||||
|
||||
if (!(vio->hs_state & VIO_HS_SENT_RDX))
|
||||
return handshake_failure(vio);
|
||||
|
||||
vio->hs_state |= VIO_HS_GOT_RDX_ACK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int process_rdx_nack(struct vio_driver_state *vio, struct vio_rdx *pkt)
|
||||
{
|
||||
viodbg(HS, "GOT RDX NACK\n");
|
||||
|
||||
return handshake_failure(vio);
|
||||
}
|
||||
|
||||
static int process_rdx(struct vio_driver_state *vio, struct vio_rdx *pkt)
|
||||
{
|
||||
if (!all_drings_registered(vio))
|
||||
handshake_failure(vio);
|
||||
|
||||
switch (pkt->tag.stype) {
|
||||
case VIO_SUBTYPE_INFO:
|
||||
return process_rdx_info(vio, pkt);
|
||||
|
||||
case VIO_SUBTYPE_ACK:
|
||||
return process_rdx_ack(vio, pkt);
|
||||
|
||||
case VIO_SUBTYPE_NACK:
|
||||
return process_rdx_nack(vio, pkt);
|
||||
|
||||
default:
|
||||
return handshake_failure(vio);
|
||||
}
|
||||
}
|
||||
|
||||
int vio_control_pkt_engine(struct vio_driver_state *vio, void *pkt)
|
||||
{
|
||||
struct vio_msg_tag *tag = pkt;
|
||||
u8 prev_state = vio->hs_state;
|
||||
int err;
|
||||
|
||||
switch (tag->stype_env) {
|
||||
case VIO_VER_INFO:
|
||||
err = process_ver(vio, pkt);
|
||||
break;
|
||||
|
||||
case VIO_ATTR_INFO:
|
||||
err = process_attr(vio, pkt);
|
||||
break;
|
||||
|
||||
case VIO_DRING_REG:
|
||||
err = process_dreg(vio, pkt);
|
||||
break;
|
||||
|
||||
case VIO_DRING_UNREG:
|
||||
err = process_dunreg(vio, pkt);
|
||||
break;
|
||||
|
||||
case VIO_RDX:
|
||||
err = process_rdx(vio, pkt);
|
||||
break;
|
||||
|
||||
default:
|
||||
err = process_unknown(vio, pkt);
|
||||
break;
|
||||
}
|
||||
if (!err &&
|
||||
vio->hs_state != prev_state &&
|
||||
(vio->hs_state & VIO_HS_COMPLETE))
|
||||
vio->ops->handshake_complete(vio);
|
||||
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(vio_control_pkt_engine);
|
||||
|
||||
void vio_conn_reset(struct vio_driver_state *vio)
|
||||
{
|
||||
}
|
||||
EXPORT_SYMBOL(vio_conn_reset);
|
||||
|
||||
/* The issue is that the Solaris virtual disk server just mirrors the
|
||||
* SID values it gets from the client peer. So we work around that
|
||||
* here in vio_{validate,send}_sid() so that the drivers don't need
|
||||
* to be aware of this crap.
|
||||
*/
|
||||
int vio_validate_sid(struct vio_driver_state *vio, struct vio_msg_tag *tp)
|
||||
{
|
||||
u32 sid;
|
||||
|
||||
/* Always let VERSION+INFO packets through unchecked, they
|
||||
* define the new SID.
|
||||
*/
|
||||
if (tp->type == VIO_TYPE_CTRL &&
|
||||
tp->stype == VIO_SUBTYPE_INFO &&
|
||||
tp->stype_env == VIO_VER_INFO)
|
||||
return 0;
|
||||
|
||||
/* Ok, now figure out which SID to use. */
|
||||
switch (vio->dev_class) {
|
||||
case VDEV_NETWORK:
|
||||
case VDEV_NETWORK_SWITCH:
|
||||
case VDEV_DISK_SERVER:
|
||||
default:
|
||||
sid = vio->_peer_sid;
|
||||
break;
|
||||
|
||||
case VDEV_DISK:
|
||||
sid = vio->_local_sid;
|
||||
break;
|
||||
}
|
||||
|
||||
if (sid == tp->sid)
|
||||
return 0;
|
||||
viodbg(DATA, "BAD SID tag->sid[%08x] peer_sid[%08x] local_sid[%08x]\n",
|
||||
tp->sid, vio->_peer_sid, vio->_local_sid);
|
||||
return -EINVAL;
|
||||
}
|
||||
EXPORT_SYMBOL(vio_validate_sid);
|
||||
|
||||
u32 vio_send_sid(struct vio_driver_state *vio)
|
||||
{
|
||||
switch (vio->dev_class) {
|
||||
case VDEV_NETWORK:
|
||||
case VDEV_NETWORK_SWITCH:
|
||||
case VDEV_DISK:
|
||||
default:
|
||||
return vio->_local_sid;
|
||||
|
||||
case VDEV_DISK_SERVER:
|
||||
return vio->_peer_sid;
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL(vio_send_sid);
|
||||
|
||||
extern int vio_ldc_alloc(struct vio_driver_state *vio,
|
||||
struct ldc_channel_config *base_cfg,
|
||||
void *event_arg)
|
||||
{
|
||||
struct ldc_channel_config cfg = *base_cfg;
|
||||
struct ldc_channel *lp;
|
||||
const u64 *id;
|
||||
|
||||
id = md_get_property(vio->endpoint, "id", NULL);
|
||||
if (!id) {
|
||||
printk(KERN_ERR "%s: Channel lacks id property.\n",
|
||||
vio->name);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
vio->channel_id = *id;
|
||||
|
||||
cfg.rx_irq = vio->rx_irq;
|
||||
cfg.tx_irq = vio->tx_irq;
|
||||
|
||||
lp = ldc_alloc(vio->channel_id, &cfg, event_arg);
|
||||
if (IS_ERR(lp))
|
||||
return PTR_ERR(lp);
|
||||
|
||||
vio->lp = lp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(vio_ldc_alloc);
|
||||
|
||||
void vio_ldc_free(struct vio_driver_state *vio)
|
||||
{
|
||||
ldc_free(vio->lp);
|
||||
vio->lp = NULL;
|
||||
|
||||
kfree(vio->desc_buf);
|
||||
vio->desc_buf = NULL;
|
||||
vio->desc_buf_len = 0;
|
||||
}
|
||||
EXPORT_SYMBOL(vio_ldc_free);
|
||||
|
||||
void vio_port_up(struct vio_driver_state *vio)
|
||||
{
|
||||
unsigned long flags;
|
||||
int err, state;
|
||||
|
||||
spin_lock_irqsave(&vio->lock, flags);
|
||||
|
||||
state = ldc_state(vio->lp);
|
||||
|
||||
err = 0;
|
||||
if (state == LDC_STATE_INIT) {
|
||||
err = ldc_bind(vio->lp);
|
||||
if (err)
|
||||
printk(KERN_WARNING "%s: Port %lu bind failed, "
|
||||
"err=%d\n",
|
||||
vio->name, vio->channel_id, err);
|
||||
}
|
||||
|
||||
if (!err) {
|
||||
err = ldc_connect(vio->lp);
|
||||
if (err)
|
||||
printk(KERN_WARNING "%s: Port %lu connect failed, "
|
||||
"err=%d\n",
|
||||
vio->name, vio->channel_id, err);
|
||||
}
|
||||
if (err) {
|
||||
unsigned long expires = jiffies + HZ;
|
||||
|
||||
expires = round_jiffies(expires);
|
||||
mod_timer(&vio->timer, expires);
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&vio->lock, flags);
|
||||
}
|
||||
EXPORT_SYMBOL(vio_port_up);
|
||||
|
||||
static void vio_port_timer(unsigned long _arg)
|
||||
{
|
||||
struct vio_driver_state *vio = (struct vio_driver_state *) _arg;
|
||||
|
||||
vio_port_up(vio);
|
||||
}
|
||||
|
||||
int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
|
||||
u8 dev_class, struct mdesc_node *channel_endpoint,
|
||||
struct vio_version *ver_table, int ver_table_size,
|
||||
struct vio_driver_ops *ops, char *name)
|
||||
{
|
||||
switch (dev_class) {
|
||||
case VDEV_NETWORK:
|
||||
case VDEV_NETWORK_SWITCH:
|
||||
case VDEV_DISK:
|
||||
case VDEV_DISK_SERVER:
|
||||
break;
|
||||
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!ops->send_attr ||
|
||||
!ops->handle_attr ||
|
||||
!ops->handshake_complete)
|
||||
return -EINVAL;
|
||||
|
||||
if (!channel_endpoint)
|
||||
return -EINVAL;
|
||||
|
||||
if (!ver_table || ver_table_size < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (!name)
|
||||
return -EINVAL;
|
||||
|
||||
spin_lock_init(&vio->lock);
|
||||
|
||||
vio->name = name;
|
||||
|
||||
vio->dev_class = dev_class;
|
||||
vio->vdev = vdev;
|
||||
|
||||
vio->endpoint = channel_endpoint;
|
||||
vio->tx_irq = channel_endpoint->irqs[0];
|
||||
vio->rx_irq = channel_endpoint->irqs[1];
|
||||
|
||||
vio->ver_table = ver_table;
|
||||
vio->ver_table_entries = ver_table_size;
|
||||
|
||||
vio->ops = ops;
|
||||
|
||||
setup_timer(&vio->timer, vio_port_timer, (unsigned long) vio);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(vio_driver_init);
|
136
include/asm-sparc64/ldc.h
Normal file
136
include/asm-sparc64/ldc.h
Normal file
@ -0,0 +1,136 @@
|
||||
#ifndef _SPARC64_LDC_H
|
||||
#define _SPARC64_LDC_H
|
||||
|
||||
#include <asm/hypervisor.h>
|
||||
|
||||
extern int ldom_domaining_enabled;
|
||||
|
||||
/* The event handler will be evoked when link state changes
|
||||
* or data becomes available on the receive side.
|
||||
*
|
||||
* For non-RAW links, if the LDC_EVENT_RESET event arrives the
|
||||
* driver should reset all of it's internal state and reinvoke
|
||||
* ldc_connect() to try and bring the link up again.
|
||||
*
|
||||
* For RAW links, ldc_connect() is not used. Instead the driver
|
||||
* just waits for the LDC_EVENT_UP event.
|
||||
*/
|
||||
struct ldc_channel_config {
|
||||
void (*event)(void *arg, int event);
|
||||
|
||||
u32 mtu;
|
||||
unsigned int rx_irq;
|
||||
unsigned int tx_irq;
|
||||
u8 mode;
|
||||
#define LDC_MODE_RAW 0x00
|
||||
#define LDC_MODE_UNRELIABLE 0x01
|
||||
#define LDC_MODE_RESERVED 0x02
|
||||
#define LDC_MODE_RELIABLE 0x03
|
||||
#define LDC_MODE_STREAM 0x04
|
||||
|
||||
u8 debug;
|
||||
#define LDC_DEBUG_HS 0x01
|
||||
#define LDC_DEBUG_STATE 0x02
|
||||
#define LDC_DEBUG_RX 0x04
|
||||
#define LDC_DEBUG_TX 0x08
|
||||
#define LDC_DEBUG_DATA 0x10
|
||||
};
|
||||
|
||||
#define LDC_EVENT_RESET 0x01
|
||||
#define LDC_EVENT_UP 0x02
|
||||
#define LDC_EVENT_DATA_READY 0x04
|
||||
|
||||
#define LDC_STATE_INVALID 0x00
|
||||
#define LDC_STATE_INIT 0x01
|
||||
#define LDC_STATE_BOUND 0x02
|
||||
#define LDC_STATE_READY 0x03
|
||||
#define LDC_STATE_CONNECTED 0x04
|
||||
|
||||
struct ldc_channel;
|
||||
|
||||
/* Allocate state for a channel. */
|
||||
extern struct ldc_channel *ldc_alloc(unsigned long id,
|
||||
const struct ldc_channel_config *cfgp,
|
||||
void *event_arg);
|
||||
|
||||
/* Shut down and free state for a channel. */
|
||||
extern void ldc_free(struct ldc_channel *lp);
|
||||
|
||||
/* Register TX and RX queues of the link with the hypervisor. */
|
||||
extern int ldc_bind(struct ldc_channel *lp);
|
||||
|
||||
/* For non-RAW protocols we need to complete a handshake before
|
||||
* communication can proceed. ldc_connect() does that, if the
|
||||
* handshake completes successfully, an LDC_EVENT_UP event will
|
||||
* be sent up to the driver.
|
||||
*/
|
||||
extern int ldc_connect(struct ldc_channel *lp);
|
||||
extern int ldc_disconnect(struct ldc_channel *lp);
|
||||
|
||||
extern int ldc_state(struct ldc_channel *lp);
|
||||
|
||||
/* Read and write operations. Only valid when the link is up. */
|
||||
extern int ldc_write(struct ldc_channel *lp, const void *buf,
|
||||
unsigned int size);
|
||||
extern int ldc_read(struct ldc_channel *lp, void *buf, unsigned int size);
|
||||
|
||||
#define LDC_MAP_SHADOW 0x01
|
||||
#define LDC_MAP_DIRECT 0x02
|
||||
#define LDC_MAP_IO 0x04
|
||||
#define LDC_MAP_R 0x08
|
||||
#define LDC_MAP_W 0x10
|
||||
#define LDC_MAP_X 0x20
|
||||
#define LDC_MAP_RW (LDC_MAP_R | LDC_MAP_W)
|
||||
#define LDC_MAP_RWX (LDC_MAP_R | LDC_MAP_W | LDC_MAP_X)
|
||||
#define LDC_MAP_ALL 0x03f
|
||||
|
||||
struct ldc_trans_cookie {
|
||||
u64 cookie_addr;
|
||||
u64 cookie_size;
|
||||
};
|
||||
|
||||
struct scatterlist;
|
||||
extern int ldc_map_sg(struct ldc_channel *lp,
|
||||
struct scatterlist *sg, int num_sg,
|
||||
struct ldc_trans_cookie *cookies, int ncookies,
|
||||
unsigned int map_perm);
|
||||
|
||||
extern int ldc_map_single(struct ldc_channel *lp,
|
||||
void *buf, unsigned int len,
|
||||
struct ldc_trans_cookie *cookies, int ncookies,
|
||||
unsigned int map_perm);
|
||||
|
||||
extern void ldc_unmap(struct ldc_channel *lp, struct ldc_trans_cookie *cookies,
|
||||
int ncookies);
|
||||
|
||||
extern int ldc_copy(struct ldc_channel *lp, int copy_dir,
|
||||
void *buf, unsigned int len, unsigned long offset,
|
||||
struct ldc_trans_cookie *cookies, int ncookies);
|
||||
|
||||
static inline int ldc_get_dring_entry(struct ldc_channel *lp,
|
||||
void *buf, unsigned int len,
|
||||
unsigned long offset,
|
||||
struct ldc_trans_cookie *cookies,
|
||||
int ncookies)
|
||||
{
|
||||
return ldc_copy(lp, LDC_COPY_IN, buf, len, offset, cookies, ncookies);
|
||||
}
|
||||
|
||||
static inline int ldc_put_dring_entry(struct ldc_channel *lp,
|
||||
void *buf, unsigned int len,
|
||||
unsigned long offset,
|
||||
struct ldc_trans_cookie *cookies,
|
||||
int ncookies)
|
||||
{
|
||||
return ldc_copy(lp, LDC_COPY_OUT, buf, len, offset, cookies, ncookies);
|
||||
}
|
||||
|
||||
extern void *ldc_alloc_exp_dring(struct ldc_channel *lp, unsigned int len,
|
||||
struct ldc_trans_cookie *cookies,
|
||||
int *ncookies, unsigned int map_perm);
|
||||
|
||||
extern void ldc_free_exp_dring(struct ldc_channel *lp, void *buf,
|
||||
unsigned int len,
|
||||
struct ldc_trans_cookie *cookies, int ncookies);
|
||||
|
||||
#endif /* _SPARC64_LDC_H */
|
402
include/asm-sparc64/vio.h
Normal file
402
include/asm-sparc64/vio.h
Normal file
@ -0,0 +1,402 @@
|
||||
#ifndef _SPARC64_VIO_H
|
||||
#define _SPARC64_VIO_H
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/mod_devicetable.h>
|
||||
#include <linux/timer.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/list.h>
|
||||
|
||||
#include <asm/ldc.h>
|
||||
#include <asm/mdesc.h>
|
||||
|
||||
struct vio_msg_tag {
|
||||
u8 type;
|
||||
#define VIO_TYPE_CTRL 0x01
|
||||
#define VIO_TYPE_DATA 0x02
|
||||
#define VIO_TYPE_ERR 0x04
|
||||
|
||||
u8 stype;
|
||||
#define VIO_SUBTYPE_INFO 0x01
|
||||
#define VIO_SUBTYPE_ACK 0x02
|
||||
#define VIO_SUBTYPE_NACK 0x04
|
||||
|
||||
u16 stype_env;
|
||||
#define VIO_VER_INFO 0x0001
|
||||
#define VIO_ATTR_INFO 0x0002
|
||||
#define VIO_DRING_REG 0x0003
|
||||
#define VIO_DRING_UNREG 0x0004
|
||||
#define VIO_RDX 0x0005
|
||||
#define VIO_PKT_DATA 0x0040
|
||||
#define VIO_DESC_DATA 0x0041
|
||||
#define VIO_DRING_DATA 0x0042
|
||||
#define VNET_MCAST_INFO 0x0101
|
||||
|
||||
u32 sid;
|
||||
};
|
||||
|
||||
struct vio_rdx {
|
||||
struct vio_msg_tag tag;
|
||||
u64 resv[6];
|
||||
};
|
||||
|
||||
struct vio_ver_info {
|
||||
struct vio_msg_tag tag;
|
||||
u16 major;
|
||||
u16 minor;
|
||||
u8 dev_class;
|
||||
#define VDEV_NETWORK 0x01
|
||||
#define VDEV_NETWORK_SWITCH 0x02
|
||||
#define VDEV_DISK 0x03
|
||||
#define VDEV_DISK_SERVER 0x04
|
||||
|
||||
u8 resv1[3];
|
||||
u64 resv2[5];
|
||||
};
|
||||
|
||||
struct vio_dring_register {
|
||||
struct vio_msg_tag tag;
|
||||
u64 dring_ident;
|
||||
u32 num_descr;
|
||||
u32 descr_size;
|
||||
u16 options;
|
||||
#define VIO_TX_DRING 0x0001
|
||||
#define VIO_RX_DRING 0x0002
|
||||
u16 resv;
|
||||
u32 num_cookies;
|
||||
struct ldc_trans_cookie cookies[0];
|
||||
};
|
||||
|
||||
struct vio_dring_unregister {
|
||||
struct vio_msg_tag tag;
|
||||
u64 dring_ident;
|
||||
u64 resv[5];
|
||||
};
|
||||
|
||||
/* Data transfer modes */
|
||||
#define VIO_PKT_MODE 0x01 /* Packet based transfer */
|
||||
#define VIO_DESC_MODE 0x02 /* In-band descriptors */
|
||||
#define VIO_DRING_MODE 0x03 /* Descriptor rings */
|
||||
|
||||
struct vio_dring_data {
|
||||
struct vio_msg_tag tag;
|
||||
u64 seq;
|
||||
u64 dring_ident;
|
||||
u32 start_idx;
|
||||
u32 end_idx;
|
||||
u8 state;
|
||||
#define VIO_DRING_ACTIVE 0x01
|
||||
#define VIO_DRING_STOPPED 0x02
|
||||
|
||||
u8 __pad1;
|
||||
u16 __pad2;
|
||||
u32 __pad3;
|
||||
u64 __par4[2];
|
||||
};
|
||||
|
||||
struct vio_dring_hdr {
|
||||
u8 state;
|
||||
#define VIO_DESC_FREE 0x01
|
||||
#define VIO_DESC_READY 0x02
|
||||
#define VIO_DESC_ACCEPTED 0x03
|
||||
#define VIO_DESC_DONE 0x04
|
||||
u8 ack;
|
||||
#define VIO_ACK_ENABLE 0x01
|
||||
#define VIO_ACK_DISABLE 0x00
|
||||
|
||||
u16 __pad1;
|
||||
u32 __pad2;
|
||||
};
|
||||
|
||||
/* VIO disk specific structures and defines */
|
||||
struct vio_disk_attr_info {
|
||||
struct vio_msg_tag tag;
|
||||
u8 xfer_mode;
|
||||
u8 vdisk_type;
|
||||
#define VD_DISK_TYPE_SLICE 0x01 /* Slice in block device */
|
||||
#define VD_DISK_TYPE_DISK 0x02 /* Entire block device */
|
||||
u16 resv1;
|
||||
u32 vdisk_block_size;
|
||||
u64 operations;
|
||||
u64 vdisk_size;
|
||||
u64 max_xfer_size;
|
||||
u64 resv2[2];
|
||||
};
|
||||
|
||||
struct vio_disk_desc {
|
||||
struct vio_dring_hdr hdr;
|
||||
u64 req_id;
|
||||
u8 operation;
|
||||
#define VD_OP_BREAD 0x01 /* Block read */
|
||||
#define VD_OP_BWRITE 0x02 /* Block write */
|
||||
#define VD_OP_FLUSH 0x03 /* Flush disk contents */
|
||||
#define VD_OP_GET_WCE 0x04 /* Get write-cache status */
|
||||
#define VD_OP_SET_WCE 0x05 /* Enable/disable write-cache */
|
||||
#define VD_OP_GET_VTOC 0x06 /* Get VTOC */
|
||||
#define VD_OP_SET_VTOC 0x07 /* Set VTOC */
|
||||
#define VD_OP_GET_DISKGEOM 0x08 /* Get disk geometry */
|
||||
#define VD_OP_SET_DISKGEOM 0x09 /* Set disk geometry */
|
||||
#define VD_OP_SCSICMD 0x0a /* SCSI control command */
|
||||
#define VD_OP_GET_DEVID 0x0b /* Get device ID */
|
||||
#define VD_OP_GET_EFI 0x0c /* Get EFI */
|
||||
#define VD_OP_SET_EFI 0x0d /* Set EFI */
|
||||
u8 slice;
|
||||
u16 resv1;
|
||||
u32 status;
|
||||
u64 offset;
|
||||
u64 size;
|
||||
u32 ncookies;
|
||||
u32 resv2;
|
||||
struct ldc_trans_cookie cookies[0];
|
||||
};
|
||||
|
||||
#define VIO_DISK_VNAME_LEN 8
|
||||
#define VIO_DISK_ALABEL_LEN 128
|
||||
#define VIO_DISK_NUM_PART 8
|
||||
|
||||
struct vio_disk_vtoc {
|
||||
u8 volume_name[VIO_DISK_VNAME_LEN];
|
||||
u16 sector_size;
|
||||
u16 num_partitions;
|
||||
u8 ascii_label[VIO_DISK_ALABEL_LEN];
|
||||
struct {
|
||||
u16 id;
|
||||
u16 perm_flags;
|
||||
u32 resv;
|
||||
u64 start_block;
|
||||
u64 num_blocks;
|
||||
} partitions[VIO_DISK_NUM_PART];
|
||||
};
|
||||
|
||||
struct vio_disk_geom {
|
||||
u16 num_cyl; /* Num data cylinders */
|
||||
u16 alt_cyl; /* Num alternate cylinders */
|
||||
u16 beg_cyl; /* Cyl off of fixed head area */
|
||||
u16 num_hd; /* Num heads */
|
||||
u16 num_sec; /* Num sectors */
|
||||
u16 ifact; /* Interleave factor */
|
||||
u16 apc; /* Alts per cylinder (SCSI) */
|
||||
u16 rpm; /* Revolutions per minute */
|
||||
u16 phy_cyl; /* Num physical cylinders */
|
||||
u16 wr_skip; /* Num sects to skip, writes */
|
||||
u16 rd_skip; /* Num sects to skip, writes */
|
||||
};
|
||||
|
||||
struct vio_disk_devid {
|
||||
u16 resv;
|
||||
u16 type;
|
||||
u32 len;
|
||||
char id[0];
|
||||
};
|
||||
|
||||
struct vio_disk_efi {
|
||||
u64 lba;
|
||||
u64 len;
|
||||
char data[0];
|
||||
};
|
||||
|
||||
/* VIO net specific structures and defines */
|
||||
struct vio_net_attr_info {
|
||||
struct vio_msg_tag tag;
|
||||
u8 xfer_mode;
|
||||
u8 addr_type;
|
||||
#define VNET_ADDR_ETHERMAC 0x01
|
||||
u16 ack_freq;
|
||||
u32 resv1;
|
||||
u64 addr;
|
||||
u64 mtu;
|
||||
u64 resv2[3];
|
||||
};
|
||||
|
||||
#define VNET_NUM_MCAST 7
|
||||
|
||||
struct vio_net_mcast_info {
|
||||
struct vio_msg_tag tag;
|
||||
u8 set;
|
||||
u8 count;
|
||||
u8 mcast_addr[VNET_NUM_MCAST * 6];
|
||||
u32 resv;
|
||||
};
|
||||
|
||||
struct vio_net_desc {
|
||||
struct vio_dring_hdr hdr;
|
||||
u32 size;
|
||||
u32 ncookies;
|
||||
struct ldc_trans_cookie cookies[0];
|
||||
};
|
||||
|
||||
#define VIO_MAX_RING_COOKIES 24
|
||||
|
||||
struct vio_dring_state {
|
||||
u64 ident;
|
||||
void *base;
|
||||
u64 snd_nxt;
|
||||
u64 rcv_nxt;
|
||||
u32 entry_size;
|
||||
u32 num_entries;
|
||||
u32 prod;
|
||||
u32 cons;
|
||||
u32 pending;
|
||||
int ncookies;
|
||||
struct ldc_trans_cookie cookies[VIO_MAX_RING_COOKIES];
|
||||
};
|
||||
|
||||
static inline void *vio_dring_cur(struct vio_dring_state *dr)
|
||||
{
|
||||
return dr->base + (dr->entry_size * dr->prod);
|
||||
}
|
||||
|
||||
static inline void *vio_dring_entry(struct vio_dring_state *dr,
|
||||
unsigned int index)
|
||||
{
|
||||
return dr->base + (dr->entry_size * index);
|
||||
}
|
||||
|
||||
static inline u32 vio_dring_avail(struct vio_dring_state *dr,
|
||||
unsigned int ring_size)
|
||||
{
|
||||
/* Ensure build-time power-of-2. */
|
||||
BUILD_BUG_ON(ring_size & (ring_size - 1));
|
||||
|
||||
return (dr->pending -
|
||||
((dr->prod - dr->cons) & (ring_size - 1)));
|
||||
}
|
||||
|
||||
struct vio_dev {
|
||||
struct mdesc_node *mp;
|
||||
struct device_node *dp;
|
||||
|
||||
const char *type;
|
||||
const char *compat;
|
||||
int compat_len;
|
||||
|
||||
struct device dev;
|
||||
};
|
||||
|
||||
struct vio_driver {
|
||||
struct list_head node;
|
||||
const struct vio_device_id *id_table;
|
||||
int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
|
||||
int (*remove)(struct vio_dev *dev);
|
||||
void (*shutdown)(struct vio_dev *dev);
|
||||
unsigned long driver_data;
|
||||
struct device_driver driver;
|
||||
};
|
||||
|
||||
struct vio_version {
|
||||
u16 major;
|
||||
u16 minor;
|
||||
};
|
||||
|
||||
struct vio_driver_state;
|
||||
struct vio_driver_ops {
|
||||
int (*send_attr)(struct vio_driver_state *vio);
|
||||
int (*handle_attr)(struct vio_driver_state *vio, void *pkt);
|
||||
void (*handshake_complete)(struct vio_driver_state *vio);
|
||||
};
|
||||
|
||||
struct vio_completion {
|
||||
struct completion com;
|
||||
int err;
|
||||
int waiting_for;
|
||||
};
|
||||
|
||||
struct vio_driver_state {
|
||||
/* Protects VIO handshake and, optionally, driver private state. */
|
||||
spinlock_t lock;
|
||||
|
||||
struct ldc_channel *lp;
|
||||
|
||||
u32 _peer_sid;
|
||||
u32 _local_sid;
|
||||
struct vio_dring_state drings[2];
|
||||
#define VIO_DRIVER_TX_RING 0
|
||||
#define VIO_DRIVER_RX_RING 1
|
||||
|
||||
u8 hs_state;
|
||||
#define VIO_HS_INVALID 0x00
|
||||
#define VIO_HS_GOTVERS 0x01
|
||||
#define VIO_HS_GOT_ATTR 0x04
|
||||
#define VIO_HS_SENT_DREG 0x08
|
||||
#define VIO_HS_SENT_RDX 0x10
|
||||
#define VIO_HS_GOT_RDX_ACK 0x20
|
||||
#define VIO_HS_GOT_RDX 0x40
|
||||
#define VIO_HS_SENT_RDX_ACK 0x80
|
||||
#define VIO_HS_COMPLETE (VIO_HS_GOT_RDX_ACK | VIO_HS_SENT_RDX_ACK)
|
||||
|
||||
u8 dev_class;
|
||||
|
||||
u8 dr_state;
|
||||
#define VIO_DR_STATE_TXREG 0x01
|
||||
#define VIO_DR_STATE_RXREG 0x02
|
||||
#define VIO_DR_STATE_TXREQ 0x10
|
||||
#define VIO_DR_STATE_RXREQ 0x20
|
||||
|
||||
u8 debug;
|
||||
#define VIO_DEBUG_HS 0x01
|
||||
#define VIO_DEBUG_DATA 0x02
|
||||
|
||||
void *desc_buf;
|
||||
unsigned int desc_buf_len;
|
||||
|
||||
struct vio_completion *cmp;
|
||||
|
||||
struct vio_dev *vdev;
|
||||
|
||||
unsigned long channel_id;
|
||||
unsigned int tx_irq;
|
||||
unsigned int rx_irq;
|
||||
|
||||
struct timer_list timer;
|
||||
|
||||
struct vio_version ver;
|
||||
|
||||
struct mdesc_node *endpoint;
|
||||
|
||||
struct vio_version *ver_table;
|
||||
int ver_table_entries;
|
||||
|
||||
char *name;
|
||||
|
||||
struct vio_driver_ops *ops;
|
||||
};
|
||||
|
||||
#define viodbg(TYPE, f, a...) \
|
||||
do { if (vio->debug & VIO_DEBUG_##TYPE) \
|
||||
printk(KERN_INFO "vio: ID[%lu] " f, vio->channel_id, ## a); \
|
||||
} while (0)
|
||||
|
||||
extern int vio_register_driver(struct vio_driver *drv);
|
||||
extern void vio_unregister_driver(struct vio_driver *drv);
|
||||
|
||||
static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
|
||||
{
|
||||
return container_of(drv, struct vio_driver, driver);
|
||||
}
|
||||
|
||||
static inline struct vio_dev *to_vio_dev(struct device *dev)
|
||||
{
|
||||
return container_of(dev, struct vio_dev, dev);
|
||||
}
|
||||
|
||||
extern int vio_ldc_send(struct vio_driver_state *vio, void *data, int len);
|
||||
extern void vio_link_state_change(struct vio_driver_state *vio, int event);
|
||||
extern void vio_conn_reset(struct vio_driver_state *vio);
|
||||
extern int vio_control_pkt_engine(struct vio_driver_state *vio, void *pkt);
|
||||
extern int vio_validate_sid(struct vio_driver_state *vio,
|
||||
struct vio_msg_tag *tp);
|
||||
extern u32 vio_send_sid(struct vio_driver_state *vio);
|
||||
extern int vio_ldc_alloc(struct vio_driver_state *vio,
|
||||
struct ldc_channel_config *base_cfg, void *event_arg);
|
||||
extern void vio_ldc_free(struct vio_driver_state *vio);
|
||||
extern int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
|
||||
u8 dev_class, struct mdesc_node *channel_endpoint,
|
||||
struct vio_version *ver_table, int ver_table_size,
|
||||
struct vio_driver_ops *ops, char *name);
|
||||
|
||||
extern struct mdesc_node *vio_find_endpoint(struct vio_dev *vdev);
|
||||
extern void vio_port_up(struct vio_driver_state *vio);
|
||||
|
||||
#endif /* _SPARC64_VIO_H */
|
Loading…
Reference in New Issue
Block a user