blob: 6766d5a91a90805329b60efed81ccc0e64e5af02 [file] [log] [blame]
/*
* Copyright 2003 Digi International (www.digi.com)
* Scott H Kilau <Scott_Kilau at digi dot com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
*/
/*
* In the original out of kernel Digi dgap driver, firmware
* loading was done via user land to driver handshaking.
*
* For cards that support a concentrator (port expander),
* I believe the concentrator its self told the card which
* concentrator is actually attached and then that info
* was used to tell user land which concentrator firmware
* image was to be downloaded. I think even the BIOS or
* FEP images required could change with the connection
* of a particular concentrator.
*
* Since I have no access to any of these cards or
* concentrators, I cannot put the correct concentrator
* firmware file names into the firmware_info structure
* as is now done for the BIOS and FEP images.
*
* I think, but am not certain, that the cards supporting
* concentrators will function without them. So support
* of these cards has been left in this driver.
*
* In order to fully support those cards, they would
* either have to be acquired for dissection or maybe
* Digi International could provide some assistance.
*/
#undef DIGI_CONCENTRATORS_SUPPORTED
#define pr_fmt(fmt) "dgap: " fmt
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/delay.h> /* For udelay */
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/sched.h>
#include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
#include <linux/ctype.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/serial_reg.h>
#include <linux/io.h> /* For read[bwl]/write[bwl] */
#include <linux/string.h>
#include <linux/device.h>
#include <linux/kdev_t.h>
#include <linux/firmware.h>
#include "dgap.h"
/*
* File operations permitted on Control/Management major.
*/
static const struct file_operations dgap_board_fops = {
.owner = THIS_MODULE,
};
static uint dgap_numboards;
static struct board_t *dgap_board[MAXBOARDS];
static ulong dgap_poll_counter;
static int dgap_driver_state = DRIVER_INITIALIZED;
static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
static struct class *dgap_class;
static uint dgap_count = 500;
/*
* Poller stuff
*/
static DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
static ulong dgap_poll_time; /* Time of next poll */
static uint dgap_poll_stop; /* Used to tell poller to stop */
static struct timer_list dgap_poll_timer;
/*
SUPPORTED PRODUCTS
Card Model Number of Ports Interface
----------------------------------------------------------------
Acceleport Xem 4 - 64 (EIA232 & EIA422)
Acceleport Xr 4 & 8 (EIA232)
Acceleport Xr 920 4 & 8 (EIA232)
Acceleport C/X 8 - 128 (EIA232)
Acceleport EPC/X 8 - 224 (EIA232)
Acceleport Xr/422 4 & 8 (EIA422)
Acceleport 2r/920 2 (EIA232)
Acceleport 4r/920 4 (EIA232)
Acceleport 8r/920 8 (EIA232)
IBM 8-Port Asynchronous PCI Adapter (EIA232)
IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
*/
static struct pci_device_id dgap_pci_tbl[] = {
{ DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
{ DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
{ DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
{ DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
{ DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
{ DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
{ DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
{ DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
{ DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
{ DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
{ DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
{ DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
{ DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
{ DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
{ DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
{0,} /* 0 terminated list. */
};
MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
/*
* A generic list of Product names, PCI Vendor ID, and PCI Device ID.
*/
struct board_id {
uint config_type;
u8 *name;
uint maxports;
uint dpatype;
};
static struct board_id dgap_ids[] = {
{ PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
{ PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) },
{ PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) },
{ PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) },
{ APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) },
{ APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) },
{ APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
{ PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
{ PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
{ PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
{ PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
{ PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
{ PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
{ APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
{ PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
{0,} /* 0 terminated list. */
};
struct firmware_info {
u8 *conf_name; /* dgap.conf */
u8 *bios_name; /* BIOS filename */
u8 *fep_name; /* FEP filename */
u8 *con_name; /* Concentrator filename FIXME*/
int num; /* sequence number */
};
/*
* Firmware - BIOS, FEP, and CONC filenames
*/
static struct firmware_info fw_info[] = {
{ "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 0 },
{ "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 1 },
{ "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 2 },
{ "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", NULL, 3 },
{ "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 4 },
{ "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 5 },
{ "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 6 },
{ "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 7 },
{ "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 8 },
{ "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 9 },
{ "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 10 },
{ "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 11 },
{ "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 12 },
{ "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 13 },
{ "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 14 },
{NULL,}
};
/*
* Default transparent print information.
*/
static struct digi_t dgap_digi_init = {
.digi_flags = DIGI_COOK, /* Flags */
.digi_maxcps = 100, /* Max CPS */
.digi_maxchar = 50, /* Max chars in print queue */
.digi_bufsize = 100, /* Printer buffer size */
.digi_onlen = 4, /* size of printer on string */
.digi_offlen = 4, /* size of printer off string */
.digi_onstr = "\033[5i", /* ANSI printer on string ] */
.digi_offstr = "\033[4i", /* ANSI printer off string ] */
.digi_term = "ansi" /* default terminal type */
};
/*
* Define a local default termios struct. All ports will be created
* with this termios initially.
*
* This defines a raw port at 9600 baud, 8 data bits, no parity,
* 1 stop bit.
*/
static struct ktermios dgap_default_termios = {
.c_iflag = (DEFAULT_IFLAGS), /* iflags */
.c_oflag = (DEFAULT_OFLAGS), /* oflags */
.c_cflag = (DEFAULT_CFLAGS), /* cflags */
.c_lflag = (DEFAULT_LFLAGS), /* lflags */
.c_cc = INIT_C_CC,
.c_line = 0,
};
/*
* Our needed internal static variables from dgap_parse.c
*/
static struct cnode dgap_head;
#define MAXCWORD 200
static char dgap_cword[MAXCWORD];
struct toklist {
int token;
char *string;
};
static struct toklist dgap_brdtype[] = {
{ PCX, "Digi_AccelePort_C/X_PCI" },
{ PEPC, "Digi_AccelePort_EPC/X_PCI" },
{ PPCM, "Digi_AccelePort_Xem_PCI" },
{ APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
{ APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
{ APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
{ PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
{ PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
{ 0, NULL }
};
static struct toklist dgap_tlist[] = {
{ BEGIN, "config_begin" },
{ END, "config_end" },
{ BOARD, "board" },
{ IO, "io" },
{ PCIINFO, "pciinfo" },
{ LINE, "line" },
{ CONC, "conc" },
{ CONC, "concentrator" },
{ CX, "cx" },
{ CX, "ccon" },
{ EPC, "epccon" },
{ EPC, "epc" },
{ MOD, "module" },
{ ID, "id" },
{ STARTO, "start" },
{ SPEED, "speed" },
{ CABLE, "cable" },
{ CONNECT, "connect" },
{ METHOD, "method" },
{ STATUS, "status" },
{ CUSTOM, "Custom" },
{ BASIC, "Basic" },
{ MEM, "mem" },
{ MEM, "memory" },
{ PORTS, "ports" },
{ MODEM, "modem" },
{ NPORTS, "nports" },
{ TTYN, "ttyname" },
{ CU, "cuname" },
{ PRINT, "prname" },
{ CMAJOR, "major" },
{ ALTPIN, "altpin" },
{ USEINTR, "useintr" },
{ TTSIZ, "ttysize" },
{ CHSIZ, "chsize" },
{ BSSIZ, "boardsize" },
{ UNTSIZ, "schedsize" },
{ F2SIZ, "f2200size" },
{ VPSIZ, "vpixsize" },
{ 0, NULL }
};
/*
* dgap_sindex: much like index(), but it looks for a match of any character in
* the group, and returns that position. If the first character is a ^, then
* this will match the first occurrence not in that group.
*/
static char *dgap_sindex(char *string, char *group)
{
char *ptr;
if (!string || !group)
return NULL;
if (*group == '^') {
group++;
for (; *string; string++) {
for (ptr = group; *ptr; ptr++) {
if (*ptr == *string)
break;
}
if (*ptr == '\0')
return string;
}
} else {
for (; *string; string++) {
for (ptr = group; *ptr; ptr++) {
if (*ptr == *string)
return string;
}
}
}
return NULL;
}
/*
* get a word from the input stream, also keep track of current line number.
* words are separated by whitespace.
*/
static char *dgap_getword(char **in)
{
char *ret_ptr = *in;
char *ptr = dgap_sindex(*in, " \t\n");
/* If no word found, return null */
if (!ptr)
return NULL;
/* Mark new location for our buffer */
*ptr = '\0';
*in = ptr + 1;
/* Eat any extra spaces/tabs/newlines that might be present */
while (*in && **in && ((**in == ' ') ||
(**in == '\t') ||
(**in == '\n'))) {
**in = '\0';
*in = *in + 1;
}
return ret_ptr;
}
/*
* Get a token from the input file; return 0 if end of file is reached
*/
static int dgap_gettok(char **in)
{
char *w;
struct toklist *t;
if (strstr(dgap_cword, "board")) {
w = dgap_getword(in);
snprintf(dgap_cword, MAXCWORD, "%s", w);
for (t = dgap_brdtype; t->token != 0; t++) {
if (!strcmp(w, t->string))
return t->token;
}
} else {
while ((w = dgap_getword(in))) {
snprintf(dgap_cword, MAXCWORD, "%s", w);
for (t = dgap_tlist; t->token != 0; t++) {
if (!strcmp(w, t->string))
return t->token;
}
}
}
return 0;
}
/*
* dgap_checknode: see if all the necessary info has been supplied for a node
* before creating the next node.
*/
static int dgap_checknode(struct cnode *p)
{
switch (p->type) {
case LNODE:
if (p->u.line.v_speed == 0) {
pr_err("line speed not specified");
return 1;
}
return 0;
case CNODE:
if (p->u.conc.v_speed == 0) {
pr_err("concentrator line speed not specified");
return 1;
}
if (p->u.conc.v_nport == 0) {
pr_err("number of ports on concentrator not specified");
return 1;
}
if (p->u.conc.v_id == 0) {
pr_err("concentrator id letter not specified");
return 1;
}
return 0;
case MNODE:
if (p->u.module.v_nport == 0) {
pr_err("number of ports on EBI module not specified");
return 1;
}
if (p->u.module.v_id == 0) {
pr_err("EBI module id letter not specified");
return 1;
}
return 0;
}
return 0;
}
/*
* Given a board pointer, returns whether we should use interrupts or not.
*/
static uint dgap_config_get_useintr(struct board_t *bd)
{
struct cnode *p;
if (!bd)
return 0;
for (p = bd->bd_config; p; p = p->next) {
if (p->type == INTRNODE) {
/*
* check for pcxr types.
*/
return p->u.useintr;
}
}
/* If not found, then don't turn on interrupts. */
return 0;
}
/*
* Given a board pointer, returns whether we turn on altpin or not.
*/
static uint dgap_config_get_altpin(struct board_t *bd)
{
struct cnode *p;
if (!bd)
return 0;
for (p = bd->bd_config; p; p = p->next) {
if (p->type == ANODE) {
/*
* check for pcxr types.
*/
return p->u.altpin;
}
}
/* If not found, then don't turn on interrupts. */
return 0;
}
/*
* Given a specific type of board, if found, detached link and
* returns the first occurrence in the list.
*/
static struct cnode *dgap_find_config(int type, int bus, int slot)
{
struct cnode *p, *prev, *prev2, *found;
p = &dgap_head;
while (p->next) {
prev = p;
p = p->next;
if (p->type != BNODE)
continue;
if (p->u.board.type != type)
continue;
if (p->u.board.v_pcibus &&
p->u.board.pcibus != bus)
continue;
if (p->u.board.v_pcislot &&
p->u.board.pcislot != slot)
continue;
found = p;
/*
* Keep walking thru the list till we
* find the next board.
*/
while (p->next) {
prev2 = p;
p = p->next;
if (p->type != BNODE)
continue;
/*
* Mark the end of our 1 board
* chain of configs.
*/
prev2->next = NULL;
/*
* Link the "next" board to the
* previous board, effectively
* "unlinking" our board from
* the main config.
*/
prev->next = p;
return found;
}
/*
* It must be the last board in the list.
*/
prev->next = NULL;
return found;
}
return NULL;
}
/*
* Given a board pointer, walks the config link, counting up
* all ports user specified should be on the board.
* (This does NOT mean they are all actually present right now tho)
*/
static uint dgap_config_get_num_prts(struct board_t *bd)
{
int count = 0;
struct cnode *p;
if (!bd)
return 0;
for (p = bd->bd_config; p; p = p->next) {
switch (p->type) {
case BNODE:
/*
* check for pcxr types.
*/
if (p->u.board.type > EPCFE)
count += p->u.board.nport;
break;
case CNODE:
count += p->u.conc.nport;
break;
case MNODE:
count += p->u.module.nport;
break;
}
}
return count;
}
static char *dgap_create_config_string(struct board_t *bd, char *string)
{
char *ptr = string;
struct cnode *p;
struct cnode *q;
int speed;
if (!bd) {
*ptr = 0xff;
return string;
}
for (p = bd->bd_config; p; p = p->next) {
switch (p->type) {
case LNODE:
*ptr = '\0';
ptr++;
*ptr = p->u.line.speed;
ptr++;
break;
case CNODE:
/*
* Because the EPC/con concentrators can have EM modules
* hanging off of them, we have to walk ahead in the
* list and keep adding the number of ports on each EM
* to the config. UGH!
*/
speed = p->u.conc.speed;
q = p->next;
if (q && (q->type == MNODE)) {
*ptr = (p->u.conc.nport + 0x80);
ptr++;
p = q;
while (q->next && (q->next->type) == MNODE) {
*ptr = (q->u.module.nport + 0x80);
ptr++;
p = q;
q = q->next;
}
*ptr = q->u.module.nport;
ptr++;
} else {
*ptr = p->u.conc.nport;
ptr++;
}
*ptr = speed;
ptr++;
break;
}
}
*ptr = 0xff;
return string;
}
/*
* Parse a configuration file read into memory as a string.
*/
static int dgap_parsefile(char **in)
{
struct cnode *p, *brd, *line, *conc;
int rc;
char *s;
int linecnt = 0;
p = &dgap_head;
brd = line = conc = NULL;
/* perhaps we are adding to an existing list? */
while (p->next)
p = p->next;
/* file must start with a BEGIN */
while ((rc = dgap_gettok(in)) != BEGIN) {
if (rc == 0) {
pr_err("unexpected EOF");
return -1;
}
}
for (; ;) {
int board_type = 0;
int conc_type = 0;
int module_type = 0;
rc = dgap_gettok(in);
if (rc == 0) {
pr_err("unexpected EOF");
return -1;
}
switch (rc) {
case BEGIN: /* should only be 1 begin */
pr_err("unexpected config_begin\n");
return -1;
case END:
return 0;
case BOARD: /* board info */
if (dgap_checknode(p))
return -1;
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = BNODE;
p->u.board.status = kstrdup("No", GFP_KERNEL);
line = conc = NULL;
brd = p;
linecnt = -1;
board_type = dgap_gettok(in);
if (board_type == 0) {
pr_err("board !!type not specified");
return -1;
}
p->u.board.type = board_type;
break;
case IO: /* i/o port */
if (p->type != BNODE) {
pr_err("IO port only valid for boards");
return -1;
}
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
p->u.board.portstr = kstrdup(s, GFP_KERNEL);
if (kstrtol(s, 0, &p->u.board.port)) {
pr_err("bad number for IO port");
return -1;
}
p->u.board.v_port = 1;
break;
case MEM: /* memory address */
if (p->type != BNODE) {
pr_err("memory address only valid for boards");
return -1;
}
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
p->u.board.addrstr = kstrdup(s, GFP_KERNEL);
if (kstrtoul(s, 0, &p->u.board.addr)) {
pr_err("bad number for memory address");
return -1;
}
p->u.board.v_addr = 1;
break;
case PCIINFO: /* pci information */
if (p->type != BNODE) {
pr_err("memory address only valid for boards");
return -1;
}
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
p->u.board.pcibusstr = kstrdup(s, GFP_KERNEL);
if (kstrtoul(s, 0, &p->u.board.pcibus)) {
pr_err("bad number for pci bus");
return -1;
}
p->u.board.v_pcibus = 1;
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
p->u.board.pcislotstr = kstrdup(s, GFP_KERNEL);
if (kstrtoul(s, 0, &p->u.board.pcislot)) {
pr_err("bad number for pci slot");
return -1;
}
p->u.board.v_pcislot = 1;
break;
case METHOD:
if (p->type != BNODE) {
pr_err("install method only valid for boards");
return -1;
}
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
p->u.board.method = kstrdup(s, GFP_KERNEL);
p->u.board.v_method = 1;
break;
case STATUS:
if (p->type != BNODE) {
pr_err("config status only valid for boards");
return -1;
}
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
p->u.board.status = kstrdup(s, GFP_KERNEL);
break;
case NPORTS: /* number of ports */
if (p->type == BNODE) {
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.board.nport)) {
pr_err("bad number for number of ports");
return -1;
}
p->u.board.v_nport = 1;
} else if (p->type == CNODE) {
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.conc.nport)) {
pr_err("bad number for number of ports");
return -1;
}
p->u.conc.v_nport = 1;
} else if (p->type == MNODE) {
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.module.nport)) {
pr_err("bad number for number of ports");
return -1;
}
p->u.module.v_nport = 1;
} else {
pr_err("nports only valid for concentrators or modules");
return -1;
}
break;
case ID: /* letter ID used in tty name */
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
p->u.board.status = kstrdup(s, GFP_KERNEL);
if (p->type == CNODE) {
p->u.conc.id = kstrdup(s, GFP_KERNEL);
p->u.conc.v_id = 1;
} else if (p->type == MNODE) {
p->u.module.id = kstrdup(s, GFP_KERNEL);
p->u.module.v_id = 1;
} else {
pr_err("id only valid for concentrators or modules");
return -1;
}
break;
case STARTO: /* start offset of ID */
if (p->type == BNODE) {
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.board.start)) {
pr_err("bad number for start of tty count");
return -1;
}
p->u.board.v_start = 1;
} else if (p->type == CNODE) {
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.conc.start)) {
pr_err("bad number for start of tty count");
return -1;
}
p->u.conc.v_start = 1;
} else if (p->type == MNODE) {
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.module.start)) {
pr_err("bad number for start of tty count");
return -1;
}
p->u.module.v_start = 1;
} else {
pr_err("start only valid for concentrators or modules");
return -1;
}
break;
case TTYN: /* tty name prefix */
if (dgap_checknode(p))
return -1;
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = TNODE;
s = dgap_getword(in);
if (!s) {
pr_err("unexpeced end of file");
return -1;
}
p->u.ttyname = kstrdup(s, GFP_KERNEL);
if (!p->u.ttyname)
return -1;
break;
case CU: /* cu name prefix */
if (dgap_checknode(p))
return -1;
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = CUNODE;
s = dgap_getword(in);
if (!s) {
pr_err("unexpeced end of file");
return -1;
}
p->u.cuname = kstrdup(s, GFP_KERNEL);
if (!p->u.cuname)
return -1;
break;
case LINE: /* line information */
if (dgap_checknode(p))
return -1;
if (!brd) {
pr_err("must specify board before line info");
return -1;
}
switch (brd->u.board.type) {
case PPCM:
pr_err("line not valid for PC/em");
return -1;
}
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = LNODE;
conc = NULL;
line = p;
linecnt++;
break;
case CONC: /* concentrator information */
if (dgap_checknode(p))
return -1;
if (!line) {
pr_err("must specify line info before concentrator");
return -1;
}
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = CNODE;
conc = p;
if (linecnt)
brd->u.board.conc2++;
else
brd->u.board.conc1++;
conc_type = dgap_gettok(in);
if (conc_type == 0 || (conc_type != CX &&
conc_type != EPC)) {
pr_err("failed to set a type of concentratros");
return -1;
}
p->u.conc.type = conc_type;
break;
case MOD: /* EBI module */
if (dgap_checknode(p))
return -1;
if (!brd) {
pr_err("must specify board info before EBI modules");
return -1;
}
switch (brd->u.board.type) {
case PPCM:
linecnt = 0;
break;
default:
if (!conc) {
pr_err("must specify concentrator info before EBI module");
return -1;
}
}
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = MNODE;
if (linecnt)
brd->u.board.module2++;
else
brd->u.board.module1++;
module_type = dgap_gettok(in);
if (module_type == 0 || (module_type != PORTS &&
module_type != MODEM)) {
pr_err("failed to set a type of module");
return -1;
}
p->u.module.type = module_type;
break;
case CABLE:
if (p->type == LNODE) {
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
p->u.line.cable = kstrdup(s, GFP_KERNEL);
p->u.line.v_cable = 1;
}
break;
case SPEED: /* sync line speed indication */
if (p->type == LNODE) {
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.line.speed)) {
pr_err("bad number for line speed");
return -1;
}
p->u.line.v_speed = 1;
} else if (p->type == CNODE) {
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.conc.speed)) {
pr_err("bad number for line speed");
return -1;
}
p->u.conc.v_speed = 1;
} else {
pr_err("speed valid only for lines or concentrators.");
return -1;
}
break;
case CONNECT:
if (p->type == CNODE) {
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
p->u.conc.connect = kstrdup(s, GFP_KERNEL);
p->u.conc.v_connect = 1;
}
break;
case PRINT: /* transparent print name prefix */
if (dgap_checknode(p))
return -1;
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = PNODE;
s = dgap_getword(in);
if (!s) {
pr_err("unexpeced end of file");
return -1;
}
p->u.printname = kstrdup(s, GFP_KERNEL);
if (!p->u.printname)
return -1;
break;
case CMAJOR: /* major number */
if (dgap_checknode(p))
return -1;
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = JNODE;
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.majornumber)) {
pr_err("bad number for major number");
return -1;
}
break;
case ALTPIN: /* altpin setting */
if (dgap_checknode(p))
return -1;
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = ANODE;
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.altpin)) {
pr_err("bad number for altpin");
return -1;
}
break;
case USEINTR: /* enable interrupt setting */
if (dgap_checknode(p))
return -1;
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = INTRNODE;
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.useintr)) {
pr_err("bad number for useintr");
return -1;
}
break;
case TTSIZ: /* size of tty structure */
if (dgap_checknode(p))
return -1;
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = TSNODE;
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.ttysize)) {
pr_err("bad number for ttysize");
return -1;
}
break;
case CHSIZ: /* channel structure size */
if (dgap_checknode(p))
return -1;
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = CSNODE;
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.chsize)) {
pr_err("bad number for chsize");
return -1;
}
break;
case BSSIZ: /* board structure size */
if (dgap_checknode(p))
return -1;
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = BSNODE;
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.bssize)) {
pr_err("bad number for bssize");
return -1;
}
break;
case UNTSIZ: /* sched structure size */
if (dgap_checknode(p))
return -1;
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = USNODE;
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.unsize)) {
pr_err("bad number for schedsize");
return -1;
}
break;
case F2SIZ: /* f2200 structure size */
if (dgap_checknode(p))
return -1;
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = FSNODE;
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.f2size)) {
pr_err("bad number for f2200size");
return -1;
}
break;
case VPSIZ: /* vpix structure size */
if (dgap_checknode(p))
return -1;
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next)
return -1;
p = p->next;
p->type = VSNODE;
s = dgap_getword(in);
if (!s) {
pr_err("unexpected end of file");
return -1;
}
if (kstrtol(s, 0, &p->u.vpixsize)) {
pr_err("bad number for vpixsize");
return -1;
}
break;
}
}
}
static void dgap_cleanup_nodes(void)
{
struct cnode *p;
p = &dgap_head;
while (p) {
struct cnode *tmp = p->next;
if (p->type == NULLNODE) {
p = tmp;
continue;
}
switch (p->type) {
case BNODE:
kfree(p->u.board.portstr);
kfree(p->u.board.addrstr);
kfree(p->u.board.pcibusstr);
kfree(p->u.board.pcislotstr);
kfree(p->u.board.method);
break;
case CNODE:
kfree(p->u.conc.id);
kfree(p->u.conc.connect);
break;
case MNODE:
kfree(p->u.module.id);
break;
case TNODE:
kfree(p->u.ttyname);
break;
case CUNODE:
kfree(p->u.cuname);
break;
case LNODE:
kfree(p->u.line.cable);
break;
case PNODE:
kfree(p->u.printname);
break;
}
kfree(p->u.board.status);
kfree(p);
p = tmp;
}
}
/*
* Retrives the current custom baud rate from FEP memory,
* and returns it back to the user.
* Returns 0 on error.
*/
static uint dgap_get_custom_baud(struct channel_t *ch)
{
u8 __iomem *vaddr;
ulong offset;
if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
return 0;
if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
return 0;
if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
return 0;
vaddr = ch->ch_bd->re_map_membase;
if (!vaddr)
return 0;
/*
* Go get from fep mem, what the fep
* believes the custom baud rate is.
*/
offset = (ioread16(vaddr + ECS_SEG) << 4) + (ch->ch_portnum * 0x28)
+ LINE_SPEED;
return readw(vaddr + offset);
}
/*
* Remap PCI memory.
*/
static int dgap_remap(struct board_t *brd)
{
if (!brd || brd->magic != DGAP_BOARD_MAGIC)
return -EIO;
if (!request_mem_region(brd->membase, 0x200000, "dgap"))
return -ENOMEM;
if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
"dgap"))
goto err_req_mem;
brd->re_map_membase = ioremap(brd->membase, 0x200000);
if (!brd->re_map_membase)
goto err_remap_mem;
brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
if (!brd->re_map_port)
goto err_remap_port;
return 0;
err_remap_port:
iounmap(brd->re_map_membase);
err_remap_mem:
release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
err_req_mem:
release_mem_region(brd->membase, 0x200000);
return -ENOMEM;
}
static void dgap_unmap(struct board_t *brd)
{
iounmap(brd->re_map_port);
iounmap(brd->re_map_membase);
release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
release_mem_region(brd->membase, 0x200000);
}
/*
* dgap_parity_scan()
*
* Convert the FEP5 way of reporting parity errors and breaks into
* the Linux line discipline way.
*/
static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
unsigned char *fbuf, int *len)
{
int l = *len;
int count = 0;
unsigned char *in, *cout, *fout;
unsigned char c;
in = cbuf;
cout = cbuf;
fout = fbuf;
if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
return;
while (l--) {
c = *in++;
switch (ch->pscan_state) {
default:
/* reset to sanity and fall through */
ch->pscan_state = 0;
case 0:
/* No FF seen yet */
if (c == (unsigned char) '\377')
/* delete this character from stream */
ch->pscan_state = 1;
else {
*cout++ = c;
*fout++ = TTY_NORMAL;
count += 1;
}
break;
case 1:
/* first FF seen */
if (c == (unsigned char) '\377') {
/* doubled ff, transform to single ff */
*cout++ = c;
*fout++ = TTY_NORMAL;
count += 1;
ch->pscan_state = 0;
} else {
/* save value examination in next state */
ch->pscan_savechar = c;
ch->pscan_state = 2;
}
break;
case 2:
/* third character of ff sequence */
*cout++ = c;
if (ch->pscan_savechar == 0x0) {
if (c == 0x0) {
ch->ch_err_break++;
*fout++ = TTY_BREAK;
} else {
ch->ch_err_parity++;
*fout++ = TTY_PARITY;
}
}
count += 1;
ch->pscan_state = 0;
}
}
*len = count;
}
/*=======================================================================
*
* dgap_input - Process received data.
*
* ch - Pointer to channel structure.
*
*=======================================================================*/
static void dgap_input(struct channel_t *ch)
{
struct board_t *bd;
struct bs_t __iomem *bs;
struct tty_struct *tp;
struct tty_ldisc *ld;
uint rmask;
uint head;
uint tail;
int data_len;
ulong lock_flags;
ulong lock_flags2;
int flip_len;
int len;
int n;
u8 *buf;
u8 tmpchar;
int s;
if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
return;
tp = ch->ch_tun.un_tty;
bs = ch->ch_bs;
if (!bs)
return;
bd = ch->ch_bd;
if (!bd || bd->magic != DGAP_BOARD_MAGIC)
return;
spin_lock_irqsave(&bd->bd_lock, lock_flags);
spin_lock_irqsave(&ch->ch_lock, lock_flags2);
/*
* Figure the number of characters in the buffer.
* Exit immediately if none.
*/
rmask = ch->ch_rsize - 1;
head = readw(&(bs->rx_head));
head &= rmask;
tail = readw(&(bs->rx_tail));
tail &= rmask;
data_len = (head - tail) & rmask;
if (data_len == 0) {
writeb(1, &(bs->idata));
spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
return;
}
/*
* If the device is not open, or CREAD is off, flush
* input data and return immediately.
*/
if ((bd->state != BOARD_READY) || !tp ||
(tp->magic != TTY_MAGIC) ||
!(ch->ch_tun.un_flags & UN_ISOPEN) ||
!(tp->termios.c_cflag & CREAD) ||
(ch->ch_tun.un_flags & UN_CLOSING)) {
writew(head, &(bs->rx_tail));
writeb(1, &(bs->idata));
spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
return;
}
/*
* If we are throttled, simply don't read any data.
*/
if (ch->ch_flags & CH_RXBLOCK) {
writeb(1, &(bs->idata));
spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
return;
}
/*
* Ignore oruns.
*/
tmpchar = readb(&(bs->orun));
if (tmpchar) {
ch->ch_err_overrun++;
writeb(0, &(bs->orun));
}
/* Decide how much data we can send into the tty layer */
flip_len = TTY_FLIPBUF_SIZE;
/* Chop down the length, if needed */
len = min(data_len, flip_len);
len = min(len, (N_TTY_BUF_SIZE - 1));
ld = tty_ldisc_ref(tp);
#ifdef TTY_DONT_FLIP
/*
* If the DONT_FLIP flag is on, don't flush our buffer, and act
* like the ld doesn't have any space to put the data right now.
*/
if (test_bit(TTY_DONT_FLIP, &tp->flags))
len = 0;
#endif
/*
* If we were unable to get a reference to the ld,
* don't flush our buffer, and act like the ld doesn't
* have any space to put the data right now.
*/
if (!ld) {
len = 0;
} else {
/*
* If ld doesn't have a pointer to a receive_buf function,
* flush the data, then act like the ld doesn't have any
* space to put the data right now.
*/
if (!ld->ops->receive_buf) {
writew(head, &(bs->rx_tail));
len = 0;
}
}
if (len <= 0) {
writeb(1, &(bs->idata));
spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
if (ld)
tty_ldisc_deref(ld);
return;
}
buf = ch->ch_bd->flipbuf;
n = len;
/*
* n now contains the most amount of data we can copy,
* bounded either by our buffer size or the amount
* of data the card actually has pending...
*/
while (n) {
s = ((head >= tail) ? head : ch->ch_rsize) - tail;
s = min(s, n);
if (s <= 0)
break;
memcpy_fromio(buf, ch->ch_raddr + tail, s);
tail += s;
buf += s;
n -= s;
/* Flip queue if needed */
tail &= rmask;
}
writew(tail, &(bs->rx_tail));
writeb(1, &(bs->idata));
ch->ch_rxcount += len;
/*
* If we are completely raw, we don't need to go through a lot
* of the tty layers that exist.
* In this case, we take the shortest and fastest route we
* can to relay the data to the user.
*
* On the other hand, if we are not raw, we need to go through
* the tty layer, which has its API more well defined.
*/
if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
dgap_parity_scan(ch, ch->ch_bd->flipbuf,
ch->ch_bd->flipflagbuf, &len);
len = tty_buffer_request_room(tp->port, len);
tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
ch->ch_bd->flipflagbuf, len);
} else {
len = tty_buffer_request_room(tp->port, len);
tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
}
spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
/* Tell the tty layer its okay to "eat" the data now */
tty_flip_buffer_push(tp->port);
if (ld)
tty_ldisc_deref(ld);
}
static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
struct un_t *un, u32 mask,
unsigned long *irq_flags1,
unsigned long *irq_flags2)
{
if (!(un->un_flags & mask))
return;
un->un_flags &= ~mask;
if (!(un->un_flags & UN_ISOPEN))
return;
if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
un->un_tty->ldisc->ops->write_wakeup) {
spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
(un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
}
wake_up_interruptible(&un->un_tty->write_wait);
wake_up_interruptible(&un->un_flags_wait);
}
/************************************************************************
* Determines when CARRIER changes state and takes appropriate
* action.
************************************************************************/
static void dgap_carrier(struct channel_t *ch)
{
struct board_t *bd;
int virt_carrier = 0;
int phys_carrier = 0;
if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
return;
bd = ch->ch_bd;
if (!bd || bd->magic != DGAP_BOARD_MAGIC)
return;
/* Make sure altpin is always set correctly */
if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
ch->ch_dsr = DM_CD;
ch->ch_cd = DM_DSR;
} else {
ch->ch_dsr = DM_DSR;
ch->ch_cd = DM_CD;
}
if (ch->ch_mistat & D_CD(ch))
phys_carrier = 1;
if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
virt_carrier = 1;
if (ch->ch_c_cflag & CLOCAL)
virt_carrier = 1;
/*
* Test for a VIRTUAL carrier transition to HIGH.
*/
if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
/*
* When carrier rises, wake any threads waiting
* for carrier in the open routine.
*/
if (waitqueue_active(&(ch->ch_flags_wait)))
wake_up_interruptible(&ch->ch_flags_wait);
}
/*
* Test for a PHYSICAL carrier transition to HIGH.
*/
if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
/*
* When carrier rises, wake any threads waiting
* for carrier in the open routine.
*/
if (waitqueue_active(&(ch->ch_flags_wait)))
wake_up_interruptible(&ch->ch_flags_wait);
}
/*
* Test for a PHYSICAL transition to low, so long as we aren't
* currently ignoring physical transitions (which is what "virtual
* carrier" indicates).
*
* The transition of the virtual carrier to low really doesn't
* matter... it really only means "ignore carrier state", not
* "make pretend that carrier is there".
*/
if ((virt_carrier == 0) &&
((ch->ch_flags & CH_CD) != 0) &&
(phys_carrier == 0)) {
/*
* When carrier drops:
*
* Drop carrier on all open units.
*
* Flush queues, waking up any task waiting in the
* line discipline.
*
* Send a hangup to the control terminal.
*
* Enable all select calls.
*/
if (waitqueue_active(&(ch->ch_flags_wait)))
wake_up_interruptible(&ch->ch_flags_wait);
if (ch->ch_tun.un_open_count > 0)
tty_hangup(ch->ch_tun.un_tty);
if (ch->ch_pun.un_open_count > 0)
tty_hangup(ch->ch_pun.un_tty);
}
/*
* Make sure that our cached values reflect the current reality.
*/
if (virt_carrier == 1)
ch->ch_flags |= CH_FCAR;
else
ch->ch_flags &= ~CH_FCAR;
if (phys_carrier == 1)
ch->ch_flags |= CH_CD;
else
ch->ch_flags &= ~CH_CD;
}
/*=======================================================================
*
* dgap_event - FEP to host event processing routine.
*
* bd - Board of current event.
*
*=======================================================================*/
static int dgap_event(struct board_t *bd)
{
struct channel_t *ch;
ulong lock_flags;
ulong lock_flags2;
struct bs_t __iomem *bs;
u8 __iomem *event;
u8 __iomem *vaddr;
struct ev_t __iomem *eaddr;
uint head;
uint tail;
int port;
int reason;
int modem;
int b1;
if (!bd || bd->magic != DGAP_BOARD_MAGIC)
return -EIO;
spin_lock_irqsave(&bd->bd_lock, lock_flags);
vaddr = bd->re_map_membase;
if (!vaddr) {
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
return -EIO;
}
eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
/* Get our head and tail */
head = readw(&(eaddr->ev_head));
tail = readw(&(eaddr->ev_tail));
/*
* Forget it if pointers out of range.
*/
if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
(head | tail) & 03) {
/* Let go of board lock */
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
return -EIO;
}
/*
* Loop to process all the events in the buffer.
*/
while (tail != head) {
/*
* Get interrupt information.
*/
event = bd->re_map_membase + tail + EVSTART;
port = ioread8(event);
reason = ioread8(event + 1);
modem = ioread8(event + 2);
b1 = ioread8(event + 3);
/*
* Make sure the interrupt is valid.
*/
if (port >= bd->nasync)
goto next;
if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
goto next;
ch = bd->channels[port];
if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
goto next;
/*
* If we have made it here, the event was valid.
* Lock down the channel.
*/
spin_lock_irqsave(&ch->ch_lock, lock_flags2);
bs = ch->ch_bs;
if (!bs) {
spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
goto next;
}
/*
* Process received data.
*/
if (reason & IFDATA) {
/*
* ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
* input could send some data to ld, which in turn
* could do a callback to one of our other functions.
*/
spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
dgap_input(ch);
spin_lock_irqsave(&bd->bd_lock, lock_flags);
spin_lock_irqsave(&ch->ch_lock, lock_flags2);
if (ch->ch_flags & CH_RACTIVE)
ch->ch_flags |= CH_RENABLE;
else
writeb(1, &(bs->idata));
if (ch->ch_flags & CH_RWAIT) {
ch->ch_flags &= ~CH_RWAIT;
wake_up_interruptible
(&ch->ch_tun.un_flags_wait);
}
}
/*
* Process Modem change signals.
*/
if (reason & IFMODEM) {
ch->ch_mistat = modem;
dgap_carrier(ch);
}
/*
* Process break.
*/
if (reason & IFBREAK) {
if (ch->ch_tun.un_tty) {
/* A break has been indicated */
ch->ch_err_break++;
tty_buffer_request_room
(ch->ch_tun.un_tty->port, 1);
tty_insert_flip_char(ch->ch_tun.un_tty->port,
0, TTY_BREAK);
tty_flip_buffer_push(ch->ch_tun.un_tty->port);
}
}
/*
* Process Transmit low.
*/
if (reason & IFTLW) {
dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
&lock_flags, &lock_flags2);
dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
&lock_flags, &lock_flags2);
if (ch->ch_flags & CH_WLOW) {
ch->ch_flags &= ~CH_WLOW;
wake_up_interruptible(&ch->ch_flags_wait);
}
}
/*
* Process Transmit empty.
*/
if (reason & IFTEM) {
dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
&lock_flags, &lock_flags2);
dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
&lock_flags, &lock_flags2);
if (ch->ch_flags & CH_WEMPTY) {
ch->ch_flags &= ~CH_WEMPTY;
wake_up_interruptible(&ch->ch_flags_wait);
}
}
spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
next:
tail = (tail + 4) & (EVMAX - EVSTART - 4);
}
writew(tail, &(eaddr->ev_tail));
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
return 0;
}
/*
* Our board poller function.
*/
static void dgap_poll_tasklet(unsigned long data)
{
struct board_t *bd = (struct board_t *) data;
ulong lock_flags;
char __iomem *vaddr;
u16 head, tail;
if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
return;
if (bd->inhibit_poller)
return;
spin_lock_irqsave(&bd->bd_lock, lock_flags);
vaddr = bd->re_map_membase;
/*
* If board is ready, parse deeper to see if there is anything to do.
*/
if (bd->state == BOARD_READY) {
struct ev_t __iomem *eaddr;
if (!bd->re_map_membase) {
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
return;
}
if (!bd->re_map_port) {
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
return;
}
if (!bd->nasync)
goto out;
eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
/* Get our head and tail */
head = readw(&(eaddr->ev_head));
tail = readw(&(eaddr->ev_tail));
/*
* If there is an event pending. Go service it.
*/
if (head != tail) {
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
dgap_event(bd);
spin_lock_irqsave(&bd->bd_lock, lock_flags);
}
out:
/*
* If board is doing interrupts, ACK the interrupt.
*/
if (bd && bd->intr_running)
readb(bd->re_map_port + 2);
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
return;
}
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
}
/*
* dgap_found_board()
*
* A board has been found, init it.
*/
static struct board_t *dgap_found_board(struct pci_dev *pdev, int id,
int boardnum)
{
struct board_t *brd;
unsigned int pci_irq;
int i;
int ret;
/* get the board structure and prep it */
brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
if (!brd)
return ERR_PTR(-ENOMEM);
/* store the info for the board we've found */
brd->magic = DGAP_BOARD_MAGIC;
brd->boardnum = boardnum;
brd->vendor = dgap_pci_tbl[id].vendor;
brd->device = dgap_pci_tbl[id].device;
brd->pdev = pdev;
brd->pci_bus = pdev->bus->number;
brd->pci_slot = PCI_SLOT(pdev->devfn);
brd->name = dgap_ids[id].name;
brd->maxports = dgap_ids[id].maxports;
brd->type = dgap_ids[id].config_type;
brd->dpatype = dgap_ids[id].dpatype;
brd->dpastatus = BD_NOFEP;
init_waitqueue_head(&brd->state_wait);
spin_lock_init(&brd->bd_lock);
brd->inhibit_poller = FALSE;
brd->wait_for_bios = 0;
brd->wait_for_fep = 0;
for (i = 0; i < MAXPORTS; i++)
brd->channels[i] = NULL;
/* store which card & revision we have */
pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
pci_irq = pdev->irq;
brd->irq = pci_irq;
/* get the PCI Base Address Registers */
/* Xr Jupiter and EPC use BAR 2 */
if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
brd->membase = pci_resource_start(pdev, 2);
brd->membase_end = pci_resource_end(pdev, 2);
}
/* Everyone else uses BAR 0 */
else {
brd->membase = pci_resource_start(pdev, 0);
brd->membase_end = pci_resource_end(pdev, 0);
}
if (!brd->membase) {
ret = -ENODEV;
goto free_brd;
}
if (brd->membase & 1)
brd->membase &= ~3;
else
brd->membase &= ~15;
/*
* On the PCI boards, there is no IO space allocated
* The I/O registers will be in the first 3 bytes of the
* upper 2MB of the 4MB memory space. The board memory
* will be mapped into the low 2MB of the 4MB memory space
*/
brd->port = brd->membase + PCI_IO_OFFSET;
brd->port_end = brd->port + PCI_IO_SIZE_DGAP;
/*
* Special initialization for non-PLX boards
*/
if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
unsigned short cmd;
pci_write_config_byte(pdev, 0x40, 0);
pci_write_config_byte(pdev, 0x46, 0);
/* Limit burst length to 2 doubleword transactions */
pci_write_config_byte(pdev, 0x42, 1);
/*
* Enable IO and mem if not already done.
* This was needed for support on Itanium.
*/
pci_read_config_word(pdev, PCI_COMMAND, &cmd);
cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
pci_write_config_word(pdev, PCI_COMMAND, cmd);
}
/* init our poll helper tasklet */
tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
(unsigned long) brd);
ret = dgap_remap(brd);
if (ret)
goto free_brd;
pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
boardnum, brd->name, brd->rev, brd->irq);
return brd;
free_brd:
kfree(brd);
return ERR_PTR(ret);
}
/*
* dgap_intr()
*
* Driver interrupt handler.
*/
static irqreturn_t dgap_intr(int irq, void *voidbrd)
{
struct board_t *brd = voidbrd;
if (!brd)
return IRQ_NONE;
/*
* Check to make sure its for us.
*/
if (brd->magic != DGAP_BOARD_MAGIC)
return IRQ_NONE;
brd->intr_count++;
/*
* Schedule tasklet to run at a better time.
*/
tasklet_schedule(&brd->helper_tasklet);
return IRQ_HANDLED;
}
/*****************************************************************************
*
* Function:
*
* dgap_poll_handler
*
* Author:
*
* Scott H Kilau
*
* Parameters:
*
* dummy -- ignored
*
* Return Values:
*
* none
*
* Description:
*
* As each timer expires, it determines (a) whether the "transmit"
* waiter needs to be woken up, and (b) whether the poller needs to
* be rescheduled.
*
******************************************************************************/
static void dgap_poll_handler(ulong dummy)
{
unsigned int i;
struct board_t *brd;
unsigned long lock_flags;
ulong new_time;
dgap_poll_counter++;
/*
* Do not start the board state machine until
* driver tells us its up and running, and has
* everything it needs.
*/
if (dgap_driver_state != DRIVER_READY)
goto schedule_poller;
/*
* If we have just 1 board, or the system is not SMP,
* then use the typical old style poller.
* Otherwise, use our new tasklet based poller, which should
* speed things up for multiple boards.
*/
if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) {
for (i = 0; i < dgap_numboards; i++) {
brd = dgap_board[i];
if (brd->state == BOARD_FAILED)
continue;
if (!brd->intr_running)
/* Call the real board poller directly */
dgap_poll_tasklet((unsigned long) brd);
}
} else {
/*
* Go thru each board, kicking off a
* tasklet for each if needed
*/
for (i = 0; i < dgap_numboards; i++) {
brd = dgap_board[i];
/*
* Attempt to grab the board lock.
*
* If we can't get it, no big deal, the next poll
* will get it. Basically, I just really don't want
* to spin in here, because I want to kick off my
* tasklets as fast as I can, and then get out the
* poller.
*/
if (!spin_trylock(&brd->bd_lock))
continue;
/*
* If board is in a failed state, don't bother
* scheduling a tasklet
*/
if (brd->state == BOARD_FAILED) {
spin_unlock(&brd->bd_lock);
continue;
}
/* Schedule a poll helper task */
if (!brd->intr_running)
tasklet_schedule(&brd->helper_tasklet);
/*
* Can't do DGAP_UNLOCK here, as we don't have
* lock_flags because we did a trylock above.
*/
spin_unlock(&brd->bd_lock);
}
}
schedule_poller:
/*
* Schedule ourself back at the nominal wakeup interval.
*/
spin_lock_irqsave(&dgap_poll_lock, lock_flags);
dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
new_time = dgap_poll_time - jiffies;
if ((ulong) new_time >= 2 * dgap_poll_tick) {
dgap_poll_time =
jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
}
dgap_poll_timer.function = dgap_poll_handler;
dgap_poll_timer.data = 0;
dgap_poll_timer.expires = dgap_poll_time;
spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
if (!dgap_poll_stop)
add_timer(&dgap_poll_timer);
}
/*=======================================================================
*
* dgap_cmdb - Sends a 2 byte command to the FEP.
*
* ch - Pointer to channel structure.
* cmd - Command to be sent.
* byte1 - Integer containing first byte to be sent.
* byte2 - Integer containing second byte to be sent.
* ncmds - Wait until ncmds or fewer cmds are left
* in the cmd buffer before returning.
*
*=======================================================================*/
static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
u8 byte2, uint ncmds)
{
char __iomem *vaddr;
struct __iomem cm_t *cm_addr;
uint count;
uint n;
u16 head;
u16 tail;
if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
return;
/*
* Check if board is still alive.
*/
if (ch->ch_bd->state == BOARD_FAILED)
return;
/*
* Make sure the pointers are in range before
* writing to the FEP memory.
*/
vaddr = ch->ch_bd->re_map_membase;
if (!vaddr)
return;
cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
head = readw(&(cm_addr->cm_head));
/*
* Forget it if pointers out of range.
*/
if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
ch->ch_bd->state = BOARD_FAILED;
return;
}
/*
* Put the data in the circular command buffer.
*/
writeb(cmd, (vaddr + head + CMDSTART + 0));
writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
writeb(byte1, (vaddr + head + CMDSTART + 2));
writeb(byte2, (vaddr + head + CMDSTART + 3));
head = (head + 4) & (CMDMAX - CMDSTART - 4);
writew(head, &(cm_addr->cm_head));
/*
* Wait if necessary before updating the head
* pointer to limit the number of outstanding
* commands to the FEP. If the time spent waiting
* is outlandish, declare the FEP dead.
*/
for (count = dgap_count ;;) {
head = readw(&(cm_addr->cm_head));
tail = readw(&(cm_addr->cm_tail));
n = (head - tail) & (CMDMAX - CMDSTART - 4);
if (n <= ncmds * sizeof(struct cm_t))
break;
if (--count == 0) {
ch->ch_bd->state = BOARD_FAILED;
return;
}
udelay(10);
}
}
/*=======================================================================
*
* dgap_cmdw - Sends a 1 word command to the FEP.
*
* ch - Pointer to channel structure.
* cmd - Command to be sent.
* word - Integer containing word to be sent.
* ncmds - Wait until ncmds or fewer cmds are left
* in the cmd buffer before returning.
*
*=======================================================================*/
static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
{
char __iomem *vaddr;
struct __iomem cm_t *cm_addr;
uint count;
uint n;
u16 head;
u16 tail;
if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
return;
/*
* Check if board is still alive.
*/
if (ch->ch_bd->state == BOARD_FAILED)
return;
/*
* Make sure the pointers are in range before
* writing to the FEP memory.
*/
vaddr = ch->ch_bd->re_map_membase;
if (!vaddr)
return;
cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
head = readw(&(cm_addr->cm_head));
/*
* Forget it if pointers out of range.
*/
if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
ch->ch_bd->state = BOARD_FAILED;
return;
}
/*
* Put the data in the circular command buffer.
*/
writeb(cmd, (vaddr + head + CMDSTART + 0));
writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
writew((u16) word, (vaddr + head + CMDSTART + 2));
head = (head + 4) & (CMDMAX - CMDSTART - 4);
writew(head, &(cm_addr->cm_head));
/*
* Wait if necessary before updating the head
* pointer to limit the number of outstanding
* commands to the FEP. If the time spent waiting
* is outlandish, declare the FEP dead.
*/
for (count = dgap_count ;;) {
head = readw(&(cm_addr->cm_head));
tail = readw(&(cm_addr->cm_tail));
n = (head - tail) & (CMDMAX - CMDSTART - 4);
if (n <= ncmds * sizeof(struct cm_t))
break;
if (--count == 0) {
ch->ch_bd->state = BOARD_FAILED;
return;
}
udelay(10);
}
}
/*=======================================================================
*
* dgap_cmdw_ext - Sends a extended word command to the FEP.
*
* ch - Pointer to channel structure.
* cmd - Command to be sent.
* word - Integer containing word to be sent.
* ncmds - Wait until ncmds or fewer cmds are left
* in the cmd buffer before returning.
*
*=======================================================================*/
static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
{
char __iomem *vaddr;
struct __iomem cm_t *cm_addr;
uint count;
uint n;
u16 head;
u16 tail;
if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
return;
/*
* Check if board is still alive.
*/
if (ch->ch_bd->state == BOARD_FAILED)
return;
/*
* Make sure the pointers are in range before
* writing to the FEP memory.
*/
vaddr = ch->ch_bd->re_map_membase;
if (!vaddr)
return;
cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
head = readw(&(cm_addr->cm_head));
/*
* Forget it if pointers out of range.
*/
if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
ch->ch_bd->state = BOARD_FAILED;
return;
}
/*
* Put the data in the circular command buffer.
*/
/* Write an FF to tell the FEP that we want an extended command */
writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
writew((u16) cmd, (vaddr + head + CMDSTART + 2));
/*
* If the second part of the command won't fit,
* put it at the beginning of the circular buffer.
*/
if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
writew((u16) word, (vaddr + CMDSTART));
else
writew((u16) word, (vaddr + head + CMDSTART + 4));
head = (head + 8) & (CMDMAX - CMDSTART - 4);
writew(head, &(cm_addr->cm_head));
/*
* Wait if necessary before updating the head
* pointer to limit the number of outstanding
* commands to the FEP. If the time spent waiting
* is outlandish, declare the FEP dead.
*/
for (count = dgap_count ;;) {
head = readw(&(cm_addr->cm_head));
tail = readw(&(cm_addr->cm_tail));
n = (head - tail) & (CMDMAX - CMDSTART - 4);
if (n <= ncmds * sizeof(struct cm_t))
break;
if (--count == 0) {
ch->ch_bd->state = BOARD_FAILED;
return;
}
udelay(10);
}
}
/*=======================================================================
*
* dgap_wmove - Write data to FEP buffer.
*
* ch - Pointer to channel structure.
* buf - Poiter to characters to be moved.
* cnt - Number of characters to move.
*
*=======================================================================*/
static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
{
int n;
char __iomem *taddr;
struct bs_t __iomem *bs;
u16 head;
if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
return;
/*
* Check parameters.
*/
bs = ch->ch_bs;
head = readw(&(bs->tx_head));
/*
* If pointers are out of range, just return.
*/
if ((cnt > ch->ch_tsize) ||
(unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
return;
/*
* If the write wraps over the top of the circular buffer,
* move the portion up to the wrap point, and reset the
* pointers to the bottom.
*/
n = ch->ch_tstart + ch->ch_tsize - head;
if (cnt >= n) {
cnt -= n;
taddr = ch->ch_taddr + head;
memcpy_toio(taddr, buf, n);
head = ch->ch_tstart;
buf += n;
}
/*
* Move rest of data.
*/
taddr = ch->ch_taddr + head;
n = cnt;
memcpy_toio(taddr, buf, n);
head += cnt;
writew(head, &(bs->tx_head));
}
/*
* Calls the firmware to reset this channel.
*/
static void dgap_firmware_reset_port(struct channel_t *ch)
{
dgap_cmdb(ch, CHRESET, 0, 0, 0);
/*
* Now that the channel is reset, we need to make sure
* all the current settings get reapplied to the port
* in the firmware.
*
* So we will set the driver's cache of firmware
* settings all to 0, and then call param.
*/
ch->ch_fepiflag = 0;
ch->ch_fepcflag = 0;
ch->ch_fepoflag = 0;
ch->ch_fepstartc = 0;
ch->ch_fepstopc = 0;
ch->ch_fepastartc = 0;
ch->ch_fepastopc = 0;
ch->ch_mostat = 0;
ch->ch_hflow = 0;
}
/*=======================================================================
*
* dgap_param - Set Digi parameters.
*
* struct tty_struct * - TTY for port.
*
*=======================================================================*/
static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
{
u16 head;
u16 cflag;
u16 iflag;
u8 mval;
u8 hflow;
/*
* If baud rate is zero, flush queues, and set mval to drop DTR.
*/
if ((ch->ch_c_cflag & (CBAUD)) == 0) {
/* flush rx */
head = readw(&(ch->ch_bs->rx_head));
writew(head, &(ch->ch_bs->rx_tail));
/* flush tx */
head = readw(&(ch->ch_bs->tx_head));
writew(head, &(ch->ch_bs->tx_tail));
ch->ch_flags |= (CH_BAUD0);
/* Drop RTS and DTR */
ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
mval = D_DTR(ch) | D_RTS(ch);
ch->ch_baud_info = 0;
} else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
/*
* Tell the fep to do the command
*/
dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
/*
* Now go get from fep mem, what the fep
* believes the custom baud rate is.
*/
ch->ch_custom_speed = dgap_get_custom_baud(ch);
ch->ch_baud_info = ch->ch_custom_speed;
/* Handle transition from B0 */
if (ch->ch_flags & CH_BAUD0) {
ch->ch_flags &= ~(CH_BAUD0);
ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
}
mval = D_DTR(ch) | D_RTS(ch);
} else {
/*
* Set baud rate, character size, and parity.
*/
int iindex = 0;
int jindex =