e1_{intf,line}_new: Allow caller to specify the numeric identifier
This will be used by the upcoming VTY interface changes. Change-Id: I9ff80831a3e3e3cb6dae178f8b438a9f3f4747df
This commit is contained in:
parent
9d6dab8992
commit
ef69fd1a63
|
@ -166,7 +166,7 @@ struct e1_line *
|
|||
e1_intf_find_line(struct e1_intf *intf, uint8_t id);
|
||||
|
||||
struct e1_intf *
|
||||
e1_intf_new(struct e1_daemon *e1d, void *drv_data);
|
||||
e1_intf_new(struct e1_daemon *e1d, int intf_id, void *drv_data);
|
||||
|
||||
struct e1_intf *
|
||||
e1d_find_intf(struct e1_daemon *e1d, uint8_t id);
|
||||
|
@ -179,7 +179,7 @@ struct e1_line *
|
|||
e1_intf_find_line(struct e1_intf *intf, uint8_t id);
|
||||
|
||||
struct e1_line *
|
||||
e1_line_new(struct e1_intf *intf, void *drv_data);
|
||||
e1_line_new(struct e1_intf *intf, int line_id, void *drv_data);
|
||||
|
||||
void
|
||||
e1_line_destroy(struct e1_line *line);
|
||||
|
|
|
@ -107,11 +107,21 @@ e1_intf_find_line(struct e1_intf *intf, uint8_t id)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* intf_id can be specified as '-1' to mean "auto-allocate intf->id" */
|
||||
struct e1_intf *
|
||||
e1_intf_new(struct e1_daemon *e1d, void *drv_data)
|
||||
e1_intf_new(struct e1_daemon *e1d, int intf_id, void *drv_data)
|
||||
{
|
||||
struct e1_intf *intf;
|
||||
|
||||
if (intf_id != -1) {
|
||||
/* ensure non-duplicate interface number */
|
||||
intf = e1d_find_intf(e1d, intf_id);
|
||||
if (intf) {
|
||||
LOGPIF(intf, DE1D, LOGL_ERROR, "Cannot create duplicate interface %d\n", intf_id);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
intf = talloc_zero(e1d->ctx, struct e1_intf);
|
||||
OSMO_ASSERT(intf);
|
||||
|
||||
|
@ -121,10 +131,14 @@ e1_intf_new(struct e1_daemon *e1d, void *drv_data)
|
|||
INIT_LLIST_HEAD(&intf->list);
|
||||
INIT_LLIST_HEAD(&intf->lines);
|
||||
|
||||
if (intf_id == -1) {
|
||||
if (!llist_empty(&e1d->interfaces)) {
|
||||
struct e1_intf *f = llist_last_entry(&e1d->interfaces, struct e1_intf, list);
|
||||
intf->id = f->id + 1;
|
||||
}
|
||||
} else
|
||||
intf->id = 0;
|
||||
} else
|
||||
intf->id = intf_id;
|
||||
|
||||
llist_add_tail(&intf->list, &e1d->interfaces);
|
||||
|
||||
|
@ -180,11 +194,20 @@ _ts_init(struct e1_ts *ts, struct e1_line *line, int id)
|
|||
ts->fd = -1;
|
||||
}
|
||||
|
||||
/* line_id can be specified as '-1' to mean "auto-allocate intf->id" */
|
||||
struct e1_line *
|
||||
e1_line_new(struct e1_intf *intf, void *drv_data)
|
||||
e1_line_new(struct e1_intf *intf, int line_id, void *drv_data)
|
||||
{
|
||||
struct e1_line *line;
|
||||
|
||||
if (line_id != -1) {
|
||||
line = e1_intf_find_line(intf, line_id);
|
||||
if (line) {
|
||||
LOGPLI(line, DE1D, LOGL_ERROR, "Cannot create duplicate line %d\n", line_id);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
line = talloc_zero(intf->e1d->ctx, struct e1_line);
|
||||
OSMO_ASSERT(line);
|
||||
|
||||
|
@ -198,10 +221,14 @@ e1_line_new(struct e1_intf *intf, void *drv_data)
|
|||
|
||||
INIT_LLIST_HEAD(&line->list);
|
||||
|
||||
if (line_id == -1) {
|
||||
if (!llist_empty(&intf->lines)) {
|
||||
struct e1_line *l = llist_last_entry(&intf->lines, struct e1_line, list);
|
||||
line->id = l->id + 1;
|
||||
}
|
||||
} else
|
||||
line->id = 0;
|
||||
} else
|
||||
line->id = line_id;
|
||||
|
||||
line->ctrs = rate_ctr_group_alloc(line, &line_ctrg_desc, line->id);
|
||||
OSMO_ASSERT(line->ctrs);
|
||||
|
|
|
@ -543,7 +543,7 @@ _e1_usb_open_device(struct e1_daemon *e1d, struct libusb_device *dev)
|
|||
intf_data = talloc_zero(e1d->ctx, struct e1_usb_intf_data);
|
||||
intf_data->devh = devh;
|
||||
|
||||
intf = e1_intf_new(e1d, intf_data);
|
||||
intf = e1_intf_new(e1d, -1, intf_data);
|
||||
intf->drv = E1_DRIVER_USB;
|
||||
|
||||
ret = libusb_get_active_config_descriptor(dev, &cd);
|
||||
|
@ -608,7 +608,7 @@ _e1_usb_open_device(struct e1_daemon *e1d, struct libusb_device *dev)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
line = e1_line_new(intf, line_data);
|
||||
line = e1_line_new(intf, -1, line_data);
|
||||
|
||||
line_data->flow_in = e1uf_create(line, e1_usb_xfer_in, line_data->ep_in, 4, line_data->pkt_size, 4);
|
||||
line_data->flow_out = e1uf_create(line, e1_usb_xfer_out, line_data->ep_out, 4, line_data->pkt_size, 4);
|
||||
|
|
|
@ -67,14 +67,14 @@ vintf_create(struct e1_daemon *e1d, unsigned int num_lines)
|
|||
|
||||
intf_data = talloc_zero(e1d->ctx, struct ve1_intf_data);
|
||||
|
||||
intf = e1_intf_new(e1d, intf_data);
|
||||
intf = e1_intf_new(e1d, -1, intf_data);
|
||||
intf->drv = E1_DRIVER_VPAIR;
|
||||
|
||||
for (i = 0; i < num_lines; i++) {
|
||||
struct ve1_line_data *line_data;
|
||||
|
||||
line_data = talloc_zero(e1d->ctx, struct ve1_line_data);
|
||||
e1_line_new(intf, line_data);
|
||||
e1_line_new(intf, -1, line_data);
|
||||
}
|
||||
|
||||
return intf;
|
||||
|
|
Loading…
Reference in New Issue