From patchwork Sun Jul 1 11:07:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 140707 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2849913ljj; Sun, 1 Jul 2018 04:12:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd7X5U4C2/oChflZ92SZjmZ/YkIkgMeMoFUxStpD3WICY+ojVNSa7CGM0Wx1t/l2e5WeYOO X-Received: by 2002:aa7:818b:: with SMTP id g11-v6mr21350565pfi.50.1530443535109; Sun, 01 Jul 2018 04:12:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530443535; cv=none; d=google.com; s=arc-20160816; b=NlSxGBrPkouiAic1MQJ71fK/2n1wpQH+qZFdB6k1kgp3uCQghl3hbO4eLpZlyqf6MA ORz3luuF6LjH7FAN+j/48v1sUR2n+USuy60IlFSbtMuE8iZB2CeblIB5GWRgitMvCPrQ yw1OjyqXDlJor/mUBZ/ngb4NWia5NZ2fC0lhhoyWSHVC9xGI0PaixWacpEv2Na7onIfv t19+g9cOPyT0qQ5krhZ1x9kVtSioN6y9BDjPEqQQtWJYshP5rNUMNbC92mo+WsxHReU2 qbkjrxUC8JWPhquJPGraDblB8t56V7reshvftXCDaKcE/yI8kM6GNHAtoqcdO+dcgge6 ytPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=iAuCWdjXri6rKXi9fj2Nss09yN2l8awn6XaA7LIbIPI=; b=RL6iaySOT2U25/TP1NTzsAXsp6e595YLlMf2pQdAsOotX5uFvl7HxUJcmGvxPwT/9I 1mGZSEBBAyb9XgsEggbYVmW6JbfLCpSyAEtpl0/UI6L6tL8kRuzDpUgl2LwK3uk4ZR6A PhDZ4VSuSJ1WnPG9yCkHFliPhY5wLKwTEXSYv8DdByXJ1FD5MO+XhazQhZEUcQ95yd+R ENN6oCqNgENgg+64sUkWzn2P/djC5v0PyXsf6Pw8FIcWZl2DrLBS07jV2raQrBJVeblb 6TzYqohHy7fmxHLlNg00Oksc/X8ysEmxHAqT3b2xphQPcrESKh54mVSwjSPuWEmMuKRr u6TQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i12-v6si12282000pgp.325.2018.07.01.04.12.14; Sun, 01 Jul 2018 04:12:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752493AbeGALMM (ORCPT + 31 others); Sun, 1 Jul 2018 07:12:12 -0400 Received: from mx2.suse.de ([195.135.220.15]:47814 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752146AbeGALJB (ORCPT ); Sun, 1 Jul 2018 07:09:01 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3DA29AE56; Sun, 1 Jul 2018 11:08:58 +0000 (UTC) From: =?utf-8?q?Andreas_F=C3=A4rber?= To: netdev@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jian-Hong Pan , Jiri Pirko , Marcel Holtmann , "David S . Miller" , Matthias Brugger , Janus Piwek , =?utf-8?q?Michael_R=C3=B6der?= , Dollar Chen , Ken Yu , =?utf-8?q?Andreas_F=C3=A4rber?= Subject: [RFC net-next 06/15] net: lora: Prepare for device drivers Date: Sun, 1 Jul 2018 13:07:55 +0200 Message-Id: <20180701110804.32415-7-afaerber@suse.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180701110804.32415-1-afaerber@suse.de> References: <20180701110804.32415-1-afaerber@suse.de> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement helper functions for use by LoRa device drivers. Signed-off-by: Andreas Färber --- drivers/net/Makefile | 1 + drivers/net/lora/Kconfig | 18 +++++++ drivers/net/lora/Makefile | 10 ++++ drivers/net/lora/dev.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/lora/dev.h | 23 +++++++++ net/lora/Kconfig | 6 +++ 6 files changed, 183 insertions(+) create mode 100644 drivers/net/lora/Kconfig create mode 100644 drivers/net/lora/Makefile create mode 100644 drivers/net/lora/dev.c create mode 100644 include/linux/lora/dev.h -- 2.16.4 diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 21cde7e78621..9819bf28633d 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -45,6 +45,7 @@ obj-$(CONFIG_ETHERNET) += ethernet/ obj-$(CONFIG_FDDI) += fddi/ obj-$(CONFIG_HIPPI) += hippi/ obj-$(CONFIG_HAMRADIO) += hamradio/ +obj-$(CONFIG_LORA) += lora/ obj-$(CONFIG_PLIP) += plip/ obj-$(CONFIG_PPP) += ppp/ obj-$(CONFIG_PPP_ASYNC) += ppp/ diff --git a/drivers/net/lora/Kconfig b/drivers/net/lora/Kconfig new file mode 100644 index 000000000000..40969b148a50 --- /dev/null +++ b/drivers/net/lora/Kconfig @@ -0,0 +1,18 @@ +# +# LoRa +# + +menu "LoRa Device Drivers" + +config LORA_DEV + tristate "LoRa drivers" + default y + help + LoRa ... + If unsure, say Y. + +# +# Alphabetically sorted. +# + +endmenu diff --git a/drivers/net/lora/Makefile b/drivers/net/lora/Makefile new file mode 100644 index 000000000000..8f9d25ea4e70 --- /dev/null +++ b/drivers/net/lora/Makefile @@ -0,0 +1,10 @@ +# +# LoRa +# + +obj-$(CONFIG_LORA_DEV) += lora-dev.o +lora-dev-y := dev.o + +# +# Alphabetically sorted. +# diff --git a/drivers/net/lora/dev.c b/drivers/net/lora/dev.c new file mode 100644 index 000000000000..8c01106008be --- /dev/null +++ b/drivers/net/lora/dev.c @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2017-2018 Andreas Färber + */ + +#include +#include +#include +#include +#include +#include +#include + +#define LORA_MTU 256 /* XXX */ + +struct sk_buff *alloc_lora_skb(struct net_device *dev, u8 **data) +{ + struct sk_buff *skb; + + skb = netdev_alloc_skb(dev, sizeof(struct lora_skb_priv) + LORA_MTU); + if (unlikely(!skb)) + return NULL; + + skb->protocol = htons(ETH_P_LORA); + skb->pkt_type = PACKET_BROADCAST; + skb->ip_summed = CHECKSUM_UNNECESSARY; + + skb_reset_mac_header(skb); + skb_reset_network_header(skb); + skb_reset_transport_header(skb); + + lora_skb_reserve(skb); + lora_skb_prv(skb)->ifindex = dev->ifindex; + + return skb; +} +EXPORT_SYMBOL_GPL(alloc_lora_skb); + +int open_loradev(struct net_device *dev) +{ + if (!netif_carrier_ok(dev)) + netif_carrier_on(dev); + + return 0; +} +EXPORT_SYMBOL_GPL(open_loradev); + +void close_loradev(struct net_device *dev) +{ +} +EXPORT_SYMBOL_GPL(close_loradev); + +static void lora_setup(struct net_device *dev) +{ + dev->type = ARPHRD_LORA; + dev->mtu = LORA_MTU; + dev->hard_header_len = 0; + dev->addr_len = 0; + dev->tx_queue_len = 10; + + dev->flags = IFF_NOARP; + dev->features = 0; +} + +struct net_device *alloc_loradev(int sizeof_priv) +{ + struct net_device *dev; + struct lora_priv *priv; + + dev = alloc_netdev(sizeof_priv, "lora%d", NET_NAME_UNKNOWN, lora_setup); + if (!dev) + return NULL; + + priv = netdev_priv(dev); + priv->dev = dev; + + return dev; +} +EXPORT_SYMBOL_GPL(alloc_loradev); + +void free_loradev(struct net_device *dev) +{ + free_netdev(dev); +} +EXPORT_SYMBOL_GPL(free_loradev); + +static struct rtnl_link_ops lora_link_ops __read_mostly = { + .kind = "lora", + .setup = lora_setup, +}; + +int register_loradev(struct net_device *dev) +{ + dev->rtnl_link_ops = &lora_link_ops; + return register_netdev(dev); +} +EXPORT_SYMBOL_GPL(register_loradev); + +void unregister_loradev(struct net_device *dev) +{ + unregister_netdev(dev); +} +EXPORT_SYMBOL_GPL(unregister_loradev); + +static int __init lora_dev_init(void) +{ + printk("lora-dev: init\n"); + + return rtnl_link_register(&lora_link_ops); +} + +static void __exit lora_dev_exit(void) +{ + printk("lora-dev: exit\n"); + + rtnl_link_unregister(&lora_link_ops); +} + +module_init(lora_dev_init); +module_exit(lora_dev_exit); + +MODULE_DESCRIPTION("LoRa device driver interface"); +MODULE_ALIAS_RTNL_LINK("lora"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Andreas Färber"); diff --git a/include/linux/lora/dev.h b/include/linux/lora/dev.h new file mode 100644 index 000000000000..531e68f0c9a6 --- /dev/null +++ b/include/linux/lora/dev.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * linux/lora/dev.h + * + * Copyright (c) 2017-2018 Andreas Färber + */ +#ifndef _LORA_DEV_H +#define _LORA_DEV_H + +#include + +struct net_device *alloc_loradev(int sizeof_priv); +void free_loradev(struct net_device *dev); +int register_loradev(struct net_device *dev); +void unregister_loradev(struct net_device *dev); +int open_loradev(struct net_device *dev); +void close_loradev(struct net_device *dev); + +struct lora_priv { + struct net_device *dev; +}; + +#endif /* _LORA_DEV_H */ diff --git a/net/lora/Kconfig b/net/lora/Kconfig index 44972ea8769f..20658fea3c7c 100644 --- a/net/lora/Kconfig +++ b/net/lora/Kconfig @@ -7,3 +7,9 @@ menuconfig LORA tristate "LoRa subsystem support" help LoRa ... + +if LORA + +source "drivers/net/lora/Kconfig" + +endif