Home | History | Annotate | Line # | Download | only in ieee1394
fwohci.c revision 1.1
      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.1  matt #include <sys/types.h>
     39  1.1  matt #include <sys/socket.h>
     40  1.1  matt #include <sys/device.h>
     41  1.1  matt 
     42  1.1  matt #include <machine/bus.h>
     43  1.1  matt 
     44  1.1  matt #include <dev/ieee1394/ieee1394reg.h>
     45  1.1  matt #include <dev/ieee1394/fwohcireg.h>
     46  1.1  matt 
     47  1.1  matt #include <dev/ieee1394/ieee1394var.h>
     48  1.1  matt #include <dev/ieee1394/fwohcivar.h>
     49  1.1  matt 
     50  1.1  matt static const char * const ieee1394_speeds[] = { IEEE1394_SPD_STRINGS };
     51  1.1  matt 
     52  1.1  matt int
     53  1.1  matt fwohci_init(struct fwohci_softc *sc)
     54  1.1  matt {
     55  1.1  matt 	u_int32_t val;
     56  1.1  matt 
     57  1.1  matt 	/* What dialect of OHCI is this device?
     58  1.1  matt 	 */
     59  1.1  matt 	val = OHCI_CSR_READ(sc, OHCI_REG_Version);
     60  1.1  matt 	printf("%s: OHCI %u.%u", sc->sc_sc1394.sc1394_dev.dv_xname,
     61  1.1  matt 	    OHCI_Version_GET_Version(val), OHCI_Version_GET_Revision(val));
     62  1.1  matt 
     63  1.1  matt 	/* Is the Global UID ROM present?
     64  1.1  matt 	 */
     65  1.1  matt 	if ((val & OHCI_Version_GUID_ROM) == 0) {
     66  1.1  matt 		printf("\n%x: fatal: no global UID ROM\n", sc->sc_sc1394.sc1394_dev.dv_xname);
     67  1.1  matt 		return -1;
     68  1.1  matt 	}
     69  1.1  matt 
     70  1.1  matt 	/* Extract the Global UID
     71  1.1  matt 	 */
     72  1.1  matt 	val = OHCI_CSR_READ(sc, OHCI_REG_GUIDHi);
     73  1.1  matt 	sc->sc_sc1394.sc1394_guid[0] = (val >> 24) & 0xff;
     74  1.1  matt 	sc->sc_sc1394.sc1394_guid[1] = (val >> 16) & 0xff;
     75  1.1  matt 	sc->sc_sc1394.sc1394_guid[2] = (val >>  8) & 0xff;
     76  1.1  matt 	sc->sc_sc1394.sc1394_guid[3] = (val >>  0) & 0xff;
     77  1.1  matt 
     78  1.1  matt 	val = OHCI_CSR_READ(sc, OHCI_REG_GUIDLo);
     79  1.1  matt 	sc->sc_sc1394.sc1394_guid[4] = (val >> 24) & 0xff;
     80  1.1  matt 	sc->sc_sc1394.sc1394_guid[5] = (val >> 16) & 0xff;
     81  1.1  matt 	sc->sc_sc1394.sc1394_guid[6] = (val >>  8) & 0xff;
     82  1.1  matt 	sc->sc_sc1394.sc1394_guid[7] = (val >>  0) & 0xff;
     83  1.1  matt 
     84  1.1  matt 	printf(", %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
     85  1.1  matt 	    sc->sc_sc1394.sc1394_guid[0], sc->sc_sc1394.sc1394_guid[1],
     86  1.1  matt 	    sc->sc_sc1394.sc1394_guid[2], sc->sc_sc1394.sc1394_guid[3],
     87  1.1  matt 	    sc->sc_sc1394.sc1394_guid[4], sc->sc_sc1394.sc1394_guid[5],
     88  1.1  matt 	    sc->sc_sc1394.sc1394_guid[6], sc->sc_sc1394.sc1394_guid[7]);
     89  1.1  matt 
     90  1.1  matt 	/* Get the maximum link speed and receive size
     91  1.1  matt 	 */
     92  1.1  matt 	val = OHCI_CSR_READ(sc, OHCI_REG_BusOptions);
     93  1.1  matt 	sc->sc_sc1394.sc1394_link_speed =
     94  1.1  matt 	    (val & OHCI_BusOptions_LinkSpd_MASK)
     95  1.1  matt 		>> OHCI_BusOptions_LinkSpd_BITPOS;
     96  1.1  matt 	if (sc->sc_sc1394.sc1394_link_speed < IEEE1394_SPD_MAX) {
     97  1.1  matt 		printf(", %s", ieee1394_speeds[sc->sc_sc1394.sc1394_link_speed]);
     98  1.1  matt 	} else {
     99  1.1  matt 		printf(", unknown speed %u", sc->sc_sc1394.sc1394_link_speed);
    100  1.1  matt 	}
    101  1.1  matt 
    102  1.1  matt 	/* MaxRec is encoded as log2(max_rec_octets)-1
    103  1.1  matt 	 */
    104  1.1  matt 	sc->sc_sc1394.sc1394_max_receive =
    105  1.1  matt 	    1 << (((val & OHCI_BusOptions_MaxRec_MASK)
    106  1.1  matt 		       >> OHCI_BusOptions_MaxRec_BITPOS) + 1);
    107  1.1  matt 	printf(", %u byte packets max", sc->sc_sc1394.sc1394_max_receive);
    108  1.1  matt 
    109  1.1  matt 	printf("\n");
    110  1.1  matt 	return 0;
    111  1.1  matt }
    112  1.1  matt 
    113  1.1  matt int
    114  1.1  matt fwohci_intr(void *arg)
    115  1.1  matt {
    116  1.1  matt 	struct fwohci_softc * const sc = arg;
    117  1.1  matt 	int progress = 0;
    118  1.1  matt 
    119  1.1  matt 	for (;;) {
    120  1.1  matt 		u_int32_t intmask = OHCI_CSR_READ(sc, OHCI_REG_IntEventClear);
    121  1.1  matt 		if (intmask == 0)
    122  1.1  matt 			return progress;
    123  1.1  matt 		OHCI_CSR_WRITE(sc, OHCI_REG_IntEventClear, intmask);
    124  1.1  matt 		progress = 1;
    125  1.1  matt 	}
    126  1.1  matt }
    127