Commit 55b307da authored by Jiri Slaby's avatar Jiri Slaby Committed by Linus Torvalds
Browse files

[PATCH] Char: mxser_new, rework to allow dynamic structs



This patch is preparation for further patches (pci probing) to allow allocated
structures to be private data in pci_dev structure.  Union two different
structures used in the driver (hw_conf and port/board descriptor) to another
2: port and board not to initialize 2 different things and to have ports
contained in board structure.
Signed-off-by: default avatarJiri Slaby <jirislaby@gmail.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 3306ce3d
......@@ -57,7 +57,7 @@
#include "mxser_new.h"
#define MXSER_VERSION "1.9.1"
#define MXSER_VERSION "2.0"
#define MXSERMAJOR 174
#define MXSERCUMAJOR 175
......@@ -85,8 +85,6 @@
#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|\
IXON|IXOFF))
#define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? IRQF_SHARED : IRQF_DISABLED)
#define C168_ASIC_ID 1
#define C104_ASIC_ID 2
#define C102_ASIC_ID 0xB
......@@ -202,8 +200,6 @@ static const struct mxpciuart_info Gpci_uart_info[UART_INFO_NUM] = {
};
#ifdef CONFIG_PCI
static struct pci_device_id mxser_pcibrds[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C168),
.driver_data = MXSER_BOARD_C168_PCI },
......@@ -243,18 +239,8 @@ static struct pci_device_id mxser_pcibrds[] = {
.driver_data = MXSER_BOARD_CP104EL },
{ }
};
MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
#endif
typedef struct _moxa_pci_info {
unsigned short busNum;
unsigned short devNum;
struct pci_dev *pdev; /* add by Victor Yu. 06-23-2003 */
} moxa_pci_info;
static int ioaddr[MXSER_BOARDS] = { 0, 0, 0, 0 };
static int ttymajor = MXSERMAJOR;
static int calloutmajor = MXSERCUMAJOR;
......@@ -301,69 +287,77 @@ struct mxser_mon_ext {
int iftype[32];
};
struct mxser_hwconf {
int board_type;
int ports;
int irq;
unsigned long vector;
unsigned long vector_mask;
int uart_type;
unsigned long ioaddr[MXSER_PORTS_PER_BOARD];
int baud_base[MXSER_PORTS_PER_BOARD];
moxa_pci_info pciInfo;
int IsMoxaMustChipFlag; /* add by Victor Yu. 08-30-2002 */
int MaxCanSetBaudRate[MXSER_PORTS_PER_BOARD]; /* add by Victor Yu. 09-04-2002 */
unsigned long opmode_ioaddr[MXSER_PORTS_PER_BOARD]; /* add by Victor Yu. 01-05-2004 */
};
struct mxser_board;
struct mxser_port {
struct mxser_board *board;
struct tty_struct *tty;
unsigned long ioaddr;
unsigned long opmode_ioaddr;
int max_baud;
struct mxser_struct {
int port;
unsigned long base; /* port base address */
int irq; /* port using irq no. */
unsigned long vector; /* port irq vector */
unsigned long vectormask; /* port vector mask */
int rx_high_water;
int rx_trigger; /* Rx fifo trigger level */
int rx_low_water;
int baud_base; /* max. speed */
int flags; /* defined in tty.h */
long realbaud;
int type; /* UART type */
struct tty_struct *tty;
int read_status_mask;
int ignore_status_mask;
int xmit_fifo_size;
int custom_divisor;
int flags; /* defined in tty.h */
long session; /* Session of opening process */
long pgrp; /* pgrp of opening process */
int x_char; /* xon/xoff character */
int close_delay;
unsigned short closing_wait;
int IER; /* Interrupt Enable Register */
int MCR; /* Modem control register */
unsigned char stop_rx;
unsigned char ldisc_stop_rx;
int custom_divisor;
int close_delay;
unsigned short closing_wait;
unsigned char err_shadow;
unsigned long event;
int count; /* # of fd on device */
int blocked_open; /* # of blocked opens */
long session; /* Session of opening process */
long pgrp; /* pgrp of opening process */
struct async_icount icount; /* kernel counters for 4 input interrupts */
int timeout;
int read_status_mask;
int ignore_status_mask;
int xmit_fifo_size;
unsigned char *xmit_buf;
int xmit_head;
int xmit_tail;
int xmit_cnt;
struct work_struct tqueue;
struct termios normal_termios;
struct termios callout_termios;
struct mxser_mon mon_data;
spinlock_t slock;
struct work_struct tqueue;
wait_queue_head_t open_wait;
wait_queue_head_t close_wait;
wait_queue_head_t delta_msr_wait;
struct async_icount icount; /* kernel counters for the 4 input interrupts */
int timeout;
int IsMoxaMustChipFlag; /* add by Victor Yu. 08-30-2002 */
int MaxCanSetBaudRate; /* add by Victor Yu. 09-04-2002 */
unsigned long opmode_ioaddr; /* add by Victor Yu. 01-05-2004 */
unsigned char stop_rx;
unsigned char ldisc_stop_rx;
long realbaud;
struct mxser_mon mon_data;
unsigned char err_shadow;
spinlock_t slock;
};
struct mxser_board {
struct pci_dev *pdev; /* temporary (until pci probing) */
int irq;
int board_type;
unsigned int nports;
unsigned long vector;
unsigned long vector_mask;
int chip_flag;
int uart_type;
struct mxser_port ports[MXSER_PORTS_PER_BOARD];
};
struct mxser_mstatus {
......@@ -381,8 +375,8 @@ static int mxserBoardCAP[MXSER_BOARDS] = {
/* 0x180, 0x280, 0x200, 0x320 */
};
static struct mxser_board mxser_boards[MXSER_BOARDS];
static struct tty_driver *mxvar_sdriver;
static struct mxser_struct mxvar_table[MXSER_PORTS];
static struct tty_struct *mxvar_tty[MXSER_PORTS + 1];
static struct termios *mxvar_termios[MXSER_PORTS + 1];
static struct termios *mxvar_termios_locked[MXSER_PORTS + 1];
......@@ -393,22 +387,14 @@ static struct mxser_mon_ext mon_data_ext;
static int mxser_set_baud_method[MXSER_PORTS + 1];
static spinlock_t gm_lock;
/*
* This is used to figure out the divisor speeds and the timeouts
*/
static struct mxser_hwconf mxsercfg[MXSER_BOARDS];
/*
* static functions:
*/
static void mxser_getcfg(int board, struct mxser_hwconf *hwconf);
static int mxser_init(void);
/* static void mxser_poll(unsigned long); */
static int mxser_get_ISA_conf(int, struct mxser_hwconf *);
static int mxser_get_PCI_conf(int, int, int, struct mxser_hwconf *);
static int mxser_get_ISA_conf(int, struct mxser_board *);
static void mxser_do_softint(void *);
static int mxser_open(struct tty_struct *, struct file *);
static void mxser_close(struct tty_struct *, struct file *);
......@@ -428,24 +414,28 @@ static void mxser_start(struct tty_struct *);
static void mxser_hangup(struct tty_struct *);
static void mxser_rs_break(struct tty_struct *, int);
static irqreturn_t mxser_interrupt(int, void *, struct pt_regs *);
static void mxser_receive_chars(struct mxser_struct *, int *);
static void mxser_transmit_chars(struct mxser_struct *);
static void mxser_check_modem_status(struct mxser_struct *, int);
static int mxser_block_til_ready(struct tty_struct *, struct file *, struct mxser_struct *);
static int mxser_startup(struct mxser_struct *);
static void mxser_shutdown(struct mxser_struct *);
static int mxser_change_speed(struct mxser_struct *, struct termios *old_termios);
static int mxser_get_serial_info(struct mxser_struct *, struct serial_struct __user *);
static int mxser_set_serial_info(struct mxser_struct *, struct serial_struct __user *);
static int mxser_get_lsr_info(struct mxser_struct *, unsigned int __user *);
static void mxser_send_break(struct mxser_struct *, int);
static void mxser_receive_chars(struct mxser_port *, int *);
static void mxser_transmit_chars(struct mxser_port *);
static void mxser_check_modem_status(struct mxser_port *, int);
static int mxser_block_til_ready(struct tty_struct *, struct file *,
struct mxser_port *);
static int mxser_startup(struct mxser_port *);
static void mxser_shutdown(struct mxser_port *);
static int mxser_change_speed(struct mxser_port *, struct termios *);
static int mxser_get_serial_info(struct mxser_port *,
struct serial_struct __user *);
static int mxser_set_serial_info(struct mxser_port *,
struct serial_struct __user *);
static int mxser_get_lsr_info(struct mxser_port *, unsigned int __user *);
static void mxser_send_break(struct mxser_port *, int);
static int mxser_tiocmget(struct tty_struct *, struct file *);
static int mxser_tiocmset(struct tty_struct *, struct file *, unsigned int, unsigned int);
static int mxser_set_baud(struct mxser_struct *info, long newspd);
static void mxser_wait_until_sent(struct tty_struct *tty, int timeout);
static int mxser_tiocmset(struct tty_struct *, struct file *, unsigned int,
unsigned int);
static int mxser_set_baud(struct mxser_port *, long);
static void mxser_wait_until_sent(struct tty_struct *, int);
static void mxser_startrx(struct tty_struct *tty);
static void mxser_stoprx(struct tty_struct *tty);
static void mxser_startrx(struct tty_struct *);
static void mxser_stoprx(struct tty_struct *);
static int CheckIsMoxaMust(int io)
......@@ -530,18 +520,18 @@ static void __exit mxser_module_exit(void)
for (i = 0; i < MXSER_BOARDS; i++) {
struct pci_dev *pdev;
if (mxsercfg[i].board_type == -1)
if (mxser_boards[i].board_type == -1)
continue;
else {
pdev = mxsercfg[i].pciInfo.pdev;
free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
pdev = mxser_boards[i].pdev;
free_irq(mxser_boards[i].irq, &mxser_boards[i]);
if (pdev != NULL) { /* PCI */
release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2));
release_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3));
pci_dev_put(pdev);
} else {
release_region(mxsercfg[i].ioaddr[0], 8 * mxsercfg[i].ports);
release_region(mxsercfg[i].vector, 1);
release_region(mxser_boards[i].ports[0].ioaddr, 8 * mxser_boards[i].nports);
release_region(mxser_boards[i].vector, 1);
}
}
}
......@@ -549,7 +539,7 @@ static void __exit mxser_module_exit(void)
printk(KERN_DEBUG "Done.\n");
}
static void process_txrx_fifo(struct mxser_struct *info)
static void process_txrx_fifo(struct mxser_port *info)
{
int i;
......@@ -558,60 +548,44 @@ static void process_txrx_fifo(struct mxser_struct *info)
info->rx_high_water = 1;
info->rx_low_water = 1;
info->xmit_fifo_size = 1;
} else {
for (i = 0; i < UART_INFO_NUM; i++) {
if (info->IsMoxaMustChipFlag == Gpci_uart_info[i].type) {
} else
for (i = 0; i < UART_INFO_NUM; i++)
if (info->board->chip_flag == Gpci_uart_info[i].type) {
info->rx_trigger = Gpci_uart_info[i].rx_trigger;
info->rx_low_water = Gpci_uart_info[i].rx_low_water;
info->rx_high_water = Gpci_uart_info[i].rx_high_water;
info->xmit_fifo_size = Gpci_uart_info[i].xmit_fifo_size;
break;
}
}
}
}
static int mxser_initbrd(int board, struct mxser_hwconf *hwconf)
static int mxser_initbrd(struct mxser_board *brd)
{
struct mxser_struct *info;
struct mxser_port *info;
unsigned int i;
int retval;
int i, n;
n = board * MXSER_PORTS_PER_BOARD;
info = &mxvar_table[n];
/*if (verbose) */ {
printk(KERN_DEBUG " ttyM%d - ttyM%d ",
n, n + hwconf->ports - 1);
printk(" max. baud rate = %d bps.\n",
hwconf->MaxCanSetBaudRate[0]);
brd->ports[0].max_baud);
}
for (i = 0; i < hwconf->ports; i++, n++, info++) {
info->port = n;
info->base = hwconf->ioaddr[i];
info->irq = hwconf->irq;
info->vector = hwconf->vector;
info->vectormask = hwconf->vector_mask;
info->opmode_ioaddr = hwconf->opmode_ioaddr[i]; /* add by Victor Yu. 01-05-2004 */
for (i = 0; i < brd->nports; i++) {
info = &brd->ports[i];
info->board = brd;
info->stop_rx = 0;
info->ldisc_stop_rx = 0;
info->IsMoxaMustChipFlag = hwconf->IsMoxaMustChipFlag;
/* Enhance mode enabled here */
if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
ENABLE_MOXA_MUST_ENCHANCE_MODE(info->base);
}
if (brd->chip_flag != MOXA_OTHER_UART)
ENABLE_MOXA_MUST_ENCHANCE_MODE(info->ioaddr);
info->flags = ASYNC_SHARE_IRQ;
info->type = hwconf->uart_type;
info->baud_base = hwconf->baud_base[i];
info->MaxCanSetBaudRate = hwconf->MaxCanSetBaudRate[i];
info->type = brd->uart_type;
process_txrx_fifo(info);
info->custom_divisor = hwconf->baud_base[i] * 16;
info->custom_divisor = info->baud_base * 16;
info->close_delay = 5 * HZ / 10;
info->closing_wait = 30 * HZ;
INIT_WORK(&info->tqueue, mxser_do_softint, info);
......@@ -622,118 +596,102 @@ static int mxser_initbrd(int board, struct mxser_hwconf *hwconf)
memset(&info->mon_data, 0, sizeof(struct mxser_mon));
info->err_shadow = 0;
spin_lock_init(&info->slock);
/* before set INT ISR, disable all int */
outb(inb(info->ioaddr + UART_IER) & 0xf0,
info->ioaddr + UART_IER);
}
/*
* Allocate the IRQ if necessary
*/
/* before set INT ISR, disable all int */
for (i = 0; i < hwconf->ports; i++) {
outb(inb(hwconf->ioaddr[i] + UART_IER) & 0xf0,
hwconf->ioaddr[i] + UART_IER);
}
n = board * MXSER_PORTS_PER_BOARD;
info = &mxvar_table[n];
retval = request_irq(hwconf->irq, mxser_interrupt, IRQ_T(info),
"mxser", info);
retval = request_irq(brd->irq, mxser_interrupt,
(brd->ports[0].flags & ASYNC_SHARE_IRQ) ? IRQF_SHARED :
IRQF_DISABLED, "mxser", brd);
if (retval) {
printk(KERN_ERR "Board %d: %s",
board, mxser_brdname[hwconf->board_type - 1]);
printk(" Request irq failed, IRQ (%d) may conflict with"
" another device.\n", info->irq);
printk(KERN_ERR "Board %s: Request irq failed, IRQ (%d) may "
"conflict with another device.\n",
mxser_brdname[brd->board_type - 1], brd->irq);
return retval;
}
return 0;
}
static void mxser_getcfg(int board, struct mxser_hwconf *hwconf)
{
mxsercfg[board] = *hwconf;
}
#ifdef CONFIG_PCI
static int mxser_get_PCI_conf(int busnum, int devnum, int board_type, struct mxser_hwconf *hwconf)
static int mxser_get_PCI_conf(int board_type, struct mxser_board *brd,
struct pci_dev *pdev)
{
int i, j;
/* unsigned int val; */
unsigned int i, j;
unsigned long ioaddress;
struct pci_dev *pdev = hwconf->pciInfo.pdev;
/* io address */
hwconf->board_type = board_type;
hwconf->ports = mxser_numports[board_type - 1];
brd->board_type = board_type;
brd->nports = mxser_numports[board_type - 1];
ioaddress = pci_resource_start(pdev, 2);
request_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2),
"mxser(IO)");
for (i = 0; i < hwconf->ports; i++)
hwconf->ioaddr[i] = ioaddress + 8 * i;
for (i = 0; i < brd->nports; i++)
brd->ports[i].ioaddr = ioaddress + 8 * i;
/* vector */
ioaddress = pci_resource_start(pdev, 3);
request_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3),
"mxser(vector)");
hwconf->vector = ioaddress;
brd->vector = ioaddress;
/* irq */
hwconf->irq = hwconf->pciInfo.pdev->irq;
brd->irq = pdev->irq;
hwconf->IsMoxaMustChipFlag = CheckIsMoxaMust(hwconf->ioaddr[0]);
hwconf->uart_type = PORT_16550A;
hwconf->vector_mask = 0;
brd->chip_flag = CheckIsMoxaMust(brd->ports[0].ioaddr);
brd->uart_type = PORT_16550A;
brd->vector_mask = 0;
for (i = 0; i < hwconf->ports; i++) {
for (i = 0; i < brd->nports; i++) {
for (j = 0; j < UART_INFO_NUM; j++) {
if (Gpci_uart_info[j].type == hwconf->IsMoxaMustChipFlag) {
hwconf->MaxCanSetBaudRate[i] = Gpci_uart_info[j].max_baud;
if (Gpci_uart_info[j].type == brd->chip_flag) {
brd->ports[i].max_baud =
Gpci_uart_info[j].max_baud;
/* exception....CP-102 */
if (board_type == MXSER_BOARD_CP102)
hwconf->MaxCanSetBaudRate[i] = 921600;
brd->ports[i].max_baud = 921600;
break;
}
}
}
if (hwconf->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID) {
for (i = 0; i < hwconf->ports; i++) {
if (brd->chip_flag == MOXA_MUST_MU860_HWID) {
for (i = 0; i < brd->nports; i++) {
if (i < 4)
hwconf->opmode_ioaddr[i] = ioaddress + 4;
brd->ports[i].opmode_ioaddr = ioaddress + 4;
else
hwconf->opmode_ioaddr[i] = ioaddress + 0x0c;
brd->ports[i].opmode_ioaddr = ioaddress + 0x0c;
}
outb(0, ioaddress + 4); /* default set to RS232 mode */
outb(0, ioaddress + 0x0c); /* default set to RS232 mode */
}
for (i = 0; i < hwconf->ports; i++) {
hwconf->vector_mask |= (1 << i);
hwconf->baud_base[i] = 921600;
for (i = 0; i < brd->nports; i++) {
brd->vector_mask |= (1 << i);
brd->ports[i].baud_base = 921600;
}
return 0;
}
#endif
static int mxser_init(void)
{
int i, m, retval, b, n;
struct pci_dev *pdev = NULL;
int index;
unsigned char busnum, devnum;
struct mxser_hwconf hwconf;
struct mxser_board *brd;
unsigned int i, m;
int retval, b, n;
mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1);
if (!mxvar_sdriver)
return -ENOMEM;
spin_lock_init(&gm_lock);
for (i = 0; i < MXSER_BOARDS; i++) {
mxsercfg[i].board_type = -1;
}
for (i = 0; i < MXSER_BOARDS; i++)
mxser_boards[i].board_type = -1;
printk(KERN_INFO "MOXA Smartio/Industio family driver version %s\n",
MXSER_VERSION);
......@@ -756,13 +714,12 @@ static int mxser_init(void)
mxvar_sdriver->termios_locked = mxvar_termios_locked;
mxvar_diagflag = 0;
memset(mxvar_table, 0, MXSER_PORTS * sizeof(struct mxser_struct));
memset(mxser_boards, 0, sizeof(mxser_boards));
memset(&mxvar_log, 0, sizeof(struct mxser_log));
memset(&mxser_msr, 0, sizeof(unsigned char) * (MXSER_PORTS + 1));
memset(&mon_data_ext, 0, sizeof(struct mxser_mon_ext));
memset(&mxser_set_baud_method, 0, sizeof(int) * (MXSER_PORTS + 1));
memset(&hwconf, 0, sizeof(struct mxser_hwconf));
m = 0;
/* Start finding ISA boards here */
......@@ -772,11 +729,12 @@ static int mxser_init(void)
if (!(cap = mxserBoardCAP[b]))
continue;
retval = mxser_get_ISA_conf(cap, &hwconf);
brd = &mxser_boards[m];
retval = mxser_get_ISA_conf(cap, brd);
if (retval != 0)
printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n",
mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
mxser_brdname[brd->board_type - 1], ioaddr[b]);
if (retval <= 0) {
if (retval == MXSER_ERR_IRQ)
......@@ -795,17 +753,10 @@ static int mxser_init(void)
continue;
}
hwconf.pciInfo.busNum = 0;
hwconf.pciInfo.devNum = 0;
hwconf.pciInfo.pdev = NULL;
brd->pdev = NULL;
mxser_getcfg(m, &hwconf);
/*
* init mxsercfg first,
* or mxsercfg data is not correct on ISR.
*/
/* mxser_initbrd will hook ISR. */
if (mxser_initbrd(m, &hwconf) < 0)
if (mxser_initbrd(brd) < 0)
continue;
m++;
......@@ -818,11 +769,12 @@ static int mxser_init(void)
if (!(cap = ioaddr[b]))
continue;
retval = mxser_get_ISA_conf(cap, &hwconf);
brd = &mxser_boards[m];
retval = mxser_get_ISA_conf(cap, &mxser_boards[m]);
if (retval != 0)
printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n",
mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
mxser_brdname[brd->board_type - 1], ioaddr[b]);
if (retval <= 0) {
if (retval == MXSER_ERR_IRQ)
......@@ -841,26 +793,16 @@ static int mxser_init(void)
continue;
}
hwconf.pciInfo.busNum = 0;
hwconf.pciInfo.devNum = 0;
hwconf.pciInfo.pdev = NULL;
mxser_getcfg(m, &hwconf);
/*
* init mxsercfg first,
* or mxsercfg data is not correct on ISR.
*/
brd->pdev = NULL;
/* mxser_initbrd will hook ISR. */
if (mxser_initbrd(m, &hwconf) < 0)
if (mxser_initbrd(brd) < 0)
continue;
m++;
}
/* start finding PCI board here */
#ifdef CONFIG_PCI
n = ARRAY_SIZE(mxser_pcibrds) - 1;
index = 0;
b = 0;
while (b < n) {
pdev = pci_get_device(mxser_pcibrds[b].vendor,
......@@ -869,13 +811,9 @@ static int mxser_init(void)
b++;
continue;
}
hwconf.pciInfo.busNum = busnum = pdev->bus->number;
hwconf.pciInfo.devNum = devnum = PCI_SLOT(pdev->devfn) << 3;
hwconf.pciInfo.pdev = pdev;
printk(KERN_INFO "Found MOXA %s board(BusNo=%d,DevNo=%d)\n",
mxser_brdname[(int) (mxser_pcibrds[b].driver_data) - 1],
busnum, devnum >> 3);
index++;
pdev->bus->number, PCI_SLOT(pdev->devfn));
if (m >= MXSER_BOARDS)
printk(KERN_ERR