1c5aa9e3bSLendacky, Thomas /* 2c5aa9e3bSLendacky, Thomas * AMD 10Gb Ethernet driver 3c5aa9e3bSLendacky, Thomas * 4c5aa9e3bSLendacky, Thomas * This file is available to you under your choice of the following two 5c5aa9e3bSLendacky, Thomas * licenses: 6c5aa9e3bSLendacky, Thomas * 7c5aa9e3bSLendacky, Thomas * License 1: GPLv2 8c5aa9e3bSLendacky, Thomas * 9c5aa9e3bSLendacky, Thomas * Copyright (c) 2014 Advanced Micro Devices, Inc. 10c5aa9e3bSLendacky, Thomas * 11c5aa9e3bSLendacky, Thomas * This file is free software; you may copy, redistribute and/or modify 12c5aa9e3bSLendacky, Thomas * it under the terms of the GNU General Public License as published by 13c5aa9e3bSLendacky, Thomas * the Free Software Foundation, either version 2 of the License, or (at 14c5aa9e3bSLendacky, Thomas * your option) any later version. 15c5aa9e3bSLendacky, Thomas * 16c5aa9e3bSLendacky, Thomas * This file is distributed in the hope that it will be useful, but 17c5aa9e3bSLendacky, Thomas * WITHOUT ANY WARRANTY; without even the implied warranty of 18c5aa9e3bSLendacky, Thomas * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19c5aa9e3bSLendacky, Thomas * General Public License for more details. 20c5aa9e3bSLendacky, Thomas * 21c5aa9e3bSLendacky, Thomas * You should have received a copy of the GNU General Public License 22c5aa9e3bSLendacky, Thomas * along with this program. If not, see <http://www.gnu.org/licenses/>. 23c5aa9e3bSLendacky, Thomas * 24c5aa9e3bSLendacky, Thomas * This file incorporates work covered by the following copyright and 25c5aa9e3bSLendacky, Thomas * permission notice: 26c5aa9e3bSLendacky, Thomas * The Synopsys DWC ETHER XGMAC Software Driver and documentation 27c5aa9e3bSLendacky, Thomas * (hereinafter "Software") is an unsupported proprietary work of Synopsys, 28c5aa9e3bSLendacky, Thomas * Inc. unless otherwise expressly agreed to in writing between Synopsys 29c5aa9e3bSLendacky, Thomas * and you. 30c5aa9e3bSLendacky, Thomas * 31c5aa9e3bSLendacky, Thomas * The Software IS NOT an item of Licensed Software or Licensed Product 32c5aa9e3bSLendacky, Thomas * under any End User Software License Agreement or Agreement for Licensed 33c5aa9e3bSLendacky, Thomas * Product with Synopsys or any supplement thereto. Permission is hereby 34c5aa9e3bSLendacky, Thomas * granted, free of charge, to any person obtaining a copy of this software 35c5aa9e3bSLendacky, Thomas * annotated with this license and the Software, to deal in the Software 36c5aa9e3bSLendacky, Thomas * without restriction, including without limitation the rights to use, 37c5aa9e3bSLendacky, Thomas * copy, modify, merge, publish, distribute, sublicense, and/or sell copies 38c5aa9e3bSLendacky, Thomas * of the Software, and to permit persons to whom the Software is furnished 39c5aa9e3bSLendacky, Thomas * to do so, subject to the following conditions: 40c5aa9e3bSLendacky, Thomas * 41c5aa9e3bSLendacky, Thomas * The above copyright notice and this permission notice shall be included 42c5aa9e3bSLendacky, Thomas * in all copies or substantial portions of the Software. 43c5aa9e3bSLendacky, Thomas * 44c5aa9e3bSLendacky, Thomas * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" 45c5aa9e3bSLendacky, Thomas * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46c5aa9e3bSLendacky, Thomas * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47c5aa9e3bSLendacky, Thomas * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS 48c5aa9e3bSLendacky, Thomas * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 49c5aa9e3bSLendacky, Thomas * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 50c5aa9e3bSLendacky, Thomas * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 51c5aa9e3bSLendacky, Thomas * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 52c5aa9e3bSLendacky, Thomas * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 53c5aa9e3bSLendacky, Thomas * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 54c5aa9e3bSLendacky, Thomas * THE POSSIBILITY OF SUCH DAMAGE. 55c5aa9e3bSLendacky, Thomas * 56c5aa9e3bSLendacky, Thomas * 57c5aa9e3bSLendacky, Thomas * License 2: Modified BSD 58c5aa9e3bSLendacky, Thomas * 59c5aa9e3bSLendacky, Thomas * Copyright (c) 2014 Advanced Micro Devices, Inc. 60c5aa9e3bSLendacky, Thomas * All rights reserved. 61c5aa9e3bSLendacky, Thomas * 62c5aa9e3bSLendacky, Thomas * Redistribution and use in source and binary forms, with or without 63c5aa9e3bSLendacky, Thomas * modification, are permitted provided that the following conditions are met: 64c5aa9e3bSLendacky, Thomas * * Redistributions of source code must retain the above copyright 65c5aa9e3bSLendacky, Thomas * notice, this list of conditions and the following disclaimer. 66c5aa9e3bSLendacky, Thomas * * Redistributions in binary form must reproduce the above copyright 67c5aa9e3bSLendacky, Thomas * notice, this list of conditions and the following disclaimer in the 68c5aa9e3bSLendacky, Thomas * documentation and/or other materials provided with the distribution. 69c5aa9e3bSLendacky, Thomas * * Neither the name of Advanced Micro Devices, Inc. nor the 70c5aa9e3bSLendacky, Thomas * names of its contributors may be used to endorse or promote products 71c5aa9e3bSLendacky, Thomas * derived from this software without specific prior written permission. 72c5aa9e3bSLendacky, Thomas * 73c5aa9e3bSLendacky, Thomas * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 74c5aa9e3bSLendacky, Thomas * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 75c5aa9e3bSLendacky, Thomas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 76c5aa9e3bSLendacky, Thomas * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 77c5aa9e3bSLendacky, Thomas * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 78c5aa9e3bSLendacky, Thomas * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 79c5aa9e3bSLendacky, Thomas * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 80c5aa9e3bSLendacky, Thomas * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 81c5aa9e3bSLendacky, Thomas * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 82c5aa9e3bSLendacky, Thomas * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 83c5aa9e3bSLendacky, Thomas * 84c5aa9e3bSLendacky, Thomas * This file incorporates work covered by the following copyright and 85c5aa9e3bSLendacky, Thomas * permission notice: 86c5aa9e3bSLendacky, Thomas * The Synopsys DWC ETHER XGMAC Software Driver and documentation 87c5aa9e3bSLendacky, Thomas * (hereinafter "Software") is an unsupported proprietary work of Synopsys, 88c5aa9e3bSLendacky, Thomas * Inc. unless otherwise expressly agreed to in writing between Synopsys 89c5aa9e3bSLendacky, Thomas * and you. 90c5aa9e3bSLendacky, Thomas * 91c5aa9e3bSLendacky, Thomas * The Software IS NOT an item of Licensed Software or Licensed Product 92c5aa9e3bSLendacky, Thomas * under any End User Software License Agreement or Agreement for Licensed 93c5aa9e3bSLendacky, Thomas * Product with Synopsys or any supplement thereto. Permission is hereby 94c5aa9e3bSLendacky, Thomas * granted, free of charge, to any person obtaining a copy of this software 95c5aa9e3bSLendacky, Thomas * annotated with this license and the Software, to deal in the Software 96c5aa9e3bSLendacky, Thomas * without restriction, including without limitation the rights to use, 97c5aa9e3bSLendacky, Thomas * copy, modify, merge, publish, distribute, sublicense, and/or sell copies 98c5aa9e3bSLendacky, Thomas * of the Software, and to permit persons to whom the Software is furnished 99c5aa9e3bSLendacky, Thomas * to do so, subject to the following conditions: 100c5aa9e3bSLendacky, Thomas * 101c5aa9e3bSLendacky, Thomas * The above copyright notice and this permission notice shall be included 102c5aa9e3bSLendacky, Thomas * in all copies or substantial portions of the Software. 103c5aa9e3bSLendacky, Thomas * 104c5aa9e3bSLendacky, Thomas * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" 105c5aa9e3bSLendacky, Thomas * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 106c5aa9e3bSLendacky, Thomas * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 107c5aa9e3bSLendacky, Thomas * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS 108c5aa9e3bSLendacky, Thomas * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 109c5aa9e3bSLendacky, Thomas * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 110c5aa9e3bSLendacky, Thomas * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 111c5aa9e3bSLendacky, Thomas * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 112c5aa9e3bSLendacky, Thomas * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 113c5aa9e3bSLendacky, Thomas * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 114c5aa9e3bSLendacky, Thomas * THE POSSIBILITY OF SUCH DAMAGE. 115c5aa9e3bSLendacky, Thomas */ 116c5aa9e3bSLendacky, Thomas 117c5aa9e3bSLendacky, Thomas #include "xgbe.h" 118c5aa9e3bSLendacky, Thomas #include "xgbe-common.h" 119c5aa9e3bSLendacky, Thomas 12008dcc47cSLendacky, Thomas static void xgbe_unmap_rdata(struct xgbe_prv_data *, struct xgbe_ring_data *); 121c5aa9e3bSLendacky, Thomas 122c5aa9e3bSLendacky, Thomas static void xgbe_free_ring(struct xgbe_prv_data *pdata, 123c5aa9e3bSLendacky, Thomas struct xgbe_ring *ring) 124c5aa9e3bSLendacky, Thomas { 125c5aa9e3bSLendacky, Thomas struct xgbe_ring_data *rdata; 126c5aa9e3bSLendacky, Thomas unsigned int i; 127c5aa9e3bSLendacky, Thomas 128c5aa9e3bSLendacky, Thomas if (!ring) 129c5aa9e3bSLendacky, Thomas return; 130c5aa9e3bSLendacky, Thomas 131c5aa9e3bSLendacky, Thomas if (ring->rdata) { 132c5aa9e3bSLendacky, Thomas for (i = 0; i < ring->rdesc_count; i++) { 133d0a8ba6cSLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, i); 13408dcc47cSLendacky, Thomas xgbe_unmap_rdata(pdata, rdata); 135c5aa9e3bSLendacky, Thomas } 136c5aa9e3bSLendacky, Thomas 137c5aa9e3bSLendacky, Thomas kfree(ring->rdata); 138c5aa9e3bSLendacky, Thomas ring->rdata = NULL; 139c5aa9e3bSLendacky, Thomas } 140c5aa9e3bSLendacky, Thomas 141174fd259SLendacky, Thomas if (ring->rx_hdr_pa.pages) { 142174fd259SLendacky, Thomas dma_unmap_page(pdata->dev, ring->rx_hdr_pa.pages_dma, 143174fd259SLendacky, Thomas ring->rx_hdr_pa.pages_len, DMA_FROM_DEVICE); 144174fd259SLendacky, Thomas put_page(ring->rx_hdr_pa.pages); 14508dcc47cSLendacky, Thomas 146174fd259SLendacky, Thomas ring->rx_hdr_pa.pages = NULL; 147174fd259SLendacky, Thomas ring->rx_hdr_pa.pages_len = 0; 148174fd259SLendacky, Thomas ring->rx_hdr_pa.pages_offset = 0; 149174fd259SLendacky, Thomas ring->rx_hdr_pa.pages_dma = 0; 150174fd259SLendacky, Thomas } 151174fd259SLendacky, Thomas 152174fd259SLendacky, Thomas if (ring->rx_buf_pa.pages) { 153174fd259SLendacky, Thomas dma_unmap_page(pdata->dev, ring->rx_buf_pa.pages_dma, 154174fd259SLendacky, Thomas ring->rx_buf_pa.pages_len, DMA_FROM_DEVICE); 155174fd259SLendacky, Thomas put_page(ring->rx_buf_pa.pages); 156174fd259SLendacky, Thomas 157174fd259SLendacky, Thomas ring->rx_buf_pa.pages = NULL; 158174fd259SLendacky, Thomas ring->rx_buf_pa.pages_len = 0; 159174fd259SLendacky, Thomas ring->rx_buf_pa.pages_offset = 0; 160174fd259SLendacky, Thomas ring->rx_buf_pa.pages_dma = 0; 16108dcc47cSLendacky, Thomas } 16208dcc47cSLendacky, Thomas 163c5aa9e3bSLendacky, Thomas if (ring->rdesc) { 164c5aa9e3bSLendacky, Thomas dma_free_coherent(pdata->dev, 165c5aa9e3bSLendacky, Thomas (sizeof(struct xgbe_ring_desc) * 166c5aa9e3bSLendacky, Thomas ring->rdesc_count), 167c5aa9e3bSLendacky, Thomas ring->rdesc, ring->rdesc_dma); 168c5aa9e3bSLendacky, Thomas ring->rdesc = NULL; 169c5aa9e3bSLendacky, Thomas } 170c5aa9e3bSLendacky, Thomas } 171c5aa9e3bSLendacky, Thomas 172c5aa9e3bSLendacky, Thomas static void xgbe_free_ring_resources(struct xgbe_prv_data *pdata) 173c5aa9e3bSLendacky, Thomas { 174c5aa9e3bSLendacky, Thomas struct xgbe_channel *channel; 175c5aa9e3bSLendacky, Thomas unsigned int i; 176c5aa9e3bSLendacky, Thomas 177c5aa9e3bSLendacky, Thomas DBGPR("-->xgbe_free_ring_resources\n"); 178c5aa9e3bSLendacky, Thomas 179c5aa9e3bSLendacky, Thomas channel = pdata->channel; 180c5aa9e3bSLendacky, Thomas for (i = 0; i < pdata->channel_count; i++, channel++) { 181c5aa9e3bSLendacky, Thomas xgbe_free_ring(pdata, channel->tx_ring); 182c5aa9e3bSLendacky, Thomas xgbe_free_ring(pdata, channel->rx_ring); 183c5aa9e3bSLendacky, Thomas } 184c5aa9e3bSLendacky, Thomas 185c5aa9e3bSLendacky, Thomas DBGPR("<--xgbe_free_ring_resources\n"); 186c5aa9e3bSLendacky, Thomas } 187c5aa9e3bSLendacky, Thomas 188c5aa9e3bSLendacky, Thomas static int xgbe_init_ring(struct xgbe_prv_data *pdata, 189c5aa9e3bSLendacky, Thomas struct xgbe_ring *ring, unsigned int rdesc_count) 190c5aa9e3bSLendacky, Thomas { 191c5aa9e3bSLendacky, Thomas DBGPR("-->xgbe_init_ring\n"); 192c5aa9e3bSLendacky, Thomas 193c5aa9e3bSLendacky, Thomas if (!ring) 194c5aa9e3bSLendacky, Thomas return 0; 195c5aa9e3bSLendacky, Thomas 196c5aa9e3bSLendacky, Thomas /* Descriptors */ 197c5aa9e3bSLendacky, Thomas ring->rdesc_count = rdesc_count; 198c5aa9e3bSLendacky, Thomas ring->rdesc = dma_alloc_coherent(pdata->dev, 199c5aa9e3bSLendacky, Thomas (sizeof(struct xgbe_ring_desc) * 200c5aa9e3bSLendacky, Thomas rdesc_count), &ring->rdesc_dma, 201c5aa9e3bSLendacky, Thomas GFP_KERNEL); 202c5aa9e3bSLendacky, Thomas if (!ring->rdesc) 203c5aa9e3bSLendacky, Thomas return -ENOMEM; 204c5aa9e3bSLendacky, Thomas 205c5aa9e3bSLendacky, Thomas /* Descriptor information */ 206c5aa9e3bSLendacky, Thomas ring->rdata = kcalloc(rdesc_count, sizeof(struct xgbe_ring_data), 207c5aa9e3bSLendacky, Thomas GFP_KERNEL); 208c5aa9e3bSLendacky, Thomas if (!ring->rdata) 209c5aa9e3bSLendacky, Thomas return -ENOMEM; 210c5aa9e3bSLendacky, Thomas 21134bf65dfSLendacky, Thomas netif_dbg(pdata, drv, pdata->netdev, 21234bf65dfSLendacky, Thomas "rdesc=%p, rdesc_dma=%pad, rdata=%p\n", 21334bf65dfSLendacky, Thomas ring->rdesc, &ring->rdesc_dma, ring->rdata); 214c5aa9e3bSLendacky, Thomas 215c5aa9e3bSLendacky, Thomas DBGPR("<--xgbe_init_ring\n"); 216c5aa9e3bSLendacky, Thomas 217c5aa9e3bSLendacky, Thomas return 0; 218c5aa9e3bSLendacky, Thomas } 219c5aa9e3bSLendacky, Thomas 220c5aa9e3bSLendacky, Thomas static int xgbe_alloc_ring_resources(struct xgbe_prv_data *pdata) 221c5aa9e3bSLendacky, Thomas { 222c5aa9e3bSLendacky, Thomas struct xgbe_channel *channel; 223c5aa9e3bSLendacky, Thomas unsigned int i; 224c5aa9e3bSLendacky, Thomas int ret; 225c5aa9e3bSLendacky, Thomas 226c5aa9e3bSLendacky, Thomas DBGPR("-->xgbe_alloc_ring_resources\n"); 227c5aa9e3bSLendacky, Thomas 228c5aa9e3bSLendacky, Thomas channel = pdata->channel; 229c5aa9e3bSLendacky, Thomas for (i = 0; i < pdata->channel_count; i++, channel++) { 23034bf65dfSLendacky, Thomas netif_dbg(pdata, drv, pdata->netdev, "%s - Tx ring:\n", 23134bf65dfSLendacky, Thomas channel->name); 23234bf65dfSLendacky, Thomas 233c5aa9e3bSLendacky, Thomas ret = xgbe_init_ring(pdata, channel->tx_ring, 234c5aa9e3bSLendacky, Thomas pdata->tx_desc_count); 235c5aa9e3bSLendacky, Thomas if (ret) { 236c5aa9e3bSLendacky, Thomas netdev_alert(pdata->netdev, 237c5aa9e3bSLendacky, Thomas "error initializing Tx ring\n"); 238c5aa9e3bSLendacky, Thomas goto err_ring; 239c5aa9e3bSLendacky, Thomas } 240c5aa9e3bSLendacky, Thomas 24134bf65dfSLendacky, Thomas netif_dbg(pdata, drv, pdata->netdev, "%s - Rx ring:\n", 24234bf65dfSLendacky, Thomas channel->name); 24334bf65dfSLendacky, Thomas 244c5aa9e3bSLendacky, Thomas ret = xgbe_init_ring(pdata, channel->rx_ring, 245c5aa9e3bSLendacky, Thomas pdata->rx_desc_count); 246c5aa9e3bSLendacky, Thomas if (ret) { 247c5aa9e3bSLendacky, Thomas netdev_alert(pdata->netdev, 24834bf65dfSLendacky, Thomas "error initializing Rx ring\n"); 249c5aa9e3bSLendacky, Thomas goto err_ring; 250c5aa9e3bSLendacky, Thomas } 251c5aa9e3bSLendacky, Thomas } 252c5aa9e3bSLendacky, Thomas 253c5aa9e3bSLendacky, Thomas DBGPR("<--xgbe_alloc_ring_resources\n"); 254c5aa9e3bSLendacky, Thomas 255c5aa9e3bSLendacky, Thomas return 0; 256c5aa9e3bSLendacky, Thomas 257c5aa9e3bSLendacky, Thomas err_ring: 258c5aa9e3bSLendacky, Thomas xgbe_free_ring_resources(pdata); 259c5aa9e3bSLendacky, Thomas 260c5aa9e3bSLendacky, Thomas return ret; 261c5aa9e3bSLendacky, Thomas } 262c5aa9e3bSLendacky, Thomas 263174fd259SLendacky, Thomas static int xgbe_alloc_pages(struct xgbe_prv_data *pdata, 264174fd259SLendacky, Thomas struct xgbe_page_alloc *pa, gfp_t gfp, int order) 26508dcc47cSLendacky, Thomas { 26608dcc47cSLendacky, Thomas struct page *pages = NULL; 26708dcc47cSLendacky, Thomas dma_addr_t pages_dma; 268174fd259SLendacky, Thomas int ret; 26908dcc47cSLendacky, Thomas 27008dcc47cSLendacky, Thomas /* Try to obtain pages, decreasing order if necessary */ 271472cfe71STom Lendacky gfp |= __GFP_COLD | __GFP_COMP | __GFP_NOWARN; 272174fd259SLendacky, Thomas while (order >= 0) { 27308dcc47cSLendacky, Thomas pages = alloc_pages(gfp, order); 27408dcc47cSLendacky, Thomas if (pages) 27508dcc47cSLendacky, Thomas break; 276174fd259SLendacky, Thomas 277174fd259SLendacky, Thomas order--; 27808dcc47cSLendacky, Thomas } 27908dcc47cSLendacky, Thomas if (!pages) 28008dcc47cSLendacky, Thomas return -ENOMEM; 28108dcc47cSLendacky, Thomas 28208dcc47cSLendacky, Thomas /* Map the pages */ 28308dcc47cSLendacky, Thomas pages_dma = dma_map_page(pdata->dev, pages, 0, 28408dcc47cSLendacky, Thomas PAGE_SIZE << order, DMA_FROM_DEVICE); 28508dcc47cSLendacky, Thomas ret = dma_mapping_error(pdata->dev, pages_dma); 28608dcc47cSLendacky, Thomas if (ret) { 28708dcc47cSLendacky, Thomas put_page(pages); 28808dcc47cSLendacky, Thomas return ret; 28908dcc47cSLendacky, Thomas } 29008dcc47cSLendacky, Thomas 291174fd259SLendacky, Thomas pa->pages = pages; 292174fd259SLendacky, Thomas pa->pages_len = PAGE_SIZE << order; 293174fd259SLendacky, Thomas pa->pages_offset = 0; 294174fd259SLendacky, Thomas pa->pages_dma = pages_dma; 295174fd259SLendacky, Thomas 296174fd259SLendacky, Thomas return 0; 29708dcc47cSLendacky, Thomas } 29808dcc47cSLendacky, Thomas 299174fd259SLendacky, Thomas static void xgbe_set_buffer_data(struct xgbe_buffer_data *bd, 300174fd259SLendacky, Thomas struct xgbe_page_alloc *pa, 301174fd259SLendacky, Thomas unsigned int len) 302174fd259SLendacky, Thomas { 303174fd259SLendacky, Thomas get_page(pa->pages); 304174fd259SLendacky, Thomas bd->pa = *pa; 30508dcc47cSLendacky, Thomas 306*cfbfd86bSLendacky, Thomas bd->dma_base = pa->pages_dma; 307*cfbfd86bSLendacky, Thomas bd->dma_off = pa->pages_offset; 308174fd259SLendacky, Thomas bd->dma_len = len; 30908dcc47cSLendacky, Thomas 310174fd259SLendacky, Thomas pa->pages_offset += len; 311174fd259SLendacky, Thomas if ((pa->pages_offset + len) > pa->pages_len) { 31208dcc47cSLendacky, Thomas /* This data descriptor is responsible for unmapping page(s) */ 313174fd259SLendacky, Thomas bd->pa_unmap = *pa; 31408dcc47cSLendacky, Thomas 31508dcc47cSLendacky, Thomas /* Get a new allocation next time */ 316174fd259SLendacky, Thomas pa->pages = NULL; 317174fd259SLendacky, Thomas pa->pages_len = 0; 318174fd259SLendacky, Thomas pa->pages_offset = 0; 319174fd259SLendacky, Thomas pa->pages_dma = 0; 32008dcc47cSLendacky, Thomas } 321174fd259SLendacky, Thomas } 322174fd259SLendacky, Thomas 323174fd259SLendacky, Thomas static int xgbe_map_rx_buffer(struct xgbe_prv_data *pdata, 324174fd259SLendacky, Thomas struct xgbe_ring *ring, 325174fd259SLendacky, Thomas struct xgbe_ring_data *rdata) 326174fd259SLendacky, Thomas { 327174fd259SLendacky, Thomas int order, ret; 328174fd259SLendacky, Thomas 329174fd259SLendacky, Thomas if (!ring->rx_hdr_pa.pages) { 330174fd259SLendacky, Thomas ret = xgbe_alloc_pages(pdata, &ring->rx_hdr_pa, GFP_ATOMIC, 0); 331174fd259SLendacky, Thomas if (ret) 332174fd259SLendacky, Thomas return ret; 333174fd259SLendacky, Thomas } 334174fd259SLendacky, Thomas 335174fd259SLendacky, Thomas if (!ring->rx_buf_pa.pages) { 336174fd259SLendacky, Thomas order = max_t(int, PAGE_ALLOC_COSTLY_ORDER - 1, 0); 337174fd259SLendacky, Thomas ret = xgbe_alloc_pages(pdata, &ring->rx_buf_pa, GFP_ATOMIC, 338174fd259SLendacky, Thomas order); 339174fd259SLendacky, Thomas if (ret) 340174fd259SLendacky, Thomas return ret; 341174fd259SLendacky, Thomas } 342174fd259SLendacky, Thomas 343174fd259SLendacky, Thomas /* Set up the header page info */ 344c9f140ebSLendacky, Thomas xgbe_set_buffer_data(&rdata->rx.hdr, &ring->rx_hdr_pa, 345174fd259SLendacky, Thomas XGBE_SKB_ALLOC_SIZE); 346174fd259SLendacky, Thomas 347174fd259SLendacky, Thomas /* Set up the buffer page info */ 348c9f140ebSLendacky, Thomas xgbe_set_buffer_data(&rdata->rx.buf, &ring->rx_buf_pa, 349174fd259SLendacky, Thomas pdata->rx_buf_size); 35008dcc47cSLendacky, Thomas 35108dcc47cSLendacky, Thomas return 0; 35208dcc47cSLendacky, Thomas } 35308dcc47cSLendacky, Thomas 354c5aa9e3bSLendacky, Thomas static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata) 355c5aa9e3bSLendacky, Thomas { 356c5aa9e3bSLendacky, Thomas struct xgbe_hw_if *hw_if = &pdata->hw_if; 357c5aa9e3bSLendacky, Thomas struct xgbe_channel *channel; 358c5aa9e3bSLendacky, Thomas struct xgbe_ring *ring; 359c5aa9e3bSLendacky, Thomas struct xgbe_ring_data *rdata; 360c5aa9e3bSLendacky, Thomas struct xgbe_ring_desc *rdesc; 361c5aa9e3bSLendacky, Thomas dma_addr_t rdesc_dma; 362c5aa9e3bSLendacky, Thomas unsigned int i, j; 363c5aa9e3bSLendacky, Thomas 364c5aa9e3bSLendacky, Thomas DBGPR("-->xgbe_wrapper_tx_descriptor_init\n"); 365c5aa9e3bSLendacky, Thomas 366c5aa9e3bSLendacky, Thomas channel = pdata->channel; 367c5aa9e3bSLendacky, Thomas for (i = 0; i < pdata->channel_count; i++, channel++) { 368c5aa9e3bSLendacky, Thomas ring = channel->tx_ring; 369c5aa9e3bSLendacky, Thomas if (!ring) 370c5aa9e3bSLendacky, Thomas break; 371c5aa9e3bSLendacky, Thomas 372c5aa9e3bSLendacky, Thomas rdesc = ring->rdesc; 373c5aa9e3bSLendacky, Thomas rdesc_dma = ring->rdesc_dma; 374c5aa9e3bSLendacky, Thomas 375c5aa9e3bSLendacky, Thomas for (j = 0; j < ring->rdesc_count; j++) { 376d0a8ba6cSLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, j); 377c5aa9e3bSLendacky, Thomas 378c5aa9e3bSLendacky, Thomas rdata->rdesc = rdesc; 379c5aa9e3bSLendacky, Thomas rdata->rdesc_dma = rdesc_dma; 380c5aa9e3bSLendacky, Thomas 381c5aa9e3bSLendacky, Thomas rdesc++; 382c5aa9e3bSLendacky, Thomas rdesc_dma += sizeof(struct xgbe_ring_desc); 383c5aa9e3bSLendacky, Thomas } 384c5aa9e3bSLendacky, Thomas 385c5aa9e3bSLendacky, Thomas ring->cur = 0; 386c5aa9e3bSLendacky, Thomas ring->dirty = 0; 38716958a2bSLendacky, Thomas memset(&ring->tx, 0, sizeof(ring->tx)); 388c5aa9e3bSLendacky, Thomas 389c5aa9e3bSLendacky, Thomas hw_if->tx_desc_init(channel); 390c5aa9e3bSLendacky, Thomas } 391c5aa9e3bSLendacky, Thomas 392c5aa9e3bSLendacky, Thomas DBGPR("<--xgbe_wrapper_tx_descriptor_init\n"); 393c5aa9e3bSLendacky, Thomas } 394c5aa9e3bSLendacky, Thomas 395c5aa9e3bSLendacky, Thomas static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata) 396c5aa9e3bSLendacky, Thomas { 397c5aa9e3bSLendacky, Thomas struct xgbe_hw_if *hw_if = &pdata->hw_if; 398c5aa9e3bSLendacky, Thomas struct xgbe_channel *channel; 399c5aa9e3bSLendacky, Thomas struct xgbe_ring *ring; 400c5aa9e3bSLendacky, Thomas struct xgbe_ring_desc *rdesc; 401c5aa9e3bSLendacky, Thomas struct xgbe_ring_data *rdata; 40208dcc47cSLendacky, Thomas dma_addr_t rdesc_dma; 403c5aa9e3bSLendacky, Thomas unsigned int i, j; 404c5aa9e3bSLendacky, Thomas 405c5aa9e3bSLendacky, Thomas DBGPR("-->xgbe_wrapper_rx_descriptor_init\n"); 406c5aa9e3bSLendacky, Thomas 407c5aa9e3bSLendacky, Thomas channel = pdata->channel; 408c5aa9e3bSLendacky, Thomas for (i = 0; i < pdata->channel_count; i++, channel++) { 409c5aa9e3bSLendacky, Thomas ring = channel->rx_ring; 410c5aa9e3bSLendacky, Thomas if (!ring) 411c5aa9e3bSLendacky, Thomas break; 412c5aa9e3bSLendacky, Thomas 413c5aa9e3bSLendacky, Thomas rdesc = ring->rdesc; 414c5aa9e3bSLendacky, Thomas rdesc_dma = ring->rdesc_dma; 415c5aa9e3bSLendacky, Thomas 416c5aa9e3bSLendacky, Thomas for (j = 0; j < ring->rdesc_count; j++) { 417d0a8ba6cSLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, j); 418c5aa9e3bSLendacky, Thomas 419c5aa9e3bSLendacky, Thomas rdata->rdesc = rdesc; 420c5aa9e3bSLendacky, Thomas rdata->rdesc_dma = rdesc_dma; 421c5aa9e3bSLendacky, Thomas 42208dcc47cSLendacky, Thomas if (xgbe_map_rx_buffer(pdata, ring, rdata)) 423c5aa9e3bSLendacky, Thomas break; 424c5aa9e3bSLendacky, Thomas 425c5aa9e3bSLendacky, Thomas rdesc++; 426c5aa9e3bSLendacky, Thomas rdesc_dma += sizeof(struct xgbe_ring_desc); 427c5aa9e3bSLendacky, Thomas } 428c5aa9e3bSLendacky, Thomas 429c5aa9e3bSLendacky, Thomas ring->cur = 0; 430c5aa9e3bSLendacky, Thomas ring->dirty = 0; 431c5aa9e3bSLendacky, Thomas 432c5aa9e3bSLendacky, Thomas hw_if->rx_desc_init(channel); 433c5aa9e3bSLendacky, Thomas } 434c5aa9e3bSLendacky, Thomas 435c5aa9e3bSLendacky, Thomas DBGPR("<--xgbe_wrapper_rx_descriptor_init\n"); 436c5aa9e3bSLendacky, Thomas } 437c5aa9e3bSLendacky, Thomas 43808dcc47cSLendacky, Thomas static void xgbe_unmap_rdata(struct xgbe_prv_data *pdata, 439c5aa9e3bSLendacky, Thomas struct xgbe_ring_data *rdata) 440c5aa9e3bSLendacky, Thomas { 441c5aa9e3bSLendacky, Thomas if (rdata->skb_dma) { 442c5aa9e3bSLendacky, Thomas if (rdata->mapped_as_page) { 443c5aa9e3bSLendacky, Thomas dma_unmap_page(pdata->dev, rdata->skb_dma, 444c5aa9e3bSLendacky, Thomas rdata->skb_dma_len, DMA_TO_DEVICE); 445c5aa9e3bSLendacky, Thomas } else { 446c5aa9e3bSLendacky, Thomas dma_unmap_single(pdata->dev, rdata->skb_dma, 447c5aa9e3bSLendacky, Thomas rdata->skb_dma_len, DMA_TO_DEVICE); 448c5aa9e3bSLendacky, Thomas } 449c5aa9e3bSLendacky, Thomas rdata->skb_dma = 0; 450c5aa9e3bSLendacky, Thomas rdata->skb_dma_len = 0; 451c5aa9e3bSLendacky, Thomas } 452c5aa9e3bSLendacky, Thomas 453c5aa9e3bSLendacky, Thomas if (rdata->skb) { 454c5aa9e3bSLendacky, Thomas dev_kfree_skb_any(rdata->skb); 455c5aa9e3bSLendacky, Thomas rdata->skb = NULL; 456c5aa9e3bSLendacky, Thomas } 457c5aa9e3bSLendacky, Thomas 458c9f140ebSLendacky, Thomas if (rdata->rx.hdr.pa.pages) 459c9f140ebSLendacky, Thomas put_page(rdata->rx.hdr.pa.pages); 46008dcc47cSLendacky, Thomas 461c9f140ebSLendacky, Thomas if (rdata->rx.hdr.pa_unmap.pages) { 462c9f140ebSLendacky, Thomas dma_unmap_page(pdata->dev, rdata->rx.hdr.pa_unmap.pages_dma, 463c9f140ebSLendacky, Thomas rdata->rx.hdr.pa_unmap.pages_len, 464174fd259SLendacky, Thomas DMA_FROM_DEVICE); 465c9f140ebSLendacky, Thomas put_page(rdata->rx.hdr.pa_unmap.pages); 46608dcc47cSLendacky, Thomas } 46708dcc47cSLendacky, Thomas 468c9f140ebSLendacky, Thomas if (rdata->rx.buf.pa.pages) 469c9f140ebSLendacky, Thomas put_page(rdata->rx.buf.pa.pages); 47008dcc47cSLendacky, Thomas 471c9f140ebSLendacky, Thomas if (rdata->rx.buf.pa_unmap.pages) { 472c9f140ebSLendacky, Thomas dma_unmap_page(pdata->dev, rdata->rx.buf.pa_unmap.pages_dma, 473c9f140ebSLendacky, Thomas rdata->rx.buf.pa_unmap.pages_len, 474174fd259SLendacky, Thomas DMA_FROM_DEVICE); 475c9f140ebSLendacky, Thomas put_page(rdata->rx.buf.pa_unmap.pages); 476174fd259SLendacky, Thomas } 477174fd259SLendacky, Thomas 478c9f140ebSLendacky, Thomas memset(&rdata->tx, 0, sizeof(rdata->tx)); 479c9f140ebSLendacky, Thomas memset(&rdata->rx, 0, sizeof(rdata->rx)); 48008dcc47cSLendacky, Thomas 481c5aa9e3bSLendacky, Thomas rdata->mapped_as_page = 0; 48223e4eef7SLendacky, Thomas 48323e4eef7SLendacky, Thomas if (rdata->state_saved) { 48423e4eef7SLendacky, Thomas rdata->state_saved = 0; 48523e4eef7SLendacky, Thomas rdata->state.skb = NULL; 48623e4eef7SLendacky, Thomas rdata->state.len = 0; 48723e4eef7SLendacky, Thomas rdata->state.error = 0; 48823e4eef7SLendacky, Thomas } 489c5aa9e3bSLendacky, Thomas } 490c5aa9e3bSLendacky, Thomas 491c5aa9e3bSLendacky, Thomas static int xgbe_map_tx_skb(struct xgbe_channel *channel, struct sk_buff *skb) 492c5aa9e3bSLendacky, Thomas { 493c5aa9e3bSLendacky, Thomas struct xgbe_prv_data *pdata = channel->pdata; 494c5aa9e3bSLendacky, Thomas struct xgbe_ring *ring = channel->tx_ring; 495c5aa9e3bSLendacky, Thomas struct xgbe_ring_data *rdata; 496c5aa9e3bSLendacky, Thomas struct xgbe_packet_data *packet; 497c5aa9e3bSLendacky, Thomas struct skb_frag_struct *frag; 498c5aa9e3bSLendacky, Thomas dma_addr_t skb_dma; 499c5aa9e3bSLendacky, Thomas unsigned int start_index, cur_index; 500c5aa9e3bSLendacky, Thomas unsigned int offset, tso, vlan, datalen, len; 501c5aa9e3bSLendacky, Thomas unsigned int i; 502c5aa9e3bSLendacky, Thomas 503c5aa9e3bSLendacky, Thomas DBGPR("-->xgbe_map_tx_skb: cur = %d\n", ring->cur); 504c5aa9e3bSLendacky, Thomas 505c5aa9e3bSLendacky, Thomas offset = 0; 506c5aa9e3bSLendacky, Thomas start_index = ring->cur; 507c5aa9e3bSLendacky, Thomas cur_index = ring->cur; 508c5aa9e3bSLendacky, Thomas 509c5aa9e3bSLendacky, Thomas packet = &ring->packet_data; 510c5aa9e3bSLendacky, Thomas packet->rdesc_count = 0; 511c5aa9e3bSLendacky, Thomas packet->length = 0; 512c5aa9e3bSLendacky, Thomas 513c5aa9e3bSLendacky, Thomas tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, 514c5aa9e3bSLendacky, Thomas TSO_ENABLE); 515c5aa9e3bSLendacky, Thomas vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, 516c5aa9e3bSLendacky, Thomas VLAN_CTAG); 517c5aa9e3bSLendacky, Thomas 518c5aa9e3bSLendacky, Thomas /* Save space for a context descriptor if needed */ 519c5aa9e3bSLendacky, Thomas if ((tso && (packet->mss != ring->tx.cur_mss)) || 520c5aa9e3bSLendacky, Thomas (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))) 521c5aa9e3bSLendacky, Thomas cur_index++; 522d0a8ba6cSLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, cur_index); 523c5aa9e3bSLendacky, Thomas 524c5aa9e3bSLendacky, Thomas if (tso) { 525c5aa9e3bSLendacky, Thomas /* Map the TSO header */ 526c5aa9e3bSLendacky, Thomas skb_dma = dma_map_single(pdata->dev, skb->data, 527c5aa9e3bSLendacky, Thomas packet->header_len, DMA_TO_DEVICE); 528c5aa9e3bSLendacky, Thomas if (dma_mapping_error(pdata->dev, skb_dma)) { 529c5aa9e3bSLendacky, Thomas netdev_alert(pdata->netdev, "dma_map_single failed\n"); 530c5aa9e3bSLendacky, Thomas goto err_out; 531c5aa9e3bSLendacky, Thomas } 532c5aa9e3bSLendacky, Thomas rdata->skb_dma = skb_dma; 533c5aa9e3bSLendacky, Thomas rdata->skb_dma_len = packet->header_len; 53434bf65dfSLendacky, Thomas netif_dbg(pdata, tx_queued, pdata->netdev, 53534bf65dfSLendacky, Thomas "skb header: index=%u, dma=%pad, len=%u\n", 53634bf65dfSLendacky, Thomas cur_index, &skb_dma, packet->header_len); 537c5aa9e3bSLendacky, Thomas 538c5aa9e3bSLendacky, Thomas offset = packet->header_len; 539c5aa9e3bSLendacky, Thomas 540c5aa9e3bSLendacky, Thomas packet->length += packet->header_len; 541c5aa9e3bSLendacky, Thomas 542c5aa9e3bSLendacky, Thomas cur_index++; 543d0a8ba6cSLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, cur_index); 544c5aa9e3bSLendacky, Thomas } 545c5aa9e3bSLendacky, Thomas 546c5aa9e3bSLendacky, Thomas /* Map the (remainder of the) packet */ 547c5aa9e3bSLendacky, Thomas for (datalen = skb_headlen(skb) - offset; datalen; ) { 548d0a8ba6cSLendacky, Thomas len = min_t(unsigned int, datalen, XGBE_TX_MAX_BUF_SIZE); 549c5aa9e3bSLendacky, Thomas 550c5aa9e3bSLendacky, Thomas skb_dma = dma_map_single(pdata->dev, skb->data + offset, len, 551c5aa9e3bSLendacky, Thomas DMA_TO_DEVICE); 552c5aa9e3bSLendacky, Thomas if (dma_mapping_error(pdata->dev, skb_dma)) { 553c5aa9e3bSLendacky, Thomas netdev_alert(pdata->netdev, "dma_map_single failed\n"); 554c5aa9e3bSLendacky, Thomas goto err_out; 555c5aa9e3bSLendacky, Thomas } 556c5aa9e3bSLendacky, Thomas rdata->skb_dma = skb_dma; 557c5aa9e3bSLendacky, Thomas rdata->skb_dma_len = len; 55834bf65dfSLendacky, Thomas netif_dbg(pdata, tx_queued, pdata->netdev, 55934bf65dfSLendacky, Thomas "skb data: index=%u, dma=%pad, len=%u\n", 56034bf65dfSLendacky, Thomas cur_index, &skb_dma, len); 561c5aa9e3bSLendacky, Thomas 562c5aa9e3bSLendacky, Thomas datalen -= len; 563c5aa9e3bSLendacky, Thomas offset += len; 564c5aa9e3bSLendacky, Thomas 565c5aa9e3bSLendacky, Thomas packet->length += len; 566c5aa9e3bSLendacky, Thomas 567c5aa9e3bSLendacky, Thomas cur_index++; 568d0a8ba6cSLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, cur_index); 569c5aa9e3bSLendacky, Thomas } 570c5aa9e3bSLendacky, Thomas 571c5aa9e3bSLendacky, Thomas for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 57234bf65dfSLendacky, Thomas netif_dbg(pdata, tx_queued, pdata->netdev, 57334bf65dfSLendacky, Thomas "mapping frag %u\n", i); 574c5aa9e3bSLendacky, Thomas 575c5aa9e3bSLendacky, Thomas frag = &skb_shinfo(skb)->frags[i]; 576c5aa9e3bSLendacky, Thomas offset = 0; 577c5aa9e3bSLendacky, Thomas 578c5aa9e3bSLendacky, Thomas for (datalen = skb_frag_size(frag); datalen; ) { 579d0a8ba6cSLendacky, Thomas len = min_t(unsigned int, datalen, 580d0a8ba6cSLendacky, Thomas XGBE_TX_MAX_BUF_SIZE); 581c5aa9e3bSLendacky, Thomas 582c5aa9e3bSLendacky, Thomas skb_dma = skb_frag_dma_map(pdata->dev, frag, offset, 583c5aa9e3bSLendacky, Thomas len, DMA_TO_DEVICE); 584c5aa9e3bSLendacky, Thomas if (dma_mapping_error(pdata->dev, skb_dma)) { 585c5aa9e3bSLendacky, Thomas netdev_alert(pdata->netdev, 586c5aa9e3bSLendacky, Thomas "skb_frag_dma_map failed\n"); 587c5aa9e3bSLendacky, Thomas goto err_out; 588c5aa9e3bSLendacky, Thomas } 589c5aa9e3bSLendacky, Thomas rdata->skb_dma = skb_dma; 590c5aa9e3bSLendacky, Thomas rdata->skb_dma_len = len; 591c5aa9e3bSLendacky, Thomas rdata->mapped_as_page = 1; 59234bf65dfSLendacky, Thomas netif_dbg(pdata, tx_queued, pdata->netdev, 59334bf65dfSLendacky, Thomas "skb frag: index=%u, dma=%pad, len=%u\n", 59434bf65dfSLendacky, Thomas cur_index, &skb_dma, len); 595c5aa9e3bSLendacky, Thomas 596c5aa9e3bSLendacky, Thomas datalen -= len; 597c5aa9e3bSLendacky, Thomas offset += len; 598c5aa9e3bSLendacky, Thomas 599c5aa9e3bSLendacky, Thomas packet->length += len; 600c5aa9e3bSLendacky, Thomas 601c5aa9e3bSLendacky, Thomas cur_index++; 602d0a8ba6cSLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, cur_index); 603c5aa9e3bSLendacky, Thomas } 604c5aa9e3bSLendacky, Thomas } 605c5aa9e3bSLendacky, Thomas 606c1530317SLendacky, Thomas /* Save the skb address in the last entry. We always have some data 607c1530317SLendacky, Thomas * that has been mapped so rdata is always advanced past the last 608c1530317SLendacky, Thomas * piece of mapped data - use the entry pointed to by cur_index - 1. 609c1530317SLendacky, Thomas */ 610c1530317SLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, cur_index - 1); 611c5aa9e3bSLendacky, Thomas rdata->skb = skb; 612c5aa9e3bSLendacky, Thomas 613c5aa9e3bSLendacky, Thomas /* Save the number of descriptor entries used */ 614c5aa9e3bSLendacky, Thomas packet->rdesc_count = cur_index - start_index; 615c5aa9e3bSLendacky, Thomas 616c5aa9e3bSLendacky, Thomas DBGPR("<--xgbe_map_tx_skb: count=%u\n", packet->rdesc_count); 617c5aa9e3bSLendacky, Thomas 618c5aa9e3bSLendacky, Thomas return packet->rdesc_count; 619c5aa9e3bSLendacky, Thomas 620c5aa9e3bSLendacky, Thomas err_out: 621c5aa9e3bSLendacky, Thomas while (start_index < cur_index) { 622d0a8ba6cSLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, start_index++); 62308dcc47cSLendacky, Thomas xgbe_unmap_rdata(pdata, rdata); 624c5aa9e3bSLendacky, Thomas } 625c5aa9e3bSLendacky, Thomas 626c5aa9e3bSLendacky, Thomas DBGPR("<--xgbe_map_tx_skb: count=0\n"); 627c5aa9e3bSLendacky, Thomas 628c5aa9e3bSLendacky, Thomas return 0; 629c5aa9e3bSLendacky, Thomas } 630c5aa9e3bSLendacky, Thomas 631c5aa9e3bSLendacky, Thomas void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if) 632c5aa9e3bSLendacky, Thomas { 633c5aa9e3bSLendacky, Thomas DBGPR("-->xgbe_init_function_ptrs_desc\n"); 634c5aa9e3bSLendacky, Thomas 635c5aa9e3bSLendacky, Thomas desc_if->alloc_ring_resources = xgbe_alloc_ring_resources; 636c5aa9e3bSLendacky, Thomas desc_if->free_ring_resources = xgbe_free_ring_resources; 637c5aa9e3bSLendacky, Thomas desc_if->map_tx_skb = xgbe_map_tx_skb; 638270894e7SLendacky, Thomas desc_if->map_rx_buffer = xgbe_map_rx_buffer; 63908dcc47cSLendacky, Thomas desc_if->unmap_rdata = xgbe_unmap_rdata; 640c5aa9e3bSLendacky, Thomas desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init; 641c5aa9e3bSLendacky, Thomas desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init; 642c5aa9e3bSLendacky, Thomas 643c5aa9e3bSLendacky, Thomas DBGPR("<--xgbe_init_function_ptrs_desc\n"); 644c5aa9e3bSLendacky, Thomas } 645