ipwireless: driver for PC Card 3G/UMTS modem

The device is manufactured by IPWireless.  In some countries (for
example Czech Republic, T-Mobile ISP) this card is shipped for service
called UMTS 4G.

It's a piece of PCMCIA "4G" UMTS PPP networking hardware that presents
itself as a serial character device (i.e.  looks like usual modem to
userspace, accepts AT commands, etc).

Rewieved-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Ben Martel <benm@symmetric.co.nz>
Signed-off-by: Stephen Blackheath <stephen@symmetric.co.nz>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
David Sterba 2008-02-07 10:57:12 +01:00 committed by Linus Torvalds
parent 151db1fc23
commit 099dc4fb62
13 changed files with 3862 additions and 0 deletions

View File

@ -2150,6 +2150,14 @@ M: acme@ghostprotocols.net
L: netdev@vger.kernel.org L: netdev@vger.kernel.org
S: Maintained S: Maintained
IPWIRELES DRIVER
P: Jiri Kosina
M: jkosina@suse.cz
P: David Sterba
M: dsterba@suse.cz
S: Maintained
T: git://git.kernel.org/pub/scm/linux/kernel/git/jikos/ipwireless_cs.git
IRDA SUBSYSTEM IRDA SUBSYSTEM
P: Samuel Ortiz P: Samuel Ortiz
M: samuel@sortiz.org M: samuel@sortiz.org

View File

