2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-4-Clause
|
|
|
|
*
|
2003-04-17 03:38:03 +00:00
|
|
|
* Copyright (c) 2003 Hidetoshi Shimokawa
|
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.
|
2014-09-27 16:50:21 +00:00
|
|
|
*
|
2002-09-13 12:31:56 +00:00
|
|
|
* $FreeBSD$
|
|
|
|
*
|
|
|
|
*/
|
2002-11-12 10:02:50 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
Extract eventfilter declarations to sys/_eventfilter.h
This allows replacing "sys/eventfilter.h" includes with "sys/_eventfilter.h"
in other header files (e.g., sys/{bus,conf,cpu}.h) and reduces header
pollution substantially.
EVENTHANDLER_DECLARE and EVENTHANDLER_LIST_DECLAREs were moved out of .c
files into appropriate headers (e.g., sys/proc.h, powernv/opal.h).
As a side effect of reduced header pollution, many .c files and headers no
longer contain needed definitions. The remainder of the patch addresses
adding appropriate includes to fix those files.
LOCK_DEBUG and LOCK_FILE_LINE_ARG are moved to sys/_lock.h, as required by
sys/mutex.h since r326106 (but silently protected by header pollution prior
to this change).
No functional change (intended). Of course, any out of tree modules that
relied on header pollution for sys/eventhandler.h, sys/lock.h, or
sys/mutex.h inclusion need to be fixed. __FreeBSD_version has been bumped.
2019-05-20 00:38:23 +00:00
|
|
|
#include <sys/lock.h>
|
2002-09-13 12:31:56 +00:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/sockio.h>
|
2007-04-30 12:38:50 +00:00
|
|
|
#include <sys/sysctl.h>
|
2002-09-13 12:31:56 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/conf.h>
|
2003-04-17 03:38:03 +00:00
|
|
|
#include <sys/endian.h>
|
2007-06-06 14:31:36 +00:00
|
|
|
#include <sys/kdb.h>
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
#include <machine/bus.h>
|
2015-01-21 20:08:24 +00:00
|
|
|
#include <machine/md_var.h>
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
#include <dev/firewire/firewire.h>
|
|
|
|
#include <dev/firewire/firewirereg.h>
|
2003-04-17 03:38:03 +00:00
|
|
|
#include <dev/firewire/fwdma.h>
|
2002-09-13 12:31:56 +00:00
|
|
|
#include <dev/firewire/fwohcireg.h>
|
|
|
|
#include <dev/firewire/fwohcivar.h>
|
|
|
|
#include <dev/firewire/firewire_phy.h>
|
|
|
|
|
|
|
|
#undef OHCI_DEBUG
|
2002-11-12 10:02:50 +00:00
|
|
|
|
2014-06-28 03:56:17 +00:00
|
|
|
static int nocyclemaster;
|
2007-06-07 13:20:48 +00:00
|
|
|
int firewire_phydma_enable = 1;
|
2007-04-30 12:38:50 +00:00
|
|
|
SYSCTL_DECL(_hw_firewire);
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_INT(_hw_firewire, OID_AUTO, nocyclemaster, CTLFLAG_RWTUN,
|
|
|
|
&nocyclemaster, 0, "Do not send cycle start packets");
|
|
|
|
SYSCTL_INT(_hw_firewire, OID_AUTO, phydma_enable, CTLFLAG_RWTUN,
|
|
|
|
&firewire_phydma_enable, 0, "Allow physical request DMA from firewire");
|
2007-04-30 12:38:50 +00:00
|
|
|
|
2014-09-27 16:50:21 +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"};
|
|
|
|
static char dbcond[4][0x10] = {"NEV", "C=1", "C=0", "ALL"};
|
|
|
|
char fwohcicode[32][0x20]= {
|
|
|
|
"No stat", "Undef", "long", "miss Ack err",
|
|
|
|
"FIFO underrun", "FIFO 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", ""};
|
2003-04-17 03:38:03 +00:00
|
|
|
|
2003-06-15 04:09:26 +00:00
|
|
|
#define MAX_SPEED 3
|
2004-01-11 15:40:42 +00:00
|
|
|
extern char *linkspeed[];
|
2014-09-27 16:50:21 +00:00
|
|
|
uint32_t tagbit[4] = {1 << 28, 1 << 29, 1 << 30, 1 << 31};
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
static struct tcode_info tinfo[] = {
|
2007-06-06 14:31:36 +00:00
|
|
|
/* hdr_len block flag valid_response */
|
|
|
|
/* 0 WREQQ */ {16, FWTI_REQ | FWTI_TLABEL, FWTCODE_WRES},
|
|
|
|
/* 1 WREQB */ {16, FWTI_REQ | FWTI_TLABEL | FWTI_BLOCK_ASY, FWTCODE_WRES},
|
|
|
|
/* 2 WRES */ {12, FWTI_RES, 0xff},
|
|
|
|
/* 3 XXX */ { 0, 0, 0xff},
|
|
|
|
/* 4 RREQQ */ {12, FWTI_REQ | FWTI_TLABEL, FWTCODE_RRESQ},
|
|
|
|
/* 5 RREQB */ {16, FWTI_REQ | FWTI_TLABEL, FWTCODE_RRESB},
|
|
|
|
/* 6 RRESQ */ {16, FWTI_RES, 0xff},
|
|
|
|
/* 7 RRESB */ {16, FWTI_RES | FWTI_BLOCK_ASY, 0xff},
|
|
|
|
/* 8 CYCS */ { 0, 0, 0xff},
|
|
|
|
/* 9 LREQ */ {16, FWTI_REQ | FWTI_TLABEL | FWTI_BLOCK_ASY, FWTCODE_LRES},
|
|
|
|
/* a STREAM */ { 4, FWTI_REQ | FWTI_BLOCK_STR, 0xff},
|
|
|
|
/* b LRES */ {16, FWTI_RES | FWTI_BLOCK_ASY, 0xff},
|
|
|
|
/* c XXX */ { 0, 0, 0xff},
|
|
|
|
/* d XXX */ { 0, 0, 0xff},
|
|
|
|
/* e PHY */ {12, FWTI_REQ, 0xff},
|
|
|
|
/* f XXX */ { 0, 0, 0xff}
|
2002-09-13 12:31:56 +00:00
|
|
|
};
|
|
|
|
|
2014-09-27 16:50:21 +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
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
#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))
|
|
|
|
|
2004-01-06 14:30:47 +00:00
|
|
|
static void fwohci_ibr (struct firewire_comm *);
|
|
|
|
static void fwohci_db_init (struct fwohci_softc *, struct fwohci_dbch *);
|
|
|
|
static void fwohci_db_free (struct fwohci_dbch *);
|
|
|
|
static void fwohci_arcv (struct fwohci_softc *, struct fwohci_dbch *, int);
|
|
|
|
static void fwohci_txd (struct fwohci_softc *, struct fwohci_dbch *);
|
|
|
|
static void fwohci_start_atq (struct firewire_comm *);
|
|
|
|
static void fwohci_start_ats (struct firewire_comm *);
|
|
|
|
static void fwohci_start (struct fwohci_softc *, struct fwohci_dbch *);
|
2014-09-27 16:50:21 +00:00
|
|
|
static uint32_t fwphy_wrdata (struct fwohci_softc *, uint32_t, uint32_t);
|
|
|
|
static uint32_t fwphy_rddata (struct fwohci_softc *, uint32_t);
|
2004-01-06 14:30:47 +00:00
|
|
|
static int fwohci_rx_enable (struct fwohci_softc *, struct fwohci_dbch *);
|
|
|
|
static int fwohci_tx_enable (struct fwohci_softc *, struct fwohci_dbch *);
|
|
|
|
static int fwohci_irx_enable (struct firewire_comm *, int);
|
|
|
|
static int fwohci_irx_disable (struct firewire_comm *, int);
|
2003-04-17 03:38:03 +00:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2004-05-22 16:14:17 +00:00
|
|
|
static void fwohci_irx_post (struct firewire_comm *, uint32_t *);
|
2003-04-17 03:38:03 +00:00
|
|
|
#endif
|
2004-01-06 14:30:47 +00:00
|
|
|
static int fwohci_itxbuf_enable (struct firewire_comm *, int);
|
|
|
|
static int fwohci_itx_disable (struct firewire_comm *, int);
|
|
|
|
static void fwohci_timeout (void *);
|
|
|
|
static void fwohci_set_intr (struct firewire_comm *, int);
|
2003-04-17 03:38:03 +00:00
|
|
|
|
2004-01-06 14:30:47 +00:00
|
|
|
static int fwohci_add_rx_buf (struct fwohci_dbch *, struct fwohcidb_tr *, int, struct fwdma_alloc *);
|
|
|
|
static int fwohci_add_tx_buf (struct fwohci_dbch *, struct fwohcidb_tr *, int);
|
2014-09-27 16:50:21 +00:00
|
|
|
static void dump_db (struct fwohci_softc *, uint32_t);
|
|
|
|
static void print_db (struct fwohcidb_tr *, struct fwohcidb *, uint32_t , uint32_t);
|
|
|
|
static void dump_dma (struct fwohci_softc *, uint32_t);
|
2004-05-22 16:14:17 +00:00
|
|
|
static uint32_t fwohci_cyctimer (struct firewire_comm *);
|
2004-01-06 14:30:47 +00:00
|
|
|
static void fwohci_rbuf_update (struct fwohci_softc *, int);
|
|
|
|
static void fwohci_tbuf_update (struct fwohci_softc *, int);
|
|
|
|
void fwohci_txbufdb (struct fwohci_softc *, int , struct fw_bulkxfer *);
|
2007-06-06 14:31:36 +00:00
|
|
|
static void fwohci_task_busreset(void *, int);
|
|
|
|
static void fwohci_task_sid(void *, int);
|
|
|
|
static void fwohci_task_dma(void *, int);
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* memory allocated for DMA programs
|
|
|
|
*/
|
|
|
|
#define DMA_PROG_ALLOC (8 * PAGE_SIZE)
|
|
|
|
|
|
|
|
#define NDB FWMAXQUEUE
|
|
|
|
|
|
|
|
#define OHCI_VERSION 0x00
|
2003-03-24 04:06:21 +00:00
|
|
|
#define OHCI_ATRETRY 0x08
|
2002-09-13 12:31:56 +00:00
|
|
|
#define OHCI_CROMHDR 0x18
|
|
|
|
#define OHCI_BUS_OPT 0x20
|
2013-11-30 22:17:27 +00:00
|
|
|
#define OHCI_BUSIRMC (1U << 31)
|
2002-09-13 12:31:56 +00:00
|
|
|
#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
|
2015-01-21 20:08:24 +00:00
|
|
|
#define OHCI_PREQUPPER_MAX 0xffff0000
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
#define OHCI_SID_BUF 0x64
|
|
|
|
#define OHCI_SID_CNT 0x68
|
2013-11-30 22:17:27 +00:00
|
|
|
#define OHCI_SID_ERR (1U << 31)
|
2002-09-13 12:31:56 +00:00
|
|
|
#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
|
|
|
|
*/
|
2007-06-06 14:31:36 +00:00
|
|
|
/* XXX need lock for phy access */
|
2004-05-22 16:14:17 +00:00
|
|
|
static uint32_t
|
2014-09-27 16:50:21 +00:00
|
|
|
fwphy_wrdata(struct fwohci_softc *sc, uint32_t addr, uint32_t data)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t fun;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
addr &= 0xf;
|
|
|
|
data &= 0xff;
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
fun = (PHYDEV_WRCMD | (addr << PHYDEV_REGADDR) |
|
|
|
|
(data << PHYDEV_WRDATA));
|
2002-09-13 12:31:56 +00:00
|
|
|
OWRITE(sc, OHCI_PHYACCESS, fun);
|
|
|
|
DELAY(100);
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
return (fwphy_rddata(sc, addr));
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
|
2004-05-22 16:14:17 +00:00
|
|
|
static uint32_t
|
2002-09-13 12:31:56 +00:00
|
|
|
fwohci_set_bus_manager(struct firewire_comm *fc, u_int node)
|
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)fc;
|
|
|
|
int i;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t bm;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
#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);
|
2014-09-27 16:50:21 +00:00
|
|
|
if ((bm & 0x3f) == 0x3f)
|
2002-09-13 12:31:56 +00:00
|
|
|
bm = node;
|
2004-07-20 04:49:44 +00:00
|
|
|
if (firewire_debug)
|
2009-02-12 03:26:05 +00:00
|
|
|
device_printf(sc->fc.dev, "%s: %d->%d (loop=%d)\n",
|
|
|
|
__func__, bm, node, i);
|
2014-09-27 16:50:21 +00:00
|
|
|
return (bm);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
|
2004-05-22 16:14:17 +00:00
|
|
|
static uint32_t
|
2014-09-27 16:50:21 +00:00
|
|
|
fwphy_rddata(struct fwohci_softc *sc, u_int addr)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t fun, stat;
|
2002-12-31 10:00:36 +00:00
|
|
|
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);
|
2014-09-27 16:50:21 +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
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
if (i >= MAX_RETRY) {
|
2004-07-20 04:49:44 +00:00
|
|
|
if (firewire_debug)
|
2009-02-12 03:26:05 +00:00
|
|
|
device_printf(sc->fc.dev, "%s: failed(1).\n", __func__);
|
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) {
|
2004-07-20 04:49:44 +00:00
|
|
|
if (firewire_debug)
|
2009-02-12 03:26:05 +00:00
|
|
|
device_printf(sc->fc.dev, "%s: failed(2).\n", __func__);
|
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;
|
|
|
|
}
|
|
|
|
}
|
2009-02-12 03:26:05 +00:00
|
|
|
if (firewire_debug > 1 || retry >= MAX_RETRY)
|
2014-09-27 16:50:21 +00:00
|
|
|
device_printf(sc->fc.dev,
|
2009-02-12 03:26:05 +00:00
|
|
|
"%s:: 0x%x loop=%d, retry=%d\n",
|
|
|
|
__func__, addr, i, retry);
|
2002-12-31 10:00:36 +00:00
|
|
|
#undef MAX_RETRY
|
2014-09-27 16:50:21 +00:00
|
|
|
return ((fun >> PHYDEV_RDDATA) & 0xff);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/* Device specific ioctl. */
|
|
|
|
int
|
2004-06-16 09:47:26 +00:00
|
|
|
fwohci_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, fw_proc *td)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct firewire_softc *sc;
|
|
|
|
struct fwohci_softc *fc;
|
|
|
|
int unit = DEV2UNIT(dev);
|
|
|
|
int err = 0;
|
2014-09-27 16:50:21 +00:00
|
|
|
struct fw_reg_req_t *reg = (struct fw_reg_req_t *) data;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t *dmach = (uint32_t *) data;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
sc = devclass_get_softc(firewire_devclass, unit);
|
2014-09-27 16:50:21 +00:00
|
|
|
if (sc == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
fc = (struct fwohci_softc *)sc->fc;
|
|
|
|
|
|
|
|
if (!data)
|
2014-09-27 16:50:21 +00:00
|
|
|
return (EINVAL);
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case FWOHCI_WRREG:
|
|
|
|
#define OHCI_MAX_REG 0x800
|
2014-09-27 16:50:21 +00:00
|
|
|
if (reg->addr <= OHCI_MAX_REG) {
|
2002-09-13 12:31:56 +00:00
|
|
|
OWRITE(fc, reg->addr, reg->data);
|
|
|
|
reg->data = OREAD(fc, reg->addr);
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
2002-09-13 12:31:56 +00:00
|
|
|
err = EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FWOHCI_RDREG:
|
2014-09-27 16:50:21 +00:00
|
|
|
if (reg->addr <= OHCI_MAX_REG) {
|
2002-09-13 12:31:56 +00:00
|
|
|
reg->data = OREAD(fc, reg->addr);
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
2002-09-13 12:31:56 +00:00
|
|
|
err = EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
/* Read DMA descriptors for debug */
|
|
|
|
case DUMPDMA:
|
2014-09-27 16:50:21 +00:00
|
|
|
if (*dmach <= OHCI_MAX_DMA_CH) {
|
2002-09-13 12:31:56 +00:00
|
|
|
dump_dma(fc, *dmach);
|
|
|
|
dump_db(fc, *dmach);
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
2002-09-13 12:31:56 +00:00
|
|
|
err = EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
2003-08-19 08:47:49 +00:00
|
|
|
/* Read/Write Phy registers */
|
|
|
|
#define OHCI_MAX_PHY_REG 0xf
|
|
|
|
case FWOHCI_RDPHYREG:
|
|
|
|
if (reg->addr <= OHCI_MAX_PHY_REG)
|
|
|
|
reg->data = fwphy_rddata(fc, reg->addr);
|
|
|
|
else
|
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
case FWOHCI_WRPHYREG:
|
|
|
|
if (reg->addr <= OHCI_MAX_PHY_REG)
|
|
|
|
reg->data = fwphy_wrdata(fc, reg->addr, reg->data);
|
|
|
|
else
|
|
|
|
err = EINVAL;
|
|
|
|
break;
|
2002-09-13 12:31:56 +00:00
|
|
|
default:
|
2003-08-19 08:47:49 +00:00
|
|
|
err = EINVAL;
|
2002-09-13 12:31:56 +00:00
|
|
|
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)
|
|
|
|
{
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t reg, reg2;
|
2003-01-01 08:25:32 +00:00
|
|
|
int e1394a = 1;
|
2014-09-27 16:50:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 .
|
|
|
|
*/
|
2003-01-01 08:25:32 +00:00
|
|
|
OWRITE(sc, OHCI_HCCCTL, OHCI_HCC_LPS);
|
2007-03-19 03:35:45 +00:00
|
|
|
DELAY(500);
|
|
|
|
|
2003-01-01 08:25:32 +00:00
|
|
|
reg = fwphy_rddata(sc, FW_PHY_SPD_REG);
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
if ((reg >> 5) != 7) {
|
2003-01-01 08:25:32 +00:00
|
|
|
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);
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
2003-01-01 08:25:32 +00:00
|
|
|
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
|
2004-07-20 04:49:44 +00:00
|
|
|
if (firewire_debug)
|
2003-01-01 08:25:32 +00:00
|
|
|
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);
|
2014-09-27 16:50:21 +00:00
|
|
|
if ((reg >> 5) == 7) {
|
2003-01-01 08:25:32 +00:00
|
|
|
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;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t reg, reg2;
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fwohcidb_tr *db_tr;
|
2003-01-01 08:25:32 +00:00
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
/* Disable interrupts */
|
2003-01-01 08:25:32 +00:00
|
|
|
OWRITE(sc, FWOHCI_INTMASKCLR, ~0);
|
|
|
|
|
2004-05-21 09:12:07 +00:00
|
|
|
/* Now stopping all DMA channels */
|
2014-09-27 16:50:21 +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);
|
2003-01-01 08:25:32 +00:00
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
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-01 08:25:32 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 03:41:25 +00:00
|
|
|
/* FLUSH FIFO and reset Transmitter/Receiver */
|
2003-01-01 08:25:32 +00:00
|
|
|
OWRITE(sc, OHCI_HCCCTL, OHCI_HCC_RESET);
|
2004-07-20 04:49:44 +00:00
|
|
|
if (firewire_debug)
|
2003-01-01 08:25:32 +00:00
|
|
|
device_printf(dev, "resetting OHCI...");
|
|
|
|
i = 0;
|
2014-09-27 16:50:21 +00:00
|
|
|
while (OREAD(sc, OHCI_HCCCTL) & OHCI_HCC_RESET) {
|
2003-01-01 08:25:32 +00:00
|
|
|
if (i++ > 100) break;
|
|
|
|
DELAY(1000);
|
|
|
|
}
|
2004-07-20 04:49:44 +00:00
|
|
|
if (firewire_debug)
|
2003-01-01 08:25:32 +00:00
|
|
|
printf("done (loop=%d)\n", i);
|
|
|
|
|
2003-01-05 06:21:30 +00:00
|
|
|
/* Probe phy */
|
|
|
|
fwohci_probe_phy(sc, dev);
|
|
|
|
|
|
|
|
/* Probe link */
|
2014-09-27 16:50:21 +00:00
|
|
|
reg = OREAD(sc, OHCI_BUS_OPT);
|
2003-01-01 08:25:32 +00:00
|
|
|
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));
|
|
|
|
}
|
2004-07-20 04:49:44 +00:00
|
|
|
if (firewire_debug)
|
2003-01-01 08:25:32 +00:00
|
|
|
device_printf(dev, "BUS_OPT 0x%x -> 0x%x\n", reg, reg2);
|
2014-09-27 16:50:21 +00:00
|
|
|
OWRITE(sc, OHCI_BUS_OPT, reg2);
|
2003-01-01 08:25:32 +00:00
|
|
|
|
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]);
|
2003-04-17 03:38:03 +00:00
|
|
|
OWRITE(sc, OHCI_CROMPTR, sc->crom_dma.bus_addr);
|
2003-01-01 08:25:32 +00:00
|
|
|
OWRITE(sc, OHCI_HCCCTLCLR, OHCI_HCC_BIGEND);
|
|
|
|
OWRITE(sc, OHCI_HCCCTL, OHCI_HCC_POSTWR);
|
2003-04-17 03:38:03 +00:00
|
|
|
OWRITE(sc, OHCI_SID_BUF, sc->sid_dma.bus_addr);
|
2003-01-01 08:25:32 +00:00
|
|
|
OWRITE(sc, OHCI_LNKCTL, OHCI_CNTL_SID);
|
|
|
|
|
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);
|
2003-06-28 11:11:36 +00:00
|
|
|
|
2003-01-05 06:21:30 +00:00
|
|
|
/* AT Retries */
|
|
|
|
OWRITE(sc, FWOHCI_RETRY,
|
|
|
|
/* CycleLimit PhyRespRetries ATRespRetries ATReqRetries */
|
2014-09-27 16:50:21 +00:00
|
|
|
(0xffff << 16) | (0x0f << 8) | (0x0f << 4) | 0x0f);
|
2003-06-28 11:11:36 +00:00
|
|
|
|
|
|
|
sc->atrq.top = STAILQ_FIRST(&sc->atrq.db_trq);
|
|
|
|
sc->atrs.top = STAILQ_FIRST(&sc->atrs.db_trq);
|
|
|
|
sc->atrq.bottom = sc->atrq.top;
|
|
|
|
sc->atrs.bottom = sc->atrs.top;
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0, db_tr = sc->atrq.top; i < sc->atrq.ndb;
|
|
|
|
i++, db_tr = STAILQ_NEXT(db_tr, link)) {
|
2003-01-01 08:25:32 +00:00
|
|
|
db_tr->xfer = NULL;
|
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0, db_tr = sc->atrs.top; i < sc->atrs.ndb;
|
|
|
|
i++, db_tr = STAILQ_NEXT(db_tr, link)) {
|
2003-01-01 08:25:32 +00:00
|
|
|
db_tr->xfer = NULL;
|
|
|
|
}
|
|
|
|
|
2004-05-21 09:12:07 +00:00
|
|
|
/* Enable interrupts */
|
2007-06-06 14:31:36 +00:00
|
|
|
sc->intmask = (OHCI_INT_ERR | OHCI_INT_PHY_SID
|
2014-09-27 16:50:21 +00:00
|
|
|
| OHCI_INT_DMA_ATRQ | OHCI_INT_DMA_ATRS
|
2003-01-01 08:25:32 +00:00
|
|
|
| OHCI_INT_DMA_PRRQ | OHCI_INT_DMA_PRRS
|
|
|
|
| OHCI_INT_PHY_BUS_R | OHCI_INT_PW_ERR);
|
2007-06-06 14:31:36 +00:00
|
|
|
sc->intmask |= OHCI_INT_DMA_IR | OHCI_INT_DMA_IT;
|
|
|
|
sc->intmask |= OHCI_INT_CYC_LOST | OHCI_INT_PHY_INT;
|
|
|
|
OWRITE(sc, FWOHCI_INTMASK, sc->intmask);
|
2003-01-01 08:25:32 +00:00
|
|
|
fwohci_set_intr(&sc->fc, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fwohci_init(struct fwohci_softc *sc, device_t dev)
|
|
|
|
{
|
2003-10-31 05:05:12 +00:00
|
|
|
int i, mver;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t reg;
|
|
|
|
uint8_t ui[8];
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-10-31 05:05:12 +00:00
|
|
|
/* OHCI version */
|
2002-09-13 12:31:56 +00:00
|
|
|
reg = OREAD(sc, OHCI_VERSION);
|
2003-10-31 05:05:12 +00:00
|
|
|
mver = (reg >> 16) & 0xff;
|
2002-09-13 12:31:56 +00:00
|
|
|
device_printf(dev, "OHCI version %x.%x (ROM=%d)\n",
|
2014-09-27 16:50:21 +00:00
|
|
|
mver, reg & 0xff, (reg >> 24) & 1);
|
2003-10-31 05:05:12 +00:00
|
|
|
if (mver < 1 || mver > 9) {
|
2003-08-04 05:43:02 +00:00
|
|
|
device_printf(dev, "invalid OHCI version\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
2004-05-21 09:12:07 +00:00
|
|
|
/* Available Isochronous DMA channel probe */
|
2003-01-29 15:32:35 +00:00
|
|
|
OWRITE(sc, OHCI_IT_MASK, 0xffffffff);
|
|
|
|
OWRITE(sc, OHCI_IR_MASK, 0xffffffff);
|
|
|
|
reg = OREAD(sc, OHCI_IT_MASK) & OREAD(sc, OHCI_IR_MASK);
|
|
|
|
OWRITE(sc, OHCI_IT_MASKCLR, 0xffffffff);
|
|
|
|
OWRITE(sc, OHCI_IR_MASKCLR, 0xffffffff);
|
|
|
|
for (i = 0; i < 0x20; i++)
|
|
|
|
if ((reg & (1 << i)) == 0)
|
|
|
|
break;
|
2002-09-13 12:31:56 +00:00
|
|
|
sc->fc.nisodma = i;
|
2004-05-21 09:12:07 +00:00
|
|
|
device_printf(dev, "No. of Isochronous channels is %d.\n", i);
|
2003-08-12 13:01:27 +00:00
|
|
|
if (i == 0)
|
|
|
|
return (ENXIO);
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
sc->fc.arq = &sc->arrq.xferq;
|
|
|
|
sc->fc.ars = &sc->arrs.xferq;
|
|
|
|
sc->fc.atq = &sc->atrq.xferq;
|
|
|
|
sc->fc.ats = &sc->atrs.xferq;
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
sc->arrq.xferq.psize = roundup2(FWPMAX_S400, PAGE_SIZE);
|
|
|
|
sc->arrs.xferq.psize = roundup2(FWPMAX_S400, PAGE_SIZE);
|
|
|
|
sc->atrq.xferq.psize = roundup2(FWPMAX_S400, PAGE_SIZE);
|
|
|
|
sc->atrs.xferq.psize = roundup2(FWPMAX_S400, PAGE_SIZE);
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
sc->arrq.xferq.start = NULL;
|
|
|
|
sc->arrs.xferq.start = NULL;
|
|
|
|
sc->atrq.xferq.start = fwohci_start_atq;
|
|
|
|
sc->atrs.xferq.start = fwohci_start_ats;
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
sc->arrq.xferq.buf = NULL;
|
|
|
|
sc->arrs.xferq.buf = NULL;
|
|
|
|
sc->atrq.xferq.buf = NULL;
|
|
|
|
sc->atrs.xferq.buf = NULL;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-08-01 04:51:21 +00:00
|
|
|
sc->arrq.xferq.dmach = -1;
|
|
|
|
sc->arrs.xferq.dmach = -1;
|
|
|
|
sc->atrq.xferq.dmach = -1;
|
|
|
|
sc->atrs.xferq.dmach = -1;
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
sc->arrq.ndesc = 1;
|
|
|
|
sc->arrs.ndesc = 1;
|
2003-02-09 17:11:55 +00:00
|
|
|
sc->atrq.ndesc = 8; /* equal to maximum of mbuf chains */
|
|
|
|
sc->atrs.ndesc = 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;
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < sc->fc.nisodma; i++) {
|
2002-09-13 12:31:56 +00:00
|
|
|
sc->fc.it[i] = &sc->it[i].xferq;
|
|
|
|
sc->fc.ir[i] = &sc->ir[i].xferq;
|
2003-08-01 04:51:21 +00:00
|
|
|
sc->it[i].xferq.dmach = i;
|
|
|
|
sc->ir[i].xferq.dmach = i;
|
2002-09-13 12:31:56 +00:00
|
|
|
sc->it[i].ndb = 0;
|
|
|
|
sc->ir[i].ndb = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->fc.tcode = tinfo;
|
2003-04-17 03:38:03 +00:00
|
|
|
sc->fc.dev = dev;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
sc->fc.config_rom = fwdma_malloc(&sc->fc, CROMSIZE, CROMSIZE,
|
2011-03-11 22:19:49 +00:00
|
|
|
&sc->crom_dma, BUS_DMA_WAITOK | BUS_DMA_COHERENT);
|
2014-09-27 16:50:21 +00:00
|
|
|
if (sc->fc.config_rom == NULL) {
|
2003-04-17 03:38:03 +00:00
|
|
|
device_printf(dev, "config_rom alloc failed.");
|
2002-09-13 12:31:56 +00:00
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
2003-06-15 04:09:26 +00:00
|
|
|
#if 0
|
|
|
|
bzero(&sc->fc.config_rom[0], CROMSIZE);
|
2002-09-13 12:31:56 +00:00
|
|
|
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);
|
2003-04-17 03:38:03 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2016-05-03 03:41:25 +00:00
|
|
|
/* SID receive buffer must align 2^11 */
|
2002-09-13 12:31:56 +00:00
|
|
|
#define OHCI_SIDSIZE (1 << 11)
|
2003-04-17 03:38:03 +00:00
|
|
|
sc->sid_buf = fwdma_malloc(&sc->fc, OHCI_SIDSIZE, OHCI_SIDSIZE,
|
2011-03-11 22:19:49 +00:00
|
|
|
&sc->sid_dma, BUS_DMA_WAITOK | BUS_DMA_COHERENT);
|
2003-04-17 03:38:03 +00:00
|
|
|
if (sc->sid_buf == NULL) {
|
|
|
|
device_printf(dev, "sid_buf alloc failed.");
|
2003-01-01 04:23:54 +00:00
|
|
|
return ENOMEM;
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
|
2004-05-22 16:14:17 +00:00
|
|
|
fwdma_malloc(&sc->fc, sizeof(uint32_t), sizeof(uint32_t),
|
2014-09-27 16:50:21 +00:00
|
|
|
&sc->dummy_dma, BUS_DMA_WAITOK);
|
2003-04-17 03:38:03 +00:00
|
|
|
|
|
|
|
if (sc->dummy_dma.v_addr == NULL) {
|
|
|
|
device_printf(dev, "dummy_dma alloc failed.");
|
2003-01-23 13:34:40 +00:00
|
|
|
return ENOMEM;
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
|
|
|
|
fwohci_db_init(sc, &sc->arrq);
|
2003-01-01 04:23:54 +00:00
|
|
|
if ((sc->arrq.flags & FWOHCI_DBCH_INIT) == 0)
|
|
|
|
return ENOMEM;
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
fwohci_db_init(sc, &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
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
fwohci_db_init(sc, &sc->atrq);
|
2003-01-01 04:23:54 +00:00
|
|
|
if ((sc->atrq.flags & FWOHCI_DBCH_INIT) == 0)
|
|
|
|
return ENOMEM;
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
fwohci_db_init(sc, &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);
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < 8; i++)
|
2003-01-25 14:47:33 +00:00
|
|
|
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;
|
2003-04-17 03:38:03 +00:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2002-09-13 12:31:56 +00:00
|
|
|
sc->fc.irx_post = fwohci_irx_post;
|
2003-04-17 03:38:03 +00:00
|
|
|
#else
|
|
|
|
sc->fc.irx_post = NULL;
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
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-04-17 03:38:03 +00:00
|
|
|
sc->intmask = sc->irstat = sc->itstat = 0;
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
/* Init task queue */
|
|
|
|
sc->fc.taskqueue = taskqueue_create_fast("fw_taskq", M_WAITOK,
|
|
|
|
taskqueue_thread_enqueue, &sc->fc.taskqueue);
|
|
|
|
taskqueue_start_threads(&sc->fc.taskqueue, 1, PI_NET, "fw%d_taskq",
|
2014-09-27 16:50:21 +00:00
|
|
|
device_get_unit(dev));
|
2007-06-06 14:31:36 +00:00
|
|
|
TASK_INIT(&sc->fwohci_task_busreset, 2, fwohci_task_busreset, sc);
|
|
|
|
TASK_INIT(&sc->fwohci_task_sid, 1, fwohci_task_sid, sc);
|
|
|
|
TASK_INIT(&sc->fwohci_task_dma, 0, fwohci_task_dma, sc);
|
|
|
|
|
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
|
|
|
{
|
2021-12-09 16:36:45 +00:00
|
|
|
struct fwohci_softc *sc __unused;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
sc = (struct fwohci_softc *)arg;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t
|
2002-11-12 05:52:01 +00:00
|
|
|
fwohci_cyctimer(struct firewire_comm *fc)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)fc;
|
2014-09-27 16:50:21 +00:00
|
|
|
return (OREAD(sc, OHCI_CYCLETIMER));
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
|
2003-01-01 04:23:54 +00:00
|
|
|
int
|
|
|
|
fwohci_detach(struct fwohci_softc *sc, device_t dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
if (sc->sid_buf != NULL)
|
|
|
|
fwdma_free(&sc->fc, &sc->sid_dma);
|
|
|
|
if (sc->fc.config_rom != NULL)
|
|
|
|
fwdma_free(&sc->fc, &sc->crom_dma);
|
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);
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < sc->fc.nisodma; i++) {
|
2003-01-01 04:23:54 +00:00
|
|
|
fwohci_db_free(&sc->it[i]);
|
|
|
|
fwohci_db_free(&sc->ir[i]);
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
if (sc->fc.taskqueue != NULL) {
|
|
|
|
taskqueue_drain(sc->fc.taskqueue, &sc->fwohci_task_busreset);
|
|
|
|
taskqueue_drain(sc->fc.taskqueue, &sc->fwohci_task_sid);
|
|
|
|
taskqueue_drain(sc->fc.taskqueue, &sc->fwohci_task_dma);
|
|
|
|
taskqueue_drain(sc->fc.taskqueue, &sc->fc.task_timeout);
|
|
|
|
taskqueue_free(sc->fc.taskqueue);
|
|
|
|
sc->fc.taskqueue = NULL;
|
|
|
|
}
|
2003-01-01 04:23:54 +00:00
|
|
|
|
|
|
|
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)
|
2014-09-27 16:50:21 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
static void
|
|
|
|
fwohci_execute_db(void *arg, bus_dma_segment_t *segs, int nseg, int error)
|
|
|
|
{
|
|
|
|
struct fwohcidb_tr *db_tr;
|
2003-10-02 04:06:56 +00:00
|
|
|
struct fwohcidb *db;
|
2003-04-17 03:38:03 +00:00
|
|
|
bus_dma_segment_t *s;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
db_tr = (struct fwohcidb_tr *)arg;
|
|
|
|
db = &db_tr->db[db_tr->dbcnt];
|
|
|
|
if (error) {
|
|
|
|
if (firewire_debug || error != EFBIG)
|
|
|
|
printf("fwohci_execute_db: error=%d\n", error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < nseg; i++) {
|
|
|
|
s = &segs[i];
|
|
|
|
FWOHCI_DMA_WRITE(db->db.desc.addr, s->ds_addr);
|
|
|
|
FWOHCI_DMA_WRITE(db->db.desc.cmd, s->ds_len);
|
|
|
|
FWOHCI_DMA_WRITE(db->db.desc.res, 0);
|
|
|
|
db++;
|
|
|
|
db_tr->dbcnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_execute_db2(void *arg, bus_dma_segment_t *segs, int nseg,
|
2014-09-27 16:50:21 +00:00
|
|
|
bus_size_t size, int error)
|
2003-04-17 03:38:03 +00:00
|
|
|
{
|
|
|
|
fwohci_execute_db(arg, segs, nseg, error);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2015-01-21 20:08:24 +00:00
|
|
|
int i;
|
2003-10-02 04:06:56 +00:00
|
|
|
int tcode, hdr_len, pl_off;
|
2002-09-13 12:31:56 +00:00
|
|
|
int fsegment = -1;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t off;
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct fw_pkt *fp;
|
2003-10-02 04:06:56 +00:00
|
|
|
struct fwohci_txpkthdr *ohcifp;
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fwohcidb_tr *db_tr;
|
2003-10-02 04:06:56 +00:00
|
|
|
struct fwohcidb *db;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t *ld;
|
2002-09-13 12:31:56 +00:00
|
|
|
struct tcode_info *info;
|
2003-01-04 10:21:11 +00:00
|
|
|
static int maxdesc=0;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GLOCK_ASSERT(&sc->fc);
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
if (&sc->atrq == dbch) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ATQOFF;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else if (&sc->atrs == dbch) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ATSOFF;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dbch->flags & FWOHCI_DBCH_FULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
db_tr = dbch->top;
|
|
|
|
txloop:
|
|
|
|
xfer = STAILQ_FIRST(&dbch->xferq.q);
|
2014-09-27 16:50:21 +00:00
|
|
|
if (xfer == NULL) {
|
2002-09-13 12:31:56 +00:00
|
|
|
goto kick;
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
#if 0
|
2014-09-27 16:50:21 +00:00
|
|
|
if (dbch->xferq.queued == 0) {
|
2002-09-13 12:31:56 +00:00
|
|
|
device_printf(sc->fc.dev, "TX queue empty\n");
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
STAILQ_REMOVE_HEAD(&dbch->xferq.q, link);
|
|
|
|
db_tr->xfer = xfer;
|
2007-06-06 14:31:36 +00:00
|
|
|
xfer->flag = FWXF_START;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
fp = &xfer->send.hdr;
|
2002-09-13 12:31:56 +00:00
|
|
|
tcode = fp->mode.common.tcode;
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
ohcifp = (struct fwohci_txpkthdr *) db_tr->db[1].db.immed;
|
2002-09-13 12:31:56 +00:00
|
|
|
info = &tinfo[tcode];
|
2003-04-17 03:38:03 +00:00
|
|
|
hdr_len = pl_off = info->hdr_len;
|
2003-08-20 03:11:37 +00:00
|
|
|
|
|
|
|
ld = &ohcifp->mode.ld[0];
|
|
|
|
ld[0] = ld[1] = ld[2] = ld[3] = 0;
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < pl_off; i+= 4)
|
2003-08-20 03:11:37 +00:00
|
|
|
ld[i/4] = fp->mode.ld[i/4];
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
ohcifp->mode.common.spd = xfer->send.spd & 0x7;
|
2014-09-27 16:50:21 +00:00
|
|
|
if (tcode == FWTCODE_STREAM) {
|
2002-09-13 12:31:56 +00:00
|
|
|
hdr_len = 8;
|
2003-04-17 03:38:03 +00:00
|
|
|
ohcifp->mode.stream.len = fp->mode.stream.len;
|
2002-09-13 12:31:56 +00:00
|
|
|
} else if (tcode == FWTCODE_PHY) {
|
|
|
|
hdr_len = 12;
|
2003-08-20 03:11:37 +00:00
|
|
|
ld[1] = fp->mode.ld[1];
|
|
|
|
ld[2] = fp->mode.ld[2];
|
2002-09-13 12:31:56 +00:00
|
|
|
ohcifp->mode.common.spd = 0;
|
|
|
|
ohcifp->mode.common.tcode = FWOHCITCODE_PHY;
|
|
|
|
} else {
|
2003-04-17 03:38:03 +00:00
|
|
|
ohcifp->mode.asycomm.dst = fp->mode.hdr.dst;
|
2002-09-13 12:31:56 +00:00
|
|
|
ohcifp->mode.asycomm.srcbus = OHCI_ASYSRCBUS;
|
|
|
|
ohcifp->mode.asycomm.tlrt |= FWRETRY_X;
|
|
|
|
}
|
|
|
|
db = &db_tr->db[0];
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_WRITE(db->db.desc.cmd,
|
|
|
|
OHCI_OUTPUT_MORE | OHCI_KEY_ST2 | hdr_len);
|
2003-08-20 03:11:37 +00:00
|
|
|
FWOHCI_DMA_WRITE(db->db.desc.addr, 0);
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_WRITE(db->db.desc.res, 0);
|
2016-05-03 03:41:25 +00:00
|
|
|
/* Specify bound timer of asy. response */
|
2014-09-27 16:50:21 +00:00
|
|
|
if (&sc->atrs == dbch) {
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_WRITE(db->db.desc.res,
|
|
|
|
(OREAD(sc, OHCI_CYCLETIMER) >> 12) + (1 << 13));
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
|
|
|
if (tcode == FWTCODE_WREQQ || tcode == FWTCODE_RRESQ)
|
|
|
|
hdr_len = 12;
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < hdr_len/4; i++)
|
2003-08-20 03:11:37 +00:00
|
|
|
FWOHCI_DMA_WRITE(ld[i], ld[i]);
|
2003-04-17 03:38:03 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-03-06 05:06:44 +00:00
|
|
|
again:
|
2002-09-13 12:31:56 +00:00
|
|
|
db_tr->dbcnt = 2;
|
|
|
|
db = &db_tr->db[db_tr->dbcnt];
|
2003-10-02 04:06:56 +00:00
|
|
|
if (xfer->send.pay_len > 0) {
|
2003-04-17 03:38:03 +00:00
|
|
|
int err;
|
|
|
|
/* handle payload */
|
2002-09-13 12:31:56 +00:00
|
|
|
if (xfer->mbuf == NULL) {
|
2003-04-17 03:38:03 +00:00
|
|
|
err = bus_dmamap_load(dbch->dmat, db_tr->dma_map,
|
2003-10-02 04:06:56 +00:00
|
|
|
&xfer->send.payload[0], xfer->send.pay_len,
|
2003-04-17 03:38:03 +00:00
|
|
|
fwohci_execute_db, db_tr,
|
|
|
|
/*flags*/0);
|
2002-09-13 12:31:56 +00:00
|
|
|
} else {
|
2003-03-06 05:06:44 +00:00
|
|
|
/* XXX we can handle only 6 (=8-2) mbuf chains */
|
2003-04-17 03:38:03 +00:00
|
|
|
err = bus_dmamap_load_mbuf(dbch->dmat, db_tr->dma_map,
|
|
|
|
xfer->mbuf,
|
|
|
|
fwohci_execute_db2, db_tr,
|
|
|
|
/* flags */0);
|
|
|
|
if (err == EFBIG) {
|
|
|
|
struct mbuf *m0;
|
|
|
|
|
|
|
|
if (firewire_debug)
|
|
|
|
device_printf(sc->fc.dev, "EFBIG.\n");
|
2012-12-04 09:32:43 +00:00
|
|
|
m0 = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
|
2003-04-17 03:38:03 +00:00
|
|
|
if (m0 != NULL) {
|
2003-03-06 05:06:44 +00:00
|
|
|
m_copydata(xfer->mbuf, 0,
|
|
|
|
xfer->mbuf->m_pkthdr.len,
|
2003-04-17 03:38:03 +00:00
|
|
|
mtod(m0, caddr_t));
|
2014-09-27 16:50:21 +00:00
|
|
|
m0->m_len = m0->m_pkthdr.len =
|
2003-03-06 05:06:44 +00:00
|
|
|
xfer->mbuf->m_pkthdr.len;
|
|
|
|
m_freem(xfer->mbuf);
|
2003-04-17 03:38:03 +00:00
|
|
|
xfer->mbuf = m0;
|
2003-03-06 05:06:44 +00:00
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
device_printf(sc->fc.dev, "m_getcl failed.\n");
|
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
if (err)
|
|
|
|
printf("dmamap_load: err=%d\n", err);
|
|
|
|
bus_dmamap_sync(dbch->dmat, db_tr->dma_map,
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
|
|
|
#if 0 /* OHCI_OUTPUT_MODE == 0 */
|
|
|
|
for (i = 2; i < db_tr->dbcnt; i++)
|
|
|
|
FWOHCI_DMA_SET(db_tr->db[i].db.desc.cmd,
|
|
|
|
OHCI_OUTPUT_MORE);
|
|
|
|
#endif
|
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;
|
2004-07-20 04:49:44 +00:00
|
|
|
if (firewire_debug)
|
2009-02-01 23:28:52 +00:00
|
|
|
device_printf(sc->fc.dev, "%s: maxdesc %d\n", __func__, maxdesc);
|
2003-01-04 10:21:11 +00:00
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
/* last db */
|
|
|
|
LAST_DB(db_tr, db);
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_SET(db->db.desc.cmd,
|
|
|
|
OHCI_OUTPUT_LAST | OHCI_INTERRUPT_ALWAYS | OHCI_BRANCH_ALWAYS);
|
|
|
|
FWOHCI_DMA_WRITE(db->db.desc.depend,
|
|
|
|
STAILQ_NEXT(db_tr, link)->bus_addr);
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
if (fsegment == -1)
|
2002-09-13 12:31:56 +00:00
|
|
|
fsegment = db_tr->dbcnt;
|
|
|
|
if (dbch->pdb_tr != NULL) {
|
|
|
|
LAST_DB(dbch->pdb_tr, db);
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_SET(db->db.desc.depend, db_tr->dbcnt);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
dbch->xferq.queued++;
|
2002-09-13 12:31:56 +00:00
|
|
|
dbch->pdb_tr = db_tr;
|
|
|
|
db_tr = STAILQ_NEXT(db_tr, link);
|
2014-09-27 16:50:21 +00:00
|
|
|
if (db_tr != dbch->bottom) {
|
2002-09-13 12:31:56 +00:00
|
|
|
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:
|
|
|
|
/* kick asy q */
|
2003-04-17 03:38:03 +00:00
|
|
|
fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_PREREAD);
|
|
|
|
fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_PREWRITE);
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
if (dbch->xferq.flag & FWXFERQ_RUNNING) {
|
2002-09-13 12:31:56 +00:00
|
|
|
OWRITE(sc, OHCI_DMACTL(off), OHCI_CNTL_DMA_WAKE);
|
|
|
|
} else {
|
2004-07-20 04:49:44 +00:00
|
|
|
if (firewire_debug)
|
2002-12-06 02:17:30 +00:00
|
|
|
device_printf(sc->fc.dev, "start AT DMA status=%x\n",
|
2002-09-13 12:31:56 +00:00
|
|
|
OREAD(sc, OHCI_DMACTL(off)));
|
2003-04-17 03:38:03 +00:00
|
|
|
OWRITE(sc, OHCI_DMACMD(off), dbch->top->bus_addr | fsegment);
|
2002-09-13 12:31:56 +00:00
|
|
|
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;
|
|
|
|
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;
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GLOCK(&sc->fc);
|
2014-09-27 16:50:21 +00:00
|
|
|
fwohci_start(sc, &(sc->atrq));
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GUNLOCK(&sc->fc);
|
2002-09-13 12:31:56 +00:00
|
|
|
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;
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GLOCK(&sc->fc);
|
2014-09-27 16:50:21 +00:00
|
|
|
fwohci_start(sc, &(sc->atrs));
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GUNLOCK(&sc->fc);
|
2002-09-13 12:31:56 +00:00
|
|
|
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
|
|
|
{
|
2003-04-17 03:38:03 +00:00
|
|
|
int s, ch, err = 0;
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fwohcidb_tr *tr;
|
2003-10-02 04:06:56 +00:00
|
|
|
struct fwohcidb *db;
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fw_xfer *xfer;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t off;
|
2003-04-17 03:38:03 +00:00
|
|
|
u_int stat, status;
|
2002-09-13 12:31:56 +00:00
|
|
|
int packets;
|
|
|
|
struct firewire_comm *fc = (struct firewire_comm *)sc;
|
2003-04-17 03:38:03 +00:00
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
if (&sc->atrq == dbch) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ATQOFF;
|
2003-04-17 03:38:03 +00:00
|
|
|
ch = ATRQ_CH;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else if (&sc->atrs == dbch) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ATSOFF;
|
2003-04-17 03:38:03 +00:00
|
|
|
ch = ATRS_CH;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
s = splfw();
|
|
|
|
tr = dbch->bottom;
|
|
|
|
packets = 0;
|
2003-04-17 03:38:03 +00:00
|
|
|
fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_POSTREAD);
|
|
|
|
fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_POSTWRITE);
|
2014-09-27 16:50:21 +00:00
|
|
|
while (dbch->xferq.queued > 0) {
|
2002-09-13 12:31:56 +00:00
|
|
|
LAST_DB(tr, db);
|
2003-04-17 03:38:03 +00:00
|
|
|
status = FWOHCI_DMA_READ(db->db.desc.res) >> OHCI_STATUS_SHIFT;
|
2014-09-27 16:50:21 +00:00
|
|
|
if (!(status & OHCI_CNTL_DMA_ACTIVE)) {
|
|
|
|
if (fc->status != FWBUSINIT)
|
2002-09-13 12:31:56 +00:00
|
|
|
/* maybe out of order?? */
|
|
|
|
goto out;
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
bus_dmamap_sync(dbch->dmat, tr->dma_map,
|
|
|
|
BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(dbch->dmat, tr->dma_map);
|
2003-08-20 03:11:37 +00:00
|
|
|
#if 1
|
2007-03-16 04:26:58 +00:00
|
|
|
if (firewire_debug > 1)
|
2003-08-20 03:11:37 +00:00
|
|
|
dump_db(sc, ch);
|
2002-09-13 12:31:56 +00:00
|
|
|
#endif
|
2014-09-27 16:50:21 +00:00
|
|
|
if (status & OHCI_CNTL_DMA_DEAD) {
|
2003-04-17 03:38:03 +00:00
|
|
|
/* Stop DMA */
|
2002-09-13 12:31:56 +00:00
|
|
|
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);
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
stat = status & FWOHCIEV_MASK;
|
2014-09-27 16:50:21 +00:00
|
|
|
switch (stat) {
|
2002-09-13 12:31:56 +00:00
|
|
|
case FWOHCIEV_ACKPEND:
|
2003-02-09 07:16:01 +00:00
|
|
|
case FWOHCIEV_ACKCOMPL:
|
2002-09-13 12:31:56 +00:00
|
|
|
err = 0;
|
|
|
|
break;
|
|
|
|
case FWOHCIEV_ACKBSA:
|
|
|
|
case FWOHCIEV_ACKBSB:
|
|
|
|
case FWOHCIEV_ACKBSX:
|
|
|
|
err = EBUSY;
|
|
|
|
break;
|
|
|
|
case FWOHCIEV_FLUSHED:
|
|
|
|
case FWOHCIEV_ACKTARD:
|
|
|
|
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:
|
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2003-02-09 07:16:01 +00:00
|
|
|
if (tr->xfer != NULL) {
|
2002-09-13 12:31:56 +00:00
|
|
|
xfer = tr->xfer;
|
2007-06-06 14:31:36 +00:00
|
|
|
if (xfer->flag & FWXF_RCVD) {
|
2003-08-22 07:30:41 +00:00
|
|
|
#if 0
|
2003-04-17 03:38:03 +00:00
|
|
|
if (firewire_debug)
|
|
|
|
printf("already rcvd\n");
|
2003-08-22 07:30:41 +00:00
|
|
|
#endif
|
2003-04-17 03:38:03 +00:00
|
|
|
fw_xfer_done(xfer);
|
|
|
|
} else {
|
2007-06-08 09:04:30 +00:00
|
|
|
microtime(&xfer->tv);
|
2007-06-06 14:31:36 +00:00
|
|
|
xfer->flag = FWXF_SENT;
|
2007-06-08 07:53:59 +00:00
|
|
|
if (err == EBUSY) {
|
2007-06-06 14:31:36 +00:00
|
|
|
xfer->flag = FWXF_BUSY;
|
2003-04-29 14:05:17 +00:00
|
|
|
xfer->resp = err;
|
2007-03-16 05:11:42 +00:00
|
|
|
xfer->recv.pay_len = 0;
|
|
|
|
fw_xfer_done(xfer);
|
2003-04-29 14:05:17 +00:00
|
|
|
} else if (stat != FWOHCIEV_ACKPEND) {
|
|
|
|
if (stat != FWOHCIEV_ACKCOMPL)
|
2007-06-06 14:31:36 +00:00
|
|
|
xfer->flag = FWXF_SENTERR;
|
2003-04-29 14:05:17 +00:00
|
|
|
xfer->resp = err;
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer->recv.pay_len = 0;
|
2003-04-17 03:38:03 +00:00
|
|
|
fw_xfer_done(xfer);
|
2003-04-29 14:05:17 +00:00
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-02-09 07:16:01 +00:00
|
|
|
/*
|
|
|
|
* The watchdog timer takes care of split
|
2014-09-27 16:50:21 +00:00
|
|
|
* transaction timeout for ACKPEND case.
|
2003-02-09 07:16:01 +00:00
|
|
|
*/
|
2003-04-17 03:38:03 +00:00
|
|
|
} else {
|
|
|
|
printf("this shouldn't happen\n");
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GLOCK(fc);
|
2014-09-27 16:50:21 +00:00
|
|
|
dbch->xferq.queued--;
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GUNLOCK(fc);
|
2002-09-13 12:31:56 +00:00
|
|
|
tr->xfer = NULL;
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
packets++;
|
2002-09-13 12:31:56 +00:00
|
|
|
tr = STAILQ_NEXT(tr, link);
|
|
|
|
dbch->bottom = tr;
|
2003-03-07 02:51:59 +00:00
|
|
|
if (dbch->bottom == dbch->top) {
|
|
|
|
/* we reaches the end of context program */
|
|
|
|
if (firewire_debug && dbch->xferq.queued > 0)
|
|
|
|
printf("queued > 0\n");
|
|
|
|
break;
|
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
out:
|
|
|
|
if ((dbch->flags & FWOHCI_DBCH_FULL) && packets > 0) {
|
|
|
|
printf("make free slot\n");
|
|
|
|
dbch->flags &= ~FWOHCI_DBCH_FULL;
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GLOCK(fc);
|
2002-09-13 12:31:56 +00:00
|
|
|
fwohci_start(sc, dbch);
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GUNLOCK(fc);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
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-04-17 03:38:03 +00:00
|
|
|
int idb;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-01-01 04:23:54 +00:00
|
|
|
if ((dbch->flags & FWOHCI_DBCH_INIT) == 0)
|
|
|
|
return;
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
for (db_tr = STAILQ_FIRST(&dbch->db_trq), idb = 0; idb < dbch->ndb;
|
|
|
|
db_tr = STAILQ_NEXT(db_tr, link), idb++) {
|
2003-04-17 03:38:03 +00:00
|
|
|
if ((dbch->xferq.flag & FWXFERQ_EXTBUF) == 0 &&
|
2014-09-27 16:50:21 +00:00
|
|
|
db_tr->buf != NULL) {
|
2003-04-17 03:38:03 +00:00
|
|
|
fwdma_free_size(dbch->dmat, db_tr->dma_map,
|
|
|
|
db_tr->buf, dbch->xferq.psize);
|
|
|
|
db_tr->buf = NULL;
|
|
|
|
} else if (db_tr->dma_map != NULL)
|
|
|
|
bus_dmamap_destroy(dbch->dmat, db_tr->dma_map);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
dbch->ndb = 0;
|
|
|
|
db_tr = STAILQ_FIRST(&dbch->db_trq);
|
2003-04-17 03:38:03 +00:00
|
|
|
fwdma_free_multiseg(dbch->am);
|
2003-02-01 15:04:33 +00:00
|
|
|
free(db_tr, M_FW);
|
2002-09-13 12:31:56 +00:00
|
|
|
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
|
2003-04-17 03:38:03 +00:00
|
|
|
fwohci_db_init(struct fwohci_softc *sc, struct fwohci_dbch *dbch)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
int idb;
|
|
|
|
struct fwohcidb_tr *db_tr;
|
2003-01-04 06:40:57 +00:00
|
|
|
|
|
|
|
if ((dbch->flags & FWOHCI_DBCH_INIT) != 0)
|
|
|
|
goto out;
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
/* create dma_tag for buffers */
|
|
|
|
#define MAX_REQCOUNT 0xffff
|
|
|
|
if (bus_dma_tag_create(/*parent*/ sc->fc.dmat,
|
|
|
|
/*alignment*/ 1, /*boundary*/ 0,
|
|
|
|
/*lowaddr*/ BUS_SPACE_MAXADDR_32BIT,
|
|
|
|
/*highaddr*/ BUS_SPACE_MAXADDR,
|
|
|
|
/*filter*/NULL, /*filterarg*/NULL,
|
|
|
|
/*maxsize*/ dbch->xferq.psize,
|
|
|
|
/*nsegments*/ dbch->ndesc > 3 ? dbch->ndesc - 2 : 1,
|
|
|
|
/*maxsegsz*/ MAX_REQCOUNT,
|
2003-07-01 15:52:06 +00:00
|
|
|
/*flags*/ 0,
|
|
|
|
/*lockfunc*/busdma_lock_mutex,
|
2007-06-06 14:31:36 +00:00
|
|
|
/*lockarg*/FW_GMTX(&sc->fc),
|
2003-07-04 14:04:41 +00:00
|
|
|
&dbch->dmat))
|
2003-04-17 03:38:03 +00:00
|
|
|
return;
|
|
|
|
|
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-04-17 03:38:03 +00:00
|
|
|
M_FW, M_WAITOK | M_ZERO);
|
2003-01-16 13:09:33 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
#define DB_SIZE(x) (sizeof(struct fwohcidb) * (x)->ndesc)
|
2014-09-27 16:50:24 +00:00
|
|
|
dbch->am = fwdma_malloc_multiseg(&sc->fc, sizeof(struct fwohcidb),
|
2003-04-17 03:38:03 +00:00
|
|
|
DB_SIZE(dbch), dbch->ndb, BUS_DMA_WAITOK);
|
|
|
|
if (dbch->am == NULL) {
|
|
|
|
printf("fwohci_db_init: fwdma_malloc_multiseg failed\n");
|
2004-01-22 14:41:17 +00:00
|
|
|
free(db_tr, M_FW);
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Attach DB to DMA ch. */
|
2014-09-27 16:50:21 +00:00
|
|
|
for (idb = 0; idb < dbch->ndb; idb++) {
|
2002-09-13 12:31:56 +00:00
|
|
|
db_tr->dbcnt = 0;
|
2003-04-17 03:38:03 +00:00
|
|
|
db_tr->db = (struct fwohcidb *)fwdma_v_addr(dbch->am, idb);
|
|
|
|
db_tr->bus_addr = fwdma_bus_addr(dbch->am, idb);
|
|
|
|
/* create dmamap for buffers */
|
|
|
|
/* XXX do we need 4bytes alignment tag? */
|
|
|
|
/* XXX don't alloc dma_map for AR */
|
|
|
|
if (bus_dmamap_create(dbch->dmat, 0, &db_tr->dma_map) != 0) {
|
|
|
|
printf("bus_dmamap_create failed\n");
|
|
|
|
dbch->flags = FWOHCI_DBCH_INIT; /* XXX fake */
|
|
|
|
fwohci_db_free(dbch);
|
|
|
|
return;
|
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
STAILQ_INSERT_TAIL(&dbch->db_trq, db_tr, link);
|
2003-04-17 03:38:03 +00:00
|
|
|
if (dbch->xferq.flag & FWXFERQ_EXTBUF) {
|
2003-01-01 08:25:32 +00:00
|
|
|
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->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
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
OWRITE(sc, OHCI_ITCTLCLR(dmach),
|
2003-04-17 03:38:03 +00:00
|
|
|
OHCI_CNTL_DMA_RUN | OHCI_CNTL_CYCMATCH_S);
|
2002-09-13 12:31:56 +00:00
|
|
|
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 */
|
2007-02-27 17:23:29 +00:00
|
|
|
pause("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;
|
|
|
|
|
|
|
|
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 */
|
2007-02-27 17:23:29 +00:00
|
|
|
pause("fwirxd", hz);
|
2002-09-13 12:31:56 +00:00
|
|
|
fwohci_db_free(&sc->ir[dmach]);
|
|
|
|
sc->ir[dmach].xferq.flag &= ~FWXFERQ_RUNNING;
|
|
|
|
return 0;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2002-11-12 05:52:01 +00:00
|
|
|
static void
|
2004-05-22 16:14:17 +00:00
|
|
|
fwohci_irx_post (struct firewire_comm *fc , uint32_t *qld)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-04-17 03:38:03 +00:00
|
|
|
qld[0] = FWOHCI_DMA_READ(qld[0]);
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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;
|
2003-04-17 03:38:03 +00:00
|
|
|
int idb, z, i, dmach = 0, ldesc;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t off = 0;
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fwohcidb_tr *db_tr;
|
2003-10-02 04:06:56 +00:00
|
|
|
struct fwohcidb *db;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
if (!(dbch->xferq.flag & FWXFERQ_EXTBUF)) {
|
2002-09-13 12:31:56 +00:00
|
|
|
err = EINVAL;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
z = dbch->ndesc;
|
2014-09-27 16:50:21 +00:00
|
|
|
for (dmach = 0; dmach < sc->fc.nisodma; dmach++) {
|
|
|
|
if (&sc->it[dmach] == dbch) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ITOFF(dmach);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
if (off == 0) {
|
2002-09-13 12:31:56 +00:00
|
|
|
err = EINVAL;
|
|
|
|
return err;
|
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
if (dbch->xferq.flag & FWXFERQ_RUNNING)
|
2002-09-13 12:31:56 +00:00
|
|
|
return err;
|
|
|
|
dbch->xferq.flag |= FWXFERQ_RUNNING;
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0, dbch->bottom = dbch->top; i < (dbch->ndb - 1); i++) {
|
2002-09-13 12:31:56 +00:00
|
|
|
dbch->bottom = STAILQ_NEXT(dbch->bottom, link);
|
|
|
|
}
|
|
|
|
db_tr = dbch->top;
|
2014-09-27 16:50:21 +00:00
|
|
|
for (idb = 0; idb < dbch->ndb; idb++) {
|
2003-04-17 03:38:03 +00:00
|
|
|
fwohci_add_tx_buf(dbch, db_tr, idb);
|
2014-09-27 16:50:21 +00:00
|
|
|
if (STAILQ_NEXT(db_tr, link) == NULL) {
|
2002-09-13 12:31:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-01-26 18:38:06 +00:00
|
|
|
db = db_tr->db;
|
2003-04-17 03:38:03 +00:00
|
|
|
ldesc = db_tr->dbcnt - 1;
|
|
|
|
FWOHCI_DMA_WRITE(db[0].db.desc.depend,
|
|
|
|
STAILQ_NEXT(db_tr, link)->bus_addr | z);
|
|
|
|
db[ldesc].db.desc.depend = db[0].db.desc.depend;
|
2014-09-27 16:50:21 +00:00
|
|
|
if (dbch->xferq.flag & FWXFERQ_EXTBUF) {
|
|
|
|
if (((idb + 1) % dbch->xferq.bnpacket) == 0) {
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_SET(
|
|
|
|
db[ldesc].db.desc.cmd,
|
|
|
|
OHCI_INTERRUPT_ALWAYS);
|
2003-01-15 04:21:16 +00:00
|
|
|
/* OHCI 1.1 and above */
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_SET(
|
|
|
|
db[0].db.desc.cmd,
|
|
|
|
OHCI_INTERRUPT_ALWAYS);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
db_tr = STAILQ_NEXT(db_tr, link);
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_CLEAR(
|
|
|
|
dbch->bottom->db[dbch->bottom->dbcnt - 1].db.desc.depend, 0xf);
|
2002-09-13 12:31:56 +00:00
|
|
|
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;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t off = 0;
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fwohcidb_tr *db_tr;
|
2003-10-02 04:06:56 +00:00
|
|
|
struct fwohcidb *db;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
z = dbch->ndesc;
|
2014-09-27 16:50:21 +00:00
|
|
|
if (&sc->arrq == dbch) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ARQOFF;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else if (&sc->arrs == dbch) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ARSOFF;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
|
|
|
for (dmach = 0; dmach < sc->fc.nisodma; dmach++) {
|
|
|
|
if (&sc->ir[dmach] == dbch) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_IROFF(dmach);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
if (off == 0) {
|
2002-09-13 12:31:56 +00:00
|
|
|
err = EINVAL;
|
|
|
|
return err;
|
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
if (dbch->xferq.flag & FWXFERQ_STREAM) {
|
|
|
|
if (dbch->xferq.flag & FWXFERQ_RUNNING)
|
2002-09-13 12:31:56 +00:00
|
|
|
return err;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
|
|
|
if (dbch->xferq.flag & FWXFERQ_RUNNING) {
|
2002-09-13 12:31:56 +00:00
|
|
|
err = EBUSY;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dbch->xferq.flag |= FWXFERQ_RUNNING;
|
2003-01-04 06:40:57 +00:00
|
|
|
dbch->top = STAILQ_FIRST(&dbch->db_trq);
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0, dbch->bottom = dbch->top; i < (dbch->ndb - 1); i++) {
|
2002-09-13 12:31:56 +00:00
|
|
|
dbch->bottom = STAILQ_NEXT(dbch->bottom, link);
|
|
|
|
}
|
|
|
|
db_tr = dbch->top;
|
2014-09-27 16:50:21 +00:00
|
|
|
for (idb = 0; idb < dbch->ndb; idb++) {
|
2003-04-17 03:38:03 +00:00
|
|
|
fwohci_add_rx_buf(dbch, db_tr, idb, &sc->dummy_dma);
|
|
|
|
if (STAILQ_NEXT(db_tr, link) == NULL)
|
2002-09-13 12:31:56 +00:00
|
|
|
break;
|
2003-01-26 18:38:06 +00:00
|
|
|
db = db_tr->db;
|
|
|
|
ldesc = db_tr->dbcnt - 1;
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_WRITE(db[ldesc].db.desc.depend,
|
|
|
|
STAILQ_NEXT(db_tr, link)->bus_addr | z);
|
2014-09-27 16:50:21 +00:00
|
|
|
if (dbch->xferq.flag & FWXFERQ_EXTBUF) {
|
|
|
|
if (((idb + 1) % dbch->xferq.bnpacket) == 0) {
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_SET(
|
|
|
|
db[ldesc].db.desc.cmd,
|
|
|
|
OHCI_INTERRUPT_ALWAYS);
|
|
|
|
FWOHCI_DMA_CLEAR(
|
|
|
|
db[ldesc].db.desc.depend,
|
|
|
|
0xf);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
db_tr = STAILQ_NEXT(db_tr, link);
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_CLEAR(
|
|
|
|
dbch->bottom->db[db_tr->dbcnt - 1].db.desc.depend, 0xf);
|
2002-09-13 12:31:56 +00:00
|
|
|
dbch->buf_offset = 0;
|
2003-04-17 03:38:03 +00:00
|
|
|
fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_PREREAD);
|
|
|
|
fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_PREWRITE);
|
2014-09-27 16:50:21 +00:00
|
|
|
if (dbch->xferq.flag & FWXFERQ_STREAM) {
|
2002-09-13 12:31:56 +00:00
|
|
|
return err;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
2003-04-17 03:38:03 +00:00
|
|
|
OWRITE(sc, OHCI_DMACMD(off), dbch->top->bus_addr | z);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
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
|
2003-04-17 03:38:03 +00:00
|
|
|
fwohci_next_cycle(struct firewire_comm *fc, int cycle_now)
|
2003-01-26 15:39:04 +00:00
|
|
|
{
|
|
|
|
int sec, cycle, cycle_match;
|
|
|
|
|
|
|
|
cycle = cycle_now & 0x1fff;
|
|
|
|
sec = cycle_now >> 13;
|
|
|
|
#define CYCLE_MOD 0x10
|
2003-04-17 03:38:03 +00:00
|
|
|
#if 1
|
2003-01-26 15:39:04 +00:00
|
|
|
#define CYCLE_DELAY 8 /* min delay to start DMA */
|
2003-04-17 03:38:03 +00:00
|
|
|
#else
|
|
|
|
#define CYCLE_DELAY 7000 /* min delay to start DMA */
|
|
|
|
#endif
|
2003-01-26 15:39:04 +00:00
|
|
|
cycle = cycle + CYCLE_DELAY;
|
|
|
|
if (cycle >= 8000) {
|
2014-09-27 16:50:21 +00:00
|
|
|
sec++;
|
2003-01-26 15:39:04 +00:00
|
|
|
cycle -= 8000;
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
cycle = roundup2(cycle, CYCLE_MOD);
|
2003-01-26 15:39:04 +00:00
|
|
|
if (cycle >= 8000) {
|
2014-09-27 16:50:21 +00:00
|
|
|
sec++;
|
2003-01-26 15:39:04 +00:00
|
|
|
if (cycle == 8000)
|
|
|
|
cycle = 0;
|
|
|
|
else
|
|
|
|
cycle = CYCLE_MOD;
|
|
|
|
}
|
|
|
|
cycle_match = ((sec << 13) | cycle) & 0x7ffff;
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
return (cycle_match);
|
2003-01-26 15:39:04 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
struct fwohci_dbch *dbch;
|
2003-01-26 15:39:04 +00:00
|
|
|
int cycle_match, cycle_now, s, ldesc;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_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;
|
|
|
|
|
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;
|
2003-04-17 03:38:03 +00:00
|
|
|
fwohci_db_init(sc, dbch);
|
2003-01-13 16:08:09 +00:00
|
|
|
if ((dbch->flags & FWOHCI_DBCH_INIT) == 0)
|
|
|
|
return ENOMEM;
|
2007-06-06 14:31:36 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
err = fwohci_tx_enable(sc, dbch);
|
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
if (err)
|
2002-09-13 12:31:56 +00:00
|
|
|
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();
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GLOCK(fc);
|
2003-01-26 15:39:04 +00:00
|
|
|
prev = STAILQ_LAST(&it->stdma, fw_bulkxfer, link);
|
|
|
|
while ((chunk = STAILQ_FIRST(&it->stvalid)) != NULL) {
|
2003-10-02 04:06:56 +00:00
|
|
|
struct fwohcidb *db;
|
2003-01-26 15:39:04 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
fwdma_sync_multiseg(it->buf, chunk->poffset, it->bnpacket,
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
2003-01-26 15:39:04 +00:00
|
|
|
fwohci_txbufdb(sc, dmach, chunk);
|
|
|
|
if (prev != NULL) {
|
|
|
|
db = ((struct fwohcidb_tr *)(prev->end))->db;
|
2003-04-17 03:38:03 +00:00
|
|
|
#if 0 /* XXX necessary? */
|
|
|
|
FWOHCI_DMA_SET(db[ldesc].db.desc.cmd,
|
|
|
|
OHCI_BRANCH_ALWAYS);
|
|
|
|
#endif
|
2003-01-26 18:38:06 +00:00
|
|
|
#if 0 /* if bulkxfer->npacket changes */
|
2014-09-27 16:50:21 +00:00
|
|
|
db[ldesc].db.desc.depend = db[0].db.desc.depend =
|
2003-04-17 03:38:03 +00:00
|
|
|
((struct fwohcidb_tr *)
|
|
|
|
(chunk->start))->bus_addr | dbch->ndesc;
|
2003-01-26 18:38:06 +00:00
|
|
|
#else
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_SET(db[0].db.desc.depend, dbch->ndesc);
|
|
|
|
FWOHCI_DMA_SET(db[ldesc].db.desc.depend, dbch->ndesc);
|
2003-01-26 18:38:06 +00:00
|
|
|
#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
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GUNLOCK(fc);
|
2003-04-17 03:38:03 +00:00
|
|
|
fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_PREWRITE);
|
|
|
|
fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_PREREAD);
|
2003-01-26 15:39:04 +00:00
|
|
|
splx(s);
|
|
|
|
stat = OREAD(sc, OHCI_ITCTL(dmach));
|
2003-04-17 03:38:03 +00:00
|
|
|
if (firewire_debug && (stat & OHCI_CNTL_CYCMATCH_S))
|
|
|
|
printf("stat 0x%x\n", stat);
|
|
|
|
|
2003-01-26 15:39:04 +00:00
|
|
|
if (stat & (OHCI_CNTL_DMA_ACTIVE | OHCI_CNTL_CYCMATCH_S))
|
|
|
|
return 0;
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
#if 0
|
2003-01-26 15:39:04 +00:00
|
|
|
OWRITE(sc, OHCI_ITCTLCLR(dmach), OHCI_CNTL_DMA_RUN);
|
2003-04-17 03:38:03 +00:00
|
|
|
#endif
|
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-04-17 03:38:03 +00:00
|
|
|
OWRITE(sc, FWOHCI_INTMASK, OHCI_INT_DMA_IT);
|
2003-01-26 15:39:04 +00:00
|
|
|
|
|
|
|
first = STAILQ_FIRST(&it->stdma);
|
2003-04-17 03:38:03 +00:00
|
|
|
OWRITE(sc, OHCI_ITCMD(dmach),
|
|
|
|
((struct fwohcidb_tr *)(first->start))->bus_addr | dbch->ndesc);
|
2007-03-16 04:26:58 +00:00
|
|
|
if (firewire_debug > 1) {
|
2003-01-26 15:39:04 +00:00
|
|
|
printf("fwohci_itxbuf_enable: kick 0x%08x\n", stat);
|
2003-04-17 03:38:03 +00:00
|
|
|
#if 1
|
|
|
|
dump_dma(sc, ITX_CH + dmach);
|
|
|
|
#endif
|
|
|
|
}
|
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-04-17 03:38:03 +00:00
|
|
|
#if 1
|
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
|
|
|
|
|
|
|
/* 2bit second + 13bit cycle */
|
|
|
|
cycle_now = (fc->cyctimer(fc) >> 12) & 0x7fff;
|
2003-04-17 03:38:03 +00:00
|
|
|
cycle_match = fwohci_next_cycle(fc, cycle_now);
|
2003-01-26 15:39:04 +00:00
|
|
|
|
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-04-17 03:38:03 +00:00
|
|
|
#else
|
|
|
|
OWRITE(sc, OHCI_ITCTL(dmach), OHCI_CNTL_DMA_RUN);
|
|
|
|
#endif
|
2007-03-16 04:26:58 +00:00
|
|
|
if (firewire_debug > 1) {
|
2003-01-17 03:52:48 +00:00
|
|
|
printf("cycle_match: 0x%04x->0x%04x\n",
|
|
|
|
cycle_now, cycle_match);
|
2003-04-17 03:38:03 +00:00
|
|
|
dump_dma(sc, ITX_CH + dmach);
|
|
|
|
dump_db(sc, ITX_CH + dmach);
|
|
|
|
}
|
2003-01-17 03:52:48 +00:00
|
|
|
} 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-04-17 03:38:03 +00:00
|
|
|
OWRITE(sc, OHCI_ITCTL(dmach), OHCI_CNTL_DMA_WAKE);
|
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
|
2003-04-17 03:38:03 +00:00
|
|
|
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;
|
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;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t stat;
|
2003-01-26 15:39:04 +00:00
|
|
|
struct fwohci_dbch *dbch;
|
2003-04-17 03:38:03 +00:00
|
|
|
struct fwohcidb_tr *db_tr;
|
2003-01-26 15:39:04 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
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->ndesc = 2;
|
2003-04-17 03:38:03 +00:00
|
|
|
fwohci_db_init(sc, dbch);
|
2003-01-26 15:39:04 +00:00
|
|
|
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
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
if (err)
|
2002-09-13 12:31:56 +00:00
|
|
|
return err;
|
|
|
|
|
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");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-05 01:50:57 +00:00
|
|
|
ldesc = dbch->ndesc - 1;
|
|
|
|
s = splfw();
|
2007-06-06 14:31:36 +00:00
|
|
|
if ((ir->flag & FWXFERQ_HANDLER) == 0)
|
|
|
|
FW_GLOCK(fc);
|
2003-01-26 15:39:04 +00:00
|
|
|
prev = STAILQ_LAST(&ir->stdma, fw_bulkxfer, link);
|
|
|
|
while ((chunk = STAILQ_FIRST(&ir->stfree)) != NULL) {
|
2003-10-02 04:06:56 +00:00
|
|
|
struct fwohcidb *db;
|
2003-01-26 15:39:04 +00:00
|
|
|
|
2003-03-06 05:06:44 +00:00
|
|
|
#if 1 /* XXX for if_fwe */
|
2003-04-17 03:38:03 +00:00
|
|
|
if (chunk->mbuf != NULL) {
|
|
|
|
db_tr = (struct fwohcidb_tr *)(chunk->start);
|
|
|
|
db_tr->dbcnt = 1;
|
|
|
|
err = bus_dmamap_load_mbuf(dbch->dmat, db_tr->dma_map,
|
|
|
|
chunk->mbuf, fwohci_execute_db2, db_tr,
|
|
|
|
/* flags */0);
|
|
|
|
FWOHCI_DMA_SET(db_tr->db[1].db.desc.cmd,
|
|
|
|
OHCI_UPDATE | OHCI_INPUT_LAST |
|
|
|
|
OHCI_INTERRUPT_ALWAYS | OHCI_BRANCH_ALWAYS);
|
|
|
|
}
|
2003-03-06 05:06:44 +00:00
|
|
|
#endif
|
2003-01-26 15:39:04 +00:00
|
|
|
db = ((struct fwohcidb_tr *)(chunk->end))->db;
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_WRITE(db[ldesc].db.desc.res, 0);
|
|
|
|
FWOHCI_DMA_CLEAR(db[ldesc].db.desc.depend, 0xf);
|
2003-01-26 15:39:04 +00:00
|
|
|
if (prev != NULL) {
|
|
|
|
db = ((struct fwohcidb_tr *)(prev->end))->db;
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_SET(db[ldesc].db.desc.depend, dbch->ndesc);
|
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;
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
if ((ir->flag & FWXFERQ_HANDLER) == 0)
|
|
|
|
FW_GUNLOCK(fc);
|
2003-04-17 03:38:03 +00:00
|
|
|
fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_PREWRITE);
|
|
|
|
fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_PREREAD);
|
2003-01-26 15:39:04 +00:00
|
|
|
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
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
if (firewire_debug)
|
|
|
|
printf("start IR DMA 0x%x\n", stat);
|
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),
|
2003-04-17 03:38:03 +00:00
|
|
|
((struct fwohcidb_tr *)(first->start))->bus_addr
|
2003-01-26 15:39:04 +00:00
|
|
|
| dbch->ndesc);
|
|
|
|
OWRITE(sc, OHCI_IRCTL(dmach), OHCI_CNTL_DMA_RUN);
|
|
|
|
OWRITE(sc, FWOHCI_INTMASK, OHCI_INT_DMA_IR);
|
2003-04-17 03:38:03 +00:00
|
|
|
#if 0
|
|
|
|
dump_db(sc, IRX_CH + dmach);
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
return err;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
int
|
2003-01-31 14:11:22 +00:00
|
|
|
fwohci_stop(struct fwohci_softc *sc, device_t dev)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
2008-05-10 09:22:06 +00:00
|
|
|
fwohci_set_intr(&sc->fc, 0);
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/* Now stopping all DMA channel */
|
2014-09-27 16:50:21 +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);
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
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);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
#if 0 /* Let dcons(4) be accessed */
|
2002-09-13 12:31:56 +00:00
|
|
|
/* Stop interrupt */
|
|
|
|
OWRITE(sc, FWOHCI_INTMASKCLR,
|
|
|
|
OHCI_INT_EN | OHCI_INT_ERR | OHCI_INT_PHY_SID
|
|
|
|
| OHCI_INT_PHY_INT
|
2014-09-27 16:50:21 +00:00
|
|
|
| OHCI_INT_DMA_ATRQ | OHCI_INT_DMA_ATRS
|
2002-09-13 12:31:56 +00:00
|
|
|
| OHCI_INT_DMA_PRRQ | OHCI_INT_DMA_PRRS
|
2014-09-27 16:50:21 +00:00
|
|
|
| OHCI_INT_DMA_ARRQ | OHCI_INT_DMA_ARRS
|
2002-09-13 12:31:56 +00:00
|
|
|
| OHCI_INT_PHY_BUS_R);
|
2003-06-28 11:11:36 +00:00
|
|
|
|
2016-05-03 03:41:25 +00:00
|
|
|
/* FLUSH FIFO and reset Transmitter/Receiver */
|
2014-09-27 16:50:21 +00:00
|
|
|
OWRITE(sc, OHCI_HCCCTL, OHCI_HCC_RESET);
|
2007-06-06 14:31:36 +00:00
|
|
|
#endif
|
2003-06-28 11:11:36 +00:00
|
|
|
|
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;
|
2003-06-28 11:11:36 +00:00
|
|
|
struct fw_xferq *ir;
|
|
|
|
struct fw_bulkxfer *chunk;
|
2003-01-04 06:40:57 +00:00
|
|
|
|
|
|
|
fwohci_reset(sc, dev);
|
2004-05-21 09:12:07 +00:00
|
|
|
/* XXX resume isochronous receive automatically. (how about TX?) */
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < sc->fc.nisodma; i++) {
|
2003-06-28 11:11:36 +00:00
|
|
|
ir = &sc->ir[i].xferq;
|
2014-09-27 16:50:21 +00:00
|
|
|
if ((ir->flag & FWXFERQ_RUNNING) != 0) {
|
2003-01-04 06:40:57 +00:00
|
|
|
device_printf(sc->fc.dev,
|
|
|
|
"resume iso receive ch: %d\n", i);
|
2003-06-28 11:11:36 +00:00
|
|
|
ir->flag &= ~FWXFERQ_RUNNING;
|
|
|
|
/* requeue stdma to stfree */
|
2014-09-27 16:50:21 +00:00
|
|
|
while ((chunk = STAILQ_FIRST(&ir->stdma)) != NULL) {
|
2003-06-28 11:11:36 +00:00
|
|
|
STAILQ_REMOVE_HEAD(&ir->stdma, link);
|
|
|
|
STAILQ_INSERT_TAIL(&ir->stfree, chunk, link);
|
|
|
|
}
|
2003-01-04 06:40:57 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
#ifdef OHCI_DEBUG
|
2002-09-13 12:31:56 +00:00
|
|
|
static void
|
2007-06-06 14:31:36 +00:00
|
|
|
fwohci_dump_intr(struct fwohci_softc *sc, uint32_t stat)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2014-09-27 16:50:21 +00:00
|
|
|
if (stat & OREAD(sc, FWOHCI_INTMASK))
|
2002-09-13 12:31:56 +00:00
|
|
|
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 " :"",
|
2014-09-27 16:50:21 +00:00
|
|
|
stat, OREAD(sc, FWOHCI_INTMASK)
|
2002-09-13 12:31:56 +00:00
|
|
|
);
|
2007-06-06 14:31:36 +00:00
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
#endif
|
2014-09-27 16:50:21 +00:00
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
static void
|
|
|
|
fwohci_intr_core(struct fwohci_softc *sc, uint32_t stat, int count)
|
|
|
|
{
|
|
|
|
struct firewire_comm *fc = (struct firewire_comm *)sc;
|
2015-01-21 20:08:24 +00:00
|
|
|
uintmax_t prequpper;
|
2007-06-06 14:31:36 +00:00
|
|
|
uint32_t node_id, plen;
|
|
|
|
|
2009-02-01 23:28:52 +00:00
|
|
|
FW_GLOCK_ASSERT(fc);
|
2007-06-06 14:31:36 +00:00
|
|
|
if ((stat & OHCI_INT_PHY_BUS_R) && (fc->status != FWBUSRESET)) {
|
|
|
|
fc->status = FWBUSRESET;
|
2003-02-18 09:39:48 +00:00
|
|
|
/* Disable bus reset interrupt until sid recv. */
|
2014-09-27 16:50:21 +00:00
|
|
|
OWRITE(sc, FWOHCI_INTMASKCLR, OHCI_INT_PHY_BUS_R);
|
|
|
|
|
2009-02-12 03:26:05 +00:00
|
|
|
device_printf(fc->dev, "%s: BUS reset\n", __func__);
|
2014-09-27 16:50:21 +00:00
|
|
|
OWRITE(sc, FWOHCI_INTMASKCLR, OHCI_INT_CYC_LOST);
|
2002-09-13 12:31:56 +00:00
|
|
|
OWRITE(sc, OHCI_LNKCTLCLR, OHCI_CNTL_CYCSRC);
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
OWRITE(sc, OHCI_ATQCTLCLR, OHCI_CNTL_DMA_RUN);
|
2002-09-13 12:31:56 +00:00
|
|
|
sc->atrq.xferq.flag &= ~FWXFERQ_RUNNING;
|
2014-09-27 16:50:21 +00:00
|
|
|
OWRITE(sc, OHCI_ATSCTLCLR, OHCI_CNTL_DMA_RUN);
|
2002-09-13 12:31:56 +00:00
|
|
|
sc->atrs.xferq.flag &= ~FWXFERQ_RUNNING;
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
if (!kdb_active)
|
|
|
|
taskqueue_enqueue(sc->fc.taskqueue, &sc->fwohci_task_busreset);
|
|
|
|
}
|
|
|
|
if (stat & OHCI_INT_PHY_SID) {
|
|
|
|
/* Enable bus reset interrupt */
|
2002-09-13 12:31:56 +00:00
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, OHCI_INT_PHY_BUS_R);
|
2007-06-06 14:31:36 +00:00
|
|
|
OWRITE(sc, FWOHCI_INTMASK, OHCI_INT_PHY_BUS_R);
|
|
|
|
|
|
|
|
/* Allow async. request to us */
|
|
|
|
OWRITE(sc, OHCI_AREQHI, 1 << 31);
|
2007-06-07 13:20:48 +00:00
|
|
|
if (firewire_phydma_enable) {
|
|
|
|
/* allow from all nodes */
|
|
|
|
OWRITE(sc, OHCI_PREQHI, 0x7fffffff);
|
|
|
|
OWRITE(sc, OHCI_PREQLO, 0xffffffff);
|
2015-01-21 20:08:24 +00:00
|
|
|
prequpper = ((uintmax_t)Maxmem << PAGE_SHIFT) >> 16;
|
|
|
|
if (prequpper > OHCI_PREQUPPER_MAX) {
|
|
|
|
device_printf(fc->dev,
|
|
|
|
"Physical memory size of 0x%jx exceeds "
|
|
|
|
"fire wire address space. Limiting dma "
|
|
|
|
"to memory below 0x%jx\n",
|
|
|
|
(uintmax_t)Maxmem << PAGE_SHIFT,
|
|
|
|
(uintmax_t)OHCI_PREQUPPER_MAX << 16);
|
|
|
|
prequpper = OHCI_PREQUPPER_MAX;
|
|
|
|
}
|
|
|
|
OWRITE(sc, OHCI_PREQUPPER, prequpper & 0xffffffff);
|
2016-11-24 09:43:42 +00:00
|
|
|
if (OREAD(sc, OHCI_PREQUPPER) !=
|
|
|
|
(prequpper & 0xffffffff)) {
|
|
|
|
device_printf(fc->dev,
|
|
|
|
"PhysicalUpperBound register is not "
|
|
|
|
"implemented. Physical memory access "
|
|
|
|
"is limited to the first 4GB\n");
|
|
|
|
device_printf(fc->dev,
|
|
|
|
"PhysicalUpperBound = 0x%08x\n",
|
|
|
|
OREAD(sc, OHCI_PREQUPPER));
|
|
|
|
}
|
2007-06-07 13:20:48 +00:00
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
/* Set ATRetries register */
|
2014-09-27 16:50:21 +00:00
|
|
|
OWRITE(sc, OHCI_ATRETRY, 1<<(13 + 16) | 0xfff);
|
2007-06-06 14:31:36 +00:00
|
|
|
|
|
|
|
/*
|
2014-09-27 16:50:21 +00:00
|
|
|
* Checking whether the node is root or not. If root, turn on
|
2007-06-06 14:31:36 +00:00
|
|
|
* cycle master.
|
|
|
|
*/
|
|
|
|
node_id = OREAD(sc, FWOHCI_NODEID);
|
|
|
|
plen = OREAD(sc, OHCI_SID_CNT);
|
|
|
|
|
|
|
|
fc->nodeid = node_id & 0x3f;
|
2009-02-12 03:26:05 +00:00
|
|
|
device_printf(fc->dev, "%s: node_id=0x%08x, SelfID Count=%d, ",
|
|
|
|
__func__, fc->nodeid, (plen >> 16) & 0xff);
|
2007-06-06 14:31:36 +00:00
|
|
|
if (!(node_id & OHCI_NODE_VALID)) {
|
2009-02-12 03:26:05 +00:00
|
|
|
device_printf(fc->dev, "%s: Bus reset failure\n",
|
|
|
|
__func__);
|
2007-06-06 14:31:36 +00:00
|
|
|
goto sidout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cycle timer */
|
|
|
|
sc->cycle_lost = 0;
|
2014-09-27 16:50:21 +00:00
|
|
|
OWRITE(sc, FWOHCI_INTMASK, OHCI_INT_CYC_LOST);
|
2007-06-06 14:31:36 +00:00
|
|
|
if ((node_id & OHCI_NODE_ROOT) && !nocyclemaster) {
|
|
|
|
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->status = FWBUSINIT;
|
|
|
|
|
|
|
|
if (!kdb_active)
|
|
|
|
taskqueue_enqueue(sc->fc.taskqueue, &sc->fwohci_task_sid);
|
|
|
|
}
|
|
|
|
sidout:
|
|
|
|
if ((stat & ~(OHCI_INT_PHY_BUS_R | OHCI_INT_PHY_SID)) && (!kdb_active))
|
|
|
|
taskqueue_enqueue(sc->fc.taskqueue, &sc->fwohci_task_dma);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_intr_dma(struct fwohci_softc *sc, uint32_t stat, int count)
|
|
|
|
{
|
|
|
|
uint32_t irstat, itstat;
|
|
|
|
u_int i;
|
|
|
|
struct firewire_comm *fc = (struct firewire_comm *)sc;
|
|
|
|
|
|
|
|
if (stat & OHCI_INT_DMA_IR) {
|
2004-03-26 23:17:10 +00:00
|
|
|
irstat = atomic_readandclear_int(&sc->irstat);
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < fc->nisodma; i++) {
|
2003-01-21 16:24:35 +00:00
|
|
|
struct fwohci_dbch *dbch;
|
|
|
|
|
2014-09-27 16:50:21 +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;
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
fwohci_rbuf_update(sc, i);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
if (stat & OHCI_INT_DMA_IT) {
|
2004-03-26 23:17:10 +00:00
|
|
|
itstat = atomic_readandclear_int(&sc->itstat);
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < fc->nisodma; i++) {
|
|
|
|
if ((itstat & (1 << i)) != 0) {
|
2002-09-13 12:31:56 +00:00
|
|
|
fwohci_tbuf_update(sc, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
if (stat & OHCI_INT_DMA_PRRS) {
|
2002-09-13 12:31:56 +00:00
|
|
|
#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
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
if (stat & OHCI_INT_DMA_PRRQ) {
|
2002-09-13 12:31:56 +00:00
|
|
|
#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
|
|
|
}
|
2007-03-16 04:25:02 +00:00
|
|
|
if (stat & OHCI_INT_CYC_LOST) {
|
|
|
|
if (sc->cycle_lost >= 0)
|
2014-09-27 16:50:21 +00:00
|
|
|
sc->cycle_lost++;
|
2007-03-16 04:25:02 +00:00
|
|
|
if (sc->cycle_lost > 10) {
|
|
|
|
sc->cycle_lost = -1;
|
|
|
|
#if 0
|
|
|
|
OWRITE(sc, OHCI_LNKCTLCLR, OHCI_CNTL_CYCTIMER);
|
|
|
|
#endif
|
2014-09-27 16:50:21 +00:00
|
|
|
OWRITE(sc, FWOHCI_INTMASKCLR, OHCI_INT_CYC_LOST);
|
2010-10-18 14:26:29 +00:00
|
|
|
device_printf(fc->dev, "too many cycles lost, "
|
|
|
|
"no cycle master present?\n");
|
2007-03-16 04:25:02 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
if (stat & OHCI_INT_DMA_ATRQ) {
|
2002-09-13 12:31:56 +00:00
|
|
|
fwohci_txd(sc, &(sc->atrq));
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
if (stat & OHCI_INT_DMA_ATRS) {
|
2002-09-13 12:31:56 +00:00
|
|
|
fwohci_txd(sc, &(sc->atrs));
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
if (stat & OHCI_INT_PW_ERR) {
|
2002-09-13 12:31:56 +00:00
|
|
|
device_printf(fc->dev, "posted write error\n");
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
if (stat & OHCI_INT_ERR) {
|
2002-09-13 12:31:56 +00:00
|
|
|
device_printf(fc->dev, "unrecoverable error\n");
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
if (stat & OHCI_INT_PHY_INT) {
|
2002-09-13 12:31:56 +00:00
|
|
|
device_printf(fc->dev, "phy int\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
static void
|
2007-06-06 14:31:36 +00:00
|
|
|
fwohci_task_busreset(void *arg, int pending)
|
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)arg;
|
|
|
|
|
2009-02-01 23:28:52 +00:00
|
|
|
FW_GLOCK(&sc->fc);
|
2007-06-06 14:31:36 +00:00
|
|
|
fw_busreset(&sc->fc, FWBUSRESET);
|
|
|
|
OWRITE(sc, OHCI_CROMHDR, ntohl(sc->fc.config_rom[0]));
|
|
|
|
OWRITE(sc, OHCI_BUS_OPT, ntohl(sc->fc.config_rom[2]));
|
2009-02-01 23:28:52 +00:00
|
|
|
FW_GUNLOCK(&sc->fc);
|
2007-06-06 14:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_task_sid(void *arg, int pending)
|
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)arg;
|
|
|
|
struct firewire_comm *fc = &sc->fc;
|
|
|
|
uint32_t *buf;
|
|
|
|
int i, plen;
|
|
|
|
|
|
|
|
|
2009-02-01 23:28:52 +00:00
|
|
|
/*
|
|
|
|
* We really should have locking
|
|
|
|
* here. Not sure why it's not
|
|
|
|
*/
|
2007-06-06 14:31:36 +00:00
|
|
|
plen = OREAD(sc, OHCI_SID_CNT);
|
|
|
|
|
|
|
|
if (plen & OHCI_SID_ERR) {
|
|
|
|
device_printf(fc->dev, "SID Error\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
plen &= OHCI_SID_CNT_MASK;
|
|
|
|
if (plen < 4 || plen > OHCI_SIDSIZE) {
|
|
|
|
device_printf(fc->dev, "invalid SID len = %d\n", plen);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
plen -= 4; /* chop control info */
|
|
|
|
buf = (uint32_t *)malloc(OHCI_SIDSIZE, M_FW, M_NOWAIT);
|
|
|
|
if (buf == NULL) {
|
|
|
|
device_printf(fc->dev, "malloc failed\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < plen / 4; i++)
|
|
|
|
buf[i] = FWOHCI_DMA_READ(sc->sid_buf[i + 1]);
|
2009-02-01 23:28:52 +00:00
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
/* pending all pre-bus_reset packets */
|
|
|
|
fwohci_txd(sc, &sc->atrq);
|
|
|
|
fwohci_txd(sc, &sc->atrs);
|
|
|
|
fwohci_arcv(sc, &sc->arrs, -1);
|
|
|
|
fwohci_arcv(sc, &sc->arrq, -1);
|
|
|
|
fw_drain_txq(fc);
|
|
|
|
fw_sidrcv(fc, buf, plen);
|
|
|
|
free(buf, M_FW);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_task_dma(void *arg, int pending)
|
2003-04-17 03:38:03 +00:00
|
|
|
{
|
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)arg;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t stat;
|
2003-04-17 03:38:03 +00:00
|
|
|
|
|
|
|
again:
|
|
|
|
stat = atomic_readandclear_int(&sc->intstat);
|
|
|
|
if (stat)
|
2007-06-06 14:31:36 +00:00
|
|
|
fwohci_intr_dma(sc, stat, -1);
|
2003-04-17 03:38:03 +00:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
static int
|
|
|
|
fwohci_check_stat(struct fwohci_softc *sc)
|
2003-04-17 03:38:03 +00:00
|
|
|
{
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t stat, irstat, itstat;
|
2003-04-17 03:38:03 +00:00
|
|
|
|
2009-02-01 23:28:52 +00:00
|
|
|
FW_GLOCK_ASSERT(&sc->fc);
|
2003-04-17 03:38:03 +00:00
|
|
|
stat = OREAD(sc, FWOHCI_INTSTAT);
|
|
|
|
if (stat == 0xffffffff) {
|
2011-06-21 03:07:59 +00:00
|
|
|
if (!bus_child_present(sc->fc.dev))
|
|
|
|
return (FILTER_HANDLED);
|
|
|
|
device_printf(sc->fc.dev, "device physically ejected?\n");
|
2007-06-06 14:31:36 +00:00
|
|
|
return (FILTER_STRAY);
|
2003-04-17 03:38:03 +00:00
|
|
|
}
|
|
|
|
if (stat)
|
2007-06-06 14:31:36 +00:00
|
|
|
OWRITE(sc, FWOHCI_INTSTATCLR, stat & ~OHCI_INT_PHY_BUS_R);
|
|
|
|
|
|
|
|
stat &= sc->intmask;
|
|
|
|
if (stat == 0)
|
|
|
|
return (FILTER_STRAY);
|
|
|
|
|
|
|
|
atomic_set_int(&sc->intstat, stat);
|
2003-04-17 03:38:03 +00:00
|
|
|
if (stat & OHCI_INT_DMA_IR) {
|
|
|
|
irstat = OREAD(sc, OHCI_IR_STAT);
|
|
|
|
OWRITE(sc, OHCI_IR_STATCLR, irstat);
|
|
|
|
atomic_set_int(&sc->irstat, irstat);
|
|
|
|
}
|
|
|
|
if (stat & OHCI_INT_DMA_IT) {
|
|
|
|
itstat = OREAD(sc, OHCI_IT_STAT);
|
|
|
|
OWRITE(sc, OHCI_IT_STATCLR, itstat);
|
|
|
|
atomic_set_int(&sc->itstat, itstat);
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
|
|
|
|
fwohci_intr_core(sc, stat, -1);
|
|
|
|
return (FILTER_HANDLED);
|
2003-04-17 03:38:03 +00:00
|
|
|
}
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
void
|
|
|
|
fwohci_intr(void *arg)
|
|
|
|
{
|
2009-02-01 23:28:52 +00:00
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)arg;
|
|
|
|
|
|
|
|
FW_GLOCK(&sc->fc);
|
|
|
|
fwohci_check_stat(sc);
|
|
|
|
FW_GUNLOCK(&sc->fc);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
|
2003-06-27 00:27:33 +00:00
|
|
|
void
|
2002-09-13 12:31:56 +00:00
|
|
|
fwohci_poll(struct firewire_comm *fc, int quick, int count)
|
|
|
|
{
|
2007-06-06 14:31:36 +00:00
|
|
|
struct fwohci_softc *sc = (struct fwohci_softc *)fc;
|
2009-02-01 23:28:52 +00:00
|
|
|
|
|
|
|
FW_GLOCK(fc);
|
2007-06-06 14:31:36 +00:00
|
|
|
fwohci_check_stat(sc);
|
2009-02-01 23:28:52 +00:00
|
|
|
FW_GUNLOCK(fc);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fwohci_set_intr(struct firewire_comm *fc, int enable)
|
|
|
|
{
|
|
|
|
struct fwohci_softc *sc;
|
|
|
|
|
|
|
|
sc = (struct fwohci_softc *)fc;
|
2004-07-20 04:49:44 +00:00
|
|
|
if (firewire_debug)
|
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-10-02 04:06:56 +00:00
|
|
|
struct fwohcidb *db;
|
2003-01-26 15:39:04 +00:00
|
|
|
struct fw_bulkxfer *chunk;
|
|
|
|
struct fw_xferq *it;
|
2021-12-09 16:36:45 +00:00
|
|
|
uint32_t stat, count __unused;
|
2003-04-17 03:38:03 +00:00
|
|
|
int s, w=0, ldesc;
|
2003-01-26 15:39:04 +00:00
|
|
|
|
|
|
|
it = fc->it[dmach];
|
2003-04-17 03:38:03 +00:00
|
|
|
ldesc = sc->it[dmach].ndesc - 1;
|
2003-01-26 15:39:04 +00:00
|
|
|
s = splfw(); /* unnecessary ? */
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GLOCK(fc);
|
2003-04-17 03:38:03 +00:00
|
|
|
fwdma_sync_multiseg_all(sc->it[dmach].am, BUS_DMASYNC_POSTREAD);
|
2003-08-20 03:11:37 +00:00
|
|
|
if (firewire_debug)
|
|
|
|
dump_db(sc, ITX_CH + dmach);
|
2003-01-26 15:39:04 +00:00
|
|
|
while ((chunk = STAILQ_FIRST(&it->stdma)) != NULL) {
|
|
|
|
db = ((struct fwohcidb_tr *)(chunk->end))->db;
|
2014-09-27 16:50:21 +00:00
|
|
|
stat = FWOHCI_DMA_READ(db[ldesc].db.desc.res)
|
2003-04-17 03:38:03 +00:00
|
|
|
>> OHCI_STATUS_SHIFT;
|
2003-01-26 15:39:04 +00:00
|
|
|
db = ((struct fwohcidb_tr *)(chunk->start))->db;
|
2003-08-20 03:11:37 +00:00
|
|
|
/* timestamp */
|
2003-04-17 03:38:03 +00:00
|
|
|
count = FWOHCI_DMA_READ(db[ldesc].db.desc.res)
|
|
|
|
& OHCI_COUNT_MASK;
|
2003-01-26 15:39:04 +00:00
|
|
|
if (stat == 0)
|
|
|
|
break;
|
|
|
|
STAILQ_REMOVE_HEAD(&it->stdma, link);
|
2014-09-27 16:50:21 +00:00
|
|
|
switch (stat & FWOHCIEV_MASK) {
|
2003-01-26 15:39:04 +00:00
|
|
|
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-04-17 03:38:03 +00:00
|
|
|
"Isochronous transmit err %02x(%s)\n",
|
|
|
|
stat, fwohcicode[stat & 0x1f]);
|
2003-01-26 15:39:04 +00:00
|
|
|
}
|
|
|
|
STAILQ_INSERT_TAIL(&it->stfree, chunk, link);
|
|
|
|
w++;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GUNLOCK(fc);
|
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-10-02 04:06:56 +00:00
|
|
|
struct fwohcidb_tr *db_tr;
|
2003-01-26 15:39:04 +00:00
|
|
|
struct fw_bulkxfer *chunk;
|
|
|
|
struct fw_xferq *ir;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t stat;
|
2015-01-21 20:08:24 +00:00
|
|
|
int w = 0, ldesc;
|
2003-01-13 16:08:09 +00:00
|
|
|
|
2003-01-26 15:39:04 +00:00
|
|
|
ir = fc->ir[dmach];
|
2003-04-17 03:38:03 +00:00
|
|
|
ldesc = sc->ir[dmach].ndesc - 1;
|
2007-06-06 14:31:36 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
#if 0
|
|
|
|
dump_db(sc, dmach);
|
|
|
|
#endif
|
2007-06-06 14:31:36 +00:00
|
|
|
if ((ir->flag & FWXFERQ_HANDLER) == 0)
|
|
|
|
FW_GLOCK(fc);
|
2003-04-17 03:38:03 +00:00
|
|
|
fwdma_sync_multiseg_all(sc->ir[dmach].am, BUS_DMASYNC_POSTREAD);
|
2003-01-26 15:39:04 +00:00
|
|
|
while ((chunk = STAILQ_FIRST(&ir->stdma)) != NULL) {
|
2003-04-17 03:38:03 +00:00
|
|
|
db_tr = (struct fwohcidb_tr *)chunk->end;
|
|
|
|
stat = FWOHCI_DMA_READ(db_tr->db[ldesc].db.desc.res)
|
|
|
|
>> OHCI_STATUS_SHIFT;
|
2003-01-26 15:39:04 +00:00
|
|
|
if (stat == 0)
|
|
|
|
break;
|
2003-04-17 03:38:03 +00:00
|
|
|
|
|
|
|
if (chunk->mbuf != NULL) {
|
|
|
|
bus_dmamap_sync(sc->ir[dmach].dmat, db_tr->dma_map,
|
|
|
|
BUS_DMASYNC_POSTREAD);
|
|
|
|
bus_dmamap_unload(sc->ir[dmach].dmat, db_tr->dma_map);
|
|
|
|
} else if (ir->buf != NULL) {
|
|
|
|
fwdma_sync_multiseg(ir->buf, chunk->poffset,
|
|
|
|
ir->bnpacket, BUS_DMASYNC_POSTREAD);
|
|
|
|
} else {
|
|
|
|
/* XXX */
|
2016-05-03 03:41:25 +00:00
|
|
|
printf("fwohci_rbuf_update: this shouldn't happened\n");
|
2003-04-17 03:38:03 +00:00
|
|
|
}
|
|
|
|
|
2003-01-26 15:39:04 +00:00
|
|
|
STAILQ_REMOVE_HEAD(&ir->stdma, link);
|
|
|
|
STAILQ_INSERT_TAIL(&ir->stvalid, chunk, link);
|
|
|
|
switch (stat & FWOHCIEV_MASK) {
|
|
|
|
case FWOHCIEV_ACKCOMPL:
|
2003-03-06 05:06:44 +00:00
|
|
|
chunk->resp = 0;
|
2003-01-26 15:39:04 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-03-06 05:06:44 +00:00
|
|
|
chunk->resp = EINVAL;
|
2003-01-26 15:39:04 +00:00
|
|
|
device_printf(fc->dev,
|
2003-04-17 03:38:03 +00:00
|
|
|
"Isochronous receive err %02x(%s)\n",
|
|
|
|
stat, fwohcicode[stat & 0x1f]);
|
2003-01-26 15:39:04 +00:00
|
|
|
}
|
|
|
|
w++;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
if ((ir->flag & FWXFERQ_HANDLER) == 0)
|
|
|
|
FW_GUNLOCK(fc);
|
|
|
|
if (w == 0)
|
|
|
|
return;
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
if (ir->flag & FWXFERQ_HANDLER)
|
2007-06-06 14:31:36 +00:00
|
|
|
ir->hand(ir);
|
|
|
|
else
|
|
|
|
wakeup(ir);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
void
|
2004-05-22 16:14:17 +00:00
|
|
|
dump_dma(struct fwohci_softc *sc, uint32_t ch)
|
2002-11-12 05:52:01 +00:00
|
|
|
{
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t off, cntl, stat, cmd, match;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
if (ch == 0) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ATQOFF;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else if (ch == 1) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ATSOFF;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else if (ch == 2) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ARQOFF;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else if (ch == 3) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ARSOFF;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else if (ch < IRX_CH) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ITCTL(ch - ITX_CH);
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_IRCTL(ch - IRX_CH);
|
|
|
|
}
|
|
|
|
cntl = stat = OREAD(sc, off);
|
|
|
|
cmd = OREAD(sc, off + 0xc);
|
|
|
|
match = OREAD(sc, off + 0x10);
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
device_printf(sc->fc.dev, "ch %1x cntl:0x%08x cmd:0x%08x match:0x%08x\n",
|
2002-09-13 12:31:56 +00:00
|
|
|
ch,
|
2014-09-27 16:50:21 +00:00
|
|
|
cntl,
|
|
|
|
cmd,
|
2002-09-13 12:31:56 +00:00
|
|
|
match);
|
2014-09-27 16:50:21 +00:00
|
|
|
stat &= 0xffff;
|
2003-04-17 03:38:03 +00:00
|
|
|
if (stat) {
|
2002-09-13 12:31:56 +00:00
|
|
|
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
|
|
|
|
);
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
2002-09-13 12:31:56 +00:00
|
|
|
device_printf(sc->fc.dev, "dma %d ch: Nostat\n", ch);
|
|
|
|
}
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
void
|
2004-05-22 16:14:17 +00:00
|
|
|
dump_db(struct fwohci_softc *sc, uint32_t ch)
|
2002-11-12 05:52:01 +00:00
|
|
|
{
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fwohci_dbch *dbch;
|
2021-12-09 16:36:45 +00:00
|
|
|
struct fwohcidb_tr *cp = NULL, *pp;
|
|
|
|
struct fwohcidb *curr = NULL;
|
|
|
|
#if 0
|
|
|
|
struct fwohcidb *prev
|
|
|
|
struct fwohcidb *next = NULL;
|
|
|
|
struct fwohcidb_tr *np = NULL;
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
int idb, jdb;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t cmd, off;
|
2014-09-27 16:50:21 +00:00
|
|
|
|
|
|
|
if (ch == 0) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ATQOFF;
|
|
|
|
dbch = &sc->atrq;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else if (ch == 1) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ATSOFF;
|
|
|
|
dbch = &sc->atrs;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else if (ch == 2) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ARQOFF;
|
|
|
|
dbch = &sc->arrq;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else if (ch == 3) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ARSOFF;
|
|
|
|
dbch = &sc->arrs;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else if (ch < IRX_CH) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ITCTL(ch - ITX_CH);
|
|
|
|
dbch = &sc->it[ch - ITX_CH];
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_IRCTL(ch - IRX_CH);
|
|
|
|
dbch = &sc->ir[ch - IRX_CH];
|
|
|
|
}
|
|
|
|
cmd = OREAD(sc, off + 0xc);
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
if (dbch->ndb == 0) {
|
2002-09-13 12:31:56 +00:00
|
|
|
device_printf(sc->fc.dev, "No DB is attached ch=%d\n", ch);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pp = dbch->top;
|
2021-12-09 16:36:45 +00:00
|
|
|
#if 0
|
2002-09-13 12:31:56 +00:00
|
|
|
prev = pp->db;
|
2021-12-09 16:36:45 +00:00
|
|
|
#endif
|
2014-09-27 16:50:21 +00:00
|
|
|
for (idb = 0; idb < dbch->ndb; idb++) {
|
2002-09-13 12:31:56 +00:00
|
|
|
cp = STAILQ_NEXT(pp, link);
|
2014-09-27 16:50:21 +00:00
|
|
|
if (cp == NULL) {
|
2002-09-13 12:31:56 +00:00
|
|
|
curr = NULL;
|
|
|
|
goto outdb;
|
|
|
|
}
|
2021-12-09 16:36:45 +00:00
|
|
|
#if 0
|
2002-09-13 12:31:56 +00:00
|
|
|
np = STAILQ_NEXT(cp, link);
|
2021-12-09 16:36:45 +00:00
|
|
|
#endif
|
2014-09-27 16:50:21 +00:00
|
|
|
for (jdb = 0; jdb < dbch->ndesc; jdb++) {
|
2003-04-17 03:38:03 +00:00
|
|
|
if ((cmd & 0xfffffff0) == cp->bus_addr) {
|
2002-09-13 12:31:56 +00:00
|
|
|
curr = cp->db;
|
2021-12-09 16:36:45 +00:00
|
|
|
#if 0
|
2014-09-27 16:50:21 +00:00
|
|
|
if (np != NULL) {
|
2002-09-13 12:31:56 +00:00
|
|
|
next = np->db;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
2002-09-13 12:31:56 +00:00
|
|
|
next = NULL;
|
|
|
|
}
|
2021-12-09 16:36:45 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
goto outdb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pp = STAILQ_NEXT(pp, link);
|
2014-09-27 16:50:21 +00:00
|
|
|
if (pp == NULL) {
|
2005-03-29 01:44:59 +00:00
|
|
|
curr = NULL;
|
|
|
|
goto outdb;
|
|
|
|
}
|
2021-12-09 16:36:45 +00:00
|
|
|
#if 0
|
2002-09-13 12:31:56 +00:00
|
|
|
prev = pp->db;
|
2021-12-09 16:36:45 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
outdb:
|
2014-09-27 16:50:21 +00:00
|
|
|
if (curr != NULL) {
|
2003-04-17 03:38:03 +00:00
|
|
|
#if 0
|
2002-09-13 12:31:56 +00:00
|
|
|
printf("Prev DB %d\n", ch);
|
2003-04-17 03:38:03 +00:00
|
|
|
print_db(pp, prev, ch, dbch->ndesc);
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
printf("Current DB %d\n", ch);
|
2003-04-17 03:38:03 +00:00
|
|
|
print_db(cp, curr, ch, dbch->ndesc);
|
|
|
|
#if 0
|
2002-09-13 12:31:56 +00:00
|
|
|
printf("Next DB %d\n", ch);
|
2003-04-17 03:38:03 +00:00
|
|
|
print_db(np, next, ch, dbch->ndesc);
|
|
|
|
#endif
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
2002-09-13 12:31:56 +00:00
|
|
|
printf("dbdump err ch = %d cmd = 0x%08x\n", ch, cmd);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
void
|
2003-10-02 04:06:56 +00:00
|
|
|
print_db(struct fwohcidb_tr *db_tr, struct fwohcidb *db,
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t ch, uint32_t max)
|
2002-11-12 05:52:01 +00:00
|
|
|
{
|
2002-09-13 12:31:56 +00:00
|
|
|
fwohcireg_t stat;
|
|
|
|
int i, key;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t cmd, res;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
if (db == NULL) {
|
2002-09-13 12:31:56 +00:00
|
|
|
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");
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i <= max; i++) {
|
2003-04-17 03:38:03 +00:00
|
|
|
cmd = FWOHCI_DMA_READ(db[i].db.desc.cmd);
|
|
|
|
res = FWOHCI_DMA_READ(db[i].db.desc.res);
|
|
|
|
key = cmd & OHCI_KEY_MASK;
|
|
|
|
stat = res >> OHCI_STATUS_SHIFT;
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%08jx %s %s %s %s %5d %08x %08x %04x:%04x",
|
|
|
|
(uintmax_t)db_tr->bus_addr,
|
2003-04-17 03:38:03 +00:00
|
|
|
dbcode[(cmd >> 28) & 0xf],
|
|
|
|
dbkey[(cmd >> 24) & 0x7],
|
|
|
|
dbcond[(cmd >> 20) & 0x3],
|
|
|
|
dbcond[(cmd >> 18) & 0x3],
|
|
|
|
cmd & OHCI_COUNT_MASK,
|
|
|
|
FWOHCI_DMA_READ(db[i].db.desc.addr),
|
|
|
|
FWOHCI_DMA_READ(db[i].db.desc.depend),
|
|
|
|
stat,
|
|
|
|
res & OHCI_COUNT_MASK);
|
2014-09-27 16:50:21 +00:00
|
|
|
if (stat & 0xff00) {
|
2002-09-13 12:31:56 +00:00
|
|
|
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
|
|
|
|
);
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
2002-09-13 12:31:56 +00:00
|
|
|
printf(" Nostat\n");
|
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
if (key == OHCI_KEY_ST2) {
|
|
|
|
printf("0x%08x 0x%08x 0x%08x 0x%08x\n",
|
|
|
|
FWOHCI_DMA_READ(db[i + 1].db.immed[0]),
|
|
|
|
FWOHCI_DMA_READ(db[i + 1].db.immed[1]),
|
|
|
|
FWOHCI_DMA_READ(db[i + 1].db.immed[2]),
|
|
|
|
FWOHCI_DMA_READ(db[i + 1].db.immed[3]));
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
if (key == OHCI_KEY_DEVICE) {
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
if ((cmd & OHCI_BRANCH_MASK)
|
|
|
|
== OHCI_BRANCH_ALWAYS) {
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
if ((cmd & OHCI_CMD_MASK)
|
|
|
|
== OHCI_OUTPUT_LAST) {
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
if ((cmd & OHCI_CMD_MASK)
|
|
|
|
== OHCI_INPUT_LAST) {
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
if (key == OHCI_KEY_ST2) {
|
2002-09-13 12:31:56 +00:00
|
|
|
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;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t fun;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-02-09 07:16:01 +00:00
|
|
|
device_printf(fc->dev, "Initiate bus reset\n");
|
2002-09-13 12:31:56 +00:00
|
|
|
sc = (struct fwohci_softc *)fc;
|
2002-12-26 03:17:59 +00:00
|
|
|
|
2009-02-01 23:28:52 +00:00
|
|
|
FW_GLOCK(fc);
|
2004-05-23 14:22:11 +00:00
|
|
|
/*
|
|
|
|
* Make sure our cached values from the config rom are
|
|
|
|
* initialised.
|
|
|
|
*/
|
|
|
|
OWRITE(sc, OHCI_CROMHDR, ntohl(sc->fc.config_rom[0]));
|
|
|
|
OWRITE(sc, OHCI_BUS_OPT, ntohl(sc->fc.config_rom[2]));
|
|
|
|
|
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
|
2009-02-01 23:28:52 +00:00
|
|
|
FW_GUNLOCK(fc);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
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
|
|
|
{
|
2021-12-09 16:36:45 +00:00
|
|
|
struct fwohcidb_tr *db_tr;
|
|
|
|
#if 0
|
|
|
|
struct fwohcidb_tr *fdb_tr;
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fwohci_dbch *dbch;
|
2003-10-02 04:06:56 +00:00
|
|
|
struct fwohcidb *db;
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fw_pkt *fp;
|
2003-10-02 04:06:56 +00:00
|
|
|
struct fwohci_txpkthdr *ohcifp;
|
2002-09-13 12:31:56 +00:00
|
|
|
unsigned short chtag;
|
|
|
|
int idb;
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GLOCK_ASSERT(&sc->fc);
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
dbch = &sc->it[dmach];
|
|
|
|
chtag = sc->it[dmach].xferq.flag & 0xff;
|
|
|
|
|
|
|
|
db_tr = (struct fwohcidb_tr *)(bulkxfer->start);
|
2021-12-09 16:36:45 +00:00
|
|
|
#if 0
|
2002-09-13 12:31:56 +00:00
|
|
|
fdb_tr = (struct fwohcidb_tr *)(bulkxfer->end);
|
2003-04-17 03:38:03 +00:00
|
|
|
device_printf(sc->fc.dev, "DB %08x %08x %08x\n", bulkxfer, db_tr->bus_addr, fdb_tr->bus_addr);
|
2021-12-09 16:36:45 +00:00
|
|
|
#endif
|
2014-09-27 16:50:21 +00:00
|
|
|
for (idb = 0; idb < dbch->xferq.bnpacket; idb++) {
|
2003-01-26 18:38:06 +00:00
|
|
|
db = db_tr->db;
|
2002-09-13 12:31:56 +00:00
|
|
|
fp = (struct fw_pkt *)db_tr->buf;
|
2003-10-02 04:06:56 +00:00
|
|
|
ohcifp = (struct fwohci_txpkthdr *) db[1].db.immed;
|
2003-04-17 03:38:03 +00:00
|
|
|
ohcifp->mode.ld[0] = fp->mode.ld[0];
|
2003-08-20 03:11:37 +00:00
|
|
|
ohcifp->mode.common.spd = 0 & 0x7;
|
2003-04-17 03:38:03 +00:00
|
|
|
ohcifp->mode.stream.len = fp->mode.stream.len;
|
2002-09-13 12:31:56 +00:00
|
|
|
ohcifp->mode.stream.chtag = chtag;
|
|
|
|
ohcifp->mode.stream.tcode = 0xa;
|
2003-04-17 03:38:03 +00:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2014-09-27 16:50:21 +00:00
|
|
|
FWOHCI_DMA_WRITE(db[1].db.immed[0], db[1].db.immed[0]);
|
|
|
|
FWOHCI_DMA_WRITE(db[1].db.immed[1], db[1].db.immed[1]);
|
2003-04-17 03:38:03 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_CLEAR(db[2].db.desc.cmd, OHCI_COUNT_MASK);
|
|
|
|
FWOHCI_DMA_SET(db[2].db.desc.cmd, fp->mode.stream.len);
|
|
|
|
FWOHCI_DMA_WRITE(db[2].db.desc.res, 0);
|
2003-01-26 18:38:06 +00:00
|
|
|
#if 0 /* if bulkxfer->npackets changes */
|
2003-04-17 03:38:03 +00:00
|
|
|
db[2].db.desc.cmd = 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-04-17 03:38:03 +00:00
|
|
|
= STAILQ_NEXT(db_tr, link)->bus_addr | dbch->ndesc;
|
2003-01-26 18:38:06 +00:00
|
|
|
#else
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_SET(db[0].db.desc.depend, dbch->ndesc);
|
|
|
|
FWOHCI_DMA_SET(db[dbch->ndesc - 1].db.desc.depend, dbch->ndesc);
|
2003-01-26 18:38:06 +00:00
|
|
|
#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;
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_CLEAR(db[0].db.desc.depend, 0xf);
|
|
|
|
FWOHCI_DMA_CLEAR(db[dbch->ndesc - 1].db.desc.depend, 0xf);
|
2003-01-26 18:38:06 +00:00
|
|
|
#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
|
2021-12-09 16:36:45 +00:00
|
|
|
#if 0
|
2002-09-13 12:31:56 +00:00
|
|
|
db_tr = (struct fwohcidb_tr *)bulkxfer->start;
|
|
|
|
fdb_tr = (struct fwohcidb_tr *)bulkxfer->end;
|
2003-04-17 03:38:03 +00:00
|
|
|
device_printf(sc->fc.dev, "DB %08x %3d %08x %08x\n", bulkxfer, bulkxfer->npacket, db_tr->bus_addr, fdb_tr->bus_addr);
|
2021-12-09 16:36:45 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
static int
|
2003-04-17 03:38:03 +00:00
|
|
|
fwohci_add_tx_buf(struct fwohci_dbch *dbch, struct fwohcidb_tr *db_tr,
|
|
|
|
int poffset)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-10-02 04:06:56 +00:00
|
|
|
struct fwohcidb *db = db_tr->db;
|
2003-04-17 03:38:03 +00:00
|
|
|
struct fw_xferq *it;
|
2002-09-13 12:31:56 +00:00
|
|
|
int err = 0;
|
2003-04-17 03:38:03 +00:00
|
|
|
|
|
|
|
it = &dbch->xferq;
|
2014-09-27 16:50:21 +00:00
|
|
|
if (it->buf == 0) {
|
2002-09-13 12:31:56 +00:00
|
|
|
err = EINVAL;
|
|
|
|
return err;
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
db_tr->buf = fwdma_v_addr(it->buf, poffset);
|
2002-09-13 12:31:56 +00:00
|
|
|
db_tr->dbcnt = 3;
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_WRITE(db[0].db.desc.cmd,
|
|
|
|
OHCI_OUTPUT_MORE | OHCI_KEY_ST2 | 8);
|
2003-08-20 03:11:37 +00:00
|
|
|
FWOHCI_DMA_WRITE(db[0].db.desc.addr, 0);
|
2003-10-02 04:06:56 +00:00
|
|
|
bzero((void *)&db[1].db.immed[0], sizeof(db[1].db.immed));
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_WRITE(db[2].db.desc.addr,
|
2004-05-22 16:14:17 +00:00
|
|
|
fwdma_bus_addr(it->buf, poffset) + sizeof(uint32_t));
|
2003-04-17 03:38:03 +00:00
|
|
|
|
|
|
|
FWOHCI_DMA_WRITE(db[2].db.desc.cmd,
|
|
|
|
OHCI_OUTPUT_LAST | OHCI_UPDATE | OHCI_BRANCH_ALWAYS);
|
2003-01-26 18:38:06 +00:00
|
|
|
#if 1
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_WRITE(db[0].db.desc.res, 0);
|
|
|
|
FWOHCI_DMA_WRITE(db[2].db.desc.res, 0);
|
2003-01-26 18:38:06 +00:00
|
|
|
#endif
|
2003-04-17 03:38:03 +00:00
|
|
|
return 0;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
|
|
|
int
|
2003-04-17 03:38:03 +00:00
|
|
|
fwohci_add_rx_buf(struct fwohci_dbch *dbch, struct fwohcidb_tr *db_tr,
|
|
|
|
int poffset, struct fwdma_alloc *dummy_dma)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-10-02 04:06:56 +00:00
|
|
|
struct fwohcidb *db = db_tr->db;
|
2003-04-17 03:38:03 +00:00
|
|
|
struct fw_xferq *ir;
|
|
|
|
int i, ldesc;
|
|
|
|
bus_addr_t dbuf[2];
|
2002-09-13 12:31:56 +00:00
|
|
|
int dsiz[2];
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
ir = &dbch->xferq;
|
|
|
|
if (ir->buf == NULL && (dbch->xferq.flag & FWXFERQ_EXTBUF) == 0) {
|
2008-05-10 09:22:06 +00:00
|
|
|
if (db_tr->buf == NULL) {
|
|
|
|
db_tr->buf = fwdma_malloc_size(dbch->dmat,
|
|
|
|
&db_tr->dma_map, ir->psize, &dbuf[0],
|
|
|
|
BUS_DMA_NOWAIT);
|
|
|
|
if (db_tr->buf == NULL)
|
2014-09-27 16:50:21 +00:00
|
|
|
return (ENOMEM);
|
2008-05-10 09:22:06 +00:00
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
db_tr->dbcnt = 1;
|
2003-04-17 03:38:03 +00:00
|
|
|
dsiz[0] = ir->psize;
|
|
|
|
bus_dmamap_sync(dbch->dmat, db_tr->dma_map,
|
|
|
|
BUS_DMASYNC_PREREAD);
|
|
|
|
} else {
|
|
|
|
db_tr->dbcnt = 0;
|
|
|
|
if (dummy_dma != NULL) {
|
2004-05-22 16:14:17 +00:00
|
|
|
dsiz[db_tr->dbcnt] = sizeof(uint32_t);
|
2003-04-17 03:38:03 +00:00
|
|
|
dbuf[db_tr->dbcnt++] = dummy_dma->bus_addr;
|
|
|
|
}
|
|
|
|
dsiz[db_tr->dbcnt] = ir->psize;
|
|
|
|
if (ir->buf != NULL) {
|
|
|
|
db_tr->buf = fwdma_v_addr(ir->buf, poffset);
|
2014-09-27 16:50:21 +00:00
|
|
|
dbuf[db_tr->dbcnt] = fwdma_bus_addr(ir->buf, poffset);
|
2003-04-17 03:38:03 +00:00
|
|
|
}
|
|
|
|
db_tr->dbcnt++;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < db_tr->dbcnt; i++) {
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_WRITE(db[i].db.desc.addr, dbuf[i]);
|
|
|
|
FWOHCI_DMA_WRITE(db[i].db.desc.cmd, OHCI_INPUT_MORE | dsiz[i]);
|
|
|
|
if (ir->flag & FWXFERQ_STREAM) {
|
|
|
|
FWOHCI_DMA_SET(db[i].db.desc.cmd, OHCI_UPDATE);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
FWOHCI_DMA_WRITE(db[i].db.desc.res, dsiz[i]);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
ldesc = db_tr->dbcnt - 1;
|
|
|
|
if (ir->flag & FWXFERQ_STREAM) {
|
|
|
|
FWOHCI_DMA_SET(db[ldesc].db.desc.cmd, OHCI_INPUT_LAST);
|
|
|
|
}
|
|
|
|
FWOHCI_DMA_SET(db[ldesc].db.desc.cmd, OHCI_BRANCH_ALWAYS);
|
|
|
|
return 0;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
fwohci_arcv_swap(struct fw_pkt *fp, int len)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-04-17 03:38:03 +00:00
|
|
|
struct fw_pkt *fp0;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t ld0;
|
2021-12-09 16:36:45 +00:00
|
|
|
int hlen;
|
2003-04-17 03:38:03 +00:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2021-12-09 16:36:45 +00:00
|
|
|
int slen;
|
2003-04-17 03:38:03 +00:00
|
|
|
int i;
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
ld0 = FWOHCI_DMA_READ(fp->mode.ld[0]);
|
|
|
|
#if 0
|
|
|
|
printf("ld0: x%08x\n", ld0);
|
|
|
|
#endif
|
|
|
|
fp0 = (struct fw_pkt *)&ld0;
|
2003-10-02 04:06:56 +00:00
|
|
|
/* determine length to swap */
|
2003-04-17 03:38:03 +00:00
|
|
|
switch (fp0->mode.common.tcode) {
|
|
|
|
case FWTCODE_RREQQ:
|
|
|
|
case FWTCODE_WRES:
|
|
|
|
case FWTCODE_WREQQ:
|
|
|
|
case FWTCODE_RRESQ:
|
|
|
|
case FWOHCITCODE_PHY:
|
2021-12-09 16:36:45 +00:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2003-04-17 03:38:03 +00:00
|
|
|
slen = 12;
|
2021-12-09 16:36:45 +00:00
|
|
|
#endif
|
2003-04-17 03:38:03 +00:00
|
|
|
break;
|
|
|
|
case FWTCODE_RREQB:
|
|
|
|
case FWTCODE_WREQB:
|
|
|
|
case FWTCODE_LREQ:
|
|
|
|
case FWTCODE_RRESB:
|
|
|
|
case FWTCODE_LRES:
|
2021-12-09 16:36:45 +00:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2003-04-17 03:38:03 +00:00
|
|
|
slen = 16;
|
2021-12-09 16:36:45 +00:00
|
|
|
#endif
|
2003-04-17 03:38:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Unknown tcode %d\n", fp0->mode.common.tcode);
|
2014-09-27 16:50:21 +00:00
|
|
|
return (0);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
hlen = tinfo[fp0->mode.common.tcode].hdr_len;
|
|
|
|
if (hlen > len) {
|
2003-04-17 03:38:03 +00:00
|
|
|
if (firewire_debug)
|
|
|
|
printf("splitted header\n");
|
2014-09-27 16:50:21 +00:00
|
|
|
return (-hlen);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < slen/4; i++)
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.ld[i] = FWOHCI_DMA_READ(fp->mode.ld[i]);
|
|
|
|
#endif
|
2014-09-27 16:50:21 +00:00
|
|
|
return (hlen);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-04-17 03:38:03 +00:00
|
|
|
fwohci_get_plen(struct fwohci_softc *sc, struct fwohci_dbch *dbch, struct fw_pkt *fp)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-10-02 04:06:56 +00:00
|
|
|
struct tcode_info *info;
|
2003-04-17 03:38:03 +00:00
|
|
|
int r;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
info = &tinfo[fp->mode.common.tcode];
|
2004-05-22 16:14:17 +00:00
|
|
|
r = info->hdr_len + sizeof(uint32_t);
|
2003-10-02 04:06:56 +00:00
|
|
|
if ((info->flag & FWTI_BLOCK_ASY) != 0)
|
2021-02-17 21:12:06 +00:00
|
|
|
r += roundup2((uint32_t)fp->mode.wreqb.len, sizeof(uint32_t));
|
2003-10-02 04:06:56 +00:00
|
|
|
|
2007-04-30 14:06:30 +00:00
|
|
|
if (r == sizeof(uint32_t)) {
|
2003-10-02 04:06:56 +00:00
|
|
|
/* XXX */
|
2003-02-13 13:35:57 +00:00
|
|
|
device_printf(sc->fc.dev, "Unknown tcode %d\n",
|
|
|
|
fp->mode.common.tcode);
|
2007-04-30 14:06:30 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
|
2003-02-13 13:35:57 +00:00
|
|
|
if (r > dbch->xferq.psize) {
|
|
|
|
device_printf(sc->fc.dev, "Invalid packet length %d\n", r);
|
2007-04-30 14:06:30 +00:00
|
|
|
return (-1);
|
2003-02-13 13:35:57 +00:00
|
|
|
/* panic ? */
|
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
|
2003-02-13 13:35:57 +00:00
|
|
|
return r;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
static void
|
2007-04-30 14:06:30 +00:00
|
|
|
fwohci_arcv_free_buf(struct fwohci_softc *sc, struct fwohci_dbch *dbch,
|
|
|
|
struct fwohcidb_tr *db_tr, uint32_t off, int wake)
|
2003-04-17 03:38:03 +00:00
|
|
|
{
|
2003-10-02 04:06:56 +00:00
|
|
|
struct fwohcidb *db = &db_tr->db[0];
|
2003-04-17 03:38:03 +00:00
|
|
|
|
|
|
|
FWOHCI_DMA_CLEAR(db->db.desc.depend, 0xf);
|
|
|
|
FWOHCI_DMA_WRITE(db->db.desc.res, dbch->xferq.psize);
|
|
|
|
FWOHCI_DMA_SET(dbch->bottom->db[0].db.desc.depend, 1);
|
|
|
|
fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_PREWRITE);
|
|
|
|
dbch->bottom = db_tr;
|
2007-04-30 14:06:30 +00:00
|
|
|
|
|
|
|
if (wake)
|
|
|
|
OWRITE(sc, OHCI_DMACTL(off), OHCI_CNTL_DMA_WAKE);
|
2003-04-17 03:38:03 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2003-04-17 03:38:03 +00:00
|
|
|
struct iovec vec[2];
|
|
|
|
struct fw_pkt pktbuf;
|
|
|
|
int nvec;
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fw_pkt *fp;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint8_t *ld;
|
2007-04-30 14:06:30 +00:00
|
|
|
uint32_t stat, off, status, event;
|
2002-09-13 12:31:56 +00:00
|
|
|
u_int spd;
|
2022-07-21 17:59:08 +00:00
|
|
|
#ifdef COUNT_PACKETS
|
|
|
|
int pcnt;
|
|
|
|
#endif
|
|
|
|
int len, plen, hlen, offset;
|
2002-09-13 12:31:56 +00:00
|
|
|
int s;
|
|
|
|
caddr_t buf;
|
|
|
|
int resCount;
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
if (&sc->arrq == dbch) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ARQOFF;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else if (&sc->arrs == dbch) {
|
2002-09-13 12:31:56 +00:00
|
|
|
off = OHCI_ARSOFF;
|
2014-09-27 16:50:21 +00:00
|
|
|
} else {
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = splfw();
|
|
|
|
db_tr = dbch->top;
|
2022-07-21 17:59:08 +00:00
|
|
|
#ifdef COUNT_PACKETS
|
2002-09-13 12:31:56 +00:00
|
|
|
pcnt = 0;
|
2022-07-21 17:59:08 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
/* XXX we cannot handle a packet which lies in more than two buf */
|
2003-04-17 03:38:03 +00:00
|
|
|
fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_POSTREAD);
|
|
|
|
fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_POSTWRITE);
|
|
|
|
status = FWOHCI_DMA_READ(db_tr->db[0].db.desc.res) >> OHCI_STATUS_SHIFT;
|
|
|
|
resCount = FWOHCI_DMA_READ(db_tr->db[0].db.desc.res) & OHCI_COUNT_MASK;
|
2007-04-30 14:06:30 +00:00
|
|
|
while (status & OHCI_CNTL_DMA_ACTIVE) {
|
2003-04-17 03:38:03 +00:00
|
|
|
#if 0
|
2007-04-30 14:06:30 +00:00
|
|
|
|
|
|
|
if (off == OHCI_ARQOFF)
|
|
|
|
printf("buf 0x%08x, status 0x%04x, resCount 0x%04x\n",
|
|
|
|
db_tr->bus_addr, status, resCount);
|
2003-04-17 03:38:03 +00:00
|
|
|
#endif
|
|
|
|
len = dbch->xferq.psize - resCount;
|
2004-05-22 16:14:17 +00:00
|
|
|
ld = (uint8_t *)db_tr->buf;
|
2003-04-17 03:38:03 +00:00
|
|
|
if (dbch->pdb_tr == NULL) {
|
|
|
|
len -= dbch->buf_offset;
|
|
|
|
ld += dbch->buf_offset;
|
|
|
|
}
|
|
|
|
if (len > 0)
|
|
|
|
bus_dmamap_sync(dbch->dmat, db_tr->dma_map,
|
|
|
|
BUS_DMASYNC_POSTREAD);
|
2014-09-27 16:50:21 +00:00
|
|
|
while (len > 0) {
|
2002-11-12 04:54:30 +00:00
|
|
|
if (count >= 0 && count-- == 0)
|
|
|
|
goto out;
|
2014-09-27 16:50:21 +00:00
|
|
|
if (dbch->pdb_tr != NULL) {
|
2003-04-17 03:38:03 +00:00
|
|
|
/* we have a fragment in previous buffer */
|
|
|
|
int rlen;
|
|
|
|
|
|
|
|
offset = dbch->buf_offset;
|
|
|
|
if (offset < 0)
|
|
|
|
offset = - offset;
|
|
|
|
buf = dbch->pdb_tr->buf + offset;
|
|
|
|
rlen = dbch->xferq.psize - offset;
|
|
|
|
if (firewire_debug)
|
|
|
|
printf("rlen=%d, offset=%d\n",
|
|
|
|
rlen, dbch->buf_offset);
|
|
|
|
if (dbch->buf_offset < 0) {
|
|
|
|
/* splitted in header, pull up */
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
p = (char *)&pktbuf;
|
|
|
|
bcopy(buf, p, rlen);
|
|
|
|
p += rlen;
|
|
|
|
/* this must be too long but harmless */
|
|
|
|
rlen = sizeof(pktbuf) - rlen;
|
|
|
|
if (rlen < 0)
|
|
|
|
printf("why rlen < 0\n");
|
|
|
|
bcopy(db_tr->buf, p, rlen);
|
2002-09-13 12:31:56 +00:00
|
|
|
ld += rlen;
|
|
|
|
len -= rlen;
|
2003-04-17 03:38:03 +00:00
|
|
|
hlen = fwohci_arcv_swap(&pktbuf, sizeof(pktbuf));
|
2007-04-30 14:06:30 +00:00
|
|
|
if (hlen <= 0) {
|
|
|
|
printf("hlen should be positive.");
|
|
|
|
goto err;
|
2003-04-17 03:38:03 +00:00
|
|
|
}
|
|
|
|
offset = sizeof(pktbuf);
|
|
|
|
vec[0].iov_base = (char *)&pktbuf;
|
|
|
|
vec[0].iov_len = offset;
|
|
|
|
} else {
|
|
|
|
/* splitted in payload */
|
|
|
|
offset = rlen;
|
|
|
|
vec[0].iov_base = buf;
|
|
|
|
vec[0].iov_len = rlen;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
fp=(struct fw_pkt *)vec[0].iov_base;
|
|
|
|
nvec = 1;
|
|
|
|
} else {
|
|
|
|
/* no fragment in previous buffer */
|
2002-09-13 12:31:56 +00:00
|
|
|
fp=(struct fw_pkt *)ld;
|
2003-04-17 03:38:03 +00:00
|
|
|
hlen = fwohci_arcv_swap(fp, len);
|
|
|
|
if (hlen == 0)
|
2007-04-30 14:06:30 +00:00
|
|
|
goto err;
|
2003-04-17 03:38:03 +00:00
|
|
|
if (hlen < 0) {
|
|
|
|
dbch->pdb_tr = db_tr;
|
|
|
|
dbch->buf_offset = - dbch->buf_offset;
|
|
|
|
/* sanity check */
|
2014-09-27 16:50:21 +00:00
|
|
|
if (resCount != 0) {
|
2007-04-30 14:06:30 +00:00
|
|
|
printf("resCount=%d hlen=%d\n",
|
|
|
|
resCount, hlen);
|
|
|
|
goto err;
|
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
offset = 0;
|
|
|
|
nvec = 0;
|
|
|
|
}
|
|
|
|
plen = fwohci_get_plen(sc, dbch, fp) - offset;
|
|
|
|
if (plen < 0) {
|
|
|
|
/* minimum header size + trailer
|
|
|
|
= sizeof(fw_pkt) so this shouldn't happens */
|
2003-10-02 04:06:56 +00:00
|
|
|
printf("plen(%d) is negative! offset=%d\n",
|
|
|
|
plen, offset);
|
2007-04-30 14:06:30 +00:00
|
|
|
goto err;
|
2003-04-17 03:38:03 +00:00
|
|
|
}
|
|
|
|
if (plen > 0) {
|
|
|
|
len -= plen;
|
|
|
|
if (len < 0) {
|
|
|
|
dbch->pdb_tr = db_tr;
|
|
|
|
if (firewire_debug)
|
|
|
|
printf("splitted payload\n");
|
|
|
|
/* sanity check */
|
2014-09-27 16:50:21 +00:00
|
|
|
if (resCount != 0) {
|
2007-04-30 14:06:30 +00:00
|
|
|
printf("resCount=%d plen=%d"
|
|
|
|
" len=%d\n",
|
|
|
|
resCount, plen, len);
|
|
|
|
goto err;
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
goto out;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
vec[nvec].iov_base = ld;
|
|
|
|
vec[nvec].iov_len = plen;
|
2014-09-27 16:50:21 +00:00
|
|
|
nvec++;
|
2002-09-13 12:31:56 +00:00
|
|
|
ld += plen;
|
|
|
|
}
|
2004-05-22 16:14:17 +00:00
|
|
|
dbch->buf_offset = ld - (uint8_t *)db_tr->buf;
|
2003-04-17 03:38:03 +00:00
|
|
|
if (nvec == 0)
|
|
|
|
printf("nvec == 0\n");
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/* DMA result-code will be written at the tail of packet */
|
2007-04-30 14:06:30 +00:00
|
|
|
stat = FWOHCI_DMA_READ(*(uint32_t *)(ld - sizeof(struct fwohci_trailer)));
|
2003-02-09 07:16:01 +00:00
|
|
|
#if 0
|
2003-10-02 04:06:56 +00:00
|
|
|
printf("plen: %d, stat %x\n",
|
|
|
|
plen ,stat);
|
2002-09-13 12:31:56 +00:00
|
|
|
#endif
|
2007-04-30 14:06:30 +00:00
|
|
|
spd = (stat >> 21) & 0x3;
|
|
|
|
event = (stat >> 16) & 0x1f;
|
|
|
|
switch (event) {
|
2003-04-17 03:38:03 +00:00
|
|
|
case FWOHCIEV_ACKPEND:
|
|
|
|
#if 0
|
|
|
|
printf("fwohci_arcv: ack pending tcode=0x%x..\n", fp->mode.common.tcode);
|
|
|
|
#endif
|
|
|
|
/* fall through */
|
|
|
|
case FWOHCIEV_ACKCOMPL:
|
2003-10-02 04:06:56 +00:00
|
|
|
{
|
|
|
|
struct fw_rcv_buf rb;
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
if ((vec[nvec-1].iov_len -=
|
|
|
|
sizeof(struct fwohci_trailer)) == 0)
|
2014-09-27 16:50:21 +00:00
|
|
|
nvec--;
|
2003-10-02 04:06:56 +00:00
|
|
|
rb.fc = &sc->fc;
|
|
|
|
rb.vec = vec;
|
|
|
|
rb.nvec = nvec;
|
|
|
|
rb.spd = spd;
|
|
|
|
fw_rcv(&rb);
|
|
|
|
break;
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
case FWOHCIEV_BUSRST:
|
2007-06-08 07:53:59 +00:00
|
|
|
if ((sc->fc.status != FWBUSRESET) &&
|
|
|
|
(sc->fc.status != FWBUSINIT))
|
2003-04-17 03:38:03 +00:00
|
|
|
printf("got BUSRST packet!?\n");
|
|
|
|
break;
|
|
|
|
default:
|
2007-04-30 14:06:30 +00:00
|
|
|
device_printf(sc->fc.dev,
|
|
|
|
"Async DMA Receive error err=%02x %s"
|
|
|
|
" plen=%d offset=%d len=%d status=0x%08x"
|
|
|
|
" tcode=0x%x, stat=0x%08x\n",
|
|
|
|
event, fwohcicode[event], plen,
|
|
|
|
dbch->buf_offset, len,
|
|
|
|
OREAD(sc, OHCI_DMACTL(off)),
|
|
|
|
fp->mode.common.tcode, stat);
|
|
|
|
#if 1 /* XXX */
|
|
|
|
goto err;
|
2002-09-13 12:31:56 +00:00
|
|
|
#endif
|
2003-04-17 03:38:03 +00:00
|
|
|
break;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2022-07-21 17:59:08 +00:00
|
|
|
#ifdef COUNT_PACKETS
|
2014-09-27 16:50:21 +00:00
|
|
|
pcnt++;
|
2022-07-21 17:59:08 +00:00
|
|
|
#endif
|
2003-04-17 03:38:03 +00:00
|
|
|
if (dbch->pdb_tr != NULL) {
|
2007-04-30 14:06:30 +00:00
|
|
|
fwohci_arcv_free_buf(sc, dbch, dbch->pdb_tr,
|
|
|
|
off, 1);
|
2003-04-17 03:38:03 +00:00
|
|
|
dbch->pdb_tr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
out:
|
|
|
|
if (resCount == 0) {
|
|
|
|
/* done on this buffer */
|
2003-04-17 03:38:03 +00:00
|
|
|
if (dbch->pdb_tr == NULL) {
|
2007-04-30 14:06:30 +00:00
|
|
|
fwohci_arcv_free_buf(sc, dbch, db_tr, off, 1);
|
2003-04-17 03:38:03 +00:00
|
|
|
dbch->buf_offset = 0;
|
|
|
|
} else
|
|
|
|
if (dbch->pdb_tr != db_tr)
|
|
|
|
printf("pdb_tr != db_tr\n");
|
2002-09-13 12:31:56 +00:00
|
|
|
db_tr = STAILQ_NEXT(db_tr, link);
|
2003-04-17 03:38:03 +00:00
|
|
|
status = FWOHCI_DMA_READ(db_tr->db[0].db.desc.res)
|
|
|
|
>> OHCI_STATUS_SHIFT;
|
|
|
|
resCount = FWOHCI_DMA_READ(db_tr->db[0].db.desc.res)
|
|
|
|
& OHCI_COUNT_MASK;
|
|
|
|
/* XXX check buffer overrun */
|
2002-09-13 12:31:56 +00:00
|
|
|
dbch->top = db_tr;
|
|
|
|
} else {
|
|
|
|
dbch->buf_offset = dbch->xferq.psize - resCount;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* XXX make sure DMA is not dead */
|
|
|
|
}
|
2022-07-21 17:59:08 +00:00
|
|
|
#ifdef COUNT_PACKETS
|
2002-09-13 12:31:56 +00:00
|
|
|
if (pcnt < 1)
|
|
|
|
printf("fwohci_arcv: no packets\n");
|
|
|
|
#endif
|
|
|
|
splx(s);
|
2007-04-30 14:06:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
device_printf(sc->fc.dev, "AR DMA status=%x, ",
|
|
|
|
OREAD(sc, OHCI_DMACTL(off)));
|
|
|
|
dbch->pdb_tr = NULL;
|
|
|
|
/* skip until resCount != 0 */
|
|
|
|
printf(" skip buffer");
|
|
|
|
while (resCount == 0) {
|
|
|
|
printf(" #");
|
|
|
|
fwohci_arcv_free_buf(sc, dbch, db_tr, off, 0);
|
|
|
|
db_tr = STAILQ_NEXT(db_tr, link);
|
|
|
|
resCount = FWOHCI_DMA_READ(db_tr->db[0].db.desc.res)
|
|
|
|
& OHCI_COUNT_MASK;
|
2009-02-13 17:44:07 +00:00
|
|
|
}
|
2007-04-30 14:06:30 +00:00
|
|
|
printf(" done\n");
|
|
|
|
dbch->top = db_tr;
|
|
|
|
dbch->buf_offset = dbch->xferq.psize - resCount;
|
|
|
|
OWRITE(sc, OHCI_DMACTL(off), OHCI_CNTL_DMA_WAKE);
|
|
|
|
splx(s);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|