pgid69 / bcm63xx-phone

Telephony driver for Broadcom 6358 running OpenWrt
23 stars 18 forks source link

bcm63xx-phone crashes LEDE 18 #29

Closed r0neko closed 6 years ago

r0neko commented 6 years ago

Hi there. After successfully compilation of this driver, I started the router, flashed the firmware and everything was ok. Then, I ssh-d into it, ran insmod bcm63xx-phone and once I ran that command, the router froze(so it crashed) and it rebooted.

Router is Huawei EchoLife HG556a Version C. LEDE is latest Version OS compilation environment is Linux Mint 19(Tara) or as known as Ubuntu 18.

Can you help me debug and fix this? My Serial is not working atm.

BR, Talnaci Alexandru

r0neko commented 6 years ago

I managed to get the kernel log and will add it ASAP.

r0neko commented 6 years ago

https://pastebin.com/wv8qge2j

pgid69 commented 6 years ago

Thank you for the log. Can you try to add the three following line in file mpi/mpi.c after line 581

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
   .prevent_deferred_probe = true,
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0) */

Recompile bcm63xx-phone.ko and test to see if it works. But i'm doubtful.

Else you can also try to use the kernel spi driver :

If you compile the OpenWrt firmware without appling the patch 001-add-fn-to-spi-bcm63xx-for-quick-transfer.patch, you have to apply it, clean the kernel to force it's recompilation (make target/linux/clean) and recompile the firmware. Else you can simply recompile bcm63xx-phone.ko

Then insmod spi-bcm63xx.ko and insmod bcm63xx-phone.ko

BR

pgid69 commented 6 years ago

Just a question : as insmod bcm63xx-phone.ko makes the router crash freezes, how did you manage to get a log ?

r0neko commented 6 years ago

I managed to compile the kernel with Crash Logging enabled, and I found it in /sys/kernel/debug/crashlog

r0neko commented 6 years ago

btw... with .prevent_deferred_probe = true; it gave compilation error, I had to set it to .prevent_deferred_probe = true Compiled successfully, will test it tomorrow, as right now it's night.

r0neko commented 6 years ago

Tested, same errors. Will try to use SPI.

r0neko commented 6 years ago

SPI works. Closing. Thank you!

p-velasco commented 4 years ago

Same problem here with OpenWrt 19.07.03 and Huawei HG556a-B Linux 4.14.180

As the OP closed the issue with a workarround by using the kernel SPI driver, I would like to dig deeper into this.

Looks like after platform_driver_register arround line 950, the probe function of the bundled SPI driver is not called, as was happening before at issue #13 I'm unable to see why.

The log is the same as reported:

bcm63xx_phone bcm_mpi_init() 951: 0 bcm63xx_phone: bcm63xx_phone bcm_mpi_init() 954: condition '((ret) && (0 == bcm_mpi_dev_data.ref_count)) || ((!ret) && (1 == bcm_mpi_dev_data.ref_count))' is false bcm63xx_phone: bcm63xx_phone bcm_mpi_init() 961: condition 'bcm_mpi_dev_data.ref_count > 0' is false CPU 0 Unable to handle kernel paging request at virtual address 00000054, epc == 8023682c, ra == 802369ec Oops[#1]

p-velasco commented 4 years ago

Ok, so the kernel changed to yet another way of managing devices.

Solved with this quick, dirty and ugly patch:

Edit: Kernel version testing may be WRONG, if someone wants to track the correct version where the change happened... It works on 4.14.180 though

diff --git a/bcm63xx-phone/src/mpi/mpi.c b/bcm63xx-phone/src/mpi/mpi.c
index fda9a47..e665de2 100644
--- a/bcm63xx-phone/src/mpi/mpi.c
+++ b/bcm63xx-phone/src/mpi/mpi.c
@@ -400,6 +400,13 @@ static const struct platform_device_id bcm63xx_spi_dev_match[] = {
 };
 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) */

+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
+static const struct of_device_id bcm63xx_spi_of_match[] = {
+       { .compatible = "brcm,bcm6358-spi", .data = &bcm6358_spi_reg_offsets },
+       { },
+};
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) */
+
 static int bcm63xx_spi_probe(struct platform_device *pdev)
 {
    struct device *dev = &(pdev->dev);
@@ -411,6 +418,9 @@ static int bcm63xx_spi_probe(struct platform_device *pdev)
    bcm_pr_debug("%s()\n", __func__);

    if (
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
+       (!dev->of_node) &&
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0) */
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
        (!pdev->id_entry->driver_data)
 #else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0) */
@@ -421,6 +431,15 @@ static int bcm63xx_spi_probe(struct platform_device *pdev)
    }

    bs = &(bcm_mpi_dev_data);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
