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: 10498631 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A0F2960284 for ; Sun, 1 Jul 2018 11:11:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91C65285EB for ; Sun, 1 Jul 2018 11:11:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8556328708; Sun, 1 Jul 2018 11:11:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0D864285EB for ; Sun, 1 Jul 2018 11:11:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BfWKt+CbHydcYoCyP4AfjXcDIhOsiI/uSOJVd13hhvk=; b=iUklGCbnLuFvbR zjmhAW59TN/zgcn/7OoAMemLXgbkrrYSWBpd2Xb4Neto1BKZcsBN5F0ZUC+2keFK4zIFt+6fTRyAi i9hEJzoUYLuzKoP79E+wsFF6nTv7pTzbRSxA0/7cg2FJi4HWEa9fXjZhCybdSmWRkbojKT7qE5weC 19dmptJZLrTSnlHfK0PFoINWy3WfLppzwnEWkyseWc3Ql66KpuF+eMDANxicKccirabfqpvFec1bZ g+39BxZtUUvO7qjSXDrfgI9O7ShGFnBTZoHdRra3JBV63y1nW5fx+cPBPyWkqs/4kd5+qBvOpDXAL 8OLLWKI+p+ISciyCgJ+w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fZaGc-0006xT-JZ; Sun, 01 Jul 2018 11:11:42 +0000 Received: from mx2.suse.de ([195.135.220.15] helo=mx1.suse.de) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fZaEP-0004XU-8e for linux-arm-kernel@lists.infradead.org; Sun, 01 Jul 2018 11:09:33 +0000 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=20F=C3=A4rber?= To: netdev@vger.kernel.org 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180701_040926_076214_CBD0ED23 X-CRM114-Status: GOOD ( 14.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Matthias Brugger , Jiri Pirko , Marcel Holtmann , Dollar Chen , linux-kernel@vger.kernel.org, =?UTF-8?q?Michael=20R=C3=B6der?= , Janus Piwek , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Jian-Hong Pan , Ken Yu , "David S . Miller" , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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