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 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
22 * This is shared code between Digi's CVS archive and the
23 * Linux Kernel sources.
24 * Changing the source just for reformatting needlessly breaks
25 * our CVS diff history.
27 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
30 * $Id: dgap_fep5.c,v 1.2 2011/06/21 10:35:40 markh Exp $
34 #include <linux/kernel.h>
35 #include <linux/version.h>
36 #include <linux/module.h>
37 #include <linux/pci.h>
38 #include <linux/delay.h> /* For udelay */
39 #include <asm/uaccess.h> /* For copy_from_user/copy_to_user */
40 #include <linux/tty.h>
41 #include <linux/tty_flip.h> /* For tty_schedule_flip */
43 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
44 #include <linux/sched.h>
47 #include "dgap_driver.h"
49 #include "dgap_fep5.h"
51 #include "dgap_conf.h"
52 #include "dgap_parse.h"
53 #include "dgap_trace.h"
56 * Our function prototypes
58 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
59 static int dgap_event(struct board_t *bd);
64 static uint dgap_count = 500;
68 * Loads the dgap.conf config file from the user.
70 void dgap_do_config_load(uchar __user *uaddr, int len)
74 uchar __user *from_addr = uaddr;
78 to_addr = dgap_config_buf = dgap_driver_kzmalloc(len + 1, GFP_ATOMIC);
79 if (!dgap_config_buf) {
80 DPR_INIT(("dgap_do_config_load - unable to allocate memory for file\n"));
81 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
91 if (copy_from_user((char *) &buf, from_addr, n) == -1 )
94 /* Copy data from buffer to kernel memory */
95 memcpy(to_addr, buf, n);
97 /* increment counts */
104 dgap_config_buf[orig_len] = '\0';
106 to_addr = dgap_config_buf;
107 dgap_parsefile(&to_addr, TRUE);
109 DPR_INIT(("dgap_config_load() finish\n"));
115 int dgap_after_config_loaded(void)
121 * Register our ttys, now that we have the config loaded.
123 for (i = 0; i < dgap_NumBoards; ++i) {
126 * Initialize KME waitqueues...
128 init_waitqueue_head(&(dgap_Board[i]->kme_wait));
131 * allocate flip buffer for board.
133 dgap_Board[i]->flipbuf = dgap_driver_kzmalloc(MYFLIPLEN, GFP_ATOMIC);
134 dgap_Board[i]->flipflagbuf = dgap_driver_kzmalloc(MYFLIPLEN, GFP_ATOMIC);
142 /*=======================================================================
144 * usertoboard - copy from user space to board space.
146 *=======================================================================*/
147 static int dgap_usertoboard(struct board_t *brd, char *to_addr, char __user *from_addr, int len)
152 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
159 if (copy_from_user((char *) &buf, from_addr, n) == -1 ) {
163 /* Copy data from buffer to card memory */
164 memcpy_toio(to_addr, buf, n);
166 /* increment counts */
177 * Copies the BIOS code from the user to the board,
178 * and starts the BIOS running.
180 void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
186 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
189 DPR_INIT(("dgap_do_bios_load() start\n"));
191 addr = brd->re_map_membase;
196 for (i = 0; i < 16; i++)
197 writeb(0, addr + POSTAREA + i);
203 if (dgap_usertoboard(brd, addr + offset, ubios, len) == -1 ) {
204 brd->state = BOARD_FAILED;
205 brd->dpastatus = BD_NOFEP;
209 writel(0x0bf00401, addr);
210 writel(0, (addr + 4));
212 /* Clear the reset, and change states. */
213 writeb(FEPCLR, brd->re_map_port);
214 brd->state = WAIT_BIOS_LOAD;
219 * Checks to see if the BIOS completed running on the card.
221 static void dgap_do_wait_for_bios(struct board_t *brd)
226 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
229 addr = brd->re_map_membase;
230 word = readw(addr + POSTAREA);
232 /* Check to see if BIOS thinks board is good. (GD). */
233 if (word == *(u16 *) "GD") {
234 DPR_INIT(("GOT GD in memory, moving states.\n"));
235 brd->state = FINISHED_BIOS_LOAD;
239 /* Give up on board after too long of time taken */
240 if (brd->wait_for_bios++ > 5000) {
241 u16 err1 = readw(addr + SEQUENCE);
242 u16 err2 = readw(addr + ERROR);
243 APR(("***WARNING*** %s failed diagnostics. Error #(%x,%x).\n",
244 brd->name, err1, err2));
245 brd->state = BOARD_FAILED;
246 brd->dpastatus = BD_NOFEP;
252 * Copies the FEP code from the user to the board,
253 * and starts the FEP running.
255 void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len)
260 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
263 addr = brd->re_map_membase;
265 DPR_INIT(("dgap_do_fep_load() for board %s : start\n", brd->name));
271 if (dgap_usertoboard(brd, addr + offset, ufep, len) == -1 ) {
272 brd->state = BOARD_FAILED;
273 brd->dpastatus = BD_NOFEP;
278 * If board is a concentrator product, we need to give
279 * it its config string describing how the concentrators look.
281 if ((brd->type == PCX) || (brd->type == PEPC)) {
283 uchar *config, *xconfig;
286 xconfig = dgap_create_config_string(brd, string);
288 /* Write string to board memory */
289 config = addr + CONFIG;
290 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
291 writeb(*xconfig, config);
292 if ((*xconfig & 0xff) == 0xff)
297 writel(0xbfc01004, (addr + 0xc34));
298 writel(0x3, (addr + 0xc30));
301 brd->state = WAIT_FEP_LOAD;
303 DPR_INIT(("dgap_do_fep_load() for board %s : finish\n", brd->name));
309 * Waits for the FEP to report thats its ready for us to use.
311 static void dgap_do_wait_for_fep(struct board_t *brd)
316 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
319 addr = brd->re_map_membase;
321 DPR_INIT(("dgap_do_wait_for_fep() for board %s : start. addr: %p\n", brd->name, addr));
323 word = readw(addr + FEPSTAT);
325 /* Check to see if FEP is up and running now. */
326 if (word == *(u16 *) "OS") {
327 DPR_INIT(("GOT OS in memory for board %s, moving states.\n", brd->name));
328 brd->state = FINISHED_FEP_LOAD;
331 * Check to see if the board can support FEP5+ commands.
333 word = readw(addr + FEP5_PLUS);
334 if (word == *(u16 *) "5A") {
335 DPR_INIT(("GOT 5A in memory for board %s, board supports extended FEP5 commands.\n", brd->name));
336 brd->bd_flags |= BD_FEP5PLUS;
342 /* Give up on board after too long of time taken */
343 if (brd->wait_for_fep++ > 5000) {
344 u16 err1 = readw(addr + SEQUENCE);
345 u16 err2 = readw(addr + ERROR);
346 APR(("***WARNING*** FEPOS for %s not functioning. Error #(%x,%x).\n",
347 brd->name, err1, err2));
348 brd->state = BOARD_FAILED;
349 brd->dpastatus = BD_NOFEP;
352 DPR_INIT(("dgap_do_wait_for_fep() for board %s : finish\n", brd->name));
357 * Physically forces the FEP5 card to reset itself.
359 static void dgap_do_reset_board(struct board_t *brd)
366 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase || !brd->re_map_port) {
367 DPR_INIT(("dgap_do_reset_board() start. bad values. brd: %p mem: %p io: %p\n",
368 brd, brd ? brd->re_map_membase : 0, brd ? brd->re_map_port : 0));
372 DPR_INIT(("dgap_do_reset_board() start. io: %p\n", brd->re_map_port));
374 /* FEPRST does not vary among supported boards */
375 writeb(FEPRST, brd->re_map_port);
377 for (i = 0; i <= 1000; i++) {
378 check = readb(brd->re_map_port) & 0xe;
385 APR(("*** WARNING *** Board not resetting... Failing board.\n"));
386 brd->state = BOARD_FAILED;
387 brd->dpastatus = BD_NOFEP;
392 * Make sure there really is memory out there.
394 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
395 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
396 check1 = readl(brd->re_map_membase + LOWMEM);
397 check2 = readl(brd->re_map_membase + HIGHMEM);
399 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
400 APR(("*** Warning *** No memory at %p for board.\n", brd->re_map_membase));
401 brd->state = BOARD_FAILED;
402 brd->dpastatus = BD_NOFEP;
406 if (brd->state != BOARD_FAILED)
407 brd->state = FINISHED_RESET;
410 DPR_INIT(("dgap_do_reset_board() finish\n"));
415 * Sends a concentrator image into the FEP5 board.
417 void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
421 struct downld_t *to_dp;
423 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
426 vaddr = brd->re_map_membase;
428 offset = readw((u16 *) (vaddr + DOWNREQ));
429 to_dp = (struct downld_t *) (vaddr + (int) offset);
432 * The image was already read into kernel space,
433 * we do NOT need a user space read here
435 memcpy_toio((char *) to_dp, uaddr, sizeof(struct downld_t));
437 /* Tell card we have data for it */
438 writew(0, vaddr + (DOWNREQ));
440 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
444 #define EXPANSION_ROM_SIZE (64 * 1024)
445 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
447 static void dgap_get_vpd(struct board_t *brd)
459 * Poke the magic number at the PCI Rom Address location.
460 * If VPD is supported, the value read from that address
463 magic = FEP5_ROM_MAGIC;
464 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
465 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
467 /* VPD not supported, bail */
472 * To get to the OTPROM memory, we have to send the boards base
473 * address or'ed with 1 into the PCI Rom Address location.
475 magic = brd->membase | 0x01;
476 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
477 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
479 byte1 = readb(brd->re_map_membase);
480 byte2 = readb(brd->re_map_membase + 1);
483 * If the board correctly swapped to the OTPROM memory,
484 * the first 2 bytes (header) should be 0x55, 0xAA
486 if (byte1 == 0x55 && byte2 == 0xAA) {
491 * We have to run through all the OTPROM memory looking
492 * for the VPD offset.
494 while (base_offset <= EXPANSION_ROM_SIZE) {
497 * Lots of magic numbers here.
499 * The VPD offset is located inside the ROM Data Structure.
500 * We also have to remember the length of each
501 * ROM Data Structure, so we can "hop" to the next
502 * entry if the VPD isn't in the current
503 * ROM Data Structure.
505 rom_offset = readw(brd->re_map_membase + base_offset + 0x18);
506 image_length = readw(brd->re_map_membase + rom_offset + 0x10) * 512;
507 vpd_offset = readw(brd->re_map_membase + rom_offset + 0x08);
509 /* Found the VPD entry */
513 /* We didn't find a VPD entry, go to next ROM entry. */
514 base_offset += image_length;
516 byte1 = readb(brd->re_map_membase + base_offset);
517 byte2 = readb(brd->re_map_membase + base_offset + 1);
520 * If the new ROM offset doesn't have 0x55, 0xAA
521 * as its header, we have run out of ROM.
523 if (byte1 != 0x55 || byte2 != 0xAA)
528 * If we have a VPD offset, then mark the board
529 * as having a valid VPD, and copy VPDSIZE (512) bytes of
530 * that VPD to the buffer we have in our board structure.
533 brd->bd_flags |= BD_HAS_VPD;
534 for (i = 0; i < VPDSIZE; i++)
535 brd->vpd[i] = readb(brd->re_map_membase + vpd_offset + i);
540 * We MUST poke the magic number at the PCI Rom Address location again.
541 * This makes the card report the regular board memory back to us,
542 * rather than the OTPROM memory.
544 magic = FEP5_ROM_MAGIC;
545 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
550 * Our board poller function.
552 void dgap_poll_tasklet(unsigned long data)
554 struct board_t *bd = (struct board_t *) data;
562 if (!bd || (bd->magic != DGAP_BOARD_MAGIC)) {
563 APR(("dgap_poll_tasklet() - NULL or bad bd.\n"));
567 if (bd->inhibit_poller)
570 DGAP_LOCK(bd->bd_lock, lock_flags);
572 vaddr = bd->re_map_membase;
575 * If board is ready, parse deeper to see if there is anything to do.
577 if (bd->state == BOARD_READY) {
579 struct ev_t *eaddr = NULL;
581 if (!bd->re_map_membase) {
582 DGAP_UNLOCK(bd->bd_lock, lock_flags);
585 if (!bd->re_map_port) {
586 DGAP_UNLOCK(bd->bd_lock, lock_flags);
595 * If this is a CX or EPCX, we need to see if the firmware
596 * is requesting a concentrator image from us.
598 if ((bd->type == PCX) || (bd->type == PEPC)) {
599 chk_addr = (u16 *) (vaddr + DOWNREQ);
600 check = readw(chk_addr);
601 /* Nonzero if FEP is requesting concentrator image. */
603 if (bd->conc_dl_status == NO_PENDING_CONCENTRATOR_REQUESTS)
604 bd->conc_dl_status = NEED_CONCENTRATOR;
606 * Signal downloader, its got some work to do.
608 DGAP_LOCK(dgap_dl_lock, lock_flags2);
609 if (dgap_dl_action != 1) {
611 wake_up_interruptible(&dgap_dl_wait);
613 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
618 eaddr = (struct ev_t *) (vaddr + EVBUF);
620 /* Get our head and tail */
621 head = readw(&(eaddr->ev_head));
622 tail = readw(&(eaddr->ev_tail));
625 * If there is an event pending. Go service it.
628 DGAP_UNLOCK(bd->bd_lock, lock_flags);
630 DGAP_LOCK(bd->bd_lock, lock_flags);
635 * If board is doing interrupts, ACK the interrupt.
637 if (bd && bd->intr_running) {
638 readb(bd->re_map_port + 2);
641 DGAP_UNLOCK(bd->bd_lock, lock_flags);
645 /* Our state machine to get the board up and running */
648 if (bd->state == NEED_RESET) {
653 dgap_do_reset_board(bd);
656 /* Move to next state */
657 if (bd->state == FINISHED_RESET) {
658 bd->state = NEED_CONFIG;
661 if (bd->state == NEED_CONFIG) {
663 * Match this board to a config the user created for us.
665 bd->bd_config = dgap_find_config(bd->type, bd->pci_bus, bd->pci_slot);
668 * Because the 4 port Xr products share the same PCI ID
669 * as the 8 port Xr products, if we receive a NULL config
670 * back, and this is a PAPORT8 board, retry with a
671 * PAPORT4 attempt as well.
673 if (bd->type == PAPORT8 && !bd->bd_config) {
674 bd->bd_config = dgap_find_config(PAPORT4, bd->pci_bus, bd->pci_slot);
678 * Register the ttys (if any) into the kernel.
681 bd->state = FINISHED_CONFIG;
684 bd->state = CONFIG_NOT_FOUND;
688 /* Move to next state */
689 if (bd->state == FINISHED_CONFIG) {
690 bd->state = NEED_DEVICE_CREATION;
693 /* Move to next state */
694 if (bd->state == NEED_DEVICE_CREATION) {
696 * Signal downloader, its got some work to do.
698 DGAP_LOCK(dgap_dl_lock, lock_flags2);
699 if (dgap_dl_action != 1) {
701 wake_up_interruptible(&dgap_dl_wait);
703 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
706 /* Move to next state */
707 if (bd->state == FINISHED_DEVICE_CREATION) {
708 bd->state = NEED_BIOS_LOAD;
711 /* Move to next state */
712 if (bd->state == NEED_BIOS_LOAD) {
714 * Signal downloader, its got some work to do.
716 DGAP_LOCK(dgap_dl_lock, lock_flags2);
717 if (dgap_dl_action != 1) {
719 wake_up_interruptible(&dgap_dl_wait);
721 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
724 /* Wait for BIOS to test board... */
725 if (bd->state == WAIT_BIOS_LOAD) {
726 dgap_do_wait_for_bios(bd);
729 /* Move to next state */
730 if (bd->state == FINISHED_BIOS_LOAD) {
731 bd->state = NEED_FEP_LOAD;
734 * Signal downloader, its got some work to do.
736 DGAP_LOCK(dgap_dl_lock, lock_flags2);
737 if (dgap_dl_action != 1) {
739 wake_up_interruptible(&dgap_dl_wait);
741 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
744 /* Wait for FEP to load on board... */
745 if (bd->state == WAIT_FEP_LOAD) {
746 dgap_do_wait_for_fep(bd);
750 /* Move to next state */
751 if (bd->state == FINISHED_FEP_LOAD) {
754 * Do tty device initialization.
756 int rc = dgap_tty_init(bd);
760 APR(("Can't init tty devices (%d)\n", rc));
761 bd->state = BOARD_FAILED;
762 bd->dpastatus = BD_NOFEP;
765 bd->state = NEED_PROC_CREATION;
768 * Signal downloader, its got some work to do.
770 DGAP_LOCK(dgap_dl_lock, lock_flags2);
771 if (dgap_dl_action != 1) {
773 wake_up_interruptible(&dgap_dl_wait);
775 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
779 /* Move to next state */
780 if (bd->state == FINISHED_PROC_CREATION) {
782 bd->state = BOARD_READY;
783 bd->dpastatus = BD_RUNNING;
786 * If user requested the board to run in interrupt mode,
787 * go and set it up on the board.
790 writew(1, (bd->re_map_membase + ENABLE_INTR));
792 * Tell the board to poll the UARTS as fast as possible.
794 writew(FEPPOLL_MIN, (bd->re_map_membase + FEPPOLL));
795 bd->intr_running = 1;
798 /* Wake up anyone waiting for board state to change to ready */
799 wake_up_interruptible(&bd->state_wait);
802 DGAP_UNLOCK(bd->bd_lock, lock_flags);
806 /*=======================================================================
808 * dgap_cmdb - Sends a 2 byte command to the FEP.
810 * ch - Pointer to channel structure.
811 * cmd - Command to be sent.
812 * byte1 - Integer containing first byte to be sent.
813 * byte2 - Integer containing second byte to be sent.
814 * ncmds - Wait until ncmds or fewer cmds are left
815 * in the cmd buffer before returning.
817 *=======================================================================*/
818 void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1, uchar byte2, uint ncmds)
821 struct cm_t *cm_addr = NULL;
827 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
831 * Check if board is still alive.
833 if (ch->ch_bd->state == BOARD_FAILED) {
834 DPR_CORE(("%s:%d board is in failed state.\n", __FILE__, __LINE__));
839 * Make sure the pointers are in range before
840 * writing to the FEP memory.
842 vaddr = ch->ch_bd->re_map_membase;
847 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
848 head = readw(&(cm_addr->cm_head));
851 * Forget it if pointers out of range.
853 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
854 DPR_CORE(("%s:%d pointers out of range, failing board!\n", __FILE__, __LINE__));
855 ch->ch_bd->state = BOARD_FAILED;
860 * Put the data in the circular command buffer.
862 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
863 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
864 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
865 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
867 head = (head + 4) & (CMDMAX - CMDSTART - 4);
869 writew(head, &(cm_addr->cm_head));
872 * Wait if necessary before updating the head
873 * pointer to limit the number of outstanding
874 * commands to the FEP. If the time spent waiting
875 * is outlandish, declare the FEP dead.
877 for (count = dgap_count ;;) {
879 head = readw(&(cm_addr->cm_head));
880 tail = readw(&(cm_addr->cm_tail));
882 n = (head - tail) & (CMDMAX - CMDSTART - 4);
884 if (n <= ncmds * sizeof(struct cm_t))
888 DPR_CORE(("%s:%d failing board.\n",__FILE__, __LINE__));
889 ch->ch_bd->state = BOARD_FAILED;
897 /*=======================================================================
899 * dgap_cmdw - Sends a 1 word command to the FEP.
901 * ch - Pointer to channel structure.
902 * cmd - Command to be sent.
903 * word - Integer containing word to be sent.
904 * ncmds - Wait until ncmds or fewer cmds are left
905 * in the cmd buffer before returning.
907 *=======================================================================*/
908 void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
911 struct cm_t *cm_addr = NULL;
917 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
921 * Check if board is still alive.
923 if (ch->ch_bd->state == BOARD_FAILED) {
924 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
929 * Make sure the pointers are in range before
930 * writing to the FEP memory.
932 vaddr = ch->ch_bd->re_map_membase;
936 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
937 head = readw(&(cm_addr->cm_head));
940 * Forget it if pointers out of range.
942 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
943 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
944 ch->ch_bd->state = BOARD_FAILED;
949 * Put the data in the circular command buffer.
951 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
952 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
953 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
955 head = (head + 4) & (CMDMAX - CMDSTART - 4);
957 writew(head, &(cm_addr->cm_head));
960 * Wait if necessary before updating the head
961 * pointer to limit the number of outstanding
962 * commands to the FEP. If the time spent waiting
963 * is outlandish, declare the FEP dead.
965 for (count = dgap_count ;;) {
967 head = readw(&(cm_addr->cm_head));
968 tail = readw(&(cm_addr->cm_tail));
970 n = (head - tail) & (CMDMAX - CMDSTART - 4);
972 if (n <= ncmds * sizeof(struct cm_t))
976 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
977 ch->ch_bd->state = BOARD_FAILED;
986 /*=======================================================================
988 * dgap_cmdw_ext - Sends a extended word command to the FEP.
990 * ch - Pointer to channel structure.
991 * cmd - Command to be sent.
992 * word - Integer containing word to be sent.
993 * ncmds - Wait until ncmds or fewer cmds are left
994 * in the cmd buffer before returning.
996 *=======================================================================*/
997 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
1000 struct cm_t *cm_addr = NULL;
1006 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1010 * Check if board is still alive.
1012 if (ch->ch_bd->state == BOARD_FAILED) {
1013 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
1018 * Make sure the pointers are in range before
1019 * writing to the FEP memory.
1021 vaddr = ch->ch_bd->re_map_membase;
1025 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
1026 head = readw(&(cm_addr->cm_head));
1029 * Forget it if pointers out of range.
1031 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
1032 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
1033 ch->ch_bd->state = BOARD_FAILED;
1038 * Put the data in the circular command buffer.
1041 /* Write an FF to tell the FEP that we want an extended command */
1042 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
1044 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
1045 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
1048 * If the second part of the command won't fit,
1049 * put it at the beginning of the circular buffer.
1051 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03))) {
1052 writew((u16) word, (char *) (vaddr + CMDSTART));
1054 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
1057 head = (head + 8) & (CMDMAX - CMDSTART - 4);
1059 writew(head, &(cm_addr->cm_head));
1062 * Wait if necessary before updating the head
1063 * pointer to limit the number of outstanding
1064 * commands to the FEP. If the time spent waiting
1065 * is outlandish, declare the FEP dead.
1067 for (count = dgap_count ;;) {
1069 head = readw(&(cm_addr->cm_head));
1070 tail = readw(&(cm_addr->cm_tail));
1072 n = (head - tail) & (CMDMAX - CMDSTART - 4);
1074 if (n <= ncmds * sizeof(struct cm_t))
1078 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
1079 ch->ch_bd->state = BOARD_FAILED;
1087 /*=======================================================================
1089 * dgap_wmove - Write data to FEP buffer.
1091 * ch - Pointer to channel structure.
1092 * buf - Poiter to characters to be moved.
1093 * cnt - Number of characters to move.
1095 *=======================================================================*/
1096 void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
1103 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1110 head = readw(&(bs->tx_head));
1113 * If pointers are out of range, just return.
1115 if ((cnt > ch->ch_tsize) || (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize) {
1116 DPR_CORE(("%s:%d pointer out of range", __FILE__, __LINE__));
1121 * If the write wraps over the top of the circular buffer,
1122 * move the portion up to the wrap point, and reset the
1123 * pointers to the bottom.
1125 n = ch->ch_tstart + ch->ch_tsize - head;
1129 taddr = ch->ch_taddr + head;
1130 memcpy_toio(taddr, buf, n);
1131 head = ch->ch_tstart;
1136 * Move rest of data.
1138 taddr = ch->ch_taddr + head;
1140 memcpy_toio(taddr, buf, n);
1143 writew(head, &(bs->tx_head));
1147 * Retrives the current custom baud rate from FEP memory,
1148 * and returns it back to the user.
1149 * Returns 0 on error.
1151 uint dgap_get_custom_baud(struct channel_t *ch)
1157 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
1161 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC) {
1165 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
1168 vaddr = ch->ch_bd->re_map_membase;
1174 * Go get from fep mem, what the fep
1175 * believes the custom baud rate is.
1177 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
1178 (ch->ch_portnum * 0x28) + LINE_SPEED));
1180 value = readw(vaddr + offset);
1186 * Calls the firmware to reset this channel.
1188 void dgap_firmware_reset_port(struct channel_t *ch)
1190 dgap_cmdb(ch, CHRESET, 0, 0, 0);
1193 * Now that the channel is reset, we need to make sure
1194 * all the current settings get reapplied to the port
1197 * So we will set the driver's cache of firmware
1198 * settings all to 0, and then call param.
1200 ch->ch_fepiflag = 0;
1201 ch->ch_fepcflag = 0;
1202 ch->ch_fepoflag = 0;
1203 ch->ch_fepstartc = 0;
1204 ch->ch_fepstopc = 0;
1205 ch->ch_fepastartc = 0;
1206 ch->ch_fepastopc = 0;
1212 /*=======================================================================
1214 * dgap_param - Set Digi parameters.
1216 * struct tty_struct * - TTY for port.
1218 *=======================================================================*/
1219 int dgap_param(struct tty_struct *tty)
1221 struct ktermios *ts;
1223 struct channel_t *ch;
1232 if (!tty || tty->magic != TTY_MAGIC)
1235 un = (struct un_t *) tty->driver_data;
1236 if (!un || un->magic != DGAP_UNIT_MAGIC)
1240 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1244 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1251 DPR_PARAM(("param start: tdev: %x cflags: %x oflags: %x iflags: %x\n",
1252 ch->ch_tun.un_dev, ch->ch_c_cflag, ch->ch_c_oflag, ch->ch_c_iflag));
1257 * If baud rate is zero, flush queues, and set mval to drop DTR.
1259 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
1262 head = readw(&(ch->ch_bs->rx_head));
1263 writew(head, &(ch->ch_bs->rx_tail));
1266 head = readw(&(ch->ch_bs->tx_head));
1267 writew(head, &(ch->ch_bs->tx_tail));
1269 ch->ch_flags |= (CH_BAUD0);
1271 /* Drop RTS and DTR */
1272 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
1273 mval = D_DTR(ch) | D_RTS(ch);
1274 ch->ch_baud_info = 0;
1276 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
1278 * Tell the fep to do the command
1281 DPR_PARAM(("param: Want %d speed\n", ch->ch_custom_speed));
1283 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
1286 * Now go get from fep mem, what the fep
1287 * believes the custom baud rate is.
1289 ch->ch_baud_info = ch->ch_custom_speed = dgap_get_custom_baud(ch);
1291 DPR_PARAM(("param: Got %d speed\n", ch->ch_custom_speed));
1293 /* Handle transition from B0 */
1294 if (ch->ch_flags & CH_BAUD0) {
1295 ch->ch_flags &= ~(CH_BAUD0);
1296 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
1298 mval = D_DTR(ch) | D_RTS(ch);
1302 * Set baud rate, character size, and parity.
1310 ulong bauds[4][16] = {
1314 600, 1200, 1800, 2400,
1315 4800, 9600, 19200, 38400 },
1316 { /* slowbaud & CBAUDEX */
1317 0, 57600, 115200, 230400,
1318 460800, 150, 200, 921600,
1319 600, 1200, 1800, 2400,
1320 4800, 9600, 19200, 38400 },
1322 0, 57600, 76800, 115200,
1323 14400, 57600, 230400, 76800,
1324 115200, 230400, 28800, 460800,
1325 921600, 9600, 19200, 38400 },
1326 { /* fastbaud & CBAUDEX */
1327 0, 57600, 115200, 230400,
1328 460800, 150, 200, 921600,
1329 600, 1200, 1800, 2400,
1330 4800, 9600, 19200, 38400 }
1333 /* Only use the TXPrint baud rate if the terminal unit is NOT open */
1334 if (!(ch->ch_tun.un_flags & UN_ISOPEN) && (un->un_type == DGAP_PRINT))
1335 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
1337 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
1339 if (ch->ch_c_cflag & CBAUDEX)
1342 if (ch->ch_digi.digi_flags & DIGI_FAST)
1347 if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) && (jindex < 16)) {
1348 baud = bauds[iindex][jindex];
1350 DPR_IOCTL(("baud indices were out of range (%d)(%d)",
1358 ch->ch_baud_info = baud;
1362 * CBAUD has bit position 0x1000 set these days to indicate Linux
1364 * We use a different bit assignment for high speed. Clear this
1365 * bit out while grabbing the parts of "cflag" we want.
1367 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
1370 * HUPCL bit is used by FEP to indicate fast baud
1371 * table is to be used.
1373 if ((ch->ch_digi.digi_flags & DIGI_FAST) || (ch->ch_c_cflag & CBAUDEX))
1377 if ((ch->ch_c_cflag & CBAUDEX) && !(ch->ch_digi.digi_flags & DIGI_FAST)) {
1379 * The below code is trying to guarantee that only baud rates
1380 * 115200, 230400, 460800, 921600 are remapped. We use exclusive or
1381 * because the various baud rates share common bit positions
1382 * and therefore can't be tested for easily.
1384 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
1387 /* Map high speed requests to index into FEP's baud table */
1416 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
1421 if (cflag != ch->ch_fepcflag) {
1422 ch->ch_fepcflag = (u16) (cflag & 0xffff);
1424 /* Okay to have channel and board locks held calling this */
1425 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
1428 /* Handle transition from B0 */
1429 if (ch->ch_flags & CH_BAUD0) {
1430 ch->ch_flags &= ~(CH_BAUD0);
1431 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
1433 mval = D_DTR(ch) | D_RTS(ch);
1439 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | IXON | IXANY | IXOFF);
1441 if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE)) {
1442 iflag &= ~(IXON | IXOFF);
1443 ch->ch_c_iflag &= ~(IXON | IXOFF);
1447 * Only the IBM Xr card can switch between
1448 * 232 and 422 modes on the fly
1450 if (bd->device == PCI_DEVICE_XR_IBM_DID) {
1451 if (ch->ch_digi.digi_flags & DIGI_422)
1452 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
1454 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
1457 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
1460 if (iflag != ch->ch_fepiflag) {
1461 ch->ch_fepiflag = iflag;
1463 /* Okay to have channel and board locks held calling this */
1464 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
1468 * Select hardware handshaking.
1472 if (ch->ch_c_cflag & CRTSCTS) {
1473 hflow |= (D_RTS(ch) | D_CTS(ch));
1475 if (ch->ch_digi.digi_flags & RTSPACE)
1477 if (ch->ch_digi.digi_flags & DTRPACE)
1479 if (ch->ch_digi.digi_flags & CTSPACE)
1481 if (ch->ch_digi.digi_flags & DSRPACE)
1483 if (ch->ch_digi.digi_flags & DCDPACE)
1486 if (hflow != ch->ch_hflow) {
1487 ch->ch_hflow = hflow;
1489 /* Okay to have channel and board locks held calling this */
1490 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
1495 * Set RTS and/or DTR Toggle if needed, but only if product is FEP5+ based.
1497 if (bd->bd_flags & BD_FEP5PLUS) {
1499 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
1500 hflow2 |= (D_RTS(ch));
1502 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
1503 hflow2 |= (D_DTR(ch));
1506 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
1510 * Set modem control lines.
1513 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
1515 DPR_PARAM(("dgap_param: mval: %x ch_mforce: %x ch_mval: %x ch_mostat: %x\n",
1516 mval, ch->ch_mforce, ch->ch_mval, ch->ch_mostat));
1518 if (ch->ch_mostat ^ mval) {
1519 ch->ch_mostat = mval;
1521 /* Okay to have channel and board locks held calling this */
1522 DPR_PARAM(("dgap_param: Sending SMODEM mval: %x\n", mval));
1523 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
1527 * Read modem signals, and then call carrier function.
1529 ch->ch_mistat = readb(&(bs->m_stat));
1533 * Set the start and stop characters.
1535 if (ch->ch_startc != ch->ch_fepstartc || ch->ch_stopc != ch->ch_fepstopc) {
1536 ch->ch_fepstartc = ch->ch_startc;
1537 ch->ch_fepstopc = ch->ch_stopc;
1539 /* Okay to have channel and board locks held calling this */
1540 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
1544 * Set the Auxiliary start and stop characters.
1546 if (ch->ch_astartc != ch->ch_fepastartc || ch->ch_astopc != ch->ch_fepastopc) {
1547 ch->ch_fepastartc = ch->ch_astartc;
1548 ch->ch_fepastopc = ch->ch_astopc;
1550 /* Okay to have channel and board locks held calling this */
1551 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
1554 DPR_PARAM(("param finish\n"));
1561 * dgap_parity_scan()
1563 * Convert the FEP5 way of reporting parity errors and breaks into
1564 * the Linux line discipline way.
1566 void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, unsigned char *fbuf, int *len)
1570 unsigned char *in, *cout, *fout;
1577 DPR_PSCAN(("dgap_parity_scan start\n"));
1579 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1584 switch (ch->pscan_state) {
1586 /* reset to sanity and fall through */
1587 ch->pscan_state = 0;
1590 /* No FF seen yet */
1591 if (c == (unsigned char) '\377') {
1592 /* delete this character from stream */
1593 ch->pscan_state = 1;
1596 *fout++ = TTY_NORMAL;
1603 if (c == (unsigned char) '\377') {
1604 /* doubled ff, transform to single ff */
1606 *fout++ = TTY_NORMAL;
1608 ch->pscan_state = 0;
1610 /* save value examination in next state */
1611 ch->pscan_savechar = c;
1612 ch->pscan_state = 2;
1617 /* third character of ff sequence */
1621 if (ch->pscan_savechar == 0x0) {
1624 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting break.\n", c));
1626 *fout++ = TTY_BREAK;
1629 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting parity.\n", c));
1630 ch->ch_err_parity++;
1631 *fout++ = TTY_PARITY;
1635 DPR_PSCAN(("%s:%d Logic Error.\n", __FILE__, __LINE__));
1639 ch->pscan_state = 0;
1643 DPR_PSCAN(("dgap_parity_scan finish\n"));
1649 /*=======================================================================
1651 * dgap_event - FEP to host event processing routine.
1653 * bd - Board of current event.
1655 *=======================================================================*/
1656 static int dgap_event(struct board_t *bd)
1658 struct channel_t *ch;
1663 uchar *vaddr = NULL;
1664 struct ev_t *eaddr = NULL;
1672 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1675 DGAP_LOCK(bd->bd_lock, lock_flags);
1677 vaddr = bd->re_map_membase;
1680 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1684 eaddr = (struct ev_t *) (vaddr + EVBUF);
1686 /* Get our head and tail */
1687 head = readw(&(eaddr->ev_head));
1688 tail = readw(&(eaddr->ev_tail));
1691 * Forget it if pointers out of range.
1694 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
1695 (head | tail) & 03) {
1696 DPR_EVENT(("should be calling xxfail %d\n", __LINE__));
1697 /* Let go of board lock */
1698 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1703 * Loop to process all the events in the buffer.
1705 while (tail != head) {
1708 * Get interrupt information.
1711 event = bd->re_map_membase + tail + EVSTART;
1718 DPR_EVENT(("event: jiffies: %ld port: %d reason: %x modem: %x\n",
1719 jiffies, port, reason, modem));
1722 * Make sure the interrupt is valid.
1724 if ( port >= bd->nasync) {
1728 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA))) {
1732 ch = bd->channels[port];
1734 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
1739 * If we have made it here, the event was valid.
1740 * Lock down the channel.
1742 DGAP_LOCK(ch->ch_lock, lock_flags2);
1747 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1752 * Process received data.
1754 if (reason & IFDATA) {
1757 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
1758 * input could send some data to ld, which in turn
1759 * could do a callback to one of our other functions.
1761 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1762 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1766 DGAP_LOCK(bd->bd_lock, lock_flags);
1767 DGAP_LOCK(ch->ch_lock, lock_flags2);
1769 if (ch->ch_flags & CH_RACTIVE)
1770 ch->ch_flags |= CH_RENABLE;
1772 writeb(1, &(bs->idata));
1774 if (ch->ch_flags & CH_RWAIT) {
1775 ch->ch_flags &= ~CH_RWAIT;
1777 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
1782 * Process Modem change signals.
1784 if (reason & IFMODEM) {
1785 ch->ch_mistat = modem;
1792 if (reason & IFBREAK) {
1794 DPR_EVENT(("got IFBREAK\n"));
1796 if (ch->ch_tun.un_tty) {
1797 /* A break has been indicated */
1799 tty_buffer_request_room(ch->ch_tun.un_tty->port, 1);
1800 tty_insert_flip_char(ch->ch_tun.un_tty->port, 0, TTY_BREAK);
1801 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
1806 * Process Transmit low.
1808 if (reason & IFTLW) {
1810 DPR_EVENT(("event: got low event\n"));
1812 if (ch->ch_tun.un_flags & UN_LOW) {
1813 ch->ch_tun.un_flags &= ~UN_LOW;
1815 if (ch->ch_tun.un_flags & UN_ISOPEN) {
1816 if ((ch->ch_tun.un_tty->flags &
1817 (1 << TTY_DO_WRITE_WAKEUP)) &&
1818 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1819 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
1821 ch->ch_tun.un_tty->ldisc.ops->write_wakeup)
1824 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1825 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1826 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1827 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
1829 (ch->ch_tun.un_tty->ldisc.ops->write_wakeup)(ch->ch_tun.un_tty);
1831 DGAP_LOCK(bd->bd_lock, lock_flags);
1832 DGAP_LOCK(ch->ch_lock, lock_flags2);
1834 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
1835 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
1837 DPR_EVENT(("event: Got low event. jiffies: %lu\n", jiffies));
1841 if (ch->ch_pun.un_flags & UN_LOW) {
1842 ch->ch_pun.un_flags &= ~UN_LOW;
1843 if (ch->ch_pun.un_flags & UN_ISOPEN) {
1844 if ((ch->ch_pun.un_tty->flags &
1845 (1 << TTY_DO_WRITE_WAKEUP)) &&
1846 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1847 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
1849 ch->ch_pun.un_tty->ldisc.ops->write_wakeup)
1852 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1853 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1854 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1855 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
1857 (ch->ch_pun.un_tty->ldisc.ops->write_wakeup)(ch->ch_pun.un_tty);
1859 DGAP_LOCK(bd->bd_lock, lock_flags);
1860 DGAP_LOCK(ch->ch_lock, lock_flags2);
1862 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
1863 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
1867 if (ch->ch_flags & CH_WLOW) {
1868 ch->ch_flags &= ~CH_WLOW;
1869 wake_up_interruptible(&ch->ch_flags_wait);
1874 * Process Transmit empty.
1876 if (reason & IFTEM) {
1877 DPR_EVENT(("event: got empty event\n"));
1879 if (ch->ch_tun.un_flags & UN_EMPTY) {
1880 ch->ch_tun.un_flags &= ~UN_EMPTY;
1881 if (ch->ch_tun.un_flags & UN_ISOPEN) {
1882 if ((ch->ch_tun.un_tty->flags &
1883 (1 << TTY_DO_WRITE_WAKEUP)) &&
1884 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1885 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
1887 ch->ch_tun.un_tty->ldisc.ops->write_wakeup)
1890 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1891 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1892 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1893 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
1895 (ch->ch_tun.un_tty->ldisc.ops->write_wakeup)(ch->ch_tun.un_tty);
1897 DGAP_LOCK(bd->bd_lock, lock_flags);
1898 DGAP_LOCK(ch->ch_lock, lock_flags2);
1900 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
1901 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
1905 if (ch->ch_pun.un_flags & UN_EMPTY) {
1906 ch->ch_pun.un_flags &= ~UN_EMPTY;
1907 if (ch->ch_pun.un_flags & UN_ISOPEN) {
1908 if ((ch->ch_pun.un_tty->flags &
1909 (1 << TTY_DO_WRITE_WAKEUP)) &&
1910 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1911 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
1913 ch->ch_pun.un_tty->ldisc.ops->write_wakeup)
1916 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1917 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1918 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
1919 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
1921 (ch->ch_pun.un_tty->ldisc.ops->write_wakeup)(ch->ch_pun.un_tty);
1923 DGAP_LOCK(bd->bd_lock, lock_flags);
1924 DGAP_LOCK(ch->ch_lock, lock_flags2);
1926 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
1927 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
1932 if (ch->ch_flags & CH_WEMPTY) {
1933 ch->ch_flags &= ~CH_WEMPTY;
1934 wake_up_interruptible(&ch->ch_flags_wait);
1938 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1941 tail = (tail + 4) & (EVMAX - EVSTART - 4);
1944 writew(tail, &(eaddr->ev_tail));
1945 DGAP_UNLOCK(bd->bd_lock, lock_flags);