Commit 83a66c22 authored by David S. Miller's avatar David S. Miller

Merge bk://kernel.bkbits.net/acme/net-2.5

into nuts.ninka.net:/home/davem/src/BK/net-2.5
parents f3ed32e2 c07aef96
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Author: Arnaldo Carvalho de Melo <acme@conectiva.com.br> * Author: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
* *
* Copyright: (c) 1998-2000 Arnaldo Carvalho de Melo * Copyright: (c) 1998-2003 Arnaldo Carvalho de Melo
* *
* Based on sdladrv.c by Gene Kozin <genek@compuserve.com> * Based on sdladrv.c by Gene Kozin <genek@compuserve.com>
* *
...@@ -66,12 +66,6 @@ MODULE_AUTHOR("Arnaldo Carvalho de Melo"); ...@@ -66,12 +66,6 @@ MODULE_AUTHOR("Arnaldo Carvalho de Melo");
MODULE_DESCRIPTION("Cyclom 2x Sync Card Driver"); MODULE_DESCRIPTION("Cyclom 2x Sync Card Driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
/* Function Prototypes */
/* Module entry points. These are called by the OS and must be public. */
int init_module(void);
void cleanup_module(void);
/* Hardware-specific functions */ /* Hardware-specific functions */
static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len); static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len);
static void cycx_bootcfg(cycxhw_t *hw); static void cycx_bootcfg(cycxhw_t *hw);
...@@ -86,27 +80,19 @@ static u16 checksum(u8 *buf, u32 len); ...@@ -86,27 +80,19 @@ static u16 checksum(u8 *buf, u32 len);
#define wait_cyc(addr) cycx_exec(addr + CMD_OFFSET) #define wait_cyc(addr) cycx_exec(addr + CMD_OFFSET)
#define cyc2x_readb(b) readb(b)
#define cyc2x_readw(b) readw(b)
#define cyc2x_writeb(b, addr) writeb(b, addr)
#define cyc2x_writew(w, addr) writew(w, addr)
#define cyc2x_memcpy_toio(addr, buf, len) memcpy_toio((addr), buf, len)
#define cyc2x_memcpy_fromio(buf, addr, len) memcpy_fromio(buf, (addr), len)
/* Global Data */ /* Global Data */
/* private data */ /* private data */
static char modname[] = "cycx_drv"; static char modname[] = "cycx_drv";
static char fullname[] = "Cyclom 2X Support Module"; static char fullname[] = "Cyclom 2X Support Module";
static char copyright[] = "(c) 1998-2000 Arnaldo Carvalho de Melo " static char copyright[] = "(c) 1998-2003 Arnaldo Carvalho de Melo "
"<acme@conectiva.com.br>"; "<acme@conectiva.com.br>";
/* Hardware configuration options. /* Hardware configuration options.
* These are arrays of configuration options used by verification routines. * These are arrays of configuration options used by verification routines.
* The first element of each array is its size (i.e. number of options). * The first element of each array is its size (i.e. number of options).
*/ */
static u32 cyc2x_dpmbase_options[] = static u32 cyc2x_dpmbase_options[] = {
{
20, 20,
0xA0000, 0xA4000, 0xA8000, 0xAC000, 0xB0000, 0xB4000, 0xB8000, 0xA0000, 0xA4000, 0xA8000, 0xAC000, 0xB0000, 0xB4000, 0xB8000,
0xBC000, 0xC0000, 0xC4000, 0xC8000, 0xCC000, 0xD0000, 0xD4000, 0xBC000, 0xC0000, 0xC4000, 0xC8000, 0xCC000, 0xD0000, 0xD4000,
...@@ -158,7 +144,7 @@ int cycx_setup(cycxhw_t *hw, void *cfm, u32 len) ...@@ -158,7 +144,7 @@ int cycx_setup(cycxhw_t *hw, void *cfm, u32 len)
if (!get_option_index(cycx_2x_irq_options, hw->irq)) { if (!get_option_index(cycx_2x_irq_options, hw->irq)) {
printk(KERN_ERR "%s: IRQ %d is illegal!\n", modname, hw->irq); printk(KERN_ERR "%s: IRQ %d is illegal!\n", modname, hw->irq);
return -EINVAL; return -EINVAL;
} }
/* Setup adapter dual-port memory window and test memory */ /* Setup adapter dual-port memory window and test memory */
if (!hw->dpmbase) { if (!hw->dpmbase) {
...@@ -190,7 +176,7 @@ int cycx_setup(cycxhw_t *hw, void *cfm, u32 len) ...@@ -190,7 +176,7 @@ int cycx_setup(cycxhw_t *hw, void *cfm, u32 len)
cycx_down(hw); /* shutdown adapter */ cycx_down(hw); /* shutdown adapter */
return err; return err;
} }
EXPORT_SYMBOL(cycx_down); EXPORT_SYMBOL(cycx_down);
int cycx_down(cycxhw_t *hw) int cycx_down(cycxhw_t *hw)
...@@ -204,14 +190,14 @@ int cycx_down(cycxhw_t *hw) ...@@ -204,14 +190,14 @@ int cycx_down(cycxhw_t *hw)
EXPORT_SYMBOL(cycx_inten); EXPORT_SYMBOL(cycx_inten);
void cycx_inten(cycxhw_t *hw) void cycx_inten(cycxhw_t *hw)
{ {
cyc2x_writeb(0, hw->dpmbase); writeb(0, hw->dpmbase);
} }
/* Generate an interrupt to adapter's CPU. */ /* Generate an interrupt to adapter's CPU. */
EXPORT_SYMBOL(cycx_intr); EXPORT_SYMBOL(cycx_intr);
void cycx_intr(cycxhw_t *hw) void cycx_intr(cycxhw_t *hw)
{ {
cyc2x_writew(0, hw->dpmbase + GEN_CYCX_INTR); writew(0, hw->dpmbase + GEN_CYCX_INTR);
} }
/* Execute Adapter Command. /* Execute Adapter Command.
...@@ -223,9 +209,9 @@ int cycx_exec(u32 addr) ...@@ -223,9 +209,9 @@ int cycx_exec(u32 addr)
u16 i = 0; u16 i = 0;
/* wait till addr content is zeroed */ /* wait till addr content is zeroed */
while (cyc2x_readw(addr)) { while (readw(addr)) {
udelay(1000); udelay(1000);
if (++i > 50) if (++i > 50)
return -1; return -1;
} }
...@@ -239,9 +225,9 @@ EXPORT_SYMBOL(cycx_peek); ...@@ -239,9 +225,9 @@ EXPORT_SYMBOL(cycx_peek);
int cycx_peek(cycxhw_t *hw, u32 addr, void *buf, u32 len) int cycx_peek(cycxhw_t *hw, u32 addr, void *buf, u32 len)
{ {
if (len == 1) if (len == 1)
*(u8*)buf = cyc2x_readb(hw->dpmbase + addr); *(u8*)buf = readb(hw->dpmbase + addr);
else else
cyc2x_memcpy_fromio(buf, hw->dpmbase + addr, len); memcpy_fromio(buf, hw->dpmbase + addr, len);
return 0; return 0;
} }
...@@ -252,9 +238,9 @@ EXPORT_SYMBOL(cycx_poke); ...@@ -252,9 +238,9 @@ EXPORT_SYMBOL(cycx_poke);
int cycx_poke(cycxhw_t *hw, u32 addr, void *buf, u32 len) int cycx_poke(cycxhw_t *hw, u32 addr, void *buf, u32 len)
{ {
if (len == 1) if (len == 1)
cyc2x_writeb(*(u8*)buf, hw->dpmbase + addr); writeb(*(u8*)buf, hw->dpmbase + addr);
else else
cyc2x_memcpy_toio(hw->dpmbase + addr, buf, len); memcpy_toio(hw->dpmbase + addr, buf, len);
return 0; return 0;
} }
...@@ -269,10 +255,10 @@ static int memory_exists(u32 addr) ...@@ -269,10 +255,10 @@ static int memory_exists(u32 addr)
int tries = 0; int tries = 0;
for (; tries < 3 ; tries++) { for (; tries < 3 ; tries++) {
cyc2x_writew(TEST_PATTERN, addr + 0x10); writew(TEST_PATTERN, addr + 0x10);
if (cyc2x_readw(addr + 0x10) == TEST_PATTERN) if (readw(addr + 0x10) == TEST_PATTERN)
if (cyc2x_readw(addr + 0x10) == TEST_PATTERN) if (readw(addr + 0x10) == TEST_PATTERN)
return 1; return 1;
delay_cycx(1); delay_cycx(1);
...@@ -289,7 +275,7 @@ static void reset_load(u32 addr, u8 *buffer, u32 cnt) ...@@ -289,7 +275,7 @@ static void reset_load(u32 addr, u8 *buffer, u32 cnt)
for (i = 0 ; i < cnt ; i++) { for (i = 0 ; i < cnt ; i++) {
/* for (j = 0 ; j < 50 ; j++); Delay - FIXME busy waiting... */ /* for (j = 0 ; j < 50 ; j++); Delay - FIXME busy waiting... */
cyc2x_writeb(*buffer++, pt_code++); writeb(*buffer++, pt_code++);
} }
} }
...@@ -298,8 +284,8 @@ static void reset_load(u32 addr, u8 *buffer, u32 cnt) ...@@ -298,8 +284,8 @@ static void reset_load(u32 addr, u8 *buffer, u32 cnt)
* o wait for reset code to copy it to right portion of memory */ * o wait for reset code to copy it to right portion of memory */
static int buffer_load(u32 addr, u8 *buffer, u32 cnt) static int buffer_load(u32 addr, u8 *buffer, u32 cnt)
{ {
cyc2x_memcpy_toio(addr + DATA_OFFSET, buffer, cnt); memcpy_toio(addr + DATA_OFFSET, buffer, cnt);
cyc2x_writew(GEN_BOOT_DAT, addr + CMD_OFFSET); writew(GEN_BOOT_DAT, addr + CMD_OFFSET);
return wait_cyc(addr); return wait_cyc(addr);
} }
...@@ -308,30 +294,30 @@ static int buffer_load(u32 addr, u8 *buffer, u32 cnt) ...@@ -308,30 +294,30 @@ static int buffer_load(u32 addr, u8 *buffer, u32 cnt)
static void cycx_start(u32 addr) static void cycx_start(u32 addr)
{ {
/* put in 0x30 offset the jump instruction to the code entry point */ /* put in 0x30 offset the jump instruction to the code entry point */
cyc2x_writeb(0xea, addr + 0x30); writeb(0xea, addr + 0x30);
cyc2x_writeb(0x00, addr + 0x31); writeb(0x00, addr + 0x31);
cyc2x_writeb(0xc4, addr + 0x32); writeb(0xc4, addr + 0x32);
cyc2x_writeb(0x00, addr + 0x33); writeb(0x00, addr + 0x33);
cyc2x_writeb(0x00, addr + 0x34); writeb(0x00, addr + 0x34);
/* cmd to start executing code */ /* cmd to start executing code */
cyc2x_writew(GEN_START, addr + CMD_OFFSET); writew(GEN_START, addr + CMD_OFFSET);
} }
/* Load and boot reset code. */ /* Load and boot reset code. */
static void cycx_reset_boot(u32 addr, u8 *code, u32 len) static void cycx_reset_boot(u32 addr, u8 *code, u32 len)
{ {
u32 pt_start = addr + START_OFFSET; u32 pt_start = addr + START_OFFSET;
cyc2x_writeb(0xea, pt_start++); /* jmp to f000:3f00 */ writeb(0xea, pt_start++); /* jmp to f000:3f00 */
cyc2x_writeb(0x00, pt_start++); writeb(0x00, pt_start++);
cyc2x_writeb(0xfc, pt_start++); writeb(0xfc, pt_start++);
cyc2x_writeb(0x00, pt_start++); writeb(0x00, pt_start++);
cyc2x_writeb(0xf0, pt_start); writeb(0xf0, pt_start);
reset_load(addr, code, len); reset_load(addr, code, len);
/* 80186 was in hold, go */ /* 80186 was in hold, go */
cyc2x_writeb(0, addr + START_CPU); writeb(0, addr + START_CPU);
delay_cycx(1); delay_cycx(1);
} }
...@@ -342,15 +328,15 @@ static int cycx_data_boot(u32 addr, u8 *code, u32 len) ...@@ -342,15 +328,15 @@ static int cycx_data_boot(u32 addr, u8 *code, u32 len)
u32 i; u32 i;
/* boot buffer lenght */ /* boot buffer lenght */
cyc2x_writew(CFM_LOAD_BUFSZ, pt_boot_cmd + sizeof(u16)); writew(CFM_LOAD_BUFSZ, pt_boot_cmd + sizeof(u16));
cyc2x_writew(GEN_DEFPAR, pt_boot_cmd); writew(GEN_DEFPAR, pt_boot_cmd);
if (wait_cyc(addr) < 0) if (wait_cyc(addr) < 0)
return -1; return -1;
cyc2x_writew(0, pt_boot_cmd + sizeof(u16)); writew(0, pt_boot_cmd + sizeof(u16));
cyc2x_writew(0x4000, pt_boot_cmd + 2 * sizeof(u16)); writew(0x4000, pt_boot_cmd + 2 * sizeof(u16));
cyc2x_writew(GEN_SET_SEG, pt_boot_cmd); writew(GEN_SET_SEG, pt_boot_cmd);
if (wait_cyc(addr) < 0) if (wait_cyc(addr) < 0)
return -1; return -1;
...@@ -373,21 +359,22 @@ static int cycx_code_boot(u32 addr, u8 *code, u32 len) ...@@ -373,21 +359,22 @@ static int cycx_code_boot(u32 addr, u8 *code, u32 len)
u32 i; u32 i;
/* boot buffer lenght */ /* boot buffer lenght */
cyc2x_writew(CFM_LOAD_BUFSZ, pt_boot_cmd + sizeof(u16)); writew(CFM_LOAD_BUFSZ, pt_boot_cmd + sizeof(u16));
cyc2x_writew(GEN_DEFPAR, pt_boot_cmd); writew(GEN_DEFPAR, pt_boot_cmd);
if (wait_cyc(addr) < 0) if (wait_cyc(addr) < 0)
return -1; return -1;
cyc2x_writew(0x0000, pt_boot_cmd + sizeof(u16)); writew(0x0000, pt_boot_cmd + sizeof(u16));
cyc2x_writew(0xc400, pt_boot_cmd + 2 * sizeof(u16)); writew(0xc400, pt_boot_cmd + 2 * sizeof(u16));
cyc2x_writew(GEN_SET_SEG, pt_boot_cmd); writew(GEN_SET_SEG, pt_boot_cmd);
if (wait_cyc(addr) < 0) if (wait_cyc(addr) < 0)
return -1; return -1;
for (i = 0 ; i < len ; i += CFM_LOAD_BUFSZ) for (i = 0 ; i < len ; i += CFM_LOAD_BUFSZ)
if (buffer_load(addr, code + i,MIN(CFM_LOAD_BUFSZ,(len - i)))) { if (buffer_load(addr, code + i,
MIN(CFM_LOAD_BUFSZ, (len - i)))) {
printk(KERN_ERR "%s: Error !!\n", modname); printk(KERN_ERR "%s: Error !!\n", modname);
return -1; return -1;
} }
...@@ -395,7 +382,7 @@ static int cycx_code_boot(u32 addr, u8 *code, u32 len) ...@@ -395,7 +382,7 @@ static int cycx_code_boot(u32 addr, u8 *code, u32 len)
return 0; return 0;
} }
/* Load adapter from the memory image of the CYCX firmware module. /* Load adapter from the memory image of the CYCX firmware module.
* o verify firmware integrity and compatibility * o verify firmware integrity and compatibility
* o start adapter up */ * o start adapter up */
static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len) static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len)
...@@ -433,7 +420,7 @@ static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len) ...@@ -433,7 +420,7 @@ static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len)
cksum = checksum((u8*)&cfm->info, sizeof(struct cycx_fw_info) + cksum = checksum((u8*)&cfm->info, sizeof(struct cycx_fw_info) +
cfm->info.codesize); cfm->info.codesize);
/* /*
FIXME cfm->info.codesize is off by 2 FIXME cfm->info.codesize is off by 2
if (((len - sizeof(struct cycx_firmware) - 1) != cfm->info.codesize) || if (((len - sizeof(struct cycx_firmware) - 1) != cfm->info.codesize) ||
*/ */
if (cksum != cfm->checksum) { if (cksum != cfm->checksum) {
...@@ -442,7 +429,7 @@ static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len) ...@@ -442,7 +429,7 @@ static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len)
printk(KERN_ERR " cdsize = 0x%x (expected 0x%lx)\n", printk(KERN_ERR " cdsize = 0x%x (expected 0x%lx)\n",
len - sizeof(struct cycx_firmware) - 1, len - sizeof(struct cycx_firmware) - 1,
cfm->info.codesize); cfm->info.codesize);
printk(KERN_ERR " chksum = 0x%x (expected 0x%x)\n", printk(KERN_ERR " chksum = 0x%x (expected 0x%x)\n",
cksum, cfm->checksum); cksum, cfm->checksum);
return -EINVAL; return -EINVAL;
} }
...@@ -462,7 +449,7 @@ static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len) ...@@ -462,7 +449,7 @@ static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len)
code_image = data_image + img_hdr->data_size; code_image = data_image + img_hdr->data_size;
/*---- Start load ----*/ /*---- Start load ----*/
/* Announce */ /* Announce */
printk(KERN_INFO "%s: loading firmware %s (ID=%u)...\n", modname, printk(KERN_INFO "%s: loading firmware %s (ID=%u)...\n", modname,
cfm->descr[0] ? cfm->descr : "unknown firmware", cfm->descr[0] ? cfm->descr : "unknown firmware",
cfm->info.codeid); cfm->info.codeid);
...@@ -476,13 +463,13 @@ static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len) ...@@ -476,13 +463,13 @@ static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len)
} }
/* Load reset.bin */ /* Load reset.bin */
cycx_reset_boot(hw->dpmbase, reset_image, img_hdr->reset_size); cycx_reset_boot(hw->dpmbase, reset_image, img_hdr->reset_size);
/* reset is waiting for boot */ /* reset is waiting for boot */
cyc2x_writew(GEN_POWER_ON, pt_cycld); writew(GEN_POWER_ON, pt_cycld);
delay_cycx(1); delay_cycx(1);
for (j = 0 ; j < 3 ; j++) for (j = 0 ; j < 3 ; j++)
if (!cyc2x_readw(pt_cycld)) if (!readw(pt_cycld))
goto reset_loaded; goto reset_loaded;
else else
delay_cycx(1); delay_cycx(1);
...@@ -516,7 +503,7 @@ static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len) ...@@ -516,7 +503,7 @@ static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len)
printk(KERN_INFO "%s: firmware loaded!\n", modname); printk(KERN_INFO "%s: firmware loaded!\n", modname);
/* enable interrupts */ /* enable interrupts */
cycx_inten(hw); cycx_inten(hw);
return 0; return 0;
} }
...@@ -530,7 +517,7 @@ static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len) ...@@ -530,7 +517,7 @@ static int load_cyc2x(cycxhw_t *hw, struct cycx_firmware *cfm, u32 len)
static void cycx_bootcfg(cycxhw_t *hw) static void cycx_bootcfg(cycxhw_t *hw)
{ {
/* use fixed buffers */ /* use fixed buffers */
cyc2x_writeb(FIXED_BUFFERS, hw->dpmbase + CONF_OFFSET); writeb(FIXED_BUFFERS, hw->dpmbase + CONF_OFFSET);
} }
/* Detect Cyclom 2x adapter. /* Detect Cyclom 2x adapter.
...@@ -563,9 +550,9 @@ static int get_option_index(u32 *optlist, u32 optval) ...@@ -563,9 +550,9 @@ static int get_option_index(u32 *optlist, u32 optval)
/* Reset adapter's CPU. */ /* Reset adapter's CPU. */
static int reset_cyc2x(u32 addr) static int reset_cyc2x(u32 addr)
{ {
cyc2x_writeb(0, addr + RST_ENABLE); writeb(0, addr + RST_ENABLE);
delay_cycx(2); delay_cycx(2);
cyc2x_writeb(0, addr + RST_DISABLE); writeb(0, addr + RST_DISABLE);
delay_cycx(2); delay_cycx(2);
return memory_exists(addr); return memory_exists(addr);
...@@ -575,7 +562,7 @@ static int reset_cyc2x(u32 addr) ...@@ -575,7 +562,7 @@ static int reset_cyc2x(u32 addr)
static void delay_cycx(int sec) static void delay_cycx(int sec)
{ {
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(sec*HZ); schedule_timeout(sec * HZ);
} }
/* Calculate 16-bit CRC using CCITT polynomial. */ /* Calculate 16-bit CRC using CCITT polynomial. */
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Author: Arnaldo Carvalho de Melo <acme@conectiva.com.br> * Author: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
* *
* Copyright: (c) 1998-2001 Arnaldo Carvalho de Melo * Copyright: (c) 1998-2003 Arnaldo Carvalho de Melo
* *
* Based on sdlamain.c by Gene Kozin <genek@compuserve.com> & * Based on sdlamain.c by Gene Kozin <genek@compuserve.com> &
* Jaspreet Singh <jaspreet@sangoma.com> * Jaspreet Singh <jaspreet@sangoma.com>
...@@ -75,7 +75,7 @@ static int shutdown(struct wan_device *wandev); ...@@ -75,7 +75,7 @@ static int shutdown(struct wan_device *wandev);
static int ioctl(struct wan_device *wandev, unsigned cmd, unsigned long arg); static int ioctl(struct wan_device *wandev, unsigned cmd, unsigned long arg);
/* Miscellaneous functions */ /* Miscellaneous functions */
static irqreturn_t cycx_isr (int irq, void *dev_id, struct pt_regs *regs); static irqreturn_t cycx_isr(int irq, void *dev_id, struct pt_regs *regs);
/* Global Data /* Global Data
* Note: All data must be explicitly initialized!!! * Note: All data must be explicitly initialized!!!
...@@ -103,7 +103,7 @@ static struct cycx_device *card_array; /* adapter data space */ ...@@ -103,7 +103,7 @@ static struct cycx_device *card_array; /* adapter data space */
* < 0 error. * < 0 error.
* Context: process * Context: process
*/ */
int __init cyclomx_init (void) int __init cyclomx_init(void)
{ {
int cnt, err = -ENOMEM; int cnt, err = -ENOMEM;
...@@ -156,7 +156,7 @@ out: return err; ...@@ -156,7 +156,7 @@ out: return err;
* o unregister all adapters from the WAN router * o unregister all adapters from the WAN router
* o release all remaining system resources * o release all remaining system resources
*/ */
static void __exit cyclomx_cleanup (void) static void __exit cyclomx_cleanup(void)
{ {
int i = 0; int i = 0;
...@@ -188,7 +188,7 @@ static int setup(struct wan_device *wandev, wandev_conf_t *conf) ...@@ -188,7 +188,7 @@ static int setup(struct wan_device *wandev, wandev_conf_t *conf)
int irq; int irq;
/* Sanity checks */ /* Sanity checks */
if (!wandev || !wandev->private || !conf) if (!wandev || !wandev->private || !conf)
goto out; goto out;
...@@ -243,14 +243,14 @@ static int setup(struct wan_device *wandev, wandev_conf_t *conf) ...@@ -243,14 +243,14 @@ static int setup(struct wan_device *wandev, wandev_conf_t *conf)
/* Protocol-specific initialization */ /* Protocol-specific initialization */
switch (card->hw.fwid) { switch (card->hw.fwid) {
#ifdef CONFIG_CYCLOMX_X25 #ifdef CONFIG_CYCLOMX_X25
case CFID_X25_2X: case CFID_X25_2X:
err = cyx_init(card, conf); err = cyx_init(card, conf);
break; break;
#endif #endif
default: default:
printk(KERN_ERR "%s: this firmware is not supported!\n", printk(KERN_ERR "%s: this firmware is not supported!\n",
wandev->name); wandev->name);
err = -EINVAL; err = -EINVAL;
} }
if (err) { if (err) {
...@@ -266,7 +266,7 @@ out: return err; ...@@ -266,7 +266,7 @@ out: return err;
} }
/* /*
* Shut down WAN link driver. * Shut down WAN link driver.
* o shut down adapter hardware * o shut down adapter hardware
* o release system resources. * o release system resources.
* *
...@@ -296,7 +296,7 @@ out: return ret; ...@@ -296,7 +296,7 @@ out: return ret;
} }
/* /*
* Driver I/O control. * Driver I/O control.
* o verify arguments * o verify arguments
* o perform requested action * o perform requested action
* *
...@@ -316,7 +316,7 @@ static int ioctl(struct wan_device *wandev, unsigned cmd, unsigned long arg) ...@@ -316,7 +316,7 @@ static int ioctl(struct wan_device *wandev, unsigned cmd, unsigned long arg)
* o acknowledge Cyclom 2X hardware interrupt. * o acknowledge Cyclom 2X hardware interrupt.
* o call protocol-specific interrupt service routine, if any. * o call protocol-specific interrupt service routine, if any.
*/ */
static irqreturn_t cycx_isr (int irq, void *dev_id, struct pt_regs *regs) static irqreturn_t cycx_isr(int irq, void *dev_id, struct pt_regs *regs)
{ {
struct cycx_device *card = (struct cycx_device *)dev_id; struct cycx_device *card = (struct cycx_device *)dev_id;
...@@ -345,15 +345,13 @@ void cyclomx_set_state(struct cycx_device *card, int state) ...@@ -345,15 +345,13 @@ void cyclomx_set_state(struct cycx_device *card, int state)
if (card->wandev.state != state) { if (card->wandev.state != state) {
switch (state) { switch (state) {
case WAN_CONNECTED: case WAN_CONNECTED:
string_state = "connected!"; string_state = "connected!";
break; break;
case WAN_DISCONNECTED:
case WAN_DISCONNECTED: string_state = "disconnected!";
string_state = "disconnected!"; break;
break;
} }
printk(KERN_INFO "%s: link %s\n", card->devname, string_state); printk(KERN_INFO "%s: link %s\n", card->devname, string_state);
card->wandev.state = state; card->wandev.state = state;
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Author: Arnaldo Carvalho de Melo <acme@conectiva.com.br> * Author: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
* *
* Copyright: (c) 1998-2001 Arnaldo Carvalho de Melo * Copyright: (c) 1998-2003 Arnaldo Carvalho de Melo
* *
* Based on sdla_x25.c by Gene Kozin <genek@compuserve.com> * Based on sdla_x25.c by Gene Kozin <genek@compuserve.com>
* *
...@@ -129,15 +129,15 @@ static int update(struct wan_device *wandev), ...@@ -129,15 +129,15 @@ static int update(struct wan_device *wandev),
del_if(struct wan_device *wandev, struct net_device *dev); del_if(struct wan_device *wandev, struct net_device *dev);
/* Network device interface */ /* Network device interface */
static int if_init (struct net_device *dev), static int if_init(struct net_device *dev),
if_open (struct net_device *dev), if_open(struct net_device *dev),
if_close (struct net_device *dev), if_close(struct net_device *dev),
if_header (struct sk_buff *skb, struct net_device *dev, if_header(struct sk_buff *skb, struct net_device *dev,
u16 type, void *daddr, void *saddr, unsigned len), u16 type, void *daddr, void *saddr, unsigned len),
if_rebuild_hdr (struct sk_buff *skb), if_rebuild_hdr(struct sk_buff *skb),
if_send (struct sk_buff *skb, struct net_device *dev); if_send(struct sk_buff *skb, struct net_device *dev);
static struct net_device_stats * if_stats (struct net_device *dev); static struct net_device_stats *if_stats(struct net_device *dev);
/* Interrupt handlers */ /* Interrupt handlers */
static void cyx_isr(struct cycx_device *card), static void cyx_isr(struct cycx_device *card),
...@@ -160,23 +160,23 @@ static int x25_configure(struct cycx_device *card, TX25Config *conf), ...@@ -160,23 +160,23 @@ static int x25_configure(struct cycx_device *card, TX25Config *conf),
x25_disconnect_response(struct cycx_device *card, u8 link, u8 lcn); x25_disconnect_response(struct cycx_device *card, u8 link, u8 lcn);
/* channel functions */ /* channel functions */
static int chan_connect (struct net_device *dev), static int chan_connect(struct net_device *dev),
chan_send (struct net_device *dev, struct sk_buff *skb); chan_send(struct net_device *dev, struct sk_buff *skb);
static void chan_disconnect (struct net_device *dev), static void chan_disconnect(struct net_device *dev),
chan_x25_send_event(struct net_device *dev, u8 event); chan_x25_send_event(struct net_device *dev, u8 event);
/* Miscellaneous functions */ /* Miscellaneous functions */
static void set_chan_state (struct net_device *dev, u8 state), static void set_chan_state(struct net_device *dev, u8 state),
chan_timer (unsigned long d); chan_timer(unsigned long d);
static void nibble_to_byte (u8 *s, u8 *d, u8 len, u8 nibble), static void nibble_to_byte(u8 *s, u8 *d, u8 len, u8 nibble),
reset_timer (struct net_device *dev); reset_timer(struct net_device *dev);
static u8 bps_to_speed_code (u32 bps); static u8 bps_to_speed_code(u32 bps);
static u8 log2 (u32 n); static u8 log2(u32 n);
static unsigned dec_to_uint (u8 *str, int len); static unsigned dec_to_uint(u8 *str, int len);
static struct net_device *get_dev_by_lcn(struct wan_device *wandev, s16 lcn); static struct net_device *get_dev_by_lcn(struct wan_device *wandev, s16 lcn);
static struct net_device *get_dev_by_dte_addr(struct wan_device *wandev, static struct net_device *get_dev_by_dte_addr(struct wan_device *wandev,
...@@ -260,7 +260,7 @@ int cyx_init(struct cycx_device *card, wandev_conf_t *conf) ...@@ -260,7 +260,7 @@ int cyx_init(struct cycx_device *card, wandev_conf_t *conf)
cfg.remaddr = 3; /* DTE */ cfg.remaddr = 3; /* DTE */
} }
if (conf->interface == WANOPT_RS232) if (conf->interface == WANOPT_RS232)
cfg.flags = 0; /* FIXME just reset the 2nd bit */ cfg.flags = 0; /* FIXME just reset the 2nd bit */
if (conf->u.x25.hi_pvc) { if (conf->u.x25.hi_pvc) {
...@@ -354,7 +354,8 @@ static int new_if(struct wan_device *wandev, struct net_device *dev, ...@@ -354,7 +354,8 @@ static int new_if(struct wan_device *wandev, struct net_device *dev,
int err = 0; int err = 0;
if (!conf->name[0] || strlen(conf->name) > WAN_IFNAME_SZ) { if (!conf->name[0] || strlen(conf->name) > WAN_IFNAME_SZ) {
printk(KERN_INFO "%s: invalid interface name!\n",card->devname); printk(KERN_INFO "%s: invalid interface name!\n",
card->devname);
return -EINVAL; return -EINVAL;
} }
...@@ -389,19 +390,19 @@ static int new_if(struct wan_device *wandev, struct net_device *dev, ...@@ -389,19 +390,19 @@ static int new_if(struct wan_device *wandev, struct net_device *dev,
} }
} }
strncpy(chan->local_addr, conf->local_addr, strncpy(chan->local_addr, conf->local_addr,
WAN_ADDRESS_SZ); WAN_ADDRESS_SZ);
} }
chan->svc = 1; chan->svc = 1;
strncpy(chan->addr, &conf->addr[1], WAN_ADDRESS_SZ); strncpy(chan->addr, &conf->addr[1], WAN_ADDRESS_SZ);
init_timer(&chan->timer); init_timer(&chan->timer);
chan->timer.function = chan_timer; chan->timer.function = chan_timer;
chan->timer.data = (unsigned long)dev; chan->timer.data = (unsigned long)dev;
/* Set channel timeouts (default if not specified) */ /* Set channel timeouts (default if not specified) */
chan->idle_tmout = conf->idle_timeout ? conf->idle_timeout : 90; chan->idle_tmout = conf->idle_timeout ? conf->idle_timeout : 90;
} else if (is_digit(conf->addr[0])) { /* PVC */ } else if (is_digit(conf->addr[0])) { /* PVC */
s16 lcn = dec_to_uint(conf->addr, 0); s16 lcn = dec_to_uint(conf->addr, 0);
if (lcn >= card->u.x.lo_pvc && lcn <= card->u.x.hi_pvc) if (lcn >= card->u.x.lo_pvc && lcn <= card->u.x.hi_pvc)
...@@ -492,8 +493,8 @@ static int if_init(struct net_device *dev) ...@@ -492,8 +493,8 @@ static int if_init(struct net_device *dev)
dev->mem_end = (unsigned long)(wandev->maddr + wandev->msize - 1); dev->mem_end = (unsigned long)(wandev->maddr + wandev->msize - 1);
dev->flags |= IFF_NOARP; dev->flags |= IFF_NOARP;
/* Set transmit buffer queue length */ /* Set transmit buffer queue length */
dev->tx_queue_len = 10; dev->tx_queue_len = 10;
SET_MODULE_OWNER(dev); SET_MODULE_OWNER(dev);
/* Initialize socket buffers */ /* Initialize socket buffers */
...@@ -510,7 +511,7 @@ static int if_init(struct net_device *dev) ...@@ -510,7 +511,7 @@ static int if_init(struct net_device *dev)
static int if_open(struct net_device *dev) static int if_open(struct net_device *dev)
{ {
if (netif_running(dev)) if (netif_running(dev))
return -EBUSY; /* only one open is allowed */ return -EBUSY; /* only one open is allowed */
netif_start_queue(dev); netif_start_queue(dev);
return 0; return 0;
...@@ -524,10 +525,10 @@ static int if_close(struct net_device *dev) ...@@ -524,10 +525,10 @@ static int if_close(struct net_device *dev)
x25_channel_t *chan = dev->priv; x25_channel_t *chan = dev->priv;
netif_stop_queue(dev); netif_stop_queue(dev);
if (chan->state == WAN_CONNECTED || chan->state == WAN_CONNECTING) if (chan->state == WAN_CONNECTED || chan->state == WAN_CONNECTING)
chan_disconnect(dev); chan_disconnect(dev);
return 0; return 0;
} }
...@@ -539,7 +540,7 @@ static int if_close(struct net_device *dev) ...@@ -539,7 +540,7 @@ static int if_close(struct net_device *dev)
* set skb->protocol to 0 and discard packet later. * set skb->protocol to 0 and discard packet later.
* *
* Return: media header length. */ * Return: media header length. */
static int if_header (struct sk_buff *skb, struct net_device *dev, static int if_header(struct sk_buff *skb, struct net_device *dev,
u16 type, void *daddr, void *saddr, unsigned len) u16 type, void *daddr, void *saddr, unsigned len)
{ {
skb->protocol = type; skb->protocol = type;
...@@ -550,7 +551,7 @@ static int if_header (struct sk_buff *skb, struct net_device *dev, ...@@ -550,7 +551,7 @@ static int if_header (struct sk_buff *skb, struct net_device *dev,
/* * Re-build media header. /* * Re-build media header.
* Return: 1 physical address resolved. * Return: 1 physical address resolved.
* 0 physical address not resolved */ * 0 physical address not resolved */
static int if_rebuild_hdr (struct sk_buff *skb) static int if_rebuild_hdr(struct sk_buff *skb)
{ {
return 1; return 1;
} }
...@@ -570,7 +571,7 @@ static int if_rebuild_hdr (struct sk_buff *skb) ...@@ -570,7 +571,7 @@ static int if_rebuild_hdr (struct sk_buff *skb)
* bottom half" (with interrupts enabled). * bottom half" (with interrupts enabled).
* 2. Setting tbusy flag will inhibit further transmit requests from the * 2. Setting tbusy flag will inhibit further transmit requests from the
* protocol stack and can be used for flow control with protocol layer. */ * protocol stack and can be used for flow control with protocol layer. */
static int if_send (struct sk_buff *skb, struct net_device *dev) static int if_send(struct sk_buff *skb, struct net_device *dev)
{ {
x25_channel_t *chan = dev->priv; x25_channel_t *chan = dev->priv;
struct cycx_device *card = chan->card; struct cycx_device *card = chan->card;
...@@ -580,55 +581,55 @@ static int if_send (struct sk_buff *skb, struct net_device *dev) ...@@ -580,55 +581,55 @@ static int if_send (struct sk_buff *skb, struct net_device *dev)
if (card->wandev.state != WAN_CONNECTED) if (card->wandev.state != WAN_CONNECTED)
++chan->ifstats.tx_dropped; ++chan->ifstats.tx_dropped;
else if (chan->svc && chan->protocol && else if (chan->svc && chan->protocol &&
chan->protocol != skb->protocol) { chan->protocol != skb->protocol) {
printk(KERN_INFO printk(KERN_INFO
"%s: unsupported Ethertype 0x%04X on interface %s!\n", "%s: unsupported Ethertype 0x%04X on interface %s!\n",
card->devname, skb->protocol, dev->name); card->devname, skb->protocol, dev->name);
++chan->ifstats.tx_errors; ++chan->ifstats.tx_errors;
} else if (chan->protocol == ETH_P_IP) { } else if (chan->protocol == ETH_P_IP) {
switch (chan->state) { switch (chan->state) {
case WAN_DISCONNECTED: case WAN_DISCONNECTED:
if (chan_connect(dev)) { if (chan_connect(dev)) {
netif_stop_queue(dev);
return -EBUSY;
}
/* fall thru */
case WAN_CONNECTED:
reset_timer(dev);
dev->trans_start = jiffies;
netif_stop_queue(dev); netif_stop_queue(dev);
return -EBUSY;
}
/* fall thru */
case WAN_CONNECTED:
reset_timer(dev);
dev->trans_start = jiffies;
netif_stop_queue(dev);
if (chan_send(dev, skb)) if (chan_send(dev, skb))
return -EBUSY; return -EBUSY;
break; break;
default: default:
++chan->ifstats.tx_dropped; ++chan->ifstats.tx_dropped;
++card->wandev.stats.tx_dropped; ++card->wandev.stats.tx_dropped;
} }
} else { /* chan->protocol == ETH_P_X25 */ } else { /* chan->protocol == ETH_P_X25 */
switch (skb->data[0]) { switch (skb->data[0]) {
case 0: break; case 0: break;
case 1: /* Connect request */ case 1: /* Connect request */
chan_connect(dev); chan_connect(dev);
goto free_packet; goto free_packet;
case 2: /* Disconnect request */ case 2: /* Disconnect request */
chan_disconnect(dev); chan_disconnect(dev);
goto free_packet; goto free_packet;
default: default:
printk(KERN_INFO printk(KERN_INFO
"%s: unknown %d x25-iface request on %s!\n", "%s: unknown %d x25-iface request on %s!\n",
card->devname, skb->data[0], dev->name); card->devname, skb->data[0], dev->name);
++chan->ifstats.tx_errors; ++chan->ifstats.tx_errors;
goto free_packet; goto free_packet;
} }
skb_pull(skb, 1); /* Remove control byte */ skb_pull(skb, 1); /* Remove control byte */
reset_timer(dev); reset_timer(dev);
dev->trans_start = jiffies; dev->trans_start = jiffies;
netif_stop_queue(dev); netif_stop_queue(dev);
if (chan_send(dev, skb)) { if (chan_send(dev, skb)) {
/* prepare for future retransmissions */ /* prepare for future retransmissions */
skb_push(skb, 1); skb_push(skb, 1);
...@@ -644,9 +645,9 @@ static int if_send (struct sk_buff *skb, struct net_device *dev) ...@@ -644,9 +645,9 @@ static int if_send (struct sk_buff *skb, struct net_device *dev)
/* Get Ethernet-style interface statistics. /* Get Ethernet-style interface statistics.
* Return a pointer to struct net_device_stats */ * Return a pointer to struct net_device_stats */
static struct net_device_stats *if_stats (struct net_device *dev) static struct net_device_stats *if_stats(struct net_device *dev)
{ {
x25_channel_t *chan = dev->priv; x25_channel_t *chan = dev->priv;
return chan ? &chan->ifstats : NULL; return chan ? &chan->ifstats : NULL;
} }
...@@ -663,38 +664,38 @@ static void cyx_isr(struct cycx_device *card) ...@@ -663,38 +664,38 @@ static void cyx_isr(struct cycx_device *card)
cycx_peek(&card->hw, X25_RXMBOX_OFFS, &cmd, sizeof(cmd)); cycx_peek(&card->hw, X25_RXMBOX_OFFS, &cmd, sizeof(cmd));
switch (cmd.command) { switch (cmd.command) {
case X25_DATA_INDICATION: case X25_DATA_INDICATION:
rx_intr(card, &cmd); rx_intr(card, &cmd);
break; break;
case X25_ACK_FROM_VC: case X25_ACK_FROM_VC:
tx_intr(card, &cmd); tx_intr(card, &cmd);
break; break;
case X25_LOG: case X25_LOG:
log_intr(card, &cmd); log_intr(card, &cmd);
break; break;
case X25_STATISTIC: case X25_STATISTIC:
stat_intr(card, &cmd); stat_intr(card, &cmd);
break; break;
case X25_CONNECT_CONFIRM: case X25_CONNECT_CONFIRM:
connect_confirm_intr(card, &cmd); connect_confirm_intr(card, &cmd);
break; break;
case X25_CONNECT_INDICATION: case X25_CONNECT_INDICATION:
connect_intr(card, &cmd); connect_intr(card, &cmd);
break; break;
case X25_DISCONNECT_INDICATION: case X25_DISCONNECT_INDICATION:
disconnect_intr(card, &cmd); disconnect_intr(card, &cmd);
break; break;
case X25_DISCONNECT_CONFIRM: case X25_DISCONNECT_CONFIRM:
disconnect_confirm_intr(card, &cmd); disconnect_confirm_intr(card, &cmd);
break; break;
case X25_LINE_ON: case X25_LINE_ON:
cyclomx_set_state(card, WAN_CONNECTED); cyclomx_set_state(card, WAN_CONNECTED);
break; break;
case X25_LINE_OFF: case X25_LINE_OFF:
cyclomx_set_state(card, WAN_DISCONNECTED); cyclomx_set_state(card, WAN_DISCONNECTED);
break; break;
default: default:
spur_intr(card, &cmd); /* unwanted interrupt */ spur_intr(card, &cmd); /* unwanted interrupt */
} }
cycx_poke(&card->hw, 0, &z, sizeof(z)); cycx_poke(&card->hw, 0, &z, sizeof(z));
...@@ -727,7 +728,7 @@ static void tx_intr(struct cycx_device *card, TX25Cmd *cmd) ...@@ -727,7 +728,7 @@ static void tx_intr(struct cycx_device *card, TX25Cmd *cmd)
* RFC1356. * RFC1356.
* o map logical channel number to network interface. * o map logical channel number to network interface.
* o allocate socket buffer or append received packet to the existing one. * o allocate socket buffer or append received packet to the existing one.
* o if M-bit is reset (i.e. it's the last packet in a sequence) then * o if M-bit is reset (i.e. it's the last packet in a sequence) then
* decapsulate packet and pass socket buffer to the protocol stack. * decapsulate packet and pass socket buffer to the protocol stack.
* *
* Notes: * Notes:
...@@ -782,7 +783,7 @@ static void rx_intr(struct cycx_device *card, TX25Cmd *cmd) ...@@ -782,7 +783,7 @@ static void rx_intr(struct cycx_device *card, TX25Cmd *cmd)
if (chan->protocol == ETH_P_X25) /* X.25 socket layer control */ if (chan->protocol == ETH_P_X25) /* X.25 socket layer control */
/* 0 = data packet (dev_alloc_skb zeroed skb->data) */ /* 0 = data packet (dev_alloc_skb zeroed skb->data) */
skb_put(skb, 1); skb_put(skb, 1);
skb->dev = dev; skb->dev = dev;
skb->protocol = htons(chan->protocol); skb->protocol = htons(chan->protocol);
...@@ -1049,7 +1050,7 @@ static int x25_configure(struct cycx_device *card, TX25Config *conf) ...@@ -1049,7 +1050,7 @@ static int x25_configure(struct cycx_device *card, TX25Config *conf)
TX25Config conf[2]; TX25Config conf[2];
} x25_cmd_conf; } x25_cmd_conf;
memset (&x25_cmd_conf, 0, sizeof(x25_cmd_conf)); memset(&x25_cmd_conf, 0, sizeof(x25_cmd_conf));
x25_cmd_conf.nlinks = 2; x25_cmd_conf.nlinks = 2;
x25_cmd_conf.conf[0] = *conf; x25_cmd_conf.conf[0] = *conf;
/* FIXME: we need to find a way in the wanrouter framework /* FIXME: we need to find a way in the wanrouter framework
...@@ -1107,27 +1108,27 @@ static int x25_get_stats(struct cycx_device *card) ...@@ -1107,27 +1108,27 @@ static int x25_get_stats(struct cycx_device *card)
/* return the number of nibbles */ /* return the number of nibbles */
static int byte_to_nibble(u8 *s, u8 *d, char *nibble) static int byte_to_nibble(u8 *s, u8 *d, char *nibble)
{ {
int i = 0; int i = 0;
if (*nibble && *s) { if (*nibble && *s) {
d[i] |= *s++ - '0'; d[i] |= *s++ - '0';
*nibble = 0; *nibble = 0;
++i; ++i;
} }
while (*s) { while (*s) {
d[i] = (*s - '0') << 4; d[i] = (*s - '0') << 4;
if (*(s + 1)) if (*(s + 1))
d[i] |= *(s + 1) - '0'; d[i] |= *(s + 1) - '0';
else { else {
*nibble = 1; *nibble = 1;
break; break;
} }
++i; ++i;
s += 2; s += 2;
} }
return i; return i;
} }
static void nibble_to_byte(u8 *s, u8 *d, u8 len, u8 nibble) static void nibble_to_byte(u8 *s, u8 *d, u8 len, u8 nibble)
...@@ -1144,7 +1145,7 @@ static void nibble_to_byte(u8 *s, u8 *d, u8 len, u8 nibble) ...@@ -1144,7 +1145,7 @@ static void nibble_to_byte(u8 *s, u8 *d, u8 len, u8 nibble)
*d++ = '0' + (*s & 0x0F); *d++ = '0' + (*s & 0x0F);
--len; --len;
} else break; } else break;
++s; ++s;
} }
...@@ -1187,14 +1188,14 @@ static int x25_place_call(struct cycx_device *card, x25_channel_t *chan) ...@@ -1187,14 +1188,14 @@ static int x25_place_call(struct cycx_device *card, x25_channel_t *chan)
d[5] = mylen << 4 | remotelen; d[5] = mylen << 4 | remotelen;
d[6 + len + 1] = 0xCC; /* TCP/IP over X.25, thanks to Daniela :) */ d[6 + len + 1] = 0xCC; /* TCP/IP over X.25, thanks to Daniela :) */
if ((err = x25_exec(card, X25_CONNECT_REQUEST, chan->link, if ((err = x25_exec(card, X25_CONNECT_REQUEST, chan->link,
&d, 7 + len + 1, NULL, 0)) != 0) &d, 7 + len + 1, NULL, 0)) != 0)
clear_bit(--key, (void*)&card->u.x.connection_keys); clear_bit(--key, (void*)&card->u.x.connection_keys);
else else
chan->lcn = -key; chan->lcn = -key;
return err; return err;
} }
/* Place X.25 CONNECT RESPONSE. */ /* Place X.25 CONNECT RESPONSE. */
...@@ -1244,7 +1245,7 @@ static int x25_clear_call(struct cycx_device *card, u8 link, u8 lcn, u8 cause, ...@@ -1244,7 +1245,7 @@ static int x25_clear_call(struct cycx_device *card, u8 link, u8 lcn, u8 cause,
static int x25_send(struct cycx_device *card, u8 link, u8 lcn, u8 bitm, int len, static int x25_send(struct cycx_device *card, u8 link, u8 lcn, u8 bitm, int len,
void *buf) void *buf)
{ {
u8 d[] = "?\xFF\x10??"; u8 d[] = "?\xFF\x10??";
d[0] = d[3] = lcn; d[0] = d[3] = lcn;
d[4] = bitm; d[4] = bitm;
...@@ -1265,7 +1266,7 @@ static struct net_device *get_dev_by_lcn(struct wan_device *wandev, s16 lcn) ...@@ -1265,7 +1266,7 @@ static struct net_device *get_dev_by_lcn(struct wan_device *wandev, s16 lcn)
if (chan->lcn == lcn) if (chan->lcn == lcn)
break; break;
dev = chan->slave; dev = chan->slave;
} }
return dev; return dev;
} }
...@@ -1293,24 +1294,24 @@ static struct net_device *get_dev_by_dte_addr(struct wan_device *wandev, ...@@ -1293,24 +1294,24 @@ static struct net_device *get_dev_by_dte_addr(struct wan_device *wandev,
* Return: 0 connected * Return: 0 connected
* >0 connection in progress * >0 connection in progress
* <0 failure */ * <0 failure */
static int chan_connect (struct net_device *dev) static int chan_connect(struct net_device *dev)
{ {
x25_channel_t *chan = dev->priv; x25_channel_t *chan = dev->priv;
struct cycx_device *card = chan->card; struct cycx_device *card = chan->card;
if (chan->svc) { if (chan->svc) {
if (!chan->addr[0]) if (!chan->addr[0])
return -EINVAL; /* no destination address */ return -EINVAL; /* no destination address */
dprintk(1, KERN_INFO "%s: placing X.25 call to %s...\n", dprintk(1, KERN_INFO "%s: placing X.25 call to %s...\n",
card->devname, chan->addr); card->devname, chan->addr);
if (x25_place_call(card, chan)) if (x25_place_call(card, chan))
return -EIO; return -EIO;
set_chan_state(dev, WAN_CONNECTING); set_chan_state(dev, WAN_CONNECTING);
return 1; return 1;
} else } else
set_chan_state(dev, WAN_CONNECTED); set_chan_state(dev, WAN_CONNECTED);
return 0; return 0;
...@@ -1318,7 +1319,7 @@ static int chan_connect (struct net_device *dev) ...@@ -1318,7 +1319,7 @@ static int chan_connect (struct net_device *dev)
/* Disconnect logical channel. /* Disconnect logical channel.
* o if SVC then clear X.25 call */ * o if SVC then clear X.25 call */
static void chan_disconnect (struct net_device *dev) static void chan_disconnect(struct net_device *dev)
{ {
x25_channel_t *chan = dev->priv; x25_channel_t *chan = dev->priv;
...@@ -1330,11 +1331,11 @@ static void chan_disconnect (struct net_device *dev) ...@@ -1330,11 +1331,11 @@ static void chan_disconnect (struct net_device *dev)
} }
/* Called by kernel timer */ /* Called by kernel timer */
static void chan_timer (unsigned long d) static void chan_timer(unsigned long d)
{ {
struct net_device *dev = (struct net_device *)d; struct net_device *dev = (struct net_device *)d;
x25_channel_t *chan = dev->priv; x25_channel_t *chan = dev->priv;
if (chan->state == WAN_CONNECTED) if (chan->state == WAN_CONNECTED)
chan_disconnect(dev); chan_disconnect(dev);
else else
...@@ -1343,7 +1344,7 @@ static void chan_timer (unsigned long d) ...@@ -1343,7 +1344,7 @@ static void chan_timer (unsigned long d)
} }
/* Set logical channel state. */ /* Set logical channel state. */
static void set_chan_state (struct net_device *dev, u8 state) static void set_chan_state(struct net_device *dev, u8 state)
{ {
x25_channel_t *chan = dev->priv; x25_channel_t *chan = dev->priv;
struct cycx_device *card = chan->card; struct cycx_device *card = chan->card;
...@@ -1355,43 +1356,40 @@ static void set_chan_state (struct net_device *dev, u8 state) ...@@ -1355,43 +1356,40 @@ static void set_chan_state (struct net_device *dev, u8 state)
if (chan->state != state) { if (chan->state != state) {
if (chan->svc && chan->state == WAN_CONNECTED) if (chan->svc && chan->state == WAN_CONNECTED)
del_timer(&chan->timer); del_timer(&chan->timer);
switch (state) { switch (state) {
case WAN_CONNECTED: case WAN_CONNECTED:
string_state = "connected!"; string_state = "connected!";
*(u16*)dev->dev_addr = htons(chan->lcn); *(u16*)dev->dev_addr = htons(chan->lcn);
netif_wake_queue(dev); netif_wake_queue(dev);
reset_timer(dev); reset_timer(dev);
if (chan->protocol == ETH_P_X25) if (chan->protocol == ETH_P_X25)
chan_x25_send_event(dev, 1); chan_x25_send_event(dev, 1);
break; break;
case WAN_CONNECTING:
case WAN_CONNECTING: string_state = "connecting...";
string_state = "connecting..."; break;
break; case WAN_DISCONNECTING:
string_state = "disconnecting...";
case WAN_DISCONNECTING: break;
string_state = "disconnecting..."; case WAN_DISCONNECTED:
break; string_state = "disconnected!";
case WAN_DISCONNECTED: if (chan->svc) {
string_state = "disconnected!"; *(unsigned short*)dev->dev_addr = 0;
chan->lcn = 0;
if (chan->svc) { }
*(unsigned short*)dev->dev_addr = 0;
chan->lcn = 0; if (chan->protocol == ETH_P_X25)
} chan_x25_send_event(dev, 2);
if (chan->protocol == ETH_P_X25) netif_wake_queue(dev);
chan_x25_send_event(dev, 2); break;
netif_wake_queue(dev);
break;
} }
printk (KERN_INFO "%s: interface %s %s\n", card->devname, printk(KERN_INFO "%s: interface %s %s\n", card->devname,
dev->name, string_state); dev->name, string_state);
chan->state = state; chan->state = state;
} }
...@@ -1412,7 +1410,7 @@ static void set_chan_state (struct net_device *dev, u8 state) ...@@ -1412,7 +1410,7 @@ static void set_chan_state (struct net_device *dev, u8 state)
* the packet into 'complete sequence' using M-bit. * the packet into 'complete sequence' using M-bit.
* 2. When transmission is complete, an event notification should be issued * 2. When transmission is complete, an event notification should be issued
* to the router. */ * to the router. */
static int chan_send (struct net_device *dev, struct sk_buff *skb) static int chan_send(struct net_device *dev, struct sk_buff *skb)
{ {
x25_channel_t *chan = dev->priv; x25_channel_t *chan = dev->priv;
struct cycx_device *card = chan->card; struct cycx_device *card = chan->card;
...@@ -1426,7 +1424,7 @@ static int chan_send (struct net_device *dev, struct sk_buff *skb) ...@@ -1426,7 +1424,7 @@ static int chan_send (struct net_device *dev, struct sk_buff *skb)
if (x25_send(card, chan->link, chan->lcn, bitm, len, skb->data)) if (x25_send(card, chan->link, chan->lcn, bitm, len, skb->data))
return 1; return 1;
if (bitm) { if (bitm) {
skb_pull(skb, len); skb_pull(skb, len);
return 1; return 1;
...@@ -1442,28 +1440,28 @@ static int chan_send (struct net_device *dev, struct sk_buff *skb) ...@@ -1442,28 +1440,28 @@ static int chan_send (struct net_device *dev, struct sk_buff *skb)
static void chan_x25_send_event(struct net_device *dev, u8 event) static void chan_x25_send_event(struct net_device *dev, u8 event)
{ {
struct sk_buff *skb; struct sk_buff *skb;
unsigned char *ptr; unsigned char *ptr;
if ((skb = dev_alloc_skb(1)) == NULL) { if ((skb = dev_alloc_skb(1)) == NULL) {
printk(KERN_ERR "%s: out of memory\n", __FUNCTION__); printk(KERN_ERR "%s: out of memory\n", __FUNCTION__);
return; return;
} }
ptr = skb_put(skb, 1); ptr = skb_put(skb, 1);
*ptr = event; *ptr = event;
skb->dev = dev; skb->dev = dev;
skb->protocol = htons(ETH_P_X25); skb->protocol = htons(ETH_P_X25);
skb->mac.raw = skb->data; skb->mac.raw = skb->data;
skb->pkt_type = PACKET_HOST; skb->pkt_type = PACKET_HOST;
netif_rx(skb); netif_rx(skb);
dev->last_rx = jiffies; /* timestamp */ dev->last_rx = jiffies; /* timestamp */
} }
/* Convert line speed in bps to a number used by cyclom 2x code. */ /* Convert line speed in bps to a number used by cyclom 2x code. */
static u8 bps_to_speed_code (u32 bps) static u8 bps_to_speed_code(u32 bps)
{ {
u8 number = 0; /* defaults to the lowest (1200) speed ;> */ u8 number = 0; /* defaults to the lowest (1200) speed ;> */
...@@ -1480,24 +1478,24 @@ static u8 bps_to_speed_code (u32 bps) ...@@ -1480,24 +1478,24 @@ static u8 bps_to_speed_code (u32 bps)
} }
/* log base 2 */ /* log base 2 */
static u8 log2 (u32 n) static u8 log2(u32 n)
{ {
u8 log = 0; u8 log = 0;
if (!n) if (!n)
return 0; return 0;
while (n > 1) { while (n > 1) {
n >>= 1; n >>= 1;
++log; ++log;
} }
return log; return log;
} }
/* Convert decimal string to unsigned integer. /* Convert decimal string to unsigned integer.
* If len != 0 then only 'len' characters of the string are converted. */ * If len != 0 then only 'len' characters of the string are converted. */
static unsigned dec_to_uint (u8 *str, int len) static unsigned dec_to_uint(u8 *str, int len)
{ {
unsigned val = 0; unsigned val = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment