usb_mbuf.h revision 184610
1/* $FreeBSD: head/sys/dev/usb2/core/usb2_mbuf.h 184610 2008-11-04 02:31:03Z alfred $ */ 2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#ifndef _USB2_MBUF_H_ 28#define _USB2_MBUF_H_ 29 30/* 31 * The following structure defines a minimum re-implementation of the 32 * mbuf system in the kernel. 33 */ 34struct usb2_mbuf { 35 uint8_t *cur_data_ptr; 36 uint8_t *min_data_ptr; 37 struct usb2_mbuf *usb2_nextpkt; 38 struct usb2_mbuf *usb2_next; 39 40 uint32_t cur_data_len; 41 uint32_t max_data_len:31; 42 uint32_t last_packet:1; 43}; 44 45/* 46 * The following structure defines a minimum re-implementation of the 47 * ifqueue structure in the kernel. 48 */ 49struct usb2_ifqueue { 50 struct usb2_mbuf *ifq_head; 51 struct usb2_mbuf *ifq_tail; 52 53 uint32_t ifq_len; 54 uint32_t ifq_maxlen; 55}; 56 57#define USB_IF_ENQUEUE(ifq, m) do { \ 58 (m)->usb2_nextpkt = NULL; \ 59 if ((ifq)->ifq_tail == NULL) \ 60 (ifq)->ifq_head = (m); \ 61 else \ 62 (ifq)->ifq_tail->usb2_nextpkt = (m); \ 63 (ifq)->ifq_tail = (m); \ 64 (ifq)->ifq_len++; \ 65 } while (0) 66 67#define USB_IF_DEQUEUE(ifq, m) do { \ 68 (m) = (ifq)->ifq_head; \ 69 if (m) { \ 70 if (((ifq)->ifq_head = (m)->usb2_nextpkt) == NULL) { \ 71 (ifq)->ifq_tail = NULL; \ 72 } \ 73 (m)->usb2_nextpkt = NULL; \ 74 (ifq)->ifq_len--; \ 75 } \ 76 } while (0) 77 78#define USB_IF_PREPEND(ifq, m) do { \ 79 (m)->usb2_nextpkt = (ifq)->ifq_head; \ 80 if ((ifq)->ifq_tail == NULL) { \ 81 (ifq)->ifq_tail = (m); \ 82 } \ 83 (ifq)->ifq_head = (m); \ 84 (ifq)->ifq_len++; \ 85 } while (0) 86 87#define USB_IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 88#define USB_IF_QLEN(ifq) ((ifq)->ifq_len) 89#define USB_IF_POLL(ifq, m) ((m) = (ifq)->ifq_head) 90 91#define USB_MBUF_RESET(m) do { \ 92 (m)->cur_data_ptr = (m)->min_data_ptr; \ 93 (m)->cur_data_len = (m)->max_data_len; \ 94 (m)->last_packet = 0; \ 95 } while (0) 96 97/* prototypes */ 98void *usb2_alloc_mbufs(struct malloc_type *type, struct usb2_ifqueue *ifq, uint32_t block_size, uint16_t nblocks); 99 100#endif /* _USB2_MBUF_H_ */ 101