Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

CHG: Code review.

   * board/smart3250/net.c: Format the source code.
   * board/smart3250/net.c: (phy_get_link_status): Remove one comment to eliminate the so many output in ethernet initialization.
  • Loading branch information...
commit ca6b5ce3f184f770fcf34383f8703dab324cdd9a 1 parent e54b917
@diverger authored
Showing with 226 additions and 219 deletions.
  1. +226 −219 board/smart3250/net.c
View
445 board/smart3250/net.c
@@ -1,45 +1,45 @@
-/*
- * Copyright (C) 2008 by NXP Semiconductors
- * All rights reserved.
- *
- * @Author: Kevin Wells
- * @Descr: Phytec 3250 net interface support functions
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <common.h>
-#include <command.h>
-#include <net.h>
-#include <lpc3250.h>
-#include <configs/smart3250.h>
-#include "smart3250_prv.h"
-#include "miiphy.h"
-
-#define ETHERNET_DEBUG
+/*
+ * Copyright (C) 2008 by NXP Semiconductors
+ * All rights reserved.
+ *
+ * @Author: Kevin Wells
+ * @Descr: Phytec 3250 net interface support functions
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <common.h>
+#include <command.h>
+#include <net.h>
+#include <lpc3250.h>
+#include <configs/smart3250.h>
+#include "smart3250_prv.h"
+#include "miiphy.h"
+
+#define ETHERNET_DEBUG
//#undef ETHERNET_DEBUG
#ifdef ETHERNET_DEBUG
#define __ether_printf(fmt, args...) printf(fmt , ##args)
#else
#define __ether_printf(fmt, args...)
-#endif
-
+#endif
+
static unsigned long g_dmabase;
static unsigned long gdma_size;
static TXRX_DESC_T *pTXDesc;
@@ -47,15 +47,15 @@ static unsigned long *pTXStatus;
static unsigned long pTXVBuffs [ENET_MAX_TX_PACKETS];
static TXRX_DESC_T *pRXDesc;
static RX_STATUS_T *pRXStatus;
-static unsigned long pRXVBuffs [ENET_MAX_RX_PACKETS];
-#ifndef USE_IRAM_FOR_ETH_BUFFERS
+static unsigned long pRXVBuffs [ENET_MAX_RX_PACKETS];
+#ifndef USE_IRAM_FOR_ETH_BUFFERS
static unsigned long ethbuffs[4096];
-#endif
+#endif
extern PHY_HW_T phyhwdesc;
static void msDelay(unsigned long ms)
{
- udelay(ms * 1000);
+ udelay(ms * 1000);
}
//------------------------------------------------------------------------------
@@ -152,54 +152,54 @@ int phy_reset(void)
return goodacc;
}
-static int phy_get_link_status (void)
-{
- unsigned long status;
- int mst = 1000;
-
- /* Status is read once to clear old link state */
- RMII_Read(PHY_BMSR,&status);
-
- /*
- * Wait if the link is up, and auto-negotiation is in progress
- * (ie - we're capable and it's not done)
- */
- status = 0;
- RMII_Read(PHY_BMSR, &status);
-
- while ( (status & PHY_BMSR_LS) // link is up
- && (status & PHY_BMSR_AUTN_ABLE) // auto-negotiation enabled
- && !(status & PHY_BMSR_AUTN_COMP) // auto-negotiation not complete
- && ( mst > 0 ) // not timeout yet
- )
- {
- RMII_Read(PHY_BMSR, &status);
- --mst;
- msDelay(1); // delay 1ms
- }
-
- // auto-negotiation timeout, or not enabled, or link isn't up, or negotiation complete
- if ( status & PHY_BMSR_AUTN_COMP )
- {
- // auto negotiation complete
- printf( "ENET:auto-negotiation complete.\n" );
- return 0;
- }
- else if ( (status & PHY_BMSR_LS) && (!(status & PHY_BMSR_AUTN_ABLE)) )
- {
- // Auto-negotiation not available, and link is up
- return 0;
- }
- else
- {
- //
- printf( "ENET:Link isn't up.\n" );
- return 1;
- }
-
- return 1;
-}
-
+static int phy_get_link_status (void)
+{
+ unsigned long status;
+ int mst = 1000;
+
+ /* Status is read once to clear old link state */
+ RMII_Read(PHY_BMSR,&status);
+
+ /*
+ * Wait if the link is up, and auto-negotiation is in progress
+ * (ie - we're capable and it's not done)
+ */
+ status = 0;
+ RMII_Read(PHY_BMSR, &status);
+
+ while ( (status & PHY_BMSR_LS) // link is up
+ && (status & PHY_BMSR_AUTN_ABLE) // auto-negotiation enabled
+ && !(status & PHY_BMSR_AUTN_COMP) // auto-negotiation not complete
+ && ( mst > 0 ) // not timeout yet
+ )
+ {
+ RMII_Read(PHY_BMSR, &status);
+ --mst;
+ msDelay(1); // delay 1ms
+ }
+
+ // auto-negotiation timeout, or not enabled, or link isn't up, or negotiation complete
+ if ( status & PHY_BMSR_AUTN_COMP )
+ {
+ // auto negotiation complete
+ printf( "ENET:auto-negotiation complete.\n" );
+ return 0;
+ }
+ else if ( (status & PHY_BMSR_LS) && (!(status & PHY_BMSR_AUTN_ABLE)) )
+ {
+ // Auto-negotiation not available, and link is up
+ return 0;
+ }
+ else
+ {
+ //
+ //printf( "ENET:Link isn't up.\n" );
+ return 1;
+ }
+
+ return 1;
+}
+
//------------------------------------------------------------------------------
int txrx_setup(void)
{
@@ -208,14 +208,14 @@ int txrx_setup(void)
TXRX_DESC_T *pTXRXDesc;
RX_STATUS_T *pRXStatusL;
- // Get physical address and size of DMA buffers
-#ifdef USE_IRAM_FOR_ETH_BUFFERS
- g_dmabase = (unsigned long) IRAM_ETH_BUFF_BASE;
- gdma_size = IRAM_ETH_BUFF_SIZE;
-#else
- g_dmabase = (unsigned long) &ethbuffs;
- gdma_size = sizeof(ethbuffs);
-#endif
+ // Get physical address and size of DMA buffers
+#ifdef USE_IRAM_FOR_ETH_BUFFERS
+ g_dmabase = (unsigned long) IRAM_ETH_BUFF_BASE;
+ gdma_size = IRAM_ETH_BUFF_SIZE;
+#else
+ g_dmabase = (unsigned long) &ethbuffs;
+ gdma_size = sizeof(ethbuffs);
+#endif
// Setup base pointers
pbase1 = g_dmabase; // Start of descriptors
@@ -241,11 +241,11 @@ int txrx_setup(void)
*pTXStatusL = 0;
// Save virtual address of buffer
-#ifdef USE_IRAM_FOR_ETH_BUFFERS
+#ifdef USE_IRAM_FOR_ETH_BUFFERS
pTXVBuffs [idx] = (unsigned long) pbase3;
-#else
-#pragma error "NOT supported"
-#endif
+#else
+#pragma error "NOT supported"
+#endif
// Next descriptor and status
pTXRXDesc++;
@@ -273,10 +273,10 @@ int txrx_setup(void)
pRXStatusL->statushashcrc = 0;
// Save virtual address of buffer
-#ifdef USE_IRAM_FOR_ETH_BUFFERS
- pRXVBuffs [idx] = (unsigned long) pbase3;
-#else
-#pragma error "NOT supported"
+#ifdef USE_IRAM_FOR_ETH_BUFFERS
+ pRXVBuffs [idx] = (unsigned long) pbase3;
+#else
+#pragma error "NOT supported"
#endif
// Next descriptor and status
@@ -293,11 +293,11 @@ int txrx_setup(void)
//------------------------------------------------------------------------------
int HWInit(bd_t * bd)
{
- int btemp;
- unsigned int duplex, speed;
- unsigned long tmp1, mst = 250;
- int val = 0;
-
+ int btemp;
+ unsigned int duplex, speed;
+ unsigned long tmp1, mst = 250;
+ int val = 0;
+
// Enable MAC interface
CLKPWR->clkpwr_macclk_ctrl = (CLKPWR_MACCTRL_HRCCLK_EN |
CLKPWR_MACCTRL_MMIOCLK_EN | CLKPWR_MACCTRL_DMACLK_EN |
@@ -339,79 +339,81 @@ int HWInit(bd_t * bd)
// MII setup
ENETMAC->command = COMMAND_PASSRUNTFRAME;
#endif
-
- //////////////////////////////////////////////////////////////////////////
- // In the former, this have a reset procedure, and software auto-negotiation setting. This is true for
- // smartarm3250 board's official u-boot code.
- // KSZ8041NL has two method to enable auto-negotiation, hardware (Pin 30 pull-up, this is default setting) and software.
- // On the smartarm3250 board, this pin has been pulled up to 3.3V.
- btemp = phy_reset();
- if ( btemp == 0 )
- {
+
+ //////////////////////////////////////////////////////////////////////////
+ // In the former, this have a reset procedure, and software auto-negotiation setting. This is true for
+ // smartarm3250 board's official u-boot code.
+ // KSZ8041NL has two method to enable auto-negotiation, hardware (Pin 30 pull-up, this is default setting) and software.
+ // On the smartarm3250 board, this pin has been pulled up to 3.3V.
+ /*
+ btemp = phy_reset();
+ if ( btemp == 0 )
+ {
printf("ENET:Reset of PHY timed out\n");
return 0;
- }
-
+ }
+ */
+
// Enable rate auto-negotiation for the link
if (RMII_Write(PHY_BMCR,
(PHY_BMCR_100MB | PHY_BMCR_AUTON)) == 0)
{
return 0;
- }
-
- mst = 1000;
- btemp = 1;
- while(mst > 0)
- {
- /* Wait for Link status to set UP or Timeout */
- if(phy_get_link_status() == 0) {
- mst = 0;
- btemp = 0;
- printf("ENET:auto-negotiation complete\n");
- }
- else {
- mst--;
- msDelay(1);
- }
- }
-
- if(btemp)
- {
- // We've known that the board is designed to enable auto-negotiation ability, so if failed, the only reason is auto-negotiation failed.
- printf("ENET:auto-negotiation failed.\n");
- return 0;
- }
-
- /*
- * Read Vendor specific PHY Ctrl/Status Register to determine
- * Ethernet Configuration
- */
- tmp1 = 0;
- RMII_Read (KSZ8041NL_PHY_STATUS,&tmp1);
- val = (tmp1 & 0x1c) >> 2;
- switch (val) {
- case 1:
- /* 10Mbps Half Duplex */
- duplex = 0;
- speed = 0;
- break;
- case 5:
- /* 10Mbps Full Duplex */
- duplex = 1;
- speed = 0;
- break;
- case 2:
- /* 100Mbps Half Duplex */
- duplex = 0;
- speed = 1;
- break;
- case 6:
- /* 100Mbps Full Duplex */
- duplex = 1;
- speed = 1;
- break;
- }
-
+ }
+
+ mst = 1000;
+ btemp = 1;
+ while(mst > 0)
+ {
+ /* Wait for Link status to set UP or Timeout */
+ if(phy_get_link_status() == 0) {
+ mst = 0;
+ btemp = 0;
+ printf("ENET:auto-negotiation complete\n");
+ }
+ else {
+ mst--;
+ msDelay(1);
+ }
+ }
+
+ if(btemp)
+ {
+ // We've known that the board is designed to enable auto-negotiation ability, so if failed, the only reason is auto-negotiation failed.
+ printf("ENET:auto-negotiation failed.\n");
+ return 0;
+ }
+
+ /*
+ * Read Vendor specific PHY Ctrl/Status Register to determine
+ * Ethernet Configuration
+ */
+ tmp1 = 0;
+ RMII_Read (KSZ8041NL_PHY_STATUS,&tmp1);
+ val = (tmp1 & 0x1c) >> 2;
+ switch (val) {
+ case 1:
+ /* 10Mbps Half Duplex */
+ duplex = 0;
+ speed = 0;
+ break;
+ case 5:
+ /* 10Mbps Full Duplex */
+ duplex = 1;
+ speed = 0;
+ break;
+ case 2:
+ /* 100Mbps Half Duplex */
+ duplex = 0;
+ speed = 1;
+ break;
+ case 6:
+ /* 100Mbps Full Duplex */
+ duplex = 1;
+ speed = 1;
+ break;
+ }
+
// Configure Full/Half Duplex mode
if (duplex == 1)
{
@@ -490,60 +492,65 @@ int HWDeInit(void)
return 1;
}
-
-void eth_halt (void)
-{
- HWDeInit();
-}
-
-int eth_init (bd_t * bd)
-{
- int rc;
-
+
+void eth_halt (void)
+{
+ HWDeInit();
+}
+
+int eth_init (bd_t * bd)
+{
+ int rc;
+
// Set MAC address from hardware
- bd->bi_enetaddr[0] = phyhwdesc.mac[0];
- bd->bi_enetaddr[1] = phyhwdesc.mac[1];
- bd->bi_enetaddr[2] = phyhwdesc.mac[2];
- bd->bi_enetaddr[3] = phyhwdesc.mac[3];
- bd->bi_enetaddr[4] = phyhwdesc.mac[4];
- bd->bi_enetaddr[5] = phyhwdesc.mac[5];
- printf ("\tHW MAC address: "
+ bd->bi_enetaddr[0] = phyhwdesc.mac[0];
+ bd->bi_enetaddr[1] = phyhwdesc.mac[1];
+ bd->bi_enetaddr[2] = phyhwdesc.mac[2];
+ bd->bi_enetaddr[3] = phyhwdesc.mac[3];
+ bd->bi_enetaddr[4] = phyhwdesc.mac[4];
+ bd->bi_enetaddr[5] = phyhwdesc.mac[5];
+ printf ("\tHW MAC address: "
+ "%02X:%02X:%02X:%02X:%02X:%02X\n",
+ bd->bi_enetaddr[0], bd->bi_enetaddr[1],
+ bd->bi_enetaddr[2], bd->bi_enetaddr[3],
+ bd->bi_enetaddr[4], bd->bi_enetaddr[5] );
+
rc = HWInit(bd);
// De-init if an error occurred
if (rc == 0)
-
+ {
printf ("ENET init failure\n");
HWDeInit();
- // De-init if an error occurred
+ return -1;
}
return 0;
- HWDeInit();
- return -1;
- }
-
- return 0;
+}
+
+/* Get a data block via Ethernet */
+int eth_rx (void)
+{
unsigned long idx, length;
-
+
// Determine if a frame has been received
length = 0;
idx = ENETMAC->rxconsumeindex;
if (ENETMAC->rxproduceindex != idx)
-
+ {
// Clear interrupt
ENETMAC->intclear = MACINT_RXDONEINTEN;
// Frame received, get size of RX packet
length = (pRXStatus[idx].statusinfo & 0x7FF);
- // Clear interrupt
- ENETMAC->intclear = MACINT_RXDONEINTEN;
-
- // Frame received, get size of RX packet
+
+ /* Pass the packet up to the protocol layer */
+ if (length > 0)
+ {
memcpy((void *) NetRxPackets[0], (void *) pRXVBuffs [idx], length);
-
- /* Pass the packet up to the protocol layer */
- if (length > 0)
+ NetReceive (NetRxPackets[0], (unsigned short) length);
+ }
+
// Return DMA buffer
idx++;
if (idx >= ENET_MAX_TX_PACKETS)
@@ -553,14 +560,14 @@ int eth_rx (void)
ENETMAC->rxconsumeindex = (unsigned long) idx;
}
- idx = 0;
- }
- ENETMAC->rxconsumeindex = (unsigned long) idx;
- }
-
- return (int) length;
-}
-
+ return (int) length;
+}
+
+/* Send a data block via Ethernet. */
+int eth_send (volatile void *packet, int length)
+{
+ unsigned long idx, cidx, fb;
+
// Determine number of free buffers and wait for a buffer if needed
fb = 0;
while (fb == 0)
@@ -598,6 +605,6 @@ int eth_send (volatile void *packet, int length)
}
ENETMAC->txproduceindex = idx;
- {
- idx = 0;
- }
+ return 0;
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.