@ -43,5 +43,14 @@ config CARDMAN_4040
(http://www.omnikey.com/), or a current development version of OpenCT (http://www.omnikey.com/), or a current development version of OpenCT
(http://www.opensc.org/). (http://www.opensc.org/).
config IPWIRELESS
tristate "IPWireless 3G UMTS PCMCIA card support"
depends on PCMCIA
select PPP
help
This is a driver for 3G UMTS PCMCIA card from IPWireless company. In
some countries (for example Czech Republic, T-Mobile ISP) this card
is shipped for service called UMTS 4G.
endmenu endmenu

View File

@ -4,6 +4,8 @@
# Makefile for the Linux PCMCIA char device drivers. # Makefile for the Linux PCMCIA char device drivers.
# #
obj-y += ipwireless/
obj-$(CONFIG_SYNCLINK_CS) += synclink_cs.o obj-$(CONFIG_SYNCLINK_CS) += synclink_cs.o
obj-$(CONFIG_CARDMAN_4000) += cm4000_cs.o obj-$(CONFIG_CARDMAN_4000) += cm4000_cs.o
obj-$(CONFIG_CARDMAN_4040) += cm4040_cs.o obj-$(CONFIG_CARDMAN_4040) += cm4040_cs.o

View File

@ -0,0 +1,10 @@
#
# drivers/char/pcmcia/ipwireless/Makefile
#
# Makefile for the IPWireless driver
#
obj-$(CONFIG_IPWIRELESS) += ipwireless.o
ipwireless-objs := hardware.o main.o network.o tty.o

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,64 @@
/*
* IPWireless 3G PCMCIA Network Driver
*
* Original code
* by Stephen Blackheath <stephen@blacksapphire.com>,
* Ben Martel <benm@symmetric.co.nz>
*
* Copyrighted as follows:
* Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
*
* Various driver changes and rewrites, port to new kernels
* Copyright (C) 2006-2007 Jiri Kosina
*
* Misc code cleanups and updates
* Copyright (C) 2007 David Sterba
*/
#ifndef _IPWIRELESS_CS_HARDWARE_H_
#define _IPWIRELESS_CS_HARDWARE_H_
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#define IPW_CONTROL_LINE_CTS 0x0001
#define IPW_CONTROL_LINE_DCD 0x0002
#define IPW_CONTROL_LINE_DSR 0x0004
#define IPW_CONTROL_LINE_RI 0x0008
#define IPW_CONTROL_LINE_DTR 0x0010
#define IPW_CONTROL_LINE_RTS 0x0020
struct ipw_hardware;
struct ipw_network;
struct ipw_hardware *ipwireless_hardware_create(void);
void ipwireless_hardware_free(struct ipw_hardware *hw);
irqreturn_t ipwireless_interrupt(int irq, void *dev_id, struct pt_regs *regs);
int ipwireless_set_DTR(struct ipw_hardware *hw, unsigned int channel_idx,
int state);
int ipwireless_set_RTS(struct ipw_hardware *hw, unsigned int channel_idx,
int state);
int ipwireless_send_packet(struct ipw_hardware *hw,
unsigned int channel_idx,
unsigned char *data,
unsigned int length,
void (*packet_sent_callback) (void *cb,
unsigned int length),
void *sent_cb_data);
void ipwireless_associate_network(struct ipw_hardware *hw,
struct ipw_network *net);
void ipwireless_stop_interrupts(struct ipw_hardware *hw);
void ipwireless_init_hardware_v1(struct ipw_hardware *hw,
unsigned int base_port,
void __iomem *attr_memory,
void __iomem *common_memory,
int is_v2_card,
void (*reboot_cb) (void *data),
void *reboot_cb_data);
void ipwireless_init_hardware_v2_v3(struct ipw_hardware *hw);
void ipwireless_sleep(unsigned int tenths);
int ipwireless_dump_hardware_state(char *p, size_t limit,
struct ipw_hardware *hw);
#endif

View File

@ -0,0 +1,501 @@
/*
* IPWireless 3G PCMCIA Network Driver
*
* Original code
* by Stephen Blackheath <stephen@blacksapphire.com>,
* Ben Martel <benm@symmetric.co.nz>
*
* Copyrighted as follows:
* Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
*
* Various driver changes and rewrites, port to new kernels
* Copyright (C) 2006-2007 Jiri Kosina
*
* Misc code cleanups and updates
* Copyright (C) 2007 David Sterba
*/
#include "hardware.h"
#include "network.h"
#include "main.h"
#include "tty.h"
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <pcmcia/version.h>
#include <pcmcia/cisreg.h>
#include <pcmcia/device_id.h>
#include <pcmcia/ss.h>
#include <pcmcia/ds.h>
#include <pcmcia/cs.h>
static struct pcmcia_device_id ipw_ids[] = {
PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0100),
PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0200),
PCMCIA_DEVICE_NULL
};
MODULE_DEVICE_TABLE(pcmcia, ipw_ids);
static void ipwireless_detach(struct pcmcia_device *link);
/*
* Module params
*/
/* Debug mode: more verbose, print sent/recv bytes */
int ipwireless_debug;
int ipwireless_loopback;
int ipwireless_out_queue = 1;
module_param_named(debug, ipwireless_debug, int, 0);
module_param_named(loopback, ipwireless_loopback, int, 0);
module_param_named(out_queue, ipwireless_out_queue, int, 0);
MODULE_PARM_DESC(debug, "switch on debug messages [0]");
MODULE_PARM_DESC(loopback,
"debug: enable ras_raw channel [0]");
MODULE_PARM_DESC(out_queue, "debug: set size of outgoing queue [1]");
/* Executes in process context. */
static void signalled_reboot_work(struct work_struct *work_reboot)
{
struct ipw_dev *ipw = container_of(work_reboot, struct ipw_dev,
work_reboot);
struct pcmcia_device *link = ipw->link;
int ret = pccard_reset_card(link->socket);
if (ret != CS_SUCCESS)
cs_error(link, ResetCard, ret);
}
static void signalled_reboot_callback(void *callback_data)
{
struct ipw_dev *ipw = (struct ipw_dev *) callback_data;
/* Delegate to process context. */
schedule_work(&ipw->work_reboot);
}
static int config_ipwireless(struct ipw_dev *ipw)
{
struct pcmcia_device *link = ipw->link;
int ret;
config_info_t conf;
tuple_t tuple;
unsigned short buf[64];
cisparse_t parse;
unsigned short cor_value;
win_req_t request_attr_memory;
win_req_t request_common_memory;
memreq_t memreq_attr_memory;
memreq_t memreq_common_memory;
ipw->is_v2_card = 0;
tuple.Attributes = 0;
tuple.TupleData = (cisdata_t *) buf;
tuple.TupleDataMax = sizeof(buf);
tuple.TupleOffset = 0;
tuple.DesiredTuple = RETURN_FIRST_TUPLE;
ret = pcmcia_get_first_tuple(link, &tuple);
while (ret == 0) {
ret = pcmcia_get_tuple_data(link, &tuple);
if (ret != CS_SUCCESS) {
cs_error(link, GetTupleData, ret);
goto exit0;
}
ret = pcmcia_get_next_tuple(link, &tuple);
}
tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
ret = pcmcia_get_first_tuple(link, &tuple);
if (ret != CS_SUCCESS) {
cs_error(link, GetFirstTuple, ret);
goto exit0;
}
ret = pcmcia_get_tuple_data(link, &tuple);
if (ret != CS_SUCCESS) {
cs_error(link, GetTupleData, ret);
goto exit0;
}
ret = pcmcia_parse_tuple(link, &tuple, &parse);
if (ret != CS_SUCCESS) {
cs_error(link, ParseTuple, ret);
goto exit0;
}
link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
link->io.IOAddrLines = 16;
link->irq.IRQInfo1 = parse.cftable_entry.irq.IRQInfo1;
/* 0x40 causes it to generate level mode interrupts. */
/* 0x04 enables IREQ pin. */
cor_value = parse.cftable_entry.index | 0x44;
link->conf.ConfigIndex = cor_value;
/* IRQ and I/O settings */
tuple.DesiredTuple = CISTPL_CONFIG;
ret = pcmcia_get_first_tuple(link, &tuple);
if (ret != CS_SUCCESS) {
cs_error(link, GetFirstTuple, ret);
goto exit0;
}
ret = pcmcia_get_tuple_data(link, &tuple);
if (ret != CS_SUCCESS) {
cs_error(link, GetTupleData, ret);
goto exit0;
}
ret = pcmcia_parse_tuple(link, &tuple, &parse);
if (ret != CS_SUCCESS) {
cs_error(link, GetTupleData, ret);
goto exit0;
}
link->conf.Attributes = CONF_ENABLE_IRQ;
link->conf.ConfigBase = parse.config.base;
link->conf.Present = parse.config.rmask[0];
link->conf.IntType = INT_MEMORY_AND_IO;
link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT;
link->irq.Handler = ipwireless_interrupt;
link->irq.Instance = ipw->hardware;
ret = pcmcia_request_io(link, &link->io);
if (ret != CS_SUCCESS) {
cs_error(link, RequestIO, ret);
goto exit0;
}
/* memory settings */
tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
ret = pcmcia_get_first_tuple(link, &tuple);
if (ret != CS_SUCCESS) {
cs_error(link, GetFirstTuple, ret);
goto exit1;
}
ret = pcmcia_get_tuple_data(link, &tuple);
if (ret != CS_SUCCESS) {
cs_error(link, GetTupleData, ret);
goto exit1;
}
ret = pcmcia_parse_tuple(link, &tuple, &parse);
if (ret != CS_SUCCESS) {
cs_error(link, ParseTuple, ret);
goto exit1;
}
if (parse.cftable_entry.mem.nwin > 0) {
request_common_memory.Attributes =
WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM | WIN_ENABLE;
request_common_memory.Base =
parse.cftable_entry.mem.win[0].host_addr;
request_common_memory.Size = parse.cftable_entry.mem.win[0].len;
if (request_common_memory.Size < 0x1000)
request_common_memory.Size = 0x1000;
request_common_memory.AccessSpeed = 0;
ret = pcmcia_request_window(&link, &request_common_memory,
&ipw->handle_common_memory);
if (ret != CS_SUCCESS) {
cs_error(link, RequestWindow, ret);
goto exit1;
}
memreq_common_memory.CardOffset =
parse.cftable_entry.mem.win[0].card_addr;
memreq_common_memory.Page = 0;
ret = pcmcia_map_mem_page(ipw->handle_common_memory,
&memreq_common_memory);
if (ret != CS_SUCCESS) {
cs_error(link, MapMemPage, ret);
goto exit1;
}
ipw->is_v2_card =
parse.cftable_entry.mem.win[0].len == 0x100;
ipw->common_memory = ioremap(request_common_memory.Base,
request_common_memory.Size);
request_attr_memory.Attributes =
WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_AM | WIN_ENABLE;
request_attr_memory.Base = 0;
request_attr_memory.Size = 0; /* this used to be 0x1000 */
request_attr_memory.AccessSpeed = 0;
ret = pcmcia_request_window(&link, &request_attr_memory,
&ipw->handle_attr_memory);
if (ret != CS_SUCCESS) {
cs_error(link, RequestWindow, ret);
goto exit2;
}
memreq_attr_memory.CardOffset = 0;
memreq_attr_memory.Page = 0;
ret = pcmcia_map_mem_page(ipw->handle_attr_memory,
&memreq_attr_memory);
if (ret != CS_SUCCESS) {
cs_error(link, MapMemPage, ret);
goto exit2;
}
ipw->attr_memory = ioremap(request_attr_memory.Base,
request_attr_memory.Size);
}
INIT_WORK(&ipw->work_reboot, signalled_reboot_work);
ipwireless_init_hardware_v1(ipw->hardware, link->io.BasePort1,
ipw->attr_memory, ipw->common_memory,
ipw->is_v2_card, signalled_reboot_callback,
ipw);
ret = pcmcia_request_irq(link, &link->irq);
if (ret != CS_SUCCESS) {
cs_error(link, RequestIRQ, ret);
goto exit3;
}
/* Look up current Vcc */
ret = pcmcia_get_configuration_info(link, &conf);
if (ret != CS_SUCCESS) {
cs_error(link, GetConfigurationInfo, ret);
goto exit4;
}
printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": Card type %s\n",
ipw->is_v2_card ? "V2/V3" : "V1");
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": I/O ports 0x%04x-0x%04x, irq %d\n",
(unsigned int) link->io.BasePort1,
(unsigned int) (link->io.BasePort1 +
link->io.NumPorts1 - 1),
(unsigned int) link->irq.AssignedIRQ);
if (ipw->attr_memory && ipw->common_memory)
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": attr memory 0x%08lx-0x%08lx, "
"common memory 0x%08lx-0x%08lx\n",
request_attr_memory.Base,
request_attr_memory.Base
+ request_attr_memory.Size - 1,
request_common_memory.Base,
request_common_memory.Base
+ request_common_memory.Size - 1);
ipw->network = ipwireless_network_create(ipw->hardware);
if (!ipw->network)
goto exit3;
ipw->tty = ipwireless_tty_create(ipw->hardware, ipw->network,
ipw->nodes);
if (!ipw->tty)
goto exit3;
ipwireless_init_hardware_v2_v3(ipw->hardware);
/*
* Do the RequestConfiguration last, because it enables interrupts.
* Then we don't get any interrupts before we're ready for them.
*/
ret = pcmcia_request_configuration(link, &link->conf);
if (ret != CS_SUCCESS) {
cs_error(link, RequestConfiguration, ret);
goto exit4;
}
link->dev_node = &ipw->nodes[0];
return 0;
exit4:
pcmcia_disable_device(link);
exit3:
if (ipw->attr_memory) {
iounmap(ipw->attr_memory);
pcmcia_release_window(ipw->handle_attr_memory);
pcmcia_disable_device(link);
}
exit2:
if (ipw->common_memory) {
iounmap(ipw->common_memory);
pcmcia_release_window(ipw->handle_common_memory);
}
exit1:
pcmcia_disable_device(link);
exit0:
return -1;
}
static void release_ipwireless(struct ipw_dev *ipw)
{
struct pcmcia_device *link = ipw->link;
pcmcia_disable_device(link);
if (ipw->common_memory)
iounmap(ipw->common_memory);
if (ipw->attr_memory)
iounmap(ipw->attr_memory);
if (ipw->common_memory)
pcmcia_release_window(ipw->handle_common_memory);
if (ipw->attr_memory)
pcmcia_release_window(ipw->handle_attr_memory);
pcmcia_disable_device(link);
}
/*
* ipwireless_attach() creates an "instance" of the driver, allocating
* local data structures for one device (one interface). The device
* is registered with Card Services.
*
* The pcmcia_device structure is initialized, but we don't actually
* configure the card at this point -- we wait until we receive a
* card insertion event.
*/
static int ipwireless_attach(struct pcmcia_device *link)
{
struct ipw_dev *ipw;
int ret;
ipw = kzalloc(sizeof(struct ipw_dev), GFP_KERNEL);
if (!ipw)
return -ENOMEM;
ipw->link = link;
link->priv = ipw;
link->irq.Instance = ipw;
/* Link this device into our device list. */
link->dev_node = &ipw->nodes[0];
ipw->hardware = ipwireless_hardware_create();
if (!ipw->hardware) {
kfree(ipw);
return -ENOMEM;
}
/* RegisterClient will call config_ipwireless */
ret = config_ipwireless(ipw);
if (ret != 0) {
cs_error(link, RegisterClient, ret);
ipwireless_detach(link);
return ret;
}
return 0;
}
/*
* This deletes a driver "instance". The device is de-registered with
* Card Services. If it has been released, all local data structures
* are freed. Otherwise, the structures will be freed when the device
* is released.
*/
static void ipwireless_detach(struct pcmcia_device *link)
{
struct ipw_dev *ipw = link->priv;
release_ipwireless(ipw);
/* Break the link with Card Services */
if (link)
pcmcia_disable_device(link);
if (ipw->tty != NULL)
ipwireless_tty_free(ipw->tty);
if (ipw->network != NULL)
ipwireless_network_free(ipw->network);
if (ipw->hardware != NULL)
ipwireless_hardware_free(ipw->hardware);
kfree(ipw);
}
static struct pcmcia_driver me = {
.owner = THIS_MODULE,
.probe = ipwireless_attach,
.remove = ipwireless_detach,
.drv = { .name = IPWIRELESS_PCCARD_NAME },
.id_table = ipw_ids
};
/*
* Module insertion : initialisation of the module.
* Register the card with cardmgr...
*/
static int __init init_ipwireless(void)
{
int ret;
printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
IPWIRELESS_PCMCIA_VERSION " by " IPWIRELESS_PCMCIA_AUTHOR "\n");
ret = ipwireless_tty_init();
if (ret != 0)
return ret;
ret = pcmcia_register_driver(&me);
if (ret != 0)
ipwireless_tty_release();
return ret;
}
/*
* Module removal
*/
static void __exit exit_ipwireless(void)
{
printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
IPWIRELESS_PCMCIA_VERSION " removed\n");
pcmcia_unregister_driver(&me);
ipwireless_tty_release();
}
module_init(init_ipwireless);
module_exit(exit_ipwireless);
MODULE_AUTHOR(IPWIRELESS_PCMCIA_AUTHOR);
MODULE_DESCRIPTION(IPWIRELESS_PCCARD_NAME " " IPWIRELESS_PCMCIA_VERSION);
MODULE_LICENSE("GPL");

