diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c --- a/drivers/char/isicom.c +++ b/drivers/char/isicom.c @@ -91,6 +91,8 @@ * 06/01/05 Alan Cox Merged the ISI and base kernel strands * into a single 2.6 driver * + * 10/09/05 Jiri Slaby driver rewritten to 2.6 API + * * *********************************************************** * * To use this driver you also need the support package. You @@ -107,12 +109,12 @@ * Omit those entries for boards you don't have installed. * * TODO - * Hotplug * Merge testing * 64-bit verification */ #include +#include #include #include #include @@ -121,7 +123,6 @@ #include #include #include -#include #include #include #include @@ -135,6 +136,9 @@ #include +static int isicom_probe(struct pci_dev*, const struct pci_device_id*); +static void __devexit isicom_remove(struct pci_dev*); + static struct pci_device_id isicom_pci_tbl[] = { { VENDOR_ID, 0x2028, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, { VENDOR_ID, 0x2051, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, @@ -149,6 +153,13 @@ static struct pci_device_id isicom_pci_t }; MODULE_DEVICE_TABLE(pci, isicom_pci_tbl); +static struct pci_driver isicom_driver = { + .name = "isicom", + .id_table = isicom_pci_tbl, + .probe = isicom_probe, + .remove = __devexit_p(isicom_remove) +}; + static int prev_card = 3; /* start servicing isi_card[0] */ static struct tty_driver *isicom_normal; @@ -158,51 +169,47 @@ static char re_schedule = 1; static unsigned long tx_count = 0; #endif -static int ISILoad_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg); - static void isicom_tx(unsigned long _data); static void isicom_start(struct tty_struct * tty); -static unsigned char * tmp_buf; -static DECLARE_MUTEX(tmp_buf_sem); - /* baud index mappings from linux defns to isi */ -static signed char linuxb_to_isib[] = { +static s8 linuxb_to_isib[] = { -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 16, 17, 18, 19 }; struct isi_board { - unsigned short base; - unsigned char irq; - unsigned char port_count; - unsigned short status; - unsigned short port_status; /* each bit represents a single port */ - unsigned short shift_count; + u16 base; + u8 irq; + u8 port_count; + u16 status; + u16 port_status; /* each bit represents a ... */ + u16 shift_count; /* ... single port */ struct isi_port * ports; - signed char count; - unsigned char isa; + s8 count; + u8 isa; spinlock_t card_lock; /* Card wide lock 11/5/00 -sameer */ unsigned long flags; + struct device device; }; struct isi_port { - unsigned short magic; + u16 magic; unsigned int flags; int count; int blocked_open; int close_delay; - unsigned short channel; - unsigned short status; - unsigned short closing_wait; + u16 channel; + u16 status; + u16 closing_wait; struct isi_board * card; struct tty_struct * tty; wait_queue_head_t close_wait; wait_queue_head_t open_wait; struct work_struct hangup_tq; struct work_struct bh_tqueue; - unsigned char * xmit_buf; + u8 * xmit_buf; int xmit_head; int xmit_tail; int xmit_cnt; @@ -220,7 +227,7 @@ static struct isi_port isi_ports[PORT_C static int lock_card(struct isi_board *card) { char retries; - unsigned short base = card->base; + u16 base = card->base; for (retries = 0; retries < 100; retries++) { spin_lock_irqsave(&card->card_lock, card->flags); @@ -237,8 +244,8 @@ static int lock_card(struct isi_board *c static int lock_card_at_interrupt(struct isi_board *card) { - unsigned char retries; - unsigned short base = card->base; + u8 retries; + u16 base = card->base; for (retries = 0; retries < 200; retries++) { spin_lock_irqsave(&card->card_lock, card->flags); @@ -264,8 +271,8 @@ static void unlock_card(struct isi_board static void raise_dtr(struct isi_port * port) { struct isi_board * card = port->card; - unsigned short base = card->base; - unsigned char channel = port->channel; + u16 base = card->base; + u8 channel = port->channel; if (!lock_card(card)) return; @@ -280,8 +287,8 @@ static void raise_dtr(struct isi_port * static inline void drop_dtr(struct isi_port * port) { struct isi_board * card = port->card; - unsigned short base = card->base; - unsigned char channel = port->channel; + u16 base = card->base; + u8 channel = port->channel; if (!lock_card(card)) return; @@ -296,8 +303,8 @@ static inline void drop_dtr(struct isi_p static inline void raise_rts(struct isi_port * port) { struct isi_board * card = port->card; - unsigned short base = card->base; - unsigned char channel = port->channel; + u16 base = card->base; + u8 channel = port->channel; if (!lock_card(card)) return; @@ -311,8 +318,8 @@ static inline void raise_rts(struct isi_ static inline void drop_rts(struct isi_port * port) { struct isi_board * card = port->card; - unsigned short base = card->base; - unsigned char channel = port->channel; + u16 base = card->base; + u8 channel = port->channel; if (!lock_card(card)) return; @@ -327,8 +334,8 @@ static inline void drop_rts(struct isi_p static inline void raise_dtr_rts(struct isi_port * port) { struct isi_board * card = port->card; - unsigned short base = card->base; - unsigned char channel = port->channel; + u16 base = card->base; + u8 channel = port->channel; if (!lock_card(card)) return; @@ -343,8 +350,8 @@ static inline void raise_dtr_rts(struct static void drop_dtr_rts(struct isi_port * port) { struct isi_board * card = port->card; - unsigned short base = card->base; - unsigned char channel = port->channel; + u16 base = card->base; + u8 channel = port->channel; if (!lock_card(card)) return; @@ -359,8 +366,8 @@ static void drop_dtr_rts(struct isi_port static inline void kill_queue(struct isi_port * port, short queue) { struct isi_board * card = port->card; - unsigned short base = card->base; - unsigned char channel = port->channel; + u16 base = card->base; + u8 channel = port->channel; if (!lock_card(card)) return; @@ -371,257 +378,26 @@ static inline void kill_queue(struct isi unlock_card(card); } - -/* - * Firmware loader driver specific routines. This needs to mostly die - * and be replaced with request_firmware. - */ - -static struct file_operations ISILoad_fops = { - .owner = THIS_MODULE, - .ioctl = ISILoad_ioctl, -}; - -static struct miscdevice isiloader_device = { - ISILOAD_MISC_MINOR, "isictl", &ISILoad_fops -}; - - -static inline int WaitTillCardIsFree(unsigned short base) -{ - unsigned long count=0; - while( (!(inw(base+0xe) & 0x1)) && (count++ < 6000000)); - if (inw(base+0xe)&0x1) - return 0; - else - return 1; -} - -static int ISILoad_ioctl(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) -{ - unsigned int card, i, j, signature, status, portcount = 0; - unsigned long t; - unsigned short word_count, base; - bin_frame frame; - void __user *argp = (void __user *)arg; - /* exec_record exec_rec; */ - - if(get_user(card, (int __user *)argp)) - return -EFAULT; - - if(card < 0 || card >= BOARD_COUNT) - return -ENXIO; - - base=isi_card[card].base; - - if(base==0) - return -ENXIO; /* disabled or not used */ - - switch(cmd) { - case MIOCTL_RESET_CARD: - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - printk(KERN_DEBUG "ISILoad:Resetting Card%d at 0x%x ",card+1,base); - - inw(base+0x8); - - for(t=jiffies+HZ/100;time_before(jiffies, t);); - - outw(0,base+0x8); /* Reset */ - - for(j=1;j<=3;j++) { - for(t=jiffies+HZ;time_before(jiffies, t);); - printk("."); - } - signature=(inw(base+0x4)) & 0xff; - if (isi_card[card].isa) { - - if (!(inw(base+0xe) & 0x1) || (inw(base+0x2))) { -#ifdef ISICOM_DEBUG - printk("\nbase+0x2=0x%x , base+0xe=0x%x",inw(base+0x2),inw(base+0xe)); -#endif - printk("\nISILoad:ISA Card%d reset failure (Possible bad I/O Port Address 0x%x).\n",card+1,base); - return -EIO; - } - } - else { - portcount = inw(base+0x2); - if (!(inw(base+0xe) & 0x1) || ((portcount!=0) && (portcount!=4) && (portcount!=8))) { -#ifdef ISICOM_DEBUG - printk("\nbase+0x2=0x%x , base+0xe=0x%x",inw(base+0x2),inw(base+0xe)); -#endif - printk("\nISILoad:PCI Card%d reset failure (Possible bad I/O Port Address 0x%x).\n",card+1,base); - return -EIO; - } - } - switch(signature) { - case 0xa5: - case 0xbb: - case 0xdd: - if (isi_card[card].isa) - isi_card[card].port_count = 8; - else { - if (portcount == 4) - isi_card[card].port_count = 4; - else - isi_card[card].port_count = 8; - } - isi_card[card].shift_count = 12; - break; - - case 0xcc: isi_card[card].port_count = 16; - isi_card[card].shift_count = 11; - break; - - default: printk("ISILoad:Card%d reset failure (Possible bad I/O Port Address 0x%x).\n",card+1,base); -#ifdef ISICOM_DEBUG - printk("Sig=0x%x\n",signature); -#endif - return -EIO; - } - printk("-Done\n"); - return put_user(signature,(unsigned __user *)argp); - - case MIOCTL_LOAD_FIRMWARE: - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - - if(copy_from_user(&frame, argp, sizeof(bin_frame))) - return -EFAULT; - - if (WaitTillCardIsFree(base)) - return -EIO; - - outw(0xf0,base); /* start upload sequence */ - outw(0x00,base); - outw((frame.addr), base);/* lsb of adderess */ - - word_count=(frame.count >> 1) + frame.count % 2; - outw(word_count, base); - InterruptTheCard(base); - - for(i=0;i<=0x2f;i++); /* a wee bit of delay */ - - if (WaitTillCardIsFree(base)) - return -EIO; - - if ((status=inw(base+0x4))!=0) { - printk(KERN_WARNING "ISILoad:Card%d rejected load header:\nAddress:0x%x \nCount:0x%x \nStatus:0x%x \n", - card+1, frame.addr, frame.count, status); - return -EIO; - } - outsw(base, (void *) frame.bin_data, word_count); - - InterruptTheCard(base); - - for(i=0;i<=0x0f;i++); /* another wee bit of delay */ - - if (WaitTillCardIsFree(base)) - return -EIO; - - if ((status=inw(base+0x4))!=0) { - printk(KERN_ERR "ISILoad:Card%d got out of sync.Card Status:0x%x\n",card+1, status); - return -EIO; - } - return 0; - - case MIOCTL_READ_FIRMWARE: - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - - if(copy_from_user(&frame, argp, sizeof(bin_header))) - return -EFAULT; - - if (WaitTillCardIsFree(base)) - return -EIO; - - outw(0xf1,base); /* start download sequence */ - outw(0x00,base); - outw((frame.addr), base);/* lsb of adderess */ - - word_count=(frame.count >> 1) + frame.count % 2; - outw(word_count+1, base); - InterruptTheCard(base); - - for(i=0;i<=0xf;i++); /* a wee bit of delay */ - - if (WaitTillCardIsFree(base)) - return -EIO; - - if ((status=inw(base+0x4))!=0) { - printk(KERN_WARNING "ISILoad:Card%d rejected verify header:\nAddress:0x%x \nCount:0x%x \nStatus:0x%x \n", - card+1, frame.addr, frame.count, status); - return -EIO; - } - - inw(base); - insw(base, frame.bin_data, word_count); - InterruptTheCard(base); - - for(i=0;i<=0x0f;i++); /* another wee bit of delay */ - - if (WaitTillCardIsFree(base)) - return -EIO; - - if ((status=inw(base+0x4))!=0) { - printk(KERN_ERR "ISILoad:Card%d verify got out of sync.Card Status:0x%x\n",card+1, status); - return -EIO; - } - - if(copy_to_user(argp, &frame, sizeof(bin_frame))) - return -EFAULT; - return 0; - - case MIOCTL_XFER_CTRL: - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - if (WaitTillCardIsFree(base)) - return -EIO; - - outw(0xf2, base); - outw(0x800, base); - outw(0x0, base); - outw(0x0, base); - InterruptTheCard(base); - outw(0x0, base+0x4); /* for ISI4608 cards */ - - isi_card[card].status |= FIRMWARE_LOADED; - return 0; - - default: -#ifdef ISICOM_DEBUG - printk(KERN_DEBUG "ISILoad: Received Ioctl cmd 0x%x.\n", cmd); -#endif - return -ENOIOCTLCMD; - - } - -} - - /* * ISICOM Driver specific routines ... * */ - -static inline int isicom_paranoia_check(struct isi_port const * port, char *name, - const char * routine) + +static inline int isicom_paranoia_check(struct isi_port const * port, + char *name, const char * routine) { -#ifdef ISICOM_DEBUG - static const char * badmagic = - KERN_WARNING "ISICOM: Warning: bad isicom magic for dev %s in %s.\n"; - static const char * badport = - KERN_WARNING "ISICOM: Warning: NULL isicom port for dev %s in %s.\n"; +#ifdef ISICOM_DEBUG if (!port) { - printk(badport, name, routine); + printk(KERN_WARNING "ISICOM: Warning: bad isicom magic for " + "dev %s in %s.\n", name, routine); return 1; } if (port->magic != ISICOM_MAGIC) { - printk(badmagic, name, routine); + printk(KERN_WARNING "ISICOM: Warning: NULL isicom port for " + "dev %s in %s.\n", name, routine); return 1; } -#endif +#endif return 0; } @@ -731,12 +507,15 @@ static void isicom_tx(unsigned long _dat if (port->xmit_cnt <= WAKEUP_CHARS) schedule_work(&port->bh_tqueue); unlock_card(&isi_card[card]); - } + } - /* schedule another tx for hopefully in about 10ms */ -sched_again: - if (!re_schedule) + /* schedule another tx for hopefully in about 10ms */ +sched_again: + if (!re_schedule) + { + re_schedule = 2; return; + } init_timer(&tx); tx.expires = jiffies + HZ/100; tx.data = 0; @@ -771,8 +550,8 @@ static irqreturn_t isicom_interrupt(int struct isi_board * card; struct isi_port * port; struct tty_struct * tty; - unsigned short base, header, word_count, count; - unsigned char channel; + u16 base, header, word_count, count; + u8 channel; short byte_count; unsigned char *rp; @@ -956,9 +735,9 @@ static void isicom_config_port(struct is struct isi_board * card = port->card; struct tty_struct * tty; unsigned long baud; - unsigned short channel_setup, base = card->base; - unsigned short channel = port->channel, shift_count = card->shift_count; - unsigned char flow_ctrl; + u16 channel_setup, base = card->base; + u16 channel = port->channel, shift_count = card->shift_count; + u8 flow_ctrl; if (!(tty = port->tty) || !tty->termios) return; @@ -1097,7 +876,7 @@ static int isicom_setup_port(struct isi_ free_page(page); return -ERESTARTSYS; } - port->xmit_buf = (unsigned char *) page; + port->xmit_buf = (u8 *) page; } spin_lock_irqsave(&card->card_lock, flags); @@ -1374,7 +1153,7 @@ static void isicom_close(struct tty_stru /* write et all */ static int isicom_write(struct tty_struct * tty, - const unsigned char * buf, int count) + const u8 * buf, int count) { struct isi_port * port = (struct isi_port *) tty->driver_data; struct isi_board * card = port->card; @@ -1383,8 +1162,8 @@ static int isicom_write(struct tty_struc if (isicom_paranoia_check(port, tty->name, "isicom_write")) return 0; - - if (!tty || !port->xmit_buf || !tmp_buf) + + if (!tty || !port->xmit_buf) return 0; spin_lock_irqsave(&card->card_lock, flags); @@ -1409,7 +1188,7 @@ static int isicom_write(struct tty_struc } /* put_char et all */ -static void isicom_put_char(struct tty_struct * tty, unsigned char ch) +static void isicom_put_char(struct tty_struct * tty, u8 ch) { struct isi_port * port = (struct isi_port *) tty->driver_data; struct isi_board * card = port->card; @@ -1477,7 +1256,7 @@ static int isicom_chars_in_buffer(struct static inline void isicom_send_break(struct isi_port * port, unsigned long length) { struct isi_board * card = port->card; - unsigned short base = card->base; + u16 base = card->base; if(!lock_card(card)) return; @@ -1494,7 +1273,7 @@ static int isicom_tiocmget(struct tty_st { struct isi_port * port = (struct isi_port *) tty->driver_data; /* just send the port status */ - unsigned short status = port->status; + u16 status = port->status; if (isicom_paranoia_check(port, tty->name, "isicom_ioctl")) return -ENODEV; @@ -1750,54 +1529,54 @@ static void isicom_flush_buffer(struct t } -static int __devinit register_ioregion(void) +static int register_ioregion(struct isi_board* board, const int index) { - int count, done=0; - for (count=0; count < BOARD_COUNT; count++ ) { - if (isi_card[count].base) - if (!request_region(isi_card[count].base,16,ISICOM_NAME)) { - printk(KERN_DEBUG "ISICOM: I/O Region 0x%x-0x%x is busy. Card%d will be disabled.\n", - isi_card[count].base,isi_card[count].base+15,count+1); - isi_card[count].base=0; - done++; - } + if (!board->base) + return 0; + + if (!request_region(board->base, 16, ISICOM_NAME)) { + printk(KERN_DEBUG "ISICOM: I/O Region 0x%x-0x%x is busy. " + "Card%d will be disabled.\n", board->base, + board->base + 15, index + 1); + return -EBUSY; } - return done; + + return 0; } -static void unregister_ioregion(void) +static void unregister_ioregion(struct isi_board* board, const int index) { - int count; - for (count=0; count < BOARD_COUNT; count++ ) - if (isi_card[count].base) { - release_region(isi_card[count].base,16); -#ifdef ISICOM_DEBUG - printk(KERN_DEBUG "ISICOM: I/O Region 0x%x-0x%x released for Card%d.\n",isi_card[count].base,isi_card[count].base+15,count+1); -#endif - } + if (board->base) { + release_region(board->base, 16); + board->base = 0; +#ifdef ISICOM_DEBUG + printk(KERN_DEBUG "ISICOM: I/O Region 0x%x-0x%x released for " + "Card%d.\n", board->base, board->base + 15, index + 1); +#endif + } } static struct tty_operations isicom_ops = { - .open = isicom_open, - .close = isicom_close, - .write = isicom_write, - .put_char = isicom_put_char, - .flush_chars = isicom_flush_chars, - .write_room = isicom_write_room, + .open = isicom_open, + .close = isicom_close, + .write = isicom_write, + .put_char = isicom_put_char, + .flush_chars = isicom_flush_chars, + .write_room = isicom_write_room, .chars_in_buffer = isicom_chars_in_buffer, - .ioctl = isicom_ioctl, - .set_termios = isicom_set_termios, - .throttle = isicom_throttle, - .unthrottle = isicom_unthrottle, - .stop = isicom_stop, - .start = isicom_start, - .hangup = isicom_hangup, - .flush_buffer = isicom_flush_buffer, - .tiocmget = isicom_tiocmget, - .tiocmset = isicom_tiocmset, + .ioctl = isicom_ioctl, + .set_termios = isicom_set_termios, + .throttle = isicom_throttle, + .unthrottle = isicom_unthrottle, + .stop = isicom_stop, + .start = isicom_start, + .hangup = isicom_hangup, + .flush_buffer = isicom_flush_buffer, + .tiocmget = isicom_tiocmget, + .tiocmset = isicom_tiocmset, }; -static int __devinit register_drivers(void) +static int register_tty_driver(void) { int error; @@ -1806,146 +1585,321 @@ static int __devinit register_drivers(vo if (!isicom_normal) return -ENOMEM; - isicom_normal->owner = THIS_MODULE; - isicom_normal->name = "ttyM"; - isicom_normal->devfs_name = "isicom/"; - isicom_normal->major = ISICOM_NMAJOR; - isicom_normal->minor_start = 0; - isicom_normal->type = TTY_DRIVER_TYPE_SERIAL; - isicom_normal->subtype = SERIAL_TYPE_NORMAL; - isicom_normal->init_termios = tty_std_termios; - isicom_normal->init_termios.c_cflag = - B9600 | CS8 | CREAD | HUPCL |CLOCAL; - isicom_normal->flags = TTY_DRIVER_REAL_RAW; + isicom_normal->owner = THIS_MODULE; + isicom_normal->name = "ttyM"; + isicom_normal->devfs_name = "isicom/"; + isicom_normal->major = ISICOM_NMAJOR; + isicom_normal->minor_start = 0; + isicom_normal->type = TTY_DRIVER_TYPE_SERIAL; + isicom_normal->subtype = SERIAL_TYPE_NORMAL; + isicom_normal->init_termios = tty_std_termios; + isicom_normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | + CLOCAL; + isicom_normal->flags = TTY_DRIVER_REAL_RAW; tty_set_operations(isicom_normal, &isicom_ops); - - if ((error=tty_register_driver(isicom_normal))!=0) { - printk(KERN_DEBUG "ISICOM: Couldn't register the dialin driver, error=%d\n", - error); + + if ((error = tty_register_driver(isicom_normal))) { + printk(KERN_DEBUG "ISICOM: Couldn't register the dialin " + "driver, error=%d\n", error); put_tty_driver(isicom_normal); return error; } return 0; } -static void unregister_drivers(void) +static void unregister_tty_driver(void) { - int error = tty_unregister_driver(isicom_normal); + int error; + + error = tty_unregister_driver(isicom_normal); + if (error) - printk(KERN_DEBUG "ISICOM: couldn't unregister normal driver error=%d.\n",error); + printk(KERN_DEBUG "ISICOM: couldn't unregister normal driver " + "error=%d.\n", error); + put_tty_driver(isicom_normal); } -static int __devinit register_isr(void) +static int register_isr(struct isi_board* board, const int index) { - int count, done=0; - unsigned long irqflags; + unsigned long irqflags = SA_INTERRUPT; + int retval; + + if (!board->base) + return 0; - for (count=0; count < BOARD_COUNT; count++ ) { - if (isi_card[count].base) { - irqflags = (isi_card[count].isa == YES) ? - SA_INTERRUPT : - (SA_INTERRUPT | SA_SHIRQ); - - if (request_irq(isi_card[count].irq, - isicom_interrupt, - irqflags, - ISICOM_NAME, &isi_card[count])) { - - printk(KERN_WARNING "ISICOM: Could not" - " install handler at Irq %d." - " Card%d will be disabled.\n", - isi_card[count].irq, count+1); + if (board->isa == NO) + irqflags |= SA_SHIRQ; - release_region(isi_card[count].base,16); - isi_card[count].base=0; - } - else - done++; - } + retval = request_irq(board->irq, isicom_interrupt, irqflags, + ISICOM_NAME, board); + if (retval < 0) { + printk(KERN_WARNING "ISICOM: Could not install handler at Irq " + "%d. Card%d will be disabled.\n", board->irq, + index + 1); + return retval; } - return done; + + return 0; } -static void __exit unregister_isr(void) +static void unregister_isr(struct isi_board* board) { - int count; + if (board->base) + free_irq(board->irq, board); +} - for (count=0; count < BOARD_COUNT; count++ ) { - if (isi_card[count].base) - free_irq(isi_card[count].irq, &isi_card[count]); - } +static inline int WaitTillCardIsFree(u16 base) +{ + int count = 0; + + while ((!(inw(base+0xe) & 0x1)) && (count++ < 1000)) + msleep(1); + + return !(inw(base+0xe) & 0x1); } -static int __devinit isicom_init(void) +static int reset_card(struct isi_board* board, const int card, + unsigned int *signature) { - int card, channel, base; - struct isi_port * port; - unsigned long page; - - if (!tmp_buf) { - page = get_zeroed_page(GFP_KERNEL); - if (!page) { -#ifdef ISICOM_DEBUG - printk(KERN_DEBUG "ISICOM: Couldn't allocate page for tmp_buf.\n"); -#else - printk(KERN_ERR "ISICOM: Not enough memory...\n"); -#endif - return 0; - } - tmp_buf = (unsigned char *) page; + u16 base = board->base; + unsigned long t; + unsigned int j, portcount = 0; + + printk(KERN_DEBUG "ISILoad:Resetting Card%d at 0x%x ", card + 1, base); + + inw(base + 0x8); + + for(t = jiffies + HZ/100; time_before(jiffies, t); ) + ; + + outw(0, base + 0x8); /* Reset */ + + for(j = 1; j <= 3; j++) { + for(t = jiffies + HZ; time_before(jiffies, t); ) + ; + printk("."); } - - if (!register_ioregion()) - { - printk(KERN_ERR "ISICOM: All required I/O space found busy.\n"); - free_page((unsigned long)tmp_buf); - return 0; + + *signature = (inw(base+0x4)) & 0xff; + + if (board->isa == YES) { + if (!(inw(base + 0xe) & 0x1) || (inw(base + 0x2))) { +#ifdef ISICOM_DEBUG + printk("\nbase+0x2=0x%x , base+0xe=0x%x", + inw(base + 0x2), inw(base + 0xe)); +#endif + printk("\nISILoad:ISA Card%d reset failure (Possible " + "bad I/O Port Address 0x%x).\n", card + 1, + base); + return -EIO; + } } - if (register_drivers()) - { - unregister_ioregion(); - free_page((unsigned long)tmp_buf); - return 0; + else { + portcount = inw(base + 0x2); + if (!(inw(base + 0xe) & 0x1) || ((portcount != 0) && + (portcount != 4) && (portcount != 8))) { +#ifdef ISICOM_DEBUG + printk("\nbase+0x2=0x%x , base+0xe=0x%x", + inw(base + 0x2), inw(base + 0xe)); +#endif + printk("\nISILoad:PCI Card%d reset failure (Possible " + "bad I/O Port Address 0x%x).\n", card + 1, + base); + return -EIO; + } } - if (!register_isr()) - { - unregister_drivers(); - /* ioports already uregistered in register_isr */ - free_page((unsigned long)tmp_buf); - return 0; + + switch (*signature) { + case 0xa5: + case 0xbb: + case 0xdd: + board->port_count = (board->isa == NO && + portcount == 4) ? 4 : 8; + board->shift_count = 12; + break; + case 0xcc: + board->port_count = 16; + board->shift_count = 11; + break; + default: + printk(KERN_WARNING "ISILoad:Card%d reset failure " + "(Possible bad I/O Port Address 0x%x).\n", + card + 1, base); +#ifdef ISICOM_DEBUG + printk(KERN_DEBUG "Sig=0x%x\n", signature); +#endif + return -EIO; } - - memset(isi_ports, 0, sizeof(isi_ports)); - for (card = 0; card < BOARD_COUNT; card++) { - port = &isi_ports[card * 16]; - isi_card[card].ports = port; - spin_lock_init(&isi_card[card].card_lock); - base = isi_card[card].base; - for (channel = 0; channel < 16; channel++, port++) { - port->magic = ISICOM_MAGIC; - port->card = &isi_card[card]; - port->channel = channel; - port->close_delay = 50 * HZ/100; - port->closing_wait = 3000 * HZ/100; - INIT_WORK(&port->hangup_tq, do_isicom_hangup, port); - INIT_WORK(&port->bh_tqueue, isicom_bottomhalf, port); - port->status = 0; - init_waitqueue_head(&port->open_wait); - init_waitqueue_head(&port->close_wait); - /* . . . */ - } - } - - return 1; + printk("-Done\n"); + + return 0; +} + +static int load_firmware(struct isi_board* board, const int index, + const unsigned int signature) +{ + u16 base = board->base; + int i, retval; + char *name; + u16 word_count, status; + const struct firmware *fw; + struct stframe { + u16 addr; + u16 count; + u8 data[0]; + } *frame; + + switch (signature) { + case 0xa5: + name = "isi608.bin"; + break; + case 0xbb: + name = "isi608em.bin"; + break; + case 0xcc: + name = "isi616em.bin"; + break; + case 0xdd: + name = "isi4608.bin"; + break; + case 0xee: + name = "isi4616.bin"; + break; + default: + printk(KERN_ERR "Unknown signature.\n"); + return -EIO; + } + + retval = request_firmware(&fw, name, &board->device); + if (retval) + return retval; + + for (frame = (struct stframe*)fw->data; + frame < (struct stframe*)(fw->data + fw->size); + frame++) { + if (WaitTillCardIsFree(base)) + goto errrelfw; + + outw(0xf0, base); /* start upload sequence */ + outw(0x00, base); + outw(frame->addr, base); /* lsb of address */ + + word_count = frame->count / 2 + frame->count % 2; + outw(word_count, base); + InterruptTheCard(base); + + for(i = 0; i <= 0x2f; i++) /* a wee bit of delay */ + ; + + if (WaitTillCardIsFree(base)) + goto errrelfw; + + if ((status = inw(base + 0x4)) != 0) { + printk(KERN_WARNING "ISILoad:Card%d rejected load " + "header:\nAddress:0x%x \nCount:0x%x \n" + "Status:0x%x \n", index + 1, frame->addr, + frame->count, status); + goto errrelfw; + } + outsw(base, (void *) frame->data, word_count); + + InterruptTheCard(base); + + for(i = 0; i <= 0x0f; i++) /* another wee bit of delay */ + ; + + if (WaitTillCardIsFree(base)) + goto errrelfw; + + if ((status = inw(base + 0x4)) != 0) { + printk(KERN_ERR "ISILoad:Card%d got out of sync.Card " + "Status:0x%x\n", index + 1, status); + goto errrelfw; + } + } + + release_firmware(fw); + + if (WaitTillCardIsFree(base)) + return -EIO; + + outw(0xf2, base); + outw(0x800, base); + outw(0x0, base); + outw(0x0, base); + InterruptTheCard(base); + outw(0x0, base + 0x4); /* for ISI4608 cards */ + + board->status |= FIRMWARE_LOADED; + + return 0; + +errrelfw: + release_firmware(fw); + return -EIO; + +/* XXX: should I test it by reading it back and comparing with original like + * in load firmware package? */ +#if 0 + case MIOCTL_READ_FIRMWARE: + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if(copy_from_user(&frame, argp, sizeof(bin_header))) + return -EFAULT; + + if (WaitTillCardIsFree(base)) + return -EIO; + + outw(0xf1,base); /* start download sequence */ + outw(0x00,base); + outw((frame.addr), base);/* lsb of adderess */ + + word_count=(frame.count >> 1) + frame.count % 2; + outw(word_count+1, base); + InterruptTheCard(base); + + for(i=0;i<=0xf;i++); /* a wee bit of delay */ + + if (WaitTillCardIsFree(base)) + return -EIO; + + if ((status=inw(base+0x4))!=0) { + printk(KERN_WARNING "ISILoad:Card%d rejected verify header:\nAddress:0x%x \nCount:0x%x \nStatus:0x%x \n", + card+1, frame.addr, frame.count, status); + return -EIO; + } + + inw(base); + insw(base, frame.bin_data, word_count); + InterruptTheCard(base); + + for(i=0;i<=0x0f;i++); /* another wee bit of delay */ + + if (WaitTillCardIsFree(base)) + return -EIO; + + if ((status=inw(base+0x4))!=0) { + printk(KERN_ERR "ISILoad:Card%d verify got out of sync.Card Status:0x%x\n",card+1, status); + return -EIO; + } + + if(copy_to_user(argp, &frame, sizeof(bin_frame))) + return -EFAULT; + return 0; +#endif } + + /* * Insmod can set static symbols so keep these static */ static int io[4]; static int irq[4]; +static int card; MODULE_AUTHOR("MultiTech"); MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech"); @@ -1955,94 +1909,135 @@ MODULE_PARM_DESC(io, "I/O ports for the module_param_array(irq, int, NULL, 0); MODULE_PARM_DESC(irq, "Interrupts for the cards"); -static int __devinit isicom_setup(void) +static int isicom_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { - struct pci_dev *dev = NULL; - int retval, card, idx, count; - unsigned char pciirq; - unsigned int ioaddr; - - card = 0; - for(idx=0; idx < BOARD_COUNT; idx++) { - if (io[idx]) { - isi_card[idx].base=io[idx]; - isi_card[idx].irq=irq[idx]; - isi_card[idx].isa=YES; - card++; - } - else { - isi_card[idx].base = 0; - isi_card[idx].irq = 0; - } - } - - for (idx=0 ;idx < card; idx++) { - if (!((isi_card[idx].irq==2)||(isi_card[idx].irq==3)|| - (isi_card[idx].irq==4)||(isi_card[idx].irq==5)|| - (isi_card[idx].irq==7)||(isi_card[idx].irq==10)|| - (isi_card[idx].irq==11)||(isi_card[idx].irq==12)|| - (isi_card[idx].irq==15))) { - - if (isi_card[idx].base) { - printk(KERN_ERR "ISICOM: Irq %d unsupported. Disabling Card%d...\n", - isi_card[idx].irq, idx+1); - isi_card[idx].base=0; - card--; - } + unsigned int ioaddr, signature; + u8 pciirq; + int index, retval; + struct isi_board *board = NULL; + + if (card >= BOARD_COUNT) { + return -EPERM; + } + + ioaddr = pci_resource_start(pdev, 3); + /* i.e at offset 0x1c in the PCI configuration register space. */ + pciirq = pdev->irq; + printk(KERN_INFO "ISI PCI Card(Device ID 0x%x)\n", ent->device); + + /* allot the first empty slot in the array */ + for (index = 0; index < BOARD_COUNT; index++) + if (isi_card[index].base == 0) { + board = &isi_card[index]; + break; } - } + + board->base = ioaddr; + board->irq = pciirq; + board->isa = NO; + board->device = pdev->dev; + card++; + + retval = register_ioregion(board, index); + if (retval < 0) + goto err; + + retval = register_isr(board, index); + if (retval < 0) + goto errunrr; + + retval = reset_card(board, index, &signature); + if (retval < 0) + goto errunri; + + retval = load_firmware(board, index, signature); + if (retval < 0) + goto errunri; + + return 0; + +errunri: + unregister_isr(board); +errunrr: + unregister_ioregion(board, index); +err: + board->base = 0; + return retval; +} + +static void __devexit isicom_remove(struct pci_dev *pdev) +{ + int idx; + + for(idx = 0; idx < BOARD_COUNT; idx++) + if (isi_card[idx].base == pci_resource_start(pdev, 3)) + break; + + if (idx == BOARD_COUNT) + return; - if (card < BOARD_COUNT) { - for (idx=0; idx < DEVID_COUNT; idx++) { - dev = NULL; - for (;;){ - if (!(dev = pci_find_device(VENDOR_ID, isicom_pci_tbl[idx].device, dev))) - break; - if (card >= BOARD_COUNT) - break; - - if (pci_enable_device(dev)) - break; + unregister_isr(&isi_card[idx]); + unregister_ioregion(&isi_card[idx], idx); +} - /* found a PCI ISI card! */ - ioaddr = pci_resource_start (dev, 3); /* i.e at offset 0x1c in the - * PCI configuration register - * space. - */ - pciirq = dev->irq; - printk(KERN_INFO "ISI PCI Card(Device ID 0x%x)\n", isicom_pci_tbl[idx].device); - /* - * allot the first empty slot in the array - */ - for (count=0; count < BOARD_COUNT; count++) { - if (isi_card[count].base == 0) { - isi_card[count].base = ioaddr; - isi_card[count].irq = pciirq; - isi_card[count].isa = NO; - card++; - break; - } - } - } - if (card >= BOARD_COUNT) break; +static int __devinit isicom_setup(void) +{ + int retval, idx, channel; + struct isi_port *port; + + card = 0; + memset(isi_ports, 0, sizeof(isi_ports)); + + for(idx = 0; idx < BOARD_COUNT; idx++) { + port = &isi_ports[idx * 16]; + isi_card[idx].ports = port; + spin_lock_init(&isi_card[idx].card_lock); + for (channel = 0; channel < 16; channel++, port++) { + port->magic = ISICOM_MAGIC; + port->card = &isi_card[idx]; + port->channel = channel; + port->close_delay = 50 * HZ/100; + port->closing_wait = 3000 * HZ/100; + INIT_WORK(&port->hangup_tq, do_isicom_hangup, port); + INIT_WORK(&port->bh_tqueue, isicom_bottomhalf, port); + port->status = 0; + init_waitqueue_head(&port->open_wait); + init_waitqueue_head(&port->close_wait); + /* . . . */ } - } - - if (!(isi_card[0].base || isi_card[1].base || isi_card[2].base || isi_card[3].base)) { - printk(KERN_ERR "ISICOM: No valid card configuration. Driver cannot be initialized...\n"); - return -EIO; - } - retval = misc_register(&isiloader_device); - if (retval < 0) { - printk(KERN_ERR "ISICOM: Unable to register firmware loader driver.\n"); - return retval; - } - - if (!isicom_init()) { - if (misc_deregister(&isiloader_device)) - printk(KERN_ERR "ISICOM: Unable to unregister Firmware Loader driver\n"); - return -EIO; + isi_card[idx].base = 0; + isi_card[idx].irq = 0; + + if (!io[idx]) + continue; + + if (irq[idx] == 2 || irq[idx] == 3 || irq[idx] == 4 || + irq[idx] == 5 || irq[idx] == 7 || + irq[idx] == 10 || irq[idx] == 11 || + irq[idx] == 12 || irq[idx] == 15) { + printk(KERN_ERR "ISICOM: ISA not supported yet."); + return -EIO; +/* isi_card[idx].base = io[idx]; + isi_card[idx].irq = irq[idx]; + isi_card[idx].isa = YES; + FIXME: which device for request_firmware use? if you know, uncomment this and + delete printk and return + isi_card[idx].device = ???; + card++;*/ + } else + printk(KERN_ERR "ISICOM: Irq %d unsupported. " + "Disabling Card%d...\n", irq[idx], idx + 1); + } + + retval = register_tty_driver(); + if (retval < 0) + goto error; + + retval = pci_register_driver(&isicom_driver); + if (retval < 0) { + printk(KERN_ERR "ISICOM: Unable to register pci driver.\n"); + goto error; } init_timer(&tx); @@ -2053,20 +2048,27 @@ static int __devinit isicom_setup(void) add_timer(&tx); return 0; + +error: + return retval; } static void __exit isicom_exit(void) { + int index = 0; + re_schedule = 0; - /* FIXME */ - msleep(1000); - unregister_isr(); - unregister_drivers(); - unregister_ioregion(); - if(tmp_buf) - free_page((unsigned long)tmp_buf); - if (misc_deregister(&isiloader_device)) - printk(KERN_ERR "ISICOM: Unable to unregister Firmware Loader driver\n"); + + while (re_schedule != 2 && index++ < 100) + msleep(10); + + pci_unregister_driver(&isicom_driver); + unregister_tty_driver(); + + for (index = 0; index < BOARD_COUNT; index++) { + unregister_isr(&isi_card[index]); + unregister_ioregion(&isi_card[index], index); + } } module_init(isicom_setup); diff --git a/include/linux/isicom.h b/include/linux/isicom.h --- a/include/linux/isicom.h +++ b/include/linux/isicom.h @@ -5,46 +5,12 @@ /*#define ISICOM_DEBUG_DTR_RTS*/ -/* - * Firmware Loader definitions ... - */ - -#define __MultiTech ('M'<<8) -#define MIOCTL_LOAD_FIRMWARE (__MultiTech | 0x01) -#define MIOCTL_READ_FIRMWARE (__MultiTech | 0x02) -#define MIOCTL_XFER_CTRL (__MultiTech | 0x03) -#define MIOCTL_RESET_CARD (__MultiTech | 0x04) - -#define DATA_SIZE 16 - -typedef struct { - unsigned short exec_segment; - unsigned short exec_addr; -} exec_record; - -typedef struct { - int board; /* Board to load */ - unsigned short addr; - unsigned short count; -} bin_header; - -typedef struct { - int board; /* Board to load */ - unsigned short addr; - unsigned short count; - unsigned short segment; - unsigned char bin_data[DATA_SIZE]; -} bin_frame; - #ifdef __KERNEL__ #define YES 1 #define NO 0 -#define ISILOAD_MISC_MINOR 155 /* /dev/isctl */ -#define ISILOAD_NAME "ISILoad" - -/* +/* * ISICOM Driver definitions ... * */ @@ -66,9 +32,9 @@ typedef struct { #define ISICOM_CMAJOR 113 /* callout */ #define ISICOM_MAGIC (('M' << 8) | 'T') -#define WAKEUP_CHARS 256 /* hard coded for now */ -#define TX_SIZE 254 - +#define WAKEUP_CHARS 256 /* hard coded for now */ +#define TX_SIZE 254 + #define BOARD_COUNT 4 #define PORT_COUNT (BOARD_COUNT*16) @@ -98,18 +64,18 @@ typedef struct { #define ISICOM_INITIATE_XONXOFF 0x04 #define ISICOM_RESPOND_XONXOFF 0x08 -#define InterruptTheCard(base) (outw(0,(base)+0xc)) -#define ClearInterrupt(base) (inw((base)+0x0a)) +#define InterruptTheCard(base) (outw(0,(base)+0xc)) +#define ClearInterrupt(base) (inw((base)+0x0a)) #define BOARD(line) (((line) >> 4) & 0x3) /* isi kill queue bitmap */ - + #define ISICOM_KILLTX 0x01 #define ISICOM_KILLRX 0x02 /* isi_board status bitmap */ - + #define FIRMWARE_LOADED 0x0001 #define BOARD_ACTIVE 0x0002 @@ -123,8 +89,8 @@ typedef struct { #define ISI_RTS 0x0200 -#define ISI_TXOK 0x0001 - +#define ISI_TXOK 0x0001 + #endif /* __KERNEL__ */ #endif /* ISICOM_H */