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 179*18f9f0acSLendacky, Thomas for (i = 0; i < pdata->channel_count; i++) { 180*18f9f0acSLendacky, Thomas channel = pdata->channel[i]; 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 188*18f9f0acSLendacky, Thomas static void *xgbe_alloc_node(size_t size, int node) 189*18f9f0acSLendacky, Thomas { 190*18f9f0acSLendacky, Thomas void *mem; 191*18f9f0acSLendacky, Thomas 192*18f9f0acSLendacky, Thomas mem = kzalloc_node(size, GFP_KERNEL, node); 193*18f9f0acSLendacky, Thomas if (!mem) 194*18f9f0acSLendacky, Thomas mem = kzalloc(size, GFP_KERNEL); 195*18f9f0acSLendacky, Thomas 196*18f9f0acSLendacky, Thomas return mem; 197*18f9f0acSLendacky, Thomas } 198*18f9f0acSLendacky, Thomas 199*18f9f0acSLendacky, Thomas static void *xgbe_dma_alloc_node(struct device *dev, size_t size, 200*18f9f0acSLendacky, Thomas dma_addr_t *dma, int node) 201*18f9f0acSLendacky, Thomas { 202*18f9f0acSLendacky, Thomas void *mem; 203*18f9f0acSLendacky, Thomas int cur_node = dev_to_node(dev); 204*18f9f0acSLendacky, Thomas 205*18f9f0acSLendacky, Thomas set_dev_node(dev, node); 206*18f9f0acSLendacky, Thomas mem = dma_alloc_coherent(dev, size, dma, GFP_KERNEL); 207*18f9f0acSLendacky, Thomas set_dev_node(dev, cur_node); 208*18f9f0acSLendacky, Thomas 209*18f9f0acSLendacky, Thomas if (!mem) 210*18f9f0acSLendacky, Thomas mem = dma_alloc_coherent(dev, size, dma, GFP_KERNEL); 211*18f9f0acSLendacky, Thomas 212*18f9f0acSLendacky, Thomas return mem; 213*18f9f0acSLendacky, Thomas } 214*18f9f0acSLendacky, Thomas 215c5aa9e3bSLendacky, Thomas static int xgbe_init_ring(struct xgbe_prv_data *pdata, 216c5aa9e3bSLendacky, Thomas struct xgbe_ring *ring, unsigned int rdesc_count) 217c5aa9e3bSLendacky, Thomas { 218*18f9f0acSLendacky, Thomas size_t size; 219c5aa9e3bSLendacky, Thomas 220c5aa9e3bSLendacky, Thomas if (!ring) 221c5aa9e3bSLendacky, Thomas return 0; 222c5aa9e3bSLendacky, Thomas 223c5aa9e3bSLendacky, Thomas /* Descriptors */ 224*18f9f0acSLendacky, Thomas size = rdesc_count * sizeof(struct xgbe_ring_desc); 225*18f9f0acSLendacky, Thomas 226c5aa9e3bSLendacky, Thomas ring->rdesc_count = rdesc_count; 227*18f9f0acSLendacky, Thomas ring->rdesc = xgbe_dma_alloc_node(pdata->dev, size, &ring->rdesc_dma, 228*18f9f0acSLendacky, Thomas ring->node); 229c5aa9e3bSLendacky, Thomas if (!ring->rdesc) 230c5aa9e3bSLendacky, Thomas return -ENOMEM; 231c5aa9e3bSLendacky, Thomas 232c5aa9e3bSLendacky, Thomas /* Descriptor information */ 233*18f9f0acSLendacky, Thomas size = rdesc_count * sizeof(struct xgbe_ring_data); 234*18f9f0acSLendacky, Thomas 235*18f9f0acSLendacky, Thomas ring->rdata = xgbe_alloc_node(size, ring->node); 236c5aa9e3bSLendacky, Thomas if (!ring->rdata) 237c5aa9e3bSLendacky, Thomas return -ENOMEM; 238c5aa9e3bSLendacky, Thomas 23934bf65dfSLendacky, Thomas netif_dbg(pdata, drv, pdata->netdev, 240*18f9f0acSLendacky, Thomas "rdesc=%p, rdesc_dma=%pad, rdata=%p, node=%d\n", 241*18f9f0acSLendacky, Thomas ring->rdesc, &ring->rdesc_dma, ring->rdata, ring->node); 242c5aa9e3bSLendacky, Thomas 243c5aa9e3bSLendacky, Thomas return 0; 244c5aa9e3bSLendacky, Thomas } 245c5aa9e3bSLendacky, Thomas 246c5aa9e3bSLendacky, Thomas static int xgbe_alloc_ring_resources(struct xgbe_prv_data *pdata) 247c5aa9e3bSLendacky, Thomas { 248c5aa9e3bSLendacky, Thomas struct xgbe_channel *channel; 249c5aa9e3bSLendacky, Thomas unsigned int i; 250c5aa9e3bSLendacky, Thomas int ret; 251c5aa9e3bSLendacky, Thomas 252*18f9f0acSLendacky, Thomas for (i = 0; i < pdata->channel_count; i++) { 253*18f9f0acSLendacky, Thomas channel = pdata->channel[i]; 25434bf65dfSLendacky, Thomas netif_dbg(pdata, drv, pdata->netdev, "%s - Tx ring:\n", 25534bf65dfSLendacky, Thomas channel->name); 25634bf65dfSLendacky, Thomas 257c5aa9e3bSLendacky, Thomas ret = xgbe_init_ring(pdata, channel->tx_ring, 258c5aa9e3bSLendacky, Thomas pdata->tx_desc_count); 259c5aa9e3bSLendacky, Thomas if (ret) { 260c5aa9e3bSLendacky, Thomas netdev_alert(pdata->netdev, 261c5aa9e3bSLendacky, Thomas "error initializing Tx ring\n"); 262c5aa9e3bSLendacky, Thomas goto err_ring; 263c5aa9e3bSLendacky, Thomas } 264c5aa9e3bSLendacky, Thomas 26534bf65dfSLendacky, Thomas netif_dbg(pdata, drv, pdata->netdev, "%s - Rx ring:\n", 26634bf65dfSLendacky, Thomas channel->name); 26734bf65dfSLendacky, Thomas 268c5aa9e3bSLendacky, Thomas ret = xgbe_init_ring(pdata, channel->rx_ring, 269c5aa9e3bSLendacky, Thomas pdata->rx_desc_count); 270c5aa9e3bSLendacky, Thomas if (ret) { 271c5aa9e3bSLendacky, Thomas netdev_alert(pdata->netdev, 27234bf65dfSLendacky, Thomas "error initializing Rx ring\n"); 273c5aa9e3bSLendacky, Thomas goto err_ring; 274c5aa9e3bSLendacky, Thomas } 275c5aa9e3bSLendacky, Thomas } 276c5aa9e3bSLendacky, Thomas 277c5aa9e3bSLendacky, Thomas return 0; 278c5aa9e3bSLendacky, Thomas 279c5aa9e3bSLendacky, Thomas err_ring: 280c5aa9e3bSLendacky, Thomas xgbe_free_ring_resources(pdata); 281c5aa9e3bSLendacky, Thomas 282c5aa9e3bSLendacky, Thomas return ret; 283c5aa9e3bSLendacky, Thomas } 284c5aa9e3bSLendacky, Thomas 285174fd259SLendacky, Thomas static int xgbe_alloc_pages(struct xgbe_prv_data *pdata, 286*18f9f0acSLendacky, Thomas struct xgbe_page_alloc *pa, int alloc_order, 287*18f9f0acSLendacky, Thomas int node) 28808dcc47cSLendacky, Thomas { 28908dcc47cSLendacky, Thomas struct page *pages = NULL; 29008dcc47cSLendacky, Thomas dma_addr_t pages_dma; 291*18f9f0acSLendacky, Thomas gfp_t gfp; 292*18f9f0acSLendacky, Thomas int order, ret; 293*18f9f0acSLendacky, Thomas 294*18f9f0acSLendacky, Thomas again: 295*18f9f0acSLendacky, Thomas order = alloc_order; 29608dcc47cSLendacky, Thomas 29708dcc47cSLendacky, Thomas /* Try to obtain pages, decreasing order if necessary */ 298*18f9f0acSLendacky, Thomas gfp = GFP_ATOMIC | __GFP_COLD | __GFP_COMP | __GFP_NOWARN; 299174fd259SLendacky, Thomas while (order >= 0) { 300*18f9f0acSLendacky, Thomas pages = alloc_pages_node(node, gfp, order); 30108dcc47cSLendacky, Thomas if (pages) 30208dcc47cSLendacky, Thomas break; 303174fd259SLendacky, Thomas 304174fd259SLendacky, Thomas order--; 30508dcc47cSLendacky, Thomas } 306*18f9f0acSLendacky, Thomas 307*18f9f0acSLendacky, Thomas /* If we couldn't get local pages, try getting from anywhere */ 308*18f9f0acSLendacky, Thomas if (!pages && (node != NUMA_NO_NODE)) { 309*18f9f0acSLendacky, Thomas node = NUMA_NO_NODE; 310*18f9f0acSLendacky, Thomas goto again; 311*18f9f0acSLendacky, Thomas } 312*18f9f0acSLendacky, Thomas 31308dcc47cSLendacky, Thomas if (!pages) 31408dcc47cSLendacky, Thomas return -ENOMEM; 31508dcc47cSLendacky, Thomas 31608dcc47cSLendacky, Thomas /* Map the pages */ 31708dcc47cSLendacky, Thomas pages_dma = dma_map_page(pdata->dev, pages, 0, 31808dcc47cSLendacky, Thomas PAGE_SIZE << order, DMA_FROM_DEVICE); 31908dcc47cSLendacky, Thomas ret = dma_mapping_error(pdata->dev, pages_dma); 32008dcc47cSLendacky, Thomas if (ret) { 32108dcc47cSLendacky, Thomas put_page(pages); 32208dcc47cSLendacky, Thomas return ret; 32308dcc47cSLendacky, Thomas } 32408dcc47cSLendacky, Thomas 325174fd259SLendacky, Thomas pa->pages = pages; 326174fd259SLendacky, Thomas pa->pages_len = PAGE_SIZE << order; 327174fd259SLendacky, Thomas pa->pages_offset = 0; 328174fd259SLendacky, Thomas pa->pages_dma = pages_dma; 329174fd259SLendacky, Thomas 330174fd259SLendacky, Thomas return 0; 33108dcc47cSLendacky, Thomas } 33208dcc47cSLendacky, Thomas 333174fd259SLendacky, Thomas static void xgbe_set_buffer_data(struct xgbe_buffer_data *bd, 334174fd259SLendacky, Thomas struct xgbe_page_alloc *pa, 335174fd259SLendacky, Thomas unsigned int len) 336174fd259SLendacky, Thomas { 337174fd259SLendacky, Thomas get_page(pa->pages); 338174fd259SLendacky, Thomas bd->pa = *pa; 33908dcc47cSLendacky, Thomas 340cfbfd86bSLendacky, Thomas bd->dma_base = pa->pages_dma; 341cfbfd86bSLendacky, Thomas bd->dma_off = pa->pages_offset; 342174fd259SLendacky, Thomas bd->dma_len = len; 34308dcc47cSLendacky, Thomas 344174fd259SLendacky, Thomas pa->pages_offset += len; 345174fd259SLendacky, Thomas if ((pa->pages_offset + len) > pa->pages_len) { 34608dcc47cSLendacky, Thomas /* This data descriptor is responsible for unmapping page(s) */ 347174fd259SLendacky, Thomas bd->pa_unmap = *pa; 34808dcc47cSLendacky, Thomas 34908dcc47cSLendacky, Thomas /* Get a new allocation next time */ 350174fd259SLendacky, Thomas pa->pages = NULL; 351174fd259SLendacky, Thomas pa->pages_len = 0; 352174fd259SLendacky, Thomas pa->pages_offset = 0; 353174fd259SLendacky, Thomas pa->pages_dma = 0; 35408dcc47cSLendacky, Thomas } 355174fd259SLendacky, Thomas } 356174fd259SLendacky, Thomas 357174fd259SLendacky, Thomas static int xgbe_map_rx_buffer(struct xgbe_prv_data *pdata, 358174fd259SLendacky, Thomas struct xgbe_ring *ring, 359174fd259SLendacky, Thomas struct xgbe_ring_data *rdata) 360174fd259SLendacky, Thomas { 361a7c0b8beSMichal Hocko int ret; 362174fd259SLendacky, Thomas 363174fd259SLendacky, Thomas if (!ring->rx_hdr_pa.pages) { 364*18f9f0acSLendacky, Thomas ret = xgbe_alloc_pages(pdata, &ring->rx_hdr_pa, 0, ring->node); 365174fd259SLendacky, Thomas if (ret) 366174fd259SLendacky, Thomas return ret; 367174fd259SLendacky, Thomas } 368174fd259SLendacky, Thomas 369174fd259SLendacky, Thomas if (!ring->rx_buf_pa.pages) { 370*18f9f0acSLendacky, Thomas ret = xgbe_alloc_pages(pdata, &ring->rx_buf_pa, 371*18f9f0acSLendacky, Thomas PAGE_ALLOC_COSTLY_ORDER, ring->node); 372174fd259SLendacky, Thomas if (ret) 373174fd259SLendacky, Thomas return ret; 374174fd259SLendacky, Thomas } 375174fd259SLendacky, Thomas 376174fd259SLendacky, Thomas /* Set up the header page info */ 377c9f140ebSLendacky, Thomas xgbe_set_buffer_data(&rdata->rx.hdr, &ring->rx_hdr_pa, 378174fd259SLendacky, Thomas XGBE_SKB_ALLOC_SIZE); 379174fd259SLendacky, Thomas 380174fd259SLendacky, Thomas /* Set up the buffer page info */ 381c9f140ebSLendacky, Thomas xgbe_set_buffer_data(&rdata->rx.buf, &ring->rx_buf_pa, 382174fd259SLendacky, Thomas pdata->rx_buf_size); 38308dcc47cSLendacky, Thomas 38408dcc47cSLendacky, Thomas return 0; 38508dcc47cSLendacky, Thomas } 38608dcc47cSLendacky, Thomas 387c5aa9e3bSLendacky, Thomas static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata) 388c5aa9e3bSLendacky, Thomas { 389c5aa9e3bSLendacky, Thomas struct xgbe_hw_if *hw_if = &pdata->hw_if; 390c5aa9e3bSLendacky, Thomas struct xgbe_channel *channel; 391c5aa9e3bSLendacky, Thomas struct xgbe_ring *ring; 392c5aa9e3bSLendacky, Thomas struct xgbe_ring_data *rdata; 393c5aa9e3bSLendacky, Thomas struct xgbe_ring_desc *rdesc; 394c5aa9e3bSLendacky, Thomas dma_addr_t rdesc_dma; 395c5aa9e3bSLendacky, Thomas unsigned int i, j; 396c5aa9e3bSLendacky, Thomas 397c5aa9e3bSLendacky, Thomas DBGPR("-->xgbe_wrapper_tx_descriptor_init\n"); 398c5aa9e3bSLendacky, Thomas 399*18f9f0acSLendacky, Thomas for (i = 0; i < pdata->channel_count; i++) { 400*18f9f0acSLendacky, Thomas channel = pdata->channel[i]; 401c5aa9e3bSLendacky, Thomas ring = channel->tx_ring; 402c5aa9e3bSLendacky, Thomas if (!ring) 403c5aa9e3bSLendacky, Thomas break; 404c5aa9e3bSLendacky, Thomas 405c5aa9e3bSLendacky, Thomas rdesc = ring->rdesc; 406c5aa9e3bSLendacky, Thomas rdesc_dma = ring->rdesc_dma; 407c5aa9e3bSLendacky, Thomas 408c5aa9e3bSLendacky, Thomas for (j = 0; j < ring->rdesc_count; j++) { 409d0a8ba6cSLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, j); 410c5aa9e3bSLendacky, Thomas 411c5aa9e3bSLendacky, Thomas rdata->rdesc = rdesc; 412c5aa9e3bSLendacky, Thomas rdata->rdesc_dma = rdesc_dma; 413c5aa9e3bSLendacky, Thomas 414c5aa9e3bSLendacky, Thomas rdesc++; 415c5aa9e3bSLendacky, Thomas rdesc_dma += sizeof(struct xgbe_ring_desc); 416c5aa9e3bSLendacky, Thomas } 417c5aa9e3bSLendacky, Thomas 418c5aa9e3bSLendacky, Thomas ring->cur = 0; 419c5aa9e3bSLendacky, Thomas ring->dirty = 0; 42016958a2bSLendacky, Thomas memset(&ring->tx, 0, sizeof(ring->tx)); 421c5aa9e3bSLendacky, Thomas 422c5aa9e3bSLendacky, Thomas hw_if->tx_desc_init(channel); 423c5aa9e3bSLendacky, Thomas } 424c5aa9e3bSLendacky, Thomas 425c5aa9e3bSLendacky, Thomas DBGPR("<--xgbe_wrapper_tx_descriptor_init\n"); 426c5aa9e3bSLendacky, Thomas } 427c5aa9e3bSLendacky, Thomas 428c5aa9e3bSLendacky, Thomas static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata) 429c5aa9e3bSLendacky, Thomas { 430c5aa9e3bSLendacky, Thomas struct xgbe_hw_if *hw_if = &pdata->hw_if; 431c5aa9e3bSLendacky, Thomas struct xgbe_channel *channel; 432c5aa9e3bSLendacky, Thomas struct xgbe_ring *ring; 433c5aa9e3bSLendacky, Thomas struct xgbe_ring_desc *rdesc; 434c5aa9e3bSLendacky, Thomas struct xgbe_ring_data *rdata; 43508dcc47cSLendacky, Thomas dma_addr_t rdesc_dma; 436c5aa9e3bSLendacky, Thomas unsigned int i, j; 437c5aa9e3bSLendacky, Thomas 438c5aa9e3bSLendacky, Thomas DBGPR("-->xgbe_wrapper_rx_descriptor_init\n"); 439c5aa9e3bSLendacky, Thomas 440*18f9f0acSLendacky, Thomas for (i = 0; i < pdata->channel_count; i++) { 441*18f9f0acSLendacky, Thomas channel = pdata->channel[i]; 442c5aa9e3bSLendacky, Thomas ring = channel->rx_ring; 443c5aa9e3bSLendacky, Thomas if (!ring) 444c5aa9e3bSLendacky, Thomas break; 445c5aa9e3bSLendacky, Thomas 446c5aa9e3bSLendacky, Thomas rdesc = ring->rdesc; 447c5aa9e3bSLendacky, Thomas rdesc_dma = ring->rdesc_dma; 448c5aa9e3bSLendacky, Thomas 449c5aa9e3bSLendacky, Thomas for (j = 0; j < ring->rdesc_count; j++) { 450d0a8ba6cSLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, j); 451c5aa9e3bSLendacky, Thomas 452c5aa9e3bSLendacky, Thomas rdata->rdesc = rdesc; 453c5aa9e3bSLendacky, Thomas rdata->rdesc_dma = rdesc_dma; 454c5aa9e3bSLendacky, Thomas 45508dcc47cSLendacky, Thomas if (xgbe_map_rx_buffer(pdata, ring, rdata)) 456c5aa9e3bSLendacky, Thomas break; 457c5aa9e3bSLendacky, Thomas 458c5aa9e3bSLendacky, Thomas rdesc++; 459c5aa9e3bSLendacky, Thomas rdesc_dma += sizeof(struct xgbe_ring_desc); 460c5aa9e3bSLendacky, Thomas } 461c5aa9e3bSLendacky, Thomas 462c5aa9e3bSLendacky, Thomas ring->cur = 0; 463c5aa9e3bSLendacky, Thomas ring->dirty = 0; 464c5aa9e3bSLendacky, Thomas 465c5aa9e3bSLendacky, Thomas hw_if->rx_desc_init(channel); 466c5aa9e3bSLendacky, Thomas } 467c5aa9e3bSLendacky, Thomas 468c5aa9e3bSLendacky, Thomas DBGPR("<--xgbe_wrapper_rx_descriptor_init\n"); 469c5aa9e3bSLendacky, Thomas } 470c5aa9e3bSLendacky, Thomas 47108dcc47cSLendacky, Thomas static void xgbe_unmap_rdata(struct xgbe_prv_data *pdata, 472c5aa9e3bSLendacky, Thomas struct xgbe_ring_data *rdata) 473c5aa9e3bSLendacky, Thomas { 474c5aa9e3bSLendacky, Thomas if (rdata->skb_dma) { 475c5aa9e3bSLendacky, Thomas if (rdata->mapped_as_page) { 476c5aa9e3bSLendacky, Thomas dma_unmap_page(pdata->dev, rdata->skb_dma, 477c5aa9e3bSLendacky, Thomas rdata->skb_dma_len, DMA_TO_DEVICE); 478c5aa9e3bSLendacky, Thomas } else { 479c5aa9e3bSLendacky, Thomas dma_unmap_single(pdata->dev, rdata->skb_dma, 480c5aa9e3bSLendacky, Thomas rdata->skb_dma_len, DMA_TO_DEVICE); 481c5aa9e3bSLendacky, Thomas } 482c5aa9e3bSLendacky, Thomas rdata->skb_dma = 0; 483c5aa9e3bSLendacky, Thomas rdata->skb_dma_len = 0; 484c5aa9e3bSLendacky, Thomas } 485c5aa9e3bSLendacky, Thomas 486c5aa9e3bSLendacky, Thomas if (rdata->skb) { 487c5aa9e3bSLendacky, Thomas dev_kfree_skb_any(rdata->skb); 488c5aa9e3bSLendacky, Thomas rdata->skb = NULL; 489c5aa9e3bSLendacky, Thomas } 490c5aa9e3bSLendacky, Thomas 491c9f140ebSLendacky, Thomas if (rdata->rx.hdr.pa.pages) 492c9f140ebSLendacky, Thomas put_page(rdata->rx.hdr.pa.pages); 49308dcc47cSLendacky, Thomas 494c9f140ebSLendacky, Thomas if (rdata->rx.hdr.pa_unmap.pages) { 495c9f140ebSLendacky, Thomas dma_unmap_page(pdata->dev, rdata->rx.hdr.pa_unmap.pages_dma, 496c9f140ebSLendacky, Thomas rdata->rx.hdr.pa_unmap.pages_len, 497174fd259SLendacky, Thomas DMA_FROM_DEVICE); 498c9f140ebSLendacky, Thomas put_page(rdata->rx.hdr.pa_unmap.pages); 49908dcc47cSLendacky, Thomas } 50008dcc47cSLendacky, Thomas 501c9f140ebSLendacky, Thomas if (rdata->rx.buf.pa.pages) 502c9f140ebSLendacky, Thomas put_page(rdata->rx.buf.pa.pages); 50308dcc47cSLendacky, Thomas 504c9f140ebSLendacky, Thomas if (rdata->rx.buf.pa_unmap.pages) { 505c9f140ebSLendacky, Thomas dma_unmap_page(pdata->dev, rdata->rx.buf.pa_unmap.pages_dma, 506c9f140ebSLendacky, Thomas rdata->rx.buf.pa_unmap.pages_len, 507174fd259SLendacky, Thomas DMA_FROM_DEVICE); 508c9f140ebSLendacky, Thomas put_page(rdata->rx.buf.pa_unmap.pages); 509174fd259SLendacky, Thomas } 510174fd259SLendacky, Thomas 511c9f140ebSLendacky, Thomas memset(&rdata->tx, 0, sizeof(rdata->tx)); 512c9f140ebSLendacky, Thomas memset(&rdata->rx, 0, sizeof(rdata->rx)); 51308dcc47cSLendacky, Thomas 514c5aa9e3bSLendacky, Thomas rdata->mapped_as_page = 0; 51523e4eef7SLendacky, Thomas 51623e4eef7SLendacky, Thomas if (rdata->state_saved) { 51723e4eef7SLendacky, Thomas rdata->state_saved = 0; 51823e4eef7SLendacky, Thomas rdata->state.skb = NULL; 51923e4eef7SLendacky, Thomas rdata->state.len = 0; 52023e4eef7SLendacky, Thomas rdata->state.error = 0; 52123e4eef7SLendacky, Thomas } 522c5aa9e3bSLendacky, Thomas } 523c5aa9e3bSLendacky, Thomas 524c5aa9e3bSLendacky, Thomas static int xgbe_map_tx_skb(struct xgbe_channel *channel, struct sk_buff *skb) 525c5aa9e3bSLendacky, Thomas { 526c5aa9e3bSLendacky, Thomas struct xgbe_prv_data *pdata = channel->pdata; 527c5aa9e3bSLendacky, Thomas struct xgbe_ring *ring = channel->tx_ring; 528c5aa9e3bSLendacky, Thomas struct xgbe_ring_data *rdata; 529c5aa9e3bSLendacky, Thomas struct xgbe_packet_data *packet; 530c5aa9e3bSLendacky, Thomas struct skb_frag_struct *frag; 531c5aa9e3bSLendacky, Thomas dma_addr_t skb_dma; 532c5aa9e3bSLendacky, Thomas unsigned int start_index, cur_index; 533c5aa9e3bSLendacky, Thomas unsigned int offset, tso, vlan, datalen, len; 534c5aa9e3bSLendacky, Thomas unsigned int i; 535c5aa9e3bSLendacky, Thomas 536c5aa9e3bSLendacky, Thomas DBGPR("-->xgbe_map_tx_skb: cur = %d\n", ring->cur); 537c5aa9e3bSLendacky, Thomas 538c5aa9e3bSLendacky, Thomas offset = 0; 539c5aa9e3bSLendacky, Thomas start_index = ring->cur; 540c5aa9e3bSLendacky, Thomas cur_index = ring->cur; 541c5aa9e3bSLendacky, Thomas 542c5aa9e3bSLendacky, Thomas packet = &ring->packet_data; 543c5aa9e3bSLendacky, Thomas packet->rdesc_count = 0; 544c5aa9e3bSLendacky, Thomas packet->length = 0; 545c5aa9e3bSLendacky, Thomas 546c5aa9e3bSLendacky, Thomas tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, 547c5aa9e3bSLendacky, Thomas TSO_ENABLE); 548c5aa9e3bSLendacky, Thomas vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, 549c5aa9e3bSLendacky, Thomas VLAN_CTAG); 550c5aa9e3bSLendacky, Thomas 551c5aa9e3bSLendacky, Thomas /* Save space for a context descriptor if needed */ 552c5aa9e3bSLendacky, Thomas if ((tso && (packet->mss != ring->tx.cur_mss)) || 553c5aa9e3bSLendacky, Thomas (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))) 554c5aa9e3bSLendacky, Thomas cur_index++; 555d0a8ba6cSLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, cur_index); 556c5aa9e3bSLendacky, Thomas 557c5aa9e3bSLendacky, Thomas if (tso) { 558c5aa9e3bSLendacky, Thomas /* Map the TSO header */ 559c5aa9e3bSLendacky, Thomas skb_dma = dma_map_single(pdata->dev, skb->data, 560c5aa9e3bSLendacky, Thomas packet->header_len, DMA_TO_DEVICE); 561c5aa9e3bSLendacky, Thomas if (dma_mapping_error(pdata->dev, skb_dma)) { 562c5aa9e3bSLendacky, Thomas netdev_alert(pdata->netdev, "dma_map_single failed\n"); 563c5aa9e3bSLendacky, Thomas goto err_out; 564c5aa9e3bSLendacky, Thomas } 565c5aa9e3bSLendacky, Thomas rdata->skb_dma = skb_dma; 566c5aa9e3bSLendacky, Thomas rdata->skb_dma_len = packet->header_len; 56734bf65dfSLendacky, Thomas netif_dbg(pdata, tx_queued, pdata->netdev, 56834bf65dfSLendacky, Thomas "skb header: index=%u, dma=%pad, len=%u\n", 56934bf65dfSLendacky, Thomas cur_index, &skb_dma, packet->header_len); 570c5aa9e3bSLendacky, Thomas 571c5aa9e3bSLendacky, Thomas offset = packet->header_len; 572c5aa9e3bSLendacky, Thomas 573c5aa9e3bSLendacky, Thomas packet->length += packet->header_len; 574c5aa9e3bSLendacky, Thomas 575c5aa9e3bSLendacky, Thomas cur_index++; 576d0a8ba6cSLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, cur_index); 577c5aa9e3bSLendacky, Thomas } 578c5aa9e3bSLendacky, Thomas 579c5aa9e3bSLendacky, Thomas /* Map the (remainder of the) packet */ 580c5aa9e3bSLendacky, Thomas for (datalen = skb_headlen(skb) - offset; datalen; ) { 581d0a8ba6cSLendacky, Thomas len = min_t(unsigned int, datalen, XGBE_TX_MAX_BUF_SIZE); 582c5aa9e3bSLendacky, Thomas 583c5aa9e3bSLendacky, Thomas skb_dma = dma_map_single(pdata->dev, skb->data + offset, len, 584c5aa9e3bSLendacky, Thomas DMA_TO_DEVICE); 585c5aa9e3bSLendacky, Thomas if (dma_mapping_error(pdata->dev, skb_dma)) { 586c5aa9e3bSLendacky, Thomas netdev_alert(pdata->netdev, "dma_map_single failed\n"); 587c5aa9e3bSLendacky, Thomas goto err_out; 588c5aa9e3bSLendacky, Thomas } 589c5aa9e3bSLendacky, Thomas rdata->skb_dma = skb_dma; 590c5aa9e3bSLendacky, Thomas rdata->skb_dma_len = len; 59134bf65dfSLendacky, Thomas netif_dbg(pdata, tx_queued, pdata->netdev, 59234bf65dfSLendacky, Thomas "skb data: index=%u, dma=%pad, len=%u\n", 59334bf65dfSLendacky, Thomas cur_index, &skb_dma, len); 594c5aa9e3bSLendacky, Thomas 595c5aa9e3bSLendacky, Thomas datalen -= len; 596c5aa9e3bSLendacky, Thomas offset += len; 597c5aa9e3bSLendacky, Thomas 598c5aa9e3bSLendacky, Thomas packet->length += len; 599c5aa9e3bSLendacky, Thomas 600c5aa9e3bSLendacky, Thomas cur_index++; 601d0a8ba6cSLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, cur_index); 602c5aa9e3bSLendacky, Thomas } 603c5aa9e3bSLendacky, Thomas 604c5aa9e3bSLendacky, Thomas for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 60534bf65dfSLendacky, Thomas netif_dbg(pdata, tx_queued, pdata->netdev, 60634bf65dfSLendacky, Thomas "mapping frag %u\n", i); 607c5aa9e3bSLendacky, Thomas 608c5aa9e3bSLendacky, Thomas frag = &skb_shinfo(skb)->frags[i]; 609c5aa9e3bSLendacky, Thomas offset = 0; 610c5aa9e3bSLendacky, Thomas 611c5aa9e3bSLendacky, Thomas for (datalen = skb_frag_size(frag); datalen; ) { 612d0a8ba6cSLendacky, Thomas len = min_t(unsigned int, datalen, 613d0a8ba6cSLendacky, Thomas XGBE_TX_MAX_BUF_SIZE); 614c5aa9e3bSLendacky, Thomas 615c5aa9e3bSLendacky, Thomas skb_dma = skb_frag_dma_map(pdata->dev, frag, offset, 616c5aa9e3bSLendacky, Thomas len, DMA_TO_DEVICE); 617c5aa9e3bSLendacky, Thomas if (dma_mapping_error(pdata->dev, skb_dma)) { 618c5aa9e3bSLendacky, Thomas netdev_alert(pdata->netdev, 619c5aa9e3bSLendacky, Thomas "skb_frag_dma_map failed\n"); 620c5aa9e3bSLendacky, Thomas goto err_out; 621c5aa9e3bSLendacky, Thomas } 622c5aa9e3bSLendacky, Thomas rdata->skb_dma = skb_dma; 623c5aa9e3bSLendacky, Thomas rdata->skb_dma_len = len; 624c5aa9e3bSLendacky, Thomas rdata->mapped_as_page = 1; 62534bf65dfSLendacky, Thomas netif_dbg(pdata, tx_queued, pdata->netdev, 62634bf65dfSLendacky, Thomas "skb frag: index=%u, dma=%pad, len=%u\n", 62734bf65dfSLendacky, Thomas cur_index, &skb_dma, len); 628c5aa9e3bSLendacky, Thomas 629c5aa9e3bSLendacky, Thomas datalen -= len; 630c5aa9e3bSLendacky, Thomas offset += len; 631c5aa9e3bSLendacky, Thomas 632c5aa9e3bSLendacky, Thomas packet->length += len; 633c5aa9e3bSLendacky, Thomas 634c5aa9e3bSLendacky, Thomas cur_index++; 635d0a8ba6cSLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, cur_index); 636c5aa9e3bSLendacky, Thomas } 637c5aa9e3bSLendacky, Thomas } 638c5aa9e3bSLendacky, Thomas 639c1530317SLendacky, Thomas /* Save the skb address in the last entry. We always have some data 640c1530317SLendacky, Thomas * that has been mapped so rdata is always advanced past the last 641c1530317SLendacky, Thomas * piece of mapped data - use the entry pointed to by cur_index - 1. 642c1530317SLendacky, Thomas */ 643c1530317SLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, cur_index - 1); 644c5aa9e3bSLendacky, Thomas rdata->skb = skb; 645c5aa9e3bSLendacky, Thomas 646c5aa9e3bSLendacky, Thomas /* Save the number of descriptor entries used */ 647c5aa9e3bSLendacky, Thomas packet->rdesc_count = cur_index - start_index; 648c5aa9e3bSLendacky, Thomas 649c5aa9e3bSLendacky, Thomas DBGPR("<--xgbe_map_tx_skb: count=%u\n", packet->rdesc_count); 650c5aa9e3bSLendacky, Thomas 651c5aa9e3bSLendacky, Thomas return packet->rdesc_count; 652c5aa9e3bSLendacky, Thomas 653c5aa9e3bSLendacky, Thomas err_out: 654c5aa9e3bSLendacky, Thomas while (start_index < cur_index) { 655d0a8ba6cSLendacky, Thomas rdata = XGBE_GET_DESC_DATA(ring, start_index++); 65608dcc47cSLendacky, Thomas xgbe_unmap_rdata(pdata, rdata); 657c5aa9e3bSLendacky, Thomas } 658c5aa9e3bSLendacky, Thomas 659c5aa9e3bSLendacky, Thomas DBGPR("<--xgbe_map_tx_skb: count=0\n"); 660c5aa9e3bSLendacky, Thomas 661c5aa9e3bSLendacky, Thomas return 0; 662c5aa9e3bSLendacky, Thomas } 663c5aa9e3bSLendacky, Thomas 664c5aa9e3bSLendacky, Thomas void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if) 665c5aa9e3bSLendacky, Thomas { 666c5aa9e3bSLendacky, Thomas DBGPR("-->xgbe_init_function_ptrs_desc\n"); 667c5aa9e3bSLendacky, Thomas 668c5aa9e3bSLendacky, Thomas desc_if->alloc_ring_resources = xgbe_alloc_ring_resources; 669c5aa9e3bSLendacky, Thomas desc_if->free_ring_resources = xgbe_free_ring_resources; 670c5aa9e3bSLendacky, Thomas desc_if->map_tx_skb = xgbe_map_tx_skb; 671270894e7SLendacky, Thomas desc_if->map_rx_buffer = xgbe_map_rx_buffer; 67208dcc47cSLendacky, Thomas desc_if->unmap_rdata = xgbe_unmap_rdata; 673c5aa9e3bSLendacky, Thomas desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init; 674c5aa9e3bSLendacky, Thomas desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init; 675c5aa9e3bSLendacky, Thomas 676c5aa9e3bSLendacky, Thomas DBGPR("<--xgbe_init_function_ptrs_desc\n"); 677c5aa9e3bSLendacky, Thomas } 678