View File

@ -0,0 +1,70 @@
/*
* IPWireless 3G PCMCIA Network Driver
*
* Original code
* by Stephen Blackheath <stephen@blacksapphire.com>,
* Ben Martel <benm@symmetric.co.nz>
*
* Copyrighted as follows:
* Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
*
* Various driver changes and rewrites, port to new kernels
* Copyright (C) 2006-2007 Jiri Kosina
*
* Misc code cleanups and updates
* Copyright (C) 2007 David Sterba
*/
#ifndef _IPWIRELESS_CS_H_
#define _IPWIRELESS_CS_H_
#include <linux/sched.h>
#include <linux/types.h>
#include <pcmcia/cs_types.h>
#include <pcmcia/cs.h>
#include <pcmcia/cistpl.h>
#include <pcmcia/ds.h>
#include "hardware.h"
#define IPWIRELESS_PCCARD_NAME "ipwireless"
#define IPWIRELESS_PCMCIA_VERSION "1.1"
#define IPWIRELESS_PCMCIA_AUTHOR \
"Stephen Blackheath, Ben Martel, Jiri Kosina and David Sterba"
#define IPWIRELESS_TX_QUEUE_SIZE 262144
#define IPWIRELESS_RX_QUEUE_SIZE 262144
#define IPWIRELESS_STATE_DEBUG
struct ipw_hardware;
struct ipw_network;
struct ipw_tty;
struct ipw_dev {
struct pcmcia_device *link;
int is_v2_card;
window_handle_t handle_attr_memory;
void __iomem *attr_memory;
window_handle_t handle_common_memory;
void __iomem *common_memory;
dev_node_t nodes[2];
/* Reference to attribute memory, containing CIS data */
void *attribute_memory;
/* Hardware context */
struct ipw_hardware *hardware;
/* Network layer context */
struct ipw_network *network;
/* TTY device context */
struct ipw_tty *tty;
struct work_struct work_reboot;
};
/* Module parametres */
extern int ipwireless_debug;
extern int ipwireless_loopback;
extern int ipwireless_out_queue;
#endif

View File

