2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the acknowledgement as bellow:
|
|
|
|
*
|
2002-11-12 10:02:50 +00:00
|
|
|
* This product includes software developed by K. Kobayashi and H. Shimokawa
|
2002-09-13 12:31:56 +00:00
|
|
|
*
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*
|
|
|
|
*/
|
2002-11-12 10:02:50 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
#define ATRQ_CH 0
|
|
|
|
#define ATRS_CH 1
|
|
|
|
#define ARRQ_CH 2
|
|
|
|
#define ARRS_CH 3
|
|
|
|
#define ITX_CH 4
|
|
|
|
#define IRX_CH 0x24
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2003-01-26 15:39:04 +00:00
|
|
|
#include <sys/proc.h>
|
2002-09-13 12:31:56 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
|
|
|
#include <machine/cpufunc.h> /* for rdtsc proto for clock.h below */
|
|
|
|
#include <machine/clock.h>
|
|
|
|
#include <pci/pcivar.h>
|
|
|
|
#include <pci/pcireg.h>
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_extern.h>
|
|
|
|
#include <vm/pmap.h> /* for vtophys proto */
|
|
|
|
|
|
|
|
#include <dev/firewire/firewire.h>
|
|
|
|
#include <dev/firewire/firewirereg.h>
|
|
|
|
#include <dev/firewire/fwohcireg.h>
|
|
|
|
#include <dev/firewire/fwohcivar.h>
|
|
|
|
#include <dev/firewire/firewire_phy.h>
|
|
|
|
|
2003-01-13 16:08:09 +00:00
|
|
|
#include <dev/firewire/iec68113.h>
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
#undef OHCI_DEBUG
|
2002-11-12 10:02:50 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
static char dbcode[16][0x10]={"OUTM", "OUTL","INPM","INPL",
|
|
|
|
"STOR","LOAD","NOP ","STOP",};
|
|
|
|
static char dbkey[8][0x10]={"ST0", "ST1","ST2","ST3",
|
|
|
|
"UNDEF","REG","SYS","DEV"};
|
|
|
|
char fwohcicode[32][0x20]={
|
|
|
|
"No stat","Undef","long","miss Ack err",
|
|
|
|
"underrun","overrun","desc err", "data read err",
|
|
|
|
"data write err","bus reset","timeout","tcode err",
|
|
|
|
"Undef","Undef","unknown event","flushed",
|
|
|
|
"Undef","ack complete","ack pend","Undef",
|
|
|
|
"ack busy_X","ack busy_A","ack busy_B","Undef",
|
|
|
|
"Undef","Undef","Undef","ack tardy",
|
|
|
|
"Undef","ack data_err","ack type_err",""};
|
|
|
|
#define MAX_SPEED 2
|
|
|
|
extern char linkspeed[MAX_SPEED+1][0x10];
|
|
|
|
static char dbcond[4][0x10]={"NEV","C=1", "C=0", "ALL"};
|
|
|
|
u_int32_t tagbit[4] = { 1 << 28, 1 << 29, 1 << 30, 1 << 31};
|
|
|
|
|
|
|
|
static struct tcode_info tinfo[] = {
|
|
|
|
/* hdr_len block flag*/
|
|
|
|
/* 0 WREQQ */ {16, FWTI_REQ | FWTI_TLABEL},
|
|
|
|
/* 1 WREQB */ {16, FWTI_REQ | FWTI_TLABEL | FWTI_BLOCK_ASY},
|
|
|
|
/* 2 WRES */ {12, FWTI_RES},
|
|
|
|
/* 3 XXX */ { 0, 0},
|
|
|
|
/* 4 RREQQ */ {12, FWTI_REQ | FWTI_TLABEL},
|
|
|
|
/* 5 RREQB */ {16, FWTI_REQ | FWTI_TLABEL},
|
|
|
|
/* 6 RRESQ */ {16, FWTI_RES},
|
|
|
|
/* 7 RRESB */ {16, FWTI_RES | FWTI_BLOCK_ASY},
|
|
|
|
/* 8 CYCS */ { 0, 0},
|
|
|
|
/* 9 LREQ */ {16, FWTI_REQ | FWTI_TLABEL | FWTI_BLOCK_ASY},
|
|
|
|
/* a STREAM */ { 4, FWTI_REQ | FWTI_BLOCK_STR},
|
|
|
|
/* b LRES */ {16, FWTI_RES | FWTI_BLOCK_ASY},
|
|
|
|
/* c XXX */ { 0, 0},
|
|
|
|
/* d XXX */ { 0, 0},
|
|
|
|
/* e PHY */ {12, FWTI_REQ},
|
|
|
|
/* f XXX */ { 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define OHCI_WRITE_SIGMASK 0xffff0000
|
|
|
|
#define OHCI_READ_SIGMASK 0xffff0000
|
|
|
|
|
|
|
|
#define OWRITE(sc, r, x) bus_space_write_4((sc)->bst, (sc)->bsh, (r), (x))
|
|
|
|
#define OREAD(sc, r) bus_space_read_4((sc)->bst, (sc)->bsh, (r))
|
|
|
|
|
|
|
|
static void fwohci_ibr __P((struct firewire_comm *));
|
|
|
|
static void fwohci_db_init __P((struct fwohci_dbch *));
|
|
|
|
static void fwohci_db_free __P((struct fwohci_dbch *));
|
2002-11-12 04:54:30 +00:00
|
|
|
static void fwohci_arcv __P((struct fwohci_softc *, struct fwohci_dbch *, int));
|
|
|
|
static void fwohci_ircv __P((struct fwohci_softc *, struct fwohci_dbch *, int));
|
2002-09-13 12:31:56 +00:00
|
|
|
static void fwohci_txd __P((struct fwohci_softc *, struct fwohci_dbch *));
|
|
|
|
static void fwohci_start_atq __P((struct firewire_comm *));
|
|
|
|
static void fwohci_start_ats __P((struct firewire_comm *));
|
|
|
|
static void fwohci_start __P((struct fwohci_softc *, struct fwohci_dbch *));
|
|
|
|
static void fwohci_drain_atq __P((struct firewire_comm *, struct fw_xfer *));
|
|
|
|
static void fwohci_drain_ats __P((struct firewire_comm *, struct fw_xfer *));
|
|
|
|
static void fwohci_drain __P((struct firewire_comm *, struct fw_xfer *, struct fwohci_dbch *));
|
|
|
|
static u_int32_t fwphy_wrdata __P(( struct fwohci_softc *, u_int32_t, u_int32_t));
|
|
|
|
static u_int32_t fwphy_rddata __P(( struct fwohci_softc *, u_int32_t));
|
|
|
|
static int fwohci_rx_enable __P((struct fwohci_softc *, struct fwohci_dbch *));
|
|
|
|
static int fwohci_tx_enable __P((struct fwohci_softc *, struct fwohci_dbch *));
|
|
|
|
static int fwohci_irx_enable __P((struct firewire_comm *, int));
|
|
|
|
static int fwohci_irxpp_enable __P((struct firewire_comm *, int));
|
|
|
|
static int fwohci_irxbuf_enable __P((struct firewire_comm *, int));
|
|
|
|
static int fwohci_irx_disable __P((struct firewire_comm *, int));
|
|
|
|
static void fwohci_irx_post __P((struct firewire_comm *, u_int32_t *));
|
|
|
|
static int fwohci_itxbuf_enable __P((struct firewire_comm *, int));
|
|
|
|
static int fwohci_itx_disable __P((struct firewire_comm *, int));
|
|
|
|
static void fwohci_timeout __P((void *));
|
|
|
|
static void fwohci_poll __P((struct firewire_comm *, int, int));
|
|
|
|
static void fwohci_set_intr __P((struct firewire_comm *, int));
|
|
|
|
static int fwohci_add_rx_buf __P((struct fwohcidb_tr *, unsigned short, int, void *, void *));
|
|
|
|
static int fwohci_add_tx_buf __P((struct fwohcidb_tr *, unsigned short, int, void *));
|
|
|
|
static void dump_db __P((struct fwohci_softc *, u_int32_t));
|
|
|
|
static void print_db __P((volatile struct fwohcidb *, u_int32_t , u_int32_t));
|
|
|
|
static void dump_dma __P((struct fwohci_softc *, u_int32_t));
|
|
|
|
static u_int32_t fwohci_cyctimer __P((struct firewire_comm *));
|
|
|
|
static void fwohci_rbuf_update __P((struct fwohci_softc *, int));
|
|
|
|
static void fwohci_tbuf_update __P((struct fwohci_softc *, int));
|
|
|
|
void fwohci_txbufdb __P((struct fwohci_softc *, int , struct fw_bulkxfer *));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* memory allocated for DMA programs
|
|
|
|
*/
|
|
|
|
#define DMA_PROG_ALLOC (8 * PAGE_SIZE)
|
|
|
|
|
|
|
|
/* #define NDB 1024 */
|
|
|
|
#define NDB FWMAXQUEUE
|
|
|
|
#define NDVDB (DVBUF * NDB)
|
|
|
|
|
|
|
|
#define OHCI_VERSION 0x00
|
|
|
|
#define OHCI_CROMHDR 0x18
|
|
|
|
#define OHCI_BUS_OPT 0x20
|
|
|
|
#define OHCI_BUSIRMC (1 << 31)
|
|
|
|
#define OHCI_BUSCMC (1 << 30)
|
|
|
|
#define OHCI_BUSISC (1 << 29)
|
|
|
|
#define OHCI_BUSBMC (1 << 28)
|
|
|
|
#define OHCI_BUSPMC (1 << 27)
|
|
|
|
#define OHCI_BUSFNC OHCI_BUSIRMC | OHCI_BUSCMC | OHCI_BUSISC |\
|
|
|
|
OHCI_BUSBMC | OHCI_BUSPMC
|
|
|
|
|
|
|
|
#define OHCI_EUID_HI 0x24
|
|
|
|
#define OHCI_EUID_LO 0x28
|
|
|
|
|
|
|
|
#define OHCI_CROMPTR 0x34
|
|
|
|
#define OHCI_HCCCTL 0x50
|
|
|
|
#define OHCI_HCCCTLCLR 0x54
|
|
|
|
#define OHCI_AREQHI 0x100
|
|
|
|
#define OHCI_AREQHICLR 0x104
|
|
|
|
#define OHCI_AREQLO 0x108
|
|
|
|
#define OHCI_AREQLOCLR 0x10c
|
|
|
|
#define OHCI_PREQHI 0x110
|
|
|
|
#define OHCI_PREQHICLR 0x114
|
|
|
|
#define OHCI_PREQLO 0x118
|
|
|
|
#define OHCI_PREQLOCLR 0x11c
|
|
|
|
#define OHCI_PREQUPPER 0x120
|
|
|
|
|
|
|
|
#define OHCI_SID_BUF 0x64
|
|
|
|
#define OHCI_SID_CNT 0x68
|
|
|
|
#define OHCI_SID_CNT_MASK 0xffc
|
|
|
|
|
|
|
|
#define OHCI_IT_STAT 0x90
|
|
|
|
#define OHCI_IT_STATCLR 0x94
|
|
|
|
#define OHCI_IT_MASK 0x98
|
|
|
|
#define OHCI_IT_MASKCLR 0x9c
|
|
|
|
|
|
|
|
#define OHCI_IR_STAT 0xa0
|
|
|
|
#define OHCI_IR_STATCLR 0xa4
|
|
|
|
#define OHCI_IR_MASK 0xa8
|
|
|
|
#define OHCI_IR_MASKCLR 0xac
|
|
|
|
|
|
|
|
#define OHCI_LNKCTL 0xe0
|
|
|
|
#define OHCI_LNKCTLCLR 0xe4
|
|
|
|
|
|
|
|
#define OHCI_PHYACCESS 0xec
|
|
|
|
#define OHCI_CYCLETIMER 0xf0
|
|
|
|
|
|
|
|
#define OHCI_DMACTL(off) (off)
|
|
|
|
#define OHCI_DMACTLCLR(off) (off + 4)
|
|
|
|
#define OHCI_DMACMD(off) (off + 0xc)
|
|
|
|
#define OHCI_DMAMATCH(off) (off + 0x10)
|
|
|
|
|
|
|
|
#define OHCI_ATQOFF 0x180
|
|
|
|
#define OHCI_ATQCTL OHCI_ATQOFF
|
|
|
|
#define OHCI_ATQCTLCLR (OHCI_ATQOFF + 4)
|
|
|
|
#define OHCI_ATQCMD (OHCI_ATQOFF + 0xc)
|
|
|
|
#define OHCI_ATQMATCH (OHCI_ATQOFF + 0x10)
|
|
|
|
|
|
|
|
#define OHCI_ATSOFF 0x1a0
|
|
|
|
#define OHCI_ATSCTL OHCI_ATSOFF
|
|
|
|
#define OHCI_ATSCTLCLR (OHCI_ATSOFF + 4)
|
|
|
|
#define OHCI_ATSCMD (OHCI_ATSOFF + 0xc)
|
|
|
|
#define OHCI_ATSMATCH (OHCI_ATSOFF + 0x10)
|
|
|
|
|
|
|
|
#define OHCI_ARQOFF 0x1c0
|
|
|
|
#define OHCI_ARQCTL OHCI_ARQOFF
|
|
|
|
#define OHCI_ARQCTLCLR (OHCI_ARQOFF + 4)
|
|
|
|
#define OHCI_ARQCMD (OHCI_ARQOFF + 0xc)
|
|
|
|
#define OHCI_ARQMATCH (OHCI_ARQOFF + 0x10)
|
|
|
|
|
|
|
|
#define OHCI_ARSOFF 0x1e0
|
|
|
|
#define OHCI_ARSCTL OHCI_ARSOFF
|
|
|
|
#define OHCI_ARSCTLCLR (OHCI_ARSOFF + 4)
|
|
|
|
#define OHCI_ARSCMD (OHCI_ARSOFF + 0xc)
|
|
|
|
#define OHCI_ARSMATCH (OHCI_ARSOFF + 0x10)
|
|
|
|
|
|
|
|
#define OHCI_ITOFF(CH) (0x200 + 0x10 * (CH))
|
|
|
|
#define OHCI_ITCTL(CH) (OHCI_ITOFF(CH))
|
|
|
|
#define OHCI_ITCTLCLR(CH) (OHCI_ITOFF(CH) + 4)
|
|
|
|
#define OHCI_ITCMD(CH) (OHCI_ITOFF(CH) + 0xc)
|
|
|
|
|
|
|
|
#define OHCI_IROFF(CH) (0x400 + 0x20 * (CH))
|
|
|
|
#define OHCI_IRCTL(CH) (OHCI_IROFF(CH))
|
|
|
|
#define OHCI_IRCTLCLR(CH) (OHCI_IROFF(CH) + 4)
|
|
|
|
#define OHCI_IRCMD(CH) (OHCI_IROFF(CH) + 0xc)
|
|
|
|
#define OHCI_IRMATCH(CH) (OHCI_IROFF(CH) + 0x10)
|
|
|
|
|
|
|
|
d_ioctl_t fwohci_ioctl;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Communication with PHY device
|
|
|
|
*/
|
2002-11-12 05:52:01 +00:00
|
|
|
static u_int32_t
|
|
|
|
fwphy_wrdata( struct fwohci_softc *sc, u_int32_t addr, u_int32_t data)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
u_int32_t fun;
|
|
|
|
|
|
|
|
addr &= 0xf;
|
|
|
|
data &= 0xff;
|
|
|
|
|
|
|
|
fun = (PHYDEV_WRCMD | (addr << PHYDEV_REGADDR) | (data << PHYDEV_WRDATA));
|
|
|
|
OWRITE(sc, OHCI_PHYACCESS, fun);
|
|
|
|
DELAY(100);
|
|
|
|
|
|
|
|
return(fwphy_rddata( sc, addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
static u_int32_t
|
|
|
|
fwohci_set_bus_manager(struct firewire_comm *fc, u_int node)
|
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)fc;
|
|
|
|
int i;
|
|
|
|
u_int32_t bm;
|
|
|
|
|
|
|
|
#define OHCI_CSR_DATA 0x0c
|
|
|
|
#define OHCI_CSR_COMP 0x10
|
|
|
|
#define OHCI_CSR_CONT 0x14
|
|
|
|
#define OHCI_BUS_MANAGER_ID 0
|
|
|
|
|
|
|
|
OWRITE(sc, OHCI_CSR_DATA, node);
|
|
|
|
OWRITE(sc, OHCI_CSR_COMP, 0x3f);
|
|
|
|
OWRITE(sc, OHCI_CSR_CONT, OHCI_BUS_MANAGER_ID);
|
|
|
|
for (i = 0; !(OREAD(sc, OHCI_CSR_CONT) & (1<<31)) && (i < 1000); i++)
|
2003-01-15 04:21:16 +00:00
|
|
|
DELAY(10);
|
2002-09-13 12:31:56 +00:00
|
|
|
bm = OREAD(sc, OHCI_CSR_DATA);
|
2002-12-06 02:17:30 +00:00
|
|
|
if((bm & 0x3f) == 0x3f)
|
2002-09-13 12:31:56 +00:00
|
|
|
bm = node;
|
2002-12-06 02:17:30 +00:00
|
|
|
if (bootverbose)
|
|
|
|
device_printf(sc->fc.dev,
|
|
|
|
"fw_set_bus_manager: %d->%d (loop=%d)\n", bm, node, i);
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
return(bm);
|
|
|
|
}
|
|
|
|
|
2002-11-12 05:52:01 +00:00
|
|
|
static u_int32_t
|
|
|
|
fwphy_rddata(struct fwohci_softc *sc, u_int addr)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2002-12-31 10:00:36 +00:00
|
|
|
u_int32_t fun, stat;
|
|
|
|
u_int i, retry = 0;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
addr &= 0xf;
|
2002-12-31 10:00:36 +00:00
|
|
|
#define MAX_RETRY 100
|
|
|
|
again:
|
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, OHCI_INT_REG_FAIL);
|
2002-09-13 12:31:56 +00:00
|
|
|
fun = PHYDEV_RDCMD | (addr << PHYDEV_REGADDR);
|
|
|
|
OWRITE(sc, OHCI_PHYACCESS, fun);
|
2002-12-31 10:00:36 +00:00
|
|
|
for ( i = 0 ; i < MAX_RETRY ; i ++ ){
|
2002-09-13 12:31:56 +00:00
|
|
|
fun = OREAD(sc, OHCI_PHYACCESS);
|
|
|
|
if ((fun & PHYDEV_RDCMD) == 0 && (fun & PHYDEV_RDDONE) != 0)
|
|
|
|
break;
|
2003-01-15 04:21:16 +00:00
|
|
|
DELAY(100);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2002-12-31 10:00:36 +00:00
|
|
|
if(i >= MAX_RETRY) {
|
2003-01-15 04:21:16 +00:00
|
|
|
if (bootverbose)
|
|
|
|
device_printf(sc->fc.dev, "phy read failed(1).\n");
|
2003-01-01 04:23:54 +00:00
|
|
|
if (++retry < MAX_RETRY) {
|
2003-01-15 04:21:16 +00:00
|
|
|
DELAY(100);
|
2003-01-01 04:23:54 +00:00
|
|
|
goto again;
|
|
|
|
}
|
2002-12-31 10:00:36 +00:00
|
|
|
}
|
|
|
|
/* Make sure that SCLK is started */
|
|
|
|
stat = OREAD(sc, FWOHCI_INTSTAT);
|
|
|
|
if ((stat & OHCI_INT_REG_FAIL) != 0 ||
|
|
|
|
((fun >> PHYDEV_REGADDR) & 0xf) != addr) {
|
2003-01-15 04:21:16 +00:00
|
|
|
if (bootverbose)
|
|
|
|
device_printf(sc->fc.dev, "phy read failed(2).\n");
|
2002-12-31 10:00:36 +00:00
|
|
|
if (++retry < MAX_RETRY) {
|
2003-01-15 04:21:16 +00:00
|
|
|
DELAY(100);
|
2002-12-31 10:00:36 +00:00
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bootverbose || retry >= MAX_RETRY)
|
|
|
|
device_printf(sc->fc.dev,
|
|
|
|
"fwphy_rddata: loop=%d, retry=%d\n", i, retry);
|
|
|
|
#undef MAX_RETRY
|
2002-09-13 12:31:56 +00:00
|
|
|
return((fun >> PHYDEV_RDDATA )& 0xff);
|
|
|
|
}
|
|
|
|
/* Device specific ioctl. */
|
|
|
|
int
|
|
|
|
fwohci_ioctl (dev_t dev, u_long cmd, caddr_t data, int flag, fw_proc *td)
|
|
|
|
{
|
|
|
|
struct firewire_softc *sc;
|
|
|
|
struct fwohci_softc *fc;
|
|
|
|
int unit = DEV2UNIT(dev);
|
|
|
|
int err = 0;
|
|
|
|
struct fw_reg_req_t *reg = (struct fw_reg_req_t *) data;
|
|
|
|
u_int32_t *dmach = (u_int32_t *) data;
|
|
|
|
|
|
|
|
sc = devclass_get_softc(firewire_devclass, unit);
|
|
|
|
if(sc == NULL){
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
fc = (struct fwohci_softc *)sc->fc;
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return(EINVAL);
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case FWOHCI_WRREG:
|
|
|
|
#define OHCI_MAX_REG 0x800
|
|
|
|
if(reg->addr <= OHCI_MAX_REG){
|
|
|
|
OWRITE(fc, reg->addr, reg->data);
|
|
|
|
reg->data = OREAD(fc, reg->addr);
|
|
|
|
}else{
|
|
|
|
err = EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FWOHCI_RDREG:
|
|
|
|
if(reg->addr <= OHCI_MAX_REG){
|
|
|
|
reg->data = OREAD(fc, reg->addr);
|
|
|
|
}else{
|
|
|
|
err = EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
/* Read DMA descriptors for debug */
|
|
|
|
case DUMPDMA:
|
|
|
|
if(*dmach <= OHCI_MAX_DMA_CH ){
|
|
|
|
dump_dma(fc, *dmach);
|
|
|
|
dump_db(fc, *dmach);
|
|
|
|
}else{
|
|
|
|
err = EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2003-01-01 08:25:32 +00:00
|
|
|
static int
|
|
|
|
fwohci_probe_phy(struct fwohci_softc *sc, device_t dev)
|
|
|
|
{
|
|
|
|
u_int32_t reg, reg2;
|
|
|
|
int e1394a = 1;
|
|
|
|
/*
|
|
|
|
* probe PHY parameters
|
|
|
|
* 0. to prove PHY version, whether compliance of 1394a.
|
|
|
|
* 1. to probe maximum speed supported by the PHY and
|
|
|
|
* number of port supported by core-logic.
|
|
|
|
* It is not actually available port on your PC .
|
|
|
|
*/
|
|
|
|
OWRITE(sc, OHCI_HCCCTL, OHCI_HCC_LPS);
|
|
|
|
#if 0
|
|
|
|
/* XXX wait for SCLK. */
|
|
|
|
DELAY(100000);
|
|
|
|
#endif
|
|
|
|
reg = fwphy_rddata(sc, FW_PHY_SPD_REG);
|
|
|
|
|
|
|
|
if((reg >> 5) != 7 ){
|
|
|
|
sc->fc.mode &= ~FWPHYASYST;
|
|
|
|
sc->fc.nport = reg & FW_PHY_NP;
|
|
|
|
sc->fc.speed = reg & FW_PHY_SPD >> 6;
|
|
|
|
if (sc->fc.speed > MAX_SPEED) {
|
|
|
|
device_printf(dev, "invalid speed %d (fixed to %d).\n",
|
|
|
|
sc->fc.speed, MAX_SPEED);
|
|
|
|
sc->fc.speed = MAX_SPEED;
|
|
|
|
}
|
|
|
|
device_printf(dev,
|
2003-01-05 06:21:30 +00:00
|
|
|
"Phy 1394 only %s, %d ports.\n",
|
|
|
|
linkspeed[sc->fc.speed], sc->fc.nport);
|
2003-01-01 08:25:32 +00:00
|
|
|
}else{
|
|
|
|
reg2 = fwphy_rddata(sc, FW_PHY_ESPD_REG);
|
|
|
|
sc->fc.mode |= FWPHYASYST;
|
|
|
|
sc->fc.nport = reg & FW_PHY_NP;
|
|
|
|
sc->fc.speed = (reg2 & FW_PHY_ESPD) >> 5;
|
|
|
|
if (sc->fc.speed > MAX_SPEED) {
|
|
|
|
device_printf(dev, "invalid speed %d (fixed to %d).\n",
|
|
|
|
sc->fc.speed, MAX_SPEED);
|
|
|
|
sc->fc.speed = MAX_SPEED;
|
|
|
|
}
|
|
|
|
device_printf(dev,
|
2003-01-05 06:21:30 +00:00
|
|
|
"Phy 1394a available %s, %d ports.\n",
|
|
|
|
linkspeed[sc->fc.speed], sc->fc.nport);
|
2003-01-01 08:25:32 +00:00
|
|
|
|
|
|
|
/* check programPhyEnable */
|
|
|
|
reg2 = fwphy_rddata(sc, 5);
|
|
|
|
#if 0
|
|
|
|
if (e1394a && (OREAD(sc, OHCI_HCCCTL) & OHCI_HCC_PRPHY)) {
|
|
|
|
#else /* XXX force to enable 1394a */
|
|
|
|
if (e1394a) {
|
|
|
|
#endif
|
|
|
|
if (bootverbose)
|
|
|
|
device_printf(dev,
|
|
|
|
"Enable 1394a Enhancements\n");
|
|
|
|
/* enable EAA EMC */
|
|
|
|
reg2 |= 0x03;
|
|
|
|
/* set aPhyEnhanceEnable */
|
|
|
|
OWRITE(sc, OHCI_HCCCTL, OHCI_HCC_PHYEN);
|
|
|
|
OWRITE(sc, OHCI_HCCCTLCLR, OHCI_HCC_PRPHY);
|
|
|
|
} else {
|
|
|
|
/* for safe */
|
|
|
|
reg2 &= ~0x83;
|
|
|
|
}
|
|
|
|
reg2 = fwphy_wrdata(sc, 5, reg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
reg = fwphy_rddata(sc, FW_PHY_SPD_REG);
|
|
|
|
if((reg >> 5) == 7 ){
|
|
|
|
reg = fwphy_rddata(sc, 4);
|
|
|
|
reg |= 1 << 6;
|
|
|
|
fwphy_wrdata(sc, 4, reg);
|
|
|
|
reg = fwphy_rddata(sc, 4);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
fwohci_reset(struct fwohci_softc *sc, device_t dev)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-01-05 06:21:30 +00:00
|
|
|
int i, max_rec, speed;
|
2002-09-13 12:31:56 +00:00
|
|
|
u_int32_t reg, reg2;
|
|
|
|
struct fwohcidb_tr *db_tr;
|
2003-01-01 08:25:32 +00:00
|
|
|
|
2003-01-05 06:21:30 +00:00
|
|
|
/* Disable interrupt */
|
2003-01-01 08:25:32 +00:00
|
|
|
OWRITE(sc, FWOHCI_INTMASKCLR, ~0);
|
|
|
|
|
2003-01-05 06:21:30 +00:00
|
|
|
/* Now stopping all DMA channel */
|
2003-01-01 08:25:32 +00:00
|
|
|
OWRITE(sc, OHCI_ARQCTLCLR, OHCI_CNTL_DMA_RUN);
|
|
|
|
OWRITE(sc, OHCI_ARSCTLCLR, OHCI_CNTL_DMA_RUN);
|
|
|
|
OWRITE(sc, OHCI_ATQCTLCLR, OHCI_CNTL_DMA_RUN);
|
|
|
|
OWRITE(sc, OHCI_ATSCTLCLR, OHCI_CNTL_DMA_RUN);
|
|
|
|
|
|
|
|
OWRITE(sc, OHCI_IR_MASKCLR, ~0);
|
|
|
|
for( i = 0 ; i < sc->fc.nisodma ; i ++ ){
|
|
|
|
OWRITE(sc, OHCI_IRCTLCLR(i), OHCI_CNTL_DMA_RUN);
|
|
|
|
OWRITE(sc, OHCI_ITCTLCLR(i), OHCI_CNTL_DMA_RUN);
|
|
|
|
}
|
|
|
|
|
2003-01-05 06:21:30 +00:00
|
|
|
/* FLUSH FIFO and reset Transmitter/Reciever */
|
2003-01-01 08:25:32 +00:00
|
|
|
OWRITE(sc, OHCI_HCCCTL, OHCI_HCC_RESET);
|
|
|
|
if (bootverbose)
|
|
|
|
device_printf(dev, "resetting OHCI...");
|
|
|
|
i = 0;
|
|
|
|
while(OREAD(sc, OHCI_HCCCTL) & OHCI_HCC_RESET) {
|
|
|
|
if (i++ > 100) break;
|
|
|
|
DELAY(1000);
|
|
|
|
}
|
|
|
|
if (bootverbose)
|
|
|
|
printf("done (loop=%d)\n", i);
|
|
|
|
|
2003-01-05 06:21:30 +00:00
|
|
|
/* Probe phy */
|
|
|
|
fwohci_probe_phy(sc, dev);
|
|
|
|
|
|
|
|
/* Probe link */
|
2003-01-01 08:25:32 +00:00
|
|
|
reg = OREAD(sc, OHCI_BUS_OPT);
|
|
|
|
reg2 = reg | OHCI_BUSFNC;
|
2003-01-05 06:21:30 +00:00
|
|
|
max_rec = (reg & 0x0000f000) >> 12;
|
|
|
|
speed = (reg & 0x00000007);
|
|
|
|
device_printf(dev, "Link %s, max_rec %d bytes.\n",
|
|
|
|
linkspeed[speed], MAXREC(max_rec));
|
|
|
|
/* XXX fix max_rec */
|
|
|
|
sc->fc.maxrec = sc->fc.speed + 8;
|
|
|
|
if (max_rec != sc->fc.maxrec) {
|
|
|
|
reg2 = (reg2 & 0xffff0fff) | (sc->fc.maxrec << 12);
|
|
|
|
device_printf(dev, "max_rec %d -> %d\n",
|
|
|
|
MAXREC(max_rec), MAXREC(sc->fc.maxrec));
|
|
|
|
}
|
2003-01-01 08:25:32 +00:00
|
|
|
if (bootverbose)
|
|
|
|
device_printf(dev, "BUS_OPT 0x%x -> 0x%x\n", reg, reg2);
|
|
|
|
OWRITE(sc, OHCI_BUS_OPT, reg2);
|
|
|
|
|
2003-01-05 06:21:30 +00:00
|
|
|
/* Initialize registers */
|
2003-01-01 08:25:32 +00:00
|
|
|
OWRITE(sc, OHCI_CROMHDR, sc->fc.config_rom[0]);
|
|
|
|
OWRITE(sc, OHCI_CROMPTR, vtophys(&sc->fc.config_rom[0]));
|
|
|
|
OWRITE(sc, OHCI_HCCCTLCLR, OHCI_HCC_BIGEND);
|
|
|
|
OWRITE(sc, OHCI_HCCCTL, OHCI_HCC_POSTWR);
|
2003-01-04 06:40:57 +00:00
|
|
|
OWRITE(sc, OHCI_SID_BUF, vtophys(sc->fc.sid_buf));
|
2003-01-01 08:25:32 +00:00
|
|
|
OWRITE(sc, OHCI_LNKCTL, OHCI_CNTL_SID);
|
2003-01-05 06:21:30 +00:00
|
|
|
fw_busreset(&sc->fc);
|
2003-01-01 08:25:32 +00:00
|
|
|
|
2003-01-05 06:21:30 +00:00
|
|
|
/* Enable link */
|
2003-01-01 08:25:32 +00:00
|
|
|
OWRITE(sc, OHCI_HCCCTL, OHCI_HCC_LINKEN);
|
2003-01-04 06:40:57 +00:00
|
|
|
|
2003-01-05 06:21:30 +00:00
|
|
|
/* Force to start async RX DMA */
|
2003-01-04 06:40:57 +00:00
|
|
|
sc->arrq.xferq.flag &= ~FWXFERQ_RUNNING;
|
|
|
|
sc->arrs.xferq.flag &= ~FWXFERQ_RUNNING;
|
2003-01-01 08:25:32 +00:00
|
|
|
fwohci_rx_enable(sc, &sc->arrq);
|
|
|
|
fwohci_rx_enable(sc, &sc->arrs);
|
|
|
|
|
2003-01-05 06:21:30 +00:00
|
|
|
/* Initialize async TX */
|
|
|
|
OWRITE(sc, OHCI_ATQCTLCLR, OHCI_CNTL_DMA_RUN | OHCI_CNTL_DMA_DEAD);
|
|
|
|
OWRITE(sc, OHCI_ATSCTLCLR, OHCI_CNTL_DMA_RUN | OHCI_CNTL_DMA_DEAD);
|
|
|
|
/* AT Retries */
|
|
|
|
OWRITE(sc, FWOHCI_RETRY,
|
|
|
|
/* CycleLimit PhyRespRetries ATRespRetries ATReqRetries */
|
|
|
|
(0xffff << 16 ) | (0x0f << 8) | (0x0f << 4) | 0x0f) ;
|
2003-01-01 08:25:32 +00:00
|
|
|
for( i = 0, db_tr = sc->atrq.top; i < sc->atrq.ndb ;
|
|
|
|
i ++, db_tr = STAILQ_NEXT(db_tr, link)){
|
|
|
|
db_tr->xfer = NULL;
|
|
|
|
}
|
|
|
|
for( i = 0, db_tr = sc->atrs.top; i < sc->atrs.ndb ;
|
|
|
|
i ++, db_tr = STAILQ_NEXT(db_tr, link)){
|
|
|
|
db_tr->xfer = NULL;
|
|
|
|
}
|
|
|
|
|
2003-01-05 06:21:30 +00:00
|
|
|
|
|
|
|
/* Enable interrupt */
|
2003-01-01 08:25:32 +00:00
|
|
|
OWRITE(sc, FWOHCI_INTMASK,
|
|
|
|
OHCI_INT_ERR | OHCI_INT_PHY_SID
|
|
|
|
| OHCI_INT_DMA_ATRQ | OHCI_INT_DMA_ATRS
|
|
|
|
| OHCI_INT_DMA_PRRQ | OHCI_INT_DMA_PRRS
|
|
|
|
| OHCI_INT_PHY_BUS_R | OHCI_INT_PW_ERR);
|
|
|
|
fwohci_set_intr(&sc->fc, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fwohci_init(struct fwohci_softc *sc, device_t dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u_int32_t reg;
|
2003-01-25 14:47:33 +00:00
|
|
|
u_int8_t ui[8];
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
reg = OREAD(sc, OHCI_VERSION);
|
|
|
|
device_printf(dev, "OHCI version %x.%x (ROM=%d)\n",
|
|
|
|
(reg>>16) & 0xff, reg & 0xff, (reg>>24) & 1);
|
|
|
|
|
|
|
|
/* XXX: Available Isochrounous DMA channel probe */
|
|
|
|
for( i = 0 ; i < 0x20 ; i ++ ){
|
|
|
|
OWRITE(sc, OHCI_IRCTL(i), OHCI_CNTL_DMA_RUN);
|
|
|
|
reg = OREAD(sc, OHCI_IRCTL(i));
|
|
|
|
if(!(reg & OHCI_CNTL_DMA_RUN)) break;
|
|
|
|
OWRITE(sc, OHCI_ITCTL(i), OHCI_CNTL_DMA_RUN);
|
|
|
|
reg = OREAD(sc, OHCI_ITCTL(i));
|
|
|
|
if(!(reg & OHCI_CNTL_DMA_RUN)) break;
|
|
|
|
}
|
|
|
|
sc->fc.nisodma = i;
|
|
|
|
device_printf(dev, "No. of Isochronous channel is %d.\n", i);
|
|
|
|
|
|
|
|
sc->fc.arq = &sc->arrq.xferq;
|
|
|
|
sc->fc.ars = &sc->arrs.xferq;
|
|
|
|
sc->fc.atq = &sc->atrq.xferq;
|
|
|
|
sc->fc.ats = &sc->atrs.xferq;
|
|
|
|
|
|
|
|
sc->arrq.xferq.start = NULL;
|
|
|
|
sc->arrs.xferq.start = NULL;
|
|
|
|
sc->atrq.xferq.start = fwohci_start_atq;
|
|
|
|
sc->atrs.xferq.start = fwohci_start_ats;
|
|
|
|
|
|
|
|
sc->arrq.xferq.drain = NULL;
|
|
|
|
sc->arrs.xferq.drain = NULL;
|
|
|
|
sc->atrq.xferq.drain = fwohci_drain_atq;
|
|
|
|
sc->atrs.xferq.drain = fwohci_drain_ats;
|
|
|
|
|
|
|
|
sc->arrq.ndesc = 1;
|
|
|
|
sc->arrs.ndesc = 1;
|
2003-01-04 10:21:11 +00:00
|
|
|
sc->atrq.ndesc = 6; /* equal to maximum of mbuf chains */
|
|
|
|
sc->atrs.ndesc = 6 / 2;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
sc->arrq.ndb = NDB;
|
|
|
|
sc->arrs.ndb = NDB / 2;
|
|
|
|
sc->atrq.ndb = NDB;
|
|
|
|
sc->atrs.ndb = NDB / 2;
|
|
|
|
|
|
|
|
sc->arrq.dummy = NULL;
|
|
|
|
sc->arrs.dummy = NULL;
|
|
|
|
sc->atrq.dummy = NULL;
|
|
|
|
sc->atrs.dummy = NULL;
|
|
|
|
for( i = 0 ; i < sc->fc.nisodma ; i ++ ){
|
|
|
|
sc->fc.it[i] = &sc->it[i].xferq;
|
|
|
|
sc->fc.ir[i] = &sc->ir[i].xferq;
|
|
|
|
sc->it[i].ndb = 0;
|
|
|
|
sc->ir[i].ndb = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->fc.tcode = tinfo;
|
|
|
|
|
2003-01-16 13:09:33 +00:00
|
|
|
sc->cromptr = (u_int32_t *) malloc(CROMSIZE * 2, M_DEVBUF, M_NOWAIT);
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
if(sc->cromptr == NULL){
|
2003-01-01 04:23:54 +00:00
|
|
|
device_printf(dev, "cromptr alloc failed.");
|
2002-09-13 12:31:56 +00:00
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
sc->fc.dev = dev;
|
|
|
|
sc->fc.config_rom = &(sc->cromptr[CROMSIZE/4]);
|
|
|
|
|
|
|
|
sc->fc.config_rom[1] = 0x31333934;
|
|
|
|
sc->fc.config_rom[2] = 0xf000a002;
|
|
|
|
sc->fc.config_rom[3] = OREAD(sc, OHCI_EUID_HI);
|
|
|
|
sc->fc.config_rom[4] = OREAD(sc, OHCI_EUID_LO);
|
|
|
|
sc->fc.config_rom[5] = 0;
|
|
|
|
sc->fc.config_rom[0] = (4 << 24) | (5 << 16);
|
|
|
|
|
|
|
|
sc->fc.config_rom[0] |= fw_crc16(&sc->fc.config_rom[1], 5*4);
|
|
|
|
|
|
|
|
|
|
|
|
/* SID recieve buffer must allign 2^11 */
|
|
|
|
#define OHCI_SIDSIZE (1 << 11)
|
2003-01-16 13:09:33 +00:00
|
|
|
sc->fc.sid_buf = (u_int32_t *) malloc(OHCI_SIDSIZE, M_DEVBUF, M_NOWAIT);
|
2003-01-01 04:23:54 +00:00
|
|
|
if (sc->fc.sid_buf == NULL) {
|
|
|
|
device_printf(dev, "sid_buf alloc failed.\n");
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
2003-01-23 13:34:40 +00:00
|
|
|
if (((u_int32_t) sc->fc.sid_buf & (OHCI_SIDSIZE - 1)) != 0) {
|
|
|
|
device_printf(dev, "sid_buf(%p) not aligned.\n",
|
|
|
|
sc->fc.sid_buf);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
2003-01-01 08:25:32 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
fwohci_db_init(&sc->arrq);
|
2003-01-01 04:23:54 +00:00
|
|
|
if ((sc->arrq.flags & FWOHCI_DBCH_INIT) == 0)
|
|
|
|
return ENOMEM;
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
fwohci_db_init(&sc->arrs);
|
2003-01-01 04:23:54 +00:00
|
|
|
if ((sc->arrs.flags & FWOHCI_DBCH_INIT) == 0)
|
|
|
|
return ENOMEM;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
fwohci_db_init(&sc->atrq);
|
2003-01-01 04:23:54 +00:00
|
|
|
if ((sc->atrq.flags & FWOHCI_DBCH_INIT) == 0)
|
|
|
|
return ENOMEM;
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
fwohci_db_init(&sc->atrs);
|
2003-01-01 04:23:54 +00:00
|
|
|
if ((sc->atrs.flags & FWOHCI_DBCH_INIT) == 0)
|
|
|
|
return ENOMEM;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-01-25 14:47:33 +00:00
|
|
|
sc->fc.eui.hi = OREAD(sc, FWOHCIGUID_H);
|
|
|
|
sc->fc.eui.lo = OREAD(sc, FWOHCIGUID_L);
|
|
|
|
for( i = 0 ; i < 8 ; i ++)
|
|
|
|
ui[i] = FW_EUI64_BYTE(&sc->fc.eui,i);
|
2002-09-13 12:31:56 +00:00
|
|
|
device_printf(dev, "EUI64 %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
|
2003-01-25 14:47:33 +00:00
|
|
|
ui[0], ui[1], ui[2], ui[3], ui[4], ui[5], ui[6], ui[7]);
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
sc->fc.ioctl = fwohci_ioctl;
|
|
|
|
sc->fc.cyctimer = fwohci_cyctimer;
|
|
|
|
sc->fc.set_bmr = fwohci_set_bus_manager;
|
|
|
|
sc->fc.ibr = fwohci_ibr;
|
|
|
|
sc->fc.irx_enable = fwohci_irx_enable;
|
|
|
|
sc->fc.irx_disable = fwohci_irx_disable;
|
|
|
|
|
|
|
|
sc->fc.itx_enable = fwohci_itxbuf_enable;
|
|
|
|
sc->fc.itx_disable = fwohci_itx_disable;
|
|
|
|
sc->fc.irx_post = fwohci_irx_post;
|
|
|
|
sc->fc.itx_post = NULL;
|
|
|
|
sc->fc.timeout = fwohci_timeout;
|
|
|
|
sc->fc.poll = fwohci_poll;
|
|
|
|
sc->fc.set_intr = fwohci_set_intr;
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2003-01-01 08:25:32 +00:00
|
|
|
fw_init(&sc->fc);
|
|
|
|
fwohci_reset(sc, dev);
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-01-01 08:25:32 +00:00
|
|
|
return 0;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
fwohci_timeout(void *arg)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohci_softc *sc;
|
|
|
|
|
|
|
|
sc = (struct fwohci_softc *)arg;
|
|
|
|
sc->fc.timeouthandle = timeout(fwohci_timeout,
|
|
|
|
(void *)sc, FW_XFERTIMEOUT * hz * 10);
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
u_int32_t
|
|
|
|
fwohci_cyctimer(struct firewire_comm *fc)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)fc;
|
|
|
|
return(OREAD(sc, OHCI_CYCLETIMER));
|
|
|
|
}
|
|
|
|
|
2003-01-01 04:23:54 +00:00
|
|
|
int
|
|
|
|
fwohci_detach(struct fwohci_softc *sc, device_t dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (sc->fc.sid_buf != NULL)
|
2003-01-16 13:09:33 +00:00
|
|
|
free((void *)(uintptr_t)sc->fc.sid_buf, M_DEVBUF);
|
2003-01-01 04:23:54 +00:00
|
|
|
if (sc->cromptr != NULL)
|
2003-01-16 13:09:33 +00:00
|
|
|
free((void *)sc->cromptr, M_DEVBUF);
|
2003-01-01 04:23:54 +00:00
|
|
|
|
|
|
|
fwohci_db_free(&sc->arrq);
|
|
|
|
fwohci_db_free(&sc->arrs);
|
|
|
|
|
|
|
|
fwohci_db_free(&sc->atrq);
|
|
|
|
fwohci_db_free(&sc->atrs);
|
|
|
|
|
|
|
|
for( i = 0 ; i < sc->fc.nisodma ; i ++ ){
|
|
|
|
fwohci_db_free(&sc->it[i]);
|
|
|
|
fwohci_db_free(&sc->ir[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-01-04 10:21:11 +00:00
|
|
|
#define LAST_DB(dbtr, db) do { \
|
|
|
|
struct fwohcidb_tr *_dbtr = (dbtr); \
|
|
|
|
int _cnt = _dbtr->dbcnt; \
|
|
|
|
db = &_dbtr->db[ (_cnt > 2) ? (_cnt -1) : 0]; \
|
|
|
|
} while (0)
|
|
|
|
|
2002-11-12 05:52:01 +00:00
|
|
|
static void
|
|
|
|
fwohci_start(struct fwohci_softc *sc, struct fwohci_dbch *dbch)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
int i, s;
|
|
|
|
int tcode, hdr_len, hdr_off, len;
|
|
|
|
int fsegment = -1;
|
|
|
|
u_int32_t off;
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct fw_pkt *fp;
|
|
|
|
volatile struct fwohci_txpkthdr *ohcifp;
|
|
|
|
struct fwohcidb_tr *db_tr;
|
|
|
|
volatile struct fwohcidb *db;
|
|
|
|
struct mbuf *m;
|
|
|
|
struct tcode_info *info;
|
2003-01-04 10:21:11 +00:00
|
|
|
static int maxdesc=0;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
if(&sc->atrq == dbch){
|
|
|
|
off = OHCI_ATQOFF;
|
|
|
|
}else if(&sc->atrs == dbch){
|
|
|
|
off = OHCI_ATSOFF;
|
|
|
|
}else{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dbch->flags & FWOHCI_DBCH_FULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
s = splfw();
|
|
|
|
db_tr = dbch->top;
|
|
|
|
txloop:
|
|
|
|
xfer = STAILQ_FIRST(&dbch->xferq.q);
|
|
|
|
if(xfer == NULL){
|
|
|
|
goto kick;
|
|
|
|
}
|
|
|
|
if(dbch->xferq.queued == 0 ){
|
|
|
|
device_printf(sc->fc.dev, "TX queue empty\n");
|
|
|
|
}
|
|
|
|
STAILQ_REMOVE_HEAD(&dbch->xferq.q, link);
|
|
|
|
db_tr->xfer = xfer;
|
|
|
|
xfer->state = FWXF_START;
|
|
|
|
dbch->xferq.packets++;
|
|
|
|
|
|
|
|
fp = (struct fw_pkt *)(xfer->send.buf + xfer->send.off);
|
|
|
|
tcode = fp->mode.common.tcode;
|
|
|
|
|
|
|
|
ohcifp = (volatile struct fwohci_txpkthdr *) db_tr->db[1].db.immed;
|
|
|
|
info = &tinfo[tcode];
|
|
|
|
hdr_len = hdr_off = info->hdr_len;
|
|
|
|
/* fw_asyreq must pass valid send.len */
|
|
|
|
len = xfer->send.len;
|
|
|
|
for( i = 0 ; i < hdr_off ; i+= 4){
|
|
|
|
ohcifp->mode.ld[i/4] = ntohl(fp->mode.ld[i/4]);
|
|
|
|
}
|
|
|
|
ohcifp->mode.common.spd = xfer->spd;
|
|
|
|
if (tcode == FWTCODE_STREAM ){
|
|
|
|
hdr_len = 8;
|
|
|
|
ohcifp->mode.stream.len = ntohs(fp->mode.stream.len);
|
|
|
|
} else if (tcode == FWTCODE_PHY) {
|
|
|
|
hdr_len = 12;
|
|
|
|
ohcifp->mode.ld[1] = ntohl(fp->mode.ld[1]);
|
|
|
|
ohcifp->mode.ld[2] = ntohl(fp->mode.ld[2]);
|
|
|
|
ohcifp->mode.common.spd = 0;
|
|
|
|
ohcifp->mode.common.tcode = FWOHCITCODE_PHY;
|
|
|
|
} else {
|
|
|
|
ohcifp->mode.asycomm.dst = ntohs(fp->mode.hdr.dst);
|
|
|
|
ohcifp->mode.asycomm.srcbus = OHCI_ASYSRCBUS;
|
|
|
|
ohcifp->mode.asycomm.tlrt |= FWRETRY_X;
|
|
|
|
}
|
|
|
|
db = &db_tr->db[0];
|
2003-01-26 18:38:06 +00:00
|
|
|
db->db.desc.control = OHCI_OUTPUT_MORE | OHCI_KEY_ST2;
|
|
|
|
db->db.desc.reqcount = hdr_len;
|
2002-09-13 12:31:56 +00:00
|
|
|
db->db.desc.status = 0;
|
|
|
|
/* Specify bound timer of asy. responce */
|
|
|
|
if(&sc->atrs == dbch){
|
|
|
|
db->db.desc.count
|
|
|
|
= (OREAD(sc, OHCI_CYCLETIMER) >> 12) + (1 << 13);
|
|
|
|
}
|
|
|
|
|
|
|
|
db_tr->dbcnt = 2;
|
|
|
|
db = &db_tr->db[db_tr->dbcnt];
|
|
|
|
if(len > hdr_off){
|
|
|
|
if (xfer->mbuf == NULL) {
|
|
|
|
db->db.desc.addr
|
|
|
|
= vtophys(xfer->send.buf + xfer->send.off) + hdr_off;
|
2003-01-26 18:38:06 +00:00
|
|
|
db->db.desc.control = OHCI_OUTPUT_MORE;
|
|
|
|
db->db.desc.reqcount = len - hdr_off;
|
2002-09-13 12:31:56 +00:00
|
|
|
db->db.desc.status = 0;
|
|
|
|
|
|
|
|
db_tr->dbcnt++;
|
|
|
|
} else {
|
2003-01-26 15:39:04 +00:00
|
|
|
int mchain=0;
|
2002-09-13 12:31:56 +00:00
|
|
|
/* XXX we assume mbuf chain is shorter than ndesc */
|
2003-01-04 10:21:11 +00:00
|
|
|
for (m = xfer->mbuf; m != NULL; m = m->m_next) {
|
|
|
|
if (m->m_len == 0)
|
2003-01-26 15:39:04 +00:00
|
|
|
/* unrecoverable error could occur. */
|
|
|
|
continue;
|
|
|
|
mchain++;
|
|
|
|
if (db_tr->dbcnt >= dbch->ndesc)
|
2003-01-04 10:21:11 +00:00
|
|
|
continue;
|
2002-09-13 12:31:56 +00:00
|
|
|
db->db.desc.addr
|
|
|
|
= vtophys(mtod(m, caddr_t));
|
2003-01-26 18:38:06 +00:00
|
|
|
db->db.desc.control = OHCI_OUTPUT_MORE;
|
|
|
|
db->db.desc.reqcount = m->m_len;
|
2002-09-13 12:31:56 +00:00
|
|
|
db->db.desc.status = 0;
|
|
|
|
db++;
|
|
|
|
db_tr->dbcnt++;
|
2003-01-04 10:21:11 +00:00
|
|
|
}
|
2003-01-26 15:39:04 +00:00
|
|
|
if (mchain > dbch->ndesc - 2)
|
|
|
|
device_printf(sc->fc.dev,
|
|
|
|
"dbch->ndesc(%d) is too small for"
|
|
|
|
" mbuf chain(%d), trancated.\n",
|
|
|
|
dbch->ndesc, mchain);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-04 10:21:11 +00:00
|
|
|
if (maxdesc < db_tr->dbcnt) {
|
|
|
|
maxdesc = db_tr->dbcnt;
|
|
|
|
if (bootverbose)
|
|
|
|
device_printf(sc->fc.dev, "maxdesc: %d\n", maxdesc);
|
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
/* last db */
|
|
|
|
LAST_DB(db_tr, db);
|
2003-01-26 18:38:06 +00:00
|
|
|
db->db.desc.control |= OHCI_OUTPUT_LAST
|
2002-09-13 12:31:56 +00:00
|
|
|
| OHCI_INTERRUPT_ALWAYS
|
|
|
|
| OHCI_BRANCH_ALWAYS;
|
|
|
|
db->db.desc.depend = vtophys(STAILQ_NEXT(db_tr, link)->db);
|
|
|
|
|
|
|
|
if(fsegment == -1 )
|
|
|
|
fsegment = db_tr->dbcnt;
|
|
|
|
if (dbch->pdb_tr != NULL) {
|
|
|
|
LAST_DB(dbch->pdb_tr, db);
|
|
|
|
db->db.desc.depend |= db_tr->dbcnt;
|
|
|
|
}
|
|
|
|
dbch->pdb_tr = db_tr;
|
|
|
|
db_tr = STAILQ_NEXT(db_tr, link);
|
|
|
|
if(db_tr != dbch->bottom){
|
|
|
|
goto txloop;
|
|
|
|
} else {
|
2002-12-06 02:17:30 +00:00
|
|
|
device_printf(sc->fc.dev, "fwohci_start: lack of db_trq\n");
|
2002-09-13 12:31:56 +00:00
|
|
|
dbch->flags |= FWOHCI_DBCH_FULL;
|
|
|
|
}
|
|
|
|
kick:
|
|
|
|
if (firewire_debug) printf("kick\n");
|
|
|
|
/* kick asy q */
|
|
|
|
|
|
|
|
if(dbch->xferq.flag & FWXFERQ_RUNNING) {
|
|
|
|
OWRITE(sc, OHCI_DMACTL(off), OHCI_CNTL_DMA_WAKE);
|
|
|
|
} else {
|
2002-12-06 02:17:30 +00:00
|
|
|
if (bootverbose)
|
|
|
|
device_printf(sc->fc.dev, "start AT DMA status=%x\n",
|
2002-09-13 12:31:56 +00:00
|
|
|
OREAD(sc, OHCI_DMACTL(off)));
|
|
|
|
OWRITE(sc, OHCI_DMACMD(off), vtophys(dbch->top->db) | fsegment);
|
|
|
|
OWRITE(sc, OHCI_DMACTL(off), OHCI_CNTL_DMA_RUN);
|
|
|
|
dbch->xferq.flag |= FWXFERQ_RUNNING;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
dbch->top = db_tr;
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_drain_atq(struct firewire_comm *fc, struct fw_xfer *xfer)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)fc;
|
|
|
|
fwohci_drain(&sc->fc, xfer, &(sc->atrq));
|
|
|
|
return;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_drain_ats(struct firewire_comm *fc, struct fw_xfer *xfer)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)fc;
|
|
|
|
fwohci_drain(&sc->fc, xfer, &(sc->atrs));
|
|
|
|
return;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_start_atq(struct firewire_comm *fc)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)fc;
|
|
|
|
fwohci_start( sc, &(sc->atrq));
|
|
|
|
return;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_start_ats(struct firewire_comm *fc)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)fc;
|
|
|
|
fwohci_start( sc, &(sc->atrs));
|
|
|
|
return;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
fwohci_txd(struct fwohci_softc *sc, struct fwohci_dbch *dbch)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
int s, err = 0;
|
|
|
|
struct fwohcidb_tr *tr;
|
|
|
|
volatile struct fwohcidb *db;
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
u_int32_t off;
|
|
|
|
u_int stat;
|
|
|
|
int packets;
|
|
|
|
struct firewire_comm *fc = (struct firewire_comm *)sc;
|
|
|
|
if(&sc->atrq == dbch){
|
|
|
|
off = OHCI_ATQOFF;
|
|
|
|
}else if(&sc->atrs == dbch){
|
|
|
|
off = OHCI_ATSOFF;
|
|
|
|
}else{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
s = splfw();
|
|
|
|
tr = dbch->bottom;
|
|
|
|
packets = 0;
|
|
|
|
while(dbch->xferq.queued > 0){
|
|
|
|
LAST_DB(tr, db);
|
|
|
|
if(!(db->db.desc.status & OHCI_CNTL_DMA_ACTIVE)){
|
|
|
|
if (fc->status != FWBUSRESET)
|
|
|
|
/* maybe out of order?? */
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if(db->db.desc.status & OHCI_CNTL_DMA_DEAD) {
|
|
|
|
#ifdef OHCI_DEBUG
|
|
|
|
dump_dma(sc, ch);
|
|
|
|
dump_db(sc, ch);
|
|
|
|
#endif
|
|
|
|
/* Stop DMA */
|
|
|
|
OWRITE(sc, OHCI_DMACTLCLR(off), OHCI_CNTL_DMA_RUN);
|
|
|
|
device_printf(sc->fc.dev, "force reset AT FIFO\n");
|
|
|
|
OWRITE(sc, OHCI_HCCCTLCLR, OHCI_HCC_LINKEN);
|
|
|
|
OWRITE(sc, OHCI_HCCCTL, OHCI_HCC_LPS | OHCI_HCC_LINKEN);
|
|
|
|
OWRITE(sc, OHCI_DMACTLCLR(off), OHCI_CNTL_DMA_RUN);
|
|
|
|
}
|
|
|
|
stat = db->db.desc.status & FWOHCIEV_MASK;
|
|
|
|
switch(stat){
|
|
|
|
case FWOHCIEV_ACKCOMPL:
|
|
|
|
case FWOHCIEV_ACKPEND:
|
|
|
|
err = 0;
|
|
|
|
break;
|
|
|
|
case FWOHCIEV_ACKBSA:
|
|
|
|
case FWOHCIEV_ACKBSB:
|
|
|
|
device_printf(sc->fc.dev, "txd err=%2x %s\n", stat, fwohcicode[stat]);
|
|
|
|
case FWOHCIEV_ACKBSX:
|
|
|
|
err = EBUSY;
|
|
|
|
break;
|
|
|
|
case FWOHCIEV_FLUSHED:
|
|
|
|
case FWOHCIEV_ACKTARD:
|
|
|
|
device_printf(sc->fc.dev, "txd err=%2x %s\n", stat, fwohcicode[stat]);
|
|
|
|
err = EAGAIN;
|
|
|
|
break;
|
|
|
|
case FWOHCIEV_MISSACK:
|
|
|
|
case FWOHCIEV_UNDRRUN:
|
|
|
|
case FWOHCIEV_OVRRUN:
|
|
|
|
case FWOHCIEV_DESCERR:
|
|
|
|
case FWOHCIEV_DTRDERR:
|
|
|
|
case FWOHCIEV_TIMEOUT:
|
|
|
|
case FWOHCIEV_TCODERR:
|
|
|
|
case FWOHCIEV_UNKNOWN:
|
|
|
|
case FWOHCIEV_ACKDERR:
|
|
|
|
case FWOHCIEV_ACKTERR:
|
|
|
|
default:
|
|
|
|
device_printf(sc->fc.dev, "txd err=%2x %s\n",
|
|
|
|
stat, fwohcicode[stat]);
|
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(tr->xfer != NULL){
|
|
|
|
xfer = tr->xfer;
|
|
|
|
xfer->state = FWXF_SENT;
|
|
|
|
if(err == EBUSY && fc->status != FWBUSRESET){
|
|
|
|
xfer->state = FWXF_BUSY;
|
|
|
|
switch(xfer->act_type){
|
|
|
|
case FWACT_XFER:
|
|
|
|
xfer->resp = err;
|
|
|
|
if(xfer->retry_req != NULL){
|
|
|
|
xfer->retry_req(xfer);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if( stat != FWOHCIEV_ACKPEND){
|
|
|
|
if (stat != FWOHCIEV_ACKCOMPL)
|
|
|
|
xfer->state = FWXF_SENTERR;
|
|
|
|
xfer->resp = err;
|
|
|
|
switch(xfer->act_type){
|
|
|
|
case FWACT_XFER:
|
|
|
|
fw_xfer_done(xfer);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dbch->xferq.queued --;
|
|
|
|
}
|
|
|
|
tr->xfer = NULL;
|
|
|
|
|
|
|
|
packets ++;
|
|
|
|
tr = STAILQ_NEXT(tr, link);
|
|
|
|
dbch->bottom = tr;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
if ((dbch->flags & FWOHCI_DBCH_FULL) && packets > 0) {
|
|
|
|
printf("make free slot\n");
|
|
|
|
dbch->flags &= ~FWOHCI_DBCH_FULL;
|
|
|
|
fwohci_start(sc, dbch);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_drain(struct firewire_comm *fc, struct fw_xfer *xfer, struct fwohci_dbch *dbch)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
int i, s;
|
|
|
|
struct fwohcidb_tr *tr;
|
|
|
|
|
|
|
|
if(xfer->state != FWXF_START) return;
|
|
|
|
|
|
|
|
s = splfw();
|
|
|
|
tr = dbch->bottom;
|
|
|
|
for( i = 0 ; i <= dbch->xferq.queued ; i ++){
|
|
|
|
if(tr->xfer == xfer){
|
|
|
|
s = splfw();
|
|
|
|
tr->xfer = NULL;
|
|
|
|
dbch->xferq.queued --;
|
|
|
|
#if 1
|
|
|
|
/* XXX */
|
|
|
|
if (tr == dbch->bottom)
|
|
|
|
dbch->bottom = STAILQ_NEXT(tr, link);
|
|
|
|
#endif
|
|
|
|
if (dbch->flags & FWOHCI_DBCH_FULL) {
|
|
|
|
printf("fwohci_drain: make slot\n");
|
|
|
|
dbch->flags &= ~FWOHCI_DBCH_FULL;
|
|
|
|
fwohci_start((struct fwohci_softc *)fc, dbch);
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tr = STAILQ_NEXT(tr, link);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-11-12 05:52:01 +00:00
|
|
|
static void
|
|
|
|
fwohci_db_free(struct fwohci_dbch *dbch)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohcidb_tr *db_tr;
|
2003-01-16 13:09:33 +00:00
|
|
|
int idb, i;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-01-01 04:23:54 +00:00
|
|
|
if ((dbch->flags & FWOHCI_DBCH_INIT) == 0)
|
|
|
|
return;
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
if(!(dbch->xferq.flag & FWXFERQ_EXTBUF)){
|
|
|
|
for(db_tr = STAILQ_FIRST(&dbch->db_trq), idb = 0;
|
|
|
|
idb < dbch->ndb;
|
|
|
|
db_tr = STAILQ_NEXT(db_tr, link), idb++){
|
2003-01-01 04:23:54 +00:00
|
|
|
if (db_tr->buf != NULL) {
|
|
|
|
free(db_tr->buf, M_DEVBUF);
|
|
|
|
db_tr->buf = NULL;
|
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dbch->ndb = 0;
|
|
|
|
db_tr = STAILQ_FIRST(&dbch->db_trq);
|
2003-01-16 13:09:33 +00:00
|
|
|
for (i = 0; i < dbch->npages; i++)
|
|
|
|
free(dbch->pages[i], M_DEVBUF);
|
2002-09-13 12:31:56 +00:00
|
|
|
free(db_tr, M_DEVBUF);
|
|
|
|
STAILQ_INIT(&dbch->db_trq);
|
2003-01-01 04:23:54 +00:00
|
|
|
dbch->flags &= ~FWOHCI_DBCH_INIT;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_db_init(struct fwohci_dbch *dbch)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
int idb;
|
|
|
|
struct fwohcidb_tr *db_tr;
|
2003-01-16 13:09:33 +00:00
|
|
|
int ndbpp, i, j;
|
2003-01-04 06:40:57 +00:00
|
|
|
|
|
|
|
if ((dbch->flags & FWOHCI_DBCH_INIT) != 0)
|
|
|
|
goto out;
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/* allocate DB entries and attach one to each DMA channels */
|
|
|
|
/* DB entry must start at 16 bytes bounary. */
|
|
|
|
STAILQ_INIT(&dbch->db_trq);
|
|
|
|
db_tr = (struct fwohcidb_tr *)
|
|
|
|
malloc(sizeof(struct fwohcidb_tr) * dbch->ndb,
|
2003-01-17 15:15:21 +00:00
|
|
|
M_DEVBUF, M_NOWAIT | M_ZERO);
|
2002-09-13 12:31:56 +00:00
|
|
|
if(db_tr == NULL){
|
2003-01-16 13:09:33 +00:00
|
|
|
printf("fwohci_db_init: malloc(1) failed\n");
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-01-16 13:09:33 +00:00
|
|
|
|
|
|
|
ndbpp = PAGE_SIZE / (sizeof(struct fwohcidb) * dbch->ndesc);
|
|
|
|
dbch->npages = (dbch->ndb + ndbpp - 1)/ ndbpp;
|
2003-01-17 03:52:48 +00:00
|
|
|
if (firewire_debug)
|
|
|
|
printf("ndesc: %d, ndbpp: %d, ndb: %d, npages: %d\n",
|
|
|
|
dbch->ndesc, ndbpp, dbch->ndb, dbch->npages);
|
2003-01-16 13:09:33 +00:00
|
|
|
if (dbch->npages > FWOHCI_DBCH_MAX_PAGES) {
|
|
|
|
printf("npages(%d) > DBCH_MAX_PAGES(%d)\n",
|
|
|
|
dbch->npages, FWOHCI_DBCH_MAX_PAGES);
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-01-16 13:09:33 +00:00
|
|
|
for (i = 0; i < dbch->npages; i++) {
|
|
|
|
dbch->pages[i] = malloc(PAGE_SIZE, M_DEVBUF,
|
2003-01-17 15:15:21 +00:00
|
|
|
M_NOWAIT | M_ZERO);
|
2003-01-16 13:09:33 +00:00
|
|
|
if (dbch->pages[i] == NULL) {
|
|
|
|
printf("fwohci_db_init: malloc(2) failed\n");
|
|
|
|
for (j = 0; j < i; j ++)
|
|
|
|
free(dbch->pages[j], M_DEVBUF);
|
|
|
|
free(db_tr, M_DEVBUF);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
/* Attach DB to DMA ch. */
|
|
|
|
for(idb = 0 ; idb < dbch->ndb ; idb++){
|
|
|
|
db_tr->dbcnt = 0;
|
2003-01-16 13:09:33 +00:00
|
|
|
db_tr->db = (struct fwohcidb *)dbch->pages[idb/ndbpp]
|
|
|
|
+ dbch->ndesc * (idb % ndbpp);
|
2002-09-13 12:31:56 +00:00
|
|
|
STAILQ_INSERT_TAIL(&dbch->db_trq, db_tr, link);
|
2003-01-01 08:25:32 +00:00
|
|
|
if (!(dbch->xferq.flag & FWXFERQ_PACKET) &&
|
|
|
|
dbch->xferq.bnpacket != 0) {
|
|
|
|
if (idb % dbch->xferq.bnpacket == 0)
|
|
|
|
dbch->xferq.bulkxfer[idb / dbch->xferq.bnpacket
|
|
|
|
].start = (caddr_t)db_tr;
|
|
|
|
if ((idb + 1) % dbch->xferq.bnpacket == 0)
|
|
|
|
dbch->xferq.bulkxfer[idb / dbch->xferq.bnpacket
|
|
|
|
].end = (caddr_t)db_tr;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
db_tr++;
|
|
|
|
}
|
|
|
|
STAILQ_LAST(&dbch->db_trq, fwohcidb_tr,link)->link.stqe_next
|
|
|
|
= STAILQ_FIRST(&dbch->db_trq);
|
2003-01-04 06:40:57 +00:00
|
|
|
out:
|
|
|
|
dbch->frag.buf = NULL;
|
|
|
|
dbch->frag.len = 0;
|
|
|
|
dbch->frag.plen = 0;
|
|
|
|
dbch->xferq.queued = 0;
|
|
|
|
dbch->pdb_tr = NULL;
|
2002-09-13 12:31:56 +00:00
|
|
|
dbch->top = STAILQ_FIRST(&dbch->db_trq);
|
|
|
|
dbch->bottom = dbch->top;
|
2003-01-01 04:23:54 +00:00
|
|
|
dbch->flags = FWOHCI_DBCH_INIT;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
fwohci_itx_disable(struct firewire_comm *fc, int dmach)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)fc;
|
2003-01-26 15:39:04 +00:00
|
|
|
int dummy;
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
OWRITE(sc, OHCI_ITCTLCLR(dmach), OHCI_CNTL_DMA_RUN);
|
|
|
|
OWRITE(sc, OHCI_IT_MASKCLR, 1 << dmach);
|
|
|
|
OWRITE(sc, OHCI_IT_STATCLR, 1 << dmach);
|
2003-01-26 15:39:04 +00:00
|
|
|
/* XXX we cannot free buffers until the DMA really stops */
|
|
|
|
tsleep((void *)&dummy, FWPRI, "fwitxd", hz);
|
2002-09-13 12:31:56 +00:00
|
|
|
fwohci_db_free(&sc->it[dmach]);
|
|
|
|
sc->it[dmach].xferq.flag &= ~FWXFERQ_RUNNING;
|
|
|
|
return 0;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
fwohci_irx_disable(struct firewire_comm *fc, int dmach)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)fc;
|
2003-01-26 15:39:04 +00:00
|
|
|
int dummy;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
OWRITE(sc, OHCI_IRCTLCLR(dmach), OHCI_CNTL_DMA_RUN);
|
|
|
|
OWRITE(sc, OHCI_IR_MASKCLR, 1 << dmach);
|
|
|
|
OWRITE(sc, OHCI_IR_STATCLR, 1 << dmach);
|
2003-01-26 15:39:04 +00:00
|
|
|
/* XXX we cannot free buffers until the DMA really stops */
|
|
|
|
tsleep((void *)&dummy, FWPRI, "fwirxd", hz);
|
2002-09-13 12:31:56 +00:00
|
|
|
if(sc->ir[dmach].dummy != NULL){
|
|
|
|
free(sc->ir[dmach].dummy, M_DEVBUF);
|
|
|
|
}
|
|
|
|
sc->ir[dmach].dummy = NULL;
|
|
|
|
fwohci_db_free(&sc->ir[dmach]);
|
|
|
|
sc->ir[dmach].xferq.flag &= ~FWXFERQ_RUNNING;
|
|
|
|
return 0;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_irx_post (struct firewire_comm *fc , u_int32_t *qld)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
qld[0] = ntohl(qld[0]);
|
|
|
|
return;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
fwohci_irxpp_enable(struct firewire_comm *fc, int dmach)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)fc;
|
|
|
|
int err = 0;
|
|
|
|
unsigned short tag, ich;
|
|
|
|
|
|
|
|
tag = (sc->ir[dmach].xferq.flag >> 6) & 3;
|
|
|
|
ich = sc->ir[dmach].xferq.flag & 0x3f;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if(STAILQ_FIRST(&fc->ir[dmach]->q) != NULL){
|
|
|
|
wakeup(fc->ir[dmach]);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
OWRITE(sc, OHCI_IRMATCH(dmach), tagbit[tag] | ich);
|
|
|
|
if(!(sc->ir[dmach].xferq.flag & FWXFERQ_RUNNING)){
|
|
|
|
sc->ir[dmach].xferq.queued = 0;
|
|
|
|
sc->ir[dmach].ndb = NDB;
|
2003-01-16 13:09:33 +00:00
|
|
|
sc->ir[dmach].xferq.psize = PAGE_SIZE;
|
2002-09-13 12:31:56 +00:00
|
|
|
sc->ir[dmach].ndesc = 1;
|
|
|
|
fwohci_db_init(&sc->ir[dmach]);
|
2003-01-13 16:08:09 +00:00
|
|
|
if ((sc->ir[dmach].flags & FWOHCI_DBCH_INIT) == 0)
|
|
|
|
return ENOMEM;
|
2002-09-13 12:31:56 +00:00
|
|
|
err = fwohci_rx_enable(sc, &sc->ir[dmach]);
|
|
|
|
}
|
|
|
|
if(err){
|
|
|
|
device_printf(sc->fc.dev, "err in IRX setting\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if(!(OREAD(sc, OHCI_IRCTL(dmach)) & OHCI_CNTL_DMA_ACTIVE)){
|
|
|
|
OWRITE(sc, OHCI_IRCTLCLR(dmach), OHCI_CNTL_DMA_RUN);
|
|
|
|
OWRITE(sc, OHCI_IR_MASKCLR, 1 << dmach);
|
|
|
|
OWRITE(sc, OHCI_IR_STATCLR, 1 << dmach);
|
|
|
|
OWRITE(sc, OHCI_IR_MASK, 1 << dmach);
|
|
|
|
OWRITE(sc, OHCI_IRCTLCLR(dmach), 0xf8000000);
|
|
|
|
OWRITE(sc, OHCI_IRCTL(dmach), OHCI_CNTL_ISOHDR);
|
|
|
|
OWRITE(sc, OHCI_IRCMD(dmach),
|
|
|
|
vtophys(sc->ir[dmach].top->db) | 1);
|
|
|
|
OWRITE(sc, OHCI_IRCTL(dmach), OHCI_CNTL_DMA_RUN);
|
|
|
|
OWRITE(sc, FWOHCI_INTMASK, OHCI_INT_DMA_IR);
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
fwohci_tx_enable(struct fwohci_softc *sc, struct fwohci_dbch *dbch)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
int idb, z, i, dmach = 0;
|
|
|
|
u_int32_t off = NULL;
|
|
|
|
struct fwohcidb_tr *db_tr;
|
2003-01-26 18:38:06 +00:00
|
|
|
volatile struct fwohcidb *db;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
if(!(dbch->xferq.flag & FWXFERQ_EXTBUF)){
|
|
|
|
err = EINVAL;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
z = dbch->ndesc;
|
|
|
|
for(dmach = 0 ; dmach < sc->fc.nisodma ; dmach++){
|
|
|
|
if( &sc->it[dmach] == dbch){
|
|
|
|
off = OHCI_ITOFF(dmach);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(off == NULL){
|
|
|
|
err = EINVAL;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if(dbch->xferq.flag & FWXFERQ_RUNNING)
|
|
|
|
return err;
|
|
|
|
dbch->xferq.flag |= FWXFERQ_RUNNING;
|
|
|
|
for( i = 0, dbch->bottom = dbch->top; i < (dbch->ndb - 1); i++){
|
|
|
|
dbch->bottom = STAILQ_NEXT(dbch->bottom, link);
|
|
|
|
}
|
|
|
|
db_tr = dbch->top;
|
|
|
|
for( idb = 0 ; idb < dbch->ndb ; idb ++){
|
|
|
|
fwohci_add_tx_buf(db_tr,
|
|
|
|
dbch->xferq.psize, dbch->xferq.flag,
|
|
|
|
dbch->xferq.buf + dbch->xferq.psize * idb);
|
|
|
|
if(STAILQ_NEXT(db_tr, link) == NULL){
|
|
|
|
break;
|
|
|
|
}
|
2003-01-26 18:38:06 +00:00
|
|
|
db = db_tr->db;
|
|
|
|
db[0].db.desc.depend = db[db_tr->dbcnt - 1].db.desc.depend
|
2002-09-13 12:31:56 +00:00
|
|
|
= vtophys(STAILQ_NEXT(db_tr, link)->db) | z;
|
|
|
|
if(dbch->xferq.flag & FWXFERQ_EXTBUF){
|
|
|
|
if(((idb + 1 ) % dbch->xferq.bnpacket) == 0){
|
2003-01-26 18:38:06 +00:00
|
|
|
db[db_tr->dbcnt - 1].db.desc.control
|
2002-09-13 12:31:56 +00:00
|
|
|
|= OHCI_INTERRUPT_ALWAYS;
|
2003-01-15 04:21:16 +00:00
|
|
|
/* OHCI 1.1 and above */
|
2003-01-26 18:38:06 +00:00
|
|
|
db[0].db.desc.control |= OHCI_INTERRUPT_ALWAYS;
|
|
|
|
#if 0
|
|
|
|
db[0].db.desc.depend &= ~0xf;
|
|
|
|
db[db_tr->dbcnt - 1].db.desc.depend &= ~0xf;
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
db_tr = STAILQ_NEXT(db_tr, link);
|
|
|
|
}
|
|
|
|
dbch->bottom->db[db_tr->dbcnt - 1].db.desc.depend &= 0xfffffff0;
|
|
|
|
return err;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
fwohci_rx_enable(struct fwohci_softc *sc, struct fwohci_dbch *dbch)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
int err = 0;
|
2003-01-26 18:38:06 +00:00
|
|
|
int idb, z, i, dmach = 0, ldesc;
|
2002-09-13 12:31:56 +00:00
|
|
|
u_int32_t off = NULL;
|
|
|
|
struct fwohcidb_tr *db_tr;
|
2003-01-26 18:38:06 +00:00
|
|
|
volatile struct fwohcidb *db;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
z = dbch->ndesc;
|
|
|
|
if(&sc->arrq == dbch){
|
|
|
|
off = OHCI_ARQOFF;
|
|
|
|
}else if(&sc->arrs == dbch){
|
|
|
|
off = OHCI_ARSOFF;
|
|
|
|
}else{
|
|
|
|
for(dmach = 0 ; dmach < sc->fc.nisodma ; dmach++){
|
|
|
|
if( &sc->ir[dmach] == dbch){
|
|
|
|
off = OHCI_IROFF(dmach);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(off == NULL){
|
|
|
|
err = EINVAL;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if(dbch->xferq.flag & FWXFERQ_STREAM){
|
|
|
|
if(dbch->xferq.flag & FWXFERQ_RUNNING)
|
|
|
|
return err;
|
|
|
|
}else{
|
|
|
|
if(dbch->xferq.flag & FWXFERQ_RUNNING){
|
|
|
|
err = EBUSY;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dbch->xferq.flag |= FWXFERQ_RUNNING;
|
2003-01-04 06:40:57 +00:00
|
|
|
dbch->top = STAILQ_FIRST(&dbch->db_trq);
|
2002-09-13 12:31:56 +00:00
|
|
|
for( i = 0, dbch->bottom = dbch->top; i < (dbch->ndb - 1); i++){
|
|
|
|
dbch->bottom = STAILQ_NEXT(dbch->bottom, link);
|
|
|
|
}
|
|
|
|
db_tr = dbch->top;
|
|
|
|
for( idb = 0 ; idb < dbch->ndb ; idb ++){
|
|
|
|
if(!(dbch->xferq.flag & FWXFERQ_EXTBUF)){
|
|
|
|
fwohci_add_rx_buf(db_tr,
|
|
|
|
dbch->xferq.psize, dbch->xferq.flag, 0, NULL);
|
|
|
|
}else{
|
|
|
|
fwohci_add_rx_buf(db_tr,
|
|
|
|
dbch->xferq.psize, dbch->xferq.flag,
|
|
|
|
dbch->xferq.buf + dbch->xferq.psize * idb,
|
|
|
|
dbch->dummy + sizeof(u_int32_t) * idb);
|
|
|
|
}
|
|
|
|
if(STAILQ_NEXT(db_tr, link) == NULL){
|
|
|
|
break;
|
|
|
|
}
|
2003-01-26 18:38:06 +00:00
|
|
|
db = db_tr->db;
|
|
|
|
ldesc = db_tr->dbcnt - 1;
|
|
|
|
db[ldesc].db.desc.depend
|
2002-09-13 12:31:56 +00:00
|
|
|
= vtophys(STAILQ_NEXT(db_tr, link)->db) | z;
|
|
|
|
if(dbch->xferq.flag & FWXFERQ_EXTBUF){
|
|
|
|
if(((idb + 1 ) % dbch->xferq.bnpacket) == 0){
|
2003-01-26 18:38:06 +00:00
|
|
|
db[ldesc].db.desc.control
|
2002-09-13 12:31:56 +00:00
|
|
|
|= OHCI_INTERRUPT_ALWAYS;
|
2003-01-26 18:38:06 +00:00
|
|
|
db[ldesc].db.desc.depend &= ~0xf;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
db_tr = STAILQ_NEXT(db_tr, link);
|
|
|
|
}
|
|
|
|
dbch->bottom->db[db_tr->dbcnt - 1].db.desc.depend &= 0xfffffff0;
|
|
|
|
dbch->buf_offset = 0;
|
|
|
|
if(dbch->xferq.flag & FWXFERQ_STREAM){
|
|
|
|
return err;
|
|
|
|
}else{
|
|
|
|
OWRITE(sc, OHCI_DMACMD(off), vtophys(dbch->top->db) | z);
|
|
|
|
}
|
|
|
|
OWRITE(sc, OHCI_DMACTL(off), OHCI_CNTL_DMA_RUN);
|
|
|
|
return err;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2003-01-26 15:39:04 +00:00
|
|
|
static int
|
|
|
|
fwochi_next_cycle(struct firewire_comm *fc, int cycle_now)
|
|
|
|
{
|
|
|
|
int sec, cycle, cycle_match;
|
|
|
|
|
|
|
|
cycle = cycle_now & 0x1fff;
|
|
|
|
sec = cycle_now >> 13;
|
|
|
|
#define CYCLE_MOD 0x10
|
|
|
|
#define CYCLE_DELAY 8 /* min delay to start DMA */
|
|
|
|
cycle = cycle + CYCLE_DELAY;
|
|
|
|
if (cycle >= 8000) {
|
|
|
|
sec ++;
|
|
|
|
cycle -= 8000;
|
|
|
|
}
|
|
|
|
cycle = ((cycle + CYCLE_MOD - 1) / CYCLE_MOD) * CYCLE_MOD;
|
|
|
|
if (cycle >= 8000) {
|
|
|
|
sec ++;
|
|
|
|
if (cycle == 8000)
|
|
|
|
cycle = 0;
|
|
|
|
else
|
|
|
|
cycle = CYCLE_MOD;
|
|
|
|
}
|
|
|
|
cycle_match = ((sec << 13) | cycle) & 0x7ffff;
|
|
|
|
|
|
|
|
return(cycle_match);
|
|
|
|
}
|
|
|
|
|
2002-11-12 05:52:01 +00:00
|
|
|
static int
|
|
|
|
fwohci_itxbuf_enable(struct firewire_comm *fc, int dmach)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)fc;
|
|
|
|
int err = 0;
|
|
|
|
unsigned short tag, ich;
|
|
|
|
struct fwohci_dbch *dbch;
|
2003-01-26 15:39:04 +00:00
|
|
|
int cycle_match, cycle_now, s, ldesc;
|
2003-01-16 07:01:54 +00:00
|
|
|
u_int32_t stat;
|
2003-01-26 15:39:04 +00:00
|
|
|
struct fw_bulkxfer *first, *chunk, *prev;
|
|
|
|
struct fw_xferq *it;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
dbch = &sc->it[dmach];
|
2003-01-26 15:39:04 +00:00
|
|
|
it = &dbch->xferq;
|
|
|
|
|
|
|
|
tag = (it->flag >> 6) & 3;
|
|
|
|
ich = it->flag & 0x3f;
|
2003-01-13 16:08:09 +00:00
|
|
|
if ((dbch->flags & FWOHCI_DBCH_INIT) == 0) {
|
2003-01-26 15:39:04 +00:00
|
|
|
dbch->ndb = it->bnpacket * it->bnchunk;
|
2002-09-13 12:31:56 +00:00
|
|
|
dbch->ndesc = 3;
|
|
|
|
fwohci_db_init(dbch);
|
2003-01-13 16:08:09 +00:00
|
|
|
if ((dbch->flags & FWOHCI_DBCH_INIT) == 0)
|
|
|
|
return ENOMEM;
|
2002-09-13 12:31:56 +00:00
|
|
|
err = fwohci_tx_enable(sc, dbch);
|
|
|
|
}
|
|
|
|
if(err)
|
|
|
|
return err;
|
2003-01-26 15:39:04 +00:00
|
|
|
|
2003-01-26 18:38:06 +00:00
|
|
|
ldesc = dbch->ndesc - 1;
|
2003-01-26 15:39:04 +00:00
|
|
|
s = splfw();
|
|
|
|
prev = STAILQ_LAST(&it->stdma, fw_bulkxfer, link);
|
|
|
|
while ((chunk = STAILQ_FIRST(&it->stvalid)) != NULL) {
|
|
|
|
volatile struct fwohcidb *db;
|
|
|
|
|
|
|
|
fwohci_txbufdb(sc, dmach, chunk);
|
2003-01-26 18:38:06 +00:00
|
|
|
#if 0
|
2003-01-26 15:39:04 +00:00
|
|
|
db = ((struct fwohcidb_tr *)(chunk->end))->db;
|
|
|
|
db[ldesc].db.desc.status = db[0].db.desc.status = 0;
|
|
|
|
db[ldesc].db.desc.count = db[0].db.desc.count = 0;
|
|
|
|
db[ldesc].db.desc.depend &= ~0xf;
|
|
|
|
db[0].db.desc.depend &= ~0xf;
|
2003-01-26 18:38:06 +00:00
|
|
|
#endif
|
2003-01-26 15:39:04 +00:00
|
|
|
if (prev != NULL) {
|
|
|
|
db = ((struct fwohcidb_tr *)(prev->end))->db;
|
2003-01-26 18:38:06 +00:00
|
|
|
db[ldesc].db.desc.control |= OHCI_BRANCH_ALWAYS;
|
|
|
|
#if 0 /* if bulkxfer->npacket changes */
|
2003-01-26 15:39:04 +00:00
|
|
|
db[ldesc].db.desc.depend = db[0].db.desc.depend =
|
|
|
|
vtophys(((struct fwohcidb_tr *)
|
|
|
|
(chunk->start))->db) | dbch->ndesc;
|
2003-01-26 18:38:06 +00:00
|
|
|
#else
|
|
|
|
db[0].db.desc.depend |= dbch->ndesc;
|
|
|
|
db[ldesc].db.desc.depend |= dbch->ndesc;
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-01-26 15:39:04 +00:00
|
|
|
STAILQ_REMOVE_HEAD(&it->stvalid, link);
|
|
|
|
STAILQ_INSERT_TAIL(&it->stdma, chunk, link);
|
|
|
|
prev = chunk;
|
2003-01-17 03:52:48 +00:00
|
|
|
}
|
2003-01-26 15:39:04 +00:00
|
|
|
splx(s);
|
|
|
|
stat = OREAD(sc, OHCI_ITCTL(dmach));
|
|
|
|
if (stat & (OHCI_CNTL_DMA_ACTIVE | OHCI_CNTL_CYCMATCH_S))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
OWRITE(sc, OHCI_ITCTLCLR(dmach), OHCI_CNTL_DMA_RUN);
|
2003-01-17 03:52:48 +00:00
|
|
|
OWRITE(sc, OHCI_IT_MASKCLR, 1 << dmach);
|
|
|
|
OWRITE(sc, OHCI_IT_STATCLR, 1 << dmach);
|
|
|
|
OWRITE(sc, OHCI_IT_MASK, 1 << dmach);
|
2003-01-26 15:39:04 +00:00
|
|
|
|
|
|
|
first = STAILQ_FIRST(&it->stdma);
|
|
|
|
OWRITE(sc, OHCI_ITCMD(dmach), vtophys(((struct fwohcidb_tr *)
|
|
|
|
(first->start))->db) | dbch->ndesc);
|
|
|
|
if (firewire_debug)
|
|
|
|
printf("fwohci_itxbuf_enable: kick 0x%08x\n", stat);
|
2003-01-17 03:52:48 +00:00
|
|
|
if ((stat & OHCI_CNTL_DMA_RUN) == 0) {
|
2003-01-26 15:39:04 +00:00
|
|
|
#if 1
|
|
|
|
/* Don't start until all chunks are buffered */
|
|
|
|
if (STAILQ_FIRST(&it->stfree) != NULL)
|
|
|
|
goto out;
|
|
|
|
#endif
|
2003-01-24 13:03:19 +00:00
|
|
|
#ifdef FWXFERQ_DV
|
2003-01-26 15:39:04 +00:00
|
|
|
#define CYCLE_OFFSET 1
|
2002-09-13 12:31:56 +00:00
|
|
|
if(dbch->xferq.flag & FWXFERQ_DV){
|
2003-01-24 13:03:19 +00:00
|
|
|
struct fw_pkt *fp;
|
|
|
|
struct fwohcidb_tr *db_tr;
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
db_tr = (struct fwohcidb_tr *)dbch->xferq.stdma->start;
|
|
|
|
fp = (struct fw_pkt *)db_tr->buf;
|
2003-01-16 07:01:54 +00:00
|
|
|
dbch->xferq.dvoffset = CYCLE_OFFSET;
|
2003-01-13 16:08:09 +00:00
|
|
|
fp->mode.ld[2] |= htonl(dbch->xferq.dvoffset << 12);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-01-24 13:03:19 +00:00
|
|
|
#endif
|
2003-01-16 07:01:54 +00:00
|
|
|
/* Clear cycle match counter bits */
|
|
|
|
OWRITE(sc, OHCI_ITCTLCLR(dmach), 0xffff0000);
|
2003-01-26 15:39:04 +00:00
|
|
|
OWRITE(sc, FWOHCI_INTMASK, OHCI_INT_DMA_IT);
|
|
|
|
|
|
|
|
/* 2bit second + 13bit cycle */
|
|
|
|
cycle_now = (fc->cyctimer(fc) >> 12) & 0x7fff;
|
|
|
|
cycle_match = fwochi_next_cycle(fc, cycle_now);
|
|
|
|
|
2003-01-16 07:01:54 +00:00
|
|
|
OWRITE(sc, OHCI_ITCTL(dmach),
|
|
|
|
OHCI_CNTL_CYCMATCH_S | (cycle_match << 16)
|
|
|
|
| OHCI_CNTL_DMA_RUN);
|
2003-01-17 03:52:48 +00:00
|
|
|
if (firewire_debug)
|
|
|
|
printf("cycle_match: 0x%04x->0x%04x\n",
|
|
|
|
cycle_now, cycle_match);
|
|
|
|
} else if ((stat & OHCI_CNTL_CYCMATCH_S) == 0) {
|
2003-01-26 15:39:04 +00:00
|
|
|
device_printf(sc->fc.dev,
|
|
|
|
"IT DMA underrun (0x%08x)\n", stat);
|
2003-01-17 03:52:48 +00:00
|
|
|
OWRITE(sc, OHCI_ITCTL(dmach), OHCI_CNTL_DMA_RUN);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-01-26 15:39:04 +00:00
|
|
|
out:
|
2002-09-13 12:31:56 +00:00
|
|
|
return err;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
fwohci_irxbuf_enable(struct firewire_comm *fc, int dmach)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)fc;
|
2003-01-26 15:39:04 +00:00
|
|
|
int err = 0, s, ldesc;
|
2002-09-13 12:31:56 +00:00
|
|
|
unsigned short tag, ich;
|
2003-01-23 13:34:40 +00:00
|
|
|
u_int32_t stat;
|
2003-01-26 15:39:04 +00:00
|
|
|
struct fwohci_dbch *dbch;
|
|
|
|
struct fw_bulkxfer *first, *prev, *chunk;
|
|
|
|
struct fw_xferq *ir;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-01-26 15:39:04 +00:00
|
|
|
dbch = &sc->ir[dmach];
|
|
|
|
ir = &dbch->xferq;
|
|
|
|
ldesc = dbch->ndesc - 1;
|
|
|
|
|
|
|
|
if ((ir->flag & FWXFERQ_RUNNING) == 0) {
|
|
|
|
tag = (ir->flag >> 6) & 3;
|
|
|
|
ich = ir->flag & 0x3f;
|
2003-01-09 10:25:07 +00:00
|
|
|
OWRITE(sc, OHCI_IRMATCH(dmach), tagbit[tag] | ich);
|
|
|
|
|
2003-01-26 15:39:04 +00:00
|
|
|
ir->queued = 0;
|
|
|
|
dbch->ndb = ir->bnpacket * ir->bnchunk;
|
|
|
|
dbch->dummy = malloc(sizeof(u_int32_t) * dbch->ndb,
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
|
|
|
if (dbch->dummy == NULL) {
|
2002-09-13 12:31:56 +00:00
|
|
|
err = ENOMEM;
|
|
|
|
return err;
|
|
|
|
}
|
2003-01-26 15:39:04 +00:00
|
|
|
dbch->ndesc = 2;
|
|
|
|
fwohci_db_init(dbch);
|
|
|
|
if ((dbch->flags & FWOHCI_DBCH_INIT) == 0)
|
2003-01-13 16:08:09 +00:00
|
|
|
return ENOMEM;
|
2003-01-26 15:39:04 +00:00
|
|
|
err = fwohci_rx_enable(sc, dbch);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
if(err)
|
|
|
|
return err;
|
|
|
|
|
2003-01-26 15:39:04 +00:00
|
|
|
s = splfw();
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-01-26 15:39:04 +00:00
|
|
|
first = STAILQ_FIRST(&ir->stfree);
|
|
|
|
if (first == NULL) {
|
|
|
|
device_printf(fc->dev, "IR DMA no free chunk\n");
|
|
|
|
splx(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = STAILQ_LAST(&ir->stdma, fw_bulkxfer, link);
|
|
|
|
while ((chunk = STAILQ_FIRST(&ir->stfree)) != NULL) {
|
|
|
|
volatile struct fwohcidb *db;
|
|
|
|
|
|
|
|
db = ((struct fwohcidb_tr *)(chunk->end))->db;
|
|
|
|
db[ldesc].db.desc.status = db[ldesc].db.desc.count = 0;
|
|
|
|
db[ldesc].db.desc.depend &= ~0xf;
|
|
|
|
if (prev != NULL) {
|
|
|
|
db = ((struct fwohcidb_tr *)(prev->end))->db;
|
2003-01-26 18:38:06 +00:00
|
|
|
#if 0
|
2003-01-26 15:39:04 +00:00
|
|
|
db[ldesc].db.desc.depend =
|
|
|
|
vtophys(((struct fwohcidb_tr *)
|
|
|
|
(chunk->start))->db) | dbch->ndesc;
|
2003-01-26 18:38:06 +00:00
|
|
|
#else
|
|
|
|
db[ldesc].db.desc.depend |= dbch->ndesc;
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-01-26 15:39:04 +00:00
|
|
|
STAILQ_REMOVE_HEAD(&ir->stfree, link);
|
|
|
|
STAILQ_INSERT_TAIL(&ir->stdma, chunk, link);
|
|
|
|
prev = chunk;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
stat = OREAD(sc, OHCI_IRCTL(dmach));
|
|
|
|
if (stat & OHCI_CNTL_DMA_ACTIVE)
|
|
|
|
return 0;
|
|
|
|
if (stat & OHCI_CNTL_DMA_RUN) {
|
|
|
|
OWRITE(sc, OHCI_IRCTLCLR(dmach), OHCI_CNTL_DMA_RUN);
|
|
|
|
device_printf(sc->fc.dev, "IR DMA overrun (0x%08x)\n", stat);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-01-26 15:39:04 +00:00
|
|
|
|
|
|
|
OWRITE(sc, OHCI_IR_MASKCLR, 1 << dmach);
|
|
|
|
OWRITE(sc, OHCI_IR_STATCLR, 1 << dmach);
|
|
|
|
OWRITE(sc, OHCI_IR_MASK, 1 << dmach);
|
|
|
|
OWRITE(sc, OHCI_IRCTLCLR(dmach), 0xf0000000);
|
|
|
|
OWRITE(sc, OHCI_IRCTL(dmach), OHCI_CNTL_ISOHDR);
|
|
|
|
OWRITE(sc, OHCI_IRCMD(dmach),
|
|
|
|
vtophys(((struct fwohcidb_tr *)(first->start))->db)
|
|
|
|
| dbch->ndesc);
|
|
|
|
OWRITE(sc, OHCI_IRCTL(dmach), OHCI_CNTL_DMA_RUN);
|
|
|
|
OWRITE(sc, FWOHCI_INTMASK, OHCI_INT_DMA_IR);
|
2002-09-13 12:31:56 +00:00
|
|
|
return err;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
fwohci_irx_enable(struct firewire_comm *fc, int dmach)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)fc;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if(sc->ir[dmach].xferq.flag & FWXFERQ_PACKET){
|
|
|
|
err = fwohci_irxpp_enable(fc, dmach);
|
|
|
|
return err;
|
|
|
|
}else{
|
|
|
|
err = fwohci_irxbuf_enable(fc, dmach);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
int
|
2003-01-04 06:40:57 +00:00
|
|
|
fwohci_shutdown(struct fwohci_softc *sc, device_t dev)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
/* Now stopping all DMA channel */
|
|
|
|
OWRITE(sc, OHCI_ARQCTLCLR, OHCI_CNTL_DMA_RUN);
|
|
|
|
OWRITE(sc, OHCI_ARSCTLCLR, OHCI_CNTL_DMA_RUN);
|
|
|
|
OWRITE(sc, OHCI_ATQCTLCLR, OHCI_CNTL_DMA_RUN);
|
|
|
|
OWRITE(sc, OHCI_ATSCTLCLR, OHCI_CNTL_DMA_RUN);
|
|
|
|
|
|
|
|
for( i = 0 ; i < sc->fc.nisodma ; i ++ ){
|
|
|
|
OWRITE(sc, OHCI_IRCTLCLR(i), OHCI_CNTL_DMA_RUN);
|
|
|
|
OWRITE(sc, OHCI_ITCTLCLR(i), OHCI_CNTL_DMA_RUN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FLUSH FIFO and reset Transmitter/Reciever */
|
|
|
|
OWRITE(sc, OHCI_HCCCTL, OHCI_HCC_RESET);
|
|
|
|
|
|
|
|
/* Stop interrupt */
|
|
|
|
OWRITE(sc, FWOHCI_INTMASKCLR,
|
|
|
|
OHCI_INT_EN | OHCI_INT_ERR | OHCI_INT_PHY_SID
|
|
|
|
| OHCI_INT_PHY_INT
|
|
|
|
| OHCI_INT_DMA_ATRQ | OHCI_INT_DMA_ATRS
|
|
|
|
| OHCI_INT_DMA_PRRQ | OHCI_INT_DMA_PRRS
|
|
|
|
| OHCI_INT_DMA_ARRQ | OHCI_INT_DMA_ARRS
|
|
|
|
| OHCI_INT_PHY_BUS_R);
|
2003-01-04 06:40:57 +00:00
|
|
|
/* XXX Link down? Bus reset? */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fwohci_resume(struct fwohci_softc *sc, device_t dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
fwohci_reset(sc, dev);
|
|
|
|
/* XXX resume isochronus receive automatically. (how about TX?) */
|
|
|
|
for(i = 0; i < sc->fc.nisodma; i ++) {
|
|
|
|
if((sc->ir[i].xferq.flag & FWXFERQ_RUNNING) != 0) {
|
|
|
|
device_printf(sc->fc.dev,
|
|
|
|
"resume iso receive ch: %d\n", i);
|
|
|
|
sc->ir[i].xferq.flag &= ~FWXFERQ_RUNNING;
|
|
|
|
sc->fc.irx_enable(&sc->fc, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bus_generic_resume(dev);
|
|
|
|
sc->fc.ibr(&sc->fc);
|
2002-09-13 12:31:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ACK_ALL
|
|
|
|
static void
|
2002-11-12 04:54:30 +00:00
|
|
|
fwohci_intr_body(struct fwohci_softc *sc, u_int32_t stat, int count)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
u_int32_t irstat, itstat;
|
|
|
|
u_int i;
|
|
|
|
struct firewire_comm *fc = (struct firewire_comm *)sc;
|
|
|
|
|
|
|
|
#ifdef OHCI_DEBUG
|
|
|
|
if(stat & OREAD(sc, FWOHCI_INTMASK))
|
|
|
|
device_printf(fc->dev, "INTERRUPT < %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s> 0x%08x, 0x%08x\n",
|
|
|
|
stat & OHCI_INT_EN ? "DMA_EN ":"",
|
|
|
|
stat & OHCI_INT_PHY_REG ? "PHY_REG ":"",
|
|
|
|
stat & OHCI_INT_CYC_LONG ? "CYC_LONG ":"",
|
|
|
|
stat & OHCI_INT_ERR ? "INT_ERR ":"",
|
|
|
|
stat & OHCI_INT_CYC_ERR ? "CYC_ERR ":"",
|
|
|
|
stat & OHCI_INT_CYC_LOST ? "CYC_LOST ":"",
|
|
|
|
stat & OHCI_INT_CYC_64SECOND ? "CYC_64SECOND ":"",
|
|
|
|
stat & OHCI_INT_CYC_START ? "CYC_START ":"",
|
|
|
|
stat & OHCI_INT_PHY_INT ? "PHY_INT ":"",
|
|
|
|
stat & OHCI_INT_PHY_BUS_R ? "BUS_RESET ":"",
|
|
|
|
stat & OHCI_INT_PHY_SID ? "SID ":"",
|
|
|
|
stat & OHCI_INT_LR_ERR ? "DMA_LR_ERR ":"",
|
|
|
|
stat & OHCI_INT_PW_ERR ? "DMA_PW_ERR ":"",
|
|
|
|
stat & OHCI_INT_DMA_IR ? "DMA_IR ":"",
|
|
|
|
stat & OHCI_INT_DMA_IT ? "DMA_IT " :"",
|
|
|
|
stat & OHCI_INT_DMA_PRRS ? "DMA_PRRS " :"",
|
|
|
|
stat & OHCI_INT_DMA_PRRQ ? "DMA_PRRQ " :"",
|
|
|
|
stat & OHCI_INT_DMA_ARRS ? "DMA_ARRS " :"",
|
|
|
|
stat & OHCI_INT_DMA_ARRQ ? "DMA_ARRQ " :"",
|
|
|
|
stat & OHCI_INT_DMA_ATRS ? "DMA_ATRS " :"",
|
|
|
|
stat & OHCI_INT_DMA_ATRQ ? "DMA_ATRQ " :"",
|
|
|
|
stat, OREAD(sc, FWOHCI_INTMASK)
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
/* Bus reset */
|
|
|
|
if(stat & OHCI_INT_PHY_BUS_R ){
|
|
|
|
device_printf(fc->dev, "BUS reset\n");
|
|
|
|
OWRITE(sc, FWOHCI_INTMASKCLR, OHCI_INT_CYC_LOST);
|
|
|
|
OWRITE(sc, OHCI_LNKCTLCLR, OHCI_CNTL_CYCSRC);
|
|
|
|
|
|
|
|
OWRITE(sc, OHCI_ATQCTLCLR, OHCI_CNTL_DMA_RUN);
|
|
|
|
sc->atrq.xferq.flag &= ~FWXFERQ_RUNNING;
|
|
|
|
OWRITE(sc, OHCI_ATSCTLCLR, OHCI_CNTL_DMA_RUN);
|
|
|
|
sc->atrs.xferq.flag &= ~FWXFERQ_RUNNING;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
for( i = 0 ; i < fc->nisodma ; i ++ ){
|
|
|
|
OWRITE(sc, OHCI_IRCTLCLR(i), OHCI_CNTL_DMA_RUN);
|
|
|
|
OWRITE(sc, OHCI_ITCTLCLR(i), OHCI_CNTL_DMA_RUN);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
fw_busreset(fc);
|
|
|
|
|
|
|
|
/* XXX need to wait DMA to stop */
|
|
|
|
#ifndef ACK_ALL
|
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, OHCI_INT_PHY_BUS_R);
|
|
|
|
#endif
|
|
|
|
#if 1
|
|
|
|
/* pending all pre-bus_reset packets */
|
|
|
|
fwohci_txd(sc, &sc->atrq);
|
|
|
|
fwohci_txd(sc, &sc->atrs);
|
2002-11-12 04:54:30 +00:00
|
|
|
fwohci_arcv(sc, &sc->arrs, -1);
|
|
|
|
fwohci_arcv(sc, &sc->arrq, -1);
|
2002-09-13 12:31:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
OWRITE(sc, OHCI_AREQHI, 1 << 31);
|
|
|
|
/* XXX insecure ?? */
|
|
|
|
OWRITE(sc, OHCI_PREQHI, 0x7fffffff);
|
|
|
|
OWRITE(sc, OHCI_PREQLO, 0xffffffff);
|
|
|
|
OWRITE(sc, OHCI_PREQUPPER, 0x10000);
|
|
|
|
|
|
|
|
}
|
|
|
|
if((stat & OHCI_INT_DMA_IR )){
|
|
|
|
#ifndef ACK_ALL
|
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, OHCI_INT_DMA_IR);
|
|
|
|
#endif
|
|
|
|
irstat = OREAD(sc, OHCI_IR_STAT);
|
2003-01-15 04:21:16 +00:00
|
|
|
OWRITE(sc, OHCI_IR_STATCLR, irstat);
|
2002-09-13 12:31:56 +00:00
|
|
|
for(i = 0; i < fc->nisodma ; i++){
|
2003-01-21 16:24:35 +00:00
|
|
|
struct fwohci_dbch *dbch;
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
if((irstat & (1 << i)) != 0){
|
2003-01-21 16:24:35 +00:00
|
|
|
dbch = &sc->ir[i];
|
|
|
|
if ((dbch->xferq.flag & FWXFERQ_OPEN) == 0) {
|
|
|
|
device_printf(sc->fc.dev,
|
|
|
|
"dma(%d) not active\n", i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (dbch->xferq.flag & FWXFERQ_PACKET) {
|
|
|
|
fwohci_ircv(sc, dbch, count);
|
|
|
|
} else {
|
2002-09-13 12:31:56 +00:00
|
|
|
fwohci_rbuf_update(sc, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if((stat & OHCI_INT_DMA_IT )){
|
|
|
|
#ifndef ACK_ALL
|
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, OHCI_INT_DMA_IT);
|
|
|
|
#endif
|
|
|
|
itstat = OREAD(sc, OHCI_IT_STAT);
|
2003-01-15 04:21:16 +00:00
|
|
|
OWRITE(sc, OHCI_IT_STATCLR, itstat);
|
2002-09-13 12:31:56 +00:00
|
|
|
for(i = 0; i < fc->nisodma ; i++){
|
|
|
|
if((itstat & (1 << i)) != 0){
|
|
|
|
fwohci_tbuf_update(sc, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if((stat & OHCI_INT_DMA_PRRS )){
|
|
|
|
#ifndef ACK_ALL
|
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, OHCI_INT_DMA_PRRS);
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
dump_dma(sc, ARRS_CH);
|
|
|
|
dump_db(sc, ARRS_CH);
|
|
|
|
#endif
|
2002-11-12 04:54:30 +00:00
|
|
|
fwohci_arcv(sc, &sc->arrs, count);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
if((stat & OHCI_INT_DMA_PRRQ )){
|
|
|
|
#ifndef ACK_ALL
|
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, OHCI_INT_DMA_PRRQ);
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
dump_dma(sc, ARRQ_CH);
|
|
|
|
dump_db(sc, ARRQ_CH);
|
|
|
|
#endif
|
2002-11-12 04:54:30 +00:00
|
|
|
fwohci_arcv(sc, &sc->arrq, count);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
if(stat & OHCI_INT_PHY_SID){
|
|
|
|
caddr_t buf;
|
|
|
|
int plen;
|
|
|
|
|
|
|
|
#ifndef ACK_ALL
|
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, OHCI_INT_PHY_SID);
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
** Checking whether the node is root or not. If root, turn on
|
|
|
|
** cycle master.
|
|
|
|
*/
|
|
|
|
device_printf(fc->dev, "node_id = 0x%08x, ", OREAD(sc, FWOHCI_NODEID));
|
|
|
|
if(!(OREAD(sc, FWOHCI_NODEID) & OHCI_NODE_VALID)){
|
|
|
|
printf("Bus reset failure\n");
|
|
|
|
goto sidout;
|
|
|
|
}
|
|
|
|
if( OREAD(sc, FWOHCI_NODEID) & OHCI_NODE_ROOT ){
|
|
|
|
printf("CYCLEMASTER mode\n");
|
|
|
|
OWRITE(sc, OHCI_LNKCTL,
|
|
|
|
OHCI_CNTL_CYCMTR | OHCI_CNTL_CYCTIMER);
|
|
|
|
}else{
|
|
|
|
printf("non CYCLEMASTER mode\n");
|
|
|
|
OWRITE(sc, OHCI_LNKCTLCLR, OHCI_CNTL_CYCMTR);
|
|
|
|
OWRITE(sc, OHCI_LNKCTL, OHCI_CNTL_CYCTIMER);
|
|
|
|
}
|
|
|
|
fc->nodeid = OREAD(sc, FWOHCI_NODEID) & 0x3f;
|
|
|
|
|
|
|
|
plen = OREAD(sc, OHCI_SID_CNT) & OHCI_SID_CNT_MASK;
|
2003-01-23 13:34:40 +00:00
|
|
|
if (plen < 4 || plen > OHCI_SIDSIZE) {
|
|
|
|
device_printf(fc->dev, "invalid SID len = %d\n", plen);
|
|
|
|
goto sidout;
|
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
plen -= 4; /* chop control info */
|
2003-01-16 13:09:33 +00:00
|
|
|
buf = malloc(OHCI_SIDSIZE, M_DEVBUF, M_NOWAIT);
|
2002-09-13 12:31:56 +00:00
|
|
|
if(buf == NULL) goto sidout;
|
2003-01-01 08:25:32 +00:00
|
|
|
bcopy((void *)(uintptr_t)(volatile void *)(fc->sid_buf + 1),
|
2002-09-13 12:31:56 +00:00
|
|
|
buf, plen);
|
|
|
|
fw_sidrcv(fc, buf, plen, 0);
|
|
|
|
}
|
|
|
|
sidout:
|
|
|
|
if((stat & OHCI_INT_DMA_ATRQ )){
|
|
|
|
#ifndef ACK_ALL
|
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, OHCI_INT_DMA_ATRQ);
|
|
|
|
#endif
|
|
|
|
fwohci_txd(sc, &(sc->atrq));
|
|
|
|
}
|
|
|
|
if((stat & OHCI_INT_DMA_ATRS )){
|
|
|
|
#ifndef ACK_ALL
|
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, OHCI_INT_DMA_ATRS);
|
|
|
|
#endif
|
|
|
|
fwohci_txd(sc, &(sc->atrs));
|
|
|
|
}
|
|
|
|
if((stat & OHCI_INT_PW_ERR )){
|
|
|
|
#ifndef ACK_ALL
|
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, OHCI_INT_PW_ERR);
|
|
|
|
#endif
|
|
|
|
device_printf(fc->dev, "posted write error\n");
|
|
|
|
}
|
|
|
|
if((stat & OHCI_INT_ERR )){
|
|
|
|
#ifndef ACK_ALL
|
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, OHCI_INT_ERR);
|
|
|
|
#endif
|
|
|
|
device_printf(fc->dev, "unrecoverable error\n");
|
|
|
|
}
|
|
|
|
if((stat & OHCI_INT_PHY_INT)) {
|
|
|
|
#ifndef ACK_ALL
|
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, OHCI_INT_PHY_INT);
|
|
|
|
#endif
|
|
|
|
device_printf(fc->dev, "phy int\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fwohci_intr(void *arg)
|
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)arg;
|
|
|
|
u_int32_t stat;
|
|
|
|
|
|
|
|
if (!(sc->intmask & OHCI_INT_EN)) {
|
|
|
|
/* polling mode */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((stat = OREAD(sc, FWOHCI_INTSTAT)) != 0) {
|
|
|
|
if (stat == 0xffffffff) {
|
|
|
|
device_printf(sc->fc.dev,
|
|
|
|
"device physically ejected?\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#ifdef ACK_ALL
|
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, stat);
|
|
|
|
#endif
|
2002-11-12 04:54:30 +00:00
|
|
|
fwohci_intr_body(sc, stat, -1);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_poll(struct firewire_comm *fc, int quick, int count)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
u_int32_t stat;
|
|
|
|
struct fwohci_softc *sc;
|
|
|
|
|
|
|
|
|
|
|
|
sc = (struct fwohci_softc *)fc;
|
|
|
|
stat = OHCI_INT_DMA_IR | OHCI_INT_DMA_IT |
|
|
|
|
OHCI_INT_DMA_PRRS | OHCI_INT_DMA_PRRQ |
|
|
|
|
OHCI_INT_DMA_ATRQ | OHCI_INT_DMA_ATRS;
|
|
|
|
#if 0
|
|
|
|
if (!quick) {
|
|
|
|
#else
|
|
|
|
if (1) {
|
|
|
|
#endif
|
|
|
|
stat = OREAD(sc, FWOHCI_INTSTAT);
|
|
|
|
if (stat == 0)
|
|
|
|
return;
|
|
|
|
if (stat == 0xffffffff) {
|
|
|
|
device_printf(sc->fc.dev,
|
|
|
|
"device physically ejected?\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#ifdef ACK_ALL
|
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, stat);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
s = splfw();
|
2002-11-12 04:54:30 +00:00
|
|
|
fwohci_intr_body(sc, stat, count);
|
2002-09-13 12:31:56 +00:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_set_intr(struct firewire_comm *fc, int enable)
|
|
|
|
{
|
|
|
|
struct fwohci_softc *sc;
|
|
|
|
|
|
|
|
sc = (struct fwohci_softc *)fc;
|
2002-12-06 02:17:30 +00:00
|
|
|
if (bootverbose)
|
2003-01-04 06:40:57 +00:00
|
|
|
device_printf(sc->fc.dev, "fwohci_set_intr: %d\n", enable);
|
2002-09-13 12:31:56 +00:00
|
|
|
if (enable) {
|
|
|
|
sc->intmask |= OHCI_INT_EN;
|
|
|
|
OWRITE(sc, FWOHCI_INTMASK, OHCI_INT_EN);
|
|
|
|
} else {
|
|
|
|
sc->intmask &= ~OHCI_INT_EN;
|
|
|
|
OWRITE(sc, FWOHCI_INTMASKCLR, OHCI_INT_EN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-12 05:52:01 +00:00
|
|
|
static void
|
|
|
|
fwohci_tbuf_update(struct fwohci_softc *sc, int dmach)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct firewire_comm *fc = &sc->fc;
|
2003-01-26 15:39:04 +00:00
|
|
|
volatile struct fwohcidb *db;
|
|
|
|
struct fw_bulkxfer *chunk;
|
|
|
|
struct fw_xferq *it;
|
|
|
|
u_int32_t stat, count;
|
|
|
|
int s, w=0;
|
|
|
|
|
|
|
|
it = fc->it[dmach];
|
|
|
|
s = splfw(); /* unnecessary ? */
|
|
|
|
while ((chunk = STAILQ_FIRST(&it->stdma)) != NULL) {
|
|
|
|
db = ((struct fwohcidb_tr *)(chunk->end))->db;
|
|
|
|
stat = db[sc->it[dmach].ndesc - 1].db.desc.status;
|
|
|
|
db = ((struct fwohcidb_tr *)(chunk->start))->db;
|
|
|
|
count = db[sc->it[dmach].ndesc - 1].db.desc.count;
|
|
|
|
if (stat == 0)
|
|
|
|
break;
|
|
|
|
STAILQ_REMOVE_HEAD(&it->stdma, link);
|
|
|
|
switch (stat & FWOHCIEV_MASK){
|
|
|
|
case FWOHCIEV_ACKCOMPL:
|
|
|
|
#if 0
|
|
|
|
device_printf(fc->dev, "0x%08x\n", count);
|
2003-01-13 16:08:09 +00:00
|
|
|
#endif
|
2003-01-26 15:39:04 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-01-17 15:03:57 +00:00
|
|
|
device_printf(fc->dev,
|
2003-01-26 15:39:04 +00:00
|
|
|
"Isochronous transmit err %02x\n", stat);
|
|
|
|
}
|
|
|
|
STAILQ_INSERT_TAIL(&it->stfree, chunk, link);
|
|
|
|
w++;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-01-26 15:39:04 +00:00
|
|
|
splx(s);
|
|
|
|
if (w)
|
|
|
|
wakeup(it);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_rbuf_update(struct fwohci_softc *sc, int dmach)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-01-13 16:08:09 +00:00
|
|
|
struct firewire_comm *fc = &sc->fc;
|
2003-01-26 15:39:04 +00:00
|
|
|
volatile struct fwohcidb *db;
|
|
|
|
struct fw_bulkxfer *chunk;
|
|
|
|
struct fw_xferq *ir;
|
|
|
|
u_int32_t stat;
|
|
|
|
int s, w=0;
|
2003-01-13 16:08:09 +00:00
|
|
|
|
2003-01-26 15:39:04 +00:00
|
|
|
ir = fc->ir[dmach];
|
|
|
|
s = splfw();
|
|
|
|
while ((chunk = STAILQ_FIRST(&ir->stdma)) != NULL) {
|
|
|
|
db = ((struct fwohcidb_tr *)(chunk->end))->db;
|
|
|
|
stat = db[sc->ir[dmach].ndesc - 1].db.desc.status;
|
|
|
|
if (stat == 0)
|
|
|
|
break;
|
|
|
|
STAILQ_REMOVE_HEAD(&ir->stdma, link);
|
|
|
|
STAILQ_INSERT_TAIL(&ir->stvalid, chunk, link);
|
|
|
|
switch (stat & FWOHCIEV_MASK) {
|
|
|
|
case FWOHCIEV_ACKCOMPL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
device_printf(fc->dev,
|
|
|
|
"Isochronous receive err %02x\n", stat);
|
|
|
|
}
|
|
|
|
w++;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-01-26 15:39:04 +00:00
|
|
|
splx(s);
|
|
|
|
if (w)
|
|
|
|
wakeup(ir);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
dump_dma(struct fwohci_softc *sc, u_int32_t ch)
|
|
|
|
{
|
2002-09-13 12:31:56 +00:00
|
|
|
u_int32_t off, cntl, stat, cmd, match;
|
|
|
|
|
|
|
|
if(ch == 0){
|
|
|
|
off = OHCI_ATQOFF;
|
|
|
|
}else if(ch == 1){
|
|
|
|
off = OHCI_ATSOFF;
|
|
|
|
}else if(ch == 2){
|
|
|
|
off = OHCI_ARQOFF;
|
|
|
|
}else if(ch == 3){
|
|
|
|
off = OHCI_ARSOFF;
|
|
|
|
}else if(ch < IRX_CH){
|
|
|
|
off = OHCI_ITCTL(ch - ITX_CH);
|
|
|
|
}else{
|
|
|
|
off = OHCI_IRCTL(ch - IRX_CH);
|
|
|
|
}
|
|
|
|
cntl = stat = OREAD(sc, off);
|
|
|
|
cmd = OREAD(sc, off + 0xc);
|
|
|
|
match = OREAD(sc, off + 0x10);
|
|
|
|
|
|
|
|
device_printf(sc->fc.dev, "dma ch %1x:dma regs 0x%08x 0x%08x 0x%08x 0x%08x \n",
|
|
|
|
ch,
|
|
|
|
cntl,
|
|
|
|
stat,
|
|
|
|
cmd,
|
|
|
|
match);
|
|
|
|
stat &= 0xffff ;
|
|
|
|
if(stat & 0xff00){
|
|
|
|
device_printf(sc->fc.dev, "dma %d ch:%s%s%s%s%s%s %s(%x)\n",
|
|
|
|
ch,
|
|
|
|
stat & OHCI_CNTL_DMA_RUN ? "RUN," : "",
|
|
|
|
stat & OHCI_CNTL_DMA_WAKE ? "WAKE," : "",
|
|
|
|
stat & OHCI_CNTL_DMA_DEAD ? "DEAD," : "",
|
|
|
|
stat & OHCI_CNTL_DMA_ACTIVE ? "ACTIVE," : "",
|
|
|
|
stat & OHCI_CNTL_DMA_BT ? "BRANCH," : "",
|
|
|
|
stat & OHCI_CNTL_DMA_BAD ? "BADDMA," : "",
|
|
|
|
fwohcicode[stat & 0x1f],
|
|
|
|
stat & 0x1f
|
|
|
|
);
|
|
|
|
}else{
|
|
|
|
device_printf(sc->fc.dev, "dma %d ch: Nostat\n", ch);
|
|
|
|
}
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
dump_db(struct fwohci_softc *sc, u_int32_t ch)
|
|
|
|
{
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fwohci_dbch *dbch;
|
|
|
|
struct fwohcidb_tr *cp = NULL, *pp, *np;
|
|
|
|
volatile struct fwohcidb *curr = NULL, *prev, *next = NULL;
|
|
|
|
int idb, jdb;
|
|
|
|
u_int32_t cmd, off;
|
|
|
|
if(ch == 0){
|
|
|
|
off = OHCI_ATQOFF;
|
|
|
|
dbch = &sc->atrq;
|
|
|
|
}else if(ch == 1){
|
|
|
|
off = OHCI_ATSOFF;
|
|
|
|
dbch = &sc->atrs;
|
|
|
|
}else if(ch == 2){
|
|
|
|
off = OHCI_ARQOFF;
|
|
|
|
dbch = &sc->arrq;
|
|
|
|
}else if(ch == 3){
|
|
|
|
off = OHCI_ARSOFF;
|
|
|
|
dbch = &sc->arrs;
|
|
|
|
}else if(ch < IRX_CH){
|
|
|
|
off = OHCI_ITCTL(ch - ITX_CH);
|
|
|
|
dbch = &sc->it[ch - ITX_CH];
|
|
|
|
}else {
|
|
|
|
off = OHCI_IRCTL(ch - IRX_CH);
|
|
|
|
dbch = &sc->ir[ch - IRX_CH];
|
|
|
|
}
|
|
|
|
cmd = OREAD(sc, off + 0xc);
|
|
|
|
|
|
|
|
if( dbch->ndb == 0 ){
|
|
|
|
device_printf(sc->fc.dev, "No DB is attached ch=%d\n", ch);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pp = dbch->top;
|
|
|
|
prev = pp->db;
|
|
|
|
for(idb = 0 ; idb < dbch->ndb ; idb ++ ){
|
|
|
|
if(pp == NULL){
|
|
|
|
curr = NULL;
|
|
|
|
goto outdb;
|
|
|
|
}
|
|
|
|
cp = STAILQ_NEXT(pp, link);
|
|
|
|
if(cp == NULL){
|
|
|
|
curr = NULL;
|
|
|
|
goto outdb;
|
|
|
|
}
|
|
|
|
np = STAILQ_NEXT(cp, link);
|
|
|
|
if(cp == NULL) break;
|
|
|
|
for(jdb = 0 ; jdb < dbch->ndesc ; jdb ++ ){
|
|
|
|
if((cmd & 0xfffffff0)
|
|
|
|
== vtophys(&(cp->db[jdb]))){
|
|
|
|
curr = cp->db;
|
|
|
|
if(np != NULL){
|
|
|
|
next = np->db;
|
|
|
|
}else{
|
|
|
|
next = NULL;
|
|
|
|
}
|
|
|
|
goto outdb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pp = STAILQ_NEXT(pp, link);
|
|
|
|
prev = pp->db;
|
|
|
|
}
|
|
|
|
outdb:
|
|
|
|
if( curr != NULL){
|
|
|
|
printf("Prev DB %d\n", ch);
|
|
|
|
print_db(prev, ch, dbch->ndesc);
|
|
|
|
printf("Current DB %d\n", ch);
|
|
|
|
print_db(curr, ch, dbch->ndesc);
|
|
|
|
printf("Next DB %d\n", ch);
|
|
|
|
print_db(next, ch, dbch->ndesc);
|
|
|
|
}else{
|
|
|
|
printf("dbdump err ch = %d cmd = 0x%08x\n", ch, cmd);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
print_db(volatile struct fwohcidb *db, u_int32_t ch, u_int32_t max)
|
|
|
|
{
|
2002-09-13 12:31:56 +00:00
|
|
|
fwohcireg_t stat;
|
|
|
|
int i, key;
|
|
|
|
|
|
|
|
if(db == NULL){
|
|
|
|
printf("No Descriptor is found\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("ch = %d\n%8s %s %s %s %s %4s %8s %8s %4s:%4s\n",
|
|
|
|
ch,
|
|
|
|
"Current",
|
|
|
|
"OP ",
|
|
|
|
"KEY",
|
|
|
|
"INT",
|
|
|
|
"BR ",
|
|
|
|
"len",
|
|
|
|
"Addr",
|
|
|
|
"Depend",
|
|
|
|
"Stat",
|
|
|
|
"Cnt");
|
|
|
|
for( i = 0 ; i <= max ; i ++){
|
2003-01-26 18:38:06 +00:00
|
|
|
key = db[i].db.desc.control & OHCI_KEY_MASK;
|
2003-01-05 14:58:45 +00:00
|
|
|
#if __FreeBSD_version >= 500000
|
2002-11-07 02:13:40 +00:00
|
|
|
printf("%08tx %s %s %s %s %5d %08x %08x %04x:%04x",
|
2003-01-05 14:58:45 +00:00
|
|
|
#else
|
|
|
|
printf("%08x %s %s %s %s %5d %08x %08x %04x:%04x",
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
vtophys(&db[i]),
|
2003-01-26 18:38:06 +00:00
|
|
|
dbcode[(db[i].db.desc.control >> 12) & 0xf],
|
|
|
|
dbkey[(db[i].db.desc.control >> 8) & 0x7],
|
|
|
|
dbcond[(db[i].db.desc.control >> 4) & 0x3],
|
|
|
|
dbcond[(db[i].db.desc.control >> 2) & 0x3],
|
|
|
|
db[i].db.desc.reqcount,
|
2002-09-13 12:31:56 +00:00
|
|
|
db[i].db.desc.addr,
|
|
|
|
db[i].db.desc.depend,
|
|
|
|
db[i].db.desc.status,
|
|
|
|
db[i].db.desc.count);
|
|
|
|
stat = db[i].db.desc.status;
|
|
|
|
if(stat & 0xff00){
|
|
|
|
printf(" %s%s%s%s%s%s %s(%x)\n",
|
|
|
|
stat & OHCI_CNTL_DMA_RUN ? "RUN," : "",
|
|
|
|
stat & OHCI_CNTL_DMA_WAKE ? "WAKE," : "",
|
|
|
|
stat & OHCI_CNTL_DMA_DEAD ? "DEAD," : "",
|
|
|
|
stat & OHCI_CNTL_DMA_ACTIVE ? "ACTIVE," : "",
|
|
|
|
stat & OHCI_CNTL_DMA_BT ? "BRANCH," : "",
|
|
|
|
stat & OHCI_CNTL_DMA_BAD ? "BADDMA," : "",
|
|
|
|
fwohcicode[stat & 0x1f],
|
|
|
|
stat & 0x1f
|
|
|
|
);
|
|
|
|
}else{
|
|
|
|
printf(" Nostat\n");
|
|
|
|
}
|
|
|
|
if(key == OHCI_KEY_ST2 ){
|
|
|
|
printf("0x%08x 0x%08x 0x%08x 0x%08x\n",
|
|
|
|
db[i+1].db.immed[0],
|
|
|
|
db[i+1].db.immed[1],
|
|
|
|
db[i+1].db.immed[2],
|
|
|
|
db[i+1].db.immed[3]);
|
|
|
|
}
|
|
|
|
if(key == OHCI_KEY_DEVICE){
|
|
|
|
return;
|
|
|
|
}
|
2003-01-26 18:38:06 +00:00
|
|
|
if((db[i].db.desc.control & OHCI_BRANCH_MASK)
|
2002-09-13 12:31:56 +00:00
|
|
|
== OHCI_BRANCH_ALWAYS){
|
|
|
|
return;
|
|
|
|
}
|
2003-01-26 18:38:06 +00:00
|
|
|
if((db[i].db.desc.control & OHCI_CMD_MASK)
|
2002-09-13 12:31:56 +00:00
|
|
|
== OHCI_OUTPUT_LAST){
|
|
|
|
return;
|
|
|
|
}
|
2003-01-26 18:38:06 +00:00
|
|
|
if((db[i].db.desc.control & OHCI_CMD_MASK)
|
2002-09-13 12:31:56 +00:00
|
|
|
== OHCI_INPUT_LAST){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(key == OHCI_KEY_ST2 ){
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
fwohci_ibr(struct firewire_comm *fc)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohci_softc *sc;
|
|
|
|
u_int32_t fun;
|
|
|
|
|
|
|
|
sc = (struct fwohci_softc *)fc;
|
2002-12-26 03:17:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set root hold-off bit so that non cyclemaster capable node
|
|
|
|
* shouldn't became the root node.
|
|
|
|
*/
|
2002-09-13 12:31:56 +00:00
|
|
|
#if 1
|
|
|
|
fun = fwphy_rddata(sc, FW_PHY_IBR_REG);
|
2003-01-15 04:21:16 +00:00
|
|
|
fun |= FW_PHY_IBR | FW_PHY_RHB;
|
2002-09-13 12:31:56 +00:00
|
|
|
fun = fwphy_wrdata(sc, FW_PHY_IBR_REG, fun);
|
2003-01-15 04:21:16 +00:00
|
|
|
#else /* Short bus reset */
|
2002-09-13 12:31:56 +00:00
|
|
|
fun = fwphy_rddata(sc, FW_PHY_ISBR_REG);
|
2003-01-15 04:21:16 +00:00
|
|
|
fun |= FW_PHY_ISBR | FW_PHY_RHB;
|
2002-09-13 12:31:56 +00:00
|
|
|
fun = fwphy_wrdata(sc, FW_PHY_ISBR_REG, fun);
|
|
|
|
#endif
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
fwohci_txbufdb(struct fwohci_softc *sc, int dmach, struct fw_bulkxfer *bulkxfer)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohcidb_tr *db_tr, *fdb_tr;
|
|
|
|
struct fwohci_dbch *dbch;
|
2003-01-26 18:38:06 +00:00
|
|
|
volatile struct fwohcidb *db;
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fw_pkt *fp;
|
|
|
|
volatile struct fwohci_txpkthdr *ohcifp;
|
|
|
|
unsigned short chtag;
|
|
|
|
int idb;
|
|
|
|
|
|
|
|
dbch = &sc->it[dmach];
|
|
|
|
chtag = sc->it[dmach].xferq.flag & 0xff;
|
|
|
|
|
|
|
|
db_tr = (struct fwohcidb_tr *)(bulkxfer->start);
|
|
|
|
fdb_tr = (struct fwohcidb_tr *)(bulkxfer->end);
|
|
|
|
/*
|
|
|
|
device_printf(sc->fc.dev, "DB %08x %08x %08x\n", bulkxfer, vtophys(db_tr->db), vtophys(fdb_tr->db));
|
|
|
|
*/
|
|
|
|
for( idb = 0 ; idb < bulkxfer->npacket ; idb ++){
|
2003-01-26 18:38:06 +00:00
|
|
|
db = db_tr->db;
|
|
|
|
#if 0
|
|
|
|
db[0].db.desc.control
|
|
|
|
= OHCI_OUTPUT_MORE | OHCI_KEY_ST2;
|
|
|
|
db[0].db.desc.reqcount = 8;
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
fp = (struct fw_pkt *)db_tr->buf;
|
2003-01-26 18:38:06 +00:00
|
|
|
ohcifp = (volatile struct fwohci_txpkthdr *) db[1].db.immed;
|
2002-09-13 12:31:56 +00:00
|
|
|
ohcifp->mode.ld[0] = ntohl(fp->mode.ld[0]);
|
|
|
|
ohcifp->mode.stream.len = ntohs(fp->mode.stream.len);
|
|
|
|
ohcifp->mode.stream.chtag = chtag;
|
|
|
|
ohcifp->mode.stream.tcode = 0xa;
|
2003-01-26 15:39:04 +00:00
|
|
|
ohcifp->mode.stream.spd = 0;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-01-26 18:38:06 +00:00
|
|
|
db[2].db.desc.reqcount = ntohs(fp->mode.stream.len);
|
|
|
|
db[2].db.desc.status = 0;
|
|
|
|
db[2].db.desc.count = 0;
|
|
|
|
#if 0 /* if bulkxfer->npackets changes */
|
|
|
|
db[2].db.desc.control = OHCI_OUTPUT_LAST
|
2002-09-13 12:31:56 +00:00
|
|
|
| OHCI_UPDATE
|
2003-01-26 18:38:06 +00:00
|
|
|
| OHCI_BRANCH_ALWAYS;
|
|
|
|
db[0].db.desc.depend =
|
|
|
|
= db[dbch->ndesc - 1].db.desc.depend
|
2003-01-15 04:21:16 +00:00
|
|
|
= vtophys(STAILQ_NEXT(db_tr, link)->db) | dbch->ndesc;
|
2003-01-26 18:38:06 +00:00
|
|
|
#else
|
|
|
|
db[0].db.desc.depend |= dbch->ndesc;
|
|
|
|
db[dbch->ndesc - 1].db.desc.depend |= dbch->ndesc;
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
bulkxfer->end = (caddr_t)db_tr;
|
|
|
|
db_tr = STAILQ_NEXT(db_tr, link);
|
|
|
|
}
|
2003-01-26 18:38:06 +00:00
|
|
|
db = ((struct fwohcidb_tr *)bulkxfer->end)->db;
|
|
|
|
db[0].db.desc.depend &= ~0xf;
|
|
|
|
db[dbch->ndesc - 1].db.desc.depend &= ~0xf;
|
|
|
|
#if 0 /* if bulkxfer->npackets changes */
|
|
|
|
db[dbch->ndesc - 1].db.desc.control |= OHCI_INTERRUPT_ALWAYS;
|
2003-01-15 04:21:16 +00:00
|
|
|
/* OHCI 1.1 and above */
|
2003-01-26 18:38:06 +00:00
|
|
|
db[0].db.desc.control |= OHCI_INTERRUPT_ALWAYS;
|
|
|
|
#endif
|
|
|
|
/*
|
2002-09-13 12:31:56 +00:00
|
|
|
db_tr = (struct fwohcidb_tr *)bulkxfer->start;
|
|
|
|
fdb_tr = (struct fwohcidb_tr *)bulkxfer->end;
|
|
|
|
device_printf(sc->fc.dev, "DB %08x %3d %08x %08x\n", bulkxfer, bulkxfer->npacket, vtophys(db_tr->db), vtophys(fdb_tr->db));
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
fwohci_add_tx_buf(struct fwohcidb_tr *db_tr, unsigned short size,
|
|
|
|
int mode, void *buf)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
volatile struct fwohcidb *db = db_tr->db;
|
|
|
|
int err = 0;
|
|
|
|
if(buf == 0){
|
|
|
|
err = EINVAL;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
db_tr->buf = buf;
|
|
|
|
db_tr->dbcnt = 3;
|
|
|
|
db_tr->dummy = NULL;
|
|
|
|
|
2003-01-26 18:38:06 +00:00
|
|
|
db[0].db.desc.control = OHCI_OUTPUT_MORE | OHCI_KEY_ST2;
|
|
|
|
db[0].db.desc.reqcount = 8;
|
2002-09-13 12:31:56 +00:00
|
|
|
db[2].db.desc.addr = vtophys(buf) + sizeof(u_int32_t);
|
2003-01-26 18:38:06 +00:00
|
|
|
db[2].db.desc.control =
|
|
|
|
OHCI_OUTPUT_LAST | OHCI_UPDATE | OHCI_BRANCH_ALWAYS;
|
|
|
|
#if 1
|
2002-09-13 12:31:56 +00:00
|
|
|
db[0].db.desc.status = 0;
|
|
|
|
db[0].db.desc.count = 0;
|
|
|
|
db[2].db.desc.status = 0;
|
|
|
|
db[2].db.desc.count = 0;
|
2003-01-26 18:38:06 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
if( mode & FWXFERQ_STREAM ){
|
|
|
|
if(mode & FWXFERQ_PACKET ){
|
2003-01-26 18:38:06 +00:00
|
|
|
db[2].db.desc.control |= OHCI_INTERRUPT_ALWAYS;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-01-26 18:38:06 +00:00
|
|
|
} else {
|
|
|
|
printf("fwohci_add_tx_buf: who calls me?");
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
fwohci_add_rx_buf(struct fwohcidb_tr *db_tr, unsigned short size, int mode,
|
|
|
|
void *buf, void *dummy)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
volatile struct fwohcidb *db = db_tr->db;
|
|
|
|
int i;
|
|
|
|
void *dbuf[2];
|
|
|
|
int dsiz[2];
|
|
|
|
|
|
|
|
if(buf == 0){
|
|
|
|
buf = malloc(size, M_DEVBUF, M_NOWAIT);
|
|
|
|
if(buf == NULL) return 0;
|
|
|
|
db_tr->buf = buf;
|
|
|
|
db_tr->dbcnt = 1;
|
|
|
|
db_tr->dummy = NULL;
|
|
|
|
dsiz[0] = size;
|
|
|
|
dbuf[0] = buf;
|
|
|
|
}else if(dummy == NULL){
|
|
|
|
db_tr->buf = buf;
|
|
|
|
db_tr->dbcnt = 1;
|
|
|
|
db_tr->dummy = NULL;
|
|
|
|
dsiz[0] = size;
|
|
|
|
dbuf[0] = buf;
|
|
|
|
}else{
|
|
|
|
db_tr->buf = buf;
|
|
|
|
db_tr->dbcnt = 2;
|
|
|
|
db_tr->dummy = dummy;
|
|
|
|
dsiz[0] = sizeof(u_int32_t);
|
|
|
|
dsiz[1] = size;
|
|
|
|
dbuf[0] = dummy;
|
|
|
|
dbuf[1] = buf;
|
|
|
|
}
|
|
|
|
for(i = 0 ; i < db_tr->dbcnt ; i++){
|
|
|
|
db[i].db.desc.addr = vtophys(dbuf[i]) ;
|
2003-01-26 18:38:06 +00:00
|
|
|
db[i].db.desc.control = OHCI_INPUT_MORE;
|
|
|
|
db[i].db.desc.reqcount = dsiz[i];
|
2002-09-13 12:31:56 +00:00
|
|
|
if( mode & FWXFERQ_STREAM ){
|
2003-01-26 18:38:06 +00:00
|
|
|
db[i].db.desc.control |= OHCI_UPDATE;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
db[i].db.desc.status = 0;
|
|
|
|
db[i].db.desc.count = dsiz[i];
|
|
|
|
}
|
|
|
|
if( mode & FWXFERQ_STREAM ){
|
2003-01-26 18:38:06 +00:00
|
|
|
db[db_tr->dbcnt - 1].db.desc.control |= OHCI_INPUT_LAST;
|
2002-09-13 12:31:56 +00:00
|
|
|
if(mode & FWXFERQ_PACKET ){
|
2003-01-26 18:38:06 +00:00
|
|
|
db[db_tr->dbcnt - 1].db.desc.control
|
2002-09-13 12:31:56 +00:00
|
|
|
|= OHCI_INTERRUPT_ALWAYS;
|
|
|
|
}
|
|
|
|
}
|
2003-01-26 18:38:06 +00:00
|
|
|
db[db_tr->dbcnt - 1].db.desc.control |= OHCI_BRANCH_ALWAYS;
|
2002-09-13 12:31:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_ircv(struct fwohci_softc *sc, struct fwohci_dbch *dbch, int count)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohcidb_tr *db_tr = dbch->top, *odb_tr;
|
|
|
|
struct firewire_comm *fc = (struct firewire_comm *)sc;
|
|
|
|
int z = 1;
|
|
|
|
struct fw_pkt *fp;
|
|
|
|
u_int8_t *ld;
|
|
|
|
u_int32_t off = NULL;
|
|
|
|
u_int32_t stat;
|
|
|
|
u_int32_t *qld;
|
|
|
|
u_int32_t reg;
|
|
|
|
u_int spd;
|
|
|
|
u_int dmach;
|
|
|
|
int len, i, plen;
|
|
|
|
caddr_t buf;
|
|
|
|
|
|
|
|
for(dmach = 0 ; dmach < sc->fc.nisodma ; dmach++){
|
|
|
|
if( &sc->ir[dmach] == dbch){
|
|
|
|
off = OHCI_IROFF(dmach);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(off == NULL){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(!(dbch->xferq.flag & FWXFERQ_RUNNING)){
|
|
|
|
fwohci_irx_disable(&sc->fc, dmach);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
odb_tr = NULL;
|
|
|
|
db_tr = dbch->top;
|
|
|
|
i = 0;
|
|
|
|
while ((reg = db_tr->db[0].db.desc.status) & 0x1f) {
|
2002-11-12 04:54:30 +00:00
|
|
|
if (count >= 0 && count-- == 0)
|
|
|
|
break;
|
2002-09-13 12:31:56 +00:00
|
|
|
ld = (u_int8_t *)db_tr->buf;
|
|
|
|
if (dbch->xferq.flag & FWXFERQ_PACKET) {
|
|
|
|
/* skip timeStamp */
|
|
|
|
ld += sizeof(struct fwohci_trailer);
|
|
|
|
}
|
|
|
|
qld = (u_int32_t *)ld;
|
|
|
|
len = dbch->xferq.psize - (db_tr->db[0].db.desc.count);
|
|
|
|
/*
|
|
|
|
{
|
|
|
|
device_printf(sc->fc.dev, "%04x %2x 0x%08x 0x%08x 0x%08x 0x%08x\n", len,
|
|
|
|
db_tr->db[0].db.desc.status & 0x1f, qld[0],qld[1],qld[2],qld[3]);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
fp=(struct fw_pkt *)ld;
|
|
|
|
qld[0] = htonl(qld[0]);
|
|
|
|
plen = sizeof(struct fw_isohdr)
|
|
|
|
+ ntohs(fp->mode.stream.len) + sizeof(u_int32_t);
|
|
|
|
ld += plen;
|
|
|
|
len -= plen;
|
|
|
|
buf = db_tr->buf;
|
|
|
|
db_tr->buf = NULL;
|
|
|
|
stat = reg & 0x1f;
|
|
|
|
spd = reg & 0x3;
|
|
|
|
switch(stat){
|
|
|
|
case FWOHCIEV_ACKCOMPL:
|
|
|
|
case FWOHCIEV_ACKPEND:
|
|
|
|
fw_rcv(&sc->fc, buf, plen - sizeof(u_int32_t), dmach, sizeof(u_int32_t), spd);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
free(buf, M_DEVBUF);
|
|
|
|
device_printf(sc->fc.dev, "Isochronous receive err %02x\n", stat);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
fwohci_add_rx_buf(db_tr, dbch->xferq.psize,
|
|
|
|
dbch->xferq.flag, 0, NULL);
|
|
|
|
db_tr->db[0].db.desc.depend &= ~0xf;
|
|
|
|
if(dbch->pdb_tr != NULL){
|
|
|
|
dbch->pdb_tr->db[0].db.desc.depend |= z;
|
|
|
|
} else {
|
|
|
|
/* XXX should be rewritten in better way */
|
|
|
|
dbch->bottom->db[0].db.desc.depend |= z;
|
|
|
|
}
|
|
|
|
dbch->pdb_tr = db_tr;
|
|
|
|
db_tr = STAILQ_NEXT(db_tr, link);
|
|
|
|
}
|
|
|
|
dbch->top = db_tr;
|
|
|
|
reg = OREAD(sc, OHCI_DMACTL(off));
|
|
|
|
if (reg & OHCI_CNTL_DMA_ACTIVE)
|
|
|
|
return;
|
|
|
|
device_printf(sc->fc.dev, "IR DMA %d stopped at %x status=%x (%d)\n",
|
|
|
|
dmach, OREAD(sc, OHCI_DMACMD(off)), reg, i);
|
|
|
|
dbch->top = db_tr;
|
|
|
|
fwohci_irx_enable(fc, dmach);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PLEN(x) (((ntohs(x))+0x3) & ~0x3)
|
|
|
|
static int
|
|
|
|
fwohci_get_plen(struct fwohci_softc *sc, struct fw_pkt *fp, int hlen)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for( i = 4; i < hlen ; i+=4){
|
|
|
|
fp->mode.ld[i/4] = htonl(fp->mode.ld[i/4]);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(fp->mode.common.tcode){
|
|
|
|
case FWTCODE_RREQQ:
|
|
|
|
return sizeof(fp->mode.rreqq) + sizeof(u_int32_t);
|
|
|
|
case FWTCODE_WRES:
|
|
|
|
return sizeof(fp->mode.wres) + sizeof(u_int32_t);
|
|
|
|
case FWTCODE_WREQQ:
|
|
|
|
return sizeof(fp->mode.wreqq) + sizeof(u_int32_t);
|
|
|
|
case FWTCODE_RREQB:
|
|
|
|
return sizeof(fp->mode.rreqb) + sizeof(u_int32_t);
|
|
|
|
case FWTCODE_RRESQ:
|
|
|
|
return sizeof(fp->mode.rresq) + sizeof(u_int32_t);
|
|
|
|
case FWTCODE_WREQB:
|
|
|
|
return sizeof(struct fw_asyhdr) + PLEN(fp->mode.wreqb.len)
|
|
|
|
+ sizeof(u_int32_t);
|
|
|
|
case FWTCODE_LREQ:
|
|
|
|
return sizeof(struct fw_asyhdr) + PLEN(fp->mode.lreq.len)
|
|
|
|
+ sizeof(u_int32_t);
|
|
|
|
case FWTCODE_RRESB:
|
|
|
|
return sizeof(struct fw_asyhdr) + PLEN(fp->mode.rresb.len)
|
|
|
|
+ sizeof(u_int32_t);
|
|
|
|
case FWTCODE_LRES:
|
|
|
|
return sizeof(struct fw_asyhdr) + PLEN(fp->mode.lres.len)
|
|
|
|
+ sizeof(u_int32_t);
|
|
|
|
case FWOHCITCODE_PHY:
|
|
|
|
return 16;
|
|
|
|
}
|
|
|
|
device_printf(sc->fc.dev, "Unknown tcode %d\n", fp->mode.common.tcode);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-11-12 05:52:01 +00:00
|
|
|
static void
|
|
|
|
fwohci_arcv(struct fwohci_softc *sc, struct fwohci_dbch *dbch, int count)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohcidb_tr *db_tr;
|
|
|
|
int z = 1;
|
|
|
|
struct fw_pkt *fp;
|
|
|
|
u_int8_t *ld;
|
|
|
|
u_int32_t stat, off;
|
|
|
|
u_int spd;
|
|
|
|
int len, plen, hlen, pcnt, poff = 0, rlen;
|
|
|
|
int s;
|
|
|
|
caddr_t buf;
|
|
|
|
int resCount;
|
|
|
|
|
|
|
|
if(&sc->arrq == dbch){
|
|
|
|
off = OHCI_ARQOFF;
|
|
|
|
}else if(&sc->arrs == dbch){
|
|
|
|
off = OHCI_ARSOFF;
|
|
|
|
}else{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = splfw();
|
|
|
|
db_tr = dbch->top;
|
|
|
|
pcnt = 0;
|
|
|
|
/* XXX we cannot handle a packet which lies in more than two buf */
|
|
|
|
while (db_tr->db[0].db.desc.status & OHCI_CNTL_DMA_ACTIVE) {
|
|
|
|
ld = (u_int8_t *)db_tr->buf + dbch->buf_offset;
|
|
|
|
resCount = db_tr->db[0].db.desc.count;
|
|
|
|
len = dbch->xferq.psize - resCount
|
|
|
|
- dbch->buf_offset;
|
|
|
|
while (len > 0 ) {
|
2002-11-12 04:54:30 +00:00
|
|
|
if (count >= 0 && count-- == 0)
|
|
|
|
goto out;
|
2002-09-13 12:31:56 +00:00
|
|
|
if(dbch->frag.buf != NULL){
|
|
|
|
buf = dbch->frag.buf;
|
|
|
|
if (dbch->frag.plen < 0) {
|
|
|
|
/* incomplete header */
|
|
|
|
int hlen;
|
|
|
|
|
|
|
|
hlen = - dbch->frag.plen;
|
|
|
|
rlen = hlen - dbch->frag.len;
|
|
|
|
bcopy(ld, dbch->frag.buf + dbch->frag.len, rlen);
|
|
|
|
ld += rlen;
|
|
|
|
len -= rlen;
|
|
|
|
dbch->frag.len += rlen;
|
|
|
|
#if 0
|
|
|
|
printf("(1)frag.plen=%d frag.len=%d rlen=%d len=%d\n", dbch->frag.plen, dbch->frag.len, rlen, len);
|
|
|
|
#endif
|
|
|
|
fp=(struct fw_pkt *)dbch->frag.buf;
|
|
|
|
dbch->frag.plen
|
|
|
|
= fwohci_get_plen(sc, fp, hlen);
|
|
|
|
if (dbch->frag.plen == 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
rlen = dbch->frag.plen - dbch->frag.len;
|
|
|
|
#if 0
|
|
|
|
printf("(2)frag.plen=%d frag.len=%d rlen=%d len=%d\n", dbch->frag.plen, dbch->frag.len, rlen, len);
|
|
|
|
#endif
|
|
|
|
bcopy(ld, dbch->frag.buf + dbch->frag.len,
|
|
|
|
rlen);
|
|
|
|
ld += rlen;
|
|
|
|
len -= rlen;
|
|
|
|
plen = dbch->frag.plen;
|
|
|
|
dbch->frag.buf = NULL;
|
|
|
|
dbch->frag.plen = 0;
|
|
|
|
dbch->frag.len = 0;
|
|
|
|
poff = 0;
|
|
|
|
}else{
|
|
|
|
fp=(struct fw_pkt *)ld;
|
|
|
|
fp->mode.ld[0] = htonl(fp->mode.ld[0]);
|
|
|
|
switch(fp->mode.common.tcode){
|
|
|
|
case FWTCODE_RREQQ:
|
|
|
|
case FWTCODE_WRES:
|
|
|
|
case FWTCODE_WREQQ:
|
|
|
|
case FWTCODE_RRESQ:
|
|
|
|
case FWOHCITCODE_PHY:
|
|
|
|
hlen = 12;
|
|
|
|
break;
|
|
|
|
case FWTCODE_RREQB:
|
|
|
|
case FWTCODE_WREQB:
|
|
|
|
case FWTCODE_LREQ:
|
|
|
|
case FWTCODE_RRESB:
|
|
|
|
case FWTCODE_LRES:
|
|
|
|
hlen = 16;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
device_printf(sc->fc.dev, "Unknown tcode %d\n", fp->mode.common.tcode);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (len >= hlen) {
|
|
|
|
plen = fwohci_get_plen(sc, fp, hlen);
|
|
|
|
if (plen == 0)
|
|
|
|
goto out;
|
|
|
|
plen = (plen + 3) & ~3;
|
|
|
|
len -= plen;
|
|
|
|
} else {
|
|
|
|
plen = -hlen;
|
|
|
|
len -= hlen;
|
|
|
|
}
|
|
|
|
if(resCount > 0 || len > 0){
|
|
|
|
buf = malloc( dbch->xferq.psize,
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
|
|
|
if(buf == NULL){
|
|
|
|
printf("cannot malloc!\n");
|
|
|
|
free(db_tr->buf, M_DEVBUF);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
bcopy(ld, buf, plen);
|
|
|
|
poff = 0;
|
|
|
|
dbch->frag.buf = NULL;
|
|
|
|
dbch->frag.plen = 0;
|
|
|
|
dbch->frag.len = 0;
|
|
|
|
}else if(len < 0){
|
|
|
|
dbch->frag.buf = db_tr->buf;
|
|
|
|
if (plen < 0) {
|
|
|
|
#if 0
|
|
|
|
printf("plen < 0:"
|
|
|
|
"hlen: %d len: %d\n",
|
|
|
|
hlen, len);
|
|
|
|
#endif
|
|
|
|
dbch->frag.len = hlen + len;
|
|
|
|
dbch->frag.plen = -hlen;
|
|
|
|
} else {
|
|
|
|
dbch->frag.len = plen + len;
|
|
|
|
dbch->frag.plen = plen;
|
|
|
|
}
|
|
|
|
bcopy(ld, db_tr->buf, dbch->frag.len);
|
|
|
|
buf = NULL;
|
|
|
|
}else{
|
|
|
|
buf = db_tr->buf;
|
|
|
|
poff = ld - (u_int8_t *)buf;
|
|
|
|
dbch->frag.buf = NULL;
|
|
|
|
dbch->frag.plen = 0;
|
|
|
|
dbch->frag.len = 0;
|
|
|
|
}
|
|
|
|
ld += plen;
|
|
|
|
}
|
|
|
|
if( buf != NULL){
|
|
|
|
/* DMA result-code will be written at the tail of packet */
|
|
|
|
stat = ((struct fwohci_trailer *)(ld - sizeof(struct fwohci_trailer)))->stat;
|
|
|
|
spd = (stat >> 5) & 0x3;
|
|
|
|
stat &= 0x1f;
|
|
|
|
switch(stat){
|
|
|
|
case FWOHCIEV_ACKPEND:
|
|
|
|
#if 0
|
|
|
|
printf("fwohci_arcv: ack pending..\n");
|
|
|
|
#endif
|
|
|
|
/* fall through */
|
|
|
|
case FWOHCIEV_ACKCOMPL:
|
|
|
|
if( poff != 0 )
|
|
|
|
bcopy(buf+poff, buf, plen - 4);
|
|
|
|
fw_rcv(&sc->fc, buf, plen - sizeof(struct fwohci_trailer), 0, 0, spd);
|
|
|
|
break;
|
|
|
|
case FWOHCIEV_BUSRST:
|
|
|
|
free(buf, M_DEVBUF);
|
|
|
|
if (sc->fc.status != FWBUSRESET)
|
|
|
|
printf("got BUSRST packet!?\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
device_printf(sc->fc.dev, "Async DMA Receive error err = %02x %s\n", stat, fwohcicode[stat]);
|
|
|
|
#if 0 /* XXX */
|
|
|
|
goto out;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pcnt ++;
|
|
|
|
};
|
|
|
|
out:
|
|
|
|
if (resCount == 0) {
|
|
|
|
/* done on this buffer */
|
|
|
|
fwohci_add_rx_buf(db_tr, dbch->xferq.psize,
|
|
|
|
dbch->xferq.flag, 0, NULL);
|
|
|
|
dbch->bottom->db[0].db.desc.depend |= z;
|
|
|
|
dbch->bottom = db_tr;
|
|
|
|
db_tr = STAILQ_NEXT(db_tr, link);
|
|
|
|
dbch->top = db_tr;
|
|
|
|
dbch->buf_offset = 0;
|
|
|
|
} else {
|
|
|
|
dbch->buf_offset = dbch->xferq.psize - resCount;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* XXX make sure DMA is not dead */
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
if (pcnt < 1)
|
|
|
|
printf("fwohci_arcv: no packets\n");
|
|
|
|
#endif
|
|
|
|
splx(s);
|
|
|
|
}
|