Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2003 Digi International (www.digi.com) |
| 3 | * Scott H Kilau <Scott_Kilau at digi dot com> |
| 4 | * |
| 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) |
| 8 | * any later version. |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 9 | * |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 10 | * This program is distributed in the hope that it will be useful, |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 11 | * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the |
| 12 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 13 | * PURPOSE. See the GNU General Public License for more details. |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 14 | * |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 15 | */ |
| 16 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 17 | /* |
| 18 | * In the original out of kernel Digi dgap driver, firmware |
| 19 | * loading was done via user land to driver handshaking. |
| 20 | * |
| 21 | * For cards that support a concentrator (port expander), |
| 22 | * I believe the concentrator its self told the card which |
| 23 | * concentrator is actually attached and then that info |
| 24 | * was used to tell user land which concentrator firmware |
| 25 | * image was to be downloaded. I think even the BIOS or |
| 26 | * FEP images required could change with the connection |
| 27 | * of a particular concentrator. |
| 28 | * |
| 29 | * Since I have no access to any of these cards or |
| 30 | * concentrators, I cannot put the correct concentrator |
| 31 | * firmware file names into the firmware_info structure |
| 32 | * as is now done for the BIOS and FEP images. |
| 33 | * |
| 34 | * I think, but am not certain, that the cards supporting |
| 35 | * concentrators will function without them. So support |
| 36 | * of these cards has been left in this driver. |
| 37 | * |
| 38 | * In order to fully support those cards, they would |
| 39 | * either have to be acquired for dissection or maybe |
| 40 | * Digi International could provide some assistance. |
| 41 | */ |
| 42 | #undef DIGI_CONCENTRATORS_SUPPORTED |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 43 | |
| 44 | #include <linux/kernel.h> |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 45 | #include <linux/module.h> |
| 46 | #include <linux/pci.h> |
| 47 | #include <linux/delay.h> /* For udelay */ |
Geert Uytterhoeven | 351699d | 2013-08-29 22:53:25 +0200 | [diff] [blame] | 48 | #include <linux/slab.h> |
Mark Hounschell | 3d9dc5d | 2014-02-28 12:42:12 -0500 | [diff] [blame] | 49 | #include <linux/uaccess.h> |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 50 | #include <linux/sched.h> |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 51 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 52 | #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */ |
| 53 | #include <linux/ctype.h> |
| 54 | #include <linux/tty.h> |
| 55 | #include <linux/tty_flip.h> |
| 56 | #include <linux/serial_reg.h> |
Mark Hounschell | 3d9dc5d | 2014-02-28 12:42:12 -0500 | [diff] [blame] | 57 | #include <linux/io.h> /* For read[bwl]/write[bwl] */ |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 58 | |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 59 | #include <linux/string.h> |
| 60 | #include <linux/device.h> |
| 61 | #include <linux/kdev_t.h> |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 62 | #include <linux/firmware.h> |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 63 | |
Mark Hounschell | ffc1c1d | 2014-02-19 13:12:14 -0500 | [diff] [blame] | 64 | #include "dgap.h" |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 65 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 66 | MODULE_LICENSE("GPL"); |
| 67 | MODULE_AUTHOR("Digi International, http://www.digi.com"); |
| 68 | MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line"); |
| 69 | MODULE_SUPPORTED_DEVICE("dgap"); |
| 70 | |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 71 | static int dgap_start(void); |
| 72 | static void dgap_init_globals(void); |
| 73 | static int dgap_found_board(struct pci_dev *pdev, int id); |
| 74 | static void dgap_cleanup_board(struct board_t *brd); |
| 75 | static void dgap_poll_handler(ulong dummy); |
| 76 | static int dgap_init_pci(void); |
| 77 | static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); |
| 78 | static void dgap_remove_one(struct pci_dev *dev); |
| 79 | static int dgap_probe1(struct pci_dev *pdev, int card_type); |
| 80 | static int dgap_do_remap(struct board_t *brd); |
| 81 | static irqreturn_t dgap_intr(int irq, void *voidbrd); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 82 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 83 | static int dgap_tty_open(struct tty_struct *tty, struct file *file); |
| 84 | static void dgap_tty_close(struct tty_struct *tty, struct file *file); |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 85 | static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, |
| 86 | struct channel_t *ch); |
| 87 | static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, |
| 88 | unsigned long arg); |
| 89 | static int dgap_tty_digigeta(struct tty_struct *tty, |
| 90 | struct digi_t __user *retinfo); |
| 91 | static int dgap_tty_digiseta(struct tty_struct *tty, |
| 92 | struct digi_t __user *new_info); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 93 | static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo); |
| 94 | static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info); |
Mark Hounschell | 5e9d817 | 2014-02-28 12:42:11 -0500 | [diff] [blame] | 95 | static int dgap_tty_write_room(struct tty_struct *tty); |
| 96 | static int dgap_tty_chars_in_buffer(struct tty_struct *tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 97 | static void dgap_tty_start(struct tty_struct *tty); |
| 98 | static void dgap_tty_stop(struct tty_struct *tty); |
| 99 | static void dgap_tty_throttle(struct tty_struct *tty); |
| 100 | static void dgap_tty_unthrottle(struct tty_struct *tty); |
| 101 | static void dgap_tty_flush_chars(struct tty_struct *tty); |
| 102 | static void dgap_tty_flush_buffer(struct tty_struct *tty); |
| 103 | static void dgap_tty_hangup(struct tty_struct *tty); |
| 104 | static int dgap_wait_for_drain(struct tty_struct *tty); |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 105 | static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, |
| 106 | unsigned int __user *value); |
| 107 | static int dgap_get_modem_info(struct channel_t *ch, |
| 108 | unsigned int __user *value); |
| 109 | static int dgap_tty_digisetcustombaud(struct tty_struct *tty, |
| 110 | int __user *new_info); |
| 111 | static int dgap_tty_digigetcustombaud(struct tty_struct *tty, |
| 112 | int __user *retinfo); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 113 | static int dgap_tty_tiocmget(struct tty_struct *tty); |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 114 | static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set, |
| 115 | unsigned int clear); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 116 | static int dgap_tty_send_break(struct tty_struct *tty, int msec); |
| 117 | static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout); |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 118 | static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, |
| 119 | int count); |
| 120 | static void dgap_tty_set_termios(struct tty_struct *tty, |
| 121 | struct ktermios *old_termios); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 122 | static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c); |
| 123 | static void dgap_tty_send_xchar(struct tty_struct *tty, char ch); |
| 124 | |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 125 | static int dgap_tty_register(struct board_t *brd); |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 126 | static int dgap_tty_init(struct board_t *); |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 127 | static void dgap_tty_uninit(struct board_t *); |
| 128 | static void dgap_carrier(struct channel_t *ch); |
| 129 | static void dgap_input(struct channel_t *ch); |
Mark Hounschell | 4aeafa8 | 2014-02-19 13:12:04 -0500 | [diff] [blame] | 130 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 131 | /* |
| 132 | * Our function prototypes from dgap_fep5 |
| 133 | */ |
| 134 | static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds); |
| 135 | static int dgap_event(struct board_t *bd); |
| 136 | |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 137 | static void dgap_poll_tasklet(unsigned long data); |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 138 | static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1, |
| 139 | u8 byte2, uint ncmds); |
| 140 | static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds); |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 141 | static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt); |
| 142 | static int dgap_param(struct tty_struct *tty); |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 143 | static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, |
| 144 | unsigned char *fbuf, int *len); |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 145 | static uint dgap_get_custom_baud(struct channel_t *ch); |
| 146 | static void dgap_firmware_reset_port(struct channel_t *ch); |
| 147 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 148 | /* |
| 149 | * Function prototypes from dgap_parse.c. |
| 150 | */ |
| 151 | static int dgap_gettok(char **in, struct cnode *p); |
| 152 | static char *dgap_getword(char **in); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 153 | static struct cnode *dgap_newnode(int t); |
| 154 | static int dgap_checknode(struct cnode *p); |
| 155 | static void dgap_err(char *s); |
| 156 | |
Mark Hounschell | 30580a7 | 2014-02-19 13:12:05 -0500 | [diff] [blame] | 157 | /* |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 158 | * Function prototypes from dgap_sysfs.h |
| 159 | */ |
Mark Hounschell | 30580a7 | 2014-02-19 13:12:05 -0500 | [diff] [blame] | 160 | struct board_t; |
| 161 | struct channel_t; |
| 162 | struct un_t; |
| 163 | struct pci_driver; |
| 164 | struct class_device; |
| 165 | |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 166 | static void dgap_create_ports_sysfiles(struct board_t *bd); |
| 167 | static void dgap_remove_ports_sysfiles(struct board_t *bd); |
Mark Hounschell | 30580a7 | 2014-02-19 13:12:05 -0500 | [diff] [blame] | 168 | |
Mark Hounschell | 434b679 | 2014-03-06 13:57:55 -0500 | [diff] [blame] | 169 | static int dgap_create_driver_sysfiles(struct pci_driver *); |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 170 | static void dgap_remove_driver_sysfiles(struct pci_driver *); |
Mark Hounschell | 30580a7 | 2014-02-19 13:12:05 -0500 | [diff] [blame] | 171 | |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 172 | static void dgap_create_tty_sysfs(struct un_t *un, struct device *c); |
| 173 | static void dgap_remove_tty_sysfs(struct device *c); |
Mark Hounschell | 30580a7 | 2014-02-19 13:12:05 -0500 | [diff] [blame] | 174 | |
Mark Hounschell | 9e9b3bb | 2014-02-19 13:12:09 -0500 | [diff] [blame] | 175 | /* |
| 176 | * Function prototypes from dgap_parse.h |
| 177 | */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 178 | static int dgap_parsefile(char **in, int remove); |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 179 | static struct cnode *dgap_find_config(int type, int bus, int slot); |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 180 | static uint dgap_config_get_num_prts(struct board_t *bd); |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 181 | static char *dgap_create_config_string(struct board_t *bd, char *string); |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 182 | static uint dgap_config_get_useintr(struct board_t *bd); |
| 183 | static uint dgap_config_get_altpin(struct board_t *bd); |
| 184 | |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 185 | static int dgap_ms_sleep(ulong ms); |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 186 | static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len); |
| 187 | static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 188 | #ifdef DIGI_CONCENTRATORS_SUPPORTED |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 189 | static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 190 | #endif |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 191 | static int dgap_after_config_loaded(int board); |
| 192 | static int dgap_finalize_board_init(struct board_t *brd); |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 193 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 194 | static void dgap_get_vpd(struct board_t *brd); |
| 195 | static void dgap_do_reset_board(struct board_t *brd); |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 196 | static int dgap_test_bios(struct board_t *brd); |
| 197 | static int dgap_test_fep(struct board_t *brd); |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 198 | static int dgap_tty_register_ports(struct board_t *brd); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 199 | static int dgap_firmware_load(struct pci_dev *pdev, int card_type); |
Mark Hounschell | 9e9b3bb | 2014-02-19 13:12:09 -0500 | [diff] [blame] | 200 | |
Mark Hounschell | 01a8d25 | 2014-03-03 09:37:22 -0500 | [diff] [blame] | 201 | static void dgap_cleanup_module(void); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 202 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 203 | module_exit(dgap_cleanup_module); |
| 204 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 205 | /* |
| 206 | * File operations permitted on Control/Management major. |
| 207 | */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 208 | static const struct file_operations dgap_board_fops = { |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 209 | .owner = THIS_MODULE, |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 210 | }; |
| 211 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 212 | static uint dgap_numboards; |
| 213 | static struct board_t *dgap_board[MAXBOARDS]; |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 214 | static ulong dgap_poll_counter; |
| 215 | static char *dgap_config_buf; |
| 216 | static int dgap_driver_state = DRIVER_INITIALIZED; |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 217 | static wait_queue_head_t dgap_dl_wait; |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 218 | static int dgap_poll_tick = 20; /* Poll interval - 20 ms */ |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 219 | |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 220 | static struct class *dgap_class; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 221 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 222 | static struct board_t *dgap_boards_by_major[256]; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 223 | static uint dgap_count = 500; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 224 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 225 | /* |
| 226 | * Poller stuff |
| 227 | */ |
Mark Hounschell | 45c44dd | 2014-04-24 10:33:58 -0400 | [diff] [blame] | 228 | static DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */ |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 229 | static ulong dgap_poll_time; /* Time of next poll */ |
| 230 | static uint dgap_poll_stop; /* Used to tell poller to stop */ |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 231 | static struct timer_list dgap_poll_timer; |
| 232 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 233 | /* |
| 234 | SUPPORTED PRODUCTS |
| 235 | |
| 236 | Card Model Number of Ports Interface |
| 237 | ---------------------------------------------------------------- |
| 238 | Acceleport Xem 4 - 64 (EIA232 & EIA422) |
| 239 | Acceleport Xr 4 & 8 (EIA232) |
| 240 | Acceleport Xr 920 4 & 8 (EIA232) |
| 241 | Acceleport C/X 8 - 128 (EIA232) |
| 242 | Acceleport EPC/X 8 - 224 (EIA232) |
| 243 | Acceleport Xr/422 4 & 8 (EIA422) |
| 244 | Acceleport 2r/920 2 (EIA232) |
| 245 | Acceleport 4r/920 4 (EIA232) |
| 246 | Acceleport 8r/920 8 (EIA232) |
| 247 | |
| 248 | IBM 8-Port Asynchronous PCI Adapter (EIA232) |
| 249 | IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422) |
| 250 | */ |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 251 | |
| 252 | static struct pci_device_id dgap_pci_tbl[] = { |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 253 | { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
| 254 | { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 }, |
| 255 | { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 }, |
| 256 | { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 }, |
| 257 | { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 }, |
| 258 | { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 }, |
| 259 | { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 }, |
| 260 | { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 }, |
| 261 | { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 }, |
| 262 | { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 }, |
| 263 | { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 }, |
| 264 | { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 }, |
| 265 | { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 }, |
| 266 | { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 }, |
| 267 | { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 }, |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 268 | {0,} /* 0 terminated list. */ |
| 269 | }; |
| 270 | MODULE_DEVICE_TABLE(pci, dgap_pci_tbl); |
| 271 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 272 | /* |
| 273 | * A generic list of Product names, PCI Vendor ID, and PCI Device ID. |
| 274 | */ |
| 275 | struct board_id { |
| 276 | uint config_type; |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 277 | u8 *name; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 278 | uint maxports; |
| 279 | uint dpatype; |
| 280 | }; |
| 281 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 282 | static struct board_id dgap_ids[] = { |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 283 | { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) }, |
| 284 | { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) }, |
| 285 | { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) }, |
| 286 | { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) }, |
| 287 | { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 288 | { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 289 | { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 290 | { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 291 | { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 292 | { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 293 | { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 294 | { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 295 | { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 296 | { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 297 | { PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) }, |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 298 | {0,} /* 0 terminated list. */ |
| 299 | }; |
| 300 | |
| 301 | static struct pci_driver dgap_driver = { |
| 302 | .name = "dgap", |
| 303 | .probe = dgap_init_one, |
| 304 | .id_table = dgap_pci_tbl, |
| 305 | .remove = dgap_remove_one, |
| 306 | }; |
| 307 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 308 | struct firmware_info { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 309 | u8 *conf_name; /* dgap.conf */ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 310 | u8 *bios_name; /* BIOS filename */ |
| 311 | u8 *fep_name; /* FEP filename */ |
| 312 | u8 *con_name; /* Concentrator filename FIXME*/ |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 313 | int num; /* sequence number */ |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 314 | }; |
| 315 | |
| 316 | /* |
| 317 | * Firmware - BIOS, FEP, and CONC filenames |
| 318 | */ |
| 319 | static struct firmware_info fw_info[] = { |
Mark Hounschell | 8f5879c | 2014-04-24 10:41:44 -0400 | [diff] [blame] | 320 | { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 0 }, |
| 321 | { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 1 }, |
| 322 | { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 2 }, |
| 323 | { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", NULL, 3 }, |
| 324 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 4 }, |
| 325 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 5 }, |
| 326 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 6 }, |
| 327 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 7 }, |
| 328 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 8 }, |
| 329 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 9 }, |
| 330 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 10 }, |
| 331 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 11 }, |
| 332 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 12 }, |
| 333 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 13 }, |
| 334 | { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 14 }, |
| 335 | {NULL,} |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 336 | }; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 337 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 338 | /* |
| 339 | * Default transparent print information. |
| 340 | */ |
| 341 | static struct digi_t dgap_digi_init = { |
| 342 | .digi_flags = DIGI_COOK, /* Flags */ |
| 343 | .digi_maxcps = 100, /* Max CPS */ |
| 344 | .digi_maxchar = 50, /* Max chars in print queue */ |
| 345 | .digi_bufsize = 100, /* Printer buffer size */ |
| 346 | .digi_onlen = 4, /* size of printer on string */ |
| 347 | .digi_offlen = 4, /* size of printer off string */ |
| 348 | .digi_onstr = "\033[5i", /* ANSI printer on string ] */ |
| 349 | .digi_offstr = "\033[4i", /* ANSI printer off string ] */ |
| 350 | .digi_term = "ansi" /* default terminal type */ |
| 351 | }; |
| 352 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 353 | /* |
| 354 | * Define a local default termios struct. All ports will be created |
| 355 | * with this termios initially. |
| 356 | * |
| 357 | * This defines a raw port at 9600 baud, 8 data bits, no parity, |
| 358 | * 1 stop bit. |
| 359 | */ |
| 360 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 361 | static struct ktermios dgap_default_termios = { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 362 | .c_iflag = (DEFAULT_IFLAGS), /* iflags */ |
| 363 | .c_oflag = (DEFAULT_OFLAGS), /* oflags */ |
| 364 | .c_cflag = (DEFAULT_CFLAGS), /* cflags */ |
| 365 | .c_lflag = (DEFAULT_LFLAGS), /* lflags */ |
| 366 | .c_cc = INIT_C_CC, |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 367 | .c_line = 0, |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 368 | }; |
| 369 | |
| 370 | static const struct tty_operations dgap_tty_ops = { |
| 371 | .open = dgap_tty_open, |
| 372 | .close = dgap_tty_close, |
| 373 | .write = dgap_tty_write, |
| 374 | .write_room = dgap_tty_write_room, |
| 375 | .flush_buffer = dgap_tty_flush_buffer, |
| 376 | .chars_in_buffer = dgap_tty_chars_in_buffer, |
| 377 | .flush_chars = dgap_tty_flush_chars, |
| 378 | .ioctl = dgap_tty_ioctl, |
| 379 | .set_termios = dgap_tty_set_termios, |
| 380 | .stop = dgap_tty_stop, |
| 381 | .start = dgap_tty_start, |
| 382 | .throttle = dgap_tty_throttle, |
| 383 | .unthrottle = dgap_tty_unthrottle, |
| 384 | .hangup = dgap_tty_hangup, |
| 385 | .put_char = dgap_tty_put_char, |
| 386 | .tiocmget = dgap_tty_tiocmget, |
| 387 | .tiocmset = dgap_tty_tiocmset, |
| 388 | .break_ctl = dgap_tty_send_break, |
| 389 | .wait_until_sent = dgap_tty_wait_until_sent, |
| 390 | .send_xchar = dgap_tty_send_xchar |
| 391 | }; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 392 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 393 | /* |
| 394 | * Our needed internal static variables from dgap_parse.c |
| 395 | */ |
| 396 | static struct cnode dgap_head; |
| 397 | #define MAXCWORD 200 |
| 398 | static char dgap_cword[MAXCWORD]; |
| 399 | |
| 400 | struct toklist { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 401 | int token; |
| 402 | char *string; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 403 | }; |
| 404 | |
| 405 | static struct toklist dgap_tlist[] = { |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 406 | { BEGIN, "config_begin" }, |
| 407 | { END, "config_end" }, |
| 408 | { BOARD, "board" }, |
| 409 | { PCX, "Digi_AccelePort_C/X_PCI" }, |
| 410 | { PEPC, "Digi_AccelePort_EPC/X_PCI" }, |
| 411 | { PPCM, "Digi_AccelePort_Xem_PCI" }, |
| 412 | { APORT2_920P, "Digi_AccelePort_2r_920_PCI" }, |
| 413 | { APORT4_920P, "Digi_AccelePort_4r_920_PCI" }, |
| 414 | { APORT8_920P, "Digi_AccelePort_8r_920_PCI" }, |
| 415 | { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" }, |
| 416 | { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" }, |
| 417 | { IO, "io" }, |
| 418 | { PCIINFO, "pciinfo" }, |
| 419 | { LINE, "line" }, |
| 420 | { CONC, "conc" }, |
| 421 | { CONC, "concentrator" }, |
| 422 | { CX, "cx" }, |
| 423 | { CX, "ccon" }, |
| 424 | { EPC, "epccon" }, |
| 425 | { EPC, "epc" }, |
| 426 | { MOD, "module" }, |
| 427 | { ID, "id" }, |
| 428 | { STARTO, "start" }, |
| 429 | { SPEED, "speed" }, |
| 430 | { CABLE, "cable" }, |
| 431 | { CONNECT, "connect" }, |
| 432 | { METHOD, "method" }, |
| 433 | { STATUS, "status" }, |
| 434 | { CUSTOM, "Custom" }, |
| 435 | { BASIC, "Basic" }, |
| 436 | { MEM, "mem" }, |
| 437 | { MEM, "memory" }, |
| 438 | { PORTS, "ports" }, |
| 439 | { MODEM, "modem" }, |
| 440 | { NPORTS, "nports" }, |
| 441 | { TTYN, "ttyname" }, |
| 442 | { CU, "cuname" }, |
| 443 | { PRINT, "prname" }, |
| 444 | { CMAJOR, "major" }, |
| 445 | { ALTPIN, "altpin" }, |
| 446 | { USEINTR, "useintr" }, |
| 447 | { TTSIZ, "ttysize" }, |
| 448 | { CHSIZ, "chsize" }, |
| 449 | { BSSIZ, "boardsize" }, |
| 450 | { UNTSIZ, "schedsize" }, |
| 451 | { F2SIZ, "f2200size" }, |
| 452 | { VPSIZ, "vpixsize" }, |
| 453 | { 0, NULL } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 454 | }; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 455 | |
| 456 | /************************************************************************ |
| 457 | * |
| 458 | * Driver load/unload functions |
| 459 | * |
| 460 | ************************************************************************/ |
| 461 | |
| 462 | /* |
| 463 | * init_module() |
| 464 | * |
| 465 | * Module load. This is where it all starts. |
| 466 | */ |
Mark Hounschell | 01a8d25 | 2014-03-03 09:37:22 -0500 | [diff] [blame] | 467 | static int dgap_init_module(void) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 468 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 469 | int rc; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 470 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 471 | pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 472 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 473 | rc = dgap_start(); |
Mark Hounschell | 002de0b | 2014-03-06 15:25:19 -0500 | [diff] [blame] | 474 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 475 | return rc; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 476 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 477 | rc = dgap_init_pci(); |
Mark Hounschell | 002de0b | 2014-03-06 15:25:19 -0500 | [diff] [blame] | 478 | if (rc) |
| 479 | goto err_cleanup; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 480 | |
Mark Hounschell | 002de0b | 2014-03-06 15:25:19 -0500 | [diff] [blame] | 481 | rc = dgap_create_driver_sysfiles(&dgap_driver); |
| 482 | if (rc) |
| 483 | goto err_cleanup; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 484 | |
Mark Hounschell | 002de0b | 2014-03-06 15:25:19 -0500 | [diff] [blame] | 485 | dgap_driver_state = DRIVER_READY; |
| 486 | |
| 487 | return 0; |
| 488 | |
| 489 | err_cleanup: |
| 490 | |
| 491 | dgap_cleanup_module(); |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 492 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 493 | return rc; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 494 | } |
Mark Hounschell | 01a8d25 | 2014-03-03 09:37:22 -0500 | [diff] [blame] | 495 | module_init(dgap_init_module); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 496 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 497 | /* |
| 498 | * Start of driver. |
| 499 | */ |
| 500 | static int dgap_start(void) |
| 501 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 502 | int rc; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 503 | unsigned long flags; |
Alexey Khoroshilov | 0669e5f | 2014-03-09 01:01:34 +0400 | [diff] [blame] | 504 | struct device *device; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 505 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 506 | /* |
| 507 | * make sure that the globals are |
| 508 | * init'd before we do anything else |
| 509 | */ |
| 510 | dgap_init_globals(); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 511 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 512 | dgap_numboards = 0; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 513 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 514 | pr_info("For the tools package please visit http://www.digi.com\n"); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 515 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 516 | /* |
| 517 | * Register our base character device into the kernel. |
| 518 | */ |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 519 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 520 | /* |
| 521 | * Register management/dpa devices |
| 522 | */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 523 | rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &dgap_board_fops); |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 524 | if (rc < 0) |
| 525 | return rc; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 526 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 527 | dgap_class = class_create(THIS_MODULE, "dgap_mgmt"); |
Alexey Khoroshilov | 0669e5f | 2014-03-09 01:01:34 +0400 | [diff] [blame] | 528 | if (IS_ERR(dgap_class)) { |
| 529 | rc = PTR_ERR(dgap_class); |
| 530 | goto failed_class; |
| 531 | } |
| 532 | |
| 533 | device = device_create(dgap_class, NULL, |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 534 | MKDEV(DIGI_DGAP_MAJOR, 0), |
| 535 | NULL, "dgap_mgmt"); |
Alexey Khoroshilov | 0669e5f | 2014-03-09 01:01:34 +0400 | [diff] [blame] | 536 | if (IS_ERR(device)) { |
| 537 | rc = PTR_ERR(device); |
| 538 | goto failed_device; |
| 539 | } |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 540 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 541 | /* Start the poller */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 542 | spin_lock_irqsave(&dgap_poll_lock, flags); |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 543 | init_timer(&dgap_poll_timer); |
| 544 | dgap_poll_timer.function = dgap_poll_handler; |
| 545 | dgap_poll_timer.data = 0; |
| 546 | dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick); |
| 547 | dgap_poll_timer.expires = dgap_poll_time; |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 548 | spin_unlock_irqrestore(&dgap_poll_lock, flags); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 549 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 550 | add_timer(&dgap_poll_timer); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 551 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 552 | return rc; |
Alexey Khoroshilov | 0669e5f | 2014-03-09 01:01:34 +0400 | [diff] [blame] | 553 | |
| 554 | failed_device: |
| 555 | class_destroy(dgap_class); |
| 556 | failed_class: |
| 557 | unregister_chrdev(DIGI_DGAP_MAJOR, "dgap"); |
| 558 | return rc; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 559 | } |
| 560 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 561 | /* |
| 562 | * Register pci driver, and return how many boards we have. |
| 563 | */ |
| 564 | static int dgap_init_pci(void) |
| 565 | { |
| 566 | return pci_register_driver(&dgap_driver); |
| 567 | } |
| 568 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 569 | static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 570 | { |
| 571 | int rc; |
| 572 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 573 | if (dgap_numboards >= MAXBOARDS) |
Mark Hounschell | acfd4aa | 2014-04-25 13:10:20 -0400 | [diff] [blame] | 574 | return -EPERM; |
| 575 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 576 | rc = pci_enable_device(pdev); |
Mark Hounschell | 6a82524 | 2014-04-25 14:19:42 -0400 | [diff] [blame] | 577 | if (rc) |
| 578 | return -EIO; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 579 | |
Mark Hounschell | 6a82524 | 2014-04-25 14:19:42 -0400 | [diff] [blame] | 580 | rc = dgap_probe1(pdev, ent->driver_data); |
| 581 | if (rc) |
| 582 | return rc; |
| 583 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 584 | dgap_numboards++; |
Mark Hounschell | 6a82524 | 2014-04-25 14:19:42 -0400 | [diff] [blame] | 585 | return dgap_firmware_load(pdev, ent->driver_data); |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 586 | } |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 587 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 588 | static int dgap_probe1(struct pci_dev *pdev, int card_type) |
| 589 | { |
| 590 | return dgap_found_board(pdev, card_type); |
| 591 | } |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 592 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 593 | static void dgap_remove_one(struct pci_dev *dev) |
| 594 | { |
| 595 | /* Do Nothing */ |
| 596 | } |
| 597 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 598 | /* |
| 599 | * dgap_cleanup_module() |
| 600 | * |
| 601 | * Module unload. This is where it all ends. |
| 602 | */ |
Mark Hounschell | 01a8d25 | 2014-03-03 09:37:22 -0500 | [diff] [blame] | 603 | static void dgap_cleanup_module(void) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 604 | { |
| 605 | int i; |
| 606 | ulong lock_flags; |
| 607 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 608 | spin_lock_irqsave(&dgap_poll_lock, lock_flags); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 609 | dgap_poll_stop = 1; |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 610 | spin_unlock_irqrestore(&dgap_poll_lock, lock_flags); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 611 | |
| 612 | /* Turn off poller right away. */ |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 613 | del_timer_sync(&dgap_poll_timer); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 614 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 615 | dgap_remove_driver_sysfiles(&dgap_driver); |
| 616 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 617 | device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0)); |
| 618 | class_destroy(dgap_class); |
| 619 | unregister_chrdev(DIGI_DGAP_MAJOR, "dgap"); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 620 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 621 | for (i = 0; i < dgap_numboards; ++i) { |
| 622 | dgap_remove_ports_sysfiles(dgap_board[i]); |
| 623 | dgap_tty_uninit(dgap_board[i]); |
| 624 | dgap_cleanup_board(dgap_board[i]); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 625 | } |
| 626 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 627 | if (dgap_numboards) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 628 | pci_unregister_driver(&dgap_driver); |
| 629 | } |
| 630 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 631 | /* |
| 632 | * dgap_cleanup_board() |
| 633 | * |
| 634 | * Free all the memory associated with a board |
| 635 | */ |
| 636 | static void dgap_cleanup_board(struct board_t *brd) |
| 637 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 638 | int i; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 639 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 640 | if (!brd || brd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 641 | return; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 642 | |
| 643 | if (brd->intr_used && brd->irq) |
| 644 | free_irq(brd->irq, brd); |
| 645 | |
| 646 | tasklet_kill(&brd->helper_tasklet); |
| 647 | |
| 648 | if (brd->re_map_port) { |
| 649 | release_mem_region(brd->membase + 0x200000, 0x200000); |
| 650 | iounmap(brd->re_map_port); |
| 651 | brd->re_map_port = NULL; |
| 652 | } |
| 653 | |
| 654 | if (brd->re_map_membase) { |
| 655 | release_mem_region(brd->membase, 0x200000); |
| 656 | iounmap(brd->re_map_membase); |
| 657 | brd->re_map_membase = NULL; |
| 658 | } |
| 659 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 660 | /* Free all allocated channels structs */ |
Mark Hounschell | 9b073ac | 2014-03-03 13:45:42 -0500 | [diff] [blame] | 661 | for (i = 0; i < MAXPORTS ; i++) |
| 662 | kfree(brd->channels[i]); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 663 | |
Lidza Louina | 57a4219 | 2013-09-23 18:47:12 -0400 | [diff] [blame] | 664 | kfree(brd->flipbuf); |
| 665 | kfree(brd->flipflagbuf); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 666 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 667 | dgap_board[brd->boardnum] = NULL; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 668 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 669 | kfree(brd); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 670 | } |
| 671 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 672 | /* |
| 673 | * dgap_found_board() |
| 674 | * |
| 675 | * A board has been found, init it. |
| 676 | */ |
| 677 | static int dgap_found_board(struct pci_dev *pdev, int id) |
| 678 | { |
| 679 | struct board_t *brd; |
| 680 | unsigned int pci_irq; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 681 | int i; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 682 | |
| 683 | /* get the board structure and prep it */ |
Mark Hounschell | 9b073ac | 2014-03-03 13:45:42 -0500 | [diff] [blame] | 684 | brd = kzalloc(sizeof(struct board_t), GFP_KERNEL); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 685 | if (!brd) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 686 | return -ENOMEM; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 687 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 688 | dgap_board[dgap_numboards] = brd; |
Mark Hounschell | 9b073ac | 2014-03-03 13:45:42 -0500 | [diff] [blame] | 689 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 690 | /* store the info for the board we've found */ |
| 691 | brd->magic = DGAP_BOARD_MAGIC; |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 692 | brd->boardnum = dgap_numboards; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 693 | brd->firstminor = 0; |
| 694 | brd->vendor = dgap_pci_tbl[id].vendor; |
| 695 | brd->device = dgap_pci_tbl[id].device; |
| 696 | brd->pdev = pdev; |
| 697 | brd->pci_bus = pdev->bus->number; |
| 698 | brd->pci_slot = PCI_SLOT(pdev->devfn); |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 699 | brd->name = dgap_ids[id].name; |
| 700 | brd->maxports = dgap_ids[id].maxports; |
| 701 | brd->type = dgap_ids[id].config_type; |
| 702 | brd->dpatype = dgap_ids[id].dpatype; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 703 | brd->dpastatus = BD_NOFEP; |
| 704 | init_waitqueue_head(&brd->state_wait); |
| 705 | |
Mark Hounschell | 211568d | 2014-03-11 10:11:43 -0400 | [diff] [blame] | 706 | spin_lock_init(&brd->bd_lock); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 707 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 708 | brd->runwait = 0; |
| 709 | brd->inhibit_poller = FALSE; |
| 710 | brd->wait_for_bios = 0; |
| 711 | brd->wait_for_fep = 0; |
| 712 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 713 | for (i = 0; i < MAXPORTS; i++) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 714 | brd->channels[i] = NULL; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 715 | |
| 716 | /* store which card & revision we have */ |
| 717 | pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor); |
| 718 | pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice); |
| 719 | pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev); |
| 720 | |
| 721 | pci_irq = pdev->irq; |
| 722 | brd->irq = pci_irq; |
| 723 | |
| 724 | /* get the PCI Base Address Registers */ |
| 725 | |
| 726 | /* Xr Jupiter and EPC use BAR 2 */ |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 727 | if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) { |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 728 | brd->membase = pci_resource_start(pdev, 2); |
| 729 | brd->membase_end = pci_resource_end(pdev, 2); |
| 730 | } |
| 731 | /* Everyone else uses BAR 0 */ |
| 732 | else { |
| 733 | brd->membase = pci_resource_start(pdev, 0); |
| 734 | brd->membase_end = pci_resource_end(pdev, 0); |
| 735 | } |
| 736 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 737 | if (!brd->membase) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 738 | return -ENODEV; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 739 | |
| 740 | if (brd->membase & 1) |
| 741 | brd->membase &= ~3; |
| 742 | else |
| 743 | brd->membase &= ~15; |
| 744 | |
| 745 | /* |
| 746 | * On the PCI boards, there is no IO space allocated |
| 747 | * The I/O registers will be in the first 3 bytes of the |
| 748 | * upper 2MB of the 4MB memory space. The board memory |
| 749 | * will be mapped into the low 2MB of the 4MB memory space |
| 750 | */ |
| 751 | brd->port = brd->membase + PCI_IO_OFFSET; |
| 752 | brd->port_end = brd->port + PCI_IO_SIZE; |
| 753 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 754 | /* |
| 755 | * Special initialization for non-PLX boards |
| 756 | */ |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 757 | if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) { |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 758 | unsigned short cmd; |
| 759 | |
| 760 | pci_write_config_byte(pdev, 0x40, 0); |
| 761 | pci_write_config_byte(pdev, 0x46, 0); |
| 762 | |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 763 | /* Limit burst length to 2 doubleword transactions */ |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 764 | pci_write_config_byte(pdev, 0x42, 1); |
| 765 | |
| 766 | /* |
| 767 | * Enable IO and mem if not already done. |
| 768 | * This was needed for support on Itanium. |
| 769 | */ |
| 770 | pci_read_config_word(pdev, PCI_COMMAND, &cmd); |
| 771 | cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY); |
| 772 | pci_write_config_word(pdev, PCI_COMMAND, cmd); |
| 773 | } |
| 774 | |
| 775 | /* init our poll helper tasklet */ |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 776 | tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet, |
| 777 | (unsigned long) brd); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 778 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 779 | i = dgap_do_remap(brd); |
| 780 | if (i) |
| 781 | brd->state = BOARD_FAILED; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 782 | |
Mark Hounschell | 20fe4ae | 2014-03-25 16:38:17 -0400 | [diff] [blame] | 783 | pr_info("dgap: board %d: %s (rev %d), irq %ld\n", |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 784 | dgap_numboards, brd->name, brd->rev, brd->irq); |
Mark Hounschell | c0c31b9 | 2014-03-12 12:50:56 -0400 | [diff] [blame] | 785 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 786 | return 0; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 790 | static int dgap_finalize_board_init(struct board_t *brd) |
| 791 | { |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 792 | int rc; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 793 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 794 | if (!brd || brd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 795 | return -ENODEV; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 796 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 797 | brd->use_interrupts = dgap_config_get_useintr(brd); |
| 798 | |
| 799 | /* |
| 800 | * Set up our interrupt handler if we are set to do interrupts. |
| 801 | */ |
| 802 | if (brd->use_interrupts && brd->irq) { |
| 803 | |
| 804 | rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd); |
| 805 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 806 | if (rc) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 807 | brd->intr_used = 0; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 808 | else |
| 809 | brd->intr_used = 1; |
| 810 | } else { |
| 811 | brd->intr_used = 0; |
| 812 | } |
| 813 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 814 | return 0; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 815 | } |
| 816 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 817 | static int dgap_firmware_load(struct pci_dev *pdev, int card_type) |
| 818 | { |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 819 | struct board_t *brd = dgap_board[dgap_numboards - 1]; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 820 | const struct firmware *fw; |
Mark Hounschell | 23aa2ad | 2014-04-23 10:33:45 -0400 | [diff] [blame] | 821 | char *tmp_ptr; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 822 | int ret; |
| 823 | |
| 824 | dgap_get_vpd(brd); |
| 825 | dgap_do_reset_board(brd); |
| 826 | |
Mark Hounschell | 9e84401 | 2014-03-25 16:38:14 -0400 | [diff] [blame] | 827 | if ((fw_info[card_type].conf_name) && !dgap_config_buf) { |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 828 | ret = request_firmware(&fw, fw_info[card_type].conf_name, |
| 829 | &pdev->dev); |
| 830 | if (ret) { |
| 831 | pr_err("dgap: config file %s not found\n", |
| 832 | fw_info[card_type].conf_name); |
| 833 | return ret; |
| 834 | } |
Mark Hounschell | 9e84401 | 2014-03-25 16:38:14 -0400 | [diff] [blame] | 835 | |
Mark Hounschell | 077c28f | 2014-04-23 10:33:44 -0400 | [diff] [blame] | 836 | dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 837 | if (!dgap_config_buf) { |
Mark Hounschell | 9e84401 | 2014-03-25 16:38:14 -0400 | [diff] [blame] | 838 | release_firmware(fw); |
| 839 | return -ENOMEM; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | memcpy(dgap_config_buf, fw->data, fw->size); |
| 843 | release_firmware(fw); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 844 | |
Mark Hounschell | 23aa2ad | 2014-04-23 10:33:45 -0400 | [diff] [blame] | 845 | /* |
| 846 | * preserve dgap_config_buf |
| 847 | * as dgap_parsefile would |
| 848 | * otherwise alter it. |
| 849 | */ |
| 850 | tmp_ptr = dgap_config_buf; |
| 851 | |
| 852 | if (dgap_parsefile(&tmp_ptr, TRUE) != 0) { |
Mark Hounschell | 9e84401 | 2014-03-25 16:38:14 -0400 | [diff] [blame] | 853 | kfree(dgap_config_buf); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 854 | return -EINVAL; |
Mark Hounschell | 9e84401 | 2014-03-25 16:38:14 -0400 | [diff] [blame] | 855 | } |
| 856 | kfree(dgap_config_buf); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | ret = dgap_after_config_loaded(brd->boardnum); |
| 860 | if (ret) |
| 861 | return ret; |
| 862 | /* |
| 863 | * Match this board to a config the user created for us. |
| 864 | */ |
| 865 | brd->bd_config = |
| 866 | dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot); |
| 867 | |
| 868 | /* |
| 869 | * Because the 4 port Xr products share the same PCI ID |
| 870 | * as the 8 port Xr products, if we receive a NULL config |
| 871 | * back, and this is a PAPORT8 board, retry with a |
| 872 | * PAPORT4 attempt as well. |
| 873 | */ |
| 874 | if (brd->type == PAPORT8 && !brd->bd_config) |
| 875 | brd->bd_config = |
| 876 | dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot); |
| 877 | |
| 878 | if (!brd->bd_config) { |
| 879 | pr_err("dgap: No valid configuration found\n"); |
| 880 | return -EINVAL; |
| 881 | } |
| 882 | |
Mark Hounschell | 7496e05 | 2014-04-25 13:10:18 -0400 | [diff] [blame] | 883 | ret = dgap_tty_register(brd); |
| 884 | if (ret) |
| 885 | return ret; |
| 886 | |
| 887 | ret = dgap_finalize_board_init(brd); |
| 888 | if (ret) |
| 889 | return ret; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 890 | |
| 891 | if (fw_info[card_type].bios_name) { |
| 892 | ret = request_firmware(&fw, fw_info[card_type].bios_name, |
| 893 | &pdev->dev); |
| 894 | if (ret) { |
| 895 | pr_err("dgap: bios file %s not found\n", |
| 896 | fw_info[card_type].bios_name); |
| 897 | return ret; |
| 898 | } |
Masood Mehmood | fd54889 | 2014-03-18 13:40:14 -0700 | [diff] [blame] | 899 | dgap_do_bios_load(brd, fw->data, fw->size); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 900 | release_firmware(fw); |
| 901 | |
| 902 | /* Wait for BIOS to test board... */ |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 903 | ret = dgap_test_bios(brd); |
| 904 | if (ret) |
| 905 | return ret; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | if (fw_info[card_type].fep_name) { |
| 909 | ret = request_firmware(&fw, fw_info[card_type].fep_name, |
| 910 | &pdev->dev); |
| 911 | if (ret) { |
| 912 | pr_err("dgap: fep file %s not found\n", |
| 913 | fw_info[card_type].fep_name); |
| 914 | return ret; |
| 915 | } |
Masood Mehmood | fd54889 | 2014-03-18 13:40:14 -0700 | [diff] [blame] | 916 | dgap_do_fep_load(brd, fw->data, fw->size); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 917 | release_firmware(fw); |
| 918 | |
| 919 | /* Wait for FEP to load on board... */ |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 920 | ret = dgap_test_fep(brd); |
| 921 | if (ret) |
| 922 | return ret; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | #ifdef DIGI_CONCENTRATORS_SUPPORTED |
| 926 | /* |
| 927 | * If this is a CX or EPCX, we need to see if the firmware |
| 928 | * is requesting a concentrator image from us. |
| 929 | */ |
| 930 | if ((bd->type == PCX) || (bd->type == PEPC)) { |
| 931 | chk_addr = (u16 *) (vaddr + DOWNREQ); |
| 932 | /* Nonzero if FEP is requesting concentrator image. */ |
| 933 | check = readw(chk_addr); |
| 934 | vaddr = brd->re_map_membase; |
| 935 | } |
| 936 | |
| 937 | if (fw_info[card_type].con_name && check && vaddr) { |
| 938 | ret = request_firmware(&fw, fw_info[card_type].con_name, |
| 939 | &pdev->dev); |
| 940 | if (ret) { |
| 941 | pr_err("dgap: conc file %s not found\n", |
| 942 | fw_info[card_type].con_name); |
| 943 | return ret; |
| 944 | } |
| 945 | /* Put concentrator firmware loading code here */ |
| 946 | offset = readw((u16 *) (vaddr + DOWNREQ)); |
| 947 | memcpy_toio(offset, fw->data, fw->size); |
| 948 | |
| 949 | dgap_do_conc_load(brd, (char *)fw->data, fw->size) |
| 950 | release_firmware(fw); |
| 951 | } |
| 952 | #endif |
| 953 | /* |
| 954 | * Do tty device initialization. |
| 955 | */ |
| 956 | ret = dgap_tty_init(brd); |
| 957 | if (ret < 0) { |
| 958 | dgap_tty_uninit(brd); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 959 | return ret; |
| 960 | } |
| 961 | |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 962 | ret = dgap_tty_register_ports(brd); |
| 963 | if (ret) |
| 964 | return ret; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 965 | |
| 966 | brd->state = BOARD_READY; |
| 967 | brd->dpastatus = BD_RUNNING; |
| 968 | |
| 969 | return 0; |
| 970 | } |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 971 | |
| 972 | /* |
| 973 | * Remap PCI memory. |
| 974 | */ |
| 975 | static int dgap_do_remap(struct board_t *brd) |
| 976 | { |
| 977 | if (!brd || brd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 978 | return -EIO; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 979 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 980 | if (!request_mem_region(brd->membase, 0x200000, "dgap")) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 981 | return -ENOMEM; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 982 | |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 983 | if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, |
| 984 | "dgap")) { |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 985 | release_mem_region(brd->membase, 0x200000); |
| 986 | return -ENOMEM; |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 987 | } |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 988 | |
| 989 | brd->re_map_membase = ioremap(brd->membase, 0x200000); |
| 990 | if (!brd->re_map_membase) { |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 991 | release_mem_region(brd->membase, 0x200000); |
| 992 | release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000); |
| 993 | return -ENOMEM; |
| 994 | } |
| 995 | |
| 996 | brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000); |
| 997 | if (!brd->re_map_port) { |
| 998 | release_mem_region(brd->membase, 0x200000); |
| 999 | release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000); |
| 1000 | iounmap(brd->re_map_membase); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1001 | return -ENOMEM; |
| 1002 | } |
| 1003 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1004 | return 0; |
| 1005 | } |
| 1006 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1007 | /***************************************************************************** |
| 1008 | * |
| 1009 | * Function: |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 1010 | * |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1011 | * dgap_poll_handler |
| 1012 | * |
| 1013 | * Author: |
| 1014 | * |
| 1015 | * Scott H Kilau |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 1016 | * |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1017 | * Parameters: |
| 1018 | * |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 1019 | * dummy -- ignored |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1020 | * |
| 1021 | * Return Values: |
| 1022 | * |
| 1023 | * none |
| 1024 | * |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 1025 | * Description: |
| 1026 | * |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1027 | * As each timer expires, it determines (a) whether the "transmit" |
| 1028 | * waiter needs to be woken up, and (b) whether the poller needs to |
| 1029 | * be rescheduled. |
| 1030 | * |
| 1031 | ******************************************************************************/ |
| 1032 | |
| 1033 | static void dgap_poll_handler(ulong dummy) |
| 1034 | { |
| 1035 | int i; |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 1036 | struct board_t *brd; |
| 1037 | unsigned long lock_flags; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1038 | ulong new_time; |
| 1039 | |
| 1040 | dgap_poll_counter++; |
| 1041 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1042 | /* |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1043 | * Do not start the board state machine until |
| 1044 | * driver tells us its up and running, and has |
| 1045 | * everything it needs. |
| 1046 | */ |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 1047 | if (dgap_driver_state != DRIVER_READY) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1048 | goto schedule_poller; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1049 | |
| 1050 | /* |
| 1051 | * If we have just 1 board, or the system is not SMP, |
| 1052 | * then use the typical old style poller. |
| 1053 | * Otherwise, use our new tasklet based poller, which should |
| 1054 | * speed things up for multiple boards. |
| 1055 | */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1056 | if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) { |
| 1057 | for (i = 0; i < dgap_numboards; i++) { |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1058 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1059 | brd = dgap_board[i]; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1060 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1061 | if (brd->state == BOARD_FAILED) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1062 | continue; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1063 | if (!brd->intr_running) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1064 | /* Call the real board poller directly */ |
| 1065 | dgap_poll_tasklet((unsigned long) brd); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1066 | } |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1067 | } else { |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1068 | /* |
| 1069 | * Go thru each board, kicking off a |
| 1070 | * tasklet for each if needed |
| 1071 | */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1072 | for (i = 0; i < dgap_numboards; i++) { |
| 1073 | brd = dgap_board[i]; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1074 | |
| 1075 | /* |
| 1076 | * Attempt to grab the board lock. |
| 1077 | * |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1078 | * If we can't get it, no big deal, the next poll |
| 1079 | * will get it. Basically, I just really don't want |
| 1080 | * to spin in here, because I want to kick off my |
| 1081 | * tasklets as fast as I can, and then get out the |
| 1082 | * poller. |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1083 | */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1084 | if (!spin_trylock(&brd->bd_lock)) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1085 | continue; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1086 | |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1087 | /* |
| 1088 | * If board is in a failed state, don't bother |
| 1089 | * scheduling a tasklet |
| 1090 | */ |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1091 | if (brd->state == BOARD_FAILED) { |
| 1092 | spin_unlock(&brd->bd_lock); |
| 1093 | continue; |
| 1094 | } |
| 1095 | |
| 1096 | /* Schedule a poll helper task */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1097 | if (!brd->intr_running) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1098 | tasklet_schedule(&brd->helper_tasklet); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1099 | |
| 1100 | /* |
| 1101 | * Can't do DGAP_UNLOCK here, as we don't have |
| 1102 | * lock_flags because we did a trylock above. |
| 1103 | */ |
| 1104 | spin_unlock(&brd->bd_lock); |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | schedule_poller: |
| 1109 | |
| 1110 | /* |
| 1111 | * Schedule ourself back at the nominal wakeup interval. |
| 1112 | */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1113 | spin_lock_irqsave(&dgap_poll_lock, lock_flags); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1114 | dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick); |
| 1115 | |
| 1116 | new_time = dgap_poll_time - jiffies; |
| 1117 | |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1118 | if ((ulong) new_time >= 2 * dgap_poll_tick) { |
| 1119 | dgap_poll_time = |
| 1120 | jiffies + dgap_jiffies_from_ms(dgap_poll_tick); |
| 1121 | } |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1122 | |
| 1123 | dgap_poll_timer.function = dgap_poll_handler; |
| 1124 | dgap_poll_timer.data = 0; |
| 1125 | dgap_poll_timer.expires = dgap_poll_time; |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1126 | spin_unlock_irqrestore(&dgap_poll_lock, lock_flags); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1127 | |
| 1128 | if (!dgap_poll_stop) |
| 1129 | add_timer(&dgap_poll_timer); |
| 1130 | } |
| 1131 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1132 | /* |
| 1133 | * dgap_intr() |
| 1134 | * |
| 1135 | * Driver interrupt handler. |
| 1136 | */ |
| 1137 | static irqreturn_t dgap_intr(int irq, void *voidbrd) |
| 1138 | { |
| 1139 | struct board_t *brd = (struct board_t *) voidbrd; |
| 1140 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 1141 | if (!brd) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1142 | return IRQ_NONE; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1143 | |
| 1144 | /* |
| 1145 | * Check to make sure its for us. |
| 1146 | */ |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 1147 | if (brd->magic != DGAP_BOARD_MAGIC) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1148 | return IRQ_NONE; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1149 | |
| 1150 | brd->intr_count++; |
| 1151 | |
| 1152 | /* |
| 1153 | * Schedule tasklet to run at a better time. |
| 1154 | */ |
| 1155 | tasklet_schedule(&brd->helper_tasklet); |
| 1156 | return IRQ_HANDLED; |
| 1157 | } |
| 1158 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1159 | /* |
| 1160 | * dgap_init_globals() |
| 1161 | * |
| 1162 | * This is where we initialize the globals from the static insmod |
| 1163 | * configuration variables. These are declared near the head of |
| 1164 | * this file. |
| 1165 | */ |
| 1166 | static void dgap_init_globals(void) |
| 1167 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 1168 | int i; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1169 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1170 | for (i = 0; i < MAXBOARDS; i++) |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1171 | dgap_board[i] = NULL; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1172 | |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 1173 | init_timer(&dgap_poll_timer); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1174 | |
| 1175 | init_waitqueue_head(&dgap_dl_wait); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1176 | } |
| 1177 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1178 | /************************************************************************ |
| 1179 | * |
| 1180 | * Utility functions |
| 1181 | * |
| 1182 | ************************************************************************/ |
| 1183 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1184 | /* |
| 1185 | * dgap_ms_sleep() |
| 1186 | * |
| 1187 | * Put the driver to sleep for x ms's |
| 1188 | * |
| 1189 | * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal. |
| 1190 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 1191 | static int dgap_ms_sleep(ulong ms) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1192 | { |
| 1193 | current->state = TASK_INTERRUPTIBLE; |
| 1194 | schedule_timeout((ms * HZ) / 1000); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 1195 | return signal_pending(current); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1196 | } |
| 1197 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1198 | /************************************************************************ |
| 1199 | * |
| 1200 | * TTY Initialization/Cleanup Functions |
| 1201 | * |
| 1202 | ************************************************************************/ |
| 1203 | |
| 1204 | /* |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1205 | * dgap_tty_register() |
| 1206 | * |
| 1207 | * Init the tty subsystem for this board. |
| 1208 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 1209 | static int dgap_tty_register(struct board_t *brd) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1210 | { |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1211 | int rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1212 | |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1213 | brd->serial_driver = tty_alloc_driver(MAXPORTS, 0); |
| 1214 | if (IS_ERR(brd->serial_driver)) |
| 1215 | return PTR_ERR(brd->serial_driver); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1216 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1217 | snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_", |
| 1218 | brd->boardnum); |
| 1219 | brd->serial_driver->name = brd->serial_name; |
| 1220 | brd->serial_driver->name_base = 0; |
| 1221 | brd->serial_driver->major = 0; |
| 1222 | brd->serial_driver->minor_start = 0; |
| 1223 | brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL; |
| 1224 | brd->serial_driver->subtype = SERIAL_TYPE_NORMAL; |
| 1225 | brd->serial_driver->init_termios = dgap_default_termios; |
| 1226 | brd->serial_driver->driver_name = DRVSTR; |
| 1227 | brd->serial_driver->flags = (TTY_DRIVER_REAL_RAW | |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1228 | TTY_DRIVER_DYNAMIC_DEV | |
| 1229 | TTY_DRIVER_HARDWARE_BREAK); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1230 | |
| 1231 | /* The kernel wants space to store pointers to tty_structs */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1232 | brd->serial_driver->ttys = |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1233 | kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL); |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1234 | if (!brd->serial_driver->ttys) { |
| 1235 | rc = -ENOMEM; |
| 1236 | goto free_serial_drv; |
| 1237 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1238 | |
| 1239 | /* |
| 1240 | * Entry points for driver. Called by the kernel from |
| 1241 | * tty_io.c and n_tty.c. |
| 1242 | */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1243 | tty_set_operations(brd->serial_driver, &dgap_tty_ops); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1244 | |
| 1245 | /* |
| 1246 | * If we're doing transparent print, we have to do all of the above |
| 1247 | * again, separately so we don't get the LD confused about what major |
| 1248 | * we are when we get into the dgap_tty_open() routine. |
| 1249 | */ |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1250 | brd->print_driver = tty_alloc_driver(MAXPORTS, 0); |
| 1251 | if (IS_ERR(brd->print_driver)) { |
| 1252 | rc = PTR_ERR(brd->print_driver); |
| 1253 | goto free_serial_drv; |
| 1254 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1255 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1256 | snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_", |
| 1257 | brd->boardnum); |
| 1258 | brd->print_driver->name = brd->print_name; |
| 1259 | brd->print_driver->name_base = 0; |
| 1260 | brd->print_driver->major = 0; |
| 1261 | brd->print_driver->minor_start = 0; |
| 1262 | brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL; |
| 1263 | brd->print_driver->subtype = SERIAL_TYPE_NORMAL; |
| 1264 | brd->print_driver->init_termios = dgap_default_termios; |
| 1265 | brd->print_driver->driver_name = DRVSTR; |
| 1266 | brd->print_driver->flags = (TTY_DRIVER_REAL_RAW | |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1267 | TTY_DRIVER_DYNAMIC_DEV | |
| 1268 | TTY_DRIVER_HARDWARE_BREAK); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1269 | |
| 1270 | /* The kernel wants space to store pointers to tty_structs */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1271 | brd->print_driver->ttys = |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1272 | kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL); |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1273 | if (!brd->print_driver->ttys) { |
| 1274 | rc = -ENOMEM; |
| 1275 | goto free_print_drv; |
| 1276 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1277 | |
| 1278 | /* |
| 1279 | * Entry points for driver. Called by the kernel from |
| 1280 | * tty_io.c and n_tty.c. |
| 1281 | */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1282 | tty_set_operations(brd->print_driver, &dgap_tty_ops); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1283 | |
Mark Hounschell | 5c3b48d | 2014-04-25 13:10:19 -0400 | [diff] [blame] | 1284 | /* Register tty devices */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1285 | rc = tty_register_driver(brd->serial_driver); |
Mark Hounschell | 5c3b48d | 2014-04-25 13:10:19 -0400 | [diff] [blame] | 1286 | if (rc < 0) |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1287 | goto free_print_drv; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1288 | |
Mark Hounschell | 5c3b48d | 2014-04-25 13:10:19 -0400 | [diff] [blame] | 1289 | /* Register Transparent Print devices */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1290 | rc = tty_register_driver(brd->print_driver); |
Mark Hounschell | 5c3b48d | 2014-04-25 13:10:19 -0400 | [diff] [blame] | 1291 | if (rc < 0) |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1292 | goto unregister_serial_drv; |
| 1293 | |
| 1294 | brd->dgap_major_serial_registered = TRUE; |
| 1295 | dgap_boards_by_major[brd->serial_driver->major] = brd; |
| 1296 | brd->dgap_serial_major = brd->serial_driver->major; |
| 1297 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1298 | brd->dgap_major_transparent_print_registered = TRUE; |
| 1299 | dgap_boards_by_major[brd->print_driver->major] = brd; |
| 1300 | brd->dgap_transparent_print_major = brd->print_driver->major; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1301 | |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1302 | return 0; |
| 1303 | |
| 1304 | unregister_serial_drv: |
| 1305 | tty_unregister_driver(brd->serial_driver); |
| 1306 | free_print_drv: |
| 1307 | put_tty_driver(brd->print_driver); |
| 1308 | free_serial_drv: |
| 1309 | put_tty_driver(brd->serial_driver); |
| 1310 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 1311 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1312 | } |
| 1313 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1314 | /* |
| 1315 | * dgap_tty_init() |
| 1316 | * |
| 1317 | * Init the tty subsystem. Called once per board after board has been |
| 1318 | * downloaded and init'ed. |
| 1319 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 1320 | static int dgap_tty_init(struct board_t *brd) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1321 | { |
| 1322 | int i; |
| 1323 | int tlw; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 1324 | uint true_count; |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 1325 | u8 __iomem *vaddr; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 1326 | u8 modem; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1327 | struct channel_t *ch; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 1328 | struct bs_t __iomem *bs; |
Mark Hounschell | 6a30cdd | 2014-04-23 16:43:21 -0400 | [diff] [blame] | 1329 | struct cm_t __iomem *cm; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1330 | |
| 1331 | if (!brd) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 1332 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1333 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1334 | /* |
| 1335 | * Initialize board structure elements. |
| 1336 | */ |
| 1337 | |
| 1338 | vaddr = brd->re_map_membase; |
| 1339 | true_count = readw((vaddr + NCHAN)); |
| 1340 | |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 1341 | brd->nasync = dgap_config_get_num_prts(brd); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1342 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1343 | if (!brd->nasync) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1344 | brd->nasync = brd->maxports; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1345 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1346 | if (brd->nasync > brd->maxports) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1347 | brd->nasync = brd->maxports; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1348 | |
| 1349 | if (true_count != brd->nasync) { |
Mark Hounschell | 249e734 | 2014-03-03 16:36:25 -0500 | [diff] [blame] | 1350 | if ((brd->type == PPCM) && (true_count == 64)) { |
| 1351 | pr_warn("dgap: %s configured for %d ports, has %d ports.\n", |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 1352 | brd->name, brd->nasync, true_count); |
Mark Hounschell | 249e734 | 2014-03-03 16:36:25 -0500 | [diff] [blame] | 1353 | pr_warn("dgap: Please make SURE the EBI cable running from the card\n"); |
| 1354 | pr_warn("dgap: to each EM module is plugged into EBI IN!\n"); |
| 1355 | } else if ((brd->type == PPCM) && (true_count == 0)) { |
| 1356 | pr_warn("dgap: %s configured for %d ports, has %d ports.\n", |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 1357 | brd->name, brd->nasync, true_count); |
Mark Hounschell | 249e734 | 2014-03-03 16:36:25 -0500 | [diff] [blame] | 1358 | pr_warn("dgap: Please make SURE the EBI cable running from the card\n"); |
| 1359 | pr_warn("dgap: to each EM module is plugged into EBI IN!\n"); |
| 1360 | } else |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 1361 | pr_warn("dgap: %s configured for %d ports, has %d ports.\n", |
| 1362 | brd->name, brd->nasync, true_count); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1363 | |
| 1364 | brd->nasync = true_count; |
| 1365 | |
| 1366 | /* If no ports, don't bother going any further */ |
| 1367 | if (!brd->nasync) { |
| 1368 | brd->state = BOARD_FAILED; |
| 1369 | brd->dpastatus = BD_NOFEP; |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 1370 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | /* |
| 1375 | * Allocate channel memory that might not have been allocated |
| 1376 | * when the driver was first loaded. |
| 1377 | */ |
| 1378 | for (i = 0; i < brd->nasync; i++) { |
| 1379 | if (!brd->channels[i]) { |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1380 | brd->channels[i] = |
Mark Hounschell | 244a034 | 2014-05-23 14:02:34 -0400 | [diff] [blame] | 1381 | kzalloc(sizeof(struct channel_t), GFP_KERNEL); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 1382 | if (!brd->channels[i]) |
| 1383 | return -ENOMEM; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | ch = brd->channels[0]; |
| 1388 | vaddr = brd->re_map_membase; |
| 1389 | |
Mark Hounschell | 630b2ab | 2014-04-24 09:22:12 -0400 | [diff] [blame] | 1390 | bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF); |
| 1391 | cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1392 | |
| 1393 | brd->bd_bs = bs; |
| 1394 | |
| 1395 | /* Set up channel variables */ |
| 1396 | for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) { |
| 1397 | |
| 1398 | if (!brd->channels[i]) |
| 1399 | continue; |
| 1400 | |
Mark Hounschell | 211568d | 2014-03-11 10:11:43 -0400 | [diff] [blame] | 1401 | spin_lock_init(&ch->ch_lock); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1402 | |
| 1403 | /* Store all our magic numbers */ |
| 1404 | ch->magic = DGAP_CHANNEL_MAGIC; |
| 1405 | ch->ch_tun.magic = DGAP_UNIT_MAGIC; |
| 1406 | ch->ch_tun.un_type = DGAP_SERIAL; |
| 1407 | ch->ch_tun.un_ch = ch; |
| 1408 | ch->ch_tun.un_dev = i; |
| 1409 | |
| 1410 | ch->ch_pun.magic = DGAP_UNIT_MAGIC; |
| 1411 | ch->ch_pun.un_type = DGAP_PRINT; |
| 1412 | ch->ch_pun.un_ch = ch; |
| 1413 | ch->ch_pun.un_dev = i; |
| 1414 | |
| 1415 | ch->ch_vaddr = vaddr; |
| 1416 | ch->ch_bs = bs; |
| 1417 | ch->ch_cm = cm; |
| 1418 | ch->ch_bd = brd; |
| 1419 | ch->ch_portnum = i; |
| 1420 | ch->ch_digi = dgap_digi_init; |
| 1421 | |
| 1422 | /* |
| 1423 | * Set up digi dsr and dcd bits based on altpin flag. |
| 1424 | */ |
| 1425 | if (dgap_config_get_altpin(brd)) { |
| 1426 | ch->ch_dsr = DM_CD; |
| 1427 | ch->ch_cd = DM_DSR; |
| 1428 | ch->ch_digi.digi_flags |= DIGI_ALTPIN; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1429 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1430 | ch->ch_cd = DM_CD; |
| 1431 | ch->ch_dsr = DM_DSR; |
| 1432 | } |
| 1433 | |
Pascal COMBES | 77870a1 | 2014-05-24 15:58:09 +0200 | [diff] [blame] | 1434 | ch->ch_taddr = vaddr + (ioread16(&(ch->ch_bs->tx_seg)) << 4); |
| 1435 | ch->ch_raddr = vaddr + (ioread16(&(ch->ch_bs->rx_seg)) << 4); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1436 | ch->ch_tx_win = 0; |
| 1437 | ch->ch_rx_win = 0; |
| 1438 | ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1; |
| 1439 | ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1; |
| 1440 | ch->ch_tstart = 0; |
| 1441 | ch->ch_rstart = 0; |
| 1442 | |
| 1443 | /* .25 second delay */ |
| 1444 | ch->ch_close_delay = 250; |
| 1445 | |
| 1446 | /* |
| 1447 | * Set queue water marks, interrupt mask, |
| 1448 | * and general tty parameters. |
| 1449 | */ |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1450 | tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) : |
| 1451 | ch->ch_tsize / 2; |
| 1452 | ch->ch_tlw = tlw; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1453 | |
| 1454 | dgap_cmdw(ch, STLOW, tlw, 0); |
| 1455 | |
| 1456 | dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0); |
| 1457 | |
| 1458 | dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0); |
| 1459 | |
| 1460 | ch->ch_mistat = readb(&(ch->ch_bs->m_stat)); |
| 1461 | |
| 1462 | init_waitqueue_head(&ch->ch_flags_wait); |
| 1463 | init_waitqueue_head(&ch->ch_tun.un_flags_wait); |
| 1464 | init_waitqueue_head(&ch->ch_pun.un_flags_wait); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1465 | |
| 1466 | /* Turn on all modem interrupts for now */ |
| 1467 | modem = (DM_CD | DM_DSR | DM_CTS | DM_RI); |
| 1468 | writeb(modem, &(ch->ch_bs->m_int)); |
| 1469 | |
| 1470 | /* |
| 1471 | * Set edelay to 0 if interrupts are turned on, |
| 1472 | * otherwise set edelay to the usual 100. |
| 1473 | */ |
| 1474 | if (brd->intr_used) |
| 1475 | writew(0, &(ch->ch_bs->edelay)); |
| 1476 | else |
| 1477 | writew(100, &(ch->ch_bs->edelay)); |
| 1478 | |
| 1479 | writeb(1, &(ch->ch_bs->idata)); |
| 1480 | } |
| 1481 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 1482 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1483 | } |
| 1484 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1485 | /* |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1486 | * dgap_tty_uninit() |
| 1487 | * |
| 1488 | * Uninitialize the TTY portion of this driver. Free all memory and |
| 1489 | * resources. |
| 1490 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 1491 | static void dgap_tty_uninit(struct board_t *brd) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1492 | { |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 1493 | struct device *dev; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 1494 | int i; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1495 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1496 | if (brd->dgap_major_serial_registered) { |
| 1497 | dgap_boards_by_major[brd->serial_driver->major] = NULL; |
| 1498 | brd->dgap_serial_major = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1499 | for (i = 0; i < brd->nasync; i++) { |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1500 | tty_port_destroy(&brd->serial_ports[i]); |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 1501 | dev = brd->channels[i]->ch_tun.un_sysfs; |
| 1502 | dgap_remove_tty_sysfs(dev); |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1503 | tty_unregister_device(brd->serial_driver, i); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1504 | } |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1505 | tty_unregister_driver(brd->serial_driver); |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1506 | put_tty_driver(brd->serial_driver); |
| 1507 | kfree(brd->serial_ports); |
| 1508 | brd->dgap_major_serial_registered = FALSE; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1509 | } |
| 1510 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1511 | if (brd->dgap_major_transparent_print_registered) { |
| 1512 | dgap_boards_by_major[brd->print_driver->major] = NULL; |
| 1513 | brd->dgap_transparent_print_major = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1514 | for (i = 0; i < brd->nasync; i++) { |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1515 | tty_port_destroy(&brd->printer_ports[i]); |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 1516 | dev = brd->channels[i]->ch_pun.un_sysfs; |
| 1517 | dgap_remove_tty_sysfs(dev); |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1518 | tty_unregister_device(brd->print_driver, i); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1519 | } |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1520 | tty_unregister_driver(brd->print_driver); |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1521 | put_tty_driver(brd->print_driver); |
| 1522 | kfree(brd->printer_ports); |
| 1523 | brd->dgap_major_transparent_print_registered = FALSE; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1524 | } |
| 1525 | } |
| 1526 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1527 | /*======================================================================= |
| 1528 | * |
| 1529 | * dgap_input - Process received data. |
| 1530 | * |
| 1531 | * ch - Pointer to channel structure. |
| 1532 | * |
| 1533 | *=======================================================================*/ |
| 1534 | |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 1535 | static void dgap_input(struct channel_t *ch) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1536 | { |
| 1537 | struct board_t *bd; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 1538 | struct bs_t __iomem *bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1539 | struct tty_struct *tp; |
| 1540 | struct tty_ldisc *ld; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 1541 | uint rmask; |
| 1542 | uint head; |
| 1543 | uint tail; |
| 1544 | int data_len; |
| 1545 | ulong lock_flags; |
| 1546 | ulong lock_flags2; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1547 | int flip_len; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 1548 | int len; |
| 1549 | int n; |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 1550 | u8 *buf; |
| 1551 | u8 tmpchar; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 1552 | int s; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1553 | |
| 1554 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 1555 | return; |
| 1556 | |
| 1557 | tp = ch->ch_tun.un_tty; |
| 1558 | |
| 1559 | bs = ch->ch_bs; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1560 | if (!bs) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1561 | return; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1562 | |
| 1563 | bd = ch->ch_bd; |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 1564 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1565 | return; |
| 1566 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1567 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 1568 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1569 | |
| 1570 | /* |
| 1571 | * Figure the number of characters in the buffer. |
| 1572 | * Exit immediately if none. |
| 1573 | */ |
| 1574 | |
| 1575 | rmask = ch->ch_rsize - 1; |
| 1576 | |
| 1577 | head = readw(&(bs->rx_head)); |
| 1578 | head &= rmask; |
| 1579 | tail = readw(&(bs->rx_tail)); |
| 1580 | tail &= rmask; |
| 1581 | |
| 1582 | data_len = (head - tail) & rmask; |
| 1583 | |
| 1584 | if (data_len == 0) { |
| 1585 | writeb(1, &(bs->idata)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1586 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1587 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1588 | return; |
| 1589 | } |
| 1590 | |
| 1591 | /* |
| 1592 | * If the device is not open, or CREAD is off, flush |
| 1593 | * input data and return immediately. |
| 1594 | */ |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 1595 | if ((bd->state != BOARD_READY) || !tp || |
| 1596 | (tp->magic != TTY_MAGIC) || |
| 1597 | !(ch->ch_tun.un_flags & UN_ISOPEN) || |
| 1598 | !(tp->termios.c_cflag & CREAD) || |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1599 | (ch->ch_tun.un_flags & UN_CLOSING)) { |
| 1600 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1601 | writew(head, &(bs->rx_tail)); |
| 1602 | writeb(1, &(bs->idata)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1603 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1604 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1605 | return; |
| 1606 | } |
| 1607 | |
| 1608 | /* |
| 1609 | * If we are throttled, simply don't read any data. |
| 1610 | */ |
| 1611 | if (ch->ch_flags & CH_RXBLOCK) { |
| 1612 | writeb(1, &(bs->idata)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1613 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1614 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1615 | return; |
| 1616 | } |
| 1617 | |
| 1618 | /* |
| 1619 | * Ignore oruns. |
| 1620 | */ |
| 1621 | tmpchar = readb(&(bs->orun)); |
| 1622 | if (tmpchar) { |
| 1623 | ch->ch_err_overrun++; |
| 1624 | writeb(0, &(bs->orun)); |
| 1625 | } |
| 1626 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1627 | /* Decide how much data we can send into the tty layer */ |
| 1628 | flip_len = TTY_FLIPBUF_SIZE; |
| 1629 | |
| 1630 | /* Chop down the length, if needed */ |
| 1631 | len = min(data_len, flip_len); |
| 1632 | len = min(len, (N_TTY_BUF_SIZE - 1)); |
| 1633 | |
| 1634 | ld = tty_ldisc_ref(tp); |
| 1635 | |
| 1636 | #ifdef TTY_DONT_FLIP |
| 1637 | /* |
| 1638 | * If the DONT_FLIP flag is on, don't flush our buffer, and act |
| 1639 | * like the ld doesn't have any space to put the data right now. |
| 1640 | */ |
| 1641 | if (test_bit(TTY_DONT_FLIP, &tp->flags)) |
| 1642 | len = 0; |
| 1643 | #endif |
| 1644 | |
| 1645 | /* |
| 1646 | * If we were unable to get a reference to the ld, |
| 1647 | * don't flush our buffer, and act like the ld doesn't |
| 1648 | * have any space to put the data right now. |
| 1649 | */ |
| 1650 | if (!ld) { |
| 1651 | len = 0; |
| 1652 | } else { |
| 1653 | /* |
| 1654 | * If ld doesn't have a pointer to a receive_buf function, |
| 1655 | * flush the data, then act like the ld doesn't have any |
| 1656 | * space to put the data right now. |
| 1657 | */ |
| 1658 | if (!ld->ops->receive_buf) { |
| 1659 | writew(head, &(bs->rx_tail)); |
| 1660 | len = 0; |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | if (len <= 0) { |
| 1665 | writeb(1, &(bs->idata)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1666 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1667 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1668 | if (ld) |
| 1669 | tty_ldisc_deref(ld); |
| 1670 | return; |
| 1671 | } |
| 1672 | |
| 1673 | buf = ch->ch_bd->flipbuf; |
| 1674 | n = len; |
| 1675 | |
| 1676 | /* |
| 1677 | * n now contains the most amount of data we can copy, |
| 1678 | * bounded either by our buffer size or the amount |
| 1679 | * of data the card actually has pending... |
| 1680 | */ |
| 1681 | while (n) { |
| 1682 | |
| 1683 | s = ((head >= tail) ? head : ch->ch_rsize) - tail; |
| 1684 | s = min(s, n); |
| 1685 | |
| 1686 | if (s <= 0) |
| 1687 | break; |
| 1688 | |
Mark Hounschell | 630b2ab | 2014-04-24 09:22:12 -0400 | [diff] [blame] | 1689 | memcpy_fromio(buf, ch->ch_raddr + tail, s); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1690 | |
| 1691 | tail += s; |
| 1692 | buf += s; |
| 1693 | |
| 1694 | n -= s; |
| 1695 | /* Flip queue if needed */ |
| 1696 | tail &= rmask; |
| 1697 | } |
| 1698 | |
| 1699 | writew(tail, &(bs->rx_tail)); |
| 1700 | writeb(1, &(bs->idata)); |
| 1701 | ch->ch_rxcount += len; |
| 1702 | |
| 1703 | /* |
| 1704 | * If we are completely raw, we don't need to go through a lot |
| 1705 | * of the tty layers that exist. |
| 1706 | * In this case, we take the shortest and fastest route we |
| 1707 | * can to relay the data to the user. |
| 1708 | * |
| 1709 | * On the other hand, if we are not raw, we need to go through |
| 1710 | * the tty layer, which has its API more well defined. |
| 1711 | */ |
| 1712 | if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) { |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 1713 | dgap_parity_scan(ch, ch->ch_bd->flipbuf, |
| 1714 | ch->ch_bd->flipflagbuf, &len); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1715 | |
| 1716 | len = tty_buffer_request_room(tp->port, len); |
| 1717 | tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf, |
| 1718 | ch->ch_bd->flipflagbuf, len); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1719 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1720 | len = tty_buffer_request_room(tp->port, len); |
| 1721 | tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len); |
| 1722 | } |
| 1723 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1724 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1725 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1726 | |
| 1727 | /* Tell the tty layer its okay to "eat" the data now */ |
| 1728 | tty_flip_buffer_push(tp->port); |
| 1729 | |
| 1730 | if (ld) |
| 1731 | tty_ldisc_deref(ld); |
| 1732 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1733 | } |
| 1734 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1735 | /************************************************************************ |
| 1736 | * Determines when CARRIER changes state and takes appropriate |
| 1737 | * action. |
| 1738 | ************************************************************************/ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 1739 | static void dgap_carrier(struct channel_t *ch) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1740 | { |
| 1741 | struct board_t *bd; |
| 1742 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 1743 | int virt_carrier = 0; |
| 1744 | int phys_carrier = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1745 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1746 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 1747 | return; |
| 1748 | |
| 1749 | bd = ch->ch_bd; |
| 1750 | |
| 1751 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 1752 | return; |
| 1753 | |
| 1754 | /* Make sure altpin is always set correctly */ |
| 1755 | if (ch->ch_digi.digi_flags & DIGI_ALTPIN) { |
| 1756 | ch->ch_dsr = DM_CD; |
| 1757 | ch->ch_cd = DM_DSR; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1758 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1759 | ch->ch_dsr = DM_DSR; |
| 1760 | ch->ch_cd = DM_CD; |
| 1761 | } |
| 1762 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 1763 | if (ch->ch_mistat & D_CD(ch)) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1764 | phys_carrier = 1; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1765 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1766 | if (ch->ch_digi.digi_flags & DIGI_FORCEDCD) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1767 | virt_carrier = 1; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1768 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1769 | if (ch->ch_c_cflag & CLOCAL) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1770 | virt_carrier = 1; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1771 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1772 | /* |
| 1773 | * Test for a VIRTUAL carrier transition to HIGH. |
| 1774 | */ |
| 1775 | if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) { |
| 1776 | |
| 1777 | /* |
| 1778 | * When carrier rises, wake any threads waiting |
| 1779 | * for carrier in the open routine. |
| 1780 | */ |
| 1781 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1782 | if (waitqueue_active(&(ch->ch_flags_wait))) |
| 1783 | wake_up_interruptible(&ch->ch_flags_wait); |
| 1784 | } |
| 1785 | |
| 1786 | /* |
| 1787 | * Test for a PHYSICAL carrier transition to HIGH. |
| 1788 | */ |
| 1789 | if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) { |
| 1790 | |
| 1791 | /* |
| 1792 | * When carrier rises, wake any threads waiting |
| 1793 | * for carrier in the open routine. |
| 1794 | */ |
| 1795 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1796 | if (waitqueue_active(&(ch->ch_flags_wait))) |
| 1797 | wake_up_interruptible(&ch->ch_flags_wait); |
| 1798 | } |
| 1799 | |
| 1800 | /* |
| 1801 | * Test for a PHYSICAL transition to low, so long as we aren't |
| 1802 | * currently ignoring physical transitions (which is what "virtual |
| 1803 | * carrier" indicates). |
| 1804 | * |
| 1805 | * The transition of the virtual carrier to low really doesn't |
| 1806 | * matter... it really only means "ignore carrier state", not |
| 1807 | * "make pretend that carrier is there". |
| 1808 | */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1809 | if ((virt_carrier == 0) && |
| 1810 | ((ch->ch_flags & CH_CD) != 0) && |
| 1811 | (phys_carrier == 0)) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1812 | |
| 1813 | /* |
| 1814 | * When carrier drops: |
| 1815 | * |
| 1816 | * Drop carrier on all open units. |
| 1817 | * |
| 1818 | * Flush queues, waking up any task waiting in the |
| 1819 | * line discipline. |
| 1820 | * |
| 1821 | * Send a hangup to the control terminal. |
| 1822 | * |
| 1823 | * Enable all select calls. |
| 1824 | */ |
| 1825 | if (waitqueue_active(&(ch->ch_flags_wait))) |
| 1826 | wake_up_interruptible(&ch->ch_flags_wait); |
| 1827 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 1828 | if (ch->ch_tun.un_open_count > 0) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1829 | tty_hangup(ch->ch_tun.un_tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1830 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 1831 | if (ch->ch_pun.un_open_count > 0) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1832 | tty_hangup(ch->ch_pun.un_tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | /* |
| 1836 | * Make sure that our cached values reflect the current reality. |
| 1837 | */ |
| 1838 | if (virt_carrier == 1) |
| 1839 | ch->ch_flags |= CH_FCAR; |
| 1840 | else |
| 1841 | ch->ch_flags &= ~CH_FCAR; |
| 1842 | |
| 1843 | if (phys_carrier == 1) |
| 1844 | ch->ch_flags |= CH_CD; |
| 1845 | else |
| 1846 | ch->ch_flags &= ~CH_CD; |
| 1847 | } |
| 1848 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1849 | /************************************************************************ |
| 1850 | * |
| 1851 | * TTY Entry points and helper functions |
| 1852 | * |
| 1853 | ************************************************************************/ |
| 1854 | |
| 1855 | /* |
| 1856 | * dgap_tty_open() |
| 1857 | * |
| 1858 | */ |
| 1859 | static int dgap_tty_open(struct tty_struct *tty, struct file *file) |
| 1860 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 1861 | struct board_t *brd; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1862 | struct channel_t *ch; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 1863 | struct un_t *un; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 1864 | struct bs_t __iomem *bs; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 1865 | uint major; |
| 1866 | uint minor; |
| 1867 | int rc; |
| 1868 | ulong lock_flags; |
| 1869 | ulong lock_flags2; |
| 1870 | u16 head; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1871 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1872 | major = MAJOR(tty_devnum(tty)); |
| 1873 | minor = MINOR(tty_devnum(tty)); |
| 1874 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1875 | if (major > 255) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 1876 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1877 | |
| 1878 | /* Get board pointer from our array of majors we have allocated */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1879 | brd = dgap_boards_by_major[major]; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1880 | if (!brd) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 1881 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1882 | |
| 1883 | /* |
| 1884 | * If board is not yet up to a state of READY, go to |
| 1885 | * sleep waiting for it to happen or they cancel the open. |
| 1886 | */ |
| 1887 | rc = wait_event_interruptible(brd->state_wait, |
| 1888 | (brd->state & BOARD_READY)); |
| 1889 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1890 | if (rc) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1891 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1892 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1893 | spin_lock_irqsave(&brd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1894 | |
| 1895 | /* The wait above should guarantee this cannot happen */ |
| 1896 | if (brd->state != BOARD_READY) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1897 | spin_unlock_irqrestore(&brd->bd_lock, lock_flags); |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 1898 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | /* If opened device is greater than our number of ports, bail. */ |
| 1902 | if (MINOR(tty_devnum(tty)) > brd->nasync) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1903 | spin_unlock_irqrestore(&brd->bd_lock, lock_flags); |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 1904 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | ch = brd->channels[minor]; |
| 1908 | if (!ch) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1909 | spin_unlock_irqrestore(&brd->bd_lock, lock_flags); |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 1910 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | /* Grab channel lock */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1914 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1915 | |
| 1916 | /* Figure out our type */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1917 | if (major == brd->dgap_serial_major) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1918 | un = &brd->channels[minor]->ch_tun; |
| 1919 | un->un_type = DGAP_SERIAL; |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1920 | } else if (major == brd->dgap_transparent_print_major) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1921 | un = &brd->channels[minor]->ch_pun; |
| 1922 | un->un_type = DGAP_PRINT; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1923 | } else { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1924 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1925 | spin_unlock_irqrestore(&brd->bd_lock, lock_flags); |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 1926 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | /* Store our unit into driver_data, so we always have it available. */ |
| 1930 | tty->driver_data = un; |
| 1931 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1932 | /* |
| 1933 | * Error if channel info pointer is NULL. |
| 1934 | */ |
| 1935 | bs = ch->ch_bs; |
| 1936 | if (!bs) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1937 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1938 | spin_unlock_irqrestore(&brd->bd_lock, lock_flags); |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 1939 | return -EIO; |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 1940 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1941 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1942 | /* |
| 1943 | * Initialize tty's |
| 1944 | */ |
| 1945 | if (!(un->un_flags & UN_ISOPEN)) { |
| 1946 | /* Store important variables. */ |
| 1947 | un->un_tty = tty; |
| 1948 | |
| 1949 | /* Maybe do something here to the TTY struct as well? */ |
| 1950 | } |
| 1951 | |
| 1952 | /* |
| 1953 | * Initialize if neither terminal or printer is open. |
| 1954 | */ |
| 1955 | if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) { |
| 1956 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1957 | ch->ch_mforce = 0; |
| 1958 | ch->ch_mval = 0; |
| 1959 | |
| 1960 | /* |
| 1961 | * Flush input queue. |
| 1962 | */ |
| 1963 | head = readw(&(bs->rx_head)); |
| 1964 | writew(head, &(bs->rx_tail)); |
| 1965 | |
| 1966 | ch->ch_flags = 0; |
| 1967 | ch->pscan_state = 0; |
| 1968 | ch->pscan_savechar = 0; |
| 1969 | |
| 1970 | ch->ch_c_cflag = tty->termios.c_cflag; |
| 1971 | ch->ch_c_iflag = tty->termios.c_iflag; |
| 1972 | ch->ch_c_oflag = tty->termios.c_oflag; |
| 1973 | ch->ch_c_lflag = tty->termios.c_lflag; |
| 1974 | ch->ch_startc = tty->termios.c_cc[VSTART]; |
| 1975 | ch->ch_stopc = tty->termios.c_cc[VSTOP]; |
| 1976 | |
| 1977 | /* TODO: flush our TTY struct here? */ |
| 1978 | } |
| 1979 | |
| 1980 | dgap_carrier(ch); |
| 1981 | /* |
| 1982 | * Run param in case we changed anything |
| 1983 | */ |
| 1984 | dgap_param(tty); |
| 1985 | |
| 1986 | /* |
| 1987 | * follow protocol for opening port |
| 1988 | */ |
| 1989 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1990 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1991 | spin_unlock_irqrestore(&brd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1992 | |
| 1993 | rc = dgap_block_til_ready(tty, file, ch); |
| 1994 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1995 | if (!un->un_tty) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1996 | return -ENODEV; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1997 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1998 | /* No going back now, increment our unit and channel counters */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1999 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2000 | ch->ch_open_count++; |
| 2001 | un->un_open_count++; |
| 2002 | un->un_flags |= (UN_ISOPEN); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2003 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2004 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2005 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2006 | } |
| 2007 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2008 | /* |
| 2009 | * dgap_block_til_ready() |
| 2010 | * |
| 2011 | * Wait for DCD, if needed. |
| 2012 | */ |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2013 | static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, |
| 2014 | struct channel_t *ch) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2015 | { |
| 2016 | int retval = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2017 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 2018 | ulong lock_flags; |
| 2019 | uint old_flags; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2020 | int sleep_on_un_flags; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2021 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2022 | if (!tty || tty->magic != TTY_MAGIC || !file || !ch || |
| 2023 | ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 2024 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2025 | |
| 2026 | un = tty->driver_data; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2027 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 2028 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2029 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2030 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2031 | |
| 2032 | ch->ch_wopen++; |
| 2033 | |
| 2034 | /* Loop forever */ |
| 2035 | while (1) { |
| 2036 | |
| 2037 | sleep_on_un_flags = 0; |
| 2038 | |
| 2039 | /* |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2040 | * If board has failed somehow during our sleep, |
| 2041 | * bail with error. |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2042 | */ |
| 2043 | if (ch->ch_bd->state == BOARD_FAILED) { |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 2044 | retval = -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2045 | break; |
| 2046 | } |
| 2047 | |
| 2048 | /* If tty was hung up, break out of loop and set error. */ |
| 2049 | if (tty_hung_up_p(file)) { |
| 2050 | retval = -EAGAIN; |
| 2051 | break; |
| 2052 | } |
| 2053 | |
| 2054 | /* |
| 2055 | * If either unit is in the middle of the fragile part of close, |
| 2056 | * we just cannot touch the channel safely. |
| 2057 | * Go back to sleep, knowing that when the channel can be |
| 2058 | * touched safely, the close routine will signal the |
| 2059 | * ch_wait_flags to wake us back up. |
| 2060 | */ |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2061 | if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & |
| 2062 | UN_CLOSING)) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2063 | |
| 2064 | /* |
| 2065 | * Our conditions to leave cleanly and happily: |
| 2066 | * 1) NONBLOCKING on the tty is set. |
| 2067 | * 2) CLOCAL is set. |
| 2068 | * 3) DCD (fake or real) is active. |
| 2069 | */ |
| 2070 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2071 | if (file->f_flags & O_NONBLOCK) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2072 | break; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2073 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2074 | if (tty->flags & (1 << TTY_IO_ERROR)) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2075 | break; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2076 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 2077 | if (ch->ch_flags & CH_CD) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2078 | break; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2079 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 2080 | if (ch->ch_flags & CH_FCAR) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2081 | break; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2082 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2083 | sleep_on_un_flags = 1; |
| 2084 | } |
| 2085 | |
| 2086 | /* |
| 2087 | * If there is a signal pending, the user probably |
| 2088 | * interrupted (ctrl-c) us. |
| 2089 | * Leave loop with error set. |
| 2090 | */ |
| 2091 | if (signal_pending(current)) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2092 | retval = -ERESTARTSYS; |
| 2093 | break; |
| 2094 | } |
| 2095 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2096 | /* |
| 2097 | * Store the flags before we let go of channel lock |
| 2098 | */ |
| 2099 | if (sleep_on_un_flags) |
| 2100 | old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags; |
| 2101 | else |
| 2102 | old_flags = ch->ch_flags; |
| 2103 | |
| 2104 | /* |
| 2105 | * Let go of channel lock before calling schedule. |
| 2106 | * Our poller will get any FEP events and wake us up when DCD |
| 2107 | * eventually goes active. |
| 2108 | */ |
| 2109 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2110 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2111 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2112 | /* |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2113 | * Wait for something in the flags to change |
| 2114 | * from the current value. |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2115 | */ |
| 2116 | if (sleep_on_un_flags) { |
| 2117 | retval = wait_event_interruptible(un->un_flags_wait, |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2118 | (old_flags != (ch->ch_tun.un_flags | |
| 2119 | ch->ch_pun.un_flags))); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2120 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2121 | retval = wait_event_interruptible(ch->ch_flags_wait, |
| 2122 | (old_flags != ch->ch_flags)); |
| 2123 | } |
| 2124 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2125 | /* |
| 2126 | * We got woken up for some reason. |
| 2127 | * Before looping around, grab our channel lock. |
| 2128 | */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2129 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | ch->ch_wopen--; |
| 2133 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2134 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2135 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 2136 | if (retval) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2137 | return retval; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2138 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2139 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2140 | } |
| 2141 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2142 | /* |
| 2143 | * dgap_tty_hangup() |
| 2144 | * |
| 2145 | * Hangup the port. Like a close, but don't wait for output to drain. |
| 2146 | */ |
| 2147 | static void dgap_tty_hangup(struct tty_struct *tty) |
| 2148 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 2149 | struct board_t *bd; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2150 | struct channel_t *ch; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 2151 | struct un_t *un; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2152 | |
| 2153 | if (!tty || tty->magic != TTY_MAGIC) |
| 2154 | return; |
| 2155 | |
| 2156 | un = tty->driver_data; |
| 2157 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 2158 | return; |
| 2159 | |
| 2160 | ch = un->un_ch; |
| 2161 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 2162 | return; |
| 2163 | |
| 2164 | bd = ch->ch_bd; |
| 2165 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 2166 | return; |
| 2167 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2168 | /* flush the transmit queues */ |
| 2169 | dgap_tty_flush_buffer(tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2170 | } |
| 2171 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2172 | /* |
| 2173 | * dgap_tty_close() |
| 2174 | * |
| 2175 | */ |
| 2176 | static void dgap_tty_close(struct tty_struct *tty, struct file *file) |
| 2177 | { |
| 2178 | struct ktermios *ts; |
| 2179 | struct board_t *bd; |
| 2180 | struct channel_t *ch; |
| 2181 | struct un_t *un; |
| 2182 | ulong lock_flags; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2183 | |
| 2184 | if (!tty || tty->magic != TTY_MAGIC) |
| 2185 | return; |
| 2186 | |
| 2187 | un = tty->driver_data; |
| 2188 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 2189 | return; |
| 2190 | |
| 2191 | ch = un->un_ch; |
| 2192 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 2193 | return; |
| 2194 | |
| 2195 | bd = ch->ch_bd; |
| 2196 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 2197 | return; |
| 2198 | |
| 2199 | ts = &tty->termios; |
| 2200 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2201 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2202 | |
| 2203 | /* |
| 2204 | * Determine if this is the last close or not - and if we agree about |
| 2205 | * which type of close it is with the Line Discipline |
| 2206 | */ |
Mark Hounschell | 82ed977 | 2014-03-03 16:36:24 -0500 | [diff] [blame] | 2207 | if ((tty->count == 1) && (un->un_open_count != 1)) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2208 | /* |
| 2209 | * Uh, oh. tty->count is 1, which means that the tty |
| 2210 | * structure will be freed. un_open_count should always |
| 2211 | * be one in these conditions. If it's greater than |
| 2212 | * one, we've got real problems, since it means the |
| 2213 | * serial port won't be shutdown. |
| 2214 | */ |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2215 | un->un_open_count = 1; |
Mark Hounschell | 82ed977 | 2014-03-03 16:36:24 -0500 | [diff] [blame] | 2216 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2217 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 2218 | if (--un->un_open_count < 0) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2219 | un->un_open_count = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2220 | |
| 2221 | ch->ch_open_count--; |
| 2222 | |
| 2223 | if (ch->ch_open_count && un->un_open_count) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2224 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2225 | return; |
| 2226 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2227 | |
| 2228 | /* OK, its the last close on the unit */ |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2229 | |
| 2230 | un->un_flags |= UN_CLOSING; |
| 2231 | |
| 2232 | tty->closing = 1; |
| 2233 | |
| 2234 | /* |
| 2235 | * Only officially close channel if count is 0 and |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2236 | * DIGI_PRINTER bit is not set. |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2237 | */ |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2238 | if ((ch->ch_open_count == 0) && |
| 2239 | !(ch->ch_digi.digi_flags & DIGI_PRINTER)) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2240 | |
| 2241 | ch->ch_flags &= ~(CH_RXBLOCK); |
| 2242 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2243 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2244 | |
| 2245 | /* wait for output to drain */ |
| 2246 | /* This will also return if we take an interrupt */ |
| 2247 | |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2248 | dgap_wait_for_drain(tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2249 | |
| 2250 | dgap_tty_flush_buffer(tty); |
| 2251 | tty_ldisc_flush(tty); |
| 2252 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2253 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2254 | |
| 2255 | tty->closing = 0; |
| 2256 | |
| 2257 | /* |
| 2258 | * If we have HUPCL set, lower DTR and RTS |
| 2259 | */ |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 2260 | if (ch->ch_c_cflag & HUPCL) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2261 | ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch)); |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 2262 | dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2263 | |
| 2264 | /* |
| 2265 | * Go to sleep to ensure RTS/DTR |
| 2266 | * have been dropped for modems to see it. |
| 2267 | */ |
| 2268 | if (ch->ch_close_delay) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2269 | spin_unlock_irqrestore(&ch->ch_lock, |
| 2270 | lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2271 | dgap_ms_sleep(ch->ch_close_delay); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2272 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | ch->pscan_state = 0; |
| 2277 | ch->pscan_savechar = 0; |
| 2278 | ch->ch_baud_info = 0; |
| 2279 | |
| 2280 | } |
| 2281 | |
| 2282 | /* |
| 2283 | * turn off print device when closing print device. |
| 2284 | */ |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 2285 | if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2286 | dgap_wmove(ch, ch->ch_digi.digi_offstr, |
| 2287 | (int) ch->ch_digi.digi_offlen); |
| 2288 | ch->ch_flags &= ~CH_PRON; |
| 2289 | } |
| 2290 | |
| 2291 | un->un_tty = NULL; |
| 2292 | un->un_flags &= ~(UN_ISOPEN | UN_CLOSING); |
| 2293 | tty->driver_data = NULL; |
| 2294 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2295 | wake_up_interruptible(&ch->ch_flags_wait); |
| 2296 | wake_up_interruptible(&un->un_flags_wait); |
| 2297 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2298 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2299 | } |
| 2300 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2301 | /* |
| 2302 | * dgap_tty_chars_in_buffer() |
| 2303 | * |
| 2304 | * Return number of characters that have not been transmitted yet. |
| 2305 | * |
| 2306 | * This routine is used by the line discipline to determine if there |
| 2307 | * is data waiting to be transmitted/drained/flushed or not. |
| 2308 | */ |
| 2309 | static int dgap_tty_chars_in_buffer(struct tty_struct *tty) |
| 2310 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2311 | struct board_t *bd; |
| 2312 | struct channel_t *ch; |
| 2313 | struct un_t *un; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 2314 | struct bs_t __iomem *bs; |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 2315 | u8 tbusy; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2316 | uint chars; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2317 | u16 thead, ttail, tmask, chead, ctail; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 2318 | ulong lock_flags = 0; |
| 2319 | ulong lock_flags2 = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2320 | |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 2321 | if (!tty) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2322 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2323 | |
| 2324 | un = tty->driver_data; |
| 2325 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2326 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2327 | |
| 2328 | ch = un->un_ch; |
| 2329 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2330 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2331 | |
| 2332 | bd = ch->ch_bd; |
| 2333 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2334 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2335 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2336 | bs = ch->ch_bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2337 | if (!bs) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2338 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2339 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2340 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 2341 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2342 | |
| 2343 | tmask = (ch->ch_tsize - 1); |
| 2344 | |
| 2345 | /* Get Transmit queue pointers */ |
| 2346 | thead = readw(&(bs->tx_head)) & tmask; |
| 2347 | ttail = readw(&(bs->tx_tail)) & tmask; |
| 2348 | |
| 2349 | /* Get tbusy flag */ |
| 2350 | tbusy = readb(&(bs->tbusy)); |
| 2351 | |
| 2352 | /* Get Command queue pointers */ |
| 2353 | chead = readw(&(ch->ch_cm->cm_head)); |
| 2354 | ctail = readw(&(ch->ch_cm->cm_tail)); |
| 2355 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2356 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 2357 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2358 | |
| 2359 | /* |
| 2360 | * The only way we know for sure if there is no pending |
| 2361 | * data left to be transferred, is if: |
| 2362 | * 1) Transmit head and tail are equal (empty). |
| 2363 | * 2) Command queue head and tail are equal (empty). |
| 2364 | * 3) The "TBUSY" flag is 0. (Transmitter not busy). |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2365 | */ |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2366 | |
| 2367 | if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) { |
| 2368 | chars = 0; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2369 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2370 | if (thead >= ttail) |
| 2371 | chars = thead - ttail; |
| 2372 | else |
| 2373 | chars = thead - ttail + ch->ch_tsize; |
| 2374 | /* |
| 2375 | * Fudge factor here. |
| 2376 | * If chars is zero, we know that the command queue had |
| 2377 | * something in it or tbusy was set. Because we cannot |
| 2378 | * be sure if there is still some data to be transmitted, |
| 2379 | * lets lie, and tell ld we have 1 byte left. |
| 2380 | */ |
| 2381 | if (chars == 0) { |
| 2382 | /* |
| 2383 | * If TBUSY is still set, and our tx buffers are empty, |
| 2384 | * force the firmware to send me another wakeup after |
| 2385 | * TBUSY has been cleared. |
| 2386 | */ |
| 2387 | if (tbusy != 0) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2388 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2389 | un->un_flags |= UN_EMPTY; |
| 2390 | writeb(1, &(bs->iempty)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2391 | spin_unlock_irqrestore(&ch->ch_lock, |
| 2392 | lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2393 | } |
| 2394 | chars = 1; |
| 2395 | } |
| 2396 | } |
| 2397 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2398 | return chars; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2399 | } |
| 2400 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2401 | static int dgap_wait_for_drain(struct tty_struct *tty) |
| 2402 | { |
| 2403 | struct channel_t *ch; |
| 2404 | struct un_t *un; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 2405 | struct bs_t __iomem *bs; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2406 | int ret = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2407 | uint count = 1; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 2408 | ulong lock_flags = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2409 | |
| 2410 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2411 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2412 | |
| 2413 | un = tty->driver_data; |
| 2414 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2415 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2416 | |
| 2417 | ch = un->un_ch; |
| 2418 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2419 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2420 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2421 | bs = ch->ch_bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2422 | if (!bs) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2423 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2424 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2425 | /* Loop until data is drained */ |
| 2426 | while (count != 0) { |
| 2427 | |
| 2428 | count = dgap_tty_chars_in_buffer(tty); |
| 2429 | |
| 2430 | if (count == 0) |
| 2431 | break; |
| 2432 | |
| 2433 | /* Set flag waiting for drain */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2434 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2435 | un->un_flags |= UN_EMPTY; |
| 2436 | writeb(1, &(bs->iempty)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2437 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2438 | |
| 2439 | /* Go to sleep till we get woken up */ |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2440 | ret = wait_event_interruptible(un->un_flags_wait, |
| 2441 | ((un->un_flags & UN_EMPTY) == 0)); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2442 | /* If ret is non-zero, user ctrl-c'ed us */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2443 | if (ret) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2444 | break; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2445 | } |
| 2446 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2447 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2448 | un->un_flags &= ~(UN_EMPTY); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2449 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2450 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2451 | return ret; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2452 | } |
| 2453 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2454 | /* |
| 2455 | * dgap_maxcps_room |
| 2456 | * |
| 2457 | * Reduces bytes_available to the max number of characters |
| 2458 | * that can be sent currently given the maxcps value, and |
| 2459 | * returns the new bytes_available. This only affects printer |
| 2460 | * output. |
| 2461 | */ |
| 2462 | static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available) |
| 2463 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2464 | struct channel_t *ch; |
| 2465 | struct un_t *un; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2466 | |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 2467 | if (!tty) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2468 | return bytes_available; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2469 | |
| 2470 | un = tty->driver_data; |
| 2471 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2472 | return bytes_available; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2473 | |
| 2474 | ch = un->un_ch; |
| 2475 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2476 | return bytes_available; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2477 | |
| 2478 | /* |
| 2479 | * If its not the Transparent print device, return |
| 2480 | * the full data amount. |
| 2481 | */ |
| 2482 | if (un->un_type != DGAP_PRINT) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2483 | return bytes_available; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2484 | |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 2485 | if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2486 | int cps_limit = 0; |
| 2487 | unsigned long current_time = jiffies; |
| 2488 | unsigned long buffer_time = current_time + |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2489 | (HZ * ch->ch_digi.digi_bufsize) / |
| 2490 | ch->ch_digi.digi_maxcps; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2491 | |
| 2492 | if (ch->ch_cpstime < current_time) { |
| 2493 | /* buffer is empty */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 2494 | ch->ch_cpstime = current_time; /* reset ch_cpstime */ |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2495 | cps_limit = ch->ch_digi.digi_bufsize; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2496 | } else if (ch->ch_cpstime < buffer_time) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2497 | /* still room in the buffer */ |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2498 | cps_limit = ((buffer_time - ch->ch_cpstime) * |
| 2499 | ch->ch_digi.digi_maxcps) / HZ; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2500 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2501 | /* no room in the buffer */ |
| 2502 | cps_limit = 0; |
| 2503 | } |
| 2504 | |
| 2505 | bytes_available = min(cps_limit, bytes_available); |
| 2506 | } |
| 2507 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2508 | return bytes_available; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2509 | } |
| 2510 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2511 | static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event) |
| 2512 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2513 | struct channel_t *ch; |
| 2514 | struct bs_t __iomem *bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2515 | |
| 2516 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 2517 | return; |
| 2518 | ch = un->un_ch; |
| 2519 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 2520 | return; |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2521 | bs = ch->ch_bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2522 | if (!bs) |
| 2523 | return; |
| 2524 | |
| 2525 | if ((event & UN_LOW) != 0) { |
| 2526 | if ((un->un_flags & UN_LOW) == 0) { |
| 2527 | un->un_flags |= UN_LOW; |
| 2528 | writeb(1, &(bs->ilow)); |
| 2529 | } |
| 2530 | } |
| 2531 | if ((event & UN_LOW) != 0) { |
| 2532 | if ((un->un_flags & UN_EMPTY) == 0) { |
| 2533 | un->un_flags |= UN_EMPTY; |
| 2534 | writeb(1, &(bs->iempty)); |
| 2535 | } |
| 2536 | } |
| 2537 | } |
| 2538 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2539 | /* |
| 2540 | * dgap_tty_write_room() |
| 2541 | * |
| 2542 | * Return space available in Tx buffer |
| 2543 | */ |
| 2544 | static int dgap_tty_write_room(struct tty_struct *tty) |
| 2545 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2546 | struct channel_t *ch; |
| 2547 | struct un_t *un; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 2548 | struct bs_t __iomem *bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2549 | u16 head, tail, tmask; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2550 | int ret; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 2551 | ulong lock_flags = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2552 | |
Mark Hounschell | 6126022 | 2014-03-06 13:03:33 -0500 | [diff] [blame] | 2553 | if (!tty) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2554 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2555 | |
| 2556 | un = tty->driver_data; |
| 2557 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2558 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2559 | |
| 2560 | ch = un->un_ch; |
| 2561 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2562 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2563 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2564 | bs = ch->ch_bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2565 | if (!bs) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2566 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2567 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2568 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2569 | |
| 2570 | tmask = ch->ch_tsize - 1; |
| 2571 | head = readw(&(bs->tx_head)) & tmask; |
| 2572 | tail = readw(&(bs->tx_tail)) & tmask; |
| 2573 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2574 | ret = tail - head - 1; |
| 2575 | if (ret < 0) |
| 2576 | ret += ch->ch_tsize; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2577 | |
| 2578 | /* Limit printer to maxcps */ |
| 2579 | ret = dgap_maxcps_room(tty, ret); |
| 2580 | |
| 2581 | /* |
| 2582 | * If we are printer device, leave space for |
| 2583 | * possibly both the on and off strings. |
| 2584 | */ |
| 2585 | if (un->un_type == DGAP_PRINT) { |
| 2586 | if (!(ch->ch_flags & CH_PRON)) |
| 2587 | ret -= ch->ch_digi.digi_onlen; |
| 2588 | ret -= ch->ch_digi.digi_offlen; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2589 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2590 | if (ch->ch_flags & CH_PRON) |
| 2591 | ret -= ch->ch_digi.digi_offlen; |
| 2592 | } |
| 2593 | |
| 2594 | if (ret < 0) |
| 2595 | ret = 0; |
| 2596 | |
| 2597 | /* |
| 2598 | * Schedule FEP to wake us up if needed. |
| 2599 | * |
| 2600 | * TODO: This might be overkill... |
| 2601 | * Do we really need to schedule callbacks from the FEP |
| 2602 | * in every case? Can we get smarter based on ret? |
| 2603 | */ |
| 2604 | dgap_set_firmware_event(un, UN_LOW | UN_EMPTY); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2605 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2606 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2607 | return ret; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2608 | } |
| 2609 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2610 | /* |
| 2611 | * dgap_tty_put_char() |
| 2612 | * |
| 2613 | * Put a character into ch->ch_buf |
| 2614 | * |
| 2615 | * - used by the line discipline for OPOST processing |
| 2616 | */ |
| 2617 | static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c) |
| 2618 | { |
| 2619 | /* |
| 2620 | * Simply call tty_write. |
| 2621 | */ |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2622 | dgap_tty_write(tty, &c, 1); |
| 2623 | return 1; |
| 2624 | } |
| 2625 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2626 | /* |
| 2627 | * dgap_tty_write() |
| 2628 | * |
| 2629 | * Take data from the user or kernel and send it out to the FEP. |
| 2630 | * In here exists all the Transparent Print magic as well. |
| 2631 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 2632 | static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, |
| 2633 | int count) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2634 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2635 | struct channel_t *ch; |
| 2636 | struct un_t *un; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 2637 | struct bs_t __iomem *bs; |
Mark Hounschell | 630b2ab | 2014-04-24 09:22:12 -0400 | [diff] [blame] | 2638 | char __iomem *vaddr; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2639 | u16 head, tail, tmask, remain; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2640 | int bufcount, n; |
| 2641 | int orig_count; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2642 | ulong lock_flags; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2643 | |
Mark Hounschell | 6126022 | 2014-03-06 13:03:33 -0500 | [diff] [blame] | 2644 | if (!tty) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2645 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2646 | |
| 2647 | un = tty->driver_data; |
| 2648 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2649 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2650 | |
| 2651 | ch = un->un_ch; |
| 2652 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2653 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2654 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2655 | bs = ch->ch_bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2656 | if (!bs) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2657 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2658 | |
| 2659 | if (!count) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2660 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2661 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2662 | /* |
| 2663 | * Store original amount of characters passed in. |
| 2664 | * This helps to figure out if we should ask the FEP |
| 2665 | * to send us an event when it has more space available. |
| 2666 | */ |
| 2667 | orig_count = count; |
| 2668 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2669 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2670 | |
| 2671 | /* Get our space available for the channel from the board */ |
| 2672 | tmask = ch->ch_tsize - 1; |
| 2673 | head = readw(&(bs->tx_head)) & tmask; |
| 2674 | tail = readw(&(bs->tx_tail)) & tmask; |
| 2675 | |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 2676 | bufcount = tail - head - 1; |
| 2677 | if (bufcount < 0) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2678 | bufcount += ch->ch_tsize; |
| 2679 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2680 | /* |
| 2681 | * Limit printer output to maxcps overall, with bursts allowed |
| 2682 | * up to bufsize characters. |
| 2683 | */ |
| 2684 | bufcount = dgap_maxcps_room(tty, bufcount); |
| 2685 | |
| 2686 | /* |
| 2687 | * Take minimum of what the user wants to send, and the |
| 2688 | * space available in the FEP buffer. |
| 2689 | */ |
| 2690 | count = min(count, bufcount); |
| 2691 | |
| 2692 | /* |
| 2693 | * Bail if no space left. |
| 2694 | */ |
| 2695 | if (count <= 0) { |
| 2696 | dgap_set_firmware_event(un, UN_LOW | UN_EMPTY); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2697 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2698 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2699 | } |
| 2700 | |
| 2701 | /* |
| 2702 | * Output the printer ON string, if we are in terminal mode, but |
| 2703 | * need to be in printer mode. |
| 2704 | */ |
| 2705 | if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) { |
| 2706 | dgap_wmove(ch, ch->ch_digi.digi_onstr, |
| 2707 | (int) ch->ch_digi.digi_onlen); |
| 2708 | head = readw(&(bs->tx_head)) & tmask; |
| 2709 | ch->ch_flags |= CH_PRON; |
| 2710 | } |
| 2711 | |
| 2712 | /* |
| 2713 | * On the other hand, output the printer OFF string, if we are |
| 2714 | * currently in printer mode, but need to output to the terminal. |
| 2715 | */ |
| 2716 | if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) { |
| 2717 | dgap_wmove(ch, ch->ch_digi.digi_offstr, |
| 2718 | (int) ch->ch_digi.digi_offlen); |
| 2719 | head = readw(&(bs->tx_head)) & tmask; |
| 2720 | ch->ch_flags &= ~CH_PRON; |
| 2721 | } |
| 2722 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2723 | n = count; |
| 2724 | |
| 2725 | /* |
| 2726 | * If the write wraps over the top of the circular buffer, |
| 2727 | * move the portion up to the wrap point, and reset the |
| 2728 | * pointers to the bottom. |
| 2729 | */ |
| 2730 | remain = ch->ch_tstart + ch->ch_tsize - head; |
| 2731 | |
| 2732 | if (n >= remain) { |
| 2733 | n -= remain; |
| 2734 | vaddr = ch->ch_taddr + head; |
| 2735 | |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 2736 | memcpy_toio(vaddr, (u8 *) buf, remain); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2737 | |
| 2738 | head = ch->ch_tstart; |
| 2739 | buf += remain; |
| 2740 | } |
| 2741 | |
| 2742 | if (n > 0) { |
| 2743 | |
| 2744 | /* |
| 2745 | * Move rest of data. |
| 2746 | */ |
| 2747 | vaddr = ch->ch_taddr + head; |
| 2748 | remain = n; |
| 2749 | |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 2750 | memcpy_toio(vaddr, (u8 *) buf, remain); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2751 | head += remain; |
| 2752 | |
| 2753 | } |
| 2754 | |
| 2755 | if (count) { |
| 2756 | ch->ch_txcount += count; |
| 2757 | head &= tmask; |
| 2758 | writew(head, &(bs->tx_head)); |
| 2759 | } |
| 2760 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2761 | dgap_set_firmware_event(un, UN_LOW | UN_EMPTY); |
| 2762 | |
| 2763 | /* |
| 2764 | * If this is the print device, and the |
| 2765 | * printer is still on, we need to turn it |
| 2766 | * off before going idle. If the buffer is |
| 2767 | * non-empty, wait until it goes empty. |
| 2768 | * Otherwise turn it off right now. |
| 2769 | */ |
| 2770 | if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) { |
| 2771 | tail = readw(&(bs->tx_tail)) & tmask; |
| 2772 | |
| 2773 | if (tail != head) { |
| 2774 | un->un_flags |= UN_EMPTY; |
| 2775 | writeb(1, &(bs->iempty)); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2776 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2777 | dgap_wmove(ch, ch->ch_digi.digi_offstr, |
| 2778 | (int) ch->ch_digi.digi_offlen); |
| 2779 | head = readw(&(bs->tx_head)) & tmask; |
| 2780 | ch->ch_flags &= ~CH_PRON; |
| 2781 | } |
| 2782 | } |
| 2783 | |
| 2784 | /* Update printer buffer empty time. */ |
| 2785 | if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0) |
| 2786 | && (ch->ch_digi.digi_bufsize > 0)) { |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2787 | ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2788 | } |
| 2789 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2790 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2791 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2792 | return count; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2793 | } |
| 2794 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2795 | /* |
| 2796 | * Return modem signals to ld. |
| 2797 | */ |
| 2798 | static int dgap_tty_tiocmget(struct tty_struct *tty) |
| 2799 | { |
| 2800 | struct channel_t *ch; |
| 2801 | struct un_t *un; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2802 | int result; |
| 2803 | u8 mstat; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2804 | ulong lock_flags; |
| 2805 | |
| 2806 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2807 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2808 | |
| 2809 | un = tty->driver_data; |
| 2810 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2811 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2812 | |
| 2813 | ch = un->un_ch; |
| 2814 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2815 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2816 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2817 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2818 | |
| 2819 | mstat = readb(&(ch->ch_bs->m_stat)); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2820 | /* Append any outbound signals that might be pending... */ |
| 2821 | mstat |= ch->ch_mostat; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2822 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2823 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2824 | |
| 2825 | result = 0; |
| 2826 | |
| 2827 | if (mstat & D_DTR(ch)) |
| 2828 | result |= TIOCM_DTR; |
| 2829 | if (mstat & D_RTS(ch)) |
| 2830 | result |= TIOCM_RTS; |
| 2831 | if (mstat & D_CTS(ch)) |
| 2832 | result |= TIOCM_CTS; |
| 2833 | if (mstat & D_DSR(ch)) |
| 2834 | result |= TIOCM_DSR; |
| 2835 | if (mstat & D_RI(ch)) |
| 2836 | result |= TIOCM_RI; |
| 2837 | if (mstat & D_CD(ch)) |
| 2838 | result |= TIOCM_CD; |
| 2839 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2840 | return result; |
| 2841 | } |
| 2842 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2843 | /* |
| 2844 | * dgap_tty_tiocmset() |
| 2845 | * |
| 2846 | * Set modem signals, called by ld. |
| 2847 | */ |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2848 | static int dgap_tty_tiocmset(struct tty_struct *tty, |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2849 | unsigned int set, unsigned int clear) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2850 | { |
| 2851 | struct board_t *bd; |
| 2852 | struct channel_t *ch; |
| 2853 | struct un_t *un; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2854 | ulong lock_flags; |
| 2855 | ulong lock_flags2; |
| 2856 | |
| 2857 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2858 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2859 | |
| 2860 | un = tty->driver_data; |
| 2861 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2862 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2863 | |
| 2864 | ch = un->un_ch; |
| 2865 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2866 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2867 | |
| 2868 | bd = ch->ch_bd; |
| 2869 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2870 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2871 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2872 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 2873 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2874 | |
| 2875 | if (set & TIOCM_RTS) { |
| 2876 | ch->ch_mforce |= D_RTS(ch); |
| 2877 | ch->ch_mval |= D_RTS(ch); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2878 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2879 | |
| 2880 | if (set & TIOCM_DTR) { |
| 2881 | ch->ch_mforce |= D_DTR(ch); |
| 2882 | ch->ch_mval |= D_DTR(ch); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2883 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2884 | |
| 2885 | if (clear & TIOCM_RTS) { |
| 2886 | ch->ch_mforce |= D_RTS(ch); |
| 2887 | ch->ch_mval &= ~(D_RTS(ch)); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2888 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2889 | |
| 2890 | if (clear & TIOCM_DTR) { |
| 2891 | ch->ch_mforce |= D_DTR(ch); |
| 2892 | ch->ch_mval &= ~(D_DTR(ch)); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2893 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2894 | |
| 2895 | dgap_param(tty); |
| 2896 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2897 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 2898 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2899 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2900 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2901 | } |
| 2902 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2903 | /* |
| 2904 | * dgap_tty_send_break() |
| 2905 | * |
| 2906 | * Send a Break, called by ld. |
| 2907 | */ |
| 2908 | static int dgap_tty_send_break(struct tty_struct *tty, int msec) |
| 2909 | { |
| 2910 | struct board_t *bd; |
| 2911 | struct channel_t *ch; |
| 2912 | struct un_t *un; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2913 | ulong lock_flags; |
| 2914 | ulong lock_flags2; |
| 2915 | |
| 2916 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2917 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2918 | |
| 2919 | un = tty->driver_data; |
| 2920 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2921 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2922 | |
| 2923 | ch = un->un_ch; |
| 2924 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2925 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2926 | |
| 2927 | bd = ch->ch_bd; |
| 2928 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2929 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2930 | |
| 2931 | switch (msec) { |
| 2932 | case -1: |
| 2933 | msec = 0xFFFF; |
| 2934 | break; |
| 2935 | case 0: |
| 2936 | msec = 1; |
| 2937 | break; |
| 2938 | default: |
| 2939 | msec /= 10; |
| 2940 | break; |
| 2941 | } |
| 2942 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2943 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 2944 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2945 | #if 0 |
| 2946 | dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0); |
| 2947 | #endif |
| 2948 | dgap_cmdw(ch, SBREAK, (u16) msec, 0); |
| 2949 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2950 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 2951 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2952 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2953 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2954 | } |
| 2955 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2956 | /* |
| 2957 | * dgap_tty_wait_until_sent() |
| 2958 | * |
| 2959 | * wait until data has been transmitted, called by ld. |
| 2960 | */ |
| 2961 | static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout) |
| 2962 | { |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 2963 | dgap_wait_for_drain(tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2964 | } |
| 2965 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2966 | /* |
| 2967 | * dgap_send_xchar() |
| 2968 | * |
| 2969 | * send a high priority character, called by ld. |
| 2970 | */ |
| 2971 | static void dgap_tty_send_xchar(struct tty_struct *tty, char c) |
| 2972 | { |
| 2973 | struct board_t *bd; |
| 2974 | struct channel_t *ch; |
| 2975 | struct un_t *un; |
| 2976 | ulong lock_flags; |
| 2977 | ulong lock_flags2; |
| 2978 | |
| 2979 | if (!tty || tty->magic != TTY_MAGIC) |
| 2980 | return; |
| 2981 | |
| 2982 | un = tty->driver_data; |
| 2983 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 2984 | return; |
| 2985 | |
| 2986 | ch = un->un_ch; |
| 2987 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 2988 | return; |
| 2989 | |
| 2990 | bd = ch->ch_bd; |
| 2991 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 2992 | return; |
| 2993 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2994 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 2995 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2996 | |
| 2997 | /* |
| 2998 | * This is technically what we should do. |
| 2999 | * However, the NIST tests specifically want |
| 3000 | * to see each XON or XOFF character that it |
| 3001 | * sends, so lets just send each character |
| 3002 | * by hand... |
| 3003 | */ |
| 3004 | #if 0 |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3005 | if (c == STOP_CHAR(tty)) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3006 | dgap_cmdw(ch, RPAUSE, 0, 0); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3007 | else if (c == START_CHAR(tty)) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3008 | dgap_cmdw(ch, RRESUME, 0, 0); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3009 | else |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3010 | dgap_wmove(ch, &c, 1); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3011 | #else |
| 3012 | dgap_wmove(ch, &c, 1); |
| 3013 | #endif |
| 3014 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3015 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3016 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3017 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3018 | return; |
| 3019 | } |
| 3020 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3021 | /* |
| 3022 | * Return modem signals to ld. |
| 3023 | */ |
| 3024 | static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value) |
| 3025 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 3026 | int result; |
| 3027 | u8 mstat; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3028 | ulong lock_flags; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 3029 | int rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3030 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3031 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 3032 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3033 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3034 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3035 | |
| 3036 | mstat = readb(&(ch->ch_bs->m_stat)); |
| 3037 | /* Append any outbound signals that might be pending... */ |
| 3038 | mstat |= ch->ch_mostat; |
| 3039 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3040 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3041 | |
| 3042 | result = 0; |
| 3043 | |
| 3044 | if (mstat & D_DTR(ch)) |
| 3045 | result |= TIOCM_DTR; |
| 3046 | if (mstat & D_RTS(ch)) |
| 3047 | result |= TIOCM_RTS; |
| 3048 | if (mstat & D_CTS(ch)) |
| 3049 | result |= TIOCM_CTS; |
| 3050 | if (mstat & D_DSR(ch)) |
| 3051 | result |= TIOCM_DSR; |
| 3052 | if (mstat & D_RI(ch)) |
| 3053 | result |= TIOCM_RI; |
| 3054 | if (mstat & D_CD(ch)) |
| 3055 | result |= TIOCM_CD; |
| 3056 | |
| 3057 | rc = put_user(result, value); |
| 3058 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3059 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3060 | } |
| 3061 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3062 | /* |
| 3063 | * dgap_set_modem_info() |
| 3064 | * |
| 3065 | * Set modem signals, called by ld. |
| 3066 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 3067 | static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, |
| 3068 | unsigned int __user *value) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3069 | { |
| 3070 | struct board_t *bd; |
| 3071 | struct channel_t *ch; |
| 3072 | struct un_t *un; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 3073 | int ret; |
| 3074 | unsigned int arg; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3075 | ulong lock_flags; |
| 3076 | ulong lock_flags2; |
| 3077 | |
| 3078 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 3079 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3080 | |
| 3081 | un = tty->driver_data; |
| 3082 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 3083 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3084 | |
| 3085 | ch = un->un_ch; |
| 3086 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 3087 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3088 | |
| 3089 | bd = ch->ch_bd; |
| 3090 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 3091 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3092 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3093 | ret = get_user(arg, value); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3094 | if (ret) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3095 | return ret; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3096 | |
| 3097 | switch (command) { |
| 3098 | case TIOCMBIS: |
| 3099 | if (arg & TIOCM_RTS) { |
| 3100 | ch->ch_mforce |= D_RTS(ch); |
| 3101 | ch->ch_mval |= D_RTS(ch); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3102 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3103 | |
| 3104 | if (arg & TIOCM_DTR) { |
| 3105 | ch->ch_mforce |= D_DTR(ch); |
| 3106 | ch->ch_mval |= D_DTR(ch); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3107 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3108 | |
| 3109 | break; |
| 3110 | |
| 3111 | case TIOCMBIC: |
| 3112 | if (arg & TIOCM_RTS) { |
| 3113 | ch->ch_mforce |= D_RTS(ch); |
| 3114 | ch->ch_mval &= ~(D_RTS(ch)); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3115 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3116 | |
| 3117 | if (arg & TIOCM_DTR) { |
| 3118 | ch->ch_mforce |= D_DTR(ch); |
| 3119 | ch->ch_mval &= ~(D_DTR(ch)); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3120 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3121 | |
| 3122 | break; |
| 3123 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3124 | case TIOCMSET: |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3125 | ch->ch_mforce = D_DTR(ch)|D_RTS(ch); |
| 3126 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3127 | if (arg & TIOCM_RTS) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3128 | ch->ch_mval |= D_RTS(ch); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3129 | else |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3130 | ch->ch_mval &= ~(D_RTS(ch)); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3131 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3132 | if (arg & TIOCM_DTR) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3133 | ch->ch_mval |= (D_DTR(ch)); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3134 | else |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3135 | ch->ch_mval &= ~(D_DTR(ch)); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3136 | |
| 3137 | break; |
| 3138 | |
| 3139 | default: |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3140 | return -EINVAL; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3141 | } |
| 3142 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3143 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3144 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3145 | |
| 3146 | dgap_param(tty); |
| 3147 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3148 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3149 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3150 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3151 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3152 | } |
| 3153 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3154 | /* |
| 3155 | * dgap_tty_digigeta() |
| 3156 | * |
| 3157 | * Ioctl to get the information for ditty. |
| 3158 | * |
| 3159 | * |
| 3160 | * |
| 3161 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 3162 | static int dgap_tty_digigeta(struct tty_struct *tty, |
| 3163 | struct digi_t __user *retinfo) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3164 | { |
| 3165 | struct channel_t *ch; |
| 3166 | struct un_t *un; |
| 3167 | struct digi_t tmp; |
| 3168 | ulong lock_flags; |
| 3169 | |
| 3170 | if (!retinfo) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3171 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3172 | |
| 3173 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3174 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3175 | |
| 3176 | un = tty->driver_data; |
| 3177 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3178 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3179 | |
| 3180 | ch = un->un_ch; |
| 3181 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3182 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3183 | |
| 3184 | memset(&tmp, 0, sizeof(tmp)); |
| 3185 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3186 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3187 | memcpy(&tmp, &ch->ch_digi, sizeof(tmp)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3188 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3189 | |
| 3190 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3191 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3192 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3193 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3194 | } |
| 3195 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3196 | /* |
| 3197 | * dgap_tty_digiseta() |
| 3198 | * |
| 3199 | * Ioctl to set the information for ditty. |
| 3200 | * |
| 3201 | * |
| 3202 | * |
| 3203 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 3204 | static int dgap_tty_digiseta(struct tty_struct *tty, |
| 3205 | struct digi_t __user *new_info) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3206 | { |
| 3207 | struct board_t *bd; |
| 3208 | struct channel_t *ch; |
| 3209 | struct un_t *un; |
| 3210 | struct digi_t new_digi; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3211 | ulong lock_flags = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3212 | unsigned long lock_flags2; |
| 3213 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3214 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3215 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3216 | |
| 3217 | un = tty->driver_data; |
| 3218 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3219 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3220 | |
| 3221 | ch = un->un_ch; |
| 3222 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3223 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3224 | |
| 3225 | bd = ch->ch_bd; |
| 3226 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3227 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3228 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3229 | if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t))) |
| 3230 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3231 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3232 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3233 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3234 | |
| 3235 | memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t)); |
| 3236 | |
| 3237 | if (ch->ch_digi.digi_maxcps < 1) |
| 3238 | ch->ch_digi.digi_maxcps = 1; |
| 3239 | |
| 3240 | if (ch->ch_digi.digi_maxcps > 10000) |
| 3241 | ch->ch_digi.digi_maxcps = 10000; |
| 3242 | |
| 3243 | if (ch->ch_digi.digi_bufsize < 10) |
| 3244 | ch->ch_digi.digi_bufsize = 10; |
| 3245 | |
| 3246 | if (ch->ch_digi.digi_maxchar < 1) |
| 3247 | ch->ch_digi.digi_maxchar = 1; |
| 3248 | |
| 3249 | if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize) |
| 3250 | ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize; |
| 3251 | |
| 3252 | if (ch->ch_digi.digi_onlen > DIGI_PLEN) |
| 3253 | ch->ch_digi.digi_onlen = DIGI_PLEN; |
| 3254 | |
| 3255 | if (ch->ch_digi.digi_offlen > DIGI_PLEN) |
| 3256 | ch->ch_digi.digi_offlen = DIGI_PLEN; |
| 3257 | |
| 3258 | dgap_param(tty); |
| 3259 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3260 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3261 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3262 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3263 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3264 | } |
| 3265 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3266 | /* |
| 3267 | * dgap_tty_digigetedelay() |
| 3268 | * |
| 3269 | * Ioctl to get the current edelay setting. |
| 3270 | * |
| 3271 | * |
| 3272 | * |
| 3273 | */ |
| 3274 | static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo) |
| 3275 | { |
| 3276 | struct channel_t *ch; |
| 3277 | struct un_t *un; |
| 3278 | int tmp; |
| 3279 | ulong lock_flags; |
| 3280 | |
| 3281 | if (!retinfo) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3282 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3283 | |
| 3284 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3285 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3286 | |
| 3287 | un = tty->driver_data; |
| 3288 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3289 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3290 | |
| 3291 | ch = un->un_ch; |
| 3292 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3293 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3294 | |
| 3295 | memset(&tmp, 0, sizeof(tmp)); |
| 3296 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3297 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3298 | tmp = readw(&(ch->ch_bs->edelay)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3299 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3300 | |
| 3301 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3302 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3303 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3304 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3305 | } |
| 3306 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3307 | /* |
| 3308 | * dgap_tty_digisetedelay() |
| 3309 | * |
| 3310 | * Ioctl to set the EDELAY setting |
| 3311 | * |
| 3312 | */ |
| 3313 | static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info) |
| 3314 | { |
| 3315 | struct board_t *bd; |
| 3316 | struct channel_t *ch; |
| 3317 | struct un_t *un; |
| 3318 | int new_digi; |
| 3319 | ulong lock_flags; |
| 3320 | ulong lock_flags2; |
| 3321 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3322 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3323 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3324 | |
| 3325 | un = tty->driver_data; |
| 3326 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3327 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3328 | |
| 3329 | ch = un->un_ch; |
| 3330 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3331 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3332 | |
| 3333 | bd = ch->ch_bd; |
| 3334 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3335 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3336 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3337 | if (copy_from_user(&new_digi, new_info, sizeof(int))) |
| 3338 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3339 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3340 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3341 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3342 | |
| 3343 | writew((u16) new_digi, &(ch->ch_bs->edelay)); |
| 3344 | |
| 3345 | dgap_param(tty); |
| 3346 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3347 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3348 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3349 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3350 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3351 | } |
| 3352 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3353 | /* |
| 3354 | * dgap_tty_digigetcustombaud() |
| 3355 | * |
| 3356 | * Ioctl to get the current custom baud rate setting. |
| 3357 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 3358 | static int dgap_tty_digigetcustombaud(struct tty_struct *tty, |
| 3359 | int __user *retinfo) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3360 | { |
| 3361 | struct channel_t *ch; |
| 3362 | struct un_t *un; |
| 3363 | int tmp; |
| 3364 | ulong lock_flags; |
| 3365 | |
| 3366 | if (!retinfo) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3367 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3368 | |
| 3369 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3370 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3371 | |
| 3372 | un = tty->driver_data; |
| 3373 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3374 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3375 | |
| 3376 | ch = un->un_ch; |
| 3377 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3378 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3379 | |
| 3380 | memset(&tmp, 0, sizeof(tmp)); |
| 3381 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3382 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3383 | tmp = dgap_get_custom_baud(ch); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3384 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3385 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3386 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3387 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3388 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3389 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3390 | } |
| 3391 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3392 | /* |
| 3393 | * dgap_tty_digisetcustombaud() |
| 3394 | * |
| 3395 | * Ioctl to set the custom baud rate setting |
| 3396 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 3397 | static int dgap_tty_digisetcustombaud(struct tty_struct *tty, |
| 3398 | int __user *new_info) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3399 | { |
| 3400 | struct board_t *bd; |
| 3401 | struct channel_t *ch; |
| 3402 | struct un_t *un; |
| 3403 | uint new_rate; |
| 3404 | ulong lock_flags; |
| 3405 | ulong lock_flags2; |
| 3406 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3407 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3408 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3409 | |
| 3410 | un = tty->driver_data; |
| 3411 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3412 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3413 | |
| 3414 | ch = un->un_ch; |
| 3415 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3416 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3417 | |
| 3418 | bd = ch->ch_bd; |
| 3419 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3420 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3421 | |
| 3422 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3423 | if (copy_from_user(&new_rate, new_info, sizeof(unsigned int))) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3424 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3425 | |
| 3426 | if (bd->bd_flags & BD_FEP5PLUS) { |
| 3427 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3428 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3429 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3430 | |
| 3431 | ch->ch_custom_speed = new_rate; |
| 3432 | |
| 3433 | dgap_param(tty); |
| 3434 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3435 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3436 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3437 | } |
| 3438 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3439 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3440 | } |
| 3441 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3442 | /* |
| 3443 | * dgap_set_termios() |
| 3444 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 3445 | static void dgap_tty_set_termios(struct tty_struct *tty, |
| 3446 | struct ktermios *old_termios) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3447 | { |
| 3448 | struct board_t *bd; |
| 3449 | struct channel_t *ch; |
| 3450 | struct un_t *un; |
| 3451 | unsigned long lock_flags; |
| 3452 | unsigned long lock_flags2; |
| 3453 | |
| 3454 | if (!tty || tty->magic != TTY_MAGIC) |
| 3455 | return; |
| 3456 | |
| 3457 | un = tty->driver_data; |
| 3458 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 3459 | return; |
| 3460 | |
| 3461 | ch = un->un_ch; |
| 3462 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 3463 | return; |
| 3464 | |
| 3465 | bd = ch->ch_bd; |
| 3466 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 3467 | return; |
| 3468 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3469 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3470 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3471 | |
| 3472 | ch->ch_c_cflag = tty->termios.c_cflag; |
| 3473 | ch->ch_c_iflag = tty->termios.c_iflag; |
| 3474 | ch->ch_c_oflag = tty->termios.c_oflag; |
| 3475 | ch->ch_c_lflag = tty->termios.c_lflag; |
| 3476 | ch->ch_startc = tty->termios.c_cc[VSTART]; |
| 3477 | ch->ch_stopc = tty->termios.c_cc[VSTOP]; |
| 3478 | |
| 3479 | dgap_carrier(ch); |
| 3480 | dgap_param(tty); |
| 3481 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3482 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3483 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3484 | } |
| 3485 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3486 | static void dgap_tty_throttle(struct tty_struct *tty) |
| 3487 | { |
| 3488 | struct board_t *bd; |
| 3489 | struct channel_t *ch; |
| 3490 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3491 | ulong lock_flags; |
| 3492 | ulong lock_flags2; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3493 | |
| 3494 | if (!tty || tty->magic != TTY_MAGIC) |
| 3495 | return; |
| 3496 | |
| 3497 | un = tty->driver_data; |
| 3498 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 3499 | return; |
| 3500 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3501 | ch = un->un_ch; |
| 3502 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3503 | return; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3504 | |
| 3505 | bd = ch->ch_bd; |
| 3506 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 3507 | return; |
| 3508 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3509 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3510 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3511 | |
| 3512 | ch->ch_flags |= (CH_RXBLOCK); |
| 3513 | #if 1 |
| 3514 | dgap_cmdw(ch, RPAUSE, 0, 0); |
| 3515 | #endif |
| 3516 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3517 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3518 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3519 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3520 | } |
| 3521 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3522 | static void dgap_tty_unthrottle(struct tty_struct *tty) |
| 3523 | { |
| 3524 | struct board_t *bd; |
| 3525 | struct channel_t *ch; |
| 3526 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3527 | ulong lock_flags; |
| 3528 | ulong lock_flags2; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3529 | |
| 3530 | if (!tty || tty->magic != TTY_MAGIC) |
| 3531 | return; |
| 3532 | |
| 3533 | un = tty->driver_data; |
| 3534 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 3535 | return; |
| 3536 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3537 | ch = un->un_ch; |
| 3538 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3539 | return; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3540 | |
| 3541 | bd = ch->ch_bd; |
| 3542 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 3543 | return; |
| 3544 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3545 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3546 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3547 | |
| 3548 | ch->ch_flags &= ~(CH_RXBLOCK); |
| 3549 | |
| 3550 | #if 1 |
| 3551 | dgap_cmdw(ch, RRESUME, 0, 0); |
| 3552 | #endif |
| 3553 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3554 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3555 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3556 | } |
| 3557 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3558 | static void dgap_tty_start(struct tty_struct *tty) |
| 3559 | { |
| 3560 | struct board_t *bd; |
| 3561 | struct channel_t *ch; |
| 3562 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3563 | ulong lock_flags; |
| 3564 | ulong lock_flags2; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3565 | |
| 3566 | if (!tty || tty->magic != TTY_MAGIC) |
| 3567 | return; |
| 3568 | |
| 3569 | un = tty->driver_data; |
| 3570 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 3571 | return; |
| 3572 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3573 | ch = un->un_ch; |
| 3574 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3575 | return; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3576 | |
| 3577 | bd = ch->ch_bd; |
| 3578 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 3579 | return; |
| 3580 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3581 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3582 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3583 | |
| 3584 | dgap_cmdw(ch, RESUMETX, 0, 0); |
| 3585 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3586 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3587 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3588 | } |
| 3589 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3590 | static void dgap_tty_stop(struct tty_struct *tty) |
| 3591 | { |
| 3592 | struct board_t *bd; |
| 3593 | struct channel_t *ch; |
| 3594 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3595 | ulong lock_flags; |
| 3596 | ulong lock_flags2; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3597 | |
| 3598 | if (!tty || tty->magic != TTY_MAGIC) |
| 3599 | return; |
| 3600 | |
| 3601 | un = tty->driver_data; |
| 3602 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 3603 | return; |
| 3604 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3605 | ch = un->un_ch; |
| 3606 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3607 | return; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3608 | |
| 3609 | bd = ch->ch_bd; |
| 3610 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 3611 | return; |
| 3612 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3613 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3614 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3615 | |
| 3616 | dgap_cmdw(ch, PAUSETX, 0, 0); |
| 3617 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3618 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3619 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3620 | } |
| 3621 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3622 | /* |
| 3623 | * dgap_tty_flush_chars() |
| 3624 | * |
| 3625 | * Flush the cook buffer |
| 3626 | * |
| 3627 | * Note to self, and any other poor souls who venture here: |
| 3628 | * |
| 3629 | * flush in this case DOES NOT mean dispose of the data. |
| 3630 | * instead, it means "stop buffering and send it if you |
| 3631 | * haven't already." Just guess how I figured that out... SRW 2-Jun-98 |
| 3632 | * |
| 3633 | * It is also always called in interrupt context - JAR 8-Sept-99 |
| 3634 | */ |
| 3635 | static void dgap_tty_flush_chars(struct tty_struct *tty) |
| 3636 | { |
| 3637 | struct board_t *bd; |
| 3638 | struct channel_t *ch; |
| 3639 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3640 | ulong lock_flags; |
| 3641 | ulong lock_flags2; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3642 | |
| 3643 | if (!tty || tty->magic != TTY_MAGIC) |
| 3644 | return; |
| 3645 | |
| 3646 | un = tty->driver_data; |
| 3647 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 3648 | return; |
| 3649 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3650 | ch = un->un_ch; |
| 3651 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3652 | return; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3653 | |
| 3654 | bd = ch->ch_bd; |
| 3655 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 3656 | return; |
| 3657 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3658 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3659 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3660 | |
| 3661 | /* TODO: Do something here */ |
| 3662 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3663 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3664 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3665 | } |
| 3666 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3667 | /* |
| 3668 | * dgap_tty_flush_buffer() |
| 3669 | * |
| 3670 | * Flush Tx buffer (make in == out) |
| 3671 | */ |
| 3672 | static void dgap_tty_flush_buffer(struct tty_struct *tty) |
| 3673 | { |
| 3674 | struct board_t *bd; |
| 3675 | struct channel_t *ch; |
| 3676 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3677 | ulong lock_flags; |
| 3678 | ulong lock_flags2; |
| 3679 | u16 head; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3680 | |
| 3681 | if (!tty || tty->magic != TTY_MAGIC) |
| 3682 | return; |
| 3683 | |
| 3684 | un = tty->driver_data; |
| 3685 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 3686 | return; |
| 3687 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3688 | ch = un->un_ch; |
| 3689 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3690 | return; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3691 | |
| 3692 | bd = ch->ch_bd; |
| 3693 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 3694 | return; |
| 3695 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3696 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3697 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3698 | |
| 3699 | ch->ch_flags &= ~CH_STOP; |
| 3700 | head = readw(&(ch->ch_bs->tx_head)); |
| 3701 | dgap_cmdw(ch, FLUSHTX, (u16) head, 0); |
| 3702 | dgap_cmdw(ch, RESUMETX, 0, 0); |
| 3703 | if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) { |
| 3704 | ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY); |
| 3705 | wake_up_interruptible(&ch->ch_tun.un_flags_wait); |
| 3706 | } |
| 3707 | if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) { |
| 3708 | ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY); |
| 3709 | wake_up_interruptible(&ch->ch_pun.un_flags_wait); |
| 3710 | } |
| 3711 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3712 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3713 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3714 | if (waitqueue_active(&tty->write_wait)) |
| 3715 | wake_up_interruptible(&tty->write_wait); |
| 3716 | tty_wakeup(tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3717 | } |
| 3718 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3719 | /***************************************************************************** |
| 3720 | * |
| 3721 | * The IOCTL function and all of its helpers |
| 3722 | * |
| 3723 | *****************************************************************************/ |
| 3724 | |
| 3725 | /* |
| 3726 | * dgap_tty_ioctl() |
| 3727 | * |
| 3728 | * The usual assortment of ioctl's |
| 3729 | */ |
| 3730 | static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, |
| 3731 | unsigned long arg) |
| 3732 | { |
| 3733 | struct board_t *bd; |
| 3734 | struct channel_t *ch; |
| 3735 | struct un_t *un; |
| 3736 | int rc; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3737 | u16 head; |
| 3738 | ulong lock_flags = 0; |
| 3739 | ulong lock_flags2 = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3740 | void __user *uarg = (void __user *) arg; |
| 3741 | |
| 3742 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3743 | return -ENODEV; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3744 | |
| 3745 | un = tty->driver_data; |
| 3746 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3747 | return -ENODEV; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3748 | |
| 3749 | ch = un->un_ch; |
| 3750 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3751 | return -ENODEV; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3752 | |
| 3753 | bd = ch->ch_bd; |
| 3754 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3755 | return -ENODEV; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3756 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3757 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3758 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3759 | |
| 3760 | if (un->un_open_count <= 0) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3761 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3762 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3763 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3764 | } |
| 3765 | |
| 3766 | switch (cmd) { |
| 3767 | |
| 3768 | /* Here are all the standard ioctl's that we MUST implement */ |
| 3769 | |
| 3770 | case TCSBRK: |
| 3771 | /* |
| 3772 | * TCSBRK is SVID version: non-zero arg --> no break |
| 3773 | * this behaviour is exploited by tcdrain(). |
| 3774 | * |
| 3775 | * According to POSIX.1 spec (7.2.2.1.2) breaks should be |
| 3776 | * between 0.25 and 0.5 seconds so we'll ask for something |
| 3777 | * in the middle: 0.375 seconds. |
| 3778 | */ |
| 3779 | rc = tty_check_change(tty); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3780 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3781 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3782 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3783 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3784 | |
| 3785 | rc = dgap_wait_for_drain(tty); |
| 3786 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3787 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3788 | return -EINTR; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3789 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3790 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3791 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3792 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3793 | if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP)) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3794 | dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3795 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3796 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3797 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3798 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3799 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3800 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3801 | case TCSBRKP: |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3802 | /* support for POSIX tcsendbreak() |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3803 | |
| 3804 | * According to POSIX.1 spec (7.2.2.1.2) breaks should be |
| 3805 | * between 0.25 and 0.5 seconds so we'll ask for something |
| 3806 | * in the middle: 0.375 seconds. |
| 3807 | */ |
| 3808 | rc = tty_check_change(tty); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3809 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3810 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3811 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3812 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3813 | |
| 3814 | rc = dgap_wait_for_drain(tty); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3815 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3816 | return -EINTR; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3817 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3818 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3819 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3820 | |
| 3821 | dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0); |
| 3822 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3823 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3824 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3825 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3826 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3827 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3828 | case TIOCSBRK: |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3829 | /* |
| 3830 | * FEP5 doesn't support turning on a break unconditionally. |
| 3831 | * The FEP5 device will stop sending a break automatically |
| 3832 | * after the specified time value that was sent when turning on |
| 3833 | * the break. |
| 3834 | */ |
| 3835 | rc = tty_check_change(tty); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3836 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3837 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3838 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3839 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3840 | |
| 3841 | rc = dgap_wait_for_drain(tty); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3842 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3843 | return -EINTR; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3844 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3845 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3846 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3847 | |
| 3848 | dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0); |
| 3849 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3850 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3851 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3852 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3853 | return 0; |
| 3854 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3855 | case TIOCCBRK: |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3856 | /* |
| 3857 | * FEP5 doesn't support turning off a break unconditionally. |
| 3858 | * The FEP5 device will stop sending a break automatically |
| 3859 | * after the specified time value that was sent when turning on |
| 3860 | * the break. |
| 3861 | */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3862 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3863 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3864 | return 0; |
| 3865 | |
| 3866 | case TIOCGSOFTCAR: |
| 3867 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3868 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3869 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3870 | |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 3871 | rc = put_user(C_CLOCAL(tty) ? 1 : 0, |
| 3872 | (unsigned long __user *) arg); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3873 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3874 | |
| 3875 | case TIOCSSOFTCAR: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3876 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3877 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3878 | |
| 3879 | rc = get_user(arg, (unsigned long __user *) arg); |
| 3880 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3881 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3882 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3883 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3884 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 3885 | tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | |
| 3886 | (arg ? CLOCAL : 0)); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3887 | dgap_param(tty); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3888 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3889 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3890 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3891 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3892 | |
| 3893 | case TIOCMGET: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3894 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3895 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3896 | return dgap_get_modem_info(ch, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3897 | |
| 3898 | case TIOCMBIS: |
| 3899 | case TIOCMBIC: |
| 3900 | case TIOCMSET: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3901 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3902 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3903 | return dgap_set_modem_info(tty, cmd, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3904 | |
| 3905 | /* |
| 3906 | * Here are any additional ioctl's that we want to implement |
| 3907 | */ |
| 3908 | |
| 3909 | case TCFLSH: |
| 3910 | /* |
| 3911 | * The linux tty driver doesn't have a flush |
| 3912 | * input routine for the driver, assuming all backed |
| 3913 | * up data is in the line disc. buffers. However, |
| 3914 | * we all know that's not the case. Here, we |
| 3915 | * act on the ioctl, but then lie and say we didn't |
| 3916 | * so the line discipline will process the flush |
| 3917 | * also. |
| 3918 | */ |
| 3919 | rc = tty_check_change(tty); |
| 3920 | if (rc) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3921 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3922 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3923 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) { |
| 3927 | if (!(un->un_type == DGAP_PRINT)) { |
| 3928 | head = readw(&(ch->ch_bs->rx_head)); |
| 3929 | writew(head, &(ch->ch_bs->rx_tail)); |
| 3930 | writeb(0, &(ch->ch_bs->orun)); |
| 3931 | } |
| 3932 | } |
| 3933 | |
Mark Hounschell | 70d97a6 | 2014-03-10 14:39:41 -0400 | [diff] [blame] | 3934 | if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) { |
| 3935 | /* pretend we didn't recognize this IOCTL */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3936 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3937 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | 70d97a6 | 2014-03-10 14:39:41 -0400 | [diff] [blame] | 3938 | |
| 3939 | return -ENOIOCTLCMD; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3940 | } |
| 3941 | |
Mark Hounschell | 70d97a6 | 2014-03-10 14:39:41 -0400 | [diff] [blame] | 3942 | ch->ch_flags &= ~CH_STOP; |
| 3943 | head = readw(&(ch->ch_bs->tx_head)); |
| 3944 | dgap_cmdw(ch, FLUSHTX, (u16) head, 0); |
| 3945 | dgap_cmdw(ch, RESUMETX, 0, 0); |
| 3946 | if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) { |
| 3947 | ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY); |
| 3948 | wake_up_interruptible(&ch->ch_tun.un_flags_wait); |
| 3949 | } |
| 3950 | if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) { |
| 3951 | ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY); |
| 3952 | wake_up_interruptible(&ch->ch_pun.un_flags_wait); |
| 3953 | } |
| 3954 | if (waitqueue_active(&tty->write_wait)) |
| 3955 | wake_up_interruptible(&tty->write_wait); |
| 3956 | |
| 3957 | /* Can't hold any locks when calling tty_wakeup! */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3958 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3959 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | 70d97a6 | 2014-03-10 14:39:41 -0400 | [diff] [blame] | 3960 | tty_wakeup(tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3961 | |
Mark Hounschell | 70d97a6 | 2014-03-10 14:39:41 -0400 | [diff] [blame] | 3962 | /* pretend we didn't recognize this IOCTL */ |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3963 | return -ENOIOCTLCMD; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3964 | |
| 3965 | case TCSETSF: |
| 3966 | case TCSETSW: |
| 3967 | /* |
| 3968 | * The linux tty driver doesn't have a flush |
| 3969 | * input routine for the driver, assuming all backed |
| 3970 | * up data is in the line disc. buffers. However, |
| 3971 | * we all know that's not the case. Here, we |
| 3972 | * act on the ioctl, but then lie and say we didn't |
| 3973 | * so the line discipline will process the flush |
| 3974 | * also. |
| 3975 | */ |
| 3976 | if (cmd == TCSETSF) { |
| 3977 | /* flush rx */ |
| 3978 | ch->ch_flags &= ~CH_STOP; |
| 3979 | head = readw(&(ch->ch_bs->rx_head)); |
| 3980 | writew(head, &(ch->ch_bs->rx_tail)); |
| 3981 | } |
| 3982 | |
| 3983 | /* now wait for all the output to drain */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3984 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3985 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3986 | rc = dgap_wait_for_drain(tty); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3987 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3988 | return -EINTR; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3989 | |
| 3990 | /* pretend we didn't recognize this */ |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3991 | return -ENOIOCTLCMD; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3992 | |
| 3993 | case TCSETAW: |
| 3994 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3995 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3996 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3997 | rc = dgap_wait_for_drain(tty); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3998 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3999 | return -EINTR; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4000 | |
| 4001 | /* pretend we didn't recognize this */ |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 4002 | return -ENOIOCTLCMD; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4003 | |
| 4004 | case TCXONC: |
| 4005 | /* |
| 4006 | * The Linux Line Discipline (LD) would do this for us if we |
| 4007 | * let it, but we have the special firmware options to do this |
| 4008 | * the "right way" regardless of hardware or software flow |
| 4009 | * control so we'll do it outselves instead of letting the LD |
| 4010 | * do it. |
| 4011 | */ |
| 4012 | rc = tty_check_change(tty); |
| 4013 | if (rc) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4014 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 4015 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 4016 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4017 | } |
| 4018 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4019 | switch (arg) { |
| 4020 | |
| 4021 | case TCOON: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4022 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 4023 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4024 | dgap_tty_start(tty); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 4025 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4026 | case TCOOFF: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4027 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 4028 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4029 | dgap_tty_stop(tty); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 4030 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4031 | case TCION: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4032 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 4033 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4034 | /* Make the ld do it */ |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 4035 | return -ENOIOCTLCMD; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4036 | case TCIOFF: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4037 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 4038 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4039 | /* Make the ld do it */ |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 4040 | return -ENOIOCTLCMD; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4041 | default: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4042 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 4043 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 4044 | return -EINVAL; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4045 | } |
| 4046 | |
| 4047 | case DIGI_GETA: |
| 4048 | /* get information for ditty */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4049 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 4050 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 4051 | return dgap_tty_digigeta(tty, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4052 | |
| 4053 | case DIGI_SETAW: |
| 4054 | case DIGI_SETAF: |
| 4055 | |
| 4056 | /* set information for ditty */ |
| 4057 | if (cmd == (DIGI_SETAW)) { |
| 4058 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4059 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 4060 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4061 | rc = dgap_wait_for_drain(tty); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4062 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 4063 | return -EINTR; |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4064 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 4065 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4066 | } else |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4067 | tty_ldisc_flush(tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4068 | /* fall thru */ |
| 4069 | |
| 4070 | case DIGI_SETA: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4071 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 4072 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 4073 | return dgap_tty_digiseta(tty, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4074 | |
| 4075 | case DIGI_GEDELAY: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4076 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 4077 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 4078 | return dgap_tty_digigetedelay(tty, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4079 | |
| 4080 | case DIGI_SEDELAY: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4081 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 4082 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 4083 | return dgap_tty_digisetedelay(tty, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4084 | |
| 4085 | case DIGI_GETCUSTOMBAUD: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4086 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 4087 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 4088 | return dgap_tty_digigetcustombaud(tty, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4089 | |
| 4090 | case DIGI_SETCUSTOMBAUD: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4091 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 4092 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 4093 | return dgap_tty_digisetcustombaud(tty, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4094 | |
| 4095 | case DIGI_RESET_PORT: |
| 4096 | dgap_firmware_reset_port(ch); |
| 4097 | dgap_param(tty); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4098 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 4099 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4100 | return 0; |
| 4101 | |
| 4102 | default: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4103 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 4104 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4105 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 4106 | return -ENOIOCTLCMD; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 4107 | } |
| 4108 | } |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4109 | |
| 4110 | static int dgap_after_config_loaded(int board) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4111 | { |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4112 | /* |
| 4113 | * Initialize KME waitqueues... |
| 4114 | */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 4115 | init_waitqueue_head(&(dgap_board[board]->kme_wait)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4116 | |
| 4117 | /* |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4118 | * allocate flip buffer for board. |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4119 | */ |
Mark Hounschell | 244a034 | 2014-05-23 14:02:34 -0400 | [diff] [blame] | 4120 | dgap_board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL); |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 4121 | if (!dgap_board[board]->flipbuf) |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4122 | return -ENOMEM; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4123 | |
Mark Hounschell | 244a034 | 2014-05-23 14:02:34 -0400 | [diff] [blame] | 4124 | dgap_board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_KERNEL); |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 4125 | if (!dgap_board[board]->flipflagbuf) { |
| 4126 | kfree(dgap_board[board]->flipbuf); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4127 | return -ENOMEM; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4128 | } |
| 4129 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4130 | return 0; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4131 | } |
| 4132 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4133 | /* |
| 4134 | * Create pr and tty device entries |
| 4135 | */ |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4136 | static int dgap_tty_register_ports(struct board_t *brd) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4137 | { |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4138 | struct channel_t *ch; |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4139 | int i; |
| 4140 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 4141 | brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports), |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4142 | GFP_KERNEL); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 4143 | if (!brd->serial_ports) |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4144 | return -ENOMEM; |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4145 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 4146 | brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports), |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4147 | GFP_KERNEL); |
Greg Kroah-Hartman | aec46bb | 2014-05-29 13:59:03 -0700 | [diff] [blame^] | 4148 | if (!brd->printer_ports) { |
| 4149 | kfree(brd->serial_ports); |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4150 | return -ENOMEM; |
Greg Kroah-Hartman | aec46bb | 2014-05-29 13:59:03 -0700 | [diff] [blame^] | 4151 | } |
Daeseok Youn | 0ade4a3 | 2014-05-26 19:24:17 +0900 | [diff] [blame] | 4152 | |
Daeseok Youn | a66369a | 2014-05-26 19:24:47 +0900 | [diff] [blame] | 4153 | for (i = 0; i < brd->nasync; i++) { |
| 4154 | tty_port_init(&brd->serial_ports[i]); |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 4155 | tty_port_init(&brd->printer_ports[i]); |
Daeseok Youn | a66369a | 2014-05-26 19:24:47 +0900 | [diff] [blame] | 4156 | } |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4157 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4158 | ch = brd->channels[0]; |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4159 | for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4160 | |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4161 | struct device *classp; |
| 4162 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 4163 | classp = tty_port_register_device(&brd->serial_ports[i], |
| 4164 | brd->serial_driver, |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4165 | brd->firstminor + i, NULL); |
| 4166 | |
| 4167 | dgap_create_tty_sysfs(&ch->ch_tun, classp); |
| 4168 | ch->ch_tun.un_sysfs = classp; |
| 4169 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 4170 | classp = tty_port_register_device(&brd->printer_ports[i], |
| 4171 | brd->print_driver, |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4172 | brd->firstminor + i, NULL); |
| 4173 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4174 | dgap_create_tty_sysfs(&ch->ch_pun, classp); |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4175 | ch->ch_pun.un_sysfs = classp; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4176 | } |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4177 | dgap_create_ports_sysfiles(brd); |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4178 | |
| 4179 | return 0; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4180 | } |
| 4181 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4182 | /* |
| 4183 | * Copies the BIOS code from the user to the board, |
| 4184 | * and starts the BIOS running. |
| 4185 | */ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4186 | static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4187 | { |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 4188 | u8 __iomem *addr; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4189 | uint offset; |
| 4190 | int i; |
| 4191 | |
| 4192 | if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase) |
| 4193 | return; |
| 4194 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4195 | addr = brd->re_map_membase; |
| 4196 | |
| 4197 | /* |
| 4198 | * clear POST area |
| 4199 | */ |
| 4200 | for (i = 0; i < 16; i++) |
| 4201 | writeb(0, addr + POSTAREA + i); |
| 4202 | |
| 4203 | /* |
| 4204 | * Download bios |
| 4205 | */ |
| 4206 | offset = 0x1000; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4207 | memcpy_toio(addr + offset, ubios, len); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4208 | |
| 4209 | writel(0x0bf00401, addr); |
| 4210 | writel(0, (addr + 4)); |
| 4211 | |
| 4212 | /* Clear the reset, and change states. */ |
| 4213 | writeb(FEPCLR, brd->re_map_port); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4214 | } |
| 4215 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4216 | /* |
| 4217 | * Checks to see if the BIOS completed running on the card. |
| 4218 | */ |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4219 | static int dgap_test_bios(struct board_t *brd) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4220 | { |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 4221 | u8 __iomem *addr; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4222 | u16 word; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4223 | u16 err1; |
| 4224 | u16 err2; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4225 | |
| 4226 | if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase) |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4227 | return -EINVAL; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4228 | |
| 4229 | addr = brd->re_map_membase; |
| 4230 | word = readw(addr + POSTAREA); |
| 4231 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4232 | /* |
| 4233 | * It can take 5-6 seconds for a board to |
| 4234 | * pass the bios self test and post results. |
| 4235 | * Give it 10 seconds. |
| 4236 | */ |
| 4237 | brd->wait_for_bios = 0; |
| 4238 | while (brd->wait_for_bios < 1000) { |
| 4239 | /* Check to see if BIOS thinks board is good. (GD). */ |
Mark Hounschell | bd3e43e | 2014-03-12 12:50:55 -0400 | [diff] [blame] | 4240 | if (word == *(u16 *) "GD") |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4241 | return 0; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4242 | msleep_interruptible(10); |
| 4243 | brd->wait_for_bios++; |
| 4244 | word = readw(addr + POSTAREA); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4245 | } |
| 4246 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4247 | /* Gave up on board after too long of time taken */ |
| 4248 | err1 = readw(addr + SEQUENCE); |
| 4249 | err2 = readw(addr + ERROR); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4250 | pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n", |
| 4251 | brd->name, err1, err2); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4252 | brd->state = BOARD_FAILED; |
| 4253 | brd->dpastatus = BD_NOBIOS; |
Mark Hounschell | bd3e43e | 2014-03-12 12:50:55 -0400 | [diff] [blame] | 4254 | |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4255 | return -EIO; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4256 | } |
| 4257 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4258 | /* |
| 4259 | * Copies the FEP code from the user to the board, |
| 4260 | * and starts the FEP running. |
| 4261 | */ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4262 | static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4263 | { |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 4264 | u8 __iomem *addr; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4265 | uint offset; |
| 4266 | |
| 4267 | if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase) |
| 4268 | return; |
| 4269 | |
| 4270 | addr = brd->re_map_membase; |
| 4271 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4272 | /* |
| 4273 | * Download FEP |
| 4274 | */ |
| 4275 | offset = 0x1000; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4276 | memcpy_toio(addr + offset, ufep, len); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4277 | |
| 4278 | /* |
| 4279 | * If board is a concentrator product, we need to give |
| 4280 | * it its config string describing how the concentrators look. |
| 4281 | */ |
| 4282 | if ((brd->type == PCX) || (brd->type == PEPC)) { |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4283 | u8 string[100]; |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4284 | u8 __iomem *config; |
| 4285 | u8 *xconfig; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4286 | int i = 0; |
| 4287 | |
| 4288 | xconfig = dgap_create_config_string(brd, string); |
| 4289 | |
| 4290 | /* Write string to board memory */ |
| 4291 | config = addr + CONFIG; |
| 4292 | for (; i < CONFIGSIZE; i++, config++, xconfig++) { |
| 4293 | writeb(*xconfig, config); |
| 4294 | if ((*xconfig & 0xff) == 0xff) |
| 4295 | break; |
| 4296 | } |
| 4297 | } |
| 4298 | |
| 4299 | writel(0xbfc01004, (addr + 0xc34)); |
| 4300 | writel(0x3, (addr + 0xc30)); |
| 4301 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4302 | } |
| 4303 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4304 | /* |
| 4305 | * Waits for the FEP to report thats its ready for us to use. |
| 4306 | */ |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4307 | static int dgap_test_fep(struct board_t *brd) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4308 | { |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 4309 | u8 __iomem *addr; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4310 | u16 word; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4311 | u16 err1; |
| 4312 | u16 err2; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4313 | |
| 4314 | if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase) |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4315 | return -EINVAL; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4316 | |
| 4317 | addr = brd->re_map_membase; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4318 | word = readw(addr + FEPSTAT); |
| 4319 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4320 | /* |
| 4321 | * It can take 2-3 seconds for the FEP to |
| 4322 | * be up and running. Give it 5 secs. |
| 4323 | */ |
| 4324 | brd->wait_for_fep = 0; |
| 4325 | while (brd->wait_for_fep < 500) { |
| 4326 | /* Check to see if FEP is up and running now. */ |
| 4327 | if (word == *(u16 *) "OS") { |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4328 | /* |
| 4329 | * Check to see if the board can support FEP5+ commands. |
| 4330 | */ |
| 4331 | word = readw(addr + FEP5_PLUS); |
| 4332 | if (word == *(u16 *) "5A") |
| 4333 | brd->bd_flags |= BD_FEP5PLUS; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4334 | |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4335 | return 0; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4336 | } |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4337 | msleep_interruptible(10); |
| 4338 | brd->wait_for_fep++; |
| 4339 | word = readw(addr + FEPSTAT); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4340 | } |
| 4341 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4342 | /* Gave up on board after too long of time taken */ |
| 4343 | err1 = readw(addr + SEQUENCE); |
| 4344 | err2 = readw(addr + ERROR); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4345 | pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n", |
| 4346 | brd->name, err1, err2); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4347 | brd->state = BOARD_FAILED; |
| 4348 | brd->dpastatus = BD_NOFEP; |
Mark Hounschell | bd3e43e | 2014-03-12 12:50:55 -0400 | [diff] [blame] | 4349 | |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4350 | return -EIO; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4351 | } |
| 4352 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4353 | /* |
| 4354 | * Physically forces the FEP5 card to reset itself. |
| 4355 | */ |
| 4356 | static void dgap_do_reset_board(struct board_t *brd) |
| 4357 | { |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4358 | u8 check; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4359 | u32 check1; |
| 4360 | u32 check2; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 4361 | int i; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4362 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4363 | if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || |
| 4364 | !brd->re_map_membase || !brd->re_map_port) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4365 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4366 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4367 | /* FEPRST does not vary among supported boards */ |
| 4368 | writeb(FEPRST, brd->re_map_port); |
| 4369 | |
| 4370 | for (i = 0; i <= 1000; i++) { |
| 4371 | check = readb(brd->re_map_port) & 0xe; |
| 4372 | if (check == FEPRST) |
| 4373 | break; |
| 4374 | udelay(10); |
| 4375 | |
| 4376 | } |
| 4377 | if (i > 1000) { |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4378 | pr_warn("dgap: Board not resetting... Failing board.\n"); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4379 | brd->state = BOARD_FAILED; |
| 4380 | brd->dpastatus = BD_NOFEP; |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4381 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4382 | } |
| 4383 | |
| 4384 | /* |
| 4385 | * Make sure there really is memory out there. |
| 4386 | */ |
| 4387 | writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM)); |
| 4388 | writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM)); |
| 4389 | check1 = readl(brd->re_map_membase + LOWMEM); |
| 4390 | check2 = readl(brd->re_map_membase + HIGHMEM); |
| 4391 | |
| 4392 | if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) { |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4393 | pr_warn("dgap: No memory at %p for board.\n", |
| 4394 | brd->re_map_membase); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4395 | brd->state = BOARD_FAILED; |
| 4396 | brd->dpastatus = BD_NOFEP; |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4397 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4398 | } |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4399 | } |
| 4400 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4401 | #ifdef DIGI_CONCENTRATORS_SUPPORTED |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4402 | /* |
| 4403 | * Sends a concentrator image into the FEP5 board. |
| 4404 | */ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4405 | static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4406 | { |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 4407 | char __iomem *vaddr; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 4408 | u16 offset; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4409 | struct downld_t *to_dp; |
| 4410 | |
| 4411 | if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase) |
| 4412 | return; |
| 4413 | |
| 4414 | vaddr = brd->re_map_membase; |
| 4415 | |
| 4416 | offset = readw((u16 *) (vaddr + DOWNREQ)); |
| 4417 | to_dp = (struct downld_t *) (vaddr + (int) offset); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4418 | memcpy_toio(to_dp, uaddr, len); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4419 | |
| 4420 | /* Tell card we have data for it */ |
| 4421 | writew(0, vaddr + (DOWNREQ)); |
| 4422 | |
| 4423 | brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS; |
| 4424 | } |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4425 | #endif |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4426 | |
| 4427 | #define EXPANSION_ROM_SIZE (64 * 1024) |
| 4428 | #define FEP5_ROM_MAGIC (0xFEFFFFFF) |
| 4429 | |
| 4430 | static void dgap_get_vpd(struct board_t *brd) |
| 4431 | { |
| 4432 | u32 magic; |
| 4433 | u32 base_offset; |
| 4434 | u16 rom_offset; |
| 4435 | u16 vpd_offset; |
| 4436 | u16 image_length; |
| 4437 | u16 i; |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4438 | u8 byte1; |
| 4439 | u8 byte2; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4440 | |
| 4441 | /* |
| 4442 | * Poke the magic number at the PCI Rom Address location. |
| 4443 | * If VPD is supported, the value read from that address |
| 4444 | * will be non-zero. |
| 4445 | */ |
| 4446 | magic = FEP5_ROM_MAGIC; |
| 4447 | pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic); |
| 4448 | pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic); |
| 4449 | |
| 4450 | /* VPD not supported, bail */ |
| 4451 | if (!magic) |
| 4452 | return; |
| 4453 | |
| 4454 | /* |
| 4455 | * To get to the OTPROM memory, we have to send the boards base |
| 4456 | * address or'ed with 1 into the PCI Rom Address location. |
| 4457 | */ |
| 4458 | magic = brd->membase | 0x01; |
| 4459 | pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic); |
| 4460 | pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic); |
| 4461 | |
| 4462 | byte1 = readb(brd->re_map_membase); |
| 4463 | byte2 = readb(brd->re_map_membase + 1); |
| 4464 | |
| 4465 | /* |
| 4466 | * If the board correctly swapped to the OTPROM memory, |
| 4467 | * the first 2 bytes (header) should be 0x55, 0xAA |
| 4468 | */ |
| 4469 | if (byte1 == 0x55 && byte2 == 0xAA) { |
| 4470 | |
| 4471 | base_offset = 0; |
| 4472 | |
| 4473 | /* |
| 4474 | * We have to run through all the OTPROM memory looking |
| 4475 | * for the VPD offset. |
| 4476 | */ |
| 4477 | while (base_offset <= EXPANSION_ROM_SIZE) { |
| 4478 | |
| 4479 | /* |
| 4480 | * Lots of magic numbers here. |
| 4481 | * |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 4482 | * The VPD offset is located inside the ROM Data |
| 4483 | * Structure. |
| 4484 | * |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4485 | * We also have to remember the length of each |
| 4486 | * ROM Data Structure, so we can "hop" to the next |
| 4487 | * entry if the VPD isn't in the current |
| 4488 | * ROM Data Structure. |
| 4489 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 4490 | rom_offset = readw(brd->re_map_membase + |
| 4491 | base_offset + 0x18); |
| 4492 | image_length = readw(brd->re_map_membase + |
| 4493 | rom_offset + 0x10) * 512; |
| 4494 | vpd_offset = readw(brd->re_map_membase + |
| 4495 | rom_offset + 0x08); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4496 | |
| 4497 | /* Found the VPD entry */ |
| 4498 | if (vpd_offset) |
| 4499 | break; |
| 4500 | |
| 4501 | /* We didn't find a VPD entry, go to next ROM entry. */ |
| 4502 | base_offset += image_length; |
| 4503 | |
| 4504 | byte1 = readb(brd->re_map_membase + base_offset); |
| 4505 | byte2 = readb(brd->re_map_membase + base_offset + 1); |
| 4506 | |
| 4507 | /* |
| 4508 | * If the new ROM offset doesn't have 0x55, 0xAA |
| 4509 | * as its header, we have run out of ROM. |
| 4510 | */ |
| 4511 | if (byte1 != 0x55 || byte2 != 0xAA) |
| 4512 | break; |
| 4513 | } |
| 4514 | |
| 4515 | /* |
| 4516 | * If we have a VPD offset, then mark the board |
| 4517 | * as having a valid VPD, and copy VPDSIZE (512) bytes of |
| 4518 | * that VPD to the buffer we have in our board structure. |
| 4519 | */ |
| 4520 | if (vpd_offset) { |
| 4521 | brd->bd_flags |= BD_HAS_VPD; |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 4522 | for (i = 0; i < VPDSIZE; i++) { |
| 4523 | brd->vpd[i] = readb(brd->re_map_membase + |
| 4524 | vpd_offset + i); |
| 4525 | } |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4526 | } |
| 4527 | } |
| 4528 | |
| 4529 | /* |
| 4530 | * We MUST poke the magic number at the PCI Rom Address location again. |
| 4531 | * This makes the card report the regular board memory back to us, |
| 4532 | * rather than the OTPROM memory. |
| 4533 | */ |
| 4534 | magic = FEP5_ROM_MAGIC; |
| 4535 | pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic); |
| 4536 | } |
| 4537 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4538 | /* |
| 4539 | * Our board poller function. |
| 4540 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 4541 | static void dgap_poll_tasklet(unsigned long data) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4542 | { |
| 4543 | struct board_t *bd = (struct board_t *) data; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4544 | ulong lock_flags; |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 4545 | char __iomem *vaddr; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4546 | u16 head, tail; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4547 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4548 | if (!bd || (bd->magic != DGAP_BOARD_MAGIC)) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4549 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4550 | |
| 4551 | if (bd->inhibit_poller) |
| 4552 | return; |
| 4553 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4554 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4555 | |
| 4556 | vaddr = bd->re_map_membase; |
| 4557 | |
| 4558 | /* |
| 4559 | * If board is ready, parse deeper to see if there is anything to do. |
| 4560 | */ |
| 4561 | if (bd->state == BOARD_READY) { |
| 4562 | |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4563 | struct ev_t __iomem *eaddr; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4564 | |
| 4565 | if (!bd->re_map_membase) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4566 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4567 | return; |
| 4568 | } |
| 4569 | if (!bd->re_map_port) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4570 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4571 | return; |
| 4572 | } |
| 4573 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4574 | if (!bd->nasync) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4575 | goto out; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4576 | |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4577 | eaddr = (struct ev_t __iomem *) (vaddr + EVBUF); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4578 | |
| 4579 | /* Get our head and tail */ |
| 4580 | head = readw(&(eaddr->ev_head)); |
| 4581 | tail = readw(&(eaddr->ev_tail)); |
| 4582 | |
| 4583 | /* |
| 4584 | * If there is an event pending. Go service it. |
| 4585 | */ |
| 4586 | if (head != tail) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4587 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4588 | dgap_event(bd); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4589 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4590 | } |
| 4591 | |
| 4592 | out: |
| 4593 | /* |
| 4594 | * If board is doing interrupts, ACK the interrupt. |
| 4595 | */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4596 | if (bd && bd->intr_running) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4597 | readb(bd->re_map_port + 2); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4598 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4599 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4600 | return; |
| 4601 | } |
| 4602 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4603 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4604 | } |
| 4605 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4606 | /*======================================================================= |
| 4607 | * |
| 4608 | * dgap_cmdb - Sends a 2 byte command to the FEP. |
| 4609 | * |
| 4610 | * ch - Pointer to channel structure. |
| 4611 | * cmd - Command to be sent. |
| 4612 | * byte1 - Integer containing first byte to be sent. |
| 4613 | * byte2 - Integer containing second byte to be sent. |
| 4614 | * ncmds - Wait until ncmds or fewer cmds are left |
| 4615 | * in the cmd buffer before returning. |
| 4616 | * |
| 4617 | *=======================================================================*/ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4618 | static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1, |
| 4619 | u8 byte2, uint ncmds) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4620 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4621 | char __iomem *vaddr; |
Mark Hounschell | 6a30cdd | 2014-04-23 16:43:21 -0400 | [diff] [blame] | 4622 | struct __iomem cm_t *cm_addr; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4623 | uint count; |
| 4624 | uint n; |
| 4625 | u16 head; |
| 4626 | u16 tail; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4627 | |
| 4628 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 4629 | return; |
| 4630 | |
| 4631 | /* |
| 4632 | * Check if board is still alive. |
| 4633 | */ |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4634 | if (ch->ch_bd->state == BOARD_FAILED) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4635 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4636 | |
| 4637 | /* |
| 4638 | * Make sure the pointers are in range before |
| 4639 | * writing to the FEP memory. |
| 4640 | */ |
| 4641 | vaddr = ch->ch_bd->re_map_membase; |
| 4642 | |
| 4643 | if (!vaddr) |
| 4644 | return; |
| 4645 | |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4646 | cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4647 | head = readw(&(cm_addr->cm_head)); |
| 4648 | |
| 4649 | /* |
| 4650 | * Forget it if pointers out of range. |
| 4651 | */ |
| 4652 | if (head >= (CMDMAX - CMDSTART) || (head & 03)) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4653 | ch->ch_bd->state = BOARD_FAILED; |
| 4654 | return; |
| 4655 | } |
| 4656 | |
| 4657 | /* |
| 4658 | * Put the data in the circular command buffer. |
| 4659 | */ |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4660 | writeb(cmd, (vaddr + head + CMDSTART + 0)); |
| 4661 | writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1)); |
| 4662 | writeb(byte1, (vaddr + head + CMDSTART + 2)); |
| 4663 | writeb(byte2, (vaddr + head + CMDSTART + 3)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4664 | |
| 4665 | head = (head + 4) & (CMDMAX - CMDSTART - 4); |
| 4666 | |
| 4667 | writew(head, &(cm_addr->cm_head)); |
| 4668 | |
| 4669 | /* |
| 4670 | * Wait if necessary before updating the head |
| 4671 | * pointer to limit the number of outstanding |
| 4672 | * commands to the FEP. If the time spent waiting |
| 4673 | * is outlandish, declare the FEP dead. |
| 4674 | */ |
| 4675 | for (count = dgap_count ;;) { |
| 4676 | |
| 4677 | head = readw(&(cm_addr->cm_head)); |
| 4678 | tail = readw(&(cm_addr->cm_tail)); |
| 4679 | |
| 4680 | n = (head - tail) & (CMDMAX - CMDSTART - 4); |
| 4681 | |
| 4682 | if (n <= ncmds * sizeof(struct cm_t)) |
| 4683 | break; |
| 4684 | |
| 4685 | if (--count == 0) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4686 | ch->ch_bd->state = BOARD_FAILED; |
| 4687 | return; |
| 4688 | } |
| 4689 | udelay(10); |
| 4690 | } |
| 4691 | } |
| 4692 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4693 | /*======================================================================= |
| 4694 | * |
| 4695 | * dgap_cmdw - Sends a 1 word command to the FEP. |
| 4696 | * |
| 4697 | * ch - Pointer to channel structure. |
| 4698 | * cmd - Command to be sent. |
| 4699 | * word - Integer containing word to be sent. |
| 4700 | * ncmds - Wait until ncmds or fewer cmds are left |
| 4701 | * in the cmd buffer before returning. |
| 4702 | * |
| 4703 | *=======================================================================*/ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4704 | static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4705 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4706 | char __iomem *vaddr; |
Mark Hounschell | 6a30cdd | 2014-04-23 16:43:21 -0400 | [diff] [blame] | 4707 | struct __iomem cm_t *cm_addr; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4708 | uint count; |
| 4709 | uint n; |
| 4710 | u16 head; |
| 4711 | u16 tail; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4712 | |
| 4713 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 4714 | return; |
| 4715 | |
| 4716 | /* |
| 4717 | * Check if board is still alive. |
| 4718 | */ |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4719 | if (ch->ch_bd->state == BOARD_FAILED) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4720 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4721 | |
| 4722 | /* |
| 4723 | * Make sure the pointers are in range before |
| 4724 | * writing to the FEP memory. |
| 4725 | */ |
| 4726 | vaddr = ch->ch_bd->re_map_membase; |
| 4727 | if (!vaddr) |
| 4728 | return; |
| 4729 | |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4730 | cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4731 | head = readw(&(cm_addr->cm_head)); |
| 4732 | |
| 4733 | /* |
| 4734 | * Forget it if pointers out of range. |
| 4735 | */ |
| 4736 | if (head >= (CMDMAX - CMDSTART) || (head & 03)) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4737 | ch->ch_bd->state = BOARD_FAILED; |
| 4738 | return; |
| 4739 | } |
| 4740 | |
| 4741 | /* |
| 4742 | * Put the data in the circular command buffer. |
| 4743 | */ |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4744 | writeb(cmd, (vaddr + head + CMDSTART + 0)); |
| 4745 | writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1)); |
| 4746 | writew((u16) word, (vaddr + head + CMDSTART + 2)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4747 | |
| 4748 | head = (head + 4) & (CMDMAX - CMDSTART - 4); |
| 4749 | |
| 4750 | writew(head, &(cm_addr->cm_head)); |
| 4751 | |
| 4752 | /* |
| 4753 | * Wait if necessary before updating the head |
| 4754 | * pointer to limit the number of outstanding |
| 4755 | * commands to the FEP. If the time spent waiting |
| 4756 | * is outlandish, declare the FEP dead. |
| 4757 | */ |
| 4758 | for (count = dgap_count ;;) { |
| 4759 | |
| 4760 | head = readw(&(cm_addr->cm_head)); |
| 4761 | tail = readw(&(cm_addr->cm_tail)); |
| 4762 | |
| 4763 | n = (head - tail) & (CMDMAX - CMDSTART - 4); |
| 4764 | |
| 4765 | if (n <= ncmds * sizeof(struct cm_t)) |
| 4766 | break; |
| 4767 | |
| 4768 | if (--count == 0) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4769 | ch->ch_bd->state = BOARD_FAILED; |
| 4770 | return; |
| 4771 | } |
| 4772 | udelay(10); |
| 4773 | } |
| 4774 | } |
| 4775 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4776 | /*======================================================================= |
| 4777 | * |
| 4778 | * dgap_cmdw_ext - Sends a extended word command to the FEP. |
| 4779 | * |
| 4780 | * ch - Pointer to channel structure. |
| 4781 | * cmd - Command to be sent. |
| 4782 | * word - Integer containing word to be sent. |
| 4783 | * ncmds - Wait until ncmds or fewer cmds are left |
| 4784 | * in the cmd buffer before returning. |
| 4785 | * |
| 4786 | *=======================================================================*/ |
| 4787 | static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds) |
| 4788 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4789 | char __iomem *vaddr; |
Mark Hounschell | 6a30cdd | 2014-04-23 16:43:21 -0400 | [diff] [blame] | 4790 | struct __iomem cm_t *cm_addr; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4791 | uint count; |
| 4792 | uint n; |
| 4793 | u16 head; |
| 4794 | u16 tail; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4795 | |
| 4796 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 4797 | return; |
| 4798 | |
| 4799 | /* |
| 4800 | * Check if board is still alive. |
| 4801 | */ |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4802 | if (ch->ch_bd->state == BOARD_FAILED) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4803 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4804 | |
| 4805 | /* |
| 4806 | * Make sure the pointers are in range before |
| 4807 | * writing to the FEP memory. |
| 4808 | */ |
| 4809 | vaddr = ch->ch_bd->re_map_membase; |
| 4810 | if (!vaddr) |
| 4811 | return; |
| 4812 | |
Mark Hounschell | 630b2ab | 2014-04-24 09:22:12 -0400 | [diff] [blame] | 4813 | cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4814 | head = readw(&(cm_addr->cm_head)); |
| 4815 | |
| 4816 | /* |
| 4817 | * Forget it if pointers out of range. |
| 4818 | */ |
| 4819 | if (head >= (CMDMAX - CMDSTART) || (head & 03)) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4820 | ch->ch_bd->state = BOARD_FAILED; |
| 4821 | return; |
| 4822 | } |
| 4823 | |
| 4824 | /* |
| 4825 | * Put the data in the circular command buffer. |
| 4826 | */ |
| 4827 | |
| 4828 | /* Write an FF to tell the FEP that we want an extended command */ |
Mark Hounschell | 630b2ab | 2014-04-24 09:22:12 -0400 | [diff] [blame] | 4829 | writeb((u8) 0xff, (vaddr + head + CMDSTART + 0)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4830 | |
Mark Hounschell | 630b2ab | 2014-04-24 09:22:12 -0400 | [diff] [blame] | 4831 | writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1)); |
| 4832 | writew((u16) cmd, (vaddr + head + CMDSTART + 2)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4833 | |
| 4834 | /* |
| 4835 | * If the second part of the command won't fit, |
| 4836 | * put it at the beginning of the circular buffer. |
| 4837 | */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4838 | if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03))) |
Mark Hounschell | 630b2ab | 2014-04-24 09:22:12 -0400 | [diff] [blame] | 4839 | writew((u16) word, (vaddr + CMDSTART)); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4840 | else |
Mark Hounschell | 630b2ab | 2014-04-24 09:22:12 -0400 | [diff] [blame] | 4841 | writew((u16) word, (vaddr + head + CMDSTART + 4)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4842 | |
| 4843 | head = (head + 8) & (CMDMAX - CMDSTART - 4); |
| 4844 | |
| 4845 | writew(head, &(cm_addr->cm_head)); |
| 4846 | |
| 4847 | /* |
| 4848 | * Wait if necessary before updating the head |
| 4849 | * pointer to limit the number of outstanding |
| 4850 | * commands to the FEP. If the time spent waiting |
| 4851 | * is outlandish, declare the FEP dead. |
| 4852 | */ |
| 4853 | for (count = dgap_count ;;) { |
| 4854 | |
| 4855 | head = readw(&(cm_addr->cm_head)); |
| 4856 | tail = readw(&(cm_addr->cm_tail)); |
| 4857 | |
| 4858 | n = (head - tail) & (CMDMAX - CMDSTART - 4); |
| 4859 | |
| 4860 | if (n <= ncmds * sizeof(struct cm_t)) |
| 4861 | break; |
| 4862 | |
| 4863 | if (--count == 0) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4864 | ch->ch_bd->state = BOARD_FAILED; |
| 4865 | return; |
| 4866 | } |
| 4867 | udelay(10); |
| 4868 | } |
| 4869 | } |
| 4870 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4871 | /*======================================================================= |
| 4872 | * |
| 4873 | * dgap_wmove - Write data to FEP buffer. |
| 4874 | * |
| 4875 | * ch - Pointer to channel structure. |
| 4876 | * buf - Poiter to characters to be moved. |
| 4877 | * cnt - Number of characters to move. |
| 4878 | * |
| 4879 | *=======================================================================*/ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 4880 | static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4881 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4882 | int n; |
| 4883 | char __iomem *taddr; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 4884 | struct bs_t __iomem *bs; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4885 | u16 head; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4886 | |
| 4887 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 4888 | return; |
| 4889 | |
| 4890 | /* |
| 4891 | * Check parameters. |
| 4892 | */ |
| 4893 | bs = ch->ch_bs; |
| 4894 | head = readw(&(bs->tx_head)); |
| 4895 | |
| 4896 | /* |
| 4897 | * If pointers are out of range, just return. |
| 4898 | */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4899 | if ((cnt > ch->ch_tsize) || |
| 4900 | (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4901 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4902 | |
| 4903 | /* |
| 4904 | * If the write wraps over the top of the circular buffer, |
| 4905 | * move the portion up to the wrap point, and reset the |
| 4906 | * pointers to the bottom. |
| 4907 | */ |
| 4908 | n = ch->ch_tstart + ch->ch_tsize - head; |
| 4909 | |
| 4910 | if (cnt >= n) { |
| 4911 | cnt -= n; |
| 4912 | taddr = ch->ch_taddr + head; |
| 4913 | memcpy_toio(taddr, buf, n); |
| 4914 | head = ch->ch_tstart; |
| 4915 | buf += n; |
| 4916 | } |
| 4917 | |
| 4918 | /* |
| 4919 | * Move rest of data. |
| 4920 | */ |
| 4921 | taddr = ch->ch_taddr + head; |
| 4922 | n = cnt; |
| 4923 | memcpy_toio(taddr, buf, n); |
| 4924 | head += cnt; |
| 4925 | |
| 4926 | writew(head, &(bs->tx_head)); |
| 4927 | } |
| 4928 | |
| 4929 | /* |
| 4930 | * Retrives the current custom baud rate from FEP memory, |
| 4931 | * and returns it back to the user. |
| 4932 | * Returns 0 on error. |
| 4933 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 4934 | static uint dgap_get_custom_baud(struct channel_t *ch) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4935 | { |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 4936 | u8 __iomem *vaddr; |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4937 | ulong offset; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 4938 | uint value; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4939 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4940 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4941 | return 0; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4942 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4943 | if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4944 | return 0; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4945 | |
| 4946 | if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS)) |
| 4947 | return 0; |
| 4948 | |
| 4949 | vaddr = ch->ch_bd->re_map_membase; |
| 4950 | |
| 4951 | if (!vaddr) |
| 4952 | return 0; |
| 4953 | |
| 4954 | /* |
| 4955 | * Go get from fep mem, what the fep |
| 4956 | * believes the custom baud rate is. |
| 4957 | */ |
Pascal COMBES | 77870a1 | 2014-05-24 15:58:09 +0200 | [diff] [blame] | 4958 | offset = (ioread16(vaddr + ECS_SEG) << 4) + (ch->ch_portnum * 0x28) |
| 4959 | + LINE_SPEED; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4960 | |
| 4961 | value = readw(vaddr + offset); |
| 4962 | return value; |
| 4963 | } |
| 4964 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4965 | /* |
| 4966 | * Calls the firmware to reset this channel. |
| 4967 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 4968 | static void dgap_firmware_reset_port(struct channel_t *ch) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4969 | { |
| 4970 | dgap_cmdb(ch, CHRESET, 0, 0, 0); |
| 4971 | |
| 4972 | /* |
| 4973 | * Now that the channel is reset, we need to make sure |
| 4974 | * all the current settings get reapplied to the port |
| 4975 | * in the firmware. |
| 4976 | * |
| 4977 | * So we will set the driver's cache of firmware |
| 4978 | * settings all to 0, and then call param. |
| 4979 | */ |
| 4980 | ch->ch_fepiflag = 0; |
| 4981 | ch->ch_fepcflag = 0; |
| 4982 | ch->ch_fepoflag = 0; |
| 4983 | ch->ch_fepstartc = 0; |
| 4984 | ch->ch_fepstopc = 0; |
| 4985 | ch->ch_fepastartc = 0; |
| 4986 | ch->ch_fepastopc = 0; |
| 4987 | ch->ch_mostat = 0; |
| 4988 | ch->ch_hflow = 0; |
| 4989 | } |
| 4990 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4991 | /*======================================================================= |
| 4992 | * |
| 4993 | * dgap_param - Set Digi parameters. |
| 4994 | * |
| 4995 | * struct tty_struct * - TTY for port. |
| 4996 | * |
| 4997 | *=======================================================================*/ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 4998 | static int dgap_param(struct tty_struct *tty) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4999 | { |
| 5000 | struct ktermios *ts; |
| 5001 | struct board_t *bd; |
| 5002 | struct channel_t *ch; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 5003 | struct bs_t __iomem *bs; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 5004 | struct un_t *un; |
| 5005 | u16 head; |
| 5006 | u16 cflag; |
| 5007 | u16 iflag; |
| 5008 | u8 mval; |
| 5009 | u8 hflow; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5010 | |
| 5011 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 5012 | return -EIO; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5013 | |
| 5014 | un = (struct un_t *) tty->driver_data; |
| 5015 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 5016 | return -EIO; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5017 | |
| 5018 | ch = un->un_ch; |
| 5019 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 5020 | return -EIO; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5021 | |
| 5022 | bd = ch->ch_bd; |
| 5023 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 5024 | return -EIO; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5025 | |
| 5026 | bs = ch->ch_bs; |
| 5027 | if (!bs) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 5028 | return -EIO; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5029 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5030 | ts = &tty->termios; |
| 5031 | |
| 5032 | /* |
| 5033 | * If baud rate is zero, flush queues, and set mval to drop DTR. |
| 5034 | */ |
| 5035 | if ((ch->ch_c_cflag & (CBAUD)) == 0) { |
| 5036 | |
| 5037 | /* flush rx */ |
| 5038 | head = readw(&(ch->ch_bs->rx_head)); |
| 5039 | writew(head, &(ch->ch_bs->rx_tail)); |
| 5040 | |
| 5041 | /* flush tx */ |
| 5042 | head = readw(&(ch->ch_bs->tx_head)); |
| 5043 | writew(head, &(ch->ch_bs->tx_tail)); |
| 5044 | |
| 5045 | ch->ch_flags |= (CH_BAUD0); |
| 5046 | |
| 5047 | /* Drop RTS and DTR */ |
| 5048 | ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch)); |
| 5049 | mval = D_DTR(ch) | D_RTS(ch); |
| 5050 | ch->ch_baud_info = 0; |
| 5051 | |
| 5052 | } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) { |
| 5053 | /* |
| 5054 | * Tell the fep to do the command |
| 5055 | */ |
| 5056 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5057 | dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0); |
| 5058 | |
| 5059 | /* |
| 5060 | * Now go get from fep mem, what the fep |
| 5061 | * believes the custom baud rate is. |
| 5062 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 5063 | ch->ch_custom_speed = dgap_get_custom_baud(ch); |
| 5064 | ch->ch_baud_info = ch->ch_custom_speed; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5065 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5066 | /* Handle transition from B0 */ |
| 5067 | if (ch->ch_flags & CH_BAUD0) { |
| 5068 | ch->ch_flags &= ~(CH_BAUD0); |
| 5069 | ch->ch_mval |= (D_RTS(ch)|D_DTR(ch)); |
| 5070 | } |
| 5071 | mval = D_DTR(ch) | D_RTS(ch); |
| 5072 | |
| 5073 | } else { |
| 5074 | /* |
| 5075 | * Set baud rate, character size, and parity. |
| 5076 | */ |
| 5077 | |
| 5078 | |
| 5079 | int iindex = 0; |
| 5080 | int jindex = 0; |
| 5081 | int baud = 0; |
| 5082 | |
| 5083 | ulong bauds[4][16] = { |
| 5084 | { /* slowbaud */ |
| 5085 | 0, 50, 75, 110, |
| 5086 | 134, 150, 200, 300, |
| 5087 | 600, 1200, 1800, 2400, |
| 5088 | 4800, 9600, 19200, 38400 }, |
| 5089 | { /* slowbaud & CBAUDEX */ |
| 5090 | 0, 57600, 115200, 230400, |
| 5091 | 460800, 150, 200, 921600, |
| 5092 | 600, 1200, 1800, 2400, |
| 5093 | 4800, 9600, 19200, 38400 }, |
| 5094 | { /* fastbaud */ |
| 5095 | 0, 57600, 76800, 115200, |
| 5096 | 14400, 57600, 230400, 76800, |
| 5097 | 115200, 230400, 28800, 460800, |
| 5098 | 921600, 9600, 19200, 38400 }, |
| 5099 | { /* fastbaud & CBAUDEX */ |
| 5100 | 0, 57600, 115200, 230400, |
| 5101 | 460800, 150, 200, 921600, |
| 5102 | 600, 1200, 1800, 2400, |
| 5103 | 4800, 9600, 19200, 38400 } |
| 5104 | }; |
| 5105 | |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 5106 | /* |
| 5107 | * Only use the TXPrint baud rate if the |
| 5108 | * terminal unit is NOT open |
| 5109 | */ |
| 5110 | if (!(ch->ch_tun.un_flags & UN_ISOPEN) && |
| 5111 | (un->un_type == DGAP_PRINT)) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5112 | baud = C_BAUD(ch->ch_pun.un_tty) & 0xff; |
| 5113 | else |
| 5114 | baud = C_BAUD(ch->ch_tun.un_tty) & 0xff; |
| 5115 | |
| 5116 | if (ch->ch_c_cflag & CBAUDEX) |
| 5117 | iindex = 1; |
| 5118 | |
| 5119 | if (ch->ch_digi.digi_flags & DIGI_FAST) |
| 5120 | iindex += 2; |
| 5121 | |
| 5122 | jindex = baud; |
| 5123 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5124 | if ((iindex >= 0) && (iindex < 4) && |
| 5125 | (jindex >= 0) && (jindex < 16)) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5126 | baud = bauds[iindex][jindex]; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5127 | else |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5128 | baud = 0; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5129 | |
| 5130 | if (baud == 0) |
| 5131 | baud = 9600; |
| 5132 | |
| 5133 | ch->ch_baud_info = baud; |
| 5134 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5135 | /* |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 5136 | * CBAUD has bit position 0x1000 set these days to |
| 5137 | * indicate Linux baud rate remap. |
| 5138 | * We use a different bit assignment for high speed. |
| 5139 | * Clear this bit out while grabbing the parts of |
| 5140 | * "cflag" we want. |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5141 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 5142 | cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | |
| 5143 | CSTOPB | CSIZE); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5144 | |
| 5145 | /* |
| 5146 | * HUPCL bit is used by FEP to indicate fast baud |
| 5147 | * table is to be used. |
| 5148 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 5149 | if ((ch->ch_digi.digi_flags & DIGI_FAST) || |
| 5150 | (ch->ch_c_cflag & CBAUDEX)) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5151 | cflag |= HUPCL; |
| 5152 | |
Mark Hounschell | af5b80b | 2014-03-04 16:03:11 -0500 | [diff] [blame] | 5153 | if ((ch->ch_c_cflag & CBAUDEX) && |
| 5154 | !(ch->ch_digi.digi_flags & DIGI_FAST)) { |
| 5155 | /* |
| 5156 | * The below code is trying to guarantee that only |
| 5157 | * baud rates 115200, 230400, 460800, 921600 are |
| 5158 | * remapped. We use exclusive or because the various |
| 5159 | * baud rates share common bit positions and therefore |
| 5160 | * can't be tested for easily. |
| 5161 | */ |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5162 | tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX; |
| 5163 | int baudpart = 0; |
| 5164 | |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 5165 | /* |
| 5166 | * Map high speed requests to index |
| 5167 | * into FEP's baud table |
| 5168 | */ |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5169 | switch (tcflag) { |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 5170 | case B57600: |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5171 | baudpart = 1; |
| 5172 | break; |
| 5173 | #ifdef B76800 |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 5174 | case B76800: |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5175 | baudpart = 2; |
| 5176 | break; |
| 5177 | #endif |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 5178 | case B115200: |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5179 | baudpart = 3; |
| 5180 | break; |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 5181 | case B230400: |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5182 | baudpart = 9; |
| 5183 | break; |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 5184 | case B460800: |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5185 | baudpart = 11; |
| 5186 | break; |
| 5187 | #ifdef B921600 |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 5188 | case B921600: |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5189 | baudpart = 12; |
| 5190 | break; |
| 5191 | #endif |
| 5192 | default: |
| 5193 | baudpart = 0; |
| 5194 | } |
| 5195 | |
| 5196 | if (baudpart) |
| 5197 | cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart; |
| 5198 | } |
| 5199 | |
| 5200 | cflag &= 0xffff; |
| 5201 | |
| 5202 | if (cflag != ch->ch_fepcflag) { |
| 5203 | ch->ch_fepcflag = (u16) (cflag & 0xffff); |
| 5204 | |
Mark Hounschell | 8fc324e | 2014-03-05 15:54:51 -0500 | [diff] [blame] | 5205 | /* |
| 5206 | * Okay to have channel and board |
| 5207 | * locks held calling this |
| 5208 | */ |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5209 | dgap_cmdw(ch, SCFLAG, (u16) cflag, 0); |
| 5210 | } |
| 5211 | |
| 5212 | /* Handle transition from B0 */ |
| 5213 | if (ch->ch_flags & CH_BAUD0) { |
| 5214 | ch->ch_flags &= ~(CH_BAUD0); |
| 5215 | ch->ch_mval |= (D_RTS(ch)|D_DTR(ch)); |
| 5216 | } |
| 5217 | mval = D_DTR(ch) | D_RTS(ch); |
| 5218 | } |
| 5219 | |
| 5220 | /* |
| 5221 | * Get input flags. |
| 5222 | */ |
Mark Hounschell | 8fc324e | 2014-03-05 15:54:51 -0500 | [diff] [blame] | 5223 | iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | |
| 5224 | INPCK | ISTRIP | IXON | IXANY | IXOFF); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5225 | |
Mark Hounschell | 8fc324e | 2014-03-05 15:54:51 -0500 | [diff] [blame] | 5226 | if ((ch->ch_startc == _POSIX_VDISABLE) || |
| 5227 | (ch->ch_stopc == _POSIX_VDISABLE)) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5228 | iflag &= ~(IXON | IXOFF); |
| 5229 | ch->ch_c_iflag &= ~(IXON | IXOFF); |
| 5230 | } |
| 5231 | |
| 5232 | /* |
| 5233 | * Only the IBM Xr card can switch between |
| 5234 | * 232 and 422 modes on the fly |
| 5235 | */ |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 5236 | if (bd->device == PCI_DEV_XR_IBM_DID) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5237 | if (ch->ch_digi.digi_flags & DIGI_422) |
| 5238 | dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0); |
| 5239 | else |
| 5240 | dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0); |
| 5241 | } |
| 5242 | |
| 5243 | if (ch->ch_digi.digi_flags & DIGI_ALTPIN) |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 5244 | iflag |= IALTPIN; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5245 | |
| 5246 | if (iflag != ch->ch_fepiflag) { |
| 5247 | ch->ch_fepiflag = iflag; |
| 5248 | |
| 5249 | /* Okay to have channel and board locks held calling this */ |
| 5250 | dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0); |
| 5251 | } |
| 5252 | |
| 5253 | /* |
| 5254 | * Select hardware handshaking. |
| 5255 | */ |
| 5256 | hflow = 0; |
| 5257 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5258 | if (ch->ch_c_cflag & CRTSCTS) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5259 | hflow |= (D_RTS(ch) | D_CTS(ch)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5260 | if (ch->ch_digi.digi_flags & RTSPACE) |
| 5261 | hflow |= D_RTS(ch); |
| 5262 | if (ch->ch_digi.digi_flags & DTRPACE) |
| 5263 | hflow |= D_DTR(ch); |
| 5264 | if (ch->ch_digi.digi_flags & CTSPACE) |
| 5265 | hflow |= D_CTS(ch); |
| 5266 | if (ch->ch_digi.digi_flags & DSRPACE) |
| 5267 | hflow |= D_DSR(ch); |
| 5268 | if (ch->ch_digi.digi_flags & DCDPACE) |
| 5269 | hflow |= D_CD(ch); |
| 5270 | |
| 5271 | if (hflow != ch->ch_hflow) { |
| 5272 | ch->ch_hflow = hflow; |
| 5273 | |
| 5274 | /* Okay to have channel and board locks held calling this */ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 5275 | dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5276 | } |
| 5277 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5278 | /* |
Mark Hounschell | 8fc324e | 2014-03-05 15:54:51 -0500 | [diff] [blame] | 5279 | * Set RTS and/or DTR Toggle if needed, |
| 5280 | * but only if product is FEP5+ based. |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5281 | */ |
| 5282 | if (bd->bd_flags & BD_FEP5PLUS) { |
| 5283 | u16 hflow2 = 0; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5284 | if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5285 | hflow2 |= (D_RTS(ch)); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5286 | if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5287 | hflow2 |= (D_DTR(ch)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5288 | |
| 5289 | dgap_cmdw_ext(ch, 0xff03, hflow2, 0); |
| 5290 | } |
| 5291 | |
| 5292 | /* |
| 5293 | * Set modem control lines. |
| 5294 | */ |
| 5295 | |
| 5296 | mval ^= ch->ch_mforce & (mval ^ ch->ch_mval); |
| 5297 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5298 | if (ch->ch_mostat ^ mval) { |
| 5299 | ch->ch_mostat = mval; |
| 5300 | |
| 5301 | /* Okay to have channel and board locks held calling this */ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 5302 | dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5303 | } |
| 5304 | |
| 5305 | /* |
| 5306 | * Read modem signals, and then call carrier function. |
| 5307 | */ |
| 5308 | ch->ch_mistat = readb(&(bs->m_stat)); |
| 5309 | dgap_carrier(ch); |
| 5310 | |
| 5311 | /* |
| 5312 | * Set the start and stop characters. |
| 5313 | */ |
Mark Hounschell | 8fc324e | 2014-03-05 15:54:51 -0500 | [diff] [blame] | 5314 | if (ch->ch_startc != ch->ch_fepstartc || |
| 5315 | ch->ch_stopc != ch->ch_fepstopc) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5316 | ch->ch_fepstartc = ch->ch_startc; |
| 5317 | ch->ch_fepstopc = ch->ch_stopc; |
| 5318 | |
| 5319 | /* Okay to have channel and board locks held calling this */ |
| 5320 | dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0); |
| 5321 | } |
| 5322 | |
| 5323 | /* |
| 5324 | * Set the Auxiliary start and stop characters. |
| 5325 | */ |
Mark Hounschell | 8fc324e | 2014-03-05 15:54:51 -0500 | [diff] [blame] | 5326 | if (ch->ch_astartc != ch->ch_fepastartc || |
| 5327 | ch->ch_astopc != ch->ch_fepastopc) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5328 | ch->ch_fepastartc = ch->ch_astartc; |
| 5329 | ch->ch_fepastopc = ch->ch_astopc; |
| 5330 | |
| 5331 | /* Okay to have channel and board locks held calling this */ |
| 5332 | dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0); |
| 5333 | } |
| 5334 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5335 | return 0; |
| 5336 | } |
| 5337 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5338 | /* |
| 5339 | * dgap_parity_scan() |
| 5340 | * |
| 5341 | * Convert the FEP5 way of reporting parity errors and breaks into |
| 5342 | * the Linux line discipline way. |
| 5343 | */ |
Mark Hounschell | 8fc324e | 2014-03-05 15:54:51 -0500 | [diff] [blame] | 5344 | static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, |
| 5345 | unsigned char *fbuf, int *len) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5346 | { |
| 5347 | int l = *len; |
| 5348 | int count = 0; |
| 5349 | unsigned char *in, *cout, *fout; |
| 5350 | unsigned char c; |
| 5351 | |
| 5352 | in = cbuf; |
| 5353 | cout = cbuf; |
| 5354 | fout = fbuf; |
| 5355 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5356 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 5357 | return; |
| 5358 | |
| 5359 | while (l--) { |
| 5360 | c = *in++; |
| 5361 | switch (ch->pscan_state) { |
| 5362 | default: |
| 5363 | /* reset to sanity and fall through */ |
| 5364 | ch->pscan_state = 0; |
| 5365 | |
| 5366 | case 0: |
| 5367 | /* No FF seen yet */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5368 | if (c == (unsigned char) '\377') |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5369 | /* delete this character from stream */ |
| 5370 | ch->pscan_state = 1; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5371 | else { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5372 | *cout++ = c; |
| 5373 | *fout++ = TTY_NORMAL; |
| 5374 | count += 1; |
| 5375 | } |
| 5376 | break; |
| 5377 | |
| 5378 | case 1: |
| 5379 | /* first FF seen */ |
| 5380 | if (c == (unsigned char) '\377') { |
| 5381 | /* doubled ff, transform to single ff */ |
| 5382 | *cout++ = c; |
| 5383 | *fout++ = TTY_NORMAL; |
| 5384 | count += 1; |
| 5385 | ch->pscan_state = 0; |
| 5386 | } else { |
| 5387 | /* save value examination in next state */ |
| 5388 | ch->pscan_savechar = c; |
| 5389 | ch->pscan_state = 2; |
| 5390 | } |
| 5391 | break; |
| 5392 | |
| 5393 | case 2: |
| 5394 | /* third character of ff sequence */ |
| 5395 | |
| 5396 | *cout++ = c; |
| 5397 | |
| 5398 | if (ch->pscan_savechar == 0x0) { |
| 5399 | |
| 5400 | if (c == 0x0) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5401 | ch->ch_err_break++; |
| 5402 | *fout++ = TTY_BREAK; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5403 | } else { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5404 | ch->ch_err_parity++; |
| 5405 | *fout++ = TTY_PARITY; |
| 5406 | } |
| 5407 | } |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5408 | |
| 5409 | count += 1; |
| 5410 | ch->pscan_state = 0; |
| 5411 | } |
| 5412 | } |
| 5413 | *len = count; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5414 | } |
| 5415 | |
Mark Hounschell | 8cdd763 | 2014-03-19 11:10:50 -0400 | [diff] [blame] | 5416 | static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch, |
| 5417 | struct un_t *un, u32 mask, |
| 5418 | unsigned long *irq_flags1, |
| 5419 | unsigned long *irq_flags2) |
| 5420 | { |
| 5421 | if (!(un->un_flags & mask)) |
| 5422 | return; |
| 5423 | |
| 5424 | un->un_flags &= ~mask; |
| 5425 | |
| 5426 | if (!(un->un_flags & UN_ISOPEN)) |
| 5427 | return; |
| 5428 | |
| 5429 | if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && |
| 5430 | un->un_tty->ldisc->ops->write_wakeup) { |
| 5431 | spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2); |
| 5432 | spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1); |
| 5433 | |
| 5434 | (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty); |
| 5435 | |
| 5436 | spin_lock_irqsave(&bd->bd_lock, *irq_flags1); |
| 5437 | spin_lock_irqsave(&ch->ch_lock, *irq_flags2); |
| 5438 | } |
| 5439 | wake_up_interruptible(&un->un_tty->write_wait); |
| 5440 | wake_up_interruptible(&un->un_flags_wait); |
| 5441 | } |
| 5442 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5443 | /*======================================================================= |
| 5444 | * |
| 5445 | * dgap_event - FEP to host event processing routine. |
| 5446 | * |
| 5447 | * bd - Board of current event. |
| 5448 | * |
| 5449 | *=======================================================================*/ |
| 5450 | static int dgap_event(struct board_t *bd) |
| 5451 | { |
| 5452 | struct channel_t *ch; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 5453 | ulong lock_flags; |
| 5454 | ulong lock_flags2; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 5455 | struct bs_t __iomem *bs; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 5456 | u8 __iomem *event; |
| 5457 | u8 __iomem *vaddr; |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 5458 | struct ev_t __iomem *eaddr; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 5459 | uint head; |
| 5460 | uint tail; |
| 5461 | int port; |
| 5462 | int reason; |
| 5463 | int modem; |
| 5464 | int b1; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5465 | |
| 5466 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 5467 | return -EIO; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5468 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5469 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5470 | |
| 5471 | vaddr = bd->re_map_membase; |
| 5472 | |
| 5473 | if (!vaddr) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5474 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 5475 | return -EIO; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5476 | } |
| 5477 | |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 5478 | eaddr = (struct ev_t __iomem *) (vaddr + EVBUF); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5479 | |
| 5480 | /* Get our head and tail */ |
| 5481 | head = readw(&(eaddr->ev_head)); |
| 5482 | tail = readw(&(eaddr->ev_tail)); |
| 5483 | |
| 5484 | /* |
| 5485 | * Forget it if pointers out of range. |
| 5486 | */ |
| 5487 | |
| 5488 | if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART || |
| 5489 | (head | tail) & 03) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5490 | /* Let go of board lock */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5491 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 5492 | return -EIO; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5493 | } |
| 5494 | |
| 5495 | /* |
| 5496 | * Loop to process all the events in the buffer. |
| 5497 | */ |
| 5498 | while (tail != head) { |
| 5499 | |
| 5500 | /* |
| 5501 | * Get interrupt information. |
| 5502 | */ |
| 5503 | |
| 5504 | event = bd->re_map_membase + tail + EVSTART; |
| 5505 | |
Pascal COMBES | 77870a1 | 2014-05-24 15:58:09 +0200 | [diff] [blame] | 5506 | port = ioread8(event); |
| 5507 | reason = ioread8(event + 1); |
| 5508 | modem = ioread8(event + 2); |
| 5509 | b1 = ioread8(event + 3); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5510 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5511 | /* |
| 5512 | * Make sure the interrupt is valid. |
| 5513 | */ |
| 5514 | if (port >= bd->nasync) |
| 5515 | goto next; |
| 5516 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5517 | if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA))) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5518 | goto next; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5519 | |
| 5520 | ch = bd->channels[port]; |
| 5521 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5522 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5523 | goto next; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5524 | |
| 5525 | /* |
| 5526 | * If we have made it here, the event was valid. |
| 5527 | * Lock down the channel. |
| 5528 | */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5529 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5530 | |
| 5531 | bs = ch->ch_bs; |
| 5532 | |
| 5533 | if (!bs) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5534 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5535 | goto next; |
| 5536 | } |
| 5537 | |
| 5538 | /* |
| 5539 | * Process received data. |
| 5540 | */ |
| 5541 | if (reason & IFDATA) { |
| 5542 | |
| 5543 | /* |
| 5544 | * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT! |
| 5545 | * input could send some data to ld, which in turn |
| 5546 | * could do a callback to one of our other functions. |
| 5547 | */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5548 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 5549 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5550 | |
| 5551 | dgap_input(ch); |
| 5552 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5553 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 5554 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5555 | |
| 5556 | if (ch->ch_flags & CH_RACTIVE) |
| 5557 | ch->ch_flags |= CH_RENABLE; |
| 5558 | else |
| 5559 | writeb(1, &(bs->idata)); |
| 5560 | |
| 5561 | if (ch->ch_flags & CH_RWAIT) { |
| 5562 | ch->ch_flags &= ~CH_RWAIT; |
| 5563 | |
Mark Hounschell | 70d97a6 | 2014-03-10 14:39:41 -0400 | [diff] [blame] | 5564 | wake_up_interruptible |
| 5565 | (&ch->ch_tun.un_flags_wait); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5566 | } |
| 5567 | } |
| 5568 | |
| 5569 | /* |
| 5570 | * Process Modem change signals. |
| 5571 | */ |
| 5572 | if (reason & IFMODEM) { |
| 5573 | ch->ch_mistat = modem; |
| 5574 | dgap_carrier(ch); |
| 5575 | } |
| 5576 | |
| 5577 | /* |
| 5578 | * Process break. |
| 5579 | */ |
| 5580 | if (reason & IFBREAK) { |
| 5581 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5582 | if (ch->ch_tun.un_tty) { |
| 5583 | /* A break has been indicated */ |
| 5584 | ch->ch_err_break++; |
Mark Hounschell | 70d97a6 | 2014-03-10 14:39:41 -0400 | [diff] [blame] | 5585 | tty_buffer_request_room |
| 5586 | (ch->ch_tun.un_tty->port, 1); |
| 5587 | tty_insert_flip_char(ch->ch_tun.un_tty->port, |
| 5588 | 0, TTY_BREAK); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5589 | tty_flip_buffer_push(ch->ch_tun.un_tty->port); |
| 5590 | } |
| 5591 | } |
| 5592 | |
| 5593 | /* |
| 5594 | * Process Transmit low. |
| 5595 | */ |
| 5596 | if (reason & IFTLW) { |
Mark Hounschell | 8cdd763 | 2014-03-19 11:10:50 -0400 | [diff] [blame] | 5597 | dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW, |
| 5598 | &lock_flags, &lock_flags2); |
| 5599 | dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW, |
| 5600 | &lock_flags, &lock_flags2); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5601 | if (ch->ch_flags & CH_WLOW) { |
| 5602 | ch->ch_flags &= ~CH_WLOW; |
| 5603 | wake_up_interruptible(&ch->ch_flags_wait); |
| 5604 | } |
| 5605 | } |
| 5606 | |
| 5607 | /* |
| 5608 | * Process Transmit empty. |
| 5609 | */ |
| 5610 | if (reason & IFTEM) { |
Mark Hounschell | 8cdd763 | 2014-03-19 11:10:50 -0400 | [diff] [blame] | 5611 | dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY, |
| 5612 | &lock_flags, &lock_flags2); |
| 5613 | dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY, |
| 5614 | &lock_flags, &lock_flags2); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5615 | if (ch->ch_flags & CH_WEMPTY) { |
| 5616 | ch->ch_flags &= ~CH_WEMPTY; |
| 5617 | wake_up_interruptible(&ch->ch_flags_wait); |
| 5618 | } |
| 5619 | } |
| 5620 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5621 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5622 | |
| 5623 | next: |
| 5624 | tail = (tail + 4) & (EVMAX - EVSTART - 4); |
| 5625 | } |
| 5626 | |
| 5627 | writew(tail, &(eaddr->ev_tail)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5628 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5629 | |
| 5630 | return 0; |
| 5631 | } |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5632 | |
| 5633 | static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf) |
| 5634 | { |
| 5635 | return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART); |
| 5636 | } |
| 5637 | static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL); |
| 5638 | |
| 5639 | |
| 5640 | static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf) |
| 5641 | { |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 5642 | return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5643 | } |
| 5644 | static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL); |
| 5645 | |
| 5646 | |
| 5647 | static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf) |
| 5648 | { |
| 5649 | return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS); |
| 5650 | } |
| 5651 | static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL); |
| 5652 | |
| 5653 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5654 | static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp, |
| 5655 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5656 | { |
| 5657 | return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter); |
| 5658 | } |
| 5659 | static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL); |
| 5660 | |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5661 | static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf) |
| 5662 | { |
| 5663 | return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick); |
| 5664 | } |
| 5665 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5666 | static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp, |
| 5667 | const char *buf, size_t count) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5668 | { |
Mark Hounschell | c4875eb | 2014-03-04 16:03:10 -0500 | [diff] [blame] | 5669 | if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1) |
| 5670 | return -EINVAL; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5671 | return count; |
| 5672 | } |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5673 | static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show, |
| 5674 | dgap_driver_pollrate_store); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5675 | |
Mark Hounschell | 434b679 | 2014-03-06 13:57:55 -0500 | [diff] [blame] | 5676 | static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5677 | { |
| 5678 | int rc = 0; |
| 5679 | struct device_driver *driverfs = &dgap_driver->driver; |
| 5680 | |
| 5681 | rc |= driver_create_file(driverfs, &driver_attr_version); |
| 5682 | rc |= driver_create_file(driverfs, &driver_attr_boards); |
| 5683 | rc |= driver_create_file(driverfs, &driver_attr_maxboards); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5684 | rc |= driver_create_file(driverfs, &driver_attr_pollrate); |
| 5685 | rc |= driver_create_file(driverfs, &driver_attr_pollcounter); |
Mark Hounschell | 434b679 | 2014-03-06 13:57:55 -0500 | [diff] [blame] | 5686 | |
| 5687 | return rc; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5688 | } |
| 5689 | |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 5690 | static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5691 | { |
| 5692 | struct device_driver *driverfs = &dgap_driver->driver; |
| 5693 | driver_remove_file(driverfs, &driver_attr_version); |
| 5694 | driver_remove_file(driverfs, &driver_attr_boards); |
| 5695 | driver_remove_file(driverfs, &driver_attr_maxboards); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5696 | driver_remove_file(driverfs, &driver_attr_pollrate); |
| 5697 | driver_remove_file(driverfs, &driver_attr_pollcounter); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5698 | } |
| 5699 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5700 | static struct board_t *dgap_verify_board(struct device *p) |
| 5701 | { |
| 5702 | struct board_t *bd; |
| 5703 | |
| 5704 | if (!p) |
| 5705 | return NULL; |
| 5706 | |
| 5707 | bd = dev_get_drvdata(p); |
| 5708 | if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY) |
| 5709 | return NULL; |
| 5710 | |
| 5711 | return bd; |
| 5712 | } |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5713 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5714 | static ssize_t dgap_ports_state_show(struct device *p, |
| 5715 | struct device_attribute *attr, |
| 5716 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5717 | { |
| 5718 | struct board_t *bd; |
| 5719 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5720 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5721 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5722 | bd = dgap_verify_board(p); |
| 5723 | if (!bd) |
| 5724 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5725 | |
| 5726 | for (i = 0; i < bd->nasync; i++) { |
| 5727 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 5728 | "%d %s\n", bd->channels[i]->ch_portnum, |
| 5729 | bd->channels[i]->ch_open_count ? "Open" : "Closed"); |
| 5730 | } |
| 5731 | return count; |
| 5732 | } |
| 5733 | static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL); |
| 5734 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5735 | static ssize_t dgap_ports_baud_show(struct device *p, |
| 5736 | struct device_attribute *attr, |
| 5737 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5738 | { |
| 5739 | struct board_t *bd; |
| 5740 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5741 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5742 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5743 | bd = dgap_verify_board(p); |
| 5744 | if (!bd) |
| 5745 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5746 | |
| 5747 | for (i = 0; i < bd->nasync; i++) { |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5748 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n", |
| 5749 | bd->channels[i]->ch_portnum, |
| 5750 | bd->channels[i]->ch_baud_info); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5751 | } |
| 5752 | return count; |
| 5753 | } |
| 5754 | static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL); |
| 5755 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5756 | static ssize_t dgap_ports_msignals_show(struct device *p, |
| 5757 | struct device_attribute *attr, |
| 5758 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5759 | { |
| 5760 | struct board_t *bd; |
| 5761 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5762 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5763 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5764 | bd = dgap_verify_board(p); |
| 5765 | if (!bd) |
| 5766 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5767 | |
| 5768 | for (i = 0; i < bd->nasync; i++) { |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5769 | if (bd->channels[i]->ch_open_count) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5770 | count += snprintf(buf + count, PAGE_SIZE - count, |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5771 | "%d %s %s %s %s %s %s\n", |
| 5772 | bd->channels[i]->ch_portnum, |
| 5773 | (bd->channels[i]->ch_mostat & |
| 5774 | UART_MCR_RTS) ? "RTS" : "", |
| 5775 | (bd->channels[i]->ch_mistat & |
| 5776 | UART_MSR_CTS) ? "CTS" : "", |
| 5777 | (bd->channels[i]->ch_mostat & |
| 5778 | UART_MCR_DTR) ? "DTR" : "", |
| 5779 | (bd->channels[i]->ch_mistat & |
| 5780 | UART_MSR_DSR) ? "DSR" : "", |
| 5781 | (bd->channels[i]->ch_mistat & |
| 5782 | UART_MSR_DCD) ? "DCD" : "", |
| 5783 | (bd->channels[i]->ch_mistat & |
| 5784 | UART_MSR_RI) ? "RI" : ""); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5785 | else |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5786 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 5787 | "%d\n", bd->channels[i]->ch_portnum); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5788 | } |
| 5789 | return count; |
| 5790 | } |
| 5791 | static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL); |
| 5792 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5793 | static ssize_t dgap_ports_iflag_show(struct device *p, |
| 5794 | struct device_attribute *attr, |
| 5795 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5796 | { |
| 5797 | struct board_t *bd; |
| 5798 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5799 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5800 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5801 | bd = dgap_verify_board(p); |
| 5802 | if (!bd) |
| 5803 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5804 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5805 | for (i = 0; i < bd->nasync; i++) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5806 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n", |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5807 | bd->channels[i]->ch_portnum, |
| 5808 | bd->channels[i]->ch_c_iflag); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5809 | return count; |
| 5810 | } |
| 5811 | static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL); |
| 5812 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5813 | static ssize_t dgap_ports_cflag_show(struct device *p, |
| 5814 | struct device_attribute *attr, |
| 5815 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5816 | { |
| 5817 | struct board_t *bd; |
| 5818 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5819 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5820 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5821 | bd = dgap_verify_board(p); |
| 5822 | if (!bd) |
| 5823 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5824 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5825 | for (i = 0; i < bd->nasync; i++) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5826 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n", |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5827 | bd->channels[i]->ch_portnum, |
| 5828 | bd->channels[i]->ch_c_cflag); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5829 | return count; |
| 5830 | } |
| 5831 | static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL); |
| 5832 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5833 | static ssize_t dgap_ports_oflag_show(struct device *p, |
| 5834 | struct device_attribute *attr, |
| 5835 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5836 | { |
| 5837 | struct board_t *bd; |
| 5838 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5839 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5840 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5841 | bd = dgap_verify_board(p); |
| 5842 | if (!bd) |
| 5843 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5844 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5845 | for (i = 0; i < bd->nasync; i++) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5846 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n", |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5847 | bd->channels[i]->ch_portnum, |
| 5848 | bd->channels[i]->ch_c_oflag); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5849 | return count; |
| 5850 | } |
| 5851 | static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL); |
| 5852 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5853 | static ssize_t dgap_ports_lflag_show(struct device *p, |
| 5854 | struct device_attribute *attr, |
| 5855 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5856 | { |
| 5857 | struct board_t *bd; |
| 5858 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5859 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5860 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5861 | bd = dgap_verify_board(p); |
| 5862 | if (!bd) |
| 5863 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5864 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5865 | for (i = 0; i < bd->nasync; i++) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5866 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n", |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5867 | bd->channels[i]->ch_portnum, |
| 5868 | bd->channels[i]->ch_c_lflag); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5869 | return count; |
| 5870 | } |
| 5871 | static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL); |
| 5872 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5873 | static ssize_t dgap_ports_digi_flag_show(struct device *p, |
| 5874 | struct device_attribute *attr, |
| 5875 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5876 | { |
| 5877 | struct board_t *bd; |
| 5878 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5879 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5880 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5881 | bd = dgap_verify_board(p); |
| 5882 | if (!bd) |
| 5883 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5884 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5885 | for (i = 0; i < bd->nasync; i++) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5886 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n", |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5887 | bd->channels[i]->ch_portnum, |
| 5888 | bd->channels[i]->ch_digi.digi_flags); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5889 | return count; |
| 5890 | } |
| 5891 | static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL); |
| 5892 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5893 | static ssize_t dgap_ports_rxcount_show(struct device *p, |
| 5894 | struct device_attribute *attr, |
| 5895 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5896 | { |
| 5897 | struct board_t *bd; |
| 5898 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5899 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5900 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5901 | bd = dgap_verify_board(p); |
| 5902 | if (!bd) |
| 5903 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5904 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5905 | for (i = 0; i < bd->nasync; i++) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5906 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n", |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5907 | bd->channels[i]->ch_portnum, |
| 5908 | bd->channels[i]->ch_rxcount); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5909 | return count; |
| 5910 | } |
| 5911 | static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL); |
| 5912 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5913 | static ssize_t dgap_ports_txcount_show(struct device *p, |
| 5914 | struct device_attribute *attr, |
| 5915 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5916 | { |
| 5917 | struct board_t *bd; |
| 5918 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5919 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5920 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5921 | bd = dgap_verify_board(p); |
| 5922 | if (!bd) |
| 5923 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5924 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5925 | for (i = 0; i < bd->nasync; i++) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5926 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n", |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5927 | bd->channels[i]->ch_portnum, |
| 5928 | bd->channels[i]->ch_txcount); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5929 | return count; |
| 5930 | } |
| 5931 | static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL); |
| 5932 | |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5933 | /* this function creates the sys files that will export each signal status |
| 5934 | * to sysfs each value will be put in a separate filename |
| 5935 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 5936 | static void dgap_create_ports_sysfiles(struct board_t *bd) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5937 | { |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5938 | dev_set_drvdata(&bd->pdev->dev, bd); |
Mark Hounschell | 434b679 | 2014-03-06 13:57:55 -0500 | [diff] [blame] | 5939 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_state); |
| 5940 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud); |
| 5941 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals); |
| 5942 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag); |
| 5943 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag); |
| 5944 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag); |
| 5945 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag); |
| 5946 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag); |
| 5947 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount); |
| 5948 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5949 | } |
| 5950 | |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5951 | /* removes all the sys files created for that port */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 5952 | static void dgap_remove_ports_sysfiles(struct board_t *bd) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5953 | { |
| 5954 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state); |
| 5955 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud); |
| 5956 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals); |
| 5957 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag); |
| 5958 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag); |
| 5959 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag); |
| 5960 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag); |
| 5961 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag); |
| 5962 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount); |
| 5963 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount); |
| 5964 | } |
| 5965 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5966 | static ssize_t dgap_tty_state_show(struct device *d, |
| 5967 | struct device_attribute *attr, |
| 5968 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5969 | { |
| 5970 | struct board_t *bd; |
| 5971 | struct channel_t *ch; |
| 5972 | struct un_t *un; |
| 5973 | |
| 5974 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5975 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5976 | un = dev_get_drvdata(d); |
| 5977 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5978 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5979 | ch = un->un_ch; |
| 5980 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5981 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5982 | bd = ch->ch_bd; |
| 5983 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5984 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5985 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5986 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5987 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5988 | return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? |
| 5989 | "Open" : "Closed"); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5990 | } |
| 5991 | static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL); |
| 5992 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5993 | static ssize_t dgap_tty_baud_show(struct device *d, |
| 5994 | struct device_attribute *attr, |
| 5995 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5996 | { |
| 5997 | struct board_t *bd; |
| 5998 | struct channel_t *ch; |
| 5999 | struct un_t *un; |
| 6000 | |
| 6001 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6002 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6003 | un = dev_get_drvdata(d); |
| 6004 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6005 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6006 | ch = un->un_ch; |
| 6007 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6008 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6009 | bd = ch->ch_bd; |
| 6010 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6011 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6012 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6013 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6014 | |
| 6015 | return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info); |
| 6016 | } |
| 6017 | static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL); |
| 6018 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6019 | static ssize_t dgap_tty_msignals_show(struct device *d, |
| 6020 | struct device_attribute *attr, |
| 6021 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6022 | { |
| 6023 | struct board_t *bd; |
| 6024 | struct channel_t *ch; |
| 6025 | struct un_t *un; |
| 6026 | |
| 6027 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6028 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6029 | un = dev_get_drvdata(d); |
| 6030 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6031 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6032 | ch = un->un_ch; |
| 6033 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6034 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6035 | bd = ch->ch_bd; |
| 6036 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6037 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6038 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6039 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6040 | |
| 6041 | if (ch->ch_open_count) { |
| 6042 | return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n", |
| 6043 | (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "", |
| 6044 | (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "", |
| 6045 | (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "", |
| 6046 | (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "", |
| 6047 | (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "", |
| 6048 | (ch->ch_mistat & UART_MSR_RI) ? "RI" : ""); |
| 6049 | } |
| 6050 | return 0; |
| 6051 | } |
| 6052 | static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL); |
| 6053 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6054 | static ssize_t dgap_tty_iflag_show(struct device *d, |
| 6055 | struct device_attribute *attr, |
| 6056 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6057 | { |
| 6058 | struct board_t *bd; |
| 6059 | struct channel_t *ch; |
| 6060 | struct un_t *un; |
| 6061 | |
| 6062 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6063 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6064 | un = dev_get_drvdata(d); |
| 6065 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6066 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6067 | ch = un->un_ch; |
| 6068 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6069 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6070 | bd = ch->ch_bd; |
| 6071 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6072 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6073 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6074 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6075 | |
| 6076 | return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag); |
| 6077 | } |
| 6078 | static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL); |
| 6079 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6080 | static ssize_t dgap_tty_cflag_show(struct device *d, |
| 6081 | struct device_attribute *attr, |
| 6082 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6083 | { |
| 6084 | struct board_t *bd; |
| 6085 | struct channel_t *ch; |
| 6086 | struct un_t *un; |
| 6087 | |
| 6088 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6089 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6090 | un = dev_get_drvdata(d); |
| 6091 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6092 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6093 | ch = un->un_ch; |
| 6094 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6095 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6096 | bd = ch->ch_bd; |
| 6097 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6098 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6099 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6100 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6101 | |
| 6102 | return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag); |
| 6103 | } |
| 6104 | static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL); |
| 6105 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6106 | static ssize_t dgap_tty_oflag_show(struct device *d, |
| 6107 | struct device_attribute *attr, |
| 6108 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6109 | { |
| 6110 | struct board_t *bd; |
| 6111 | struct channel_t *ch; |
| 6112 | struct un_t *un; |
| 6113 | |
| 6114 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6115 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6116 | un = dev_get_drvdata(d); |
| 6117 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6118 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6119 | ch = un->un_ch; |
| 6120 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6121 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6122 | bd = ch->ch_bd; |
| 6123 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6124 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6125 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6126 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6127 | |
| 6128 | return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag); |
| 6129 | } |
| 6130 | static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL); |
| 6131 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6132 | static ssize_t dgap_tty_lflag_show(struct device *d, |
| 6133 | struct device_attribute *attr, |
| 6134 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6135 | { |
| 6136 | struct board_t *bd; |
| 6137 | struct channel_t *ch; |
| 6138 | struct un_t *un; |
| 6139 | |
| 6140 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6141 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6142 | un = dev_get_drvdata(d); |
| 6143 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6144 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6145 | ch = un->un_ch; |
| 6146 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6147 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6148 | bd = ch->ch_bd; |
| 6149 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6150 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6151 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6152 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6153 | |
| 6154 | return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag); |
| 6155 | } |
| 6156 | static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL); |
| 6157 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6158 | static ssize_t dgap_tty_digi_flag_show(struct device *d, |
| 6159 | struct device_attribute *attr, |
| 6160 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6161 | { |
| 6162 | struct board_t *bd; |
| 6163 | struct channel_t *ch; |
| 6164 | struct un_t *un; |
| 6165 | |
| 6166 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6167 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6168 | un = dev_get_drvdata(d); |
| 6169 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6170 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6171 | ch = un->un_ch; |
| 6172 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6173 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6174 | bd = ch->ch_bd; |
| 6175 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6176 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6177 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6178 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6179 | |
| 6180 | return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags); |
| 6181 | } |
| 6182 | static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL); |
| 6183 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6184 | static ssize_t dgap_tty_rxcount_show(struct device *d, |
| 6185 | struct device_attribute *attr, |
| 6186 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6187 | { |
| 6188 | struct board_t *bd; |
| 6189 | struct channel_t *ch; |
| 6190 | struct un_t *un; |
| 6191 | |
| 6192 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6193 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6194 | un = dev_get_drvdata(d); |
| 6195 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6196 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6197 | ch = un->un_ch; |
| 6198 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6199 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6200 | bd = ch->ch_bd; |
| 6201 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6202 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6203 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6204 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6205 | |
| 6206 | return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount); |
| 6207 | } |
| 6208 | static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL); |
| 6209 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6210 | static ssize_t dgap_tty_txcount_show(struct device *d, |
| 6211 | struct device_attribute *attr, |
| 6212 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6213 | { |
| 6214 | struct board_t *bd; |
| 6215 | struct channel_t *ch; |
| 6216 | struct un_t *un; |
| 6217 | |
| 6218 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6219 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6220 | un = dev_get_drvdata(d); |
| 6221 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6222 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6223 | ch = un->un_ch; |
| 6224 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6225 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6226 | bd = ch->ch_bd; |
| 6227 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6228 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6229 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6230 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6231 | |
| 6232 | return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount); |
| 6233 | } |
| 6234 | static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL); |
| 6235 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6236 | static ssize_t dgap_tty_name_show(struct device *d, |
| 6237 | struct device_attribute *attr, |
| 6238 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6239 | { |
| 6240 | struct board_t *bd; |
| 6241 | struct channel_t *ch; |
| 6242 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 6243 | int cn; |
| 6244 | int bn; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 6245 | struct cnode *cptr; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6246 | int found = FALSE; |
| 6247 | int ncount = 0; |
| 6248 | int starto = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 6249 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6250 | |
| 6251 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6252 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6253 | un = dev_get_drvdata(d); |
| 6254 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6255 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6256 | ch = un->un_ch; |
| 6257 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6258 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6259 | bd = ch->ch_bd; |
| 6260 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6261 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6262 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6263 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6264 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 6265 | bn = bd->boardnum; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6266 | cn = ch->ch_portnum; |
| 6267 | |
| 6268 | for (cptr = bd->bd_config; cptr; cptr = cptr->next) { |
| 6269 | |
| 6270 | if ((cptr->type == BNODE) && |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6271 | ((cptr->u.board.type == APORT2_920P) || |
| 6272 | (cptr->u.board.type == APORT4_920P) || |
| 6273 | (cptr->u.board.type == APORT8_920P) || |
| 6274 | (cptr->u.board.type == PAPORT4) || |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6275 | (cptr->u.board.type == PAPORT8))) { |
| 6276 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6277 | found = TRUE; |
| 6278 | if (cptr->u.board.v_start) |
| 6279 | starto = cptr->u.board.start; |
| 6280 | else |
| 6281 | starto = 1; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6282 | } |
| 6283 | |
| 6284 | if (cptr->type == TNODE && found == TRUE) { |
| 6285 | char *ptr1; |
| 6286 | if (strstr(cptr->u.ttyname, "tty")) { |
| 6287 | ptr1 = cptr->u.ttyname; |
| 6288 | ptr1 += 3; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 6289 | } else |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6290 | ptr1 = cptr->u.ttyname; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6291 | |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 6292 | for (i = 0; i < dgap_config_get_num_prts(bd); i++) { |
| 6293 | if (cn != i) |
| 6294 | continue; |
| 6295 | |
| 6296 | return snprintf(buf, PAGE_SIZE, "%s%s%02d\n", |
| 6297 | (un->un_type == DGAP_PRINT) ? |
| 6298 | "pr" : "tty", |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6299 | ptr1, i + starto); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6300 | } |
| 6301 | } |
| 6302 | |
| 6303 | if (cptr->type == CNODE) { |
| 6304 | |
| 6305 | for (i = 0; i < cptr->u.conc.nport; i++) { |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 6306 | if (cn != (i + ncount)) |
| 6307 | continue; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6308 | |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6309 | return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n", |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 6310 | (un->un_type == DGAP_PRINT) ? |
| 6311 | "pr" : "tty", |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6312 | cptr->u.conc.id, |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 6313 | i + (cptr->u.conc.v_start ? |
| 6314 | cptr->u.conc.start : 1)); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6315 | } |
| 6316 | |
| 6317 | ncount += cptr->u.conc.nport; |
| 6318 | } |
| 6319 | |
| 6320 | if (cptr->type == MNODE) { |
| 6321 | |
| 6322 | for (i = 0; i < cptr->u.module.nport; i++) { |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 6323 | if (cn != (i + ncount)) |
| 6324 | continue; |
| 6325 | |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6326 | return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n", |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 6327 | (un->un_type == DGAP_PRINT) ? |
| 6328 | "pr" : "tty", |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6329 | cptr->u.module.id, |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 6330 | i + (cptr->u.module.v_start ? |
| 6331 | cptr->u.module.start : 1)); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6332 | } |
| 6333 | |
| 6334 | ncount += cptr->u.module.nport; |
| 6335 | |
| 6336 | } |
| 6337 | } |
| 6338 | |
| 6339 | return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n", |
| 6340 | (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6341 | } |
| 6342 | static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL); |
| 6343 | |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6344 | static struct attribute *dgap_sysfs_tty_entries[] = { |
| 6345 | &dev_attr_state.attr, |
| 6346 | &dev_attr_baud.attr, |
| 6347 | &dev_attr_msignals.attr, |
| 6348 | &dev_attr_iflag.attr, |
| 6349 | &dev_attr_cflag.attr, |
| 6350 | &dev_attr_oflag.attr, |
| 6351 | &dev_attr_lflag.attr, |
| 6352 | &dev_attr_digi_flag.attr, |
| 6353 | &dev_attr_rxcount.attr, |
| 6354 | &dev_attr_txcount.attr, |
| 6355 | &dev_attr_custom_name.attr, |
| 6356 | NULL |
| 6357 | }; |
| 6358 | |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6359 | static struct attribute_group dgap_tty_attribute_group = { |
| 6360 | .name = NULL, |
| 6361 | .attrs = dgap_sysfs_tty_entries, |
| 6362 | }; |
| 6363 | |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 6364 | static void dgap_create_tty_sysfs(struct un_t *un, struct device *c) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6365 | { |
| 6366 | int ret; |
| 6367 | |
| 6368 | ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group); |
Mark Hounschell | 54794d1 | 2014-03-04 16:03:07 -0500 | [diff] [blame] | 6369 | if (ret) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6370 | return; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6371 | |
| 6372 | dev_set_drvdata(c, un); |
| 6373 | |
| 6374 | } |
| 6375 | |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 6376 | static void dgap_remove_tty_sysfs(struct device *c) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6377 | { |
| 6378 | sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group); |
| 6379 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6380 | |
| 6381 | /* |
| 6382 | * Parse a configuration file read into memory as a string. |
| 6383 | */ |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 6384 | static int dgap_parsefile(char **in, int remove) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6385 | { |
| 6386 | struct cnode *p, *brd, *line, *conc; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 6387 | int rc; |
| 6388 | char *s; |
| 6389 | int linecnt = 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6390 | |
| 6391 | p = &dgap_head; |
| 6392 | brd = line = conc = NULL; |
| 6393 | |
| 6394 | /* perhaps we are adding to an existing list? */ |
Mark Hounschell | ee48710 | 2014-05-23 13:13:03 -0400 | [diff] [blame] | 6395 | while (p->next) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6396 | p = p->next; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6397 | |
| 6398 | /* file must start with a BEGIN */ |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 6399 | while ((rc = dgap_gettok(in, p)) != BEGIN) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6400 | if (rc == 0) { |
| 6401 | dgap_err("unexpected EOF"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6402 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6403 | } |
| 6404 | } |
| 6405 | |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 6406 | for (; ;) { |
| 6407 | rc = dgap_gettok(in, p); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6408 | if (rc == 0) { |
| 6409 | dgap_err("unexpected EOF"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6410 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6411 | } |
| 6412 | |
| 6413 | switch (rc) { |
| 6414 | case 0: |
| 6415 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6416 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6417 | |
| 6418 | case BEGIN: /* should only be 1 begin */ |
| 6419 | dgap_err("unexpected config_begin\n"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6420 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6421 | |
| 6422 | case END: |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6423 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6424 | |
| 6425 | case BOARD: /* board info */ |
| 6426 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6427 | return -1; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6428 | p->next = dgap_newnode(BNODE); |
| 6429 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6430 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6431 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6432 | } |
| 6433 | p = p->next; |
| 6434 | |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6435 | p->u.board.status = kstrdup("No", GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6436 | line = conc = NULL; |
| 6437 | brd = p; |
| 6438 | linecnt = -1; |
| 6439 | break; |
| 6440 | |
| 6441 | case APORT2_920P: /* AccelePort_4 */ |
| 6442 | if (p->type != BNODE) { |
| 6443 | dgap_err("unexpected Digi_2r_920 string"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6444 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6445 | } |
| 6446 | p->u.board.type = APORT2_920P; |
| 6447 | p->u.board.v_type = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6448 | break; |
| 6449 | |
| 6450 | case APORT4_920P: /* AccelePort_4 */ |
| 6451 | if (p->type != BNODE) { |
| 6452 | dgap_err("unexpected Digi_4r_920 string"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6453 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6454 | } |
| 6455 | p->u.board.type = APORT4_920P; |
| 6456 | p->u.board.v_type = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6457 | break; |
| 6458 | |
| 6459 | case APORT8_920P: /* AccelePort_8 */ |
| 6460 | if (p->type != BNODE) { |
| 6461 | dgap_err("unexpected Digi_8r_920 string"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6462 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6463 | } |
| 6464 | p->u.board.type = APORT8_920P; |
| 6465 | p->u.board.v_type = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6466 | break; |
| 6467 | |
| 6468 | case PAPORT4: /* AccelePort_4 PCI */ |
| 6469 | if (p->type != BNODE) { |
| 6470 | dgap_err("unexpected Digi_4r(PCI) string"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6471 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6472 | } |
| 6473 | p->u.board.type = PAPORT4; |
| 6474 | p->u.board.v_type = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6475 | break; |
| 6476 | |
| 6477 | case PAPORT8: /* AccelePort_8 PCI */ |
| 6478 | if (p->type != BNODE) { |
| 6479 | dgap_err("unexpected Digi_8r string"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6480 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6481 | } |
| 6482 | p->u.board.type = PAPORT8; |
| 6483 | p->u.board.v_type = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6484 | break; |
| 6485 | |
| 6486 | case PCX: /* PCI C/X */ |
| 6487 | if (p->type != BNODE) { |
| 6488 | dgap_err("unexpected Digi_C/X_(PCI) string"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6489 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6490 | } |
| 6491 | p->u.board.type = PCX; |
| 6492 | p->u.board.v_type = 1; |
| 6493 | p->u.board.conc1 = 0; |
| 6494 | p->u.board.conc2 = 0; |
| 6495 | p->u.board.module1 = 0; |
| 6496 | p->u.board.module2 = 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6497 | break; |
| 6498 | |
| 6499 | case PEPC: /* PCI EPC/X */ |
| 6500 | if (p->type != BNODE) { |
| 6501 | dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6502 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6503 | } |
| 6504 | p->u.board.type = PEPC; |
| 6505 | p->u.board.v_type = 1; |
| 6506 | p->u.board.conc1 = 0; |
| 6507 | p->u.board.conc2 = 0; |
| 6508 | p->u.board.module1 = 0; |
| 6509 | p->u.board.module2 = 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6510 | break; |
| 6511 | |
| 6512 | case PPCM: /* PCI/Xem */ |
| 6513 | if (p->type != BNODE) { |
| 6514 | dgap_err("unexpected PCI/Xem string"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6515 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6516 | } |
| 6517 | p->u.board.type = PPCM; |
| 6518 | p->u.board.v_type = 1; |
| 6519 | p->u.board.conc1 = 0; |
| 6520 | p->u.board.conc2 = 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6521 | break; |
| 6522 | |
| 6523 | case IO: /* i/o port */ |
| 6524 | if (p->type != BNODE) { |
| 6525 | dgap_err("IO port only vaild for boards"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6526 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6527 | } |
| 6528 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6529 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6530 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6531 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6532 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6533 | p->u.board.portstr = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6534 | if (kstrtol(s, 0, &p->u.board.port)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6535 | dgap_err("bad number for IO port"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6536 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6537 | } |
| 6538 | p->u.board.v_port = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6539 | break; |
| 6540 | |
| 6541 | case MEM: /* memory address */ |
| 6542 | if (p->type != BNODE) { |
| 6543 | dgap_err("memory address only vaild for boards"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6544 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6545 | } |
| 6546 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6547 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6548 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6549 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6550 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6551 | p->u.board.addrstr = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6552 | if (kstrtoul(s, 0, &p->u.board.addr)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6553 | dgap_err("bad number for memory address"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6554 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6555 | } |
| 6556 | p->u.board.v_addr = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6557 | break; |
| 6558 | |
| 6559 | case PCIINFO: /* pci information */ |
| 6560 | if (p->type != BNODE) { |
| 6561 | dgap_err("memory address only vaild for boards"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6562 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6563 | } |
| 6564 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6565 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6566 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6567 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6568 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6569 | p->u.board.pcibusstr = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6570 | if (kstrtoul(s, 0, &p->u.board.pcibus)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6571 | dgap_err("bad number for pci bus"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6572 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6573 | } |
| 6574 | p->u.board.v_pcibus = 1; |
| 6575 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6576 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6577 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6578 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6579 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6580 | p->u.board.pcislotstr = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6581 | if (kstrtoul(s, 0, &p->u.board.pcislot)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6582 | dgap_err("bad number for pci slot"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6583 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6584 | } |
| 6585 | p->u.board.v_pcislot = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6586 | break; |
| 6587 | |
| 6588 | case METHOD: |
| 6589 | if (p->type != BNODE) { |
| 6590 | dgap_err("install method only vaild for boards"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6591 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6592 | } |
| 6593 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6594 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6595 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6596 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6597 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6598 | p->u.board.method = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6599 | p->u.board.v_method = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6600 | break; |
| 6601 | |
| 6602 | case STATUS: |
| 6603 | if (p->type != BNODE) { |
| 6604 | dgap_err("config status only vaild for boards"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6605 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6606 | } |
| 6607 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6608 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6609 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6610 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6611 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6612 | p->u.board.status = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6613 | break; |
| 6614 | |
| 6615 | case NPORTS: /* number of ports */ |
| 6616 | if (p->type == BNODE) { |
| 6617 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6618 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6619 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6620 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6621 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6622 | if (kstrtol(s, 0, &p->u.board.nport)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6623 | dgap_err("bad number for number of ports"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6624 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6625 | } |
| 6626 | p->u.board.v_nport = 1; |
| 6627 | } else if (p->type == CNODE) { |
| 6628 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6629 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6630 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6631 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6632 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6633 | if (kstrtol(s, 0, &p->u.conc.nport)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6634 | dgap_err("bad number for number of ports"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6635 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6636 | } |
| 6637 | p->u.conc.v_nport = 1; |
| 6638 | } else if (p->type == MNODE) { |
| 6639 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6640 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6641 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6642 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6643 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6644 | if (kstrtol(s, 0, &p->u.module.nport)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6645 | dgap_err("bad number for number of ports"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6646 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6647 | } |
| 6648 | p->u.module.v_nport = 1; |
| 6649 | } else { |
| 6650 | dgap_err("nports only valid for concentrators or modules"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6651 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6652 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6653 | break; |
| 6654 | |
| 6655 | case ID: /* letter ID used in tty name */ |
| 6656 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6657 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6658 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6659 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6660 | } |
| 6661 | |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6662 | p->u.board.status = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6663 | |
| 6664 | if (p->type == CNODE) { |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6665 | p->u.conc.id = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6666 | p->u.conc.v_id = 1; |
| 6667 | } else if (p->type == MNODE) { |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6668 | p->u.module.id = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6669 | p->u.module.v_id = 1; |
| 6670 | } else { |
| 6671 | dgap_err("id only valid for concentrators or modules"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6672 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6673 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6674 | break; |
| 6675 | |
| 6676 | case STARTO: /* start offset of ID */ |
| 6677 | if (p->type == BNODE) { |
| 6678 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6679 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6680 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6681 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6682 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6683 | if (kstrtol(s, 0, &p->u.board.start)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6684 | dgap_err("bad number for start of tty count"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6685 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6686 | } |
| 6687 | p->u.board.v_start = 1; |
| 6688 | } else if (p->type == CNODE) { |
| 6689 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6690 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6691 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6692 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6693 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6694 | if (kstrtol(s, 0, &p->u.conc.start)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6695 | dgap_err("bad number for start of tty count"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6696 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6697 | } |
| 6698 | p->u.conc.v_start = 1; |
| 6699 | } else if (p->type == MNODE) { |
| 6700 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6701 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6702 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6703 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6704 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6705 | if (kstrtol(s, 0, &p->u.module.start)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6706 | dgap_err("bad number for start of tty count"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6707 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6708 | } |
| 6709 | p->u.module.v_start = 1; |
| 6710 | } else { |
| 6711 | dgap_err("start only valid for concentrators or modules"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6712 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6713 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6714 | break; |
| 6715 | |
| 6716 | case TTYN: /* tty name prefix */ |
| 6717 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6718 | return -1; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6719 | p->next = dgap_newnode(TNODE); |
| 6720 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6721 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6722 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6723 | } |
| 6724 | p = p->next; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6725 | s = dgap_getword(in); |
| 6726 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6727 | dgap_err("unexpeced end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6728 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6729 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6730 | p->u.ttyname = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6731 | if (!p->u.ttyname) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6732 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6733 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6734 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6735 | break; |
| 6736 | |
| 6737 | case CU: /* cu name prefix */ |
| 6738 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6739 | return -1; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6740 | p->next = dgap_newnode(CUNODE); |
| 6741 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6742 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6743 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6744 | } |
| 6745 | p = p->next; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6746 | s = dgap_getword(in); |
| 6747 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6748 | dgap_err("unexpeced end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6749 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6750 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6751 | p->u.cuname = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6752 | if (!p->u.cuname) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6753 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6754 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6755 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6756 | break; |
| 6757 | |
| 6758 | case LINE: /* line information */ |
| 6759 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6760 | return -1; |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6761 | if (!brd) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6762 | dgap_err("must specify board before line info"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6763 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6764 | } |
| 6765 | switch (brd->u.board.type) { |
| 6766 | case PPCM: |
| 6767 | dgap_err("line not vaild for PC/em"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6768 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6769 | } |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6770 | p->next = dgap_newnode(LNODE); |
| 6771 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6772 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6773 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6774 | } |
| 6775 | p = p->next; |
| 6776 | conc = NULL; |
| 6777 | line = p; |
| 6778 | linecnt++; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6779 | break; |
| 6780 | |
| 6781 | case CONC: /* concentrator information */ |
| 6782 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6783 | return -1; |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6784 | if (!line) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6785 | dgap_err("must specify line info before concentrator"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6786 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6787 | } |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6788 | p->next = dgap_newnode(CNODE); |
| 6789 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6790 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6791 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6792 | } |
| 6793 | p = p->next; |
| 6794 | conc = p; |
| 6795 | if (linecnt) |
| 6796 | brd->u.board.conc2++; |
| 6797 | else |
| 6798 | brd->u.board.conc1++; |
| 6799 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6800 | break; |
| 6801 | |
| 6802 | case CX: /* c/x type concentrator */ |
| 6803 | if (p->type != CNODE) { |
| 6804 | dgap_err("cx only valid for concentrators"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6805 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6806 | } |
| 6807 | p->u.conc.type = CX; |
| 6808 | p->u.conc.v_type = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6809 | break; |
| 6810 | |
| 6811 | case EPC: /* epc type concentrator */ |
| 6812 | if (p->type != CNODE) { |
| 6813 | dgap_err("cx only valid for concentrators"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6814 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6815 | } |
| 6816 | p->u.conc.type = EPC; |
| 6817 | p->u.conc.v_type = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6818 | break; |
| 6819 | |
| 6820 | case MOD: /* EBI module */ |
| 6821 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6822 | return -1; |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6823 | if (!brd) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6824 | dgap_err("must specify board info before EBI modules"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6825 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6826 | } |
| 6827 | switch (brd->u.board.type) { |
| 6828 | case PPCM: |
| 6829 | linecnt = 0; |
| 6830 | break; |
| 6831 | default: |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6832 | if (!conc) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6833 | dgap_err("must specify concentrator info before EBI module"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6834 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6835 | } |
| 6836 | } |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6837 | p->next = dgap_newnode(MNODE); |
| 6838 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6839 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6840 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6841 | } |
| 6842 | p = p->next; |
| 6843 | if (linecnt) |
| 6844 | brd->u.board.module2++; |
| 6845 | else |
| 6846 | brd->u.board.module1++; |
| 6847 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6848 | break; |
| 6849 | |
| 6850 | case PORTS: /* ports type EBI module */ |
| 6851 | if (p->type != MNODE) { |
| 6852 | dgap_err("ports only valid for EBI modules"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6853 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6854 | } |
| 6855 | p->u.module.type = PORTS; |
| 6856 | p->u.module.v_type = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6857 | break; |
| 6858 | |
| 6859 | case MODEM: /* ports type EBI module */ |
| 6860 | if (p->type != MNODE) { |
| 6861 | dgap_err("modem only valid for modem modules"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6862 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6863 | } |
| 6864 | p->u.module.type = MODEM; |
| 6865 | p->u.module.v_type = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6866 | break; |
| 6867 | |
| 6868 | case CABLE: |
| 6869 | if (p->type == LNODE) { |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6870 | s = dgap_getword(in); |
| 6871 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6872 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6873 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6874 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6875 | p->u.line.cable = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6876 | p->u.line.v_cable = 1; |
| 6877 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6878 | break; |
| 6879 | |
| 6880 | case SPEED: /* sync line speed indication */ |
| 6881 | if (p->type == LNODE) { |
| 6882 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6883 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6884 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6885 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6886 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6887 | if (kstrtol(s, 0, &p->u.line.speed)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6888 | dgap_err("bad number for line speed"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6889 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6890 | } |
| 6891 | p->u.line.v_speed = 1; |
| 6892 | } else if (p->type == CNODE) { |
| 6893 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6894 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6895 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6896 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6897 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6898 | if (kstrtol(s, 0, &p->u.conc.speed)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6899 | dgap_err("bad number for line speed"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6900 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6901 | } |
| 6902 | p->u.conc.v_speed = 1; |
| 6903 | } else { |
| 6904 | dgap_err("speed valid only for lines or concentrators."); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6905 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6906 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6907 | break; |
| 6908 | |
| 6909 | case CONNECT: |
| 6910 | if (p->type == CNODE) { |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6911 | s = dgap_getword(in); |
| 6912 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6913 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6914 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6915 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6916 | p->u.conc.connect = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6917 | p->u.conc.v_connect = 1; |
| 6918 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6919 | break; |
| 6920 | case PRINT: /* transparent print name prefix */ |
| 6921 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6922 | return -1; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6923 | p->next = dgap_newnode(PNODE); |
| 6924 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6925 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6926 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6927 | } |
| 6928 | p = p->next; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6929 | s = dgap_getword(in); |
| 6930 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6931 | dgap_err("unexpeced end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6932 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6933 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6934 | p->u.printname = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6935 | if (!p->u.printname) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6936 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6937 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6938 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6939 | break; |
| 6940 | |
| 6941 | case CMAJOR: /* major number */ |
| 6942 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6943 | return -1; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6944 | p->next = dgap_newnode(JNODE); |
| 6945 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6946 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6947 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6948 | } |
| 6949 | p = p->next; |
| 6950 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6951 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6952 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6953 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6954 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6955 | if (kstrtol(s, 0, &p->u.majornumber)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6956 | dgap_err("bad number for major number"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6957 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6958 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6959 | break; |
| 6960 | |
| 6961 | case ALTPIN: /* altpin setting */ |
| 6962 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6963 | return -1; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6964 | p->next = dgap_newnode(ANODE); |
| 6965 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6966 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6967 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6968 | } |
| 6969 | p = p->next; |
| 6970 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6971 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6972 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6973 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6974 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6975 | if (kstrtol(s, 0, &p->u.altpin)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6976 | dgap_err("bad number for altpin"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6977 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6978 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6979 | break; |
| 6980 | |
| 6981 | case USEINTR: /* enable interrupt setting */ |
| 6982 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6983 | return -1; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6984 | p->next = dgap_newnode(INTRNODE); |
| 6985 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6986 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6987 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6988 | } |
| 6989 | p = p->next; |
| 6990 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6991 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6992 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6993 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6994 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6995 | if (kstrtol(s, 0, &p->u.useintr)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6996 | dgap_err("bad number for useintr"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6997 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6998 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6999 | break; |
| 7000 | |
| 7001 | case TTSIZ: /* size of tty structure */ |
| 7002 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7003 | return -1; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 7004 | p->next = dgap_newnode(TSNODE); |
| 7005 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7006 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7007 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7008 | } |
| 7009 | p = p->next; |
| 7010 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 7011 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7012 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7013 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7014 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 7015 | if (kstrtol(s, 0, &p->u.ttysize)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7016 | dgap_err("bad number for ttysize"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7017 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7018 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7019 | break; |
| 7020 | |
| 7021 | case CHSIZ: /* channel structure size */ |
| 7022 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7023 | return -1; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 7024 | p->next = dgap_newnode(CSNODE); |
| 7025 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7026 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7027 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7028 | } |
| 7029 | p = p->next; |
| 7030 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 7031 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7032 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7033 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7034 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 7035 | if (kstrtol(s, 0, &p->u.chsize)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7036 | dgap_err("bad number for chsize"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7037 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7038 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7039 | break; |
| 7040 | |
| 7041 | case BSSIZ: /* board structure size */ |
| 7042 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7043 | return -1; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 7044 | p->next = dgap_newnode(BSNODE); |
| 7045 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7046 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7047 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7048 | } |
| 7049 | p = p->next; |
| 7050 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 7051 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7052 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7053 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7054 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 7055 | if (kstrtol(s, 0, &p->u.bssize)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7056 | dgap_err("bad number for bssize"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7057 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7058 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7059 | break; |
| 7060 | |
| 7061 | case UNTSIZ: /* sched structure size */ |
| 7062 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7063 | return -1; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 7064 | p->next = dgap_newnode(USNODE); |
| 7065 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7066 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7067 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7068 | } |
| 7069 | p = p->next; |
| 7070 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 7071 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7072 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7073 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7074 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 7075 | if (kstrtol(s, 0, &p->u.unsize)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7076 | dgap_err("bad number for schedsize"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7077 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7078 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7079 | break; |
| 7080 | |
| 7081 | case F2SIZ: /* f2200 structure size */ |
| 7082 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7083 | return -1; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 7084 | p->next = dgap_newnode(FSNODE); |
| 7085 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7086 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7087 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7088 | } |
| 7089 | p = p->next; |
| 7090 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 7091 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7092 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7093 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7094 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 7095 | if (kstrtol(s, 0, &p->u.f2size)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7096 | dgap_err("bad number for f2200size"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7097 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7098 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7099 | break; |
| 7100 | |
| 7101 | case VPSIZ: /* vpix structure size */ |
| 7102 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7103 | return -1; |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 7104 | p->next = dgap_newnode(VSNODE); |
| 7105 | if (!p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7106 | dgap_err("out of memory"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7107 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7108 | } |
| 7109 | p = p->next; |
| 7110 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 7111 | if (!s) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7112 | dgap_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7113 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7114 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 7115 | if (kstrtol(s, 0, &p->u.vpixsize)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7116 | dgap_err("bad number for vpixsize"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7117 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7118 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7119 | break; |
| 7120 | } |
| 7121 | } |
| 7122 | } |
| 7123 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7124 | /* |
| 7125 | * dgap_sindex: much like index(), but it looks for a match of any character in |
| 7126 | * the group, and returns that position. If the first character is a ^, then |
| 7127 | * this will match the first occurrence not in that group. |
| 7128 | */ |
Mark Hounschell | 9b073ac | 2014-03-03 13:45:42 -0500 | [diff] [blame] | 7129 | static char *dgap_sindex(char *string, char *group) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7130 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 7131 | char *ptr; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7132 | |
| 7133 | if (!string || !group) |
| 7134 | return (char *) NULL; |
| 7135 | |
| 7136 | if (*group == '^') { |
| 7137 | group++; |
| 7138 | for (; *string; string++) { |
| 7139 | for (ptr = group; *ptr; ptr++) { |
| 7140 | if (*ptr == *string) |
| 7141 | break; |
| 7142 | } |
| 7143 | if (*ptr == '\0') |
| 7144 | return string; |
| 7145 | } |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 7146 | } else { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7147 | for (; *string; string++) { |
| 7148 | for (ptr = group; *ptr; ptr++) { |
| 7149 | if (*ptr == *string) |
| 7150 | return string; |
| 7151 | } |
| 7152 | } |
| 7153 | } |
| 7154 | |
| 7155 | return (char *) NULL; |
| 7156 | } |
| 7157 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7158 | /* |
| 7159 | * Get a token from the input file; return 0 if end of file is reached |
| 7160 | */ |
| 7161 | static int dgap_gettok(char **in, struct cnode *p) |
| 7162 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 7163 | char *w; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7164 | struct toklist *t; |
| 7165 | |
| 7166 | if (strstr(dgap_cword, "boar")) { |
| 7167 | w = dgap_getword(in); |
| 7168 | snprintf(dgap_cword, MAXCWORD, "%s", w); |
| 7169 | for (t = dgap_tlist; t->token != 0; t++) { |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 7170 | if (!strcmp(w, t->string)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7171 | return t->token; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7172 | } |
| 7173 | dgap_err("board !!type not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7174 | return 1; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 7175 | } else { |
Mark Hounschell | 9b073ac | 2014-03-03 13:45:42 -0500 | [diff] [blame] | 7176 | while ((w = dgap_getword(in))) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7177 | snprintf(dgap_cword, MAXCWORD, "%s", w); |
| 7178 | for (t = dgap_tlist; t->token != 0; t++) { |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 7179 | if (!strcmp(w, t->string)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7180 | return t->token; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7181 | } |
| 7182 | } |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7183 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7184 | } |
| 7185 | } |
| 7186 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7187 | /* |
| 7188 | * get a word from the input stream, also keep track of current line number. |
| 7189 | * words are separated by whitespace. |
| 7190 | */ |
| 7191 | static char *dgap_getword(char **in) |
| 7192 | { |
| 7193 | char *ret_ptr = *in; |
| 7194 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 7195 | char *ptr = dgap_sindex(*in, " \t\n"); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7196 | |
| 7197 | /* If no word found, return null */ |
| 7198 | if (!ptr) |
| 7199 | return NULL; |
| 7200 | |
| 7201 | /* Mark new location for our buffer */ |
| 7202 | *ptr = '\0'; |
| 7203 | *in = ptr + 1; |
| 7204 | |
| 7205 | /* Eat any extra spaces/tabs/newlines that might be present */ |
Mark Hounschell | 93fb1e2 | 2014-03-10 15:46:55 -0400 | [diff] [blame] | 7206 | while (*in && **in && ((**in == ' ') || |
| 7207 | (**in == '\t') || |
| 7208 | (**in == '\n'))) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7209 | **in = '\0'; |
| 7210 | *in = *in + 1; |
| 7211 | } |
| 7212 | |
| 7213 | return ret_ptr; |
| 7214 | } |
| 7215 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7216 | /* |
| 7217 | * print an error message, giving the line number in the file where |
| 7218 | * the error occurred. |
| 7219 | */ |
| 7220 | static void dgap_err(char *s) |
| 7221 | { |
Mark Hounschell | 8cbb5e3 | 2014-03-03 14:20:51 -0500 | [diff] [blame] | 7222 | pr_err("dgap: parse: %s\n", s); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7223 | } |
| 7224 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7225 | /* |
| 7226 | * allocate a new configuration node of type t |
| 7227 | */ |
| 7228 | static struct cnode *dgap_newnode(int t) |
| 7229 | { |
| 7230 | struct cnode *n; |
| 7231 | |
Mark Hounschell | 244a034 | 2014-05-23 14:02:34 -0400 | [diff] [blame] | 7232 | n = kmalloc(sizeof(struct cnode), GFP_KERNEL); |
Mark Hounschell | ee48710 | 2014-05-23 13:13:03 -0400 | [diff] [blame] | 7233 | if (n) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7234 | memset((char *)n, 0, sizeof(struct cnode)); |
| 7235 | n->type = t; |
| 7236 | } |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7237 | return n; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7238 | } |
| 7239 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7240 | /* |
| 7241 | * dgap_checknode: see if all the necessary info has been supplied for a node |
| 7242 | * before creating the next node. |
| 7243 | */ |
| 7244 | static int dgap_checknode(struct cnode *p) |
| 7245 | { |
| 7246 | switch (p->type) { |
| 7247 | case BNODE: |
| 7248 | if (p->u.board.v_type == 0) { |
| 7249 | dgap_err("board type !not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7250 | return 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7251 | } |
| 7252 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7253 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7254 | |
| 7255 | case LNODE: |
| 7256 | if (p->u.line.v_speed == 0) { |
| 7257 | dgap_err("line speed not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7258 | return 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7259 | } |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7260 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7261 | |
| 7262 | case CNODE: |
| 7263 | if (p->u.conc.v_type == 0) { |
| 7264 | dgap_err("concentrator type not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7265 | return 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7266 | } |
| 7267 | if (p->u.conc.v_speed == 0) { |
| 7268 | dgap_err("concentrator line speed not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7269 | return 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7270 | } |
| 7271 | if (p->u.conc.v_nport == 0) { |
| 7272 | dgap_err("number of ports on concentrator not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7273 | return 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7274 | } |
| 7275 | if (p->u.conc.v_id == 0) { |
| 7276 | dgap_err("concentrator id letter not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7277 | return 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7278 | } |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7279 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7280 | |
| 7281 | case MNODE: |
| 7282 | if (p->u.module.v_type == 0) { |
| 7283 | dgap_err("EBI module type not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7284 | return 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7285 | } |
| 7286 | if (p->u.module.v_nport == 0) { |
| 7287 | dgap_err("number of ports on EBI module not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7288 | return 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7289 | } |
| 7290 | if (p->u.module.v_id == 0) { |
| 7291 | dgap_err("EBI module id letter not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7292 | return 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7293 | } |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7294 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7295 | } |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7296 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7297 | } |
| 7298 | |
| 7299 | /* |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7300 | * Given a board pointer, returns whether we should use interrupts or not. |
| 7301 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 7302 | static uint dgap_config_get_useintr(struct board_t *bd) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7303 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 7304 | struct cnode *p; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7305 | |
| 7306 | if (!bd) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7307 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7308 | |
| 7309 | for (p = bd->bd_config; p; p = p->next) { |
Mark Hounschell | 0c24b23 | 2014-05-23 13:45:57 -0400 | [diff] [blame] | 7310 | if (p->type == INTRNODE) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7311 | /* |
| 7312 | * check for pcxr types. |
| 7313 | */ |
| 7314 | return p->u.useintr; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7315 | } |
| 7316 | } |
| 7317 | |
| 7318 | /* If not found, then don't turn on interrupts. */ |
| 7319 | return 0; |
| 7320 | } |
| 7321 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7322 | /* |
| 7323 | * Given a board pointer, returns whether we turn on altpin or not. |
| 7324 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 7325 | static uint dgap_config_get_altpin(struct board_t *bd) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7326 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 7327 | struct cnode *p; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7328 | |
| 7329 | if (!bd) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7330 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7331 | |
| 7332 | for (p = bd->bd_config; p; p = p->next) { |
Mark Hounschell | 0c24b23 | 2014-05-23 13:45:57 -0400 | [diff] [blame] | 7333 | if (p->type == ANODE) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7334 | /* |
| 7335 | * check for pcxr types. |
| 7336 | */ |
| 7337 | return p->u.altpin; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7338 | } |
| 7339 | } |
| 7340 | |
| 7341 | /* If not found, then don't turn on interrupts. */ |
| 7342 | return 0; |
| 7343 | } |
| 7344 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7345 | /* |
| 7346 | * Given a specific type of board, if found, detached link and |
| 7347 | * returns the first occurrence in the list. |
| 7348 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 7349 | static struct cnode *dgap_find_config(int type, int bus, int slot) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7350 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 7351 | struct cnode *p, *prev, *prev2, *found; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7352 | |
| 7353 | p = &dgap_head; |
| 7354 | |
Mark Hounschell | ee48710 | 2014-05-23 13:13:03 -0400 | [diff] [blame] | 7355 | while (p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7356 | prev = p; |
| 7357 | p = p->next; |
| 7358 | |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7359 | if (p->type != BNODE) |
| 7360 | continue; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7361 | |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7362 | if (p->u.board.type != type) |
| 7363 | continue; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7364 | |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7365 | if (p->u.board.v_pcibus && |
| 7366 | p->u.board.pcibus != bus) |
| 7367 | continue; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7368 | |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7369 | if (p->u.board.v_pcislot && |
| 7370 | p->u.board.pcislot != slot) |
| 7371 | continue; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7372 | |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7373 | found = p; |
| 7374 | /* |
| 7375 | * Keep walking thru the list till we |
| 7376 | * find the next board. |
| 7377 | */ |
| 7378 | while (p->next) { |
| 7379 | prev2 = p; |
| 7380 | p = p->next; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7381 | |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7382 | if (p->type != BNODE) |
| 7383 | continue; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7384 | |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7385 | /* |
| 7386 | * Mark the end of our 1 board |
| 7387 | * chain of configs. |
| 7388 | */ |
| 7389 | prev2->next = NULL; |
| 7390 | |
| 7391 | /* |
| 7392 | * Link the "next" board to the |
| 7393 | * previous board, effectively |
| 7394 | * "unlinking" our board from |
| 7395 | * the main config. |
| 7396 | */ |
| 7397 | prev->next = p; |
| 7398 | |
| 7399 | return found; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7400 | } |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7401 | /* |
| 7402 | * It must be the last board in the list. |
| 7403 | */ |
| 7404 | prev->next = NULL; |
| 7405 | return found; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7406 | } |
| 7407 | return NULL; |
| 7408 | } |
| 7409 | |
| 7410 | /* |
| 7411 | * Given a board pointer, walks the config link, counting up |
| 7412 | * all ports user specified should be on the board. |
| 7413 | * (This does NOT mean they are all actually present right now tho) |
| 7414 | */ |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 7415 | static uint dgap_config_get_num_prts(struct board_t *bd) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7416 | { |
| 7417 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 7418 | struct cnode *p; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7419 | |
| 7420 | if (!bd) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7421 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7422 | |
| 7423 | for (p = bd->bd_config; p; p = p->next) { |
| 7424 | |
| 7425 | switch (p->type) { |
| 7426 | case BNODE: |
| 7427 | /* |
| 7428 | * check for pcxr types. |
| 7429 | */ |
| 7430 | if (p->u.board.type > EPCFE) |
| 7431 | count += p->u.board.nport; |
| 7432 | break; |
| 7433 | case CNODE: |
| 7434 | count += p->u.conc.nport; |
| 7435 | break; |
| 7436 | case MNODE: |
| 7437 | count += p->u.module.nport; |
| 7438 | break; |
| 7439 | } |
| 7440 | } |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7441 | return count; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7442 | } |
| 7443 | |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 7444 | static char *dgap_create_config_string(struct board_t *bd, char *string) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7445 | { |
| 7446 | char *ptr = string; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 7447 | struct cnode *p; |
| 7448 | struct cnode *q; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7449 | int speed; |
| 7450 | |
| 7451 | if (!bd) { |
| 7452 | *ptr = 0xff; |
| 7453 | return string; |
| 7454 | } |
| 7455 | |
| 7456 | for (p = bd->bd_config; p; p = p->next) { |
| 7457 | |
| 7458 | switch (p->type) { |
| 7459 | case LNODE: |
| 7460 | *ptr = '\0'; |
| 7461 | ptr++; |
| 7462 | *ptr = p->u.line.speed; |
| 7463 | ptr++; |
| 7464 | break; |
| 7465 | case CNODE: |
| 7466 | /* |
| 7467 | * Because the EPC/con concentrators can have EM modules |
Mark Hounschell | 93fb1e2 | 2014-03-10 15:46:55 -0400 | [diff] [blame] | 7468 | * hanging off of them, we have to walk ahead in the |
| 7469 | * list and keep adding the number of ports on each EM |
| 7470 | * to the config. UGH! |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7471 | */ |
| 7472 | speed = p->u.conc.speed; |
| 7473 | q = p->next; |
Mark Hounschell | ee48710 | 2014-05-23 13:13:03 -0400 | [diff] [blame] | 7474 | if (q && (q->type == MNODE)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7475 | *ptr = (p->u.conc.nport + 0x80); |
| 7476 | ptr++; |
| 7477 | p = q; |
Mark Hounschell | ee48710 | 2014-05-23 13:13:03 -0400 | [diff] [blame] | 7478 | while (q->next && (q->next->type) == MNODE) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7479 | *ptr = (q->u.module.nport + 0x80); |
| 7480 | ptr++; |
| 7481 | p = q; |
| 7482 | q = q->next; |
| 7483 | } |
| 7484 | *ptr = q->u.module.nport; |
| 7485 | ptr++; |
| 7486 | } else { |
| 7487 | *ptr = p->u.conc.nport; |
| 7488 | ptr++; |
| 7489 | } |
| 7490 | |
| 7491 | *ptr = speed; |
| 7492 | ptr++; |
| 7493 | break; |
| 7494 | } |
| 7495 | } |
| 7496 | |
| 7497 | *ptr = 0xff; |
| 7498 | return string; |
| 7499 | } |