@ -0,0 +1,512 @@
/*
* IPWireless 3G PCMCIA Network Driver
*
* Original code
* by Stephen Blackheath <stephen@blacksapphire.com>,
* Ben Martel <benm@symmetric.co.nz>
*
* Copyrighted as follows:
* Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
*
* Various driver changes and rewrites, port to new kernels
* Copyright (C) 2006-2007 Jiri Kosina
*
* Misc code cleanups and updates
* Copyright (C) 2007 David Sterba
*/
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/mutex.h>
#include <linux/netdevice.h>
#include <linux/ppp_channel.h>
#include <linux/ppp_defs.h>
#include <linux/if_ppp.h>
#include <linux/skbuff.h>
#include "network.h"
#include "hardware.h"
#include "main.h"
#include "tty.h"
#define MAX_OUTGOING_PACKETS_QUEUED ipwireless_out_queue
#define MAX_ASSOCIATED_TTYS 2
#define SC_RCV_BITS (SC_RCV_B7_1|SC_RCV_B7_0|SC_RCV_ODDP|SC_RCV_EVNP)
struct ipw_network {
/* Hardware context, used for calls to hardware layer. */
struct ipw_hardware *hardware;
/* Context for kernel 'generic_ppp' functionality */
struct ppp_channel *ppp_channel;
/* tty context connected with IPW console */
struct ipw_tty *associated_ttys[NO_OF_IPW_CHANNELS][MAX_ASSOCIATED_TTYS];
/* True if ppp needs waking up once we're ready to xmit */
int ppp_blocked;
/* Number of packets queued up in hardware module. */
int outgoing_packets_queued;
/* Spinlock to avoid interrupts during shutdown */
spinlock_t spinlock;
struct mutex close_lock;
/* PPP ioctl data, not actually used anywere */
unsigned int flags;
unsigned int rbits;
u32 xaccm[8];
u32 raccm;
int mru;
int shutting_down;
unsigned int ras_control_lines;
struct work_struct work_go_online;
struct work_struct work_go_offline;
};
#ifdef IPWIRELESS_STATE_DEBUG
int ipwireless_dump_network_state(char *p, size_t limit,
struct ipw_network *network)
{
return snprintf(p, limit,
"debug: ppp_blocked=%d\n"
"debug: outgoing_packets_queued=%d\n"
"debug: network.shutting_down=%d\n",
network->ppp_blocked,
network->outgoing_packets_queued,
network->shutting_down);
}
#endif
static void notify_packet_sent(void *callback_data, unsigned int packet_length)
{
struct ipw_network *network = callback_data;
unsigned long flags;
spin_lock_irqsave(&network->spinlock, flags);
network->outgoing_packets_queued--;
if (network->ppp_channel != NULL) {
if (network->ppp_blocked) {
network->ppp_blocked = 0;
spin_unlock_irqrestore(&network->spinlock, flags);
ppp_output_wakeup(network->ppp_channel);
if (ipwireless_debug)
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": ppp unblocked\n");
} else
spin_unlock_irqrestore(&network->spinlock, flags);
} else
spin_unlock_irqrestore(&network->spinlock, flags);
}
/*
* Called by the ppp system when it has a packet to send to the hardware.
*/
static int ipwireless_ppp_start_xmit(struct ppp_channel *ppp_channel,
struct sk_buff *skb)
{
struct ipw_network *network = ppp_channel->private;
unsigned long flags;
spin_lock_irqsave(&network->spinlock, flags);
if (network->outgoing_packets_queued < MAX_OUTGOING_PACKETS_QUEUED) {
unsigned char *buf;
static unsigned char header[] = {
PPP_ALLSTATIONS, /* 0xff */
PPP_UI, /* 0x03 */
};
int ret;
network->outgoing_packets_queued++;
spin_unlock_irqrestore(&network->spinlock, flags);
/*
* If we have the requested amount of headroom in the skb we
* were handed, then we can add the header efficiently.
*/
if (skb_headroom(skb) >= 2) {
memcpy(skb_push(skb, 2), header, 2);
ret = ipwireless_send_packet(network->hardware,
IPW_CHANNEL_RAS, skb->data,
skb->len,
notify_packet_sent,
network);
if (ret == -1) {
skb_pull(skb, 2);
return 0;
}
} else {
/* Otherwise (rarely) we do it inefficiently. */
buf = kmalloc(skb->len + 2, GFP_ATOMIC);
if (!buf)
return 0;
memcpy(buf + 2, skb->data, skb->len);
memcpy(buf, header, 2);
ret = ipwireless_send_packet(network->hardware,
IPW_CHANNEL_RAS, buf,
skb->len + 2,
notify_packet_sent,
network);
kfree(buf);
if (ret == -1)
return 0;
}
kfree_skb(skb);
return 1;
} else {
/*
* Otherwise reject the packet, and flag that the ppp system
* needs to be unblocked once we are ready to send.
*/
network->ppp_blocked = 1;
spin_unlock_irqrestore(&network->spinlock, flags);
return 0;
}
}
/* Handle an ioctl call that has come in via ppp. (copy of ppp_async_ioctl() */
static int ipwireless_ppp_ioctl(struct ppp_channel *ppp_channel,
unsigned int cmd, unsigned long arg)
{
struct ipw_network *network = ppp_channel->private;
int err, val;
u32 accm[8];
int __user *user_arg = (int __user *) arg;
err = -EFAULT;
switch (cmd) {
case PPPIOCGFLAGS:
val = network->flags | network->rbits;
if (put_user(val, user_arg))
break;
err = 0;
break;
case PPPIOCSFLAGS:
if (get_user(val, user_arg))
break;
network->flags = val & ~SC_RCV_BITS;
network->rbits = val & SC_RCV_BITS;
err = 0;
break;
case PPPIOCGASYNCMAP:
if (put_user(network->xaccm[0], user_arg))
break;
err = 0;
break;
case PPPIOCSASYNCMAP:
if (get_user(network->xaccm[0], user_arg))
break;
err = 0;
break;
case PPPIOCGRASYNCMAP:
if (put_user(network->raccm, user_arg))
break;
err = 0;
break;
case PPPIOCSRASYNCMAP:
if (get_user(network->raccm, user_arg))
break;
err = 0;
break;
case PPPIOCGXASYNCMAP:
if (copy_to_user((void __user *) arg, network->xaccm,
sizeof(network->xaccm)))
break;
err = 0;
break;
case PPPIOCSXASYNCMAP:
if (copy_from_user(accm, (void __user *) arg, sizeof(accm)))
break;
accm[2] &= ~0x40000000U; /* can't escape 0x5e */
accm[3] |= 0x60000000U; /* must escape 0x7d, 0x7e */
memcpy(network->xaccm, accm, sizeof(network->xaccm));
err = 0;
break;
case PPPIOCGMRU:
if (put_user(network->mru, user_arg))
break;
err = 0;
break;
case PPPIOCSMRU:
if (get_user(val, user_arg))
break;
if (val < PPP_MRU)
val = PPP_MRU;
network->mru = val;
err = 0;
break;
default:
err = -ENOTTY;
}
return err;
}
static struct ppp_channel_ops ipwireless_ppp_channel_ops = {
.start_xmit = ipwireless_ppp_start_xmit,
.ioctl = ipwireless_ppp_ioctl
};
static void do_go_online(struct work_struct *work_go_online)
{
struct ipw_network *network =
container_of(work_go_online, struct ipw_network,
work_go_online);
unsigned long flags;
spin_lock_irqsave(&network->spinlock, flags);
if (!network->ppp_channel) {
struct ppp_channel *channel;
spin_unlock_irqrestore(&network->spinlock, flags);
channel = kzalloc(sizeof(struct ppp_channel), GFP_KERNEL);
if (!channel) {
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": unable to allocate PPP channel\n");
return;
}
channel->private = network;
channel->mtu = 16384; /* Wild guess */
channel->hdrlen = 2;
channel->ops = &ipwireless_ppp_channel_ops;
network->flags = 0;
network->rbits = 0;
network->mru = PPP_MRU;
memset(network->xaccm, 0, sizeof(network->xaccm));
network->xaccm[0] = ~0U;
network->xaccm[3] = 0x60000000U;
network->raccm = ~0U;
ppp_register_channel(channel);
spin_lock_irqsave(&network->spinlock, flags);
network->ppp_channel = channel;
}
spin_unlock_irqrestore(&network->spinlock, flags);
}
static void do_go_offline(struct work_struct *work_go_offline)
{
struct ipw_network *network =
container_of(work_go_offline, struct ipw_network,
work_go_offline);
unsigned long flags;
mutex_lock(&network->close_lock);
spin_lock_irqsave(&network->spinlock, flags);
if (network->ppp_channel != NULL) {
struct ppp_channel *channel = network->ppp_channel;
network->ppp_channel = NULL;
spin_unlock_irqrestore(&network->spinlock, flags);
mutex_unlock(&network->close_lock);
ppp_unregister_channel(channel);
} else {
spin_unlock_irqrestore(&network->spinlock, flags);
mutex_unlock(&network->close_lock);
}
}
void ipwireless_network_notify_control_line_change(struct ipw_network *network,
unsigned int channel_idx,
unsigned int control_lines,
unsigned int changed_mask)
{
int i;
if (channel_idx == IPW_CHANNEL_RAS)
network->ras_control_lines = control_lines;
for (i = 0; i < MAX_ASSOCIATED_TTYS; i++) {
struct ipw_tty *tty =
network->associated_ttys[channel_idx][i];
/*
* If it's associated with a tty (other than the RAS channel
* when we're online), then send the data to that tty. The RAS
* channel's data is handled above - it always goes through
* ppp_generic.
*/
if (tty)
ipwireless_tty_notify_control_line_change(tty,
channel_idx,
control_lines,
changed_mask);
}
}
/*
* Some versions of firmware stuff packets with 0xff 0x03 (PPP: ALLSTATIONS, UI)
* bytes, which are required on sent packet, but not always present on received
* packets
*/
static struct sk_buff *ipw_packet_received_skb(unsigned char *data,
unsigned int length)
{
struct sk_buff *skb;
if (length > 2 && data[0] == PPP_ALLSTATIONS && data[1] == PPP_UI) {
length -= 2;
data += 2;
}
skb = dev_alloc_skb(length + 4);
skb_reserve(skb, 2);
memcpy(skb_put(skb, length), data, length);
return skb;
}
void ipwireless_network_packet_received(struct ipw_network *network,
unsigned int channel_idx,
unsigned char *data,
unsigned int length)
{
int i;
unsigned long flags;
for (i = 0; i < MAX_ASSOCIATED_TTYS; i++) {
struct ipw_tty *tty = network->associated_ttys[channel_idx][i];
/*
* If it's associated with a tty (other than the RAS channel
* when we're online), then send the data to that tty. The RAS
* channel's data is handled above - it always goes through
* ppp_generic.
*/
if (tty && channel_idx == IPW_CHANNEL_RAS
&& (network->ras_control_lines &
IPW_CONTROL_LINE_DCD) != 0
&& ipwireless_tty_is_modem(tty)) {
/*
* If data came in on the RAS channel and this tty is
* the modem tty, and we are online, then we send it to
* the PPP layer.
*/
mutex_lock(&network->close_lock);
spin_lock_irqsave(&network->spinlock, flags);
if (network->ppp_channel != NULL) {
struct sk_buff *skb;
spin_unlock_irqrestore(&network->spinlock,
flags);
/* Send the data to the ppp_generic module. */
skb = ipw_packet_received_skb(data, length);
ppp_input(network->ppp_channel, skb);
} else
spin_unlock_irqrestore(&network->spinlock,
flags);
mutex_unlock(&network->close_lock);
}
/* Otherwise we send it out the tty. */
else
ipwireless_tty_received(tty, data, length);
}
}
struct ipw_network *ipwireless_network_create(struct ipw_hardware *hw)
{
struct ipw_network *network =
kzalloc(sizeof(struct ipw_network), GFP_ATOMIC);
if (!network)
return NULL;
spin_lock_init(&network->spinlock);
mutex_init(&network->close_lock);
network->hardware = hw;
INIT_WORK(&network->work_go_online, do_go_online);
INIT_WORK(&network->work_go_offline, do_go_offline);
ipwireless_associate_network(hw, network);
return network;
}
void ipwireless_network_free(struct ipw_network *network)
{
network->shutting_down = 1;
ipwireless_ppp_close(network);
flush_scheduled_work();
ipwireless_stop_interrupts(network->hardware);
ipwireless_associate_network(network->hardware, NULL);
kfree(network);
}
void ipwireless_associate_network_tty(struct ipw_network *network,
unsigned int channel_idx,
struct ipw_tty *tty)
{
int i;
for (i = 0; i < MAX_ASSOCIATED_TTYS; i++)
if (network->associated_ttys[channel_idx][i] == NULL) {
network->associated_ttys[channel_idx][i] = tty;
break;
}
}
void ipwireless_disassociate_network_ttys(struct ipw_network *network,
unsigned int channel_idx)
{
int i;
for (i = 0; i < MAX_ASSOCIATED_TTYS; i++)
network->associated_ttys[channel_idx][i] = NULL;
}
void ipwireless_ppp_open(struct ipw_network *network)
{
if (ipwireless_debug)
printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME ": online\n");
schedule_work(&network->work_go_online);
}
void ipwireless_ppp_close(struct ipw_network *network)
{
/* Disconnect from the wireless network. */
if (ipwireless_debug)
printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME ": offline\n");
schedule_work(&network->work_go_offline);
}
int ipwireless_ppp_channel_index(struct ipw_network *network)
{
int ret = -1;
unsigned long flags;
spin_lock_irqsave(&network->spinlock, flags);
if (network->ppp_channel != NULL)
ret = ppp_channel_index(network->ppp_channel);
spin_unlock_irqrestore(&network->spinlock, flags);
return ret;
}
int ipwireless_ppp_unit_number(struct ipw_network *network)
{
int ret = -1;
unsigned long flags;
spin_lock_irqsave(&network->spinlock, flags);
if (network->ppp_channel != NULL)
ret = ppp_unit_number(network->ppp_channel);
spin_unlock_irqrestore(&network->spinlock, flags);
return ret;
}

