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 | |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 44 | #define pr_fmt(fmt) "dgap: " fmt |
| 45 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 46 | #include <linux/kernel.h> |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 47 | #include <linux/module.h> |
| 48 | #include <linux/pci.h> |
| 49 | #include <linux/delay.h> /* For udelay */ |
Geert Uytterhoeven | 351699d | 2013-08-29 22:53:25 +0200 | [diff] [blame] | 50 | #include <linux/slab.h> |
Mark Hounschell | 3d9dc5d | 2014-02-28 12:42:12 -0500 | [diff] [blame] | 51 | #include <linux/uaccess.h> |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 52 | #include <linux/sched.h> |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 53 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 54 | #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */ |
| 55 | #include <linux/ctype.h> |
| 56 | #include <linux/tty.h> |
| 57 | #include <linux/tty_flip.h> |
| 58 | #include <linux/serial_reg.h> |
Mark Hounschell | 3d9dc5d | 2014-02-28 12:42:12 -0500 | [diff] [blame] | 59 | #include <linux/io.h> /* For read[bwl]/write[bwl] */ |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 60 | |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 61 | #include <linux/string.h> |
| 62 | #include <linux/device.h> |
| 63 | #include <linux/kdev_t.h> |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 64 | #include <linux/firmware.h> |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 65 | |
Mark Hounschell | ffc1c1d | 2014-02-19 13:12:14 -0500 | [diff] [blame] | 66 | #include "dgap.h" |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 67 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 68 | MODULE_LICENSE("GPL"); |
| 69 | MODULE_AUTHOR("Digi International, http://www.digi.com"); |
| 70 | MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line"); |
| 71 | MODULE_SUPPORTED_DEVICE("dgap"); |
| 72 | |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 73 | static int dgap_start(void); |
| 74 | static void dgap_init_globals(void); |
Daeseok Youn | 7bc26a6 | 2014-06-20 18:21:50 +0900 | [diff] [blame] | 75 | static struct board_t *dgap_found_board(struct pci_dev *pdev, int id, |
| 76 | int boardnum); |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 77 | static void dgap_cleanup_board(struct board_t *brd); |
| 78 | static void dgap_poll_handler(ulong dummy); |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 79 | static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); |
| 80 | static void dgap_remove_one(struct pci_dev *dev); |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 81 | static int dgap_do_remap(struct board_t *brd); |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 82 | static void dgap_release_remap(struct board_t *brd); |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 83 | static irqreturn_t dgap_intr(int irq, void *voidbrd); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 84 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 85 | static int dgap_tty_open(struct tty_struct *tty, struct file *file); |
| 86 | static void dgap_tty_close(struct tty_struct *tty, struct file *file); |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 87 | static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, |
| 88 | struct channel_t *ch); |
| 89 | static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, |
| 90 | unsigned long arg); |
Piotr Witoslawski | 70c0ed9 | 2014-09-04 08:18:53 +0200 | [diff] [blame] | 91 | static int dgap_tty_digigeta(struct channel_t *ch, |
| 92 | struct digi_t __user *retinfo); |
Daeseok Youn | ffc11c1 | 2014-07-11 19:22:58 +0900 | [diff] [blame] | 93 | static int dgap_tty_digiseta(struct channel_t *ch, struct board_t *bd, |
| 94 | struct un_t *un, struct digi_t __user *new_info); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 95 | static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo); |
Daeseok Youn | ccbe7e5 | 2014-07-11 19:23:54 +0900 | [diff] [blame] | 96 | static int dgap_tty_digisetedelay(struct channel_t *ch, struct board_t *bd, |
| 97 | struct un_t *un, int __user *new_info); |
Mark Hounschell | 5e9d817 | 2014-02-28 12:42:11 -0500 | [diff] [blame] | 98 | static int dgap_tty_write_room(struct tty_struct *tty); |
| 99 | static int dgap_tty_chars_in_buffer(struct tty_struct *tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 100 | static void dgap_tty_start(struct tty_struct *tty); |
| 101 | static void dgap_tty_stop(struct tty_struct *tty); |
| 102 | static void dgap_tty_throttle(struct tty_struct *tty); |
| 103 | static void dgap_tty_unthrottle(struct tty_struct *tty); |
| 104 | static void dgap_tty_flush_chars(struct tty_struct *tty); |
| 105 | static void dgap_tty_flush_buffer(struct tty_struct *tty); |
| 106 | static void dgap_tty_hangup(struct tty_struct *tty); |
| 107 | static int dgap_wait_for_drain(struct tty_struct *tty); |
Piotr Witoslawski | 70c0ed9 | 2014-09-04 08:18:53 +0200 | [diff] [blame] | 108 | static int dgap_set_modem_info(struct channel_t *ch, struct board_t *bd, |
| 109 | struct un_t *un, unsigned int command, |
| 110 | unsigned int __user *value); |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 111 | static int dgap_get_modem_info(struct channel_t *ch, |
| 112 | unsigned int __user *value); |
Daeseok Youn | db6fc2d | 2014-07-11 19:24:34 +0900 | [diff] [blame] | 113 | static int dgap_tty_digisetcustombaud(struct channel_t *ch, struct board_t *bd, |
| 114 | struct un_t *un, int __user *new_info); |
Daeseok Youn | 501bcd4 | 2014-07-11 19:24:14 +0900 | [diff] [blame] | 115 | static int dgap_tty_digigetcustombaud(struct channel_t *ch, struct un_t *un, |
| 116 | int __user *retinfo); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 117 | static int dgap_tty_tiocmget(struct tty_struct *tty); |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 118 | static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set, |
| 119 | unsigned int clear); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 120 | static int dgap_tty_send_break(struct tty_struct *tty, int msec); |
| 121 | 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] | 122 | static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, |
| 123 | int count); |
| 124 | static void dgap_tty_set_termios(struct tty_struct *tty, |
| 125 | struct ktermios *old_termios); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 126 | static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c); |
| 127 | static void dgap_tty_send_xchar(struct tty_struct *tty, char ch); |
| 128 | |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 129 | static int dgap_tty_register(struct board_t *brd); |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 130 | static void dgap_tty_unregister(struct board_t *brd); |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 131 | static int dgap_tty_init(struct board_t *); |
Daeseok Youn | 08f53f6 | 2014-06-13 18:19:55 +0900 | [diff] [blame] | 132 | static void dgap_tty_free(struct board_t *); |
Daeseok Youn | 7bf0a4c | 2014-06-03 15:28:42 +0900 | [diff] [blame] | 133 | static void dgap_cleanup_tty(struct board_t *); |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 134 | static void dgap_carrier(struct channel_t *ch); |
| 135 | static void dgap_input(struct channel_t *ch); |
Mark Hounschell | 4aeafa8 | 2014-02-19 13:12:04 -0500 | [diff] [blame] | 136 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 137 | /* |
| 138 | * Our function prototypes from dgap_fep5 |
| 139 | */ |
| 140 | static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds); |
| 141 | static int dgap_event(struct board_t *bd); |
| 142 | |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 143 | static void dgap_poll_tasklet(unsigned long data); |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 144 | static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1, |
| 145 | u8 byte2, uint ncmds); |
| 146 | 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] | 147 | static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt); |
Daeseok Youn | ab6cdcb | 2014-07-11 19:22:39 +0900 | [diff] [blame] | 148 | static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type); |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 149 | static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, |
| 150 | unsigned char *fbuf, int *len); |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 151 | static uint dgap_get_custom_baud(struct channel_t *ch); |
| 152 | static void dgap_firmware_reset_port(struct channel_t *ch); |
| 153 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 154 | /* |
| 155 | * Function prototypes from dgap_parse.c. |
| 156 | */ |
Daeseok Youn | 7bab00f | 2014-07-15 18:49:52 +0900 | [diff] [blame] | 157 | static int dgap_gettok(char **in); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 158 | static char *dgap_getword(char **in); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 159 | static int dgap_checknode(struct cnode *p); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 160 | |
Mark Hounschell | 30580a7 | 2014-02-19 13:12:05 -0500 | [diff] [blame] | 161 | /* |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 162 | * Function prototypes from dgap_sysfs.h |
| 163 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 164 | static void dgap_create_ports_sysfiles(struct board_t *bd); |
| 165 | static void dgap_remove_ports_sysfiles(struct board_t *bd); |
Mark Hounschell | 30580a7 | 2014-02-19 13:12:05 -0500 | [diff] [blame] | 166 | |
Mark Hounschell | 434b679 | 2014-03-06 13:57:55 -0500 | [diff] [blame] | 167 | static int dgap_create_driver_sysfiles(struct pci_driver *); |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 168 | static void dgap_remove_driver_sysfiles(struct pci_driver *); |
Mark Hounschell | 30580a7 | 2014-02-19 13:12:05 -0500 | [diff] [blame] | 169 | |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 170 | static void dgap_create_tty_sysfs(struct un_t *un, struct device *c); |
| 171 | static void dgap_remove_tty_sysfs(struct device *c); |
Mark Hounschell | 30580a7 | 2014-02-19 13:12:05 -0500 | [diff] [blame] | 172 | |
Mark Hounschell | 9e9b3bb | 2014-02-19 13:12:09 -0500 | [diff] [blame] | 173 | /* |
| 174 | * Function prototypes from dgap_parse.h |
| 175 | */ |
Daeseok Youn | c787366 | 2014-06-13 18:18:04 +0900 | [diff] [blame] | 176 | static int dgap_parsefile(char **in); |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 177 | static struct cnode *dgap_find_config(int type, int bus, int slot); |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 178 | static uint dgap_config_get_num_prts(struct board_t *bd); |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 179 | static char *dgap_create_config_string(struct board_t *bd, char *string); |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 180 | static uint dgap_config_get_useintr(struct board_t *bd); |
| 181 | static uint dgap_config_get_altpin(struct board_t *bd); |
| 182 | |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 183 | static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len); |
| 184 | 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] | 185 | #ifdef DIGI_CONCENTRATORS_SUPPORTED |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 186 | 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] | 187 | #endif |
Daeseok Youn | 3f7fa94 | 2014-06-13 18:22:05 +0900 | [diff] [blame] | 188 | static int dgap_alloc_flipbuf(struct board_t *brd); |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 189 | static void dgap_free_flipbuf(struct board_t *brd); |
Daeseok Youn | f19eda7 | 2014-06-03 15:28:08 +0900 | [diff] [blame] | 190 | static int dgap_request_irq(struct board_t *brd); |
Daeseok Youn | 78a7966 | 2014-06-13 18:21:04 +0900 | [diff] [blame] | 191 | static void dgap_free_irq(struct board_t *brd); |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 192 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 193 | static void dgap_get_vpd(struct board_t *brd); |
| 194 | static void dgap_do_reset_board(struct board_t *brd); |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 195 | static int dgap_test_bios(struct board_t *brd); |
| 196 | static int dgap_test_fep(struct board_t *brd); |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 197 | static int dgap_tty_register_ports(struct board_t *brd); |
Daeseok Youn | 3c3befe | 2014-06-13 18:22:40 +0900 | [diff] [blame] | 198 | static int dgap_firmware_load(struct pci_dev *pdev, int card_type, |
Daeseok Youn | 1b804e2 | 2014-07-02 16:06:04 +0900 | [diff] [blame] | 199 | struct board_t *brd); |
Daeseok Youn | 99a643b | 2014-07-31 13:02:30 +0900 | [diff] [blame] | 200 | static void dgap_cleanup_nodes(void); |
Mark Hounschell | 9e9b3bb | 2014-02-19 13:12:09 -0500 | [diff] [blame] | 201 | |
Mark Hounschell | 01a8d25 | 2014-03-03 09:37:22 -0500 | [diff] [blame] | 202 | static void dgap_cleanup_module(void); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 203 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 204 | module_exit(dgap_cleanup_module); |
| 205 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 206 | /* |
| 207 | * File operations permitted on Control/Management major. |
| 208 | */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 209 | static const struct file_operations dgap_board_fops = { |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 210 | .owner = THIS_MODULE, |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 211 | }; |
| 212 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 213 | static uint dgap_numboards; |
| 214 | static struct board_t *dgap_board[MAXBOARDS]; |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 215 | static ulong dgap_poll_counter; |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 216 | static int dgap_driver_state = DRIVER_INITIALIZED; |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 217 | static int dgap_poll_tick = 20; /* Poll interval - 20 ms */ |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 218 | |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 219 | static struct class *dgap_class; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 220 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 221 | static struct board_t *dgap_boards_by_major[256]; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 222 | static uint dgap_count = 500; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 223 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 224 | /* |
| 225 | * Poller stuff |
| 226 | */ |
Mark Hounschell | 45c44dd | 2014-04-24 10:33:58 -0400 | [diff] [blame] | 227 | static DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */ |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 228 | static ulong dgap_poll_time; /* Time of next poll */ |
| 229 | 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] | 230 | static struct timer_list dgap_poll_timer; |
| 231 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 232 | /* |
| 233 | SUPPORTED PRODUCTS |
| 234 | |
| 235 | Card Model Number of Ports Interface |
| 236 | ---------------------------------------------------------------- |
| 237 | Acceleport Xem 4 - 64 (EIA232 & EIA422) |
| 238 | Acceleport Xr 4 & 8 (EIA232) |
| 239 | Acceleport Xr 920 4 & 8 (EIA232) |
| 240 | Acceleport C/X 8 - 128 (EIA232) |
| 241 | Acceleport EPC/X 8 - 224 (EIA232) |
| 242 | Acceleport Xr/422 4 & 8 (EIA422) |
| 243 | Acceleport 2r/920 2 (EIA232) |
| 244 | Acceleport 4r/920 4 (EIA232) |
| 245 | Acceleport 8r/920 8 (EIA232) |
| 246 | |
| 247 | IBM 8-Port Asynchronous PCI Adapter (EIA232) |
| 248 | IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422) |
| 249 | */ |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 250 | |
| 251 | static struct pci_device_id dgap_pci_tbl[] = { |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 252 | { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
| 253 | { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 }, |
| 254 | { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 }, |
| 255 | { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 }, |
| 256 | { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 }, |
| 257 | { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 }, |
| 258 | { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 }, |
| 259 | { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 }, |
| 260 | { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 }, |
| 261 | { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 }, |
| 262 | { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 }, |
| 263 | { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 }, |
| 264 | { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 }, |
| 265 | { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 }, |
| 266 | { 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] | 267 | {0,} /* 0 terminated list. */ |
| 268 | }; |
| 269 | MODULE_DEVICE_TABLE(pci, dgap_pci_tbl); |
| 270 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 271 | /* |
| 272 | * A generic list of Product names, PCI Vendor ID, and PCI Device ID. |
| 273 | */ |
| 274 | struct board_id { |
| 275 | uint config_type; |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 276 | u8 *name; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 277 | uint maxports; |
| 278 | uint dpatype; |
| 279 | }; |
| 280 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 281 | static struct board_id dgap_ids[] = { |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 282 | { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) }, |
| 283 | { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) }, |
| 284 | { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) }, |
| 285 | { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) }, |
| 286 | { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 287 | { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 288 | { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 289 | { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 290 | { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 291 | { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 292 | { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 293 | { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 294 | { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 295 | { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, |
| 296 | { 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] | 297 | {0,} /* 0 terminated list. */ |
| 298 | }; |
| 299 | |
| 300 | static struct pci_driver dgap_driver = { |
| 301 | .name = "dgap", |
| 302 | .probe = dgap_init_one, |
| 303 | .id_table = dgap_pci_tbl, |
| 304 | .remove = dgap_remove_one, |
| 305 | }; |
| 306 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 307 | struct firmware_info { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 308 | u8 *conf_name; /* dgap.conf */ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 309 | u8 *bios_name; /* BIOS filename */ |
| 310 | u8 *fep_name; /* FEP filename */ |
| 311 | u8 *con_name; /* Concentrator filename FIXME*/ |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 312 | int num; /* sequence number */ |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 313 | }; |
| 314 | |
| 315 | /* |
| 316 | * Firmware - BIOS, FEP, and CONC filenames |
| 317 | */ |
| 318 | static struct firmware_info fw_info[] = { |
Mark Hounschell | 8f5879c | 2014-04-24 10:41:44 -0400 | [diff] [blame] | 319 | { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 0 }, |
| 320 | { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 1 }, |
| 321 | { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 2 }, |
| 322 | { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", NULL, 3 }, |
| 323 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 4 }, |
| 324 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 5 }, |
| 325 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 6 }, |
| 326 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 7 }, |
| 327 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 8 }, |
| 328 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 9 }, |
| 329 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 10 }, |
| 330 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 11 }, |
| 331 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 12 }, |
| 332 | { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 13 }, |
| 333 | { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 14 }, |
| 334 | {NULL,} |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 335 | }; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 336 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 337 | /* |
| 338 | * Default transparent print information. |
| 339 | */ |
| 340 | static struct digi_t dgap_digi_init = { |
| 341 | .digi_flags = DIGI_COOK, /* Flags */ |
| 342 | .digi_maxcps = 100, /* Max CPS */ |
| 343 | .digi_maxchar = 50, /* Max chars in print queue */ |
| 344 | .digi_bufsize = 100, /* Printer buffer size */ |
| 345 | .digi_onlen = 4, /* size of printer on string */ |
| 346 | .digi_offlen = 4, /* size of printer off string */ |
| 347 | .digi_onstr = "\033[5i", /* ANSI printer on string ] */ |
| 348 | .digi_offstr = "\033[4i", /* ANSI printer off string ] */ |
| 349 | .digi_term = "ansi" /* default terminal type */ |
| 350 | }; |
| 351 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 352 | /* |
| 353 | * Define a local default termios struct. All ports will be created |
| 354 | * with this termios initially. |
| 355 | * |
| 356 | * This defines a raw port at 9600 baud, 8 data bits, no parity, |
| 357 | * 1 stop bit. |
| 358 | */ |
| 359 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 360 | static struct ktermios dgap_default_termios = { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 361 | .c_iflag = (DEFAULT_IFLAGS), /* iflags */ |
| 362 | .c_oflag = (DEFAULT_OFLAGS), /* oflags */ |
| 363 | .c_cflag = (DEFAULT_CFLAGS), /* cflags */ |
| 364 | .c_lflag = (DEFAULT_LFLAGS), /* lflags */ |
| 365 | .c_cc = INIT_C_CC, |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 366 | .c_line = 0, |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 367 | }; |
| 368 | |
| 369 | static const struct tty_operations dgap_tty_ops = { |
| 370 | .open = dgap_tty_open, |
| 371 | .close = dgap_tty_close, |
| 372 | .write = dgap_tty_write, |
| 373 | .write_room = dgap_tty_write_room, |
| 374 | .flush_buffer = dgap_tty_flush_buffer, |
| 375 | .chars_in_buffer = dgap_tty_chars_in_buffer, |
| 376 | .flush_chars = dgap_tty_flush_chars, |
| 377 | .ioctl = dgap_tty_ioctl, |
| 378 | .set_termios = dgap_tty_set_termios, |
| 379 | .stop = dgap_tty_stop, |
| 380 | .start = dgap_tty_start, |
| 381 | .throttle = dgap_tty_throttle, |
| 382 | .unthrottle = dgap_tty_unthrottle, |
| 383 | .hangup = dgap_tty_hangup, |
| 384 | .put_char = dgap_tty_put_char, |
| 385 | .tiocmget = dgap_tty_tiocmget, |
| 386 | .tiocmset = dgap_tty_tiocmset, |
| 387 | .break_ctl = dgap_tty_send_break, |
| 388 | .wait_until_sent = dgap_tty_wait_until_sent, |
| 389 | .send_xchar = dgap_tty_send_xchar |
| 390 | }; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 391 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 392 | /* |
| 393 | * Our needed internal static variables from dgap_parse.c |
| 394 | */ |
| 395 | static struct cnode dgap_head; |
| 396 | #define MAXCWORD 200 |
| 397 | static char dgap_cword[MAXCWORD]; |
| 398 | |
| 399 | struct toklist { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 400 | int token; |
| 401 | char *string; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 402 | }; |
| 403 | |
Daeseok Youn | 77a4492 | 2014-08-09 14:38:14 +0900 | [diff] [blame] | 404 | static struct toklist dgap_brdtype[] = { |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 405 | { PCX, "Digi_AccelePort_C/X_PCI" }, |
| 406 | { PEPC, "Digi_AccelePort_EPC/X_PCI" }, |
| 407 | { PPCM, "Digi_AccelePort_Xem_PCI" }, |
| 408 | { APORT2_920P, "Digi_AccelePort_2r_920_PCI" }, |
| 409 | { APORT4_920P, "Digi_AccelePort_4r_920_PCI" }, |
| 410 | { APORT8_920P, "Digi_AccelePort_8r_920_PCI" }, |
| 411 | { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" }, |
| 412 | { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" }, |
Daeseok Youn | 77a4492 | 2014-08-09 14:38:14 +0900 | [diff] [blame] | 413 | { 0, NULL } |
| 414 | }; |
| 415 | |
| 416 | static struct toklist dgap_tlist[] = { |
| 417 | { BEGIN, "config_begin" }, |
| 418 | { END, "config_end" }, |
| 419 | { BOARD, "board" }, |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 420 | { IO, "io" }, |
| 421 | { PCIINFO, "pciinfo" }, |
| 422 | { LINE, "line" }, |
| 423 | { CONC, "conc" }, |
| 424 | { CONC, "concentrator" }, |
| 425 | { CX, "cx" }, |
| 426 | { CX, "ccon" }, |
| 427 | { EPC, "epccon" }, |
| 428 | { EPC, "epc" }, |
| 429 | { MOD, "module" }, |
| 430 | { ID, "id" }, |
| 431 | { STARTO, "start" }, |
| 432 | { SPEED, "speed" }, |
| 433 | { CABLE, "cable" }, |
| 434 | { CONNECT, "connect" }, |
| 435 | { METHOD, "method" }, |
| 436 | { STATUS, "status" }, |
| 437 | { CUSTOM, "Custom" }, |
| 438 | { BASIC, "Basic" }, |
| 439 | { MEM, "mem" }, |
| 440 | { MEM, "memory" }, |
| 441 | { PORTS, "ports" }, |
| 442 | { MODEM, "modem" }, |
| 443 | { NPORTS, "nports" }, |
| 444 | { TTYN, "ttyname" }, |
| 445 | { CU, "cuname" }, |
| 446 | { PRINT, "prname" }, |
| 447 | { CMAJOR, "major" }, |
| 448 | { ALTPIN, "altpin" }, |
| 449 | { USEINTR, "useintr" }, |
| 450 | { TTSIZ, "ttysize" }, |
| 451 | { CHSIZ, "chsize" }, |
| 452 | { BSSIZ, "boardsize" }, |
| 453 | { UNTSIZ, "schedsize" }, |
| 454 | { F2SIZ, "f2200size" }, |
| 455 | { VPSIZ, "vpixsize" }, |
| 456 | { 0, NULL } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 457 | }; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 458 | |
| 459 | /************************************************************************ |
| 460 | * |
| 461 | * Driver load/unload functions |
| 462 | * |
| 463 | ************************************************************************/ |
| 464 | |
| 465 | /* |
| 466 | * init_module() |
| 467 | * |
| 468 | * Module load. This is where it all starts. |
| 469 | */ |
Mark Hounschell | 01a8d25 | 2014-03-03 09:37:22 -0500 | [diff] [blame] | 470 | static int dgap_init_module(void) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 471 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 472 | int rc; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 473 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 474 | 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] | 475 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 476 | rc = dgap_start(); |
Mark Hounschell | 002de0b | 2014-03-06 15:25:19 -0500 | [diff] [blame] | 477 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 478 | return rc; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 479 | |
Daeseok Youn | 77343eb | 2014-07-04 19:29:11 +0900 | [diff] [blame] | 480 | rc = pci_register_driver(&dgap_driver); |
Mark Hounschell | 002de0b | 2014-03-06 15:25:19 -0500 | [diff] [blame] | 481 | if (rc) |
| 482 | goto err_cleanup; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 483 | |
Mark Hounschell | 002de0b | 2014-03-06 15:25:19 -0500 | [diff] [blame] | 484 | rc = dgap_create_driver_sysfiles(&dgap_driver); |
| 485 | if (rc) |
| 486 | goto err_cleanup; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 487 | |
Mark Hounschell | 002de0b | 2014-03-06 15:25:19 -0500 | [diff] [blame] | 488 | dgap_driver_state = DRIVER_READY; |
| 489 | |
| 490 | return 0; |
| 491 | |
| 492 | err_cleanup: |
| 493 | |
| 494 | dgap_cleanup_module(); |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 495 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 496 | return rc; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 497 | } |
Mark Hounschell | 01a8d25 | 2014-03-03 09:37:22 -0500 | [diff] [blame] | 498 | module_init(dgap_init_module); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 499 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 500 | /* |
| 501 | * Start of driver. |
| 502 | */ |
| 503 | static int dgap_start(void) |
| 504 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 505 | int rc; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 506 | unsigned long flags; |
Alexey Khoroshilov | 0669e5f | 2014-03-09 01:01:34 +0400 | [diff] [blame] | 507 | struct device *device; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 508 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 509 | /* |
| 510 | * make sure that the globals are |
| 511 | * init'd before we do anything else |
| 512 | */ |
| 513 | dgap_init_globals(); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 514 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 515 | dgap_numboards = 0; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 516 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 517 | 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] | 518 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 519 | /* |
| 520 | * Register our base character device into the kernel. |
| 521 | */ |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 522 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 523 | /* |
| 524 | * Register management/dpa devices |
| 525 | */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 526 | rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &dgap_board_fops); |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 527 | if (rc < 0) |
| 528 | return rc; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 529 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 530 | dgap_class = class_create(THIS_MODULE, "dgap_mgmt"); |
Alexey Khoroshilov | 0669e5f | 2014-03-09 01:01:34 +0400 | [diff] [blame] | 531 | if (IS_ERR(dgap_class)) { |
| 532 | rc = PTR_ERR(dgap_class); |
| 533 | goto failed_class; |
| 534 | } |
| 535 | |
| 536 | device = device_create(dgap_class, NULL, |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 537 | MKDEV(DIGI_DGAP_MAJOR, 0), |
| 538 | NULL, "dgap_mgmt"); |
Alexey Khoroshilov | 0669e5f | 2014-03-09 01:01:34 +0400 | [diff] [blame] | 539 | if (IS_ERR(device)) { |
| 540 | rc = PTR_ERR(device); |
| 541 | goto failed_device; |
| 542 | } |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 543 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 544 | /* Start the poller */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 545 | spin_lock_irqsave(&dgap_poll_lock, flags); |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 546 | init_timer(&dgap_poll_timer); |
| 547 | dgap_poll_timer.function = dgap_poll_handler; |
| 548 | dgap_poll_timer.data = 0; |
| 549 | dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick); |
| 550 | dgap_poll_timer.expires = dgap_poll_time; |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 551 | spin_unlock_irqrestore(&dgap_poll_lock, flags); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 552 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 553 | add_timer(&dgap_poll_timer); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 554 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 555 | return rc; |
Alexey Khoroshilov | 0669e5f | 2014-03-09 01:01:34 +0400 | [diff] [blame] | 556 | |
| 557 | failed_device: |
| 558 | class_destroy(dgap_class); |
| 559 | failed_class: |
| 560 | unregister_chrdev(DIGI_DGAP_MAJOR, "dgap"); |
| 561 | return rc; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 562 | } |
| 563 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 564 | static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 565 | { |
| 566 | int rc; |
Daeseok Youn | 1b804e2 | 2014-07-02 16:06:04 +0900 | [diff] [blame] | 567 | struct board_t *brd; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 568 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 569 | if (dgap_numboards >= MAXBOARDS) |
Mark Hounschell | acfd4aa | 2014-04-25 13:10:20 -0400 | [diff] [blame] | 570 | return -EPERM; |
| 571 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 572 | rc = pci_enable_device(pdev); |
Mark Hounschell | 6a82524 | 2014-04-25 14:19:42 -0400 | [diff] [blame] | 573 | if (rc) |
| 574 | return -EIO; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 575 | |
Daeseok Youn | 7bc26a6 | 2014-06-20 18:21:50 +0900 | [diff] [blame] | 576 | brd = dgap_found_board(pdev, ent->driver_data, dgap_numboards); |
| 577 | if (IS_ERR(brd)) |
| 578 | return PTR_ERR(brd); |
Mark Hounschell | 6a82524 | 2014-04-25 14:19:42 -0400 | [diff] [blame] | 579 | |
Daeseok Youn | 3c3befe | 2014-06-13 18:22:40 +0900 | [diff] [blame] | 580 | rc = dgap_firmware_load(pdev, ent->driver_data, brd); |
| 581 | if (rc) |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 582 | goto cleanup_brd; |
Daeseok Youn | 3c3befe | 2014-06-13 18:22:40 +0900 | [diff] [blame] | 583 | |
| 584 | rc = dgap_alloc_flipbuf(brd); |
| 585 | if (rc) |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 586 | goto cleanup_brd; |
Daeseok Youn | 3c3befe | 2014-06-13 18:22:40 +0900 | [diff] [blame] | 587 | |
| 588 | rc = dgap_tty_register(brd); |
| 589 | if (rc) |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 590 | goto free_flipbuf; |
Daeseok Youn | 3c3befe | 2014-06-13 18:22:40 +0900 | [diff] [blame] | 591 | |
| 592 | rc = dgap_request_irq(brd); |
| 593 | if (rc) |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 594 | goto unregister_tty; |
Daeseok Youn | 3c3befe | 2014-06-13 18:22:40 +0900 | [diff] [blame] | 595 | |
| 596 | /* |
| 597 | * Do tty device initialization. |
| 598 | */ |
| 599 | rc = dgap_tty_init(brd); |
| 600 | if (rc < 0) |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 601 | goto free_irq; |
Daeseok Youn | 3c3befe | 2014-06-13 18:22:40 +0900 | [diff] [blame] | 602 | |
| 603 | rc = dgap_tty_register_ports(brd); |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 604 | if (rc) |
| 605 | goto tty_free; |
Daeseok Youn | 3c3befe | 2014-06-13 18:22:40 +0900 | [diff] [blame] | 606 | |
| 607 | brd->state = BOARD_READY; |
| 608 | brd->dpastatus = BD_RUNNING; |
| 609 | |
Daeseok Youn | 7bc26a6 | 2014-06-20 18:21:50 +0900 | [diff] [blame] | 610 | dgap_board[dgap_numboards++] = brd; |
| 611 | |
Daeseok Youn | 3c3befe | 2014-06-13 18:22:40 +0900 | [diff] [blame] | 612 | return 0; |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 613 | |
| 614 | tty_free: |
| 615 | dgap_tty_free(brd); |
| 616 | free_irq: |
| 617 | dgap_free_irq(brd); |
| 618 | unregister_tty: |
| 619 | dgap_tty_unregister(brd); |
| 620 | free_flipbuf: |
| 621 | dgap_free_flipbuf(brd); |
| 622 | cleanup_brd: |
Daeseok Youn | 99a643b | 2014-07-31 13:02:30 +0900 | [diff] [blame] | 623 | dgap_cleanup_nodes(); |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 624 | dgap_release_remap(brd); |
| 625 | kfree(brd); |
Daeseok Youn | 7bc26a6 | 2014-06-20 18:21:50 +0900 | [diff] [blame] | 626 | |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 627 | return rc; |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 628 | } |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 629 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 630 | static void dgap_remove_one(struct pci_dev *dev) |
| 631 | { |
| 632 | /* Do Nothing */ |
| 633 | } |
| 634 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 635 | /* |
| 636 | * dgap_cleanup_module() |
| 637 | * |
| 638 | * Module unload. This is where it all ends. |
| 639 | */ |
Mark Hounschell | 01a8d25 | 2014-03-03 09:37:22 -0500 | [diff] [blame] | 640 | static void dgap_cleanup_module(void) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 641 | { |
| 642 | int i; |
| 643 | ulong lock_flags; |
| 644 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 645 | spin_lock_irqsave(&dgap_poll_lock, lock_flags); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 646 | dgap_poll_stop = 1; |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 647 | spin_unlock_irqrestore(&dgap_poll_lock, lock_flags); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 648 | |
| 649 | /* Turn off poller right away. */ |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 650 | del_timer_sync(&dgap_poll_timer); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 651 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 652 | dgap_remove_driver_sysfiles(&dgap_driver); |
| 653 | |
Alexey Khoroshilov | af07daa | 2014-03-09 01:01:33 +0400 | [diff] [blame] | 654 | device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0)); |
| 655 | class_destroy(dgap_class); |
| 656 | unregister_chrdev(DIGI_DGAP_MAJOR, "dgap"); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 657 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 658 | for (i = 0; i < dgap_numboards; ++i) { |
| 659 | dgap_remove_ports_sysfiles(dgap_board[i]); |
Daeseok Youn | 7bf0a4c | 2014-06-03 15:28:42 +0900 | [diff] [blame] | 660 | dgap_cleanup_tty(dgap_board[i]); |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 661 | dgap_cleanup_board(dgap_board[i]); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 662 | } |
| 663 | |
Daeseok Youn | 99a643b | 2014-07-31 13:02:30 +0900 | [diff] [blame] | 664 | dgap_cleanup_nodes(); |
| 665 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 666 | if (dgap_numboards) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 667 | pci_unregister_driver(&dgap_driver); |
| 668 | } |
| 669 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 670 | /* |
| 671 | * dgap_cleanup_board() |
| 672 | * |
| 673 | * Free all the memory associated with a board |
| 674 | */ |
| 675 | static void dgap_cleanup_board(struct board_t *brd) |
| 676 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 677 | int i; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 678 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 679 | if (!brd || brd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 680 | return; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 681 | |
Daeseok Youn | 78a7966 | 2014-06-13 18:21:04 +0900 | [diff] [blame] | 682 | dgap_free_irq(brd); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 683 | |
| 684 | tasklet_kill(&brd->helper_tasklet); |
| 685 | |
Daeseok Youn | c749201 | 2014-09-23 09:22:36 +0900 | [diff] [blame^] | 686 | dgap_release_remap(brd); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 687 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 688 | /* Free all allocated channels structs */ |
Mark Hounschell | 9b073ac | 2014-03-03 13:45:42 -0500 | [diff] [blame] | 689 | for (i = 0; i < MAXPORTS ; i++) |
| 690 | kfree(brd->channels[i]); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 691 | |
Lidza Louina | 57a4219 | 2013-09-23 18:47:12 -0400 | [diff] [blame] | 692 | kfree(brd->flipbuf); |
| 693 | kfree(brd->flipflagbuf); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 694 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 695 | dgap_board[brd->boardnum] = NULL; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 696 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 697 | kfree(brd); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 698 | } |
| 699 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 700 | /* |
| 701 | * dgap_found_board() |
| 702 | * |
| 703 | * A board has been found, init it. |
| 704 | */ |
Daeseok Youn | 7bc26a6 | 2014-06-20 18:21:50 +0900 | [diff] [blame] | 705 | static struct board_t *dgap_found_board(struct pci_dev *pdev, int id, |
| 706 | int boardnum) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 707 | { |
| 708 | struct board_t *brd; |
| 709 | unsigned int pci_irq; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 710 | int i; |
Daeseok Youn | f86c55c9 | 2014-05-29 18:11:09 +0900 | [diff] [blame] | 711 | int ret; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 712 | |
| 713 | /* get the board structure and prep it */ |
Mark Hounschell | 9b073ac | 2014-03-03 13:45:42 -0500 | [diff] [blame] | 714 | brd = kzalloc(sizeof(struct board_t), GFP_KERNEL); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 715 | if (!brd) |
Daeseok Youn | 7bc26a6 | 2014-06-20 18:21:50 +0900 | [diff] [blame] | 716 | return ERR_PTR(-ENOMEM); |
Mark Hounschell | 9b073ac | 2014-03-03 13:45:42 -0500 | [diff] [blame] | 717 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 718 | /* store the info for the board we've found */ |
| 719 | brd->magic = DGAP_BOARD_MAGIC; |
Daeseok Youn | efd9618 | 2014-06-03 15:26:53 +0900 | [diff] [blame] | 720 | brd->boardnum = boardnum; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 721 | brd->vendor = dgap_pci_tbl[id].vendor; |
| 722 | brd->device = dgap_pci_tbl[id].device; |
| 723 | brd->pdev = pdev; |
| 724 | brd->pci_bus = pdev->bus->number; |
| 725 | brd->pci_slot = PCI_SLOT(pdev->devfn); |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 726 | brd->name = dgap_ids[id].name; |
| 727 | brd->maxports = dgap_ids[id].maxports; |
| 728 | brd->type = dgap_ids[id].config_type; |
| 729 | brd->dpatype = dgap_ids[id].dpatype; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 730 | brd->dpastatus = BD_NOFEP; |
| 731 | init_waitqueue_head(&brd->state_wait); |
| 732 | |
Mark Hounschell | 211568d | 2014-03-11 10:11:43 -0400 | [diff] [blame] | 733 | spin_lock_init(&brd->bd_lock); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 734 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 735 | brd->inhibit_poller = FALSE; |
| 736 | brd->wait_for_bios = 0; |
| 737 | brd->wait_for_fep = 0; |
| 738 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 739 | for (i = 0; i < MAXPORTS; i++) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 740 | brd->channels[i] = NULL; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 741 | |
| 742 | /* store which card & revision we have */ |
| 743 | pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor); |
| 744 | pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice); |
| 745 | pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev); |
| 746 | |
| 747 | pci_irq = pdev->irq; |
| 748 | brd->irq = pci_irq; |
| 749 | |
| 750 | /* get the PCI Base Address Registers */ |
| 751 | |
| 752 | /* Xr Jupiter and EPC use BAR 2 */ |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 753 | 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] | 754 | brd->membase = pci_resource_start(pdev, 2); |
| 755 | brd->membase_end = pci_resource_end(pdev, 2); |
| 756 | } |
| 757 | /* Everyone else uses BAR 0 */ |
| 758 | else { |
| 759 | brd->membase = pci_resource_start(pdev, 0); |
| 760 | brd->membase_end = pci_resource_end(pdev, 0); |
| 761 | } |
| 762 | |
Daeseok Youn | f86c55c9 | 2014-05-29 18:11:09 +0900 | [diff] [blame] | 763 | if (!brd->membase) { |
| 764 | ret = -ENODEV; |
| 765 | goto free_brd; |
| 766 | } |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 767 | |
| 768 | if (brd->membase & 1) |
| 769 | brd->membase &= ~3; |
| 770 | else |
| 771 | brd->membase &= ~15; |
| 772 | |
| 773 | /* |
| 774 | * On the PCI boards, there is no IO space allocated |
| 775 | * The I/O registers will be in the first 3 bytes of the |
| 776 | * upper 2MB of the 4MB memory space. The board memory |
| 777 | * will be mapped into the low 2MB of the 4MB memory space |
| 778 | */ |
| 779 | brd->port = brd->membase + PCI_IO_OFFSET; |
| 780 | brd->port_end = brd->port + PCI_IO_SIZE; |
| 781 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 782 | /* |
| 783 | * Special initialization for non-PLX boards |
| 784 | */ |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 785 | 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] | 786 | unsigned short cmd; |
| 787 | |
| 788 | pci_write_config_byte(pdev, 0x40, 0); |
| 789 | pci_write_config_byte(pdev, 0x46, 0); |
| 790 | |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 791 | /* Limit burst length to 2 doubleword transactions */ |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 792 | pci_write_config_byte(pdev, 0x42, 1); |
| 793 | |
| 794 | /* |
| 795 | * Enable IO and mem if not already done. |
| 796 | * This was needed for support on Itanium. |
| 797 | */ |
| 798 | pci_read_config_word(pdev, PCI_COMMAND, &cmd); |
| 799 | cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY); |
| 800 | pci_write_config_word(pdev, PCI_COMMAND, cmd); |
| 801 | } |
| 802 | |
| 803 | /* init our poll helper tasklet */ |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 804 | tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet, |
| 805 | (unsigned long) brd); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 806 | |
Daeseok Youn | f86c55c9 | 2014-05-29 18:11:09 +0900 | [diff] [blame] | 807 | ret = dgap_do_remap(brd); |
| 808 | if (ret) |
| 809 | goto free_brd; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 810 | |
Mark Hounschell | 20fe4ae | 2014-03-25 16:38:17 -0400 | [diff] [blame] | 811 | pr_info("dgap: board %d: %s (rev %d), irq %ld\n", |
Daeseok Youn | efd9618 | 2014-06-03 15:26:53 +0900 | [diff] [blame] | 812 | boardnum, brd->name, brd->rev, brd->irq); |
Mark Hounschell | c0c31b9 | 2014-03-12 12:50:56 -0400 | [diff] [blame] | 813 | |
Daeseok Youn | 7bc26a6 | 2014-06-20 18:21:50 +0900 | [diff] [blame] | 814 | return brd; |
Daeseok Youn | f86c55c9 | 2014-05-29 18:11:09 +0900 | [diff] [blame] | 815 | |
| 816 | free_brd: |
| 817 | kfree(brd); |
Daeseok Youn | f86c55c9 | 2014-05-29 18:11:09 +0900 | [diff] [blame] | 818 | |
Daeseok Youn | 7bc26a6 | 2014-06-20 18:21:50 +0900 | [diff] [blame] | 819 | return ERR_PTR(ret); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | |
Daeseok Youn | f19eda7 | 2014-06-03 15:28:08 +0900 | [diff] [blame] | 823 | static int dgap_request_irq(struct board_t *brd) |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 824 | { |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 825 | int rc; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 826 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 827 | if (!brd || brd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 828 | return -ENODEV; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 829 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 830 | /* |
| 831 | * Set up our interrupt handler if we are set to do interrupts. |
| 832 | */ |
Daeseok Youn | c643794 | 2014-08-18 23:32:36 +0900 | [diff] [blame] | 833 | if (dgap_config_get_useintr(brd) && brd->irq) { |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 834 | |
| 835 | rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd); |
| 836 | |
Daeseok Youn | 9f20ecc | 2014-08-18 23:31:46 +0900 | [diff] [blame] | 837 | if (!rc) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 838 | brd->intr_used = 1; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 839 | } |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 840 | return 0; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 841 | } |
| 842 | |
Daeseok Youn | 78a7966 | 2014-06-13 18:21:04 +0900 | [diff] [blame] | 843 | static void dgap_free_irq(struct board_t *brd) |
| 844 | { |
| 845 | if (brd->intr_used && brd->irq) |
| 846 | free_irq(brd->irq, brd); |
| 847 | } |
| 848 | |
Daeseok Youn | 3c3befe | 2014-06-13 18:22:40 +0900 | [diff] [blame] | 849 | static int dgap_firmware_load(struct pci_dev *pdev, int card_type, |
Daeseok Youn | 1b804e2 | 2014-07-02 16:06:04 +0900 | [diff] [blame] | 850 | struct board_t *brd) |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 851 | { |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 852 | const struct firmware *fw; |
Mark Hounschell | 23aa2ad | 2014-04-23 10:33:45 -0400 | [diff] [blame] | 853 | char *tmp_ptr; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 854 | int ret; |
Daeseok Youn | 67987ae | 2014-06-02 14:09:04 +0900 | [diff] [blame] | 855 | char *dgap_config_buf; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 856 | |
| 857 | dgap_get_vpd(brd); |
| 858 | dgap_do_reset_board(brd); |
| 859 | |
Daeseok Youn | 67987ae | 2014-06-02 14:09:04 +0900 | [diff] [blame] | 860 | if (fw_info[card_type].conf_name) { |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 861 | ret = request_firmware(&fw, fw_info[card_type].conf_name, |
| 862 | &pdev->dev); |
| 863 | if (ret) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 864 | dev_err(&pdev->dev, "config file %s not found\n", |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 865 | fw_info[card_type].conf_name); |
| 866 | return ret; |
| 867 | } |
Mark Hounschell | 9e84401 | 2014-03-25 16:38:14 -0400 | [diff] [blame] | 868 | |
Mark Hounschell | 077c28f | 2014-04-23 10:33:44 -0400 | [diff] [blame] | 869 | dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 870 | if (!dgap_config_buf) { |
Mark Hounschell | 9e84401 | 2014-03-25 16:38:14 -0400 | [diff] [blame] | 871 | release_firmware(fw); |
| 872 | return -ENOMEM; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | memcpy(dgap_config_buf, fw->data, fw->size); |
| 876 | release_firmware(fw); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 877 | |
Mark Hounschell | 23aa2ad | 2014-04-23 10:33:45 -0400 | [diff] [blame] | 878 | /* |
| 879 | * preserve dgap_config_buf |
| 880 | * as dgap_parsefile would |
| 881 | * otherwise alter it. |
| 882 | */ |
| 883 | tmp_ptr = dgap_config_buf; |
| 884 | |
Daeseok Youn | c787366 | 2014-06-13 18:18:04 +0900 | [diff] [blame] | 885 | if (dgap_parsefile(&tmp_ptr) != 0) { |
Mark Hounschell | 9e84401 | 2014-03-25 16:38:14 -0400 | [diff] [blame] | 886 | kfree(dgap_config_buf); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 887 | return -EINVAL; |
Mark Hounschell | 9e84401 | 2014-03-25 16:38:14 -0400 | [diff] [blame] | 888 | } |
| 889 | kfree(dgap_config_buf); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 890 | } |
| 891 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 892 | /* |
| 893 | * Match this board to a config the user created for us. |
| 894 | */ |
| 895 | brd->bd_config = |
| 896 | dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot); |
| 897 | |
| 898 | /* |
| 899 | * Because the 4 port Xr products share the same PCI ID |
| 900 | * as the 8 port Xr products, if we receive a NULL config |
| 901 | * back, and this is a PAPORT8 board, retry with a |
| 902 | * PAPORT4 attempt as well. |
| 903 | */ |
| 904 | if (brd->type == PAPORT8 && !brd->bd_config) |
| 905 | brd->bd_config = |
| 906 | dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot); |
| 907 | |
| 908 | if (!brd->bd_config) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 909 | dev_err(&pdev->dev, "No valid configuration found\n"); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 910 | return -EINVAL; |
| 911 | } |
| 912 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 913 | if (fw_info[card_type].bios_name) { |
| 914 | ret = request_firmware(&fw, fw_info[card_type].bios_name, |
| 915 | &pdev->dev); |
| 916 | if (ret) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 917 | dev_err(&pdev->dev, "bios file %s not found\n", |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 918 | fw_info[card_type].bios_name); |
| 919 | return ret; |
| 920 | } |
Masood Mehmood | fd54889 | 2014-03-18 13:40:14 -0700 | [diff] [blame] | 921 | dgap_do_bios_load(brd, fw->data, fw->size); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 922 | release_firmware(fw); |
| 923 | |
| 924 | /* Wait for BIOS to test board... */ |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 925 | ret = dgap_test_bios(brd); |
| 926 | if (ret) |
| 927 | return ret; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | if (fw_info[card_type].fep_name) { |
| 931 | ret = request_firmware(&fw, fw_info[card_type].fep_name, |
| 932 | &pdev->dev); |
| 933 | if (ret) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 934 | dev_err(&pdev->dev, "dgap: fep file %s not found\n", |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 935 | fw_info[card_type].fep_name); |
| 936 | return ret; |
| 937 | } |
Masood Mehmood | fd54889 | 2014-03-18 13:40:14 -0700 | [diff] [blame] | 938 | dgap_do_fep_load(brd, fw->data, fw->size); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 939 | release_firmware(fw); |
| 940 | |
| 941 | /* Wait for FEP to load on board... */ |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 942 | ret = dgap_test_fep(brd); |
| 943 | if (ret) |
| 944 | return ret; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | #ifdef DIGI_CONCENTRATORS_SUPPORTED |
| 948 | /* |
| 949 | * If this is a CX or EPCX, we need to see if the firmware |
| 950 | * is requesting a concentrator image from us. |
| 951 | */ |
| 952 | if ((bd->type == PCX) || (bd->type == PEPC)) { |
| 953 | chk_addr = (u16 *) (vaddr + DOWNREQ); |
| 954 | /* Nonzero if FEP is requesting concentrator image. */ |
| 955 | check = readw(chk_addr); |
| 956 | vaddr = brd->re_map_membase; |
| 957 | } |
| 958 | |
| 959 | if (fw_info[card_type].con_name && check && vaddr) { |
| 960 | ret = request_firmware(&fw, fw_info[card_type].con_name, |
| 961 | &pdev->dev); |
| 962 | if (ret) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 963 | dev_err(&pdev->dev, "conc file %s not found\n", |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 964 | fw_info[card_type].con_name); |
| 965 | return ret; |
| 966 | } |
| 967 | /* Put concentrator firmware loading code here */ |
| 968 | offset = readw((u16 *) (vaddr + DOWNREQ)); |
| 969 | memcpy_toio(offset, fw->data, fw->size); |
| 970 | |
| 971 | dgap_do_conc_load(brd, (char *)fw->data, fw->size) |
| 972 | release_firmware(fw); |
| 973 | } |
| 974 | #endif |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 975 | |
| 976 | return 0; |
| 977 | } |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 978 | |
| 979 | /* |
| 980 | * Remap PCI memory. |
| 981 | */ |
| 982 | static int dgap_do_remap(struct board_t *brd) |
| 983 | { |
| 984 | if (!brd || brd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 985 | return -EIO; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 986 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 987 | if (!request_mem_region(brd->membase, 0x200000, "dgap")) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 988 | return -ENOMEM; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 989 | |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 990 | if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, |
| 991 | "dgap")) { |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 992 | release_mem_region(brd->membase, 0x200000); |
| 993 | return -ENOMEM; |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 994 | } |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 995 | |
| 996 | brd->re_map_membase = ioremap(brd->membase, 0x200000); |
| 997 | if (!brd->re_map_membase) { |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 998 | release_mem_region(brd->membase, 0x200000); |
| 999 | release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000); |
| 1000 | return -ENOMEM; |
| 1001 | } |
| 1002 | |
| 1003 | brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000); |
| 1004 | if (!brd->re_map_port) { |
| 1005 | release_mem_region(brd->membase, 0x200000); |
| 1006 | release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000); |
| 1007 | iounmap(brd->re_map_membase); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1008 | return -ENOMEM; |
| 1009 | } |
| 1010 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1011 | return 0; |
| 1012 | } |
| 1013 | |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 1014 | static void dgap_release_remap(struct board_t *brd) |
| 1015 | { |
Daeseok Youn | c749201 | 2014-09-23 09:22:36 +0900 | [diff] [blame^] | 1016 | if (brd->re_map_membase) { |
| 1017 | release_mem_region(brd->membase, 0x200000); |
| 1018 | iounmap(brd->re_map_membase); |
| 1019 | } |
| 1020 | |
| 1021 | if (brd->re_map_port) { |
| 1022 | release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000); |
| 1023 | iounmap(brd->re_map_port); |
| 1024 | } |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 1025 | } |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1026 | /***************************************************************************** |
| 1027 | * |
| 1028 | * Function: |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 1029 | * |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1030 | * dgap_poll_handler |
| 1031 | * |
| 1032 | * Author: |
| 1033 | * |
| 1034 | * Scott H Kilau |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 1035 | * |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1036 | * Parameters: |
| 1037 | * |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 1038 | * dummy -- ignored |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1039 | * |
| 1040 | * Return Values: |
| 1041 | * |
| 1042 | * none |
| 1043 | * |
Masanari Iida | 818cc6f | 2014-01-15 00:40:44 +0900 | [diff] [blame] | 1044 | * Description: |
| 1045 | * |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1046 | * As each timer expires, it determines (a) whether the "transmit" |
| 1047 | * waiter needs to be woken up, and (b) whether the poller needs to |
| 1048 | * be rescheduled. |
| 1049 | * |
| 1050 | ******************************************************************************/ |
| 1051 | |
| 1052 | static void dgap_poll_handler(ulong dummy) |
| 1053 | { |
| 1054 | int i; |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 1055 | struct board_t *brd; |
| 1056 | unsigned long lock_flags; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1057 | ulong new_time; |
| 1058 | |
| 1059 | dgap_poll_counter++; |
| 1060 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1061 | /* |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1062 | * Do not start the board state machine until |
| 1063 | * driver tells us its up and running, and has |
| 1064 | * everything it needs. |
| 1065 | */ |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 1066 | if (dgap_driver_state != DRIVER_READY) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1067 | goto schedule_poller; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1068 | |
| 1069 | /* |
| 1070 | * If we have just 1 board, or the system is not SMP, |
| 1071 | * then use the typical old style poller. |
| 1072 | * Otherwise, use our new tasklet based poller, which should |
| 1073 | * speed things up for multiple boards. |
| 1074 | */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1075 | if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) { |
| 1076 | for (i = 0; i < dgap_numboards; i++) { |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1077 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1078 | brd = dgap_board[i]; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1079 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1080 | if (brd->state == BOARD_FAILED) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1081 | continue; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1082 | if (!brd->intr_running) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1083 | /* Call the real board poller directly */ |
| 1084 | dgap_poll_tasklet((unsigned long) brd); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1085 | } |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1086 | } else { |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1087 | /* |
| 1088 | * Go thru each board, kicking off a |
| 1089 | * tasklet for each if needed |
| 1090 | */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1091 | for (i = 0; i < dgap_numboards; i++) { |
| 1092 | brd = dgap_board[i]; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1093 | |
| 1094 | /* |
| 1095 | * Attempt to grab the board lock. |
| 1096 | * |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1097 | * If we can't get it, no big deal, the next poll |
| 1098 | * will get it. Basically, I just really don't want |
| 1099 | * to spin in here, because I want to kick off my |
| 1100 | * tasklets as fast as I can, and then get out the |
| 1101 | * poller. |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1102 | */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1103 | if (!spin_trylock(&brd->bd_lock)) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1104 | continue; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1105 | |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1106 | /* |
| 1107 | * If board is in a failed state, don't bother |
| 1108 | * scheduling a tasklet |
| 1109 | */ |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1110 | if (brd->state == BOARD_FAILED) { |
| 1111 | spin_unlock(&brd->bd_lock); |
| 1112 | continue; |
| 1113 | } |
| 1114 | |
| 1115 | /* Schedule a poll helper task */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1116 | if (!brd->intr_running) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1117 | tasklet_schedule(&brd->helper_tasklet); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1118 | |
| 1119 | /* |
| 1120 | * Can't do DGAP_UNLOCK here, as we don't have |
| 1121 | * lock_flags because we did a trylock above. |
| 1122 | */ |
| 1123 | spin_unlock(&brd->bd_lock); |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | schedule_poller: |
| 1128 | |
| 1129 | /* |
| 1130 | * Schedule ourself back at the nominal wakeup interval. |
| 1131 | */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1132 | spin_lock_irqsave(&dgap_poll_lock, lock_flags); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1133 | dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick); |
| 1134 | |
| 1135 | new_time = dgap_poll_time - jiffies; |
| 1136 | |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1137 | if ((ulong) new_time >= 2 * dgap_poll_tick) { |
| 1138 | dgap_poll_time = |
| 1139 | jiffies + dgap_jiffies_from_ms(dgap_poll_tick); |
| 1140 | } |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1141 | |
| 1142 | dgap_poll_timer.function = dgap_poll_handler; |
| 1143 | dgap_poll_timer.data = 0; |
| 1144 | dgap_poll_timer.expires = dgap_poll_time; |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1145 | spin_unlock_irqrestore(&dgap_poll_lock, lock_flags); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1146 | |
| 1147 | if (!dgap_poll_stop) |
| 1148 | add_timer(&dgap_poll_timer); |
| 1149 | } |
| 1150 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1151 | /* |
| 1152 | * dgap_intr() |
| 1153 | * |
| 1154 | * Driver interrupt handler. |
| 1155 | */ |
| 1156 | static irqreturn_t dgap_intr(int irq, void *voidbrd) |
| 1157 | { |
| 1158 | struct board_t *brd = (struct board_t *) voidbrd; |
| 1159 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 1160 | if (!brd) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1161 | return IRQ_NONE; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1162 | |
| 1163 | /* |
| 1164 | * Check to make sure its for us. |
| 1165 | */ |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 1166 | if (brd->magic != DGAP_BOARD_MAGIC) |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1167 | return IRQ_NONE; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1168 | |
| 1169 | brd->intr_count++; |
| 1170 | |
| 1171 | /* |
| 1172 | * Schedule tasklet to run at a better time. |
| 1173 | */ |
| 1174 | tasklet_schedule(&brd->helper_tasklet); |
| 1175 | return IRQ_HANDLED; |
| 1176 | } |
| 1177 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1178 | /* |
| 1179 | * dgap_init_globals() |
| 1180 | * |
| 1181 | * This is where we initialize the globals from the static insmod |
| 1182 | * configuration variables. These are declared near the head of |
| 1183 | * this file. |
| 1184 | */ |
| 1185 | static void dgap_init_globals(void) |
| 1186 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 1187 | int i; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1188 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1189 | for (i = 0; i < MAXBOARDS; i++) |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1190 | dgap_board[i] = NULL; |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1191 | |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 1192 | init_timer(&dgap_poll_timer); |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1193 | } |
| 1194 | |
Scott_Kilau@digi.com | c84b8b5 | 2013-08-21 21:48:31 -0400 | [diff] [blame] | 1195 | /************************************************************************ |
| 1196 | * |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1197 | * TTY Initialization/Cleanup Functions |
| 1198 | * |
| 1199 | ************************************************************************/ |
| 1200 | |
| 1201 | /* |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1202 | * dgap_tty_register() |
| 1203 | * |
| 1204 | * Init the tty subsystem for this board. |
| 1205 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 1206 | static int dgap_tty_register(struct board_t *brd) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1207 | { |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1208 | int rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1209 | |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1210 | brd->serial_driver = tty_alloc_driver(MAXPORTS, 0); |
| 1211 | if (IS_ERR(brd->serial_driver)) |
| 1212 | return PTR_ERR(brd->serial_driver); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1213 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1214 | snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_", |
| 1215 | brd->boardnum); |
| 1216 | brd->serial_driver->name = brd->serial_name; |
| 1217 | brd->serial_driver->name_base = 0; |
| 1218 | brd->serial_driver->major = 0; |
| 1219 | brd->serial_driver->minor_start = 0; |
| 1220 | brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL; |
| 1221 | brd->serial_driver->subtype = SERIAL_TYPE_NORMAL; |
| 1222 | brd->serial_driver->init_termios = dgap_default_termios; |
| 1223 | brd->serial_driver->driver_name = DRVSTR; |
| 1224 | brd->serial_driver->flags = (TTY_DRIVER_REAL_RAW | |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1225 | TTY_DRIVER_DYNAMIC_DEV | |
| 1226 | TTY_DRIVER_HARDWARE_BREAK); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1227 | |
| 1228 | /* The kernel wants space to store pointers to tty_structs */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1229 | brd->serial_driver->ttys = |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1230 | kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL); |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1231 | if (!brd->serial_driver->ttys) { |
| 1232 | rc = -ENOMEM; |
| 1233 | goto free_serial_drv; |
| 1234 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1235 | |
| 1236 | /* |
| 1237 | * Entry points for driver. Called by the kernel from |
| 1238 | * tty_io.c and n_tty.c. |
| 1239 | */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1240 | tty_set_operations(brd->serial_driver, &dgap_tty_ops); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1241 | |
| 1242 | /* |
| 1243 | * If we're doing transparent print, we have to do all of the above |
| 1244 | * again, separately so we don't get the LD confused about what major |
| 1245 | * we are when we get into the dgap_tty_open() routine. |
| 1246 | */ |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1247 | brd->print_driver = tty_alloc_driver(MAXPORTS, 0); |
| 1248 | if (IS_ERR(brd->print_driver)) { |
| 1249 | rc = PTR_ERR(brd->print_driver); |
| 1250 | goto free_serial_drv; |
| 1251 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1252 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1253 | snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_", |
| 1254 | brd->boardnum); |
| 1255 | brd->print_driver->name = brd->print_name; |
| 1256 | brd->print_driver->name_base = 0; |
| 1257 | brd->print_driver->major = 0; |
| 1258 | brd->print_driver->minor_start = 0; |
| 1259 | brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL; |
| 1260 | brd->print_driver->subtype = SERIAL_TYPE_NORMAL; |
| 1261 | brd->print_driver->init_termios = dgap_default_termios; |
| 1262 | brd->print_driver->driver_name = DRVSTR; |
| 1263 | brd->print_driver->flags = (TTY_DRIVER_REAL_RAW | |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1264 | TTY_DRIVER_DYNAMIC_DEV | |
| 1265 | TTY_DRIVER_HARDWARE_BREAK); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1266 | |
| 1267 | /* The kernel wants space to store pointers to tty_structs */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1268 | brd->print_driver->ttys = |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1269 | kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL); |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1270 | if (!brd->print_driver->ttys) { |
| 1271 | rc = -ENOMEM; |
| 1272 | goto free_print_drv; |
| 1273 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1274 | |
| 1275 | /* |
| 1276 | * Entry points for driver. Called by the kernel from |
| 1277 | * tty_io.c and n_tty.c. |
| 1278 | */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1279 | tty_set_operations(brd->print_driver, &dgap_tty_ops); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1280 | |
Mark Hounschell | 5c3b48d | 2014-04-25 13:10:19 -0400 | [diff] [blame] | 1281 | /* Register tty devices */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1282 | rc = tty_register_driver(brd->serial_driver); |
Mark Hounschell | 5c3b48d | 2014-04-25 13:10:19 -0400 | [diff] [blame] | 1283 | if (rc < 0) |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1284 | goto free_print_drv; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1285 | |
Mark Hounschell | 5c3b48d | 2014-04-25 13:10:19 -0400 | [diff] [blame] | 1286 | /* Register Transparent Print devices */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1287 | rc = tty_register_driver(brd->print_driver); |
Mark Hounschell | 5c3b48d | 2014-04-25 13:10:19 -0400 | [diff] [blame] | 1288 | if (rc < 0) |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1289 | goto unregister_serial_drv; |
| 1290 | |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1291 | dgap_boards_by_major[brd->serial_driver->major] = brd; |
| 1292 | brd->dgap_serial_major = brd->serial_driver->major; |
| 1293 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1294 | dgap_boards_by_major[brd->print_driver->major] = brd; |
| 1295 | brd->dgap_transparent_print_major = brd->print_driver->major; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1296 | |
Daeseok Youn | 9140fcd | 2014-05-19 18:56:34 +0900 | [diff] [blame] | 1297 | return 0; |
| 1298 | |
| 1299 | unregister_serial_drv: |
| 1300 | tty_unregister_driver(brd->serial_driver); |
| 1301 | free_print_drv: |
| 1302 | put_tty_driver(brd->print_driver); |
| 1303 | free_serial_drv: |
| 1304 | put_tty_driver(brd->serial_driver); |
| 1305 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 1306 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1307 | } |
| 1308 | |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 1309 | static void dgap_tty_unregister(struct board_t *brd) |
| 1310 | { |
| 1311 | tty_unregister_driver(brd->print_driver); |
| 1312 | tty_unregister_driver(brd->serial_driver); |
| 1313 | put_tty_driver(brd->print_driver); |
| 1314 | put_tty_driver(brd->serial_driver); |
| 1315 | } |
| 1316 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1317 | /* |
| 1318 | * dgap_tty_init() |
| 1319 | * |
| 1320 | * Init the tty subsystem. Called once per board after board has been |
| 1321 | * downloaded and init'ed. |
| 1322 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 1323 | static int dgap_tty_init(struct board_t *brd) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1324 | { |
| 1325 | int i; |
| 1326 | int tlw; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 1327 | uint true_count; |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 1328 | u8 __iomem *vaddr; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 1329 | u8 modem; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1330 | struct channel_t *ch; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 1331 | struct bs_t __iomem *bs; |
Mark Hounschell | 6a30cdd | 2014-04-23 16:43:21 -0400 | [diff] [blame] | 1332 | struct cm_t __iomem *cm; |
Daeseok Youn | 551a9d7 | 2014-06-02 14:07:46 +0900 | [diff] [blame] | 1333 | int ret; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1334 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1335 | /* |
| 1336 | * Initialize board structure elements. |
| 1337 | */ |
| 1338 | |
| 1339 | vaddr = brd->re_map_membase; |
| 1340 | true_count = readw((vaddr + NCHAN)); |
| 1341 | |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 1342 | brd->nasync = dgap_config_get_num_prts(brd); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1343 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1344 | if (!brd->nasync) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1345 | brd->nasync = brd->maxports; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1346 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1347 | if (brd->nasync > brd->maxports) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1348 | brd->nasync = brd->maxports; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1349 | |
| 1350 | if (true_count != brd->nasync) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 1351 | dev_warn(&brd->pdev->dev, |
| 1352 | "%s configured for %d ports, has %d ports.\n", |
| 1353 | brd->name, brd->nasync, true_count); |
Daeseok Youn | 35edf11 | 2014-08-09 14:37:39 +0900 | [diff] [blame] | 1354 | |
| 1355 | if ((brd->type == PPCM) && |
| 1356 | (true_count == 64 || true_count == 0)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 1357 | dev_warn(&brd->pdev->dev, |
| 1358 | "Please make SURE the EBI cable running from the card\n"); |
| 1359 | dev_warn(&brd->pdev->dev, |
| 1360 | "to each EM module is plugged into EBI IN!\n"); |
Daeseok Youn | 35edf11 | 2014-08-09 14:37:39 +0900 | [diff] [blame] | 1361 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1362 | |
| 1363 | brd->nasync = true_count; |
| 1364 | |
| 1365 | /* If no ports, don't bother going any further */ |
| 1366 | if (!brd->nasync) { |
| 1367 | brd->state = BOARD_FAILED; |
| 1368 | brd->dpastatus = BD_NOFEP; |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 1369 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | /* |
| 1374 | * Allocate channel memory that might not have been allocated |
| 1375 | * when the driver was first loaded. |
| 1376 | */ |
| 1377 | for (i = 0; i < brd->nasync; i++) { |
Daeseok Youn | e74c2dd | 2014-06-02 14:06:53 +0900 | [diff] [blame] | 1378 | brd->channels[i] = |
| 1379 | kzalloc(sizeof(struct channel_t), GFP_KERNEL); |
Daeseok Youn | 551a9d7 | 2014-06-02 14:07:46 +0900 | [diff] [blame] | 1380 | if (!brd->channels[i]) { |
| 1381 | ret = -ENOMEM; |
| 1382 | goto free_chan; |
| 1383 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | ch = brd->channels[0]; |
| 1387 | vaddr = brd->re_map_membase; |
| 1388 | |
Mark Hounschell | 630b2ab | 2014-04-24 09:22:12 -0400 | [diff] [blame] | 1389 | bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF); |
| 1390 | cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1391 | |
| 1392 | brd->bd_bs = bs; |
| 1393 | |
| 1394 | /* Set up channel variables */ |
| 1395 | for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) { |
| 1396 | |
Mark Hounschell | 211568d | 2014-03-11 10:11:43 -0400 | [diff] [blame] | 1397 | spin_lock_init(&ch->ch_lock); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1398 | |
| 1399 | /* Store all our magic numbers */ |
| 1400 | ch->magic = DGAP_CHANNEL_MAGIC; |
| 1401 | ch->ch_tun.magic = DGAP_UNIT_MAGIC; |
| 1402 | ch->ch_tun.un_type = DGAP_SERIAL; |
| 1403 | ch->ch_tun.un_ch = ch; |
| 1404 | ch->ch_tun.un_dev = i; |
| 1405 | |
| 1406 | ch->ch_pun.magic = DGAP_UNIT_MAGIC; |
| 1407 | ch->ch_pun.un_type = DGAP_PRINT; |
| 1408 | ch->ch_pun.un_ch = ch; |
| 1409 | ch->ch_pun.un_dev = i; |
| 1410 | |
| 1411 | ch->ch_vaddr = vaddr; |
| 1412 | ch->ch_bs = bs; |
| 1413 | ch->ch_cm = cm; |
| 1414 | ch->ch_bd = brd; |
| 1415 | ch->ch_portnum = i; |
| 1416 | ch->ch_digi = dgap_digi_init; |
| 1417 | |
| 1418 | /* |
| 1419 | * Set up digi dsr and dcd bits based on altpin flag. |
| 1420 | */ |
| 1421 | if (dgap_config_get_altpin(brd)) { |
| 1422 | ch->ch_dsr = DM_CD; |
| 1423 | ch->ch_cd = DM_DSR; |
| 1424 | ch->ch_digi.digi_flags |= DIGI_ALTPIN; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1425 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1426 | ch->ch_cd = DM_CD; |
| 1427 | ch->ch_dsr = DM_DSR; |
| 1428 | } |
| 1429 | |
Pascal COMBES | 77870a1 | 2014-05-24 15:58:09 +0200 | [diff] [blame] | 1430 | ch->ch_taddr = vaddr + (ioread16(&(ch->ch_bs->tx_seg)) << 4); |
| 1431 | ch->ch_raddr = vaddr + (ioread16(&(ch->ch_bs->rx_seg)) << 4); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1432 | ch->ch_tx_win = 0; |
| 1433 | ch->ch_rx_win = 0; |
| 1434 | ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1; |
| 1435 | ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1; |
| 1436 | ch->ch_tstart = 0; |
| 1437 | ch->ch_rstart = 0; |
| 1438 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1439 | /* |
| 1440 | * Set queue water marks, interrupt mask, |
| 1441 | * and general tty parameters. |
| 1442 | */ |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 1443 | tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) : |
| 1444 | ch->ch_tsize / 2; |
| 1445 | ch->ch_tlw = tlw; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1446 | |
| 1447 | dgap_cmdw(ch, STLOW, tlw, 0); |
| 1448 | |
| 1449 | dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0); |
| 1450 | |
| 1451 | dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0); |
| 1452 | |
| 1453 | ch->ch_mistat = readb(&(ch->ch_bs->m_stat)); |
| 1454 | |
| 1455 | init_waitqueue_head(&ch->ch_flags_wait); |
| 1456 | init_waitqueue_head(&ch->ch_tun.un_flags_wait); |
| 1457 | init_waitqueue_head(&ch->ch_pun.un_flags_wait); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1458 | |
| 1459 | /* Turn on all modem interrupts for now */ |
| 1460 | modem = (DM_CD | DM_DSR | DM_CTS | DM_RI); |
| 1461 | writeb(modem, &(ch->ch_bs->m_int)); |
| 1462 | |
| 1463 | /* |
| 1464 | * Set edelay to 0 if interrupts are turned on, |
| 1465 | * otherwise set edelay to the usual 100. |
| 1466 | */ |
| 1467 | if (brd->intr_used) |
| 1468 | writew(0, &(ch->ch_bs->edelay)); |
| 1469 | else |
| 1470 | writew(100, &(ch->ch_bs->edelay)); |
| 1471 | |
| 1472 | writeb(1, &(ch->ch_bs->idata)); |
| 1473 | } |
| 1474 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 1475 | return 0; |
Daeseok Youn | 551a9d7 | 2014-06-02 14:07:46 +0900 | [diff] [blame] | 1476 | |
| 1477 | free_chan: |
| 1478 | while (--i >= 0) { |
| 1479 | kfree(brd->channels[i]); |
| 1480 | brd->channels[i] = NULL; |
| 1481 | } |
| 1482 | return ret; |
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 | /* |
Daeseok Youn | 08f53f6 | 2014-06-13 18:19:55 +0900 | [diff] [blame] | 1486 | * dgap_tty_free() |
| 1487 | * |
| 1488 | * Free the channles which are allocated in dgap_tty_init(). |
| 1489 | */ |
| 1490 | static void dgap_tty_free(struct board_t *brd) |
| 1491 | { |
| 1492 | int i; |
| 1493 | |
| 1494 | for (i = 0; i < brd->nasync; i++) |
| 1495 | kfree(brd->channels[i]); |
| 1496 | } |
| 1497 | /* |
Daeseok Youn | 7bf0a4c | 2014-06-03 15:28:42 +0900 | [diff] [blame] | 1498 | * dgap_cleanup_tty() |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1499 | * |
| 1500 | * Uninitialize the TTY portion of this driver. Free all memory and |
| 1501 | * resources. |
| 1502 | */ |
Daeseok Youn | 7bf0a4c | 2014-06-03 15:28:42 +0900 | [diff] [blame] | 1503 | static void dgap_cleanup_tty(struct board_t *brd) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1504 | { |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 1505 | struct device *dev; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 1506 | int i; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1507 | |
Daeseok Youn | 83d24f8 | 2014-08-09 14:36:44 +0900 | [diff] [blame] | 1508 | dgap_boards_by_major[brd->serial_driver->major] = NULL; |
| 1509 | brd->dgap_serial_major = 0; |
| 1510 | for (i = 0; i < brd->nasync; i++) { |
| 1511 | tty_port_destroy(&brd->serial_ports[i]); |
| 1512 | dev = brd->channels[i]->ch_tun.un_sysfs; |
| 1513 | dgap_remove_tty_sysfs(dev); |
| 1514 | tty_unregister_device(brd->serial_driver, i); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1515 | } |
Daeseok Youn | 83d24f8 | 2014-08-09 14:36:44 +0900 | [diff] [blame] | 1516 | tty_unregister_driver(brd->serial_driver); |
| 1517 | put_tty_driver(brd->serial_driver); |
| 1518 | kfree(brd->serial_ports); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1519 | |
Daeseok Youn | 83d24f8 | 2014-08-09 14:36:44 +0900 | [diff] [blame] | 1520 | dgap_boards_by_major[brd->print_driver->major] = NULL; |
| 1521 | brd->dgap_transparent_print_major = 0; |
| 1522 | for (i = 0; i < brd->nasync; i++) { |
| 1523 | tty_port_destroy(&brd->printer_ports[i]); |
| 1524 | dev = brd->channels[i]->ch_pun.un_sysfs; |
| 1525 | dgap_remove_tty_sysfs(dev); |
| 1526 | tty_unregister_device(brd->print_driver, i); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1527 | } |
Daeseok Youn | 83d24f8 | 2014-08-09 14:36:44 +0900 | [diff] [blame] | 1528 | tty_unregister_driver(brd->print_driver); |
| 1529 | put_tty_driver(brd->print_driver); |
| 1530 | kfree(brd->printer_ports); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1531 | } |
| 1532 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1533 | /*======================================================================= |
| 1534 | * |
| 1535 | * dgap_input - Process received data. |
| 1536 | * |
| 1537 | * ch - Pointer to channel structure. |
| 1538 | * |
| 1539 | *=======================================================================*/ |
| 1540 | |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 1541 | static void dgap_input(struct channel_t *ch) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1542 | { |
| 1543 | struct board_t *bd; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 1544 | struct bs_t __iomem *bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1545 | struct tty_struct *tp; |
| 1546 | struct tty_ldisc *ld; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 1547 | uint rmask; |
| 1548 | uint head; |
| 1549 | uint tail; |
| 1550 | int data_len; |
| 1551 | ulong lock_flags; |
| 1552 | ulong lock_flags2; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1553 | int flip_len; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 1554 | int len; |
| 1555 | int n; |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 1556 | u8 *buf; |
| 1557 | u8 tmpchar; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 1558 | int s; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1559 | |
| 1560 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 1561 | return; |
| 1562 | |
| 1563 | tp = ch->ch_tun.un_tty; |
| 1564 | |
| 1565 | bs = ch->ch_bs; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1566 | if (!bs) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1567 | return; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1568 | |
| 1569 | bd = ch->ch_bd; |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 1570 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1571 | return; |
| 1572 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1573 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 1574 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1575 | |
| 1576 | /* |
| 1577 | * Figure the number of characters in the buffer. |
| 1578 | * Exit immediately if none. |
| 1579 | */ |
| 1580 | |
| 1581 | rmask = ch->ch_rsize - 1; |
| 1582 | |
| 1583 | head = readw(&(bs->rx_head)); |
| 1584 | head &= rmask; |
| 1585 | tail = readw(&(bs->rx_tail)); |
| 1586 | tail &= rmask; |
| 1587 | |
| 1588 | data_len = (head - tail) & rmask; |
| 1589 | |
| 1590 | if (data_len == 0) { |
| 1591 | writeb(1, &(bs->idata)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1592 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1593 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1594 | return; |
| 1595 | } |
| 1596 | |
| 1597 | /* |
| 1598 | * If the device is not open, or CREAD is off, flush |
| 1599 | * input data and return immediately. |
| 1600 | */ |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 1601 | if ((bd->state != BOARD_READY) || !tp || |
| 1602 | (tp->magic != TTY_MAGIC) || |
| 1603 | !(ch->ch_tun.un_flags & UN_ISOPEN) || |
| 1604 | !(tp->termios.c_cflag & CREAD) || |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1605 | (ch->ch_tun.un_flags & UN_CLOSING)) { |
| 1606 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1607 | writew(head, &(bs->rx_tail)); |
| 1608 | writeb(1, &(bs->idata)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1609 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1610 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1611 | return; |
| 1612 | } |
| 1613 | |
| 1614 | /* |
| 1615 | * If we are throttled, simply don't read any data. |
| 1616 | */ |
| 1617 | if (ch->ch_flags & CH_RXBLOCK) { |
| 1618 | writeb(1, &(bs->idata)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1619 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1620 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1621 | return; |
| 1622 | } |
| 1623 | |
| 1624 | /* |
| 1625 | * Ignore oruns. |
| 1626 | */ |
| 1627 | tmpchar = readb(&(bs->orun)); |
| 1628 | if (tmpchar) { |
| 1629 | ch->ch_err_overrun++; |
| 1630 | writeb(0, &(bs->orun)); |
| 1631 | } |
| 1632 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1633 | /* Decide how much data we can send into the tty layer */ |
| 1634 | flip_len = TTY_FLIPBUF_SIZE; |
| 1635 | |
| 1636 | /* Chop down the length, if needed */ |
| 1637 | len = min(data_len, flip_len); |
| 1638 | len = min(len, (N_TTY_BUF_SIZE - 1)); |
| 1639 | |
| 1640 | ld = tty_ldisc_ref(tp); |
| 1641 | |
| 1642 | #ifdef TTY_DONT_FLIP |
| 1643 | /* |
| 1644 | * If the DONT_FLIP flag is on, don't flush our buffer, and act |
| 1645 | * like the ld doesn't have any space to put the data right now. |
| 1646 | */ |
| 1647 | if (test_bit(TTY_DONT_FLIP, &tp->flags)) |
| 1648 | len = 0; |
| 1649 | #endif |
| 1650 | |
| 1651 | /* |
| 1652 | * If we were unable to get a reference to the ld, |
| 1653 | * don't flush our buffer, and act like the ld doesn't |
| 1654 | * have any space to put the data right now. |
| 1655 | */ |
| 1656 | if (!ld) { |
| 1657 | len = 0; |
| 1658 | } else { |
| 1659 | /* |
| 1660 | * If ld doesn't have a pointer to a receive_buf function, |
| 1661 | * flush the data, then act like the ld doesn't have any |
| 1662 | * space to put the data right now. |
| 1663 | */ |
| 1664 | if (!ld->ops->receive_buf) { |
| 1665 | writew(head, &(bs->rx_tail)); |
| 1666 | len = 0; |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | if (len <= 0) { |
| 1671 | writeb(1, &(bs->idata)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1672 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1673 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1674 | if (ld) |
| 1675 | tty_ldisc_deref(ld); |
| 1676 | return; |
| 1677 | } |
| 1678 | |
| 1679 | buf = ch->ch_bd->flipbuf; |
| 1680 | n = len; |
| 1681 | |
| 1682 | /* |
| 1683 | * n now contains the most amount of data we can copy, |
| 1684 | * bounded either by our buffer size or the amount |
| 1685 | * of data the card actually has pending... |
| 1686 | */ |
| 1687 | while (n) { |
| 1688 | |
| 1689 | s = ((head >= tail) ? head : ch->ch_rsize) - tail; |
| 1690 | s = min(s, n); |
| 1691 | |
| 1692 | if (s <= 0) |
| 1693 | break; |
| 1694 | |
Mark Hounschell | 630b2ab | 2014-04-24 09:22:12 -0400 | [diff] [blame] | 1695 | memcpy_fromio(buf, ch->ch_raddr + tail, s); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1696 | |
| 1697 | tail += s; |
| 1698 | buf += s; |
| 1699 | |
| 1700 | n -= s; |
| 1701 | /* Flip queue if needed */ |
| 1702 | tail &= rmask; |
| 1703 | } |
| 1704 | |
| 1705 | writew(tail, &(bs->rx_tail)); |
| 1706 | writeb(1, &(bs->idata)); |
| 1707 | ch->ch_rxcount += len; |
| 1708 | |
| 1709 | /* |
| 1710 | * If we are completely raw, we don't need to go through a lot |
| 1711 | * of the tty layers that exist. |
| 1712 | * In this case, we take the shortest and fastest route we |
| 1713 | * can to relay the data to the user. |
| 1714 | * |
| 1715 | * On the other hand, if we are not raw, we need to go through |
| 1716 | * the tty layer, which has its API more well defined. |
| 1717 | */ |
| 1718 | if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) { |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 1719 | dgap_parity_scan(ch, ch->ch_bd->flipbuf, |
| 1720 | ch->ch_bd->flipflagbuf, &len); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1721 | |
| 1722 | len = tty_buffer_request_room(tp->port, len); |
| 1723 | tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf, |
| 1724 | ch->ch_bd->flipflagbuf, len); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1725 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1726 | len = tty_buffer_request_room(tp->port, len); |
| 1727 | tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len); |
| 1728 | } |
| 1729 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1730 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1731 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1732 | |
| 1733 | /* Tell the tty layer its okay to "eat" the data now */ |
| 1734 | tty_flip_buffer_push(tp->port); |
| 1735 | |
| 1736 | if (ld) |
| 1737 | tty_ldisc_deref(ld); |
| 1738 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1739 | } |
| 1740 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1741 | /************************************************************************ |
| 1742 | * Determines when CARRIER changes state and takes appropriate |
| 1743 | * action. |
| 1744 | ************************************************************************/ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 1745 | static void dgap_carrier(struct channel_t *ch) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1746 | { |
| 1747 | struct board_t *bd; |
| 1748 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 1749 | int virt_carrier = 0; |
| 1750 | int phys_carrier = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1751 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1752 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 1753 | return; |
| 1754 | |
| 1755 | bd = ch->ch_bd; |
| 1756 | |
| 1757 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 1758 | return; |
| 1759 | |
| 1760 | /* Make sure altpin is always set correctly */ |
| 1761 | if (ch->ch_digi.digi_flags & DIGI_ALTPIN) { |
| 1762 | ch->ch_dsr = DM_CD; |
| 1763 | ch->ch_cd = DM_DSR; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1764 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1765 | ch->ch_dsr = DM_DSR; |
| 1766 | ch->ch_cd = DM_CD; |
| 1767 | } |
| 1768 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 1769 | if (ch->ch_mistat & D_CD(ch)) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1770 | phys_carrier = 1; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1771 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1772 | if (ch->ch_digi.digi_flags & DIGI_FORCEDCD) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1773 | virt_carrier = 1; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1774 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1775 | if (ch->ch_c_cflag & CLOCAL) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1776 | virt_carrier = 1; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1777 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1778 | /* |
| 1779 | * Test for a VIRTUAL carrier transition to HIGH. |
| 1780 | */ |
| 1781 | if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) { |
| 1782 | |
| 1783 | /* |
| 1784 | * When carrier rises, wake any threads waiting |
| 1785 | * for carrier in the open routine. |
| 1786 | */ |
| 1787 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1788 | if (waitqueue_active(&(ch->ch_flags_wait))) |
| 1789 | wake_up_interruptible(&ch->ch_flags_wait); |
| 1790 | } |
| 1791 | |
| 1792 | /* |
| 1793 | * Test for a PHYSICAL carrier transition to HIGH. |
| 1794 | */ |
| 1795 | if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) { |
| 1796 | |
| 1797 | /* |
| 1798 | * When carrier rises, wake any threads waiting |
| 1799 | * for carrier in the open routine. |
| 1800 | */ |
| 1801 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1802 | if (waitqueue_active(&(ch->ch_flags_wait))) |
| 1803 | wake_up_interruptible(&ch->ch_flags_wait); |
| 1804 | } |
| 1805 | |
| 1806 | /* |
| 1807 | * Test for a PHYSICAL transition to low, so long as we aren't |
| 1808 | * currently ignoring physical transitions (which is what "virtual |
| 1809 | * carrier" indicates). |
| 1810 | * |
| 1811 | * The transition of the virtual carrier to low really doesn't |
| 1812 | * matter... it really only means "ignore carrier state", not |
| 1813 | * "make pretend that carrier is there". |
| 1814 | */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1815 | if ((virt_carrier == 0) && |
| 1816 | ((ch->ch_flags & CH_CD) != 0) && |
| 1817 | (phys_carrier == 0)) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1818 | |
| 1819 | /* |
| 1820 | * When carrier drops: |
| 1821 | * |
| 1822 | * Drop carrier on all open units. |
| 1823 | * |
| 1824 | * Flush queues, waking up any task waiting in the |
| 1825 | * line discipline. |
| 1826 | * |
| 1827 | * Send a hangup to the control terminal. |
| 1828 | * |
| 1829 | * Enable all select calls. |
| 1830 | */ |
| 1831 | if (waitqueue_active(&(ch->ch_flags_wait))) |
| 1832 | wake_up_interruptible(&ch->ch_flags_wait); |
| 1833 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 1834 | if (ch->ch_tun.un_open_count > 0) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1835 | tty_hangup(ch->ch_tun.un_tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1836 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 1837 | if (ch->ch_pun.un_open_count > 0) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1838 | tty_hangup(ch->ch_pun.un_tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | /* |
| 1842 | * Make sure that our cached values reflect the current reality. |
| 1843 | */ |
| 1844 | if (virt_carrier == 1) |
| 1845 | ch->ch_flags |= CH_FCAR; |
| 1846 | else |
| 1847 | ch->ch_flags &= ~CH_FCAR; |
| 1848 | |
| 1849 | if (phys_carrier == 1) |
| 1850 | ch->ch_flags |= CH_CD; |
| 1851 | else |
| 1852 | ch->ch_flags &= ~CH_CD; |
| 1853 | } |
| 1854 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1855 | /************************************************************************ |
| 1856 | * |
| 1857 | * TTY Entry points and helper functions |
| 1858 | * |
| 1859 | ************************************************************************/ |
| 1860 | |
| 1861 | /* |
| 1862 | * dgap_tty_open() |
| 1863 | * |
| 1864 | */ |
| 1865 | static int dgap_tty_open(struct tty_struct *tty, struct file *file) |
| 1866 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 1867 | struct board_t *brd; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1868 | struct channel_t *ch; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 1869 | struct un_t *un; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 1870 | struct bs_t __iomem *bs; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 1871 | uint major; |
| 1872 | uint minor; |
| 1873 | int rc; |
| 1874 | ulong lock_flags; |
| 1875 | ulong lock_flags2; |
| 1876 | u16 head; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1877 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1878 | major = MAJOR(tty_devnum(tty)); |
| 1879 | minor = MINOR(tty_devnum(tty)); |
| 1880 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1881 | if (major > 255) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 1882 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1883 | |
| 1884 | /* Get board pointer from our array of majors we have allocated */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1885 | brd = dgap_boards_by_major[major]; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1886 | if (!brd) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 1887 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1888 | |
| 1889 | /* |
| 1890 | * If board is not yet up to a state of READY, go to |
| 1891 | * sleep waiting for it to happen or they cancel the open. |
| 1892 | */ |
| 1893 | rc = wait_event_interruptible(brd->state_wait, |
| 1894 | (brd->state & BOARD_READY)); |
| 1895 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1896 | if (rc) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1897 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1898 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1899 | spin_lock_irqsave(&brd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1900 | |
| 1901 | /* The wait above should guarantee this cannot happen */ |
| 1902 | if (brd->state != BOARD_READY) { |
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 | /* If opened device is greater than our number of ports, bail. */ |
| 1908 | if (MINOR(tty_devnum(tty)) > brd->nasync) { |
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 | ch = brd->channels[minor]; |
| 1914 | if (!ch) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1915 | spin_unlock_irqrestore(&brd->bd_lock, lock_flags); |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 1916 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1917 | } |
| 1918 | |
| 1919 | /* Grab channel lock */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1920 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1921 | |
| 1922 | /* Figure out our type */ |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1923 | if (major == brd->dgap_serial_major) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1924 | un = &brd->channels[minor]->ch_tun; |
| 1925 | un->un_type = DGAP_SERIAL; |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 1926 | } else if (major == brd->dgap_transparent_print_major) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1927 | un = &brd->channels[minor]->ch_pun; |
| 1928 | un->un_type = DGAP_PRINT; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 1929 | } else { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1930 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1931 | spin_unlock_irqrestore(&brd->bd_lock, lock_flags); |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 1932 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | /* Store our unit into driver_data, so we always have it available. */ |
| 1936 | tty->driver_data = un; |
| 1937 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1938 | /* |
| 1939 | * Error if channel info pointer is NULL. |
| 1940 | */ |
| 1941 | bs = ch->ch_bs; |
| 1942 | if (!bs) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1943 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1944 | spin_unlock_irqrestore(&brd->bd_lock, lock_flags); |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 1945 | return -EIO; |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 1946 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1947 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1948 | /* |
| 1949 | * Initialize tty's |
| 1950 | */ |
| 1951 | if (!(un->un_flags & UN_ISOPEN)) { |
| 1952 | /* Store important variables. */ |
| 1953 | un->un_tty = tty; |
| 1954 | |
| 1955 | /* Maybe do something here to the TTY struct as well? */ |
| 1956 | } |
| 1957 | |
| 1958 | /* |
| 1959 | * Initialize if neither terminal or printer is open. |
| 1960 | */ |
| 1961 | if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) { |
| 1962 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1963 | ch->ch_mforce = 0; |
| 1964 | ch->ch_mval = 0; |
| 1965 | |
| 1966 | /* |
| 1967 | * Flush input queue. |
| 1968 | */ |
| 1969 | head = readw(&(bs->rx_head)); |
| 1970 | writew(head, &(bs->rx_tail)); |
| 1971 | |
| 1972 | ch->ch_flags = 0; |
| 1973 | ch->pscan_state = 0; |
| 1974 | ch->pscan_savechar = 0; |
| 1975 | |
| 1976 | ch->ch_c_cflag = tty->termios.c_cflag; |
| 1977 | ch->ch_c_iflag = tty->termios.c_iflag; |
| 1978 | ch->ch_c_oflag = tty->termios.c_oflag; |
| 1979 | ch->ch_c_lflag = tty->termios.c_lflag; |
| 1980 | ch->ch_startc = tty->termios.c_cc[VSTART]; |
| 1981 | ch->ch_stopc = tty->termios.c_cc[VSTOP]; |
| 1982 | |
| 1983 | /* TODO: flush our TTY struct here? */ |
| 1984 | } |
| 1985 | |
| 1986 | dgap_carrier(ch); |
| 1987 | /* |
| 1988 | * Run param in case we changed anything |
| 1989 | */ |
Daeseok Youn | ab6cdcb | 2014-07-11 19:22:39 +0900 | [diff] [blame] | 1990 | dgap_param(ch, brd, un->un_type); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1991 | |
| 1992 | /* |
| 1993 | * follow protocol for opening port |
| 1994 | */ |
| 1995 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 1996 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 1997 | spin_unlock_irqrestore(&brd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 1998 | |
| 1999 | rc = dgap_block_til_ready(tty, file, ch); |
| 2000 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2001 | if (!un->un_tty) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2002 | return -ENODEV; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2003 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2004 | /* No going back now, increment our unit and channel counters */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2005 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2006 | ch->ch_open_count++; |
| 2007 | un->un_open_count++; |
| 2008 | un->un_flags |= (UN_ISOPEN); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2009 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2010 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2011 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2012 | } |
| 2013 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2014 | /* |
| 2015 | * dgap_block_til_ready() |
| 2016 | * |
| 2017 | * Wait for DCD, if needed. |
| 2018 | */ |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2019 | static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, |
| 2020 | struct channel_t *ch) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2021 | { |
| 2022 | int retval = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2023 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 2024 | ulong lock_flags; |
| 2025 | uint old_flags; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2026 | int sleep_on_un_flags; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2027 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2028 | if (!tty || tty->magic != TTY_MAGIC || !file || !ch || |
| 2029 | ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 2030 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2031 | |
| 2032 | un = tty->driver_data; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2033 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 2034 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2035 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2036 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2037 | |
| 2038 | ch->ch_wopen++; |
| 2039 | |
| 2040 | /* Loop forever */ |
| 2041 | while (1) { |
| 2042 | |
| 2043 | sleep_on_un_flags = 0; |
| 2044 | |
| 2045 | /* |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2046 | * If board has failed somehow during our sleep, |
| 2047 | * bail with error. |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2048 | */ |
| 2049 | if (ch->ch_bd->state == BOARD_FAILED) { |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 2050 | retval = -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2051 | break; |
| 2052 | } |
| 2053 | |
| 2054 | /* If tty was hung up, break out of loop and set error. */ |
| 2055 | if (tty_hung_up_p(file)) { |
| 2056 | retval = -EAGAIN; |
| 2057 | break; |
| 2058 | } |
| 2059 | |
| 2060 | /* |
| 2061 | * If either unit is in the middle of the fragile part of close, |
| 2062 | * we just cannot touch the channel safely. |
| 2063 | * Go back to sleep, knowing that when the channel can be |
| 2064 | * touched safely, the close routine will signal the |
| 2065 | * ch_wait_flags to wake us back up. |
| 2066 | */ |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2067 | if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & |
| 2068 | UN_CLOSING)) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2069 | |
| 2070 | /* |
| 2071 | * Our conditions to leave cleanly and happily: |
| 2072 | * 1) NONBLOCKING on the tty is set. |
| 2073 | * 2) CLOCAL is set. |
| 2074 | * 3) DCD (fake or real) is active. |
| 2075 | */ |
| 2076 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2077 | if (file->f_flags & O_NONBLOCK) |
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 | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2080 | if (tty->flags & (1 << TTY_IO_ERROR)) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2081 | break; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2082 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 2083 | if (ch->ch_flags & CH_CD) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2084 | break; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2085 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 2086 | if (ch->ch_flags & CH_FCAR) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2087 | break; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2088 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2089 | sleep_on_un_flags = 1; |
| 2090 | } |
| 2091 | |
| 2092 | /* |
| 2093 | * If there is a signal pending, the user probably |
| 2094 | * interrupted (ctrl-c) us. |
| 2095 | * Leave loop with error set. |
| 2096 | */ |
| 2097 | if (signal_pending(current)) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2098 | retval = -ERESTARTSYS; |
| 2099 | break; |
| 2100 | } |
| 2101 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2102 | /* |
| 2103 | * Store the flags before we let go of channel lock |
| 2104 | */ |
| 2105 | if (sleep_on_un_flags) |
| 2106 | old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags; |
| 2107 | else |
| 2108 | old_flags = ch->ch_flags; |
| 2109 | |
| 2110 | /* |
| 2111 | * Let go of channel lock before calling schedule. |
| 2112 | * Our poller will get any FEP events and wake us up when DCD |
| 2113 | * eventually goes active. |
| 2114 | */ |
| 2115 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2116 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2117 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2118 | /* |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2119 | * Wait for something in the flags to change |
| 2120 | * from the current value. |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2121 | */ |
| 2122 | if (sleep_on_un_flags) { |
| 2123 | retval = wait_event_interruptible(un->un_flags_wait, |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2124 | (old_flags != (ch->ch_tun.un_flags | |
| 2125 | ch->ch_pun.un_flags))); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2126 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2127 | retval = wait_event_interruptible(ch->ch_flags_wait, |
| 2128 | (old_flags != ch->ch_flags)); |
| 2129 | } |
| 2130 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2131 | /* |
| 2132 | * We got woken up for some reason. |
| 2133 | * Before looping around, grab our channel lock. |
| 2134 | */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2135 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | ch->ch_wopen--; |
| 2139 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2140 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2141 | |
Daeseok Youn | dfa30ac | 2014-07-15 18:47:11 +0900 | [diff] [blame] | 2142 | return retval; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2143 | } |
| 2144 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2145 | /* |
| 2146 | * dgap_tty_hangup() |
| 2147 | * |
| 2148 | * Hangup the port. Like a close, but don't wait for output to drain. |
| 2149 | */ |
| 2150 | static void dgap_tty_hangup(struct tty_struct *tty) |
| 2151 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 2152 | struct board_t *bd; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2153 | struct channel_t *ch; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 2154 | struct un_t *un; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2155 | |
| 2156 | if (!tty || tty->magic != TTY_MAGIC) |
| 2157 | return; |
| 2158 | |
| 2159 | un = tty->driver_data; |
| 2160 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 2161 | return; |
| 2162 | |
| 2163 | ch = un->un_ch; |
| 2164 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 2165 | return; |
| 2166 | |
| 2167 | bd = ch->ch_bd; |
| 2168 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 2169 | return; |
| 2170 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2171 | /* flush the transmit queues */ |
| 2172 | dgap_tty_flush_buffer(tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2173 | } |
| 2174 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2175 | /* |
| 2176 | * dgap_tty_close() |
| 2177 | * |
| 2178 | */ |
| 2179 | static void dgap_tty_close(struct tty_struct *tty, struct file *file) |
| 2180 | { |
| 2181 | struct ktermios *ts; |
| 2182 | struct board_t *bd; |
| 2183 | struct channel_t *ch; |
| 2184 | struct un_t *un; |
| 2185 | ulong lock_flags; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2186 | |
| 2187 | if (!tty || tty->magic != TTY_MAGIC) |
| 2188 | return; |
| 2189 | |
| 2190 | un = tty->driver_data; |
| 2191 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 2192 | return; |
| 2193 | |
| 2194 | ch = un->un_ch; |
| 2195 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 2196 | return; |
| 2197 | |
| 2198 | bd = ch->ch_bd; |
| 2199 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 2200 | return; |
| 2201 | |
| 2202 | ts = &tty->termios; |
| 2203 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2204 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2205 | |
| 2206 | /* |
| 2207 | * Determine if this is the last close or not - and if we agree about |
| 2208 | * which type of close it is with the Line Discipline |
| 2209 | */ |
Mark Hounschell | 82ed977 | 2014-03-03 16:36:24 -0500 | [diff] [blame] | 2210 | if ((tty->count == 1) && (un->un_open_count != 1)) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2211 | /* |
| 2212 | * Uh, oh. tty->count is 1, which means that the tty |
| 2213 | * structure will be freed. un_open_count should always |
| 2214 | * be one in these conditions. If it's greater than |
| 2215 | * one, we've got real problems, since it means the |
| 2216 | * serial port won't be shutdown. |
| 2217 | */ |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2218 | un->un_open_count = 1; |
Mark Hounschell | 82ed977 | 2014-03-03 16:36:24 -0500 | [diff] [blame] | 2219 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2220 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 2221 | if (--un->un_open_count < 0) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2222 | un->un_open_count = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2223 | |
| 2224 | ch->ch_open_count--; |
| 2225 | |
| 2226 | if (ch->ch_open_count && un->un_open_count) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2227 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2228 | return; |
| 2229 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2230 | |
| 2231 | /* OK, its the last close on the unit */ |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2232 | |
| 2233 | un->un_flags |= UN_CLOSING; |
| 2234 | |
| 2235 | tty->closing = 1; |
| 2236 | |
| 2237 | /* |
| 2238 | * Only officially close channel if count is 0 and |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2239 | * DIGI_PRINTER bit is not set. |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2240 | */ |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2241 | if ((ch->ch_open_count == 0) && |
| 2242 | !(ch->ch_digi.digi_flags & DIGI_PRINTER)) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2243 | |
| 2244 | ch->ch_flags &= ~(CH_RXBLOCK); |
| 2245 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2246 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2247 | |
| 2248 | /* wait for output to drain */ |
| 2249 | /* This will also return if we take an interrupt */ |
| 2250 | |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2251 | dgap_wait_for_drain(tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2252 | |
| 2253 | dgap_tty_flush_buffer(tty); |
| 2254 | tty_ldisc_flush(tty); |
| 2255 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2256 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2257 | |
| 2258 | tty->closing = 0; |
| 2259 | |
| 2260 | /* |
| 2261 | * If we have HUPCL set, lower DTR and RTS |
| 2262 | */ |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 2263 | if (ch->ch_c_cflag & HUPCL) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2264 | ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch)); |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 2265 | dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2266 | |
| 2267 | /* |
| 2268 | * Go to sleep to ensure RTS/DTR |
| 2269 | * have been dropped for modems to see it. |
| 2270 | */ |
Daeseok Youn | 492a1e7 | 2014-09-16 16:19:06 +0900 | [diff] [blame] | 2271 | spin_unlock_irqrestore(&ch->ch_lock, |
| 2272 | lock_flags); |
| 2273 | |
| 2274 | /* .25 second delay for dropping RTS/DTR */ |
| 2275 | schedule_timeout_interruptible(msecs_to_jiffies(250)); |
| 2276 | |
| 2277 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | ch->pscan_state = 0; |
| 2281 | ch->pscan_savechar = 0; |
| 2282 | ch->ch_baud_info = 0; |
| 2283 | |
| 2284 | } |
| 2285 | |
| 2286 | /* |
| 2287 | * turn off print device when closing print device. |
| 2288 | */ |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 2289 | if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2290 | dgap_wmove(ch, ch->ch_digi.digi_offstr, |
| 2291 | (int) ch->ch_digi.digi_offlen); |
| 2292 | ch->ch_flags &= ~CH_PRON; |
| 2293 | } |
| 2294 | |
| 2295 | un->un_tty = NULL; |
| 2296 | un->un_flags &= ~(UN_ISOPEN | UN_CLOSING); |
| 2297 | tty->driver_data = NULL; |
| 2298 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2299 | wake_up_interruptible(&ch->ch_flags_wait); |
| 2300 | wake_up_interruptible(&un->un_flags_wait); |
| 2301 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2302 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2303 | } |
| 2304 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2305 | /* |
| 2306 | * dgap_tty_chars_in_buffer() |
| 2307 | * |
| 2308 | * Return number of characters that have not been transmitted yet. |
| 2309 | * |
| 2310 | * This routine is used by the line discipline to determine if there |
| 2311 | * is data waiting to be transmitted/drained/flushed or not. |
| 2312 | */ |
| 2313 | static int dgap_tty_chars_in_buffer(struct tty_struct *tty) |
| 2314 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2315 | struct board_t *bd; |
| 2316 | struct channel_t *ch; |
| 2317 | struct un_t *un; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 2318 | struct bs_t __iomem *bs; |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 2319 | u8 tbusy; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2320 | uint chars; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2321 | u16 thead, ttail, tmask, chead, ctail; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 2322 | ulong lock_flags = 0; |
| 2323 | ulong lock_flags2 = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2324 | |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 2325 | if (!tty) |
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 | un = tty->driver_data; |
| 2329 | if (!un || un->magic != DGAP_UNIT_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 | ch = un->un_ch; |
| 2333 | if (!ch || ch->magic != DGAP_CHANNEL_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 | |
| 2336 | bd = ch->ch_bd; |
| 2337 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
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 | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2340 | bs = ch->ch_bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2341 | if (!bs) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2342 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2343 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2344 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 2345 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2346 | |
| 2347 | tmask = (ch->ch_tsize - 1); |
| 2348 | |
| 2349 | /* Get Transmit queue pointers */ |
| 2350 | thead = readw(&(bs->tx_head)) & tmask; |
| 2351 | ttail = readw(&(bs->tx_tail)) & tmask; |
| 2352 | |
| 2353 | /* Get tbusy flag */ |
| 2354 | tbusy = readb(&(bs->tbusy)); |
| 2355 | |
| 2356 | /* Get Command queue pointers */ |
| 2357 | chead = readw(&(ch->ch_cm->cm_head)); |
| 2358 | ctail = readw(&(ch->ch_cm->cm_tail)); |
| 2359 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2360 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 2361 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2362 | |
| 2363 | /* |
| 2364 | * The only way we know for sure if there is no pending |
| 2365 | * data left to be transferred, is if: |
| 2366 | * 1) Transmit head and tail are equal (empty). |
| 2367 | * 2) Command queue head and tail are equal (empty). |
| 2368 | * 3) The "TBUSY" flag is 0. (Transmitter not busy). |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2369 | */ |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2370 | |
| 2371 | if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) { |
| 2372 | chars = 0; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2373 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2374 | if (thead >= ttail) |
| 2375 | chars = thead - ttail; |
| 2376 | else |
| 2377 | chars = thead - ttail + ch->ch_tsize; |
| 2378 | /* |
| 2379 | * Fudge factor here. |
| 2380 | * If chars is zero, we know that the command queue had |
| 2381 | * something in it or tbusy was set. Because we cannot |
| 2382 | * be sure if there is still some data to be transmitted, |
| 2383 | * lets lie, and tell ld we have 1 byte left. |
| 2384 | */ |
| 2385 | if (chars == 0) { |
| 2386 | /* |
| 2387 | * If TBUSY is still set, and our tx buffers are empty, |
| 2388 | * force the firmware to send me another wakeup after |
| 2389 | * TBUSY has been cleared. |
| 2390 | */ |
| 2391 | if (tbusy != 0) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2392 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2393 | un->un_flags |= UN_EMPTY; |
| 2394 | writeb(1, &(bs->iempty)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2395 | spin_unlock_irqrestore(&ch->ch_lock, |
| 2396 | lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2397 | } |
| 2398 | chars = 1; |
| 2399 | } |
| 2400 | } |
| 2401 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2402 | return chars; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2403 | } |
| 2404 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2405 | static int dgap_wait_for_drain(struct tty_struct *tty) |
| 2406 | { |
| 2407 | struct channel_t *ch; |
| 2408 | struct un_t *un; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 2409 | struct bs_t __iomem *bs; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2410 | int ret = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2411 | uint count = 1; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 2412 | ulong lock_flags = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2413 | |
| 2414 | if (!tty || tty->magic != TTY_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 | un = tty->driver_data; |
| 2418 | if (!un || un->magic != DGAP_UNIT_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 | |
| 2421 | ch = un->un_ch; |
| 2422 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
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 | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2425 | bs = ch->ch_bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2426 | if (!bs) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2427 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2428 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2429 | /* Loop until data is drained */ |
| 2430 | while (count != 0) { |
| 2431 | |
| 2432 | count = dgap_tty_chars_in_buffer(tty); |
| 2433 | |
| 2434 | if (count == 0) |
| 2435 | break; |
| 2436 | |
| 2437 | /* Set flag waiting for drain */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2438 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2439 | un->un_flags |= UN_EMPTY; |
| 2440 | writeb(1, &(bs->iempty)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2441 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2442 | |
| 2443 | /* Go to sleep till we get woken up */ |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2444 | ret = wait_event_interruptible(un->un_flags_wait, |
| 2445 | ((un->un_flags & UN_EMPTY) == 0)); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2446 | /* If ret is non-zero, user ctrl-c'ed us */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2447 | if (ret) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2448 | break; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2449 | } |
| 2450 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2451 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2452 | un->un_flags &= ~(UN_EMPTY); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2453 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2454 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2455 | return ret; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2456 | } |
| 2457 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2458 | /* |
| 2459 | * dgap_maxcps_room |
| 2460 | * |
| 2461 | * Reduces bytes_available to the max number of characters |
| 2462 | * that can be sent currently given the maxcps value, and |
| 2463 | * returns the new bytes_available. This only affects printer |
| 2464 | * output. |
| 2465 | */ |
Daeseok Youn | bdf4d4f | 2014-07-10 12:26:04 +0900 | [diff] [blame] | 2466 | static int dgap_maxcps_room(struct channel_t *ch, struct un_t *un, |
| 2467 | int bytes_available) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2468 | { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2469 | /* |
| 2470 | * If its not the Transparent print device, return |
| 2471 | * the full data amount. |
| 2472 | */ |
| 2473 | if (un->un_type != DGAP_PRINT) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2474 | return bytes_available; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2475 | |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 2476 | 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] | 2477 | int cps_limit = 0; |
| 2478 | unsigned long current_time = jiffies; |
| 2479 | unsigned long buffer_time = current_time + |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2480 | (HZ * ch->ch_digi.digi_bufsize) / |
| 2481 | ch->ch_digi.digi_maxcps; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2482 | |
| 2483 | if (ch->ch_cpstime < current_time) { |
| 2484 | /* buffer is empty */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 2485 | ch->ch_cpstime = current_time; /* reset ch_cpstime */ |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2486 | cps_limit = ch->ch_digi.digi_bufsize; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2487 | } else if (ch->ch_cpstime < buffer_time) { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2488 | /* still room in the buffer */ |
Mark Hounschell | 6045b6a | 2014-03-06 13:02:45 -0500 | [diff] [blame] | 2489 | cps_limit = ((buffer_time - ch->ch_cpstime) * |
| 2490 | ch->ch_digi.digi_maxcps) / HZ; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2491 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2492 | /* no room in the buffer */ |
| 2493 | cps_limit = 0; |
| 2494 | } |
| 2495 | |
| 2496 | bytes_available = min(cps_limit, bytes_available); |
| 2497 | } |
| 2498 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2499 | return bytes_available; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2500 | } |
| 2501 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2502 | static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event) |
| 2503 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2504 | struct channel_t *ch; |
| 2505 | struct bs_t __iomem *bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2506 | |
| 2507 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 2508 | return; |
| 2509 | ch = un->un_ch; |
| 2510 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 2511 | return; |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2512 | bs = ch->ch_bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2513 | if (!bs) |
| 2514 | return; |
| 2515 | |
| 2516 | if ((event & UN_LOW) != 0) { |
| 2517 | if ((un->un_flags & UN_LOW) == 0) { |
| 2518 | un->un_flags |= UN_LOW; |
| 2519 | writeb(1, &(bs->ilow)); |
| 2520 | } |
| 2521 | } |
| 2522 | if ((event & UN_LOW) != 0) { |
| 2523 | if ((un->un_flags & UN_EMPTY) == 0) { |
| 2524 | un->un_flags |= UN_EMPTY; |
| 2525 | writeb(1, &(bs->iempty)); |
| 2526 | } |
| 2527 | } |
| 2528 | } |
| 2529 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2530 | /* |
| 2531 | * dgap_tty_write_room() |
| 2532 | * |
| 2533 | * Return space available in Tx buffer |
| 2534 | */ |
| 2535 | static int dgap_tty_write_room(struct tty_struct *tty) |
| 2536 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2537 | struct channel_t *ch; |
| 2538 | struct un_t *un; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 2539 | struct bs_t __iomem *bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2540 | u16 head, tail, tmask; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2541 | int ret; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 2542 | ulong lock_flags = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2543 | |
Mark Hounschell | 6126022 | 2014-03-06 13:03:33 -0500 | [diff] [blame] | 2544 | if (!tty) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2545 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2546 | |
| 2547 | un = tty->driver_data; |
| 2548 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2549 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2550 | |
| 2551 | ch = un->un_ch; |
| 2552 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2553 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2554 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2555 | bs = ch->ch_bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2556 | if (!bs) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2557 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2558 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2559 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2560 | |
| 2561 | tmask = ch->ch_tsize - 1; |
| 2562 | head = readw(&(bs->tx_head)) & tmask; |
| 2563 | tail = readw(&(bs->tx_tail)) & tmask; |
| 2564 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2565 | ret = tail - head - 1; |
| 2566 | if (ret < 0) |
| 2567 | ret += ch->ch_tsize; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2568 | |
| 2569 | /* Limit printer to maxcps */ |
Daeseok Youn | bdf4d4f | 2014-07-10 12:26:04 +0900 | [diff] [blame] | 2570 | ret = dgap_maxcps_room(ch, un, ret); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2571 | |
| 2572 | /* |
| 2573 | * If we are printer device, leave space for |
| 2574 | * possibly both the on and off strings. |
| 2575 | */ |
| 2576 | if (un->un_type == DGAP_PRINT) { |
| 2577 | if (!(ch->ch_flags & CH_PRON)) |
| 2578 | ret -= ch->ch_digi.digi_onlen; |
| 2579 | ret -= ch->ch_digi.digi_offlen; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2580 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2581 | if (ch->ch_flags & CH_PRON) |
| 2582 | ret -= ch->ch_digi.digi_offlen; |
| 2583 | } |
| 2584 | |
| 2585 | if (ret < 0) |
| 2586 | ret = 0; |
| 2587 | |
| 2588 | /* |
| 2589 | * Schedule FEP to wake us up if needed. |
| 2590 | * |
| 2591 | * TODO: This might be overkill... |
| 2592 | * Do we really need to schedule callbacks from the FEP |
| 2593 | * in every case? Can we get smarter based on ret? |
| 2594 | */ |
| 2595 | dgap_set_firmware_event(un, UN_LOW | UN_EMPTY); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2596 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2597 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2598 | return ret; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2599 | } |
| 2600 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2601 | /* |
| 2602 | * dgap_tty_put_char() |
| 2603 | * |
| 2604 | * Put a character into ch->ch_buf |
| 2605 | * |
| 2606 | * - used by the line discipline for OPOST processing |
| 2607 | */ |
| 2608 | static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c) |
| 2609 | { |
| 2610 | /* |
| 2611 | * Simply call tty_write. |
| 2612 | */ |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2613 | dgap_tty_write(tty, &c, 1); |
| 2614 | return 1; |
| 2615 | } |
| 2616 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2617 | /* |
| 2618 | * dgap_tty_write() |
| 2619 | * |
| 2620 | * Take data from the user or kernel and send it out to the FEP. |
| 2621 | * In here exists all the Transparent Print magic as well. |
| 2622 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 2623 | static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, |
| 2624 | int count) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2625 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2626 | struct channel_t *ch; |
| 2627 | struct un_t *un; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 2628 | struct bs_t __iomem *bs; |
Mark Hounschell | 630b2ab | 2014-04-24 09:22:12 -0400 | [diff] [blame] | 2629 | char __iomem *vaddr; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2630 | u16 head, tail, tmask, remain; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2631 | int bufcount, n; |
| 2632 | int orig_count; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2633 | ulong lock_flags; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2634 | |
Mark Hounschell | 6126022 | 2014-03-06 13:03:33 -0500 | [diff] [blame] | 2635 | if (!tty) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2636 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2637 | |
| 2638 | un = tty->driver_data; |
| 2639 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2640 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2641 | |
| 2642 | ch = un->un_ch; |
| 2643 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2644 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2645 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2646 | bs = ch->ch_bs; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2647 | if (!bs) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2648 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2649 | |
| 2650 | if (!count) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2651 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2652 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2653 | /* |
| 2654 | * Store original amount of characters passed in. |
| 2655 | * This helps to figure out if we should ask the FEP |
| 2656 | * to send us an event when it has more space available. |
| 2657 | */ |
| 2658 | orig_count = count; |
| 2659 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2660 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2661 | |
| 2662 | /* Get our space available for the channel from the board */ |
| 2663 | tmask = ch->ch_tsize - 1; |
| 2664 | head = readw(&(bs->tx_head)) & tmask; |
| 2665 | tail = readw(&(bs->tx_tail)) & tmask; |
| 2666 | |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 2667 | bufcount = tail - head - 1; |
| 2668 | if (bufcount < 0) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2669 | bufcount += ch->ch_tsize; |
| 2670 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2671 | /* |
| 2672 | * Limit printer output to maxcps overall, with bursts allowed |
| 2673 | * up to bufsize characters. |
| 2674 | */ |
Daeseok Youn | bdf4d4f | 2014-07-10 12:26:04 +0900 | [diff] [blame] | 2675 | bufcount = dgap_maxcps_room(ch, un, bufcount); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2676 | |
| 2677 | /* |
| 2678 | * Take minimum of what the user wants to send, and the |
| 2679 | * space available in the FEP buffer. |
| 2680 | */ |
| 2681 | count = min(count, bufcount); |
| 2682 | |
| 2683 | /* |
| 2684 | * Bail if no space left. |
| 2685 | */ |
| 2686 | if (count <= 0) { |
| 2687 | dgap_set_firmware_event(un, UN_LOW | UN_EMPTY); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2688 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2689 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | /* |
| 2693 | * Output the printer ON string, if we are in terminal mode, but |
| 2694 | * need to be in printer mode. |
| 2695 | */ |
| 2696 | if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) { |
| 2697 | dgap_wmove(ch, ch->ch_digi.digi_onstr, |
| 2698 | (int) ch->ch_digi.digi_onlen); |
| 2699 | head = readw(&(bs->tx_head)) & tmask; |
| 2700 | ch->ch_flags |= CH_PRON; |
| 2701 | } |
| 2702 | |
| 2703 | /* |
| 2704 | * On the other hand, output the printer OFF string, if we are |
| 2705 | * currently in printer mode, but need to output to the terminal. |
| 2706 | */ |
| 2707 | if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) { |
| 2708 | dgap_wmove(ch, ch->ch_digi.digi_offstr, |
| 2709 | (int) ch->ch_digi.digi_offlen); |
| 2710 | head = readw(&(bs->tx_head)) & tmask; |
| 2711 | ch->ch_flags &= ~CH_PRON; |
| 2712 | } |
| 2713 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2714 | n = count; |
| 2715 | |
| 2716 | /* |
| 2717 | * If the write wraps over the top of the circular buffer, |
| 2718 | * move the portion up to the wrap point, and reset the |
| 2719 | * pointers to the bottom. |
| 2720 | */ |
| 2721 | remain = ch->ch_tstart + ch->ch_tsize - head; |
| 2722 | |
| 2723 | if (n >= remain) { |
| 2724 | n -= remain; |
| 2725 | vaddr = ch->ch_taddr + head; |
| 2726 | |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 2727 | memcpy_toio(vaddr, (u8 *) buf, remain); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2728 | |
| 2729 | head = ch->ch_tstart; |
| 2730 | buf += remain; |
| 2731 | } |
| 2732 | |
| 2733 | if (n > 0) { |
| 2734 | |
| 2735 | /* |
| 2736 | * Move rest of data. |
| 2737 | */ |
| 2738 | vaddr = ch->ch_taddr + head; |
| 2739 | remain = n; |
| 2740 | |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 2741 | memcpy_toio(vaddr, (u8 *) buf, remain); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2742 | head += remain; |
| 2743 | |
| 2744 | } |
| 2745 | |
| 2746 | if (count) { |
| 2747 | ch->ch_txcount += count; |
| 2748 | head &= tmask; |
| 2749 | writew(head, &(bs->tx_head)); |
| 2750 | } |
| 2751 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2752 | dgap_set_firmware_event(un, UN_LOW | UN_EMPTY); |
| 2753 | |
| 2754 | /* |
| 2755 | * If this is the print device, and the |
| 2756 | * printer is still on, we need to turn it |
| 2757 | * off before going idle. If the buffer is |
| 2758 | * non-empty, wait until it goes empty. |
| 2759 | * Otherwise turn it off right now. |
| 2760 | */ |
| 2761 | if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) { |
| 2762 | tail = readw(&(bs->tx_tail)) & tmask; |
| 2763 | |
| 2764 | if (tail != head) { |
| 2765 | un->un_flags |= UN_EMPTY; |
| 2766 | writeb(1, &(bs->iempty)); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2767 | } else { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2768 | dgap_wmove(ch, ch->ch_digi.digi_offstr, |
| 2769 | (int) ch->ch_digi.digi_offlen); |
| 2770 | head = readw(&(bs->tx_head)) & tmask; |
| 2771 | ch->ch_flags &= ~CH_PRON; |
| 2772 | } |
| 2773 | } |
| 2774 | |
| 2775 | /* Update printer buffer empty time. */ |
| 2776 | if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0) |
| 2777 | && (ch->ch_digi.digi_bufsize > 0)) { |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2778 | ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2779 | } |
| 2780 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2781 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2782 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2783 | return count; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2784 | } |
| 2785 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2786 | /* |
| 2787 | * Return modem signals to ld. |
| 2788 | */ |
| 2789 | static int dgap_tty_tiocmget(struct tty_struct *tty) |
| 2790 | { |
| 2791 | struct channel_t *ch; |
| 2792 | struct un_t *un; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2793 | int result; |
| 2794 | u8 mstat; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2795 | ulong lock_flags; |
| 2796 | |
| 2797 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2798 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2799 | |
| 2800 | un = tty->driver_data; |
| 2801 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2802 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2803 | |
| 2804 | ch = un->un_ch; |
| 2805 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2806 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2807 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2808 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2809 | |
| 2810 | mstat = readb(&(ch->ch_bs->m_stat)); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2811 | /* Append any outbound signals that might be pending... */ |
| 2812 | mstat |= ch->ch_mostat; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2813 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2814 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2815 | |
| 2816 | result = 0; |
| 2817 | |
| 2818 | if (mstat & D_DTR(ch)) |
| 2819 | result |= TIOCM_DTR; |
| 2820 | if (mstat & D_RTS(ch)) |
| 2821 | result |= TIOCM_RTS; |
| 2822 | if (mstat & D_CTS(ch)) |
| 2823 | result |= TIOCM_CTS; |
| 2824 | if (mstat & D_DSR(ch)) |
| 2825 | result |= TIOCM_DSR; |
| 2826 | if (mstat & D_RI(ch)) |
| 2827 | result |= TIOCM_RI; |
| 2828 | if (mstat & D_CD(ch)) |
| 2829 | result |= TIOCM_CD; |
| 2830 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2831 | return result; |
| 2832 | } |
| 2833 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2834 | /* |
| 2835 | * dgap_tty_tiocmset() |
| 2836 | * |
| 2837 | * Set modem signals, called by ld. |
| 2838 | */ |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2839 | static int dgap_tty_tiocmset(struct tty_struct *tty, |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2840 | unsigned int set, unsigned int clear) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2841 | { |
| 2842 | struct board_t *bd; |
| 2843 | struct channel_t *ch; |
| 2844 | struct un_t *un; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2845 | ulong lock_flags; |
| 2846 | ulong lock_flags2; |
| 2847 | |
| 2848 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2849 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2850 | |
| 2851 | un = tty->driver_data; |
| 2852 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2853 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2854 | |
| 2855 | ch = un->un_ch; |
| 2856 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2857 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2858 | |
| 2859 | bd = ch->ch_bd; |
| 2860 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2861 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2862 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2863 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 2864 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2865 | |
| 2866 | if (set & TIOCM_RTS) { |
| 2867 | ch->ch_mforce |= D_RTS(ch); |
| 2868 | ch->ch_mval |= D_RTS(ch); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2869 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2870 | |
| 2871 | if (set & TIOCM_DTR) { |
| 2872 | ch->ch_mforce |= D_DTR(ch); |
| 2873 | ch->ch_mval |= D_DTR(ch); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2874 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2875 | |
| 2876 | if (clear & TIOCM_RTS) { |
| 2877 | ch->ch_mforce |= D_RTS(ch); |
| 2878 | ch->ch_mval &= ~(D_RTS(ch)); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2879 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2880 | |
| 2881 | if (clear & TIOCM_DTR) { |
| 2882 | ch->ch_mforce |= D_DTR(ch); |
| 2883 | ch->ch_mval &= ~(D_DTR(ch)); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 2884 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2885 | |
Daeseok Youn | ab6cdcb | 2014-07-11 19:22:39 +0900 | [diff] [blame] | 2886 | dgap_param(ch, bd, un->un_type); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2887 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2888 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 2889 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2890 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2891 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2892 | } |
| 2893 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2894 | /* |
| 2895 | * dgap_tty_send_break() |
| 2896 | * |
| 2897 | * Send a Break, called by ld. |
| 2898 | */ |
| 2899 | static int dgap_tty_send_break(struct tty_struct *tty, int msec) |
| 2900 | { |
| 2901 | struct board_t *bd; |
| 2902 | struct channel_t *ch; |
| 2903 | struct un_t *un; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2904 | ulong lock_flags; |
| 2905 | ulong lock_flags2; |
| 2906 | |
| 2907 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2908 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2909 | |
| 2910 | un = tty->driver_data; |
| 2911 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2912 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2913 | |
| 2914 | ch = un->un_ch; |
| 2915 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2916 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2917 | |
| 2918 | bd = ch->ch_bd; |
| 2919 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 2920 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2921 | |
| 2922 | switch (msec) { |
| 2923 | case -1: |
| 2924 | msec = 0xFFFF; |
| 2925 | break; |
| 2926 | case 0: |
| 2927 | msec = 1; |
| 2928 | break; |
| 2929 | default: |
| 2930 | msec /= 10; |
| 2931 | break; |
| 2932 | } |
| 2933 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2934 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 2935 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2936 | #if 0 |
| 2937 | dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0); |
| 2938 | #endif |
| 2939 | dgap_cmdw(ch, SBREAK, (u16) msec, 0); |
| 2940 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2941 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 2942 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2943 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 2944 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2945 | } |
| 2946 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2947 | /* |
| 2948 | * dgap_tty_wait_until_sent() |
| 2949 | * |
| 2950 | * wait until data has been transmitted, called by ld. |
| 2951 | */ |
| 2952 | static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout) |
| 2953 | { |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 2954 | dgap_wait_for_drain(tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2955 | } |
| 2956 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2957 | /* |
| 2958 | * dgap_send_xchar() |
| 2959 | * |
| 2960 | * send a high priority character, called by ld. |
| 2961 | */ |
| 2962 | static void dgap_tty_send_xchar(struct tty_struct *tty, char c) |
| 2963 | { |
| 2964 | struct board_t *bd; |
| 2965 | struct channel_t *ch; |
| 2966 | struct un_t *un; |
| 2967 | ulong lock_flags; |
| 2968 | ulong lock_flags2; |
| 2969 | |
| 2970 | if (!tty || tty->magic != TTY_MAGIC) |
| 2971 | return; |
| 2972 | |
| 2973 | un = tty->driver_data; |
| 2974 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 2975 | return; |
| 2976 | |
| 2977 | ch = un->un_ch; |
| 2978 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 2979 | return; |
| 2980 | |
| 2981 | bd = ch->ch_bd; |
| 2982 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 2983 | return; |
| 2984 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 2985 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 2986 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2987 | |
| 2988 | /* |
| 2989 | * This is technically what we should do. |
| 2990 | * However, the NIST tests specifically want |
| 2991 | * to see each XON or XOFF character that it |
| 2992 | * sends, so lets just send each character |
| 2993 | * by hand... |
| 2994 | */ |
| 2995 | #if 0 |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2996 | if (c == STOP_CHAR(tty)) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2997 | dgap_cmdw(ch, RPAUSE, 0, 0); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 2998 | else if (c == START_CHAR(tty)) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 2999 | dgap_cmdw(ch, RRESUME, 0, 0); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3000 | else |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3001 | dgap_wmove(ch, &c, 1); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3002 | #else |
| 3003 | dgap_wmove(ch, &c, 1); |
| 3004 | #endif |
| 3005 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3006 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3007 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3008 | } |
| 3009 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3010 | /* |
| 3011 | * Return modem signals to ld. |
| 3012 | */ |
| 3013 | static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value) |
| 3014 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 3015 | int result; |
| 3016 | u8 mstat; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3017 | ulong lock_flags; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 3018 | int rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3019 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3020 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3021 | |
| 3022 | mstat = readb(&(ch->ch_bs->m_stat)); |
| 3023 | /* Append any outbound signals that might be pending... */ |
| 3024 | mstat |= ch->ch_mostat; |
| 3025 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3026 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3027 | |
| 3028 | result = 0; |
| 3029 | |
| 3030 | if (mstat & D_DTR(ch)) |
| 3031 | result |= TIOCM_DTR; |
| 3032 | if (mstat & D_RTS(ch)) |
| 3033 | result |= TIOCM_RTS; |
| 3034 | if (mstat & D_CTS(ch)) |
| 3035 | result |= TIOCM_CTS; |
| 3036 | if (mstat & D_DSR(ch)) |
| 3037 | result |= TIOCM_DSR; |
| 3038 | if (mstat & D_RI(ch)) |
| 3039 | result |= TIOCM_RI; |
| 3040 | if (mstat & D_CD(ch)) |
| 3041 | result |= TIOCM_CD; |
| 3042 | |
| 3043 | rc = put_user(result, value); |
| 3044 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3045 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3046 | } |
| 3047 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3048 | /* |
| 3049 | * dgap_set_modem_info() |
| 3050 | * |
| 3051 | * Set modem signals, called by ld. |
| 3052 | */ |
Piotr Witoslawski | 70c0ed9 | 2014-09-04 08:18:53 +0200 | [diff] [blame] | 3053 | static int dgap_set_modem_info(struct channel_t *ch, struct board_t *bd, |
| 3054 | struct un_t *un, unsigned int command, |
| 3055 | unsigned int __user *value) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3056 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 3057 | int ret; |
| 3058 | unsigned int arg; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3059 | ulong lock_flags; |
| 3060 | ulong lock_flags2; |
| 3061 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3062 | ret = get_user(arg, value); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3063 | if (ret) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3064 | return ret; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3065 | |
| 3066 | switch (command) { |
| 3067 | case TIOCMBIS: |
| 3068 | if (arg & TIOCM_RTS) { |
| 3069 | ch->ch_mforce |= D_RTS(ch); |
| 3070 | ch->ch_mval |= D_RTS(ch); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3071 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3072 | |
| 3073 | if (arg & TIOCM_DTR) { |
| 3074 | ch->ch_mforce |= D_DTR(ch); |
| 3075 | ch->ch_mval |= D_DTR(ch); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3076 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3077 | |
| 3078 | break; |
| 3079 | |
| 3080 | case TIOCMBIC: |
| 3081 | if (arg & TIOCM_RTS) { |
| 3082 | ch->ch_mforce |= D_RTS(ch); |
| 3083 | ch->ch_mval &= ~(D_RTS(ch)); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3084 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3085 | |
| 3086 | if (arg & TIOCM_DTR) { |
| 3087 | ch->ch_mforce |= D_DTR(ch); |
| 3088 | ch->ch_mval &= ~(D_DTR(ch)); |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3089 | } |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3090 | |
| 3091 | break; |
| 3092 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3093 | case TIOCMSET: |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3094 | ch->ch_mforce = D_DTR(ch)|D_RTS(ch); |
| 3095 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3096 | if (arg & TIOCM_RTS) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3097 | ch->ch_mval |= D_RTS(ch); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3098 | else |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3099 | ch->ch_mval &= ~(D_RTS(ch)); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3100 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3101 | if (arg & TIOCM_DTR) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3102 | ch->ch_mval |= (D_DTR(ch)); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3103 | else |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3104 | ch->ch_mval &= ~(D_DTR(ch)); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3105 | |
| 3106 | break; |
| 3107 | |
| 3108 | default: |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3109 | return -EINVAL; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3110 | } |
| 3111 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3112 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3113 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3114 | |
Daeseok Youn | ab6cdcb | 2014-07-11 19:22:39 +0900 | [diff] [blame] | 3115 | dgap_param(ch, bd, un->un_type); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3116 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3117 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3118 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3119 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3120 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3121 | } |
| 3122 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3123 | /* |
| 3124 | * dgap_tty_digigeta() |
| 3125 | * |
| 3126 | * Ioctl to get the information for ditty. |
| 3127 | * |
| 3128 | * |
| 3129 | * |
| 3130 | */ |
Piotr Witoslawski | 70c0ed9 | 2014-09-04 08:18:53 +0200 | [diff] [blame] | 3131 | static int dgap_tty_digigeta(struct channel_t *ch, |
| 3132 | struct digi_t __user *retinfo) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3133 | { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3134 | struct digi_t tmp; |
| 3135 | ulong lock_flags; |
| 3136 | |
| 3137 | if (!retinfo) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3138 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3139 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3140 | memset(&tmp, 0, sizeof(tmp)); |
| 3141 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3142 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3143 | memcpy(&tmp, &ch->ch_digi, sizeof(tmp)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3144 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3145 | |
| 3146 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3147 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3148 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3149 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3150 | } |
| 3151 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3152 | /* |
| 3153 | * dgap_tty_digiseta() |
| 3154 | * |
| 3155 | * Ioctl to set the information for ditty. |
| 3156 | * |
| 3157 | * |
| 3158 | * |
| 3159 | */ |
Daeseok Youn | ffc11c1 | 2014-07-11 19:22:58 +0900 | [diff] [blame] | 3160 | static int dgap_tty_digiseta(struct channel_t *ch, struct board_t *bd, |
| 3161 | struct un_t *un, struct digi_t __user *new_info) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3162 | { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3163 | struct digi_t new_digi; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3164 | ulong lock_flags = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3165 | unsigned long lock_flags2; |
| 3166 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3167 | if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t))) |
| 3168 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3169 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3170 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3171 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3172 | |
| 3173 | memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t)); |
| 3174 | |
| 3175 | if (ch->ch_digi.digi_maxcps < 1) |
| 3176 | ch->ch_digi.digi_maxcps = 1; |
| 3177 | |
| 3178 | if (ch->ch_digi.digi_maxcps > 10000) |
| 3179 | ch->ch_digi.digi_maxcps = 10000; |
| 3180 | |
| 3181 | if (ch->ch_digi.digi_bufsize < 10) |
| 3182 | ch->ch_digi.digi_bufsize = 10; |
| 3183 | |
| 3184 | if (ch->ch_digi.digi_maxchar < 1) |
| 3185 | ch->ch_digi.digi_maxchar = 1; |
| 3186 | |
| 3187 | if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize) |
| 3188 | ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize; |
| 3189 | |
| 3190 | if (ch->ch_digi.digi_onlen > DIGI_PLEN) |
| 3191 | ch->ch_digi.digi_onlen = DIGI_PLEN; |
| 3192 | |
| 3193 | if (ch->ch_digi.digi_offlen > DIGI_PLEN) |
| 3194 | ch->ch_digi.digi_offlen = DIGI_PLEN; |
| 3195 | |
Daeseok Youn | ab6cdcb | 2014-07-11 19:22:39 +0900 | [diff] [blame] | 3196 | dgap_param(ch, bd, un->un_type); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3197 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3198 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3199 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3200 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3201 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3202 | } |
| 3203 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3204 | /* |
| 3205 | * dgap_tty_digigetedelay() |
| 3206 | * |
| 3207 | * Ioctl to get the current edelay setting. |
| 3208 | * |
| 3209 | * |
| 3210 | * |
| 3211 | */ |
| 3212 | static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo) |
| 3213 | { |
| 3214 | struct channel_t *ch; |
| 3215 | struct un_t *un; |
| 3216 | int tmp; |
| 3217 | ulong lock_flags; |
| 3218 | |
| 3219 | if (!retinfo) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3220 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3221 | |
| 3222 | if (!tty || tty->magic != TTY_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 | un = tty->driver_data; |
| 3226 | if (!un || un->magic != DGAP_UNIT_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 | |
| 3229 | ch = un->un_ch; |
| 3230 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3231 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3232 | |
| 3233 | memset(&tmp, 0, sizeof(tmp)); |
| 3234 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3235 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3236 | tmp = readw(&(ch->ch_bs->edelay)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3237 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3238 | |
| 3239 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3240 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3241 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3242 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3243 | } |
| 3244 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3245 | /* |
| 3246 | * dgap_tty_digisetedelay() |
| 3247 | * |
| 3248 | * Ioctl to set the EDELAY setting |
| 3249 | * |
| 3250 | */ |
Daeseok Youn | ccbe7e5 | 2014-07-11 19:23:54 +0900 | [diff] [blame] | 3251 | static int dgap_tty_digisetedelay(struct channel_t *ch, struct board_t *bd, |
| 3252 | struct un_t *un, int __user *new_info) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3253 | { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3254 | int new_digi; |
| 3255 | ulong lock_flags; |
| 3256 | ulong lock_flags2; |
| 3257 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3258 | if (copy_from_user(&new_digi, new_info, sizeof(int))) |
| 3259 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3260 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3261 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3262 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3263 | |
| 3264 | writew((u16) new_digi, &(ch->ch_bs->edelay)); |
| 3265 | |
Daeseok Youn | ab6cdcb | 2014-07-11 19:22:39 +0900 | [diff] [blame] | 3266 | dgap_param(ch, bd, un->un_type); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3267 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3268 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3269 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3270 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3271 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3272 | } |
| 3273 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3274 | /* |
| 3275 | * dgap_tty_digigetcustombaud() |
| 3276 | * |
| 3277 | * Ioctl to get the current custom baud rate setting. |
| 3278 | */ |
Daeseok Youn | 501bcd4 | 2014-07-11 19:24:14 +0900 | [diff] [blame] | 3279 | static int dgap_tty_digigetcustombaud(struct channel_t *ch, struct un_t *un, |
| 3280 | int __user *retinfo) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3281 | { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3282 | int tmp; |
| 3283 | ulong lock_flags; |
| 3284 | |
| 3285 | if (!retinfo) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3286 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3287 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3288 | memset(&tmp, 0, sizeof(tmp)); |
| 3289 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3290 | spin_lock_irqsave(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3291 | tmp = dgap_get_custom_baud(ch); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3292 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3293 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3294 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3295 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3296 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3297 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3298 | } |
| 3299 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3300 | /* |
| 3301 | * dgap_tty_digisetcustombaud() |
| 3302 | * |
| 3303 | * Ioctl to set the custom baud rate setting |
| 3304 | */ |
Daeseok Youn | db6fc2d | 2014-07-11 19:24:34 +0900 | [diff] [blame] | 3305 | static int dgap_tty_digisetcustombaud(struct channel_t *ch, struct board_t *bd, |
| 3306 | struct un_t *un, int __user *new_info) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3307 | { |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3308 | uint new_rate; |
| 3309 | ulong lock_flags; |
| 3310 | ulong lock_flags2; |
| 3311 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3312 | if (copy_from_user(&new_rate, new_info, sizeof(unsigned int))) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3313 | return -EFAULT; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3314 | |
| 3315 | if (bd->bd_flags & BD_FEP5PLUS) { |
| 3316 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3317 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3318 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3319 | |
| 3320 | ch->ch_custom_speed = new_rate; |
| 3321 | |
Daeseok Youn | ab6cdcb | 2014-07-11 19:22:39 +0900 | [diff] [blame] | 3322 | dgap_param(ch, bd, un->un_type); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3323 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3324 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3325 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3326 | } |
| 3327 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3328 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3329 | } |
| 3330 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3331 | /* |
| 3332 | * dgap_set_termios() |
| 3333 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 3334 | static void dgap_tty_set_termios(struct tty_struct *tty, |
| 3335 | struct ktermios *old_termios) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3336 | { |
| 3337 | struct board_t *bd; |
| 3338 | struct channel_t *ch; |
| 3339 | struct un_t *un; |
| 3340 | unsigned long lock_flags; |
| 3341 | unsigned long lock_flags2; |
| 3342 | |
| 3343 | if (!tty || tty->magic != TTY_MAGIC) |
| 3344 | return; |
| 3345 | |
| 3346 | un = tty->driver_data; |
| 3347 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 3348 | return; |
| 3349 | |
| 3350 | ch = un->un_ch; |
| 3351 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 3352 | return; |
| 3353 | |
| 3354 | bd = ch->ch_bd; |
| 3355 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 3356 | return; |
| 3357 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3358 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3359 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3360 | |
| 3361 | ch->ch_c_cflag = tty->termios.c_cflag; |
| 3362 | ch->ch_c_iflag = tty->termios.c_iflag; |
| 3363 | ch->ch_c_oflag = tty->termios.c_oflag; |
| 3364 | ch->ch_c_lflag = tty->termios.c_lflag; |
| 3365 | ch->ch_startc = tty->termios.c_cc[VSTART]; |
| 3366 | ch->ch_stopc = tty->termios.c_cc[VSTOP]; |
| 3367 | |
| 3368 | dgap_carrier(ch); |
Daeseok Youn | ab6cdcb | 2014-07-11 19:22:39 +0900 | [diff] [blame] | 3369 | dgap_param(ch, bd, un->un_type); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3370 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3371 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3372 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3373 | } |
| 3374 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3375 | static void dgap_tty_throttle(struct tty_struct *tty) |
| 3376 | { |
| 3377 | struct board_t *bd; |
| 3378 | struct channel_t *ch; |
| 3379 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3380 | ulong lock_flags; |
| 3381 | ulong lock_flags2; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3382 | |
| 3383 | if (!tty || tty->magic != TTY_MAGIC) |
| 3384 | return; |
| 3385 | |
| 3386 | un = tty->driver_data; |
| 3387 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 3388 | return; |
| 3389 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3390 | ch = un->un_ch; |
| 3391 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3392 | return; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3393 | |
| 3394 | bd = ch->ch_bd; |
| 3395 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 3396 | return; |
| 3397 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3398 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3399 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3400 | |
| 3401 | ch->ch_flags |= (CH_RXBLOCK); |
| 3402 | #if 1 |
| 3403 | dgap_cmdw(ch, RPAUSE, 0, 0); |
| 3404 | #endif |
| 3405 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3406 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3407 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3408 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3409 | } |
| 3410 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3411 | static void dgap_tty_unthrottle(struct tty_struct *tty) |
| 3412 | { |
| 3413 | struct board_t *bd; |
| 3414 | struct channel_t *ch; |
| 3415 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3416 | ulong lock_flags; |
| 3417 | ulong lock_flags2; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3418 | |
| 3419 | if (!tty || tty->magic != TTY_MAGIC) |
| 3420 | return; |
| 3421 | |
| 3422 | un = tty->driver_data; |
| 3423 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 3424 | return; |
| 3425 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3426 | ch = un->un_ch; |
| 3427 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3428 | return; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3429 | |
| 3430 | bd = ch->ch_bd; |
| 3431 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 3432 | return; |
| 3433 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3434 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3435 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3436 | |
| 3437 | ch->ch_flags &= ~(CH_RXBLOCK); |
| 3438 | |
| 3439 | #if 1 |
| 3440 | dgap_cmdw(ch, RRESUME, 0, 0); |
| 3441 | #endif |
| 3442 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3443 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3444 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3445 | } |
| 3446 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3447 | static void dgap_tty_start(struct tty_struct *tty) |
| 3448 | { |
| 3449 | struct board_t *bd; |
| 3450 | struct channel_t *ch; |
| 3451 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3452 | ulong lock_flags; |
| 3453 | ulong lock_flags2; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3454 | |
| 3455 | if (!tty || tty->magic != TTY_MAGIC) |
| 3456 | return; |
| 3457 | |
| 3458 | un = tty->driver_data; |
| 3459 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 3460 | return; |
| 3461 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3462 | ch = un->un_ch; |
| 3463 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3464 | return; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3465 | |
| 3466 | bd = ch->ch_bd; |
| 3467 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 3468 | return; |
| 3469 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3470 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3471 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3472 | |
| 3473 | dgap_cmdw(ch, RESUMETX, 0, 0); |
| 3474 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3475 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3476 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3477 | } |
| 3478 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3479 | static void dgap_tty_stop(struct tty_struct *tty) |
| 3480 | { |
| 3481 | struct board_t *bd; |
| 3482 | struct channel_t *ch; |
| 3483 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3484 | ulong lock_flags; |
| 3485 | ulong lock_flags2; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3486 | |
| 3487 | if (!tty || tty->magic != TTY_MAGIC) |
| 3488 | return; |
| 3489 | |
| 3490 | un = tty->driver_data; |
| 3491 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 3492 | return; |
| 3493 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3494 | ch = un->un_ch; |
| 3495 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3496 | return; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3497 | |
| 3498 | bd = ch->ch_bd; |
| 3499 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 3500 | return; |
| 3501 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3502 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3503 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3504 | |
| 3505 | dgap_cmdw(ch, PAUSETX, 0, 0); |
| 3506 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3507 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3508 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3509 | } |
| 3510 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3511 | /* |
| 3512 | * dgap_tty_flush_chars() |
| 3513 | * |
| 3514 | * Flush the cook buffer |
| 3515 | * |
| 3516 | * Note to self, and any other poor souls who venture here: |
| 3517 | * |
| 3518 | * flush in this case DOES NOT mean dispose of the data. |
| 3519 | * instead, it means "stop buffering and send it if you |
| 3520 | * haven't already." Just guess how I figured that out... SRW 2-Jun-98 |
| 3521 | * |
| 3522 | * It is also always called in interrupt context - JAR 8-Sept-99 |
| 3523 | */ |
| 3524 | static void dgap_tty_flush_chars(struct tty_struct *tty) |
| 3525 | { |
| 3526 | struct board_t *bd; |
| 3527 | struct channel_t *ch; |
| 3528 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3529 | ulong lock_flags; |
| 3530 | ulong lock_flags2; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3531 | |
| 3532 | if (!tty || tty->magic != TTY_MAGIC) |
| 3533 | return; |
| 3534 | |
| 3535 | un = tty->driver_data; |
| 3536 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 3537 | return; |
| 3538 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3539 | ch = un->un_ch; |
| 3540 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3541 | return; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3542 | |
| 3543 | bd = ch->ch_bd; |
| 3544 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 3545 | return; |
| 3546 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3547 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3548 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3549 | |
| 3550 | /* TODO: Do something here */ |
| 3551 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3552 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3553 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3554 | } |
| 3555 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3556 | /* |
| 3557 | * dgap_tty_flush_buffer() |
| 3558 | * |
| 3559 | * Flush Tx buffer (make in == out) |
| 3560 | */ |
| 3561 | static void dgap_tty_flush_buffer(struct tty_struct *tty) |
| 3562 | { |
| 3563 | struct board_t *bd; |
| 3564 | struct channel_t *ch; |
| 3565 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3566 | ulong lock_flags; |
| 3567 | ulong lock_flags2; |
| 3568 | u16 head; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3569 | |
| 3570 | if (!tty || tty->magic != TTY_MAGIC) |
| 3571 | return; |
| 3572 | |
| 3573 | un = tty->driver_data; |
| 3574 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
| 3575 | return; |
| 3576 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3577 | ch = un->un_ch; |
| 3578 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3579 | return; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3580 | |
| 3581 | bd = ch->ch_bd; |
| 3582 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
| 3583 | return; |
| 3584 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3585 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3586 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3587 | |
| 3588 | ch->ch_flags &= ~CH_STOP; |
| 3589 | head = readw(&(ch->ch_bs->tx_head)); |
| 3590 | dgap_cmdw(ch, FLUSHTX, (u16) head, 0); |
| 3591 | dgap_cmdw(ch, RESUMETX, 0, 0); |
| 3592 | if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) { |
| 3593 | ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY); |
| 3594 | wake_up_interruptible(&ch->ch_tun.un_flags_wait); |
| 3595 | } |
| 3596 | if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) { |
| 3597 | ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY); |
| 3598 | wake_up_interruptible(&ch->ch_pun.un_flags_wait); |
| 3599 | } |
| 3600 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3601 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3602 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3603 | if (waitqueue_active(&tty->write_wait)) |
| 3604 | wake_up_interruptible(&tty->write_wait); |
| 3605 | tty_wakeup(tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3606 | } |
| 3607 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3608 | /***************************************************************************** |
| 3609 | * |
| 3610 | * The IOCTL function and all of its helpers |
| 3611 | * |
| 3612 | *****************************************************************************/ |
| 3613 | |
| 3614 | /* |
| 3615 | * dgap_tty_ioctl() |
| 3616 | * |
| 3617 | * The usual assortment of ioctl's |
| 3618 | */ |
| 3619 | static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, |
| 3620 | unsigned long arg) |
| 3621 | { |
| 3622 | struct board_t *bd; |
| 3623 | struct channel_t *ch; |
| 3624 | struct un_t *un; |
| 3625 | int rc; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 3626 | u16 head; |
| 3627 | ulong lock_flags = 0; |
| 3628 | ulong lock_flags2 = 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3629 | void __user *uarg = (void __user *) arg; |
| 3630 | |
| 3631 | if (!tty || tty->magic != TTY_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3632 | return -ENODEV; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3633 | |
| 3634 | un = tty->driver_data; |
| 3635 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3636 | return -ENODEV; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3637 | |
| 3638 | ch = un->un_ch; |
| 3639 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3640 | return -ENODEV; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3641 | |
| 3642 | bd = ch->ch_bd; |
| 3643 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3644 | return -ENODEV; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3645 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3646 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3647 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3648 | |
| 3649 | if (un->un_open_count <= 0) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3650 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3651 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3652 | return -EIO; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3653 | } |
| 3654 | |
| 3655 | switch (cmd) { |
| 3656 | |
| 3657 | /* Here are all the standard ioctl's that we MUST implement */ |
| 3658 | |
| 3659 | case TCSBRK: |
| 3660 | /* |
| 3661 | * TCSBRK is SVID version: non-zero arg --> no break |
| 3662 | * this behaviour is exploited by tcdrain(). |
| 3663 | * |
| 3664 | * According to POSIX.1 spec (7.2.2.1.2) breaks should be |
| 3665 | * between 0.25 and 0.5 seconds so we'll ask for something |
| 3666 | * in the middle: 0.375 seconds. |
| 3667 | */ |
| 3668 | rc = tty_check_change(tty); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3669 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3670 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3671 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3672 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3673 | |
| 3674 | rc = dgap_wait_for_drain(tty); |
| 3675 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3676 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3677 | return -EINTR; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3678 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3679 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3680 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3681 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3682 | if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP)) |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3683 | dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3684 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3685 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3686 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3687 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3688 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3689 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3690 | case TCSBRKP: |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3691 | /* support for POSIX tcsendbreak() |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3692 | |
| 3693 | * According to POSIX.1 spec (7.2.2.1.2) breaks should be |
| 3694 | * between 0.25 and 0.5 seconds so we'll ask for something |
| 3695 | * in the middle: 0.375 seconds. |
| 3696 | */ |
| 3697 | rc = tty_check_change(tty); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3698 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3699 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3700 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3701 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3702 | |
| 3703 | rc = dgap_wait_for_drain(tty); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3704 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3705 | return -EINTR; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3706 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3707 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3708 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3709 | |
| 3710 | dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0); |
| 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 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3715 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3716 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3717 | case TIOCSBRK: |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3718 | /* |
| 3719 | * FEP5 doesn't support turning on a break unconditionally. |
| 3720 | * The FEP5 device will stop sending a break automatically |
| 3721 | * after the specified time value that was sent when turning on |
| 3722 | * the break. |
| 3723 | */ |
| 3724 | rc = tty_check_change(tty); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3725 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3726 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3727 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3728 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3729 | |
| 3730 | rc = dgap_wait_for_drain(tty); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3731 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3732 | return -EINTR; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3733 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3734 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3735 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3736 | |
| 3737 | dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0); |
| 3738 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3739 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3740 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3741 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3742 | return 0; |
| 3743 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 3744 | case TIOCCBRK: |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3745 | /* |
| 3746 | * FEP5 doesn't support turning off a break unconditionally. |
| 3747 | * The FEP5 device will stop sending a break automatically |
| 3748 | * after the specified time value that was sent when turning on |
| 3749 | * the break. |
| 3750 | */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3751 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3752 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3753 | return 0; |
| 3754 | |
| 3755 | case TIOCGSOFTCAR: |
| 3756 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3757 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3758 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3759 | |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 3760 | rc = put_user(C_CLOCAL(tty) ? 1 : 0, |
| 3761 | (unsigned long __user *) arg); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3762 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3763 | |
| 3764 | case TIOCSSOFTCAR: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3765 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3766 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3767 | |
| 3768 | rc = get_user(arg, (unsigned long __user *) arg); |
| 3769 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3770 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3771 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3772 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3773 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 3774 | tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | |
| 3775 | (arg ? CLOCAL : 0)); |
Daeseok Youn | ab6cdcb | 2014-07-11 19:22:39 +0900 | [diff] [blame] | 3776 | dgap_param(ch, bd, un->un_type); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3777 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3778 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3779 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3780 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3781 | |
| 3782 | case TIOCMGET: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3783 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3784 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3785 | return dgap_get_modem_info(ch, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3786 | |
| 3787 | case TIOCMBIS: |
| 3788 | case TIOCMBIC: |
| 3789 | case TIOCMSET: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3790 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3791 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Daeseok Youn | 4285c97 | 2014-07-11 19:23:34 +0900 | [diff] [blame] | 3792 | return dgap_set_modem_info(ch, bd, un, cmd, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3793 | |
| 3794 | /* |
| 3795 | * Here are any additional ioctl's that we want to implement |
| 3796 | */ |
| 3797 | |
| 3798 | case TCFLSH: |
| 3799 | /* |
| 3800 | * The linux tty driver doesn't have a flush |
| 3801 | * input routine for the driver, assuming all backed |
| 3802 | * up data is in the line disc. buffers. However, |
| 3803 | * we all know that's not the case. Here, we |
| 3804 | * act on the ioctl, but then lie and say we didn't |
| 3805 | * so the line discipline will process the flush |
| 3806 | * also. |
| 3807 | */ |
| 3808 | rc = tty_check_change(tty); |
| 3809 | if (rc) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3810 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3811 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
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 | |
| 3815 | if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) { |
| 3816 | if (!(un->un_type == DGAP_PRINT)) { |
| 3817 | head = readw(&(ch->ch_bs->rx_head)); |
| 3818 | writew(head, &(ch->ch_bs->rx_tail)); |
| 3819 | writeb(0, &(ch->ch_bs->orun)); |
| 3820 | } |
| 3821 | } |
| 3822 | |
Mark Hounschell | 70d97a6 | 2014-03-10 14:39:41 -0400 | [diff] [blame] | 3823 | if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) { |
| 3824 | /* pretend we didn't recognize this IOCTL */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3825 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3826 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | 70d97a6 | 2014-03-10 14:39:41 -0400 | [diff] [blame] | 3827 | |
| 3828 | return -ENOIOCTLCMD; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3829 | } |
| 3830 | |
Mark Hounschell | 70d97a6 | 2014-03-10 14:39:41 -0400 | [diff] [blame] | 3831 | ch->ch_flags &= ~CH_STOP; |
| 3832 | head = readw(&(ch->ch_bs->tx_head)); |
| 3833 | dgap_cmdw(ch, FLUSHTX, (u16) head, 0); |
| 3834 | dgap_cmdw(ch, RESUMETX, 0, 0); |
| 3835 | if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) { |
| 3836 | ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY); |
| 3837 | wake_up_interruptible(&ch->ch_tun.un_flags_wait); |
| 3838 | } |
| 3839 | if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) { |
| 3840 | ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY); |
| 3841 | wake_up_interruptible(&ch->ch_pun.un_flags_wait); |
| 3842 | } |
| 3843 | if (waitqueue_active(&tty->write_wait)) |
| 3844 | wake_up_interruptible(&tty->write_wait); |
| 3845 | |
| 3846 | /* Can't hold any locks when calling tty_wakeup! */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3847 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3848 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | 70d97a6 | 2014-03-10 14:39:41 -0400 | [diff] [blame] | 3849 | tty_wakeup(tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3850 | |
Mark Hounschell | 70d97a6 | 2014-03-10 14:39:41 -0400 | [diff] [blame] | 3851 | /* pretend we didn't recognize this IOCTL */ |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3852 | return -ENOIOCTLCMD; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3853 | |
| 3854 | case TCSETSF: |
| 3855 | case TCSETSW: |
| 3856 | /* |
| 3857 | * The linux tty driver doesn't have a flush |
| 3858 | * input routine for the driver, assuming all backed |
| 3859 | * up data is in the line disc. buffers. However, |
| 3860 | * we all know that's not the case. Here, we |
| 3861 | * act on the ioctl, but then lie and say we didn't |
| 3862 | * so the line discipline will process the flush |
| 3863 | * also. |
| 3864 | */ |
| 3865 | if (cmd == TCSETSF) { |
| 3866 | /* flush rx */ |
| 3867 | ch->ch_flags &= ~CH_STOP; |
| 3868 | head = readw(&(ch->ch_bs->rx_head)); |
| 3869 | writew(head, &(ch->ch_bs->rx_tail)); |
| 3870 | } |
| 3871 | |
| 3872 | /* now wait for all the output to drain */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3873 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3874 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3875 | rc = dgap_wait_for_drain(tty); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3876 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3877 | return -EINTR; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3878 | |
| 3879 | /* pretend we didn't recognize this */ |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3880 | return -ENOIOCTLCMD; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3881 | |
| 3882 | case TCSETAW: |
| 3883 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3884 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3885 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3886 | rc = dgap_wait_for_drain(tty); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3887 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3888 | return -EINTR; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3889 | |
| 3890 | /* pretend we didn't recognize this */ |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3891 | return -ENOIOCTLCMD; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3892 | |
| 3893 | case TCXONC: |
| 3894 | /* |
| 3895 | * The Linux Line Discipline (LD) would do this for us if we |
| 3896 | * let it, but we have the special firmware options to do this |
| 3897 | * the "right way" regardless of hardware or software flow |
| 3898 | * control so we'll do it outselves instead of letting the LD |
| 3899 | * do it. |
| 3900 | */ |
| 3901 | rc = tty_check_change(tty); |
| 3902 | if (rc) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3903 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3904 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3905 | return rc; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3906 | } |
| 3907 | |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3908 | switch (arg) { |
| 3909 | |
| 3910 | case TCOON: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3911 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3912 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3913 | dgap_tty_start(tty); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3914 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3915 | case TCOOFF: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3916 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3917 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3918 | dgap_tty_stop(tty); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3919 | return 0; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3920 | case TCION: |
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 | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3923 | /* Make the ld do it */ |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3924 | return -ENOIOCTLCMD; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3925 | case TCIOFF: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3926 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3927 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3928 | /* Make the ld do it */ |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3929 | return -ENOIOCTLCMD; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3930 | default: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3931 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3932 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3933 | return -EINVAL; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3934 | } |
| 3935 | |
| 3936 | case DIGI_GETA: |
| 3937 | /* get information for ditty */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3938 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3939 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Daeseok Youn | 4285c97 | 2014-07-11 19:23:34 +0900 | [diff] [blame] | 3940 | return dgap_tty_digigeta(ch, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3941 | |
| 3942 | case DIGI_SETAW: |
| 3943 | case DIGI_SETAF: |
| 3944 | |
| 3945 | /* set information for ditty */ |
| 3946 | if (cmd == (DIGI_SETAW)) { |
| 3947 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3948 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3949 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3950 | rc = dgap_wait_for_drain(tty); |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 3951 | if (rc) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3952 | return -EINTR; |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3953 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 3954 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 3955 | } else |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3956 | tty_ldisc_flush(tty); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3957 | /* fall thru */ |
| 3958 | |
| 3959 | case DIGI_SETA: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3960 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3961 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Daeseok Youn | ffc11c1 | 2014-07-11 19:22:58 +0900 | [diff] [blame] | 3962 | return dgap_tty_digiseta(ch, bd, un, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3963 | |
| 3964 | case DIGI_GEDELAY: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3965 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3966 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3967 | return dgap_tty_digigetedelay(tty, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3968 | |
| 3969 | case DIGI_SEDELAY: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3970 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3971 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Daeseok Youn | ccbe7e5 | 2014-07-11 19:23:54 +0900 | [diff] [blame] | 3972 | return dgap_tty_digisetedelay(ch, bd, un, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3973 | |
| 3974 | case DIGI_GETCUSTOMBAUD: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3975 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3976 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Daeseok Youn | 501bcd4 | 2014-07-11 19:24:14 +0900 | [diff] [blame] | 3977 | return dgap_tty_digigetcustombaud(ch, un, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3978 | |
| 3979 | case DIGI_SETCUSTOMBAUD: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3980 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3981 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Daeseok Youn | db6fc2d | 2014-07-11 19:24:34 +0900 | [diff] [blame] | 3982 | return dgap_tty_digisetcustombaud(ch, bd, un, uarg); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3983 | |
| 3984 | case DIGI_RESET_PORT: |
| 3985 | dgap_firmware_reset_port(ch); |
Daeseok Youn | ab6cdcb | 2014-07-11 19:22:39 +0900 | [diff] [blame] | 3986 | dgap_param(ch, bd, un->un_type); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3987 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3988 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3989 | return 0; |
| 3990 | |
| 3991 | default: |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 3992 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 3993 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3994 | |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 3995 | return -ENOIOCTLCMD; |
Mark Hounschell | a6792a3 | 2014-02-19 13:11:59 -0500 | [diff] [blame] | 3996 | } |
| 3997 | } |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 3998 | |
Daeseok Youn | 3f7fa94 | 2014-06-13 18:22:05 +0900 | [diff] [blame] | 3999 | static int dgap_alloc_flipbuf(struct board_t *brd) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4000 | { |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4001 | /* |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4002 | * allocate flip buffer for board. |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4003 | */ |
Daeseok Youn | 8148f37 | 2014-06-03 17:01:31 +0900 | [diff] [blame] | 4004 | brd->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL); |
| 4005 | if (!brd->flipbuf) |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4006 | return -ENOMEM; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4007 | |
Daeseok Youn | 8148f37 | 2014-06-03 17:01:31 +0900 | [diff] [blame] | 4008 | brd->flipflagbuf = kmalloc(MYFLIPLEN, GFP_KERNEL); |
| 4009 | if (!brd->flipflagbuf) { |
| 4010 | kfree(brd->flipbuf); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4011 | return -ENOMEM; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4012 | } |
| 4013 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4014 | return 0; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4015 | } |
| 4016 | |
Daeseok Youn | 91177d5 | 2014-06-13 18:23:15 +0900 | [diff] [blame] | 4017 | static void dgap_free_flipbuf(struct board_t *brd) |
| 4018 | { |
| 4019 | kfree(brd->flipbuf); |
| 4020 | kfree(brd->flipflagbuf); |
| 4021 | } |
| 4022 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4023 | /* |
| 4024 | * Create pr and tty device entries |
| 4025 | */ |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4026 | static int dgap_tty_register_ports(struct board_t *brd) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4027 | { |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4028 | struct channel_t *ch; |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4029 | int i; |
Daeseok Youn | 72d0f6f | 2014-06-02 14:08:24 +0900 | [diff] [blame] | 4030 | int ret; |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4031 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 4032 | brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports), |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4033 | GFP_KERNEL); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 4034 | if (!brd->serial_ports) |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4035 | return -ENOMEM; |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4036 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 4037 | brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports), |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4038 | GFP_KERNEL); |
Greg Kroah-Hartman | aec46bb | 2014-05-29 13:59:03 -0700 | [diff] [blame] | 4039 | if (!brd->printer_ports) { |
Daeseok Youn | 72d0f6f | 2014-06-02 14:08:24 +0900 | [diff] [blame] | 4040 | ret = -ENOMEM; |
| 4041 | goto free_serial_ports; |
Greg Kroah-Hartman | aec46bb | 2014-05-29 13:59:03 -0700 | [diff] [blame] | 4042 | } |
Daeseok Youn | 0ade4a3 | 2014-05-26 19:24:17 +0900 | [diff] [blame] | 4043 | |
Daeseok Youn | a66369a | 2014-05-26 19:24:47 +0900 | [diff] [blame] | 4044 | for (i = 0; i < brd->nasync; i++) { |
| 4045 | tty_port_init(&brd->serial_ports[i]); |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 4046 | tty_port_init(&brd->printer_ports[i]); |
Daeseok Youn | a66369a | 2014-05-26 19:24:47 +0900 | [diff] [blame] | 4047 | } |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4048 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4049 | ch = brd->channels[0]; |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4050 | for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4051 | |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4052 | struct device *classp; |
| 4053 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 4054 | classp = tty_port_register_device(&brd->serial_ports[i], |
Daeseok Youn | 219a40d | 2014-06-13 18:19:03 +0900 | [diff] [blame] | 4055 | brd->serial_driver, |
| 4056 | i, NULL); |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4057 | |
Daeseok Youn | 72d0f6f | 2014-06-02 14:08:24 +0900 | [diff] [blame] | 4058 | if (IS_ERR(classp)) { |
| 4059 | ret = PTR_ERR(classp); |
| 4060 | goto unregister_ttys; |
| 4061 | } |
| 4062 | |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4063 | dgap_create_tty_sysfs(&ch->ch_tun, classp); |
| 4064 | ch->ch_tun.un_sysfs = classp; |
| 4065 | |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 4066 | classp = tty_port_register_device(&brd->printer_ports[i], |
Daeseok Youn | 219a40d | 2014-06-13 18:19:03 +0900 | [diff] [blame] | 4067 | brd->print_driver, |
| 4068 | i, NULL); |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4069 | |
Daeseok Youn | 72d0f6f | 2014-06-02 14:08:24 +0900 | [diff] [blame] | 4070 | if (IS_ERR(classp)) { |
| 4071 | ret = PTR_ERR(classp); |
| 4072 | goto unregister_ttys; |
| 4073 | } |
| 4074 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4075 | dgap_create_tty_sysfs(&ch->ch_pun, classp); |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4076 | ch->ch_pun.un_sysfs = classp; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4077 | } |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4078 | dgap_create_ports_sysfiles(brd); |
Mark Hounschell | 6c8b84e | 2014-02-26 10:18:26 -0500 | [diff] [blame] | 4079 | |
| 4080 | return 0; |
Daeseok Youn | 72d0f6f | 2014-06-02 14:08:24 +0900 | [diff] [blame] | 4081 | |
| 4082 | unregister_ttys: |
| 4083 | while (i >= 0) { |
| 4084 | ch = brd->channels[i]; |
| 4085 | if (ch->ch_tun.un_sysfs) { |
| 4086 | dgap_remove_tty_sysfs(ch->ch_tun.un_sysfs); |
| 4087 | tty_unregister_device(brd->serial_driver, i); |
| 4088 | } |
| 4089 | |
| 4090 | if (ch->ch_pun.un_sysfs) { |
| 4091 | dgap_remove_tty_sysfs(ch->ch_pun.un_sysfs); |
| 4092 | tty_unregister_device(brd->print_driver, i); |
| 4093 | } |
| 4094 | i--; |
| 4095 | } |
| 4096 | |
| 4097 | for (i = 0; i < brd->nasync; i++) { |
| 4098 | tty_port_destroy(&brd->serial_ports[i]); |
| 4099 | tty_port_destroy(&brd->printer_ports[i]); |
| 4100 | } |
| 4101 | |
| 4102 | kfree(brd->printer_ports); |
| 4103 | brd->printer_ports = NULL; |
| 4104 | |
| 4105 | free_serial_ports: |
| 4106 | kfree(brd->serial_ports); |
| 4107 | brd->serial_ports = NULL; |
| 4108 | |
| 4109 | return ret; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4110 | } |
| 4111 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4112 | /* |
| 4113 | * Copies the BIOS code from the user to the board, |
| 4114 | * and starts the BIOS running. |
| 4115 | */ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4116 | 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] | 4117 | { |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 4118 | u8 __iomem *addr; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4119 | uint offset; |
| 4120 | int i; |
| 4121 | |
| 4122 | if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase) |
| 4123 | return; |
| 4124 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4125 | addr = brd->re_map_membase; |
| 4126 | |
| 4127 | /* |
| 4128 | * clear POST area |
| 4129 | */ |
| 4130 | for (i = 0; i < 16; i++) |
| 4131 | writeb(0, addr + POSTAREA + i); |
| 4132 | |
| 4133 | /* |
| 4134 | * Download bios |
| 4135 | */ |
| 4136 | offset = 0x1000; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4137 | memcpy_toio(addr + offset, ubios, len); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4138 | |
| 4139 | writel(0x0bf00401, addr); |
| 4140 | writel(0, (addr + 4)); |
| 4141 | |
| 4142 | /* Clear the reset, and change states. */ |
| 4143 | writeb(FEPCLR, brd->re_map_port); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4144 | } |
| 4145 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4146 | /* |
| 4147 | * Checks to see if the BIOS completed running on the card. |
| 4148 | */ |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4149 | static int dgap_test_bios(struct board_t *brd) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4150 | { |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 4151 | u8 __iomem *addr; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4152 | u16 word; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4153 | u16 err1; |
| 4154 | u16 err2; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4155 | |
| 4156 | if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase) |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4157 | return -EINVAL; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4158 | |
| 4159 | addr = brd->re_map_membase; |
| 4160 | word = readw(addr + POSTAREA); |
| 4161 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4162 | /* |
| 4163 | * It can take 5-6 seconds for a board to |
| 4164 | * pass the bios self test and post results. |
| 4165 | * Give it 10 seconds. |
| 4166 | */ |
| 4167 | brd->wait_for_bios = 0; |
| 4168 | while (brd->wait_for_bios < 1000) { |
| 4169 | /* Check to see if BIOS thinks board is good. (GD). */ |
Mark Hounschell | bd3e43e | 2014-03-12 12:50:55 -0400 | [diff] [blame] | 4170 | if (word == *(u16 *) "GD") |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4171 | return 0; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4172 | msleep_interruptible(10); |
| 4173 | brd->wait_for_bios++; |
| 4174 | word = readw(addr + POSTAREA); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4175 | } |
| 4176 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4177 | /* Gave up on board after too long of time taken */ |
| 4178 | err1 = readw(addr + SEQUENCE); |
| 4179 | err2 = readw(addr + ERROR); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 4180 | dev_warn(&brd->pdev->dev, "%s failed diagnostics. Error #(%x,%x).\n", |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4181 | brd->name, err1, err2); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4182 | brd->state = BOARD_FAILED; |
| 4183 | brd->dpastatus = BD_NOBIOS; |
Mark Hounschell | bd3e43e | 2014-03-12 12:50:55 -0400 | [diff] [blame] | 4184 | |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4185 | return -EIO; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4186 | } |
| 4187 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4188 | /* |
| 4189 | * Copies the FEP code from the user to the board, |
| 4190 | * and starts the FEP running. |
| 4191 | */ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4192 | 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] | 4193 | { |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 4194 | u8 __iomem *addr; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4195 | uint offset; |
| 4196 | |
| 4197 | if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase) |
| 4198 | return; |
| 4199 | |
| 4200 | addr = brd->re_map_membase; |
| 4201 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4202 | /* |
| 4203 | * Download FEP |
| 4204 | */ |
| 4205 | offset = 0x1000; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4206 | memcpy_toio(addr + offset, ufep, len); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4207 | |
| 4208 | /* |
| 4209 | * If board is a concentrator product, we need to give |
| 4210 | * it its config string describing how the concentrators look. |
| 4211 | */ |
| 4212 | if ((brd->type == PCX) || (brd->type == PEPC)) { |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4213 | u8 string[100]; |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4214 | u8 __iomem *config; |
| 4215 | u8 *xconfig; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4216 | int i = 0; |
| 4217 | |
| 4218 | xconfig = dgap_create_config_string(brd, string); |
| 4219 | |
| 4220 | /* Write string to board memory */ |
| 4221 | config = addr + CONFIG; |
| 4222 | for (; i < CONFIGSIZE; i++, config++, xconfig++) { |
| 4223 | writeb(*xconfig, config); |
| 4224 | if ((*xconfig & 0xff) == 0xff) |
| 4225 | break; |
| 4226 | } |
| 4227 | } |
| 4228 | |
| 4229 | writel(0xbfc01004, (addr + 0xc34)); |
| 4230 | writel(0x3, (addr + 0xc30)); |
| 4231 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4232 | } |
| 4233 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4234 | /* |
| 4235 | * Waits for the FEP to report thats its ready for us to use. |
| 4236 | */ |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4237 | static int dgap_test_fep(struct board_t *brd) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4238 | { |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 4239 | u8 __iomem *addr; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4240 | u16 word; |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4241 | u16 err1; |
| 4242 | u16 err2; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4243 | |
| 4244 | if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase) |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4245 | return -EINVAL; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4246 | |
| 4247 | addr = brd->re_map_membase; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4248 | word = readw(addr + FEPSTAT); |
| 4249 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4250 | /* |
| 4251 | * It can take 2-3 seconds for the FEP to |
| 4252 | * be up and running. Give it 5 secs. |
| 4253 | */ |
| 4254 | brd->wait_for_fep = 0; |
| 4255 | while (brd->wait_for_fep < 500) { |
| 4256 | /* Check to see if FEP is up and running now. */ |
| 4257 | if (word == *(u16 *) "OS") { |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4258 | /* |
| 4259 | * Check to see if the board can support FEP5+ commands. |
| 4260 | */ |
| 4261 | word = readw(addr + FEP5_PLUS); |
| 4262 | if (word == *(u16 *) "5A") |
| 4263 | brd->bd_flags |= BD_FEP5PLUS; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4264 | |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4265 | return 0; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4266 | } |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4267 | msleep_interruptible(10); |
| 4268 | brd->wait_for_fep++; |
| 4269 | word = readw(addr + FEPSTAT); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4270 | } |
| 4271 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4272 | /* Gave up on board after too long of time taken */ |
| 4273 | err1 = readw(addr + SEQUENCE); |
| 4274 | err2 = readw(addr + ERROR); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 4275 | dev_warn(&brd->pdev->dev, |
| 4276 | "FEPOS for %s not functioning. Error #(%x,%x).\n", |
| 4277 | brd->name, err1, err2); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4278 | brd->state = BOARD_FAILED; |
| 4279 | brd->dpastatus = BD_NOFEP; |
Mark Hounschell | bd3e43e | 2014-03-12 12:50:55 -0400 | [diff] [blame] | 4280 | |
Mark Hounschell | c9a1299 | 2014-03-28 09:30:15 -0400 | [diff] [blame] | 4281 | return -EIO; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4282 | } |
| 4283 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4284 | /* |
| 4285 | * Physically forces the FEP5 card to reset itself. |
| 4286 | */ |
| 4287 | static void dgap_do_reset_board(struct board_t *brd) |
| 4288 | { |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4289 | u8 check; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4290 | u32 check1; |
| 4291 | u32 check2; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 4292 | int i; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4293 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4294 | if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || |
| 4295 | !brd->re_map_membase || !brd->re_map_port) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4296 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4297 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4298 | /* FEPRST does not vary among supported boards */ |
| 4299 | writeb(FEPRST, brd->re_map_port); |
| 4300 | |
| 4301 | for (i = 0; i <= 1000; i++) { |
| 4302 | check = readb(brd->re_map_port) & 0xe; |
| 4303 | if (check == FEPRST) |
| 4304 | break; |
| 4305 | udelay(10); |
| 4306 | |
| 4307 | } |
| 4308 | if (i > 1000) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 4309 | dev_warn(&brd->pdev->dev, |
| 4310 | "dgap: Board not resetting... Failing board.\n"); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4311 | brd->state = BOARD_FAILED; |
| 4312 | brd->dpastatus = BD_NOFEP; |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4313 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4314 | } |
| 4315 | |
| 4316 | /* |
| 4317 | * Make sure there really is memory out there. |
| 4318 | */ |
| 4319 | writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM)); |
| 4320 | writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM)); |
| 4321 | check1 = readl(brd->re_map_membase + LOWMEM); |
| 4322 | check2 = readl(brd->re_map_membase + HIGHMEM); |
| 4323 | |
| 4324 | if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 4325 | dev_warn(&brd->pdev->dev, |
| 4326 | "No memory at %p for board.\n", |
| 4327 | brd->re_map_membase); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4328 | brd->state = BOARD_FAILED; |
| 4329 | brd->dpastatus = BD_NOFEP; |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4330 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4331 | } |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4332 | } |
| 4333 | |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4334 | #ifdef DIGI_CONCENTRATORS_SUPPORTED |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4335 | /* |
| 4336 | * Sends a concentrator image into the FEP5 board. |
| 4337 | */ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4338 | 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] | 4339 | { |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 4340 | char __iomem *vaddr; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 4341 | u16 offset; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4342 | struct downld_t *to_dp; |
| 4343 | |
| 4344 | if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase) |
| 4345 | return; |
| 4346 | |
| 4347 | vaddr = brd->re_map_membase; |
| 4348 | |
| 4349 | offset = readw((u16 *) (vaddr + DOWNREQ)); |
| 4350 | to_dp = (struct downld_t *) (vaddr + (int) offset); |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4351 | memcpy_toio(to_dp, uaddr, len); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4352 | |
| 4353 | /* Tell card we have data for it */ |
| 4354 | writew(0, vaddr + (DOWNREQ)); |
| 4355 | |
| 4356 | brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS; |
| 4357 | } |
Mark Hounschell | b28ec88 | 2014-02-20 08:48:48 -0500 | [diff] [blame] | 4358 | #endif |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4359 | |
| 4360 | #define EXPANSION_ROM_SIZE (64 * 1024) |
| 4361 | #define FEP5_ROM_MAGIC (0xFEFFFFFF) |
| 4362 | |
| 4363 | static void dgap_get_vpd(struct board_t *brd) |
| 4364 | { |
| 4365 | u32 magic; |
| 4366 | u32 base_offset; |
| 4367 | u16 rom_offset; |
| 4368 | u16 vpd_offset; |
| 4369 | u16 image_length; |
| 4370 | u16 i; |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4371 | u8 byte1; |
| 4372 | u8 byte2; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4373 | |
| 4374 | /* |
| 4375 | * Poke the magic number at the PCI Rom Address location. |
| 4376 | * If VPD is supported, the value read from that address |
| 4377 | * will be non-zero. |
| 4378 | */ |
| 4379 | magic = FEP5_ROM_MAGIC; |
| 4380 | pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic); |
| 4381 | pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic); |
| 4382 | |
| 4383 | /* VPD not supported, bail */ |
| 4384 | if (!magic) |
| 4385 | return; |
| 4386 | |
| 4387 | /* |
| 4388 | * To get to the OTPROM memory, we have to send the boards base |
| 4389 | * address or'ed with 1 into the PCI Rom Address location. |
| 4390 | */ |
| 4391 | magic = brd->membase | 0x01; |
| 4392 | pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic); |
| 4393 | pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic); |
| 4394 | |
| 4395 | byte1 = readb(brd->re_map_membase); |
| 4396 | byte2 = readb(brd->re_map_membase + 1); |
| 4397 | |
| 4398 | /* |
| 4399 | * If the board correctly swapped to the OTPROM memory, |
| 4400 | * the first 2 bytes (header) should be 0x55, 0xAA |
| 4401 | */ |
| 4402 | if (byte1 == 0x55 && byte2 == 0xAA) { |
| 4403 | |
| 4404 | base_offset = 0; |
| 4405 | |
| 4406 | /* |
| 4407 | * We have to run through all the OTPROM memory looking |
| 4408 | * for the VPD offset. |
| 4409 | */ |
| 4410 | while (base_offset <= EXPANSION_ROM_SIZE) { |
| 4411 | |
| 4412 | /* |
| 4413 | * Lots of magic numbers here. |
| 4414 | * |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 4415 | * The VPD offset is located inside the ROM Data |
| 4416 | * Structure. |
| 4417 | * |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4418 | * We also have to remember the length of each |
| 4419 | * ROM Data Structure, so we can "hop" to the next |
| 4420 | * entry if the VPD isn't in the current |
| 4421 | * ROM Data Structure. |
| 4422 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 4423 | rom_offset = readw(brd->re_map_membase + |
| 4424 | base_offset + 0x18); |
| 4425 | image_length = readw(brd->re_map_membase + |
| 4426 | rom_offset + 0x10) * 512; |
| 4427 | vpd_offset = readw(brd->re_map_membase + |
| 4428 | rom_offset + 0x08); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4429 | |
| 4430 | /* Found the VPD entry */ |
| 4431 | if (vpd_offset) |
| 4432 | break; |
| 4433 | |
| 4434 | /* We didn't find a VPD entry, go to next ROM entry. */ |
| 4435 | base_offset += image_length; |
| 4436 | |
| 4437 | byte1 = readb(brd->re_map_membase + base_offset); |
| 4438 | byte2 = readb(brd->re_map_membase + base_offset + 1); |
| 4439 | |
| 4440 | /* |
| 4441 | * If the new ROM offset doesn't have 0x55, 0xAA |
| 4442 | * as its header, we have run out of ROM. |
| 4443 | */ |
| 4444 | if (byte1 != 0x55 || byte2 != 0xAA) |
| 4445 | break; |
| 4446 | } |
| 4447 | |
| 4448 | /* |
| 4449 | * If we have a VPD offset, then mark the board |
| 4450 | * as having a valid VPD, and copy VPDSIZE (512) bytes of |
| 4451 | * that VPD to the buffer we have in our board structure. |
| 4452 | */ |
| 4453 | if (vpd_offset) { |
| 4454 | brd->bd_flags |= BD_HAS_VPD; |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 4455 | for (i = 0; i < VPDSIZE; i++) { |
| 4456 | brd->vpd[i] = readb(brd->re_map_membase + |
| 4457 | vpd_offset + i); |
| 4458 | } |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4459 | } |
| 4460 | } |
| 4461 | |
| 4462 | /* |
| 4463 | * We MUST poke the magic number at the PCI Rom Address location again. |
| 4464 | * This makes the card report the regular board memory back to us, |
| 4465 | * rather than the OTPROM memory. |
| 4466 | */ |
| 4467 | magic = FEP5_ROM_MAGIC; |
| 4468 | pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic); |
| 4469 | } |
| 4470 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4471 | /* |
| 4472 | * Our board poller function. |
| 4473 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 4474 | static void dgap_poll_tasklet(unsigned long data) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4475 | { |
| 4476 | struct board_t *bd = (struct board_t *) data; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4477 | ulong lock_flags; |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 4478 | char __iomem *vaddr; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4479 | u16 head, tail; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4480 | |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4481 | if (!bd || (bd->magic != DGAP_BOARD_MAGIC)) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4482 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4483 | |
| 4484 | if (bd->inhibit_poller) |
| 4485 | return; |
| 4486 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4487 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4488 | |
| 4489 | vaddr = bd->re_map_membase; |
| 4490 | |
| 4491 | /* |
| 4492 | * If board is ready, parse deeper to see if there is anything to do. |
| 4493 | */ |
| 4494 | if (bd->state == BOARD_READY) { |
| 4495 | |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4496 | struct ev_t __iomem *eaddr; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4497 | |
| 4498 | if (!bd->re_map_membase) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4499 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4500 | return; |
| 4501 | } |
| 4502 | if (!bd->re_map_port) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4503 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4504 | return; |
| 4505 | } |
| 4506 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4507 | if (!bd->nasync) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4508 | goto out; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4509 | |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4510 | eaddr = (struct ev_t __iomem *) (vaddr + EVBUF); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4511 | |
| 4512 | /* Get our head and tail */ |
| 4513 | head = readw(&(eaddr->ev_head)); |
| 4514 | tail = readw(&(eaddr->ev_tail)); |
| 4515 | |
| 4516 | /* |
| 4517 | * If there is an event pending. Go service it. |
| 4518 | */ |
| 4519 | if (head != tail) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4520 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4521 | dgap_event(bd); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4522 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4523 | } |
| 4524 | |
| 4525 | out: |
| 4526 | /* |
| 4527 | * If board is doing interrupts, ACK the interrupt. |
| 4528 | */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4529 | if (bd && bd->intr_running) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4530 | readb(bd->re_map_port + 2); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4531 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4532 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4533 | return; |
| 4534 | } |
| 4535 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 4536 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4537 | } |
| 4538 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4539 | /*======================================================================= |
| 4540 | * |
| 4541 | * dgap_cmdb - Sends a 2 byte command to the FEP. |
| 4542 | * |
| 4543 | * ch - Pointer to channel structure. |
| 4544 | * cmd - Command to be sent. |
| 4545 | * byte1 - Integer containing first byte to be sent. |
| 4546 | * byte2 - Integer containing second byte to be sent. |
| 4547 | * ncmds - Wait until ncmds or fewer cmds are left |
| 4548 | * in the cmd buffer before returning. |
| 4549 | * |
| 4550 | *=======================================================================*/ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4551 | static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1, |
| 4552 | u8 byte2, uint ncmds) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4553 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4554 | char __iomem *vaddr; |
Mark Hounschell | 6a30cdd | 2014-04-23 16:43:21 -0400 | [diff] [blame] | 4555 | struct __iomem cm_t *cm_addr; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4556 | uint count; |
| 4557 | uint n; |
| 4558 | u16 head; |
| 4559 | u16 tail; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4560 | |
| 4561 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 4562 | return; |
| 4563 | |
| 4564 | /* |
| 4565 | * Check if board is still alive. |
| 4566 | */ |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4567 | if (ch->ch_bd->state == BOARD_FAILED) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4568 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4569 | |
| 4570 | /* |
| 4571 | * Make sure the pointers are in range before |
| 4572 | * writing to the FEP memory. |
| 4573 | */ |
| 4574 | vaddr = ch->ch_bd->re_map_membase; |
| 4575 | |
| 4576 | if (!vaddr) |
| 4577 | return; |
| 4578 | |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4579 | cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4580 | head = readw(&(cm_addr->cm_head)); |
| 4581 | |
| 4582 | /* |
| 4583 | * Forget it if pointers out of range. |
| 4584 | */ |
| 4585 | if (head >= (CMDMAX - CMDSTART) || (head & 03)) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4586 | ch->ch_bd->state = BOARD_FAILED; |
| 4587 | return; |
| 4588 | } |
| 4589 | |
| 4590 | /* |
| 4591 | * Put the data in the circular command buffer. |
| 4592 | */ |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4593 | writeb(cmd, (vaddr + head + CMDSTART + 0)); |
| 4594 | writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1)); |
| 4595 | writeb(byte1, (vaddr + head + CMDSTART + 2)); |
| 4596 | writeb(byte2, (vaddr + head + CMDSTART + 3)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4597 | |
| 4598 | head = (head + 4) & (CMDMAX - CMDSTART - 4); |
| 4599 | |
| 4600 | writew(head, &(cm_addr->cm_head)); |
| 4601 | |
| 4602 | /* |
| 4603 | * Wait if necessary before updating the head |
| 4604 | * pointer to limit the number of outstanding |
| 4605 | * commands to the FEP. If the time spent waiting |
| 4606 | * is outlandish, declare the FEP dead. |
| 4607 | */ |
| 4608 | for (count = dgap_count ;;) { |
| 4609 | |
| 4610 | head = readw(&(cm_addr->cm_head)); |
| 4611 | tail = readw(&(cm_addr->cm_tail)); |
| 4612 | |
| 4613 | n = (head - tail) & (CMDMAX - CMDSTART - 4); |
| 4614 | |
| 4615 | if (n <= ncmds * sizeof(struct cm_t)) |
| 4616 | break; |
| 4617 | |
| 4618 | if (--count == 0) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4619 | ch->ch_bd->state = BOARD_FAILED; |
| 4620 | return; |
| 4621 | } |
| 4622 | udelay(10); |
| 4623 | } |
| 4624 | } |
| 4625 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4626 | /*======================================================================= |
| 4627 | * |
| 4628 | * dgap_cmdw - Sends a 1 word command to the FEP. |
| 4629 | * |
| 4630 | * ch - Pointer to channel structure. |
| 4631 | * cmd - Command to be sent. |
| 4632 | * word - Integer containing word to be sent. |
| 4633 | * ncmds - Wait until ncmds or fewer cmds are left |
| 4634 | * in the cmd buffer before returning. |
| 4635 | * |
| 4636 | *=======================================================================*/ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 4637 | 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] | 4638 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4639 | char __iomem *vaddr; |
Mark Hounschell | 6a30cdd | 2014-04-23 16:43:21 -0400 | [diff] [blame] | 4640 | struct __iomem cm_t *cm_addr; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4641 | uint count; |
| 4642 | uint n; |
| 4643 | u16 head; |
| 4644 | u16 tail; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4645 | |
| 4646 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 4647 | return; |
| 4648 | |
| 4649 | /* |
| 4650 | * Check if board is still alive. |
| 4651 | */ |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4652 | if (ch->ch_bd->state == BOARD_FAILED) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4653 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4654 | |
| 4655 | /* |
| 4656 | * Make sure the pointers are in range before |
| 4657 | * writing to the FEP memory. |
| 4658 | */ |
| 4659 | vaddr = ch->ch_bd->re_map_membase; |
| 4660 | if (!vaddr) |
| 4661 | return; |
| 4662 | |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4663 | cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4664 | head = readw(&(cm_addr->cm_head)); |
| 4665 | |
| 4666 | /* |
| 4667 | * Forget it if pointers out of range. |
| 4668 | */ |
| 4669 | if (head >= (CMDMAX - CMDSTART) || (head & 03)) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4670 | ch->ch_bd->state = BOARD_FAILED; |
| 4671 | return; |
| 4672 | } |
| 4673 | |
| 4674 | /* |
| 4675 | * Put the data in the circular command buffer. |
| 4676 | */ |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4677 | writeb(cmd, (vaddr + head + CMDSTART + 0)); |
| 4678 | writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1)); |
| 4679 | writew((u16) word, (vaddr + head + CMDSTART + 2)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4680 | |
| 4681 | head = (head + 4) & (CMDMAX - CMDSTART - 4); |
| 4682 | |
| 4683 | writew(head, &(cm_addr->cm_head)); |
| 4684 | |
| 4685 | /* |
| 4686 | * Wait if necessary before updating the head |
| 4687 | * pointer to limit the number of outstanding |
| 4688 | * commands to the FEP. If the time spent waiting |
| 4689 | * is outlandish, declare the FEP dead. |
| 4690 | */ |
| 4691 | for (count = dgap_count ;;) { |
| 4692 | |
| 4693 | head = readw(&(cm_addr->cm_head)); |
| 4694 | tail = readw(&(cm_addr->cm_tail)); |
| 4695 | |
| 4696 | n = (head - tail) & (CMDMAX - CMDSTART - 4); |
| 4697 | |
| 4698 | if (n <= ncmds * sizeof(struct cm_t)) |
| 4699 | break; |
| 4700 | |
| 4701 | if (--count == 0) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4702 | ch->ch_bd->state = BOARD_FAILED; |
| 4703 | return; |
| 4704 | } |
| 4705 | udelay(10); |
| 4706 | } |
| 4707 | } |
| 4708 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4709 | /*======================================================================= |
| 4710 | * |
| 4711 | * dgap_cmdw_ext - Sends a extended word command to the FEP. |
| 4712 | * |
| 4713 | * ch - Pointer to channel structure. |
| 4714 | * cmd - Command to be sent. |
| 4715 | * word - Integer containing word to be sent. |
| 4716 | * ncmds - Wait until ncmds or fewer cmds are left |
| 4717 | * in the cmd buffer before returning. |
| 4718 | * |
| 4719 | *=======================================================================*/ |
| 4720 | static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds) |
| 4721 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4722 | char __iomem *vaddr; |
Mark Hounschell | 6a30cdd | 2014-04-23 16:43:21 -0400 | [diff] [blame] | 4723 | struct __iomem cm_t *cm_addr; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4724 | uint count; |
| 4725 | uint n; |
| 4726 | u16 head; |
| 4727 | u16 tail; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4728 | |
| 4729 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 4730 | return; |
| 4731 | |
| 4732 | /* |
| 4733 | * Check if board is still alive. |
| 4734 | */ |
Mark Hounschell | 31960c1 | 2014-02-28 12:42:08 -0500 | [diff] [blame] | 4735 | if (ch->ch_bd->state == BOARD_FAILED) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4736 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4737 | |
| 4738 | /* |
| 4739 | * Make sure the pointers are in range before |
| 4740 | * writing to the FEP memory. |
| 4741 | */ |
| 4742 | vaddr = ch->ch_bd->re_map_membase; |
| 4743 | if (!vaddr) |
| 4744 | return; |
| 4745 | |
Mark Hounschell | 630b2ab | 2014-04-24 09:22:12 -0400 | [diff] [blame] | 4746 | cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4747 | head = readw(&(cm_addr->cm_head)); |
| 4748 | |
| 4749 | /* |
| 4750 | * Forget it if pointers out of range. |
| 4751 | */ |
| 4752 | if (head >= (CMDMAX - CMDSTART) || (head & 03)) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4753 | ch->ch_bd->state = BOARD_FAILED; |
| 4754 | return; |
| 4755 | } |
| 4756 | |
| 4757 | /* |
| 4758 | * Put the data in the circular command buffer. |
| 4759 | */ |
| 4760 | |
| 4761 | /* 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] | 4762 | writeb((u8) 0xff, (vaddr + head + CMDSTART + 0)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4763 | |
Mark Hounschell | 630b2ab | 2014-04-24 09:22:12 -0400 | [diff] [blame] | 4764 | writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1)); |
| 4765 | writew((u16) cmd, (vaddr + head + CMDSTART + 2)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4766 | |
| 4767 | /* |
| 4768 | * If the second part of the command won't fit, |
| 4769 | * put it at the beginning of the circular buffer. |
| 4770 | */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4771 | if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03))) |
Mark Hounschell | 630b2ab | 2014-04-24 09:22:12 -0400 | [diff] [blame] | 4772 | writew((u16) word, (vaddr + CMDSTART)); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4773 | else |
Mark Hounschell | 630b2ab | 2014-04-24 09:22:12 -0400 | [diff] [blame] | 4774 | writew((u16) word, (vaddr + head + CMDSTART + 4)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4775 | |
| 4776 | head = (head + 8) & (CMDMAX - CMDSTART - 4); |
| 4777 | |
| 4778 | writew(head, &(cm_addr->cm_head)); |
| 4779 | |
| 4780 | /* |
| 4781 | * Wait if necessary before updating the head |
| 4782 | * pointer to limit the number of outstanding |
| 4783 | * commands to the FEP. If the time spent waiting |
| 4784 | * is outlandish, declare the FEP dead. |
| 4785 | */ |
| 4786 | for (count = dgap_count ;;) { |
| 4787 | |
| 4788 | head = readw(&(cm_addr->cm_head)); |
| 4789 | tail = readw(&(cm_addr->cm_tail)); |
| 4790 | |
| 4791 | n = (head - tail) & (CMDMAX - CMDSTART - 4); |
| 4792 | |
| 4793 | if (n <= ncmds * sizeof(struct cm_t)) |
| 4794 | break; |
| 4795 | |
| 4796 | if (--count == 0) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4797 | ch->ch_bd->state = BOARD_FAILED; |
| 4798 | return; |
| 4799 | } |
| 4800 | udelay(10); |
| 4801 | } |
| 4802 | } |
| 4803 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4804 | /*======================================================================= |
| 4805 | * |
| 4806 | * dgap_wmove - Write data to FEP buffer. |
| 4807 | * |
| 4808 | * ch - Pointer to channel structure. |
| 4809 | * buf - Poiter to characters to be moved. |
| 4810 | * cnt - Number of characters to move. |
| 4811 | * |
| 4812 | *=======================================================================*/ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 4813 | static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4814 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4815 | int n; |
| 4816 | char __iomem *taddr; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 4817 | struct bs_t __iomem *bs; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4818 | u16 head; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4819 | |
| 4820 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 4821 | return; |
| 4822 | |
| 4823 | /* |
| 4824 | * Check parameters. |
| 4825 | */ |
| 4826 | bs = ch->ch_bs; |
| 4827 | head = readw(&(bs->tx_head)); |
| 4828 | |
| 4829 | /* |
| 4830 | * If pointers are out of range, just return. |
| 4831 | */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4832 | if ((cnt > ch->ch_tsize) || |
| 4833 | (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4834 | return; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4835 | |
| 4836 | /* |
| 4837 | * If the write wraps over the top of the circular buffer, |
| 4838 | * move the portion up to the wrap point, and reset the |
| 4839 | * pointers to the bottom. |
| 4840 | */ |
| 4841 | n = ch->ch_tstart + ch->ch_tsize - head; |
| 4842 | |
| 4843 | if (cnt >= n) { |
| 4844 | cnt -= n; |
| 4845 | taddr = ch->ch_taddr + head; |
| 4846 | memcpy_toio(taddr, buf, n); |
| 4847 | head = ch->ch_tstart; |
| 4848 | buf += n; |
| 4849 | } |
| 4850 | |
| 4851 | /* |
| 4852 | * Move rest of data. |
| 4853 | */ |
| 4854 | taddr = ch->ch_taddr + head; |
| 4855 | n = cnt; |
| 4856 | memcpy_toio(taddr, buf, n); |
| 4857 | head += cnt; |
| 4858 | |
| 4859 | writew(head, &(bs->tx_head)); |
| 4860 | } |
| 4861 | |
| 4862 | /* |
| 4863 | * Retrives the current custom baud rate from FEP memory, |
| 4864 | * and returns it back to the user. |
| 4865 | * Returns 0 on error. |
| 4866 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 4867 | static uint dgap_get_custom_baud(struct channel_t *ch) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4868 | { |
Mark Hounschell | b6339d0 | 2014-04-23 15:43:07 -0400 | [diff] [blame] | 4869 | u8 __iomem *vaddr; |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 4870 | ulong offset; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 4871 | uint value; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4872 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4873 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4874 | return 0; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4875 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 4876 | if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4877 | return 0; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4878 | |
| 4879 | if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS)) |
| 4880 | return 0; |
| 4881 | |
| 4882 | vaddr = ch->ch_bd->re_map_membase; |
| 4883 | |
| 4884 | if (!vaddr) |
| 4885 | return 0; |
| 4886 | |
| 4887 | /* |
| 4888 | * Go get from fep mem, what the fep |
| 4889 | * believes the custom baud rate is. |
| 4890 | */ |
Pascal COMBES | 77870a1 | 2014-05-24 15:58:09 +0200 | [diff] [blame] | 4891 | offset = (ioread16(vaddr + ECS_SEG) << 4) + (ch->ch_portnum * 0x28) |
| 4892 | + LINE_SPEED; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4893 | |
| 4894 | value = readw(vaddr + offset); |
| 4895 | return value; |
| 4896 | } |
| 4897 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4898 | /* |
| 4899 | * Calls the firmware to reset this channel. |
| 4900 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 4901 | static void dgap_firmware_reset_port(struct channel_t *ch) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4902 | { |
| 4903 | dgap_cmdb(ch, CHRESET, 0, 0, 0); |
| 4904 | |
| 4905 | /* |
| 4906 | * Now that the channel is reset, we need to make sure |
| 4907 | * all the current settings get reapplied to the port |
| 4908 | * in the firmware. |
| 4909 | * |
| 4910 | * So we will set the driver's cache of firmware |
| 4911 | * settings all to 0, and then call param. |
| 4912 | */ |
| 4913 | ch->ch_fepiflag = 0; |
| 4914 | ch->ch_fepcflag = 0; |
| 4915 | ch->ch_fepoflag = 0; |
| 4916 | ch->ch_fepstartc = 0; |
| 4917 | ch->ch_fepstopc = 0; |
| 4918 | ch->ch_fepastartc = 0; |
| 4919 | ch->ch_fepastopc = 0; |
| 4920 | ch->ch_mostat = 0; |
| 4921 | ch->ch_hflow = 0; |
| 4922 | } |
| 4923 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4924 | /*======================================================================= |
| 4925 | * |
| 4926 | * dgap_param - Set Digi parameters. |
| 4927 | * |
| 4928 | * struct tty_struct * - TTY for port. |
| 4929 | * |
| 4930 | *=======================================================================*/ |
Daeseok Youn | ab6cdcb | 2014-07-11 19:22:39 +0900 | [diff] [blame] | 4931 | static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4932 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 4933 | u16 head; |
| 4934 | u16 cflag; |
| 4935 | u16 iflag; |
| 4936 | u8 mval; |
| 4937 | u8 hflow; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4938 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4939 | /* |
| 4940 | * If baud rate is zero, flush queues, and set mval to drop DTR. |
| 4941 | */ |
| 4942 | if ((ch->ch_c_cflag & (CBAUD)) == 0) { |
| 4943 | |
| 4944 | /* flush rx */ |
| 4945 | head = readw(&(ch->ch_bs->rx_head)); |
| 4946 | writew(head, &(ch->ch_bs->rx_tail)); |
| 4947 | |
| 4948 | /* flush tx */ |
| 4949 | head = readw(&(ch->ch_bs->tx_head)); |
| 4950 | writew(head, &(ch->ch_bs->tx_tail)); |
| 4951 | |
| 4952 | ch->ch_flags |= (CH_BAUD0); |
| 4953 | |
| 4954 | /* Drop RTS and DTR */ |
| 4955 | ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch)); |
| 4956 | mval = D_DTR(ch) | D_RTS(ch); |
| 4957 | ch->ch_baud_info = 0; |
| 4958 | |
| 4959 | } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) { |
| 4960 | /* |
| 4961 | * Tell the fep to do the command |
| 4962 | */ |
| 4963 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4964 | dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0); |
| 4965 | |
| 4966 | /* |
| 4967 | * Now go get from fep mem, what the fep |
| 4968 | * believes the custom baud rate is. |
| 4969 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 4970 | ch->ch_custom_speed = dgap_get_custom_baud(ch); |
| 4971 | ch->ch_baud_info = ch->ch_custom_speed; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4972 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 4973 | /* Handle transition from B0 */ |
| 4974 | if (ch->ch_flags & CH_BAUD0) { |
| 4975 | ch->ch_flags &= ~(CH_BAUD0); |
| 4976 | ch->ch_mval |= (D_RTS(ch)|D_DTR(ch)); |
| 4977 | } |
| 4978 | mval = D_DTR(ch) | D_RTS(ch); |
| 4979 | |
| 4980 | } else { |
| 4981 | /* |
| 4982 | * Set baud rate, character size, and parity. |
| 4983 | */ |
| 4984 | |
| 4985 | |
| 4986 | int iindex = 0; |
| 4987 | int jindex = 0; |
| 4988 | int baud = 0; |
| 4989 | |
| 4990 | ulong bauds[4][16] = { |
| 4991 | { /* slowbaud */ |
| 4992 | 0, 50, 75, 110, |
| 4993 | 134, 150, 200, 300, |
| 4994 | 600, 1200, 1800, 2400, |
| 4995 | 4800, 9600, 19200, 38400 }, |
| 4996 | { /* slowbaud & CBAUDEX */ |
| 4997 | 0, 57600, 115200, 230400, |
| 4998 | 460800, 150, 200, 921600, |
| 4999 | 600, 1200, 1800, 2400, |
| 5000 | 4800, 9600, 19200, 38400 }, |
| 5001 | { /* fastbaud */ |
| 5002 | 0, 57600, 76800, 115200, |
| 5003 | 14400, 57600, 230400, 76800, |
| 5004 | 115200, 230400, 28800, 460800, |
| 5005 | 921600, 9600, 19200, 38400 }, |
| 5006 | { /* fastbaud & CBAUDEX */ |
| 5007 | 0, 57600, 115200, 230400, |
| 5008 | 460800, 150, 200, 921600, |
| 5009 | 600, 1200, 1800, 2400, |
| 5010 | 4800, 9600, 19200, 38400 } |
| 5011 | }; |
| 5012 | |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 5013 | /* |
| 5014 | * Only use the TXPrint baud rate if the |
| 5015 | * terminal unit is NOT open |
| 5016 | */ |
| 5017 | if (!(ch->ch_tun.un_flags & UN_ISOPEN) && |
Daeseok Youn | ab6cdcb | 2014-07-11 19:22:39 +0900 | [diff] [blame] | 5018 | un_type == DGAP_PRINT) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5019 | baud = C_BAUD(ch->ch_pun.un_tty) & 0xff; |
| 5020 | else |
| 5021 | baud = C_BAUD(ch->ch_tun.un_tty) & 0xff; |
| 5022 | |
| 5023 | if (ch->ch_c_cflag & CBAUDEX) |
| 5024 | iindex = 1; |
| 5025 | |
| 5026 | if (ch->ch_digi.digi_flags & DIGI_FAST) |
| 5027 | iindex += 2; |
| 5028 | |
| 5029 | jindex = baud; |
| 5030 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5031 | if ((iindex >= 0) && (iindex < 4) && |
| 5032 | (jindex >= 0) && (jindex < 16)) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5033 | baud = bauds[iindex][jindex]; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5034 | else |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5035 | baud = 0; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5036 | |
| 5037 | if (baud == 0) |
| 5038 | baud = 9600; |
| 5039 | |
| 5040 | ch->ch_baud_info = baud; |
| 5041 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5042 | /* |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 5043 | * CBAUD has bit position 0x1000 set these days to |
| 5044 | * indicate Linux baud rate remap. |
| 5045 | * We use a different bit assignment for high speed. |
| 5046 | * Clear this bit out while grabbing the parts of |
| 5047 | * "cflag" we want. |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5048 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 5049 | cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | |
| 5050 | CSTOPB | CSIZE); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5051 | |
| 5052 | /* |
| 5053 | * HUPCL bit is used by FEP to indicate fast baud |
| 5054 | * table is to be used. |
| 5055 | */ |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 5056 | if ((ch->ch_digi.digi_flags & DIGI_FAST) || |
| 5057 | (ch->ch_c_cflag & CBAUDEX)) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5058 | cflag |= HUPCL; |
| 5059 | |
Mark Hounschell | af5b80b | 2014-03-04 16:03:11 -0500 | [diff] [blame] | 5060 | if ((ch->ch_c_cflag & CBAUDEX) && |
| 5061 | !(ch->ch_digi.digi_flags & DIGI_FAST)) { |
| 5062 | /* |
| 5063 | * The below code is trying to guarantee that only |
| 5064 | * baud rates 115200, 230400, 460800, 921600 are |
| 5065 | * remapped. We use exclusive or because the various |
| 5066 | * baud rates share common bit positions and therefore |
| 5067 | * can't be tested for easily. |
| 5068 | */ |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5069 | tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX; |
| 5070 | int baudpart = 0; |
| 5071 | |
Mark Hounschell | 8a2c9c4 | 2014-03-05 15:54:50 -0500 | [diff] [blame] | 5072 | /* |
| 5073 | * Map high speed requests to index |
| 5074 | * into FEP's baud table |
| 5075 | */ |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5076 | switch (tcflag) { |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 5077 | case B57600: |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5078 | baudpart = 1; |
| 5079 | break; |
| 5080 | #ifdef B76800 |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 5081 | case B76800: |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5082 | baudpart = 2; |
| 5083 | break; |
| 5084 | #endif |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 5085 | case B115200: |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5086 | baudpart = 3; |
| 5087 | break; |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 5088 | case B230400: |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5089 | baudpart = 9; |
| 5090 | break; |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 5091 | case B460800: |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5092 | baudpart = 11; |
| 5093 | break; |
| 5094 | #ifdef B921600 |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 5095 | case B921600: |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5096 | baudpart = 12; |
| 5097 | break; |
| 5098 | #endif |
| 5099 | default: |
| 5100 | baudpart = 0; |
| 5101 | } |
| 5102 | |
| 5103 | if (baudpart) |
| 5104 | cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart; |
| 5105 | } |
| 5106 | |
| 5107 | cflag &= 0xffff; |
| 5108 | |
| 5109 | if (cflag != ch->ch_fepcflag) { |
| 5110 | ch->ch_fepcflag = (u16) (cflag & 0xffff); |
| 5111 | |
Mark Hounschell | 8fc324e | 2014-03-05 15:54:51 -0500 | [diff] [blame] | 5112 | /* |
| 5113 | * Okay to have channel and board |
| 5114 | * locks held calling this |
| 5115 | */ |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5116 | dgap_cmdw(ch, SCFLAG, (u16) cflag, 0); |
| 5117 | } |
| 5118 | |
| 5119 | /* Handle transition from B0 */ |
| 5120 | if (ch->ch_flags & CH_BAUD0) { |
| 5121 | ch->ch_flags &= ~(CH_BAUD0); |
| 5122 | ch->ch_mval |= (D_RTS(ch)|D_DTR(ch)); |
| 5123 | } |
| 5124 | mval = D_DTR(ch) | D_RTS(ch); |
| 5125 | } |
| 5126 | |
| 5127 | /* |
| 5128 | * Get input flags. |
| 5129 | */ |
Mark Hounschell | 8fc324e | 2014-03-05 15:54:51 -0500 | [diff] [blame] | 5130 | iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | |
| 5131 | INPCK | ISTRIP | IXON | IXANY | IXOFF); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5132 | |
Mark Hounschell | 8fc324e | 2014-03-05 15:54:51 -0500 | [diff] [blame] | 5133 | if ((ch->ch_startc == _POSIX_VDISABLE) || |
| 5134 | (ch->ch_stopc == _POSIX_VDISABLE)) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5135 | iflag &= ~(IXON | IXOFF); |
| 5136 | ch->ch_c_iflag &= ~(IXON | IXOFF); |
| 5137 | } |
| 5138 | |
| 5139 | /* |
| 5140 | * Only the IBM Xr card can switch between |
| 5141 | * 232 and 422 modes on the fly |
| 5142 | */ |
Mark Hounschell | 2f60b33 | 2014-03-04 16:03:12 -0500 | [diff] [blame] | 5143 | if (bd->device == PCI_DEV_XR_IBM_DID) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5144 | if (ch->ch_digi.digi_flags & DIGI_422) |
| 5145 | dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0); |
| 5146 | else |
| 5147 | dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0); |
| 5148 | } |
| 5149 | |
| 5150 | if (ch->ch_digi.digi_flags & DIGI_ALTPIN) |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 5151 | iflag |= IALTPIN; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5152 | |
| 5153 | if (iflag != ch->ch_fepiflag) { |
| 5154 | ch->ch_fepiflag = iflag; |
| 5155 | |
| 5156 | /* Okay to have channel and board locks held calling this */ |
| 5157 | dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0); |
| 5158 | } |
| 5159 | |
| 5160 | /* |
| 5161 | * Select hardware handshaking. |
| 5162 | */ |
| 5163 | hflow = 0; |
| 5164 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5165 | if (ch->ch_c_cflag & CRTSCTS) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5166 | hflow |= (D_RTS(ch) | D_CTS(ch)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5167 | if (ch->ch_digi.digi_flags & RTSPACE) |
| 5168 | hflow |= D_RTS(ch); |
| 5169 | if (ch->ch_digi.digi_flags & DTRPACE) |
| 5170 | hflow |= D_DTR(ch); |
| 5171 | if (ch->ch_digi.digi_flags & CTSPACE) |
| 5172 | hflow |= D_CTS(ch); |
| 5173 | if (ch->ch_digi.digi_flags & DSRPACE) |
| 5174 | hflow |= D_DSR(ch); |
| 5175 | if (ch->ch_digi.digi_flags & DCDPACE) |
| 5176 | hflow |= D_CD(ch); |
| 5177 | |
| 5178 | if (hflow != ch->ch_hflow) { |
| 5179 | ch->ch_hflow = hflow; |
| 5180 | |
| 5181 | /* Okay to have channel and board locks held calling this */ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 5182 | dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5183 | } |
| 5184 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5185 | /* |
Mark Hounschell | 8fc324e | 2014-03-05 15:54:51 -0500 | [diff] [blame] | 5186 | * Set RTS and/or DTR Toggle if needed, |
| 5187 | * but only if product is FEP5+ based. |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5188 | */ |
| 5189 | if (bd->bd_flags & BD_FEP5PLUS) { |
| 5190 | u16 hflow2 = 0; |
Daeseok Youn | 96045db | 2014-07-02 16:07:16 +0900 | [diff] [blame] | 5191 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5192 | if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5193 | hflow2 |= (D_RTS(ch)); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5194 | if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5195 | hflow2 |= (D_DTR(ch)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5196 | |
| 5197 | dgap_cmdw_ext(ch, 0xff03, hflow2, 0); |
| 5198 | } |
| 5199 | |
| 5200 | /* |
| 5201 | * Set modem control lines. |
| 5202 | */ |
| 5203 | |
| 5204 | mval ^= ch->ch_mforce & (mval ^ ch->ch_mval); |
| 5205 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5206 | if (ch->ch_mostat ^ mval) { |
| 5207 | ch->ch_mostat = mval; |
| 5208 | |
| 5209 | /* Okay to have channel and board locks held calling this */ |
Mark Hounschell | 2023d18 | 2014-04-14 16:42:43 -0400 | [diff] [blame] | 5210 | 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] | 5211 | } |
| 5212 | |
| 5213 | /* |
| 5214 | * Read modem signals, and then call carrier function. |
| 5215 | */ |
Daeseok Youn | ab6cdcb | 2014-07-11 19:22:39 +0900 | [diff] [blame] | 5216 | ch->ch_mistat = readb(&(ch->ch_bs->m_stat)); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5217 | dgap_carrier(ch); |
| 5218 | |
| 5219 | /* |
| 5220 | * Set the start and stop characters. |
| 5221 | */ |
Mark Hounschell | 8fc324e | 2014-03-05 15:54:51 -0500 | [diff] [blame] | 5222 | if (ch->ch_startc != ch->ch_fepstartc || |
| 5223 | ch->ch_stopc != ch->ch_fepstopc) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5224 | ch->ch_fepstartc = ch->ch_startc; |
| 5225 | ch->ch_fepstopc = ch->ch_stopc; |
| 5226 | |
| 5227 | /* Okay to have channel and board locks held calling this */ |
| 5228 | dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0); |
| 5229 | } |
| 5230 | |
| 5231 | /* |
| 5232 | * Set the Auxiliary start and stop characters. |
| 5233 | */ |
Mark Hounschell | 8fc324e | 2014-03-05 15:54:51 -0500 | [diff] [blame] | 5234 | if (ch->ch_astartc != ch->ch_fepastartc || |
| 5235 | ch->ch_astopc != ch->ch_fepastopc) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5236 | ch->ch_fepastartc = ch->ch_astartc; |
| 5237 | ch->ch_fepastopc = ch->ch_astopc; |
| 5238 | |
| 5239 | /* Okay to have channel and board locks held calling this */ |
| 5240 | dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0); |
| 5241 | } |
| 5242 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5243 | return 0; |
| 5244 | } |
| 5245 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5246 | /* |
| 5247 | * dgap_parity_scan() |
| 5248 | * |
| 5249 | * Convert the FEP5 way of reporting parity errors and breaks into |
| 5250 | * the Linux line discipline way. |
| 5251 | */ |
Mark Hounschell | 8fc324e | 2014-03-05 15:54:51 -0500 | [diff] [blame] | 5252 | static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, |
| 5253 | unsigned char *fbuf, int *len) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5254 | { |
| 5255 | int l = *len; |
| 5256 | int count = 0; |
| 5257 | unsigned char *in, *cout, *fout; |
| 5258 | unsigned char c; |
| 5259 | |
| 5260 | in = cbuf; |
| 5261 | cout = cbuf; |
| 5262 | fout = fbuf; |
| 5263 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5264 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
| 5265 | return; |
| 5266 | |
| 5267 | while (l--) { |
| 5268 | c = *in++; |
| 5269 | switch (ch->pscan_state) { |
| 5270 | default: |
| 5271 | /* reset to sanity and fall through */ |
| 5272 | ch->pscan_state = 0; |
| 5273 | |
| 5274 | case 0: |
| 5275 | /* No FF seen yet */ |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5276 | if (c == (unsigned char) '\377') |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5277 | /* delete this character from stream */ |
| 5278 | ch->pscan_state = 1; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5279 | else { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5280 | *cout++ = c; |
| 5281 | *fout++ = TTY_NORMAL; |
| 5282 | count += 1; |
| 5283 | } |
| 5284 | break; |
| 5285 | |
| 5286 | case 1: |
| 5287 | /* first FF seen */ |
| 5288 | if (c == (unsigned char) '\377') { |
| 5289 | /* doubled ff, transform to single ff */ |
| 5290 | *cout++ = c; |
| 5291 | *fout++ = TTY_NORMAL; |
| 5292 | count += 1; |
| 5293 | ch->pscan_state = 0; |
| 5294 | } else { |
| 5295 | /* save value examination in next state */ |
| 5296 | ch->pscan_savechar = c; |
| 5297 | ch->pscan_state = 2; |
| 5298 | } |
| 5299 | break; |
| 5300 | |
| 5301 | case 2: |
| 5302 | /* third character of ff sequence */ |
| 5303 | |
| 5304 | *cout++ = c; |
| 5305 | |
| 5306 | if (ch->pscan_savechar == 0x0) { |
| 5307 | |
| 5308 | if (c == 0x0) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5309 | ch->ch_err_break++; |
| 5310 | *fout++ = TTY_BREAK; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5311 | } else { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5312 | ch->ch_err_parity++; |
| 5313 | *fout++ = TTY_PARITY; |
| 5314 | } |
| 5315 | } |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5316 | |
| 5317 | count += 1; |
| 5318 | ch->pscan_state = 0; |
| 5319 | } |
| 5320 | } |
| 5321 | *len = count; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5322 | } |
| 5323 | |
Mark Hounschell | 8cdd763 | 2014-03-19 11:10:50 -0400 | [diff] [blame] | 5324 | static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch, |
| 5325 | struct un_t *un, u32 mask, |
| 5326 | unsigned long *irq_flags1, |
| 5327 | unsigned long *irq_flags2) |
| 5328 | { |
| 5329 | if (!(un->un_flags & mask)) |
| 5330 | return; |
| 5331 | |
| 5332 | un->un_flags &= ~mask; |
| 5333 | |
| 5334 | if (!(un->un_flags & UN_ISOPEN)) |
| 5335 | return; |
| 5336 | |
| 5337 | if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && |
| 5338 | un->un_tty->ldisc->ops->write_wakeup) { |
| 5339 | spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2); |
| 5340 | spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1); |
| 5341 | |
| 5342 | (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty); |
| 5343 | |
| 5344 | spin_lock_irqsave(&bd->bd_lock, *irq_flags1); |
| 5345 | spin_lock_irqsave(&ch->ch_lock, *irq_flags2); |
| 5346 | } |
| 5347 | wake_up_interruptible(&un->un_tty->write_wait); |
| 5348 | wake_up_interruptible(&un->un_flags_wait); |
| 5349 | } |
| 5350 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5351 | /*======================================================================= |
| 5352 | * |
| 5353 | * dgap_event - FEP to host event processing routine. |
| 5354 | * |
| 5355 | * bd - Board of current event. |
| 5356 | * |
| 5357 | *=======================================================================*/ |
| 5358 | static int dgap_event(struct board_t *bd) |
| 5359 | { |
| 5360 | struct channel_t *ch; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 5361 | ulong lock_flags; |
| 5362 | ulong lock_flags2; |
Mark Hounschell | 405b26d | 2014-04-23 16:25:27 -0400 | [diff] [blame] | 5363 | struct bs_t __iomem *bs; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 5364 | u8 __iomem *event; |
| 5365 | u8 __iomem *vaddr; |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 5366 | struct ev_t __iomem *eaddr; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 5367 | uint head; |
| 5368 | uint tail; |
| 5369 | int port; |
| 5370 | int reason; |
| 5371 | int modem; |
| 5372 | int b1; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5373 | |
| 5374 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 5375 | return -EIO; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5376 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5377 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5378 | |
| 5379 | vaddr = bd->re_map_membase; |
| 5380 | |
| 5381 | if (!vaddr) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5382 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 5383 | return -EIO; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5384 | } |
| 5385 | |
Mark Hounschell | cacaf10 | 2014-04-25 10:00:42 -0400 | [diff] [blame] | 5386 | eaddr = (struct ev_t __iomem *) (vaddr + EVBUF); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5387 | |
| 5388 | /* Get our head and tail */ |
| 5389 | head = readw(&(eaddr->ev_head)); |
| 5390 | tail = readw(&(eaddr->ev_tail)); |
| 5391 | |
| 5392 | /* |
| 5393 | * Forget it if pointers out of range. |
| 5394 | */ |
| 5395 | |
| 5396 | if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART || |
| 5397 | (head | tail) & 03) { |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5398 | /* Let go of board lock */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5399 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | 6d488a0 | 2014-05-28 16:18:03 -0400 | [diff] [blame] | 5400 | return -EIO; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5401 | } |
| 5402 | |
| 5403 | /* |
| 5404 | * Loop to process all the events in the buffer. |
| 5405 | */ |
| 5406 | while (tail != head) { |
| 5407 | |
| 5408 | /* |
| 5409 | * Get interrupt information. |
| 5410 | */ |
| 5411 | |
| 5412 | event = bd->re_map_membase + tail + EVSTART; |
| 5413 | |
Pascal COMBES | 77870a1 | 2014-05-24 15:58:09 +0200 | [diff] [blame] | 5414 | port = ioread8(event); |
| 5415 | reason = ioread8(event + 1); |
| 5416 | modem = ioread8(event + 2); |
| 5417 | b1 = ioread8(event + 3); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5418 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5419 | /* |
| 5420 | * Make sure the interrupt is valid. |
| 5421 | */ |
| 5422 | if (port >= bd->nasync) |
| 5423 | goto next; |
| 5424 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5425 | if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA))) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5426 | goto next; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5427 | |
| 5428 | ch = bd->channels[port]; |
| 5429 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5430 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5431 | goto next; |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5432 | |
| 5433 | /* |
| 5434 | * If we have made it here, the event was valid. |
| 5435 | * Lock down the channel. |
| 5436 | */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5437 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5438 | |
| 5439 | bs = ch->ch_bs; |
| 5440 | |
| 5441 | if (!bs) { |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5442 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5443 | goto next; |
| 5444 | } |
| 5445 | |
| 5446 | /* |
| 5447 | * Process received data. |
| 5448 | */ |
| 5449 | if (reason & IFDATA) { |
| 5450 | |
| 5451 | /* |
| 5452 | * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT! |
| 5453 | * input could send some data to ld, which in turn |
| 5454 | * could do a callback to one of our other functions. |
| 5455 | */ |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5456 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
| 5457 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5458 | |
| 5459 | dgap_input(ch); |
| 5460 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5461 | spin_lock_irqsave(&bd->bd_lock, lock_flags); |
| 5462 | spin_lock_irqsave(&ch->ch_lock, lock_flags2); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5463 | |
| 5464 | if (ch->ch_flags & CH_RACTIVE) |
| 5465 | ch->ch_flags |= CH_RENABLE; |
| 5466 | else |
| 5467 | writeb(1, &(bs->idata)); |
| 5468 | |
| 5469 | if (ch->ch_flags & CH_RWAIT) { |
| 5470 | ch->ch_flags &= ~CH_RWAIT; |
| 5471 | |
Mark Hounschell | 70d97a6 | 2014-03-10 14:39:41 -0400 | [diff] [blame] | 5472 | wake_up_interruptible |
| 5473 | (&ch->ch_tun.un_flags_wait); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5474 | } |
| 5475 | } |
| 5476 | |
| 5477 | /* |
| 5478 | * Process Modem change signals. |
| 5479 | */ |
| 5480 | if (reason & IFMODEM) { |
| 5481 | ch->ch_mistat = modem; |
| 5482 | dgap_carrier(ch); |
| 5483 | } |
| 5484 | |
| 5485 | /* |
| 5486 | * Process break. |
| 5487 | */ |
| 5488 | if (reason & IFBREAK) { |
| 5489 | |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5490 | if (ch->ch_tun.un_tty) { |
| 5491 | /* A break has been indicated */ |
| 5492 | ch->ch_err_break++; |
Mark Hounschell | 70d97a6 | 2014-03-10 14:39:41 -0400 | [diff] [blame] | 5493 | tty_buffer_request_room |
| 5494 | (ch->ch_tun.un_tty->port, 1); |
| 5495 | tty_insert_flip_char(ch->ch_tun.un_tty->port, |
| 5496 | 0, TTY_BREAK); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5497 | tty_flip_buffer_push(ch->ch_tun.un_tty->port); |
| 5498 | } |
| 5499 | } |
| 5500 | |
| 5501 | /* |
| 5502 | * Process Transmit low. |
| 5503 | */ |
| 5504 | if (reason & IFTLW) { |
Mark Hounschell | 8cdd763 | 2014-03-19 11:10:50 -0400 | [diff] [blame] | 5505 | dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW, |
| 5506 | &lock_flags, &lock_flags2); |
| 5507 | dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW, |
| 5508 | &lock_flags, &lock_flags2); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5509 | if (ch->ch_flags & CH_WLOW) { |
| 5510 | ch->ch_flags &= ~CH_WLOW; |
| 5511 | wake_up_interruptible(&ch->ch_flags_wait); |
| 5512 | } |
| 5513 | } |
| 5514 | |
| 5515 | /* |
| 5516 | * Process Transmit empty. |
| 5517 | */ |
| 5518 | if (reason & IFTEM) { |
Mark Hounschell | 8cdd763 | 2014-03-19 11:10:50 -0400 | [diff] [blame] | 5519 | dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY, |
| 5520 | &lock_flags, &lock_flags2); |
| 5521 | dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY, |
| 5522 | &lock_flags, &lock_flags2); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5523 | if (ch->ch_flags & CH_WEMPTY) { |
| 5524 | ch->ch_flags &= ~CH_WEMPTY; |
| 5525 | wake_up_interruptible(&ch->ch_flags_wait); |
| 5526 | } |
| 5527 | } |
| 5528 | |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5529 | spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5530 | |
| 5531 | next: |
| 5532 | tail = (tail + 4) & (EVMAX - EVSTART - 4); |
| 5533 | } |
| 5534 | |
| 5535 | writew(tail, &(eaddr->ev_tail)); |
Mark Hounschell | c43846a | 2014-03-19 11:10:51 -0400 | [diff] [blame] | 5536 | spin_unlock_irqrestore(&bd->bd_lock, lock_flags); |
Mark Hounschell | b053bb8 | 2014-02-19 13:12:00 -0500 | [diff] [blame] | 5537 | |
| 5538 | return 0; |
| 5539 | } |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5540 | |
| 5541 | static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf) |
| 5542 | { |
| 5543 | return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART); |
| 5544 | } |
| 5545 | static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL); |
| 5546 | |
| 5547 | |
| 5548 | static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf) |
| 5549 | { |
Mark Hounschell | fea0683 | 2014-04-25 16:49:29 -0400 | [diff] [blame] | 5550 | return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5551 | } |
| 5552 | static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL); |
| 5553 | |
| 5554 | |
| 5555 | static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf) |
| 5556 | { |
| 5557 | return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS); |
| 5558 | } |
| 5559 | static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL); |
| 5560 | |
| 5561 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5562 | static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp, |
| 5563 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5564 | { |
| 5565 | return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter); |
| 5566 | } |
| 5567 | static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL); |
| 5568 | |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5569 | static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf) |
| 5570 | { |
| 5571 | return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick); |
| 5572 | } |
| 5573 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5574 | static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp, |
| 5575 | const char *buf, size_t count) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5576 | { |
Mark Hounschell | c4875eb | 2014-03-04 16:03:10 -0500 | [diff] [blame] | 5577 | if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1) |
| 5578 | return -EINVAL; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5579 | return count; |
| 5580 | } |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5581 | static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show, |
| 5582 | dgap_driver_pollrate_store); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5583 | |
Mark Hounschell | 434b679 | 2014-03-06 13:57:55 -0500 | [diff] [blame] | 5584 | static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5585 | { |
| 5586 | int rc = 0; |
| 5587 | struct device_driver *driverfs = &dgap_driver->driver; |
| 5588 | |
| 5589 | rc |= driver_create_file(driverfs, &driver_attr_version); |
| 5590 | rc |= driver_create_file(driverfs, &driver_attr_boards); |
| 5591 | rc |= driver_create_file(driverfs, &driver_attr_maxboards); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5592 | rc |= driver_create_file(driverfs, &driver_attr_pollrate); |
| 5593 | rc |= driver_create_file(driverfs, &driver_attr_pollcounter); |
Mark Hounschell | 434b679 | 2014-03-06 13:57:55 -0500 | [diff] [blame] | 5594 | |
| 5595 | return rc; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5596 | } |
| 5597 | |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 5598 | static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5599 | { |
| 5600 | struct device_driver *driverfs = &dgap_driver->driver; |
Daeseok Youn | 96045db | 2014-07-02 16:07:16 +0900 | [diff] [blame] | 5601 | |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5602 | driver_remove_file(driverfs, &driver_attr_version); |
| 5603 | driver_remove_file(driverfs, &driver_attr_boards); |
| 5604 | driver_remove_file(driverfs, &driver_attr_maxboards); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5605 | driver_remove_file(driverfs, &driver_attr_pollrate); |
| 5606 | driver_remove_file(driverfs, &driver_attr_pollcounter); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5607 | } |
| 5608 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5609 | static struct board_t *dgap_verify_board(struct device *p) |
| 5610 | { |
| 5611 | struct board_t *bd; |
| 5612 | |
| 5613 | if (!p) |
| 5614 | return NULL; |
| 5615 | |
| 5616 | bd = dev_get_drvdata(p); |
| 5617 | if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY) |
| 5618 | return NULL; |
| 5619 | |
| 5620 | return bd; |
| 5621 | } |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5622 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5623 | static ssize_t dgap_ports_state_show(struct device *p, |
| 5624 | struct device_attribute *attr, |
| 5625 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5626 | { |
| 5627 | struct board_t *bd; |
| 5628 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5629 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5630 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5631 | bd = dgap_verify_board(p); |
| 5632 | if (!bd) |
| 5633 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5634 | |
| 5635 | for (i = 0; i < bd->nasync; i++) { |
| 5636 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 5637 | "%d %s\n", bd->channels[i]->ch_portnum, |
| 5638 | bd->channels[i]->ch_open_count ? "Open" : "Closed"); |
| 5639 | } |
| 5640 | return count; |
| 5641 | } |
| 5642 | static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL); |
| 5643 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5644 | static ssize_t dgap_ports_baud_show(struct device *p, |
| 5645 | struct device_attribute *attr, |
| 5646 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5647 | { |
| 5648 | struct board_t *bd; |
| 5649 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5650 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5651 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5652 | bd = dgap_verify_board(p); |
| 5653 | if (!bd) |
| 5654 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5655 | |
| 5656 | for (i = 0; i < bd->nasync; i++) { |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5657 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n", |
| 5658 | bd->channels[i]->ch_portnum, |
| 5659 | bd->channels[i]->ch_baud_info); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5660 | } |
| 5661 | return count; |
| 5662 | } |
| 5663 | static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL); |
| 5664 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5665 | static ssize_t dgap_ports_msignals_show(struct device *p, |
| 5666 | struct device_attribute *attr, |
| 5667 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5668 | { |
| 5669 | struct board_t *bd; |
| 5670 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5671 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5672 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5673 | bd = dgap_verify_board(p); |
| 5674 | if (!bd) |
| 5675 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5676 | |
| 5677 | for (i = 0; i < bd->nasync; i++) { |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5678 | if (bd->channels[i]->ch_open_count) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5679 | count += snprintf(buf + count, PAGE_SIZE - count, |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5680 | "%d %s %s %s %s %s %s\n", |
| 5681 | bd->channels[i]->ch_portnum, |
| 5682 | (bd->channels[i]->ch_mostat & |
| 5683 | UART_MCR_RTS) ? "RTS" : "", |
| 5684 | (bd->channels[i]->ch_mistat & |
| 5685 | UART_MSR_CTS) ? "CTS" : "", |
| 5686 | (bd->channels[i]->ch_mostat & |
| 5687 | UART_MCR_DTR) ? "DTR" : "", |
| 5688 | (bd->channels[i]->ch_mistat & |
| 5689 | UART_MSR_DSR) ? "DSR" : "", |
| 5690 | (bd->channels[i]->ch_mistat & |
| 5691 | UART_MSR_DCD) ? "DCD" : "", |
| 5692 | (bd->channels[i]->ch_mistat & |
| 5693 | UART_MSR_RI) ? "RI" : ""); |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5694 | else |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5695 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 5696 | "%d\n", bd->channels[i]->ch_portnum); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5697 | } |
| 5698 | return count; |
| 5699 | } |
| 5700 | static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL); |
| 5701 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5702 | static ssize_t dgap_ports_iflag_show(struct device *p, |
| 5703 | struct device_attribute *attr, |
| 5704 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5705 | { |
| 5706 | struct board_t *bd; |
| 5707 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5708 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5709 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5710 | bd = dgap_verify_board(p); |
| 5711 | if (!bd) |
| 5712 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5713 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5714 | for (i = 0; i < bd->nasync; i++) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5715 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n", |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5716 | bd->channels[i]->ch_portnum, |
| 5717 | bd->channels[i]->ch_c_iflag); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5718 | return count; |
| 5719 | } |
| 5720 | static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL); |
| 5721 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5722 | static ssize_t dgap_ports_cflag_show(struct device *p, |
| 5723 | struct device_attribute *attr, |
| 5724 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5725 | { |
| 5726 | struct board_t *bd; |
| 5727 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5728 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5729 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5730 | bd = dgap_verify_board(p); |
| 5731 | if (!bd) |
| 5732 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5733 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5734 | for (i = 0; i < bd->nasync; i++) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5735 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n", |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5736 | bd->channels[i]->ch_portnum, |
| 5737 | bd->channels[i]->ch_c_cflag); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5738 | return count; |
| 5739 | } |
| 5740 | static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL); |
| 5741 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5742 | static ssize_t dgap_ports_oflag_show(struct device *p, |
| 5743 | struct device_attribute *attr, |
| 5744 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5745 | { |
| 5746 | struct board_t *bd; |
| 5747 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5748 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5749 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5750 | bd = dgap_verify_board(p); |
| 5751 | if (!bd) |
| 5752 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5753 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5754 | for (i = 0; i < bd->nasync; i++) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5755 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n", |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5756 | bd->channels[i]->ch_portnum, |
| 5757 | bd->channels[i]->ch_c_oflag); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5758 | return count; |
| 5759 | } |
| 5760 | static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL); |
| 5761 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5762 | static ssize_t dgap_ports_lflag_show(struct device *p, |
| 5763 | struct device_attribute *attr, |
| 5764 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5765 | { |
| 5766 | struct board_t *bd; |
| 5767 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5768 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5769 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5770 | bd = dgap_verify_board(p); |
| 5771 | if (!bd) |
| 5772 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5773 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5774 | for (i = 0; i < bd->nasync; i++) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5775 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n", |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5776 | bd->channels[i]->ch_portnum, |
| 5777 | bd->channels[i]->ch_c_lflag); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5778 | return count; |
| 5779 | } |
| 5780 | static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL); |
| 5781 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5782 | static ssize_t dgap_ports_digi_flag_show(struct device *p, |
| 5783 | struct device_attribute *attr, |
| 5784 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5785 | { |
| 5786 | struct board_t *bd; |
| 5787 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5788 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5789 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5790 | bd = dgap_verify_board(p); |
| 5791 | if (!bd) |
| 5792 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5793 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5794 | for (i = 0; i < bd->nasync; i++) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5795 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n", |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5796 | bd->channels[i]->ch_portnum, |
| 5797 | bd->channels[i]->ch_digi.digi_flags); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5798 | return count; |
| 5799 | } |
| 5800 | static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL); |
| 5801 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5802 | static ssize_t dgap_ports_rxcount_show(struct device *p, |
| 5803 | struct device_attribute *attr, |
| 5804 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5805 | { |
| 5806 | struct board_t *bd; |
| 5807 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5808 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5809 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5810 | bd = dgap_verify_board(p); |
| 5811 | if (!bd) |
| 5812 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5813 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5814 | for (i = 0; i < bd->nasync; i++) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5815 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n", |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5816 | bd->channels[i]->ch_portnum, |
| 5817 | bd->channels[i]->ch_rxcount); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5818 | return count; |
| 5819 | } |
| 5820 | static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL); |
| 5821 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5822 | static ssize_t dgap_ports_txcount_show(struct device *p, |
| 5823 | struct device_attribute *attr, |
| 5824 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5825 | { |
| 5826 | struct board_t *bd; |
| 5827 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 5828 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5829 | |
Mark Hounschell | 3eb1415 | 2014-03-04 09:33:46 -0500 | [diff] [blame] | 5830 | bd = dgap_verify_board(p); |
| 5831 | if (!bd) |
| 5832 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5833 | |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 5834 | for (i = 0; i < bd->nasync; i++) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5835 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n", |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5836 | bd->channels[i]->ch_portnum, |
| 5837 | bd->channels[i]->ch_txcount); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5838 | return count; |
| 5839 | } |
| 5840 | static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL); |
| 5841 | |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5842 | /* this function creates the sys files that will export each signal status |
| 5843 | * to sysfs each value will be put in a separate filename |
| 5844 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 5845 | static void dgap_create_ports_sysfiles(struct board_t *bd) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5846 | { |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5847 | dev_set_drvdata(&bd->pdev->dev, bd); |
Mark Hounschell | 434b679 | 2014-03-06 13:57:55 -0500 | [diff] [blame] | 5848 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_state); |
| 5849 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud); |
| 5850 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals); |
| 5851 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag); |
| 5852 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag); |
| 5853 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag); |
| 5854 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag); |
| 5855 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag); |
| 5856 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount); |
| 5857 | device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5858 | } |
| 5859 | |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5860 | /* removes all the sys files created for that port */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 5861 | static void dgap_remove_ports_sysfiles(struct board_t *bd) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5862 | { |
| 5863 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state); |
| 5864 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud); |
| 5865 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals); |
| 5866 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag); |
| 5867 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag); |
| 5868 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag); |
| 5869 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag); |
| 5870 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag); |
| 5871 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount); |
| 5872 | device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount); |
| 5873 | } |
| 5874 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5875 | static ssize_t dgap_tty_state_show(struct device *d, |
| 5876 | struct device_attribute *attr, |
| 5877 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5878 | { |
| 5879 | struct board_t *bd; |
| 5880 | struct channel_t *ch; |
| 5881 | struct un_t *un; |
| 5882 | |
| 5883 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5884 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5885 | un = dev_get_drvdata(d); |
| 5886 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5887 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5888 | ch = un->un_ch; |
| 5889 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5890 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5891 | bd = ch->ch_bd; |
| 5892 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5893 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5894 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5895 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5896 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5897 | return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? |
| 5898 | "Open" : "Closed"); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5899 | } |
| 5900 | static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL); |
| 5901 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5902 | static ssize_t dgap_tty_baud_show(struct device *d, |
| 5903 | struct device_attribute *attr, |
| 5904 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5905 | { |
| 5906 | struct board_t *bd; |
| 5907 | struct channel_t *ch; |
| 5908 | struct un_t *un; |
| 5909 | |
| 5910 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5911 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5912 | un = dev_get_drvdata(d); |
| 5913 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5914 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5915 | ch = un->un_ch; |
| 5916 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5917 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5918 | bd = ch->ch_bd; |
| 5919 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5920 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5921 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5922 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5923 | |
| 5924 | return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info); |
| 5925 | } |
| 5926 | static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL); |
| 5927 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5928 | static ssize_t dgap_tty_msignals_show(struct device *d, |
| 5929 | struct device_attribute *attr, |
| 5930 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5931 | { |
| 5932 | struct board_t *bd; |
| 5933 | struct channel_t *ch; |
| 5934 | struct un_t *un; |
| 5935 | |
| 5936 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5937 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5938 | un = dev_get_drvdata(d); |
| 5939 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5940 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5941 | ch = un->un_ch; |
| 5942 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5943 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5944 | bd = ch->ch_bd; |
| 5945 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5946 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5947 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5948 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5949 | |
| 5950 | if (ch->ch_open_count) { |
| 5951 | return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n", |
| 5952 | (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "", |
| 5953 | (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "", |
| 5954 | (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "", |
| 5955 | (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "", |
| 5956 | (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "", |
| 5957 | (ch->ch_mistat & UART_MSR_RI) ? "RI" : ""); |
| 5958 | } |
| 5959 | return 0; |
| 5960 | } |
| 5961 | static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL); |
| 5962 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5963 | static ssize_t dgap_tty_iflag_show(struct device *d, |
| 5964 | struct device_attribute *attr, |
| 5965 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5966 | { |
| 5967 | struct board_t *bd; |
| 5968 | struct channel_t *ch; |
| 5969 | struct un_t *un; |
| 5970 | |
| 5971 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5972 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5973 | un = dev_get_drvdata(d); |
| 5974 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
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 | ch = un->un_ch; |
| 5977 | if (!ch || ch->magic != DGAP_CHANNEL_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 | bd = ch->ch_bd; |
| 5980 | if (!bd || bd->magic != DGAP_BOARD_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 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5983 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5984 | |
| 5985 | return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag); |
| 5986 | } |
| 5987 | static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL); |
| 5988 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 5989 | static ssize_t dgap_tty_cflag_show(struct device *d, |
| 5990 | struct device_attribute *attr, |
| 5991 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5992 | { |
| 5993 | struct board_t *bd; |
| 5994 | struct channel_t *ch; |
| 5995 | struct un_t *un; |
| 5996 | |
| 5997 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 5998 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 5999 | un = dev_get_drvdata(d); |
| 6000 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6001 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6002 | ch = un->un_ch; |
| 6003 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6004 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6005 | bd = ch->ch_bd; |
| 6006 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6007 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6008 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6009 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6010 | |
| 6011 | return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag); |
| 6012 | } |
| 6013 | static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL); |
| 6014 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6015 | static ssize_t dgap_tty_oflag_show(struct device *d, |
| 6016 | struct device_attribute *attr, |
| 6017 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6018 | { |
| 6019 | struct board_t *bd; |
| 6020 | struct channel_t *ch; |
| 6021 | struct un_t *un; |
| 6022 | |
| 6023 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6024 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6025 | un = dev_get_drvdata(d); |
| 6026 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6027 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6028 | ch = un->un_ch; |
| 6029 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6030 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6031 | bd = ch->ch_bd; |
| 6032 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6033 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6034 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6035 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6036 | |
| 6037 | return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag); |
| 6038 | } |
| 6039 | static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL); |
| 6040 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6041 | static ssize_t dgap_tty_lflag_show(struct device *d, |
| 6042 | struct device_attribute *attr, |
| 6043 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6044 | { |
| 6045 | struct board_t *bd; |
| 6046 | struct channel_t *ch; |
| 6047 | struct un_t *un; |
| 6048 | |
| 6049 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6050 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6051 | un = dev_get_drvdata(d); |
| 6052 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6053 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6054 | ch = un->un_ch; |
| 6055 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6056 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6057 | bd = ch->ch_bd; |
| 6058 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6059 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6060 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6061 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6062 | |
| 6063 | return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag); |
| 6064 | } |
| 6065 | static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL); |
| 6066 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6067 | static ssize_t dgap_tty_digi_flag_show(struct device *d, |
| 6068 | struct device_attribute *attr, |
| 6069 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6070 | { |
| 6071 | struct board_t *bd; |
| 6072 | struct channel_t *ch; |
| 6073 | struct un_t *un; |
| 6074 | |
| 6075 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6076 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6077 | un = dev_get_drvdata(d); |
| 6078 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6079 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6080 | ch = un->un_ch; |
| 6081 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6082 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6083 | bd = ch->ch_bd; |
| 6084 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6085 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6086 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6087 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6088 | |
| 6089 | return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags); |
| 6090 | } |
| 6091 | static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL); |
| 6092 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6093 | static ssize_t dgap_tty_rxcount_show(struct device *d, |
| 6094 | struct device_attribute *attr, |
| 6095 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6096 | { |
| 6097 | struct board_t *bd; |
| 6098 | struct channel_t *ch; |
| 6099 | struct un_t *un; |
| 6100 | |
| 6101 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6102 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6103 | un = dev_get_drvdata(d); |
| 6104 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6105 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6106 | ch = un->un_ch; |
| 6107 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6108 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6109 | bd = ch->ch_bd; |
| 6110 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6111 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6112 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6113 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6114 | |
| 6115 | return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount); |
| 6116 | } |
| 6117 | static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL); |
| 6118 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6119 | static ssize_t dgap_tty_txcount_show(struct device *d, |
| 6120 | struct device_attribute *attr, |
| 6121 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6122 | { |
| 6123 | struct board_t *bd; |
| 6124 | struct channel_t *ch; |
| 6125 | struct un_t *un; |
| 6126 | |
| 6127 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6128 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6129 | un = dev_get_drvdata(d); |
| 6130 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6131 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6132 | ch = un->un_ch; |
| 6133 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6134 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6135 | bd = ch->ch_bd; |
| 6136 | if (!bd || bd->magic != DGAP_BOARD_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6137 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6138 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6139 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6140 | |
| 6141 | return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount); |
| 6142 | } |
| 6143 | static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL); |
| 6144 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6145 | static ssize_t dgap_tty_name_show(struct device *d, |
| 6146 | struct device_attribute *attr, |
| 6147 | char *buf) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6148 | { |
| 6149 | struct board_t *bd; |
| 6150 | struct channel_t *ch; |
| 6151 | struct un_t *un; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 6152 | int cn; |
| 6153 | int bn; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 6154 | struct cnode *cptr; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6155 | int found = FALSE; |
| 6156 | int ncount = 0; |
| 6157 | int starto = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 6158 | int i; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6159 | |
| 6160 | if (!d) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6161 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6162 | un = dev_get_drvdata(d); |
| 6163 | if (!un || un->magic != DGAP_UNIT_MAGIC) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6164 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6165 | ch = un->un_ch; |
| 6166 | if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) |
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 | bd = ch->ch_bd; |
| 6169 | if (!bd || bd->magic != DGAP_BOARD_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 | if (bd->state != BOARD_READY) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6172 | return 0; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6173 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 6174 | bn = bd->boardnum; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6175 | cn = ch->ch_portnum; |
| 6176 | |
| 6177 | for (cptr = bd->bd_config; cptr; cptr = cptr->next) { |
| 6178 | |
| 6179 | if ((cptr->type == BNODE) && |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6180 | ((cptr->u.board.type == APORT2_920P) || |
| 6181 | (cptr->u.board.type == APORT4_920P) || |
| 6182 | (cptr->u.board.type == APORT8_920P) || |
| 6183 | (cptr->u.board.type == PAPORT4) || |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6184 | (cptr->u.board.type == PAPORT8))) { |
| 6185 | |
Mark Hounschell | 84e8828 | 2014-03-10 15:46:54 -0400 | [diff] [blame] | 6186 | found = TRUE; |
| 6187 | if (cptr->u.board.v_start) |
| 6188 | starto = cptr->u.board.start; |
| 6189 | else |
| 6190 | starto = 1; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6191 | } |
| 6192 | |
| 6193 | if (cptr->type == TNODE && found == TRUE) { |
| 6194 | char *ptr1; |
Daeseok Youn | 96045db | 2014-07-02 16:07:16 +0900 | [diff] [blame] | 6195 | |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6196 | if (strstr(cptr->u.ttyname, "tty")) { |
| 6197 | ptr1 = cptr->u.ttyname; |
| 6198 | ptr1 += 3; |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 6199 | } else |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6200 | ptr1 = cptr->u.ttyname; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6201 | |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 6202 | for (i = 0; i < dgap_config_get_num_prts(bd); i++) { |
| 6203 | if (cn != i) |
| 6204 | continue; |
| 6205 | |
| 6206 | return snprintf(buf, PAGE_SIZE, "%s%s%02d\n", |
| 6207 | (un->un_type == DGAP_PRINT) ? |
| 6208 | "pr" : "tty", |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6209 | ptr1, i + starto); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6210 | } |
| 6211 | } |
| 6212 | |
| 6213 | if (cptr->type == CNODE) { |
| 6214 | |
| 6215 | for (i = 0; i < cptr->u.conc.nport; i++) { |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 6216 | if (cn != (i + ncount)) |
| 6217 | continue; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6218 | |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6219 | return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n", |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 6220 | (un->un_type == DGAP_PRINT) ? |
| 6221 | "pr" : "tty", |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6222 | cptr->u.conc.id, |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 6223 | i + (cptr->u.conc.v_start ? |
| 6224 | cptr->u.conc.start : 1)); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6225 | } |
| 6226 | |
| 6227 | ncount += cptr->u.conc.nport; |
| 6228 | } |
| 6229 | |
| 6230 | if (cptr->type == MNODE) { |
| 6231 | |
| 6232 | for (i = 0; i < cptr->u.module.nport; i++) { |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 6233 | if (cn != (i + ncount)) |
| 6234 | continue; |
| 6235 | |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6236 | return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n", |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 6237 | (un->un_type == DGAP_PRINT) ? |
| 6238 | "pr" : "tty", |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6239 | cptr->u.module.id, |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 6240 | i + (cptr->u.module.v_start ? |
| 6241 | cptr->u.module.start : 1)); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6242 | } |
| 6243 | |
| 6244 | ncount += cptr->u.module.nport; |
| 6245 | |
| 6246 | } |
| 6247 | } |
| 6248 | |
| 6249 | return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n", |
| 6250 | (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn); |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6251 | } |
| 6252 | static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL); |
| 6253 | |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6254 | static struct attribute *dgap_sysfs_tty_entries[] = { |
| 6255 | &dev_attr_state.attr, |
| 6256 | &dev_attr_baud.attr, |
| 6257 | &dev_attr_msignals.attr, |
| 6258 | &dev_attr_iflag.attr, |
| 6259 | &dev_attr_cflag.attr, |
| 6260 | &dev_attr_oflag.attr, |
| 6261 | &dev_attr_lflag.attr, |
| 6262 | &dev_attr_digi_flag.attr, |
| 6263 | &dev_attr_rxcount.attr, |
| 6264 | &dev_attr_txcount.attr, |
| 6265 | &dev_attr_custom_name.attr, |
| 6266 | NULL |
| 6267 | }; |
| 6268 | |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6269 | static struct attribute_group dgap_tty_attribute_group = { |
| 6270 | .name = NULL, |
| 6271 | .attrs = dgap_sysfs_tty_entries, |
| 6272 | }; |
| 6273 | |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 6274 | 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] | 6275 | { |
| 6276 | int ret; |
| 6277 | |
| 6278 | ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group); |
Mark Hounschell | 54794d1 | 2014-03-04 16:03:07 -0500 | [diff] [blame] | 6279 | if (ret) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6280 | return; |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6281 | |
| 6282 | dev_set_drvdata(c, un); |
| 6283 | |
| 6284 | } |
| 6285 | |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 6286 | static void dgap_remove_tty_sysfs(struct device *c) |
Mark Hounschell | 7568f7d | 2014-02-19 13:12:01 -0500 | [diff] [blame] | 6287 | { |
| 6288 | sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group); |
| 6289 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6290 | |
Daeseok Youn | 99a643b | 2014-07-31 13:02:30 +0900 | [diff] [blame] | 6291 | static void dgap_cleanup_nodes(void) |
| 6292 | { |
| 6293 | struct cnode *p; |
| 6294 | |
| 6295 | p = &dgap_head; |
| 6296 | |
| 6297 | while (p) { |
| 6298 | struct cnode *tmp = p->next; |
| 6299 | |
| 6300 | if (p->type == NULLNODE) { |
| 6301 | p = tmp; |
| 6302 | continue; |
| 6303 | } |
| 6304 | |
| 6305 | switch (p->type) { |
| 6306 | case BNODE: |
| 6307 | kfree(p->u.board.portstr); |
| 6308 | kfree(p->u.board.addrstr); |
| 6309 | kfree(p->u.board.pcibusstr); |
| 6310 | kfree(p->u.board.pcislotstr); |
| 6311 | kfree(p->u.board.method); |
| 6312 | break; |
| 6313 | case CNODE: |
| 6314 | kfree(p->u.conc.id); |
| 6315 | kfree(p->u.conc.connect); |
| 6316 | break; |
| 6317 | case MNODE: |
| 6318 | kfree(p->u.module.id); |
| 6319 | break; |
| 6320 | case TNODE: |
| 6321 | kfree(p->u.ttyname); |
| 6322 | break; |
| 6323 | case CUNODE: |
| 6324 | kfree(p->u.cuname); |
| 6325 | break; |
| 6326 | case LNODE: |
| 6327 | kfree(p->u.line.cable); |
| 6328 | break; |
| 6329 | case PNODE: |
| 6330 | kfree(p->u.printname); |
| 6331 | break; |
| 6332 | } |
| 6333 | |
| 6334 | kfree(p->u.board.status); |
| 6335 | kfree(p); |
| 6336 | p = tmp; |
| 6337 | } |
| 6338 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6339 | /* |
| 6340 | * Parse a configuration file read into memory as a string. |
| 6341 | */ |
Daeseok Youn | c787366 | 2014-06-13 18:18:04 +0900 | [diff] [blame] | 6342 | static int dgap_parsefile(char **in) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6343 | { |
| 6344 | struct cnode *p, *brd, *line, *conc; |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 6345 | int rc; |
| 6346 | char *s; |
| 6347 | int linecnt = 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6348 | |
| 6349 | p = &dgap_head; |
| 6350 | brd = line = conc = NULL; |
| 6351 | |
| 6352 | /* perhaps we are adding to an existing list? */ |
Mark Hounschell | ee48710 | 2014-05-23 13:13:03 -0400 | [diff] [blame] | 6353 | while (p->next) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6354 | p = p->next; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6355 | |
| 6356 | /* file must start with a BEGIN */ |
Daeseok Youn | 7bab00f | 2014-07-15 18:49:52 +0900 | [diff] [blame] | 6357 | while ((rc = dgap_gettok(in)) != BEGIN) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6358 | if (rc == 0) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6359 | pr_err("unexpected EOF"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6360 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6361 | } |
| 6362 | } |
| 6363 | |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 6364 | for (; ;) { |
Daeseok Youn | 77a4492 | 2014-08-09 14:38:14 +0900 | [diff] [blame] | 6365 | int board_type = 0; |
Daeseok Youn | f6aa016 | 2014-08-09 14:38:41 +0900 | [diff] [blame] | 6366 | int conc_type = 0; |
Daeseok Youn | 3cfa648 | 2014-08-09 14:39:05 +0900 | [diff] [blame] | 6367 | int module_type = 0; |
Daeseok Youn | 77a4492 | 2014-08-09 14:38:14 +0900 | [diff] [blame] | 6368 | |
Daeseok Youn | 7bab00f | 2014-07-15 18:49:52 +0900 | [diff] [blame] | 6369 | rc = dgap_gettok(in); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6370 | if (rc == 0) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6371 | pr_err("unexpected EOF"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6372 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6373 | } |
| 6374 | |
| 6375 | switch (rc) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6376 | case BEGIN: /* should only be 1 begin */ |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6377 | pr_err("unexpected config_begin\n"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6378 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6379 | |
| 6380 | case END: |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6381 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6382 | |
| 6383 | case BOARD: /* board info */ |
| 6384 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6385 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6386 | |
| 6387 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6388 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6389 | return -1; |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6390 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6391 | p = p->next; |
| 6392 | |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6393 | p->type = BNODE; |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6394 | p->u.board.status = kstrdup("No", GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6395 | line = conc = NULL; |
| 6396 | brd = p; |
| 6397 | linecnt = -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6398 | |
Daeseok Youn | 77a4492 | 2014-08-09 14:38:14 +0900 | [diff] [blame] | 6399 | board_type = dgap_gettok(in); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6400 | if (board_type == 0) { |
| 6401 | pr_err("board !!type not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6402 | return -1; |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6403 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6404 | |
Daeseok Youn | 77a4492 | 2014-08-09 14:38:14 +0900 | [diff] [blame] | 6405 | p->u.board.type = board_type; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6406 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6407 | break; |
| 6408 | |
| 6409 | case IO: /* i/o port */ |
| 6410 | if (p->type != BNODE) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6411 | pr_err("IO port only vaild for boards"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6412 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6413 | } |
| 6414 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6415 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6416 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6417 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6418 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6419 | p->u.board.portstr = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6420 | if (kstrtol(s, 0, &p->u.board.port)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6421 | pr_err("bad number for IO port"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6422 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6423 | } |
| 6424 | p->u.board.v_port = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6425 | break; |
| 6426 | |
| 6427 | case MEM: /* memory address */ |
| 6428 | if (p->type != BNODE) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6429 | pr_err("memory address only vaild for boards"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6430 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6431 | } |
| 6432 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6433 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6434 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6435 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6436 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6437 | p->u.board.addrstr = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6438 | if (kstrtoul(s, 0, &p->u.board.addr)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6439 | pr_err("bad number for memory address"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6440 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6441 | } |
| 6442 | p->u.board.v_addr = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6443 | break; |
| 6444 | |
| 6445 | case PCIINFO: /* pci information */ |
| 6446 | if (p->type != BNODE) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6447 | pr_err("memory address only vaild for boards"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6448 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6449 | } |
| 6450 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6451 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6452 | pr_err("unexpected end of file"); |
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 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6455 | p->u.board.pcibusstr = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6456 | if (kstrtoul(s, 0, &p->u.board.pcibus)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6457 | pr_err("bad number for pci bus"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6458 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6459 | } |
| 6460 | p->u.board.v_pcibus = 1; |
| 6461 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6462 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6463 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6464 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6465 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6466 | p->u.board.pcislotstr = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6467 | if (kstrtoul(s, 0, &p->u.board.pcislot)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6468 | pr_err("bad number for pci slot"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6469 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6470 | } |
| 6471 | p->u.board.v_pcislot = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6472 | break; |
| 6473 | |
| 6474 | case METHOD: |
| 6475 | if (p->type != BNODE) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6476 | pr_err("install method only vaild for boards"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6477 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6478 | } |
| 6479 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6480 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6481 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6482 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6483 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6484 | p->u.board.method = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6485 | p->u.board.v_method = 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6486 | break; |
| 6487 | |
| 6488 | case STATUS: |
| 6489 | if (p->type != BNODE) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6490 | pr_err("config status only vaild for boards"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6491 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6492 | } |
| 6493 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6494 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6495 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6496 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6497 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6498 | p->u.board.status = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6499 | break; |
| 6500 | |
| 6501 | case NPORTS: /* number of ports */ |
| 6502 | if (p->type == BNODE) { |
| 6503 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6504 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6505 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6506 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6507 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6508 | if (kstrtol(s, 0, &p->u.board.nport)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6509 | pr_err("bad number for number of ports"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6510 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6511 | } |
| 6512 | p->u.board.v_nport = 1; |
| 6513 | } else if (p->type == CNODE) { |
| 6514 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6515 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6516 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6517 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6518 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6519 | if (kstrtol(s, 0, &p->u.conc.nport)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6520 | pr_err("bad number for number of ports"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6521 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6522 | } |
| 6523 | p->u.conc.v_nport = 1; |
| 6524 | } else if (p->type == MNODE) { |
| 6525 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6526 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6527 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6528 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6529 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6530 | if (kstrtol(s, 0, &p->u.module.nport)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6531 | pr_err("bad number for number of ports"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6532 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6533 | } |
| 6534 | p->u.module.v_nport = 1; |
| 6535 | } else { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6536 | pr_err("nports only valid for concentrators or modules"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6537 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6538 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6539 | break; |
| 6540 | |
| 6541 | case ID: /* letter ID used in tty name */ |
| 6542 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6543 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6544 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6545 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6546 | } |
| 6547 | |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6548 | p->u.board.status = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6549 | |
| 6550 | if (p->type == CNODE) { |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6551 | p->u.conc.id = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6552 | p->u.conc.v_id = 1; |
| 6553 | } else if (p->type == MNODE) { |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6554 | p->u.module.id = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6555 | p->u.module.v_id = 1; |
| 6556 | } else { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6557 | pr_err("id only valid for concentrators or modules"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6558 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6559 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6560 | break; |
| 6561 | |
| 6562 | case STARTO: /* start offset of ID */ |
| 6563 | if (p->type == BNODE) { |
| 6564 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6565 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6566 | pr_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 | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6569 | if (kstrtol(s, 0, &p->u.board.start)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6570 | pr_err("bad number for start of tty count"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6571 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6572 | } |
| 6573 | p->u.board.v_start = 1; |
| 6574 | } else if (p->type == CNODE) { |
| 6575 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6576 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6577 | pr_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 | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6580 | if (kstrtol(s, 0, &p->u.conc.start)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6581 | pr_err("bad number for start of tty count"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6582 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6583 | } |
| 6584 | p->u.conc.v_start = 1; |
| 6585 | } else if (p->type == MNODE) { |
| 6586 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6587 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6588 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6589 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6590 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6591 | if (kstrtol(s, 0, &p->u.module.start)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6592 | pr_err("bad number for start of tty count"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6593 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6594 | } |
| 6595 | p->u.module.v_start = 1; |
| 6596 | } else { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6597 | pr_err("start only valid for concentrators or modules"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6598 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6599 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6600 | break; |
| 6601 | |
| 6602 | case TTYN: /* tty name prefix */ |
| 6603 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6604 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6605 | |
| 6606 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6607 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6608 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6609 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6610 | p = p->next; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6611 | p->type = TNODE; |
| 6612 | |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6613 | s = dgap_getword(in); |
| 6614 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6615 | pr_err("unexpeced end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6616 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6617 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6618 | p->u.ttyname = kstrdup(s, GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6619 | if (!p->u.ttyname) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6620 | return -1; |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6621 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6622 | break; |
| 6623 | |
| 6624 | case CU: /* cu name prefix */ |
| 6625 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6626 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6627 | |
| 6628 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6629 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6630 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6631 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6632 | p = p->next; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6633 | p->type = CUNODE; |
| 6634 | |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6635 | s = dgap_getword(in); |
| 6636 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6637 | pr_err("unexpeced end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6638 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6639 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6640 | p->u.cuname = kstrdup(s, GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6641 | if (!p->u.cuname) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6642 | return -1; |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6643 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6644 | break; |
| 6645 | |
| 6646 | case LINE: /* line information */ |
| 6647 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6648 | return -1; |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6649 | if (!brd) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6650 | pr_err("must specify board before line info"); |
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 | } |
| 6653 | switch (brd->u.board.type) { |
| 6654 | case PPCM: |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6655 | pr_err("line not vaild for PC/em"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6656 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6657 | } |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6658 | |
| 6659 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6660 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6661 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6662 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6663 | p = p->next; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6664 | p->type = LNODE; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6665 | conc = NULL; |
| 6666 | line = p; |
| 6667 | linecnt++; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6668 | break; |
| 6669 | |
| 6670 | case CONC: /* concentrator information */ |
| 6671 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6672 | return -1; |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6673 | if (!line) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6674 | pr_err("must specify line info before concentrator"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6675 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6676 | } |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6677 | |
| 6678 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6679 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6680 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6681 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6682 | p = p->next; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6683 | p->type = CNODE; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6684 | conc = p; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6685 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6686 | if (linecnt) |
| 6687 | brd->u.board.conc2++; |
| 6688 | else |
| 6689 | brd->u.board.conc1++; |
| 6690 | |
Daeseok Youn | f6aa016 | 2014-08-09 14:38:41 +0900 | [diff] [blame] | 6691 | conc_type = dgap_gettok(in); |
| 6692 | if (conc_type == 0 || conc_type != CX || |
| 6693 | conc_type != EPC) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6694 | pr_err("failed to set a type of concentratros"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6695 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6696 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6697 | |
Daeseok Youn | f6aa016 | 2014-08-09 14:38:41 +0900 | [diff] [blame] | 6698 | p->u.conc.type = conc_type; |
| 6699 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6700 | break; |
| 6701 | |
| 6702 | case MOD: /* EBI module */ |
| 6703 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6704 | return -1; |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6705 | if (!brd) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6706 | pr_err("must specify board info before EBI modules"); |
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 | switch (brd->u.board.type) { |
| 6710 | case PPCM: |
| 6711 | linecnt = 0; |
| 6712 | break; |
| 6713 | default: |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6714 | if (!conc) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6715 | pr_err("must specify concentrator info before EBI module"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6716 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6717 | } |
| 6718 | } |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6719 | |
| 6720 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6721 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6722 | return -1; |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6723 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6724 | p = p->next; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6725 | p->type = MNODE; |
| 6726 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6727 | if (linecnt) |
| 6728 | brd->u.board.module2++; |
| 6729 | else |
| 6730 | brd->u.board.module1++; |
| 6731 | |
Daeseok Youn | 3cfa648 | 2014-08-09 14:39:05 +0900 | [diff] [blame] | 6732 | module_type = dgap_gettok(in); |
| 6733 | if (module_type == 0 || module_type != PORTS || |
| 6734 | module_type != MODEM) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6735 | pr_err("failed to set a type of module"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6736 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6737 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6738 | |
Daeseok Youn | 3cfa648 | 2014-08-09 14:39:05 +0900 | [diff] [blame] | 6739 | p->u.module.type = module_type; |
| 6740 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6741 | break; |
| 6742 | |
| 6743 | case CABLE: |
| 6744 | if (p->type == LNODE) { |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6745 | s = dgap_getword(in); |
| 6746 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6747 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6748 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6749 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6750 | p->u.line.cable = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6751 | p->u.line.v_cable = 1; |
| 6752 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6753 | break; |
| 6754 | |
| 6755 | case SPEED: /* sync line speed indication */ |
| 6756 | if (p->type == LNODE) { |
| 6757 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6758 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6759 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6760 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6761 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6762 | if (kstrtol(s, 0, &p->u.line.speed)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6763 | pr_err("bad number for line speed"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6764 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6765 | } |
| 6766 | p->u.line.v_speed = 1; |
| 6767 | } else if (p->type == CNODE) { |
| 6768 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6769 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6770 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6771 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6772 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6773 | if (kstrtol(s, 0, &p->u.conc.speed)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6774 | pr_err("bad number for line speed"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6775 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6776 | } |
| 6777 | p->u.conc.v_speed = 1; |
| 6778 | } else { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6779 | pr_err("speed valid only for lines or concentrators."); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6780 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6781 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6782 | break; |
| 6783 | |
| 6784 | case CONNECT: |
| 6785 | if (p->type == CNODE) { |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6786 | s = dgap_getword(in); |
| 6787 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6788 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6789 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6790 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6791 | p->u.conc.connect = kstrdup(s, GFP_KERNEL); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6792 | p->u.conc.v_connect = 1; |
| 6793 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6794 | break; |
| 6795 | case PRINT: /* transparent print name prefix */ |
| 6796 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6797 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6798 | |
| 6799 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6800 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6801 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6802 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6803 | p = p->next; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6804 | p->type = PNODE; |
| 6805 | |
Mark Hounschell | d1c3c6f | 2014-02-28 15:48:44 -0500 | [diff] [blame] | 6806 | s = dgap_getword(in); |
| 6807 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6808 | pr_err("unexpeced end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6809 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6810 | } |
Mark Hounschell | 6081443 | 2014-05-21 16:17:51 -0400 | [diff] [blame] | 6811 | p->u.printname = kstrdup(s, GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6812 | if (!p->u.printname) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6813 | return -1; |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6814 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6815 | break; |
| 6816 | |
| 6817 | case CMAJOR: /* major number */ |
| 6818 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6819 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6820 | |
| 6821 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6822 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6823 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6824 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6825 | p = p->next; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6826 | p->type = JNODE; |
| 6827 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6828 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6829 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6830 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6831 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6832 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6833 | if (kstrtol(s, 0, &p->u.majornumber)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6834 | pr_err("bad number for major number"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6835 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6836 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6837 | break; |
| 6838 | |
| 6839 | case ALTPIN: /* altpin setting */ |
| 6840 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6841 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6842 | |
| 6843 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6844 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6845 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6846 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6847 | p = p->next; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6848 | p->type = ANODE; |
| 6849 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6850 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6851 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6852 | pr_err("unexpected end of file"); |
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 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6855 | if (kstrtol(s, 0, &p->u.altpin)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6856 | pr_err("bad number for altpin"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6857 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6858 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6859 | break; |
| 6860 | |
| 6861 | case USEINTR: /* enable interrupt setting */ |
| 6862 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6863 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6864 | |
| 6865 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6866 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6867 | return -1; |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6868 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6869 | p = p->next; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6870 | p->type = INTRNODE; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6871 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6872 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6873 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6874 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6875 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6876 | if (kstrtol(s, 0, &p->u.useintr)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6877 | pr_err("bad number for useintr"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6878 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6879 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6880 | break; |
| 6881 | |
| 6882 | case TTSIZ: /* size of tty structure */ |
| 6883 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6884 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6885 | |
| 6886 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6887 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6888 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6889 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6890 | p = p->next; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6891 | p->type = TSNODE; |
| 6892 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6893 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6894 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6895 | pr_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.ttysize)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6899 | pr_err("bad number for ttysize"); |
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 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6902 | break; |
| 6903 | |
| 6904 | case CHSIZ: /* channel structure size */ |
| 6905 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6906 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6907 | |
| 6908 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6909 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6910 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6911 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6912 | p = p->next; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6913 | p->type = CSNODE; |
| 6914 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6915 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6916 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6917 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6918 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6919 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6920 | if (kstrtol(s, 0, &p->u.chsize)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6921 | pr_err("bad number for chsize"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6922 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6923 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6924 | break; |
| 6925 | |
| 6926 | case BSSIZ: /* board structure size */ |
| 6927 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6928 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6929 | |
| 6930 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6931 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6932 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6933 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6934 | p = p->next; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6935 | p->type = BSNODE; |
| 6936 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6937 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6938 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6939 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6940 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6941 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6942 | if (kstrtol(s, 0, &p->u.bssize)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6943 | pr_err("bad number for bssize"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6944 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6945 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6946 | break; |
| 6947 | |
| 6948 | case UNTSIZ: /* sched structure size */ |
| 6949 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6950 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6951 | |
| 6952 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6953 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6954 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6955 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6956 | p = p->next; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6957 | p->type = USNODE; |
| 6958 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6959 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6960 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6961 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6962 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6963 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6964 | if (kstrtol(s, 0, &p->u.unsize)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6965 | pr_err("bad number for schedsize"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6966 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6967 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6968 | break; |
| 6969 | |
| 6970 | case F2SIZ: /* f2200 structure size */ |
| 6971 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6972 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6973 | |
| 6974 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6975 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6976 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6977 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6978 | p = p->next; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6979 | p->type = FSNODE; |
| 6980 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6981 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 6982 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6983 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6984 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6985 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 6986 | if (kstrtol(s, 0, &p->u.f2size)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6987 | pr_err("bad number for f2200size"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6988 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6989 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 6990 | break; |
| 6991 | |
| 6992 | case VPSIZ: /* vpix structure size */ |
| 6993 | if (dgap_checknode(p)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6994 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6995 | |
| 6996 | p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 6997 | if (!p->next) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 6998 | return -1; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 6999 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7000 | p = p->next; |
Daeseok Youn | 8251223 | 2014-07-15 18:50:37 +0900 | [diff] [blame] | 7001 | p->type = VSNODE; |
| 7002 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7003 | s = dgap_getword(in); |
Mark Hounschell | 9a133a9 | 2014-05-28 16:17:45 -0400 | [diff] [blame] | 7004 | if (!s) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 7005 | pr_err("unexpected end of file"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7006 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7007 | } |
Mark Hounschell | 67d5dc8 | 2014-03-19 15:46:57 -0400 | [diff] [blame] | 7008 | if (kstrtol(s, 0, &p->u.vpixsize)) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 7009 | pr_err("bad number for vpixsize"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7010 | return -1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7011 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7012 | break; |
| 7013 | } |
| 7014 | } |
| 7015 | } |
| 7016 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7017 | /* |
| 7018 | * dgap_sindex: much like index(), but it looks for a match of any character in |
| 7019 | * the group, and returns that position. If the first character is a ^, then |
| 7020 | * this will match the first occurrence not in that group. |
| 7021 | */ |
Mark Hounschell | 9b073ac | 2014-03-03 13:45:42 -0500 | [diff] [blame] | 7022 | static char *dgap_sindex(char *string, char *group) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7023 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 7024 | char *ptr; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7025 | |
| 7026 | if (!string || !group) |
| 7027 | return (char *) NULL; |
| 7028 | |
| 7029 | if (*group == '^') { |
| 7030 | group++; |
| 7031 | for (; *string; string++) { |
| 7032 | for (ptr = group; *ptr; ptr++) { |
| 7033 | if (*ptr == *string) |
| 7034 | break; |
| 7035 | } |
| 7036 | if (*ptr == '\0') |
| 7037 | return string; |
| 7038 | } |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 7039 | } else { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7040 | for (; *string; string++) { |
| 7041 | for (ptr = group; *ptr; ptr++) { |
| 7042 | if (*ptr == *string) |
| 7043 | return string; |
| 7044 | } |
| 7045 | } |
| 7046 | } |
| 7047 | |
| 7048 | return (char *) NULL; |
| 7049 | } |
| 7050 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7051 | /* |
| 7052 | * Get a token from the input file; return 0 if end of file is reached |
| 7053 | */ |
Daeseok Youn | 7bab00f | 2014-07-15 18:49:52 +0900 | [diff] [blame] | 7054 | static int dgap_gettok(char **in) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7055 | { |
Mark Hounschell | 174efc1 | 2014-05-23 12:54:04 -0400 | [diff] [blame] | 7056 | char *w; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7057 | struct toklist *t; |
| 7058 | |
Daeseok Youn | e9cc5b2 | 2014-07-15 18:49:09 +0900 | [diff] [blame] | 7059 | if (strstr(dgap_cword, "board")) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7060 | w = dgap_getword(in); |
| 7061 | snprintf(dgap_cword, MAXCWORD, "%s", w); |
Daeseok Youn | 77a4492 | 2014-08-09 14:38:14 +0900 | [diff] [blame] | 7062 | for (t = dgap_brdtype; t->token != 0; t++) { |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 7063 | if (!strcmp(w, t->string)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7064 | return t->token; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7065 | } |
Mark Hounschell | 305ec87 | 2014-02-28 12:42:13 -0500 | [diff] [blame] | 7066 | } else { |
Mark Hounschell | 9b073ac | 2014-03-03 13:45:42 -0500 | [diff] [blame] | 7067 | while ((w = dgap_getword(in))) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7068 | snprintf(dgap_cword, MAXCWORD, "%s", w); |
| 7069 | for (t = dgap_tlist; t->token != 0; t++) { |
Mark Hounschell | b115b02 | 2014-02-28 12:42:15 -0500 | [diff] [blame] | 7070 | if (!strcmp(w, t->string)) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7071 | return t->token; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7072 | } |
| 7073 | } |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7074 | } |
Daeseok Youn | 77a4492 | 2014-08-09 14:38:14 +0900 | [diff] [blame] | 7075 | |
| 7076 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7077 | } |
| 7078 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7079 | /* |
| 7080 | * get a word from the input stream, also keep track of current line number. |
| 7081 | * words are separated by whitespace. |
| 7082 | */ |
| 7083 | static char *dgap_getword(char **in) |
| 7084 | { |
| 7085 | char *ret_ptr = *in; |
| 7086 | |
Mark Hounschell | 7d6069d7 | 2014-02-28 12:42:10 -0500 | [diff] [blame] | 7087 | char *ptr = dgap_sindex(*in, " \t\n"); |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7088 | |
| 7089 | /* If no word found, return null */ |
| 7090 | if (!ptr) |
| 7091 | return NULL; |
| 7092 | |
| 7093 | /* Mark new location for our buffer */ |
| 7094 | *ptr = '\0'; |
| 7095 | *in = ptr + 1; |
| 7096 | |
| 7097 | /* Eat any extra spaces/tabs/newlines that might be present */ |
Mark Hounschell | 93fb1e2 | 2014-03-10 15:46:55 -0400 | [diff] [blame] | 7098 | while (*in && **in && ((**in == ' ') || |
| 7099 | (**in == '\t') || |
| 7100 | (**in == '\n'))) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7101 | **in = '\0'; |
| 7102 | *in = *in + 1; |
| 7103 | } |
| 7104 | |
| 7105 | return ret_ptr; |
| 7106 | } |
| 7107 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7108 | /* |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7109 | * dgap_checknode: see if all the necessary info has been supplied for a node |
| 7110 | * before creating the next node. |
| 7111 | */ |
| 7112 | static int dgap_checknode(struct cnode *p) |
| 7113 | { |
| 7114 | switch (p->type) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7115 | case LNODE: |
| 7116 | if (p->u.line.v_speed == 0) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 7117 | pr_err("line speed not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7118 | return 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7119 | } |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7120 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7121 | |
| 7122 | case CNODE: |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7123 | if (p->u.conc.v_speed == 0) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 7124 | pr_err("concentrator line speed not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7125 | return 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7126 | } |
| 7127 | if (p->u.conc.v_nport == 0) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 7128 | pr_err("number of ports on concentrator not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7129 | return 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7130 | } |
| 7131 | if (p->u.conc.v_id == 0) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 7132 | pr_err("concentrator id letter not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7133 | return 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7134 | } |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7135 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7136 | |
| 7137 | case MNODE: |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7138 | if (p->u.module.v_nport == 0) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 7139 | pr_err("number of ports on EBI module not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7140 | return 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7141 | } |
| 7142 | if (p->u.module.v_id == 0) { |
Daeseok Youn | 6c66843d | 2014-08-09 14:39:29 +0900 | [diff] [blame] | 7143 | pr_err("EBI module id letter not specified"); |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7144 | return 1; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7145 | } |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7146 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7147 | } |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7148 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7149 | } |
| 7150 | |
| 7151 | /* |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7152 | * Given a board pointer, returns whether we should use interrupts or not. |
| 7153 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 7154 | static uint dgap_config_get_useintr(struct board_t *bd) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7155 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 7156 | struct cnode *p; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7157 | |
| 7158 | if (!bd) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7159 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7160 | |
| 7161 | for (p = bd->bd_config; p; p = p->next) { |
Mark Hounschell | 0c24b23 | 2014-05-23 13:45:57 -0400 | [diff] [blame] | 7162 | if (p->type == INTRNODE) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7163 | /* |
| 7164 | * check for pcxr types. |
| 7165 | */ |
| 7166 | return p->u.useintr; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7167 | } |
| 7168 | } |
| 7169 | |
| 7170 | /* If not found, then don't turn on interrupts. */ |
| 7171 | return 0; |
| 7172 | } |
| 7173 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7174 | /* |
| 7175 | * Given a board pointer, returns whether we turn on altpin or not. |
| 7176 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 7177 | static uint dgap_config_get_altpin(struct board_t *bd) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7178 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 7179 | struct cnode *p; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7180 | |
| 7181 | if (!bd) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7182 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7183 | |
| 7184 | for (p = bd->bd_config; p; p = p->next) { |
Mark Hounschell | 0c24b23 | 2014-05-23 13:45:57 -0400 | [diff] [blame] | 7185 | if (p->type == ANODE) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7186 | /* |
| 7187 | * check for pcxr types. |
| 7188 | */ |
| 7189 | return p->u.altpin; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7190 | } |
| 7191 | } |
| 7192 | |
| 7193 | /* If not found, then don't turn on interrupts. */ |
| 7194 | return 0; |
| 7195 | } |
| 7196 | |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7197 | /* |
| 7198 | * Given a specific type of board, if found, detached link and |
| 7199 | * returns the first occurrence in the list. |
| 7200 | */ |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 7201 | static struct cnode *dgap_find_config(int type, int bus, int slot) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7202 | { |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 7203 | struct cnode *p, *prev, *prev2, *found; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7204 | |
| 7205 | p = &dgap_head; |
| 7206 | |
Mark Hounschell | ee48710 | 2014-05-23 13:13:03 -0400 | [diff] [blame] | 7207 | while (p->next) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7208 | prev = p; |
| 7209 | p = p->next; |
| 7210 | |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7211 | if (p->type != BNODE) |
| 7212 | continue; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7213 | |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7214 | if (p->u.board.type != type) |
| 7215 | continue; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7216 | |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7217 | if (p->u.board.v_pcibus && |
| 7218 | p->u.board.pcibus != bus) |
| 7219 | continue; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7220 | |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7221 | if (p->u.board.v_pcislot && |
| 7222 | p->u.board.pcislot != slot) |
| 7223 | continue; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7224 | |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7225 | found = p; |
| 7226 | /* |
| 7227 | * Keep walking thru the list till we |
| 7228 | * find the next board. |
| 7229 | */ |
| 7230 | while (p->next) { |
| 7231 | prev2 = p; |
| 7232 | p = p->next; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7233 | |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7234 | if (p->type != BNODE) |
| 7235 | continue; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7236 | |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7237 | /* |
| 7238 | * Mark the end of our 1 board |
| 7239 | * chain of configs. |
| 7240 | */ |
| 7241 | prev2->next = NULL; |
| 7242 | |
| 7243 | /* |
| 7244 | * Link the "next" board to the |
| 7245 | * previous board, effectively |
| 7246 | * "unlinking" our board from |
| 7247 | * the main config. |
| 7248 | */ |
| 7249 | prev->next = p; |
| 7250 | |
| 7251 | return found; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7252 | } |
Mark Hounschell | 0be048c | 2014-05-28 16:17:55 -0400 | [diff] [blame] | 7253 | /* |
| 7254 | * It must be the last board in the list. |
| 7255 | */ |
| 7256 | prev->next = NULL; |
| 7257 | return found; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7258 | } |
| 7259 | return NULL; |
| 7260 | } |
| 7261 | |
| 7262 | /* |
| 7263 | * Given a board pointer, walks the config link, counting up |
| 7264 | * all ports user specified should be on the board. |
| 7265 | * (This does NOT mean they are all actually present right now tho) |
| 7266 | */ |
Mark Hounschell | bbfbe83 | 2014-03-19 11:10:52 -0400 | [diff] [blame] | 7267 | static uint dgap_config_get_num_prts(struct board_t *bd) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7268 | { |
| 7269 | int count = 0; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 7270 | struct cnode *p; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7271 | |
| 7272 | if (!bd) |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7273 | return 0; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7274 | |
| 7275 | for (p = bd->bd_config; p; p = p->next) { |
| 7276 | |
| 7277 | switch (p->type) { |
| 7278 | case BNODE: |
| 7279 | /* |
| 7280 | * check for pcxr types. |
| 7281 | */ |
| 7282 | if (p->u.board.type > EPCFE) |
| 7283 | count += p->u.board.nport; |
| 7284 | break; |
| 7285 | case CNODE: |
| 7286 | count += p->u.conc.nport; |
| 7287 | break; |
| 7288 | case MNODE: |
| 7289 | count += p->u.module.nport; |
| 7290 | break; |
| 7291 | } |
| 7292 | } |
Mark Hounschell | cf42c34 | 2014-02-28 12:42:09 -0500 | [diff] [blame] | 7293 | return count; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7294 | } |
| 7295 | |
Mark Hounschell | fe0ef8e | 2014-02-19 13:12:13 -0500 | [diff] [blame] | 7296 | static char *dgap_create_config_string(struct board_t *bd, char *string) |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7297 | { |
| 7298 | char *ptr = string; |
Mark Hounschell | 7dfa383 | 2014-05-23 10:14:02 -0400 | [diff] [blame] | 7299 | struct cnode *p; |
| 7300 | struct cnode *q; |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7301 | int speed; |
| 7302 | |
| 7303 | if (!bd) { |
| 7304 | *ptr = 0xff; |
| 7305 | return string; |
| 7306 | } |
| 7307 | |
| 7308 | for (p = bd->bd_config; p; p = p->next) { |
| 7309 | |
| 7310 | switch (p->type) { |
| 7311 | case LNODE: |
| 7312 | *ptr = '\0'; |
| 7313 | ptr++; |
| 7314 | *ptr = p->u.line.speed; |
| 7315 | ptr++; |
| 7316 | break; |
| 7317 | case CNODE: |
| 7318 | /* |
| 7319 | * Because the EPC/con concentrators can have EM modules |
Mark Hounschell | 93fb1e2 | 2014-03-10 15:46:55 -0400 | [diff] [blame] | 7320 | * hanging off of them, we have to walk ahead in the |
| 7321 | * list and keep adding the number of ports on each EM |
| 7322 | * to the config. UGH! |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7323 | */ |
| 7324 | speed = p->u.conc.speed; |
| 7325 | q = p->next; |
Mark Hounschell | ee48710 | 2014-05-23 13:13:03 -0400 | [diff] [blame] | 7326 | if (q && (q->type == MNODE)) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7327 | *ptr = (p->u.conc.nport + 0x80); |
| 7328 | ptr++; |
| 7329 | p = q; |
Mark Hounschell | ee48710 | 2014-05-23 13:13:03 -0400 | [diff] [blame] | 7330 | while (q->next && (q->next->type) == MNODE) { |
Mark Hounschell | 69edaa2 | 2014-02-19 13:12:02 -0500 | [diff] [blame] | 7331 | *ptr = (q->u.module.nport + 0x80); |
| 7332 | ptr++; |
| 7333 | p = q; |
| 7334 | q = q->next; |
| 7335 | } |
| 7336 | *ptr = q->u.module.nport; |
| 7337 | ptr++; |
| 7338 | } else { |
| 7339 | *ptr = p->u.conc.nport; |
| 7340 | ptr++; |
| 7341 | } |
| 7342 | |
| 7343 | *ptr = speed; |
| 7344 | ptr++; |
| 7345 | break; |
| 7346 | } |
| 7347 | } |
| 7348 | |
| 7349 | *ptr = 0xff; |
| 7350 | return string; |
| 7351 | } |