Commit af1c35a5 authored by Paolo Savini's avatar Paolo Savini Committed by Federico Vaga

Enumerate channels and channel-sets in sysfs

Create a sysfs symlink for backward compatibility using cset/chan name
Signed-off-by: Paolo Savini's avatarPaolo Savini <il.paolo.savini@gmail.com>
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 45506166
...@@ -637,6 +637,29 @@ static uint16_t __get_nbits(struct zio_channel *chan) ...@@ -637,6 +637,29 @@ static uint16_t __get_nbits(struct zio_channel *chan)
/* The attr. is optional, so devices with no attributes are allowed */ /* The attr. is optional, so devices with no attributes are allowed */
return chan->cset->ssize * BITS_PER_BYTE; return chan->cset->ssize * BITS_PER_BYTE;
} }
static void zobj_create_link(struct zio_obj_head *head)
{
int err;
/* Create the symlink with custom channel name */
if (strlen(head->name) == 0)
return;
err = sysfs_create_link(&head->dev.parent->kobj, &head->dev.kobj,
head->name);
if (err)
pr_warn("ZIO: not able to create the symlinks\n");
}
static void zobj_remove_link(struct zio_obj_head *head)
{
if (strlen(head->name) == 0)
return;
sysfs_remove_link(&head->dev.parent->kobj, head->name);
}
/* /*
* chan_register * chan_register
* *
...@@ -654,6 +677,8 @@ static int chan_register(struct zio_channel *chan, struct zio_channel *chan_t) ...@@ -654,6 +677,8 @@ static int chan_register(struct zio_channel *chan, struct zio_channel *chan_t)
{ {
struct zio_control *ctrl; struct zio_control *ctrl;
struct zio_bi *bi; struct zio_bi *bi;
char *fmtname;
char chan_name[ZIO_NAME_LEN];
int err, i; int err, i;
if (!chan) if (!chan)
...@@ -702,15 +727,12 @@ static int chan_register(struct zio_channel *chan, struct zio_channel *chan_t) ...@@ -702,15 +727,12 @@ static int chan_register(struct zio_channel *chan, struct zio_channel *chan_t)
chan->current_ctrl = ctrl; chan->current_ctrl = ctrl;
/* Initialize and register channel device */ /* Initialize and register channel device */
if (strlen(chan->head.name) == 0) { fmtname = (chan->flags & ZIO_CSET_CHAN_INTERLEAVE) ? "chani" : "chan%i";
char *mask; snprintf(chan_name, ZIO_NAME_LEN, fmtname, chan->index);
mask = chan->flags & ZIO_CSET_CHAN_INTERLEAVE ? "chani" : dev_set_name(&chan->head.dev, chan_name);
"chan%i";
snprintf(chan->head.name, ZIO_NAME_LEN, mask, chan->index);
}
dev_set_name(&chan->head.dev, chan->head.name);
chan->head.dev.type = &chan_device_type; chan->head.dev.type = &chan_device_type;
chan->head.dev.parent = &chan->cset->head.dev; chan->head.dev.parent = &chan->cset->head.dev;
err = device_register(&chan->head.dev); err = device_register(&chan->head.dev);
if (err) if (err)
goto out_ctrl_bits; goto out_ctrl_bits;
...@@ -723,6 +745,9 @@ static int chan_register(struct zio_channel *chan, struct zio_channel *chan_t) ...@@ -723,6 +745,9 @@ static int chan_register(struct zio_channel *chan, struct zio_channel *chan_t)
goto out_bin_attr; goto out_bin_attr;
} }
} }
zobj_create_link(&chan->head);
/* Create buffer */ /* Create buffer */
bi = __bi_create(chan->cset->zbuf, chan, "buffer"); bi = __bi_create(chan->cset->zbuf, chan, "buffer");
if (IS_ERR(bi)) { if (IS_ERR(bi)) {
...@@ -769,6 +794,7 @@ static void chan_unregister(struct zio_channel *chan) ...@@ -769,6 +794,7 @@ static void chan_unregister(struct zio_channel *chan)
for (i = 0; i < __ZIO_BIN_ATTR_NUM; ++i) for (i = 0; i < __ZIO_BIN_ATTR_NUM; ++i)
sysfs_remove_bin_file(&chan->head.dev.kobj, sysfs_remove_bin_file(&chan->head.dev.kobj,
&zio_bin_attr[i]); &zio_bin_attr[i]);
zobj_remove_link(&chan->head);
device_unregister(&chan->head.dev); device_unregister(&chan->head.dev);
} }
...@@ -856,6 +882,7 @@ static int cset_register(struct zio_cset *cset, struct zio_cset *cset_t) ...@@ -856,6 +882,7 @@ static int cset_register(struct zio_cset *cset, struct zio_cset *cset_t)
{ {
int i, j, err = 0, size; int i, j, err = 0, size;
unsigned long flags; unsigned long flags;
char cset_name[ZIO_NAME_LEN];
struct zio_channel *chan_tmp; struct zio_channel *chan_tmp;
struct zio_ti *ti = NULL; struct zio_ti *ti = NULL;
...@@ -885,15 +912,17 @@ static int cset_register(struct zio_cset *cset, struct zio_cset *cset_t) ...@@ -885,15 +912,17 @@ static int cset_register(struct zio_cset *cset, struct zio_cset *cset_t)
goto out_zattr_check; goto out_zattr_check;
/* Initialize and register zio device */ /* Initialize and register zio device */
if (strlen(cset->head.name) == 0) snprintf(cset_name, ZIO_NAME_LEN, "cset%i", cset->index);
snprintf(cset->head.name, ZIO_NAME_LEN, "cset%i", cset->index); dev_set_name(&cset->head.dev, cset_name);
dev_set_name(&cset->head.dev, cset->head.name);
spin_lock_init(&cset->lock); spin_lock_init(&cset->lock);
cset->head.dev.type = &cset_device_type; cset->head.dev.type = &cset_device_type;
cset->head.dev.parent = &cset->zdev->head.dev; cset->head.dev.parent = &cset->zdev->head.dev;
err = device_register(&cset->head.dev); err = device_register(&cset->head.dev);
if (err) if (err)
goto out_zattr_check; goto out_zattr_check;
zobj_create_link(&cset->head);
/* /*
* The cset must have a buffer type. If none is associated * The cset must have a buffer type. If none is associated
* to the cset, ZIO selects the preferred or default one. * to the cset, ZIO selects the preferred or default one.
...@@ -998,6 +1027,7 @@ static void cset_unregister(struct zio_cset *cset) ...@@ -998,6 +1027,7 @@ static void cset_unregister(struct zio_cset *cset)
/* destroy instance and decrement trigger usage */ /* destroy instance and decrement trigger usage */
__ti_destroy(cset->trig, cset->ti); __ti_destroy(cset->trig, cset->ti);
zobj_remove_link(&cset->head);
device_unregister(&cset->head.dev); device_unregister(&cset->head.dev);
} }
......
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