From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Chou Date: Fri, 6 Nov 2015 12:52:39 +0800 Subject: [U-Boot] [PATCH] nios2: nios2-generic: do not allocate rx buf in net.c In-Reply-To: <201511060240.03312.marex@denx.de> References: <1446712963-32179-1-git-send-email-thomas@wytron.com.tw> <201511051716.11450.marex@denx.de> <563BEA81.4070305@wytron.com.tw> <201511060240.03312.marex@denx.de> Message-ID: <563C3217.7070400@wytron.com.tw> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Marek, On 2015?11?06? 09:40, Marek Vasut wrote: > On Friday, November 06, 2015 at 12:47:13 AM, Thomas Chou wrote: >> Hi Marek, > > Hi! > >> On 2015?11?06? 00:16, Marek Vasut wrote: >>> On Thursday, November 05, 2015 at 09:42:43 AM, Thomas Chou wrote: >>>> Do not allocate rx buf in net.c, because altera_tse allocates >>>> its own rx buf in driver. This can save 6KB memory. >>>> >>>> Signed-off-by: Thomas Chou >>> >>> Shouldn't we instead fix the altera driver to use the pre-allocated >>> buffer ? >> >> It should not. The drivers and devices are dynamically binding in driver >> model. The buffers used by devices should be allocated per device. Eg, >> there may be multiple ethernet devices and they should not use the same >> pre-allocated rx bufs. > > Oh ok, I see your point now. But then, this allocation of buffers in the > ethernet drivers becomes a boilerplate code, right ? So maybe there should > be some mechanism in the network stack to allocate the buffers for the drivers > to prevent duplication of code. The pre-alloacted tx_buf is still in use by net/ . But most ethernet drivers allocate their own rx_buf (perhaps as ring buffer). Most of them use memalign(PKTSIZE_ALIGN), which is the same as malloc_cache_aligned(PKTSIZE_ALIGN). Each driver may have different requirement of size/number of the rx buf. The driver passes the rx buf to net/ . And the net/ return the rx buf with free_pkt() to the driver after use. I think this scheme works fine. There not much duplication of code for rx_buf allocation, which might be only a malloc_cache_aligned(). Best regards, Thomas