View File

@ -0,0 +1,55 @@
/*
* IPWireless 3G PCMCIA Network Driver
*
* Original code
* by Stephen Blackheath <stephen@blacksapphire.com>,
* Ben Martel <benm@symmetric.co.nz>
*
* Copyrighted as follows:
* Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
*
* Various driver changes and rewrites, port to new kernels
* Copyright (C) 2006-2007 Jiri Kosina
*
* Misc code cleanups and updates
* Copyright (C) 2007 David Sterba
*/
#ifndef _IPWIRELESS_CS_NETWORK_H_
#define _IPWIRELESS_CS_NETWORK_H_
#include <linux/types.h>
struct ipw_network;
struct ipw_tty;
struct ipw_hardware;
/* Definitions of the different channels on the PCMCIA UE */
#define IPW_CHANNEL_RAS 0
#define IPW_CHANNEL_DIALLER 1
#define IPW_CHANNEL_CONSOLE 2
#define NO_OF_IPW_CHANNELS 5
void ipwireless_network_notify_control_line_change(struct ipw_network *net,
unsigned int channel_idx, unsigned int control_lines,
unsigned int control_mask);
void ipwireless_network_packet_received(struct ipw_network *net,
unsigned int channel_idx, unsigned char *data,
unsigned int length);
struct ipw_network *ipwireless_network_create(struct ipw_hardware *hw);
void ipwireless_network_free(struct ipw_network *net);
void ipwireless_associate_network_tty(struct ipw_network *net,
unsigned int channel_idx, struct ipw_tty *tty);
void ipwireless_disassociate_network_ttys(struct ipw_network *net,
unsigned int channel_idx);
void ipwireless_ppp_open(struct ipw_network *net);
void ipwireless_ppp_close(struct ipw_network *net);
int ipwireless_ppp_channel_index(struct ipw_network *net);
int ipwireless_ppp_unit_number(struct ipw_network *net);
int ipwireless_dump_network_state(char *p, size_t limit,
struct ipw_network *net);
#endif

View File

