2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
12 * This is shared code between Digi's CVS archive and the
13 * Linux Kernel sources.
14 * Changing the source just for reformatting needlessly breaks
15 * our CVS diff history.
17 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
20 * $Id: dgap_fep5.c,v 1.2 2011/06/21 10:35:40 markh Exp $
24 #include <linux/kernel.h>
25 #include <linux/version.h>
26 #include <linux/module.h>
27 #include <linux/pci.h>
28 #include <linux/delay.h> /* For udelay */
29 #include <asm/uaccess.h> /* For copy_from_user/copy_to_user */
30 #include <linux/tty.h>
31 #include <linux/tty_flip.h> /* For tty_schedule_flip */
32 #include <linux/slab.h>
34 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
35 #include <linux/sched.h>
38 #include "dgap_driver.h"
40 #include "dgap_fep5.h"
42 #include "dgap_conf.h"
43 #include "dgap_parse.h"
44 #include "dgap_trace.h"
47 * Our function prototypes
49 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
50 static int dgap_event(struct board_t *bd);
55 static uint dgap_count = 500;
59 * Loads the dgap.conf config file from the user.
61 void dgap_do_config_load(uchar __user *uaddr, int len)
65 uchar __user *from_addr = uaddr;
69 to_addr = dgap_config_buf = kzalloc(len + 1, GFP_ATOMIC);
70 if (!dgap_config_buf) {
71 DPR_INIT(("dgap_do_config_load - unable to allocate memory for file\n"));
72 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
82 if (copy_from_user((char *) &buf, from_addr, n) == -1 )
85 /* Copy data from buffer to kernel memory */
86 memcpy(to_addr, buf, n);
88 /* increment counts */
95 dgap_config_buf[orig_len] = '\0';
97 to_addr = dgap_config_buf;
98 dgap_parsefile(&to_addr, TRUE);
100 DPR_INIT(("dgap_config_load() finish\n"));
106 int dgap_after_config_loaded(void)
112 * Register our ttys, now that we have the config loaded.
114 for (i = 0; i < dgap_NumBoards; ++i) {
117 * Initialize KME waitqueues...
119 init_waitqueue_head(&(dgap_Board[i]->kme_wait));
122 * allocate flip buffer for board.
124 dgap_Board[i]->flipbuf = kzalloc(MYFLIPLEN, GFP_ATOMIC);
125 dgap_Board[i]->flipflagbuf = kzalloc(MYFLIPLEN, GFP_ATOMIC);
133 /*=======================================================================
135 * usertoboard - copy from user space to board space.
137 *=======================================================================*/
138 static int dgap_usertoboard(struct board_t *brd, char *to_addr, char __user *from_addr, int len)
143 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
150 if (copy_from_user((char *) &buf, from_addr, n) == -1 ) {
154 /* Copy data from buffer to card memory */
155 memcpy_toio(to_addr, buf, n);
157 /* increment counts */
168 * Copies the BIOS code from the user to the board,
169 * and starts the BIOS running.
171 void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
177 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
180 DPR_INIT(("dgap_do_bios_load() start\n"));
182 addr = brd->re_map_membase;
187 for (i = 0; i < 16; i++)
188 writeb(0, addr + POSTAREA + i);
194 if (dgap_usertoboard(brd, addr + offset, ubios, len) == -1 ) {
195 brd->state = BOARD_FAILED;
196 brd->dpastatus = BD_NOFEP;
200 writel(0x0bf00401, addr);
201 writel(0, (addr + 4));
203 /* Clear the reset, and change states. */
204 writeb(FEPCLR, brd->re_map_port);
205 brd->state = WAIT_BIOS_LOAD;
210 * Checks to see if the BIOS completed running on the card.
212 static void dgap_do_wait_for_bios(struct board_t *brd)
217 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
220 addr = brd->re_map_membase;
221 word = readw(addr + POSTAREA);
223 /* Check to see if BIOS thinks board is good. (GD). */
224 if (word == *(u16 *) "GD") {
225 DPR_INIT(("GOT GD in memory, moving states.\n"));
226 brd->state = FINISHED_BIOS_LOAD;
230 /* Give up on board after too long of time taken */
231 if (brd->wait_for_bios++ > 5000) {
232 u16 err1 = readw(addr + SEQUENCE);
233 u16 err2 = readw(addr + ERROR);
234 APR(("***WARNING*** %s failed diagnostics. Error #(%x,%x).\n",
235 brd->name, err1, err2));
236 brd->state = BOARD_FAILED;
237 brd->dpastatus = BD_NOFEP;
243 * Copies the FEP code from the user to the board,
244 * and starts the FEP running.
246 void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len)
251 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
254 addr = brd->re_map_membase;
256 DPR_INIT(("dgap_do_fep_load() for board %s : start\n", brd->name));
262 if (dgap_usertoboard(brd, addr + offset, ufep, len) == -1 ) {
263 brd->state = BOARD_FAILED;
264 brd->dpastatus = BD_NOFEP;
269 * If board is a concentrator product, we need to give
270 * it its config string describing how the concentrators look.
272 if ((brd->type == PCX) || (brd->type == PEPC)) {
274 uchar *config, *xconfig;
277 xconfig = dgap_create_config_string(brd, string);
279 /* Write string to board memory */
280 config = addr + CONFIG;
281 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
282 writeb(*xconfig, config);
283 if ((*xconfig & 0xff) == 0xff)
288 writel(0xbfc01004, (addr + 0xc34));
289 writel(0x3, (addr + 0xc30));
292 brd->state = WAIT_FEP_LOAD;
294 DPR_INIT(("dgap_do_fep_load() for board %s : finish\n", brd->name));
300 * Waits for the FEP to report thats its ready for us to use.
302 static void dgap_do_wait_for_fep(struct board_t *brd)
307 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
310 addr = brd->re_map_membase;
312 DPR_INIT(("dgap_do_wait_for_fep() for board %s : start. addr: %p\n", brd->name, addr));
314 word = readw(addr + FEPSTAT);
316 /* Check to see if FEP is up and running now. */
317 if (word == *(u16 *) "OS") {
318 DPR_INIT(("GOT OS in memory for board %s, moving states.\n", brd->name));
319 brd->state = FINISHED_FEP_LOAD;
322 * Check to see if the board can support FEP5+ commands.
324 word = readw(addr + FEP5_PLUS);
325 if (word == *(u16 *) "5A") {
326 DPR_INIT(("GOT 5A in memory for board %s, board supports extended FEP5 commands.\n", brd->name));
327 brd->bd_flags |= BD_FEP5PLUS;
333 /* Give up on board after too long of time taken */
334 if (brd->wait_for_fep++ > 5000) {
335 u16 err1 = readw(addr + SEQUENCE);
336 u16 err2 = readw(addr + ERROR);
337 APR(("***WARNING*** FEPOS for %s not functioning. Error #(%x,%x).\n",
338 brd->name, err1, err2));
339 brd->state = BOARD_FAILED;
340 brd->dpastatus = BD_NOFEP;
343 DPR_INIT(("dgap_do_wait_for_fep() for board %s : finish\n", brd->name));
348 * Physically forces the FEP5 card to reset itself.
350 static void dgap_do_reset_board(struct board_t *brd)
357 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase || !brd->re_map_port) {
358 DPR_INIT(("dgap_do_reset_board() start. bad values. brd: %p mem: %p io: %p\n",
359 brd, brd ? brd->re_map_membase : 0, brd ? brd->re_map_port : 0));
363 DPR_INIT(("dgap_do_reset_board() start. io: %p\n", brd->re_map_port));
365 /* FEPRST does not vary among supported boards */
366 writeb(FEPRST, brd->re_map_port);
368 for (i = 0; i <= 1000; i++) {
369 check = readb(brd->re_map_port) & 0xe;
376 APR(("*** WARNING *** Board not resetting... Failing board.\n"));
377 brd->state = BOARD_FAILED;
378 brd->dpastatus = BD_NOFEP;
383 * Make sure there really is memory out there.
385 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
386 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
387 check1 = readl(brd->re_map_membase + LOWMEM);
388 check2 = readl(brd->re_map_membase + HIGHMEM);
390 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
391 APR(("*** Warning *** No memory at %p for board.\n", brd->re_map_membase));
392 brd->state = BOARD_FAILED;
393 brd->dpastatus = BD_NOFEP;
397 if (brd->state != BOARD_FAILED)
398 brd->state = FINISHED_RESET;
401 DPR_INIT(("dgap_do_reset_board() finish\n"));
406 * Sends a concentrator image into the FEP5 board.
408 void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
412 struct downld_t *to_dp;
414 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
417 vaddr = brd->re_map_membase;
419 offset = readw((u16 *) (vaddr + DOWNREQ));
420 to_dp = (struct downld_t *) (vaddr + (int) offset);
423 * The image was already read into kernel space,
424 * we do NOT need a user space read here
426 memcpy_toio((char *) to_dp, uaddr, sizeof(struct downld_t));
428 /* Tell card we have data for it */
429 writew(0, vaddr + (DOWNREQ));
431 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
435 #define EXPANSION_ROM_SIZE (64 * 1024)
436 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
438 static void dgap_get_vpd(struct board_t *brd)
450 * Poke the magic number at the PCI Rom Address location.
451 * If VPD is supported, the value read from that address
454 magic = FEP5_ROM_MAGIC;
455 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
456 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
458 /* VPD not supported, bail */
463 * To get to the OTPROM memory, we have to send the boards base
464 * address or'ed with 1 into the PCI Rom Address location.
466 magic = brd->membase | 0x01;
467 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
468 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
470 byte1 = readb(brd->re_map_membase);
471 byte2 = readb(brd->re_map_membase + 1);
474 * If the board correctly swapped to the OTPROM memory,
475 * the first 2 bytes (header) should be 0x55, 0xAA
477 if (byte1 == 0x55 && byte2 == 0xAA) {
482 * We have to run through all the OTPROM memory looking
483 * for the VPD offset.
485 while (base_offset <= EXPANSION_ROM_SIZE) {
488 * Lots of magic numbers here.
490 * The VPD offset is located inside the ROM Data Structure.
491 * We also have to remember the length of each
492 * ROM Data Structure, so we can "hop" to the next
493 * entry if the VPD isn't in the current
494 * ROM Data Structure.
496 rom_offset = readw(brd->re_map_membase + base_offset + 0x18);
497 image_length = readw(brd->re_map_membase + rom_offset + 0x10) * 512;
498 vpd_offset = readw(brd->re_map_membase + rom_offset + 0x08);
500 /* Found the VPD entry */
504 /* We didn't find a VPD entry, go to next ROM entry. */
505 base_offset += image_length;
507 byte1 = readb(brd->re_map_membase + base_offset);
508 byte2 = readb(brd->re_map_membase + base_offset + 1);
511 * If the new ROM offset doesn't have 0x55, 0xAA
512 * as its header, we have run out of ROM.
514 if (byte1 != 0x55 || byte2 != 0xAA)
519 * If we have a VPD offset, then mark the board
520 * as having a valid VPD, and copy VPDSIZE (512) bytes of
521 * that VPD to the buffer we have in our board structure.
524 brd->bd_flags |= BD_HAS_VPD;
525 for (i = 0; i < VPDSIZE; i++)
526 brd->vpd[i] = readb(brd->re_map_membase + vpd_offset + i);
531 * We MUST poke the magic number at the PCI Rom Address location again.
532 * This makes the card report the regular board memory back to us,
533 * rather than the OTPROM memory.
535 magic = FEP5_ROM_MAGIC;
536 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
541 * Our board poller function.
543 void dgap_poll_tasklet(unsigned long data)
545 struct board_t *bd = (struct board_t *) data;
553 if (!bd || (bd->magic != DGAP_BOARD_MAGIC)) {
554 APR(("dgap_poll_tasklet() - NULL or bad bd.\n"));
558 if (bd->inhibit_poller)
561 DGAP_LOCK(bd->bd_lock, lock_flags);
563 vaddr = bd->re_map_membase;
566 * If board is ready, parse deeper to see if there is anything to do.
568 if (bd->state == BOARD_READY) {
570 struct ev_t *eaddr = NULL;
572 if (!bd->re_map_membase) {
573 DGAP_UNLOCK(bd->bd_lock, lock_flags);
576 if (!bd->re_map_port) {
577 DGAP_UNLOCK(bd->bd_lock, lock_flags);
586 * If this is a CX or EPCX, we need to see if the firmware
587 * is requesting a concentrator image from us.
589 if ((bd->type == PCX) || (bd->type == PEPC)) {
590 chk_addr = (u16 *) (vaddr + DOWNREQ);
591 check = readw(chk_addr);
592 /* Nonzero if FEP is requesting concentrator image. */
594 if (bd->conc_dl_status == NO_PENDING_CONCENTRATOR_REQUESTS)
595 bd->conc_dl_status = NEED_CONCENTRATOR;
597 * Signal downloader, its got some work to do.
599 DGAP_LOCK(dgap_dl_lock, lock_flags2);
600 if (dgap_dl_action != 1) {
602 wake_up_interruptible(&dgap_dl_wait);
604 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
609 eaddr = (struct ev_t *) (vaddr + EVBUF);
611 /* Get our head and tail */
612 head = readw(&(eaddr->ev_head));
613 tail = readw(&(eaddr->ev_tail));
616 * If there is an event pending. Go service it.
619 DGAP_UNLOCK(bd->bd_lock, lock_flags);
621 DGAP_LOCK(bd->bd_lock, lock_flags);
626 * If board is doing interrupts, ACK the interrupt.
628 if (bd && bd->intr_running) {
629 readb(bd->re_map_port + 2);
632 DGAP_UNLOCK(bd->bd_lock, lock_flags);
636 /* Our state machine to get the board up and running */
639 if (bd->state == NEED_RESET) {
644 dgap_do_reset_board(bd);
647 /* Move to next state */
648 if (bd->state == FINISHED_RESET) {
649 bd->state = NEED_CONFIG;
652 if (bd->state == NEED_CONFIG) {
654 * Match this board to a config the user created for us.
656 bd->bd_config = dgap_find_config(bd->type, bd->pci_bus, bd->pci_slot);
659 * Because the 4 port Xr products share the same PCI ID
660 * as the 8 port Xr products, if we receive a NULL config
661 * back, and this is a PAPORT8 board, retry with a
662 * PAPORT4 attempt as well.
664 if (bd->type == PAPORT8 && !bd->bd_config) {
665 bd->bd_config = dgap_find_config(PAPORT4, bd->pci_bus, bd->pci_slot);
669 * Register the ttys (if any) into the kernel.
672 bd->state = FINISHED_CONFIG;
675 bd->state = CONFIG_NOT_FOUND;
679 /* Move to next state */
680 if (bd->state == FINISHED_CONFIG) {
681 bd->state = NEED_DEVICE_CREATION;
684 /* Move to next state */
685 if (bd->state == NEED_DEVICE_CREATION) {
687 * Signal downloader, its got some work to do.
689 DGAP_LOCK(dgap_dl_lock, lock_flags2);
690 if (dgap_dl_action != 1) {
692 wake_up_interruptible(&dgap_dl_wait);
694 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
697 /* Move to next state */
698 if (bd->state == FINISHED_DEVICE_CREATION) {
699 bd->state = NEED_BIOS_LOAD;
702 /* Move to next state */
703 if (bd->state == NEED_BIOS_LOAD) {
705 * Signal downloader, its got some work to do.
707 DGAP_LOCK(dgap_dl_lock, lock_flags2);
708 if (dgap_dl_action != 1) {
710 wake_up_interruptible(&dgap_dl_wait);
712 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
715 /* Wait for BIOS to test board... */
716 if (bd->state == WAIT_BIOS_LOAD) {
717 dgap_do_wait_for_bios(bd);
720 /* Move to next state */
721 if (bd->state == FINISHED_BIOS_LOAD) {
722 bd->state = NEED_FEP_LOAD;
725 * Signal downloader, its got some work to do.
727 DGAP_LOCK(dgap_dl_lock, lock_flags2);
728 if (dgap_dl_action != 1) {
730 wake_up_interruptible(&dgap_dl_wait);
732 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
735 /* Wait for FEP to load on board... */
736 if (bd->state == WAIT_FEP_LOAD) {
737 dgap_do_wait_for_fep(bd);
741 /* Move to next state */
742 if (bd->state == FINISHED_FEP_LOAD) {
745 * Do tty device initialization.
747 int rc = dgap_tty_init(bd);
751 APR(("Can't init tty devices (%d)\n", rc));
752 bd->state = BOARD_FAILED;
753 bd->dpastatus = BD_NOFEP;
756 bd->state = NEED_PROC_CREATION;
759 * Signal downloader, its got some work to do.
761 DGAP_LOCK(dgap_dl_lock, lock_flags2);
762 if (dgap_dl_action != 1) {
764 wake_up_interruptible(&dgap_dl_wait);
766 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
770 /* Move to next state */
771 if (bd->state == FINISHED_PROC_CREATION) {
773 bd->state = BOARD_READY;
774 bd->dpastatus = BD_RUNNING;
777 * If user requested the board to run in interrupt mode,
778 * go and set it up on the board.
781 writew(1, (bd->re_map_membase + ENABLE_INTR));
783 * Tell the board to poll the UARTS as fast as possible.
785 writew(FEPPOLL_MIN, (bd->re_map_membase + FEPPOLL));
786 bd->intr_running = 1;
789 /* Wake up anyone waiting for board state to change to ready */
790 wake_up_interruptible(&bd->state_wait);
793 DGAP_UNLOCK(bd->bd_lock, lock_flags);
797 /*=======================================================================
799 * dgap_cmdb - Sends a 2 byte command to the FEP.
801 * ch - Pointer to channel structure.
802 * cmd - Command to be sent.
803 * byte1 - Integer containing first byte to be sent.
804 * byte2 - Integer containing second byte to be sent.
805 * ncmds - Wait until ncmds or fewer cmds are left
806 * in the cmd buffer before returning.
808 *=======================================================================*/
809 void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1, uchar byte2, uint ncmds)
812 struct cm_t *cm_addr = NULL;
818 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
822 * Check if board is still alive.
824 if (ch->ch_bd->state == BOARD_FAILED) {
825 DPR_CORE(("%s:%d board is in failed state.\n", __FILE__, __LINE__));
830 * Make sure the pointers are in range before
831 * writing to the FEP memory.
833 vaddr = ch->ch_bd->re_map_membase;
838 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
839 head = readw(&(cm_addr->cm_head));
842 * Forget it if pointers out of range.
844 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
845 DPR_CORE(("%s:%d pointers out of range, failing board!\n", __FILE__, __LINE__));
846 ch->ch_bd->state = BOARD_FAILED;
851 * Put the data in the circular command buffer.
853 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
854 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
855 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
856 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
858 head = (head + 4) & (CMDMAX - CMDSTART - 4);
860 writew(head, &(cm_addr->cm_head));
863 * Wait if necessary before updating the head
864 * pointer to limit the number of outstanding
865 * commands to the FEP. If the time spent waiting
866 * is outlandish, declare the FEP dead.
868 for (count = dgap_count ;;) {
870 head = readw(&(cm_addr->cm_head));
871 tail = readw(&(cm_addr->cm_tail));
873 n = (head - tail) & (CMDMAX - CMDSTART - 4);
875 if (n <= ncmds * sizeof(struct cm_t))
879 DPR_CORE(("%s:%d failing board.\n",__FILE__, __LINE__));
880 ch->ch_bd->state = BOARD_FAILED;
888 /*=======================================================================
890 * dgap_cmdw - Sends a 1 word command to the FEP.
892 * ch - Pointer to channel structure.
893 * cmd - Command to be sent.
894 * word - Integer containing word to be sent.
895 * ncmds - Wait until ncmds or fewer cmds are left
896 * in the cmd buffer before returning.
898 *=======================================================================*/
899 void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
902 struct cm_t *cm_addr = NULL;
908 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
912 * Check if board is still alive.
914 if (ch->ch_bd->state == BOARD_FAILED) {
915 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
920 * Make sure the pointers are in range before
921 * writing to the FEP memory.
923 vaddr = ch->ch_bd->re_map_membase;
927 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
928 head = readw(&(cm_addr->cm_head));
931 * Forget it if pointers out of range.
933 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
934 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
935 ch->ch_bd->state = BOARD_FAILED;
940 * Put the data in the circular command buffer.
942 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
943 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
944 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
946 head = (head + 4) & (CMDMAX - CMDSTART - 4);
948 writew(head, &(cm_addr->cm_head));
951 * Wait if necessary before updating the head
952 * pointer to limit the number of outstanding
953 * commands to the FEP. If the time spent waiting
954 * is outlandish, declare the FEP dead.
956 for (count = dgap_count ;;) {
958 head = readw(&(cm_addr->cm_head));
959 tail = readw(&(cm_addr->cm_tail));
961 n = (head - tail) & (CMDMAX - CMDSTART - 4);
963 if (n <= ncmds * sizeof(struct cm_t))
967 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
968 ch->ch_bd->state = BOARD_FAILED;
977 /*=======================================================================
979 * dgap_cmdw_ext - Sends a extended word command to the FEP.
981 * ch - Pointer to channel structure.
982 * cmd - Command to be sent.
983 * word - Integer containing word to be sent.
984 * ncmds - Wait until ncmds or fewer cmds are left
985 * in the cmd buffer before returning.
987 *=======================================================================*/
988 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
991 struct cm_t *cm_addr = NULL;
997 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1001 * Check if board is still alive.
1003 if (ch->ch_bd->state == BOARD_FAILED) {
1004 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
1009 * Make sure the pointers are in range before
1010 * writing to the FEP memory.
1012 vaddr = ch->ch_bd->re_map_membase;
1016 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
1017 head = readw(&(cm_addr->cm_head));
1020 * Forget it if pointers out of range.
1022 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
1023 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
1024 ch->ch_bd->state = BOARD_FAILED;
1029 * Put the data in the circular command buffer.
1032 /* Write an FF to tell the FEP that we want an extended command */
1033 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
1035 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
1036 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
1039 * If the second part of the command won't fit,
1040 * put it at the beginning of the circular buffer.
1042 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03))) {
1043 writew((u16) word, (char *) (vaddr + CMDSTART));
1045 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
1048 head = (head + 8) & (CMDMAX - CMDSTART - 4);
1050 writew(head, &(cm_addr->cm_head));
1053 * Wait if necessary before updating the head
1054 * pointer to limit the number of outstanding
1055 * commands to the FEP. If the time spent waiting
1056 * is outlandish, declare the FEP dead.
1058 for (count = dgap_count ;;) {
1060 head = readw(&(cm_addr->cm_head));
1061 tail = readw(&(cm_addr->cm_tail));
1063 n = (head - tail) & (CMDMAX - CMDSTART - 4);
1065 if (n <= ncmds * sizeof(struct cm_t))
1069 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
1070 ch->ch_bd->state = BOARD_FAILED;
1078 /*=======================================================================
1080 * dgap_wmove - Write data to FEP buffer.
1082 * ch - Pointer to channel structure.
1083 * buf - Poiter to characters to be moved.
1084 * cnt - Number of characters to move.
1086 *=======================================================================*/
1087 void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
1094 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1101 head = readw(&(bs->tx_head));
1104 * If pointers are out of range, just return.
1106 if ((cnt > ch->ch_tsize) || (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize) {
1107 DPR_CORE(("%s:%d pointer out of range", __FILE__, __LINE__));
1112 * If the write wraps over the top of the circular buffer,
1113 * move the portion up to the wrap point, and reset the
1114 * pointers to the bottom.
1116 n = ch->ch_tstart + ch->ch_tsize - head;
1120 taddr = ch->ch_taddr + head;
1121 memcpy_toio(taddr, buf, n);
1122 head = ch->ch_tstart;
1127 * Move rest of data.
1129 taddr = ch->ch_taddr + head;
1131 memcpy_toio(taddr, buf, n);
1134 writew(head, &(bs->tx_head));
1138 * Retrives the current custom baud rate from FEP memory,
1139 * and returns it back to the user.
1140 * Returns 0 on error.
1142 uint dgap_get_custom_baud(struct channel_t *ch)
1148 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
1152 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC) {
1156 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
1159 vaddr = ch->ch_bd->re_map_membase;
1165 * Go get from fep mem, what the fep
1166 * believes the custom baud rate is.
1168 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
1169 (ch->ch_portnum * 0x28) + LINE_SPEED));
1171 value = readw(vaddr + offset);
1177 * Calls the firmware to reset this channel.
1179 void dgap_firmware_reset_port(struct channel_t *ch)
1181 dgap_cmdb(ch, CHRESET, 0, 0, 0);
1184 * Now that the channel is reset, we need to make sure
1185 * all the current settings get reapplied to the port
1188 * So we will set the driver's cache of firmware
1189 * settings all to 0, and then call param.
1191 ch->ch_fepiflag = 0;
1192 ch->ch_fepcflag = 0;
1193 ch->ch_fepoflag = 0;
1194 ch->ch_fepstartc = 0;
1195 ch->ch_fepstopc = 0;
1196 ch->ch_fepastartc = 0;
1197 ch->ch_fepastopc = 0;
1203 /*=======================================================================
1205 * dgap_param - Set Digi parameters.
1207 * struct tty_struct * - TTY for port.
1209 *=======================================================================*/
1210 int dgap_param(struct tty_struct *tty)
1212 struct ktermios *ts;
1214 struct channel_t *ch;
1223 if (!tty || tty->magic != TTY_MAGIC)
1226 un = (struct un_t *) tty->driver_data;
1227 if (!un || un->magic != DGAP_UNIT_MAGIC)
1231 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1235 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1242 DPR_PARAM(("param start: tdev: %x cflags: %x oflags: %x iflags: %x\n",
1243 ch->ch_tun.un_dev, ch->ch_c_cflag, ch->ch_c_oflag, ch->ch_c_iflag));
1248 * If baud rate is zero, flush queues, and set mval to drop DTR.
1250 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
1253 head = readw(&(ch->ch_bs->rx_head));
1254 writew(head, &(ch->ch_bs->rx_tail));
1257 head = readw(&(ch->ch_bs->tx_head));
1258 writew(head, &(ch->ch_bs->tx_tail));
1260 ch->ch_flags |= (CH_BAUD0);
1262 /* Drop RTS and DTR */
1263 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
1264 mval = D_DTR(ch) | D_RTS(ch);
1265 ch->ch_baud_info = 0;
1267 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
1269 * Tell the fep to do the command
1272 DPR_PARAM(("param: Want %d speed\n", ch->ch_custom_speed));
1274 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
1277 * Now go get from fep mem, what the fep
1278 * believes the custom baud rate is.
1280 ch->ch_baud_info = ch->ch_custom_speed = dgap_get_custom_baud(ch);
1282 DPR_PARAM(("param: Got %d speed\n", ch->ch_custom_speed));
1284 /* Handle transition from B0 */
1285 if (ch->ch_flags & CH_BAUD0) {
1286 ch->ch_flags &= ~(CH_BAUD0);
1287 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
1289 mval = D_DTR(ch) | D_RTS(ch);
1293 * Set baud rate, character size, and parity.
1301 ulong bauds[4][16] = {
1305 600, 1200, 1800, 2400,
1306 4800, 9600, 19200, 38400 },
1307 { /* slowbaud & CBAUDEX */
1308 0, 57600, 115200, 230400,
1309 460800, 150, 200, 921600,
1310 600, 1200, 1800, 2400,
1311 4800, 9600, 19200, 38400 },
1313 0, 57600, 76800, 115200,
1314 14400, 57600, 230400, 76800,
1315 115200, 230400, 28800, 460800,
1316 921600, 9600, 19200, 38400 },
1317 { /* fastbaud & CBAUDEX */
1318 0, 57600, 115200, 230400,
1319 460800, 150, 200, 921600,
1320 600, 1200, 1800, 2400,
1321 4800, 9600, 19200, 38400 }
1324 /* Only use the TXPrint baud rate if the terminal unit is NOT open */
1325 if (!(ch->ch_tun.un_flags & UN_ISOPEN) && (un->un_type == DGAP_PRINT))
1326 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
1328 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
1330 if (ch->ch_c_cflag & CBAUDEX)
1333 if (ch->ch_digi.digi_flags & DIGI_FAST)
1338 if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) && (jindex < 16)) {
1339 baud = bauds[iindex][jindex];
1341 DPR_IOCTL(("baud indices were out of range (%d)(%d)",
1349 ch->ch_baud_info = baud;
1353 * CBAUD has bit position 0x1000 set these days to indicate Linux
1355 * We use a different bit assignment for high speed. Clear this
1356 * bit out while grabbing the parts of "cflag" we want.
1358 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
1361 * HUPCL bit is used by FEP to indicate fast baud
1362 * table is to be used.
1364 if ((ch->ch_digi.digi_flags & DIGI_FAST) || (ch->ch_c_cflag & CBAUDEX))
1368 if ((ch->ch_c_cflag & CBAUDEX) && !(ch->ch_digi.digi_flags & DIGI_FAST)) {
1370 * The below code is trying to guarantee that only baud rates
1371 * 115200, 230400, 460800, 921600 are remapped. We use exclusive or
1372 * because the various baud rates share common bit positions
1373 * and therefore can't be tested for easily.
1375 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
1378 /* Map high speed requests to index into FEP's baud table */
1407 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
1412 if (cflag != ch->ch_fepcflag) {
1413 ch->ch_fepcflag = (u16) (cflag & 0xffff);
1415 /* Okay to have channel and board locks held calling this */
1416 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
1419 /* Handle transition from B0 */
1420 if (ch->ch_flags & CH_BAUD0) {
1421 ch->ch_flags &= ~(CH_BAUD0);
1422 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
1424 mval = D_DTR(ch) | D_RTS(ch);
1430 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | IXON | IXANY | IXOFF);
1432 if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE)) {
1433 iflag &= ~(IXON | IXOFF);
1434 ch->ch_c_iflag &= ~(IXON | IXOFF);
1438 * Only the IBM Xr card can switch between
1439 * 232 and 422 modes on the fly
1441 if (bd->device == PCI_DEVICE_XR_IBM_DID) {
1442 if (ch->ch_digi.digi_flags & DIGI_422)
1443 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
1445 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
1448 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
1451 if (iflag != ch->ch_fepiflag) {
1452 ch->ch_fepiflag = iflag;
1454 /* Okay to have channel and board locks held calling this */
1455 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
1459 * Select hardware handshaking.
1463 if (ch->ch_c_cflag & CRTSCTS) {
1464 hflow |= (D_RTS(ch) | D_CTS(ch));
1466 if (ch->ch_digi.digi_flags & RTSPACE)
1468 if (ch->ch_digi.digi_flags & DTRPACE)
1470 if (ch->ch_digi.digi_flags & CTSPACE)
1472 if (ch->ch_digi.digi_flags & DSRPACE)
1474 if (ch->ch_digi.digi_flags & DCDPACE)
1477 if (hflow != ch->ch_hflow) {
1478 ch->ch_hflow = hflow;
1480 /* Okay to have channel and board locks held calling this */
1481 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
1486 * Set RTS and/or DTR Toggle if needed, but only if product is FEP5+ based.
1488 if (bd->bd_flags & BD_FEP5PLUS) {
1490 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
1491 hflow2 |= (D_RTS(ch));
1493 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
1494 hflow2 |= (D_DTR(ch));
1497 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
1501 * Set modem control lines.
1504 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
1506 DPR_PARAM(("dgap_param: mval: %x ch_mforce: %x ch_mval: %x ch_mostat: %x\n",
1507 mval, ch->ch_mforce, ch->ch_mval, ch->ch_mostat));
1509 if (ch->ch_mostat ^ mval) {
1510 ch->ch_mostat = mval;
1512 /* Okay to have channel and board locks held calling this */
1513 DPR_PARAM(("dgap_param: Sending SMODEM mval: %x\n", mval));
1514 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
1518 * Read modem signals, and then call carrier function.
1520 ch->ch_mistat = readb(&(bs->m_stat));
1524 * Set the start and stop characters.
1526 if (ch->ch_startc != ch->ch_fepstartc || ch->ch_stopc != ch->ch_fepstopc) {
1527 ch->ch_fepstartc = ch->ch_startc;
1528 ch->ch_fepstopc = ch->ch_stopc;
1530 /* Okay to have channel and board locks held calling this */
1531 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
1535 * Set the Auxiliary start and stop characters.
1537 if (ch->ch_astartc != ch->ch_fepastartc || ch->ch_astopc != ch->ch_fepastopc) {
1538 ch->ch_fepastartc = ch->ch_astartc;
1539 ch->ch_fepastopc = ch->ch_astopc;
1541 /* Okay to have channel and board locks held calling this */
1542 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
1545 DPR_PARAM(("param finish\n"));
1552 * dgap_parity_scan()
1554 * Convert the FEP5 way of reporting parity errors and breaks into
1555 * the Linux line discipline way.
1557 void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, unsigned char *fbuf, int *len)
1561 unsigned char *in, *cout, *fout;
1568 DPR_PSCAN(("dgap_parity_scan start\n"));
1570 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1575 switch (ch->pscan_state) {
1577 /* reset to sanity and fall through */
1578 ch->pscan_state = 0;
1581 /* No FF seen yet */
1582 if (c == (unsigned char) '\377') {
1583 /* delete this character from stream */
1584 ch->pscan_state = 1;
1587 *fout++ = TTY_NORMAL;
1594 if (c == (unsigned char) '\377') {
1595 /* doubled ff, transform to single ff */
1597 *fout++ = TTY_NORMAL;
1599 ch->pscan_state = 0;
1601 /* save value examination in next state */
1602 ch->pscan_savechar = c;
1603 ch->pscan_state = 2;
1608 /* third character of ff sequence */
1612 if (ch->pscan_savechar == 0x0) {
1615 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting break.\n", c));
1617 *fout++ = TTY_BREAK;
1620 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting parity.\n", c));
1621 ch->ch_err_parity++;
1622 *fout++ = TTY_PARITY;
1626 DPR_PSCAN(("%s:%d Logic Error.\n", __FILE__, __LINE__));
1630 ch->pscan_state = 0;
1634 DPR_PSCAN(("dgap_parity_scan finish\n"));
1640 /*=======================================================================
1642 * dgap_event - FEP to host event processing routine.
1644 * bd - Board of current event.
1646 *=======================================================================*/
1647 static int dgap_event(struct board_t *bd)
1649 struct channel_t *ch;
1654 uchar *vaddr = NULL;
1655 struct ev_t *eaddr = NULL;
1663 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1666 DGAP_LOCK(bd->bd_lock, lock_flags);
1668 vaddr = bd->re_map_membase;
1671 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1675 eaddr = (struct ev_t *) (vaddr + EVBUF);
1677 /* Get our head and tail */
1678 head = readw(&(eaddr->ev_head));
1679 tail = readw(&(eaddr->ev_tail));
1682 * Forget it if pointers out of range.
1685 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
1686 (head | tail) & 03) {
1687 DPR_EVENT(("should be calling xxfail %d\n", __LINE__));
1688 /* Let go of board lock */
1689 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1694 * Loop to process all the events in the buffer.
1696 while (tail != head) {
1699 * Get interrupt information.
1702 event = bd->re_map_membase + tail + EVSTART;
1709 DPR_EVENT(("event: jiffies: %ld port: %d reason: %x modem: %x\n",
1710 jiffies, port, reason, modem));
1713 * Make sure the interrupt is valid.
1715 if (port >= bd->nasync)
1718 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA))) {
1722 ch = bd->channels[port];
1724 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
1729 * If we have made it here, the event was valid.
1730 * Lock down the channel.
1732 DGAP_LOCK(ch->ch_lock, lock_flags2);
1737 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1742 * Process received data.
1744 if (reason & IFDATA) {
1747 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
1748 * input could send some data to ld, which in turn
1749 * could do a callback to one of our other functions.
1751 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1752 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1756 DGAP_LOCK(bd->bd_lock, lock_flags);
1757 DGAP_LOCK(ch->ch_lock, lock_flags2);
1759 if (ch->ch_flags & CH_RACTIVE)
1760 ch->ch_flags |= CH_RENABLE;
1762 writeb(1, &(bs->idata));
1764 if (ch->ch_flags & CH_RWAIT) {
1765 ch->ch_flags &= ~CH_RWAIT;
1767 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
1772 * Process Modem change signals.
1774 if (reason & IFMODEM) {
1775 ch->ch_mistat = modem;
1782 if (reason & IFBREAK) {
1784 DPR_EVENT(("got IFBREAK\n"));
1786 if (ch->ch_tun.un_tty) {
1787 /* A break has been indicated */
1789 tty_buffer_request_room(ch->ch_tun.un_tty->port, 1);
1790 tty_insert_flip_char(ch->ch_tun.un_tty->port, 0, TTY_BREAK);
1791 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
1796 * Process Transmit low.
1798 if (reason & IFTLW) {
1800 DPR_EVENT(("event: got low event\n"));
1802 if (ch->ch_tun.un_flags & UN_LOW) {
1803 ch->ch_tun.un_flags &= ~UN_LOW;
1805 if (ch->ch_tun.un_flags & UN_ISOPEN) {
1806 if ((ch->ch_tun.un_tty->flags &
1807 (1 << TTY_DO_WRITE_WAKEUP)) &&
1808 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1809 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
1811 ch->ch_tun.un_tty->ldisc.ops->write_wakeup)
1814 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1815 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1816 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1817 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
1819 (ch->ch_tun.un_tty->ldisc.ops->write_wakeup)(ch->ch_tun.un_tty);
1821 DGAP_LOCK(bd->bd_lock, lock_flags);
1822 DGAP_LOCK(ch->ch_lock, lock_flags2);
1824 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
1825 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
1827 DPR_EVENT(("event: Got low event. jiffies: %lu\n", jiffies));
1831 if (ch->ch_pun.un_flags & UN_LOW) {
1832 ch->ch_pun.un_flags &= ~UN_LOW;
1833 if (ch->ch_pun.un_flags & UN_ISOPEN) {
1834 if ((ch->ch_pun.un_tty->flags &
1835 (1 << TTY_DO_WRITE_WAKEUP)) &&
1836 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1837 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
1839 ch->ch_pun.un_tty->ldisc.ops->write_wakeup)
1842 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1843 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1844 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1845 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
1847 (ch->ch_pun.un_tty->ldisc.ops->write_wakeup)(ch->ch_pun.un_tty);
1849 DGAP_LOCK(bd->bd_lock, lock_flags);
1850 DGAP_LOCK(ch->ch_lock, lock_flags2);
1852 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
1853 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
1857 if (ch->ch_flags & CH_WLOW) {
1858 ch->ch_flags &= ~CH_WLOW;
1859 wake_up_interruptible(&ch->ch_flags_wait);
1864 * Process Transmit empty.
1866 if (reason & IFTEM) {
1867 DPR_EVENT(("event: got empty event\n"));
1869 if (ch->ch_tun.un_flags & UN_EMPTY) {
1870 ch->ch_tun.un_flags &= ~UN_EMPTY;
1871 if (ch->ch_tun.un_flags & UN_ISOPEN) {
1872 if ((ch->ch_tun.un_tty->flags &
1873 (1 << TTY_DO_WRITE_WAKEUP)) &&
1874 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1875 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
1877 ch->ch_tun.un_tty->ldisc.ops->write_wakeup)
1880 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1881 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1882 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1883 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
1885 (ch->ch_tun.un_tty->ldisc.ops->write_wakeup)(ch->ch_tun.un_tty);
1887 DGAP_LOCK(bd->bd_lock, lock_flags);
1888 DGAP_LOCK(ch->ch_lock, lock_flags2);
1890 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
1891 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
1895 if (ch->ch_pun.un_flags & UN_EMPTY) {
1896 ch->ch_pun.un_flags &= ~UN_EMPTY;
1897 if (ch->ch_pun.un_flags & UN_ISOPEN) {
1898 if ((ch->ch_pun.un_tty->flags &
1899 (1 << TTY_DO_WRITE_WAKEUP)) &&
1900 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1901 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
1903 ch->ch_pun.un_tty->ldisc.ops->write_wakeup)
1906 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1907 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1908 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1909 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
1911 (ch->ch_pun.un_tty->ldisc.ops->write_wakeup)(ch->ch_pun.un_tty);
1913 DGAP_LOCK(bd->bd_lock, lock_flags);
1914 DGAP_LOCK(ch->ch_lock, lock_flags2);
1916 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
1917 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
1922 if (ch->ch_flags & CH_WEMPTY) {
1923 ch->ch_flags &= ~CH_WEMPTY;
1924 wake_up_interruptible(&ch->ch_flags_wait);
1928 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1931 tail = (tail + 4) & (EVMAX - EVSTART - 4);
1934 writew(tail, &(eaddr->ev_tail));
1935 DGAP_UNLOCK(bd->bd_lock, lock_flags);