Commit 61e12104 authored by Won Kang's avatar Won Kang Committed by Greg Kroah-Hartman

staging: gdm7240: adding LTE USB driver

GCT Semiconductor GDM7240 is 4G LTE chip.
This driver supports GCT reference platform as a USB device.
Signed-off-by: default avatarWon Kang <wonkang@gctsemi.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 17dc1597
...@@ -118,6 +118,8 @@ source "drivers/staging/ozwpan/Kconfig" ...@@ -118,6 +118,8 @@ source "drivers/staging/ozwpan/Kconfig"
source "drivers/staging/gdm72xx/Kconfig" source "drivers/staging/gdm72xx/Kconfig"
source "drivers/staging/gdm724x/Kconfig"
source "drivers/staging/silicom/Kconfig" source "drivers/staging/silicom/Kconfig"
source "drivers/staging/ced1401/Kconfig" source "drivers/staging/ced1401/Kconfig"
......
...@@ -52,6 +52,7 @@ obj-$(CONFIG_MFD_NVEC) += nvec/ ...@@ -52,6 +52,7 @@ obj-$(CONFIG_MFD_NVEC) += nvec/
obj-$(CONFIG_ANDROID) += android/ obj-$(CONFIG_ANDROID) += android/
obj-$(CONFIG_USB_WPAN_HCD) += ozwpan/ obj-$(CONFIG_USB_WPAN_HCD) += ozwpan/
obj-$(CONFIG_WIMAX_GDM72XX) += gdm72xx/ obj-$(CONFIG_WIMAX_GDM72XX) += gdm72xx/
obj-$(CONFIG_LTE_GDM724X) += gdm724x/
obj-$(CONFIG_NET_VENDOR_SILICOM) += silicom/ obj-$(CONFIG_NET_VENDOR_SILICOM) += silicom/
obj-$(CONFIG_CED1401) += ced1401/ obj-$(CONFIG_CED1401) += ced1401/
obj-$(CONFIG_DRM_IMX) += imx-drm/ obj-$(CONFIG_DRM_IMX) += imx-drm/
......
#
# GCT GDM724x LTE driver configuration
#
config LTE_GDM724X
tristate "GCT GDM724x LTE support"
depends on NET && USB
help
This driver supports GCT GDM724x LTE chip based USB modem devices.
It exposes 4 network devices to be used per PDN and 2 tty devices to be
used for AT commands and DM monitoring applications.
The modules will be called gdmulte.ko and gdmtty.ko
GCT-ATCx can be used for AT Commands
GCT-DMx can be used for LTE protocol monitoring
obj-$(CONFIG_LTE_GDM724X) := gdmulte.o
gdmulte-y += gdm_lte.o netlink_k.o
gdmulte-y += gdm_usb.o gdm_endian.o
obj-$(CONFIG_LTE_GDM724X) += gdmtty.o
gdmtty-y := gdm_tty.o gdm_mux.o
TODO:
- Clean up coding style to meet kernel standard. (80 line limit, netdev_err)
- Remove test for host endian
- Remove confusing macros (endian, hci_send, sdu_send, rcv_with_cb)
- Fixes for every instances of function returning -1
- Check for skb->len in gdm_lte_emulate_arp()
- Use ALIGN() macro for dummy_cnt in up_to_host()
- Error handling in init_usb()
- Explain reason for multiples of 512 bytes in alloc_tx_struct()
- Review use of atomic allocation for tx structs
- No error checking for alloc_tx_struct in do_tx()
Patches to:
Jonathan Kim <jonathankim@gctsemi.com>
Dean ahn <deanahn@gctsemi.com>
/*
* Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/slab.h>
#include "gdm_endian.h"
void set_endian(struct gdm_endian *ed, u8 dev_endian)
{
u8 a[2] = {0x12, 0x34};
u8 b[2] = {0, };
u16 c = 0x1234;
if (dev_endian == ENDIANNESS_BIG)
ed->dev_ed = ENDIANNESS_BIG;
else
ed->dev_ed = ENDIANNESS_LITTLE;
memcpy(b, &c, 2);
if (a[0] != b[0])
ed->host_ed = ENDIANNESS_LITTLE;
else
ed->host_ed = ENDIANNESS_BIG;
}
u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x)
{
if (ed->dev_ed == ed->host_ed)
return x;
return Endian16_Swap(x);
}
u16 gdm_dev16_to_cpu(struct gdm_endian *ed, u16 x)
{
if (ed->dev_ed == ed->host_ed)
return x;
return Endian16_Swap(x);
}
u32 gdm_cpu_to_dev32(struct gdm_endian *ed, u32 x)
{
if (ed->dev_ed == ed->host_ed)
return x;
return Endian32_Swap(x);
}
u32 gdm_dev32_to_cpu(struct gdm_endian *ed, u32 x)
{
if (ed->dev_ed == ed->host_ed)
return x;
return Endian32_Swap(x);
}
/*
* Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef __GDM_ENDIAN_H__
#define __GDM_ENDIAN_H__
#include <linux/types.h>
#define Endian16_Swap(value) \
((((u16)((value) & 0x00FF)) << 8) | \
(((u16)((value) & 0xFF00)) >> 8))
#define Endian32_Swap(value) \
((((u32)((value) & 0x000000FF)) << 24) | \
(((u32)((value) & 0x0000FF00)) << 8) | \
(((u32)((value) & 0x00FF0000)) >> 8) | \
(((u32)((value) & 0xFF000000)) >> 24))
enum {
ENDIANNESS_MIN = 0,
ENDIANNESS_UNKNOWN,
ENDIANNESS_LITTLE,
ENDIANNESS_BIG,
ENDIANNESS_MIDDLE,
ENDIANNESS_MAX
};
struct gdm_endian {
u8 dev_ed;
u8 host_ed;
};
void set_endian(struct gdm_endian *ed, u8 dev_endian);
u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x);
u16 gdm_dev16_to_cpu(struct gdm_endian *ed, u16 x);
u32 gdm_cpu_to_dev32(struct gdm_endian *ed, u32 x);
u32 gdm_dev32_to_cpu(struct gdm_endian *ed, u32 x);
#endif /*__GDM_ENDIAN_H__*/
This diff is collapsed.
/*
* Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _GDM_LTE_H_
#define _GDM_LTE_H_
#include <linux/netdevice.h>
#include <linux/version.h>
#include <linux/types.h>
#include "gdm_endian.h"
#define MAX_NIC_TYPE 4
#define MAX_RX_SUBMIT_COUNT 3
#define DRIVER_VERSION "3.7.17.0"
enum TX_ERROR_CODE {
TX_NO_ERROR = 0,
TX_NO_DEV,
TX_NO_SPC,
TX_NO_BUFFER,
};
enum CALLBACK_CONTEXT {
KERNEL_THREAD = 0,
USB_COMPLETE,
};
struct pdn_table {
u8 activate;
u32 dft_eps_id;
u32 nic_type;
} __packed;
struct nic;
struct phy_dev {
void *priv_dev;
struct net_device *dev[MAX_NIC_TYPE];
int (*send_hci_func)(void *priv_dev, void *data, int len,
void (*cb)(void *cb_data), void *cb_data);
int (*send_sdu_func)(void *priv_dev, void *data, int len,
unsigned int dftEpsId, unsigned int epsId,
void (*cb)(void *cb_data), void *cb_data,
int dev_idx, int nic_type);
int (*rcv_func)(void *priv_dev,
int (*cb)(void *cb_data, void *data, int len, int context),
void *cb_data, int context);
struct gdm_endian *(*get_endian)(void *priv_dev);
};
struct nic {
struct net_device *netdev;
struct phy_dev *phy_dev;
struct net_device_stats stats;
struct pdn_table pdn_table;
u8 dest_mac_addr[ETH_ALEN];
u8 src_mac_addr[ETH_ALEN];
u32 nic_id;
u16 vlan_id;
};
int gdm_lte_event_init(void);
void gdm_lte_event_exit(void);
void start_rx_proc(struct phy_dev *phy_dev);
int register_lte_device(struct phy_dev *phy_dev, struct device *dev, u8 *mac_address);
void unregister_lte_device(struct phy_dev *phy_dev);
#endif /* _GDM_LTE_H_ */
This diff is collapsed.
/*
* Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _GDM_MUX_H_
#define _GDM_MUX_H_
#include <linux/types.h>
#include <linux/usb.h>
#include <linux/list.h>
#define PM_NORMAL 0
#define PM_SUSPEND 1
#define USB_RT_ACM (USB_TYPE_CLASS | USB_RECIP_INTERFACE)
#define START_FLAG 0xA512485A
#define MUX_HEADER_SIZE 14
#define MUX_TX_MAX_SIZE (1024*10)
#define MUX_RX_MAX_SIZE (1024*30)
#define AT_PKT_TYPE 0xF011
#define DM_PKT_TYPE 0xF010
#define RETRY_TIMER 30 /* msec */
struct mux_pkt_header {
unsigned int start_flag;
unsigned int seq_num;
unsigned int payload_size;
unsigned short packet_type;
unsigned char data[0];
};
struct mux_tx {
struct urb *urb;
u8 *buf;
int len;
void (*callback)(void *cb_data);
void *cb_data;
};
struct mux_rx {
struct list_head free_list;
struct list_head rx_submit_list;
struct list_head to_host_list;
struct urb *urb;
u8 *buf;
void *mux_dev;
u32 offset;
u32 len;
int (*callback)(void *data, int len, int tty_index, int minor, int complete);
};
struct rx_cxt {
struct list_head to_host_list;
struct list_head rx_submit_list;
struct list_head rx_free_list;
spinlock_t to_host_lock;
spinlock_t submit_list_lock;
spinlock_t free_list_lock;
};
struct mux_dev {
struct usb_device *usbdev;
struct usb_interface *control_intf;
struct usb_interface *data_intf;
struct rx_cxt rx;
struct delayed_work work_rx;
struct usb_interface *intf;
int usb_state;
int (*rx_cb)(void *data, int len, int tty_index, int minor, int complete);
spinlock_t write_lock;
u8 minor[2];
};
#endif /* _GDM_MUX_H_ */
/*
* Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/usb/cdc.h>
#include <linux/serial.h>
#include "gdm_tty.h"
#define GDM_TTY_MAJOR 0
#define GDM_TTY_MINOR 32
#define ACM_CTRL_DTR 0x01
#define ACM_CTRL_RTS 0x02
#define ACM_CTRL_DSR 0x02
#define ACM_CTRL_RI 0x08
#define ACM_CTRL_DCD 0x01
#define WRITE_SIZE 2048
#define MUX_TX_MAX_SIZE 2048
#define gdm_tty_send(n, d, l, i, c, b) (\
n->tty_dev->send_func(n->tty_dev->priv_dev, d, l, i, c, b))
#define gdm_tty_recv(n, c) (\
n->tty_dev->recv_func(n->tty_dev->priv_dev, c))
#define gdm_tty_send_control(n, r, v, d, l) (\
n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
#define acm_set_comm_feature(n, v) \
gdm_tty_send_control(n, 0x02, v, NULL, 0)
#define GDM_TTY_READY(tty_str) (tty_str && tty_str->tty_dev && tty_str->port.count)
struct tty_driver *g_tty_drv[TTY_MAX_COUNT] = {NULL, };
struct tty_str *g_tty_str[TTY_MAX_COUNT][GDM_TTY_MINOR] = {{NULL, }, };
static char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
static char *DEVICE_STRING[TTY_MAX_COUNT] = {"GCT-ATC", "GCT-DM"};
static DEFINE_MUTEX(open_mutex);
static struct tty_port_operations gdm_tty_port_ops = {
};
static int gdm_tty_open(struct tty_struct *tty, struct file *filp)
{
struct tty_str *tty_str = NULL;
int i;
int ret = 0;
mutex_lock(&open_mutex);
for (i = 0; i < TTY_MAX_COUNT; i++) {
if (!strcmp(tty->driver->driver_name, DRIVER_STRING[i])) {
tty_str = g_tty_str[i][tty->index];
break;
}
}
if (!tty_str) {
printk(KERN_INFO "glte: no tty device\n");
mutex_unlock(&open_mutex);
return -ENODEV;
}
set_bit(TTY_NO_WRITE_SPLIT, &tty->flags);
tty->driver_data = tty_str;
tty_port_tty_set(&tty_str->port, tty);
tty_str->port.count++;
set_bit(ASYNCB_INITIALIZED, &tty_str->port.flags);
ret = tty_port_block_til_ready(&tty_str->port, tty, filp);
mutex_unlock(&open_mutex);
return ret;
}
static void gdm_tty_close(struct tty_struct *tty, struct file *filp)
{
struct tty_str *tty_str = tty->driver_data;
int i;
if (!tty_str) {
printk(KERN_INFO "glte: tty device already close\n");
return;
}
if (tty_str->port.count != 0) {
tty_port_close_start(&tty_str->port, tty, filp);
tty_port_close_end(&tty_str->port, tty);
if (tty_str->port.count == 0)
tty_port_tty_set(&tty_str->port, NULL);
tty_str->port.tty = NULL;
}
if (!tty_str->tty_dev) {
for (i = 0; i < TTY_MAX_COUNT; i++) {
if (!strcmp(tty->driver->driver_name, DRIVER_STRING[i]))
break;
}
if (i < TTY_MAX_COUNT) {
tty_unregister_device(g_tty_drv[i], tty->index);
tty_port_tty_set(&tty_str->port, NULL);
kfree(tty_str);
g_tty_str[i][tty->index] = NULL;
}
}
}
static int gdm_tty_recv_complete(void *data, int len, int index, int minor, int complete)
{
struct tty_str *tty_str = g_tty_str[index][minor];
struct tty_struct *tty;
if (!GDM_TTY_READY(tty_str)) {
if (complete == RECV_PACKET_PROCESS_COMPLETE)
gdm_tty_recv(tty_str, gdm_tty_recv_complete);
return TO_HOST_PORT_CLOSE;
}
if (!data || !len)
goto complete_routine;
tty = tty_port_tty_get(&tty_str->port);
if (tty_buffer_request_room(tty, len) == len) {
tty_insert_flip_string(tty, data, len);
tty_flip_buffer_push(tty);
} else {
tty_kref_put(tty);
return TO_HOST_BUFFER_REQUEST_FAIL;
}
tty_kref_put(tty);
complete_routine:
if (complete == RECV_PACKET_PROCESS_COMPLETE)
gdm_tty_recv(tty_str, gdm_tty_recv_complete);
return TO_HOST_SUCCESS;
}
static void gdm_tty_send_complete(void *arg)
{
struct tty_str *tty_str = (struct tty_str *)arg;
struct tty_struct *tty;
if (!GDM_TTY_READY(tty_str))
return;
tty = tty_port_tty_get(&tty_str->port);
tty_wakeup(tty);
tty_kref_put(tty);
}
static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf, int len)
{
struct tty_str *tty_str = tty->driver_data;
int remain = len;
int sent_len = 0;
int sending_len = 0;
if (!GDM_TTY_READY(tty_str))
return -ENODEV;
if (!len)
return 0;
while (1) {
sending_len = remain > MUX_TX_MAX_SIZE ? MUX_TX_MAX_SIZE : remain;
gdm_tty_send(tty_str,
(void *)(buf+sent_len),
sending_len,
tty_str->tty_drv_index,
gdm_tty_send_complete,
tty_str
);
sent_len += sending_len;
remain -= sending_len;
if (remain <= 0)
break;
}
return len;
}
static int gdm_tty_write_room(struct tty_struct *tty)
{
struct tty_str *tty_str = tty->driver_data;
if (!GDM_TTY_READY(tty_str))
return -ENODEV;
return WRITE_SIZE;
}
static int gdm_tty_tiocmget(struct tty_struct *tty)
{
struct tty_str *tty_str = tty->driver_data;
if (!GDM_TTY_READY(tty_str))
return -ENODEV;
return (0 & ACM_CTRL_DTR ? TIOCM_DTR : 0) |
(0 & ACM_CTRL_RTS ? TIOCM_RTS : 0) |
(0 & ACM_CTRL_DSR ? TIOCM_DSR : 0) |
(0 & ACM_CTRL_RI ? TIOCM_RI : 0) |
(0 & ACM_CTRL_DCD ? TIOCM_CD : 0) |
TIOCM_CTS;
}
static int gdm_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear)
{
struct tty_str *tty_str = tty->driver_data;
if (!GDM_TTY_READY(tty_str))
return -ENODEV;
return 1;
}
int register_lte_tty_device(struct tty_dev *tty_dev, struct device *dev)
{
struct tty_str *tty_str;
int i, j;
for (i = 0; i < TTY_MAX_COUNT; i++) {
for (j = 0; j < GDM_TTY_MINOR; j++) {
if (!g_tty_str[i][j])
break;
}
if (j == GDM_TTY_MINOR) {
tty_dev->minor[i] = j;
return -1;
}
tty_str = kmalloc(sizeof(struct tty_str), GFP_KERNEL);
if (!tty_str)
return -ENOMEM;
g_tty_str[i][j] = tty_str;
tty_str->tty_dev = tty_dev;
tty_str->tty_drv_index = i;
tty_dev->minor[i] = j;
tty_port_init(&tty_str->port);
tty_str->port.ops = &gdm_tty_port_ops;
if (strcmp(DEVICE_STRING[i], "GCT-ATC") != 0)
dev = NULL;
tty_register_device(g_tty_drv[i], j, dev);
}
acm_set_comm_feature(tty_str, 1);
for (i = 0; i < MAX_ISSUE_NUM; i++)
gdm_tty_recv(tty_str, gdm_tty_recv_complete);
return 0;
}
void unregister_lte_tty_device(struct tty_dev *tty_dev)
{
struct tty_str *tty_str;
int i;
for (i = 0; i < TTY_MAX_COUNT; i++) {
if (tty_dev->minor[i] >= GDM_TTY_MINOR)
continue;
tty_str = g_tty_str[i][tty_dev->minor[i]];
if (!tty_str)
continue;
tty_str->tty_dev = NULL;
if (!tty_str->port.count) {
tty_unregister_device(g_tty_drv[i], tty_dev->minor[i]);
tty_port_tty_set(&tty_str->port, NULL);
kfree(tty_str);
g_tty_str[i][tty_dev->minor[i]] = NULL;
}
}
}
static void gdm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios_old)
{
return;
}
static const struct tty_operations gdm_tty_ops = {
.open = gdm_tty_open,
.close = gdm_tty_close,
.write = gdm_tty_write,
.write_room = gdm_tty_write_room,
.tiocmget = gdm_tty_tiocmget,
.tiocmset = gdm_tty_tiocmset,
.set_termios = gdm_tty_set_termios,
};
int register_lte_tty_driver(void)
{
struct tty_driver *tty_driver = NULL;
int i;
int ret;
for (i = 0; i < TTY_MAX_COUNT; i++) {
tty_driver = alloc_tty_driver(GDM_TTY_MINOR);
if (!tty_driver) {
printk(KERN_ERR "glte: alloc_tty_driver fail\n");
return -ENOMEM;
}
tty_driver->owner = THIS_MODULE;
tty_driver->driver_name = DRIVER_STRING[i];
tty_driver->name = DEVICE_STRING[i];
tty_driver->major = GDM_TTY_MAJOR;
tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
tty_driver->subtype = SERIAL_TYPE_NORMAL;
tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
tty_driver->init_termios = tty_std_termios;
tty_driver->init_termios.c_cflag = B9600 | CS8 | HUPCL | CLOCAL;
tty_driver->init_termios.c_lflag = ISIG | ICANON | IEXTEN;
tty_set_operations(tty_driver, &gdm_tty_ops);
ret = tty_register_driver(tty_driver);
g_tty_drv[i] = tty_driver;
}
return ret;
}
void unregister_lte_tty_driver(void)
{
struct tty_driver *tty_driver;
int i;
for (i = 0; i < TTY_MAX_COUNT; i++) {
tty_driver = g_tty_drv[i];
if (tty_driver) {
tty_unregister_driver(tty_driver);
put_tty_driver(tty_driver);
}
}
}
/*
* Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _GDM_TTY_H_
#define _GDM_TTY_H_
#include <linux/version.h>
#include <linux/types.h>
#include <linux/tty.h>
#define TTY_MAX_COUNT 2
#define MAX_ISSUE_NUM 3
enum TO_HOST_RESULT {
TO_HOST_SUCCESS = 0,
TO_HOST_BUFFER_REQUEST_FAIL = 1,
TO_HOST_PORT_CLOSE = 2,
TO_HOST_INVALID_PACKET = 3,
};
enum RECV_PACKET_PROCESS {
RECV_PACKET_PROCESS_COMPLETE = 0,
RECV_PACKET_PROCESS_CONTINUE = 1,
};
struct tty_dev {
void *priv_dev;
int (*send_func)(void *priv_dev, void *data, int len, int tty_index,
void (*cb)(void *cb_data), void *cb_data);
int (*recv_func)(void *priv_dev, int (*cb)(void *data, int len, int tty_index, int minor, int complete));
int (*send_control)(void *priv_dev, int request, int value, void *data, int len);
u8 minor[2];
};
struct tty_str {
struct tty_dev *tty_dev;
int tty_drv_index;
struct tty_port port;
};
int register_lte_tty_driver(void);
void unregister_lte_tty_driver(void);
int register_lte_tty_device(struct tty_dev *tty_dev, struct device *dev);
void unregister_lte_tty_device(struct tty_dev *tty_dev);
#endif /* _GDM_USB_H_ */
This diff is collapsed.
/*
* Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _GDM_USB_H_
#define _GDM_USB_H_
#include <linux/version.h>
#include <linux/types.h>
#include <linux/usb.h>
#include <linux/list.h>
#include <linux/time.h>
#include "gdm_endian.h"
#include "hci_packet.h"
#define PM_NORMAL 0
#define PM_SUSPEND 1
#define AUTO_SUSPEND_TIMER 5000 /* ms */
#define RX_BUF_SIZE (1024*32)
#define TX_BUF_SIZE (1024*32)
#define SDU_BUF_SIZE 2048
#define MAX_SDU_SIZE (1024*30)
#define MAX_PACKET_IN_MULTI_SDU 256
#define VID_GCT 0x1076
#define PID_GDM7240 0x8000
#define PID_GDM7243 0x9000
#define NETWORK_INTERFACE 1
#define USB_SC_SCSI 0x06
#define USB_PR_BULK 0x50
#define MAX_NUM_SDU_BUF 64
struct usb_tx {
struct list_head list;
struct urb *urb;
u8 *buf;
u32 len;
void (*callback)(void *cb_data);
void *cb_data;
struct tx_cxt *tx;
u8 is_sdu;
};
struct usb_tx_sdu {
struct list_head list;
u8 *buf;
u32 len;
void (*callback)(void *cb_data);
void *cb_data;
};
struct usb_rx {
struct list_head to_host_list;
struct list_head free_list;
struct list_head rx_submit_list;
struct rx_cxt *rx;
struct urb *urb;
u8 *buf;
int (*callback)(void *cb_data, void *data, int len, int context);
void *cb_data;
void *index;
};
struct tx_cxt {
struct list_head sdu_list;
struct list_head hci_list;
struct list_head free_list;
u32 avail_count;
spinlock_t lock;
};
struct rx_cxt {
struct list_head to_host_list;
struct list_head rx_submit_list;
struct list_head free_list;
u32 avail_count;
spinlock_t to_host_lock;
spinlock_t rx_lock;
spinlock_t submit_lock;
};
struct lte_udev {
struct usb_device *usbdev;
struct gdm_endian gdm_ed;
struct tx_cxt tx;
struct rx_cxt rx;
struct delayed_work work_tx;
struct delayed_work work_rx;
u8 send_complete;
u8 tx_stop;
struct usb_interface *intf;
int (*rx_cb)(void *cb_data, void *data, int len, int context);
int usb_state;
u8 request_mac_addr;
};
#endif /* _GDM_USB_H_ */
/*
* Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _HCI_H_
#define _HCI_H_
#define LTE_GET_INFORMATION 0x3002
#define LTE_GET_INFORMATION_RESULT 0xB003
#define MAC_ADDRESS 0xA2
#define LTE_LINK_ON_OFF_INDICATION 0xB133
#define LTE_PDN_TABLE_IND 0xB143
#define LTE_TX_SDU 0x3200
#define LTE_RX_SDU 0xB201
#define LTE_TX_MULTI_SDU 0x3202
#define LTE_RX_MULTI_SDU 0xB203
#define LTE_DL_SDU_FLOW_CONTROL 0x3305
#define LTE_UL_SDU_FLOW_CONTROL 0xB306
#define LTE_AT_CMD_TO_DEVICE 0x3307
#define LTE_AT_CMD_FROM_DEVICE 0xB308
#define LTE_SDIO_DM_SEND_PKT 0x3312
#define LTE_SDIO_DM_RECV_PKT 0xB313
#define LTE_NV_RESTORE_REQUEST 0xB30C
#define LTE_NV_RESTORE_RESPONSE 0x330D
#define LTE_NV_SAVE_REQUEST 0xB30E
#define NV_TYPE_LTE_INFO 0x00
#define NV_TYPE_BOARD_CONFIG 0x01
#define NV_TYPE_RF_CAL 0x02
#define NV_TYPE_TEMP 0x03
#define NV_TYPE_NET_INFO 0x04
#define NV_TYPE_SAFETY_INFO 0x05
#define NV_TYPE_CDMA_CAL 0x06
#define NV_TYPE_VENDOR 0x07
#define NV_TYPE_ALL 0xff
#define LTE_NV_SAVE_RESPONSE 0x330F
#define LTE_AT_CMD_TO_DEVICE_EXT 0x3323
#define LTE_AT_CMD_FROM_DEVICE_EXT 0xB324
#endif /* _HCI_H_ */
/*
* Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _HCI_PACKET_H_
#define _HCI_PACKET_H_
#define HCI_HEADER_SIZE 4
/*
* The NIC type definition:
* For backward compatibility, lower 16 bits used as they were.
* Lower 16 bit: NIC_TYPE values
* Uppoer 16 bit: NIC_TYPE Flags
*/
#define NIC_TYPE_NIC0 0x00000010
#define NIC_TYPE_NIC1 0x00000011
#define NIC_TYPE_NIC2 0x00000012
#define NIC_TYPE_NIC3 0x00000013
#define NIC_TYPE_ARP 0x00000100
#define NIC_TYPE_ICMPV6 0x00000200
#define NIC_TYPE_MASK 0x0000FFFF
#define NIC_TYPE_F_IPV4 0x00010000
#define NIC_TYPE_F_IPV6 0x00020000
#define NIC_TYPE_F_DHCP 0x00040000
#define NIC_TYPE_F_NDP 0x00080000
#define NIC_TYPE_F_VLAN 0x00100000
struct hci_packet {
u16 cmd_evt;
u16 len;
u8 data[0];
} __packed;
struct tlv {
u8 type;
u8 len;
u8 *data[1];
} __packed;
struct sdu_header {
u16 cmd_evt;
u16 len;
u32 dftEpsId;
u32 bearer_ID;
u32 nic_type;
} __packed;
struct sdu {
u16 cmd_evt;
u16 len;
u32 dftEpsId;
u32 bearer_ID;
u32 nic_type;
u8 data[0];
} __packed;
struct multi_sdu {
u16 cmd_evt;
u16 len;
u16 num_packet;
u16 reserved;
u8 data[0];
} __packed;
struct hci_pdn_table_ind {
u16 cmd_evt;
u16 len;
u8 activate;
u32 dft_eps_id;
u32 nic_type;
u8 pdn_type;
u8 ipv4_addr[4];
u8 ipv6_intf_id[8];
} __packed;
struct hci_connect_ind {
u16 cmd_evt;
u16 len;
u32 connect;
} __packed;
#endif /* _HCI_PACKET_H_ */
/*
* Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _LTE_IOCTL_H_
#define _LTE_IOCTL_H_
#define SIOCLTEIOCTL SIOCDEVPRIVATE
#define SIOCG_DATA 0x8D10
#define SIOCS_DATA 0x8D11
/*
* For historical reason, ioctl number and structure must be maintained
*/
enum {
LINK_ON,
LINK_OFF,
GET_NETWORK_STATICS,
RX_STOP,
RX_RESUME,
GET_DRV_VER,
GET_SDIO_DEVICE_STATUS,
GET_ENDIAN_INFO,
};
struct dev_endian_t {
unsigned char dev_endian;
unsigned char host_endian;
} __packed;
struct data_t {
long len;
void *buf;
} __packed;
struct wm_req_t {
union {
char ifrn_name[IFNAMSIZ];
} ifr_ifrn;
unsigned short cmd;
unsigned short data_id;
struct data_t data;
} __packed;
#ifndef ifr_name
#define ifr_name (ifr_ifrn.ifrm_name)
#endif
#endif /* _LTE_IOCTL_H_ */
/*
* Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/version.h>
#include <linux/export.h>
#include <linux/etherdevice.h>
#include <linux/netlink.h>
#include <asm/byteorder.h>
#include <net/sock.h>
#include "netlink_k.h"
#if defined(DEFINE_MUTEX)
static DEFINE_MUTEX(netlink_mutex);
#else
static struct semaphore netlink_mutex;
#define mutex_lock(x) down(x)
#define mutex_unlock(x) up(x)
#endif
#define ND_MAX_GROUP 30
#define ND_IFINDEX_LEN sizeof(int)
#define ND_NLMSG_SPACE(len) (NLMSG_SPACE(len) + ND_IFINDEX_LEN)
#define ND_NLMSG_DATA(nlh) ((void *)((char *)NLMSG_DATA(nlh) + ND_IFINDEX_LEN))
#define ND_NLMSG_S_LEN(len) (len+ND_IFINDEX_LEN)
#define ND_NLMSG_R_LEN(nlh) (nlh->nlmsg_len-ND_IFINDEX_LEN)
#define ND_NLMSG_IFIDX(nlh) NLMSG_DATA(nlh)
#define ND_MAX_MSG_LEN (1024 * 32)
static void (*rcv_cb)(struct net_device *dev, u16 type, void *msg, int len);
static void netlink_rcv_cb(struct sk_buff *skb)
{
struct nlmsghdr *nlh;
struct net_device *dev;
u32 mlen;
void *msg;
int ifindex;
if (!rcv_cb) {
printk(KERN_ERR "glte: nl cb - unregistered\n");
return;
}
if (skb->len < NLMSG_SPACE(0)) {
printk(KERN_ERR "glte: nl cb - invalid skb length\n");
return;
}
nlh = (struct nlmsghdr *)skb->data;
if (skb->len < nlh->nlmsg_len || nlh->nlmsg_len > ND_MAX_MSG_LEN) {
printk(KERN_ERR "glte: nl cb - invalid length (%d,%d)\n",
skb->len, nlh->nlmsg_len);
return;
}
memcpy(&ifindex, ND_NLMSG_IFIDX(nlh), ND_IFINDEX_LEN);
msg = ND_NLMSG_DATA(nlh);
mlen = ND_NLMSG_R_LEN(nlh);
dev = dev_get_by_index(&init_net, ifindex);
if (dev) {
rcv_cb(dev, nlh->nlmsg_type, msg, mlen);
dev_put(dev);
} else {
printk(KERN_ERR "glte: nl cb - dev (%d) not found\n", ifindex);
}
}
static void netlink_rcv(struct sk_buff *skb)
{
mutex_lock(&netlink_mutex);
netlink_rcv_cb(skb);
mutex_unlock(&netlink_mutex);
}
struct sock *netlink_init(int unit,
void (*cb)(struct net_device *dev, u16 type, void *msg, int len))
{
struct sock *sock;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)
struct netlink_kernel_cfg cfg = {
.input = netlink_rcv,
};
#endif
#if !defined(DEFINE_MUTEX)
init_MUTEX(&netlink_mutex);
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0)
sock = netlink_kernel_create(&init_net, unit, 0, netlink_rcv, NULL,
THIS_MODULE);
#elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
sock = netlink_kernel_create(&init_net, unit, THIS_MODULE, &cfg);
#else
sock = netlink_kernel_create(&init_net, unit, &cfg);
#endif
if (sock)
rcv_cb = cb;
return sock;
}
void netlink_exit(struct sock *sock)
{
sock_release(sock->sk_socket);
}
int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len)
{
static u32 seq;
struct sk_buff *skb = NULL;
struct nlmsghdr *nlh;
int ret = 0;
if (group > ND_MAX_GROUP)
return -EINVAL;
if (!netlink_has_listeners(sock, group+1))
return -ESRCH;
skb = alloc_skb(NLMSG_SPACE(len), GFP_ATOMIC);
if (!skb)
return -ENOMEM;
seq++;
nlh = nlmsg_put(skb, 0, seq, type, len, 0);
memcpy(NLMSG_DATA(nlh), msg, len);
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
NETLINK_CB(skb).pid = 0;
#else
NETLINK_CB(skb).portid = 0;
#endif
NETLINK_CB(skb).dst_group = 0;
ret = netlink_broadcast(sock, skb, 0, group+1, GFP_ATOMIC);
if (!ret)
return len;
if (ret != -ESRCH)
printk(KERN_ERR "glte: nl broadcast g=%d, t=%d, l=%d, r=%d\n",
group, type, len, ret);
else if (netlink_has_listeners(sock, group+1))
return -EAGAIN;
return ret;
}
/*
* Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _NETLINK_K_H
#define _NETLINK_K_H
#include <linux/netdevice.h>
#include <net/sock.h>
struct sock *netlink_init(int unit,
void (*cb)(struct net_device *dev, u16 type, void *msg, int len));
void netlink_exit(struct sock *sock);
int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len);
#endif /* _NETLINK_K_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment