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