Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / uts / common / io / 1394 / adapters / hci1394_ohci.c
blob25a1144b90e61072a5788b270ef8c6a76f9e3fcd
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright (c) 2016 by Delphix. All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * hci1394_ohci.c
31 * Provides access routines to the OpenHCI HW.
34 #include <sys/conf.h>
35 #include <sys/ddi.h>
36 #include <sys/modctl.h>
37 #include <sys/sunddi.h>
38 #include <sys/types.h>
39 #include <sys/mkdev.h>
40 #include <sys/kmem.h>
41 #include <sys/pci.h>
43 #include <sys/1394/adapters/hci1394.h>
44 #include <sys/1394/adapters/hci1394_extern.h>
48 * Data swap macros used to swap config rom data that is going to be placed
49 * in OpenHCI registers. The config rom is treated like a byte stream. When
50 * the services layer calls into us to update the config rom, they pass us a
51 * byte stream of data. This works well except for the the fact that the
52 * hardware uses its internal registers for the first 5 quadlets. We have to
53 * copy the cfgrom header and bus options into their corresponding OpenHCI
54 * registers. On an x86 machine, this means we have to byte swap them first.
56 #ifdef _LITTLE_ENDIAN
57 #define OHCI_SWAP32(DATA) (ddi_swap32(DATA))
58 #else
59 #define OHCI_SWAP32(DATA) (DATA)
60 #endif
63 static int hci1394_ohci_selfid_init(hci1394_ohci_handle_t ohci_hdl);
64 static int hci1394_ohci_cfgrom_init(hci1394_ohci_handle_t ohci_hdl);
65 static int hci1394_ohci_chip_init(hci1394_ohci_handle_t ohci_hdl);
66 static int hci1394_ohci_phy_resume(hci1394_ohci_handle_t ohci_hdl);
67 static int hci1394_ohci_1394a_init(hci1394_ohci_handle_t ohci_hdl);
68 static int hci1394_ohci_1394a_resume(hci1394_ohci_handle_t ohci_hdl);
69 static int hci1394_ohci_phy_read_no_lock(hci1394_ohci_handle_t ohci_hdl,
70 uint_t address, uint_t *data);
71 static int hci1394_ohci_phy_write_no_lock(hci1394_ohci_handle_t ohci_hdl,
72 uint_t address, uint_t data);
76 * hci1394_ohci_init()
77 * Initialize the OpenHCI hardware.
79 int
80 hci1394_ohci_init(hci1394_state_t *soft_state, hci1394_drvinfo_t *drvinfo,
81 hci1394_ohci_handle_t *ohci_hdl)
83 int status;
84 uint32_t version;
85 hci1394_ohci_t *ohci;
86 #if defined(__x86)
87 uint16_t cmdreg;
88 #endif
91 ASSERT(ohci_hdl != NULL);
93 /* alloc the space for ohci */
94 ohci = kmem_alloc(sizeof (hci1394_ohci_t), KM_SLEEP);
95 *ohci_hdl = ohci;
98 * Start with the cycle timer rollover interrupt disabled. When it is
99 * enabled, we will get an interrupt every 64 seconds, even if we have
100 * nothing plugged into the bus. This interrupt is used to keep track
101 * of the bus time. We will enable the interrupt when the bus manager
102 * writes to the bus_time CSR register (Currently there are not known
103 * implementations that write to the bus_time register)
105 ohci->ohci_bustime_enabled = B_FALSE;
106 ohci->ohci_bustime_count = 0;
108 ohci->ohci_set_root_holdoff = B_FALSE;
109 ohci->ohci_set_gap_count = B_FALSE;
110 ohci->ohci_gap_count = 0;
112 mutex_init(&ohci->ohci_mutex, NULL, MUTEX_DRIVER,
113 drvinfo->di_iblock_cookie);
115 /* Map OpenHCI Registers */
116 status = ddi_regs_map_setup(drvinfo->di_dip, OHCI_REG_SET,
117 (caddr_t *)&ohci->ohci_regs, 0, 0, &drvinfo->di_reg_attr,
118 &ohci->ohci_reg_handle);
119 if (status != DDI_SUCCESS) {
120 mutex_destroy(&ohci->ohci_mutex);
121 kmem_free(ohci, sizeof (hci1394_ohci_t));
122 *ohci_hdl = NULL;
123 return (DDI_FAILURE);
126 ohci->soft_state = soft_state;
127 ohci->ohci_drvinfo = drvinfo;
130 * make sure PCI Master and PCI Memory Access are enabled on x86
131 * platforms. This may not be the case if plug and play OS is
132 * set in the BIOS
134 #if defined(__x86)
135 cmdreg = pci_config_get16(soft_state->pci_config, PCI_CONF_COMM);
136 if ((cmdreg & (PCI_COMM_MAE | PCI_COMM_ME)) != (PCI_COMM_MAE |
137 PCI_COMM_ME)) {
138 cmdreg |= PCI_COMM_MAE | PCI_COMM_ME;
139 pci_config_put16(soft_state->pci_config, PCI_CONF_COMM, cmdreg);
141 #endif
144 * Initialize the openHCI chip. This is broken out because we need to
145 * do this when resuming too.
147 status = hci1394_ohci_chip_init(ohci);
148 if (status != DDI_SUCCESS) {
149 ddi_regs_map_free(&ohci->ohci_reg_handle);
150 mutex_destroy(&ohci->ohci_mutex);
151 kmem_free(ohci, sizeof (hci1394_ohci_t));
152 *ohci_hdl = NULL;
153 return (DDI_FAILURE);
156 /* Init the 1394 PHY */
157 status = hci1394_ohci_phy_init(ohci);
158 if (status != DDI_SUCCESS) {
159 (void) hci1394_ohci_soft_reset(ohci);
160 ddi_regs_map_free(&ohci->ohci_reg_handle);
161 mutex_destroy(&ohci->ohci_mutex);
162 kmem_free(ohci, sizeof (hci1394_ohci_t));
163 *ohci_hdl = NULL;
164 return (DDI_FAILURE);
167 /* Init 1394a features if present */
168 if (ohci->ohci_phy == H1394_PHY_1394A) {
169 status = hci1394_ohci_1394a_init(ohci);
170 if (status != DDI_SUCCESS) {
171 (void) hci1394_ohci_soft_reset(ohci);
172 ddi_regs_map_free(&ohci->ohci_reg_handle);
173 mutex_destroy(&ohci->ohci_mutex);
174 kmem_free(ohci, sizeof (hci1394_ohci_t));
175 *ohci_hdl = NULL;
176 return (DDI_FAILURE);
180 /* save away guid, phy type, and vendor info */
181 soft_state->halinfo.guid = hci1394_ohci_guid(ohci);
182 soft_state->halinfo.phy = ohci->ohci_phy;
183 soft_state->vendor_info.ohci_vendor_id =
184 ddi_get32(ohci->ohci_reg_handle, &ohci->ohci_regs->vendor_id);
185 version = ddi_get32(ohci->ohci_reg_handle, &ohci->ohci_regs->version);
186 soft_state->vendor_info.ohci_version = version;
188 /* We do not support version < 1.0 */
189 if (OHCI_VERSION(version) == 0) {
190 cmn_err(CE_NOTE,
191 "hci1394(%d): OpenHCI version %x.%x is not supported",
192 drvinfo->di_instance, OHCI_VERSION(version),
193 OHCI_REVISION(version));
194 (void) hci1394_ohci_soft_reset(ohci);
195 ddi_regs_map_free(&ohci->ohci_reg_handle);
196 mutex_destroy(&ohci->ohci_mutex);
197 kmem_free(ohci, sizeof (hci1394_ohci_t));
198 *ohci_hdl = NULL;
199 return (DDI_FAILURE);
202 /* Initialize the selfid buffer */
203 status = hci1394_ohci_selfid_init(ohci);
204 if (status != DDI_SUCCESS) {
205 (void) hci1394_ohci_soft_reset(ohci);
206 ddi_regs_map_free(&ohci->ohci_reg_handle);
207 mutex_destroy(&ohci->ohci_mutex);
208 kmem_free(ohci, sizeof (hci1394_ohci_t));
209 *ohci_hdl = NULL;
210 return (DDI_FAILURE);
213 /* Initialize the config rom buffer */
214 status = hci1394_ohci_cfgrom_init(ohci);
215 if (status != DDI_SUCCESS) {
216 (void) hci1394_ohci_soft_reset(ohci);
217 hci1394_buf_free(&ohci->ohci_selfid_handle);
218 ddi_regs_map_free(&ohci->ohci_reg_handle);
219 mutex_destroy(&ohci->ohci_mutex);
220 kmem_free(ohci, sizeof (hci1394_ohci_t));
221 *ohci_hdl = NULL;
222 return (DDI_FAILURE);
225 return (DDI_SUCCESS);
230 * hci1394_ohci_fini()
231 * Cleanup after OpenHCI init. This should be called during detach.
233 void
234 hci1394_ohci_fini(hci1394_ohci_handle_t *ohci_hdl)
236 hci1394_ohci_t *ohci;
239 ASSERT(ohci_hdl != NULL);
241 ohci = *ohci_hdl;
243 /* reset chip */
244 (void) hci1394_ohci_soft_reset(ohci);
246 /* Free config rom space */
247 hci1394_buf_free(&ohci->ohci_cfgrom_handle);
249 /* Free selfid buffer space */
250 hci1394_buf_free(&ohci->ohci_selfid_handle);
252 /* Free up the OpenHCI registers */
253 ddi_regs_map_free(&ohci->ohci_reg_handle);
255 mutex_destroy(&ohci->ohci_mutex);
257 /* Free the OpenHCI state space */
258 kmem_free(ohci, sizeof (hci1394_ohci_t));
259 *ohci_hdl = NULL;
264 * hci1394_ohci_chip_init()
265 * Initialize the OpenHCI registers. This contains the bulk of the initial
266 * register setup.
268 static int
269 hci1394_ohci_chip_init(hci1394_ohci_handle_t ohci_hdl)
271 int status;
274 ASSERT(ohci_hdl != NULL);
276 /* Reset 1394 OHCI HW */
277 status = hci1394_ohci_soft_reset(ohci_hdl);
278 if (status != DDI_SUCCESS) {
279 return (DDI_FAILURE);
283 * Setup Host Control Register. The software reset does not put all
284 * registers in a known state. The Host Control Register is one of these
285 * registers. First make sure noByteSwapData and postedWriteEnable and
286 * are cleared.
288 ddi_put32(ohci_hdl->ohci_reg_handle,
289 &ohci_hdl->ohci_regs->hc_ctrl_clr, OHCI_HC_NO_BSWAP |
290 OHCI_HC_POSTWR_ENBL);
293 * the determination if we should swap data is made during the PCI
294 * initialization.
296 if (ohci_hdl->soft_state->swap_data == B_FALSE) {
298 * most hba's don't swap data. It will be swapped in the
299 * global swap for SPARC. Enable Link Power(LPS). Enable
300 * Posted Writes
302 ddi_put32(ohci_hdl->ohci_reg_handle,
303 &ohci_hdl->ohci_regs->hc_ctrl_set, OHCI_HC_NO_BSWAP |
304 OHCI_HC_LPS | OHCI_HC_POSTWR_ENBL);
305 } else {
307 * Swap Data. Enable Link Power(LPS). Enable Posted Writes
309 ddi_put32(ohci_hdl->ohci_reg_handle,
310 &ohci_hdl->ohci_regs->hc_ctrl_set, OHCI_HC_LPS |
311 OHCI_HC_POSTWR_ENBL);
315 * Wait for PHY to come up. There does not seem to be standard time for
316 * how long wait for the PHY to come up. The problem is that the PHY
317 * provides a clock to the link layer and if that is not stable, we
318 * could get a PCI timeout error when reading/writing a phy register
319 * (and maybe an OpenHCI register?) This used to be set to 10mS which
320 * works for just about every adapter we tested on. We got a new TI
321 * adapter which would crash the system once in a while if nothing
322 * (1394 device) was pluged into the adapter. Changing this delay to
323 * 50mS made that problem go away. This value is set via a patchable
324 * variable located in hci1394_extern.c
326 delay(drv_usectohz(hci1394_phy_stabilization_delay_uS));
328 /* Clear Isochrounous receive multi-chan mode registers */
329 ddi_put32(ohci_hdl->ohci_reg_handle,
330 &ohci_hdl->ohci_regs->ir_multi_maskhi_clr, 0xFFFFFFFF);
331 ddi_put32(ohci_hdl->ohci_reg_handle,
332 &ohci_hdl->ohci_regs->ir_multi_masklo_clr, 0xFFFFFFFF);
335 * Setup async retry on busy or ack_data_error
336 * secondlimit = 0 <= bits 31-29
337 * cycleLimit = 0 <= bits 28-16
338 * maxPhysRespRetries = 0 <= bits 11-8
339 * maxARRespRetries = 0 <= bits 7-4
340 * maxATReqRetries = 2 <= bits 3-0
342 ddi_put32(ohci_hdl->ohci_reg_handle,
343 &ohci_hdl->ohci_regs->at_retries, 0x00000002);
346 * Setup Link Control
347 * Enable cycleMaster, cycleTimerEnable, and rcvPhyPkt.
349 ddi_put32(ohci_hdl->ohci_reg_handle,
350 &ohci_hdl->ohci_regs->link_ctrl_clr, 0xFFFFFFFF);
351 ddi_put32(ohci_hdl->ohci_reg_handle,
352 &ohci_hdl->ohci_regs->link_ctrl_set, OHCI_LC_CYC_MAST |
353 OHCI_LC_CTIME_ENBL | OHCI_LC_RCV_PHY);
356 * Set the Physical address map boundary to 0x0000FFFFFFFF. The
357 * phys_upper_bound is the upper 32-bits of the 48-bit 1394 address. The
358 * lower 16 bits are assumed to be 0xFFFF.
360 ddi_put32(ohci_hdl->ohci_reg_handle,
361 &ohci_hdl->ohci_regs->phys_upper_bound, (uint32_t)0x0000FFFF);
364 * Enable all async requests.
365 * The asyncReqResourceAll bit (0x80000000) does not get cleared during
366 * a bus reset. If this code is changed to selectively allow nodes to
367 * perform ARREQ's, the ARREQ filter bits will need to be updated after
368 * every bus reset.
370 ddi_put32(ohci_hdl->ohci_reg_handle,
371 &ohci_hdl->ohci_regs->ar_req_filterhi_set, (uint32_t)0x80000000);
374 * clear isochronous interrupt event and mask registers clearing the
375 * mask registers disable all isoc tx & rx ints
377 ddi_put32(ohci_hdl->ohci_reg_handle,
378 &ohci_hdl->ohci_regs->it_intr_event_clr, (uint32_t)0xFFFFFFFF);
379 ddi_put32(ohci_hdl->ohci_reg_handle,
380 &ohci_hdl->ohci_regs->it_intr_mask_clr, (uint32_t)0xFFFFFFFF);
381 ddi_put32(ohci_hdl->ohci_reg_handle,
382 &ohci_hdl->ohci_regs->ir_intr_event_clr, (uint32_t)0xFFFFFFFF);
383 ddi_put32(ohci_hdl->ohci_reg_handle,
384 &ohci_hdl->ohci_regs->ir_intr_mask_clr, (uint32_t)0xFFFFFFFF);
386 /* Clear interrupt event/mask register */
387 ddi_put32(ohci_hdl->ohci_reg_handle,
388 &ohci_hdl->ohci_regs->intr_event_clr, (uint32_t)0xFFFFFFFF);
389 ddi_put32(ohci_hdl->ohci_reg_handle,
390 &ohci_hdl->ohci_regs->intr_mask_clr, (uint32_t)0xFFFFFFFF);
392 return (DDI_SUCCESS);
397 * hci1394_ohci_soft_reset()
398 * Reset OpenHCI HW.
401 hci1394_ohci_soft_reset(hci1394_ohci_handle_t ohci_hdl)
403 uint32_t resetStatus;
406 ASSERT(ohci_hdl != NULL);
408 /* Reset 1394 HW - Reset is bit 16 in HCControl */
409 ddi_put32(ohci_hdl->ohci_reg_handle,
410 &ohci_hdl->ohci_regs->hc_ctrl_set, OHCI_HC_SOFT_RESET);
412 /* Wait for reset to complete */
413 drv_usecwait(OHCI_CHIP_RESET_TIME_IN_uSEC);
415 /* Verify reset is complete */
416 resetStatus = ddi_get32(ohci_hdl->ohci_reg_handle,
417 &ohci_hdl->ohci_regs->hc_ctrl_set);
418 resetStatus = resetStatus & OHCI_HC_SOFT_RESET;
419 if (resetStatus != 0) {
420 return (DDI_FAILURE);
423 return (DDI_SUCCESS);
428 * hci1394_ohci_reg_read()
429 * Read OpenHCI register. This is called from the test ioctl interface
430 * through devctl.
432 void
433 hci1394_ohci_reg_read(hci1394_ohci_handle_t ohci_hdl,
434 uint_t offset, uint32_t *data)
436 uint32_t *addr;
439 ASSERT(ohci_hdl != NULL);
440 ASSERT(data != NULL);
442 addr = (uint32_t *)((uintptr_t)ohci_hdl->ohci_regs +
443 (uintptr_t)(offset & OHCI_REG_ADDR_MASK));
444 *data = ddi_get32(ohci_hdl->ohci_reg_handle, addr);
449 * hci1394_ohci_reg_write()
450 * Write OpenHCI register. This is called from the test ioctl interface
451 * through devctl.
453 void
454 hci1394_ohci_reg_write(hci1394_ohci_handle_t ohci_hdl,
455 uint_t offset, uint32_t data)
457 uint32_t *addr;
460 ASSERT(ohci_hdl != NULL);
462 addr = (uint32_t *)((uintptr_t)ohci_hdl->ohci_regs +
463 (uintptr_t)(offset & OHCI_REG_ADDR_MASK));
464 ddi_put32(ohci_hdl->ohci_reg_handle, addr, data);
469 * hci1394_ohci_intr_master_enable()
470 * Enable interrupts to be passed on from OpenHCI. This is a global mask.
471 * Individual interrupts still need to be enabled for interrupts to be
472 * generated.
474 void
475 hci1394_ohci_intr_master_enable(hci1394_ohci_handle_t ohci_hdl)
477 ASSERT(ohci_hdl != NULL);
479 ddi_put32(ohci_hdl->ohci_reg_handle,
480 &ohci_hdl->ohci_regs->intr_mask_set, OHCI_INTR_MASTER_INTR_ENBL);
485 * hci1394_ohci_intr_master_disable()
486 * Disable all OpenHCI interrupts from being passed on. This does not affect
487 * the individual interrupt mask settings. When interrupts are enabled
488 * again, the same individual interrupts will still be enabled.
490 void
491 hci1394_ohci_intr_master_disable(hci1394_ohci_handle_t ohci_hdl)
493 ASSERT(ohci_hdl != NULL);
495 ddi_put32(ohci_hdl->ohci_reg_handle,
496 &ohci_hdl->ohci_regs->intr_mask_clr, OHCI_INTR_MASTER_INTR_ENBL);
501 * hci1394_ohci_intr_asserted()
502 * Return which ENABLED interrupts are asserted. If an interrupt is disabled
503 * via its mask bit, it will not be returned from here.
505 * NOTE: we may want to make this a macro at some point.
507 uint32_t
508 hci1394_ohci_intr_asserted(hci1394_ohci_handle_t ohci_hdl)
510 uint32_t interrupts_asserted;
512 ASSERT(ohci_hdl != NULL);
515 * Only look at interrupts which are enabled by reading the
516 * intr_event_clr register.
518 interrupts_asserted = ddi_get32(ohci_hdl->ohci_reg_handle,
519 &ohci_hdl->ohci_regs->intr_event_clr);
521 return (interrupts_asserted);
526 * hci1394_ohci_intr_enable()
527 * Enable an individual interrupt or set of interrupts. This does not affect
528 * the global interrupt mask.
530 void
531 hci1394_ohci_intr_enable(hci1394_ohci_handle_t ohci_hdl,
532 uint32_t interrupt_mask)
534 ASSERT(ohci_hdl != NULL);
536 ddi_put32(ohci_hdl->ohci_reg_handle,
537 &ohci_hdl->ohci_regs->intr_mask_set, interrupt_mask);
542 * hci1394_ohci_intr_disable()
543 * Disable an individual interrupt or set of interrupts. This does not affect
544 * the global interrupt mask.
546 void
547 hci1394_ohci_intr_disable(hci1394_ohci_handle_t ohci_hdl,
548 uint32_t interrupt_mask)
550 ASSERT(ohci_hdl != NULL);
552 ddi_put32(ohci_hdl->ohci_reg_handle,
553 &ohci_hdl->ohci_regs->intr_mask_clr, interrupt_mask);
558 * hci1394_ohci_intr_clear()
559 * Clear a set of interrupts so that they are not asserted anymore.
561 * NOTE: we may want to make this a macro at some point.
563 void
564 hci1394_ohci_intr_clear(hci1394_ohci_handle_t ohci_hdl,
565 uint32_t interrupt_mask)
567 ASSERT(ohci_hdl != NULL);
569 ddi_put32(ohci_hdl->ohci_reg_handle,
570 &ohci_hdl->ohci_regs->intr_event_clr, interrupt_mask);
575 * hci1394_ohci_it_intr_asserted()
576 * Return which ENABLED isoch TX interrupts are asserted. If an interrupt is
577 * disabled via its mask bit, it will not be returned from here.
579 * NOTE: we may want to make this a macro at some point.
581 uint32_t
582 hci1394_ohci_it_intr_asserted(hci1394_ohci_handle_t ohci_hdl)
584 uint32_t interrupts_asserted;
586 ASSERT(ohci_hdl != NULL);
588 /* Only look at interrupts which are enabled */
589 interrupts_asserted = ddi_get32(ohci_hdl->ohci_reg_handle,
590 &ohci_hdl->ohci_regs->it_intr_event_clr);
592 return (interrupts_asserted);
597 * hci1394_ohci_it_intr_enable()
598 * Enable an individual isoch TX interrupt. This does not affect the general
599 * isoch interrupt mask in the OpenHCI Mask register. That is enabled/
600 * disabled via hci1394_ohci_intr_enable/hci1394_ohci_intr_disable.
602 void
603 hci1394_ohci_it_intr_enable(hci1394_ohci_handle_t ohci_hdl,
604 uint32_t interrupt_mask)
606 ASSERT(ohci_hdl != NULL);
608 ddi_put32(ohci_hdl->ohci_reg_handle,
609 &ohci_hdl->ohci_regs->it_intr_mask_set, interrupt_mask);
614 * hci1394_ohci_it_intr_disable()
615 * Disable an individual isoch TX interrupt. This does not affect the general
616 * isoch interrupt mask in the OpenHCI Mask register. That is enabled/
617 * disabled via hci1394_ohci_intr_enable/hci1394_ohci_intr_disable.
619 void
620 hci1394_ohci_it_intr_disable(hci1394_ohci_handle_t ohci_hdl,
621 uint32_t interrupt_mask)
623 ASSERT(ohci_hdl != NULL);
625 ddi_put32(ohci_hdl->ohci_reg_handle,
626 &ohci_hdl->ohci_regs->it_intr_mask_clr, interrupt_mask);
631 * hci1394_ohci_it_intr_clear()
632 * Clear an individual isoch TX interrupt so that it is not asserted anymore.
634 * NOTE: we may want to make this a macro at some point.
636 void
637 hci1394_ohci_it_intr_clear(hci1394_ohci_handle_t ohci_hdl,
638 uint32_t interrupt_mask)
640 ASSERT(ohci_hdl != NULL);
642 ddi_put32(ohci_hdl->ohci_reg_handle,
643 &ohci_hdl->ohci_regs->it_intr_event_clr, interrupt_mask);
648 * hci1394_ohci_it_ctxt_count_get()
649 * Determine the number of supported isochronous transmit contexts.
652 hci1394_ohci_it_ctxt_count_get(hci1394_ohci_handle_t ohci_hdl)
654 uint32_t channel_mask;
655 int count;
657 ASSERT(ohci_hdl != NULL);
660 * hw is required to support contexts 0 to N, where N <= 31
661 * the interrupt mask bits are wired to ground for unsupported
662 * contexts. Write 1's to all it mask bits, then read the mask.
663 * Implemented contexts will read (sequentially) as 1
665 ddi_put32(ohci_hdl->ohci_reg_handle,
666 &ohci_hdl->ohci_regs->it_intr_mask_set, 0xFFFFFFFF);
667 channel_mask = ddi_get32(ohci_hdl->ohci_reg_handle,
668 &ohci_hdl->ohci_regs->it_intr_mask_set);
669 count = 0;
670 while (channel_mask != 0) {
671 channel_mask = channel_mask >> 1;
672 count++;
675 return (count);
680 * hci1394_ohci_it_cmd_ptr_set()
681 * Set the context pointer for a given isoch TX context. This is the IO
682 * address for the HW to fetch the first descriptor. The context should
683 * not be running when this routine is called.
685 void
686 hci1394_ohci_it_cmd_ptr_set(hci1394_ohci_handle_t ohci_hdl,
687 uint_t context_number, uint32_t io_addr)
689 ASSERT(ohci_hdl != NULL);
691 ddi_put32(ohci_hdl->ohci_reg_handle,
692 &ohci_hdl->ohci_regs->it[context_number].cmd_ptrlo,
693 io_addr);
698 * hci1394_ohci_ir_intr_asserted()
699 * Return which ENABLED isoch RX interrupts are asserted. If an interrupt is
700 * disabled via its mask bit, it will not be returned from here.
702 * NOTE: we may want to make this a macro at some point.
704 uint32_t
705 hci1394_ohci_ir_intr_asserted(hci1394_ohci_handle_t ohci_hdl)
707 uint32_t interrupts_asserted;
709 ASSERT(ohci_hdl != NULL);
711 /* Only look at interrupts which are enabled */
712 interrupts_asserted = ddi_get32(ohci_hdl->ohci_reg_handle,
713 &ohci_hdl->ohci_regs->ir_intr_event_clr);
715 return (interrupts_asserted);
720 * hci1394_ohci_ir_intr_enable()
721 * Enable an individual isoch RX interrupt. This does not affect the isoch
722 * interrupt mask in the OpenHCI Mask register. That is enabled/disabled
723 * via hci1394_ohci_intr_enable/hci1394_ohci_intr_disable.
725 void
726 hci1394_ohci_ir_intr_enable(hci1394_ohci_handle_t ohci_hdl,
727 uint32_t interrupt_mask)
729 ASSERT(ohci_hdl != NULL);
731 ddi_put32(ohci_hdl->ohci_reg_handle,
732 &ohci_hdl->ohci_regs->ir_intr_mask_set, interrupt_mask);
737 * hci1394_ohci_ir_intr_disable()
738 * Disable an individual isoch RX interrupt. This does not affect the isoch
739 * interrupt mask in the OpenHCI Mask register. That is enabled/disabled
740 * via hci1394_ohci_intr_enable/hci1394_ohci_intr_disable.
742 void
743 hci1394_ohci_ir_intr_disable(hci1394_ohci_handle_t ohci_hdl,
744 uint32_t interrupt_mask)
746 ASSERT(ohci_hdl != NULL);
748 ddi_put32(ohci_hdl->ohci_reg_handle,
749 &ohci_hdl->ohci_regs->ir_intr_mask_clr, interrupt_mask);
754 * hci1394_ohci_ir_intr_clear()
755 * Clear an individual isoch RX interrupt so that it is not asserted anymore.
757 * NOTE: we may want to make this a macro at some point.
759 void
760 hci1394_ohci_ir_intr_clear(hci1394_ohci_handle_t ohci_hdl,
761 uint32_t interrupt_mask)
763 ASSERT(ohci_hdl != NULL);
765 ddi_put32(ohci_hdl->ohci_reg_handle,
766 &ohci_hdl->ohci_regs->ir_intr_event_clr, interrupt_mask);
771 * hci1394_ohci_ir_ctxt_count_get()
772 * Determine the number of supported isochronous receive contexts.
775 hci1394_ohci_ir_ctxt_count_get(hci1394_ohci_handle_t ohci_hdl)
777 uint32_t channel_mask;
778 int count;
780 ASSERT(ohci_hdl != NULL);
783 * hw is required to support contexts 0 to N, where N <= 31
784 * the interrupt mask bits are wired to ground for unsupported
785 * contexts. Write 1's to all ir mask bits, then read the mask.
786 * Implemented contexts will read (sequentially) as 1
788 ddi_put32(ohci_hdl->ohci_reg_handle,
789 &ohci_hdl->ohci_regs->ir_intr_mask_set, 0xFFFFFFFF);
790 channel_mask = ddi_get32(ohci_hdl->ohci_reg_handle,
791 &ohci_hdl->ohci_regs->ir_intr_mask_set);
792 count = 0;
793 while (channel_mask != 0) {
794 channel_mask = channel_mask >> 1;
795 count++;
798 return (count);
803 * hci1394_ohci_ir_cmd_ptr_set()
804 * Set the context pointer for a given isoch RX context. This is the IO
805 * address for the HW to fetch the first descriptor. The context should
806 * not be running when this routine is called.
808 void
809 hci1394_ohci_ir_cmd_ptr_set(hci1394_ohci_handle_t ohci_hdl,
810 uint_t context_number, uint32_t io_addr)
812 ASSERT(ohci_hdl != NULL);
814 ddi_put32(ohci_hdl->ohci_reg_handle,
815 &ohci_hdl->ohci_regs->ir[context_number].cmd_ptrlo,
816 io_addr);
821 * hci1394_ohci_link_enable()
822 * Enable the 1394 link layer. When the link is enabled, the PHY will pass
823 * up any 1394 bus transactions which would normally come up to the link.
825 void
826 hci1394_ohci_link_enable(hci1394_ohci_handle_t ohci_hdl)
828 ASSERT(ohci_hdl != NULL);
830 ddi_put32(ohci_hdl->ohci_reg_handle,
831 &ohci_hdl->ohci_regs->hc_ctrl_set, OHCI_HC_LINK_ENBL);
836 * hci1394_ohci_link_disable()
837 * Disable the 1394 link layer. When the link is disabled, the PHY will NOT
838 * pass up any 1394 bus transactions which would normally come up to the
839 * link. This "logically" disconnects us from the 1394 bus.
841 void
842 hci1394_ohci_link_disable(hci1394_ohci_handle_t ohci_hdl)
844 ASSERT(ohci_hdl != NULL);
846 ddi_put32(ohci_hdl->ohci_reg_handle,
847 &ohci_hdl->ohci_regs->hc_ctrl_clr, OHCI_HC_LINK_ENBL);
852 * hci1394_ohci_bus_reset()
853 * Reset the 1394 bus. This performs a "long" bus reset and can be called
854 * when the adapter has either a 1394-1995 or 1394A PHY.
857 hci1394_ohci_bus_reset(hci1394_ohci_handle_t ohci_hdl)
859 int status;
860 uint_t reg;
863 ASSERT(ohci_hdl != NULL);
866 * We want to reset the bus. We also handle the root_holdoff and gap
867 * count cacheing explained at the top of this file.
869 reg = OHCI_PHY_IBR;
870 if (ohci_hdl->ohci_set_root_holdoff == B_TRUE) {
871 reg = reg | OHCI_PHY_RHB;
873 if (ohci_hdl->ohci_set_gap_count == B_TRUE) {
874 reg = reg | ohci_hdl->ohci_gap_count;
875 } else {
876 reg = reg | OHCI_PHY_MAX_GAP;
880 * Reset the bus. We intentionally do NOT do a PHY read here. A PHY
881 * read could introduce race conditions and would be more likely to fail
882 * due to a timeout.
884 status = hci1394_ohci_phy_write(ohci_hdl, 0x1, reg);
885 if (status != DDI_SUCCESS) {
886 return (DDI_FAILURE);
889 /* clear the root holdoff and gap count state bits */
890 ohci_hdl->ohci_set_root_holdoff = B_FALSE;
891 ohci_hdl->ohci_set_gap_count = B_FALSE;
893 return (DDI_SUCCESS);
898 * hci1394_ohci_bus_reset_nroot()
899 * Reset the 1394 bus. This performs a "long" bus reset with out a root.
902 hci1394_ohci_bus_reset_nroot(hci1394_ohci_handle_t ohci_hdl)
904 int status;
905 uint_t reg;
907 ASSERT(ohci_hdl != NULL);
910 * We want to reset the bus. We don't care about any holdoff
911 * we are suspending need no root...
913 (void) hci1394_ohci_phy_read(ohci_hdl, 0x1, &reg);
914 reg = reg | OHCI_PHY_IBR;
915 reg = reg & ~OHCI_PHY_RHB;
918 * Reset the bus. We intentionally do NOT do a PHY read here. A PHY
919 * read could introduce race conditions and would be more likely to fail
920 * due to a timeout.
922 status = hci1394_ohci_phy_write(ohci_hdl, 0x1, reg);
923 if (status != DDI_SUCCESS) {
924 return (DDI_FAILURE);
927 return (DDI_SUCCESS);
931 * hci1394_ohci_phy_init()
932 * Setup the PHY. This should be called during attach and performs any PHY
933 * initialization required including figuring out what kind of PHY we have.
936 hci1394_ohci_phy_init(hci1394_ohci_handle_t ohci_hdl)
938 int status;
939 uint_t phy_reg;
942 ASSERT(ohci_hdl != NULL);
945 * if the phy has extended set to 7, the phy is a not a 1394-1995 PHY.
946 * It could be a 1394a phy or beyond. The PHY type can be found in PHY
947 * register page 1 in the compliance_level register.
949 * Since there are not any current standards beyond 1394A, we are going
950 * to consider the PHY to be a 1394A phy if the extended bit is set.
952 * phy registers are byte wide registers and are addressed as 0, 1, 2,
953 * 3, ... Phy register 0 may not be read or written.
955 * Phy register 0x2 (bit 0 MSB, 7 LSB)
956 * Extended - bits 0 - 2
957 * Total Ports - bits 4 - 7
959 status = hci1394_ohci_phy_read(ohci_hdl, 2, &phy_reg);
960 if (status != DDI_SUCCESS) {
961 return (DDI_FAILURE);
964 if ((phy_reg & OHCI_PHY_EXTND_MASK) != OHCI_PHY_EXTND) {
966 * if the extended bit is not set, we have to be a 1394-1995
967 * PHY
969 ohci_hdl->ohci_phy = H1394_PHY_1995;
970 } else {
971 /* Treat all other PHY's as a 1394A PHY */
972 ohci_hdl->ohci_phy = H1394_PHY_1394A;
975 return (DDI_SUCCESS);
980 * hci1394_ohci_phy_resume()
981 * re-initialize the PHY. This routine should be called during a resume after
982 * a successful suspend has been done.
984 /* ARGSUSED */
985 static int
986 hci1394_ohci_phy_resume(hci1394_ohci_handle_t ohci_hdl)
988 ASSERT(ohci_hdl != NULL);
990 return (DDI_SUCCESS);
995 * hci1394_ohci_phy_set()
996 * Perform bitset operation on PHY register.
999 hci1394_ohci_phy_set(hci1394_ohci_handle_t ohci_hdl, uint_t address,
1000 uint_t bits)
1002 int status;
1003 uint_t reg;
1006 ASSERT(ohci_hdl != NULL);
1008 mutex_enter(&ohci_hdl->ohci_mutex);
1010 /* read the PHY register */
1011 status = hci1394_ohci_phy_read_no_lock(ohci_hdl, address, &reg);
1012 if (status != DDI_SUCCESS) {
1013 mutex_exit(&ohci_hdl->ohci_mutex);
1014 return (DDI_FAILURE);
1017 /* Set the bits and write the result back */
1018 reg = reg | bits;
1019 status = hci1394_ohci_phy_write_no_lock(ohci_hdl, address, reg);
1020 if (status != DDI_SUCCESS) {
1021 mutex_exit(&ohci_hdl->ohci_mutex);
1022 return (DDI_FAILURE);
1025 mutex_exit(&ohci_hdl->ohci_mutex);
1027 return (DDI_SUCCESS);
1032 * hci1394_ohci_phy_clr()
1033 * Perform bitclr operation on PHY register.
1036 hci1394_ohci_phy_clr(hci1394_ohci_handle_t ohci_hdl, uint_t address,
1037 uint_t bits)
1039 int status;
1040 uint_t reg;
1043 ASSERT(ohci_hdl != NULL);
1045 mutex_enter(&ohci_hdl->ohci_mutex);
1047 /* read the PHY register */
1048 status = hci1394_ohci_phy_read_no_lock(ohci_hdl, address, &reg);
1049 if (status != DDI_SUCCESS) {
1050 mutex_exit(&ohci_hdl->ohci_mutex);
1051 return (DDI_FAILURE);
1054 /* Set the bits and write the result back */
1055 reg = reg & ~bits;
1056 status = hci1394_ohci_phy_write_no_lock(ohci_hdl, address, reg);
1057 if (status != DDI_SUCCESS) {
1058 mutex_exit(&ohci_hdl->ohci_mutex);
1059 return (DDI_FAILURE);
1062 mutex_exit(&ohci_hdl->ohci_mutex);
1064 return (DDI_SUCCESS);
1069 * hci1394_ohci_phy_read()
1070 * Atomic PHY register read
1073 hci1394_ohci_phy_read(hci1394_ohci_handle_t ohci_hdl, uint_t address,
1074 uint_t *data)
1076 int status;
1078 ASSERT(ohci_hdl != NULL);
1079 mutex_enter(&ohci_hdl->ohci_mutex);
1080 status = hci1394_ohci_phy_read_no_lock(ohci_hdl, address, data);
1081 mutex_exit(&ohci_hdl->ohci_mutex);
1083 return (status);
1088 * hci1394_ohci_phy_write()
1089 * Atomic PHY register write
1092 hci1394_ohci_phy_write(hci1394_ohci_handle_t ohci_hdl, uint_t address,
1093 uint_t data)
1095 int status;
1097 ASSERT(ohci_hdl != NULL);
1098 mutex_enter(&ohci_hdl->ohci_mutex);
1099 status = hci1394_ohci_phy_write_no_lock(ohci_hdl, address, data);
1100 mutex_exit(&ohci_hdl->ohci_mutex);
1102 return (status);
1107 * hci1394_ohci_phy_read_no_lock()
1108 * This routine actually performs the PHY register read. It is seperated
1109 * out from phy_read so set & clr lock can perform an atomic PHY register
1110 * operation. It assumes the OpenHCI mutex is held.
1112 static int
1113 hci1394_ohci_phy_read_no_lock(hci1394_ohci_handle_t ohci_hdl, uint_t address,
1114 uint_t *data)
1116 uint32_t ohci_reg;
1117 int count;
1120 ASSERT(ohci_hdl != NULL);
1121 ASSERT(data != NULL);
1122 ASSERT(MUTEX_HELD(&ohci_hdl->ohci_mutex));
1124 /* You can't read or write PHY register #0 */
1125 if (address == 0) {
1126 return (DDI_FAILURE);
1129 /* Verify phy access not in progress */
1130 ohci_reg = ddi_get32(ohci_hdl->ohci_reg_handle,
1131 &ohci_hdl->ohci_regs->phy_ctrl);
1132 if ((ohci_reg & (OHCI_PHYC_RDREG | OHCI_PHYC_WRREG)) != 0) {
1133 return (DDI_FAILURE);
1136 /* Start the PHY register read */
1137 ohci_reg = OHCI_PHYC_RDREG | ((address & 0xF) <<
1138 OHCI_PHYC_REGADDR_SHIFT);
1139 ddi_put32(ohci_hdl->ohci_reg_handle, &ohci_hdl->ohci_regs->phy_ctrl,
1140 ohci_reg);
1143 * The PHY read usually takes less than 1uS. It is not worth having
1144 * this be interrupt driven. Having this be interrupt driven would also
1145 * make the bus reset and self id processing much more complex for
1146 * 1995 PHY's. We will wait up to hci1394_phy_delay_uS for the read
1147 * to complete (this was initially set to 10). I have yet to see
1148 * count > 1. The delay is a patchable variable.
1150 count = 0;
1151 while (count < hci1394_phy_delay_uS) {
1152 /* See if the read is done yet */
1153 ohci_reg = ddi_get32(ohci_hdl->ohci_reg_handle,
1154 &ohci_hdl->ohci_regs->phy_ctrl);
1155 if ((ohci_reg & OHCI_PHYC_RDDONE) != 0) {
1157 * The read is done. clear the phyRegRecv interrupt. We
1158 * do not have this interrupt enabled but this keeps
1159 * things clean in case someone in the future does.
1160 * Break out of the loop, we are done.
1162 ddi_put32(ohci_hdl->ohci_reg_handle,
1163 &ohci_hdl->ohci_regs->intr_event_clr,
1164 OHCI_INTR_PHY_REG_RCVD);
1165 break;
1169 * the phy read did not yet complete, wait 1uS, increment the
1170 * count and try again.
1172 drv_usecwait(1);
1173 count++;
1176 /* Check to see if we timed out */
1177 if (count >= hci1394_phy_delay_uS) {
1178 /* we timed out, return failure */
1179 *data = 0;
1180 return (DDI_FAILURE);
1183 /* setup the PHY read data to be returned */
1184 *data = (ddi_get32(ohci_hdl->ohci_reg_handle,
1185 &ohci_hdl->ohci_regs->phy_ctrl) & OHCI_PHYC_RDDATA_MASK) >>
1186 OHCI_PHYC_RDDATA_SHIFT;
1188 return (DDI_SUCCESS);
1193 * hci1394_ohci_phy_write_no_lock()
1194 * This routine actually performs the PHY register write. It is separated
1195 * out from phy_write so set & clr lock can perform an atomic PHY register
1196 * operation. It assumes the OpenHCI mutex is held.
1198 static int
1199 hci1394_ohci_phy_write_no_lock(hci1394_ohci_handle_t ohci_hdl, uint_t address,
1200 uint_t data)
1202 uint32_t ohci_reg;
1203 int count;
1206 ASSERT(ohci_hdl != NULL);
1207 ASSERT(MUTEX_HELD(&ohci_hdl->ohci_mutex));
1209 /* You can't read or write PHY register #0 */
1210 if (address == 0) {
1211 return (DDI_FAILURE);
1214 /* Verify phy access not in progress */
1215 ohci_reg = ddi_get32(ohci_hdl->ohci_reg_handle,
1216 &ohci_hdl->ohci_regs->phy_ctrl);
1217 if ((ohci_reg & (OHCI_PHYC_RDREG | OHCI_PHYC_WRREG)) != 0) {
1218 return (DDI_FAILURE);
1221 /* Start the PHY register write */
1222 ohci_reg = OHCI_PHYC_WRREG | ((address & 0xF) <<
1223 OHCI_PHYC_REGADDR_SHIFT) | (data & OHCI_PHYC_WRDATA_MASK);
1224 ddi_put32(ohci_hdl->ohci_reg_handle,
1225 &ohci_hdl->ohci_regs->phy_ctrl, ohci_reg);
1228 * The PHY write usually takes less than 1uS. It is not worth having
1229 * this be interrupt driven. Having this be interrupt driven would also
1230 * make the bus reset and self id processing much more complex. We will
1231 * wait up to hci1394_phy_delay_uS for the write to complete (this was
1232 * initially set to 10). I have yet to see count > 0. The delay is a
1233 * patchable variable.
1235 count = 0;
1236 while (count < hci1394_phy_delay_uS) {
1237 /* See if the write is done yet */
1238 ohci_reg = ddi_get32(ohci_hdl->ohci_reg_handle,
1239 &ohci_hdl->ohci_regs->phy_ctrl);
1240 if ((ohci_reg & OHCI_PHYC_WRREG) == 0) {
1242 * The write completed. Break out of the loop, we are
1243 * done.
1245 break;
1249 * the phy write did not yet complete, wait 1uS, increment the
1250 * count and try again.
1252 drv_usecwait(1);
1253 count++;
1256 /* Check to see if we timed out */
1257 if (count >= hci1394_phy_delay_uS) {
1258 /* we timed out, return failure */
1259 return (DDI_FAILURE);
1262 return (DDI_SUCCESS);
1267 * hci1394_ohci_phy_info()
1268 * Return selfid word for our PHY. This routine should ONLY be called for
1269 * adapters with a 1394-1995 PHY. These PHY's do not embed their own selfid
1270 * information in the selfid buffer so we need to do it for them in the
1271 * selfid complete interrupt handler. This routine only supports building
1272 * selfid info for a 3 port PHY. Since we will probably not ever see a
1273 * 1394-1995 PHY in any production system, and if we do it will have 3 ports
1274 * or less, this is a pretty safe assumption.
1277 hci1394_ohci_phy_info(hci1394_ohci_handle_t ohci_hdl, uint32_t *info)
1279 int status;
1280 uint32_t phy_info;
1281 uint32_t reg;
1282 int index;
1283 int num_ports;
1284 int count;
1285 uint32_t port_status;
1288 ASSERT(ohci_hdl != NULL);
1289 ASSERT(info != NULL);
1290 ASSERT(ohci_hdl->ohci_phy == H1394_PHY_1995);
1293 * Set Link on. We are using power class 0 since we have no idea what
1294 * our real power class is.
1296 phy_info = 0x80400000;
1298 /* Add in Physical ID */
1299 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
1300 &ohci_hdl->ohci_regs->node_id);
1301 phy_info = phy_info | ((reg << IEEE1394_SELFID_PHYID_SHIFT) &
1302 IEEE1394_SELFID_PHYID_MASK);
1304 /* Add in Gap Count */
1305 status = hci1394_ohci_phy_read(ohci_hdl, 1, &reg);
1306 if (status != DDI_SUCCESS) {
1307 return (DDI_FAILURE);
1309 phy_info = phy_info | ((reg << IEEE1394_SELFID_GAP_CNT_SHIFT) &
1310 IEEE1394_SELFID_GAP_CNT_MASK);
1312 /* Add in speed & ports */
1313 status = hci1394_ohci_phy_read(ohci_hdl, 2, &reg);
1314 if (status != DDI_SUCCESS) {
1315 return (DDI_FAILURE);
1317 phy_info = phy_info | ((reg & 0xC0) << 8);
1318 num_ports = reg & 0x1F;
1320 /* PHY reports that it has 0 ports?? */
1321 if (num_ports == 0) {
1322 return (DDI_FAILURE);
1325 /* Build up the port information for each port in the PHY */
1326 count = 0;
1327 for (index = 0; index < 3; index++) {
1328 if (num_ports > 0) {
1329 status = hci1394_ohci_phy_read(ohci_hdl,
1330 count + 3, &reg);
1331 if (status != DDI_SUCCESS) {
1332 return (DDI_FAILURE);
1334 /* if port is not connected */
1335 if ((reg & 0x04) == 0) {
1336 port_status =
1337 IEEE1394_SELFID_PORT_NOT_CONNECTED;
1339 /* else if port is connected to parent */
1340 } else if ((reg & 0x08) == 0) {
1341 port_status = IEEE1394_SELFID_PORT_TO_PARENT;
1343 /* else port is connected to child */
1344 } else {
1345 port_status = IEEE1394_SELFID_PORT_TO_CHILD;
1348 num_ports--;
1349 } else {
1350 port_status = IEEE1394_SELFID_PORT_NO_PORT;
1353 /* add in the port information */
1354 phy_info = phy_info | (port_status << (6 - (index * 2)));
1355 count++;
1358 /* Copy the PHY selfid info to the return parameter */
1359 *info = phy_info;
1361 return (DDI_SUCCESS);
1366 * hci1394_ohci_current_busgen()
1367 * return the current bus generation.
1369 uint_t
1370 hci1394_ohci_current_busgen(hci1394_ohci_handle_t ohci_hdl)
1372 uint32_t reg;
1373 uint_t generation_count;
1376 ASSERT(ohci_hdl != NULL);
1378 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
1379 &ohci_hdl->ohci_regs->self_id_count);
1380 generation_count = (reg & OHCI_SLFC_GEN_MASK) >> OHCI_SLFC_GEN_SHIFT;
1382 return (generation_count);
1387 * hci1394_ohci_startup()
1388 * Startup the 1394 nexus driver. This is called after all of the HW has
1389 * been initialized (in both attach and resume) and we are ready to
1390 * participate on the bus.
1393 hci1394_ohci_startup(hci1394_ohci_handle_t ohci_hdl)
1395 int status;
1398 ASSERT(ohci_hdl != NULL);
1401 * Turn on 1394 link. This allows us to receive 1394 traffic off the
1402 * bus
1404 hci1394_ohci_link_enable(ohci_hdl);
1407 * Reset the 1394 Bus.
1408 * Need to do this so that the link layer can collect all of the self-id
1409 * packets. The Interrupt routine will cause further initialization
1410 * after the bus reset has completed
1412 status = hci1394_ohci_bus_reset(ohci_hdl);
1413 if (status != DDI_SUCCESS) {
1414 return (DDI_FAILURE);
1417 /* setup out initial interrupt mask and enable interrupts */
1418 hci1394_isr_mask_setup(ohci_hdl->soft_state);
1419 hci1394_ohci_intr_master_enable(ohci_hdl);
1421 return (DDI_SUCCESS);
1426 * hci1394_ohci_postwr_addr()
1427 * Read the Posted Write Address registers. This should be read when a
1428 * posted write error is detected to find out what transaction had an error.
1430 void
1431 hci1394_ohci_postwr_addr(hci1394_ohci_handle_t ohci_hdl, uint64_t *addr)
1433 uint32_t reg;
1436 ASSERT(ohci_hdl != NULL);
1437 ASSERT(addr != NULL);
1439 /* read in the errored address */
1440 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
1441 &ohci_hdl->ohci_regs->posted_write_addrhi);
1442 *addr = ((uint64_t)reg) << 32;
1443 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
1444 &ohci_hdl->ohci_regs->posted_write_addrlo);
1445 *addr = *addr | (uint64_t)reg;
1448 * Interrupt should be cleared after reading the posted write address.
1449 * See 13.2.8.1 in OpenHCI spec v1.0.
1451 hci1394_ohci_intr_clear(ohci_hdl, OHCI_INTR_POST_WR_ERR);
1456 * hci1394_ohci_guid()
1457 * Return the adapter's GUID
1459 uint64_t
1460 hci1394_ohci_guid(hci1394_ohci_handle_t ohci_hdl)
1462 uint32_t reg;
1463 uint64_t guid;
1466 ASSERT(ohci_hdl != NULL);
1468 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
1469 &ohci_hdl->ohci_regs->guid_hi);
1470 guid = ((uint64_t)reg) << 32;
1471 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
1472 &ohci_hdl->ohci_regs->guid_lo);
1473 guid = guid | (uint64_t)reg;
1475 return (guid);
1480 * hci1394_ohci_csr_read()
1481 * Read one of the HW implemented CSR registers. These include
1482 * bus_manager_id, bandwidth_available, channels_available_hi, and
1483 * channels_available_lo. Offset should be set to
1484 * OHCI_CSR_SEL_BUS_MGR_ID, OHCI_CSR_SEL_BANDWIDTH_AVAIL
1485 * OHCI_CSR_SEL_CHANS_AVAIL_HI, or OHCI_CSR_SEL_CHANS_AVAIL_LO.
1488 hci1394_ohci_csr_read(hci1394_ohci_handle_t ohci_hdl, uint_t offset,
1489 uint32_t *data)
1491 uint_t generation;
1492 int status;
1495 ASSERT(ohci_hdl != NULL);
1496 ASSERT(data != NULL);
1499 * read the CSR register by doing a cswap with the same compare and
1500 * swap value.
1502 generation = hci1394_ohci_current_busgen(ohci_hdl);
1503 status = hci1394_ohci_csr_cswap(ohci_hdl, generation, offset, 0, 0,
1504 data);
1505 if (status != DDI_SUCCESS) {
1506 return (DDI_FAILURE);
1509 return (DDI_SUCCESS);
1514 * hci1394_ohci_csr_cswap()
1515 * Perform a compare/swap on one of the HW implemented CSR registers. These
1516 * include bus_manager_id, bandwidth_available, channels_available_hi, and
1517 * channels_available_lo. Offset should be set to
1518 * OHCI_CSR_SEL_BUS_MGR_ID, OHCI_CSR_SEL_BANDWIDTH_AVAIL
1519 * OHCI_CSR_SEL_CHANS_AVAIL_HI, or OHCI_CSR_SEL_CHANS_AVAIL_LO.
1522 hci1394_ohci_csr_cswap(hci1394_ohci_handle_t ohci_hdl, uint_t generation,
1523 uint_t offset, uint32_t compare, uint32_t swap, uint32_t *old)
1525 int count;
1526 uint32_t ohci_reg;
1529 ASSERT(ohci_hdl != NULL);
1530 ASSERT(old != NULL);
1533 * Make sure we have not gotten a bus reset since this action was
1534 * started.
1536 if (generation != hci1394_ohci_current_busgen(ohci_hdl)) {
1537 return (DDI_FAILURE);
1540 mutex_enter(&ohci_hdl->ohci_mutex);
1542 /* init csrData and csrCompare */
1543 ddi_put32(ohci_hdl->ohci_reg_handle,
1544 &ohci_hdl->ohci_regs->csr_data, swap);
1545 ddi_put32(ohci_hdl->ohci_reg_handle,
1546 &ohci_hdl->ohci_regs->csr_compare_data, compare);
1548 /* start the compare swap */
1549 ddi_put32(ohci_hdl->ohci_reg_handle,
1550 &ohci_hdl->ohci_regs->csr_ctrl, offset & OHCI_CSR_SELECT);
1553 * The CSR access should be immediate. There in nothing that officially
1554 * states this so we will wait up to 2uS just in case before we timeout.
1555 * We actually perform a compare swap with both compare and swap set
1556 * to the same value. This will return the old value which is in
1557 * essence, a read.
1559 count = 0;
1560 while (count < 2) {
1561 /* See if the compare swap is done */
1562 ohci_reg = ddi_get32(ohci_hdl->ohci_reg_handle,
1563 &ohci_hdl->ohci_regs->csr_ctrl);
1564 if ((ohci_reg & OHCI_CSR_DONE) != 0) {
1565 /* The compare swap is done, break out of the loop */
1566 break;
1569 * The compare swap has not completed yet, wait 1uS, increment
1570 * the count and try again
1572 drv_usecwait(1);
1573 count++;
1576 /* If we timed out, return an error */
1577 if (count >= 2) {
1578 *old = 0;
1579 mutex_exit(&ohci_hdl->ohci_mutex);
1580 return (DDI_FAILURE);
1583 /* Copy the old data into the return parameter */
1584 *old = ddi_get32(ohci_hdl->ohci_reg_handle,
1585 &ohci_hdl->ohci_regs->csr_data);
1587 mutex_exit(&ohci_hdl->ohci_mutex);
1590 * There is a race condition in the OpenHCI design here. After checking
1591 * the generation and before performing the cswap, we could get a bus
1592 * reset and incorrectly set something like the bus manager. This would
1593 * put us into a condition where we would not have a bus manager and
1594 * we would think there was one. If it is possible that this race
1595 * condition occured, we will reset the bus to clean things up. We only
1596 * care about this if the compare swap was successful.
1598 if (generation != hci1394_ohci_current_busgen(ohci_hdl)) {
1599 if (*old == compare) {
1600 (void) hci1394_ohci_bus_reset(ohci_hdl);
1601 return (DDI_FAILURE);
1605 return (DDI_SUCCESS);
1610 * hci1394_ohci_contender_enable()
1611 * Set the contender bit in the PHY. This routine should only be called
1612 * if our PHY is 1394A compliant. (i.e. this routine should not be called
1613 * for a 1394-1995 PHY).
1616 hci1394_ohci_contender_enable(hci1394_ohci_handle_t ohci_hdl)
1618 int status;
1621 ASSERT(ohci_hdl != NULL);
1624 * Make sure that phy is not a 1394-1995 phy. Those phy's do not have a
1625 * contender bit to set.
1627 if (ohci_hdl->ohci_phy == H1394_PHY_1995) {
1628 return (DDI_FAILURE);
1631 /* Set the Contender Bit */
1632 status = hci1394_ohci_phy_set(ohci_hdl, 0x4, OHCI_PHY_CNTDR);
1633 if (status != DDI_SUCCESS) {
1634 return (DDI_FAILURE);
1637 return (DDI_SUCCESS);
1642 * hci1394_ohci_root_holdoff_enable()
1643 * Set the root holdoff bit in the PHY. Since there are race conditions when
1644 * writing to PHY register 1 (which can get updated from a PHY packet off the
1645 * bus), we cache this state until a "long" bus reset is issued.
1648 hci1394_ohci_root_holdoff_enable(hci1394_ohci_handle_t ohci_hdl)
1650 ASSERT(ohci_hdl != NULL);
1652 ohci_hdl->ohci_set_root_holdoff = B_TRUE;
1654 return (DDI_SUCCESS);
1659 * hci1394_ohci_gap_count_set()
1660 * Set the gap count in the PHY. Since there are race conditions when writing
1661 * to PHY register 1 (which can get updated from a PHY packet off the bus),
1662 * we cache this gap count until a "long" bus reset is issued.
1665 hci1394_ohci_gap_count_set(hci1394_ohci_handle_t ohci_hdl, uint_t gap_count)
1667 ASSERT(ohci_hdl != NULL);
1669 ohci_hdl->ohci_set_gap_count = B_TRUE;
1670 ohci_hdl->ohci_gap_count = gap_count & OHCI_PHY_MAX_GAP;
1672 return (DDI_SUCCESS);
1677 * hci1394_ohci_phy_filter_set()
1678 * Enable a node (or nodes) to perform transactions to our physical
1679 * memory. OpenHCI allows you to disable/enable physical requests on a node
1680 * per node basis. A physical request is basically a read/write to 1394
1681 * address space 0x0 - 0xFFFFFFFF. This address goes out to the IO MMU (in
1682 * the case of a SPARC machine). The HAL starts with all nodes unable to
1683 * read/write physical memory. The Services Layer will call down and enable
1684 * nodes via setting a physical filter bit for that given node. Since node
1685 * numbers change every bus reset, the services layer has to call down after
1686 * every bus reset to re-enable physical accesses. (NOTE: the hardware
1687 * automatically clears these bits.
1690 hci1394_ohci_phy_filter_set(hci1394_ohci_handle_t ohci_hdl, uint64_t mask,
1691 uint_t generation)
1693 uint32_t data;
1696 ASSERT(ohci_hdl != NULL);
1699 * Make sure we have not gotten a bus reset since this action was
1700 * started.
1702 if (generation != hci1394_ohci_current_busgen(ohci_hdl)) {
1703 return (DDI_FAILURE);
1706 data = (uint32_t)((mask >> 32) & 0xFFFFFFFF);
1707 ddi_put32(ohci_hdl->ohci_reg_handle,
1708 &ohci_hdl->ohci_regs->phys_req_filterhi_set, data);
1709 data = (uint32_t)(mask & 0xFFFFFFFF);
1710 ddi_put32(ohci_hdl->ohci_reg_handle,
1711 &ohci_hdl->ohci_regs->phys_req_filterlo_set, data);
1714 * There is a race condition in the OpenHCI design here. After checking
1715 * the generation and before setting the physical filter bits, we could
1716 * get a bus reset and incorrectly set the physical filter bits. If it
1717 * is possible that this race condition occured, we will reset the bus
1718 * to clean things up.
1720 if (generation != hci1394_ohci_current_busgen(ohci_hdl)) {
1721 (void) hci1394_ohci_bus_reset(ohci_hdl);
1722 return (DDI_SUCCESS);
1725 return (DDI_SUCCESS);
1730 * hci1394_ohci_phy_filter_clr()
1731 * Disable a node (or nodes) from performing transactions to our physical
1732 * memory. See hci1394_ohci_phy_filter_set() above for more info.
1735 hci1394_ohci_phy_filter_clr(hci1394_ohci_handle_t ohci_hdl,
1736 uint64_t mask, uint_t generation)
1738 uint32_t data;
1741 ASSERT(ohci_hdl != NULL);
1744 * Make sure we have not gotten a bus reset since this action was
1745 * started.
1747 if (generation != hci1394_ohci_current_busgen(ohci_hdl)) {
1748 return (DDI_FAILURE);
1751 data = (uint32_t)((mask >> 32) & 0xFFFFFFFF);
1752 ddi_put32(ohci_hdl->ohci_reg_handle,
1753 &ohci_hdl->ohci_regs->phys_req_filterhi_clr, data);
1754 data = (uint32_t)(mask & 0xFFFFFFFF);
1755 ddi_put32(ohci_hdl->ohci_reg_handle,
1756 &ohci_hdl->ohci_regs->phys_req_filterlo_clr, data);
1758 return (DDI_SUCCESS);
1763 * hci1394_ohci_bus_reset_short()
1764 * Perform a 1394A short bus reset. This function should only be called
1765 * on an adapter with a 1394A PHY (or later).
1768 hci1394_ohci_bus_reset_short(hci1394_ohci_handle_t ohci_hdl)
1770 int status;
1772 ASSERT(ohci_hdl != NULL);
1775 * Make sure that phy is not a 1394-1995 phy. Those phy's do not have a
1776 * contender bit to set.
1778 if (ohci_hdl->ohci_phy == H1394_PHY_1995) {
1779 return (DDI_FAILURE);
1782 /* Initiate the short bus reset */
1783 status = hci1394_ohci_phy_set(ohci_hdl, 0x5, OHCI_PHY_ISBR);
1784 if (status != DDI_SUCCESS) {
1785 return (DDI_FAILURE);
1788 return (status);
1793 * hci1394_ohci_cfgrom_update()
1794 * Update the config rom with the provided contents. The config rom is
1795 * provided as a byte stream which is multiple of 4 bytes large. The
1796 * size is passed as a quadlet (4 bytes) count. The entire contents
1797 * of the config rom is updated at once. We do not provide a partial
1798 * update interface.
1800 void
1801 hci1394_ohci_cfgrom_update(hci1394_ohci_handle_t ohci_hdl, void *local_buf,
1802 uint_t quadlet_count)
1804 uint32_t *data;
1807 ASSERT(ohci_hdl != NULL);
1808 ASSERT(local_buf != NULL);
1810 data = (uint32_t *)local_buf;
1812 /* zero out the config ROM header to start */
1813 ddi_put32(ohci_hdl->ohci_reg_handle,
1814 &ohci_hdl->ohci_regs->config_rom_hdr, 0);
1816 /* copy Services Layer buffer into config rom buffer */
1817 ddi_rep_put8(ohci_hdl->ohci_cfgrom.bi_handle, local_buf,
1818 (uint8_t *)ohci_hdl->ohci_cfgrom.bi_kaddr, quadlet_count << 2,
1819 DDI_DEV_AUTOINCR);
1821 (void) ddi_dma_sync(ohci_hdl->ohci_cfgrom.bi_dma_handle, 0,
1822 quadlet_count << 2, DDI_DMA_SYNC_FORDEV);
1825 * setup OHCI bus options and config rom hdr registers. We need to swap
1826 * the config rom header and bus options on an X86 machine since the
1827 * data is provided to us as a byte stream and the OHCI registers expect
1828 * a big endian 32-bit number.
1830 ddi_put32(ohci_hdl->ohci_reg_handle,
1831 &ohci_hdl->ohci_regs->bus_options, OHCI_SWAP32(data[2]));
1832 ddi_put32(ohci_hdl->ohci_reg_handle,
1833 &ohci_hdl->ohci_regs->config_rom_hdr, OHCI_SWAP32(data[0]));
1838 * hci1394_ohci_nodeid_get()
1839 * Return our current nodeid (bus #/Node #)
1841 void
1842 hci1394_ohci_nodeid_get(hci1394_ohci_handle_t ohci_hdl, uint_t *nodeid)
1844 uint32_t reg;
1846 ASSERT(ohci_hdl != NULL);
1847 ASSERT(nodeid != NULL);
1848 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
1849 &ohci_hdl->ohci_regs->node_id);
1850 *nodeid = (reg & 0xFFFF) << 16;
1855 * hci1394_ohci_nodeid_set()
1856 * Set our current nodeid (bus #/Node #). This actually sets our bus number.
1857 * Our node number cannot be set by software. This is usually trigered via
1858 * a write to the CSR NODEIDS register.
1860 void
1861 hci1394_ohci_nodeid_set(hci1394_ohci_handle_t ohci_hdl, uint_t nodeid)
1863 uint32_t reg;
1865 ASSERT(ohci_hdl != NULL);
1867 reg = ((nodeid & 0xFFC00000) >> 16);
1868 ddi_put32(ohci_hdl->ohci_reg_handle,
1869 &ohci_hdl->ohci_regs->node_id, reg);
1874 * hci1394_ohci_nodeid_info()
1875 * Return our current nodeid (bus #/Node #). This also returns whether or
1876 * not our nodeid error bit is set. This is useful in determining if the
1877 * bus reset completed without errors in the selfid complete interrupt
1878 * processing.
1880 void
1881 hci1394_ohci_nodeid_info(hci1394_ohci_handle_t ohci_hdl, uint_t *nodeid,
1882 boolean_t *error)
1884 uint32_t reg;
1886 ASSERT(ohci_hdl != NULL);
1887 ASSERT(nodeid != NULL);
1889 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
1890 &ohci_hdl->ohci_regs->node_id);
1891 *nodeid = reg & 0xFFFF;
1892 if ((reg & OHCI_NDID_IDVALID) == 0) {
1893 *error = B_TRUE;
1894 } else {
1895 *error = B_FALSE;
1901 * hci1394_ohci_cycletime_get()
1902 * Return the current cycle time
1904 void
1905 hci1394_ohci_cycletime_get(hci1394_ohci_handle_t ohci_hdl,
1906 uint32_t *cycle_time)
1908 ASSERT(ohci_hdl != NULL);
1909 ASSERT(cycle_time != NULL);
1910 *cycle_time = ddi_get32(ohci_hdl->ohci_reg_handle,
1911 &ohci_hdl->ohci_regs->isoch_cycle_timer);
1916 * hci1394_ohci_cycletime_get()
1917 * Set the cycle time
1919 void
1920 hci1394_ohci_cycletime_set(hci1394_ohci_handle_t ohci_hdl,
1921 uint32_t cycle_time)
1923 ASSERT(ohci_hdl != NULL);
1924 ddi_put32(ohci_hdl->ohci_reg_handle,
1925 &ohci_hdl->ohci_regs->isoch_cycle_timer, cycle_time);
1930 * hci1394_ohci_bustime_get()
1931 * Return the current bus time.
1933 void
1934 hci1394_ohci_bustime_get(hci1394_ohci_handle_t ohci_hdl, uint32_t *bus_time)
1936 uint32_t bus_time1;
1937 uint32_t bus_time2;
1938 uint32_t cycle_time;
1941 ASSERT(ohci_hdl != NULL);
1942 ASSERT(bus_time != NULL);
1945 * The bus time is composed of a portion of the cycle time and the
1946 * cycle time rollover count (ohci_bustime_count). There is a race
1947 * condition where we read the rollover count and then the cycle
1948 * timer rolls over. This is the reason for the double read of the
1949 * rollover count.
1951 do {
1952 bus_time1 = ohci_hdl->ohci_bustime_count;
1953 cycle_time = ddi_get32(ohci_hdl->ohci_reg_handle,
1954 &ohci_hdl->ohci_regs->isoch_cycle_timer);
1955 bus_time2 = ohci_hdl->ohci_bustime_count;
1956 } while (bus_time1 != bus_time2);
1958 *bus_time = (bus_time2 << 7) | (cycle_time >> 25);
1963 * hci1394_ohci_bustime_set()
1964 * Set the cycle timer rollover portion of the bus time.
1966 void
1967 hci1394_ohci_bustime_set(hci1394_ohci_handle_t ohci_hdl, uint32_t bus_time)
1969 ASSERT(ohci_hdl != NULL);
1972 * we will start with the cycle 64 seconds interrupt disabled. If this
1973 * is the first write to bus time, enable the interrupt.
1975 if (ohci_hdl->ohci_bustime_enabled == B_FALSE) {
1976 ohci_hdl->ohci_bustime_enabled = B_TRUE;
1977 /* Clear the cycle64Seconds interrupt then enable it */
1978 hci1394_ohci_intr_clear(ohci_hdl, OHCI_INTR_CYC_64_SECS);
1979 hci1394_ohci_intr_enable(ohci_hdl, OHCI_INTR_CYC_64_SECS);
1981 ohci_hdl->ohci_bustime_count = (bus_time >> 7);
1986 * hci1394_ohci_atreq_retries_get()
1987 * Get the number of atreq retries we will perform.
1989 void
1990 hci1394_ohci_atreq_retries_get(hci1394_ohci_handle_t ohci_hdl,
1991 uint_t *atreq_retries)
1993 uint32_t reg;
1995 ASSERT(ohci_hdl != NULL);
1996 ASSERT(atreq_retries != NULL);
1997 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
1998 &ohci_hdl->ohci_regs->at_retries);
1999 *atreq_retries = reg & OHCI_RET_MAX_ATREQ_MASK;
2004 * hci1394_ohci_atreq_retries_get()
2005 * Set the number of atreq retries we will perform.
2007 void
2008 hci1394_ohci_atreq_retries_set(hci1394_ohci_handle_t ohci_hdl,
2009 uint_t atreq_retries)
2011 uint32_t reg;
2014 ASSERT(ohci_hdl != NULL);
2016 mutex_enter(&ohci_hdl->ohci_mutex);
2017 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
2018 &ohci_hdl->ohci_regs->at_retries);
2019 reg = reg & ~OHCI_RET_MAX_ATREQ_MASK;
2020 reg = reg | (atreq_retries & OHCI_RET_MAX_ATREQ_MASK);
2021 ddi_put32(ohci_hdl->ohci_reg_handle,
2022 &ohci_hdl->ohci_regs->at_retries, reg);
2023 mutex_exit(&ohci_hdl->ohci_mutex);
2028 * hci1394_ohci_isr_cycle64seconds()
2029 * Interrupt handler for the cycle64seconds interrupt.
2031 void
2032 hci1394_ohci_isr_cycle64seconds(hci1394_ohci_handle_t ohci_hdl)
2034 uint32_t cycle_time;
2036 ASSERT(ohci_hdl != NULL);
2038 hci1394_ohci_intr_clear(ohci_hdl, OHCI_INTR_CYC_64_SECS);
2039 cycle_time = ddi_get32(ohci_hdl->ohci_reg_handle,
2040 &ohci_hdl->ohci_regs->isoch_cycle_timer);
2043 * cycle64second interrupts when the MSBit in the cycle timer changes
2044 * state. We only care about rollover so we will increment only when
2045 * the MSBit is set to 0.
2047 if ((cycle_time & 0x80000000) == 0) {
2048 ohci_hdl->ohci_bustime_count++;
2054 * hci1394_ohci_isr_phy()
2055 * Interrupt handler for a PHY event
2057 void
2058 hci1394_ohci_isr_phy(hci1394_ohci_handle_t ohci_hdl)
2060 uint_t phy_status;
2061 int status;
2064 ASSERT(ohci_hdl != NULL);
2066 /* clear the interrupt */
2067 hci1394_ohci_intr_clear(ohci_hdl, OHCI_INTR_PHY);
2069 /* increment the statistics count */
2070 ohci_hdl->ohci_drvinfo->di_stats.st_phy_isr++;
2073 * If the PHY is a 1995 phy, just return since there are no status bits
2074 * to read.
2076 if (ohci_hdl->ohci_phy == H1394_PHY_1995) {
2077 return;
2080 /* See why we got this interrupt */
2081 status = hci1394_ohci_phy_read(ohci_hdl, 5, &phy_status);
2082 if (status != DDI_SUCCESS) {
2083 return;
2086 if (phy_status & OHCI_PHY_LOOP_ERR) {
2087 ohci_hdl->ohci_drvinfo->di_stats.st_phy_loop_err++;
2088 cmn_err(CE_NOTE, "hci1394(%d): ERROR - bus loop detected",
2089 ohci_hdl->ohci_drvinfo->di_instance);
2091 if (phy_status & OHCI_PHY_PWRFAIL_ERR) {
2092 ohci_hdl->ohci_drvinfo->di_stats.st_phy_pwrfail_err++;
2094 if (phy_status & OHCI_PHY_TIMEOUT_ERR) {
2095 ohci_hdl->ohci_drvinfo->di_stats.st_phy_timeout_err++;
2097 if (phy_status & OHCI_PHY_PORTEVT_ERR) {
2098 ohci_hdl->ohci_drvinfo->di_stats.st_phy_portevt_err++;
2101 /* clear any set status bits */
2102 status = hci1394_ohci_phy_write(ohci_hdl, 5, phy_status);
2103 if (status != DDI_SUCCESS) {
2104 return;
2108 * Disable the PHY interrupt. We are getting stuck in this ISR in
2109 * certain PHY implementations so we will disable the interrupt until
2110 * we see a selfid complete.
2112 hci1394_ohci_intr_disable(ohci_hdl, OHCI_INTR_PHY);
2117 * hci1394_ohci_root_check
2118 * Returns status about if we are currently the root node on the 1394 bus.
2119 * returns B_TRUE if we are the root, B_FALSE if we are not the root.
2121 boolean_t
2122 hci1394_ohci_root_check(hci1394_ohci_handle_t ohci_hdl)
2124 uint32_t reg;
2125 int status;
2127 ASSERT(ohci_hdl != NULL);
2128 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
2129 &ohci_hdl->ohci_regs->node_id);
2130 if ((reg & OHCI_REG_NODEID_ROOT) && (reg & OHCI_NDID_IDVALID)) {
2131 status = B_TRUE;
2132 } else {
2133 status = B_FALSE;
2136 return (status);
2141 * hci1394_ohci_cmc_check()
2142 * Returns status about if we are cycle master capable. Returns
2143 * B_TRUE if we are the cycle master capable, B_FALSE if we are not the cycle
2144 * master capable.
2146 boolean_t
2147 hci1394_ohci_cmc_check(hci1394_ohci_handle_t ohci_hdl)
2149 uint32_t reg;
2150 int status;
2152 ASSERT(ohci_hdl != NULL);
2153 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
2154 &ohci_hdl->ohci_regs->bus_options);
2155 if (reg & OHCI_REG_BUSOPTIONS_CMC) {
2156 status = B_TRUE;
2157 } else {
2158 status = B_FALSE;
2161 return (status);
2166 * hci1394_ohci_cycle_master_enable()
2167 * Enables us to be cycle master. If we are root, we will start generating
2168 * cycle start packets.
2170 void
2171 hci1394_ohci_cycle_master_enable(hci1394_ohci_handle_t ohci_hdl)
2173 ASSERT(ohci_hdl != NULL);
2175 /* First make sure that cycleTooLong is clear */
2176 ddi_put32(ohci_hdl->ohci_reg_handle,
2177 &ohci_hdl->ohci_regs->intr_event_clr, OHCI_INTR_CYC_TOO_LONG);
2179 /* Enable Cycle Master */
2180 ddi_put32(ohci_hdl->ohci_reg_handle,
2181 &ohci_hdl->ohci_regs->link_ctrl_set, OHCI_LC_CYC_MAST);
2186 * hci1394_ohci_cycle_master_disable()
2187 * Disabled us from being cycle master. If we are root, we will stop
2188 * generating cycle start packets.
2190 void
2191 hci1394_ohci_cycle_master_disable(hci1394_ohci_handle_t ohci_hdl)
2193 ASSERT(ohci_hdl != NULL);
2195 /* disable cycle master */
2196 ddi_put32(ohci_hdl->ohci_reg_handle,
2197 &ohci_hdl->ohci_regs->link_ctrl_clr, OHCI_LC_CYC_MAST);
2202 * hci1394_ohci_resume()
2203 * Re-initialize the openHCI HW during a resume. (after a power suspend)
2206 hci1394_ohci_resume(hci1394_ohci_handle_t ohci_hdl)
2208 uint32_t quadlet;
2209 int status;
2212 ASSERT(ohci_hdl != NULL);
2214 /* Re-initialize the OpenHCI chip */
2215 status = hci1394_ohci_chip_init(ohci_hdl);
2216 if (status != DDI_SUCCESS) {
2217 return (DDI_FAILURE);
2220 /* Re-initialize the PHY */
2221 status = hci1394_ohci_phy_resume(ohci_hdl);
2222 if (status != DDI_SUCCESS) {
2223 return (DDI_FAILURE);
2226 /* Re-initialize any 1394A features we are using */
2227 status = hci1394_ohci_1394a_resume(ohci_hdl);
2228 if (status != DDI_SUCCESS) {
2229 return (DDI_FAILURE);
2232 /* Tell OpenHCI where the Config ROM buffer is */
2233 ddi_put32(ohci_hdl->ohci_reg_handle,
2234 &ohci_hdl->ohci_regs->config_rom_maplo,
2235 (uint32_t)ohci_hdl->ohci_cfgrom.bi_cookie.dmac_address);
2237 /* Tell OpenHCI where the SelfId buffer is */
2238 ddi_put32(ohci_hdl->ohci_reg_handle,
2239 &ohci_hdl->ohci_regs->self_id_buflo,
2240 (uint32_t)ohci_hdl->ohci_selfid.bi_cookie.dmac_address);
2242 /* Enable selfid DMA engine */
2243 hci1394_ohci_selfid_enable(ohci_hdl);
2246 * re-setup OHCI bus options and config rom hdr registers. We need to
2247 * read from the config rom using ddi_rep_get8 since it is stored as
2248 * a byte stream. We need to swap the config rom header and bus options
2249 * on an X86 machine since the data is a byte stream and the OHCI
2250 * registers expect a big endian 32-bit number.
2252 ddi_rep_get8(ohci_hdl->ohci_cfgrom.bi_handle, (uint8_t *)&quadlet,
2253 &((uint8_t *)ohci_hdl->ohci_cfgrom.bi_kaddr)[8], 4,
2254 DDI_DEV_AUTOINCR);
2255 ddi_put32(ohci_hdl->ohci_reg_handle,
2256 &ohci_hdl->ohci_regs->bus_options, OHCI_SWAP32(quadlet));
2257 ddi_rep_get8(ohci_hdl->ohci_cfgrom.bi_handle, (uint8_t *)&quadlet,
2258 &((uint8_t *)ohci_hdl->ohci_cfgrom.bi_kaddr)[0], 4,
2259 DDI_DEV_AUTOINCR);
2260 ddi_put32(ohci_hdl->ohci_reg_handle,
2261 &ohci_hdl->ohci_regs->config_rom_hdr, OHCI_SWAP32(quadlet));
2263 return (DDI_SUCCESS);
2268 * hci1394_ohci_selfid_init()
2269 * Initialize the selfid buffer
2271 static int
2272 hci1394_ohci_selfid_init(hci1394_ohci_handle_t ohci_hdl)
2274 hci1394_buf_parms_t parms;
2275 int status;
2278 ASSERT(ohci_hdl != NULL);
2281 * Setup for 2K buffer, aligned on a 2Kbyte address boundary. Make sure
2282 * that the buffer is not broken up into multiple cookies. OpenHCI can
2283 * only handle one address for the selfid buffer location.
2285 parms.bp_length = 2048;
2286 parms.bp_max_cookies = 1;
2287 parms.bp_alignment = 2048;
2288 status = hci1394_buf_alloc(ohci_hdl->ohci_drvinfo, &parms,
2289 &ohci_hdl->ohci_selfid, &ohci_hdl->ohci_selfid_handle);
2290 if (status != DDI_SUCCESS) {
2291 return (DDI_FAILURE);
2294 /* Tell OpenHCI where the buffer is */
2295 ddi_put32(ohci_hdl->ohci_reg_handle,
2296 &ohci_hdl->ohci_regs->self_id_buflo,
2297 (uint32_t)ohci_hdl->ohci_selfid.bi_cookie.dmac_address);
2299 /* Enable selfid DMA engine */
2300 hci1394_ohci_selfid_enable(ohci_hdl);
2302 return (DDI_SUCCESS);
2307 * hci1394_ohci_selfid_enable()
2308 * Allow selfid packets to be placed into the selfid buffer. This should be
2309 * called after the selfid buffer address has been setup in the HW.
2311 void
2312 hci1394_ohci_selfid_enable(hci1394_ohci_handle_t ohci_hdl)
2314 ASSERT(ohci_hdl != NULL);
2317 * Allow selfid packets to be received. This should be called during
2318 * driver attach after the selfid buffer address has been initialized.
2320 * Link Control Register
2321 * rscSelfId = 1 <= bit 9
2323 ddi_put32(ohci_hdl->ohci_reg_handle,
2324 &ohci_hdl->ohci_regs->link_ctrl_set, OHCI_LC_RCV_SELF);
2329 * hci1394_ohci_selfid_read()
2330 * Read a word out of the selfid buffer.
2332 void
2333 hci1394_ohci_selfid_read(hci1394_ohci_handle_t ohci_hdl, uint_t offset,
2334 uint32_t *data)
2336 ASSERT(ohci_hdl != NULL);
2337 ASSERT(data != NULL);
2338 *data = ddi_get32(ohci_hdl->ohci_selfid.bi_handle,
2339 &((uint32_t *)ohci_hdl->ohci_selfid.bi_kaddr)[offset]);
2344 * hci1394_ohci_selfid_info()
2345 * Return the current bus generation, the number of bytes currently in the
2346 * selfid buffer, and if we have seen any selfid errors.
2348 void
2349 hci1394_ohci_selfid_info(hci1394_ohci_handle_t ohci_hdl, uint_t *busgen,
2350 uint_t *size, boolean_t *error)
2352 uint32_t reg;
2355 ASSERT(ohci_hdl != NULL);
2356 ASSERT(busgen != NULL);
2357 ASSERT(size != NULL);
2358 ASSERT(error != NULL);
2360 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
2361 &ohci_hdl->ohci_regs->self_id_count);
2362 *busgen = (reg & OHCI_SLFC_GEN_MASK) >> OHCI_SLFC_GEN_SHIFT;
2363 *size = reg & OHCI_SLFC_NUM_QUADS_MASK;
2364 if ((reg & OHCI_SLFC_ERROR) == 0) {
2365 *error = B_FALSE;
2366 } else {
2367 *error = B_TRUE;
2373 * hci1394_ohci_selfid_buf_current()
2374 * Test if the selfid buffer is current. Return B_TRUE if it is current and
2375 * B_FALSE if it is not current.
2377 boolean_t
2378 hci1394_ohci_selfid_buf_current(hci1394_ohci_handle_t ohci_hdl)
2380 uint32_t reg;
2381 int status;
2383 ASSERT(ohci_hdl != NULL);
2386 * if the generation stored in the selfid buffer is not equal to the
2387 * generation we have previously stored, the selfid buffer is not
2388 * current. (It maybe older or it maybe newer)
2390 reg = ddi_get32(ohci_hdl->ohci_selfid.bi_handle,
2391 &((uint32_t *)ohci_hdl->ohci_selfid.bi_kaddr)[0]);
2392 if (ohci_hdl->ohci_drvinfo->di_gencnt != ((reg & OHCI_SLFC_GEN_MASK) >>
2393 OHCI_SLFC_GEN_SHIFT)) {
2394 status = B_FALSE;
2395 } else {
2396 status = B_TRUE;
2399 return (status);
2404 * hci1394_ohci_selfid_sync()
2405 * Perform a ddi_dma_sync on the selfid buffer
2407 void
2408 hci1394_ohci_selfid_sync(hci1394_ohci_handle_t ohci_hdl)
2410 ASSERT(ohci_hdl != NULL);
2411 (void) ddi_dma_sync(ohci_hdl->ohci_selfid.bi_dma_handle, 0,
2412 ohci_hdl->ohci_selfid.bi_length, DDI_DMA_SYNC_FORKERNEL);
2417 * hci1394_ohci_cfgrom_init()
2418 * Initialize the configuration ROM buffer
2420 static int
2421 hci1394_ohci_cfgrom_init(hci1394_ohci_handle_t ohci_hdl)
2423 hci1394_buf_parms_t parms;
2424 int status;
2427 ASSERT(ohci_hdl != NULL);
2430 * Setup for 1K buffer, aligned at 1K address boundary, and allow no
2431 * less than 4 byte data transfers. Create the Buffer. Make sure that
2432 * the buffer is not broken up into multiple cookies. OpenHCI can only
2433 * handle one address for the config ROM buffer location.
2435 parms.bp_length = 1024;
2436 parms.bp_max_cookies = 1;
2437 parms.bp_alignment = 1024;
2438 status = hci1394_buf_alloc(ohci_hdl->ohci_drvinfo, &parms,
2439 &ohci_hdl->ohci_cfgrom, &ohci_hdl->ohci_cfgrom_handle);
2440 if (status != DDI_SUCCESS) {
2441 return (DDI_FAILURE);
2444 /* Tell OpenHCI where the buffer is */
2445 ddi_put32(ohci_hdl->ohci_reg_handle,
2446 &ohci_hdl->ohci_regs->config_rom_maplo,
2447 (uint32_t)ohci_hdl->ohci_cfgrom.bi_cookie.dmac_address);
2449 return (DDI_SUCCESS);
2454 * hci1394_ohci_bus_capabilities()
2455 * Return our current bus capabilities
2457 void
2458 hci1394_ohci_bus_capabilities(hci1394_ohci_handle_t ohci_hdl,
2459 uint32_t *bus_capabilities)
2461 ASSERT(ohci_hdl != NULL);
2463 * read in the bus options register. Set bits saying that we are isoch
2464 * resource manager capable, Cycle master capable, and Isoch capable
2466 *bus_capabilities = ddi_get32(ohci_hdl->ohci_reg_handle,
2467 &ohci_hdl->ohci_regs->bus_options) | (OHCI_BOPT_IRMC |
2468 OHCI_BOPT_CMC | OHCI_BOPT_ISC);
2473 * hci1394_ohci_at_active()
2474 * Returns status one if either of the AT engines are active. If either AT
2475 * engine is active, we return B_TRUE. If both AT engines are not active, we
2476 * return B_FALSE.
2478 boolean_t
2479 hci1394_ohci_at_active(hci1394_ohci_handle_t ohci_hdl)
2481 uint32_t reg;
2484 ASSERT(ohci_hdl != NULL);
2486 /* see if atreq active bit set */
2487 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
2488 &ohci_hdl->ohci_regs->at_req.ctxt_ctrl_set);
2489 if (reg & OHCI_CC_ACTIVE_MASK) {
2490 /* atreq engine is still active */
2491 return (B_TRUE);
2494 /* see if atresp active bit set */
2495 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
2496 &ohci_hdl->ohci_regs->at_resp.ctxt_ctrl_set);
2497 if (reg & OHCI_CC_ACTIVE_MASK) {
2498 /* atresp engine is still active */
2499 return (B_TRUE);
2502 /* both atreq and atresp active bits are cleared */
2503 return (B_FALSE);
2508 * hci1394_ohci_atreq_start()
2509 * Start the atreq dma engine. Set the address of the first descriptor
2510 * to read in equal to cmdptr.
2512 void
2513 hci1394_ohci_atreq_start(hci1394_ohci_handle_t ohci_hdl, uint32_t cmdptr)
2515 ASSERT(ohci_hdl != NULL);
2517 ddi_put32(ohci_hdl->ohci_reg_handle,
2518 &ohci_hdl->ohci_regs->at_req.cmd_ptrlo, cmdptr);
2519 ddi_put32(ohci_hdl->ohci_reg_handle,
2520 &ohci_hdl->ohci_regs->at_req.ctxt_ctrl_set, OHCI_CC_RUN_MASK);
2525 * hci1394_ohci_atreq_wake()
2526 * Wake up the atreq dma engine. This should be called when a new descriptor
2527 * is added to the Q and the dma engine has already be started. It it OK to
2528 * call this when the DMA engine is active.
2530 void
2531 hci1394_ohci_atreq_wake(hci1394_ohci_handle_t ohci_hdl)
2533 ASSERT(ohci_hdl != NULL);
2535 ddi_put32(ohci_hdl->ohci_reg_handle,
2536 &ohci_hdl->ohci_regs->at_req.ctxt_ctrl_set, OHCI_CC_WAKE_MASK);
2541 * hci1394_ohci_atreq_stop()
2542 * Stop the atreq dma engine. No further descriptors will be read until
2543 * it dma engine is started again.
2545 void
2546 hci1394_ohci_atreq_stop(hci1394_ohci_handle_t ohci_hdl)
2548 ASSERT(ohci_hdl != NULL);
2550 ddi_put32(ohci_hdl->ohci_reg_handle,
2551 &ohci_hdl->ohci_regs->at_req.ctxt_ctrl_clr, OHCI_CC_RUN_MASK);
2556 * hci1394_ohci_arresp_start()
2557 * Start the arresp dma engine. Set the address of the first descriptor
2558 * to read in equal to cmdptr.
2560 void
2561 hci1394_ohci_arresp_start(hci1394_ohci_handle_t ohci_hdl, uint32_t cmdptr)
2563 ASSERT(ohci_hdl != NULL);
2565 ddi_put32(ohci_hdl->ohci_reg_handle,
2566 &ohci_hdl->ohci_regs->ar_resp.cmd_ptrlo, cmdptr);
2567 ddi_put32(ohci_hdl->ohci_reg_handle,
2568 &ohci_hdl->ohci_regs->ar_resp.ctxt_ctrl_set, OHCI_CC_RUN_MASK);
2573 * hci1394_ohci_arresp_wake()
2574 * Wake up the arresp dma engine. This should be called when a new
2575 * descriptor is added to the Q and the dma engine has already be started.
2576 * It is OK to call this when the DMA engine is active.
2578 void
2579 hci1394_ohci_arresp_wake(hci1394_ohci_handle_t ohci_hdl)
2581 ASSERT(ohci_hdl != NULL);
2583 ddi_put32(ohci_hdl->ohci_reg_handle,
2584 &ohci_hdl->ohci_regs->ar_resp.ctxt_ctrl_set, OHCI_CC_WAKE_MASK);
2589 * hci1394_ohci_atreq_stop()
2590 * Stop the arresp dma engine. No further data will be received after any
2591 * current packets being received have finished.
2593 void
2594 hci1394_ohci_arresp_stop(hci1394_ohci_handle_t ohci_hdl)
2596 ASSERT(ohci_hdl != NULL);
2598 ddi_put32(ohci_hdl->ohci_reg_handle,
2599 &ohci_hdl->ohci_regs->ar_resp.ctxt_ctrl_clr, OHCI_CC_RUN_MASK);
2604 * hci1394_ohci_arreq_start()
2605 * Start the arreq dma engine. Set the address of the first descriptor
2606 * to read in equal to cmdptr.
2608 void
2609 hci1394_ohci_arreq_start(hci1394_ohci_handle_t ohci_hdl, uint32_t cmdptr)
2611 ASSERT(ohci_hdl != NULL);
2613 ddi_put32(ohci_hdl->ohci_reg_handle,
2614 &ohci_hdl->ohci_regs->ar_req.cmd_ptrlo, cmdptr);
2615 ddi_put32(ohci_hdl->ohci_reg_handle,
2616 &ohci_hdl->ohci_regs->ar_req.ctxt_ctrl_set, OHCI_CC_RUN_MASK);
2621 * hci1394_ohci_arreq_wake()
2622 * Wake up the arreq dma engine. This should be called when a new descriptor
2623 * is added to the Q and the dma engine has already be started. It is OK to
2624 * call this when the DMA engine is active.
2626 void
2627 hci1394_ohci_arreq_wake(hci1394_ohci_handle_t ohci_hdl)
2629 ASSERT(ohci_hdl != NULL);
2631 ddi_put32(ohci_hdl->ohci_reg_handle,
2632 &ohci_hdl->ohci_regs->ar_req.ctxt_ctrl_set, OHCI_CC_WAKE_MASK);
2637 * hci1394_ohci_arreq_stop()
2638 * Stop the arreq dma engine. No further data will be received after any
2639 * current packets being received have finished.
2641 void
2642 hci1394_ohci_arreq_stop(hci1394_ohci_handle_t ohci_hdl)
2644 ASSERT(ohci_hdl != NULL);
2646 ddi_put32(ohci_hdl->ohci_reg_handle,
2647 &ohci_hdl->ohci_regs->ar_req.ctxt_ctrl_clr, OHCI_CC_RUN_MASK);
2652 * hci1394_ohci_atresp_start()
2653 * Start the atresp dma engine. Set the address of the first descriptor
2654 * to read in equal to cmdptr.
2656 void
2657 hci1394_ohci_atresp_start(hci1394_ohci_handle_t ohci_hdl, uint32_t cmdptr)
2659 ASSERT(ohci_hdl != NULL);
2661 ddi_put32(ohci_hdl->ohci_reg_handle,
2662 &ohci_hdl->ohci_regs->at_resp.cmd_ptrlo, cmdptr);
2663 ddi_put32(ohci_hdl->ohci_reg_handle,
2664 &ohci_hdl->ohci_regs->at_resp.ctxt_ctrl_set, OHCI_CC_RUN_MASK);
2669 * hci1394_ohci_atresp_wake()
2670 * Wake up the atresp dma engine. This should be called when a new
2671 * descriptor is added to the Q and the dma engine has already be started.
2672 * It is OK to call this when the DMA engine is active.
2674 void
2675 hci1394_ohci_atresp_wake(hci1394_ohci_handle_t ohci_hdl)
2677 ASSERT(ohci_hdl != NULL);
2679 ddi_put32(ohci_hdl->ohci_reg_handle,
2680 &ohci_hdl->ohci_regs->at_resp.ctxt_ctrl_set, OHCI_CC_WAKE_MASK);
2685 * hci1394_ohci_atresp_stop()
2686 * Stop the atresp dma engine. No further descriptors will be read until
2687 * it dma engine is started again.
2689 void
2690 hci1394_ohci_atresp_stop(hci1394_ohci_handle_t ohci_hdl)
2692 ASSERT(ohci_hdl != NULL);
2694 ddi_put32(ohci_hdl->ohci_reg_handle,
2695 &ohci_hdl->ohci_regs->at_resp.ctxt_ctrl_clr, OHCI_CC_RUN_MASK);
2700 * hci1394_ohci_1394a_init()
2701 * Initialize any 1394a features that we are using.
2703 /* ARGSUSED */
2705 hci1394_ohci_1394a_init(hci1394_ohci_handle_t ohci_hdl)
2707 uint32_t reg;
2708 int status;
2710 ASSERT(ohci_hdl != NULL);
2712 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
2713 &ohci_hdl->ohci_regs->hc_ctrl_set);
2714 if (reg & OHCI_HC_PROG_PHY_ENBL) {
2715 ddi_put32(ohci_hdl->ohci_reg_handle,
2716 &ohci_hdl->ohci_regs->hc_ctrl_set, OHCI_HC_APHY_ENBL);
2717 status = hci1394_ohci_phy_set(ohci_hdl, 5,
2718 (OHCI_PHY_ENBL_ACCEL | OHCI_PHY_ENBL_MULTI));
2719 if (status != DDI_SUCCESS) {
2720 return (DDI_FAILURE);
2724 return (DDI_SUCCESS);
2729 * hci1394_ohci_1394a_init()
2730 * Re-initialize any 1394a features that we are using.
2732 /* ARGSUSED */
2734 hci1394_ohci_1394a_resume(hci1394_ohci_handle_t ohci_hdl)
2736 uint32_t reg;
2737 int status;
2739 ASSERT(ohci_hdl != NULL);
2741 reg = ddi_get32(ohci_hdl->ohci_reg_handle,
2742 &ohci_hdl->ohci_regs->hc_ctrl_set);
2743 if (reg & OHCI_HC_PROG_PHY_ENBL) {
2744 ddi_put32(ohci_hdl->ohci_reg_handle,
2745 &ohci_hdl->ohci_regs->hc_ctrl_set, OHCI_HC_APHY_ENBL);
2746 status = hci1394_ohci_phy_set(ohci_hdl, 5,
2747 (OHCI_PHY_ENBL_ACCEL | OHCI_PHY_ENBL_MULTI));
2748 if (status != DDI_SUCCESS) {
2749 return (DDI_FAILURE);
2753 return (DDI_SUCCESS);