Add support for WASP SoC on AVM router boards
Subsystems (2)
v3 cover Add support for WASP SoC on AVM router boards
There is a popular set of Lantiq xrx200 router boards by AVM in Germany (AVM Fritzbox 3390, 3490, 5490, 5491 and 7490) which have the strange implementation of having the wifi cards connected to a separate memory only ATH79 based SoC. It has no persistent storage and no access to any resource on the Lantiq host, but is connect to the Lantiq GSWIP switch on an additional fixed internal network port.
This kernel module is to support booting the secondary SoC called Wireless Assistant Support Processor (WASP).
After turning it on, a small network boot firmware is sent to the SoC by using mdio and when it is started, an initramfs linux image is sent to the SoC using raw ethernet frames.
The whole procedure takes about 6 seconds, if there is no error. So far tested on 3490, 5490 and 7490 devices based on OpenWrt, 3390 takes about 20 seconds.
Patch 1/3 adds the vendor name
Patch 2/3 adds the dt-bindings
Patch 3/3 adds the remoteproc driver
To build and run, there is OpenWrt PR 5075.
Please review.
Changes in v3:
- Replace generic avm,fritzboxx490-wasp with actual device names for device tree documentation and change the driver to accept them
- Add maxItems to device tree documentation
- Change example in the device tree documentation
- Fix wait time to make the Wasp upload work for 3390 more reliable
- Enable the SOC on driver load, use reset instead of disable/enable while driver is loaded and disable on unloading the driver
- Change some messages printed to adhere to standards (e.g. remove !)
Changes in v2:
- Remove firmware names from dt-binding and add as kmod parameters
- Rename other bindings with vender prefix and fix gpios suffix
- Change descriptions in dt-binding
- Replace/Remove asynch load of firmware with request_firmware_direct
- Fix comments to use the errno define instead of the number
- Implement wait loops with read_poll_timeout() macro
- Wrap read_poll_timeout() macro in function saving 6k module size
- Return -ETIMEDOUT for all errors returned by read_poll_timeout
- Replace mdio writes/reads with mdiobus_write and mdiobus_read and add return codes and their handling
- Remove mutex for mdiobus_lock and add return code checking for mdio ops
- Replaced the mdio register array with directly specifying registers
- As a result of the previous 3 changes remove the functions for mdio
- Consolidate error messages for mdio writes into a single one saved 1k for module size
- Replaced mdelay with usleep_range saved 0,7k module size
- Remove unneeded include <linux/interrupt.h> and <linux/error.h>
- Wrap all blocks with {} and fix some indentation errors
- Change const len in to size_t in avm_wasp_netboot_write_chunk
- Make all methods static to fix kernel bot warning
- Change read variable name in avm_wasp_load_initramfs_image
- Change ssize_t variables to size_t in avm_wasp_load_initramfs_image
- avm_wasp_netboot_write_chunk change for loop for 2 byte divisibility
- Change uint32_t to u32
- Change int count = -1 to u32 with U32_MAX initialisation
- Add check for firmware len divisable by 4
- Replace big endian bit shift operations with be32_to_cpu
- Change loop to write 14 byte firmware chuncks like suggested
- Change WASP_CHUNK_SIZE to ARRAY_SIZE(mac_data) for readability
- Change int done to boolean
- Change unsigned ints to u32
- Change int to size_t for send_len
- Use int for numbytes because kernel_recvmsg returns error or number
- Two sockets are not needed, so reduce to one socket usage
- Remove struct timeval definition, replace with __kernel_old_timeval
- __kernel_old_timeval is depracated, but arch mips is 32bit platform
- Replace &avmwasp->pdev->dev with local dev
- Check if wasp network interface is up and fail if not in start method
- Remove setsockopt for SO_REUSEADDR and SO_BINDTODEVICE
- Remove packet_counter
- Move firmware and firmware_end out of RESP_DISCOVER to make sure that they are initialized if RESP_DISCOVER is not happening first
- indend break;
- Move second half of the send/receive paket while loop to RESP_OK and let RESP_DISCOVER fall through
- Remove bringing up the wasp network interface
- Check if wasp network interface is up in probe and defer if not
- Remove the check for the root device and replace it with match data for WASP device identification
- Move of_read and find of mdio bus to rproc_start but delete reference after using it in the rproc_start method
- Replace dev_set_drvdata with platform_set_drvdata
- Remove avm_wasp_rproc_boot_addr because its not needed and move setting the fw struct pointer to avm_wasp_rproc_load
- Move avm_wasp.h definitions to kernel module
Daniel Kestrel (3):
dt-bindings: vendor-prefixes: Add AVM
dt-bindings: remoteproc: Add AVM WASP
remoteproc: Add AVM WASP driver
.../bindings/remoteproc/avm,wasp-rproc.yaml | 61 + .../devicetree/bindings/vendor-prefixes.yaml | 2 + drivers/remoteproc/Kconfig | 10 + drivers/remoteproc/Makefile | 1 + drivers/remoteproc/avm_wasp.c | 1056 +++++++++++++++++ 5 files changed, 1130 insertions(+) create mode 100644 Documentation/devicetree/bindings/remoteproc/avm,wasp-rproc.yaml create mode 100644 drivers/remoteproc/avm_wasp.c
Signature · 1 line
2.17.1
PATCH v3 1/3 dt-bindings: vendor-prefixes: Add AVM
Add vendor prefix for AVM Computersysteme Vertriebs GmbH (http://www.avm.de/en)
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -153,6 +153,8 @@ patternProperties: description: avia semiconductor "^avic,.*": description: Shanghai AVIC Optoelectronics Co., Ltd. + "^avm,.*": + description: AVM Computersysteme Vertriebs GmbH "^avnet,.*": description: Avnet, Inc. "^awinic,.*":
Signature · 1 line
2.17.1
PATCH v3 2/3 dt-bindings: remoteproc: Add AVM WASP
In reply to Daniel KestrelAVM Fritzbox router boards may contain an additional ATH79 based SoC that has the wifi cards connected.
This patch adds bindings for this remote processor.
--- .../bindings/remoteproc/avm,wasp-rproc.yaml | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Documentation/devicetree/bindings/remoteproc/avm,wasp-rproc.yaml
Documentation/devicetree/bindings/remoteproc/avm,wasp-rproc.yaml new file +61 -0
@@ -0,0 +1,61 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/remoteproc/avm,wasp-rproc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: AVM WASP processor controller bindings + +maintainers: + - Daniel Kestrel <[email protected]> + +description: | + This document defines the bindings for the remoteproc component that loads and + boots firmwares on the AVM Wireless Assistant Support Processor (WASP) SoC + that is attached to some AVM Fritzbox devices (3390, 3490, 5490, 5491, 7490). + +properties: + compatible: + enum: + - avm,fritzbox3390-wasp + - avm,fritzbox3490-wasp + - avm,fritzbox5490-wasp + - avm,fritzbox5491-wasp + - avm,fritzbox7490-wasp + + avm,wasp-mdio: + $ref: /schemas/types.yaml#/definitions/phandle + description: Lantiq GSWIP switch mdio. + + avm,wasp-port: + $ref: /schemas/types.yaml#/definitions/phandle + description: Network port, where the WASP SoC is connected to. + + avm,reset-gpios: + description: Reset gpio of the WASP SoC. + maxItems: 1 + + avm,startup-gpios: + description: Startup gpio of the WASP SoC. + maxItems: 1 + +required: + - compatible + - avm,wasp-mdio + - avm,wasp-port + - avm,reset-gpios + - avm,startup-gpios + +additionalProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + remoteproc { + compatible = "avm,fritzbox7490-wasp"; + avm,wasp-mdio = <&gswip_mdio>; + avm,wasp-port = <&port5>; + avm,reset-gpios = <&gpio 34 GPIO_ACTIVE_HIGH>; + avm,startup-gpios = <&gpio 5 GPIO_ACTIVE_HIGH>; + };
Signature · 1 line
2.17.1
PATCH v3 3/3 remoteproc: Add AVM WASP driver
In reply to Daniel KestrelSome AVM Fritzbox router boards (3390, 3490, 5490, 5491, 7490), that are Lantiq XRX200 based, have a memory only ATH79 based WASP (Wireless Assistant Support Processor) SoC that has wifi cards connected to it. It does not share anything with the Lantiq host and has no persistent storage. It has an mdio based connection for bringing up a small network boot firmware and is connected to the Lantiq GSWIP switch via gigabit ethernet. This is used to load an initramfs linux image to it, after the network boot firmware was started.
In order to initialize this remote processor we need to:
- power on the SoC using startup gpio
- reset the SoC using the reset gpio
- send the network boot firmware using mdio
- send the linux image using raw ethernet frames
This driver allows to start and stop the WASP SoC.
--- drivers/remoteproc/Kconfig | 10 + drivers/remoteproc/Makefile | 1 + drivers/remoteproc/avm_wasp.c | 1056 +++++++++++++++++++++++++++++++++ 3 files changed, 1067 insertions(+) create mode 100644 drivers/remoteproc/avm_wasp.c
drivers/remoteproc/Kconfig +10 -0
@@ -23,6 +23,16 @@ config REMOTEPROC_CDEV It's safe to say N if you don't want to use this interface. +config AVM_WASP_REMOTEPROC + tristate "AVM WASP remoteproc support" + depends on NET_DSA_LANTIQ_GSWIP + help + Say y here to support booting the secondary SoC ATH79 target + called Wireless Assistant Support Processor (WASP) that some + AVM Fritzbox devices (3390, 3490, 5490, 5491, 7490) have built in. + + It's safe to say N here. + config IMX_REMOTEPROC tristate "i.MX remoteproc support" depends on ARCH_MXC
drivers/remoteproc/Makefile +1 -0
@@ -11,6 +11,7 @@ remoteproc-y += remoteproc_sysfs.o remoteproc-y += remoteproc_virtio.o remoteproc-y += remoteproc_elf_loader.o obj-$(CONFIG_REMOTEPROC_CDEV) += remoteproc_cdev.o +obj-$(CONFIG_AVM_WASP_REMOTEPROC) += avm_wasp.o obj-$(CONFIG_IMX_REMOTEPROC) += imx_rproc.o obj-$(CONFIG_IMX_DSP_REMOTEPROC) += imx_dsp_rproc.o obj-$(CONFIG_INGENIC_VPU_RPROC) += ingenic_rproc.o
drivers/remoteproc/avm_wasp.c new file +1056 -0
1,056 lines not on this page · raw message
Signature · 1 line
2.17.1
kernel test robot
build botRe: [PATCH v3 3/3] remoteproc: Add AVM WASP driver
Thank you for the patch! Perhaps something to improve:
Hi Daniel,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on remoteproc/rproc-next]
[also build test WARNING on robh/for-next linus/master v5.19-rc7 next-20220721] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Daniel-Kestrel/Add-support-for-WASP-SoC-on-AVM-router-boards/20220722-033724 base: git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc/linux.git rproc-next config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20220722/[email protected]/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 72686d68c137551cce816416190a18d45b4d4e2a)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/b737a00511b74767e3eb13b2ddfba8e6dfe8e5c2
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Daniel-Kestrel/Add-support-for-WASP-SoC-on-AVM-router-boards/20220722-033724 git checkout b737a00511b74767e3eb13b2ddfba8e6dfe8e5c2
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/remoteproc/
If you fix the issue, kindly add following tag where applicable
All warnings (new ones prefixed by >>):
>> drivers/remoteproc/avm_wasp.c:582:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (!avmwasp->linux_blob) {
^~~~~~~~~~~~~~~~~~~~
drivers/remoteproc/avm_wasp.c:776:9: note: uninitialized use occurs here
return ret;
^~~
drivers/remoteproc/avm_wasp.c:582:2: note: remove the 'if' if its condition is always false
if (!avmwasp->linux_blob) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/remoteproc/avm_wasp.c:566:9: note: initialize the variable 'ret' to silence this warning
int ret;
^
= 01 warning generated.
vim +582 drivers/remoteproc/avm_wasp.c
545
546 /**
547 * avm_wasp_load_initramfs_image() - load initramfs image to WASP
548 * @avmwasp: pointer to drivers private avm_wasp_rproc structure
549 *
550 * Uses the lan port specified from DT to load the initramfs to
551 * WASP after the network boot firmware was successfully started.
552 * Communication is done by using raw sockets.
553 * There are several commands and status values which are checked.
554 * First a discovery packet is received and then each data packet
555 * is acknowledged by the WASP network boot firmware.
556 * First packet needs to prepend the load address and last packet
557 * needs to append the execution address.
558 *
559 * Return: 0 on Success, -EFAULT if errors with the WASP send protocol
560 * have occurred, -EAGAIN if the wasp network interface is down or the
561 * error returned from the failed operating system function or service
562 */
563 static int avm_wasp_load_initramfs_image(struct avm_wasp_rproc *avmwasp)
564 {
565 bool done = false;
566 int ret;
567 u32 num_chunks, chunk_counter;
568 short interface_flags;
569 const u8 *firmware, *firmware_end;
570 struct device *dev = &avmwasp->pdev->dev;
571 struct kvec socket_kvec;
572 struct msghdr socket_msghdr;
573 struct net_device *send_netdev;
574 struct sockaddr send_sock_addr;
575 struct sockaddr_ll send_socket_address;
576 struct socket *wasp_socket;
577 struct wasp_packet *packet = (struct wasp_packet *)
578 (avmwasp->buffer);
579 struct __kernel_old_timeval timeout;
580 time64_t start_time, current_time;
581
> 582 if (!avmwasp->linux_blob) {
583 dev_err(dev, "error accessing initramfs image\n");
584 goto err;
585 }
586
587 firmware = avmwasp->linux_blob->data;
588 firmware_end = firmware + avmwasp->linux_blob->size;
589
590 ret = sock_create_kern(&init_net, PF_PACKET, SOCK_RAW,
591 htons(ETH_TYPE_ATH_ECPS_FRAME),
592 &wasp_socket);
593 if (ret < 0) {
594 dev_err(dev, "error opening recv socket: %d\n", ret);
595 goto err;
596 }
597
598 timeout.tv_sec = 10;
599 timeout.tv_usec = 0;
600 ret = sock_setsockopt(wasp_socket, SOL_SOCKET, SO_RCVTIMEO_OLD,
601 KERNEL_SOCKPTR(&timeout), sizeof(timeout));
602 if (ret < 0) {
603 dev_err(dev, "error SO_RCVTIMEO recv socket: %d\n", ret);
604 goto err_socket;
605 }
606
607 ret = sock_setsockopt(wasp_socket, SOL_SOCKET, SO_SNDTIMEO_OLD,
608 KERNEL_SOCKPTR(&timeout), sizeof(timeout));
609 if (ret < 0) {
610 dev_err(dev, "error SO_SNDTIMEO send socket: %d\n", ret);
611 goto err_socket;
612 }
613
614 rcu_read_lock();
615 send_netdev = dev_get_by_name_rcu(sock_net(wasp_socket->sk),
616 avmwasp->loader_port);
617 if (send_netdev)
618 interface_flags = (short)dev_get_flags(send_netdev);
619 rcu_read_unlock();
620
621 if (IS_ERR_OR_NULL(send_netdev)) {
622 dev_err(dev, "error accessing net device\n");
623 ret = -ENODEV;
624 goto err_socket;
625 }
626
627 if (!(interface_flags & IFF_UP && interface_flags & IFF_RUNNING)) {
628 dev_err(dev, "error wasp interface %s is down\n",
629 avmwasp->loader_port);
630 ret = -EAGAIN;
631 goto err_socket;
632 }
633
634 avmwasp->ifindex = send_netdev->ifindex;
635 ret = dev_get_mac_address(&send_sock_addr, &init_net,
636 avmwasp->loader_port);
637 if (ret < 0) {
638 dev_err(dev, "error getting mac address: %d\n", ret);
639 goto err_socket;
640 }
641
642 send_socket_address.sll_halen = ETH_ALEN;
643 send_socket_address.sll_ifindex = avmwasp->ifindex;
644 memset(&socket_msghdr, 0, sizeof(socket_msghdr));
645 socket_msghdr.msg_name = (struct sockaddr *)&send_socket_address;
646 socket_msghdr.msg_namelen = sizeof(struct sockaddr_ll);
647
648 start_time = ktime_get_seconds();
649
650 while (!done) {
651 current_time = ktime_get_seconds();
652 if ((current_time - start_time) > ETH_SEND_LOOP_TIMEOUT_SECS) {
653 dev_err(dev,
654 "waiting for packet from WASP timed out\n");
655 ret = -ETIMEDOUT;
656 goto err_socket;
657 }
658
659 socket_kvec.iov_base = avmwasp->buffer;
660 socket_kvec.iov_len = ETH_BUF_SIZE;
661 ret = kernel_recvmsg(wasp_socket,
662 &socket_msghdr, &socket_kvec, 1,
663 ETH_BUF_SIZE, 0);
664
665 if (ret < 0) {
666 dev_err(dev,
667 "error receiving any packet or timeout: %d\n",
668 ret);
669 goto err_socket;
670 }
671
672 if (ret < (sizeof(struct ethhdr) + sizeof(packet->hdr))) {
673 dev_err(dev,
674 "packet too small, discard and continue\n");
675 continue;
676 }
677
678 if (packet->eh.h_proto != ETH_TYPE_ATH_ECPS_FRAME)
679 continue;
680
681 memcpy(wasp_mac, packet->eh.h_source, sizeof(wasp_mac));
682
683 if (packet->hdr.packet_start == ETH_WASP_PACKET_ID) {
684 switch (packet->hdr.response) {
685 case RESP_DISCOVER:
686 chunk_counter = 1;
687 num_chunks = DIV_ROUND_UP(avmwasp->linux_blob->size,
688 ETH_DATA_SIZE);
689 fallthrough;
690 case RESP_OK:
691 memcpy(packet->eh.h_dest, wasp_mac, sizeof(packet->eh.h_dest));
692 packet->eh.h_proto = ETH_TYPE_ATH_ECPS_FRAME;
693 memcpy(packet->eh.h_source, send_sock_addr.sa_data,
694 sizeof(packet->eh.h_source));
695
696 if (firmware < firmware_end) {
697 size_t bytestosend, send_len;
698 u32 data_offset = 0;
699
700 if (chunk_counter == 1) {
701 memcpy(packet->payload,
702 &m_load_addr,
703 sizeof(m_load_addr));
704 data_offset = sizeof(m_load_addr);
705 }
706
707 if ((firmware_end - firmware) >=
708 ETH_DATA_SIZE)
709 bytestosend = ETH_DATA_SIZE;
710 else
711 bytestosend = firmware_end -
712 firmware;
713 memcpy(&packet->payload[data_offset],
714 firmware, bytestosend);
715 firmware = firmware + ETH_DATA_SIZE;
716
717 packet->hdr.packet_start =
718 ETH_WASP_PACKET_ID;
719 if (chunk_counter == num_chunks) {
720 packet->hdr.response =
721 CMD_START_FIRMWARE;
722 memcpy(&packet->payload
723 [data_offset + bytestosend],
724 &m_load_addr,
725 sizeof(m_load_addr));
726 bytestosend += sizeof(m_load_addr);
727 } else {
728 packet->hdr.command =
729 CMD_FIRMWARE_DATA;
730 }
731 packet->hdr.counter =
732 (chunk_counter - 1) * 4;
733
734 send_len = sizeof(struct ethhdr)
735 + sizeof(packet->hdr) + bytestosend +
736 data_offset;
737
738 socket_kvec.iov_len = send_len;
739 socket_kvec.iov_base = avmwasp->buffer;
740
741 ret = kernel_sendmsg(wasp_socket,
742 &socket_msghdr,
743 &socket_kvec,
744 1, send_len); 745 if (ret < 0) {
746 dev_err(dev,
747 "error sending to WASP %d\n",
748 ret);
749 goto err_socket;
750 }
751
752 chunk_counter++;
753 }
754 break;
755 case RESP_ERROR:
756 dev_err(dev,
757 "received an WASP error packet\n");
758 ret = -EFAULT;
759 goto err_socket;
760 case RESP_STARTING:
761 done = true;
762 ret = 0;
763 continue;
764 break;
765 default:
766 dev_err(dev, "unknown packet, continue\n");
767 continue;
768 break;
769 }
770 }
771 }
772
773 err_socket:
774 wasp_socket->ops->release(wasp_socket);
775 err:
776 return ret;
777 }
778
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp