From patchwork Sun Jul 1 11:07:50 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: 140711 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2850753ljj; Sun, 1 Jul 2018 04:13:29 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJthdVzpMPCfFZNrHyZyAPzuMcnxxkAZUmXnRpjEcPHpWD+/yHdO0cZCKIfo1RXIMIvet09 X-Received: by 2002:a17:902:b08d:: with SMTP id p13-v6mr21717854plr.344.1530443609226; Sun, 01 Jul 2018 04:13:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530443609; cv=none; d=google.com; s=arc-20160816; b=dgwaOxuoQ4qVgVzicbvVT2lcJwzQPn13jmgHjxVwT6pMNmSkPNV2yD7gT9bCxXQlMC 8ev0mUOzKlhm5lTmFjy2tlHYe+ophhZxYIK516xlg5sbei6MowAciweSuwpMW/S4blKh Cj2J/A0uf3/g37+XmQ1Th5QwWkLvDOJBiwzPhyF7iZ76r3nnoHdyZLP5Nj17h4j/FCXl 0IMFo+ZFeMHIYsC6K/pUgqlMdnc3tUzDPPeIOzj3BnZErieyA4xLJafsKVGASxr5qinW h3uYLZV3OqzCsrd03lqPTaaVn48jqItnAfoxfSSbcwGzVVLUrQZ+w9YPyfbmkr6h5Ic3 YiUg== 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=SnBjGgHwy6bFzIRl66ufncbnlwOqkOlB2e460Qd7CIw=; b=gAPjlq5ecJslsCs/scIDudGe4yg2JbYycHulwauA7o8BuzWZQyQGTMfcMhNJRHJOlz snGHBenfEAjtZHFXUJObv+IhT1PLbgW9PdGBJV8yPAveoVsv393CGraDFVmdCfDhb5+T wkIZKjpdBBG08pYSB/t0Rzf6sxwsYymarvLPbB9L2gVjWEk7tDECnEA1QnwYNmi3xnNj gFzA1N6zDOjsyEexhiF1QP8UAkhP6TQDbvr5caRrbUi16hngbeHRYfOd3xXnng9ZyuHG OtrkDLGi0FHmQGZXK4N/okjgoeHmprJNGOw2ftbpfCATIIhsC8NeLWjgY4gnX0iVk/lz dh8A== 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 a21-v6si13219161pls.237.2018.07.01.04.13.28; Sun, 01 Jul 2018 04:13:29 -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 S1752756AbeGALM5 (ORCPT + 31 others); Sun, 1 Jul 2018 07:12:57 -0400 Received: from mx2.suse.de ([195.135.220.15]:47740 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752039AbeGALI7 (ORCPT ); Sun, 1 Jul 2018 07:08:59 -0400 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 7BAEDAE53; Sun, 1 Jul 2018 11:08:57 +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?= , Paul Moore , Stephen Smalley , Eric Paris , selinux@tycho.nsa.gov Subject: [RFC net-next 01/15] net: Reserve protocol numbers for LoRa Date: Sun, 1 Jul 2018 13:07:50 +0200 Message-Id: <20180701110804.32415-2-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 LoRa is a long-range, low-power wireless network technology by Semtech. It serves as base for LoRaWAN as well as multiple proprietary protocols. AF_LORA PF_LORA ARPHRD_LORA ETH_P_LORA Signed-off-by: Andreas Färber --- include/linux/socket.h | 4 +++- include/uapi/linux/if_arp.h | 1 + include/uapi/linux/if_ether.h | 1 + security/selinux/hooks.c | 4 +++- security/selinux/include/classmap.h | 4 +++- 5 files changed, 11 insertions(+), 3 deletions(-) -- 2.16.4 diff --git a/include/linux/socket.h b/include/linux/socket.h index 7ed4713d5337..aa1e288b1659 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -208,8 +208,9 @@ struct ucred { * reuses AF_INET address family */ #define AF_XDP 44 /* XDP sockets */ +#define AF_LORA 45 /* LoRa sockets */ -#define AF_MAX 45 /* For now.. */ +#define AF_MAX 46 /* For now.. */ /* Protocol families, same as address families. */ #define PF_UNSPEC AF_UNSPEC @@ -259,6 +260,7 @@ struct ucred { #define PF_QIPCRTR AF_QIPCRTR #define PF_SMC AF_SMC #define PF_XDP AF_XDP +#define PF_LORA AF_LORA #define PF_MAX AF_MAX /* Maximum queue length specifiable by listen. */ diff --git a/include/uapi/linux/if_arp.h b/include/uapi/linux/if_arp.h index 4605527ca41b..1ed7cb3f2129 100644 --- a/include/uapi/linux/if_arp.h +++ b/include/uapi/linux/if_arp.h @@ -98,6 +98,7 @@ #define ARPHRD_NETLINK 824 /* Netlink header */ #define ARPHRD_6LOWPAN 825 /* IPv6 over LoWPAN */ #define ARPHRD_VSOCKMON 826 /* Vsock monitor header */ +#define ARPHRD_LORA 827 /* LoRa */ #define ARPHRD_VOID 0xFFFF /* Void type, nothing is known */ #define ARPHRD_NONE 0xFFFE /* zero header length */ diff --git a/include/uapi/linux/if_ether.h b/include/uapi/linux/if_ether.h index 3a45b4ad71a3..45644dcf5b39 100644 --- a/include/uapi/linux/if_ether.h +++ b/include/uapi/linux/if_ether.h @@ -147,6 +147,7 @@ #define ETH_P_MAP 0x00F9 /* Qualcomm multiplexing and * aggregation protocol */ +#define ETH_P_LORA 0x00FA /* LoRa */ /* * This is an Ethernet frame header. diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 10a5d2ce3870..b62bb0389d70 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -1473,7 +1473,9 @@ static inline u16 socket_type_to_security_class(int family, int type, int protoc return SECCLASS_SMC_SOCKET; case PF_XDP: return SECCLASS_XDP_SOCKET; -#if PF_MAX > 45 + case PF_LORA: + return SECCLASS_LORA_SOCKET; +#if PF_MAX > 46 #error New address family defined, please update this function. #endif } diff --git a/security/selinux/include/classmap.h b/security/selinux/include/classmap.h index bd5fe0d3204a..060d4bf8385e 100644 --- a/security/selinux/include/classmap.h +++ b/security/selinux/include/classmap.h @@ -242,9 +242,11 @@ struct security_class_mapping secclass_map[] = { {"map_create", "map_read", "map_write", "prog_load", "prog_run"} }, { "xdp_socket", { COMMON_SOCK_PERMS, NULL } }, + { "lora_socket", + { COMMON_SOCK_PERMS, NULL } }, { NULL } }; -#if PF_MAX > 45 +#if PF_MAX > 46 #error New address family defined, please update secclass_map. #endif From patchwork Sun Jul 1 11:07:51 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: 140708 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2850382ljj; Sun, 1 Jul 2018 04:12:56 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKlAk1pLe/j0/x9vTxvFprVKE80YrnpfLzClG22eQ1RPJshM4oFIMYoI/Z3AVSATdRviIO8 X-Received: by 2002:a65:64c6:: with SMTP id t6-v6mr18392625pgv.223.1530443576006; Sun, 01 Jul 2018 04:12:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530443575; cv=none; d=google.com; s=arc-20160816; b=r/rGCQ+AIBLxEN+u9lkVALrivgI9yVCL3gIXLXB/4Vi2gfub/UQvIoa+enf834lzzr ywIfJoR9Wj91LXNlVPXTQz4tAbU5Z7xac0SKMhEERW9QkgZ1iLzFDO8hXFBMe2TpqGNv yufELxkn/KZCDZ9nHsY7LmXiwEyASxrT4mnFdXEYodAEqKfMDd+N3DgPtOVQrL87rXUf PARHVkiGXKSf32gZxm8cqtjtW1uENuewVIuTwtpNjHXUMtAFutD7YQMbj5oagGpqvM0p ZbYidOpiJqF2tFT0/sP+wv2+wJG6O44oonRAFw0ZhZJ2mslHpoFYuAV05T6WGKLneRNu OBlw== 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=w2nQtwCeEZhezQkCR9ABvpRzJx4OeaIuwaCyU8gdC6g=; b=AQQePFe4P29Vs2pFLFRd9OJUr6+bla7EQ6FMaXhDW9m/gEalht3PCRCZhyedoCDk+n sFoHC3JDVF8A63S4MoYbaKNcqt/jnSb6/5j8vBhN1NbDziM9hp9S1FoiOT5bUDo82uDt YAZRa5vNyMr0UAWQfWfYDCr2m5x3WrHCVRlQc0MF4Dmr3cdOa2+UdrS1JMmDH14rlLQY vbIjECm1Bc8ab9jWxgnKFoAIj7gsAg8wQJmp5M5pnapyVf+vsRn4+VXB0+Ji4PHH0LEy 7I6jrWkVo7ge6BCkL31XtSm4IGpBgQH0ZFXJG4vHEhhQlUTOVWWc2YUaoDxLZw/BAjzQ OUjA== 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.55; Sun, 01 Jul 2018 04:12:55 -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 S1752724AbeGALMy (ORCPT + 31 others); Sun, 1 Jul 2018 07:12:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:47766 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752082AbeGALI7 (ORCPT ); Sun, 1 Jul 2018 07:08:59 -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 78657AE0B; Sun, 1 Jul 2018 11:08:57 +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 02/15] net: lora: Define sockaddr_lora Date: Sun, 1 Jul 2018 13:07:51 +0200 Message-Id: <20180701110804.32415-3-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 Prepare a uapi linux/lora.h header defining sockaddr_lora for AF_LORA. Signed-off-by: Andreas Färber --- include/uapi/linux/lora.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 include/uapi/linux/lora.h -- 2.16.4 diff --git a/include/uapi/linux/lora.h b/include/uapi/linux/lora.h new file mode 100644 index 000000000000..9368e8a84f3a --- /dev/null +++ b/include/uapi/linux/lora.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: (GPL-2.0-or-later WITH Linux-syscall-note) */ +/* + * linux/lora.h + * + * Copyright (c) 2017-2018 Andreas Färber + */ +#ifndef _UAPI_LINUX_LORA_H +#define _UAPI_LINUX_LORA_H + +#include +#include + +struct sockaddr_lora { + __kernel_sa_family_t lora_family; + int lora_ifindex; + union { + } lora_addr; +}; + +#endif /* _UAPI_LINUX_LORA_H */ From patchwork Sun Jul 1 11:07:52 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: 140696 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2847416ljj; Sun, 1 Jul 2018 04:09:15 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLG9jP3+XTQN8LYvjXGnzPsqlZe0r5sOsZ8Nt+d//xPwgLjROdKaIUsCzTTKaMTiDKXPzp8 X-Received: by 2002:a17:902:28a6:: with SMTP id f35-v6mr21813349plb.110.1530443355373; Sun, 01 Jul 2018 04:09:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530443355; cv=none; d=google.com; s=arc-20160816; b=LpGe5rG81c+o8aNcyhRQO98505py7NJE7f/WBH2ZBnpVAEvqLj0UcV+e1am5E3V9VK F2IaWEty+BBlKTAVSC4dHR6IfTLlZmKniKSrpYkoDBRHowUSHkXu5eabekly5fDULzNn YAtVMpbp6pZbtqPxLwBzMlU0BXGUUM3OzJ8c21ggTpxzNHB4X4YhModmj2dCTaBSRcKQ CzPh/2G15Iy8n1cxQByB40gJz8qJKa+YfdEjoOUXP+3oy6y5tDUXVbLXMOW+faeljpxo CfUqnmWTFGNHecT8f7ZKkCvahYuyCFs/FJgcS4T/Ne9K5m1jGPlFVyRR1Jq9v+IpshDF LnbQ== 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=BP9HHyg7i2eQb8D1YdCpsMm24PNvps5gwXNYMbRHD2c=; b=bPpCNpKiKtlLS+FEaXwfIygMv27vXi71s52U37QL0p5SqkEJI33PxteHX41fkqV5Hs NTf9Fy94Gboum1r7OE1FCjvAemDQ8DMSz4+KOQICY+70R4chgAU0L+UktpXiE+tnMUNa Tu/X/xO0jOGnIf6x8fPnWuKprDUlGziss6mBJ6d/JcKp6pEc05cOWrVejeXrK7yoK06B n1py51QLUoulLoxAXB5vNeabddYecQuFY+CDa/tfvCuzS6hatx3yuhtxwSZJmDIEaC41 IGdod038KGgcWUPTBGi/P4Qb4v2hYkPNfitS2ZG/SnUssAfkWG23RhmZC9jtRYalrSkh PSUg== 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 l26-v6si11251445pgu.191.2018.07.01.04.09.14; Sun, 01 Jul 2018 04:09: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 S1752326AbeGALJC (ORCPT + 31 others); Sun, 1 Jul 2018 07:09:02 -0400 Received: from mx2.suse.de ([195.135.220.15]:47690 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751909AbeGALI7 (ORCPT ); Sun, 1 Jul 2018 07:08:59 -0400 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 787A0AE3F; Sun, 1 Jul 2018 11:08:57 +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 03/15] net: lora: Add protocol numbers Date: Sun, 1 Jul 2018 13:07:52 +0200 Message-Id: <20180701110804.32415-4-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 Default protocol implementation will be datagram. No other protocols are implemented yet. Q: Would these protocol numbers be the suitable place to define LoRaWAN? Signed-off-by: Andreas Färber --- include/uapi/linux/lora.h | 4 ++++ 1 file changed, 4 insertions(+) -- 2.16.4 diff --git a/include/uapi/linux/lora.h b/include/uapi/linux/lora.h index 9368e8a84f3a..4ff00b9c3c20 100644 --- a/include/uapi/linux/lora.h +++ b/include/uapi/linux/lora.h @@ -10,6 +10,10 @@ #include #include +/* particular protocols of the protocol family PF_LORA */ +#define LORA_PROTO_DATAGRAM 0 +#define LORA_NPROTO 1 + struct sockaddr_lora { __kernel_sa_family_t lora_family; int lora_ifindex; 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 From patchwork Sun Jul 1 11:07:57 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: 140698 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2847453ljj; Sun, 1 Jul 2018 04:09:17 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIdEtpiFQKzydvF/sqJxHWlkHMlLDKpcv69NMBJF42JGuQRuOIAjhURLdKVwS2XQvuV6/to X-Received: by 2002:a17:902:8f8e:: with SMTP id z14-v6mr21645491plo.139.1530443357157; Sun, 01 Jul 2018 04:09:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530443357; cv=none; d=google.com; s=arc-20160816; b=S0OH2srAYw6KqVeH+nSmcHiRNPu4B3evIUh1fqX/9pf9/6I82vWH5ox7G2HbSFqXaP G2x1wITHnTsNzAmqBR9WBceXJ9xOXHr/Nv4afq0VjAglLud4fYkW+DGt9KAiTHdyV3k8 5RIn3cVgBdv0LK1I6JYjZ+g9HCeTxu71kcsTGlnnmMefVjxs56DqZSaBSEBJQv/x+fgw HYIiS1oZYNaFhtXiGRsPkcOxwhTdKUltcx71ZzSD+jBk7GBKmElEEMq31l5ttZu2+gvm DHNjjIteygqDcswK9O5uw9vxHsNU4bQvokcvpGYF1buqjjwpbze5HRFh1RYThtQizTP7 NNQw== 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=CtvqvVkDp3Lh2iRV41eD7XR2PaZZzTZn6vmw8wN2ms0=; b=UGuSDnTU0wLExn3HYTWF1QP76jhdAbG9tkMRdM6rpOT6uzBhZGoX7QGqt8yFyHTxcT VKgP3pxiUusGHKpBWON3WhZb9X2LEvNU7cXlvXGOggxVh8oxMqdSFnYdze93XQZ/5Y9H P3HUNC65C11mlMpSNyhpyEsELEFcuNlfTomt7m+21s4jmiRH6+LtX7PnC0gD72E7pedd UZi+Pa2JKSNgBFA+PMDWGhVQL/RDHxf1NX7p/9YpncNDQONb2y21HmyRtKRLBvijEpKB jjm5dliRiFDgr+VuC83bqyJGL3lE3WN7fp6NDYzPOZOaGG8cf7Eg82VQSyXs1oWooCCy dt0g== 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 l26-v6si11251445pgu.191.2018.07.01.04.09.16; Sun, 01 Jul 2018 04:09:17 -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 S1752433AbeGALJN (ORCPT + 31 others); Sun, 1 Jul 2018 07:09:13 -0400 Received: from mx2.suse.de ([195.135.220.15]:47844 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752293AbeGALJC (ORCPT ); Sun, 1 Jul 2018 07:09:02 -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 77AE8AF53; Sun, 1 Jul 2018 11:08:59 +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 08/15] net: lora: sx1276: Add debugfs Date: Sun, 1 Jul 2018 13:07:57 +0200 Message-Id: <20180701110804.32415-9-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 Allow some interactive inspection at runtime via debugfs. Signed-off-by: Andreas Färber --- drivers/net/lora/sx1276.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) -- 2.16.4 diff --git a/drivers/net/lora/sx1276.c b/drivers/net/lora/sx1276.c index d6732111247a..1072019cfcc1 100644 --- a/drivers/net/lora/sx1276.c +++ b/drivers/net/lora/sx1276.c @@ -5,6 +5,7 @@ * Copyright (c) 2016-2018 Andreas Färber */ +#include #include #include #include @@ -61,6 +62,8 @@ struct sx1276_priv { struct workqueue_struct *wq; struct work_struct tx_work; + + struct dentry *debugfs; }; static int sx1276_read_single(struct spi_device *spi, u8 reg, u8 *val) @@ -416,6 +419,128 @@ static const struct net_device_ops sx1276_netdev_ops = { .ndo_start_xmit = sx1276_loradev_start_xmit, }; +static ssize_t sx1276_freq_read(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct net_device *netdev = file->private_data; + struct sx1276_priv *priv = netdev_priv(netdev); + struct spi_device *spi = priv->spi; + ssize_t size; + char *buf; + int ret; + u8 msb, mid, lsb; + u32 freq_xosc; + unsigned long long frf; + + ret = of_property_read_u32(spi->dev.of_node, "clock-frequency", &freq_xosc); + if (ret) + return 0; + + mutex_lock(&priv->spi_lock); + + ret = sx1276_read_single(spi, REG_FRF_MSB, &msb); + if (!ret) + ret = sx1276_read_single(spi, REG_FRF_MID, &mid); + if (!ret) + ret = sx1276_read_single(spi, REG_FRF_LSB, &lsb); + + mutex_unlock(&priv->spi_lock); + + if (ret) + return 0; + + frf = freq_xosc; + frf *= ((ulong)msb << 16) | ((ulong)mid << 8) | lsb; + frf /= (1 << 19); + + buf = kasprintf(GFP_KERNEL, "%llu\n", frf); + if (!buf) + return 0; + + size = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); + kfree(buf); + + return size; +} + +static const struct file_operations sx1276_freq_fops = { + .owner = THIS_MODULE, + .open = simple_open, + .read = sx1276_freq_read, +}; + +static ssize_t sx1276_state_read(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct net_device *netdev = file->private_data; + struct sx1276_priv *priv = netdev_priv(netdev); + struct spi_device *spi = priv->spi; + ssize_t size; + char *buf; + int len = 0; + int ret; + u8 val; + bool lora_mode = true; + const int max_len = 4096; + + buf = kzalloc(max_len, GFP_KERNEL); + if (!buf) + return 0; + + mutex_lock(&priv->spi_lock); + + ret = sx1276_read_single(spi, REG_OPMODE, &val); + if (!ret) { + len += snprintf(buf + len, max_len - len, "RegOpMode = 0x%02x\n", val); + lora_mode = (val & REG_OPMODE_LONG_RANGE_MODE) != 0; + } + + ret = sx1276_read_single(spi, REG_FRF_MSB, &val); + if (!ret) + len += snprintf(buf + len, max_len - len, "RegFrMsb = 0x%02x\n", val); + ret = sx1276_read_single(spi, REG_FRF_MID, &val); + if (!ret) + len += snprintf(buf + len, max_len - len, "RegFrMid = 0x%02x\n", val); + ret = sx1276_read_single(spi, REG_FRF_LSB, &val); + if (!ret) + len += snprintf(buf + len, max_len - len, "RegFrLsb = 0x%02x\n", val); + + ret = sx1276_read_single(spi, REG_PA_CONFIG, &val); + if (!ret) + len += snprintf(buf + len, max_len - len, "RegPaConfig = 0x%02x\n", val); + + if (lora_mode) { + ret = sx1276_read_single(spi, LORA_REG_IRQ_FLAGS_MASK, &val); + if (!ret) + len += snprintf(buf + len, max_len - len, "RegIrqFlagsMask = 0x%02x\n", val); + + ret = sx1276_read_single(spi, LORA_REG_IRQ_FLAGS, &val); + if (!ret) + len += snprintf(buf + len, max_len - len, "RegIrqFlags = 0x%02x\n", val); + + ret = sx1276_read_single(spi, LORA_REG_SYNC_WORD, &val); + if (!ret) + len += snprintf(buf + len, max_len - len, "RegSyncWord = 0x%02x\n", val); + } + + ret = sx1276_read_single(spi, REG_PA_DAC, &val); + if (!ret) + len += snprintf(buf + len, max_len - len, "RegPaDac = 0x%02x\n", val); + + mutex_unlock(&priv->spi_lock); + + size = simple_read_from_buffer(user_buf, count, ppos, buf, len); + kfree(buf); + + return size; +} + +static const struct file_operations sx1276_state_fops = { + .owner = THIS_MODULE, + .open = simple_open, + .read = sx1276_state_read, +}; + static int sx1276_probe(struct spi_device *spi) { struct net_device *netdev; @@ -566,6 +691,10 @@ static int sx1276_probe(struct spi_device *spi) return ret; } + priv->debugfs = debugfs_create_dir(dev_name(&spi->dev), NULL); + debugfs_create_file("state", S_IRUGO, priv->debugfs, netdev, &sx1276_state_fops); + debugfs_create_file("frequency", S_IRUGO, priv->debugfs, netdev, &sx1276_freq_fops); + dev_info(&spi->dev, "SX1276 module probed (SX%d)", model); return 0; @@ -574,6 +703,9 @@ static int sx1276_probe(struct spi_device *spi) static int sx1276_remove(struct spi_device *spi) { struct net_device *netdev = spi_get_drvdata(spi); + struct sx1276_priv *priv = netdev_priv(netdev); + + debugfs_remove_recursive(priv->debugfs); unregister_loradev(netdev); free_loradev(netdev); From patchwork Sun Jul 1 11:08:00 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: 140704 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2848704ljj; Sun, 1 Jul 2018 04:10:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIXcgXr2nhwdOFJQFo2vFr9joEBoeOxydX1nWq+db6v2kdrnijcvY+ETWZBTrfYz9Np8YXG X-Received: by 2002:a17:902:650a:: with SMTP id b10-v6mr22154800plk.45.1530443437387; Sun, 01 Jul 2018 04:10:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530443437; cv=none; d=google.com; s=arc-20160816; b=Bmp5opj4Wsj10mWwqxDBmt/rlMpkOkzGoqL1WKYO33WA3JpWai7Qtd5IDOYuVx5vAp 07xRAK3B7lzjCYWN+yElkbKs2h4gHZo14XgG0liKkR61dZnzq8NTX6sbsSZM1rqkF3Ln hPa7JBVQNgn95t5doMwIJ+t+Y1U90ZmhottUDzDhB0KF4VqfA/O9NbRM1KVdIm1pjoeF 7CntPvJFsHc3+RqTXjWaoOd2f8VtKCStQ3yFsXpX4DJ8pRNhYUcZxDqXssxZJhISTep1 9VL8nya5w30TPDChyYz+C1ViX2oXa+DBAyKoD0T6lGAPQa7bBzZ9O+CdKVkYyMH4h1zP ooeA== 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=EiByaCrSpSmESH5UOj84bivCzsNuZyONvKoALmn4KqI=; b=OHLCmLj0wfXYQSEcwOriCYlne6nUd2gfqLyUgYiuq1A/j8Kdmt4G6DV+tbthN+DueY 230QWbkNCUbhO4r8VLyhmWjacJS8u3kHxlC1jKSAsaqrFA6mChxgOqYo7yttHtTc9uRA vqyESpsn0L2jW872puYb3Mnfw5GkXxK+iF1GNsYV9KI6VgpJYBOOf/mvAGQniNJQl0l+ L3Cd2Wued6ARTet6OuRCgP8z2hWBByejzm9DKjPKjm6/b6NzgYzTBFcYqhd/bI8/Vnt7 mdv7y3654x3yXlpE7Ga/PJH4F4yEpOOlvn68quSbK0XnVKq6buRiHQ/crBEajqBYwyNe TK7w== 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 x125-v6si14371658pfb.237.2018.07.01.04.10.37; Sun, 01 Jul 2018 04:10:37 -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 S1752694AbeGALKe (ORCPT + 31 others); Sun, 1 Jul 2018 07:10:34 -0400 Received: from mx2.suse.de ([195.135.220.15]:47936 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752328AbeGALJD (ORCPT ); Sun, 1 Jul 2018 07:09:03 -0400 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 89CB7AFA3; Sun, 1 Jul 2018 11:09:01 +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?= , Jon Ortego Subject: [RFC net-next 11/15] net: lora: Add IMST WiMOD Date: Sun, 1 Jul 2018 13:08:00 +0200 Message-Id: <20180701110804.32415-12-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 The IMST WiMOD uses a SLIP based binary UART protocol. Two separate firmwares are available. By default it ships with a LoRaWAN firmware. The alternative firmware is a custom P2P addressing mode based on LoRa. Cc: Jon Ortego Signed-off-by: Andreas Färber --- drivers/net/lora/Kconfig | 8 + drivers/net/lora/Makefile | 3 + drivers/net/lora/wimod.c | 597 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 608 insertions(+) create mode 100644 drivers/net/lora/wimod.c -- 2.16.4 diff --git a/drivers/net/lora/Kconfig b/drivers/net/lora/Kconfig index 940bd2cbe106..2e05caef8645 100644 --- a/drivers/net/lora/Kconfig +++ b/drivers/net/lora/Kconfig @@ -31,6 +31,14 @@ config LORA_SX1276 help Semtech SX1272/1276/1278 +config LORA_WIMOD + tristate "IMST WiMOD driver" + default y + depends on SERIAL_DEV_BUS + select CRC_CCITT + help + IMST WiMOD + endif endmenu diff --git a/drivers/net/lora/Makefile b/drivers/net/lora/Makefile index 07839c3ce9f8..ecb326c859a5 100644 --- a/drivers/net/lora/Makefile +++ b/drivers/net/lora/Makefile @@ -15,3 +15,6 @@ lora-rn2483-y += rn2483_cmd.o obj-$(CONFIG_LORA_SX1276) += lora-sx1276.o lora-sx1276-y := sx1276.o + +obj-$(CONFIG_LORA_WIMOD) += lora-wimod.o +lora-wimod-y := wimod.o diff --git a/drivers/net/lora/wimod.c b/drivers/net/lora/wimod.c new file mode 100644 index 000000000000..a70d5a6dc7c4 --- /dev/null +++ b/drivers/net/lora/wimod.c @@ -0,0 +1,597 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * IMST WiMOD + * + * Copyright (c) 2017-2018 Andreas Färber + */ + +#include +#include +#include +#include +#include +#include +#include + +#define WIMOD_HCI_PAYLOAD_MAX 300 +#define WIMOD_HCI_PACKET_MAX (1 + (2 + WIMOD_HCI_PAYLOAD_MAX + 2) * 2 + 1) + +struct wimod_device { + struct serdev_device *serdev; + + u8 rx_buf[WIMOD_HCI_PACKET_MAX]; + int rx_len; + bool rx_esc; + struct list_head packet_dispatchers; +}; + +#define SLIP_END 0300 +#define SLIP_ESC 0333 +#define SLIP_ESC_END 0334 +#define SLIP_ESC_ESC 0335 + +static inline void slip_print_bytes(const u8* buf, int len) +{ + int i; + + for (i = 0; i < len; i++) + printk("%02x ", buf[i]); +} + +static int slip_send_end(struct serdev_device *sdev, unsigned long timeout) +{ + u8 val = SLIP_END; + + return serdev_device_write(sdev, &val, 1, timeout); +} + +#if 0 +static int slip_send_data(struct serdev_device *sdev, const u8 *buf, int len, + unsigned long timeout) +{ + int last_idx = -1; + int i; + u8 esc[2] = { SLIP_ESC, 0 }; + int ret; + + for (i = 0; i < len; i++) { + if (buf[i] != SLIP_END && + buf[i] != SLIP_ESC) + continue; + + slip_print_bytes(&buf[last_idx + 1], i - (last_idx + 1)); + + ret = serdev_device_write(sdev, + &buf[last_idx + 1], i - (last_idx + 1), timeout); + if (ret) + return ret; + + switch (buf[i]) { + case SLIP_END: + esc[1] = SLIP_ESC_END; + break; + case SLIP_ESC: + esc[1] = SLIP_ESC_ESC; + break; + } + slip_print_bytes(esc, 2); + ret = serdev_device_write(sdev, esc, 2, timeout); + if (ret) + return ret; + + last_idx = i; + } + + slip_print_bytes(&buf[last_idx + 1], len - (last_idx + 1)); + + ret = serdev_device_write(sdev, + &buf[last_idx + 1], len - (last_idx + 1), timeout); + + return ret; +} +#endif + +static int slip_write_data(u8 *buf, int buf_len, const u8 *data, int data_len) +{ + int last_idx = -1; + int i, n; + int count = 0; + + for (i = 0; i < data_len; i++) { + if (data[i] != SLIP_END && + data[i] != SLIP_ESC) + continue; + + n = i - (last_idx + 1); + if (count + n + 2 > buf_len) + return -ENOMEM; + + memcpy(buf + count, &data[last_idx + 1], n); + count += n; + + buf[count++] = SLIP_ESC; + switch (data[i]) { + case SLIP_END: + buf[count++] = SLIP_ESC_END; + break; + case SLIP_ESC: + buf[count++] = SLIP_ESC_ESC; + break; + } + + last_idx = i; + } + + n = data_len - (last_idx + 1); + if (count + n > buf_len) + return -ENOMEM; + + memcpy(buf + count, &data[last_idx + 1], n); + count += n; + + return count; +} + +#define DEVMGMT_ID 0x01 + +#define DEVMGMT_MSG_PING_REQ 0x01 +#define DEVMGMT_MSG_PING_RSP 0x02 +#define DEVMGMT_MSG_GET_DEVICE_INFO_REQ 0x03 +#define DEVMGMT_MSG_GET_DEVICE_INFO_RSP 0x04 +#define DEVMGMT_MSG_GET_FW_INFO_REQ 0x05 +#define DEVMGMT_MSG_GET_FW_INFO_RSP 0x06 + +#define DEVMGMT_STATUS_OK 0x00 + +struct wimod_hci_packet_dispatcher { + struct list_head list; + u8 dst_id; + u8 msg_id; + void (*dispatchee)(const u8*, int, struct wimod_hci_packet_dispatcher *); + void *priv; +}; + +struct wimod_hci_packet_completion { + struct wimod_hci_packet_dispatcher disp; + struct completion comp; + char *payload; + int payload_len; +}; + +static void wimod_hci_add_dispatcher(struct wimod_device *wmdev, + struct wimod_hci_packet_dispatcher *entry) +{ + list_add_tail_rcu(&entry->list, &wmdev->packet_dispatchers); +} + +static void wimod_hci_remove_dispatcher(struct wimod_device *wmdev, + struct wimod_hci_packet_dispatcher *entry) +{ + list_del_rcu(&entry->list); +} + +static void wimod_hci_packet_dispatch_completion(const u8 *data, int len, + struct wimod_hci_packet_dispatcher *d) +{ + struct wimod_hci_packet_completion *disp = + container_of(d, struct wimod_hci_packet_completion, disp); + + if (completion_done(&disp->comp)) + return; + + disp->payload_len = len - 2; + disp->payload = kzalloc(disp->payload_len, GFP_KERNEL); + if (disp->payload) + memcpy(disp->payload, data + 2, len - 2); + + complete(&disp->comp); +} + +static int wimod_hci_send(struct serdev_device *sdev, + u8 dst_id, u8 msg_id, const u8 *payload, int payload_len, + unsigned long timeout) +{ + u8 buf[WIMOD_HCI_PACKET_MAX]; + int buf_len = 0; + u16 crc = 0xffff; + int ret, i; + + if (payload_len > WIMOD_HCI_PAYLOAD_MAX) + return -EINVAL; + + for (i = 0; i < 30; i++) { + ret = slip_send_end(sdev, timeout); + if (ret) { + dev_err(&sdev->dev, "%s: wakeup END %d failed\n", __func__, i); + return ret; + } + } + + crc = crc_ccitt_byte(crc, dst_id); + crc = crc_ccitt_byte(crc, msg_id); + if (payload_len > 0) + crc = crc_ccitt(crc, payload, payload_len); + crc = ~crc; + + printk(KERN_INFO "sending: "); + + /*ret = slip_send_end(sdev, timeout); + if (ret) { + dev_err(&sdev->dev, "%s: initial END failed\n", __func__); + return ret; + } + + ret = slip_send_data(sdev, &dst_id, 1, timeout); + if (ret) { + dev_err(&sdev->dev, "%s: dst_id failed\n", __func__); + return ret; + } + + ret = slip_send_data(sdev, &msg_id, 1, timeout); + if (ret) { + dev_err(&sdev->dev, "%s: msg_id failed\n", __func__); + return ret; + }*/ + + buf[buf_len++] = SLIP_END; + + ret = slip_write_data(buf + buf_len, sizeof(buf) - buf_len, &dst_id, 1); + if (ret < 0) + return ret; + buf_len += ret; + + ret = slip_write_data(buf + buf_len, sizeof(buf) - buf_len, &msg_id, 1); + if (ret < 0) + return ret; + buf_len += ret; + + if (payload_len > 0) { + /*ret = slip_send_data(sdev, payload, payload_len, timeout); + if (ret) { + dev_err(&sdev->dev, "%s: payload failed\n", __func__); + return ret; + }*/ + ret = slip_write_data(buf + buf_len, sizeof(buf) - buf_len, payload, payload_len); + if (ret < 0) + return ret; + buf_len += ret; + } + + cpu_to_le16s(crc); + /*ret = slip_send_data(sdev, (u8 *)&crc, 2, timeout); + if (ret) { + dev_err(&sdev->dev, "%s: FCS failed\n", __func__); + return ret; + } + + ret = slip_send_end(sdev, timeout); + if (ret) { + dev_err(&sdev->dev, "%s: trailing END failed\n", __func__); + return ret; + }*/ + + ret = slip_write_data(buf + buf_len, sizeof(buf) - buf_len, (u8 *)&crc, 2); + if (ret < 0) + return ret; + buf_len += ret; + + buf[buf_len++] = SLIP_END; + + slip_print_bytes(buf, buf_len); + + return serdev_device_write(sdev, buf, buf_len, timeout); + + //printk("\n"); + + //return 0; +} + +static int wimod_hci_devmgmt_status(u8 status) +{ + switch (status) { + case DEVMGMT_STATUS_OK: + return 0; + default: + pr_info("DEVMGMT status %u\n", (int)status); + return -EINVAL; + } +} + +static int wimod_hci_devmgmt_send_sync(struct wimod_device *wmdev, + u8 req_msg_id, const u8 *req_payload, int req_payload_len, + u8 rsp_msg_id, u8 **rsp_payload, int *rsp_payload_len, + unsigned long timeout) +{ + struct wimod_hci_packet_completion packet = {0}; + int ret; + + if (rsp_payload && !rsp_payload_len) + return -EINVAL; + + packet.disp.dst_id = DEVMGMT_ID; + packet.disp.msg_id = rsp_msg_id; + packet.disp.dispatchee = wimod_hci_packet_dispatch_completion; + init_completion(&packet.comp); + + wimod_hci_add_dispatcher(wmdev, &packet.disp); + + ret = wimod_hci_send(wmdev->serdev, DEVMGMT_ID, req_msg_id, req_payload, req_payload_len, timeout); + if (ret) { + wimod_hci_remove_dispatcher(wmdev, &(packet.disp)); + return ret; + } + + timeout = wait_for_completion_timeout(&packet.comp, timeout); + wimod_hci_remove_dispatcher(wmdev, &packet.disp); + if (!timeout) + return -ETIMEDOUT; + + if (packet.payload_len < 1) { + kfree(packet.payload); + return -EINVAL; + } + + ret = wimod_hci_devmgmt_status(packet.payload[0]); + if (ret || !rsp_payload) + kfree(packet.payload); + else if (rsp_payload) { + *rsp_payload = packet.payload; + *rsp_payload_len = packet.payload_len; + } + return ret; +} + +static int wimod_hci_ping(struct wimod_device *wmdev, unsigned long timeout) +{ + return wimod_hci_devmgmt_send_sync(wmdev, + DEVMGMT_MSG_PING_REQ, NULL, 0, + DEVMGMT_MSG_PING_RSP, NULL, NULL, + timeout); +} + +static int wimod_hci_get_device_info(struct wimod_device *wmdev, u8 *buf, unsigned long timeout) +{ + u8 *payload; + int payload_len; + int ret; + + ret = wimod_hci_devmgmt_send_sync(wmdev, + DEVMGMT_MSG_GET_DEVICE_INFO_REQ, NULL, 0, + DEVMGMT_MSG_GET_DEVICE_INFO_RSP, &payload, &payload_len, + timeout); + if (ret) + return ret; + + if (payload_len < 10) { + dev_err(&wmdev->serdev->dev, "get_device_info: payload length (10)\n"); + kfree(payload); + return -EINVAL; + } + + if (buf) + memcpy(buf, payload + 1, min(payload_len - 1, 9)); + + kfree(payload); + return 0; +} + +static int wimod_hci_get_fw_info(struct wimod_device *wmdev, u8 **info, int *info_len, unsigned long timeout) +{ + u8 *payload; + int payload_len; + int ret; + + if (info && !info_len) + return -EINVAL; + + ret = wimod_hci_devmgmt_send_sync(wmdev, + DEVMGMT_MSG_GET_FW_INFO_REQ, NULL, 0, + DEVMGMT_MSG_GET_FW_INFO_RSP, &payload, &payload_len, + timeout); + if (ret) + return ret; + + if (info) { + *info = payload + 1; + *info_len = payload_len - 1; + } else + kfree(payload); + + return 0; +} + +static void wimod_hci_get_fw_info_free(u8* info) +{ + u8 *payload = info - 1; + + kfree(payload); +} + +static void wimod_process_packet(struct serdev_device *sdev, const u8 *data, int len) +{ + struct wimod_device *wmdev = serdev_device_get_drvdata(sdev); + struct wimod_hci_packet_dispatcher *e; + u16 crc; + + dev_info(&sdev->dev, "Processing incoming packet (%d)\n", len); + + if (len < 4) { + dev_dbg(&sdev->dev, "Discarding packet of length %d\n", len); + return; + } + + crc = ~crc_ccitt(0xffff, data, len); + if (crc != 0x0f47) { + dev_dbg(&sdev->dev, "Discarding packet with wrong checksum\n"); + return; + } + + list_for_each_entry(e, &wmdev->packet_dispatchers, list) { + if (e->dst_id == data[0] && e->msg_id == data[1]) { + e->dispatchee(data, len - 2, e); + break; + } + } +} + +static int wimod_receive_buf(struct serdev_device *sdev, const u8 *data, size_t count) +{ + struct wimod_device *wmdev = serdev_device_get_drvdata(sdev); + size_t i = 0; + int len = 0; + + dev_dbg(&sdev->dev, "Receive (%d)\n", (int)count); + + while (i < min(count, sizeof(wmdev->rx_buf) - wmdev->rx_len)) { + if (wmdev->rx_esc) { + wmdev->rx_esc = false; + switch (data[i]) { + case SLIP_ESC_END: + wmdev->rx_buf[wmdev->rx_len++] = SLIP_END; + break; + case SLIP_ESC_ESC: + wmdev->rx_buf[wmdev->rx_len++] = SLIP_ESC; + break; + default: + dev_warn(&sdev->dev, "Ignoring unknown escape sequence 0300 0%o\n", data[i]); + break; + } + len += i + 1; + data += i + 1; + count -= i + 1; + i = 0; + continue; + } + if (data[i] != SLIP_END && + data[i] != SLIP_ESC) { + i++; + continue; + } + if (i > 0) { + memcpy(&wmdev->rx_buf[wmdev->rx_len], data, i); + wmdev->rx_len += i; + } + if (data[i] == SLIP_END && wmdev->rx_len > 0) { + wimod_process_packet(sdev, wmdev->rx_buf, wmdev->rx_len); + wmdev->rx_len = 0; + } else if (data[i] == SLIP_ESC) { + wmdev->rx_esc = true; + } + len += i + 1; + data += i + 1; + count -= i + 1; + i = 0; + } + + dev_dbg(&sdev->dev, "Receive: processed %d\n", len); + + return len; +} + +static const struct serdev_device_ops wimod_serdev_client_ops = { + .receive_buf = wimod_receive_buf, + .write_wakeup = serdev_device_write_wakeup, +}; + +static int wimod_probe(struct serdev_device *sdev) +{ + struct wimod_device *wmdev; + u8 buf[9]; + u8 *data; + int data_len; + int ret; + + dev_info(&sdev->dev, "Probing"); + + wmdev = devm_kzalloc(&sdev->dev, sizeof(struct wimod_device), GFP_KERNEL); + if (!wmdev) + return -ENOMEM; + + wmdev->serdev = sdev; + INIT_LIST_HEAD(&wmdev->packet_dispatchers); + serdev_device_set_drvdata(sdev, wmdev); + + ret = serdev_device_open(sdev); + if (ret) { + dev_err(&sdev->dev, "Failed to open (%d)\n", ret); + return ret; + } + + serdev_device_set_baudrate(sdev, 115200); + serdev_device_set_flow_control(sdev, false); + serdev_device_set_client_ops(sdev, &wimod_serdev_client_ops); + + ret = wimod_hci_ping(wmdev, HZ); + if (ret) { + dev_err(&sdev->dev, "Ping failed (%d)\n", ret); + goto err; + } + + ret = wimod_hci_get_device_info(wmdev, buf, HZ); + if (ret) { + dev_err(&sdev->dev, "Failed to obtain device info (%d)\n", ret); + goto err; + } + dev_info(&sdev->dev, "Module type: 0x%02x\n", (int)buf[0]); + + ret = wimod_hci_get_fw_info(wmdev, &data, &data_len, HZ); + if (ret) { + dev_err(&sdev->dev, "Failed to obtain firmware info (%d)\n", ret); + goto err; + } + dev_info(&sdev->dev, "Firmware: %u.%u build %u '%s'\n", + data[1], data[0], ((u16)data[3] << 8) | data[2], data + 4); + wimod_hci_get_fw_info_free(data); + + dev_info(&sdev->dev, "Done.\n"); + + return 0; +err: + serdev_device_close(sdev); + return ret; +} + +static void wimod_remove(struct serdev_device *sdev) +{ + serdev_device_close(sdev); + + dev_info(&sdev->dev, "Removed\n"); +} + +static const struct of_device_id wimod_of_match[] = { + { .compatible = "imst,wimod-hci" }, + {} +}; +MODULE_DEVICE_TABLE(of, wimod_of_match); + +static struct serdev_device_driver wimod_serdev_driver = { + .probe = wimod_probe, + .remove = wimod_remove, + .driver = { + .name = "wimod", + .of_match_table = wimod_of_match, + }, +}; + +static int __init wimod_init(void) +{ + int ret; + + ret = serdev_device_driver_register(&wimod_serdev_driver); + if (ret) + return ret; + + return 0; +} + +static void __exit wimod_exit(void) +{ + serdev_device_driver_unregister(&wimod_serdev_driver); +} + +module_init(wimod_init); +module_exit(wimod_exit); + +MODULE_DESCRIPTION("WiMOD serdev driver"); +MODULE_AUTHOR("Andreas Färber "); +MODULE_LICENSE("GPL"); From patchwork Sun Jul 1 11:08:03 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: 140705 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2849586ljj; Sun, 1 Jul 2018 04:11:48 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdFtWS0MhfWzdhoKqMGZLiAcC471WhDVrxJM7Fa/kM8kQxBmjIQkcLh2/cizvKwwvA6ggzS X-Received: by 2002:a62:9652:: with SMTP id c79-v6mr21538926pfe.114.1530443508640; Sun, 01 Jul 2018 04:11:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530443508; cv=none; d=google.com; s=arc-20160816; b=EeT1FmCeiMVaNhDS6vMGHG3BmGgZLXBy6zLMI81avyhAv2BvP59laB12xA5+rOcqfH 2CVHGdeGiqwkj46e1uDNHL1r3gGxuUhXcCiNbZEzHR+I1tL8IoZRfG92oYWcVaS/B1HK UDQNqGhpIPREMIQvfJxPp+IvX5o6lLT70+ZAC6rp472/ICvXeMWNkW7J5Nj9OtbxaMP6 idAuCyJlcqxWgMQ9UR3/B53gw+QVJqAEJY2gNiMvwATKA+f6KVC/0Qta7/8TPPW7rjVu TVOQ6UQjuWftS4CVtOh4RyeaRSvZo2Ud3zlgyFQ/CPVXtrtL0p9sF0rOFKP/de1mTQXS CiJg== 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=t2zdSFuj8q83bQeIuiXmNPVzv5Wvj5naoZs1Ftpb1Yw=; b=0QLGZ1xVjVm2KAZV0Xf9kCsoNNNqZSJDpvKpNyNLKSe8nk7tDyqRHY4AeycaJ8Re73 NuGTMHTK5NyDf4dlP1z2wPzytW/CWKUndDlaNCpyaEtMr8ckFjN8Ko7Xd6y5CFxUDt9P W9fU4F/QlLiWcTb45dzp61MUKXEpuUZ1BOlsHwHIuvjpcxd35DGLP6wKqTRb/HKRhNAc ioIvpDi+MUVjbmOUpWelM5eXJkDbBUQADBfL9/bgX5MgtC5tYtKOjUDCmOx1X0kdGrU9 AlSO+iT/74VpAxfqfwBE2frrEFhyFaZP8iz5O3S9fMiXHgWdNM6GarcaVxHnDryomv3A hG5Q== 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 a66-v6si13714179pfe.364.2018.07.01.04.11.48; Sun, 01 Jul 2018 04:11:48 -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 S1752570AbeGALKU (ORCPT + 31 others); Sun, 1 Jul 2018 07:10:20 -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 S1752339AbeGALJE (ORCPT ); Sun, 1 Jul 2018 07:09:04 -0400 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 AD20FAFB3; Sun, 1 Jul 2018 11:09:03 +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?= , Ben Whitten , Steve deRosier , Mark Brown Subject: [RFC net-next 14/15] net: lora: Prepare Semtech SX1257 Date: Sun, 1 Jul 2018 13:08:03 +0200 Message-Id: <20180701110804.32415-15-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 The Semtech SX1257 and Sx1255 are usually used for radios A/B of SX1301. This will not implement a netdev itself, but rather needs to interface with SX130x somehow. Cc: Ben Whitten Cc: Steve deRosier Cc: Mark Brown Cc: Michael Röder Cc: Ken Yu (禹凯) Signed-off-by: Andreas Färber --- drivers/net/lora/Kconfig | 7 ++++ drivers/net/lora/Makefile | 3 ++ drivers/net/lora/sx1257.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 drivers/net/lora/sx1257.c -- 2.16.4 diff --git a/drivers/net/lora/Kconfig b/drivers/net/lora/Kconfig index 3e384493cbdd..68c7480d7812 100644 --- a/drivers/net/lora/Kconfig +++ b/drivers/net/lora/Kconfig @@ -31,6 +31,13 @@ config LORA_RN2483 help Microchip RN2483/2903 +config LORA_SX1257 + tristate "Semtech SX125x SPI driver" + default y + depends on SPI + help + Semtech SX1255/1257 + config LORA_SX1276 tristate "Semtech SX127x SPI driver" default y diff --git a/drivers/net/lora/Makefile b/drivers/net/lora/Makefile index 6b6870ffbfd8..44c578bde7d5 100644 --- a/drivers/net/lora/Makefile +++ b/drivers/net/lora/Makefile @@ -16,6 +16,9 @@ obj-$(CONFIG_LORA_RN2483) += lora-rn2483.o lora-rn2483-y := rn2483.o lora-rn2483-y += rn2483_cmd.o +obj-$(CONFIG_LORA_SX1257) += lora-sx1257.o +lora-sx1257-y := sx1257.o + obj-$(CONFIG_LORA_SX1276) += lora-sx1276.o lora-sx1276-y := sx1276.o diff --git a/drivers/net/lora/sx1257.c b/drivers/net/lora/sx1257.c new file mode 100644 index 000000000000..c4e04ee3ec4b --- /dev/null +++ b/drivers/net/lora/sx1257.c @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Semtech SX1255/SX1257 LoRa transceiver + * + * Copyright (c) 2018 Andreas Färber + * + * Based on SX1301 HAL code: + * Copyright (c) 2013 Semtech-Cycleo + */ + +#include +#include +#include +#include + +static int sx1257_write(struct spi_device *spi, u8 reg, u8 val) +{ + u8 buf[2]; + + buf[0] = reg | BIT(7); + buf[1] = val; + return spi_write(spi, buf, 2); +} + +static int sx1257_read(struct spi_device *spi, u8 reg, u8 *val) +{ + u8 addr = reg & 0x7f; + return spi_write_then_read(spi, &addr, 1, val, 1); +} + +static int sx1257_probe(struct spi_device *spi) +{ + u8 val; + int ret; + + if (true) { + ret = sx1257_read(spi, 0x07, &val); + if (ret) { + dev_err(&spi->dev, "version read failed\n"); + return ret; + } + + dev_info(&spi->dev, "SX125x version: %02x\n", (unsigned)val); + } + + ret = sx1257_write(spi, 0x10, 1 /* + 2 */); + if (ret) { + dev_err(&spi->dev, "clk write failed\n"); + return ret; + } + + dev_info(&spi->dev, "clk written\n"); + + if (true) { + ret = sx1257_write(spi, 0x26, 13 + 2 * 16); + if (ret) { + dev_err(&spi->dev, "xosc write failed\n"); + return ret; + } + } + + dev_info(&spi->dev, "SX1257 module probed\n"); + + return 0; +} + +static int sx1257_remove(struct spi_device *spi) +{ + dev_info(&spi->dev, "SX1257 module removed\n"); + + return 0; +} + +#ifdef CONFIG_OF +static const struct of_device_id sx1257_dt_ids[] = { + { .compatible = "semtech,sx1255" }, + { .compatible = "semtech,sx1257" }, + {} +}; +MODULE_DEVICE_TABLE(of, sx1257_dt_ids); +#endif + +static struct spi_driver sx1257_spi_driver = { + .driver = { + .name = "sx1257", + .of_match_table = of_match_ptr(sx1257_dt_ids), + }, + .probe = sx1257_probe, + .remove = sx1257_remove, +}; + +module_spi_driver(sx1257_spi_driver); + +MODULE_DESCRIPTION("SX1257 SPI driver"); +MODULE_AUTHOR("Andreas Färber "); +MODULE_LICENSE("GPL");