usb_mbuf.h revision 187183
139220Sgibbs/* $FreeBSD: head/sys/dev/usb2/core/usb2_mbuf.h 187183 2009-01-13 19:05:51Z thompsa $ */ 239220Sgibbs/*- 339220Sgibbs * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 439220Sgibbs * 539220Sgibbs * Redistribution and use in source and binary forms, with or without 639220Sgibbs * modification, are permitted provided that the following conditions 739220Sgibbs * are met: 839220Sgibbs * 1. Redistributions of source code must retain the above copyright 939220Sgibbs * notice, this list of conditions and the following disclaimer. 1039220Sgibbs * 2. Redistributions in binary form must reproduce the above copyright 1139220Sgibbs * notice, this list of conditions and the following disclaimer in the 1239220Sgibbs * documentation and/or other materials provided with the distribution. 1339220Sgibbs * 1439220Sgibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1539220Sgibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1639220Sgibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1739220Sgibbs * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1839220Sgibbs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1939220Sgibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2039220Sgibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2147507Sgibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2239220Sgibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2339220Sgibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2439220Sgibbs * SUCH DAMAGE. 2539220Sgibbs */ 2639220Sgibbs 2739220Sgibbs#ifndef _USB2_MBUF_H_ 2839220Sgibbs#define _USB2_MBUF_H_ 2939220Sgibbs 3039220Sgibbs/* 3139220Sgibbs * The following structure defines a minimum re-implementation of the 3239220Sgibbs * mbuf system in the kernel. 3339220Sgibbs */ 3439220Sgibbsstruct usb2_mbuf { 3539220Sgibbs uint8_t *cur_data_ptr; 3639220Sgibbs uint8_t *min_data_ptr; 3739220Sgibbs struct usb2_mbuf *usb2_nextpkt; 3839220Sgibbs struct usb2_mbuf *usb2_next; 3939220Sgibbs 4039220Sgibbs uint32_t cur_data_len; 4139220Sgibbs uint32_t max_data_len; 4239220Sgibbs uint8_t last_packet:1; 4339220Sgibbs uint8_t unused:7; 4439220Sgibbs}; 4539220Sgibbs 4639220Sgibbs/* 4739220Sgibbs * The following structure defines a minimum re-implementation of the 4839220Sgibbs * ifqueue structure in the kernel. 4939220Sgibbs */ 5039220Sgibbsstruct usb2_ifqueue { 5139220Sgibbs struct usb2_mbuf *ifq_head; 5239220Sgibbs struct usb2_mbuf *ifq_tail; 5339220Sgibbs 5439220Sgibbs uint32_t ifq_len; 5539220Sgibbs uint32_t ifq_maxlen; 5639220Sgibbs}; 5739220Sgibbs 5847507Sgibbs#define USB_IF_ENQUEUE(ifq, m) do { \ 5947507Sgibbs (m)->usb2_nextpkt = NULL; \ 6039220Sgibbs if ((ifq)->ifq_tail == NULL) \ 6139220Sgibbs (ifq)->ifq_head = (m); \ 6239220Sgibbs else \ 6339220Sgibbs (ifq)->ifq_tail->usb2_nextpkt = (m); \ 6439220Sgibbs (ifq)->ifq_tail = (m); \ 6539220Sgibbs (ifq)->ifq_len++; \ 6639220Sgibbs } while (0) 6739220Sgibbs 6839220Sgibbs#define USB_IF_DEQUEUE(ifq, m) do { \ 6939220Sgibbs (m) = (ifq)->ifq_head; \ 7039220Sgibbs if (m) { \ 7139220Sgibbs if (((ifq)->ifq_head = (m)->usb2_nextpkt) == NULL) { \ 7239220Sgibbs (ifq)->ifq_tail = NULL; \ 7339220Sgibbs } \ 7439220Sgibbs (m)->usb2_nextpkt = NULL; \ 7539220Sgibbs (ifq)->ifq_len--; \ 7639220Sgibbs } \ 7739220Sgibbs } while (0) 7839220Sgibbs 7939220Sgibbs#define USB_IF_PREPEND(ifq, m) do { \ 8039220Sgibbs (m)->usb2_nextpkt = (ifq)->ifq_head; \ 8139220Sgibbs if ((ifq)->ifq_tail == NULL) { \ 8239220Sgibbs (ifq)->ifq_tail = (m); \ 8339220Sgibbs } \ 8439220Sgibbs (ifq)->ifq_head = (m); \ 8539220Sgibbs (ifq)->ifq_len++; \ 8639220Sgibbs } while (0) 8739220Sgibbs 8839220Sgibbs#define USB_IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 8939220Sgibbs#define USB_IF_QLEN(ifq) ((ifq)->ifq_len) 9039220Sgibbs#define USB_IF_POLL(ifq, m) ((m) = (ifq)->ifq_head) 9139220Sgibbs 9239220Sgibbs#define USB_MBUF_RESET(m) do { \ 9339220Sgibbs (m)->cur_data_ptr = (m)->min_data_ptr; \ 9439220Sgibbs (m)->cur_data_len = (m)->max_data_len; \ 9539220Sgibbs (m)->last_packet = 0; \ 9639220Sgibbs } while (0) 9739220Sgibbs 9839220Sgibbs/* prototypes */ 9939220Sgibbsvoid *usb2_alloc_mbufs(struct malloc_type *type, struct usb2_ifqueue *ifq, 10039220Sgibbs uint32_t block_size, uint16_t nblocks); 10139220Sgibbs 10239220Sgibbs#endif /* _USB2_MBUF_H_ */ 10339220Sgibbs