Home | History | Annotate | Line # | Download | only in ieee1394
fwohci.c revision 1.2
      1  1.1      matt /*-
      2  1.1      matt  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      3  1.1      matt  * All rights reserved.
      4  1.1      matt  *
      5  1.1      matt  * This code is derived from software contributed to The NetBSD Foundation
      6  1.1      matt  * by Matt Thomas of 3am Software Foundry.
      7  1.1      matt  *
      8  1.1      matt  * Redistribution and use in source and binary forms, with or without
      9  1.1      matt  * modification, are permitted provided that the following conditions
     10  1.1      matt  * are met:
     11  1.1      matt  * 1. Redistributions of source code must retain the above copyright
     12  1.1      matt  *    notice, this list of conditions and the following disclaimer.
     13  1.1      matt  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1      matt  *    notice, this list of conditions and the following disclaimer in the
     15  1.1      matt  *    documentation and/or other materials provided with the distribution.
     16  1.1      matt  * 3. All advertising materials mentioning features or use of this software
     17  1.1      matt  *    must display the following acknowledgement:
     18  1.1      matt  *        This product includes software developed by the NetBSD
     19  1.1      matt  *        Foundation, Inc. and its contributors.
     20  1.1      matt  * 4. Neither the name of The NetBSD Foundation nor the names of its
     21  1.1      matt  *    contributors may be used to endorse or promote products derived
     22  1.1      matt  *    from this software without specific prior written permission.
     23  1.1      matt  *
     24  1.1      matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     25  1.1      matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     26  1.1      matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     27  1.1      matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     28  1.1      matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     29  1.1      matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     30  1.1      matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     31  1.1      matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     32  1.1      matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     33  1.1      matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     34  1.1      matt  * POSSIBILITY OF SUCH DAMAGE.
     35  1.1      matt  */
     36  1.1      matt 
     37  1.1      matt #include <sys/param.h>
     38  1.2  augustss #include <sys/systm.h>
     39  1.1      matt #include <sys/types.h>
     40  1.1      matt #include <sys/socket.h>
     41  1.1      matt #include <sys/device.h>
     42  1.1      matt 
     43  1.1      matt #include <machine/bus.h>
     44  1.1      matt 
     45  1.1      matt #include <dev/ieee1394/ieee1394reg.h>
     46  1.1      matt #include <dev/ieee1394/fwohcireg.h>
     47  1.1      matt 
     48  1.1      matt #include <dev/ieee1394/ieee1394var.h>
     49  1.1      matt #include <dev/ieee1394/fwohcivar.h>
     50  1.1      matt 
     51  1.1      matt static const char * const ieee1394_speeds[] = { IEEE1394_SPD_STRINGS };
     52  1.1      matt 
     53  1.1      matt int
     54  1.1      matt fwohci_init(struct fwohci_softc *sc)
     55  1.1      matt {
     56  1.1      matt 	u_int32_t val;
     57  1.1      matt 
     58  1.1      matt 	/* What dialect of OHCI is this device?
     59  1.1      matt 	 */
     60  1.1      matt 	val = OHCI_CSR_READ(sc, OHCI_REG_Version);
     61  1.1      matt 	printf("%s: OHCI %u.%u", sc->sc_sc1394.sc1394_dev.dv_xname,
     62  1.1      matt 	    OHCI_Version_GET_Version(val), OHCI_Version_GET_Revision(val));
     63  1.1      matt 
     64  1.1      matt 	/* Is the Global UID ROM present?
     65  1.1      matt 	 */
     66  1.1      matt 	if ((val & OHCI_Version_GUID_ROM) == 0) {
     67  1.2  augustss 		printf("\n%s: fatal: no global UID ROM\n", sc->sc_sc1394.sc1394_dev.dv_xname);
     68  1.1      matt 		return -1;
     69  1.1      matt 	}
     70  1.1      matt 
     71  1.1      matt 	/* Extract the Global UID
     72  1.1      matt 	 */
     73  1.1      matt 	val = OHCI_CSR_READ(sc, OHCI_REG_GUIDHi);
     74  1.1      matt 	sc->sc_sc1394.sc1394_guid[0] = (val >> 24) & 0xff;
     75  1.1      matt 	sc->sc_sc1394.sc1394_guid[1] = (val >> 16) & 0xff;
     76  1.1      matt 	sc->sc_sc1394.sc1394_guid[2] = (val >>  8) & 0xff;
     77  1.1      matt 	sc->sc_sc1394.sc1394_guid[3] = (val >>  0) & 0xff;
     78  1.1      matt 
     79  1.1      matt 	val = OHCI_CSR_READ(sc, OHCI_REG_GUIDLo);
     80  1.1      matt 	sc->sc_sc1394.sc1394_guid[4] = (val >> 24) & 0xff;
     81  1.1      matt 	sc->sc_sc1394.sc1394_guid[5] = (val >> 16) & 0xff;
     82  1.1      matt 	sc->sc_sc1394.sc1394_guid[6] = (val >>  8) & 0xff;
     83  1.1      matt 	sc->sc_sc1394.sc1394_guid[7] = (val >>  0) & 0xff;
     84  1.1      matt 
     85  1.1      matt 	printf(", %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
     86  1.1      matt 	    sc->sc_sc1394.sc1394_guid[0], sc->sc_sc1394.sc1394_guid[1],
     87  1.1      matt 	    sc->sc_sc1394.sc1394_guid[2], sc->sc_sc1394.sc1394_guid[3],
     88  1.1      matt 	    sc->sc_sc1394.sc1394_guid[4], sc->sc_sc1394.sc1394_guid[5],
     89  1.1      matt 	    sc->sc_sc1394.sc1394_guid[6], sc->sc_sc1394.sc1394_guid[7]);
     90  1.1      matt 
     91  1.1      matt 	/* Get the maximum link speed and receive size
     92  1.1      matt 	 */
     93  1.1      matt 	val = OHCI_CSR_READ(sc, OHCI_REG_BusOptions);
     94  1.1      matt 	sc->sc_sc1394.sc1394_link_speed =
     95  1.1      matt 	    (val & OHCI_BusOptions_LinkSpd_MASK)
     96  1.1      matt 		>> OHCI_BusOptions_LinkSpd_BITPOS;
     97  1.1      matt 	if (sc->sc_sc1394.sc1394_link_speed < IEEE1394_SPD_MAX) {
     98  1.1      matt 		printf(", %s", ieee1394_speeds[sc->sc_sc1394.sc1394_link_speed]);
     99  1.1      matt 	} else {
    100  1.1      matt 		printf(", unknown speed %u", sc->sc_sc1394.sc1394_link_speed);
    101  1.1      matt 	}
    102  1.1      matt 
    103  1.1      matt 	/* MaxRec is encoded as log2(max_rec_octets)-1
    104  1.1      matt 	 */
    105  1.1      matt 	sc->sc_sc1394.sc1394_max_receive =
    106  1.1      matt 	    1 << (((val & OHCI_BusOptions_MaxRec_MASK)
    107  1.1      matt 		       >> OHCI_BusOptions_MaxRec_BITPOS) + 1);
    108  1.1      matt 	printf(", %u byte packets max", sc->sc_sc1394.sc1394_max_receive);
    109  1.1      matt 
    110  1.1      matt 	printf("\n");
    111  1.1      matt 	return 0;
    112  1.1      matt }
    113  1.1      matt 
    114  1.1      matt int
    115  1.1      matt fwohci_intr(void *arg)
    116  1.1      matt {
    117  1.1      matt 	struct fwohci_softc * const sc = arg;
    118  1.1      matt 	int progress = 0;
    119  1.1      matt 
    120  1.1      matt 	for (;;) {
    121  1.1      matt 		u_int32_t intmask = OHCI_CSR_READ(sc, OHCI_REG_IntEventClear);
    122  1.1      matt 		if (intmask == 0)
    123  1.1      matt 			return progress;
    124  1.1      matt 		OHCI_CSR_WRITE(sc, OHCI_REG_IntEventClear, intmask);
    125  1.1      matt 		progress = 1;
    126  1.1      matt 	}
    127  1.1      matt }
    128