@ -0,0 +1,108 @@
/*
* IPWireless 3G PCMCIA Network Driver
*
* Original code
* by Stephen Blackheath <stephen@blacksapphire.com>,
* Ben Martel <benm@symmetric.co.nz>
*
* Copyrighted as follows:
* Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
*
* Various driver changes and rewrites, port to new kernels
* Copyright (C) 2006-2007 Jiri Kosina
*
* Misc code cleanups and updates
* Copyright (C) 2007 David Sterba
*/
#ifndef _IPWIRELESS_CS_SETUP_PROTOCOL_H_
#define _IPWIRELESS_CS_SETUP_PROTOCOL_H_
/* Version of the setup protocol and transport protocols */
#define TL_SETUP_VERSION 1
#define TL_SETUP_VERSION_QRY_TMO 1000
#define TL_SETUP_MAX_VERSION_QRY 30
/* Message numbers 0-9 are obsoleted and must not be reused! */
#define TL_SETUP_SIGNO_GET_VERSION_QRY 10
#define TL_SETUP_SIGNO_GET_VERSION_RSP 11
#define TL_SETUP_SIGNO_CONFIG_MSG 12
#define TL_SETUP_SIGNO_CONFIG_DONE_MSG 13
#define TL_SETUP_SIGNO_OPEN_MSG 14
#define TL_SETUP_SIGNO_CLOSE_MSG 15
#define TL_SETUP_SIGNO_INFO_MSG 20
#define TL_SETUP_SIGNO_INFO_MSG_ACK 21
#define TL_SETUP_SIGNO_REBOOT_MSG 22
#define TL_SETUP_SIGNO_REBOOT_MSG_ACK 23
/* Synchronous start-messages */
struct tl_setup_get_version_qry {
unsigned char sig_no; /* TL_SETUP_SIGNO_GET_VERSION_QRY */
} __attribute__ ((__packed__));
struct tl_setup_get_version_rsp {
unsigned char sig_no; /* TL_SETUP_SIGNO_GET_VERSION_RSP */
unsigned char version; /* TL_SETUP_VERSION */
} __attribute__ ((__packed__));
struct tl_setup_config_msg {
unsigned char sig_no; /* TL_SETUP_SIGNO_CONFIG_MSG */
unsigned char port_no;
unsigned char prio_data;
unsigned char prio_ctrl;
} __attribute__ ((__packed__));
struct tl_setup_config_done_msg {
unsigned char sig_no; /* TL_SETUP_SIGNO_CONFIG_DONE_MSG */
} __attribute__ ((__packed__));
/* Asyncronous messages */
struct tl_setup_open_msg {
unsigned char sig_no; /* TL_SETUP_SIGNO_OPEN_MSG */
unsigned char port_no;
} __attribute__ ((__packed__));
struct tl_setup_close_msg {
unsigned char sig_no; /* TL_SETUP_SIGNO_CLOSE_MSG */
unsigned char port_no;
} __attribute__ ((__packed__));
/* Driver type - for use in tl_setup_info_msg.driver_type */
#define COMM_DRIVER 0
#define NDISWAN_DRIVER 1
#define NDISWAN_DRIVER_MAJOR_VERSION 2
#define NDISWAN_DRIVER_MINOR_VERSION 0
/*
* It should not matter when this message comes over as we just store the
* results and send the ACK.
*/
struct tl_setup_info_msg {
unsigned char sig_no; /* TL_SETUP_SIGNO_INFO_MSG */
unsigned char driver_type;
unsigned char major_version;
unsigned char minor_version;
} __attribute__ ((__packed__));
struct tl_setup_info_msgAck {
unsigned char sig_no; /* TL_SETUP_SIGNO_INFO_MSG_ACK */
} __attribute__ ((__packed__));
struct TlSetupRebootMsgAck {
unsigned char sig_no; /* TL_SETUP_SIGNO_REBOOT_MSG_ACK */
} __attribute__ ((__packed__));
/* Define a union of all the msgs that the driver can receive from the card.*/
union ipw_setup_rx_msg {
unsigned char sig_no;
struct tl_setup_get_version_rsp version_rsp_msg;
struct tl_setup_open_msg open_msg;
struct tl_setup_close_msg close_msg;
struct tl_setup_info_msg InfoMsg;
struct tl_setup_info_msgAck info_msg_ack;
} __attribute__ ((__packed__));
#endif /* _IPWIRELESS_CS_SETUP_PROTOCOL_H_ */

View File

