Commit d1c815e549ff40f9e9db65654855118e6bdff6a4

Authored by Alan Cox
Committed by Linus Torvalds
1 parent 542f548236

tty: relock epca

Bring epca into line with the port locking.

Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 104 additions and 91 deletions Inline Diff

1 /* 1 /*
2 Copyright (C) 1996 Digi International. 2 Copyright (C) 1996 Digi International.
3 3
4 For technical support please email digiLinux@dgii.com or 4 For technical support please email digiLinux@dgii.com or
5 call Digi tech support at (612) 912-3456 5 call Digi tech support at (612) 912-3456
6 6
7 ** This driver is no longer supported by Digi ** 7 ** This driver is no longer supported by Digi **
8 8
9 Much of this design and code came from epca.c which was 9 Much of this design and code came from epca.c which was
10 copyright (C) 1994, 1995 Troy De Jongh, and subsquently 10 copyright (C) 1994, 1995 Troy De Jongh, and subsquently
11 modified by David Nugent, Christoph Lameter, Mike McLagan. 11 modified by David Nugent, Christoph Lameter, Mike McLagan.
12 12
13 This program is free software; you can redistribute it and/or modify 13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by 14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or 15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version. 16 (at your option) any later version.
17 17
18 This program is distributed in the hope that it will be useful, 18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details. 21 GNU General Public License for more details.
22 22
23 You should have received a copy of the GNU General Public License 23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */ 26 */
27 /* See README.epca for change history --DAT*/ 27 /* See README.epca for change history --DAT*/
28 28
29 #include <linux/module.h> 29 #include <linux/module.h>
30 #include <linux/kernel.h> 30 #include <linux/kernel.h>
31 #include <linux/types.h> 31 #include <linux/types.h>
32 #include <linux/init.h> 32 #include <linux/init.h>
33 #include <linux/serial.h> 33 #include <linux/serial.h>
34 #include <linux/delay.h> 34 #include <linux/delay.h>
35 #include <linux/ctype.h> 35 #include <linux/ctype.h>
36 #include <linux/tty.h> 36 #include <linux/tty.h>
37 #include <linux/tty_flip.h> 37 #include <linux/tty_flip.h>
38 #include <linux/slab.h> 38 #include <linux/slab.h>
39 #include <linux/ioport.h> 39 #include <linux/ioport.h>
40 #include <linux/interrupt.h> 40 #include <linux/interrupt.h>
41 #include <linux/uaccess.h> 41 #include <linux/uaccess.h>
42 #include <linux/io.h> 42 #include <linux/io.h>
43 #include <linux/spinlock.h> 43 #include <linux/spinlock.h>
44 #include <linux/pci.h> 44 #include <linux/pci.h>
45 #include "digiPCI.h" 45 #include "digiPCI.h"
46 46
47 47
48 #include "digi1.h" 48 #include "digi1.h"
49 #include "digiFep1.h" 49 #include "digiFep1.h"
50 #include "epca.h" 50 #include "epca.h"
51 #include "epcaconfig.h" 51 #include "epcaconfig.h"
52 52
53 #define VERSION "1.3.0.1-LK2.6" 53 #define VERSION "1.3.0.1-LK2.6"
54 54
55 /* This major needs to be submitted to Linux to join the majors list */ 55 /* This major needs to be submitted to Linux to join the majors list */
56 #define DIGIINFOMAJOR 35 /* For Digi specific ioctl */ 56 #define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
57 57
58 58
59 #define MAXCARDS 7 59 #define MAXCARDS 7
60 #define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg) 60 #define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
61 61
62 #define PFX "epca: " 62 #define PFX "epca: "
63 63
64 static int nbdevs, num_cards, liloconfig; 64 static int nbdevs, num_cards, liloconfig;
65 static int digi_poller_inhibited = 1 ; 65 static int digi_poller_inhibited = 1 ;
66 66
67 static int setup_error_code; 67 static int setup_error_code;
68 static int invalid_lilo_config; 68 static int invalid_lilo_config;
69 69
70 /* 70 /*
71 * The ISA boards do window flipping into the same spaces so its only sane with 71 * The ISA boards do window flipping into the same spaces so its only sane with
72 * a single lock. It's still pretty efficient. 72 * a single lock. It's still pretty efficient. This lock guards the hardware
73 * and the tty_port lock guards the kernel side stuff like use counts. Take
74 * this lock inside the port lock if you must take both.
73 */ 75 */
74 static DEFINE_SPINLOCK(epca_lock); 76 static DEFINE_SPINLOCK(epca_lock);
75 77
76 /* MAXBOARDS is typically 12, but ISA and EISA cards are restricted 78 /* MAXBOARDS is typically 12, but ISA and EISA cards are restricted
77 to 7 below. */ 79 to 7 below. */
78 static struct board_info boards[MAXBOARDS]; 80 static struct board_info boards[MAXBOARDS];
79 81
80 static struct tty_driver *pc_driver; 82 static struct tty_driver *pc_driver;
81 static struct tty_driver *pc_info; 83 static struct tty_driver *pc_info;
82 84
83 /* ------------------ Begin Digi specific structures -------------------- */ 85 /* ------------------ Begin Digi specific structures -------------------- */
84 86
85 /* 87 /*
86 * digi_channels represents an array of structures that keep track of each 88 * digi_channels represents an array of structures that keep track of each
87 * channel of the Digi product. Information such as transmit and receive 89 * channel of the Digi product. Information such as transmit and receive
88 * pointers, termio data, and signal definitions (DTR, CTS, etc ...) are stored 90 * pointers, termio data, and signal definitions (DTR, CTS, etc ...) are stored
89 * here. This structure is NOT used to overlay the cards physical channel 91 * here. This structure is NOT used to overlay the cards physical channel
90 * structure. 92 * structure.
91 */ 93 */
92 static struct channel digi_channels[MAX_ALLOC]; 94 static struct channel digi_channels[MAX_ALLOC];
93 95
94 /* 96 /*
95 * card_ptr is an array used to hold the address of the first channel structure 97 * card_ptr is an array used to hold the address of the first channel structure
96 * of each card. This array will hold the addresses of various channels located 98 * of each card. This array will hold the addresses of various channels located
97 * in digi_channels. 99 * in digi_channels.
98 */ 100 */
99 static struct channel *card_ptr[MAXCARDS]; 101 static struct channel *card_ptr[MAXCARDS];
100 102
101 static struct timer_list epca_timer; 103 static struct timer_list epca_timer;
102 104
103 /* 105 /*
104 * Begin generic memory functions. These functions will be alias (point at) 106 * Begin generic memory functions. These functions will be alias (point at)
105 * more specific functions dependent on the board being configured. 107 * more specific functions dependent on the board being configured.
106 */ 108 */
107 static void memwinon(struct board_info *b, unsigned int win); 109 static void memwinon(struct board_info *b, unsigned int win);
108 static void memwinoff(struct board_info *b, unsigned int win); 110 static void memwinoff(struct board_info *b, unsigned int win);
109 static void globalwinon(struct channel *ch); 111 static void globalwinon(struct channel *ch);
110 static void rxwinon(struct channel *ch); 112 static void rxwinon(struct channel *ch);
111 static void txwinon(struct channel *ch); 113 static void txwinon(struct channel *ch);
112 static void memoff(struct channel *ch); 114 static void memoff(struct channel *ch);
113 static void assertgwinon(struct channel *ch); 115 static void assertgwinon(struct channel *ch);
114 static void assertmemoff(struct channel *ch); 116 static void assertmemoff(struct channel *ch);
115 117
116 /* ---- Begin more 'specific' memory functions for cx_like products --- */ 118 /* ---- Begin more 'specific' memory functions for cx_like products --- */
117 119
118 static void pcxem_memwinon(struct board_info *b, unsigned int win); 120 static void pcxem_memwinon(struct board_info *b, unsigned int win);
119 static void pcxem_memwinoff(struct board_info *b, unsigned int win); 121 static void pcxem_memwinoff(struct board_info *b, unsigned int win);
120 static void pcxem_globalwinon(struct channel *ch); 122 static void pcxem_globalwinon(struct channel *ch);
121 static void pcxem_rxwinon(struct channel *ch); 123 static void pcxem_rxwinon(struct channel *ch);
122 static void pcxem_txwinon(struct channel *ch); 124 static void pcxem_txwinon(struct channel *ch);
123 static void pcxem_memoff(struct channel *ch); 125 static void pcxem_memoff(struct channel *ch);
124 126
125 /* ------ Begin more 'specific' memory functions for the pcxe ------- */ 127 /* ------ Begin more 'specific' memory functions for the pcxe ------- */
126 128
127 static void pcxe_memwinon(struct board_info *b, unsigned int win); 129 static void pcxe_memwinon(struct board_info *b, unsigned int win);
128 static void pcxe_memwinoff(struct board_info *b, unsigned int win); 130 static void pcxe_memwinoff(struct board_info *b, unsigned int win);
129 static void pcxe_globalwinon(struct channel *ch); 131 static void pcxe_globalwinon(struct channel *ch);
130 static void pcxe_rxwinon(struct channel *ch); 132 static void pcxe_rxwinon(struct channel *ch);
131 static void pcxe_txwinon(struct channel *ch); 133 static void pcxe_txwinon(struct channel *ch);
132 static void pcxe_memoff(struct channel *ch); 134 static void pcxe_memoff(struct channel *ch);
133 135
134 /* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */ 136 /* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
135 /* Note : pc64xe and pcxi share the same windowing routines */ 137 /* Note : pc64xe and pcxi share the same windowing routines */
136 138
137 static void pcxi_memwinon(struct board_info *b, unsigned int win); 139 static void pcxi_memwinon(struct board_info *b, unsigned int win);
138 static void pcxi_memwinoff(struct board_info *b, unsigned int win); 140 static void pcxi_memwinoff(struct board_info *b, unsigned int win);
139 static void pcxi_globalwinon(struct channel *ch); 141 static void pcxi_globalwinon(struct channel *ch);
140 static void pcxi_rxwinon(struct channel *ch); 142 static void pcxi_rxwinon(struct channel *ch);
141 static void pcxi_txwinon(struct channel *ch); 143 static void pcxi_txwinon(struct channel *ch);
142 static void pcxi_memoff(struct channel *ch); 144 static void pcxi_memoff(struct channel *ch);
143 145
144 /* - Begin 'specific' do nothing memory functions needed for some cards - */ 146 /* - Begin 'specific' do nothing memory functions needed for some cards - */
145 147
146 static void dummy_memwinon(struct board_info *b, unsigned int win); 148 static void dummy_memwinon(struct board_info *b, unsigned int win);
147 static void dummy_memwinoff(struct board_info *b, unsigned int win); 149 static void dummy_memwinoff(struct board_info *b, unsigned int win);
148 static void dummy_globalwinon(struct channel *ch); 150 static void dummy_globalwinon(struct channel *ch);
149 static void dummy_rxwinon(struct channel *ch); 151 static void dummy_rxwinon(struct channel *ch);
150 static void dummy_txwinon(struct channel *ch); 152 static void dummy_txwinon(struct channel *ch);
151 static void dummy_memoff(struct channel *ch); 153 static void dummy_memoff(struct channel *ch);
152 static void dummy_assertgwinon(struct channel *ch); 154 static void dummy_assertgwinon(struct channel *ch);
153 static void dummy_assertmemoff(struct channel *ch); 155 static void dummy_assertmemoff(struct channel *ch);
154 156
155 static struct channel *verifyChannel(struct tty_struct *); 157 static struct channel *verifyChannel(struct tty_struct *);
156 static void pc_sched_event(struct channel *, int); 158 static void pc_sched_event(struct channel *, int);
157 static void epca_error(int, char *); 159 static void epca_error(int, char *);
158 static void pc_close(struct tty_struct *, struct file *); 160 static void pc_close(struct tty_struct *, struct file *);
159 static void shutdown(struct channel *); 161 static void shutdown(struct channel *, struct tty_struct *tty);
160 static void pc_hangup(struct tty_struct *); 162 static void pc_hangup(struct tty_struct *);
161 static int pc_write_room(struct tty_struct *); 163 static int pc_write_room(struct tty_struct *);
162 static int pc_chars_in_buffer(struct tty_struct *); 164 static int pc_chars_in_buffer(struct tty_struct *);
163 static void pc_flush_buffer(struct tty_struct *); 165 static void pc_flush_buffer(struct tty_struct *);
164 static void pc_flush_chars(struct tty_struct *); 166 static void pc_flush_chars(struct tty_struct *);
165 static int block_til_ready(struct tty_struct *, struct file *, 167 static int block_til_ready(struct tty_struct *, struct file *,
166 struct channel *); 168 struct channel *);
167 static int pc_open(struct tty_struct *, struct file *); 169 static int pc_open(struct tty_struct *, struct file *);
168 static void post_fep_init(unsigned int crd); 170 static void post_fep_init(unsigned int crd);
169 static void epcapoll(unsigned long); 171 static void epcapoll(unsigned long);
170 static void doevent(int); 172 static void doevent(int);
171 static void fepcmd(struct channel *, int, int, int, int, int); 173 static void fepcmd(struct channel *, int, int, int, int, int);
172 static unsigned termios2digi_h(struct channel *ch, unsigned); 174 static unsigned termios2digi_h(struct channel *ch, unsigned);
173 static unsigned termios2digi_i(struct channel *ch, unsigned); 175 static unsigned termios2digi_i(struct channel *ch, unsigned);
174 static unsigned termios2digi_c(struct channel *ch, unsigned); 176 static unsigned termios2digi_c(struct channel *ch, unsigned);
175 static void epcaparam(struct tty_struct *, struct channel *); 177 static void epcaparam(struct tty_struct *, struct channel *);
176 static void receive_data(struct channel *); 178 static void receive_data(struct channel *);
177 static int pc_ioctl(struct tty_struct *, struct file *, 179 static int pc_ioctl(struct tty_struct *, struct file *,
178 unsigned int, unsigned long); 180 unsigned int, unsigned long);
179 static int info_ioctl(struct tty_struct *, struct file *, 181 static int info_ioctl(struct tty_struct *, struct file *,
180 unsigned int, unsigned long); 182 unsigned int, unsigned long);
181 static void pc_set_termios(struct tty_struct *, struct ktermios *); 183 static void pc_set_termios(struct tty_struct *, struct ktermios *);
182 static void do_softint(struct work_struct *work); 184 static void do_softint(struct work_struct *work);
183 static void pc_stop(struct tty_struct *); 185 static void pc_stop(struct tty_struct *);
184 static void pc_start(struct tty_struct *); 186 static void pc_start(struct tty_struct *);
185 static void pc_throttle(struct tty_struct *tty); 187 static void pc_throttle(struct tty_struct *tty);
186 static void pc_unthrottle(struct tty_struct *tty); 188 static void pc_unthrottle(struct tty_struct *tty);
187 static int pc_send_break(struct tty_struct *tty, int msec); 189 static int pc_send_break(struct tty_struct *tty, int msec);
188 static void setup_empty_event(struct tty_struct *tty, struct channel *ch); 190 static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
189 191
190 static int pc_write(struct tty_struct *, const unsigned char *, int); 192 static int pc_write(struct tty_struct *, const unsigned char *, int);
191 static int pc_init(void); 193 static int pc_init(void);
192 static int init_PCI(void); 194 static int init_PCI(void);
193 195
194 /* 196 /*
195 * Table of functions for each board to handle memory. Mantaining parallelism 197 * Table of functions for each board to handle memory. Mantaining parallelism
196 * is a *very* good idea here. The idea is for the runtime code to blindly call 198 * is a *very* good idea here. The idea is for the runtime code to blindly call
197 * these functions, not knowing/caring about the underlying hardware. This 199 * these functions, not knowing/caring about the underlying hardware. This
198 * stuff should contain no conditionals; if more functionality is needed a 200 * stuff should contain no conditionals; if more functionality is needed a
199 * different entry should be established. These calls are the interface calls 201 * different entry should be established. These calls are the interface calls
200 * and are the only functions that should be accessed. Anyone caught making 202 * and are the only functions that should be accessed. Anyone caught making
201 * direct calls deserves what they get. 203 * direct calls deserves what they get.
202 */ 204 */
203 static void memwinon(struct board_info *b, unsigned int win) 205 static void memwinon(struct board_info *b, unsigned int win)
204 { 206 {
205 b->memwinon(b, win); 207 b->memwinon(b, win);
206 } 208 }
207 209
208 static void memwinoff(struct board_info *b, unsigned int win) 210 static void memwinoff(struct board_info *b, unsigned int win)
209 { 211 {
210 b->memwinoff(b, win); 212 b->memwinoff(b, win);
211 } 213 }
212 214
213 static void globalwinon(struct channel *ch) 215 static void globalwinon(struct channel *ch)
214 { 216 {
215 ch->board->globalwinon(ch); 217 ch->board->globalwinon(ch);
216 } 218 }
217 219
218 static void rxwinon(struct channel *ch) 220 static void rxwinon(struct channel *ch)
219 { 221 {
220 ch->board->rxwinon(ch); 222 ch->board->rxwinon(ch);
221 } 223 }
222 224
223 static void txwinon(struct channel *ch) 225 static void txwinon(struct channel *ch)
224 { 226 {
225 ch->board->txwinon(ch); 227 ch->board->txwinon(ch);
226 } 228 }
227 229
228 static void memoff(struct channel *ch) 230 static void memoff(struct channel *ch)
229 { 231 {
230 ch->board->memoff(ch); 232 ch->board->memoff(ch);
231 } 233 }
232 static void assertgwinon(struct channel *ch) 234 static void assertgwinon(struct channel *ch)
233 { 235 {
234 ch->board->assertgwinon(ch); 236 ch->board->assertgwinon(ch);
235 } 237 }
236 238
237 static void assertmemoff(struct channel *ch) 239 static void assertmemoff(struct channel *ch)
238 { 240 {
239 ch->board->assertmemoff(ch); 241 ch->board->assertmemoff(ch);
240 } 242 }
241 243
242 /* PCXEM windowing is the same as that used in the PCXR and CX series cards. */ 244 /* PCXEM windowing is the same as that used in the PCXR and CX series cards. */
243 static void pcxem_memwinon(struct board_info *b, unsigned int win) 245 static void pcxem_memwinon(struct board_info *b, unsigned int win)
244 { 246 {
245 outb_p(FEPWIN | win, b->port + 1); 247 outb_p(FEPWIN | win, b->port + 1);
246 } 248 }
247 249
248 static void pcxem_memwinoff(struct board_info *b, unsigned int win) 250 static void pcxem_memwinoff(struct board_info *b, unsigned int win)
249 { 251 {
250 outb_p(0, b->port + 1); 252 outb_p(0, b->port + 1);
251 } 253 }
252 254
253 static void pcxem_globalwinon(struct channel *ch) 255 static void pcxem_globalwinon(struct channel *ch)
254 { 256 {
255 outb_p(FEPWIN, (int)ch->board->port + 1); 257 outb_p(FEPWIN, (int)ch->board->port + 1);
256 } 258 }
257 259
258 static void pcxem_rxwinon(struct channel *ch) 260 static void pcxem_rxwinon(struct channel *ch)
259 { 261 {
260 outb_p(ch->rxwin, (int)ch->board->port + 1); 262 outb_p(ch->rxwin, (int)ch->board->port + 1);
261 } 263 }
262 264
263 static void pcxem_txwinon(struct channel *ch) 265 static void pcxem_txwinon(struct channel *ch)
264 { 266 {
265 outb_p(ch->txwin, (int)ch->board->port + 1); 267 outb_p(ch->txwin, (int)ch->board->port + 1);
266 } 268 }
267 269
268 static void pcxem_memoff(struct channel *ch) 270 static void pcxem_memoff(struct channel *ch)
269 { 271 {
270 outb_p(0, (int)ch->board->port + 1); 272 outb_p(0, (int)ch->board->port + 1);
271 } 273 }
272 274
273 /* ----------------- Begin pcxe memory window stuff ------------------ */ 275 /* ----------------- Begin pcxe memory window stuff ------------------ */
274 static void pcxe_memwinon(struct board_info *b, unsigned int win) 276 static void pcxe_memwinon(struct board_info *b, unsigned int win)
275 { 277 {
276 outb_p(FEPWIN | win, b->port + 1); 278 outb_p(FEPWIN | win, b->port + 1);
277 } 279 }
278 280
279 static void pcxe_memwinoff(struct board_info *b, unsigned int win) 281 static void pcxe_memwinoff(struct board_info *b, unsigned int win)
280 { 282 {
281 outb_p(inb(b->port) & ~FEPMEM, b->port + 1); 283 outb_p(inb(b->port) & ~FEPMEM, b->port + 1);
282 outb_p(0, b->port + 1); 284 outb_p(0, b->port + 1);
283 } 285 }
284 286
285 static void pcxe_globalwinon(struct channel *ch) 287 static void pcxe_globalwinon(struct channel *ch)
286 { 288 {
287 outb_p(FEPWIN, (int)ch->board->port + 1); 289 outb_p(FEPWIN, (int)ch->board->port + 1);
288 } 290 }
289 291
290 static void pcxe_rxwinon(struct channel *ch) 292 static void pcxe_rxwinon(struct channel *ch)
291 { 293 {
292 outb_p(ch->rxwin, (int)ch->board->port + 1); 294 outb_p(ch->rxwin, (int)ch->board->port + 1);
293 } 295 }
294 296
295 static void pcxe_txwinon(struct channel *ch) 297 static void pcxe_txwinon(struct channel *ch)
296 { 298 {
297 outb_p(ch->txwin, (int)ch->board->port + 1); 299 outb_p(ch->txwin, (int)ch->board->port + 1);
298 } 300 }
299 301
300 static void pcxe_memoff(struct channel *ch) 302 static void pcxe_memoff(struct channel *ch)
301 { 303 {
302 outb_p(0, (int)ch->board->port); 304 outb_p(0, (int)ch->board->port);
303 outb_p(0, (int)ch->board->port + 1); 305 outb_p(0, (int)ch->board->port + 1);
304 } 306 }
305 307
306 /* ------------- Begin pc64xe and pcxi memory window stuff -------------- */ 308 /* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
307 static void pcxi_memwinon(struct board_info *b, unsigned int win) 309 static void pcxi_memwinon(struct board_info *b, unsigned int win)
308 { 310 {
309 outb_p(inb(b->port) | FEPMEM, b->port); 311 outb_p(inb(b->port) | FEPMEM, b->port);
310 } 312 }
311 313
312 static void pcxi_memwinoff(struct board_info *b, unsigned int win) 314 static void pcxi_memwinoff(struct board_info *b, unsigned int win)
313 { 315 {
314 outb_p(inb(b->port) & ~FEPMEM, b->port); 316 outb_p(inb(b->port) & ~FEPMEM, b->port);
315 } 317 }
316 318
317 static void pcxi_globalwinon(struct channel *ch) 319 static void pcxi_globalwinon(struct channel *ch)
318 { 320 {
319 outb_p(FEPMEM, ch->board->port); 321 outb_p(FEPMEM, ch->board->port);
320 } 322 }
321 323
322 static void pcxi_rxwinon(struct channel *ch) 324 static void pcxi_rxwinon(struct channel *ch)
323 { 325 {
324 outb_p(FEPMEM, ch->board->port); 326 outb_p(FEPMEM, ch->board->port);
325 } 327 }
326 328
327 static void pcxi_txwinon(struct channel *ch) 329 static void pcxi_txwinon(struct channel *ch)
328 { 330 {
329 outb_p(FEPMEM, ch->board->port); 331 outb_p(FEPMEM, ch->board->port);
330 } 332 }
331 333
332 static void pcxi_memoff(struct channel *ch) 334 static void pcxi_memoff(struct channel *ch)
333 { 335 {
334 outb_p(0, ch->board->port); 336 outb_p(0, ch->board->port);
335 } 337 }
336 338
337 static void pcxi_assertgwinon(struct channel *ch) 339 static void pcxi_assertgwinon(struct channel *ch)
338 { 340 {
339 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off"); 341 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
340 } 342 }
341 343
342 static void pcxi_assertmemoff(struct channel *ch) 344 static void pcxi_assertmemoff(struct channel *ch)
343 { 345 {
344 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on"); 346 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
345 } 347 }
346 348
347 /* 349 /*
348 * Not all of the cards need specific memory windowing routines. Some cards 350 * Not all of the cards need specific memory windowing routines. Some cards
349 * (Such as PCI) needs no windowing routines at all. We provide these do 351 * (Such as PCI) needs no windowing routines at all. We provide these do
350 * nothing routines so that the same code base can be used. The driver will 352 * nothing routines so that the same code base can be used. The driver will
351 * ALWAYS call a windowing routine if it thinks it needs to; regardless of the 353 * ALWAYS call a windowing routine if it thinks it needs to; regardless of the
352 * card. However, dependent on the card the routine may or may not do anything. 354 * card. However, dependent on the card the routine may or may not do anything.
353 */ 355 */
354 static void dummy_memwinon(struct board_info *b, unsigned int win) 356 static void dummy_memwinon(struct board_info *b, unsigned int win)
355 { 357 {
356 } 358 }
357 359
358 static void dummy_memwinoff(struct board_info *b, unsigned int win) 360 static void dummy_memwinoff(struct board_info *b, unsigned int win)
359 { 361 {
360 } 362 }
361 363
362 static void dummy_globalwinon(struct channel *ch) 364 static void dummy_globalwinon(struct channel *ch)
363 { 365 {
364 } 366 }
365 367
366 static void dummy_rxwinon(struct channel *ch) 368 static void dummy_rxwinon(struct channel *ch)
367 { 369 {
368 } 370 }
369 371
370 static void dummy_txwinon(struct channel *ch) 372 static void dummy_txwinon(struct channel *ch)
371 { 373 {
372 } 374 }
373 375
374 static void dummy_memoff(struct channel *ch) 376 static void dummy_memoff(struct channel *ch)
375 { 377 {
376 } 378 }
377 379
378 static void dummy_assertgwinon(struct channel *ch) 380 static void dummy_assertgwinon(struct channel *ch)
379 { 381 {
380 } 382 }
381 383
382 static void dummy_assertmemoff(struct channel *ch) 384 static void dummy_assertmemoff(struct channel *ch)
383 { 385 {
384 } 386 }
385 387
386 static struct channel *verifyChannel(struct tty_struct *tty) 388 static struct channel *verifyChannel(struct tty_struct *tty)
387 { 389 {
388 /* 390 /*
389 * This routine basically provides a sanity check. It insures that the 391 * This routine basically provides a sanity check. It insures that the
390 * channel returned is within the proper range of addresses as well as 392 * channel returned is within the proper range of addresses as well as
391 * properly initialized. If some bogus info gets passed in 393 * properly initialized. If some bogus info gets passed in
392 * through tty->driver_data this should catch it. 394 * through tty->driver_data this should catch it.
393 */ 395 */
394 if (tty) { 396 if (tty) {
395 struct channel *ch = tty->driver_data; 397 struct channel *ch = tty->driver_data;
396 if (ch >= &digi_channels[0] && ch < &digi_channels[nbdevs]) { 398 if (ch >= &digi_channels[0] && ch < &digi_channels[nbdevs]) {
397 if (ch->magic == EPCA_MAGIC) 399 if (ch->magic == EPCA_MAGIC)
398 return ch; 400 return ch;
399 } 401 }
400 } 402 }
401 return NULL; 403 return NULL;
402 } 404 }
403 405
404 static void pc_sched_event(struct channel *ch, int event) 406 static void pc_sched_event(struct channel *ch, int event)
405 { 407 {
406 /* 408 /*
407 * We call this to schedule interrupt processing on some event. The 409 * We call this to schedule interrupt processing on some event. The
408 * kernel sees our request and calls the related routine in OUR driver. 410 * kernel sees our request and calls the related routine in OUR driver.
409 */ 411 */
410 ch->event |= 1 << event; 412 ch->event |= 1 << event;
411 schedule_work(&ch->tqueue); 413 schedule_work(&ch->tqueue);
412 } 414 }
413 415
414 static void epca_error(int line, char *msg) 416 static void epca_error(int line, char *msg)
415 { 417 {
416 printk(KERN_ERR "epca_error (Digi): line = %d %s\n", line, msg); 418 printk(KERN_ERR "epca_error (Digi): line = %d %s\n", line, msg);
417 } 419 }
418 420
419 static void pc_close(struct tty_struct *tty, struct file *filp) 421 static void pc_close(struct tty_struct *tty, struct file *filp)
420 { 422 {
421 struct channel *ch; 423 struct channel *ch;
424 struct tty_port *port;
422 unsigned long flags; 425 unsigned long flags;
423 /* 426 /*
424 * verifyChannel returns the channel from the tty struct if it is 427 * verifyChannel returns the channel from the tty struct if it is
425 * valid. This serves as a sanity check. 428 * valid. This serves as a sanity check.
426 */ 429 */
427 ch = verifyChannel(tty); 430 ch = verifyChannel(tty);
428 if (ch != NULL) { 431 if (ch == NULL)
429 spin_lock_irqsave(&epca_lock, flags); 432 return;
430 if (tty_hung_up_p(filp)) { 433 port = &ch->port;
431 spin_unlock_irqrestore(&epca_lock, flags);
432 return;
433 }
434 if (ch->port.count-- > 1) {
435 /* Begin channel is open more than once */
436 /*
437 * Return without doing anything. Someone might still
438 * be using the channel.
439 */
440 spin_unlock_irqrestore(&epca_lock, flags);
441 return;
442 }
443 /* Port open only once go ahead with shutdown & reset */
444 BUG_ON(ch->port.count < 0);
445 434
435 spin_lock_irqsave(&port->lock, flags);
436 if (tty_hung_up_p(filp)) {
437 spin_unlock_irqrestore(&port->lock, flags);
438 return;
439 }
440 if (port->count-- > 1) {
441 /* Begin channel is open more than once */
446 /* 442 /*
447 * Let the rest of the driver know the channel is being closed. 443 * Return without doing anything. Someone might still
448 * This becomes important if an open is attempted before close 444 * be using the channel.
449 * is finished.
450 */ 445 */
451 ch->port.flags |= ASYNC_CLOSING; 446 spin_unlock_irqrestore(&port->lock, flags);
452 tty->closing = 1; 447 return;
448 }
449 /* Port open only once go ahead with shutdown & reset */
450 WARN_ON(port->count < 0);
453 451
454 spin_unlock_irqrestore(&epca_lock, flags); 452 /*
453 * Let the rest of the driver know the channel is being closed.
454 * This becomes important if an open is attempted before close
455 * is finished.
456 */
457 port->flags |= ASYNC_CLOSING;
458 tty->closing = 1;
455 459
456 if (ch->port.flags & ASYNC_INITIALIZED) { 460 spin_unlock_irqrestore(&port->lock, flags);
457 /* Setup an event to indicate when the
458 transmit buffer empties */
459 setup_empty_event(tty, ch);
460 /* 30 seconds timeout */
461 tty_wait_until_sent(tty, 3000);
462 }
463 pc_flush_buffer(tty);
464 461
465 tty_ldisc_flush(tty); 462 if (port->flags & ASYNC_INITIALIZED) {
466 shutdown(ch); 463 /* Setup an event to indicate when the
464 transmit buffer empties */
465 setup_empty_event(tty, ch);
466 /* 30 seconds timeout */
467 tty_wait_until_sent(tty, 3000);
468 }
469 pc_flush_buffer(tty);
470 tty_ldisc_flush(tty);
471 shutdown(ch, tty);
467 472
468 spin_lock_irqsave(&epca_lock, flags); 473 spin_lock_irqsave(&port->lock, flags);
469 tty->closing = 0; 474 tty->closing = 0;
470 ch->event = 0; 475 ch->event = 0;
471 ch->port.tty = NULL; 476 port->tty = NULL;
472 spin_unlock_irqrestore(&epca_lock, flags); 477 spin_unlock_irqrestore(&port->lock, flags);
473 478
474 if (ch->port.blocked_open) { 479 if (port->blocked_open) {
475 if (ch->close_delay) 480 if (ch->close_delay)
476 msleep_interruptible(jiffies_to_msecs(ch->close_delay)); 481 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
477 wake_up_interruptible(&ch->port.open_wait); 482 wake_up_interruptible(&port->open_wait);
478 }
479 ch->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
480 ASYNC_CLOSING);
481 wake_up_interruptible(&ch->port.close_wait);
482 } 483 }
484 port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
485 ASYNC_CLOSING);
486 wake_up_interruptible(&port->close_wait);
483 } 487 }
484 488
485 static void shutdown(struct channel *ch) 489 static void shutdown(struct channel *ch, struct tty_struct *tty)
486 { 490 {
487 unsigned long flags; 491 unsigned long flags;
488 struct tty_struct *tty;
489 struct board_chan __iomem *bc; 492 struct board_chan __iomem *bc;
493 struct tty_port *port = &ch->port;
490 494
491 if (!(ch->port.flags & ASYNC_INITIALIZED)) 495 if (!(port->flags & ASYNC_INITIALIZED))
492 return; 496 return;
493 497
494 spin_lock_irqsave(&epca_lock, flags); 498 spin_lock_irqsave(&epca_lock, flags);
495 499
496 globalwinon(ch); 500 globalwinon(ch);
497 bc = ch->brdchan; 501 bc = ch->brdchan;
498 502
499 /* 503 /*
500 * In order for an event to be generated on the receipt of data the 504 * In order for an event to be generated on the receipt of data the
501 * idata flag must be set. Since we are shutting down, this is not 505 * idata flag must be set. Since we are shutting down, this is not
502 * necessary clear this flag. 506 * necessary clear this flag.
503 */ 507 */
504 if (bc) 508 if (bc)
505 writeb(0, &bc->idata); 509 writeb(0, &bc->idata);
506 tty = ch->port.tty;
507 510
508 /* If we're a modem control device and HUPCL is on, drop RTS & DTR. */ 511 /* If we're a modem control device and HUPCL is on, drop RTS & DTR. */
509 if (tty->termios->c_cflag & HUPCL) { 512 if (tty->termios->c_cflag & HUPCL) {
510 ch->omodem &= ~(ch->m_rts | ch->m_dtr); 513 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
511 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1); 514 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
512 } 515 }
513 memoff(ch); 516 memoff(ch);
514 517
515 /* 518 /*
516 * The channel has officialy been closed. The next time it is opened it 519 * The channel has officialy been closed. The next time it is opened it
517 * will have to reinitialized. Set a flag to indicate this. 520 * will have to reinitialized. Set a flag to indicate this.
518 */ 521 */
519 /* Prevent future Digi programmed interrupts from coming active */ 522 /* Prevent future Digi programmed interrupts from coming active */
520 ch->port.flags &= ~ASYNC_INITIALIZED; 523 port->flags &= ~ASYNC_INITIALIZED;
521 spin_unlock_irqrestore(&epca_lock, flags); 524 spin_unlock_irqrestore(&epca_lock, flags);
522 } 525 }
523 526
524 static void pc_hangup(struct tty_struct *tty) 527 static void pc_hangup(struct tty_struct *tty)
525 { 528 {
526 struct channel *ch; 529 struct channel *ch;
530 struct tty_port *port;
531
527 /* 532 /*
528 * verifyChannel returns the channel from the tty struct if it is 533 * verifyChannel returns the channel from the tty struct if it is
529 * valid. This serves as a sanity check. 534 * valid. This serves as a sanity check.
530 */ 535 */
531 ch = verifyChannel(tty); 536 ch = verifyChannel(tty);
532 if (ch != NULL) { 537 if (ch != NULL) {
533 unsigned long flags; 538 unsigned long flags;
539 port = &ch->port;
534 540
535 pc_flush_buffer(tty); 541 pc_flush_buffer(tty);
536 tty_ldisc_flush(tty); 542 tty_ldisc_flush(tty);
537 shutdown(ch); 543 shutdown(ch, tty);
538 544
539 spin_lock_irqsave(&epca_lock, flags); 545 spin_lock_irqsave(&port->lock, flags);
540 ch->port.tty = NULL; 546 port->tty = NULL;
541 ch->event = 0; 547 ch->event = 0; /* FIXME: review locking of ch->event */
542 ch->port.count = 0; 548 port->count = 0;
543 ch->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED); 549 port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
544 spin_unlock_irqrestore(&epca_lock, flags); 550 spin_unlock_irqrestore(&port->lock, flags);
545 wake_up_interruptible(&ch->port.open_wait); 551 wake_up_interruptible(&port->open_wait);
546 } 552 }
547 } 553 }
548 554
549 static int pc_write(struct tty_struct *tty, 555 static int pc_write(struct tty_struct *tty,
550 const unsigned char *buf, int bytesAvailable) 556 const unsigned char *buf, int bytesAvailable)
551 { 557 {
552 unsigned int head, tail; 558 unsigned int head, tail;
553 int dataLen; 559 int dataLen;
554 int size; 560 int size;
555 int amountCopied; 561 int amountCopied;
556 struct channel *ch; 562 struct channel *ch;
557 unsigned long flags; 563 unsigned long flags;
558 int remain; 564 int remain;
559 struct board_chan __iomem *bc; 565 struct board_chan __iomem *bc;
560 566
561 /* 567 /*
562 * pc_write is primarily called directly by the kernel routine 568 * pc_write is primarily called directly by the kernel routine
563 * tty_write (Though it can also be called by put_char) found in 569 * tty_write (Though it can also be called by put_char) found in
564 * tty_io.c. pc_write is passed a line discipline buffer where the data 570 * tty_io.c. pc_write is passed a line discipline buffer where the data
565 * to be written out is stored. The line discipline implementation 571 * to be written out is stored. The line discipline implementation
566 * itself is done at the kernel level and is not brought into the 572 * itself is done at the kernel level and is not brought into the
567 * driver. 573 * driver.
568 */ 574 */
569 575
570 /* 576 /*
571 * verifyChannel returns the channel from the tty struct if it is 577 * verifyChannel returns the channel from the tty struct if it is
572 * valid. This serves as a sanity check. 578 * valid. This serves as a sanity check.
573 */ 579 */
574 ch = verifyChannel(tty); 580 ch = verifyChannel(tty);
575 if (ch == NULL) 581 if (ch == NULL)
576 return 0; 582 return 0;
577 583
578 /* Make a pointer to the channel data structure found on the board. */ 584 /* Make a pointer to the channel data structure found on the board. */
579 bc = ch->brdchan; 585 bc = ch->brdchan;
580 size = ch->txbufsize; 586 size = ch->txbufsize;
581 amountCopied = 0; 587 amountCopied = 0;
582 588
583 spin_lock_irqsave(&epca_lock, flags); 589 spin_lock_irqsave(&epca_lock, flags);
584 globalwinon(ch); 590 globalwinon(ch);
585 591
586 head = readw(&bc->tin) & (size - 1); 592 head = readw(&bc->tin) & (size - 1);
587 tail = readw(&bc->tout); 593 tail = readw(&bc->tout);
588 594
589 if (tail != readw(&bc->tout)) 595 if (tail != readw(&bc->tout))
590 tail = readw(&bc->tout); 596 tail = readw(&bc->tout);
591 tail &= (size - 1); 597 tail &= (size - 1);
592 598
593 if (head >= tail) { 599 if (head >= tail) {
594 /* head has not wrapped */ 600 /* head has not wrapped */
595 /* 601 /*
596 * remain (much like dataLen above) represents the total amount 602 * remain (much like dataLen above) represents the total amount
597 * of space available on the card for data. Here dataLen 603 * of space available on the card for data. Here dataLen
598 * represents the space existing between the head pointer and 604 * represents the space existing between the head pointer and
599 * the end of buffer. This is important because a memcpy cannot 605 * the end of buffer. This is important because a memcpy cannot
600 * be told to automatically wrap around when it hits the buffer 606 * be told to automatically wrap around when it hits the buffer
601 * end. 607 * end.
602 */ 608 */
603 dataLen = size - head; 609 dataLen = size - head;
604 remain = size - (head - tail) - 1; 610 remain = size - (head - tail) - 1;
605 } else { 611 } else {
606 /* head has wrapped around */ 612 /* head has wrapped around */
607 remain = tail - head - 1; 613 remain = tail - head - 1;
608 dataLen = remain; 614 dataLen = remain;
609 } 615 }
610 /* 616 /*
611 * Check the space on the card. If we have more data than space; reduce 617 * Check the space on the card. If we have more data than space; reduce
612 * the amount of data to fit the space. 618 * the amount of data to fit the space.
613 */ 619 */
614 bytesAvailable = min(remain, bytesAvailable); 620 bytesAvailable = min(remain, bytesAvailable);
615 txwinon(ch); 621 txwinon(ch);
616 while (bytesAvailable > 0) { 622 while (bytesAvailable > 0) {
617 /* there is data to copy onto card */ 623 /* there is data to copy onto card */
618 624
619 /* 625 /*
620 * If head is not wrapped, the below will make sure the first 626 * If head is not wrapped, the below will make sure the first
621 * data copy fills to the end of card buffer. 627 * data copy fills to the end of card buffer.
622 */ 628 */
623 dataLen = min(bytesAvailable, dataLen); 629 dataLen = min(bytesAvailable, dataLen);
624 memcpy_toio(ch->txptr + head, buf, dataLen); 630 memcpy_toio(ch->txptr + head, buf, dataLen);
625 buf += dataLen; 631 buf += dataLen;
626 head += dataLen; 632 head += dataLen;
627 amountCopied += dataLen; 633 amountCopied += dataLen;
628 bytesAvailable -= dataLen; 634 bytesAvailable -= dataLen;
629 635
630 if (head >= size) { 636 if (head >= size) {
631 head = 0; 637 head = 0;
632 dataLen = tail; 638 dataLen = tail;
633 } 639 }
634 } 640 }
635 ch->statusflags |= TXBUSY; 641 ch->statusflags |= TXBUSY;
636 globalwinon(ch); 642 globalwinon(ch);
637 writew(head, &bc->tin); 643 writew(head, &bc->tin);
638 644
639 if ((ch->statusflags & LOWWAIT) == 0) { 645 if ((ch->statusflags & LOWWAIT) == 0) {
640 ch->statusflags |= LOWWAIT; 646 ch->statusflags |= LOWWAIT;
641 writeb(1, &bc->ilow); 647 writeb(1, &bc->ilow);
642 } 648 }
643 memoff(ch); 649 memoff(ch);
644 spin_unlock_irqrestore(&epca_lock, flags); 650 spin_unlock_irqrestore(&epca_lock, flags);
645 return amountCopied; 651 return amountCopied;
646 } 652 }
647 653
648 static int pc_write_room(struct tty_struct *tty) 654 static int pc_write_room(struct tty_struct *tty)
649 { 655 {
650 int remain = 0; 656 int remain = 0;
651 struct channel *ch; 657 struct channel *ch;
652 unsigned long flags; 658 unsigned long flags;
653 unsigned int head, tail; 659 unsigned int head, tail;
654 struct board_chan __iomem *bc; 660 struct board_chan __iomem *bc;
655 /* 661 /*
656 * verifyChannel returns the channel from the tty struct if it is 662 * verifyChannel returns the channel from the tty struct if it is
657 * valid. This serves as a sanity check. 663 * valid. This serves as a sanity check.
658 */ 664 */
659 ch = verifyChannel(tty); 665 ch = verifyChannel(tty);
660 if (ch != NULL) { 666 if (ch != NULL) {
661 spin_lock_irqsave(&epca_lock, flags); 667 spin_lock_irqsave(&epca_lock, flags);
662 globalwinon(ch); 668 globalwinon(ch);
663 669
664 bc = ch->brdchan; 670 bc = ch->brdchan;
665 head = readw(&bc->tin) & (ch->txbufsize - 1); 671 head = readw(&bc->tin) & (ch->txbufsize - 1);
666 tail = readw(&bc->tout); 672 tail = readw(&bc->tout);
667 673
668 if (tail != readw(&bc->tout)) 674 if (tail != readw(&bc->tout))
669 tail = readw(&bc->tout); 675 tail = readw(&bc->tout);
670 /* Wrap tail if necessary */ 676 /* Wrap tail if necessary */
671 tail &= (ch->txbufsize - 1); 677 tail &= (ch->txbufsize - 1);
672 remain = tail - head - 1; 678 remain = tail - head - 1;
673 if (remain < 0) 679 if (remain < 0)
674 remain += ch->txbufsize; 680 remain += ch->txbufsize;
675 681
676 if (remain && (ch->statusflags & LOWWAIT) == 0) { 682 if (remain && (ch->statusflags & LOWWAIT) == 0) {
677 ch->statusflags |= LOWWAIT; 683 ch->statusflags |= LOWWAIT;
678 writeb(1, &bc->ilow); 684 writeb(1, &bc->ilow);
679 } 685 }
680 memoff(ch); 686 memoff(ch);
681 spin_unlock_irqrestore(&epca_lock, flags); 687 spin_unlock_irqrestore(&epca_lock, flags);
682 } 688 }
683 /* Return how much room is left on card */ 689 /* Return how much room is left on card */
684 return remain; 690 return remain;
685 } 691 }
686 692
687 static int pc_chars_in_buffer(struct tty_struct *tty) 693 static int pc_chars_in_buffer(struct tty_struct *tty)
688 { 694 {
689 int chars; 695 int chars;
690 unsigned int ctail, head, tail; 696 unsigned int ctail, head, tail;
691 int remain; 697 int remain;
692 unsigned long flags; 698 unsigned long flags;
693 struct channel *ch; 699 struct channel *ch;
694 struct board_chan __iomem *bc; 700 struct board_chan __iomem *bc;
695 /* 701 /*
696 * verifyChannel returns the channel from the tty struct if it is 702 * verifyChannel returns the channel from the tty struct if it is
697 * valid. This serves as a sanity check. 703 * valid. This serves as a sanity check.
698 */ 704 */
699 ch = verifyChannel(tty); 705 ch = verifyChannel(tty);
700 if (ch == NULL) 706 if (ch == NULL)
701 return 0; 707 return 0;
702 708
703 spin_lock_irqsave(&epca_lock, flags); 709 spin_lock_irqsave(&epca_lock, flags);
704 globalwinon(ch); 710 globalwinon(ch);
705 711
706 bc = ch->brdchan; 712 bc = ch->brdchan;
707 tail = readw(&bc->tout); 713 tail = readw(&bc->tout);
708 head = readw(&bc->tin); 714 head = readw(&bc->tin);
709 ctail = readw(&ch->mailbox->cout); 715 ctail = readw(&ch->mailbox->cout);
710 716
711 if (tail == head && readw(&ch->mailbox->cin) == ctail && 717 if (tail == head && readw(&ch->mailbox->cin) == ctail &&
712 readb(&bc->tbusy) == 0) 718 readb(&bc->tbusy) == 0)
713 chars = 0; 719 chars = 0;
714 else { /* Begin if some space on the card has been used */ 720 else { /* Begin if some space on the card has been used */
715 head = readw(&bc->tin) & (ch->txbufsize - 1); 721 head = readw(&bc->tin) & (ch->txbufsize - 1);
716 tail &= (ch->txbufsize - 1); 722 tail &= (ch->txbufsize - 1);
717 /* 723 /*
718 * The logic here is basically opposite of the above 724 * The logic here is basically opposite of the above
719 * pc_write_room here we are finding the amount of bytes in the 725 * pc_write_room here we are finding the amount of bytes in the
720 * buffer filled. Not the amount of bytes empty. 726 * buffer filled. Not the amount of bytes empty.
721 */ 727 */
722 remain = tail - head - 1; 728 remain = tail - head - 1;
723 if (remain < 0) 729 if (remain < 0)
724 remain += ch->txbufsize; 730 remain += ch->txbufsize;
725 chars = (int)(ch->txbufsize - remain); 731 chars = (int)(ch->txbufsize - remain);
726 /* 732 /*
727 * Make it possible to wakeup anything waiting for output in 733 * Make it possible to wakeup anything waiting for output in
728 * tty_ioctl.c, etc. 734 * tty_ioctl.c, etc.
729 * 735 *
730 * If not already set. Setup an event to indicate when the 736 * If not already set. Setup an event to indicate when the
731 * transmit buffer empties. 737 * transmit buffer empties.
732 */ 738 */
733 if (!(ch->statusflags & EMPTYWAIT)) 739 if (!(ch->statusflags & EMPTYWAIT))
734 setup_empty_event(tty, ch); 740 setup_empty_event(tty, ch);
735 } /* End if some space on the card has been used */ 741 } /* End if some space on the card has been used */
736 memoff(ch); 742 memoff(ch);
737 spin_unlock_irqrestore(&epca_lock, flags); 743 spin_unlock_irqrestore(&epca_lock, flags);
738 /* Return number of characters residing on card. */ 744 /* Return number of characters residing on card. */
739 return chars; 745 return chars;
740 } 746 }
741 747
742 static void pc_flush_buffer(struct tty_struct *tty) 748 static void pc_flush_buffer(struct tty_struct *tty)
743 { 749 {
744 unsigned int tail; 750 unsigned int tail;
745 unsigned long flags; 751 unsigned long flags;
746 struct channel *ch; 752 struct channel *ch;
747 struct board_chan __iomem *bc; 753 struct board_chan __iomem *bc;
748 /* 754 /*
749 * verifyChannel returns the channel from the tty struct if it is 755 * verifyChannel returns the channel from the tty struct if it is
750 * valid. This serves as a sanity check. 756 * valid. This serves as a sanity check.
751 */ 757 */
752 ch = verifyChannel(tty); 758 ch = verifyChannel(tty);
753 if (ch == NULL) 759 if (ch == NULL)
754 return; 760 return;
755 761
756 spin_lock_irqsave(&epca_lock, flags); 762 spin_lock_irqsave(&epca_lock, flags);
757 globalwinon(ch); 763 globalwinon(ch);
758 bc = ch->brdchan; 764 bc = ch->brdchan;
759 tail = readw(&bc->tout); 765 tail = readw(&bc->tout);
760 /* Have FEP move tout pointer; effectively flushing transmit buffer */ 766 /* Have FEP move tout pointer; effectively flushing transmit buffer */
761 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0); 767 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
762 memoff(ch); 768 memoff(ch);
763 spin_unlock_irqrestore(&epca_lock, flags); 769 spin_unlock_irqrestore(&epca_lock, flags);
764 tty_wakeup(tty); 770 tty_wakeup(tty);
765 } 771 }
766 772
767 static void pc_flush_chars(struct tty_struct *tty) 773 static void pc_flush_chars(struct tty_struct *tty)
768 { 774 {
769 struct channel *ch; 775 struct channel *ch;
770 /* 776 /*
771 * verifyChannel returns the channel from the tty struct if it is 777 * verifyChannel returns the channel from the tty struct if it is
772 * valid. This serves as a sanity check. 778 * valid. This serves as a sanity check.
773 */ 779 */
774 ch = verifyChannel(tty); 780 ch = verifyChannel(tty);
775 if (ch != NULL) { 781 if (ch != NULL) {
776 unsigned long flags; 782 unsigned long flags;
777 spin_lock_irqsave(&epca_lock, flags); 783 spin_lock_irqsave(&epca_lock, flags);
778 /* 784 /*
779 * If not already set and the transmitter is busy setup an 785 * If not already set and the transmitter is busy setup an
780 * event to indicate when the transmit empties. 786 * event to indicate when the transmit empties.
781 */ 787 */
782 if ((ch->statusflags & TXBUSY) && 788 if ((ch->statusflags & TXBUSY) &&
783 !(ch->statusflags & EMPTYWAIT)) 789 !(ch->statusflags & EMPTYWAIT))
784 setup_empty_event(tty, ch); 790 setup_empty_event(tty, ch);
785 spin_unlock_irqrestore(&epca_lock, flags); 791 spin_unlock_irqrestore(&epca_lock, flags);
786 } 792 }
787 } 793 }
788 794
789 static int block_til_ready(struct tty_struct *tty, 795 static int block_til_ready(struct tty_struct *tty,
790 struct file *filp, struct channel *ch) 796 struct file *filp, struct channel *ch)
791 { 797 {
792 DECLARE_WAITQUEUE(wait, current); 798 DECLARE_WAITQUEUE(wait, current);
793 int retval, do_clocal = 0; 799 int retval, do_clocal = 0;
794 unsigned long flags; 800 unsigned long flags;
801 struct tty_port *port = &ch->port;
795 802
796 if (tty_hung_up_p(filp)) { 803 if (tty_hung_up_p(filp)) {
797 if (ch->port.flags & ASYNC_HUP_NOTIFY) 804 if (port->flags & ASYNC_HUP_NOTIFY)
798 retval = -EAGAIN; 805 retval = -EAGAIN;
799 else 806 else
800 retval = -ERESTARTSYS; 807 retval = -ERESTARTSYS;
801 return retval; 808 return retval;
802 } 809 }
803 810
804 /* 811 /*
805 * If the device is in the middle of being closed, then block until 812 * If the device is in the middle of being closed, then block until
806 * it's done, and then try again. 813 * it's done, and then try again.
807 */ 814 */
808 if (ch->port.flags & ASYNC_CLOSING) { 815 if (port->flags & ASYNC_CLOSING) {
809 interruptible_sleep_on(&ch->port.close_wait); 816 interruptible_sleep_on(&port->close_wait);
810 817
811 if (ch->port.flags & ASYNC_HUP_NOTIFY) 818 if (port->flags & ASYNC_HUP_NOTIFY)
812 return -EAGAIN; 819 return -EAGAIN;
813 else 820 else
814 return -ERESTARTSYS; 821 return -ERESTARTSYS;
815 } 822 }
816 823
817 if (filp->f_flags & O_NONBLOCK) { 824 if (filp->f_flags & O_NONBLOCK) {
818 /* 825 /*
819 * If non-blocking mode is set, then make the check up front 826 * If non-blocking mode is set, then make the check up front
820 * and then exit. 827 * and then exit.
821 */ 828 */
822 ch->port.flags |= ASYNC_NORMAL_ACTIVE; 829 port->flags |= ASYNC_NORMAL_ACTIVE;
823 return 0; 830 return 0;
824 } 831 }
825 if (tty->termios->c_cflag & CLOCAL) 832 if (tty->termios->c_cflag & CLOCAL)
826 do_clocal = 1; 833 do_clocal = 1;
827 /* Block waiting for the carrier detect and the line to become free */ 834 /* Block waiting for the carrier detect and the line to become free */
828 835
829 retval = 0; 836 retval = 0;
830 add_wait_queue(&ch->port.open_wait, &wait); 837 add_wait_queue(&port->open_wait, &wait);
831 838
832 spin_lock_irqsave(&epca_lock, flags); 839 spin_lock_irqsave(&port->lock, flags);
833 /* We dec count so that pc_close will know when to free things */ 840 /* We dec count so that pc_close will know when to free things */
834 if (!tty_hung_up_p(filp)) 841 if (!tty_hung_up_p(filp))
835 ch->port.count--; 842 port->count--;
836 ch->port.blocked_open++; 843 port->blocked_open++;
837 while (1) { 844 while (1) {
838 set_current_state(TASK_INTERRUPTIBLE); 845 set_current_state(TASK_INTERRUPTIBLE);
839 if (tty_hung_up_p(filp) || 846 if (tty_hung_up_p(filp) ||
840 !(ch->port.flags & ASYNC_INITIALIZED)) { 847 !(port->flags & ASYNC_INITIALIZED)) {
841 if (ch->port.flags & ASYNC_HUP_NOTIFY) 848 if (port->flags & ASYNC_HUP_NOTIFY)
842 retval = -EAGAIN; 849 retval = -EAGAIN;
843 else 850 else
844 retval = -ERESTARTSYS; 851 retval = -ERESTARTSYS;
845 break; 852 break;
846 } 853 }
847 if (!(ch->port.flags & ASYNC_CLOSING) && 854 if (!(port->flags & ASYNC_CLOSING) &&
848 (do_clocal || (ch->imodem & ch->dcd))) 855 (do_clocal || (ch->imodem & ch->dcd)))
849 break; 856 break;
850 if (signal_pending(current)) { 857 if (signal_pending(current)) {
851 retval = -ERESTARTSYS; 858 retval = -ERESTARTSYS;
852 break; 859 break;
853 } 860 }
854 spin_unlock_irqrestore(&epca_lock, flags); 861 spin_unlock_irqrestore(&port->lock, flags);
855 /* 862 /*
856 * Allow someone else to be scheduled. We will occasionally go 863 * Allow someone else to be scheduled. We will occasionally go
857 * through this loop until one of the above conditions change. 864 * through this loop until one of the above conditions change.
858 * The below schedule call will allow other processes to enter 865 * The below schedule call will allow other processes to enter
859 * and prevent this loop from hogging the cpu. 866 * and prevent this loop from hogging the cpu.
860 */ 867 */
861 schedule(); 868 schedule();
862 spin_lock_irqsave(&epca_lock, flags); 869 spin_lock_irqsave(&port->lock, flags);
863 } 870 }
864 871
865 __set_current_state(TASK_RUNNING); 872 __set_current_state(TASK_RUNNING);
866 remove_wait_queue(&ch->port.open_wait, &wait); 873 remove_wait_queue(&port->open_wait, &wait);
867 if (!tty_hung_up_p(filp)) 874 if (!tty_hung_up_p(filp))
868 ch->port.count++; 875 port->count++;
869 ch->port.blocked_open--; 876 port->blocked_open--;
870 877
871 spin_unlock_irqrestore(&epca_lock, flags); 878 spin_unlock_irqrestore(&port->lock, flags);
872 879
873 if (retval) 880 if (retval)
874 return retval; 881 return retval;
875 882
876 ch->port.flags |= ASYNC_NORMAL_ACTIVE; 883 port->flags |= ASYNC_NORMAL_ACTIVE;
877 return 0; 884 return 0;
878 } 885 }
879 886
880 static int pc_open(struct tty_struct *tty, struct file *filp) 887 static int pc_open(struct tty_struct *tty, struct file *filp)
881 { 888 {
882 struct channel *ch; 889 struct channel *ch;
890 struct tty_port *port;
883 unsigned long flags; 891 unsigned long flags;
884 int line, retval, boardnum; 892 int line, retval, boardnum;
885 struct board_chan __iomem *bc; 893 struct board_chan __iomem *bc;
886 unsigned int head; 894 unsigned int head;
887 895
888 line = tty->index; 896 line = tty->index;
889 if (line < 0 || line >= nbdevs) 897 if (line < 0 || line >= nbdevs)
890 return -ENODEV; 898 return -ENODEV;
891 899
892 ch = &digi_channels[line]; 900 ch = &digi_channels[line];
901 port = &ch->port;
893 boardnum = ch->boardnum; 902 boardnum = ch->boardnum;
894 903
895 /* Check status of board configured in system. */ 904 /* Check status of board configured in system. */
896 905
897 /* 906 /*
898 * I check to see if the epca_setup routine detected an user error. It 907 * I check to see if the epca_setup routine detected an user error. It
899 * might be better to put this in pc_init, but for the moment it goes 908 * might be better to put this in pc_init, but for the moment it goes
900 * here. 909 * here.
901 */ 910 */
902 if (invalid_lilo_config) { 911 if (invalid_lilo_config) {
903 if (setup_error_code & INVALID_BOARD_TYPE) 912 if (setup_error_code & INVALID_BOARD_TYPE)
904 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n"); 913 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
905 if (setup_error_code & INVALID_NUM_PORTS) 914 if (setup_error_code & INVALID_NUM_PORTS)
906 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n"); 915 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
907 if (setup_error_code & INVALID_MEM_BASE) 916 if (setup_error_code & INVALID_MEM_BASE)
908 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n"); 917 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
909 if (setup_error_code & INVALID_PORT_BASE) 918 if (setup_error_code & INVALID_PORT_BASE)
910 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n"); 919 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
911 if (setup_error_code & INVALID_BOARD_STATUS) 920 if (setup_error_code & INVALID_BOARD_STATUS)
912 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n"); 921 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
913 if (setup_error_code & INVALID_ALTPIN) 922 if (setup_error_code & INVALID_ALTPIN)
914 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n"); 923 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
915 tty->driver_data = NULL; /* Mark this device as 'down' */ 924 tty->driver_data = NULL; /* Mark this device as 'down' */
916 return -ENODEV; 925 return -ENODEV;
917 } 926 }
918 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) { 927 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
919 tty->driver_data = NULL; /* Mark this device as 'down' */ 928 tty->driver_data = NULL; /* Mark this device as 'down' */
920 return(-ENODEV); 929 return(-ENODEV);
921 } 930 }
922 931
923 bc = ch->brdchan; 932 bc = ch->brdchan;
924 if (bc == NULL) { 933 if (bc == NULL) {
925 tty->driver_data = NULL; 934 tty->driver_data = NULL;
926 return -ENODEV; 935 return -ENODEV;
927 } 936 }
928 937
929 spin_lock_irqsave(&epca_lock, flags); 938 spin_lock_irqsave(&port->lock, flags);
930 /* 939 /*
931 * Every time a channel is opened, increment a counter. This is 940 * Every time a channel is opened, increment a counter. This is
932 * necessary because we do not wish to flush and shutdown the channel 941 * necessary because we do not wish to flush and shutdown the channel
933 * until the last app holding the channel open, closes it. 942 * until the last app holding the channel open, closes it.
934 */ 943 */
935 ch->port.count++; 944 port->count++;
936 /* 945 /*
937 * Set a kernel structures pointer to our local channel structure. This 946 * Set a kernel structures pointer to our local channel structure. This
938 * way we can get to it when passed only a tty struct. 947 * way we can get to it when passed only a tty struct.
939 */ 948 */
940 tty->driver_data = ch; 949 tty->driver_data = ch;
950 port->tty = tty;
941 /* 951 /*
942 * If this is the first time the channel has been opened, initialize 952 * If this is the first time the channel has been opened, initialize
943 * the tty->termios struct otherwise let pc_close handle it. 953 * the tty->termios struct otherwise let pc_close handle it.
944 */ 954 */
955 spin_lock(&epca_lock);
945 globalwinon(ch); 956 globalwinon(ch);
946 ch->statusflags = 0; 957 ch->statusflags = 0;
947 958
948 /* Save boards current modem status */ 959 /* Save boards current modem status */
949 ch->imodem = readb(&bc->mstat); 960 ch->imodem = readb(&bc->mstat);
950 961
951 /* 962 /*
952 * Set receive head and tail ptrs to each other. This indicates no data 963 * Set receive head and tail ptrs to each other. This indicates no data
953 * available to read. 964 * available to read.
954 */ 965 */
955 head = readw(&bc->rin); 966 head = readw(&bc->rin);
956 writew(head, &bc->rout); 967 writew(head, &bc->rout);
957 968
958 /* Set the channels associated tty structure */ 969 /* Set the channels associated tty structure */
959 ch->port.tty = tty;
960 970
961 /* 971 /*
962 * The below routine generally sets up parity, baud, flow control 972 * The below routine generally sets up parity, baud, flow control
963 * issues, etc.... It effect both control flags and input flags. 973 * issues, etc.... It effect both control flags and input flags.
964 */ 974 */
965 epcaparam(tty, ch); 975 epcaparam(tty, ch);
966 ch->port.flags |= ASYNC_INITIALIZED;
967 memoff(ch); 976 memoff(ch);
968 spin_unlock_irqrestore(&epca_lock, flags); 977 spin_unlock(&epca_lock);
978 port->flags |= ASYNC_INITIALIZED;
979 spin_unlock_irqrestore(&port->lock, flags);
969 980
970 retval = block_til_ready(tty, filp, ch); 981 retval = block_til_ready(tty, filp, ch);
971 if (retval) 982 if (retval)
972 return retval; 983 return retval;
973 /* 984 /*
974 * Set this again in case a hangup set it to zero while this open() was 985 * Set this again in case a hangup set it to zero while this open() was
975 * waiting for the line... 986 * waiting for the line...
976 */ 987 */
977 spin_lock_irqsave(&epca_lock, flags); 988 spin_lock_irqsave(&port->lock, flags);
978 ch->port.tty = tty; 989 port->tty = tty;
990 spin_lock(&epca_lock);
979 globalwinon(ch); 991 globalwinon(ch);
980 /* Enable Digi Data events */ 992 /* Enable Digi Data events */
981 writeb(1, &bc->idata); 993 writeb(1, &bc->idata);
982 memoff(ch); 994 memoff(ch);
983 spin_unlock_irqrestore(&epca_lock, flags); 995 spin_unlock(&epca_lock);
996 spin_unlock_irqrestore(&port->lock, flags);
984 return 0; 997 return 0;
985 } 998 }
986 999
987 static int __init epca_module_init(void) 1000 static int __init epca_module_init(void)
988 { 1001 {
989 return pc_init(); 1002 return pc_init();
990 } 1003 }
991 module_init(epca_module_init); 1004 module_init(epca_module_init);
992 1005
993 static struct pci_driver epca_driver; 1006 static struct pci_driver epca_driver;
994 1007
995 static void __exit epca_module_exit(void) 1008 static void __exit epca_module_exit(void)
996 { 1009 {
997 int count, crd; 1010 int count, crd;
998 struct board_info *bd; 1011 struct board_info *bd;
999 struct channel *ch; 1012 struct channel *ch;
1000 1013
1001 del_timer_sync(&epca_timer); 1014 del_timer_sync(&epca_timer);
1002 1015
1003 if (tty_unregister_driver(pc_driver) || 1016 if (tty_unregister_driver(pc_driver) ||
1004 tty_unregister_driver(pc_info)) { 1017 tty_unregister_driver(pc_info)) {
1005 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n"); 1018 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
1006 return; 1019 return;
1007 } 1020 }
1008 put_tty_driver(pc_driver); 1021 put_tty_driver(pc_driver);
1009 put_tty_driver(pc_info); 1022 put_tty_driver(pc_info);
1010 1023
1011 for (crd = 0; crd < num_cards; crd++) { 1024 for (crd = 0; crd < num_cards; crd++) {
1012 bd = &boards[crd]; 1025 bd = &boards[crd];
1013 if (!bd) { /* sanity check */ 1026 if (!bd) { /* sanity check */
1014 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n"); 1027 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1015 return; 1028 return;
1016 } 1029 }
1017 ch = card_ptr[crd]; 1030 ch = card_ptr[crd];
1018 for (count = 0; count < bd->numports; count++, ch++) { 1031 for (count = 0; count < bd->numports; count++, ch++) {
1019 if (ch && ch->port.tty) 1032 if (ch && ch->port.tty)
1020 tty_hangup(ch->port.tty); 1033 tty_hangup(ch->port.tty);
1021 } 1034 }
1022 } 1035 }
1023 pci_unregister_driver(&epca_driver); 1036 pci_unregister_driver(&epca_driver);
1024 } 1037 }
1025 module_exit(epca_module_exit); 1038 module_exit(epca_module_exit);
1026 1039
1027 static const struct tty_operations pc_ops = { 1040 static const struct tty_operations pc_ops = {
1028 .open = pc_open, 1041 .open = pc_open,
1029 .close = pc_close, 1042 .close = pc_close,
1030 .write = pc_write, 1043 .write = pc_write,
1031 .write_room = pc_write_room, 1044 .write_room = pc_write_room,
1032 .flush_buffer = pc_flush_buffer, 1045 .flush_buffer = pc_flush_buffer,
1033 .chars_in_buffer = pc_chars_in_buffer, 1046 .chars_in_buffer = pc_chars_in_buffer,
1034 .flush_chars = pc_flush_chars, 1047 .flush_chars = pc_flush_chars,
1035 .ioctl = pc_ioctl, 1048 .ioctl = pc_ioctl,
1036 .set_termios = pc_set_termios, 1049 .set_termios = pc_set_termios,
1037 .stop = pc_stop, 1050 .stop = pc_stop,
1038 .start = pc_start, 1051 .start = pc_start,
1039 .throttle = pc_throttle, 1052 .throttle = pc_throttle,
1040 .unthrottle = pc_unthrottle, 1053 .unthrottle = pc_unthrottle,
1041 .hangup = pc_hangup, 1054 .hangup = pc_hangup,
1042 .break_ctl = pc_send_break 1055 .break_ctl = pc_send_break
1043 }; 1056 };
1044 1057
1045 static int info_open(struct tty_struct *tty, struct file *filp) 1058 static int info_open(struct tty_struct *tty, struct file *filp)
1046 { 1059 {
1047 return 0; 1060 return 0;
1048 } 1061 }
1049 1062
1050 static struct tty_operations info_ops = { 1063 static struct tty_operations info_ops = {
1051 .open = info_open, 1064 .open = info_open,
1052 .ioctl = info_ioctl, 1065 .ioctl = info_ioctl,
1053 }; 1066 };
1054 1067
1055 static int __init pc_init(void) 1068 static int __init pc_init(void)
1056 { 1069 {
1057 int crd; 1070 int crd;
1058 struct board_info *bd; 1071 struct board_info *bd;
1059 unsigned char board_id = 0; 1072 unsigned char board_id = 0;
1060 int err = -ENOMEM; 1073 int err = -ENOMEM;
1061 1074
1062 int pci_boards_found, pci_count; 1075 int pci_boards_found, pci_count;
1063 1076
1064 pci_count = 0; 1077 pci_count = 0;
1065 1078
1066 pc_driver = alloc_tty_driver(MAX_ALLOC); 1079 pc_driver = alloc_tty_driver(MAX_ALLOC);
1067 if (!pc_driver) 1080 if (!pc_driver)
1068 goto out1; 1081 goto out1;
1069 1082
1070 pc_info = alloc_tty_driver(MAX_ALLOC); 1083 pc_info = alloc_tty_driver(MAX_ALLOC);
1071 if (!pc_info) 1084 if (!pc_info)
1072 goto out2; 1085 goto out2;
1073 1086
1074 /* 1087 /*
1075 * If epca_setup has not been ran by LILO set num_cards to defaults; 1088 * If epca_setup has not been ran by LILO set num_cards to defaults;
1076 * copy board structure defined by digiConfig into drivers board 1089 * copy board structure defined by digiConfig into drivers board
1077 * structure. Note : If LILO has ran epca_setup then epca_setup will 1090 * structure. Note : If LILO has ran epca_setup then epca_setup will
1078 * handle defining num_cards as well as copying the data into the board 1091 * handle defining num_cards as well as copying the data into the board
1079 * structure. 1092 * structure.
1080 */ 1093 */
1081 if (!liloconfig) { 1094 if (!liloconfig) {
1082 /* driver has been configured via. epcaconfig */ 1095 /* driver has been configured via. epcaconfig */
1083 nbdevs = NBDEVS; 1096 nbdevs = NBDEVS;
1084 num_cards = NUMCARDS; 1097 num_cards = NUMCARDS;
1085 memcpy(&boards, &static_boards, 1098 memcpy(&boards, &static_boards,
1086 sizeof(struct board_info) * NUMCARDS); 1099 sizeof(struct board_info) * NUMCARDS);
1087 } 1100 }
1088 1101
1089 /* 1102 /*
1090 * Note : If lilo was used to configure the driver and the ignore 1103 * Note : If lilo was used to configure the driver and the ignore
1091 * epcaconfig option was choosen (digiepca=2) then nbdevs and num_cards 1104 * epcaconfig option was choosen (digiepca=2) then nbdevs and num_cards
1092 * will equal 0 at this point. This is okay; PCI cards will still be 1105 * will equal 0 at this point. This is okay; PCI cards will still be
1093 * picked up if detected. 1106 * picked up if detected.
1094 */ 1107 */
1095 1108
1096 /* 1109 /*
1097 * Set up interrupt, we will worry about memory allocation in 1110 * Set up interrupt, we will worry about memory allocation in
1098 * post_fep_init. 1111 * post_fep_init.
1099 */ 1112 */
1100 printk(KERN_INFO "DIGI epca driver version %s loaded.\n", VERSION); 1113 printk(KERN_INFO "DIGI epca driver version %s loaded.\n", VERSION);
1101 1114
1102 /* 1115 /*
1103 * NOTE : This code assumes that the number of ports found in the 1116 * NOTE : This code assumes that the number of ports found in the
1104 * boards array is correct. This could be wrong if the card in question 1117 * boards array is correct. This could be wrong if the card in question
1105 * is PCI (And therefore has no ports entry in the boards structure.) 1118 * is PCI (And therefore has no ports entry in the boards structure.)
1106 * The rest of the information will be valid for PCI because the 1119 * The rest of the information will be valid for PCI because the
1107 * beginning of pc_init scans for PCI and determines i/o and base 1120 * beginning of pc_init scans for PCI and determines i/o and base
1108 * memory addresses. I am not sure if it is possible to read the number 1121 * memory addresses. I am not sure if it is possible to read the number
1109 * of ports supported by the card prior to it being booted (Since that 1122 * of ports supported by the card prior to it being booted (Since that
1110 * is the state it is in when pc_init is run). Because it is not 1123 * is the state it is in when pc_init is run). Because it is not
1111 * possible to query the number of supported ports until after the card 1124 * possible to query the number of supported ports until after the card
1112 * has booted; we are required to calculate the card_ptrs as the card 1125 * has booted; we are required to calculate the card_ptrs as the card
1113 * is initialized (Inside post_fep_init). The negative thing about this 1126 * is initialized (Inside post_fep_init). The negative thing about this
1114 * approach is that digiDload's call to GET_INFO will have a bad port 1127 * approach is that digiDload's call to GET_INFO will have a bad port
1115 * value. (Since this is called prior to post_fep_init.) 1128 * value. (Since this is called prior to post_fep_init.)
1116 */ 1129 */
1117 pci_boards_found = 0; 1130 pci_boards_found = 0;
1118 if (num_cards < MAXBOARDS) 1131 if (num_cards < MAXBOARDS)
1119 pci_boards_found += init_PCI(); 1132 pci_boards_found += init_PCI();
1120 num_cards += pci_boards_found; 1133 num_cards += pci_boards_found;
1121 1134
1122 pc_driver->owner = THIS_MODULE; 1135 pc_driver->owner = THIS_MODULE;
1123 pc_driver->name = "ttyD"; 1136 pc_driver->name = "ttyD";
1124 pc_driver->major = DIGI_MAJOR; 1137 pc_driver->major = DIGI_MAJOR;
1125 pc_driver->minor_start = 0; 1138 pc_driver->minor_start = 0;
1126 pc_driver->type = TTY_DRIVER_TYPE_SERIAL; 1139 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1127 pc_driver->subtype = SERIAL_TYPE_NORMAL; 1140 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1128 pc_driver->init_termios = tty_std_termios; 1141 pc_driver->init_termios = tty_std_termios;
1129 pc_driver->init_termios.c_iflag = 0; 1142 pc_driver->init_termios.c_iflag = 0;
1130 pc_driver->init_termios.c_oflag = 0; 1143 pc_driver->init_termios.c_oflag = 0;
1131 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; 1144 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1132 pc_driver->init_termios.c_lflag = 0; 1145 pc_driver->init_termios.c_lflag = 0;
1133 pc_driver->init_termios.c_ispeed = 9600; 1146 pc_driver->init_termios.c_ispeed = 9600;
1134 pc_driver->init_termios.c_ospeed = 9600; 1147 pc_driver->init_termios.c_ospeed = 9600;
1135 pc_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK; 1148 pc_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK;
1136 tty_set_operations(pc_driver, &pc_ops); 1149 tty_set_operations(pc_driver, &pc_ops);
1137 1150
1138 pc_info->owner = THIS_MODULE; 1151 pc_info->owner = THIS_MODULE;
1139 pc_info->name = "digi_ctl"; 1152 pc_info->name = "digi_ctl";
1140 pc_info->major = DIGIINFOMAJOR; 1153 pc_info->major = DIGIINFOMAJOR;
1141 pc_info->minor_start = 0; 1154 pc_info->minor_start = 0;
1142 pc_info->type = TTY_DRIVER_TYPE_SERIAL; 1155 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1143 pc_info->subtype = SERIAL_TYPE_INFO; 1156 pc_info->subtype = SERIAL_TYPE_INFO;
1144 pc_info->init_termios = tty_std_termios; 1157 pc_info->init_termios = tty_std_termios;
1145 pc_info->init_termios.c_iflag = 0; 1158 pc_info->init_termios.c_iflag = 0;
1146 pc_info->init_termios.c_oflag = 0; 1159 pc_info->init_termios.c_oflag = 0;
1147 pc_info->init_termios.c_lflag = 0; 1160 pc_info->init_termios.c_lflag = 0;
1148 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL; 1161 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1149 pc_info->init_termios.c_ispeed = 9600; 1162 pc_info->init_termios.c_ispeed = 9600;
1150 pc_info->init_termios.c_ospeed = 9600; 1163 pc_info->init_termios.c_ospeed = 9600;
1151 pc_info->flags = TTY_DRIVER_REAL_RAW; 1164 pc_info->flags = TTY_DRIVER_REAL_RAW;
1152 tty_set_operations(pc_info, &info_ops); 1165 tty_set_operations(pc_info, &info_ops);
1153 1166
1154 1167
1155 for (crd = 0; crd < num_cards; crd++) { 1168 for (crd = 0; crd < num_cards; crd++) {
1156 /* 1169 /*
1157 * This is where the appropriate memory handlers for the 1170 * This is where the appropriate memory handlers for the
1158 * hardware is set. Everything at runtime blindly jumps through 1171 * hardware is set. Everything at runtime blindly jumps through
1159 * these vectors. 1172 * these vectors.
1160 */ 1173 */
1161 1174
1162 /* defined in epcaconfig.h */ 1175 /* defined in epcaconfig.h */
1163 bd = &boards[crd]; 1176 bd = &boards[crd];
1164 1177
1165 switch (bd->type) { 1178 switch (bd->type) {
1166 case PCXEM: 1179 case PCXEM:
1167 case EISAXEM: 1180 case EISAXEM:
1168 bd->memwinon = pcxem_memwinon; 1181 bd->memwinon = pcxem_memwinon;
1169 bd->memwinoff = pcxem_memwinoff; 1182 bd->memwinoff = pcxem_memwinoff;
1170 bd->globalwinon = pcxem_globalwinon; 1183 bd->globalwinon = pcxem_globalwinon;
1171 bd->txwinon = pcxem_txwinon; 1184 bd->txwinon = pcxem_txwinon;
1172 bd->rxwinon = pcxem_rxwinon; 1185 bd->rxwinon = pcxem_rxwinon;
1173 bd->memoff = pcxem_memoff; 1186 bd->memoff = pcxem_memoff;
1174 bd->assertgwinon = dummy_assertgwinon; 1187 bd->assertgwinon = dummy_assertgwinon;
1175 bd->assertmemoff = dummy_assertmemoff; 1188 bd->assertmemoff = dummy_assertmemoff;
1176 break; 1189 break;
1177 1190
1178 case PCIXEM: 1191 case PCIXEM:
1179 case PCIXRJ: 1192 case PCIXRJ:
1180 case PCIXR: 1193 case PCIXR:
1181 bd->memwinon = dummy_memwinon; 1194 bd->memwinon = dummy_memwinon;
1182 bd->memwinoff = dummy_memwinoff; 1195 bd->memwinoff = dummy_memwinoff;
1183 bd->globalwinon = dummy_globalwinon; 1196 bd->globalwinon = dummy_globalwinon;
1184 bd->txwinon = dummy_txwinon; 1197 bd->txwinon = dummy_txwinon;
1185 bd->rxwinon = dummy_rxwinon; 1198 bd->rxwinon = dummy_rxwinon;
1186 bd->memoff = dummy_memoff; 1199 bd->memoff = dummy_memoff;
1187 bd->assertgwinon = dummy_assertgwinon; 1200 bd->assertgwinon = dummy_assertgwinon;
1188 bd->assertmemoff = dummy_assertmemoff; 1201 bd->assertmemoff = dummy_assertmemoff;
1189 break; 1202 break;
1190 1203
1191 case PCXE: 1204 case PCXE:
1192 case PCXEVE: 1205 case PCXEVE:
1193 bd->memwinon = pcxe_memwinon; 1206 bd->memwinon = pcxe_memwinon;
1194 bd->memwinoff = pcxe_memwinoff; 1207 bd->memwinoff = pcxe_memwinoff;
1195 bd->globalwinon = pcxe_globalwinon; 1208 bd->globalwinon = pcxe_globalwinon;
1196 bd->txwinon = pcxe_txwinon; 1209 bd->txwinon = pcxe_txwinon;
1197 bd->rxwinon = pcxe_rxwinon; 1210 bd->rxwinon = pcxe_rxwinon;
1198 bd->memoff = pcxe_memoff; 1211 bd->memoff = pcxe_memoff;
1199 bd->assertgwinon = dummy_assertgwinon; 1212 bd->assertgwinon = dummy_assertgwinon;
1200 bd->assertmemoff = dummy_assertmemoff; 1213 bd->assertmemoff = dummy_assertmemoff;
1201 break; 1214 break;
1202 1215
1203 case PCXI: 1216 case PCXI:
1204 case PC64XE: 1217 case PC64XE:
1205 bd->memwinon = pcxi_memwinon; 1218 bd->memwinon = pcxi_memwinon;
1206 bd->memwinoff = pcxi_memwinoff; 1219 bd->memwinoff = pcxi_memwinoff;
1207 bd->globalwinon = pcxi_globalwinon; 1220 bd->globalwinon = pcxi_globalwinon;
1208 bd->txwinon = pcxi_txwinon; 1221 bd->txwinon = pcxi_txwinon;
1209 bd->rxwinon = pcxi_rxwinon; 1222 bd->rxwinon = pcxi_rxwinon;
1210 bd->memoff = pcxi_memoff; 1223 bd->memoff = pcxi_memoff;
1211 bd->assertgwinon = pcxi_assertgwinon; 1224 bd->assertgwinon = pcxi_assertgwinon;
1212 bd->assertmemoff = pcxi_assertmemoff; 1225 bd->assertmemoff = pcxi_assertmemoff;
1213 break; 1226 break;
1214 1227
1215 default: 1228 default:
1216 break; 1229 break;
1217 } 1230 }
1218 1231
1219 /* 1232 /*
1220 * Some cards need a memory segment to be defined for use in 1233 * Some cards need a memory segment to be defined for use in
1221 * transmit and receive windowing operations. These boards are 1234 * transmit and receive windowing operations. These boards are
1222 * listed in the below switch. In the case of the XI the amount 1235 * listed in the below switch. In the case of the XI the amount
1223 * of memory on the board is variable so the memory_seg is also 1236 * of memory on the board is variable so the memory_seg is also
1224 * variable. This code determines what they segment should be. 1237 * variable. This code determines what they segment should be.
1225 */ 1238 */
1226 switch (bd->type) { 1239 switch (bd->type) {
1227 case PCXE: 1240 case PCXE:
1228 case PCXEVE: 1241 case PCXEVE:
1229 case PC64XE: 1242 case PC64XE:
1230 bd->memory_seg = 0xf000; 1243 bd->memory_seg = 0xf000;
1231 break; 1244 break;
1232 1245
1233 case PCXI: 1246 case PCXI:
1234 board_id = inb((int)bd->port); 1247 board_id = inb((int)bd->port);
1235 if ((board_id & 0x1) == 0x1) { 1248 if ((board_id & 0x1) == 0x1) {
1236 /* it's an XI card */ 1249 /* it's an XI card */
1237 /* Is it a 64K board */ 1250 /* Is it a 64K board */
1238 if ((board_id & 0x30) == 0) 1251 if ((board_id & 0x30) == 0)
1239 bd->memory_seg = 0xf000; 1252 bd->memory_seg = 0xf000;
1240 1253
1241 /* Is it a 128K board */ 1254 /* Is it a 128K board */
1242 if ((board_id & 0x30) == 0x10) 1255 if ((board_id & 0x30) == 0x10)
1243 bd->memory_seg = 0xe000; 1256 bd->memory_seg = 0xe000;
1244 1257
1245 /* Is is a 256K board */ 1258 /* Is is a 256K board */
1246 if ((board_id & 0x30) == 0x20) 1259 if ((board_id & 0x30) == 0x20)
1247 bd->memory_seg = 0xc000; 1260 bd->memory_seg = 0xc000;
1248 1261
1249 /* Is it a 512K board */ 1262 /* Is it a 512K board */
1250 if ((board_id & 0x30) == 0x30) 1263 if ((board_id & 0x30) == 0x30)
1251 bd->memory_seg = 0x8000; 1264 bd->memory_seg = 0x8000;
1252 } else 1265 } else
1253 printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n", (int)bd->port); 1266 printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n", (int)bd->port);
1254 break; 1267 break;
1255 } 1268 }
1256 } 1269 }
1257 1270
1258 err = tty_register_driver(pc_driver); 1271 err = tty_register_driver(pc_driver);
1259 if (err) { 1272 if (err) {
1260 printk(KERN_ERR "Couldn't register Digi PC/ driver"); 1273 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1261 goto out3; 1274 goto out3;
1262 } 1275 }
1263 1276
1264 err = tty_register_driver(pc_info); 1277 err = tty_register_driver(pc_info);
1265 if (err) { 1278 if (err) {
1266 printk(KERN_ERR "Couldn't register Digi PC/ info "); 1279 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1267 goto out4; 1280 goto out4;
1268 } 1281 }
1269 1282
1270 /* Start up the poller to check for events on all enabled boards */ 1283 /* Start up the poller to check for events on all enabled boards */
1271 init_timer(&epca_timer); 1284 init_timer(&epca_timer);
1272 epca_timer.function = epcapoll; 1285 epca_timer.function = epcapoll;
1273 mod_timer(&epca_timer, jiffies + HZ/25); 1286 mod_timer(&epca_timer, jiffies + HZ/25);
1274 return 0; 1287 return 0;
1275 1288
1276 out4: 1289 out4:
1277 tty_unregister_driver(pc_driver); 1290 tty_unregister_driver(pc_driver);
1278 out3: 1291 out3:
1279 put_tty_driver(pc_info); 1292 put_tty_driver(pc_info);
1280 out2: 1293 out2:
1281 put_tty_driver(pc_driver); 1294 put_tty_driver(pc_driver);
1282 out1: 1295 out1:
1283 return err; 1296 return err;
1284 } 1297 }
1285 1298
1286 static void post_fep_init(unsigned int crd) 1299 static void post_fep_init(unsigned int crd)
1287 { 1300 {
1288 int i; 1301 int i;
1289 void __iomem *memaddr; 1302 void __iomem *memaddr;
1290 struct global_data __iomem *gd; 1303 struct global_data __iomem *gd;
1291 struct board_info *bd; 1304 struct board_info *bd;
1292 struct board_chan __iomem *bc; 1305 struct board_chan __iomem *bc;
1293 struct channel *ch; 1306 struct channel *ch;
1294 int shrinkmem = 0, lowwater; 1307 int shrinkmem = 0, lowwater;
1295 1308
1296 /* 1309 /*
1297 * This call is made by the user via. the ioctl call DIGI_INIT. It is 1310 * This call is made by the user via. the ioctl call DIGI_INIT. It is
1298 * responsible for setting up all the card specific stuff. 1311 * responsible for setting up all the card specific stuff.
1299 */ 1312 */
1300 bd = &boards[crd]; 1313 bd = &boards[crd];
1301 1314
1302 /* 1315 /*
1303 * If this is a PCI board, get the port info. Remember PCI cards do not 1316 * If this is a PCI board, get the port info. Remember PCI cards do not
1304 * have entries into the epcaconfig.h file, so we can't get the number 1317 * have entries into the epcaconfig.h file, so we can't get the number
1305 * of ports from it. Unfortunetly, this means that anyone doing a 1318 * of ports from it. Unfortunetly, this means that anyone doing a
1306 * DIGI_GETINFO before the board has booted will get an invalid number 1319 * DIGI_GETINFO before the board has booted will get an invalid number
1307 * of ports returned (It should return 0). Calls to DIGI_GETINFO after 1320 * of ports returned (It should return 0). Calls to DIGI_GETINFO after
1308 * DIGI_INIT has been called will return the proper values. 1321 * DIGI_INIT has been called will return the proper values.
1309 */ 1322 */
1310 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */ 1323 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
1311 /* 1324 /*
1312 * Below we use XEMPORTS as a memory offset regardless of which 1325 * Below we use XEMPORTS as a memory offset regardless of which
1313 * PCI card it is. This is because all of the supported PCI 1326 * PCI card it is. This is because all of the supported PCI
1314 * cards have the same memory offset for the channel data. This 1327 * cards have the same memory offset for the channel data. This
1315 * will have to be changed if we ever develop a PCI/XE card. 1328 * will have to be changed if we ever develop a PCI/XE card.
1316 * NOTE : The FEP manual states that the port offset is 0xC22 1329 * NOTE : The FEP manual states that the port offset is 0xC22
1317 * as opposed to 0xC02. This is only true for PC/XE, and PC/XI 1330 * as opposed to 0xC02. This is only true for PC/XE, and PC/XI
1318 * cards; not for the XEM, or CX series. On the PCI cards the 1331 * cards; not for the XEM, or CX series. On the PCI cards the
1319 * number of ports is determined by reading a ID PROM located 1332 * number of ports is determined by reading a ID PROM located
1320 * in the box attached to the card. The card can then determine 1333 * in the box attached to the card. The card can then determine
1321 * the index the id to determine the number of ports available. 1334 * the index the id to determine the number of ports available.
1322 * (FYI - The id should be located at 0x1ac (And may use up to 1335 * (FYI - The id should be located at 0x1ac (And may use up to
1323 * 4 bytes if the box in question is a XEM or CX)). 1336 * 4 bytes if the box in question is a XEM or CX)).
1324 */ 1337 */
1325 /* PCI cards are already remapped at this point ISA are not */ 1338 /* PCI cards are already remapped at this point ISA are not */
1326 bd->numports = readw(bd->re_map_membase + XEMPORTS); 1339 bd->numports = readw(bd->re_map_membase + XEMPORTS);
1327 epcaassert(bd->numports <= 64, "PCI returned a invalid number of ports"); 1340 epcaassert(bd->numports <= 64, "PCI returned a invalid number of ports");
1328 nbdevs += (bd->numports); 1341 nbdevs += (bd->numports);
1329 } else { 1342 } else {
1330 /* Fix up the mappings for ISA/EISA etc */ 1343 /* Fix up the mappings for ISA/EISA etc */
1331 /* FIXME: 64K - can we be smarter ? */ 1344 /* FIXME: 64K - can we be smarter ? */
1332 bd->re_map_membase = ioremap_nocache(bd->membase, 0x10000); 1345 bd->re_map_membase = ioremap_nocache(bd->membase, 0x10000);
1333 } 1346 }
1334 1347
1335 if (crd != 0) 1348 if (crd != 0)
1336 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports; 1349 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1337 else 1350 else
1338 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */ 1351 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1339 1352
1340 ch = card_ptr[crd]; 1353 ch = card_ptr[crd];
1341 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range"); 1354 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1342 1355
1343 memaddr = bd->re_map_membase; 1356 memaddr = bd->re_map_membase;
1344 1357
1345 /* 1358 /*
1346 * The below assignment will set bc to point at the BEGINING of the 1359 * The below assignment will set bc to point at the BEGINING of the
1347 * cards channel structures. For 1 card there will be between 8 and 64 1360 * cards channel structures. For 1 card there will be between 8 and 64
1348 * of these structures. 1361 * of these structures.
1349 */ 1362 */
1350 bc = memaddr + CHANSTRUCT; 1363 bc = memaddr + CHANSTRUCT;
1351 1364
1352 /* 1365 /*
1353 * The below assignment will set gd to point at the BEGINING of global 1366 * The below assignment will set gd to point at the BEGINING of global
1354 * memory address 0xc00. The first data in that global memory actually 1367 * memory address 0xc00. The first data in that global memory actually
1355 * starts at address 0xc1a. The command in pointer begins at 0xd10. 1368 * starts at address 0xc1a. The command in pointer begins at 0xd10.
1356 */ 1369 */
1357 gd = memaddr + GLOBAL; 1370 gd = memaddr + GLOBAL;
1358 1371
1359 /* 1372 /*
1360 * XEPORTS (address 0xc22) points at the number of channels the card 1373 * XEPORTS (address 0xc22) points at the number of channels the card
1361 * supports. (For 64XE, XI, XEM, and XR use 0xc02) 1374 * supports. (For 64XE, XI, XEM, and XR use 0xc02)
1362 */ 1375 */
1363 if ((bd->type == PCXEVE || bd->type == PCXE) && 1376 if ((bd->type == PCXEVE || bd->type == PCXE) &&
1364 (readw(memaddr + XEPORTS) < 3)) 1377 (readw(memaddr + XEPORTS) < 3))
1365 shrinkmem = 1; 1378 shrinkmem = 1;
1366 if (bd->type < PCIXEM) 1379 if (bd->type < PCIXEM)
1367 if (!request_region((int)bd->port, 4, board_desc[bd->type])) 1380 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1368 return; 1381 return;
1369 memwinon(bd, 0); 1382 memwinon(bd, 0);
1370 1383
1371 /* 1384 /*
1372 * Remember ch is the main drivers channels structure, while bc is the 1385 * Remember ch is the main drivers channels structure, while bc is the
1373 * cards channel structure. 1386 * cards channel structure.
1374 */ 1387 */
1375 for (i = 0; i < bd->numports; i++, ch++, bc++) { 1388 for (i = 0; i < bd->numports; i++, ch++, bc++) {
1376 unsigned long flags; 1389 unsigned long flags;
1377 u16 tseg, rseg; 1390 u16 tseg, rseg;
1378 1391
1379 tty_port_init(&ch->port); 1392 tty_port_init(&ch->port);
1380 ch->brdchan = bc; 1393 ch->brdchan = bc;
1381 ch->mailbox = gd; 1394 ch->mailbox = gd;
1382 INIT_WORK(&ch->tqueue, do_softint); 1395 INIT_WORK(&ch->tqueue, do_softint);
1383 ch->board = &boards[crd]; 1396 ch->board = &boards[crd];
1384 1397
1385 spin_lock_irqsave(&epca_lock, flags); 1398 spin_lock_irqsave(&epca_lock, flags);
1386 switch (bd->type) { 1399 switch (bd->type) {
1387 /* 1400 /*
1388 * Since some of the boards use different bitmaps for 1401 * Since some of the boards use different bitmaps for
1389 * their control signals we cannot hard code these 1402 * their control signals we cannot hard code these
1390 * values and retain portability. We virtualize this 1403 * values and retain portability. We virtualize this
1391 * data here. 1404 * data here.
1392 */ 1405 */
1393 case EISAXEM: 1406 case EISAXEM:
1394 case PCXEM: 1407 case PCXEM:
1395 case PCIXEM: 1408 case PCIXEM:
1396 case PCIXRJ: 1409 case PCIXRJ:
1397 case PCIXR: 1410 case PCIXR:
1398 ch->m_rts = 0x02; 1411 ch->m_rts = 0x02;
1399 ch->m_dcd = 0x80; 1412 ch->m_dcd = 0x80;
1400 ch->m_dsr = 0x20; 1413 ch->m_dsr = 0x20;
1401 ch->m_cts = 0x10; 1414 ch->m_cts = 0x10;
1402 ch->m_ri = 0x40; 1415 ch->m_ri = 0x40;
1403 ch->m_dtr = 0x01; 1416 ch->m_dtr = 0x01;
1404 break; 1417 break;
1405 1418
1406 case PCXE: 1419 case PCXE:
1407 case PCXEVE: 1420 case PCXEVE:
1408 case PCXI: 1421 case PCXI:
1409 case PC64XE: 1422 case PC64XE:
1410 ch->m_rts = 0x02; 1423 ch->m_rts = 0x02;
1411 ch->m_dcd = 0x08; 1424 ch->m_dcd = 0x08;
1412 ch->m_dsr = 0x10; 1425 ch->m_dsr = 0x10;
1413 ch->m_cts = 0x20; 1426 ch->m_cts = 0x20;
1414 ch->m_ri = 0x40; 1427 ch->m_ri = 0x40;
1415 ch->m_dtr = 0x80; 1428 ch->m_dtr = 0x80;
1416 break; 1429 break;
1417 } 1430 }
1418 1431
1419 if (boards[crd].altpin) { 1432 if (boards[crd].altpin) {
1420 ch->dsr = ch->m_dcd; 1433 ch->dsr = ch->m_dcd;
1421 ch->dcd = ch->m_dsr; 1434 ch->dcd = ch->m_dsr;
1422 ch->digiext.digi_flags |= DIGI_ALTPIN; 1435 ch->digiext.digi_flags |= DIGI_ALTPIN;
1423 } else { 1436 } else {
1424 ch->dcd = ch->m_dcd; 1437 ch->dcd = ch->m_dcd;
1425 ch->dsr = ch->m_dsr; 1438 ch->dsr = ch->m_dsr;
1426 } 1439 }
1427 1440
1428 ch->boardnum = crd; 1441 ch->boardnum = crd;
1429 ch->channelnum = i; 1442 ch->channelnum = i;
1430 ch->magic = EPCA_MAGIC; 1443 ch->magic = EPCA_MAGIC;
1431 ch->port.tty = NULL; 1444 ch->port.tty = NULL;
1432 1445
1433 if (shrinkmem) { 1446 if (shrinkmem) {
1434 fepcmd(ch, SETBUFFER, 32, 0, 0, 0); 1447 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1435 shrinkmem = 0; 1448 shrinkmem = 0;
1436 } 1449 }
1437 1450
1438 tseg = readw(&bc->tseg); 1451 tseg = readw(&bc->tseg);
1439 rseg = readw(&bc->rseg); 1452 rseg = readw(&bc->rseg);
1440 1453
1441 switch (bd->type) { 1454 switch (bd->type) {
1442 case PCIXEM: 1455 case PCIXEM:
1443 case PCIXRJ: 1456 case PCIXRJ:
1444 case PCIXR: 1457 case PCIXR:
1445 /* Cover all the 2MEG cards */ 1458 /* Cover all the 2MEG cards */
1446 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff); 1459 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1447 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff); 1460 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1448 ch->txwin = FEPWIN | (tseg >> 11); 1461 ch->txwin = FEPWIN | (tseg >> 11);
1449 ch->rxwin = FEPWIN | (rseg >> 11); 1462 ch->rxwin = FEPWIN | (rseg >> 11);
1450 break; 1463 break;
1451 1464
1452 case PCXEM: 1465 case PCXEM:
1453 case EISAXEM: 1466 case EISAXEM:
1454 /* Cover all the 32K windowed cards */ 1467 /* Cover all the 32K windowed cards */
1455 /* Mask equal to window size - 1 */ 1468 /* Mask equal to window size - 1 */
1456 ch->txptr = memaddr + ((tseg << 4) & 0x7fff); 1469 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1457 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff); 1470 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1458 ch->txwin = FEPWIN | (tseg >> 11); 1471 ch->txwin = FEPWIN | (tseg >> 11);
1459 ch->rxwin = FEPWIN | (rseg >> 11); 1472 ch->rxwin = FEPWIN | (rseg >> 11);
1460 break; 1473 break;
1461 1474
1462 case PCXEVE: 1475 case PCXEVE:
1463 case PCXE: 1476 case PCXE:
1464 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4) 1477 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4)
1465 & 0x1fff); 1478 & 0x1fff);
1466 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9); 1479 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1467 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4) 1480 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4)
1468 & 0x1fff); 1481 & 0x1fff);
1469 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >> 9); 1482 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >> 9);
1470 break; 1483 break;
1471 1484
1472 case PCXI: 1485 case PCXI:
1473 case PC64XE: 1486 case PC64XE:
1474 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4); 1487 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1475 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4); 1488 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
1476 ch->txwin = ch->rxwin = 0; 1489 ch->txwin = ch->rxwin = 0;
1477 break; 1490 break;
1478 } 1491 }
1479 1492
1480 ch->txbufhead = 0; 1493 ch->txbufhead = 0;
1481 ch->txbufsize = readw(&bc->tmax) + 1; 1494 ch->txbufsize = readw(&bc->tmax) + 1;
1482 1495
1483 ch->rxbufhead = 0; 1496 ch->rxbufhead = 0;
1484 ch->rxbufsize = readw(&bc->rmax) + 1; 1497 ch->rxbufsize = readw(&bc->rmax) + 1;
1485 1498
1486 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2); 1499 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1487 1500
1488 /* Set transmitter low water mark */ 1501 /* Set transmitter low water mark */
1489 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0); 1502 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1490 1503
1491 /* Set receiver low water mark */ 1504 /* Set receiver low water mark */
1492 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0); 1505 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1493 1506
1494 /* Set receiver high water mark */ 1507 /* Set receiver high water mark */
1495 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0); 1508 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1496 1509
1497 writew(100, &bc->edelay); 1510 writew(100, &bc->edelay);
1498 writeb(1, &bc->idata); 1511 writeb(1, &bc->idata);
1499 1512
1500 ch->startc = readb(&bc->startc); 1513 ch->startc = readb(&bc->startc);
1501 ch->stopc = readb(&bc->stopc); 1514 ch->stopc = readb(&bc->stopc);
1502 ch->startca = readb(&bc->startca); 1515 ch->startca = readb(&bc->startca);
1503 ch->stopca = readb(&bc->stopca); 1516 ch->stopca = readb(&bc->stopca);
1504 1517
1505 ch->fepcflag = 0; 1518 ch->fepcflag = 0;
1506 ch->fepiflag = 0; 1519 ch->fepiflag = 0;
1507 ch->fepoflag = 0; 1520 ch->fepoflag = 0;
1508 ch->fepstartc = 0; 1521 ch->fepstartc = 0;
1509 ch->fepstopc = 0; 1522 ch->fepstopc = 0;
1510 ch->fepstartca = 0; 1523 ch->fepstartca = 0;
1511 ch->fepstopca = 0; 1524 ch->fepstopca = 0;
1512 1525
1513 ch->close_delay = 50; 1526 ch->close_delay = 50;
1514 1527
1515 spin_unlock_irqrestore(&epca_lock, flags); 1528 spin_unlock_irqrestore(&epca_lock, flags);
1516 } 1529 }
1517 1530
1518 printk(KERN_INFO 1531 printk(KERN_INFO
1519 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n", 1532 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1520 VERSION, board_desc[bd->type], (long)bd->port, 1533 VERSION, board_desc[bd->type], (long)bd->port,
1521 (long)bd->membase, bd->numports); 1534 (long)bd->membase, bd->numports);
1522 memwinoff(bd, 0); 1535 memwinoff(bd, 0);
1523 } 1536 }
1524 1537
1525 static void epcapoll(unsigned long ignored) 1538 static void epcapoll(unsigned long ignored)
1526 { 1539 {
1527 unsigned long flags; 1540 unsigned long flags;
1528 int crd; 1541 int crd;
1529 unsigned int head, tail; 1542 unsigned int head, tail;
1530 struct channel *ch; 1543 struct channel *ch;
1531 struct board_info *bd; 1544 struct board_info *bd;
1532 1545
1533 /* 1546 /*
1534 * This routine is called upon every timer interrupt. Even though the 1547 * This routine is called upon every timer interrupt. Even though the
1535 * Digi series cards are capable of generating interrupts this method 1548 * Digi series cards are capable of generating interrupts this method
1536 * of non-looping polling is more efficient. This routine checks for 1549 * of non-looping polling is more efficient. This routine checks for
1537 * card generated events (Such as receive data, are transmit buffer 1550 * card generated events (Such as receive data, are transmit buffer
1538 * empty) and acts on those events. 1551 * empty) and acts on those events.
1539 */ 1552 */
1540 for (crd = 0; crd < num_cards; crd++) { 1553 for (crd = 0; crd < num_cards; crd++) {
1541 bd = &boards[crd]; 1554 bd = &boards[crd];
1542 ch = card_ptr[crd]; 1555 ch = card_ptr[crd];
1543 1556
1544 if ((bd->status == DISABLED) || digi_poller_inhibited) 1557 if ((bd->status == DISABLED) || digi_poller_inhibited)
1545 continue; 1558 continue;
1546 1559
1547 /* 1560 /*
1548 * assertmemoff is not needed here; indeed it is an empty 1561 * assertmemoff is not needed here; indeed it is an empty
1549 * subroutine. It is being kept because future boards may need 1562 * subroutine. It is being kept because future boards may need
1550 * this as well as some legacy boards. 1563 * this as well as some legacy boards.
1551 */ 1564 */
1552 spin_lock_irqsave(&epca_lock, flags); 1565 spin_lock_irqsave(&epca_lock, flags);
1553 1566
1554 assertmemoff(ch); 1567 assertmemoff(ch);
1555 1568
1556 globalwinon(ch); 1569 globalwinon(ch);
1557 1570
1558 /* 1571 /*
1559 * In this case head and tail actually refer to the event queue 1572 * In this case head and tail actually refer to the event queue
1560 * not the transmit or receive queue. 1573 * not the transmit or receive queue.
1561 */ 1574 */
1562 head = readw(&ch->mailbox->ein); 1575 head = readw(&ch->mailbox->ein);
1563 tail = readw(&ch->mailbox->eout); 1576 tail = readw(&ch->mailbox->eout);
1564 1577
1565 /* If head isn't equal to tail we have an event */ 1578 /* If head isn't equal to tail we have an event */
1566 if (head != tail) 1579 if (head != tail)
1567 doevent(crd); 1580 doevent(crd);
1568 memoff(ch); 1581 memoff(ch);
1569 1582
1570 spin_unlock_irqrestore(&epca_lock, flags); 1583 spin_unlock_irqrestore(&epca_lock, flags);
1571 } /* End for each card */ 1584 } /* End for each card */
1572 mod_timer(&epca_timer, jiffies + (HZ / 25)); 1585 mod_timer(&epca_timer, jiffies + (HZ / 25));
1573 } 1586 }
1574 1587
1575 static void doevent(int crd) 1588 static void doevent(int crd)
1576 { 1589 {
1577 void __iomem *eventbuf; 1590 void __iomem *eventbuf;
1578 struct channel *ch, *chan0; 1591 struct channel *ch, *chan0;
1579 static struct tty_struct *tty; 1592 static struct tty_struct *tty;
1580 struct board_info *bd; 1593 struct board_info *bd;
1581 struct board_chan __iomem *bc; 1594 struct board_chan __iomem *bc;
1582 unsigned int tail, head; 1595 unsigned int tail, head;
1583 int event, channel; 1596 int event, channel;
1584 int mstat, lstat; 1597 int mstat, lstat;
1585 1598
1586 /* 1599 /*
1587 * This subroutine is called by epcapoll when an event is detected 1600 * This subroutine is called by epcapoll when an event is detected
1588 * in the event queue. This routine responds to those events. 1601 * in the event queue. This routine responds to those events.
1589 */ 1602 */
1590 bd = &boards[crd]; 1603 bd = &boards[crd];
1591 1604
1592 chan0 = card_ptr[crd]; 1605 chan0 = card_ptr[crd];
1593 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range"); 1606 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
1594 assertgwinon(chan0); 1607 assertgwinon(chan0);
1595 while ((tail = readw(&chan0->mailbox->eout)) != 1608 while ((tail = readw(&chan0->mailbox->eout)) !=
1596 (head = readw(&chan0->mailbox->ein))) { 1609 (head = readw(&chan0->mailbox->ein))) {
1597 /* Begin while something in event queue */ 1610 /* Begin while something in event queue */
1598 assertgwinon(chan0); 1611 assertgwinon(chan0);
1599 eventbuf = bd->re_map_membase + tail + ISTART; 1612 eventbuf = bd->re_map_membase + tail + ISTART;
1600 /* Get the channel the event occurred on */ 1613 /* Get the channel the event occurred on */
1601 channel = readb(eventbuf); 1614 channel = readb(eventbuf);
1602 /* Get the actual event code that occurred */ 1615 /* Get the actual event code that occurred */
1603 event = readb(eventbuf + 1); 1616 event = readb(eventbuf + 1);
1604 /* 1617 /*
1605 * The two assignments below get the current modem status 1618 * The two assignments below get the current modem status
1606 * (mstat) and the previous modem status (lstat). These are 1619 * (mstat) and the previous modem status (lstat). These are
1607 * useful becuase an event could signal a change in modem 1620 * useful becuase an event could signal a change in modem
1608 * signals itself. 1621 * signals itself.
1609 */ 1622 */
1610 mstat = readb(eventbuf + 2); 1623 mstat = readb(eventbuf + 2);
1611 lstat = readb(eventbuf + 3); 1624 lstat = readb(eventbuf + 3);
1612 1625
1613 ch = chan0 + channel; 1626 ch = chan0 + channel;
1614 if ((unsigned)channel >= bd->numports || !ch) { 1627 if ((unsigned)channel >= bd->numports || !ch) {
1615 if (channel >= bd->numports) 1628 if (channel >= bd->numports)
1616 ch = chan0; 1629 ch = chan0;
1617 bc = ch->brdchan; 1630 bc = ch->brdchan;
1618 goto next; 1631 goto next;
1619 } 1632 }
1620 1633
1621 bc = ch->brdchan; 1634 bc = ch->brdchan;
1622 if (bc == NULL) 1635 if (bc == NULL)
1623 goto next; 1636 goto next;
1624 1637
1625 if (event & DATA_IND) { /* Begin DATA_IND */ 1638 if (event & DATA_IND) { /* Begin DATA_IND */
1626 receive_data(ch); 1639 receive_data(ch);
1627 assertgwinon(ch); 1640 assertgwinon(ch);
1628 } /* End DATA_IND */ 1641 } /* End DATA_IND */
1629 /* else *//* Fix for DCD transition missed bug */ 1642 /* else *//* Fix for DCD transition missed bug */
1630 if (event & MODEMCHG_IND) { 1643 if (event & MODEMCHG_IND) {
1631 /* A modem signal change has been indicated */ 1644 /* A modem signal change has been indicated */
1632 ch->imodem = mstat; 1645 ch->imodem = mstat;
1633 if (ch->port.flags & ASYNC_CHECK_CD) { 1646 if (ch->port.flags & ASYNC_CHECK_CD) {
1634 /* We are now receiving dcd */ 1647 /* We are now receiving dcd */
1635 if (mstat & ch->dcd) 1648 if (mstat & ch->dcd)
1636 wake_up_interruptible(&ch->port.open_wait); 1649 wake_up_interruptible(&ch->port.open_wait);
1637 else /* No dcd; hangup */ 1650 else /* No dcd; hangup */
1638 pc_sched_event(ch, EPCA_EVENT_HANGUP); 1651 pc_sched_event(ch, EPCA_EVENT_HANGUP);
1639 } 1652 }
1640 } 1653 }
1641 tty = ch->port.tty; 1654 tty = ch->port.tty;
1642 if (tty) { 1655 if (tty) {
1643 if (event & BREAK_IND) { 1656 if (event & BREAK_IND) {
1644 /* A break has been indicated */ 1657 /* A break has been indicated */
1645 tty_insert_flip_char(tty, 0, TTY_BREAK); 1658 tty_insert_flip_char(tty, 0, TTY_BREAK);
1646 tty_schedule_flip(tty); 1659 tty_schedule_flip(tty);
1647 } else if (event & LOWTX_IND) { 1660 } else if (event & LOWTX_IND) {
1648 if (ch->statusflags & LOWWAIT) { 1661 if (ch->statusflags & LOWWAIT) {
1649 ch->statusflags &= ~LOWWAIT; 1662 ch->statusflags &= ~LOWWAIT;
1650 tty_wakeup(tty); 1663 tty_wakeup(tty);
1651 } 1664 }
1652 } else if (event & EMPTYTX_IND) { 1665 } else if (event & EMPTYTX_IND) {
1653 /* This event is generated by 1666 /* This event is generated by
1654 setup_empty_event */ 1667 setup_empty_event */
1655 ch->statusflags &= ~TXBUSY; 1668 ch->statusflags &= ~TXBUSY;
1656 if (ch->statusflags & EMPTYWAIT) { 1669 if (ch->statusflags & EMPTYWAIT) {
1657 ch->statusflags &= ~EMPTYWAIT; 1670 ch->statusflags &= ~EMPTYWAIT;
1658 tty_wakeup(tty); 1671 tty_wakeup(tty);
1659 } 1672 }
1660 } 1673 }
1661 } 1674 }
1662 next: 1675 next:
1663 globalwinon(ch); 1676 globalwinon(ch);
1664 BUG_ON(!bc); 1677 BUG_ON(!bc);
1665 writew(1, &bc->idata); 1678 writew(1, &bc->idata);
1666 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout); 1679 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
1667 globalwinon(chan0); 1680 globalwinon(chan0);
1668 } /* End while something in event queue */ 1681 } /* End while something in event queue */
1669 } 1682 }
1670 1683
1671 static void fepcmd(struct channel *ch, int cmd, int word_or_byte, 1684 static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1672 int byte2, int ncmds, int bytecmd) 1685 int byte2, int ncmds, int bytecmd)
1673 { 1686 {
1674 unchar __iomem *memaddr; 1687 unchar __iomem *memaddr;
1675 unsigned int head, cmdTail, cmdStart, cmdMax; 1688 unsigned int head, cmdTail, cmdStart, cmdMax;
1676 long count; 1689 long count;
1677 int n; 1690 int n;
1678 1691
1679 /* This is the routine in which commands may be passed to the card. */ 1692 /* This is the routine in which commands may be passed to the card. */
1680 1693
1681 if (ch->board->status == DISABLED) 1694 if (ch->board->status == DISABLED)
1682 return; 1695 return;
1683 assertgwinon(ch); 1696 assertgwinon(ch);
1684 /* Remember head (As well as max) is just an offset not a base addr */ 1697 /* Remember head (As well as max) is just an offset not a base addr */
1685 head = readw(&ch->mailbox->cin); 1698 head = readw(&ch->mailbox->cin);
1686 /* cmdStart is a base address */ 1699 /* cmdStart is a base address */
1687 cmdStart = readw(&ch->mailbox->cstart); 1700 cmdStart = readw(&ch->mailbox->cstart);
1688 /* 1701 /*
1689 * We do the addition below because we do not want a max pointer 1702 * We do the addition below because we do not want a max pointer
1690 * relative to cmdStart. We want a max pointer that points at the 1703 * relative to cmdStart. We want a max pointer that points at the
1691 * physical end of the command queue. 1704 * physical end of the command queue.
1692 */ 1705 */
1693 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax)); 1706 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
1694 memaddr = ch->board->re_map_membase; 1707 memaddr = ch->board->re_map_membase;
1695 1708
1696 if (head >= (cmdMax - cmdStart) || (head & 03)) { 1709 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1697 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", 1710 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n",
1698 __LINE__, cmd, head); 1711 __LINE__, cmd, head);
1699 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", 1712 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n",
1700 __LINE__, cmdMax, cmdStart); 1713 __LINE__, cmdMax, cmdStart);
1701 return; 1714 return;
1702 } 1715 }
1703 if (bytecmd) { 1716 if (bytecmd) {
1704 writeb(cmd, memaddr + head + cmdStart + 0); 1717 writeb(cmd, memaddr + head + cmdStart + 0);
1705 writeb(ch->channelnum, memaddr + head + cmdStart + 1); 1718 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1706 /* Below word_or_byte is bits to set */ 1719 /* Below word_or_byte is bits to set */
1707 writeb(word_or_byte, memaddr + head + cmdStart + 2); 1720 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1708 /* Below byte2 is bits to reset */ 1721 /* Below byte2 is bits to reset */
1709 writeb(byte2, memaddr + head + cmdStart + 3); 1722 writeb(byte2, memaddr + head + cmdStart + 3);
1710 } else { 1723 } else {
1711 writeb(cmd, memaddr + head + cmdStart + 0); 1724 writeb(cmd, memaddr + head + cmdStart + 0);
1712 writeb(ch->channelnum, memaddr + head + cmdStart + 1); 1725 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1713 writeb(word_or_byte, memaddr + head + cmdStart + 2); 1726 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1714 } 1727 }
1715 head = (head + 4) & (cmdMax - cmdStart - 4); 1728 head = (head + 4) & (cmdMax - cmdStart - 4);
1716 writew(head, &ch->mailbox->cin); 1729 writew(head, &ch->mailbox->cin);
1717 count = FEPTIMEOUT; 1730 count = FEPTIMEOUT;
1718 1731
1719 for (;;) { 1732 for (;;) {
1720 count--; 1733 count--;
1721 if (count == 0) { 1734 if (count == 0) {
1722 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n"); 1735 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1723 return; 1736 return;
1724 } 1737 }
1725 head = readw(&ch->mailbox->cin); 1738 head = readw(&ch->mailbox->cin);
1726 cmdTail = readw(&ch->mailbox->cout); 1739 cmdTail = readw(&ch->mailbox->cout);
1727 n = (head - cmdTail) & (cmdMax - cmdStart - 4); 1740 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
1728 /* 1741 /*
1729 * Basically this will break when the FEP acknowledges the 1742 * Basically this will break when the FEP acknowledges the
1730 * command by incrementing cmdTail (Making it equal to head). 1743 * command by incrementing cmdTail (Making it equal to head).
1731 */ 1744 */
1732 if (n <= ncmds * (sizeof(short) * 4)) 1745 if (n <= ncmds * (sizeof(short) * 4))
1733 break; 1746 break;
1734 } 1747 }
1735 } 1748 }
1736 1749
1737 /* 1750 /*
1738 * Digi products use fields in their channels structures that are very similar 1751 * Digi products use fields in their channels structures that are very similar
1739 * to the c_cflag and c_iflag fields typically found in UNIX termios 1752 * to the c_cflag and c_iflag fields typically found in UNIX termios
1740 * structures. The below three routines allow mappings between these hardware 1753 * structures. The below three routines allow mappings between these hardware
1741 * "flags" and their respective Linux flags. 1754 * "flags" and their respective Linux flags.
1742 */ 1755 */
1743 static unsigned termios2digi_h(struct channel *ch, unsigned cflag) 1756 static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1744 { 1757 {
1745 unsigned res = 0; 1758 unsigned res = 0;
1746 1759
1747 if (cflag & CRTSCTS) { 1760 if (cflag & CRTSCTS) {
1748 ch->digiext.digi_flags |= (RTSPACE | CTSPACE); 1761 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1749 res |= ((ch->m_cts) | (ch->m_rts)); 1762 res |= ((ch->m_cts) | (ch->m_rts));
1750 } 1763 }
1751 1764
1752 if (ch->digiext.digi_flags & RTSPACE) 1765 if (ch->digiext.digi_flags & RTSPACE)
1753 res |= ch->m_rts; 1766 res |= ch->m_rts;
1754 1767
1755 if (ch->digiext.digi_flags & DTRPACE) 1768 if (ch->digiext.digi_flags & DTRPACE)
1756 res |= ch->m_dtr; 1769 res |= ch->m_dtr;
1757 1770
1758 if (ch->digiext.digi_flags & CTSPACE) 1771 if (ch->digiext.digi_flags & CTSPACE)
1759 res |= ch->m_cts; 1772 res |= ch->m_cts;
1760 1773
1761 if (ch->digiext.digi_flags & DSRPACE) 1774 if (ch->digiext.digi_flags & DSRPACE)
1762 res |= ch->dsr; 1775 res |= ch->dsr;
1763 1776
1764 if (ch->digiext.digi_flags & DCDPACE) 1777 if (ch->digiext.digi_flags & DCDPACE)
1765 res |= ch->dcd; 1778 res |= ch->dcd;
1766 1779
1767 if (res & (ch->m_rts)) 1780 if (res & (ch->m_rts))
1768 ch->digiext.digi_flags |= RTSPACE; 1781 ch->digiext.digi_flags |= RTSPACE;
1769 1782
1770 if (res & (ch->m_cts)) 1783 if (res & (ch->m_cts))
1771 ch->digiext.digi_flags |= CTSPACE; 1784 ch->digiext.digi_flags |= CTSPACE;
1772 1785
1773 return res; 1786 return res;
1774 } 1787 }
1775 1788
1776 static unsigned termios2digi_i(struct channel *ch, unsigned iflag) 1789 static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1777 { 1790 {
1778 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | 1791 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
1779 INPCK | ISTRIP | IXON | IXANY | IXOFF); 1792 INPCK | ISTRIP | IXON | IXANY | IXOFF);
1780 if (ch->digiext.digi_flags & DIGI_AIXON) 1793 if (ch->digiext.digi_flags & DIGI_AIXON)
1781 res |= IAIXON; 1794 res |= IAIXON;
1782 return res; 1795 return res;
1783 } 1796 }
1784 1797
1785 static unsigned termios2digi_c(struct channel *ch, unsigned cflag) 1798 static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
1786 { 1799 {
1787 unsigned res = 0; 1800 unsigned res = 0;
1788 if (cflag & CBAUDEX) { 1801 if (cflag & CBAUDEX) {
1789 ch->digiext.digi_flags |= DIGI_FAST; 1802 ch->digiext.digi_flags |= DIGI_FAST;
1790 /* 1803 /*
1791 * HUPCL bit is used by FEP to indicate fast baud table is to 1804 * HUPCL bit is used by FEP to indicate fast baud table is to
1792 * be used. 1805 * be used.
1793 */ 1806 */
1794 res |= FEP_HUPCL; 1807 res |= FEP_HUPCL;
1795 } else 1808 } else
1796 ch->digiext.digi_flags &= ~DIGI_FAST; 1809 ch->digiext.digi_flags &= ~DIGI_FAST;
1797 /* 1810 /*
1798 * CBAUD has bit position 0x1000 set these days to indicate Linux 1811 * CBAUD has bit position 0x1000 set these days to indicate Linux
1799 * baud rate remap. Digi hardware can't handle the bit assignment. 1812 * baud rate remap. Digi hardware can't handle the bit assignment.
1800 * (We use a different bit assignment for high speed.). Clear this 1813 * (We use a different bit assignment for high speed.). Clear this
1801 * bit out. 1814 * bit out.
1802 */ 1815 */
1803 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE); 1816 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
1804 /* 1817 /*
1805 * This gets a little confusing. The Digi cards have their own 1818 * This gets a little confusing. The Digi cards have their own
1806 * representation of c_cflags controlling baud rate. For the most part 1819 * representation of c_cflags controlling baud rate. For the most part
1807 * this is identical to the Linux implementation. However; Digi 1820 * this is identical to the Linux implementation. However; Digi
1808 * supports one rate (76800) that Linux doesn't. This means that the 1821 * supports one rate (76800) that Linux doesn't. This means that the
1809 * c_cflag entry that would normally mean 76800 for Digi actually means 1822 * c_cflag entry that would normally mean 76800 for Digi actually means
1810 * 115200 under Linux. Without the below mapping, a stty 115200 would 1823 * 115200 under Linux. Without the below mapping, a stty 115200 would
1811 * only drive the board at 76800. Since the rate 230400 is also found 1824 * only drive the board at 76800. Since the rate 230400 is also found
1812 * after 76800, the same problem afflicts us when we choose a rate of 1825 * after 76800, the same problem afflicts us when we choose a rate of
1813 * 230400. Without the below modificiation stty 230400 would actually 1826 * 230400. Without the below modificiation stty 230400 would actually
1814 * give us 115200. 1827 * give us 115200.
1815 * 1828 *
1816 * There are two additional differences. The Linux value for CLOCAL 1829 * There are two additional differences. The Linux value for CLOCAL
1817 * (0x800; 0004000) has no meaning to the Digi hardware. Also in later 1830 * (0x800; 0004000) has no meaning to the Digi hardware. Also in later
1818 * releases of Linux; the CBAUD define has CBAUDEX (0x1000; 0010000) 1831 * releases of Linux; the CBAUD define has CBAUDEX (0x1000; 0010000)
1819 * ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX should be 1832 * ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX should be
1820 * checked for a screened out prior to termios2digi_c returning. Since 1833 * checked for a screened out prior to termios2digi_c returning. Since
1821 * CLOCAL isn't used by the board this can be ignored as long as the 1834 * CLOCAL isn't used by the board this can be ignored as long as the
1822 * returned value is used only by Digi hardware. 1835 * returned value is used only by Digi hardware.
1823 */ 1836 */
1824 if (cflag & CBAUDEX) { 1837 if (cflag & CBAUDEX) {
1825 /* 1838 /*
1826 * The below code is trying to guarantee that only baud rates 1839 * The below code is trying to guarantee that only baud rates
1827 * 115200 and 230400 are remapped. We use exclusive or because 1840 * 115200 and 230400 are remapped. We use exclusive or because
1828 * the various baud rates share common bit positions and 1841 * the various baud rates share common bit positions and
1829 * therefore can't be tested for easily. 1842 * therefore can't be tested for easily.
1830 */ 1843 */
1831 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) || 1844 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
1832 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX)))) 1845 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
1833 res += 1; 1846 res += 1;
1834 } 1847 }
1835 return res; 1848 return res;
1836 } 1849 }
1837 1850
1838 /* Caller must hold the locks */ 1851 /* Caller must hold the locks */
1839 static void epcaparam(struct tty_struct *tty, struct channel *ch) 1852 static void epcaparam(struct tty_struct *tty, struct channel *ch)
1840 { 1853 {
1841 unsigned int cmdHead; 1854 unsigned int cmdHead;
1842 struct ktermios *ts; 1855 struct ktermios *ts;
1843 struct board_chan __iomem *bc; 1856 struct board_chan __iomem *bc;
1844 unsigned mval, hflow, cflag, iflag; 1857 unsigned mval, hflow, cflag, iflag;
1845 1858
1846 bc = ch->brdchan; 1859 bc = ch->brdchan;
1847 epcaassert(bc != NULL, "bc out of range"); 1860 epcaassert(bc != NULL, "bc out of range");
1848 1861
1849 assertgwinon(ch); 1862 assertgwinon(ch);
1850 ts = tty->termios; 1863 ts = tty->termios;
1851 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */ 1864 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
1852 cmdHead = readw(&bc->rin); 1865 cmdHead = readw(&bc->rin);
1853 writew(cmdHead, &bc->rout); 1866 writew(cmdHead, &bc->rout);
1854 cmdHead = readw(&bc->tin); 1867 cmdHead = readw(&bc->tin);
1855 /* Changing baud in mid-stream transmission can be wonderful */ 1868 /* Changing baud in mid-stream transmission can be wonderful */
1856 /* 1869 /*
1857 * Flush current transmit buffer by setting cmdTail pointer 1870 * Flush current transmit buffer by setting cmdTail pointer
1858 * (tout) to cmdHead pointer (tin). Hopefully the transmit 1871 * (tout) to cmdHead pointer (tin). Hopefully the transmit
1859 * buffer is empty. 1872 * buffer is empty.
1860 */ 1873 */
1861 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0); 1874 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
1862 mval = 0; 1875 mval = 0;
1863 } else { /* Begin CBAUD not detected */ 1876 } else { /* Begin CBAUD not detected */
1864 /* 1877 /*
1865 * c_cflags have changed but that change had nothing to do with 1878 * c_cflags have changed but that change had nothing to do with
1866 * BAUD. Propagate the change to the card. 1879 * BAUD. Propagate the change to the card.
1867 */ 1880 */
1868 cflag = termios2digi_c(ch, ts->c_cflag); 1881 cflag = termios2digi_c(ch, ts->c_cflag);
1869 if (cflag != ch->fepcflag) { 1882 if (cflag != ch->fepcflag) {
1870 ch->fepcflag = cflag; 1883 ch->fepcflag = cflag;
1871 /* Set baud rate, char size, stop bits, parity */ 1884 /* Set baud rate, char size, stop bits, parity */
1872 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0); 1885 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
1873 } 1886 }
1874 /* 1887 /*
1875 * If the user has not forced CLOCAL and if the device is not a 1888 * If the user has not forced CLOCAL and if the device is not a
1876 * CALLOUT device (Which is always CLOCAL) we set flags such 1889 * CALLOUT device (Which is always CLOCAL) we set flags such
1877 * that the driver will wait on carrier detect. 1890 * that the driver will wait on carrier detect.
1878 */ 1891 */
1879 if (ts->c_cflag & CLOCAL) 1892 if (ts->c_cflag & CLOCAL)
1880 ch->port.flags &= ~ASYNC_CHECK_CD; 1893 ch->port.flags &= ~ASYNC_CHECK_CD;
1881 else 1894 else
1882 ch->port.flags |= ASYNC_CHECK_CD; 1895 ch->port.flags |= ASYNC_CHECK_CD;
1883 mval = ch->m_dtr | ch->m_rts; 1896 mval = ch->m_dtr | ch->m_rts;
1884 } /* End CBAUD not detected */ 1897 } /* End CBAUD not detected */
1885 iflag = termios2digi_i(ch, ts->c_iflag); 1898 iflag = termios2digi_i(ch, ts->c_iflag);
1886 /* Check input mode flags */ 1899 /* Check input mode flags */
1887 if (iflag != ch->fepiflag) { 1900 if (iflag != ch->fepiflag) {
1888 ch->fepiflag = iflag; 1901 ch->fepiflag = iflag;
1889 /* 1902 /*
1890 * Command sets channels iflag structure on the board. Such 1903 * Command sets channels iflag structure on the board. Such
1891 * things as input soft flow control, handling of parity 1904 * things as input soft flow control, handling of parity
1892 * errors, and break handling are all set here. 1905 * errors, and break handling are all set here.
1893 * 1906 *
1894 * break handling, parity handling, input stripping, 1907 * break handling, parity handling, input stripping,
1895 * flow control chars 1908 * flow control chars
1896 */ 1909 */
1897 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0); 1910 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
1898 } 1911 }
1899 /* 1912 /*
1900 * Set the board mint value for this channel. This will cause hardware 1913 * Set the board mint value for this channel. This will cause hardware
1901 * events to be generated each time the DCD signal (Described in mint) 1914 * events to be generated each time the DCD signal (Described in mint)
1902 * changes. 1915 * changes.
1903 */ 1916 */
1904 writeb(ch->dcd, &bc->mint); 1917 writeb(ch->dcd, &bc->mint);
1905 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD)) 1918 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
1906 if (ch->digiext.digi_flags & DIGI_FORCEDCD) 1919 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
1907 writeb(0, &bc->mint); 1920 writeb(0, &bc->mint);
1908 ch->imodem = readb(&bc->mstat); 1921 ch->imodem = readb(&bc->mstat);
1909 hflow = termios2digi_h(ch, ts->c_cflag); 1922 hflow = termios2digi_h(ch, ts->c_cflag);
1910 if (hflow != ch->hflow) { 1923 if (hflow != ch->hflow) {
1911 ch->hflow = hflow; 1924 ch->hflow = hflow;
1912 /* 1925 /*
1913 * Hard flow control has been selected but the board is not 1926 * Hard flow control has been selected but the board is not
1914 * using it. Activate hard flow control now. 1927 * using it. Activate hard flow control now.
1915 */ 1928 */
1916 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1); 1929 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
1917 } 1930 }
1918 mval ^= ch->modemfake & (mval ^ ch->modem); 1931 mval ^= ch->modemfake & (mval ^ ch->modem);
1919 1932
1920 if (ch->omodem ^ mval) { 1933 if (ch->omodem ^ mval) {
1921 ch->omodem = mval; 1934 ch->omodem = mval;
1922 /* 1935 /*
1923 * The below command sets the DTR and RTS mstat structure. If 1936 * The below command sets the DTR and RTS mstat structure. If
1924 * hard flow control is NOT active these changes will drive the 1937 * hard flow control is NOT active these changes will drive the
1925 * output of the actual DTR and RTS lines. If hard flow control 1938 * output of the actual DTR and RTS lines. If hard flow control
1926 * is active, the changes will be saved in the mstat structure 1939 * is active, the changes will be saved in the mstat structure
1927 * and only asserted when hard flow control is turned off. 1940 * and only asserted when hard flow control is turned off.
1928 */ 1941 */
1929 1942
1930 /* First reset DTR & RTS; then set them */ 1943 /* First reset DTR & RTS; then set them */
1931 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1); 1944 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
1932 fepcmd(ch, SETMODEM, mval, 0, 0, 1); 1945 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
1933 } 1946 }
1934 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) { 1947 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
1935 ch->fepstartc = ch->startc; 1948 ch->fepstartc = ch->startc;
1936 ch->fepstopc = ch->stopc; 1949 ch->fepstopc = ch->stopc;
1937 /* 1950 /*
1938 * The XON / XOFF characters have changed; propagate these 1951 * The XON / XOFF characters have changed; propagate these
1939 * changes to the card. 1952 * changes to the card.
1940 */ 1953 */
1941 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1); 1954 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
1942 } 1955 }
1943 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) { 1956 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
1944 ch->fepstartca = ch->startca; 1957 ch->fepstartca = ch->startca;
1945 ch->fepstopca = ch->stopca; 1958 ch->fepstopca = ch->stopca;
1946 /* 1959 /*
1947 * Similar to the above, this time the auxilarly XON / XOFF 1960 * Similar to the above, this time the auxilarly XON / XOFF
1948 * characters have changed; propagate these changes to the card. 1961 * characters have changed; propagate these changes to the card.
1949 */ 1962 */
1950 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1); 1963 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
1951 } 1964 }
1952 } 1965 }
1953 1966
1954 /* Caller holds lock */ 1967 /* Caller holds lock */
1955 static void receive_data(struct channel *ch) 1968 static void receive_data(struct channel *ch)
1956 { 1969 {
1957 unchar *rptr; 1970 unchar *rptr;
1958 struct ktermios *ts = NULL; 1971 struct ktermios *ts = NULL;
1959 struct tty_struct *tty; 1972 struct tty_struct *tty;
1960 struct board_chan __iomem *bc; 1973 struct board_chan __iomem *bc;
1961 int dataToRead, wrapgap, bytesAvailable; 1974 int dataToRead, wrapgap, bytesAvailable;
1962 unsigned int tail, head; 1975 unsigned int tail, head;
1963 unsigned int wrapmask; 1976 unsigned int wrapmask;
1964 1977
1965 /* 1978 /*
1966 * This routine is called by doint when a receive data event has taken 1979 * This routine is called by doint when a receive data event has taken
1967 * place. 1980 * place.
1968 */ 1981 */
1969 globalwinon(ch); 1982 globalwinon(ch);
1970 if (ch->statusflags & RXSTOPPED) 1983 if (ch->statusflags & RXSTOPPED)
1971 return; 1984 return;
1972 tty = ch->port.tty; 1985 tty = ch->port.tty;
1973 if (tty) 1986 if (tty)
1974 ts = tty->termios; 1987 ts = tty->termios;
1975 bc = ch->brdchan; 1988 bc = ch->brdchan;
1976 BUG_ON(!bc); 1989 BUG_ON(!bc);
1977 wrapmask = ch->rxbufsize - 1; 1990 wrapmask = ch->rxbufsize - 1;
1978 1991
1979 /* 1992 /*
1980 * Get the head and tail pointers to the receiver queue. Wrap the head 1993 * Get the head and tail pointers to the receiver queue. Wrap the head
1981 * pointer if it has reached the end of the buffer. 1994 * pointer if it has reached the end of the buffer.
1982 */ 1995 */
1983 head = readw(&bc->rin); 1996 head = readw(&bc->rin);
1984 head &= wrapmask; 1997 head &= wrapmask;
1985 tail = readw(&bc->rout) & wrapmask; 1998 tail = readw(&bc->rout) & wrapmask;
1986 1999
1987 bytesAvailable = (head - tail) & wrapmask; 2000 bytesAvailable = (head - tail) & wrapmask;
1988 if (bytesAvailable == 0) 2001 if (bytesAvailable == 0)
1989 return; 2002 return;
1990 2003
1991 /* If CREAD bit is off or device not open, set TX tail to head */ 2004 /* If CREAD bit is off or device not open, set TX tail to head */
1992 if (!tty || !ts || !(ts->c_cflag & CREAD)) { 2005 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
1993 writew(head, &bc->rout); 2006 writew(head, &bc->rout);
1994 return; 2007 return;
1995 } 2008 }
1996 2009
1997 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0) 2010 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
1998 return; 2011 return;
1999 2012
2000 if (readb(&bc->orun)) { 2013 if (readb(&bc->orun)) {
2001 writeb(0, &bc->orun); 2014 writeb(0, &bc->orun);
2002 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n", 2015 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",
2003 tty->name); 2016 tty->name);
2004 tty_insert_flip_char(tty, 0, TTY_OVERRUN); 2017 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
2005 } 2018 }
2006 rxwinon(ch); 2019 rxwinon(ch);
2007 while (bytesAvailable > 0) { 2020 while (bytesAvailable > 0) {
2008 /* Begin while there is data on the card */ 2021 /* Begin while there is data on the card */
2009 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail; 2022 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
2010 /* 2023 /*
2011 * Even if head has wrapped around only report the amount of 2024 * Even if head has wrapped around only report the amount of
2012 * data to be equal to the size - tail. Remember memcpy can't 2025 * data to be equal to the size - tail. Remember memcpy can't
2013 * automaticly wrap around the receive buffer. 2026 * automaticly wrap around the receive buffer.
2014 */ 2027 */
2015 dataToRead = (wrapgap < bytesAvailable) ? wrapgap 2028 dataToRead = (wrapgap < bytesAvailable) ? wrapgap
2016 : bytesAvailable; 2029 : bytesAvailable;
2017 /* Make sure we don't overflow the buffer */ 2030 /* Make sure we don't overflow the buffer */
2018 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead); 2031 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
2019 if (dataToRead == 0) 2032 if (dataToRead == 0)
2020 break; 2033 break;
2021 /* 2034 /*
2022 * Move data read from our card into the line disciplines 2035 * Move data read from our card into the line disciplines
2023 * buffer for translation if necessary. 2036 * buffer for translation if necessary.
2024 */ 2037 */
2025 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead); 2038 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
2026 tail = (tail + dataToRead) & wrapmask; 2039 tail = (tail + dataToRead) & wrapmask;
2027 bytesAvailable -= dataToRead; 2040 bytesAvailable -= dataToRead;
2028 } /* End while there is data on the card */ 2041 } /* End while there is data on the card */
2029 globalwinon(ch); 2042 globalwinon(ch);
2030 writew(tail, &bc->rout); 2043 writew(tail, &bc->rout);
2031 /* Must be called with global data */ 2044 /* Must be called with global data */
2032 tty_schedule_flip(ch->port.tty); 2045 tty_schedule_flip(ch->port.tty);
2033 } 2046 }
2034 2047
2035 static int info_ioctl(struct tty_struct *tty, struct file *file, 2048 static int info_ioctl(struct tty_struct *tty, struct file *file,
2036 unsigned int cmd, unsigned long arg) 2049 unsigned int cmd, unsigned long arg)
2037 { 2050 {
2038 switch (cmd) { 2051 switch (cmd) {
2039 case DIGI_GETINFO: 2052 case DIGI_GETINFO:
2040 { 2053 {
2041 struct digi_info di; 2054 struct digi_info di;
2042 int brd; 2055 int brd;
2043 2056
2044 if (get_user(brd, (unsigned int __user *)arg)) 2057 if (get_user(brd, (unsigned int __user *)arg))
2045 return -EFAULT; 2058 return -EFAULT;
2046 if (brd < 0 || brd >= num_cards || num_cards == 0) 2059 if (brd < 0 || brd >= num_cards || num_cards == 0)
2047 return -ENODEV; 2060 return -ENODEV;
2048 2061
2049 memset(&di, 0, sizeof(di)); 2062 memset(&di, 0, sizeof(di));
2050 2063
2051 di.board = brd; 2064 di.board = brd;
2052 di.status = boards[brd].status; 2065 di.status = boards[brd].status;
2053 di.type = boards[brd].type ; 2066 di.type = boards[brd].type ;
2054 di.numports = boards[brd].numports ; 2067 di.numports = boards[brd].numports ;
2055 /* Legacy fixups - just move along nothing to see */ 2068 /* Legacy fixups - just move along nothing to see */
2056 di.port = (unsigned char *)boards[brd].port ; 2069 di.port = (unsigned char *)boards[brd].port ;
2057 di.membase = (unsigned char *)boards[brd].membase ; 2070 di.membase = (unsigned char *)boards[brd].membase ;
2058 2071
2059 if (copy_to_user((void __user *)arg, &di, sizeof(di))) 2072 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
2060 return -EFAULT; 2073 return -EFAULT;
2061 break; 2074 break;
2062 2075
2063 } 2076 }
2064 2077
2065 case DIGI_POLLER: 2078 case DIGI_POLLER:
2066 { 2079 {
2067 int brd = arg & 0xff000000 >> 16; 2080 int brd = arg & 0xff000000 >> 16;
2068 unsigned char state = arg & 0xff; 2081 unsigned char state = arg & 0xff;
2069 2082
2070 if (brd < 0 || brd >= num_cards) { 2083 if (brd < 0 || brd >= num_cards) {
2071 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n"); 2084 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
2072 return -ENODEV; 2085 return -ENODEV;
2073 } 2086 }
2074 digi_poller_inhibited = state; 2087 digi_poller_inhibited = state;
2075 break; 2088 break;
2076 } 2089 }
2077 2090
2078 case DIGI_INIT: 2091 case DIGI_INIT:
2079 { 2092 {
2080 /* 2093 /*
2081 * This call is made by the apps to complete the 2094 * This call is made by the apps to complete the
2082 * initialization of the board(s). This routine is 2095 * initialization of the board(s). This routine is
2083 * responsible for setting the card to its initial 2096 * responsible for setting the card to its initial
2084 * state and setting the drivers control fields to the 2097 * state and setting the drivers control fields to the
2085 * sutianle settings for the card in question. 2098 * sutianle settings for the card in question.
2086 */ 2099 */
2087 int crd; 2100 int crd;
2088 for (crd = 0; crd < num_cards; crd++) 2101 for (crd = 0; crd < num_cards; crd++)
2089 post_fep_init(crd); 2102 post_fep_init(crd);
2090 break; 2103 break;
2091 } 2104 }
2092 default: 2105 default:
2093 return -ENOTTY; 2106 return -ENOTTY;
2094 } 2107 }
2095 return 0; 2108 return 0;
2096 } 2109 }
2097 2110
2098 static int pc_tiocmget(struct tty_struct *tty, struct file *file) 2111 static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2099 { 2112 {
2100 struct channel *ch = tty->driver_data; 2113 struct channel *ch = tty->driver_data;
2101 struct board_chan __iomem *bc; 2114 struct board_chan __iomem *bc;
2102 unsigned int mstat, mflag = 0; 2115 unsigned int mstat, mflag = 0;
2103 unsigned long flags; 2116 unsigned long flags;
2104 2117
2105 if (ch) 2118 if (ch)
2106 bc = ch->brdchan; 2119 bc = ch->brdchan;
2107 else 2120 else
2108 return -EINVAL; 2121 return -EINVAL;
2109 2122
2110 spin_lock_irqsave(&epca_lock, flags); 2123 spin_lock_irqsave(&epca_lock, flags);
2111 globalwinon(ch); 2124 globalwinon(ch);
2112 mstat = readb(&bc->mstat); 2125 mstat = readb(&bc->mstat);
2113 memoff(ch); 2126 memoff(ch);
2114 spin_unlock_irqrestore(&epca_lock, flags); 2127 spin_unlock_irqrestore(&epca_lock, flags);
2115 2128
2116 if (mstat & ch->m_dtr) 2129 if (mstat & ch->m_dtr)
2117 mflag |= TIOCM_DTR; 2130 mflag |= TIOCM_DTR;
2118 if (mstat & ch->m_rts) 2131 if (mstat & ch->m_rts)
2119 mflag |= TIOCM_RTS; 2132 mflag |= TIOCM_RTS;
2120 if (mstat & ch->m_cts) 2133 if (mstat & ch->m_cts)
2121 mflag |= TIOCM_CTS; 2134 mflag |= TIOCM_CTS;
2122 if (mstat & ch->dsr) 2135 if (mstat & ch->dsr)
2123 mflag |= TIOCM_DSR; 2136 mflag |= TIOCM_DSR;
2124 if (mstat & ch->m_ri) 2137 if (mstat & ch->m_ri)
2125 mflag |= TIOCM_RI; 2138 mflag |= TIOCM_RI;
2126 if (mstat & ch->dcd) 2139 if (mstat & ch->dcd)
2127 mflag |= TIOCM_CD; 2140 mflag |= TIOCM_CD;
2128 return mflag; 2141 return mflag;
2129 } 2142 }
2130 2143
2131 static int pc_tiocmset(struct tty_struct *tty, struct file *file, 2144 static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2132 unsigned int set, unsigned int clear) 2145 unsigned int set, unsigned int clear)
2133 { 2146 {
2134 struct channel *ch = tty->driver_data; 2147 struct channel *ch = tty->driver_data;
2135 unsigned long flags; 2148 unsigned long flags;
2136 2149
2137 if (!ch) 2150 if (!ch)
2138 return -EINVAL; 2151 return -EINVAL;
2139 2152
2140 spin_lock_irqsave(&epca_lock, flags); 2153 spin_lock_irqsave(&epca_lock, flags);
2141 /* 2154 /*
2142 * I think this modemfake stuff is broken. It doesn't correctly reflect 2155 * I think this modemfake stuff is broken. It doesn't correctly reflect
2143 * the behaviour desired by the TIOCM* ioctls. Therefore this is 2156 * the behaviour desired by the TIOCM* ioctls. Therefore this is
2144 * probably broken. 2157 * probably broken.
2145 */ 2158 */
2146 if (set & TIOCM_RTS) { 2159 if (set & TIOCM_RTS) {
2147 ch->modemfake |= ch->m_rts; 2160 ch->modemfake |= ch->m_rts;
2148 ch->modem |= ch->m_rts; 2161 ch->modem |= ch->m_rts;
2149 } 2162 }
2150 if (set & TIOCM_DTR) { 2163 if (set & TIOCM_DTR) {
2151 ch->modemfake |= ch->m_dtr; 2164 ch->modemfake |= ch->m_dtr;
2152 ch->modem |= ch->m_dtr; 2165 ch->modem |= ch->m_dtr;
2153 } 2166 }
2154 if (clear & TIOCM_RTS) { 2167 if (clear & TIOCM_RTS) {
2155 ch->modemfake |= ch->m_rts; 2168 ch->modemfake |= ch->m_rts;
2156 ch->modem &= ~ch->m_rts; 2169 ch->modem &= ~ch->m_rts;
2157 } 2170 }
2158 if (clear & TIOCM_DTR) { 2171 if (clear & TIOCM_DTR) {
2159 ch->modemfake |= ch->m_dtr; 2172 ch->modemfake |= ch->m_dtr;
2160 ch->modem &= ~ch->m_dtr; 2173 ch->modem &= ~ch->m_dtr;
2161 } 2174 }
2162 globalwinon(ch); 2175 globalwinon(ch);
2163 /* 2176 /*
2164 * The below routine generally sets up parity, baud, flow control 2177 * The below routine generally sets up parity, baud, flow control
2165 * issues, etc.... It effect both control flags and input flags. 2178 * issues, etc.... It effect both control flags and input flags.
2166 */ 2179 */
2167 epcaparam(tty, ch); 2180 epcaparam(tty, ch);
2168 memoff(ch); 2181 memoff(ch);
2169 spin_unlock_irqrestore(&epca_lock, flags); 2182 spin_unlock_irqrestore(&epca_lock, flags);
2170 return 0; 2183 return 0;
2171 } 2184 }
2172 2185
2173 static int pc_ioctl(struct tty_struct *tty, struct file *file, 2186 static int pc_ioctl(struct tty_struct *tty, struct file *file,
2174 unsigned int cmd, unsigned long arg) 2187 unsigned int cmd, unsigned long arg)
2175 { 2188 {
2176 digiflow_t dflow; 2189 digiflow_t dflow;
2177 unsigned long flags; 2190 unsigned long flags;
2178 unsigned int mflag, mstat; 2191 unsigned int mflag, mstat;
2179 unsigned char startc, stopc; 2192 unsigned char startc, stopc;
2180 struct board_chan __iomem *bc; 2193 struct board_chan __iomem *bc;
2181 struct channel *ch = tty->driver_data; 2194 struct channel *ch = tty->driver_data;
2182 void __user *argp = (void __user *)arg; 2195 void __user *argp = (void __user *)arg;
2183 2196
2184 if (ch) 2197 if (ch)
2185 bc = ch->brdchan; 2198 bc = ch->brdchan;
2186 else 2199 else
2187 return -EINVAL; 2200 return -EINVAL;
2188 switch (cmd) { 2201 switch (cmd) {
2189 case TIOCMODG: 2202 case TIOCMODG:
2190 mflag = pc_tiocmget(tty, file); 2203 mflag = pc_tiocmget(tty, file);
2191 if (put_user(mflag, (unsigned long __user *)argp)) 2204 if (put_user(mflag, (unsigned long __user *)argp))
2192 return -EFAULT; 2205 return -EFAULT;
2193 break; 2206 break;
2194 case TIOCMODS: 2207 case TIOCMODS:
2195 if (get_user(mstat, (unsigned __user *)argp)) 2208 if (get_user(mstat, (unsigned __user *)argp))
2196 return -EFAULT; 2209 return -EFAULT;
2197 return pc_tiocmset(tty, file, mstat, ~mstat); 2210 return pc_tiocmset(tty, file, mstat, ~mstat);
2198 case TIOCSDTR: 2211 case TIOCSDTR:
2199 spin_lock_irqsave(&epca_lock, flags); 2212 spin_lock_irqsave(&epca_lock, flags);
2200 ch->omodem |= ch->m_dtr; 2213 ch->omodem |= ch->m_dtr;
2201 globalwinon(ch); 2214 globalwinon(ch);
2202 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1); 2215 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2203 memoff(ch); 2216 memoff(ch);
2204 spin_unlock_irqrestore(&epca_lock, flags); 2217 spin_unlock_irqrestore(&epca_lock, flags);
2205 break; 2218 break;
2206 2219
2207 case TIOCCDTR: 2220 case TIOCCDTR:
2208 spin_lock_irqsave(&epca_lock, flags); 2221 spin_lock_irqsave(&epca_lock, flags);
2209 ch->omodem &= ~ch->m_dtr; 2222 ch->omodem &= ~ch->m_dtr;
2210 globalwinon(ch); 2223 globalwinon(ch);
2211 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1); 2224 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2212 memoff(ch); 2225 memoff(ch);
2213 spin_unlock_irqrestore(&epca_lock, flags); 2226 spin_unlock_irqrestore(&epca_lock, flags);
2214 break; 2227 break;
2215 case DIGI_GETA: 2228 case DIGI_GETA:
2216 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t))) 2229 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2217 return -EFAULT; 2230 return -EFAULT;
2218 break; 2231 break;
2219 case DIGI_SETAW: 2232 case DIGI_SETAW:
2220 case DIGI_SETAF: 2233 case DIGI_SETAF:
2221 lock_kernel(); 2234 lock_kernel();
2222 if (cmd == DIGI_SETAW) { 2235 if (cmd == DIGI_SETAW) {
2223 /* Setup an event to indicate when the transmit 2236 /* Setup an event to indicate when the transmit
2224 buffer empties */ 2237 buffer empties */
2225 spin_lock_irqsave(&epca_lock, flags); 2238 spin_lock_irqsave(&epca_lock, flags);
2226 setup_empty_event(tty, ch); 2239 setup_empty_event(tty, ch);
2227 spin_unlock_irqrestore(&epca_lock, flags); 2240 spin_unlock_irqrestore(&epca_lock, flags);
2228 tty_wait_until_sent(tty, 0); 2241 tty_wait_until_sent(tty, 0);
2229 } else { 2242 } else {
2230 /* ldisc lock already held in ioctl */ 2243 /* ldisc lock already held in ioctl */
2231 if (tty->ldisc.ops->flush_buffer) 2244 if (tty->ldisc.ops->flush_buffer)
2232 tty->ldisc.ops->flush_buffer(tty); 2245 tty->ldisc.ops->flush_buffer(tty);
2233 } 2246 }
2234 unlock_kernel(); 2247 unlock_kernel();
2235 /* Fall Thru */ 2248 /* Fall Thru */
2236 case DIGI_SETA: 2249 case DIGI_SETA:
2237 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t))) 2250 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2238 return -EFAULT; 2251 return -EFAULT;
2239 2252
2240 if (ch->digiext.digi_flags & DIGI_ALTPIN) { 2253 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
2241 ch->dcd = ch->m_dsr; 2254 ch->dcd = ch->m_dsr;
2242 ch->dsr = ch->m_dcd; 2255 ch->dsr = ch->m_dcd;
2243 } else { 2256 } else {
2244 ch->dcd = ch->m_dcd; 2257 ch->dcd = ch->m_dcd;
2245 ch->dsr = ch->m_dsr; 2258 ch->dsr = ch->m_dsr;
2246 } 2259 }
2247 2260
2248 spin_lock_irqsave(&epca_lock, flags); 2261 spin_lock_irqsave(&epca_lock, flags);
2249 globalwinon(ch); 2262 globalwinon(ch);
2250 2263
2251 /* 2264 /*
2252 * The below routine generally sets up parity, baud, flow 2265 * The below routine generally sets up parity, baud, flow
2253 * control issues, etc.... It effect both control flags and 2266 * control issues, etc.... It effect both control flags and
2254 * input flags. 2267 * input flags.
2255 */ 2268 */
2256 epcaparam(tty, ch); 2269 epcaparam(tty, ch);
2257 memoff(ch); 2270 memoff(ch);
2258 spin_unlock_irqrestore(&epca_lock, flags); 2271 spin_unlock_irqrestore(&epca_lock, flags);
2259 break; 2272 break;
2260 2273
2261 case DIGI_GETFLOW: 2274 case DIGI_GETFLOW:
2262 case DIGI_GETAFLOW: 2275 case DIGI_GETAFLOW:
2263 spin_lock_irqsave(&epca_lock, flags); 2276 spin_lock_irqsave(&epca_lock, flags);
2264 globalwinon(ch); 2277 globalwinon(ch);
2265 if (cmd == DIGI_GETFLOW) { 2278 if (cmd == DIGI_GETFLOW) {
2266 dflow.startc = readb(&bc->startc); 2279 dflow.startc = readb(&bc->startc);
2267 dflow.stopc = readb(&bc->stopc); 2280 dflow.stopc = readb(&bc->stopc);
2268 } else { 2281 } else {
2269 dflow.startc = readb(&bc->startca); 2282 dflow.startc = readb(&bc->startca);
2270 dflow.stopc = readb(&bc->stopca); 2283 dflow.stopc = readb(&bc->stopca);
2271 } 2284 }
2272 memoff(ch); 2285 memoff(ch);
2273 spin_unlock_irqrestore(&epca_lock, flags); 2286 spin_unlock_irqrestore(&epca_lock, flags);
2274 2287
2275 if (copy_to_user(argp, &dflow, sizeof(dflow))) 2288 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2276 return -EFAULT; 2289 return -EFAULT;
2277 break; 2290 break;
2278 2291
2279 case DIGI_SETAFLOW: 2292 case DIGI_SETAFLOW:
2280 case DIGI_SETFLOW: 2293 case DIGI_SETFLOW:
2281 if (cmd == DIGI_SETFLOW) { 2294 if (cmd == DIGI_SETFLOW) {
2282 startc = ch->startc; 2295 startc = ch->startc;
2283 stopc = ch->stopc; 2296 stopc = ch->stopc;
2284 } else { 2297 } else {
2285 startc = ch->startca; 2298 startc = ch->startca;
2286 stopc = ch->stopca; 2299 stopc = ch->stopca;
2287 } 2300 }
2288 2301
2289 if (copy_from_user(&dflow, argp, sizeof(dflow))) 2302 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2290 return -EFAULT; 2303 return -EFAULT;
2291 2304
2292 if (dflow.startc != startc || dflow.stopc != stopc) { 2305 if (dflow.startc != startc || dflow.stopc != stopc) {
2293 /* Begin if setflow toggled */ 2306 /* Begin if setflow toggled */
2294 spin_lock_irqsave(&epca_lock, flags); 2307 spin_lock_irqsave(&epca_lock, flags);
2295 globalwinon(ch); 2308 globalwinon(ch);
2296 2309
2297 if (cmd == DIGI_SETFLOW) { 2310 if (cmd == DIGI_SETFLOW) {
2298 ch->fepstartc = ch->startc = dflow.startc; 2311 ch->fepstartc = ch->startc = dflow.startc;
2299 ch->fepstopc = ch->stopc = dflow.stopc; 2312 ch->fepstopc = ch->stopc = dflow.stopc;
2300 fepcmd(ch, SONOFFC, ch->fepstartc, 2313 fepcmd(ch, SONOFFC, ch->fepstartc,
2301 ch->fepstopc, 0, 1); 2314 ch->fepstopc, 0, 1);
2302 } else { 2315 } else {
2303 ch->fepstartca = ch->startca = dflow.startc; 2316 ch->fepstartca = ch->startca = dflow.startc;
2304 ch->fepstopca = ch->stopca = dflow.stopc; 2317 ch->fepstopca = ch->stopca = dflow.stopc;
2305 fepcmd(ch, SAUXONOFFC, ch->fepstartca, 2318 fepcmd(ch, SAUXONOFFC, ch->fepstartca,
2306 ch->fepstopca, 0, 1); 2319 ch->fepstopca, 0, 1);
2307 } 2320 }
2308 2321
2309 if (ch->statusflags & TXSTOPPED) 2322 if (ch->statusflags & TXSTOPPED)
2310 pc_start(tty); 2323 pc_start(tty);
2311 2324
2312 memoff(ch); 2325 memoff(ch);
2313 spin_unlock_irqrestore(&epca_lock, flags); 2326 spin_unlock_irqrestore(&epca_lock, flags);
2314 } /* End if setflow toggled */ 2327 } /* End if setflow toggled */
2315 break; 2328 break;
2316 default: 2329 default:
2317 return -ENOIOCTLCMD; 2330 return -ENOIOCTLCMD;
2318 } 2331 }
2319 return 0; 2332 return 0;
2320 } 2333 }
2321 2334
2322 static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios) 2335 static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2323 { 2336 {
2324 struct channel *ch; 2337 struct channel *ch;
2325 unsigned long flags; 2338 unsigned long flags;
2326 /* 2339 /*
2327 * verifyChannel returns the channel from the tty struct if it is 2340 * verifyChannel returns the channel from the tty struct if it is
2328 * valid. This serves as a sanity check. 2341 * valid. This serves as a sanity check.
2329 */ 2342 */
2330 ch = verifyChannel(tty); 2343 ch = verifyChannel(tty);
2331 2344
2332 if (ch != NULL) { /* Begin if channel valid */ 2345 if (ch != NULL) { /* Begin if channel valid */
2333 spin_lock_irqsave(&epca_lock, flags); 2346 spin_lock_irqsave(&epca_lock, flags);
2334 globalwinon(ch); 2347 globalwinon(ch);
2335 epcaparam(tty, ch); 2348 epcaparam(tty, ch);
2336 memoff(ch); 2349 memoff(ch);
2337 spin_unlock_irqrestore(&epca_lock, flags); 2350 spin_unlock_irqrestore(&epca_lock, flags);
2338 2351
2339 if ((old_termios->c_cflag & CRTSCTS) && 2352 if ((old_termios->c_cflag & CRTSCTS) &&
2340 ((tty->termios->c_cflag & CRTSCTS) == 0)) 2353 ((tty->termios->c_cflag & CRTSCTS) == 0))
2341 tty->hw_stopped = 0; 2354 tty->hw_stopped = 0;
2342 2355
2343 if (!(old_termios->c_cflag & CLOCAL) && 2356 if (!(old_termios->c_cflag & CLOCAL) &&
2344 (tty->termios->c_cflag & CLOCAL)) 2357 (tty->termios->c_cflag & CLOCAL))
2345 wake_up_interruptible(&ch->port.open_wait); 2358 wake_up_interruptible(&ch->port.open_wait);
2346 2359
2347 } /* End if channel valid */ 2360 } /* End if channel valid */
2348 } 2361 }
2349 2362
2350 static void do_softint(struct work_struct *work) 2363 static void do_softint(struct work_struct *work)
2351 { 2364 {
2352 struct channel *ch = container_of(work, struct channel, tqueue); 2365 struct channel *ch = container_of(work, struct channel, tqueue);
2353 /* Called in response to a modem change event */ 2366 /* Called in response to a modem change event */
2354 if (ch && ch->magic == EPCA_MAGIC) { 2367 if (ch && ch->magic == EPCA_MAGIC) {
2355 struct tty_struct *tty = ch->port.tty; 2368 struct tty_struct *tty = ch->port.tty;
2356 2369
2357 if (tty && tty->driver_data) { 2370 if (tty && tty->driver_data) {
2358 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { 2371 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
2359 tty_hangup(tty); 2372 tty_hangup(tty);
2360 wake_up_interruptible(&ch->port.open_wait); 2373 wake_up_interruptible(&ch->port.open_wait);
2361 ch->port.flags &= ~ASYNC_NORMAL_ACTIVE; 2374 ch->port.flags &= ~ASYNC_NORMAL_ACTIVE;
2362 } 2375 }
2363 } 2376 }
2364 } 2377 }
2365 } 2378 }
2366 2379
2367 /* 2380 /*
2368 * pc_stop and pc_start provide software flow control to the routine and the 2381 * pc_stop and pc_start provide software flow control to the routine and the
2369 * pc_ioctl routine. 2382 * pc_ioctl routine.
2370 */ 2383 */
2371 static void pc_stop(struct tty_struct *tty) 2384 static void pc_stop(struct tty_struct *tty)
2372 { 2385 {
2373 struct channel *ch; 2386 struct channel *ch;
2374 unsigned long flags; 2387 unsigned long flags;
2375 /* 2388 /*
2376 * verifyChannel returns the channel from the tty struct if it is 2389 * verifyChannel returns the channel from the tty struct if it is
2377 * valid. This serves as a sanity check. 2390 * valid. This serves as a sanity check.
2378 */ 2391 */
2379 ch = verifyChannel(tty); 2392 ch = verifyChannel(tty);
2380 if (ch != NULL) { 2393 if (ch != NULL) {
2381 spin_lock_irqsave(&epca_lock, flags); 2394 spin_lock_irqsave(&epca_lock, flags);
2382 if ((ch->statusflags & TXSTOPPED) == 0) { 2395 if ((ch->statusflags & TXSTOPPED) == 0) {
2383 /* Begin if transmit stop requested */ 2396 /* Begin if transmit stop requested */
2384 globalwinon(ch); 2397 globalwinon(ch);
2385 /* STOP transmitting now !! */ 2398 /* STOP transmitting now !! */
2386 fepcmd(ch, PAUSETX, 0, 0, 0, 0); 2399 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
2387 ch->statusflags |= TXSTOPPED; 2400 ch->statusflags |= TXSTOPPED;
2388 memoff(ch); 2401 memoff(ch);
2389 } /* End if transmit stop requested */ 2402 } /* End if transmit stop requested */
2390 spin_unlock_irqrestore(&epca_lock, flags); 2403 spin_unlock_irqrestore(&epca_lock, flags);
2391 } 2404 }
2392 } 2405 }
2393 2406
2394 static void pc_start(struct tty_struct *tty) 2407 static void pc_start(struct tty_struct *tty)
2395 { 2408 {
2396 struct channel *ch; 2409 struct channel *ch;
2397 /* 2410 /*
2398 * verifyChannel returns the channel from the tty struct if it is 2411 * verifyChannel returns the channel from the tty struct if it is
2399 * valid. This serves as a sanity check. 2412 * valid. This serves as a sanity check.
2400 */ 2413 */
2401 ch = verifyChannel(tty); 2414 ch = verifyChannel(tty);
2402 if (ch != NULL) { 2415 if (ch != NULL) {
2403 unsigned long flags; 2416 unsigned long flags;
2404 spin_lock_irqsave(&epca_lock, flags); 2417 spin_lock_irqsave(&epca_lock, flags);
2405 /* Just in case output was resumed because of a change 2418 /* Just in case output was resumed because of a change
2406 in Digi-flow */ 2419 in Digi-flow */
2407 if (ch->statusflags & TXSTOPPED) { 2420 if (ch->statusflags & TXSTOPPED) {
2408 /* Begin transmit resume requested */ 2421 /* Begin transmit resume requested */
2409 struct board_chan __iomem *bc; 2422 struct board_chan __iomem *bc;
2410 globalwinon(ch); 2423 globalwinon(ch);
2411 bc = ch->brdchan; 2424 bc = ch->brdchan;
2412 if (ch->statusflags & LOWWAIT) 2425 if (ch->statusflags & LOWWAIT)
2413 writeb(1, &bc->ilow); 2426 writeb(1, &bc->ilow);
2414 /* Okay, you can start transmitting again... */ 2427 /* Okay, you can start transmitting again... */
2415 fepcmd(ch, RESUMETX, 0, 0, 0, 0); 2428 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
2416 ch->statusflags &= ~TXSTOPPED; 2429 ch->statusflags &= ~TXSTOPPED;
2417 memoff(ch); 2430 memoff(ch);
2418 } /* End transmit resume requested */ 2431 } /* End transmit resume requested */
2419 spin_unlock_irqrestore(&epca_lock, flags); 2432 spin_unlock_irqrestore(&epca_lock, flags);
2420 } 2433 }
2421 } 2434 }
2422 2435
2423 /* 2436 /*
2424 * The below routines pc_throttle and pc_unthrottle are used to slow (And 2437 * The below routines pc_throttle and pc_unthrottle are used to slow (And
2425 * resume) the receipt of data into the kernels receive buffers. The exact 2438 * resume) the receipt of data into the kernels receive buffers. The exact
2426 * occurrence of this depends on the size of the kernels receive buffer and 2439 * occurrence of this depends on the size of the kernels receive buffer and
2427 * what the 'watermarks' are set to for that buffer. See the n_ttys.c file for 2440 * what the 'watermarks' are set to for that buffer. See the n_ttys.c file for
2428 * more details. 2441 * more details.
2429 */ 2442 */
2430 static void pc_throttle(struct tty_struct *tty) 2443 static void pc_throttle(struct tty_struct *tty)
2431 { 2444 {
2432 struct channel *ch; 2445 struct channel *ch;
2433 unsigned long flags; 2446 unsigned long flags;
2434 /* 2447 /*
2435 * verifyChannel returns the channel from the tty struct if it is 2448 * verifyChannel returns the channel from the tty struct if it is
2436 * valid. This serves as a sanity check. 2449 * valid. This serves as a sanity check.
2437 */ 2450 */
2438 ch = verifyChannel(tty); 2451 ch = verifyChannel(tty);
2439 if (ch != NULL) { 2452 if (ch != NULL) {
2440 spin_lock_irqsave(&epca_lock, flags); 2453 spin_lock_irqsave(&epca_lock, flags);
2441 if ((ch->statusflags & RXSTOPPED) == 0) { 2454 if ((ch->statusflags & RXSTOPPED) == 0) {
2442 globalwinon(ch); 2455 globalwinon(ch);
2443 fepcmd(ch, PAUSERX, 0, 0, 0, 0); 2456 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
2444 ch->statusflags |= RXSTOPPED; 2457 ch->statusflags |= RXSTOPPED;
2445 memoff(ch); 2458 memoff(ch);
2446 } 2459 }
2447 spin_unlock_irqrestore(&epca_lock, flags); 2460 spin_unlock_irqrestore(&epca_lock, flags);
2448 } 2461 }
2449 } 2462 }
2450 2463
2451 static void pc_unthrottle(struct tty_struct *tty) 2464 static void pc_unthrottle(struct tty_struct *tty)
2452 { 2465 {
2453 struct channel *ch; 2466 struct channel *ch;
2454 unsigned long flags; 2467 unsigned long flags;
2455 /* 2468 /*
2456 * verifyChannel returns the channel from the tty struct if it is 2469 * verifyChannel returns the channel from the tty struct if it is
2457 * valid. This serves as a sanity check. 2470 * valid. This serves as a sanity check.
2458 */ 2471 */
2459 ch = verifyChannel(tty); 2472 ch = verifyChannel(tty);
2460 if (ch != NULL) { 2473 if (ch != NULL) {
2461 /* Just in case output was resumed because of a change 2474 /* Just in case output was resumed because of a change
2462 in Digi-flow */ 2475 in Digi-flow */
2463 spin_lock_irqsave(&epca_lock, flags); 2476 spin_lock_irqsave(&epca_lock, flags);
2464 if (ch->statusflags & RXSTOPPED) { 2477 if (ch->statusflags & RXSTOPPED) {
2465 globalwinon(ch); 2478 globalwinon(ch);
2466 fepcmd(ch, RESUMERX, 0, 0, 0, 0); 2479 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
2467 ch->statusflags &= ~RXSTOPPED; 2480 ch->statusflags &= ~RXSTOPPED;
2468 memoff(ch); 2481 memoff(ch);
2469 } 2482 }
2470 spin_unlock_irqrestore(&epca_lock, flags); 2483 spin_unlock_irqrestore(&epca_lock, flags);
2471 } 2484 }
2472 } 2485 }
2473 2486
2474 static int pc_send_break(struct tty_struct *tty, int msec) 2487 static int pc_send_break(struct tty_struct *tty, int msec)
2475 { 2488 {
2476 struct channel *ch = tty->driver_data; 2489 struct channel *ch = tty->driver_data;
2477 unsigned long flags; 2490 unsigned long flags;
2478 2491
2479 if (msec == -1) 2492 if (msec == -1)
2480 msec = 0xFFFF; 2493 msec = 0xFFFF;
2481 else if (msec > 0xFFFE) 2494 else if (msec > 0xFFFE)
2482 msec = 0xFFFE; 2495 msec = 0xFFFE;
2483 else if (msec < 1) 2496 else if (msec < 1)
2484 msec = 1; 2497 msec = 1;
2485 2498
2486 spin_lock_irqsave(&epca_lock, flags); 2499 spin_lock_irqsave(&epca_lock, flags);
2487 globalwinon(ch); 2500 globalwinon(ch);
2488 /* 2501 /*
2489 * Maybe I should send an infinite break here, schedule() for msec 2502 * Maybe I should send an infinite break here, schedule() for msec
2490 * amount of time, and then stop the break. This way, the user can't 2503 * amount of time, and then stop the break. This way, the user can't
2491 * screw up the FEP by causing digi_send_break() to be called (i.e. via 2504 * screw up the FEP by causing digi_send_break() to be called (i.e. via
2492 * an ioctl()) more than once in msec amount of time. 2505 * an ioctl()) more than once in msec amount of time.
2493 * Try this for now... 2506 * Try this for now...
2494 */ 2507 */
2495 fepcmd(ch, SENDBREAK, msec, 0, 10, 0); 2508 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2496 memoff(ch); 2509 memoff(ch);
2497 spin_unlock_irqrestore(&epca_lock, flags); 2510 spin_unlock_irqrestore(&epca_lock, flags);
2498 return 0; 2511 return 0;
2499 } 2512 }
2500 2513
2501 /* Caller MUST hold the lock */ 2514 /* Caller MUST hold the lock */
2502 static void setup_empty_event(struct tty_struct *tty, struct channel *ch) 2515 static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2503 { 2516 {
2504 struct board_chan __iomem *bc = ch->brdchan; 2517 struct board_chan __iomem *bc = ch->brdchan;
2505 2518
2506 globalwinon(ch); 2519 globalwinon(ch);
2507 ch->statusflags |= EMPTYWAIT; 2520 ch->statusflags |= EMPTYWAIT;
2508 /* 2521 /*
2509 * When set the iempty flag request a event to be generated when the 2522 * When set the iempty flag request a event to be generated when the
2510 * transmit buffer is empty (If there is no BREAK in progress). 2523 * transmit buffer is empty (If there is no BREAK in progress).
2511 */ 2524 */
2512 writeb(1, &bc->iempty); 2525 writeb(1, &bc->iempty);
2513 memoff(ch); 2526 memoff(ch);
2514 } 2527 }
2515 2528
2516 #ifndef MODULE 2529 #ifndef MODULE
2517 static void __init epca_setup(char *str, int *ints) 2530 static void __init epca_setup(char *str, int *ints)
2518 { 2531 {
2519 struct board_info board; 2532 struct board_info board;
2520 int index, loop, last; 2533 int index, loop, last;
2521 char *temp, *t2; 2534 char *temp, *t2;
2522 unsigned len; 2535 unsigned len;
2523 2536
2524 /* 2537 /*
2525 * If this routine looks a little strange it is because it is only 2538 * If this routine looks a little strange it is because it is only
2526 * called if a LILO append command is given to boot the kernel with 2539 * called if a LILO append command is given to boot the kernel with
2527 * parameters. In this way, we can provide the user a method of 2540 * parameters. In this way, we can provide the user a method of
2528 * changing his board configuration without rebuilding the kernel. 2541 * changing his board configuration without rebuilding the kernel.
2529 */ 2542 */
2530 if (!liloconfig) 2543 if (!liloconfig)
2531 liloconfig = 1; 2544 liloconfig = 1;
2532 2545
2533 memset(&board, 0, sizeof(board)); 2546 memset(&board, 0, sizeof(board));
2534 2547
2535 /* Assume the data is int first, later we can change it */ 2548 /* Assume the data is int first, later we can change it */
2536 /* I think that array position 0 of ints holds the number of args */ 2549 /* I think that array position 0 of ints holds the number of args */
2537 for (last = 0, index = 1; index <= ints[0]; index++) 2550 for (last = 0, index = 1; index <= ints[0]; index++)
2538 switch (index) { /* Begin parse switch */ 2551 switch (index) { /* Begin parse switch */
2539 case 1: 2552 case 1:
2540 board.status = ints[index]; 2553 board.status = ints[index];
2541 /* 2554 /*
2542 * We check for 2 (As opposed to 1; because 2 is a flag 2555 * We check for 2 (As opposed to 1; because 2 is a flag
2543 * instructing the driver to ignore epcaconfig.) For 2556 * instructing the driver to ignore epcaconfig.) For
2544 * this reason we check for 2. 2557 * this reason we check for 2.
2545 */ 2558 */
2546 if (board.status == 2) { 2559 if (board.status == 2) {
2547 /* Begin ignore epcaconfig as well as lilo cmd line */ 2560 /* Begin ignore epcaconfig as well as lilo cmd line */
2548 nbdevs = 0; 2561 nbdevs = 0;
2549 num_cards = 0; 2562 num_cards = 0;
2550 return; 2563 return;
2551 } /* End ignore epcaconfig as well as lilo cmd line */ 2564 } /* End ignore epcaconfig as well as lilo cmd line */
2552 2565
2553 if (board.status > 2) { 2566 if (board.status > 2) {
2554 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n", 2567 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n",
2555 board.status); 2568 board.status);
2556 invalid_lilo_config = 1; 2569 invalid_lilo_config = 1;
2557 setup_error_code |= INVALID_BOARD_STATUS; 2570 setup_error_code |= INVALID_BOARD_STATUS;
2558 return; 2571 return;
2559 } 2572 }
2560 last = index; 2573 last = index;
2561 break; 2574 break;
2562 case 2: 2575 case 2:
2563 board.type = ints[index]; 2576 board.type = ints[index];
2564 if (board.type >= PCIXEM) { 2577 if (board.type >= PCIXEM) {
2565 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type); 2578 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
2566 invalid_lilo_config = 1; 2579 invalid_lilo_config = 1;
2567 setup_error_code |= INVALID_BOARD_TYPE; 2580 setup_error_code |= INVALID_BOARD_TYPE;
2568 return; 2581 return;
2569 } 2582 }
2570 last = index; 2583 last = index;
2571 break; 2584 break;
2572 case 3: 2585 case 3:
2573 board.altpin = ints[index]; 2586 board.altpin = ints[index];
2574 if (board.altpin > 1) { 2587 if (board.altpin > 1) {
2575 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin); 2588 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
2576 invalid_lilo_config = 1; 2589 invalid_lilo_config = 1;
2577 setup_error_code |= INVALID_ALTPIN; 2590 setup_error_code |= INVALID_ALTPIN;
2578 return; 2591 return;
2579 } 2592 }
2580 last = index; 2593 last = index;
2581 break; 2594 break;
2582 2595
2583 case 4: 2596 case 4:
2584 board.numports = ints[index]; 2597 board.numports = ints[index];
2585 if (board.numports < 2 || board.numports > 256) { 2598 if (board.numports < 2 || board.numports > 256) {
2586 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports); 2599 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
2587 invalid_lilo_config = 1; 2600 invalid_lilo_config = 1;
2588 setup_error_code |= INVALID_NUM_PORTS; 2601 setup_error_code |= INVALID_NUM_PORTS;
2589 return; 2602 return;
2590 } 2603 }
2591 nbdevs += board.numports; 2604 nbdevs += board.numports;
2592 last = index; 2605 last = index;
2593 break; 2606 break;
2594 2607
2595 case 5: 2608 case 5:
2596 board.port = ints[index]; 2609 board.port = ints[index];
2597 if (ints[index] <= 0) { 2610 if (ints[index] <= 0) {
2598 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port); 2611 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
2599 invalid_lilo_config = 1; 2612 invalid_lilo_config = 1;
2600 setup_error_code |= INVALID_PORT_BASE; 2613 setup_error_code |= INVALID_PORT_BASE;
2601 return; 2614 return;
2602 } 2615 }
2603 last = index; 2616 last = index;
2604 break; 2617 break;
2605 2618
2606 case 6: 2619 case 6:
2607 board.membase = ints[index]; 2620 board.membase = ints[index];
2608 if (ints[index] <= 0) { 2621 if (ints[index] <= 0) {
2609 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n", 2622 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",
2610 (unsigned int)board.membase); 2623 (unsigned int)board.membase);
2611 invalid_lilo_config = 1; 2624 invalid_lilo_config = 1;
2612 setup_error_code |= INVALID_MEM_BASE; 2625 setup_error_code |= INVALID_MEM_BASE;
2613 return; 2626 return;
2614 } 2627 }
2615 last = index; 2628 last = index;
2616 break; 2629 break;
2617 2630
2618 default: 2631 default:
2619 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n"); 2632 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2620 return; 2633 return;
2621 2634
2622 } /* End parse switch */ 2635 } /* End parse switch */
2623 2636
2624 while (str && *str) { /* Begin while there is a string arg */ 2637 while (str && *str) { /* Begin while there is a string arg */
2625 /* find the next comma or terminator */ 2638 /* find the next comma or terminator */
2626 temp = str; 2639 temp = str;
2627 /* While string is not null, and a comma hasn't been found */ 2640 /* While string is not null, and a comma hasn't been found */
2628 while (*temp && (*temp != ',')) 2641 while (*temp && (*temp != ','))
2629 temp++; 2642 temp++;
2630 if (!*temp) 2643 if (!*temp)
2631 temp = NULL; 2644 temp = NULL;
2632 else 2645 else
2633 *temp++ = 0; 2646 *temp++ = 0;
2634 /* Set index to the number of args + 1 */ 2647 /* Set index to the number of args + 1 */
2635 index = last + 1; 2648 index = last + 1;
2636 2649
2637 switch (index) { 2650 switch (index) {
2638 case 1: 2651 case 1:
2639 len = strlen(str); 2652 len = strlen(str);
2640 if (strncmp("Disable", str, len) == 0) 2653 if (strncmp("Disable", str, len) == 0)
2641 board.status = 0; 2654 board.status = 0;
2642 else if (strncmp("Enable", str, len) == 0) 2655 else if (strncmp("Enable", str, len) == 0)
2643 board.status = 1; 2656 board.status = 1;
2644 else { 2657 else {
2645 printk(KERN_ERR "epca_setup: Invalid status %s\n", str); 2658 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
2646 invalid_lilo_config = 1; 2659 invalid_lilo_config = 1;
2647 setup_error_code |= INVALID_BOARD_STATUS; 2660 setup_error_code |= INVALID_BOARD_STATUS;
2648 return; 2661 return;
2649 } 2662 }
2650 last = index; 2663 last = index;
2651 break; 2664 break;
2652 2665
2653 case 2: 2666 case 2:
2654 for (loop = 0; loop < EPCA_NUM_TYPES; loop++) 2667 for (loop = 0; loop < EPCA_NUM_TYPES; loop++)
2655 if (strcmp(board_desc[loop], str) == 0) 2668 if (strcmp(board_desc[loop], str) == 0)
2656 break; 2669 break;
2657 /* 2670 /*
2658 * If the index incremented above refers to a 2671 * If the index incremented above refers to a
2659 * legitamate board type set it here. 2672 * legitamate board type set it here.
2660 */ 2673 */
2661 if (index < EPCA_NUM_TYPES) 2674 if (index < EPCA_NUM_TYPES)
2662 board.type = loop; 2675 board.type = loop;
2663 else { 2676 else {
2664 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str); 2677 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
2665 invalid_lilo_config = 1; 2678 invalid_lilo_config = 1;
2666 setup_error_code |= INVALID_BOARD_TYPE; 2679 setup_error_code |= INVALID_BOARD_TYPE;
2667 return; 2680 return;
2668 } 2681 }
2669 last = index; 2682 last = index;
2670 break; 2683 break;
2671 2684
2672 case 3: 2685 case 3:
2673 len = strlen(str); 2686 len = strlen(str);
2674 if (strncmp("Disable", str, len) == 0) 2687 if (strncmp("Disable", str, len) == 0)
2675 board.altpin = 0; 2688 board.altpin = 0;
2676 else if (strncmp("Enable", str, len) == 0) 2689 else if (strncmp("Enable", str, len) == 0)
2677 board.altpin = 1; 2690 board.altpin = 1;
2678 else { 2691 else {
2679 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str); 2692 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
2680 invalid_lilo_config = 1; 2693 invalid_lilo_config = 1;
2681 setup_error_code |= INVALID_ALTPIN; 2694 setup_error_code |= INVALID_ALTPIN;
2682 return; 2695 return;
2683 } 2696 }
2684 last = index; 2697 last = index;
2685 break; 2698 break;
2686 2699
2687 case 4: 2700 case 4:
2688 t2 = str; 2701 t2 = str;
2689 while (isdigit(*t2)) 2702 while (isdigit(*t2))
2690 t2++; 2703 t2++;
2691 2704
2692 if (*t2) { 2705 if (*t2) {
2693 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str); 2706 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
2694 invalid_lilo_config = 1; 2707 invalid_lilo_config = 1;
2695 setup_error_code |= INVALID_NUM_PORTS; 2708 setup_error_code |= INVALID_NUM_PORTS;
2696 return; 2709 return;
2697 } 2710 }
2698 2711
2699 /* 2712 /*
2700 * There is not a man page for simple_strtoul but the 2713 * There is not a man page for simple_strtoul but the
2701 * code can be found in vsprintf.c. The first argument 2714 * code can be found in vsprintf.c. The first argument
2702 * is the string to translate (To an unsigned long 2715 * is the string to translate (To an unsigned long
2703 * obviously), the second argument can be the address 2716 * obviously), the second argument can be the address
2704 * of any character variable or a NULL. If a variable 2717 * of any character variable or a NULL. If a variable
2705 * is given, the end pointer of the string will be 2718 * is given, the end pointer of the string will be
2706 * stored in that variable; if a NULL is given the end 2719 * stored in that variable; if a NULL is given the end
2707 * pointer will not be returned. The last argument is 2720 * pointer will not be returned. The last argument is
2708 * the base to use. If a 0 is indicated, the routine 2721 * the base to use. If a 0 is indicated, the routine
2709 * will attempt to determine the proper base by looking 2722 * will attempt to determine the proper base by looking
2710 * at the values prefix (A '0' for octal, a 'x' for 2723 * at the values prefix (A '0' for octal, a 'x' for
2711 * hex, etc ... If a value is given it will use that 2724 * hex, etc ... If a value is given it will use that
2712 * value as the base. 2725 * value as the base.
2713 */ 2726 */
2714 board.numports = simple_strtoul(str, NULL, 0); 2727 board.numports = simple_strtoul(str, NULL, 0);
2715 nbdevs += board.numports; 2728 nbdevs += board.numports;
2716 last = index; 2729 last = index;
2717 break; 2730 break;
2718 2731
2719 case 5: 2732 case 5:
2720 t2 = str; 2733 t2 = str;
2721 while (isxdigit(*t2)) 2734 while (isxdigit(*t2))
2722 t2++; 2735 t2++;
2723 2736
2724 if (*t2) { 2737 if (*t2) {
2725 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str); 2738 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
2726 invalid_lilo_config = 1; 2739 invalid_lilo_config = 1;
2727 setup_error_code |= INVALID_PORT_BASE; 2740 setup_error_code |= INVALID_PORT_BASE;
2728 return; 2741 return;
2729 } 2742 }
2730 2743
2731 board.port = simple_strtoul(str, NULL, 16); 2744 board.port = simple_strtoul(str, NULL, 16);
2732 last = index; 2745 last = index;
2733 break; 2746 break;
2734 2747
2735 case 6: 2748 case 6:
2736 t2 = str; 2749 t2 = str;
2737 while (isxdigit(*t2)) 2750 while (isxdigit(*t2))
2738 t2++; 2751 t2++;
2739 2752
2740 if (*t2) { 2753 if (*t2) {
2741 printk(KERN_ERR "epca_setup: Invalid memory base %s\n", str); 2754 printk(KERN_ERR "epca_setup: Invalid memory base %s\n", str);
2742 invalid_lilo_config = 1; 2755 invalid_lilo_config = 1;
2743 setup_error_code |= INVALID_MEM_BASE; 2756 setup_error_code |= INVALID_MEM_BASE;
2744 return; 2757 return;
2745 } 2758 }
2746 board.membase = simple_strtoul(str, NULL, 16); 2759 board.membase = simple_strtoul(str, NULL, 16);
2747 last = index; 2760 last = index;
2748 break; 2761 break;
2749 default: 2762 default:
2750 printk(KERN_ERR "epca: Too many string parms\n"); 2763 printk(KERN_ERR "epca: Too many string parms\n");
2751 return; 2764 return;
2752 } 2765 }
2753 str = temp; 2766 str = temp;
2754 } /* End while there is a string arg */ 2767 } /* End while there is a string arg */
2755 2768
2756 if (last < 6) { 2769 if (last < 6) {
2757 printk(KERN_ERR "epca: Insufficient parms specified\n"); 2770 printk(KERN_ERR "epca: Insufficient parms specified\n");
2758 return; 2771 return;
2759 } 2772 }
2760 2773
2761 /* I should REALLY validate the stuff here */ 2774 /* I should REALLY validate the stuff here */
2762 /* Copies our local copy of board into boards */ 2775 /* Copies our local copy of board into boards */
2763 memcpy((void *)&boards[num_cards], (void *)&board, sizeof(board)); 2776 memcpy((void *)&boards[num_cards], (void *)&board, sizeof(board));
2764 /* Does this get called once per lilo arg are what ? */ 2777 /* Does this get called once per lilo arg are what ? */
2765 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n", 2778 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2766 num_cards, board_desc[board.type], 2779 num_cards, board_desc[board.type],
2767 board.numports, (int)board.port, (unsigned int) board.membase); 2780 board.numports, (int)board.port, (unsigned int) board.membase);
2768 num_cards++; 2781 num_cards++;
2769 } 2782 }
2770 2783
2771 static int __init epca_real_setup(char *str) 2784 static int __init epca_real_setup(char *str)
2772 { 2785 {
2773 int ints[11]; 2786 int ints[11];
2774 2787
2775 epca_setup(get_options(str, 11, ints), ints); 2788 epca_setup(get_options(str, 11, ints), ints);
2776 return 1; 2789 return 1;
2777 } 2790 }
2778 2791
2779 __setup("digiepca", epca_real_setup); 2792 __setup("digiepca", epca_real_setup);
2780 #endif 2793 #endif
2781 2794
2782 enum epic_board_types { 2795 enum epic_board_types {
2783 brd_xr = 0, 2796 brd_xr = 0,
2784 brd_xem, 2797 brd_xem,
2785 brd_cx, 2798 brd_cx,
2786 brd_xrj, 2799 brd_xrj,
2787 }; 2800 };
2788 2801
2789 /* indexed directly by epic_board_types enum */ 2802 /* indexed directly by epic_board_types enum */
2790 static struct { 2803 static struct {
2791 unsigned char board_type; 2804 unsigned char board_type;
2792 unsigned bar_idx; /* PCI base address region */ 2805 unsigned bar_idx; /* PCI base address region */
2793 } epca_info_tbl[] = { 2806 } epca_info_tbl[] = {
2794 { PCIXR, 0, }, 2807 { PCIXR, 0, },
2795 { PCIXEM, 0, }, 2808 { PCIXEM, 0, },
2796 { PCICX, 0, }, 2809 { PCICX, 0, },
2797 { PCIXRJ, 2, }, 2810 { PCIXRJ, 2, },
2798 }; 2811 };
2799 2812
2800 static int __devinit epca_init_one(struct pci_dev *pdev, 2813 static int __devinit epca_init_one(struct pci_dev *pdev,
2801 const struct pci_device_id *ent) 2814 const struct pci_device_id *ent)
2802 { 2815 {
2803 static int board_num = -1; 2816 static int board_num = -1;
2804 int board_idx, info_idx = ent->driver_data; 2817 int board_idx, info_idx = ent->driver_data;
2805 unsigned long addr; 2818 unsigned long addr;
2806 2819
2807 if (pci_enable_device(pdev)) 2820 if (pci_enable_device(pdev))
2808 return -EIO; 2821 return -EIO;
2809 2822
2810 board_num++; 2823 board_num++;
2811 board_idx = board_num + num_cards; 2824 board_idx = board_num + num_cards;
2812 if (board_idx >= MAXBOARDS) 2825 if (board_idx >= MAXBOARDS)
2813 goto err_out; 2826 goto err_out;
2814 2827
2815 addr = pci_resource_start(pdev, epca_info_tbl[info_idx].bar_idx); 2828 addr = pci_resource_start(pdev, epca_info_tbl[info_idx].bar_idx);
2816 if (!addr) { 2829 if (!addr) {
2817 printk(KERN_ERR PFX "PCI region #%d not available (size 0)\n", 2830 printk(KERN_ERR PFX "PCI region #%d not available (size 0)\n",
2818 epca_info_tbl[info_idx].bar_idx); 2831 epca_info_tbl[info_idx].bar_idx);
2819 goto err_out; 2832 goto err_out;
2820 } 2833 }
2821 2834
2822 boards[board_idx].status = ENABLED; 2835 boards[board_idx].status = ENABLED;
2823 boards[board_idx].type = epca_info_tbl[info_idx].board_type; 2836 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
2824 boards[board_idx].numports = 0x0; 2837 boards[board_idx].numports = 0x0;
2825 boards[board_idx].port = addr + PCI_IO_OFFSET; 2838 boards[board_idx].port = addr + PCI_IO_OFFSET;
2826 boards[board_idx].membase = addr; 2839 boards[board_idx].membase = addr;
2827 2840
2828 if (!request_mem_region(addr + PCI_IO_OFFSET, 0x200000, "epca")) { 2841 if (!request_mem_region(addr + PCI_IO_OFFSET, 0x200000, "epca")) {
2829 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n", 2842 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2830 0x200000, addr + PCI_IO_OFFSET); 2843 0x200000, addr + PCI_IO_OFFSET);
2831 goto err_out; 2844 goto err_out;
2832 } 2845 }
2833 2846
2834 boards[board_idx].re_map_port = ioremap_nocache(addr + PCI_IO_OFFSET, 2847 boards[board_idx].re_map_port = ioremap_nocache(addr + PCI_IO_OFFSET,
2835 0x200000); 2848 0x200000);
2836 if (!boards[board_idx].re_map_port) { 2849 if (!boards[board_idx].re_map_port) {
2837 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n", 2850 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2838 0x200000, addr + PCI_IO_OFFSET); 2851 0x200000, addr + PCI_IO_OFFSET);
2839 goto err_out_free_pciio; 2852 goto err_out_free_pciio;
2840 } 2853 }
2841 2854
2842 if (!request_mem_region(addr, 0x200000, "epca")) { 2855 if (!request_mem_region(addr, 0x200000, "epca")) {
2843 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n", 2856 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2844 0x200000, addr); 2857 0x200000, addr);
2845 goto err_out_free_iounmap; 2858 goto err_out_free_iounmap;
2846 } 2859 }
2847 2860
2848 boards[board_idx].re_map_membase = ioremap_nocache(addr, 0x200000); 2861 boards[board_idx].re_map_membase = ioremap_nocache(addr, 0x200000);
2849 if (!boards[board_idx].re_map_membase) { 2862 if (!boards[board_idx].re_map_membase) {
2850 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n", 2863 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2851 0x200000, addr + PCI_IO_OFFSET); 2864 0x200000, addr + PCI_IO_OFFSET);
2852 goto err_out_free_memregion; 2865 goto err_out_free_memregion;
2853 } 2866 }
2854 2867
2855 /* 2868 /*
2856 * I don't know what the below does, but the hardware guys say its 2869 * I don't know what the below does, but the hardware guys say its
2857 * required on everything except PLX (In this case XRJ). 2870 * required on everything except PLX (In this case XRJ).
2858 */ 2871 */
2859 if (info_idx != brd_xrj) { 2872 if (info_idx != brd_xrj) {
2860 pci_write_config_byte(pdev, 0x40, 0); 2873 pci_write_config_byte(pdev, 0x40, 0);
2861 pci_write_config_byte(pdev, 0x46, 0); 2874 pci_write_config_byte(pdev, 0x46, 0);
2862 } 2875 }
2863 2876
2864 return 0; 2877 return 0;
2865 2878
2866 err_out_free_memregion: 2879 err_out_free_memregion:
2867 release_mem_region(addr, 0x200000); 2880 release_mem_region(addr, 0x200000);
2868 err_out_free_iounmap: 2881 err_out_free_iounmap: