1184610Salfred/* $FreeBSD: releng/10.2/sys/dev/usb/usb_mbuf.h 196219 2009-08-14 20:03:53Z jhb $ */ 2184610Salfred/*- 3184610Salfred * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4184610Salfred * 5184610Salfred * Redistribution and use in source and binary forms, with or without 6184610Salfred * modification, are permitted provided that the following conditions 7184610Salfred * are met: 8184610Salfred * 1. Redistributions of source code must retain the above copyright 9184610Salfred * notice, this list of conditions and the following disclaimer. 10184610Salfred * 2. Redistributions in binary form must reproduce the above copyright 11184610Salfred * notice, this list of conditions and the following disclaimer in the 12184610Salfred * documentation and/or other materials provided with the distribution. 13184610Salfred * 14184610Salfred * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15184610Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16184610Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17184610Salfred * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18184610Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19184610Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20184610Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21184610Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22184610Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23184610Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24184610Salfred * SUCH DAMAGE. 25184610Salfred */ 26184610Salfred 27194230Sthompsa#ifndef _USB_MBUF_H_ 28194230Sthompsa#define _USB_MBUF_H_ 29184610Salfred 30184610Salfred/* 31184610Salfred * The following structure defines a minimum re-implementation of the 32184610Salfred * mbuf system in the kernel. 33184610Salfred */ 34192984Sthompsastruct usb_mbuf { 35184610Salfred uint8_t *cur_data_ptr; 36184610Salfred uint8_t *min_data_ptr; 37194228Sthompsa struct usb_mbuf *usb_nextpkt; 38194228Sthompsa struct usb_mbuf *usb_next; 39184610Salfred 40193074Sthompsa usb_size_t cur_data_len; 41193074Sthompsa usb_size_t max_data_len; 42187183Sthompsa uint8_t last_packet:1; 43187183Sthompsa uint8_t unused:7; 44184610Salfred}; 45184610Salfred 46184610Salfred#define USB_IF_ENQUEUE(ifq, m) do { \ 47194228Sthompsa (m)->usb_nextpkt = NULL; \ 48184610Salfred if ((ifq)->ifq_tail == NULL) \ 49184610Salfred (ifq)->ifq_head = (m); \ 50184610Salfred else \ 51194228Sthompsa (ifq)->ifq_tail->usb_nextpkt = (m); \ 52184610Salfred (ifq)->ifq_tail = (m); \ 53184610Salfred (ifq)->ifq_len++; \ 54184610Salfred } while (0) 55184610Salfred 56184610Salfred#define USB_IF_DEQUEUE(ifq, m) do { \ 57184610Salfred (m) = (ifq)->ifq_head; \ 58184610Salfred if (m) { \ 59194228Sthompsa if (((ifq)->ifq_head = (m)->usb_nextpkt) == NULL) { \ 60184610Salfred (ifq)->ifq_tail = NULL; \ 61184610Salfred } \ 62194228Sthompsa (m)->usb_nextpkt = NULL; \ 63184610Salfred (ifq)->ifq_len--; \ 64184610Salfred } \ 65184610Salfred } while (0) 66184610Salfred 67184610Salfred#define USB_IF_PREPEND(ifq, m) do { \ 68194228Sthompsa (m)->usb_nextpkt = (ifq)->ifq_head; \ 69184610Salfred if ((ifq)->ifq_tail == NULL) { \ 70184610Salfred (ifq)->ifq_tail = (m); \ 71184610Salfred } \ 72184610Salfred (ifq)->ifq_head = (m); \ 73184610Salfred (ifq)->ifq_len++; \ 74184610Salfred } while (0) 75184610Salfred 76184610Salfred#define USB_IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 77184610Salfred#define USB_IF_QLEN(ifq) ((ifq)->ifq_len) 78184610Salfred#define USB_IF_POLL(ifq, m) ((m) = (ifq)->ifq_head) 79184610Salfred 80184610Salfred#define USB_MBUF_RESET(m) do { \ 81184610Salfred (m)->cur_data_ptr = (m)->min_data_ptr; \ 82184610Salfred (m)->cur_data_len = (m)->max_data_len; \ 83184610Salfred (m)->last_packet = 0; \ 84184610Salfred } while (0) 85184610Salfred 86184610Salfred/* prototypes */ 87194228Sthompsavoid *usb_alloc_mbufs(struct malloc_type *type, struct usb_ifqueue *ifq, 88193074Sthompsa usb_size_t block_size, uint16_t nblocks); 89184610Salfred 90194230Sthompsa#endif /* _USB_MBUF_H_ */ 91