Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4247587imu; Mon, 28 Jan 2019 21:03:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN4bN+WZOuMbOnGfzD984zQ1RBnAV3pwsZ2H33J0ggwqtOTAU8TdSr3UEwlnNSBXqLGmvXL2 X-Received: by 2002:a63:4c04:: with SMTP id z4mr22503637pga.312.1548738186375; Mon, 28 Jan 2019 21:03:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548738186; cv=none; d=google.com; s=arc-20160816; b=H+BDfGxVcvn6L7wwVGvKEBvgoHC/QqhjTu7fjrGtFwXAPM8YCVvKtX0lxCY/zxC+NW sBMBBmNsTaxa4IA73a9TBypNM1nPgvDyTxMelZx0QSWqBb/h30DC+fcvy/n35N8JKbmc GoSHlSkjr49acV+j+7vOv2/RiFt7M0NAuMeEfAuRdGVhbCpc1KXI6Ha9Aas0bl9WGjhH f+X4yA7V52V9FC5NRdD6qU8+yD16wFUVtezAvLvZH8hMJSBIsR3HrpJoJyTGUqEKv/XR saIFFfx47CsOOYzG4Tt+b/fxHOYSK97h5l1AjdliYBvorwqh0oyPYMOx9gse2crgrDQo JWcg== 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; bh=ze+i/52K7VHG68Cy8gTwTQLjEqt8BPol/g+8ZL6QUJA=; b=mpKczkB3kZcBvTqlqQU99y/XaLVSzRXtukP3HJMJ1CSzjORPAVdm3x+jAdi+EF5Cr6 /qf+p0cT377Hk99vgHvN9Xlqz7L54gkK9Ezajq7M6jnwlLwMq9V+yQQGu7eihbbCPsyJ +P6Y+iYmyXOB4CfsrhQ4+HgByjP2V+ckbpJZYWMSd3oTHGJBejztFDGGOvEW1D2pFfwA CCYUezT4mWyy8BAyvAKXcofUlTOJ6iohGo/ZWYXzV20BCEQiboFUhbyzKtmpbjNsqopm cvP9nraZtNCOXXSfmV25HbInFp69HoPjWY9lDqfmZ5+wATlo9z4ox15xouvN6nCGofTe SVjg== 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 o3si4727648pgm.441.2019.01.28.21.02.51; Mon, 28 Jan 2019 21:03:06 -0800 (PST) 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 S1726193AbfA2FBt (ORCPT + 99 others); Tue, 29 Jan 2019 00:01:49 -0500 Received: from mx2.suse.de ([195.135.220.15]:53342 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725294AbfA2FBo (ORCPT ); Tue, 29 Jan 2019 00:01:44 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 225BCADC8; Tue, 29 Jan 2019 05:01:42 +0000 (UTC) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: linux-lpwan@lists.infradead.org, linux-wpan@vger.kernel.org Cc: Alexander Aring , Stefan Schmidt , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, support@enocean.com, =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [RFC net-next 2/4] net: Prepare EnOcean device drivers Date: Tue, 29 Jan 2019 06:01:28 +0100 Message-Id: <20190129050130.10932-3-afaerber@suse.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190129050130.10932-1-afaerber@suse.de> References: <20190129050130.10932-1-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add net_device helpers for EnOcean. Signed-off-by: Andreas Färber --- drivers/net/enocean/Makefile | 2 + drivers/net/enocean/enocean.c | 124 ++++++++++++++++++++++++++++++++++++++++++ include/linux/enocean/dev.h | 23 ++++++++ 3 files changed, 149 insertions(+) create mode 100644 drivers/net/enocean/Makefile create mode 100644 drivers/net/enocean/enocean.c create mode 100644 include/linux/enocean/dev.h diff --git a/drivers/net/enocean/Makefile b/drivers/net/enocean/Makefile new file mode 100644 index 000000000000..efb3cd16c7f2 --- /dev/null +++ b/drivers/net/enocean/Makefile @@ -0,0 +1,2 @@ +obj-m += enocean-dev.o +enocean-dev-y := enocean.o diff --git a/drivers/net/enocean/enocean.c b/drivers/net/enocean/enocean.c new file mode 100644 index 000000000000..087a4de274c8 --- /dev/null +++ b/drivers/net/enocean/enocean.c @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * EnOcean net device + * + * Copyright (c) 2019 Andreas Färber + */ + +#include +#include +#include +#include +#include + +int open_enocean_dev(struct net_device *dev) +{ + if (!netif_carrier_ok(dev)) + netif_carrier_on(dev); + + return 0; +} +EXPORT_SYMBOL_GPL(open_enocean_dev); + +void close_enocean_dev(struct net_device *dev) +{ +} +EXPORT_SYMBOL_GPL(close_enocean_dev); + +static void enocean_setup(struct net_device *dev) +{ + dev->type = ARPHRD_ENOCEAN; + dev->mtu = 255; /* XXX */ + dev->hard_header_len = 0; + dev->addr_len = 0; /* XXX 4 */ + dev->tx_queue_len = 10; + + dev->flags = IFF_NOARP; + dev->features = 0; +} + +struct net_device *alloc_enocean_dev(size_t priv_size) +{ + struct enocean_dev_priv *priv; + struct net_device *netdev; + + netdev = alloc_netdev(priv_size, "enocean%d", NET_NAME_UNKNOWN, enocean_setup); + if (!netdev) + return NULL; + + priv = netdev_priv(netdev); + priv->dev = netdev; + + return netdev; +} +EXPORT_SYMBOL_GPL(alloc_enocean_dev); + +void free_enocean_dev(struct net_device *netdev) +{ + free_netdev(netdev); +} +EXPORT_SYMBOL_GPL(free_enocean_dev); + +static void devm_free_enocean_dev(struct device *dev, void *res) +{ + struct net_device **net = res; + + free_enocean_dev(*net); +} + +struct net_device *devm_alloc_enocean_dev(struct device *dev, size_t priv) +{ + struct net_device **ptr; + struct net_device *net; + + net = alloc_enocean_dev(priv); + if (!net) + return NULL; + + ptr = devres_alloc(devm_free_enocean_dev, sizeof(*ptr), GFP_KERNEL); + if (!ptr) { + free_enocean_dev(net); + return NULL; + } + + *ptr = net; + devres_add(dev, ptr); + + return net; +} +EXPORT_SYMBOL_GPL(devm_alloc_enocean_dev); + +static struct rtnl_link_ops enocean_link_ops __read_mostly = { + .kind = "enocean", + .setup = enocean_setup, +}; + +int register_enocean_dev(struct net_device *dev) +{ + dev->rtnl_link_ops = &enocean_link_ops; + return register_netdev(dev); +} +EXPORT_SYMBOL_GPL(register_enocean_dev); + +void unregister_enocean_dev(struct net_device *dev) +{ + unregister_netdev(dev); +} +EXPORT_SYMBOL_GPL(unregister_enocean_dev); + +static int __init enocean_dev_init(void) +{ + return rtnl_link_register(&enocean_link_ops); +} +module_init(enocean_dev_init); + +static void __exit enocean_dev_exit(void) +{ + rtnl_link_unregister(&enocean_link_ops); +} +module_exit(enocean_dev_exit); + +MODULE_DESCRIPTION("EnOcean device driver interface"); +MODULE_ALIAS_RTNL_LINK("enocean"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Andreas Färber"); diff --git a/include/linux/enocean/dev.h b/include/linux/enocean/dev.h new file mode 100644 index 000000000000..be9d37cdde37 --- /dev/null +++ b/include/linux/enocean/dev.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * linux/enocean/dev.h + * + * Copyright (c) 2019 Andreas Färber + */ +#ifndef _ENOCEAN_DEV_H +#define _ENOCEAN_DEV_H + +#include + +struct net_device *alloc_enocean_dev(size_t priv_size); +struct net_device *devm_alloc_enocean_dev(struct device *dev, size_t priv_size); +int register_enocean_dev(struct net_device *netdev); +void unregister_enocean_dev(struct net_device *netdev); +int open_enocean_dev(struct net_device *netdev); +void close_enocean_dev(struct net_device *netdev); + +struct enocean_dev_priv { + struct net_device *dev; +}; + +#endif -- 2.16.4