\hypertarget{usb__mbuf_8c_source}{}\doxysection{usb\+\_\+mbuf.\+c}
\label{usb__mbuf_8c_source}\index{dev/usb/usb\_mbuf.c@{dev/usb/usb\_mbuf.c}}
\mbox{\hyperlink{usb__mbuf_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00001}00001 \textcolor{comment}{/* \$FreeBSD\$ */}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00002}00002 \textcolor{comment}{/*-\/}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00003}00003 \textcolor{comment}{ * SPDX-\/License-\/Identifier: BSD-\/2-\/Clause-\/FreeBSD}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00004}00004 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00005}00005 \textcolor{comment}{ * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00006}00006 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00007}00007 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00008}00008 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00009}00009 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00010}00010 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00011}00011 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00012}00012 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00013}00013 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00014}00014 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00015}00015 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00016}00016 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00017}00017 \textcolor{comment}{ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00018}00018 \textcolor{comment}{ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00019}00019 \textcolor{comment}{ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00020}00020 \textcolor{comment}{ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00021}00021 \textcolor{comment}{ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00022}00022 \textcolor{comment}{ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00023}00023 \textcolor{comment}{ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00024}00024 \textcolor{comment}{ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00025}00025 \textcolor{comment}{ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00026}00026 \textcolor{comment}{ * SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00027}00027 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00028}00028 }
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00029}00029 \textcolor{preprocessor}{\#ifdef USB\_GLOBAL\_INCLUDE\_FILE}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00030}00030 \textcolor{preprocessor}{\#include USB\_GLOBAL\_INCLUDE\_FILE}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00031}00031 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00032}00032 \textcolor{preprocessor}{\#include <sys/stdint.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00033}00033 \textcolor{preprocessor}{\#include <sys/stddef.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00034}00034 \textcolor{preprocessor}{\#include <sys/param.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00035}00035 \textcolor{preprocessor}{\#include <sys/queue.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00036}00036 \textcolor{preprocessor}{\#include <sys/types.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00037}00037 \textcolor{preprocessor}{\#include <sys/systm.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00038}00038 \textcolor{preprocessor}{\#include <sys/kernel.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00039}00039 \textcolor{preprocessor}{\#include <sys/bus.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00040}00040 \textcolor{preprocessor}{\#include <sys/module.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00041}00041 \textcolor{preprocessor}{\#include <sys/lock.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00042}00042 \textcolor{preprocessor}{\#include <sys/mutex.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00043}00043 \textcolor{preprocessor}{\#include <sys/condvar.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00044}00044 \textcolor{preprocessor}{\#include <sys/sysctl.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00045}00045 \textcolor{preprocessor}{\#include <sys/sx.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00046}00046 \textcolor{preprocessor}{\#include <sys/unistd.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00047}00047 \textcolor{preprocessor}{\#include <sys/callout.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00048}00048 \textcolor{preprocessor}{\#include <sys/malloc.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00049}00049 \textcolor{preprocessor}{\#include <sys/priv.h>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00050}00050 }
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00051}00051 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{usb_8h}{dev/usb/usb.h}}>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00052}00052 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{usbdi_8h}{dev/usb/usbdi.h}}>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00053}00053 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{usb__dev_8h}{dev/usb/usb\_dev.h}}>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00054}00054 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{usb__mbuf_8h}{dev/usb/usb\_mbuf.h}}>}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00055}00055 \textcolor{preprocessor}{\#endif                  }\textcolor{comment}{/* USB\_GLOBAL\_INCLUDE\_FILE */}\textcolor{preprocessor}{}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00056}00056 }
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00057}00057 \textcolor{comment}{/*-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/*}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00058}00058 \textcolor{comment}{ *      usb\_alloc\_mbufs -\/ allocate mbufs to an usbd interface queue}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00059}00059 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00060}00060 \textcolor{comment}{ * Returns:}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00061}00061 \textcolor{comment}{ *   A pointer that should be passed to "{}free()"{} when the buffer(s)}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00062}00062 \textcolor{comment}{ *   should be released.}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00063}00063 \textcolor{comment}{ *-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/*/}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00064}00064 \textcolor{keywordtype}{void}   *}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00065}\mbox{\hyperlink{usb__mbuf_8c_a956d7e2ac8bfec14073b3ffdceae89ec}{00065}} \mbox{\hyperlink{usb__mbuf_8c_a956d7e2ac8bfec14073b3ffdceae89ec}{usb\_alloc\_mbufs}}(\textcolor{keyword}{struct} malloc\_type *type, \textcolor{keyword}{struct} \mbox{\hyperlink{structusb__ifqueue}{usb\_ifqueue}} *ifq,}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00066}00066     \mbox{\hyperlink{usb__freebsd_8h_aef76bd5158b84c44681a07bc5f22aff1}{usb\_size\_t}} block\_size, uint16\_t nblocks)}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00067}00067 \{}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00068}00068         \textcolor{keyword}{struct }\mbox{\hyperlink{structusb__mbuf}{usb\_mbuf}} *m\_ptr;}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00069}00069         uint8\_t *data\_ptr;}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00070}00070         \textcolor{keywordtype}{void} *free\_ptr = NULL;}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00071}00071         \mbox{\hyperlink{usb__freebsd_8h_aef76bd5158b84c44681a07bc5f22aff1}{usb\_size\_t}} alloc\_size;}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00072}00072 }
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00073}00073         \textcolor{comment}{/* align data */}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00074}00074         block\_size += ((-\/block\_size) \& (\mbox{\hyperlink{usb__freebsd_8h_a0d41cb59a7c8f7a0d52857d77d54f392}{USB\_HOST\_ALIGN}} -\/ 1));}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00075}00075 }
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00076}00076         \textcolor{keywordflow}{if} (nblocks \&\& block\_size) \{}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00077}00077                 alloc\_size = (block\_size + \textcolor{keyword}{sizeof}(\textcolor{keyword}{struct }\mbox{\hyperlink{structusb__mbuf}{usb\_mbuf}})) * nblocks;}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00078}00078 }
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00079}00079                 free\_ptr = malloc(alloc\_size, type, M\_WAITOK | M\_ZERO);}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00080}00080                 m\_ptr = free\_ptr;}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00081}00081                 data\_ptr = (\textcolor{keywordtype}{void} *)(m\_ptr + nblocks);}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00082}00082 }
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00083}00083                 \textcolor{keywordflow}{while} (nblocks-\/-\/) \{}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00084}00084                         m\_ptr-\/>\mbox{\hyperlink{structusb__mbuf_a266a505a5ba6191e526bbba0da412836}{cur\_data\_ptr}} =}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00085}00085                             m\_ptr-\/>\mbox{\hyperlink{structusb__mbuf_a2982f0f907e29bba9c80dc3e0bb1d7df}{min\_data\_ptr}} = data\_ptr;}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00086}00086 }
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00087}00087                         m\_ptr-\/>\mbox{\hyperlink{structusb__mbuf_af413f80b0ab6d0d2cd9d97f21237fb3e}{cur\_data\_len}} =}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00088}00088                             m\_ptr-\/>\mbox{\hyperlink{structusb__mbuf_af2184ebabf2803f6ae5f9aadafbbf833}{max\_data\_len}} = block\_size;}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00089}00089 }
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00090}00090                         \mbox{\hyperlink{usb__mbuf_8h_a687851a62f15d69c340d6d93268c6686}{USB\_IF\_ENQUEUE}}(ifq, m\_ptr);}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00091}00091 }
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00092}00092                         m\_ptr++;}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00093}00093                         data\_ptr += block\_size;}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00094}00094                 \}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00095}00095         \}}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00096}00096         \textcolor{keywordflow}{return} (free\_ptr);}
\DoxyCodeLine{\Hypertarget{usb__mbuf_8c_source_l00097}00097 \}}

\end{DoxyCode}
