iobpad.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020 
00021 /**
00022  * @file
00023  *
00024  * I/O buffer padding
00025  *
00026  */
00027 
00028 #include <string.h>
00029 #include <gpxe/iobuf.h>
00030 
00031 /**
00032  * Pad I/O buffer
00033  *
00034  * @v iobuf             I/O buffer
00035  * @v min_len           Minimum length
00036  *
00037  * This function pads and aligns I/O buffers, for devices that
00038  * aren't capable of padding in hardware, or that require specific
00039  * alignment in TX buffers.  The packet data will end up aligned to a
00040  * multiple of @c IOB_ALIGN.
00041  *
00042  * @c min_len must not exceed @v IOB_ZLEN.
00043  */
00044 void iob_pad ( struct io_buffer *iobuf, size_t min_len ) {
00045         void *data;
00046         size_t len;
00047         size_t headroom;
00048         signed int pad_len;
00049 
00050         assert ( min_len <= IOB_ZLEN );
00051 
00052         /* Move packet data to start of I/O buffer.  This will both
00053          * align the data (since I/O buffers are aligned to
00054          * IOB_ALIGN) and give us sufficient space for the
00055          * zero-padding
00056          */
00057         data = iobuf->data;
00058         len = iob_len ( iobuf );
00059         headroom = iob_headroom ( iobuf );
00060         iob_push ( iobuf, headroom );
00061         memmove ( iobuf->data, data, len );
00062         iob_unput ( iobuf, headroom );
00063 
00064         /* Pad to minimum packet length */
00065         pad_len = ( min_len - iob_len ( iobuf ) );
00066         if ( pad_len > 0 )
00067                 memset ( iob_put ( iobuf, pad_len ), 0, pad_len );
00068 }

Generated on Tue Apr 6 20:01:10 2010 for gPXE by  doxygen 1.5.7.1