+   if (dev->of_node) {
+      const struct of_device_id *match;
+      match = of_match_node(bcm63xx_spi_of_match, dev->of_node);
+      if (!match)
+         return -EINVAL;
+      bcm_mpi_dev_data_init(bs, match->data);
+   } else
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) */
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
    bcm_mpi_dev_data_init(bs, (const unsigned long *)pdev->id_entry->driver_data);
 #else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0) */
@@ -573,12 +592,18 @@ static struct platform_driver bcm63xx_spi_driver = {
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
       .probe_type = PROBE_FORCE_SYNCHRONOUS,
 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
+      .of_match_table = bcm63xx_spi_of_match,
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) */
    },
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
    .id_table   = bcm63xx_spi_dev_match,
 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) */
    .probe      = bcm63xx_spi_probe,
    .remove     = bcm63xx_spi_remove,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
+   .prevent_deferred_probe = true,
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0) */
 };
 #endif // BCMPH_USE_SPI_DRIVER
 #endif // !BCMPH_NOHW
sturia commented 4 years ago

Thanks a lot for the patch, working on Pirelli A226M, Openwrt 19.07.3, kernel 4.14.180

p-velasco commented 4 years ago

Thanks a lot for the patch, working on Pirelli A226M, Openwrt 19.07.3, kernel 4.14.180

Maybe you also need my ast-chan patch. If you manage to set up the DAHDI driver, please let me know (Asterisk segfaults with it for me, and I don't have time just now to attach GDB)

sturia commented 4 years ago

well I actually talked too fast. Driver loads properly, but when I goto to test it with asterisk I realized I have issues with asterisk on 19.07.3 - it basically doesn't load any modules (here and there I understand it might be related to compiling against musl instead of legacy uclibc, but this is way too advanced field for my analysis). Which asterisk version are you using? I tweaked asterisk 13 source feed (Makefile etc.) from Chaos Chalmer as on 19.07.3 the only asterisk version available is 16, for which there is no bcm63xx-phone official channel. Is this the patch you're referring to?

thanks

p-velasco commented 4 years ago

Asterisk 16, and yes, I was talking about that patch for ast-chan to make it work with it. Check my fork on the branch for 19.07.3 or the PR #35

sturia commented 4 years ago

Excellent, it compiled and it eventually works on asterisk16. The only issue left is when asterisk loads the bcm63xx_chan module: i have to force it as "preload" in modules.conf, otherwise it messes up with something and crashes asterisk. With preload it works fine, but there is a side effect of bcm63xx_chan NOT loading properly country tone rules from bcm63xx_phone.conf - it defaults to US tones. ever experienced anything similar?

p-velasco commented 4 years ago

Didn't test tones, but I don't remember any problems loading the module. I just tested it with chan-dongle and was properly routing calls, but didn't have the time to complete my setup. Will try in the next days if I get some spare time

sturia commented 4 years ago

I performed few other tests - now everything works fine. country tones are recognized and bcm63xx_chan module doesn't require to be preloaded in asterisk to work. Unfortunately I didn't perform tests systematically, what I did is to go back to a very standard compile conditions and removing all non strictly necessary modules from asterisk, which in my case are:

asterisk16 - 16.3.0-7 asterisk16-app-confbridge - 16.3.0-7 asterisk16-app-exec - 16.3.0-7 asterisk16-app-system - 16.3.0-7 asterisk16-bridge-builtin-features - 16.3.0-7 asterisk16-bridge-simple - 16.3.0-7 asterisk16-bridge-softmix - 16.3.0-7 asterisk16-cdr - 16.3.0-7 asterisk16-chan-bcm63xx-phone - 4.14.180-4.14.180 asterisk16-chan-rtp - 16.3.0-7 asterisk16-chan-sip - 16.3.0-7 asterisk16-codec-a-mu - 16.3.0-7 asterisk16-codec-alaw - 16.3.0-7 asterisk16-codec-ulaw - 16.3.0-7 asterisk16-format-gsm - 16.3.0-7 asterisk16-format-pcm - 16.3.0-7 asterisk16-format-sln - 16.3.0-7 asterisk16-format-wav - 16.3.0-7 asterisk16-func-shell - 16.3.0-7 asterisk16-res-adsi - 16.3.0-7 asterisk16-res-musiconhold - 16.3.0-7 asterisk16-res-pjproject - 16.3.0-7 asterisk16-res-rtp-asterisk - 16.3.0-7 asterisk16-res-rtp-multicast - 16.3.0-7 asterisk16-res-smdi - 16.3.0-7 asterisk16-res-sorcery - 16.3.0-7 asterisk16-voicemail - 16.3.0-7