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

[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 @@ ...@@ -15,6 +15,7 @@
#include <asm/ldc.h> #include <asm/ldc.h>
#include <asm/vio.h> #include <asm/vio.h>
#include <asm/power.h> #include <asm/power.h>
#include <asm/mdesc.h>
#define DRV_MODULE_NAME "ds" #define DRV_MODULE_NAME "ds"
#define PFX DRV_MODULE_NAME ": " #define PFX DRV_MODULE_NAME ": "
...@@ -170,8 +171,7 @@ static void md_update_data(struct ldc_channel *lp, ...@@ -170,8 +171,7 @@ static void md_update_data(struct ldc_channel *lp,
rp = (struct ds_md_update_req *) (dpkt + 1); rp = (struct ds_md_update_req *) (dpkt + 1);
printk(KERN_ERR PFX "MD update REQ [%lx] len=%d\n", printk(KERN_ERR PFX "Machine description update.\n");
rp->req_num, len);
memset(&pkt, 0, sizeof(pkt)); memset(&pkt, 0, sizeof(pkt));
pkt.data.tag.type = DS_DATA; pkt.data.tag.type = DS_DATA;
...@@ -181,6 +181,8 @@ static void md_update_data(struct ldc_channel *lp, ...@@ -181,6 +181,8 @@ static void md_update_data(struct ldc_channel *lp,
pkt.res.result = DS_OK; pkt.res.result = DS_OK;
ds_send(lp, &pkt, sizeof(pkt)); ds_send(lp, &pkt, sizeof(pkt));
mdesc_update();
} }
struct ds_shutdown_req { struct ds_shutdown_req {
...@@ -555,7 +557,6 @@ static int __devinit ds_probe(struct vio_dev *vdev, ...@@ -555,7 +557,6 @@ static int __devinit ds_probe(struct vio_dev *vdev,
const struct vio_device_id *id) const struct vio_device_id *id)
{ {
static int ds_version_printed; static int ds_version_printed;
struct mdesc_node *endp;
struct ldc_channel_config ds_cfg = { struct ldc_channel_config ds_cfg = {
.event = ds_event, .event = ds_event,
.mtu = 4096, .mtu = 4096,
...@@ -563,20 +564,11 @@ static int __devinit ds_probe(struct vio_dev *vdev, ...@@ -563,20 +564,11 @@ static int __devinit ds_probe(struct vio_dev *vdev,
}; };
struct ldc_channel *lp; struct ldc_channel *lp;
struct ds_info *dp; struct ds_info *dp;
const u64 *chan_id;
int err; int err;
if (ds_version_printed++ == 0) if (ds_version_printed++ == 0)
printk(KERN_INFO "%s", version); 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); dp = kzalloc(sizeof(*dp), GFP_KERNEL);
err = -ENOMEM; err = -ENOMEM;
if (!dp) if (!dp)
...@@ -588,10 +580,10 @@ static int __devinit ds_probe(struct vio_dev *vdev, ...@@ -588,10 +580,10 @@ static int __devinit ds_probe(struct vio_dev *vdev,
dp->rcv_buf_len = 4096; dp->rcv_buf_len = 4096;
ds_cfg.tx_irq = endp->irqs[0]; ds_cfg.tx_irq = vdev->tx_irq;
ds_cfg.rx_irq = endp->irqs[1]; 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)) { if (IS_ERR(lp)) {
err = PTR_ERR(lp); err = PTR_ERR(lp);
goto out_free_rcv_buf; goto out_free_rcv_buf;
......
...@@ -2335,15 +2335,20 @@ EXPORT_SYMBOL(ldc_free_exp_dring); ...@@ -2335,15 +2335,20 @@ EXPORT_SYMBOL(ldc_free_exp_dring);
static int __init ldc_init(void) static int __init ldc_init(void)
{ {
struct mdesc_node *mp;
unsigned long major, minor; unsigned long major, minor;
struct mdesc_handle *hp;
const u64 *v; const u64 *v;
u64 mp;
mp = md_find_node_by_name(NULL, "platform"); hp = mdesc_grab();
if (!mp) if (!hp)
return -ENODEV; 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) if (!v)
return -ENODEV; return -ENODEV;
......
This diff is collapsed.
...@@ -147,30 +147,6 @@ void vio_unregister_driver(struct vio_driver *viodrv) ...@@ -147,30 +147,6 @@ void vio_unregister_driver(struct vio_driver *viodrv)
} }
EXPORT_SYMBOL(vio_unregister_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) static void __devinit vio_dev_release(struct device *dev)
{ {
kfree(to_vio_dev(dev)); kfree(to_vio_dev(dev));
...@@ -197,22 +173,47 @@ struct device_node *cdev_node; ...@@ -197,22 +173,47 @@ struct device_node *cdev_node;
static struct vio_dev *root_vdev; static struct vio_dev *root_vdev;
static u64 cdev_cfg_handle; 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) struct device *parent)
{ {
const char *type, *compat; const char *type, *compat;
struct device_node *dp; struct device_node *dp;
struct vio_dev *vdev; struct vio_dev *vdev;
const u64 *irq;
int err, clen; int err, clen;
type = md_get_property(mp, "device-type", NULL); type = mdesc_get_property(hp, mp, "device-type", NULL);
if (!type) { if (!type) {
type = md_get_property(mp, "name", NULL); type = mdesc_get_property(hp, mp, "name", NULL);
if (!type) 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); vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
if (!vdev) { if (!vdev) {
...@@ -225,15 +226,13 @@ static struct vio_dev *vio_create_one(struct mdesc_node *mp, ...@@ -225,15 +226,13 @@ static struct vio_dev *vio_create_one(struct mdesc_node *mp,
vdev->compat = compat; vdev->compat = compat;
vdev->compat_len = clen; vdev->compat_len = clen;
irq = md_get_property(mp, "tx-ino", NULL); vdev->channel_id = ~0UL;
if (irq) vdev->tx_irq = ~0;
mp->irqs[0] = sun4v_build_virq(cdev_cfg_handle, *irq); vdev->rx_irq = ~0;
irq = md_get_property(mp, "rx-ino", NULL); vio_fill_channel_info(hp, mp, vdev);
if (irq)
mp->irqs[1] = sun4v_build_virq(cdev_cfg_handle, *irq);
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.parent = parent;
vdev->dev.bus = &vio_bus_type; vdev->dev.bus = &vio_bus_type;
vdev->dev.release = vio_dev_release; vdev->dev.release = vio_dev_release;
...@@ -267,46 +266,43 @@ static struct vio_dev *vio_create_one(struct mdesc_node *mp, ...@@ -267,46 +266,43 @@ static struct vio_dev *vio_create_one(struct mdesc_node *mp,
return vdev; 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++) { mdesc_for_each_arc(a, hp, n, MDESC_ARC_TYPE_FWD) {
struct mdesc_node *mp;
struct vio_dev *vdev; struct vio_dev *vdev;
u64 target;
if (strcmp(n->arcs[i].name, "fwd")) target = mdesc_arc_target(hp, a);
continue; vdev = vio_create_one(hp, target, &parent->dev);
if (vdev)
mp = n->arcs[i].arc; walk_tree(hp, target, vdev);
vdev = vio_create_one(mp, &parent->dev);
if (vdev && mp->num_arcs)
walk_tree(mp, 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) { if (!root_vdev) {
printk(KERN_ERR "VIO: Coult not create root device.\n"); printk(KERN_ERR "VIO: Coult not create root device.\n");
return; return;
} }
walk_tree(root, root_vdev); walk_tree(hp, root, root_vdev);
/* Domain services is odd as it doesn't sit underneath the /* Domain services is odd as it doesn't sit underneath the
* channel-devices node, so we plug it in manually. * channel-devices node, so we plug it in manually.
*/ */
mp = md_find_node_by_name(NULL, "domain-services"); mp = mdesc_node_by_name(hp, MDESC_NODE_NULL, "domain-services");
if (mp) { if (mp != MDESC_NODE_NULL) {
struct vio_dev *parent = vio_create_one(mp, &root_vdev->dev); struct vio_dev *parent = vio_create_one(hp, mp,
&root_vdev->dev);
if (parent) if (parent)
walk_tree(mp, parent); walk_tree(hp, mp, parent);
} }
} }
...@@ -316,40 +312,47 @@ const char *cfg_handle_prop = "cfg-handle"; ...@@ -316,40 +312,47 @@ const char *cfg_handle_prop = "cfg-handle";
static int __init vio_init(void) static int __init vio_init(void)
{ {
struct mdesc_node *root; struct mdesc_handle *hp;
const char *compat; const char *compat;
const u64 *cfg_handle; const u64 *cfg_handle;
int err, len; int err, len;
u64 root;
hp = mdesc_grab();
if (!hp)
return 0;
root = md_find_node_by_name(NULL, channel_devices_node); root = mdesc_node_by_name(hp, MDESC_NODE_NULL, channel_devices_node);
if (!root) { if (root == MDESC_NODE_NULL) {
printk(KERN_INFO "VIO: No channel-devices MDESC node.\n"); printk(KERN_INFO "VIO: No channel-devices MDESC node.\n");
mdesc_release(hp);
return 0; return 0;
} }
cdev_node = of_find_node_by_name(NULL, "channel-devices"); cdev_node = of_find_node_by_name(NULL, "channel-devices");
err = -ENODEV;
if (!cdev_node) { if (!cdev_node) {
printk(KERN_INFO "VIO: No channel-devices OBP node.\n"); 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) { if (!compat) {
printk(KERN_ERR "VIO: Channel devices lacks compatible " printk(KERN_ERR "VIO: Channel devices lacks compatible "
"property\n"); "property\n");
return -ENODEV; goto out_release;
} }
if (!find_in_proplist(compat, channel_devices_compat, len)) { if (!find_in_proplist(compat, channel_devices_compat, len)) {
printk(KERN_ERR "VIO: Channel devices node lacks (%s) " printk(KERN_ERR "VIO: Channel devices node lacks (%s) "
"compat entry.\n", channel_devices_compat); "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) { if (!cfg_handle) {
printk(KERN_ERR "VIO: Channel devices lacks %s property\n", printk(KERN_ERR "VIO: Channel devices lacks %s property\n",
cfg_handle_prop); cfg_handle_prop);
return -ENODEV; goto out_release;
} }
cdev_cfg_handle = *cfg_handle; cdev_cfg_handle = *cfg_handle;
...@@ -361,9 +364,15 @@ static int __init vio_init(void) ...@@ -361,9 +364,15 @@ static int __init vio_init(void)
return err; return err;
} }
create_devices(root); create_devices(hp, root);
mdesc_release(hp);
return 0; return 0;
out_release:
mdesc_release(hp);
return err;
} }
postcore_initcall(vio_init); postcore_initcall(vio_init);
...@@ -136,7 +136,7 @@ static int process_unknown(struct vio_driver_state *vio, void *arg) ...@@ -136,7 +136,7 @@ static int process_unknown(struct vio_driver_state *vio, void *arg)
pkt->type, pkt->stype, pkt->stype_env, pkt->sid); pkt->type, pkt->stype, pkt->stype_env, pkt->sid);
printk(KERN_ERR "vio: ID[%lu] Resetting connection.\n", printk(KERN_ERR "vio: ID[%lu] Resetting connection.\n",
vio->channel_id); vio->vdev->channel_id);
ldc_disconnect(vio->lp); ldc_disconnect(vio->lp);
...@@ -678,21 +678,11 @@ extern int vio_ldc_alloc(struct vio_driver_state *vio, ...@@ -678,21 +678,11 @@ extern int vio_ldc_alloc(struct vio_driver_state *vio,
{ {
struct ldc_channel_config cfg = *base_cfg; struct ldc_channel_config cfg = *base_cfg;
struct ldc_channel *lp; struct ldc_channel *lp;
const u64 *id;
id = md_get_property(vio->endpoint, "id", NULL); cfg.tx_irq = vio->vdev->tx_irq;
if (!id) { cfg.rx_irq = vio->vdev->rx_irq;
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); lp = ldc_alloc(vio->vdev->channel_id, &cfg, event_arg);
if (IS_ERR(lp)) if (IS_ERR(lp))
return PTR_ERR(lp); return PTR_ERR(lp);
...@@ -728,7 +718,7 @@ void vio_port_up(struct vio_driver_state *vio) ...@@ -728,7 +718,7 @@ void vio_port_up(struct vio_driver_state *vio)
if (err) if (err)
printk(KERN_WARNING "%s: Port %lu bind failed, " printk(KERN_WARNING "%s: Port %lu bind failed, "
"err=%d\n", "err=%d\n",
vio->name, vio->channel_id, err); vio->name, vio->vdev->channel_id, err);
} }
if (!err) { if (!err) {
...@@ -736,7 +726,7 @@ void vio_port_up(struct vio_driver_state *vio) ...@@ -736,7 +726,7 @@ void vio_port_up(struct vio_driver_state *vio)
if (err) if (err)
printk(KERN_WARNING "%s: Port %lu connect failed, " printk(KERN_WARNING "%s: Port %lu connect failed, "
"err=%d\n", "err=%d\n",
vio->name, vio->channel_id, err); vio->name, vio->vdev->channel_id, err);
} }
if (err) { if (err) {
unsigned long expires = jiffies + HZ; unsigned long expires = jiffies + HZ;
...@@ -757,9 +747,9 @@ static void vio_port_timer(unsigned long _arg) ...@@ -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, int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
u8 dev_class, struct mdesc_node *channel_endpoint, u8 dev_class, struct vio_version *ver_table,
struct vio_version *ver_table, int ver_table_size, int ver_table_size, struct vio_driver_ops *ops,
struct vio_driver_ops *ops, char *name) char *name)
{ {
switch (dev_class) { switch (dev_class) {
case VDEV_NETWORK: case VDEV_NETWORK:
...@@ -777,9 +767,6 @@ int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev, ...@@ -777,9 +767,6 @@ int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
!ops->handshake_complete) !ops->handshake_complete)
return -EINVAL; return -EINVAL;
if (!channel_endpoint)
return -EINVAL;
if (!ver_table || ver_table_size < 0) if (!ver_table || ver_table_size < 0)
return -EINVAL; return -EINVAL;
...@@ -793,10 +780,6 @@ int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev, ...@@ -793,10 +780,6 @@ int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
vio->dev_class = dev_class; vio->dev_class = dev_class;
vio->vdev = vdev; 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 = ver_table;
vio->ver_table_entries = ver_table_size; vio->ver_table_entries = ver_table_size;
......
...@@ -750,7 +750,7 @@ static struct vio_driver_ops vdc_vio_ops = { ...@@ -750,7 +750,7 @@ static struct vio_driver_ops vdc_vio_ops = {
static int __devinit vdc_port_probe(struct vio_dev *vdev, static int __devinit vdc_port_probe(struct vio_dev *vdev,
const struct vio_device_id *id) const struct vio_device_id *id)
{ {
struct mdesc_node *endp; struct mdesc_handle *hp;
struct vdc_port *port; struct vdc_port *port;
unsigned long flags; unsigned long flags;
struct vdc *vp; struct vdc *vp;
...@@ -763,26 +763,24 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev, ...@@ -763,26 +763,24 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev,
return -ENODEV; return -ENODEV;
} }
endp = vio_find_endpoint(vdev); hp = mdesc_grab();
if (!endp) {
printk(KERN_ERR PFX "Port lacks channel-endpoint.\n");
return -ENODEV;
}
port_id = md_get_property(vdev->mp, "id", NULL); port_id = mdesc_get_property(hp, vdev->mp, "id", NULL);
err = -ENODEV;
if (!port_id) { if (!port_id) {
printk(KERN_ERR PFX "Port lacks id property.\n"); printk(KERN_ERR PFX "Port lacks id property.\n");
return -ENODEV; goto err_out_release_mdesc;
} }
if ((*port_id << PARTITION_SHIFT) & ~(u64)MINORMASK) { if ((*port_id << PARTITION_SHIFT) & ~(u64)MINORMASK) {
printk(KERN_ERR PFX "Port id [%lu] too large.\n", *port_id); 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); port = kzalloc(sizeof(*port), GFP_KERNEL);
err = -ENOMEM;
if (!port) { if (!port) {
printk(KERN_ERR PFX "Cannot allocate vdc_port.\n"); printk(KERN_ERR PFX "Cannot allocate vdc_port.\n");
return -ENOMEM; goto err_out_release_mdesc;
} }
port->vp = vp; port->vp = vp;
...@@ -797,7 +795,7 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev, ...@@ -797,7 +795,7 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev,
snprintf(port->disk_name, sizeof(port->disk_name), snprintf(port->disk_name, sizeof(port->disk_name),
VDCBLK_NAME "%c", 'a' + (port->dev_no % 26)); 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_versions, ARRAY_SIZE(vdc_versions),
&vdc_vio_ops, port->disk_name); &vdc_vio_ops, port->disk_name);
if (err) if (err)
...@@ -828,6 +826,8 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev, ...@@ -828,6 +826,8 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev,
dev_set_drvdata(&vdev->dev, port); dev_set_drvdata(&vdev->dev, port);
mdesc_release(hp);
return 0; return 0;
err_out_free_tx_ring: err_out_free_tx_ring:
...@@ -839,6 +839,8 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev, ...@@ -839,6 +839,8 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev,
err_out_free_port: err_out_free_port:
kfree(port); kfree(port);
err_out_release_mdesc:
mdesc_release(hp);
return err; return err;
} }
......
...@@ -892,7 +892,7 @@ const char *remote_macaddr_prop = "remote-mac-address"; ...@@ -892,7 +892,7 @@ const char *remote_macaddr_prop = "remote-mac-address";
static int __devinit vnet_port_probe(struct vio_dev *vdev, static int __devinit vnet_port_probe(struct vio_dev *vdev,
const struct vio_device_id *id) const struct vio_device_id *id)
{ {
struct mdesc_node *endp; struct mdesc_handle *hp;
struct vnet_port *port; struct vnet_port *port;
unsigned long flags; unsigned long flags;
struct vnet *vp; struct vnet *vp;
...@@ -905,23 +905,21 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev, ...@@ -905,23 +905,21 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev,
return -ENODEV; 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) { if (!rmac) {
printk(KERN_ERR PFX "Port lacks %s property.\n", printk(KERN_ERR PFX "Port lacks %s property.\n",
remote_macaddr_prop); remote_macaddr_prop);
return -ENODEV; goto err_out_put_mdesc;
}
endp = vio_find_endpoint(vdev);
if (!endp) {
printk(KERN_ERR PFX "Port lacks channel-endpoint.\n");
return -ENODEV;
} }
port = kzalloc(sizeof(*port), GFP_KERNEL); port = kzalloc(sizeof(*port), GFP_KERNEL);
err = -ENOMEM;
if (!port) { if (!port) {
printk(KERN_ERR PFX "Cannot allocate vnet_port.\n"); printk(KERN_ERR PFX "Cannot allocate vnet_port.\n");
return -ENOMEM; goto err_out_put_mdesc;
} }
for (i = 0; i < ETH_ALEN; i++) for (i = 0; i < ETH_ALEN; i++)
...@@ -929,7 +927,7 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev, ...@@ -929,7 +927,7 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev,
port->vp = vp; 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_versions, ARRAY_SIZE(vnet_versions),
&vnet_vio_ops, vp->dev->name); &vnet_vio_ops, vp->dev->name);
if (err) if (err)
...@@ -947,7 +945,7 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev, ...@@ -947,7 +945,7 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev,
INIT_LIST_HEAD(&port->list); INIT_LIST_HEAD(&port->list);
switch_port = 0; 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; switch_port = 1;
spin_lock_irqsave(&vp->lock, flags); spin_lock_irqsave(&vp->lock, flags);
...@@ -969,6 +967,8 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev, ...@@ -969,6 +967,8 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev,
vio_port_up(&port->vio); vio_port_up(&port->vio);
mdesc_release(hp);
return 0; return 0;
err_out_free_ldc: err_out_free_ldc:
...@@ -977,6 +977,8 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev, ...@@ -977,6 +977,8 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev,
err_out_free_port: err_out_free_port:
kfree(port); kfree(port);
err_out_put_mdesc:
mdesc_release(hp);
return err; return err;
} }
...@@ -1029,6 +1031,7 @@ static int __devinit vnet_probe(struct vio_dev *vdev, ...@@ -1029,6 +1031,7 @@ static int __devinit vnet_probe(struct vio_dev *vdev,
const struct vio_device_id *id) const struct vio_device_id *id)
{ {
static int vnet_version_printed; static int vnet_version_printed;
struct mdesc_handle *hp;
struct net_device *dev; struct net_device *dev;
struct vnet *vp; struct vnet *vp;
const u64 *mac; const u64 *mac;
...@@ -1037,7 +1040,9 @@ static int __devinit vnet_probe(struct vio_dev *vdev, ...@@ -1037,7 +1040,9 @@ static int __devinit vnet_probe(struct vio_dev *vdev,
if (vnet_version_printed++ == 0) if (vnet_version_printed++ == 0)
printk(KERN_INFO "%s", version); 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) { if (!mac) {
printk(KERN_ERR PFX "vnet lacks %s property.\n", printk(KERN_ERR PFX "vnet lacks %s property.\n",
local_mac_prop); local_mac_prop);
...@@ -1093,12 +1098,15 @@ static int __devinit vnet_probe(struct vio_dev *vdev, ...@@ -1093,12 +1098,15 @@ static int __devinit vnet_probe(struct vio_dev *vdev,
dev_set_drvdata(&vdev->dev, vp); dev_set_drvdata(&vdev->dev, vp);
mdesc_release(hp);
return 0; return 0;
err_out_free_dev: err_out_free_dev:
free_netdev(dev); free_netdev(dev);
err_out: err_out:
mdesc_release(hp);
return err; return err;
} }
......
...@@ -4,36 +4,43 @@ ...@@ -4,36 +4,43 @@
#include <linux/types.h> #include <linux/types.h>
#include <asm/prom.h> #include <asm/prom.h>
struct mdesc_node; struct mdesc_handle;
struct mdesc_arc {
const char *name; /* Machine description operations are to be surrounded by grab and
struct mdesc_node *arc; * release calls. The mdesc_handle returned from the grab is
}; * the first argument to all of the operational calls that work
* on mdescs.
struct mdesc_node { */
const char *name; extern struct mdesc_handle *mdesc_grab(void);
u64 node; extern void mdesc_release(struct mdesc_handle *);
unsigned int unique_id;
unsigned int num_arcs; #define MDESC_NODE_NULL (~(u64)0)
unsigned int irqs[2];
struct property *properties; extern u64 mdesc_node_by_name(struct mdesc_handle *handle,
struct mdesc_node *hash_next; u64 from_node, const char *name);
struct mdesc_node *allnodes_next; #define mdesc_for_each_node_by_name(__hdl, __node, __name) \
struct mdesc_arc arcs[0]; for (__node = mdesc_node_by_name(__hdl, MDESC_NODE_NULL, __name); \
}; (__node) != MDESC_NODE_NULL; \
__node = mdesc_node_by_name(__hdl, __node, __name))
extern struct mdesc_node *md_find_node_by_name(struct mdesc_node *from,
const char *name); extern const void *mdesc_get_property(struct mdesc_handle *handle,
#define md_for_each_node_by_name(__mn, __name) \ u64 node, const char *name, int *lenp);
for (__mn = md_find_node_by_name(NULL, __name); __mn; \
__mn = md_find_node_by_name(__mn, __name)) #define MDESC_ARC_TYPE_FWD "fwd"
#define MDESC_ARC_TYPE_BACK "back"
extern struct property *md_find_property(const struct mdesc_node *mp,
const char *name, extern u64 mdesc_next_arc(struct mdesc_handle *handle, u64 from,
int *lenp); const char *arc_type);
extern const void *md_get_property(const struct mdesc_node *mp, #define mdesc_for_each_arc(__arc, __hdl, __node, __type) \
const char *name, for (__arc = mdesc_next_arc(__hdl, __node, __type); \
int *lenp); (__arc) != MDESC_NODE_NULL; \
__arc = mdesc_next_arc(__hdl, __arc, __type))
extern u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc);
extern const char *mdesc_node_name(struct mdesc_handle *hp, u64 node);
extern void mdesc_update(void);
extern void sun4v_mdesc_init(void); extern void sun4v_mdesc_init(void);
......
...@@ -265,13 +265,18 @@ static inline u32 vio_dring_avail(struct vio_dring_state *dr, ...@@ -265,13 +265,18 @@ static inline u32 vio_dring_avail(struct vio_dring_state *dr,
} }
struct vio_dev { struct vio_dev {
struct mdesc_node *mp; u64 mp;
struct device_node *dp; struct device_node *dp;
const char *type; const char *type;
const char *compat; const char *compat;
int compat_len; int compat_len;
unsigned long channel_id;
unsigned int tx_irq;
unsigned int rx_irq;
struct device dev; struct device dev;
}; };
...@@ -345,16 +350,10 @@ struct vio_driver_state { ...@@ -345,16 +350,10 @@ struct vio_driver_state {
struct vio_dev *vdev; struct vio_dev *vdev;
unsigned long channel_id;
unsigned int tx_irq;
unsigned int rx_irq;
struct timer_list timer; struct timer_list timer;
struct vio_version ver; struct vio_version ver;
struct mdesc_node *endpoint;
struct vio_version *ver_table; struct vio_version *ver_table;
int ver_table_entries; int ver_table_entries;
...@@ -365,7 +364,8 @@ struct vio_driver_state { ...@@ -365,7 +364,8 @@ struct vio_driver_state {
#define viodbg(TYPE, f, a...) \ #define viodbg(TYPE, f, a...) \
do { if (vio->debug & VIO_DEBUG_##TYPE) \ do { if (vio->debug & VIO_DEBUG_##TYPE) \
printk(KERN_INFO "vio: ID[%lu] " f, vio->channel_id, ## a); \ printk(KERN_INFO "vio: ID[%lu] " f, \
vio->vdev->channel_id, ## a); \
} while (0) } while (0)
extern int vio_register_driver(struct vio_driver *drv); extern int vio_register_driver(struct vio_driver *drv);
...@@ -392,11 +392,10 @@ extern int vio_ldc_alloc(struct vio_driver_state *vio, ...@@ -392,11 +392,10 @@ extern int vio_ldc_alloc(struct vio_driver_state *vio,
struct ldc_channel_config *base_cfg, void *event_arg); struct ldc_channel_config *base_cfg, void *event_arg);
extern void vio_ldc_free(struct vio_driver_state *vio); extern void vio_ldc_free(struct vio_driver_state *vio);
extern int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev, extern int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
u8 dev_class, struct mdesc_node *channel_endpoint, u8 dev_class, struct vio_version *ver_table,
struct vio_version *ver_table, int ver_table_size, int ver_table_size, struct vio_driver_ops *ops,
struct vio_driver_ops *ops, char *name); char *name);
extern struct mdesc_node *vio_find_endpoint(struct vio_dev *vdev);
extern void vio_port_up(struct vio_driver_state *vio); extern void vio_port_up(struct vio_driver_state *vio);
#endif /* _SPARC64_VIO_H */ #endif /* _SPARC64_VIO_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment