stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Ingo Assmus <ingo.assmus@keymile.com> |
| 4 | * |
| 5 | * based on - Driver for MV64360X ethernet ports |
| 6 | * Copyright (C) 2002 rabeeh@galileo.co.il |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU 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, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | /* |
| 28 | * mv_eth.c - header file for the polled mode GT ethernet driver |
| 29 | */ |
| 30 | #include <common.h> |
| 31 | #include <net.h> |
| 32 | #include <malloc.h> |
| 33 | |
| 34 | #include "mv_eth.h" |
| 35 | |
| 36 | /* enable Debug outputs */ |
| 37 | |
| 38 | #undef DEBUG_MV_ETH |
| 39 | |
| 40 | #ifdef DEBUG_MV_ETH |
| 41 | #define DEBUG |
| 42 | #define DP(x) x |
| 43 | #else |
| 44 | #define DP(x) |
| 45 | #endif |
| 46 | |
| 47 | #undef MV64360_CHECKSUM_OFFLOAD |
| 48 | /************************************************************************* |
| 49 | ************************************************************************** |
| 50 | ************************************************************************** |
| 51 | * The first part is the high level driver of the gigE ethernet ports. * |
| 52 | ************************************************************************** |
| 53 | ************************************************************************** |
| 54 | *************************************************************************/ |
| 55 | |
| 56 | /* Definition for configuring driver */ |
| 57 | /* #define UPDATE_STATS_BY_SOFTWARE */ |
| 58 | #undef MV64360_RX_QUEUE_FILL_ON_TASK |
| 59 | |
| 60 | |
| 61 | /* Constants */ |
| 62 | #define MAGIC_ETH_RUNNING 8031971 |
| 63 | #define MV64360_INTERNAL_SRAM_SIZE _256K |
| 64 | #define EXTRA_BYTES 32 |
| 65 | #define WRAP ETH_HLEN + 2 + 4 + 16 |
| 66 | #define BUFFER_MTU dev->mtu + WRAP |
| 67 | #define INT_CAUSE_UNMASK_ALL 0x0007ffff |
| 68 | #define INT_CAUSE_UNMASK_ALL_EXT 0x0011ffff |
| 69 | #ifdef MV64360_RX_FILL_ON_TASK |
| 70 | #define INT_CAUSE_MASK_ALL 0x00000000 |
| 71 | #define INT_CAUSE_CHECK_BITS INT_CAUSE_UNMASK_ALL |
| 72 | #define INT_CAUSE_CHECK_BITS_EXT INT_CAUSE_UNMASK_ALL_EXT |
| 73 | #endif |
| 74 | |
| 75 | /* Read/Write to/from MV64360 internal registers */ |
| 76 | #define MV_REG_READ(offset) my_le32_to_cpu(* (volatile unsigned int *) (INTERNAL_REG_BASE_ADDR + offset)) |
| 77 | #define MV_REG_WRITE(offset,data) *(volatile unsigned int *) (INTERNAL_REG_BASE_ADDR + offset) = my_cpu_to_le32 (data) |
| 78 | #define MV_SET_REG_BITS(regOffset,bits) ((*((volatile unsigned int*)((INTERNAL_REG_BASE_ADDR) + (regOffset)))) |= ((unsigned int)my_cpu_to_le32(bits))) |
| 79 | #define MV_RESET_REG_BITS(regOffset,bits) ((*((volatile unsigned int*)((INTERNAL_REG_BASE_ADDR) + (regOffset)))) &= ~((unsigned int)my_cpu_to_le32(bits))) |
| 80 | |
| 81 | /* Static function declarations */ |
| 82 | static int mv64360_eth_real_open (struct eth_device *eth); |
| 83 | static int mv64360_eth_real_stop (struct eth_device *eth); |
| 84 | static struct net_device_stats *mv64360_eth_get_stats (struct eth_device |
| 85 | *dev); |
| 86 | static void eth_port_init_mac_tables (ETH_PORT eth_port_num); |
| 87 | static void mv64360_eth_update_stat (struct eth_device *dev); |
| 88 | bool db64360_eth_start (struct eth_device *eth); |
| 89 | unsigned int eth_read_mib_counter (ETH_PORT eth_port_num, |
| 90 | unsigned int mib_offset); |
| 91 | int mv64360_eth_receive (struct eth_device *dev); |
| 92 | |
| 93 | int mv64360_eth_xmit (struct eth_device *, volatile void *packet, int length); |
| 94 | |
| 95 | #ifndef UPDATE_STATS_BY_SOFTWARE |
| 96 | static void mv64360_eth_print_stat (struct eth_device *dev); |
| 97 | #endif |
| 98 | /* Processes a received packet */ |
| 99 | extern void NetReceive (volatile uchar *, int); |
| 100 | |
| 101 | extern unsigned int INTERNAL_REG_BASE_ADDR; |
| 102 | |
| 103 | /************************************************* |
| 104 | *Helper functions - used inside the driver only * |
| 105 | *************************************************/ |
| 106 | #ifdef DEBUG_MV_ETH |
| 107 | void print_globals (struct eth_device *dev) |
| 108 | { |
| 109 | printf ("Ethernet PRINT_Globals-Debug function\n"); |
| 110 | printf ("Base Address for ETH_PORT_INFO: %08x\n", |
| 111 | (unsigned int) dev->priv); |
| 112 | printf ("Base Address for mv64360_eth_priv: %08x\n", |
| 113 | (unsigned int) &(((ETH_PORT_INFO *) dev->priv)-> |
| 114 | port_private)); |
| 115 | |
| 116 | printf ("GT Internal Base Address: %08x\n", |
| 117 | INTERNAL_REG_BASE_ADDR); |
| 118 | printf ("Base Address for TX-DESCs: %08x Number of allocated Buffers %d\n", (unsigned int) ((ETH_PORT_INFO *) dev->priv)->p_tx_desc_area_base[0], MV64360_TX_QUEUE_SIZE); |
| 119 | printf ("Base Address for RX-DESCs: %08x Number of allocated Buffers %d\n", (unsigned int) ((ETH_PORT_INFO *) dev->priv)->p_rx_desc_area_base[0], MV64360_RX_QUEUE_SIZE); |
| 120 | printf ("Base Address for RX-Buffer: %08x allocated Bytes %d\n", |
| 121 | (unsigned int) ((ETH_PORT_INFO *) dev->priv)-> |
| 122 | p_rx_buffer_base[0], |
| 123 | (MV64360_RX_QUEUE_SIZE * MV64360_RX_BUFFER_SIZE) + 32); |
| 124 | printf ("Base Address for TX-Buffer: %08x allocated Bytes %d\n", |
| 125 | (unsigned int) ((ETH_PORT_INFO *) dev->priv)-> |
| 126 | p_tx_buffer_base[0], |
| 127 | (MV64360_TX_QUEUE_SIZE * MV64360_TX_BUFFER_SIZE) + 32); |
| 128 | } |
| 129 | #endif |
| 130 | |
| 131 | #define my_cpu_to_le32(x) my_le32_to_cpu((x)) |
| 132 | |
| 133 | unsigned long my_le32_to_cpu (unsigned long x) |
| 134 | { |
| 135 | return (((x & 0x000000ffU) << 24) | |
| 136 | ((x & 0x0000ff00U) << 8) | |
| 137 | ((x & 0x00ff0000U) >> 8) | ((x & 0xff000000U) >> 24)); |
| 138 | } |
| 139 | |
| 140 | |
| 141 | /********************************************************************** |
| 142 | * mv64360_eth_print_phy_status |
| 143 | * |
| 144 | * Prints gigabit ethenret phy status |
| 145 | * |
| 146 | * Input : pointer to ethernet interface network device structure |
| 147 | * Output : N/A |
| 148 | **********************************************************************/ |
| 149 | |
| 150 | static void mv64360_eth_print_phy_status (struct eth_device *dev) |
| 151 | { |
| 152 | struct mv64360_eth_priv *port_private; |
| 153 | unsigned int port_num; |
| 154 | ETH_PORT_INFO *ethernet_private = (ETH_PORT_INFO *) dev->priv; |
| 155 | unsigned int port_status, phy_reg_data; |
| 156 | |
| 157 | port_private = |
| 158 | (struct mv64360_eth_priv *) ethernet_private->port_private; |
| 159 | port_num = port_private->port_num; |
| 160 | |
| 161 | /* Check Link status on phy */ |
| 162 | eth_port_read_smi_reg (port_num, 1, &phy_reg_data); |
| 163 | if (!(phy_reg_data & 0x20)) { |
| 164 | printf ("Ethernet port changed link status to DOWN\n"); |
| 165 | } else { |
| 166 | port_status = |
| 167 | MV_REG_READ (MV64360_ETH_PORT_STATUS_REG (port_num)); |
| 168 | printf ("Ethernet status port %d: Link up", port_num); |
| 169 | printf (", %s", |
| 170 | (port_status & BIT2) ? "Full Duplex" : "Half Duplex"); |
| 171 | if (port_status & BIT4) |
| 172 | printf (", Speed 1 Gbps"); |
| 173 | else |
| 174 | printf (", %s", |
| 175 | (port_status & BIT5) ? "Speed 100 Mbps" : |
| 176 | "Speed 10 Mbps"); |
| 177 | printf ("\n"); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | /********************************************************************** |
| 182 | * u-boot entry functions for mv64360_eth |
| 183 | * |
| 184 | **********************************************************************/ |
| 185 | int db64360_eth_probe (struct eth_device *dev) |
| 186 | { |
| 187 | return ((int) db64360_eth_start (dev)); |
| 188 | } |
| 189 | |
| 190 | int db64360_eth_poll (struct eth_device *dev) |
| 191 | { |
| 192 | return mv64360_eth_receive (dev); |
| 193 | } |
| 194 | |
| 195 | int db64360_eth_transmit (struct eth_device *dev, volatile void *packet, |
| 196 | int length) |
| 197 | { |
| 198 | mv64360_eth_xmit (dev, packet, length); |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | void db64360_eth_disable (struct eth_device *dev) |
| 203 | { |
| 204 | mv64360_eth_stop (dev); |
| 205 | } |
| 206 | |
| 207 | |
| 208 | void mv6436x_eth_initialize (bd_t * bis) |
| 209 | { |
| 210 | struct eth_device *dev; |
| 211 | ETH_PORT_INFO *ethernet_private; |
| 212 | struct mv64360_eth_priv *port_private; |
| 213 | int devnum, x, temp; |
| 214 | char *s, *e, buf[64]; |
| 215 | |
| 216 | for (devnum = 0; devnum < MV_ETH_DEVS; devnum++) { |
| 217 | dev = calloc (sizeof (*dev), 1); |
| 218 | if (!dev) { |
| 219 | printf ("%s: mv_enet%d allocation failure, %s\n", |
| 220 | __FUNCTION__, devnum, "eth_device structure"); |
| 221 | return; |
| 222 | } |
| 223 | |
Mike Frysinger | f6add13 | 2011-11-10 14:11:04 +0000 | [diff] [blame] | 224 | /* must be less than sizeof(dev->name) */ |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 225 | sprintf (dev->name, "mv_enet%d", devnum); |
| 226 | |
| 227 | #ifdef DEBUG |
| 228 | printf ("Initializing %s\n", dev->name); |
| 229 | #endif |
| 230 | |
| 231 | /* Extract the MAC address from the environment */ |
| 232 | switch (devnum) { |
| 233 | case 0: |
| 234 | s = "ethaddr"; |
| 235 | break; |
| 236 | |
| 237 | case 1: |
| 238 | s = "eth1addr"; |
| 239 | break; |
| 240 | |
| 241 | case 2: |
| 242 | s = "eth2addr"; |
| 243 | break; |
| 244 | |
| 245 | default: /* this should never happen */ |
| 246 | printf ("%s: Invalid device number %d\n", |
| 247 | __FUNCTION__, devnum); |
| 248 | return; |
| 249 | } |
| 250 | |
Wolfgang Denk | cdb7497 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 251 | temp = getenv_f(s, buf, sizeof (buf)); |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 252 | s = (temp > 0) ? buf : NULL; |
| 253 | |
| 254 | #ifdef DEBUG |
| 255 | printf ("Setting MAC %d to %s\n", devnum, s); |
| 256 | #endif |
| 257 | for (x = 0; x < 6; ++x) { |
| 258 | dev->enetaddr[x] = s ? simple_strtoul (s, &e, 16) : 0; |
| 259 | if (s) |
| 260 | s = (*e) ? e + 1 : e; |
| 261 | } |
| 262 | /* ronen - set the MAC addr in the HW */ |
| 263 | eth_port_uc_addr_set (devnum, dev->enetaddr, 0); |
| 264 | |
| 265 | dev->init = (void *) db64360_eth_probe; |
| 266 | dev->halt = (void *) ethernet_phy_reset; |
| 267 | dev->send = (void *) db64360_eth_transmit; |
| 268 | dev->recv = (void *) db64360_eth_poll; |
| 269 | |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 270 | ethernet_private = |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 271 | calloc (sizeof (*ethernet_private), 1); |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 272 | dev->priv = (void *) ethernet_private; |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 273 | if (!ethernet_private) { |
| 274 | printf ("%s: %s allocation failure, %s\n", |
| 275 | __FUNCTION__, dev->name, |
| 276 | "Private Device Structure"); |
| 277 | free (dev); |
| 278 | return; |
| 279 | } |
| 280 | /* start with an zeroed ETH_PORT_INFO */ |
| 281 | memset (ethernet_private, 0, sizeof (ETH_PORT_INFO)); |
| 282 | memcpy (ethernet_private->port_mac_addr, dev->enetaddr, 6); |
| 283 | |
| 284 | /* set pointer to memory for stats data structure etc... */ |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 285 | port_private = |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 286 | calloc (sizeof (*ethernet_private), 1); |
Wolfgang Denk | f013dac | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 287 | ethernet_private->port_private = (void *)port_private; |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 288 | if (!port_private) { |
| 289 | printf ("%s: %s allocation failure, %s\n", |
| 290 | __FUNCTION__, dev->name, |
| 291 | "Port Private Device Structure"); |
| 292 | |
| 293 | free (ethernet_private); |
| 294 | free (dev); |
| 295 | return; |
| 296 | } |
| 297 | |
| 298 | port_private->stats = |
| 299 | calloc (sizeof (struct net_device_stats), 1); |
| 300 | if (!port_private->stats) { |
| 301 | printf ("%s: %s allocation failure, %s\n", |
| 302 | __FUNCTION__, dev->name, |
| 303 | "Net stat Structure"); |
| 304 | |
| 305 | free (port_private); |
| 306 | free (ethernet_private); |
| 307 | free (dev); |
| 308 | return; |
| 309 | } |
| 310 | memset (ethernet_private->port_private, 0, |
| 311 | sizeof (struct mv64360_eth_priv)); |
| 312 | switch (devnum) { |
| 313 | case 0: |
| 314 | ethernet_private->port_num = ETH_0; |
| 315 | break; |
| 316 | case 1: |
| 317 | ethernet_private->port_num = ETH_1; |
| 318 | break; |
| 319 | case 2: |
| 320 | ethernet_private->port_num = ETH_2; |
| 321 | break; |
| 322 | default: |
| 323 | printf ("Invalid device number %d\n", devnum); |
| 324 | break; |
| 325 | }; |
| 326 | |
| 327 | port_private->port_num = devnum; |
| 328 | /* |
| 329 | * Read MIB counter on the GT in order to reset them, |
| 330 | * then zero all the stats fields in memory |
| 331 | */ |
| 332 | mv64360_eth_update_stat (dev); |
| 333 | memset (port_private->stats, 0, |
| 334 | sizeof (struct net_device_stats)); |
| 335 | /* Extract the MAC address from the environment */ |
| 336 | switch (devnum) { |
| 337 | case 0: |
| 338 | s = "ethaddr"; |
| 339 | break; |
| 340 | |
| 341 | case 1: |
| 342 | s = "eth1addr"; |
| 343 | break; |
| 344 | |
| 345 | case 2: |
| 346 | s = "eth2addr"; |
| 347 | break; |
| 348 | |
| 349 | default: /* this should never happen */ |
| 350 | printf ("%s: Invalid device number %d\n", |
| 351 | __FUNCTION__, devnum); |
| 352 | return; |
| 353 | } |
| 354 | |
Wolfgang Denk | cdb7497 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 355 | temp = getenv_f(s, buf, sizeof (buf)); |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 356 | s = (temp > 0) ? buf : NULL; |
| 357 | |
| 358 | #ifdef DEBUG |
| 359 | printf ("Setting MAC %d to %s\n", devnum, s); |
| 360 | #endif |
| 361 | for (x = 0; x < 6; ++x) { |
| 362 | dev->enetaddr[x] = s ? simple_strtoul (s, &e, 16) : 0; |
| 363 | if (s) |
| 364 | s = (*e) ? e + 1 : e; |
| 365 | } |
| 366 | |
| 367 | DP (printf ("Allocating descriptor and buffer rings\n")); |
| 368 | |
| 369 | ethernet_private->p_rx_desc_area_base[0] = |
| 370 | (ETH_RX_DESC *) memalign (16, |
| 371 | RX_DESC_ALIGNED_SIZE * |
| 372 | MV64360_RX_QUEUE_SIZE + 1); |
| 373 | ethernet_private->p_tx_desc_area_base[0] = |
| 374 | (ETH_TX_DESC *) memalign (16, |
| 375 | TX_DESC_ALIGNED_SIZE * |
| 376 | MV64360_TX_QUEUE_SIZE + 1); |
| 377 | |
| 378 | ethernet_private->p_rx_buffer_base[0] = |
| 379 | (char *) memalign (16, |
| 380 | MV64360_RX_QUEUE_SIZE * |
| 381 | MV64360_TX_BUFFER_SIZE + 1); |
| 382 | ethernet_private->p_tx_buffer_base[0] = |
| 383 | (char *) memalign (16, |
| 384 | MV64360_RX_QUEUE_SIZE * |
| 385 | MV64360_TX_BUFFER_SIZE + 1); |
| 386 | |
| 387 | #ifdef DEBUG_MV_ETH |
| 388 | /* DEBUG OUTPUT prints adresses of globals */ |
| 389 | print_globals (dev); |
| 390 | #endif |
| 391 | eth_register (dev); |
| 392 | |
| 393 | } |
| 394 | DP (printf ("%s: exit\n", __FUNCTION__)); |
| 395 | |
| 396 | } |
| 397 | |
| 398 | /********************************************************************** |
| 399 | * mv64360_eth_open |
| 400 | * |
| 401 | * This function is called when openning the network device. The function |
| 402 | * should initialize all the hardware, initialize cyclic Rx/Tx |
| 403 | * descriptors chain and buffers and allocate an IRQ to the network |
| 404 | * device. |
| 405 | * |
| 406 | * Input : a pointer to the network device structure |
| 407 | * / / ronen - changed the output to match net/eth.c needs |
| 408 | * Output : nonzero of success , zero if fails. |
| 409 | * under construction |
| 410 | **********************************************************************/ |
| 411 | |
| 412 | int mv64360_eth_open (struct eth_device *dev) |
| 413 | { |
| 414 | return (mv64360_eth_real_open (dev)); |
| 415 | } |
| 416 | |
| 417 | /* Helper function for mv64360_eth_open */ |
| 418 | static int mv64360_eth_real_open (struct eth_device *dev) |
| 419 | { |
| 420 | |
| 421 | unsigned int queue; |
| 422 | ETH_PORT_INFO *ethernet_private; |
| 423 | struct mv64360_eth_priv *port_private; |
| 424 | unsigned int port_num; |
Anatolij Gustschin | 821315f | 2011-12-20 05:16:45 +0000 | [diff] [blame] | 425 | u32 phy_reg_data; |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 426 | |
| 427 | ethernet_private = (ETH_PORT_INFO *) dev->priv; |
| 428 | /* ronen - when we update the MAC env params we only update dev->enetaddr |
| 429 | see ./net/eth.c eth_set_enetaddr() */ |
| 430 | memcpy (ethernet_private->port_mac_addr, dev->enetaddr, 6); |
| 431 | |
| 432 | port_private = |
| 433 | (struct mv64360_eth_priv *) ethernet_private->port_private; |
| 434 | port_num = port_private->port_num; |
| 435 | |
| 436 | /* Stop RX Queues */ |
| 437 | MV_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG (port_num), |
| 438 | 0x0000ff00); |
| 439 | |
| 440 | /* Clear the ethernet port interrupts */ |
| 441 | MV_REG_WRITE (MV64360_ETH_INTERRUPT_CAUSE_REG (port_num), 0); |
| 442 | MV_REG_WRITE (MV64360_ETH_INTERRUPT_CAUSE_EXTEND_REG (port_num), 0); |
| 443 | |
| 444 | /* Unmask RX buffer and TX end interrupt */ |
| 445 | MV_REG_WRITE (MV64360_ETH_INTERRUPT_MASK_REG (port_num), |
| 446 | INT_CAUSE_UNMASK_ALL); |
| 447 | |
| 448 | /* Unmask phy and link status changes interrupts */ |
| 449 | MV_REG_WRITE (MV64360_ETH_INTERRUPT_EXTEND_MASK_REG (port_num), |
| 450 | INT_CAUSE_UNMASK_ALL_EXT); |
| 451 | |
| 452 | /* Set phy address of the port */ |
| 453 | ethernet_private->port_phy_addr = 0x8 + port_num; |
| 454 | |
| 455 | /* Activate the DMA channels etc */ |
| 456 | eth_port_init (ethernet_private); |
| 457 | |
| 458 | |
| 459 | /* "Allocate" setup TX rings */ |
| 460 | |
| 461 | for (queue = 0; queue < MV64360_TX_QUEUE_NUM; queue++) { |
| 462 | unsigned int size; |
| 463 | |
| 464 | port_private->tx_ring_size[queue] = MV64360_TX_QUEUE_SIZE; |
| 465 | size = (port_private->tx_ring_size[queue] * TX_DESC_ALIGNED_SIZE); /*size = no of DESCs times DESC-size */ |
| 466 | ethernet_private->tx_desc_area_size[queue] = size; |
| 467 | |
| 468 | /* first clear desc area completely */ |
| 469 | memset ((void *) ethernet_private->p_tx_desc_area_base[queue], |
| 470 | 0, ethernet_private->tx_desc_area_size[queue]); |
| 471 | |
| 472 | /* initialize tx desc ring with low level driver */ |
| 473 | if (ether_init_tx_desc_ring |
| 474 | (ethernet_private, ETH_Q0, |
| 475 | port_private->tx_ring_size[queue], |
| 476 | MV64360_TX_BUFFER_SIZE /* Each Buffer is 1600 Byte */ , |
| 477 | (unsigned int) ethernet_private-> |
| 478 | p_tx_desc_area_base[queue], |
| 479 | (unsigned int) ethernet_private-> |
| 480 | p_tx_buffer_base[queue]) == false) |
| 481 | printf ("### Error initializing TX Ring\n"); |
| 482 | } |
| 483 | |
| 484 | /* "Allocate" setup RX rings */ |
| 485 | for (queue = 0; queue < MV64360_RX_QUEUE_NUM; queue++) { |
| 486 | unsigned int size; |
| 487 | |
| 488 | /* Meantime RX Ring are fixed - but must be configurable by user */ |
| 489 | port_private->rx_ring_size[queue] = MV64360_RX_QUEUE_SIZE; |
| 490 | size = (port_private->rx_ring_size[queue] * |
| 491 | RX_DESC_ALIGNED_SIZE); |
| 492 | ethernet_private->rx_desc_area_size[queue] = size; |
| 493 | |
| 494 | /* first clear desc area completely */ |
| 495 | memset ((void *) ethernet_private->p_rx_desc_area_base[queue], |
| 496 | 0, ethernet_private->rx_desc_area_size[queue]); |
| 497 | if ((ether_init_rx_desc_ring |
| 498 | (ethernet_private, ETH_Q0, |
| 499 | port_private->rx_ring_size[queue], |
| 500 | MV64360_RX_BUFFER_SIZE /* Each Buffer is 1600 Byte */ , |
| 501 | (unsigned int) ethernet_private-> |
| 502 | p_rx_desc_area_base[queue], |
| 503 | (unsigned int) ethernet_private-> |
| 504 | p_rx_buffer_base[queue])) == false) |
| 505 | printf ("### Error initializing RX Ring\n"); |
| 506 | } |
| 507 | |
| 508 | eth_port_start (ethernet_private); |
| 509 | |
| 510 | /* Set maximum receive buffer to 9700 bytes */ |
| 511 | MV_REG_WRITE (MV64360_ETH_PORT_SERIAL_CONTROL_REG (port_num), |
| 512 | (0x5 << 17) | |
| 513 | (MV_REG_READ |
| 514 | (MV64360_ETH_PORT_SERIAL_CONTROL_REG (port_num)) |
| 515 | & 0xfff1ffff)); |
| 516 | |
| 517 | /* |
| 518 | * Set ethernet MTU for leaky bucket mechanism to 0 - this will |
| 519 | * disable the leaky bucket mechanism . |
| 520 | */ |
| 521 | |
| 522 | MV_REG_WRITE (MV64360_ETH_MAXIMUM_TRANSMIT_UNIT (port_num), 0); |
Anatolij Gustschin | 821315f | 2011-12-20 05:16:45 +0000 | [diff] [blame] | 523 | MV_REG_READ (MV64360_ETH_PORT_STATUS_REG (port_num)); |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 524 | |
| 525 | /* Check Link status on phy */ |
| 526 | eth_port_read_smi_reg (port_num, 1, &phy_reg_data); |
| 527 | if (!(phy_reg_data & 0x20)) { |
| 528 | /* Reset PHY */ |
| 529 | if ((ethernet_phy_reset (port_num)) != true) { |
| 530 | printf ("$$ Warnning: No link on port %d \n", |
| 531 | port_num); |
| 532 | return 0; |
| 533 | } else { |
| 534 | eth_port_read_smi_reg (port_num, 1, &phy_reg_data); |
| 535 | if (!(phy_reg_data & 0x20)) { |
| 536 | printf ("### Error: Phy is not active\n"); |
| 537 | return 0; |
| 538 | } |
| 539 | } |
| 540 | } else { |
| 541 | mv64360_eth_print_phy_status (dev); |
| 542 | } |
| 543 | port_private->eth_running = MAGIC_ETH_RUNNING; |
| 544 | return 1; |
| 545 | } |
| 546 | |
| 547 | |
| 548 | static int mv64360_eth_free_tx_rings (struct eth_device *dev) |
| 549 | { |
| 550 | unsigned int queue; |
| 551 | ETH_PORT_INFO *ethernet_private; |
| 552 | struct mv64360_eth_priv *port_private; |
| 553 | unsigned int port_num; |
| 554 | volatile ETH_TX_DESC *p_tx_curr_desc; |
| 555 | |
| 556 | ethernet_private = (ETH_PORT_INFO *) dev->priv; |
| 557 | port_private = |
| 558 | (struct mv64360_eth_priv *) ethernet_private->port_private; |
| 559 | port_num = port_private->port_num; |
| 560 | |
| 561 | /* Stop Tx Queues */ |
| 562 | MV_REG_WRITE (MV64360_ETH_TRANSMIT_QUEUE_COMMAND_REG (port_num), |
| 563 | 0x0000ff00); |
| 564 | |
| 565 | /* Free TX rings */ |
| 566 | DP (printf ("Clearing previously allocated TX queues... ")); |
| 567 | for (queue = 0; queue < MV64360_TX_QUEUE_NUM; queue++) { |
| 568 | /* Free on TX rings */ |
| 569 | for (p_tx_curr_desc = |
| 570 | ethernet_private->p_tx_desc_area_base[queue]; |
| 571 | ((unsigned int) p_tx_curr_desc <= (unsigned int) |
| 572 | ethernet_private->p_tx_desc_area_base[queue] + |
| 573 | ethernet_private->tx_desc_area_size[queue]); |
| 574 | p_tx_curr_desc = |
| 575 | (ETH_TX_DESC *) ((unsigned int) p_tx_curr_desc + |
| 576 | TX_DESC_ALIGNED_SIZE)) { |
| 577 | /* this is inside for loop */ |
| 578 | if (p_tx_curr_desc->return_info != 0) { |
| 579 | p_tx_curr_desc->return_info = 0; |
| 580 | DP (printf ("freed\n")); |
| 581 | } |
| 582 | } |
| 583 | DP (printf ("Done\n")); |
| 584 | } |
| 585 | return 0; |
| 586 | } |
| 587 | |
| 588 | static int mv64360_eth_free_rx_rings (struct eth_device *dev) |
| 589 | { |
| 590 | unsigned int queue; |
| 591 | ETH_PORT_INFO *ethernet_private; |
| 592 | struct mv64360_eth_priv *port_private; |
| 593 | unsigned int port_num; |
| 594 | volatile ETH_RX_DESC *p_rx_curr_desc; |
| 595 | |
| 596 | ethernet_private = (ETH_PORT_INFO *) dev->priv; |
| 597 | port_private = |
| 598 | (struct mv64360_eth_priv *) ethernet_private->port_private; |
| 599 | port_num = port_private->port_num; |
| 600 | |
| 601 | |
| 602 | /* Stop RX Queues */ |
| 603 | MV_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG (port_num), |
| 604 | 0x0000ff00); |
| 605 | |
| 606 | /* Free RX rings */ |
| 607 | DP (printf ("Clearing previously allocated RX queues... ")); |
| 608 | for (queue = 0; queue < MV64360_RX_QUEUE_NUM; queue++) { |
| 609 | /* Free preallocated skb's on RX rings */ |
| 610 | for (p_rx_curr_desc = |
| 611 | ethernet_private->p_rx_desc_area_base[queue]; |
| 612 | (((unsigned int) p_rx_curr_desc < |
| 613 | ((unsigned int) ethernet_private-> |
| 614 | p_rx_desc_area_base[queue] + |
| 615 | ethernet_private->rx_desc_area_size[queue]))); |
| 616 | p_rx_curr_desc = |
| 617 | (ETH_RX_DESC *) ((unsigned int) p_rx_curr_desc + |
| 618 | RX_DESC_ALIGNED_SIZE)) { |
| 619 | if (p_rx_curr_desc->return_info != 0) { |
| 620 | p_rx_curr_desc->return_info = 0; |
| 621 | DP (printf ("freed\n")); |
| 622 | } |
| 623 | } |
| 624 | DP (printf ("Done\n")); |
| 625 | } |
| 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | /********************************************************************** |
| 630 | * mv64360_eth_stop |
| 631 | * |
| 632 | * This function is used when closing the network device. |
| 633 | * It updates the hardware, |
| 634 | * release all memory that holds buffers and descriptors and release the IRQ. |
| 635 | * Input : a pointer to the device structure |
| 636 | * Output : zero if success , nonzero if fails |
| 637 | *********************************************************************/ |
| 638 | |
| 639 | int mv64360_eth_stop (struct eth_device *dev) |
| 640 | { |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 641 | /* Disable all gigE address decoder */ |
| 642 | MV_REG_WRITE (MV64360_ETH_BASE_ADDR_ENABLE_REG, 0x3f); |
| 643 | DP (printf ("%s Ethernet stop called ... \n", __FUNCTION__)); |
| 644 | mv64360_eth_real_stop (dev); |
| 645 | |
| 646 | return 0; |
| 647 | }; |
| 648 | |
| 649 | /* Helper function for mv64360_eth_stop */ |
| 650 | |
| 651 | static int mv64360_eth_real_stop (struct eth_device *dev) |
| 652 | { |
| 653 | ETH_PORT_INFO *ethernet_private; |
| 654 | struct mv64360_eth_priv *port_private; |
| 655 | unsigned int port_num; |
| 656 | |
| 657 | ethernet_private = (ETH_PORT_INFO *) dev->priv; |
| 658 | port_private = |
| 659 | (struct mv64360_eth_priv *) ethernet_private->port_private; |
| 660 | port_num = port_private->port_num; |
| 661 | |
| 662 | |
| 663 | mv64360_eth_free_tx_rings (dev); |
| 664 | mv64360_eth_free_rx_rings (dev); |
| 665 | |
| 666 | eth_port_reset (ethernet_private->port_num); |
| 667 | /* Disable ethernet port interrupts */ |
| 668 | MV_REG_WRITE (MV64360_ETH_INTERRUPT_CAUSE_REG (port_num), 0); |
| 669 | MV_REG_WRITE (MV64360_ETH_INTERRUPT_CAUSE_EXTEND_REG (port_num), 0); |
| 670 | /* Mask RX buffer and TX end interrupt */ |
| 671 | MV_REG_WRITE (MV64360_ETH_INTERRUPT_MASK_REG (port_num), 0); |
| 672 | /* Mask phy and link status changes interrupts */ |
| 673 | MV_REG_WRITE (MV64360_ETH_INTERRUPT_EXTEND_MASK_REG (port_num), 0); |
| 674 | MV_RESET_REG_BITS (MV64360_CPU_INTERRUPT0_MASK_HIGH, |
| 675 | BIT0 << port_num); |
| 676 | /* Print Network statistics */ |
| 677 | #ifndef UPDATE_STATS_BY_SOFTWARE |
| 678 | /* |
| 679 | * Print statistics (only if ethernet is running), |
| 680 | * then zero all the stats fields in memory |
| 681 | */ |
| 682 | if (port_private->eth_running == MAGIC_ETH_RUNNING) { |
| 683 | port_private->eth_running = 0; |
| 684 | mv64360_eth_print_stat (dev); |
| 685 | } |
| 686 | memset (port_private->stats, 0, sizeof (struct net_device_stats)); |
| 687 | #endif |
| 688 | DP (printf ("\nEthernet stopped ... \n")); |
| 689 | return 0; |
| 690 | } |
| 691 | |
| 692 | |
| 693 | /********************************************************************** |
| 694 | * mv64360_eth_start_xmit |
| 695 | * |
| 696 | * This function is queues a packet in the Tx descriptor for |
| 697 | * required port. |
| 698 | * |
| 699 | * Input : skb - a pointer to socket buffer |
| 700 | * dev - a pointer to the required port |
| 701 | * |
| 702 | * Output : zero upon success |
| 703 | **********************************************************************/ |
| 704 | |
| 705 | int mv64360_eth_xmit (struct eth_device *dev, volatile void *dataPtr, |
| 706 | int dataSize) |
| 707 | { |
| 708 | ETH_PORT_INFO *ethernet_private; |
| 709 | struct mv64360_eth_priv *port_private; |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 710 | PKT_INFO pkt_info; |
| 711 | ETH_FUNC_RET_STATUS status; |
| 712 | struct net_device_stats *stats; |
| 713 | ETH_FUNC_RET_STATUS release_result; |
| 714 | |
| 715 | ethernet_private = (ETH_PORT_INFO *) dev->priv; |
| 716 | port_private = |
| 717 | (struct mv64360_eth_priv *) ethernet_private->port_private; |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 718 | |
| 719 | stats = port_private->stats; |
| 720 | |
| 721 | /* Update packet info data structure */ |
| 722 | pkt_info.cmd_sts = ETH_TX_FIRST_DESC | ETH_TX_LAST_DESC; /* DMA owned, first last */ |
| 723 | pkt_info.byte_cnt = dataSize; |
| 724 | pkt_info.buf_ptr = (unsigned int) dataPtr; |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 725 | pkt_info.return_info = 0; |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 726 | |
| 727 | status = eth_port_send (ethernet_private, ETH_Q0, &pkt_info); |
| 728 | if ((status == ETH_ERROR) || (status == ETH_QUEUE_FULL)) { |
| 729 | printf ("Error on transmitting packet .."); |
| 730 | if (status == ETH_QUEUE_FULL) |
| 731 | printf ("ETH Queue is full. \n"); |
| 732 | if (status == ETH_QUEUE_LAST_RESOURCE) |
| 733 | printf ("ETH Queue: using last available resource. \n"); |
| 734 | goto error; |
| 735 | } |
| 736 | |
| 737 | /* Update statistics and start of transmittion time */ |
| 738 | stats->tx_bytes += dataSize; |
| 739 | stats->tx_packets++; |
| 740 | |
| 741 | /* Check if packet(s) is(are) transmitted correctly (release everything) */ |
| 742 | do { |
| 743 | release_result = |
| 744 | eth_tx_return_desc (ethernet_private, ETH_Q0, |
| 745 | &pkt_info); |
| 746 | switch (release_result) { |
| 747 | case ETH_OK: |
| 748 | DP (printf ("descriptor released\n")); |
| 749 | if (pkt_info.cmd_sts & BIT0) { |
| 750 | printf ("Error in TX\n"); |
| 751 | stats->tx_errors++; |
| 752 | |
| 753 | } |
| 754 | break; |
| 755 | case ETH_RETRY: |
| 756 | DP (printf ("transmission still in process\n")); |
| 757 | break; |
| 758 | |
| 759 | case ETH_ERROR: |
| 760 | printf ("routine can not access Tx desc ring\n"); |
| 761 | break; |
| 762 | |
| 763 | case ETH_END_OF_JOB: |
| 764 | DP (printf ("the routine has nothing to release\n")); |
| 765 | break; |
| 766 | default: /* should not happen */ |
| 767 | break; |
| 768 | } |
| 769 | } while (release_result == ETH_OK); |
| 770 | |
| 771 | |
| 772 | return 0; /* success */ |
| 773 | error: |
| 774 | return 1; /* Failed - higher layers will free the skb */ |
| 775 | } |
| 776 | |
| 777 | /********************************************************************** |
| 778 | * mv64360_eth_receive |
| 779 | * |
| 780 | * This function is forward packets that are received from the port's |
| 781 | * queues toward kernel core or FastRoute them to another interface. |
| 782 | * |
| 783 | * Input : dev - a pointer to the required interface |
| 784 | * max - maximum number to receive (0 means unlimted) |
| 785 | * |
| 786 | * Output : number of served packets |
| 787 | **********************************************************************/ |
| 788 | |
| 789 | int mv64360_eth_receive (struct eth_device *dev) |
| 790 | { |
| 791 | ETH_PORT_INFO *ethernet_private; |
| 792 | struct mv64360_eth_priv *port_private; |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 793 | PKT_INFO pkt_info; |
| 794 | struct net_device_stats *stats; |
| 795 | |
| 796 | |
| 797 | ethernet_private = (ETH_PORT_INFO *) dev->priv; |
| 798 | port_private = |
| 799 | (struct mv64360_eth_priv *) ethernet_private->port_private; |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 800 | stats = port_private->stats; |
| 801 | |
| 802 | while ((eth_port_receive (ethernet_private, ETH_Q0, &pkt_info) == |
| 803 | ETH_OK)) { |
| 804 | |
| 805 | #ifdef DEBUG_MV_ETH |
| 806 | if (pkt_info.byte_cnt != 0) { |
| 807 | printf ("%s: Received %d byte Packet @ 0x%x\n", |
| 808 | __FUNCTION__, pkt_info.byte_cnt, |
| 809 | pkt_info.buf_ptr); |
| 810 | } |
| 811 | #endif |
| 812 | /* Update statistics. Note byte count includes 4 byte CRC count */ |
| 813 | stats->rx_packets++; |
| 814 | stats->rx_bytes += pkt_info.byte_cnt; |
| 815 | |
| 816 | /* |
| 817 | * In case received a packet without first / last bits on OR the error |
| 818 | * summary bit is on, the packets needs to be dropeed. |
| 819 | */ |
| 820 | if (((pkt_info. |
| 821 | cmd_sts & (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) != |
| 822 | (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) |
| 823 | || (pkt_info.cmd_sts & ETH_ERROR_SUMMARY)) { |
| 824 | stats->rx_dropped++; |
| 825 | |
| 826 | printf ("Received packet spread on multiple descriptors\n"); |
| 827 | |
| 828 | /* Is this caused by an error ? */ |
| 829 | if (pkt_info.cmd_sts & ETH_ERROR_SUMMARY) { |
| 830 | stats->rx_errors++; |
| 831 | } |
| 832 | |
| 833 | /* free these descriptors again without forwarding them to the higher layers */ |
| 834 | pkt_info.buf_ptr &= ~0x7; /* realign buffer again */ |
| 835 | pkt_info.byte_cnt = 0x0000; /* Reset Byte count */ |
| 836 | |
| 837 | if (eth_rx_return_buff |
| 838 | (ethernet_private, ETH_Q0, &pkt_info) != ETH_OK) { |
| 839 | printf ("Error while returning the RX Desc to Ring\n"); |
| 840 | } else { |
| 841 | DP (printf ("RX Desc returned to Ring\n")); |
| 842 | } |
| 843 | /* /free these descriptors again */ |
| 844 | } else { |
| 845 | |
| 846 | /* !!! call higher layer processing */ |
| 847 | #ifdef DEBUG_MV_ETH |
| 848 | printf ("\nNow send it to upper layer protocols (NetReceive) ...\n"); |
| 849 | #endif |
| 850 | /* let the upper layer handle the packet */ |
| 851 | NetReceive ((uchar *) pkt_info.buf_ptr, |
| 852 | (int) pkt_info.byte_cnt); |
| 853 | |
| 854 | /* **************************************************************** */ |
| 855 | /* free descriptor */ |
| 856 | pkt_info.buf_ptr &= ~0x7; /* realign buffer again */ |
| 857 | pkt_info.byte_cnt = 0x0000; /* Reset Byte count */ |
| 858 | DP (printf |
| 859 | ("RX: pkt_info.buf_ptr = %x\n", |
| 860 | pkt_info.buf_ptr)); |
| 861 | if (eth_rx_return_buff |
| 862 | (ethernet_private, ETH_Q0, &pkt_info) != ETH_OK) { |
| 863 | printf ("Error while returning the RX Desc to Ring\n"); |
| 864 | } else { |
| 865 | DP (printf ("RX Desc returned to Ring\n")); |
| 866 | } |
| 867 | |
| 868 | /* **************************************************************** */ |
| 869 | |
| 870 | } |
| 871 | } |
| 872 | mv64360_eth_get_stats (dev); /* update statistics */ |
| 873 | return 1; |
| 874 | } |
| 875 | |
| 876 | /********************************************************************** |
| 877 | * mv64360_eth_get_stats |
| 878 | * |
| 879 | * Returns a pointer to the interface statistics. |
| 880 | * |
| 881 | * Input : dev - a pointer to the required interface |
| 882 | * |
| 883 | * Output : a pointer to the interface's statistics |
| 884 | **********************************************************************/ |
| 885 | |
| 886 | static struct net_device_stats *mv64360_eth_get_stats (struct eth_device *dev) |
| 887 | { |
| 888 | ETH_PORT_INFO *ethernet_private; |
| 889 | struct mv64360_eth_priv *port_private; |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 890 | |
| 891 | ethernet_private = (ETH_PORT_INFO *) dev->priv; |
| 892 | port_private = |
| 893 | (struct mv64360_eth_priv *) ethernet_private->port_private; |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 894 | |
| 895 | mv64360_eth_update_stat (dev); |
| 896 | |
| 897 | return port_private->stats; |
| 898 | } |
| 899 | |
| 900 | |
| 901 | /********************************************************************** |
| 902 | * mv64360_eth_update_stat |
| 903 | * |
| 904 | * Update the statistics structure in the private data structure |
| 905 | * |
| 906 | * Input : pointer to ethernet interface network device structure |
| 907 | * Output : N/A |
| 908 | **********************************************************************/ |
| 909 | |
| 910 | static void mv64360_eth_update_stat (struct eth_device *dev) |
| 911 | { |
| 912 | ETH_PORT_INFO *ethernet_private; |
| 913 | struct mv64360_eth_priv *port_private; |
| 914 | struct net_device_stats *stats; |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 915 | |
| 916 | ethernet_private = (ETH_PORT_INFO *) dev->priv; |
| 917 | port_private = |
| 918 | (struct mv64360_eth_priv *) ethernet_private->port_private; |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 919 | stats = port_private->stats; |
| 920 | |
| 921 | /* These are false updates */ |
| 922 | stats->rx_packets += (unsigned long) |
| 923 | eth_read_mib_counter (ethernet_private->port_num, |
| 924 | ETH_MIB_GOOD_FRAMES_RECEIVED); |
| 925 | stats->tx_packets += (unsigned long) |
| 926 | eth_read_mib_counter (ethernet_private->port_num, |
| 927 | ETH_MIB_GOOD_FRAMES_SENT); |
| 928 | stats->rx_bytes += (unsigned long) |
| 929 | eth_read_mib_counter (ethernet_private->port_num, |
| 930 | ETH_MIB_GOOD_OCTETS_RECEIVED_LOW); |
| 931 | /* |
| 932 | * Ideally this should be as follows - |
| 933 | * |
| 934 | * stats->rx_bytes += stats->rx_bytes + |
| 935 | * ((unsigned long) ethReadMibCounter (ethernet_private->port_num , |
| 936 | * ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH) << 32); |
| 937 | * |
| 938 | * But the unsigned long in PowerPC and MIPS are 32bit. So the next read |
| 939 | * is just a dummy read for proper work of the GigE port |
| 940 | */ |
Anatolij Gustschin | 821315f | 2011-12-20 05:16:45 +0000 | [diff] [blame] | 941 | (void)eth_read_mib_counter (ethernet_private->port_num, |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 942 | ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH); |
| 943 | stats->tx_bytes += (unsigned long) |
| 944 | eth_read_mib_counter (ethernet_private->port_num, |
| 945 | ETH_MIB_GOOD_OCTETS_SENT_LOW); |
Anatolij Gustschin | 821315f | 2011-12-20 05:16:45 +0000 | [diff] [blame] | 946 | (void)eth_read_mib_counter (ethernet_private->port_num, |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 947 | ETH_MIB_GOOD_OCTETS_SENT_HIGH); |
| 948 | stats->rx_errors += (unsigned long) |
| 949 | eth_read_mib_counter (ethernet_private->port_num, |
| 950 | ETH_MIB_MAC_RECEIVE_ERROR); |
| 951 | |
| 952 | /* Rx dropped is for received packet with CRC error */ |
| 953 | stats->rx_dropped += |
| 954 | (unsigned long) eth_read_mib_counter (ethernet_private-> |
| 955 | port_num, |
| 956 | ETH_MIB_BAD_CRC_EVENT); |
| 957 | stats->multicast += (unsigned long) |
| 958 | eth_read_mib_counter (ethernet_private->port_num, |
| 959 | ETH_MIB_MULTICAST_FRAMES_RECEIVED); |
| 960 | stats->collisions += |
| 961 | (unsigned long) eth_read_mib_counter (ethernet_private-> |
| 962 | port_num, |
| 963 | ETH_MIB_COLLISION) + |
| 964 | (unsigned long) eth_read_mib_counter (ethernet_private-> |
| 965 | port_num, |
| 966 | ETH_MIB_LATE_COLLISION); |
| 967 | /* detailed rx errors */ |
| 968 | stats->rx_length_errors += |
| 969 | (unsigned long) eth_read_mib_counter (ethernet_private-> |
| 970 | port_num, |
| 971 | ETH_MIB_UNDERSIZE_RECEIVED) |
| 972 | + |
| 973 | (unsigned long) eth_read_mib_counter (ethernet_private-> |
| 974 | port_num, |
| 975 | ETH_MIB_OVERSIZE_RECEIVED); |
| 976 | /* detailed tx errors */ |
| 977 | } |
| 978 | |
| 979 | #ifndef UPDATE_STATS_BY_SOFTWARE |
| 980 | /********************************************************************** |
| 981 | * mv64360_eth_print_stat |
| 982 | * |
| 983 | * Update the statistics structure in the private data structure |
| 984 | * |
| 985 | * Input : pointer to ethernet interface network device structure |
| 986 | * Output : N/A |
| 987 | **********************************************************************/ |
| 988 | |
| 989 | static void mv64360_eth_print_stat (struct eth_device *dev) |
| 990 | { |
| 991 | ETH_PORT_INFO *ethernet_private; |
| 992 | struct mv64360_eth_priv *port_private; |
| 993 | struct net_device_stats *stats; |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 994 | |
| 995 | ethernet_private = (ETH_PORT_INFO *) dev->priv; |
| 996 | port_private = |
| 997 | (struct mv64360_eth_priv *) ethernet_private->port_private; |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 998 | stats = port_private->stats; |
| 999 | |
| 1000 | /* These are false updates */ |
| 1001 | printf ("\n### Network statistics: ###\n"); |
| 1002 | printf ("--------------------------\n"); |
| 1003 | printf (" Packets received: %ld\n", stats->rx_packets); |
| 1004 | printf (" Packets send: %ld\n", stats->tx_packets); |
| 1005 | printf (" Received bytes: %ld\n", stats->rx_bytes); |
| 1006 | printf (" Send bytes: %ld\n", stats->tx_bytes); |
| 1007 | if (stats->rx_errors != 0) |
| 1008 | printf (" Rx Errors: %ld\n", |
| 1009 | stats->rx_errors); |
| 1010 | if (stats->rx_dropped != 0) |
| 1011 | printf (" Rx dropped (CRC Errors): %ld\n", |
| 1012 | stats->rx_dropped); |
| 1013 | if (stats->multicast != 0) |
| 1014 | printf (" Rx mulicast frames: %ld\n", |
| 1015 | stats->multicast); |
| 1016 | if (stats->collisions != 0) |
| 1017 | printf (" No. of collisions: %ld\n", |
| 1018 | stats->collisions); |
| 1019 | if (stats->rx_length_errors != 0) |
| 1020 | printf (" Rx length errors: %ld\n", |
| 1021 | stats->rx_length_errors); |
| 1022 | } |
| 1023 | #endif |
| 1024 | |
| 1025 | /************************************************************************** |
| 1026 | *network_start - Network Kick Off Routine UBoot |
| 1027 | *Inputs : |
| 1028 | *Outputs : |
| 1029 | **************************************************************************/ |
| 1030 | |
| 1031 | bool db64360_eth_start (struct eth_device *dev) |
| 1032 | { |
| 1033 | return (mv64360_eth_open (dev)); /* calls real open */ |
| 1034 | } |
| 1035 | |
| 1036 | /************************************************************************* |
| 1037 | ************************************************************************** |
| 1038 | ************************************************************************** |
| 1039 | * The second part is the low level driver of the gigE ethernet ports. * |
| 1040 | ************************************************************************** |
| 1041 | ************************************************************************** |
| 1042 | *************************************************************************/ |
| 1043 | /* |
| 1044 | * based on Linux code |
Stefan Roese | a47a12b | 2010-04-15 16:07:28 +0200 | [diff] [blame] | 1045 | * arch/powerpc/galileo/EVB64360/mv64360_eth.c - Driver for MV64360X ethernet ports |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 1046 | * Copyright (C) 2002 rabeeh@galileo.co.il |
| 1047 | |
| 1048 | * This program is free software; you can redistribute it and/or |
| 1049 | * modify it under the terms of the GNU General Public License |
| 1050 | * as published by the Free Software Foundation; either version 2 |
| 1051 | * of the License, or (at your option) any later version. |
| 1052 | |
| 1053 | * This program is distributed in the hope that it will be useful, |
| 1054 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1055 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 1056 | * GNU General Public License for more details. |
| 1057 | |
| 1058 | * You should have received a copy of the GNU General Public License |
| 1059 | * along with this program; if not, write to the Free Software |
| 1060 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 1061 | * |
| 1062 | */ |
| 1063 | |
| 1064 | /******************************************************************************** |
| 1065 | * Marvell's Gigabit Ethernet controller low level driver |
| 1066 | * |
| 1067 | * DESCRIPTION: |
| 1068 | * This file introduce low level API to Marvell's Gigabit Ethernet |
| 1069 | * controller. This Gigabit Ethernet Controller driver API controls |
| 1070 | * 1) Operations (i.e. port init, start, reset etc'). |
| 1071 | * 2) Data flow (i.e. port send, receive etc'). |
| 1072 | * Each Gigabit Ethernet port is controlled via ETH_PORT_INFO |
| 1073 | * struct. |
| 1074 | * This struct includes user configuration information as well as |
| 1075 | * driver internal data needed for its operations. |
| 1076 | * |
| 1077 | * Supported Features: |
| 1078 | * - This low level driver is OS independent. Allocating memory for |
| 1079 | * the descriptor rings and buffers are not within the scope of |
| 1080 | * this driver. |
| 1081 | * - The user is free from Rx/Tx queue managing. |
| 1082 | * - This low level driver introduce functionality API that enable |
| 1083 | * the to operate Marvell's Gigabit Ethernet Controller in a |
| 1084 | * convenient way. |
| 1085 | * - Simple Gigabit Ethernet port operation API. |
| 1086 | * - Simple Gigabit Ethernet port data flow API. |
| 1087 | * - Data flow and operation API support per queue functionality. |
| 1088 | * - Support cached descriptors for better performance. |
| 1089 | * - Enable access to all four DRAM banks and internal SRAM memory |
| 1090 | * spaces. |
| 1091 | * - PHY access and control API. |
| 1092 | * - Port control register configuration API. |
| 1093 | * - Full control over Unicast and Multicast MAC configurations. |
| 1094 | * |
| 1095 | * Operation flow: |
| 1096 | * |
| 1097 | * Initialization phase |
| 1098 | * This phase complete the initialization of the ETH_PORT_INFO |
| 1099 | * struct. |
| 1100 | * User information regarding port configuration has to be set |
| 1101 | * prior to calling the port initialization routine. For example, |
| 1102 | * the user has to assign the port_phy_addr field which is board |
| 1103 | * depended parameter. |
| 1104 | * In this phase any port Tx/Rx activity is halted, MIB counters |
| 1105 | * are cleared, PHY address is set according to user parameter and |
| 1106 | * access to DRAM and internal SRAM memory spaces. |
| 1107 | * |
| 1108 | * Driver ring initialization |
| 1109 | * Allocating memory for the descriptor rings and buffers is not |
| 1110 | * within the scope of this driver. Thus, the user is required to |
| 1111 | * allocate memory for the descriptors ring and buffers. Those |
| 1112 | * memory parameters are used by the Rx and Tx ring initialization |
| 1113 | * routines in order to curve the descriptor linked list in a form |
| 1114 | * of a ring. |
| 1115 | * Note: Pay special attention to alignment issues when using |
| 1116 | * cached descriptors/buffers. In this phase the driver store |
| 1117 | * information in the ETH_PORT_INFO struct regarding each queue |
| 1118 | * ring. |
| 1119 | * |
| 1120 | * Driver start |
| 1121 | * This phase prepares the Ethernet port for Rx and Tx activity. |
| 1122 | * It uses the information stored in the ETH_PORT_INFO struct to |
| 1123 | * initialize the various port registers. |
| 1124 | * |
| 1125 | * Data flow: |
| 1126 | * All packet references to/from the driver are done using PKT_INFO |
| 1127 | * struct. |
| 1128 | * This struct is a unified struct used with Rx and Tx operations. |
| 1129 | * This way the user is not required to be familiar with neither |
| 1130 | * Tx nor Rx descriptors structures. |
| 1131 | * The driver's descriptors rings are management by indexes. |
| 1132 | * Those indexes controls the ring resources and used to indicate |
| 1133 | * a SW resource error: |
| 1134 | * 'current' |
| 1135 | * This index points to the current available resource for use. For |
| 1136 | * example in Rx process this index will point to the descriptor |
| 1137 | * that will be passed to the user upon calling the receive routine. |
| 1138 | * In Tx process, this index will point to the descriptor |
| 1139 | * that will be assigned with the user packet info and transmitted. |
| 1140 | * 'used' |
| 1141 | * This index points to the descriptor that need to restore its |
| 1142 | * resources. For example in Rx process, using the Rx buffer return |
| 1143 | * API will attach the buffer returned in packet info to the |
| 1144 | * descriptor pointed by 'used'. In Tx process, using the Tx |
| 1145 | * descriptor return will merely return the user packet info with |
| 1146 | * the command status of the transmitted buffer pointed by the |
| 1147 | * 'used' index. Nevertheless, it is essential to use this routine |
| 1148 | * to update the 'used' index. |
| 1149 | * 'first' |
| 1150 | * This index supports Tx Scatter-Gather. It points to the first |
| 1151 | * descriptor of a packet assembled of multiple buffers. For example |
| 1152 | * when in middle of Such packet we have a Tx resource error the |
| 1153 | * 'curr' index get the value of 'first' to indicate that the ring |
| 1154 | * returned to its state before trying to transmit this packet. |
| 1155 | * |
| 1156 | * Receive operation: |
| 1157 | * The eth_port_receive API set the packet information struct, |
| 1158 | * passed by the caller, with received information from the |
| 1159 | * 'current' SDMA descriptor. |
| 1160 | * It is the user responsibility to return this resource back |
| 1161 | * to the Rx descriptor ring to enable the reuse of this source. |
| 1162 | * Return Rx resource is done using the eth_rx_return_buff API. |
| 1163 | * |
| 1164 | * Transmit operation: |
| 1165 | * The eth_port_send API supports Scatter-Gather which enables to |
| 1166 | * send a packet spanned over multiple buffers. This means that |
| 1167 | * for each packet info structure given by the user and put into |
| 1168 | * the Tx descriptors ring, will be transmitted only if the 'LAST' |
| 1169 | * bit will be set in the packet info command status field. This |
| 1170 | * API also consider restriction regarding buffer alignments and |
| 1171 | * sizes. |
| 1172 | * The user must return a Tx resource after ensuring the buffer |
| 1173 | * has been transmitted to enable the Tx ring indexes to update. |
| 1174 | * |
| 1175 | * BOARD LAYOUT |
| 1176 | * This device is on-board. No jumper diagram is necessary. |
| 1177 | * |
| 1178 | * EXTERNAL INTERFACE |
| 1179 | * |
| 1180 | * Prior to calling the initialization routine eth_port_init() the user |
| 1181 | * must set the following fields under ETH_PORT_INFO struct: |
| 1182 | * port_num User Ethernet port number. |
| 1183 | * port_phy_addr User PHY address of Ethernet port. |
| 1184 | * port_mac_addr[6] User defined port MAC address. |
| 1185 | * port_config User port configuration value. |
| 1186 | * port_config_extend User port config extend value. |
| 1187 | * port_sdma_config User port SDMA config value. |
| 1188 | * port_serial_control User port serial control value. |
| 1189 | * *port_virt_to_phys () User function to cast virtual addr to CPU bus addr. |
| 1190 | * *port_private User scratch pad for user specific data structures. |
| 1191 | * |
| 1192 | * This driver introduce a set of default values: |
| 1193 | * PORT_CONFIG_VALUE Default port configuration value |
| 1194 | * PORT_CONFIG_EXTEND_VALUE Default port extend configuration value |
| 1195 | * PORT_SDMA_CONFIG_VALUE Default sdma control value |
| 1196 | * PORT_SERIAL_CONTROL_VALUE Default port serial control value |
| 1197 | * |
| 1198 | * This driver data flow is done using the PKT_INFO struct which is |
| 1199 | * a unified struct for Rx and Tx operations: |
| 1200 | * byte_cnt Tx/Rx descriptor buffer byte count. |
| 1201 | * l4i_chk CPU provided TCP Checksum. For Tx operation only. |
| 1202 | * cmd_sts Tx/Rx descriptor command status. |
| 1203 | * buf_ptr Tx/Rx descriptor buffer pointer. |
| 1204 | * return_info Tx/Rx user resource return information. |
| 1205 | * |
| 1206 | * |
| 1207 | * EXTERNAL SUPPORT REQUIREMENTS |
| 1208 | * |
| 1209 | * This driver requires the following external support: |
| 1210 | * |
| 1211 | * D_CACHE_FLUSH_LINE (address, address offset) |
| 1212 | * |
| 1213 | * This macro applies assembly code to flush and invalidate cache |
| 1214 | * line. |
| 1215 | * address - address base. |
| 1216 | * address offset - address offset |
| 1217 | * |
| 1218 | * |
| 1219 | * CPU_PIPE_FLUSH |
| 1220 | * |
| 1221 | * This macro applies assembly code to flush the CPU pipeline. |
| 1222 | * |
| 1223 | *******************************************************************************/ |
| 1224 | /* includes */ |
| 1225 | |
| 1226 | /* defines */ |
| 1227 | /* SDMA command macros */ |
| 1228 | #define ETH_ENABLE_TX_QUEUE(tx_queue, eth_port) \ |
| 1229 | MV_REG_WRITE(MV64360_ETH_TRANSMIT_QUEUE_COMMAND_REG(eth_port), (1 << tx_queue)) |
| 1230 | |
| 1231 | #define ETH_DISABLE_TX_QUEUE(tx_queue, eth_port) \ |
| 1232 | MV_REG_WRITE(MV64360_ETH_TRANSMIT_QUEUE_COMMAND_REG(eth_port),\ |
| 1233 | (1 << (8 + tx_queue))) |
| 1234 | |
| 1235 | #define ETH_ENABLE_RX_QUEUE(rx_queue, eth_port) \ |
| 1236 | MV_REG_WRITE(MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG(eth_port), (1 << rx_queue)) |
| 1237 | |
| 1238 | #define ETH_DISABLE_RX_QUEUE(rx_queue, eth_port) \ |
| 1239 | MV_REG_WRITE(MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG(eth_port), (1 << (8 + rx_queue))) |
| 1240 | |
| 1241 | #define CURR_RFD_GET(p_curr_desc, queue) \ |
| 1242 | ((p_curr_desc) = p_eth_port_ctrl->p_rx_curr_desc_q[queue]) |
| 1243 | |
| 1244 | #define CURR_RFD_SET(p_curr_desc, queue) \ |
| 1245 | (p_eth_port_ctrl->p_rx_curr_desc_q[queue] = (p_curr_desc)) |
| 1246 | |
| 1247 | #define USED_RFD_GET(p_used_desc, queue) \ |
| 1248 | ((p_used_desc) = p_eth_port_ctrl->p_rx_used_desc_q[queue]) |
| 1249 | |
| 1250 | #define USED_RFD_SET(p_used_desc, queue)\ |
| 1251 | (p_eth_port_ctrl->p_rx_used_desc_q[queue] = (p_used_desc)) |
| 1252 | |
| 1253 | |
| 1254 | #define CURR_TFD_GET(p_curr_desc, queue) \ |
| 1255 | ((p_curr_desc) = p_eth_port_ctrl->p_tx_curr_desc_q[queue]) |
| 1256 | |
| 1257 | #define CURR_TFD_SET(p_curr_desc, queue) \ |
| 1258 | (p_eth_port_ctrl->p_tx_curr_desc_q[queue] = (p_curr_desc)) |
| 1259 | |
| 1260 | #define USED_TFD_GET(p_used_desc, queue) \ |
| 1261 | ((p_used_desc) = p_eth_port_ctrl->p_tx_used_desc_q[queue]) |
| 1262 | |
| 1263 | #define USED_TFD_SET(p_used_desc, queue) \ |
| 1264 | (p_eth_port_ctrl->p_tx_used_desc_q[queue] = (p_used_desc)) |
| 1265 | |
| 1266 | #define FIRST_TFD_GET(p_first_desc, queue) \ |
| 1267 | ((p_first_desc) = p_eth_port_ctrl->p_tx_first_desc_q[queue]) |
| 1268 | |
| 1269 | #define FIRST_TFD_SET(p_first_desc, queue) \ |
| 1270 | (p_eth_port_ctrl->p_tx_first_desc_q[queue] = (p_first_desc)) |
| 1271 | |
| 1272 | |
| 1273 | /* Macros that save access to desc in order to find next desc pointer */ |
| 1274 | #define RX_NEXT_DESC_PTR(p_rx_desc, queue) (ETH_RX_DESC*)(((((unsigned int)p_rx_desc - (unsigned int)p_eth_port_ctrl->p_rx_desc_area_base[queue]) + RX_DESC_ALIGNED_SIZE) % p_eth_port_ctrl->rx_desc_area_size[queue]) + (unsigned int)p_eth_port_ctrl->p_rx_desc_area_base[queue]) |
| 1275 | |
| 1276 | #define TX_NEXT_DESC_PTR(p_tx_desc, queue) (ETH_TX_DESC*)(((((unsigned int)p_tx_desc - (unsigned int)p_eth_port_ctrl->p_tx_desc_area_base[queue]) + TX_DESC_ALIGNED_SIZE) % p_eth_port_ctrl->tx_desc_area_size[queue]) + (unsigned int)p_eth_port_ctrl->p_tx_desc_area_base[queue]) |
| 1277 | |
| 1278 | #define LINK_UP_TIMEOUT 100000 |
| 1279 | #define PHY_BUSY_TIMEOUT 10000000 |
| 1280 | |
| 1281 | /* locals */ |
| 1282 | |
| 1283 | /* PHY routines */ |
| 1284 | static void ethernet_phy_set (ETH_PORT eth_port_num, int phy_addr); |
| 1285 | static int ethernet_phy_get (ETH_PORT eth_port_num); |
| 1286 | |
| 1287 | /* Ethernet Port routines */ |
| 1288 | static void eth_set_access_control (ETH_PORT eth_port_num, |
| 1289 | ETH_WIN_PARAM * param); |
| 1290 | static bool eth_port_uc_addr (ETH_PORT eth_port_num, unsigned char uc_nibble, |
| 1291 | ETH_QUEUE queue, int option); |
| 1292 | #if 0 /* FIXME */ |
| 1293 | static bool eth_port_smc_addr (ETH_PORT eth_port_num, |
| 1294 | unsigned char mc_byte, |
| 1295 | ETH_QUEUE queue, int option); |
| 1296 | static bool eth_port_omc_addr (ETH_PORT eth_port_num, |
| 1297 | unsigned char crc8, |
| 1298 | ETH_QUEUE queue, int option); |
| 1299 | #endif |
| 1300 | |
| 1301 | static void eth_b_copy (unsigned int src_addr, unsigned int dst_addr, |
| 1302 | int byte_count); |
| 1303 | |
| 1304 | void eth_dbg (ETH_PORT_INFO * p_eth_port_ctrl); |
| 1305 | |
| 1306 | |
| 1307 | typedef enum _memory_bank { BANK0, BANK1, BANK2, BANK3 } MEMORY_BANK; |
| 1308 | u32 mv_get_dram_bank_base_addr (MEMORY_BANK bank) |
| 1309 | { |
| 1310 | u32 result = 0; |
| 1311 | u32 enable = MV_REG_READ (MV64360_BASE_ADDR_ENABLE); |
| 1312 | |
| 1313 | if (enable & (1 << bank)) |
| 1314 | return 0; |
| 1315 | if (bank == BANK0) |
| 1316 | result = MV_REG_READ (MV64360_CS_0_BASE_ADDR); |
| 1317 | if (bank == BANK1) |
| 1318 | result = MV_REG_READ (MV64360_CS_1_BASE_ADDR); |
| 1319 | if (bank == BANK2) |
| 1320 | result = MV_REG_READ (MV64360_CS_2_BASE_ADDR); |
| 1321 | if (bank == BANK3) |
| 1322 | result = MV_REG_READ (MV64360_CS_3_BASE_ADDR); |
| 1323 | result &= 0x0000ffff; |
| 1324 | result = result << 16; |
| 1325 | return result; |
| 1326 | } |
| 1327 | |
| 1328 | u32 mv_get_dram_bank_size (MEMORY_BANK bank) |
| 1329 | { |
| 1330 | u32 result = 0; |
| 1331 | u32 enable = MV_REG_READ (MV64360_BASE_ADDR_ENABLE); |
| 1332 | |
| 1333 | if (enable & (1 << bank)) |
| 1334 | return 0; |
| 1335 | if (bank == BANK0) |
| 1336 | result = MV_REG_READ (MV64360_CS_0_SIZE); |
| 1337 | if (bank == BANK1) |
| 1338 | result = MV_REG_READ (MV64360_CS_1_SIZE); |
| 1339 | if (bank == BANK2) |
| 1340 | result = MV_REG_READ (MV64360_CS_2_SIZE); |
| 1341 | if (bank == BANK3) |
| 1342 | result = MV_REG_READ (MV64360_CS_3_SIZE); |
| 1343 | result += 1; |
| 1344 | result &= 0x0000ffff; |
| 1345 | result = result << 16; |
| 1346 | return result; |
| 1347 | } |
| 1348 | |
| 1349 | u32 mv_get_internal_sram_base (void) |
| 1350 | { |
| 1351 | u32 result; |
| 1352 | |
| 1353 | result = MV_REG_READ (MV64360_INTEGRATED_SRAM_BASE_ADDR); |
| 1354 | result &= 0x0000ffff; |
| 1355 | result = result << 16; |
| 1356 | return result; |
| 1357 | } |
| 1358 | |
| 1359 | /******************************************************************************* |
| 1360 | * eth_port_init - Initialize the Ethernet port driver |
| 1361 | * |
| 1362 | * DESCRIPTION: |
| 1363 | * This function prepares the ethernet port to start its activity: |
| 1364 | * 1) Completes the ethernet port driver struct initialization toward port |
| 1365 | * start routine. |
| 1366 | * 2) Resets the device to a quiescent state in case of warm reboot. |
| 1367 | * 3) Enable SDMA access to all four DRAM banks as well as internal SRAM. |
| 1368 | * 4) Clean MAC tables. The reset status of those tables is unknown. |
| 1369 | * 5) Set PHY address. |
| 1370 | * Note: Call this routine prior to eth_port_start routine and after setting |
| 1371 | * user values in the user fields of Ethernet port control struct (i.e. |
| 1372 | * port_phy_addr). |
| 1373 | * |
| 1374 | * INPUT: |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1375 | * ETH_PORT_INFO *p_eth_port_ctrl Ethernet port control struct |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 1376 | * |
| 1377 | * OUTPUT: |
| 1378 | * See description. |
| 1379 | * |
| 1380 | * RETURN: |
| 1381 | * None. |
| 1382 | * |
| 1383 | *******************************************************************************/ |
| 1384 | static void eth_port_init (ETH_PORT_INFO * p_eth_port_ctrl) |
| 1385 | { |
| 1386 | int queue; |
| 1387 | ETH_WIN_PARAM win_param; |
| 1388 | |
| 1389 | p_eth_port_ctrl->port_config = PORT_CONFIG_VALUE; |
| 1390 | p_eth_port_ctrl->port_config_extend = PORT_CONFIG_EXTEND_VALUE; |
| 1391 | p_eth_port_ctrl->port_sdma_config = PORT_SDMA_CONFIG_VALUE; |
| 1392 | p_eth_port_ctrl->port_serial_control = PORT_SERIAL_CONTROL_VALUE; |
| 1393 | |
| 1394 | p_eth_port_ctrl->port_rx_queue_command = 0; |
| 1395 | p_eth_port_ctrl->port_tx_queue_command = 0; |
| 1396 | |
| 1397 | /* Zero out SW structs */ |
| 1398 | for (queue = 0; queue < MAX_RX_QUEUE_NUM; queue++) { |
| 1399 | CURR_RFD_SET ((ETH_RX_DESC *) 0x00000000, queue); |
| 1400 | USED_RFD_SET ((ETH_RX_DESC *) 0x00000000, queue); |
| 1401 | p_eth_port_ctrl->rx_resource_err[queue] = false; |
| 1402 | } |
| 1403 | |
| 1404 | for (queue = 0; queue < MAX_TX_QUEUE_NUM; queue++) { |
| 1405 | CURR_TFD_SET ((ETH_TX_DESC *) 0x00000000, queue); |
| 1406 | USED_TFD_SET ((ETH_TX_DESC *) 0x00000000, queue); |
| 1407 | FIRST_TFD_SET ((ETH_TX_DESC *) 0x00000000, queue); |
| 1408 | p_eth_port_ctrl->tx_resource_err[queue] = false; |
| 1409 | } |
| 1410 | |
| 1411 | eth_port_reset (p_eth_port_ctrl->port_num); |
| 1412 | |
| 1413 | /* Set access parameters for DRAM bank 0 */ |
| 1414 | win_param.win = ETH_WIN0; /* Use Ethernet window 0 */ |
| 1415 | win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */ |
| 1416 | win_param.attributes = EBAR_ATTR_DRAM_CS0; /* Enable DRAM bank */ |
| 1417 | #ifndef CONFIG_NOT_COHERENT_CACHE |
| 1418 | win_param.attributes |= EBAR_ATTR_DRAM_CACHE_COHERENCY_WB; |
| 1419 | #endif |
| 1420 | win_param.high_addr = 0; |
| 1421 | /* Get bank base */ |
| 1422 | win_param.base_addr = mv_get_dram_bank_base_addr (BANK0); |
| 1423 | win_param.size = mv_get_dram_bank_size (BANK0); /* Get bank size */ |
| 1424 | if (win_param.size == 0) |
| 1425 | win_param.enable = 0; |
| 1426 | else |
| 1427 | win_param.enable = 1; /* Enable the access */ |
| 1428 | win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */ |
| 1429 | |
| 1430 | /* Set the access control for address window (EPAPR) READ & WRITE */ |
| 1431 | eth_set_access_control (p_eth_port_ctrl->port_num, &win_param); |
| 1432 | |
| 1433 | /* Set access parameters for DRAM bank 1 */ |
| 1434 | win_param.win = ETH_WIN1; /* Use Ethernet window 1 */ |
| 1435 | win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */ |
| 1436 | win_param.attributes = EBAR_ATTR_DRAM_CS1; /* Enable DRAM bank */ |
| 1437 | #ifndef CONFIG_NOT_COHERENT_CACHE |
| 1438 | win_param.attributes |= EBAR_ATTR_DRAM_CACHE_COHERENCY_WB; |
| 1439 | #endif |
| 1440 | win_param.high_addr = 0; |
| 1441 | /* Get bank base */ |
| 1442 | win_param.base_addr = mv_get_dram_bank_base_addr (BANK1); |
| 1443 | win_param.size = mv_get_dram_bank_size (BANK1); /* Get bank size */ |
| 1444 | if (win_param.size == 0) |
| 1445 | win_param.enable = 0; |
| 1446 | else |
| 1447 | win_param.enable = 1; /* Enable the access */ |
| 1448 | win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */ |
| 1449 | |
| 1450 | /* Set the access control for address window (EPAPR) READ & WRITE */ |
| 1451 | eth_set_access_control (p_eth_port_ctrl->port_num, &win_param); |
| 1452 | |
| 1453 | /* Set access parameters for DRAM bank 2 */ |
| 1454 | win_param.win = ETH_WIN2; /* Use Ethernet window 2 */ |
| 1455 | win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */ |
| 1456 | win_param.attributes = EBAR_ATTR_DRAM_CS2; /* Enable DRAM bank */ |
| 1457 | #ifndef CONFIG_NOT_COHERENT_CACHE |
| 1458 | win_param.attributes |= EBAR_ATTR_DRAM_CACHE_COHERENCY_WB; |
| 1459 | #endif |
| 1460 | win_param.high_addr = 0; |
| 1461 | /* Get bank base */ |
| 1462 | win_param.base_addr = mv_get_dram_bank_base_addr (BANK2); |
| 1463 | win_param.size = mv_get_dram_bank_size (BANK2); /* Get bank size */ |
| 1464 | if (win_param.size == 0) |
| 1465 | win_param.enable = 0; |
| 1466 | else |
| 1467 | win_param.enable = 1; /* Enable the access */ |
| 1468 | win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */ |
| 1469 | |
| 1470 | /* Set the access control for address window (EPAPR) READ & WRITE */ |
| 1471 | eth_set_access_control (p_eth_port_ctrl->port_num, &win_param); |
| 1472 | |
| 1473 | /* Set access parameters for DRAM bank 3 */ |
| 1474 | win_param.win = ETH_WIN3; /* Use Ethernet window 3 */ |
| 1475 | win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */ |
| 1476 | win_param.attributes = EBAR_ATTR_DRAM_CS3; /* Enable DRAM bank */ |
| 1477 | #ifndef CONFIG_NOT_COHERENT_CACHE |
| 1478 | win_param.attributes |= EBAR_ATTR_DRAM_CACHE_COHERENCY_WB; |
| 1479 | #endif |
| 1480 | win_param.high_addr = 0; |
| 1481 | /* Get bank base */ |
| 1482 | win_param.base_addr = mv_get_dram_bank_base_addr (BANK3); |
| 1483 | win_param.size = mv_get_dram_bank_size (BANK3); /* Get bank size */ |
| 1484 | if (win_param.size == 0) |
| 1485 | win_param.enable = 0; |
| 1486 | else |
| 1487 | win_param.enable = 1; /* Enable the access */ |
| 1488 | win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */ |
| 1489 | |
| 1490 | /* Set the access control for address window (EPAPR) READ & WRITE */ |
| 1491 | eth_set_access_control (p_eth_port_ctrl->port_num, &win_param); |
| 1492 | |
| 1493 | /* Set access parameters for Internal SRAM */ |
| 1494 | win_param.win = ETH_WIN4; /* Use Ethernet window 0 */ |
| 1495 | win_param.target = EBAR_TARGET_CBS; /* Target - Internal SRAM */ |
| 1496 | win_param.attributes = EBAR_ATTR_CBS_SRAM | EBAR_ATTR_CBS_SRAM_BLOCK0; |
| 1497 | win_param.high_addr = 0; |
| 1498 | win_param.base_addr = mv_get_internal_sram_base (); /* Get base addr */ |
| 1499 | win_param.size = MV64360_INTERNAL_SRAM_SIZE; /* Get bank size */ |
| 1500 | win_param.enable = 1; /* Enable the access */ |
| 1501 | win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */ |
| 1502 | |
| 1503 | /* Set the access control for address window (EPAPR) READ & WRITE */ |
| 1504 | eth_set_access_control (p_eth_port_ctrl->port_num, &win_param); |
| 1505 | |
| 1506 | eth_port_init_mac_tables (p_eth_port_ctrl->port_num); |
| 1507 | |
| 1508 | ethernet_phy_set (p_eth_port_ctrl->port_num, |
| 1509 | p_eth_port_ctrl->port_phy_addr); |
| 1510 | |
| 1511 | return; |
| 1512 | |
| 1513 | } |
| 1514 | |
| 1515 | /******************************************************************************* |
| 1516 | * eth_port_start - Start the Ethernet port activity. |
| 1517 | * |
| 1518 | * DESCRIPTION: |
| 1519 | * This routine prepares the Ethernet port for Rx and Tx activity: |
| 1520 | * 1. Initialize Tx and Rx Current Descriptor Pointer for each queue that |
| 1521 | * has been initialized a descriptor's ring (using ether_init_tx_desc_ring |
| 1522 | * for Tx and ether_init_rx_desc_ring for Rx) |
| 1523 | * 2. Initialize and enable the Ethernet configuration port by writing to |
| 1524 | * the port's configuration and command registers. |
| 1525 | * 3. Initialize and enable the SDMA by writing to the SDMA's |
| 1526 | * configuration and command registers. |
| 1527 | * After completing these steps, the ethernet port SDMA can starts to |
| 1528 | * perform Rx and Tx activities. |
| 1529 | * |
| 1530 | * Note: Each Rx and Tx queue descriptor's list must be initialized prior |
| 1531 | * to calling this function (use ether_init_tx_desc_ring for Tx queues and |
| 1532 | * ether_init_rx_desc_ring for Rx queues). |
| 1533 | * |
| 1534 | * INPUT: |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1535 | * ETH_PORT_INFO *p_eth_port_ctrl Ethernet port control struct |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 1536 | * |
| 1537 | * OUTPUT: |
| 1538 | * Ethernet port is ready to receive and transmit. |
| 1539 | * |
| 1540 | * RETURN: |
| 1541 | * false if the port PHY is not up. |
| 1542 | * true otherwise. |
| 1543 | * |
| 1544 | *******************************************************************************/ |
| 1545 | static bool eth_port_start (ETH_PORT_INFO * p_eth_port_ctrl) |
| 1546 | { |
| 1547 | int queue; |
| 1548 | volatile ETH_TX_DESC *p_tx_curr_desc; |
| 1549 | volatile ETH_RX_DESC *p_rx_curr_desc; |
| 1550 | unsigned int phy_reg_data; |
| 1551 | ETH_PORT eth_port_num = p_eth_port_ctrl->port_num; |
| 1552 | |
| 1553 | |
| 1554 | /* Assignment of Tx CTRP of given queue */ |
| 1555 | for (queue = 0; queue < MAX_TX_QUEUE_NUM; queue++) { |
| 1556 | CURR_TFD_GET (p_tx_curr_desc, queue); |
| 1557 | MV_REG_WRITE ((MV64360_ETH_TX_CURRENT_QUEUE_DESC_PTR_0 |
| 1558 | (eth_port_num) |
| 1559 | + (4 * queue)), |
| 1560 | ((unsigned int) p_tx_curr_desc)); |
| 1561 | |
| 1562 | } |
| 1563 | |
| 1564 | /* Assignment of Rx CRDP of given queue */ |
| 1565 | for (queue = 0; queue < MAX_RX_QUEUE_NUM; queue++) { |
| 1566 | CURR_RFD_GET (p_rx_curr_desc, queue); |
| 1567 | MV_REG_WRITE ((MV64360_ETH_RX_CURRENT_QUEUE_DESC_PTR_0 |
| 1568 | (eth_port_num) |
| 1569 | + (4 * queue)), |
| 1570 | ((unsigned int) p_rx_curr_desc)); |
| 1571 | |
| 1572 | if (p_rx_curr_desc != NULL) |
| 1573 | /* Add the assigned Ethernet address to the port's address table */ |
| 1574 | eth_port_uc_addr_set (p_eth_port_ctrl->port_num, |
| 1575 | p_eth_port_ctrl->port_mac_addr, |
| 1576 | queue); |
| 1577 | } |
| 1578 | |
| 1579 | /* Assign port configuration and command. */ |
| 1580 | MV_REG_WRITE (MV64360_ETH_PORT_CONFIG_REG (eth_port_num), |
| 1581 | p_eth_port_ctrl->port_config); |
| 1582 | |
| 1583 | MV_REG_WRITE (MV64360_ETH_PORT_CONFIG_EXTEND_REG (eth_port_num), |
| 1584 | p_eth_port_ctrl->port_config_extend); |
| 1585 | |
| 1586 | MV_REG_WRITE (MV64360_ETH_PORT_SERIAL_CONTROL_REG (eth_port_num), |
| 1587 | p_eth_port_ctrl->port_serial_control); |
| 1588 | |
| 1589 | MV_SET_REG_BITS (MV64360_ETH_PORT_SERIAL_CONTROL_REG (eth_port_num), |
| 1590 | ETH_SERIAL_PORT_ENABLE); |
| 1591 | |
| 1592 | /* Assign port SDMA configuration */ |
| 1593 | MV_REG_WRITE (MV64360_ETH_SDMA_CONFIG_REG (eth_port_num), |
| 1594 | p_eth_port_ctrl->port_sdma_config); |
| 1595 | |
| 1596 | MV_REG_WRITE (MV64360_ETH_TX_QUEUE_0_TOKEN_BUCKET_COUNT |
| 1597 | (eth_port_num), 0x3fffffff); |
| 1598 | MV_REG_WRITE (MV64360_ETH_TX_QUEUE_0_TOKEN_BUCKET_CONFIG |
| 1599 | (eth_port_num), 0x03fffcff); |
| 1600 | /* Turn off the port/queue bandwidth limitation */ |
| 1601 | MV_REG_WRITE (MV64360_ETH_MAXIMUM_TRANSMIT_UNIT (eth_port_num), 0x0); |
| 1602 | |
| 1603 | /* Enable port Rx. */ |
| 1604 | MV_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG (eth_port_num), |
| 1605 | p_eth_port_ctrl->port_rx_queue_command); |
| 1606 | |
| 1607 | /* Check if link is up */ |
| 1608 | eth_port_read_smi_reg (eth_port_num, 1, &phy_reg_data); |
| 1609 | |
| 1610 | if (!(phy_reg_data & 0x20)) |
| 1611 | return false; |
| 1612 | |
| 1613 | return true; |
| 1614 | } |
| 1615 | |
| 1616 | /******************************************************************************* |
| 1617 | * eth_port_uc_addr_set - This function Set the port Unicast address. |
| 1618 | * |
| 1619 | * DESCRIPTION: |
| 1620 | * This function Set the port Ethernet MAC address. |
| 1621 | * |
| 1622 | * INPUT: |
| 1623 | * ETH_PORT eth_port_num Port number. |
| 1624 | * char * p_addr Address to be set |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1625 | * ETH_QUEUE queue Rx queue number for this MAC address. |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 1626 | * |
| 1627 | * OUTPUT: |
| 1628 | * Set MAC address low and high registers. also calls eth_port_uc_addr() |
| 1629 | * To set the unicast table with the proper information. |
| 1630 | * |
| 1631 | * RETURN: |
| 1632 | * N/A. |
| 1633 | * |
| 1634 | *******************************************************************************/ |
| 1635 | static void eth_port_uc_addr_set (ETH_PORT eth_port_num, |
| 1636 | unsigned char *p_addr, ETH_QUEUE queue) |
| 1637 | { |
| 1638 | unsigned int mac_h; |
| 1639 | unsigned int mac_l; |
| 1640 | |
| 1641 | mac_l = (p_addr[4] << 8) | (p_addr[5]); |
| 1642 | mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) | |
| 1643 | (p_addr[2] << 8) | (p_addr[3] << 0); |
| 1644 | |
| 1645 | MV_REG_WRITE (MV64360_ETH_MAC_ADDR_LOW (eth_port_num), mac_l); |
| 1646 | MV_REG_WRITE (MV64360_ETH_MAC_ADDR_HIGH (eth_port_num), mac_h); |
| 1647 | |
| 1648 | /* Accept frames of this address */ |
| 1649 | eth_port_uc_addr (eth_port_num, p_addr[5], queue, ACCEPT_MAC_ADDR); |
| 1650 | |
| 1651 | return; |
| 1652 | } |
| 1653 | |
| 1654 | /******************************************************************************* |
| 1655 | * eth_port_uc_addr - This function Set the port unicast address table |
| 1656 | * |
| 1657 | * DESCRIPTION: |
| 1658 | * This function locates the proper entry in the Unicast table for the |
| 1659 | * specified MAC nibble and sets its properties according to function |
| 1660 | * parameters. |
| 1661 | * |
| 1662 | * INPUT: |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1663 | * ETH_PORT eth_port_num Port number. |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 1664 | * unsigned char uc_nibble Unicast MAC Address last nibble. |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1665 | * ETH_QUEUE queue Rx queue number for this MAC address. |
| 1666 | * int option 0 = Add, 1 = remove address. |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 1667 | * |
| 1668 | * OUTPUT: |
| 1669 | * This function add/removes MAC addresses from the port unicast address |
| 1670 | * table. |
| 1671 | * |
| 1672 | * RETURN: |
| 1673 | * true is output succeeded. |
| 1674 | * false if option parameter is invalid. |
| 1675 | * |
| 1676 | *******************************************************************************/ |
| 1677 | static bool eth_port_uc_addr (ETH_PORT eth_port_num, |
| 1678 | unsigned char uc_nibble, |
| 1679 | ETH_QUEUE queue, int option) |
| 1680 | { |
| 1681 | unsigned int unicast_reg; |
| 1682 | unsigned int tbl_offset; |
| 1683 | unsigned int reg_offset; |
| 1684 | |
| 1685 | /* Locate the Unicast table entry */ |
| 1686 | uc_nibble = (0xf & uc_nibble); |
| 1687 | tbl_offset = (uc_nibble / 4) * 4; /* Register offset from unicast table base */ |
| 1688 | reg_offset = uc_nibble % 4; /* Entry offset within the above register */ |
| 1689 | |
| 1690 | switch (option) { |
| 1691 | case REJECT_MAC_ADDR: |
| 1692 | /* Clear accepts frame bit at specified unicast DA table entry */ |
| 1693 | unicast_reg = |
| 1694 | MV_REG_READ ((MV64360_ETH_DA_FILTER_UNICAST_TABLE_BASE |
| 1695 | (eth_port_num) |
| 1696 | + tbl_offset)); |
| 1697 | |
| 1698 | unicast_reg &= (0x0E << (8 * reg_offset)); |
| 1699 | |
| 1700 | MV_REG_WRITE ((MV64360_ETH_DA_FILTER_UNICAST_TABLE_BASE |
| 1701 | (eth_port_num) |
| 1702 | + tbl_offset), unicast_reg); |
| 1703 | break; |
| 1704 | |
| 1705 | case ACCEPT_MAC_ADDR: |
| 1706 | /* Set accepts frame bit at unicast DA filter table entry */ |
| 1707 | unicast_reg = |
| 1708 | MV_REG_READ ((MV64360_ETH_DA_FILTER_UNICAST_TABLE_BASE |
| 1709 | (eth_port_num) |
| 1710 | + tbl_offset)); |
| 1711 | |
| 1712 | unicast_reg |= ((0x01 | queue) << (8 * reg_offset)); |
| 1713 | |
| 1714 | MV_REG_WRITE ((MV64360_ETH_DA_FILTER_UNICAST_TABLE_BASE |
| 1715 | (eth_port_num) |
| 1716 | + tbl_offset), unicast_reg); |
| 1717 | |
| 1718 | break; |
| 1719 | |
| 1720 | default: |
| 1721 | return false; |
| 1722 | } |
| 1723 | return true; |
| 1724 | } |
| 1725 | |
| 1726 | #if 0 /* FIXME */ |
| 1727 | /******************************************************************************* |
| 1728 | * eth_port_mc_addr - Multicast address settings. |
| 1729 | * |
| 1730 | * DESCRIPTION: |
| 1731 | * This API controls the MV device MAC multicast support. |
| 1732 | * The MV device supports multicast using two tables: |
| 1733 | * 1) Special Multicast Table for MAC addresses of the form |
| 1734 | * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0x_fF). |
| 1735 | * The MAC DA[7:0] bits are used as a pointer to the Special Multicast |
| 1736 | * Table entries in the DA-Filter table. |
| 1737 | * In this case, the function calls eth_port_smc_addr() routine to set the |
| 1738 | * Special Multicast Table. |
| 1739 | * 2) Other Multicast Table for multicast of another type. A CRC-8bit |
| 1740 | * is used as an index to the Other Multicast Table entries in the |
| 1741 | * DA-Filter table. |
| 1742 | * In this case, the function calculates the CRC-8bit value and calls |
| 1743 | * eth_port_omc_addr() routine to set the Other Multicast Table. |
| 1744 | * INPUT: |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1745 | * ETH_PORT eth_port_num Port number. |
| 1746 | * unsigned char *p_addr Unicast MAC Address. |
| 1747 | * ETH_QUEUE queue Rx queue number for this MAC address. |
| 1748 | * int option 0 = Add, 1 = remove address. |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 1749 | * |
| 1750 | * OUTPUT: |
| 1751 | * See description. |
| 1752 | * |
| 1753 | * RETURN: |
| 1754 | * true is output succeeded. |
| 1755 | * false if add_address_table_entry( ) failed. |
| 1756 | * |
| 1757 | *******************************************************************************/ |
| 1758 | static void eth_port_mc_addr (ETH_PORT eth_port_num, |
| 1759 | unsigned char *p_addr, |
| 1760 | ETH_QUEUE queue, int option) |
| 1761 | { |
| 1762 | unsigned int mac_h; |
| 1763 | unsigned int mac_l; |
| 1764 | unsigned char crc_result = 0; |
| 1765 | int mac_array[48]; |
| 1766 | int crc[8]; |
| 1767 | int i; |
| 1768 | |
| 1769 | |
| 1770 | if ((p_addr[0] == 0x01) && |
| 1771 | (p_addr[1] == 0x00) && |
| 1772 | (p_addr[2] == 0x5E) && (p_addr[3] == 0x00) && (p_addr[4] == 0x00)) |
| 1773 | |
| 1774 | eth_port_smc_addr (eth_port_num, p_addr[5], queue, option); |
| 1775 | else { |
| 1776 | /* Calculate CRC-8 out of the given address */ |
| 1777 | mac_h = (p_addr[0] << 8) | (p_addr[1]); |
| 1778 | mac_l = (p_addr[2] << 24) | (p_addr[3] << 16) | |
| 1779 | (p_addr[4] << 8) | (p_addr[5] << 0); |
| 1780 | |
| 1781 | for (i = 0; i < 32; i++) |
| 1782 | mac_array[i] = (mac_l >> i) & 0x1; |
| 1783 | for (i = 32; i < 48; i++) |
| 1784 | mac_array[i] = (mac_h >> (i - 32)) & 0x1; |
| 1785 | |
| 1786 | |
| 1787 | crc[0] = mac_array[45] ^ mac_array[43] ^ mac_array[40] ^ |
| 1788 | mac_array[39] ^ mac_array[35] ^ mac_array[34] ^ |
| 1789 | mac_array[31] ^ mac_array[30] ^ mac_array[28] ^ |
| 1790 | mac_array[23] ^ mac_array[21] ^ mac_array[19] ^ |
| 1791 | mac_array[18] ^ mac_array[16] ^ mac_array[14] ^ |
| 1792 | mac_array[12] ^ mac_array[8] ^ mac_array[7] ^ |
| 1793 | mac_array[6] ^ mac_array[0]; |
| 1794 | |
| 1795 | crc[1] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ |
| 1796 | mac_array[43] ^ mac_array[41] ^ mac_array[39] ^ |
| 1797 | mac_array[36] ^ mac_array[34] ^ mac_array[32] ^ |
| 1798 | mac_array[30] ^ mac_array[29] ^ mac_array[28] ^ |
| 1799 | mac_array[24] ^ mac_array[23] ^ mac_array[22] ^ |
| 1800 | mac_array[21] ^ mac_array[20] ^ mac_array[18] ^ |
| 1801 | mac_array[17] ^ mac_array[16] ^ mac_array[15] ^ |
| 1802 | mac_array[14] ^ mac_array[13] ^ mac_array[12] ^ |
| 1803 | mac_array[9] ^ mac_array[6] ^ mac_array[1] ^ |
| 1804 | mac_array[0]; |
| 1805 | |
| 1806 | crc[2] = mac_array[47] ^ mac_array[46] ^ mac_array[44] ^ |
| 1807 | mac_array[43] ^ mac_array[42] ^ mac_array[39] ^ |
| 1808 | mac_array[37] ^ mac_array[34] ^ mac_array[33] ^ |
| 1809 | mac_array[29] ^ mac_array[28] ^ mac_array[25] ^ |
| 1810 | mac_array[24] ^ mac_array[22] ^ mac_array[17] ^ |
| 1811 | mac_array[15] ^ mac_array[13] ^ mac_array[12] ^ |
| 1812 | mac_array[10] ^ mac_array[8] ^ mac_array[6] ^ |
| 1813 | mac_array[2] ^ mac_array[1] ^ mac_array[0]; |
| 1814 | |
| 1815 | crc[3] = mac_array[47] ^ mac_array[45] ^ mac_array[44] ^ |
| 1816 | mac_array[43] ^ mac_array[40] ^ mac_array[38] ^ |
| 1817 | mac_array[35] ^ mac_array[34] ^ mac_array[30] ^ |
| 1818 | mac_array[29] ^ mac_array[26] ^ mac_array[25] ^ |
| 1819 | mac_array[23] ^ mac_array[18] ^ mac_array[16] ^ |
| 1820 | mac_array[14] ^ mac_array[13] ^ mac_array[11] ^ |
| 1821 | mac_array[9] ^ mac_array[7] ^ mac_array[3] ^ |
| 1822 | mac_array[2] ^ mac_array[1]; |
| 1823 | |
| 1824 | crc[4] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ |
| 1825 | mac_array[41] ^ mac_array[39] ^ mac_array[36] ^ |
| 1826 | mac_array[35] ^ mac_array[31] ^ mac_array[30] ^ |
| 1827 | mac_array[27] ^ mac_array[26] ^ mac_array[24] ^ |
| 1828 | mac_array[19] ^ mac_array[17] ^ mac_array[15] ^ |
| 1829 | mac_array[14] ^ mac_array[12] ^ mac_array[10] ^ |
| 1830 | mac_array[8] ^ mac_array[4] ^ mac_array[3] ^ |
| 1831 | mac_array[2]; |
| 1832 | |
| 1833 | crc[5] = mac_array[47] ^ mac_array[46] ^ mac_array[45] ^ |
| 1834 | mac_array[42] ^ mac_array[40] ^ mac_array[37] ^ |
| 1835 | mac_array[36] ^ mac_array[32] ^ mac_array[31] ^ |
| 1836 | mac_array[28] ^ mac_array[27] ^ mac_array[25] ^ |
| 1837 | mac_array[20] ^ mac_array[18] ^ mac_array[16] ^ |
| 1838 | mac_array[15] ^ mac_array[13] ^ mac_array[11] ^ |
| 1839 | mac_array[9] ^ mac_array[5] ^ mac_array[4] ^ |
| 1840 | mac_array[3]; |
| 1841 | |
| 1842 | crc[6] = mac_array[47] ^ mac_array[46] ^ mac_array[43] ^ |
| 1843 | mac_array[41] ^ mac_array[38] ^ mac_array[37] ^ |
| 1844 | mac_array[33] ^ mac_array[32] ^ mac_array[29] ^ |
| 1845 | mac_array[28] ^ mac_array[26] ^ mac_array[21] ^ |
| 1846 | mac_array[19] ^ mac_array[17] ^ mac_array[16] ^ |
| 1847 | mac_array[14] ^ mac_array[12] ^ mac_array[10] ^ |
| 1848 | mac_array[6] ^ mac_array[5] ^ mac_array[4]; |
| 1849 | |
| 1850 | crc[7] = mac_array[47] ^ mac_array[44] ^ mac_array[42] ^ |
| 1851 | mac_array[39] ^ mac_array[38] ^ mac_array[34] ^ |
| 1852 | mac_array[33] ^ mac_array[30] ^ mac_array[29] ^ |
| 1853 | mac_array[27] ^ mac_array[22] ^ mac_array[20] ^ |
| 1854 | mac_array[18] ^ mac_array[17] ^ mac_array[15] ^ |
| 1855 | mac_array[13] ^ mac_array[11] ^ mac_array[7] ^ |
| 1856 | mac_array[6] ^ mac_array[5]; |
| 1857 | |
| 1858 | for (i = 0; i < 8; i++) |
| 1859 | crc_result = crc_result | (crc[i] << i); |
| 1860 | |
| 1861 | eth_port_omc_addr (eth_port_num, crc_result, queue, option); |
| 1862 | } |
| 1863 | return; |
| 1864 | } |
| 1865 | |
| 1866 | /******************************************************************************* |
| 1867 | * eth_port_smc_addr - Special Multicast address settings. |
| 1868 | * |
| 1869 | * DESCRIPTION: |
| 1870 | * This routine controls the MV device special MAC multicast support. |
| 1871 | * The Special Multicast Table for MAC addresses supports MAC of the form |
| 1872 | * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0x_fF). |
| 1873 | * The MAC DA[7:0] bits are used as a pointer to the Special Multicast |
| 1874 | * Table entries in the DA-Filter table. |
| 1875 | * This function set the Special Multicast Table appropriate entry |
| 1876 | * according to the argument given. |
| 1877 | * |
| 1878 | * INPUT: |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1879 | * ETH_PORT eth_port_num Port number. |
| 1880 | * unsigned char mc_byte Multicast addr last byte (MAC DA[7:0] bits). |
| 1881 | * ETH_QUEUE queue Rx queue number for this MAC address. |
| 1882 | * int option 0 = Add, 1 = remove address. |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 1883 | * |
| 1884 | * OUTPUT: |
| 1885 | * See description. |
| 1886 | * |
| 1887 | * RETURN: |
| 1888 | * true is output succeeded. |
| 1889 | * false if option parameter is invalid. |
| 1890 | * |
| 1891 | *******************************************************************************/ |
| 1892 | static bool eth_port_smc_addr (ETH_PORT eth_port_num, |
| 1893 | unsigned char mc_byte, |
| 1894 | ETH_QUEUE queue, int option) |
| 1895 | { |
| 1896 | unsigned int smc_table_reg; |
| 1897 | unsigned int tbl_offset; |
| 1898 | unsigned int reg_offset; |
| 1899 | |
| 1900 | /* Locate the SMC table entry */ |
| 1901 | tbl_offset = (mc_byte / 4) * 4; /* Register offset from SMC table base */ |
| 1902 | reg_offset = mc_byte % 4; /* Entry offset within the above register */ |
| 1903 | queue &= 0x7; |
| 1904 | |
| 1905 | switch (option) { |
| 1906 | case REJECT_MAC_ADDR: |
| 1907 | /* Clear accepts frame bit at specified Special DA table entry */ |
| 1908 | smc_table_reg = |
| 1909 | MV_REG_READ ((MV64360_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset)); |
| 1910 | smc_table_reg &= (0x0E << (8 * reg_offset)); |
| 1911 | |
| 1912 | MV_REG_WRITE ((MV64360_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), smc_table_reg); |
| 1913 | break; |
| 1914 | |
| 1915 | case ACCEPT_MAC_ADDR: |
| 1916 | /* Set accepts frame bit at specified Special DA table entry */ |
| 1917 | smc_table_reg = |
| 1918 | MV_REG_READ ((MV64360_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset)); |
| 1919 | smc_table_reg |= ((0x01 | queue) << (8 * reg_offset)); |
| 1920 | |
| 1921 | MV_REG_WRITE ((MV64360_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), smc_table_reg); |
| 1922 | break; |
| 1923 | |
| 1924 | default: |
| 1925 | return false; |
| 1926 | } |
| 1927 | return true; |
| 1928 | } |
| 1929 | |
| 1930 | /******************************************************************************* |
| 1931 | * eth_port_omc_addr - Multicast address settings. |
| 1932 | * |
| 1933 | * DESCRIPTION: |
| 1934 | * This routine controls the MV device Other MAC multicast support. |
| 1935 | * The Other Multicast Table is used for multicast of another type. |
| 1936 | * A CRC-8bit is used as an index to the Other Multicast Table entries |
| 1937 | * in the DA-Filter table. |
| 1938 | * The function gets the CRC-8bit value from the calling routine and |
| 1939 | * set the Other Multicast Table appropriate entry according to the |
| 1940 | * CRC-8 argument given. |
| 1941 | * |
| 1942 | * INPUT: |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1943 | * ETH_PORT eth_port_num Port number. |
| 1944 | * unsigned char crc8 A CRC-8bit (Polynomial: x^8+x^2+x^1+1). |
| 1945 | * ETH_QUEUE queue Rx queue number for this MAC address. |
| 1946 | * int option 0 = Add, 1 = remove address. |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 1947 | * |
| 1948 | * OUTPUT: |
| 1949 | * See description. |
| 1950 | * |
| 1951 | * RETURN: |
| 1952 | * true is output succeeded. |
| 1953 | * false if option parameter is invalid. |
| 1954 | * |
| 1955 | *******************************************************************************/ |
| 1956 | static bool eth_port_omc_addr (ETH_PORT eth_port_num, |
| 1957 | unsigned char crc8, |
| 1958 | ETH_QUEUE queue, int option) |
| 1959 | { |
| 1960 | unsigned int omc_table_reg; |
| 1961 | unsigned int tbl_offset; |
| 1962 | unsigned int reg_offset; |
| 1963 | |
| 1964 | /* Locate the OMC table entry */ |
| 1965 | tbl_offset = (crc8 / 4) * 4; /* Register offset from OMC table base */ |
| 1966 | reg_offset = crc8 % 4; /* Entry offset within the above register */ |
| 1967 | queue &= 0x7; |
| 1968 | |
| 1969 | switch (option) { |
| 1970 | case REJECT_MAC_ADDR: |
| 1971 | /* Clear accepts frame bit at specified Other DA table entry */ |
| 1972 | omc_table_reg = |
| 1973 | MV_REG_READ ((MV64360_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset)); |
| 1974 | omc_table_reg &= (0x0E << (8 * reg_offset)); |
| 1975 | |
| 1976 | MV_REG_WRITE ((MV64360_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), omc_table_reg); |
| 1977 | break; |
| 1978 | |
| 1979 | case ACCEPT_MAC_ADDR: |
| 1980 | /* Set accepts frame bit at specified Other DA table entry */ |
| 1981 | omc_table_reg = |
| 1982 | MV_REG_READ ((MV64360_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset)); |
| 1983 | omc_table_reg |= ((0x01 | queue) << (8 * reg_offset)); |
| 1984 | |
| 1985 | MV_REG_WRITE ((MV64360_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), omc_table_reg); |
| 1986 | break; |
| 1987 | |
| 1988 | default: |
| 1989 | return false; |
| 1990 | } |
| 1991 | return true; |
| 1992 | } |
| 1993 | #endif |
| 1994 | |
| 1995 | /******************************************************************************* |
| 1996 | * eth_port_init_mac_tables - Clear all entrance in the UC, SMC and OMC tables |
| 1997 | * |
| 1998 | * DESCRIPTION: |
| 1999 | * Go through all the DA filter tables (Unicast, Special Multicast & Other |
| 2000 | * Multicast) and set each entry to 0. |
| 2001 | * |
| 2002 | * INPUT: |
| 2003 | * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum. |
| 2004 | * |
| 2005 | * OUTPUT: |
| 2006 | * Multicast and Unicast packets are rejected. |
| 2007 | * |
| 2008 | * RETURN: |
| 2009 | * None. |
| 2010 | * |
| 2011 | *******************************************************************************/ |
| 2012 | static void eth_port_init_mac_tables (ETH_PORT eth_port_num) |
| 2013 | { |
| 2014 | int table_index; |
| 2015 | |
| 2016 | /* Clear DA filter unicast table (Ex_dFUT) */ |
| 2017 | for (table_index = 0; table_index <= 0xC; table_index += 4) |
| 2018 | MV_REG_WRITE ((MV64360_ETH_DA_FILTER_UNICAST_TABLE_BASE |
| 2019 | (eth_port_num) + table_index), 0); |
| 2020 | |
| 2021 | for (table_index = 0; table_index <= 0xFC; table_index += 4) { |
| 2022 | /* Clear DA filter special multicast table (Ex_dFSMT) */ |
| 2023 | MV_REG_WRITE ((MV64360_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + table_index), 0); |
| 2024 | /* Clear DA filter other multicast table (Ex_dFOMT) */ |
| 2025 | MV_REG_WRITE ((MV64360_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + table_index), 0); |
| 2026 | } |
| 2027 | } |
| 2028 | |
| 2029 | /******************************************************************************* |
| 2030 | * eth_clear_mib_counters - Clear all MIB counters |
| 2031 | * |
| 2032 | * DESCRIPTION: |
| 2033 | * This function clears all MIB counters of a specific ethernet port. |
| 2034 | * A read from the MIB counter will reset the counter. |
| 2035 | * |
| 2036 | * INPUT: |
| 2037 | * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum. |
| 2038 | * |
| 2039 | * OUTPUT: |
| 2040 | * After reading all MIB counters, the counters resets. |
| 2041 | * |
| 2042 | * RETURN: |
| 2043 | * MIB counter value. |
| 2044 | * |
| 2045 | *******************************************************************************/ |
| 2046 | static void eth_clear_mib_counters (ETH_PORT eth_port_num) |
| 2047 | { |
| 2048 | int i; |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 2049 | |
| 2050 | /* Perform dummy reads from MIB counters */ |
| 2051 | for (i = ETH_MIB_GOOD_OCTETS_RECEIVED_LOW; i < ETH_MIB_LATE_COLLISION; |
Anatolij Gustschin | 821315f | 2011-12-20 05:16:45 +0000 | [diff] [blame] | 2052 | i += 4) { |
| 2053 | (void)MV_REG_READ ((MV64360_ETH_MIB_COUNTERS_BASE |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 2054 | (eth_port_num) + i)); |
Anatolij Gustschin | 821315f | 2011-12-20 05:16:45 +0000 | [diff] [blame] | 2055 | } |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 2056 | |
| 2057 | return; |
| 2058 | } |
| 2059 | |
| 2060 | /******************************************************************************* |
| 2061 | * eth_read_mib_counter - Read a MIB counter |
| 2062 | * |
| 2063 | * DESCRIPTION: |
| 2064 | * This function reads a MIB counter of a specific ethernet port. |
| 2065 | * NOTE - If read from ETH_MIB_GOOD_OCTETS_RECEIVED_LOW, then the |
| 2066 | * following read must be from ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH |
| 2067 | * register. The same applies for ETH_MIB_GOOD_OCTETS_SENT_LOW and |
| 2068 | * ETH_MIB_GOOD_OCTETS_SENT_HIGH |
| 2069 | * |
| 2070 | * INPUT: |
| 2071 | * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum. |
| 2072 | * unsigned int mib_offset MIB counter offset (use ETH_MIB_... macros). |
| 2073 | * |
| 2074 | * OUTPUT: |
| 2075 | * After reading the MIB counter, the counter resets. |
| 2076 | * |
| 2077 | * RETURN: |
| 2078 | * MIB counter value. |
| 2079 | * |
| 2080 | *******************************************************************************/ |
| 2081 | unsigned int eth_read_mib_counter (ETH_PORT eth_port_num, |
| 2082 | unsigned int mib_offset) |
| 2083 | { |
| 2084 | return (MV_REG_READ (MV64360_ETH_MIB_COUNTERS_BASE (eth_port_num) |
| 2085 | + mib_offset)); |
| 2086 | } |
| 2087 | |
| 2088 | /******************************************************************************* |
| 2089 | * ethernet_phy_set - Set the ethernet port PHY address. |
| 2090 | * |
| 2091 | * DESCRIPTION: |
| 2092 | * This routine set the ethernet port PHY address according to given |
| 2093 | * parameter. |
| 2094 | * |
| 2095 | * INPUT: |
| 2096 | * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum. |
| 2097 | * |
| 2098 | * OUTPUT: |
| 2099 | * Set PHY Address Register with given PHY address parameter. |
| 2100 | * |
| 2101 | * RETURN: |
| 2102 | * None. |
| 2103 | * |
| 2104 | *******************************************************************************/ |
| 2105 | static void ethernet_phy_set (ETH_PORT eth_port_num, int phy_addr) |
| 2106 | { |
| 2107 | unsigned int reg_data; |
| 2108 | |
| 2109 | reg_data = MV_REG_READ (MV64360_ETH_PHY_ADDR_REG); |
| 2110 | |
| 2111 | reg_data &= ~(0x1F << (5 * eth_port_num)); |
| 2112 | reg_data |= (phy_addr << (5 * eth_port_num)); |
| 2113 | |
| 2114 | MV_REG_WRITE (MV64360_ETH_PHY_ADDR_REG, reg_data); |
| 2115 | |
| 2116 | return; |
| 2117 | } |
| 2118 | |
| 2119 | /******************************************************************************* |
| 2120 | * ethernet_phy_get - Get the ethernet port PHY address. |
| 2121 | * |
| 2122 | * DESCRIPTION: |
| 2123 | * This routine returns the given ethernet port PHY address. |
| 2124 | * |
| 2125 | * INPUT: |
| 2126 | * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum. |
| 2127 | * |
| 2128 | * OUTPUT: |
| 2129 | * None. |
| 2130 | * |
| 2131 | * RETURN: |
| 2132 | * PHY address. |
| 2133 | * |
| 2134 | *******************************************************************************/ |
| 2135 | static int ethernet_phy_get (ETH_PORT eth_port_num) |
| 2136 | { |
| 2137 | unsigned int reg_data; |
| 2138 | |
| 2139 | reg_data = MV_REG_READ (MV64360_ETH_PHY_ADDR_REG); |
| 2140 | |
| 2141 | return ((reg_data >> (5 * eth_port_num)) & 0x1f); |
| 2142 | } |
| 2143 | |
| 2144 | /******************************************************************************* |
| 2145 | * ethernet_phy_reset - Reset Ethernet port PHY. |
| 2146 | * |
| 2147 | * DESCRIPTION: |
| 2148 | * This routine utilize the SMI interface to reset the ethernet port PHY. |
| 2149 | * The routine waits until the link is up again or link up is timeout. |
| 2150 | * |
| 2151 | * INPUT: |
| 2152 | * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum. |
| 2153 | * |
| 2154 | * OUTPUT: |
| 2155 | * The ethernet port PHY renew its link. |
| 2156 | * |
| 2157 | * RETURN: |
| 2158 | * None. |
| 2159 | * |
| 2160 | *******************************************************************************/ |
| 2161 | static bool ethernet_phy_reset (ETH_PORT eth_port_num) |
| 2162 | { |
| 2163 | unsigned int time_out = 50; |
| 2164 | unsigned int phy_reg_data; |
| 2165 | |
| 2166 | /* Reset the PHY */ |
| 2167 | eth_port_read_smi_reg (eth_port_num, 0, &phy_reg_data); |
| 2168 | phy_reg_data |= 0x8000; /* Set bit 15 to reset the PHY */ |
| 2169 | eth_port_write_smi_reg (eth_port_num, 0, phy_reg_data); |
| 2170 | |
| 2171 | /* Poll on the PHY LINK */ |
| 2172 | do { |
| 2173 | eth_port_read_smi_reg (eth_port_num, 1, &phy_reg_data); |
| 2174 | |
| 2175 | if (time_out-- == 0) |
| 2176 | return false; |
| 2177 | } |
| 2178 | while (!(phy_reg_data & 0x20)); |
| 2179 | |
| 2180 | return true; |
| 2181 | } |
| 2182 | |
| 2183 | /******************************************************************************* |
| 2184 | * eth_port_reset - Reset Ethernet port |
| 2185 | * |
| 2186 | * DESCRIPTION: |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 2187 | * This routine resets the chip by aborting any SDMA engine activity and |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 2188 | * clearing the MIB counters. The Receiver and the Transmit unit are in |
| 2189 | * idle state after this command is performed and the port is disabled. |
| 2190 | * |
| 2191 | * INPUT: |
| 2192 | * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum. |
| 2193 | * |
| 2194 | * OUTPUT: |
| 2195 | * Channel activity is halted. |
| 2196 | * |
| 2197 | * RETURN: |
| 2198 | * None. |
| 2199 | * |
| 2200 | *******************************************************************************/ |
| 2201 | static void eth_port_reset (ETH_PORT eth_port_num) |
| 2202 | { |
| 2203 | unsigned int reg_data; |
| 2204 | |
| 2205 | /* Stop Tx port activity. Check port Tx activity. */ |
| 2206 | reg_data = |
| 2207 | MV_REG_READ (MV64360_ETH_TRANSMIT_QUEUE_COMMAND_REG |
| 2208 | (eth_port_num)); |
| 2209 | |
| 2210 | if (reg_data & 0xFF) { |
| 2211 | /* Issue stop command for active channels only */ |
| 2212 | MV_REG_WRITE (MV64360_ETH_TRANSMIT_QUEUE_COMMAND_REG |
| 2213 | (eth_port_num), (reg_data << 8)); |
| 2214 | |
| 2215 | /* Wait for all Tx activity to terminate. */ |
| 2216 | do { |
| 2217 | /* Check port cause register that all Tx queues are stopped */ |
| 2218 | reg_data = |
| 2219 | MV_REG_READ |
| 2220 | (MV64360_ETH_TRANSMIT_QUEUE_COMMAND_REG |
| 2221 | (eth_port_num)); |
| 2222 | } |
| 2223 | while (reg_data & 0xFF); |
| 2224 | } |
| 2225 | |
| 2226 | /* Stop Rx port activity. Check port Rx activity. */ |
| 2227 | reg_data = |
| 2228 | MV_REG_READ (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG |
| 2229 | (eth_port_num)); |
| 2230 | |
| 2231 | if (reg_data & 0xFF) { |
| 2232 | /* Issue stop command for active channels only */ |
| 2233 | MV_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG |
| 2234 | (eth_port_num), (reg_data << 8)); |
| 2235 | |
| 2236 | /* Wait for all Rx activity to terminate. */ |
| 2237 | do { |
| 2238 | /* Check port cause register that all Rx queues are stopped */ |
| 2239 | reg_data = |
| 2240 | MV_REG_READ |
| 2241 | (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG |
| 2242 | (eth_port_num)); |
| 2243 | } |
| 2244 | while (reg_data & 0xFF); |
| 2245 | } |
| 2246 | |
| 2247 | |
| 2248 | /* Clear all MIB counters */ |
| 2249 | eth_clear_mib_counters (eth_port_num); |
| 2250 | |
| 2251 | /* Reset the Enable bit in the Configuration Register */ |
| 2252 | reg_data = |
| 2253 | MV_REG_READ (MV64360_ETH_PORT_SERIAL_CONTROL_REG |
| 2254 | (eth_port_num)); |
| 2255 | reg_data &= ~ETH_SERIAL_PORT_ENABLE; |
| 2256 | MV_REG_WRITE (MV64360_ETH_PORT_SERIAL_CONTROL_REG (eth_port_num), |
| 2257 | reg_data); |
| 2258 | |
| 2259 | return; |
| 2260 | } |
| 2261 | |
| 2262 | #if 0 /* Not needed here */ |
| 2263 | /******************************************************************************* |
| 2264 | * ethernet_set_config_reg - Set specified bits in configuration register. |
| 2265 | * |
| 2266 | * DESCRIPTION: |
| 2267 | * This function sets specified bits in the given ethernet |
| 2268 | * configuration register. |
| 2269 | * |
| 2270 | * INPUT: |
| 2271 | * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum. |
| 2272 | * unsigned int value 32 bit value. |
| 2273 | * |
| 2274 | * OUTPUT: |
| 2275 | * The set bits in the value parameter are set in the configuration |
| 2276 | * register. |
| 2277 | * |
| 2278 | * RETURN: |
| 2279 | * None. |
| 2280 | * |
| 2281 | *******************************************************************************/ |
| 2282 | static void ethernet_set_config_reg (ETH_PORT eth_port_num, |
| 2283 | unsigned int value) |
| 2284 | { |
| 2285 | unsigned int eth_config_reg; |
| 2286 | |
| 2287 | eth_config_reg = |
| 2288 | MV_REG_READ (MV64360_ETH_PORT_CONFIG_REG (eth_port_num)); |
| 2289 | eth_config_reg |= value; |
| 2290 | MV_REG_WRITE (MV64360_ETH_PORT_CONFIG_REG (eth_port_num), |
| 2291 | eth_config_reg); |
| 2292 | |
| 2293 | return; |
| 2294 | } |
| 2295 | #endif |
| 2296 | |
| 2297 | #if 0 /* FIXME */ |
| 2298 | /******************************************************************************* |
| 2299 | * ethernet_reset_config_reg - Reset specified bits in configuration register. |
| 2300 | * |
| 2301 | * DESCRIPTION: |
| 2302 | * This function resets specified bits in the given Ethernet |
| 2303 | * configuration register. |
| 2304 | * |
| 2305 | * INPUT: |
| 2306 | * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum. |
| 2307 | * unsigned int value 32 bit value. |
| 2308 | * |
| 2309 | * OUTPUT: |
| 2310 | * The set bits in the value parameter are reset in the configuration |
| 2311 | * register. |
| 2312 | * |
| 2313 | * RETURN: |
| 2314 | * None. |
| 2315 | * |
| 2316 | *******************************************************************************/ |
| 2317 | static void ethernet_reset_config_reg (ETH_PORT eth_port_num, |
| 2318 | unsigned int value) |
| 2319 | { |
| 2320 | unsigned int eth_config_reg; |
| 2321 | |
| 2322 | eth_config_reg = MV_REG_READ (MV64360_ETH_PORT_CONFIG_EXTEND_REG |
| 2323 | (eth_port_num)); |
| 2324 | eth_config_reg &= ~value; |
| 2325 | MV_REG_WRITE (MV64360_ETH_PORT_CONFIG_EXTEND_REG (eth_port_num), |
| 2326 | eth_config_reg); |
| 2327 | |
| 2328 | return; |
| 2329 | } |
| 2330 | #endif |
| 2331 | |
| 2332 | #if 0 /* Not needed here */ |
| 2333 | /******************************************************************************* |
| 2334 | * ethernet_get_config_reg - Get the port configuration register |
| 2335 | * |
| 2336 | * DESCRIPTION: |
| 2337 | * This function returns the configuration register value of the given |
| 2338 | * ethernet port. |
| 2339 | * |
| 2340 | * INPUT: |
| 2341 | * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum. |
| 2342 | * |
| 2343 | * OUTPUT: |
| 2344 | * None. |
| 2345 | * |
| 2346 | * RETURN: |
| 2347 | * Port configuration register value. |
| 2348 | * |
| 2349 | *******************************************************************************/ |
| 2350 | static unsigned int ethernet_get_config_reg (ETH_PORT eth_port_num) |
| 2351 | { |
| 2352 | unsigned int eth_config_reg; |
| 2353 | |
| 2354 | eth_config_reg = MV_REG_READ (MV64360_ETH_PORT_CONFIG_EXTEND_REG |
| 2355 | (eth_port_num)); |
| 2356 | return eth_config_reg; |
| 2357 | } |
| 2358 | |
| 2359 | #endif |
| 2360 | |
| 2361 | /******************************************************************************* |
| 2362 | * eth_port_read_smi_reg - Read PHY registers |
| 2363 | * |
| 2364 | * DESCRIPTION: |
| 2365 | * This routine utilize the SMI interface to interact with the PHY in |
| 2366 | * order to perform PHY register read. |
| 2367 | * |
| 2368 | * INPUT: |
| 2369 | * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum. |
| 2370 | * unsigned int phy_reg PHY register address offset. |
| 2371 | * unsigned int *value Register value buffer. |
| 2372 | * |
| 2373 | * OUTPUT: |
| 2374 | * Write the value of a specified PHY register into given buffer. |
| 2375 | * |
| 2376 | * RETURN: |
| 2377 | * false if the PHY is busy or read data is not in valid state. |
| 2378 | * true otherwise. |
| 2379 | * |
| 2380 | *******************************************************************************/ |
| 2381 | static bool eth_port_read_smi_reg (ETH_PORT eth_port_num, |
| 2382 | unsigned int phy_reg, unsigned int *value) |
| 2383 | { |
| 2384 | unsigned int reg_value; |
| 2385 | unsigned int time_out = PHY_BUSY_TIMEOUT; |
| 2386 | int phy_addr; |
| 2387 | |
| 2388 | phy_addr = ethernet_phy_get (eth_port_num); |
| 2389 | /* printf(" Phy-Port %d has addess %d \n",eth_port_num, phy_addr );*/ |
| 2390 | |
| 2391 | /* first check that it is not busy */ |
| 2392 | do { |
| 2393 | reg_value = MV_REG_READ (MV64360_ETH_SMI_REG); |
| 2394 | if (time_out-- == 0) { |
| 2395 | return false; |
| 2396 | } |
| 2397 | } |
| 2398 | while (reg_value & ETH_SMI_BUSY); |
| 2399 | |
| 2400 | /* not busy */ |
| 2401 | |
| 2402 | MV_REG_WRITE (MV64360_ETH_SMI_REG, |
| 2403 | (phy_addr << 16) | (phy_reg << 21) | |
| 2404 | ETH_SMI_OPCODE_READ); |
| 2405 | |
| 2406 | time_out = PHY_BUSY_TIMEOUT; /* initialize the time out var again */ |
| 2407 | |
| 2408 | do { |
| 2409 | reg_value = MV_REG_READ (MV64360_ETH_SMI_REG); |
| 2410 | if (time_out-- == 0) { |
| 2411 | return false; |
| 2412 | } |
| 2413 | } |
| 2414 | while ((reg_value & ETH_SMI_READ_VALID) != ETH_SMI_READ_VALID); /* Bit set equ operation done */ |
| 2415 | |
| 2416 | /* Wait for the data to update in the SMI register */ |
| 2417 | #define PHY_UPDATE_TIMEOUT 10000 |
| 2418 | for (time_out = 0; time_out < PHY_UPDATE_TIMEOUT; time_out++); |
| 2419 | |
| 2420 | reg_value = MV_REG_READ (MV64360_ETH_SMI_REG); |
| 2421 | |
| 2422 | *value = reg_value & 0xffff; |
| 2423 | |
| 2424 | return true; |
| 2425 | } |
| 2426 | |
| 2427 | /******************************************************************************* |
| 2428 | * eth_port_write_smi_reg - Write to PHY registers |
| 2429 | * |
| 2430 | * DESCRIPTION: |
| 2431 | * This routine utilize the SMI interface to interact with the PHY in |
| 2432 | * order to perform writes to PHY registers. |
| 2433 | * |
| 2434 | * INPUT: |
| 2435 | * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum. |
| 2436 | * unsigned int phy_reg PHY register address offset. |
| 2437 | * unsigned int value Register value. |
| 2438 | * |
| 2439 | * OUTPUT: |
| 2440 | * Write the given value to the specified PHY register. |
| 2441 | * |
| 2442 | * RETURN: |
| 2443 | * false if the PHY is busy. |
| 2444 | * true otherwise. |
| 2445 | * |
| 2446 | *******************************************************************************/ |
| 2447 | static bool eth_port_write_smi_reg (ETH_PORT eth_port_num, |
| 2448 | unsigned int phy_reg, unsigned int value) |
| 2449 | { |
| 2450 | unsigned int reg_value; |
| 2451 | unsigned int time_out = PHY_BUSY_TIMEOUT; |
| 2452 | int phy_addr; |
| 2453 | |
| 2454 | phy_addr = ethernet_phy_get (eth_port_num); |
| 2455 | |
| 2456 | /* first check that it is not busy */ |
| 2457 | do { |
| 2458 | reg_value = MV_REG_READ (MV64360_ETH_SMI_REG); |
| 2459 | if (time_out-- == 0) { |
| 2460 | return false; |
| 2461 | } |
| 2462 | } |
| 2463 | while (reg_value & ETH_SMI_BUSY); |
| 2464 | |
| 2465 | /* not busy */ |
| 2466 | MV_REG_WRITE (MV64360_ETH_SMI_REG, |
| 2467 | (phy_addr << 16) | (phy_reg << 21) | |
| 2468 | ETH_SMI_OPCODE_WRITE | (value & 0xffff)); |
| 2469 | return true; |
| 2470 | } |
| 2471 | |
| 2472 | /******************************************************************************* |
| 2473 | * eth_set_access_control - Config address decode parameters for Ethernet unit |
| 2474 | * |
| 2475 | * DESCRIPTION: |
| 2476 | * This function configures the address decode parameters for the Gigabit |
| 2477 | * Ethernet Controller according the given parameters struct. |
| 2478 | * |
| 2479 | * INPUT: |
| 2480 | * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum. |
| 2481 | * ETH_WIN_PARAM *param Address decode parameter struct. |
| 2482 | * |
| 2483 | * OUTPUT: |
| 2484 | * An access window is opened using the given access parameters. |
| 2485 | * |
| 2486 | * RETURN: |
| 2487 | * None. |
| 2488 | * |
| 2489 | *******************************************************************************/ |
| 2490 | static void eth_set_access_control (ETH_PORT eth_port_num, |
| 2491 | ETH_WIN_PARAM * param) |
| 2492 | { |
| 2493 | unsigned int access_prot_reg; |
| 2494 | |
| 2495 | /* Set access control register */ |
| 2496 | access_prot_reg = MV_REG_READ (MV64360_ETH_ACCESS_PROTECTION_REG |
| 2497 | (eth_port_num)); |
| 2498 | access_prot_reg &= (~(3 << (param->win * 2))); /* clear window permission */ |
| 2499 | access_prot_reg |= (param->access_ctrl << (param->win * 2)); |
| 2500 | MV_REG_WRITE (MV64360_ETH_ACCESS_PROTECTION_REG (eth_port_num), |
| 2501 | access_prot_reg); |
| 2502 | |
| 2503 | /* Set window Size reg (SR) */ |
| 2504 | MV_REG_WRITE ((MV64360_ETH_SIZE_REG_0 + |
| 2505 | (ETH_SIZE_REG_GAP * param->win)), |
| 2506 | (((param->size / 0x10000) - 1) << 16)); |
| 2507 | |
| 2508 | /* Set window Base address reg (BA) */ |
| 2509 | MV_REG_WRITE ((MV64360_ETH_BAR_0 + (ETH_BAR_GAP * param->win)), |
| 2510 | (param->target | param->attributes | param->base_addr)); |
| 2511 | /* High address remap reg (HARR) */ |
| 2512 | if (param->win < 4) |
| 2513 | MV_REG_WRITE ((MV64360_ETH_HIGH_ADDR_REMAP_REG_0 + |
| 2514 | (ETH_HIGH_ADDR_REMAP_REG_GAP * param->win)), |
| 2515 | param->high_addr); |
| 2516 | |
| 2517 | /* Base address enable reg (BARER) */ |
| 2518 | if (param->enable == 1) |
| 2519 | MV_RESET_REG_BITS (MV64360_ETH_BASE_ADDR_ENABLE_REG, |
| 2520 | (1 << param->win)); |
| 2521 | else |
| 2522 | MV_SET_REG_BITS (MV64360_ETH_BASE_ADDR_ENABLE_REG, |
| 2523 | (1 << param->win)); |
| 2524 | } |
| 2525 | |
| 2526 | /******************************************************************************* |
| 2527 | * ether_init_rx_desc_ring - Curve a Rx chain desc list and buffer in memory. |
| 2528 | * |
| 2529 | * DESCRIPTION: |
| 2530 | * This function prepares a Rx chained list of descriptors and packet |
| 2531 | * buffers in a form of a ring. The routine must be called after port |
| 2532 | * initialization routine and before port start routine. |
| 2533 | * The Ethernet SDMA engine uses CPU bus addresses to access the various |
| 2534 | * devices in the system (i.e. DRAM). This function uses the ethernet |
| 2535 | * struct 'virtual to physical' routine (set by the user) to set the ring |
| 2536 | * with physical addresses. |
| 2537 | * |
| 2538 | * INPUT: |
| 2539 | * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct. |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 2540 | * ETH_QUEUE rx_queue Number of Rx queue. |
| 2541 | * int rx_desc_num Number of Rx descriptors |
| 2542 | * int rx_buff_size Size of Rx buffer |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 2543 | * unsigned int rx_desc_base_addr Rx descriptors memory area base addr. |
| 2544 | * unsigned int rx_buff_base_addr Rx buffer memory area base addr. |
| 2545 | * |
| 2546 | * OUTPUT: |
| 2547 | * The routine updates the Ethernet port control struct with information |
| 2548 | * regarding the Rx descriptors and buffers. |
| 2549 | * |
| 2550 | * RETURN: |
| 2551 | * false if the given descriptors memory area is not aligned according to |
| 2552 | * Ethernet SDMA specifications. |
| 2553 | * true otherwise. |
| 2554 | * |
| 2555 | *******************************************************************************/ |
| 2556 | static bool ether_init_rx_desc_ring (ETH_PORT_INFO * p_eth_port_ctrl, |
| 2557 | ETH_QUEUE rx_queue, |
| 2558 | int rx_desc_num, |
| 2559 | int rx_buff_size, |
| 2560 | unsigned int rx_desc_base_addr, |
| 2561 | unsigned int rx_buff_base_addr) |
| 2562 | { |
| 2563 | ETH_RX_DESC *p_rx_desc; |
| 2564 | ETH_RX_DESC *p_rx_prev_desc; /* pointer to link with the last descriptor */ |
| 2565 | unsigned int buffer_addr; |
| 2566 | int ix; /* a counter */ |
| 2567 | |
| 2568 | |
| 2569 | p_rx_desc = (ETH_RX_DESC *) rx_desc_base_addr; |
| 2570 | p_rx_prev_desc = p_rx_desc; |
| 2571 | buffer_addr = rx_buff_base_addr; |
| 2572 | |
| 2573 | /* Rx desc Must be 4LW aligned (i.e. Descriptor_Address[3:0]=0000). */ |
| 2574 | if (rx_buff_base_addr & 0xF) |
| 2575 | return false; |
| 2576 | |
| 2577 | /* Rx buffers are limited to 64K bytes and Minimum size is 8 bytes */ |
| 2578 | if ((rx_buff_size < 8) || (rx_buff_size > RX_BUFFER_MAX_SIZE)) |
| 2579 | return false; |
| 2580 | |
| 2581 | /* Rx buffers must be 64-bit aligned. */ |
| 2582 | if ((rx_buff_base_addr + rx_buff_size) & 0x7) |
| 2583 | return false; |
| 2584 | |
| 2585 | /* initialize the Rx descriptors ring */ |
| 2586 | for (ix = 0; ix < rx_desc_num; ix++) { |
| 2587 | p_rx_desc->buf_size = rx_buff_size; |
| 2588 | p_rx_desc->byte_cnt = 0x0000; |
| 2589 | p_rx_desc->cmd_sts = |
| 2590 | ETH_BUFFER_OWNED_BY_DMA | ETH_RX_ENABLE_INTERRUPT; |
| 2591 | p_rx_desc->next_desc_ptr = |
| 2592 | ((unsigned int) p_rx_desc) + RX_DESC_ALIGNED_SIZE; |
| 2593 | p_rx_desc->buf_ptr = buffer_addr; |
| 2594 | p_rx_desc->return_info = 0x00000000; |
| 2595 | D_CACHE_FLUSH_LINE (p_rx_desc, 0); |
| 2596 | buffer_addr += rx_buff_size; |
| 2597 | p_rx_prev_desc = p_rx_desc; |
| 2598 | p_rx_desc = (ETH_RX_DESC *) |
| 2599 | ((unsigned int) p_rx_desc + RX_DESC_ALIGNED_SIZE); |
| 2600 | } |
| 2601 | |
| 2602 | /* Closing Rx descriptors ring */ |
| 2603 | p_rx_prev_desc->next_desc_ptr = (rx_desc_base_addr); |
| 2604 | D_CACHE_FLUSH_LINE (p_rx_prev_desc, 0); |
| 2605 | |
| 2606 | /* Save Rx desc pointer to driver struct. */ |
| 2607 | CURR_RFD_SET ((ETH_RX_DESC *) rx_desc_base_addr, rx_queue); |
| 2608 | USED_RFD_SET ((ETH_RX_DESC *) rx_desc_base_addr, rx_queue); |
| 2609 | |
| 2610 | p_eth_port_ctrl->p_rx_desc_area_base[rx_queue] = |
| 2611 | (ETH_RX_DESC *) rx_desc_base_addr; |
| 2612 | p_eth_port_ctrl->rx_desc_area_size[rx_queue] = |
| 2613 | rx_desc_num * RX_DESC_ALIGNED_SIZE; |
| 2614 | |
| 2615 | p_eth_port_ctrl->port_rx_queue_command |= (1 << rx_queue); |
| 2616 | |
| 2617 | return true; |
| 2618 | } |
| 2619 | |
| 2620 | /******************************************************************************* |
| 2621 | * ether_init_tx_desc_ring - Curve a Tx chain desc list and buffer in memory. |
| 2622 | * |
| 2623 | * DESCRIPTION: |
| 2624 | * This function prepares a Tx chained list of descriptors and packet |
| 2625 | * buffers in a form of a ring. The routine must be called after port |
| 2626 | * initialization routine and before port start routine. |
| 2627 | * The Ethernet SDMA engine uses CPU bus addresses to access the various |
| 2628 | * devices in the system (i.e. DRAM). This function uses the ethernet |
| 2629 | * struct 'virtual to physical' routine (set by the user) to set the ring |
| 2630 | * with physical addresses. |
| 2631 | * |
| 2632 | * INPUT: |
| 2633 | * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct. |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 2634 | * ETH_QUEUE tx_queue Number of Tx queue. |
| 2635 | * int tx_desc_num Number of Tx descriptors |
| 2636 | * int tx_buff_size Size of Tx buffer |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 2637 | * unsigned int tx_desc_base_addr Tx descriptors memory area base addr. |
| 2638 | * unsigned int tx_buff_base_addr Tx buffer memory area base addr. |
| 2639 | * |
| 2640 | * OUTPUT: |
| 2641 | * The routine updates the Ethernet port control struct with information |
| 2642 | * regarding the Tx descriptors and buffers. |
| 2643 | * |
| 2644 | * RETURN: |
| 2645 | * false if the given descriptors memory area is not aligned according to |
| 2646 | * Ethernet SDMA specifications. |
| 2647 | * true otherwise. |
| 2648 | * |
| 2649 | *******************************************************************************/ |
| 2650 | static bool ether_init_tx_desc_ring (ETH_PORT_INFO * p_eth_port_ctrl, |
| 2651 | ETH_QUEUE tx_queue, |
| 2652 | int tx_desc_num, |
| 2653 | int tx_buff_size, |
| 2654 | unsigned int tx_desc_base_addr, |
| 2655 | unsigned int tx_buff_base_addr) |
| 2656 | { |
| 2657 | |
| 2658 | ETH_TX_DESC *p_tx_desc; |
| 2659 | ETH_TX_DESC *p_tx_prev_desc; |
| 2660 | unsigned int buffer_addr; |
| 2661 | int ix; /* a counter */ |
| 2662 | |
| 2663 | |
| 2664 | /* save the first desc pointer to link with the last descriptor */ |
| 2665 | p_tx_desc = (ETH_TX_DESC *) tx_desc_base_addr; |
| 2666 | p_tx_prev_desc = p_tx_desc; |
| 2667 | buffer_addr = tx_buff_base_addr; |
| 2668 | |
| 2669 | /* Tx desc Must be 4LW aligned (i.e. Descriptor_Address[3:0]=0000). */ |
| 2670 | if (tx_buff_base_addr & 0xF) |
| 2671 | return false; |
| 2672 | |
| 2673 | /* Tx buffers are limited to 64K bytes and Minimum size is 8 bytes */ |
| 2674 | if ((tx_buff_size > TX_BUFFER_MAX_SIZE) |
| 2675 | || (tx_buff_size < TX_BUFFER_MIN_SIZE)) |
| 2676 | return false; |
| 2677 | |
| 2678 | /* Initialize the Tx descriptors ring */ |
| 2679 | for (ix = 0; ix < tx_desc_num; ix++) { |
| 2680 | p_tx_desc->byte_cnt = 0x0000; |
| 2681 | p_tx_desc->l4i_chk = 0x0000; |
| 2682 | p_tx_desc->cmd_sts = 0x00000000; |
| 2683 | p_tx_desc->next_desc_ptr = |
| 2684 | ((unsigned int) p_tx_desc) + TX_DESC_ALIGNED_SIZE; |
| 2685 | |
| 2686 | p_tx_desc->buf_ptr = buffer_addr; |
| 2687 | p_tx_desc->return_info = 0x00000000; |
| 2688 | D_CACHE_FLUSH_LINE (p_tx_desc, 0); |
| 2689 | buffer_addr += tx_buff_size; |
| 2690 | p_tx_prev_desc = p_tx_desc; |
| 2691 | p_tx_desc = (ETH_TX_DESC *) |
| 2692 | ((unsigned int) p_tx_desc + TX_DESC_ALIGNED_SIZE); |
| 2693 | |
| 2694 | } |
| 2695 | /* Closing Tx descriptors ring */ |
| 2696 | p_tx_prev_desc->next_desc_ptr = tx_desc_base_addr; |
| 2697 | D_CACHE_FLUSH_LINE (p_tx_prev_desc, 0); |
| 2698 | /* Set Tx desc pointer in driver struct. */ |
| 2699 | CURR_TFD_SET ((ETH_TX_DESC *) tx_desc_base_addr, tx_queue); |
| 2700 | USED_TFD_SET ((ETH_TX_DESC *) tx_desc_base_addr, tx_queue); |
| 2701 | |
| 2702 | /* Init Tx ring base and size parameters */ |
| 2703 | p_eth_port_ctrl->p_tx_desc_area_base[tx_queue] = |
| 2704 | (ETH_TX_DESC *) tx_desc_base_addr; |
| 2705 | p_eth_port_ctrl->tx_desc_area_size[tx_queue] = |
| 2706 | (tx_desc_num * TX_DESC_ALIGNED_SIZE); |
| 2707 | |
| 2708 | /* Add the queue to the list of Tx queues of this port */ |
| 2709 | p_eth_port_ctrl->port_tx_queue_command |= (1 << tx_queue); |
| 2710 | |
| 2711 | return true; |
| 2712 | } |
| 2713 | |
| 2714 | /******************************************************************************* |
| 2715 | * eth_port_send - Send an Ethernet packet |
| 2716 | * |
| 2717 | * DESCRIPTION: |
| 2718 | * This routine send a given packet described by p_pktinfo parameter. It |
| 2719 | * supports transmitting of a packet spaned over multiple buffers. The |
| 2720 | * routine updates 'curr' and 'first' indexes according to the packet |
| 2721 | * segment passed to the routine. In case the packet segment is first, |
| 2722 | * the 'first' index is update. In any case, the 'curr' index is updated. |
| 2723 | * If the routine get into Tx resource error it assigns 'curr' index as |
| 2724 | * 'first'. This way the function can abort Tx process of multiple |
| 2725 | * descriptors per packet. |
| 2726 | * |
| 2727 | * INPUT: |
| 2728 | * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct. |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 2729 | * ETH_QUEUE tx_queue Number of Tx queue. |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 2730 | * PKT_INFO *p_pkt_info User packet buffer. |
| 2731 | * |
| 2732 | * OUTPUT: |
| 2733 | * Tx ring 'curr' and 'first' indexes are updated. |
| 2734 | * |
| 2735 | * RETURN: |
| 2736 | * ETH_QUEUE_FULL in case of Tx resource error. |
| 2737 | * ETH_ERROR in case the routine can not access Tx desc ring. |
| 2738 | * ETH_QUEUE_LAST_RESOURCE if the routine uses the last Tx resource. |
| 2739 | * ETH_OK otherwise. |
| 2740 | * |
| 2741 | *******************************************************************************/ |
| 2742 | static ETH_FUNC_RET_STATUS eth_port_send (ETH_PORT_INFO * p_eth_port_ctrl, |
| 2743 | ETH_QUEUE tx_queue, |
| 2744 | PKT_INFO * p_pkt_info) |
| 2745 | { |
| 2746 | volatile ETH_TX_DESC *p_tx_desc_first; |
| 2747 | volatile ETH_TX_DESC *p_tx_desc_curr; |
| 2748 | volatile ETH_TX_DESC *p_tx_next_desc_curr; |
| 2749 | volatile ETH_TX_DESC *p_tx_desc_used; |
| 2750 | unsigned int command_status; |
| 2751 | |
| 2752 | /* Do not process Tx ring in case of Tx ring resource error */ |
| 2753 | if (p_eth_port_ctrl->tx_resource_err[tx_queue] == true) |
| 2754 | return ETH_QUEUE_FULL; |
| 2755 | |
| 2756 | /* Get the Tx Desc ring indexes */ |
| 2757 | CURR_TFD_GET (p_tx_desc_curr, tx_queue); |
| 2758 | USED_TFD_GET (p_tx_desc_used, tx_queue); |
| 2759 | |
| 2760 | if (p_tx_desc_curr == NULL) |
| 2761 | return ETH_ERROR; |
| 2762 | |
| 2763 | /* The following parameters are used to save readings from memory */ |
| 2764 | p_tx_next_desc_curr = TX_NEXT_DESC_PTR (p_tx_desc_curr, tx_queue); |
| 2765 | command_status = p_pkt_info->cmd_sts | ETH_ZERO_PADDING | ETH_GEN_CRC; |
| 2766 | |
| 2767 | if (command_status & (ETH_TX_FIRST_DESC)) { |
| 2768 | /* Update first desc */ |
| 2769 | FIRST_TFD_SET (p_tx_desc_curr, tx_queue); |
| 2770 | p_tx_desc_first = p_tx_desc_curr; |
| 2771 | } else { |
| 2772 | FIRST_TFD_GET (p_tx_desc_first, tx_queue); |
| 2773 | command_status |= ETH_BUFFER_OWNED_BY_DMA; |
| 2774 | } |
| 2775 | |
| 2776 | /* Buffers with a payload smaller than 8 bytes must be aligned to 64-bit */ |
| 2777 | /* boundary. We use the memory allocated for Tx descriptor. This memory */ |
| 2778 | /* located in TX_BUF_OFFSET_IN_DESC offset within the Tx descriptor. */ |
| 2779 | if (p_pkt_info->byte_cnt <= 8) { |
| 2780 | printf ("You have failed in the < 8 bytes errata - fixme\n"); /* RABEEH - TBD */ |
| 2781 | return ETH_ERROR; |
| 2782 | |
| 2783 | p_tx_desc_curr->buf_ptr = |
| 2784 | (unsigned int) p_tx_desc_curr + TX_BUF_OFFSET_IN_DESC; |
| 2785 | eth_b_copy (p_pkt_info->buf_ptr, p_tx_desc_curr->buf_ptr, |
| 2786 | p_pkt_info->byte_cnt); |
| 2787 | } else |
| 2788 | p_tx_desc_curr->buf_ptr = p_pkt_info->buf_ptr; |
| 2789 | |
| 2790 | p_tx_desc_curr->byte_cnt = p_pkt_info->byte_cnt; |
| 2791 | p_tx_desc_curr->return_info = p_pkt_info->return_info; |
| 2792 | |
| 2793 | if (p_pkt_info->cmd_sts & (ETH_TX_LAST_DESC)) { |
| 2794 | /* Set last desc with DMA ownership and interrupt enable. */ |
| 2795 | p_tx_desc_curr->cmd_sts = command_status | |
| 2796 | ETH_BUFFER_OWNED_BY_DMA | ETH_TX_ENABLE_INTERRUPT; |
| 2797 | |
| 2798 | if (p_tx_desc_curr != p_tx_desc_first) |
| 2799 | p_tx_desc_first->cmd_sts |= ETH_BUFFER_OWNED_BY_DMA; |
| 2800 | |
| 2801 | /* Flush CPU pipe */ |
| 2802 | |
| 2803 | D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_curr, 0); |
| 2804 | D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_first, 0); |
| 2805 | CPU_PIPE_FLUSH; |
| 2806 | |
| 2807 | /* Apply send command */ |
| 2808 | ETH_ENABLE_TX_QUEUE (tx_queue, p_eth_port_ctrl->port_num); |
| 2809 | |
| 2810 | /* Finish Tx packet. Update first desc in case of Tx resource error */ |
| 2811 | p_tx_desc_first = p_tx_next_desc_curr; |
| 2812 | FIRST_TFD_SET (p_tx_desc_first, tx_queue); |
| 2813 | |
| 2814 | } else { |
| 2815 | p_tx_desc_curr->cmd_sts = command_status; |
| 2816 | D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_curr, 0); |
| 2817 | } |
| 2818 | |
| 2819 | /* Check for ring index overlap in the Tx desc ring */ |
| 2820 | if (p_tx_next_desc_curr == p_tx_desc_used) { |
| 2821 | /* Update the current descriptor */ |
| 2822 | CURR_TFD_SET (p_tx_desc_first, tx_queue); |
| 2823 | |
| 2824 | p_eth_port_ctrl->tx_resource_err[tx_queue] = true; |
| 2825 | return ETH_QUEUE_LAST_RESOURCE; |
| 2826 | } else { |
| 2827 | /* Update the current descriptor */ |
| 2828 | CURR_TFD_SET (p_tx_next_desc_curr, tx_queue); |
| 2829 | return ETH_OK; |
| 2830 | } |
| 2831 | } |
| 2832 | |
| 2833 | /******************************************************************************* |
| 2834 | * eth_tx_return_desc - Free all used Tx descriptors |
| 2835 | * |
| 2836 | * DESCRIPTION: |
| 2837 | * This routine returns the transmitted packet information to the caller. |
| 2838 | * It uses the 'first' index to support Tx desc return in case a transmit |
| 2839 | * of a packet spanned over multiple buffer still in process. |
| 2840 | * In case the Tx queue was in "resource error" condition, where there are |
| 2841 | * no available Tx resources, the function resets the resource error flag. |
| 2842 | * |
| 2843 | * INPUT: |
| 2844 | * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct. |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 2845 | * ETH_QUEUE tx_queue Number of Tx queue. |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 2846 | * PKT_INFO *p_pkt_info User packet buffer. |
| 2847 | * |
| 2848 | * OUTPUT: |
| 2849 | * Tx ring 'first' and 'used' indexes are updated. |
| 2850 | * |
| 2851 | * RETURN: |
| 2852 | * ETH_ERROR in case the routine can not access Tx desc ring. |
| 2853 | * ETH_RETRY in case there is transmission in process. |
| 2854 | * ETH_END_OF_JOB if the routine has nothing to release. |
| 2855 | * ETH_OK otherwise. |
| 2856 | * |
| 2857 | *******************************************************************************/ |
| 2858 | static ETH_FUNC_RET_STATUS eth_tx_return_desc (ETH_PORT_INFO * |
| 2859 | p_eth_port_ctrl, |
| 2860 | ETH_QUEUE tx_queue, |
| 2861 | PKT_INFO * p_pkt_info) |
| 2862 | { |
| 2863 | volatile ETH_TX_DESC *p_tx_desc_used = NULL; |
| 2864 | volatile ETH_TX_DESC *p_tx_desc_first = NULL; |
| 2865 | unsigned int command_status; |
| 2866 | |
| 2867 | |
| 2868 | /* Get the Tx Desc ring indexes */ |
| 2869 | USED_TFD_GET (p_tx_desc_used, tx_queue); |
| 2870 | FIRST_TFD_GET (p_tx_desc_first, tx_queue); |
| 2871 | |
| 2872 | |
| 2873 | /* Sanity check */ |
| 2874 | if (p_tx_desc_used == NULL) |
| 2875 | return ETH_ERROR; |
| 2876 | |
| 2877 | command_status = p_tx_desc_used->cmd_sts; |
| 2878 | |
| 2879 | /* Still transmitting... */ |
| 2880 | if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) { |
| 2881 | D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_used, 0); |
| 2882 | return ETH_RETRY; |
| 2883 | } |
| 2884 | |
| 2885 | /* Stop release. About to overlap the current available Tx descriptor */ |
| 2886 | if ((p_tx_desc_used == p_tx_desc_first) && |
| 2887 | (p_eth_port_ctrl->tx_resource_err[tx_queue] == false)) { |
| 2888 | D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_used, 0); |
| 2889 | return ETH_END_OF_JOB; |
| 2890 | } |
| 2891 | |
| 2892 | /* Pass the packet information to the caller */ |
| 2893 | p_pkt_info->cmd_sts = command_status; |
| 2894 | p_pkt_info->return_info = p_tx_desc_used->return_info; |
| 2895 | p_tx_desc_used->return_info = 0; |
| 2896 | |
| 2897 | /* Update the next descriptor to release. */ |
| 2898 | USED_TFD_SET (TX_NEXT_DESC_PTR (p_tx_desc_used, tx_queue), tx_queue); |
| 2899 | |
| 2900 | /* Any Tx return cancels the Tx resource error status */ |
| 2901 | if (p_eth_port_ctrl->tx_resource_err[tx_queue] == true) |
| 2902 | p_eth_port_ctrl->tx_resource_err[tx_queue] = false; |
| 2903 | |
| 2904 | D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_used, 0); |
| 2905 | |
| 2906 | return ETH_OK; |
| 2907 | |
| 2908 | } |
| 2909 | |
| 2910 | /******************************************************************************* |
| 2911 | * eth_port_receive - Get received information from Rx ring. |
| 2912 | * |
| 2913 | * DESCRIPTION: |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 2914 | * This routine returns the received data to the caller. There is no |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 2915 | * data copying during routine operation. All information is returned |
| 2916 | * using pointer to packet information struct passed from the caller. |
| 2917 | * If the routine exhausts Rx ring resources then the resource error flag |
| 2918 | * is set. |
| 2919 | * |
| 2920 | * INPUT: |
| 2921 | * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct. |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 2922 | * ETH_QUEUE rx_queue Number of Rx queue. |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 2923 | * PKT_INFO *p_pkt_info User packet buffer. |
| 2924 | * |
| 2925 | * OUTPUT: |
| 2926 | * Rx ring current and used indexes are updated. |
| 2927 | * |
| 2928 | * RETURN: |
| 2929 | * ETH_ERROR in case the routine can not access Rx desc ring. |
| 2930 | * ETH_QUEUE_FULL if Rx ring resources are exhausted. |
| 2931 | * ETH_END_OF_JOB if there is no received data. |
| 2932 | * ETH_OK otherwise. |
| 2933 | * |
| 2934 | *******************************************************************************/ |
| 2935 | static ETH_FUNC_RET_STATUS eth_port_receive (ETH_PORT_INFO * p_eth_port_ctrl, |
| 2936 | ETH_QUEUE rx_queue, |
| 2937 | PKT_INFO * p_pkt_info) |
| 2938 | { |
| 2939 | volatile ETH_RX_DESC *p_rx_curr_desc; |
| 2940 | volatile ETH_RX_DESC *p_rx_next_curr_desc; |
| 2941 | volatile ETH_RX_DESC *p_rx_used_desc; |
| 2942 | unsigned int command_status; |
| 2943 | |
| 2944 | /* Do not process Rx ring in case of Rx ring resource error */ |
| 2945 | if (p_eth_port_ctrl->rx_resource_err[rx_queue] == true) { |
| 2946 | printf ("\nRx Queue is full ...\n"); |
| 2947 | return ETH_QUEUE_FULL; |
| 2948 | } |
| 2949 | |
| 2950 | /* Get the Rx Desc ring 'curr and 'used' indexes */ |
| 2951 | CURR_RFD_GET (p_rx_curr_desc, rx_queue); |
| 2952 | USED_RFD_GET (p_rx_used_desc, rx_queue); |
| 2953 | |
| 2954 | /* Sanity check */ |
| 2955 | if (p_rx_curr_desc == NULL) |
| 2956 | return ETH_ERROR; |
| 2957 | |
| 2958 | /* The following parameters are used to save readings from memory */ |
| 2959 | p_rx_next_curr_desc = RX_NEXT_DESC_PTR (p_rx_curr_desc, rx_queue); |
| 2960 | command_status = p_rx_curr_desc->cmd_sts; |
| 2961 | |
| 2962 | /* Nothing to receive... */ |
| 2963 | if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) { |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 2964 | /* DP(printf("Rx: command_status: %08x\n", command_status)); */ |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 2965 | D_CACHE_FLUSH_LINE ((unsigned int) p_rx_curr_desc, 0); |
| 2966 | /* DP(printf("\nETH_END_OF_JOB ...\n"));*/ |
| 2967 | return ETH_END_OF_JOB; |
| 2968 | } |
| 2969 | |
| 2970 | p_pkt_info->byte_cnt = (p_rx_curr_desc->byte_cnt) - RX_BUF_OFFSET; |
| 2971 | p_pkt_info->cmd_sts = command_status; |
| 2972 | p_pkt_info->buf_ptr = (p_rx_curr_desc->buf_ptr) + RX_BUF_OFFSET; |
| 2973 | p_pkt_info->return_info = p_rx_curr_desc->return_info; |
| 2974 | p_pkt_info->l4i_chk = p_rx_curr_desc->buf_size; /* IP fragment indicator */ |
| 2975 | |
| 2976 | /* Clean the return info field to indicate that the packet has been */ |
| 2977 | /* moved to the upper layers */ |
| 2978 | p_rx_curr_desc->return_info = 0; |
| 2979 | |
| 2980 | /* Update 'curr' in data structure */ |
| 2981 | CURR_RFD_SET (p_rx_next_curr_desc, rx_queue); |
| 2982 | |
| 2983 | /* Rx descriptors resource exhausted. Set the Rx ring resource error flag */ |
| 2984 | if (p_rx_next_curr_desc == p_rx_used_desc) |
| 2985 | p_eth_port_ctrl->rx_resource_err[rx_queue] = true; |
| 2986 | |
| 2987 | D_CACHE_FLUSH_LINE ((unsigned int) p_rx_curr_desc, 0); |
| 2988 | CPU_PIPE_FLUSH; |
| 2989 | return ETH_OK; |
| 2990 | } |
| 2991 | |
| 2992 | /******************************************************************************* |
| 2993 | * eth_rx_return_buff - Returns a Rx buffer back to the Rx ring. |
| 2994 | * |
| 2995 | * DESCRIPTION: |
| 2996 | * This routine returns a Rx buffer back to the Rx ring. It retrieves the |
| 2997 | * next 'used' descriptor and attached the returned buffer to it. |
| 2998 | * In case the Rx ring was in "resource error" condition, where there are |
| 2999 | * no available Rx resources, the function resets the resource error flag. |
| 3000 | * |
| 3001 | * INPUT: |
| 3002 | * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct. |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 3003 | * ETH_QUEUE rx_queue Number of Rx queue. |
stroese | 771e05b | 2004-12-16 18:21:17 +0000 | [diff] [blame] | 3004 | * PKT_INFO *p_pkt_info Information on the returned buffer. |
| 3005 | * |
| 3006 | * OUTPUT: |
| 3007 | * New available Rx resource in Rx descriptor ring. |
| 3008 | * |
| 3009 | * RETURN: |
| 3010 | * ETH_ERROR in case the routine can not access Rx desc ring. |
| 3011 | * ETH_OK otherwise. |
| 3012 | * |
| 3013 | *******************************************************************************/ |
| 3014 | static ETH_FUNC_RET_STATUS eth_rx_return_buff (ETH_PORT_INFO * |
| 3015 | p_eth_port_ctrl, |
| 3016 | ETH_QUEUE rx_queue, |
| 3017 | PKT_INFO * p_pkt_info) |
| 3018 | { |
| 3019 | volatile ETH_RX_DESC *p_used_rx_desc; /* Where to return Rx resource */ |
| 3020 | |
| 3021 | /* Get 'used' Rx descriptor */ |
| 3022 | USED_RFD_GET (p_used_rx_desc, rx_queue); |
| 3023 | |
| 3024 | /* Sanity check */ |
| 3025 | if (p_used_rx_desc == NULL) |
| 3026 | return ETH_ERROR; |
| 3027 | |
| 3028 | p_used_rx_desc->buf_ptr = p_pkt_info->buf_ptr; |
| 3029 | p_used_rx_desc->return_info = p_pkt_info->return_info; |
| 3030 | p_used_rx_desc->byte_cnt = p_pkt_info->byte_cnt; |
| 3031 | p_used_rx_desc->buf_size = MV64360_RX_BUFFER_SIZE; /* Reset Buffer size */ |
| 3032 | |
| 3033 | /* Flush the write pipe */ |
| 3034 | CPU_PIPE_FLUSH; |
| 3035 | |
| 3036 | /* Return the descriptor to DMA ownership */ |
| 3037 | p_used_rx_desc->cmd_sts = |
| 3038 | ETH_BUFFER_OWNED_BY_DMA | ETH_RX_ENABLE_INTERRUPT; |
| 3039 | |
| 3040 | /* Flush descriptor and CPU pipe */ |
| 3041 | D_CACHE_FLUSH_LINE ((unsigned int) p_used_rx_desc, 0); |
| 3042 | CPU_PIPE_FLUSH; |
| 3043 | |
| 3044 | /* Move the used descriptor pointer to the next descriptor */ |
| 3045 | USED_RFD_SET (RX_NEXT_DESC_PTR (p_used_rx_desc, rx_queue), rx_queue); |
| 3046 | |
| 3047 | /* Any Rx return cancels the Rx resource error status */ |
| 3048 | if (p_eth_port_ctrl->rx_resource_err[rx_queue] == true) |
| 3049 | p_eth_port_ctrl->rx_resource_err[rx_queue] = false; |
| 3050 | |
| 3051 | return ETH_OK; |
| 3052 | } |
| 3053 | |
| 3054 | /******************************************************************************* |
| 3055 | * eth_port_set_rx_coal - Sets coalescing interrupt mechanism on RX path |
| 3056 | * |
| 3057 | * DESCRIPTION: |
| 3058 | * This routine sets the RX coalescing interrupt mechanism parameter. |
| 3059 | * This parameter is a timeout counter, that counts in 64 t_clk |
| 3060 | * chunks ; that when timeout event occurs a maskable interrupt |
| 3061 | * occurs. |
| 3062 | * The parameter is calculated using the tClk of the MV-643xx chip |
| 3063 | * , and the required delay of the interrupt in usec. |
| 3064 | * |
| 3065 | * INPUT: |
| 3066 | * ETH_PORT eth_port_num Ethernet port number |
| 3067 | * unsigned int t_clk t_clk of the MV-643xx chip in HZ units |
| 3068 | * unsigned int delay Delay in usec |
| 3069 | * |
| 3070 | * OUTPUT: |
| 3071 | * Interrupt coalescing mechanism value is set in MV-643xx chip. |
| 3072 | * |
| 3073 | * RETURN: |
| 3074 | * The interrupt coalescing value set in the gigE port. |
| 3075 | * |
| 3076 | *******************************************************************************/ |
| 3077 | #if 0 /* FIXME */ |
| 3078 | static unsigned int eth_port_set_rx_coal (ETH_PORT eth_port_num, |
| 3079 | unsigned int t_clk, |
| 3080 | unsigned int delay) |
| 3081 | { |
| 3082 | unsigned int coal; |
| 3083 | |
| 3084 | coal = ((t_clk / 1000000) * delay) / 64; |
| 3085 | /* Set RX Coalescing mechanism */ |
| 3086 | MV_REG_WRITE (MV64360_ETH_SDMA_CONFIG_REG (eth_port_num), |
| 3087 | ((coal & 0x3fff) << 8) | |
| 3088 | (MV_REG_READ |
| 3089 | (MV64360_ETH_SDMA_CONFIG_REG (eth_port_num)) |
| 3090 | & 0xffc000ff)); |
| 3091 | return coal; |
| 3092 | } |
| 3093 | |
| 3094 | #endif |
| 3095 | /******************************************************************************* |
| 3096 | * eth_port_set_tx_coal - Sets coalescing interrupt mechanism on TX path |
| 3097 | * |
| 3098 | * DESCRIPTION: |
| 3099 | * This routine sets the TX coalescing interrupt mechanism parameter. |
| 3100 | * This parameter is a timeout counter, that counts in 64 t_clk |
| 3101 | * chunks ; that when timeout event occurs a maskable interrupt |
| 3102 | * occurs. |
| 3103 | * The parameter is calculated using the t_cLK frequency of the |
| 3104 | * MV-643xx chip and the required delay in the interrupt in uSec |
| 3105 | * |
| 3106 | * INPUT: |
| 3107 | * ETH_PORT eth_port_num Ethernet port number |
| 3108 | * unsigned int t_clk t_clk of the MV-643xx chip in HZ units |
| 3109 | * unsigned int delay Delay in uSeconds |
| 3110 | * |
| 3111 | * OUTPUT: |
| 3112 | * Interrupt coalescing mechanism value is set in MV-643xx chip. |
| 3113 | * |
| 3114 | * RETURN: |
| 3115 | * The interrupt coalescing value set in the gigE port. |
| 3116 | * |
| 3117 | *******************************************************************************/ |
| 3118 | #if 0 /* FIXME */ |
| 3119 | static unsigned int eth_port_set_tx_coal (ETH_PORT eth_port_num, |
| 3120 | unsigned int t_clk, |
| 3121 | unsigned int delay) |
| 3122 | { |
| 3123 | unsigned int coal; |
| 3124 | |
| 3125 | coal = ((t_clk / 1000000) * delay) / 64; |
| 3126 | /* Set TX Coalescing mechanism */ |
| 3127 | MV_REG_WRITE (MV64360_ETH_TX_FIFO_URGENT_THRESHOLD_REG (eth_port_num), |
| 3128 | coal << 4); |
| 3129 | return coal; |
| 3130 | } |
| 3131 | #endif |
| 3132 | |
| 3133 | /******************************************************************************* |
| 3134 | * eth_b_copy - Copy bytes from source to destination |
| 3135 | * |
| 3136 | * DESCRIPTION: |
| 3137 | * This function supports the eight bytes limitation on Tx buffer size. |
| 3138 | * The routine will zero eight bytes starting from the destination address |
| 3139 | * followed by copying bytes from the source address to the destination. |
| 3140 | * |
| 3141 | * INPUT: |
| 3142 | * unsigned int src_addr 32 bit source address. |
| 3143 | * unsigned int dst_addr 32 bit destination address. |
| 3144 | * int byte_count Number of bytes to copy. |
| 3145 | * |
| 3146 | * OUTPUT: |
| 3147 | * See description. |
| 3148 | * |
| 3149 | * RETURN: |
| 3150 | * None. |
| 3151 | * |
| 3152 | *******************************************************************************/ |
| 3153 | static void eth_b_copy (unsigned int src_addr, unsigned int dst_addr, |
| 3154 | int byte_count) |
| 3155 | { |
| 3156 | /* Zero the dst_addr area */ |
| 3157 | *(unsigned int *) dst_addr = 0x0; |
| 3158 | |
| 3159 | while (byte_count != 0) { |
| 3160 | *(char *) dst_addr = *(char *) src_addr; |
| 3161 | dst_addr++; |
| 3162 | src_addr++; |
| 3163 | byte_count--; |
| 3164 | } |
| 3165 | } |