Add support for rmnet driver
Subsystems (4)
v9 cover Add support for rmnet driver
This patch adds support for the rmnet driver which is required to support recent chipsets using Qualcomm Technologies, Inc. modems. The data from hardware follows the multiplexing and aggregation protocol (MAP).
This driver can be used to register onto any physical network device in IP mode. Physical transports include USB, HSIC, PCIe and IP accelerator.
rmnet driver helps to decode these packets and queue them to network stack (and encode and transmit it to the physical device).
--
v1: Same as the RFC patch with some minor fixes for issues reported by kbuild test robot.
v1->v2: Change datatypes and remove config IOCTL as mentioned by David. Also fix checkpatch issues and remove some unused code.
v2->v3: Move location to drivers/net and rename to rmnet. Change the userspace - netlink communication from custom netlink to rtnl_link_ops. Refactor some code. Use a fixed config for ingress and egress.
v3->v4: Move location to drivers/net/ethernet/qualcomm/. Fix comments from Stephen and Jiri -
Split the ether and arp type changes into seperate patches. Remove debug and custom logging and switch to standard netdevice log. Remove module parameters. Refactor and change some code style issues.
v4->v5: Rename some structs and variables. Move the initializer before the for loop start. Put the arp type in correct sequence.
v5->v6: Fix comments from Dan -
Use the upper link API. As a result, remove all the refcounting logic. Device refcount is explicitly held on real_dev on rx_handler registration only. Modifiy the flow control struct. Remove the unused ethernet mode handling.
v6->v7: Fix comments from David - Add newline to end of Makefile. Remove inline from .c files. Move the module init/exit to rmnet config. Fix an error reported by kbuild test robot for an unused file.
v7->v8: Use a smaller value for ETH_P_MAP as mentioned by David. Change netdev_info to netdev_dbg as mentioned by Andew. Fix comments from Stephen regarding netdev_priv and sparse related errors of using 0 as NULL
v8->v9: Fix comments from David - Remove the CFLAG rule. Change the way rmnet devices are freed. Instead of using a workqueue to unregister devices individually, go through the list and free all devices within the rtnl_lock().
Subash Abhinov Kasiviswanathan (3):
net: ether: Add support for multiplexing and aggregation type
net: arp: Add support for raw IP device
drivers: net: ethernet: qualcomm: rmnet: Initial implementation
Documentation/networking/rmnet.txt | 82 +++++ drivers/net/ethernet/qualcomm/Kconfig | 2 + drivers/net/ethernet/qualcomm/Makefile | 2 + drivers/net/ethernet/qualcomm/rmnet/Kconfig | 12 + drivers/net/ethernet/qualcomm/rmnet/Makefile | 10 + drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c | 401 +++++++++++++++++++++ drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h | 54 +++ .../net/ethernet/qualcomm/rmnet/rmnet_handlers.c | 271 ++++++++++++++ .../net/ethernet/qualcomm/rmnet/rmnet_handlers.h | 26 ++ drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h | 88 +++++ .../ethernet/qualcomm/rmnet/rmnet_map_command.c | 107 ++++++ .../net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 105 ++++++ .../net/ethernet/qualcomm/rmnet/rmnet_private.h | 45 +++ drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c | 197 ++++++++++ drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h | 30 ++ include/uapi/linux/if_arp.h | 1 + include/uapi/linux/if_ether.h | 1 + 17 files changed, 1434 insertions(+) create mode 100644 Documentation/networking/rmnet.txt create mode 100644 drivers/net/ethernet/qualcomm/rmnet/Kconfig create mode 100644 drivers/net/ethernet/qualcomm/rmnet/Makefile create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.h create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_private.h create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h
Signature · 1 line
1.9.1
PATCH v9 1/3 net: ether: Add support for multiplexing and aggregation type
Define the multiplexing and aggregation (MAP) ether type 0x00F9. This is needed for receiving data in the MAP protocol like RMNET. This is not an officially registered ID.
--- include/uapi/linux/if_ether.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/if_ether.h +1 -0
@@ -137,6 +137,7 @@#define ETH_P_IEEE802154 0x00F6/* IEEE802.15.4 frame */ #define ETH_P_CAIF 0x00F7/* ST-Ericsson CAIF protocol */ #define ETH_P_XDSA 0x00F8/* Multiplexed DSA protocol */ +#define ETH_P_MAP 0x00F9/* Multiplex & aggregation proto*/ /* * This is an Ethernet frame header.
Signature · 1 line
1.9.1
Re: [PATCH net-next 1/3 v9] net: ether: Add support for multiplexing and aggregation type
Quoted 19 lines · Subash Abhinov Kasiviswanathan
Define the multiplexing and aggregation (MAP) ether type
0x00F9. This is needed for receiving data in the MAP protocol like RMNET. This is not an officially registered ID.Signed-off-by Subash Abhinov Kasiviswanathan <[email protected]g>
---
include/uapi/linux/if_ether.h | 1 +1 file changed, 1 insertion(+)include/uapi/linux/if_ether.h +0
-0@@ -137,6 +137,7 @@ #define ETH_P_IEEE802154 0x00F6 /* IEEE802.15.4 frame*/ #define ETH_P_CAIF 0x00F7 /* ST-Ericsson CAIF
Quoted 5 lines
protocol */
#defineETH_P_XDSA0x00F8/* Multiplexed DSA
protocol */
+#defineETH_P_MAP0x00F9/* Multiplex &
aggregation proto*/
Any chance you could name this QUALCOMM_MAP or something like that? Or at least update the comment to include that fact.
Dan
Quoted 2 lines
/*
* This is an Ethernet frame header.
Re: [PATCH net-next 1/3 v9] net: ether: Add support for multiplexing and aggregation type
Quoted 6 lines · Dan Williams
Quoted 4 lines · Subash Abhinov Kasiviswanathan
Define the multiplexing and aggregation (MAP) ether type
0x00F9. This is needed for receiving data in the MAP protocol like RMNET. This is not an officially registered ID.
Quoted 9 lines
Quoted 3 lines
Signed-off-by: Subash Abhinov Kasiviswanathan <subash
+#defineETH_P_MAP0x00F9/* Multiplex &
aggregation proto*/Any chance you could name this
QUALCOMM_MAPor something like that? Or at least update the comment to include that fact.Dan
Hi Dan
Sure, I can add a comment for it.
PATCH v9 2/3 net: arp: Add support for raw IP device
In reply to Subash Abhinov KasiviswanathanDefine the raw IP type. This is needed for raw IP net devices like rmnet.
--- include/uapi/linux/if_arp.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/if_arp.h +1 -0
@@ -59,6 +59,7 @@#define ARPHRD_LAPB 516/* LAPB */ #define ARPHRD_DDCMP 517/* Digital's DDCMP protocol */ #define ARPHRD_RAWHDLC 518/* Raw HDLC */ +#define ARPHRD_RAWIP 519/* Raw IP */ #define ARPHRD_TUNNEL 768/* IPIP tunnel */ #define ARPHRD_TUNNEL6 769/* IP6IP6 tunnel */
Signature · 1 line
1.9.1
PATCH v9 3/3 drivers: net: ethernet: qualcomm: rmnet: Initial implementation
In reply to Subash Abhinov KasiviswanathanRmNet driver provides a transport agnostic MAP (multiplexing and aggregation protocol) support in embedded module. Module provides virtual network devices which can be attached to any IP-mode physical device. This will be used to provide all MAP functionality on future hardware in a single consistent location.
--- Documentation/networking/rmnet.txt | 82 +++++ drivers/net/ethernet/qualcomm/Kconfig | 2 + drivers/net/ethernet/qualcomm/Makefile | 2 + drivers/net/ethernet/qualcomm/rmnet/Kconfig | 12 + drivers/net/ethernet/qualcomm/rmnet/Makefile | 10 + drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c | 401 +++++++++++++++++++++ drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h | 54 +++ .../net/ethernet/qualcomm/rmnet/rmnet_handlers.c | 271 ++++++++++++++ .../net/ethernet/qualcomm/rmnet/rmnet_handlers.h | 26 ++ drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h | 88 +++++ .../ethernet/qualcomm/rmnet/rmnet_map_command.c | 107 ++++++ .../net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 105 ++++++ .../net/ethernet/qualcomm/rmnet/rmnet_private.h | 45 +++ drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c | 197 ++++++++++ drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h | 30 ++ 15 files changed, 1432 insertions(+) create mode 100644 Documentation/networking/rmnet.txt create mode 100644 drivers/net/ethernet/qualcomm/rmnet/Kconfig create mode 100644 drivers/net/ethernet/qualcomm/rmnet/Makefile create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.h create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_private.h create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h
Documentation/networking/rmnet.txt new file +82 -0
@@ -0,0 +1,82 @@ +1. Introduction + +rmnet driver is used for supporting the Multiplexing and aggregation +Protocol (MAP). This protocol is used by all recent chipsets using Qualcomm +Technologies, Inc. modems. + +This driver can be used to register onto any physical network device in +IP mode. Physical transports include USB, HSIC, PCIe and IP accelerator. + +Multiplexing allows for creation of logical netdevices (rmnet devices) to +handle multiple private data networks (PDN) like a default internet, tethering, +multimedia messaging service (MMS) or IP media subsystem (IMS). Hardware sends +packets with MAP headers to rmnet. Based on the multiplexer id, rmnet +routes to the appropriate PDN after removing the MAP header. + +Aggregation is required to achieve high data rates. This involves hardware +sending aggregated bunch of MAP frames. rmnet driver will de-aggregate +these MAP frames and send them to appropriate PDN's. + +2. Packet format + +a. MAP packet (data / control) + +MAP header has the same endianness of the IP packet. + +Packet format - + +Bit 0 1 2-7 8 - 15 16 - 31 +Function Command / Data Reserved Pad Multiplexer ID Payload length +Bit 32 - x +Function Raw Bytes + +Command (1)/ Data (0) bit value is to indicate if the packet is a MAP command +or data packet. Control packet is used for transport level flow control. Data +packets are standard IP packets. + +Reserved bits are usually zeroed out and to be ignored by receiver. + +Padding is number of bytes to be added for 4 byte alignment if required by +hardware. + +Multiplexer ID is to indicate the PDN on which data has to be sent. + +Payload length includes the padding length but does not include MAP header +length. + +b. MAP packet (command specific) + +Bit 0 1 2-7 8 - 15 16 - 31 +Function Command Reserved Pad Multiplexer ID Payload length +Bit 32 - 39 40 - 45 46 - 47 48 - 63 +Function Command name Reserved Command Type Reserved +Bit 64 - 95 +Function Transaction ID +Bit 96 - 127 +Function Command data + +Command 1 indicates disabling flow while 2 is enabling flow + +Command types - +0 for MAP command request +1 is to acknowledge the receipt of a command +2 is for unsupported commands +3 is for error during processing of commands + +c. Aggregation + +Aggregation is multiple MAP packets (can be data or command) delivered to +rmnet in a single linear skb. rmnet will process the individual +packets and either ACK the MAP command or deliver the IP packet to the +network stack as needed + +MAP header|IP Packet|Optional padding|MAP header|IP Packet|Optional padding.... +MAP header|IP Packet|Optional padding|MAP header|Command Packet|Optional pad... + +3. Userspace configuration + +rmnet userspace configuration is done through netlink library librmnetctl +and command line utility rmnetcli. Utility is hosted in codeaurora forum git. +The driver uses rtnl_link_ops for communication. + +https://source.codeaurora.org/quic/la/platform/vendor/qcom-opensource/dataservices/tree/rmnetctl
drivers/net/ethernet/qualcomm/Kconfig +2 -0
@@ -59,4 +59,6 @@ config QCOM_EMAC low power, Receive-Side Scaling (RSS), and IEEE 1588-2008 Precision Clock Synchronization Protocol. +source "drivers/net/ethernet/qualcomm/rmnet/Kconfig" + endif # NET_VENDOR_QUALCOMM
drivers/net/ethernet/qualcomm/Makefile +2 -0
@@ -9,3 +9,5 @@ obj-$(CONFIG_QCA7000_UART) += qcauart.o qcauart-objs := qca_uart.o obj-y += emac/ + +obj-$(CONFIG_RMNET) += rmnet/
drivers/net/ethernet/qualcomm/rmnet/Kconfig new file +12 -0
@@ -0,0 +1,12 @@ +# +# RMNET MAP driver +# + +menuconfig RMNET + depends on NETDEVICES + bool "RmNet MAP driver" + default n + ---help--- + If you say Y here, then the rmnet module will be statically + compiled into the kernel. The rmnet module provides MAP + functionality for embedded and bridged traffic.
drivers/net/ethernet/qualcomm/rmnet/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# +# Makefile for the RMNET module +# + +rmnet-y := rmnet_config.o +rmnet-y += rmnet_vnd.o +rmnet-y += rmnet_handlers.o +rmnet-y += rmnet_map_data.o +rmnet-y += rmnet_map_command.o +obj-$(CONFIG_RMNET) += rmnet.o
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +401 -0
401 lines not on this page · raw message
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h new file +54 -0
54 lines not on this page · raw message
drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c new file +271 -0
271 lines not on this page · raw message
drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.h new file +26 -0
@@ -0,0 +1,26 @@ +/* Copyright (c) 2013, 2016-2017 The Linux Foundation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* RMNET Data ingress/egress handler +* +*/ + +#ifndef _RMNET_HANDLERS_H_ +#define _RMNET_HANDLERS_H_ + +#include "rmnet_config.h" + +void rmnet_egress_handler (struct sk_buff *skb, +struct rmnet_endpoint *ep); + +rx_handler_result_t rmnet_rx_handler (struct sk_buff **pskb); + +#endif /* _RMNET_HANDLERS_H_ */
drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h new file +88 -0
88 lines not on this page · raw message
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c new file +107 -0
107 lines not on this page · raw message
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c new file +105 -0
105 lines not on this page · raw message
drivers/net/ethernet/qualcomm/rmnet/rmnet_private.h new file +45 -0
45 lines not on this page · raw message
drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c new file +197 -0
197 lines not on this page · raw message
drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h new file +30 -0
@@ -0,0 +1,30 @@ +/* Copyright (c) 2013-2017, The Linux Foundation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* RMNET Data Virtual Network Device APIs +* +*/ + +#ifndef _RMNET_VND_H_ +#define _RMNET_VND_H_ + +int rmnet_vnd_do_flow_control (struct net_device *dev,int enable); +struct rmnet_endpoint *rmnet_vnd_get_endpoint (struct net_device *dev); +int rmnet_vnd_remove_ref_dev (struct net_device *real_dev,int id); +void rmnet_vnd_rx_fixup (struct sk_buff *skb,struct net_device *dev); +void rmnet_vnd_tx_fixup (struct sk_buff *skb,struct net_device *dev); +int rmnet_vnd_get_mux (struct net_device *real_dev, +struct net_device *rmnet_dev); +struct net_device *rmnet_vnd_get_by_id (struct net_device *real_dev,int id); +void rmnet_vnd_setup (struct net_device *dev); +int rmnet_vnd_newlink (struct net_device *real_dev,int id, +struct net_device *new_device); +#endif /* _RMNET_VND_H_ */
Signature · 1 line
1.9.1
David Miller
maintainerRe: [PATCH net-next 3/3 v9] drivers: net: ethernet: qualcomm: rmnet: Initial implementation
From: Subash Abhinov Kasiviswanathan <[email protected]>
Date: Thu, 24 Aug 2017 22:39:26 -0600
Quoted 13 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +13
-0+static void rmnet_force_unassociate_device (struct net_device *dev) +{ +struct net_device *real_dev = dev; +struct rmnet_walk_data d; +LIST_HEAD (list); + +if (!rmnet_is_real_dev_registered (real_dev)) +return ; + +ASSERT_RTNL (); + + d.real_dev = real_dev; + d.head = &list;
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c line 311
Quoted 10 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +10
-0+ +rcu_read_lock (); +netdev_walk_all_lower_dev_rcu (real_dev, rmnet_dev_walk_unreg, &d); +synchronize_net (); + +unregister_netdevice_many (&list); +rcu_read_unlock (); + +rmnet_unregister_real_device (real_dev); +}
In these code paths where you are the writer, you have to rely upon the RTNL mutex (or some other mutual exclusion mechanism) to protect the update operation. RCU locking itself does not provide this.
So you should use something like rcu_dereference_rtnl() or similar.
So this would be rmnet_force_unassociate_device() and rmnet_dellink()
RCU is subtle and the writer paths have the be handled differently from the reader paths. Please take some time to study how RCU should be applied properly in these situations rather than just slapping a patch together overnight.
Thank you.
Re: [PATCH net-next 3/3 v9] drivers: net: ethernet: qualcomm: rmnet: Initial implementation
Quoted 7 lines
In these code paths where you are the writer, you have to rely upon the RTNL mutex (or some other mutual exclusion mechanism) to protect the update operation. RCU locking itself does not provide this.
So you should use something like
rcu_dereference_rtnl()or similar.
Quoted 8 lines
So this would be
rmnet_force_unassociate_device()andrmnet_dellink()RCU is subtle and the writer paths have the be handled differently from the reader paths. Please take some time to study how RCU should be applied properly in these situations rather than just slapping a patch together overnight.
Thank you.
Sorry about the mess David.
Can you tell me if the following design is correct -
The shared resource which needs to be protected is real_dev->rx_handler_data.
For the writer path, this needs to be protected using rtnl_lock() and rcu. The writer paths are rmnet_newlink(), rmnet_delink() and rmnet_force_unassociate_device(). These paths are already called with rtnl_lock() acquired in, so we just need to acquire the rcu_read_lock(). To dereference here, we will need to use rtnl_dereference().
For the reader path, the real_dev->rx_handler_data is called in the TX / RX path. We only need rcu_read_lock() for these scenarios. In these cases, the rcu_read_lock() is held in __dev_queue_xmit() and netif_receive_skb_internal(), so readers need to use rcu_dereference_rtnl() to get the relevant information.