Skip to contentSkip to conversation

Add support for rmnet driver

PATCH Superseded Subash Abhinov Kasiviswanathan 5 participants 11 messages Aug 16, 2017 – Aug 17, 2017

Subsystems (4)

v4 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add support for rmnet driver

--
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.

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       |  14 +
 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c | 470 +++++++++++++++++++++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h |  60 +++
 .../net/ethernet/qualcomm/rmnet/rmnet_handlers.c   | 301 +++++++++++++
 .../net/ethernet/qualcomm/rmnet/rmnet_handlers.h   |  26 ++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_main.c   |  37 ++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h    |  88 ++++
 .../ethernet/qualcomm/rmnet/rmnet_map_command.c    | 122 ++++++
 .../net/ethernet/qualcomm/rmnet/rmnet_map_data.c   | 105 +++++
 .../net/ethernet/qualcomm/rmnet/rmnet_private.h    |  47 +++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c    | 270 ++++++++++++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h    |  32 ++
 include/uapi/linux/if_arp.h                        |   1 +
 include/uapi/linux/if_ether.h                      |   4 +-
 18 files changed, 1674 insertions(+), 1 deletion(-)
 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_main.c
 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
#1 lore raw

PATCH v4 1/3 net: ether: Add support for multiplexing and aggregation type

Define the multiplexing and aggregation (MAP) ether type 0xDA1A. 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 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/uapi/linux/if_ether.h +3 -1
index 5bc9bfd..e80b03f 100644
@@ -104,7 +104,9 @@
 #define ETH_P_QINQ3	0x9300		/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */
 #define ETH_P_EDSA	0xDADA		/* Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] */
 #define ETH_P_AF_IUCV   0xFBFB		/* IBM af_iucv [ NOT AN OFFICIALLY REGISTERED ID ] */
-
+#define ETH_P_MAP       0xDA1A          /* Multiplexing and Aggregation Protocol
+					 *  NOT AN OFFICIALLY REGISTERED ID ]
+					 */
 #define ETH_P_802_3_MIN	0x0600		/* If the value in the ethernet type is less than this value
 					 * then the frame is Ethernet II. Else it is 802.3 */
 
Signature · 1 line
1.9.1
#2 lore raw

PATCH v4 2/3 net: arp: Add support for raw IP device

In reply to Subash Abhinov Kasiviswanathan

Define 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
index cf73510..d6650e2 100644
@@ -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    530             /* Raw IP                       */
 
 #define ARPHRD_TUNNEL	768		/* IPIP tunnel			*/
 #define ARPHRD_TUNNEL6	769		/* IP6IP6 tunnel       		*/
Signature · 1 line
1.9.1
#3 lore raw

Re: [PATCH net-next 2/3 v4] net: arp: Add support for raw IP device

Hi Subash,

Quoted 13 lines

Define 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 +0 -0
index cf73510..d6650e2 100644

include/uapi/linux/if_arp.h line 62

Quoted 4 lines
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    530             /* Raw IP                       */

what is up with gap here?

Regards

Marcel

#4 lore raw

Re: [PATCH net-next 2/3 v4] net: arp: Add support for raw IP device

Quoted 13 lines

include/uapi/linux/if_arp.h line 63

Quoted 10 lines
include/uapi/linux/if_arp.h +1 -0
index cf73510..d6650e2 100644
@@ -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    530             /* Raw IP                     
  */

what is up with gap here?

Quoted 3 lines

Regards

Marcel

Hi Marcel

I was earlier using that id internally since I was not sure if some conflict could arise there. I have picked 519 for it now.

#5 lore raw

PATCH v4 3/3 drivers: net: ethernet: qualcomm: rmnet: Initial implementation

In reply to Subash Abhinov Kasiviswanathan

RmNet 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       |  14 +
 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c | 470 +++++++++++++++++++++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h |  60 +++
 .../net/ethernet/qualcomm/rmnet/rmnet_handlers.c   | 301 +++++++++++++
 .../net/ethernet/qualcomm/rmnet/rmnet_handlers.h   |  26 ++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_main.c   |  37 ++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h    |  88 ++++
 .../ethernet/qualcomm/rmnet/rmnet_map_command.c    | 122 ++++++
 .../net/ethernet/qualcomm/rmnet/rmnet_map_data.c   | 105 +++++
 .../net/ethernet/qualcomm/rmnet/rmnet_private.h    |  47 +++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c    | 270 ++++++++++++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h    |  32 ++
 16 files changed, 1670 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_main.c
 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
