Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1 | /* |
| 2 | * AMD 10Gb Ethernet driver |
| 3 | * |
| 4 | * This file is available to you under your choice of the following two |
| 5 | * licenses: |
| 6 | * |
| 7 | * License 1: GPLv2 |
| 8 | * |
Lendacky, Thomas | b4eee84 | 2016-02-17 11:48:08 -0600 | [diff] [blame] | 9 | * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 10 | * |
| 11 | * This file is free software; you may copy, redistribute and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation, either version 2 of the License, or (at |
| 14 | * your option) any later version. |
| 15 | * |
| 16 | * This file is distributed in the hope that it will be useful, but |
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | * |
| 24 | * This file incorporates work covered by the following copyright and |
| 25 | * permission notice: |
| 26 | * The Synopsys DWC ETHER XGMAC Software Driver and documentation |
| 27 | * (hereinafter "Software") is an unsupported proprietary work of Synopsys, |
| 28 | * Inc. unless otherwise expressly agreed to in writing between Synopsys |
| 29 | * and you. |
| 30 | * |
| 31 | * The Software IS NOT an item of Licensed Software or Licensed Product |
| 32 | * under any End User Software License Agreement or Agreement for Licensed |
| 33 | * Product with Synopsys or any supplement thereto. Permission is hereby |
| 34 | * granted, free of charge, to any person obtaining a copy of this software |
| 35 | * annotated with this license and the Software, to deal in the Software |
| 36 | * without restriction, including without limitation the rights to use, |
| 37 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 38 | * of the Software, and to permit persons to whom the Software is furnished |
| 39 | * to do so, subject to the following conditions: |
| 40 | * |
| 41 | * The above copyright notice and this permission notice shall be included |
| 42 | * in all copies or substantial portions of the Software. |
| 43 | * |
| 44 | * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" |
| 45 | * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 47 | * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS |
| 48 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 49 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 50 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 51 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 52 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 53 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 54 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 55 | * |
| 56 | * |
| 57 | * License 2: Modified BSD |
| 58 | * |
Lendacky, Thomas | b4eee84 | 2016-02-17 11:48:08 -0600 | [diff] [blame] | 59 | * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 60 | * All rights reserved. |
| 61 | * |
| 62 | * Redistribution and use in source and binary forms, with or without |
| 63 | * modification, are permitted provided that the following conditions are met: |
| 64 | * * Redistributions of source code must retain the above copyright |
| 65 | * notice, this list of conditions and the following disclaimer. |
| 66 | * * Redistributions in binary form must reproduce the above copyright |
| 67 | * notice, this list of conditions and the following disclaimer in the |
| 68 | * documentation and/or other materials provided with the distribution. |
| 69 | * * Neither the name of Advanced Micro Devices, Inc. nor the |
| 70 | * names of its contributors may be used to endorse or promote products |
| 71 | * derived from this software without specific prior written permission. |
| 72 | * |
| 73 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 74 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 75 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 76 | * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY |
| 77 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 78 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 79 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 80 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 81 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 82 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 83 | * |
| 84 | * This file incorporates work covered by the following copyright and |
| 85 | * permission notice: |
| 86 | * The Synopsys DWC ETHER XGMAC Software Driver and documentation |
| 87 | * (hereinafter "Software") is an unsupported proprietary work of Synopsys, |
| 88 | * Inc. unless otherwise expressly agreed to in writing between Synopsys |
| 89 | * and you. |
| 90 | * |
| 91 | * The Software IS NOT an item of Licensed Software or Licensed Product |
| 92 | * under any End User Software License Agreement or Agreement for Licensed |
| 93 | * Product with Synopsys or any supplement thereto. Permission is hereby |
| 94 | * granted, free of charge, to any person obtaining a copy of this software |
| 95 | * annotated with this license and the Software, to deal in the Software |
| 96 | * without restriction, including without limitation the rights to use, |
| 97 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 98 | * of the Software, and to permit persons to whom the Software is furnished |
| 99 | * to do so, subject to the following conditions: |
| 100 | * |
| 101 | * The above copyright notice and this permission notice shall be included |
| 102 | * in all copies or substantial portions of the Software. |
| 103 | * |
| 104 | * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" |
| 105 | * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 106 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 107 | * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS |
| 108 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 109 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 110 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 111 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 112 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 113 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 114 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 115 | */ |
| 116 | |
| 117 | #include <linux/phy.h> |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 118 | #include <linux/mdio.h> |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 119 | #include <linux/clk.h> |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 120 | #include <linux/bitrev.h> |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 121 | #include <linux/crc32.h> |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 122 | |
| 123 | #include "xgbe.h" |
| 124 | #include "xgbe-common.h" |
| 125 | |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 126 | static inline unsigned int xgbe_get_max_frame(struct xgbe_prv_data *pdata) |
| 127 | { |
| 128 | return pdata->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
| 129 | } |
| 130 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 131 | static unsigned int xgbe_usec_to_riwt(struct xgbe_prv_data *pdata, |
| 132 | unsigned int usec) |
| 133 | { |
| 134 | unsigned long rate; |
| 135 | unsigned int ret; |
| 136 | |
| 137 | DBGPR("-->xgbe_usec_to_riwt\n"); |
| 138 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 139 | rate = pdata->sysclk_rate; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 140 | |
| 141 | /* |
| 142 | * Convert the input usec value to the watchdog timer value. Each |
| 143 | * watchdog timer value is equivalent to 256 clock cycles. |
| 144 | * Calculate the required value as: |
| 145 | * ( usec * ( system_clock_mhz / 10^6 ) / 256 |
| 146 | */ |
| 147 | ret = (usec * (rate / 1000000)) / 256; |
| 148 | |
| 149 | DBGPR("<--xgbe_usec_to_riwt\n"); |
| 150 | |
| 151 | return ret; |
| 152 | } |
| 153 | |
| 154 | static unsigned int xgbe_riwt_to_usec(struct xgbe_prv_data *pdata, |
| 155 | unsigned int riwt) |
| 156 | { |
| 157 | unsigned long rate; |
| 158 | unsigned int ret; |
| 159 | |
| 160 | DBGPR("-->xgbe_riwt_to_usec\n"); |
| 161 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 162 | rate = pdata->sysclk_rate; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 163 | |
| 164 | /* |
| 165 | * Convert the input watchdog timer value to the usec value. Each |
| 166 | * watchdog timer value is equivalent to 256 clock cycles. |
| 167 | * Calculate the required value as: |
| 168 | * ( riwt * 256 ) / ( system_clock_mhz / 10^6 ) |
| 169 | */ |
| 170 | ret = (riwt * 256) / (rate / 1000000); |
| 171 | |
| 172 | DBGPR("<--xgbe_riwt_to_usec\n"); |
| 173 | |
| 174 | return ret; |
| 175 | } |
| 176 | |
| 177 | static int xgbe_config_pblx8(struct xgbe_prv_data *pdata) |
| 178 | { |
| 179 | struct xgbe_channel *channel; |
| 180 | unsigned int i; |
| 181 | |
| 182 | channel = pdata->channel; |
| 183 | for (i = 0; i < pdata->channel_count; i++, channel++) |
| 184 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, PBLX8, |
| 185 | pdata->pblx8); |
| 186 | |
| 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | static int xgbe_get_tx_pbl_val(struct xgbe_prv_data *pdata) |
| 191 | { |
| 192 | return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_TCR, PBL); |
| 193 | } |
| 194 | |
| 195 | static int xgbe_config_tx_pbl_val(struct xgbe_prv_data *pdata) |
| 196 | { |
| 197 | struct xgbe_channel *channel; |
| 198 | unsigned int i; |
| 199 | |
| 200 | channel = pdata->channel; |
| 201 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 202 | if (!channel->tx_ring) |
| 203 | break; |
| 204 | |
| 205 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, PBL, |
| 206 | pdata->tx_pbl); |
| 207 | } |
| 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | static int xgbe_get_rx_pbl_val(struct xgbe_prv_data *pdata) |
| 213 | { |
| 214 | return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_RCR, PBL); |
| 215 | } |
| 216 | |
| 217 | static int xgbe_config_rx_pbl_val(struct xgbe_prv_data *pdata) |
| 218 | { |
| 219 | struct xgbe_channel *channel; |
| 220 | unsigned int i; |
| 221 | |
| 222 | channel = pdata->channel; |
| 223 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 224 | if (!channel->rx_ring) |
| 225 | break; |
| 226 | |
| 227 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, PBL, |
| 228 | pdata->rx_pbl); |
| 229 | } |
| 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | static int xgbe_config_osp_mode(struct xgbe_prv_data *pdata) |
| 235 | { |
| 236 | struct xgbe_channel *channel; |
| 237 | unsigned int i; |
| 238 | |
| 239 | channel = pdata->channel; |
| 240 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 241 | if (!channel->tx_ring) |
| 242 | break; |
| 243 | |
| 244 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, OSP, |
| 245 | pdata->tx_osp_mode); |
| 246 | } |
| 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | static int xgbe_config_rsf_mode(struct xgbe_prv_data *pdata, unsigned int val) |
| 252 | { |
| 253 | unsigned int i; |
| 254 | |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 255 | for (i = 0; i < pdata->rx_q_count; i++) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 256 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RSF, val); |
| 257 | |
| 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | static int xgbe_config_tsf_mode(struct xgbe_prv_data *pdata, unsigned int val) |
| 262 | { |
| 263 | unsigned int i; |
| 264 | |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 265 | for (i = 0; i < pdata->tx_q_count; i++) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 266 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TSF, val); |
| 267 | |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | static int xgbe_config_rx_threshold(struct xgbe_prv_data *pdata, |
| 272 | unsigned int val) |
| 273 | { |
| 274 | unsigned int i; |
| 275 | |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 276 | for (i = 0; i < pdata->rx_q_count; i++) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 277 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RTC, val); |
| 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | static int xgbe_config_tx_threshold(struct xgbe_prv_data *pdata, |
| 283 | unsigned int val) |
| 284 | { |
| 285 | unsigned int i; |
| 286 | |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 287 | for (i = 0; i < pdata->tx_q_count; i++) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 288 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TTC, val); |
| 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | static int xgbe_config_rx_coalesce(struct xgbe_prv_data *pdata) |
| 294 | { |
| 295 | struct xgbe_channel *channel; |
| 296 | unsigned int i; |
| 297 | |
| 298 | channel = pdata->channel; |
| 299 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 300 | if (!channel->rx_ring) |
| 301 | break; |
| 302 | |
| 303 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RIWT, RWT, |
| 304 | pdata->rx_riwt); |
| 305 | } |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | static int xgbe_config_tx_coalesce(struct xgbe_prv_data *pdata) |
| 311 | { |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | static void xgbe_config_rx_buffer_size(struct xgbe_prv_data *pdata) |
| 316 | { |
| 317 | struct xgbe_channel *channel; |
| 318 | unsigned int i; |
| 319 | |
| 320 | channel = pdata->channel; |
| 321 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 322 | if (!channel->rx_ring) |
| 323 | break; |
| 324 | |
| 325 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, RBSZ, |
| 326 | pdata->rx_buf_size); |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | static void xgbe_config_tso_mode(struct xgbe_prv_data *pdata) |
| 331 | { |
| 332 | struct xgbe_channel *channel; |
| 333 | unsigned int i; |
| 334 | |
| 335 | channel = pdata->channel; |
| 336 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 337 | if (!channel->tx_ring) |
| 338 | break; |
| 339 | |
| 340 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, TSE, 1); |
| 341 | } |
| 342 | } |
| 343 | |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 344 | static void xgbe_config_sph_mode(struct xgbe_prv_data *pdata) |
| 345 | { |
| 346 | struct xgbe_channel *channel; |
| 347 | unsigned int i; |
| 348 | |
| 349 | channel = pdata->channel; |
| 350 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 351 | if (!channel->rx_ring) |
| 352 | break; |
| 353 | |
| 354 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, SPH, 1); |
| 355 | } |
| 356 | |
| 357 | XGMAC_IOWRITE_BITS(pdata, MAC_RCR, HDSMS, XGBE_SPH_HDSMS_SIZE); |
| 358 | } |
| 359 | |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 360 | static int xgbe_write_rss_reg(struct xgbe_prv_data *pdata, unsigned int type, |
| 361 | unsigned int index, unsigned int val) |
| 362 | { |
| 363 | unsigned int wait; |
| 364 | int ret = 0; |
| 365 | |
| 366 | mutex_lock(&pdata->rss_mutex); |
| 367 | |
| 368 | if (XGMAC_IOREAD_BITS(pdata, MAC_RSSAR, OB)) { |
| 369 | ret = -EBUSY; |
| 370 | goto unlock; |
| 371 | } |
| 372 | |
| 373 | XGMAC_IOWRITE(pdata, MAC_RSSDR, val); |
| 374 | |
| 375 | XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, RSSIA, index); |
| 376 | XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, ADDRT, type); |
| 377 | XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, CT, 0); |
| 378 | XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, OB, 1); |
| 379 | |
| 380 | wait = 1000; |
| 381 | while (wait--) { |
| 382 | if (!XGMAC_IOREAD_BITS(pdata, MAC_RSSAR, OB)) |
| 383 | goto unlock; |
| 384 | |
| 385 | usleep_range(1000, 1500); |
| 386 | } |
| 387 | |
| 388 | ret = -EBUSY; |
| 389 | |
| 390 | unlock: |
| 391 | mutex_unlock(&pdata->rss_mutex); |
| 392 | |
| 393 | return ret; |
| 394 | } |
| 395 | |
| 396 | static int xgbe_write_rss_hash_key(struct xgbe_prv_data *pdata) |
| 397 | { |
| 398 | unsigned int key_regs = sizeof(pdata->rss_key) / sizeof(u32); |
| 399 | unsigned int *key = (unsigned int *)&pdata->rss_key; |
| 400 | int ret; |
| 401 | |
| 402 | while (key_regs--) { |
| 403 | ret = xgbe_write_rss_reg(pdata, XGBE_RSS_HASH_KEY_TYPE, |
| 404 | key_regs, *key++); |
| 405 | if (ret) |
| 406 | return ret; |
| 407 | } |
| 408 | |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | static int xgbe_write_rss_lookup_table(struct xgbe_prv_data *pdata) |
| 413 | { |
| 414 | unsigned int i; |
| 415 | int ret; |
| 416 | |
| 417 | for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++) { |
| 418 | ret = xgbe_write_rss_reg(pdata, |
| 419 | XGBE_RSS_LOOKUP_TABLE_TYPE, i, |
| 420 | pdata->rss_table[i]); |
| 421 | if (ret) |
| 422 | return ret; |
| 423 | } |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
Lendacky, Thomas | f6ac862 | 2014-11-04 16:07:23 -0600 | [diff] [blame] | 428 | static int xgbe_set_rss_hash_key(struct xgbe_prv_data *pdata, const u8 *key) |
| 429 | { |
| 430 | memcpy(pdata->rss_key, key, sizeof(pdata->rss_key)); |
| 431 | |
| 432 | return xgbe_write_rss_hash_key(pdata); |
| 433 | } |
| 434 | |
| 435 | static int xgbe_set_rss_lookup_table(struct xgbe_prv_data *pdata, |
| 436 | const u32 *table) |
| 437 | { |
| 438 | unsigned int i; |
| 439 | |
| 440 | for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++) |
| 441 | XGMAC_SET_BITS(pdata->rss_table[i], MAC_RSSDR, DMCH, table[i]); |
| 442 | |
| 443 | return xgbe_write_rss_lookup_table(pdata); |
| 444 | } |
| 445 | |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 446 | static int xgbe_enable_rss(struct xgbe_prv_data *pdata) |
| 447 | { |
| 448 | int ret; |
| 449 | |
| 450 | if (!pdata->hw_feat.rss) |
| 451 | return -EOPNOTSUPP; |
| 452 | |
| 453 | /* Program the hash key */ |
| 454 | ret = xgbe_write_rss_hash_key(pdata); |
| 455 | if (ret) |
| 456 | return ret; |
| 457 | |
| 458 | /* Program the lookup table */ |
| 459 | ret = xgbe_write_rss_lookup_table(pdata); |
| 460 | if (ret) |
| 461 | return ret; |
| 462 | |
| 463 | /* Set the RSS options */ |
| 464 | XGMAC_IOWRITE(pdata, MAC_RSSCR, pdata->rss_options); |
| 465 | |
| 466 | /* Enable RSS */ |
| 467 | XGMAC_IOWRITE_BITS(pdata, MAC_RSSCR, RSSE, 1); |
| 468 | |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | static int xgbe_disable_rss(struct xgbe_prv_data *pdata) |
| 473 | { |
| 474 | if (!pdata->hw_feat.rss) |
| 475 | return -EOPNOTSUPP; |
| 476 | |
| 477 | XGMAC_IOWRITE_BITS(pdata, MAC_RSSCR, RSSE, 0); |
| 478 | |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | static void xgbe_config_rss(struct xgbe_prv_data *pdata) |
| 483 | { |
| 484 | int ret; |
| 485 | |
| 486 | if (!pdata->hw_feat.rss) |
| 487 | return; |
| 488 | |
| 489 | if (pdata->netdev->features & NETIF_F_RXHASH) |
| 490 | ret = xgbe_enable_rss(pdata); |
| 491 | else |
| 492 | ret = xgbe_disable_rss(pdata); |
| 493 | |
| 494 | if (ret) |
| 495 | netdev_err(pdata->netdev, |
| 496 | "error configuring RSS, RSS disabled\n"); |
| 497 | } |
| 498 | |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 499 | static bool xgbe_is_pfc_queue(struct xgbe_prv_data *pdata, |
| 500 | unsigned int queue) |
| 501 | { |
| 502 | unsigned int prio, tc; |
| 503 | |
| 504 | for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) { |
| 505 | /* Does this queue handle the priority? */ |
| 506 | if (pdata->prio2q_map[prio] != queue) |
| 507 | continue; |
| 508 | |
| 509 | /* Get the Traffic Class for this priority */ |
| 510 | tc = pdata->ets->prio_tc[prio]; |
| 511 | |
| 512 | /* Check if PFC is enabled for this traffic class */ |
| 513 | if (pdata->pfc->pfc_en & (1 << tc)) |
| 514 | return true; |
| 515 | } |
| 516 | |
| 517 | return false; |
| 518 | } |
| 519 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 520 | static int xgbe_disable_tx_flow_control(struct xgbe_prv_data *pdata) |
| 521 | { |
| 522 | unsigned int max_q_count, q_count; |
| 523 | unsigned int reg, reg_val; |
| 524 | unsigned int i; |
| 525 | |
| 526 | /* Clear MTL flow control */ |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 527 | for (i = 0; i < pdata->rx_q_count; i++) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 528 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 0); |
| 529 | |
| 530 | /* Clear MAC flow control */ |
| 531 | max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES; |
Lendacky, Thomas | 9fc69af | 2014-08-29 13:17:08 -0500 | [diff] [blame] | 532 | q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 533 | reg = MAC_Q0TFCR; |
| 534 | for (i = 0; i < q_count; i++) { |
| 535 | reg_val = XGMAC_IOREAD(pdata, reg); |
| 536 | XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 0); |
| 537 | XGMAC_IOWRITE(pdata, reg, reg_val); |
| 538 | |
| 539 | reg += MAC_QTFCR_INC; |
| 540 | } |
| 541 | |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | static int xgbe_enable_tx_flow_control(struct xgbe_prv_data *pdata) |
| 546 | { |
Lendacky, Thomas | 8dba2a2 | 2016-02-17 11:48:48 -0600 | [diff] [blame] | 547 | struct ieee_pfc *pfc = pdata->pfc; |
| 548 | struct ieee_ets *ets = pdata->ets; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 549 | unsigned int max_q_count, q_count; |
| 550 | unsigned int reg, reg_val; |
| 551 | unsigned int i; |
| 552 | |
| 553 | /* Set MTL flow control */ |
Lendacky, Thomas | 8dba2a2 | 2016-02-17 11:48:48 -0600 | [diff] [blame] | 554 | for (i = 0; i < pdata->rx_q_count; i++) { |
| 555 | unsigned int ehfc = 0; |
| 556 | |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 557 | if (pdata->rx_rfd[i]) { |
| 558 | /* Flow control thresholds are established */ |
| 559 | if (pfc && ets) { |
| 560 | if (xgbe_is_pfc_queue(pdata, i)) |
Lendacky, Thomas | 8dba2a2 | 2016-02-17 11:48:48 -0600 | [diff] [blame] | 561 | ehfc = 1; |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 562 | } else { |
| 563 | ehfc = 1; |
Lendacky, Thomas | 8dba2a2 | 2016-02-17 11:48:48 -0600 | [diff] [blame] | 564 | } |
Lendacky, Thomas | 8dba2a2 | 2016-02-17 11:48:48 -0600 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, ehfc); |
| 568 | |
| 569 | netif_dbg(pdata, drv, pdata->netdev, |
| 570 | "flow control %s for RXq%u\n", |
| 571 | ehfc ? "enabled" : "disabled", i); |
| 572 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 573 | |
| 574 | /* Set MAC flow control */ |
| 575 | max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES; |
Lendacky, Thomas | 9fc69af | 2014-08-29 13:17:08 -0500 | [diff] [blame] | 576 | q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 577 | reg = MAC_Q0TFCR; |
| 578 | for (i = 0; i < q_count; i++) { |
| 579 | reg_val = XGMAC_IOREAD(pdata, reg); |
| 580 | |
| 581 | /* Enable transmit flow control */ |
| 582 | XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 1); |
| 583 | /* Set pause time */ |
| 584 | XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, 0xffff); |
| 585 | |
| 586 | XGMAC_IOWRITE(pdata, reg, reg_val); |
| 587 | |
| 588 | reg += MAC_QTFCR_INC; |
| 589 | } |
| 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | static int xgbe_disable_rx_flow_control(struct xgbe_prv_data *pdata) |
| 595 | { |
| 596 | XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 0); |
| 597 | |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | static int xgbe_enable_rx_flow_control(struct xgbe_prv_data *pdata) |
| 602 | { |
| 603 | XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 1); |
| 604 | |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | static int xgbe_config_tx_flow_control(struct xgbe_prv_data *pdata) |
| 609 | { |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 610 | struct ieee_pfc *pfc = pdata->pfc; |
| 611 | |
| 612 | if (pdata->tx_pause || (pfc && pfc->pfc_en)) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 613 | xgbe_enable_tx_flow_control(pdata); |
| 614 | else |
| 615 | xgbe_disable_tx_flow_control(pdata); |
| 616 | |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | static int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata) |
| 621 | { |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 622 | struct ieee_pfc *pfc = pdata->pfc; |
| 623 | |
| 624 | if (pdata->rx_pause || (pfc && pfc->pfc_en)) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 625 | xgbe_enable_rx_flow_control(pdata); |
| 626 | else |
| 627 | xgbe_disable_rx_flow_control(pdata); |
| 628 | |
| 629 | return 0; |
| 630 | } |
| 631 | |
| 632 | static void xgbe_config_flow_control(struct xgbe_prv_data *pdata) |
| 633 | { |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 634 | struct ieee_pfc *pfc = pdata->pfc; |
| 635 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 636 | xgbe_config_tx_flow_control(pdata); |
| 637 | xgbe_config_rx_flow_control(pdata); |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 638 | |
| 639 | XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, |
| 640 | (pfc && pfc->pfc_en) ? 1 : 0); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | static void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata) |
| 644 | { |
| 645 | struct xgbe_channel *channel; |
| 646 | unsigned int dma_ch_isr, dma_ch_ier; |
| 647 | unsigned int i; |
| 648 | |
| 649 | channel = pdata->channel; |
| 650 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 651 | /* Clear all the interrupts which are set */ |
| 652 | dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR); |
| 653 | XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr); |
| 654 | |
| 655 | /* Clear all interrupt enable bits */ |
| 656 | dma_ch_ier = 0; |
| 657 | |
| 658 | /* Enable following interrupts |
| 659 | * NIE - Normal Interrupt Summary Enable |
| 660 | * AIE - Abnormal Interrupt Summary Enable |
| 661 | * FBEE - Fatal Bus Error Enable |
| 662 | */ |
| 663 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, NIE, 1); |
| 664 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, AIE, 1); |
| 665 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1); |
| 666 | |
| 667 | if (channel->tx_ring) { |
| 668 | /* Enable the following Tx interrupts |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 669 | * TIE - Transmit Interrupt Enable (unless using |
| 670 | * per channel interrupts) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 671 | */ |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 672 | if (!pdata->per_channel_irq) |
| 673 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 674 | } |
| 675 | if (channel->rx_ring) { |
| 676 | /* Enable following Rx interrupts |
| 677 | * RBUE - Receive Buffer Unavailable Enable |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 678 | * RIE - Receive Interrupt Enable (unless using |
| 679 | * per channel interrupts) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 680 | */ |
| 681 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1); |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 682 | if (!pdata->per_channel_irq) |
| 683 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | static void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata) |
| 691 | { |
| 692 | unsigned int mtl_q_isr; |
| 693 | unsigned int q_count, i; |
| 694 | |
| 695 | q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt); |
| 696 | for (i = 0; i < q_count; i++) { |
| 697 | /* Clear all the interrupts which are set */ |
| 698 | mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR); |
| 699 | XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr); |
| 700 | |
| 701 | /* No MTL interrupts to be enabled */ |
Lendacky, Thomas | 91f8734 | 2014-07-02 13:04:34 -0500 | [diff] [blame] | 702 | XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_IER, 0); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | |
| 706 | static void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata) |
| 707 | { |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 708 | unsigned int mac_ier = 0; |
| 709 | |
| 710 | /* Enable Timestamp interrupt */ |
| 711 | XGMAC_SET_BITS(mac_ier, MAC_IER, TSIE, 1); |
| 712 | |
| 713 | XGMAC_IOWRITE(pdata, MAC_IER, mac_ier); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 714 | |
| 715 | /* Enable all counter interrupts */ |
Lendacky, Thomas | a3ba7c9 | 2014-09-05 18:02:36 -0500 | [diff] [blame] | 716 | XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xffffffff); |
| 717 | XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xffffffff); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 718 | } |
| 719 | |
Lendacky, Thomas | e57f7a3 | 2016-11-03 13:18:27 -0500 | [diff] [blame] | 720 | static int xgbe_set_speed(struct xgbe_prv_data *pdata, int speed) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 721 | { |
Lendacky, Thomas | e57f7a3 | 2016-11-03 13:18:27 -0500 | [diff] [blame] | 722 | unsigned int ss; |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 723 | |
Lendacky, Thomas | e57f7a3 | 2016-11-03 13:18:27 -0500 | [diff] [blame] | 724 | switch (speed) { |
| 725 | case SPEED_1000: |
| 726 | ss = 0x03; |
| 727 | break; |
| 728 | case SPEED_2500: |
| 729 | ss = 0x02; |
| 730 | break; |
| 731 | case SPEED_10000: |
| 732 | ss = 0x00; |
| 733 | break; |
| 734 | default: |
| 735 | return -EINVAL; |
| 736 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 737 | |
Lendacky, Thomas | e57f7a3 | 2016-11-03 13:18:27 -0500 | [diff] [blame] | 738 | if (XGMAC_IOREAD_BITS(pdata, MAC_TCR, SS) != ss) |
| 739 | XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, ss); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 740 | |
| 741 | return 0; |
| 742 | } |
| 743 | |
Lendacky, Thomas | b4eee84 | 2016-02-17 11:48:08 -0600 | [diff] [blame] | 744 | static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata) |
| 745 | { |
| 746 | /* Put the VLAN tag in the Rx descriptor */ |
| 747 | XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1); |
| 748 | |
| 749 | /* Don't check the VLAN type */ |
| 750 | XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1); |
| 751 | |
| 752 | /* Check only C-TAG (0x8100) packets */ |
| 753 | XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0); |
| 754 | |
| 755 | /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */ |
| 756 | XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0); |
| 757 | |
| 758 | /* Enable VLAN tag stripping */ |
| 759 | XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3); |
| 760 | |
| 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata) |
| 765 | { |
| 766 | XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0); |
| 767 | |
| 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | static int xgbe_enable_rx_vlan_filtering(struct xgbe_prv_data *pdata) |
| 772 | { |
| 773 | /* Enable VLAN filtering */ |
| 774 | XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1); |
| 775 | |
| 776 | /* Enable VLAN Hash Table filtering */ |
| 777 | XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTHM, 1); |
| 778 | |
| 779 | /* Disable VLAN tag inverse matching */ |
| 780 | XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTIM, 0); |
| 781 | |
| 782 | /* Only filter on the lower 12-bits of the VLAN tag */ |
| 783 | XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ETV, 1); |
| 784 | |
| 785 | /* In order for the VLAN Hash Table filtering to be effective, |
| 786 | * the VLAN tag identifier in the VLAN Tag Register must not |
| 787 | * be zero. Set the VLAN tag identifier to "1" to enable the |
| 788 | * VLAN Hash Table filtering. This implies that a VLAN tag of |
| 789 | * 1 will always pass filtering. |
| 790 | */ |
| 791 | XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VL, 1); |
| 792 | |
| 793 | return 0; |
| 794 | } |
| 795 | |
| 796 | static int xgbe_disable_rx_vlan_filtering(struct xgbe_prv_data *pdata) |
| 797 | { |
| 798 | /* Disable VLAN filtering */ |
| 799 | XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0); |
| 800 | |
| 801 | return 0; |
| 802 | } |
| 803 | |
| 804 | static u32 xgbe_vid_crc32_le(__le16 vid_le) |
| 805 | { |
| 806 | u32 poly = 0xedb88320; /* CRCPOLY_LE */ |
| 807 | u32 crc = ~0; |
| 808 | u32 temp = 0; |
| 809 | unsigned char *data = (unsigned char *)&vid_le; |
| 810 | unsigned char data_byte = 0; |
| 811 | int i, bits; |
| 812 | |
| 813 | bits = get_bitmask_order(VLAN_VID_MASK); |
| 814 | for (i = 0; i < bits; i++) { |
| 815 | if ((i % 8) == 0) |
| 816 | data_byte = data[i / 8]; |
| 817 | |
| 818 | temp = ((crc & 1) ^ data_byte) & 1; |
| 819 | crc >>= 1; |
| 820 | data_byte >>= 1; |
| 821 | |
| 822 | if (temp) |
| 823 | crc ^= poly; |
| 824 | } |
| 825 | |
| 826 | return crc; |
| 827 | } |
| 828 | |
| 829 | static int xgbe_update_vlan_hash_table(struct xgbe_prv_data *pdata) |
| 830 | { |
| 831 | u32 crc; |
| 832 | u16 vid; |
| 833 | __le16 vid_le; |
| 834 | u16 vlan_hash_table = 0; |
| 835 | |
| 836 | /* Generate the VLAN Hash Table value */ |
| 837 | for_each_set_bit(vid, pdata->active_vlans, VLAN_N_VID) { |
| 838 | /* Get the CRC32 value of the VLAN ID */ |
| 839 | vid_le = cpu_to_le16(vid); |
| 840 | crc = bitrev32(~xgbe_vid_crc32_le(vid_le)) >> 28; |
| 841 | |
| 842 | vlan_hash_table |= (1 << crc); |
| 843 | } |
| 844 | |
| 845 | /* Set the VLAN Hash Table filtering register */ |
| 846 | XGMAC_IOWRITE_BITS(pdata, MAC_VLANHTR, VLHT, vlan_hash_table); |
| 847 | |
| 848 | return 0; |
| 849 | } |
| 850 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 851 | static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata, |
| 852 | unsigned int enable) |
| 853 | { |
| 854 | unsigned int val = enable ? 1 : 0; |
| 855 | |
| 856 | if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val) |
| 857 | return 0; |
| 858 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 859 | netif_dbg(pdata, drv, pdata->netdev, "%s promiscuous mode\n", |
| 860 | enable ? "entering" : "leaving"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 861 | XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val); |
| 862 | |
Lendacky, Thomas | b4eee84 | 2016-02-17 11:48:08 -0600 | [diff] [blame] | 863 | /* Hardware will still perform VLAN filtering in promiscuous mode */ |
| 864 | if (enable) { |
| 865 | xgbe_disable_rx_vlan_filtering(pdata); |
| 866 | } else { |
| 867 | if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER) |
| 868 | xgbe_enable_rx_vlan_filtering(pdata); |
| 869 | } |
| 870 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 871 | return 0; |
| 872 | } |
| 873 | |
| 874 | static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata, |
| 875 | unsigned int enable) |
| 876 | { |
| 877 | unsigned int val = enable ? 1 : 0; |
| 878 | |
| 879 | if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val) |
| 880 | return 0; |
| 881 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 882 | netif_dbg(pdata, drv, pdata->netdev, "%s allmulti mode\n", |
| 883 | enable ? "entering" : "leaving"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 884 | XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val); |
| 885 | |
| 886 | return 0; |
| 887 | } |
| 888 | |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 889 | static void xgbe_set_mac_reg(struct xgbe_prv_data *pdata, |
| 890 | struct netdev_hw_addr *ha, unsigned int *mac_reg) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 891 | { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 892 | unsigned int mac_addr_hi, mac_addr_lo; |
| 893 | u8 *mac_addr; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 894 | |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 895 | mac_addr_lo = 0; |
| 896 | mac_addr_hi = 0; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 897 | |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 898 | if (ha) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 899 | mac_addr = (u8 *)&mac_addr_lo; |
| 900 | mac_addr[0] = ha->addr[0]; |
| 901 | mac_addr[1] = ha->addr[1]; |
| 902 | mac_addr[2] = ha->addr[2]; |
| 903 | mac_addr[3] = ha->addr[3]; |
| 904 | mac_addr = (u8 *)&mac_addr_hi; |
| 905 | mac_addr[0] = ha->addr[4]; |
| 906 | mac_addr[1] = ha->addr[5]; |
| 907 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 908 | netif_dbg(pdata, drv, pdata->netdev, |
| 909 | "adding mac address %pM at %#x\n", |
| 910 | ha->addr, *mac_reg); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 911 | |
| 912 | XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 913 | } |
| 914 | |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 915 | XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_hi); |
| 916 | *mac_reg += MAC_MACA_INC; |
| 917 | XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_lo); |
| 918 | *mac_reg += MAC_MACA_INC; |
| 919 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 920 | |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 921 | static void xgbe_set_mac_addn_addrs(struct xgbe_prv_data *pdata) |
| 922 | { |
| 923 | struct net_device *netdev = pdata->netdev; |
| 924 | struct netdev_hw_addr *ha; |
| 925 | unsigned int mac_reg; |
| 926 | unsigned int addn_macs; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 927 | |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 928 | mac_reg = MAC_MACA1HR; |
| 929 | addn_macs = pdata->hw_feat.addn_mac; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 930 | |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 931 | if (netdev_uc_count(netdev) > addn_macs) { |
| 932 | xgbe_set_promiscuous_mode(pdata, 1); |
| 933 | } else { |
| 934 | netdev_for_each_uc_addr(ha, netdev) { |
| 935 | xgbe_set_mac_reg(pdata, ha, &mac_reg); |
| 936 | addn_macs--; |
| 937 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 938 | |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 939 | if (netdev_mc_count(netdev) > addn_macs) { |
| 940 | xgbe_set_all_multicast_mode(pdata, 1); |
| 941 | } else { |
| 942 | netdev_for_each_mc_addr(ha, netdev) { |
| 943 | xgbe_set_mac_reg(pdata, ha, &mac_reg); |
| 944 | addn_macs--; |
| 945 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 946 | } |
| 947 | } |
| 948 | |
| 949 | /* Clear remaining additional MAC address entries */ |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 950 | while (addn_macs--) |
| 951 | xgbe_set_mac_reg(pdata, NULL, &mac_reg); |
| 952 | } |
| 953 | |
| 954 | static void xgbe_set_mac_hash_table(struct xgbe_prv_data *pdata) |
| 955 | { |
| 956 | struct net_device *netdev = pdata->netdev; |
| 957 | struct netdev_hw_addr *ha; |
| 958 | unsigned int hash_reg; |
| 959 | unsigned int hash_table_shift, hash_table_count; |
| 960 | u32 hash_table[XGBE_MAC_HASH_TABLE_SIZE]; |
| 961 | u32 crc; |
| 962 | unsigned int i; |
| 963 | |
| 964 | hash_table_shift = 26 - (pdata->hw_feat.hash_table_size >> 7); |
| 965 | hash_table_count = pdata->hw_feat.hash_table_size / 32; |
| 966 | memset(hash_table, 0, sizeof(hash_table)); |
| 967 | |
| 968 | /* Build the MAC Hash Table register values */ |
| 969 | netdev_for_each_uc_addr(ha, netdev) { |
| 970 | crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN)); |
| 971 | crc >>= hash_table_shift; |
| 972 | hash_table[crc >> 5] |= (1 << (crc & 0x1f)); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 973 | } |
| 974 | |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 975 | netdev_for_each_mc_addr(ha, netdev) { |
| 976 | crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN)); |
| 977 | crc >>= hash_table_shift; |
| 978 | hash_table[crc >> 5] |= (1 << (crc & 0x1f)); |
| 979 | } |
| 980 | |
| 981 | /* Set the MAC Hash Table registers */ |
| 982 | hash_reg = MAC_HTR0; |
| 983 | for (i = 0; i < hash_table_count; i++) { |
| 984 | XGMAC_IOWRITE(pdata, hash_reg, hash_table[i]); |
| 985 | hash_reg += MAC_HTR_INC; |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | static int xgbe_add_mac_addresses(struct xgbe_prv_data *pdata) |
| 990 | { |
| 991 | if (pdata->hw_feat.hash_table_size) |
| 992 | xgbe_set_mac_hash_table(pdata); |
| 993 | else |
| 994 | xgbe_set_mac_addn_addrs(pdata); |
| 995 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 996 | return 0; |
| 997 | } |
| 998 | |
| 999 | static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr) |
| 1000 | { |
| 1001 | unsigned int mac_addr_hi, mac_addr_lo; |
| 1002 | |
| 1003 | mac_addr_hi = (addr[5] << 8) | (addr[4] << 0); |
| 1004 | mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) | |
| 1005 | (addr[1] << 8) | (addr[0] << 0); |
| 1006 | |
| 1007 | XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi); |
| 1008 | XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo); |
| 1009 | |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
Lendacky, Thomas | b876382 | 2015-04-09 12:11:57 -0500 | [diff] [blame] | 1013 | static int xgbe_config_rx_mode(struct xgbe_prv_data *pdata) |
| 1014 | { |
| 1015 | struct net_device *netdev = pdata->netdev; |
| 1016 | unsigned int pr_mode, am_mode; |
| 1017 | |
| 1018 | pr_mode = ((netdev->flags & IFF_PROMISC) != 0); |
| 1019 | am_mode = ((netdev->flags & IFF_ALLMULTI) != 0); |
| 1020 | |
| 1021 | xgbe_set_promiscuous_mode(pdata, pr_mode); |
| 1022 | xgbe_set_all_multicast_mode(pdata, am_mode); |
| 1023 | |
| 1024 | xgbe_add_mac_addresses(pdata); |
| 1025 | |
| 1026 | return 0; |
| 1027 | } |
| 1028 | |
Lendacky, Thomas | b03a4a6 | 2016-11-03 13:18:56 -0500 | [diff] [blame] | 1029 | static int xgbe_read_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad, |
| 1030 | int mmd_reg) |
| 1031 | { |
| 1032 | unsigned long flags; |
| 1033 | unsigned int mmd_address, index, offset; |
| 1034 | int mmd_data; |
| 1035 | |
| 1036 | if (mmd_reg & MII_ADDR_C45) |
| 1037 | mmd_address = mmd_reg & ~MII_ADDR_C45; |
| 1038 | else |
| 1039 | mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); |
| 1040 | |
| 1041 | /* The PCS registers are accessed using mmio. The underlying |
| 1042 | * management interface uses indirect addressing to access the MMD |
| 1043 | * register sets. This requires accessing of the PCS register in two |
| 1044 | * phases, an address phase and a data phase. |
| 1045 | * |
| 1046 | * The mmio interface is based on 16-bit offsets and values. All |
| 1047 | * register offsets must therefore be adjusted by left shifting the |
| 1048 | * offset 1 bit and reading 16 bits of data. |
| 1049 | */ |
| 1050 | mmd_address <<= 1; |
| 1051 | index = mmd_address & ~pdata->xpcs_window_mask; |
| 1052 | offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); |
| 1053 | |
| 1054 | spin_lock_irqsave(&pdata->xpcs_lock, flags); |
| 1055 | XPCS32_IOWRITE(pdata, PCS_V2_WINDOW_SELECT, index); |
| 1056 | mmd_data = XPCS16_IOREAD(pdata, offset); |
| 1057 | spin_unlock_irqrestore(&pdata->xpcs_lock, flags); |
| 1058 | |
| 1059 | return mmd_data; |
| 1060 | } |
| 1061 | |
| 1062 | static void xgbe_write_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad, |
| 1063 | int mmd_reg, int mmd_data) |
| 1064 | { |
| 1065 | unsigned long flags; |
| 1066 | unsigned int mmd_address, index, offset; |
| 1067 | |
| 1068 | if (mmd_reg & MII_ADDR_C45) |
| 1069 | mmd_address = mmd_reg & ~MII_ADDR_C45; |
| 1070 | else |
| 1071 | mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); |
| 1072 | |
| 1073 | /* The PCS registers are accessed using mmio. The underlying |
| 1074 | * management interface uses indirect addressing to access the MMD |
| 1075 | * register sets. This requires accessing of the PCS register in two |
| 1076 | * phases, an address phase and a data phase. |
| 1077 | * |
| 1078 | * The mmio interface is based on 16-bit offsets and values. All |
| 1079 | * register offsets must therefore be adjusted by left shifting the |
| 1080 | * offset 1 bit and writing 16 bits of data. |
| 1081 | */ |
| 1082 | mmd_address <<= 1; |
| 1083 | index = mmd_address & ~pdata->xpcs_window_mask; |
| 1084 | offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); |
| 1085 | |
| 1086 | spin_lock_irqsave(&pdata->xpcs_lock, flags); |
| 1087 | XPCS32_IOWRITE(pdata, PCS_V2_WINDOW_SELECT, index); |
| 1088 | XPCS16_IOWRITE(pdata, offset, mmd_data); |
| 1089 | spin_unlock_irqrestore(&pdata->xpcs_lock, flags); |
| 1090 | } |
| 1091 | |
| 1092 | static int xgbe_read_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad, |
| 1093 | int mmd_reg) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1094 | { |
Lendacky, Thomas | ced3fca | 2016-02-17 11:49:28 -0600 | [diff] [blame] | 1095 | unsigned long flags; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1096 | unsigned int mmd_address; |
| 1097 | int mmd_data; |
| 1098 | |
| 1099 | if (mmd_reg & MII_ADDR_C45) |
| 1100 | mmd_address = mmd_reg & ~MII_ADDR_C45; |
| 1101 | else |
| 1102 | mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); |
| 1103 | |
| 1104 | /* The PCS registers are accessed using mmio. The underlying APB3 |
| 1105 | * management interface uses indirect addressing to access the MMD |
| 1106 | * register sets. This requires accessing of the PCS register in two |
| 1107 | * phases, an address phase and a data phase. |
| 1108 | * |
| 1109 | * The mmio interface is based on 32-bit offsets and values. All |
| 1110 | * register offsets must therefore be adjusted by left shifting the |
| 1111 | * offset 2 bits and reading 32 bits of data. |
| 1112 | */ |
Lendacky, Thomas | ced3fca | 2016-02-17 11:49:28 -0600 | [diff] [blame] | 1113 | spin_lock_irqsave(&pdata->xpcs_lock, flags); |
Lendacky, Thomas | b03a4a6 | 2016-11-03 13:18:56 -0500 | [diff] [blame] | 1114 | XPCS32_IOWRITE(pdata, PCS_V1_WINDOW_SELECT, mmd_address >> 8); |
| 1115 | mmd_data = XPCS32_IOREAD(pdata, (mmd_address & 0xff) << 2); |
Lendacky, Thomas | ced3fca | 2016-02-17 11:49:28 -0600 | [diff] [blame] | 1116 | spin_unlock_irqrestore(&pdata->xpcs_lock, flags); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1117 | |
| 1118 | return mmd_data; |
| 1119 | } |
| 1120 | |
Lendacky, Thomas | b03a4a6 | 2016-11-03 13:18:56 -0500 | [diff] [blame] | 1121 | static void xgbe_write_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad, |
| 1122 | int mmd_reg, int mmd_data) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1123 | { |
| 1124 | unsigned int mmd_address; |
Lendacky, Thomas | ced3fca | 2016-02-17 11:49:28 -0600 | [diff] [blame] | 1125 | unsigned long flags; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1126 | |
| 1127 | if (mmd_reg & MII_ADDR_C45) |
| 1128 | mmd_address = mmd_reg & ~MII_ADDR_C45; |
| 1129 | else |
| 1130 | mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); |
| 1131 | |
| 1132 | /* The PCS registers are accessed using mmio. The underlying APB3 |
| 1133 | * management interface uses indirect addressing to access the MMD |
| 1134 | * register sets. This requires accessing of the PCS register in two |
| 1135 | * phases, an address phase and a data phase. |
| 1136 | * |
| 1137 | * The mmio interface is based on 32-bit offsets and values. All |
| 1138 | * register offsets must therefore be adjusted by left shifting the |
Lendacky, Thomas | b03a4a6 | 2016-11-03 13:18:56 -0500 | [diff] [blame] | 1139 | * offset 2 bits and writing 32 bits of data. |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1140 | */ |
Lendacky, Thomas | ced3fca | 2016-02-17 11:49:28 -0600 | [diff] [blame] | 1141 | spin_lock_irqsave(&pdata->xpcs_lock, flags); |
Lendacky, Thomas | b03a4a6 | 2016-11-03 13:18:56 -0500 | [diff] [blame] | 1142 | XPCS32_IOWRITE(pdata, PCS_V1_WINDOW_SELECT, mmd_address >> 8); |
| 1143 | XPCS32_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data); |
Lendacky, Thomas | ced3fca | 2016-02-17 11:49:28 -0600 | [diff] [blame] | 1144 | spin_unlock_irqrestore(&pdata->xpcs_lock, flags); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1145 | } |
| 1146 | |
Lendacky, Thomas | b03a4a6 | 2016-11-03 13:18:56 -0500 | [diff] [blame] | 1147 | static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad, |
| 1148 | int mmd_reg) |
| 1149 | { |
| 1150 | switch (pdata->vdata->xpcs_access) { |
| 1151 | case XGBE_XPCS_ACCESS_V1: |
| 1152 | return xgbe_read_mmd_regs_v1(pdata, prtad, mmd_reg); |
| 1153 | |
| 1154 | case XGBE_XPCS_ACCESS_V2: |
| 1155 | default: |
| 1156 | return xgbe_read_mmd_regs_v2(pdata, prtad, mmd_reg); |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad, |
| 1161 | int mmd_reg, int mmd_data) |
| 1162 | { |
| 1163 | switch (pdata->vdata->xpcs_access) { |
| 1164 | case XGBE_XPCS_ACCESS_V1: |
| 1165 | return xgbe_write_mmd_regs_v1(pdata, prtad, mmd_reg, mmd_data); |
| 1166 | |
| 1167 | case XGBE_XPCS_ACCESS_V2: |
| 1168 | default: |
| 1169 | return xgbe_write_mmd_regs_v2(pdata, prtad, mmd_reg, mmd_data); |
| 1170 | } |
| 1171 | } |
| 1172 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1173 | static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc) |
| 1174 | { |
| 1175 | return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN); |
| 1176 | } |
| 1177 | |
| 1178 | static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata) |
| 1179 | { |
| 1180 | XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0); |
| 1181 | |
| 1182 | return 0; |
| 1183 | } |
| 1184 | |
| 1185 | static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata) |
| 1186 | { |
| 1187 | XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1); |
| 1188 | |
| 1189 | return 0; |
| 1190 | } |
| 1191 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1192 | static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata) |
| 1193 | { |
| 1194 | struct xgbe_ring_desc *rdesc = rdata->rdesc; |
| 1195 | |
| 1196 | /* Reset the Tx descriptor |
| 1197 | * Set buffer 1 (lo) address to zero |
| 1198 | * Set buffer 1 (hi) address to zero |
| 1199 | * Reset all other control bits (IC, TTSE, B2L & B1L) |
| 1200 | * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc) |
| 1201 | */ |
| 1202 | rdesc->desc0 = 0; |
| 1203 | rdesc->desc1 = 0; |
| 1204 | rdesc->desc2 = 0; |
| 1205 | rdesc->desc3 = 0; |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1206 | |
| 1207 | /* Make sure ownership is written to the descriptor */ |
Lendacky, Thomas | ceb8f6b | 2015-03-20 11:50:16 -0500 | [diff] [blame] | 1208 | dma_wmb(); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | static void xgbe_tx_desc_init(struct xgbe_channel *channel) |
| 1212 | { |
| 1213 | struct xgbe_ring *ring = channel->tx_ring; |
| 1214 | struct xgbe_ring_data *rdata; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1215 | int i; |
| 1216 | int start_index = ring->cur; |
| 1217 | |
| 1218 | DBGPR("-->tx_desc_init\n"); |
| 1219 | |
| 1220 | /* Initialze all descriptors */ |
| 1221 | for (i = 0; i < ring->rdesc_count; i++) { |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1222 | rdata = XGBE_GET_DESC_DATA(ring, i); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1223 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1224 | /* Initialize Tx descriptor */ |
| 1225 | xgbe_tx_desc_reset(rdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1226 | } |
| 1227 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1228 | /* Update the total number of Tx descriptors */ |
| 1229 | XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1); |
| 1230 | |
| 1231 | /* Update the starting address of descriptor ring */ |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1232 | rdata = XGBE_GET_DESC_DATA(ring, start_index); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1233 | XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI, |
| 1234 | upper_32_bits(rdata->rdesc_dma)); |
| 1235 | XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO, |
| 1236 | lower_32_bits(rdata->rdesc_dma)); |
| 1237 | |
| 1238 | DBGPR("<--tx_desc_init\n"); |
| 1239 | } |
| 1240 | |
Lendacky, Thomas | 8dee19e | 2015-04-09 12:11:51 -0500 | [diff] [blame] | 1241 | static void xgbe_rx_desc_reset(struct xgbe_prv_data *pdata, |
| 1242 | struct xgbe_ring_data *rdata, unsigned int index) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1243 | { |
| 1244 | struct xgbe_ring_desc *rdesc = rdata->rdesc; |
Lendacky, Thomas | 8dee19e | 2015-04-09 12:11:51 -0500 | [diff] [blame] | 1245 | unsigned int rx_usecs = pdata->rx_usecs; |
| 1246 | unsigned int rx_frames = pdata->rx_frames; |
| 1247 | unsigned int inte; |
Lendacky, Thomas | cfbfd86 | 2015-07-06 11:57:37 -0500 | [diff] [blame] | 1248 | dma_addr_t hdr_dma, buf_dma; |
Lendacky, Thomas | 8dee19e | 2015-04-09 12:11:51 -0500 | [diff] [blame] | 1249 | |
| 1250 | if (!rx_usecs && !rx_frames) { |
| 1251 | /* No coalescing, interrupt for every descriptor */ |
| 1252 | inte = 1; |
| 1253 | } else { |
| 1254 | /* Set interrupt based on Rx frame coalescing setting */ |
| 1255 | if (rx_frames && !((index + 1) % rx_frames)) |
| 1256 | inte = 1; |
| 1257 | else |
| 1258 | inte = 0; |
| 1259 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1260 | |
| 1261 | /* Reset the Rx descriptor |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 1262 | * Set buffer 1 (lo) address to header dma address (lo) |
| 1263 | * Set buffer 1 (hi) address to header dma address (hi) |
| 1264 | * Set buffer 2 (lo) address to buffer dma address (lo) |
| 1265 | * Set buffer 2 (hi) address to buffer dma address (hi) and |
| 1266 | * set control bits OWN and INTE |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1267 | */ |
Lendacky, Thomas | cfbfd86 | 2015-07-06 11:57:37 -0500 | [diff] [blame] | 1268 | hdr_dma = rdata->rx.hdr.dma_base + rdata->rx.hdr.dma_off; |
| 1269 | buf_dma = rdata->rx.buf.dma_base + rdata->rx.buf.dma_off; |
| 1270 | rdesc->desc0 = cpu_to_le32(lower_32_bits(hdr_dma)); |
| 1271 | rdesc->desc1 = cpu_to_le32(upper_32_bits(hdr_dma)); |
| 1272 | rdesc->desc2 = cpu_to_le32(lower_32_bits(buf_dma)); |
| 1273 | rdesc->desc3 = cpu_to_le32(upper_32_bits(buf_dma)); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1274 | |
Lendacky, Thomas | 8dee19e | 2015-04-09 12:11:51 -0500 | [diff] [blame] | 1275 | XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, inte); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1276 | |
| 1277 | /* Since the Rx DMA engine is likely running, make sure everything |
| 1278 | * is written to the descriptor(s) before setting the OWN bit |
| 1279 | * for the descriptor |
| 1280 | */ |
Lendacky, Thomas | ceb8f6b | 2015-03-20 11:50:16 -0500 | [diff] [blame] | 1281 | dma_wmb(); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1282 | |
| 1283 | XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1); |
| 1284 | |
| 1285 | /* Make sure ownership is written to the descriptor */ |
Lendacky, Thomas | ceb8f6b | 2015-03-20 11:50:16 -0500 | [diff] [blame] | 1286 | dma_wmb(); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | static void xgbe_rx_desc_init(struct xgbe_channel *channel) |
| 1290 | { |
| 1291 | struct xgbe_prv_data *pdata = channel->pdata; |
| 1292 | struct xgbe_ring *ring = channel->rx_ring; |
| 1293 | struct xgbe_ring_data *rdata; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1294 | unsigned int start_index = ring->cur; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1295 | unsigned int i; |
| 1296 | |
| 1297 | DBGPR("-->rx_desc_init\n"); |
| 1298 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1299 | /* Initialize all descriptors */ |
| 1300 | for (i = 0; i < ring->rdesc_count; i++) { |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1301 | rdata = XGBE_GET_DESC_DATA(ring, i); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1302 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1303 | /* Initialize Rx descriptor */ |
Lendacky, Thomas | 8dee19e | 2015-04-09 12:11:51 -0500 | [diff] [blame] | 1304 | xgbe_rx_desc_reset(pdata, rdata, i); |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1305 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1306 | |
| 1307 | /* Update the total number of Rx descriptors */ |
| 1308 | XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1); |
| 1309 | |
| 1310 | /* Update the starting address of descriptor ring */ |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1311 | rdata = XGBE_GET_DESC_DATA(ring, start_index); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1312 | XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI, |
| 1313 | upper_32_bits(rdata->rdesc_dma)); |
| 1314 | XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO, |
| 1315 | lower_32_bits(rdata->rdesc_dma)); |
| 1316 | |
| 1317 | /* Update the Rx Descriptor Tail Pointer */ |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1318 | rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1319 | XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO, |
| 1320 | lower_32_bits(rdata->rdesc_dma)); |
| 1321 | |
| 1322 | DBGPR("<--rx_desc_init\n"); |
| 1323 | } |
| 1324 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1325 | static void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata, |
| 1326 | unsigned int addend) |
| 1327 | { |
| 1328 | /* Set the addend register value and tell the device */ |
| 1329 | XGMAC_IOWRITE(pdata, MAC_TSAR, addend); |
| 1330 | XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1); |
| 1331 | |
| 1332 | /* Wait for addend update to complete */ |
| 1333 | while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG)) |
| 1334 | udelay(5); |
| 1335 | } |
| 1336 | |
| 1337 | static void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec, |
| 1338 | unsigned int nsec) |
| 1339 | { |
| 1340 | /* Set the time values and tell the device */ |
| 1341 | XGMAC_IOWRITE(pdata, MAC_STSUR, sec); |
| 1342 | XGMAC_IOWRITE(pdata, MAC_STNUR, nsec); |
| 1343 | XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1); |
| 1344 | |
| 1345 | /* Wait for time update to complete */ |
| 1346 | while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT)) |
| 1347 | udelay(5); |
| 1348 | } |
| 1349 | |
| 1350 | static u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata) |
| 1351 | { |
| 1352 | u64 nsec; |
| 1353 | |
| 1354 | nsec = XGMAC_IOREAD(pdata, MAC_STSR); |
| 1355 | nsec *= NSEC_PER_SEC; |
| 1356 | nsec += XGMAC_IOREAD(pdata, MAC_STNR); |
| 1357 | |
| 1358 | return nsec; |
| 1359 | } |
| 1360 | |
| 1361 | static u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata) |
| 1362 | { |
| 1363 | unsigned int tx_snr; |
| 1364 | u64 nsec; |
| 1365 | |
| 1366 | tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR); |
| 1367 | if (XGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS)) |
| 1368 | return 0; |
| 1369 | |
| 1370 | nsec = XGMAC_IOREAD(pdata, MAC_TXSSR); |
| 1371 | nsec *= NSEC_PER_SEC; |
| 1372 | nsec += tx_snr; |
| 1373 | |
| 1374 | return nsec; |
| 1375 | } |
| 1376 | |
| 1377 | static void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet, |
| 1378 | struct xgbe_ring_desc *rdesc) |
| 1379 | { |
| 1380 | u64 nsec; |
| 1381 | |
| 1382 | if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSA) && |
| 1383 | !XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSD)) { |
| 1384 | nsec = le32_to_cpu(rdesc->desc1); |
| 1385 | nsec <<= 32; |
| 1386 | nsec |= le32_to_cpu(rdesc->desc0); |
| 1387 | if (nsec != 0xffffffffffffffffULL) { |
| 1388 | packet->rx_tstamp = nsec; |
| 1389 | XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, |
| 1390 | RX_TSTAMP, 1); |
| 1391 | } |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | static int xgbe_config_tstamp(struct xgbe_prv_data *pdata, |
| 1396 | unsigned int mac_tscr) |
| 1397 | { |
| 1398 | /* Set one nano-second accuracy */ |
| 1399 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1); |
| 1400 | |
| 1401 | /* Set fine timestamp update */ |
| 1402 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1); |
| 1403 | |
| 1404 | /* Overwrite earlier timestamps */ |
| 1405 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1); |
| 1406 | |
| 1407 | XGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr); |
| 1408 | |
| 1409 | /* Exit if timestamping is not enabled */ |
| 1410 | if (!XGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA)) |
| 1411 | return 0; |
| 1412 | |
| 1413 | /* Initialize time registers */ |
| 1414 | XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, XGBE_TSTAMP_SSINC); |
| 1415 | XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, XGBE_TSTAMP_SNSINC); |
| 1416 | xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend); |
| 1417 | xgbe_set_tstamp_time(pdata, 0, 0); |
| 1418 | |
| 1419 | /* Initialize the timecounter */ |
| 1420 | timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc, |
| 1421 | ktime_to_ns(ktime_get_real())); |
| 1422 | |
| 1423 | return 0; |
| 1424 | } |
| 1425 | |
Lendacky, Thomas | 16958a2 | 2014-11-20 11:04:08 -0600 | [diff] [blame] | 1426 | static void xgbe_tx_start_xmit(struct xgbe_channel *channel, |
| 1427 | struct xgbe_ring *ring) |
| 1428 | { |
| 1429 | struct xgbe_prv_data *pdata = channel->pdata; |
| 1430 | struct xgbe_ring_data *rdata; |
| 1431 | |
Lendacky, Thomas | ceb8f6b | 2015-03-20 11:50:16 -0500 | [diff] [blame] | 1432 | /* Make sure everything is written before the register write */ |
| 1433 | wmb(); |
| 1434 | |
Lendacky, Thomas | 16958a2 | 2014-11-20 11:04:08 -0600 | [diff] [blame] | 1435 | /* Issue a poll command to Tx DMA by writing address |
| 1436 | * of next immediate free descriptor */ |
| 1437 | rdata = XGBE_GET_DESC_DATA(ring, ring->cur); |
| 1438 | XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO, |
| 1439 | lower_32_bits(rdata->rdesc_dma)); |
| 1440 | |
Lendacky, Thomas | c635eaa | 2015-03-20 11:50:28 -0500 | [diff] [blame] | 1441 | /* Start the Tx timer */ |
Lendacky, Thomas | 16958a2 | 2014-11-20 11:04:08 -0600 | [diff] [blame] | 1442 | if (pdata->tx_usecs && !channel->tx_timer_active) { |
| 1443 | channel->tx_timer_active = 1; |
Lendacky, Thomas | c635eaa | 2015-03-20 11:50:28 -0500 | [diff] [blame] | 1444 | mod_timer(&channel->tx_timer, |
| 1445 | jiffies + usecs_to_jiffies(pdata->tx_usecs)); |
Lendacky, Thomas | 16958a2 | 2014-11-20 11:04:08 -0600 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | ring->tx.xmit_more = 0; |
| 1449 | } |
| 1450 | |
Lendacky, Thomas | a9d4198 | 2014-11-04 16:06:32 -0600 | [diff] [blame] | 1451 | static void xgbe_dev_xmit(struct xgbe_channel *channel) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1452 | { |
| 1453 | struct xgbe_prv_data *pdata = channel->pdata; |
| 1454 | struct xgbe_ring *ring = channel->tx_ring; |
| 1455 | struct xgbe_ring_data *rdata; |
| 1456 | struct xgbe_ring_desc *rdesc; |
| 1457 | struct xgbe_packet_data *packet = &ring->packet_data; |
| 1458 | unsigned int csum, tso, vlan; |
| 1459 | unsigned int tso_context, vlan_context; |
Lendacky, Thomas | eb79e64 | 2014-11-20 11:04:02 -0600 | [diff] [blame] | 1460 | unsigned int tx_set_ic; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1461 | int start_index = ring->cur; |
Lendacky, Thomas | a83ef42 | 2015-01-16 12:46:55 -0600 | [diff] [blame] | 1462 | int cur_index = ring->cur; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1463 | int i; |
| 1464 | |
Lendacky, Thomas | a9d4198 | 2014-11-04 16:06:32 -0600 | [diff] [blame] | 1465 | DBGPR("-->xgbe_dev_xmit\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1466 | |
| 1467 | csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 1468 | CSUM_ENABLE); |
| 1469 | tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 1470 | TSO_ENABLE); |
| 1471 | vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 1472 | VLAN_CTAG); |
| 1473 | |
| 1474 | if (tso && (packet->mss != ring->tx.cur_mss)) |
| 1475 | tso_context = 1; |
| 1476 | else |
| 1477 | tso_context = 0; |
| 1478 | |
| 1479 | if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag)) |
| 1480 | vlan_context = 1; |
| 1481 | else |
| 1482 | vlan_context = 0; |
| 1483 | |
Lendacky, Thomas | eb79e64 | 2014-11-20 11:04:02 -0600 | [diff] [blame] | 1484 | /* Determine if an interrupt should be generated for this Tx: |
| 1485 | * Interrupt: |
| 1486 | * - Tx frame count exceeds the frame count setting |
| 1487 | * - Addition of Tx frame count to the frame count since the |
| 1488 | * last interrupt was set exceeds the frame count setting |
| 1489 | * No interrupt: |
| 1490 | * - No frame count setting specified (ethtool -C ethX tx-frames 0) |
| 1491 | * - Addition of Tx frame count to the frame count since the |
| 1492 | * last interrupt was set does not exceed the frame count setting |
| 1493 | */ |
| 1494 | ring->coalesce_count += packet->tx_packets; |
| 1495 | if (!pdata->tx_frames) |
| 1496 | tx_set_ic = 0; |
| 1497 | else if (packet->tx_packets > pdata->tx_frames) |
| 1498 | tx_set_ic = 1; |
| 1499 | else if ((ring->coalesce_count % pdata->tx_frames) < |
| 1500 | packet->tx_packets) |
| 1501 | tx_set_ic = 1; |
| 1502 | else |
| 1503 | tx_set_ic = 0; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1504 | |
Lendacky, Thomas | a83ef42 | 2015-01-16 12:46:55 -0600 | [diff] [blame] | 1505 | rdata = XGBE_GET_DESC_DATA(ring, cur_index); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1506 | rdesc = rdata->rdesc; |
| 1507 | |
| 1508 | /* Create a context descriptor if this is a TSO packet */ |
| 1509 | if (tso_context || vlan_context) { |
| 1510 | if (tso_context) { |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 1511 | netif_dbg(pdata, tx_queued, pdata->netdev, |
| 1512 | "TSO context descriptor, mss=%u\n", |
| 1513 | packet->mss); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1514 | |
| 1515 | /* Set the MSS size */ |
| 1516 | XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2, |
| 1517 | MSS, packet->mss); |
| 1518 | |
| 1519 | /* Mark it as a CONTEXT descriptor */ |
| 1520 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3, |
| 1521 | CTXT, 1); |
| 1522 | |
| 1523 | /* Indicate this descriptor contains the MSS */ |
| 1524 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3, |
| 1525 | TCMSSV, 1); |
| 1526 | |
| 1527 | ring->tx.cur_mss = packet->mss; |
| 1528 | } |
| 1529 | |
| 1530 | if (vlan_context) { |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 1531 | netif_dbg(pdata, tx_queued, pdata->netdev, |
| 1532 | "VLAN context descriptor, ctag=%u\n", |
| 1533 | packet->vlan_ctag); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1534 | |
| 1535 | /* Mark it as a CONTEXT descriptor */ |
| 1536 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3, |
| 1537 | CTXT, 1); |
| 1538 | |
| 1539 | /* Set the VLAN tag */ |
| 1540 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3, |
| 1541 | VT, packet->vlan_ctag); |
| 1542 | |
| 1543 | /* Indicate this descriptor contains the VLAN tag */ |
| 1544 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3, |
| 1545 | VLTV, 1); |
| 1546 | |
| 1547 | ring->tx.cur_vlan_ctag = packet->vlan_ctag; |
| 1548 | } |
| 1549 | |
Lendacky, Thomas | a83ef42 | 2015-01-16 12:46:55 -0600 | [diff] [blame] | 1550 | cur_index++; |
| 1551 | rdata = XGBE_GET_DESC_DATA(ring, cur_index); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1552 | rdesc = rdata->rdesc; |
| 1553 | } |
| 1554 | |
| 1555 | /* Update buffer address (for TSO this is the header) */ |
| 1556 | rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma)); |
| 1557 | rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma)); |
| 1558 | |
| 1559 | /* Update the buffer length */ |
| 1560 | XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L, |
| 1561 | rdata->skb_dma_len); |
| 1562 | |
| 1563 | /* VLAN tag insertion check */ |
| 1564 | if (vlan) |
| 1565 | XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR, |
| 1566 | TX_NORMAL_DESC2_VLAN_INSERT); |
| 1567 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1568 | /* Timestamp enablement check */ |
| 1569 | if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP)) |
| 1570 | XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, TTSE, 1); |
| 1571 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1572 | /* Mark it as First Descriptor */ |
| 1573 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1); |
| 1574 | |
| 1575 | /* Mark it as a NORMAL descriptor */ |
| 1576 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0); |
| 1577 | |
| 1578 | /* Set OWN bit if not the first descriptor */ |
Lendacky, Thomas | a83ef42 | 2015-01-16 12:46:55 -0600 | [diff] [blame] | 1579 | if (cur_index != start_index) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1580 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1); |
| 1581 | |
| 1582 | if (tso) { |
| 1583 | /* Enable TSO */ |
| 1584 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1); |
| 1585 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL, |
| 1586 | packet->tcp_payload_len); |
| 1587 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN, |
| 1588 | packet->tcp_header_len / 4); |
Lendacky, Thomas | 5452b2d | 2015-05-14 11:43:57 -0500 | [diff] [blame] | 1589 | |
| 1590 | pdata->ext_stats.tx_tso_packets++; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1591 | } else { |
| 1592 | /* Enable CRC and Pad Insertion */ |
| 1593 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0); |
| 1594 | |
| 1595 | /* Enable HW CSUM */ |
| 1596 | if (csum) |
| 1597 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, |
| 1598 | CIC, 0x3); |
| 1599 | |
| 1600 | /* Set the total length to be transmitted */ |
| 1601 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL, |
| 1602 | packet->length); |
| 1603 | } |
| 1604 | |
Lendacky, Thomas | a83ef42 | 2015-01-16 12:46:55 -0600 | [diff] [blame] | 1605 | for (i = cur_index - start_index + 1; i < packet->rdesc_count; i++) { |
| 1606 | cur_index++; |
| 1607 | rdata = XGBE_GET_DESC_DATA(ring, cur_index); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1608 | rdesc = rdata->rdesc; |
| 1609 | |
| 1610 | /* Update buffer address */ |
| 1611 | rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma)); |
| 1612 | rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma)); |
| 1613 | |
| 1614 | /* Update the buffer length */ |
| 1615 | XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L, |
| 1616 | rdata->skb_dma_len); |
| 1617 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1618 | /* Set OWN bit */ |
| 1619 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1); |
| 1620 | |
| 1621 | /* Mark it as NORMAL descriptor */ |
| 1622 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0); |
| 1623 | |
| 1624 | /* Enable HW CSUM */ |
| 1625 | if (csum) |
| 1626 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, |
| 1627 | CIC, 0x3); |
| 1628 | } |
| 1629 | |
| 1630 | /* Set LAST bit for the last descriptor */ |
| 1631 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1); |
| 1632 | |
Lendacky, Thomas | eb79e64 | 2014-11-20 11:04:02 -0600 | [diff] [blame] | 1633 | /* Set IC bit based on Tx coalescing settings */ |
| 1634 | if (tx_set_ic) |
| 1635 | XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1); |
| 1636 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1637 | /* Save the Tx info to report back during cleanup */ |
| 1638 | rdata->tx.packets = packet->tx_packets; |
| 1639 | rdata->tx.bytes = packet->tx_bytes; |
| 1640 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1641 | /* In case the Tx DMA engine is running, make sure everything |
| 1642 | * is written to the descriptor(s) before setting the OWN bit |
| 1643 | * for the first descriptor |
| 1644 | */ |
Lendacky, Thomas | ceb8f6b | 2015-03-20 11:50:16 -0500 | [diff] [blame] | 1645 | dma_wmb(); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1646 | |
| 1647 | /* Set OWN bit for the first descriptor */ |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1648 | rdata = XGBE_GET_DESC_DATA(ring, start_index); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1649 | rdesc = rdata->rdesc; |
| 1650 | XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1); |
| 1651 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 1652 | if (netif_msg_tx_queued(pdata)) |
| 1653 | xgbe_dump_tx_desc(pdata, ring, start_index, |
| 1654 | packet->rdesc_count, 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1655 | |
| 1656 | /* Make sure ownership is written to the descriptor */ |
Lendacky, Thomas | 20986ed | 2015-10-26 17:13:54 -0500 | [diff] [blame] | 1657 | smp_wmb(); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1658 | |
Lendacky, Thomas | a83ef42 | 2015-01-16 12:46:55 -0600 | [diff] [blame] | 1659 | ring->cur = cur_index + 1; |
Lendacky, Thomas | 16958a2 | 2014-11-20 11:04:08 -0600 | [diff] [blame] | 1660 | if (!packet->skb->xmit_more || |
| 1661 | netif_xmit_stopped(netdev_get_tx_queue(pdata->netdev, |
| 1662 | channel->queue_index))) |
| 1663 | xgbe_tx_start_xmit(channel, ring); |
| 1664 | else |
| 1665 | ring->tx.xmit_more = 1; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1666 | |
| 1667 | DBGPR(" %s: descriptors %u to %u written\n", |
| 1668 | channel->name, start_index & (ring->rdesc_count - 1), |
| 1669 | (ring->cur - 1) & (ring->rdesc_count - 1)); |
| 1670 | |
Lendacky, Thomas | a9d4198 | 2014-11-04 16:06:32 -0600 | [diff] [blame] | 1671 | DBGPR("<--xgbe_dev_xmit\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | static int xgbe_dev_read(struct xgbe_channel *channel) |
| 1675 | { |
Lendacky, Thomas | 5452b2d | 2015-05-14 11:43:57 -0500 | [diff] [blame] | 1676 | struct xgbe_prv_data *pdata = channel->pdata; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1677 | struct xgbe_ring *ring = channel->rx_ring; |
| 1678 | struct xgbe_ring_data *rdata; |
| 1679 | struct xgbe_ring_desc *rdesc; |
| 1680 | struct xgbe_packet_data *packet = &ring->packet_data; |
Lendacky, Thomas | 5452b2d | 2015-05-14 11:43:57 -0500 | [diff] [blame] | 1681 | struct net_device *netdev = pdata->netdev; |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 1682 | unsigned int err, etlt, l34t; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1683 | |
| 1684 | DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur); |
| 1685 | |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1686 | rdata = XGBE_GET_DESC_DATA(ring, ring->cur); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1687 | rdesc = rdata->rdesc; |
| 1688 | |
| 1689 | /* Check for data availability */ |
| 1690 | if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN)) |
| 1691 | return 1; |
| 1692 | |
Lendacky, Thomas | 5449e27 | 2014-11-20 11:03:26 -0600 | [diff] [blame] | 1693 | /* Make sure descriptor fields are read after reading the OWN bit */ |
Lendacky, Thomas | ceb8f6b | 2015-03-20 11:50:16 -0500 | [diff] [blame] | 1694 | dma_rmb(); |
Lendacky, Thomas | 5449e27 | 2014-11-20 11:03:26 -0600 | [diff] [blame] | 1695 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 1696 | if (netif_msg_rx_status(pdata)) |
| 1697 | xgbe_dump_rx_desc(pdata, ring, ring->cur); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1698 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1699 | if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CTXT)) { |
| 1700 | /* Timestamp Context Descriptor */ |
| 1701 | xgbe_get_rx_tstamp(packet, rdesc); |
| 1702 | |
| 1703 | XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, |
| 1704 | CONTEXT, 1); |
| 1705 | XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, |
| 1706 | CONTEXT_NEXT, 0); |
| 1707 | return 0; |
| 1708 | } |
| 1709 | |
| 1710 | /* Normal Descriptor, be sure Context Descriptor bit is off */ |
| 1711 | XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT, 0); |
| 1712 | |
| 1713 | /* Indicate if a Context Descriptor is next */ |
| 1714 | if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CDA)) |
| 1715 | XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, |
| 1716 | CONTEXT_NEXT, 1); |
| 1717 | |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 1718 | /* Get the header length */ |
Lendacky, Thomas | 5452b2d | 2015-05-14 11:43:57 -0500 | [diff] [blame] | 1719 | if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, FD)) { |
Lendacky, Thomas | c9f140e | 2014-11-20 11:03:44 -0600 | [diff] [blame] | 1720 | rdata->rx.hdr_len = XGMAC_GET_BITS_LE(rdesc->desc2, |
| 1721 | RX_NORMAL_DESC2, HL); |
Lendacky, Thomas | 5452b2d | 2015-05-14 11:43:57 -0500 | [diff] [blame] | 1722 | if (rdata->rx.hdr_len) |
| 1723 | pdata->ext_stats.rx_split_header_packets++; |
| 1724 | } |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 1725 | |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 1726 | /* Get the RSS hash */ |
| 1727 | if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, RSV)) { |
| 1728 | XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, |
| 1729 | RSS_HASH, 1); |
| 1730 | |
| 1731 | packet->rss_hash = le32_to_cpu(rdesc->desc1); |
| 1732 | |
| 1733 | l34t = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, L34T); |
| 1734 | switch (l34t) { |
| 1735 | case RX_DESC3_L34T_IPV4_TCP: |
| 1736 | case RX_DESC3_L34T_IPV4_UDP: |
| 1737 | case RX_DESC3_L34T_IPV6_TCP: |
| 1738 | case RX_DESC3_L34T_IPV6_UDP: |
| 1739 | packet->rss_hash_type = PKT_HASH_TYPE_L4; |
Dan Carpenter | b6267d3 | 2014-11-13 09:19:06 +0300 | [diff] [blame] | 1740 | break; |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 1741 | default: |
| 1742 | packet->rss_hash_type = PKT_HASH_TYPE_L3; |
| 1743 | } |
| 1744 | } |
| 1745 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1746 | /* Get the packet length */ |
Lendacky, Thomas | c9f140e | 2014-11-20 11:03:44 -0600 | [diff] [blame] | 1747 | rdata->rx.len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1748 | |
| 1749 | if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) { |
| 1750 | /* Not all the data has been transferred for this packet */ |
| 1751 | XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, |
| 1752 | INCOMPLETE, 1); |
| 1753 | return 0; |
| 1754 | } |
| 1755 | |
| 1756 | /* This is the last of the data for this packet */ |
| 1757 | XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, |
| 1758 | INCOMPLETE, 0); |
| 1759 | |
| 1760 | /* Set checksum done indicator as appropriate */ |
Lendacky, Thomas | 5452b2d | 2015-05-14 11:43:57 -0500 | [diff] [blame] | 1761 | if (netdev->features & NETIF_F_RXCSUM) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1762 | XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, |
| 1763 | CSUM_DONE, 1); |
| 1764 | |
| 1765 | /* Check for errors (only valid in last descriptor) */ |
| 1766 | err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES); |
| 1767 | etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT); |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 1768 | netif_dbg(pdata, rx_status, netdev, "err=%u, etlt=%#x\n", err, etlt); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1769 | |
Lendacky, Thomas | 7bba35b | 2014-11-20 11:03:38 -0600 | [diff] [blame] | 1770 | if (!err || !etlt) { |
| 1771 | /* No error if err is 0 or etlt is 0 */ |
Lendacky, Thomas | c52e9c6 | 2014-06-24 16:19:18 -0500 | [diff] [blame] | 1772 | if ((etlt == 0x09) && |
| 1773 | (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1774 | XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, |
| 1775 | VLAN_CTAG, 1); |
| 1776 | packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0, |
| 1777 | RX_NORMAL_DESC0, |
| 1778 | OVT); |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 1779 | netif_dbg(pdata, rx_status, netdev, "vlan-ctag=%#06x\n", |
| 1780 | packet->vlan_ctag); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1781 | } |
| 1782 | } else { |
| 1783 | if ((etlt == 0x05) || (etlt == 0x06)) |
| 1784 | XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, |
| 1785 | CSUM_DONE, 0); |
| 1786 | else |
| 1787 | XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS, |
| 1788 | FRAME, 1); |
| 1789 | } |
| 1790 | |
| 1791 | DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name, |
| 1792 | ring->cur & (ring->rdesc_count - 1), ring->cur); |
| 1793 | |
| 1794 | return 0; |
| 1795 | } |
| 1796 | |
| 1797 | static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc) |
| 1798 | { |
| 1799 | /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */ |
| 1800 | return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT); |
| 1801 | } |
| 1802 | |
| 1803 | static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc) |
| 1804 | { |
| 1805 | /* Rx and Tx share LD bit, so check TDES3.LD bit */ |
| 1806 | return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD); |
| 1807 | } |
| 1808 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1809 | static int xgbe_enable_int(struct xgbe_channel *channel, |
| 1810 | enum xgbe_int int_id) |
| 1811 | { |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1812 | unsigned int dma_ch_ier; |
| 1813 | |
| 1814 | dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER); |
| 1815 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1816 | switch (int_id) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1817 | case XGMAC_INT_DMA_CH_SR_TI: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1818 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1819 | break; |
| 1820 | case XGMAC_INT_DMA_CH_SR_TPS: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1821 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1822 | break; |
| 1823 | case XGMAC_INT_DMA_CH_SR_TBU: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1824 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1825 | break; |
| 1826 | case XGMAC_INT_DMA_CH_SR_RI: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1827 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1828 | break; |
| 1829 | case XGMAC_INT_DMA_CH_SR_RBU: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1830 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1831 | break; |
| 1832 | case XGMAC_INT_DMA_CH_SR_RPS: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1833 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 1); |
| 1834 | break; |
| 1835 | case XGMAC_INT_DMA_CH_SR_TI_RI: |
| 1836 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1); |
| 1837 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1838 | break; |
| 1839 | case XGMAC_INT_DMA_CH_SR_FBE: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1840 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1841 | break; |
| 1842 | case XGMAC_INT_DMA_ALL: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1843 | dma_ch_ier |= channel->saved_ier; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1844 | break; |
| 1845 | default: |
| 1846 | return -1; |
| 1847 | } |
| 1848 | |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1849 | XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier); |
| 1850 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1851 | return 0; |
| 1852 | } |
| 1853 | |
| 1854 | static int xgbe_disable_int(struct xgbe_channel *channel, |
| 1855 | enum xgbe_int int_id) |
| 1856 | { |
| 1857 | unsigned int dma_ch_ier; |
| 1858 | |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1859 | dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER); |
| 1860 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1861 | switch (int_id) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1862 | case XGMAC_INT_DMA_CH_SR_TI: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1863 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1864 | break; |
| 1865 | case XGMAC_INT_DMA_CH_SR_TPS: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1866 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 0); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1867 | break; |
| 1868 | case XGMAC_INT_DMA_CH_SR_TBU: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1869 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 0); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1870 | break; |
| 1871 | case XGMAC_INT_DMA_CH_SR_RI: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1872 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1873 | break; |
| 1874 | case XGMAC_INT_DMA_CH_SR_RBU: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1875 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 0); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1876 | break; |
| 1877 | case XGMAC_INT_DMA_CH_SR_RPS: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1878 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 0); |
| 1879 | break; |
| 1880 | case XGMAC_INT_DMA_CH_SR_TI_RI: |
| 1881 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0); |
| 1882 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1883 | break; |
| 1884 | case XGMAC_INT_DMA_CH_SR_FBE: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1885 | XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 0); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1886 | break; |
| 1887 | case XGMAC_INT_DMA_ALL: |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1888 | channel->saved_ier = dma_ch_ier & XGBE_DMA_INTERRUPT_MASK; |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1889 | dma_ch_ier &= ~XGBE_DMA_INTERRUPT_MASK; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1890 | break; |
| 1891 | default: |
| 1892 | return -1; |
| 1893 | } |
| 1894 | |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1895 | XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier); |
| 1896 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1897 | return 0; |
| 1898 | } |
| 1899 | |
| 1900 | static int xgbe_exit(struct xgbe_prv_data *pdata) |
| 1901 | { |
| 1902 | unsigned int count = 2000; |
| 1903 | |
| 1904 | DBGPR("-->xgbe_exit\n"); |
| 1905 | |
| 1906 | /* Issue a software reset */ |
| 1907 | XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1); |
| 1908 | usleep_range(10, 15); |
| 1909 | |
| 1910 | /* Poll Until Poll Condition */ |
Dan Carpenter | c7557e6 | 2015-12-15 13:12:29 +0300 | [diff] [blame] | 1911 | while (--count && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR)) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1912 | usleep_range(500, 600); |
| 1913 | |
| 1914 | if (!count) |
| 1915 | return -EBUSY; |
| 1916 | |
| 1917 | DBGPR("<--xgbe_exit\n"); |
| 1918 | |
| 1919 | return 0; |
| 1920 | } |
| 1921 | |
| 1922 | static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata) |
| 1923 | { |
| 1924 | unsigned int i, count; |
| 1925 | |
Lendacky, Thomas | a9a4a2d | 2014-08-29 13:16:50 -0500 | [diff] [blame] | 1926 | if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) < 0x21) |
| 1927 | return 0; |
| 1928 | |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 1929 | for (i = 0; i < pdata->tx_q_count; i++) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1930 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1); |
| 1931 | |
| 1932 | /* Poll Until Poll Condition */ |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 1933 | for (i = 0; i < pdata->tx_q_count; i++) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1934 | count = 2000; |
Dan Carpenter | c7557e6 | 2015-12-15 13:12:29 +0300 | [diff] [blame] | 1935 | while (--count && XGMAC_MTL_IOREAD_BITS(pdata, i, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1936 | MTL_Q_TQOMR, FTQ)) |
| 1937 | usleep_range(500, 600); |
| 1938 | |
| 1939 | if (!count) |
| 1940 | return -EBUSY; |
| 1941 | } |
| 1942 | |
| 1943 | return 0; |
| 1944 | } |
| 1945 | |
| 1946 | static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata) |
| 1947 | { |
| 1948 | /* Set enhanced addressing mode */ |
| 1949 | XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1); |
| 1950 | |
| 1951 | /* Set the System Bus mode */ |
| 1952 | XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1); |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1953 | XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, BLEN_256, 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata) |
| 1957 | { |
| 1958 | unsigned int arcache, awcache; |
| 1959 | |
| 1960 | arcache = 0; |
Lendacky, Thomas | cfa50c7 | 2014-07-02 13:04:57 -0500 | [diff] [blame] | 1961 | XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, pdata->arcache); |
| 1962 | XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, pdata->axdomain); |
| 1963 | XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, pdata->arcache); |
| 1964 | XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, pdata->axdomain); |
| 1965 | XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, pdata->arcache); |
| 1966 | XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, pdata->axdomain); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1967 | XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache); |
| 1968 | |
| 1969 | awcache = 0; |
Lendacky, Thomas | cfa50c7 | 2014-07-02 13:04:57 -0500 | [diff] [blame] | 1970 | XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, pdata->awcache); |
| 1971 | XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, pdata->axdomain); |
| 1972 | XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, pdata->awcache); |
| 1973 | XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, pdata->axdomain); |
| 1974 | XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, pdata->awcache); |
| 1975 | XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, pdata->axdomain); |
| 1976 | XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, pdata->awcache); |
| 1977 | XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, pdata->axdomain); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1978 | XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache); |
| 1979 | } |
| 1980 | |
| 1981 | static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata) |
| 1982 | { |
| 1983 | unsigned int i; |
| 1984 | |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 1985 | /* Set Tx to weighted round robin scheduling algorithm */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1986 | XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR); |
| 1987 | |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 1988 | /* Set Tx traffic classes to use WRR algorithm with equal weights */ |
| 1989 | for (i = 0; i < pdata->hw_feat.tc_cnt; i++) { |
| 1990 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA, |
| 1991 | MTL_TSA_ETS); |
| 1992 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 1); |
| 1993 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1994 | |
| 1995 | /* Set Rx to strict priority algorithm */ |
| 1996 | XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP); |
| 1997 | } |
| 1998 | |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 1999 | static void xgbe_queue_flow_control_threshold(struct xgbe_prv_data *pdata, |
| 2000 | unsigned int queue, |
| 2001 | unsigned int q_fifo_size) |
| 2002 | { |
| 2003 | unsigned int frame_fifo_size; |
| 2004 | unsigned int rfa, rfd; |
| 2005 | |
| 2006 | frame_fifo_size = XGMAC_FLOW_CONTROL_ALIGN(xgbe_get_max_frame(pdata)); |
| 2007 | |
| 2008 | if (pdata->pfcq[queue] && (q_fifo_size > pdata->pfc_rfa)) { |
| 2009 | /* PFC is active for this queue */ |
| 2010 | rfa = pdata->pfc_rfa; |
| 2011 | rfd = rfa + frame_fifo_size; |
| 2012 | if (rfd > XGMAC_FLOW_CONTROL_MAX) |
| 2013 | rfd = XGMAC_FLOW_CONTROL_MAX; |
| 2014 | if (rfa >= XGMAC_FLOW_CONTROL_MAX) |
| 2015 | rfa = XGMAC_FLOW_CONTROL_MAX - XGMAC_FLOW_CONTROL_UNIT; |
| 2016 | } else { |
| 2017 | /* This path deals with just maximum frame sizes which are |
| 2018 | * limited to a jumbo frame of 9,000 (plus headers, etc.) |
| 2019 | * so we can never exceed the maximum allowable RFA/RFD |
| 2020 | * values. |
| 2021 | */ |
| 2022 | if (q_fifo_size <= 2048) { |
| 2023 | /* rx_rfd to zero to signal no flow control */ |
| 2024 | pdata->rx_rfa[queue] = 0; |
| 2025 | pdata->rx_rfd[queue] = 0; |
| 2026 | return; |
| 2027 | } |
| 2028 | |
| 2029 | if (q_fifo_size <= 4096) { |
| 2030 | /* Between 2048 and 4096 */ |
| 2031 | pdata->rx_rfa[queue] = 0; /* Full - 1024 bytes */ |
| 2032 | pdata->rx_rfd[queue] = 1; /* Full - 1536 bytes */ |
| 2033 | return; |
| 2034 | } |
| 2035 | |
| 2036 | if (q_fifo_size <= frame_fifo_size) { |
| 2037 | /* Between 4096 and max-frame */ |
| 2038 | pdata->rx_rfa[queue] = 2; /* Full - 2048 bytes */ |
| 2039 | pdata->rx_rfd[queue] = 5; /* Full - 3584 bytes */ |
| 2040 | return; |
| 2041 | } |
| 2042 | |
| 2043 | if (q_fifo_size <= (frame_fifo_size * 3)) { |
| 2044 | /* Between max-frame and 3 max-frames, |
| 2045 | * trigger if we get just over a frame of data and |
| 2046 | * resume when we have just under half a frame left. |
| 2047 | */ |
| 2048 | rfa = q_fifo_size - frame_fifo_size; |
| 2049 | rfd = rfa + (frame_fifo_size / 2); |
| 2050 | } else { |
| 2051 | /* Above 3 max-frames - trigger when just over |
| 2052 | * 2 frames of space available |
| 2053 | */ |
| 2054 | rfa = frame_fifo_size * 2; |
| 2055 | rfa += XGMAC_FLOW_CONTROL_UNIT; |
| 2056 | rfd = rfa + frame_fifo_size; |
| 2057 | } |
| 2058 | } |
| 2059 | |
| 2060 | pdata->rx_rfa[queue] = XGMAC_FLOW_CONTROL_VALUE(rfa); |
| 2061 | pdata->rx_rfd[queue] = XGMAC_FLOW_CONTROL_VALUE(rfd); |
| 2062 | } |
| 2063 | |
| 2064 | static void xgbe_calculate_flow_control_threshold(struct xgbe_prv_data *pdata, |
| 2065 | unsigned int *fifo) |
| 2066 | { |
| 2067 | unsigned int q_fifo_size; |
| 2068 | unsigned int i; |
| 2069 | |
| 2070 | for (i = 0; i < pdata->rx_q_count; i++) { |
| 2071 | q_fifo_size = (fifo[i] + 1) * XGMAC_FIFO_UNIT; |
| 2072 | |
| 2073 | xgbe_queue_flow_control_threshold(pdata, i, q_fifo_size); |
| 2074 | } |
| 2075 | } |
| 2076 | |
| 2077 | static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata) |
| 2078 | { |
| 2079 | unsigned int i; |
| 2080 | |
| 2081 | for (i = 0; i < pdata->rx_q_count; i++) { |
| 2082 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFA, |
| 2083 | pdata->rx_rfa[i]); |
| 2084 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFD, |
| 2085 | pdata->rx_rfd[i]); |
| 2086 | } |
| 2087 | } |
| 2088 | |
Lendacky, Thomas | 586e3cfb | 2016-11-03 13:17:48 -0500 | [diff] [blame] | 2089 | static unsigned int xgbe_get_tx_fifo_size(struct xgbe_prv_data *pdata) |
| 2090 | { |
Lendacky, Thomas | 586e3cfb | 2016-11-03 13:17:48 -0500 | [diff] [blame] | 2091 | /* The configured value may not be the actual amount of fifo RAM */ |
Lendacky, Thomas | bd8255d | 2016-11-03 13:19:27 -0500 | [diff] [blame^] | 2092 | return min_t(unsigned int, pdata->tx_max_fifo_size, |
| 2093 | pdata->hw_feat.tx_fifo_size); |
Lendacky, Thomas | 586e3cfb | 2016-11-03 13:17:48 -0500 | [diff] [blame] | 2094 | } |
| 2095 | |
| 2096 | static unsigned int xgbe_get_rx_fifo_size(struct xgbe_prv_data *pdata) |
| 2097 | { |
Lendacky, Thomas | 586e3cfb | 2016-11-03 13:17:48 -0500 | [diff] [blame] | 2098 | /* The configured value may not be the actual amount of fifo RAM */ |
Lendacky, Thomas | bd8255d | 2016-11-03 13:19:27 -0500 | [diff] [blame^] | 2099 | return min_t(unsigned int, pdata->rx_max_fifo_size, |
| 2100 | pdata->hw_feat.rx_fifo_size); |
Lendacky, Thomas | 586e3cfb | 2016-11-03 13:17:48 -0500 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | static void xgbe_calculate_equal_fifo(unsigned int fifo_size, |
| 2104 | unsigned int queue_count, |
| 2105 | unsigned int *fifo) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2106 | { |
Lendacky, Thomas | 9c439e4 | 2015-09-30 08:53:03 -0500 | [diff] [blame] | 2107 | unsigned int q_fifo_size; |
| 2108 | unsigned int p_fifo; |
Lendacky, Thomas | 586e3cfb | 2016-11-03 13:17:48 -0500 | [diff] [blame] | 2109 | unsigned int i; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2110 | |
Lendacky, Thomas | 586e3cfb | 2016-11-03 13:17:48 -0500 | [diff] [blame] | 2111 | q_fifo_size = fifo_size / queue_count; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2112 | |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 2113 | /* Calculate the fifo setting by dividing the queue's fifo size |
| 2114 | * by the fifo allocation increment (with 0 representing the |
| 2115 | * base allocation increment so decrement the result by 1). |
Lendacky, Thomas | 9c439e4 | 2015-09-30 08:53:03 -0500 | [diff] [blame] | 2116 | */ |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 2117 | p_fifo = q_fifo_size / XGMAC_FIFO_UNIT; |
Lendacky, Thomas | 9c439e4 | 2015-09-30 08:53:03 -0500 | [diff] [blame] | 2118 | if (p_fifo) |
| 2119 | p_fifo--; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2120 | |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 2121 | /* Distribute the fifo equally amongst the queues */ |
Lendacky, Thomas | 586e3cfb | 2016-11-03 13:17:48 -0500 | [diff] [blame] | 2122 | for (i = 0; i < queue_count; i++) |
| 2123 | fifo[i] = p_fifo; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2124 | } |
| 2125 | |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 2126 | static unsigned int xgbe_set_nonprio_fifos(unsigned int fifo_size, |
| 2127 | unsigned int queue_count, |
| 2128 | unsigned int *fifo) |
| 2129 | { |
| 2130 | unsigned int i; |
| 2131 | |
| 2132 | BUILD_BUG_ON_NOT_POWER_OF_2(XGMAC_FIFO_MIN_ALLOC); |
| 2133 | |
| 2134 | if (queue_count <= IEEE_8021QAZ_MAX_TCS) |
| 2135 | return fifo_size; |
| 2136 | |
| 2137 | /* Rx queues 9 and up are for specialized packets, |
| 2138 | * such as PTP or DCB control packets, etc. and |
| 2139 | * don't require a large fifo |
| 2140 | */ |
| 2141 | for (i = IEEE_8021QAZ_MAX_TCS; i < queue_count; i++) { |
| 2142 | fifo[i] = (XGMAC_FIFO_MIN_ALLOC / XGMAC_FIFO_UNIT) - 1; |
| 2143 | fifo_size -= XGMAC_FIFO_MIN_ALLOC; |
| 2144 | } |
| 2145 | |
| 2146 | return fifo_size; |
| 2147 | } |
| 2148 | |
| 2149 | static unsigned int xgbe_get_pfc_delay(struct xgbe_prv_data *pdata) |
| 2150 | { |
| 2151 | unsigned int delay; |
| 2152 | |
| 2153 | /* If a delay has been provided, use that */ |
| 2154 | if (pdata->pfc->delay) |
| 2155 | return pdata->pfc->delay / 8; |
| 2156 | |
| 2157 | /* Allow for two maximum size frames */ |
| 2158 | delay = xgbe_get_max_frame(pdata); |
| 2159 | delay += XGMAC_ETH_PREAMBLE; |
| 2160 | delay *= 2; |
| 2161 | |
| 2162 | /* Allow for PFC frame */ |
| 2163 | delay += XGMAC_PFC_DATA_LEN; |
| 2164 | delay += ETH_HLEN + ETH_FCS_LEN; |
| 2165 | delay += XGMAC_ETH_PREAMBLE; |
| 2166 | |
| 2167 | /* Allow for miscellaneous delays (LPI exit, cable, etc.) */ |
| 2168 | delay += XGMAC_PFC_DELAYS; |
| 2169 | |
| 2170 | return delay; |
| 2171 | } |
| 2172 | |
| 2173 | static unsigned int xgbe_get_pfc_queues(struct xgbe_prv_data *pdata) |
| 2174 | { |
| 2175 | unsigned int count, prio_queues; |
| 2176 | unsigned int i; |
| 2177 | |
| 2178 | if (!pdata->pfc->pfc_en) |
| 2179 | return 0; |
| 2180 | |
| 2181 | count = 0; |
| 2182 | prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count); |
| 2183 | for (i = 0; i < prio_queues; i++) { |
| 2184 | if (!xgbe_is_pfc_queue(pdata, i)) |
| 2185 | continue; |
| 2186 | |
| 2187 | pdata->pfcq[i] = 1; |
| 2188 | count++; |
| 2189 | } |
| 2190 | |
| 2191 | return count; |
| 2192 | } |
| 2193 | |
| 2194 | static void xgbe_calculate_dcb_fifo(struct xgbe_prv_data *pdata, |
| 2195 | unsigned int fifo_size, |
| 2196 | unsigned int *fifo) |
| 2197 | { |
| 2198 | unsigned int q_fifo_size, rem_fifo, addn_fifo; |
| 2199 | unsigned int prio_queues; |
| 2200 | unsigned int pfc_count; |
| 2201 | unsigned int i; |
| 2202 | |
| 2203 | q_fifo_size = XGMAC_FIFO_ALIGN(xgbe_get_max_frame(pdata)); |
| 2204 | prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count); |
| 2205 | pfc_count = xgbe_get_pfc_queues(pdata); |
| 2206 | |
| 2207 | if (!pfc_count || ((q_fifo_size * prio_queues) > fifo_size)) { |
| 2208 | /* No traffic classes with PFC enabled or can't do lossless */ |
| 2209 | xgbe_calculate_equal_fifo(fifo_size, prio_queues, fifo); |
| 2210 | return; |
| 2211 | } |
| 2212 | |
| 2213 | /* Calculate how much fifo we have to play with */ |
| 2214 | rem_fifo = fifo_size - (q_fifo_size * prio_queues); |
| 2215 | |
| 2216 | /* Calculate how much more than base fifo PFC needs, which also |
| 2217 | * becomes the threshold activation point (RFA) |
| 2218 | */ |
| 2219 | pdata->pfc_rfa = xgbe_get_pfc_delay(pdata); |
| 2220 | pdata->pfc_rfa = XGMAC_FLOW_CONTROL_ALIGN(pdata->pfc_rfa); |
| 2221 | |
| 2222 | if (pdata->pfc_rfa > q_fifo_size) { |
| 2223 | addn_fifo = pdata->pfc_rfa - q_fifo_size; |
| 2224 | addn_fifo = XGMAC_FIFO_ALIGN(addn_fifo); |
| 2225 | } else { |
| 2226 | addn_fifo = 0; |
| 2227 | } |
| 2228 | |
| 2229 | /* Calculate DCB fifo settings: |
| 2230 | * - distribute remaining fifo between the VLAN priority |
| 2231 | * queues based on traffic class PFC enablement and overall |
| 2232 | * priority (0 is lowest priority, so start at highest) |
| 2233 | */ |
| 2234 | i = prio_queues; |
| 2235 | while (i > 0) { |
| 2236 | i--; |
| 2237 | |
| 2238 | fifo[i] = (q_fifo_size / XGMAC_FIFO_UNIT) - 1; |
| 2239 | |
| 2240 | if (!pdata->pfcq[i] || !addn_fifo) |
| 2241 | continue; |
| 2242 | |
| 2243 | if (addn_fifo > rem_fifo) { |
| 2244 | netdev_warn(pdata->netdev, |
| 2245 | "RXq%u cannot set needed fifo size\n", i); |
| 2246 | if (!rem_fifo) |
| 2247 | continue; |
| 2248 | |
| 2249 | addn_fifo = rem_fifo; |
| 2250 | } |
| 2251 | |
| 2252 | fifo[i] += (addn_fifo / XGMAC_FIFO_UNIT); |
| 2253 | rem_fifo -= addn_fifo; |
| 2254 | } |
| 2255 | |
| 2256 | if (rem_fifo) { |
| 2257 | unsigned int inc_fifo = rem_fifo / prio_queues; |
| 2258 | |
| 2259 | /* Distribute remaining fifo across queues */ |
| 2260 | for (i = 0; i < prio_queues; i++) |
| 2261 | fifo[i] += (inc_fifo / XGMAC_FIFO_UNIT); |
| 2262 | } |
| 2263 | } |
| 2264 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2265 | static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata) |
| 2266 | { |
Lendacky, Thomas | 9c439e4 | 2015-09-30 08:53:03 -0500 | [diff] [blame] | 2267 | unsigned int fifo_size; |
Lendacky, Thomas | 586e3cfb | 2016-11-03 13:17:48 -0500 | [diff] [blame] | 2268 | unsigned int fifo[XGBE_MAX_QUEUES]; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2269 | unsigned int i; |
| 2270 | |
Lendacky, Thomas | 586e3cfb | 2016-11-03 13:17:48 -0500 | [diff] [blame] | 2271 | fifo_size = xgbe_get_tx_fifo_size(pdata); |
| 2272 | |
| 2273 | xgbe_calculate_equal_fifo(fifo_size, pdata->tx_q_count, fifo); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2274 | |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 2275 | for (i = 0; i < pdata->tx_q_count; i++) |
Lendacky, Thomas | 586e3cfb | 2016-11-03 13:17:48 -0500 | [diff] [blame] | 2276 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo[i]); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2277 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2278 | netif_info(pdata, drv, pdata->netdev, |
| 2279 | "%d Tx hardware queues, %d byte fifo per queue\n", |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 2280 | pdata->tx_q_count, ((fifo[0] + 1) * XGMAC_FIFO_UNIT)); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata) |
| 2284 | { |
Lendacky, Thomas | 9c439e4 | 2015-09-30 08:53:03 -0500 | [diff] [blame] | 2285 | unsigned int fifo_size; |
Lendacky, Thomas | 586e3cfb | 2016-11-03 13:17:48 -0500 | [diff] [blame] | 2286 | unsigned int fifo[XGBE_MAX_QUEUES]; |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 2287 | unsigned int prio_queues; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2288 | unsigned int i; |
| 2289 | |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 2290 | /* Clear any DCB related fifo/queue information */ |
| 2291 | memset(pdata->pfcq, 0, sizeof(pdata->pfcq)); |
| 2292 | pdata->pfc_rfa = 0; |
Lendacky, Thomas | 586e3cfb | 2016-11-03 13:17:48 -0500 | [diff] [blame] | 2293 | |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 2294 | fifo_size = xgbe_get_rx_fifo_size(pdata); |
| 2295 | prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count); |
| 2296 | |
| 2297 | /* Assign a minimum fifo to the non-VLAN priority queues */ |
| 2298 | fifo_size = xgbe_set_nonprio_fifos(fifo_size, pdata->rx_q_count, fifo); |
| 2299 | |
| 2300 | if (pdata->pfc && pdata->ets) |
| 2301 | xgbe_calculate_dcb_fifo(pdata, fifo_size, fifo); |
| 2302 | else |
| 2303 | xgbe_calculate_equal_fifo(fifo_size, prio_queues, fifo); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2304 | |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 2305 | for (i = 0; i < pdata->rx_q_count; i++) |
Lendacky, Thomas | 586e3cfb | 2016-11-03 13:17:48 -0500 | [diff] [blame] | 2306 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo[i]); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2307 | |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 2308 | xgbe_calculate_flow_control_threshold(pdata, fifo); |
| 2309 | xgbe_config_flow_control_threshold(pdata); |
| 2310 | |
| 2311 | if (pdata->pfc && pdata->ets && pdata->pfc->pfc_en) { |
| 2312 | netif_info(pdata, drv, pdata->netdev, |
| 2313 | "%u Rx hardware queues\n", pdata->rx_q_count); |
| 2314 | for (i = 0; i < pdata->rx_q_count; i++) |
| 2315 | netif_info(pdata, drv, pdata->netdev, |
| 2316 | "RxQ%u, %u byte fifo queue\n", i, |
| 2317 | ((fifo[i] + 1) * XGMAC_FIFO_UNIT)); |
| 2318 | } else { |
| 2319 | netif_info(pdata, drv, pdata->netdev, |
| 2320 | "%u Rx hardware queues, %u byte fifo per queue\n", |
| 2321 | pdata->rx_q_count, |
| 2322 | ((fifo[0] + 1) * XGMAC_FIFO_UNIT)); |
| 2323 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2324 | } |
| 2325 | |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 2326 | static void xgbe_config_queue_mapping(struct xgbe_prv_data *pdata) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2327 | { |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 2328 | unsigned int qptc, qptc_extra, queue; |
| 2329 | unsigned int prio_queues; |
| 2330 | unsigned int ppq, ppq_extra, prio; |
| 2331 | unsigned int mask; |
| 2332 | unsigned int i, j, reg, reg_val; |
| 2333 | |
| 2334 | /* Map the MTL Tx Queues to Traffic Classes |
| 2335 | * Note: Tx Queues >= Traffic Classes |
| 2336 | */ |
| 2337 | qptc = pdata->tx_q_count / pdata->hw_feat.tc_cnt; |
| 2338 | qptc_extra = pdata->tx_q_count % pdata->hw_feat.tc_cnt; |
| 2339 | |
| 2340 | for (i = 0, queue = 0; i < pdata->hw_feat.tc_cnt; i++) { |
| 2341 | for (j = 0; j < qptc; j++) { |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2342 | netif_dbg(pdata, drv, pdata->netdev, |
| 2343 | "TXq%u mapped to TC%u\n", queue, i); |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 2344 | XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR, |
| 2345 | Q2TCMAP, i); |
| 2346 | pdata->q2tc_map[queue++] = i; |
| 2347 | } |
| 2348 | |
| 2349 | if (i < qptc_extra) { |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2350 | netif_dbg(pdata, drv, pdata->netdev, |
| 2351 | "TXq%u mapped to TC%u\n", queue, i); |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 2352 | XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR, |
| 2353 | Q2TCMAP, i); |
| 2354 | pdata->q2tc_map[queue++] = i; |
| 2355 | } |
| 2356 | } |
| 2357 | |
| 2358 | /* Map the 8 VLAN priority values to available MTL Rx queues */ |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 2359 | prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count); |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 2360 | ppq = IEEE_8021QAZ_MAX_TCS / prio_queues; |
| 2361 | ppq_extra = IEEE_8021QAZ_MAX_TCS % prio_queues; |
| 2362 | |
| 2363 | reg = MAC_RQC2R; |
| 2364 | reg_val = 0; |
| 2365 | for (i = 0, prio = 0; i < prio_queues;) { |
| 2366 | mask = 0; |
| 2367 | for (j = 0; j < ppq; j++) { |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2368 | netif_dbg(pdata, drv, pdata->netdev, |
| 2369 | "PRIO%u mapped to RXq%u\n", prio, i); |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 2370 | mask |= (1 << prio); |
| 2371 | pdata->prio2q_map[prio++] = i; |
| 2372 | } |
| 2373 | |
| 2374 | if (i < ppq_extra) { |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2375 | netif_dbg(pdata, drv, pdata->netdev, |
| 2376 | "PRIO%u mapped to RXq%u\n", prio, i); |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 2377 | mask |= (1 << prio); |
| 2378 | pdata->prio2q_map[prio++] = i; |
| 2379 | } |
| 2380 | |
| 2381 | reg_val |= (mask << ((i++ % MAC_RQC2_Q_PER_REG) << 3)); |
| 2382 | |
| 2383 | if ((i % MAC_RQC2_Q_PER_REG) && (i != prio_queues)) |
| 2384 | continue; |
| 2385 | |
| 2386 | XGMAC_IOWRITE(pdata, reg, reg_val); |
| 2387 | reg += MAC_RQC2_INC; |
| 2388 | reg_val = 0; |
| 2389 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2390 | |
| 2391 | /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */ |
| 2392 | reg = MTL_RQDCM0R; |
| 2393 | reg_val = 0; |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 2394 | for (i = 0; i < pdata->rx_q_count;) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2395 | reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3)); |
| 2396 | |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 2397 | if ((i % MTL_RQDCM_Q_PER_REG) && (i != pdata->rx_q_count)) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2398 | continue; |
| 2399 | |
| 2400 | XGMAC_IOWRITE(pdata, reg, reg_val); |
| 2401 | |
| 2402 | reg += MTL_RQDCM_INC; |
| 2403 | reg_val = 0; |
| 2404 | } |
| 2405 | } |
| 2406 | |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 2407 | static void xgbe_config_tc(struct xgbe_prv_data *pdata) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2408 | { |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 2409 | unsigned int offset, queue, prio; |
| 2410 | u8 i; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2411 | |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 2412 | netdev_reset_tc(pdata->netdev); |
| 2413 | if (!pdata->num_tcs) |
| 2414 | return; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2415 | |
Lendacky, Thomas | 43e0dcf | 2016-11-03 13:18:16 -0500 | [diff] [blame] | 2416 | netdev_set_num_tc(pdata->netdev, pdata->num_tcs); |
| 2417 | |
| 2418 | for (i = 0, queue = 0, offset = 0; i < pdata->num_tcs; i++) { |
| 2419 | while ((queue < pdata->tx_q_count) && |
| 2420 | (pdata->q2tc_map[queue] == i)) |
| 2421 | queue++; |
| 2422 | |
| 2423 | netif_dbg(pdata, drv, pdata->netdev, "TC%u using TXq%u-%u\n", |
| 2424 | i, offset, queue - 1); |
| 2425 | netdev_set_tc_queue(pdata->netdev, i, queue - offset, offset); |
| 2426 | offset = queue; |
| 2427 | } |
| 2428 | |
| 2429 | if (!pdata->ets) |
| 2430 | return; |
| 2431 | |
| 2432 | for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) |
| 2433 | netdev_set_prio_tc_map(pdata->netdev, prio, |
| 2434 | pdata->ets->prio_tc[prio]); |
| 2435 | } |
| 2436 | |
| 2437 | static void xgbe_config_dcb_tc(struct xgbe_prv_data *pdata) |
| 2438 | { |
| 2439 | struct ieee_ets *ets = pdata->ets; |
| 2440 | unsigned int total_weight, min_weight, weight; |
| 2441 | unsigned int mask, reg, reg_val; |
| 2442 | unsigned int i, prio; |
| 2443 | |
| 2444 | if (!ets) |
| 2445 | return; |
| 2446 | |
| 2447 | /* Set Tx to deficit weighted round robin scheduling algorithm (when |
| 2448 | * traffic class is using ETS algorithm) |
| 2449 | */ |
| 2450 | XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_DWRR); |
| 2451 | |
| 2452 | /* Set Traffic Class algorithms */ |
| 2453 | total_weight = pdata->netdev->mtu * pdata->hw_feat.tc_cnt; |
| 2454 | min_weight = total_weight / 100; |
| 2455 | if (!min_weight) |
| 2456 | min_weight = 1; |
| 2457 | |
| 2458 | for (i = 0; i < pdata->hw_feat.tc_cnt; i++) { |
| 2459 | /* Map the priorities to the traffic class */ |
| 2460 | mask = 0; |
| 2461 | for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) { |
| 2462 | if (ets->prio_tc[prio] == i) |
| 2463 | mask |= (1 << prio); |
| 2464 | } |
| 2465 | mask &= 0xff; |
| 2466 | |
| 2467 | netif_dbg(pdata, drv, pdata->netdev, "TC%u PRIO mask=%#x\n", |
| 2468 | i, mask); |
| 2469 | reg = MTL_TCPM0R + (MTL_TCPM_INC * (i / MTL_TCPM_TC_PER_REG)); |
| 2470 | reg_val = XGMAC_IOREAD(pdata, reg); |
| 2471 | |
| 2472 | reg_val &= ~(0xff << ((i % MTL_TCPM_TC_PER_REG) << 3)); |
| 2473 | reg_val |= (mask << ((i % MTL_TCPM_TC_PER_REG) << 3)); |
| 2474 | |
| 2475 | XGMAC_IOWRITE(pdata, reg, reg_val); |
| 2476 | |
| 2477 | /* Set the traffic class algorithm */ |
| 2478 | switch (ets->tc_tsa[i]) { |
| 2479 | case IEEE_8021QAZ_TSA_STRICT: |
| 2480 | netif_dbg(pdata, drv, pdata->netdev, |
| 2481 | "TC%u using SP\n", i); |
| 2482 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA, |
| 2483 | MTL_TSA_SP); |
| 2484 | break; |
| 2485 | case IEEE_8021QAZ_TSA_ETS: |
| 2486 | weight = total_weight * ets->tc_tx_bw[i] / 100; |
| 2487 | weight = clamp(weight, min_weight, total_weight); |
| 2488 | |
| 2489 | netif_dbg(pdata, drv, pdata->netdev, |
| 2490 | "TC%u using DWRR (weight %u)\n", i, weight); |
| 2491 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA, |
| 2492 | MTL_TSA_ETS); |
| 2493 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, |
| 2494 | weight); |
| 2495 | break; |
| 2496 | } |
| 2497 | } |
| 2498 | |
| 2499 | xgbe_config_tc(pdata); |
| 2500 | } |
| 2501 | |
| 2502 | static void xgbe_config_dcb_pfc(struct xgbe_prv_data *pdata) |
| 2503 | { |
| 2504 | if (!test_bit(XGBE_DOWN, &pdata->dev_state)) { |
| 2505 | /* Just stop the Tx queues while Rx fifo is changed */ |
| 2506 | netif_tx_stop_all_queues(pdata->netdev); |
| 2507 | |
| 2508 | /* Suspend Rx so that fifo's can be adjusted */ |
| 2509 | pdata->hw_if.disable_rx(pdata); |
| 2510 | } |
| 2511 | |
| 2512 | xgbe_config_rx_fifo_size(pdata); |
| 2513 | xgbe_config_flow_control(pdata); |
| 2514 | |
| 2515 | if (!test_bit(XGBE_DOWN, &pdata->dev_state)) { |
| 2516 | /* Resume Rx */ |
| 2517 | pdata->hw_if.enable_rx(pdata); |
| 2518 | |
| 2519 | /* Resume Tx queues */ |
| 2520 | netif_tx_start_all_queues(pdata->netdev); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | static void xgbe_config_mac_address(struct xgbe_prv_data *pdata) |
| 2525 | { |
| 2526 | xgbe_set_mac_address(pdata, pdata->netdev->dev_addr); |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 2527 | |
| 2528 | /* Filtering is done using perfect filtering and hash filtering */ |
| 2529 | if (pdata->hw_feat.hash_table_size) { |
| 2530 | XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1); |
| 2531 | XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1); |
| 2532 | XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 1); |
| 2533 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata) |
| 2537 | { |
| 2538 | unsigned int val; |
| 2539 | |
| 2540 | val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0; |
| 2541 | |
| 2542 | XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val); |
| 2543 | } |
| 2544 | |
Lendacky, Thomas | 916102c | 2015-01-16 12:46:45 -0600 | [diff] [blame] | 2545 | static void xgbe_config_mac_speed(struct xgbe_prv_data *pdata) |
| 2546 | { |
Lendacky, Thomas | e57f7a3 | 2016-11-03 13:18:27 -0500 | [diff] [blame] | 2547 | xgbe_set_speed(pdata, pdata->phy_speed); |
Lendacky, Thomas | 916102c | 2015-01-16 12:46:45 -0600 | [diff] [blame] | 2548 | } |
| 2549 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2550 | static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata) |
| 2551 | { |
| 2552 | if (pdata->netdev->features & NETIF_F_RXCSUM) |
| 2553 | xgbe_enable_rx_csum(pdata); |
| 2554 | else |
| 2555 | xgbe_disable_rx_csum(pdata); |
| 2556 | } |
| 2557 | |
| 2558 | static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata) |
| 2559 | { |
Lendacky, Thomas | 6e5eed0 | 2014-06-24 16:19:12 -0500 | [diff] [blame] | 2560 | /* Indicate that VLAN Tx CTAGs come from context descriptors */ |
| 2561 | XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0); |
| 2562 | XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1); |
| 2563 | |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 2564 | /* Set the current VLAN Hash Table register value */ |
| 2565 | xgbe_update_vlan_hash_table(pdata); |
| 2566 | |
| 2567 | if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER) |
| 2568 | xgbe_enable_rx_vlan_filtering(pdata); |
| 2569 | else |
| 2570 | xgbe_disable_rx_vlan_filtering(pdata); |
| 2571 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2572 | if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2573 | xgbe_enable_rx_vlan_stripping(pdata); |
| 2574 | else |
| 2575 | xgbe_disable_rx_vlan_stripping(pdata); |
| 2576 | } |
| 2577 | |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2578 | static u64 xgbe_mmc_read(struct xgbe_prv_data *pdata, unsigned int reg_lo) |
| 2579 | { |
| 2580 | bool read_hi; |
| 2581 | u64 val; |
| 2582 | |
Lendacky, Thomas | e5a20b9 | 2016-11-03 13:19:07 -0500 | [diff] [blame] | 2583 | if (pdata->vdata->mmc_64bit) { |
| 2584 | switch (reg_lo) { |
| 2585 | /* These registers are always 32 bit */ |
| 2586 | case MMC_RXRUNTERROR: |
| 2587 | case MMC_RXJABBERERROR: |
| 2588 | case MMC_RXUNDERSIZE_G: |
| 2589 | case MMC_RXOVERSIZE_G: |
| 2590 | case MMC_RXWATCHDOGERROR: |
| 2591 | read_hi = false; |
| 2592 | break; |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2593 | |
Lendacky, Thomas | e5a20b9 | 2016-11-03 13:19:07 -0500 | [diff] [blame] | 2594 | default: |
| 2595 | read_hi = true; |
| 2596 | } |
| 2597 | } else { |
| 2598 | switch (reg_lo) { |
| 2599 | /* These registers are always 64 bit */ |
| 2600 | case MMC_TXOCTETCOUNT_GB_LO: |
| 2601 | case MMC_TXOCTETCOUNT_G_LO: |
| 2602 | case MMC_RXOCTETCOUNT_GB_LO: |
| 2603 | case MMC_RXOCTETCOUNT_G_LO: |
| 2604 | read_hi = true; |
| 2605 | break; |
| 2606 | |
| 2607 | default: |
| 2608 | read_hi = false; |
| 2609 | } |
Lendacky, Thomas | 3947d78 | 2015-09-30 08:52:38 -0500 | [diff] [blame] | 2610 | } |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2611 | |
| 2612 | val = XGMAC_IOREAD(pdata, reg_lo); |
| 2613 | |
| 2614 | if (read_hi) |
| 2615 | val |= ((u64)XGMAC_IOREAD(pdata, reg_lo + 4) << 32); |
| 2616 | |
| 2617 | return val; |
| 2618 | } |
| 2619 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2620 | static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata) |
| 2621 | { |
| 2622 | struct xgbe_mmc_stats *stats = &pdata->mmc_stats; |
| 2623 | unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR); |
| 2624 | |
| 2625 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB)) |
| 2626 | stats->txoctetcount_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2627 | xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2628 | |
| 2629 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB)) |
| 2630 | stats->txframecount_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2631 | xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2632 | |
| 2633 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G)) |
| 2634 | stats->txbroadcastframes_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2635 | xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2636 | |
| 2637 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G)) |
| 2638 | stats->txmulticastframes_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2639 | xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2640 | |
| 2641 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB)) |
| 2642 | stats->tx64octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2643 | xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2644 | |
| 2645 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB)) |
| 2646 | stats->tx65to127octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2647 | xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2648 | |
| 2649 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB)) |
| 2650 | stats->tx128to255octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2651 | xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2652 | |
| 2653 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB)) |
| 2654 | stats->tx256to511octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2655 | xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2656 | |
| 2657 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB)) |
| 2658 | stats->tx512to1023octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2659 | xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2660 | |
| 2661 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB)) |
| 2662 | stats->tx1024tomaxoctets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2663 | xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2664 | |
| 2665 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB)) |
| 2666 | stats->txunicastframes_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2667 | xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2668 | |
| 2669 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB)) |
| 2670 | stats->txmulticastframes_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2671 | xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2672 | |
| 2673 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB)) |
| 2674 | stats->txbroadcastframes_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2675 | xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2676 | |
| 2677 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR)) |
| 2678 | stats->txunderflowerror += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2679 | xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2680 | |
| 2681 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G)) |
| 2682 | stats->txoctetcount_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2683 | xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2684 | |
| 2685 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G)) |
| 2686 | stats->txframecount_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2687 | xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2688 | |
| 2689 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES)) |
| 2690 | stats->txpauseframes += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2691 | xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2692 | |
| 2693 | if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G)) |
| 2694 | stats->txvlanframes_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2695 | xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata) |
| 2699 | { |
| 2700 | struct xgbe_mmc_stats *stats = &pdata->mmc_stats; |
| 2701 | unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR); |
| 2702 | |
| 2703 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB)) |
| 2704 | stats->rxframecount_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2705 | xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2706 | |
| 2707 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB)) |
| 2708 | stats->rxoctetcount_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2709 | xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2710 | |
| 2711 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G)) |
| 2712 | stats->rxoctetcount_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2713 | xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2714 | |
| 2715 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G)) |
| 2716 | stats->rxbroadcastframes_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2717 | xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2718 | |
| 2719 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G)) |
| 2720 | stats->rxmulticastframes_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2721 | xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2722 | |
| 2723 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR)) |
| 2724 | stats->rxcrcerror += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2725 | xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2726 | |
| 2727 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR)) |
| 2728 | stats->rxrunterror += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2729 | xgbe_mmc_read(pdata, MMC_RXRUNTERROR); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2730 | |
| 2731 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR)) |
| 2732 | stats->rxjabbererror += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2733 | xgbe_mmc_read(pdata, MMC_RXJABBERERROR); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2734 | |
| 2735 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G)) |
| 2736 | stats->rxundersize_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2737 | xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2738 | |
| 2739 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G)) |
| 2740 | stats->rxoversize_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2741 | xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2742 | |
| 2743 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB)) |
| 2744 | stats->rx64octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2745 | xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2746 | |
| 2747 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB)) |
| 2748 | stats->rx65to127octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2749 | xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2750 | |
| 2751 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB)) |
| 2752 | stats->rx128to255octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2753 | xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2754 | |
| 2755 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB)) |
| 2756 | stats->rx256to511octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2757 | xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2758 | |
| 2759 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB)) |
| 2760 | stats->rx512to1023octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2761 | xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2762 | |
| 2763 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB)) |
| 2764 | stats->rx1024tomaxoctets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2765 | xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2766 | |
| 2767 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G)) |
| 2768 | stats->rxunicastframes_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2769 | xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2770 | |
| 2771 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR)) |
| 2772 | stats->rxlengtherror += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2773 | xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2774 | |
| 2775 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE)) |
| 2776 | stats->rxoutofrangetype += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2777 | xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2778 | |
| 2779 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES)) |
| 2780 | stats->rxpauseframes += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2781 | xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2782 | |
| 2783 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW)) |
| 2784 | stats->rxfifooverflow += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2785 | xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2786 | |
| 2787 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB)) |
| 2788 | stats->rxvlanframes_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2789 | xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2790 | |
| 2791 | if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR)) |
| 2792 | stats->rxwatchdogerror += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2793 | xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata) |
| 2797 | { |
| 2798 | struct xgbe_mmc_stats *stats = &pdata->mmc_stats; |
| 2799 | |
| 2800 | /* Freeze counters */ |
| 2801 | XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1); |
| 2802 | |
| 2803 | stats->txoctetcount_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2804 | xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2805 | |
| 2806 | stats->txframecount_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2807 | xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2808 | |
| 2809 | stats->txbroadcastframes_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2810 | xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2811 | |
| 2812 | stats->txmulticastframes_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2813 | xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2814 | |
| 2815 | stats->tx64octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2816 | xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2817 | |
| 2818 | stats->tx65to127octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2819 | xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2820 | |
| 2821 | stats->tx128to255octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2822 | xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2823 | |
| 2824 | stats->tx256to511octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2825 | xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2826 | |
| 2827 | stats->tx512to1023octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2828 | xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2829 | |
| 2830 | stats->tx1024tomaxoctets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2831 | xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2832 | |
| 2833 | stats->txunicastframes_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2834 | xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2835 | |
| 2836 | stats->txmulticastframes_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2837 | xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2838 | |
| 2839 | stats->txbroadcastframes_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2840 | xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2841 | |
| 2842 | stats->txunderflowerror += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2843 | xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2844 | |
| 2845 | stats->txoctetcount_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2846 | xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2847 | |
| 2848 | stats->txframecount_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2849 | xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2850 | |
| 2851 | stats->txpauseframes += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2852 | xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2853 | |
| 2854 | stats->txvlanframes_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2855 | xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2856 | |
| 2857 | stats->rxframecount_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2858 | xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2859 | |
| 2860 | stats->rxoctetcount_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2861 | xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2862 | |
| 2863 | stats->rxoctetcount_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2864 | xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2865 | |
| 2866 | stats->rxbroadcastframes_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2867 | xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2868 | |
| 2869 | stats->rxmulticastframes_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2870 | xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2871 | |
| 2872 | stats->rxcrcerror += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2873 | xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2874 | |
| 2875 | stats->rxrunterror += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2876 | xgbe_mmc_read(pdata, MMC_RXRUNTERROR); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2877 | |
| 2878 | stats->rxjabbererror += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2879 | xgbe_mmc_read(pdata, MMC_RXJABBERERROR); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2880 | |
| 2881 | stats->rxundersize_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2882 | xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2883 | |
| 2884 | stats->rxoversize_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2885 | xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2886 | |
| 2887 | stats->rx64octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2888 | xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2889 | |
| 2890 | stats->rx65to127octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2891 | xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2892 | |
| 2893 | stats->rx128to255octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2894 | xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2895 | |
| 2896 | stats->rx256to511octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2897 | xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2898 | |
| 2899 | stats->rx512to1023octets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2900 | xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2901 | |
| 2902 | stats->rx1024tomaxoctets_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2903 | xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2904 | |
| 2905 | stats->rxunicastframes_g += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2906 | xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2907 | |
| 2908 | stats->rxlengtherror += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2909 | xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2910 | |
| 2911 | stats->rxoutofrangetype += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2912 | xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2913 | |
| 2914 | stats->rxpauseframes += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2915 | xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2916 | |
| 2917 | stats->rxfifooverflow += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2918 | xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2919 | |
| 2920 | stats->rxvlanframes_gb += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2921 | xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2922 | |
| 2923 | stats->rxwatchdogerror += |
Lendacky, Thomas | 6026510 | 2014-09-05 18:02:30 -0500 | [diff] [blame] | 2924 | xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2925 | |
| 2926 | /* Un-freeze counters */ |
| 2927 | XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0); |
| 2928 | } |
| 2929 | |
| 2930 | static void xgbe_config_mmc(struct xgbe_prv_data *pdata) |
| 2931 | { |
| 2932 | /* Set counters to reset on read */ |
| 2933 | XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1); |
| 2934 | |
| 2935 | /* Reset the counters */ |
| 2936 | XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1); |
| 2937 | } |
| 2938 | |
Lendacky, Thomas | 4b8acdf | 2016-11-03 13:19:17 -0500 | [diff] [blame] | 2939 | static void xgbe_txq_prepare_tx_stop(struct xgbe_prv_data *pdata, |
| 2940 | unsigned int queue) |
| 2941 | { |
| 2942 | unsigned int tx_status; |
| 2943 | unsigned long tx_timeout; |
| 2944 | |
| 2945 | /* The Tx engine cannot be stopped if it is actively processing |
| 2946 | * packets. Wait for the Tx queue to empty the Tx fifo. Don't |
| 2947 | * wait forever though... |
| 2948 | */ |
| 2949 | tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ); |
| 2950 | while (time_before(jiffies, tx_timeout)) { |
| 2951 | tx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_TQDR); |
| 2952 | if ((XGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TRCSTS) != 1) && |
| 2953 | (XGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TXQSTS) == 0)) |
| 2954 | break; |
| 2955 | |
| 2956 | usleep_range(500, 1000); |
| 2957 | } |
| 2958 | |
| 2959 | if (!time_before(jiffies, tx_timeout)) |
| 2960 | netdev_info(pdata->netdev, |
| 2961 | "timed out waiting for Tx queue %u to empty\n", |
| 2962 | queue); |
| 2963 | } |
| 2964 | |
Lendacky, Thomas | 16edd34 | 2014-11-20 11:03:32 -0600 | [diff] [blame] | 2965 | static void xgbe_prepare_tx_stop(struct xgbe_prv_data *pdata, |
Lendacky, Thomas | 4b8acdf | 2016-11-03 13:19:17 -0500 | [diff] [blame] | 2966 | unsigned int queue) |
Lendacky, Thomas | 16edd34 | 2014-11-20 11:03:32 -0600 | [diff] [blame] | 2967 | { |
| 2968 | unsigned int tx_dsr, tx_pos, tx_qidx; |
| 2969 | unsigned int tx_status; |
| 2970 | unsigned long tx_timeout; |
| 2971 | |
Lendacky, Thomas | 4b8acdf | 2016-11-03 13:19:17 -0500 | [diff] [blame] | 2972 | if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) > 0x20) |
| 2973 | return xgbe_txq_prepare_tx_stop(pdata, queue); |
| 2974 | |
Lendacky, Thomas | 16edd34 | 2014-11-20 11:03:32 -0600 | [diff] [blame] | 2975 | /* Calculate the status register to read and the position within */ |
Lendacky, Thomas | 4b8acdf | 2016-11-03 13:19:17 -0500 | [diff] [blame] | 2976 | if (queue < DMA_DSRX_FIRST_QUEUE) { |
Lendacky, Thomas | 16edd34 | 2014-11-20 11:03:32 -0600 | [diff] [blame] | 2977 | tx_dsr = DMA_DSR0; |
Lendacky, Thomas | 4b8acdf | 2016-11-03 13:19:17 -0500 | [diff] [blame] | 2978 | tx_pos = (queue * DMA_DSR_Q_WIDTH) + DMA_DSR0_TPS_START; |
Lendacky, Thomas | 16edd34 | 2014-11-20 11:03:32 -0600 | [diff] [blame] | 2979 | } else { |
Lendacky, Thomas | 4b8acdf | 2016-11-03 13:19:17 -0500 | [diff] [blame] | 2980 | tx_qidx = queue - DMA_DSRX_FIRST_QUEUE; |
Lendacky, Thomas | 16edd34 | 2014-11-20 11:03:32 -0600 | [diff] [blame] | 2981 | |
| 2982 | tx_dsr = DMA_DSR1 + ((tx_qidx / DMA_DSRX_QPR) * DMA_DSRX_INC); |
| 2983 | tx_pos = ((tx_qidx % DMA_DSRX_QPR) * DMA_DSR_Q_WIDTH) + |
| 2984 | DMA_DSRX_TPS_START; |
| 2985 | } |
| 2986 | |
| 2987 | /* The Tx engine cannot be stopped if it is actively processing |
| 2988 | * descriptors. Wait for the Tx engine to enter the stopped or |
| 2989 | * suspended state. Don't wait forever though... |
| 2990 | */ |
| 2991 | tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ); |
| 2992 | while (time_before(jiffies, tx_timeout)) { |
| 2993 | tx_status = XGMAC_IOREAD(pdata, tx_dsr); |
| 2994 | tx_status = GET_BITS(tx_status, tx_pos, DMA_DSR_TPS_WIDTH); |
| 2995 | if ((tx_status == DMA_TPS_STOPPED) || |
| 2996 | (tx_status == DMA_TPS_SUSPENDED)) |
| 2997 | break; |
| 2998 | |
| 2999 | usleep_range(500, 1000); |
| 3000 | } |
| 3001 | |
| 3002 | if (!time_before(jiffies, tx_timeout)) |
| 3003 | netdev_info(pdata->netdev, |
| 3004 | "timed out waiting for Tx DMA channel %u to stop\n", |
Lendacky, Thomas | 4b8acdf | 2016-11-03 13:19:17 -0500 | [diff] [blame] | 3005 | queue); |
Lendacky, Thomas | 16edd34 | 2014-11-20 11:03:32 -0600 | [diff] [blame] | 3006 | } |
| 3007 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3008 | static void xgbe_enable_tx(struct xgbe_prv_data *pdata) |
| 3009 | { |
| 3010 | struct xgbe_channel *channel; |
| 3011 | unsigned int i; |
| 3012 | |
| 3013 | /* Enable each Tx DMA channel */ |
| 3014 | channel = pdata->channel; |
| 3015 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 3016 | if (!channel->tx_ring) |
| 3017 | break; |
| 3018 | |
| 3019 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1); |
| 3020 | } |
| 3021 | |
| 3022 | /* Enable each Tx queue */ |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 3023 | for (i = 0; i < pdata->tx_q_count; i++) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3024 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, |
| 3025 | MTL_Q_ENABLED); |
| 3026 | |
| 3027 | /* Enable MAC Tx */ |
| 3028 | XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1); |
| 3029 | } |
| 3030 | |
| 3031 | static void xgbe_disable_tx(struct xgbe_prv_data *pdata) |
| 3032 | { |
| 3033 | struct xgbe_channel *channel; |
| 3034 | unsigned int i; |
| 3035 | |
Lendacky, Thomas | 16edd34 | 2014-11-20 11:03:32 -0600 | [diff] [blame] | 3036 | /* Prepare for Tx DMA channel stop */ |
Lendacky, Thomas | 4b8acdf | 2016-11-03 13:19:17 -0500 | [diff] [blame] | 3037 | for (i = 0; i < pdata->tx_q_count; i++) |
| 3038 | xgbe_prepare_tx_stop(pdata, i); |
Lendacky, Thomas | 16edd34 | 2014-11-20 11:03:32 -0600 | [diff] [blame] | 3039 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3040 | /* Disable MAC Tx */ |
| 3041 | XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0); |
| 3042 | |
| 3043 | /* Disable each Tx queue */ |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 3044 | for (i = 0; i < pdata->tx_q_count; i++) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3045 | XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0); |
| 3046 | |
| 3047 | /* Disable each Tx DMA channel */ |
| 3048 | channel = pdata->channel; |
| 3049 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 3050 | if (!channel->tx_ring) |
| 3051 | break; |
| 3052 | |
| 3053 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0); |
| 3054 | } |
| 3055 | } |
| 3056 | |
Lendacky, Thomas | c3727d6 | 2016-02-17 11:49:16 -0600 | [diff] [blame] | 3057 | static void xgbe_prepare_rx_stop(struct xgbe_prv_data *pdata, |
| 3058 | unsigned int queue) |
| 3059 | { |
| 3060 | unsigned int rx_status; |
| 3061 | unsigned long rx_timeout; |
| 3062 | |
| 3063 | /* The Rx engine cannot be stopped if it is actively processing |
| 3064 | * packets. Wait for the Rx queue to empty the Rx fifo. Don't |
| 3065 | * wait forever though... |
| 3066 | */ |
| 3067 | rx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ); |
| 3068 | while (time_before(jiffies, rx_timeout)) { |
| 3069 | rx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_RQDR); |
| 3070 | if ((XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, PRXQ) == 0) && |
| 3071 | (XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, RXQSTS) == 0)) |
| 3072 | break; |
| 3073 | |
| 3074 | usleep_range(500, 1000); |
| 3075 | } |
| 3076 | |
| 3077 | if (!time_before(jiffies, rx_timeout)) |
| 3078 | netdev_info(pdata->netdev, |
| 3079 | "timed out waiting for Rx queue %u to empty\n", |
| 3080 | queue); |
| 3081 | } |
| 3082 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3083 | static void xgbe_enable_rx(struct xgbe_prv_data *pdata) |
| 3084 | { |
| 3085 | struct xgbe_channel *channel; |
| 3086 | unsigned int reg_val, i; |
| 3087 | |
| 3088 | /* Enable each Rx DMA channel */ |
| 3089 | channel = pdata->channel; |
| 3090 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 3091 | if (!channel->rx_ring) |
| 3092 | break; |
| 3093 | |
| 3094 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1); |
| 3095 | } |
| 3096 | |
| 3097 | /* Enable each Rx queue */ |
| 3098 | reg_val = 0; |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 3099 | for (i = 0; i < pdata->rx_q_count; i++) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3100 | reg_val |= (0x02 << (i << 1)); |
| 3101 | XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val); |
| 3102 | |
| 3103 | /* Enable MAC Rx */ |
| 3104 | XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1); |
| 3105 | XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1); |
| 3106 | XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1); |
| 3107 | XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1); |
| 3108 | } |
| 3109 | |
| 3110 | static void xgbe_disable_rx(struct xgbe_prv_data *pdata) |
| 3111 | { |
| 3112 | struct xgbe_channel *channel; |
| 3113 | unsigned int i; |
| 3114 | |
| 3115 | /* Disable MAC Rx */ |
| 3116 | XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0); |
| 3117 | XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0); |
| 3118 | XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0); |
| 3119 | XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0); |
| 3120 | |
Lendacky, Thomas | c3727d6 | 2016-02-17 11:49:16 -0600 | [diff] [blame] | 3121 | /* Prepare for Rx DMA channel stop */ |
| 3122 | for (i = 0; i < pdata->rx_q_count; i++) |
| 3123 | xgbe_prepare_rx_stop(pdata, i); |
| 3124 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3125 | /* Disable each Rx queue */ |
| 3126 | XGMAC_IOWRITE(pdata, MAC_RQC0R, 0); |
| 3127 | |
| 3128 | /* Disable each Rx DMA channel */ |
| 3129 | channel = pdata->channel; |
| 3130 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 3131 | if (!channel->rx_ring) |
| 3132 | break; |
| 3133 | |
| 3134 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0); |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | static void xgbe_powerup_tx(struct xgbe_prv_data *pdata) |
| 3139 | { |
| 3140 | struct xgbe_channel *channel; |
| 3141 | unsigned int i; |
| 3142 | |
| 3143 | /* Enable each Tx DMA channel */ |
| 3144 | channel = pdata->channel; |
| 3145 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 3146 | if (!channel->tx_ring) |
| 3147 | break; |
| 3148 | |
| 3149 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1); |
| 3150 | } |
| 3151 | |
| 3152 | /* Enable MAC Tx */ |
| 3153 | XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1); |
| 3154 | } |
| 3155 | |
| 3156 | static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata) |
| 3157 | { |
| 3158 | struct xgbe_channel *channel; |
| 3159 | unsigned int i; |
| 3160 | |
Lendacky, Thomas | 16edd34 | 2014-11-20 11:03:32 -0600 | [diff] [blame] | 3161 | /* Prepare for Tx DMA channel stop */ |
Lendacky, Thomas | 4b8acdf | 2016-11-03 13:19:17 -0500 | [diff] [blame] | 3162 | for (i = 0; i < pdata->tx_q_count; i++) |
| 3163 | xgbe_prepare_tx_stop(pdata, i); |
Lendacky, Thomas | 16edd34 | 2014-11-20 11:03:32 -0600 | [diff] [blame] | 3164 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3165 | /* Disable MAC Tx */ |
| 3166 | XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0); |
| 3167 | |
| 3168 | /* Disable each Tx DMA channel */ |
| 3169 | channel = pdata->channel; |
| 3170 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 3171 | if (!channel->tx_ring) |
| 3172 | break; |
| 3173 | |
| 3174 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0); |
| 3175 | } |
| 3176 | } |
| 3177 | |
| 3178 | static void xgbe_powerup_rx(struct xgbe_prv_data *pdata) |
| 3179 | { |
| 3180 | struct xgbe_channel *channel; |
| 3181 | unsigned int i; |
| 3182 | |
| 3183 | /* Enable each Rx DMA channel */ |
| 3184 | channel = pdata->channel; |
| 3185 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 3186 | if (!channel->rx_ring) |
| 3187 | break; |
| 3188 | |
| 3189 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1); |
| 3190 | } |
| 3191 | } |
| 3192 | |
| 3193 | static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata) |
| 3194 | { |
| 3195 | struct xgbe_channel *channel; |
| 3196 | unsigned int i; |
| 3197 | |
| 3198 | /* Disable each Rx DMA channel */ |
| 3199 | channel = pdata->channel; |
| 3200 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 3201 | if (!channel->rx_ring) |
| 3202 | break; |
| 3203 | |
| 3204 | XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0); |
| 3205 | } |
| 3206 | } |
| 3207 | |
| 3208 | static int xgbe_init(struct xgbe_prv_data *pdata) |
| 3209 | { |
| 3210 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 3211 | int ret; |
| 3212 | |
| 3213 | DBGPR("-->xgbe_init\n"); |
| 3214 | |
| 3215 | /* Flush Tx queues */ |
| 3216 | ret = xgbe_flush_tx_queues(pdata); |
| 3217 | if (ret) |
| 3218 | return ret; |
| 3219 | |
| 3220 | /* |
| 3221 | * Initialize DMA related features |
| 3222 | */ |
| 3223 | xgbe_config_dma_bus(pdata); |
| 3224 | xgbe_config_dma_cache(pdata); |
| 3225 | xgbe_config_osp_mode(pdata); |
| 3226 | xgbe_config_pblx8(pdata); |
| 3227 | xgbe_config_tx_pbl_val(pdata); |
| 3228 | xgbe_config_rx_pbl_val(pdata); |
| 3229 | xgbe_config_rx_coalesce(pdata); |
| 3230 | xgbe_config_tx_coalesce(pdata); |
| 3231 | xgbe_config_rx_buffer_size(pdata); |
| 3232 | xgbe_config_tso_mode(pdata); |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 3233 | xgbe_config_sph_mode(pdata); |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 3234 | xgbe_config_rss(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3235 | desc_if->wrapper_tx_desc_init(pdata); |
| 3236 | desc_if->wrapper_rx_desc_init(pdata); |
| 3237 | xgbe_enable_dma_interrupts(pdata); |
| 3238 | |
| 3239 | /* |
| 3240 | * Initialize MTL related features |
| 3241 | */ |
| 3242 | xgbe_config_mtl_mode(pdata); |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 3243 | xgbe_config_queue_mapping(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3244 | xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode); |
| 3245 | xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode); |
| 3246 | xgbe_config_tx_threshold(pdata, pdata->tx_threshold); |
| 3247 | xgbe_config_rx_threshold(pdata, pdata->rx_threshold); |
| 3248 | xgbe_config_tx_fifo_size(pdata); |
| 3249 | xgbe_config_rx_fifo_size(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3250 | /*TODO: Error Packet and undersized good Packet forwarding enable |
| 3251 | (FEP and FUP) |
| 3252 | */ |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 3253 | xgbe_config_dcb_tc(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3254 | xgbe_enable_mtl_interrupts(pdata); |
| 3255 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3256 | /* |
| 3257 | * Initialize MAC related features |
| 3258 | */ |
| 3259 | xgbe_config_mac_address(pdata); |
Lendacky, Thomas | b876382 | 2015-04-09 12:11:57 -0500 | [diff] [blame] | 3260 | xgbe_config_rx_mode(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3261 | xgbe_config_jumbo_enable(pdata); |
| 3262 | xgbe_config_flow_control(pdata); |
Lendacky, Thomas | 916102c | 2015-01-16 12:46:45 -0600 | [diff] [blame] | 3263 | xgbe_config_mac_speed(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3264 | xgbe_config_checksum_offload(pdata); |
| 3265 | xgbe_config_vlan_support(pdata); |
| 3266 | xgbe_config_mmc(pdata); |
| 3267 | xgbe_enable_mac_interrupts(pdata); |
| 3268 | |
| 3269 | DBGPR("<--xgbe_init\n"); |
| 3270 | |
| 3271 | return 0; |
| 3272 | } |
| 3273 | |
| 3274 | void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if) |
| 3275 | { |
| 3276 | DBGPR("-->xgbe_init_function_ptrs\n"); |
| 3277 | |
| 3278 | hw_if->tx_complete = xgbe_tx_complete; |
| 3279 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3280 | hw_if->set_mac_address = xgbe_set_mac_address; |
Lendacky, Thomas | b876382 | 2015-04-09 12:11:57 -0500 | [diff] [blame] | 3281 | hw_if->config_rx_mode = xgbe_config_rx_mode; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3282 | |
| 3283 | hw_if->enable_rx_csum = xgbe_enable_rx_csum; |
| 3284 | hw_if->disable_rx_csum = xgbe_disable_rx_csum; |
| 3285 | |
| 3286 | hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping; |
| 3287 | hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping; |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 3288 | hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering; |
| 3289 | hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering; |
| 3290 | hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3291 | |
| 3292 | hw_if->read_mmd_regs = xgbe_read_mmd_regs; |
| 3293 | hw_if->write_mmd_regs = xgbe_write_mmd_regs; |
| 3294 | |
Lendacky, Thomas | e57f7a3 | 2016-11-03 13:18:27 -0500 | [diff] [blame] | 3295 | hw_if->set_speed = xgbe_set_speed; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3296 | |
| 3297 | hw_if->enable_tx = xgbe_enable_tx; |
| 3298 | hw_if->disable_tx = xgbe_disable_tx; |
| 3299 | hw_if->enable_rx = xgbe_enable_rx; |
| 3300 | hw_if->disable_rx = xgbe_disable_rx; |
| 3301 | |
| 3302 | hw_if->powerup_tx = xgbe_powerup_tx; |
| 3303 | hw_if->powerdown_tx = xgbe_powerdown_tx; |
| 3304 | hw_if->powerup_rx = xgbe_powerup_rx; |
| 3305 | hw_if->powerdown_rx = xgbe_powerdown_rx; |
| 3306 | |
Lendacky, Thomas | a9d4198 | 2014-11-04 16:06:32 -0600 | [diff] [blame] | 3307 | hw_if->dev_xmit = xgbe_dev_xmit; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3308 | hw_if->dev_read = xgbe_dev_read; |
| 3309 | hw_if->enable_int = xgbe_enable_int; |
| 3310 | hw_if->disable_int = xgbe_disable_int; |
| 3311 | hw_if->init = xgbe_init; |
| 3312 | hw_if->exit = xgbe_exit; |
| 3313 | |
| 3314 | /* Descriptor related Sequences have to be initialized here */ |
| 3315 | hw_if->tx_desc_init = xgbe_tx_desc_init; |
| 3316 | hw_if->rx_desc_init = xgbe_rx_desc_init; |
| 3317 | hw_if->tx_desc_reset = xgbe_tx_desc_reset; |
| 3318 | hw_if->rx_desc_reset = xgbe_rx_desc_reset; |
| 3319 | hw_if->is_last_desc = xgbe_is_last_desc; |
| 3320 | hw_if->is_context_desc = xgbe_is_context_desc; |
Lendacky, Thomas | 16958a2 | 2014-11-20 11:04:08 -0600 | [diff] [blame] | 3321 | hw_if->tx_start_xmit = xgbe_tx_start_xmit; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3322 | |
| 3323 | /* For FLOW ctrl */ |
| 3324 | hw_if->config_tx_flow_control = xgbe_config_tx_flow_control; |
| 3325 | hw_if->config_rx_flow_control = xgbe_config_rx_flow_control; |
| 3326 | |
| 3327 | /* For RX coalescing */ |
| 3328 | hw_if->config_rx_coalesce = xgbe_config_rx_coalesce; |
| 3329 | hw_if->config_tx_coalesce = xgbe_config_tx_coalesce; |
| 3330 | hw_if->usec_to_riwt = xgbe_usec_to_riwt; |
| 3331 | hw_if->riwt_to_usec = xgbe_riwt_to_usec; |
| 3332 | |
| 3333 | /* For RX and TX threshold config */ |
| 3334 | hw_if->config_rx_threshold = xgbe_config_rx_threshold; |
| 3335 | hw_if->config_tx_threshold = xgbe_config_tx_threshold; |
| 3336 | |
| 3337 | /* For RX and TX Store and Forward Mode config */ |
| 3338 | hw_if->config_rsf_mode = xgbe_config_rsf_mode; |
| 3339 | hw_if->config_tsf_mode = xgbe_config_tsf_mode; |
| 3340 | |
| 3341 | /* For TX DMA Operating on Second Frame config */ |
| 3342 | hw_if->config_osp_mode = xgbe_config_osp_mode; |
| 3343 | |
| 3344 | /* For RX and TX PBL config */ |
| 3345 | hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val; |
| 3346 | hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val; |
| 3347 | hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val; |
| 3348 | hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val; |
| 3349 | hw_if->config_pblx8 = xgbe_config_pblx8; |
| 3350 | |
| 3351 | /* For MMC statistics support */ |
| 3352 | hw_if->tx_mmc_int = xgbe_tx_mmc_int; |
| 3353 | hw_if->rx_mmc_int = xgbe_rx_mmc_int; |
| 3354 | hw_if->read_mmc_stats = xgbe_read_mmc_stats; |
| 3355 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 3356 | /* For PTP config */ |
| 3357 | hw_if->config_tstamp = xgbe_config_tstamp; |
| 3358 | hw_if->update_tstamp_addend = xgbe_update_tstamp_addend; |
| 3359 | hw_if->set_tstamp_time = xgbe_set_tstamp_time; |
| 3360 | hw_if->get_tstamp_time = xgbe_get_tstamp_time; |
| 3361 | hw_if->get_tx_tstamp = xgbe_get_tx_tstamp; |
| 3362 | |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 3363 | /* For Data Center Bridging config */ |
Lendacky, Thomas | b3b7159 | 2016-02-17 11:49:08 -0600 | [diff] [blame] | 3364 | hw_if->config_tc = xgbe_config_tc; |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 3365 | hw_if->config_dcb_tc = xgbe_config_dcb_tc; |
| 3366 | hw_if->config_dcb_pfc = xgbe_config_dcb_pfc; |
| 3367 | |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 3368 | /* For Receive Side Scaling */ |
| 3369 | hw_if->enable_rss = xgbe_enable_rss; |
| 3370 | hw_if->disable_rss = xgbe_disable_rss; |
Lendacky, Thomas | f6ac862 | 2014-11-04 16:07:23 -0600 | [diff] [blame] | 3371 | hw_if->set_rss_hash_key = xgbe_set_rss_hash_key; |
| 3372 | hw_if->set_rss_lookup_table = xgbe_set_rss_lookup_table; |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 3373 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 3374 | DBGPR("<--xgbe_init_function_ptrs\n"); |
| 3375 | } |