From patchwork Tue Jan 29 05:01:28 2019 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: 156922 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4228733jaa; Mon, 28 Jan 2019 21:01:48 -0800 (PST) X-Google-Smtp-Source: ALg8bN7zmfw5CDNoDF8llB+0wDaIHmHDasdqQ5o82nE6W7PXemzMfThzPiAzpsIdRBf8Khb9WHc0 X-Received: by 2002:a62:26c7:: with SMTP id m190mr25117817pfm.79.1548738108821; Mon, 28 Jan 2019 21:01:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548738108; cv=none; d=google.com; s=arc-20160816; b=vFUn5EelMcc3zaA5L/qmrY2y9zFX1ZPOnZ7RG8JDqNyxQKodaQUxfLW5NfhhCUyDld ae8cRApAHQzPMrv5DMT82O/Zm3T3fqO4Gl+E3xwXXTTiIyhM8HX34X8LVlZ/f7NMAIU8 O/odxgHXFhlFHT70jR1enu4G1BoJf5FWnlkuhmkXyUQv1dh33SWS+d57vTp3fTMBOOeR Rt0ddUOtX1Pj7+J5QHR0inf8GeMIXPYPdqzdcl29paLfrmJLwMAuDITfYpK3rZKhAXSt VaqnRiGE/BzNuZFo2EbZdnMh43OVnfKvX1J30Lh7gLiH+VidrTPzWXu2kjRYyvUErCPO RLaA== 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=nx3/dM+SfwEO9SqoYQ+VoH+HjqfVSJwku3AHuAbH1+MYOV/82EqJBKgJQWi40pM76m p1XdBJc8IxlK2fKCU/3PsRMG3cd02vRYSekVEyNoqbNIoU0gM0iFku4unZaKTIiB7XXx QhrpkRrKVxOFb+Xw/NxvP/IDxt+EsWpF7sxO05zuWqsp4HggCSFiRo4Ehq+AReet0oQy mKWbfqgkTSw+otvLJ1plIUbnwQRpHKhksb4a29KuIhYF2xwL/fYi9TlyKF404PEoBqA+ wp6AAxKnhJit4BlVHXMhseOORGCWO7ww0yUJRfRSa5p/Xd2CWPcIrInHW1wzZ4/UZNOy ZZSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 r29si1013299pga.477.2019.01.28.21.01.48; Mon, 28 Jan 2019 21:01:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of netdev-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 netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725267AbfA2FBq (ORCPT + 10 others); Tue, 29 Jan 2019 00:01:46 -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_F=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_F=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 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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 -- 2.16.4 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