new file mode 100644
index 0000000..6b341ea
@@ -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
index 877675a..f520071 100644
@@ -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
index 92fa7c4..c4f38bd 100644
@@ -9,3 +9,5 @@ obj-$(CONFIG_QCA7000_UART) += qcauart.o
 qcauart-objs := qca_uart.o
 
 obj-y += emac/
+
+obj-$(CONFIG_RMNET) += rmnet/
\ No newline at end of file
drivers/net/ethernet/qualcomm/rmnet/Kconfig new file +12 -0
new file mode 100644
index 0000000..4948f14
@@ -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 +14 -0
new file mode 100644
index 0000000..2b6c9cf
@@ -0,0 +1,14 @@
+#
+# Makefile for the RMNET module
+#
+
+rmnet-y		 := rmnet_main.o
+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
+rmnet-y		 += rmnet_stats.o
+obj-$(CONFIG_RMNET) += rmnet.o
+
+CFLAGS_rmnet_main.o := -I$(src)
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +470 -0

470 lines not on this page · raw message

drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h new file +60 -0

60 lines not on this page · raw message

drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c new file +301 -0

301 lines not on this page · raw message

drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.h new file +26 -0
new file mode 100644
index 0000000..ea9c7d9
@@ -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_logical_ep_conf_s *ep);
+
+rx_handler_result_t rmnet_rx_handler(struct sk_buff **pskb);
+
+#endif /* _RMNET_HANDLERS_H_ */
drivers/net/ethernet/qualcomm/rmnet/rmnet_main.c new file +37 -0
new file mode 100644
index 0000000..80c3920
@@ -0,0 +1,37 @@
+/* Copyright (c) 2013-2014, 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 generic framework
+ *
+ */
+
+#include <linux/module.h>
+#include "rmnet_private.h"
+#include "rmnet_config.h"
+#include "rmnet_vnd.h"
+
+/* Startup/Shutdown */
+
+static int __init rmnet_init(void)
+{
+	rmnet_config_init();
+	return 0;
+}
+
+static void __exit rmnet_exit(void)
+{
+	rmnet_config_exit();
+}
+
+module_init(rmnet_init)
+module_exit(rmnet_exit)
+MODULE_LICENSE("GPL v2");
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 +122 -0

122 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 +47 -0

47 lines not on this page · raw message

drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c new file +270 -0

270 lines not on this page · raw message

drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h new file +32 -0
new file mode 100644
index 0000000..482e130
@@ -0,0 +1,32 @@
+/* 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 rmnet_phys_ep_conf_s *config,
+			      struct net_device *dev, int enable);
+struct rmnet_logical_ep_conf_s *rmnet_vnd_get_le_config(struct net_device *dev);
+int rmnet_vnd_free_dev(struct net_device *real_dev, int id);
+int rmnet_vnd_remove_ref_dev(struct net_device *real_dev, int id);
+int rmnet_vnd_rx_fixup(struct sk_buff *skb, struct net_device *dev);
+int rmnet_vnd_tx_fixup(struct sk_buff *skb, struct net_device *dev);
+int rmnet_vnd_is_vnd(struct net_device *real_dev, struct net_device *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
maintainer
#6 lore raw

Re: [PATCH net-next 3/3 v4] drivers: net: ethernet: qualcomm: rmnet: Initial implementation

From: Subash Abhinov Kasiviswanathan <[email protected]>
Date: Tue, 15 Aug 2017 22:15:53 -0600

Quoted 4 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +4 -0
+static int rmnet_unregister_real_device(struct net_device *dev)
+{
+	int config_id = RMNET_LOCAL_LOGICAL_ENDPOINT;
+	struct rmnet_logical_ep_conf_s *epconfig_l;

drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c line 89

Quoted 10 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +10 -0
+	struct rmnet_phys_ep_conf_s *config;
+
+	ASSERT_RTNL();
+
+	netdev_info(dev, "Removing device %s\n", dev->name);
+
+	if (!rmnet_is_real_dev_registered(dev))
+		return -EINVAL;
+
+	for (; config_id < RMNET_MAX_LOGICAL_EP; config_id++) {

This loop is so much harder to understand because you initialize the loop index several lines above the for() statement. Just initialize it here at the beginning of the for() loop and deal with the fact that this will have to therefore be a multi-line for() statement the best you can.

drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c line 122

Quoted 2 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +2 -0
+static int rmnet_set_egress_data_format(struct net_device *dev,	u32 edf,
+					u16 agg_size, u16 agg_count)

Use a space instead of a TAB character before the "u32 edf," argument.

Quoted 13 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +13 -0
+static int
+__rmnet_set_logical_endpoint_config(struct net_device *dev,
+				    int config_id,
+				    struct rmnet_logical_ep_conf_s *epconfig)
+{
+	struct rmnet_logical_ep_conf_s *epconfig_l;
+
+	ASSERT_RTNL();
+
+	epconfig_l = rmnet_get_logical_ep(dev, config_id);
+
+	if (!epconfig_l || epconfig_l->refcount)
+		return -EINVAL;

drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c line 190

Quoted 10 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +10 -0
+
+	memcpy(epconfig_l, epconfig, sizeof(struct rmnet_logical_ep_conf_s));
+	if (config_id == RMNET_LOCAL_LOGICAL_ENDPOINT)
+		epconfig_l->mux_id = 0;
+	else
+		epconfig_l->mux_id = config_id;
+
+	dev_hold(epconfig_l->egress_dev);
+	return 0;
+}

This looks really messy.

One invariant that must hold is that if I try to take down netdev "X", all resources holding a reference to X will be immediately (or quickly) dropped when that request comes in via notifiers.

Will this happen properly for this egress_dev reference counting?

Quoted 4 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +4 -0
+static int rmnet_config_notify_cb(struct notifier_block *nb,
+				  unsigned long event, void *data)
+{
+	struct net_device *dev = netdev_notifier_info_to_dev(data);

drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c line 342

Quoted 10 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +10 -0
+
+	if (!dev)
+		return NOTIFY_DONE;
+
+	switch (event) {
+	case NETDEV_UNREGISTER_FINAL:
+	case NETDEV_UNREGISTER:
+		netdev_info(dev, "Kernel unregister\n");
+		rmnet_force_unassociate_device(dev);
+		break;

So I guess it happens here?

#7 lore raw

RE: [PATCH net-next 3/3 v4] drivers: net: ethernet: qualcomm: rmnet: Initial implementation

From: David Miller

Quoted 16 lines

Sent: 16 August 2017 05:24
From: Subash Abhinov Kasiviswanathan <[email protected]>
Date: Tue, 15 Aug 2017 22:15:53 -0600

Quoted 12 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +12 -0
+static int rmnet_unregister_real_device(struct net_device *dev)
+{
+	int config_id = RMNET_LOCAL_LOGICAL_ENDPOINT;
+	struct rmnet_logical_ep_conf_s *epconfig_l;
+	struct rmnet_phys_ep_conf_s *config;
+
+	ASSERT_RTNL();
+
+	netdev_info(dev, "Removing device %s\n", dev->name);
+
+	if (!rmnet_is_real_dev_registered(dev))
+		return -EINVAL;
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	for (; config_id < RMNET_MAX_LOGICAL_EP; config_id++) {

This loop is so much harder to understand because you initialize the loop index several lines above the for() statement. Just initialize it here at the beginning of the for() loop and deal with the fact that this will have to therefore be a multi-line for() statement the best you can.

...

One way to split the multi-line for() is to put the initialiser on the immediately preceding line:

	config_id = RMNET_LOCAL_LOGICAL_ENDPOINT;
	for (; config_id < RMNET_MAX_LOGICAL_EP; config_id++) {

	David
#8 lore raw

Re: [PATCH net-next 3/3 v4] drivers: net: ethernet: qualcomm: rmnet: Initial implementation

In reply to David Miller
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +12 -0
+static int rmnet_unregister_real_device(struct net_device *dev)
+{
+	int config_id = RMNET_LOCAL_LOGICAL_ENDPOINT;
+	struct rmnet_logical_ep_conf_s *epconfig_l;
+	struct rmnet_phys_ep_conf_s *config;
+
+	ASSERT_RTNL();
+
+	netdev_info(dev, "Removing device %s\n", dev->name);
+
+	if (!rmnet_is_real_dev_registered(dev))
+		return -EINVAL;
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	for (; config_id < RMNET_MAX_LOGICAL_EP; config_id++) {

This loop is so much harder to understand because you initialize the loop index several lines above the for() statement. Just initialize it here at the beginning of the for() loop and deal with the fact that this will have to therefore be a multi-line for() statement the best you can.

Quoted 8 lines

...

One way to split the multi-line for() is to put the initialiser on the immediately preceding line:

	config_id = RMNET_LOCAL_LOGICAL_ENDPOINT;
	for (; config_id < RMNET_MAX_LOGICAL_EP; config_id++) {

	David

Hi DaveM / David

I'll move the initialization as above.

Quoted 7 lines

drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c line 122

Quoted 4 lines

+static int rmnet_set_egress_data_format(struct net_device *dev, u32
edf,

drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +1 -0
+					u16 agg_size, u16 agg_count)

Use a space instead of a TAB character before the "u32 edf," argument.

I'll fix this.

Quoted 33 lines
Quoted 16 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +15 -0
+static int
+__rmnet_set_logical_endpoint_config(struct net_device *dev,
+				    int config_id,
+				    struct rmnet_logical_ep_conf_s *epconfig)
+{
+	struct rmnet_logical_ep_conf_s *epconfig_l;
+
+	ASSERT_RTNL();
+
+	epconfig_l = rmnet_get_logical_ep(dev, config_id);
+
+	if (!epconfig_l || epconfig_l->refcount)
+		return -EINVAL;
+
+	memcpy(epconfig_l, epconfig, sizeof(struct 

rmnet_logical_ep_conf_s));

drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c line 190

Quoted 8 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +8 -0
+	if (config_id == RMNET_LOCAL_LOGICAL_ENDPOINT)
+		epconfig_l->mux_id = 0;
+	else
+		epconfig_l->mux_id = config_id;
+
+	dev_hold(epconfig_l->egress_dev);
+	return 0;
+}

This looks really messy.

One invariant that must hold is that if I try to take down netdev "X", all resources holding a reference to X will be immediately (or quickly) dropped when that request comes in via notifiers.

Will this happen properly for this egress_dev reference counting?

Quoted 16 lines
Quoted 4 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +4 -0
+static int rmnet_config_notify_cb(struct notifier_block *nb,
+				  unsigned long event, void *data)
+{
+	struct net_device *dev = netdev_notifier_info_to_dev(data);

drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c line 342

Quoted 10 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +10 -0
+
+	if (!dev)
+		return NOTIFY_DONE;
+
+	switch (event) {
+	case NETDEV_UNREGISTER_FINAL:
+	case NETDEV_UNREGISTER:
+		netdev_info(dev, "Kernel unregister\n");
+		rmnet_force_unassociate_device(dev);
+		break;

So I guess it happens here?

Yes, all the rmnet devices are removed from the real_dev in the notifier callback.

#9 lore raw

Re: [PATCH net-next 3/3 v4] drivers: net: ethernet: qualcomm: rmnet: Initial implementation

In reply to Subash Abhinov Kasiviswanathan
Quoted 7 lines · Wed, Aug 16, 2017 at 06:15:53AM CEST, [email protected] wrote:

RmNet 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.

[...]

Quoted 1 line

+struct rmnet_phys_ep_conf_s {

The name is cryptic. Why "_s"?

drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h line 49

Quoted 11 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h new file +11 -0
+	struct net_device *dev;
+	struct rmnet_logical_ep_conf_s local_ep;
+	struct rmnet_logical_ep_conf_s muxed_ep[RMNET_MAX_LOGICAL_EP];
+	u32 ingress_data_format;
+	u32 egress_data_format;
+	struct net_device *rmnet_devices[RMNET_MAX_VND];
+};
+
+extern struct rtnl_link_ops rmnet_link_ops;
+
+struct rmnet_vnd_private_s {

Again, cryptic.

Quoted 3 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h new file +3 -0
+	struct rmnet_logical_ep_conf_s local_ep;
+	u32 msg_enable;
+};

[...]

drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c line 211

Quoted 3 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c new file +3 -0
+rx_handler_result_t rmnet_ingress_handler(struct sk_buff *skb)
+{
+	struct rmnet_phys_ep_conf_s *config;

I still fail to understand why the name of this is "config". Please change to something else across whole code. Including the name of the struct.

drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c line 219

Quoted 8 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c new file +8 -0
+	struct net_device *dev;
+	int rc;
+
+	if (!skb)
+		return RX_HANDLER_CONSUMED;
+
+	dev = skb->dev;
+	config = rmnet_get_phys_ep_config(skb->dev);

You have dev. Why not use dev?

Quoted 32 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c new file +32 -0
+
+	/* Sometimes devices operate in ethernet mode even thouth there is no
+	 * ethernet header. This causes the skb->protocol to contain a bogus
+	 * value and the skb->data pointer to be off by 14 bytes. Fix it if
+	 * configured to do so
+	 */
+	if (config->ingress_data_format & RMNET_INGRESS_FIX_ETHERNET) {
+		skb_push(skb, RMNET_ETHERNET_HEADER_LENGTH);
+		rmnet_set_skb_proto(skb);
+	}
+
+	if (config->ingress_data_format & RMNET_INGRESS_FORMAT_MAP) {
+		rc = rmnet_map_ingress_handler(skb, config);
+	} else {
+		switch (ntohs(skb->protocol)) {
+		case ETH_P_MAP:
+			if (config->local_ep.rmnet_mode ==
+				RMNET_EPMODE_BRIDGE) {
+				rc = rmnet_ingress_deliver_packet(skb, config);
+			} else {
+				kfree_skb(skb);
+				rc = RX_HANDLER_CONSUMED;
+			}
+			break;
+
+		case ETH_P_ARP:
+		case ETH_P_IP:
+		case ETH_P_IPV6:
+			rc = rmnet_ingress_deliver_packet(skb, config);
+			break;
+
+		default:

drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c line 261

Quoted 10 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c new file +10 -0
+			rc = RX_HANDLER_PASS;
+		}
+	}
+
+	return rc;
+}
+
+rx_handler_result_t rmnet_rx_handler(struct sk_buff **pskb)
+{
+	return rmnet_ingress_handler(*pskb);

This is just silly. Why you don't have the content of rmnet_ingress_handler right here?

#10 lore raw

Re: [PATCH net-next 3/3 v4] drivers: net: ethernet: qualcomm: rmnet: Initial implementation

Quoted 9 lines
Quoted 1 line

+struct rmnet_phys_ep_conf_s {

The name is cryptic. Why "_s"?

drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h line 49

Quoted 2 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h new file +2 -0
+
+struct rmnet_vnd_private_s {

Again, cryptic.

Quoted 3 lines

drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h line 52

Quoted 3 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h new file +3 -0
+	struct rmnet_logical_ep_conf_s local_ep;
+	u32 msg_enable;
+};

Hi Jiri

The _s was to indicate struct. I'll remove that.

Quoted 18 lines

drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c line 211

Quoted 3 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c new file +3 -0
+rx_handler_result_t rmnet_ingress_handler(struct sk_buff *skb)
+{
+	struct rmnet_phys_ep_conf_s *config;

I still fail to understand why the name of this is "config". Please change to something else across whole code. Including the name of the struct.

drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c line 219

Quoted 8 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c new file +8 -0
+	struct net_device *dev;
+	int rc;
+
+	if (!skb)
+		return RX_HANDLER_CONSUMED;
+
+	dev = skb->dev;
+	config = rmnet_get_phys_ep_config(skb->dev);

You have dev. Why not use dev?

Quoted 6 lines

drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c line 261

Quoted 3 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c new file +3 -0
+rx_handler_result_t rmnet_rx_handler(struct sk_buff **pskb)
+{
+	return rmnet_ingress_handler(*pskb);

This is just silly. Why you don't have the content of rmnet_ingress_handler right here?

I'll make these changes now.