@ -0,0 +1,688 @@
/*
* IPWireless 3G PCMCIA Network Driver
*
* Original code
* by Stephen Blackheath <stephen@blacksapphire.com>,
* Ben Martel <benm@symmetric.co.nz>
*
* Copyrighted as follows:
* Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
*
* Various driver changes and rewrites, port to new kernels
* Copyright (C) 2006-2007 Jiri Kosina
*
* Misc code cleanups and updates
* Copyright (C) 2007 David Sterba
*/
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/ppp_defs.h>
#include <linux/if.h>
#include <linux/if_ppp.h>
#include <linux/sched.h>
#include <linux/serial.h>
#include <linux/slab.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/uaccess.h>
#include <linux/version.h>
#include "tty.h"
#include "network.h"
#include "hardware.h"
#include "main.h"
#define IPWIRELESS_PCMCIA_START (0)
#define IPWIRELESS_PCMCIA_MINORS (24)
#define IPWIRELESS_PCMCIA_MINOR_RANGE (8)
#define TTYTYPE_MODEM (0)
#define TTYTYPE_MONITOR (1)
#define TTYTYPE_RAS_RAW (2)
struct ipw_tty {
int index;
struct ipw_hardware *hardware;
unsigned int channel_idx;
unsigned int secondary_channel_idx;
int tty_type;
struct ipw_network *network;
struct tty_struct *linux_tty;
int open_count;
unsigned int control_lines;
struct mutex ipw_tty_mutex;
int tx_bytes_queued;
int closing;
};
static struct ipw_tty *ttys[IPWIRELESS_PCMCIA_MINORS];
static struct tty_driver *ipw_tty_driver;
static char *tty_type_name(int tty_type)
{
static char *channel_names[] = {
"modem",
"monitor",
"RAS-raw"
};
return channel_names[tty_type];
}
static void report_registering(struct ipw_tty *tty)
{
char *iftype = tty_type_name(tty->tty_type);
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": registering %s device ttyIPWp%d\n", iftype, tty->index);
}
static void report_deregistering(struct ipw_tty *tty)
{
char *iftype = tty_type_name(tty->tty_type);
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": deregistering %s device ttyIPWp%d\n", iftype,
tty->index);
}
static struct ipw_tty *get_tty(int minor)
{
if (minor < ipw_tty_driver->minor_start
|| minor >= ipw_tty_driver->minor_start +
IPWIRELESS_PCMCIA_MINORS)
return NULL;
else {
int minor_offset = minor - ipw_tty_driver->minor_start;
/*
* The 'ras_raw' channel is only available when 'loopback' mode
* is enabled.
* Number of minor starts with 16 (_RANGE * _RAS_RAW).
*/
if (!ipwireless_loopback &&
minor_offset >=
IPWIRELESS_PCMCIA_MINOR_RANGE * TTYTYPE_RAS_RAW)
return NULL;
return ttys[minor_offset];
}
}
static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
{
int minor = linux_tty->index;
struct ipw_tty *tty = get_tty(minor);
if (!tty)
return -ENODEV;
mutex_lock(&tty->ipw_tty_mutex);
if (tty->closing) {
mutex_unlock(&tty->ipw_tty_mutex);
return -ENODEV;
}
if (tty->open_count == 0)
tty->tx_bytes_queued = 0;
tty->open_count++;
tty->linux_tty = linux_tty;
linux_tty->driver_data = tty;
linux_tty->low_latency = 1;
if (tty->tty_type == TTYTYPE_MODEM)
ipwireless_ppp_open(tty->network);
mutex_unlock(&tty->ipw_tty_mutex);
return 0;
}
static void do_ipw_close(struct ipw_tty *tty)
{
tty->open_count--;
if (tty->open_count == 0) {
struct tty_struct *linux_tty = tty->linux_tty;
if (linux_tty != NULL) {
tty->linux_tty = NULL;
linux_tty->driver_data = NULL;
if (tty->tty_type == TTYTYPE_MODEM)
ipwireless_ppp_close(tty->network);
}
}
}
static void ipw_hangup(struct tty_struct *linux_tty)
{
struct ipw_tty *tty = linux_tty->driver_data;
if (!tty)
return;
mutex_lock(&tty->ipw_tty_mutex);
if (tty->open_count == 0) {
mutex_unlock(&tty->ipw_tty_mutex);
return;
}
do_ipw_close(tty);
mutex_unlock(&tty->ipw_tty_mutex);
}
static void ipw_close(struct tty_struct *linux_tty, struct file *filp)
{
ipw_hangup(linux_tty);
}
/* Take data received from hardware, and send it out the tty */
void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
unsigned int length)
{
struct tty_struct *linux_tty;
int work = 0;
mutex_lock(&tty->ipw_tty_mutex);
linux_tty = tty->linux_tty;
if (linux_tty == NULL) {
mutex_unlock(&tty->ipw_tty_mutex);
return;
}
if (!tty->open_count) {
mutex_unlock(&tty->ipw_tty_mutex);
return;
}
mutex_unlock(&tty->ipw_tty_mutex);
work = tty_insert_flip_string(linux_tty, data, length);
if (work != length)
printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
": %d chars not inserted to flip buffer!\n",
length - work);
/*
* This may sleep if ->low_latency is set
*/
if (work)
tty_flip_buffer_push(linux_tty);
}
static void ipw_write_packet_sent_callback(void *callback_data,
unsigned int packet_length)
{
struct ipw_tty *tty = callback_data;
/*
* Packet has been sent, so we subtract the number of bytes from our
* tally of outstanding TX bytes.
*/
tty->tx_bytes_queued -= packet_length;
}
static int ipw_write(struct tty_struct *linux_tty,
const unsigned char *buf, int count)
{
struct ipw_tty *tty = linux_tty->driver_data;
int room, ret;
if (!tty)
return -ENODEV;
mutex_lock(&tty->ipw_tty_mutex);
if (!tty->open_count) {
mutex_unlock(&tty->ipw_tty_mutex);
return -EINVAL;
}
room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
if (room < 0)
room = 0;
/* Don't allow caller to write any more than we have room for */
if (count > room)
count = room;
if (count == 0) {
mutex_unlock(&tty->ipw_tty_mutex);
return 0;
}
ret = ipwireless_send_packet(tty->hardware, IPW_CHANNEL_RAS,
(unsigned char *) buf, count,
ipw_write_packet_sent_callback, tty);
if (ret == -1) {
mutex_unlock(&tty->ipw_tty_mutex);
return 0;
}
tty->tx_bytes_queued += count;
mutex_unlock(&tty->ipw_tty_mutex);
return count;
}
static int ipw_write_room(struct tty_struct *linux_tty)
{
struct ipw_tty *tty = linux_tty->driver_data;
int room;
if (!tty)
return -ENODEV;
if (!tty->open_count)
return -EINVAL;
room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
if (room < 0)
room = 0;
return room;
}
static int ipwireless_get_serial_info(struct ipw_tty *tty,
struct serial_struct __user *retinfo)
{
struct serial_struct tmp;
if (!retinfo)
return (-EFAULT);
memset(&tmp, 0, sizeof(tmp));
tmp.type = PORT_UNKNOWN;
tmp.line = tty->index;
tmp.port = 0;
tmp.irq = 0;
tmp.flags = 0;
tmp.baud_base = 115200;
tmp.close_delay = 0;
tmp.closing_wait = 0;
tmp.custom_divisor = 0;
tmp.hub6 = 0;
if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
return -EFAULT;
return 0;
}
static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
{
struct ipw_tty *tty = linux_tty->driver_data;
if (!tty)
return -ENODEV;
if (!tty->open_count)
return -EINVAL;
return tty->tx_bytes_queued;
}
static int get_control_lines(struct ipw_tty *tty)
{
unsigned int my = tty->control_lines;
unsigned int out = 0;
if (my & IPW_CONTROL_LINE_RTS)
out |= TIOCM_RTS;
if (my & IPW_CONTROL_LINE_DTR)
out |= TIOCM_DTR;
if (my & IPW_CONTROL_LINE_CTS)
out |= TIOCM_CTS;
if (my & IPW_CONTROL_LINE_DSR)
out |= TIOCM_DSR;
if (my & IPW_CONTROL_LINE_DCD)
out |= TIOCM_CD;
return out;
}
static int set_control_lines(struct ipw_tty *tty, unsigned int set,
unsigned int clear)
{
int ret;
if (set & TIOCM_RTS) {
ret = ipwireless_set_RTS(tty->hardware, tty->channel_idx, 1);
if (ret)
return ret;
if (tty->secondary_channel_idx != -1) {
ret = ipwireless_set_RTS(tty->hardware,
tty->secondary_channel_idx, 1);
if (ret)
return ret;
}
}
if (set & TIOCM_DTR) {
ret = ipwireless_set_DTR(tty->hardware, tty->channel_idx, 1);
if (ret)
return ret;
if (tty->secondary_channel_idx != -1) {
ret = ipwireless_set_DTR(tty->hardware,
tty->secondary_channel_idx, 1);
if (ret)
return ret;
}
}
if (clear & TIOCM_RTS) {
ret = ipwireless_set_RTS(tty->hardware, tty->channel_idx, 0);
if (tty->secondary_channel_idx != -1) {
ret = ipwireless_set_RTS(tty->hardware,
tty->secondary_channel_idx, 0);
if (ret)
return ret;
}
}
if (clear & TIOCM_DTR) {
ret = ipwireless_set_DTR(tty->hardware, tty->channel_idx, 0);
if (tty->secondary_channel_idx != -1) {
ret = ipwireless_set_DTR(tty->hardware,
tty->secondary_channel_idx, 0);
if (ret)
return ret;
}
}
return 0;
}
static int ipw_tiocmget(struct tty_struct *linux_tty, struct file *file)
{
struct ipw_tty *tty = linux_tty->driver_data;
if (!tty)
return -ENODEV;
if (!tty->open_count)
return -EINVAL;
return get_control_lines(tty);
}
static int
ipw_tiocmset(struct tty_struct *linux_tty, struct file *file,
unsigned int set, unsigned int clear)
{
struct ipw_tty *tty = linux_tty->driver_data;
if (!tty)
return -ENODEV;
if (!tty->open_count)
return -EINVAL;
return set_control_lines(tty, set, clear);
}
static int ipw_ioctl(struct tty_struct *linux_tty, struct file *file,
unsigned int cmd, unsigned long arg)
{
struct ipw_tty *tty = linux_tty->driver_data;
if (!tty)
return -ENODEV;
if (!tty->open_count)
return -EINVAL;
switch (cmd) {
case TIOCGSERIAL:
return ipwireless_get_serial_info(tty, (void __user *) arg);
case TIOCSSERIAL:
return 0; /* Keeps the PCMCIA scripts happy. */
}
if (tty->tty_type == TTYTYPE_MODEM) {
switch (cmd) {
case PPPIOCGCHAN:
{
int chan = ipwireless_ppp_channel_index(
tty->network);
if (chan < 0)
return -ENODEV;
if (put_user(chan, (int __user *) arg))
return -EFAULT;
}
return 0;
case PPPIOCGUNIT:
{
int unit = ipwireless_ppp_unit_number(
tty->network);
if (unit < 0)
return -ENODEV;
if (put_user(unit, (int __user *) arg))
return -EFAULT;
}
return 0;
case TCGETS:
case TCGETA:
return n_tty_ioctl(linux_tty, file, cmd, arg);
case TCFLSH:
return n_tty_ioctl(linux_tty, file, cmd, arg);
case FIONREAD:
{
int val = 0;
if (put_user(val, (int __user *) arg))
return -EFAULT;
}
return 0;
}
}
return -ENOIOCTLCMD;
}
static int add_tty(dev_node_t *nodesp, int j,
struct ipw_hardware *hardware,
struct ipw_network *network, int channel_idx,
int secondary_channel_idx, int tty_type)
{
ttys[j] = kzalloc(sizeof(struct ipw_tty), GFP_KERNEL);
if (!ttys[j])
return -ENOMEM;
ttys[j]->index = j;
ttys[j]->hardware = hardware;
ttys[j]->channel_idx = channel_idx;
ttys[j]->secondary_channel_idx = secondary_channel_idx;
ttys[j]->network = network;
ttys[j]->tty_type = tty_type;
mutex_init(&ttys[j]->ipw_tty_mutex);
tty_register_device(ipw_tty_driver, j, NULL);
ipwireless_associate_network_tty(network, channel_idx, ttys[j]);
if (secondary_channel_idx != -1)
ipwireless_associate_network_tty(network,
secondary_channel_idx,
ttys[j]);
if (nodesp != NULL) {
sprintf(nodesp->dev_name, "ttyIPWp%d", j);
nodesp->major = ipw_tty_driver->major;
nodesp->minor = j + ipw_tty_driver->minor_start;
}
if (get_tty(j + ipw_tty_driver->minor_start) == ttys[j])
report_registering(ttys[j]);
return 0;
}
struct ipw_tty *ipwireless_tty_create(struct ipw_hardware *hardware,
struct ipw_network *network,
dev_node_t *nodes)
{
int i, j;
for (i = 0; i < IPWIRELESS_PCMCIA_MINOR_RANGE; i++) {
int allfree = 1;
for (j = i; j < IPWIRELESS_PCMCIA_MINORS;
j += IPWIRELESS_PCMCIA_MINOR_RANGE)
if (ttys[j] != NULL) {
allfree = 0;
break;
}
if (allfree) {
j = i;
if (add_tty(&nodes[0], j, hardware, network,
IPW_CHANNEL_DIALLER, IPW_CHANNEL_RAS,
TTYTYPE_MODEM))
return NULL;
j += IPWIRELESS_PCMCIA_MINOR_RANGE;
if (add_tty(&nodes[1], j, hardware, network,
IPW_CHANNEL_DIALLER, -1,
TTYTYPE_MONITOR))
return NULL;
j += IPWIRELESS_PCMCIA_MINOR_RANGE;
if (add_tty(NULL, j, hardware, network,
IPW_CHANNEL_RAS, -1,
TTYTYPE_RAS_RAW))
return NULL;
nodes[0].next = &nodes[1];
nodes[1].next = NULL;
return ttys[i];
}
}
return NULL;
}
/*
* Must be called before ipwireless_network_free().
*/
void ipwireless_tty_free(struct ipw_tty *tty)
{
int j;
struct ipw_network *network = ttys[tty->index]->network;
for (j = tty->index; j < IPWIRELESS_PCMCIA_MINORS;
j += IPWIRELESS_PCMCIA_MINOR_RANGE) {
struct ipw_tty *ttyj = ttys[j];
if (ttyj) {
mutex_lock(&ttyj->ipw_tty_mutex);
if (get_tty(j + ipw_tty_driver->minor_start) == ttyj)
report_deregistering(ttyj);
ttyj->closing = 1;
if (ttyj->linux_tty != NULL) {
mutex_unlock(&ttyj->ipw_tty_mutex);
tty_hangup(ttyj->linux_tty);
/* Wait till the tty_hangup has completed */
flush_scheduled_work();
mutex_lock(&ttyj->ipw_tty_mutex);
}
while (ttyj->open_count)
do_ipw_close(ttyj);
ipwireless_disassociate_network_ttys(network,
ttyj->channel_idx);
tty_unregister_device(ipw_tty_driver, j);
ttys[j] = NULL;
mutex_unlock(&ttyj->ipw_tty_mutex);
kfree(ttyj);
}
}
}
static struct tty_operations tty_ops = {
.open = ipw_open,
.close = ipw_close,
.hangup = ipw_hangup,
.write = ipw_write,
.write_room = ipw_write_room,
.ioctl = ipw_ioctl,
.chars_in_buffer = ipw_chars_in_buffer,
.tiocmget = ipw_tiocmget,
.tiocmset = ipw_tiocmset,
};
int ipwireless_tty_init(void)
{
int result;
ipw_tty_driver = alloc_tty_driver(IPWIRELESS_PCMCIA_MINORS);
if (!ipw_tty_driver)
return -ENOMEM;
ipw_tty_driver->owner = THIS_MODULE;
ipw_tty_driver->driver_name = IPWIRELESS_PCCARD_NAME;
ipw_tty_driver->name = "ttyIPWp";
ipw_tty_driver->major = 0;
ipw_tty_driver->minor_start = IPWIRELESS_PCMCIA_START;
ipw_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
ipw_tty_driver->subtype = SERIAL_TYPE_NORMAL;
ipw_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
ipw_tty_driver->init_termios = tty_std_termios;
ipw_tty_driver->init_termios.c_cflag =
B9600 | CS8 | CREAD | HUPCL | CLOCAL;
ipw_tty_driver->init_termios.c_ispeed = 9600;
ipw_tty_driver->init_termios.c_ospeed = 9600;
tty_set_operations(ipw_tty_driver, &tty_ops);
result = tty_register_driver(ipw_tty_driver);
if (result) {
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": failed to register tty driver\n");
put_tty_driver(ipw_tty_driver);
return result;
}
return 0;
}
void ipwireless_tty_release(void)
{
int ret;
ret = tty_unregister_driver(ipw_tty_driver);
put_tty_driver(ipw_tty_driver);
if (ret != 0)
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": tty_unregister_driver failed with code %d\n", ret);
}
int ipwireless_tty_is_modem(struct ipw_tty *tty)
{
return tty->tty_type == TTYTYPE_MODEM;
}
void
ipwireless_tty_notify_control_line_change(struct ipw_tty *tty,
unsigned int channel_idx,
unsigned int control_lines,
unsigned int changed_mask)
{
unsigned int old_control_lines = tty->control_lines;
tty->control_lines = (tty->control_lines & ~changed_mask)
| (control_lines & changed_mask);
/*
* If DCD is de-asserted, we close the tty so pppd can tell that we
* have gone offline.
*/
if ((old_control_lines & IPW_CONTROL_LINE_DCD)
&& !(tty->control_lines & IPW_CONTROL_LINE_DCD)
&& tty->linux_tty) {
tty_hangup(tty->linux_tty);
}
}

