Commit 43fdf274 authored by David S. Miller's avatar David S. Miller
Browse files

[SPARC64]: Abstract out mdesc accesses for better MD update handling.



Since we have to be able to handle MD updates, having an in-tree
set of data structures representing the MD objects actually makes
things more painful.

The MD itself is easy to parse, and we can implement the existing
interfaces using direct parsing of the MD binary image.

The MD is now reference counted, so accesses have to now take the
form:

	handle = mdesc_grab();

	... operations on MD ...

	mdesc_release(handle);

The only remaining issue are cases where code holds on to references
to MD property values.  mdesc_get_property() returns a direct pointer
to the property value, most cases just pull in the information they
need and discard the pointer, but there are few that use the pointer
directly over a long lifetime.  Those will be fixed up in a subsequent
changeset.

A preliminary handler for MD update events from domain services is
there, it is rudimentry but it works and handles all of the reference
counting.  It does not check the generation number of the MDs,
and it does not generate a "add/delete" list for notification to
interesting parties about MD changes but that will be forthcoming.
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 133f09a1
......@@ -15,6 +15,7 @@
#include <asm/ldc.h>
#include <asm/vio.h>
#include <asm/power.h>
#include <asm/mdesc.h>
#define DRV_MODULE_NAME "ds"
#define PFX DRV_MODULE_NAME ": "
......@@ -170,8 +171,7 @@ static void md_update_data(struct ldc_channel *lp,
rp = (struct ds_md_update_req *) (dpkt + 1);
printk(KERN_ERR PFX "MD update REQ [%lx] len=%d\n",
rp->req_num, len);
printk(KERN_ERR PFX "Machine description update.\n");
memset(&pkt, 0, sizeof(pkt));
pkt.data.tag.type = DS_DATA;
......@@ -181,6 +181,8 @@ static void md_update_data(struct ldc_channel *lp,
pkt.res.result = DS_OK;
ds_send(lp, &pkt, sizeof(pkt));
mdesc_update();
}
struct ds_shutdown_req {
......@@ -555,7 +557,6 @@ static int __devinit ds_probe(struct vio_dev *vdev,
const struct vio_device_id *id)
{
static int ds_version_printed;
struct mdesc_node *endp;
struct ldc_channel_config ds_cfg = {
.event = ds_event,
.mtu = 4096,
......@@ -563,20 +564,11 @@ static int __devinit ds_probe(struct vio_dev *vdev,
};
struct ldc_channel *lp;
struct ds_info *dp;
const u64 *chan_id;
int err;
if (ds_version_printed++ == 0)
printk(KERN_INFO "%s", version);
endp = vio_find_endpoint(vdev);
if (!endp)
return -ENODEV;
chan_id = md_get_property(endp, "id", NULL);
if (!chan_id)
return -ENODEV;
dp = kzalloc(sizeof(*dp), GFP_KERNEL);
err = -ENOMEM;
if (!dp)
......@@ -588,10 +580,10 @@ static int __devinit ds_probe(struct vio_dev *vdev,
dp->rcv_buf_len = 4096;
ds_cfg.tx_irq = endp->irqs[0];
ds_cfg.rx_irq = endp->irqs[1];
ds_cfg.tx_irq = vdev->tx_irq;
ds_cfg.rx_irq = vdev->rx_irq;
lp = ldc_alloc(*chan_id, &ds_cfg, dp);
lp = ldc_alloc(vdev->channel_id, &ds_cfg, dp);
if (IS_ERR(lp)) {
err = PTR_ERR(lp);
goto out_free_rcv_buf;
......
......@@ -2335,15 +2335,20 @@ EXPORT_SYMBOL(ldc_free_exp_dring);
static int __init ldc_init(void)
{
struct mdesc_node *mp;
unsigned long major, minor;
struct mdesc_handle *hp;
const u64 *v;
u64 mp;
mp = md_find_node_by_name(NULL, "platform");
if (!mp)
hp = mdesc_grab();
if (!hp)
return -ENODEV;
v = md_get_property(mp, "domaining-enabled", NULL);
mp = mdesc_node_by_name(hp, MDESC_NODE_NULL, "platform");
if (mp == MDESC_NODE_NULL)
return -ENODEV;
v = mdesc_get_property(hp, mp, "domaining-enabled", NULL);
if (!v)
return -ENODEV;
......
This diff is collapsed.
......@@ -147,30 +147,6 @@ void vio_unregister_driver(struct vio_driver *viodrv)
}
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));
......@@ -197,22 +173,47 @@ 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,
static void vio_fill_channel_info(struct mdesc_handle *hp, u64 mp,
struct vio_dev *vdev)
{
u64 a;
mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
const u64 *chan_id;
const u64 *irq;
u64 target;
target = mdesc_arc_target(hp, a);
irq = mdesc_get_property(hp, target, "tx-ino", NULL);
if (irq)
vdev->tx_irq = sun4v_build_virq(cdev_cfg_handle, *irq);
irq = mdesc_get_property(hp, target, "rx-ino", NULL);
if (irq)
vdev->rx_irq = sun4v_build_virq(cdev_cfg_handle, *irq);
chan_id = mdesc_get_property(hp, target, "id", NULL);
if (chan_id)
vdev->channel_id = *chan_id;
}
}
static struct vio_dev *vio_create_one(struct mdesc_handle *hp, u64 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);
type = mdesc_get_property(hp, mp, "device-type", NULL);
if (!type) {
type = md_get_property(mp, "name", NULL);
type = mdesc_get_property(hp, mp, "name", NULL);
if (!type)
type = mp->name;
type = mdesc_node_name(hp, mp);
}
compat = md_get_property(mp, "device-type", &clen);
compat = mdesc_get_property(hp, mp, "device-type", &clen);
vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
if (!vdev) {
......@@ -225,15 +226,13 @@ static struct vio_dev *vio_create_one(struct mdesc_node *mp,
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);
vdev->channel_id = ~0UL;
vdev->tx_irq = ~0;
vdev->rx_irq = ~0;
irq = md_get_property(mp, "rx-ino", NULL);
if (irq)
mp->irqs[1] = sun4v_build_virq(cdev_cfg_handle, *irq);
vio_fill_channel_info(hp, mp, vdev);
snprintf(vdev->dev.bus_id, BUS_ID_SIZE, "%lx", mp->node);
snprintf(vdev->dev.bus_id, BUS_ID_SIZE, "%lx", mp);
vdev->dev.parent = parent;
vdev->dev.bus = &vio_bus_type;
vdev->dev.release = vio_dev_release;
......@@ -267,46 +266,43 @@ static struct vio_dev *vio_create_one(struct mdesc_node *mp,
return vdev;
}
static void walk_tree(struct mdesc_node *n, struct vio_dev *parent)
static void walk_tree(struct mdesc_handle *hp, u64 n, struct vio_dev *parent)
{
int i;
u64 a;
for (i = 0; i < n->num_arcs; i++) {
struct mdesc_node *mp;
mdesc_for_each_arc(a, hp, n, MDESC_ARC_TYPE_FWD) {
struct vio_dev *vdev;
u64 target;
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);
target = mdesc_arc_target(hp, a);
vdev = vio_create_one(hp, target, &parent->dev);
if (vdev)
walk_tree(hp, target, vdev);
}
}
static void create_devices(struct mdesc_node *root)
static void create_devices(struct mdesc_handle *hp, u64 root)
{
struct mdesc_node *mp;
u64 mp;
root_vdev = vio_create_one(root, NULL);
root_vdev = vio_create_one(hp, root, NULL);
if (!root_vdev) {
printk(KERN_ERR "VIO: Coult not create root device.\n");
return;
}
walk_tree(root, root_vdev);
walk_tree(hp, root, root_vdev);
/* Domain services is odd as it doesn't sit underneath the
* channel-devices node, so we plug it in manually.
*/
mp = md_find_node_by_name(NULL, "domain-services");
if (mp) {
struct vio_dev *parent = vio_create_one(mp, &root_vdev->dev);
mp = mdesc_node_by_name(hp, MDESC_NODE_NULL, "domain-services");
if (mp != MDESC_NODE_NULL) {
struct vio_dev *parent = vio_create_one(hp, mp,
&root_vdev->dev);
if (parent)
walk_tree(mp, parent);
walk_tree(hp, mp, parent);
}
}
......@@ -316,40 +312,47 @@ const char *cfg_handle_prop = "cfg-handle";
static int __init vio_init(void)
{
struct mdesc_node *root;
struct mdesc_handle *hp;
const char *compat;
const u64 *cfg_handle;
int err, len;
u64 root;
hp = mdesc_grab();
if (!hp)
return 0;
root = md_find_node_by_name(NULL, channel_devices_node);
if (!root) {
root = mdesc_node_by_name(hp, MDESC_NODE_NULL, channel_devices_node);
if (root == MDESC_NODE_NULL) {
printk(KERN_INFO "VIO: No channel-devices MDESC node.\n");
mdesc_release(hp);
return 0;
}
cdev_node = of_find_node_by_name(NULL, "channel-devices");
err = -ENODEV;
if (!cdev_node) {
printk(KERN_INFO "VIO: No channel-devices OBP node.\n");
return -ENODEV;
goto out_release;
}
compat = md_get_property(root, "compatible", &len);
compat = mdesc_get_property(hp, root, "compatible", &len);
if (!compat) {
printk(KERN_ERR "VIO: Channel devices lacks compatible "
"property\n");
return -ENODEV;
goto out_release;
}
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;
goto out_release;
}
cfg_handle = md_get_property(root, cfg_handle_prop, NULL);
cfg_handle = mdesc_get_property(hp, root, cfg_handle_prop, NULL);
if (!cfg_handle) {
printk(KERN_ERR "VIO: Channel devices lacks %s property\n",
cfg_handle_prop);
return -ENODEV;
goto out_release;
}
cdev_cfg_handle = *cfg_handle;
......@@ -361,9 +364,15 @@ static int __init vio_init(void)
return err;
}
create_devices(root);
create_devices(hp, root);
mdesc_release(hp);
return 0;
out_release:
mdesc_release(hp);
return err;
}
postcore_initcall(vio_init);
......@@ -136,7 +136,7 @@ static int process_unknown(struct vio_driver_state *vio, void *arg)
pkt->type, pkt->stype, pkt->stype_env, pkt->sid);
printk(KERN_ERR "vio: ID[%lu] Resetting connection.\n",
vio->channel_id);
vio->vdev->channel_id);
ldc_disconnect(vio->lp);
......@@ -678,21 +678,11 @@ extern int vio_ldc_alloc(struct vio_driver_state *vio,
{
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;
cfg.tx_irq = vio->vdev->tx_irq;
cfg.rx_irq = vio->vdev->rx_irq;
lp = ldc_alloc(vio->channel_id, &cfg, event_arg);
lp = ldc_alloc(vio->vdev->channel_id, &cfg, event_arg);
if (IS_ERR(lp))
return PTR_ERR(lp);
......@@ -728,7 +718,7 @@ void vio_port_up(struct vio_driver_state *vio)
if (err)
printk(KERN_WARNING "%s: Port %lu bind failed, "
"err=%d\n",
vio->name, vio->channel_id, err);
vio->name, vio->vdev->channel_id, err);
}
if (!err) {
......@@ -736,7 +726,7 @@ void vio_port_up(struct vio_driver_state *vio)
if (err)
printk(KERN_WARNING "%s: Port %lu connect failed, "
"err=%d\n",
vio->name, vio->channel_id, err);
vio->name, vio->vdev->channel_id, err);
}
if (err) {
unsigned long expires = jiffies + HZ;
......@@ -757,9 +747,9 @@ static void vio_port_timer(unsigned long _arg)
}
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)
u8 dev_class, struct vio_version *ver_table,
int ver_table_size, struct vio_driver_ops *ops,
char *name)
{
switch (dev_class) {
case VDEV_NETWORK:
......@@ -777,9 +767,6 @@ int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
!ops->handshake_complete)
return -EINVAL;
if (!channel_endpoint)
return -EINVAL;
if (!ver_table || ver_table_size < 0)
return -EINVAL;
......@@ -793,10 +780,6 @@ int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
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;
......
......@@ -750,7 +750,7 @@ static struct vio_driver_ops vdc_vio_ops = {
static int __devinit vdc_port_probe(struct vio_dev *vdev,
const struct vio_device_id *id)
{
struct mdesc_node *endp;
struct mdesc_handle *hp;
struct vdc_port *port;
unsigned long flags;
struct vdc *vp;
......@@ -763,26 +763,24 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev,
return -ENODEV;
}
endp = vio_find_endpoint(vdev);
if (!endp) {
printk(KERN_ERR PFX "Port lacks channel-endpoint.\n");
return -ENODEV;
}
hp = mdesc_grab();
port_id = md_get_property(vdev->mp, "id", NULL);
port_id = mdesc_get_property(hp, vdev->mp, "id", NULL);
err = -ENODEV;
if (!port_id) {
printk(KERN_ERR PFX "Port lacks id property.\n");
return -ENODEV;
goto err_out_release_mdesc;
}
if ((*port_id << PARTITION_SHIFT) & ~(u64)MINORMASK) {
printk(KERN_ERR PFX "Port id [%lu] too large.\n", *port_id);
return -ENODEV;
goto err_out_release_mdesc;
}
port = kzalloc(sizeof(*port), GFP_KERNEL);
err = -ENOMEM;
if (!port) {
printk(KERN_ERR PFX "Cannot allocate vdc_port.\n");
return -ENOMEM;
goto err_out_release_mdesc;
}
port->vp = vp;
......@@ -797,7 +795,7 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev,
snprintf(port->disk_name, sizeof(port->disk_name),
VDCBLK_NAME "%c", 'a' + (port->dev_no % 26));
err = vio_driver_init(&port->vio, vdev, VDEV_DISK, endp,
err = vio_driver_init(&port->vio, vdev, VDEV_DISK,
vdc_versions, ARRAY_SIZE(vdc_versions),
&vdc_vio_ops, port->disk_name);
if (err)
......@@ -828,6 +826,8 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev,
dev_set_drvdata(&vdev->dev, port);
mdesc_release(hp);
return 0;
err_out_free_tx_ring:
......@@ -839,6 +839,8 @@ err_out_free_ldc:
err_out_free_port:
kfree(port);
err_out_release_mdesc:
mdesc_release(hp);
return err;
}
......
......@@ -892,7 +892,7 @@ const char *remote_macaddr_prop = "remote-mac-address";
static int __devinit vnet_port_probe(struct vio_dev *vdev,
const struct vio_device_id *id)
{
struct mdesc_node *endp;
struct mdesc_handle *hp;
struct vnet_port *port;
unsigned long flags;
struct vnet *vp;
......@@ -905,23 +905,21 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev,
return -ENODEV;
}
rmac = md_get_property(vdev->mp, remote_macaddr_prop, &len);
hp = mdesc_grab();
rmac = mdesc_get_property(hp, vdev->mp, remote_macaddr_prop, &len);
err = -ENODEV;
if (!rmac) {
printk(KERN_ERR PFX "Port lacks %s property.\n",
remote_macaddr_prop);
return -ENODEV;
}
endp = vio_find_endpoint(vdev);
if (!endp) {
printk(KERN_ERR PFX "Port lacks channel-endpoint.\n");
return -ENODEV;
goto err_out_put_mdesc;
}
port = kzalloc(sizeof(*port), GFP_KERNEL);
err = -ENOMEM;
if (!port) {
printk(KERN_ERR PFX "Cannot allocate vnet_port.\n");
return -ENOMEM;
goto err_out_put_mdesc;
}
for (i = 0; i < ETH_ALEN; i++)
......@@ -929,7 +927,7 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev,
port->vp = vp;
err = vio_driver_init(&port->vio, vdev, VDEV_NETWORK, endp,
err = vio_driver_init(&port->vio, vdev, VDEV_NETWORK,
vnet_versions, ARRAY_SIZE(vnet_versions),
&vnet_vio_ops, vp->dev->name);
if (err)
......@@ -947,7 +945,7 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev,
INIT_LIST_HEAD(&port->list);
switch_port = 0;
if (md_get_property(vdev->mp, "switch-port", NULL) != NULL)
if (mdesc_get_property(hp, vdev->mp, "switch-port", NULL) != NULL)
switch_port = 1;
spin_lock_irqsave(&vp->lock, flags);
......@@ -969,6 +967,8 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev,
vio_port_up(&port->vio);
mdesc_release(hp);
return 0;
err_out_free_ldc:
......@@ -977,6 +977,8 @@ err_out_free_ldc:
err_out_free_port:
kfree(port);
err_out_put_mdesc:
mdesc_release(hp);
return err;
}
......@@ -1029,6 +1031,7 @@ static int __devinit vnet_probe(struct vio_dev *vdev,
const struct vio_device_id *id)
{
static int vnet_version_printed;
struct mdesc_handle *hp;
struct net_device *dev;
struct vnet *vp;
const u64 *mac;
......@@ -1037,7 +1040,9 @@ static int __devinit vnet_probe(struct vio_dev *vdev,
if (vnet_version_printed++ == 0)
printk(KERN_INFO "%s", version);
mac = md_get_property(vdev->mp, local_mac_prop, &len);
hp = mdesc_grab();
mac = mdesc_get_property(hp, vdev->mp, local_mac_prop, &len);
if (!mac) {
printk(KERN_ERR PFX "vnet lacks %s property.\n",
local_mac_prop);
......@@ -1093,12 +1098,15 @@ static int __devinit vnet_probe(struct vio_dev *vdev,
dev_set_drvdata(&vdev->dev, vp);
mdesc_release(hp);
return 0;
err_out_free_dev:
free_netdev(dev);
err_out:
mdesc_release(hp);
return err;
}
......
......@@ -4,36 +4,43 @@
#include <linux/types.h>
#include <asm/prom.h>
struct mdesc_node;
struct mdesc_arc {
const char *name;
struct mdesc_node *arc;
};
struct mdesc_node {
const char *name;
u64 node;
unsigned int unique_id;
unsigned int num_arcs;
unsigned int irqs[2];
struct property *properties;
struct mdesc_node *hash_next;
struct mdesc_node *allnodes_next;
struct mdesc_arc arcs[