Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/asy.c
+++ new/usr/src/uts/common/io/asy.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
23 23 /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
24 24 /* All Rights Reserved */
25 25
26 26 /*
27 27 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
28 28 * Copyright 2012 Milan Jurik. All rights reserved.
29 29 */
30 30
31 31
32 32 /*
33 33 * Serial I/O driver for 8250/16450/16550A/16650/16750 chips.
34 34 */
35 35
36 36 #include <sys/param.h>
37 37 #include <sys/types.h>
38 38 #include <sys/signal.h>
39 39 #include <sys/stream.h>
40 40 #include <sys/termio.h>
41 41 #include <sys/errno.h>
42 42 #include <sys/file.h>
43 43 #include <sys/cmn_err.h>
44 44 #include <sys/stropts.h>
45 45 #include <sys/strsubr.h>
46 46 #include <sys/strtty.h>
47 47 #include <sys/debug.h>
48 48 #include <sys/kbio.h>
49 49 #include <sys/cred.h>
50 50 #include <sys/stat.h>
51 51 #include <sys/consdev.h>
52 52 #include <sys/mkdev.h>
53 53 #include <sys/kmem.h>
54 54 #include <sys/cred.h>
55 55 #include <sys/strsun.h>
56 56 #ifdef DEBUG
57 57 #include <sys/promif.h>
58 58 #endif
59 59 #include <sys/modctl.h>
60 60 #include <sys/ddi.h>
61 61 #include <sys/sunddi.h>
62 62 #include <sys/pci.h>
63 63 #include <sys/asy.h>
64 64 #include <sys/policy.h>
65 65
66 66 /*
67 67 * set the RX FIFO trigger_level to half the RX FIFO size for now
68 68 * we may want to make this configurable later.
69 69 */
70 70 static int asy_trig_level = FIFO_TRIG_8;
71 71
72 72 int asy_drain_check = 15000000; /* tunable: exit drain check time */
73 73 int asy_min_dtr_low = 500000; /* tunable: minimum DTR down time */
74 74 int asy_min_utbrk = 100000; /* tunable: minumum untimed brk time */
75 75
76 76 int asymaxchip = ASY16750; /* tunable: limit chip support we look for */
77 77
78 78 /*
79 79 * Just in case someone has a chip with broken loopback mode, we provide a
80 80 * means to disable the loopback test. By default, we only loopback test
81 81 * UARTs which look like they have FIFOs bigger than 16 bytes.
82 82 * Set to 0 to suppress test, or to 2 to enable test on any size FIFO.
83 83 */
84 84 int asy_fifo_test = 1; /* tunable: set to 0, 1, or 2 */
85 85
86 86 /*
87 87 * Allow ability to switch off testing of the scratch register.
88 88 * Some UART emulators might not have it. This will also disable the test
89 89 * for Exar/Startech ST16C650, as that requires use of the SCR register.
90 90 */
91 91 int asy_scr_test = 1; /* tunable: set to 0 to disable SCR reg test */
92 92
93 93 /*
94 94 * As we don't yet support on-chip flow control, it's a bad idea to put a
95 95 * large number of characters in the TX FIFO, since if other end tells us
96 96 * to stop transmitting, we can only stop filling the TX FIFO, but it will
97 97 * still carry on draining by itself, so remote end still gets what's left
98 98 * in the FIFO.
99 99 */
100 100 int asy_max_tx_fifo = 16; /* tunable: max fill of TX FIFO */
101 101
102 102 #define async_stopc async_ttycommon.t_stopc
103 103 #define async_startc async_ttycommon.t_startc
104 104
105 105 #define ASY_INIT 1
106 106 #define ASY_NOINIT 0
107 107
108 108 /* enum value for sw and hw flow control action */
109 109 typedef enum {
110 110 FLOW_CHECK,
111 111 FLOW_STOP,
112 112 FLOW_START
113 113 } async_flowc_action;
114 114
115 115 #ifdef DEBUG
116 116 #define ASY_DEBUG_INIT 0x0001 /* Output msgs during driver initialization. */
117 117 #define ASY_DEBUG_INPUT 0x0002 /* Report characters received during int. */
118 118 #define ASY_DEBUG_EOT 0x0004 /* Output msgs when wait for xmit to finish. */
119 119 #define ASY_DEBUG_CLOSE 0x0008 /* Output msgs when driver open/close called */
120 120 #define ASY_DEBUG_HFLOW 0x0010 /* Output msgs when H/W flowcontrol is active */
121 121 #define ASY_DEBUG_PROCS 0x0020 /* Output each proc name as it is entered. */
122 122 #define ASY_DEBUG_STATE 0x0040 /* Output value of Interrupt Service Reg. */
123 123 #define ASY_DEBUG_INTR 0x0080 /* Output value of Interrupt Service Reg. */
124 124 #define ASY_DEBUG_OUT 0x0100 /* Output msgs about output events. */
125 125 #define ASY_DEBUG_BUSY 0x0200 /* Output msgs when xmit is enabled/disabled */
126 126 #define ASY_DEBUG_MODEM 0x0400 /* Output msgs about modem status & control. */
127 127 #define ASY_DEBUG_MODM2 0x0800 /* Output msgs about modem status & control. */
128 128 #define ASY_DEBUG_IOCTL 0x1000 /* Output msgs about ioctl messages. */
129 129 #define ASY_DEBUG_CHIP 0x2000 /* Output msgs about chip identification. */
130 130 #define ASY_DEBUG_SFLOW 0x4000 /* Output msgs when S/W flowcontrol is active */
131 131 #define ASY_DEBUG(x) (debug & (x))
132 132 static int debug = 0;
133 133 #else
134 134 #define ASY_DEBUG(x) B_FALSE
135 135 #endif
136 136
137 137 /* pnpISA compressed device ids */
138 138 #define pnpMTS0219 0xb6930219 /* Multitech MT5634ZTX modem */
139 139
140 140 /*
141 141 * PPS (Pulse Per Second) support.
142 142 */
143 143 void ddi_hardpps(struct timeval *, int);
144 144 /*
145 145 * This is protected by the asy_excl_hi of the port on which PPS event
146 146 * handling is enabled. Note that only one port should have this enabled at
147 147 * any one time. Enabling PPS handling on multiple ports will result in
148 148 * unpredictable (but benign) results.
149 149 */
150 150 static struct ppsclockev asy_ppsev;
151 151
152 152 #ifdef PPSCLOCKLED
153 153 /* XXX Use these to observe PPS latencies and jitter on a scope */
154 154 #define LED_ON
155 155 #define LED_OFF
156 156 #else
157 157 #define LED_ON
158 158 #define LED_OFF
159 159 #endif
160 160
161 161 static int max_asy_instance = -1;
162 162
163 163 static uint_t asysoftintr(caddr_t intarg);
164 164 static uint_t asyintr(caddr_t argasy);
165 165
166 166 static boolean_t abort_charseq_recognize(uchar_t ch);
167 167
168 168 /* The async interrupt entry points */
169 169 static void async_txint(struct asycom *asy);
170 170 static void async_rxint(struct asycom *asy, uchar_t lsr);
171 171 static void async_msint(struct asycom *asy);
172 172 static void async_softint(struct asycom *asy);
173 173
174 174 static void async_ioctl(struct asyncline *async, queue_t *q, mblk_t *mp);
175 175 static void async_reioctl(void *unit);
176 176 static void async_iocdata(queue_t *q, mblk_t *mp);
177 177 static void async_restart(void *arg);
178 178 static void async_start(struct asyncline *async);
179 179 static void async_nstart(struct asyncline *async, int mode);
180 180 static void async_resume(struct asyncline *async);
181 181 static void asy_program(struct asycom *asy, int mode);
182 182 static void asyinit(struct asycom *asy);
183 183 static void asy_waiteot(struct asycom *asy);
184 184 static void asyputchar(cons_polledio_arg_t, uchar_t c);
185 185 static int asygetchar(cons_polledio_arg_t);
186 186 static boolean_t asyischar(cons_polledio_arg_t);
187 187
188 188 static int asymctl(struct asycom *, int, int);
189 189 static int asytodm(int, int);
190 190 static int dmtoasy(int);
191 191 /*PRINTFLIKE2*/
192 192 static void asyerror(int level, const char *fmt, ...) __KPRINTFLIKE(2);
193 193 static void asy_parse_mode(dev_info_t *devi, struct asycom *asy);
194 194 static void asy_soft_state_free(struct asycom *);
195 195 static char *asy_hw_name(struct asycom *asy);
196 196 static void async_hold_utbrk(void *arg);
197 197 static void async_resume_utbrk(struct asyncline *async);
198 198 static void async_dtr_free(struct asyncline *async);
199 199 static int asy_identify_chip(dev_info_t *devi, struct asycom *asy);
200 200 static void asy_reset_fifo(struct asycom *asy, uchar_t flags);
201 201 static int asy_getproperty(dev_info_t *devi, struct asycom *asy,
202 202 const char *property);
203 203 static boolean_t async_flowcontrol_sw_input(struct asycom *asy,
204 204 async_flowc_action onoff, int type);
205 205 static void async_flowcontrol_sw_output(struct asycom *asy,
206 206 async_flowc_action onoff);
207 207 static void async_flowcontrol_hw_input(struct asycom *asy,
208 208 async_flowc_action onoff, int type);
209 209 static void async_flowcontrol_hw_output(struct asycom *asy,
210 210 async_flowc_action onoff);
211 211
212 212 #define GET_PROP(devi, pname, pflag, pval, plen) \
213 213 (ddi_prop_op(DDI_DEV_T_ANY, (devi), PROP_LEN_AND_VAL_BUF, \
214 214 (pflag), (pname), (caddr_t)(pval), (plen)))
215 215
216 216 kmutex_t asy_glob_lock; /* lock protecting global data manipulation */
217 217 void *asy_soft_state;
218 218
219 219 /* Standard COM port I/O addresses */
220 220 static const int standard_com_ports[] = {
221 221 COM1_IOADDR, COM2_IOADDR, COM3_IOADDR, COM4_IOADDR
222 222 };
223 223
224 224 static int *com_ports;
225 225 static uint_t num_com_ports;
226 226
227 227 #ifdef DEBUG
228 228 /*
229 229 * Set this to true to make the driver pretend to do a suspend. Useful
230 230 * for debugging suspend/resume code with a serial debugger.
231 231 */
232 232 boolean_t asy_nosuspend = B_FALSE;
233 233 #endif
234 234
235 235
236 236 /*
237 237 * Baud rate table. Indexed by #defines found in sys/termios.h
238 238 */
239 239 ushort_t asyspdtab[] = {
240 240 0, /* 0 baud rate */
241 241 0x900, /* 50 baud rate */
242 242 0x600, /* 75 baud rate */
243 243 0x417, /* 110 baud rate (%0.026) */
244 244 0x359, /* 134 baud rate (%0.058) */
245 245 0x300, /* 150 baud rate */
246 246 0x240, /* 200 baud rate */
247 247 0x180, /* 300 baud rate */
248 248 0x0c0, /* 600 baud rate */
249 249 0x060, /* 1200 baud rate */
250 250 0x040, /* 1800 baud rate */
251 251 0x030, /* 2400 baud rate */
252 252 0x018, /* 4800 baud rate */
253 253 0x00c, /* 9600 baud rate */
254 254 0x006, /* 19200 baud rate */
255 255 0x003, /* 38400 baud rate */
256 256
257 257 0x002, /* 57600 baud rate */
258 258 0x0, /* 76800 baud rate not supported */
259 259 0x001, /* 115200 baud rate */
260 260 0x0, /* 153600 baud rate not supported */
261 261 0x0, /* 0x8002 (SMC chip) 230400 baud rate not supported */
262 262 0x0, /* 307200 baud rate not supported */
263 263 0x0, /* 0x8001 (SMC chip) 460800 baud rate not supported */
264 264 0x0, /* unused */
265 265 0x0, /* unused */
266 266 0x0, /* unused */
267 267 0x0, /* unused */
268 268 0x0, /* unused */
269 269 0x0, /* unused */
270 270 0x0, /* unused */
271 271 0x0, /* unused */
272 272 0x0, /* unused */
273 273 };
274 274
275 275 static int asyrsrv(queue_t *q);
276 276 static int asyopen(queue_t *rq, dev_t *dev, int flag, int sflag, cred_t *cr);
277 277 static int asyclose(queue_t *q, int flag, cred_t *credp);
278 278 static int asywputdo(queue_t *q, mblk_t *mp, boolean_t);
279 279 static int asywput(queue_t *q, mblk_t *mp);
280 280
281 281 struct module_info asy_info = {
282 282 0,
283 283 "asy",
284 284 0,
285 285 INFPSZ,
286 286 4096,
287 287 128
288 288 };
289 289
290 290 static struct qinit asy_rint = {
291 291 putq,
292 292 asyrsrv,
293 293 asyopen,
294 294 asyclose,
295 295 NULL,
296 296 &asy_info,
297 297 NULL
298 298 };
299 299
300 300 static struct qinit asy_wint = {
301 301 asywput,
302 302 NULL,
303 303 NULL,
304 304 NULL,
305 305 NULL,
306 306 &asy_info,
307 307 NULL
308 308 };
309 309
310 310 struct streamtab asy_str_info = {
311 311 &asy_rint,
312 312 &asy_wint,
313 313 NULL,
314 314 NULL
315 315 };
316 316
317 317 static int asyinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
318 318 void **result);
319 319 static int asyprobe(dev_info_t *);
320 320 static int asyattach(dev_info_t *, ddi_attach_cmd_t);
321 321 static int asydetach(dev_info_t *, ddi_detach_cmd_t);
322 322 static int asyquiesce(dev_info_t *);
323 323
324 324 static struct cb_ops cb_asy_ops = {
325 325 nodev, /* cb_open */
326 326 nodev, /* cb_close */
327 327 nodev, /* cb_strategy */
328 328 nodev, /* cb_print */
329 329 nodev, /* cb_dump */
330 330 nodev, /* cb_read */
331 331 nodev, /* cb_write */
332 332 nodev, /* cb_ioctl */
333 333 nodev, /* cb_devmap */
334 334 nodev, /* cb_mmap */
335 335 nodev, /* cb_segmap */
336 336 nochpoll, /* cb_chpoll */
337 337 ddi_prop_op, /* cb_prop_op */
338 338 &asy_str_info, /* cb_stream */
339 339 D_MP /* cb_flag */
340 340 };
341 341
342 342 struct dev_ops asy_ops = {
343 343 DEVO_REV, /* devo_rev */
344 344 0, /* devo_refcnt */
345 345 asyinfo, /* devo_getinfo */
346 346 nulldev, /* devo_identify */
347 347 asyprobe, /* devo_probe */
348 348 asyattach, /* devo_attach */
349 349 asydetach, /* devo_detach */
350 350 nodev, /* devo_reset */
351 351 &cb_asy_ops, /* devo_cb_ops */
352 352 NULL, /* devo_bus_ops */
353 353 NULL, /* power */
354 354 asyquiesce, /* quiesce */
↓ open down ↓ |
354 lines elided |
↑ open up ↑ |
355 355 };
356 356
357 357 static struct modldrv modldrv = {
358 358 &mod_driverops, /* Type of module. This one is a driver */
359 359 "ASY driver",
360 360 &asy_ops, /* driver ops */
361 361 };
362 362
363 363 static struct modlinkage modlinkage = {
364 364 MODREV_1,
365 - (void *)&modldrv,
366 - NULL
365 + { (void *)&modldrv, NULL }
367 366 };
368 367
369 368 int
370 369 _init(void)
371 370 {
372 371 int i;
373 372
374 373 i = ddi_soft_state_init(&asy_soft_state, sizeof (struct asycom), 2);
375 374 if (i == 0) {
376 375 mutex_init(&asy_glob_lock, NULL, MUTEX_DRIVER, NULL);
377 376 if ((i = mod_install(&modlinkage)) != 0) {
378 377 mutex_destroy(&asy_glob_lock);
379 378 ddi_soft_state_fini(&asy_soft_state);
380 379 } else {
381 380 DEBUGCONT2(ASY_DEBUG_INIT, "%s, debug = %x\n",
382 381 modldrv.drv_linkinfo, debug);
383 382 }
384 383 }
385 384 return (i);
386 385 }
387 386
388 387 int
389 388 _fini(void)
390 389 {
391 390 int i;
392 391
393 392 if ((i = mod_remove(&modlinkage)) == 0) {
394 393 DEBUGCONT1(ASY_DEBUG_INIT, "%s unloading\n",
395 394 modldrv.drv_linkinfo);
396 395 ASSERT(max_asy_instance == -1);
397 396 mutex_destroy(&asy_glob_lock);
398 397 /* free "motherboard-serial-ports" property if allocated */
399 398 if (com_ports != NULL && com_ports != (int *)standard_com_ports)
400 399 ddi_prop_free(com_ports);
401 400 com_ports = NULL;
402 401 ddi_soft_state_fini(&asy_soft_state);
403 402 }
404 403 return (i);
405 404 }
406 405
407 406 int
408 407 _info(struct modinfo *modinfop)
409 408 {
410 409 return (mod_info(&modlinkage, modinfop));
411 410 }
412 411
413 412 void
414 413 async_put_suspq(struct asycom *asy, mblk_t *mp)
415 414 {
416 415 struct asyncline *async = asy->asy_priv;
417 416
418 417 ASSERT(mutex_owned(&asy->asy_excl));
419 418
420 419 if (async->async_suspqf == NULL)
421 420 async->async_suspqf = mp;
422 421 else
423 422 async->async_suspqb->b_next = mp;
424 423
425 424 async->async_suspqb = mp;
426 425 }
427 426
428 427 static mblk_t *
429 428 async_get_suspq(struct asycom *asy)
430 429 {
431 430 struct asyncline *async = asy->asy_priv;
432 431 mblk_t *mp;
433 432
434 433 ASSERT(mutex_owned(&asy->asy_excl));
435 434
436 435 if ((mp = async->async_suspqf) != NULL) {
437 436 async->async_suspqf = mp->b_next;
438 437 mp->b_next = NULL;
439 438 } else {
440 439 async->async_suspqb = NULL;
441 440 }
442 441 return (mp);
443 442 }
444 443
445 444 static void
446 445 async_process_suspq(struct asycom *asy)
447 446 {
448 447 struct asyncline *async = asy->asy_priv;
449 448 mblk_t *mp;
450 449
451 450 ASSERT(mutex_owned(&asy->asy_excl));
452 451
453 452 while ((mp = async_get_suspq(asy)) != NULL) {
454 453 queue_t *q;
455 454
456 455 q = async->async_ttycommon.t_writeq;
457 456 ASSERT(q != NULL);
458 457 mutex_exit(&asy->asy_excl);
459 458 (void) asywputdo(q, mp, B_FALSE);
460 459 mutex_enter(&asy->asy_excl);
461 460 }
462 461 async->async_flags &= ~ASYNC_DDI_SUSPENDED;
463 462 cv_broadcast(&async->async_flags_cv);
464 463 }
465 464
466 465 static int
467 466 asy_get_bus_type(dev_info_t *devinfo)
468 467 {
469 468 char parent_type[16];
470 469 int parentlen;
471 470
472 471 parentlen = sizeof (parent_type);
473 472
474 473 if (ddi_prop_op(DDI_DEV_T_ANY, devinfo, PROP_LEN_AND_VAL_BUF, 0,
475 474 "device_type", (caddr_t)parent_type, &parentlen)
476 475 != DDI_PROP_SUCCESS && ddi_prop_op(DDI_DEV_T_ANY, devinfo,
477 476 PROP_LEN_AND_VAL_BUF, 0, "bus-type", (caddr_t)parent_type,
478 477 &parentlen) != DDI_PROP_SUCCESS) {
479 478 cmn_err(CE_WARN,
480 479 "asy: can't figure out device type for"
481 480 " parent \"%s\"",
482 481 ddi_get_name(ddi_get_parent(devinfo)));
483 482 return (ASY_BUS_UNKNOWN);
484 483 }
485 484 if (strcmp(parent_type, "isa") == 0)
486 485 return (ASY_BUS_ISA);
487 486 else if (strcmp(parent_type, "pci") == 0)
488 487 return (ASY_BUS_PCI);
489 488 else
490 489 return (ASY_BUS_UNKNOWN);
491 490 }
492 491
493 492 static int
494 493 asy_get_io_regnum_pci(dev_info_t *devi, struct asycom *asy)
495 494 {
496 495 int reglen, nregs;
497 496 int regnum, i;
498 497 uint64_t size;
499 498 struct pci_phys_spec *reglist;
500 499
501 500 if (ddi_getlongprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS,
502 501 "reg", (caddr_t)®list, ®len) != DDI_PROP_SUCCESS) {
503 502 cmn_err(CE_WARN, "asy_get_io_regnum_pci: reg property"
504 503 " not found in devices property list");
505 504 return (-1);
506 505 }
507 506
508 507 /*
509 508 * PCI devices are assumed to not have broken FIFOs;
510 509 * Agere/Lucent Venus PCI modem chipsets are an example
511 510 */
512 511 if (asy)
513 512 asy->asy_flags2 |= ASY2_NO_LOOPBACK;
514 513
515 514 regnum = -1;
516 515 nregs = reglen / sizeof (*reglist);
517 516 for (i = 0; i < nregs; i++) {
518 517 switch (reglist[i].pci_phys_hi & PCI_ADDR_MASK) {
519 518 case PCI_ADDR_IO: /* I/O bus reg property */
520 519 if (regnum == -1) /* use only the first one */
521 520 regnum = i;
522 521 break;
523 522
524 523 default:
525 524 break;
526 525 }
527 526 }
528 527
529 528 /* check for valid count of registers */
530 529 if (regnum >= 0) {
531 530 size = ((uint64_t)reglist[regnum].pci_size_low) |
532 531 ((uint64_t)reglist[regnum].pci_size_hi) << 32;
533 532 if (size < 8)
534 533 regnum = -1;
535 534 }
536 535 kmem_free(reglist, reglen);
537 536 return (regnum);
538 537 }
539 538
540 539 static int
541 540 asy_get_io_regnum_isa(dev_info_t *devi, struct asycom *asy)
542 541 {
543 542 int reglen, nregs;
544 543 int regnum, i;
545 544 struct {
546 545 uint_t bustype;
547 546 int base;
548 547 int size;
549 548 } *reglist;
550 549
551 550 if (ddi_getlongprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS,
552 551 "reg", (caddr_t)®list, ®len) != DDI_PROP_SUCCESS) {
553 552 cmn_err(CE_WARN, "asy_get_io_regnum: reg property not found "
554 553 "in devices property list");
555 554 return (-1);
556 555 }
557 556
558 557 regnum = -1;
559 558 nregs = reglen / sizeof (*reglist);
560 559 for (i = 0; i < nregs; i++) {
561 560 switch (reglist[i].bustype) {
562 561 case 1: /* I/O bus reg property */
563 562 if (regnum == -1) /* only use the first one */
564 563 regnum = i;
565 564 break;
566 565
567 566 case pnpMTS0219: /* Multitech MT5634ZTX modem */
568 567 /* Venus chipset can't do loopback test */
569 568 if (asy)
570 569 asy->asy_flags2 |= ASY2_NO_LOOPBACK;
571 570 break;
572 571
573 572 default:
574 573 break;
575 574 }
576 575 }
577 576
578 577 /* check for valid count of registers */
579 578 if ((regnum < 0) || (reglist[regnum].size < 8))
580 579 regnum = -1;
581 580 kmem_free(reglist, reglen);
582 581 return (regnum);
583 582 }
584 583
585 584 static int
586 585 asy_get_io_regnum(dev_info_t *devinfo, struct asycom *asy)
587 586 {
588 587 switch (asy_get_bus_type(devinfo)) {
589 588 case ASY_BUS_ISA:
590 589 return (asy_get_io_regnum_isa(devinfo, asy));
591 590 case ASY_BUS_PCI:
592 591 return (asy_get_io_regnum_pci(devinfo, asy));
593 592 default:
594 593 return (-1);
595 594 }
596 595 }
597 596
598 597 static int
599 598 asydetach(dev_info_t *devi, ddi_detach_cmd_t cmd)
600 599 {
601 600 int instance;
602 601 struct asycom *asy;
603 602 struct asyncline *async;
604 603
605 604 instance = ddi_get_instance(devi); /* find out which unit */
606 605
607 606 asy = ddi_get_soft_state(asy_soft_state, instance);
608 607 if (asy == NULL)
609 608 return (DDI_FAILURE);
610 609 async = asy->asy_priv;
611 610
612 611 switch (cmd) {
613 612 case DDI_DETACH:
614 613 DEBUGNOTE2(ASY_DEBUG_INIT, "asy%d: %s shutdown.",
615 614 instance, asy_hw_name(asy));
616 615
617 616 /* cancel DTR hold timeout */
618 617 if (async->async_dtrtid != 0) {
619 618 (void) untimeout(async->async_dtrtid);
620 619 async->async_dtrtid = 0;
621 620 }
622 621
623 622 /* remove all minor device node(s) for this device */
624 623 ddi_remove_minor_node(devi, NULL);
625 624
626 625 mutex_destroy(&asy->asy_excl);
627 626 mutex_destroy(&asy->asy_excl_hi);
628 627 cv_destroy(&async->async_flags_cv);
629 628 ddi_remove_intr(devi, 0, asy->asy_iblock);
630 629 ddi_regs_map_free(&asy->asy_iohandle);
631 630 ddi_remove_softintr(asy->asy_softintr_id);
632 631 mutex_destroy(&asy->asy_soft_lock);
633 632 asy_soft_state_free(asy);
634 633 DEBUGNOTE1(ASY_DEBUG_INIT, "asy%d: shutdown complete",
635 634 instance);
636 635 break;
637 636 case DDI_SUSPEND:
638 637 {
639 638 unsigned i;
640 639 uchar_t lsr;
641 640
642 641 #ifdef DEBUG
643 642 if (asy_nosuspend)
644 643 return (DDI_SUCCESS);
645 644 #endif
646 645 mutex_enter(&asy->asy_excl);
647 646
648 647 ASSERT(async->async_ops >= 0);
649 648 while (async->async_ops > 0)
650 649 cv_wait(&async->async_ops_cv, &asy->asy_excl);
651 650
652 651 async->async_flags |= ASYNC_DDI_SUSPENDED;
653 652
654 653 /* Wait for timed break and delay to complete */
655 654 while ((async->async_flags & (ASYNC_BREAK|ASYNC_DELAY))) {
656 655 if (cv_wait_sig(&async->async_flags_cv, &asy->asy_excl)
657 656 == 0) {
658 657 async_process_suspq(asy);
659 658 mutex_exit(&asy->asy_excl);
660 659 return (DDI_FAILURE);
661 660 }
662 661 }
663 662
664 663 /* Clear untimed break */
665 664 if (async->async_flags & ASYNC_OUT_SUSPEND)
666 665 async_resume_utbrk(async);
667 666
668 667 mutex_exit(&asy->asy_excl);
669 668
670 669 mutex_enter(&asy->asy_soft_sr);
671 670 mutex_enter(&asy->asy_excl);
672 671 if (async->async_wbufcid != 0) {
673 672 bufcall_id_t bcid = async->async_wbufcid;
674 673 async->async_wbufcid = 0;
675 674 async->async_flags |= ASYNC_RESUME_BUFCALL;
676 675 mutex_exit(&asy->asy_excl);
677 676 unbufcall(bcid);
678 677 mutex_enter(&asy->asy_excl);
679 678 }
680 679 mutex_enter(&asy->asy_excl_hi);
681 680
682 681 /* Disable interrupts from chip */
683 682 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + ICR, 0);
684 683 asy->asy_flags |= ASY_DDI_SUSPENDED;
685 684
686 685 /*
687 686 * Hardware interrupts are disabled we can drop our high level
688 687 * lock and proceed.
689 688 */
690 689 mutex_exit(&asy->asy_excl_hi);
691 690
692 691 /* Process remaining RX characters and RX errors, if any */
693 692 lsr = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + LSR);
694 693 async_rxint(asy, lsr);
695 694
696 695 /* Wait for TX to drain */
697 696 for (i = 1000; i > 0; i--) {
698 697 lsr = ddi_get8(asy->asy_iohandle,
699 698 asy->asy_ioaddr + LSR);
700 699 if ((lsr & (XSRE | XHRE)) == (XSRE | XHRE))
701 700 break;
702 701 delay(drv_usectohz(10000));
703 702 }
704 703 if (i == 0)
705 704 cmn_err(CE_WARN,
706 705 "asy: transmitter wasn't drained before "
707 706 "driver was suspended");
708 707
709 708 mutex_exit(&asy->asy_excl);
710 709 mutex_exit(&asy->asy_soft_sr);
711 710 break;
712 711 }
713 712 default:
714 713 return (DDI_FAILURE);
715 714 }
716 715
717 716 return (DDI_SUCCESS);
718 717 }
719 718
720 719 /*
721 720 * asyprobe
722 721 * We don't bother probing for the hardware, as since Solaris 2.6, device
723 722 * nodes are only created for auto-detected hardware or nodes explicitly
724 723 * created by the user, e.g. via the DCA. However, we should check the
725 724 * device node is at least vaguely usable, i.e. we have a block of 8 i/o
726 725 * ports. This prevents attempting to attach to bogus serial ports which
727 726 * some BIOSs still partially report when they are disabled in the BIOS.
728 727 */
729 728 static int
730 729 asyprobe(dev_info_t *devi)
731 730 {
732 731 return ((asy_get_io_regnum(devi, NULL) < 0) ?
733 732 DDI_PROBE_FAILURE : DDI_PROBE_DONTCARE);
734 733 }
735 734
736 735 static int
737 736 asyattach(dev_info_t *devi, ddi_attach_cmd_t cmd)
738 737 {
739 738 int instance;
740 739 int mcr;
741 740 int ret;
742 741 int regnum = 0;
743 742 int i;
744 743 struct asycom *asy;
745 744 char name[ASY_MINOR_LEN];
746 745 int status;
747 746 static ddi_device_acc_attr_t ioattr = {
748 747 DDI_DEVICE_ATTR_V0,
749 748 DDI_NEVERSWAP_ACC,
750 749 DDI_STRICTORDER_ACC,
751 750 };
752 751
753 752 instance = ddi_get_instance(devi); /* find out which unit */
754 753
755 754 switch (cmd) {
756 755 case DDI_ATTACH:
757 756 break;
758 757 case DDI_RESUME:
759 758 {
760 759 struct asyncline *async;
761 760
762 761 #ifdef DEBUG
763 762 if (asy_nosuspend)
764 763 return (DDI_SUCCESS);
765 764 #endif
766 765 asy = ddi_get_soft_state(asy_soft_state, instance);
767 766 if (asy == NULL)
768 767 return (DDI_FAILURE);
769 768
770 769 mutex_enter(&asy->asy_soft_sr);
771 770 mutex_enter(&asy->asy_excl);
772 771 mutex_enter(&asy->asy_excl_hi);
773 772
774 773 async = asy->asy_priv;
775 774 /* Disable interrupts */
776 775 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + ICR, 0);
777 776 if (asy_identify_chip(devi, asy) != DDI_SUCCESS) {
778 777 mutex_exit(&asy->asy_excl_hi);
779 778 mutex_exit(&asy->asy_excl);
780 779 mutex_exit(&asy->asy_soft_sr);
781 780 cmn_err(CE_WARN, "!Cannot identify UART chip at %p\n",
782 781 (void *)asy->asy_ioaddr);
783 782 return (DDI_FAILURE);
784 783 }
785 784 asy->asy_flags &= ~ASY_DDI_SUSPENDED;
786 785 if (async->async_flags & ASYNC_ISOPEN) {
787 786 asy_program(asy, ASY_INIT);
788 787 /* Kick off output */
789 788 if (async->async_ocnt > 0) {
790 789 async_resume(async);
791 790 } else {
792 791 mutex_exit(&asy->asy_excl_hi);
793 792 if (async->async_xmitblk)
794 793 freeb(async->async_xmitblk);
795 794 async->async_xmitblk = NULL;
796 795 async_start(async);
797 796 mutex_enter(&asy->asy_excl_hi);
798 797 }
799 798 ASYSETSOFT(asy);
800 799 }
801 800 mutex_exit(&asy->asy_excl_hi);
802 801 mutex_exit(&asy->asy_excl);
803 802 mutex_exit(&asy->asy_soft_sr);
804 803
805 804 mutex_enter(&asy->asy_excl);
806 805 if (async->async_flags & ASYNC_RESUME_BUFCALL) {
807 806 async->async_wbufcid = bufcall(async->async_wbufcds,
808 807 BPRI_HI, (void (*)(void *)) async_reioctl,
809 808 (void *)(intptr_t)async->async_common->asy_unit);
810 809 async->async_flags &= ~ASYNC_RESUME_BUFCALL;
811 810 }
812 811 async_process_suspq(asy);
813 812 mutex_exit(&asy->asy_excl);
814 813 return (DDI_SUCCESS);
815 814 }
816 815 default:
817 816 return (DDI_FAILURE);
818 817 }
819 818
820 819 ret = ddi_soft_state_zalloc(asy_soft_state, instance);
821 820 if (ret != DDI_SUCCESS)
822 821 return (DDI_FAILURE);
823 822 asy = ddi_get_soft_state(asy_soft_state, instance);
824 823 ASSERT(asy != NULL); /* can't fail - we only just allocated it */
825 824 asy->asy_unit = instance;
826 825 mutex_enter(&asy_glob_lock);
827 826 if (instance > max_asy_instance)
828 827 max_asy_instance = instance;
829 828 mutex_exit(&asy_glob_lock);
830 829
831 830 regnum = asy_get_io_regnum(devi, asy);
832 831
833 832 if (regnum < 0 ||
834 833 ddi_regs_map_setup(devi, regnum, (caddr_t *)&asy->asy_ioaddr,
835 834 (offset_t)0, (offset_t)0, &ioattr, &asy->asy_iohandle)
836 835 != DDI_SUCCESS) {
837 836 cmn_err(CE_WARN, "asy%d: could not map UART registers @ %p",
838 837 instance, (void *)asy->asy_ioaddr);
839 838
840 839 asy_soft_state_free(asy);
841 840 return (DDI_FAILURE);
842 841 }
843 842
844 843 DEBUGCONT2(ASY_DEBUG_INIT, "asy%dattach: UART @ %p\n",
845 844 instance, (void *)asy->asy_ioaddr);
846 845
847 846 mutex_enter(&asy_glob_lock);
848 847 if (com_ports == NULL) { /* need to initialize com_ports */
849 848 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, devi, 0,
850 849 "motherboard-serial-ports", &com_ports, &num_com_ports) !=
851 850 DDI_PROP_SUCCESS) {
852 851 /* Use our built-in COM[1234] values */
853 852 com_ports = (int *)standard_com_ports;
854 853 num_com_ports = sizeof (standard_com_ports) /
855 854 sizeof (standard_com_ports[0]);
856 855 }
857 856 if (num_com_ports > 10) {
858 857 /* We run out of single digits for device properties */
859 858 num_com_ports = 10;
860 859 cmn_err(CE_WARN,
861 860 "More than %d motherboard-serial-ports",
862 861 num_com_ports);
863 862 }
864 863 }
865 864 mutex_exit(&asy_glob_lock);
866 865
867 866 /*
868 867 * Lookup the i/o address to see if this is a standard COM port
869 868 * in which case we assign it the correct tty[a-d] to match the
870 869 * COM port number, or some other i/o address in which case it
871 870 * will be assigned /dev/term/[0123...] in some rather arbitrary
872 871 * fashion.
873 872 */
874 873
875 874 for (i = 0; i < num_com_ports; i++) {
876 875 if (asy->asy_ioaddr == (uint8_t *)(uintptr_t)com_ports[i]) {
877 876 asy->asy_com_port = i + 1;
878 877 break;
879 878 }
880 879 }
881 880
882 881 /*
883 882 * It appears that there was async hardware that on reset
884 883 * did not clear ICR. Hence when we get to
885 884 * ddi_get_iblock_cookie below, this hardware would cause
886 885 * the system to hang if there was input available.
887 886 */
888 887
889 888 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + ICR, 0x00);
890 889
891 890 /* establish default usage */
892 891 asy->asy_mcr |= RTS|DTR; /* do use RTS/DTR after open */
893 892 asy->asy_lcr = STOP1|BITS8; /* default to 1 stop 8 bits */
894 893 asy->asy_bidx = B9600; /* default to 9600 */
895 894 #ifdef DEBUG
896 895 asy->asy_msint_cnt = 0; /* # of times in async_msint */
897 896 #endif
898 897 mcr = 0; /* don't enable until open */
899 898
900 899 if (asy->asy_com_port != 0) {
901 900 /*
902 901 * For motherboard ports, emulate tty eeprom properties.
903 902 * Actually, we can't tell if a port is motherboard or not,
904 903 * so for "motherboard ports", read standard DOS COM ports.
905 904 */
906 905 switch (asy_getproperty(devi, asy, "ignore-cd")) {
907 906 case 0: /* *-ignore-cd=False */
908 907 DEBUGCONT1(ASY_DEBUG_MODEM,
909 908 "asy%dattach: clear ASY_IGNORE_CD\n", instance);
910 909 asy->asy_flags &= ~ASY_IGNORE_CD; /* wait for cd */
911 910 break;
912 911 case 1: /* *-ignore-cd=True */
913 912 /*FALLTHRU*/
914 913 default: /* *-ignore-cd not defined */
915 914 /*
916 915 * We set rather silly defaults of soft carrier on
917 916 * and DTR/RTS raised here because it might be that
918 917 * one of the motherboard ports is the system console.
919 918 */
920 919 DEBUGCONT1(ASY_DEBUG_MODEM,
921 920 "asy%dattach: set ASY_IGNORE_CD, set RTS & DTR\n",
922 921 instance);
923 922 mcr = asy->asy_mcr; /* rts/dtr on */
924 923 asy->asy_flags |= ASY_IGNORE_CD; /* ignore cd */
925 924 break;
926 925 }
927 926
928 927 /* Property for not raising DTR/RTS */
929 928 switch (asy_getproperty(devi, asy, "rts-dtr-off")) {
930 929 case 0: /* *-rts-dtr-off=False */
931 930 asy->asy_flags |= ASY_RTS_DTR_OFF; /* OFF */
932 931 mcr = asy->asy_mcr; /* rts/dtr on */
933 932 DEBUGCONT1(ASY_DEBUG_MODEM, "asy%dattach: "
934 933 "ASY_RTS_DTR_OFF set and DTR & RTS set\n",
935 934 instance);
936 935 break;
937 936 case 1: /* *-rts-dtr-off=True */
938 937 /*FALLTHRU*/
939 938 default: /* *-rts-dtr-off undefined */
940 939 break;
941 940 }
942 941
943 942 /* Parse property for tty modes */
944 943 asy_parse_mode(devi, asy);
945 944 } else {
946 945 DEBUGCONT1(ASY_DEBUG_MODEM,
947 946 "asy%dattach: clear ASY_IGNORE_CD, clear RTS & DTR\n",
948 947 instance);
949 948 asy->asy_flags &= ~ASY_IGNORE_CD; /* wait for cd */
950 949 }
951 950
952 951 /*
953 952 * Initialize the port with default settings.
954 953 */
955 954
956 955 asy->asy_fifo_buf = 1;
957 956 asy->asy_use_fifo = FIFO_OFF;
958 957
959 958 /*
960 959 * Get icookie for mutexes initialization
961 960 */
962 961 if ((ddi_get_iblock_cookie(devi, 0, &asy->asy_iblock) !=
963 962 DDI_SUCCESS) ||
964 963 (ddi_get_soft_iblock_cookie(devi, DDI_SOFTINT_MED,
965 964 &asy->asy_soft_iblock) != DDI_SUCCESS)) {
966 965 ddi_regs_map_free(&asy->asy_iohandle);
967 966 cmn_err(CE_CONT,
968 967 "asy%d: could not hook interrupt for UART @ %p\n",
969 968 instance, (void *)asy->asy_ioaddr);
970 969 asy_soft_state_free(asy);
971 970 return (DDI_FAILURE);
972 971 }
973 972
974 973 /*
975 974 * Initialize mutexes before accessing the hardware
976 975 */
977 976 mutex_init(&asy->asy_soft_lock, NULL, MUTEX_DRIVER,
978 977 (void *)asy->asy_soft_iblock);
979 978 mutex_init(&asy->asy_excl, NULL, MUTEX_DRIVER, NULL);
980 979 mutex_init(&asy->asy_excl_hi, NULL, MUTEX_DRIVER,
981 980 (void *)asy->asy_iblock);
982 981 mutex_init(&asy->asy_soft_sr, NULL, MUTEX_DRIVER,
983 982 (void *)asy->asy_soft_iblock);
984 983 mutex_enter(&asy->asy_excl);
985 984 mutex_enter(&asy->asy_excl_hi);
986 985
987 986 if (asy_identify_chip(devi, asy) != DDI_SUCCESS) {
988 987 mutex_exit(&asy->asy_excl_hi);
989 988 mutex_exit(&asy->asy_excl);
990 989 mutex_destroy(&asy->asy_soft_lock);
991 990 mutex_destroy(&asy->asy_excl);
992 991 mutex_destroy(&asy->asy_excl_hi);
993 992 mutex_destroy(&asy->asy_soft_sr);
994 993 ddi_regs_map_free(&asy->asy_iohandle);
995 994 cmn_err(CE_CONT, "!Cannot identify UART chip at %p\n",
996 995 (void *)asy->asy_ioaddr);
997 996 asy_soft_state_free(asy);
998 997 return (DDI_FAILURE);
999 998 }
1000 999
1001 1000 /* disable all interrupts */
1002 1001 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + ICR, 0);
1003 1002 /* select baud rate generator */
1004 1003 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR, DLAB);
1005 1004 /* Set the baud rate to 9600 */
1006 1005 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + (DAT+DLL),
1007 1006 asyspdtab[asy->asy_bidx] & 0xff);
1008 1007 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + (DAT+DLH),
1009 1008 (asyspdtab[asy->asy_bidx] >> 8) & 0xff);
1010 1009 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR, asy->asy_lcr);
1011 1010 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + MCR, mcr);
1012 1011
1013 1012 mutex_exit(&asy->asy_excl_hi);
1014 1013 mutex_exit(&asy->asy_excl);
1015 1014
1016 1015 /*
1017 1016 * Set up the other components of the asycom structure for this port.
1018 1017 */
1019 1018 asy->asy_dip = devi;
1020 1019
1021 1020 /*
1022 1021 * Install per instance software interrupt handler.
1023 1022 */
1024 1023 if (ddi_add_softintr(devi, DDI_SOFTINT_MED,
1025 1024 &(asy->asy_softintr_id), NULL, 0, asysoftintr,
1026 1025 (caddr_t)asy) != DDI_SUCCESS) {
1027 1026 mutex_destroy(&asy->asy_soft_lock);
1028 1027 mutex_destroy(&asy->asy_excl);
1029 1028 mutex_destroy(&asy->asy_excl_hi);
1030 1029 ddi_regs_map_free(&asy->asy_iohandle);
1031 1030 cmn_err(CE_CONT,
1032 1031 "Can not set soft interrupt for ASY driver\n");
1033 1032 asy_soft_state_free(asy);
1034 1033 return (DDI_FAILURE);
1035 1034 }
1036 1035
1037 1036 mutex_enter(&asy->asy_excl);
1038 1037 mutex_enter(&asy->asy_excl_hi);
1039 1038
1040 1039 /*
1041 1040 * Install interrupt handler for this device.
1042 1041 */
1043 1042 if (ddi_add_intr(devi, 0, NULL, 0, asyintr,
1044 1043 (caddr_t)asy) != DDI_SUCCESS) {
1045 1044 mutex_exit(&asy->asy_excl_hi);
1046 1045 mutex_exit(&asy->asy_excl);
1047 1046 ddi_remove_softintr(asy->asy_softintr_id);
1048 1047 mutex_destroy(&asy->asy_soft_lock);
1049 1048 mutex_destroy(&asy->asy_excl);
1050 1049 mutex_destroy(&asy->asy_excl_hi);
1051 1050 ddi_regs_map_free(&asy->asy_iohandle);
1052 1051 cmn_err(CE_CONT,
1053 1052 "Can not set device interrupt for ASY driver\n");
1054 1053 asy_soft_state_free(asy);
1055 1054 return (DDI_FAILURE);
1056 1055 }
1057 1056
1058 1057 mutex_exit(&asy->asy_excl_hi);
1059 1058 mutex_exit(&asy->asy_excl);
1060 1059
1061 1060 asyinit(asy); /* initialize the asyncline structure */
1062 1061
1063 1062 /* create minor device nodes for this device */
1064 1063 if (asy->asy_com_port != 0) {
1065 1064 /*
1066 1065 * For DOS COM ports, add letter suffix so
1067 1066 * devfsadm can create correct link names.
1068 1067 */
1069 1068 name[0] = asy->asy_com_port + 'a' - 1;
1070 1069 name[1] = '\0';
1071 1070 } else {
1072 1071 /*
1073 1072 * asy port which isn't a standard DOS COM
1074 1073 * port gets a numeric name based on instance
1075 1074 */
1076 1075 (void) snprintf(name, ASY_MINOR_LEN, "%d", instance);
1077 1076 }
1078 1077 status = ddi_create_minor_node(devi, name, S_IFCHR, instance,
1079 1078 asy->asy_com_port != 0 ? DDI_NT_SERIAL_MB : DDI_NT_SERIAL, NULL);
1080 1079 if (status == DDI_SUCCESS) {
1081 1080 (void) strcat(name, ",cu");
1082 1081 status = ddi_create_minor_node(devi, name, S_IFCHR,
1083 1082 OUTLINE | instance,
1084 1083 asy->asy_com_port != 0 ? DDI_NT_SERIAL_MB_DO :
1085 1084 DDI_NT_SERIAL_DO, NULL);
1086 1085 }
1087 1086
1088 1087 if (status != DDI_SUCCESS) {
1089 1088 struct asyncline *async = asy->asy_priv;
1090 1089
1091 1090 ddi_remove_minor_node(devi, NULL);
1092 1091 ddi_remove_intr(devi, 0, asy->asy_iblock);
1093 1092 ddi_remove_softintr(asy->asy_softintr_id);
1094 1093 mutex_destroy(&asy->asy_soft_lock);
1095 1094 mutex_destroy(&asy->asy_excl);
1096 1095 mutex_destroy(&asy->asy_excl_hi);
1097 1096 cv_destroy(&async->async_flags_cv);
1098 1097 ddi_regs_map_free(&asy->asy_iohandle);
1099 1098 asy_soft_state_free(asy);
1100 1099 return (DDI_FAILURE);
1101 1100 }
1102 1101
1103 1102 /*
1104 1103 * Fill in the polled I/O structure.
1105 1104 */
1106 1105 asy->polledio.cons_polledio_version = CONSPOLLEDIO_V0;
1107 1106 asy->polledio.cons_polledio_argument = (cons_polledio_arg_t)asy;
1108 1107 asy->polledio.cons_polledio_putchar = asyputchar;
1109 1108 asy->polledio.cons_polledio_getchar = asygetchar;
1110 1109 asy->polledio.cons_polledio_ischar = asyischar;
1111 1110 asy->polledio.cons_polledio_enter = NULL;
1112 1111 asy->polledio.cons_polledio_exit = NULL;
1113 1112
1114 1113 ddi_report_dev(devi);
1115 1114 DEBUGCONT1(ASY_DEBUG_INIT, "asy%dattach: done\n", instance);
1116 1115 return (DDI_SUCCESS);
1117 1116 }
1118 1117
1119 1118 /*ARGSUSED*/
1120 1119 static int
1121 1120 asyinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
1122 1121 void **result)
1123 1122 {
1124 1123 dev_t dev = (dev_t)arg;
1125 1124 int instance, error;
1126 1125 struct asycom *asy;
1127 1126
1128 1127 instance = UNIT(dev);
1129 1128
1130 1129 switch (infocmd) {
1131 1130 case DDI_INFO_DEVT2DEVINFO:
1132 1131 asy = ddi_get_soft_state(asy_soft_state, instance);
1133 1132 if ((asy == NULL) || (asy->asy_dip == NULL))
1134 1133 error = DDI_FAILURE;
1135 1134 else {
1136 1135 *result = (void *) asy->asy_dip;
1137 1136 error = DDI_SUCCESS;
1138 1137 }
1139 1138 break;
1140 1139 case DDI_INFO_DEVT2INSTANCE:
1141 1140 *result = (void *)(intptr_t)instance;
1142 1141 error = DDI_SUCCESS;
1143 1142 break;
1144 1143 default:
1145 1144 error = DDI_FAILURE;
1146 1145 }
1147 1146 return (error);
1148 1147 }
1149 1148
1150 1149 /* asy_getproperty -- walk through all name variants until we find a match */
1151 1150
1152 1151 static int
1153 1152 asy_getproperty(dev_info_t *devi, struct asycom *asy, const char *property)
1154 1153 {
1155 1154 int len;
1156 1155 int ret;
1157 1156 char letter = asy->asy_com_port + 'a' - 1; /* for ttya */
1158 1157 char number = asy->asy_com_port + '0'; /* for COM1 */
1159 1158 char val[40];
1160 1159 char name[40];
1161 1160
1162 1161 /* Property for ignoring DCD */
1163 1162 (void) sprintf(name, "tty%c-%s", letter, property);
1164 1163 len = sizeof (val);
1165 1164 ret = GET_PROP(devi, name, DDI_PROP_CANSLEEP, val, &len);
1166 1165 if (ret != DDI_PROP_SUCCESS) {
1167 1166 (void) sprintf(name, "com%c-%s", number, property);
1168 1167 len = sizeof (val);
1169 1168 ret = GET_PROP(devi, name, DDI_PROP_CANSLEEP, val, &len);
1170 1169 }
1171 1170 if (ret != DDI_PROP_SUCCESS) {
1172 1171 (void) sprintf(name, "tty0%c-%s", number, property);
1173 1172 len = sizeof (val);
1174 1173 ret = GET_PROP(devi, name, DDI_PROP_CANSLEEP, val, &len);
1175 1174 }
1176 1175 if (ret != DDI_PROP_SUCCESS) {
1177 1176 (void) sprintf(name, "port-%c-%s", letter, property);
1178 1177 len = sizeof (val);
1179 1178 ret = GET_PROP(devi, name, DDI_PROP_CANSLEEP, val, &len);
1180 1179 }
1181 1180 if (ret != DDI_PROP_SUCCESS)
1182 1181 return (-1); /* property non-existant */
1183 1182 if (val[0] == 'f' || val[0] == 'F' || val[0] == '0')
1184 1183 return (0); /* property false/0 */
1185 1184 return (1); /* property true/!0 */
1186 1185 }
1187 1186
1188 1187 /* asy_soft_state_free - local wrapper for ddi_soft_state_free(9F) */
1189 1188
1190 1189 static void
1191 1190 asy_soft_state_free(struct asycom *asy)
1192 1191 {
1193 1192 mutex_enter(&asy_glob_lock);
1194 1193 /* If we were the max_asy_instance, work out new value */
1195 1194 if (asy->asy_unit == max_asy_instance) {
1196 1195 while (--max_asy_instance >= 0) {
1197 1196 if (ddi_get_soft_state(asy_soft_state,
1198 1197 max_asy_instance) != NULL)
1199 1198 break;
1200 1199 }
1201 1200 }
1202 1201 mutex_exit(&asy_glob_lock);
1203 1202
1204 1203 if (asy->asy_priv != NULL) {
1205 1204 kmem_free(asy->asy_priv, sizeof (struct asyncline));
1206 1205 asy->asy_priv = NULL;
1207 1206 }
1208 1207 ddi_soft_state_free(asy_soft_state, asy->asy_unit);
1209 1208 }
1210 1209
1211 1210 static char *
1212 1211 asy_hw_name(struct asycom *asy)
1213 1212 {
1214 1213 switch (asy->asy_hwtype) {
1215 1214 case ASY8250A:
1216 1215 return ("8250A/16450");
1217 1216 case ASY16550:
1218 1217 return ("16550");
1219 1218 case ASY16550A:
1220 1219 return ("16550A");
1221 1220 case ASY16650:
1222 1221 return ("16650");
1223 1222 case ASY16750:
1224 1223 return ("16750");
1225 1224 default:
1226 1225 DEBUGNOTE2(ASY_DEBUG_INIT,
1227 1226 "asy%d: asy_hw_name: unknown asy_hwtype: %d",
1228 1227 asy->asy_unit, asy->asy_hwtype);
1229 1228 return ("?");
1230 1229 }
1231 1230 }
1232 1231
1233 1232 static int
1234 1233 asy_identify_chip(dev_info_t *devi, struct asycom *asy)
1235 1234 {
1236 1235 int ret;
1237 1236 int mcr;
1238 1237 dev_t dev;
1239 1238 uint_t hwtype;
1240 1239
1241 1240 if (asy_scr_test) {
1242 1241 /* Check scratch register works. */
1243 1242
1244 1243 /* write to scratch register */
1245 1244 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + SCR, SCRTEST);
1246 1245 /* make sure that pattern doesn't just linger on the bus */
1247 1246 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + FIFOR, 0x00);
1248 1247 /* read data back from scratch register */
1249 1248 ret = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + SCR);
1250 1249 if (ret != SCRTEST) {
1251 1250 /*
1252 1251 * Scratch register not working.
1253 1252 * Probably not an async chip.
1254 1253 * 8250 and 8250B don't have scratch registers,
1255 1254 * but only worked in ancient PC XT's anyway.
1256 1255 */
1257 1256 cmn_err(CE_CONT, "!asy%d: UART @ %p "
1258 1257 "scratch register: expected 0x5a, got 0x%02x\n",
1259 1258 asy->asy_unit, (void *)asy->asy_ioaddr, ret);
1260 1259 return (DDI_FAILURE);
1261 1260 }
1262 1261 }
1263 1262 /*
1264 1263 * Use 16550 fifo reset sequence specified in NS application
1265 1264 * note. Disable fifos until chip is initialized.
1266 1265 */
1267 1266 ddi_put8(asy->asy_iohandle,
1268 1267 asy->asy_ioaddr + FIFOR, 0x00); /* clear */
1269 1268 ddi_put8(asy->asy_iohandle,
1270 1269 asy->asy_ioaddr + FIFOR, FIFO_ON); /* enable */
1271 1270 ddi_put8(asy->asy_iohandle,
1272 1271 asy->asy_ioaddr + FIFOR, FIFO_ON | FIFORXFLSH);
1273 1272 /* reset */
1274 1273 if (asymaxchip >= ASY16650 && asy_scr_test) {
1275 1274 /*
1276 1275 * Reset 16650 enhanced regs also, in case we have one of these
1277 1276 */
1278 1277 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR,
1279 1278 EFRACCESS);
1280 1279 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + EFR,
1281 1280 0);
1282 1281 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR,
1283 1282 STOP1|BITS8);
1284 1283 }
1285 1284
1286 1285 /*
1287 1286 * See what sort of FIFO we have.
1288 1287 * Try enabling it and see what chip makes of this.
1289 1288 */
1290 1289
1291 1290 asy->asy_fifor = 0;
1292 1291 asy->asy_hwtype = asymaxchip; /* just for asy_reset_fifo() */
1293 1292 if (asymaxchip >= ASY16550A)
1294 1293 asy->asy_fifor |=
1295 1294 FIFO_ON | FIFODMA | (asy_trig_level & 0xff);
1296 1295 if (asymaxchip >= ASY16650)
1297 1296 asy->asy_fifor |= FIFOEXTRA1 | FIFOEXTRA2;
1298 1297
1299 1298 asy_reset_fifo(asy, FIFOTXFLSH | FIFORXFLSH);
1300 1299
1301 1300 mcr = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + MCR);
1302 1301 ret = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + ISR);
1303 1302 DEBUGCONT4(ASY_DEBUG_CHIP,
1304 1303 "asy%d: probe fifo FIFOR=0x%02x ISR=0x%02x MCR=0x%02x\n",
1305 1304 asy->asy_unit, asy->asy_fifor | FIFOTXFLSH | FIFORXFLSH,
1306 1305 ret, mcr);
1307 1306 switch (ret & 0xf0) {
1308 1307 case 0x40:
1309 1308 hwtype = ASY16550; /* 16550 with broken FIFO */
1310 1309 asy->asy_fifor = 0;
1311 1310 break;
1312 1311 case 0xc0:
1313 1312 hwtype = ASY16550A;
1314 1313 asy->asy_fifo_buf = 16;
1315 1314 asy->asy_use_fifo = FIFO_ON;
1316 1315 asy->asy_fifor &= ~(FIFOEXTRA1 | FIFOEXTRA2);
1317 1316 break;
1318 1317 case 0xe0:
1319 1318 hwtype = ASY16650;
1320 1319 asy->asy_fifo_buf = 32;
1321 1320 asy->asy_use_fifo = FIFO_ON;
1322 1321 asy->asy_fifor &= ~(FIFOEXTRA1);
1323 1322 break;
1324 1323 case 0xf0:
1325 1324 /*
1326 1325 * Note we get 0xff if chip didn't return us anything,
1327 1326 * e.g. if there's no chip there.
1328 1327 */
1329 1328 if (ret == 0xff) {
1330 1329 cmn_err(CE_CONT, "asy%d: UART @ %p "
1331 1330 "interrupt register: got 0xff\n",
1332 1331 asy->asy_unit, (void *)asy->asy_ioaddr);
1333 1332 return (DDI_FAILURE);
1334 1333 }
1335 1334 /*FALLTHRU*/
1336 1335 case 0xd0:
1337 1336 hwtype = ASY16750;
1338 1337 asy->asy_fifo_buf = 64;
1339 1338 asy->asy_use_fifo = FIFO_ON;
1340 1339 break;
1341 1340 default:
1342 1341 hwtype = ASY8250A; /* No FIFO */
1343 1342 asy->asy_fifor = 0;
1344 1343 }
1345 1344
1346 1345 if (hwtype > asymaxchip) {
1347 1346 cmn_err(CE_CONT, "asy%d: UART @ %p "
1348 1347 "unexpected probe result: "
1349 1348 "FIFOR=0x%02x ISR=0x%02x MCR=0x%02x\n",
1350 1349 asy->asy_unit, (void *)asy->asy_ioaddr,
1351 1350 asy->asy_fifor | FIFOTXFLSH | FIFORXFLSH, ret, mcr);
1352 1351 return (DDI_FAILURE);
1353 1352 }
1354 1353
1355 1354 /*
1356 1355 * Now reset the FIFO operation appropriate for the chip type.
1357 1356 * Note we must call asy_reset_fifo() before any possible
1358 1357 * downgrade of the asy->asy_hwtype, or it may not disable
1359 1358 * the more advanced features we specifically want downgraded.
1360 1359 */
1361 1360 asy_reset_fifo(asy, 0);
1362 1361 asy->asy_hwtype = hwtype;
1363 1362
1364 1363 /*
1365 1364 * Check for Exar/Startech ST16C650, which will still look like a
1366 1365 * 16550A until we enable its enhanced mode.
1367 1366 */
1368 1367 if (asy->asy_hwtype == ASY16550A && asymaxchip >= ASY16650 &&
1369 1368 asy_scr_test) {
1370 1369 /* Enable enhanced mode register access */
1371 1370 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR,
1372 1371 EFRACCESS);
1373 1372 /* zero scratch register (not scratch register if enhanced) */
1374 1373 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + SCR, 0);
1375 1374 /* Disable enhanced mode register access */
1376 1375 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR,
1377 1376 STOP1|BITS8);
1378 1377 /* read back scratch register */
1379 1378 ret = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + SCR);
1380 1379 if (ret == SCRTEST) {
1381 1380 /* looks like we have an ST16650 -- enable it */
1382 1381 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR,
1383 1382 EFRACCESS);
1384 1383 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + EFR,
1385 1384 ENHENABLE);
1386 1385 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR,
1387 1386 STOP1|BITS8);
1388 1387 asy->asy_hwtype = ASY16650;
1389 1388 asy->asy_fifo_buf = 32;
1390 1389 asy->asy_fifor |= 0x10; /* 24 byte txfifo trigger */
1391 1390 asy_reset_fifo(asy, 0);
1392 1391 }
1393 1392 }
1394 1393
1395 1394 /*
1396 1395 * If we think we might have a FIFO larger than 16 characters,
1397 1396 * measure FIFO size and check it against expected.
1398 1397 */
1399 1398 if (asy_fifo_test > 0 &&
1400 1399 !(asy->asy_flags2 & ASY2_NO_LOOPBACK) &&
1401 1400 (asy->asy_fifo_buf > 16 ||
1402 1401 (asy_fifo_test > 1 && asy->asy_use_fifo == FIFO_ON) ||
1403 1402 ASY_DEBUG(ASY_DEBUG_CHIP))) {
1404 1403 int i;
1405 1404
1406 1405 /* Set baud rate to 57600 (fairly arbitrary choice) */
1407 1406 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR,
1408 1407 DLAB);
1409 1408 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + DAT,
1410 1409 asyspdtab[B57600] & 0xff);
1411 1410 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + ICR,
1412 1411 (asyspdtab[B57600] >> 8) & 0xff);
1413 1412 /* Set 8 bits, 1 stop bit */
1414 1413 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR,
1415 1414 STOP1|BITS8);
1416 1415 /* Set loopback mode */
1417 1416 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + MCR,
1418 1417 DTR | RTS | ASY_LOOP | OUT1 | OUT2);
1419 1418
1420 1419 /* Overfill fifo */
1421 1420 for (i = 0; i < asy->asy_fifo_buf * 2; i++) {
1422 1421 ddi_put8(asy->asy_iohandle,
1423 1422 asy->asy_ioaddr + DAT, i);
1424 1423 }
1425 1424 /*
1426 1425 * Now there's an interesting question here about which
1427 1426 * FIFO we're testing the size of, RX or TX. We just
1428 1427 * filled the TX FIFO much faster than it can empty,
1429 1428 * although it is possible one or two characters may
1430 1429 * have gone from it to the TX shift register.
1431 1430 * We wait for enough time for all the characters to
1432 1431 * move into the RX FIFO and any excess characters to
1433 1432 * have been lost, and then read all the RX FIFO. So
1434 1433 * the answer we finally get will be the size which is
1435 1434 * the MIN(RX FIFO,(TX FIFO + 1 or 2)). The critical
1436 1435 * one is actually the TX FIFO, because if we overfill
1437 1436 * it in normal operation, the excess characters are
1438 1437 * lost with no warning.
1439 1438 */
1440 1439 /*
1441 1440 * Wait for characters to move into RX FIFO.
1442 1441 * In theory, 200 * asy->asy_fifo_buf * 2 should be
1443 1442 * enough. However, in practice it isn't always, so we
1444 1443 * increase to 400 so some slow 16550A's finish, and we
1445 1444 * increase to 3 so we spot more characters coming back
1446 1445 * than we sent, in case that should ever happen.
1447 1446 */
1448 1447 delay(drv_usectohz(400 * asy->asy_fifo_buf * 3));
1449 1448
1450 1449 /* Now see how many characters we can read back */
1451 1450 for (i = 0; i < asy->asy_fifo_buf * 3; i++) {
1452 1451 ret = ddi_get8(asy->asy_iohandle,
1453 1452 asy->asy_ioaddr + LSR);
1454 1453 if (!(ret & RCA))
1455 1454 break; /* FIFO emptied */
1456 1455 (void) ddi_get8(asy->asy_iohandle,
1457 1456 asy->asy_ioaddr + DAT); /* lose another */
1458 1457 }
1459 1458
1460 1459 DEBUGCONT3(ASY_DEBUG_CHIP,
1461 1460 "asy%d FIFO size: expected=%d, measured=%d\n",
1462 1461 asy->asy_unit, asy->asy_fifo_buf, i);
1463 1462
1464 1463 hwtype = asy->asy_hwtype;
1465 1464 if (i < asy->asy_fifo_buf) {
1466 1465 /*
1467 1466 * FIFO is somewhat smaller than we anticipated.
1468 1467 * If we have 16 characters usable, then this
1469 1468 * UART will probably work well enough in
1470 1469 * 16550A mode. If less than 16 characters,
1471 1470 * then we'd better not use it at all.
1472 1471 * UARTs with busted FIFOs do crop up.
1473 1472 */
1474 1473 if (i >= 16 && asy->asy_fifo_buf >= 16) {
1475 1474 /* fall back to a 16550A */
1476 1475 hwtype = ASY16550A;
1477 1476 asy->asy_fifo_buf = 16;
1478 1477 asy->asy_fifor &= ~(FIFOEXTRA1 | FIFOEXTRA2);
1479 1478 } else {
1480 1479 /* fall back to no FIFO at all */
1481 1480 hwtype = ASY16550;
1482 1481 asy->asy_fifo_buf = 1;
1483 1482 asy->asy_use_fifo = FIFO_OFF;
1484 1483 asy->asy_fifor &=
1485 1484 ~(FIFO_ON | FIFOEXTRA1 | FIFOEXTRA2);
1486 1485 }
1487 1486 }
1488 1487 /*
1489 1488 * We will need to reprogram the FIFO if we changed
1490 1489 * our mind about how to drive it above, and in any
1491 1490 * case, it would be a good idea to flush any garbage
1492 1491 * out incase the loopback test left anything behind.
1493 1492 * Again as earlier above, we must call asy_reset_fifo()
1494 1493 * before any possible downgrade of asy->asy_hwtype.
1495 1494 */
1496 1495 if (asy->asy_hwtype >= ASY16650 && hwtype < ASY16650) {
1497 1496 /* Disable 16650 enhanced mode */
1498 1497 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR,
1499 1498 EFRACCESS);
1500 1499 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + EFR,
1501 1500 0);
1502 1501 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR,
1503 1502 STOP1|BITS8);
1504 1503 }
1505 1504 asy_reset_fifo(asy, FIFOTXFLSH | FIFORXFLSH);
1506 1505 asy->asy_hwtype = hwtype;
1507 1506
1508 1507 /* Clear loopback mode and restore DTR/RTS */
1509 1508 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + MCR, mcr);
1510 1509 }
1511 1510
1512 1511 DEBUGNOTE3(ASY_DEBUG_CHIP, "asy%d %s @ %p",
1513 1512 asy->asy_unit, asy_hw_name(asy), (void *)asy->asy_ioaddr);
1514 1513
1515 1514 /* Make UART type visible in device tree for prtconf, etc */
1516 1515 dev = makedevice(DDI_MAJOR_T_UNKNOWN, asy->asy_unit);
1517 1516 (void) ddi_prop_update_string(dev, devi, "uart", asy_hw_name(asy));
1518 1517
1519 1518 if (asy->asy_hwtype == ASY16550) /* for broken 16550's, */
1520 1519 asy->asy_hwtype = ASY8250A; /* drive them as 8250A */
1521 1520
1522 1521 return (DDI_SUCCESS);
1523 1522 }
1524 1523
1525 1524 /*
1526 1525 * asyinit() initializes the TTY protocol-private data for this channel
1527 1526 * before enabling the interrupts.
1528 1527 */
1529 1528 static void
1530 1529 asyinit(struct asycom *asy)
1531 1530 {
1532 1531 struct asyncline *async;
1533 1532
1534 1533 asy->asy_priv = kmem_zalloc(sizeof (struct asyncline), KM_SLEEP);
1535 1534 async = asy->asy_priv;
1536 1535 mutex_enter(&asy->asy_excl);
1537 1536 async->async_common = asy;
1538 1537 cv_init(&async->async_flags_cv, NULL, CV_DRIVER, NULL);
1539 1538 mutex_exit(&asy->asy_excl);
1540 1539 }
1541 1540
1542 1541 /*ARGSUSED3*/
1543 1542 static int
1544 1543 asyopen(queue_t *rq, dev_t *dev, int flag, int sflag, cred_t *cr)
1545 1544 {
1546 1545 struct asycom *asy;
1547 1546 struct asyncline *async;
1548 1547 int mcr;
1549 1548 int unit;
1550 1549 int len;
1551 1550 struct termios *termiosp;
1552 1551
1553 1552 unit = UNIT(*dev);
1554 1553 DEBUGCONT1(ASY_DEBUG_CLOSE, "asy%dopen\n", unit);
1555 1554 asy = ddi_get_soft_state(asy_soft_state, unit);
1556 1555 if (asy == NULL)
1557 1556 return (ENXIO); /* unit not configured */
1558 1557 async = asy->asy_priv;
1559 1558 mutex_enter(&asy->asy_excl);
1560 1559
1561 1560 again:
1562 1561 mutex_enter(&asy->asy_excl_hi);
1563 1562
1564 1563 /*
1565 1564 * Block waiting for carrier to come up, unless this is a no-delay open.
1566 1565 */
1567 1566 if (!(async->async_flags & ASYNC_ISOPEN)) {
1568 1567 /*
1569 1568 * Set the default termios settings (cflag).
1570 1569 * Others are set in ldterm.
1571 1570 */
1572 1571 mutex_exit(&asy->asy_excl_hi);
1573 1572
1574 1573 if (ddi_getlongprop(DDI_DEV_T_ANY, ddi_root_node(),
1575 1574 0, "ttymodes",
1576 1575 (caddr_t)&termiosp, &len) == DDI_PROP_SUCCESS &&
1577 1576 len == sizeof (struct termios)) {
1578 1577 async->async_ttycommon.t_cflag = termiosp->c_cflag;
1579 1578 kmem_free(termiosp, len);
1580 1579 } else
1581 1580 cmn_err(CE_WARN,
1582 1581 "asy: couldn't get ttymodes property!");
1583 1582 mutex_enter(&asy->asy_excl_hi);
1584 1583
1585 1584 /* eeprom mode support - respect properties */
1586 1585 if (asy->asy_cflag)
1587 1586 async->async_ttycommon.t_cflag = asy->asy_cflag;
1588 1587
1589 1588 async->async_ttycommon.t_iflag = 0;
1590 1589 async->async_ttycommon.t_iocpending = NULL;
1591 1590 async->async_ttycommon.t_size.ws_row = 0;
1592 1591 async->async_ttycommon.t_size.ws_col = 0;
1593 1592 async->async_ttycommon.t_size.ws_xpixel = 0;
1594 1593 async->async_ttycommon.t_size.ws_ypixel = 0;
1595 1594 async->async_dev = *dev;
1596 1595 async->async_wbufcid = 0;
1597 1596
1598 1597 async->async_startc = CSTART;
1599 1598 async->async_stopc = CSTOP;
1600 1599 asy_program(asy, ASY_INIT);
1601 1600 } else
1602 1601 if ((async->async_ttycommon.t_flags & TS_XCLUDE) &&
1603 1602 secpolicy_excl_open(cr) != 0) {
1604 1603 mutex_exit(&asy->asy_excl_hi);
1605 1604 mutex_exit(&asy->asy_excl);
1606 1605 return (EBUSY);
1607 1606 } else if ((*dev & OUTLINE) && !(async->async_flags & ASYNC_OUT)) {
1608 1607 mutex_exit(&asy->asy_excl_hi);
1609 1608 mutex_exit(&asy->asy_excl);
1610 1609 return (EBUSY);
1611 1610 }
1612 1611
1613 1612 if (*dev & OUTLINE)
1614 1613 async->async_flags |= ASYNC_OUT;
1615 1614
1616 1615 /* Raise DTR on every open, but delay if it was just lowered. */
1617 1616 while (async->async_flags & ASYNC_DTR_DELAY) {
1618 1617 DEBUGCONT1(ASY_DEBUG_MODEM,
1619 1618 "asy%dopen: waiting for the ASYNC_DTR_DELAY to be clear\n",
1620 1619 unit);
1621 1620 mutex_exit(&asy->asy_excl_hi);
1622 1621 if (cv_wait_sig(&async->async_flags_cv,
1623 1622 &asy->asy_excl) == 0) {
1624 1623 DEBUGCONT1(ASY_DEBUG_MODEM,
1625 1624 "asy%dopen: interrupted by signal, exiting\n",
1626 1625 unit);
1627 1626 mutex_exit(&asy->asy_excl);
1628 1627 return (EINTR);
1629 1628 }
1630 1629 mutex_enter(&asy->asy_excl_hi);
1631 1630 }
1632 1631
1633 1632 mcr = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + MCR);
1634 1633 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + MCR,
1635 1634 mcr|(asy->asy_mcr&DTR));
1636 1635
1637 1636 DEBUGCONT3(ASY_DEBUG_INIT,
1638 1637 "asy%dopen: \"Raise DTR on every open\": make mcr = %x, "
1639 1638 "make TS_SOFTCAR = %s\n",
1640 1639 unit, mcr|(asy->asy_mcr&DTR),
1641 1640 (asy->asy_flags & ASY_IGNORE_CD) ? "ON" : "OFF");
1642 1641
1643 1642 if (asy->asy_flags & ASY_IGNORE_CD) {
1644 1643 DEBUGCONT1(ASY_DEBUG_MODEM,
1645 1644 "asy%dopen: ASY_IGNORE_CD set, set TS_SOFTCAR\n",
1646 1645 unit);
1647 1646 async->async_ttycommon.t_flags |= TS_SOFTCAR;
1648 1647 }
1649 1648 else
1650 1649 async->async_ttycommon.t_flags &= ~TS_SOFTCAR;
1651 1650
1652 1651 /*
1653 1652 * Check carrier.
1654 1653 */
1655 1654 asy->asy_msr = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + MSR);
1656 1655 DEBUGCONT3(ASY_DEBUG_INIT, "asy%dopen: TS_SOFTCAR is %s, "
1657 1656 "MSR & DCD is %s\n",
1658 1657 unit,
1659 1658 (async->async_ttycommon.t_flags & TS_SOFTCAR) ? "set" : "clear",
1660 1659 (asy->asy_msr & DCD) ? "set" : "clear");
1661 1660
1662 1661 if (asy->asy_msr & DCD)
1663 1662 async->async_flags |= ASYNC_CARR_ON;
1664 1663 else
1665 1664 async->async_flags &= ~ASYNC_CARR_ON;
1666 1665 mutex_exit(&asy->asy_excl_hi);
1667 1666
1668 1667 /*
1669 1668 * If FNDELAY and FNONBLOCK are clear, block until carrier up.
1670 1669 * Quit on interrupt.
1671 1670 */
1672 1671 if (!(flag & (FNDELAY|FNONBLOCK)) &&
1673 1672 !(async->async_ttycommon.t_cflag & CLOCAL)) {
1674 1673 if ((!(async->async_flags & (ASYNC_CARR_ON|ASYNC_OUT)) &&
1675 1674 !(async->async_ttycommon.t_flags & TS_SOFTCAR)) ||
1676 1675 ((async->async_flags & ASYNC_OUT) &&
1677 1676 !(*dev & OUTLINE))) {
1678 1677 async->async_flags |= ASYNC_WOPEN;
1679 1678 if (cv_wait_sig(&async->async_flags_cv,
1680 1679 &asy->asy_excl) == B_FALSE) {
1681 1680 async->async_flags &= ~ASYNC_WOPEN;
1682 1681 mutex_exit(&asy->asy_excl);
1683 1682 return (EINTR);
1684 1683 }
1685 1684 async->async_flags &= ~ASYNC_WOPEN;
1686 1685 goto again;
1687 1686 }
1688 1687 } else if ((async->async_flags & ASYNC_OUT) && !(*dev & OUTLINE)) {
1689 1688 mutex_exit(&asy->asy_excl);
1690 1689 return (EBUSY);
1691 1690 }
1692 1691
1693 1692 async->async_ttycommon.t_readq = rq;
1694 1693 async->async_ttycommon.t_writeq = WR(rq);
1695 1694 rq->q_ptr = WR(rq)->q_ptr = (caddr_t)async;
1696 1695 mutex_exit(&asy->asy_excl);
1697 1696 /*
1698 1697 * Caution here -- qprocson sets the pointers that are used by canput
1699 1698 * called by async_softint. ASYNC_ISOPEN must *not* be set until those
1700 1699 * pointers are valid.
1701 1700 */
1702 1701 qprocson(rq);
1703 1702 async->async_flags |= ASYNC_ISOPEN;
1704 1703 async->async_polltid = 0;
1705 1704 DEBUGCONT1(ASY_DEBUG_INIT, "asy%dopen: done\n", unit);
1706 1705 return (0);
1707 1706 }
1708 1707
1709 1708 static void
1710 1709 async_progress_check(void *arg)
1711 1710 {
1712 1711 struct asyncline *async = arg;
1713 1712 struct asycom *asy = async->async_common;
1714 1713 mblk_t *bp;
1715 1714
1716 1715 /*
1717 1716 * We define "progress" as either waiting on a timed break or delay, or
1718 1717 * having had at least one transmitter interrupt. If none of these are
1719 1718 * true, then just terminate the output and wake up that close thread.
1720 1719 */
1721 1720 mutex_enter(&asy->asy_excl);
1722 1721 mutex_enter(&asy->asy_excl_hi);
1723 1722 if (!(async->async_flags & (ASYNC_BREAK|ASYNC_DELAY|ASYNC_PROGRESS))) {
1724 1723 async->async_ocnt = 0;
1725 1724 async->async_flags &= ~ASYNC_BUSY;
1726 1725 async->async_timer = 0;
1727 1726 bp = async->async_xmitblk;
1728 1727 async->async_xmitblk = NULL;
1729 1728 mutex_exit(&asy->asy_excl_hi);
1730 1729 if (bp != NULL)
1731 1730 freeb(bp);
1732 1731 /*
1733 1732 * Since this timer is running, we know that we're in exit(2).
1734 1733 * That means that the user can't possibly be waiting on any
1735 1734 * valid ioctl(2) completion anymore, and we should just flush
1736 1735 * everything.
1737 1736 */
1738 1737 flushq(async->async_ttycommon.t_writeq, FLUSHALL);
1739 1738 cv_broadcast(&async->async_flags_cv);
1740 1739 } else {
1741 1740 async->async_flags &= ~ASYNC_PROGRESS;
1742 1741 async->async_timer = timeout(async_progress_check, async,
1743 1742 drv_usectohz(asy_drain_check));
1744 1743 mutex_exit(&asy->asy_excl_hi);
1745 1744 }
1746 1745 mutex_exit(&asy->asy_excl);
1747 1746 }
1748 1747
1749 1748 /*
1750 1749 * Release DTR so that asyopen() can raise it.
1751 1750 */
1752 1751 static void
1753 1752 async_dtr_free(struct asyncline *async)
1754 1753 {
1755 1754 struct asycom *asy = async->async_common;
1756 1755
1757 1756 DEBUGCONT0(ASY_DEBUG_MODEM,
1758 1757 "async_dtr_free, clearing ASYNC_DTR_DELAY\n");
1759 1758 mutex_enter(&asy->asy_excl);
1760 1759 async->async_flags &= ~ASYNC_DTR_DELAY;
1761 1760 async->async_dtrtid = 0;
1762 1761 cv_broadcast(&async->async_flags_cv);
1763 1762 mutex_exit(&asy->asy_excl);
1764 1763 }
1765 1764
1766 1765 /*
1767 1766 * Close routine.
1768 1767 */
1769 1768 /*ARGSUSED2*/
1770 1769 static int
1771 1770 asyclose(queue_t *q, int flag, cred_t *credp)
1772 1771 {
1773 1772 struct asyncline *async;
1774 1773 struct asycom *asy;
1775 1774 int icr, lcr;
1776 1775 #ifdef DEBUG
1777 1776 int instance;
1778 1777 #endif
1779 1778
1780 1779 async = (struct asyncline *)q->q_ptr;
1781 1780 ASSERT(async != NULL);
1782 1781 #ifdef DEBUG
1783 1782 instance = UNIT(async->async_dev);
1784 1783 DEBUGCONT1(ASY_DEBUG_CLOSE, "asy%dclose\n", instance);
1785 1784 #endif
1786 1785 asy = async->async_common;
1787 1786
1788 1787 mutex_enter(&asy->asy_excl);
1789 1788 async->async_flags |= ASYNC_CLOSING;
1790 1789
1791 1790 /*
1792 1791 * Turn off PPS handling early to avoid events occuring during
1793 1792 * close. Also reset the DCD edge monitoring bit.
1794 1793 */
1795 1794 mutex_enter(&asy->asy_excl_hi);
1796 1795 asy->asy_flags &= ~(ASY_PPS | ASY_PPS_EDGE);
1797 1796 mutex_exit(&asy->asy_excl_hi);
1798 1797
1799 1798 /*
1800 1799 * There are two flavors of break -- timed (M_BREAK or TCSBRK) and
1801 1800 * untimed (TIOCSBRK). For the timed case, these are enqueued on our
1802 1801 * write queue and there's a timer running, so we don't have to worry
1803 1802 * about them. For the untimed case, though, the user obviously made a
1804 1803 * mistake, because these are handled immediately. We'll terminate the
1805 1804 * break now and honor his implicit request by discarding the rest of
1806 1805 * the data.
1807 1806 */
1808 1807 if (async->async_flags & ASYNC_OUT_SUSPEND) {
1809 1808 if (async->async_utbrktid != 0) {
1810 1809 (void) untimeout(async->async_utbrktid);
1811 1810 async->async_utbrktid = 0;
1812 1811 }
1813 1812 mutex_enter(&asy->asy_excl_hi);
1814 1813 lcr = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + LCR);
1815 1814 ddi_put8(asy->asy_iohandle,
1816 1815 asy->asy_ioaddr + LCR, (lcr & ~SETBREAK));
1817 1816 mutex_exit(&asy->asy_excl_hi);
1818 1817 async->async_flags &= ~ASYNC_OUT_SUSPEND;
1819 1818 goto nodrain;
1820 1819 }
1821 1820
1822 1821 /*
1823 1822 * If the user told us not to delay the close ("non-blocking"), then
1824 1823 * don't bother trying to drain.
1825 1824 *
1826 1825 * If the user did M_STOP (ASYNC_STOPPED), there's no hope of ever
1827 1826 * getting an M_START (since these messages aren't enqueued), and the
1828 1827 * only other way to clear the stop condition is by loss of DCD, which
1829 1828 * would discard the queue data. Thus, we drop the output data if
1830 1829 * ASYNC_STOPPED is set.
1831 1830 */
1832 1831 if ((flag & (FNDELAY|FNONBLOCK)) ||
1833 1832 (async->async_flags & ASYNC_STOPPED)) {
1834 1833 goto nodrain;
1835 1834 }
1836 1835
1837 1836 /*
1838 1837 * If there's any pending output, then we have to try to drain it.
1839 1838 * There are two main cases to be handled:
1840 1839 * - called by close(2): need to drain until done or until
1841 1840 * a signal is received. No timeout.
1842 1841 * - called by exit(2): need to drain while making progress
1843 1842 * or until a timeout occurs. No signals.
1844 1843 *
1845 1844 * If we can't rely on receiving a signal to get us out of a hung
1846 1845 * session, then we have to use a timer. In this case, we set a timer
1847 1846 * to check for progress in sending the output data -- all that we ask
1848 1847 * (at each interval) is that there's been some progress made. Since
1849 1848 * the interrupt routine grabs buffers from the write queue, we can't
1850 1849 * trust changes in async_ocnt. Instead, we use a progress flag.
1851 1850 *
1852 1851 * Note that loss of carrier will cause the output queue to be flushed,
1853 1852 * and we'll wake up again and finish normally.
1854 1853 */
1855 1854 if (!ddi_can_receive_sig() && asy_drain_check != 0) {
1856 1855 async->async_flags &= ~ASYNC_PROGRESS;
1857 1856 async->async_timer = timeout(async_progress_check, async,
1858 1857 drv_usectohz(asy_drain_check));
1859 1858 }
1860 1859 while (async->async_ocnt > 0 ||
1861 1860 async->async_ttycommon.t_writeq->q_first != NULL ||
1862 1861 (async->async_flags & (ASYNC_BUSY|ASYNC_BREAK|ASYNC_DELAY))) {
1863 1862 if (cv_wait_sig(&async->async_flags_cv, &asy->asy_excl) == 0)
1864 1863 break;
1865 1864 }
1866 1865 if (async->async_timer != 0) {
1867 1866 (void) untimeout(async->async_timer);
1868 1867 async->async_timer = 0;
1869 1868 }
1870 1869
1871 1870 nodrain:
1872 1871 async->async_ocnt = 0;
1873 1872 if (async->async_xmitblk != NULL)
1874 1873 freeb(async->async_xmitblk);
1875 1874 async->async_xmitblk = NULL;
1876 1875
1877 1876 /*
1878 1877 * If line has HUPCL set or is incompletely opened fix up the modem
1879 1878 * lines.
1880 1879 */
1881 1880 DEBUGCONT1(ASY_DEBUG_MODEM, "asy%dclose: next check HUPCL flag\n",
1882 1881 instance);
1883 1882 mutex_enter(&asy->asy_excl_hi);
1884 1883 if ((async->async_ttycommon.t_cflag & HUPCL) ||
1885 1884 (async->async_flags & ASYNC_WOPEN)) {
1886 1885 DEBUGCONT3(ASY_DEBUG_MODEM,
1887 1886 "asy%dclose: HUPCL flag = %x, ASYNC_WOPEN flag = %x\n",
1888 1887 instance,
1889 1888 async->async_ttycommon.t_cflag & HUPCL,
1890 1889 async->async_ttycommon.t_cflag & ASYNC_WOPEN);
1891 1890 async->async_flags |= ASYNC_DTR_DELAY;
1892 1891
1893 1892 /* turn off DTR, RTS but NOT interrupt to 386 */
1894 1893 if (asy->asy_flags & (ASY_IGNORE_CD|ASY_RTS_DTR_OFF)) {
1895 1894 DEBUGCONT3(ASY_DEBUG_MODEM,
1896 1895 "asy%dclose: ASY_IGNORE_CD flag = %x, "
1897 1896 "ASY_RTS_DTR_OFF flag = %x\n",
1898 1897 instance,
1899 1898 asy->asy_flags & ASY_IGNORE_CD,
1900 1899 asy->asy_flags & ASY_RTS_DTR_OFF);
1901 1900
1902 1901 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + MCR,
1903 1902 asy->asy_mcr|OUT2);
1904 1903 } else {
1905 1904 DEBUGCONT1(ASY_DEBUG_MODEM,
1906 1905 "asy%dclose: Dropping DTR and RTS\n", instance);
1907 1906 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + MCR,
1908 1907 OUT2);
1909 1908 }
1910 1909 async->async_dtrtid =
1911 1910 timeout((void (*)())async_dtr_free,
1912 1911 (caddr_t)async, drv_usectohz(asy_min_dtr_low));
1913 1912 }
1914 1913 /*
1915 1914 * If nobody's using it now, turn off receiver interrupts.
1916 1915 */
1917 1916 if ((async->async_flags & (ASYNC_WOPEN|ASYNC_ISOPEN)) == 0) {
1918 1917 icr = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + ICR);
1919 1918 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + ICR,
1920 1919 (icr & ~RIEN));
1921 1920 }
1922 1921 mutex_exit(&asy->asy_excl_hi);
1923 1922 out:
1924 1923 ttycommon_close(&async->async_ttycommon);
1925 1924
1926 1925 /*
1927 1926 * Cancel outstanding "bufcall" request.
1928 1927 */
1929 1928 if (async->async_wbufcid != 0) {
1930 1929 unbufcall(async->async_wbufcid);
1931 1930 async->async_wbufcid = 0;
1932 1931 }
1933 1932
1934 1933 /* Note that qprocsoff can't be done until after interrupts are off */
1935 1934 qprocsoff(q);
1936 1935 q->q_ptr = WR(q)->q_ptr = NULL;
1937 1936 async->async_ttycommon.t_readq = NULL;
1938 1937 async->async_ttycommon.t_writeq = NULL;
1939 1938
1940 1939 /*
1941 1940 * Clear out device state, except persistant device property flags.
1942 1941 */
1943 1942 async->async_flags &= (ASYNC_DTR_DELAY|ASY_RTS_DTR_OFF);
1944 1943 cv_broadcast(&async->async_flags_cv);
1945 1944 mutex_exit(&asy->asy_excl);
1946 1945
1947 1946 DEBUGCONT1(ASY_DEBUG_CLOSE, "asy%dclose: done\n", instance);
1948 1947 return (0);
1949 1948 }
1950 1949
1951 1950 static boolean_t
1952 1951 asy_isbusy(struct asycom *asy)
1953 1952 {
1954 1953 struct asyncline *async;
1955 1954
1956 1955 DEBUGCONT0(ASY_DEBUG_EOT, "asy_isbusy\n");
1957 1956 async = asy->asy_priv;
1958 1957 ASSERT(mutex_owned(&asy->asy_excl));
1959 1958 ASSERT(mutex_owned(&asy->asy_excl_hi));
1960 1959 /*
1961 1960 * XXXX this should be recoded
1962 1961 */
1963 1962 return ((async->async_ocnt > 0) ||
1964 1963 ((ddi_get8(asy->asy_iohandle,
1965 1964 asy->asy_ioaddr + LSR) & (XSRE|XHRE)) == 0));
1966 1965 }
1967 1966
1968 1967 static void
1969 1968 asy_waiteot(struct asycom *asy)
1970 1969 {
1971 1970 /*
1972 1971 * Wait for the current transmission block and the
1973 1972 * current fifo data to transmit. Once this is done
1974 1973 * we may go on.
1975 1974 */
1976 1975 DEBUGCONT0(ASY_DEBUG_EOT, "asy_waiteot\n");
1977 1976 ASSERT(mutex_owned(&asy->asy_excl));
1978 1977 ASSERT(mutex_owned(&asy->asy_excl_hi));
1979 1978 while (asy_isbusy(asy)) {
1980 1979 mutex_exit(&asy->asy_excl_hi);
1981 1980 mutex_exit(&asy->asy_excl);
1982 1981 drv_usecwait(10000); /* wait .01 */
1983 1982 mutex_enter(&asy->asy_excl);
1984 1983 mutex_enter(&asy->asy_excl_hi);
1985 1984 }
1986 1985 }
1987 1986
1988 1987 /* asy_reset_fifo -- flush fifos and [re]program fifo control register */
1989 1988 static void
1990 1989 asy_reset_fifo(struct asycom *asy, uchar_t flush)
1991 1990 {
1992 1991 uchar_t lcr;
1993 1992
1994 1993 /* On a 16750, we have to set DLAB in order to set FIFOEXTRA. */
1995 1994
1996 1995 if (asy->asy_hwtype >= ASY16750) {
1997 1996 lcr = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + LCR);
1998 1997 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR,
1999 1998 lcr | DLAB);
2000 1999 }
2001 2000
2002 2001 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + FIFOR,
2003 2002 asy->asy_fifor | flush);
2004 2003
2005 2004 /* Clear DLAB */
2006 2005
2007 2006 if (asy->asy_hwtype >= ASY16750) {
2008 2007 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR, lcr);
2009 2008 }
2010 2009 }
2011 2010
2012 2011 /*
2013 2012 * Program the ASY port. Most of the async operation is based on the values
2014 2013 * of 'c_iflag' and 'c_cflag'.
2015 2014 */
2016 2015
2017 2016 #define BAUDINDEX(cflg) (((cflg) & CBAUDEXT) ? \
2018 2017 (((cflg) & CBAUD) + CBAUD + 1) : ((cflg) & CBAUD))
2019 2018
2020 2019 static void
2021 2020 asy_program(struct asycom *asy, int mode)
2022 2021 {
2023 2022 struct asyncline *async;
2024 2023 int baudrate, c_flag;
2025 2024 int icr, lcr;
2026 2025 int flush_reg;
2027 2026 int ocflags;
2028 2027 #ifdef DEBUG
2029 2028 int instance;
2030 2029 #endif
2031 2030
2032 2031 ASSERT(mutex_owned(&asy->asy_excl));
2033 2032 ASSERT(mutex_owned(&asy->asy_excl_hi));
2034 2033
2035 2034 async = asy->asy_priv;
2036 2035 #ifdef DEBUG
2037 2036 instance = UNIT(async->async_dev);
2038 2037 DEBUGCONT2(ASY_DEBUG_PROCS,
2039 2038 "asy%d_program: mode = 0x%08X, enter\n", instance, mode);
2040 2039 #endif
2041 2040
2042 2041 baudrate = BAUDINDEX(async->async_ttycommon.t_cflag);
2043 2042
2044 2043 async->async_ttycommon.t_cflag &= ~(CIBAUD);
2045 2044
2046 2045 if (baudrate > CBAUD) {
2047 2046 async->async_ttycommon.t_cflag |= CIBAUDEXT;
2048 2047 async->async_ttycommon.t_cflag |=
2049 2048 (((baudrate - CBAUD - 1) << IBSHIFT) & CIBAUD);
2050 2049 } else {
2051 2050 async->async_ttycommon.t_cflag &= ~CIBAUDEXT;
2052 2051 async->async_ttycommon.t_cflag |=
2053 2052 ((baudrate << IBSHIFT) & CIBAUD);
2054 2053 }
2055 2054
2056 2055 c_flag = async->async_ttycommon.t_cflag &
2057 2056 (CLOCAL|CREAD|CSTOPB|CSIZE|PARENB|PARODD|CBAUD|CBAUDEXT);
2058 2057
2059 2058 /* disable interrupts */
2060 2059 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + ICR, 0);
2061 2060
2062 2061 ocflags = asy->asy_ocflag;
2063 2062
2064 2063 /* flush/reset the status registers */
2065 2064 (void) ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + ISR);
2066 2065 (void) ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + LSR);
2067 2066 asy->asy_msr = flush_reg = ddi_get8(asy->asy_iohandle,
2068 2067 asy->asy_ioaddr + MSR);
2069 2068 /*
2070 2069 * The device is programmed in the open sequence, if we
2071 2070 * have to hardware handshake, then this is a good time
2072 2071 * to check if the device can receive any data.
2073 2072 */
2074 2073
2075 2074 if ((CRTSCTS & async->async_ttycommon.t_cflag) && !(flush_reg & CTS)) {
2076 2075 async_flowcontrol_hw_output(asy, FLOW_STOP);
2077 2076 } else {
2078 2077 /*
2079 2078 * We can not use async_flowcontrol_hw_output(asy, FLOW_START)
2080 2079 * here, because if CRTSCTS is clear, we need clear
2081 2080 * ASYNC_HW_OUT_FLW bit.
2082 2081 */
2083 2082 async->async_flags &= ~ASYNC_HW_OUT_FLW;
2084 2083 }
2085 2084
2086 2085 /*
2087 2086 * If IXON is not set, clear ASYNC_SW_OUT_FLW;
2088 2087 * If IXON is set, no matter what IXON flag is before this
2089 2088 * function call to asy_program,
2090 2089 * we will use the old ASYNC_SW_OUT_FLW status.
2091 2090 * Because of handling IXON in the driver, we also should re-calculate
2092 2091 * the value of ASYNC_OUT_FLW_RESUME bit, but in fact,
2093 2092 * the TCSET* commands which call asy_program
2094 2093 * are put into the write queue, so there is no output needed to
2095 2094 * be resumed at this point.
2096 2095 */
2097 2096 if (!(IXON & async->async_ttycommon.t_iflag))
2098 2097 async->async_flags &= ~ASYNC_SW_OUT_FLW;
2099 2098
2100 2099 /* manually flush receive buffer or fifo (workaround for buggy fifos) */
2101 2100 if (mode == ASY_INIT)
2102 2101 if (asy->asy_use_fifo == FIFO_ON) {
2103 2102 for (flush_reg = asy->asy_fifo_buf; flush_reg-- > 0; ) {
2104 2103 (void) ddi_get8(asy->asy_iohandle,
2105 2104 asy->asy_ioaddr + DAT);
2106 2105 }
2107 2106 } else {
2108 2107 flush_reg = ddi_get8(asy->asy_iohandle,
2109 2108 asy->asy_ioaddr + DAT);
2110 2109 }
2111 2110
2112 2111 if (ocflags != (c_flag & ~CLOCAL) || mode == ASY_INIT) {
2113 2112 /* Set line control */
2114 2113 lcr = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + LCR);
2115 2114 lcr &= ~(WLS0|WLS1|STB|PEN|EPS);
2116 2115
2117 2116 if (c_flag & CSTOPB)
2118 2117 lcr |= STB; /* 2 stop bits */
2119 2118
2120 2119 if (c_flag & PARENB)
2121 2120 lcr |= PEN;
2122 2121
2123 2122 if ((c_flag & PARODD) == 0)
2124 2123 lcr |= EPS;
2125 2124
2126 2125 switch (c_flag & CSIZE) {
2127 2126 case CS5:
2128 2127 lcr |= BITS5;
2129 2128 break;
2130 2129 case CS6:
2131 2130 lcr |= BITS6;
2132 2131 break;
2133 2132 case CS7:
2134 2133 lcr |= BITS7;
2135 2134 break;
2136 2135 case CS8:
2137 2136 lcr |= BITS8;
2138 2137 break;
2139 2138 }
2140 2139
2141 2140 /* set the baud rate, unless it is "0" */
2142 2141 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR, DLAB);
2143 2142
2144 2143 if (baudrate != 0) {
2145 2144 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + DAT,
2146 2145 asyspdtab[baudrate] & 0xff);
2147 2146 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + ICR,
2148 2147 (asyspdtab[baudrate] >> 8) & 0xff);
2149 2148 }
2150 2149 /* set the line control modes */
2151 2150 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR, lcr);
2152 2151
2153 2152 /*
2154 2153 * If we have a FIFO buffer, enable/flush
2155 2154 * at intialize time, flush if transitioning from
2156 2155 * CREAD off to CREAD on.
2157 2156 */
2158 2157 if ((ocflags & CREAD) == 0 && (c_flag & CREAD) ||
2159 2158 mode == ASY_INIT)
2160 2159 if (asy->asy_use_fifo == FIFO_ON)
2161 2160 asy_reset_fifo(asy, FIFORXFLSH);
2162 2161
2163 2162 /* remember the new cflags */
2164 2163 asy->asy_ocflag = c_flag & ~CLOCAL;
2165 2164 }
2166 2165
2167 2166 if (baudrate == 0)
2168 2167 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + MCR,
2169 2168 (asy->asy_mcr & RTS) | OUT2);
2170 2169 else
2171 2170 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + MCR,
2172 2171 asy->asy_mcr | OUT2);
2173 2172
2174 2173 /*
2175 2174 * Call the modem status interrupt handler to check for the carrier
2176 2175 * in case CLOCAL was turned off after the carrier came on.
2177 2176 * (Note: Modem status interrupt is not enabled if CLOCAL is ON.)
2178 2177 */
2179 2178 async_msint(asy);
2180 2179
2181 2180 /* Set interrupt control */
2182 2181 DEBUGCONT3(ASY_DEBUG_MODM2,
2183 2182 "asy%d_program: c_flag & CLOCAL = %x t_cflag & CRTSCTS = %x\n",
2184 2183 instance, c_flag & CLOCAL,
2185 2184 async->async_ttycommon.t_cflag & CRTSCTS);
2186 2185
2187 2186 if ((c_flag & CLOCAL) && !(async->async_ttycommon.t_cflag & CRTSCTS))
2188 2187 /*
2189 2188 * direct-wired line ignores DCD, so we don't enable modem
2190 2189 * status interrupts.
2191 2190 */
2192 2191 icr = (TIEN | SIEN);
2193 2192 else
2194 2193 icr = (TIEN | SIEN | MIEN);
2195 2194
2196 2195 if (c_flag & CREAD)
2197 2196 icr |= RIEN;
2198 2197
2199 2198 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + ICR, icr);
2200 2199 DEBUGCONT1(ASY_DEBUG_PROCS, "asy%d_program: done\n", instance);
2201 2200 }
2202 2201
2203 2202 static boolean_t
2204 2203 asy_baudok(struct asycom *asy)
2205 2204 {
2206 2205 struct asyncline *async = asy->asy_priv;
2207 2206 int baudrate;
2208 2207
2209 2208
2210 2209 baudrate = BAUDINDEX(async->async_ttycommon.t_cflag);
2211 2210
2212 2211 if (baudrate >= sizeof (asyspdtab)/sizeof (*asyspdtab))
2213 2212 return (0);
2214 2213
2215 2214 return (baudrate == 0 || asyspdtab[baudrate]);
2216 2215 }
2217 2216
2218 2217 /*
2219 2218 * asyintr() is the High Level Interrupt Handler.
2220 2219 *
2221 2220 * There are four different interrupt types indexed by ISR register values:
2222 2221 * 0: modem
2223 2222 * 1: Tx holding register is empty, ready for next char
2224 2223 * 2: Rx register now holds a char to be picked up
2225 2224 * 3: error or break on line
2226 2225 * This routine checks the Bit 0 (interrupt-not-pending) to determine if
2227 2226 * the interrupt is from this port.
2228 2227 */
2229 2228 uint_t
2230 2229 asyintr(caddr_t argasy)
2231 2230 {
2232 2231 struct asycom *asy = (struct asycom *)argasy;
2233 2232 struct asyncline *async;
2234 2233 int ret_status = DDI_INTR_UNCLAIMED;
2235 2234 uchar_t interrupt_id, lsr;
2236 2235
2237 2236 interrupt_id = ddi_get8(asy->asy_iohandle,
2238 2237 asy->asy_ioaddr + ISR) & 0x0F;
2239 2238 async = asy->asy_priv;
2240 2239
2241 2240 if ((async == NULL) ||
2242 2241 !(async->async_flags & (ASYNC_ISOPEN|ASYNC_WOPEN))) {
2243 2242 if (interrupt_id & NOINTERRUPT)
2244 2243 return (DDI_INTR_UNCLAIMED);
2245 2244 else {
2246 2245 /*
2247 2246 * reset the device by:
2248 2247 * reading line status
2249 2248 * reading any data from data status register
2250 2249 * reading modem status
2251 2250 */
2252 2251 (void) ddi_get8(asy->asy_iohandle,
2253 2252 asy->asy_ioaddr + LSR);
2254 2253 (void) ddi_get8(asy->asy_iohandle,
2255 2254 asy->asy_ioaddr + DAT);
2256 2255 asy->asy_msr = ddi_get8(asy->asy_iohandle,
2257 2256 asy->asy_ioaddr + MSR);
2258 2257 return (DDI_INTR_CLAIMED);
2259 2258 }
2260 2259 }
2261 2260
2262 2261 mutex_enter(&asy->asy_excl_hi);
2263 2262
2264 2263 if (asy->asy_flags & ASY_DDI_SUSPENDED) {
2265 2264 mutex_exit(&asy->asy_excl_hi);
2266 2265 return (DDI_INTR_CLAIMED);
2267 2266 }
2268 2267
2269 2268 /*
2270 2269 * We will loop until the interrupt line is pulled low. asy
2271 2270 * interrupt is edge triggered.
2272 2271 */
2273 2272 /* CSTYLED */
2274 2273 for (;; interrupt_id =
2275 2274 (ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + ISR) & 0x0F)) {
2276 2275
2277 2276 if (interrupt_id & NOINTERRUPT)
2278 2277 break;
2279 2278 ret_status = DDI_INTR_CLAIMED;
2280 2279
2281 2280 DEBUGCONT1(ASY_DEBUG_INTR, "asyintr: interrupt_id = 0x%d\n",
2282 2281 interrupt_id);
2283 2282 lsr = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + LSR);
2284 2283 switch (interrupt_id) {
2285 2284 case RxRDY:
2286 2285 case RSTATUS:
2287 2286 case FFTMOUT:
2288 2287 /* receiver interrupt or receiver errors */
2289 2288 async_rxint(asy, lsr);
2290 2289 break;
2291 2290 case TxRDY:
2292 2291 /* transmit interrupt */
2293 2292 async_txint(asy);
2294 2293 continue;
2295 2294 case MSTATUS:
2296 2295 /* modem status interrupt */
2297 2296 async_msint(asy);
2298 2297 break;
2299 2298 }
2300 2299 if ((lsr & XHRE) && (async->async_flags & ASYNC_BUSY) &&
2301 2300 (async->async_ocnt > 0))
2302 2301 async_txint(asy);
2303 2302 }
2304 2303 mutex_exit(&asy->asy_excl_hi);
2305 2304 return (ret_status);
2306 2305 }
2307 2306
2308 2307 /*
2309 2308 * Transmitter interrupt service routine.
2310 2309 * If there is more data to transmit in the current pseudo-DMA block,
2311 2310 * send the next character if output is not stopped or draining.
2312 2311 * Otherwise, queue up a soft interrupt.
2313 2312 *
2314 2313 * XXX - Needs review for HW FIFOs.
2315 2314 */
2316 2315 static void
2317 2316 async_txint(struct asycom *asy)
2318 2317 {
2319 2318 struct asyncline *async = asy->asy_priv;
2320 2319 int fifo_len;
2321 2320
2322 2321 /*
2323 2322 * If ASYNC_BREAK or ASYNC_OUT_SUSPEND has been set, return to
2324 2323 * asyintr()'s context to claim the interrupt without performing
2325 2324 * any action. No character will be loaded into FIFO/THR until
2326 2325 * timed or untimed break is removed
2327 2326 */
2328 2327 if (async->async_flags & (ASYNC_BREAK|ASYNC_OUT_SUSPEND))
2329 2328 return;
2330 2329
2331 2330 fifo_len = asy->asy_fifo_buf; /* with FIFO buffers */
2332 2331 if (fifo_len > asy_max_tx_fifo)
2333 2332 fifo_len = asy_max_tx_fifo;
2334 2333
2335 2334 if (async_flowcontrol_sw_input(asy, FLOW_CHECK, IN_FLOW_NULL))
2336 2335 fifo_len--;
2337 2336
2338 2337 if (async->async_ocnt > 0 && fifo_len > 0 &&
2339 2338 !(async->async_flags &
2340 2339 (ASYNC_HW_OUT_FLW|ASYNC_SW_OUT_FLW|ASYNC_STOPPED))) {
2341 2340 while (fifo_len-- > 0 && async->async_ocnt-- > 0) {
2342 2341 ddi_put8(asy->asy_iohandle,
2343 2342 asy->asy_ioaddr + DAT, *async->async_optr++);
2344 2343 }
2345 2344 async->async_flags |= ASYNC_PROGRESS;
2346 2345 }
2347 2346
2348 2347 if (fifo_len <= 0)
2349 2348 return;
2350 2349
2351 2350 ASYSETSOFT(asy);
2352 2351 }
2353 2352
2354 2353 /*
2355 2354 * Interrupt on port: handle PPS event. This function is only called
2356 2355 * for a port on which PPS event handling has been enabled.
2357 2356 */
2358 2357 static void
2359 2358 asy_ppsevent(struct asycom *asy, int msr)
2360 2359 {
2361 2360 if (asy->asy_flags & ASY_PPS_EDGE) {
2362 2361 /* Have seen leading edge, now look for and record drop */
2363 2362 if ((msr & DCD) == 0)
2364 2363 asy->asy_flags &= ~ASY_PPS_EDGE;
2365 2364 /*
2366 2365 * Waiting for leading edge, look for rise; stamp event and
2367 2366 * calibrate kernel clock.
2368 2367 */
2369 2368 } else if (msr & DCD) {
2370 2369 /*
2371 2370 * This code captures a timestamp at the designated
2372 2371 * transition of the PPS signal (DCD asserted). The
2373 2372 * code provides a pointer to the timestamp, as well
2374 2373 * as the hardware counter value at the capture.
2375 2374 *
2376 2375 * Note: the kernel has nano based time values while
2377 2376 * NTP requires micro based, an in-line fast algorithm
2378 2377 * to convert nsec to usec is used here -- see hrt2ts()
2379 2378 * in common/os/timers.c for a full description.
2380 2379 */
2381 2380 struct timeval *tvp = &asy_ppsev.tv;
2382 2381 timestruc_t ts;
2383 2382 long nsec, usec;
2384 2383
2385 2384 asy->asy_flags |= ASY_PPS_EDGE;
2386 2385 LED_OFF;
2387 2386 gethrestime(&ts);
2388 2387 LED_ON;
2389 2388 nsec = ts.tv_nsec;
2390 2389 usec = nsec + (nsec >> 2);
2391 2390 usec = nsec + (usec >> 1);
2392 2391 usec = nsec + (usec >> 2);
2393 2392 usec = nsec + (usec >> 4);
2394 2393 usec = nsec - (usec >> 3);
2395 2394 usec = nsec + (usec >> 2);
2396 2395 usec = nsec + (usec >> 3);
2397 2396 usec = nsec + (usec >> 4);
2398 2397 usec = nsec + (usec >> 1);
2399 2398 usec = nsec + (usec >> 6);
2400 2399 tvp->tv_usec = usec >> 10;
2401 2400 tvp->tv_sec = ts.tv_sec;
2402 2401
2403 2402 ++asy_ppsev.serial;
2404 2403
2405 2404 /*
2406 2405 * Because the kernel keeps a high-resolution time,
2407 2406 * pass the current highres timestamp in tvp and zero
2408 2407 * in usec.
2409 2408 */
2410 2409 ddi_hardpps(tvp, 0);
2411 2410 }
2412 2411 }
2413 2412
2414 2413 /*
2415 2414 * Receiver interrupt: RxRDY interrupt, FIFO timeout interrupt or receive
2416 2415 * error interrupt.
2417 2416 * Try to put the character into the circular buffer for this line; if it
2418 2417 * overflows, indicate a circular buffer overrun. If this port is always
2419 2418 * to be serviced immediately, or the character is a STOP character, or
2420 2419 * more than 15 characters have arrived, queue up a soft interrupt to
2421 2420 * drain the circular buffer.
2422 2421 * XXX - needs review for hw FIFOs support.
2423 2422 */
2424 2423
2425 2424 static void
2426 2425 async_rxint(struct asycom *asy, uchar_t lsr)
2427 2426 {
2428 2427 struct asyncline *async = asy->asy_priv;
2429 2428 uchar_t c;
2430 2429 uint_t s, needsoft = 0;
2431 2430 tty_common_t *tp;
2432 2431 int looplim = asy->asy_fifo_buf * 2;
2433 2432
2434 2433 tp = &async->async_ttycommon;
2435 2434 if (!(tp->t_cflag & CREAD)) {
2436 2435 while (lsr & (RCA|PARERR|FRMERR|BRKDET|OVRRUN)) {
2437 2436 (void) (ddi_get8(asy->asy_iohandle,
2438 2437 asy->asy_ioaddr + DAT) & 0xff);
2439 2438 lsr = ddi_get8(asy->asy_iohandle,
2440 2439 asy->asy_ioaddr + LSR);
2441 2440 if (looplim-- < 0) /* limit loop */
2442 2441 break;
2443 2442 }
2444 2443 return; /* line is not open for read? */
2445 2444 }
2446 2445
2447 2446 while (lsr & (RCA|PARERR|FRMERR|BRKDET|OVRRUN)) {
2448 2447 c = 0;
2449 2448 s = 0; /* reset error status */
2450 2449 if (lsr & RCA) {
2451 2450 c = ddi_get8(asy->asy_iohandle,
2452 2451 asy->asy_ioaddr + DAT) & 0xff;
2453 2452
2454 2453 /*
2455 2454 * We handle XON/XOFF char if IXON is set,
2456 2455 * but if received char is _POSIX_VDISABLE,
2457 2456 * we left it to the up level module.
2458 2457 */
2459 2458 if (tp->t_iflag & IXON) {
2460 2459 if ((c == async->async_stopc) &&
2461 2460 (c != _POSIX_VDISABLE)) {
2462 2461 async_flowcontrol_sw_output(asy,
2463 2462 FLOW_STOP);
2464 2463 goto check_looplim;
2465 2464 } else if ((c == async->async_startc) &&
2466 2465 (c != _POSIX_VDISABLE)) {
2467 2466 async_flowcontrol_sw_output(asy,
2468 2467 FLOW_START);
2469 2468 needsoft = 1;
2470 2469 goto check_looplim;
2471 2470 }
2472 2471 if ((tp->t_iflag & IXANY) &&
2473 2472 (async->async_flags & ASYNC_SW_OUT_FLW)) {
2474 2473 async_flowcontrol_sw_output(asy,
2475 2474 FLOW_START);
2476 2475 needsoft = 1;
2477 2476 }
2478 2477 }
2479 2478 }
2480 2479
2481 2480 /*
2482 2481 * Check for character break sequence
2483 2482 */
2484 2483 if ((abort_enable == KIOCABORTALTERNATE) &&
2485 2484 (asy->asy_flags & ASY_CONSOLE)) {
2486 2485 if (abort_charseq_recognize(c))
2487 2486 abort_sequence_enter((char *)NULL);
2488 2487 }
2489 2488
2490 2489 /* Handle framing errors */
2491 2490 if (lsr & (PARERR|FRMERR|BRKDET|OVRRUN)) {
2492 2491 if (lsr & PARERR) {
2493 2492 if (tp->t_iflag & INPCK) /* parity enabled */
2494 2493 s |= PERROR;
2495 2494 }
2496 2495
2497 2496 if (lsr & (FRMERR|BRKDET))
2498 2497 s |= FRERROR;
2499 2498 if (lsr & OVRRUN) {
2500 2499 async->async_hw_overrun = 1;
2501 2500 s |= OVERRUN;
2502 2501 }
2503 2502 }
2504 2503
2505 2504 if (s == 0)
2506 2505 if ((tp->t_iflag & PARMRK) &&
2507 2506 !(tp->t_iflag & (IGNPAR|ISTRIP)) &&
2508 2507 (c == 0377))
2509 2508 if (RING_POK(async, 2)) {
2510 2509 RING_PUT(async, 0377);
2511 2510 RING_PUT(async, c);
2512 2511 } else
2513 2512 async->async_sw_overrun = 1;
2514 2513 else
2515 2514 if (RING_POK(async, 1))
2516 2515 RING_PUT(async, c);
2517 2516 else
2518 2517 async->async_sw_overrun = 1;
2519 2518 else
2520 2519 if (s & FRERROR) /* Handle framing errors */
2521 2520 if (c == 0)
2522 2521 if ((asy->asy_flags & ASY_CONSOLE) &&
2523 2522 (abort_enable !=
2524 2523 KIOCABORTALTERNATE))
2525 2524 abort_sequence_enter((char *)0);
2526 2525 else
2527 2526 async->async_break++;
2528 2527 else
2529 2528 if (RING_POK(async, 1))
2530 2529 RING_MARK(async, c, s);
2531 2530 else
2532 2531 async->async_sw_overrun = 1;
2533 2532 else /* Parity errors are handled by ldterm */
2534 2533 if (RING_POK(async, 1))
2535 2534 RING_MARK(async, c, s);
2536 2535 else
2537 2536 async->async_sw_overrun = 1;
2538 2537 check_looplim:
2539 2538 lsr = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + LSR);
2540 2539 if (looplim-- < 0) /* limit loop */
2541 2540 break;
2542 2541 }
2543 2542 if ((RING_CNT(async) > (RINGSIZE * 3)/4) &&
2544 2543 !(async->async_inflow_source & IN_FLOW_RINGBUFF)) {
2545 2544 async_flowcontrol_hw_input(asy, FLOW_STOP, IN_FLOW_RINGBUFF);
2546 2545 (void) async_flowcontrol_sw_input(asy, FLOW_STOP,
2547 2546 IN_FLOW_RINGBUFF);
2548 2547 }
2549 2548
2550 2549 if ((async->async_flags & ASYNC_SERVICEIMM) || needsoft ||
2551 2550 (RING_FRAC(async)) || (async->async_polltid == 0))
2552 2551 ASYSETSOFT(asy); /* need a soft interrupt */
2553 2552 }
2554 2553
2555 2554 /*
2556 2555 * Modem status interrupt.
2557 2556 *
2558 2557 * (Note: It is assumed that the MSR hasn't been read by asyintr().)
2559 2558 */
2560 2559
2561 2560 static void
2562 2561 async_msint(struct asycom *asy)
2563 2562 {
2564 2563 struct asyncline *async = asy->asy_priv;
2565 2564 int msr, t_cflag = async->async_ttycommon.t_cflag;
2566 2565 #ifdef DEBUG
2567 2566 int instance = UNIT(async->async_dev);
2568 2567 #endif
2569 2568
2570 2569 async_msint_retry:
2571 2570 /* this resets the interrupt */
2572 2571 msr = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + MSR);
2573 2572 DEBUGCONT10(ASY_DEBUG_STATE,
2574 2573 "async%d_msint call #%d:\n"
2575 2574 " transition: %3s %3s %3s %3s\n"
2576 2575 "current state: %3s %3s %3s %3s\n",
2577 2576 instance,
2578 2577 ++(asy->asy_msint_cnt),
2579 2578 (msr & DCTS) ? "DCTS" : " ",
2580 2579 (msr & DDSR) ? "DDSR" : " ",
2581 2580 (msr & DRI) ? "DRI " : " ",
2582 2581 (msr & DDCD) ? "DDCD" : " ",
2583 2582 (msr & CTS) ? "CTS " : " ",
2584 2583 (msr & DSR) ? "DSR " : " ",
2585 2584 (msr & RI) ? "RI " : " ",
2586 2585 (msr & DCD) ? "DCD " : " ");
2587 2586
2588 2587 /* If CTS status is changed, do H/W output flow control */
2589 2588 if ((t_cflag & CRTSCTS) && (((asy->asy_msr ^ msr) & CTS) != 0))
2590 2589 async_flowcontrol_hw_output(asy,
2591 2590 msr & CTS ? FLOW_START : FLOW_STOP);
2592 2591 /*
2593 2592 * Reading MSR resets the interrupt, we save the
2594 2593 * value of msr so that other functions could examine MSR by
2595 2594 * looking at asy_msr.
2596 2595 */
2597 2596 asy->asy_msr = (uchar_t)msr;
2598 2597
2599 2598 /* Handle PPS event */
2600 2599 if (asy->asy_flags & ASY_PPS)
2601 2600 asy_ppsevent(asy, msr);
2602 2601
2603 2602 async->async_ext++;
2604 2603 ASYSETSOFT(asy);
2605 2604 /*
2606 2605 * We will make sure that the modem status presented to us
2607 2606 * during the previous read has not changed. If the chip samples
2608 2607 * the modem status on the falling edge of the interrupt line,
2609 2608 * and uses this state as the base for detecting change of modem
2610 2609 * status, we would miss a change of modem status event that occured
2611 2610 * after we initiated a read MSR operation.
2612 2611 */
2613 2612 msr = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + MSR);
2614 2613 if (STATES(msr) != STATES(asy->asy_msr))
2615 2614 goto async_msint_retry;
2616 2615 }
2617 2616
2618 2617 /*
2619 2618 * Handle a second-stage interrupt.
2620 2619 */
2621 2620 /*ARGSUSED*/
2622 2621 uint_t
2623 2622 asysoftintr(caddr_t intarg)
2624 2623 {
2625 2624 struct asycom *asy = (struct asycom *)intarg;
2626 2625 struct asyncline *async;
2627 2626 int rv;
2628 2627 uint_t cc;
2629 2628
2630 2629 /*
2631 2630 * Test and clear soft interrupt.
2632 2631 */
2633 2632 mutex_enter(&asy->asy_soft_lock);
2634 2633 DEBUGCONT0(ASY_DEBUG_PROCS, "asysoftintr: enter\n");
2635 2634 rv = asy->asysoftpend;
2636 2635 if (rv != 0)
2637 2636 asy->asysoftpend = 0;
2638 2637 mutex_exit(&asy->asy_soft_lock);
2639 2638
2640 2639 if (rv) {
2641 2640 if (asy->asy_priv == NULL)
2642 2641 return (rv ? DDI_INTR_CLAIMED : DDI_INTR_UNCLAIMED);
2643 2642 async = (struct asyncline *)asy->asy_priv;
2644 2643 mutex_enter(&asy->asy_excl_hi);
2645 2644 if (asy->asy_flags & ASY_NEEDSOFT) {
2646 2645 asy->asy_flags &= ~ASY_NEEDSOFT;
2647 2646 mutex_exit(&asy->asy_excl_hi);
2648 2647 async_softint(asy);
2649 2648 mutex_enter(&asy->asy_excl_hi);
2650 2649 }
2651 2650
2652 2651 /*
2653 2652 * There are some instances where the softintr is not
2654 2653 * scheduled and hence not called. It so happens that
2655 2654 * causes the last few characters to be stuck in the
2656 2655 * ringbuffer. Hence, call the handler once again so
2657 2656 * the last few characters are cleared.
2658 2657 */
2659 2658 cc = RING_CNT(async);
2660 2659 mutex_exit(&asy->asy_excl_hi);
2661 2660 if (cc > 0)
2662 2661 (void) async_softint(asy);
2663 2662 }
2664 2663 return (rv ? DDI_INTR_CLAIMED : DDI_INTR_UNCLAIMED);
2665 2664 }
2666 2665
2667 2666 /*
2668 2667 * Handle a software interrupt.
2669 2668 */
2670 2669 static void
2671 2670 async_softint(struct asycom *asy)
2672 2671 {
2673 2672 struct asyncline *async = asy->asy_priv;
2674 2673 uint_t cc;
2675 2674 mblk_t *bp;
2676 2675 queue_t *q;
2677 2676 uchar_t val;
2678 2677 uchar_t c;
2679 2678 tty_common_t *tp;
2680 2679 int nb;
2681 2680 int instance = UNIT(async->async_dev);
2682 2681
2683 2682 DEBUGCONT1(ASY_DEBUG_PROCS, "async%d_softint\n", instance);
2684 2683 mutex_enter(&asy->asy_excl_hi);
2685 2684 if (asy->asy_flags & ASY_DOINGSOFT) {
2686 2685 asy->asy_flags |= ASY_DOINGSOFT_RETRY;
2687 2686 mutex_exit(&asy->asy_excl_hi);
2688 2687 return;
2689 2688 }
2690 2689 asy->asy_flags |= ASY_DOINGSOFT;
2691 2690 begin:
2692 2691 asy->asy_flags &= ~ASY_DOINGSOFT_RETRY;
2693 2692 mutex_exit(&asy->asy_excl_hi);
2694 2693 mutex_enter(&asy->asy_excl);
2695 2694 tp = &async->async_ttycommon;
2696 2695 q = tp->t_readq;
2697 2696 if (async->async_flags & ASYNC_OUT_FLW_RESUME) {
2698 2697 if (async->async_ocnt > 0) {
2699 2698 mutex_enter(&asy->asy_excl_hi);
2700 2699 async_resume(async);
2701 2700 mutex_exit(&asy->asy_excl_hi);
2702 2701 } else {
2703 2702 if (async->async_xmitblk)
2704 2703 freeb(async->async_xmitblk);
2705 2704 async->async_xmitblk = NULL;
2706 2705 async_start(async);
2707 2706 }
2708 2707 async->async_flags &= ~ASYNC_OUT_FLW_RESUME;
2709 2708 }
2710 2709 mutex_enter(&asy->asy_excl_hi);
2711 2710 if (async->async_ext) {
2712 2711 async->async_ext = 0;
2713 2712 /* check for carrier up */
2714 2713 DEBUGCONT3(ASY_DEBUG_MODM2,
2715 2714 "async%d_softint: asy_msr & DCD = %x, "
2716 2715 "tp->t_flags & TS_SOFTCAR = %x\n",
2717 2716 instance, asy->asy_msr & DCD, tp->t_flags & TS_SOFTCAR);
2718 2717
2719 2718 if (asy->asy_msr & DCD) {
2720 2719 /* carrier present */
2721 2720 if ((async->async_flags & ASYNC_CARR_ON) == 0) {
2722 2721 DEBUGCONT1(ASY_DEBUG_MODM2,
2723 2722 "async%d_softint: set ASYNC_CARR_ON\n",
2724 2723 instance);
2725 2724 async->async_flags |= ASYNC_CARR_ON;
2726 2725 if (async->async_flags & ASYNC_ISOPEN) {
2727 2726 mutex_exit(&asy->asy_excl_hi);
2728 2727 mutex_exit(&asy->asy_excl);
2729 2728 (void) putctl(q, M_UNHANGUP);
2730 2729 mutex_enter(&asy->asy_excl);
2731 2730 mutex_enter(&asy->asy_excl_hi);
2732 2731 }
2733 2732 cv_broadcast(&async->async_flags_cv);
2734 2733 }
2735 2734 } else {
2736 2735 if ((async->async_flags & ASYNC_CARR_ON) &&
2737 2736 !(tp->t_cflag & CLOCAL) &&
2738 2737 !(tp->t_flags & TS_SOFTCAR)) {
2739 2738 int flushflag;
2740 2739
2741 2740 DEBUGCONT1(ASY_DEBUG_MODEM,
2742 2741 "async%d_softint: carrier dropped, "
2743 2742 "so drop DTR\n",
2744 2743 instance);
2745 2744 /*
2746 2745 * Carrier went away.
2747 2746 * Drop DTR, abort any output in
2748 2747 * progress, indicate that output is
2749 2748 * not stopped, and send a hangup
2750 2749 * notification upstream.
2751 2750 */
2752 2751 val = ddi_get8(asy->asy_iohandle,
2753 2752 asy->asy_ioaddr + MCR);
2754 2753 ddi_put8(asy->asy_iohandle,
2755 2754 asy->asy_ioaddr + MCR, (val & ~DTR));
2756 2755
2757 2756 if (async->async_flags & ASYNC_BUSY) {
2758 2757 DEBUGCONT0(ASY_DEBUG_BUSY,
2759 2758 "async_softint: "
2760 2759 "Carrier dropped. "
2761 2760 "Clearing async_ocnt\n");
2762 2761 async->async_ocnt = 0;
2763 2762 } /* if */
2764 2763
2765 2764 async->async_flags &= ~ASYNC_STOPPED;
2766 2765 if (async->async_flags & ASYNC_ISOPEN) {
2767 2766 mutex_exit(&asy->asy_excl_hi);
2768 2767 mutex_exit(&asy->asy_excl);
2769 2768 (void) putctl(q, M_HANGUP);
2770 2769 mutex_enter(&asy->asy_excl);
2771 2770 DEBUGCONT1(ASY_DEBUG_MODEM,
2772 2771 "async%d_softint: "
2773 2772 "putctl(q, M_HANGUP)\n",
2774 2773 instance);
2775 2774 /*
2776 2775 * Flush FIFO buffers
2777 2776 * Any data left in there is invalid now
2778 2777 */
2779 2778 if (asy->asy_use_fifo == FIFO_ON)
2780 2779 asy_reset_fifo(asy, FIFOTXFLSH);
2781 2780 /*
2782 2781 * Flush our write queue if we have one.
2783 2782 * If we're in the midst of close, then
2784 2783 * flush everything. Don't leave stale
2785 2784 * ioctls lying about.
2786 2785 */
2787 2786 flushflag = (async->async_flags &
2788 2787 ASYNC_CLOSING) ? FLUSHALL :
2789 2788 FLUSHDATA;
2790 2789 flushq(tp->t_writeq, flushflag);
2791 2790
2792 2791 /* active msg */
2793 2792 bp = async->async_xmitblk;
2794 2793 if (bp != NULL) {
2795 2794 freeb(bp);
2796 2795 async->async_xmitblk = NULL;
2797 2796 }
2798 2797
2799 2798 mutex_enter(&asy->asy_excl_hi);
2800 2799 async->async_flags &= ~ASYNC_BUSY;
2801 2800 /*
2802 2801 * This message warns of Carrier loss
2803 2802 * with data left to transmit can hang
2804 2803 * the system.
2805 2804 */
2806 2805 DEBUGCONT0(ASY_DEBUG_MODEM,
2807 2806 "async_softint: Flushing to "
2808 2807 "prevent HUPCL hanging\n");
2809 2808 } /* if (ASYNC_ISOPEN) */
2810 2809 } /* if (ASYNC_CARR_ON && CLOCAL) */
2811 2810 async->async_flags &= ~ASYNC_CARR_ON;
2812 2811 cv_broadcast(&async->async_flags_cv);
2813 2812 } /* else */
2814 2813 } /* if (async->async_ext) */
2815 2814
2816 2815 mutex_exit(&asy->asy_excl_hi);
2817 2816
2818 2817 /*
2819 2818 * If data has been added to the circular buffer, remove
2820 2819 * it from the buffer, and send it up the stream if there's
2821 2820 * somebody listening. Try to do it 16 bytes at a time. If we
2822 2821 * have more than 16 bytes to move, move 16 byte chunks and
2823 2822 * leave the rest for next time around (maybe it will grow).
2824 2823 */
2825 2824 mutex_enter(&asy->asy_excl_hi);
2826 2825 if (!(async->async_flags & ASYNC_ISOPEN)) {
2827 2826 RING_INIT(async);
2828 2827 goto rv;
2829 2828 }
2830 2829 if ((cc = RING_CNT(async)) == 0)
2831 2830 goto rv;
2832 2831 mutex_exit(&asy->asy_excl_hi);
2833 2832
2834 2833 if (!canput(q)) {
2835 2834 mutex_enter(&asy->asy_excl_hi);
2836 2835 if (!(async->async_inflow_source & IN_FLOW_STREAMS)) {
2837 2836 async_flowcontrol_hw_input(asy, FLOW_STOP,
2838 2837 IN_FLOW_STREAMS);
2839 2838 (void) async_flowcontrol_sw_input(asy, FLOW_STOP,
2840 2839 IN_FLOW_STREAMS);
2841 2840 }
2842 2841 goto rv;
2843 2842 }
2844 2843 if (async->async_inflow_source & IN_FLOW_STREAMS) {
2845 2844 mutex_enter(&asy->asy_excl_hi);
2846 2845 async_flowcontrol_hw_input(asy, FLOW_START,
2847 2846 IN_FLOW_STREAMS);
2848 2847 (void) async_flowcontrol_sw_input(asy, FLOW_START,
2849 2848 IN_FLOW_STREAMS);
2850 2849 mutex_exit(&asy->asy_excl_hi);
2851 2850 }
2852 2851
2853 2852 DEBUGCONT2(ASY_DEBUG_INPUT, "async%d_softint: %d char(s) in queue.\n",
2854 2853 instance, cc);
2855 2854
2856 2855 if (!(bp = allocb(cc, BPRI_MED))) {
2857 2856 mutex_exit(&asy->asy_excl);
2858 2857 ttycommon_qfull(&async->async_ttycommon, q);
2859 2858 mutex_enter(&asy->asy_excl);
2860 2859 mutex_enter(&asy->asy_excl_hi);
2861 2860 goto rv;
2862 2861 }
2863 2862 mutex_enter(&asy->asy_excl_hi);
2864 2863 do {
2865 2864 if (RING_ERR(async, S_ERRORS)) {
2866 2865 RING_UNMARK(async);
2867 2866 c = RING_GET(async);
2868 2867 break;
2869 2868 } else
2870 2869 *bp->b_wptr++ = RING_GET(async);
2871 2870 } while (--cc);
2872 2871 mutex_exit(&asy->asy_excl_hi);
2873 2872 mutex_exit(&asy->asy_excl);
2874 2873 if (bp->b_wptr > bp->b_rptr) {
2875 2874 if (!canput(q)) {
2876 2875 asyerror(CE_NOTE, "asy%d: local queue full",
2877 2876 instance);
2878 2877 freemsg(bp);
2879 2878 } else
2880 2879 (void) putq(q, bp);
2881 2880 } else
2882 2881 freemsg(bp);
2883 2882 /*
2884 2883 * If we have a parity error, then send
2885 2884 * up an M_BREAK with the "bad"
2886 2885 * character as an argument. Let ldterm
2887 2886 * figure out what to do with the error.
2888 2887 */
2889 2888 if (cc) {
2890 2889 (void) putctl1(q, M_BREAK, c);
2891 2890 ASYSETSOFT(async->async_common); /* finish cc chars */
2892 2891 }
2893 2892 mutex_enter(&asy->asy_excl);
2894 2893 mutex_enter(&asy->asy_excl_hi);
2895 2894 rv:
2896 2895 if ((RING_CNT(async) < (RINGSIZE/4)) &&
2897 2896 (async->async_inflow_source & IN_FLOW_RINGBUFF)) {
2898 2897 async_flowcontrol_hw_input(asy, FLOW_START, IN_FLOW_RINGBUFF);
2899 2898 (void) async_flowcontrol_sw_input(asy, FLOW_START,
2900 2899 IN_FLOW_RINGBUFF);
2901 2900 }
2902 2901
2903 2902 /*
2904 2903 * If a transmission has finished, indicate that it's finished,
2905 2904 * and start that line up again.
2906 2905 */
2907 2906 if (async->async_break > 0) {
2908 2907 nb = async->async_break;
2909 2908 async->async_break = 0;
2910 2909 if (async->async_flags & ASYNC_ISOPEN) {
2911 2910 mutex_exit(&asy->asy_excl_hi);
2912 2911 mutex_exit(&asy->asy_excl);
2913 2912 for (; nb > 0; nb--)
2914 2913 (void) putctl(q, M_BREAK);
2915 2914 mutex_enter(&asy->asy_excl);
2916 2915 mutex_enter(&asy->asy_excl_hi);
2917 2916 }
2918 2917 }
2919 2918 if (async->async_ocnt <= 0 && (async->async_flags & ASYNC_BUSY)) {
2920 2919 DEBUGCONT2(ASY_DEBUG_BUSY,
2921 2920 "async%d_softint: Clearing ASYNC_BUSY. async_ocnt=%d\n",
2922 2921 instance,
2923 2922 async->async_ocnt);
2924 2923 async->async_flags &= ~ASYNC_BUSY;
2925 2924 mutex_exit(&asy->asy_excl_hi);
2926 2925 if (async->async_xmitblk)
2927 2926 freeb(async->async_xmitblk);
2928 2927 async->async_xmitblk = NULL;
2929 2928 async_start(async);
2930 2929 /*
2931 2930 * If the flag isn't set after doing the async_start above, we
2932 2931 * may have finished all the queued output. Signal any thread
2933 2932 * stuck in close.
2934 2933 */
2935 2934 if (!(async->async_flags & ASYNC_BUSY))
2936 2935 cv_broadcast(&async->async_flags_cv);
2937 2936 mutex_enter(&asy->asy_excl_hi);
2938 2937 }
2939 2938 /*
2940 2939 * A note about these overrun bits: all they do is *tell* someone
2941 2940 * about an error- They do not track multiple errors. In fact,
2942 2941 * you could consider them latched register bits if you like.
2943 2942 * We are only interested in printing the error message once for
2944 2943 * any cluster of overrun errrors.
2945 2944 */
2946 2945 if (async->async_hw_overrun) {
2947 2946 if (async->async_flags & ASYNC_ISOPEN) {
2948 2947 mutex_exit(&asy->asy_excl_hi);
2949 2948 mutex_exit(&asy->asy_excl);
2950 2949 asyerror(CE_NOTE, "asy%d: silo overflow", instance);
2951 2950 mutex_enter(&asy->asy_excl);
2952 2951 mutex_enter(&asy->asy_excl_hi);
2953 2952 }
2954 2953 async->async_hw_overrun = 0;
2955 2954 }
2956 2955 if (async->async_sw_overrun) {
2957 2956 if (async->async_flags & ASYNC_ISOPEN) {
2958 2957 mutex_exit(&asy->asy_excl_hi);
2959 2958 mutex_exit(&asy->asy_excl);
2960 2959 asyerror(CE_NOTE, "asy%d: ring buffer overflow",
2961 2960 instance);
2962 2961 mutex_enter(&asy->asy_excl);
2963 2962 mutex_enter(&asy->asy_excl_hi);
2964 2963 }
2965 2964 async->async_sw_overrun = 0;
2966 2965 }
2967 2966 if (asy->asy_flags & ASY_DOINGSOFT_RETRY) {
2968 2967 mutex_exit(&asy->asy_excl);
2969 2968 goto begin;
2970 2969 }
2971 2970 asy->asy_flags &= ~ASY_DOINGSOFT;
2972 2971 mutex_exit(&asy->asy_excl_hi);
2973 2972 mutex_exit(&asy->asy_excl);
2974 2973 DEBUGCONT1(ASY_DEBUG_PROCS, "async%d_softint: done\n", instance);
2975 2974 }
2976 2975
2977 2976 /*
2978 2977 * Restart output on a line after a delay or break timer expired.
2979 2978 */
2980 2979 static void
2981 2980 async_restart(void *arg)
2982 2981 {
2983 2982 struct asyncline *async = (struct asyncline *)arg;
2984 2983 struct asycom *asy = async->async_common;
2985 2984 uchar_t lcr;
2986 2985
2987 2986 /*
2988 2987 * If break timer expired, turn off the break bit.
2989 2988 */
2990 2989 #ifdef DEBUG
2991 2990 int instance = UNIT(async->async_dev);
2992 2991
2993 2992 DEBUGCONT1(ASY_DEBUG_PROCS, "async%d_restart\n", instance);
2994 2993 #endif
2995 2994 mutex_enter(&asy->asy_excl);
2996 2995 /*
2997 2996 * If ASYNC_OUT_SUSPEND is also set, we don't really
2998 2997 * clean the HW break, TIOCCBRK is responsible for this.
2999 2998 */
3000 2999 if ((async->async_flags & ASYNC_BREAK) &&
3001 3000 !(async->async_flags & ASYNC_OUT_SUSPEND)) {
3002 3001 mutex_enter(&asy->asy_excl_hi);
3003 3002 lcr = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + LCR);
3004 3003 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR,
3005 3004 (lcr & ~SETBREAK));
3006 3005 mutex_exit(&asy->asy_excl_hi);
3007 3006 }
3008 3007 async->async_flags &= ~(ASYNC_DELAY|ASYNC_BREAK);
3009 3008 cv_broadcast(&async->async_flags_cv);
3010 3009 async_start(async);
3011 3010
3012 3011 mutex_exit(&asy->asy_excl);
3013 3012 }
3014 3013
3015 3014 static void
3016 3015 async_start(struct asyncline *async)
3017 3016 {
3018 3017 async_nstart(async, 0);
3019 3018 }
3020 3019
3021 3020 /*
3022 3021 * Start output on a line, unless it's busy, frozen, or otherwise.
3023 3022 */
3024 3023 /*ARGSUSED*/
3025 3024 static void
3026 3025 async_nstart(struct asyncline *async, int mode)
3027 3026 {
3028 3027 struct asycom *asy = async->async_common;
3029 3028 int cc;
3030 3029 queue_t *q;
3031 3030 mblk_t *bp;
3032 3031 uchar_t *xmit_addr;
3033 3032 uchar_t val;
3034 3033 int fifo_len = 1;
3035 3034 boolean_t didsome;
3036 3035 mblk_t *nbp;
3037 3036
3038 3037 #ifdef DEBUG
3039 3038 int instance = UNIT(async->async_dev);
3040 3039
3041 3040 DEBUGCONT1(ASY_DEBUG_PROCS, "async%d_nstart\n", instance);
3042 3041 #endif
3043 3042 if (asy->asy_use_fifo == FIFO_ON) {
3044 3043 fifo_len = asy->asy_fifo_buf; /* with FIFO buffers */
3045 3044 if (fifo_len > asy_max_tx_fifo)
3046 3045 fifo_len = asy_max_tx_fifo;
3047 3046 }
3048 3047
3049 3048 ASSERT(mutex_owned(&asy->asy_excl));
3050 3049
3051 3050 /*
3052 3051 * If the chip is busy (i.e., we're waiting for a break timeout
3053 3052 * to expire, or for the current transmission to finish, or for
3054 3053 * output to finish draining from chip), don't grab anything new.
3055 3054 */
3056 3055 if (async->async_flags & (ASYNC_BREAK|ASYNC_BUSY)) {
3057 3056 DEBUGCONT2((mode? ASY_DEBUG_OUT : 0),
3058 3057 "async%d_nstart: start %s.\n",
3059 3058 instance,
3060 3059 async->async_flags & ASYNC_BREAK ? "break" : "busy");
3061 3060 return;
3062 3061 }
3063 3062
3064 3063 /*
3065 3064 * Check only pended sw input flow control.
3066 3065 */
3067 3066 mutex_enter(&asy->asy_excl_hi);
3068 3067 if (async_flowcontrol_sw_input(asy, FLOW_CHECK, IN_FLOW_NULL))
3069 3068 fifo_len--;
3070 3069 mutex_exit(&asy->asy_excl_hi);
3071 3070
3072 3071 /*
3073 3072 * If we're waiting for a delay timeout to expire, don't grab
3074 3073 * anything new.
3075 3074 */
3076 3075 if (async->async_flags & ASYNC_DELAY) {
3077 3076 DEBUGCONT1((mode? ASY_DEBUG_OUT : 0),
3078 3077 "async%d_nstart: start ASYNC_DELAY.\n", instance);
3079 3078 return;
3080 3079 }
3081 3080
3082 3081 if ((q = async->async_ttycommon.t_writeq) == NULL) {
3083 3082 DEBUGCONT1((mode? ASY_DEBUG_OUT : 0),
3084 3083 "async%d_nstart: start writeq is null.\n", instance);
3085 3084 return; /* not attached to a stream */
3086 3085 }
3087 3086
3088 3087 for (;;) {
3089 3088 if ((bp = getq(q)) == NULL)
3090 3089 return; /* no data to transmit */
3091 3090
3092 3091 /*
3093 3092 * We have a message block to work on.
3094 3093 * Check whether it's a break, a delay, or an ioctl (the latter
3095 3094 * occurs if the ioctl in question was waiting for the output
3096 3095 * to drain). If it's one of those, process it immediately.
3097 3096 */
3098 3097 switch (bp->b_datap->db_type) {
3099 3098
3100 3099 case M_BREAK:
3101 3100 /*
3102 3101 * Set the break bit, and arrange for "async_restart"
3103 3102 * to be called in 1/4 second; it will turn the
3104 3103 * break bit off, and call "async_start" to grab
3105 3104 * the next message.
3106 3105 */
3107 3106 mutex_enter(&asy->asy_excl_hi);
3108 3107 val = ddi_get8(asy->asy_iohandle,
3109 3108 asy->asy_ioaddr + LCR);
3110 3109 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR,
3111 3110 (val | SETBREAK));
3112 3111 mutex_exit(&asy->asy_excl_hi);
3113 3112 async->async_flags |= ASYNC_BREAK;
3114 3113 (void) timeout(async_restart, (caddr_t)async,
3115 3114 drv_usectohz(1000000)/4);
3116 3115 freemsg(bp);
3117 3116 return; /* wait for this to finish */
3118 3117
3119 3118 case M_DELAY:
3120 3119 /*
3121 3120 * Arrange for "async_restart" to be called when the
3122 3121 * delay expires; it will turn ASYNC_DELAY off,
3123 3122 * and call "async_start" to grab the next message.
3124 3123 */
3125 3124 (void) timeout(async_restart, (caddr_t)async,
3126 3125 (int)(*(unsigned char *)bp->b_rptr + 6));
3127 3126 async->async_flags |= ASYNC_DELAY;
3128 3127 freemsg(bp);
3129 3128 return; /* wait for this to finish */
3130 3129
3131 3130 case M_IOCTL:
3132 3131 /*
3133 3132 * This ioctl was waiting for the output ahead of
3134 3133 * it to drain; obviously, it has. Do it, and
3135 3134 * then grab the next message after it.
3136 3135 */
3137 3136 mutex_exit(&asy->asy_excl);
3138 3137 async_ioctl(async, q, bp);
3139 3138 mutex_enter(&asy->asy_excl);
3140 3139 continue;
3141 3140 }
3142 3141
3143 3142 while (bp != NULL && ((cc = MBLKL(bp)) == 0)) {
3144 3143 nbp = bp->b_cont;
3145 3144 freeb(bp);
3146 3145 bp = nbp;
3147 3146 }
3148 3147 if (bp != NULL)
3149 3148 break;
3150 3149 }
3151 3150
3152 3151 /*
3153 3152 * We have data to transmit. If output is stopped, put
3154 3153 * it back and try again later.
3155 3154 */
3156 3155 if (async->async_flags & (ASYNC_HW_OUT_FLW | ASYNC_SW_OUT_FLW |
3157 3156 ASYNC_STOPPED | ASYNC_OUT_SUSPEND)) {
3158 3157 (void) putbq(q, bp);
3159 3158 return;
3160 3159 }
3161 3160
3162 3161 async->async_xmitblk = bp;
3163 3162 xmit_addr = bp->b_rptr;
3164 3163 bp = bp->b_cont;
3165 3164 if (bp != NULL)
3166 3165 (void) putbq(q, bp); /* not done with this message yet */
3167 3166
3168 3167 /*
3169 3168 * In 5-bit mode, the high order bits are used
3170 3169 * to indicate character sizes less than five,
3171 3170 * so we need to explicitly mask before transmitting
3172 3171 */
3173 3172 if ((async->async_ttycommon.t_cflag & CSIZE) == CS5) {
3174 3173 unsigned char *p = xmit_addr;
3175 3174 int cnt = cc;
3176 3175
3177 3176 while (cnt--)
3178 3177 *p++ &= (unsigned char) 0x1f;
3179 3178 }
3180 3179
3181 3180 /*
3182 3181 * Set up this block for pseudo-DMA.
3183 3182 */
3184 3183 mutex_enter(&asy->asy_excl_hi);
3185 3184 /*
3186 3185 * If the transmitter is ready, shove the first
3187 3186 * character out.
3188 3187 */
3189 3188 didsome = B_FALSE;
3190 3189 while (--fifo_len >= 0 && cc > 0) {
3191 3190 if (!(ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + LSR) &
3192 3191 XHRE))
3193 3192 break;
3194 3193 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + DAT,
3195 3194 *xmit_addr++);
3196 3195 cc--;
3197 3196 didsome = B_TRUE;
3198 3197 }
3199 3198 async->async_optr = xmit_addr;
3200 3199 async->async_ocnt = cc;
3201 3200 if (didsome)
3202 3201 async->async_flags |= ASYNC_PROGRESS;
3203 3202 DEBUGCONT2(ASY_DEBUG_BUSY,
3204 3203 "async%d_nstart: Set ASYNC_BUSY. async_ocnt=%d\n",
3205 3204 instance, async->async_ocnt);
3206 3205 async->async_flags |= ASYNC_BUSY;
3207 3206 mutex_exit(&asy->asy_excl_hi);
3208 3207 }
3209 3208
3210 3209 /*
3211 3210 * Resume output by poking the transmitter.
3212 3211 */
3213 3212 static void
3214 3213 async_resume(struct asyncline *async)
3215 3214 {
3216 3215 struct asycom *asy = async->async_common;
3217 3216 #ifdef DEBUG
3218 3217 int instance;
3219 3218 #endif
3220 3219
3221 3220 ASSERT(mutex_owned(&asy->asy_excl_hi));
3222 3221 #ifdef DEBUG
3223 3222 instance = UNIT(async->async_dev);
3224 3223 DEBUGCONT1(ASY_DEBUG_PROCS, "async%d_resume\n", instance);
3225 3224 #endif
3226 3225
3227 3226 if (ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + LSR) & XHRE) {
3228 3227 if (async_flowcontrol_sw_input(asy, FLOW_CHECK, IN_FLOW_NULL))
3229 3228 return;
3230 3229 if (async->async_ocnt > 0 &&
3231 3230 !(async->async_flags &
3232 3231 (ASYNC_HW_OUT_FLW|ASYNC_SW_OUT_FLW|ASYNC_OUT_SUSPEND))) {
3233 3232 ddi_put8(asy->asy_iohandle,
3234 3233 asy->asy_ioaddr + DAT, *async->async_optr++);
3235 3234 async->async_ocnt--;
3236 3235 async->async_flags |= ASYNC_PROGRESS;
3237 3236 }
3238 3237 }
3239 3238 }
3240 3239
3241 3240 /*
3242 3241 * Hold the untimed break to last the minimum time.
3243 3242 */
3244 3243 static void
3245 3244 async_hold_utbrk(void *arg)
3246 3245 {
3247 3246 struct asyncline *async = arg;
3248 3247 struct asycom *asy = async->async_common;
3249 3248
3250 3249 mutex_enter(&asy->asy_excl);
3251 3250 async->async_flags &= ~ASYNC_HOLD_UTBRK;
3252 3251 cv_broadcast(&async->async_flags_cv);
3253 3252 async->async_utbrktid = 0;
3254 3253 mutex_exit(&asy->asy_excl);
3255 3254 }
3256 3255
3257 3256 /*
3258 3257 * Resume the untimed break.
3259 3258 */
3260 3259 static void
3261 3260 async_resume_utbrk(struct asyncline *async)
3262 3261 {
3263 3262 uchar_t val;
3264 3263 struct asycom *asy = async->async_common;
3265 3264 ASSERT(mutex_owned(&asy->asy_excl));
3266 3265
3267 3266 /*
3268 3267 * Because the wait time is very short,
3269 3268 * so we use uninterruptably wait.
3270 3269 */
3271 3270 while (async->async_flags & ASYNC_HOLD_UTBRK) {
3272 3271 cv_wait(&async->async_flags_cv, &asy->asy_excl);
3273 3272 }
3274 3273 mutex_enter(&asy->asy_excl_hi);
3275 3274 /*
3276 3275 * Timed break and untimed break can exist simultaneously,
3277 3276 * if ASYNC_BREAK is also set at here, we don't
3278 3277 * really clean the HW break.
3279 3278 */
3280 3279 if (!(async->async_flags & ASYNC_BREAK)) {
3281 3280 val = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + LCR);
3282 3281 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + LCR,
3283 3282 (val & ~SETBREAK));
3284 3283 }
3285 3284 async->async_flags &= ~ASYNC_OUT_SUSPEND;
3286 3285 cv_broadcast(&async->async_flags_cv);
3287 3286 if (async->async_ocnt > 0) {
3288 3287 async_resume(async);
3289 3288 mutex_exit(&asy->asy_excl_hi);
3290 3289 } else {
3291 3290 async->async_flags &= ~ASYNC_BUSY;
3292 3291 mutex_exit(&asy->asy_excl_hi);
3293 3292 if (async->async_xmitblk != NULL) {
3294 3293 freeb(async->async_xmitblk);
3295 3294 async->async_xmitblk = NULL;
3296 3295 }
3297 3296 async_start(async);
3298 3297 }
3299 3298 }
3300 3299
3301 3300 /*
3302 3301 * Process an "ioctl" message sent down to us.
3303 3302 * Note that we don't need to get any locks until we are ready to access
3304 3303 * the hardware. Nothing we access until then is going to be altered
3305 3304 * outside of the STREAMS framework, so we should be safe.
3306 3305 */
3307 3306 int asydelay = 10000;
3308 3307 static void
3309 3308 async_ioctl(struct asyncline *async, queue_t *wq, mblk_t *mp)
3310 3309 {
3311 3310 struct asycom *asy = async->async_common;
3312 3311 tty_common_t *tp = &async->async_ttycommon;
3313 3312 struct iocblk *iocp;
3314 3313 unsigned datasize;
3315 3314 int error = 0;
3316 3315 uchar_t val;
3317 3316 mblk_t *datamp;
3318 3317 unsigned int index;
3319 3318
3320 3319 #ifdef DEBUG
3321 3320 int instance = UNIT(async->async_dev);
3322 3321
3323 3322 DEBUGCONT1(ASY_DEBUG_PROCS, "async%d_ioctl\n", instance);
3324 3323 #endif
3325 3324
3326 3325 if (tp->t_iocpending != NULL) {
3327 3326 /*
3328 3327 * We were holding an "ioctl" response pending the
3329 3328 * availability of an "mblk" to hold data to be passed up;
3330 3329 * another "ioctl" came through, which means that "ioctl"
3331 3330 * must have timed out or been aborted.
3332 3331 */
3333 3332 freemsg(async->async_ttycommon.t_iocpending);
3334 3333 async->async_ttycommon.t_iocpending = NULL;
3335 3334 }
3336 3335
3337 3336 iocp = (struct iocblk *)mp->b_rptr;
3338 3337
3339 3338 /*
3340 3339 * For TIOCMGET and the PPS ioctls, do NOT call ttycommon_ioctl()
3341 3340 * because this function frees up the message block (mp->b_cont) that
3342 3341 * contains the user location where we pass back the results.
3343 3342 *
3344 3343 * Similarly, CONSOPENPOLLEDIO needs ioc_count, which ttycommon_ioctl
3345 3344 * zaps. We know that ttycommon_ioctl doesn't know any CONS*
3346 3345 * ioctls, so keep the others safe too.
3347 3346 */
3348 3347 DEBUGCONT2(ASY_DEBUG_IOCTL, "async%d_ioctl: %s\n",
3349 3348 instance,
3350 3349 iocp->ioc_cmd == TIOCMGET ? "TIOCMGET" :
3351 3350 iocp->ioc_cmd == TIOCMSET ? "TIOCMSET" :
3352 3351 iocp->ioc_cmd == TIOCMBIS ? "TIOCMBIS" :
3353 3352 iocp->ioc_cmd == TIOCMBIC ? "TIOCMBIC" :
3354 3353 "other");
3355 3354
3356 3355 switch (iocp->ioc_cmd) {
3357 3356 case TIOCMGET:
3358 3357 case TIOCGPPS:
3359 3358 case TIOCSPPS:
3360 3359 case TIOCGPPSEV:
3361 3360 case CONSOPENPOLLEDIO:
3362 3361 case CONSCLOSEPOLLEDIO:
3363 3362 case CONSSETABORTENABLE:
3364 3363 case CONSGETABORTENABLE:
3365 3364 error = -1; /* Do Nothing */
3366 3365 break;
3367 3366 default:
3368 3367
3369 3368 /*
3370 3369 * The only way in which "ttycommon_ioctl" can fail is if the
3371 3370 * "ioctl" requires a response containing data to be returned
3372 3371 * to the user, and no mblk could be allocated for the data.
3373 3372 * No such "ioctl" alters our state. Thus, we always go ahead
3374 3373 * and do any state-changes the "ioctl" calls for. If we
3375 3374 * couldn't allocate the data, "ttycommon_ioctl" has stashed
3376 3375 * the "ioctl" away safely, so we just call "bufcall" to
3377 3376 * request that we be called back when we stand a better
3378 3377 * chance of allocating the data.
3379 3378 */
3380 3379 if ((datasize = ttycommon_ioctl(tp, wq, mp, &error)) != 0) {
3381 3380 if (async->async_wbufcid)
3382 3381 unbufcall(async->async_wbufcid);
3383 3382 async->async_wbufcid = bufcall(datasize, BPRI_HI,
3384 3383 (void (*)(void *)) async_reioctl,
3385 3384 (void *)(intptr_t)async->async_common->asy_unit);
3386 3385 return;
3387 3386 }
3388 3387 }
3389 3388
3390 3389 mutex_enter(&asy->asy_excl);
3391 3390
3392 3391 if (error == 0) {
3393 3392 /*
3394 3393 * "ttycommon_ioctl" did most of the work; we just use the
3395 3394 * data it set up.
3396 3395 */
3397 3396 switch (iocp->ioc_cmd) {
3398 3397
3399 3398 case TCSETS:
3400 3399 mutex_enter(&asy->asy_excl_hi);
3401 3400 if (asy_baudok(asy))
3402 3401 asy_program(asy, ASY_NOINIT);
3403 3402 else
3404 3403 error = EINVAL;
3405 3404 mutex_exit(&asy->asy_excl_hi);
3406 3405 break;
3407 3406 case TCSETSF:
3408 3407 case TCSETSW:
3409 3408 case TCSETA:
3410 3409 case TCSETAW:
3411 3410 case TCSETAF:
3412 3411 mutex_enter(&asy->asy_excl_hi);
3413 3412 if (!asy_baudok(asy))
3414 3413 error = EINVAL;
3415 3414 else {
3416 3415 if (asy_isbusy(asy))
3417 3416 asy_waiteot(asy);
3418 3417 asy_program(asy, ASY_NOINIT);
3419 3418 }
3420 3419 mutex_exit(&asy->asy_excl_hi);
3421 3420 break;
3422 3421 }
3423 3422 } else if (error < 0) {
3424 3423 /*
3425 3424 * "ttycommon_ioctl" didn't do anything; we process it here.
3426 3425 */
3427 3426 error = 0;
3428 3427 switch (iocp->ioc_cmd) {
3429 3428
3430 3429 case TIOCGPPS:
3431 3430 /*
3432 3431 * Get PPS on/off.
3433 3432 */
3434 3433 if (mp->b_cont != NULL)
3435 3434 freemsg(mp->b_cont);
3436 3435
3437 3436 mp->b_cont = allocb(sizeof (int), BPRI_HI);
3438 3437 if (mp->b_cont == NULL) {
3439 3438 error = ENOMEM;
3440 3439 break;
3441 3440 }
3442 3441 if (asy->asy_flags & ASY_PPS)
3443 3442 *(int *)mp->b_cont->b_wptr = 1;
3444 3443 else
3445 3444 *(int *)mp->b_cont->b_wptr = 0;
3446 3445 mp->b_cont->b_wptr += sizeof (int);
3447 3446 mp->b_datap->db_type = M_IOCACK;
3448 3447 iocp->ioc_count = sizeof (int);
3449 3448 break;
3450 3449
3451 3450 case TIOCSPPS:
3452 3451 /*
3453 3452 * Set PPS on/off.
3454 3453 */
3455 3454 error = miocpullup(mp, sizeof (int));
3456 3455 if (error != 0)
3457 3456 break;
3458 3457
3459 3458 mutex_enter(&asy->asy_excl_hi);
3460 3459 if (*(int *)mp->b_cont->b_rptr)
3461 3460 asy->asy_flags |= ASY_PPS;
3462 3461 else
3463 3462 asy->asy_flags &= ~ASY_PPS;
3464 3463 /* Reset edge sense */
3465 3464 asy->asy_flags &= ~ASY_PPS_EDGE;
3466 3465 mutex_exit(&asy->asy_excl_hi);
3467 3466 mp->b_datap->db_type = M_IOCACK;
3468 3467 break;
3469 3468
3470 3469 case TIOCGPPSEV:
3471 3470 {
3472 3471 /*
3473 3472 * Get PPS event data.
3474 3473 */
3475 3474 mblk_t *bp;
3476 3475 void *buf;
3477 3476 #ifdef _SYSCALL32_IMPL
3478 3477 struct ppsclockev32 p32;
3479 3478 #endif
3480 3479 struct ppsclockev ppsclockev;
3481 3480
3482 3481 if (mp->b_cont != NULL) {
3483 3482 freemsg(mp->b_cont);
3484 3483 mp->b_cont = NULL;
3485 3484 }
3486 3485
3487 3486 if ((asy->asy_flags & ASY_PPS) == 0) {
3488 3487 error = ENXIO;
3489 3488 break;
3490 3489 }
3491 3490
3492 3491 /* Protect from incomplete asy_ppsev */
3493 3492 mutex_enter(&asy->asy_excl_hi);
3494 3493 ppsclockev = asy_ppsev;
3495 3494 mutex_exit(&asy->asy_excl_hi);
3496 3495
3497 3496 #ifdef _SYSCALL32_IMPL
3498 3497 if ((iocp->ioc_flag & IOC_MODELS) != IOC_NATIVE) {
3499 3498 TIMEVAL_TO_TIMEVAL32(&p32.tv, &ppsclockev.tv);
3500 3499 p32.serial = ppsclockev.serial;
3501 3500 buf = &p32;
3502 3501 iocp->ioc_count = sizeof (struct ppsclockev32);
3503 3502 } else
3504 3503 #endif
3505 3504 {
3506 3505 buf = &ppsclockev;
3507 3506 iocp->ioc_count = sizeof (struct ppsclockev);
3508 3507 }
3509 3508
3510 3509 if ((bp = allocb(iocp->ioc_count, BPRI_HI)) == NULL) {
3511 3510 error = ENOMEM;
3512 3511 break;
3513 3512 }
3514 3513 mp->b_cont = bp;
3515 3514
3516 3515 bcopy(buf, bp->b_wptr, iocp->ioc_count);
3517 3516 bp->b_wptr += iocp->ioc_count;
3518 3517 mp->b_datap->db_type = M_IOCACK;
3519 3518 break;
3520 3519 }
3521 3520
3522 3521 case TCSBRK:
3523 3522 error = miocpullup(mp, sizeof (int));
3524 3523 if (error != 0)
3525 3524 break;
3526 3525
3527 3526 if (*(int *)mp->b_cont->b_rptr == 0) {
3528 3527
3529 3528 /*
3530 3529 * XXX Arrangements to ensure that a break
3531 3530 * isn't in progress should be sufficient.
3532 3531 * This ugly delay() is the only thing
3533 3532 * that seems to work on the NCR Worldmark.
3534 3533 * It should be replaced. Note that an
3535 3534 * asy_waiteot() also does not work.
3536 3535 */
3537 3536 if (asydelay)
3538 3537 delay(drv_usectohz(asydelay));
3539 3538
3540 3539 while (async->async_flags & ASYNC_BREAK) {
3541 3540 cv_wait(&async->async_flags_cv,
3542 3541 &asy->asy_excl);
3543 3542 }
3544 3543 mutex_enter(&asy->asy_excl_hi);
3545 3544 /*
3546 3545 * We loop until the TSR is empty and then
3547 3546 * set the break. ASYNC_BREAK has been set
3548 3547 * to ensure that no characters are
3549 3548 * transmitted while the TSR is being
3550 3549 * flushed and SOUT is being used for the
3551 3550 * break signal.
3552 3551 *
3553 3552 * The wait period is equal to
3554 3553 * clock / (baud * 16) * 16 * 2.
3555 3554 */
3556 3555 index = BAUDINDEX(
3557 3556 async->async_ttycommon.t_cflag);
3558 3557 async->async_flags |= ASYNC_BREAK;
3559 3558
3560 3559 while ((ddi_get8(asy->asy_iohandle,
3561 3560 asy->asy_ioaddr + LSR) & XSRE) == 0) {
3562 3561 mutex_exit(&asy->asy_excl_hi);
3563 3562 mutex_exit(&asy->asy_excl);
3564 3563 drv_usecwait(
3565 3564 32*asyspdtab[index] & 0xfff);
3566 3565 mutex_enter(&asy->asy_excl);
3567 3566 mutex_enter(&asy->asy_excl_hi);
3568 3567 }
3569 3568 /*
3570 3569 * Arrange for "async_restart"
3571 3570 * to be called in 1/4 second;
3572 3571 * it will turn the break bit off, and call
3573 3572 * "async_start" to grab the next message.
3574 3573 */
3575 3574 val = ddi_get8(asy->asy_iohandle,
3576 3575 asy->asy_ioaddr + LCR);
3577 3576 ddi_put8(asy->asy_iohandle,
3578 3577 asy->asy_ioaddr + LCR,
3579 3578 (val | SETBREAK));
3580 3579 mutex_exit(&asy->asy_excl_hi);
3581 3580 (void) timeout(async_restart, (caddr_t)async,
3582 3581 drv_usectohz(1000000)/4);
3583 3582 } else {
3584 3583 DEBUGCONT1(ASY_DEBUG_OUT,
3585 3584 "async%d_ioctl: wait for flush.\n",
3586 3585 instance);
3587 3586 mutex_enter(&asy->asy_excl_hi);
3588 3587 asy_waiteot(asy);
3589 3588 mutex_exit(&asy->asy_excl_hi);
3590 3589 DEBUGCONT1(ASY_DEBUG_OUT,
3591 3590 "async%d_ioctl: ldterm satisfied.\n",
3592 3591 instance);
3593 3592 }
3594 3593 break;
3595 3594
3596 3595 case TIOCSBRK:
3597 3596 if (!(async->async_flags & ASYNC_OUT_SUSPEND)) {
3598 3597 mutex_enter(&asy->asy_excl_hi);
3599 3598 async->async_flags |= ASYNC_OUT_SUSPEND;
3600 3599 async->async_flags |= ASYNC_HOLD_UTBRK;
3601 3600 index = BAUDINDEX(
3602 3601 async->async_ttycommon.t_cflag);
3603 3602 while ((ddi_get8(asy->asy_iohandle,
3604 3603 asy->asy_ioaddr + LSR) & XSRE) == 0) {
3605 3604 mutex_exit(&asy->asy_excl_hi);
3606 3605 mutex_exit(&asy->asy_excl);
3607 3606 drv_usecwait(
3608 3607 32*asyspdtab[index] & 0xfff);
3609 3608 mutex_enter(&asy->asy_excl);
3610 3609 mutex_enter(&asy->asy_excl_hi);
3611 3610 }
3612 3611 val = ddi_get8(asy->asy_iohandle,
3613 3612 asy->asy_ioaddr + LCR);
3614 3613 ddi_put8(asy->asy_iohandle,
3615 3614 asy->asy_ioaddr + LCR, (val | SETBREAK));
3616 3615 mutex_exit(&asy->asy_excl_hi);
3617 3616 /* wait for 100ms to hold BREAK */
3618 3617 async->async_utbrktid =
3619 3618 timeout((void (*)())async_hold_utbrk,
3620 3619 (caddr_t)async,
3621 3620 drv_usectohz(asy_min_utbrk));
3622 3621 }
3623 3622 mioc2ack(mp, NULL, 0, 0);
3624 3623 break;
3625 3624
3626 3625 case TIOCCBRK:
3627 3626 if (async->async_flags & ASYNC_OUT_SUSPEND)
3628 3627 async_resume_utbrk(async);
3629 3628 mioc2ack(mp, NULL, 0, 0);
3630 3629 break;
3631 3630
3632 3631 case TIOCMSET:
3633 3632 case TIOCMBIS:
3634 3633 case TIOCMBIC:
3635 3634 if (iocp->ioc_count != TRANSPARENT) {
3636 3635 DEBUGCONT1(ASY_DEBUG_IOCTL, "async%d_ioctl: "
3637 3636 "non-transparent\n", instance);
3638 3637
3639 3638 error = miocpullup(mp, sizeof (int));
3640 3639 if (error != 0)
3641 3640 break;
3642 3641
3643 3642 mutex_enter(&asy->asy_excl_hi);
3644 3643 (void) asymctl(asy,
3645 3644 dmtoasy(*(int *)mp->b_cont->b_rptr),
3646 3645 iocp->ioc_cmd);
3647 3646 mutex_exit(&asy->asy_excl_hi);
3648 3647 iocp->ioc_error = 0;
3649 3648 mp->b_datap->db_type = M_IOCACK;
3650 3649 } else {
3651 3650 DEBUGCONT1(ASY_DEBUG_IOCTL, "async%d_ioctl: "
3652 3651 "transparent\n", instance);
3653 3652 mcopyin(mp, NULL, sizeof (int), NULL);
3654 3653 }
3655 3654 break;
3656 3655
3657 3656 case TIOCMGET:
3658 3657 datamp = allocb(sizeof (int), BPRI_MED);
3659 3658 if (datamp == NULL) {
3660 3659 error = EAGAIN;
3661 3660 break;
3662 3661 }
3663 3662
3664 3663 mutex_enter(&asy->asy_excl_hi);
3665 3664 *(int *)datamp->b_rptr = asymctl(asy, 0, TIOCMGET);
3666 3665 mutex_exit(&asy->asy_excl_hi);
3667 3666
3668 3667 if (iocp->ioc_count == TRANSPARENT) {
3669 3668 DEBUGCONT1(ASY_DEBUG_IOCTL, "async%d_ioctl: "
3670 3669 "transparent\n", instance);
3671 3670 mcopyout(mp, NULL, sizeof (int), NULL, datamp);
3672 3671 } else {
3673 3672 DEBUGCONT1(ASY_DEBUG_IOCTL, "async%d_ioctl: "
3674 3673 "non-transparent\n", instance);
3675 3674 mioc2ack(mp, datamp, sizeof (int), 0);
3676 3675 }
3677 3676 break;
3678 3677
3679 3678 case CONSOPENPOLLEDIO:
3680 3679 error = miocpullup(mp, sizeof (struct cons_polledio *));
3681 3680 if (error != 0)
3682 3681 break;
3683 3682
3684 3683 *(struct cons_polledio **)mp->b_cont->b_rptr =
3685 3684 &asy->polledio;
3686 3685
3687 3686 mp->b_datap->db_type = M_IOCACK;
3688 3687 break;
3689 3688
3690 3689 case CONSCLOSEPOLLEDIO:
3691 3690 mp->b_datap->db_type = M_IOCACK;
3692 3691 iocp->ioc_error = 0;
3693 3692 iocp->ioc_rval = 0;
3694 3693 break;
3695 3694
3696 3695 case CONSSETABORTENABLE:
3697 3696 error = secpolicy_console(iocp->ioc_cr);
3698 3697 if (error != 0)
3699 3698 break;
3700 3699
3701 3700 if (iocp->ioc_count != TRANSPARENT) {
3702 3701 error = EINVAL;
3703 3702 break;
3704 3703 }
3705 3704
3706 3705 if (*(intptr_t *)mp->b_cont->b_rptr)
3707 3706 asy->asy_flags |= ASY_CONSOLE;
3708 3707 else
3709 3708 asy->asy_flags &= ~ASY_CONSOLE;
3710 3709
3711 3710 mp->b_datap->db_type = M_IOCACK;
3712 3711 iocp->ioc_error = 0;
3713 3712 iocp->ioc_rval = 0;
3714 3713 break;
3715 3714
3716 3715 case CONSGETABORTENABLE:
3717 3716 /*CONSTANTCONDITION*/
3718 3717 ASSERT(sizeof (boolean_t) <= sizeof (boolean_t *));
3719 3718 /*
3720 3719 * Store the return value right in the payload
3721 3720 * we were passed. Crude.
3722 3721 */
3723 3722 mcopyout(mp, NULL, sizeof (boolean_t), NULL, NULL);
3724 3723 *(boolean_t *)mp->b_cont->b_rptr =
3725 3724 (asy->asy_flags & ASY_CONSOLE) != 0;
3726 3725 break;
3727 3726
3728 3727 default:
3729 3728 /*
3730 3729 * If we don't understand it, it's an error. NAK it.
3731 3730 */
3732 3731 error = EINVAL;
3733 3732 break;
3734 3733 }
3735 3734 }
3736 3735 if (error != 0) {
3737 3736 iocp->ioc_error = error;
3738 3737 mp->b_datap->db_type = M_IOCNAK;
3739 3738 }
3740 3739 mutex_exit(&asy->asy_excl);
3741 3740 qreply(wq, mp);
3742 3741 DEBUGCONT1(ASY_DEBUG_PROCS, "async%d_ioctl: done\n", instance);
3743 3742 }
3744 3743
3745 3744 static int
3746 3745 asyrsrv(queue_t *q)
3747 3746 {
3748 3747 mblk_t *bp;
3749 3748 struct asyncline *async;
3750 3749
3751 3750 async = (struct asyncline *)q->q_ptr;
3752 3751
3753 3752 while (canputnext(q) && (bp = getq(q)))
3754 3753 putnext(q, bp);
3755 3754 ASYSETSOFT(async->async_common);
3756 3755 async->async_polltid = 0;
3757 3756 return (0);
3758 3757 }
3759 3758
3760 3759 /*
3761 3760 * The ASYWPUTDO_NOT_SUSP macro indicates to asywputdo() whether it should
3762 3761 * handle messages as though the driver is operating normally or is
3763 3762 * suspended. In the suspended case, some or all of the processing may have
3764 3763 * to be delayed until the driver is resumed.
3765 3764 */
3766 3765 #define ASYWPUTDO_NOT_SUSP(async, wput) \
3767 3766 !((wput) && ((async)->async_flags & ASYNC_DDI_SUSPENDED))
3768 3767
3769 3768 /*
3770 3769 * Processing for write queue put procedure.
3771 3770 * Respond to M_STOP, M_START, M_IOCTL, and M_FLUSH messages here;
3772 3771 * set the flow control character for M_STOPI and M_STARTI messages;
3773 3772 * queue up M_BREAK, M_DELAY, and M_DATA messages for processing
3774 3773 * by the start routine, and then call the start routine; discard
3775 3774 * everything else. Note that this driver does not incorporate any
3776 3775 * mechanism to negotiate to handle the canonicalization process.
3777 3776 * It expects that these functions are handled in upper module(s),
3778 3777 * as we do in ldterm.
3779 3778 */
3780 3779 static int
3781 3780 asywputdo(queue_t *q, mblk_t *mp, boolean_t wput)
3782 3781 {
3783 3782 struct asyncline *async;
3784 3783 struct asycom *asy;
3785 3784 #ifdef DEBUG
3786 3785 int instance;
3787 3786 #endif
3788 3787 int error;
3789 3788
3790 3789 async = (struct asyncline *)q->q_ptr;
3791 3790
3792 3791 #ifdef DEBUG
3793 3792 instance = UNIT(async->async_dev);
3794 3793 #endif
3795 3794 asy = async->async_common;
3796 3795
3797 3796 switch (mp->b_datap->db_type) {
3798 3797
3799 3798 case M_STOP:
3800 3799 /*
3801 3800 * Since we don't do real DMA, we can just let the
3802 3801 * chip coast to a stop after applying the brakes.
3803 3802 */
3804 3803 mutex_enter(&asy->asy_excl);
3805 3804 async->async_flags |= ASYNC_STOPPED;
3806 3805 mutex_exit(&asy->asy_excl);
3807 3806 freemsg(mp);
3808 3807 break;
3809 3808
3810 3809 case M_START:
3811 3810 mutex_enter(&asy->asy_excl);
3812 3811 if (async->async_flags & ASYNC_STOPPED) {
3813 3812 async->async_flags &= ~ASYNC_STOPPED;
3814 3813 if (ASYWPUTDO_NOT_SUSP(async, wput)) {
3815 3814 /*
3816 3815 * If an output operation is in progress,
3817 3816 * resume it. Otherwise, prod the start
3818 3817 * routine.
3819 3818 */
3820 3819 if (async->async_ocnt > 0) {
3821 3820 mutex_enter(&asy->asy_excl_hi);
3822 3821 async_resume(async);
3823 3822 mutex_exit(&asy->asy_excl_hi);
3824 3823 } else {
3825 3824 async_start(async);
3826 3825 }
3827 3826 }
3828 3827 }
3829 3828 mutex_exit(&asy->asy_excl);
3830 3829 freemsg(mp);
3831 3830 break;
3832 3831
3833 3832 case M_IOCTL:
3834 3833 switch (((struct iocblk *)mp->b_rptr)->ioc_cmd) {
3835 3834
3836 3835 case TCSBRK:
3837 3836 error = miocpullup(mp, sizeof (int));
3838 3837 if (error != 0) {
3839 3838 miocnak(q, mp, 0, error);
3840 3839 return (0);
3841 3840 }
3842 3841
3843 3842 if (*(int *)mp->b_cont->b_rptr != 0) {
3844 3843 DEBUGCONT1(ASY_DEBUG_OUT,
3845 3844 "async%d_ioctl: flush request.\n",
3846 3845 instance);
3847 3846 (void) putq(q, mp);
3848 3847
3849 3848 mutex_enter(&asy->asy_excl);
3850 3849 if (ASYWPUTDO_NOT_SUSP(async, wput)) {
3851 3850 /*
3852 3851 * If an TIOCSBRK is in progress,
3853 3852 * clean it as TIOCCBRK does,
3854 3853 * then kick off output.
3855 3854 * If TIOCSBRK is not in progress,
3856 3855 * just kick off output.
3857 3856 */
3858 3857 async_resume_utbrk(async);
3859 3858 }
3860 3859 mutex_exit(&asy->asy_excl);
3861 3860 break;
3862 3861 }
3863 3862 /*FALLTHROUGH*/
3864 3863 case TCSETSW:
3865 3864 case TCSETSF:
3866 3865 case TCSETAW:
3867 3866 case TCSETAF:
3868 3867 /*
3869 3868 * The changes do not take effect until all
3870 3869 * output queued before them is drained.
3871 3870 * Put this message on the queue, so that
3872 3871 * "async_start" will see it when it's done
3873 3872 * with the output before it. Poke the
3874 3873 * start routine, just in case.
3875 3874 */
3876 3875 (void) putq(q, mp);
3877 3876
3878 3877 mutex_enter(&asy->asy_excl);
3879 3878 if (ASYWPUTDO_NOT_SUSP(async, wput)) {
3880 3879 /*
3881 3880 * If an TIOCSBRK is in progress,
3882 3881 * clean it as TIOCCBRK does.
3883 3882 * then kick off output.
3884 3883 * If TIOCSBRK is not in progress,
3885 3884 * just kick off output.
3886 3885 */
3887 3886 async_resume_utbrk(async);
3888 3887 }
3889 3888 mutex_exit(&asy->asy_excl);
3890 3889 break;
3891 3890
3892 3891 default:
3893 3892 /*
3894 3893 * Do it now.
3895 3894 */
3896 3895 mutex_enter(&asy->asy_excl);
3897 3896 if (ASYWPUTDO_NOT_SUSP(async, wput)) {
3898 3897 mutex_exit(&asy->asy_excl);
3899 3898 async_ioctl(async, q, mp);
3900 3899 break;
3901 3900 }
3902 3901 async_put_suspq(asy, mp);
3903 3902 mutex_exit(&asy->asy_excl);
3904 3903 break;
3905 3904 }
3906 3905 break;
3907 3906
3908 3907 case M_FLUSH:
3909 3908 if (*mp->b_rptr & FLUSHW) {
3910 3909 mutex_enter(&asy->asy_excl);
3911 3910
3912 3911 /*
3913 3912 * Abort any output in progress.
3914 3913 */
3915 3914 mutex_enter(&asy->asy_excl_hi);
3916 3915 if (async->async_flags & ASYNC_BUSY) {
3917 3916 DEBUGCONT1(ASY_DEBUG_BUSY, "asy%dwput: "
3918 3917 "Clearing async_ocnt, "
3919 3918 "leaving ASYNC_BUSY set\n",
3920 3919 instance);
3921 3920 async->async_ocnt = 0;
3922 3921 async->async_flags &= ~ASYNC_BUSY;
3923 3922 } /* if */
3924 3923
3925 3924 if (ASYWPUTDO_NOT_SUSP(async, wput)) {
3926 3925 /* Flush FIFO buffers */
3927 3926 if (asy->asy_use_fifo == FIFO_ON) {
3928 3927 asy_reset_fifo(asy, FIFOTXFLSH);
3929 3928 }
3930 3929 }
3931 3930 mutex_exit(&asy->asy_excl_hi);
3932 3931
3933 3932 /* Flush FIFO buffers */
3934 3933 if (asy->asy_use_fifo == FIFO_ON) {
3935 3934 asy_reset_fifo(asy, FIFOTXFLSH);
3936 3935 }
3937 3936
3938 3937 /*
3939 3938 * Flush our write queue.
3940 3939 */
3941 3940 flushq(q, FLUSHDATA); /* XXX doesn't flush M_DELAY */
3942 3941 if (async->async_xmitblk != NULL) {
3943 3942 freeb(async->async_xmitblk);
3944 3943 async->async_xmitblk = NULL;
3945 3944 }
3946 3945 mutex_exit(&asy->asy_excl);
3947 3946 *mp->b_rptr &= ~FLUSHW; /* it has been flushed */
3948 3947 }
3949 3948 if (*mp->b_rptr & FLUSHR) {
3950 3949 if (ASYWPUTDO_NOT_SUSP(async, wput)) {
3951 3950 /* Flush FIFO buffers */
3952 3951 if (asy->asy_use_fifo == FIFO_ON) {
3953 3952 asy_reset_fifo(asy, FIFORXFLSH);
3954 3953 }
3955 3954 }
3956 3955 flushq(RD(q), FLUSHDATA);
3957 3956 qreply(q, mp); /* give the read queues a crack at it */
3958 3957 } else {
3959 3958 freemsg(mp);
3960 3959 }
3961 3960
3962 3961 /*
3963 3962 * We must make sure we process messages that survive the
3964 3963 * write-side flush.
3965 3964 */
3966 3965 if (ASYWPUTDO_NOT_SUSP(async, wput)) {
3967 3966 mutex_enter(&asy->asy_excl);
3968 3967 async_start(async);
3969 3968 mutex_exit(&asy->asy_excl);
3970 3969 }
3971 3970 break;
3972 3971
3973 3972 case M_BREAK:
3974 3973 case M_DELAY:
3975 3974 case M_DATA:
3976 3975 /*
3977 3976 * Queue the message up to be transmitted,
3978 3977 * and poke the start routine.
3979 3978 */
3980 3979 (void) putq(q, mp);
3981 3980 if (ASYWPUTDO_NOT_SUSP(async, wput)) {
3982 3981 mutex_enter(&asy->asy_excl);
3983 3982 async_start(async);
3984 3983 mutex_exit(&asy->asy_excl);
3985 3984 }
3986 3985 break;
3987 3986
3988 3987 case M_STOPI:
3989 3988 mutex_enter(&asy->asy_excl);
3990 3989 if (ASYWPUTDO_NOT_SUSP(async, wput)) {
3991 3990 mutex_enter(&asy->asy_excl_hi);
3992 3991 if (!(async->async_inflow_source & IN_FLOW_USER)) {
3993 3992 async_flowcontrol_hw_input(asy, FLOW_STOP,
3994 3993 IN_FLOW_USER);
3995 3994 (void) async_flowcontrol_sw_input(asy,
3996 3995 FLOW_STOP, IN_FLOW_USER);
3997 3996 }
3998 3997 mutex_exit(&asy->asy_excl_hi);
3999 3998 mutex_exit(&asy->asy_excl);
4000 3999 freemsg(mp);
4001 4000 break;
4002 4001 }
4003 4002 async_put_suspq(asy, mp);
4004 4003 mutex_exit(&asy->asy_excl);
4005 4004 break;
4006 4005
4007 4006 case M_STARTI:
4008 4007 mutex_enter(&asy->asy_excl);
4009 4008 if (ASYWPUTDO_NOT_SUSP(async, wput)) {
4010 4009 mutex_enter(&asy->asy_excl_hi);
4011 4010 if (async->async_inflow_source & IN_FLOW_USER) {
4012 4011 async_flowcontrol_hw_input(asy, FLOW_START,
4013 4012 IN_FLOW_USER);
4014 4013 (void) async_flowcontrol_sw_input(asy,
4015 4014 FLOW_START, IN_FLOW_USER);
4016 4015 }
4017 4016 mutex_exit(&asy->asy_excl_hi);
4018 4017 mutex_exit(&asy->asy_excl);
4019 4018 freemsg(mp);
4020 4019 break;
4021 4020 }
4022 4021 async_put_suspq(asy, mp);
4023 4022 mutex_exit(&asy->asy_excl);
4024 4023 break;
4025 4024
4026 4025 case M_CTL:
4027 4026 if (MBLKL(mp) >= sizeof (struct iocblk) &&
4028 4027 ((struct iocblk *)mp->b_rptr)->ioc_cmd == MC_POSIXQUERY) {
4029 4028 mutex_enter(&asy->asy_excl);
4030 4029 if (ASYWPUTDO_NOT_SUSP(async, wput)) {
4031 4030 ((struct iocblk *)mp->b_rptr)->ioc_cmd =
4032 4031 MC_HAS_POSIX;
4033 4032 mutex_exit(&asy->asy_excl);
4034 4033 qreply(q, mp);
4035 4034 break;
4036 4035 } else {
4037 4036 async_put_suspq(asy, mp);
4038 4037 }
4039 4038 } else {
4040 4039 /*
4041 4040 * These MC_SERVICE type messages are used by upper
4042 4041 * modules to tell this driver to send input up
4043 4042 * immediately, or that it can wait for normal
4044 4043 * processing that may or may not be done. Sun
4045 4044 * requires these for the mouse module.
4046 4045 * (XXX - for x86?)
4047 4046 */
4048 4047 mutex_enter(&asy->asy_excl);
4049 4048 switch (*mp->b_rptr) {
4050 4049
4051 4050 case MC_SERVICEIMM:
4052 4051 async->async_flags |= ASYNC_SERVICEIMM;
4053 4052 break;
4054 4053
4055 4054 case MC_SERVICEDEF:
4056 4055 async->async_flags &= ~ASYNC_SERVICEIMM;
4057 4056 break;
4058 4057 }
4059 4058 mutex_exit(&asy->asy_excl);
4060 4059 freemsg(mp);
4061 4060 }
4062 4061 break;
4063 4062
4064 4063 case M_IOCDATA:
4065 4064 mutex_enter(&asy->asy_excl);
4066 4065 if (ASYWPUTDO_NOT_SUSP(async, wput)) {
4067 4066 mutex_exit(&asy->asy_excl);
4068 4067 async_iocdata(q, mp);
4069 4068 break;
4070 4069 }
4071 4070 async_put_suspq(asy, mp);
4072 4071 mutex_exit(&asy->asy_excl);
4073 4072 break;
4074 4073
4075 4074 default:
4076 4075 freemsg(mp);
4077 4076 break;
4078 4077 }
4079 4078 return (0);
4080 4079 }
4081 4080
4082 4081 static int
4083 4082 asywput(queue_t *q, mblk_t *mp)
4084 4083 {
4085 4084 return (asywputdo(q, mp, B_TRUE));
4086 4085 }
4087 4086
4088 4087 /*
4089 4088 * Retry an "ioctl", now that "bufcall" claims we may be able to allocate
4090 4089 * the buffer we need.
4091 4090 */
4092 4091 static void
4093 4092 async_reioctl(void *unit)
4094 4093 {
4095 4094 int instance = (uintptr_t)unit;
4096 4095 struct asyncline *async;
4097 4096 struct asycom *asy;
4098 4097 queue_t *q;
4099 4098 mblk_t *mp;
4100 4099
4101 4100 asy = ddi_get_soft_state(asy_soft_state, instance);
4102 4101 ASSERT(asy != NULL);
4103 4102 async = asy->asy_priv;
4104 4103
4105 4104 /*
4106 4105 * The bufcall is no longer pending.
4107 4106 */
4108 4107 mutex_enter(&asy->asy_excl);
4109 4108 async->async_wbufcid = 0;
4110 4109 if ((q = async->async_ttycommon.t_writeq) == NULL) {
4111 4110 mutex_exit(&asy->asy_excl);
4112 4111 return;
4113 4112 }
4114 4113 if ((mp = async->async_ttycommon.t_iocpending) != NULL) {
4115 4114 /* not pending any more */
4116 4115 async->async_ttycommon.t_iocpending = NULL;
4117 4116 mutex_exit(&asy->asy_excl);
4118 4117 async_ioctl(async, q, mp);
4119 4118 } else
4120 4119 mutex_exit(&asy->asy_excl);
4121 4120 }
4122 4121
4123 4122 static void
4124 4123 async_iocdata(queue_t *q, mblk_t *mp)
4125 4124 {
4126 4125 struct asyncline *async = (struct asyncline *)q->q_ptr;
4127 4126 struct asycom *asy;
4128 4127 struct iocblk *ip;
4129 4128 struct copyresp *csp;
4130 4129 #ifdef DEBUG
4131 4130 int instance = UNIT(async->async_dev);
4132 4131 #endif
4133 4132
4134 4133 asy = async->async_common;
4135 4134 ip = (struct iocblk *)mp->b_rptr;
4136 4135 csp = (struct copyresp *)mp->b_rptr;
4137 4136
4138 4137 if (csp->cp_rval != 0) {
4139 4138 if (csp->cp_private)
4140 4139 freemsg(csp->cp_private);
4141 4140 freemsg(mp);
4142 4141 return;
4143 4142 }
4144 4143
4145 4144 mutex_enter(&asy->asy_excl);
4146 4145 DEBUGCONT2(ASY_DEBUG_MODEM, "async%d_iocdata: case %s\n",
4147 4146 instance,
4148 4147 csp->cp_cmd == TIOCMGET ? "TIOCMGET" :
4149 4148 csp->cp_cmd == TIOCMSET ? "TIOCMSET" :
4150 4149 csp->cp_cmd == TIOCMBIS ? "TIOCMBIS" :
4151 4150 "TIOCMBIC");
4152 4151 switch (csp->cp_cmd) {
4153 4152
4154 4153 case TIOCMGET:
4155 4154 if (mp->b_cont) {
4156 4155 freemsg(mp->b_cont);
4157 4156 mp->b_cont = NULL;
4158 4157 }
4159 4158 mp->b_datap->db_type = M_IOCACK;
4160 4159 ip->ioc_error = 0;
4161 4160 ip->ioc_count = 0;
4162 4161 ip->ioc_rval = 0;
4163 4162 mp->b_wptr = mp->b_rptr + sizeof (struct iocblk);
4164 4163 break;
4165 4164
4166 4165 case TIOCMSET:
4167 4166 case TIOCMBIS:
4168 4167 case TIOCMBIC:
4169 4168 mutex_enter(&asy->asy_excl_hi);
4170 4169 (void) asymctl(asy, dmtoasy(*(int *)mp->b_cont->b_rptr),
4171 4170 csp->cp_cmd);
4172 4171 mutex_exit(&asy->asy_excl_hi);
4173 4172 mioc2ack(mp, NULL, 0, 0);
4174 4173 break;
4175 4174
4176 4175 default:
4177 4176 mp->b_datap->db_type = M_IOCNAK;
4178 4177 ip->ioc_error = EINVAL;
4179 4178 break;
4180 4179 }
4181 4180 qreply(q, mp);
4182 4181 mutex_exit(&asy->asy_excl);
4183 4182 }
4184 4183
4185 4184 /*
4186 4185 * debugger/console support routines.
4187 4186 */
4188 4187
4189 4188 /*
4190 4189 * put a character out
4191 4190 * Do not use interrupts. If char is LF, put out CR, LF.
4192 4191 */
4193 4192 static void
4194 4193 asyputchar(cons_polledio_arg_t arg, uchar_t c)
4195 4194 {
4196 4195 struct asycom *asy = (struct asycom *)arg;
4197 4196
4198 4197 if (c == '\n')
4199 4198 asyputchar(arg, '\r');
4200 4199
4201 4200 while ((ddi_get8(asy->asy_iohandle,
4202 4201 asy->asy_ioaddr + LSR) & XHRE) == 0) {
4203 4202 /* wait for xmit to finish */
4204 4203 drv_usecwait(10);
4205 4204 }
4206 4205
4207 4206 /* put the character out */
4208 4207 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + DAT, c);
4209 4208 }
4210 4209
4211 4210 /*
4212 4211 * See if there's a character available. If no character is
4213 4212 * available, return 0. Run in polled mode, no interrupts.
4214 4213 */
4215 4214 static boolean_t
4216 4215 asyischar(cons_polledio_arg_t arg)
4217 4216 {
4218 4217 struct asycom *asy = (struct asycom *)arg;
4219 4218
4220 4219 return ((ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + LSR) & RCA)
4221 4220 != 0);
4222 4221 }
4223 4222
4224 4223 /*
4225 4224 * Get a character. Run in polled mode, no interrupts.
4226 4225 */
4227 4226 static int
4228 4227 asygetchar(cons_polledio_arg_t arg)
4229 4228 {
4230 4229 struct asycom *asy = (struct asycom *)arg;
4231 4230
4232 4231 while (!asyischar(arg))
4233 4232 drv_usecwait(10);
4234 4233 return (ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + DAT));
4235 4234 }
4236 4235
4237 4236 /*
4238 4237 * Set or get the modem control status.
4239 4238 */
4240 4239 static int
4241 4240 asymctl(struct asycom *asy, int bits, int how)
4242 4241 {
4243 4242 int mcr_r, msr_r;
4244 4243 int instance = asy->asy_unit;
4245 4244
4246 4245 ASSERT(mutex_owned(&asy->asy_excl_hi));
4247 4246 ASSERT(mutex_owned(&asy->asy_excl));
4248 4247
4249 4248 /* Read Modem Control Registers */
4250 4249 mcr_r = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + MCR);
4251 4250
4252 4251 switch (how) {
4253 4252
4254 4253 case TIOCMSET:
4255 4254 DEBUGCONT2(ASY_DEBUG_MODEM,
4256 4255 "asy%dmctl: TIOCMSET, bits = %x\n", instance, bits);
4257 4256 mcr_r = bits; /* Set bits */
4258 4257 break;
4259 4258
4260 4259 case TIOCMBIS:
4261 4260 DEBUGCONT2(ASY_DEBUG_MODEM, "asy%dmctl: TIOCMBIS, bits = %x\n",
4262 4261 instance, bits);
4263 4262 mcr_r |= bits; /* Mask in bits */
4264 4263 break;
4265 4264
4266 4265 case TIOCMBIC:
4267 4266 DEBUGCONT2(ASY_DEBUG_MODEM, "asy%dmctl: TIOCMBIC, bits = %x\n",
4268 4267 instance, bits);
4269 4268 mcr_r &= ~bits; /* Mask out bits */
4270 4269 break;
4271 4270
4272 4271 case TIOCMGET:
4273 4272 /* Read Modem Status Registers */
4274 4273 /*
4275 4274 * If modem interrupts are enabled, we return the
4276 4275 * saved value of msr. We read MSR only in async_msint()
4277 4276 */
4278 4277 if (ddi_get8(asy->asy_iohandle,
4279 4278 asy->asy_ioaddr + ICR) & MIEN) {
4280 4279 msr_r = asy->asy_msr;
4281 4280 DEBUGCONT2(ASY_DEBUG_MODEM,
4282 4281 "asy%dmctl: TIOCMGET, read msr_r = %x\n",
4283 4282 instance, msr_r);
4284 4283 } else {
4285 4284 msr_r = ddi_get8(asy->asy_iohandle,
4286 4285 asy->asy_ioaddr + MSR);
4287 4286 DEBUGCONT2(ASY_DEBUG_MODEM,
4288 4287 "asy%dmctl: TIOCMGET, read MSR = %x\n",
4289 4288 instance, msr_r);
4290 4289 }
4291 4290 DEBUGCONT2(ASY_DEBUG_MODEM, "asy%dtodm: modem_lines = %x\n",
4292 4291 instance, asytodm(mcr_r, msr_r));
4293 4292 return (asytodm(mcr_r, msr_r));
4294 4293 }
4295 4294
4296 4295 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + MCR, mcr_r);
4297 4296
4298 4297 return (mcr_r);
4299 4298 }
4300 4299
4301 4300 static int
4302 4301 asytodm(int mcr_r, int msr_r)
4303 4302 {
4304 4303 int b = 0;
4305 4304
4306 4305 /* MCR registers */
4307 4306 if (mcr_r & RTS)
4308 4307 b |= TIOCM_RTS;
4309 4308
4310 4309 if (mcr_r & DTR)
4311 4310 b |= TIOCM_DTR;
4312 4311
4313 4312 /* MSR registers */
4314 4313 if (msr_r & DCD)
4315 4314 b |= TIOCM_CAR;
4316 4315
4317 4316 if (msr_r & CTS)
4318 4317 b |= TIOCM_CTS;
4319 4318
4320 4319 if (msr_r & DSR)
4321 4320 b |= TIOCM_DSR;
4322 4321
4323 4322 if (msr_r & RI)
4324 4323 b |= TIOCM_RNG;
4325 4324 return (b);
4326 4325 }
4327 4326
4328 4327 static int
4329 4328 dmtoasy(int bits)
4330 4329 {
4331 4330 int b = 0;
4332 4331
4333 4332 DEBUGCONT1(ASY_DEBUG_MODEM, "dmtoasy: bits = %x\n", bits);
4334 4333 #ifdef CAN_NOT_SET /* only DTR and RTS can be set */
4335 4334 if (bits & TIOCM_CAR)
4336 4335 b |= DCD;
4337 4336 if (bits & TIOCM_CTS)
4338 4337 b |= CTS;
4339 4338 if (bits & TIOCM_DSR)
4340 4339 b |= DSR;
4341 4340 if (bits & TIOCM_RNG)
4342 4341 b |= RI;
4343 4342 #endif
4344 4343
4345 4344 if (bits & TIOCM_RTS) {
4346 4345 DEBUGCONT0(ASY_DEBUG_MODEM, "dmtoasy: set b & RTS\n");
4347 4346 b |= RTS;
4348 4347 }
4349 4348 if (bits & TIOCM_DTR) {
4350 4349 DEBUGCONT0(ASY_DEBUG_MODEM, "dmtoasy: set b & DTR\n");
4351 4350 b |= DTR;
4352 4351 }
4353 4352
4354 4353 return (b);
4355 4354 }
4356 4355
4357 4356 static void
4358 4357 asyerror(int level, const char *fmt, ...)
4359 4358 {
4360 4359 va_list adx;
4361 4360 static time_t last;
4362 4361 static const char *lastfmt;
4363 4362 time_t now;
4364 4363
4365 4364 /*
4366 4365 * Don't print the same error message too often.
4367 4366 * Print the message only if we have not printed the
4368 4367 * message within the last second.
4369 4368 * Note: that fmt cannot be a pointer to a string
4370 4369 * stored on the stack. The fmt pointer
4371 4370 * must be in the data segment otherwise lastfmt would point
4372 4371 * to non-sense.
4373 4372 */
4374 4373 now = gethrestime_sec();
4375 4374 if (last == now && lastfmt == fmt)
4376 4375 return;
4377 4376
4378 4377 last = now;
4379 4378 lastfmt = fmt;
4380 4379
4381 4380 va_start(adx, fmt);
4382 4381 vcmn_err(level, fmt, adx);
4383 4382 va_end(adx);
4384 4383 }
4385 4384
4386 4385 /*
4387 4386 * asy_parse_mode(dev_info_t *devi, struct asycom *asy)
4388 4387 * The value of this property is in the form of "9600,8,n,1,-"
4389 4388 * 1) speed: 9600, 4800, ...
4390 4389 * 2) data bits
4391 4390 * 3) parity: n(none), e(even), o(odd)
4392 4391 * 4) stop bits
4393 4392 * 5) handshake: -(none), h(hardware: rts/cts), s(software: xon/off)
4394 4393 *
4395 4394 * This parsing came from a SPARCstation eeprom.
4396 4395 */
4397 4396 static void
4398 4397 asy_parse_mode(dev_info_t *devi, struct asycom *asy)
4399 4398 {
4400 4399 char name[40];
4401 4400 char val[40];
4402 4401 int len;
4403 4402 int ret;
4404 4403 char *p;
4405 4404 char *p1;
4406 4405
4407 4406 ASSERT(asy->asy_com_port != 0);
4408 4407
4409 4408 /*
4410 4409 * Parse the ttyx-mode property
4411 4410 */
4412 4411 (void) sprintf(name, "tty%c-mode", asy->asy_com_port + 'a' - 1);
4413 4412 len = sizeof (val);
4414 4413 ret = GET_PROP(devi, name, DDI_PROP_CANSLEEP, val, &len);
4415 4414 if (ret != DDI_PROP_SUCCESS) {
4416 4415 (void) sprintf(name, "com%c-mode", asy->asy_com_port + '0');
4417 4416 len = sizeof (val);
4418 4417 ret = GET_PROP(devi, name, DDI_PROP_CANSLEEP, val, &len);
4419 4418 }
4420 4419
4421 4420 /* no property to parse */
4422 4421 asy->asy_cflag = 0;
4423 4422 if (ret != DDI_PROP_SUCCESS)
4424 4423 return;
4425 4424
4426 4425 p = val;
4427 4426 /* ---- baud rate ---- */
4428 4427 asy->asy_cflag = CREAD|B9600; /* initial default */
4429 4428 if (p && (p1 = strchr(p, ',')) != 0) {
4430 4429 *p1++ = '\0';
4431 4430 } else {
4432 4431 asy->asy_cflag |= BITS8; /* add default bits */
4433 4432 return;
4434 4433 }
4435 4434
4436 4435 if (strcmp(p, "110") == 0)
4437 4436 asy->asy_bidx = B110;
4438 4437 else if (strcmp(p, "150") == 0)
4439 4438 asy->asy_bidx = B150;
4440 4439 else if (strcmp(p, "300") == 0)
4441 4440 asy->asy_bidx = B300;
4442 4441 else if (strcmp(p, "600") == 0)
4443 4442 asy->asy_bidx = B600;
4444 4443 else if (strcmp(p, "1200") == 0)
4445 4444 asy->asy_bidx = B1200;
4446 4445 else if (strcmp(p, "2400") == 0)
4447 4446 asy->asy_bidx = B2400;
4448 4447 else if (strcmp(p, "4800") == 0)
4449 4448 asy->asy_bidx = B4800;
4450 4449 else if (strcmp(p, "9600") == 0)
4451 4450 asy->asy_bidx = B9600;
4452 4451 else if (strcmp(p, "19200") == 0)
4453 4452 asy->asy_bidx = B19200;
4454 4453 else if (strcmp(p, "38400") == 0)
4455 4454 asy->asy_bidx = B38400;
4456 4455 else if (strcmp(p, "57600") == 0)
4457 4456 asy->asy_bidx = B57600;
4458 4457 else if (strcmp(p, "115200") == 0)
4459 4458 asy->asy_bidx = B115200;
4460 4459 else
4461 4460 asy->asy_bidx = B9600;
4462 4461
4463 4462 asy->asy_cflag &= ~CBAUD;
4464 4463 if (asy->asy_bidx > CBAUD) { /* > 38400 uses the CBAUDEXT bit */
4465 4464 asy->asy_cflag |= CBAUDEXT;
4466 4465 asy->asy_cflag |= asy->asy_bidx - CBAUD - 1;
4467 4466 } else {
4468 4467 asy->asy_cflag |= asy->asy_bidx;
4469 4468 }
4470 4469
4471 4470 ASSERT(asy->asy_bidx == BAUDINDEX(asy->asy_cflag));
4472 4471
4473 4472 /* ---- Next item is data bits ---- */
4474 4473 p = p1;
4475 4474 if (p && (p1 = strchr(p, ',')) != 0) {
4476 4475 *p1++ = '\0';
4477 4476 } else {
4478 4477 asy->asy_cflag |= BITS8; /* add default bits */
4479 4478 return;
4480 4479 }
4481 4480 switch (*p) {
4482 4481 default:
4483 4482 case '8':
4484 4483 asy->asy_cflag |= CS8;
4485 4484 asy->asy_lcr = BITS8;
4486 4485 break;
4487 4486 case '7':
4488 4487 asy->asy_cflag |= CS7;
4489 4488 asy->asy_lcr = BITS7;
4490 4489 break;
4491 4490 case '6':
4492 4491 asy->asy_cflag |= CS6;
4493 4492 asy->asy_lcr = BITS6;
4494 4493 break;
4495 4494 case '5':
4496 4495 /* LINTED: CS5 is currently zero (but might change) */
4497 4496 asy->asy_cflag |= CS5;
4498 4497 asy->asy_lcr = BITS5;
4499 4498 break;
4500 4499 }
4501 4500
4502 4501 /* ---- Parity info ---- */
4503 4502 p = p1;
4504 4503 if (p && (p1 = strchr(p, ',')) != 0) {
4505 4504 *p1++ = '\0';
4506 4505 } else {
4507 4506 return;
4508 4507 }
4509 4508 switch (*p) {
4510 4509 default:
4511 4510 case 'n':
4512 4511 break;
4513 4512 case 'e':
4514 4513 asy->asy_cflag |= PARENB;
4515 4514 asy->asy_lcr |= PEN; break;
4516 4515 case 'o':
4517 4516 asy->asy_cflag |= PARENB|PARODD;
4518 4517 asy->asy_lcr |= PEN|EPS;
4519 4518 break;
4520 4519 }
4521 4520
4522 4521 /* ---- Find stop bits ---- */
4523 4522 p = p1;
4524 4523 if (p && (p1 = strchr(p, ',')) != 0) {
4525 4524 *p1++ = '\0';
4526 4525 } else {
4527 4526 return;
4528 4527 }
4529 4528 if (*p == '2') {
4530 4529 asy->asy_cflag |= CSTOPB;
4531 4530 asy->asy_lcr |= STB;
4532 4531 }
4533 4532
4534 4533 /* ---- handshake is next ---- */
4535 4534 p = p1;
4536 4535 if (p) {
4537 4536 if ((p1 = strchr(p, ',')) != 0)
4538 4537 *p1++ = '\0';
4539 4538
4540 4539 if (*p == 'h')
4541 4540 asy->asy_cflag |= CRTSCTS;
4542 4541 else if (*p == 's')
4543 4542 asy->asy_cflag |= CRTSXOFF;
4544 4543 }
4545 4544 }
4546 4545
4547 4546 /*
4548 4547 * Check for abort character sequence
4549 4548 */
4550 4549 static boolean_t
4551 4550 abort_charseq_recognize(uchar_t ch)
4552 4551 {
4553 4552 static int state = 0;
4554 4553 #define CNTRL(c) ((c)&037)
4555 4554 static char sequence[] = { '\r', '~', CNTRL('b') };
4556 4555
4557 4556 if (ch == sequence[state]) {
4558 4557 if (++state >= sizeof (sequence)) {
4559 4558 state = 0;
4560 4559 return (B_TRUE);
4561 4560 }
4562 4561 } else {
4563 4562 state = (ch == sequence[0]) ? 1 : 0;
4564 4563 }
4565 4564 return (B_FALSE);
4566 4565 }
4567 4566
4568 4567 /*
4569 4568 * Flow control functions
4570 4569 */
4571 4570 /*
4572 4571 * Software input flow control
4573 4572 * This function can execute software input flow control sucessfully
4574 4573 * at most of situations except that the line is in BREAK status
4575 4574 * (timed and untimed break).
4576 4575 * INPUT VALUE of onoff:
4577 4576 * FLOW_START means to send out a XON char
4578 4577 * and clear SW input flow control flag.
4579 4578 * FLOW_STOP means to send out a XOFF char
4580 4579 * and set SW input flow control flag.
4581 4580 * FLOW_CHECK means to check whether there is pending XON/XOFF
4582 4581 * if it is true, send it out.
4583 4582 * INPUT VALUE of type:
4584 4583 * IN_FLOW_RINGBUFF means flow control is due to RING BUFFER
4585 4584 * IN_FLOW_STREAMS means flow control is due to STREAMS
4586 4585 * IN_FLOW_USER means flow control is due to user's commands
4587 4586 * RETURN VALUE: B_FALSE means no flow control char is sent
4588 4587 * B_TRUE means one flow control char is sent
4589 4588 */
4590 4589 static boolean_t
4591 4590 async_flowcontrol_sw_input(struct asycom *asy, async_flowc_action onoff,
4592 4591 int type)
4593 4592 {
4594 4593 struct asyncline *async = asy->asy_priv;
4595 4594 int instance = UNIT(async->async_dev);
4596 4595 int rval = B_FALSE;
4597 4596
4598 4597 ASSERT(mutex_owned(&asy->asy_excl_hi));
4599 4598
4600 4599 if (!(async->async_ttycommon.t_iflag & IXOFF))
4601 4600 return (rval);
4602 4601
4603 4602 /*
4604 4603 * If we get this far, then we know IXOFF is set.
4605 4604 */
4606 4605 switch (onoff) {
4607 4606 case FLOW_STOP:
4608 4607 async->async_inflow_source |= type;
4609 4608
4610 4609 /*
4611 4610 * We'll send an XOFF character for each of up to
4612 4611 * three different input flow control attempts to stop input.
4613 4612 * If we already send out one XOFF, but FLOW_STOP comes again,
4614 4613 * it seems that input flow control becomes more serious,
4615 4614 * then send XOFF again.
4616 4615 */
4617 4616 if (async->async_inflow_source & (IN_FLOW_RINGBUFF |
4618 4617 IN_FLOW_STREAMS | IN_FLOW_USER))
4619 4618 async->async_flags |= ASYNC_SW_IN_FLOW |
4620 4619 ASYNC_SW_IN_NEEDED;
4621 4620 DEBUGCONT2(ASY_DEBUG_SFLOW, "async%d: input sflow stop, "
4622 4621 "type = %x\n", instance, async->async_inflow_source);
4623 4622 break;
4624 4623 case FLOW_START:
4625 4624 async->async_inflow_source &= ~type;
4626 4625 if (async->async_inflow_source == 0) {
4627 4626 async->async_flags = (async->async_flags &
4628 4627 ~ASYNC_SW_IN_FLOW) | ASYNC_SW_IN_NEEDED;
4629 4628 DEBUGCONT1(ASY_DEBUG_SFLOW, "async%d: "
4630 4629 "input sflow start\n", instance);
4631 4630 }
4632 4631 break;
4633 4632 default:
4634 4633 break;
4635 4634 }
4636 4635
4637 4636 if (((async->async_flags & (ASYNC_SW_IN_NEEDED | ASYNC_BREAK |
4638 4637 ASYNC_OUT_SUSPEND)) == ASYNC_SW_IN_NEEDED) &&
4639 4638 (ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + LSR) & XHRE)) {
4640 4639 /*
4641 4640 * If we get this far, then we know we need to send out
4642 4641 * XON or XOFF char.
4643 4642 */
4644 4643 async->async_flags = (async->async_flags &
4645 4644 ~ASYNC_SW_IN_NEEDED) | ASYNC_BUSY;
4646 4645 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + DAT,
4647 4646 async->async_flags & ASYNC_SW_IN_FLOW ?
4648 4647 async->async_stopc : async->async_startc);
4649 4648 rval = B_TRUE;
4650 4649 }
4651 4650 return (rval);
4652 4651 }
4653 4652
4654 4653 /*
4655 4654 * Software output flow control
4656 4655 * This function can be executed sucessfully at any situation.
4657 4656 * It does not handle HW, and just change the SW output flow control flag.
4658 4657 * INPUT VALUE of onoff:
4659 4658 * FLOW_START means to clear SW output flow control flag,
4660 4659 * also combine with HW output flow control status to
4661 4660 * determine if we need to set ASYNC_OUT_FLW_RESUME.
4662 4661 * FLOW_STOP means to set SW output flow control flag,
4663 4662 * also clear ASYNC_OUT_FLW_RESUME.
4664 4663 */
4665 4664 static void
4666 4665 async_flowcontrol_sw_output(struct asycom *asy, async_flowc_action onoff)
4667 4666 {
4668 4667 struct asyncline *async = asy->asy_priv;
4669 4668 int instance = UNIT(async->async_dev);
4670 4669
4671 4670 ASSERT(mutex_owned(&asy->asy_excl_hi));
4672 4671
4673 4672 if (!(async->async_ttycommon.t_iflag & IXON))
4674 4673 return;
4675 4674
4676 4675 switch (onoff) {
4677 4676 case FLOW_STOP:
4678 4677 async->async_flags |= ASYNC_SW_OUT_FLW;
4679 4678 async->async_flags &= ~ASYNC_OUT_FLW_RESUME;
4680 4679 DEBUGCONT1(ASY_DEBUG_SFLOW, "async%d: output sflow stop\n",
4681 4680 instance);
4682 4681 break;
4683 4682 case FLOW_START:
4684 4683 async->async_flags &= ~ASYNC_SW_OUT_FLW;
4685 4684 if (!(async->async_flags & ASYNC_HW_OUT_FLW))
4686 4685 async->async_flags |= ASYNC_OUT_FLW_RESUME;
4687 4686 DEBUGCONT1(ASY_DEBUG_SFLOW, "async%d: output sflow start\n",
4688 4687 instance);
4689 4688 break;
4690 4689 default:
4691 4690 break;
4692 4691 }
4693 4692 }
4694 4693
4695 4694 /*
4696 4695 * Hardware input flow control
4697 4696 * This function can be executed sucessfully at any situation.
4698 4697 * It directly changes RTS depending on input parameter onoff.
4699 4698 * INPUT VALUE of onoff:
4700 4699 * FLOW_START means to clear HW input flow control flag,
4701 4700 * and pull up RTS if it is low.
4702 4701 * FLOW_STOP means to set HW input flow control flag,
4703 4702 * and low RTS if it is high.
4704 4703 * INPUT VALUE of type:
4705 4704 * IN_FLOW_RINGBUFF means flow control is due to RING BUFFER
4706 4705 * IN_FLOW_STREAMS means flow control is due to STREAMS
4707 4706 * IN_FLOW_USER means flow control is due to user's commands
4708 4707 */
4709 4708 static void
4710 4709 async_flowcontrol_hw_input(struct asycom *asy, async_flowc_action onoff,
4711 4710 int type)
4712 4711 {
4713 4712 uchar_t mcr;
4714 4713 uchar_t flag;
4715 4714 struct asyncline *async = asy->asy_priv;
4716 4715 int instance = UNIT(async->async_dev);
4717 4716
4718 4717 ASSERT(mutex_owned(&asy->asy_excl_hi));
4719 4718
4720 4719 if (!(async->async_ttycommon.t_cflag & CRTSXOFF))
4721 4720 return;
4722 4721
4723 4722 switch (onoff) {
4724 4723 case FLOW_STOP:
4725 4724 async->async_inflow_source |= type;
4726 4725 if (async->async_inflow_source & (IN_FLOW_RINGBUFF |
4727 4726 IN_FLOW_STREAMS | IN_FLOW_USER))
4728 4727 async->async_flags |= ASYNC_HW_IN_FLOW;
4729 4728 DEBUGCONT2(ASY_DEBUG_HFLOW, "async%d: input hflow stop, "
4730 4729 "type = %x\n", instance, async->async_inflow_source);
4731 4730 break;
4732 4731 case FLOW_START:
4733 4732 async->async_inflow_source &= ~type;
4734 4733 if (async->async_inflow_source == 0) {
4735 4734 async->async_flags &= ~ASYNC_HW_IN_FLOW;
4736 4735 DEBUGCONT1(ASY_DEBUG_HFLOW, "async%d: "
4737 4736 "input hflow start\n", instance);
4738 4737 }
4739 4738 break;
4740 4739 default:
4741 4740 break;
4742 4741 }
4743 4742 mcr = ddi_get8(asy->asy_iohandle, asy->asy_ioaddr + MCR);
4744 4743 flag = (async->async_flags & ASYNC_HW_IN_FLOW) ? 0 : RTS;
4745 4744
4746 4745 if (((mcr ^ flag) & RTS) != 0) {
4747 4746 ddi_put8(asy->asy_iohandle,
4748 4747 asy->asy_ioaddr + MCR, (mcr ^ RTS));
4749 4748 }
4750 4749 }
4751 4750
4752 4751 /*
4753 4752 * Hardware output flow control
4754 4753 * This function can execute HW output flow control sucessfully
4755 4754 * at any situation.
4756 4755 * It doesn't really change RTS, and just change
4757 4756 * HW output flow control flag depending on CTS status.
4758 4757 * INPUT VALUE of onoff:
4759 4758 * FLOW_START means to clear HW output flow control flag.
4760 4759 * also combine with SW output flow control status to
4761 4760 * determine if we need to set ASYNC_OUT_FLW_RESUME.
4762 4761 * FLOW_STOP means to set HW output flow control flag.
4763 4762 * also clear ASYNC_OUT_FLW_RESUME.
4764 4763 */
4765 4764 static void
4766 4765 async_flowcontrol_hw_output(struct asycom *asy, async_flowc_action onoff)
4767 4766 {
4768 4767 struct asyncline *async = asy->asy_priv;
4769 4768 int instance = UNIT(async->async_dev);
4770 4769
4771 4770 ASSERT(mutex_owned(&asy->asy_excl_hi));
4772 4771
4773 4772 if (!(async->async_ttycommon.t_cflag & CRTSCTS))
4774 4773 return;
4775 4774
4776 4775 switch (onoff) {
4777 4776 case FLOW_STOP:
4778 4777 async->async_flags |= ASYNC_HW_OUT_FLW;
4779 4778 async->async_flags &= ~ASYNC_OUT_FLW_RESUME;
4780 4779 DEBUGCONT1(ASY_DEBUG_HFLOW, "async%d: output hflow stop\n",
4781 4780 instance);
4782 4781 break;
4783 4782 case FLOW_START:
4784 4783 async->async_flags &= ~ASYNC_HW_OUT_FLW;
4785 4784 if (!(async->async_flags & ASYNC_SW_OUT_FLW))
4786 4785 async->async_flags |= ASYNC_OUT_FLW_RESUME;
4787 4786 DEBUGCONT1(ASY_DEBUG_HFLOW, "async%d: output hflow start\n",
4788 4787 instance);
4789 4788 break;
4790 4789 default:
4791 4790 break;
4792 4791 }
4793 4792 }
4794 4793
4795 4794
4796 4795 /*
4797 4796 * quiesce(9E) entry point.
4798 4797 *
4799 4798 * This function is called when the system is single-threaded at high
4800 4799 * PIL with preemption disabled. Therefore, this function must not be
4801 4800 * blocked.
4802 4801 *
4803 4802 * This function returns DDI_SUCCESS on success, or DDI_FAILURE on failure.
4804 4803 * DDI_FAILURE indicates an error condition and should almost never happen.
4805 4804 */
4806 4805 static int
4807 4806 asyquiesce(dev_info_t *devi)
4808 4807 {
4809 4808 int instance;
4810 4809 struct asycom *asy;
4811 4810
4812 4811 instance = ddi_get_instance(devi); /* find out which unit */
4813 4812
4814 4813 asy = ddi_get_soft_state(asy_soft_state, instance);
4815 4814 if (asy == NULL)
4816 4815 return (DDI_FAILURE);
4817 4816
4818 4817 /* disable all interrupts */
4819 4818 ddi_put8(asy->asy_iohandle, asy->asy_ioaddr + ICR, 0);
4820 4819
4821 4820 /* reset the FIFO */
4822 4821 asy_reset_fifo(asy, FIFOTXFLSH | FIFORXFLSH);
4823 4822
4824 4823 return (DDI_SUCCESS);
4825 4824 }
↓ open down ↓ |
4449 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX