From 7a7d4000a0a95e66035c359040c2a0b4f79e4704 Mon Sep 17 00:00:00 2001 From: Kinsey Moore Date: Thu, 9 Dec 2010 20:19:26 +0000 Subject: [PATCH] dahdi-base, dahdi_echocan_*, wcb4xxp, wct4xxp, wctdm24xxp, wcte12xp, kernel: Allow name of EC factory to vary based on channel Changed the echocan factory name to a function (get_name) called to get the name. This allows a factory to return a different name when being called in reference to a channel such as in the case of hardware echo cancellers. To further accommodate this change for HWEC, a new echocan_name function was added to the span ops struct and is used in hwec_factory in dahdi-base for all cards that support hardware echo cancellation. Signed-off-by: Kinsey Moore Acked-by: Shaun Ruffell git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@9524 a0bf4364-ded3-4de4-8d8a-66a801d63aff --- drivers/dahdi/dahdi-base.c | 26 +++++++++++----- drivers/dahdi/dahdi_echocan_jpah.c | 7 +++-- drivers/dahdi/dahdi_echocan_kb1.c | 7 +++-- drivers/dahdi/dahdi_echocan_mg2.c | 7 +++-- drivers/dahdi/dahdi_echocan_oslec.c | 7 +++-- drivers/dahdi/dahdi_echocan_sec.c | 7 +++-- drivers/dahdi/dahdi_echocan_sec2.c | 7 +++-- drivers/dahdi/wcb4xxp/base.c | 14 +++++++++ drivers/dahdi/wct4xxp/base.c | 46 ++++++++++++++++------------- drivers/dahdi/wctdm24xxp/base.c | 42 +++++++++++++------------- drivers/dahdi/wcte12xp/base.c | 16 ++++++++-- include/dahdi/kernel.h | 7 +++-- 12 files changed, 130 insertions(+), 63 deletions(-) diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c index 1f20176..698e37d 100644 --- a/drivers/dahdi/dahdi-base.c +++ b/drivers/dahdi/dahdi-base.c @@ -799,7 +799,7 @@ static int dahdi_proc_read(char *page, char **start, off_t off, int count, int * if (chan->ec_factory) len += snprintf(page+len, count-len, "(EC: %s - %s) ", - chan->ec_factory->name, + chan->ec_factory->get_name(chan), chan->ec_state ? "ACTIVE" : "INACTIVE"); len += snprintf(page+len, count-len, "\n"); @@ -1197,7 +1197,7 @@ retry: read_lock(&ecfactory_list_lock); list_for_each_entry(cur, &ecfactory_list, list) { - if (!strcmp(name_upper, cur->ec->name)) { + if (!strcmp(name_upper, cur->ec->get_name(NULL))) { if (try_module_get(cur->ec->owner)) { read_unlock(&ecfactory_list_lock); kfree(name_upper); @@ -4603,8 +4603,9 @@ static int dahdi_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long da dahdi_copy_string(vi.version, DAHDI_VERSION, sizeof(vi.version)); read_lock(&ecfactory_list_lock); list_for_each_entry(cur, &ecfactory_list, list) { - strncat(vi.echo_canceller + strlen(vi.echo_canceller), cur->ec->name, space); - space -= strlen(cur->ec->name); + strncat(vi.echo_canceller + strlen(vi.echo_canceller), + cur->ec->get_name(NULL), space); + space -= strlen(cur->ec->get_name(NULL)); if (space < 1) { break; } @@ -5478,7 +5479,9 @@ ioctl_echocancel(struct dahdi_chan *chan, struct dahdi_echocanparams *ecp, /* try to get another reference to the module providing this channel's echo canceler */ if (!try_module_get(chan->ec_factory->owner)) { - module_printk(KERN_ERR, "Cannot get a reference to the '%s' echo canceler\n", chan->ec_factory->name); + module_printk(KERN_ERR, "Cannot get a reference to the" + " '%s' echo canceler\n", + chan->ec_factory->get_name(chan)); goto exit_with_free; } @@ -5495,7 +5498,7 @@ ioctl_echocancel(struct dahdi_chan *chan, struct dahdi_echocanparams *ecp, if (!ec) { module_printk(KERN_ERR, "%s failed to allocate an " \ "dahdi_echocan_state instance.\n", - ec_current->name); + ec_current->get_name(chan)); ret = -EFAULT; goto exit_with_free; } @@ -8899,6 +8902,15 @@ int dahdi_unregister_chardev(struct dahdi_chardev *dev) return 0; } +static const char *hwec_def_name = "HWEC"; +static const char *hwec_get_name(const struct dahdi_chan *chan) +{ + if (chan && chan->span && chan->span->ops->echocan_name) + return chan->span->ops->echocan_name(chan); + else + return hwec_def_name; +} + static int hwec_echocan_create(struct dahdi_chan *chan, struct dahdi_echocanparams *ecp, struct dahdi_echocanparam *p, struct dahdi_echocan_state **ec) @@ -8910,7 +8922,7 @@ static int hwec_echocan_create(struct dahdi_chan *chan, } static const struct dahdi_echocan_factory hwec_factory = { - .name = "HWEC", + .get_name = hwec_get_name, .owner = THIS_MODULE, .echocan_create = hwec_echocan_create, }; diff --git a/drivers/dahdi/dahdi_echocan_jpah.c b/drivers/dahdi/dahdi_echocan_jpah.c index 9c684aa..167460c 100644 --- a/drivers/dahdi/dahdi_echocan_jpah.c +++ b/drivers/dahdi/dahdi_echocan_jpah.c @@ -46,9 +46,11 @@ static int echo_can_create(struct dahdi_chan *chan, struct dahdi_echocanparams * static void echo_can_free(struct dahdi_chan *chan, struct dahdi_echocan_state *ec); static void echo_can_process(struct dahdi_echocan_state *ec, short *isig, const short *iref, u32 size); static int echo_can_traintap(struct dahdi_echocan_state *ec, int pos, short val); +static const char *name = "JPAH"; +static const char *ec_name(const struct dahdi_chan *chan) { return name; } static const struct dahdi_echocan_factory my_factory = { - .name = "JPAH", + .get_name = ec_name, .owner = THIS_MODULE, .echocan_create = echo_can_create, }; @@ -124,7 +126,8 @@ static int __init mod_init(void) return -EPERM; } - module_printk(KERN_NOTICE, "Registered echo canceler '%s'\n", my_factory.name); + module_printk(KERN_NOTICE, "Registered echo canceler '%s'\n", + my_factory.get_name(NULL)); return 0; } diff --git a/drivers/dahdi/dahdi_echocan_kb1.c b/drivers/dahdi/dahdi_echocan_kb1.c index 3bf14c1..cf58260 100644 --- a/drivers/dahdi/dahdi_echocan_kb1.c +++ b/drivers/dahdi/dahdi_echocan_kb1.c @@ -148,9 +148,11 @@ static void echo_can_free(struct dahdi_chan *chan, struct dahdi_echocan_state *e static void echo_can_process(struct dahdi_echocan_state *ec, short *isig, const short *iref, u32 size); static int echo_can_traintap(struct dahdi_echocan_state *ec, int pos, short val); static void echocan_NLP_toggle(struct dahdi_echocan_state *ec, unsigned int enable); +static const char *name = "KB1"; +static const char *ec_name(const struct dahdi_chan *chan) { return name; } static const struct dahdi_echocan_factory my_factory = { - .name = "KB1", + .get_name = ec_name, .owner = THIS_MODULE, .echocan_create = echo_can_create, }; @@ -722,7 +724,8 @@ static int __init mod_init(void) return -EPERM; } - module_printk(KERN_NOTICE, "Registered echo canceler '%s'\n", my_factory.name); + module_printk(KERN_NOTICE, "Registered echo canceler '%s'\n", + my_factory.get_name(NULL)); return 0; } diff --git a/drivers/dahdi/dahdi_echocan_mg2.c b/drivers/dahdi/dahdi_echocan_mg2.c index fc0e650..4713ed8 100644 --- a/drivers/dahdi/dahdi_echocan_mg2.c +++ b/drivers/dahdi/dahdi_echocan_mg2.c @@ -180,9 +180,11 @@ static void echo_can_free(struct dahdi_chan *chan, struct dahdi_echocan_state *e static void echo_can_process(struct dahdi_echocan_state *ec, short *isig, const short *iref, u32 size); static int echo_can_traintap(struct dahdi_echocan_state *ec, int pos, short val); static void echocan_NLP_toggle(struct dahdi_echocan_state *ec, unsigned int enable); +static const char *name = "MG2"; +static const char *ec_name(const struct dahdi_chan *chan) { return name; } static const struct dahdi_echocan_factory my_factory = { - .name = "MG2", + .get_name = ec_name, .owner = THIS_MODULE, .echocan_create = echo_can_create, }; @@ -869,7 +871,8 @@ static int __init mod_init(void) return -EPERM; } - module_printk(KERN_NOTICE, "Registered echo canceler '%s'\n", my_factory.name); + module_printk(KERN_NOTICE, "Registered echo canceler '%s'\n", + my_factory.get_name(NULL)); return 0; } diff --git a/drivers/dahdi/dahdi_echocan_oslec.c b/drivers/dahdi/dahdi_echocan_oslec.c index 496769a..805597a 100644 --- a/drivers/dahdi/dahdi_echocan_oslec.c +++ b/drivers/dahdi/dahdi_echocan_oslec.c @@ -47,9 +47,11 @@ static int echo_can_traintap(struct dahdi_echocan_state *ec, int pos, short val) static void echo_can_hpf_tx(struct dahdi_echocan_state *ec, short *tx, u32 size); #endif +static const char *name = "OSLEC"; +static const char *ec_name(const struct dahdi_chan *chan) { return name; } static const struct dahdi_echocan_factory my_factory = { - .name = "OSLEC", + .get_name = ec_name, .owner = THIS_MODULE, .echocan_create = echo_can_create, }; @@ -147,7 +149,8 @@ static int __init mod_init(void) return -EPERM; } - module_printk(KERN_INFO, "Registered echo canceler '%s'\n", my_factory.name); + module_printk(KERN_INFO, "Registered echo canceler '%s'\n", + my_factory.get_name(NULL)); return 0; } diff --git a/drivers/dahdi/dahdi_echocan_sec.c b/drivers/dahdi/dahdi_echocan_sec.c index bd7cb90..5f6f9ae 100644 --- a/drivers/dahdi/dahdi_echocan_sec.c +++ b/drivers/dahdi/dahdi_echocan_sec.c @@ -86,9 +86,11 @@ static void echo_can_free(struct dahdi_chan *chan, struct dahdi_echocan_state *e static void echo_can_process(struct dahdi_echocan_state *ec, short *isig, const short *iref, u32 size); static int echo_can_traintap(struct dahdi_echocan_state *ec, int pos, short val); static void echocan_NLP_toggle(struct dahdi_echocan_state *ec, unsigned int enable); +static const char *name = "SEC"; +static const char *ec_name(const struct dahdi_chan *chan) { return name; } static const struct dahdi_echocan_factory my_factory = { - .name = "SEC", + .get_name = ec_name, .owner = THIS_MODULE, .echocan_create = echo_can_create, }; @@ -335,7 +337,8 @@ static int __init mod_init(void) return -EPERM; } - module_printk(KERN_NOTICE, "Registered echo canceler '%s'\n", my_factory.name); + module_printk(KERN_NOTICE, "Registered echo canceler '%s'\n", + my_factory.get_name(NULL)); return 0; } diff --git a/drivers/dahdi/dahdi_echocan_sec2.c b/drivers/dahdi/dahdi_echocan_sec2.c index 81b05fe..a7cc551 100644 --- a/drivers/dahdi/dahdi_echocan_sec2.c +++ b/drivers/dahdi/dahdi_echocan_sec2.c @@ -81,9 +81,11 @@ static int echo_can_create(struct dahdi_chan *chan, struct dahdi_echocanparams * static void echo_can_free(struct dahdi_chan *chan, struct dahdi_echocan_state *ec); static void echo_can_process(struct dahdi_echocan_state *ec, short *isig, const short *iref, u32 size); static int echo_can_traintap(struct dahdi_echocan_state *ec, int pos, short val); +static const char *name = "SEC2"; +static const char *ec_name(const struct dahdi_chan *chan) { return name; } static const struct dahdi_echocan_factory my_factory = { - .name = "SEC2", + .get_name = ec_name, .owner = THIS_MODULE, .echocan_create = echo_can_create, }; @@ -330,7 +332,8 @@ static int __init mod_init(void) return -EPERM; } - module_printk(KERN_NOTICE, "Registered echo canceler '%s'\n", my_factory.name); + module_printk(KERN_NOTICE, "Registered echo canceler '%s'\n", + my_factory.get_name(NULL)); return 0; } diff --git a/drivers/dahdi/wcb4xxp/base.c b/drivers/dahdi/wcb4xxp/base.c index 2b09ed3..6b147c4 100644 --- a/drivers/dahdi/wcb4xxp/base.c +++ b/drivers/dahdi/wcb4xxp/base.c @@ -103,6 +103,10 @@ static char *companding = "alaw"; #define MAX_B4_CARDS 64 static struct b4xxp *cards[MAX_B4_CARDS]; +/* names of HWEC modules */ +static const char *lasvegas2_name = "LASVEGAS2"; +static const char *noec_name = "NONE"; + static int led_fader_table[] = { 0, 0, 0, 1, 2, 3, 4, 6, 8, 9, 11, 13, 16, 18, 20, 22, 24, 25, 27, 28, 29, 30, 31, 31, 32, 31, 31, 30, 29, 28, 27, 25, 23, 22, @@ -2129,6 +2133,15 @@ static void b4xxp_update_leds(struct b4xxp *b4) } } +static const char *b4xxp_echocan_name(const struct dahdi_chan *chan) +{ + struct b4xxp_span *bspan = container_of(chan->span, struct b4xxp_span, + span); + if (bspan->parent->card_type == B410P) + return lasvegas2_name; + return noec_name; +} + static int b4xxp_echocan_create(struct dahdi_chan *chan, struct dahdi_echocanparams *ecp, struct dahdi_echocanparam *p, @@ -2370,6 +2383,7 @@ static const struct dahdi_span_ops b4xxp_span_ops = { .ioctl = b4xxp_ioctl, .hdlc_hard_xmit = b4xxp_hdlc_hard_xmit, .echocan_create = b4xxp_echocan_create, + .echocan_name = b4xxp_echocan_name, }; /* initialize the span/chan structures. Doesn't touch hardware, although the callbacks might. */ diff --git a/drivers/dahdi/wct4xxp/base.c b/drivers/dahdi/wct4xxp/base.c index 71d98f8..4df3c34 100644 --- a/drivers/dahdi/wct4xxp/base.c +++ b/drivers/dahdi/wct4xxp/base.c @@ -236,6 +236,11 @@ static int altab[] = { #define CANARY 0xc0de +/* names of available HWEC modules */ +static const char *vpm400_name = "VPM400M"; +static const char *vpmoct064_name = "VPMOCT064"; +static const char *vpmoct128_name = "VPMOCT128"; +static const char *noec_name = "NONE"; #define PORTS_PER_FRAMER 4 @@ -393,23 +398,13 @@ static void t4_vpm_set_dtmf_threshold(struct t4 *wc, unsigned int threshold); static void echocan_free(struct dahdi_chan *chan, struct dahdi_echocan_state *ec); -static const struct dahdi_echocan_features vpm400m_ec_features = { +static const struct dahdi_echocan_features vpm_ec_features = { .NLP_automatic = 1, .CED_tx_detect = 1, .CED_rx_detect = 1, }; -static const struct dahdi_echocan_features vpm450m_ec_features = { - .NLP_automatic = 1, - .CED_tx_detect = 1, - .CED_rx_detect = 1, -}; - -static const struct dahdi_echocan_ops vpm400m_ec_ops = { - .echocan_free = echocan_free, -}; - -static const struct dahdi_echocan_ops vpm450m_ec_ops = { +static const struct dahdi_echocan_ops vpm_ec_ops = { .echocan_free = echocan_free, }; #endif @@ -1279,6 +1274,21 @@ static int t4_vpm_unit(int span, int channel) return unit; } +static const char *t4_echocan_name(const struct dahdi_chan *chan) +{ + struct t4 *wc = chan->pvt; + if (wc->vpm == T4_VPM_PRESENT) { + if (!wc->vpm450m) + return vpm400_name; + else + if (wc->numspans == 2) + return vpmoct064_name; + else if (wc->numspans == 4) + return vpmoct128_name; + } + return noec_name; +} + static int t4_echocan_create(struct dahdi_chan *chan, struct dahdi_echocanparams *ecp, struct dahdi_echocanparam *p, @@ -1296,18 +1306,13 @@ static int t4_echocan_create(struct dahdi_chan *chan, if (chan->span->offset >= vpmspans) return -ENODEV; - if (wc->vpm450m) { - ops = &vpm450m_ec_ops; - features = &vpm450m_ec_features; - } else { - ops = &vpm400m_ec_ops; - features = &vpm400m_ec_features; - } + ops = &vpm_ec_ops; + features = &vpm_ec_features; if (ecp->param_count > 0) { dev_warn(&wc->dev->dev, "%s echo canceller does not support " "parameters; failing request\n", - chan->ec_factory->name); + chan->ec_factory->get_name(chan)); return -EINVAL; } @@ -2082,6 +2087,7 @@ static const struct dahdi_span_ops t4_gen2_span_ops = { .dacs = t4_dacs, #ifdef VPM_SUPPORT .echocan_create = t4_echocan_create, + .echocan_name = t4_echocan_name, #endif }; diff --git a/drivers/dahdi/wctdm24xxp/base.c b/drivers/dahdi/wctdm24xxp/base.c index 10f7ea8..d96d176 100644 --- a/drivers/dahdi/wctdm24xxp/base.c +++ b/drivers/dahdi/wctdm24xxp/base.c @@ -174,6 +174,11 @@ static int ectrans[4] = { 0, 1, 3, 2 }; #define EC_SIZE_Q (sizeof(ectab) / 4) #endif +/* names of HWEC modules */ +static const char *vpm100m_name = "VPM100M"; +static const char *vpmadt032_name = "VPMADT032"; +static const char *noec_name = "NONE"; + /* Undefine to enable Power alarm / Transistor debug -- note: do not enable for normal operation! */ /* #define PAQ_DEBUG */ @@ -255,23 +260,13 @@ static int vpmnlpmaxsupp = DEFAULT_NLPMAXSUPP; static void echocan_free(struct dahdi_chan *chan, struct dahdi_echocan_state *ec); -static const struct dahdi_echocan_features vpm100m_ec_features = { +static const struct dahdi_echocan_features vpm_ec_features = { .NLP_automatic = 1, .CED_tx_detect = 1, .CED_rx_detect = 1, }; -static const struct dahdi_echocan_features vpm150m_ec_features = { - .NLP_automatic = 1, - .CED_tx_detect = 1, - .CED_rx_detect = 1, -}; - -static const struct dahdi_echocan_ops vpm100m_ec_ops = { - .echocan_free = echocan_free, -}; - -static const struct dahdi_echocan_ops vpm150m_ec_ops = { +static const struct dahdi_echocan_ops vpm_ec_ops = { .echocan_free = echocan_free, }; @@ -1963,6 +1958,16 @@ static inline void wctdm_vpm_check(struct wctdm *wc, int x) } } +static const char *wctdm_echocan_name(const struct dahdi_chan *chan) +{ + struct wctdm *wc = chan->pvt; + if (wc->vpm100) + return vpm100m_name; + else if (wc->vpmadt032) + return vpmadt032_name; + return noec_name; +} + static int wctdm_echocan_create(struct dahdi_chan *chan, struct dahdi_echocanparams *ecp, struct dahdi_echocanparam *p, @@ -1980,18 +1985,13 @@ static int wctdm_echocan_create(struct dahdi_chan *chan, if (!wc->vpm100 && !wc->vpmadt032) return -ENODEV; - if (wc->vpmadt032) { - ops = &vpm150m_ec_ops; - features = &vpm150m_ec_features; - } else { - ops = &vpm100m_ec_ops; - features = &vpm100m_ec_features; - } + ops = &vpm_ec_ops; + features = &vpm_ec_features; if (wc->vpm100 && (ecp->param_count > 0)) { dev_warn(&wc->vb.pdev->dev, "%s echo canceller does not " "support parameters; failing request\n", - chan->ec_factory->name); + chan->ec_factory->get_name(chan)); return -EINVAL; } @@ -3682,6 +3682,7 @@ static const struct dahdi_span_ops wctdm24xxp_analog_span_ops = { .dacs = wctdm_dacs, #ifdef VPM_SUPPORT .echocan_create = wctdm_echocan_create, + .echocan_name = wctdm_echocan_name, #endif }; @@ -3697,6 +3698,7 @@ static const struct dahdi_span_ops wctdm24xxp_digital_span_ops = { .dacs = wctdm_dacs, #ifdef VPM_SUPPORT .echocan_create = wctdm_echocan_create, + .echocan_name = wctdm_echocan_name, #endif }; diff --git a/drivers/dahdi/wcte12xp/base.c b/drivers/dahdi/wcte12xp/base.c index 8631f98..99267be 100644 --- a/drivers/dahdi/wcte12xp/base.c +++ b/drivers/dahdi/wcte12xp/base.c @@ -95,6 +95,10 @@ static const struct t1_desc te120p = {"Wildcard TE120P"}; static const struct t1_desc te122 = {"Wildcard TE122"}; static const struct t1_desc te121 = {"Wildcard TE121"}; +/* names of HWEC modules */ +static const char *vpmadt032_name = "VPMADT032"; +static const char *noec_name = "NONE"; + #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) static kmem_cache_t *cmd_cache; #else @@ -945,10 +949,9 @@ static void set_span_devicetype(struct t1 *wc) sizeof(wc->span.devicetype) - 1); #if defined(VPM_SUPPORT) - if (wc->vpmadt032) { + if (wc->vpmadt032) strncat(wc->span.devicetype, " (VPMADT032)", sizeof(wc->span.devicetype) - 1); - } #endif } @@ -1308,6 +1311,14 @@ static int t1xxp_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long return 0; } +static const char *t1xxp_echocan_name(const struct dahdi_chan *chan) +{ + struct t1 *wc = chan->pvt; + if (wc->vpmadt032) + return vpmadt032_name; + return noec_name; +} + static int t1xxp_echocan_create(struct dahdi_chan *chan, struct dahdi_echocanparams *ecp, struct dahdi_echocanparam *p, @@ -1537,6 +1548,7 @@ static const struct dahdi_span_ops t1_span_ops = { .ioctl = t1xxp_ioctl, #ifdef VPM_SUPPORT .echocan_create = t1xxp_echocan_create, + .echocan_name = t1xxp_echocan_name, #endif }; diff --git a/include/dahdi/kernel.h b/include/dahdi/kernel.h index d7f69f2..e7dff97 100644 --- a/include/dahdi/kernel.h +++ b/include/dahdi/kernel.h @@ -268,8 +268,8 @@ struct dahdi_echocan_ops { /*! A factory for creating instances of software echo cancelers to be used on DAHDI channels. */ struct dahdi_echocan_factory { - /*! The name of the factory. */ - const char *name; + /*! Get the name of the factory. */ + const char *(*get_name)(const struct dahdi_chan *chan); /*! Pointer to the module that owns this factory; the module's reference count will be * incremented/decremented by the DAHDI core as needed. @@ -851,6 +851,9 @@ struct dahdi_span_ops { struct dahdi_echocanparams *ecp, struct dahdi_echocanparam *p, struct dahdi_echocan_state **ec); + + /*! Opt: Provide the name of the echo canceller on a channel */ + const char *(*echocan_name)(const struct dahdi_chan *chan); }; struct dahdi_span {