/* $FreeBSD$ */ /*- * Copyright (c) 2010,2011 Aleksandr Rybalko. All rights reserved. * Copyright (c) 2010 Hans Petter Selasky. 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. */ #ifndef _DOTG_H_ #define _DOTG_H_ #define DOTG_MAX_DEVICES MIN(USB_MAX_DEVICES, 64) /* * The second port is on a different IRQ and so we disable it for now. */ #if 1 #define DOTG_MAX_PORTS 1 /* hardcoded */ #else #define DOTG_MAX_PORTS 2 /* hardcoded */ #endif #if 1 //#define DOTG_MAX_FIXUP 0x2000 /* bytes */ #define DOTG_MAX_FIXUP 0x1000 /* bytes */ //#define DOTG_MAX_FIXUP 4096 /* bytes */ #else #define DOTG_MAX_FIXUP 2048 /* bytes */ #endif #define DOTG_INTR_ENDPT 0x01 #define MAX_RETRIES 3 #define MAX_PIPES 32 #define MAX_TRANSACTIONS 256 #define MAX_CHANNELS 4 #define MAX_USB_ADDRESS 127 #define MAX_USB_ENDPOINT 15 #define MAX_USB_HUB_PORT 15 typedef enum { DOTG_COMPLETE_SUCCESS, DOTG_COMPLETE_SHORT, DOTG_COMPLETE_CANCEL, DOTG_COMPLETE_ERROR, DOTG_COMPLETE_STALL, DOTG_COMPLETE_XACTERR, DOTG_COMPLETE_DATATGLERR, DOTG_COMPLETE_BABBLEERR, DOTG_COMPLETE_FRAMEERR, } dotg_complete_t; typedef enum { __DOTG_FLAGS_NEED_PING = 1 << 0, __DOTG_FLAGS_DONE_PING = 1 << 1, } dotg_flags_t; enum fixup_state { FIXUP_NONE = 0, FIXUP_ALOC, FIXUP_PEND, FIXUP_NAK, FIXUP_CMPL }; struct dotg_qh; struct dotg_td; struct dotg_softc; typedef uint8_t (dotg_cmd_t)(struct dotg_td *td); struct dotg_td { struct dotg_qh *qh; struct dotg_td *obj_next; struct usb_page_cache *pc; dotg_cmd_t *func; uint8_t error_any:1; uint8_t error_stall:1; uint8_t short_pkt:1; uint8_t alt_next:1; uint8_t reserved:4; int8_t channel; uint16_t offset; uint32_t remainder; }; struct dotg_qh { struct dotg_softc *sc; struct usb_page_cache *fixup_pc; uint8_t *fixup_buf; uint16_t max_frame_size; uint16_t max_packet_size; uint16_t fixup_len; uint16_t fixup_actlen; uint16_t fixup_off; uint16_t this_xfersize; uint16_t ep_interval; uint8_t dev_addr; uint8_t dev_speed; uint8_t ep_mult; uint8_t ep_num; uint8_t ep_type; uint8_t ep_toggle_next:1; uint8_t fixup_state:3; uint8_t port_index:3;//30 uint8_t hs_hub_port; //31 uint8_t hs_hub_addr; //32 /* We don`t know system address width */ vm_paddr_t fixup_phys; int8_t split_sc_frame; uint64_t next_tx_cycle; uint32_t flags; int retries; }; struct dotg_config_desc { struct usb_config_descriptor confd; struct usb_interface_descriptor ifcd; struct usb_endpoint_descriptor endpd; } __packed; union dotg_hub_desc { struct usb_status stat; struct usb_port_status ps; uint8_t temp[128]; }; struct dotg_softc { struct usb_bus sc_bus; /* base device */ union dotg_hub_desc sc_hub_desc; struct usb_device *sc_devices[DOTG_MAX_DEVICES]; int sc_mem_rid; struct resource *sc_mem_res; int sc_irq_rid; struct resource *sc_irq_res; void *sc_intr_hdl; bus_space_handle_t sc_bsh; /* bus space handle */ bus_space_tag_t sc_bst; /* bus space tag */ /* Next two used on Octeons */ bus_space_handle_t sc_iobsh; /* bus space handle for 64b pointers*/ bus_space_tag_t sc_iobst; /* bus space tag for 64b pointers */ device_t sc_dev; struct usb_hub_descriptor_min sc_hubd; uint8_t sc_addr; /* device address */ uint8_t sc_conf; /* device configuration */ uint8_t sc_isreset; /* set if current port * is reset */ uint8_t sc_ischange; /* port change status */ uint8_t sc_hub_idata[1]; uint8_t sc_mode_device; int init_flags; int index; int channels; int idle_hardware_channels; int active_transactions; uint32_t dotg_hprt; struct dotg_td *td_for_channel[MAX_CHANNELS]; struct dotg_ports *port_status; uint32_t tx_packets; uint32_t tx_packets_ack; struct mtx q_mtx; }; #define GETFLD(data, fld) (((data) & fld ## _MASK) >> fld ## _SHIFT) #define SETFLD(data, fld) (((data) << fld ## _SHIFT) & fld ## _MASK) #define SETFIELD32(sc, address, field, value) \ WRITE4(sc, (address), (READ4(sc, (address)) & ~field) | \ ((value)?(field):0)) #define SETFIELD32_(sc, address, field, value) \ WRITE4(sc, (address), (READ4(sc, (address)) & ~field ## _MASK) |\ ((value)<< field ## _SHIFT) ) /* This macro spins on a field waiting for it to reach a value */ #define WAIT_FOR_FIELD32(sc, address, field, value, timeout_usec)\ ({int result; \ do { \ uint32_t c, timeout = timeout_usec; \ while (1) \ { \ c = (READ4(sc, address) & field)?1:0; \ if (c == (value)) { \ result = 0; \ break; \ } else if (!timeout) { \ result = -1; \ break; \ } else { \ DELAY(1); timeout--; \ } \ } \ } while (0); \ result;}) int dotg_get_num_ports(void); int dotg_enable(struct dotg_softc *); int dotg_disable(struct dotg_softc *); usb_bus_mem_cb_t dotg_iterate_hw_softc; usb_error_t dotg_init(struct dotg_softc *); usb_error_t dotg_uninit(struct dotg_softc *); void dotg_suspend(struct dotg_softc *); void dotg_resume(struct dotg_softc *); int dotg_interrupt(void *); #endif /* _DOTG_H_ */