View File

@ -0,0 +1,48 @@
/*
* IPWireless 3G PCMCIA Network Driver
*
* Original code
* by Stephen Blackheath <stephen@blacksapphire.com>,
* Ben Martel <benm@symmetric.co.nz>
*
* Copyrighted as follows:
* Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
*
* Various driver changes and rewrites, port to new kernels
* Copyright (C) 2006-2007 Jiri Kosina
*
* Misc code cleanups and updates
* Copyright (C) 2007 David Sterba
*/
#ifndef _IPWIRELESS_CS_TTY_H_
#define _IPWIRELESS_CS_TTY_H_
#include <linux/types.h>
#include <linux/sched.h>
#include <pcmcia/cs_types.h>
#include <pcmcia/cs.h>
#include <pcmcia/cistpl.h>
#include <pcmcia/ds.h>
struct ipw_tty;
struct ipw_network;
struct ipw_hardware;
int ipwireless_tty_init(void);
void ipwireless_tty_release(void);
struct ipw_tty *ipwireless_tty_create(struct ipw_hardware *hw,
struct ipw_network *net,
dev_node_t *nodes);
void ipwireless_tty_free(struct ipw_tty *tty);
void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
unsigned int length);
int ipwireless_tty_is_modem(struct ipw_tty *tty);
void ipwireless_tty_notify_control_line_change(struct ipw_tty *tty,
unsigned int channel_idx,
unsigned int control_lines,
unsigned int changed_mask);
#endif