4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
29 * IEEE 1284 Parallel Port Device Driver
33 #include <sys/param.h>
34 #include <sys/errno.h>
36 #include <sys/cmn_err.h>
37 #include <sys/stropts.h>
38 #include <sys/debug.h>
39 #include <sys/stream.h>
40 #include <sys/strsun.h>
43 #include <sys/sunddi.h>
44 #include <sys/conf.h> /* req. by dev_ops flags MTSAFE etc. */
45 #include <sys/modctl.h> /* for modldrv */
46 #include <sys/stat.h> /* ddi_create_minor_node S_IFCHR */
48 #include <sys/ddi_impldefs.h>
49 #include <sys/kstat.h>
51 #include <sys/prnio.h>
52 #include <sys/ecppreg.h> /* hw description */
53 #include <sys/ecppio.h> /* ioctl description */
54 #include <sys/ecppvar.h> /* driver description */
55 #include <sys/dma_engine.h>
56 #include <sys/dma_i8237A.h>
61 * IEEE 1284-1994 standard defines "a signalling method for asynchronous,
62 * fully interlocked, bidirectional parallel communications between hosts
63 * and printers or other peripherals." (1.1) The standard defines 5 modes
64 * of operation - Compatibility, Nibble, Byte, ECP and EPP - which differ
65 * in direction, bandwidth, pins assignment, DMA capability, etc.
67 * Negotiation is a mechanism for moving between modes. Compatibility mode
68 * is a default mode, from which negotiations to other modes occur and
69 * to which both host and peripheral break in case of interface errors.
70 * Compatibility mode provides a unidirectional (forward) channel for
71 * communicating with old pre-1284 peripherals.
73 * Each mode has a number of phases. [Mode, phase] pair represents the
74 * interface state. Host initiates all transfers, though peripheral can
75 * request backchannel transfer by asserting nErr pin.
77 * Ecpp driver implements an IEEE 1284-compliant host using a combination
78 * of hardware and software. Hardware part is represented by a controller,
79 * which is a part of the SuperIO chip. Ecpp supports the following SuperIOs:
80 * PC82332/PC82336 (U5/U10/U60), PC97317 (U100), M1553 (Grover).
81 * Struct ecpp_hw describes each SuperIO and is determined in ecpp_attach().
83 * Negotiation is performed in software. Transfer may be performed either
84 * in software by driving output pins for each byte (PIO method), or with
85 * hardware assistance - SuperIO has a 16-byte FIFO, which is filled by
86 * the driver (normally using DMA), while the chip performs the actual xfer.
87 * PIO is used for Nibble and Compat, DMA is used for ECP and Compat modes.
89 * Driver currently supports the following modes:
91 * - Compatibility mode: byte-wide forward channel ~50KB/sec;
92 * pp->io_mode defines PIO or DMA method of transfer;
93 * - Nibble mode: nibble-wide (4-bit) reverse channel ~30KB/sec;
94 * - ECP mode: byte-wide bidirectional channel (~1MB/sec);
98 * The manner in which ecpp drives 1284 interface is that of a state machine.
99 * State is a combination of 1284 mode {ECPP_*_MODE}, 1284 phase {ECPP_PHASE_*}
100 * and transfer method {PIO, DMA}. State is a function of application actions
101 * {write(2), ioctl(2)} and peripheral reaction.
103 * 1284 interface state is described by the following variables:
104 * pp->current_mode -- 1284 mode used for forward transfers;
105 * pp->backchannel -- 1284 mode used for backward transfers;
106 * pp->curent_phase -- 1284 phase;
108 * Bidirectional operation in Compatibility mode is provided by a combination:
109 * pp->current_mode == ECPP_COMPAT_MODE && pp->backchannel == ECPP_NIBBLE_MODE
110 * ECPP_CENTRONICS means no backchannel
112 * Driver internal state is defined by pp->e_busy as follows:
113 * ECPP_IDLE -- idle, no active transfers;
114 * ECPP_BUSY -- transfer is in progress;
115 * ECPP_ERR -- have data to transfer, but peripheral can`t receive data;
116 * ECPP_FLUSH -- flushing the queues;
118 * When opened, driver is in ECPP_IDLE state, current mode is ECPP_CENTRONICS
119 * Default negotiation tries to negotiate to the best mode supported by printer,
120 * sets pp->current_mode and pp->backchannel accordingly.
122 * When output data arrives in M_DATA mblks ecpp_wput() puts them on the queue
123 * to let ecpp_wsrv() concatenate small blocks into one big transfer
124 * by copying them into pp->ioblock. If first the mblk data is bigger than
125 * pp->ioblock, then it is used instead of i/o block (pointed by pp->msg)
127 * Before starting the transfer the driver will check if peripheral is ready
128 * by calling ecpp_check_status() and if it is not, driver goes ECPP_ERR state
129 * and schedules ecpp_wsrv_timer() which would qenable() the wq, effectively
130 * rechecking the peripheral readiness and restarting itself until it is ready.
131 * The transfer is then started by calling ecpp_start(), driver goes ECPP_BUSY
133 * While transfer is in progress all arriving messages will be queued up.
134 * Transfer can end up in either of two ways:
135 * - interrupt occurs, ecpp_isr() checks if all the data was transferred, if so
136 * cleanup and go ECPP_IDLE, otherwise putback untransferred and qenable();
137 * - ecpp_xfer_timeout() cancels the transfer and puts back untransferred data;
139 * PIO transfer method is very CPU intensive: for each sent byte the peripheral
140 * state is checked, then the byte is transfered and driver waits for an nAck
141 * interrupt; ecpp_isr() will then look if there is more data and if so
142 * triggers the soft interrupt, which transfers the next byte. PIO method
143 * is needed only for legacy printers which are sensitive to strobe problem
146 * ecpp_wsrv() is responsible for both starting transfers (ecpp_start()) and
147 * going idle (ecpp_idle_phase()). Many routines qenable() the write queue,
148 * meaning "check if there are pending requests, process them and go idle".
150 * In it`s idle state the driver will always try to listen to the backchannel
151 * (as advised by 1284).
153 * The mechanism for handling backchannel requests is as follows:
154 * - when the peripheral has data to send it asserts nErr pin
155 * (and also nAck in Nibble Mode) which results in an interrupt on the host;
156 * - ISR creates M_CTL message containing an ECPP_BACKCHANNEL byte and
157 * puts it back on the write queue;
158 * - ecpp_wsrv() gets M_CTL and calls ecpp_peripheral2host(), which kicks off
161 * This way Nibble and ECP mode backchannel are implemented.
162 * If the read queue gets full, backchannel request is rejected.
163 * As the application reads data and queue size falls below the low watermark,
164 * ecpp_rsrv() gets called and enables the backchannel again.
166 * Future enhancements
167 * ===================
169 * Support new modes: Byte and EPP.
174 #endif /* ECPP_DEBUG */
175 int ecpp_debug
= ECPP_DEBUG
;
177 int noecp
= 0; /* flag not to use ECP mode */
179 /* driver entry point fn definitions */
180 static int ecpp_open(queue_t
*, dev_t
*, int, int, cred_t
*);
181 static int ecpp_close(queue_t
*, int, cred_t
*);
182 static uint_t
ecpp_isr(caddr_t
);
183 static uint_t
ecpp_softintr(caddr_t
);
185 /* configuration entry point fn definitions */
186 static int ecpp_getinfo(dev_info_t
*, ddi_info_cmd_t
, void *, void **);
187 static int ecpp_attach(dev_info_t
*, ddi_attach_cmd_t
);
188 static int ecpp_detach(dev_info_t
*, ddi_detach_cmd_t
);
189 static struct ecpp_hw_bind
*ecpp_determine_sio_type(struct ecppunit
*);
191 /* isr support routines */
192 static uint_t
ecpp_nErr_ihdlr(struct ecppunit
*);
193 static uint_t
ecpp_pio_ihdlr(struct ecppunit
*);
194 static uint_t
ecpp_dma_ihdlr(struct ecppunit
*);
195 static uint_t
ecpp_M1553_intr(struct ecppunit
*);
197 /* configuration support routines */
198 static void ecpp_get_props(struct ecppunit
*);
200 /* Streams Routines */
201 static int ecpp_wput(queue_t
*, mblk_t
*);
202 static int ecpp_wsrv(queue_t
*);
203 static int ecpp_rsrv(queue_t
*);
204 static void ecpp_flush(struct ecppunit
*, int);
205 static void ecpp_start(struct ecppunit
*, caddr_t
, size_t);
208 static void ecpp_putioc(queue_t
*, mblk_t
*);
209 static void ecpp_srvioc(queue_t
*, mblk_t
*);
210 static void ecpp_wput_iocdata_devid(queue_t
*, mblk_t
*, uintptr_t);
211 static void ecpp_putioc_copyout(queue_t
*, mblk_t
*, void *, int);
212 static void ecpp_putioc_stateful_copyin(queue_t
*, mblk_t
*, size_t);
213 static void ecpp_srvioc_devid(queue_t
*, mblk_t
*,
214 struct ecpp_device_id
*, int *);
215 static void ecpp_srvioc_prnif(queue_t
*, mblk_t
*);
216 static void ecpp_ack_ioctl(queue_t
*, mblk_t
*);
217 static void ecpp_nack_ioctl(queue_t
*, mblk_t
*, int);
220 static void ecpp_kstat_init(struct ecppunit
*);
221 static int ecpp_kstat_update(kstat_t
*, int);
222 static int ecpp_kstatintr_update(kstat_t
*, int);
225 static void ecpp_putback_untransfered(struct ecppunit
*, void *, uint_t
);
226 static uint8_t ecpp_setup_dma_resources(struct ecppunit
*, caddr_t
, size_t);
227 static uint8_t ecpp_init_dma_xfer(struct ecppunit
*, caddr_t
, size_t);
230 static void ecpp_pio_writeb(struct ecppunit
*);
231 static void ecpp_xfer_cleanup(struct ecppunit
*);
232 static uint8_t ecpp_prep_pio_xfer(struct ecppunit
*, caddr_t
, size_t);
235 static uchar_t
ecpp_reset_port_regs(struct ecppunit
*);
236 static void ecpp_xfer_timeout(void *);
237 static void ecpp_fifo_timer(void *);
238 static void ecpp_wsrv_timer(void *);
239 static uchar_t
dcr_write(struct ecppunit
*, uint8_t);
240 static uchar_t
ecr_write(struct ecppunit
*, uint8_t);
241 static uchar_t
ecpp_check_status(struct ecppunit
*);
242 static int ecpp_backchan_req(struct ecppunit
*);
243 static void ecpp_untimeout_unblock(struct ecppunit
*, timeout_id_t
*);
244 static uint_t
ecpp_get_prn_ifcap(struct ecppunit
*);
247 static void empty_config_mode(struct ecppunit
*);
248 static void empty_mask_intr(struct ecppunit
*);
250 /* PC87332 support */
251 static int pc87332_map_regs(struct ecppunit
*);
252 static void pc87332_unmap_regs(struct ecppunit
*);
253 static int pc87332_config_chip(struct ecppunit
*);
254 static void pc87332_config_mode(struct ecppunit
*);
255 static uint8_t pc87332_read_config_reg(struct ecppunit
*, uint8_t);
256 static void pc87332_write_config_reg(struct ecppunit
*, uint8_t, uint8_t);
257 static void cheerio_mask_intr(struct ecppunit
*);
258 static void cheerio_unmask_intr(struct ecppunit
*);
259 static int cheerio_dma_start(struct ecppunit
*);
260 static int cheerio_dma_stop(struct ecppunit
*, size_t *);
261 static size_t cheerio_getcnt(struct ecppunit
*);
262 static void cheerio_reset_dcsr(struct ecppunit
*);
264 /* PC97317 support */
265 static int pc97317_map_regs(struct ecppunit
*);
266 static void pc97317_unmap_regs(struct ecppunit
*);
267 static int pc97317_config_chip(struct ecppunit
*);
268 static void pc97317_config_mode(struct ecppunit
*);
270 /* M1553 Southbridge support */
271 static int m1553_map_regs(struct ecppunit
*pp
);
272 static void m1553_unmap_regs(struct ecppunit
*pp
);
273 static int m1553_config_chip(struct ecppunit
*);
274 static uint8_t m1553_read_config_reg(struct ecppunit
*, uint8_t);
275 static void m1553_write_config_reg(struct ecppunit
*, uint8_t, uint8_t);
277 /* M1553 Southbridge DMAC 8237 support routines */
278 static int dma8237_dma_start(struct ecppunit
*);
279 static int dma8237_dma_stop(struct ecppunit
*, size_t *);
280 static size_t dma8237_getcnt(struct ecppunit
*);
281 static void dma8237_write_addr(struct ecppunit
*, uint32_t);
282 static void dma8237_write_count(struct ecppunit
*, uint32_t);
283 static uint32_t dma8237_read_count(struct ecppunit
*);
284 static void dma8237_write(struct ecppunit
*, int, uint8_t);
285 static uint8_t dma8237_read(struct ecppunit
*, int);
286 #ifdef INCLUDE_DMA8237_READ_ADDR
287 static uint32_t dma8237_read_addr(struct ecppunit
*);
290 /* i86 PC support rountines */
293 static int x86_dma_start(struct ecppunit
*);
294 static int x86_dma_stop(struct ecppunit
*, size_t *);
295 static int x86_map_regs(struct ecppunit
*);
296 static void x86_unmap_regs(struct ecppunit
*);
297 static int x86_config_chip(struct ecppunit
*);
298 static size_t x86_getcnt(struct ecppunit
*);
301 /* IEEE 1284 phase transitions */
302 static void ecpp_1284_init_interface(struct ecppunit
*);
303 static int ecpp_1284_termination(struct ecppunit
*);
304 static uchar_t
ecpp_idle_phase(struct ecppunit
*);
305 static int ecp_forward2reverse(struct ecppunit
*);
306 static int ecp_reverse2forward(struct ecppunit
*);
307 static int read_nibble_backchan(struct ecppunit
*);
309 /* reverse transfers */
310 static uint_t
ecpp_peripheral2host(struct ecppunit
*);
311 static uchar_t
ecp_peripheral2host(struct ecppunit
*);
312 static uchar_t
nibble_peripheral2host(struct ecppunit
*pp
, uint8_t *);
313 static int ecpp_getdevid(struct ecppunit
*, uint8_t *, int *, int);
314 static void ecpp_ecp_read_timeout(void *);
315 static void ecpp_ecp_read_completion(struct ecppunit
*);
317 /* IEEE 1284 mode transitions */
318 static void ecpp_default_negotiation(struct ecppunit
*);
319 static int ecpp_mode_negotiation(struct ecppunit
*, uchar_t
);
320 static int ecpp_1284_negotiation(struct ecppunit
*, uint8_t, uint8_t *);
321 static int ecp_negotiation(struct ecppunit
*);
322 static int nibble_negotiation(struct ecppunit
*);
323 static int devidnib_negotiation(struct ecppunit
*);
325 /* IEEE 1284 utility routines */
326 static int wait_dsr(struct ecppunit
*, uint8_t, uint8_t, int);
328 /* debugging functions */
329 static void ecpp_error(dev_info_t
*, char *, ...);
330 static uchar_t
ecpp_get_error_status(uchar_t
);
333 * Chip-dependent structures
335 static ddi_dma_attr_t cheerio_dma_attr
= {
336 DMA_ATTR_VERSION
, /* version */
337 0x00000000ull
, /* dlim_addr_lo */
338 0xfffffffeull
, /* dlim_addr_hi */
339 0xffffff, /* DMA counter register */
340 1, /* DMA address alignment */
341 0x74, /* burst sizes */
342 0x0001, /* min effective DMA size */
343 0xffff, /* maximum transfer size */
344 0xffff, /* segment boundary */
345 1, /* s/g list length */
346 1, /* granularity of device */
350 static struct ecpp_hw pc87332
= {
363 static struct ecpp_hw pc97317
= {
376 static ddi_dma_attr_t i8237_dma_attr
= {
377 DMA_ATTR_VERSION
, /* version */
378 0x00000000ull
, /* dlim_addr_lo */
379 0xfffffffeull
, /* dlim_addr_hi */
380 0xffff, /* DMA counter register */
381 1, /* DMA address alignment */
382 0x01, /* burst sizes */
383 0x0001, /* min effective DMA size */
384 0xffff, /* maximum transfer size */
385 0x7fff, /* segment boundary */
386 1, /* s/g list length */
387 1, /* granularity of device */
391 static struct ecpp_hw m1553
= {
395 empty_config_mode
, /* no config_mode */
396 empty_mask_intr
, /* no mask_intr */
397 empty_mask_intr
, /* no unmask_intr */
405 static ddi_dma_attr_t sb_dma_attr
= {
406 DMA_ATTR_VERSION
, /* version */
407 0x00000000ull
, /* dlim_addr_lo */
408 0xffffff, /* dlim_addr_hi */
409 0xffff, /* DMA counter register */
410 1, /* DMA address alignment */
411 0x01, /* burst sizes */
412 0x0001, /* min effective DMA size */
413 0xffffffff, /* maximum transfer size */
414 0xffff, /* segment boundary */
415 1, /* s/g list length */
416 1, /* granularity of device */
420 static struct ecpp_hw x86
= {
424 empty_config_mode
, /* no config_mode */
425 empty_mask_intr
, /* no mask_intr */
426 empty_mask_intr
, /* no unmask_intr */
435 * list of supported devices
437 struct ecpp_hw_bind ecpp_hw_bind
[] = {
438 { "ns87317-ecpp", &pc97317
, "PC97317" },
439 { "pnpALI,1533,3", &m1553
, "M1553" },
440 { "ecpp", &pc87332
, "PC87332" },
442 { "lp", &x86
, "i86pc"},
446 static ddi_device_acc_attr_t acc_attr
= {
448 DDI_STRUCTURE_LE_ACC
,
452 static struct ecpp_transfer_parms default_xfer_parms
= {
453 FWD_TIMEOUT_DEFAULT
, /* write timeout in seconds */
454 ECPP_CENTRONICS
/* supported mode */
457 /* prnio interface info string */
458 static const char prn_ifinfo
[] = PRN_PARALLEL
;
461 static const struct prn_timeouts prn_timeouts_default
= {
462 FWD_TIMEOUT_DEFAULT
, /* forward timeout */
463 REV_TIMEOUT_DEFAULT
/* reverse timeout */
466 static int ecpp_isr_max_delay
= ECPP_ISR_MAX_DELAY
;
467 static int ecpp_def_timeout
= 90; /* left in for 2.7 compatibility */
469 static void *ecppsoft_statep
;
472 * STREAMS framework manages locks for these structures
474 _NOTE(SCHEME_PROTECTS_DATA("unique per call", iocblk
))
475 _NOTE(SCHEME_PROTECTS_DATA("unique per call", datab
))
476 _NOTE(SCHEME_PROTECTS_DATA("unique per call", msgb
))
477 _NOTE(SCHEME_PROTECTS_DATA("unique per call", queue
))
478 _NOTE(SCHEME_PROTECTS_DATA("unique per call", copyreq
))
479 _NOTE(SCHEME_PROTECTS_DATA("unique per call", stroptions
))
481 struct module_info ecppinfo
= {
482 /* id, name, min pkt siz, max pkt siz, hi water, low water */
483 42, "ecpp", 0, IO_BLOCK_SZ
, ECPPHIWAT
, ECPPLOWAT
486 static struct qinit ecpp_rinit
= {
487 putq
, ecpp_rsrv
, ecpp_open
, ecpp_close
, NULL
, &ecppinfo
, NULL
490 static struct qinit ecpp_wint
= {
491 ecpp_wput
, ecpp_wsrv
, ecpp_open
, ecpp_close
, NULL
, &ecppinfo
, NULL
494 struct streamtab ecpp_str_info
= {
495 &ecpp_rinit
, &ecpp_wint
, NULL
, NULL
498 static struct cb_ops ecpp_cb_ops
= {
500 nodev
, /* cb_close */
501 nodev
, /* cb_strategy */
502 nodev
, /* cb_print */
505 nodev
, /* cb_write */
506 nodev
, /* cb_ioctl */
507 nodev
, /* cb_devmap */
509 nodev
, /* cb_segmap */
510 nochpoll
, /* cb_chpoll */
511 ddi_prop_op
, /* cb_prop_op */
512 &ecpp_str_info
, /* cb_stream */
513 (D_NEW
| D_MP
| D_MTPERQ
) /* cb_flag */
517 * Declare ops vectors for auto configuration.
519 struct dev_ops ecpp_ops
= {
520 DEVO_REV
, /* devo_rev */
522 ecpp_getinfo
, /* devo_getinfo */
523 nulldev
, /* devo_identify */
524 nulldev
, /* devo_probe */
525 ecpp_attach
, /* devo_attach */
526 ecpp_detach
, /* devo_detach */
527 nodev
, /* devo_reset */
528 &ecpp_cb_ops
, /* devo_cb_ops */
529 NULL
, /* devo_bus_ops */
530 nulldev
, /* devo_power */
531 ddi_quiesce_not_needed
, /* devo_quiesce */
534 extern struct mod_ops mod_driverops
;
536 static struct modldrv ecppmodldrv
= {
537 &mod_driverops
, /* type of module - driver */
538 "parallel port driver",
542 static struct modlinkage ecppmodlinkage
= {
551 * DDI/DKI entry points and supplementary routines
561 if ((error
= mod_install(&ecppmodlinkage
)) == 0) {
562 (void) ddi_soft_state_init(&ecppsoft_statep
,
563 sizeof (struct ecppunit
), 1);
574 if ((error
= mod_remove(&ecppmodlinkage
)) == 0) {
575 ddi_soft_state_fini(&ecppsoft_statep
);
582 _info(struct modinfo
*modinfop
)
584 return (mod_info(&ecppmodlinkage
, modinfop
));
588 ecpp_attach(dev_info_t
*dip
, ddi_attach_cmd_t cmd
)
593 struct ecpp_hw_bind
*hw_bind
;
595 instance
= ddi_get_instance(dip
);
602 if (!(pp
= ddi_get_soft_state(ecppsoft_statep
, instance
))) {
603 return (DDI_FAILURE
);
606 mutex_enter(&pp
->umutex
);
608 pp
->suspended
= FALSE
;
611 * Initialize the chip and restore current mode if needed
613 (void) ECPP_CONFIG_CHIP(pp
);
614 (void) ecpp_reset_port_regs(pp
);
616 if (pp
->oflag
== TRUE
) {
617 int current_mode
= pp
->current_mode
;
619 (void) ecpp_1284_termination(pp
);
620 (void) ecpp_mode_negotiation(pp
, current_mode
);
623 mutex_exit(&pp
->umutex
);
625 return (DDI_SUCCESS
);
628 return (DDI_FAILURE
);
631 if (ddi_soft_state_zalloc(ecppsoft_statep
, instance
) != 0) {
632 ecpp_error(dip
, "ddi_soft_state_zalloc failed\n");
636 pp
= ddi_get_soft_state(ecppsoft_statep
, instance
);
639 pp
->suspended
= FALSE
;
642 * Determine SuperIO type and set chip-dependent variables
644 hw_bind
= ecpp_determine_sio_type(pp
);
646 if (hw_bind
== NULL
) {
647 cmn_err(CE_NOTE
, "parallel port controller not supported");
650 pp
->hw
= hw_bind
->hw
;
651 ecpp_error(pp
->dip
, "SuperIO type: %s\n", hw_bind
->info
);
657 if (ECPP_MAP_REGS(pp
) != SUCCESS
) {
661 if (ddi_dma_alloc_handle(dip
, pp
->hw
->attr
, DDI_DMA_DONTWAIT
,
662 NULL
, &pp
->dma_handle
) != DDI_SUCCESS
) {
663 ecpp_error(dip
, "ecpp_attach: failed ddi_dma_alloc_handle\n");
667 if (ddi_get_iblock_cookie(dip
, 0,
668 &pp
->ecpp_trap_cookie
) != DDI_SUCCESS
) {
669 ecpp_error(dip
, "ecpp_attach: failed ddi_get_iblock_cookie\n");
673 mutex_init(&pp
->umutex
, NULL
, MUTEX_DRIVER
,
674 (void *)pp
->ecpp_trap_cookie
);
676 cv_init(&pp
->pport_cv
, NULL
, CV_DRIVER
, NULL
);
678 if (ddi_add_intr(dip
, 0, &pp
->ecpp_trap_cookie
, NULL
, ecpp_isr
,
679 (caddr_t
)pp
) != DDI_SUCCESS
) {
680 ecpp_error(dip
, "ecpp_attach: failed to add hard intr\n");
684 if (ddi_add_softintr(dip
, DDI_SOFTINT_LOW
,
685 &pp
->softintr_id
, 0, 0, ecpp_softintr
,
686 (caddr_t
)pp
) != DDI_SUCCESS
) {
687 ecpp_error(dip
, "ecpp_attach: failed to add soft intr\n");
691 (void) sprintf(name
, "ecpp%d", instance
);
693 if (ddi_create_minor_node(dip
, name
, S_IFCHR
, instance
,
694 DDI_NT_PRINTER
, 0) == DDI_FAILURE
) {
695 ecpp_error(dip
, "ecpp_attach: create_minor_node failed\n");
699 pp
->ioblock
= kmem_alloc(IO_BLOCK_SZ
, KM_SLEEP
);
700 if (pp
->ioblock
== NULL
) {
701 ecpp_error(dip
, "ecpp_attach: kmem_alloc failed\n");
704 ecpp_error(pp
->dip
, "ecpp_attach: ioblock=0x%x\n", pp
->ioblock
);
709 if (pp
->hw
== &x86
&& pp
->uh
.x86
.chn
!= 0xff) {
710 if (ddi_dmae_alloc(dip
, pp
->uh
.x86
.chn
,
711 DDI_DMA_DONTWAIT
, NULL
) == DDI_SUCCESS
)
712 ecpp_error(pp
->dip
, "dmae_alloc success!\n");
715 if (ECPP_CONFIG_CHIP(pp
) == FAILURE
) {
716 ecpp_error(pp
->dip
, "config_chip failed.\n");
724 return (DDI_SUCCESS
);
727 ddi_prop_remove_all(dip
);
728 kmem_free(pp
->ioblock
, IO_BLOCK_SZ
);
730 ddi_remove_minor_node(dip
, NULL
);
732 ddi_remove_softintr(pp
->softintr_id
);
734 ddi_remove_intr(dip
, 0, pp
->ecpp_trap_cookie
);
736 mutex_destroy(&pp
->umutex
);
737 cv_destroy(&pp
->pport_cv
);
739 ddi_dma_free_handle(&pp
->dma_handle
);
744 ddi_soft_state_free(ecppsoft_statep
, instance
);
746 ecpp_error(dip
, "ecpp_attach: failed.\n");
748 return (DDI_FAILURE
);
752 ecpp_detach(dev_info_t
*dip
, ddi_detach_cmd_t cmd
)
757 instance
= ddi_get_instance(dip
);
764 if (!(pp
= ddi_get_soft_state(ecppsoft_statep
, instance
))) {
765 return (DDI_FAILURE
);
768 mutex_enter(&pp
->umutex
);
769 ASSERT(pp
->suspended
== FALSE
);
771 pp
->suspended
= TRUE
; /* prevent new transfers */
774 * Wait if there's any activity on the port
776 if ((pp
->e_busy
== ECPP_BUSY
) || (pp
->e_busy
== ECPP_FLUSH
)) {
777 (void) cv_reltimedwait(&pp
->pport_cv
, &pp
->umutex
,
778 SUSPEND_TOUT
* drv_usectohz(1000000),
780 if ((pp
->e_busy
== ECPP_BUSY
) ||
781 (pp
->e_busy
== ECPP_FLUSH
)) {
782 pp
->suspended
= FALSE
;
783 mutex_exit(&pp
->umutex
);
785 "ecpp_detach: suspend timeout\n");
786 return (DDI_FAILURE
);
790 mutex_exit(&pp
->umutex
);
791 return (DDI_SUCCESS
);
794 return (DDI_FAILURE
);
797 pp
= ddi_get_soft_state(ecppsoft_statep
, instance
);
799 if (pp
->hw
== &x86
&& pp
->uh
.x86
.chn
!= 0xff)
800 (void) ddi_dmae_release(pp
->dip
, pp
->uh
.x86
.chn
);
802 if (pp
->dma_handle
!= NULL
)
803 ddi_dma_free_handle(&pp
->dma_handle
);
805 ddi_remove_minor_node(dip
, NULL
);
807 ddi_remove_softintr(pp
->softintr_id
);
809 ddi_remove_intr(dip
, 0, pp
->ecpp_trap_cookie
);
812 kstat_delete(pp
->ksp
);
815 kstat_delete(pp
->intrstats
);
818 cv_destroy(&pp
->pport_cv
);
820 mutex_destroy(&pp
->umutex
);
824 kmem_free(pp
->ioblock
, IO_BLOCK_SZ
);
826 ddi_prop_remove_all(dip
);
828 ddi_soft_state_free(ecppsoft_statep
, instance
);
830 return (DDI_SUCCESS
);
835 * ecpp_get_props() reads ecpp.conf for user defineable tuneables.
836 * If the file or a particular variable is not there, a default value
841 ecpp_get_props(struct ecppunit
*pp
)
849 * If fast_centronics is TRUE, non-compliant IEEE 1284
850 * peripherals ( Centronics peripherals) will operate in DMA mode.
851 * Transfers betwee main memory and the device will be via DMA;
852 * peripheral handshaking will be conducted by superio logic.
853 * If ecpp can not read the variable correctly fast_centronics will
854 * be set to FALSE. In this case, transfers and handshaking
855 * will be conducted by PIO for Centronics devices.
857 if (ddi_prop_lookup_string(DDI_DEV_T_ANY
, pp
->dip
, 0,
858 "fast-centronics", &prop
) == DDI_PROP_SUCCESS
) {
859 pp
->fast_centronics
=
860 (strcmp(prop
, "true") == 0) ? TRUE
: FALSE
;
863 pp
->fast_centronics
= FALSE
;
867 * If fast-1284-compatible is set to TRUE, when ecpp communicates
868 * with IEEE 1284 compliant peripherals, data transfers between
869 * main memory and the parallel port will be conducted by DMA.
870 * Handshaking between the port and peripheral will be conducted
871 * by superio logic. This is the default characteristic. If
872 * fast-1284-compatible is set to FALSE, transfers and handshaking
873 * will be conducted by PIO.
876 if (ddi_prop_lookup_string(DDI_DEV_T_ANY
, pp
->dip
, 0,
877 "fast-1284-compatible", &prop
) == DDI_PROP_SUCCESS
) {
878 pp
->fast_compat
= (strcmp(prop
, "true") == 0) ? TRUE
: FALSE
;
881 pp
->fast_compat
= TRUE
;
885 * Some centronics peripherals require the nInit signal to be
886 * toggled to reset the device. If centronics_init_seq is set
887 * to TRUE, ecpp will toggle the nInit signal upon every ecpp_open().
888 * Applications have the opportunity to toggle the nInit signal
889 * with ioctl(2) calls as well. The default is to set it to FALSE.
891 if (ddi_prop_lookup_string(DDI_DEV_T_ANY
, pp
->dip
, 0,
892 "centronics-init-seq", &prop
) == DDI_PROP_SUCCESS
) {
893 pp
->init_seq
= (strcmp(prop
, "true") == 0) ? TRUE
: FALSE
;
896 pp
->init_seq
= FALSE
;
900 * If one of the centronics status signals are in an erroneous
901 * state, ecpp_wsrv() will be reinvoked centronics-retry ms to
902 * check if the status is ok to transfer. If the property is not
903 * found, wsrv_retry will be set to CENTRONICS_RETRY ms.
905 pp
->wsrv_retry
= ddi_prop_get_int(DDI_DEV_T_ANY
, pp
->dip
, 0,
906 "centronics-retry", CENTRONICS_RETRY
);
909 * In PIO mode, ecpp_isr() will loop for wait for the busy signal
910 * to be deasserted before transferring the next byte. wait_for_busy
911 * is specificied in microseconds. If the property is not found
912 * ecpp_isr() will wait for a maximum of WAIT_FOR_BUSY us.
914 pp
->wait_for_busy
= ddi_prop_get_int(DDI_DEV_T_ANY
, pp
->dip
, 0,
915 "centronics-wait-for-busy", WAIT_FOR_BUSY
);
918 * In PIO mode, centronics transfers must hold the data signals
919 * for a data_setup_time milliseconds before the strobe is asserted.
921 pp
->data_setup_time
= ddi_prop_get_int(DDI_DEV_T_ANY
, pp
->dip
, 0,
922 "centronics-data-setup-time", DATA_SETUP_TIME
);
925 * In PIO mode, centronics transfers asserts the strobe signal
926 * for a period of strobe_pulse_width milliseconds.
928 pp
->strobe_pulse_width
= ddi_prop_get_int(DDI_DEV_T_ANY
, pp
->dip
, 0,
929 "centronics-strobe-pulse-width", STROBE_PULSE_WIDTH
);
932 * Upon a transfer the peripheral, ecpp waits write_timeout seconds
933 * for the transmission to complete.
935 default_xfer_parms
.write_timeout
= ddi_prop_get_int(DDI_DEV_T_ANY
,
936 pp
->dip
, 0, "ecpp-transfer-timeout", ecpp_def_timeout
);
938 pp
->xfer_parms
= default_xfer_parms
;
941 * Get dma channel for M1553
943 if (pp
->hw
== &m1553
) {
944 pp
->uh
.m1553
.chn
= ddi_prop_get_int(DDI_DEV_T_ANY
,
945 pp
->dip
, 0, "dma-channel", 0x1);
946 ecpp_error(pp
->dip
, "ecpp_get_prop:chn=%x\n", pp
->uh
.m1553
.chn
);
949 len
= sizeof (value
);
950 /* Get dma channel for i86 pc */
951 if (pp
->hw
== &x86
) {
952 if (ddi_prop_op(DDI_DEV_T_ANY
, pp
->dip
, PROP_LEN_AND_VAL_BUF
,
953 DDI_PROP_DONTPASS
, "dma-channels", (caddr_t
)&value
, &len
)
954 != DDI_PROP_SUCCESS
) {
955 ecpp_error(pp
->dip
, "No dma channel found\n");
956 pp
->uh
.x86
.chn
= 0xff;
957 pp
->fast_compat
= FALSE
;
958 pp
->noecpregs
= TRUE
;
960 pp
->uh
.x86
.chn
= (uint8_t)value
;
964 * these properties are not yet public
966 pp
->ecp_rev_speed
= ddi_prop_get_int(DDI_DEV_T_ANY
, pp
->dip
, 0,
967 "ecp-rev-speed", ECP_REV_SPEED
);
969 pp
->rev_watchdog
= ddi_prop_get_int(DDI_DEV_T_ANY
, pp
->dip
, 0,
970 "rev-watchdog", REV_WATCHDOG
);
973 "ecpp_get_prop: fast_centronics=%x, fast-1284=%x\n"
974 "ecpp_get_prop: wsrv_retry=%d, wait_for_busy=%d\n"
975 "ecpp_get_prop: data_setup=%d, strobe_pulse=%d\n"
976 "ecpp_get_prop: transfer-timeout=%d\n",
977 pp
->fast_centronics
, pp
->fast_compat
,
978 pp
->wsrv_retry
, pp
->wait_for_busy
,
979 pp
->data_setup_time
, pp
->strobe_pulse_width
,
980 pp
->xfer_parms
.write_timeout
);
985 ecpp_getinfo(dev_info_t
*dip
, ddi_info_cmd_t infocmd
, void *arg
, void **result
)
987 dev_t dev
= (dev_t
)arg
;
991 instance
= getminor(dev
);
994 case DDI_INFO_DEVT2DEVINFO
:
995 pp
= ddi_get_soft_state(ecppsoft_statep
, instance
);
1004 case DDI_INFO_DEVT2INSTANCE
:
1005 *result
= (void *)(uintptr_t)instance
;
1019 ecpp_open(queue_t
*q
, dev_t
*dev
, int flag
, int sflag
, cred_t
*credp
)
1021 struct ecppunit
*pp
;
1023 struct stroptions
*sop
;
1026 instance
= getminor(*dev
);
1032 pp
= (struct ecppunit
*)ddi_get_soft_state(ecppsoft_statep
, instance
);
1038 mutex_enter(&pp
->umutex
);
1041 * Parallel port is an exclusive-use device
1042 * thus providing print job integrity
1044 if (pp
->oflag
== TRUE
) {
1045 ecpp_error(pp
->dip
, "ecpp open failed");
1046 mutex_exit(&pp
->umutex
);
1052 /* initialize state variables */
1053 pp
->prn_timeouts
= prn_timeouts_default
;
1054 pp
->xfer_parms
= default_xfer_parms
;
1055 pp
->current_mode
= ECPP_CENTRONICS
;
1056 pp
->backchannel
= ECPP_CENTRONICS
;
1057 pp
->current_phase
= ECPP_PHASE_PO
;
1058 pp
->port
= ECPP_PORT_DMA
;
1059 pp
->instance
= instance
;
1060 pp
->timeout_error
= 0;
1061 pp
->saved_dsr
= DSR_READ(pp
);
1062 pp
->ecpp_drain_counter
= 0;
1063 pp
->dma_cancelled
= FALSE
;
1064 pp
->io_mode
= ECPP_DMA
;
1067 pp
->softintr_pending
= 0;
1070 /* clear the state flag */
1071 pp
->e_busy
= ECPP_IDLE
;
1077 RD(q
)->q_ptr
= WR(q
)->q_ptr
= (caddr_t
)pp
;
1080 * Get ready: check host/peripheral, negotiate into default mode
1082 if (ecpp_reset_port_regs(pp
) == FAILURE
) {
1083 mutex_exit(&pp
->umutex
);
1087 mutex_exit(&pp
->umutex
);
1090 * Configure the Stream head and enable the Stream
1092 if (!(mop
= allocb(sizeof (struct stroptions
), BPRI_MED
))) {
1096 mop
->b_datap
->db_type
= M_SETOPTS
;
1097 mop
->b_wptr
+= sizeof (struct stroptions
);
1100 * if device is open with O_NONBLOCK flag set, let read(2) return 0
1101 * if no data waiting to be read. Writes will block on flow control.
1103 sop
= (struct stroptions
*)mop
->b_rptr
;
1104 sop
->so_flags
= SO_HIWAT
| SO_LOWAT
| SO_NDELON
| SO_MREADON
;
1105 sop
->so_hiwat
= ECPPHIWAT
;
1106 sop
->so_lowat
= ECPPLOWAT
;
1108 /* enable the stream */
1113 mutex_enter(&pp
->umutex
);
1115 ecpp_default_negotiation(pp
);
1118 (void) ecpp_idle_phase(pp
);
1121 "ecpp_open: mode=%x, phase=%x ecr=%x, dsr=%x, dcr=%x\n",
1122 pp
->current_mode
, pp
->current_phase
,
1123 ECR_READ(pp
), DSR_READ(pp
), DCR_READ(pp
));
1125 mutex_exit(&pp
->umutex
);
1132 ecpp_close(queue_t
*q
, int flag
, cred_t
*cred_p
)
1134 struct ecppunit
*pp
;
1135 timeout_id_t timeout_id
, fifo_timer_id
, wsrv_timer_id
;
1137 pp
= (struct ecppunit
*)q
->q_ptr
;
1139 ecpp_error(pp
->dip
, "ecpp_close: entering ...\n");
1141 mutex_enter(&pp
->umutex
);
1144 * ecpp_close() will continue to loop until the
1145 * queue has been drained or if the thread
1146 * has received a SIG. Typically, when the queue
1147 * has data, the port will be ECPP_BUSY. However,
1148 * after a dma completes and before the wsrv
1149 * starts the next transfer, the port may be IDLE.
1150 * In this case, ecpp_close() will loop within this
1151 * while(qsize) segment. Since, ecpp_wsrv() runs
1152 * at software interupt level, this shouldn't loop
1155 while (pp
->e_busy
!= ECPP_IDLE
|| qsize(WR(q
))) {
1156 if (!cv_wait_sig(&pp
->pport_cv
, &pp
->umutex
)) {
1157 ecpp_error(pp
->dip
, "ecpp_close:B: received SIG\n");
1159 * Returning from a signal such as
1160 * SIGTERM or SIGKILL
1162 ecpp_flush(pp
, FWRITE
);
1165 ecpp_error(pp
->dip
, "ecpp_close:rcvd cv-sig\n");
1169 ecpp_error(pp
->dip
, "ecpp_close: joblen=%d, ctx_cf=%d, "
1170 "qsize(WR(q))=%d, qsize(RD(q))=%d\n",
1171 pp
->joblen
, pp
->ctx_cf
, qsize(pp
->writeq
), qsize(q
));
1174 * Cancel all timeouts, disable interrupts
1176 * Note that we can`t call untimeout(9F) with mutex held:
1177 * callout may be blocked on the same mutex, and untimeout() will
1178 * cv_wait() while callout is executing, thus creating a deadlock
1179 * So we zero the timeout id's inside mutex and call untimeout later
1181 timeout_id
= pp
->timeout_id
;
1182 fifo_timer_id
= pp
->fifo_timer_id
;
1183 wsrv_timer_id
= pp
->wsrv_timer_id
;
1185 pp
->timeout_id
= pp
->fifo_timer_id
= pp
->wsrv_timer_id
= 0;
1187 pp
->softintr_pending
= 0;
1188 pp
->dma_cancelled
= TRUE
;
1191 mutex_exit(&pp
->umutex
);
1196 (void) untimeout(timeout_id
);
1198 if (fifo_timer_id
) {
1199 (void) untimeout(fifo_timer_id
);
1201 if (wsrv_timer_id
) {
1202 (void) untimeout(wsrv_timer_id
);
1205 mutex_enter(&pp
->umutex
);
1207 /* set link to Compatible mode */
1208 if ((pp
->current_mode
== ECPP_ECP_MODE
) &&
1209 (pp
->current_phase
!= ECPP_PHASE_ECP_FWD_IDLE
)) {
1210 (void) ecp_reverse2forward(pp
);
1213 (void) ecpp_1284_termination(pp
);
1216 q
->q_ptr
= WR(q
)->q_ptr
= NULL
;
1217 pp
->readq
= pp
->writeq
= NULL
;
1220 ecpp_error(pp
->dip
, "ecpp_close: ecr=%x, dsr=%x, dcr=%x\n",
1221 ECR_READ(pp
), DSR_READ(pp
), DCR_READ(pp
));
1223 mutex_exit(&pp
->umutex
);
1229 * standard put procedure for ecpp
1232 ecpp_wput(queue_t
*q
, mblk_t
*mp
)
1235 struct ecppunit
*pp
;
1237 pp
= (struct ecppunit
*)q
->q_ptr
;
1243 if ((mp
->b_wptr
- mp
->b_rptr
) <= 0) {
1245 "ecpp_wput:bogus packet recieved mp=%x\n", mp
);
1250 switch (DB_TYPE(mp
)) {
1253 * This is a quick fix for multiple message block problem,
1254 * it will be changed later with better performance code.
1258 * mblk has scattered data ... do msgpullup
1259 * if it fails, continue with the current mblk
1261 if ((nmp
= msgpullup(mp
, -1)) != NULL
) {
1265 "ecpp_wput:msgpullup: mp=%p len=%d\n",
1266 mp
, mp
->b_wptr
- mp
->b_rptr
);
1270 /* let ecpp_wsrv() concatenate small blocks */
1281 struct iocblk
*iocbp
;
1283 iocbp
= (struct iocblk
*)mp
->b_rptr
;
1285 ecpp_error(pp
->dip
, "ecpp_wput:M_IOCTL %x\n", iocbp
->ioc_cmd
);
1287 mutex_enter(&pp
->umutex
);
1289 /* TESTIO and GET_STATUS can be used during transfer */
1290 if ((pp
->e_busy
== ECPP_BUSY
) &&
1291 (iocbp
->ioc_cmd
!= BPPIOC_TESTIO
) &&
1292 (iocbp
->ioc_cmd
!= PRNIOC_GET_STATUS
)) {
1293 mutex_exit(&pp
->umutex
);
1296 mutex_exit(&pp
->umutex
);
1304 struct copyresp
*csp
;
1306 ecpp_error(pp
->dip
, "ecpp_wput:M_IOCDATA\n");
1308 csp
= (struct copyresp
*)mp
->b_rptr
;
1311 * If copy request failed, quit now
1313 if (csp
->cp_rval
!= 0) {
1318 switch (csp
->cp_cmd
) {
1319 case ECPPIOC_SETPARMS
:
1320 case ECPPIOC_SETREGS
:
1321 case ECPPIOC_SETPORT
:
1322 case ECPPIOC_SETDATA
:
1323 case PRNIOC_SET_IFCAP
:
1324 case PRNIOC_SET_TIMEOUTS
:
1326 * need to retrieve and use the data, but if the
1327 * device is busy, wait.
1332 case ECPPIOC_GETPARMS
:
1333 case ECPPIOC_GETREGS
:
1334 case ECPPIOC_GETPORT
:
1335 case ECPPIOC_GETDATA
:
1338 case PRNIOC_GET_IFCAP
:
1339 case PRNIOC_GET_STATUS
:
1340 case PRNIOC_GET_1284_STATUS
:
1341 case PRNIOC_GET_TIMEOUTS
:
1342 /* data transfered to user space okay */
1343 ecpp_ack_ioctl(q
, mp
);
1346 case ECPPIOC_GETDEVID
:
1347 ecpp_wput_iocdata_devid(q
, mp
,
1348 offsetof(struct ecpp_device_id
, rlen
));
1351 case PRNIOC_GET_1284_DEVID
:
1352 ecpp_wput_iocdata_devid(q
, mp
,
1353 offsetof(struct prn_1284_device_id
, id_rlen
));
1356 case PRNIOC_GET_IFINFO
:
1357 ecpp_wput_iocdata_devid(q
, mp
,
1358 offsetof(struct prn_interface_info
, if_rlen
));
1362 ecpp_nack_ioctl(q
, mp
, EINVAL
);
1370 ecpp_error(pp
->dip
, "ecpp_wput:M_FLUSH\n");
1372 if (*mp
->b_rptr
& FLUSHW
) {
1373 mutex_enter(&pp
->umutex
);
1374 ecpp_flush(pp
, FWRITE
);
1375 mutex_exit(&pp
->umutex
);
1378 if (*mp
->b_rptr
& FLUSHR
) {
1379 mutex_enter(&pp
->umutex
);
1380 ecpp_flush(pp
, FREAD
);
1381 mutex_exit(&pp
->umutex
);
1391 * When the user calls read(2), M_READ message is sent to us,
1392 * first byte of which is the number of requested bytes
1393 * We add up user requests and use resulting number
1394 * to calculate the reverse transfer block size
1396 mutex_enter(&pp
->umutex
);
1397 if (pp
->e_busy
== ECPP_IDLE
) {
1398 pp
->nread
+= *(size_t *)mp
->b_rptr
;
1399 ecpp_error(pp
->dip
, "ecpp_wput: M_READ %d", pp
->nread
);
1402 ecpp_error(pp
->dip
, "ecpp_wput: M_READ queueing");
1405 mutex_exit(&pp
->umutex
);
1409 ecpp_error(pp
->dip
, "ecpp_wput: bad messagetype 0x%x\n",
1419 * Process ECPPIOC_GETDEVID-like ioctls
1422 ecpp_wput_iocdata_devid(queue_t
*q
, mblk_t
*mp
, uintptr_t rlen_offset
)
1424 struct copyresp
*csp
;
1425 struct ecpp_copystate
*stp
;
1428 csp
= (struct copyresp
*)mp
->b_rptr
;
1429 stp
= (struct ecpp_copystate
*)csp
->cp_private
->b_rptr
;
1431 /* determine the state of copyin/copyout process */
1432 switch (stp
->state
) {
1434 /* user structure has arrived */
1440 * data transfered to user space okay
1441 * now update user structure
1443 datamp
= allocb(sizeof (int), BPRI_MED
);
1444 if (datamp
== NULL
) {
1445 ecpp_nack_ioctl(q
, mp
, ENOSR
);
1449 *(int *)datamp
->b_rptr
=
1450 *(int *)((char *)&stp
->un
+ rlen_offset
);
1451 stp
->state
= ECPP_STRUCTOUT
;
1453 mcopyout(mp
, csp
->cp_private
, sizeof (int),
1454 (char *)stp
->uaddr
+ rlen_offset
, datamp
);
1458 case ECPP_STRUCTOUT
:
1459 /* user structure was updated okay */
1460 freemsg(csp
->cp_private
);
1461 ecpp_ack_ioctl(q
, mp
);
1465 ecpp_nack_ioctl(q
, mp
, EINVAL
);
1471 ecpp_get_error_status(uchar_t status
)
1473 uchar_t pin_status
= 0;
1475 if (!(status
& ECPP_nERR
)) {
1476 pin_status
|= BPP_ERR_ERR
;
1479 if (status
& ECPP_PE
) {
1480 pin_status
|= BPP_PE_ERR
;
1483 if (!(status
& ECPP_SLCT
)) {
1484 pin_status
|= BPP_SLCT_ERR
;
1487 if (!(status
& ECPP_nBUSY
)) {
1488 pin_status
|= BPP_SLCT_ERR
;
1491 return (pin_status
);
1495 * ioctl handler for output PUT procedure.
1498 ecpp_putioc(queue_t
*q
, mblk_t
*mp
)
1500 struct iocblk
*iocbp
;
1501 struct ecppunit
*pp
;
1503 pp
= (struct ecppunit
*)q
->q_ptr
;
1505 iocbp
= (struct iocblk
*)mp
->b_rptr
;
1507 /* I_STR ioctls are invalid */
1508 if (iocbp
->ioc_count
!= TRANSPARENT
) {
1509 ecpp_nack_ioctl(q
, mp
, EINVAL
);
1513 switch (iocbp
->ioc_cmd
) {
1514 case ECPPIOC_SETPARMS
: {
1515 mcopyin(mp
, NULL
, sizeof (struct ecpp_transfer_parms
), NULL
);
1520 case ECPPIOC_GETPARMS
: {
1521 struct ecpp_transfer_parms xfer_parms
;
1523 mutex_enter(&pp
->umutex
);
1525 pp
->xfer_parms
.mode
= pp
->current_mode
;
1526 xfer_parms
= pp
->xfer_parms
;
1528 mutex_exit(&pp
->umutex
);
1530 ecpp_putioc_copyout(q
, mp
, &xfer_parms
, sizeof (xfer_parms
));
1534 case ECPPIOC_SETREGS
: {
1535 mutex_enter(&pp
->umutex
);
1536 if (pp
->current_mode
!= ECPP_DIAG_MODE
) {
1537 mutex_exit(&pp
->umutex
);
1538 ecpp_nack_ioctl(q
, mp
, EINVAL
);
1541 mutex_exit(&pp
->umutex
);
1543 mcopyin(mp
, NULL
, sizeof (struct ecpp_regs
), NULL
);
1548 case ECPPIOC_GETREGS
: {
1549 struct ecpp_regs rg
;
1551 mutex_enter(&pp
->umutex
);
1553 if (pp
->current_mode
!= ECPP_DIAG_MODE
) {
1554 mutex_exit(&pp
->umutex
);
1555 ecpp_nack_ioctl(q
, mp
, EINVAL
);
1559 rg
.dsr
= DSR_READ(pp
);
1560 rg
.dcr
= DCR_READ(pp
);
1562 mutex_exit(&pp
->umutex
);
1564 ecpp_error(pp
->dip
, "ECPPIOC_GETREGS: dsr=%x,dcr=%x\n",
1567 /* these bits must be 1 */
1568 rg
.dsr
|= ECPP_SETREGS_DSR_MASK
;
1569 rg
.dcr
|= ECPP_SETREGS_DCR_MASK
;
1571 ecpp_putioc_copyout(q
, mp
, &rg
, sizeof (rg
));
1575 case ECPPIOC_SETPORT
:
1576 case ECPPIOC_SETDATA
: {
1577 mutex_enter(&pp
->umutex
);
1578 if (pp
->current_mode
!= ECPP_DIAG_MODE
) {
1579 mutex_exit(&pp
->umutex
);
1580 ecpp_nack_ioctl(q
, mp
, EINVAL
);
1583 mutex_exit(&pp
->umutex
);
1586 * each of the commands fetches a byte quantity.
1588 mcopyin(mp
, NULL
, sizeof (uchar_t
), NULL
);
1593 case ECPPIOC_GETDATA
:
1594 case ECPPIOC_GETPORT
: {
1597 mutex_enter(&pp
->umutex
);
1599 /* must be in diagnostic mode for these commands to work */
1600 if (pp
->current_mode
!= ECPP_DIAG_MODE
) {
1601 mutex_exit(&pp
->umutex
);
1602 ecpp_nack_ioctl(q
, mp
, EINVAL
);
1606 if (iocbp
->ioc_cmd
== ECPPIOC_GETPORT
) {
1608 } else if (iocbp
->ioc_cmd
== ECPPIOC_GETDATA
) {
1611 byte
= DATAR_READ(pp
);
1613 case ECPP_PORT_TDMA
:
1614 byte
= TFIFO_READ(pp
);
1615 ecpp_error(pp
->dip
, "GETDATA=0x%x\n", byte
);
1618 ecpp_nack_ioctl(q
, mp
, EINVAL
);
1622 mutex_exit(&pp
->umutex
);
1623 ecpp_error(pp
->dip
, "weird command");
1624 ecpp_nack_ioctl(q
, mp
, EINVAL
);
1628 mutex_exit(&pp
->umutex
);
1630 ecpp_putioc_copyout(q
, mp
, &byte
, sizeof (byte
));
1635 case BPPIOC_GETERR
: {
1636 struct bpp_error_status bpp_status
;
1638 mutex_enter(&pp
->umutex
);
1640 bpp_status
.timeout_occurred
= pp
->timeout_error
;
1641 bpp_status
.bus_error
= 0; /* not used */
1642 bpp_status
.pin_status
= ecpp_get_error_status(pp
->saved_dsr
);
1644 mutex_exit(&pp
->umutex
);
1646 ecpp_putioc_copyout(q
, mp
, &bpp_status
, sizeof (bpp_status
));
1651 case BPPIOC_TESTIO
: {
1652 mutex_enter(&pp
->umutex
);
1654 if (!((pp
->current_mode
== ECPP_CENTRONICS
) ||
1655 (pp
->current_mode
== ECPP_COMPAT_MODE
))) {
1656 ecpp_nack_ioctl(q
, mp
, EINVAL
);
1658 pp
->saved_dsr
= DSR_READ(pp
);
1660 if ((pp
->saved_dsr
& ECPP_PE
) ||
1661 !(pp
->saved_dsr
& ECPP_SLCT
) ||
1662 !(pp
->saved_dsr
& ECPP_nERR
)) {
1663 ecpp_nack_ioctl(q
, mp
, EIO
);
1665 ecpp_ack_ioctl(q
, mp
);
1669 mutex_exit(&pp
->umutex
);
1676 * Initialize interface only if no transfer is in progress
1678 mutex_enter(&pp
->umutex
);
1679 if (pp
->e_busy
== ECPP_BUSY
) {
1680 mutex_exit(&pp
->umutex
);
1681 ecpp_nack_ioctl(q
, mp
, EIO
);
1683 (void) ecpp_mode_negotiation(pp
, ECPP_CENTRONICS
);
1685 DCR_WRITE(pp
, ECPP_SLCTIN
);
1687 DCR_WRITE(pp
, ECPP_SLCTIN
| ECPP_nINIT
);
1689 ecpp_default_negotiation(pp
);
1691 mutex_exit(&pp
->umutex
);
1692 ecpp_ack_ioctl(q
, mp
);
1696 case PRNIOC_GET_IFCAP
: {
1699 mutex_enter(&pp
->umutex
);
1701 ifcap
= ecpp_get_prn_ifcap(pp
);
1703 mutex_exit(&pp
->umutex
);
1705 ecpp_putioc_copyout(q
, mp
, &ifcap
, sizeof (ifcap
));
1709 case PRNIOC_SET_IFCAP
: {
1710 mcopyin(mp
, NULL
, sizeof (uint_t
), NULL
);
1715 case PRNIOC_GET_TIMEOUTS
: {
1716 struct prn_timeouts timeouts
;
1718 mutex_enter(&pp
->umutex
);
1719 timeouts
= pp
->prn_timeouts
;
1720 mutex_exit(&pp
->umutex
);
1722 ecpp_putioc_copyout(q
, mp
, &timeouts
, sizeof (timeouts
));
1727 case PRNIOC_SET_TIMEOUTS
:
1728 mcopyin(mp
, NULL
, sizeof (struct prn_timeouts
),
1729 *(caddr_t
*)(void *)mp
->b_cont
->b_rptr
);
1733 case PRNIOC_GET_STATUS
: {
1737 mutex_enter(&pp
->umutex
);
1739 /* DSR only makes sense in Centronics & Compat mode */
1740 if (pp
->current_mode
== ECPP_CENTRONICS
||
1741 pp
->current_mode
== ECPP_COMPAT_MODE
) {
1743 if ((dsr
& ECPP_PE
) ||
1744 !(dsr
& ECPP_SLCT
) || !(dsr
& ECPP_nERR
)) {
1745 status
= PRN_ONLINE
;
1747 status
= PRN_ONLINE
| PRN_READY
;
1750 status
= PRN_ONLINE
| PRN_READY
;
1753 mutex_exit(&pp
->umutex
);
1755 ecpp_putioc_copyout(q
, mp
, &status
, sizeof (status
));
1759 case PRNIOC_GET_1284_STATUS
: {
1763 mutex_enter(&pp
->umutex
);
1765 /* status only makes sense in Centronics & Compat mode */
1766 if (pp
->current_mode
!= ECPP_COMPAT_MODE
&&
1767 pp
->current_mode
!= ECPP_CENTRONICS
) {
1768 mutex_exit(&pp
->umutex
);
1769 ecpp_nack_ioctl(q
, mp
, EINVAL
);
1773 dsr
= DSR_READ(pp
); /* read status */
1775 mutex_exit(&pp
->umutex
);
1777 ecpp_error(pp
->dip
, "PRNIOC_GET_STATUS: %x\n", dsr
);
1779 status
= (dsr
& (ECPP_SLCT
| ECPP_PE
| ECPP_nERR
)) |
1780 (~dsr
& ECPP_nBUSY
);
1782 ecpp_putioc_copyout(q
, mp
, &status
, sizeof (status
));
1786 case ECPPIOC_GETDEVID
:
1787 ecpp_putioc_stateful_copyin(q
, mp
,
1788 sizeof (struct ecpp_device_id
));
1791 case PRNIOC_GET_1284_DEVID
:
1792 ecpp_putioc_stateful_copyin(q
, mp
,
1793 sizeof (struct prn_1284_device_id
));
1796 case PRNIOC_GET_IFINFO
:
1797 ecpp_putioc_stateful_copyin(q
, mp
,
1798 sizeof (struct prn_interface_info
));
1802 ecpp_error(pp
->dip
, "putioc: unknown IOCTL: %x\n",
1804 ecpp_nack_ioctl(q
, mp
, EINVAL
);
1810 * allocate mblk and copyout the requested number of bytes
1813 ecpp_putioc_copyout(queue_t
*q
, mblk_t
*mp
, void *buf
, int len
)
1817 if ((tmp
= allocb(len
, BPRI_MED
)) == NULL
) {
1818 ecpp_nack_ioctl(q
, mp
, ENOSR
);
1822 bcopy(buf
, tmp
->b_wptr
, len
);
1824 mcopyout(mp
, NULL
, len
, NULL
, tmp
);
1829 * copyin the structure using struct ecpp_copystate
1832 ecpp_putioc_stateful_copyin(queue_t
*q
, mblk_t
*mp
, size_t size
)
1835 struct ecpp_copystate
*stp
;
1837 if ((tmp
= allocb(sizeof (struct ecpp_copystate
), BPRI_MED
)) == NULL
) {
1838 ecpp_nack_ioctl(q
, mp
, EAGAIN
);
1842 stp
= (struct ecpp_copystate
*)tmp
->b_rptr
;
1843 stp
->state
= ECPP_STRUCTIN
;
1844 stp
->uaddr
= *(caddr_t
*)mp
->b_cont
->b_rptr
;
1846 tmp
->b_wptr
+= sizeof (struct ecpp_copystate
);
1848 mcopyin(mp
, tmp
, size
, stp
->uaddr
);
1853 * read queue is only used when the peripheral sends data faster,
1854 * then the application consumes it;
1855 * once the low water mark is reached, this routine will be scheduled
1858 ecpp_rsrv(queue_t
*q
)
1863 * send data upstream until next queue is full or the queue is empty
1865 while (canputnext(q
) && (mp
= getq(q
))) {
1870 * if there is still space on the queue, enable backchannel
1872 if (canputnext(q
)) {
1873 struct ecppunit
*pp
= (struct ecppunit
*)q
->q_ptr
;
1875 mutex_enter(&pp
->umutex
);
1877 if (pp
->e_busy
== ECPP_IDLE
) {
1878 (void) ecpp_idle_phase(pp
);
1879 cv_signal(&pp
->pport_cv
); /* signal ecpp_close() */
1882 mutex_exit(&pp
->umutex
);
1889 ecpp_wsrv(queue_t
*q
)
1891 struct ecppunit
*pp
= (struct ecppunit
*)q
->q_ptr
;
1893 size_t len
, total_len
;
1894 size_t my_ioblock_sz
;
1898 mutex_enter(&pp
->umutex
);
1900 ecpp_error(pp
->dip
, "ecpp_wsrv: e_busy=%x\n", pp
->e_busy
);
1902 /* if channel is actively doing work, wait till completed */
1903 if (pp
->e_busy
== ECPP_BUSY
|| pp
->e_busy
== ECPP_FLUSH
) {
1904 mutex_exit(&pp
->umutex
);
1906 } else if (pp
->suspended
== TRUE
) {
1908 * if the system is about to suspend and ecpp_detach()
1909 * is blocked due to active transfers, wake it up and exit
1911 cv_signal(&pp
->pport_cv
);
1912 mutex_exit(&pp
->umutex
);
1916 /* peripheral status should be okay before starting transfer */
1917 if (pp
->e_busy
== ECPP_ERR
) {
1918 if (ecpp_check_status(pp
) == FAILURE
) {
1919 if (pp
->wsrv_timer_id
== 0) {
1920 ecpp_error(pp
->dip
, "wsrv: start wrsv_timer\n");
1921 pp
->wsrv_timer_id
= timeout(ecpp_wsrv_timer
,
1923 drv_usectohz(pp
->wsrv_retry
* 1000));
1926 "ecpp_wsrv: wrsv_timer is active\n");
1929 mutex_exit(&pp
->umutex
);
1932 pp
->e_busy
= ECPP_IDLE
;
1936 my_ioblock
= pp
->ioblock
;
1937 my_ioblock_sz
= IO_BLOCK_SZ
;
1940 * it`s important to null pp->msg here,
1941 * cleaning up from the previous transfer attempts
1946 len
= total_len
= 0;
1948 * The following loop is implemented to gather the
1949 * many small writes that the lp subsystem makes and
1950 * compile them into one large dma transfer. The len and
1951 * total_len variables are a running count of the number of
1952 * bytes that have been gathered. They are bcopied to the
1953 * ioblock buffer. The pp->e_busy is set to E_BUSY as soon as
1954 * we start gathering packets to indicate the following transfer.
1956 while (mp
= getq(q
)) {
1957 switch (DB_TYPE(mp
)) {
1959 pp
->e_busy
= ECPP_BUSY
;
1960 len
= mp
->b_wptr
- mp
->b_rptr
;
1962 if ((total_len
== 0) && (len
>= my_ioblock_sz
)) {
1964 * if the first M_DATA is bigger than ioblock,
1965 * just use this mblk and start the transfer
1968 start_addr
= (caddr_t
)mp
->b_rptr
;
1971 } else if (total_len
+ len
> my_ioblock_sz
) {
1973 * current M_DATA does not fit in ioblock,
1974 * put it back and start the transfer
1976 (void) putbq(q
, mp
);
1980 * otherwise add data to ioblock and free mblk
1982 bcopy(mp
->b_rptr
, my_ioblock
, len
);
1985 start_addr
= (caddr_t
)pp
->ioblock
;
1992 * Assume a simple loopback test: an application
1993 * writes data into the TFIFO, reads it using
1994 * ECPPIOC_GETDATA and compares. If the transfer
1995 * times out (which is only possible on Grover),
1996 * the ioctl might be processed before the data
1997 * got to the TFIFO, which leads to miscompare.
1998 * So if we met ioctl, postpone it until after xfer.
2000 if (total_len
> 0) {
2001 (void) putbq(q
, mp
);
2005 ecpp_error(pp
->dip
, "M_IOCTL.\n");
2007 mutex_exit(&pp
->umutex
);
2011 mutex_enter(&pp
->umutex
);
2016 struct copyresp
*csp
= (struct copyresp
*)mp
->b_rptr
;
2018 ecpp_error(pp
->dip
, "M_IOCDATA\n");
2021 * If copy request failed, quit now
2023 if (csp
->cp_rval
!= 0) {
2028 switch (csp
->cp_cmd
) {
2029 case ECPPIOC_SETPARMS
:
2030 case ECPPIOC_SETREGS
:
2031 case ECPPIOC_SETPORT
:
2032 case ECPPIOC_SETDATA
:
2033 case ECPPIOC_GETDEVID
:
2034 case PRNIOC_SET_IFCAP
:
2035 case PRNIOC_GET_1284_DEVID
:
2036 case PRNIOC_SET_TIMEOUTS
:
2037 case PRNIOC_GET_IFINFO
:
2042 ecpp_nack_ioctl(q
, mp
, EINVAL
);
2050 if (pp
->e_busy
!= ECPP_IDLE
) {
2051 ecpp_error(pp
->dip
, "wsrv: M_CTL postponed\n");
2052 (void) putbq(q
, mp
);
2055 ecpp_error(pp
->dip
, "wsrv: M_CTL\n");
2059 if ((mp
->b_wptr
- mp
->b_rptr
!= sizeof (int)) ||
2060 (*(int *)mp
->b_rptr
!= ECPP_BACKCHANNEL
)) {
2061 ecpp_error(pp
->dip
, "wsrv: bogus M_CTL");
2068 /* This was a backchannel request */
2069 (void) ecpp_peripheral2host(pp
);
2071 /* exit if transfer have been initiated */
2072 if (pp
->e_busy
== ECPP_BUSY
) {
2078 pp
->nread
+= *(size_t *)mp
->b_rptr
;
2080 ecpp_error(pp
->dip
, "wsrv: M_READ %d", pp
->nread
);
2084 ecpp_error(pp
->dip
, "wsrv: should never get here\n");
2091 * If total_len > 0 then start the transfer, otherwise goto idle state
2093 if (total_len
> 0) {
2094 ecpp_error(pp
->dip
, "wsrv:starting: total_len=%d\n", total_len
);
2095 pp
->e_busy
= ECPP_BUSY
;
2096 ecpp_start(pp
, start_addr
, total_len
);
2098 ecpp_error(pp
->dip
, "wsrv:finishing: ebusy=%x\n", pp
->e_busy
);
2100 /* IDLE if xfer_timeout, or FIFO_EMPTY */
2101 if (pp
->e_busy
== ECPP_IDLE
) {
2102 (void) ecpp_idle_phase(pp
);
2103 cv_signal(&pp
->pport_cv
); /* signal ecpp_close() */
2107 mutex_exit(&pp
->umutex
);
2112 * Ioctl processor for queued ioctl data transfer messages.
2115 ecpp_srvioc(queue_t
*q
, mblk_t
*mp
)
2117 struct iocblk
*iocbp
;
2118 struct ecppunit
*pp
;
2120 iocbp
= (struct iocblk
*)mp
->b_rptr
;
2121 pp
= (struct ecppunit
*)q
->q_ptr
;
2123 switch (iocbp
->ioc_cmd
) {
2124 case ECPPIOC_SETPARMS
: {
2125 struct ecpp_transfer_parms
*xferp
;
2127 xferp
= (struct ecpp_transfer_parms
*)mp
->b_cont
->b_rptr
;
2129 if (xferp
->write_timeout
<= 0 ||
2130 xferp
->write_timeout
>= ECPP_MAX_TIMEOUT
) {
2131 ecpp_nack_ioctl(q
, mp
, EINVAL
);
2135 if (!((xferp
->mode
== ECPP_CENTRONICS
) ||
2136 (xferp
->mode
== ECPP_COMPAT_MODE
) ||
2137 (xferp
->mode
== ECPP_NIBBLE_MODE
) ||
2138 (xferp
->mode
== ECPP_ECP_MODE
) ||
2139 (xferp
->mode
== ECPP_DIAG_MODE
))) {
2140 ecpp_nack_ioctl(q
, mp
, EINVAL
);
2144 pp
->xfer_parms
= *xferp
;
2145 pp
->prn_timeouts
.tmo_forward
= pp
->xfer_parms
.write_timeout
;
2147 ecpp_error(pp
->dip
, "srvioc: current_mode =%x new mode=%x\n",
2148 pp
->current_mode
, pp
->xfer_parms
.mode
);
2150 if (ecpp_mode_negotiation(pp
, pp
->xfer_parms
.mode
) == FAILURE
) {
2151 ecpp_nack_ioctl(q
, mp
, EPROTONOSUPPORT
);
2154 * mode nego was a success. If nibble mode check
2155 * back channel and set into REVIDLE.
2157 if ((pp
->current_mode
== ECPP_NIBBLE_MODE
) &&
2158 (read_nibble_backchan(pp
) == FAILURE
)) {
2160 * problems reading the backchannel
2161 * returned to centronics;
2164 ecpp_nack_ioctl(q
, mp
, EPROTONOSUPPORT
);
2168 ecpp_ack_ioctl(q
, mp
);
2170 if (pp
->current_mode
!= ECPP_DIAG_MODE
) {
2171 pp
->port
= ECPP_PORT_DMA
;
2173 pp
->port
= ECPP_PORT_PIO
;
2176 pp
->xfer_parms
.mode
= pp
->current_mode
;
2181 case ECPPIOC_SETREGS
: {
2182 struct ecpp_regs
*rg
;
2185 rg
= (struct ecpp_regs
*)mp
->b_cont
->b_rptr
;
2187 /* must be in diagnostic mode for these commands to work */
2188 if (pp
->current_mode
!= ECPP_DIAG_MODE
) {
2189 ecpp_nack_ioctl(q
, mp
, EINVAL
);
2193 /* bits 4-7 must be 1 or return EINVAL */
2194 if ((rg
->dcr
& ECPP_SETREGS_DCR_MASK
) !=
2195 ECPP_SETREGS_DCR_MASK
) {
2196 ecpp_nack_ioctl(q
, mp
, EINVAL
);
2200 /* get the old dcr */
2201 dcr
= DCR_READ(pp
) & ~ECPP_REV_DIR
;
2202 /* get the new dcr */
2203 dcr
= (dcr
& ECPP_SETREGS_DCR_MASK
) |
2204 (rg
->dcr
& ~ECPP_SETREGS_DCR_MASK
);
2206 ecpp_error(pp
->dip
, "ECPPIOC_SETREGS:dcr=%x\n", dcr
);
2207 ecpp_ack_ioctl(q
, mp
);
2211 case ECPPIOC_SETPORT
: {
2214 port
= (uchar_t
*)mp
->b_cont
->b_rptr
;
2216 /* must be in diagnostic mode for these commands to work */
2217 if (pp
->current_mode
!= ECPP_DIAG_MODE
) {
2218 ecpp_nack_ioctl(q
, mp
, EINVAL
);
2224 /* put superio into PIO mode */
2226 ECR_mode_001
| ECPP_INTR_MASK
| ECPP_INTR_SRV
);
2228 ecpp_ack_ioctl(q
, mp
);
2231 case ECPP_PORT_TDMA
:
2232 ecpp_error(pp
->dip
, "SETPORT: to TDMA\n");
2234 /* change to mode 110 */
2236 ECR_mode_110
| ECPP_INTR_MASK
| ECPP_INTR_SRV
);
2238 ecpp_ack_ioctl(q
, mp
);
2242 ecpp_nack_ioctl(q
, mp
, EINVAL
);
2248 case ECPPIOC_SETDATA
: {
2251 data
= (uchar_t
*)mp
->b_cont
->b_rptr
;
2253 /* must be in diagnostic mode for these commands to work */
2254 if (pp
->current_mode
!= ECPP_DIAG_MODE
) {
2255 ecpp_nack_ioctl(q
, mp
, EINVAL
);
2261 DATAR_WRITE(pp
, *data
);
2262 ecpp_ack_ioctl(q
, mp
);
2265 case ECPP_PORT_TDMA
:
2266 TFIFO_WRITE(pp
, *data
);
2267 ecpp_ack_ioctl(q
, mp
);
2271 ecpp_nack_ioctl(q
, mp
, EINVAL
);
2277 case ECPPIOC_GETDEVID
: {
2278 struct copyresp
*csp
;
2279 struct ecpp_copystate
*stp
;
2280 struct ecpp_device_id
*dp
;
2281 struct ecpp_device_id id
;
2283 csp
= (struct copyresp
*)mp
->b_rptr
;
2284 stp
= (struct ecpp_copystate
*)csp
->cp_private
->b_rptr
;
2285 dp
= (struct ecpp_device_id
*)mp
->b_cont
->b_rptr
;
2287 #ifdef _MULTI_DATAMODEL
2288 if (IOC_CONVERT_FROM(iocbp
) == IOC_ILP32
) {
2289 struct ecpp_device_id32
*dp32
;
2291 dp32
= (struct ecpp_device_id32
*)dp
;
2292 id
.mode
= dp32
->mode
;
2294 id
.addr
= (char *)(uintptr_t)dp32
->addr
;
2296 #endif /* _MULTI_DATAMODEL */
2298 #ifdef _MULTI_DATAMODEL
2300 #endif /* _MULTI_DATAMODEL */
2302 ecpp_srvioc_devid(q
, mp
, &id
, &stp
->un
.devid
.rlen
);
2306 case PRNIOC_GET_1284_DEVID
: {
2307 struct copyresp
*csp
;
2308 struct ecpp_copystate
*stp
;
2309 struct prn_1284_device_id
*dp
;
2310 struct ecpp_device_id id
;
2312 csp
= (struct copyresp
*)mp
->b_rptr
;
2313 stp
= (struct ecpp_copystate
*)csp
->cp_private
->b_rptr
;
2314 dp
= (struct prn_1284_device_id
*)mp
->b_cont
->b_rptr
;
2316 /* imitate struct ecpp_device_id */
2317 id
.mode
= ECPP_NIBBLE_MODE
;
2319 #ifdef _MULTI_DATAMODEL
2320 if (IOC_CONVERT_FROM(iocbp
) == IOC_ILP32
) {
2321 struct prn_1284_device_id32
*dp32
;
2323 dp32
= (struct prn_1284_device_id32
*)dp
;
2324 id
.len
= dp32
->id_len
;
2325 id
.addr
= (char *)(uintptr_t)dp32
->id_data
;
2327 #endif /* _MULTI_DATAMODEL */
2328 id
.len
= dp
->id_len
;
2329 id
.addr
= (char *)dp
->id_data
;
2330 #ifdef _MULTI_DATAMODEL
2332 #endif /* _MULTI_DATAMODEL */
2334 ecpp_srvioc_devid(q
, mp
, &id
,
2335 (int *)&stp
->un
.prn_devid
.id_rlen
);
2339 case PRNIOC_SET_IFCAP
: {
2340 uint_t ifcap
, new_ifcap
;
2342 ifcap
= ecpp_get_prn_ifcap(pp
);
2343 new_ifcap
= *(uint_t
*)mp
->b_cont
->b_rptr
;
2345 if (ifcap
== new_ifcap
) {
2346 ecpp_ack_ioctl(q
, mp
);
2350 /* only changing PRN_BIDI is supported */
2351 if ((ifcap
^ new_ifcap
) & ~PRN_BIDI
) {
2352 ecpp_nack_ioctl(q
, mp
, EINVAL
);
2356 if (new_ifcap
& PRN_BIDI
) { /* go bidirectional */
2357 ecpp_default_negotiation(pp
);
2358 } else { /* go unidirectional */
2359 (void) ecpp_mode_negotiation(pp
, ECPP_CENTRONICS
);
2362 ecpp_ack_ioctl(q
, mp
);
2366 case PRNIOC_SET_TIMEOUTS
: {
2367 struct prn_timeouts
*prn_timeouts
;
2369 prn_timeouts
= (struct prn_timeouts
*)mp
->b_cont
->b_rptr
;
2371 if (prn_timeouts
->tmo_forward
> ECPP_MAX_TIMEOUT
) {
2372 ecpp_nack_ioctl(q
, mp
, EINVAL
);
2376 pp
->prn_timeouts
= *prn_timeouts
;
2377 pp
->xfer_parms
.write_timeout
= (int)prn_timeouts
->tmo_forward
;
2379 ecpp_ack_ioctl(q
, mp
);
2383 case PRNIOC_GET_IFINFO
:
2384 ecpp_srvioc_prnif(q
, mp
);
2387 default: /* unexpected ioctl type */
2388 ecpp_nack_ioctl(q
, mp
, EINVAL
);
2394 ecpp_srvioc_devid(queue_t
*q
, mblk_t
*mp
, struct ecpp_device_id
*id
, int *rlen
)
2396 struct ecppunit
*pp
;
2397 struct copyresp
*csp
;
2398 struct ecpp_copystate
*stp
;
2404 pp
= (struct ecppunit
*)q
->q_ptr
;
2405 csp
= (struct copyresp
*)mp
->b_rptr
;
2406 stp
= (struct ecpp_copystate
*)csp
->cp_private
->b_rptr
;
2409 /* check arguments */
2410 if ((mode
< ECPP_CENTRONICS
) || (mode
> ECPP_ECP_MODE
)) {
2411 ecpp_error(pp
->dip
, "ecpp_srvioc_devid: mode=%x, len=%x\n",
2413 ecpp_nack_ioctl(q
, mp
, EINVAL
);
2417 /* Currently only Nibble mode is supported */
2418 if (mode
!= ECPP_NIBBLE_MODE
) {
2419 ecpp_nack_ioctl(q
, mp
, EPROTONOSUPPORT
);
2423 if ((id
->addr
== NULL
) && (id
->len
!= 0)) {
2424 ecpp_nack_ioctl(q
, mp
, EFAULT
);
2428 /* read device ID length */
2429 if (error
= ecpp_getdevid(pp
, NULL
, &len
, mode
)) {
2430 ecpp_nack_ioctl(q
, mp
, error
);
2434 /* don't take into account two length bytes */
2438 /* limit transfer to user buffer length */
2439 if (id
->len
< len
) {
2444 /* just return rlen */
2445 stp
->state
= ECPP_ADDROUT
;
2446 ecpp_wput_iocdata_devid(q
, mp
,
2447 (uintptr_t)rlen
- (uintptr_t)&stp
->un
);
2451 if ((datamp
= allocb(len
, BPRI_MED
)) == NULL
) {
2452 ecpp_nack_ioctl(q
, mp
, ENOSR
);
2456 /* read ID string */
2457 error
= ecpp_getdevid(pp
, datamp
->b_rptr
, &len
, mode
);
2460 ecpp_nack_ioctl(q
, mp
, error
);
2463 datamp
->b_wptr
+= len
;
2465 stp
->state
= ECPP_ADDROUT
;
2466 mcopyout(mp
, csp
->cp_private
, len
, id
->addr
, datamp
);
2473 (void) ecpp_1284_termination(pp
);
2477 * PRNIOC_GET_IFINFO: return prnio interface info string
2480 ecpp_srvioc_prnif(queue_t
*q
, mblk_t
*mp
)
2482 struct copyresp
*csp
;
2483 struct ecpp_copystate
*stp
;
2485 struct prn_interface_info
*ip
;
2486 struct prn_interface_info info
;
2488 #ifdef _MULTI_DATAMODEL
2489 struct iocblk
*iocbp
= (struct iocblk
*)mp
->b_rptr
;
2492 csp
= (struct copyresp
*)mp
->b_rptr
;
2493 stp
= (struct ecpp_copystate
*)csp
->cp_private
->b_rptr
;
2494 ip
= (struct prn_interface_info
*)mp
->b_cont
->b_rptr
;
2496 #ifdef _MULTI_DATAMODEL
2497 if (IOC_CONVERT_FROM(iocbp
) == IOC_ILP32
) {
2498 struct prn_interface_info32
*ip32
;
2500 ip32
= (struct prn_interface_info32
*)ip
;
2501 info
.if_len
= ip32
->if_len
;
2502 info
.if_data
= (char *)(uintptr_t)ip32
->if_data
;
2504 #endif /* _MULTI_DATAMODEL */
2506 #ifdef _MULTI_DATAMODEL
2508 #endif /* _MULTI_DATAMODEL */
2510 len
= strlen(prn_ifinfo
);
2511 stp
->un
.prn_if
.if_rlen
= len
;
2512 stp
->state
= ECPP_ADDROUT
;
2514 /* check arguments */
2515 if ((info
.if_data
== NULL
) && (info
.if_len
!= 0)) {
2516 ecpp_nack_ioctl(q
, mp
, EFAULT
);
2520 if (info
.if_len
== 0) {
2521 /* just copyout rlen */
2522 ecpp_wput_iocdata_devid(q
, mp
,
2523 offsetof(struct prn_interface_info
, if_rlen
));
2527 /* if needed, trim to the buffer size */
2528 if (len
> info
.if_len
) {
2532 if ((datamp
= allocb(len
, BPRI_MED
)) == NULL
) {
2533 ecpp_nack_ioctl(q
, mp
, ENOSR
);
2537 bcopy(&prn_ifinfo
[0], datamp
->b_wptr
, len
);
2538 datamp
->b_wptr
+= len
;
2540 mcopyout(mp
, csp
->cp_private
, len
, info
.if_data
, datamp
);
2545 ecpp_flush(struct ecppunit
*pp
, int cmd
)
2549 timeout_id_t timeout_id
, fifo_timer_id
, wsrv_timer_id
;
2551 ASSERT(mutex_owned(&pp
->umutex
));
2553 if (!(cmd
& FWRITE
)) {
2558 timeout_id
= fifo_timer_id
= wsrv_timer_id
= 0;
2560 ecpp_error(pp
->dip
, "ecpp_flush e_busy=%x\n", pp
->e_busy
);
2562 /* if there is an ongoing DMA, it needs to be turned off. */
2563 switch (pp
->e_busy
) {
2566 * Change the port status to ECPP_FLUSH to
2567 * indicate to ecpp_wsrv that the wq is being flushed.
2569 pp
->e_busy
= ECPP_FLUSH
;
2572 * dma_cancelled indicates to ecpp_isr() that we have
2573 * turned off the DMA. Since the mutex is held, ecpp_isr()
2574 * may be blocked. Once ecpp_flush() finishes and ecpp_isr()
2575 * gains the mutex, ecpp_isr() will have a _reset_ DMAC. Most
2576 * significantly, the DMAC will be reset after ecpp_isr() was
2577 * invoked. Therefore we need to have a flag "dma_cancelled"
2578 * to signify when the described condition has occured. If
2579 * ecpp_isr() notes a dma_cancelled, it will ignore the DMAC csr
2580 * and simply claim the interupt.
2583 pp
->dma_cancelled
= TRUE
;
2585 /* either DMA or PIO transfer */
2586 if (COMPAT_DMA(pp
) ||
2587 (pp
->current_mode
== ECPP_ECP_MODE
) ||
2588 (pp
->current_mode
== ECPP_DIAG_MODE
)) {
2590 * if the bcr is zero, then DMA is complete and
2591 * we are waiting for the fifo to drain. Therefore,
2594 if (ECPP_DMA_STOP(pp
, NULL
) == FAILURE
) {
2596 "ecpp_flush: dma_stop failed.\n");
2600 * If the status of the port is ECPP_BUSY,
2601 * the DMA is stopped by either explicitly above, or by
2602 * ecpp_isr() but the FIFO hasn't drained yet. In either
2603 * case, we need to unbind the dma mappings.
2605 if (ddi_dma_unbind_handle(
2606 pp
->dma_handle
) != DDI_SUCCESS
)
2608 "ecpp_flush: unbind failed.\n");
2610 if (pp
->msg
!= NULL
) {
2616 * PIO transfer: disable nAck interrups
2619 dcr
&= ~(ECPP_REV_DIR
| ECPP_INTR_EN
);
2625 * The transfer is cleaned up. There may or may not be data
2626 * in the fifo. We don't care at this point. Ie. SuperIO may
2627 * transfer the remaining bytes in the fifo or not. it doesn't
2628 * matter. All that is important at this stage is that no more
2629 * fifo timers are started.
2632 timeout_id
= pp
->timeout_id
;
2633 fifo_timer_id
= pp
->fifo_timer_id
;
2634 pp
->timeout_id
= pp
->fifo_timer_id
= 0;
2635 pp
->softintr_pending
= 0;
2641 * Change the port status to ECPP_FLUSH to
2642 * indicate to ecpp_wsrv that the wq is being flushed.
2644 pp
->e_busy
= ECPP_FLUSH
;
2647 * Most likely there are mblks in the queue,
2648 * but the driver can not transmit because
2649 * of the bad port status. In this case,
2650 * ecpp_flush() should make sure ecpp_wsrv_timer()
2653 wsrv_timer_id
= pp
->wsrv_timer_id
;
2654 pp
->wsrv_timer_id
= 0;
2659 /* No work to do. Ready to flush */
2664 "ecpp_flush: illegal state %x\n", pp
->e_busy
);
2667 /* in DIAG mode clear TFIFO if needed */
2668 if (pp
->current_mode
== ECPP_DIAG_MODE
) {
2670 if (!(ecr
& ECPP_FIFO_EMPTY
)) {
2672 ECPP_INTR_SRV
| ECPP_INTR_MASK
| ECR_mode_001
);
2677 /* Discard all messages on the output queue. */
2678 flushq(q
, FLUSHDATA
);
2680 /* The port is no longer flushing or dma'ing for that matter. */
2681 pp
->e_busy
= ECPP_IDLE
;
2683 /* Set the right phase */
2684 if (pp
->current_mode
== ECPP_ECP_MODE
) {
2685 if (pp
->current_phase
== ECPP_PHASE_ECP_REV_XFER
) {
2686 pp
->current_phase
= ECPP_PHASE_ECP_REV_IDLE
;
2688 pp
->current_phase
= ECPP_PHASE_ECP_FWD_IDLE
;
2692 /* cancel timeouts if any */
2693 mutex_exit(&pp
->umutex
);
2696 (void) untimeout(timeout_id
);
2698 if (fifo_timer_id
) {
2699 (void) untimeout(fifo_timer_id
);
2701 if (wsrv_timer_id
) {
2702 (void) untimeout(wsrv_timer_id
);
2705 mutex_enter(&pp
->umutex
);
2707 cv_signal(&pp
->pport_cv
); /* wake up ecpp_close() */
2711 ecpp_start(struct ecppunit
*pp
, caddr_t addr
, size_t len
)
2713 ASSERT(mutex_owned(&pp
->umutex
));
2714 ASSERT(pp
->e_busy
== ECPP_BUSY
);
2717 "ecpp_start:current_mode=%x,current_phase=%x,ecr=%x,len=%d\n",
2718 pp
->current_mode
, pp
->current_phase
, ECR_READ(pp
), len
);
2720 pp
->dma_dir
= DDI_DMA_WRITE
; /* this is a forward transfer */
2722 switch (pp
->current_mode
) {
2723 case ECPP_NIBBLE_MODE
:
2724 (void) ecpp_1284_termination(pp
);
2726 /* After termination we are either Compatible or Centronics */
2730 case ECPP_CENTRONICS
:
2731 case ECPP_COMPAT_MODE
:
2732 if (pp
->io_mode
== ECPP_DMA
) {
2733 if (ecpp_init_dma_xfer(pp
, addr
, len
) == FAILURE
) {
2738 if (ecpp_prep_pio_xfer(pp
, addr
, len
) == FAILURE
) {
2741 (void) ecpp_pio_writeb(pp
);
2745 case ECPP_DIAG_MODE
: {
2748 /* put superio into TFIFO mode, if not already */
2749 ECR_WRITE(pp
, ECPP_INTR_SRV
| ECPP_INTR_MASK
| ECR_mode_110
);
2751 * DMA would block if the TFIFO is not empty
2752 * if by this moment nobody read these bytes, they`re gone
2755 if (!(ECR_READ(pp
) & ECPP_FIFO_EMPTY
)) {
2757 "ecpp_start: TFIFO not empty, clearing\n");
2759 ECPP_INTR_SRV
| ECPP_INTR_MASK
| ECR_mode_001
);
2761 ECPP_INTR_SRV
| ECPP_INTR_MASK
| ECR_mode_110
);
2764 /* we can DMA at most 16 bytes into TFIFO */
2766 if (len
> ECPP_FIFO_SZ
) {
2770 if (ecpp_init_dma_xfer(pp
, addr
, len
) == FAILURE
) {
2774 /* put the rest of data back on the queue */
2776 ecpp_putback_untransfered(pp
, addr
+ len
, oldlen
- len
);
2783 ASSERT(pp
->current_phase
== ECPP_PHASE_ECP_FWD_IDLE
||
2784 pp
->current_phase
== ECPP_PHASE_ECP_REV_IDLE
);
2786 /* if in Reverse Phase negotiate to Forward */
2787 if (pp
->current_phase
== ECPP_PHASE_ECP_REV_IDLE
) {
2788 if (ecp_reverse2forward(pp
) == FAILURE
) {
2790 (void) putbq(pp
->writeq
, pp
->msg
);
2792 ecpp_putback_untransfered(pp
,
2798 if (ecpp_init_dma_xfer(pp
, addr
, len
) == FAILURE
) {
2805 /* schedule transfer timeout */
2806 pp
->timeout_id
= timeout(ecpp_xfer_timeout
, (caddr_t
)pp
,
2807 pp
->xfer_parms
.write_timeout
* drv_usectohz(1000000));
2811 * Transfer a PIO "block" a byte at a time.
2812 * The block is starts at addr and ends at pp->last_byte
2815 ecpp_prep_pio_xfer(struct ecppunit
*pp
, caddr_t addr
, size_t len
)
2817 pp
->next_byte
= addr
;
2818 pp
->last_byte
= (caddr_t
)((ulong_t
)addr
+ len
);
2820 if (ecpp_check_status(pp
) == FAILURE
) {
2822 * if status signals are bad, do not start PIO,
2823 * put everything back on the queue.
2826 "ecpp_prep_pio_xfer:suspend PIO len=%d\n", len
);
2828 if (pp
->msg
!= NULL
) {
2830 * this circumstance we want to copy the
2831 * untransfered section of msg to a new mblk,
2832 * then free the orignal one.
2834 ecpp_putback_untransfered(pp
,
2835 (void *)pp
->msg
->b_rptr
, len
);
2837 "ecpp_prep_pio_xfer: len1=%d\n", len
);
2842 ecpp_putback_untransfered(pp
, pp
->ioblock
, len
);
2844 "ecpp_prep_pio_xfer: len2=%d\n", len
);
2846 qenable(pp
->writeq
);
2851 pp
->dma_cancelled
= FALSE
;
2853 /* pport must be in PIO mode */
2854 if (ecr_write(pp
, ECR_mode_001
|
2855 ECPP_INTR_MASK
| ECPP_INTR_SRV
) != SUCCESS
) {
2856 ecpp_error(pp
->dip
, "ecpp_prep_pio_xfer: failed w/ECR.\n");
2859 ecpp_error(pp
->dip
, "ecpp_prep_pio_xfer: dcr=%x ecr=%x\n",
2860 DCR_READ(pp
), ECR_READ(pp
));
2866 ecpp_init_dma_xfer(struct ecppunit
*pp
, caddr_t addr
, size_t len
)
2868 uint8_t ecr_mode
[] = {
2870 ECR_mode_010
, /* Centronix */
2871 ECR_mode_010
, /* Compat */
2874 ECR_mode_011
, /* ECP */
2876 ECR_mode_110
, /* Diag */
2880 ASSERT((pp
->current_mode
<= ECPP_DIAG_MODE
) &&
2881 (ecr_mode
[pp
->current_mode
] != 0));
2883 if (ecpp_setup_dma_resources(pp
, addr
, len
) == FAILURE
) {
2884 qenable(pp
->writeq
);
2888 if (ecpp_check_status(pp
) == FAILURE
) {
2890 * if status signals are bad, do not start DMA, but
2891 * rather put everything back on the queue.
2894 "ecpp_init_dma_xfer: suspending DMA len=%d\n",
2895 pp
->dma_cookie
.dmac_size
);
2897 if (pp
->msg
!= NULL
) {
2899 * this circumstance we want to copy the
2900 * untransfered section of msg to a new mblk,
2901 * then free the orignal one.
2903 ecpp_putback_untransfered(pp
,
2904 (void *)pp
->msg
->b_rptr
, len
);
2906 "ecpp_init_dma_xfer:a:len=%d\n", len
);
2911 ecpp_putback_untransfered(pp
, pp
->ioblock
, len
);
2913 "ecpp_init_dma_xfer:b:len=%d\n", len
);
2916 if (ddi_dma_unbind_handle(pp
->dma_handle
) != DDI_SUCCESS
) {
2918 "ecpp_init_dma_xfer: unbind FAILURE.\n");
2920 qenable(pp
->writeq
);
2924 pp
->xfercnt
= pp
->resid
= len
;
2925 pp
->dma_cancelled
= FALSE
;
2928 /* set the right ECR mode and disable DMA */
2929 ecr
= ecr_mode
[pp
->current_mode
];
2930 (void) ecr_write(pp
, ecr
| ECPP_INTR_SRV
| ECPP_INTR_MASK
);
2932 /* prepare DMAC for a transfer */
2933 if (ECPP_DMA_START(pp
) == FAILURE
) {
2934 ecpp_error(pp
->dip
, "ecpp_init_dma_xfer: dma_start FAILED.\n");
2939 (void) ecr_write(pp
, ecr
| ECPP_DMA_ENABLE
| ECPP_INTR_MASK
);
2945 ecpp_setup_dma_resources(struct ecppunit
*pp
, caddr_t addr
, size_t len
)
2951 ASSERT(pp
->dma_dir
== DDI_DMA_READ
|| pp
->dma_dir
== DDI_DMA_WRITE
);
2953 err
= ddi_dma_addr_bind_handle(pp
->dma_handle
, NULL
,
2954 addr
, len
, pp
->dma_dir
| DDI_DMA_PARTIAL
,
2955 DDI_DMA_DONTWAIT
, NULL
,
2956 &pp
->dma_cookie
, &pp
->dma_cookie_count
);
2959 case DDI_DMA_MAPPED
:
2960 ecpp_error(pp
->dip
, "ecpp_setup_dma: DMA_MAPPED\n");
2966 case DDI_DMA_PARTIAL_MAP
: {
2967 ecpp_error(pp
->dip
, "ecpp_setup_dma: DMA_PARTIAL_MAP\n");
2969 if (ddi_dma_numwin(pp
->dma_handle
,
2970 &pp
->dma_nwin
) != DDI_SUCCESS
) {
2971 (void) ddi_dma_unbind_handle(pp
->dma_handle
);
2977 * The very first window is returned by bind_handle,
2978 * but we must do this explicitly here, otherwise
2979 * next getwin would return wrong cookie dmac_size
2981 if (ddi_dma_getwin(pp
->dma_handle
, 0, &woff
, &wlen
,
2982 &pp
->dma_cookie
, &pp
->dma_cookie_count
) != DDI_SUCCESS
) {
2984 "ecpp_setup_dma: ddi_dma_getwin failed!");
2985 (void) ddi_dma_unbind_handle(pp
->dma_handle
);
2990 "ecpp_setup_dma: cookies=%d, windows=%d"
2991 " addr=%lx len=%d\n",
2992 pp
->dma_cookie_count
, pp
->dma_nwin
,
2993 pp
->dma_cookie
.dmac_address
, pp
->dma_cookie
.dmac_size
);
2999 ecpp_error(pp
->dip
, "ecpp_setup_dma: err=%x\n", err
);
3007 ecpp_ack_ioctl(queue_t
*q
, mblk_t
*mp
)
3009 struct iocblk
*iocbp
;
3011 mp
->b_datap
->db_type
= M_IOCACK
;
3012 mp
->b_wptr
= mp
->b_rptr
+ sizeof (struct iocblk
);
3015 freemsg(mp
->b_cont
);
3019 iocbp
= (struct iocblk
*)mp
->b_rptr
;
3020 iocbp
->ioc_error
= 0;
3021 iocbp
->ioc_count
= 0;
3022 iocbp
->ioc_rval
= 0;
3028 ecpp_nack_ioctl(queue_t
*q
, mblk_t
*mp
, int err
)
3030 struct iocblk
*iocbp
;
3032 mp
->b_datap
->db_type
= M_IOCNAK
;
3033 mp
->b_wptr
= mp
->b_rptr
+ sizeof (struct iocblk
);
3034 iocbp
= (struct iocblk
*)mp
->b_rptr
;
3035 iocbp
->ioc_error
= err
;
3038 freemsg(mp
->b_cont
);
3046 ecpp_isr(caddr_t arg
)
3048 struct ecppunit
*pp
= (struct ecppunit
*)(void *)arg
;
3051 int cheerio_pend_counter
;
3052 int retval
= DDI_INTR_UNCLAIMED
;
3055 mutex_enter(&pp
->umutex
);
3057 * interrupt may occur while other thread is holding the lock
3058 * and cancels DMA transfer (e.g. ecpp_flush())
3059 * since it cannot cancel the interrupt thread,
3060 * it just sets dma_cancelled to TRUE,
3061 * telling interrupt handler to exit immediately
3063 if (pp
->dma_cancelled
== TRUE
) {
3064 ecpp_error(pp
->dip
, "dma-cancel isr\n");
3067 pp
->dma_cancelled
= FALSE
;
3069 mutex_exit(&pp
->umutex
);
3070 return (DDI_INTR_CLAIMED
);
3073 /* Southbridge interrupts are handled separately */
3077 if (pp
->hw
== &m1553
)
3080 retval
= ecpp_M1553_intr(pp
);
3081 if (retval
== DDI_INTR_UNCLAIMED
) {
3084 mutex_exit(&pp
->umutex
);
3085 return (DDI_INTR_CLAIMED
);
3089 * the intr is through the motherboard. it is faster than PCI route.
3090 * sometimes ecpp_isr() is invoked before cheerio csr is updated.
3092 cheerio_pend_counter
= ecpp_isr_max_delay
;
3093 dcsr
= GET_DMAC_CSR(pp
);
3095 while (!(dcsr
& DCSR_INT_PEND
) && cheerio_pend_counter
-- > 0) {
3097 dcsr
= GET_DMAC_CSR(pp
);
3101 * This is a workaround for what seems to be a timing problem
3102 * with the delivery of interrupts and CSR updating with the
3103 * ebus2 csr, superio and the n_ERR pin from the peripheral.
3105 * delay is not needed for PIO mode
3107 if (!COMPAT_PIO(pp
)) {
3109 dcsr
= GET_DMAC_CSR(pp
);
3112 /* on 97317 in Extended mode IRQ_ST of DSR is deasserted when read */
3116 * check if interrupt is for this device:
3117 * it should be reflected either in cheerio DCSR register
3118 * or in IRQ_ST bit of DSR on 97317
3120 if ((dcsr
& DCSR_INT_PEND
) == 0) {
3121 if (pp
->hw
!= &pc97317
) {
3125 * on Excalibur, reading DSR will deassert SuperIO IRQx line
3126 * RIO's DCSR_INT_PEND seems to follow IRQx transitions,
3127 * so if DSR is read after interrupt occured, but before
3128 * we get here, IRQx and hence INT_PEND will be deasserted
3129 * as a result, we can miss a service interrupt in PIO mode
3131 * malicious DSR reader is BPPIOC_TESTIO, which is called
3132 * by LP in between data blocks to check printer status
3133 * this workaround lets us not to miss an interrupt
3135 * also, nErr interrupt (ECP mode) not always reflected in DCSR
3137 if (((dsr
& ECPP_IRQ_ST
) == 0) ||
3138 ((COMPAT_PIO(pp
)) && (pp
->e_busy
== ECPP_BUSY
)) ||
3139 (((dsr
& ECPP_nERR
) == 0) &&
3140 (pp
->current_mode
== ECPP_ECP_MODE
))) {
3149 /* the intr is for us - check all possible interrupt sources */
3150 if (dcsr
& DCSR_ERR_PEND
) {
3153 /* we are expecting a data transfer interrupt */
3154 ASSERT(pp
->e_busy
== ECPP_BUSY
);
3157 * some kind of DMA error
3159 if (ECPP_DMA_STOP(pp
, &bcr
) == FAILURE
) {
3160 ecpp_error(pp
->dip
, "ecpp_isr: dma_stop failed\n");
3163 ecpp_error(pp
->dip
, "ecpp_isr: DMAC ERROR bcr=%d\n", bcr
);
3165 ecpp_xfer_cleanup(pp
);
3167 if (ddi_dma_unbind_handle(pp
->dma_handle
) != DDI_SUCCESS
) {
3168 ecpp_error(pp
->dip
, "ecpp_isr(e): unbind failed\n");
3171 mutex_exit(&pp
->umutex
);
3172 return (DDI_INTR_CLAIMED
);
3175 if (dcsr
& DCSR_TC
) {
3176 retval
= ecpp_dma_ihdlr(pp
);
3177 mutex_exit(&pp
->umutex
);
3178 return (DDI_INTR_CLAIMED
);
3181 if (COMPAT_PIO(pp
)) {
3182 retval
= ecpp_pio_ihdlr(pp
);
3183 mutex_exit(&pp
->umutex
);
3184 return (DDI_INTR_CLAIMED
);
3187 /* does peripheral need attention? */
3188 if ((dsr
& ECPP_nERR
) == 0) {
3189 retval
= ecpp_nErr_ihdlr(pp
);
3190 mutex_exit(&pp
->umutex
);
3191 return (DDI_INTR_CLAIMED
);
3198 pp
->intr_spurious
++;
3201 * The following procedure tries to prevent soft hangs
3202 * in event of peripheral/superio misbehaviour:
3203 * if number of unexpected interrupts in the last SPUR_PERIOD ns
3204 * exceeded SPUR_CRITICAL, then shut up interrupts
3207 if (pp
->lastspur
== 0 || now
- pp
->lastspur
> SPUR_PERIOD
) {
3208 /* last unexpected interrupt was long ago */
3212 /* last unexpected interrupt was recently */
3216 if (pp
->nspur
>= SPUR_CRITICAL
) {
3218 ECR_WRITE(pp
, ECR_READ(pp
) | ECPP_INTR_MASK
| ECPP_INTR_SRV
);
3220 cmn_err(CE_NOTE
, "%s%d: too many interrupt requests",
3221 ddi_get_name(pp
->dip
), ddi_get_instance(pp
->dip
));
3223 ECR_WRITE(pp
, ECR_READ(pp
) | ECPP_INTR_SRV
| ECPP_INTR_MASK
);
3227 "isr:unknown: dcsr=%x ecr=%x dsr=%x dcr=%x\nmode=%x phase=%x\n",
3228 dcsr
, ECR_READ(pp
), dsr
, DCR_READ(pp
),
3229 pp
->current_mode
, pp
->current_phase
);
3231 mutex_exit(&pp
->umutex
);
3232 return (DDI_INTR_CLAIMED
);
3236 pp
->intr_spurious
++;
3239 "isr:UNCL: dcsr=%x ecr=%x dsr=%x dcr=%x\nmode=%x phase=%x\n",
3240 dcsr
, ECR_READ(pp
), DSR_READ(pp
), DCR_READ(pp
),
3241 pp
->current_mode
, pp
->current_phase
);
3243 mutex_exit(&pp
->umutex
);
3244 return (DDI_INTR_UNCLAIMED
);
3248 * M1553 intr handler
3251 ecpp_M1553_intr(struct ecppunit
*pp
)
3253 int retval
= DDI_INTR_UNCLAIMED
;
3257 if (pp
->e_busy
== ECPP_BUSY
) {
3258 /* Centronics or Compat PIO transfer */
3259 if (COMPAT_PIO(pp
)) {
3260 return (ecpp_pio_ihdlr(pp
));
3263 /* Centronics or Compat DMA transfer */
3264 if (COMPAT_DMA(pp
) ||
3265 (pp
->current_mode
== ECPP_ECP_MODE
) ||
3266 (pp
->current_mode
== ECPP_DIAG_MODE
)) {
3267 return (ecpp_dma_ihdlr(pp
));
3271 /* Nibble or ECP backchannel request? */
3272 if ((DSR_READ(pp
) & ECPP_nERR
) == 0) {
3273 return (ecpp_nErr_ihdlr(pp
));
3280 * DMA completion interrupt handler
3283 ecpp_dma_ihdlr(struct ecppunit
*pp
)
3287 ecpp_error(pp
->dip
, "ecpp_dma_ihdlr(%x): ecr=%x, dsr=%x, dcr=%x\n",
3288 pp
->current_mode
, ECR_READ(pp
), DSR_READ(pp
), DCR_READ(pp
));
3290 /* we are expecting a data transfer interrupt */
3291 ASSERT(pp
->e_busy
== ECPP_BUSY
);
3293 /* Intr generated while invoking TFIFO mode. Exit */
3294 if (pp
->tfifo_intr
== 1) {
3296 ecpp_error(pp
->dip
, "ecpp_dma_ihdlr: tfifo_intr is 1\n");
3297 return (DDI_INTR_CLAIMED
);
3300 if (ECPP_DMA_STOP(pp
, NULL
) == FAILURE
) {
3301 ecpp_error(pp
->dip
, "ecpp_dma_ihdlr: dma_stop failed\n");
3304 if (pp
->current_mode
== ECPP_ECP_MODE
&&
3305 pp
->current_phase
== ECPP_PHASE_ECP_REV_XFER
) {
3306 ecpp_ecp_read_completion(pp
);
3309 * fifo_timer() will do the cleanup when the FIFO drains
3311 if ((ECR_READ(pp
) & ECPP_FIFO_EMPTY
) ||
3312 (pp
->current_mode
== ECPP_DIAG_MODE
)) {
3313 tm
= 0; /* no use in waiting if FIFO is already empty */
3315 tm
= drv_usectohz(FIFO_DRAIN_PERIOD
);
3317 pp
->fifo_timer_id
= timeout(ecpp_fifo_timer
, (caddr_t
)pp
, tm
);
3321 * Stop the DMA transfer timeout timer
3322 * this operation will temporarily give up the mutex,
3323 * so we do it in the end of the handler to avoid races
3325 ecpp_untimeout_unblock(pp
, &pp
->timeout_id
);
3327 return (DDI_INTR_CLAIMED
);
3331 * ecpp_pio_ihdlr() is a PIO interrupt processing routine
3332 * It masks interrupts, updates statistics and initiates next byte transfer
3335 ecpp_pio_ihdlr(struct ecppunit
*pp
)
3337 ASSERT(mutex_owned(&pp
->umutex
));
3338 ASSERT(pp
->e_busy
== ECPP_BUSY
);
3340 /* update statistics */
3342 pp
->ctxpio_obytes
++;
3344 /* disable nAck interrups */
3346 DCR_WRITE(pp
, DCR_READ(pp
) & ~(ECPP_REV_DIR
| ECPP_INTR_EN
));
3349 * If it was the last byte of the data block cleanup,
3350 * otherwise trigger a soft interrupt to send the next byte
3352 if (pp
->next_byte
>= pp
->last_byte
) {
3353 ecpp_xfer_cleanup(pp
);
3355 "ecpp_pio_ihdlr: pp->joblen=%d,pp->ctx_cf=%d,\n",
3356 pp
->joblen
, pp
->ctx_cf
);
3358 if (pp
->softintr_pending
) {
3360 "ecpp_pio_ihdlr:E: next byte in progress\n");
3362 pp
->softintr_flags
= ECPP_SOFTINTR_PIONEXT
;
3363 pp
->softintr_pending
= 1;
3364 ddi_trigger_softintr(pp
->softintr_id
);
3368 return (DDI_INTR_CLAIMED
);
3372 * ecpp_pio_writeb() sends a byte using Centronics handshake
3375 ecpp_pio_writeb(struct ecppunit
*pp
)
3379 dcr
= DCR_READ(pp
) & ~ECPP_REV_DIR
;
3380 dcr
|= ECPP_INTR_EN
;
3382 /* send the next byte */
3383 DATAR_WRITE(pp
, *(pp
->next_byte
++));
3385 drv_usecwait(pp
->data_setup_time
);
3387 /* Now Assert (neg logic) nStrobe */
3388 if (dcr_write(pp
, dcr
| ECPP_STB
) == FAILURE
) {
3389 ecpp_error(pp
->dip
, "ecpp_pio_writeb:1: failed w/DCR\n");
3392 /* Enable nAck interrupts */
3393 (void) DSR_READ(pp
); /* ensure IRQ_ST is armed */
3394 ECPP_UNMASK_INTR(pp
);
3396 drv_usecwait(pp
->strobe_pulse_width
);
3398 if (dcr_write(pp
, dcr
& ~ECPP_STB
) == FAILURE
) {
3399 ecpp_error(pp
->dip
, "ecpp_pio_writeb:2: failed w/DCR\n");
3404 * Backchannel request interrupt handler
3407 ecpp_nErr_ihdlr(struct ecppunit
*pp
)
3409 ecpp_error(pp
->dip
, "ecpp_nErr_ihdlr: mode=%x, phase=%x\n",
3410 pp
->current_mode
, pp
->current_phase
);
3412 if (pp
->oflag
!= TRUE
) {
3413 ecpp_error(pp
->dip
, "ecpp_nErr_ihdlr: not open!\n");
3414 return (DDI_INTR_UNCLAIMED
);
3417 if (pp
->e_busy
== ECPP_BUSY
) {
3418 ecpp_error(pp
->dip
, "ecpp_nErr_ihdlr: busy\n");
3419 ECR_WRITE(pp
, ECR_READ(pp
) | ECPP_INTR_MASK
);
3420 return (DDI_INTR_CLAIMED
);
3423 /* mask nErr & nAck interrupts */
3425 DCR_WRITE(pp
, DCR_READ(pp
) & ~(ECPP_INTR_EN
| ECPP_REV_DIR
));
3426 ECR_WRITE(pp
, ECR_READ(pp
) | ECPP_INTR_MASK
);
3429 switch (pp
->current_mode
) {
3432 * Peripheral asserts nPeriphRequest (nFault)
3435 case ECPP_NIBBLE_MODE
:
3437 * Event 18: Periph asserts nErr to indicate data avail
3438 * Event 19: After waiting minimum pulse width,
3439 * periph sets nAck high to generate an interrupt
3441 * Interface is in Interrupt Phase
3443 pp
->current_phase
= ECPP_PHASE_NIBT_REVINTR
;
3447 ecpp_error(pp
->dip
, "ecpp_nErr_ihdlr: wrong mode!\n");
3448 return (DDI_INTR_UNCLAIMED
);
3451 (void) ecpp_backchan_req(pp
); /* put backchannel request on the wq */
3453 return (DDI_INTR_CLAIMED
);
3457 * Softintr handler does work according to softintr_flags:
3458 * in case of ECPP_SOFTINTR_PIONEXT it sends next byte of PIO transfer
3461 ecpp_softintr(caddr_t arg
)
3463 struct ecppunit
*pp
= (struct ecppunit
*)arg
;
3464 uint32_t unx_len
, ecpp_reattempts
= 0;
3466 mutex_enter(&pp
->umutex
);
3470 if (!pp
->softintr_pending
) {
3471 mutex_exit(&pp
->umutex
);
3472 return (DDI_INTR_CLAIMED
);
3474 pp
->softintr_pending
= 0;
3477 if (pp
->softintr_flags
& ECPP_SOFTINTR_PIONEXT
) {
3478 pp
->softintr_flags
&= ~ECPP_SOFTINTR_PIONEXT
;
3480 * Sent next byte in PIO mode
3482 ecpp_reattempts
= 0;
3484 if (ecpp_check_status(pp
) == SUCCESS
) {
3485 pp
->e_busy
= ECPP_BUSY
;
3489 if (pp
->isr_reattempt_high
< ecpp_reattempts
) {
3490 pp
->isr_reattempt_high
= ecpp_reattempts
;
3492 } while (++ecpp_reattempts
< pp
->wait_for_busy
);
3494 /* if the peripheral still not recovered suspend the transfer */
3495 if (pp
->e_busy
== ECPP_ERR
) {
3496 ++pp
->ctx_cf
; /* check status fail */
3497 ecpp_error(pp
->dip
, "ecpp_softintr:check_status:F: "
3498 "dsr=%x jl=%d cf_isr=%d\n",
3499 DSR_READ(pp
), pp
->joblen
, pp
->ctx_cf
);
3502 * if status signals are bad,
3503 * put everything back on the wq.
3505 unx_len
= pp
->last_byte
- pp
->next_byte
;
3506 if (pp
->msg
!= NULL
) {
3507 ecpp_putback_untransfered(pp
,
3508 (void *)pp
->msg
->b_rptr
, unx_len
);
3510 "ecpp_softintr:e1:unx_len=%d\n", unx_len
);
3515 ecpp_putback_untransfered(pp
,
3516 pp
->next_byte
, unx_len
);
3518 "ecpp_softintr:e2:unx_len=%d\n", unx_len
);
3521 ecpp_xfer_cleanup(pp
);
3522 pp
->e_busy
= ECPP_ERR
;
3523 qenable(pp
->writeq
);
3525 /* send the next one */
3526 pp
->e_busy
= ECPP_BUSY
;
3527 (void) ecpp_pio_writeb(pp
);
3531 mutex_exit(&pp
->umutex
);
3532 return (DDI_INTR_CLAIMED
);
3537 * Transfer clean-up:
3538 * shut down the DMAC
3539 * stop the transfer timer
3540 * enable write queue
3543 ecpp_xfer_cleanup(struct ecppunit
*pp
)
3545 ASSERT(mutex_owned(&pp
->umutex
));
3548 * if we did not use the ioblock, the mblk that
3549 * was used should be freed.
3551 if (pp
->msg
!= NULL
) {
3556 /* The port is no longer active */
3557 pp
->e_busy
= ECPP_IDLE
;
3559 /* Stop the transfer timeout timer */
3560 ecpp_untimeout_unblock(pp
, &pp
->timeout_id
);
3562 qenable(pp
->writeq
);
3567 ecpp_error(dev_info_t
*dip
, char *fmt
, ...)
3570 static char *lastfmt
;
3571 char msg_buffer
[255];
3580 * Don't print same error message too often.
3582 now
= gethrestime_sec();
3583 if ((last
== (now
& ~1)) && (lastfmt
== fmt
))
3590 (void) vsprintf(msg_buffer
, fmt
, ap
);
3591 cmn_err(CE_CONT
, "%s%d: %s", ddi_get_name(dip
),
3592 ddi_get_instance(dip
), msg_buffer
);
3597 * Forward transfer timeout
3600 ecpp_xfer_timeout(void *arg
)
3602 struct ecppunit
*pp
= arg
;
3604 size_t unx_len
, xferd
;
3606 timeout_id_t fifo_timer_id
;
3608 mutex_enter(&pp
->umutex
);
3610 if (pp
->timeout_id
== 0) {
3611 mutex_exit(&pp
->umutex
);
3619 pp
->dma_cancelled
= TRUE
; /* prevent race with isr() */
3621 if (COMPAT_PIO(pp
)) {
3626 /* turn off nAck interrupts */
3628 (void) dcr_write(pp
, dcr
& ~(ECPP_REV_DIR
| ECPP_INTR_EN
));
3631 pp
->softintr_pending
= 0;
3632 unx_len
= pp
->last_byte
- pp
->next_byte
;
3633 ecpp_error(pp
->dip
, "xfer_timeout: unx_len=%d\n", unx_len
);
3636 unx_addr
= pp
->next_byte
;
3638 ecpp_xfer_cleanup(pp
);
3639 qenable(pp
->writeq
);
3640 mutex_exit(&pp
->umutex
);
3647 * If DMAC fails to shut off, continue anyways and attempt
3648 * to put untransfered data back on queue.
3650 if (ECPP_DMA_STOP(pp
, &unx_len
) == FAILURE
) {
3652 "ecpp_xfer_timeout: failed dma_stop\n");
3655 ecpp_error(pp
->dip
, "xfer_timeout: unx_len=%d\n", unx_len
);
3657 if (ddi_dma_unbind_handle(pp
->dma_handle
) == DDI_FAILURE
) {
3659 "ecpp_xfer_timeout: failed unbind\n");
3663 * if the bcr is zero, then DMA is complete and
3664 * we are waiting for the fifo to drain. So let
3665 * ecpp_fifo_timer() look after the clean up.
3668 qenable(pp
->writeq
);
3669 mutex_exit(&pp
->umutex
);
3672 xferd
= pp
->dma_cookie
.dmac_size
- unx_len
;
3674 unx_len
= pp
->resid
;
3676 /* update statistics */
3677 pp
->obytes
[pp
->current_mode
] += xferd
;
3678 pp
->joblen
+= xferd
;
3680 if (pp
->msg
!= NULL
) {
3681 unx_addr
= (caddr_t
)pp
->msg
->b_wptr
- unx_len
;
3683 unx_addr
= pp
->ioblock
+
3684 (pp
->xfercnt
- unx_len
);
3689 /* Following code is common for PIO and DMA modes */
3691 ecpp_putback_untransfered(pp
, (caddr_t
)unx_addr
, unx_len
);
3693 if (pp
->msg
!= NULL
) {
3698 /* mark the error status structure */
3699 pp
->timeout_error
= 1;
3700 pp
->e_busy
= ECPP_ERR
;
3701 fifo_timer_id
= pp
->fifo_timer_id
;
3702 pp
->fifo_timer_id
= 0;
3704 qenable(pp
->writeq
);
3706 mutex_exit(&pp
->umutex
);
3708 if (fifo_timer_id
) {
3709 (void) untimeout(fifo_timer_id
);
3714 ecpp_putback_untransfered(struct ecppunit
*pp
, void *startp
, uint_t len
)
3718 ecpp_error(pp
->dip
, "ecpp_putback_untrans=%d\n", len
);
3724 new_mp
= allocb(len
, BPRI_MED
);
3725 if (new_mp
== NULL
) {
3727 "ecpp_putback_untransfered: allocb FAILURE.\n");
3731 bcopy(startp
, new_mp
->b_rptr
, len
);
3732 new_mp
->b_wptr
= new_mp
->b_rptr
+ len
;
3734 if (!putbq(pp
->writeq
, new_mp
)) {
3740 ecr_write(struct ecppunit
*pp
, uint8_t ecr_byte
)
3744 for (i
= ECPP_REG_WRITE_MAX_LOOP
; i
> 0; i
--) {
3745 ECR_WRITE(pp
, ecr_byte
);
3747 current_ecr
= ECR_READ(pp
);
3749 /* mask off the lower two read-only bits */
3750 if ((ecr_byte
& 0xFC) == (current_ecr
& 0xFC))
3757 dcr_write(struct ecppunit
*pp
, uint8_t dcr_byte
)
3759 uint8_t current_dcr
;
3762 for (i
= ECPP_REG_WRITE_MAX_LOOP
; i
> 0; i
--) {
3763 DCR_WRITE(pp
, dcr_byte
);
3765 current_dcr
= DCR_READ(pp
);
3767 /* compare only bits 0-4 (direction bit return 1) */
3768 if ((dcr_byte
& 0x1F) == (current_dcr
& 0x1F))
3772 "(%d)dcr_write: dcr written =%x, dcr readback =%x\n",
3773 i
, dcr_byte
, current_dcr
);
3779 ecpp_reset_port_regs(struct ecppunit
*pp
)
3781 DCR_WRITE(pp
, ECPP_SLCTIN
| ECPP_nINIT
);
3782 ECR_WRITE(pp
, ECR_mode_001
| ECPP_INTR_MASK
| ECPP_INTR_SRV
);
3787 * The data transferred by the DMA engine goes through the FIFO,
3788 * so that when the DMA counter reaches zero (and an interrupt occurs)
3789 * the FIFO can still contain data. If this is the case, the ISR will
3790 * schedule this callback to wait until the FIFO drains or a timeout occurs.
3793 ecpp_fifo_timer(void *arg
)
3795 struct ecppunit
*pp
= arg
;
3797 timeout_id_t timeout_id
;
3799 mutex_enter(&pp
->umutex
);
3802 * If the FIFO timer has been turned off, exit.
3804 if (pp
->fifo_timer_id
== 0) {
3805 ecpp_error(pp
->dip
, "ecpp_fifo_timer: untimedout\n");
3806 mutex_exit(&pp
->umutex
);
3809 pp
->fifo_timer_id
= 0;
3813 * If the FIFO is not empty restart timer. Wait FIFO_DRAIN_PERIOD
3814 * (250 ms) and check FIFO_EMPTY bit again. Repeat until FIFO is
3815 * empty or until 10 * FIFO_DRAIN_PERIOD expires.
3819 if ((pp
->current_mode
!= ECPP_DIAG_MODE
) &&
3820 (((ecr
& ECPP_FIFO_EMPTY
) == 0) &&
3821 (pp
->ecpp_drain_counter
< 10))) {
3824 "ecpp_fifo_timer(%d):FIFO not empty:ecr=%x\n",
3825 pp
->ecpp_drain_counter
, ecr
);
3827 pp
->fifo_timer_id
= timeout(ecpp_fifo_timer
,
3828 (caddr_t
)pp
, drv_usectohz(FIFO_DRAIN_PERIOD
));
3829 ++pp
->ecpp_drain_counter
;
3831 mutex_exit(&pp
->umutex
);
3835 if (pp
->current_mode
!= ECPP_DIAG_MODE
) {
3837 * If the FIFO won't drain after 10 FIFO_DRAIN_PERIODs
3838 * then don't wait any longer. Simply clean up the transfer.
3840 if (pp
->ecpp_drain_counter
>= 10) {
3841 ecpp_error(pp
->dip
, "ecpp_fifo_timer(%d):"
3842 " clearing FIFO,can't wait:ecr=%x\n",
3843 pp
->ecpp_drain_counter
, ecr
);
3846 "ecpp_fifo_timer(%d):FIFO empty:ecr=%x\n",
3847 pp
->ecpp_drain_counter
, ecr
);
3850 pp
->ecpp_drain_counter
= 0;
3854 * Main section of routine:
3855 * - stop the DMA transfer timer
3856 * - program DMA with next cookie/window or unbind the DMA mapping
3858 * - if last mblk in queue, signal to close() & return to idle state
3861 /* Stop the DMA transfer timeout timer */
3862 timeout_id
= pp
->timeout_id
;
3865 /* data has drained from fifo, it is ok to free dma resource */
3866 if (pp
->current_mode
== ECPP_ECP_MODE
||
3867 pp
->current_mode
== ECPP_DIAG_MODE
||
3872 /* update residual */
3873 pp
->resid
-= pp
->dma_cookie
.dmac_size
;
3875 /* update statistics */
3876 pp
->joblen
+= pp
->dma_cookie
.dmac_size
;
3877 if (pp
->dma_dir
== DDI_DMA_WRITE
) {
3878 pp
->obytes
[pp
->current_mode
] +=
3879 pp
->dma_cookie
.dmac_size
;
3881 pp
->ibytes
[pp
->current_mode
] +=
3882 pp
->dma_cookie
.dmac_size
;
3886 * Look if any cookies/windows left
3888 if (--pp
->dma_cookie_count
> 0) {
3889 /* process the next cookie */
3890 ddi_dma_nextcookie(pp
->dma_handle
,
3892 } else if (pp
->dma_curwin
< pp
->dma_nwin
) {
3893 /* process the next window */
3894 if (ddi_dma_getwin(pp
->dma_handle
,
3895 pp
->dma_curwin
, &off
, &len
,
3897 &pp
->dma_cookie_count
) != DDI_SUCCESS
) {
3899 "ecpp_fifo_timer: ddi_dma_getwin failed\n");
3908 ecpp_error(pp
->dip
, "ecpp_fifo_timer: next addr=%llx len=%d\n",
3909 pp
->dma_cookie
.dmac_address
,
3910 pp
->dma_cookie
.dmac_size
);
3912 /* kick off new transfer */
3913 if (ECPP_DMA_START(pp
) != SUCCESS
) {
3915 "ecpp_fifo_timer: dma_start failed\n");
3919 (void) ecr_write(pp
, (ecr
& 0xe0) |
3920 ECPP_DMA_ENABLE
| ECPP_INTR_MASK
);
3922 mutex_exit(&pp
->umutex
);
3925 (void) untimeout(timeout_id
);
3930 if (ddi_dma_unbind_handle(pp
->dma_handle
) != DDI_SUCCESS
) {
3931 ecpp_error(pp
->dip
, "ecpp_fifo_timer: unbind failed\n");
3933 ecpp_error(pp
->dip
, "ecpp_fifo_timer: unbind ok\n");
3938 * if we did not use the dmablock, the mblk that
3939 * was used should be freed.
3941 if (pp
->msg
!= NULL
) {
3946 /* The port is no longer active */
3947 pp
->e_busy
= ECPP_IDLE
;
3949 qenable(pp
->writeq
);
3951 mutex_exit(&pp
->umutex
);
3954 (void) untimeout(timeout_id
);
3959 * In Compatibility mode, check if the peripheral is ready to accept data
3962 ecpp_check_status(struct ecppunit
*pp
)
3967 if (pp
->current_mode
== ECPP_ECP_MODE
||
3968 pp
->current_mode
== ECPP_DIAG_MODE
)
3971 statmask
= ECPP_nERR
| ECPP_SLCT
| ECPP_nBUSY
| ECPP_nACK
;
3974 if ((dsr
& ECPP_PE
) || ((dsr
& statmask
) != statmask
)) {
3975 pp
->e_busy
= ECPP_ERR
;
3983 * if the peripheral is not ready to accept data, write service routine
3984 * periodically reschedules itself to recheck peripheral status
3985 * and start data transfer as soon as possible
3988 ecpp_wsrv_timer(void *arg
)
3990 struct ecppunit
*pp
= arg
;
3992 ecpp_error(pp
->dip
, "ecpp_wsrv_timer: starting\n");
3994 mutex_enter(&pp
->umutex
);
3996 if (pp
->wsrv_timer_id
== 0) {
3997 mutex_exit(&pp
->umutex
);
4000 pp
->wsrv_timer_id
= 0;
4003 ecpp_error(pp
->dip
, "ecpp_wsrv_timer: qenabling...\n");
4005 qenable(pp
->writeq
);
4007 mutex_exit(&pp
->umutex
);
4011 * Allocate a message indicating a backchannel request
4012 * and put it on the write queue
4015 ecpp_backchan_req(struct ecppunit
*pp
)
4019 if ((mp
= allocb(sizeof (int), BPRI_MED
)) == NULL
) {
4020 ecpp_error(pp
->dip
, "ecpp_backchan_req: allocb failed\n");
4023 mp
->b_datap
->db_type
= M_CTL
;
4024 *(int *)mp
->b_rptr
= ECPP_BACKCHANNEL
;
4025 mp
->b_wptr
= mp
->b_rptr
+ sizeof (int);
4026 if (!putbq(pp
->writeq
, mp
)) {
4027 ecpp_error(pp
->dip
, "ecpp_backchan_req:putbq failed\n");
4036 * Cancel the function scheduled with timeout(9F)
4037 * This function is to be called with the mutex held
4040 ecpp_untimeout_unblock(struct ecppunit
*pp
, timeout_id_t
*id
)
4042 timeout_id_t saved_id
;
4044 ASSERT(mutex_owned(&pp
->umutex
));
4049 mutex_exit(&pp
->umutex
);
4050 (void) untimeout(saved_id
);
4051 mutex_enter(&pp
->umutex
);
4056 * get prnio interface capabilities
4059 ecpp_get_prn_ifcap(struct ecppunit
*pp
)
4063 ifcap
= PRN_1284_DEVID
| PRN_TIMEOUTS
| PRN_STREAMS
;
4065 /* status (DSR) only makes sense in Centronics & Compat modes */
4066 if (pp
->current_mode
== ECPP_CENTRONICS
||
4067 pp
->current_mode
== ECPP_COMPAT_MODE
) {
4068 ifcap
|= PRN_1284_STATUS
;
4069 } else if (pp
->current_mode
== ECPP_NIBBLE_MODE
||
4070 pp
->current_mode
== ECPP_ECP_MODE
) {
4078 * Determine SuperI/O type
4080 static struct ecpp_hw_bind
*
4081 ecpp_determine_sio_type(struct ecppunit
*pp
)
4083 struct ecpp_hw_bind
*hw_bind
;
4087 name
= ddi_binding_name(pp
->dip
);
4089 for (hw_bind
= NULL
, i
= 0; i
< NELEM(ecpp_hw_bind
); i
++) {
4090 if (strcmp(name
, ecpp_hw_bind
[i
].name
) == 0) {
4091 hw_bind
= &ecpp_hw_bind
[i
];
4102 * IEEE 1284 support routines:
4103 * negotiation and termination;
4104 * phase transitions;
4110 * Interface initialization, abnormal termination into Compatibility mode
4112 * Peripheral may be non-1284, so we set current mode to ECPP_CENTRONICS
4115 ecpp_1284_init_interface(struct ecppunit
*pp
)
4117 ECR_WRITE(pp
, ECPP_INTR_SRV
| ECPP_INTR_MASK
| ECR_mode_001
);
4120 * Toggle the nInit signal if configured in ecpp.conf
4121 * for most peripherals it is not needed
4123 if (pp
->init_seq
== TRUE
) {
4124 DCR_WRITE(pp
, ECPP_SLCTIN
);
4125 drv_usecwait(50); /* T(ER) = 50us */
4128 DCR_WRITE(pp
, ECPP_nINIT
| ECPP_SLCTIN
);
4130 pp
->current_mode
= pp
->backchannel
= ECPP_CENTRONICS
;
4131 pp
->current_phase
= ECPP_PHASE_C_IDLE
;
4132 ECPP_CONFIG_MODE(pp
);
4133 pp
->to_mode
[pp
->current_mode
]++;
4135 ecpp_error(pp
->dip
, "ecpp_1284_init_interface: ok\n");
4139 * ECP mode negotiation
4142 ecp_negotiation(struct ecppunit
*pp
)
4146 /* ECP mode negotiation */
4148 if (ecpp_1284_negotiation(pp
, ECPP_XREQ_ECP
, &dsr
) == FAILURE
)
4151 /* Event 5: peripheral deasserts PError and Busy, asserts Select */
4152 if ((dsr
& (ECPP_PE
| ECPP_nBUSY
| ECPP_SLCT
)) !=
4153 (ECPP_nBUSY
| ECPP_SLCT
)) {
4155 "ecp_negotiation: failed event 5 %x\n", DSR_READ(pp
));
4156 (void) ecpp_1284_termination(pp
);
4160 /* entered Setup Phase */
4161 pp
->current_phase
= ECPP_PHASE_ECP_SETUP
;
4163 /* Event 30: host asserts nAutoFd */
4164 DCR_WRITE(pp
, ECPP_nINIT
| ECPP_AFX
);
4166 /* Event 31: peripheral asserts PError */
4167 if (wait_dsr(pp
, ECPP_PE
, ECPP_PE
, 35000) < 0) {
4169 "ecp_negotiation: failed event 31 %x\n", DSR_READ(pp
));
4170 (void) ecpp_1284_termination(pp
);
4174 /* entered Forward Idle Phase */
4175 pp
->current_phase
= ECPP_PHASE_ECP_FWD_IDLE
;
4177 /* successful negotiation into ECP mode */
4178 pp
->current_mode
= ECPP_ECP_MODE
;
4179 pp
->backchannel
= ECPP_ECP_MODE
;
4181 ecpp_error(pp
->dip
, "ecp_negotiation: ok\n");
4187 * Nibble mode negotiation
4190 nibble_negotiation(struct ecppunit
*pp
)
4194 if (ecpp_1284_negotiation(pp
, ECPP_XREQ_NIBBLE
, &dsr
) == FAILURE
) {
4199 * If peripheral has data available, PE and nErr will
4200 * be set low at Event 5 & 6.
4202 if ((dsr
& (ECPP_PE
| ECPP_nERR
)) == 0) {
4203 pp
->current_phase
= ECPP_PHASE_NIBT_AVAIL
;
4205 pp
->current_phase
= ECPP_PHASE_NIBT_NAVAIL
;
4208 /* successful negotiation into Nibble mode */
4209 pp
->current_mode
= ECPP_NIBBLE_MODE
;
4210 pp
->backchannel
= ECPP_NIBBLE_MODE
;
4212 ecpp_error(pp
->dip
, "nibble_negotiation: ok (phase=%x)\n",
4220 * Wait ptimeout usec for periph to set 'mask' bits to 'val' state
4222 * return value < 0 indicates timeout
4225 wait_dsr(struct ecppunit
*pp
, uint8_t mask
, uint8_t val
, int ptimeout
)
4227 while (((DSR_READ(pp
) & mask
) != val
) && ptimeout
--) {
4235 * 1284 negotiation Events 0..6
4236 * required mode is indicated by extensibility request value
4238 * After successful negotiation SUCCESS is returned and
4239 * current mode is set according to xreq,
4240 * otherwise FAILURE is returned and current mode is set to
4241 * either COMPAT (1284 periph) or CENTRONICS (non-1284 periph)
4243 * Current phase must be set by the caller (mode-specific negotiation)
4245 * If rdsr is not NULL, DSR value after Event 6 is stored here
4248 ecpp_1284_negotiation(struct ecppunit
*pp
, uint8_t xreq
, uint8_t *rdsr
)
4252 ecpp_error(pp
->dip
, "nego(%x): entering...\n", xreq
);
4254 /* negotiation should start in Compatibility mode */
4255 (void) ecpp_1284_termination(pp
);
4257 /* Set host into Compat mode */
4258 ECR_WRITE(pp
, ECPP_INTR_SRV
| ECPP_INTR_MASK
| ECR_mode_001
);
4260 pp
->current_phase
= ECPP_PHASE_NEGO
;
4262 /* Event 0: host sets extensibility request on data lines */
4263 DATAR_WRITE(pp
, xreq
);
4265 /* Event 1: host deassert nSelectin and assert nAutoFd */
4266 DCR_WRITE(pp
, ECPP_nINIT
| ECPP_AFX
);
4268 drv_usecwait(1); /* Tp(ecp) == 0.5us */
4271 * Event 2: peripheral asserts nAck, deasserts nFault,
4272 * asserts Select, asserts PError
4274 if (wait_dsr(pp
, ECPP_nERR
| ECPP_SLCT
| ECPP_PE
| ECPP_nACK
,
4275 ECPP_nERR
| ECPP_SLCT
| ECPP_PE
, 35000) < 0) {
4276 /* peripheral is not 1284-compliant */
4278 "nego(%x): failed event 2 %x\n", xreq
, DSR_READ(pp
));
4279 (void) ecpp_1284_termination(pp
);
4284 * Event 3: host asserts nStrobe, latching extensibility value into
4285 * peripherals input latch.
4287 DCR_WRITE(pp
, ECPP_nINIT
| ECPP_AFX
| ECPP_STB
);
4289 drv_usecwait(2); /* Tp(ecp) = 0.5us */
4292 * Event 4: hosts deasserts nStrobe and nAutoFD to acknowledge that
4293 * it has recognized an 1284 compatible peripheral
4295 DCR_WRITE(pp
, ECPP_nINIT
);
4298 * Event 5: Peripheral confirms it supports requested extension
4299 * For Nibble mode Xflag must be low, otherwise it must be high
4301 xflag
= (xreq
== ECPP_XREQ_NIBBLE
) ? 0 : ECPP_SLCT
;
4304 * Event 6: Peripheral sets nAck high
4305 * indicating that status lines are valid
4307 if (wait_dsr(pp
, ECPP_nACK
, ECPP_nACK
, 35000) < 0) {
4308 /* Something wrong with peripheral */
4310 "nego(%x): failed event 6 %x\n", xreq
, DSR_READ(pp
));
4311 (void) ecpp_1284_termination(pp
);
4315 if ((DSR_READ(pp
) & ECPP_SLCT
) != xflag
) {
4316 /* Extensibility value is not supported */
4318 "nego(%x): failed event 5 %x\n", xreq
, DSR_READ(pp
));
4319 (void) ecpp_1284_termination(pp
);
4324 *rdsr
= DSR_READ(pp
);
4331 * 1284 Termination: Events 22..28 - set link to Compatibility mode
4333 * This routine is not designed for Immediate termination,
4334 * caller must take care of waiting for a valid state,
4335 * (in particular, in ECP mode current phase must be Forward Idle)
4336 * otherwise interface will be reinitialized
4338 * In case of Valid state termination SUCCESS is returned and
4339 * current_mode is ECPP_COMPAT_MODE, current phase is ECPP_PHASE_C_IDLE
4340 * Otherwise interface is reinitialized, FAILURE is returned and
4341 * current mode is ECPP_CENTRONICS, current phase is ECPP_PHASE_C_IDLE
4344 ecpp_1284_termination(struct ecppunit
*pp
)
4346 int previous_mode
= pp
->current_mode
;
4348 if (((pp
->current_mode
== ECPP_COMPAT_MODE
||
4349 pp
->current_mode
== ECPP_CENTRONICS
) &&
4350 pp
->current_phase
== ECPP_PHASE_C_IDLE
) ||
4351 pp
->current_mode
== ECPP_DIAG_MODE
) {
4352 ecpp_error(pp
->dip
, "termination: not needed\n");
4356 /* Set host into Compat mode, interrupts disabled */
4358 ECR_WRITE(pp
, ECPP_INTR_SRV
| ECPP_INTR_MASK
| ECR_mode_001
);
4360 pp
->current_mode
= ECPP_COMPAT_MODE
; /* needed by next function */
4362 ECPP_CONFIG_MODE(pp
);
4365 * EPP mode uses simple nInit pulse for termination
4367 if (previous_mode
== ECPP_EPP_MODE
) {
4368 /* Event 68: host sets nInit low */
4371 drv_usecwait(55); /* T(ER) = 50us */
4373 /* Event 69: host sets nInit high */
4374 DCR_WRITE(pp
, ECPP_nINIT
| ECPP_SLCTIN
);
4379 /* terminate peripheral to Compat mode */
4380 pp
->current_phase
= ECPP_PHASE_TERM
;
4382 /* Event 22: hosts sets nSelectIn low and nAutoFd high */
4383 DCR_WRITE(pp
, ECPP_nINIT
| ECPP_SLCTIN
);
4385 /* Event 23: peripheral deasserts nFault and nBusy */
4386 /* Event 24: peripheral asserts nAck */
4387 if (wait_dsr(pp
, ECPP_nERR
| ECPP_nBUSY
| ECPP_nACK
,
4388 ECPP_nERR
, 35000) < 0) {
4390 "termination: failed events 23,24 %x\n", DSR_READ(pp
));
4391 ecpp_1284_init_interface(pp
);
4395 drv_usecwait(1); /* Tp = 0.5us */
4397 /* Event 25: hosts sets nAutoFd low */
4398 DCR_WRITE(pp
, ECPP_nINIT
| ECPP_SLCTIN
| ECPP_AFX
);
4400 /* Event 26: the peripheral puts itself in Compatible mode */
4402 /* Event 27: peripheral deasserts nAck */
4403 if (wait_dsr(pp
, ECPP_nACK
, ECPP_nACK
, 35000) < 0) {
4405 "termination: failed event 27 %x\n", DSR_READ(pp
));
4406 ecpp_1284_init_interface(pp
);
4410 drv_usecwait(1); /* Tp = 0.5us */
4412 /* Event 28: hosts deasserts nAutoFd */
4413 DCR_WRITE(pp
, ECPP_nINIT
| ECPP_SLCTIN
);
4415 drv_usecwait(1); /* Tp = 0.5us */
4418 /* Compatible mode Idle Phase */
4419 pp
->current_phase
= ECPP_PHASE_C_IDLE
;
4421 ecpp_error(pp
->dip
, "termination: completed %x %x\n",
4422 DSR_READ(pp
), DCR_READ(pp
));
4428 * Initiate ECP backchannel DMA transfer
4431 ecp_peripheral2host(struct ecppunit
*pp
)
4437 ASSERT(pp
->current_mode
== ECPP_ECP_MODE
&&
4438 pp
->current_phase
== ECPP_PHASE_ECP_REV_IDLE
);
4441 * hardware generates cycles to receive data from the peripheral
4442 * we only need to read from FIFO
4446 * If user issued read(2) of rev_resid bytes, xfer exactly this amount
4447 * unless it exceeds ECP_REV_BLKSZ_MAX; otherwise try to read
4448 * ECP_REV_BLKSZ_MAX or at least ECP_REV_BLKSZ bytes
4450 if (pp
->nread
> 0) {
4451 len
= min(pp
->nread
, ECP_REV_BLKSZ_MAX
);
4453 len
= ECP_REV_BLKSZ_MAX
;
4456 pp
->nread
= 0; /* clear after use */
4459 * Allocate mblk for data, make max 2 attepmts:
4460 * if len bytes block fails, try our block size
4462 while ((mp
= allocb(len
, BPRI_MED
)) == NULL
) {
4464 "ecp_periph2host: failed allocb(%d)\n", len
);
4465 if (len
> ECP_REV_BLKSZ
) {
4466 len
= ECP_REV_BLKSZ
;
4477 pp
->e_busy
= ECPP_BUSY
;
4478 pp
->dma_dir
= DDI_DMA_READ
;
4479 pp
->current_phase
= ECPP_PHASE_ECP_REV_XFER
;
4481 if (ecpp_init_dma_xfer(pp
, (caddr_t
)mp
->b_rptr
, len
) == FAILURE
) {
4486 * there are two problems with defining ECP backchannel xfer timeout
4488 * a) IEEE 1284 allows infinite time between backchannel bytes,
4489 * but we must stop at some point to send the data upstream,
4490 * look if any forward transfer requests are pending, etc;
4491 * all that done, we can continue with backchannel data;
4493 * b) we don`t know how much data peripheral has;
4494 * DMA counter is set to our buffer size, which can be bigger
4495 * than needed - in this case a timeout must detect this;
4497 * The timeout we schedule here serves as both the transfer timeout
4498 * and a means of detecting backchannel stalls; in fact, there are
4499 * two timeouts in one:
4501 * - transfer timeout is based on the ECP bandwidth of ~1MB/sec and
4502 * equals the time needed to transfer the whole buffer
4503 * (but not less than ECP_REV_MINTOUT ms); if it occurs,
4504 * DMA is stopped and the data is sent upstream;
4506 * - backchannel watchdog, which would look at DMA counter
4507 * every rev_watchdog ms and stop the transfer only
4508 * if the counter hasn`t changed since the last time;
4509 * otherwise it would save DMA counter value and restart itself;
4511 * transfer timeout is a multiple of rev_watchdog
4512 * and implemented as a downward counter
4514 * on Grover, we can`t access DMAC registers while DMA is in flight,
4515 * so we can`t have watchdog on Grover, only timeout
4518 /* calculate number of watchdog invocations equal to the xfer timeout */
4519 xfer_time
= max((1000 * len
) / pp
->ecp_rev_speed
, ECP_REV_MINTOUT
);
4521 pp
->rev_timeout_cnt
= (pp
->hw
== &x86
) ? 1 :
4522 max(xfer_time
/ pp
->rev_watchdog
, 1);
4524 pp
->rev_timeout_cnt
= (pp
->hw
== &m1553
) ? 1 :
4525 max(xfer_time
/ pp
->rev_watchdog
, 1);
4528 pp
->last_dmacnt
= len
; /* nothing xferred yet */
4530 pp
->timeout_id
= timeout(ecpp_ecp_read_timeout
, (caddr_t
)pp
,
4531 drv_usectohz(pp
->rev_watchdog
* 1000));
4533 ecpp_error(pp
->dip
, "ecp_periph2host: DMA started len=%d\n"
4534 "xfer_time=%d wdog=%d cnt=%d\n",
4535 len
, xfer_time
, pp
->rev_watchdog
, pp
->rev_timeout_cnt
);
4543 pp
->e_busy
= ECPP_IDLE
;
4544 pp
->current_phase
= ECPP_PHASE_ECP_REV_IDLE
;
4550 * ECP backchannel read timeout
4551 * implements both backchannel watchdog and transfer timeout in ECP mode
4552 * if the transfer is still in progress, reschedule itself,
4553 * otherwise call completion routine
4556 ecpp_ecp_read_timeout(void *arg
)
4558 struct ecppunit
*pp
= arg
;
4561 mutex_enter(&pp
->umutex
);
4563 if (pp
->timeout_id
== 0) {
4564 mutex_exit(&pp
->umutex
);
4570 if (--pp
->rev_timeout_cnt
== 0) {
4572 * Transfer timed out
4574 ecpp_error(pp
->dip
, "ecp_read_timeout: timeout\n");
4576 ecpp_ecp_read_completion(pp
);
4579 * Backchannel watchdog:
4580 * look if DMA made any progress from the last time
4582 dmacnt
= ECPP_DMA_GETCNT(pp
);
4583 if (dmacnt
- pp
->last_dmacnt
== 0) {
4585 * No progress - stop the transfer and send
4586 * whatever has been read so far up the stream
4588 ecpp_error(pp
->dip
, "ecp_read_timeout: no progress\n");
4590 ecpp_ecp_read_completion(pp
);
4593 * Something was transferred - restart ourselves
4595 ecpp_error(pp
->dip
, "ecp_read_timeout: restarting\n");
4596 pp
->last_dmacnt
= dmacnt
;
4597 pp
->timeout_id
= timeout(ecpp_ecp_read_timeout
,
4599 drv_usectohz(pp
->rev_watchdog
* 1000));
4603 mutex_exit(&pp
->umutex
);
4607 * ECP backchannel read completion:
4608 * stop the DMA, free DMA resources and send read data upstream
4611 ecpp_ecp_read_completion(struct ecppunit
*pp
)
4613 size_t xfer_len
, unx_len
;
4616 ASSERT(mutex_owned(&pp
->umutex
));
4617 ASSERT(pp
->current_mode
== ECPP_ECP_MODE
&&
4618 pp
->current_phase
== ECPP_PHASE_ECP_REV_XFER
);
4619 ASSERT(pp
->msg
!= NULL
);
4622 * Stop the transfer and unbind DMA handle
4624 if (ECPP_DMA_STOP(pp
, &unx_len
) == FAILURE
) {
4625 unx_len
= pp
->resid
;
4626 ecpp_error(pp
->dip
, "ecp_read_completion: failed dma_stop\n");
4630 xfer_len
= pp
->resid
- unx_len
; /* how much data was transferred */
4632 if (ddi_dma_unbind_handle(pp
->dma_handle
) != DDI_SUCCESS
) {
4633 ecpp_error(pp
->dip
, "ecp_read_completion: unbind failed.\n");
4636 ecpp_error(pp
->dip
, "ecp_read_completion: xfered %d bytes of %d\n",
4637 xfer_len
, pp
->resid
);
4639 /* clean up and update statistics */
4641 pp
->resid
-= xfer_len
;
4642 pp
->ibytes
[pp
->current_mode
] += xfer_len
;
4643 pp
->e_busy
= ECPP_IDLE
;
4644 pp
->current_phase
= ECPP_PHASE_ECP_REV_IDLE
;
4647 * Send the read data up the stream
4649 mp
->b_wptr
+= xfer_len
;
4650 if (canputnext(pp
->readq
)) {
4651 mutex_exit(&pp
->umutex
);
4652 putnext(pp
->readq
, mp
);
4653 mutex_enter(&pp
->umutex
);
4655 ecpp_error(pp
->dip
, "ecp_read_completion: fail canputnext\n");
4656 if (!putq(pp
->readq
, mp
)) {
4661 /* if bytes left in the FIFO another transfer is needed */
4662 if (!(ECR_READ(pp
) & ECPP_FIFO_EMPTY
)) {
4663 (void) ecpp_backchan_req(pp
);
4666 qenable(pp
->writeq
);
4670 * Read one byte in the Nibble mode
4673 nibble_peripheral2host(struct ecppunit
*pp
, uint8_t *byte
)
4675 uint8_t n
[2]; /* two nibbles */
4679 * One byte is made of two nibbles
4681 for (i
= 0; i
< 2; i
++) {
4682 /* Event 7, 12: host asserts nAutoFd to move to read a nibble */
4683 DCR_WRITE(pp
, ECPP_nINIT
| ECPP_AFX
);
4685 /* Event 8: peripheral puts data on the status lines */
4687 /* Event 9: peripheral asserts nAck, data available */
4688 if (wait_dsr(pp
, ECPP_nACK
, 0, 35000) < 0) {
4690 "nibble_periph2host(%d): failed event 9 %x\n",
4691 i
+ 1, DSR_READ(pp
));
4692 (void) ecpp_1284_termination(pp
);
4696 n
[i
] = DSR_READ(pp
); /* get a nibble */
4698 /* Event 10: host deasserts nAutoFd to say it grabbed data */
4699 DCR_WRITE(pp
, ECPP_nINIT
);
4701 /* (2) Event 13: peripheral asserts PE - end of data phase */
4703 /* Event 11: peripheral deasserts nAck to finish handshake */
4704 if (wait_dsr(pp
, ECPP_nACK
, ECPP_nACK
, 35000) < 0) {
4706 "nibble_periph2host(%d): failed event 11 %x\n",
4707 i
+ 1, DSR_READ(pp
));
4708 (void) ecpp_1284_termination(pp
);
4713 /* extract data byte from two nibbles - optimized formula */
4714 *byte
= ((((n
[1] & ~ECPP_nACK
) << 1) | (~n
[1] & ECPP_nBUSY
)) & 0xf0) |
4715 ((((n
[0] & ~ECPP_nACK
) >> 3) | ((~n
[0] & ECPP_nBUSY
) >> 4)) & 0x0f);
4717 pp
->ibytes
[ECPP_NIBBLE_MODE
]++;
4722 * process data transfers requested by the peripheral
4725 ecpp_peripheral2host(struct ecppunit
*pp
)
4727 if (!canputnext(pp
->readq
)) {
4728 ecpp_error(pp
->dip
, "ecpp_peripheral2host: readq full\n");
4732 switch (pp
->backchannel
) {
4733 case ECPP_CENTRONICS
:
4734 /* no backchannel */
4737 case ECPP_NIBBLE_MODE
:
4738 ASSERT(pp
->current_mode
== ECPP_NIBBLE_MODE
);
4741 * Event 20: Host sets nAutoFd high to ack request
4743 DCR_WRITE(pp
, ECPP_nINIT
);
4745 /* Event 21: Periph sets PError low to ack host */
4746 if (wait_dsr(pp
, ECPP_PE
, 0, 35000) < 0) {
4748 "ecpp_periph2host: failed event 21 %x\n",
4750 (void) ecpp_1284_termination(pp
);
4754 pp
->current_phase
= ECPP_PHASE_NIBT_AVAIL
;
4756 /* this routine will read the data in Nibble mode */
4757 return (ecpp_idle_phase(pp
));
4760 if ((pp
->current_phase
== ECPP_PHASE_ECP_FWD_IDLE
) &&
4761 (ecp_forward2reverse(pp
) == FAILURE
)) {
4765 return (ecp_peripheral2host(pp
)); /* start the transfer */
4767 case ECPP_DIAG_MODE
: {
4771 if (ECR_READ(pp
) & ECPP_FIFO_EMPTY
) {
4772 ecpp_error(pp
->dip
, "ecpp_periph2host: fifo empty\n");
4776 /* allocate the FIFO size */
4777 if ((mp
= allocb(ECPP_FIFO_SZ
, BPRI_MED
)) == NULL
) {
4779 "ecpp_periph2host: allocb FAILURE.\n");
4784 * For the time being just read it byte by byte
4787 while (i
-- && (!(ECR_READ(pp
) & ECPP_FIFO_EMPTY
))) {
4788 *mp
->b_wptr
++ = TFIFO_READ(pp
);
4789 drv_usecwait(1); /* ECR is sometimes slow to update */
4792 if (canputnext(pp
->readq
)) {
4793 mutex_exit(&pp
->umutex
);
4794 mp
->b_datap
->db_type
= M_DATA
;
4796 "ecpp_periph2host: sending %d bytes\n",
4797 mp
->b_wptr
- mp
->b_rptr
);
4798 putnext(pp
->readq
, mp
);
4799 mutex_enter(&pp
->umutex
);
4803 "ecpp_periph2host: !canputnext data lost\n");
4810 ecpp_error(pp
->dip
, "ecpp_peripheraltohost: illegal back");
4816 * Negotiate from ECP Forward Idle to Reverse Idle Phase
4818 * (manipulations with dcr/ecr are according to ECP Specification)
4821 ecp_forward2reverse(struct ecppunit
*pp
)
4823 ASSERT(pp
->current_mode
== ECPP_ECP_MODE
&&
4824 pp
->current_phase
== ECPP_PHASE_ECP_FWD_IDLE
);
4826 /* place port into PS2 mode */
4827 ECR_WRITE(pp
, ECR_mode_001
| ECPP_INTR_SRV
| ECPP_INTR_MASK
);
4829 /* set direction bit (DCR3-0 must be 0100 - National) */
4830 DCR_WRITE(pp
, ECPP_REV_DIR
| ECPP_nINIT
);
4832 /* enable hardware assist */
4833 ECR_WRITE(pp
, ECR_mode_011
| ECPP_INTR_SRV
| ECPP_INTR_MASK
);
4835 drv_usecwait(1); /* Tp(ecp) = 0.5us */
4837 /* Event 39: host sets nInit low */
4838 DCR_WRITE(pp
, ECPP_REV_DIR
);
4840 /* Event 40: peripheral sets PError low */
4842 pp
->current_phase
= ECPP_PHASE_ECP_REV_IDLE
;
4844 ecpp_error(pp
->dip
, "ecp_forward2reverse ok\n");
4850 * Negotiate from ECP Reverse Idle to Forward Idle Phase
4852 * (manipulations with dcr/ecr are according to ECP Specification)
4855 ecp_reverse2forward(struct ecppunit
*pp
)
4857 ASSERT(pp
->current_mode
== ECPP_ECP_MODE
&&
4858 pp
->current_phase
== ECPP_PHASE_ECP_REV_IDLE
);
4860 /* Event 47: host deasserts nInit */
4861 DCR_WRITE(pp
, ECPP_REV_DIR
| ECPP_nINIT
);
4864 * Event 48: peripheral deasserts nAck
4865 * Event 49: peripheral asserts PError
4867 if (wait_dsr(pp
, ECPP_PE
, ECPP_PE
, 35000) < 0) {
4869 "ecp_reverse2forward: failed event 49 %x\n", DSR_READ(pp
));
4870 (void) ecpp_1284_termination(pp
);
4874 /* place port into PS2 mode */
4875 ECR_WRITE(pp
, ECR_mode_001
| ECPP_INTR_SRV
| ECPP_INTR_MASK
);
4877 /* clear direction bit */
4878 DCR_WRITE(pp
, ECPP_nINIT
);
4880 /* reenable hardware assist */
4881 ECR_WRITE(pp
, ECR_mode_011
| ECPP_INTR_SRV
| ECPP_INTR_MASK
);
4883 pp
->current_phase
= ECPP_PHASE_ECP_FWD_IDLE
;
4885 ecpp_error(pp
->dip
, "ecp_reverse2forward ok\n");
4891 * Default negotiation chooses the best mode supported by peripheral
4892 * Note that backchannel mode may be different from forward mode
4895 ecpp_default_negotiation(struct ecppunit
*pp
)
4897 if (!noecp
&& (ecpp_mode_negotiation(pp
, ECPP_ECP_MODE
) == SUCCESS
)) {
4898 /* 1284 compatible device */
4899 pp
->io_mode
= (pp
->fast_compat
== TRUE
) ? ECPP_DMA
: ECPP_PIO
;
4901 } else if (ecpp_mode_negotiation(pp
, ECPP_NIBBLE_MODE
) == SUCCESS
) {
4902 /* 1284 compatible device */
4903 pp
->io_mode
= (pp
->fast_compat
== TRUE
) ? ECPP_DMA
: ECPP_PIO
;
4905 /* Centronics device */
4907 (pp
->fast_centronics
== TRUE
) ? ECPP_DMA
: ECPP_PIO
;
4909 ECPP_CONFIG_MODE(pp
);
4913 * Negotiate to the mode indicated by newmode
4916 ecpp_mode_negotiation(struct ecppunit
*pp
, uchar_t newmode
)
4918 /* any other mode is impossible */
4919 ASSERT(pp
->current_mode
== ECPP_CENTRONICS
||
4920 pp
->current_mode
== ECPP_COMPAT_MODE
||
4921 pp
->current_mode
== ECPP_NIBBLE_MODE
||
4922 pp
->current_mode
== ECPP_ECP_MODE
||
4923 pp
->current_mode
== ECPP_DIAG_MODE
);
4925 if (pp
->current_mode
== newmode
) {
4929 /* termination from ECP is only allowed from the Forward Idle Phase */
4930 if ((pp
->current_mode
== ECPP_ECP_MODE
) &&
4931 (pp
->current_phase
!= ECPP_PHASE_ECP_FWD_IDLE
)) {
4932 /* this may break into Centronics */
4933 (void) ecp_reverse2forward(pp
);
4937 case ECPP_CENTRONICS
:
4938 (void) ecpp_1284_termination(pp
);
4940 /* put superio into PIO mode */
4941 ECR_WRITE(pp
, ECR_mode_001
| ECPP_INTR_MASK
| ECPP_INTR_SRV
);
4943 pp
->current_mode
= ECPP_CENTRONICS
;
4944 pp
->backchannel
= ECPP_CENTRONICS
;
4945 ECPP_CONFIG_MODE(pp
);
4947 pp
->to_mode
[pp
->current_mode
]++;
4950 case ECPP_COMPAT_MODE
:
4951 /* ECPP_COMPAT_MODE should support Nibble as a backchannel */
4952 if (pp
->current_mode
== ECPP_NIBBLE_MODE
) {
4953 if (ecpp_1284_termination(pp
) == SUCCESS
) {
4954 pp
->current_mode
= ECPP_COMPAT_MODE
;
4955 pp
->backchannel
= ECPP_NIBBLE_MODE
;
4956 ECPP_CONFIG_MODE(pp
);
4957 pp
->to_mode
[pp
->current_mode
]++;
4964 if ((nibble_negotiation(pp
) == SUCCESS
) &&
4965 (ecpp_1284_termination(pp
) == SUCCESS
)) {
4966 pp
->backchannel
= ECPP_NIBBLE_MODE
;
4967 pp
->current_mode
= ECPP_COMPAT_MODE
;
4968 ECPP_CONFIG_MODE(pp
);
4969 pp
->to_mode
[pp
->current_mode
]++;
4975 case ECPP_NIBBLE_MODE
:
4976 if (nibble_negotiation(pp
) == FAILURE
) {
4980 pp
->backchannel
= ECPP_NIBBLE_MODE
;
4981 ECPP_CONFIG_MODE(pp
);
4982 pp
->to_mode
[pp
->current_mode
]++;
4989 if (ecp_negotiation(pp
) == FAILURE
) {
4994 * National says CTR[3:0] should be 0100b before moving to 011
4996 DCR_WRITE(pp
, ECPP_nINIT
);
4998 if (ecr_write(pp
, ECR_mode_011
|
4999 ECPP_INTR_MASK
| ECPP_INTR_SRV
) == FAILURE
) {
5000 ecpp_error(pp
->dip
, "mode_nego:ECP: failed w/ecr\n");
5004 ECPP_CONFIG_MODE(pp
);
5005 pp
->to_mode
[pp
->current_mode
]++;
5009 case ECPP_DIAG_MODE
:
5011 * In DIAG mode application can do nasty things(e.g drive pins)
5012 * To keep peripheral sane, terminate to Compatibility mode
5014 (void) ecpp_1284_termination(pp
);
5016 /* put superio into TFIFO mode */
5017 if (ecr_write(pp
, ECR_mode_001
|
5018 ECPP_INTR_MASK
| ECPP_INTR_SRV
) == FAILURE
) {
5019 ecpp_error(pp
->dip
, "put to TFIFO: failed w/ecr\n");
5023 pp
->current_mode
= ECPP_DIAG_MODE
;
5024 pp
->backchannel
= ECPP_DIAG_MODE
;
5025 ECPP_CONFIG_MODE(pp
);
5026 pp
->to_mode
[pp
->current_mode
]++;
5032 "ecpp_mode_negotiation: mode %d not supported\n", newmode
);
5038 * Standard (9.1): Peripheral data is available only when the host places
5039 * the interface in a mode capable of peripheral-to-host data transfer.
5040 * This requires the host periodically to place the interface in such a mode.
5041 * Polling can be eliminated by leaving the interface in an 1284 idle phase.
5044 ecpp_idle_phase(struct ecppunit
*pp
)
5046 uchar_t rval
= FAILURE
;
5049 * If there is no space on the read queue, do not reverse channel
5051 if (!canputnext(pp
->readq
)) {
5052 ecpp_error(pp
->dip
, "ecpp_idle_phase: readq full\n");
5056 switch (pp
->backchannel
) {
5057 case ECPP_CENTRONICS
:
5058 case ECPP_COMPAT_MODE
:
5059 case ECPP_DIAG_MODE
:
5061 ecpp_error(pp
->dip
, "ecpp_idle_phase: compat idle\n");
5064 case ECPP_NIBBLE_MODE
:
5066 * read as much data as possible, ending up in either
5067 * Reverse Idle or Host Busy Data Available phase
5069 ecpp_error(pp
->dip
, "ecpp_idle_phase: nibble backchannel\n");
5070 if ((pp
->current_mode
!= ECPP_NIBBLE_MODE
) &&
5071 (ecpp_mode_negotiation(pp
, ECPP_NIBBLE_MODE
) == FAILURE
)) {
5075 rval
= read_nibble_backchan(pp
);
5077 /* put interface into Reverse Idle phase */
5078 if (pp
->current_phase
== ECPP_PHASE_NIBT_NAVAIL
&&
5079 canputnext(pp
->readq
)) {
5080 ecpp_error(pp
->dip
, "ecpp_idle_phase: going revidle\n");
5083 * Event 7: host asserts nAutoFd
5084 * enable nAck interrupt to get a backchannel request
5086 DCR_WRITE(pp
, ECPP_nINIT
| ECPP_AFX
| ECPP_INTR_EN
);
5088 ECPP_UNMASK_INTR(pp
);
5095 * if data is already available, request the backchannel xfer
5096 * otherwise stay in Forward Idle and enable nErr interrupts
5098 ecpp_error(pp
->dip
, "ecpp_idle_phase: ECP forward\n");
5100 ASSERT(pp
->current_phase
== ECPP_PHASE_ECP_FWD_IDLE
||
5101 pp
->current_phase
== ECPP_PHASE_ECP_REV_IDLE
);
5103 /* put interface into Forward Idle phase */
5104 if ((pp
->current_phase
== ECPP_PHASE_ECP_REV_IDLE
) &&
5105 (ecp_reverse2forward(pp
) == FAILURE
)) {
5110 * if data already available, put backchannel request on the wq
5111 * otherwise enable nErr interrupts
5113 if ((DSR_READ(pp
) & ECPP_nERR
) == 0) {
5114 (void) ecpp_backchan_req(pp
);
5117 ECR_READ(pp
) & ~ECPP_INTR_MASK
| ECPP_INTR_SRV
);
5119 ECPP_UNMASK_INTR(pp
);
5125 ecpp_error(pp
->dip
, "ecpp_idle_phase: illegal backchannel");
5132 * This routine will leave the port in ECPP_PHASE_NIBT_REVIDLE
5133 * Due to flow control, though, it may stop at ECPP_PHASE_NIBT_AVAIL,
5134 * and continue later as the user consumes data from the read queue
5136 * The current phase should be NIBT_AVAIL or NIBT_NAVAIL
5137 * If some events fail during transfer, termination puts link
5138 * to Compatibility mode and FAILURE is returned
5141 read_nibble_backchan(struct ecppunit
*pp
)
5147 ASSERT(pp
->current_mode
== ECPP_NIBBLE_MODE
);
5149 pp
->current_phase
= (DSR_READ(pp
) & (ECPP_nERR
| ECPP_PE
))
5150 ? ECPP_PHASE_NIBT_NAVAIL
: ECPP_PHASE_NIBT_AVAIL
;
5152 ecpp_error(pp
->dip
, "read_nibble_backchan: %x\n", DSR_READ(pp
));
5155 * While data is available, read it in NIBBLE_REV_BLKSZ byte chunks
5156 * and send up the stream
5158 while (pp
->current_phase
== ECPP_PHASE_NIBT_AVAIL
&& rval
== SUCCESS
) {
5159 /* see if there's space on the queue */
5160 if (!canputnext(pp
->readq
)) {
5162 "read_nibble_backchan: canputnext failed\n");
5166 if ((mp
= allocb(NIBBLE_REV_BLKSZ
, BPRI_MED
)) == NULL
) {
5168 "read_nibble_backchan: allocb failed\n");
5172 /* read a chunk of data from the peripheral byte by byte */
5173 i
= NIBBLE_REV_BLKSZ
;
5174 while (i
-- && !(DSR_READ(pp
) & ECPP_nERR
)) {
5175 if (nibble_peripheral2host(pp
, mp
->b_wptr
) != SUCCESS
) {
5182 pp
->current_phase
= (DSR_READ(pp
) & (ECPP_nERR
| ECPP_PE
))
5183 ? ECPP_PHASE_NIBT_NAVAIL
5184 : ECPP_PHASE_NIBT_AVAIL
;
5186 if (mp
->b_wptr
- mp
->b_rptr
> 0) {
5188 "read_nibble_backchan: sending %d bytes\n",
5189 mp
->b_wptr
- mp
->b_rptr
);
5191 mutex_exit(&pp
->umutex
);
5192 putnext(pp
->readq
, mp
);
5193 mutex_enter(&pp
->umutex
);
5203 * 'Request Device ID using nibble mode' negotiation
5206 devidnib_negotiation(struct ecppunit
*pp
)
5210 if (ecpp_1284_negotiation(pp
,
5211 ECPP_XREQ_NIBBLE
| ECPP_XREQ_ID
, &dsr
) == FAILURE
) {
5216 * If peripheral has data available, PE and nErr will
5217 * be set low at Event 5 & 6.
5219 if ((dsr
& (ECPP_PE
| ECPP_nERR
)) == 0) {
5220 pp
->current_phase
= ECPP_PHASE_NIBT_AVAIL
;
5222 pp
->current_phase
= ECPP_PHASE_NIBT_NAVAIL
;
5225 ecpp_error(pp
->dip
, "ecpp_devidnib_nego: current_phase=%x\n",
5228 /* successful negotiation into Nibble mode */
5229 pp
->current_mode
= ECPP_NIBBLE_MODE
;
5230 pp
->backchannel
= ECPP_NIBBLE_MODE
;
5232 ecpp_error(pp
->dip
, "ecpp_devidnib_nego: ok\n");
5238 * Read 1284 device ID sequence
5240 * This function should be called two times:
5241 * 1) ecpp_getdevid(pp, NULL, &len) - to retrieve ID length;
5242 * 2) ecpp_getdevid(pp, buffer, &len) - to read len bytes into buffer
5244 * After 2) port is in Compatible mode
5245 * If the caller fails to make second call, it must reset port to Centronics
5249 ecpp_getdevid(struct ecppunit
*pp
, uint8_t *id
, int *lenp
, int mode
)
5251 uint8_t lenhi
, lenlo
;
5256 case ECPP_NIBBLE_MODE
:
5257 /* negotiate only if neccessary */
5258 if ((pp
->current_mode
!= mode
) || (id
== NULL
)) {
5259 if (devidnib_negotiation(pp
) == FAILURE
) {
5264 if (pp
->current_phase
!= ECPP_PHASE_NIBT_AVAIL
) {
5269 * Event 14: Host tristates data bus, peripheral
5270 * asserts nERR if data available, usually the
5271 * status bits (7-0) and requires two reads since
5272 * only nibbles are transfered.
5278 * first two bytes are the length of the sequence
5279 * (incl. these bytes)
5282 if ((dsr
& ECPP_nERR
) ||
5283 (nibble_peripheral2host(pp
, &lenhi
) == FAILURE
) ||
5284 (dsr
& ECPP_nERR
) ||
5285 (nibble_peripheral2host(pp
, &lenlo
) == FAILURE
)) {
5287 "ecpp_getdevid: id length read error\n");
5291 *lenp
= (lenhi
<< 8) | (lenlo
);
5294 "ecpp_getdevid: id length = %d\n", *lenp
);
5301 * read the rest of the data
5304 while (i
&& ((dsr
& ECPP_nERR
) == 0)) {
5305 if (nibble_peripheral2host(pp
, id
++) == FAILURE
)
5312 "ecpp_getdevid: read %d bytes\n", *lenp
- i
);
5315 * 1284: After receiving the sequence, the host is
5316 * required to return the link to the Compatibility mode
5318 (void) ecpp_1284_termination(pp
);
5323 /* Other modes are not yet supported */
5332 * Various hardware support
5334 * First define some stubs for functions that do nothing
5339 empty_config_mode(struct ecppunit
*pp
)
5345 empty_mask_intr(struct ecppunit
*pp
)
5351 x86_getcnt(struct ecppunit
*pp
)
5355 (void) ddi_dmae_getcnt(pp
->dip
, pp
->uh
.x86
.chn
, &count
);
5362 * National PC87332 and PC97317 SuperIOs support routines
5363 * These chips are used in PCI-based Darwin, Quark, Quasar, Excalibur
5364 * and use EBus DMA facilities (Cheerio or RIO)
5369 pc87332_map_regs(struct ecppunit
*pp
)
5371 if (ddi_regs_map_setup(pp
->dip
, 1, (caddr_t
*)&pp
->uh
.ebus
.c_reg
, 0,
5372 sizeof (struct config_reg
), &acc_attr
,
5373 &pp
->uh
.ebus
.c_handle
) != DDI_SUCCESS
) {
5374 ecpp_error(pp
->dip
, "pc87332_map_regs: failed c_reg\n");
5378 if (ddi_regs_map_setup(pp
->dip
, 0, (caddr_t
*)&pp
->i_reg
, 0,
5379 sizeof (struct info_reg
), &acc_attr
, &pp
->i_handle
)
5381 ecpp_error(pp
->dip
, "pc87332_map_regs: failed i_reg\n");
5385 if (ddi_regs_map_setup(pp
->dip
, 0, (caddr_t
*)&pp
->f_reg
, 0x400,
5386 sizeof (struct fifo_reg
), &acc_attr
, &pp
->f_handle
)
5388 ecpp_error(pp
->dip
, "pc87332_map_regs: failed f_reg\n");
5392 if (ddi_regs_map_setup(pp
->dip
, 2, (caddr_t
*)&pp
->uh
.ebus
.dmac
, 0,
5393 sizeof (struct cheerio_dma_reg
), &acc_attr
,
5394 &pp
->uh
.ebus
.d_handle
) != DDI_SUCCESS
) {
5395 ecpp_error(pp
->dip
, "pc87332_map_regs: failed dmac\n");
5402 pc87332_unmap_regs(pp
);
5407 pc87332_unmap_regs(struct ecppunit
*pp
)
5409 if (pp
->uh
.ebus
.c_handle
) {
5410 ddi_regs_map_free(&pp
->uh
.ebus
.c_handle
);
5412 if (pp
->uh
.ebus
.d_handle
) {
5413 ddi_regs_map_free(&pp
->uh
.ebus
.d_handle
);
5416 ddi_regs_map_free(&pp
->i_handle
);
5419 ddi_regs_map_free(&pp
->f_handle
);
5424 pc87332_read_config_reg(struct ecppunit
*pp
, uint8_t reg_num
)
5428 PP_PUTB(pp
->uh
.ebus
.c_handle
, &pp
->uh
.ebus
.c_reg
->index
, reg_num
);
5429 retval
= PP_GETB(pp
->uh
.ebus
.c_handle
, &pp
->uh
.ebus
.c_reg
->data
);
5435 pc87332_write_config_reg(struct ecppunit
*pp
, uint8_t reg_num
, uint8_t val
)
5437 PP_PUTB(pp
->uh
.ebus
.c_handle
, &pp
->uh
.ebus
.c_reg
->index
, reg_num
);
5438 PP_PUTB(pp
->uh
.ebus
.c_handle
, &pp
->uh
.ebus
.c_reg
->data
, val
);
5441 * second write to this register is needed. the register behaves as
5442 * a fifo. the first value written goes to the data register. the
5443 * second write pushes the initial value to the register indexed.
5446 PP_PUTB(pp
->uh
.ebus
.c_handle
, &pp
->uh
.ebus
.c_reg
->data
, val
);
5450 pc87332_config_chip(struct ecppunit
*pp
)
5454 pp
->current_phase
= ECPP_PHASE_INIT
;
5456 /* ECP DMA configuration bit (PMC4) must be set */
5457 pmc
= pc87332_read_config_reg(pp
, PMC
);
5458 if (!(pmc
& PC87332_PMC_ECP_DMA_CONFIG
)) {
5459 pc87332_write_config_reg(pp
, PMC
,
5460 pmc
| PC87332_PMC_ECP_DMA_CONFIG
);
5464 * The Parallel Port Multiplexor pins must be driven.
5465 * Check to see if FCR3 is zero, if not clear FCR3.
5467 fcr
= pc87332_read_config_reg(pp
, FCR
);
5468 if (fcr
& PC87332_FCR_PPM_FLOAT_CTL
) {
5469 pc87332_write_config_reg(pp
, FCR
,
5470 fcr
& ~PC87332_FCR_PPM_FLOAT_CTL
);
5474 * clear bits 3-0 in CTR (aka DCR) prior to enabling ECP mode
5475 * CTR5 can not be cleared in SPP mode, CTR5 will return 1.
5476 * "FAILURE" in this case is ok. Better to use dcr_write()
5477 * to ensure reliable writing to DCR.
5479 if (dcr_write(pp
, ECPP_DCR_SET
| ECPP_nINIT
) == FAILURE
) {
5480 ecpp_error(pp
->dip
, "ecpp_config_87332: DCR config\n");
5483 /* enable ECP mode, level intr (note that DCR bits 3-0 == 0x0) */
5484 pc87332_write_config_reg(pp
, PCR
,
5485 PC87332_PCR_INTR_LEVL
| PC87332_PCR_ECP_EN
);
5487 /* put SuperIO in initial state */
5488 if (ecr_write(pp
, ECR_mode_001
|
5489 ECPP_INTR_MASK
| ECPP_INTR_SRV
) == FAILURE
) {
5490 ecpp_error(pp
->dip
, "ecpp_config_87332: ECR\n");
5493 if (dcr_write(pp
, ECPP_DCR_SET
| ECPP_SLCTIN
| ECPP_nINIT
) == FAILURE
) {
5494 ecpp_error(pp
->dip
, "ecpp_config_87332: w/DCR failed2.\n");
5498 /* we are in centronic mode */
5499 pp
->current_mode
= ECPP_CENTRONICS
;
5501 /* in compatible mode with no data transfer in progress */
5502 pp
->current_phase
= ECPP_PHASE_C_IDLE
;
5508 * A new mode was set, do some mode specific reconfiguration
5509 * in this case - set interrupt characteristic
5512 pc87332_config_mode(struct ecppunit
*pp
)
5514 if (COMPAT_PIO(pp
)) {
5515 pc87332_write_config_reg(pp
, PCR
, 0x04);
5517 pc87332_write_config_reg(pp
, PCR
, 0x14);
5522 pc97317_map_regs(struct ecppunit
*pp
)
5524 if (pc87332_map_regs(pp
) != SUCCESS
) {
5528 if (ddi_regs_map_setup(pp
->dip
, 0, (caddr_t
*)&pp
->uh
.ebus
.c2_reg
,
5529 0x403, sizeof (struct config2_reg
), &acc_attr
,
5530 &pp
->uh
.ebus
.c2_handle
) != DDI_SUCCESS
) {
5531 ecpp_error(pp
->dip
, "pc97317_map_regs: failed c2_reg\n");
5532 pc87332_unmap_regs(pp
);
5540 pc97317_unmap_regs(struct ecppunit
*pp
)
5542 if (pp
->uh
.ebus
.c2_handle
) {
5543 ddi_regs_map_free(&pp
->uh
.ebus
.c2_handle
);
5546 pc87332_unmap_regs(pp
);
5550 * OBP should configure the PC97317 such that it does not need further
5551 * configuration. Upon sustaining, it may be necessary to examine
5552 * or change the configuration registers. This routine is left in
5553 * the file for that purpose.
5556 pc97317_config_chip(struct ecppunit
*pp
)
5560 /* set the logical device name */
5561 pc87332_write_config_reg(pp
, PC97317_CONFIG_DEV_NO
, 0x4);
5563 /* SPP Compatibility */
5564 PP_PUTB(pp
->uh
.ebus
.c2_handle
,
5565 &pp
->uh
.ebus
.c2_reg
->eir
, PC97317_CONFIG2_CONTROL2
);
5566 PP_PUTB(pp
->uh
.ebus
.c2_handle
, &pp
->uh
.ebus
.c2_reg
->edr
, 0x80);
5568 /* low interrupt polarity */
5569 pc87332_write_config_reg(pp
, PC97317_CONFIG_INTR_TYPE
, 0x00);
5572 pc87332_write_config_reg(pp
, PC97317_CONFIG_PP_CONFIG
, 0xf2);
5574 if (dcr_write(pp
, ECPP_SLCTIN
| ECPP_nINIT
) == FAILURE
) {
5575 ecpp_error(pp
->dip
, "pc97317_config_chip: failed w/DCR\n");
5578 if (ecr_write(pp
, ECR_mode_001
|
5579 ECPP_INTR_MASK
| ECPP_INTR_SRV
) == FAILURE
) {
5580 ecpp_error(pp
->dip
, "pc97317_config_chip: failed w/ECR\n");
5584 conreg
= pc87332_read_config_reg(pp
, PC97317_CONFIG_DEV_NO
);
5585 ecpp_error(pp
->dip
, "97317:conreg7(logical dev)=%x\n", conreg
);
5587 conreg
= pc87332_read_config_reg(pp
, PC97317_CONFIG_BASE_ADDR_MSB
);
5588 ecpp_error(pp
->dip
, "97317:conreg60(addrHi)=%x\n", conreg
);
5590 conreg
= pc87332_read_config_reg(pp
, PC97317_CONFIG_BASE_ADDR_LSB
);
5591 ecpp_error(pp
->dip
, "97317:conreg61(addrLo)=%x\n", conreg
);
5593 conreg
= pc87332_read_config_reg(pp
, PC97317_CONFIG_INTR_SEL
);
5594 ecpp_error(pp
->dip
, "97317:conreg70(IRQL)=%x\n", conreg
);
5596 conreg
= pc87332_read_config_reg(pp
, PC97317_CONFIG_INTR_TYPE
);
5597 ecpp_error(pp
->dip
, "97317:conreg71(intr type)=%x\n", conreg
);
5599 conreg
= pc87332_read_config_reg(pp
, PC97317_CONFIG_ACTIVATE
);
5600 ecpp_error(pp
->dip
, "97317:conreg30(Active)=%x\n", conreg
);
5602 conreg
= pc87332_read_config_reg(pp
, PC97317_CONFIG_IO_RANGE
);
5603 ecpp_error(pp
->dip
, "97317:conreg31(IO Range Check)=%x\n", conreg
);
5605 conreg
= pc87332_read_config_reg(pp
, PC97317_CONFIG_DMA0_CHAN
);
5606 ecpp_error(pp
->dip
, "97317:conreg74(DMA0 Chan)=%x\n", conreg
);
5607 conreg
= pc87332_read_config_reg(pp
, PC97317_CONFIG_DMA1_CHAN
);
5608 ecpp_error(pp
->dip
, "97317:conreg75(DMA1 Chan)=%x\n", conreg
);
5610 conreg
= pc87332_read_config_reg(pp
, PC97317_CONFIG_PP_CONFIG
);
5611 ecpp_error(pp
->dip
, "97317:conregFO(pport conf)=%x\n", conreg
);
5613 conreg
= pc87332_read_config_reg(pp
, PC97317_CONFIG_PP_CONFIG
);
5614 ecpp_error(pp
->dip
, "97317:conregFO(pport conf)=%x\n", conreg
);
5621 * A new mode was set, do some mode specific reconfiguration
5622 * in this case - set interrupt polarity
5625 pc97317_config_mode(struct ecppunit
*pp
)
5627 /* set the logical device name */
5628 pc87332_write_config_reg(pp
, PC97317_CONFIG_DEV_NO
, 0x4);
5630 if (COMPAT_PIO(pp
) || pp
->current_mode
== ECPP_NIBBLE_MODE
) {
5631 pc87332_write_config_reg(pp
, PC97317_CONFIG_INTR_TYPE
, 0x02);
5633 pc87332_write_config_reg(pp
, PC97317_CONFIG_INTR_TYPE
, 0x00);
5638 cheerio_mask_intr(struct ecppunit
*pp
)
5640 /* mask Cheerio interrupts */
5641 AND_SET_LONG_R(pp
->uh
.ebus
.d_handle
,
5642 &pp
->uh
.ebus
.dmac
->csr
, ~DCSR_INT_EN
);
5646 cheerio_unmask_intr(struct ecppunit
*pp
)
5648 /* unmask Cheerio interrupts */
5649 OR_SET_LONG_R(pp
->uh
.ebus
.d_handle
,
5650 &pp
->uh
.ebus
.dmac
->csr
, DCSR_INT_EN
| DCSR_TCI_DIS
);
5654 cheerio_dma_start(struct ecppunit
*pp
)
5656 cheerio_reset_dcsr(pp
);
5657 SET_DMAC_BCR(pp
, pp
->dma_cookie
.dmac_size
);
5658 SET_DMAC_ACR(pp
, pp
->dma_cookie
.dmac_address
);
5660 if (pp
->dma_dir
== DDI_DMA_READ
) {
5661 SET_DMAC_CSR(pp
, DCSR_INT_EN
| DCSR_EN_CNT
| DCSR_EN_DMA
|
5662 DCSR_CSR_DRAIN
| DCSR_BURST_1
| DCSR_BURST_0
| DCSR_WRITE
);
5664 SET_DMAC_CSR(pp
, DCSR_INT_EN
| DCSR_EN_CNT
| DCSR_EN_DMA
|
5665 DCSR_CSR_DRAIN
| DCSR_BURST_1
| DCSR_BURST_0
);
5672 * Note: BCR is reset to 0, so counter should always be read before dma_stop
5675 cheerio_dma_stop(struct ecppunit
*pp
, size_t *countp
)
5679 /* disable DMA and byte counter */
5680 AND_SET_LONG_R(pp
->uh
.ebus
.d_handle
, &pp
->uh
.ebus
.dmac
->csr
,
5681 ~(DCSR_EN_DMA
| DCSR_EN_CNT
| DCSR_INT_EN
));
5683 /* ACK and disable the TC interrupt */
5684 OR_SET_LONG_R(pp
->uh
.ebus
.d_handle
, &pp
->uh
.ebus
.dmac
->csr
,
5685 DCSR_TC
| DCSR_TCI_DIS
);
5687 /* read DMA count if requested */
5689 *countp
= cheerio_getcnt(pp
);
5692 cheerio_reset_dcsr(pp
);
5693 SET_DMAC_BCR(pp
, 0);
5695 /* turn off SuperIO's DMA */
5697 if (ecr_write(pp
, ecr
& ~ECPP_DMA_ENABLE
) == FAILURE
) {
5701 /* Disable SuperIO interrupts and DMA */
5704 return (ecr_write(pp
, ecr
| ECPP_INTR_SRV
));
5708 cheerio_getcnt(struct ecppunit
*pp
)
5710 return (GET_DMAC_BCR(pp
));
5714 * Reset the DCSR by first setting the RESET bit to 1. Poll the
5715 * DCSR_CYC_PEND bit to make sure there are no more pending DMA cycles.
5716 * If there are no more pending cycles, clear the RESET bit.
5719 cheerio_reset_dcsr(struct ecppunit
*pp
)
5721 int timeout
= DMAC_RESET_TIMEOUT
;
5723 SET_DMAC_CSR(pp
, DCSR_RESET
);
5725 while (GET_DMAC_CSR(pp
) & DCSR_CYC_PEND
) {
5727 ecpp_error(pp
->dip
, "cheerio_reset_dcsr: timeout\n");
5735 SET_DMAC_CSR(pp
, 0);
5740 * Grover Southbridge (M1553) support routines
5741 * Southbridge contains an Intel 8237 DMAC onboard which is used
5742 * to transport data to/from PCI space to superio parallel port
5748 m1553_map_regs(struct ecppunit
*pp
)
5750 if (ddi_regs_map_setup(pp
->dip
, 1, (caddr_t
*)&pp
->uh
.m1553
.isa_space
,
5751 0, sizeof (struct isaspace
), &acc_attr
,
5752 &pp
->uh
.m1553
.d_handle
) != DDI_SUCCESS
) {
5753 ecpp_error(pp
->dip
, "m1553_map_regs: failed isa space\n");
5757 if (ddi_regs_map_setup(pp
->dip
, 0, (caddr_t
*)&pp
->i_reg
, 0,
5758 sizeof (struct info_reg
), &acc_attr
, &pp
->i_handle
)
5760 ecpp_error(pp
->dip
, "m1553_map_regs: failed i_reg\n");
5764 if (ddi_regs_map_setup(pp
->dip
, 0, (caddr_t
*)&pp
->f_reg
, 0x400,
5765 sizeof (struct fifo_reg
), &acc_attr
, &pp
->f_handle
)
5767 ecpp_error(pp
->dip
, "m1553_map_regs: failed f_reg\n");
5774 m1553_unmap_regs(pp
);
5779 m1553_unmap_regs(struct ecppunit
*pp
)
5781 if (pp
->uh
.m1553
.d_handle
) {
5782 ddi_regs_map_free(&pp
->uh
.m1553
.d_handle
);
5785 ddi_regs_map_free(&pp
->i_handle
);
5788 ddi_regs_map_free(&pp
->f_handle
);
5794 x86_map_regs(struct ecppunit
*pp
)
5798 if (ddi_regs_map_setup(pp
->dip
, 0, (caddr_t
*)&pp
->i_reg
, 0,
5799 sizeof (struct info_reg
), &acc_attr
, &pp
->i_handle
)
5801 ecpp_error(pp
->dip
, "x86_map_regs: failed i_reg\n");
5804 if (ddi_dev_nregs(pp
->dip
, &nregs
) == DDI_SUCCESS
&& nregs
== 2) {
5805 if (ddi_regs_map_setup(pp
->dip
, 1, (caddr_t
*)&pp
->f_reg
, 0,
5806 sizeof (struct fifo_reg
), &acc_attr
, &pp
->f_handle
)
5808 ecpp_error(pp
->dip
, "x86_map_regs: failed f_reg\n");
5811 pp
->noecpregs
= FALSE
;
5813 pp
->noecpregs
= TRUE
;
5822 x86_unmap_regs(struct ecppunit
*pp
)
5825 ddi_regs_map_free(&pp
->i_handle
);
5828 ddi_regs_map_free(&pp
->f_handle
);
5834 m1553_read_config_reg(struct ecppunit
*pp
, uint8_t reg_num
)
5838 dma8237_write(pp
, 0x3F0, reg_num
);
5839 retval
= dma8237_read(pp
, 0x3F1);
5845 m1553_write_config_reg(struct ecppunit
*pp
, uint8_t reg_num
, uint8_t val
)
5847 dma8237_write(pp
, 0x3F0, reg_num
);
5848 dma8237_write(pp
, 0x3F1, val
);
5852 m1553_config_chip(struct ecppunit
*pp
)
5856 /* Unlock configuration regs with "key sequence" */
5857 dma8237_write(pp
, 0x3F0, 0x51);
5858 dma8237_write(pp
, 0x3F0, 0x23);
5860 m1553_write_config_reg(pp
, PnP_CONFIG_DEV_NO
, 0x3);
5861 conreg
= m1553_read_config_reg(pp
, PnP_CONFIG_DEV_NO
);
5862 ecpp_error(pp
->dip
, "M1553:conreg7(logical dev)=%x\n", conreg
);
5864 conreg
= m1553_read_config_reg(pp
, PnP_CONFIG_ACTIVATE
);
5865 ecpp_error(pp
->dip
, "M1553:conreg30(Active)=%x\n", conreg
);
5867 conreg
= m1553_read_config_reg(pp
, PnP_CONFIG_BASE_ADDR_MSB
);
5868 ecpp_error(pp
->dip
, "M1553:conreg60(addrHi)=%x\n", conreg
);
5869 conreg
= m1553_read_config_reg(pp
, PnP_CONFIG_BASE_ADDR_LSB
);
5870 ecpp_error(pp
->dip
, "M1553:conreg61(addrLo)=%x\n", conreg
);
5872 conreg
= m1553_read_config_reg(pp
, PnP_CONFIG_INTR_SEL
);
5873 ecpp_error(pp
->dip
, "M1553:conreg70(IRQL)=%x\n", conreg
);
5875 conreg
= m1553_read_config_reg(pp
, PnP_CONFIG_DMA0_CHAN
);
5876 ecpp_error(pp
->dip
, "M1553:conreg74(DMA0 Chan)=%x\n", conreg
);
5878 /* set FIFO threshold 1 and ECP mode, preserve bit 7 (IRQ polarity) */
5879 conreg
= m1553_read_config_reg(pp
, PnP_CONFIG_PP_CONFIG0
);
5880 conreg
= (conreg
& ~0x7F) | 0x0A;
5881 m1553_write_config_reg(pp
, PnP_CONFIG_PP_CONFIG0
, conreg
);
5882 conreg
= m1553_read_config_reg(pp
, PnP_CONFIG_PP_CONFIG0
);
5883 ecpp_error(pp
->dip
, "M1553:conregFO(pport conf)=%x\n", conreg
);
5885 m1553_write_config_reg(pp
, PnP_CONFIG_PP_CONFIG1
, 0x04);
5886 conreg
= m1553_read_config_reg(pp
, PnP_CONFIG_PP_CONFIG1
);
5887 ecpp_error(pp
->dip
, "M1553:conregF1(outconf)=%x\n", conreg
);
5889 /* lock configuration regs with key */
5890 dma8237_write(pp
, 0x3F0, 0xBB);
5892 /* Set ECR, DCR in known state */
5893 ECR_WRITE(pp
, ECR_mode_001
| ECPP_INTR_MASK
| ECPP_INTR_SRV
);
5894 DCR_WRITE(pp
, ECPP_SLCTIN
| ECPP_nINIT
);
5896 ecpp_error(pp
->dip
, "m1553_config_chip: ecr=%x, dsr=%x, dcr=%x\n",
5897 ECR_READ(pp
), DSR_READ(pp
), DCR_READ(pp
));
5904 x86_config_chip(struct ecppunit
*pp
)
5906 if (ecr_write(pp
, ECR_mode_001
|
5907 ECPP_INTR_MASK
| ECPP_INTR_SRV
) == FAILURE
) {
5908 ecpp_error(pp
->dip
, "config chip: failed w/ecr\n");
5909 pp
->noecpregs
= TRUE
;
5912 pp
->fast_compat
= FALSE
;
5913 DCR_WRITE(pp
, ECPP_SLCTIN
| ECPP_nINIT
);
5914 ecpp_error(pp
->dip
, "x86_config_chip: ecr=%x, dsr=%x, dcr=%x\n",
5915 ECR_READ(pp
), DSR_READ(pp
), DCR_READ(pp
));
5921 * dma8237_dma_start() programs the selected 8 bit channel
5922 * of DMAC1 with the dma cookie. pp->dma_cookie must
5923 * be set before this routine is called.
5926 dma8237_dma_start(struct ecppunit
*pp
)
5930 chn
= pp
->uh
.m1553
.chn
;
5932 ASSERT(chn
<= DMAE_CH3
&&
5933 pp
->dma_cookie
.dmac_size
!= 0 &&
5934 pp
->dma_cookie
.dmac_address
!= (uintptr_t)NULL
);
5936 /* At this point Southbridge has not yet asserted DREQ */
5938 /* set mode to read-from-memory. */
5939 dma8237_write(pp
, DMAC2_MODE
, DMAMODE_CASC
);
5940 if (pp
->dma_dir
== DDI_DMA_READ
) {
5941 dma8237_write(pp
, DMAC1_MODE
, DMAMODE_SINGLE
|
5942 DMAMODE_READ
| chn
);
5944 dma8237_write(pp
, DMAC1_MODE
, DMAMODE_SINGLE
|
5945 DMAMODE_WRITE
| chn
);
5948 dma8237_write_addr(pp
, pp
->dma_cookie
.dmac_address
);
5949 dma8237_write_count(pp
, pp
->dma_cookie
.dmac_size
- 1);
5952 * M1553 chip does not permit to access DMA register banks
5953 * while DMA is in flight. As a result, ecpp and floppy drivers
5954 * can potentially corrupt each other's DMA. The interlocking mechanism
5955 * is provided by a parent nexus driver (isadma), which is enabled
5956 * indirectly through a DMAC1_ALLMASK register access:
5958 * writing a non-zero value to this register enters a lock,
5959 * writing zero releases the lock.
5961 * DMA transfer must only occur after entering a lock.
5962 * If the lock is already owned by other driver, we will block.
5964 * The following operation unmasks our channel and masks all others
5966 dma8237_write(pp
, DMAC1_ALLMASK
, ~(1 << chn
));
5967 pp
->uh
.m1553
.isadma_entered
= 1;
5973 dma8237_dma_stop(struct ecppunit
*pp
, size_t *countp
)
5978 ecr
= (ECR_READ(pp
) & 0xe0) | ECPP_INTR_MASK
| ECPP_INTR_SRV
;
5979 (void) ecr_write(pp
, ecr
);
5981 if (pp
->uh
.m1553
.isadma_entered
) {
5982 /* reset the channel mask so we can issue PIO's to our device */
5983 dma8237_write(pp
, DMAC1_ALLMASK
, 0);
5984 pp
->uh
.m1553
.isadma_entered
= 0;
5988 /* read DMA count if requested */
5990 *countp
= dma8237_getcnt(pp
);
5991 if (pp
->dma_dir
== DDI_DMA_READ
&& *countp
> 0) {
5992 (*countp
)++; /* need correction for reverse xfers */
5999 x86_dma_start(struct ecppunit
*pp
)
6002 struct ddi_dmae_req dmaereq
;
6004 chn
= pp
->uh
.x86
.chn
;
6005 ASSERT(chn
<= DMAE_CH3
&&
6006 pp
->dma_cookie
.dmac_size
!= 0 &&
6007 pp
->dma_cookie
.dmac_address
!= (uintptr_t)NULL
);
6008 bzero(&dmaereq
, sizeof (struct ddi_dmae_req
));
6009 dmaereq
.der_command
=
6010 (pp
->dma_dir
& DDI_DMA_READ
) ? DMAE_CMD_READ
: DMAE_CMD_WRITE
;
6011 if (ddi_dmae_prog(pp
->dip
, &dmaereq
, &pp
->dma_cookie
, chn
)
6013 ecpp_error(pp
->dip
, "prog failed !!!\n");
6014 ecpp_error(pp
->dip
, "dma_started..\n");
6019 x86_dma_stop(struct ecppunit
*pp
, size_t *countp
)
6024 if (pp
->uh
.x86
.chn
== 0xff)
6026 ecr
= (ECR_READ(pp
) & 0xe0) | ECPP_INTR_MASK
| ECPP_INTR_SRV
;
6027 (void) ecr_write(pp
, ecr
);
6028 ecpp_error(pp
->dip
, "dma_stop\n");
6030 /* read DMA count if requested */
6032 *countp
= x86_getcnt(pp
);
6034 ecpp_error(pp
->dip
, "dma_stoped..\n");
6039 /* channel must be masked */
6041 dma8237_write_addr(struct ecppunit
*pp
, uint32_t addr
)
6043 uint8_t c_addr
, c_lpage
;
6044 uint16_t c_hpage
, *p
;
6046 switch (pp
->uh
.m1553
.chn
) {
6049 c_lpage
= DMA_0PAGE
;
6055 c_lpage
= DMA_1PAGE
;
6061 c_lpage
= DMA_2PAGE
;
6067 c_lpage
= DMA_3PAGE
;
6075 p
= (uint16_t *)&pp
->uh
.m1553
.isa_space
->isa_reg
[c_addr
];
6076 ddi_put16(pp
->uh
.m1553
.d_handle
, p
, addr
& 0xFFFF);
6078 dma8237_write(pp
, c_lpage
, (addr
& 0xFF0000) >> 16);
6079 dma8237_write(pp
, c_hpage
, (addr
& 0xFF000000) >> 24);
6084 * This function may be useful during debugging,
6085 * so we leave it in, but do not include in the binary
6087 #ifdef INCLUDE_DMA8237_READ_ADDR
6089 dma8237_read_addr(struct ecppunit
*pp
)
6091 uint8_t rval3
, rval4
;
6094 uint8_t c_addr
, c_lpage
;
6095 uint16_t c_hpage
, *p
;
6097 switch (pp
->uh
.m1553
.chn
) {
6100 c_lpage
= DMA_0PAGE
;
6106 c_lpage
= DMA_1PAGE
;
6112 c_lpage
= DMA_2PAGE
;
6118 c_lpage
= DMA_3PAGE
;
6126 p
= (uint16_t *)&pp
->uh
.m1553
.isa_space
->isa_reg
[c_addr
];
6127 rval16
= ddi_get16(pp
->uh
.m1553
.d_handle
, p
);
6129 rval3
= dma8237_read(pp
, c_lpage
);
6130 rval4
= dma8237_read(pp
, c_hpage
);
6132 rval
= rval16
| (rval3
<< 16) | (rval4
<<24);
6139 dma8237_write_count(struct ecppunit
*pp
, uint32_t count
)
6144 switch (pp
->uh
.m1553
.chn
) {
6165 p
= (uint16_t *)&pp
->uh
.m1553
.isa_space
->isa_reg
[c_wcnt
];
6166 ddi_put16(pp
->uh
.m1553
.d_handle
, p
, count
& 0xFFFF);
6171 dma8237_read_count(struct ecppunit
*pp
)
6176 switch (pp
->uh
.m1553
.chn
) {
6197 p
= (uint16_t *)&pp
->uh
.m1553
.isa_space
->isa_reg
[c_wcnt
];
6198 return (ddi_get16(pp
->uh
.m1553
.d_handle
, p
));
6203 dma8237_write(struct ecppunit
*pp
, int reg_num
, uint8_t val
)
6205 ddi_put8(pp
->uh
.m1553
.d_handle
,
6206 &pp
->uh
.m1553
.isa_space
->isa_reg
[reg_num
], val
);
6210 dma8237_read(struct ecppunit
*pp
, int reg_num
)
6212 return (ddi_get8(pp
->uh
.m1553
.d_handle
,
6213 &pp
->uh
.m1553
.isa_space
->isa_reg
[reg_num
]));
6217 dma8237_getcnt(struct ecppunit
*pp
)
6221 if ((cnt
= dma8237_read_count(pp
)) == 0xffff)
6231 * Kstat support routines
6235 ecpp_kstat_init(struct ecppunit
*pp
)
6237 struct ecppkstat
*ekp
;
6241 * Allocate, initialize and install interrupt counter kstat
6243 (void) sprintf(buf
, "ecppc%d", pp
->instance
);
6244 pp
->intrstats
= kstat_create("ecpp", pp
->instance
, buf
, "controller",
6245 KSTAT_TYPE_INTR
, 1, KSTAT_FLAG_PERSISTENT
);
6246 if (pp
->intrstats
== NULL
) {
6247 ecpp_error(pp
->dip
, "ecpp_kstat_init:1: kstat_create failed");
6249 pp
->intrstats
->ks_update
= ecpp_kstatintr_update
;
6250 pp
->intrstats
->ks_private
= (void *) pp
;
6251 kstat_install(pp
->intrstats
);
6255 * Allocate, initialize and install misc stats kstat
6257 pp
->ksp
= kstat_create("ecpp", pp
->instance
, NULL
, "misc",
6259 sizeof (struct ecppkstat
) / sizeof (kstat_named_t
),
6260 KSTAT_FLAG_PERSISTENT
);
6261 if (pp
->ksp
== NULL
) {
6262 ecpp_error(pp
->dip
, "ecpp_kstat_init:2: kstat_create failed");
6266 ekp
= (struct ecppkstat
*)pp
->ksp
->ks_data
;
6268 #define EK_NAMED_INIT(name) \
6269 kstat_named_init(&ekp->ek_##name, #name, KSTAT_DATA_UINT32)
6271 EK_NAMED_INIT(ctx_obytes
);
6272 EK_NAMED_INIT(ctxpio_obytes
);
6273 EK_NAMED_INIT(nib_ibytes
);
6274 EK_NAMED_INIT(ecp_obytes
);
6275 EK_NAMED_INIT(ecp_ibytes
);
6276 EK_NAMED_INIT(epp_obytes
);
6277 EK_NAMED_INIT(epp_ibytes
);
6278 EK_NAMED_INIT(diag_obytes
);
6279 EK_NAMED_INIT(to_ctx
);
6280 EK_NAMED_INIT(to_nib
);
6281 EK_NAMED_INIT(to_ecp
);
6282 EK_NAMED_INIT(to_epp
);
6283 EK_NAMED_INIT(to_diag
);
6284 EK_NAMED_INIT(xfer_tout
);
6285 EK_NAMED_INIT(ctx_cf
);
6286 EK_NAMED_INIT(joblen
);
6287 EK_NAMED_INIT(isr_reattempt_high
);
6288 EK_NAMED_INIT(mode
);
6289 EK_NAMED_INIT(phase
);
6290 EK_NAMED_INIT(backchan
);
6291 EK_NAMED_INIT(iomode
);
6292 EK_NAMED_INIT(state
);
6294 pp
->ksp
->ks_update
= ecpp_kstat_update
;
6295 pp
->ksp
->ks_private
= (void *) pp
;
6296 kstat_install(pp
->ksp
);
6300 ecpp_kstat_update(kstat_t
*ksp
, int rw
)
6302 struct ecppunit
*pp
;
6303 struct ecppkstat
*ekp
;
6306 * For the time being there is no point
6307 * in supporting writable kstats
6309 if (rw
== KSTAT_WRITE
) {
6313 pp
= (struct ecppunit
*)ksp
->ks_private
;
6314 ekp
= (struct ecppkstat
*)ksp
->ks_data
;
6316 mutex_enter(&pp
->umutex
);
6318 ekp
->ek_ctx_obytes
.value
.ui32
= pp
->obytes
[ECPP_CENTRONICS
] +
6319 pp
->obytes
[ECPP_COMPAT_MODE
];
6320 ekp
->ek_ctxpio_obytes
.value
.ui32
= pp
->ctxpio_obytes
;
6321 ekp
->ek_nib_ibytes
.value
.ui32
= pp
->ibytes
[ECPP_NIBBLE_MODE
];
6322 ekp
->ek_ecp_obytes
.value
.ui32
= pp
->obytes
[ECPP_ECP_MODE
];
6323 ekp
->ek_ecp_ibytes
.value
.ui32
= pp
->ibytes
[ECPP_ECP_MODE
];
6324 ekp
->ek_epp_obytes
.value
.ui32
= pp
->obytes
[ECPP_EPP_MODE
];
6325 ekp
->ek_epp_ibytes
.value
.ui32
= pp
->ibytes
[ECPP_EPP_MODE
];
6326 ekp
->ek_diag_obytes
.value
.ui32
= pp
->obytes
[ECPP_DIAG_MODE
];
6327 ekp
->ek_to_ctx
.value
.ui32
= pp
->to_mode
[ECPP_CENTRONICS
] +
6328 pp
->to_mode
[ECPP_COMPAT_MODE
];
6329 ekp
->ek_to_nib
.value
.ui32
= pp
->to_mode
[ECPP_NIBBLE_MODE
];
6330 ekp
->ek_to_ecp
.value
.ui32
= pp
->to_mode
[ECPP_ECP_MODE
];
6331 ekp
->ek_to_epp
.value
.ui32
= pp
->to_mode
[ECPP_EPP_MODE
];
6332 ekp
->ek_to_diag
.value
.ui32
= pp
->to_mode
[ECPP_DIAG_MODE
];
6333 ekp
->ek_xfer_tout
.value
.ui32
= pp
->xfer_tout
;
6334 ekp
->ek_ctx_cf
.value
.ui32
= pp
->ctx_cf
;
6335 ekp
->ek_joblen
.value
.ui32
= pp
->joblen
;
6336 ekp
->ek_isr_reattempt_high
.value
.ui32
= pp
->isr_reattempt_high
;
6337 ekp
->ek_mode
.value
.ui32
= pp
->current_mode
;
6338 ekp
->ek_phase
.value
.ui32
= pp
->current_phase
;
6339 ekp
->ek_backchan
.value
.ui32
= pp
->backchannel
;
6340 ekp
->ek_iomode
.value
.ui32
= pp
->io_mode
;
6341 ekp
->ek_state
.value
.ui32
= pp
->e_busy
;
6343 mutex_exit(&pp
->umutex
);
6349 ecpp_kstatintr_update(kstat_t
*ksp
, int rw
)
6351 struct ecppunit
*pp
;
6354 * For the time being there is no point
6355 * in supporting writable kstats
6357 if (rw
== KSTAT_WRITE
) {
6361 pp
= (struct ecppunit
*)ksp
->ks_private
;
6363 mutex_enter(&pp
->umutex
);
6365 KSTAT_INTR_PTR(ksp
)->intrs
[KSTAT_INTR_HARD
] = pp
->intr_hard
;
6366 KSTAT_INTR_PTR(ksp
)->intrs
[KSTAT_INTR_SPURIOUS
] = pp
->intr_spurious
;
6367 KSTAT_INTR_PTR(ksp
)->intrs
[KSTAT_INTR_SOFT
] = pp
->intr_soft
;
6369 mutex_exit(&pp
->umutex
);