Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pci Add driver for Intel XMM7360 LTE modem, based up...
details: https://anonhg.NetBSD.org/src/rev/fdb5c3eae605
branches: trunk
changeset: 974223:fdb5c3eae605
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Sun Jul 26 14:51:18 2020 +0000
description:
Add driver for Intel XMM7360 LTE modem, based upon Linux driver available
at https://github.com/xmm7360/xmm7360-pci
This version works on Linux, OpenBSD, and NetBSD.
OpenBSD port written for genua GmbH
Modem requires python script from the master site to initialize the network,
it will be added to pkgsrc shortly
diffstat:
sys/arch/amd64/conf/ALL | 6 +-
sys/conf/majors | 3 +-
sys/dev/pci/files.pci | 9 +-
sys/dev/pci/xmm7360.c | 3335 +++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 3349 insertions(+), 4 deletions(-)
diffs (truncated from 3400 to 300 lines):
diff -r 3f1e6a3a2bc3 -r fdb5c3eae605 sys/arch/amd64/conf/ALL
--- a/sys/arch/amd64/conf/ALL Sun Jul 26 14:39:46 2020 +0000
+++ b/sys/arch/amd64/conf/ALL Sun Jul 26 14:51:18 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.157 2020/07/19 14:31:31 maxv Exp $
+# $NetBSD: ALL,v 1.158 2020/07/26 14:51:18 jdolecek Exp $
# From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
#
# ALL machine description file
@@ -17,7 +17,7 @@
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "ALL-$Revision: 1.157 $"
+#ident "ALL-$Revision: 1.158 $"
maxusers 64 # estimated number of users
@@ -1022,6 +1022,8 @@
wm* at pci? dev ? function ? # Intel 8254x gigabit
wpi* at pci? dev ? function ? # Intel PRO/Wireless 3945ABG
xge* at pci? dev ? function ? # Neterion (S2io) Xframe-I 10GbE
+wwanc* at pci? dev ? function ? # Intel XMM7360 LTE modem
+wwan* at wwanc? # Intel XMM7360 LTE modem
# PCMCIA network interfaces
an* at pcmcia? function ? # Aironet PC4500/PC4800 (802.11)
diff -r 3f1e6a3a2bc3 -r fdb5c3eae605 sys/conf/majors
--- a/sys/conf/majors Sun Jul 26 14:39:46 2020 +0000
+++ b/sys/conf/majors Sun Jul 26 14:51:18 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: majors,v 1.94 2020/06/07 09:45:19 maxv Exp $
+# $NetBSD: majors,v 1.95 2020/07/26 14:51:18 jdolecek Exp $
#
# Device majors for Machine-Independent drivers.
#
@@ -89,3 +89,4 @@
device-major vhci char 355 vhci
device-major vio9p char 356 vio9p
device-major fault char 357 fault
+device-major wwanc char 358 wwanc
diff -r 3f1e6a3a2bc3 -r fdb5c3eae605 sys/dev/pci/files.pci
--- a/sys/dev/pci/files.pci Sun Jul 26 14:39:46 2020 +0000
+++ b/sys/dev/pci/files.pci Sun Jul 26 14:51:18 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.pci,v 1.429 2020/06/24 03:38:01 thorpej Exp $
+# $NetBSD: files.pci,v 1.430 2020/07/26 14:51:18 jdolecek Exp $
#
# Config file and device description for machine-independent PCI code.
# Included by ports that need it. Requires that the SCSI files be
@@ -1165,3 +1165,10 @@
defflag opt_if_ixl.h IXL_DEBUG
defparam opt_if_ixl.h IXL_STATS_INTERVAL_MSEC
IXL_QUEUE_NUM
+
+# Intel XMM 7360 LTE modem
+device wwanc {} : tty
+attach wwanc at pci
+device wwan: ifnet
+attach wwan at wwanc
+file dev/pci/xmm7360.c wwanc | wwan needs-flag
diff -r 3f1e6a3a2bc3 -r fdb5c3eae605 sys/dev/pci/xmm7360.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/xmm7360.c Sun Jul 26 14:51:18 2020 +0000
@@ -0,0 +1,3335 @@
+// vim: noet ts=8 sts=8 sw=8
+/*
+ * Device driver for Intel XMM7360 LTE modems, eg. Fibocom L850-GL.
+ * Written by James Wah
+ * james%laird-wah.net@localhost
+ *
+ * Development of this driver was supported by genua GmbH
+ *
+ * Copyright (c) 2020 genua GmbH <info%genua.de@localhost>
+ * Copyright (c) 2020 James Wah <james%laird-wah.net@localhost>
+ * Copyright (c) 2020 Jaromir Dolecek <jdolecek%NetBSD.org@localhost>
+ *
+ * OpenBSD port written by Jaromir Dolecek for genua GmbH
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES ON
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGE
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifdef __linux__
+
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/delay.h>
+#include <linux/uaccess.h>
+#include <linux/cdev.h>
+#include <linux/wait.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/poll.h>
+#include <linux/skbuff.h>
+#include <linux/netdevice.h>
+#include <linux/if.h>
+#include <linux/if_arp.h>
+#include <net/rtnetlink.h>
+#include <linux/hrtimer.h>
+#include <linux/workqueue.h>
+
+MODULE_LICENSE("Dual BSD/GPL");
+
+static const struct pci_device_id xmm7360_ids[] = {
+ { PCI_DEVICE(0x8086, 0x7360), },
+ { 0, }
+};
+MODULE_DEVICE_TABLE(pci, xmm7360_ids);
+
+/* Actually this ioctl not used for xmm0/rpc device by python code */
+#define XMM7360_IOCTL_GET_PAGE_SIZE _IOC(_IOC_READ, 'x', 0xc0, sizeof(u32))
+
+#define xmm7360_os_msleep(msec) msleep(msec)
+
+#define __unused /* nothing */
+
+#endif
+
+#if defined(__OpenBSD__) || defined(__NetBSD__)
+
+#ifdef __OpenBSD__
+#include "bpfilter.h"
+#endif
+#ifdef __NetBSD__
+#include "opt_inet.h"
+#include "opt_gateway.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: xmm7360.c,v 1.1 2020/07/26 14:51:18 jdolecek Exp $");
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/sockio.h>
+#include <sys/mbuf.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/socket.h>
+#include <sys/mutex.h>
+#include <sys/tty.h>
+#include <sys/conf.h>
+#include <sys/kthread.h>
+#include <sys/poll.h>
+#include <sys/fcntl.h> /* for FREAD/FWRITE */
+#include <sys/vnode.h>
+#include <uvm/uvm_param.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcidevs.h>
+
+#include <net/if.h>
+#include <net/if_types.h>
+
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <netinet/ip6.h>
+
+#ifdef __OpenBSD__
+#include <netinet/if_ether.h>
+#include <sys/timeout.h>
+#include <machine/bus.h>
+#endif
+
+#if NBPFILTER > 0 || defined(__NetBSD__)
+#include <net/bpf.h>
+#endif
+
+#ifdef __NetBSD__
+#include "ioconf.h"
+#include <sys/cpu.h>
+#endif
+
+#ifdef INET
+#include <netinet/in_var.h>
+#endif
+#ifdef INET6
+#include <netinet6/in6_var.h>
+#endif
+
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef bus_addr_t dma_addr_t;
+typedef void * wait_queue_head_t; /* just address for tsleep() */
+
+#define WWAN_BAR0 PCI_MAPREG_START
+#define WWAN_BAR1 (PCI_MAPREG_START + 4)
+#define WWAN_BAR2 (PCI_MAPREG_START + 8)
+
+#define BUG_ON(never_true) KASSERT(!(never_true))
+#define WARN_ON(x) /* nothing */
+
+#ifdef __OpenBSD__
+typedef struct mutex spinlock_t;
+#define dev_err(devp, fmt, ...) \
+ printf("%s: " fmt, (devp)->dv_xname, ##__VA_ARGS__)
+#define dev_info(devp, fmt, ...) \
+ printf("%s: " fmt, (devp)->dv_xname, ##__VA_ARGS__)
+#define kzalloc(size, flags) malloc(size, M_DEVBUF, M_WAITOK | M_ZERO)
+#define kfree(addr) free(addr, M_DEVBUF, 0)
+#define mutex_init(lock) mtx_init(lock, IPL_TTY)
+#define mutex_lock(lock) mtx_enter(lock)
+#define mutex_unlock(lock) mtx_leave(lock)
+/* In OpenBSD every mutex is spin mutex, and it must not be held on sleep */
+#define spin_lock_irqsave(lock, flags) mtx_enter(lock)
+#define spin_unlock_irqrestore(lock, flags) mtx_leave(lock)
+
+/* Compat defines for NetBSD API */
+#define curlwp curproc
+#define LINESW(tp) (linesw[(tp)->t_line])
+#define selnotify(sel, band, note) selwakeup(sel)
+#define cfdata_t void *
+#define device_lookup_private(cdp, unit) \
+ (unit < (*cdp).cd_ndevs) ? (*cdp).cd_devs[unit] : NULL
+#define IFQ_SET_READY(ifq) /* nothing */
+#define device_private(devt) (void *)devt;
+#define if_deferred_start_init(ifp, arg) /* nothing */
+#define IF_OUTPUT_CONST /* nothing */
+#define tty_lock() int s = spltty()
+#define tty_unlock() splx(s)
+#define tty_locked() /* nothing */
+#define pmf_device_deregister(dev) /* nothing */
+#if NBPFILTER > 0
+#define BPF_MTAP_OUT(ifp, m) \
+ if (ifp->if_bpf) { \
+ bpf_mtap_af(ifp->if_bpf, m->m_pkthdr.ph_family, \
+ m, BPF_DIRECTION_OUT); \
+ }
+#else
+#define BPF_MTAP_OUT(ifp, m) /* nothing */
+#endif
+
+/* Copied from NetBSD <lib/libkern/libkern.h> */
+#define __validate_container_of(PTR, TYPE, FIELD) \
+ (0 * sizeof((PTR) - &((TYPE *)(((char *)(PTR)) - \
+ offsetof(TYPE, FIELD)))->FIELD))
+#define container_of(PTR, TYPE, FIELD) \
+ ((TYPE *)(((char *)(PTR)) - offsetof(TYPE, FIELD)) \
+ + __validate_container_of(PTR, TYPE, FIELD))
+
+/* Copied from NetBSD <sys/cdefs.h> */
+#define __UNVOLATILE(a) ((void *)(unsigned long)(volatile void *)(a))
+
+#if OpenBSD <= 201911
+/* Backward compat with OpenBSD 6.6 */
+#define klist_insert(klist, kn) \
+ SLIST_INSERT_HEAD(klist, kn, kn_selnext)
+#define klist_remove(klist, kn) \
+ SLIST_REMOVE(klist, kn, knote, kn_selnext)
+#define XMM_KQ_ISFD_INITIALIZER .f_isfd = 1
+#else
+#define XMM_KQ_ISFD_INITIALIZER .f_flags = FILTEROP_ISFD
+#endif /* OpenBSD <= 201911 */
+
+#endif
+
+#ifdef __NetBSD__
+typedef struct kmutex spinlock_t;
+#define dev_err aprint_error_dev
+#define dev_info aprint_normal_dev
+#define mutex kmutex
+#define kzalloc(size, flags) malloc(size, M_DEVBUF, M_WAITOK | M_ZERO)
+#define kfree(addr) free(addr, M_DEVBUF)
+#define mutex_init(lock) mutex_init(lock, MUTEX_DEFAULT, IPL_TTY)
+#define mutex_lock(lock) mutex_enter(lock)
+#define mutex_unlock(lock) mutex_exit(lock)
+#define spin_lock_irqsave(lock, flags) mutex_enter(lock)
+#define spin_unlock_irqrestore(lock, flags) mutex_exit(lock)
+
+/* Compat defines with OpenBSD API */
+#define caddr_t void *
+#define proc lwp
+#define LINESW(tp) (*tp->t_linesw)
+#define ttymalloc(speed) tty_alloc()
+#define ttyfree(tp) tty_free(tp)
+#define l_open(dev, tp, p) l_open(dev, tp)
+#define l_close(tp, flag, p) l_close(tp, flag)
+#define ttkqfilter(dev, kn) ttykqfilter(dev, kn)
+#define msleep(ident, lock, prio, wmesg, timo) \
+ mtsleep(ident, prio, wmesg, timo, lock)
+#define pci_mapreg_map(pa, reg, type, busfl, tp, hp, bp, szp, maxsize) \
+ pci_mapreg_map(pa, reg, type, busfl, tp, hp, bp, szp)
+#define pci_intr_establish(pc, ih, lvl, func, arg, name) \
+ pci_intr_establish_xname(pc, ih, lvl, func, arg, name)
+#define suser(l) \
+ kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp)
Home |
Main Index |
Thread Index |
Old Index