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