freebsd-nq/sys/dev/usb/usb_transfer.h
Andrew Thompson 4eae601ebd MFp4 //depot/projects/usb@159909
- make usb2_power_mask_t 16-bit
- remove "usb2_config_sub" structure from "usb2_config". To compensate for this
  "usb2_config" has a new field called "usb_mode" which select for which mode
  the current xfer entry is active. Options are: a) Device mode only b) Host
  mode only (default-by-zero) c) Both modes.  This change was scripted using
  the following sed script: "s/\.mh\././g".
- the standard packet size table in "usb_transfer.c" is now a function, hence
  the code for the function uses less memory than the table itself.

Submitted by:	Hans Petter Selasky
2009-04-05 18:20:38 +00:00

139 lines
5.0 KiB
C

/* $FreeBSD$ */
/*-
* Copyright (c) 2008 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 _USB2_TRANSFER_H_
#define _USB2_TRANSFER_H_
/*
* The following structure defines the messages that is used to signal
* the "done_p" USB process.
*/
struct usb2_done_msg {
struct usb2_proc_msg hdr;
struct usb2_xfer_root *xroot;
};
#define USB_DMATAG_TO_XROOT(dpt) \
((struct usb2_xfer_root *)( \
((uint8_t *)(dpt)) - \
((uint8_t *)&((struct usb2_xfer_root *)0)->dma_parent_tag)))
/*
* The following structure is used to keep information about memory
* that should be automatically freed at the moment all USB transfers
* have been freed.
*/
struct usb2_xfer_root {
struct usb2_dma_parent_tag dma_parent_tag;
#if USB_HAVE_BUSDMA
struct usb2_xfer_queue dma_q;
#endif
struct usb2_xfer_queue done_q;
struct usb2_done_msg done_m[2];
struct cv cv_drain;
struct usb2_process *done_p; /* pointer to callback process */
void *memory_base;
struct mtx *xfer_mtx; /* cannot be changed during operation */
#if USB_HAVE_BUSDMA
struct usb2_page_cache *dma_page_cache_start;
struct usb2_page_cache *dma_page_cache_end;
#endif
struct usb2_page_cache *xfer_page_cache_start;
struct usb2_page_cache *xfer_page_cache_end;
struct usb2_bus *bus; /* pointer to USB bus (cached) */
struct usb2_device *udev; /* pointer to USB device */
usb2_size_t memory_size;
usb2_size_t setup_refcount;
#if USB_HAVE_BUSDMA
usb2_frcount_t dma_nframes; /* number of page caches to load */
usb2_frcount_t dma_currframe; /* currect page cache number */
usb2_frlength_t dma_frlength_0; /* length of page cache zero */
uint8_t dma_error; /* set if virtual memory could not be
* loaded */
#endif
uint8_t done_sleep; /* set if done thread is sleeping */
};
/*
* The following structure is used when setting up an array of USB
* transfers.
*/
struct usb2_setup_params {
struct usb2_dma_tag *dma_tag_p;
struct usb2_page *dma_page_ptr;
struct usb2_page_cache *dma_page_cache_ptr; /* these will be
* auto-freed */
struct usb2_page_cache *xfer_page_cache_ptr; /* these will not be
* auto-freed */
struct usb2_device *udev;
struct usb2_xfer *curr_xfer;
const struct usb2_config *curr_setup;
const struct usb2_pipe_methods *methods;
void *buf;
usb2_frlength_t *xfer_length_ptr;
usb2_size_t size[7];
usb2_frlength_t bufsize;
usb2_frlength_t bufsize_max;
uint16_t hc_max_frame_size;
uint16_t hc_max_packet_size;
uint8_t hc_max_packet_count;
uint8_t speed;
uint8_t dma_tag_max;
usb2_error_t err;
};
/* function prototypes */
uint8_t usb2_transfer_setup_sub_malloc(struct usb2_setup_params *parm,
struct usb2_page_cache **ppc, usb2_size_t size, usb2_size_t align,
usb2_size_t count);
void usb2_command_wrapper(struct usb2_xfer_queue *pq,
struct usb2_xfer *xfer);
void usb2_pipe_enter(struct usb2_xfer *xfer);
void usb2_pipe_start(struct usb2_xfer_queue *pq);
void usb2_transfer_dequeue(struct usb2_xfer *xfer);
void usb2_transfer_done(struct usb2_xfer *xfer, usb2_error_t error);
void usb2_transfer_enqueue(struct usb2_xfer_queue *pq,
struct usb2_xfer *xfer);
void usb2_transfer_setup_sub(struct usb2_setup_params *parm);
void usb2_default_transfer_setup(struct usb2_device *udev);
void usb2_clear_data_toggle(struct usb2_device *udev,
struct usb2_pipe *pipe);
void usb2_do_poll(struct usb2_xfer **ppxfer, uint16_t max);
usb2_callback_t usb2_do_request_callback;
usb2_callback_t usb2_handle_request_callback;
usb2_callback_t usb2_do_clear_stall_callback;
void usb2_transfer_timeout_ms(struct usb2_xfer *xfer,
void (*cb) (void *arg), usb2_timeout_t ms);
usb2_timeout_t usb2_get_dma_delay(struct usb2_bus *bus);
void usb2_transfer_power_ref(struct usb2_xfer *xfer, int val);
#endif /* _USB2_TRANSFER_H_ */